diff --git a/consensus/fuzz/fuzz_targets/simplex_bls12381_multisig_minpk.rs b/consensus/fuzz/fuzz_targets/simplex_bls12381_multisig_minpk.rs index cda4c32018..c062355376 100644 --- a/consensus/fuzz/fuzz_targets/simplex_bls12381_multisig_minpk.rs +++ b/consensus/fuzz/fuzz_targets/simplex_bls12381_multisig_minpk.rs @@ -16,11 +16,11 @@ impl Simplex for SimplexBls12381MultisigMinPk { type Elector = RoundRobin; fn fixture( - namespace: &[u8], context: &mut deterministic::Context, + namespace: &[u8], n: u32, ) -> Fixture { - bls12381_multisig::fixture::(namespace, context, n) + bls12381_multisig::fixture::(context, namespace, n) } } diff --git a/consensus/fuzz/fuzz_targets/simplex_bls12381_multisig_minsig.rs b/consensus/fuzz/fuzz_targets/simplex_bls12381_multisig_minsig.rs index 7e5a8b1f6d..ce224984b5 100644 --- a/consensus/fuzz/fuzz_targets/simplex_bls12381_multisig_minsig.rs +++ b/consensus/fuzz/fuzz_targets/simplex_bls12381_multisig_minsig.rs @@ -16,11 +16,11 @@ impl Simplex for SimplexBls12381MultisigMinSig { type Elector = RoundRobin; fn fixture( - namespace: &[u8], context: &mut deterministic::Context, + namespace: &[u8], n: u32, ) -> Fixture { - bls12381_multisig::fixture::(namespace, context, n) + bls12381_multisig::fixture::(context, namespace, n) } } diff --git a/consensus/fuzz/fuzz_targets/simplex_bls12381_threshold_minpk.rs b/consensus/fuzz/fuzz_targets/simplex_bls12381_threshold_minpk.rs index de664b2f9d..f723b843b2 100644 --- a/consensus/fuzz/fuzz_targets/simplex_bls12381_threshold_minpk.rs +++ b/consensus/fuzz/fuzz_targets/simplex_bls12381_threshold_minpk.rs @@ -16,11 +16,11 @@ impl Simplex for SimplexBls12381MinPk { type Elector = Random; fn fixture( - namespace: &[u8], context: &mut deterministic::Context, + namespace: &[u8], n: u32, ) -> Fixture { - bls12381_threshold::fixture::(namespace, context, n) + bls12381_threshold::fixture::(context, namespace, n) } } diff --git a/consensus/fuzz/fuzz_targets/simplex_bls12381_threshold_minsig.rs b/consensus/fuzz/fuzz_targets/simplex_bls12381_threshold_minsig.rs index 6873fb395d..81f066ee40 100644 --- a/consensus/fuzz/fuzz_targets/simplex_bls12381_threshold_minsig.rs +++ b/consensus/fuzz/fuzz_targets/simplex_bls12381_threshold_minsig.rs @@ -16,11 +16,11 @@ impl Simplex for SimplexBls12381MinSig { type Elector = Random; fn fixture( - namespace: &[u8], context: &mut deterministic::Context, + namespace: &[u8], n: u32, ) -> Fixture { - bls12381_threshold::fixture::(namespace, context, n) + bls12381_threshold::fixture::(context, namespace, n) } } diff --git a/consensus/fuzz/fuzz_targets/simplex_ed25519.rs b/consensus/fuzz/fuzz_targets/simplex_ed25519.rs index 2b07c680bf..ffc1a50f0d 100644 --- a/consensus/fuzz/fuzz_targets/simplex_ed25519.rs +++ b/consensus/fuzz/fuzz_targets/simplex_ed25519.rs @@ -13,11 +13,11 @@ impl Simplex for SimplexEd25519 { type Elector = RoundRobin; fn fixture( - namespace: &[u8], context: &mut deterministic::Context, + namespace: &[u8], n: u32, ) -> Fixture { - ed25519::fixture(namespace, context, n) + ed25519::fixture(context, namespace, n) } } diff --git a/consensus/fuzz/fuzz_targets/simplex_secp256r1.rs b/consensus/fuzz/fuzz_targets/simplex_secp256r1.rs index 2c287c5e24..f633499eb7 100644 --- a/consensus/fuzz/fuzz_targets/simplex_secp256r1.rs +++ b/consensus/fuzz/fuzz_targets/simplex_secp256r1.rs @@ -15,11 +15,11 @@ impl Simplex for SimplexSecp256r1 { type Elector = RoundRobin; fn fixture( - namespace: &[u8], context: &mut deterministic::Context, + namespace: &[u8], n: u32, ) -> Fixture { - secp256r1::fixture(namespace, context, n) + secp256r1::fixture(context, namespace, n) } } diff --git a/consensus/fuzz/src/lib.rs b/consensus/fuzz/src/lib.rs index fdc0c0423b..988491fa6a 100644 --- a/consensus/fuzz/src/lib.rs +++ b/consensus/fuzz/src/lib.rs @@ -56,8 +56,8 @@ where type Scheme: Scheme; type Elector: Elector; fn fixture( - namespace: &[u8], context: &mut deterministic::Context, + namespace: &[u8], n: u32, ) -> Fixture; } @@ -166,7 +166,7 @@ fn run(input: FuzzInput) { schemes, verifier: _, .. - } = P::fixture(NAMESPACE, &mut context, n); + } = P::fixture(&mut context, NAMESPACE, n); let mut registrations = register(&mut oracle, &participants).await; diff --git a/consensus/src/aggregation/mod.rs b/consensus/src/aggregation/mod.rs index ff8fec5ab2..be6dbc11c6 100644 --- a/consensus/src/aggregation/mod.rs +++ b/consensus/src/aggregation/mod.rs @@ -312,13 +312,13 @@ mod tests { fn all_online(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnOnce(&mut deterministic::Context, &[u8], u32) -> Fixture, { let runner = deterministic::Runner::timed(Duration::from_secs(30)); runner.start(|mut context| async move { let num_validators = 4; - let fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); let epoch = Epoch::new(111); let (mut oracle, mut registrations) = @@ -353,13 +353,13 @@ mod tests { fn byzantine_proposer(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnOnce(&mut deterministic::Context, &[u8], u32) -> Fixture, { let runner = deterministic::Runner::timed(Duration::from_secs(30)); runner.start(|mut context| async move { let num_validators = 4; - let fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); let epoch = Epoch::new(111); let (mut oracle, mut registrations) = @@ -393,7 +393,7 @@ mod tests { fn unclean_byzantine_shutdown(fixture: F) where S: Scheme, - F: Fn(&[u8], &mut StdRng, u32) -> Fixture, + F: Fn(&mut StdRng, &[u8], u32) -> Fixture, { // Test parameters let num_validators = 4; @@ -408,7 +408,7 @@ mod tests { // Generate fixture once (persists across restarts) let mut rng = test_rng(); - let fixture = fixture(TEST_NAMESPACE, &mut rng, num_validators); + let fixture = fixture(&mut rng, TEST_NAMESPACE, num_validators); // Continue until shared reporter reaches target or max shutdowns exceeded let mut shutdown_count = 0; @@ -550,7 +550,7 @@ mod tests { fn unclean_shutdown_with_unsigned_index(fixture: F) where S: Scheme, - F: Fn(&[u8], &mut StdRng, u32) -> Fixture, + F: Fn(&mut StdRng, &[u8], u32) -> Fixture, { // Test parameters let num_validators = 4; @@ -560,7 +560,7 @@ mod tests { // Generate fixture once (persists across restarts) let mut rng = test_rng(); - let fixture = fixture(TEST_NAMESPACE, &mut rng, num_validators); + let fixture = fixture(&mut rng, TEST_NAMESPACE, num_validators); // First run: let validators skip signing at skip_index and reach beyond it let f = |context: Context| { @@ -743,7 +743,7 @@ mod tests { fn slow_and_lossy_links(fixture: F, seed: u64) -> String where S: Scheme, - F: FnOnce(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnOnce(&mut deterministic::Context, &[u8], u32) -> Fixture, { let cfg = deterministic::Config::new() .with_seed(seed) @@ -752,7 +752,7 @@ mod tests { runner.start(|mut context| async move { let num_validators = 4; - let fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); let epoch = Epoch::new(111); // Use degraded network links with realistic conditions @@ -855,13 +855,13 @@ mod tests { fn one_offline(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnOnce(&mut deterministic::Context, &[u8], u32) -> Fixture, { let runner = deterministic::Runner::timed(Duration::from_secs(30)); runner.start(|mut context| async move { let num_validators = 5; - let mut fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let mut fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); let epoch = Epoch::new(111); // Truncate to only 4 validators (one offline) @@ -900,13 +900,13 @@ mod tests { fn network_partition(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnOnce(&mut deterministic::Context, &[u8], u32) -> Fixture, { let runner = deterministic::Runner::timed(Duration::from_secs(60)); runner.start(|mut context| async move { let num_validators = 4; - let fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); let epoch = Epoch::new(111); let (mut oracle, mut registrations) = @@ -965,13 +965,13 @@ mod tests { fn insufficient_validators(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnOnce(&mut deterministic::Context, &[u8], u32) -> Fixture, { let runner = deterministic::Runner::timed(Duration::from_secs(15)); runner.start(|mut context| async move { let num_validators = 5; - let fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); let epoch = Epoch::new(111); // Set up simulated network diff --git a/consensus/src/aggregation/types.rs b/consensus/src/aggregation/types.rs index 4d5c9b2ddc..e580c2f48a 100644 --- a/consensus/src/aggregation/types.rs +++ b/consensus/src/aggregation/types.rs @@ -477,10 +477,10 @@ mod tests { fn codec(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); + let fixture = fixture(&mut rng, NAMESPACE, 4); let schemes = &fixture.schemes; let item = Item { index: 100, @@ -572,9 +572,9 @@ mod tests { fn activity_invalid_enum(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { - let fixture = fixture(NAMESPACE, &mut test_rng(), 4); + let fixture = fixture(&mut test_rng(), NAMESPACE, 4); let mut buf = BytesMut::new(); 3u8.write(&mut buf); // Invalid discriminant diff --git a/consensus/src/marshal/mod.rs b/consensus/src/marshal/mod.rs index 2486bc6b13..3ae9268309 100644 --- a/consensus/src/marshal/mod.rs +++ b/consensus/src/marshal/mod.rs @@ -418,7 +418,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); // Initialize applications and actors let mut applications = BTreeMap::new(); @@ -563,7 +563,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); // Initialize applications and actors let mut applications = BTreeMap::new(); @@ -730,7 +730,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); let mut actors = Vec::new(); for (i, validator) in participants.iter().enumerate() { @@ -785,7 +785,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); let mut actors = Vec::new(); for (i, validator) in participants.iter().enumerate() { @@ -861,7 +861,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); let mut actors = Vec::new(); for (i, validator) in participants.iter().enumerate() { @@ -929,7 +929,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); let mut actors = Vec::new(); for (i, validator) in participants.iter().enumerate() { @@ -1040,7 +1040,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); // Single validator actor let me = participants[0].clone(); @@ -1100,7 +1100,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); // Single validator actor let me = participants[0].clone(); @@ -1182,7 +1182,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); let me = participants[0].clone(); let (application, mut actor, _processed_height) = setup_validator( @@ -1241,7 +1241,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); let me = participants[0].clone(); let (_application, mut actor, _processed_height) = setup_validator( @@ -1299,7 +1299,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); let me = participants[0].clone(); let (_application, mut actor, _processed_height) = setup_validator( @@ -1357,7 +1357,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); // Register the initial peer set let mut manager = oracle.manager(); @@ -1439,7 +1439,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); let me = participants[0].clone(); let (_application, mut actor, _processed_height) = setup_validator( @@ -1524,7 +1524,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); let me = participants[0].clone(); let (_base_app, marshal, _processed_height) = setup_validator( @@ -1656,7 +1656,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); // Set up two validators let mut actors = Vec::new(); @@ -1768,7 +1768,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); // Test 1: Fresh init should return processed height 0 let me = participants[0].clone(); @@ -1903,7 +1903,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); let me = participants[0].clone(); let (_base_app, marshal, _processed_height) = setup_validator( @@ -1968,7 +1968,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut context, NUM_VALIDATORS); + } = bls12381_threshold::fixture::(&mut context, NAMESPACE, NUM_VALIDATORS); // Set up one validator let (i, validator) = participants.iter().enumerate().next().unwrap(); diff --git a/consensus/src/ordered_broadcast/ack_manager.rs b/consensus/src/ordered_broadcast/ack_manager.rs index fc3a04aa89..16e7854900 100644 --- a/consensus/src/ordered_broadcast/ack_manager.rs +++ b/consensus/src/ordered_broadcast/ack_manager.rs @@ -240,11 +240,11 @@ mod tests { fn chunk_different_payloads(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { // Use 8 validators so quorum is 6 let num_validators = 8; - let fixture = fixture(NAMESPACE, &mut test_rng(), num_validators); + let fixture = fixture(&mut test_rng(), NAMESPACE, num_validators); let mut acks = AckManager::::Digest>::new(); let sequencer = fixture.participants[1].clone(); let height = 10; @@ -290,10 +290,10 @@ mod tests { fn sequencer_different_heights(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let num_validators = 4; - let fixture = fixture(NAMESPACE, &mut test_rng(), num_validators); + let fixture = fixture(&mut test_rng(), NAMESPACE, num_validators); let mut acks = AckManager::::Digest>::new(); let sequencer = fixture.participants[1].clone(); let epoch = Epoch::new(10); @@ -337,10 +337,10 @@ mod tests { fn sequencer_contiguous_heights(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let num_validators = 4; - let fixture = fixture(NAMESPACE, &mut test_rng(), num_validators); + let fixture = fixture(&mut test_rng(), NAMESPACE, num_validators); let mut acks = AckManager::::Digest>::new(); let sequencer = fixture.participants[1].clone(); let epoch = Epoch::new(10); @@ -386,10 +386,10 @@ mod tests { fn chunk_different_epochs(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let num_validators = 4; - let fixture = fixture(NAMESPACE, &mut test_rng(), num_validators); + let fixture = fixture(&mut test_rng(), NAMESPACE, num_validators); let mut acks = AckManager::::Digest>::new(); let sequencer = fixture.participants[1].clone(); let height = 30; @@ -433,10 +433,10 @@ mod tests { fn add_certificate(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let num_validators = 4; - let fixture = fixture(NAMESPACE, &mut test_rng(), num_validators); + let fixture = fixture(&mut test_rng(), NAMESPACE, num_validators); let mut acks = AckManager::::Digest>::new(); let epoch = Epoch::new(99); let sequencer = fixture.participants[1].clone(); @@ -474,10 +474,10 @@ mod tests { fn duplicate_attestation_submission(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let num_validators = 4; - let fixture = fixture(NAMESPACE, &mut test_rng(), num_validators); + let fixture = fixture(&mut test_rng(), NAMESPACE, num_validators); let mut acks = AckManager::::Digest>::new(); let sequencer = fixture.participants[1].clone(); let epoch = Epoch::new(1); @@ -503,10 +503,10 @@ mod tests { fn subsequent_acks_after_certificate_reached(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let num_validators = 4; - let fixture = fixture(NAMESPACE, &mut test_rng(), num_validators); + let fixture = fixture(&mut test_rng(), NAMESPACE, num_validators); let mut acks = AckManager::::Digest>::new(); let sequencer = fixture.participants[1].clone(); let epoch = Epoch::new(1); @@ -541,10 +541,10 @@ mod tests { fn multiple_sequencers(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let num_validators = 4; - let fixture = fixture(NAMESPACE, &mut test_rng(), num_validators); + let fixture = fixture(&mut test_rng(), NAMESPACE, num_validators); let mut acks = AckManager::::Digest>::new(); let sequencer1 = fixture.participants[1].clone(); @@ -581,10 +581,10 @@ mod tests { fn incomplete_quorum(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let num_validators = 4; - let fixture = fixture(NAMESPACE, &mut test_rng(), num_validators); + let fixture = fixture(&mut test_rng(), NAMESPACE, num_validators); let mut acks = AckManager::::Digest>::new(); let sequencer = fixture.participants[1].clone(); let epoch = Epoch::new(1); @@ -612,13 +612,13 @@ mod tests { fn interleaved_payloads(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { // Use 20 validators so quorum is 14 // We'll have validators [0-13] vote for payload1 and [6-19] vote for payload2 // This gives us overlapping sets but each reaches quorum let num_validators = 20; - let fixture = fixture(NAMESPACE, &mut test_rng(), num_validators); + let fixture = fixture(&mut test_rng(), NAMESPACE, num_validators); let mut acks = AckManager::::Digest>::new(); let sequencer = fixture.participants[1].clone(); let epoch = Epoch::new(1); diff --git a/consensus/src/ordered_broadcast/config.rs b/consensus/src/ordered_broadcast/config.rs index 042e7244a5..b861cf647d 100644 --- a/consensus/src/ordered_broadcast/config.rs +++ b/consensus/src/ordered_broadcast/config.rs @@ -1,4 +1,4 @@ -use super::types::{Activity, Context, SequencersProvider}; +use super::types::{Activity, ChunkSigner, ChunkVerifier, Context, SequencersProvider}; use crate::{ types::{Epoch, EpochDelta}, Automaton, Monitor, Relay, Reporter, @@ -19,7 +19,15 @@ pub struct Config< M: Monitor, > { /// The signer used when this engine acts as a sequencer. - pub sequencer_signer: Option, + /// + /// Create with `ChunkSigner::new(namespace, signer)`. + pub sequencer_signer: Option>, + + /// Verifier for node signatures. + /// + /// Create with `ChunkVerifier::new(namespace)` using the same namespace + /// as the `ChunkSigner`. + pub chunk_verifier: ChunkVerifier, /// Provider for epoch-specific sequencers set. pub sequencers_provider: S, @@ -40,10 +48,6 @@ pub struct Config< /// be involved in the current broadcast attempt). pub monitor: M, - /// The application namespace used to sign over different types of messages. - /// Used to prevent replay attacks on other applications. - pub namespace: Vec, - /// Whether proposals are sent as priority. pub priority_proposals: bool, diff --git a/consensus/src/ordered_broadcast/engine.rs b/consensus/src/ordered_broadcast/engine.rs index 4ebb497c6c..3a326bd9ea 100644 --- a/consensus/src/ordered_broadcast/engine.rs +++ b/consensus/src/ordered_broadcast/engine.rs @@ -10,7 +10,8 @@ use super::{ metrics, scheme, types::{ - Ack, Activity, Chunk, Context, Error, Lock, Node, Parent, Proposal, SequencersProvider, + Ack, Activity, Chunk, ChunkSigner, ChunkVerifier, Context, Error, Lock, Node, Parent, + Proposal, SequencersProvider, }, AckManager, Config, TipManager, }; @@ -76,7 +77,7 @@ pub struct Engine< // Interfaces //////////////////////////////////////// context: ContextCell, - sequencer_signer: Option, + sequencer_signer: Option>, sequencers_provider: S, validators_provider: P, automaton: A, @@ -88,8 +89,8 @@ pub struct Engine< // Namespace Constants //////////////////////////////////////// - // The namespace signatures. - namespace: Vec, + // Verifier for chunk signatures. + chunk_verifier: ChunkVerifier, //////////////////////////////////////// // Timeouts @@ -223,7 +224,7 @@ impl< relay: cfg.relay, reporter: cfg.reporter, monitor: cfg.monitor, - namespace: cfg.namespace, + chunk_verifier: cfg.chunk_verifier, rebroadcast_timeout: cfg.rebroadcast_timeout, rebroadcast_deadline: None, epoch_bounds: cfg.epoch_bounds, @@ -745,7 +746,7 @@ impl< } // Construct new node - let node = Node::sign(&self.namespace, signer, height, payload, parent); + let node = Node::sign(signer, height, payload, parent); // Deal with the chunk as if it were received over the network self.handle_node(&node).await; @@ -882,7 +883,7 @@ impl< // Verify the node node.verify( &mut self.context, - &self.namespace, + &self.chunk_verifier, &self.validators_provider, ) } diff --git a/consensus/src/ordered_broadcast/mocks/reporter.rs b/consensus/src/ordered_broadcast/mocks/reporter.rs index e6e90f6ec3..a2ff5ce30f 100644 --- a/consensus/src/ordered_broadcast/mocks/reporter.rs +++ b/consensus/src/ordered_broadcast/mocks/reporter.rs @@ -1,7 +1,7 @@ use crate::{ ordered_broadcast::{ scheme, - types::{Activity, Chunk, Lock, Proposal}, + types::{Activity, Chunk, ChunkVerifier, Lock, Proposal}, }, types::Epoch, }; @@ -29,8 +29,8 @@ pub struct Reporter { // RNG used for signature verification with scheme. rng: R, - // Application namespace - namespace: Vec, + // Verifier for node signatures. + chunk_verifier: ChunkVerifier, // Scheme for verification scheme: S, @@ -58,7 +58,7 @@ where { pub fn new( rng: R, - namespace: &[u8], + chunk_verifier: ChunkVerifier, scheme: S, limit_misses: Option, ) -> (Self, Mailbox) { @@ -67,7 +67,7 @@ where Self { rng, mailbox: receiver, - namespace: namespace.to_vec(), + chunk_verifier, scheme, proposals: HashSet::new(), limit_misses, @@ -88,7 +88,7 @@ where match msg { Message::Proposal(proposal) => { // Verify properly constructed (not needed in production) - if !proposal.verify(&self.namespace) { + if !proposal.verify(&self.chunk_verifier) { panic!("Invalid proof"); } diff --git a/consensus/src/ordered_broadcast/mod.rs b/consensus/src/ordered_broadcast/mod.rs index d101e9f616..7dbe461f0c 100644 --- a/consensus/src/ordered_broadcast/mod.rs +++ b/consensus/src/ordered_broadcast/mod.rs @@ -72,7 +72,11 @@ pub mod mocks; #[cfg(test)] mod tests { - use super::{mocks, Config, Engine}; + use super::{ + mocks, + types::{ChunkSigner, ChunkVerifier}, + Config, Engine, + }; use crate::{ ordered_broadcast::scheme::{ bls12381_multisig, bls12381_threshold, ed25519, secp256r1, Scheme, @@ -220,9 +224,10 @@ mod tests { assert!(validators_provider.register(epoch, fixture.schemes[idx].clone())); let automaton = mocks::Automaton::::new(invalid_when); + let chunk_verifier = ChunkVerifier::new(namespace); let (reporter, reporter_mailbox) = mocks::Reporter::new( context.clone(), - namespace, + chunk_verifier.clone(), fixture.verifier.clone(), misses_allowed, ); @@ -232,14 +237,17 @@ mod tests { let engine = Engine::new( context.with_label("engine"), Config { - sequencer_signer: Some(fixture.private_keys[idx].clone()), + sequencer_signer: Some(ChunkSigner::new( + namespace, + fixture.private_keys[idx].clone(), + )), + chunk_verifier, sequencers_provider: sequencers, validators_provider, automaton: automaton.clone(), relay: automaton.clone(), reporter: reporters.get(validator).unwrap().clone(), monitor, - namespace: namespace.to_vec(), priority_proposals: false, priority_acks: false, rebroadcast_timeout, @@ -336,14 +344,14 @@ mod tests { fn all_online(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnOnce(&mut deterministic::Context, &[u8], u32) -> Fixture, { let runner = deterministic::Runner::timed(Duration::from_secs(120)); runner.start(|mut context| async move { let epoch = Epoch::new(111); let num_validators = 4; - let fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); let (_oracle, mut registrations) = initialize_simulation(context.with_label("simulation"), &fixture, RELIABLE_LINK) @@ -383,7 +391,7 @@ mod tests { fn unclean_shutdown(fixture: F) where S: Scheme, - F: Fn(&[u8], &mut deterministic::Context, u32) -> Fixture + Clone, + F: Fn(&mut deterministic::Context, &[u8], u32) -> Fixture + Clone, { let mut prev_checkpoint = None; let epoch = Epoch::new(111); @@ -394,7 +402,7 @@ mod tests { loop { let fixture = fixture.clone(); let f = |mut context: deterministic::Context| async move { - let fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); let (network, mut oracle) = Network::new( context.with_label("network"), @@ -470,14 +478,14 @@ mod tests { fn network_partition(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnOnce(&mut deterministic::Context, &[u8], u32) -> Fixture, { let runner = deterministic::Runner::timed(Duration::from_secs(60)); runner.start(|mut context| async move { let epoch = Epoch::new(111); let num_validators = 4; - let fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); // Configure the network let (mut oracle, mut registrations) = @@ -533,7 +541,7 @@ mod tests { fn slow_and_lossy_links(fixture: F, seed: u64) -> String where S: Scheme, - F: Fn(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: Fn(&mut deterministic::Context, &[u8], u32) -> Fixture, { let cfg = deterministic::Config::new() .with_seed(seed) @@ -543,7 +551,7 @@ mod tests { runner.start(|mut context| async move { let epoch = Epoch::new(111); let num_validators = 4; - let fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); let (mut oracle, mut registrations) = initialize_simulation(context.with_label("simulation"), &fixture, RELIABLE_LINK) @@ -657,14 +665,14 @@ mod tests { fn invalid_signature_injection(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnOnce(&mut deterministic::Context, &[u8], u32) -> Fixture, { let runner = deterministic::Runner::timed(Duration::from_secs(30)); runner.start(|mut context| async move { let epoch = Epoch::new(111); let num_validators = 4; - let fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); let (_oracle, mut registrations) = initialize_simulation(context.with_label("simulation"), &fixture, RELIABLE_LINK) @@ -704,14 +712,14 @@ mod tests { fn updated_epoch(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnOnce(&mut deterministic::Context, &[u8], u32) -> Fixture, { let runner = deterministic::Runner::timed(Duration::from_secs(60)); runner.start(|mut context| async move { let epoch = Epoch::new(111); let num_validators = 4; - let fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); // Setup network let (mut oracle, mut registrations) = @@ -737,9 +745,10 @@ mod tests { validators_providers.insert(validator.clone(), validators_provider.clone()); let automaton = mocks::Automaton::::new(|_| false); + let chunk_verifier = ChunkVerifier::new(namespace); let (reporter, reporter_mailbox) = mocks::Reporter::new( context.clone(), - namespace, + chunk_verifier.clone(), fixture.verifier.clone(), Some(5), ); @@ -749,14 +758,17 @@ mod tests { let engine = Engine::new( context.with_label("engine"), Config { - sequencer_signer: Some(fixture.private_keys[idx].clone()), + sequencer_signer: Some(ChunkSigner::new( + namespace, + fixture.private_keys[idx].clone(), + )), + chunk_verifier, sequencers_provider: sequencers, validators_provider, relay: automaton.clone(), automaton: automaton.clone(), reporter: reporters.get(validator).unwrap().clone(), monitor, - namespace: namespace.to_vec(), epoch_bounds: (EpochDelta::new(1), EpochDelta::new(1)), height_bound: 2, rebroadcast_timeout: Duration::from_secs(1), @@ -837,13 +849,13 @@ mod tests { fn external_sequencer(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnOnce(&mut deterministic::Context, &[u8], u32) -> Fixture, { let runner = deterministic::Runner::timed(Duration::from_secs(60)); runner.start(|mut context| async move { let epoch = Epoch::new(111); let num_validators = 4; - let fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); // Generate sequencer (external, not a validator) let sequencer = PrivateKey::from_seed(u64::MAX); @@ -889,9 +901,10 @@ mod tests { let automaton = mocks::Automaton::::new(|_| false); + let chunk_verifier = ChunkVerifier::new(namespace); let (reporter, reporter_mailbox) = mocks::Reporter::new( context.clone(), - namespace, + chunk_verifier.clone(), fixture.verifier.clone(), Some(5), ); @@ -901,14 +914,14 @@ mod tests { let engine = Engine::new( context.with_label("engine"), Config { - sequencer_signer: None::, // Validators don't propose in this test + sequencer_signer: None::>, // Validators don't propose in this test + chunk_verifier, sequencers_provider: sequencers, validators_provider, relay: automaton.clone(), automaton: automaton.clone(), reporter: reporters.get(validator).unwrap().clone(), monitor, - namespace: namespace.to_vec(), epoch_bounds: (EpochDelta::new(1), EpochDelta::new(1)), height_bound: 2, rebroadcast_timeout: Duration::from_secs(5), @@ -931,9 +944,10 @@ mod tests { { let context = context.with_label("sequencer"); let automaton = mocks::Automaton::::new(|_| false); + let chunk_verifier = ChunkVerifier::new(namespace); let (reporter, reporter_mailbox) = mocks::Reporter::new( context.clone(), - namespace, + chunk_verifier.clone(), fixture.verifier.clone(), Some(5), ); @@ -948,7 +962,8 @@ mod tests { let engine = Engine::new( context.with_label("engine"), Config { - sequencer_signer: Some(sequencer.clone()), + sequencer_signer: Some(ChunkSigner::new(namespace, sequencer.clone())), + chunk_verifier, sequencers_provider: mocks::Sequencers::::new(vec![ sequencer.public_key() ]), @@ -957,7 +972,6 @@ mod tests { automaton, reporter: reporters.get(&sequencer.public_key()).unwrap().clone(), monitor: mocks::Monitor::new(epoch), - namespace: namespace.to_vec(), epoch_bounds: (EpochDelta::new(1), EpochDelta::new(1)), height_bound: 2, rebroadcast_timeout: Duration::from_secs(5), @@ -1003,7 +1017,7 @@ mod tests { fn run_1k(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnOnce(&mut deterministic::Context, &[u8], u32) -> Fixture, { let cfg = deterministic::Config::new(); let runner = deterministic::Runner::new(cfg); @@ -1011,7 +1025,7 @@ mod tests { runner.start(|mut context| async move { let epoch = Epoch::new(111); let num_validators = 10; - let fixture = fixture(TEST_NAMESPACE, &mut context, num_validators); + let fixture = fixture(&mut context, TEST_NAMESPACE, num_validators); let delayed_link = Link { latency: Duration::from_millis(80), diff --git a/consensus/src/ordered_broadcast/tip_manager.rs b/consensus/src/ordered_broadcast/tip_manager.rs index 19885bd639..177a051d5d 100644 --- a/consensus/src/ordered_broadcast/tip_manager.rs +++ b/consensus/src/ordered_broadcast/tip_manager.rs @@ -58,7 +58,7 @@ mod tests { use super::*; use crate::ordered_broadcast::{ scheme::{bls12381_multisig, bls12381_threshold, ed25519, secp256r1, Scheme}, - types::Chunk, + types::{Chunk, ChunkSigner}, }; use commonware_cryptography::{ bls12381::primitives::variant::{MinPk, MinSig}, @@ -81,9 +81,6 @@ mod tests { height: u64, payload: &str, ) -> Node { - use crate::ordered_broadcast::types::chunk_namespace; - use commonware_codec::Encode; - let sequencer = fixture.participants[sequencer_idx].clone(); let digest = Sha256::hash(payload.as_bytes()); let chunk = Chunk::new(sequencer, height, digest); @@ -92,9 +89,8 @@ mod tests { // which is ed25519::Signature for our PublicKey type) let mut rng = StdRng::seed_from_u64(sequencer_idx as u64); let private_key = commonware_cryptography::ed25519::PrivateKey::random(&mut rng); - let namespace = chunk_namespace(b"test"); - let message = chunk.encode(); - let signature = private_key.sign(namespace.as_ref(), &message); + let mut signer = ChunkSigner::new(b"test", private_key); + let signature = signer.sign(&chunk); Node::new(chunk, signature, None) } @@ -108,9 +104,9 @@ mod tests { fn put_new_tip(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { - let fixture = fixture(NAMESPACE, &mut test_rng(), 4); + let fixture = fixture(&mut test_rng(), NAMESPACE, 4); let mut manager = TipManager::::new(); let node = create_node(&fixture, 0, 1, "payload"); let key = node.chunk.sequencer.clone(); @@ -134,9 +130,9 @@ mod tests { fn put_same_height_same_payload(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { - let fixture = fixture(NAMESPACE, &mut test_rng(), 4); + let fixture = fixture(&mut test_rng(), NAMESPACE, 4); let mut manager = TipManager::::new(); let node = create_node(&fixture, 0, 1, "payload"); let key = node.chunk.sequencer.clone(); @@ -161,9 +157,9 @@ mod tests { fn put_higher_tip(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { - let fixture = fixture(NAMESPACE, &mut test_rng(), 4); + let fixture = fixture(&mut test_rng(), NAMESPACE, 4); let mut manager = TipManager::::new(); let node1 = create_node(&fixture, 0, 1, "payload1"); let key = node1.chunk.sequencer.clone(); @@ -189,9 +185,9 @@ mod tests { fn put_lower_tip_panics(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { - let fixture = fixture(NAMESPACE, &mut test_rng(), 4); + let fixture = fixture(&mut test_rng(), NAMESPACE, 4); let mut manager = TipManager::::new(); let node1 = create_node(&fixture, 0, 2, "payload"); assert!(manager.put(&node1)); @@ -221,9 +217,9 @@ mod tests { fn put_same_height_different_payload_panics(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { - let fixture = fixture(NAMESPACE, &mut test_rng(), 4); + let fixture = fixture(&mut test_rng(), NAMESPACE, 4); let mut manager = TipManager::::new(); let node1 = create_node(&fixture, 0, 1, "payload1"); assert!(manager.put(&node1)); @@ -279,9 +275,9 @@ mod tests { fn multiple_sequencers(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { - let fixture = fixture(NAMESPACE, &mut test_rng(), 4); + let fixture = fixture(&mut test_rng(), NAMESPACE, 4); let mut manager = TipManager::::new(); let node1 = create_node(&fixture, 0, 1, "payload1"); let node2 = create_node(&fixture, 1, 2, "payload2"); @@ -309,9 +305,9 @@ mod tests { fn put_multiple_updates(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { - let fixture = fixture(NAMESPACE, &mut test_rng(), 4); + let fixture = fixture(&mut test_rng(), NAMESPACE, 4); let mut manager = TipManager::::new(); // Insert tip with height 1. diff --git a/consensus/src/ordered_broadcast/types.rs b/consensus/src/ordered_broadcast/types.rs index aa7a2bd496..2bc37cbd86 100644 --- a/consensus/src/ordered_broadcast/types.rs +++ b/consensus/src/ordered_broadcast/types.rs @@ -158,7 +158,7 @@ pub const ACK_SUFFIX: &[u8] = b"_ACK"; /// This provides domain separation for signatures, preventing cross-protocol attacks /// by ensuring signatures for chunks cannot be reused for other message types. #[inline] -pub fn chunk_namespace(namespace: &[u8]) -> Vec { +fn chunk_namespace(namespace: &[u8]) -> Vec { union(namespace, CHUNK_SUFFIX) } @@ -171,6 +171,82 @@ pub fn ack_namespace(namespace: &[u8]) -> Vec { union(namespace, ACK_SUFFIX) } +/// Namespace type for chunk signing/verification. +/// +/// This type encapsulates the pre-computed namespace bytes used for signing and +/// verifying chunks (nodes and proposals). +#[derive(Clone, Debug)] +pub struct ChunkNamespace(Vec); + +impl Namespace for ChunkNamespace { + fn derive(namespace: &[u8]) -> Self { + Self(chunk_namespace(namespace)) + } +} + +/// Signer for chunk operations. +/// +/// The namespace is pre-computed at construction time. +#[derive(Clone)] +pub struct ChunkSigner { + signer: C, + namespace: ChunkNamespace, +} + +impl ChunkSigner { + /// Creates a new ChunkSigner with the given namespace and signer. + /// + /// The chunk namespace is pre-computed from the base namespace. + pub fn new(namespace: &[u8], signer: C) -> Self { + Self { + signer, + namespace: ChunkNamespace::derive(namespace), + } + } + + /// Returns the public key of the underlying signer. + pub fn public_key(&self) -> C::PublicKey { + self.signer.public_key() + } + + /// Signs a chunk and returns the signature. + pub fn sign(&mut self, chunk: &Chunk) -> C::Signature + where + P: PublicKey, + D: Digest, + { + self.signer.sign(&self.namespace.0, &chunk.encode()) + } +} + +/// Verifier for chunk operations. +/// +/// The namespace is pre-computed at construction time. +#[derive(Clone)] +pub struct ChunkVerifier { + namespace: ChunkNamespace, +} + +impl ChunkVerifier { + /// Creates a new ChunkVerifier with the given namespace. + pub fn new(namespace: &[u8]) -> Self { + Self { + namespace: ChunkNamespace::derive(namespace), + } + } + + /// Verifies a chunk signature. + pub fn verify( + &self, + chunk: &Chunk, + signature: &P::Signature, + ) -> bool { + chunk + .sequencer + .verify(&self.namespace.0, &chunk.encode(), signature) + } +} + /// Used as the [crate::Automaton::Context] type. /// /// Carries the necessary context for the automaton to verify a payload, including @@ -451,86 +527,6 @@ impl Node { } } - /// Verify the Node (and its parent). - /// - /// This ensures: - /// 1. The sequencer's signature over the chunk is valid - /// 2. For non-genesis nodes, the parent's certificate is valid - /// - /// If verification is successful, returns: - /// - None for genesis nodes - /// - Some(parent_chunk) for non-genesis nodes - /// - /// If verification fails, returns an appropriate error. - pub fn verify( - &self, - rng: &mut R, - namespace: &[u8], - provider: &impl Provider, - ) -> Result>, Error> - where - R: CryptoRngCore, - S: scheme::Scheme, - { - // Verify chunk - let chunk_namespace = chunk_namespace(namespace); - let message = self.chunk.encode(); - if !self - .chunk - .sequencer - .verify(chunk_namespace.as_ref(), &message, &self.signature) - { - return Err(Error::InvalidSequencerSignature); - } - let Some(parent) = &self.parent else { - return Ok(None); - }; - - // Verify parent (if present) - let parent_chunk = Chunk::new( - self.chunk.sequencer.clone(), - self.chunk - .height - .checked_sub(1) - .ok_or(Error::ParentMissing)?, - parent.digest, - ); - - // Verify parent certificate using the scheme for the parent's epoch - let parent_scheme = provider - .scoped(parent.epoch) - .ok_or(Error::UnknownScheme(parent.epoch))?; - let ack_ctx = AckSubject { - chunk: &parent_chunk, - epoch: parent.epoch, - }; - if !parent_scheme.verify_certificate::(rng, ack_ctx, &parent.certificate) { - return Err(Error::InvalidCertificate); - } - Ok(Some(parent_chunk)) - } - - /// Generate a new node with the given chunk, signature, (and parent). - /// - /// This is used by sequencers to create and sign new nodes for broadcast. - /// For non-genesis nodes (height > 0), a parent with a certificate must be provided. - pub fn sign( - namespace: &[u8], - signer: &mut C, - height: u64, - payload: D, - parent: Option>, - ) -> Self - where - C: Signer, - { - let chunk_namespace = chunk_namespace(namespace); - let pub_key = signer.public_key(); - let chunk = Chunk::new(pub_key, height, payload); - let signature = signer.sign(chunk_namespace.as_ref(), &chunk.encode()); - Self::new(chunk, signature, parent) - } - /// Decode a Node from network bytes with epoch-aware certificate decoding. /// /// This method performs staged decoding: @@ -593,6 +589,74 @@ impl Node { parent, }) } + + /// Signs and creates a new Node. + /// + /// This is used by sequencers to create and sign new nodes for broadcast. + /// For non-genesis nodes (height > 0), a parent with a certificate must be provided. + pub fn sign( + signer: &mut ChunkSigner, + height: u64, + payload: D, + parent: Option>, + ) -> Self + where + C: Signer, + { + let chunk = Chunk::new(signer.public_key(), height, payload); + let signature = signer.sign(&chunk); + Self::new(chunk, signature, parent) + } + + /// Verifies a Node (and its parent). + /// + /// This ensures: + /// 1. The sequencer's signature over the chunk is valid + /// 2. For non-genesis nodes, the parent's certificate is valid + /// + /// If verification is successful, returns: + /// - None for genesis nodes + /// - Some(parent_chunk) for non-genesis nodes + /// + /// If verification fails, returns an appropriate error. + pub fn verify( + &self, + rng: &mut R, + verifier: &ChunkVerifier, + provider: &impl Provider, + ) -> Result>, Error> + where + S: scheme::Scheme, + { + // Verify chunk signature + if !verifier.verify(&self.chunk, &self.signature) { + return Err(Error::InvalidSequencerSignature); + } + let Some(parent) = &self.parent else { + return Ok(None); + }; + + // Verify parent (if present) + let parent_chunk = Chunk::new( + self.chunk.sequencer.clone(), + self.chunk + .height + .checked_sub(1) + .expect("non-genesis nodes should have height > 0"), + parent.digest, + ); + let ctx = AckSubject { + chunk: &parent_chunk, + epoch: parent.epoch, + }; + let scheme = provider + .scoped(parent.epoch) + .ok_or(Error::UnknownScheme(parent.epoch))?; + if !scheme.verify_certificate::(rng, ctx, &parent.certificate) { + return Err(Error::InvalidCertificate); + } + Ok(Some(parent_chunk)) + } } impl Hash for Node { @@ -890,17 +954,11 @@ impl Proposal { Self { chunk, signature } } - /// Verify the Proposal. + /// Verifies the proposal's signature. /// - /// This ensures that the sequencer's signature over the chunk is valid. - /// Returns true if the signature is valid, false otherwise. - pub fn verify(&self, namespace: &[u8]) -> bool { - // Verify chunk - let chunk_namespace = chunk_namespace(namespace); - let message = self.chunk.encode(); - self.chunk - .sequencer - .verify(chunk_namespace.as_ref(), &message, &self.signature) + /// Returns true if the sequencer's signature over the chunk is valid. + pub fn verify(&self, verifier: &ChunkVerifier) -> bool { + verifier.verify(&self.chunk, &self.signature) } } @@ -1075,6 +1133,14 @@ mod tests { const NAMESPACE: &[u8] = b"test"; + fn chunk_verifier() -> ChunkVerifier { + ChunkVerifier::new(NAMESPACE) + } + + fn chunk_signer(signer: PrivateKey) -> ChunkSigner { + ChunkSigner::new(NAMESPACE, signer) + } + // Helper function to create a sample digest fn sample_digest(v: u8) -> Sha256Digest { Sha256Digest::from([v; 32]) // Simple fixed digest for testing @@ -1088,10 +1154,10 @@ mod tests { /// Generate a fixture using the provided generator function with a specific seed. fn setup_seeded(n: u32, seed: u64, fixture: F) -> Fixture where - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = StdRng::seed_from_u64(seed); - fixture(NAMESPACE, &mut rng, n) + fixture(&mut rng, NAMESPACE, n) } #[test] @@ -1107,9 +1173,9 @@ mod tests { fn parent_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { - let fixture = fixture(NAMESPACE, &mut test_rng(), 4); + let fixture = fixture(&mut test_rng(), NAMESPACE, 4); let chunk = Chunk::new(fixture.participants[0].clone(), 0, sample_digest(1)); let epoch = Epoch::new(5); let quorum = commonware_utils::quorum(fixture.schemes.len() as u32) as usize; @@ -1150,9 +1216,9 @@ mod tests { fn node_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { - let fixture = fixture(NAMESPACE, &mut test_rng(), 4); + let fixture = fixture(&mut test_rng(), NAMESPACE, 4); let ed_scheme = sample_scheme(0); let public_key = ed_scheme.public_key(); let chunk_namespace = chunk_namespace(NAMESPACE); @@ -1225,9 +1291,9 @@ mod tests { fn node_read_staged(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { - let fixture = fixture(NAMESPACE, &mut test_rng(), 4); + let fixture = fixture(&mut test_rng(), NAMESPACE, 4); // Create a provider that returns the verifier for any epoch. // This simulates the normal case where the scheme is available. @@ -1323,9 +1389,9 @@ mod tests { fn ack_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { - let fixture = fixture(NAMESPACE, &mut test_rng(), 4); + let fixture = fixture(&mut test_rng(), NAMESPACE, 4); let chunk = Chunk::new(fixture.participants[0].clone(), 42, sample_digest(1)); let epoch = Epoch::new(5); @@ -1364,10 +1430,10 @@ mod tests { fn activity_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); + let fixture = fixture(&mut rng, NAMESPACE, 4); let scheme = sample_scheme(0); let public_key = scheme.public_key(); let chunk_namespace = chunk_namespace(NAMESPACE); @@ -1461,16 +1527,17 @@ mod tests { assert_eq!(decoded.signature, proposal.signature); // Verify the decoded proposal - assert!(decoded.verify(NAMESPACE)); + let verifier = chunk_verifier(); + assert!(decoded.verify(&verifier)); } fn lock_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); + let fixture = fixture(&mut rng, NAMESPACE, 4); let public_key = sample_scheme(0).public_key(); let chunk = Chunk::new(public_key, 42, sample_digest(1)); let epoch = Epoch::new(5); @@ -1518,24 +1585,21 @@ mod tests { fn node_sign_verify(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); - let mut scheme = sample_scheme(0); + let fixture = fixture(&mut rng, NAMESPACE, 4); + let scheme = sample_scheme(0); let public_key = scheme.public_key(); + let mut signer = chunk_signer(scheme); + let verifier = chunk_verifier(); let quorum = commonware_utils::quorum(fixture.schemes.len() as u32) as usize; // Test genesis node (no parent) - let node = Node::::sign( - NAMESPACE, - &mut scheme, - 0, - sample_digest(1), - None, - ); + let node: Node = + Node::sign(&mut signer, 0, sample_digest(1), None); let provider = ConstantProvider::new(fixture.verifier.clone()); - let result = node.verify(&mut rng, NAMESPACE, &provider); + let result = node.verify(&mut rng, &verifier, &provider); assert!(result.is_ok()); assert!(result.unwrap().is_none()); @@ -1561,15 +1625,10 @@ mod tests { parent_epoch, parent_certificate, )); - let node = Node::::sign( - NAMESPACE, - &mut scheme, - 1, - sample_digest(2), - parent, - ); + let node: Node = + Node::sign(&mut signer, 1, sample_digest(2), parent); - let result = node.verify(&mut rng, NAMESPACE, &provider); + let result = node.verify(&mut rng, &verifier, &provider); assert!(result.is_ok()); assert!(result.unwrap().is_some()); } @@ -1587,10 +1646,10 @@ mod tests { fn ack_sign_verify(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); + let fixture = fixture(&mut rng, NAMESPACE, 4); let public_key = sample_scheme(0).public_key(); let chunk = Chunk::new(public_key, 42, sample_digest(1)); let epoch = Epoch::new(5); @@ -1612,10 +1671,10 @@ mod tests { fn certificate_assembly(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); + let fixture = fixture(&mut rng, NAMESPACE, 4); let public_key = sample_scheme(0).public_key(); let chunk = Chunk::new(public_key, 42, sample_digest(1)); let epoch = Epoch::new(5); @@ -1656,10 +1715,10 @@ mod tests { fn lock_verify(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); + let fixture = fixture(&mut rng, NAMESPACE, 4); let public_key = sample_scheme(0).public_key(); let chunk = Chunk::new(public_key, 42, sample_digest(1)); let epoch = Epoch::new(5); @@ -1707,19 +1766,21 @@ mod tests { let proposal = Proposal::::new(chunk, signature); // Verify proposal - assert!(proposal.verify(NAMESPACE)); + let verifier = chunk_verifier(); + assert!(proposal.verify(&verifier)); // Test that verification fails with wrong namespace - assert!(!proposal.verify(b"wrong")); + let wrong_verifier = ChunkVerifier::new(b"wrong"); + assert!(!proposal.verify(&wrong_verifier)); } fn node_verify_invalid_signature(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); + let fixture = fixture(&mut rng, NAMESPACE, 4); let scheme = sample_scheme(0); let public_key = scheme.public_key(); @@ -1736,7 +1797,8 @@ mod tests { // Verification should succeed let provider = ConstantProvider::new(fixture.verifier); - assert!(node.verify(&mut rng, NAMESPACE, &provider).is_ok()); + let verifier = chunk_verifier(); + assert!(node.verify(&mut rng, &verifier, &provider).is_ok()); // Now create a node with invalid signature let tampered_signature = scheme.sign(chunk_namespace.as_ref(), &node.encode()); @@ -1744,7 +1806,7 @@ mod tests { // Verification should fail assert!(matches!( - invalid_node.verify(&mut rng, NAMESPACE, &provider), + invalid_node.verify(&mut rng, &verifier, &provider), Err(Error::InvalidSequencerSignature) )); } @@ -1762,10 +1824,10 @@ mod tests { fn node_verify_invalid_parent_signature(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); + let fixture = fixture(&mut rng, NAMESPACE, 4); let scheme = sample_scheme(0); let public_key = scheme.public_key(); let quorum = commonware_utils::quorum(fixture.schemes.len() as u32) as usize; @@ -1803,7 +1865,8 @@ mod tests { // Verification should succeed let provider = ConstantProvider::new(fixture.verifier.clone()); - assert!(node.verify(&mut rng, NAMESPACE, &provider).is_ok()); + let verifier = chunk_verifier(); + assert!(node.verify(&mut rng, &verifier, &provider).is_ok()); // Now create a parent with invalid certificate // Generate certificate with the wrong keys (sign with schemes[1..] but pretend it's from schemes[0..]) @@ -1832,7 +1895,7 @@ mod tests { // Verification should fail because the parent certificate was signed for different epoch assert!(matches!( - node.verify(&mut rng, NAMESPACE, &provider), + node.verify(&mut rng, &verifier, &provider), Err(Error::InvalidCertificate) )); } @@ -1850,10 +1913,10 @@ mod tests { fn ack_verify_invalid_signature(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); + let fixture = fixture(&mut rng, NAMESPACE, 4); // Create a chunk and ack let public_key = sample_scheme(0).public_key(); let chunk = Chunk::new(public_key, 42, sample_digest(1)); @@ -1897,7 +1960,7 @@ mod tests { fn ack_verify_wrong_validator(f: F) where S: Scheme, - F: Fn(&[u8], &mut StdRng, u32) -> Fixture, + F: Fn(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); let fixture = setup_seeded(4, 0, &f); @@ -1931,7 +1994,7 @@ mod tests { fn lock_verify_invalid_signature(f: F) where S: Scheme, - F: Fn(&[u8], &mut StdRng, u32) -> Fixture, + F: Fn(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); let fixture = setup_seeded(4, 0, &f); @@ -2001,10 +2064,12 @@ mod tests { let proposal = Proposal::::new(chunk, signature); // Verify with correct namespace - should pass - assert!(proposal.verify(NAMESPACE)); + let verifier = chunk_verifier(); + assert!(proposal.verify(&verifier)); // Verify with wrong namespace - should fail - assert!(!proposal.verify(b"wrong_namespace")); + let wrong_verifier = ChunkVerifier::new(b"wrong_namespace"); + assert!(!proposal.verify(&wrong_verifier)); } #[test] @@ -2022,16 +2087,17 @@ mod tests { let proposal = Proposal::::new(chunk, signature); // Verification should fail because the signature doesn't match the sequencer's public key - assert!(!proposal.verify(NAMESPACE)); + let verifier = chunk_verifier(); + assert!(!proposal.verify(&verifier)); } fn node_genesis_with_parent_fails(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); + let fixture = fixture(&mut rng, NAMESPACE, 4); // Try to create a node with height 0 and a parent let public_key = sample_scheme(0).public_key(); let chunk = Chunk::new(public_key.clone(), 0, sample_digest(1)); @@ -2080,10 +2146,10 @@ mod tests { fn node_non_genesis_without_parent_fails(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); + let fixture = fixture(&mut rng, NAMESPACE, 4); // Try to create a non-genesis node without a parent let public_key = sample_scheme(0).public_key(); let chunk = Chunk::new(public_key, 1, sample_digest(1)); // Height > 0 @@ -2113,10 +2179,10 @@ mod tests { fn node_genesis_with_parent_panics(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); + let fixture = fixture(&mut rng, NAMESPACE, 4); // Try to create a genesis node (height 0) with a parent - should panic in Node::new let public_key = sample_scheme(0).public_key(); @@ -2175,10 +2241,10 @@ mod tests { fn node_non_genesis_without_parent_panics(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 4); + let fixture = fixture(&mut rng, NAMESPACE, 4); // Try to create a non-genesis node (height > 0) without a parent - should panic on decode let public_key = sample_scheme(0).public_key(); diff --git a/consensus/src/simplex/actors/batcher/mod.rs b/consensus/src/simplex/actors/batcher/mod.rs index 7bf7260872..f18147d5da 100644 --- a/consensus/src/simplex/actors/batcher/mod.rs +++ b/consensus/src/simplex/actors/batcher/mod.rs @@ -109,7 +109,7 @@ mod tests { fn certificate_forwarding_from_network(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, { let n = 5; let quorum = quorum(n) as usize; @@ -133,7 +133,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup reporter mock let reporter_cfg = mocks::reporter::Config { @@ -270,7 +270,7 @@ mod tests { fn quorum_votes_construct_certificate(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, { let n = 5; let quorum_size = quorum(n) as usize; @@ -294,7 +294,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup reporter mock let reporter_cfg = mocks::reporter::Config { @@ -415,7 +415,7 @@ mod tests { fn votes_and_certificate_deduplication(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, { let n = 5; let quorum_size = quorum(n) as usize; @@ -439,7 +439,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup reporter mock let reporter_cfg = mocks::reporter::Config { @@ -606,7 +606,7 @@ mod tests { fn conflicting_votes_dont_produce_invalid_certificate(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, { let n = 7; let namespace = b"batcher_test".to_vec(); @@ -629,7 +629,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup reporter mock let reporter_cfg = mocks::reporter::Config { @@ -809,7 +809,7 @@ mod tests { fn proposal_forwarded_after_leader_set(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, { let n = 5; let namespace = b"batcher_test".to_vec(); @@ -832,7 +832,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup reporter mock let reporter_cfg = mocks::reporter::Config { @@ -935,7 +935,7 @@ mod tests { fn proposal_forwarded_before_leader_set(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, { let n = 5; let namespace = b"batcher_test".to_vec(); @@ -958,7 +958,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup reporter mock let reporter_cfg = mocks::reporter::Config { @@ -1062,7 +1062,7 @@ mod tests { fn leader_activity_detection(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, { let n = 5; let namespace = b"batcher_test".to_vec(); @@ -1086,7 +1086,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup reporter mock let reporter_cfg = mocks::reporter::Config { @@ -1210,7 +1210,7 @@ mod tests { fn votes_skipped_for_finalized_views(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, { let n = 5; let quorum_size = quorum(n) as usize; @@ -1234,7 +1234,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup reporter mock let reporter_cfg = mocks::reporter::Config { diff --git a/consensus/src/simplex/actors/batcher/verifier.rs b/consensus/src/simplex/actors/batcher/verifier.rs index 48daa7893e..cc0ff0fd4f 100644 --- a/consensus/src/simplex/actors/batcher/verifier.rs +++ b/consensus/src/simplex/actors/batcher/verifier.rs @@ -493,10 +493,10 @@ mod tests { fn add_notarize(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); @@ -559,10 +559,10 @@ mod tests { fn set_leader(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); @@ -601,10 +601,10 @@ mod tests { fn ready_and_verify_notarizes(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); let round = Round::new(Epoch::new(0), View::new(1)); @@ -673,10 +673,10 @@ mod tests { fn add_nullify(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); let round = Round::new(Epoch::new(0), View::new(1)); @@ -704,10 +704,10 @@ mod tests { fn ready_and_verify_nullifies(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); let round = Round::new(Epoch::new(0), View::new(1)); @@ -749,10 +749,10 @@ mod tests { fn add_finalize(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); let round = Round::new(Epoch::new(0), View::new(1)); @@ -795,10 +795,10 @@ mod tests { fn ready_and_verify_finalizes(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); let round = Round::new(Epoch::new(0), View::new(1)); @@ -845,10 +845,10 @@ mod tests { fn leader_proposal_filters_messages(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 3); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 3); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); let round = Round::new(Epoch::new(0), View::new(1)); @@ -889,10 +889,10 @@ mod tests { fn set_leader_twice_panics(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 3); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 3); let mut verifier = Verifier::::new(schemes[0].clone(), 3); verifier.set_leader(0); verifier.set_leader(1); @@ -937,10 +937,10 @@ mod tests { fn notarizes_wait_for_quorum(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); let round = Round::new(Epoch::new(0), View::new(1)); @@ -981,10 +981,10 @@ mod tests { fn ready_notarizes_without_leader(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 3); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 3); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); let round = Round::new(Epoch::new(0), View::new(1)); @@ -1024,10 +1024,10 @@ mod tests { fn ready_finalizes_without_leader(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 3); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 3); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); let round = Round::new(Epoch::new(0), View::new(1)); @@ -1066,10 +1066,10 @@ mod tests { fn verify_notarizes_empty(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 3); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 3); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); let round = Round::new(Epoch::new(0), View::new(1)); @@ -1092,10 +1092,10 @@ mod tests { fn verify_nullifies_empty(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 3); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 3); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); assert!(verifier.nullifies.is_empty()); @@ -1119,10 +1119,10 @@ mod tests { fn verify_finalizes_empty(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 3); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 3); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); verifier.set_leader(0); @@ -1147,10 +1147,10 @@ mod tests { fn ready_notarizes_exact_quorum(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); let round = Round::new(Epoch::new(0), View::new(1)); @@ -1200,10 +1200,10 @@ mod tests { fn ready_nullifies_exact_quorum(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); let round = Round::new(Epoch::new(0), View::new(1)); @@ -1240,10 +1240,10 @@ mod tests { fn ready_finalizes_exact_quorum(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); let mut verifier = Verifier::::new(schemes[0].clone(), quorum); let round = Round::new(Epoch::new(0), View::new(1)); @@ -1285,10 +1285,10 @@ mod tests { fn ready_notarizes_quorum_already_met_by_verified(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); assert!( schemes.len() > quorum as usize, @@ -1337,10 +1337,10 @@ mod tests { fn ready_nullifies_quorum_already_met_by_verified(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); assert!( schemes.len() > quorum as usize, @@ -1381,10 +1381,10 @@ mod tests { fn ready_finalizes_quorum_already_met_by_verified(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let Fixture { schemes, .. } = fixture(NAMESPACE, &mut rng, 5); + let Fixture { schemes, .. } = fixture(&mut rng, NAMESPACE, 5); let quorum = quorum_from_slice(&schemes); assert!( schemes.len() > quorum as usize, diff --git a/consensus/src/simplex/actors/resolver/state.rs b/consensus/src/simplex/actors/resolver/state.rs index 056205d859..943378d3a5 100644 --- a/consensus/src/simplex/actors/resolver/state.rs +++ b/consensus/src/simplex/actors/resolver/state.rs @@ -298,7 +298,7 @@ mod tests { let mut rng = StdRng::seed_from_u64(42); let Fixture { schemes, verifier, .. - } = ed25519::fixture(NAMESPACE, &mut rng, 5); + } = ed25519::fixture(&mut rng, NAMESPACE, 5); (schemes, verifier) } diff --git a/consensus/src/simplex/actors/voter/mod.rs b/consensus/src/simplex/actors/voter/mod.rs index 91e772267a..60bdafbd60 100644 --- a/consensus/src/simplex/actors/voter/mod.rs +++ b/consensus/src/simplex/actors/voter/mod.rs @@ -128,7 +128,7 @@ mod tests { fn stale_backfill(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: ElectorConfig, { let n = 5; @@ -152,7 +152,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Initialize voter actor let me = participants[0].clone(); @@ -364,7 +364,7 @@ mod tests { fn append_old_interesting_view(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: ElectorConfig, { let n = 5; @@ -389,7 +389,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup the target Voter actor (validator 0) let signing = schemes[0].clone(); @@ -642,7 +642,7 @@ mod tests { fn finalization_without_notarization_certificate(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: ElectorConfig, { let n = 5; @@ -666,7 +666,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup application mock let elector = L::default(); @@ -824,7 +824,7 @@ mod tests { fn certificate_conflicts_proposal(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: ElectorConfig, { let n = 5; @@ -848,7 +848,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup application mock let elector = L::default(); @@ -1020,7 +1020,7 @@ mod tests { fn proposal_conflicts_certificate(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: ElectorConfig, { let n = 5; @@ -1042,7 +1042,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let elector = L::default(); let reporter_cfg = mocks::reporter::Config { @@ -1199,7 +1199,7 @@ mod tests { fn certificate_verifies_proposal(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: ElectorConfig, { let n = 5; @@ -1221,7 +1221,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let elector = L::default(); let reporter_cfg = mocks::reporter::Config { @@ -1377,7 +1377,7 @@ mod tests { fn drop_our_proposal_on_conflict(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, { let n = 5; let quorum = quorum(n); @@ -1402,7 +1402,7 @@ mod tests { schemes, verifier: _, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Figure out who the leader will be for view 2 let view2_round = Round::new(epoch, View::new(2)); @@ -1595,7 +1595,7 @@ mod tests { fn populate_resolver_on_restart(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: ElectorConfig, { let n = 5; @@ -1619,7 +1619,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup application mock let elector = L::default(); @@ -1822,7 +1822,7 @@ mod tests { fn finalization_from_resolver(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: ElectorConfig, { // This is a regression test as the resolver didn't use to send @@ -1848,7 +1848,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup application mock let elector = L::default(); @@ -1986,7 +1986,7 @@ mod tests { fn no_resolver_boomerang(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: ElectorConfig, { let n = 5; @@ -2010,7 +2010,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Setup application mock let elector = L::default(); @@ -2159,7 +2159,7 @@ mod tests { fn verification_failure_emits_nullify_immediately(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: ElectorConfig, { let n = 5; @@ -2184,7 +2184,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Use participant[0] as the voter let signing = schemes[0].clone(); @@ -2384,7 +2384,7 @@ mod tests { fn no_recertification_after_replay(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: ElectorConfig, { let n = 5; @@ -2406,7 +2406,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Track certify calls across restarts let certify_calls: Arc>> = Arc::new(Mutex::new(Vec::new())); diff --git a/consensus/src/simplex/actors/voter/round.rs b/consensus/src/simplex/actors/voter/round.rs index ec987d23c8..f09e850677 100644 --- a/consensus/src/simplex/actors/voter/round.rs +++ b/consensus/src/simplex/actors/voter/round.rs @@ -550,7 +550,7 @@ mod tests { participants, verifier, .. - } = ed25519::fixture(namespace, &mut rng, 4); + } = ed25519::fixture(&mut rng, namespace, 4); let proposal_a = Proposal::new( Rnd::new(Epoch::new(1), View::new(1)), View::new(0), @@ -603,7 +603,7 @@ mod tests { participants, verifier, .. - } = ed25519::fixture(namespace, &mut rng, 4); + } = ed25519::fixture(&mut rng, namespace, 4); let proposal_a = Proposal::new( Rnd::new(Epoch::new(1), View::new(1)), View::new(0), @@ -666,7 +666,7 @@ mod tests { let namespace = b"ns"; let Fixture { schemes, verifier, .. - } = ed25519::fixture(namespace, &mut rng, 4); + } = ed25519::fixture(&mut rng, namespace, 4); let proposal = Proposal::new( Rnd::new(Epoch::new(1), View::new(1)), View::new(0), @@ -697,7 +697,7 @@ mod tests { let namespace = b"ns"; let Fixture { schemes, verifier, .. - } = ed25519::fixture(namespace, &mut rng, 4); + } = ed25519::fixture(&mut rng, namespace, 4); let local_scheme = schemes[0].clone(); // Setup round and proposal @@ -762,7 +762,7 @@ mod tests { fn construct_nullify_blocked_by_finalize() { let mut rng = StdRng::seed_from_u64(2029); let namespace = b"ns"; - let Fixture { schemes, .. } = ed25519::fixture(namespace, &mut rng, 4); + let Fixture { schemes, .. } = ed25519::fixture(&mut rng, namespace, 4); let local_scheme = schemes[0].clone(); // Setup round and proposal diff --git a/consensus/src/simplex/actors/voter/state.rs b/consensus/src/simplex/actors/voter/state.rs index 29128e6655..da38847c80 100644 --- a/consensus/src/simplex/actors/voter/state.rs +++ b/consensus/src/simplex/actors/voter/state.rs @@ -609,7 +609,7 @@ mod tests { let namespace = b"ns".to_vec(); let Fixture { schemes, verifier, .. - } = ed25519::fixture(&namespace, &mut context, 4); + } = ed25519::fixture(&mut context, &namespace, 4); let mut state = State::new( context, Config { @@ -685,7 +685,7 @@ mod tests { let runtime = deterministic::Runner::default(); runtime.start(|mut context| async move { let namespace = b"ns".to_vec(); - let Fixture { schemes, .. } = ed25519::fixture(&namespace, &mut context, 4); + let Fixture { schemes, .. } = ed25519::fixture(&mut context, &namespace, 4); let local_scheme = schemes[0].clone(); // leader of view 1 let retry = Duration::from_secs(3); let cfg = Config { @@ -744,7 +744,7 @@ mod tests { let namespace = b"ns".to_vec(); let Fixture { schemes, verifier, .. - } = ed25519::fixture(&namespace, &mut context, 4); + } = ed25519::fixture(&mut context, &namespace, 4); let cfg = Config { scheme: schemes[0].clone(), elector: ::default(), @@ -799,7 +799,7 @@ mod tests { let namespace = b"ns".to_vec(); let Fixture { schemes, verifier, .. - } = ed25519::fixture(&namespace, &mut context, 4); + } = ed25519::fixture(&mut context, &namespace, 4); let local_scheme = schemes[2].clone(); // leader of view 1 let cfg = Config { scheme: local_scheme, @@ -856,7 +856,7 @@ mod tests { let namespace = b"ns".to_vec(); let Fixture { schemes, verifier, .. - } = ed25519::fixture(&namespace, &mut context, 4); + } = ed25519::fixture(&mut context, &namespace, 4); let local_scheme = schemes[1].clone(); // leader of view 2 let cfg = Config { scheme: local_scheme, @@ -916,7 +916,7 @@ mod tests { let namespace = b"ns".to_vec(); let Fixture { schemes, verifier, .. - } = ed25519::fixture(&namespace, &mut context, 4); + } = ed25519::fixture(&mut context, &namespace, 4); let cfg = Config { scheme: verifier.clone(), elector: ::default(), @@ -962,7 +962,7 @@ mod tests { let namespace = b"ns".to_vec(); let Fixture { schemes, verifier, .. - } = ed25519::fixture(&namespace, &mut context, 4); + } = ed25519::fixture(&mut context, &namespace, 4); let cfg = Config { scheme: verifier.clone(), elector: ::default(), @@ -1005,7 +1005,7 @@ mod tests { let namespace = b"ns".to_vec(); let Fixture { schemes, verifier, .. - } = ed25519::fixture(&namespace, &mut context, 4); + } = ed25519::fixture(&mut context, &namespace, 4); let cfg = Config { scheme: verifier.clone(), elector: ::default(), @@ -1049,7 +1049,7 @@ mod tests { let namespace = b"ns".to_vec(); let Fixture { schemes, verifier, .. - } = ed25519::fixture(&namespace, &mut context, 4); + } = ed25519::fixture(&mut context, &namespace, 4); let mut scheme_iter = schemes.into_iter(); let local_scheme = scheme_iter.next().unwrap(); let other_schemes: Vec<_> = scheme_iter.collect(); @@ -1118,7 +1118,7 @@ mod tests { let runtime = deterministic::Runner::default(); runtime.start(|mut context| async move { let namespace = b"ns".to_vec(); - let Fixture { schemes, .. } = ed25519::fixture(&namespace, &mut context, 4); + let Fixture { schemes, .. } = ed25519::fixture(&mut context, &namespace, 4); let cfg = Config { scheme: schemes[0].clone(), elector: ::default(), diff --git a/consensus/src/simplex/elector.rs b/consensus/src/simplex/elector.rs index e6d28b7ed5..aefecaf959 100644 --- a/consensus/src/simplex/elector.rs +++ b/consensus/src/simplex/elector.rs @@ -241,7 +241,7 @@ mod tests { #[test] fn round_robin_rotates_through_participants() { let mut rng = StdRng::seed_from_u64(42); - let Fixture { participants, .. } = ed25519::fixture(NAMESPACE, &mut rng, 4); + let Fixture { participants, .. } = ed25519::fixture(&mut rng, NAMESPACE, 4); let participants = Set::try_from_iter(participants).unwrap(); let n = participants.len(); let elector: RoundRobinElector = @@ -264,7 +264,7 @@ mod tests { #[test] fn round_robin_cycles_through_epochs() { let mut rng = StdRng::seed_from_u64(42); - let Fixture { participants, .. } = ed25519::fixture(NAMESPACE, &mut rng, 5); + let Fixture { participants, .. } = ed25519::fixture(&mut rng, NAMESPACE, 5); let participants = Set::try_from_iter(participants).unwrap(); let n = participants.len(); let elector: RoundRobinElector = @@ -290,7 +290,7 @@ mod tests { #[test] fn round_robin_shuffled_changes_order() { let mut rng = StdRng::seed_from_u64(42); - let Fixture { participants, .. } = ed25519::fixture(NAMESPACE, &mut rng, 5); + let Fixture { participants, .. } = ed25519::fixture(&mut rng, NAMESPACE, 5); let participants = Set::try_from_iter(participants).unwrap(); let elector_no_seed: RoundRobinElector = @@ -331,7 +331,7 @@ mod tests { #[test] fn round_robin_same_seed_is_deterministic() { let mut rng = StdRng::seed_from_u64(42); - let Fixture { participants, .. } = ed25519::fixture(NAMESPACE, &mut rng, 5); + let Fixture { participants, .. } = ed25519::fixture(&mut rng, NAMESPACE, 5); let participants = Set::try_from_iter(participants).unwrap(); let elector1: RoundRobinElector = @@ -358,7 +358,7 @@ mod tests { fn random_falls_back_to_round_robin_for_view_1() { let mut rng = StdRng::seed_from_u64(42); let Fixture { participants, .. } = - bls12381_threshold::fixture::(NAMESPACE, &mut rng, 5); + bls12381_threshold::fixture::(&mut rng, NAMESPACE, 5); let participants = Set::try_from_iter(participants).unwrap(); let n = participants.len(); let elector: RandomElector = Random.build(&participants); @@ -387,7 +387,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut rng, 5); + } = bls12381_threshold::fixture::(&mut rng, NAMESPACE, 5); let participants = Set::try_from_iter(participants).unwrap(); let elector: RandomElector = Random.build(&participants); let quorum = quorum_from_slice(&schemes) as usize; @@ -442,7 +442,7 @@ mod tests { fn random_panics_on_none_certificate_after_view_1() { let mut rng = StdRng::seed_from_u64(42); let Fixture { participants, .. } = - bls12381_threshold::fixture::(NAMESPACE, &mut rng, 5); + bls12381_threshold::fixture::(&mut rng, NAMESPACE, 5); let participants = Set::try_from_iter(participants).unwrap(); let elector: RandomElector = Random.build(&participants); diff --git a/consensus/src/simplex/mod.rs b/consensus/src/simplex/mod.rs index d5a139fd96..a8104c34be 100644 --- a/consensus/src/simplex/mod.rs +++ b/consensus/src/simplex/mod.rs @@ -538,7 +538,7 @@ mod tests { fn all_online(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -568,7 +568,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -789,7 +789,7 @@ mod tests { fn observer(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -819,7 +819,7 @@ mod tests { schemes, verifier, .. - } = fixture(&namespace, &mut context, n_active); + } = fixture(&mut context, &namespace, n_active); // Add observer (no share) let private_key_observer = PrivateKey::from_seed(n_active as u64); @@ -953,7 +953,7 @@ mod tests { fn unclean_shutdown(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut StdRng, u32) -> Fixture, + F: FnMut(&mut StdRng, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -974,7 +974,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut rng, n); + } = fixture(&mut rng, &namespace, n); // Create block relay, shared across restarts. let relay = Arc::new(mocks::relay::Relay::::new()); @@ -1150,7 +1150,7 @@ mod tests { fn backfill(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -1179,7 +1179,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators except first @@ -1407,7 +1407,7 @@ mod tests { fn one_offline(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -1438,7 +1438,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators except first @@ -1669,7 +1669,7 @@ mod tests { fn slow_validator(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -1698,7 +1698,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -1857,7 +1857,7 @@ mod tests { fn all_recovery(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -1886,7 +1886,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -2070,7 +2070,7 @@ mod tests { fn partition(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -2099,7 +2099,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -2271,7 +2271,7 @@ mod tests { fn slow_and_lossy_links(seed: u64, mut fixture: F) -> String where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -2303,7 +2303,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -2501,7 +2501,7 @@ mod tests { fn conflicter(seed: u64, mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -2533,7 +2533,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -2687,7 +2687,7 @@ mod tests { fn invalid(seed: u64, mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -2719,13 +2719,13 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); // Create scheme with wrong namespace for byzantine node (index 0) let Fixture { schemes: wrong_schemes, .. - } = fixture(b"wrong-namespace", &mut context, n); + } = fixture(&mut context, b"wrong-namespace", n); let mut registrations = register_validators(&mut oracle, &participants).await; @@ -2865,7 +2865,7 @@ mod tests { fn impersonator(seed: u64, mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -2897,7 +2897,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -3035,7 +3035,7 @@ mod tests { fn equivocator(seed: u64, mut fixture: F) -> bool where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -3067,7 +3067,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -3337,7 +3337,7 @@ mod tests { fn reconfigurer(seed: u64, mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -3369,7 +3369,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -3506,7 +3506,7 @@ mod tests { fn nuller(seed: u64, mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -3538,7 +3538,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -3685,7 +3685,7 @@ mod tests { fn outdated(seed: u64, mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -3717,7 +3717,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -3847,7 +3847,7 @@ mod tests { fn run_1k(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -3877,7 +3877,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -4023,7 +4023,7 @@ mod tests { fn engine_shutdown(mut fixture: F, graceful: bool) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -4049,7 +4049,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link the single validator to itself (no-ops for completeness) @@ -4192,7 +4192,7 @@ mod tests { fn attributable_reporter_filtering(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { let n = 3; @@ -4218,7 +4218,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -4391,7 +4391,7 @@ mod tests { fn split_views_no_lockup(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Scenario: @@ -4447,7 +4447,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // ========== Create engines ========== @@ -4790,7 +4790,7 @@ mod tests { participants, schemes, .. - } = bls12381_threshold::fixture::(&namespace, &mut context, n); + } = bls12381_threshold::fixture::(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -4916,7 +4916,7 @@ mod tests { ) -> String where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { // Create context @@ -4945,7 +4945,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let mut registrations = register_validators(&mut oracle, &participants).await; // Link all validators @@ -5321,7 +5321,7 @@ mod tests { fn twins(seed: u64, n: u32, strategy: Strategy, link: Link, mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { let faults = max_faults(n); @@ -5348,7 +5348,7 @@ mod tests { participants, schemes, .. - } = fixture(&namespace, &mut context, n); + } = fixture(&mut context, &namespace, n); let participants: Arc<[_]> = participants.into(); let mut registrations = register_validators(&mut oracle, &participants).await; link_validators(&mut oracle, &participants, Action::Link(link), None).await; @@ -5636,7 +5636,7 @@ mod tests { fn test_twins(mut fixture: F) where S: Scheme, - F: FnMut(&[u8], &mut deterministic::Context, u32) -> Fixture, + F: FnMut(&mut deterministic::Context, &[u8], u32) -> Fixture, L: Elector, { for strategy in [ diff --git a/consensus/src/simplex/scheme/bls12381_threshold.rs b/consensus/src/simplex/scheme/bls12381_threshold.rs index 6412faf474..ce24881a93 100644 --- a/consensus/src/simplex/scheme/bls12381_threshold.rs +++ b/consensus/src/simplex/scheme/bls12381_threshold.rs @@ -237,8 +237,8 @@ pub fn encrypt( /// scheme instances share a consistent ordering. #[cfg(feature = "mocks")] pub fn fixture( - namespace: &[u8], rng: &mut R, + namespace: &[u8], n: u32, ) -> commonware_cryptography::certificate::mocks::Fixture< Scheme, @@ -248,8 +248,8 @@ where R: rand::RngCore + rand::CryptoRng, { commonware_cryptography::bls12381::certificate::threshold::mocks::fixture::<_, V, _>( - namespace, rng, + namespace, n, Scheme::signer, Scheme::verifier, @@ -750,7 +750,7 @@ mod tests { let mut rng = StdRng::seed_from_u64(seed); let Fixture { schemes, verifier, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut rng, n); + } = bls12381_threshold::fixture::(&mut rng, NAMESPACE, n); (schemes, verifier) } diff --git a/consensus/src/simplex/scheme/reporter.rs b/consensus/src/simplex/scheme/reporter.rs index 1428ffbec8..427f2a1227 100644 --- a/consensus/src/simplex/scheme/reporter.rs +++ b/consensus/src/simplex/scheme/reporter.rs @@ -170,13 +170,13 @@ mod tests { fn test_invalid_peer_activity_dropped() { // Invalid peer activities should be dropped when verification is enabled let mut rng = StdRng::seed_from_u64(42); - let Fixture { verifier, .. } = ed25519::fixture(NAMESPACE, &mut rng, 4); + let Fixture { verifier, .. } = ed25519::fixture(&mut rng, NAMESPACE, 4); // Create a scheme with wrong namespace to generate invalid signatures let Fixture { schemes: wrong_schemes, .. - } = ed25519::fixture(b"wrong-namespace", &mut rng, 4); + } = ed25519::fixture(&mut rng, b"wrong-namespace", 4); assert!( ed25519::Scheme::is_attributable(), @@ -209,13 +209,13 @@ mod tests { fn test_skip_verification() { // When verification is disabled, invalid activities pass through let mut rng = StdRng::seed_from_u64(42); - let Fixture { verifier, .. } = ed25519::fixture(NAMESPACE, &mut rng, 4); + let Fixture { verifier, .. } = ed25519::fixture(&mut rng, NAMESPACE, 4); // Create a scheme with wrong namespace to generate invalid signatures let Fixture { schemes: wrong_schemes, .. - } = ed25519::fixture(b"wrong-namespace", &mut rng, 4); + } = ed25519::fixture(&mut rng, b"wrong-namespace", 4); assert!( ed25519::Scheme::is_attributable(), @@ -257,7 +257,7 @@ mod tests { let mut rng = StdRng::seed_from_u64(42); let Fixture { schemes, verifier, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut rng, 4); + } = bls12381_threshold::fixture::(&mut rng, NAMESPACE, 4); assert!( !bls12381_threshold::Scheme::::is_attributable(), @@ -304,7 +304,7 @@ mod tests { let mut rng = StdRng::seed_from_u64(42); let Fixture { schemes, verifier, .. - } = bls12381_threshold::fixture::(NAMESPACE, &mut rng, 4); + } = bls12381_threshold::fixture::(&mut rng, NAMESPACE, 4); assert!( !bls12381_threshold::Scheme::::is_attributable(), @@ -340,7 +340,7 @@ mod tests { let mut rng = StdRng::seed_from_u64(42); let Fixture { schemes, verifier, .. - } = ed25519::fixture(NAMESPACE, &mut rng, 4); + } = ed25519::fixture(&mut rng, NAMESPACE, 4); assert!( ed25519::Scheme::is_attributable(), diff --git a/consensus/src/simplex/types.rs b/consensus/src/simplex/types.rs index c0053249d5..2872beab7d 100644 --- a/consensus/src/simplex/types.rs +++ b/consensus/src/simplex/types.rs @@ -2474,7 +2474,7 @@ mod tests { /// Generate a fixture using the provided generator function with a specific seed. fn setup_seeded(n: u32, seed: u64, fixture: F) -> Fixture where - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { setup_seeded_ns(n, seed, NAMESPACE, fixture) } @@ -2482,10 +2482,10 @@ mod tests { /// Generate a fixture using the provided generator function with a specific seed and namespace. fn setup_seeded_ns(n: u32, seed: u64, namespace: &[u8], fixture: F) -> Fixture where - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = StdRng::seed_from_u64(seed); - fixture(namespace, &mut rng, n) + fixture(&mut rng, namespace, n) } #[test] @@ -2503,10 +2503,10 @@ mod tests { fn notarize_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 5); + let fixture = fixture(&mut rng, NAMESPACE, 5); let round = Round::new(Epoch::new(0), View::new(10)); let proposal = Proposal::new(round, View::new(5), sample_digest(1)); let notarize = Notarize::sign(&fixture.schemes[0], proposal).unwrap(); @@ -2531,10 +2531,10 @@ mod tests { fn notarization_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 5); + let fixture = fixture(&mut rng, NAMESPACE, 5); let proposal = Proposal::new( Round::new(Epoch::new(0), View::new(10)), View::new(5), @@ -2566,10 +2566,10 @@ mod tests { fn nullify_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 5); + let fixture = fixture(&mut rng, NAMESPACE, 5); let round = Round::new(Epoch::new(0), View::new(10)); let nullify = Nullify::sign::(&fixture.schemes[0], round).unwrap(); let encoded = nullify.encode(); @@ -2591,10 +2591,10 @@ mod tests { fn nullification_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 5); + let fixture = fixture(&mut rng, NAMESPACE, 5); let round = Round::new(Epoch::new(333), View::new(10)); let nullifies: Vec<_> = fixture .schemes @@ -2622,10 +2622,10 @@ mod tests { fn finalize_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 5); + let fixture = fixture(&mut rng, NAMESPACE, 5); let round = Round::new(Epoch::new(0), View::new(10)); let proposal = Proposal::new(round, View::new(5), sample_digest(1)); let finalize = Finalize::sign(&fixture.schemes[0], proposal).unwrap(); @@ -2648,10 +2648,10 @@ mod tests { fn finalization_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 5); + let fixture = fixture(&mut rng, NAMESPACE, 5); let round = Round::new(Epoch::new(0), View::new(10)); let proposal = Proposal::new(round, View::new(5), sample_digest(1)); let finalizes: Vec<_> = fixture @@ -2680,10 +2680,10 @@ mod tests { fn backfiller_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 5); + let fixture = fixture(&mut rng, NAMESPACE, 5); let cfg = fixture.schemes[0].certificate_codec_config(); let request = Request::new( 1, @@ -2744,10 +2744,10 @@ mod tests { fn response_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 5); + let fixture = fixture(&mut rng, NAMESPACE, 5); let round = Round::new(Epoch::new(0), View::new(10)); let proposal = Proposal::new(round, View::new(5), sample_digest(1)); @@ -2796,10 +2796,10 @@ mod tests { fn conflicting_notarize_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 5); + let fixture = fixture(&mut rng, NAMESPACE, 5); let proposal1 = Proposal::new( Round::new(Epoch::new(0), View::new(10)), View::new(5), @@ -2834,10 +2834,10 @@ mod tests { fn conflicting_finalize_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 5); + let fixture = fixture(&mut rng, NAMESPACE, 5); let proposal1 = Proposal::new( Round::new(Epoch::new(0), View::new(10)), View::new(5), @@ -2872,10 +2872,10 @@ mod tests { fn nullify_finalize_encode_decode(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 5); + let fixture = fixture(&mut rng, NAMESPACE, 5); let round = Round::new(Epoch::new(0), View::new(10)); let proposal = Proposal::new(round, View::new(5), sample_digest(1)); let nullify = Nullify::sign::(&fixture.schemes[0], round).unwrap(); @@ -2902,7 +2902,7 @@ mod tests { fn notarize_verify_wrong_namespace(f: F) where S: Scheme, - F: Fn(&[u8], &mut StdRng, u32) -> Fixture, + F: Fn(&mut StdRng, &[u8], u32) -> Fixture, { // Create two fixtures with different namespaces let mut rng = test_rng(); @@ -2929,7 +2929,7 @@ mod tests { fn notarize_verify_wrong_scheme(f: F) where S: Scheme, - F: Fn(&[u8], &mut StdRng, u32) -> Fixture, + F: Fn(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); let fixture = setup_seeded(5, 0, &f); @@ -2955,7 +2955,7 @@ mod tests { fn notarization_verify_wrong_scheme(f: F) where S: Scheme, - F: Fn(&[u8], &mut StdRng, u32) -> Fixture, + F: Fn(&mut StdRng, &[u8], u32) -> Fixture, { let fixture = setup_seeded(5, 0, &f); let wrong_fixture = setup_seeded(5, 1, &f); @@ -2991,7 +2991,7 @@ mod tests { fn notarization_verify_wrong_namespace(f: F) where S: Scheme, - F: Fn(&[u8], &mut StdRng, u32) -> Fixture, + F: Fn(&mut StdRng, &[u8], u32) -> Fixture, { // Create two fixtures with different namespaces let fixture = setup_seeded_ns(5, 0, NAMESPACE, &f); @@ -3027,10 +3027,10 @@ mod tests { fn notarization_recover_insufficient_signatures(fixture: F) where S: Scheme, - F: FnOnce(&[u8], &mut StdRng, u32) -> Fixture, + F: FnOnce(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); - let fixture = fixture(NAMESPACE, &mut rng, 5); + let fixture = fixture(&mut rng, NAMESPACE, 5); let quorum_size = quorum(fixture.schemes.len() as u32) as usize; assert!(quorum_size > 1, "test requires quorum larger than one"); let round = Round::new(Epoch::new(0), View::new(10)); @@ -3061,7 +3061,7 @@ mod tests { fn conflicting_notarize_detection(f: F) where S: Scheme, - F: Fn(&[u8], &mut StdRng, u32) -> Fixture, + F: Fn(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); let fixture = setup_seeded(5, 0, &f); @@ -3094,7 +3094,7 @@ mod tests { fn nullify_finalize_detection(f: F) where S: Scheme, - F: Fn(&[u8], &mut StdRng, u32) -> Fixture, + F: Fn(&mut StdRng, &[u8], u32) -> Fixture, { let mut rng = test_rng(); let fixture = setup_seeded(5, 0, &f); @@ -3126,7 +3126,7 @@ mod tests { fn finalization_verify_wrong_scheme(f: F) where S: Scheme, - F: Fn(&[u8], &mut StdRng, u32) -> Fixture, + F: Fn(&mut StdRng, &[u8], u32) -> Fixture, { let fixture = setup_seeded(5, 0, &f); let wrong_fixture = setup_seeded(5, 1, &f); diff --git a/cryptography/src/bls12381/certificate/multisig/mocks.rs b/cryptography/src/bls12381/certificate/multisig/mocks.rs index 6bef142f7f..7337d4fe75 100644 --- a/cryptography/src/bls12381/certificate/multisig/mocks.rs +++ b/cryptography/src/bls12381/certificate/multisig/mocks.rs @@ -11,8 +11,8 @@ use rand::{CryptoRng, RngCore}; /// Builds ed25519 identities and matching BLS12-381 multisig schemes. pub fn fixture( - namespace: &[u8], rng: &mut R, + namespace: &[u8], n: u32, signer: impl Fn(&[u8], BiMap, Private) -> Option, verifier: impl Fn(&[u8], BiMap) -> S, diff --git a/cryptography/src/bls12381/certificate/multisig/mod.rs b/cryptography/src/bls12381/certificate/multisig/mod.rs index 9447ecd2e4..102bf39606 100644 --- a/cryptography/src/bls12381/certificate/multisig/mod.rs +++ b/cryptography/src/bls12381/certificate/multisig/mod.rs @@ -381,8 +381,8 @@ mod macros { #[cfg(feature = "mocks")] #[allow(dead_code)] pub fn fixture( - namespace: &[u8], rng: &mut R, + namespace: &[u8], n: u32, ) -> $crate::certificate::mocks::Fixture> where @@ -390,8 +390,8 @@ mod macros { R: rand::RngCore + rand::CryptoRng, { $crate::bls12381::certificate::multisig::mocks::fixture::<_, V, _>( - namespace, rng, + namespace, n, Scheme::signer, Scheme::verifier, diff --git a/cryptography/src/bls12381/certificate/threshold/mocks.rs b/cryptography/src/bls12381/certificate/threshold/mocks.rs index 652090a9c4..7ba89244f6 100644 --- a/cryptography/src/bls12381/certificate/threshold/mocks.rs +++ b/cryptography/src/bls12381/certificate/threshold/mocks.rs @@ -13,8 +13,8 @@ use rand::{CryptoRng, RngCore}; /// Builds ed25519 identities and matching BLS12-381 threshold schemes. pub fn fixture( - namespace: &[u8], rng: &mut R, + namespace: &[u8], n: u32, signer: impl Fn(&[u8], Set, Sharing, Share) -> Option, verifier: impl Fn(&[u8], Set, Sharing) -> S, diff --git a/cryptography/src/bls12381/certificate/threshold/mod.rs b/cryptography/src/bls12381/certificate/threshold/mod.rs index 5c132a6941..ecdf184832 100644 --- a/cryptography/src/bls12381/certificate/threshold/mod.rs +++ b/cryptography/src/bls12381/certificate/threshold/mod.rs @@ -414,8 +414,8 @@ mod macros { #[cfg(feature = "mocks")] #[allow(dead_code)] pub fn fixture( - namespace: &[u8], rng: &mut R, + namespace: &[u8], n: u32, ) -> $crate::certificate::mocks::Fixture> where @@ -423,8 +423,8 @@ mod macros { R: rand::RngCore + rand::CryptoRng, { $crate::bls12381::certificate::threshold::mocks::fixture::<_, V, _>( - namespace, rng, + namespace, n, Scheme::signer, Scheme::verifier, diff --git a/cryptography/src/ed25519/certificate/mocks.rs b/cryptography/src/ed25519/certificate/mocks.rs index 29c99304b2..1a8bbef102 100644 --- a/cryptography/src/ed25519/certificate/mocks.rs +++ b/cryptography/src/ed25519/certificate/mocks.rs @@ -29,8 +29,8 @@ where /// Builds ed25519 identities alongside a caller-provided ed25519 certificate scheme wrapper. pub fn fixture( - namespace: &[u8], rng: &mut R, + namespace: &[u8], n: u32, signer: impl Fn(&[u8], Set, PrivateKey) -> Option, verifier: impl Fn(&[u8], Set) -> S, diff --git a/cryptography/src/ed25519/certificate/mod.rs b/cryptography/src/ed25519/certificate/mod.rs index 28ec8646fd..b44dbd7976 100644 --- a/cryptography/src/ed25519/certificate/mod.rs +++ b/cryptography/src/ed25519/certificate/mod.rs @@ -493,16 +493,16 @@ mod macros { #[cfg(feature = "mocks")] #[allow(dead_code)] pub fn fixture( - namespace: &[u8], rng: &mut R, + namespace: &[u8], n: u32, ) -> $crate::certificate::mocks::Fixture where R: rand::RngCore + rand::CryptoRng, { $crate::ed25519::certificate::mocks::fixture( - namespace, rng, + namespace, n, Scheme::signer, Scheme::verifier, diff --git a/cryptography/src/secp256r1/certificate/mocks.rs b/cryptography/src/secp256r1/certificate/mocks.rs index 7dab90841c..44ea937dfb 100644 --- a/cryptography/src/secp256r1/certificate/mocks.rs +++ b/cryptography/src/secp256r1/certificate/mocks.rs @@ -12,8 +12,8 @@ use rand::{CryptoRng, RngCore}; /// Builds ed25519 identities and matching Secp256r1 signing schemes. pub fn fixture( - namespace: &[u8], rng: &mut R, + namespace: &[u8], n: u32, signer: impl Fn(&[u8], BiMap, PrivateKey) -> Option, verifier: impl Fn(&[u8], BiMap) -> S, diff --git a/cryptography/src/secp256r1/certificate/mod.rs b/cryptography/src/secp256r1/certificate/mod.rs index f90f5d1f0c..dfcb9ab550 100644 --- a/cryptography/src/secp256r1/certificate/mod.rs +++ b/cryptography/src/secp256r1/certificate/mod.rs @@ -334,16 +334,16 @@ mod macros { #[cfg(feature = "mocks")] #[allow(dead_code)] pub fn fixture( - namespace: &[u8], rng: &mut R, + namespace: &[u8], n: u32, ) -> $crate::certificate::mocks::Fixture> where R: rand::RngCore + rand::CryptoRng, { $crate::secp256r1::certificate::mocks::fixture( - namespace, rng, + namespace, n, Scheme::signer, Scheme::verifier, diff --git a/examples/bridge/src/application/actor.rs b/examples/bridge/src/application/actor.rs index 027cd47852..a03cee8854 100644 --- a/examples/bridge/src/application/actor.rs +++ b/examples/bridge/src/application/actor.rs @@ -30,8 +30,8 @@ const GENESIS: &[u8] = b"commonware is neat"; pub struct Application { context: R, indexer: (Sender, Receiver), - public: ::Public, - other_certificate_verifier: Scheme, + this_network: ::Public, + other_network: Scheme, hasher: H, mailbox: mpsc::Receiver>, } @@ -40,25 +40,17 @@ impl Application) -> (Self, Scheme, Mailbox) { let (sender, mailbox) = mpsc::channel(config.mailbox_size); + let this_network = *config.this_network.identity(); ( Self { context, indexer: config.indexer, - public: *config.identity.public(), - other_certificate_verifier: Scheme::certificate_verifier( - &config.namespace, - config.other_public, - ), + this_network, + other_network: config.other_network, hasher: config.hasher, mailbox, }, - Scheme::signer( - &config.namespace, - config.participants, - config.identity, - config.share, - ) - .expect("share must be in participants"), + config.this_network, Mailbox::new(sender), ) } @@ -88,7 +80,7 @@ impl Application(inbound::GetFinalization { - network: *self.other_certificate_verifier.identity(), + network: *self.other_network.identity(), }) .encode(); indexer_sender @@ -112,8 +104,7 @@ impl Application Application(inbound::PutBlock { - network: self.public, + network: self.this_network, block, }) .encode(); @@ -157,7 +148,7 @@ impl Application { // Fetch payload from indexer let msg = Inbound::GetBlock(inbound::GetBlock { - network: self.public, + network: self.this_network, digest: payload, }) .encode(); @@ -186,8 +177,8 @@ impl Application { - let result = finalization - .verify(&mut self.context, &self.other_certificate_verifier); + let result = + finalization.verify(&mut self.context, &self.other_network); let _ = response.send(result); } } @@ -210,7 +201,7 @@ impl Application(inbound::PutFinalization { - network: self.public, + network: self.this_network, finalization, }) .encode(); diff --git a/examples/bridge/src/application/mod.rs b/examples/bridge/src/application/mod.rs index 8fd9c57844..9cfa64c1b1 100644 --- a/examples/bridge/src/application/mod.rs +++ b/examples/bridge/src/application/mod.rs @@ -2,21 +2,13 @@ //! This includes things like how to produce/verify blocks and how to identify which //! participants are active at a given view. -use commonware_cryptography::{ - bls12381::primitives::{ - group, - sharing::Sharing, - variant::{MinSig, Variant}, - }, - ed25519::PublicKey, - Hasher, -}; +use crate::Scheme; +use commonware_cryptography::Hasher; mod actor; pub use actor::Application; use commonware_runtime::{Sink, Stream}; use commonware_stream::{Receiver, Sender}; -use commonware_utils::ordered::Set; mod ingress; /// Configuration for the application. @@ -26,14 +18,11 @@ pub struct Config { /// Hashing scheme to use. pub hasher: H, - pub namespace: Vec, - pub identity: Sharing, - pub other_public: ::Public, + /// Signing scheme for this network. + pub this_network: Scheme, - /// Participants active in consensus. - pub participants: Set, - - pub share: group::Share, + /// Certificate verifier for the other network. + pub other_network: Scheme, /// Number of messages from consensus to hold in our backlog /// before blocking. diff --git a/examples/bridge/src/bin/validator.rs b/examples/bridge/src/bin/validator.rs index bc5f9b6c02..be6e9f6f96 100644 --- a/examples/bridge/src/bin/validator.rs +++ b/examples/bridge/src/bin/validator.rs @@ -1,6 +1,6 @@ use clap::{value_parser, Arg, Command}; use commonware_bridge::{ - application, APPLICATION_NAMESPACE, CONSENSUS_SUFFIX, INDEXER_NAMESPACE, P2P_SUFFIX, + application, Scheme, APPLICATION_NAMESPACE, CONSENSUS_SUFFIX, INDEXER_NAMESPACE, P2P_SUFFIX, }; use commonware_codec::{Decode, DecodeExt}; use commonware_consensus::{ @@ -218,17 +218,18 @@ fn main() { // Initialize application let consensus_namespace = union(APPLICATION_NAMESPACE, CONSENSUS_SUFFIX); + let this_network = + Scheme::signer(&consensus_namespace, validators.clone(), identity, share) + .expect("share must be in participants"); + let other_network = Scheme::certificate_verifier(&consensus_namespace, other_public); let (application, scheme, mailbox) = application::Application::new( context.with_label("application"), application::Config { indexer, - namespace: consensus_namespace.clone(), - identity, - other_public, hasher: Sha256::default(), + this_network, + other_network, mailbox_size: 1024, - participants: validators.clone(), - share, }, ); diff --git a/examples/log/src/application/actor.rs b/examples/log/src/application/actor.rs index da52dc96d5..235084c5ad 100644 --- a/examples/log/src/application/actor.rs +++ b/examples/log/src/application/actor.rs @@ -35,8 +35,7 @@ impl Application { hasher: config.hasher, mailbox, }, - Scheme::signer(&config.namespace, config.participants, config.private_key) - .expect("private key must be in participants"), + config.scheme, Reporter::new(), Mailbox::new(sender), ) diff --git a/examples/log/src/application/mod.rs b/examples/log/src/application/mod.rs index 34e570201f..d1b9630d36 100644 --- a/examples/log/src/application/mod.rs +++ b/examples/log/src/application/mod.rs @@ -2,11 +2,7 @@ //! This includes things like how to produce/verify blocks and how to identify which //! participants are active at a given view. -use commonware_cryptography::{ - ed25519::{PrivateKey, PublicKey}, - Hasher, -}; -use commonware_utils::ordered::Set; +use commonware_cryptography::Hasher; mod actor; pub use actor::Application; @@ -20,14 +16,8 @@ pub struct Config { /// Hashing scheme to use. pub hasher: H, - /// Namespace for domain separation. - pub namespace: Vec, - - /// Participants active in consensus. - pub participants: Set, - - /// Our private key. - pub private_key: PrivateKey, + /// Signing scheme for this network. + pub scheme: Scheme, /// Number of messages from consensus to hold in our backlog /// before blocking. diff --git a/examples/log/src/main.rs b/examples/log/src/main.rs index 062f83ea4d..db93410646 100644 --- a/examples/log/src/main.rs +++ b/examples/log/src/main.rs @@ -192,14 +192,14 @@ fn main() { // Initialize application let namespace = union(APPLICATION_NAMESPACE, b"_CONSENSUS"); + let scheme = application::Scheme::signer(&namespace, validators.clone(), signer.clone()) + .expect("private key must be in participants"); let (application, scheme, reporter, mailbox) = application::Application::new( context.with_label("application"), application::Config { hasher: Sha256::default(), - namespace: namespace.clone(), + scheme, mailbox_size: 1024, - participants: validators.clone(), - private_key: signer.clone(), }, );