diff --git a/CHANGELOG.md b/CHANGELOG.md index ae3c5f7c..e084214a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add `size` method to the `Circuit` trait [#767] +- Add `ff` dependency ### Removed -- Remove public parametes as parameters for circuit compression [#767] +- Remove `PublicParameters` from parameters for circuit compression [#767] +- Remove `canonical` and `canonical_derive` dependency +- Remove `canon` feature + +### Changed + +- update `dusk-bls12_381` dependency to "0.12" +- update `dusk-jubjub` dependency to "0.13" ## [0.15.0] - 2023-08-30 diff --git a/Cargo.toml b/Cargo.toml index 85846c18..cd87e815 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,9 @@ exclude = [ merlin = {version = "3.0", default-features = false} rand_core = {version="0.6", default-features=false} dusk-bytes = "0.1" -dusk-bls12_381 = {version = "0.11", default-features = false, features = ["groups", "pairings", "endo"]} -dusk-jubjub = {version = "0.12", default-features = false} +dusk-bls12_381 = {version = "0.12", default-features = false, features = ["groups", "pairings"]} +dusk-jubjub = {version = "0.13", default-features = false} +ff = {version = "0.13", default-features = false} itertools = {version = "0.9", default-features = false} hashbrown = {version = "0.9", default-features=false, features = ["ahash"]} msgpacker = {version = "0.4", default-features=false, features = ["alloc", "derive"], optional=true} @@ -30,8 +31,6 @@ rayon = {version = "1.3", optional = true} sha2 = {version = "0.10", default-features = false, optional = true} cfg-if = "1.0" # Dusk related deps for WASMI serde -canonical = {version = "0.7", optional = true} -canonical_derive = {version = "0.7", optional = true} rkyv = {version = "0.7", optional = true, default-features = false} bytecheck = {version = "0.6", optional = true, default-features = false} backtrace = {version = "0.3", optional = true} @@ -62,7 +61,6 @@ std = [ ] alloc = ["dusk-bls12_381/alloc", "msgpacker", "miniz_oxide", "sha2"] debug = ["dusk-cdf", "backtrace"] -canon = ["dusk-bls12_381/canon", "dusk-jubjub/canon", "canonical", "canonical_derive"] rkyv-impl = ["dusk-bls12_381/rkyv-impl", "dusk-jubjub/rkyv-impl", "rkyv", "bytecheck"] [profile.release] diff --git a/refactor_circuit.md b/refactor_circuit.md new file mode 100644 index 00000000..e694bd7e --- /dev/null +++ b/refactor_circuit.md @@ -0,0 +1,51 @@ +Matteo's suggestion of restructuring the `Circuit` trait. + +1. Without the need to retain the private or public input values: +```rust +fn op(f: F, a: u32, b: u32) -> u32 where F: Fn(u32, u32) -> u32 { + f(a, b) +} + +fn add(a: u32, b: u32) -> u32 { + a + b +} + +fn mul(a: u32, b: u32) -> u32 { + a * b +} +``` + +2. With the option of retaining the private and public input values: +```rust +struct Foo where F: Fn(u32, u32) -> u32 { + a: u32, + b: u32, + callback: F +} + +impl Foo where F: Fn(u32, u32) -> u32 { + fn calc(&self) -> u32 { + (self.callback)(self.a, self.b) + } +} + +fn main() { + + let foo = Foo { + a: 10, + b: 20, + callback: add, + }; + + println!("add: {}", op(add, 10, 20)); + println!("mul: {}", op(mul, 10, 20)); + + println!("foo add: {}", foo.calc()); +} +``` + +Notes: +- The funcitons `add` and `mul` would be different circuit implementation, returning the size of the circuit. +- I wouldn't know how to search for the circuit implementation in the AST though. + +3. Another approach is the restructuring of the `Circuit` trait as proposed by Ed diff --git a/src/bit_iterator.rs b/src/bit_iterator.rs index 5eb1edaa..7aaf486d 100644 --- a/src/bit_iterator.rs +++ b/src/bit_iterator.rs @@ -57,7 +57,6 @@ mod test { use super::*; use alloc::vec::Vec; use dusk_bls12_381::BlsScalar; - use dusk_bytes::Serializable; #[test] fn test_bit_iterator8() { diff --git a/src/commitment_scheme/kzg10/srs.rs b/src/commitment_scheme/kzg10/srs.rs index 6ea40a83..c9a56aea 100644 --- a/src/commitment_scheme/kzg10/srs.rs +++ b/src/commitment_scheme/kzg10/srs.rs @@ -9,8 +9,9 @@ use super::key::{CommitKey, OpeningKey}; use crate::{error::Error, util}; use alloc::vec::Vec; -use dusk_bls12_381::{G1Affine, G1Projective, G2Affine}; +use dusk_bls12_381::{BlsScalar, G1Affine, G1Projective, G2Affine}; use dusk_bytes::{DeserializableSlice, Serializable}; +use ff::Field; use rand_core::{CryptoRng, RngCore}; #[cfg(feature = "rkyv-impl")] @@ -67,7 +68,7 @@ impl PublicParameters { max_degree = max_degree + Self::ADDED_BLINDING_DEGREE; // Generate the secret scalar x - let x = util::random_scalar(&mut rng); + let x = BlsScalar::random(&mut rng); // Compute powers of x up to and including x^max_degree let powers_of_x = util::powers_of(&x, max_degree); diff --git a/src/composer.rs b/src/composer.rs index 8d953da4..bc7bd340 100644 --- a/src/composer.rs +++ b/src/composer.rs @@ -11,7 +11,6 @@ use core::cmp; use core::ops::Index; use dusk_bls12_381::BlsScalar; -use dusk_bytes::Serializable; use dusk_jubjub::{JubJubAffine, JubJubExtended, JubJubScalar}; use crate::bit_iterator::BitIterator8; @@ -276,7 +275,11 @@ pub trait Composer: Sized + Index { // we should error instead of producing invalid proofs - otherwise this // can easily become an attack vector to either shutdown prover // services or create malicious statements - let scalar = JubJubScalar::from_bytes(&self[jubjub].to_bytes())?; + let scalar: JubJubScalar = + match JubJubScalar::from_bytes(&self[jubjub].to_bytes()).into() { + Some(s) => s, + None => return Err(Error::BlsScalarMalformed), + }; let width = 2; let wnaf_entries = scalar.compute_windowed_naf(width); @@ -316,16 +319,16 @@ pub trait Composer: Sized + Index { let point = a + b; point_acc.push(point.into()); - let x_alpha = point_to_add.get_x(); - let y_alpha = point_to_add.get_y(); + let x_alpha = point_to_add.get_u(); + let y_alpha = point_to_add.get_v(); Ok(x_alpha * y_alpha) }) .collect::>()?; for i in 0..bits { - let acc_x = self.append_witness(point_acc[i].get_x()); - let acc_y = self.append_witness(point_acc[i].get_y()); + let acc_x = self.append_witness(point_acc[i].get_u()); + let acc_y = self.append_witness(point_acc[i].get_v()); let accumulated_bit = self.append_witness(scalar_acc[i]); // the point accumulator must start from identity and its scalar @@ -340,8 +343,8 @@ pub trait Composer: Sized + Index { ); } - let x_beta = wnaf_point_multiples[i].get_x(); - let y_beta = wnaf_point_multiples[i].get_y(); + let x_beta = wnaf_point_multiples[i].get_u(); + let y_beta = wnaf_point_multiples[i].get_v(); let xy_alpha = self.append_witness(xy_alphas[i]); let xy_beta = x_beta * y_beta; @@ -370,8 +373,8 @@ pub trait Composer: Sized + Index { } // last gate isn't activated for ecc - let acc_x = self.append_witness(point_acc[bits].get_x()); - let acc_y = self.append_witness(point_acc[bits].get_y()); + let acc_x = self.append_witness(point_acc[bits].get_u()); + let acc_y = self.append_witness(point_acc[bits].get_v()); // FIXME this implementation presents a plethora of vulnerabilities and // requires reworking @@ -509,8 +512,8 @@ pub trait Composer: Sized + Index { ) -> WitnessPoint { let affine = affine.into(); - let x = self.append_witness(affine.get_x()); - let y = self.append_witness(affine.get_y()); + let x = self.append_witness(affine.get_u()); + let y = self.append_witness(affine.get_v()); WitnessPoint::new(x, y) } @@ -523,8 +526,8 @@ pub trait Composer: Sized + Index { ) -> WitnessPoint { let affine = affine.into(); - let x = self.append_constant(affine.get_x()); - let y = self.append_constant(affine.get_y()); + let x = self.append_constant(affine.get_u()); + let y = self.append_constant(affine.get_v()); WitnessPoint::new(x, y) } @@ -542,13 +545,13 @@ pub trait Composer: Sized + Index { self.assert_equal_constant( *point.x(), BlsScalar::zero(), - Some(affine.get_x()), + Some(affine.get_u()), ); self.assert_equal_constant( *point.y(), BlsScalar::zero(), - Some(affine.get_y()), + Some(affine.get_v()), ); point @@ -640,13 +643,13 @@ pub trait Composer: Sized + Index { self.assert_equal_constant( *point.x(), BlsScalar::zero(), - Some(public.get_x()), + Some(public.get_u()), ); self.assert_equal_constant( *point.y(), BlsScalar::zero(), - Some(public.get_y()), + Some(public.get_v()), ); } @@ -671,8 +674,8 @@ pub trait Composer: Sized + Index { let point: JubJubAffine = (JubJubExtended::from(p1) + p2).into(); - let x_3 = point.get_x(); - let y_3 = point.get_y(); + let x_3 = point.get_u(); + let y_3 = point.get_v(); let x1_y2 = self[x_1] * self[y_2]; diff --git a/src/composer/compiler/compress.rs b/src/composer/compiler/compress.rs index 069fab06..1e1892ef 100644 --- a/src/composer/compiler/compress.rs +++ b/src/composer/compiler/compress.rs @@ -247,7 +247,11 @@ impl CompressedCircuit { .into_iter() .for_each(|(s, i)| version_scalars[i] = s); for s in scalars { - version_scalars.push(BlsScalar::from_bytes(&s)?); + let scalar: BlsScalar = match BlsScalar::from_bytes(&s).into() { + Some(scalar) => scalar, + None => return Err(Error::BlsScalarMalformed), + }; + version_scalars.push(scalar); } let scalars = version_scalars; diff --git a/src/composer/prover.rs b/src/composer/prover.rs index ddec11a1..079c4026 100644 --- a/src/composer/prover.rs +++ b/src/composer/prover.rs @@ -9,6 +9,7 @@ use core::ops; use dusk_bls12_381::BlsScalar; use dusk_bytes::{DeserializableSlice, Serializable}; +use ff::Field; use merlin::Transcript; use rand_core::{CryptoRng, RngCore}; @@ -20,7 +21,6 @@ use crate::proof_system::{ linearization_poly, quotient_poly, ProverKey, VerifierKey, }; use crate::transcript::TranscriptProtocol; -use crate::util; use super::{Builder, Circuit, Composer}; @@ -85,7 +85,7 @@ impl Prover { let mut w_vec_inverse = domain.ifft(witnesses); for i in 0..hiding_degree + 1 { - let blinding_scalar = util::random_scalar(rng); + let blinding_scalar = BlsScalar::random(&mut *rng); w_vec_inverse[i] = w_vec_inverse[i] - blinding_scalar; w_vec_inverse.push(blinding_scalar); diff --git a/src/fft/polynomial.rs b/src/fft/polynomial.rs index 9632a2ea..178dcdf2 100644 --- a/src/fft/polynomial.rs +++ b/src/fft/polynomial.rs @@ -421,6 +421,7 @@ impl<'a, 'b> Sub<&'a BlsScalar> for &'b Polynomial { #[cfg(test)] mod test { use super::*; + use ff::Field; use rand_core::{CryptoRng, RngCore}; impl Polynomial { @@ -435,7 +436,7 @@ mod test { ) -> Self { let mut random_coeffs = Vec::with_capacity(d + 1); for _ in 0..=d { - random_coeffs.push(util::random_scalar(&mut rng)); + random_coeffs.push(BlsScalar::random(&mut rng)); } Self::from_coefficients_vec(random_coeffs) } diff --git a/src/permutation.rs b/src/permutation.rs index d6b5f78e..a5717945 100644 --- a/src/permutation.rs +++ b/src/permutation.rs @@ -301,9 +301,9 @@ impl Permutation { #[cfg(test)] mod test { use super::*; - //use crate::constraint_system::Constraint; use crate::fft::Polynomial; use dusk_bls12_381::BlsScalar; + use ff::Field; use rand_core::OsRng; #[allow(dead_code)] diff --git a/src/proof_system/proof.rs b/src/proof_system/proof.rs index afb4ef39..e6b1171a 100644 --- a/src/proof_system/proof.rs +++ b/src/proof_system/proof.rs @@ -586,6 +586,7 @@ pub(crate) mod alloc { mod proof_tests { use super::*; use dusk_bls12_381::BlsScalar; + use ff::Field; use rand_core::OsRng; #[test] diff --git a/src/proof_system/widget.rs b/src/proof_system/widget.rs index 4e99a3c5..f1c48846 100644 --- a/src/proof_system/widget.rs +++ b/src/proof_system/widget.rs @@ -576,6 +576,7 @@ mod test { use super::alloc::ProverKey; use super::*; use crate::fft::{EvaluationDomain, Evaluations, Polynomial}; + use ff::Field; #[rustfmt::skip] use ::alloc::vec::Vec; use dusk_bls12_381::BlsScalar; diff --git a/src/util.rs b/src/util.rs index d0155309..90b977b7 100644 --- a/src/util.rs +++ b/src/util.rs @@ -8,6 +8,7 @@ use alloc::vec::Vec; use dusk_bls12_381::{ BlsScalar, G1Affine, G1Projective, G2Affine, G2Projective, }; +use ff::Field; use rand_core::{CryptoRng, RngCore}; #[cfg(feature = "rkyv-impl")] @@ -42,22 +43,17 @@ pub(crate) fn powers_of( powers } -/// Generates a random BlsScalar using a RNG seed. -pub(crate) fn random_scalar(rng: &mut R) -> BlsScalar { - BlsScalar::random(rng) -} - /// Generates a random G1 Point using an RNG seed. pub(crate) fn random_g1_point( rng: &mut R, ) -> G1Projective { - G1Affine::generator() * random_scalar(rng) + G1Affine::generator() * BlsScalar::random(rng) } /// Generates a random G2 point using an RNG seed. pub(crate) fn random_g2_point( rng: &mut R, ) -> G2Projective { - G2Affine::generator() * random_scalar(rng) + G2Affine::generator() * BlsScalar::random(rng) } /// This function is only used to generate the SRS. diff --git a/tests/append_gate.rs b/tests/append_gate.rs index 0722e534..20e478c3 100644 --- a/tests/append_gate.rs +++ b/tests/append_gate.rs @@ -5,6 +5,7 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_plonk::prelude::*; +use ff::Field; use rand::rngs::StdRng; use rand::SeedableRng; @@ -64,7 +65,7 @@ fn append_gate() { } let label = b"append_gate_with_constant"; - let rng = &mut StdRng::seed_from_u64(0x1ab); + let mut rng = StdRng::seed_from_u64(0x1ab); let capacity = 1 << 4; // Test: constant = zero, selectors = one @@ -77,14 +78,14 @@ fn append_gate() { let o = BlsScalar::zero(); let pi = vec![public]; let circuit = TestCircuit::new(a, b, d, o, public); - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile"); // Test default works: let msg = "Default circuit verification should pass"; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test satisfied circuit: // q_l·a + q_r·b + q_m·a·b + q_o·o + q_4·d + public + constant = 0 @@ -94,7 +95,7 @@ fn append_gate() { let d = BlsScalar::one(); let o = -BlsScalar::from(4); let circuit = TestCircuit::new(a, b, d, o, public); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test satisfied circuit: // q_l·a + q_r·b + q_m·a·b + q_o·o + q_4·d + public + constant = 0 @@ -104,7 +105,7 @@ fn append_gate() { let d = BlsScalar::zero(); let o = -BlsScalar::one(); let circuit = TestCircuit::new(a, b, d, o, public); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test satisfied circuit: // q_l·a + q_r·b + q_m·a·b + q_o·o + q_4·d + public + constant = 0 @@ -114,7 +115,7 @@ fn append_gate() { let d = BlsScalar::zero(); let o = -BlsScalar::one(); let circuit = TestCircuit::new(a, b, d, o, public); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test satisfied circuit: // q_l·a + q_r·b + q_m·a·b + q_o·o + q_4·d + public + constant = 0 @@ -124,7 +125,7 @@ fn append_gate() { let d = BlsScalar::zero(); let o = -BlsScalar::from(3u64); let circuit = TestCircuit::new(a, b, d, o, public); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test satisfied circuit: // q_l·a + q_r·b + q_m·a·b + q_o·o + q_4·d + public + constant = 0 @@ -134,29 +135,29 @@ fn append_gate() { let d = BlsScalar::one(); let o = BlsScalar::zero(); let circuit = TestCircuit::new(a, b, d, o, public); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test satisfied circuit: // q_l·a + q_r·b + q_m·a·b + q_o·o + q_4·d + public + constant = 0 let msg = "Verification of satisfied circuit should pass"; - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); - let d = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); + let d = BlsScalar::random(&mut rng); let public = BlsScalar::from(42); let o = -(a + b + a * b + d + public); let pi = vec![public]; let circuit = TestCircuit::new(a, b, d, o, public); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test unsatisfied circuit: let msg = "Proof creation of unsatisfied circuit should fail"; - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); - let d = BlsScalar::random(rng); - let o = BlsScalar::random(rng); - let public = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); + let d = BlsScalar::random(&mut rng); + let o = BlsScalar::random(&mut rng); + let public = BlsScalar::random(&mut rng); let circuit = TestCircuit::new(a, b, d, o, public); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test unsatisfied circuit: // q_l·a + q_r·b + q_m·a·b + q_o·o + q_4·d + public + constant = 0 @@ -167,7 +168,7 @@ fn append_gate() { let o = BlsScalar::one(); let public = BlsScalar::one(); let circuit = TestCircuit::new(a, b, d, o, public); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test unsatisfied circuit let msg = "Verification of unsatisfied circuit should pass"; @@ -177,5 +178,5 @@ fn append_gate() { let o = BlsScalar::one(); let public = BlsScalar::one(); let circuit = TestCircuit::new(a, b, d, o, public); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); } diff --git a/tests/assert_point.rs b/tests/assert_point.rs index ca1d938e..66364e53 100644 --- a/tests/assert_point.rs +++ b/tests/assert_point.rs @@ -152,8 +152,8 @@ fn assert_equal_public_point() { let msg = "Default circuit verification should pass"; let circuit = TestCircuit::default(); let pi = vec![ - dusk_jubjub::GENERATOR.get_x(), - dusk_jubjub::GENERATOR.get_y(), + dusk_jubjub::GENERATOR.get_u(), + dusk_jubjub::GENERATOR.get_v(), ]; check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); @@ -165,7 +165,7 @@ fn assert_equal_public_point() { let public = dusk_jubjub::GENERATOR_EXTENDED * &scalar; let circuit = TestCircuit::new(point.into(), public.into()); let public_affine: JubJubAffine = public.into(); - let pi = vec![public_affine.get_x(), public_affine.get_y()]; + let pi = vec![public_affine.get_u(), public_affine.get_v()]; check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); // Test: diff --git a/tests/assert_scalar.rs b/tests/assert_scalar.rs index 4ae8a691..351e328a 100644 --- a/tests/assert_scalar.rs +++ b/tests/assert_scalar.rs @@ -5,6 +5,7 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_plonk::prelude::*; +use ff::Field; use rand::rngs::StdRng; use rand::SeedableRng; @@ -53,9 +54,9 @@ fn assert_equal() { // Compile common circuit descriptions for the prover and verifier to be // used by all tests let label = b"assert_equal_constant_without_pi"; - let rng = &mut StdRng::seed_from_u64(0xc1adde); + let mut rng = StdRng::seed_from_u64(0xc1adde); let capacity = 1 << 4; - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile"); @@ -67,7 +68,7 @@ fn assert_equal() { // 0 = 0 let msg = "Default circuit verification should pass"; let circuit = TestCircuit::default(); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test: // 1 = 1 @@ -75,15 +76,15 @@ fn assert_equal() { let scalar_a = BlsScalar::one(); let scalar_b = BlsScalar::one(); let circuit = TestCircuit::new(scalar_a, scalar_b); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test: // x = x let msg = "Satisfied circuit verification should pass"; - let scalar_a = BlsScalar::random(rng); + let scalar_a = BlsScalar::random(&mut rng); let scalar_b = scalar_a.clone(); let circuit = TestCircuit::new(scalar_a, scalar_b); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test: // 1 != 0 @@ -91,15 +92,15 @@ fn assert_equal() { let scalar_a = BlsScalar::one(); let scalar_b = BlsScalar::zero(); let circuit = TestCircuit::new(scalar_a, scalar_b); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test: // x != y let msg = "Proof creation should fail with unsatisfied circuit"; - let scalar_a = BlsScalar::random(rng); - let scalar_b = BlsScalar::random(rng); + let scalar_a = BlsScalar::random(&mut rng); + let scalar_b = BlsScalar::random(&mut rng); let circuit = TestCircuit::new(scalar_a, scalar_b); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); } #[test] @@ -146,9 +147,9 @@ fn assert_equal_constant() { // // Compile common circuit descriptions for the prover and verifier let label = b"assert_equal_constant"; - let rng = &mut StdRng::seed_from_u64(0xfa11); + let mut rng = StdRng::seed_from_u64(0xfa11); let capacity = 1 << 4; - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile"); @@ -158,7 +159,7 @@ fn assert_equal_constant() { let msg = "Default circuit verification should pass"; let circuit = TestCircuit::default(); let pi = vec![]; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test public input doesn't match let msg = "Satisfied circuit should not verify because pi length is not the same as in circuit description"; @@ -168,7 +169,9 @@ fn assert_equal_constant() { let public = Some(public_value); let pi = vec![public_value]; let circuit = TestCircuit::new(scalar, constant, public); - check_satisfied_circuit_fails(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit_fails( + &prover, &verifier, &pi, &circuit, &mut rng, &msg, + ); // Test constant doesn't match let msg = "Proof creation should not be possible with different constant than in circuit description"; @@ -176,7 +179,7 @@ fn assert_equal_constant() { let constant = BlsScalar::one(); let public = None; let circuit = TestCircuit::new(scalar, constant, public); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test: public = Some(_), constant = zero // @@ -193,18 +196,18 @@ fn assert_equal_constant() { // 0 = 0 + 0 let msg = "Default circuit verification should pass"; let pi = vec![BlsScalar::zero()]; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test: // witness = 0 + pi let msg = "Satisfied circuit should verify"; - let scalar = BlsScalar::random(rng); + let scalar = BlsScalar::random(&mut rng); let constant = BlsScalar::zero(); let public_value = scalar.clone(); let public = Some(public_value); let pi = vec![public_value]; let circuit = TestCircuit::new(scalar, constant, public); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test public input doesn't match let msg = "Satisfied circuit should not verify because pi length is not the same as in circuit description"; @@ -213,7 +216,9 @@ fn assert_equal_constant() { let public = None; let pi = vec![]; let circuit = TestCircuit::new(scalar, constant, public); - check_satisfied_circuit_fails(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit_fails( + &prover, &verifier, &pi, &circuit, &mut rng, &msg, + ); // Test constant doesn't match let msg = "Proof creation should not be possible with different constant than in circuit description"; @@ -221,12 +226,12 @@ fn assert_equal_constant() { let constant = BlsScalar::one(); let public = Some(BlsScalar::zero()); let circuit = TestCircuit::new(scalar, constant, public); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test: public = None, constant = random // // Compile new circuit descriptions for the prover and verifier - let constant = BlsScalar::random(rng); + let constant = BlsScalar::random(&mut rng); let scalar = constant.clone(); let public = None; let circuit = TestCircuit::new(scalar, constant, public); @@ -238,7 +243,7 @@ fn assert_equal_constant() { // x = x + None let msg = "Default circuit verification should pass"; let pi = vec![]; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test public input doesn't match let msg = "Satisfied circuit should not verify because pi length is not the same as in circuit description"; @@ -246,7 +251,9 @@ fn assert_equal_constant() { let public = Some(public_value); let pi = vec![public_value]; let circuit = TestCircuit::new(scalar, constant, public); - check_satisfied_circuit_fails(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit_fails( + &prover, &verifier, &pi, &circuit, &mut rng, &msg, + ); // Test constant doesn't match let msg = "Proof creation should not be possible with different constant than in circuit description"; @@ -254,12 +261,12 @@ fn assert_equal_constant() { let constant = BlsScalar::one(); let public = None; let circuit = TestCircuit::new(scalar, constant, public); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test: public = Some(_), constant = random // // Compile new circuit descriptions for the prover and verifier - let constant = BlsScalar::random(rng); + let constant = BlsScalar::random(&mut rng); let scalar = constant.clone(); let public = Some(BlsScalar::zero()); let circuit = TestCircuit::new(scalar, constant, public); @@ -271,17 +278,17 @@ fn assert_equal_constant() { // 0 = 0 + 0 let msg = "Default circuit verification should pass"; let pi = vec![BlsScalar::zero()]; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test: // witness = constant + pi let msg = "Satisfied circuit should verify"; - let scalar = BlsScalar::random(rng); + let scalar = BlsScalar::random(&mut rng); let public_value = scalar - constant; let public = Some(public_value); let pi = vec![public_value]; let circuit = TestCircuit::new(scalar, constant, public); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test public input doesn't match let msg = "Satisfied circuit should not verify because pi length is not the same as in circuit description"; @@ -289,7 +296,9 @@ fn assert_equal_constant() { let public = None; let pi = vec![]; let circuit = TestCircuit::new(scalar, constant, public); - check_satisfied_circuit_fails(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit_fails( + &prover, &verifier, &pi, &circuit, &mut rng, &msg, + ); // Test constant doesn't match let msg = "Proof creation should not be possible with different constant than in circuit description"; @@ -297,5 +306,5 @@ fn assert_equal_constant() { let constant = BlsScalar::one(); let public = Some(BlsScalar::zero()); let circuit = TestCircuit::new(scalar, constant, public); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); } diff --git a/tests/boolean.rs b/tests/boolean.rs index 5789ddb7..05f0535b 100644 --- a/tests/boolean.rs +++ b/tests/boolean.rs @@ -5,6 +5,7 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_plonk::prelude::*; +use ff::Field; use rand::rngs::StdRng; use rand::SeedableRng; @@ -45,9 +46,9 @@ fn component_boolean() { // Compile common circuit descriptions for the prover and verifier to be // used by all tests let label = b"component_boolean"; - let rng = &mut StdRng::seed_from_u64(0xfade); + let mut rng = StdRng::seed_from_u64(0xfade); let capacity = 1 << 4; - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile"); @@ -58,35 +59,35 @@ fn component_boolean() { // Test default works: let msg = "Default circuit verification should pass"; let circuit = TestCircuit::default(); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one works let msg = "Circuit with bit = 1 should pass"; let bit = BlsScalar::one(); let circuit = TestCircuit::new(bit); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test zero works let msg = "Circuit with bit = 0 should pass"; let bit = BlsScalar::zero(); let circuit = TestCircuit::new(bit); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test -zero works let msg = "Circuit with bit = -0 should pass"; let bit = -BlsScalar::zero(); let circuit = TestCircuit::new(bit); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test -one fails let msg = "Circuit with bit = -1 shouldn't pass"; let bit = -BlsScalar::one(); let circuit = TestCircuit::new(bit); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test random fails let msg = "Circuit with bit = -1 shouldn't pass"; - let bit = BlsScalar::random(rng); + let bit = BlsScalar::random(&mut rng); let circuit = TestCircuit::new(bit); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); } diff --git a/tests/decomposition.rs b/tests/decomposition.rs index 0c0a4a03..0a017fa9 100644 --- a/tests/decomposition.rs +++ b/tests/decomposition.rs @@ -5,6 +5,7 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_plonk::prelude::*; +use ff::Field; use rand::rngs::StdRng; use rand::SeedableRng; @@ -51,7 +52,7 @@ fn component_decomposition() { } let label = b"component_decomposition"; - let rng = &mut StdRng::seed_from_u64(0x1ea); + let mut rng = StdRng::seed_from_u64(0x1ea); let capacity = 1 << 10; let pi = vec![]; @@ -60,14 +61,14 @@ fn component_decomposition() { // Compile new circuit descriptions for the prover and verifier const N1: usize = 1; let circuit = TestCircuit::::default(); - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::>(&pp, label) .expect("Circuit should compile"); // Test default works: let msg = "Default circuit verification should pass"; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test bls one let msg = "Verification of satisfied circuit should pass"; @@ -75,14 +76,14 @@ fn component_decomposition() { let mut decomp_expected = [BlsScalar::zero(); N1]; decomp_expected[0] = BlsScalar::one(); let circuit = TestCircuit::new(a, decomp_expected); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test bls two fails let msg = "Proof creation of unsatisfied circuit should fail"; let a = BlsScalar::from(2); let decomp_expected = [BlsScalar::zero(); N1]; let circuit = TestCircuit::new(a, decomp_expected); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test N = 64 // @@ -95,7 +96,7 @@ fn component_decomposition() { // Test default works: let msg = "Default circuit verification should pass"; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test bls two let msg = "Verification of satisfied circuit should pass"; @@ -103,7 +104,7 @@ fn component_decomposition() { let mut decomp_expected = [BlsScalar::zero(); N64]; decomp_expected[1] = BlsScalar::one(); let circuit = TestCircuit::new(a, decomp_expected); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test bls forty two let msg = "Verification of satisfied circuit should pass"; @@ -113,21 +114,21 @@ fn component_decomposition() { decomp_expected[3] = BlsScalar::one(); decomp_expected[1] = BlsScalar::one(); let circuit = TestCircuit::new(a, decomp_expected); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test u64::MAX let msg = "Verification of satisfied circuit should pass"; let a = BlsScalar::from(u64::MAX); let decomp_expected = [BlsScalar::one(); N64]; let circuit = TestCircuit::new(a, decomp_expected); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test 2 * u64::MAX + 1 fails let msg = "Proof creation of unsatisfied circuit should fail"; let a = BlsScalar::from(u64::MAX) * BlsScalar::from(2) + BlsScalar::one(); let decomp_expected = [BlsScalar::one(); N64]; let circuit = TestCircuit::new(a, decomp_expected); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test N = 64 // @@ -140,17 +141,17 @@ fn component_decomposition() { // Test random works: let msg = "Verification of satisfied circuit should pass"; - let a = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); let mut decomp_expected = [BlsScalar::zero(); N256]; a.to_bits().iter().enumerate().for_each(|(i, bit)| { decomp_expected[i] = BlsScalar::from(*bit as u64); }); let circuit = TestCircuit::new(a, decomp_expected); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test flipping one bit fails let msg = "Proof creation of unsatisfied circuit should fail"; - let a = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); let mut decomp_expected = [BlsScalar::zero(); N256]; a.to_bits().iter().enumerate().for_each(|(i, bit)| { decomp_expected[i] = BlsScalar::from(*bit as u64); @@ -158,5 +159,5 @@ fn component_decomposition() { decomp_expected[123] *= -BlsScalar::one(); decomp_expected[123] += BlsScalar::one(); let circuit = TestCircuit::new(a, decomp_expected); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); } diff --git a/tests/gate_add_mul.rs b/tests/gate_add_mul.rs index 719252e6..98a90da0 100644 --- a/tests/gate_add_mul.rs +++ b/tests/gate_add_mul.rs @@ -5,6 +5,7 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_plonk::prelude::*; +use ff::Field; use rand::rngs::StdRng; use rand::SeedableRng; @@ -75,7 +76,7 @@ fn gate_add_mul() { } let label = b"gate_add_mul"; - let rng = &mut StdRng::seed_from_u64(0xbe11); + let mut rng = StdRng::seed_from_u64(0xbe11); let capacity = 1 << 4; // Test: public = zero, constant = zero, selectors = one @@ -89,14 +90,14 @@ fn gate_add_mul() { let result = a + b + a * b + d + public + CONST; let pi = vec![public, public]; let circuit = TestCircuit::new(a, b, d, public, result); - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile"); // Test default works: let msg = "Default circuit verification should pass"; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test satisfied circuit: // a + b + a·b + d + public + 1 = result @@ -106,29 +107,29 @@ fn gate_add_mul() { let d = BlsScalar::one(); let result = a + b + a * b + d + public + CONST; let circuit = TestCircuit::new(a, b, d, public, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test satisfied circuit: // a + b + a·b + d + public + 1 = result let msg = "Verification of satisfied circuit should pass"; - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); - let d = BlsScalar::random(rng); - let public = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); + let d = BlsScalar::random(&mut rng); + let public = BlsScalar::random(&mut rng); let pi = vec![public, public]; let result = a + b + a * b + d + public + CONST; let circuit = TestCircuit::new(a, b, d, public, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test unsatisfied circuit: let msg = "Proof creation of unsatisfied circuit should fail"; - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); - let d = BlsScalar::random(rng); - let public = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); + let d = BlsScalar::random(&mut rng); + let public = BlsScalar::random(&mut rng); let result = a + b + a * b + d + public + CONST + BlsScalar::one(); let circuit = TestCircuit::new(a, b, d, public, result); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test unsatisfied circuit: // a + b + a·b + d + public + 1 = result @@ -139,7 +140,7 @@ fn gate_add_mul() { let public = BlsScalar::one(); let result = BlsScalar::from(42); let circuit = TestCircuit::new(a, b, d, public, result); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test circuit where circuit description doesn't match let msg = "Proof creation of circuit that has different constant than in description should fail"; @@ -150,5 +151,5 @@ fn gate_add_mul() { let incorrect_constant = -BlsScalar::from(2u64); let result = a + b + a * b + d + public + incorrect_constant; let circuit = TestCircuit::new(a, b, d, public, result); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); } diff --git a/tests/logic.rs b/tests/logic.rs index ed418013..244427d3 100644 --- a/tests/logic.rs +++ b/tests/logic.rs @@ -6,6 +6,7 @@ use core::cmp; use dusk_plonk::prelude::*; +use ff::Field; use rand::rngs::StdRng; use rand::SeedableRng; @@ -58,9 +59,9 @@ fn append_logic_and() { // Compile common circuit descriptions for the prover and verifier with the // default circuit let label = b"append_logic_and"; - let rng = &mut StdRng::seed_from_u64(0x1ead); + let mut rng = StdRng::seed_from_u64(0x1ead); let capacity = 1 << 8; - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::>(&pp, label) .expect("Circuit should compile"); @@ -73,18 +74,18 @@ fn append_logic_and() { // Test default works let msg = "Default circuit verification should pass"; let circuit = TestCircuit::<0>::default(); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test comparing 0 bits is always zero let msg = "Circuit verification of satisfied circuit should pass"; - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); let circuit = TestCircuit::<0> { a, b, result: BlsScalar::zero(), }; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test with bits = 32 // @@ -99,22 +100,22 @@ fn append_logic_and() { let b = BlsScalar::from(0xffff_0000_0000_ffff); let result = BlsScalar::from(0x0000_0ff0); let circuit: TestCircuit = TestCircuit { a, b, result }; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test random works: - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); let circuit: TestCircuit = TestCircuit::new(a, b); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test invalid circuit fails let msg = "Proof creation of unsatisfied circuit should fail"; let bit_mask = BlsScalar::pow_of_2(BIT_PAIRS_16 as u64 * 2) - BlsScalar::one(); - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); let right_result = a & b & bit_mask; - let c = BlsScalar::random(rng); + let c = BlsScalar::random(&mut rng); let wrong_result = a & c & bit_mask; assert_ne!(right_result, wrong_result); let circuit_unsatisfied: TestCircuit = TestCircuit { @@ -122,7 +123,7 @@ fn append_logic_and() { b, result: wrong_result, }; - check_unsatisfied_circuit(&prover, &circuit_unsatisfied, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit_unsatisfied, &mut rng, &msg); // sanity check let circuit_satisfied: TestCircuit = TestCircuit { a, @@ -134,7 +135,7 @@ fn append_logic_and() { &verifier, &pi, &circuit_satisfied, - rng, + &mut rng, &"Sanity check should pass", ); @@ -151,21 +152,21 @@ fn append_logic_and() { let b = -BlsScalar::one(); let result = -BlsScalar::one(); let circuit: TestCircuit = TestCircuit { a, b, result }; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test random works: let msg = "Circuit verification with random values should pass"; - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); let circuit: TestCircuit = TestCircuit::new(a, b); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test invalid circuit fails let msg = "Proof creation of unsatisfied circuit should fail"; - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); let right_result = a & b; - let c = BlsScalar::random(rng); + let c = BlsScalar::random(&mut rng); let wrong_result = a & c; assert_ne!(right_result, wrong_result); let circuit: TestCircuit = TestCircuit { @@ -173,7 +174,7 @@ fn append_logic_and() { b, result: wrong_result, }; - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // sanity check let circuit_satisfied: TestCircuit = TestCircuit { a, @@ -185,7 +186,7 @@ fn append_logic_and() { &verifier, &pi, &circuit_satisfied, - rng, + &mut rng, &"Sanity check should pass", ); } @@ -236,9 +237,9 @@ fn append_logic_xor() { // Compile common circuit descriptions for the prover and verifier to be // used by all tests let label = b"append_logic_xor"; - let rng = &mut StdRng::seed_from_u64(0xdea1); + let mut rng = StdRng::seed_from_u64(0xdea1); let capacity = 1 << 8; - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::>(&pp, label) .expect("Circuit should compile"); @@ -251,18 +252,18 @@ fn append_logic_xor() { // Test default works let msg = "Default circuit verification should pass"; let circuit = TestCircuit::<0>::default(); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test comparing 0 bits is always zero let msg = "Circuit verification of satisfied circuit should pass"; - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); let circuit: TestCircuit<0> = TestCircuit { a, b, result: BlsScalar::zero(), }; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test with bits = 32 // @@ -278,22 +279,22 @@ fn append_logic_xor() { let result = BlsScalar::from(0x0f0f_f00f); let circuit: TestCircuit = TestCircuit { a, b, result }; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test random works: - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); let circuit: TestCircuit = TestCircuit::new(a, b); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test invalid circuit fails let msg = "Proof creation of unsatisfied circuit should fail"; let bit_mask = BlsScalar::pow_of_2(BIT_PAIRS_16 as u64 * 2) - BlsScalar::one(); - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); let right_result = (a ^ b) & bit_mask; - let c = BlsScalar::random(rng); + let c = BlsScalar::random(&mut rng); let wrong_result = (a ^ c) & bit_mask; assert_ne!(right_result, wrong_result); let circuit_unsatisfied: TestCircuit = TestCircuit { @@ -301,7 +302,7 @@ fn append_logic_xor() { b, result: wrong_result, }; - check_unsatisfied_circuit(&prover, &circuit_unsatisfied, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit_unsatisfied, &mut rng, &msg); // sanity check let circuit_satisfied: TestCircuit = TestCircuit { a, @@ -313,7 +314,7 @@ fn append_logic_xor() { &verifier, &pi, &circuit_satisfied, - rng, + &mut rng, &"Sanity check should pass", ); @@ -330,21 +331,21 @@ fn append_logic_xor() { let b = BlsScalar::zero(); let result = -BlsScalar::one(); let circuit: TestCircuit = TestCircuit { a, b, result }; - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test random works: let msg = "Circuit verification with random values should pass"; - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); let circuit: TestCircuit = TestCircuit::new(a, b); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test invalid circuit fails let msg = "Proof creation of unsatisfied circuit should fail"; - let a = BlsScalar::random(rng); - let b = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); + let b = BlsScalar::random(&mut rng); let right_result = a ^ b; - let c = BlsScalar::random(rng); + let c = BlsScalar::random(&mut rng); let wrong_result = a ^ c; assert_ne!(right_result, wrong_result); let circuit: TestCircuit = TestCircuit { @@ -352,7 +353,7 @@ fn append_logic_xor() { b, result: wrong_result, }; - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // sanity check let circuit_satisfied: TestCircuit = TestCircuit { a, @@ -364,7 +365,7 @@ fn append_logic_xor() { &verifier, &pi, &circuit_satisfied, - rng, + &mut rng, &"Sanity check should pass", ); } diff --git a/tests/range.rs b/tests/range.rs index 91fc7722..56effa2d 100644 --- a/tests/range.rs +++ b/tests/range.rs @@ -5,6 +5,7 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_plonk::prelude::*; +use ff::Field; use rand::rngs::StdRng; use rand::SeedableRng; @@ -40,9 +41,9 @@ fn range() { // Compile common circuit descriptions for the prover and verifier to be // used by all tests let label = b"component_range"; - let rng = &mut StdRng::seed_from_u64(0xb1eeb); + let mut rng = StdRng::seed_from_u64(0xb1eeb); let capacity = 1 << 6; - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::>(&pp, label) .expect("Circuit should compile"); @@ -56,22 +57,22 @@ fn range() { // 0 < 2^0 let msg = "Default circuit verification should pass"; let circuit = TestCircuit::<0>::default(); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test: // 1 < 2^0 let msg = "Verification of satisfied circuit should pass"; let a = BlsScalar::one(); let circuit: TestCircuit<0> = TestCircuit::new(a); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test: // random !< 2^0 let msg = "Unsatisfied circuit should fail"; - let a = BlsScalar::random(rng); + let a = BlsScalar::random(&mut rng); assert!(a != BlsScalar::zero()); let circuit: TestCircuit<0> = TestCircuit::new(a); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test bits = 2 // @@ -86,14 +87,14 @@ fn range() { let msg = "Verification of a satisfied circuit should pass"; let a = BlsScalar::one(); let circuit: TestCircuit = TestCircuit::new(a); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test fails: // 4 !< 2^2 let msg = "Proof creation of an unsatisfied circuit should fail"; let a = BlsScalar::from(4); let circuit: TestCircuit = TestCircuit::new(a); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test bits = 74 // @@ -108,21 +109,21 @@ fn range() { let msg = "Verification of a satisfied circuit should pass"; let a = BlsScalar::pow_of_2(73); let circuit: TestCircuit = TestCircuit::new(a); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test: // 2^74 - 1 < 2^74 let msg = "Verification of a satisfied circuit should pass"; let a = BlsScalar::pow_of_2(74) - BlsScalar::one(); let circuit: TestCircuit = TestCircuit::new(a); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test fails: // 2^74 !< 2^74 let msg = "Proof creation of an unsatisfied circuit should fail"; let a = BlsScalar::pow_of_2(74); let circuit: TestCircuit = TestCircuit::new(a); - check_unsatisfied_circuit(&prover, &circuit, rng, &msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, &msg); // Test bits = 256 // @@ -137,12 +138,12 @@ fn range() { let msg = "Verification of a satisfied circuit should pass"; let a = BlsScalar::pow_of_2(255); let circuit: TestCircuit = TestCircuit::new(a); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test: // -bls(1) < 2^256 let msg = "Verification of a satisfied circuit should pass"; let a = -BlsScalar::one(); let circuit: TestCircuit = TestCircuit::new(a); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); } diff --git a/tests/select_bls.rs b/tests/select_bls.rs index 0b61d63d..de6a15f2 100644 --- a/tests/select_bls.rs +++ b/tests/select_bls.rs @@ -5,6 +5,7 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_plonk::prelude::*; +use ff::Field; use rand::rngs::StdRng; use rand::SeedableRng; @@ -69,9 +70,9 @@ fn component_select() { // Compile common circuit descriptions for the prover and verifier to be // used by all tests let label = b"component_select"; - let rng = &mut StdRng::seed_from_u64(0xbeef); + let mut rng = StdRng::seed_from_u64(0xbeef); let capacity = 1 << 5; - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile"); @@ -82,7 +83,7 @@ fn component_select() { // Test default works: let msg = "Default circuit verification should pass"; let circuit = TestCircuit::default(); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one works let msg = "Circuit with bit = 1 that selects value_a should pass"; @@ -91,16 +92,16 @@ fn component_select() { let value_b = BlsScalar::zero(); let result = value_a.clone(); let circuit = TestCircuit::new(bit, value_a, value_b, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one works with random let msg = "Circuit with bit = 1 that selects value_a should pass"; let bit = BlsScalar::one(); - let value_a = BlsScalar::random(rng); - let value_b = BlsScalar::random(rng); + let value_a = BlsScalar::random(&mut rng); + let value_b = BlsScalar::random(&mut rng); let result = value_a.clone(); let circuit = TestCircuit::new(bit, value_a, value_b, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test zero works let msg = "Circuit with bit = 0 that selects value_b should pass"; @@ -109,26 +110,26 @@ fn component_select() { let value_b = BlsScalar::zero(); let result = value_b.clone(); let circuit = TestCircuit::new(bit, value_a, value_b, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test zero works with random let msg = "Circuit with bit = 0 that selects value_b should pass"; let bit = BlsScalar::zero(); - let value_a = BlsScalar::random(rng); - let value_b = BlsScalar::random(rng); + let value_a = BlsScalar::random(&mut rng); + let value_b = BlsScalar::random(&mut rng); let result = value_b.clone(); let circuit = TestCircuit::new(bit, value_a, value_b, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test invalid bit passes (bit should be constrained outside of the // `select` component) let msg = "Circuit with invalid bit shouldn't pass"; - let bit = BlsScalar::random(rng); + let bit = BlsScalar::random(&mut rng); let value_a = BlsScalar::zero(); let value_b = BlsScalar::zero(); let result = BlsScalar::zero(); let circuit = TestCircuit::new(bit, value_a, value_b, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one fails let msg = "Circuit with bit = 1 that selects value_b shouldn't pass"; @@ -137,16 +138,16 @@ fn component_select() { let value_b = BlsScalar::zero(); let result = value_b.clone(); let circuit = TestCircuit::new(bit, value_a, value_b, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test one fails with random let msg = "Circuit with bit = 1 that selects value_b shouldn't pass"; let bit = BlsScalar::one(); - let value_a = BlsScalar::random(rng); - let value_b = BlsScalar::random(rng); + let value_a = BlsScalar::random(&mut rng); + let value_b = BlsScalar::random(&mut rng); let result = value_b.clone(); let circuit = TestCircuit::new(bit, value_a, value_b, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test zero fails let msg = "Circuit with bit = 0 that selects value_a shouldn't pass"; @@ -155,36 +156,36 @@ fn component_select() { let value_b = BlsScalar::zero(); let result = value_a.clone(); let circuit = TestCircuit::new(bit, value_a, value_b, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test zero fails with random let msg = "Circuit with bit = 0 that selects value_a shouldn't pass"; let bit = BlsScalar::zero(); - let value_a = BlsScalar::random(rng); - let value_b = BlsScalar::random(rng); + let value_a = BlsScalar::random(&mut rng); + let value_b = BlsScalar::random(&mut rng); let result = value_a.clone(); let circuit = TestCircuit::new(bit, value_a, value_b, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test random fails let msg = "Circuit with random result shouldn't pass no matter the selector bit"; let bit = BlsScalar::one(); - let value_a = BlsScalar::random(rng); - let value_b = BlsScalar::random(rng); - let result = BlsScalar::random(rng); + let value_a = BlsScalar::random(&mut rng); + let value_b = BlsScalar::random(&mut rng); + let result = BlsScalar::random(&mut rng); let circuit = TestCircuit::new(bit, value_a, value_b, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test random fails let msg = "Circuit with random result shouldn't pass no matter the selector bit"; let bit = BlsScalar::zero(); - let value_a = BlsScalar::random(rng); - let value_b = BlsScalar::random(rng); - let result = BlsScalar::random(rng); + let value_a = BlsScalar::random(&mut rng); + let value_b = BlsScalar::random(&mut rng); + let result = BlsScalar::random(&mut rng); let circuit = TestCircuit::new(bit, value_a, value_b, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); } #[test] @@ -230,9 +231,9 @@ fn component_select_one() { // Compile common circuit descriptions for the prover and verifier to be // used by all tests let label = b"component_select_one"; - let rng = &mut StdRng::seed_from_u64(0xfee); + let mut rng = StdRng::seed_from_u64(0xfee); let capacity = 1 << 5; - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile"); @@ -243,7 +244,7 @@ fn component_select_one() { // Test default works: let msg = "Default circuit verification should pass"; let circuit = TestCircuit::default(); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one works let msg = "Circuit with bit = 1 that selects value should pass"; @@ -251,15 +252,15 @@ fn component_select_one() { let value = BlsScalar::one(); let result = value.clone(); let circuit = TestCircuit::new(bit, value, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one works with random let msg = "Circuit with bit = 1 that selects value should pass"; let bit = BlsScalar::one(); - let value = BlsScalar::random(rng); + let value = BlsScalar::random(&mut rng); let result = value.clone(); let circuit = TestCircuit::new(bit, value, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test zero works let msg = "Circuit with bit = 0 that selects 1 should pass"; @@ -267,24 +268,24 @@ fn component_select_one() { let value = BlsScalar::zero(); let result = BlsScalar::one(); let circuit = TestCircuit::new(bit, value, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test zero works with random let msg = "Circuit with bit = 0 that selects 1 should pass"; let bit = BlsScalar::zero(); - let value = BlsScalar::random(rng); + let value = BlsScalar::random(&mut rng); let result = BlsScalar::one(); let circuit = TestCircuit::new(bit, value, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test invalid bit passes (bit should be constrained outside of the // `select` component) let msg = "Circuit with invalid bit can pass"; - let bit = BlsScalar::random(rng); + let bit = BlsScalar::random(&mut rng); let value = BlsScalar::one(); let result = BlsScalar::one(); let circuit = TestCircuit::new(bit, value, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one fails let msg = "Circuit with bit = 1 that selects 1 shouldn't pass"; @@ -292,15 +293,15 @@ fn component_select_one() { let value = BlsScalar::zero(); let result = BlsScalar::one(); let circuit = TestCircuit::new(bit, value, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test one fails with random let msg = "Circuit with bit = 1 that selects 1 shouldn't pass"; let bit = BlsScalar::one(); - let value = BlsScalar::random(rng); + let value = BlsScalar::random(&mut rng); let result = BlsScalar::one(); let circuit = TestCircuit::new(bit, value, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test zero fails let msg = "Circuit with bit = 0 that selects value shouldn't pass"; @@ -308,33 +309,33 @@ fn component_select_one() { let value = BlsScalar::zero(); let result = BlsScalar::zero(); let circuit = TestCircuit::new(bit, value, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test zero fails with random let msg = "Circuit with bit = 0 that selects value shouldn't pass"; let bit = BlsScalar::zero(); - let value = BlsScalar::random(rng); + let value = BlsScalar::random(&mut rng); let result = value.clone(); let circuit = TestCircuit::new(bit, value, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test random fails let msg = "Circuit with random result shouldn't pass no matter the selector bit"; let bit = BlsScalar::one(); - let value = BlsScalar::random(rng); - let result = BlsScalar::random(rng); + let value = BlsScalar::random(&mut rng); + let result = BlsScalar::random(&mut rng); let circuit = TestCircuit::new(bit, value, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test random fails let msg = "Circuit with random result shouldn't pass no matter the selector bit"; let bit = BlsScalar::zero(); - let value = BlsScalar::random(rng); - let result = BlsScalar::random(rng); + let value = BlsScalar::random(&mut rng); + let result = BlsScalar::random(&mut rng); let circuit = TestCircuit::new(bit, value, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); } #[test] @@ -380,9 +381,9 @@ fn component_select_zero() { // Compile common circuit descriptions for the prover and verifier to be // used by all tests let label = b"component_select_zero"; - let rng = &mut StdRng::seed_from_u64(0xca11); + let mut rng = StdRng::seed_from_u64(0xca11); let capacity = 1 << 5; - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile"); @@ -393,7 +394,7 @@ fn component_select_zero() { // Test default works: let msg = "Default circuit verification should pass"; let circuit = TestCircuit::default(); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one works let msg = "Circuit with bit = 1 that selects value should pass"; @@ -401,15 +402,15 @@ fn component_select_zero() { let value = BlsScalar::one(); let result = value.clone(); let circuit = TestCircuit::new(bit, value, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one works with random let msg = "Circuit with bit = 1 that selects value should pass"; let bit = BlsScalar::one(); - let value = BlsScalar::random(rng); + let value = BlsScalar::random(&mut rng); let result = value.clone(); let circuit = TestCircuit::new(bit, value, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test zero works let msg = "Circuit with bit = 0 that selects 0 should pass"; @@ -417,24 +418,24 @@ fn component_select_zero() { let value = BlsScalar::one(); let result = BlsScalar::zero(); let circuit = TestCircuit::new(bit, value, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test zero works with random let msg = "Circuit with bit = 0 that selects 0 should pass"; let bit = BlsScalar::zero(); - let value = BlsScalar::random(rng); + let value = BlsScalar::random(&mut rng); let result = BlsScalar::zero(); let circuit = TestCircuit::new(bit, value, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test invalid bit passes (bit should be constrained outside of the // `select` component) let msg = "Circuit with invalid bit can pass"; - let bit = BlsScalar::random(rng); + let bit = BlsScalar::random(&mut rng); let value = BlsScalar::zero(); let result = BlsScalar::zero(); let circuit = TestCircuit::new(bit, value, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one fails let msg = "Circuit with bit = 1 that selects 1 shouldn't pass"; @@ -442,15 +443,15 @@ fn component_select_zero() { let value = BlsScalar::zero(); let result = BlsScalar::one(); let circuit = TestCircuit::new(bit, value, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test one fails with random let msg = "Circuit with bit = 1 that selects 0 shouldn't pass"; let bit = BlsScalar::one(); - let value = BlsScalar::random(rng); + let value = BlsScalar::random(&mut rng); let result = BlsScalar::zero(); let circuit = TestCircuit::new(bit, value, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test zero fails let msg = "Circuit with bit = 0 that selects value shouldn't pass"; @@ -458,31 +459,31 @@ fn component_select_zero() { let value = BlsScalar::one(); let result = BlsScalar::one(); let circuit = TestCircuit::new(bit, value, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test zero fails with random let msg = "Circuit with bit = 0 that selects value shouldn't pass"; let bit = BlsScalar::zero(); - let value = BlsScalar::random(rng); + let value = BlsScalar::random(&mut rng); let result = value.clone(); let circuit = TestCircuit::new(bit, value, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test random fails let msg = "Circuit with random result shouldn't pass no matter the selector bit"; let bit = BlsScalar::one(); - let value = BlsScalar::random(rng); - let result = BlsScalar::random(rng); + let value = BlsScalar::random(&mut rng); + let result = BlsScalar::random(&mut rng); let circuit = TestCircuit::new(bit, value, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test random fails let msg = "Circuit with random result shouldn't pass no matter the selector bit"; let bit = BlsScalar::zero(); - let value = BlsScalar::random(rng); - let result = BlsScalar::random(rng); + let value = BlsScalar::random(&mut rng); + let result = BlsScalar::random(&mut rng); let circuit = TestCircuit::new(bit, value, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); } diff --git a/tests/select_point.rs b/tests/select_point.rs index 17120630..db79c6fe 100644 --- a/tests/select_point.rs +++ b/tests/select_point.rs @@ -5,6 +5,7 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_plonk::prelude::*; +use ff::Field; use rand::rngs::StdRng; use rand::SeedableRng; @@ -69,9 +70,9 @@ fn component_select_point() { // Compile common circuit descriptions for the prover and verifier to be // used by all tests let label = b"component_select_point"; - let rng = &mut StdRng::seed_from_u64(0xce11); + let mut rng = StdRng::seed_from_u64(0xce11); let capacity = 1 << 5; - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile"); @@ -82,7 +83,7 @@ fn component_select_point() { // Test default works: let msg = "Default circuit verification should pass"; let circuit = TestCircuit::default(); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one works let msg = "Circuit with bit = 1 that selects point_a should pass"; @@ -91,18 +92,20 @@ fn component_select_point() { let point_b = JubJubAffine::identity(); let result = point_a.clone(); let circuit = TestCircuit::new(bit, point_a, point_b, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one works with random let msg = "Circuit with bit = 1 that selects point_a should pass"; let bit = BlsScalar::one(); - let point_a: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); - let point_b: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); + let point_a: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); + let point_b: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); let result = point_a.clone(); let circuit = TestCircuit::new(bit, point_a, point_b, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test zero works let msg = "Circuit with bit = 0 that selects point_b should pass"; @@ -111,28 +114,30 @@ fn component_select_point() { let point_b = JubJubAffine::identity(); let result = point_b.clone(); let circuit = TestCircuit::new(bit, point_a, point_b, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test zero works with random let msg = "Circuit with bit = 0 that selects point_b should pass"; let bit = BlsScalar::zero(); - let point_a: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); - let point_b: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); + let point_a: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); + let point_b: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); let result = point_b.clone(); let circuit = TestCircuit::new(bit, point_a, point_b, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test invalid bit passes (bit should be constrained outside of the // `select` component) let msg = "Circuit with invalid bit shouldn't pass"; - let bit = BlsScalar::random(rng); + let bit = BlsScalar::random(&mut rng); let point_a = JubJubAffine::identity(); let point_b = JubJubAffine::identity(); let result = JubJubAffine::identity(); let circuit = TestCircuit::new(bit, point_a, point_b, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one fails let msg = "Circuit with bit = 1 that selects point_b shouldn't pass"; @@ -141,18 +146,20 @@ fn component_select_point() { let point_b = JubJubAffine::identity(); let result = point_b.clone(); let circuit = TestCircuit::new(bit, point_a, point_b, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test one fails with random let msg = "Circuit with bit = 1 that selects point_b shouldn't pass"; let bit = BlsScalar::one(); - let point_a: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); - let point_b: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); + let point_a: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); + let point_b: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); let result = point_b.clone(); let circuit = TestCircuit::new(bit, point_a, point_b, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test zero fails let msg = "Circuit with bit = 0 that selects point_a shouldn't pass"; @@ -161,44 +168,52 @@ fn component_select_point() { let point_b = JubJubAffine::identity(); let result = point_a.clone(); let circuit = TestCircuit::new(bit, point_a, point_b, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test zero fails with random let msg = "Circuit with bit = 0 that selects point_a shouldn't pass"; let bit = BlsScalar::zero(); - let point_a: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); - let point_b: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); + let point_a: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); + let point_b: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); let result = point_a.clone(); let circuit = TestCircuit::new(bit, point_a, point_b, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test random fails let msg = "Circuit with random result shouldn't pass no matter the selector bit"; let bit = BlsScalar::one(); - let point_a: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); - let point_b: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); - let result: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); + let point_a: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); + let point_b: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); + let result: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); let circuit = TestCircuit::new(bit, point_a, point_b, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test random fails let msg = "Circuit with random result shouldn't pass no matter the selector bit"; let bit = BlsScalar::zero(); - let point_a: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); - let point_b: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); - let result: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); + let point_a: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); + let point_b: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); + let result: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); let circuit = TestCircuit::new(bit, point_a, point_b, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); } #[test] @@ -249,9 +264,9 @@ fn component_select_identity() { // Compile common circuit descriptions for the prover and verifier to be // used by all tests let label = b"component_select_one"; - let rng = &mut StdRng::seed_from_u64(0xfee); + let mut rng = StdRng::seed_from_u64(0xfee); let capacity = 1 << 5; - let pp = PublicParameters::setup(capacity, rng) + let pp = PublicParameters::setup(capacity, &mut rng) .expect("Creation of public parameter shouldn't fail"); let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile"); @@ -262,7 +277,7 @@ fn component_select_identity() { // Test default works: let msg = "Default circuit verification should pass"; let circuit = TestCircuit::default(); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one works let msg = "Circuit with bit = 1 that selects point should pass"; @@ -270,16 +285,17 @@ fn component_select_identity() { let point = dusk_jubjub::GENERATOR; let result = point.clone(); let circuit = TestCircuit::new(bit, point, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one works with random let msg = "Circuit with bit = 1 that selects point should pass"; let bit = BlsScalar::one(); - let point: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); + let point: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); let result = point.clone(); let circuit = TestCircuit::new(bit, point, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test zero works let msg = "Circuit with bit = 0 that selects identity should pass"; @@ -287,25 +303,26 @@ fn component_select_identity() { let point = dusk_jubjub::GENERATOR; let result = JubJubAffine::identity(); let circuit = TestCircuit::new(bit, point, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test zero works with random let msg = "Circuit with bit = 0 that selects identity should pass"; let bit = BlsScalar::zero(); - let point: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); + let point: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); let result = JubJubAffine::identity(); let circuit = TestCircuit::new(bit, point, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test invalid bit passes (bit should be constrained outside of the // `select` component) let msg = "Circuit with invalid bit can pass"; - let bit = BlsScalar::random(rng); + let bit = BlsScalar::random(&mut rng); let point = JubJubAffine::identity(); let result = JubJubAffine::identity(); let circuit = TestCircuit::new(bit, point, result); - check_satisfied_circuit(&prover, &verifier, &pi, &circuit, rng, &msg); + check_satisfied_circuit(&prover, &verifier, &pi, &circuit, &mut rng, &msg); // Test one fails let msg = "Circuit with bit = 1 that selects identity shouldn't pass"; @@ -313,16 +330,17 @@ fn component_select_identity() { let point = dusk_jubjub::GENERATOR; let result = JubJubAffine::identity(); let circuit = TestCircuit::new(bit, point, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test one fails with random let msg = "Circuit with bit = 1 that selects identity shouldn't pass"; let bit = BlsScalar::one(); - let point: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); + let point: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); let result = JubJubAffine::identity(); let circuit = TestCircuit::new(bit, point, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test zero fails let msg = "Circuit with bit = 0 that selects point shouldn't pass"; @@ -330,36 +348,41 @@ fn component_select_identity() { let point = dusk_jubjub::GENERATOR; let result = point.clone(); let circuit = TestCircuit::new(bit, point, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test zero fails with random let msg = "Circuit with bit = 0 that selects point shouldn't pass"; let bit = BlsScalar::zero(); - let point: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); + let point: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); let result = point.clone(); let circuit = TestCircuit::new(bit, point, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test random fails let msg = "Circuit with random result shouldn't pass no matter the selector bit"; let bit = BlsScalar::one(); - let point: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); - let result: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); + let point: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); + let result: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); let circuit = TestCircuit::new(bit, point, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); // Test random fails let msg = "Circuit with random result shouldn't pass no matter the selector bit"; let bit = BlsScalar::zero(); - let point: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); - let result: JubJubAffine = - (dusk_jubjub::GENERATOR_EXTENDED * &JubJubScalar::random(rng)).into(); + let point: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); + let result: JubJubAffine = (dusk_jubjub::GENERATOR_EXTENDED + * &JubJubScalar::random(&mut rng)) + .into(); let circuit = TestCircuit::new(bit, point, result); - check_unsatisfied_circuit(&prover, &circuit, rng, msg); + check_unsatisfied_circuit(&prover, &circuit, &mut rng, msg); }