1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
//! The finality standard, in Rust.
//!
//! Go is the network. This module is correct exactly insofar as it reproduces
//! what `github.com/luxfi/consensus/engine/chain` produces, and `tests/
//! conformance.rs` holds it to that against `conformance/corpus.json` — the
//! corpus generated from the Go definitions themselves.
//!
//! Two rungs, never collapsed. `Nova` is a strict majority of stake and
//! authorizes local execution; it is reorgable. `Quasar` is a strict two thirds
//! of stake and is the only rung a bridge, a settlement or a cross-chain message
//! may read. An implementation with one rung cannot express the accept that
//! every Lux chain actually runs on.
/// A 32-byte identifier. Empty means unset.
pub type Id = ;
/// The empty identifier — the value that triggers the canonical degrade.
pub const EMPTY: Id = ;
/// The domain tag, NUL-terminated. Its own version rides in the tag so a
/// signature over the canonical commitment can never be read as a signature
/// over the outer envelope id.
pub const VOTE_TAG: & = b"LUX/chain/vote/v2\0";
/// The certificate version folded into every signed message.
pub const QUORUM_CERT_VERSION: u16 = 3;
/// The certificate role. A finality certificate witnesses acceptance, so this is
/// the only role a chain vote carries.
pub const QC_FINALITY: u8 = 1;
/// The length of a signed vote message. Every field is fixed width, so the
/// message is length-free and always exactly this long.
pub const VOTE_MESSAGE_LEN: usize = 226;
/// The consensus position a vote binds to.
///
/// It carries two identities. The canonical execution identity — `canonical_id`,
/// `parent_canonical_id`, `execution_state_root`, `payload_root` — is the
/// primary consensus object and is signed. The transport identity — `block_id`,
/// `parent_id` — is the outer envelope, a cache key for block lookup, and is NOT
/// signed. Two nodes that executed the same inner block therefore sign identical
/// bytes however it was wrapped, and their votes interoperate.
/// The exact bytes a validator signs.
///
/// Layout, big-endian and fixed width throughout:
///
/// ```text
/// "LUX/chain/vote/v2\0" 18
/// version 2
/// qc_type 1
/// chain_id 32
/// height 8
/// round 4
/// canonical_id 32
/// parent_canonical_id 32
/// execution_state_root 32
/// payload_root 32
/// validator_set_root 32
/// accept 1
/// ```
///
/// `accept` is bound, so an accept signature and a reject signature over one
/// position are distinct messages and neither can be presented as the other.
///
/// The degrade is resolved here and only here: a position whose canonical slots
/// are unset — a block with no inner/outer split — binds its transport ids under
/// them, so every producer of a position signs the same bytes for the same
/// block.
/// `floor(2·total/3)` — the threshold an export quorum must STRICTLY exceed.
///
/// Computed from `total` alone because `2·total` overflows near 2^64:
/// `floor(2·total/3) = 2·(total/3) + floor(2·(total mod 3)/3)`, and
/// `floor(2r/3)` for r in {0,1,2} is {0,0,1}.
/// `floor(total/2)` — the threshold a local-execution quorum must STRICTLY
/// exceed. One rung below the export floor, and deliberately so.
/// The majority the sampler needs to ignite a block to Nova. `n < 1` yields 1: a
/// lone node self-ignites, and never 0, which would let a transiently empty view
/// self-accept.
/// The smallest Byzantine-fault-tolerant committee: the least n whose fault budget
/// f = ⌊(n−1)/3⌋ reaches one. Below it a two-thirds supermajority tolerates no
/// Byzantine fault at all.
///
/// Two consumers, one constant: [`nova_signer_floor`] saturates its count here so a
/// lone node can never ignite, and [`crate::cert::QuorumCert::verify_weighted`]
/// refuses an EXPORT certificate over a signing set smaller than this. Go's
/// `engine/chain.minBFTCommittee`, C++'s `kMinBFTCommittee`.
pub const MIN_BFT_COMMITTEE: i64 = 4;
/// The minimum distinct signers a Nova certificate needs whatever the stake
/// distribution. The Nova gate proper is a stake majority; this count is the
/// guard the stake predicate cannot give — a single holder of a stake majority
/// would otherwise self-ignite.
/// The confidence depth: consecutive majority rounds required to ignite Nova.
/// Simultaneous crash faults Nova ignition survives.
/// The two-thirds SUPERMAJORITY COUNT of n — the smallest number of seats that is
/// strictly more than two thirds of them, `floor(2n/3) + 1`. For n = 21 this is
/// 15, not 14: 14/21 does not strictly exceed two thirds. Derived from
/// [`two_thirds_stake_floor`] over n unit weights rather than restated, so the
/// count and the stake predicate cannot drift.
///
/// Two consumers, one rule seen from two sides. It is the count a live
/// equal-stake network sizes alpha to, and it is the floor on DISTINCT signers
/// that [`crate::cert::QuorumCert::verify_weighted`] demands of an export
/// certificate whatever the stake distribution — the guard the stake predicate
/// cannot give, because two thirds of the stake is one signature wherever two
/// thirds of the stake is one validator. Go's `config.TwoThirdsCount`.
/// The DISTINCT signers a certificate must carry to attest `tier` over a set of
/// `n` signers — the whole of a certificate's authority in seats, and a function
/// of the set and the rung, never of the certificate.
///
/// One definition, read in three places: the assembler picks its alpha from it,
/// the weighted predicate enforces it, and the derived-threshold clause compares
/// the certificate's own declaration against it. A second spelling anywhere is
/// how a certificate acquires a quorum of its own choosing.
///
/// * Nova — [`nova_signer_floor`], which saturates at three: local execution has
/// to stay reachable on a small chain, and it is reorgable.
/// * Quasar — [`two_thirds_count`], the export supermajority read in seats, the
/// same supermajority the stake clause reads in weight.
///
/// A rung that is not an accept tier has no floor and gets none: 0, which every
/// caller reads as a refusal. Go's `chain.SignerFloor`.
/// The minimum vote count that CAN reach the two-thirds-by-stake predicate for a
/// weight vector: order heaviest first and count until the running stake first
/// exceeds the floor. Returns 0 for an empty set, a zero total, or a vector with
/// no representable total — no stake model, fail closed.
///
/// This is a SIZER, not a floor. It answers "below how many votes is two thirds
/// of this particular stake distribution unreachable", which is what a parameter
/// sizer needs and is Go's `config.WeightedSupermajorityThreshold`. The floor a
/// certificate is held to is [`two_thirds_count`] over the set SIZE, and it is
/// deliberately the larger of the two on a skewed set: the whole point of the
/// floor is that concentrated stake must not shrink the number of parties whose
/// agreement export finality reports.
/// A block's rung: the single highest authority it has reached.