From 0cbdc1a5a1f1c227d35e813292b3c0de9b50eaee Mon Sep 17 00:00:00 2001 From: moana Date: Wed, 11 Oct 2023 18:24:46 +0200 Subject: [PATCH] Update dependencies - Update `dusk-bls12_381` to 0.12 - Update `dusk-jubjub` to 0.13 - Update `dusk-plonk` to 0.16 - Update `dusk-hades` to 0.22 --- CHANGELOG.md | 7 +++++++ Cargo.toml | 11 ++++++----- benches/cipher_decrypt.rs | 14 ++++++++------ benches/cipher_encrypt.rs | 14 ++++++++------ benches/sponge.rs | 17 +++++++++-------- src/cipher.rs | 5 +++-- src/perm_uses.rs | 1 + src/sponge/truncated.rs | 2 +- tests/cipher.rs | 1 + tests/merkle.rs | 7 ++++--- tests/sponge.rs | 25 +++++++++++++------------ 11 files changed, 61 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d2c276..bab9bfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Update `dusk-bls12_381` to 0.12 +- Update `dusk-jubjub` to 0.13 +- Update `dusk-plonk` to 0.16 +- Update `dusk-hades` to 0.22 + ## [0.30.1] - 2023-06-28 ### Fixed diff --git a/Cargo.toml b/Cargo.toml index e75ea68..7fed175 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,22 +18,23 @@ edition = "2021" license = "MPL-2.0" [dependencies] -dusk-bls12_381 = { version = "0.11", default-features = false } -dusk-jubjub = { version = "0.12", default-features = false } +dusk-bls12_381 = { version = "0.12", default-features = false } +dusk-jubjub = { version = "0.13", default-features = false } dusk-bytes = "0.1" -dusk-hades = "0.21" -dusk-plonk = { version = "0.14", default-features = false, features = ["alloc"] } +dusk-hades = "0.22" +dusk-plonk = { version = "0.16", default-features = false, features = ["alloc"] } rkyv = { version = "0.7", optional = true, default-features = false } bytecheck = { version = "0.6", optional = true, default-features = false } [dev-dependencies] criterion = "0.3" rand = { version = "0.8", default-features = false, features = ["getrandom", "std_rng"] } +ff = { version = "0.13", default-features = false } [features] default = [ "dusk-plonk/std", - "dusk-jubjub/std", + "dusk-jubjub/default", "dusk-bls12_381/default", "alloc", ] diff --git a/benches/cipher_decrypt.rs b/benches/cipher_decrypt.rs index ff13a5b..9a31879 100644 --- a/benches/cipher_decrypt.rs +++ b/benches/cipher_decrypt.rs @@ -9,6 +9,7 @@ use dusk_poseidon::cipher::{self, PoseidonCipher}; use criterion::{black_box, criterion_group, criterion_main, Criterion}; use dusk_jubjub::GENERATOR; use dusk_plonk::prelude::*; +use ff::Field; use rand::rngs::StdRng; use rand::SeedableRng; @@ -29,8 +30,9 @@ impl CipherDecrypt { pub fn random(rng: &mut StdRng) -> Self { let shared = GENERATOR.to_niels().mul(&JubJubScalar::random(rng)).into(); - let nonce = BlsScalar::random(rng); - let message = [BlsScalar::random(rng), BlsScalar::random(rng)]; + let nonce = BlsScalar::random(&mut *rng); + let message = + [BlsScalar::random(&mut *rng), BlsScalar::random(&mut *rng)]; let cipher = PoseidonCipher::encrypt(&message, &shared, &nonce); Self { @@ -68,13 +70,13 @@ impl Circuit for CipherDecrypt { fn bench_cipher_decryption(c: &mut Criterion) { // Prepare benchmarks and initialize variables let label = b"cipher decryption benchmark"; - let rng = &mut StdRng::seed_from_u64(0xc001); - let pp = PublicParameters::setup(1 << CAPACITY, rng).unwrap(); + let mut rng = StdRng::seed_from_u64(0xc001); + let pp = PublicParameters::setup(1 << CAPACITY, &mut rng).unwrap(); let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile successfully"); let mut proof = Proof::default(); let public_inputs = Vec::new(); - let circuit = CipherDecrypt::random(rng); + let circuit = CipherDecrypt::random(&mut rng); // Benchmark native cipher decryption c.bench_function("cipher decryption native", |b| { @@ -91,7 +93,7 @@ fn bench_cipher_decryption(c: &mut Criterion) { c.bench_function("cipher decryption proof generation", |b| { b.iter(|| { (proof, _) = prover - .prove(rng, black_box(&circuit)) + .prove(&mut rng, black_box(&circuit)) .expect("Proof generation should succeed"); }) }); diff --git a/benches/cipher_encrypt.rs b/benches/cipher_encrypt.rs index 2109c29..108e21e 100644 --- a/benches/cipher_encrypt.rs +++ b/benches/cipher_encrypt.rs @@ -9,6 +9,7 @@ use dusk_poseidon::cipher::{self, PoseidonCipher}; use criterion::{black_box, criterion_group, criterion_main, Criterion}; use dusk_jubjub::GENERATOR; use dusk_plonk::prelude::*; +use ff::Field; use rand::rngs::StdRng; use rand::SeedableRng; @@ -28,8 +29,9 @@ impl CipherEncrypt { pub fn random(rng: &mut StdRng) -> Self { let shared = GENERATOR.to_niels().mul(&JubJubScalar::random(rng)).into(); - let nonce = BlsScalar::random(rng); - let message = [BlsScalar::random(rng), BlsScalar::random(rng)]; + let nonce = BlsScalar::random(&mut *rng); + let message = + [BlsScalar::random(&mut *rng), BlsScalar::random(&mut *rng)]; Self { shared, @@ -65,13 +67,13 @@ impl Circuit for CipherEncrypt { fn bench_cipher_encryption(c: &mut Criterion) { // Prepare benchmarks and initialize variables let label = b"cipher encryption benchmark"; - let rng = &mut StdRng::seed_from_u64(0xc001); - let pp = PublicParameters::setup(1 << CAPACITY, rng).unwrap(); + let mut rng = StdRng::seed_from_u64(0xc001); + let pp = PublicParameters::setup(1 << CAPACITY, &mut rng).unwrap(); let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile successfully"); let mut proof = Proof::default(); let public_inputs = Vec::new(); - let circuit = CipherEncrypt::random(rng); + let circuit = CipherEncrypt::random(&mut rng); // Benchmark native cipher encryption c.bench_function("cipher encryption native", |b| { @@ -88,7 +90,7 @@ fn bench_cipher_encryption(c: &mut Criterion) { c.bench_function("cipher encryption proof generation", |b| { b.iter(|| { (proof, _) = prover - .prove(rng, black_box(&circuit)) + .prove(&mut rng, black_box(&circuit)) .expect("Proof generation should succeed"); }) }); diff --git a/benches/sponge.rs b/benches/sponge.rs index bed453d..af6dbde 100644 --- a/benches/sponge.rs +++ b/benches/sponge.rs @@ -7,6 +7,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; use dusk_hades::WIDTH; use dusk_plonk::prelude::*; +use ff::Field; use rand::rngs::StdRng; use rand::SeedableRng; @@ -46,18 +47,18 @@ impl Circuit for SpongeCircuit { fn bench_sponge(c: &mut Criterion) { // Prepare benchmarks and initialize variables let label = b"sponge benchmark"; - let rng = &mut StdRng::seed_from_u64(0xc10d); - let pp = PublicParameters::setup(1 << CAPACITY, rng).unwrap(); + let mut rng = StdRng::seed_from_u64(0xc10d); + let pp = PublicParameters::setup(1 << CAPACITY, &mut rng).unwrap(); let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile successfully"); let mut proof = Proof::default(); let public_inputs = Vec::new(); let message = [ - BlsScalar::random(rng), - BlsScalar::random(rng), - BlsScalar::random(rng), - BlsScalar::random(rng), - BlsScalar::random(rng), + BlsScalar::random(&mut rng), + BlsScalar::random(&mut rng), + BlsScalar::random(&mut rng), + BlsScalar::random(&mut rng), + BlsScalar::random(&mut rng), ]; let circuit = SpongeCircuit::new(message); @@ -72,7 +73,7 @@ fn bench_sponge(c: &mut Criterion) { c.bench_function("sponge proof generation", |b| { b.iter(|| { (proof, _) = prover - .prove(rng, black_box(&circuit)) + .prove(&mut rng, black_box(&circuit)) .expect("Proof generation should succeed"); }) }); diff --git a/src/cipher.rs b/src/cipher.rs index 4e01aab..e7f25e5 100644 --- a/src/cipher.rs +++ b/src/cipher.rs @@ -26,6 +26,7 @@ //! use dusk_jubjub::{dhke, JubJubExtended, JubJubScalar, GENERATOR}; //! use dusk_poseidon::cipher::PoseidonCipher; //! use rand::rngs::OsRng; +//! use ff::Field; //! //! fn sender( //! sender_secret: &JubJubScalar, @@ -173,8 +174,8 @@ impl PoseidonCipher { // The size of the message is constant because any absent input is // replaced by zero BlsScalar::from_raw([MESSAGE_CAPACITY as u64, 0, 0, 0]), - secret.get_x(), - secret.get_y(), + secret.get_u(), + secret.get_v(), nonce, ] } diff --git a/src/perm_uses.rs b/src/perm_uses.rs index dda7824..1d98555 100644 --- a/src/perm_uses.rs +++ b/src/perm_uses.rs @@ -30,6 +30,7 @@ pub fn two_outputs(message: BlsScalar) -> [BlsScalar; 2] { #[cfg(test)] mod tests { use super::*; + use ff::Field; use rand::rngs::OsRng; #[test] diff --git a/src/sponge/truncated.rs b/src/sponge/truncated.rs index 4415083..9e27549 100644 --- a/src/sponge/truncated.rs +++ b/src/sponge/truncated.rs @@ -64,5 +64,5 @@ where let h = sponge::gadget(composer, message); // Truncate to 250 bits - composer.append_logic_xor(h, C::ZERO, 250) + composer.append_logic_xor::<125>(h, C::ZERO) } diff --git a/tests/cipher.rs b/tests/cipher.rs index 7237aa8..f967a2c 100644 --- a/tests/cipher.rs +++ b/tests/cipher.rs @@ -15,6 +15,7 @@ use dusk_jubjub::{ }; 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}; diff --git a/tests/merkle.rs b/tests/merkle.rs index c0ecb8c..c7d3f45 100644 --- a/tests/merkle.rs +++ b/tests/merkle.rs @@ -10,6 +10,7 @@ use dusk_plonk::error::Error as PlonkError; use dusk_plonk::prelude::*; use dusk_poseidon::sponge; +use ff::Field; use rand::rngs::StdRng; use rand::SeedableRng; @@ -51,15 +52,15 @@ impl Circuit for MerkleCircuit { #[test] fn merkle_sponge() -> Result<(), PlonkError> { - let mut rng = &mut StdRng::seed_from_u64(0xbeef); + let mut rng = StdRng::seed_from_u64(0xbeef); let label = b"merkle-sponge-tester"; - let pp = PublicParameters::setup(1 << MERKLE_CAPACITY, rng)?; + let pp = PublicParameters::setup(1 << MERKLE_CAPACITY, &mut rng)?; let (prover, verifier) = Compiler::compile::(&pp, label) .expect("Circuit should compile"); let mut input = [BlsScalar::zero(); A]; for scalar in input.iter_mut() { - *scalar = BlsScalar::random(rng); + *scalar = BlsScalar::random(&mut rng); } let expected_output = sponge::merkle::hash(&input); diff --git a/tests/sponge.rs b/tests/sponge.rs index 9a77522..4c97a24 100644 --- a/tests/sponge.rs +++ b/tests/sponge.rs @@ -10,6 +10,7 @@ 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; @@ -127,33 +128,33 @@ fn sponge_hash_test() { .collect(); assert_eq!( - "0xe36f4ea9b858d5c85b02770823c7c5d8253c28787d17f283ca348b906dca8528", - format!("{:#x}", sponge::hash(&test_inputs[..3])) + "0x2885ca6d908b34ca83f2177d78283c25d8c5c7230877025bc8d558b8a94e6fe3", + format!("{:?}", sponge::hash(&test_inputs[..3])) ); assert_eq!( - "0x75ea3265c80d07e608c1f363ea0b4394ff1fa1cbf50b43b14c880a5755f7f755", - format!("{:#x}", sponge::hash(&test_inputs[..4])) + "0x55f7f755570a884cb1430bf5cba11fff94430bea63f3c108e6070dc86532ea75", + format!("{:?}", sponge::hash(&test_inputs[..4])) ); assert_eq!( - "0x533106a0980eff5b01f5ce63a6b0dd87328b318ac6aa600fc28b9a2ab9f88842", - format!("{:#x}", sponge::hash(&test_inputs[..5])) + "0x4288f8b92a9a8bc20f60aac68a318b3287ddb0a663cef5015bff0e98a0063153", + format!("{:?}", sponge::hash(&test_inputs[..5])) ); assert_eq!( - "0x1a815864684fff47c4d279ee4c31ad964c9dc232734e08188554fa27d33e6731", - format!("{:#x}", sponge::hash(&test_inputs[..6])) + "0x31673ed327fa548518084e7332c29d4c96ad314cee79d2c447ff4f686458811a", + format!("{:?}", sponge::hash(&test_inputs[..6])) ); assert_eq!( - "0xa8b936d057df818048e634254719d13970df22926c51e5190c916fcf13dfa25a", - format!("{:#x}", sponge::hash(&test_inputs[..8])) + "0x5aa2df13cf6f910c19e5516c9222df7039d119472534e6488081df57d036b9a8", + format!("{:?}", sponge::hash(&test_inputs[..8])) ); assert_eq!( - "0x982934231a0410c86f9ed1daa46863a5ddae6d250670d27cb21d10739088e30b", - format!("{:#x}", sponge::hash(&test_inputs[..10])) + "0x0be3889073101db27cd27006256daedda56368a4dad19e6fc810041a23342998", + format!("{:?}", sponge::hash(&test_inputs[..10])) ); }