Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/v2-lab-validator-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ After a successful 4- or 7-validator height-one QC plus separate nonvoting obser
## Two-height QC finality and observer recovery

The next GitHub 4/7-process matrix finalizes **two consecutive empty V2 blocks**, exercising deterministic proposer rotation, signer journal monotonicity and both real QUIC signed-QC broadcasts. All validator replicas and the nonvoting observer must independently converge on the exact signed header hash at **each height**, and hashes at heights 1 and 2 must differ. A separate keyless proof verifier validates the independently expected height, genesis and header for **both** snapshots, then rejects a deliberately mutated height-two vote. Following process shutdown, the observer must fully replay the two-height QC-certified disk history to the exact height-two header; one-byte append corruption must fail closed. Still a same-runner and empty-block lab, not a multi-host network, nonempty TPS or an independently administered custody guarantee.


## P0 cross-round signing lock (conservative safety boundary)

Until a verifiable multi-round BFT unlocking protocol is specified, a validator signing guard must **never** authorize a different consensus header hash at the same height, even when the round advances. A newer round alone is not a valid unlock certificate. `DurableSigningGuard.Authorize` now rejects such a target change with `ErrSigningConflict`; the full hash-chained journal replay likewise fails closed if previously recorded same-height rounds contain conflicting targets, even if each record is correctly checksummed. Repeated signatures for the same header in later rounds remain legal; a new height can sign a new header. This deliberately prioritizes safety and may block liveness for an alternative block at the same height until a real lock/unlock protocol with cryptographic proof is implemented. It does **not** mean complete multi-round BFT liveness has been delivered. See P0 security issue #226, mainnet remains NO-GO.
17 changes: 13 additions & 4 deletions internal/v2/consensus/signing_guard.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,13 @@ func (g *DurableSigningGuard) replay() error {
hash != types.Hash(codec.DomainHash("zephyr/consensus/signing-intent/v1", raw[:80])) {
return ErrSigningJournal
}
// A signing key must never endorse different consensus header
// hashes at one height, including across later rounds. Without a
// separately proven BFT lock/unlock rule, two authentic quorums
// for different same-height headers would be a safety violation.
// Check this on FULL replay, not just new Authorize calls.
if g.hasRecord && (height < g.height ||
(height == g.height && round <= g.round)) {
(height == g.height && (round <= g.round || target != g.target))) {
return ErrSigningJournal
}
g.height, g.round, g.target, g.lastRecordHash, g.hasRecord = height, round, target, hash, true
Expand Down Expand Up @@ -300,10 +305,14 @@ func (g *DurableSigningGuard) Authorize(network types.NetworkID, validator types
if height < g.height || (height == g.height && round < g.round) {
return ErrSigningConflict
}
if height == g.height && target != g.target {
// Monotonic rounds alone do not certify that a validator
// safely unlocked its old header. Until a verifiable unlock
// protocol exists, remain locked on the first signed target
// for the entire height, even after a process restart.
return ErrSigningConflict
}
if height == g.height && round == g.round {
if target != g.target {
return ErrSigningConflict
}
return nil
}
}
Expand Down
101 changes: 99 additions & 2 deletions internal/v2/consensus/signing_guard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"testing"

"github.com/zephyr-chain/zephyr-chain/internal/v2/codec"
"github.com/zephyr-chain/zephyr-chain/internal/v2/types"
)

Expand Down Expand Up @@ -52,8 +53,11 @@ func TestDurableSigningGuardRejectsConflictsAcrossRestarts(t *testing.T) {
if err := guard.Authorize(network, types.ValidatorID{8}, 10, 1, hashB); !errors.Is(err, ErrSigningGuard) {
t.Fatalf("validator substitution allowed: %v", err)
}
if err := guard.Authorize(network, validator, 10, 1, hashB); err != nil {
t.Fatalf("next round rejected: %v", err)
if err := guard.Authorize(network, validator, 10, 1, hashB); !errors.Is(err, ErrSigningConflict) {
t.Fatalf("conflicting next-round header authorized: %v", err)
}
if err := guard.Authorize(network, validator, 10, 1, hashA); err != nil {
t.Fatalf("same-header next round rejected: %v", err)
}
if err := guard.Authorize(network, validator, 11, 0, hashA); err != nil {
t.Fatalf("next height rejected: %v", err)
Expand Down Expand Up @@ -86,6 +90,99 @@ func TestDurableSigningGuardRejectsConflictsAcrossRestarts(t *testing.T) {
}
}

// A later round is NOT evidence that an old signed header is safely
// unlocked. Proving and committing a new height is the only release this
// conservative signer permits until a dedicated BFT unlock protocol exists.
func TestDurableSigningGuardCrossRoundHeaderLockSurvivesRestarts(t *testing.T) {
dir := testSigningJournalDir(t)
network, id := types.NetworkID{7}, types.ValidatorID{8}
headerA, headerB := types.Hash{9}, types.Hash{10}
guard, err := OpenDurableSigningGuard(dir, network, id)
if err != nil {
t.Fatal(err)
}
if err := guard.Authorize(network, id, 2, 0, headerA); err != nil {
t.Fatal(err)
}
if err := guard.Close(); err != nil {
t.Fatal(err)
}
for _, round := range []uint64{1, 2, 3} {
guard, err = OpenDurableSigningGuard(dir, network, id)
if err != nil {
t.Fatal(err)
}
if err := guard.Authorize(network, id, 2, round, headerB); !errors.Is(err, ErrSigningConflict) {
t.Fatalf("round %d changed signed header after restart: %v", round, err)
}
if err := guard.Authorize(network, id, 2, round, headerA); err != nil {
t.Fatalf("round %d same-header vote rejected: %v", round, err)
}
if err := guard.Close(); err != nil {
t.Fatal(err)
}
}
guard, err = OpenDurableSigningGuard(dir, network, id)
if err != nil {
t.Fatal(err)
}
defer guard.Close()
if err := guard.Authorize(network, id, 3, 0, headerB); err != nil {
t.Fatalf("new finalized height must release the old header lock: %v", err)
}
}

// A privileged test author can construct a fully hash-chained journal with
// an illicit same-height cross-round header change. Replay must reject it,
// not merely the broken-checksum and truncated-file cases.
func TestDurableSigningGuardReplayRejectsValidHashChainWithCrossRoundConflict(t *testing.T) {
dir := testSigningJournalDir(t)
network, id := types.NetworkID{17}, types.ValidatorID{18}
headerA, headerB := types.Hash{19}, types.Hash{20}
guard, err := OpenDurableSigningGuard(dir, network, id)
if err != nil {
t.Fatal(err)
}
if err := guard.Authorize(network, id, 4, 0, headerA); err != nil {
t.Fatal(err)
}
if err := guard.Close(); err != nil {
t.Fatal(err)
}
path := filepath.Join(dir, "consensus-signing.journal")
before, err := os.ReadFile(path)
if err != nil || len(before) != signingJournalHeaderBytes+signingJournalRecordBytes {
t.Fatalf("original signer journal: %v", err)
}
var w codec.Writer
w.U64(4)
w.U64(1)
w.Fixed(headerB[:])
w.Fixed(before[len(before)-32:])
body := w.BytesCopy()
digest := codec.DomainHash("zephyr/consensus/signing-intent/v1", body)
w.Fixed(digest[:])
record := w.BytesCopy()
if len(record) != signingJournalRecordBytes {
t.Fatalf("wrong replay record length: %d", len(record))
}
file, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND, 0)
if err != nil {
t.Fatal(err)
}
_, writeErr := file.Write(record)
if writeErr == nil {
writeErr = file.Sync()
}
closeErr := file.Close()
if err := errors.Join(writeErr, closeErr); err != nil {
t.Fatal(err)
}
if _, err := OpenDurableSigningGuard(dir, network, id); !errors.Is(err, ErrSigningJournal) {
t.Fatalf("valid hash-chain with conflicting same-height target admitted: %v", err)
}
}

func TestDurableSigningGuardCorruptionFailsClosed(t *testing.T) {
network := types.NetworkID{1}
validator := types.ValidatorID{2}
Expand Down
Loading