{"id":"XE-0995","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":242,"title":"verifyBlockCredential uses unfinalized frontier keyset instead of keyset at b.Previous, and addBlock conflict staging omits BlockLeaseSettle stake refund","area":"consensus","claimed_tier":"medium","assessed_tier":"medium","verdict":"likely-valid","duplicate_of":null,"tracked":true,"internal_ref":"#1090","internal_url":"https://github.com/xeprotocol/core/issues/1090","status":"patched","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-07T04:07:22.409710+00:00","updated_at":"2026-11-18T08:09:51.799125+00:00","source_created_at":null,"told_at":"2026-11-17T16:39:19.324101+00:00","status_changed_at":"2026-11-18T08:09:51.865083+00:00","url":"https://bounty.xe.network/XE-0995","body":"Two validation defects in `core/ledger.go` cause valid sibling blocks in conflict forks to be rejected before conflict resolution can run:\n\n### 1. `verifyBlockCredential` validates sibling conflicts against the unfinalized frontier keyset (`core/ledger.go:1544-1567`)\n\nWhen a multisig account `M` has an unfinalized `multisig_update` block `B1` at height `h` that rotates its keyset from `K1` to `K2`, `B1` immediately mutates `l.keysets[M] = K2` on ingest (`core/ledger.go:1428`).\n\nIf a competing sibling block `B2` at the same height `h` (sharing `B2.Previous == B1.Previous`) arrives signed by the prior quorum `K1`, `addBlock` calls `l.verifyBlockCredential(B2)` at `core/ledger.go:804` **before** reaching the conflict fork detection at `core/ledger.go:819`:\n\n```go\nfunc (l *Ledger) verifyBlockCredential(b *Block) error {\n    ...\n    ks := l.GetKeyset(b.Account)\n    if ks != nil {\n        if len(b.Signatures) == 0 {\n            return fmt.Errorf(\"multisig account %s requires threshold signatures\", b.Account[:12])\n        }\n        return verifyMultisig(ks, hashBytes, b.Signatures)\n    }\n```\n\nBecause `l.GetKeyset(b.Account)` returns the unfinalized frontier keyset `K2` installed by `B1` rather than the keyset active at `b.Previous` (`K1`), `verifyBlockCredential(B2)` fails with an unknown/insufficient signer error and drops `B2` before `registerConflict(B1, B2)` is ever reached. Thus an unfinalized `multisig_update` cannot be contested at the same height by a sibling block signed under the keyset that was actually active at `b.Previous`.\n\n### 2. `addBlock` conflict staging `parentBalance` inline loop omits `BlockLeaseSettle` `+lease.Stake` XUSD refund (`core/ledger.go:838-869`)\n\nWhen a sibling conflict is detected at `core/ledger.go:819` (`headHash != \"\" && b.Previous != headHash`), `addBlock` reconstructs `parentBalance` and `parentAssetBalances` at `b.Previous` using an inline loop over `chain[:len(chain)-1]` (`core/ledger.go:838-869`) instead of calling `computeParentState` (`core/ledger.go:2408-2469`).\n\nWhile `computeParentState` handles `BlockLeaseSettle` (`core/ledger.go:2447-2454`) by crediting `lease.Stake` back to `assets[AssetXUSD]`, the inline loop in `addBlock` (`core/ledger.go:840-865`) only handles `BlockSend`, `BlockReceive`, `BlockMint`, `BlockBurn`, `BlockSwap`, `BlockSlashing`, `BlockEpochRewards`, and `BlockLeaseOpen`, completely omitting `BlockLeaseSettle`, `BlockLeaseAccept`, `BlockLeaseRenew`, `BlockLeaseCancel`, and `BlockLeaseForceSettle`.\n\nConsequently, if an account settles a lease (`BlockLeaseSettle`, receiving its `+lease.Stake` XUSD refund) and then has two conflicting blocks at the next height where the second block spends that refunded XUSD, `validateBlockStaged` checks `parentAssetBalances[AssetXUSD]` (`0` instead of `lease.Stake`) and rejects the valid sibling block with `insufficient XUSD balance: have 0, need ...`.\n\n### Remediation\n\n1. In `addBlock`, replace the duplicated inline `parentBalance` / `parentAssetBalances` reconstruction at `core/ledger.go:838-869` with `l.computeParentState(b.Account, chain)` (and extend `computeParentState` to include `BlockLeaseRenew`, `BlockLeaseCancel`, and `BlockLeaseForceSettle`).\n2. When `b.Previous != headHash` on a multisig account, resolve the keyset effective at `b.Previous` rather than the unfinalized tip keyset.","patch_refs":[],"thread":[{"id":1218,"source":"desk","source_ref":"reply:759","author":"Joseph Denne","team":true,"body":"Thanks for the report. We have read both parts against the current tree. The first part is being handled alongside related work already in progress. The second part refers to functions that are not present in the ledger code at head, so we could not confirm it as described. We will update this ticket when there is more to say.","created_at":"2026-11-08T20:39:23.186915+00:00"},{"id":10909,"source":"desk","source_ref":"reply:9279","author":"XE desk","team":true,"body":"Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is\nupdated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0995.","created_at":"2026-11-17T16:39:19.321112+00:00"}]}