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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions consensus/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ commonware-cryptography.workspace = true
commonware-macros.workspace = true
commonware-math.workspace = true
commonware-p2p.workspace = true
commonware-parallel.workspace = true
commonware-runtime.workspace = true
commonware-utils.workspace = true
futures.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use commonware_cryptography::{
bls12381::primitives::variant::MinPk, certificate::mocks::Fixture,
ed25519::PublicKey as Ed25519PublicKey,
};
use commonware_parallel::Sequential;
use commonware_runtime::deterministic;
use libfuzzer_sys::fuzz_target;

struct SimplexBls12381MinPk;

impl Simplex for SimplexBls12381MinPk {
type Scheme = bls12381_threshold::Scheme<Ed25519PublicKey, MinPk>;
type Scheme = bls12381_threshold::Scheme<Ed25519PublicKey, MinPk, Sequential>;
type Elector = Random;

fn fixture(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use commonware_cryptography::{
bls12381::primitives::variant::MinSig, certificate::mocks::Fixture,
ed25519::PublicKey as Ed25519PublicKey,
};
use commonware_parallel::Sequential;
use commonware_runtime::deterministic;
use libfuzzer_sys::fuzz_target;

struct SimplexBls12381MinSig;

impl Simplex for SimplexBls12381MinSig {
type Scheme = bls12381_threshold::Scheme<Ed25519PublicKey, MinSig>;
type Scheme = bls12381_threshold::Scheme<Ed25519PublicKey, MinSig, Sequential>;
type Elector = Random;

fn fixture(
Expand Down
13 changes: 11 additions & 2 deletions consensus/fuzz/fuzz_targets/simplex_elector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use commonware_cryptography::{
Sha256, Signer,
};
use commonware_math::algebra::Random as _;
use commonware_parallel::Sequential;
use commonware_utils::{ordered::Set, TryCollect};
use libfuzzer_sys::fuzz_target;
use rand::{rngs::StdRng, SeedableRng};
Expand Down Expand Up @@ -76,10 +77,18 @@ fuzz_target!(|input: FuzzInput| {
fuzz::<ed25519::Scheme, _>(&input, RoundRobin::<Sha256>::shuffled(seed), None);
}
FuzzElector::RandomMinPk(certificate) => {
fuzz::<bls12381_threshold::Scheme<_, MinPk>, _>(&input, Random, Some(certificate));
fuzz::<bls12381_threshold::Scheme<_, MinPk, Sequential>, _>(
&input,
Random,
Some(certificate),
);
}
FuzzElector::RandomMinSig(certificate) => {
fuzz::<bls12381_threshold::Scheme<_, MinSig>, _>(&input, Random, Some(certificate));
fuzz::<bls12381_threshold::Scheme<_, MinSig, Sequential>, _>(
&input,
Random,
Some(certificate),
);
}
}
});
5 changes: 3 additions & 2 deletions consensus/fuzz/fuzz_targets/simplex_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ use commonware_cryptography::{
ed25519::PublicKey,
sha256,
};
use commonware_parallel::Sequential;
use libfuzzer_sys::fuzz_target;

type Ed25519Scheme = ed25519::Scheme;
type Bls12381MultisigMinPk = bls12381_multisig::Scheme<PublicKey, MinPk>;
type Bls12381MultisigMinSig = bls12381_multisig::Scheme<PublicKey, MinSig>;
type ThresholdSchemeMinPk = bls12381_threshold::Scheme<PublicKey, MinPk>;
type ThresholdSchemeMinSig = bls12381_threshold::Scheme<PublicKey, MinSig>;
type ThresholdSchemeMinPk = bls12381_threshold::Scheme<PublicKey, MinPk, Sequential>;
type ThresholdSchemeMinSig = bls12381_threshold::Scheme<PublicKey, MinSig, Sequential>;

#[derive(Arbitrary, Debug)]
enum FuzzInput {
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/marshal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ mod tests {
simulated::{self, Link, Network, Oracle},
Manager,
};
use commonware_parallel::Sequential;
use commonware_runtime::{buffer::PoolRef, deterministic, Clock, Metrics, Quota, Runner};
use commonware_storage::archive::immutable;
use commonware_utils::{vec::NonEmptyVec, NZUsize, NZU16, NZU64};
Expand All @@ -147,7 +148,7 @@ mod tests {
type B = Block<D>;
type K = PublicKey;
type V = MinPk;
type S = bls12381_threshold::Scheme<K, V>;
type S = bls12381_threshold::Scheme<K, V, Sequential>;
type P = ConstantProvider<S, Epoch>;

const PAGE_SIZE: NonZeroU16 = NZU16!(1024);
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/simplex/elector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,14 @@ mod tests {
bls12381::primitives::variant::MinPk, certificate::mocks::Fixture,
sha256::Digest as Sha256Digest, Sha256,
};
use commonware_parallel::Sequential;
use commonware_utils::{quorum_from_slice, TryFromIterator};
use rand::{rngs::StdRng, SeedableRng};

const NAMESPACE: &[u8] = b"test";

type ThresholdScheme =
bls12381_threshold::Scheme<commonware_cryptography::ed25519::PublicKey, MinPk>;
bls12381_threshold::Scheme<commonware_cryptography::ed25519::PublicKey, MinPk, Sequential>;

#[test]
fn round_robin_rotates_through_participants() {
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/simplex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ mod tests {
simulated::{Config, Link, Network, Oracle, Receiver, Sender, SplitOrigin, SplitTarget},
Recipients, Sender as _,
};
use commonware_parallel::Sequential;
use commonware_runtime::{
buffer::PoolRef, count_running_tasks, deterministic, Clock, Metrics, Quota, Runner, Spawner,
};
Expand Down Expand Up @@ -4763,7 +4764,7 @@ mod tests {
fn tle<V, L>()
where
V: Variant,
L: Elector<bls12381_threshold::Scheme<PublicKey, V>>,
L: Elector<bls12381_threshold::Scheme<PublicKey, V, Sequential>>,
{
// Create context
let n = 4;
Expand Down
16 changes: 10 additions & 6 deletions consensus/src/simplex/scheme/bls12381_threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ enum Role<P: PublicKey, V: Variant> {
/// The scheme is generic over a [`Strategy`] which determines whether cryptographic
/// operations such as signature recovery and batch verification run sequentially or in parallel.
#[derive(Clone, Debug)]
pub struct Scheme<P: PublicKey, V: Variant, S: Strategy = Sequential> {
pub struct Scheme<P: PublicKey, V: Variant, S: Strategy> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opted to remove the default strategy since it caused the silent API blunder.

role: Role<P, V>,
strategy: S,
}
Expand Down Expand Up @@ -274,7 +274,7 @@ pub fn fixture<V, R>(
namespace: &[u8],
n: u32,
) -> commonware_cryptography::certificate::mocks::Fixture<
Scheme<commonware_cryptography::ed25519::PublicKey, V>,
Scheme<commonware_cryptography::ed25519::PublicKey, V, Sequential>,
>
where
V: Variant,
Expand Down Expand Up @@ -356,7 +356,7 @@ impl<V: Variant> Seed<V> {
}

/// Verifies the threshold signature on this [Seed].
pub fn verify<P: PublicKey>(&self, scheme: &Scheme<P, V>) -> bool {
pub fn verify<P: PublicKey, S: Strategy>(&self, scheme: &Scheme<P, V, S>) -> bool {
let seed_message = self.round.encode();

ops::verify_message::<V>(
Expand Down Expand Up @@ -446,13 +446,17 @@ pub trait Seedable<V: Variant> {
fn seed(&self) -> Seed<V>;
}

impl<P: PublicKey, V: Variant, D: Digest> Seedable<V> for Notarization<Scheme<P, V>, D> {
impl<P: PublicKey, V: Variant, D: Digest, S: Strategy> Seedable<V>
for Notarization<Scheme<P, V, S>, D>
{
fn seed(&self) -> Seed<V> {
Seed::new(self.proposal.round, self.certificate.seed_signature)
}
}

impl<P: PublicKey, V: Variant, D: Digest> Seedable<V> for Finalization<Scheme<P, V>, D> {
impl<P: PublicKey, V: Variant, D: Digest, S: Strategy> Seedable<V>
for Finalization<Scheme<P, V, S>, D>
{
fn seed(&self) -> Seed<V> {
Seed::new(self.proposal.round, self.certificate.seed_signature)
}
Expand Down Expand Up @@ -773,7 +777,7 @@ mod tests {

const NAMESPACE: &[u8] = b"bls-threshold-signing-scheme";

type Scheme<V> = super::Scheme<ed25519::PublicKey, V>;
type Scheme<V> = super::Scheme<ed25519::PublicKey, V, Sequential>;
type Signature<V> = super::Signature<V>;

fn setup_signers<V: Variant>(n: u32, seed: u64) -> (Vec<Scheme<V>>, Scheme<V>) {
Expand Down
5 changes: 3 additions & 2 deletions consensus/src/simplex/scheme/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ mod tests {
sha256::Digest as Sha256Digest,
Hasher, Sha256,
};
use commonware_parallel::Sequential;
use futures::executor::block_on;
use rand::{rngs::StdRng, SeedableRng};
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -260,7 +261,7 @@ mod tests {
} = bls12381_threshold::fixture::<MinPk, _>(&mut rng, NAMESPACE, 4);

assert!(
!bls12381_threshold::Scheme::<Ed25519PublicKey, MinPk>::is_attributable(),
!bls12381_threshold::Scheme::<Ed25519PublicKey, MinPk, Sequential>::is_attributable(),
"BLS threshold must be non-attributable"
);

Expand Down Expand Up @@ -307,7 +308,7 @@ mod tests {
} = bls12381_threshold::fixture::<MinPk, _>(&mut rng, NAMESPACE, 4);

assert!(
!bls12381_threshold::Scheme::<Ed25519PublicKey, MinPk>::is_attributable(),
!bls12381_threshold::Scheme::<Ed25519PublicKey, MinPk, Sequential>::is_attributable(),
"BLS threshold must be non-attributable"
);

Expand Down
3 changes: 2 additions & 1 deletion consensus/src/simplex/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3241,8 +3241,9 @@ mod tests {
use crate::simplex::scheme::bls12381_threshold;
use commonware_codec::conformance::CodecConformance;
use commonware_cryptography::{ed25519::PublicKey, sha256::Digest as Sha256Digest};
use commonware_parallel::Sequential;

type Scheme = bls12381_threshold::Scheme<PublicKey, MinSig>;
type Scheme = bls12381_threshold::Scheme<PublicKey, MinSig, Sequential>;

commonware_conformance::conformance_tests! {
CodecConformance<Vote<Scheme, Sha256Digest>>,
Expand Down
Loading