Bounty
XE-0109 · Bounty

node: a gossiped vote for a conflict that does not exist is persisted forever — unbounded vote-store and mutex growth from one peer

Triaging claimed High xe#161 filed 2026-10-29 02:53 UTC by memekomik

Report

Suggested tier: High (10,000 XE) — remote, persistent, unbounded resource growth; the bounded buffer the code intends for this case is unreachable. Repo pin: 978785929bc17a2f4ab30c383e5fc9cf4d634512 (testnet-0005) Area: net/gossip_validate.go → core/vote.go → store

Summary

ReceiveVote validates a vote and, if it is valid, writes it to the persistent vote store and allocates a per-position mutex. Validation checks signature, vote weight and timestamp — it never checks that the conflict position the vote names actually exists. The design clearly intends those votes to be held in a small bounded buffer instead: bufferVote caps at maxPendingVotesPerConflict per (account, previous) key — but that path only runs when ValidateVote fails, and a well-formed vote for a non-existent position does not fail.

Result: one peer with any positive vote weight can name arbitrary (account, previous) pairs, and every vote becomes a permanent store row plus a permanent mutex. Nothing reclaims either unless a conflict for that exact position later appears and resolves. There is no global cap and no TTL, and Badger rows survive restart.

Where

core/vote.go:107-132 — the branch that makes the bounded path unreachable:

func (vm *VoteManager) ReceiveVote(v *Vote) error {
	if err := vm.ValidateVote(v); err != nil {
		if vm.isConflictNotFound(v) {
			vm.bufferVote(v)      // bounded 10-per-key buffer
			return nil
		}
		return err
	}

	mu := vm.conflictLock(v.ConflictAccount, v.ConflictPrev)   // allocates per attacker-chosen key
	mu.Lock()
	defer mu.Unlock()

	if vm.positionResolved(v.ConflictAccount, v.ConflictPrev) {
		vm.reaffirmFromState(v.ConflictAccount, v.ConflictPrev)
		return nil
	}

	if err := vm.receiveVoteInner(v); err != nil {   // -> store.PutVote, unconditional
		return err
	}

	vm.castVoteLocked(v.ConflictAccount, v.ConflictPrev)
	return nil
}

ValidateVote (core/vote.go:225-260) checks exactly three things — signature, non-zero vote weight, and a ±5 minute timestamp window — and returns nil for a vote naming a position that does not exist:

weight := vm.ledger.GetVoteWeight(v.RepAccount())
if weight.Sign() <= 0 {
	return fmt.Errorf("ValidateVote: representative %s has zero vote weight", v.RepPubKey[:8])
}
...
if delta > voteWindowNanos {
	return fmt.Errorf("ValidateVote: timestamp out of range: delta=%v", time.Duration(delta))
}
return nil

receiveVoteInner then persists it without any existence check (core/vote.go:134-165):

if err := vm.store.PutVote(v); err != nil {
	return err
}

and conflictLock (core/vote.go:48) adds one mutex per distinct |-joined key:

func (vm *VoteManager) conflictLock(account, prev string) *sync.Mutex {

Reproduction

The PoC drives the real core.VoteManager over the real Badger store; the gossip-side validator is exercised separately to show the vote is accepted on the wire.

cd /root/xe-audit/poc-D
nice -n 15 taskset -c 0-1 go test ./audit/ ./net/ -run "TestD1" -count=1 -v

Observed (poc-D/observed-D.log):

d1_vote_buffer_test.go:92: ReceiveVote accepted 20000/20000 votes for non-existent conflicts
d1_vote_buffer_test.go:93: distinct (account|previous) positions written to the vote store: 20000
d1_vote_buffer_test.go:94: conflict-key mutexes retained in VoteManager.conflictMu: 20000
d1_vote_buffer_test.go:99: pendingVotes (the bounded 10-per-key buffer): 0 keys, 0 votes
d1_vote_buffer_test.go:100: heap: 0.6 MiB -> 21.3 MiB (+20.67 MiB retained after GC)
d1_vote_buffer_test.go:115: sample: GetVote(000000000000..., 000000000000...) returned a stored FINAL vote
d1_vote_buffer_test.go:123: RESULT: 20000 permanent vote-store records and 20000 permanent mutexes from one peer

net/zz_d1_validator_test.go:57: vote for conflict (111111111111…, 222222222222…) → ValidationResult 0 (ValidationAccept == 0)
net/zz_d1_validator_test.go:68: same vote with a rewritten ConflictPrev → 1 (rejected as expected)

The last two lines matter: the gossip validator accepts the vote as published (only signature shape and signature validity are checked on that path), so it reaches ReceiveVote on every node that receives it.

Impact

  • Unbounded, persistent state growth on every node, driven by one peer: 20,000 votes cost +20.7 MiB heap and 20,000 Badger rows for 494-byte messages, and both scale linearly with attacker input. Badger rows survive restart, so the growth is not self-healing.
  • No cap and no TTL. bufferVote's maxPendingVotesPerConflict limit is dead for this input class — the bounded map stays empty (0 keys) while the store and mutex map grow.
  • Entry cost is dust. The signer needs a representative key with non-zero vote weight (GetVoteWeight > 0); an account that delegates a micro-XE to itself qualifies. The PoC used the genesis representative's weight, but any funded account can self-delegate.
  • Every receiving node pays, not just the direct peer: the vote is gossiped and passes each node's validator.

Why this is not a duplicate

Checked against all 155 issues/PRs at the time of writing (dupe_check.py):

  • #46 is the closest, and it is a different mechanism: its votes are zero-weight and are rejected later in the vote manager — the harm there is occupying a slot in the 1024-deep gossip channel so honest CONVERGE votes drop. Here the votes pass ValidateVote, are written to the store, allocate a mutex, and persist forever. Different input class, different sink, different impact.
  • #95 / #107 are about vote weight being counted from a stale receipt-time snapshot during conflict resolution — no persistence angle.
  • #8 §1 covers vote hex case-malleability, quorum forgery and replay of stale votes, not unbounded insertion of new positions.
  • #51 is the DAO's process-local replay cache, unrelated.

Suggested fix

  1. In ValidateVote (or immediately before PutVote), require the position to exist: conflict := vm.ledger.GetConflict(v.ConflictAccount, v.ConflictPrev); if conflict == nil { buffer or drop }. That is what isConflictNotFound was written for; it just is not consulted on the valid path.
  2. Make bufferVote's bound the only way to hold a vote for an unknown position, and bound the number of distinct positions too (per-rep and global), with expiry.
  3. In conflictLock, cap the map (LRU) or key it by an existing conflict only, so a mutex cannot be allocated for an arbitrary string pair.
  4. Consider refusing votes for positions that are already resolved and unlikely to reappear (the positionResolved path already partly does this, but only after the lock is allocated).

Notes

Source-level only: no traffic to testnet-0005, no accounts, no live node; PoC runs offline against the pinned tree. Test tree /root/xe-audit/poc-D (6/6 pass); only test-only additions (core/zz_audit_shim.go accessors plus a vote signer), no production logic changed.

Thread

fangjian-bit2026-10-29 10:25 UTCgithub

I have investigated and resolved this issue in PR #188.

Forensic Summary

  1. 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).
  2. Mitigation:
    • ReceiveVote enforces strict admission checks against ledger.GetConflict(...), immediately routing absent conflicts to bufferVote without acquiring locks or calling store.PutVote.
    • 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).
    • Double-check and deadlock-free replay mechanisms (flushPendingVotes, replayPending) ensure vote-before-block ordering is safely accommodated once genuine conflicts arrive.
  3. Verification:
    • 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).
Joseph Denneteam2026-11-08 19:34 UTCgithub

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.

Alfonova-Node2026-11-16 23:26 UTCgithub

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.