From a4350cf414909afa16f4982bdd5df31351fad32c Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Mon, 21 Aug 2023 10:22:13 +0530 Subject: [PATCH 01/19] happy path test works --- src/auxinfo/proof.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++ src/protocol.rs | 15 ++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index e5eb2f04..2c5120b9 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -142,3 +142,52 @@ impl AuxInfoProof { Ok(()) } } + +#[cfg(test)] +mod tests { + use crate::{ + paillier::prime_gen, + protocol::SharedContext, + utils::{k256_order, testing::init_testing, CurvePoint}, + ParticipantIdentifier, + }; + use rand::random; + + use super::*; + + pub(crate) fn generate_shared_context() -> SharedContext { + let mut rng = init_testing(); + let sid = Identifier::random(&mut rng); + let participant = ParticipantIdentifier::random(&mut rng); + let participant2 = ParticipantIdentifier::random(&mut rng); + let participants = vec![participant, participant2]; + let generator = CurvePoint::GENERATOR; + let order = k256_order(); + SharedContext::gen_shared_context(sid, participants, generator, order) + } + + #[test] + fn auxinfo_proof_verifies() -> Result<()> { + let mut rng = init_testing(); + let sid = Identifier::random(&mut rng); + let rho = random(); + let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; + let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); + let modulus = &p * &q; + let shared_context = &generate_shared_context(); + let proof = AuxInfoProof::prove( + &mut rng, + shared_context, + sid, + rho, + &setup_params, + &modulus, + &p, + &q, + )?; + assert!(proof + .verify(shared_context, sid, rho, &setup_params, &modulus) + .is_ok()); + Ok(()) + } +} diff --git a/src/protocol.rs b/src/protocol.rs index 54243f3e..b057493f 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -511,6 +511,21 @@ impl ProofContext for SharedContext { } impl SharedContext { + #[cfg(test)] + pub fn gen_shared_context( + sid: Identifier, + participants: Vec, + generator: CurvePoint, + order: BigNumber, + ) -> Self { + SharedContext { + sid, + participants, + generator, + order, + } + } + pub(crate) fn collect(p: &P) -> Self { let mut participants = p.all_participants(); participants.sort(); From 1a6cf8c5a97ff4a367cfd622fb228480bbce4d4b Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Mon, 21 Aug 2023 19:10:01 +0530 Subject: [PATCH 02/19] sap pimod pifac proof test works --- src/auxinfo/proof.rs | 81 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index 2c5120b9..b549a550 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -190,4 +190,85 @@ mod tests { .is_ok()); Ok(()) } + + #[test] + fn each_constituent_proof_must_be_valid() -> Result<()> { + let mut rng = init_testing(); + let sid = Identifier::random(&mut rng); + let rho = random(); + let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; + let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); + let modulus = &p * &q; + let shared_context = &generate_shared_context(); + let mut transcript = AuxInfoProof::new_transcript(); + AuxInfoProof::append_pimod_transcript(&mut transcript, shared_context, sid, rho)?; + let pimod = pimod::PiModProof::prove( + &pimod::CommonInput::new(&modulus), + &pimod::ProverSecret::new(&p, &q), + shared_context, + &mut transcript, + &mut rng, + )?; + AuxInfoProof::append_pifac_transcript(&mut transcript, shared_context, sid, rho)?; + let pifac = pifac::PiFacProof::prove( + pifac::CommonInput::new(&setup_params, &modulus), + pifac::ProverSecret::new(&p, &q), + shared_context, + &mut transcript, + &mut rng, + )?; + let proof = AuxInfoProof { + pimod: pimod.clone(), + pifac: pifac.clone(), + }; + assert!(proof + .verify(shared_context, sid, rho, &setup_params, &modulus) + .is_ok()); + let mut rng1 = init_testing(); + let sid1 = Identifier::random(&mut rng1); + let rho1: [u8; 32] = random(); + let setup_params1 = VerifiedRingPedersen::gen(&mut rng1, &())?; + let (p1, q1) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng1).unwrap(); + let modulus1 = &p1 * &q1; + let shared_context1 = &generate_shared_context(); + let mut transcript1 = AuxInfoProof::new_transcript(); + AuxInfoProof::append_pimod_transcript(&mut transcript1, shared_context1, sid1, rho1)?; + let pimod1 = pimod::PiModProof::prove( + &pimod::CommonInput::new(&modulus1), + &pimod::ProverSecret::new(&p1, &q1), + shared_context1, + &mut transcript1, + &mut rng1, + )?; + AuxInfoProof::append_pifac_transcript(&mut transcript1, shared_context1, sid1, rho1)?; + let pifac1 = pifac::PiFacProof::prove( + pifac::CommonInput::new(&setup_params1, &modulus1), + pifac::ProverSecret::new(&p1, &q1), + shared_context1, + &mut transcript1, + &mut rng1, + )?; + let proof1 = AuxInfoProof { + pimod: pimod1.clone(), + pifac: pifac1.clone(), + }; + assert!(proof1 + .verify(shared_context1, sid1, rho1, &setup_params1, &modulus1) + .is_ok()); + let proof2 = AuxInfoProof { + pimod, + pifac: pifac1, + }; + assert!(proof2 + .verify(shared_context1, sid1, rho1, &setup_params1, &modulus1) + .is_err()); + let proof3 = AuxInfoProof { + pimod: pimod1, + pifac, + }; + assert!(proof3 + .verify(shared_context1, sid1, rho1, &setup_params1, &modulus1) + .is_err()); + Ok(()) + } } From d037e0968f96b908487772e5b5fe52469adc4325 Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Mon, 21 Aug 2023 19:21:06 +0530 Subject: [PATCH 03/19] individual proofs must be correct test works --- src/auxinfo/proof.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index b549a550..dc3e2c64 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -271,4 +271,64 @@ mod tests { .is_err()); Ok(()) } + + #[test] + fn pimod_pifac_proofs_must_be_correct_individually() -> Result<()> { + let mut rng = init_testing(); + let sid = Identifier::random(&mut rng); + let rho = random(); + let bad_rho: [u8; 32] = random(); + let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; + let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); + let modulus = &p * &q; + let shared_context = &generate_shared_context(); + let mut transcript = AuxInfoProof::new_transcript(); + AuxInfoProof::append_pimod_transcript(&mut transcript, shared_context, sid, bad_rho)?; + let bad_pimod = pimod::PiModProof::prove( + &pimod::CommonInput::new(&modulus), + &pimod::ProverSecret::new(&p, &q), + shared_context, + &mut transcript, + &mut rng, + )?; + AuxInfoProof::append_pifac_transcript(&mut transcript, shared_context, sid, rho)?; + let pifac = pifac::PiFacProof::prove( + pifac::CommonInput::new(&setup_params, &modulus), + pifac::ProverSecret::new(&p, &q), + shared_context, + &mut transcript, + &mut rng, + )?; + let proof = AuxInfoProof { + pimod: bad_pimod.clone(), + pifac: pifac.clone(), + }; + assert!(proof + .verify(shared_context, sid, rho, &setup_params, &modulus) + .is_err()); + AuxInfoProof::append_pimod_transcript(&mut transcript, shared_context, sid, rho)?; + let pimod = pimod::PiModProof::prove( + &pimod::CommonInput::new(&modulus), + &pimod::ProverSecret::new(&p, &q), + shared_context, + &mut transcript, + &mut rng, + )?; + AuxInfoProof::append_pifac_transcript(&mut transcript, shared_context, sid, bad_rho)?; + let bad_pifac = pifac::PiFacProof::prove( + pifac::CommonInput::new(&setup_params, &modulus), + pifac::ProverSecret::new(&p, &q), + shared_context, + &mut transcript, + &mut rng, + )?; + let proof = AuxInfoProof { + pimod: pimod.clone(), + pifac: bad_pifac.clone(), + }; + assert!(proof + .verify(shared_context, sid, rho, &setup_params, &modulus) + .is_err()); + Ok(()) + } } From 271f86d393694c7139e7f16980ce13c928a9d957 Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Tue, 22 Aug 2023 10:15:44 +0530 Subject: [PATCH 04/19] comments addressed --- src/auxinfo/proof.rs | 48 ++++++++++++++------------------------------ src/protocol.rs | 15 ++++++++------ 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index dc3e2c64..644ae9b0 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -145,26 +145,9 @@ impl AuxInfoProof { #[cfg(test)] mod tests { - use crate::{ - paillier::prime_gen, - protocol::SharedContext, - utils::{k256_order, testing::init_testing, CurvePoint}, - ParticipantIdentifier, - }; - use rand::random; - use super::*; - - pub(crate) fn generate_shared_context() -> SharedContext { - let mut rng = init_testing(); - let sid = Identifier::random(&mut rng); - let participant = ParticipantIdentifier::random(&mut rng); - let participant2 = ParticipantIdentifier::random(&mut rng); - let participants = vec![participant, participant2]; - let generator = CurvePoint::GENERATOR; - let order = k256_order(); - SharedContext::gen_shared_context(sid, participants, generator, order) - } + use crate::{paillier::prime_gen, protocol::SharedContext, utils::testing::init_testing}; + use rand::{random, Rng}; #[test] fn auxinfo_proof_verifies() -> Result<()> { @@ -174,10 +157,10 @@ mod tests { let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus = &p * &q; - let shared_context = &generate_shared_context(); + let shared_context = SharedContext::random(&mut rng); let proof = AuxInfoProof::prove( &mut rng, - shared_context, + &shared_context, sid, rho, &setup_params, @@ -186,7 +169,7 @@ mod tests { &q, )?; assert!(proof - .verify(shared_context, sid, rho, &setup_params, &modulus) + .verify(&shared_context, sid, rho, &setup_params, &modulus) .is_ok()); Ok(()) } @@ -195,11 +178,11 @@ mod tests { fn each_constituent_proof_must_be_valid() -> Result<()> { let mut rng = init_testing(); let sid = Identifier::random(&mut rng); - let rho = random(); + let rho = rng.gen(); let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus = &p * &q; - let shared_context = &generate_shared_context(); + let shared_context = &SharedContext::random(&mut rng); let mut transcript = AuxInfoProof::new_transcript(); AuxInfoProof::append_pimod_transcript(&mut transcript, shared_context, sid, rho)?; let pimod = pimod::PiModProof::prove( @@ -224,13 +207,12 @@ mod tests { assert!(proof .verify(shared_context, sid, rho, &setup_params, &modulus) .is_ok()); - let mut rng1 = init_testing(); - let sid1 = Identifier::random(&mut rng1); - let rho1: [u8; 32] = random(); - let setup_params1 = VerifiedRingPedersen::gen(&mut rng1, &())?; - let (p1, q1) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng1).unwrap(); + let sid1 = Identifier::random(&mut rng); + let rho1: [u8; 32] = rng.gen(); + let setup_params1 = VerifiedRingPedersen::gen(&mut rng, &())?; + let (p1, q1) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus1 = &p1 * &q1; - let shared_context1 = &generate_shared_context(); + let shared_context1 = &SharedContext::random(&mut rng); let mut transcript1 = AuxInfoProof::new_transcript(); AuxInfoProof::append_pimod_transcript(&mut transcript1, shared_context1, sid1, rho1)?; let pimod1 = pimod::PiModProof::prove( @@ -238,7 +220,7 @@ mod tests { &pimod::ProverSecret::new(&p1, &q1), shared_context1, &mut transcript1, - &mut rng1, + &mut rng, )?; AuxInfoProof::append_pifac_transcript(&mut transcript1, shared_context1, sid1, rho1)?; let pifac1 = pifac::PiFacProof::prove( @@ -246,7 +228,7 @@ mod tests { pifac::ProverSecret::new(&p1, &q1), shared_context1, &mut transcript1, - &mut rng1, + &mut rng, )?; let proof1 = AuxInfoProof { pimod: pimod1.clone(), @@ -281,7 +263,7 @@ mod tests { let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus = &p * &q; - let shared_context = &generate_shared_context(); + let shared_context = &SharedContext::random(&mut rng); let mut transcript = AuxInfoProof::new_transcript(); AuxInfoProof::append_pimod_transcript(&mut transcript, shared_context, sid, bad_rho)?; let bad_pimod = pimod::PiModProof::prove( diff --git a/src/protocol.rs b/src/protocol.rs index b057493f..4bf4bc0b 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -510,14 +510,17 @@ impl ProofContext for SharedContext { } } +use rand::rngs::StdRng; impl SharedContext { + /// This function should not be used outside of the tests. #[cfg(test)] - pub fn gen_shared_context( - sid: Identifier, - participants: Vec, - generator: CurvePoint, - order: BigNumber, - ) -> Self { + pub fn random(rng: &mut StdRng) -> Self { + let sid = Identifier::random(rng); + let participant = ParticipantIdentifier::random(rng); + let participant2 = ParticipantIdentifier::random(rng); + let participants = vec![participant, participant2]; + let generator = CurvePoint::GENERATOR; + let order = k256_order(); SharedContext { sid, participants, From ed9a382e6fd72f8a8be7f60e192e94a7fab49c88 Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Tue, 22 Aug 2023 16:40:43 +0530 Subject: [PATCH 05/19] functions squashed --- src/protocol.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/protocol.rs b/src/protocol.rs index 4bf4bc0b..6150d955 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -510,11 +510,10 @@ impl ProofContext for SharedContext { } } -use rand::rngs::StdRng; impl SharedContext { /// This function should not be used outside of the tests. #[cfg(test)] - pub fn random(rng: &mut StdRng) -> Self { + pub fn random(rng: &mut rand::rngs::StdRng) -> Self { let sid = Identifier::random(rng); let participant = ParticipantIdentifier::random(rng); let participant2 = ParticipantIdentifier::random(rng); From f2071dd4eb2bc0579b2f4cae6fa8914bcf51c20d Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Tue, 22 Aug 2023 23:36:29 +0530 Subject: [PATCH 06/19] bad tests added --- src/auxinfo/proof.rs | 86 +++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 45 deletions(-) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index 644ae9b0..3552efd8 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -255,62 +255,58 @@ mod tests { } #[test] - fn pimod_pifac_proofs_must_be_correct_individually() -> Result<()> { + fn modulus_factors_must_be_correct() -> Result<()> { let mut rng = init_testing(); let sid = Identifier::random(&mut rng); let rho = random(); - let bad_rho: [u8; 32] = random(); let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); + let (p1, q1) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus = &p * &q; let shared_context = &SharedContext::random(&mut rng); - let mut transcript = AuxInfoProof::new_transcript(); - AuxInfoProof::append_pimod_transcript(&mut transcript, shared_context, sid, bad_rho)?; - let bad_pimod = pimod::PiModProof::prove( - &pimod::CommonInput::new(&modulus), - &pimod::ProverSecret::new(&p, &q), - shared_context, - &mut transcript, + match AuxInfoProof::prove( &mut rng, - )?; - AuxInfoProof::append_pifac_transcript(&mut transcript, shared_context, sid, rho)?; - let pifac = pifac::PiFacProof::prove( - pifac::CommonInput::new(&setup_params, &modulus), - pifac::ProverSecret::new(&p, &q), - shared_context, - &mut transcript, - &mut rng, - )?; - let proof = AuxInfoProof { - pimod: bad_pimod.clone(), - pifac: pifac.clone(), - }; - assert!(proof - .verify(shared_context, sid, rho, &setup_params, &modulus) - .is_err()); - AuxInfoProof::append_pimod_transcript(&mut transcript, shared_context, sid, rho)?; - let pimod = pimod::PiModProof::prove( - &pimod::CommonInput::new(&modulus), - &pimod::ProverSecret::new(&p, &q), shared_context, - &mut transcript, + sid, + rho, + &setup_params, + &modulus, + &p1, + &q1, + ) { + Ok(proof) => assert!(proof + .verify(shared_context, sid, rho, &setup_params, &modulus) + .is_err()), + Err(_) => return Ok(()), + } + Ok(()) + } + + #[test] + fn context_must_be_correct() -> Result<()> { + let mut rng = init_testing(); + let sid = Identifier::random(&mut rng); + let rho = random(); + let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; + let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); + let modulus = &p * &q; + let shared_context = &SharedContext::random(&mut rng); + let bad_shared_context = &SharedContext::random(&mut rng); + match AuxInfoProof::prove( &mut rng, - )?; - AuxInfoProof::append_pifac_transcript(&mut transcript, shared_context, sid, bad_rho)?; - let bad_pifac = pifac::PiFacProof::prove( - pifac::CommonInput::new(&setup_params, &modulus), - pifac::ProverSecret::new(&p, &q), shared_context, - &mut transcript, - &mut rng, - )?; - let proof = AuxInfoProof { - pimod: pimod.clone(), - pifac: bad_pifac.clone(), - }; - assert!(proof - .verify(shared_context, sid, rho, &setup_params, &modulus) - .is_err()); + sid, + rho, + &setup_params, + &modulus, + &p, + &q, + ) { + Ok(proof) => assert!(proof + .verify(bad_shared_context, sid, rho, &setup_params, &modulus) + .is_err()), + Err(_) => return Ok(()), + } Ok(()) } } From b9f0052349620c7e588727a480d884fcb0adc3f6 Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Tue, 29 Aug 2023 15:56:08 +0530 Subject: [PATCH 07/19] random auxinfo proof added --- src/auxinfo/proof.rs | 47 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index 3552efd8..8d43c63f 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -147,13 +147,33 @@ impl AuxInfoProof { mod tests { use super::*; use crate::{paillier::prime_gen, protocol::SharedContext, utils::testing::init_testing}; - use rand::{random, Rng}; + use rand::Rng; + + fn random_auxinfo_proof() -> Result { + let mut rng = init_testing(); + let sid = Identifier::random(&mut rng); + let rho = rng.gen(); + let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; + let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); + let modulus = &p * &q; + let shared_context = SharedContext::random(&mut rng); + AuxInfoProof::prove( + &mut rng, + &shared_context, + sid, + rho, + &setup_params, + &modulus, + &p, + &q, + ) + } #[test] fn auxinfo_proof_verifies() -> Result<()> { let mut rng = init_testing(); let sid = Identifier::random(&mut rng); - let rho = random(); + let rho = rng.gen(); let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus = &p * &q; @@ -244,11 +264,22 @@ mod tests { assert!(proof2 .verify(shared_context1, sid1, rho1, &setup_params1, &modulus1) .is_err()); - let proof3 = AuxInfoProof { - pimod: pimod1, - pifac, + let proof1: AuxInfoProof = random_auxinfo_proof()?; + let proof2: AuxInfoProof = random_auxinfo_proof()?; + + let mix_one = AuxInfoProof { + pifac: proof1.pifac, + pimod: proof2.pimod, }; - assert!(proof3 + + let mix_two = AuxInfoProof { + pifac: proof2.pifac, + pimod: proof1.pimod, + }; + assert!(mix_one + .verify(shared_context1, sid1, rho1, &setup_params1, &modulus1) + .is_err()); + assert!(mix_two .verify(shared_context1, sid1, rho1, &setup_params1, &modulus1) .is_err()); Ok(()) @@ -258,7 +289,7 @@ mod tests { fn modulus_factors_must_be_correct() -> Result<()> { let mut rng = init_testing(); let sid = Identifier::random(&mut rng); - let rho = random(); + let rho = rng.gen(); let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let (p1, q1) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); @@ -286,7 +317,7 @@ mod tests { fn context_must_be_correct() -> Result<()> { let mut rng = init_testing(); let sid = Identifier::random(&mut rng); - let rho = random(); + let rho = rng.gen(); let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus = &p * &q; From f74a90a6436933115694d777829623e875247c09 Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Fri, 8 Sep 2023 22:09:07 +0530 Subject: [PATCH 08/19] commoninput added --- src/auxinfo/proof.rs | 69 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 10 deletions(-) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index 8d43c63f..2b2156e0 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -12,7 +12,7 @@ use crate::{ messages::{AuxinfoMessageType, Message, MessageType}, participant::InnerProtocolParticipant, ring_pedersen::VerifiedRingPedersen, - Identifier, + Identifier, protocol::SharedContext, }; use crate::zkp::{pifac, pimod, Proof, ProofContext}; @@ -31,6 +31,34 @@ pub(crate) struct AuxInfoProof { pifac: pifac::PiFacProof, } +/// Common input and setup parameters known to both the prover and the verifier. +pub(crate) struct CommonInput<'a> { + shared_context: &'a SharedContext, + sid: Identifier, + rho: [u8; 32], + setup_parameters: &'a VerifiedRingPedersen, + modulus: &'a BigNumber, +} + +impl<'a> CommonInput<'a> { + /// Collect common parameters for proving or verifying a [`PiLogProof`] + pub(crate) fn new( + shared_context: &'a SharedContext, + sid: Identifier, + rho: [u8; 32], + setup_parameters: &'a VerifiedRingPedersen, + modulus: &'a BigNumber, + ) -> CommonInput<'a> { + Self { + shared_context, + sid, + rho, + setup_parameters, + modulus, + } + } +} + impl AuxInfoProof { /// Generate a fresh transcript to be used in [`AuxInfoProof`]. fn new_transcript() -> Transcript { @@ -91,7 +119,7 @@ impl AuxInfoProof { /// /// Note: The [`VerifiedRingPedersen`] argument **must be** provided by the /// verifier! - pub(crate) fn verify( + /*pub(crate) fn verify( self, context: &::Context, sid: Identifier, @@ -110,6 +138,23 @@ impl AuxInfoProof { &mut transcript, )?; Ok(()) + }*/ + + pub(crate) fn verify( + self, + common_input: CommonInput + ) -> Result<()> { + let mut transcript = Self::new_transcript(); + Self::append_pimod_transcript(&mut transcript, common_input.shared_context, common_input.sid, common_input.rho)?; + self.pimod + .verify(&pimod::CommonInput::new(common_input.modulus), common_input.shared_context, &mut transcript)?; + Self::append_pifac_transcript(&mut transcript, common_input.shared_context, common_input.sid, common_input.rho)?; + self.pifac.verify( + pifac::CommonInput::new(common_input.setup_parameters, common_input.modulus), + common_input.shared_context, + &mut transcript, + )?; + Ok(()) } /// Append info relevant to the `𝚷[mod]` proof to the provided @@ -188,8 +233,9 @@ mod tests { &p, &q, )?; + let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); assert!(proof - .verify(&shared_context, sid, rho, &setup_params, &modulus) + .verify(common_input) .is_ok()); Ok(()) } @@ -224,8 +270,9 @@ mod tests { pimod: pimod.clone(), pifac: pifac.clone(), }; + let common_input = CommonInput::new(shared_context, sid, rho, &setup_params, &modulus); assert!(proof - .verify(shared_context, sid, rho, &setup_params, &modulus) + .verify(common_input) .is_ok()); let sid1 = Identifier::random(&mut rng); let rho1: [u8; 32] = rng.gen(); @@ -255,14 +302,14 @@ mod tests { pifac: pifac1.clone(), }; assert!(proof1 - .verify(shared_context1, sid1, rho1, &setup_params1, &modulus1) + .verify(common_input) .is_ok()); let proof2 = AuxInfoProof { pimod, pifac: pifac1, }; assert!(proof2 - .verify(shared_context1, sid1, rho1, &setup_params1, &modulus1) + .verify(common_input) .is_err()); let proof1: AuxInfoProof = random_auxinfo_proof()?; let proof2: AuxInfoProof = random_auxinfo_proof()?; @@ -277,10 +324,10 @@ mod tests { pimod: proof1.pimod, }; assert!(mix_one - .verify(shared_context1, sid1, rho1, &setup_params1, &modulus1) + .verify(common_input) .is_err()); assert!(mix_two - .verify(shared_context1, sid1, rho1, &setup_params1, &modulus1) + .verify(common_input) .is_err()); Ok(()) } @@ -295,6 +342,7 @@ mod tests { let (p1, q1) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus = &p * &q; let shared_context = &SharedContext::random(&mut rng); + let common_input = CommonInput::new(shared_context, sid, rho, &setup_params, &modulus); match AuxInfoProof::prove( &mut rng, shared_context, @@ -306,7 +354,7 @@ mod tests { &q1, ) { Ok(proof) => assert!(proof - .verify(shared_context, sid, rho, &setup_params, &modulus) + .verify(common_input) .is_err()), Err(_) => return Ok(()), } @@ -323,6 +371,7 @@ mod tests { let modulus = &p * &q; let shared_context = &SharedContext::random(&mut rng); let bad_shared_context = &SharedContext::random(&mut rng); + let common_input = CommonInput{shared_context: bad_shared_context, sid, rho, setup_parameters: &setup_params, modulus: &modulus}; match AuxInfoProof::prove( &mut rng, shared_context, @@ -334,7 +383,7 @@ mod tests { &q, ) { Ok(proof) => assert!(proof - .verify(bad_shared_context, sid, rho, &setup_params, &modulus) + .verify(common_input) .is_err()), Err(_) => return Ok(()), } From a571957e35c7dd971277caec04d55c1f7a97915f Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Mon, 11 Sep 2023 16:21:11 +0530 Subject: [PATCH 09/19] verify function modified rebased --- src/auxinfo/participant.rs | 14 ++-- src/auxinfo/proof.rs | 129 +++++++++++-------------------------- 2 files changed, 46 insertions(+), 97 deletions(-) diff --git a/src/auxinfo/participant.rs b/src/auxinfo/participant.rs index c8aeba2c..4ba60832 100644 --- a/src/auxinfo/participant.rs +++ b/src/auxinfo/participant.rs @@ -13,7 +13,7 @@ use crate::{ auxinfo::{ auxinfo_commit::{Commitment, CommitmentScheme}, info::{AuxInfoPrivate, AuxInfoPublic, AuxInfoWitnesses}, - proof::AuxInfoProof, + proof::{AuxInfoProof, CommonInput}, Output, }, broadcast::participant::{BroadcastOutput, BroadcastParticipant, BroadcastTag}, @@ -552,15 +552,17 @@ impl AuxInfoParticipant { let my_public = self.local_storage.retrieve::(self.id)?; let proof = AuxInfoProof::from_message(message)?; - // Verify the public parameters for the given participant. Note that - // this verification verifies _both_ the `𝚷[mod]` and `𝚷[fac]` proofs. - proof.verify( - &self.retrieve_context(), + let shared_context = &self.retrieve_context(); + let common_input = CommonInput::new( + shared_context, message.id(), *global_rid, my_public.params(), auxinfo_pub.pk().modulus(), - )?; + ); + // Verify the public parameters for the given participant. Note that + // this verification verifies _both_ the `𝚷[mod]` and `𝚷[fac]` proofs. + proof.verify(&common_input)?; self.local_storage .store::(message.from(), auxinfo_pub); diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index 2b2156e0..4b429f61 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -11,8 +11,9 @@ use crate::{ errors::Result, messages::{AuxinfoMessageType, Message, MessageType}, participant::InnerProtocolParticipant, + protocol::SharedContext, ring_pedersen::VerifiedRingPedersen, - Identifier, protocol::SharedContext, + Identifier, }; use crate::zkp::{pifac, pimod, Proof, ProofContext}; @@ -32,23 +33,23 @@ pub(crate) struct AuxInfoProof { } /// Common input and setup parameters known to both the prover and the verifier. -pub(crate) struct CommonInput<'a> { +pub(crate) struct CommonInput<'a> { shared_context: &'a SharedContext, - sid: Identifier, + sid: Identifier, rho: [u8; 32], setup_parameters: &'a VerifiedRingPedersen, modulus: &'a BigNumber, } -impl<'a> CommonInput<'a> { - /// Collect common parameters for proving or verifying a [`PiLogProof`] +impl<'a> CommonInput<'a> { + /// Collect common parameters for proving or verifying a [`AuxInfoProof`] pub(crate) fn new( shared_context: &'a SharedContext, sid: Identifier, rho: [u8; 32], setup_parameters: &'a VerifiedRingPedersen, modulus: &'a BigNumber, - ) -> CommonInput<'a> { + ) -> CommonInput<'a> { Self { shared_context, sid, @@ -119,36 +120,25 @@ impl AuxInfoProof { /// /// Note: The [`VerifiedRingPedersen`] argument **must be** provided by the /// verifier! - /*pub(crate) fn verify( - self, - context: &::Context, - sid: Identifier, - rho: [u8; 32], - verifier_params: &VerifiedRingPedersen, - N: &BigNumber, - ) -> Result<()> { + pub(crate) fn verify(self, common_input: &CommonInput) -> Result<()> { let mut transcript = Self::new_transcript(); - Self::append_pimod_transcript(&mut transcript, context, sid, rho)?; - self.pimod - .verify(pimod::CommonInput::new(N), context, &mut transcript)?; - Self::append_pifac_transcript(&mut transcript, context, sid, rho)?; - self.pifac.verify( - pifac::CommonInput::new(verifier_params, N), - context, + Self::append_pimod_transcript( &mut transcript, + common_input.shared_context, + common_input.sid, + common_input.rho, + )?; + self.pimod.verify( + pimod::CommonInput::new(common_input.modulus), + common_input.shared_context, + &mut transcript, + )?; + Self::append_pifac_transcript( + &mut transcript, + common_input.shared_context, + common_input.sid, + common_input.rho, )?; - Ok(()) - }*/ - - pub(crate) fn verify( - self, - common_input: CommonInput - ) -> Result<()> { - let mut transcript = Self::new_transcript(); - Self::append_pimod_transcript(&mut transcript, common_input.shared_context, common_input.sid, common_input.rho)?; - self.pimod - .verify(&pimod::CommonInput::new(common_input.modulus), common_input.shared_context, &mut transcript)?; - Self::append_pifac_transcript(&mut transcript, common_input.shared_context, common_input.sid, common_input.rho)?; self.pifac.verify( pifac::CommonInput::new(common_input.setup_parameters, common_input.modulus), common_input.shared_context, @@ -234,9 +224,7 @@ mod tests { &q, )?; let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); - assert!(proof - .verify(common_input) - .is_ok()); + assert!(proof.verify(&common_input).is_ok()); Ok(()) } @@ -252,8 +240,8 @@ mod tests { let mut transcript = AuxInfoProof::new_transcript(); AuxInfoProof::append_pimod_transcript(&mut transcript, shared_context, sid, rho)?; let pimod = pimod::PiModProof::prove( - &pimod::CommonInput::new(&modulus), - &pimod::ProverSecret::new(&p, &q), + pimod::CommonInput::new(&modulus), + pimod::ProverSecret::new(&p, &q), shared_context, &mut transcript, &mut rng, @@ -271,46 +259,7 @@ mod tests { pifac: pifac.clone(), }; let common_input = CommonInput::new(shared_context, sid, rho, &setup_params, &modulus); - assert!(proof - .verify(common_input) - .is_ok()); - let sid1 = Identifier::random(&mut rng); - let rho1: [u8; 32] = rng.gen(); - let setup_params1 = VerifiedRingPedersen::gen(&mut rng, &())?; - let (p1, q1) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); - let modulus1 = &p1 * &q1; - let shared_context1 = &SharedContext::random(&mut rng); - let mut transcript1 = AuxInfoProof::new_transcript(); - AuxInfoProof::append_pimod_transcript(&mut transcript1, shared_context1, sid1, rho1)?; - let pimod1 = pimod::PiModProof::prove( - &pimod::CommonInput::new(&modulus1), - &pimod::ProverSecret::new(&p1, &q1), - shared_context1, - &mut transcript1, - &mut rng, - )?; - AuxInfoProof::append_pifac_transcript(&mut transcript1, shared_context1, sid1, rho1)?; - let pifac1 = pifac::PiFacProof::prove( - pifac::CommonInput::new(&setup_params1, &modulus1), - pifac::ProverSecret::new(&p1, &q1), - shared_context1, - &mut transcript1, - &mut rng, - )?; - let proof1 = AuxInfoProof { - pimod: pimod1.clone(), - pifac: pifac1.clone(), - }; - assert!(proof1 - .verify(common_input) - .is_ok()); - let proof2 = AuxInfoProof { - pimod, - pifac: pifac1, - }; - assert!(proof2 - .verify(common_input) - .is_err()); + assert!(proof.verify(&common_input).is_ok()); let proof1: AuxInfoProof = random_auxinfo_proof()?; let proof2: AuxInfoProof = random_auxinfo_proof()?; @@ -323,12 +272,8 @@ mod tests { pifac: proof2.pifac, pimod: proof1.pimod, }; - assert!(mix_one - .verify(common_input) - .is_err()); - assert!(mix_two - .verify(common_input) - .is_err()); + assert!(mix_one.verify(&common_input).is_err()); + assert!(mix_two.verify(&common_input).is_err()); Ok(()) } @@ -353,9 +298,7 @@ mod tests { &p1, &q1, ) { - Ok(proof) => assert!(proof - .verify(common_input) - .is_err()), + Ok(proof) => assert!(proof.verify(&common_input).is_err()), Err(_) => return Ok(()), } Ok(()) @@ -371,7 +314,13 @@ mod tests { let modulus = &p * &q; let shared_context = &SharedContext::random(&mut rng); let bad_shared_context = &SharedContext::random(&mut rng); - let common_input = CommonInput{shared_context: bad_shared_context, sid, rho, setup_parameters: &setup_params, modulus: &modulus}; + let common_input = CommonInput { + shared_context: bad_shared_context, + sid, + rho, + setup_parameters: &setup_params, + modulus: &modulus, + }; match AuxInfoProof::prove( &mut rng, shared_context, @@ -382,9 +331,7 @@ mod tests { &p, &q, ) { - Ok(proof) => assert!(proof - .verify(common_input) - .is_err()), + Ok(proof) => assert!(proof.verify(&common_input).is_err()), Err(_) => return Ok(()), } Ok(()) From 4c80c101f1becba507e46702b0e039247fac8ab2 Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Wed, 13 Sep 2023 13:57:21 +0530 Subject: [PATCH 10/19] prove function cleaned --- src/auxinfo/participant.rs | 17 +++----- src/auxinfo/proof.rs | 84 ++++++++++++-------------------------- 2 files changed, 33 insertions(+), 68 deletions(-) diff --git a/src/auxinfo/participant.rs b/src/auxinfo/participant.rs index 4ba60832..ba612a05 100644 --- a/src/auxinfo/participant.rs +++ b/src/auxinfo/participant.rs @@ -493,23 +493,18 @@ impl AuxInfoParticipant { let witness = self.local_storage.retrieve::(self.id)?; let product = &witness.p * &witness.q; - self.other_participant_ids .iter() .map(|&pid| { // Grab the other participant's decommitment record from storage... let verifier_decommit = self.local_storage.retrieve::(pid)?; + let setup_params = verifier_decommit.clone().into_public(); + let params = setup_params.params(); + let shared_context = &self.retrieve_context(); // ... and use its setup parameters in the proof. - let proof = AuxInfoProof::prove( - rng, - &self.retrieve_context(), - sid, - global_rid, - verifier_decommit.clone().into_public().params(), - &product, - &witness.p, - &witness.q, - )?; + let common_input = + CommonInput::new(shared_context, sid, global_rid, params, &product); + let proof = AuxInfoProof::prove(rng, &common_input, &witness.p, &witness.q)?; Message::new( MessageType::Auxinfo(AuxinfoMessageType::R3Proof), sid, diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index 4b429f61..751d7114 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -11,7 +11,6 @@ use crate::{ errors::Result, messages::{AuxinfoMessageType, Message, MessageType}, participant::InnerProtocolParticipant, - protocol::SharedContext, ring_pedersen::VerifiedRingPedersen, Identifier, }; @@ -34,7 +33,7 @@ pub(crate) struct AuxInfoProof { /// Common input and setup parameters known to both the prover and the verifier. pub(crate) struct CommonInput<'a> { - shared_context: &'a SharedContext, + shared_context: &'a ::Context, sid: Identifier, rho: [u8; 32], setup_parameters: &'a VerifiedRingPedersen, @@ -44,17 +43,17 @@ pub(crate) struct CommonInput<'a> { impl<'a> CommonInput<'a> { /// Collect common parameters for proving or verifying a [`AuxInfoProof`] pub(crate) fn new( - shared_context: &'a SharedContext, + shared_context: &'a ::Context, sid: Identifier, rho: [u8; 32], - setup_parameters: &'a VerifiedRingPedersen, + verifier_setup_parameters: &'a VerifiedRingPedersen, modulus: &'a BigNumber, ) -> CommonInput<'a> { Self { shared_context, sid, rho, - setup_parameters, + setup_parameters: verifier_setup_parameters, modulus, } } @@ -85,28 +84,34 @@ impl AuxInfoProof { #[allow(clippy::too_many_arguments)] pub(crate) fn prove( rng: &mut R, - context: &::Context, - sid: Identifier, - rho: [u8; 32], - verifier_params: &VerifiedRingPedersen, - N: &BigNumber, + common_input: &CommonInput, p: &BigNumber, q: &BigNumber, ) -> Result { let mut transcript = Self::new_transcript(); - Self::append_pimod_transcript(&mut transcript, context, sid, rho)?; + Self::append_pimod_transcript( + &mut transcript, + common_input.shared_context, + common_input.sid, + common_input.rho, + )?; let pimod = pimod::PiModProof::prove( - pimod::CommonInput::new(N), + pimod::CommonInput::new(common_input.modulus), pimod::ProverSecret::new(p, q), - context, + common_input.shared_context, &mut transcript, rng, )?; - Self::append_pifac_transcript(&mut transcript, context, sid, rho)?; + Self::append_pifac_transcript( + &mut transcript, + common_input.shared_context, + common_input.sid, + common_input.rho, + )?; let pifac = pifac::PiFacProof::prove( - pifac::CommonInput::new(verifier_params, N), + pifac::CommonInput::new(common_input.setup_parameters, common_input.modulus), pifac::ProverSecret::new(p, q), - context, + common_input.shared_context, &mut transcript, rng, )?; @@ -192,16 +197,8 @@ mod tests { let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus = &p * &q; let shared_context = SharedContext::random(&mut rng); - AuxInfoProof::prove( - &mut rng, - &shared_context, - sid, - rho, - &setup_params, - &modulus, - &p, - &q, - ) + let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); + AuxInfoProof::prove(&mut rng, &common_input, &p, &q) } #[test] @@ -213,16 +210,8 @@ mod tests { let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus = &p * &q; let shared_context = SharedContext::random(&mut rng); - let proof = AuxInfoProof::prove( - &mut rng, - &shared_context, - sid, - rho, - &setup_params, - &modulus, - &p, - &q, - )?; + let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); + let proof = AuxInfoProof::prove(&mut rng, &common_input, &p, &q)?; let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); assert!(proof.verify(&common_input).is_ok()); Ok(()) @@ -288,16 +277,7 @@ mod tests { let modulus = &p * &q; let shared_context = &SharedContext::random(&mut rng); let common_input = CommonInput::new(shared_context, sid, rho, &setup_params, &modulus); - match AuxInfoProof::prove( - &mut rng, - shared_context, - sid, - rho, - &setup_params, - &modulus, - &p1, - &q1, - ) { + match AuxInfoProof::prove(&mut rng, &common_input, &p1, &q1) { Ok(proof) => assert!(proof.verify(&common_input).is_err()), Err(_) => return Ok(()), } @@ -312,7 +292,6 @@ mod tests { let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus = &p * &q; - let shared_context = &SharedContext::random(&mut rng); let bad_shared_context = &SharedContext::random(&mut rng); let common_input = CommonInput { shared_context: bad_shared_context, @@ -321,16 +300,7 @@ mod tests { setup_parameters: &setup_params, modulus: &modulus, }; - match AuxInfoProof::prove( - &mut rng, - shared_context, - sid, - rho, - &setup_params, - &modulus, - &p, - &q, - ) { + match AuxInfoProof::prove(&mut rng, &common_input, &p, &q) { Ok(proof) => assert!(proof.verify(&common_input).is_err()), Err(_) => return Ok(()), } From 09f22a655cb3b1f9937a3fb875f3b38f614b644f Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Thu, 14 Sep 2023 16:11:38 +0530 Subject: [PATCH 11/19] all tests work --- src/auxinfo/proof.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index 751d7114..949b5bb9 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -292,8 +292,16 @@ mod tests { let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus = &p * &q; + let shared_context = &SharedContext::random(&mut rng); let bad_shared_context = &SharedContext::random(&mut rng); let common_input = CommonInput { + shared_context, + sid, + rho, + setup_parameters: &setup_params, + modulus: &modulus, + }; + let bad_common_input = CommonInput { shared_context: bad_shared_context, sid, rho, @@ -301,7 +309,7 @@ mod tests { modulus: &modulus, }; match AuxInfoProof::prove(&mut rng, &common_input, &p, &q) { - Ok(proof) => assert!(proof.verify(&common_input).is_err()), + Ok(proof) => assert!(proof.verify(&bad_common_input).is_err()), Err(_) => return Ok(()), } Ok(()) From c0186d0040ffbee196393fee0397736031810aaa Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Thu, 14 Sep 2023 17:03:35 +0530 Subject: [PATCH 12/19] removing redundant code from each constitutent proof must be valid test --- src/auxinfo/proof.rs | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index 949b5bb9..a4028251 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -226,37 +226,13 @@ mod tests { let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus = &p * &q; let shared_context = &SharedContext::random(&mut rng); - let mut transcript = AuxInfoProof::new_transcript(); - AuxInfoProof::append_pimod_transcript(&mut transcript, shared_context, sid, rho)?; - let pimod = pimod::PiModProof::prove( - pimod::CommonInput::new(&modulus), - pimod::ProverSecret::new(&p, &q), - shared_context, - &mut transcript, - &mut rng, - )?; - AuxInfoProof::append_pifac_transcript(&mut transcript, shared_context, sid, rho)?; - let pifac = pifac::PiFacProof::prove( - pifac::CommonInput::new(&setup_params, &modulus), - pifac::ProverSecret::new(&p, &q), - shared_context, - &mut transcript, - &mut rng, - )?; - let proof = AuxInfoProof { - pimod: pimod.clone(), - pifac: pifac.clone(), - }; let common_input = CommonInput::new(shared_context, sid, rho, &setup_params, &modulus); - assert!(proof.verify(&common_input).is_ok()); let proof1: AuxInfoProof = random_auxinfo_proof()?; let proof2: AuxInfoProof = random_auxinfo_proof()?; - let mix_one = AuxInfoProof { pifac: proof1.pifac, pimod: proof2.pimod, }; - let mix_two = AuxInfoProof { pifac: proof2.pifac, pimod: proof1.pimod, From 83ba0e5b4f6e006bee8f6cc56ffeefbeb3df111c Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Tue, 19 Sep 2023 09:38:13 +0530 Subject: [PATCH 13/19] mix proofs nested closure --- src/auxinfo/proof.rs | 158 +++++++++++++++++++++++++++++++++++++++---- src/protocol.rs | 2 +- 2 files changed, 146 insertions(+), 14 deletions(-) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index a4028251..384219bb 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -32,6 +32,7 @@ pub(crate) struct AuxInfoProof { } /// Common input and setup parameters known to both the prover and the verifier. +#[derive(Clone)] pub(crate) struct CommonInput<'a> { shared_context: &'a ::Context, sid: Identifier, @@ -189,7 +190,7 @@ mod tests { use crate::{paillier::prime_gen, protocol::SharedContext, utils::testing::init_testing}; use rand::Rng; - fn random_auxinfo_proof() -> Result { + /*fn random_auxinfo_proof() -> Result { let mut rng = init_testing(); let sid = Identifier::random(&mut rng); let rho = rng.gen(); @@ -199,8 +200,96 @@ mod tests { let shared_context = SharedContext::random(&mut rng); let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); AuxInfoProof::prove(&mut rng, &common_input, &p, &q) + }*/ + + /*fn random_auxinfo_proof() -> (Result, Result>) { + let mut rng = init_testing(); + let sid = Identifier::random(&mut rng); + let rho = rng.gen(); + let setup_params = VerifiedRingPedersen::gen(&mut rng, &()).unwrap(); + let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); + let modulus = &p * &q; + let shared_context = SharedContext::random(&mut rng); + let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus).clone(); + let proof = AuxInfoProof::prove(&mut rng, &common_input, &p, &q).unwrap().clone(); + //let proof = proof.clone(); + //let cloned_common = common_input.clone(); + (Ok(proof), Ok(common_input)) + }*/ + + /*fn random_auxinfo_proof() -> (Result, Result>) { + let mut rng = init_testing(); + let sid = Identifier::random(&mut rng); + let rho = rng.gen(); + let setup_params = VerifiedRingPedersen::gen(&mut rng, &()).unwrap(); + let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); + let modulus = &p * &q; + let shared_context = SharedContext::random(&mut rng); + let common_input = CommonInput::new(&shared_context.clone(), sid, rho, &setup_params.clone(), &modulus.clone()); + let proof = AuxInfoProof::prove(&mut rng.clone(), &common_input.clone(), &p.clone(), &q.clone()).unwrap(); + (Ok(proof.clone()), Ok(common_input.clone())) + }*/ + + /*fn random_auxinfo_proof( + rng: &mut R, + mut test_code: impl FnMut(CommonInput, AuxInfoProof) -> Result<()>, + ) -> Result<()> { + let mut rng = init_testing(); + let sid = Identifier::random(&mut rng); + let rho = rng.gen(); + let setup_params = VerifiedRingPedersen::gen(&mut rng, &()).unwrap(); + let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); + let modulus = &p * &q; + let shared_context = SharedContext::random(&mut rng); + let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); + let proof = AuxInfoProof::prove(&mut rng.clone(), &common_input.clone(), &p.clone(), &q.clone()).unwrap(); + //(Ok(proof.clone()), Ok(common_input.clone())) + test_code(common_input, proof) + }*/ + fn random_auxinfo_proof( + rng: &mut R, + mut test_code: impl FnMut(CommonInput, AuxInfoProof) -> Result<()>, + ) -> Result<()> { + let mut rng = init_testing(); + let sid = Identifier::random(&mut rng); + let rho = rng.gen(); + let setup_params = VerifiedRingPedersen::gen(&mut rng, &()).unwrap(); + let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); + let modulus = &p * &q; + let shared_context = SharedContext::random(&mut rng); + let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); + let proof = AuxInfoProof::prove(&mut rng.clone(), &common_input.clone(), &p.clone(), &q.clone()).unwrap(); + //(Ok(proof.clone()), Ok(common_input.clone())) + test_code(common_input, proof) } + /*fn random_auxinfo_proof() -> (Result, Result<&’a CommonInput<'static>>) { + let mut rng = init_testing(); + let sid = Identifier::random(&mut rng); + let rho = rng.gen(); + let setup_params = VerifiedRingPedersen::gen(&mut rng, &()).unwrap(); + let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); + let modulus = &p * &q; + let shared_context = SharedContext::random(&mut rng); + let common_input = CommonInput::new(&shared_context.clone(), sid, rho, &setup_params.clone(), &modulus.clone()); + let proof = AuxInfoProof::prove(&mut rng.clone(), &common_input.clone(), &p.clone(), &q.clone()).unwrap(); + (Ok(proof), Ok(&common_input)) + }*/ + /*use std::sync::Arc; + fn random_auxinfo_proof() -> (Result, Result>>) { + let mut rng = init_testing(); + let sid = Identifier::random(&mut rng); + let rho = rng.gen(); + let setup_params = VerifiedRingPedersen::gen(&mut rng, &()).unwrap(); + let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); + let modulus = &p * &q; + let shared_context = SharedContext::random(&mut rng); + let common_input = CommonInput::new(&shared_context.clone(), sid, rho, &setup_params.clone(), &modulus.clone()); + let proof = AuxInfoProof::prove(&mut rng.clone(), &common_input.clone(), &p.clone(), &q.clone()).unwrap(); + let common_input = Arc::new(&common_input); + (Ok(proof), Ok(common_input)) + }*/ + #[test] fn auxinfo_proof_verifies() -> Result<()> { let mut rng = init_testing(); @@ -220,25 +309,68 @@ mod tests { #[test] fn each_constituent_proof_must_be_valid() -> Result<()> { let mut rng = init_testing(); - let sid = Identifier::random(&mut rng); + /*let sid = Identifier::random(&mut rng); let rho = rng.gen(); let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); let modulus = &p * &q; let shared_context = &SharedContext::random(&mut rng); - let common_input = CommonInput::new(shared_context, sid, rho, &setup_params, &modulus); - let proof1: AuxInfoProof = random_auxinfo_proof()?; - let proof2: AuxInfoProof = random_auxinfo_proof()?; - let mix_one = AuxInfoProof { - pifac: proof1.pifac, - pimod: proof2.pimod, + let common_input = CommonInput::new(shared_context, sid, rho, &setup_params, &modulus);*/ + /*let (proof1, _common_input) = match random_auxinfo_proof() { + Ok((proof, input)) => (proof, input), + Err(err) => { + eprintln!("Error: {}", err); + panic!("Error occurred while generating the proof"); + } + };*/ + //let (proof1, common_input) = random_auxinfo_proof(); + //let (proof2, _) = random_auxinfo_proof(); + //let proof1 = proof1.unwrap(); + //let proof2 = proof2.unwrap(); + let f = |input: CommonInput, proof: &'a AuxInfoProof| { + let result = proof.verify(&input); + let input_clone = input.clone(); + let proof_clone = proof.clone(); + let f1 = move |input1: CommonInput, proof1: &'a AuxInfoProof| { + let result1 = proof_clone.verify(&input1); + let mix_one = AuxInfoProof { + pifac: proof_clone.pifac, + pimod: proof1.pimod, + }; + let mix_two = AuxInfoProof { + pifac: proof1.pifac, + pimod: proof_clone.pimod, + }; + Ok(()) + }; + random_auxinfo_proof(&mut rng, f1); + Ok(()) }; - let mix_two = AuxInfoProof { - pifac: proof2.pifac, - pimod: proof1.pimod, + random_auxinfo_proof(&mut rng, f); + /*let f = |input: CommonInput, proof: AuxInfoProof| { + let result = proof.verify(&input); + //let input_clone = input.clone(); + //let proof_clone = proof.clone(); + let f1 = |input1: CommonInput, proof1: AuxInfoProof| { + //let proof_clone = proof.clone(); // Clone the proof variable + let result1 = proof1.verify(&input1); + let mix_one = AuxInfoProof { + pifac: proof.pifac, + pimod: proof1.pimod, + }; + /*let mix_two = AuxInfoProof { + pifac: proof1.pifac, + pimod: proof_clone.pimod, + };*/ + Ok(()) + }; + random_auxinfo_proof(&mut rng, f1); + Ok(()) }; - assert!(mix_one.verify(&common_input).is_err()); - assert!(mix_two.verify(&common_input).is_err()); + random_auxinfo_proof(&mut init_testing(), f);*/ + + //assert!(mix_one.verify(&comm_inp).is_err()); + //assert!(mix_two.verify(&comm_inp).is_err()); Ok(()) } diff --git a/src/protocol.rs b/src/protocol.rs index 6150d955..cb02cb6e 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -487,7 +487,7 @@ impl ParticipantIdentifier { /// The `SharedContext` contains fixed known parameters across the entire /// protocol. It does not however contain the entire protocol context. -#[derive(Debug)] +#[derive(Debug, Clone)] pub(crate) struct SharedContext { sid: Identifier, participants: Vec, From 2c4aea9e46a70384114b4528f9974c30d9ece930 Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Wed, 20 Sep 2023 17:56:36 +0530 Subject: [PATCH 14/19] all tests working --- src/auxinfo/proof.rs | 156 +++++-------------------------------------- 1 file changed, 18 insertions(+), 138 deletions(-) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index 384219bb..408650c1 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -190,65 +190,9 @@ mod tests { use crate::{paillier::prime_gen, protocol::SharedContext, utils::testing::init_testing}; use rand::Rng; - /*fn random_auxinfo_proof() -> Result { - let mut rng = init_testing(); - let sid = Identifier::random(&mut rng); - let rho = rng.gen(); - let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; - let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); - let modulus = &p * &q; - let shared_context = SharedContext::random(&mut rng); - let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); - AuxInfoProof::prove(&mut rng, &common_input, &p, &q) - }*/ - - /*fn random_auxinfo_proof() -> (Result, Result>) { - let mut rng = init_testing(); - let sid = Identifier::random(&mut rng); - let rho = rng.gen(); - let setup_params = VerifiedRingPedersen::gen(&mut rng, &()).unwrap(); - let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); - let modulus = &p * &q; - let shared_context = SharedContext::random(&mut rng); - let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus).clone(); - let proof = AuxInfoProof::prove(&mut rng, &common_input, &p, &q).unwrap().clone(); - //let proof = proof.clone(); - //let cloned_common = common_input.clone(); - (Ok(proof), Ok(common_input)) - }*/ - - /*fn random_auxinfo_proof() -> (Result, Result>) { - let mut rng = init_testing(); - let sid = Identifier::random(&mut rng); - let rho = rng.gen(); - let setup_params = VerifiedRingPedersen::gen(&mut rng, &()).unwrap(); - let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); - let modulus = &p * &q; - let shared_context = SharedContext::random(&mut rng); - let common_input = CommonInput::new(&shared_context.clone(), sid, rho, &setup_params.clone(), &modulus.clone()); - let proof = AuxInfoProof::prove(&mut rng.clone(), &common_input.clone(), &p.clone(), &q.clone()).unwrap(); - (Ok(proof.clone()), Ok(common_input.clone())) - }*/ - - /*fn random_auxinfo_proof( - rng: &mut R, - mut test_code: impl FnMut(CommonInput, AuxInfoProof) -> Result<()>, - ) -> Result<()> { - let mut rng = init_testing(); - let sid = Identifier::random(&mut rng); - let rho = rng.gen(); - let setup_params = VerifiedRingPedersen::gen(&mut rng, &()).unwrap(); - let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); - let modulus = &p * &q; - let shared_context = SharedContext::random(&mut rng); - let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); - let proof = AuxInfoProof::prove(&mut rng.clone(), &common_input.clone(), &p.clone(), &q.clone()).unwrap(); - //(Ok(proof.clone()), Ok(common_input.clone())) - test_code(common_input, proof) - }*/ fn random_auxinfo_proof( - rng: &mut R, - mut test_code: impl FnMut(CommonInput, AuxInfoProof) -> Result<()>, + _rng: &mut R, + test_code: impl FnOnce(CommonInput, AuxInfoProof) -> Result<()>, ) -> Result<()> { let mut rng = init_testing(); let sid = Identifier::random(&mut rng); @@ -258,38 +202,17 @@ mod tests { let modulus = &p * &q; let shared_context = SharedContext::random(&mut rng); let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); - let proof = AuxInfoProof::prove(&mut rng.clone(), &common_input.clone(), &p.clone(), &q.clone()).unwrap(); + let proof = AuxInfoProof::prove( + &mut rng.clone(), + &common_input.clone(), + &p.clone(), + &q.clone(), + ) + .unwrap(); //(Ok(proof.clone()), Ok(common_input.clone())) test_code(common_input, proof) } - /*fn random_auxinfo_proof() -> (Result, Result<&’a CommonInput<'static>>) { - let mut rng = init_testing(); - let sid = Identifier::random(&mut rng); - let rho = rng.gen(); - let setup_params = VerifiedRingPedersen::gen(&mut rng, &()).unwrap(); - let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); - let modulus = &p * &q; - let shared_context = SharedContext::random(&mut rng); - let common_input = CommonInput::new(&shared_context.clone(), sid, rho, &setup_params.clone(), &modulus.clone()); - let proof = AuxInfoProof::prove(&mut rng.clone(), &common_input.clone(), &p.clone(), &q.clone()).unwrap(); - (Ok(proof), Ok(&common_input)) - }*/ - /*use std::sync::Arc; - fn random_auxinfo_proof() -> (Result, Result>>) { - let mut rng = init_testing(); - let sid = Identifier::random(&mut rng); - let rho = rng.gen(); - let setup_params = VerifiedRingPedersen::gen(&mut rng, &()).unwrap(); - let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); - let modulus = &p * &q; - let shared_context = SharedContext::random(&mut rng); - let common_input = CommonInput::new(&shared_context.clone(), sid, rho, &setup_params.clone(), &modulus.clone()); - let proof = AuxInfoProof::prove(&mut rng.clone(), &common_input.clone(), &p.clone(), &q.clone()).unwrap(); - let common_input = Arc::new(&common_input); - (Ok(proof), Ok(common_input)) - }*/ - #[test] fn auxinfo_proof_verifies() -> Result<()> { let mut rng = init_testing(); @@ -309,68 +232,25 @@ mod tests { #[test] fn each_constituent_proof_must_be_valid() -> Result<()> { let mut rng = init_testing(); - /*let sid = Identifier::random(&mut rng); - let rho = rng.gen(); - let setup_params = VerifiedRingPedersen::gen(&mut rng, &())?; - let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); - let modulus = &p * &q; - let shared_context = &SharedContext::random(&mut rng); - let common_input = CommonInput::new(shared_context, sid, rho, &setup_params, &modulus);*/ - /*let (proof1, _common_input) = match random_auxinfo_proof() { - Ok((proof, input)) => (proof, input), - Err(err) => { - eprintln!("Error: {}", err); - panic!("Error occurred while generating the proof"); - } - };*/ - //let (proof1, common_input) = random_auxinfo_proof(); - //let (proof2, _) = random_auxinfo_proof(); - //let proof1 = proof1.unwrap(); - //let proof2 = proof2.unwrap(); - let f = |input: CommonInput, proof: &'a AuxInfoProof| { - let result = proof.verify(&input); - let input_clone = input.clone(); - let proof_clone = proof.clone(); - let f1 = move |input1: CommonInput, proof1: &'a AuxInfoProof| { - let result1 = proof_clone.verify(&input1); - let mix_one = AuxInfoProof { - pifac: proof_clone.pifac, - pimod: proof1.pimod, - }; - let mix_two = AuxInfoProof { - pifac: proof1.pifac, - pimod: proof_clone.pimod, - }; - Ok(()) - }; - random_auxinfo_proof(&mut rng, f1); - Ok(()) - }; - random_auxinfo_proof(&mut rng, f); - /*let f = |input: CommonInput, proof: AuxInfoProof| { - let result = proof.verify(&input); - //let input_clone = input.clone(); - //let proof_clone = proof.clone(); + let mut rng_clone = rng.clone(); + let f = |input: CommonInput, proof: AuxInfoProof| { let f1 = |input1: CommonInput, proof1: AuxInfoProof| { - //let proof_clone = proof.clone(); // Clone the proof variable - let result1 = proof1.verify(&input1); let mix_one = AuxInfoProof { pifac: proof.pifac, pimod: proof1.pimod, }; - /*let mix_two = AuxInfoProof { + let mix_two = AuxInfoProof { pifac: proof1.pifac, - pimod: proof_clone.pimod, - };*/ + pimod: proof.pimod, + }; + assert!(mix_one.verify(&input).is_err()); + assert!(mix_two.verify(&input1).is_err()); Ok(()) }; - random_auxinfo_proof(&mut rng, f1); + let _ = random_auxinfo_proof(&mut rng_clone, f1); Ok(()) }; - random_auxinfo_proof(&mut init_testing(), f);*/ - - //assert!(mix_one.verify(&comm_inp).is_err()); - //assert!(mix_two.verify(&comm_inp).is_err()); + let _ = random_auxinfo_proof(&mut rng, f); Ok(()) } From 069329e1876193368b1c92a4de8c6ddc75d21af8 Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Thu, 21 Sep 2023 18:44:49 +0530 Subject: [PATCH 15/19] one comment addressed --- src/auxinfo/proof.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index 408650c1..b7b82adc 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -247,10 +247,10 @@ mod tests { assert!(mix_two.verify(&input1).is_err()); Ok(()) }; - let _ = random_auxinfo_proof(&mut rng_clone, f1); + random_auxinfo_proof(&mut rng_clone, f1)?; Ok(()) }; - let _ = random_auxinfo_proof(&mut rng, f); + random_auxinfo_proof(&mut rng, f)?; Ok(()) } From 17aea0b6eb494446a4f379fe4aa98b9ede95f6b6 Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Thu, 21 Sep 2023 18:58:15 +0530 Subject: [PATCH 16/19] nits fixed --- src/auxinfo/proof.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index b7b82adc..7f5c1a62 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -209,7 +209,6 @@ mod tests { &q.clone(), ) .unwrap(); - //(Ok(proof.clone()), Ok(common_input.clone())) test_code(common_input, proof) } @@ -224,7 +223,6 @@ mod tests { let shared_context = SharedContext::random(&mut rng); let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); let proof = AuxInfoProof::prove(&mut rng, &common_input, &p, &q)?; - let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); assert!(proof.verify(&common_input).is_ok()); Ok(()) } From d344a3c589cfac22b269cca44051a015db3ede6a Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Thu, 21 Sep 2023 19:08:31 +0530 Subject: [PATCH 17/19] rng included in random proof function --- src/auxinfo/proof.rs | 20 +++++++------------- src/protocol.rs | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index 7f5c1a62..5f295ba2 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -191,24 +191,18 @@ mod tests { use rand::Rng; fn random_auxinfo_proof( - _rng: &mut R, + rng: &mut R, test_code: impl FnOnce(CommonInput, AuxInfoProof) -> Result<()>, ) -> Result<()> { - let mut rng = init_testing(); - let sid = Identifier::random(&mut rng); + let sid = Identifier::random(rng); let rho = rng.gen(); - let setup_params = VerifiedRingPedersen::gen(&mut rng, &()).unwrap(); - let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(&mut rng).unwrap(); + let setup_params = VerifiedRingPedersen::gen(rng, &()).unwrap(); + let (p, q) = prime_gen::get_prime_pair_from_pool_insecure(rng).unwrap(); let modulus = &p * &q; - let shared_context = SharedContext::random(&mut rng); + let shared_context = SharedContext::random(rng); let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); - let proof = AuxInfoProof::prove( - &mut rng.clone(), - &common_input.clone(), - &p.clone(), - &q.clone(), - ) - .unwrap(); + let proof = + AuxInfoProof::prove(rng, &common_input.clone(), &p.clone(), &q.clone()).unwrap(); test_code(common_input, proof) } diff --git a/src/protocol.rs b/src/protocol.rs index cb02cb6e..86c080a9 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -513,7 +513,7 @@ impl ProofContext for SharedContext { impl SharedContext { /// This function should not be used outside of the tests. #[cfg(test)] - pub fn random(rng: &mut rand::rngs::StdRng) -> Self { + pub fn random(rng: &mut R) -> Self { let sid = Identifier::random(rng); let participant = ParticipantIdentifier::random(rng); let participant2 = ParticipantIdentifier::random(rng); From 0ea64a471448fcb89ca777e21d1f18b9345fc6f4 Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Sat, 23 Sep 2023 10:24:36 +0530 Subject: [PATCH 18/19] rng issue fixed --- src/auxinfo/proof.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index 5f295ba2..c9bc6672 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -188,7 +188,7 @@ impl AuxInfoProof { mod tests { use super::*; use crate::{paillier::prime_gen, protocol::SharedContext, utils::testing::init_testing}; - use rand::Rng; + use rand::{rngs::StdRng, Rng, SeedableRng}; fn random_auxinfo_proof( rng: &mut R, @@ -224,7 +224,7 @@ mod tests { #[test] fn each_constituent_proof_must_be_valid() -> Result<()> { let mut rng = init_testing(); - let mut rng_clone = rng.clone(); + let mut rng2 = StdRng::from_rng(&mut rng).unwrap(); let f = |input: CommonInput, proof: AuxInfoProof| { let f1 = |input1: CommonInput, proof1: AuxInfoProof| { let mix_one = AuxInfoProof { @@ -239,7 +239,7 @@ mod tests { assert!(mix_two.verify(&input1).is_err()); Ok(()) }; - random_auxinfo_proof(&mut rng_clone, f1)?; + random_auxinfo_proof(&mut rng2, f1)?; Ok(()) }; random_auxinfo_proof(&mut rng, f)?; From a52a63fb1cc9293c1d12cd78cac73fdea72598b0 Mon Sep 17 00:00:00 2001 From: Hridam Basu Date: Mon, 25 Sep 2023 20:37:58 +0530 Subject: [PATCH 19/19] clones removed --- src/auxinfo/proof.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/auxinfo/proof.rs b/src/auxinfo/proof.rs index c9bc6672..60bd4544 100644 --- a/src/auxinfo/proof.rs +++ b/src/auxinfo/proof.rs @@ -201,8 +201,7 @@ mod tests { let modulus = &p * &q; let shared_context = SharedContext::random(rng); let common_input = CommonInput::new(&shared_context, sid, rho, &setup_params, &modulus); - let proof = - AuxInfoProof::prove(rng, &common_input.clone(), &p.clone(), &q.clone()).unwrap(); + let proof = AuxInfoProof::prove(rng, &common_input, &p, &q).unwrap(); test_code(common_input, proof) }