CLI Self-Fork Race Condition: cmdReceive loops multiple pending blocks without frontier propagation creating intra-account conflicts
Report
Vulnerability Summary
In cmd/xe/main.go:747-781, cmdReceive() loops over unreceived pending transfers to construct and submit BlockReceive transactions:
fmt.Printf("Receiving %d pending send(s)...
", len(pending))
for _, p := range pending {
chain, _ := c.GetChain(addr)
bals, _ := c.GetBalances(addr)
prev := "0"
if len(chain) > 0 {
prev = chain[len(chain)-1].Hash
}
b := &core.Block{
Type: core.BlockReceive,
Account: addr,
Previous: prev,
Balance: bals[p.Asset] + p.Amount,
Timestamp: time.Now().UnixNano(),
Asset: p.Asset,
Source: p.SendHash,
}
...
if err := c.SubmitBlock(b, "receive"); err != nil {
fmt.Fprintf(os.Stderr, " skip %s: %v
", shortHash(p.SendHash), err)
continue
}
When an account has multiple pending transfers (len(pending) > 1), cmdReceive() processes them in rapid succession. On iteration 0, block $B_0$ is submitted to the node.
Because c.SubmitBlock returns before the network or local store propagates the new frontier block, iteration 1 immediately queries c.GetChain(addr) and c.GetBalances(addr). The node's store has not yet committed $B_0$ or updated chain[len(chain)-1].
As a result:
- Iteration 1 receives the exact same frontier
prevand the exact same stalebals[p.Asset]. - Iteration 1 generates block $B_1$ pointing to the same
Previous: prevas $B_0$. - Two blocks with identical
Previoushashes are broadcast to the network for the same account.
Impact & Severity
- Account Deadlock: Emitting two blocks with the same
Previouspointer triggers an immediate fork conflict (core.ErrForkDetected) on the user's own lattice account. - Quorum Lockout: The account's chain is frozen into conflict arbitration in
core.QuorumManager, blocking subsequent receives and sends until external representatives cast votes. - Balance Corruption: Stale balance computation in subsequent iterations leads to consensus rejection with
balance mismatch.
Proposed Remediation
In cmdReceive(), track local frontier state and balance offsets in-memory across loop iterations:
currentPrev := prev
currentBalances := bals
for _, p := range pending {
b := &core.Block{
Type: core.BlockReceive,
Account: addr,
Previous: currentPrev,
Balance: currentBalances[p.Asset] + p.Amount,
...
}
...
currentPrev = b.Hash
currentBalances[p.Asset] += p.Amount
}
Thread
Thanks for the report. We read it against the code and could not confirm a bug in what it describes.
This report is closed as invalid. If we have missed something, file a new report that links https://bounty.xe.network/XE-10033 and says what; it is read like any other.