barretenberg
Loading...
Searching...
No Matches
goblin.hpp
1#pragma once
2
3#include "barretenberg/eccvm/eccvm_composer.hpp"
4#include "barretenberg/goblin/mock_circuits.hpp"
5#include "barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp"
6#include "barretenberg/proof_system/circuit_builder/goblin_translator_circuit_builder.hpp"
7#include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp"
8#include "barretenberg/proof_system/instance_inspector.hpp"
9#include "barretenberg/stdlib/recursion/honk/verifier/merge_recursive_verifier.hpp"
10#include "barretenberg/translator_vm/goblin_translator_composer.hpp"
11#include "barretenberg/ultra_honk/ultra_composer.hpp"
12
13namespace barretenberg {
14
15class Goblin {
17
20
22 using Commitment = GUHFlavor::Commitment;
23 using FF = GUHFlavor::FF;
24
25 public:
31 HonkProof proof;
32 std::shared_ptr<GUHVerificationKey> verification_key;
33 };
34
35 struct Proof {
36 HonkProof merge_proof;
37 HonkProof eccvm_proof;
38 HonkProof translator_proof;
39 TranslationEvaluations translation_evaluations;
40 std::vector<uint8_t> to_buffer()
41 {
42 // ACIRHACK: so much copying and duplication added here and elsewhere
43 std::vector<uint8_t> translation_evaluations_buf = translation_evaluations.to_buffer();
44 size_t proof_size = merge_proof.proof_data.size() + eccvm_proof.proof_data.size() +
45 translator_proof.proof_data.size() + translation_evaluations_buf.size();
46
47 std::vector<uint8_t> result(proof_size);
48 const auto insert = [&result](const std::vector<uint8_t>& buf) {
49 result.insert(result.end(), buf.begin(), buf.end());
50 };
51 insert(merge_proof.proof_data);
52 insert(eccvm_proof.proof_data);
53 insert(translator_proof.proof_data);
54 insert(translation_evaluations_buf);
55 return result;
56 }
57 };
58
71
72 std::shared_ptr<OpQueue> op_queue = std::make_shared<OpQueue>();
73
74 HonkProof merge_proof;
75
76 // on the first call to accumulate there is no merge proof to verify
77 bool merge_proof_exists{ false };
78
79 private:
80 // TODO(https://github.com/AztecProtocol/barretenberg/issues/798) unique_ptr use is a hack
81 std::unique_ptr<ECCVMBuilder> eccvm_builder;
82 std::unique_ptr<TranslatorBuilder> translator_builder;
83 std::unique_ptr<ECCVMComposer> eccvm_composer;
84 std::unique_ptr<TranslatorComposer> translator_composer;
85
86 AccumulationOutput accumulator; // ACIRHACK
87 Proof proof_; // ACIRHACK
88
89 public:
96 {
97 // Complete the circuit logic by recursively verifying previous merge proof if it exists
98 if (merge_proof_exists) {
99 RecursiveMergeVerifier merge_verifier{ &circuit_builder };
100 [[maybe_unused]] auto pairing_points = merge_verifier.verify_proof(merge_proof);
101 }
102
103 // Construct a Honk proof for the main circuit
104 GoblinUltraComposer composer;
105 auto instance = composer.create_instance(circuit_builder);
106 auto prover = composer.create_prover(instance);
107 auto ultra_proof = prover.construct_proof();
108
109 // Construct and store the merge proof to be recursively verified on the next call to accumulate
110 auto merge_prover = composer.create_merge_prover(op_queue);
111 merge_proof = merge_prover.construct_proof();
112
113 if (!merge_proof_exists) {
114 merge_proof_exists = true;
115 }
116
117 return { ultra_proof, instance->verification_key };
118 };
119
120 Proof prove()
121 {
122 Proof proof;
123
124 proof.merge_proof = std::move(merge_proof);
125
126 eccvm_builder = std::make_unique<ECCVMBuilder>(op_queue);
127 eccvm_composer = std::make_unique<ECCVMComposer>();
128 auto eccvm_prover = eccvm_composer->create_prover(*eccvm_builder);
129 proof.eccvm_proof = eccvm_prover.construct_proof();
130 proof.translation_evaluations = eccvm_prover.translation_evaluations;
131
132 translator_builder = std::make_unique<TranslatorBuilder>(
133 eccvm_prover.translation_batching_challenge_v, eccvm_prover.evaluation_challenge_x, op_queue);
134 translator_composer = std::make_unique<TranslatorComposer>();
135 auto translator_prover = translator_composer->create_prover(*translator_builder, eccvm_prover.transcript);
136 proof.translator_proof = translator_prover.construct_proof();
137
138 return proof;
139 };
140
141 bool verify(const Proof& proof)
142 {
143 MergeVerifier merge_verifier;
144 bool merge_verified = merge_verifier.verify_proof(proof.merge_proof);
145
146 auto eccvm_verifier = eccvm_composer->create_verifier(*eccvm_builder);
147 bool eccvm_verified = eccvm_verifier.verify_proof(proof.eccvm_proof);
148
149 auto translator_verifier = translator_composer->create_verifier(*translator_builder, eccvm_verifier.transcript);
150 bool accumulator_construction_verified = translator_verifier.verify_proof(proof.translator_proof);
151 // TODO(https://github.com/AztecProtocol/barretenberg/issues/799): Ensure translation_evaluations are passed
152 // correctly
153 bool translation_verified = translator_verifier.verify_translation(proof.translation_evaluations);
154
155 return merge_verified && eccvm_verified && accumulator_construction_verified && translation_verified;
156 };
157
158 // ACIRHACK
159 AccumulationOutput accumulate_for_acir(GoblinUltraCircuitBuilder& circuit_builder)
160 {
161 // Complete the circuit logic by recursively verifying previous merge proof if it exists
162 if (merge_proof_exists) {
163 RecursiveMergeVerifier merge_verifier{ &circuit_builder };
164 [[maybe_unused]] auto pairing_points = merge_verifier.verify_proof(merge_proof);
165 }
166
167 // Construct a Honk proof for the main circuit
168 GoblinUltraComposer composer;
169 auto instance = composer.create_instance(circuit_builder);
170 auto prover = composer.create_prover(instance);
171 auto ultra_proof = prover.construct_proof();
172 instance_inspector::inspect_instance(instance);
173
174 // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): no merge prover for now since we're not
175 // mocking the first set of ecc ops
176 // // Construct and store the merge proof to be recursively verified on the next call to accumulate
177 // info("create_merge_prover");
178 // auto merge_prover = composer.create_merge_prover(op_queue);
179 // info("merge_prover.construct_proof()");
180 // merge_proof = merge_prover.construct_proof();
181
182 // if (!merge_proof_exists) {
183 // merge_proof_exists = true;
184 // }
185
186 accumulator = { ultra_proof, instance->verification_key };
187 return accumulator;
188 };
189
190 // ACIRHACK
191 Proof prove_for_acir()
192 {
193 info("Goblin.prove(): op_queue size = ", op_queue->ultra_ops[0].size());
194 Proof proof;
195
196 proof.merge_proof = std::move(merge_proof);
197
198 eccvm_builder = std::make_unique<ECCVMBuilder>(op_queue);
199 eccvm_composer = std::make_unique<ECCVMComposer>();
200 auto eccvm_prover = eccvm_composer->create_prover(*eccvm_builder);
201 proof.eccvm_proof = eccvm_prover.construct_proof();
202 proof.translation_evaluations = eccvm_prover.translation_evaluations;
203
204 translator_builder = std::make_unique<TranslatorBuilder>(
205 eccvm_prover.translation_batching_challenge_v, eccvm_prover.evaluation_challenge_x, op_queue);
206 translator_composer = std::make_unique<TranslatorComposer>();
207 auto translator_prover = translator_composer->create_prover(*translator_builder, eccvm_prover.transcript);
208 proof.translator_proof = translator_prover.construct_proof();
209
210 proof_ = proof; // ACIRHACK
211 return proof;
212 };
213
214 // ACIRHACK
215 bool verify_for_acir(const Proof& proof) const
216 {
217 // ACIRHACK
218 // MergeVerifier merge_verifier;
219 // info("constructed merge_verifier");
220 // bool merge_verified = merge_verifier.verify_proof(proof.merge_proof);
221 // info("verified merge proof. result: ", merge_verified);
222
223 auto eccvm_verifier = eccvm_composer->create_verifier(*eccvm_builder);
224 bool eccvm_verified = eccvm_verifier.verify_proof(proof.eccvm_proof);
225
226 auto translator_verifier = translator_composer->create_verifier(*translator_builder, eccvm_verifier.transcript);
227 bool accumulator_construction_verified = translator_verifier.verify_proof(proof.translator_proof);
228 // TODO(https://github.com/AztecProtocol/barretenberg/issues/799): Ensure translation_evaluations are passed
229 // correctly
230 bool translation_verified = translator_verifier.verify_translation(proof.translation_evaluations);
231
232 return /* merge_verified && */ eccvm_verified && accumulator_construction_verified && translation_verified;
233 };
234
235 // ACIRHACK
236 std::vector<uint8_t> construct_proof(GoblinUltraCircuitBuilder& builder)
237 {
238 info("goblin: construct_proof");
239 accumulate_for_acir(builder);
240 info("accumulate complete.");
241 std::vector<uint8_t> goblin_proof = prove_for_acir().to_buffer();
242 std::vector<uint8_t> result(accumulator.proof.proof_data.size() + goblin_proof.size());
243
244 const auto insert = [&result](const std::vector<uint8_t>& buf) {
245 result.insert(result.end(), buf.begin(), buf.end());
246 };
247 insert(accumulator.proof.proof_data);
248 insert(goblin_proof);
249 return result;
250 }
251
252 // ACIRHACK
253 bool verify_proof([[maybe_unused]] const proof_system::plonk::proof& proof) const
254 {
255 // ACIRHACK: to do this properly, extract the proof correctly or maybe share transcripts.
256 const auto extract_final_kernel_proof = [&]([[maybe_unused]] auto& input_proof) { return accumulator.proof; };
257
258 GoblinUltraVerifier verifier{ accumulator.verification_key };
259 info("constructed GUH verifier");
260 bool verified = verifier.verify_proof(extract_final_kernel_proof(proof));
261 info(" verified GUH proof; result: ", verified);
262
263 const auto extract_goblin_proof = [&]([[maybe_unused]] auto& input_proof) { return proof_; };
264 auto goblin_proof = extract_goblin_proof(proof);
265 info("extracted goblin proof");
266 verified = verified && verify_for_acir(goblin_proof);
267 info("verified goblin proof");
268 return verified;
269 }
270};
271} // namespace barretenberg
Definition: goblin.hpp:15
AccumulationOutput accumulate(GoblinUltraCircuitBuilder &circuit_builder)
If there is a previous merge proof, recursively verify it. Generate next accmulated proof and merge p...
Definition: goblin.hpp:95
Used to construct execution trace representations of elliptic curve operations.
Definition: ecc_op_queue.hpp:18
Definition: eccvm_circuit_builder.hpp:17
GoblinTranslatorCircuitBuilder creates a circuit that evaluates the correctness of the evaluation of ...
Definition: goblin_translator_circuit_builder.hpp:76
Definition: goblin_ultra_circuit_builder.hpp:16
Definition: eccvm_composer.hpp:11
Definition: goblin_translator_composer.hpp:11
Verifier class for the Goblin ECC op queue transcript merge protocol.
Definition: merge_verifier.hpp:18
Definition: ultra_composer.hpp:14
MergeProver_< Flavor > create_merge_prover(const std::shared_ptr< ECCOpQueue > &op_queue, const std::shared_ptr< Transcript > &transcript=std::make_shared< Transcript >())
Create Prover for Goblin ECC op queue merge protocol.
Definition: ultra_composer.hpp:81
Definition: ultra_verifier.hpp:9
Definition: ecc_vm.hpp:927
Definition: goblin_ultra.hpp:24
VerificationKey_< PrecomputedEntities< Commitment > > VerificationKey
The verification key is responsible for storing the the commitments to the precomputed (non-witnessk)...
Definition: goblin_ultra.hpp:287
constexpr_utils defines some helper methods that perform some stl-equivalent operations but in a cons...
Definition: constexpr_utils.hpp:16
Output of goblin::accumulate; an Ultra proof and the corresponding verification key.
Definition: goblin.hpp:30
Definition: goblin.hpp:35
Definition: translation_evaluations.hpp:5
Definition: proof.hpp:11