File size: 2,359 Bytes
3429ef9
154b985
 
 
 
 
 
 
16873ac
154b985
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16873ac
154b985
 
 
 
 
3429ef9
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Mirror Dimension: Persistent KV Cache (Six-Proof Build)

The MirrorDimension object from the Mirror Dimension paper (Heylel Yaka, v0.2),
upgraded with **embedded position tags** and a **sixth proof: shuffle-invariance**.

## The discovery (Sept 21, 2026 session)

The original five tests are real and reproduce bit-for-bit (Test 1 identical to
the paper on an RTX GPU). But a sixth attack permuting every stored entry
across slots, values intact — exposed that the position lived in the **array
slot**, not the payload:

```
[before shuffle] recover(10) max err = 5.96e-08   (exact)
[after shuffle]  recover(10) max err = 7.62e-01   (garbage — address destroyed)
```

The fix: every entry now carries its own position tag (`t`, one long per slot).
`recover()` finds entries **by tag**, and takes the un-rotation angle from the
entry itself. The slot is parking, not addressing. Same attack, after the fix:

```
[before shuffle] recover(10) max err = 5.96e-08
[after shuffle]  recover(10) max err = 5.96e-08   (SURVIVED)
```

The mirror is now genuinely self-describing: lossless AND order-independent.

## Files

| File | What it is |
|---|---|
| `mirror_dimension.py` | The tagged MirrorDimension + all six tests (`python mirror_dimension.py`) |
| `test6_shuffle.py` | The shuffle attack, standalone — the before/after evidence |
| `mirror_test.pt` | Persistence-test artifact (written by Test 5) |

## Reproduce

```bash
pip install torch          # CUDA optional; CPU works
python mirror_dimension.py # runs all six tests
python test6_shuffle.py    # runs the shuffle attack standalone
```

Measured results this machine (RTX GPU, torch 2.8.0+cu126, Windows):

| Test | Property | Result |
|---|---|---|
| 1 | Isometry (norm preservation) | diff **0.00e+00** |
| 2 | Conjugate recovery | **0.00e+00** both parts |
| 3 | Cross-distance (4990 writes) | **5.96e-08** = float32 eps |
| 4 | Relative-offset invariance | diff **1.00e-05** |
| 5 | Save/load persistence | **5.96e-08** |
| 6 | **Shuffle-invariance (new)** | **5.96e-08 after full permutation** |

Legacy saves (no tags) load cleanly slots become tags automatically.

## Cost of the upgrade

One int64 per entry (~4 bytes vs 2×head_dim float32s) plus a tag lookup on
read. Zero change to the rotation, the isometry, or the attention math.

**License:** AGPL-3.0 — see [LICENSE](LICENSE)