diff --git a/barretenberg/cpp/src/CMakeLists.txt b/barretenberg/cpp/src/CMakeLists.txt index 0ca963d4f87..65176f7c421 100644 --- a/barretenberg/cpp/src/CMakeLists.txt +++ b/barretenberg/cpp/src/CMakeLists.txt @@ -137,7 +137,8 @@ set(BARRETENBERG_TARGET_OBJECTS $ $ $ - $) + $ + $) add_library( barretenberg diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index b49d6f95908..fa91f8f3667 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -1,5 +1,9 @@ +#include "barretenberg/bb/file_io.hpp" +#include "barretenberg/common/serialize.hpp" #include "barretenberg/dsl/types.hpp" +#include "barretenberg/honk/proof_system/types/proof.hpp" #include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" +#include "barretenberg/vm/avm_trace/AvmMini_execution.hpp" #include "config.hpp" #include "get_bn254_crs.hpp" #include "get_bytecode.hpp" @@ -12,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -506,6 +511,7 @@ int main(int argc, char* argv[]) if (command == "prove_and_verify_goblin") { return proveAndVerifyGoblin(bytecode_path, witness_path) ? 0 : 1; } + if (command == "prove") { std::string output_path = get_option(args, "-o", "./proofs/proof"); prove(bytecode_path, witness_path, output_path); @@ -528,6 +534,23 @@ int main(int argc, char* argv[]) } else if (command == "vk_as_fields") { std::string output_path = get_option(args, "-o", vk_path + "_fields.json"); vk_as_fields(vk_path, output_path); + } else if (command == "avm_prove") { + std::string avm_bytecode_path = get_option(args, "-b", "./target/avm_bytecode.bin"); + std::string output_path = get_option(args, "-o", "./proofs/avm_proof"); + std::vector call_data_bytes{}; + + if (flag_present(args, "-d")) { + auto const call_data_path = get_option(args, "-d", "./target/call_data.bin"); + call_data_bytes = read_file(call_data_path); + } + + srs::init_crs_factory("../srs_db/ignition"); + + std::vector const call_data = many_from_buffer(call_data_bytes); + auto const avm_bytecode = read_file(avm_bytecode_path); + auto const proof = avm_trace::Execution::run_and_prove(avm_bytecode, call_data); + std::vector const proof_bytes = to_buffer(proof); + write_file(output_path, proof_bytes); } else { std::cerr << "Unknown command: " << command << "\n"; return 1; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.cpp index 9a5f8f5a396..53019fb77ce 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.cpp @@ -1,5 +1,6 @@ #include "AvmMini_execution.hpp" #include "barretenberg/common/serialize.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp" #include "barretenberg/vm/avm_trace/AvmMini_common.hpp" #include "barretenberg/vm/avm_trace/AvmMini_instructions.hpp" @@ -56,7 +57,7 @@ std::vector Execution::parse(std::vector const& bytecode) pos += AVM_OPCODE_BYTE_LENGTH; if (!Bytecode::is_valid(opcode_byte)) { - throw std::runtime_error("Invalid opcode byte: " + std::to_string(opcode_byte)); + throw_or_abort("Invalid opcode byte: " + std::to_string(opcode_byte)); } const auto opcode = static_cast(opcode_byte); @@ -64,12 +65,12 @@ std::vector Execution::parse(std::vector const& bytecode) if (Bytecode::has_in_tag(opcode)) { if (pos + AVM_IN_TAG_BYTE_LENGTH > length) { - throw std::runtime_error("Instruction tag missing at position " + std::to_string(pos)); + throw_or_abort("Instruction tag missing at position " + std::to_string(pos)); } in_tag_u8 = bytecode.at(pos); if (in_tag_u8 == static_cast(AvmMemoryTag::U0) || in_tag_u8 > MAX_MEM_TAG) { - throw std::runtime_error("Instruction tag is invalid at position " + std::to_string(pos) + - " value: " + std::to_string(in_tag_u8)); + throw_or_abort("Instruction tag is invalid at position " + std::to_string(pos) + + " value: " + std::to_string(in_tag_u8)); } pos += AVM_IN_TAG_BYTE_LENGTH; } @@ -109,8 +110,8 @@ std::vector Execution::parse(std::vector const& bytecode) operands_size = 20; break; default: - throw std::runtime_error("Instruction tag for SET opcode is invalid at position " + - std::to_string(pos) + " value: " + std::to_string(in_tag_u8)); + throw_or_abort("Instruction tag for SET opcode is invalid at position " + std::to_string(pos) + + " value: " + std::to_string(in_tag_u8)); break; } } else { @@ -119,7 +120,7 @@ std::vector Execution::parse(std::vector const& bytecode) } if (pos + operands_size > length) { - throw std::runtime_error("Operand is missing at position " + std::to_string(pos)); + throw_or_abort("Operand is missing at position " + std::to_string(pos)); } // We handle operands which are encoded with less than 4 bytes. diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.hpp index ae041f65bb0..6c31f52d040 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.hpp @@ -22,7 +22,8 @@ class Execution { static std::vector parse(std::vector const& bytecode); static std::vector gen_trace(std::vector const& instructions, std::vector const& calldata); - static bb::HonkProof run_and_prove(std::vector const& bytecode, std::vector const& calldata); + static bb::HonkProof run_and_prove(std::vector const& bytecode, + std::vector const& calldata = std::vector{}); }; } // namespace avm_trace \ No newline at end of file