<!-- XE-0258 · statechain: transition validation reads the pre-block snapshot, so one block can break its own monotonic invariants · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0258>. The page is the record; this is the same page for reading.*

XE-0258 · Bounty

# statechain: transition validation reads the pre-block snapshot, so one block can break its own monotonic invariants

Triaging
[xe#241](https://github.com/xeprotocol/xe/issues/241)
filed 2026-11-02 21:17 UTC
by hayokakoweda75

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   —

Area
:   DAO harness

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-08 20:17 UTC

Told
:   2026-11-08 20:18 UTC

### Patches

None linked.

### History

- [43803](https://bounty.xe.network/log/43803) 2026-11-08 20:19 UTC reply.mirror\_failed
- [43335](https://bounty.xe.network/log/43335) 2026-11-08 20:18 UTC proposal.adopted
- [43334](https://bounty.xe.network/log/43334) 2026-11-08 20:18 UTC reply.sent
- [40215](https://bounty.xe.network/log/40215) 2026-11-08 20:17 UTC proposal.adopted
- [40214](https://bounty.xe.network/log/40214) 2026-11-08 20:17 UTC ticket.facts area
- [40213](https://bounty.xe.network/log/40213) 2026-11-08 20:17 UTC proposal.adopted
- [40212](https://bounty.xe.network/log/40212) 2026-11-08 20:17 UTC ticket.facts
- [40211](https://bounty.xe.network/log/40211) 2026-11-08 20:17 UTC proposal.adopted
- [40210](https://bounty.xe.network/log/40210) 2026-11-08 20:17 UTC ticket.facts
- [40209](https://bounty.xe.network/log/40209) 2026-11-08 20:17 UTC proposal.adopted
- [40208](https://bounty.xe.network/log/40208) 2026-11-08 20:17 UTC ticket.facts
- [40207](https://bounty.xe.network/log/40207) 2026-11-08 20:17 UTC proposal.adopted

[Full history](https://bounty.xe.network/log?ref=XE-0258) · [JSON](https://bounty.xe.network/v1/tickets/XE-0258) · [markdown](https://bounty.xe.network/XE-0258.md)

### Report

## Ringkas

Validator transisi memeriksa setiap op terhadap KV **pra-blok**, sedangkan op baru diterapkan sekali di akhir. Dua op yang menyentuh kunci sama dalam satu blok karena itu sama-sama lolos validasi terhadap nilai lama, sehingga blok yang sah secara tanda tangan bisa melanggar invariant yang ditegakkan validator itu sendiri.

## Akar

`statechain/chain.go:168` — loop validasi:

```
for _, op := range b.Ops {
    if err := ValidateOp(op); err != nil { return err }
    if err := validateTransition(c.kv, c.tip, b, op); err != nil { return err }
}
...
c.kv.ApplyOps(b.Ops)   // chain.go:210, sekali di akhir
```

`validateTransition` membaca `c.kv`, yang belum memuat op sebelumnya pada blok yang sama. Aturan yang jadi korban:

- `statechain/activations.go:191` — "the floor only rises": `CompareProtocolVersion(newV, oldV) < 0` dibandingkan ke nilai tersimpan, bukan ke op sebelumnya dalam blok.
- `statechain/activations.go:121` — "feature cannot be removed (activations are one-directional)".
- `statechain/chain.go:181-183` — kunci epoch write-once: `if _, exists := c.kv.Get(op.Key); exists` juga membaca snapshot lama, jadi dua op `epoch.N` dalam satu blok sama-sama diterima dan yang terakhir menang.

## Reproduksi

```
go test ./statechain/ -run 'TestAuditIntraBlock' -v
```

Pada `9787859`:

```
--- FAIL: TestAuditIntraBlockDuplicateKeyLowersProtocolFloor
    protocol floor regressed inside one block: got "1.5.0", want 2.0.0 (both ops were validated against the stale pre-block value)
--- FAIL: TestAuditIntraBlockActivationsDropFeature
    feat_b, declared and accepted by block 2, vanished from state; activations are supposed to be one-directional
--- PASS: TestAuditIntraBlockEpochWriteOnceBypass   (karakterisasi: write-once dilewati, last-write-wins)
```

Blok `[set sys.min_protocol_version 2.0.0, set 1.5.0]` diterima; blok `[set activations{a,b}, set activations{a}]` diterima dan `feat_b` hilang.

## Dampak

`MinProtocolVersion()` memasok gerbang versi peer (`node/activations.go:126` → `net/netcheck.go:409,465`). Satu blok DAO ber-tanda-tangan sah bisa menurunkan lantai yang baru ia umumkan, sehingga peer versi lama di bawah lantai diizinkan lagi masuk gossip; atau membuang aktivasi fitur yang baru dinyatakan.

Lebih buruk: `replay()` memakai `applyValidated` (`chain.go:77-79`) tanpa `ValidateOp`/`validateTransition`, jadi saat node restart hasil yang melanggar invariant tidak divalidasi ulang — semua node sepakat pada state bengkok, permanen di history.

## Saran perbaikan

Validasi terhadap state yang sudah memuat op sebelumnya (overlay per blok, atau `ApplyOps` per op di dalam loop dengan rollback bila ada yang gagal), dan jalankan ulang `validateTransition` pada `replay()`.

### Thread

**hayokakoweda75**2026-11-02 21:33 UTCgithub

Tracked privately on the bounty desk as **XE-0262** — same defect, verified with the same PoC. Filing here too so the evidence stays public.

**Joseph Denne**team2026-11-08 20:17 UTCdesk

Thanks for the report. We have confirmed the behaviour you describe in statechain block validation and it is being handled; we will update https://bounty.xe.network/XE-0258 when there is a fix to point at.
