arnaucube
arnaucube/hash-chain-sonobePublic Self-hosted repository
adapt to use the sonobe branch 'reduce-memory-usage'
arnaucube root@arnaucube.com
Thu, 08 Aug 2024 23:28:35 +0200
commit

4e40220e124eeb588f35f547fcdc16b6266cb293

parent

b77cb532cf7819ab08e15a66206001a71348e0ac

3 files changed, 15 insertions(+), 12 deletions(-)

jump to
M Cargo.toml → Cargo.toml

@@ -29,7 +29,10 @@ # Note: for testing purposes we use the 'light-test' feature when importing

# Sonobe's folding-schemes, but for a real-world usage it must be used without # 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 = { git = "https://github.com/privacy-scaling-explorations/sonobe", package = "folding-schemes", features=["light-test"]} + +# note: this branch uses the 'reduce-memory-usage' branch from sonobe: +folding-schemes = { git = "https://github.com/privacy-scaling-explorations/sonobe", package = "folding-schemes", features=["light-test"], branch="reduce-memory-usage" } solidity-verifiers = { git = "https://github.com/privacy-scaling-explorations/sonobe", package = "solidity-verifiers"} serde = "1.0.198" serde_json = "1.0.116"
M src/keccak_chain.rs → src/keccak_chain.rs

@@ -43,8 +43,8 @@ // check the Circom values.

use tiny_keccak::{Hasher, Keccak}; fn rust_native_step<F: PrimeField>( _i: usize, - z_i: Vec<F>, - _external_inputs: Vec<F>, + z_i: &[F], + _external_inputs: &[F], ) -> Result<Vec<F>, Error> { let b = f_vec_bits_to_bytes(z_i.to_vec()); let mut h = Keccak::v256();

@@ -84,10 +84,10 @@ use ark_relations::r1cs::ConstraintSystem;

let cs = ConstraintSystem::<Fr>::new_ref(); let z_0_var = Vec::<FpVar<Fr>>::new_witness(cs.clone(), || Ok(z_0.clone())).unwrap(); let z_1_var = f_circuit - .generate_step_constraints(cs.clone(), 1, z_0_var, vec![]) + .generate_step_constraints(cs.clone(), 1, &z_0_var, &[]) .unwrap(); // check z_1_var against the native z_1 - let z_1_native = f_circuit.step_native(1, z_0.clone(), vec![]).unwrap(); + let z_1_native = f_circuit.step_native(1, &z_0, &[]).unwrap(); assert_eq!(z_1_var.value().unwrap(), z_1_native); // check that the constraint system is satisfied assert!(cs.is_satisfied().unwrap());

@@ -141,7 +141,7 @@

// perform the hash chain natively in rust (which uses a rust Keccak256 library) let mut z_i_native = z_0.clone(); for i in 0..n_steps { - z_i_native = rust_native_step(i, z_i_native, vec![]).unwrap(); + z_i_native = rust_native_step(i, &z_i_native, &[]).unwrap(); } // check that the value of the last folding state (nova.z_i) computed through folding, is // equal to the natively computed hash using the rust_native_step method
M src/sha_chain.rs → src/sha_chain.rs

@@ -65,8 +65,8 @@ // check the Circom values.

fn step_native( &self, _i: usize, - z_i: Vec<F>, - _external_inputs: Vec<F>, + z_i: &[F], + _external_inputs: &[F], ) -> Result<Vec<F>, Error> { let mut b = f_vec_to_bytes(z_i.to_vec());

@@ -82,8 +82,8 @@ fn generate_step_constraints(

&self, _cs: ConstraintSystemRef<F>, _i: usize, - z_i: Vec<FpVar<F>>, - _external_inputs: Vec<FpVar<F>>, + z_i: &[FpVar<F>], + _external_inputs: &[FpVar<F>], ) -> Result<Vec<FpVar<F>>, SynthesisError> { let mut b: Vec<UInt8<F>> = z_i .iter()

@@ -132,10 +132,10 @@ use ark_relations::r1cs::ConstraintSystem;

let cs = ConstraintSystem::<Fr>::new_ref(); let z_0_var = Vec::<FpVar<Fr>>::new_witness(cs.clone(), || Ok(z_0.clone())).unwrap(); let z_1_var = f_circuit - .generate_step_constraints(cs.clone(), 1, z_0_var, vec![]) + .generate_step_constraints(cs.clone(), 1, &z_0_var, &[]) .unwrap(); // check z_1_var against the native z_1 - let z_1_native = f_circuit.step_native(1, z_0.clone(), vec![]).unwrap(); + let z_1_native = f_circuit.step_native(1, &z_0, &[]).unwrap(); assert_eq!(z_1_var.value().unwrap(), z_1_native); // check that the constraint system is satisfied assert!(cs.is_satisfied().unwrap());