Skip to content

Commit 107e900

Browse files
AztecBotAztecBotfedericobarbacoviludamad
authored
feat: merge-train/barretenberg (#16244)
See [merge-train-readme.md](https://github.com/AztecProtocol/aztec-packages/blob/next/.github/workflows/merge-train-readme.md). BEGIN_COMMIT_OVERRIDE chore: Template ultra verifier `verify_proof` over the public inputs type (#16239) END_COMMIT_OVERRIDE --------- Co-authored-by: AztecBot <tech@aztecprotocol.com> Co-authored-by: federicobarbacovi <171914500+federicobarbacovi@users.noreply.github.com> Co-authored-by: ludamad <adam.domurad@gmail.com>
1 parent 563ee8a commit 107e900

33 files changed

+353
-256
lines changed

barretenberg/cpp/src/barretenberg/api/api_ultra_honk.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ PubInputsProofAndKey<Flavor> _prove(const bool compute_vk,
115115
}
116116

117117
template <typename Flavor>
118-
bool _verify(const bool ipa_accumulation,
119-
const std::filesystem::path& public_inputs_path,
118+
bool _verify(const std::filesystem::path& public_inputs_path,
120119
const std::filesystem::path& proof_path,
121120
const std::filesystem::path& vk_path)
122121
{
@@ -134,14 +133,14 @@ bool _verify(const bool ipa_accumulation,
134133
complete_proof.insert(complete_proof.end(), proof.begin(), proof.end());
135134

136135
VerifierCommitmentKey<curve::Grumpkin> ipa_verification_key;
137-
if (ipa_accumulation) {
136+
if constexpr (HasIPAAccumulator<Flavor>) {
138137
ipa_verification_key = VerifierCommitmentKey<curve::Grumpkin>(1 << CONST_ECCVM_LOG_N);
139138
}
140139

141140
Verifier verifier{ vk, ipa_verification_key };
142141

143-
bool verified;
144-
if (ipa_accumulation) {
142+
bool verified = false;
143+
if constexpr (HasIPAAccumulator<Flavor>) {
145144
const size_t HONK_PROOF_LENGTH = Flavor::PROOF_LENGTH_WITHOUT_PUB_INPUTS - IPA_PROOF_LENGTH;
146145
const size_t num_public_inputs = static_cast<size_t>(vk->num_public_inputs);
147146
// The extra calculation is for the IPA proof length.
@@ -153,9 +152,9 @@ bool _verify(const bool ipa_accumulation,
153152
auto ipa_proof = Proof(complete_proof.begin() + honk_proof_with_pub_inputs_length, complete_proof.end());
154153
auto tube_honk_proof =
155154
Proof(complete_proof.begin(), complete_proof.begin() + honk_proof_with_pub_inputs_length);
156-
verified = verifier.verify_proof(complete_proof, ipa_proof);
155+
verified = verifier.template verify_proof<RollupIO>(complete_proof, ipa_proof).result;
157156
} else {
158-
verified = verifier.verify_proof(complete_proof);
157+
verified = verifier.template verify_proof<DefaultIO>(complete_proof).result;
159158
}
160159

161160
if (verified) {
@@ -217,15 +216,15 @@ bool UltraHonkAPI::verify(const Flags& flags,
217216
const bool ipa_accumulation = flags.ipa_accumulation;
218217
// if the ipa accumulation flag is set we are using the UltraRollupFlavor
219218
if (ipa_accumulation) {
220-
return _verify<UltraRollupFlavor>(ipa_accumulation, public_inputs_path, proof_path, vk_path);
219+
return _verify<UltraRollupFlavor>(public_inputs_path, proof_path, vk_path);
221220
} else if (flags.oracle_hash_type == "poseidon2" && !flags.disable_zk) {
222-
return _verify<UltraZKFlavor>(ipa_accumulation, public_inputs_path, proof_path, vk_path);
221+
return _verify<UltraZKFlavor>(public_inputs_path, proof_path, vk_path);
223222
} else if (flags.oracle_hash_type == "poseidon2" && flags.disable_zk) {
224-
return _verify<UltraFlavor>(ipa_accumulation, public_inputs_path, proof_path, vk_path);
223+
return _verify<UltraFlavor>(public_inputs_path, proof_path, vk_path);
225224
} else if (flags.oracle_hash_type == "keccak" && !flags.disable_zk) {
226-
return _verify<UltraKeccakZKFlavor>(ipa_accumulation, public_inputs_path, proof_path, vk_path);
225+
return _verify<UltraKeccakZKFlavor>(public_inputs_path, proof_path, vk_path);
227226
} else if (flags.oracle_hash_type == "keccak" && flags.disable_zk) {
228-
return _verify<UltraKeccakFlavor>(ipa_accumulation, public_inputs_path, proof_path, vk_path);
227+
return _verify<UltraKeccakFlavor>(public_inputs_path, proof_path, vk_path);
229228
#ifdef STARKNET_GARAGA_FLAVORS
230229
} else if (flags.oracle_hash_type == "starknet" && !flags.disable_zk) {
231230
return _verify<UltraStarknetZKFlavor>(ipa_accumulation, public_inputs_path, proof_path, vk_path);

barretenberg/cpp/src/barretenberg/api/prove_tube.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void prove_tube(const std::string& output_path, const std::string& vk_path)
109109
HONK_PROOF_LENGTH_WITHOUT_INNER_PUB_INPUTS - IPA_PROOF_LENGTH + num_inner_public_inputs);
110110
auto ipa_proof = HonkProof(tube_proof.begin() + honk_proof_with_pub_inputs_length, tube_proof.end());
111111
auto tube_honk_proof = HonkProof(tube_proof.begin(), tube_proof.end() + honk_proof_with_pub_inputs_length);
112-
bool verified = tube_verifier.verify_proof(tube_honk_proof, ipa_proof);
112+
bool verified = tube_verifier.template verify_proof<bb::RollupIO>(tube_honk_proof, ipa_proof).result;
113113
info("Tube proof verification: ", verified);
114114
}
115115

barretenberg/cpp/src/barretenberg/boomerang_value_detection/graph_description_goblin.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ TEST_F(BoomerangGoblinRecursiveVerifierTests, graph_description_basic)
104104
OuterProver prover(proving_key, verification_key);
105105
OuterVerifier verifier(verification_key);
106106
auto proof = prover.construct_proof();
107-
bool verified = verifier.verify_proof(proof);
107+
bool verified = verifier.template verify_proof<bb::DefaultIO>(proof).result;
108108

109109
ASSERT_TRUE(verified);
110110
}

barretenberg/cpp/src/barretenberg/boomerang_value_detection/graph_description_ultra_recursive_verifier.test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ template <typename RecursiveFlavor> class BoomerangRecursiveVerifierTest : publi
4747

4848
using PairingObject = PairingPoints<OuterBuilder>;
4949
using VerifierOutput = bb::stdlib::recursion::honk::UltraRecursiveVerifierOutput<OuterBuilder>;
50+
using StdlibProof = bb::stdlib::Proof<OuterBuilder>;
5051

5152
/**
5253
* @brief Create a non-trivial arbitrary inner circuit, the proof of which will be recursively verified
@@ -114,7 +115,8 @@ template <typename RecursiveFlavor> class BoomerangRecursiveVerifierTest : publi
114115
verifier.key->vk_and_hash->vk->num_public_inputs.fix_witness();
115116
verifier.key->vk_and_hash->vk->pub_inputs_offset.fix_witness();
116117

117-
VerifierOutput output = verifier.verify_proof(inner_proof);
118+
StdlibProof stdlib_inner_proof(outer_circuit, inner_proof);
119+
VerifierOutput output = verifier.template verify_proof<DefaultIO<OuterBuilder>>(stdlib_inner_proof);
118120
PairingObject pairing_points = output.points_accumulator;
119121
pairing_points.P0.x.fix_witness();
120122
pairing_points.P0.y.fix_witness();

barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ bool ClientIVC::verify(const Proof& proof, const VerificationKey& vk)
514514
std::shared_ptr<Goblin::Transcript> civc_verifier_transcript = std::make_shared<Goblin::Transcript>();
515515
// Verify the hiding circuit proof
516516
MegaZKVerifier verifier{ vk.mega, /*ipa_verification_key=*/{}, civc_verifier_transcript };
517-
auto [mega_verified, T_prev_commitments] = verifier.verify_proof(proof.mega_proof);
517+
auto [mega_verified, T_prev_commitments] = verifier.template verify_proof<bb::HidingKernelIO>(proof.mega_proof);
518518
vinfo("Mega verified: ", mega_verified);
519519

520520
// Extract the commitments to the subtable corresponding to the incoming circuit

barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_integration.test.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ class AcirIntegrationTest : public ::testing::Test {
7575

7676
// Verify Honk proof
7777
Verifier verifier{ verification_key };
78-
if constexpr (IsUltraHonk<Flavor>) {
79-
return verifier.verify_proof(proof);
80-
} else {
81-
return std::get<0>(verifier.verify_proof(proof));
82-
}
78+
bool result = verifier.template verify_proof<DefaultIO>(proof).result;
79+
80+
return result;
8381
}
8482

8583
void add_some_simple_RAM_gates(auto& circuit)

barretenberg/cpp/src/barretenberg/dsl/acir_format/avm2_recursion_constraint.test.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ TEST_F(AcirAvm2RecursionConstraint, TestBasicSingleAvm2RecursionConstraint)
140140
auto proof = prover.construct_proof();
141141
VerifierCommitmentKey<curve::Grumpkin> ipa_verification_key(1 << CONST_ECCVM_LOG_N);
142142
OuterVerifier verifier(verification_key, ipa_verification_key);
143-
EXPECT_EQ(verifier.verify_proof(proof, proving_key->ipa_proof), true);
143+
bool result = verifier.template verify_proof<bb::RollupIO>(proof, proving_key->ipa_proof).result;
144+
EXPECT_TRUE(result);
144145
}
145146

146147
/**
@@ -173,7 +174,9 @@ TEST_F(AcirAvm2RecursionConstraint, TestGenerateVKFromConstraintsWithoutWitness)
173174
auto proof = prover.construct_proof();
174175
VerifierCommitmentKey<curve::Grumpkin> ipa_verification_key(1 << CONST_ECCVM_LOG_N);
175176
OuterVerifier verifier(expected_vk, ipa_verification_key);
176-
EXPECT_TRUE(verifier.verify_proof(proof, proving_key->ipa_proof));
177+
178+
bool result = verifier.template verify_proof<bb::RollupIO>(proof, proving_key->ipa_proof).result;
179+
EXPECT_TRUE(result);
177180
}
178181

179182
// Now, construct the AVM2 recursive verifier circuit VK by providing the program without a witness

barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class MegaHonk : public ::testing::Test {
3434

3535
Verifier verifier{ verification_key };
3636

37-
return std::get<0>(verifier.verify_proof(proof));
37+
bool result = verifier.template verify_proof<DefaultIO>(proof).result;
38+
return result;
3839
}
3940

4041
protected:

barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ HonkRecursionConstraintOutput<typename Flavor::CircuitBuilder> create_honk_recur
222222
using RecursiveVerificationKey = Flavor::VerificationKey;
223223
using RecursiveVKAndHash = Flavor::VKAndHash;
224224
using RecursiveVerifier = bb::stdlib::recursion::honk::UltraRecursiveVerifier_<Flavor>;
225+
using IO = std::conditional_t<HasIPAAccumulator<Flavor>,
226+
stdlib::recursion::honk::RollupIO,
227+
stdlib::recursion::honk::DefaultIO<Builder>>;
225228

226229
ASSERT(input.proof_type == HONK || input.proof_type == HONK_ZK || HasIPAAccumulator<Flavor>);
227230
BB_ASSERT_EQ(input.proof_type == ROLLUP_HONK || input.proof_type == ROOT_ROLLUP_HONK, HasIPAAccumulator<Flavor>);
@@ -254,17 +257,8 @@ HonkRecursionConstraintOutput<typename Flavor::CircuitBuilder> create_honk_recur
254257
if (!has_valid_witness_assignments) {
255258
// In the constraint, the agg object public inputs are still contained in the proof. To get the 'raw' size of
256259
// the proof and public_inputs we subtract and add the corresponding amount from the respective sizes.
257-
size_t size_of_proof_with_no_pub_inputs = input.proof.size();
258-
size_t total_num_public_inputs = input.public_inputs.size();
259-
if constexpr (HasIPAAccumulator<Flavor>) {
260-
using RollupIO = stdlib::recursion::honk::RollupIO;
261-
size_of_proof_with_no_pub_inputs -= RollupIO::PUBLIC_INPUTS_SIZE;
262-
total_num_public_inputs += RollupIO::PUBLIC_INPUTS_SIZE;
263-
} else {
264-
using DefaultIO = stdlib::recursion::honk::DefaultIO<Builder>;
265-
size_of_proof_with_no_pub_inputs -= DefaultIO::PUBLIC_INPUTS_SIZE;
266-
total_num_public_inputs += DefaultIO::PUBLIC_INPUTS_SIZE;
267-
}
260+
size_t size_of_proof_with_no_pub_inputs = input.proof.size() - IO::PUBLIC_INPUTS_SIZE;
261+
size_t total_num_public_inputs = input.public_inputs.size() + IO::PUBLIC_INPUTS_SIZE;
268262

269263
create_dummy_vkey_and_proof<Flavor>(
270264
builder, size_of_proof_with_no_pub_inputs, total_num_public_inputs, key_fields, proof_fields);
@@ -274,7 +268,7 @@ HonkRecursionConstraintOutput<typename Flavor::CircuitBuilder> create_honk_recur
274268
auto vkey = std::make_shared<RecursiveVerificationKey>(builder, key_fields);
275269
auto vk_and_hash = std::make_shared<RecursiveVKAndHash>(vkey, vk_hash);
276270
RecursiveVerifier verifier(&builder, vk_and_hash);
277-
UltraRecursiveVerifierOutput<Builder> verifier_output = verifier.verify_proof(proof_fields);
271+
UltraRecursiveVerifierOutput<Builder> verifier_output = verifier.template verify_proof<IO>(proof_fields);
278272
// TODO(https://github.com/AztecProtocol/barretenberg/issues/996): investigate whether assert_equal on public inputs
279273
// is important, like what the plonk recursion constraint does.
280274
return verifier_output;

barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.test.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -222,36 +222,27 @@ template <typename RecursiveFlavor> class AcirHonkRecursionConstraint : public :
222222
AcirProgram program{ constraint_system, witness };
223223
BuilderType outer_circuit = create_circuit<BuilderType>(program, metadata);
224224

225-
// If BuilderType = Mega, then the proof of outer_circuit will be a Mega proof, and thus will be verified with
226-
// a MegaVerifier = UltraVerifier<MegaFlavor>. By design, the MegaVerifier expects the public inputs to be the
227-
// ones of the HidingKernel, so we mock the missing part: ecc_op_tables
228-
if constexpr (IsMegaBuilder<BuilderType>) {
229-
for (auto& commitment :
230-
stdlib::recursion::honk::HidingKernelIO<BuilderType>::default_ecc_op_tables(outer_circuit)) {
231-
commitment.set_public();
232-
}
233-
}
234-
235225
return outer_circuit;
236226
}
237227

238228
bool verify_proof(const std::shared_ptr<OuterDeciderProvingKey>& proving_key,
239229
const std::shared_ptr<OuterVerificationKey>& verification_key,
240230
const HonkProof& proof)
241231
{
242-
if constexpr (IsMegaFlavor<OuterFlavor>) {
243-
OuterVerifier verifier(verification_key);
244-
return std::get<0>(verifier.verify_proof(proof));
232+
using IO = std::conditional_t<HasIPAAccumulator<RecursiveFlavor>, RollupIO, DefaultIO>;
233+
234+
bool result = false;
235+
236+
if constexpr (HasIPAAccumulator<RecursiveFlavor>) {
237+
VerifierCommitmentKey<curve::Grumpkin> ipa_verification_key(1 << CONST_ECCVM_LOG_N);
238+
OuterVerifier verifier(verification_key, ipa_verification_key);
239+
result = verifier.template verify_proof<IO>(proof, proving_key->ipa_proof).result;
245240
} else {
246-
if constexpr (HasIPAAccumulator<RecursiveFlavor>) {
247-
VerifierCommitmentKey<curve::Grumpkin> ipa_verification_key(1 << CONST_ECCVM_LOG_N);
248-
OuterVerifier verifier(verification_key, ipa_verification_key);
249-
return verifier.verify_proof(proof, proving_key->ipa_proof);
250-
} else {
251-
OuterVerifier verifier(verification_key);
252-
return verifier.verify_proof(proof);
253-
}
241+
OuterVerifier verifier(verification_key);
242+
result = verifier.template verify_proof<IO>(proof).result;
254243
}
244+
245+
return result;
255246
}
256247

257248
protected:

0 commit comments

Comments
 (0)