|
9 | 9 | #include "barretenberg/constants.hpp"
|
10 | 10 | #include "barretenberg/dsl/acir_format/acir_format.hpp"
|
11 | 11 | #include "barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp"
|
| 12 | +#include "barretenberg/dsl/acir_format/ivc_recursion_constraint.hpp" |
12 | 13 | #include "barretenberg/dsl/acir_format/proof_surgeon.hpp"
|
13 | 14 | #include "barretenberg/dsl/acir_proofs/acir_composer.hpp"
|
14 | 15 | #include "barretenberg/dsl/acir_proofs/honk_contract.hpp"
|
@@ -833,6 +834,62 @@ void write_vk_honk(const std::string& bytecodePath, const std::string& outputPat
|
833 | 834 | }
|
834 | 835 | }
|
835 | 836 |
|
| 837 | +/** |
| 838 | + * @brief Compute and write to file a MegaHonk VK for a circuit to be accumulated in the IVC |
| 839 | + * @note This method differes from write_vk_honk<MegaFlavor> in that it handles kernel circuits which require special |
| 840 | + * treatment (i.e. construction of mock IVC state to correctly complete the kernel logic). |
| 841 | + * |
| 842 | + * @param bytecodePath |
| 843 | + * @param witnessPath |
| 844 | + */ |
| 845 | +void write_vk_for_ivc(const std::string& bytecodePath, const std::string& outputPath) |
| 846 | +{ |
| 847 | + using Builder = ClientIVC::ClientCircuit; |
| 848 | + using Prover = ClientIVC::MegaProver; |
| 849 | + using DeciderProvingKey = ClientIVC::DeciderProvingKey; |
| 850 | + using VerificationKey = ClientIVC::MegaVerificationKey; |
| 851 | + |
| 852 | + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1163) set these dynamically |
| 853 | + init_bn254_crs(1 << 20); |
| 854 | + init_grumpkin_crs(1 << 15); |
| 855 | + |
| 856 | + auto constraints = get_constraint_system(bytecodePath, /*honk_recursion=*/false); |
| 857 | + acir_format::WitnessVector witness = {}; |
| 858 | + |
| 859 | + TraceSettings trace_settings{ E2E_FULL_TEST_STRUCTURE }; |
| 860 | + |
| 861 | + // The presence of ivc recursion constraints determines whether or not the program is a kernel |
| 862 | + bool is_kernel = !constraints.ivc_recursion_constraints.empty(); |
| 863 | + |
| 864 | + Builder builder; |
| 865 | + if (is_kernel) { |
| 866 | + // Create a mock IVC instance based on the IVC recursion constraints in the kernel program |
| 867 | + ClientIVC mock_ivc = create_mock_ivc_from_constraints(constraints.ivc_recursion_constraints, trace_settings); |
| 868 | + builder = acir_format::create_kernel_circuit(constraints, mock_ivc, witness); |
| 869 | + } else { |
| 870 | + builder = acir_format::create_circuit<Builder>( |
| 871 | + constraints, /*recursive=*/false, 0, witness, /*honk_recursion=*/false); |
| 872 | + } |
| 873 | + // Add public inputs corresponding to pairing point accumulator |
| 874 | + builder.add_pairing_point_accumulator(stdlib::recursion::init_default_agg_obj_indices<Builder>(builder)); |
| 875 | + |
| 876 | + // Construct the verification key via the prover-constructed proving key with the proper trace settings |
| 877 | + auto proving_key = std::make_shared<DeciderProvingKey>(builder, trace_settings); |
| 878 | + Prover prover{ proving_key }; |
| 879 | + init_bn254_crs(prover.proving_key->proving_key.circuit_size); |
| 880 | + VerificationKey vk(prover.proving_key->proving_key); |
| 881 | + |
| 882 | + // Write the VK to file as a buffer |
| 883 | + auto serialized_vk = to_buffer(vk); |
| 884 | + if (outputPath == "-") { |
| 885 | + writeRawBytesToStdout(serialized_vk); |
| 886 | + vinfo("vk written to stdout"); |
| 887 | + } else { |
| 888 | + write_file(outputPath, serialized_vk); |
| 889 | + vinfo("vk written to: ", outputPath); |
| 890 | + } |
| 891 | +} |
| 892 | + |
836 | 893 | /**
|
837 | 894 | * @brief Write a toml file containing recursive verifier inputs for a given program + witness
|
838 | 895 | *
|
@@ -1073,7 +1130,8 @@ int main(int argc, char* argv[])
|
1073 | 1130 |
|
1074 | 1131 | const API::Flags flags = [&args]() {
|
1075 | 1132 | return API::Flags{ .output_type = get_option(args, "--output_type", "fields_msgpack"),
|
1076 |
| - .input_type = get_option(args, "--input_type", "compiletime_stack") }; |
| 1133 | + .input_type = get_option(args, "--input_type", "compiletime_stack"), |
| 1134 | + .no_auto_verify = flag_present(args, "--no_auto_verify") }; |
1077 | 1135 | }();
|
1078 | 1136 |
|
1079 | 1137 | const std::string command = args[0];
|
@@ -1227,6 +1285,9 @@ int main(int argc, char* argv[])
|
1227 | 1285 | } else if (command == "write_vk_mega_honk") {
|
1228 | 1286 | std::string output_path = get_option(args, "-o", "./target/vk");
|
1229 | 1287 | write_vk_honk<MegaFlavor>(bytecode_path, output_path, recursive);
|
| 1288 | + } else if (command == "write_vk_for_ivc") { |
| 1289 | + std::string output_path = get_option(args, "-o", "./target/vk"); |
| 1290 | + write_vk_for_ivc(bytecode_path, output_path); |
1230 | 1291 | } else if (command == "proof_as_fields_honk") {
|
1231 | 1292 | std::string output_path = get_option(args, "-o", proof_path + "_fields.json");
|
1232 | 1293 | proof_as_fields_honk(proof_path, output_path);
|
|
0 commit comments