Skip to content

Commit 6d6d045

Browse files
committed
update circuit with StepCounterType
1 parent affeb19 commit 6d6d045

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/circuit.rs

+26-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
traits::{
1515
circuit::StepCircuit, commitment::CommitmentTrait, Engine, ROCircuitTrait, ROConstantsCircuit,
1616
},
17-
Commitment,
17+
Commitment, StepCounterType,
1818
};
1919
use abomonation_derive::Abomonation;
2020
use bellpepper::gadgets::{boolean_utils::conditionally_select_slice, Assignment};
@@ -260,6 +260,7 @@ impl<'a, E: Engine, SC: StepCircuit<E::Base>> NovaAugmentedCircuit<'a, E, SC> {
260260
cs: &mut CS,
261261
) -> Result<Vec<AllocatedNum<E::Base>>, SynthesisError> {
262262
let arity = self.step_circuit.arity();
263+
let counter_type = self.step_circuit.get_counter_type();
263264

264265
// Allocate all witnesses
265266
let (params, i, z_0, z_i, U, u, T) =
@@ -307,15 +308,31 @@ impl<'a, E: Engine, SC: StepCircuit<E::Base>> NovaAugmentedCircuit<'a, E, SC> {
307308
)?;
308309

309310
// Compute i + 1
310-
let i_new = AllocatedNum::alloc(cs.namespace(|| "i + 1"), || {
311-
Ok(*i.get_value().get()? + E::Base::ONE)
311+
let i_new = AllocatedNum::alloc(cs.namespace(|| "next i"), || match counter_type {
312+
StepCounterType::Incremental => Ok(*i.get_value().get()? + E::Base::ONE),
313+
StepCounterType::External => {
314+
let inc = *is_base_case.get_value().get()? as u64;
315+
Ok(*i.get_value().get()? + E::Base::from(inc))
316+
}
312317
})?;
313-
cs.enforce(
314-
|| "check i + 1",
315-
|lc| lc,
316-
|lc| lc,
317-
|lc| lc + i_new.get_variable() - CS::one() - i.get_variable(),
318-
);
318+
match counter_type {
319+
StepCounterType::Incremental => {
320+
cs.enforce(
321+
|| "check i + 1",
322+
|lc| lc,
323+
|lc| lc,
324+
|lc| lc + i_new.get_variable() - CS::one() - i.get_variable(),
325+
);
326+
}
327+
StepCounterType::External => {
328+
cs.enforce(
329+
|| "check i + 1 base",
330+
|lc| lc,
331+
|lc| lc,
332+
|lc| lc + i_new.get_variable() - is_base_case.get_variable() - i.get_variable(),
333+
);
334+
}
335+
}
319336

320337
// Compute z_{i+1}
321338
let z_input = conditionally_select_slice(

0 commit comments

Comments
 (0)