diff --git a/Cargo.lock b/Cargo.lock index e498bdc5618..6d29e90d88f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4413,7 +4413,7 @@ dependencies = [ [[package]] name = "mithril-stm" -version = "0.4.8" +version = "0.4.9" dependencies = [ "bincode", "blake2 0.10.6", diff --git a/demo/protocol-demo/src/demonstrator.rs b/demo/protocol-demo/src/demonstrator.rs index 268f5b24b10..a8a8621ede9 100644 --- a/demo/protocol-demo/src/demonstrator.rs +++ b/demo/protocol-demo/src/demonstrator.rs @@ -108,9 +108,11 @@ impl Party { } let closed_reg = key_reg.close(); - let signer = self.initializer.clone().unwrap().new_signer(closed_reg).unwrap(); + let signer = self.initializer.clone().unwrap().create_signer(closed_reg).unwrap(); self.signer = Some(signer); - self.clerk = Some(ProtocolClerk::from_signer(self.signer.as_ref().unwrap())); + self.clerk = Some(ProtocolClerk::new_clerk_from_signer( + self.signer.as_ref().unwrap(), + )); } /// Individually sign a message through lottery @@ -140,7 +142,7 @@ impl Party { message: &Vec, signatures: &[ProtocolSingleSignature], ) -> Option<&ProtocolMultiSignature> { - let msig = self.clerk.as_ref().unwrap().aggregate(signatures, message); + let msig = self.clerk.as_ref().unwrap().aggregate_signatures(signatures, message); match msig { Ok(aggregate_signature) => { println!("Party #{}: aggregate signature computed", self.party_id); @@ -167,7 +169,7 @@ impl Party { match self.get_aggregate(message) { Some(msig) => match msig.verify( message, - &self.clerk.as_ref().unwrap().compute_avk(), + &self.clerk.as_ref().unwrap().compute_aggregate_verification_key(), &self.params.unwrap(), ) { Ok(_) => { @@ -245,7 +247,7 @@ impl Verifier { } let closed_reg = key_reg.close(); - self.clerk = Some(ProtocolClerk::from_registration( + self.clerk = Some(ProtocolClerk::new_clerk_from_closed_key_registration( &self.params.unwrap(), &closed_reg, )); @@ -259,7 +261,7 @@ impl Verifier { ) -> Result<(), String> { match msig.verify( message, - &self.clerk.as_ref().unwrap().compute_avk(), + &self.clerk.as_ref().unwrap().compute_aggregate_verification_key(), &self.params.unwrap(), ) { Ok(_) => { @@ -358,11 +360,14 @@ impl ProtocolDemonstrator for Demonstrator { let mut players_artifacts = Vec::new(); for party in self.parties.iter_mut() { let protocol_initializer = - ProtocolInitializerNotCertified::setup(self.params.unwrap(), party.stake, rng); + ProtocolInitializerNotCertified::new(self.params.unwrap(), party.stake, rng); players_artifacts.push(PlayerArtifact { party_id: party.clone().party_id, stake: party.stake, - verification_key: key_encode_hex(protocol_initializer.verification_key()).unwrap(), + verification_key: key_encode_hex( + protocol_initializer.get_verification_key_proof_of_possession(), + ) + .unwrap(), initializer: key_encode_hex(protocol_initializer.clone()).unwrap(), }); party.initializer = Some(protocol_initializer); diff --git a/mithril-common/src/certificate_chain/certificate_verifier.rs b/mithril-common/src/certificate_chain/certificate_verifier.rs index 62bf59b686f..4f308ec49a3 100644 --- a/mithril-common/src/certificate_chain/certificate_verifier.rs +++ b/mithril-common/src/certificate_chain/certificate_verifier.rs @@ -495,9 +495,12 @@ mod tests { .collect::>(); let first_signer = &signers[0].protocol_signer; - let clerk = ProtocolClerk::from_signer(first_signer); - let aggregate_verification_key = clerk.compute_avk().into(); - let multi_signature = clerk.aggregate(&single_signatures, &message_hash).unwrap().into(); + let clerk = ProtocolClerk::new_clerk_from_signer(first_signer); + let aggregate_verification_key = clerk.compute_aggregate_verification_key().into(); + let multi_signature = clerk + .aggregate_signatures(&single_signatures, &message_hash) + .unwrap() + .into(); let verifier = MithrilCertificateVerifier::new( TestLogger::stdout(), @@ -785,9 +788,10 @@ mod tests { .iter() .filter_map(|s| s.protocol_signer.sign(signed_message.as_bytes())) .collect::>(); - let clerk = ProtocolClerk::from_signer(&fixture.signers_fixture()[0].protocol_signer); + let clerk = + ProtocolClerk::new_clerk_from_signer(&fixture.signers_fixture()[0].protocol_signer); let modified_multi_signature = clerk - .aggregate(&single_signatures, signed_message.as_bytes()) + .aggregate_signatures(&single_signatures, signed_message.as_bytes()) .unwrap(); modified_certificate.signature = CertificateSignature::MultiSignature( modified_certificate.signed_entity_type(), @@ -1082,12 +1086,12 @@ mod tests { s_adversary.protocol_signer.sign(signed_message.as_bytes()) }) .collect::>(); - let forged_clerk = ProtocolClerk::from_registration( + let forged_clerk = ProtocolClerk::new_clerk_from_closed_key_registration( &forged_protocol_parameters.clone().into(), &fixture.signers_fixture()[0].protocol_closed_key_registration, ); let forged_multi_signature = forged_clerk - .aggregate(&forged_single_signatures, signed_message.as_bytes()) + .aggregate_signatures(&forged_single_signatures, signed_message.as_bytes()) .unwrap(); forged_certificate.signature = CertificateSignature::MultiSignature( forged_certificate.signed_entity_type(), diff --git a/mithril-common/src/crypto_helper/cardano/key_certification.rs b/mithril-common/src/crypto_helper/cardano/key_certification.rs index 760b2919192..5cbd057f275 100644 --- a/mithril-common/src/crypto_helper/cardano/key_certification.rs +++ b/mithril-common/src/crypto_helper/cardano/key_certification.rs @@ -120,10 +120,10 @@ impl StmInitializerWrapper { stake: Stake, rng: &mut R, ) -> StdResult { - let stm_initializer = Initializer::setup(params, stake, rng); + let stm_initializer = Initializer::new(params, stake, rng); let kes_signature = if let Some(kes_signer) = kes_signer { let (signature, _op_cert) = kes_signer.sign( - &stm_initializer.verification_key().to_bytes(), + &stm_initializer.get_verification_key_proof_of_possession().to_bytes(), kes_period.unwrap_or_default(), )?; @@ -143,7 +143,7 @@ impl StmInitializerWrapper { /// Extract the verification key. pub fn verification_key(&self) -> VerificationKeyProofOfPossession { - self.stm_initializer.verification_key() + self.stm_initializer.get_verification_key_proof_of_possession() } /// Extract the verification key signature. @@ -178,7 +178,7 @@ impl StmInitializerWrapper { closed_reg: ClosedKeyRegistration, ) -> Result, ProtocolRegistrationErrorWrapper> { self.stm_initializer - .new_signer(closed_reg) + .create_signer(closed_reg) .map_err(ProtocolRegistrationErrorWrapper::CoreRegister) } @@ -365,7 +365,10 @@ mod test { Some(opcert1), initializer_1.verification_key_signature(), Some(0), - initializer_1.stm_initializer.verification_key().into(), + initializer_1 + .stm_initializer + .get_verification_key_proof_of_possession() + .into(), ); assert!(key_registration_1.is_ok()); @@ -390,7 +393,10 @@ mod test { Some(opcert2), initializer_2.verification_key_signature(), Some(0), - initializer_2.stm_initializer.verification_key().into(), + initializer_2 + .stm_initializer + .get_verification_key_proof_of_possession() + .into(), ); assert!(key_registration_2.is_ok()) } diff --git a/mithril-common/src/protocol/multi_signer.rs b/mithril-common/src/protocol/multi_signer.rs index c8f8422b8ce..1965edd2b70 100644 --- a/mithril-common/src/protocol/multi_signer.rs +++ b/mithril-common/src/protocol/multi_signer.rs @@ -37,13 +37,13 @@ impl MultiSigner { .collect(); self.protocol_clerk - .aggregate(&protocol_signatures, message.to_message().as_bytes()) + .aggregate_signatures(&protocol_signatures, message.to_message().as_bytes()) .map(|multi_sig| multi_sig.into()) } /// Compute aggregate verification key from stake distribution pub fn compute_aggregate_verification_key(&self) -> ProtocolAggregateVerificationKey { - self.protocol_clerk.compute_avk().into() + self.protocol_clerk.compute_aggregate_verification_key().into() } /// Verify a single signature @@ -60,7 +60,7 @@ impl MultiSigner { // party, and we can ignore the request. let (vk, stake) = self .protocol_clerk - .get_reg_party(&protocol_signature.signer_index) + .get_registered_party_for_index(&protocol_signature.signer_index) .ok_or_else(|| { anyhow!(format!( "Unregistered party: '{}'", diff --git a/mithril-common/src/protocol/signer_builder.rs b/mithril-common/src/protocol/signer_builder.rs index a7729cf423e..1eece99c56d 100644 --- a/mithril-common/src/protocol/signer_builder.rs +++ b/mithril-common/src/protocol/signer_builder.rs @@ -73,8 +73,10 @@ impl SignerBuilder { /// Build a [MultiSigner] based on the registered parties pub fn build_multi_signer(&self) -> MultiSigner { let stm_parameters = self.protocol_parameters.clone().into(); - let clerk = - ProtocolClerk::from_registration(&stm_parameters, &self.closed_key_registration); + let clerk = ProtocolClerk::new_clerk_from_closed_key_registration( + &stm_parameters, + &self.closed_key_registration, + ); MultiSigner::new(clerk, stm_parameters) } @@ -82,10 +84,12 @@ impl SignerBuilder { /// Compute aggregate verification key from stake distribution pub fn compute_aggregate_verification_key(&self) -> ProtocolAggregateVerificationKey { let stm_parameters = self.protocol_parameters.clone().into(); - let clerk = - ProtocolClerk::from_registration(&stm_parameters, &self.closed_key_registration); + let clerk = ProtocolClerk::new_clerk_from_closed_key_registration( + &stm_parameters, + &self.closed_key_registration, + ); - clerk.compute_avk().into() + clerk.compute_aggregate_verification_key().into() } fn build_single_signer_with_rng( diff --git a/mithril-common/src/test_utils/certificate_chain_builder.rs b/mithril-common/src/test_utils/certificate_chain_builder.rs index 21adb058b70..6bf1beea035 100644 --- a/mithril-common/src/test_utils/certificate_chain_builder.rs +++ b/mithril-common/src/test_utils/certificate_chain_builder.rs @@ -350,13 +350,13 @@ impl<'a> CertificateChainBuilder<'a> { fn compute_clerk_for_signers(signers: &[SignerFixture]) -> ProtocolClerk { let first_signer = &signers[0].protocol_signer; - ProtocolClerk::from_signer(first_signer) + ProtocolClerk::new_clerk_from_signer(first_signer) } fn compute_avk_for_signers(signers: &[SignerFixture]) -> ProtocolAggregateVerificationKey { let clerk = Self::compute_clerk_for_signers(signers); - clerk.compute_avk().into() + clerk.compute_aggregate_verification_key().into() } fn setup_genesis() -> (ProtocolGenesisSigner, ProtocolGenesisVerifier) { @@ -499,7 +499,7 @@ impl<'a> CertificateChainBuilder<'a> { .collect::>(); let clerk = CertificateChainBuilder::compute_clerk_for_signers(&fixture.signers_fixture()); let multi_signature = clerk - .aggregate(&single_signatures, certificate.signed_message.as_bytes()) + .aggregate_signatures(&single_signatures, certificate.signed_message.as_bytes()) .unwrap(); certificate.signature = CertificateSignature::MultiSignature( SignedEntityType::CardanoDatabase(CardanoDbBeacon::new( diff --git a/mithril-signer/src/services/single_signer.rs b/mithril-signer/src/services/single_signer.rs index 0c7d17f06a0..f2d3c7a4344 100644 --- a/mithril-signer/src/services/single_signer.rs +++ b/mithril-signer/src/services/single_signer.rs @@ -183,8 +183,8 @@ mod tests { let snapshot_digest = "digest".to_string(); let fixture = MithrilFixtureBuilder::default().with_signers(5).build(); let current_signer = &fixture.signers_fixture()[0]; - let clerk = ProtocolClerk::from_signer(¤t_signer.protocol_signer); - let avk = clerk.compute_avk(); + let clerk = ProtocolClerk::new_clerk_from_signer(¤t_signer.protocol_signer); + let avk = clerk.compute_aggregate_verification_key(); let logger = TestLogger::stdout(); let connection = Arc::new(main_db_connection().unwrap()); let stake_store = { @@ -228,7 +228,7 @@ mod tests { decoded_sig .verify( &fixture.protocol_parameters().into(), - ¤t_signer.protocol_signer.verification_key(), + ¤t_signer.protocol_signer.get_verification_key(), ¤t_signer.protocol_signer.get_stake(), &avk, &expected_message diff --git a/mithril-stm/CHANGELOG.md b/mithril-stm/CHANGELOG.md index 48a9bf2432c..5b1376de77f 100644 --- a/mithril-stm/CHANGELOG.md +++ b/mithril-stm/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.4.9 (07-07-2025) + +### Changed + +- Function names are changed. + ## 0.4.8 (02-07-2025) ### Deprecated diff --git a/mithril-stm/Cargo.toml b/mithril-stm/Cargo.toml index c077e459aaf..8d2d2cdee4c 100644 --- a/mithril-stm/Cargo.toml +++ b/mithril-stm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-stm" -version = "0.4.8" +version = "0.4.9" edition = { workspace = true } authors = { workspace = true } homepage = { workspace = true } diff --git a/mithril-stm/benches/size_benches.rs b/mithril-stm/benches/size_benches.rs index 2655ee315ff..bad9f0299cc 100644 --- a/mithril-stm/benches/size_benches.rs +++ b/mithril-stm/benches/size_benches.rs @@ -30,8 +30,10 @@ where let mut key_reg = KeyRegistration::init(); for stake in parties { - let p = Initializer::setup(params, stake, &mut rng); - key_reg.register(stake, p.verification_key()).unwrap(); + let p = Initializer::new(params, stake, &mut rng); + key_reg + .register(stake, p.get_verification_key_proof_of_possession()) + .unwrap(); ps.push(p); } @@ -39,17 +41,17 @@ where let ps = ps .into_par_iter() - .map(|p| p.new_signer(closed_reg.clone()).unwrap()) + .map(|p| p.create_signer(closed_reg.clone()).unwrap()) .collect::>>(); let sigs = ps .par_iter() .filter_map(|p| p.sign(&msg)) .collect::>(); - let clerk = Clerk::from_signer(&ps[0]); + let clerk = Clerk::new_clerk_from_signer(&ps[0]); // Aggregate with random parties - let aggr = clerk.aggregate(&sigs, &msg).unwrap(); + let aggr = clerk.aggregate_signatures(&sigs, &msg).unwrap(); println!( "k = {} | m = {} | nr parties = {}; {} bytes", @@ -76,21 +78,24 @@ where let params = Parameters { k, m, phi_f: 0.2 }; for stake in parties { - let initializer = Initializer::setup(params, stake, &mut rng); + let initializer = Initializer::new(params, stake, &mut rng); initializers.push(initializer.clone()); - public_signers.push((initializer.verification_key().vk, initializer.stake)); + public_signers.push(( + initializer.get_verification_key_proof_of_possession().vk, + initializer.stake, + )); } - let core_verifier = BasicVerifier::setup(&public_signers); + let core_verifier = BasicVerifier::new(&public_signers); let signers: Vec> = initializers .into_iter() - .filter_map(|s| s.new_core_signer(&core_verifier.eligible_parties)) + .filter_map(|s| s.create_basic_signer(&core_verifier.eligible_parties)) .collect(); let mut signatures: Vec = Vec::with_capacity(nparties); for s in signers { - if let Some(sig) = s.core_sign(&msg, core_verifier.total_stake) { + if let Some(sig) = s.basic_sign(&msg, core_verifier.total_stake) { signatures.push(sig); } } @@ -103,7 +108,7 @@ where }) .collect::>(); - let dedup_sigs = BasicVerifier::dedup_sigs_for_indices( + let dedup_sigs = BasicVerifier::select_valid_signatures_for_k_indices( &core_verifier.total_stake, ¶ms, &msg, diff --git a/mithril-stm/benches/stm.rs b/mithril-stm/benches/stm.rs index d1039183b3b..4975d5f5f12 100644 --- a/mithril-stm/benches/stm.rs +++ b/mithril-stm/benches/stm.rs @@ -35,7 +35,7 @@ where let mut initializers: Vec = Vec::with_capacity(nr_parties); for stake in stakes { - initializers.push(Initializer::setup(params, stake, &mut rng)); + initializers.push(Initializer::new(params, stake, &mut rng)); } let mut key_reg = KeyRegistration::init(); @@ -44,7 +44,9 @@ where // We need to initialise the key_reg at each iteration key_reg = KeyRegistration::init(); for p in initializers.iter() { - key_reg.register(p.stake, p.verification_key()).unwrap(); + key_reg + .register(p.stake, p.get_verification_key_proof_of_possession()) + .unwrap(); } }) }); @@ -53,7 +55,7 @@ where let signers = initializers .into_par_iter() - .map(|p| p.new_signer(closed_reg.clone()).unwrap()) + .map(|p| p.create_signer(closed_reg.clone()).unwrap()) .collect::>>(); group.bench_function(BenchmarkId::new("Play all lotteries", ¶m_string), |b| { @@ -64,10 +66,10 @@ where let sigs = signers.par_iter().filter_map(|p| p.sign(&msg)).collect::>(); - let clerk = Clerk::from_signer(&signers[0]); + let clerk = Clerk::new_clerk_from_signer(&signers[0]); group.bench_function(BenchmarkId::new("Aggregation", ¶m_string), |b| { - b.iter(|| clerk.aggregate(&sigs, &msg)) + b.iter(|| clerk.aggregate_signatures(&sigs, &msg)) }); } @@ -108,26 +110,28 @@ fn batch_benches( let mut initializers: Vec = Vec::with_capacity(nr_parties); for stake in stakes { - initializers.push(Initializer::setup(params, stake, &mut rng)); + initializers.push(Initializer::new(params, stake, &mut rng)); } let mut key_reg = KeyRegistration::init(); for p in initializers.iter() { - key_reg.register(p.stake, p.verification_key()).unwrap(); + key_reg + .register(p.stake, p.get_verification_key_proof_of_possession()) + .unwrap(); } let closed_reg = key_reg.close(); let signers = initializers .into_par_iter() - .map(|p| p.new_signer(closed_reg.clone()).unwrap()) + .map(|p| p.create_signer(closed_reg.clone()).unwrap()) .collect::>>(); let sigs = signers.par_iter().filter_map(|p| p.sign(&msg)).collect::>(); - let clerk = Clerk::from_signer(&signers[0]); - let msig = clerk.aggregate(&sigs, &msg).unwrap(); + let clerk = Clerk::new_clerk_from_signer(&signers[0]); + let msig = clerk.aggregate_signatures(&sigs, &msg).unwrap(); - batch_avks.push(clerk.compute_avk()); + batch_avks.push(clerk.compute_aggregate_verification_key()); batch_stms.push(msig); } @@ -167,27 +171,30 @@ where .collect::>(); for stake in stakes { - let initializer = Initializer::setup(params, stake, &mut rng); + let initializer = Initializer::new(params, stake, &mut rng); initializers.push(initializer.clone()); - public_signers.push((initializer.verification_key().vk, initializer.stake)); + public_signers.push(( + initializer.get_verification_key_proof_of_possession().vk, + initializer.stake, + )); } - let core_verifier = BasicVerifier::setup(&public_signers); + let core_verifier = BasicVerifier::new(&public_signers); let signers: Vec> = initializers .into_iter() - .filter_map(|s| s.new_core_signer(&core_verifier.eligible_parties)) + .filter_map(|s| s.create_basic_signer(&core_verifier.eligible_parties)) .collect(); group.bench_function(BenchmarkId::new("Play all lotteries", ¶m_string), |b| { b.iter(|| { - signers[0].core_sign(&msg, core_verifier.total_stake); + signers[0].basic_sign(&msg, core_verifier.total_stake); }) }); let signatures = signers .par_iter() - .filter_map(|p| p.core_sign(&msg, core_verifier.total_stake)) + .filter_map(|p| p.basic_sign(&msg, core_verifier.total_stake)) .collect::>(); group.bench_function(BenchmarkId::new("Core verification", ¶m_string), |b| { diff --git a/mithril-stm/examples/key_registration.rs b/mithril-stm/examples/key_registration.rs index 4f7abc18358..650b07e7c0c 100644 --- a/mithril-stm/examples/key_registration.rs +++ b/mithril-stm/examples/key_registration.rs @@ -38,17 +38,17 @@ fn main() { .collect::>(); // Each party generates their Stm keys - let party_0_init = Initializer::setup(params, stakes[0], &mut rng); - let party_1_init = Initializer::setup(params, stakes[1], &mut rng); - let party_2_init = Initializer::setup(params, stakes[2], &mut rng); - let party_3_init = Initializer::setup(params, stakes[3], &mut rng); + let party_0_init = Initializer::new(params, stakes[0], &mut rng); + let party_1_init = Initializer::new(params, stakes[1], &mut rng); + let party_2_init = Initializer::new(params, stakes[2], &mut rng); + let party_3_init = Initializer::new(params, stakes[3], &mut rng); // The public keys are broadcast. All participants will have the same keys. let parties_pks: Vec = vec![ - party_0_init.verification_key(), - party_1_init.verification_key(), - party_2_init.verification_key(), - party_3_init.verification_key(), + party_0_init.get_verification_key_proof_of_possession(), + party_1_init.get_verification_key_proof_of_possession(), + party_2_init.get_verification_key_proof_of_possession(), + party_3_init.get_verification_key_proof_of_possession(), ]; // Now, each party generates their own KeyReg instance, and registers all other participating @@ -60,10 +60,10 @@ fn main() { // Now, with information of all participating parties (we can create the Merkle Tree), the // signers can be initialised. - let party_0 = party_0_init.new_signer(key_reg_0).unwrap(); - let party_1 = party_1_init.new_signer(key_reg_1).unwrap(); - let party_2 = party_2_init.new_signer(key_reg_2).unwrap(); - let party_3 = party_3_init.new_signer(key_reg_3).unwrap(); + let party_0 = party_0_init.create_signer(key_reg_0).unwrap(); + let party_1 = party_1_init.create_signer(key_reg_1).unwrap(); + let party_2 = party_2_init.create_signer(key_reg_2).unwrap(); + let party_3 = party_3_init.create_signer(key_reg_3).unwrap(); ///////////////////// // operation phase // @@ -110,26 +110,34 @@ fn main() { let incomplete_sigs_3 = vec![party_0_sigs, party_1_sigs, party_2_sigs, party_3_sigs]; let closed_registration = local_reg(&stakes, &parties_pks); - let clerk = Clerk::from_registration(¶ms, &closed_registration); + let clerk = Clerk::new_clerk_from_closed_key_registration(¶ms, &closed_registration); // Now we aggregate the signatures - let msig_1 = match clerk.aggregate(&complete_sigs_1, &msg) { + let msig_1 = match clerk.aggregate_signatures(&complete_sigs_1, &msg) { Ok(s) => s, Err(e) => { panic!("Aggregation failed: {e:?}") } }; - assert!(msig_1.verify(&msg, &clerk.compute_avk(), ¶ms).is_ok()); + assert!( + msig_1 + .verify(&msg, &clerk.compute_aggregate_verification_key(), ¶ms) + .is_ok() + ); - let msig_2 = match clerk.aggregate(&complete_sigs_2, &msg) { + let msig_2 = match clerk.aggregate_signatures(&complete_sigs_2, &msg) { Ok(s) => s, Err(e) => { panic!("Aggregation failed: {e:?}") } }; - assert!(msig_2.verify(&msg, &clerk.compute_avk(), ¶ms).is_ok()); + assert!( + msig_2 + .verify(&msg, &clerk.compute_aggregate_verification_key(), ¶ms) + .is_ok() + ); - let msig_3 = clerk.aggregate(&incomplete_sigs_3, &msg); + let msig_3 = clerk.aggregate_signatures(&incomplete_sigs_3, &msg); assert!(msig_3.is_err()); } diff --git a/mithril-stm/src/aggregate_signature/aggregate_key.rs b/mithril-stm/src/aggregate_signature/aggregate_key.rs index 9d6508736f3..741f5cc7b46 100644 --- a/mithril-stm/src/aggregate_signature/aggregate_key.rs +++ b/mithril-stm/src/aggregate_signature/aggregate_key.rs @@ -17,10 +17,18 @@ pub struct AggregateVerificationKey { } impl AggregateVerificationKey { - pub fn get_mt_commitment(&self) -> MerkleTreeBatchCommitment { + pub(crate) fn get_merkle_tree_batch_commitment(&self) -> MerkleTreeBatchCommitment { self.mt_commitment.clone() } + #[deprecated( + since = "0.4.9", + note = "Use `get_merkle_tree_batch_commitment` instead" + )] + pub fn get_mt_commitment(&self) -> MerkleTreeBatchCommitment { + Self::get_merkle_tree_batch_commitment(self) + } + pub fn get_total_stake(&self) -> Stake { self.total_stake } @@ -39,7 +47,7 @@ impl From<&ClosedKeyRegistration> { fn from(reg: &ClosedKeyRegistration) -> Self { Self { - mt_commitment: reg.merkle_tree.to_commitment_batch_compat(), + mt_commitment: reg.merkle_tree.to_merkle_tree_batch_commitment(), total_stake: reg.total_stake, } } diff --git a/mithril-stm/src/aggregate_signature/basic_verifier.rs b/mithril-stm/src/aggregate_signature/basic_verifier.rs index 134c8799ea3..22402770f43 100644 --- a/mithril-stm/src/aggregate_signature/basic_verifier.rs +++ b/mithril-stm/src/aggregate_signature/basic_verifier.rs @@ -21,7 +21,7 @@ impl BasicVerifier { /// * Collect the unique signers in a hash set, /// * Calculate the total stake of the eligible signers, /// * Sort the eligible signers. - pub fn setup(public_signers: &[(BlsVerificationKey, Stake)]) -> Self { + pub fn new(public_signers: &[(BlsVerificationKey, Stake)]) -> Self { let mut total_stake: Stake = 0; let mut unique_parties = HashSet::new(); for signer in public_signers.iter() { @@ -41,6 +41,15 @@ impl BasicVerifier { } } + /// Setup a basic verifier for given list of signers. + /// * Collect the unique signers in a hash set, + /// * Calculate the total stake of the eligible signers, + /// * Sort the eligible signers. + #[deprecated(since = "0.4.9", note = "Use `new` instead")] + pub fn setup(public_signers: &[(BlsVerificationKey, Stake)]) -> Self { + Self::new(public_signers) + } + /// Preliminary verification that checks whether indices are unique and the quorum is achieved. pub(crate) fn preliminary_verify( total_stake: &Stake, @@ -79,7 +88,7 @@ impl BasicVerifier { /// If there is no sufficient signatures, then the function fails. // todo: We need to agree on a criteria to dedup (by default we use a BTreeMap that guarantees keys order) // todo: not good, because it only removes index if there is a conflict (see benches) - pub fn dedup_sigs_for_indices( + pub fn select_valid_signatures_for_k_indices( total_stake: &Stake, params: &Parameters, msg: &[u8], @@ -93,7 +102,7 @@ impl BasicVerifier { for sig_reg in sigs.iter() { if sig_reg .sig - .verify_core( + .basic_verify( params, &sig_reg.reg_party.0, &sig_reg.reg_party.1, @@ -160,13 +169,33 @@ impl BasicVerifier { } } } - Err(AggregationError::NotEnoughSignatures(count, params.k)) } + /// Given a slice of `sig_reg_list`, this function returns a new list of `sig_reg_list` with only valid indices. + /// In case of conflict (having several signatures for the same index) + /// it selects the smallest signature (i.e. takes the signature with the smallest scalar). + /// The function selects at least `self.k` indexes. + /// # Error + /// If there is no sufficient signatures, then the function fails. + // todo: We need to agree on a criteria to dedup (by default we use a BTreeMap that guarantees keys order) + // todo: not good, because it only removes index if there is a conflict (see benches) + #[deprecated( + since = "0.4.9", + note = "Use `select_valid_signatures_for_k_indices` instead" + )] + pub fn dedup_sigs_for_indices( + total_stake: &Stake, + params: &Parameters, + msg: &[u8], + sigs: &[SingleSignatureWithRegisteredParty], + ) -> Result, AggregationError> { + Self::select_valid_signatures_for_k_indices(total_stake, params, msg, sigs) + } + /// Collect and return `Vec, Vec` which will be used /// by the aggregate verification. - pub(crate) fn collect_sigs_vks( + pub(crate) fn collect_signatures_verification_keys( sig_reg_list: &[SingleSignatureWithRegisteredParty], ) -> (Vec, Vec) { let sigs = sig_reg_list @@ -198,12 +227,16 @@ impl BasicVerifier { }) .collect::>(); - let unique_sigs = - Self::dedup_sigs_for_indices(&self.total_stake, parameters, msg, &sig_reg_list)?; + let unique_sigs = Self::select_valid_signatures_for_k_indices( + &self.total_stake, + parameters, + msg, + &sig_reg_list, + )?; Self::preliminary_verify(&self.total_stake, &unique_sigs, parameters, msg)?; - let (sigs, vks) = Self::collect_sigs_vks(&unique_sigs); + let (sigs, vks) = Self::collect_signatures_verification_keys(&unique_sigs); BlsSignature::verify_aggregate(msg.to_vec().as_slice(), &vks, &sigs)?; diff --git a/mithril-stm/src/aggregate_signature/clerk.rs b/mithril-stm/src/aggregate_signature/clerk.rs index 9a7b72b8f13..8e54edb031a 100644 --- a/mithril-stm/src/aggregate_signature/clerk.rs +++ b/mithril-stm/src/aggregate_signature/clerk.rs @@ -17,34 +17,52 @@ pub struct Clerk { impl Clerk { /// Create a new `Clerk` from a closed registration instance. - pub fn from_registration(params: &Parameters, closed_reg: &ClosedKeyRegistration) -> Self { + pub fn new_clerk_from_closed_key_registration( + params: &Parameters, + closed_reg: &ClosedKeyRegistration, + ) -> Self { Self { params: *params, closed_reg: closed_reg.clone(), } } + /// Create a new `Clerk` from a closed registration instance. + #[deprecated( + since = "0.4.9", + note = "Use `new_clerk_from_closed_key_registration` instead" + )] + pub fn from_registration(params: &Parameters, closed_reg: &ClosedKeyRegistration) -> Self { + Self::new_clerk_from_closed_key_registration(params, closed_reg) + } + /// Create a Clerk from a signer. - pub fn from_signer(signer: &Signer) -> Self { + pub fn new_clerk_from_signer(signer: &Signer) -> Self { let closed_reg = signer - .get_closed_reg() + .get_closed_key_registration() .clone() .expect("Core signer does not include closed registration. Clerk, and so, the Stm certificate cannot be built without closed registration!") ; Self { - params: signer.get_params(), + params: signer.get_parameters(), closed_reg, } } + /// Create a Clerk from a signer. + #[deprecated(since = "0.4.9", note = "Use `new_clerk_from_signer` instead")] + pub fn from_signer(signer: &Signer) -> Self { + Self::new_clerk_from_signer(signer) + } + /// Aggregate a set of signatures for their corresponding indices. /// /// This function first deduplicates the repeated signatures, and if there are enough signatures, it collects the merkle tree indexes of unique signatures. /// The list of merkle tree indexes is used to create a batch proof, to prove that all signatures are from eligible signers. /// /// It returns an instance of `AggregateSignature`. - pub fn aggregate( + pub fn aggregate_signatures( &self, sigs: &[SingleSignature], msg: &[u8], @@ -58,8 +76,8 @@ impl Clerk { .collect::>(); let avk = AggregateVerificationKey::from(&self.closed_reg); - let msgp = avk.get_mt_commitment().concat_with_msg(msg); - let mut unique_sigs = BasicVerifier::dedup_sigs_for_indices( + let msgp = avk.get_merkle_tree_batch_commitment().concatenate_with_message(msg); + let mut unique_sigs = BasicVerifier::select_valid_signatures_for_k_indices( &self.closed_reg.total_stake, &self.params, &msgp, @@ -73,7 +91,10 @@ impl Clerk { .map(|sig_reg| sig_reg.sig.signer_index as usize) .collect::>(); - let batch_proof = self.closed_reg.merkle_tree.get_batched_path(mt_index_list); + let batch_proof = self + .closed_reg + .merkle_tree + .compute_merkle_tree_batch_path(mt_index_list); Ok(AggregateSignature { signatures: unique_sigs, @@ -81,16 +102,49 @@ impl Clerk { }) } + /// Aggregate a set of signatures for their corresponding indices. + /// + /// This function first deduplicates the repeated signatures, and if there are enough signatures, it collects the merkle tree indexes of unique signatures. + /// The list of merkle tree indexes is used to create a batch proof, to prove that all signatures are from eligible signers. + /// + /// It returns an instance of `AggregateSignature`. + #[deprecated(since = "0.4.9", note = "Use `aggregate_signatures` instead")] + pub fn aggregate( + &self, + sigs: &[SingleSignature], + msg: &[u8], + ) -> Result, AggregationError> { + Self::aggregate_signatures(self, sigs, msg) + } + /// Compute the `AggregateVerificationKey` related to the used registration. - pub fn compute_avk(&self) -> AggregateVerificationKey { + pub fn compute_aggregate_verification_key(&self) -> AggregateVerificationKey { AggregateVerificationKey::from(&self.closed_reg) } + /// Compute the `AggregateVerificationKey` related to the used registration. + #[deprecated( + since = "0.4.9", + note = "Use `compute_aggregate_verification_key` instead" + )] + pub fn compute_avk(&self) -> AggregateVerificationKey { + Self::compute_aggregate_verification_key(self) + } + /// Get the (VK, stake) of a party given its index. - pub fn get_reg_party(&self, party_index: &Index) -> Option<(VerificationKey, Stake)> { + pub fn get_registered_party_for_index( + &self, + party_index: &Index, + ) -> Option<(VerificationKey, Stake)> { self.closed_reg .reg_parties .get(*party_index as usize) .map(|&r| r.into()) } + + /// Get the (VK, stake) of a party given its index. + #[deprecated(since = "0.4.9", note = "Use `get_registered_party_for_index` instead")] + pub fn get_reg_party(&self, party_index: &Index) -> Option<(VerificationKey, Stake)> { + Self::get_registered_party_for_index(self, party_index) + } } diff --git a/mithril-stm/src/aggregate_signature/mod.rs b/mithril-stm/src/aggregate_signature/mod.rs index 872bd82a537..f9742b3b2cc 100644 --- a/mithril-stm/src/aggregate_signature/mod.rs +++ b/mithril-stm/src/aggregate_signature/mod.rs @@ -46,14 +46,14 @@ mod tests { let ps = stake .into_iter() .map(|stake| { - let p = Initializer::setup(params, stake, &mut rng); + let p = Initializer::new(params, stake, &mut rng); kr.register(stake, p.pk).unwrap(); p }) .collect::>(); let closed_reg = kr.close(); ps.into_iter() - .map(|p| p.new_signer(closed_reg.clone()).unwrap()) + .map(|p| p.create_signer(closed_reg.clone()).unwrap()) .collect() } @@ -161,12 +161,12 @@ mod tests { phi_f: 1.0, }; let ps = setup_equal_parties(params, n); - let clerk = Clerk::from_signer(&ps[0]); + let clerk = Clerk::new_clerk_from_signer(&ps[0]); let all_ps: Vec = (0..n).collect(); let sigs = find_signatures(&msg, &ps, &all_ps); - let msig = clerk.aggregate(&sigs, &msg); + let msig = clerk.aggregate_signatures(&sigs, &msg); ProofTest { msig, clerk, msg } }) }) @@ -180,8 +180,12 @@ mod tests { Ok(mut aggr) => { f(&mut aggr, &mut tc.clerk, &mut tc.msg); assert!( - aggr.verify(&tc.msg, &tc.clerk.compute_avk(), &tc.clerk.params) - .is_err() + aggr.verify( + &tc.msg, + &tc.clerk.compute_aggregate_verification_key(), + &tc.clerk.params + ) + .is_err() ) } Err(e) => unreachable!("Reached an unexpected error: {:?}", e), @@ -197,8 +201,8 @@ mod tests { let false_msg = [1u8; 20]; let params = Parameters { m: 1, k: 1, phi_f: 1.0 }; let ps = setup_equal_parties(params, 1); - let clerk = Clerk::from_signer(&ps[0]); - let avk = clerk.compute_avk(); + let clerk = Clerk::new_clerk_from_signer(&ps[0]); + let avk = clerk.compute_aggregate_verification_key(); let mut sigs = Vec::with_capacity(2); if let Some(sig) = ps[0].sign(&false_msg) { @@ -217,8 +221,8 @@ mod tests { }) .collect::>(); - let msgp = avk.get_mt_commitment().concat_with_msg(&msg); - let dedup_result = BasicVerifier::dedup_sigs_for_indices( + let msgp = avk.get_merkle_tree_batch_commitment().concatenate_with_message(&msg); + let dedup_result = BasicVerifier::select_valid_signatures_for_k_indices( &clerk.closed_reg.total_stake, ¶ms, &msgp, @@ -226,7 +230,7 @@ mod tests { ); assert!(dedup_result.is_ok(), "dedup failure {dedup_result:?}"); for passed_sigs in dedup_result.unwrap() { - let verify_result = passed_sigs.sig.verify(¶ms, &ps[0].get_vk(), &ps[0].get_stake(), &avk, &msg); + let verify_result = passed_sigs.sig.verify(¶ms, &ps[0].get_verification_key(), &ps[0].get_stake(), &avk, &msg); assert!(verify_result.is_ok(), "verify {verify_result:?}"); } } @@ -244,15 +248,15 @@ mod tests { msg in any::<[u8;16]>()) { let params = Parameters { m, k, phi_f: 0.2 }; let ps = setup_equal_parties(params, nparties); - let clerk = Clerk::from_signer(&ps[0]); + let clerk = Clerk::new_clerk_from_signer(&ps[0]); let all_ps: Vec = (0..nparties).collect(); let sigs = find_signatures(&msg, &ps, &all_ps); - let msig = clerk.aggregate(&sigs, &msg); + let msig = clerk.aggregate_signatures(&sigs, &msg); match msig { Ok(aggr) => { - let verify_result = aggr.verify(&msg, &clerk.compute_avk(), ¶ms); + let verify_result = aggr.verify(&msg, &clerk.compute_aggregate_verification_key(), ¶ms); assert!(verify_result.is_ok(), "Verification failed: {verify_result:?}"); } Err(AggregationError::NotEnoughSignatures(n, k)) => @@ -280,15 +284,15 @@ mod tests { rng.fill_bytes(&mut msg); let params = Parameters { m, k, phi_f: 0.95 }; let ps = setup_equal_parties(params, nparties); - let clerk = Clerk::from_signer(&ps[0]); + let clerk = Clerk::new_clerk_from_signer(&ps[0]); let all_ps: Vec = (0..nparties).collect(); let sigs = find_signatures(&msg, &ps, &all_ps); - let msig = clerk.aggregate(&sigs, &msg); + let msig = clerk.aggregate_signatures(&sigs, &msg); match msig { Ok(aggr) => { - aggr_avks.push(clerk.compute_avk()); + aggr_avks.push(clerk.compute_aggregate_verification_key()); aggr_stms.push(aggr); batch_msgs.push(msg.to_vec()); batch_params.push(params); @@ -306,11 +310,11 @@ mod tests { rng.fill_bytes(&mut msg); let params = Parameters { m, k, phi_f: 0.8 }; let ps = setup_equal_parties(params, nparties); - let clerk = Clerk::from_signer(&ps[0]); + let clerk = Clerk::new_clerk_from_signer(&ps[0]); let all_ps: Vec = (0..nparties).collect(); let sigs = find_signatures(&msg, &ps, &all_ps); - let fake_msig = clerk.aggregate(&sigs, &msg); + let fake_msig = clerk.aggregate_signatures(&sigs, &msg); aggr_stms[0] = fake_msig.unwrap(); assert!(AggregateSignature::batch_verify(&aggr_stms, &batch_msgs, &aggr_avks, &batch_params).is_err()); @@ -323,11 +327,11 @@ mod tests { fn test_sig(msg in any::<[u8;16]>()) { let params = Parameters { m: 1, k: 1, phi_f: 0.2 }; let ps = setup_equal_parties(params, 1); - let clerk = Clerk::from_signer(&ps[0]); - let avk = clerk.compute_avk(); + let clerk = Clerk::new_clerk_from_signer(&ps[0]); + let avk = clerk.compute_aggregate_verification_key(); if let Some(sig) = ps[0].sign(&msg) { - assert!(sig.verify(¶ms, &ps[0].get_vk(), &ps[0].get_stake(), &avk, &msg).is_ok()); + assert!(sig.verify(¶ms, &ps[0].get_verification_key(), &ps[0].get_stake(), &avk, &msg).is_ok()); } } } @@ -348,7 +352,7 @@ mod tests { let mut rng = ChaCha20Rng::from_seed(seed); let params = Parameters { m: 1, k: 1, phi_f: 1.0 }; let stake = rng.next_u64(); - let initializer = Initializer::setup(params, stake, &mut rng); + let initializer = Initializer::new(params, stake, &mut rng); let bytes = initializer.to_bytes(); assert!(Initializer::from_bytes(&bytes).is_ok()); @@ -361,17 +365,17 @@ mod tests { fn test_sig_serialize_deserialize(msg in any::<[u8;16]>()) { let params = Parameters { m: 1, k: 1, phi_f: 0.2 }; let ps = setup_equal_parties(params, 1); - let clerk = Clerk::from_signer(&ps[0]); - let avk = clerk.compute_avk(); + let clerk = Clerk::new_clerk_from_signer(&ps[0]); + let avk = clerk.compute_aggregate_verification_key(); if let Some(sig) = ps[0].sign(&msg) { let bytes = sig.to_bytes(); let sig_deser = SingleSignature::from_bytes::(&bytes).unwrap(); - assert!(sig_deser.verify(¶ms, &ps[0].get_vk(), &ps[0].get_stake(), &avk, &msg).is_ok()); + assert!(sig_deser.verify(¶ms, &ps[0].get_verification_key(), &ps[0].get_stake(), &avk, &msg).is_ok()); let encoded = bincode::serde::encode_to_vec(&sig, bincode::config::legacy()).unwrap(); let (decoded,_) = bincode::serde::decode_from_slice::(&encoded, bincode::config::legacy()).unwrap(); - assert!(decoded.verify(¶ms, &ps[0].get_vk(), &ps[0].get_stake(), &avk, &msg).is_ok()); + assert!(decoded.verify(¶ms, &ps[0].get_verification_key(), &ps[0].get_stake(), &avk, &msg).is_ok()); } } @@ -380,19 +384,19 @@ mod tests { msg in any::<[u8;16]>()) { let params = Parameters { m: 10, k: 5, phi_f: 1.0 }; let ps = setup_equal_parties(params, nparties); - let clerk = Clerk::from_signer(&ps[0]); + let clerk = Clerk::new_clerk_from_signer(&ps[0]); let all_ps: Vec = (0..nparties).collect(); let sigs = find_signatures(&msg, &ps, &all_ps); - let msig = clerk.aggregate(&sigs, &msg); + let msig = clerk.aggregate_signatures(&sigs, &msg); if let Ok(aggr) = msig { let bytes: Vec = aggr.to_bytes(); let aggr2 = AggregateSignature::from_bytes(&bytes).unwrap(); - assert!(aggr2.verify(&msg, &clerk.compute_avk(), ¶ms).is_ok()); + assert!(aggr2.verify(&msg, &clerk.compute_aggregate_verification_key(), ¶ms).is_ok()); let encoded = bincode::serde::encode_to_vec(&aggr, bincode::config::legacy()).unwrap(); let (decoded,_) = bincode::serde::decode_from_slice::,_>(&encoded, bincode::config::legacy()).unwrap(); - assert!(decoded.verify(&msg, &clerk.compute_avk(), ¶ms).is_ok()); + assert!(decoded.verify(&msg, &clerk.compute_aggregate_verification_key(), ¶ms).is_ok()); } } } @@ -424,9 +428,9 @@ mod tests { assert!(sigs.len() < params.k as usize); - let clerk = Clerk::from_signer(&ps[0]); + let clerk = Clerk::new_clerk_from_signer(&ps[0]); - let msig = clerk.aggregate(&sigs, &msg); + let msig = clerk.aggregate_signatures(&sigs, &msg); match msig { Err(AggregationError::NotEnoughSignatures(n, k)) => assert!(n < params.k && params.k == k), @@ -501,7 +505,7 @@ mod tests { let ps = stake .into_iter() - .map(|stake| Initializer::setup(params, stake, &mut rng)) + .map(|stake| Initializer::new(params, stake, &mut rng)) .collect::>(); let public_signers = ps @@ -520,7 +524,7 @@ mod tests { ) -> Vec { let mut sigs = Vec::new(); for i in is { - if let Some(sig) = ps[*i].core_sign(msg, total_stake) { + if let Some(sig) = ps[*i].basic_sign(msg, total_stake) { sigs.push(sig); } } @@ -540,11 +544,11 @@ mod tests { let (initializers, public_signers) = setup_equal_core_parties(params, nparties); let all_ps: Vec = (0..nparties).collect(); - let core_verifier = BasicVerifier::setup(&public_signers); + let core_verifier = BasicVerifier::new(&public_signers); let signers = initializers .into_iter() - .filter_map(|s| s.new_core_signer(&core_verifier.eligible_parties)) + .filter_map(|s| s.create_basic_signer(&core_verifier.eligible_parties)) .collect::>>(); let signatures = find_core_signatures(&msg, &signers, core_verifier.total_stake, &all_ps); @@ -569,7 +573,7 @@ mod tests { k in 1_u64..5,) { let params = Parameters { m, k, phi_f: 0.2 }; let (_initializers, public_signers) = setup_equal_core_parties(params, nparties); - let core_verifier = BasicVerifier::setup(&public_signers); + let core_verifier = BasicVerifier::new(&public_signers); assert_eq!(nparties as u64, core_verifier.total_stake, "Total stake expected: {}, got: {}.", nparties, core_verifier.total_stake); } } diff --git a/mithril-stm/src/aggregate_signature/signature.rs b/mithril-stm/src/aggregate_signature/signature.rs index 91fc4d219ed..24bb7a848f9 100644 --- a/mithril-stm/src/aggregate_signature/signature.rs +++ b/mithril-stm/src/aggregate_signature/signature.rs @@ -37,7 +37,7 @@ impl AggregateSignature { avk: &AggregateVerificationKey, parameters: &Parameters, ) -> Result<(Vec, Vec), StmAggregateSignatureError> { - let msgp = avk.get_mt_commitment().concat_with_msg(msg); + let msgp = avk.get_merkle_tree_batch_commitment().concatenate_with_message(msg); BasicVerifier::preliminary_verify( &avk.get_total_stake(), &self.signatures, @@ -51,9 +51,12 @@ impl AggregateSignature { .map(|r| r.reg_party) .collect::>(); - avk.get_mt_commitment().check(&leaves, &self.batch_proof)?; + avk.get_merkle_tree_batch_commitment() + .verify_leaves_membership_from_batch_path(&leaves, &self.batch_proof)?; - Ok(BasicVerifier::collect_sigs_vks(&self.signatures)) + Ok(BasicVerifier::collect_signatures_verification_keys( + &self.signatures, + )) } /// Verify aggregate signature, by checking that @@ -68,7 +71,7 @@ impl AggregateSignature { avk: &AggregateVerificationKey, parameters: &Parameters, ) -> Result<(), StmAggregateSignatureError> { - let msgp = avk.get_mt_commitment().concat_with_msg(msg); + let msgp = avk.get_merkle_tree_batch_commitment().concatenate_with_message(msg); let (sigs, vks) = self.preliminary_verify(msg, avk, parameters)?; BlsSignature::verify_aggregate(msgp.as_slice(), &vks, &sigs)?; @@ -119,7 +122,7 @@ impl AggregateSignature { let concat_msgs: Vec> = msgs .iter() .zip(avks.iter()) - .map(|(msg, avk)| avk.get_mt_commitment().concat_with_msg(msg)) + .map(|(msg, avk)| avk.get_merkle_tree_batch_commitment().concatenate_with_message(msg)) .collect(); BlsSignature::batch_verify_aggregates(&concat_msgs, &aggr_vks, &aggr_sigs)?; diff --git a/mithril-stm/src/bls_multi_signature/helper.rs b/mithril-stm/src/bls_multi_signature/helper.rs index c53abfc6126..d2be6e32d16 100644 --- a/mithril-stm/src/bls_multi_signature/helper.rs +++ b/mithril-stm/src/bls_multi_signature/helper.rs @@ -14,11 +14,12 @@ pub(crate) mod unsafe_helpers { pub(crate) fn verify_pairing(vk: &BlsVerificationKey, pop: &BlsProofOfPossession) -> bool { unsafe { let g1_p = *blst_p1_affine_generator(); - let mvk_p = std::mem::transmute::(vk.to_blst_vk()); + let mvk_p = + std::mem::transmute::(vk.to_blst_verification_key()); let ml_lhs = blst_fp12::miller_loop(&mvk_p, &g1_p); let mut k2_p = blst_p1_affine::default(); - blst_p1_to_affine(&mut k2_p, &pop.to_k2()); + blst_p1_to_affine(&mut k2_p, &pop.get_k2()); let g2_p = *blst_p2_affine_generator(); let ml_rhs = blst_fp12::miller_loop(&g2_p, &k2_p); @@ -60,7 +61,7 @@ pub(crate) mod unsafe_helpers { let mut projective_p2 = blst_p2::default(); blst_p2_from_affine( &mut projective_p2, - &std::mem::transmute::(vk.to_blst_vk()), + &std::mem::transmute::(vk.to_blst_verification_key()), ); projective_p2 } diff --git a/mithril-stm/src/bls_multi_signature/mod.rs b/mithril-stm/src/bls_multi_signature/mod.rs index 2d9e5a644ea..9259c3c86e3 100644 --- a/mithril-stm/src/bls_multi_signature/mod.rs +++ b/mithril-stm/src/bls_multi_signature/mod.rs @@ -102,7 +102,7 @@ mod tests { impl PartialEq for BlsSigningKey { fn eq(&self, other: &Self) -> bool { - self.to_blst_sk().to_bytes() == other.to_blst_sk().to_bytes() + self.to_blst_secret_key().to_bytes() == other.to_blst_secret_key().to_bytes() } } @@ -158,7 +158,7 @@ mod tests { let vk_infinity = BlsVerificationKey(p2_affine_to_vk(&p2)); let vkpop_infinity = BlsVerificationKeyProofOfPossession { vk: vk_infinity, pop }; - let result = vkpop_infinity.check(); + let result = vkpop_infinity.verify_proof_of_possesion(); assert_eq!(result, Err(MultiSignatureError::VerificationKeyInfinity(Box::new(vkpop_infinity.vk)))); } @@ -210,7 +210,7 @@ mod tests { seed in any::<[u8;32]>()) { let sk = BlsSigningKey::generate(&mut ChaCha20Rng::from_seed(seed)); let sig = sk.sign(&msg); - sig.eval(&msg, idx); + sig.evaluate_dense_mapping(&msg, idx); } #[test] diff --git a/mithril-stm/src/bls_multi_signature/proof_of_possession.rs b/mithril-stm/src/bls_multi_signature/proof_of_possession.rs index 6b73b9b5cdd..9794c21d4d8 100644 --- a/mithril-stm/src/bls_multi_signature/proof_of_possession.rs +++ b/mithril-stm/src/bls_multi_signature/proof_of_possession.rs @@ -49,11 +49,11 @@ impl BlsProofOfPossession { Ok(Self { k1, k2 }) } - pub(crate) fn to_k1(self) -> BlstSig { + pub(crate) fn get_k1(self) -> BlstSig { self.k1 } - pub(crate) fn to_k2(self) -> blst_p1 { + pub(crate) fn get_k2(self) -> blst_p1 { self.k2 } } @@ -63,8 +63,8 @@ impl From<&BlsSigningKey> for BlsProofOfPossession { /// `k1 = H_G1(b"PoP" || mvk)` and `k2 = g1 * sk` where `H_G1` hashes into /// `G1` and `g1` is the generator in `G1`. fn from(sk: &BlsSigningKey) -> Self { - let k1 = sk.to_blst_sk().sign(POP, &[], &[]); - let k2 = scalar_to_pk_in_g1(&sk.to_blst_sk()); + let k1 = sk.to_blst_secret_key().sign(POP, &[], &[]); + let k2 = scalar_to_pk_in_g1(&sk.to_blst_secret_key()); Self { k1, k2 } } } diff --git a/mithril-stm/src/bls_multi_signature/signature.rs b/mithril-stm/src/bls_multi_signature/signature.rs index 0d59f01fd52..86f08a834c7 100644 --- a/mithril-stm/src/bls_multi_signature/signature.rs +++ b/mithril-stm/src/bls_multi_signature/signature.rs @@ -27,7 +27,10 @@ impl BlsSignature { blst_err_to_mithril( self.0.validate(true).map_or_else( |e| e, - |_| self.0.verify(false, msg, &[], &[], &mvk.to_blst_vk(), false), + |_| { + self.0 + .verify(false, msg, &[], &[], &mvk.to_blst_verification_key(), false) + }, ), Some(*self), None, @@ -38,7 +41,7 @@ impl BlsSignature { /// We hash the signature to produce a 64 bytes integer. /// The return value of this function refers to /// `ev = H("map" || msg || index || σ) <- MSP.Eval(msg,index,σ)` given in paper. - pub fn eval(&self, msg: &[u8], index: Index) -> [u8; 64] { + pub(crate) fn evaluate_dense_mapping(&self, msg: &[u8], index: Index) -> [u8; 64] { let hasher = Blake2b512::new() .chain_update(b"map") .chain_update(msg) @@ -72,7 +75,7 @@ impl BlsSignature { /// Compare two signatures. Used for PartialOrd impl, used to rank signatures. The comparison /// function can be anything, as long as it is consistent across different nodes. - fn cmp_msp_sig(&self, other: &Self) -> Ordering { + fn compare_signatures(&self, other: &Self) -> Ordering { let self_bytes = self.to_bytes(); let other_bytes = other.to_bytes(); let mut result = Ordering::Equal; @@ -139,7 +142,14 @@ impl BlsSignature { let (aggr_vk, aggr_sig) = Self::aggregate(vks, sigs)?; blst_err_to_mithril( - aggr_sig.0.verify(false, msg, &[], &[], &aggr_vk.to_blst_vk(), false), + aggr_sig.0.verify( + false, + msg, + &[], + &[], + &aggr_vk.to_blst_verification_key(), + false, + ), Some(aggr_sig), None, ) @@ -159,7 +169,7 @@ impl BlsSignature { Err(e) => return blst_err_to_mithril(e, None, None), }; - let p2_vks: Vec = vks.iter().map(|vk| vk.to_blst_vk()).collect(); + let p2_vks: Vec = vks.iter().map(|vk| vk.to_blst_verification_key()).collect(); let p2_vks_ref: Vec<&BlstVk> = p2_vks.iter().collect(); let slice_msgs = msgs.iter().map(|msg| msg.as_slice()).collect::>(); @@ -195,6 +205,6 @@ impl PartialOrd for BlsSignature { impl Ord for BlsSignature { fn cmp(&self, other: &Self) -> Ordering { - self.cmp_msp_sig(other) + self.compare_signatures(other) } } diff --git a/mithril-stm/src/bls_multi_signature/signing_key.rs b/mithril-stm/src/bls_multi_signature/signing_key.rs index f96fb36396c..486dd9ba165 100644 --- a/mithril-stm/src/bls_multi_signature/signing_key.rs +++ b/mithril-stm/src/bls_multi_signature/signing_key.rs @@ -43,7 +43,7 @@ impl BlsSigningKey { } } - pub(crate) fn to_blst_sk(&self) -> BlstSk { + pub(crate) fn to_blst_secret_key(&self) -> BlstSk { self.0.clone() } } diff --git a/mithril-stm/src/bls_multi_signature/verification_key.rs b/mithril-stm/src/bls_multi_signature/verification_key.rs index a148645f7ad..a4b7389ab23 100644 --- a/mithril-stm/src/bls_multi_signature/verification_key.rs +++ b/mithril-stm/src/bls_multi_signature/verification_key.rs @@ -43,7 +43,7 @@ impl BlsVerificationKey { /// Compare two `VerificationKey`. Used for PartialOrd impl, used to order signatures. The comparison /// function can be anything, as long as it is consistent. - fn cmp_msp_mvk(&self, other: &BlsVerificationKey) -> Ordering { + fn compare_verification_keys(&self, other: &BlsVerificationKey) -> Ordering { let self_bytes = self.to_bytes(); let other_bytes = other.to_bytes(); let mut result = Ordering::Equal; @@ -58,7 +58,7 @@ impl BlsVerificationKey { result } - pub(crate) fn to_blst_vk(self) -> BlstVk { + pub(crate) fn to_blst_verification_key(self) -> BlstVk { self.0 } } @@ -91,7 +91,7 @@ impl PartialOrd for BlsVerificationKey { impl Ord for BlsVerificationKey { fn cmp(&self, other: &Self) -> Ordering { - self.cmp_msp_mvk(other) + self.compare_verification_keys(other) } } @@ -116,7 +116,7 @@ impl From<&BlsSigningKey> for BlsVerificationKey { /// `MspMvk = g2 * sk`, where `g2` is the generator in G2. We can use the /// blst built-in function `sk_to_pk`. fn from(sk: &BlsSigningKey) -> Self { - BlsVerificationKey(sk.to_blst_sk().sk_to_pk()) + BlsVerificationKey(sk.to_blst_secret_key().sk_to_pk()) } } @@ -136,15 +136,18 @@ impl BlsVerificationKeyProofOfPossession { /// manually. // If we are really looking for performance improvements, we can combine the // two final exponentiations (for verifying k1 and k2) into a single one. - pub fn check(&self) -> Result<(), MultiSignatureError> { - match self.vk.to_blst_vk().validate() { + pub(crate) fn verify_proof_of_possesion(&self) -> Result<(), MultiSignatureError> { + match self.vk.to_blst_verification_key().validate() { Ok(_) => { let result = verify_pairing(&self.vk, &self.pop); - if !(self - .pop - .to_k1() - .verify(false, POP, &[], &[], &self.vk.to_blst_vk(), false) - == BLST_ERROR::BLST_SUCCESS + if !(self.pop.get_k1().verify( + false, + POP, + &[], + &[], + &self.vk.to_blst_verification_key(), + false, + ) == BLST_ERROR::BLST_SUCCESS && result) { return Err(MultiSignatureError::KeyInvalid(Box::new(*self))); @@ -155,6 +158,17 @@ impl BlsVerificationKeyProofOfPossession { } } + /// if `e(k1,g2) = e(H_G1("PoP" || mvk),mvk)` and `e(g1,mvk) = e(k2,g2)` + /// are both true, return 1. The first part is a signature verification + /// of message "PoP", while the second we need to compute the pairing + /// manually. + // If we are really looking for performance improvements, we can combine the + // two final exponentiations (for verifying k1 and k2) into a single one. + #[deprecated(since = "0.4.9", note = "Use `verify_proof_of_possesion` instead")] + pub fn check(&self) -> Result<(), MultiSignatureError> { + Self::verify_proof_of_possesion(self) + } + /// Convert to a 144 byte string. /// /// # Layout diff --git a/mithril-stm/src/eligibility_check.rs b/mithril-stm/src/eligibility_check.rs index e9e35fb0951..bf51d690054 100644 --- a/mithril-stm/src/eligibility_check.rs +++ b/mithril-stm/src/eligibility_check.rs @@ -31,7 +31,7 @@ use { /// 1 - p 1 - (ev / evMax) (evMax - ev) /// /// Used to determine winning lottery tickets. -pub(crate) fn ev_lt_phi(phi_f: f64, ev: [u8; 64], stake: Stake, total_stake: Stake) -> bool { +pub(crate) fn is_lottery_won(phi_f: f64, ev: [u8; 64], stake: Stake, total_stake: Stake) -> bool { // If phi_f = 1, then we automatically break with true if (phi_f - 1.0).abs() < f64::EPSILON { return true; @@ -92,7 +92,7 @@ fn taylor_comparison(bound: usize, cmp: Ratio, x: Ratio) -> bool /// order to keep the error in the 1e-17 range, we need to carry out the computations with 34 /// decimal digits (in order to represent the 4.5e16 ada without any rounding errors, we need /// double that precision). -pub(crate) fn ev_lt_phi(phi_f: f64, ev: [u8; 64], stake: Stake, total_stake: Stake) -> bool { +pub(crate) fn is_lottery_won(phi_f: f64, ev: [u8; 64], stake: Stake, total_stake: Stake) -> bool { use rug::{Float, integer::Order, ops::Pow}; // If phi_f = 1, then we automatically break with true @@ -115,8 +115,8 @@ mod tests { use num_bigint::{BigInt, Sign}; use num_rational::Ratio; use proptest::prelude::*; - // Implementation of `ev_lt_phi` without approximation. We only get the precision of f64 here. - fn simple_ev_lt_phi(phi_f: f64, ev: [u8; 64], stake: Stake, total_stake: Stake) -> bool { + // Implementation of `is_lottery_won` without approximation. We only get the precision of f64 here. + fn trivial_is_lottery_won(phi_f: f64, ev: [u8; 64], stake: Stake, total_stake: Stake) -> bool { let ev_max = BigInt::from(2u8).pow(512); let ev = BigInt::from_bytes_le(Sign::Plus, &ev); let q = Ratio::new_raw(ev, ev_max); @@ -130,8 +130,8 @@ mod tests { #![proptest_config(ProptestConfig::with_cases(50))] #[test] - /// Checking the ev_lt_phi function. - fn test_precision_approximation( + /// Checking the `is_lottery_won` function. + fn is_lottery_won_check_precision_against_trivial_implementation( phi_f in 0.01..0.5f64, ev_1 in any::<[u8; 32]>(), ev_2 in any::<[u8; 32]>(), @@ -141,15 +141,15 @@ mod tests { let mut ev = [0u8; 64]; ev.copy_from_slice(&[&ev_1[..], &ev_2[..]].concat()); - let quick_result = simple_ev_lt_phi(phi_f, ev, stake, total_stake); - let result = ev_lt_phi(phi_f, ev, stake, total_stake); + let quick_result = trivial_is_lottery_won(phi_f, ev, stake, total_stake); + let result = is_lottery_won(phi_f, ev, stake, total_stake); assert_eq!(quick_result, result); } #[cfg(any(feature = "num-integer-backend", target_family = "wasm", windows))] #[test] /// Checking the early break of Taylor computation - fn early_break_taylor( + fn taylor_comparison_breaks_early( x in -0.9..0.9f64, ) { let exponential = num_traits::float::Float::exp(x); diff --git a/mithril-stm/src/key_registration.rs b/mithril-stm/src/key_registration.rs index 664dda91887..4b243b0a108 100644 --- a/mithril-stm/src/key_registration.rs +++ b/mithril-stm/src/key_registration.rs @@ -37,7 +37,7 @@ impl KeyRegistration { pk: BlsVerificationKeyProofOfPossession, ) -> Result<(), RegisterError> { if let Entry::Vacant(e) = self.keys.entry(pk.vk) { - pk.check()?; + pk.verify_proof_of_possesion()?; e.insert(stake); return Ok(()); } @@ -66,7 +66,7 @@ impl KeyRegistration { reg_parties.sort(); ClosedKeyRegistration { - merkle_tree: Arc::new(MerkleTree::create(®_parties)), + merkle_tree: Arc::new(MerkleTree::new(®_parties)), reg_parties, total_stake, } @@ -136,7 +136,7 @@ mod tests { } Err(RegisterError::KeyInvalid(a)) => { assert_eq!(fake_it, 0); - assert!(a.check().is_err()); + assert!(a.verify_proof_of_possesion().is_err()); } Err(RegisterError::SerializationError) => unreachable!(), _ => unreachable!(), diff --git a/mithril-stm/src/merkle_tree/commitment.rs b/mithril-stm/src/merkle_tree/commitment.rs index 8b48d6837b0..663371e9e45 100644 --- a/mithril-stm/src/merkle_tree/commitment.rs +++ b/mithril-stm/src/merkle_tree/commitment.rs @@ -27,7 +27,7 @@ impl MerkleTreeCommitment { /// Check an inclusion proof that `val` is part of the tree by traveling the whole path until the root. /// # Error /// If the merkle tree path is invalid, then the function fails. - pub fn check( + pub(crate) fn verify_leaf_membership_from_path( &self, val: &MerkleTreeLeaf, proof: &MerklePath, @@ -53,9 +53,27 @@ impl MerkleTreeCommitment { Err(MerkleTreeError::PathInvalid(proof.clone())) } + /// Check an inclusion proof that `val` is part of the tree by traveling the whole path until the root. + /// # Error + /// If the merkle tree path is invalid, then the function fails. + #[deprecated( + since = "0.4.9", + note = "Use `verify_leaf_membership_from_path` instead" + )] + pub fn check( + &self, + val: &MerkleTreeLeaf, + proof: &MerklePath, + ) -> Result<(), MerkleTreeError> + where + D: FixedOutput + Clone, + { + Self::verify_leaf_membership_from_path(self, val, proof) + } + /// Serializes the Merkle Tree commitment together with a message in a single vector of bytes. /// Outputs `msg || self` as a vector of bytes. - pub fn concat_with_msg(&self, msg: &[u8]) -> Vec + fn concatenate_with_message(&self, msg: &[u8]) -> Vec where D: Digest, { @@ -65,6 +83,16 @@ impl MerkleTreeCommitment { msgp } + + /// Serializes the Merkle Tree commitment together with a message in a single vector of bytes. + /// Outputs `msg || self` as a vector of bytes. + #[deprecated(since = "0.4.9", note = "Use `concatenate_with_message` instead")] + pub fn concat_with_msg(&self, msg: &[u8]) -> Vec + where + D: Digest, + { + Self::concatenate_with_message(self, msg) + } } /// Batch compatible `MerkleTree` commitment . @@ -90,14 +118,14 @@ impl MerkleTreeBatchCommitment { #[cfg(test)] /// Used in property test of `tree`: `test_bytes_tree_commitment_batch_compat` - pub(crate) fn get_nr_leaves(&self) -> usize { + pub(crate) fn get_number_of_leaves(&self) -> usize { self.nr_leaves } /// Serializes the Merkle Tree commitment together with a message in a single vector of bytes. /// Outputs `msg || self` as a vector of bytes. // todo: Do we need to concat msg to whole commitment (nr_leaves and root) or just the root? - pub fn concat_with_msg(&self, msg: &[u8]) -> Vec { + pub(crate) fn concatenate_with_message(&self, msg: &[u8]) -> Vec { let mut msgp = msg.to_vec(); let mut bytes = self.root.clone(); msgp.append(&mut bytes); @@ -105,6 +133,14 @@ impl MerkleTreeBatchCommitment { msgp } + /// Serializes the Merkle Tree commitment together with a message in a single vector of bytes. + /// Outputs `msg || self` as a vector of bytes. + // todo: Do we need to concat msg to whole commitment (nr_leaves and root) or just the root? + #[deprecated(since = "0.4.9", note = "Use `concatenate_with_message` instead")] + pub fn concat_with_msg(&self, msg: &[u8]) -> Vec { + Self::concatenate_with_message(self, msg) + } + /// Check a proof of a batched opening. The indices must be ordered. /// /// # Error @@ -112,7 +148,7 @@ impl MerkleTreeBatchCommitment { // todo: Update doc. // todo: Simplify the algorithm. // todo: Maybe we want more granular errors, rather than only `BatchPathInvalid` - pub fn check( + pub(crate) fn verify_leaves_membership_from_batch_path( &self, batch_val: &[MerkleTreeLeaf], proof: &MerkleBatchPath, @@ -196,6 +232,28 @@ impl MerkleTreeBatchCommitment { Err(MerkleTreeError::BatchPathInvalid(proof.clone())) } + + /// Check a proof of a batched opening. The indices must be ordered. + /// + /// # Error + /// Returns an error if the proof is invalid. + // todo: Update doc. + // todo: Simplify the algorithm. + // todo: Maybe we want more granular errors, rather than only `BatchPathInvalid` + #[deprecated( + since = "0.4.9", + note = "Use `verify_leaves_membership_from_batch_path` instead" + )] + pub fn check( + &self, + batch_val: &[MerkleTreeLeaf], + proof: &MerkleBatchPath, + ) -> Result<(), MerkleTreeError> + where + D: FixedOutput + Clone, + { + Self::verify_leaves_membership_from_batch_path(self, batch_val, proof) + } } impl PartialEq for MerkleTreeBatchCommitment { diff --git a/mithril-stm/src/merkle_tree/tree.rs b/mithril-stm/src/merkle_tree/tree.rs index 8c046eeb9a3..0a56a04d892 100644 --- a/mithril-stm/src/merkle_tree/tree.rs +++ b/mithril-stm/src/merkle_tree/tree.rs @@ -28,7 +28,7 @@ pub struct MerkleTree { impl MerkleTree { /// Provided a non-empty list of leaves, `create` generates its corresponding `MerkleTree`. - pub fn create(leaves: &[MerkleTreeLeaf]) -> MerkleTree { + pub(crate) fn new(leaves: &[MerkleTreeLeaf]) -> MerkleTree { let n = leaves.len(); assert!(n > 0, "MerkleTree::create() called with no leaves"); @@ -63,22 +63,33 @@ impl MerkleTree { } } - /// Get the root of the tree. - pub fn root(&self) -> &Vec { - &self.nodes[0] + /// Provided a non-empty list of leaves, `create` generates its corresponding `MerkleTree`. + #[deprecated(since = "0.4.9", note = "Use `new` instead")] + pub fn create(leaves: &[MerkleTreeLeaf]) -> MerkleTree { + Self::new(leaves) } /// Return the index of the leaf. - fn idx_of_leaf(&self, i: usize) -> usize { + fn get_leaf_index(&self, i: usize) -> usize { self.leaf_off + i } /// Convert merkle tree to a batch compatible commitment. /// This function simply returns the root and the number of leaves in the tree. - pub fn to_commitment_batch_compat(&self) -> MerkleTreeBatchCommitment { + pub(crate) fn to_merkle_tree_batch_commitment(&self) -> MerkleTreeBatchCommitment { MerkleTreeBatchCommitment::new(self.nodes[0].clone(), self.n) } + /// Convert merkle tree to a batch compatible commitment. + /// This function simply returns the root and the number of leaves in the tree. + #[deprecated( + since = "0.4.9", + note = "Use `to_merkle_tree_batch_commitment` instead" + )] + pub fn to_commitment_batch_compat(&self) -> MerkleTreeBatchCommitment { + Self::to_merkle_tree_batch_commitment(self) + } + /// Get a path for a batch of leaves. The indices must be ordered. We use the Octopus algorithm to /// avoid redundancy with nodes in the path. Let `x1, . . . , xk` be the indices of elements we /// want to produce an opening for. The algorithm takes as input `x1, . . ., xk`, and proceeds as follows: @@ -95,7 +106,7 @@ impl MerkleTree { /// If the indices provided are out of bounds (higher than the number of elements /// committed in the `MerkleTree`) or are not ordered, the function fails. // todo: Update doc. - pub fn get_batched_path(&self, indices: Vec) -> MerkleBatchPath + pub(crate) fn compute_merkle_tree_batch_path(&self, indices: Vec) -> MerkleBatchPath where D: FixedOutput, { @@ -117,7 +128,7 @@ impl MerkleTree { assert_eq!(ordered_indices, indices, "Indices should be ordered"); - ordered_indices = ordered_indices.into_iter().map(|i| self.idx_of_leaf(i)).collect(); + ordered_indices = ordered_indices.into_iter().map(|i| self.get_leaf_index(i)).collect(); let mut idx = ordered_indices[0]; let mut proof = Vec::new(); @@ -142,6 +153,30 @@ impl MerkleTree { MerkleBatchPath::new(proof, indices) } + /// Get a path for a batch of leaves. The indices must be ordered. We use the Octopus algorithm to + /// avoid redundancy with nodes in the path. Let `x1, . . . , xk` be the indices of elements we + /// want to produce an opening for. The algorithm takes as input `x1, . . ., xk`, and proceeds as follows: + /// 1. Initialise the proof vector, `proof = []`. + /// 2. Given an input vector `v = v1, . . .,vl`, if `v.len() == 1`, return `proof`, else, continue. + /// 3. Map each `vi` to the corresponding number of the leaf (by adding the offset). + /// 4. Initialise a new empty vector `p = []`. Next, iterate over each element `vi` + /// a. Append the parent of `vi` to `p` + /// b. Compute the sibling, `si` of `vi` + /// c. If `si == v(i+1)` then do nothing, and skip step four for `v(i+1)`. Else append `si` to `proof` + /// 5. Iterate from step 2 with input vector `p` + /// + /// # Panics + /// If the indices provided are out of bounds (higher than the number of elements + /// committed in the `MerkleTree`) or are not ordered, the function fails. + // todo: Update doc. + #[deprecated(since = "0.4.9", note = "Use `compute_merkle_tree_batch_path` instead")] + pub fn get_batched_path(&self, indices: Vec) -> MerkleBatchPath + where + D: FixedOutput, + { + Self::compute_merkle_tree_batch_path(self, indices) + } + /// Convert a `MerkleTree` into a byte string, containing $4 + n * S$ bytes where $n$ is the /// number of nodes and $S$ the output size of the hash function. /// # Layout @@ -186,21 +221,27 @@ impl MerkleTree { } /// Convert merkle tree to a commitment. This function simply returns the root. - pub fn to_commitment(&self) -> MerkleTreeCommitment { + pub(crate) fn to_merkle_tree_commitment(&self) -> MerkleTreeCommitment { MerkleTreeCommitment::new(self.nodes[0].clone()) // Use private constructor } + /// Convert merkle tree to a commitment. This function simply returns the root. + #[deprecated(since = "0.4.9", note = "Use `to_merkle_tree_commitment` instead")] + pub fn to_commitment(&self) -> MerkleTreeCommitment { + Self::to_merkle_tree_commitment(self) + } + /// Get a path (hashes of siblings of the path to the root node) /// for the `i`th value stored in the tree. /// Requires `i < self.n` - pub fn get_path(&self, i: usize) -> MerklePath { + pub(crate) fn compute_merkle_tree_path(&self, i: usize) -> MerklePath { assert!( i < self.n, "Proof index out of bounds: asked for {} out of {}", i, self.n ); - let mut idx = self.idx_of_leaf(i); + let mut idx = self.get_leaf_index(i); let mut proof = Vec::new(); while idx > 0 { @@ -215,6 +256,14 @@ impl MerkleTree { MerklePath::new(proof, i) } + + /// Get a path (hashes of siblings of the path to the root node) + /// for the `i`th value stored in the tree. + /// Requires `i < self.n` + #[deprecated(since = "0.4.9", note = "Use `compute_merkle_tree_path` instead")] + pub fn get_path(&self, i: usize) -> MerklePath { + Self::compute_merkle_tree_path(self, i) + } } #[cfg(test)] @@ -235,7 +284,7 @@ mod tests { (v in vec(any::(), 2..max_size as usize)) -> (MerkleTree>, Vec) { let pks = vec![BlsVerificationKey::default(); v.len()]; let leaves = pks.into_iter().zip(v.into_iter()).map(|(key, stake)| MerkleTreeLeaf(key, stake)).collect::>(); - (MerkleTree::>::create(&leaves), leaves) + (MerkleTree::>::new(&leaves), leaves) } } @@ -246,31 +295,31 @@ mod tests { #[test] fn test_create_proof((t, values) in arb_tree(30)) { values.iter().enumerate().for_each(|(i, _v)| { - let pf = t.get_path(i); - assert!(t.to_commitment().check(&values[i], &pf).is_ok()); + let pf = t.compute_merkle_tree_path(i); + assert!(t.to_merkle_tree_commitment().verify_leaf_membership_from_path(&values[i], &pf).is_ok()); }) } #[test] fn test_bytes_path((t, values) in arb_tree(30)) { values.iter().enumerate().for_each(|(i, _v)| { - let pf = t.get_path(i); + let pf = t.compute_merkle_tree_path(i); let bytes = pf.to_bytes(); let deserialised = MerklePath::from_bytes(&bytes).unwrap(); - assert!(t.to_commitment().check(&values[i], &deserialised).is_ok()); + assert!(t.to_merkle_tree_commitment().verify_leaf_membership_from_path(&values[i], &deserialised).is_ok()); let encoded = bincode::serde::encode_to_vec(&pf, bincode::config::legacy()).unwrap(); let (decoded,_) = bincode::serde::decode_from_slice::>,_>(&encoded, bincode::config::legacy()).unwrap(); - assert!(t.to_commitment().check(&values[i], &decoded).is_ok()); + assert!(t.to_merkle_tree_commitment().verify_leaf_membership_from_path(&values[i], &decoded).is_ok()); }) } #[test] fn test_bytes_tree_commitment((t, values) in arb_tree(5)) { - let encoded = bincode::serde::encode_to_vec(t.to_commitment(), bincode::config::legacy()).unwrap(); + let encoded = bincode::serde::encode_to_vec(t.to_merkle_tree_commitment(), bincode::config::legacy()).unwrap(); let (decoded,_) = bincode::serde::decode_from_slice::>,_>(&encoded, bincode::config::legacy()).unwrap(); - let tree_commitment = MerkleTree::>::create(&values).to_commitment(); + let tree_commitment = MerkleTree::>::new(&values).to_merkle_tree_commitment(); assert_eq!(tree_commitment.root, decoded.root); } @@ -278,7 +327,7 @@ mod tests { fn test_bytes_tree((t, values) in arb_tree(5)) { let bytes = t.to_bytes(); let deserialised = MerkleTree::>::from_bytes(&bytes).unwrap(); - let tree = MerkleTree::>::create(&values); + let tree = MerkleTree::>::new(&values); assert_eq!(tree.nodes, deserialised.nodes); let encoded = bincode::serde::encode_to_vec(&t, bincode::config::legacy()).unwrap(); @@ -288,11 +337,11 @@ mod tests { #[test] fn test_bytes_tree_commitment_batch_compat((t, values) in arb_tree(5)) { - let encoded = bincode::serde::encode_to_vec(t.to_commitment_batch_compat(), bincode::config::legacy()).unwrap(); + let encoded = bincode::serde::encode_to_vec(t.to_merkle_tree_batch_commitment(), bincode::config::legacy()).unwrap(); let (decoded,_) = bincode::serde::decode_from_slice::>,_>(&encoded, bincode::config::legacy()).unwrap(); - let tree_commitment = MerkleTree::>::create(&values).to_commitment_batch_compat(); + let tree_commitment = MerkleTree::>::new(&values).to_merkle_tree_batch_commitment(); assert_eq!(tree_commitment.root, decoded.root); - assert_eq!(tree_commitment.get_nr_leaves(), decoded.get_nr_leaves()); + assert_eq!(tree_commitment.get_number_of_leaves(), decoded.get_number_of_leaves()); } @@ -316,11 +365,11 @@ mod tests { i in any::(), (values, proof) in values_with_invalid_proof(10) ) { - let t = MerkleTree::>::create(&values[1..]); + let t = MerkleTree::>::new(&values[1..]); let index = i % (values.len() - 1); let path_values = proof. iter().map(|x| Blake2b::::digest(x).to_vec()).collect(); let path = MerklePath::new(path_values, index); - assert!(t.to_commitment().check(&values[0], &path).is_err()); + assert!(t.to_merkle_tree_commitment().verify_leaf_membership_from_path(&values[0], &path).is_err()); } #[test] @@ -328,7 +377,7 @@ mod tests { i in any::(), (values, proof) in values_with_invalid_proof(10) ) { - let t = MerkleTree::>::create(&values[1..]); + let t = MerkleTree::>::new(&values[1..]); let indices = vec![i % (values.len() - 1); values.len() / 2]; let batch_values = vec![values[i % (values.len() - 1)]; values.len() / 2]; let path = MerkleBatchPath{values: proof @@ -338,7 +387,7 @@ mod tests { indices, hasher: PhantomData::> }; - assert!(t.to_commitment_batch_compat().check(&batch_values, &path).is_err()); + assert!(t.to_merkle_tree_batch_commitment().verify_leaves_membership_from_batch_path(&batch_values, &path).is_err()); } } @@ -359,7 +408,7 @@ mod tests { batch_values.push(leaves[*i]); } - (MerkleTree::>::create(&leaves), batch_values, mt_list) + (MerkleTree::>::new(&leaves), batch_values, mt_list) } } @@ -367,21 +416,21 @@ mod tests { #![proptest_config(ProptestConfig::with_cases(100))] #[test] fn test_create_batch_proof((t, batch_values, indices) in arb_tree_arb_batch(30)) { - let batch_proof = t.get_batched_path(indices); - assert!(t.to_commitment_batch_compat().check(&batch_values, &batch_proof).is_ok()); + let batch_proof = t.compute_merkle_tree_batch_path(indices); + assert!(t.to_merkle_tree_batch_commitment().verify_leaves_membership_from_batch_path(&batch_values, &batch_proof).is_ok()); } #[test] fn test_bytes_batch_path((t, batch_values, indices) in arb_tree_arb_batch(30)) { - let bp = t.get_batched_path(indices); + let bp = t.compute_merkle_tree_batch_path(indices); let bytes = &bp.to_bytes(); let deserialized = MerkleBatchPath::from_bytes(bytes).unwrap(); - assert!(t.to_commitment_batch_compat().check(&batch_values, &deserialized).is_ok()); + assert!(t.to_merkle_tree_batch_commitment().verify_leaves_membership_from_batch_path(&batch_values, &deserialized).is_ok()); let encoded = bincode::serde::encode_to_vec(&bp, bincode::config::legacy()).unwrap(); let (decoded,_) = bincode::serde::decode_from_slice::>,_>(&encoded, bincode::config::legacy()).unwrap(); - assert!(t.to_commitment_batch_compat().check(&batch_values, &decoded).is_ok()); + assert!(t.to_merkle_tree_batch_commitment().verify_leaves_membership_from_batch_path(&batch_values, &decoded).is_ok()); } } } diff --git a/mithril-stm/src/participant/initializer.rs b/mithril-stm/src/participant/initializer.rs index 324890b8b16..1292226bf5e 100644 --- a/mithril-stm/src/participant/initializer.rs +++ b/mithril-stm/src/participant/initializer.rs @@ -28,7 +28,7 @@ pub struct Initializer { impl Initializer { /// Builds an `Initializer` that is ready to register with the key registration service. /// This function generates the signing and verification key with a PoP, and initialises the structure. - pub fn setup(params: Parameters, stake: Stake, rng: &mut R) -> Self { + pub fn new(params: Parameters, stake: Stake, rng: &mut R) -> Self { let sk = BlsSigningKey::generate(rng); let pk = VerificationKeyProofOfPossession::from(&sk); Self { @@ -39,9 +39,25 @@ impl Initializer { } } + /// Builds an `Initializer` that is ready to register with the key registration service. + /// This function generates the signing and verification key with a PoP, and initialises the structure. + #[deprecated(since = "0.4.9", note = "Use `new` instead")] + pub fn setup(params: Parameters, stake: Stake, rng: &mut R) -> Self { + Self::new(params, stake, rng) + } + + /// Extract the verification key with proof of possession. + pub fn get_verification_key_proof_of_possession(&self) -> VerificationKeyProofOfPossession { + self.pk + } + /// Extract the verification key. + #[deprecated( + since = "0.4.9", + note = "Use `get_verification_key_proof_of_possession` instead" + )] pub fn verification_key(&self) -> VerificationKeyProofOfPossession { - self.pk + Self::get_verification_key_proof_of_possession(self) } /// Build the `avk` for the given list of parties. @@ -56,7 +72,7 @@ impl Initializer { /// * the current total stake (according to the registration service) /// # Error /// This function fails if the initializer is not registered. - pub fn new_signer( + pub fn create_signer( self, closed_reg: ClosedKeyRegistration, ) -> Result, RegisterError> { @@ -71,7 +87,7 @@ impl Initializer { return Err(RegisterError::UnregisteredInitializer); } - Ok(Signer::set_stm_signer( + Ok(Signer::set_signer( my_index.unwrap(), self.stake, self.params, @@ -81,11 +97,31 @@ impl Initializer { )) } - /// Creates a new core signer that does not include closed registration. + /// Build the `avk` for the given list of parties. + /// + /// Note that if this Initializer was modified *between* the last call to `register`, + /// then the resulting `Signer` may not be able to produce valid signatures. + /// + /// Returns an `Signer` specialized to + /// * this `Signer`'s ID and current stake + /// * this `Signer`'s parameter valuation + /// * the `avk` as built from the current registered parties (according to the registration service) + /// * the current total stake (according to the registration service) + /// # Error + /// This function fails if the initializer is not registered. + #[deprecated(since = "0.4.9", note = "Use `create_signer` instead")] + pub fn new_signer( + self, + closed_reg: ClosedKeyRegistration, + ) -> Result, RegisterError> { + Self::create_signer(self, closed_reg) + } + + /// Creates a new basic signer that does not include closed registration. /// Takes `eligible_parties` as a parameter and determines the signer's index in the parties. /// `eligible_parties` is verified and trusted which is only run by a full-node /// that has already verified the parties. - pub fn new_core_signer( + pub fn create_basic_signer( self, eligible_parties: &[RegisteredParty], ) -> Option> { @@ -99,7 +135,7 @@ impl Initializer { } } if let Some(index) = my_index { - Some(Signer::set_core_signer( + Some(Signer::set_basic_signer( index, self.stake, self.params, @@ -111,6 +147,18 @@ impl Initializer { } } + /// Creates a new basic signer that does not include closed registration. + /// Takes `eligible_parties` as a parameter and determines the signer's index in the parties. + /// `eligible_parties` is verified and trusted which is only run by a full-node + /// that has already verified the parties. + #[deprecated(since = "0.4.9", note = "Use `create_basic_signer` instead")] + pub fn new_core_signer( + self, + eligible_parties: &[RegisteredParty], + ) -> Option> { + Self::create_basic_signer(self, eligible_parties) + } + /// Convert to bytes /// # Layout /// * Stake (u64) diff --git a/mithril-stm/src/participant/signer.rs b/mithril-stm/src/participant/signer.rs index 648fa8cf901..68324970e42 100644 --- a/mithril-stm/src/participant/signer.rs +++ b/mithril-stm/src/participant/signer.rs @@ -1,7 +1,7 @@ use blake2::digest::{Digest, FixedOutput}; use crate::bls_multi_signature::{BlsSignature, BlsSigningKey, BlsVerificationKey}; -use crate::eligibility_check::ev_lt_phi; +use crate::eligibility_check::is_lottery_won; use crate::key_registration::ClosedKeyRegistration; use crate::{Parameters, SingleSignature, Stake}; @@ -27,7 +27,7 @@ pub struct Signer { impl Signer { /// Create a Signer for given input - pub fn set_stm_signer( + pub(crate) fn set_signer( signer_index: u64, stake: Stake, params: Parameters, @@ -45,8 +45,21 @@ impl Signer { } } - /// Create a core signer (no registration data) for given input - pub fn set_core_signer( + /// Create a Signer for given input + #[deprecated(since = "0.4.9", note = "Use `set_signer` instead")] + pub fn set_stm_signer( + signer_index: u64, + stake: Stake, + params: Parameters, + sk: BlsSigningKey, + vk: VerificationKey, + closed_reg: ClosedKeyRegistration, + ) -> Signer { + Self::set_signer(signer_index, stake, params, sk, vk, closed_reg) + } + + /// Create a basic signer (no registration data) for given input + pub(crate) fn set_basic_signer( signer_index: u64, stake: Stake, params: Parameters, @@ -63,6 +76,18 @@ impl Signer { } } + /// Create a core signer (no registration data) for given input + #[deprecated(since = "0.4.9", note = "Use `set_basic_signer` instead")] + pub fn set_core_signer( + signer_index: u64, + stake: Stake, + params: Parameters, + sk: BlsSigningKey, + vk: VerificationKey, + ) -> Signer { + Self::set_basic_signer(signer_index, stake, params, sk, vk) + } + /// This function produces a signature following the description of Section 2.4. /// Once the signature is produced, this function checks whether any index in `[0,..,self.params.m]` /// wins the lottery by evaluating the dense mapping. @@ -73,9 +98,9 @@ impl Signer { let closed_reg = self.closed_reg.as_ref().expect("Closed registration not found! Cannot produce SingleSignatures. Use core_sign to produce core signatures (not valid for an StmCertificate)."); let msgp = closed_reg .merkle_tree - .to_commitment_batch_compat() - .concat_with_msg(msg); - let signature = self.core_sign(&msgp, closed_reg.total_stake)?; + .to_merkle_tree_batch_commitment() + .concatenate_with_message(msg); + let signature = self.basic_sign(&msgp, closed_reg.total_stake)?; Some(SingleSignature { sigma: signature.sigma, @@ -85,21 +110,27 @@ impl Signer { } /// Extract the verification key. - pub fn verification_key(&self) -> VerificationKey { + pub fn get_verification_key(&self) -> VerificationKey { self.vk } + /// Extract the verification key. + #[deprecated(since = "0.4.9", note = "Use `get_verification_key` instead")] + pub fn verification_key(&self) -> VerificationKey { + Self::get_verification_key(self) + } + /// Extract stake from the signer. pub fn get_stake(&self) -> Stake { self.stake } - /// A core signature generated without closed registration. - /// The core signature can be verified by core verifier. + /// A basic signature generated without closed key registration. + /// The basic signature can be verified by basic verifier. /// Once the signature is produced, this function checks whether any index in `[0,..,self.params.m]` /// wins the lottery by evaluating the dense mapping. /// It records all the winning indexes in `Self.indexes`. - pub fn core_sign(&self, msg: &[u8], total_stake: Stake) -> Option { + pub fn basic_sign(&self, msg: &[u8], total_stake: Stake) -> Option { let sigma = self.sk.sign(msg); let indexes = self.check_lottery(msg, &sigma, total_stake); @@ -114,13 +145,23 @@ impl Signer { } } + /// A basic signature generated without closed key registration. + /// The basic signature can be verified by basic verifier. + /// Once the signature is produced, this function checks whether any index in `[0,..,self.params.m]` + /// wins the lottery by evaluating the dense mapping. + /// It records all the winning indexes in `Self.indexes`. + #[deprecated(since = "0.4.9", note = "Use `basic_sign` instead")] + pub fn core_sign(&self, msg: &[u8], total_stake: Stake) -> Option { + Self::basic_sign(self, msg, total_stake) + } + /// Collects and returns the winning indices. pub fn check_lottery(&self, msg: &[u8], sigma: &BlsSignature, total_stake: Stake) -> Vec { let mut indexes = Vec::new(); for index in 0..self.params.m { - if ev_lt_phi( + if is_lottery_won( self.params.phi_f, - sigma.eval(msg, index), + sigma.evaluate_dense_mapping(msg, index), self.stake, total_stake, ) { @@ -131,17 +172,24 @@ impl Signer { } /// Get Parameters - pub fn get_params(&self) -> Parameters { + pub(crate) fn get_parameters(&self) -> Parameters { self.params } + /// Get Parameters + #[deprecated(since = "0.4.9", note = "Use `get_parameters` instead")] + pub fn get_params(&self) -> Parameters { + Self::get_parameters(self) + } + /// Get closed key registration - pub fn get_closed_reg(&self) -> Option> { + pub(crate) fn get_closed_key_registration(&self) -> Option> { self.closed_reg.clone() } - /// Get verification key - pub fn get_vk(&self) -> VerificationKey { - self.vk + /// Get closed key registration + #[deprecated(since = "0.4.9", note = "Use `get_closed_key_registration` instead")] + pub fn get_closed_reg(&self) -> Option> { + Self::get_closed_key_registration(self) } } diff --git a/mithril-stm/src/single_signature/signature.rs b/mithril-stm/src/single_signature/signature.rs index cff93ece8a8..1fcf0d3a46b 100644 --- a/mithril-stm/src/single_signature/signature.rs +++ b/mithril-stm/src/single_signature/signature.rs @@ -7,7 +7,7 @@ use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; use crate::bls_multi_signature::BlsSignature; -use crate::eligibility_check::ev_lt_phi; +use crate::eligibility_check::is_lottery_won; use crate::{ AggregateVerificationKey, Index, Parameters, Stake, StmSignatureError, VerificationKey, }; @@ -34,8 +34,8 @@ impl SingleSignature { avk: &AggregateVerificationKey, msg: &[u8], ) -> Result<(), StmSignatureError> { - let msgp = avk.get_mt_commitment().concat_with_msg(msg); - self.verify_core(params, pk, stake, &msgp, &avk.get_total_stake())?; + let msgp = avk.get_merkle_tree_batch_commitment().concatenate_with_message(msg); + self.basic_verify(params, pk, stake, &msgp, &avk.get_total_stake())?; Ok(()) } @@ -52,9 +52,9 @@ impl SingleSignature { return Err(StmSignatureError::IndexBoundFailed(index, params.m)); } - let ev = self.sigma.eval(msg, index); + let ev = self.sigma.evaluate_dense_mapping(msg, index); - if !ev_lt_phi(params.phi_f, ev, *stake, *total_stake) { + if !is_lottery_won(params.phi_f, ev, *stake, *total_stake) { return Err(StmSignatureError::LotteryLost); } } @@ -126,13 +126,19 @@ impl SingleSignature { } /// Compare two `SingleSignature` by their signers' merkle tree indexes. - pub fn cmp_stm_sig(&self, other: &Self) -> Ordering { + fn compare_signer_index(&self, other: &Self) -> Ordering { self.signer_index.cmp(&other.signer_index) } - /// Verify a core signature by checking that the lottery was won, + /// Compare two `SingleSignature` by their signers' merkle tree indexes. + #[deprecated(since = "0.4.9", note = "This function will be removed")] + pub fn cmp_stm_sig(&self, other: &Self) -> Ordering { + Self::compare_signer_index(self, other) + } + + /// Verify a basic signature by checking that the lottery was won, /// the indexes are in the desired range and the underlying multi signature validates. - pub fn verify_core( + pub(crate) fn basic_verify( &self, params: &Parameters, pk: &VerificationKey, @@ -145,6 +151,19 @@ impl SingleSignature { Ok(()) } + + /// Will be deprecated. Use `basic_verify` instead. + #[deprecated(since = "0.4.9", note = "Use `basic_verify` instead")] + pub fn core_verify( + &self, + params: &Parameters, + pk: &VerificationKey, + stake: &Stake, + msg: &[u8], + total_stake: &Stake, + ) -> Result<(), StmSignatureError> { + Self::basic_verify(self, params, pk, stake, msg, total_stake) + } } impl Hash for SingleSignature { @@ -169,6 +188,6 @@ impl PartialOrd for SingleSignature { impl Ord for SingleSignature { fn cmp(&self, other: &Self) -> Ordering { - self.cmp_stm_sig(other) + self.signer_index.cmp(&other.signer_index) } } diff --git a/mithril-stm/tests/stm_core.rs b/mithril-stm/tests/stm_basic.rs similarity index 80% rename from mithril-stm/tests/stm_core.rs rename to mithril-stm/tests/stm_basic.rs index 594a9cc90d3..8cc4ff71ac2 100644 --- a/mithril-stm/tests/stm_core.rs +++ b/mithril-stm/tests/stm_basic.rs @@ -30,16 +30,19 @@ fn test_core_verifier() { let parties = (0..nparties).map(|_| 1 + (rng.next_u64() % 9999)).collect::>(); for stake in parties { - let initializer = Initializer::setup(params, stake, &mut rng); + let initializer = Initializer::new(params, stake, &mut rng); initializers.push(initializer.clone()); - public_signers.push((initializer.verification_key().vk, initializer.stake)); + public_signers.push(( + initializer.get_verification_key_proof_of_possession().vk, + initializer.stake, + )); } - let core_verifier = BasicVerifier::setup(&public_signers); + let core_verifier = BasicVerifier::new(&public_signers); let signers: Vec> = initializers .into_iter() - .filter_map(|s| s.new_core_signer(&core_verifier.eligible_parties)) + .filter_map(|s| s.create_basic_signer(&core_verifier.eligible_parties)) .collect(); ////////////////////////// @@ -48,7 +51,7 @@ fn test_core_verifier() { let mut signatures: Vec = Vec::with_capacity(nparties); for s in signers { - if let Some(sig) = s.core_sign(&msg, core_verifier.total_stake) { + if let Some(sig) = s.basic_sign(&msg, core_verifier.total_stake) { signatures.push(sig); } } diff --git a/mithril-stm/tests/test_extensions/protocol_phase.rs b/mithril-stm/tests/test_extensions/protocol_phase.rs index 5eb996aedb9..35be24d92e0 100644 --- a/mithril-stm/tests/test_extensions/protocol_phase.rs +++ b/mithril-stm/tests/test_extensions/protocol_phase.rs @@ -37,9 +37,11 @@ pub fn initialization_phase( let mut reg_parties: Vec<(VerificationKey, Stake)> = Vec::with_capacity(nparties); for stake in parties { - let p = Initializer::setup(params, stake, &mut rng); - key_reg.register(stake, p.verification_key()).unwrap(); - reg_parties.push((p.verification_key().vk, stake)); + let p = Initializer::new(params, stake, &mut rng); + key_reg + .register(stake, p.get_verification_key_proof_of_possession()) + .unwrap(); + reg_parties.push((p.get_verification_key_proof_of_possession().vk, stake)); initializers.push(p); } @@ -48,7 +50,7 @@ pub fn initialization_phase( let signers = initializers .clone() .into_par_iter() - .map(|p| p.new_signer(closed_reg.clone()).unwrap()) + .map(|p| p.create_signer(closed_reg.clone()).unwrap()) .collect::>>(); InitializationPhaseResult { @@ -69,8 +71,8 @@ pub fn operation_phase( .filter_map(|p| p.sign(&msg)) .collect::>(); - let clerk = Clerk::from_signer(&signers[0]); - let avk = clerk.compute_avk(); + let clerk = Clerk::new_clerk_from_signer(&signers[0]); + let avk = clerk.compute_aggregate_verification_key(); // Check all parties can verify every sig for (s, (vk, stake)) in sigs.iter().zip(reg_parties.iter()) { @@ -80,7 +82,7 @@ pub fn operation_phase( ); } - let msig = clerk.aggregate(&sigs, &msg); + let msig = clerk.aggregate_signatures(&sigs, &msg); OperationPhaseResult { msig, avk, sigs } }