|
3 | 3 | #include "barretenberg/bb/acir_format_getters.hpp"
|
4 | 4 | #include "barretenberg/bb/api.hpp"
|
5 | 5 | #include "barretenberg/bb/init_srs.hpp"
|
| 6 | +#include "barretenberg/client_ivc/mock_circuit_producer.hpp" |
6 | 7 | #include "barretenberg/common/throw_or_abort.hpp"
|
7 | 8 | #include "libdeflate.h"
|
8 | 9 |
|
@@ -125,35 +126,22 @@ class ClientIVCAPI : public API {
|
125 | 126 | return folding_stack;
|
126 | 127 | };
|
127 | 128 |
|
128 |
| - static std::shared_ptr<ClientIVC> _accumulate(std::vector<acir_format::AcirProgram>& folding_stack, |
129 |
| - bool auto_verify = false) |
| 129 | + static std::shared_ptr<ClientIVC> _accumulate(std::vector<acir_format::AcirProgram>& folding_stack) |
130 | 130 | {
|
131 | 131 | using Builder = MegaCircuitBuilder;
|
132 | 132 | using Program = acir_format::AcirProgram;
|
133 | 133 | using namespace acir_format;
|
134 | 134 |
|
135 |
| - vinfo("performing accumulation with auto-verify = ", auto_verify); |
136 |
| - |
137 | 135 | TraceSettings trace_settings{ E2E_FULL_TEST_STRUCTURE };
|
138 |
| - auto ivc = std::make_shared<ClientIVC>(trace_settings, auto_verify); |
| 136 | + auto ivc = std::make_shared<ClientIVC>(trace_settings); |
139 | 137 |
|
140 | 138 | const ProgramMetadata metadata{ ivc };
|
141 | 139 |
|
142 | 140 | // Accumulate the entire program stack into the IVC
|
143 |
| - // TODO(https://github.com/AztecProtocol/barretenberg/issues/1116): remove manual setting of is_kernel |
144 |
| - bool is_kernel = false; |
145 | 141 | for (Program& program : folding_stack) {
|
146 | 142 | // Construct a bberg circuit from the acir representation then accumulate it into the IVC
|
147 | 143 | Builder circuit = acir_format::create_circuit<Builder>(program, metadata);
|
148 | 144 |
|
149 |
| - // Set the internal is_kernel flag based on the local mechanism only if it has not already been set to true |
150 |
| - if (ivc->auto_verify_mode) { |
151 |
| - if (!circuit.databus_propagation_data.is_kernel) { |
152 |
| - circuit.databus_propagation_data.is_kernel = is_kernel; |
153 |
| - } |
154 |
| - is_kernel = !is_kernel; |
155 |
| - } |
156 |
| - |
157 | 145 | // Do one step of ivc accumulator or, if there is only one circuit in the stack, prove that circuit. In this
|
158 | 146 | // case, no work is added to the Goblin opqueue, but VM proofs for trivials inputs are produced.
|
159 | 147 | ivc->accumulate(circuit, /*one_circuit=*/folding_stack.size() == 1);
|
@@ -183,8 +171,7 @@ class ClientIVCAPI : public API {
|
183 | 171 | std::vector<acir_format::AcirProgram> folding_stack =
|
184 | 172 | _build_folding_stack(*flags.input_type, bytecode_path, witness_path);
|
185 | 173 |
|
186 |
| - bool auto_verify = !flags.no_auto_verify; |
187 |
| - std::shared_ptr<ClientIVC> ivc = _accumulate(folding_stack, auto_verify); |
| 174 | + std::shared_ptr<ClientIVC> ivc = _accumulate(folding_stack); |
188 | 175 | ClientIVC::Proof proof = ivc->prove();
|
189 | 176 |
|
190 | 177 | // Write the proof and verification keys into the working directory in 'binary' format (in practice it seems
|
@@ -246,11 +233,56 @@ class ClientIVCAPI : public API {
|
246 | 233 |
|
247 | 234 | std::vector<acir_format::AcirProgram> folding_stack =
|
248 | 235 | _build_folding_stack(*flags.input_type, bytecode_path, witness_path);
|
249 |
| - std::shared_ptr<ClientIVC> ivc = _accumulate(folding_stack, /*auto_verify=*/true); |
| 236 | + std::shared_ptr<ClientIVC> ivc = _accumulate(folding_stack); |
250 | 237 | const bool verified = ivc->prove_and_verify();
|
251 | 238 | return verified;
|
252 | 239 | };
|
253 | 240 |
|
| 241 | + /** |
| 242 | + * @brief Write an arbitrary but valid ClientIVC proof and VK to files |
| 243 | + * @details used to test the prove_tube flow |
| 244 | + * |
| 245 | + * @param flags |
| 246 | + * @param output_dir |
| 247 | + */ |
| 248 | + void write_arbitrary_valid_proof_and_vk_to_file(const API::Flags& flags, |
| 249 | + const std::filesystem::path& output_dir) override |
| 250 | + { |
| 251 | + if (!flags.output_type || *flags.output_type != "fields_msgpack") { |
| 252 | + throw_or_abort("No output_type or output_type not supported"); |
| 253 | + } |
| 254 | + |
| 255 | + if (!flags.input_type || !(*flags.input_type == "compiletime_stack" || *flags.input_type == "runtime_stack")) { |
| 256 | + throw_or_abort("No input_type or input_type not supported"); |
| 257 | + } |
| 258 | + |
| 259 | + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1163) set these dynamically |
| 260 | + init_bn254_crs(1 << 20); |
| 261 | + init_grumpkin_crs(1 << 15); |
| 262 | + |
| 263 | + ClientIVC ivc{ { CLIENT_IVC_BENCH_STRUCTURE } }; |
| 264 | + |
| 265 | + // Construct and accumulate a series of mocked private function execution circuits |
| 266 | + PrivateFunctionExecutionMockCircuitProducer circuit_producer; |
| 267 | + size_t NUM_CIRCUITS = 2; |
| 268 | + for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { |
| 269 | + auto circuit = circuit_producer.create_next_circuit(ivc); |
| 270 | + ivc.accumulate(circuit); |
| 271 | + } |
| 272 | + |
| 273 | + ClientIVC::Proof proof = ivc.prove(); |
| 274 | + |
| 275 | + // Write the proof and verification keys into the working directory in 'binary' format |
| 276 | + vinfo("writing ClientIVC proof and vk..."); |
| 277 | + write_file(output_dir / "client_ivc_proof", to_buffer(proof)); |
| 278 | + |
| 279 | + auto eccvm_vk = std::make_shared<ECCVMFlavor::VerificationKey>(ivc.goblin.get_eccvm_proving_key()); |
| 280 | + auto translator_vk = |
| 281 | + std::make_shared<TranslatorFlavor::VerificationKey>(ivc.goblin.get_translator_proving_key()); |
| 282 | + write_file(output_dir / "client_ivc_vk", |
| 283 | + to_buffer(ClientIVC::VerificationKey{ ivc.honk_vk, eccvm_vk, translator_vk })); |
| 284 | + }; |
| 285 | + |
254 | 286 | void gates([[maybe_unused]] const API::Flags& flags,
|
255 | 287 | [[maybe_unused]] const std::filesystem::path& bytecode_path,
|
256 | 288 | [[maybe_unused]] const std::filesystem::path& witness_path) override
|
|
0 commit comments