Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
goblin_verifier.test.cpp
Go to the documentation of this file.
11
13class GoblinRecursiveVerifierTests : public testing::Test {
14 public:
18
23
25 using RecursiveCommitment = bb::GoblinRecursiveVerifier::MergeVerifier::Commitment;
27 using RecursiveMergeCommitments = bb::GoblinRecursiveVerifier::MergeVerifier::InputCommitments;
31
37 static void tamper_with_op_commitment(MergeCommitments& merge_commitments)
38 {
39 // The first commitment in merged table is the `op` wire commitment
40 merge_commitments.t_commitments[0] = merge_commitments.t_commitments[0] * FF(2);
41 };
42
43 // ECCVM pre-IPA proof ends with evaluations including `op`. We tamper with the `op` evaluation.
44 // The structure is: [..., op_eval, x_lo_y_hi_eval, x_hi_z_1_eval, y_lo_z_2_eval, IPA_proof...]
45 // So op_eval is 3 fields before the IPA proof starts.
46 static void tamper_with_eccvm_op_eval(HonkProof& eccvm_proof)
47 {
48 // The `op` evaluation is located 3 evaluations before the end of pre-IPA proof
49 // (followed by x_lo_y_hi, x_hi_z_1, y_lo_z_2 evaluations)
50 static constexpr size_t evals_after_op = 3; // x_lo_y_hi, x_hi_z_1, y_lo_z_2
51 const size_t op_eval_idx = eccvm_proof.size() - evals_after_op;
52
53 // Tamper with the op evaluation
54 eccvm_proof[op_eval_idx] += FF(1);
55 };
56
62 static ProverOutput create_goblin_prover_output(Builder* outer_builder = nullptr, const size_t num_circuits = 5)
63 {
64
65 Goblin goblin;
67 goblin.op_queue->construct_zk_columns();
68
69 // Merge the ecc ops from the newly constructed circuit
70 auto goblin_proof = goblin.prove();
71 // Subtable values and commitments - needed for (Recursive)MergeVerifier
72 MergeCommitments merge_commitments;
73 auto t_current = goblin.op_queue->construct_current_ultra_ops_subtable_columns();
74 auto T_prev = goblin.op_queue->construct_table_columns_up_to_tail();
75 CommitmentKey<curve::BN254> pcs_commitment_key(goblin.op_queue->get_ultra_ops_table_num_rows() +
77 for (size_t idx = 0; idx < MegaFlavor::NUM_WIRES; idx++) {
78 merge_commitments.t_commitments[idx] = pcs_commitment_key.commit(t_current[idx]);
79 merge_commitments.T_prev_commitments[idx] = pcs_commitment_key.commit(T_prev[idx]);
80 }
81
82 RecursiveMergeCommitments recursive_merge_commitments;
83 if (outer_builder != nullptr) {
84 for (size_t idx = 0; idx < MegaFlavor::NUM_WIRES; idx++) {
85 recursive_merge_commitments.t_commitments[idx] =
86 RecursiveCommitment::from_witness(outer_builder, merge_commitments.t_commitments[idx]);
87 recursive_merge_commitments.T_prev_commitments[idx] =
88 RecursiveCommitment::from_witness(outer_builder, merge_commitments.T_prev_commitments[idx]);
89 // Removing the free witness tag, since the merge commitments in the full scheme are supposed to
90 // be fiat-shamirred earlier
91 recursive_merge_commitments.t_commitments[idx].unset_free_witness_tag();
92 recursive_merge_commitments.T_prev_commitments[idx].unset_free_witness_tag();
93 }
94 }
95
96 // Output is a goblin proof plus merge commitments
97 return { goblin_proof, merge_commitments, recursive_merge_commitments };
98 }
99};
100
106{
107 auto [proof, merge_commitments, _] = create_goblin_prover_output();
108
109 auto transcript = std::make_shared<NativeTranscript>();
110 bb::GoblinVerifier verifier(transcript, proof, merge_commitments);
111 auto result = verifier.reduce_to_pairing_check_and_ipa_opening();
112
113 // Check pairing points (aggregate merge + translator)
114 result.translator_pairing_points.aggregate(result.merge_pairing_points);
115 bool pairing_verified = result.translator_pairing_points.check();
116
117 // Verify IPA opening
118 auto ipa_transcript = std::make_shared<NativeTranscript>(result.ipa_proof);
120 bool ipa_verified = IPA<curve::Grumpkin>::reduce_verify(ipa_vk, result.ipa_claim, ipa_transcript);
121
122 EXPECT_TRUE(pairing_verified && ipa_verified);
123}
124
130{
132
133 auto [proof, merge_commitments, recursive_merge_commitments] = create_goblin_prover_output(&builder);
134
135 auto transcript = std::make_shared<Transcript>();
136 GoblinStdlibProof stdlib_proof(builder, proof);
137 bb::GoblinRecursiveVerifier verifier{ transcript, stdlib_proof, recursive_merge_commitments };
138 auto output = verifier.reduce_to_pairing_check_and_ipa_opening();
139
140 // Aggregate merge + translator pairing points
141 output.translator_pairing_points.aggregate(output.merge_pairing_points);
142
144 inputs.pairing_inputs = output.translator_pairing_points;
145 inputs.ipa_claim = output.ipa_claim;
146 inputs.set_public();
147
148 builder.ipa_proof = output.ipa_proof.get_value();
149
150 info("Recursive Verifier: num gates = ", builder.num_gates());
151
152 EXPECT_EQ(builder.failed(), false) << builder.err();
153
154 EXPECT_TRUE(CircuitChecker::check(builder));
155
156 // Construct and verify a proof for the Goblin Recursive Verifier circuit
157 {
158 auto prover_instance = std::make_shared<OuterProverInstance>(builder);
159 auto verification_key =
160 std::make_shared<typename OuterFlavor::VerificationKey>(prover_instance->get_precomputed());
161 auto vk_and_hash = std::make_shared<typename OuterFlavor::VKAndHash>(verification_key);
162 OuterProver prover(prover_instance, verification_key);
163 OuterVerifier verifier(vk_and_hash);
164 auto proof = prover.construct_proof();
165 bool verified = verifier.verify_proof(proof).result;
166
167 ASSERT_TRUE(verified);
168 }
169}
170
171// Check that the GoblinRecursiveVerifier circuit does not depend on the inputs.
173{
174 // Retrieves the trace blocks (each consisting of a specific gate) from the recursive verifier circuit
175 auto get_blocks = [](size_t inner_size)
176 -> std::tuple<typename Builder::ExecutionTrace, std::shared_ptr<OuterFlavor::VerificationKey>> {
178
179 auto [proof, merge_commitments, recursive_merge_commitments] =
180 create_goblin_prover_output(&builder, inner_size);
181
182 auto transcript = std::make_shared<Transcript>();
183 GoblinStdlibProof stdlib_proof(builder, proof);
184 bb::GoblinRecursiveVerifier verifier{ transcript, stdlib_proof, recursive_merge_commitments };
185 auto output = verifier.reduce_to_pairing_check_and_ipa_opening();
186
187 // Aggregate merge + translator pairing points
188 output.translator_pairing_points.aggregate(output.merge_pairing_points);
189
191 inputs.pairing_inputs = output.translator_pairing_points;
192 inputs.ipa_claim = output.ipa_claim;
193 inputs.set_public();
194
195 builder.ipa_proof = output.ipa_proof.get_value();
196
197 info("Recursive Verifier: num gates = ", builder.num_gates());
198
199 // Construct and verify a proof for the Goblin Recursive Verifier circuit
200 auto prover_instance = std::make_shared<OuterProverInstance>(builder);
201 auto outer_verification_key =
202 std::make_shared<typename OuterFlavor::VerificationKey>(prover_instance->get_precomputed());
203 auto vk_and_hash = std::make_shared<typename OuterFlavor::VKAndHash>(outer_verification_key);
204 OuterProver prover(prover_instance, outer_verification_key);
205 OuterVerifier outer_verifier(vk_and_hash);
206 return { builder.blocks, outer_verification_key };
207 };
208
209 auto [blocks_5, verification_key_5] = get_blocks(5);
210 auto [blocks_6, verification_key_6] = get_blocks(6);
211
212 compare_ultra_blocks_and_verification_keys<OuterFlavor>({ blocks_5, blocks_6 },
213 { verification_key_5, verification_key_6 });
214}
215
221TEST_F(GoblinRecursiveVerifierTests, MergeToTranslatorBindingFailure)
222{
223 auto [proof, merge_commitments, _] = create_goblin_prover_output();
224
225 // Tamper with the op commitment in merge commitments (used by Translator verifier)
226 MergeCommitments tampered_merge_commitments = merge_commitments;
227 tamper_with_op_commitment(tampered_merge_commitments);
229
230 RecursiveMergeCommitments recursive_merge_commitments;
231 for (size_t idx = 0; idx < MegaFlavor::NUM_WIRES; idx++) {
232 recursive_merge_commitments.t_commitments[idx] =
233 RecursiveCommitment::from_witness(&builder, tampered_merge_commitments.t_commitments[idx]);
234 recursive_merge_commitments.T_prev_commitments[idx] =
235 RecursiveCommitment::from_witness(&builder, tampered_merge_commitments.T_prev_commitments[idx]);
236 recursive_merge_commitments.t_commitments[idx].fix_witness();
237 recursive_merge_commitments.T_prev_commitments[idx].fix_witness();
238 }
239
240 auto transcript = std::make_shared<Transcript>();
241 GoblinStdlibProof stdlib_proof(builder, proof);
242 bb::GoblinRecursiveVerifier verifier{ transcript, stdlib_proof, recursive_merge_commitments };
243 auto goblin_rec_verifier_output = verifier.reduce_to_pairing_check_and_ipa_opening();
244
245 // Aggregate merge + translator pairing points
246 goblin_rec_verifier_output.translator_pairing_points.aggregate(goblin_rec_verifier_output.merge_pairing_points);
247
248 // Circuit is correct but pairing check should fail
249 EXPECT_TRUE(CircuitChecker::check(builder));
250
251 // Check that the pairing fails natively
252 bb::PairingPoints<curve::BN254> native_pairing_points(
253 goblin_rec_verifier_output.translator_pairing_points.P0().get_value(),
254 goblin_rec_verifier_output.translator_pairing_points.P1().get_value());
255 bool pairing_result = native_pairing_points.check();
256 EXPECT_FALSE(pairing_result);
257}
258
265TEST_F(GoblinRecursiveVerifierTests, ECCVMToTranslatorBindingFailure)
266{
268
269 auto [proof, merge_commitments, recursive_merge_commitments] = create_goblin_prover_output(&builder);
270
271 // Tamper with the `op` evaluation in the ECCVM proof
272 tamper_with_eccvm_op_eval(proof.eccvm_proof);
273
274 auto transcript = std::make_shared<Transcript>();
275 GoblinStdlibProof stdlib_proof(builder, proof);
276 bb::GoblinRecursiveVerifier verifier{ transcript, stdlib_proof, recursive_merge_commitments };
277 [[maybe_unused]] auto goblin_rec_verifier_output = verifier.reduce_to_pairing_check_and_ipa_opening();
278
279 EXPECT_FALSE(CircuitChecker::check(builder));
280}
281} // namespace bb::stdlib::recursion::honk
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
CommitmentKey object over a pairing group ๐”พโ‚.
Commitment commit(PolynomialSpan< const Fr > polynomial) const
Uses the ProverSRS to create a commitment to p(X)
static constexpr size_t ECCVM_FIXED_SIZE
Simple verification key class for fixed-size circuits (ECCVM, Translator, AVM).
Definition flavor.hpp:101
TranslatorFlavor::VerificationKey TranslatorVerificationKey
Definition goblin.hpp:45
GoblinProof prove()
Constuct a full Goblin proof (ECCVM, Translator, merge)
Definition goblin.cpp:69
std::shared_ptr< OpQueue > op_queue
Definition goblin.hpp:59
ECCVMFlavor::VerificationKey ECCVMVerificationKey
Definition goblin.hpp:44
static void construct_and_merge_mock_circuits(Goblin &goblin, const size_t num_circuits=3)
Unified Goblin verifier for both native and recursive verification.
ReductionResult reduce_to_pairing_check_and_ipa_opening()
Reduce Goblin proof to pairing check and IPA opening claim.
IPA (inner product argument) commitment scheme class.
Definition ipa.hpp:86
static constexpr size_t NUM_WIRES
typename Curve::AffineElement Commitment
An object storing two EC points that represent the inputs to a pairing check.
bool check() const
Verify the pairing equation e(P0, [1]โ‚‚) ยท e(P1, [x]โ‚‚) = 1.
Contains all the information required by a Honk prover to create a proof, constructed from a finalize...
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
Curve::ScalarField FF
static constexpr size_t ZK_ULTRA_OPS
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
static ProverOutput create_goblin_prover_output(Builder *outer_builder=nullptr, const size_t num_circuits=5)
Create a goblin proof and the VM verification keys needed by the goblin recursive verifier.
bb::GoblinRecursiveVerifier::MergeVerifier::InputCommitments RecursiveMergeCommitments
bb::GoblinRecursiveVerifier::MergeVerifier::Commitment RecursiveCommitment
static void tamper_with_op_commitment(MergeCommitments &merge_commitments)
The data that is propagated on the public inputs of a rollup circuit.
#define info(...)
Definition log.hpp:93
AluTraceBuilder builder
Definition alu.test.cpp:124
AvmProvingInputs inputs
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
TEST_F(BoomerangGoblinRecursiveVerifierTests, graph_description_basic)
Construct and check a goblin recursive verification circuit.
std::vector< fr > HonkProof
Definition proof.hpp:15
UltraVerifier_< UltraFlavor, RollupIO > UltraRollupVerifier
BaseTranscript< stdlib::StdlibCodec< stdlib::field_t< UltraCircuitBuilder > >, stdlib::poseidon2< UltraCircuitBuilder > > UltraStdlibTranscript
UltraCircuitBuilder_< UltraExecutionTraceBlocks > UltraCircuitBuilder
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13