From 6bdc0c8064fa5d7c2e42d144cc314d7d7a637e7e Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Wed, 16 Apr 2025 22:28:14 +0000 Subject: [PATCH 1/4] new test for checking vks of circuits with honk recursion constraint --- .../acir_format/honk_recursion_constraint.cpp | 2 +- .../honk_recursion_constraint.test.cpp | 32 +++++++++++++++++-- .../src/barretenberg/eccvm/eccvm_flavor.hpp | 2 -- .../cpp/src/barretenberg/flavor/flavor.hpp | 14 +++++++- .../ultra_recursive_verifier.cpp | 1 + .../stdlib_circuit_builders/mega_flavor.hpp | 6 +++- .../stdlib_circuit_builders/ultra_flavor.hpp | 1 - .../ultra_rollup_flavor.hpp | 7 +++- 8 files changed, 56 insertions(+), 9 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp index 1f2fc25673ff..6de09720f001 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp @@ -99,7 +99,7 @@ void create_dummy_vkey_and_proof(typename Flavor::CircuitBuilder& builder, } // The aggregation object for (size_t i = 0; i < AggregationObject::PUBLIC_INPUTS_SIZE; i++) { - builder.assert_equal(builder.add_variable(fr::random_element()), proof_fields[offset].witness_index); + builder.assert_equal(builder.add_variable(2), proof_fields[offset].witness_index); offset++; } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.test.cpp index 20d4c4b399f4..67217d9b5f79 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.test.cpp @@ -155,7 +155,8 @@ template class AcirHonkRecursionConstraint : public : * @param inner_circuits * @return Composer */ - template BuilderType create_outer_circuit(std::vector& inner_circuits) + template + BuilderType create_outer_circuit(std::vector& inner_circuits, bool dummy_witnesses = false) { std::vector honk_recursion_constraints; @@ -208,6 +209,9 @@ template class AcirHonkRecursionConstraint : public : honk_recursion = 2; } ProgramMetadata metadata{ .honk_recursion = honk_recursion }; + if (dummy_witnesses) { + witness = {}; // set it all to 0 + } AcirProgram program{ constraint_system, witness }; BuilderType outer_circuit = create_circuit(program, metadata); @@ -228,6 +232,30 @@ using Flavors = testing::Types, TYPED_TEST_SUITE(AcirHonkRecursionConstraint, Flavors); +TYPED_TEST(AcirHonkRecursionConstraint, TestHonkRecursionConstraintVKGeneration) +{ + std::vector layer_1_circuits; + layer_1_circuits.push_back(TestFixture::create_inner_circuit()); + + auto layer_2_circuit = + TestFixture::template create_outer_circuit(layer_1_circuits); + + auto layer_2_circuit_with_dummy_witnesses = + TestFixture::template create_outer_circuit(layer_1_circuits, + /*dummy_witnesses=*/true); + + auto proving_key = std::make_shared(layer_2_circuit); + auto verification_key = std::make_shared(proving_key->proving_key); + + auto proving_key_dummy = + std::make_shared(layer_2_circuit_with_dummy_witnesses); + auto verification_key_dummy = + std::make_shared(proving_key_dummy->proving_key); + + // Compare the two vks + EXPECT_EQ(*verification_key_dummy, *verification_key); +} + TYPED_TEST(AcirHonkRecursionConstraint, TestBasicSingleHonkRecursionConstraint) { std::vector layer_1_circuits; @@ -243,7 +271,7 @@ TYPED_TEST(AcirHonkRecursionConstraint, TestBasicSingleHonkRecursionConstraint) info("prover gates = ", proving_key->proving_key.circuit_size); auto proof = prover.construct_proof(); auto verification_key = std::make_shared(proving_key->proving_key); - info(HasIPAAccumulator); + if constexpr (HasIPAAccumulator) { auto ipa_verification_key = std::make_shared>(1 << CONST_ECCVM_LOG_N); typename TestFixture::OuterVerifier verifier(verification_key, ipa_verification_key); diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp index 75fbc636a5cd..97590c3ee5ed 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp @@ -748,8 +748,6 @@ class ECCVMFlavor { */ class VerificationKey : public VerificationKey_, VerifierCommitmentKey> { public: - bool operator==(const VerificationKey&) const = default; - // Default construct the fixed VK that results from ECCVM_FIXED_SIZE VerificationKey() : VerificationKey_(ECCVM_FIXED_SIZE, /*num_public_inputs=*/0) diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index 835ea934221a..6e1b9b84d631 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -171,7 +171,19 @@ class VerificationKey_ : public PrecomputedCommitments { bool contains_pairing_point_accumulator = false; PairingPointAccumulatorPubInputIndices pairing_point_accumulator_public_input_indices = {}; - bool operator==(const VerificationKey_&) const = default; + bool operator==(const VerificationKey_& other) const + { + bool equal = true; + equal &= this->circuit_size == other.circuit_size; + equal &= this->log_circuit_size == other.log_circuit_size; + equal &= this->num_public_inputs == other.num_public_inputs; + equal &= this->pub_inputs_offset == other.pub_inputs_offset; + equal &= this->contains_pairing_point_accumulator == other.contains_pairing_point_accumulator; + for (auto [comm, other_comm] : zip_view(this->get_all(), other.get_all())) { + equal &= comm == other_comm; + } + return equal; + } VerificationKey_() = default; VerificationKey_(const size_t circuit_size, const size_t num_public_inputs) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.cpp index 9c569a24d4fd..86ef41dad9f6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.cpp @@ -128,6 +128,7 @@ UltraRecursiveVerifier_::Output UltraRecursiveVerifier_::verify_ auto pairing_points = PCS::reduce_verify_batch_opening_claim(opening_claim, transcript); + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1352): Investigate if normalize() calls are needed. pairing_points[0] = pairing_points[0].normalize(); pairing_points[1] = pairing_points[1].normalize(); // TODO(https://github.com/AztecProtocol/barretenberg/issues/995): generate recursion separator challenge properly. diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 5cd8a2c33881..ee7972d2ef7c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -429,7 +429,11 @@ class MegaFlavor { // Data pertaining to transfer of databus return data via public inputs of the proof being recursively verified DatabusPropagationData databus_propagation_data; - bool operator==(const VerificationKey&) const = default; + bool operator==(const VerificationKey& other) const + { + // call parent one + return (VerificationKey_::operator==(other) && databus_propagation_data == other.databus_propagation_data); + } VerificationKey() = default; VerificationKey(const size_t circuit_size, const size_t num_public_inputs) : VerificationKey_(circuit_size, num_public_inputs) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 0348685ff2e2..f6309930165f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -353,7 +353,6 @@ class UltraFlavor { */ class VerificationKey : public VerificationKey_, VerifierCommitmentKey> { public: - bool operator==(const VerificationKey&) const = default; VerificationKey() = default; VerificationKey(const size_t circuit_size, const size_t num_public_inputs) : VerificationKey_(circuit_size, num_public_inputs) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_rollup_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_rollup_flavor.hpp index 8b633dd87e12..90f05d3a0f77 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_rollup_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_rollup_flavor.hpp @@ -43,7 +43,12 @@ class UltraRollupFlavor : public bb::UltraFlavor { bool contains_ipa_claim; IPAClaimPubInputIndices ipa_claim_public_input_indices; - bool operator==(const VerificationKey&) const = default; + bool operator==(const VerificationKey& other) const + { + // call the parent one + return (VerificationKey_::operator==(other) && contains_ipa_claim == other.contains_ipa_claim && + ipa_claim_public_input_indices == other.ipa_claim_public_input_indices); + } VerificationKey() = default; VerificationKey(const size_t circuit_size, const size_t num_public_inputs) : VerificationKey_(circuit_size, num_public_inputs) From b30e2426a1b2328dc559ce744e3d0127ecb0edaf Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Thu, 17 Apr 2025 18:22:52 +0000 Subject: [PATCH 2/4] undo operator== changes now that pcs key is gone --- .../cpp/src/barretenberg/flavor/flavor.hpp | 14 +------------- .../stdlib_circuit_builders/mega_flavor.hpp | 6 +----- .../stdlib_circuit_builders/ultra_flavor.hpp | 1 + .../ultra_rollup_flavor.hpp | 7 +------ 4 files changed, 4 insertions(+), 24 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index b2890257a779..eb071dc31c9e 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -170,19 +170,7 @@ class VerificationKey_ : public PrecomputedCommitments { bool contains_pairing_point_accumulator = false; PairingPointAccumulatorPubInputIndices pairing_point_accumulator_public_input_indices = {}; - bool operator==(const VerificationKey_& other) const - { - bool equal = true; - equal &= this->circuit_size == other.circuit_size; - equal &= this->log_circuit_size == other.log_circuit_size; - equal &= this->num_public_inputs == other.num_public_inputs; - equal &= this->pub_inputs_offset == other.pub_inputs_offset; - equal &= this->contains_pairing_point_accumulator == other.contains_pairing_point_accumulator; - for (auto [comm, other_comm] : zip_view(this->get_all(), other.get_all())) { - equal &= comm == other_comm; - } - return equal; - } + bool operator==(const VerificationKey_& other) const = default; VerificationKey_() = default; VerificationKey_(const size_t circuit_size, const size_t num_public_inputs) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 17e8afb15d3f..a0ef6db3b4f9 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -429,11 +429,7 @@ class MegaFlavor { // Data pertaining to transfer of databus return data via public inputs of the proof being recursively verified DatabusPropagationData databus_propagation_data; - bool operator==(const VerificationKey& other) const - { - // call parent one - return (VerificationKey_::operator==(other) && databus_propagation_data == other.databus_propagation_data); - } + bool operator==(const VerificationKey& other) const = default; VerificationKey() = default; VerificationKey(const size_t circuit_size, const size_t num_public_inputs) : VerificationKey_(circuit_size, num_public_inputs) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index a6b2d34cc98c..bd2d74fc0b8d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -353,6 +353,7 @@ class UltraFlavor { */ class VerificationKey : public VerificationKey_, VerifierCommitmentKey> { public: + bool operator==(const VerificationKey&) const = default; VerificationKey() = default; VerificationKey(const size_t circuit_size, const size_t num_public_inputs) : VerificationKey_(circuit_size, num_public_inputs) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_rollup_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_rollup_flavor.hpp index 44617ffbce67..20f8fee63ea0 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_rollup_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_rollup_flavor.hpp @@ -43,12 +43,7 @@ class UltraRollupFlavor : public bb::UltraFlavor { bool contains_ipa_claim; IPAClaimPubInputIndices ipa_claim_public_input_indices; - bool operator==(const VerificationKey& other) const - { - // call the parent one - return (VerificationKey_::operator==(other) && contains_ipa_claim == other.contains_ipa_claim && - ipa_claim_public_input_indices == other.ipa_claim_public_input_indices); - } + bool operator==(const VerificationKey&) const = default; VerificationKey() = default; VerificationKey(const size_t circuit_size, const size_t num_public_inputs) : VerificationKey_(circuit_size, num_public_inputs) From c6ddd7f6c63aefe45af942be97f56b2eae53d7da Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Thu, 17 Apr 2025 18:30:23 +0000 Subject: [PATCH 3/4] address comment --- .../dsl/acir_format/honk_recursion_constraint.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp index 6de09720f001..1edd3c3ce234 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp @@ -97,9 +97,12 @@ void create_dummy_vkey_and_proof(typename Flavor::CircuitBuilder& builder, builder.assert_equal(builder.add_variable(fr::random_element()), proof_fields[offset].witness_index); offset++; } + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1352): Using SMALL_DUMMY_VALUE might resolve this + // issue. + fr SMALL_DUMMY_VALUE(2); // arbtirary small value that shouldn't cause builder problems. // The aggregation object for (size_t i = 0; i < AggregationObject::PUBLIC_INPUTS_SIZE; i++) { - builder.assert_equal(builder.add_variable(2), proof_fields[offset].witness_index); + builder.assert_equal(builder.add_variable(SMALL_DUMMY_VALUE), proof_fields[offset].witness_index); offset++; } From fc1d7758ab299d22caa3c28491ae84bc60cbd2e1 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Thu, 17 Apr 2025 18:32:07 +0000 Subject: [PATCH 4/4] undo other changes --- barretenberg/cpp/src/barretenberg/flavor/flavor.hpp | 2 +- .../src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index eb071dc31c9e..c530eeebd92d 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -170,7 +170,7 @@ class VerificationKey_ : public PrecomputedCommitments { bool contains_pairing_point_accumulator = false; PairingPointAccumulatorPubInputIndices pairing_point_accumulator_public_input_indices = {}; - bool operator==(const VerificationKey_& other) const = default; + bool operator==(const VerificationKey_&) const = default; VerificationKey_() = default; VerificationKey_(const size_t circuit_size, const size_t num_public_inputs) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index a0ef6db3b4f9..64e127806d53 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -429,7 +429,7 @@ class MegaFlavor { // Data pertaining to transfer of databus return data via public inputs of the proof being recursively verified DatabusPropagationData databus_propagation_data; - bool operator==(const VerificationKey& other) const = default; + bool operator==(const VerificationKey&) const = default; VerificationKey() = default; VerificationKey(const size_t circuit_size, const size_t num_public_inputs) : VerificationKey_(circuit_size, num_public_inputs)