Browse Source

adapt to use the sonobe branch 'reduce-memory-usage'

reduce-memory-usage
arnaucube 4 months ago
parent
commit
4e40220e12
3 changed files with 15 additions and 12 deletions
  1. +4
    -1
      Cargo.toml
  2. +5
    -5
      src/keccak_chain.rs
  3. +6
    -6
      src/sha_chain.rs

+ 4
- 1
Cargo.toml

@ -29,7 +29,10 @@ num-bigint = "0.4.3"
# 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"

+ 5
- 5
src/keccak_chain.rs

@ -43,8 +43,8 @@ mod tests {
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 @@ mod tests {
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 @@ mod tests {
// 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

+ 6
- 6
src/sha_chain.rs

@ -65,8 +65,8 @@ mod tests {
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 @@ mod tests {
&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 @@ mod tests {
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());

Loading…
Cancel
Save