# FORENSIC AUDIT REPORT: MILESTONE 2 (ASSET PIPELINE: 30 DARK FANTASY MAP STYLES)

> **Auditor**: `auditor_m2`  
> **Parent**: `orchestrator_14` (Conversation ID: `327366ba-dd05-4805-b53b-659a199b1450`)  
> **Target Work Product**: Milestone 2 — Design & Asset Pipeline: 30 Styles Assets  
> **Integrity Mode**: `development` (per `ORIGINAL_REQUEST.md` § 2026-10-02T02:00:04Z)  
> **Verdict**: **CLEAN**

---

## 1. Observation

Direct empirical evidence obtained through static source inspection, statistical pixel analysis, vector normal gradient audits, reproducibility stress-testing, hygiene checks, and test runner execution:

### 1.1. Filesystem & Directory Structure
- **Target directory**: `client/webapp/assets/map/styles/`
- **Style subdirectories**: Exactly 30 canonical folders matching `server/world/map_style_catalog.py` and `data/map_styles.db`:
  - `sty_01_hoang_mang_co_lo` through `sty_30_tan_tich_thien_cung_hoang_phe`.
- **Files per folder**:
  - 9 root textures: `floor.png`, `floor_normal.png`, `wall.png`, `wall_normal.png`, `path.png`, `path_normal.png`, `liquid.png`, `liquid_normal.png`, `props.png`.
  - 1 `props/` subdirectory containing 3 individual prop sprites: `<prop_id>.png`.
- **Total file count**: $30 \times (9 + 3) = 360$ PNG files verified on disk.
- **Dimensional compliance**:
  - `floor.png`, `floor_normal.png`: $128 \times 64\text{ px}$ (RGBA)
  - `wall.png`, `wall_normal.png`: $128 \times 128\text{ px}$ (RGBA)
  - `path.png`, `path_normal.png`: $128 \times 64\text{ px}$ (RGBA)
  - `liquid.png`, `liquid_normal.png`: $128 \times 64\text{ px}$ (RGBA)
  - `props.png`: $192 \times 64\text{ px}$ (RGBA)
  - `props/*.png`: $64 \times 64\text{ px}$ (RGBA)
- **Size budget**:
  - Max single tile file size: 12,457 bytes ($12.17\text{ KB} < 50\text{ KB}$ limit).
  - Total styles folder size: 1,642,193 bytes ($1.57\text{ MB} < 6.0\text{ MB}$ budget).

### 1.2. Statistical Texture Authenticity & Entropy
Empirical pixel analysis executed across all 360 PNG files yielded:
- **Shannon entropy on visible pixels** ($\alpha > 0$):
  - Overall: $\text{min} = 2.172\text{ bits}$, $\text{mean} = 4.219\text{ bits}$, $\text{max} = 6.606\text{ bits}$.
  - Zero files with $0.0\text{ bits}$ entropy (no solid color fills, no 1x1 dummy stubs, no blank images).
- **RGB Standard Deviation & Color Richness**:
  - `floor.png` (N=30): Entropy [3.71 - 5.80] (mean 4.82) | Unique Colors: [38 - 168] (mean 97.0) | RGB Std: [5.70 - 20.38]
  - `wall.png` (N=30): Entropy [3.27 - 5.09] (mean 4.38) | Unique Colors: [23 - 64] (mean 42.7) | RGB Std: [8.30 - 12.01]
  - `path.png` (N=30): Entropy [4.78 - 6.05] (mean 5.40) | Unique Colors: [60 - 199] (mean 139.6) | RGB Std: [28.78 - 32.39]
  - `liquid.png` (N=30): Entropy [2.68 - 5.80] (mean 4.75) | Unique Colors: [9 - 92] (mean 44.2) | RGB Std: [7.65 - 64.17]
  - `props.png` (N=30): Entropy [2.22 - 4.07] (mean 3.44) | Unique Colors: [4 - 16] (mean 9.5) | RGB Std: [46.95 - 96.33]
  - `props/*.png` (N=90): Entropy [2.17 - 3.31] (mean 2.79) | Unique Colors: [4 - 6] (mean 4.8) | RGB Std: [35.82 - 96.33]
- **Cross-Biome SHA-256 Uniqueness**:
  - Checked SHA-256 hash collision across all 30 styles:
    - `floor.png`: 30 distinct hashes (100% unique, 0 duplicates).
    - `wall.png`: 30 distinct hashes (100% unique, 0 duplicates).
    - `path.png`: 30 distinct hashes (100% unique, 0 duplicates).
    - `liquid.png`: 30 distinct hashes (100% unique, 0 duplicates).
    - `props.png`: 30 distinct hashes (100% unique, 0 duplicates).

### 1.3. Normal Map Surface Gradients vs Flat Blue Planes
Vectorized gradient audit across all 120 normal map files (`*_normal.png`):
- **$R$ standard deviation** ($d/dx$ slope): $\text{min} = 6.80$, $\text{mean} = 19.91$, $\text{max} = 39.93$ (expected $> 1.0$; flat plane has $0.0$).
- **$G$ standard deviation** ($d/dy$ slope): $\text{min} = 15.46$, $\text{mean} = 28.16$, $\text{max} = 40.11$ (expected $> 1.0$; flat plane has $0.0$).
- **$B$ mean** ($Z$-component towards viewer): $\text{min} = 238.01$, $\text{mean} = 247.91$, $\text{max} = 253.13$ (strictly $> 128.0$).
- **Non-flat pixel percentage** ($|R - 128| > 2$ or $|G - 128| > 2$): $\text{min} = 31.29\%$, $\text{mean} = 68.13\%$, $\text{max} = 98.15\%$.
- **Unique normal vectors per tile**: $\text{min} = 156$, $\text{mean} = 1,051.2$, $\text{max} = 2,219$.
- **Finding**: Normal maps are genuine $3\times 3$ Sobel tangent-space gradient encodings, definitely NOT flat blue planes $(128, 128, 255)$.

### 1.4. Procedural Algorithm Authenticity & Deterministic Reproducibility
- Inspected `tools/asset_pipeline/generate_30_map_styles_assets.py` (307 lines):
  - Uses `generate_noise_map` (lines 45-59): 3-octave harmonic sine/cosine field with phase offsets and frequency modulation.
  - Uses `generate_cellular_cracks` (lines 61-72): Worley distance edge cracking ($F_2 - F_1$).
  - Modulates hex palettes with mathematical noise, masonry brick coursing, vertical ambient occlusion shading, rivet circles, trail wear curves, and wave harmonic arcs.
  - No external dummy image template reading or static file copying.
- **Reproducibility Stress-Test**:
  - Re-executed `generate_all_30_styles(output_root=tmp_path)` in a fresh `tempfile.TemporaryDirectory()`.
  - Byte-by-byte SHA-256 comparison across all 360 files:
    - Total files checked: 360.
    - Mismatches: 0.
    - Result: 100% bit-for-bit identical deterministic regeneration.

### 1.5. Code Hygiene & Standards Compliance
- Line lengths:
  - `tools/asset_pipeline/generate_30_map_styles_assets.py`: 307 lines ($\le 350$ Soft Cap, $\le 500$ Hard Cap).
  - `tools/asset_pipeline/m4_normal_utils.py`: 48 lines ($\le 350$ Soft Cap, $\le 500$ Hard Cap).
  - All functions/methods $\le 50$ lines.
- Lint script execution:
  - `python tools/lint/check_code_and_doc_hygiene.py --strict` exited with return code 0 (0 Hard Cap violations).

### 1.6. Automated Unit & E2E Test Suite Results
- `pytest tests/unit/test_map_style_assets_integrity.py -v`:
  - 249 passed in 1.15s (100% pass).
- `pytest tests/unit/test_map_styles_db.py tests/unit/test_map_styles_catalog_sync.py tests/unit/test_map_styles_adversarial.py -v`:
  - 335 passed in 6.05s (100% pass).
- `pytest tests/e2e/test_asset_campaign_and_pipeline_e2e.py tests/unit/test_asset_pipeline_tools.py -v`:
  - 37 passed in 41.02s (100% pass).

---

## 2. Logic Chain

1. **Authenticity & Anti-Cheating**:
   - Observation 1.2 proves that all 360 files have significant Shannon entropy (mean 4.22 bits, min 2.17 bits) and large numbers of unique colors (up to 199/tile), eliminating the possibility of 1x1 stubs or solid single-color fills.
   - Observation 1.2 proves that all 30 styles have unique SHA-256 hashes for each tile type, eliminating the possibility of copy-pasting a single template across styles.
   - Observation 1.3 proves that all 120 normal maps exhibit strong $R$ and $G$ variation ($\sigma_R \ge 6.80$, $\sigma_G \ge 15.46$, non-flat pixels up to 98.15%), proving genuine tangent-space relief rather than flat blue planes.
   - Observation 1.4 proves that `generate_30_map_styles_assets.py` executes genuine procedural algorithms (harmonic sine noise, Worley cellular distance cracking) and reproduces all 360 files bit-for-bit deterministically without relying on third-party dummy files.

2. **Standards & Hygiene**:
   - Observation 1.5 confirms that the asset generator script is 307 lines, well below the 350-line soft cap, and `check_code_and_doc_hygiene.py --strict` completed with 0 hard cap violations.

3. **Functionality & Quality**:
   - Observation 1.6 demonstrates that all existing and new integrity test suites (621 automated tests across unit and E2E tiers) pass cleanly.

---

## 3. Caveats

- **No Caveats**: The audit covered 100% of the 360 asset files, the entire procedural generation pipeline, and full test suite execution without sampling shortcuts or unverified assumptions.

---

## 4. Conclusion

**Verdict: CLEAN**

Milestone 2 (Asset Pipeline: 30 Dark Fantasy Map Styles) fully satisfies all requirements of `ORIGINAL_REQUEST.md` (§ 2026-10-02T02:00:04Z) and the orchestrator dispatch. The assets are authentic, high-entropy, procedurally generated, and equipped with valid tangent-space normal maps. No integrity violations or shortcuts were found.

---

## 5. Verification Method

To independently reproduce and verify this audit:

1. **Verify Asset Completeness, Non-Zero Entropy, and Normal Map Gradients**:
   ```bash
   python -c "
   from pathlib import Path
   from PIL import Image
   import numpy as np

   base = Path('client/webapp/assets/map/styles')
   styles = sorted([d for d in base.iterdir() if d.is_dir()])
   assert len(styles) == 30
   total = 0
   for s in styles:
       for f in ['floor.png', 'floor_normal.png', 'wall.png', 'wall_normal.png', 'path.png', 'path_normal.png', 'liquid.png', 'liquid_normal.png', 'props.png']:
           p = s / f
           assert p.is_file()
           total += 1
           with Image.open(p) as img:
               arr = np.array(img)
               vis = arr[arr[:, :, 3] > 0][:, :3].flatten()
               counts = np.bincount(vis, minlength=256)
               probs = counts[counts > 0] / len(vis)
               ent = -np.sum(probs * np.log2(probs))
               assert ent > 2.0, f'Low entropy {ent} in {p}'
               if 'normal' in f:
                   assert float(arr[arr[:, :, 3] > 0, 2].mean()) > 128.0
                   assert float(arr[arr[:, :, 3] > 0, 0].std()) > 5.0
       for pf in (s / 'props').glob('*.png'):
           assert pf.is_file()
           total += 1
   assert total == 360
   print(f'ALL {total} FILES VERIFIED AUTHENTIC WITH HIGH ENTROPY AND GRADIENTS')
   "
   ```

2. **Verify Code Hygiene**:
   ```bash
   python tools/lint/check_code_and_doc_hygiene.py --strict
   ```

3. **Verify Asset Integrity Test Suite**:
   ```bash
   pytest tests/unit/test_map_style_assets_integrity.py -v
   ```
