diff --git a/Cargo.toml b/Cargo.toml index b3378b8..39a68f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,8 @@ license = "MPL-2.0" dusk-bls12_381 = { version = "0.13", default-features = false } dusk-jubjub = { version = "0.14", default-features = false } dusk-bytes = "0.1" -dusk-hades = "0.23" -dusk-plonk = { version = "0.18", default-features = false, features = ["alloc"] } +dusk-hades = "0.24" +dusk-plonk = { version = "0.19", default-features = false, features = ["alloc"] } rkyv = { version = "0.7", optional = true, default-features = false } bytecheck = { version = "0.6", optional = true, default-features = false } diff --git a/src/cipher/zk.rs b/src/cipher/zk.rs index c014ef4..ae4998a 100644 --- a/src/cipher/zk.rs +++ b/src/cipher/zk.rs @@ -11,15 +11,12 @@ use dusk_plonk::prelude::*; impl PoseidonCipher { /// Returns the initial state of the encryption within a composer circuit - pub fn initial_state_circuit( - composer: &mut C, + pub fn initial_state_circuit( + composer: &mut Composer, ks0: Witness, ks1: Witness, nonce: Witness, - ) -> [Witness; dusk_hades::WIDTH] - where - C: Composer, - { + ) -> [Witness; dusk_hades::WIDTH] { let domain = BlsScalar::from_raw([0x100000000u64, 0, 0, 0]); let domain = composer.append_constant(domain); @@ -35,19 +32,16 @@ impl PoseidonCipher { /// and jubjub, perform the encryption of the message. /// /// The returned set of variables is the cipher text -pub fn encrypt( - composer: &mut C, +pub fn encrypt( + composer: &mut Composer, shared_secret: &WitnessPoint, nonce: Witness, message: &[Witness], -) -> [Witness; PoseidonCipher::cipher_size()] -where - C: Composer, -{ +) -> [Witness; PoseidonCipher::cipher_size()] { let ks0 = *shared_secret.x(); let ks1 = *shared_secret.y(); - let mut cipher = [C::ZERO; PoseidonCipher::cipher_size()]; + let mut cipher = [Composer::ZERO; PoseidonCipher::cipher_size()]; let mut state = PoseidonCipher::initial_state_circuit(composer, ks0, ks1, nonce); @@ -58,7 +52,7 @@ where let x = if i < message.len() { message[i] } else { - C::ZERO + Composer::ZERO }; let constraint = @@ -79,19 +73,16 @@ where /// and jubjub, perform the decryption of the cipher. /// /// The returned set of variables is the original message -pub fn decrypt( - composer: &mut C, +pub fn decrypt( + composer: &mut Composer, shared_secret: &WitnessPoint, nonce: Witness, cipher: &[Witness], -) -> [Witness; PoseidonCipher::capacity()] -where - C: Composer, -{ +) -> [Witness; PoseidonCipher::capacity()] { let ks0 = *shared_secret.x(); let ks1 = *shared_secret.y(); - let mut message = [C::ZERO; PoseidonCipher::capacity()]; + let mut message = [Composer::ZERO; PoseidonCipher::capacity()]; let mut state = PoseidonCipher::initial_state_circuit(composer, ks0, ks1, nonce); diff --git a/src/sponge.rs b/src/sponge.rs index 19ffa3d..34fd42c 100644 --- a/src/sponge.rs +++ b/src/sponge.rs @@ -88,11 +88,8 @@ pub fn hash(messages: &[BlsScalar]) -> BlsScalar { /// /// [`hash`]: crate::sponge::hash #[cfg(feature = "alloc")] -pub fn gadget(composer: &mut C, messages: &[Witness]) -> Witness -where - C: Composer, -{ - let mut state = [C::ZERO; WIDTH]; +pub fn gadget(composer: &mut Composer, messages: &[Witness]) -> Witness { + let mut state = [Composer::ZERO; WIDTH]; let l = messages.len(); let m = l / (WIDTH - 1); diff --git a/src/sponge/merkle.rs b/src/sponge/merkle.rs index 414b3c9..938daa2 100644 --- a/src/sponge/merkle.rs +++ b/src/sponge/merkle.rs @@ -73,15 +73,12 @@ pub fn hash(messages: &[BlsScalar; A]) -> BlsScalar { /// /// The returned value is the witness of the hash of the levels. #[cfg(feature = "alloc")] -pub fn gadget( - composer: &mut C, +pub fn gadget( + composer: &mut Composer, messages: &[Witness; A], -) -> Witness -where - C: Composer, -{ +) -> Witness { // initialize the state with the capacity - let mut state = [C::ZERO; WIDTH]; + let mut state = [Composer::ZERO; WIDTH]; state[0] = composer.append_witness(BlsScalar::from(tag::())); messages.chunks(WIDTH - 1).for_each(|chunk| { diff --git a/src/sponge/truncated.rs b/src/sponge/truncated.rs index 9e27549..debd739 100644 --- a/src/sponge/truncated.rs +++ b/src/sponge/truncated.rs @@ -57,12 +57,9 @@ pub fn hash(messages: &[BlsScalar]) -> JubJubScalar { /// /// [`hash`]: crate::sponge::hash #[cfg(feature = "alloc")] -pub fn gadget(composer: &mut C, message: &[Witness]) -> Witness -where - C: Composer, -{ +pub fn gadget(composer: &mut Composer, message: &[Witness]) -> Witness { let h = sponge::gadget(composer, message); // Truncate to 250 bits - composer.append_logic_xor::<125>(h, C::ZERO) + composer.append_logic_xor::<125>(h, Composer::ZERO) } diff --git a/tests/cipher.rs b/tests/cipher.rs index f967a2c..3141594 100644 --- a/tests/cipher.rs +++ b/tests/cipher.rs @@ -13,12 +13,12 @@ use dusk_jubjub::{ dhke, JubJubAffine, JubJubExtended, JubJubScalar, GENERATOR, GENERATOR_EXTENDED, }; -use dusk_plonk::error::Error as PlonkError; use dusk_poseidon::cipher::{self, PoseidonCipher}; use ff::Field; use rand::rngs::{OsRng, StdRng}; use rand::{RngCore, SeedableRng}; +use dusk_plonk::prelude::Error as PlonkError; use dusk_plonk::prelude::*; fn gen() -> ( @@ -168,10 +168,7 @@ impl<'a> Default for TestCipherCircuit<'a> { } impl<'a> Circuit for TestCipherCircuit<'a> { - fn circuit(&self, composer: &mut C) -> Result<(), PlonkError> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), PlonkError> { let nonce = composer.append_witness(self.nonce); let secret = composer.append_witness(self.secret); @@ -179,7 +176,7 @@ impl<'a> Circuit for TestCipherCircuit<'a> { let shared = composer.component_mul_point(secret, public); - let mut message_circuit = [C::ZERO; PoseidonCipher::capacity()]; + let mut message_circuit = [Composer::ZERO; PoseidonCipher::capacity()]; self.message .iter() diff --git a/tests/merkle.rs b/tests/merkle.rs index c7d3f45..c3d3c26 100644 --- a/tests/merkle.rs +++ b/tests/merkle.rs @@ -7,7 +7,7 @@ #![cfg(feature = "alloc")] #![cfg(feature = "merkle")] -use dusk_plonk::error::Error as PlonkError; +use dusk_plonk::prelude::Error as PlonkError; use dusk_plonk::prelude::*; use dusk_poseidon::sponge; use ff::Field; @@ -30,11 +30,8 @@ impl MerkleCircuit { } impl Circuit for MerkleCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), PlonkError> - where - C: Composer, - { - let mut input_witnesses = [C::ZERO; A]; + fn circuit(&self, composer: &mut Composer) -> Result<(), PlonkError> { + let mut input_witnesses = [Composer::ZERO; A]; for (i, witness) in input_witnesses.iter_mut().enumerate() { *witness = composer.append_witness(self.input[i]); } diff --git a/tests/sponge.rs b/tests/sponge.rs index 4c97a24..35589e2 100644 --- a/tests/sponge.rs +++ b/tests/sponge.rs @@ -8,12 +8,12 @@ use dusk_bls12_381::BlsScalar; use dusk_bytes::ParseHexStr; -use dusk_plonk::error::Error as PlonkError; use dusk_poseidon::sponge; use ff::Field; use rand::rngs::{OsRng, StdRng}; use rand::SeedableRng; +use dusk_plonk::prelude::Error as PlonkError; use dusk_plonk::prelude::*; const TEST_INPUTS: [&str; 32] = [ @@ -78,11 +78,8 @@ impl TestSpongeCircuit { } impl Circuit for TestSpongeCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), PlonkError> - where - C: Composer, - { - let mut i_var = vec![C::ZERO; self.input.len()]; + fn circuit(&self, composer: &mut Composer) -> Result<(), PlonkError> { + let mut i_var = vec![Composer::ZERO; self.input.len()]; self.input.iter().zip(i_var.iter_mut()).for_each(|(i, v)| { *v = composer.append_witness(*i); }); @@ -173,10 +170,7 @@ impl TestTruncatedCircuit { } impl Circuit for TestTruncatedCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), PlonkError> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), PlonkError> { let h = sponge::truncated::hash(self.input.as_slice()); let p = JubJubAffine::from(dusk_jubjub::GENERATOR_EXTENDED * h); let p = composer.append_point(p);