Files
consensus/engine/chain/zz_refute_authvote_nonvalidator_test.go
zeekayandHanzo Dev bba3234534 consensus: a quorum of zero is not a quorum
The chain engine decides on `acceptVotes() >= alpha`, so alpha=0 makes that
predicate hold over an EMPTY accept set. Any arriving vote — including one
AGAINST the block — then marks it accepted with zero accept votes, and Poll's
`rejectVotes() >= alpha` fires on nothing too, rejecting every fresh block and
dropping it from the tips. Two partitioned nodes could settle different blocks
at the same height with no quorum and no cert.

alpha=0 was reachable because Config.Validate had no callers — New,
NewWithConfig, NewWithParams and NewRuntime all reached NewChainConsensus
unchecked — and because Parameters.Valid gated its alpha checks behind
`AlphaPreference != 0`. The one value that destroys safety was the one value
that skipped validation.

Three independent layers close it, each judged by ONE definition of a safe
quorum:

  - config.Parameters.ValidQuorum, split out of Valid, judges K and the two
    integer alphas: 1 <= alpha <= K (unconditional now), AlphaConfidence >=
    AlphaPreference (never enforced before, so preference=15/confidence=1
    passed), and the Byzantine overlap floor, also unconditional. Valid calls
    it, so the two cannot drift. The split lets the engine demand SAFETY
    without also demanding the descriptive Alpha ratio and block timings,
    which have no bearing on whether a quorum can fork.

  - Transitive.Start refuses to run unsafe parameters. The check belongs here,
    not in the constructors: options are applied AFTER config, so WithParams
    can replace params a constructor already validated. Start is the one point
    every engine passes through with its final parameters.

  - NewChainConsensus, the single place the running predicate is armed, pins
    (k, alpha) into k >= 1, 1 <= alpha <= k. A path that skips both checks
    still cannot arm a predicate satisfiable by nothing.

Reclamp gains the safety floor as well. It installs a quorum on a LIVE engine
from a DERIVED validator count, and used to accept any well-formed alpha —
including k=4/alpha=2, where two disjoint quorums overlap in nothing. The
supermajority the committee sizer derives clears the floor at every k, so no
legitimate re-clamp is refused.

Fixtures that encoded unsafe quorums are corrected rather than exempted.
params5 was K=5/alpha=3: two 3-of-5 quorums overlap in a SINGLE node, so one
faulty validator (f=1 at K=5) can certify both sides of a fork. It is now
K=5/alpha=4 — the Byzantine floor, and what FeasibleParams(Local, 5) derives
for the live nets — which makes params5Prod an exact duplicate, so it goes.
Two config cases declared K and Beta with no integer alpha at all and expected
Valid to pass; that is a zero-vote quorum, not an unspecified one. Catch-up
certs carrying four signatures now declare the 4-of-5 threshold they are, and
the forged-signature case declares a real threshold so it still fails on the
forgery rather than on a stale bound.

The single-validator path is untouched: K=1/alpha=1 satisfies the floor, needs
no vote verifier, and bftCommittee still leaves a genuine K=1 preset unclamped.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-01 12:01:23 -07:00

107 lines
4.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright (C) 2019-2026, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package chain
import (
"testing"
"time"
"github.com/luxfi/ids"
)
// The transport-authenticated entry point proves WHO sent a message. It does not
// ask whether that sender is a validator of this chain. On the payload path the
// question is answered as a side effect: VerifyVote resolves the voter's key out
// of the set at the block's epoch height, so an id that is not in the set has no
// key and the vote dies. The transport path skips that resolution entirely, and
// nothing downstream re-asks: acceptVoters/rejectVoters are plain NodeID-keyed
// maps and alpha is a count over them.
//
// So the tallies count distinct PEERS, not distinct VALIDATORS — which is what
// the comment on those maps says they count. NodeIDs are self-minted (a hash of
// a cert the peer generates), peers may connect without being validators
// (RequireValidatorToConnect is off by default), and an inbound Chits is
// processed whether or not this node ever polled the sender.
func TestAuthVote_StrangerMovesTheAcceptTally(t *testing.T) {
vs := newTestValidatorSet(5)
e, chainID := newQuorumEngineOpts(t, params5(), vs, 0, &recordingGossiper{})
alpha := e.consensus.Alpha()
blk := newTestBlock(90001, ids.GenerateTestID(), "stranger-accept")
trackFollowedBlock(e, chainID, blk)
// Every voter here is a stranger: freshly generated, never in vs.
for i := 0; i < alpha; i++ {
stranger := ids.GenerateTestNodeID()
if vs.pub[stranger] != nil {
t.Fatal("precondition: the voter must not be a validator")
}
// Refused at the door is the point. If it is queued instead, the tally
// check below is what has to catch it.
e.ReceiveAuthenticatedVote(stranger, blk.id, true)
}
reached := waitFor(2*time.Second, func() bool {
return readVoteTally(e, blk).acceptVotes >= alpha
})
got := readVoteTally(e, blk)
if reached {
t.Fatalf("STRANGERS REACHED α: %d ids that hold no stake and sit in no validator "+
"set moved the accept tally to %d and accepted=%v (%+v). alpha is supposed to mean "+
"'α distinct VALIDATORS agreed'.", alpha, got.acceptVotes, got.accepted, got)
}
}
// The same hole on the reject side, where the consequence is not a futile
// finalize attempt. Reaching α rejects sets block.rejected, drops the block from
// tips, and the engine commits VM.Reject inline — the accept path's cert gate
// does not stand in front of it ("Rejections carry no stake-safety concern (a
// block is dropped, not finalized) and are committed inline", engine.go).
//
// The peer does not choose the polarity: applyPollResponse derives it from THIS
// node's re-Verify, which fails routinely for reasons that are not disagreement
// (already-verified, missing parent, state conflict — the node comments say so).
// A stranger therefore does not need to lie. It names a block; if our re-Verify
// errors, its preference is filed as that stranger's REJECT.
func TestAuthVote_StrangerMovesTheRejectTally(t *testing.T) {
vs := newTestValidatorSet(5)
e, chainID := newQuorumEngineOpts(t, params5(), vs, 0, &recordingGossiper{})
alpha := e.consensus.Alpha()
blk := newTestBlock(90002, ids.GenerateTestID(), "stranger-reject")
trackFollowedBlock(e, chainID, blk)
for i := 0; i < alpha; i++ {
e.ReceiveAuthenticatedVote(ids.GenerateTestNodeID(), blk.id, false)
}
reached := waitFor(2*time.Second, func() bool {
return readVoteTally(e, blk).rejectVotes >= alpha
})
got := readVoteTally(e, blk)
if reached || e.consensus.IsRejected(blk.id) {
t.Fatalf("STRANGERS REJECTED A BLOCK: reject tally %d, IsRejected=%v (%+v). The reject "+
"road has no cert in front of it — this is the one the engine commits inline.",
got.rejectVotes, e.consensus.IsRejected(blk.id), got)
}
}
// Even a real validator id is insufficient without a signature over the exact
// consensus position. Transport identity is not a substitute for that proof.
func TestAuthVote_ValidatorsWithoutSignaturesAreRefused(t *testing.T) {
vs := newTestValidatorSet(5)
e, chainID := newQuorumEngineOpts(t, params5(), vs, 0, &recordingGossiper{})
alpha := e.consensus.Alpha()
blk := newTestBlock(90003, ids.GenerateTestID(), "control")
trackFollowedBlock(e, chainID, blk)
for i := 0; i < alpha; i++ {
e.ReceiveAuthenticatedVote(vs.nodeID(i), blk.id, true)
}
if waitFor(100*time.Millisecond, func() bool { return readVoteTally(e, blk).acceptVotes >= alpha }) {
t.Fatalf("unsigned validator identities reached α (%+v)", readVoteTally(e, blk))
}
}