From 44899140ddcb92fe8e17911528a3c5ea5c25114f Mon Sep 17 00:00:00 2001 From: arnaucube Date: Mon, 16 Dec 2024 09:28:34 +0100 Subject: [PATCH] update to latest Sonobe version & arkworks v0.5.0 --- Cargo.toml | 38 ++++++++++------------------ src/naive_approach_poseidon_chain.rs | 8 ++---- src/naive_approach_sha_chain.rs | 10 +++++--- src/sha_chain_offchain.rs | 10 +++++--- src/sha_chain_onchain.rs | 10 +++++--- 5 files changed, 37 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1879369..7908f17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,23 +6,23 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ark-groth16 = { version = "^0.4.0" } -ark-pallas = {version="0.4.0", features=["r1cs"]} -ark-vesta = {version="0.4.0", features=["r1cs"]} -ark-bn254 = { version = "0.4.0", features = ["r1cs"] } -ark-grumpkin = {version="0.4.0", features=["r1cs"]} -ark-ec = "0.4.1" -ark-ff = "0.4.1" -ark-r1cs-std = { version = "0.4.0", default-features = false } -ark-relations = { version = "0.4.0", default-features = false } -ark-snark = { version = "^0.4.0", default-features = false } -ark-poly-commit = "^0.4.0" -ark-crypto-primitives = { version = "^0.4.0", default-features = false, features = [ +ark-groth16 = { version = "^0.5.0" } +ark-pallas = {version="0.5.0", features=["r1cs"]} +ark-vesta = {version="0.5.0", features=["r1cs"]} +ark-bn254 = { version = "0.5.0", features = ["r1cs"] } +ark-grumpkin = {version="0.5.0", features=["r1cs"]} +ark-ec = "0.5.0" +ark-ff = "0.5.0" +ark-r1cs-std = { version = "0.5.0", default-features = false } +ark-relations = { version = "0.5.0", default-features = false } +ark-snark = { version = "^0.5.0", default-features = false } +ark-poly-commit = "^0.5.0" +ark-crypto-primitives = { version = "^0.5.0", default-features = false, features = [ "r1cs", "sponge", "crh", ] } -ark-std = "0.4.0" +ark-std = "0.5.0" color-eyre = "0.6.2" num-bigint = "0.4.3" # Note: for testing purposes we use the 'light-test' feature when importing @@ -30,7 +30,7 @@ num-bigint = "0.4.3" # this feature (but then the DeciderETH circuit is bigger and takes more time # to compute). folding-schemes = { git = "https://github.com/privacy-scaling-explorations/sonobe", package = "folding-schemes", features=["light-test"]} -folding-schemes-circom = { git = "https://github.com/privacy-scaling-explorations/sonobe", package = "frontends", optional=true} +folding-schemes-circom = { git = "https://github.com/privacy-scaling-explorations/sonobe", package = "experimental-frontends", optional=true} solidity-verifiers = { git = "https://github.com/privacy-scaling-explorations/sonobe", package = "solidity-verifiers"} serde = "1.0.198" serde_json = "1.0.116" @@ -45,13 +45,3 @@ rand = "0.8.5" [features] default = [] experimental-frontends = ["dep:folding-schemes-circom"] - - -[patch.crates-io] -# patch ark_curves to use a cherry-picked version which contains -# bn254::constraints & grumpkin for v0.4.0 (once arkworks v0.5.0 is released -# this will no longer be needed) -ark-bn254 = { git = "https://github.com/arnaucube/ark-curves-cherry-picked", branch="cherry-pick"} -ark-grumpkin = { git = "https://github.com/arnaucube/ark-curves-cherry-picked", branch="cherry-pick"} -ark-circom = { git = "https://github.com/arnaucube/circom-compat" } -ark-r1cs-std = { git = "https://github.com/winderica/r1cs-std", branch="cherry-pick" } diff --git a/src/naive_approach_poseidon_chain.rs b/src/naive_approach_poseidon_chain.rs index 8373401..2cdc4ee 100644 --- a/src/naive_approach_poseidon_chain.rs +++ b/src/naive_approach_poseidon_chain.rs @@ -15,19 +15,16 @@ mod tests { use ark_crypto_primitives::sponge::{ constraints::CryptographicSpongeVar, poseidon::{constraints::PoseidonSpongeVar, PoseidonConfig, PoseidonSponge}, - Absorb, CryptographicSponge, + CryptographicSponge, }; use ark_r1cs_std::fields::fp::FpVar; use ark_r1cs_std::{alloc::AllocVar, eq::EqGadget}; - use ark_r1cs_std::{bits::uint8::UInt8, boolean::Boolean, ToBitsGadget, ToBytesGadget}; use ark_relations::r1cs::{ ConstraintSynthesizer, ConstraintSystem, ConstraintSystemRef, SynthesisError, }; use folding_schemes::transcript::poseidon::poseidon_canonical_config; - use crate::utils::tests::*; - /// Test circuit to be folded #[derive(Clone, Debug)] pub struct PoseidonChainCircuit { @@ -66,9 +63,8 @@ mod tests { hashes_per_step: usize, ) -> Vec { let mut z_i: Vec = z_0.clone(); + let mut sponge = PoseidonSponge::::new(&poseidon_config); for _ in 0..n_steps { - let mut sponge = PoseidonSponge::::new(&poseidon_config); - for _ in 0..hashes_per_step { sponge.absorb(&z_i); z_i = sponge.squeeze_field_elements(1); diff --git a/src/naive_approach_sha_chain.rs b/src/naive_approach_sha_chain.rs index 840647f..aac7757 100644 --- a/src/naive_approach_sha_chain.rs +++ b/src/naive_approach_sha_chain.rs @@ -15,7 +15,11 @@ mod tests { use ark_crypto_primitives::crh::sha256::{constraints::Sha256Gadget, digest::Digest, Sha256}; use ark_r1cs_std::fields::fp::FpVar; use ark_r1cs_std::{alloc::AllocVar, eq::EqGadget}; - use ark_r1cs_std::{bits::uint8::UInt8, boolean::Boolean, ToBitsGadget, ToBytesGadget}; + use ark_r1cs_std::{ + boolean::Boolean, + convert::{ToBitsGadget, ToBytesGadget}, + uint8::UInt8, + }; use ark_relations::r1cs::{ ConstraintSynthesizer, ConstraintSystem, ConstraintSystemRef, SynthesisError, }; @@ -47,7 +51,7 @@ mod tests { for _ in 0..HASHES_PER_STEP { let mut sha256_var = Sha256Gadget::default(); sha256_var.update(&b).unwrap(); - b = sha256_var.finalize()?.to_bytes()?; + b = sha256_var.finalize()?.to_bytes_le()?; } // update z_i = z_{i+1} @@ -55,7 +59,7 @@ mod tests { .iter() .map(|e| { let bits = e.to_bits_le().unwrap(); - Boolean::::le_bits_to_fp_var(&bits).unwrap() + Boolean::::le_bits_to_fp(&bits).unwrap() }) .collect(); } diff --git a/src/sha_chain_offchain.rs b/src/sha_chain_offchain.rs index cf23750..b1d1f1d 100644 --- a/src/sha_chain_offchain.rs +++ b/src/sha_chain_offchain.rs @@ -13,7 +13,11 @@ mod tests { use ark_crypto_primitives::crh::sha256::{constraints::Sha256Gadget, digest::Digest, Sha256}; use ark_ff::PrimeField; use ark_r1cs_std::fields::fp::FpVar; - use ark_r1cs_std::{bits::uint8::UInt8, boolean::Boolean, ToBitsGadget, ToBytesGadget}; + use ark_r1cs_std::{ + boolean::Boolean, + convert::{ToBitsGadget, ToBytesGadget}, + uint8::UInt8, + }; use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; use std::marker::PhantomData; use std::time::Instant; @@ -77,14 +81,14 @@ mod tests { for _ in 0..HASHES_PER_STEP { let mut sha256_var = Sha256Gadget::default(); sha256_var.update(&b).unwrap(); - b = sha256_var.finalize()?.to_bytes()?; + b = sha256_var.finalize()?.to_bytes_le()?; } let z_i1: Vec> = b .iter() .map(|e| { let bits = e.to_bits_le().unwrap(); - Boolean::::le_bits_to_fp_var(&bits).unwrap() + Boolean::::le_bits_to_fp(&bits).unwrap() }) .collect(); diff --git a/src/sha_chain_onchain.rs b/src/sha_chain_onchain.rs index 8f37288..d113e60 100644 --- a/src/sha_chain_onchain.rs +++ b/src/sha_chain_onchain.rs @@ -21,7 +21,11 @@ mod tests { use ark_crypto_primitives::crh::sha256::{constraints::Sha256Gadget, digest::Digest, Sha256}; use ark_r1cs_std::fields::fp::FpVar; - use ark_r1cs_std::{bits::uint8::UInt8, boolean::Boolean, ToBitsGadget, ToBytesGadget}; + use ark_r1cs_std::{ + boolean::Boolean, + convert::{ToBitsGadget, ToBytesGadget}, + uint8::UInt8, + }; use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; use std::marker::PhantomData; @@ -95,14 +99,14 @@ mod tests { for _ in 0..HASHES_PER_STEP { let mut sha256_var = Sha256Gadget::default(); sha256_var.update(&b).unwrap(); - b = sha256_var.finalize()?.to_bytes()?; + b = sha256_var.finalize()?.to_bytes_le()?; } let z_i1: Vec> = b .iter() .map(|e| { let bits = e.to_bits_le().unwrap(); - Boolean::::le_bits_to_fp_var(&bits).unwrap() + Boolean::::le_bits_to_fp(&bits).unwrap() }) .collect();