{"id":"XE-0109","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"161","source_url":"https://github.com/xeprotocol/xe/issues/161","reporter_id":35,"title":"node: a gossiped vote for a conflict that does not exist is persisted forever — unbounded vote-store and mutex growth from one peer","area":"consensus","claimed_tier":"high","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T13:57:28.223330+00:00","updated_at":"2026-11-10T00:11:47.718685+00:00","source_created_at":"2026-10-29T02:53:40+00:00","told_at":"2026-11-08T19:34:05+00:00","status_changed_at":"2026-11-08T19:33:40.894987+00:00","url":"https://bounty.xe.network/XE-0109","body":"**Suggested tier:** High (10,000 XE) — remote, persistent, unbounded resource growth; the\nbounded buffer the code intends for this case is unreachable.\n**Repo pin:** `978785929bc17a2f4ab30c383e5fc9cf4d634512` (testnet-0005)\n**Area:** `net/gossip_validate.go` → `core/vote.go` → `store`\n\n## Summary\n\n`ReceiveVote` validates a vote and, if it is valid, writes it to the persistent vote store and\nallocates a per-position mutex. Validation checks signature, vote weight and timestamp — **it\nnever checks that the conflict position the vote names actually exists**. The design clearly\nintends those votes to be held in a small bounded buffer instead: `bufferVote` caps at\n`maxPendingVotesPerConflict` per `(account, previous)` key — but that path only runs when\n`ValidateVote` *fails*, and a well-formed vote for a non-existent position does not fail.\n\nResult: one peer with any positive vote weight can name arbitrary `(account, previous)` pairs,\nand every vote becomes a permanent store row plus a permanent mutex. Nothing reclaims either\nunless a conflict for that exact position later appears and resolves. There is no global cap\nand no TTL, and Badger rows survive restart.\n\n## Where\n\n`core/vote.go:107-132` — the branch that makes the bounded path unreachable:\n\n```go\nfunc (vm *VoteManager) ReceiveVote(v *Vote) error {\n\tif err := vm.ValidateVote(v); err != nil {\n\t\tif vm.isConflictNotFound(v) {\n\t\t\tvm.bufferVote(v)      // bounded 10-per-key buffer\n\t\t\treturn nil\n\t\t}\n\t\treturn err\n\t}\n\n\tmu := vm.conflictLock(v.ConflictAccount, v.ConflictPrev)   // allocates per attacker-chosen key\n\tmu.Lock()\n\tdefer mu.Unlock()\n\n\tif vm.positionResolved(v.ConflictAccount, v.ConflictPrev) {\n\t\tvm.reaffirmFromState(v.ConflictAccount, v.ConflictPrev)\n\t\treturn nil\n\t}\n\n\tif err := vm.receiveVoteInner(v); err != nil {   // -> store.PutVote, unconditional\n\t\treturn err\n\t}\n\n\tvm.castVoteLocked(v.ConflictAccount, v.ConflictPrev)\n\treturn nil\n}\n```\n\n`ValidateVote` (`core/vote.go:225-260`) checks exactly three things — signature, non-zero vote\nweight, and a ±5 minute timestamp window — and returns `nil` for a vote naming a position that\ndoes not exist:\n\n```go\nweight := vm.ledger.GetVoteWeight(v.RepAccount())\nif weight.Sign() <= 0 {\n\treturn fmt.Errorf(\"ValidateVote: representative %s has zero vote weight\", v.RepPubKey[:8])\n}\n...\nif delta > voteWindowNanos {\n\treturn fmt.Errorf(\"ValidateVote: timestamp out of range: delta=%v\", time.Duration(delta))\n}\nreturn nil\n```\n\n`receiveVoteInner` then persists it without any existence check (`core/vote.go:134-165`):\n\n```go\nif err := vm.store.PutVote(v); err != nil {\n\treturn err\n}\n```\n\nand `conflictLock` (`core/vote.go:48`) adds one mutex per distinct `|`-joined key:\n\n```go\nfunc (vm *VoteManager) conflictLock(account, prev string) *sync.Mutex {\n```\n\n## Reproduction\n\nThe PoC drives the real `core.VoteManager` over the real Badger store; the gossip-side\nvalidator is exercised separately to show the vote is accepted on the wire.\n\n```bash\ncd /root/xe-audit/poc-D\nnice -n 15 taskset -c 0-1 go test ./audit/ ./net/ -run \"TestD1\" -count=1 -v\n```\n\nObserved (`poc-D/observed-D.log`):\n\n```\nd1_vote_buffer_test.go:92: ReceiveVote accepted 20000/20000 votes for non-existent conflicts\nd1_vote_buffer_test.go:93: distinct (account|previous) positions written to the vote store: 20000\nd1_vote_buffer_test.go:94: conflict-key mutexes retained in VoteManager.conflictMu: 20000\nd1_vote_buffer_test.go:99: pendingVotes (the bounded 10-per-key buffer): 0 keys, 0 votes\nd1_vote_buffer_test.go:100: heap: 0.6 MiB -> 21.3 MiB (+20.67 MiB retained after GC)\nd1_vote_buffer_test.go:115: sample: GetVote(000000000000..., 000000000000...) returned a stored FINAL vote\nd1_vote_buffer_test.go:123: RESULT: 20000 permanent vote-store records and 20000 permanent mutexes from one peer\n\nnet/zz_d1_validator_test.go:57: vote for conflict (111111111111…, 222222222222…) → ValidationResult 0 (ValidationAccept == 0)\nnet/zz_d1_validator_test.go:68: same vote with a rewritten ConflictPrev → 1 (rejected as expected)\n```\n\nThe last two lines matter: the gossip validator accepts the vote as published (only signature\nshape and signature validity are checked on that path), so it reaches `ReceiveVote` on every\nnode that receives it.\n\n## Impact\n\n- **Unbounded, persistent state growth on every node**, driven by one peer: 20,000 votes cost\n  +20.7 MiB heap and 20,000 Badger rows for 494-byte messages, and both scale linearly with\n  attacker input. Badger rows survive restart, so the growth is not self-healing.\n- **No cap and no TTL.** `bufferVote`'s `maxPendingVotesPerConflict` limit is dead for this\n  input class — the bounded map stays empty (0 keys) while the store and mutex map grow.\n- **Entry cost is dust.** The signer needs a representative key with non-zero vote weight\n  (`GetVoteWeight > 0`); an account that delegates a micro-XE to itself qualifies. The PoC used\n  the genesis representative's weight, but any funded account can self-delegate.\n- Every receiving node pays, not just the direct peer: the vote is gossiped and passes each\n  node's validator.\n\n## Why this is not a duplicate\n\nChecked against all 155 issues/PRs at the time of writing (`dupe_check.py`):\n\n- **#46** is the closest, and it is a different mechanism: its votes are *zero-weight* and are\n  **rejected later** in the vote manager — the harm there is occupying a slot in the 1024-deep\n  gossip channel so honest CONVERGE votes drop. Here the votes **pass** `ValidateVote`, are\n  written to the store, allocate a mutex, and persist forever. Different input class, different\n  sink, different impact.\n- **#95 / #107** are about vote *weight* being counted from a stale receipt-time snapshot during\n  conflict resolution — no persistence angle.\n- **#8 §1** covers vote hex case-malleability, quorum forgery and *replay of stale* votes, not\n  unbounded insertion of new positions.\n- **#51** is the DAO's process-local replay cache, unrelated.\n\n## Suggested fix\n\n1. In `ValidateVote` (or immediately before `PutVote`), require the position to exist:\n   `conflict := vm.ledger.GetConflict(v.ConflictAccount, v.ConflictPrev); if conflict == nil { buffer or drop }`.\n   That is what `isConflictNotFound` was written for; it just is not consulted on the valid path.\n2. Make `bufferVote`'s bound the only way to hold a vote for an unknown position, and bound the\n   number of distinct positions too (per-rep and global), with expiry.\n3. In `conflictLock`, cap the map (LRU) or key it by an existing conflict only, so a mutex cannot\n   be allocated for an arbitrary string pair.\n4. Consider refusing votes for positions that are already resolved and unlikely to reappear\n   (the `positionResolved` path already partly does this, but only after the lock is allocated).\n\n## Notes\n\nSource-level only: no traffic to testnet-0005, no accounts, no live node; PoC runs offline\nagainst the pinned tree. Test tree `/root/xe-audit/poc-D` (6/6 pass); only test-only additions\n(`core/zz_audit_shim.go` accessors plus a vote signer), no production logic changed.","patch_refs":[{"id":183,"repo":"xeprotocol/xe","kind":"pr","ref":"188","title":"core: bound vote buffer and do not persist votes for absent conflicts (#161)","url":"https://github.com/xeprotocol/xe/pull/188","note":"","state":"open","author":"fangjian-bit","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"}],"thread":[{"id":51,"source":"github","source_ref":"6494146814","author":"fangjian-bit","team":false,"body":"I have investigated and resolved this issue in PR #188.\n\n### Forensic Summary\n1. **Root Cause**: `ValidateVote` only checked cryptographic signatures, weight, and timestamp windows, so votes for non-existent conflicts bypassed the `isConflictNotFound` buffer logic. This led directly to permanent `*sync.Mutex` allocations in `conflictMu` and permanent row creation in Badger store (`store.PutVote`).\n2. **Mitigation**:\n   - `ReceiveVote` enforces strict admission checks against `ledger.GetConflict(...)`, immediately routing absent conflicts to `bufferVote` without acquiring locks or calling `store.PutVote`.\n   - `pendingVotes` buffer is bounded with a global hard cap (`maxPendingConflicts = 1024`, up to 10 votes each) and FIFO eviction. Refreshing an existing key updates timestamps but does not alter FIFO position (preventing anti-pinning attacks).\n   - Double-check and deadlock-free replay mechanisms (`flushPendingVotes`, `replayPending`) ensure vote-before-block ordering is safely accommodated once genuine conflicts arrive.\n3. **Verification**:\n   - Tested under Go 1.27.3 with race detector enabled (`go test -v -race ./core/ -run 'TestReceiveVote' -count=1`), including 32-worker concurrent floods and eviction verification (100% green).","created_at":"2026-10-29T10:25:01+00:00"},{"id":876,"source":"github","source_ref":"6726102941","author":"Joseph Denne","team":true,"body":"Thank you for the report. We have confirmed the behaviour you describe and it is being handled; we will update this ticket as the fix progresses.","created_at":"2026-11-08T19:34:05+00:00"},{"id":8950,"source":"github","source_ref":"6932492323","author":"Alfonova-Node","team":false,"body":"Status check at HEAD 89a542e (testnet-0005): the fix claimed from PR #188 is not present. PR #188 itself is still open/unmerged on GitHub. At this HEAD there is no maxPendingConflicts symbol anywhere in the codebase (grep: 0 hits), no pendingByKey/pendingFIFO FIFO buffer, and ReceiveVote (core/vote.go:107) still persists well-formed votes for non-existent conflicts because ValidateVote (core/vote.go:225) never checks that the conflict exists — bufferVote remains reachable only when validation fails. Only the per-conflict cap maxPendingVotesPerConflict = 10 (core/vote.go:13) is present, with no global cap on distinct conflict keys, and conflictMu entries are never deleted. Requesting the ticket stay open until the PR (or an equivalent fix) lands at HEAD.","created_at":"2026-11-16T23:26:29+00:00"}]}