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.
10
12class GoblinRecursiveVerifierTests : public testing::Test {
13 public:
17
22
24 using RecursiveCommitment = bb::GoblinRecursiveVerifier::MergeVerifier::Commitment;
26 using RecursiveMergeCommitments = bb::GoblinRecursiveVerifier::MergeVerifier::InputCommitments;
30
36 static void tamper_with_op_commitment(MergeCommitments& merge_commitments)
37 {
38 // The first commitment in merged table is the `op` wire commitment
39 merge_commitments.t_commitments[0] = merge_commitments.t_commitments[0] * FF(2);
40 };
41
42 // ECCVM pre-IPA proof ends with evaluations including `op`. We tamper with the `op` evaluation.
43 // The structure is: [..., op_eval, x_lo_y_hi_eval, x_hi_z_1_eval, y_lo_z_2_eval, IPA_proof...]
44 // So op_eval is 3 fields before the IPA proof starts.
45 static void tamper_with_eccvm_op_eval(HonkProof& eccvm_proof)
46 {
47 // The `op` evaluation is located 3 evaluations before the end of pre-IPA proof
48 // (followed by x_lo_y_hi, x_hi_z_1, y_lo_z_2 evaluations)
49 static constexpr size_t evals_after_op = 3; // x_lo_y_hi, x_hi_z_1, y_lo_z_2
50 const size_t op_eval_idx = eccvm_proof.size() - evals_after_op;
51
52 // Tamper with the op evaluation
53 eccvm_proof[op_eval_idx] += FF(1);
54 };
55
61 static ProverOutput create_goblin_prover_output(Builder* outer_builder = nullptr, const size_t num_circuits = 5)
62 {
63
64 Goblin goblin;
66
67 // Merge the ecc ops from the newly constructed circuit
68 auto goblin_proof = goblin.prove();
69 // Subtable values and commitments - needed for (Recursive)MergeVerifier
70 MergeCommitments merge_commitments;
71 auto t_current = goblin.op_queue->construct_current_ultra_ops_subtable_columns();
72 auto T_prev = goblin.op_queue->construct_previous_ultra_ops_table_columns();
73 CommitmentKey<curve::BN254> pcs_commitment_key(goblin.op_queue->get_ultra_ops_table_num_rows());
74 for (size_t idx = 0; idx < MegaFlavor::NUM_WIRES; idx++) {
75 merge_commitments.t_commitments[idx] = pcs_commitment_key.commit(t_current[idx]);
76 merge_commitments.T_prev_commitments[idx] = pcs_commitment_key.commit(T_prev[idx]);
77 }
78
79 RecursiveMergeCommitments recursive_merge_commitments;
80 if (outer_builder != nullptr) {
81 for (size_t idx = 0; idx < MegaFlavor::NUM_WIRES; idx++) {
82 recursive_merge_commitments.t_commitments[idx] =
83 RecursiveCommitment::from_witness(outer_builder, merge_commitments.t_commitments[idx]);
84 recursive_merge_commitments.T_prev_commitments[idx] =
85 RecursiveCommitment::from_witness(outer_builder, merge_commitments.T_prev_commitments[idx]);
86 // Removing the free witness tag, since the merge commitments in the full scheme are supposed to
87 // be fiat-shamirred earlier
88 recursive_merge_commitments.t_commitments[idx].unset_free_witness_tag();
89 recursive_merge_commitments.T_prev_commitments[idx].unset_free_witness_tag();
90 }
91 }
92
93 // Output is a goblin proof plus merge commitments
94 return { goblin_proof, merge_commitments, recursive_merge_commitments };
95 }
96};
97
103{
104 auto [proof, merge_commitments, _] = create_goblin_prover_output();
105
106 auto transcript = std::make_shared<NativeTranscript>();
107 bb::GoblinVerifier verifier(transcript, proof, merge_commitments, MergeSettings::APPEND);
108 auto result = verifier.reduce_to_pairing_check_and_ipa_opening();
109
110 // Check pairing points (aggregate merge + translator)
111 result.translator_pairing_points.aggregate(result.merge_pairing_points);
112 bool pairing_verified = result.translator_pairing_points.check();
113
114 // Verify IPA opening
115 auto ipa_transcript = std::make_shared<NativeTranscript>(result.ipa_proof);
117 bool ipa_verified = IPA<curve::Grumpkin>::reduce_verify(ipa_vk, result.ipa_claim, ipa_transcript);
118
119 EXPECT_TRUE(pairing_verified && ipa_verified);
120}
121
127{
129
130 auto [proof, merge_commitments, recursive_merge_commitments] = create_goblin_prover_output(&builder);
131
132 auto transcript = std::make_shared<Transcript>();
133 GoblinStdlibProof stdlib_proof(builder, proof);
135 transcript, stdlib_proof, recursive_merge_commitments, MergeSettings::APPEND
136 };
137 auto output = verifier.reduce_to_pairing_check_and_ipa_opening();
138
139 // Aggregate merge + translator pairing points
140 output.translator_pairing_points.aggregate(output.merge_pairing_points);
141
143 inputs.pairing_inputs = output.translator_pairing_points;
144 inputs.ipa_claim = output.ipa_claim;
145 inputs.set_public();
146
147 builder.ipa_proof = output.ipa_proof.get_value();
148
149 info("Recursive Verifier: num gates = ", builder.num_gates());
150
151 EXPECT_EQ(builder.failed(), false) << builder.err();
152
153 EXPECT_TRUE(CircuitChecker::check(builder));
154
155 // Construct and verify a proof for the Goblin Recursive Verifier circuit
156 {
157 auto prover_instance = std::make_shared<OuterProverInstance>(builder);
158 auto verification_key =
159 std::make_shared<typename OuterFlavor::VerificationKey>(prover_instance->get_precomputed());
160 auto vk_and_hash = std::make_shared<typename OuterFlavor::VKAndHash>(verification_key);
161 OuterProver prover(prover_instance, verification_key);
162 OuterVerifier verifier(vk_and_hash);
163 auto proof = prover.construct_proof();
164 bool verified = verifier.verify_proof(proof).result;
165
166 ASSERT_TRUE(verified);
167 }
168}
169
170// Check that the GoblinRecursiveVerifier circuit does not depend on the inputs.
172{
173 // Retrieves the trace blocks (each consisting of a specific gate) from the recursive verifier circuit
174 auto get_blocks = [](size_t inner_size)
175 -> std::tuple<typename Builder::ExecutionTrace, std::shared_ptr<OuterFlavor::VerificationKey>> {
177
178 auto [proof, merge_commitments, recursive_merge_commitments] =
179 create_goblin_prover_output(&builder, inner_size);
180
181 auto transcript = std::make_shared<Transcript>();
182 GoblinStdlibProof stdlib_proof(builder, proof);
184 transcript, stdlib_proof, recursive_merge_commitments, MergeSettings::APPEND
185 };
186 auto output = verifier.reduce_to_pairing_check_and_ipa_opening();
187
188 // Aggregate merge + translator pairing points
189 output.translator_pairing_points.aggregate(output.merge_pairing_points);
190
192 inputs.pairing_inputs = output.translator_pairing_points;
193 inputs.ipa_claim = output.ipa_claim;
194 inputs.set_public();
195
196 builder.ipa_proof = output.ipa_proof.get_value();
197
198 info("Recursive Verifier: num gates = ", builder.num_gates());
199
200 // Construct and verify a proof for the Goblin Recursive Verifier circuit
201 auto prover_instance = std::make_shared<OuterProverInstance>(builder);
202 auto outer_verification_key =
203 std::make_shared<typename OuterFlavor::VerificationKey>(prover_instance->get_precomputed());
204 auto vk_and_hash = std::make_shared<typename OuterFlavor::VKAndHash>(outer_verification_key);
205 OuterProver prover(prover_instance, outer_verification_key);
206 OuterVerifier outer_verifier(vk_and_hash);
207 return { builder.blocks, outer_verification_key };
208 };
209
210 auto [blocks_5, verification_key_5] = get_blocks(5);
211 auto [blocks_6, verification_key_6] = get_blocks(6);
212
213 compare_ultra_blocks_and_verification_keys<OuterFlavor>({ blocks_5, blocks_6 },
214 { verification_key_5, verification_key_6 });
215}
216
222TEST_F(GoblinRecursiveVerifierTests, MergeToTranslatorBindingFailure)
223{
224 auto [proof, merge_commitments, _] = create_goblin_prover_output();
225
226 // Tamper with the op commitment in merge commitments (used by Translator verifier)
227 MergeCommitments tampered_merge_commitments = merge_commitments;
228 tamper_with_op_commitment(tampered_merge_commitments);
230
231 RecursiveMergeCommitments recursive_merge_commitments;
232 for (size_t idx = 0; idx < MegaFlavor::NUM_WIRES; idx++) {
233 recursive_merge_commitments.t_commitments[idx] =
234 RecursiveCommitment::from_witness(&builder, tampered_merge_commitments.t_commitments[idx]);
235 recursive_merge_commitments.T_prev_commitments[idx] =
236 RecursiveCommitment::from_witness(&builder, tampered_merge_commitments.T_prev_commitments[idx]);
237 recursive_merge_commitments.t_commitments[idx].fix_witness();
238 recursive_merge_commitments.T_prev_commitments[idx].fix_witness();
239 }
240
241 auto transcript = std::make_shared<Transcript>();
242 GoblinStdlibProof stdlib_proof(builder, proof);
244 transcript, stdlib_proof, recursive_merge_commitments, MergeSettings::APPEND
245 };
246 auto goblin_rec_verifier_output = verifier.reduce_to_pairing_check_and_ipa_opening();
247
248 // Aggregate merge + translator pairing points
249 goblin_rec_verifier_output.translator_pairing_points.aggregate(goblin_rec_verifier_output.merge_pairing_points);
250
251 // Circuit is correct but pairing check should fail
252 EXPECT_TRUE(CircuitChecker::check(builder));
253
254 // Check that the pairing fails natively
255 bb::PairingPoints<curve::BN254> native_pairing_points(
256 goblin_rec_verifier_output.translator_pairing_points.P0().get_value(),
257 goblin_rec_verifier_output.translator_pairing_points.P1().get_value());
258 bool pairing_result = native_pairing_points.check();
259 EXPECT_FALSE(pairing_result);
260}
261
268TEST_F(GoblinRecursiveVerifierTests, ECCVMToTranslatorBindingFailure)
269{
271
272 auto [proof, merge_commitments, recursive_merge_commitments] = create_goblin_prover_output(&builder);
273
274 // Tamper with the `op` evaluation in the ECCVM proof
275 tamper_with_eccvm_op_eval(proof.eccvm_proof);
276
277 auto transcript = std::make_shared<Transcript>();
278 GoblinStdlibProof stdlib_proof(builder, proof);
280 transcript, stdlib_proof, recursive_merge_commitments, MergeSettings::APPEND
281 };
282 [[maybe_unused]] auto goblin_rec_verifier_output = verifier.reduce_to_pairing_check_and_ipa_opening();
283
284 EXPECT_FALSE(CircuitChecker::check(builder));
285}
286} // 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:42
GoblinProof prove()
Constuct a full Goblin proof (ECCVM, Translator, merge)
Definition goblin.cpp:61
std::shared_ptr< OpQueue > op_queue
Definition goblin.hpp:54
ECCVMFlavor::VerificationKey ECCVMVerificationKey
Definition goblin.hpp:41
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
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