Bounty
XE-0258 · Bounty

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

Triaging xe#241 filed 2026-11-02 21:17 UTC by hayokakoweda75

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

hayokakoweda752026-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 Denneteam2026-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.