Skip to content

Commit 75d6bf6

Browse files
authored
early detection for constrain failure in recursion circuit (#1369)
Signed-off-by: noelwei <[email protected]>
1 parent 2a99204 commit 75d6bf6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

aggregator/src/recursion/circuit.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,13 @@ impl<ST: StateTransition> Circuit<Fr> for RecursionCircuit<ST> {
410410
// Verify initial_state is same as the first application snark in the
411411
// first round of recursion.
412412
(
413+
"initial state equal to app's initial (first round)",
413414
main_gate.mul(&mut ctx, Existing(st), Existing(first_round)),
414415
main_gate.mul(&mut ctx, Existing(app_inst), Existing(first_round)),
415416
),
416417
// Propagate initial_state for subsequent rounds of recursion.
417418
(
419+
"initial state equal to prev_recursion's initial (not first round)",
418420
main_gate.mul(&mut ctx, Existing(st), Existing(not_first_round)),
419421
previous_st,
420422
),
@@ -436,7 +438,7 @@ impl<ST: StateTransition> Circuit<Fr> for RecursionCircuit<ST> {
436438
.map(|i| &app_instances[i]),
437439
),
438440
)
439-
.map(|(&st, &app_inst)| (st, app_inst))
441+
.map(|(&st, &app_inst)| ("passing cur state to app", st, app_inst))
440442
.collect::<Vec<_>>();
441443

442444
// Verify that the "previous state" (additional state not included) is the same
@@ -451,6 +453,7 @@ impl<ST: StateTransition> Circuit<Fr> for RecursionCircuit<ST> {
451453
)
452454
.map(|(&st, &app_inst)| {
453455
(
456+
"chain prev state with cur init state (not first round)",
454457
main_gate.mul(&mut ctx, Existing(app_inst), Existing(not_first_round)),
455458
st,
456459
)
@@ -459,9 +462,10 @@ impl<ST: StateTransition> Circuit<Fr> for RecursionCircuit<ST> {
459462

460463
// Finally apply the equality constraints between the (LHS, RHS) values constructed
461464
// above.
462-
for (lhs, rhs) in [
465+
for (comment, lhs, rhs) in [
463466
// Propagate the preprocessed digest.
464467
(
468+
"chain preprocessed digest",
465469
main_gate.mul(
466470
&mut ctx,
467471
Existing(preprocessed_digest),
@@ -471,6 +475,7 @@ impl<ST: StateTransition> Circuit<Fr> for RecursionCircuit<ST> {
471475
),
472476
// Verify that "round" increments by 1 when not the first round of recursion.
473477
(
478+
"round increment",
474479
round,
475480
main_gate.add(
476481
&mut ctx,
@@ -484,6 +489,13 @@ impl<ST: StateTransition> Circuit<Fr> for RecursionCircuit<ST> {
484489
.chain(verify_app_state)
485490
.chain(verify_app_init_state)
486491
{
492+
use halo2_proofs::dev::unwrap_value;
493+
debug_assert_eq!(
494+
unwrap_value(lhs.value()),
495+
unwrap_value(rhs.value()),
496+
"equality constraint fail: {}",
497+
comment
498+
);
487499
ctx.region.constrain_equal(lhs.cell(), rhs.cell())?;
488500
}
489501

0 commit comments

Comments
 (0)