mirror of
https://github.com/luxfi/consensus.git
synced 2026-09-24 00:26:58 +00:00
The Quasar rung read only stake. Two thirds of the stake is one signature wherever two thirds of the stake is one validator, so a whale holding a supermajority could mint an export-grade certificate alone — and export-grade finality is what a bridge, a settlement and a cross-chain message admit on. A certificate one key can produce is not a claim that a Byzantine supermajority agreed, however much weight stands behind the key. VerifyWeighted now demands config.TwoThirdsCount(n) = floor(2n/3)+1 DISTINCT signers of a Quasar certificate as well as the stake. Two independent predicates, neither sufficient alone, the same shape Nova has one rung up. TwoThirdsCount is the count that value has always been, given its own name and one home. It is derived from TwoThirdsStakeFloor over unit weights rather than restated, so the count and the stake predicate cannot drift. It replaces three spellings of the same closed form that had grown apart in reach if not yet in value: config.EqualStakeSupermajorityThreshold (the alpha sizer), the private chain.quasarQuorum (the attestor's assembly trigger), and the clause that was missing from the verifier entirely. Stake is read first and the count second. Both must hold, so the order names only which clause a refusal reports: on an equal-stake set the two are one bar in two units and bind together, and the count clause binds ALONE only where the weights are lopsided — so reaching it means the stake was there and the signers were not. Every verdict the R3 corpus froze is unchanged. Liveness. Nothing that exports today stops exporting. QuasarAttestor, the only producer of export certificates, already assembled at exactly floor(2n/3)+1 attestations, and FeasibleParams already sized alpha — the floor HandleIncomingCert applies to a gossiped Quasar cert — to the same number. Producer, gossip door and verifier now read one function, so the verifier's new clause refuses nothing the engine can build and exactly what it never could. quasar_count_floor_test.go holds all three to that. The tests that moved were the ones written on three seats, where floor(2n/3)+1 is three and no two-signer certificate can isolate the stake half any more. They ask the same question on four. Rust: the same clause in Cert::verify_quasar_supermajority, the same name. 1.22.4 -> 1.22.5 — this changes what the crate accepts. Also, at the already-admitted door: the zero-weight refusal is justified by agreement with Register, not by the phantom-signer argument alone. A seat whose key does not decode can never sign and is refused anyway, because the weight is read before the key is — and deferring it would make admission depend on which keys a node's crypto build can parse. Co-authored-by: Hanzo Dev <[email protected]>
88 lines
3.0 KiB
Go
88 lines
3.0 KiB
Go
package config
|
||
|
||
import (
|
||
"errors"
|
||
"testing"
|
||
)
|
||
|
||
// A set with no stake has no supermajority to reach, so the threshold is zero
|
||
// rather than a count some empty quorum could satisfy. Breaks if a stakeless or
|
||
// empty validator set ever yields a reachable threshold — that is a quorum of
|
||
// nobody.
|
||
func TestStakelessSetHasNoSupermajority(t *testing.T) {
|
||
for name, weights := range map[string][]uint64{
|
||
"no validators": {},
|
||
"nil": nil,
|
||
"all zero stake": {0, 0, 0},
|
||
} {
|
||
if got := WeightedSupermajorityThreshold(weights); got != 0 {
|
||
t.Errorf("%s: threshold %d, want 0", name, got)
|
||
}
|
||
}
|
||
}
|
||
|
||
// The equal-stake closed form and the general heaviest-first computation are two
|
||
// spellings of one predicate; they must agree on every n, or a network sized by
|
||
// one rule would be validated against the other.
|
||
func TestEqualStakeClosedFormMatchesTheWeightedComputation(t *testing.T) {
|
||
for n := 1; n <= 300; n++ {
|
||
unit := make([]uint64, n)
|
||
for i := range unit {
|
||
unit[i] = 1
|
||
}
|
||
if closed, general := TwoThirdsCount(n), WeightedSupermajorityThreshold(unit); closed != general {
|
||
t.Fatalf("n=%d: closed form %d, heaviest-first %d", n, closed, general)
|
||
}
|
||
}
|
||
|
||
// An unknown validator count still needs someone to accept, never zero.
|
||
for _, n := range []int{0, -1, -100} {
|
||
if got := TwoThirdsCount(n); got != 1 {
|
||
t.Errorf("n=%d: threshold %d, want 1", n, got)
|
||
}
|
||
}
|
||
}
|
||
|
||
// FeasibleParams derives α from the committee size alone. This holds the ground
|
||
// the function's missing clamps rest on: for every k it can produce, α already
|
||
// sits at or above the BFT overlap floor, at or below k, and its ratio lands
|
||
// inside the [0.66, 1.0] window Valid() demands. If a formula change breaks any
|
||
// of these, the clamps have to come back — and this fails first.
|
||
func TestFeasibleParamsNeedsNoClamping(t *testing.T) {
|
||
for n := -1; n <= 2000; n++ {
|
||
p := FeasibleParams(1, n)
|
||
|
||
if p.K < 4 {
|
||
t.Fatalf("n=%d: K=%d below the minimal BFT committee", n, p.K)
|
||
}
|
||
if floor := (Parameters{K: p.K}).bftQuorumFloor(); p.AlphaPreference < floor {
|
||
t.Fatalf("K=%d: α=%d under the BFT overlap floor %d", p.K, p.AlphaPreference, floor)
|
||
}
|
||
if p.AlphaPreference > p.K {
|
||
t.Fatalf("K=%d: α=%d demands more votes than the committee holds", p.K, p.AlphaPreference)
|
||
}
|
||
if p.Alpha < 0.66 || p.Alpha > 1.0 {
|
||
t.Fatalf("K=%d: ratio %.4f outside [0.66, 1.0]", p.K, p.Alpha)
|
||
}
|
||
if err := p.Valid(); err != nil {
|
||
t.Fatalf("n=%d: derived params do not validate: %v", n, err)
|
||
}
|
||
}
|
||
}
|
||
|
||
// The live-aware check still runs the ordinary parameter validation first, so a
|
||
// structurally broken set is refused on its own terms rather than reaching the
|
||
// live-count reasoning with nonsense.
|
||
func TestLiveValidationRefusesStructurallyBrokenParams(t *testing.T) {
|
||
p := MainnetParams()
|
||
p.K = 0
|
||
|
||
err := p.ValidateForLiveValueNetwork(1, 21)
|
||
if err == nil {
|
||
t.Fatal("accepted params with an empty committee")
|
||
}
|
||
if errors.Is(err, ErrKBelowMainnetTarget) {
|
||
t.Errorf("reported a decentralisation target for params that are not even valid: %v", err)
|
||
}
|
||
}
|