@@ -479,6 +479,12 @@ MegaCircuitBuilder create_circuit(AcirFormat& constraint_system,
479
479
480
480
/* *
481
481
* @brief Create a kernel circuit from a constraint system and an IVC instance
482
+ * @details This method processes ivc_recursion_constraints using the kernel completion logic contained in AztecIvc.
483
+ * Since verification keys are known at the time of acir generation, the verification key witnesses contained in the
484
+ * constraints are used directly to instantiate the recursive verifiers. On the other hand, the proof witnesses
485
+ * contained in the constraints are generally 'dummy' values since proofs are not known during acir generation (with the
486
+ * exception of public inputs). This is remedied by connecting the dummy proof witnesses to the genuine proof witnesses,
487
+ * known internally to the IVC class, via copy constraints.
482
488
*
483
489
* @param constraint_system AcirFormat constraint system possibly containing IVC recursion constraints
484
490
* @param ivc An IVC instance containing internal data about proofs to be verified
@@ -491,6 +497,8 @@ MegaCircuitBuilder create_kernel_circuit(AcirFormat& constraint_system,
491
497
const WitnessVector& witness,
492
498
const size_t size_hint)
493
499
{
500
+ using StdlibVerificationKey = AztecIVC::RecursiveVerificationKey;
501
+
494
502
// Construct the main kernel circuit logic excluding recursive verifiers
495
503
auto circuit = create_circuit<MegaCircuitBuilder>(constraint_system,
496
504
size_hint,
@@ -499,18 +507,26 @@ MegaCircuitBuilder create_kernel_circuit(AcirFormat& constraint_system,
499
507
ivc.goblin .op_queue ,
500
508
/* collect_gates_per_opcode=*/ false );
501
509
502
- // We expect the length of the internal verification queue to matche the number of ivc recursion constraints
510
+ // We expect the length of the internal verification queue to match the number of ivc recursion constraints
503
511
if (constraint_system.ivc_recursion_constraints .size () != ivc.verification_queue .size ()) {
504
512
info (" WARNING: Mismatch in number of recursive verifications during kernel creation!" );
505
513
ASSERT (false );
506
514
}
507
515
508
- // Create stdlib representations of each {proof, vkey} pair in the queue based on their native counterparts
509
- ivc.instantiate_stdlib_verification_queue (circuit);
516
+ // Construct a stdlib verification key for each constraint based on the verification key witness indices therein
517
+ std::vector<std::shared_ptr<StdlibVerificationKey>> stdlib_verification_keys;
518
+ stdlib_verification_keys.reserve (constraint_system.ivc_recursion_constraints .size ());
519
+ for (const auto & constraint : constraint_system.ivc_recursion_constraints ) {
520
+ stdlib_verification_keys.push_back (std::make_shared<StdlibVerificationKey>(
521
+ StdlibVerificationKey::from_witness_indices (circuit, constraint.key )));
522
+ }
523
+
524
+ // Create stdlib representations of each {proof, vkey} pair to be recursively verified
525
+ ivc.instantiate_stdlib_verification_queue (circuit, stdlib_verification_keys);
510
526
511
- // Connect each { proof, vkey} pair from the constraint to the corresponding entry in the internal verification
512
- // queue. This ensures that the witnesses utlized in constraints generated based on acir are properly connected to
513
- // the constraints generated herein via the ivc scheme (e.g. recursive verifications).
527
+ // Connect the proof/public_input witness indices from each constraint to the corresponding proof witnesses in the
528
+ // internal verification queue. This ensures that the witnesses utlized in constraints generated based on acir are
529
+ // properly connected to the constraints generated herein via the ivc scheme (e.g. recursive verifications).
514
530
for (auto [constraint, queue_entry] :
515
531
zip_view (constraint_system.ivc_recursion_constraints , ivc.stdlib_verification_queue )) {
516
532
@@ -520,11 +536,9 @@ MegaCircuitBuilder create_kernel_circuit(AcirFormat& constraint_system,
520
536
ASSERT (complete_proof_indices.size () == queue_entry.proof .size ());
521
537
522
538
// Assert equality between the proof indices from the constraint data and those of the internal proof
523
- for (auto [proof_idx, proof_value ] : zip_view (complete_proof_indices, queue_entry.proof )) {
539
+ for (auto [proof_value, proof_idx ] : zip_view (queue_entry.proof , complete_proof_indices )) {
524
540
circuit.assert_equal (proof_value.get_witness_index (), proof_idx);
525
541
}
526
- // TODO(https://github.com/AztecProtocol/barretenberg/issues/1090): assert equality between the internal vkey
527
- // and the constaint vkey, or simply use the constraint vkey directly to construct the stdlib vkey used in IVC.
528
542
}
529
543
530
544
// Complete the kernel circuit with all required recursive verifications, databus consistency checks etc.
0 commit comments