This document describes the QBFT consensus protocol used for reaching agreement among distributed validator nodes.
Scope:
- Over-the-wire message structures and fields
- Consensus flow and round mechanics
- Protocol identifiers and exchange patterns
- Verification and validation flows
Out of scope: cluster discovery/formation, storage, application-specific value encoding beyond the hashing contract, and any non-libp2p transport.
n: Number of nodes in the clusterf: Maximum Byzantine faults tolerated, where f < n/3quorum: ceil(2n/3) nodes must agree for decisionsduty: Consensus instance identifier(slot, type). Each duty requires independent consensusround: 1-based counter for coordination. Rounds increase on timeout or failurepeer_idx: 0-based index into membership list, maps to a configured public key
All messages are sent under protocol ID:
/charon/consensus/qbft/2.0.0
QBFT operates in rounds. Each round attempts to reach consensus through three phases:
Normal operation:
- Pre-Prepare: The leader for
(duty, round)proposes a valueVby broadcastingPRE_PREPARE(round, V) - Prepare: Upon receiving a justified
PRE_PREPARE, nodes broadcastPREPARE(round, V) - Commit: Upon receiving quorum
PREPARE(round, V), nodes broadcastCOMMIT(round, V) - Decision: Upon receiving quorum
COMMIT(round, V), nodes decide onV
Round changes:
When a round times out or fails, nodes initiate a round change:
- Nodes broadcast
ROUND_CHANGEmessages for the next round - A quorum of
ROUND_CHANGEallows entering the new round - The new round's leader includes justification in their
PRE_PREPARE
Justification types:
- J1 (null-prepared): Quorum of
ROUND_CHANGEwith no prepared value (fresh start) - J2 (prepared): Quorum of
ROUND_CHANGEwhere some have prepared(round*, value*)in a prior round. The leader MUST proposevalue*withprepared_round=round*
Note: round* and value* denote the highest prepared round number and its corresponding value from the justification (i.e., values from a previous round, not the current round).
Leader selection:
leader_index = (duty.slot + duty.type + round) % n
Timers:
- Each round runs under a timer
- On timeout, nodes trigger a round change and increment the round
- Timer/backoff strategy does not affect safety, but must guarantee eventual progress
- The default strategy is the eager double linear timer: round
rlastsrseconds — except round 1 of a proposer duty, which lasts 1.5 seconds (block proposals need longer to fetch and agree on a value; seePROPOSAL_ROUND_TIMEOUTin the reference implementation). The first deadline of each round is computed deterministically from the chain (genesis_time + slot * slot_duration + duty_start_delay + timeout) rather than the local clock, so round boundaries — and hence leader election — stay aligned across all peers. The duty start delay isslot_duration/3for attestations,2*slot_duration/3for aggregations and sync contributions, and0otherwise. Implementations SHOULD match this strategy: a peer with misaligned round deadlines degrades cluster liveness (it changes rounds, and expects leaders, at the wrong times)
See the Python reference implementation: RoundTimer.
Message limits:
Receivers MUST bound incoming consensus messages before expensive
verification work (see verify_msg_limits and MAX_CONSENSUS_MSG_SIZE in
the reference implementation):
- Wire size: at most 32 MiB per message (enforced as a stream read limit)
- Justifications: at most
2 * nper message - Values: at most
2 * (justifications + 1)per message
The justification count is checked before the value count, so a message exceeding both is rejected for its justifications. Implementations that agree on rejecting but not on why will disagree on this case.
Note the wire size is a narrowing of the transport default: charon's libp2p reader allows 128 MiB and consensus overrides it to 32 MiB. Leaving the transport default in place accepts messages four times the size the protocol permits.
test_vectors/qbft_msg_limits.json
pins all three limits as accept/reject pairs either side of each boundary, each
naming which limit fired.
Decided messages:
DECIDED messages are optional since consensus is achieved upon quorum COMMIT(r, V), however they can be used to help slow nodes catch up.
After deciding, a node responds to any ROUND-CHANGE from a peer by
rebroadcasting DECIDED (helping lagging peers catch up), rate-limited to at
most one rebroadcast per source per strictly-increasing round and at most 16
rebroadcasts per source in total, to prevent amplification abuse.
Both halves of that rule matter: without the strictly-increasing requirement a
peer replays one round forever, and without the cap it mints ever-higher rounds.
test_vectors/qbft_decided_resends.json
replays charon's own event sequences and gives the expected rebroadcast decision
for each event, so an implementation missing either half fails a specific event
rather than a total.
The following protobuf definitions are used over the wire:
- consensus.proto - QBFT consensus message definitions
- core.proto - Common core type definitions (Duty, ParSignedData, etc.)
See the Python reference implementation: MsgType, QBFTMsg and QBFTConsensusMsg in qbft/message.py, and Duty in types/duty.py.
Value carriage:
The values array MUST contain an Any-wrapped payload for every non-zero hash referenced by:
msg.value_hashmsg.prepared_value_hash- Every
justification[i].value_hash - Every
justification[i].prepared_value_hash
Extra values MAY be included; order is irrelevant.
Both the value hash and the message signing root are HashRoot(deterministic_proto(...)). That construction is exact and easy to get subtly wrong, so it is specified separately in Canonical Encoding and Hashing, with test vectors generated by Charon. What follows is only a summary.
Hashing:
- Leader computes a deterministic hash root for values from deterministic protobuf encodings:
HashRoot(deterministic_proto(value))
Signature:
- Message signature is computed over
HashRoot(deterministic_proto(QBFTMsg))with thesignaturefield excluded from the encoding - Format: secp256k1 signature (65-byte R||S||V)
- The public key used for verification can be obtained by matching the
peer_idxfrom the message with thepeer_idxin the lock file (see Cluster Configuration for lock file structure)
See the Python validation implementation in qbft/message.py and types/duty.py; the names in parentheses below are the symbols in those modules that implement each rule.
Validation rules (receivers MUST reject if any fails):
msgandmsg.dutyare presentmsg.type∈ {1,...,5} (MsgType)duty.typeis valid (DutyType)peer_idx>= 0 (validate_peer_idx)peer_idxis a valid index in ordered peer list and maps to a known public keysignatureis 65 bytes when present (R||S||V format) (validate_signature)- Signature recovery matches the public key for
peer_idx round>= 1 (validate_round)prepared_round>= 0;0indicates no preparation (null-prepared) (validate_prepared_round)prepared_round<=round(validate_prepared_round)value_hashis 32 bytes when non-zero (validate_value_hash)prepared_value_hashmust be zero hash ifprepared_roundis 0; must be non-zero hash ifprepared_round> 0 (validate_prepared_value_hash)justificationis a flat list (nested justifications are rejected) with each object injustificationhaving identical duty tomsg.duty- For each referenced non-zero hash in
msgorjustifications, a matching value exists invaluesand re-hashes to that hash
All message types share these common requirements:
type: MUST be set to the appropriateMsgTypeduty: MUST be present with validslotandtypefieldspeer_idx: MUST be >= 0 and a valid index in the ordered peer listround: MUST be >= 1signature: MUST be 65 bytes (secp256k1 R||S||V format) and verify against the peer's public key
PRE_PREPARE:
Sent by the leader of (duty, round) only upon startup or round change to every other node.
Required fields:
value_hash: MUST be present (32-byte non-zero hash of proposed value)prepared_roundandprepared_value_hash:- For J1 (null-prepared): MUST be
0and zero hash (32 zero bytes) respectively - For J2 (prepared): MUST be present with
prepared_round=round*(whereround* > 0) andprepared_value_hash=H(value*)(non-zero hash) from the highest prepared round in the justification
- For J1 (null-prepared): MUST be
justification:- Round 1: MUST be empty
- J1 (null-prepared): MUST include quorum
ROUND_CHANGEmessages with null prepared values - J2 (prepared): MUST include quorum
ROUND_CHANGEmessages AND quorumPREPARE(round*, value*)messages from the highest prepared round
PREPARE:
Sent by any node upon receiving justified PRE_PREPARE to every other node.
Required fields:
value_hash: MUST be present (32-byte non-zero hash matching thePRE_PREPAREvalue)
COMMIT:
Sent by any node upon receiving quorum PREPARE messages to every other node.
Required fields:
value_hash: MUST be present (32-byte non-zero hash of the prepared value)
ROUND_CHANGE:
Sent by any node on round timeout or f+1 ROUND_CHANGE receipt to every other node.
Required fields:
prepared_round:- If null-prepared:
0 - If prepared: MUST be
> 0withround*from the highest prepared round
- If null-prepared:
prepared_value_hash:- If null-prepared: zero hash (32 zero bytes)
- If prepared: MUST be non-zero hash
H(value*)from the highest prepared round
justification:- If null-prepared: MUST be empty
- If prepared: MUST include quorum
PREPARE(round*, value*)messages that justify the prepared round and value
DECIDED:
Sent by decided nodes when receiving ROUND_CHANGE from late-joining peers.
Optional message type for optimization, implementations MUST NOT rely on DECIDED messages for safety or liveness guarantees
Required fields:
value_hash: MUST be present (32-byte non-zero hash of decided value)justification: MUST include quorumCOMMIT(round, value)messages that achieved consensus