mirror of
https://github.com/arnaucube/sonobe.git
synced 2026-01-11 08:21:37 +01:00
Add external inputs logic to F function/circuit. Add an example of usage with external inputs too. (#78)
* Add external inputs logic to F function/circuit. Add an example of usage with external inputs too. * Add examples run into CI
This commit is contained in:
@@ -96,7 +96,7 @@ impl<C: CurveGroup> LCCCS<C> {
|
||||
w: &Witness<C::ScalarField>,
|
||||
) -> Result<(), Error> {
|
||||
// check that C is the commitment of w. Notice that this is not verifying a Pedersen
|
||||
// opening, but checking that the Commmitment comes from committing to the witness.
|
||||
// opening, but checking that the Commitment comes from committing to the witness.
|
||||
if self.C != Pedersen::<C>::commit(pedersen_params, &w.w, &w.r_w)? {
|
||||
return Err(Error::NotSatisfied);
|
||||
}
|
||||
|
||||
@@ -245,6 +245,7 @@ pub struct AugmentedFCircuit<
|
||||
pub _gc2: PhantomData<GC2>,
|
||||
pub poseidon_config: PoseidonConfig<CF1<C1>>,
|
||||
pub i: Option<CF1<C1>>,
|
||||
pub i_usize: Option<usize>,
|
||||
pub z_0: Option<Vec<C1::ScalarField>>,
|
||||
pub z_i: Option<Vec<C1::ScalarField>>,
|
||||
pub u_i: Option<CommittedInstance<C1>>,
|
||||
@@ -278,6 +279,7 @@ where
|
||||
_gc2: PhantomData,
|
||||
poseidon_config: poseidon_config.clone(),
|
||||
i: None,
|
||||
i_usize: None,
|
||||
z_0: None,
|
||||
z_i: None,
|
||||
u_i: None,
|
||||
@@ -349,7 +351,10 @@ where
|
||||
)?;
|
||||
|
||||
// get z_{i+1} from the F circuit
|
||||
let z_i1 = self.F.generate_step_constraints(cs.clone(), z_i.clone())?;
|
||||
let i_usize = self.i_usize.unwrap_or(0);
|
||||
let z_i1 = self
|
||||
.F
|
||||
.generate_step_constraints(cs.clone(), i_usize, z_i.clone())?;
|
||||
|
||||
let zero = FpVar::<CF1<C1>>::new_constant(cs.clone(), CF1::<C1>::zero())?;
|
||||
let is_not_basecase = i.is_neq(&zero)?;
|
||||
|
||||
@@ -508,7 +508,7 @@ pub mod tests {
|
||||
let circuit = WrapperCircuit::<Fr, CubicFCircuit<Fr>> {
|
||||
FC: cubic_circuit,
|
||||
z_i: Some(z_i.clone()),
|
||||
z_i1: Some(cubic_circuit.step_native(z_i).unwrap()),
|
||||
z_i1: Some(cubic_circuit.step_native(0, z_i).unwrap()),
|
||||
};
|
||||
|
||||
test_relaxed_r1cs_gadget(circuit);
|
||||
@@ -551,7 +551,7 @@ pub mod tests {
|
||||
let circuit = WrapperCircuit::<Fr, CustomFCircuit<Fr>> {
|
||||
FC: custom_circuit,
|
||||
z_i: Some(z_i.clone()),
|
||||
z_i1: Some(custom_circuit.step_native(z_i).unwrap()),
|
||||
z_i1: Some(custom_circuit.step_native(0, z_i).unwrap()),
|
||||
};
|
||||
test_relaxed_r1cs_gadget(circuit);
|
||||
}
|
||||
@@ -567,7 +567,7 @@ pub mod tests {
|
||||
let circuit = WrapperCircuit::<Fq, CustomFCircuit<Fq>> {
|
||||
FC: custom_circuit,
|
||||
z_i: Some(z_i.clone()),
|
||||
z_i1: Some(custom_circuit.step_native(z_i).unwrap()),
|
||||
z_i1: Some(custom_circuit.step_native(0, z_i).unwrap()),
|
||||
};
|
||||
circuit.generate_constraints(cs.clone()).unwrap();
|
||||
cs.finalize();
|
||||
|
||||
@@ -227,7 +227,7 @@ where
|
||||
let (prover_params, F_circuit) = prep_param;
|
||||
|
||||
let (r1cs, cf_r1cs) =
|
||||
get_r1cs::<C1, GC1, C2, GC2, FC>(&prover_params.poseidon_config, *F_circuit)?;
|
||||
get_r1cs::<C1, GC1, C2, GC2, FC>(&prover_params.poseidon_config, F_circuit.clone())?;
|
||||
|
||||
let verifier_params = VerifierParams::<C1, C2> {
|
||||
poseidon_config: prover_params.poseidon_config.clone(),
|
||||
@@ -244,7 +244,7 @@ where
|
||||
let cs2 = ConstraintSystem::<C1::BaseField>::new_ref();
|
||||
|
||||
let augmented_F_circuit =
|
||||
AugmentedFCircuit::<C1, C2, GC2, FC>::empty(&pp.poseidon_config, F);
|
||||
AugmentedFCircuit::<C1, C2, GC2, FC>::empty(&pp.poseidon_config, F.clone());
|
||||
let cf_circuit = CycleFoldCircuit::<C1, GC1>::empty();
|
||||
|
||||
augmented_F_circuit.generate_constraints(cs.clone())?;
|
||||
@@ -292,7 +292,14 @@ where
|
||||
let cfW_circuit: CycleFoldCircuit<C1, GC1>;
|
||||
let cfE_circuit: CycleFoldCircuit<C1, GC1>;
|
||||
|
||||
let z_i1 = self.F.step_native(self.z_i.clone())?;
|
||||
if self.i > C1::ScalarField::from_le_bytes_mod_order(&std::usize::MAX.to_le_bytes()) {
|
||||
return Err(Error::MaxStep);
|
||||
}
|
||||
let mut i_bytes: [u8; 8] = [0; 8];
|
||||
i_bytes.copy_from_slice(&self.i.into_bigint().to_bytes_le()[..8]);
|
||||
let i_usize: usize = usize::from_le_bytes(i_bytes);
|
||||
|
||||
let z_i1 = self.F.step_native(i_usize, self.z_i.clone())?;
|
||||
|
||||
// compute T and cmT for AugmentedFCircuit
|
||||
let (T, cmT) = self.compute_cmT()?;
|
||||
@@ -327,13 +334,14 @@ where
|
||||
_gc2: PhantomData,
|
||||
poseidon_config: self.poseidon_config.clone(),
|
||||
i: Some(C1::ScalarField::zero()), // = i=0
|
||||
z_0: Some(self.z_0.clone()), // = z_i
|
||||
i_usize: Some(0),
|
||||
z_0: Some(self.z_0.clone()), // = z_i
|
||||
z_i: Some(self.z_i.clone()),
|
||||
u_i: Some(self.u_i.clone()), // = dummy
|
||||
U_i: Some(self.U_i.clone()), // = dummy
|
||||
U_i1: Some(U_i1.clone()),
|
||||
cmT: Some(cmT),
|
||||
F: self.F,
|
||||
F: self.F.clone(),
|
||||
x: Some(u_i1_x),
|
||||
cf1_u_i: None,
|
||||
cf2_u_i: None,
|
||||
@@ -399,13 +407,14 @@ where
|
||||
_gc2: PhantomData,
|
||||
poseidon_config: self.poseidon_config.clone(),
|
||||
i: Some(self.i),
|
||||
i_usize: Some(i_usize),
|
||||
z_0: Some(self.z_0.clone()),
|
||||
z_i: Some(self.z_i.clone()),
|
||||
u_i: Some(self.u_i.clone()),
|
||||
U_i: Some(self.U_i.clone()),
|
||||
U_i1: Some(U_i1.clone()),
|
||||
cmT: Some(cmT),
|
||||
F: self.F,
|
||||
F: self.F.clone(),
|
||||
x: Some(u_i1_x),
|
||||
// cyclefold values
|
||||
cf1_u_i: Some(cfW_u_i.clone()),
|
||||
|
||||
Reference in New Issue
Block a user