Skip to content

Commit

Permalink
refactor(chunk-pattern): passing xclippy
Browse files Browse the repository at this point in the history
  • Loading branch information
tchataigner committed Feb 19, 2024
1 parent bf0d78f commit 87864f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
15 changes: 5 additions & 10 deletions crates/chunk/examples/chunk_add_nivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ impl<F: PrimeField> ChunkStepCircuit<F> for ChunkStep<F> {
let mut acc = z[0].clone();

for (i, elem) in chunk_in.iter().enumerate() {
// TODO i is not what we want here. Should be fold_step + i
acc = acc.add(&mut cs.namespace(|| format!("add{i}")), &elem)?;
acc = acc.add(&mut cs.namespace(|| format!("add{i}")), elem)?;
}

Ok(vec![acc])
Expand Down Expand Up @@ -152,14 +151,10 @@ impl<E1: CurveCycleEquipped, C: ChunkStepCircuit<E1::Scalar>, const N: usize> No
}

fn primary_circuit(&self, circuit_index: usize) -> Self::C1 {
match circuit_index {
_ => {
if let Some(fold_step) = self.inner.circuits().get(circuit_index) {
return Self::C1::IterStep(FoldStepWrapper::new(fold_step.clone()));
}
unreachable!()
}
if let Some(fold_step) = self.inner.circuits().get(circuit_index) {
return Self::C1::IterStep(FoldStepWrapper::new(fold_step.clone()));
}
unreachable!()
}

fn secondary_circuit(&self) -> Self::C2 {
Expand Down Expand Up @@ -271,7 +266,7 @@ fn main() {
}
println!(
"Calculated sum: {:?}",
recursive_snark.zi_primary().get(0).unwrap()
recursive_snark.zi_primary().first().unwrap()
);

println!("Generating a CompressedSNARK...");
Expand Down
2 changes: 2 additions & 0 deletions crates/chunk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ impl<F: PrimeField, C: ChunkStepCircuit<F> + Clone, const N: usize> FoldStep<F,
/// This `synthesize` implementation consists of two parts:
/// 1. Call the inner synthesize method of `ChunkStepCircuit` with correct inputs.
/// 2. Calculate the next program and allocate the next input values for the next `FoldStep` instance.
// Inherited from `StepCircuit`
#[allow(clippy::type_complexity)]
pub fn synthesize<CS: ConstraintSystem<F>>(
&self,
cs: &mut CS,
Expand Down
14 changes: 5 additions & 9 deletions crates/chunk/tests/gadget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl<F: PrimeField> ChunkStepCircuit<F> for ChunkStep<F> {
let mut acc = z[0].clone();

for (i, elem) in chunk_in.iter().enumerate() {
// TODO i is not what we want here. Should be fold_step + i
acc = acc.add(&mut cs.namespace(|| format!("add{i}")), &elem)?;
acc = acc.add(&mut cs.namespace(|| format!("add{i}")), elem)?;
}

Ok(vec![acc])
Expand Down Expand Up @@ -125,20 +124,17 @@ impl<E1: CurveCycleEquipped, C: ChunkStepCircuit<E1::Scalar>, const N: usize> No
}

fn primary_circuit(&self, circuit_index: usize) -> Self::C1 {
match circuit_index {
_ => {
if let Some(fold_step) = self.inner.circuits().get(circuit_index) {
return Self::C1::IterStep(FoldStepWrapper::new(fold_step.clone()));
}
unreachable!()
}
if let Some(fold_step) = self.inner.circuits().get(circuit_index) {
return Self::C1::IterStep(FoldStepWrapper::new(fold_step.clone()));
}
unreachable!()
}

fn secondary_circuit(&self) -> Self::C2 {
Default::default()
}
}

fn verify_chunk_circuit<F: PrimeField, C: ChunkStepCircuit<F>, const N: usize>() {
let test_inputs = vec![F::ONE; 18];

Expand Down

0 comments on commit 87864f6

Please sign in to comment.