Skip to content

Commit

Permalink
(wip) add recursive_snark test
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenciak committed Feb 13, 2024
1 parent 5456b3c commit e36efdb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/cyclefold/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ mod tests {
.iter()
.map(|b| Some(*b))
.collect::<Option<Vec<_>>>()
.map(|v| v.try_into().unwrap());
.map(|mut vec| {
vec.resize_with(128, || false);
vec.try_into().unwrap()
});

let circuit: CyclefoldCircuit<Dual<E1>> = CyclefoldCircuit::new(Some(C_1), Some(C_2), r_bits);

Expand Down
8 changes: 7 additions & 1 deletion src/cyclefold/nifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ where
),
NovaError,
> {
let arity = U1.X.len();

if arity != U2.X.len() {
return Err(NovaError::InvalidInputLength);
}

let mut ro = E2::RO::new(
ro_consts.clone(),
1 + NUM_FE_IN_EMULATED_POINT + 2 + NUM_FE_IN_EMULATED_POINT, // pp_digest + u.W + u.X + T
1 + NUM_FE_IN_EMULATED_POINT + arity + NUM_FE_IN_EMULATED_POINT, // pp_digest + u.W + u.X + T
);

ro.absorb(*pp_digest);
Expand Down
10 changes: 5 additions & 5 deletions src/cyclefold/nova_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ mod test {

use super::*;

fn test_circuit_size_with<E>()
fn test_augmented_circuit_size_with<E>()
where
E: CurveCycleEquipped,
{
Expand Down Expand Up @@ -552,9 +552,9 @@ mod test {
}

#[test]
fn test_circuit_size() {
test_circuit_size_with::<PallasEngine>();
test_circuit_size_with::<Secp256k1Engine>();
test_circuit_size_with::<Bn256Engine>();
fn test_augmented_circuit_size() {
test_augmented_circuit_size_with::<PallasEngine>();
test_augmented_circuit_size_with::<Secp256k1Engine>();
test_augmented_circuit_size_with::<Bn256Engine>();
}
}
58 changes: 57 additions & 1 deletion src/cyclefold/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,5 +526,61 @@ where

#[cfg(test)]
mod test {
// use super::*;
use std::marker::PhantomData;

use bellpepper_core::num::AllocatedNum;

use super::*;
use crate::{
provider::{Bn256Engine, PallasEngine, Secp256k1Engine},
traits::snark::default_ck_hint,
};

#[derive(Clone)]
struct SquareCircuit<F> {
_p: PhantomData<F>,
}

impl<F: PrimeField> StepCircuit<F> for SquareCircuit<F> {
fn arity(&self) -> usize {
1
}

fn synthesize<CS: ConstraintSystem<F>>(
&self,
cs: &mut CS,
z: &[AllocatedNum<F>],
) -> Result<Vec<AllocatedNum<F>>, SynthesisError> {
let x = &z[0];
let x_sq = x.square(cs.namespace(|| "x_sq"))?;

Ok(vec![x_sq])
}
}

fn test_trivial_cyclefold_prove_verify_with<E: CurveCycleEquipped>() {
let num_steps = 1;
let primary_circuit = SquareCircuit::<E::Scalar> { _p: PhantomData };

let pp = PublicParams::<E>::setup(&primary_circuit, &*default_ck_hint(), &*default_ck_hint());

let z0 = vec![E::Scalar::from(2u64)];

let mut recursive_snark = RecursiveSNARK::new(&pp, &primary_circuit, &z0).unwrap();

let res = recursive_snark.prove_step(&pp, &primary_circuit);

assert!(res.is_ok());

let res = recursive_snark.verify(&pp, num_steps, &z0);

assert!(res.is_ok());
}

#[test]
fn test_cyclefold_prove_verify() {
test_trivial_cyclefold_prove_verify_with::<PallasEngine>();
test_trivial_cyclefold_prove_verify_with::<Bn256Engine>();
test_trivial_cyclefold_prove_verify_with::<Secp256k1Engine>();
}
}

0 comments on commit e36efdb

Please sign in to comment.