From 9a20fc4e0840e1dcae8add4b496e670fafefa0ff Mon Sep 17 00:00:00 2001 From: arnaucube Date: Wed, 18 Dec 2024 10:11:19 +0100 Subject: [PATCH] upgrade to latest Sonobe version (FCircuit interface updated) --- src/poseidon_chain.rs | 25 +++---------------------- src/sha_chain_offchain.rs | 26 ++------------------------ src/sha_chain_onchain.rs | 26 ++------------------------ 3 files changed, 7 insertions(+), 70 deletions(-) diff --git a/src/poseidon_chain.rs b/src/poseidon_chain.rs index f8943a9..d9658d9 100644 --- a/src/poseidon_chain.rs +++ b/src/poseidon_chain.rs @@ -12,8 +12,8 @@ mod tests { use ark_crypto_primitives::sponge::{ constraints::CryptographicSpongeVar, - poseidon::{constraints::PoseidonSpongeVar, PoseidonConfig, PoseidonSponge}, - Absorb, CryptographicSponge, + poseidon::{constraints::PoseidonSpongeVar, PoseidonConfig}, + Absorb, }; use ark_r1cs_std::fields::fp::FpVar; @@ -49,21 +49,6 @@ mod tests { fn external_inputs_len(&self) -> usize { 0 } - fn step_native( - &self, - _i: usize, - z_i: Vec, - _external_inputs: Vec, - ) -> Result, Error> { - let mut sponge = PoseidonSponge::::new(&self.config); - - let mut v = z_i.clone(); - for _ in 0..HASHES_PER_STEP { - sponge.absorb(&v); - v = sponge.squeeze_field_elements(1); - } - Ok(v) - } fn generate_step_constraints( &self, cs: ConstraintSystemRef, @@ -103,16 +88,12 @@ mod tests { // check that the f_circuit produces valid R1CS constraints use ark_r1cs_std::alloc::AllocVar; use ark_r1cs_std::fields::fp::FpVar; - use ark_r1cs_std::R1CSVar; use ark_relations::r1cs::ConstraintSystem; let cs = ConstraintSystem::::new_ref(); let z_0_var = Vec::>::new_witness(cs.clone(), || Ok(z_0.clone())).unwrap(); - let z_1_var = f_circuit + let _z_1_var = f_circuit .generate_step_constraints(cs.clone(), 1, z_0_var, vec![]) .unwrap(); - // check z_1_var against the native z_1 - let z_1_native = f_circuit.step_native(1, z_0.clone(), vec![]).unwrap(); - assert_eq!(z_1_var.value().unwrap(), z_1_native); // check that the constraint system is satisfied assert!(cs.is_satisfied().unwrap()); println!( diff --git a/src/sha_chain_offchain.rs b/src/sha_chain_offchain.rs index b1d1f1d..08a2ea3 100644 --- a/src/sha_chain_offchain.rs +++ b/src/sha_chain_offchain.rs @@ -10,7 +10,7 @@ mod tests { use ark_pallas::{constraints::GVar, Fr, Projective as G1}; use ark_vesta::{constraints::GVar as GVar2, Projective as G2}; - use ark_crypto_primitives::crh::sha256::{constraints::Sha256Gadget, digest::Digest, Sha256}; + use ark_crypto_primitives::crh::sha256::constraints::Sha256Gadget; use ark_ff::PrimeField; use ark_r1cs_std::fields::fp::FpVar; use ark_r1cs_std::{ @@ -30,8 +30,6 @@ mod tests { Error, FoldingScheme, }; - use crate::utils::tests::*; - /// Test circuit to be folded #[derive(Clone, Copy, Debug)] pub struct SHA256FoldStepCircuit { @@ -50,22 +48,6 @@ mod tests { fn external_inputs_len(&self) -> usize { 0 } - fn step_native( - &self, - _i: usize, - z_i: Vec, - _external_inputs: Vec, - ) -> Result, Error> { - let mut b = f_vec_to_bytes(z_i.to_vec()); - - for _ in 0..HASHES_PER_STEP { - let mut sha256 = Sha256::default(); - sha256.update(b); - b = sha256.finalize().to_vec(); - } - - bytes_to_f_vec(b.to_vec()) // z_{i+1} - } fn generate_step_constraints( &self, _cs: ConstraintSystemRef, @@ -115,16 +97,12 @@ mod tests { // check that the f_circuit produces valid R1CS constraints use ark_r1cs_std::alloc::AllocVar; use ark_r1cs_std::fields::fp::FpVar; - use ark_r1cs_std::R1CSVar; use ark_relations::r1cs::ConstraintSystem; let cs = ConstraintSystem::::new_ref(); let z_0_var = Vec::>::new_witness(cs.clone(), || Ok(z_0.clone())).unwrap(); - let z_1_var = f_circuit + let _z_1_var = f_circuit .generate_step_constraints(cs.clone(), 1, z_0_var, vec![]) .unwrap(); - // check z_1_var against the native z_1 - let z_1_native = f_circuit.step_native(1, z_0.clone(), vec![]).unwrap(); - assert_eq!(z_1_var.value().unwrap(), z_1_native); // check that the constraint system is satisfied assert!(cs.is_satisfied().unwrap()); println!( diff --git a/src/sha_chain_onchain.rs b/src/sha_chain_onchain.rs index d113e60..f8822a0 100644 --- a/src/sha_chain_onchain.rs +++ b/src/sha_chain_onchain.rs @@ -19,7 +19,7 @@ mod tests { use std::time::Instant; - use ark_crypto_primitives::crh::sha256::{constraints::Sha256Gadget, digest::Digest, Sha256}; + use ark_crypto_primitives::crh::sha256::constraints::Sha256Gadget; use ark_r1cs_std::fields::fp::FpVar; use ark_r1cs_std::{ boolean::Boolean, @@ -48,8 +48,6 @@ mod tests { NovaCycleFoldVerifierKey, }; - use crate::utils::tests::*; - /// Test circuit to be folded #[derive(Clone, Copy, Debug)] pub struct SHA256FoldStepCircuit { @@ -68,22 +66,6 @@ mod tests { fn external_inputs_len(&self) -> usize { 0 } - fn step_native( - &self, - _i: usize, - z_i: Vec, - _external_inputs: Vec, - ) -> Result, Error> { - let mut b = f_vec_to_bytes(z_i.to_vec()); - - for _ in 0..HASHES_PER_STEP { - let mut sha256 = Sha256::default(); - sha256.update(b); - b = sha256.finalize().to_vec(); - } - - bytes_to_f_vec(b.to_vec()) // z_{i+1} - } fn generate_step_constraints( &self, _cs: ConstraintSystemRef, @@ -133,16 +115,12 @@ mod tests { // check that the f_circuit produces valid R1CS constraints use ark_r1cs_std::alloc::AllocVar; use ark_r1cs_std::fields::fp::FpVar; - use ark_r1cs_std::R1CSVar; use ark_relations::r1cs::ConstraintSystem; let cs = ConstraintSystem::::new_ref(); let z_0_var = Vec::>::new_witness(cs.clone(), || Ok(z_0.clone())).unwrap(); - let z_1_var = f_circuit + let _z_1_var = f_circuit .generate_step_constraints(cs.clone(), 1, z_0_var, vec![]) .unwrap(); - // check z_1_var against the native z_1 - let z_1_native = f_circuit.step_native(1, z_0.clone(), vec![]).unwrap(); - assert_eq!(z_1_var.value().unwrap(), z_1_native); // check that the constraint system is satisfied assert!(cs.is_satisfied().unwrap()); println!(