{"id":"XE-0258","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"241","source_url":"https://github.com/xeprotocol/xe/issues/241","reporter_id":39,"title":"statechain: transition validation reads the pre-block snapshot, so one block can break its own monotonic invariants","area":"dao-harness","claimed_tier":null,"assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-02T21:17:59.152532+00:00","updated_at":"2026-11-08T20:17:41.885067+00:00","source_created_at":"2026-11-02T21:17:45+00:00","told_at":"2026-11-08T20:18:39.394875+00:00","status_changed_at":"2026-11-08T20:17:49.144817+00:00","url":"https://bounty.xe.network/XE-0258","body":"## Ringkas\n\nValidator 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.\n\n## Akar\n\n`statechain/chain.go:168` — loop validasi:\n\n```go\nfor _, op := range b.Ops {\n    if err := ValidateOp(op); err != nil { return err }\n    if err := validateTransition(c.kv, c.tip, b, op); err != nil { return err }\n}\n...\nc.kv.ApplyOps(b.Ops)   // chain.go:210, sekali di akhir\n```\n\n`validateTransition` membaca `c.kv`, yang belum memuat op sebelumnya pada blok yang sama. Aturan yang jadi korban:\n\n- `statechain/activations.go:191` — \"the floor only rises\": `CompareProtocolVersion(newV, oldV) < 0` dibandingkan ke nilai tersimpan, bukan ke op sebelumnya dalam blok.\n- `statechain/activations.go:121` — \"feature cannot be removed (activations are one-directional)\".\n- `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.\n\n## Reproduksi\n\n```\ngo test ./statechain/ -run 'TestAuditIntraBlock' -v\n```\n\nPada `9787859`:\n\n```\n--- FAIL: TestAuditIntraBlockDuplicateKeyLowersProtocolFloor\n    protocol floor regressed inside one block: got \"1.5.0\", want 2.0.0 (both ops were validated against the stale pre-block value)\n--- FAIL: TestAuditIntraBlockActivationsDropFeature\n    feat_b, declared and accepted by block 2, vanished from state; activations are supposed to be one-directional\n--- PASS: TestAuditIntraBlockEpochWriteOnceBypass   (karakterisasi: write-once dilewati, last-write-wins)\n```\n\nBlok `[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.\n\n## Dampak\n\n`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.\n\nLebih 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.\n\n## Saran perbaikan\n\nValidasi 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()`.\n","patch_refs":[],"thread":[{"id":111,"source":"github","source_ref":"6588997041","author":"hayokakoweda75","team":false,"body":"Tracked privately on the bounty desk as **XE-0262** — same defect, verified with the same PoC. Filing here too so the evidence stays public.","created_at":"2026-11-02T21:33:14+00:00"},{"id":1594,"source":"desk","source_ref":"reply:495","author":"Joseph Denne","team":true,"body":"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.","created_at":"2026-11-08T20:17:41.885067+00:00"}]}