diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index d44a5321f2b..29692fa1a64 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -547,7 +547,7 @@ void avm_prove(const std::filesystem::path& bytecode_path, init_bn254_crs(1 << 17); // Prove execution and return vk - auto const [verification_key, proof] = avm_trace::Execution::prove(bytecode, calldata); + auto const [verification_key, proof] = avm_trace::Execution::prove(bytecode, calldata, public_inputs_vec); // TODO(ilyas): <#4887>: Currently we only need these two parts of the vk, look into pcs_verification key reqs std::vector vk_vector = { verification_key.circuit_size, verification_key.num_public_inputs }; std::vector vk_as_fields = { verification_key.circuit_size, verification_key.num_public_inputs }; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp index e45b8f80afc..a2707bb932f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp @@ -32,8 +32,8 @@ namespace bb::avm_trace { std::vector Execution::getDefaultPublicInputs() { std::vector public_inputs_vec(PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH); - public_inputs_vec.at(DA_GAS_LEFT_CONTEXT_INPUTS_OFFSET) = 1000000000; - public_inputs_vec.at(L2_GAS_LEFT_CONTEXT_INPUTS_OFFSET) = 1000000000; + public_inputs_vec.at(DA_START_GAS_LEFT_PCPI_OFFSET) = 1000000000; + public_inputs_vec.at(L2_START_GAS_LEFT_PCPI_OFFSET) = 1000000000; return public_inputs_vec; } @@ -51,19 +51,25 @@ std::tuple Execution::prove(std::vector const& public_inputs_vec, ExecutionHints const& execution_hints) { - // TODO: temp - info("logging to silence warning for now: ", public_inputs_vec.size()); + if (public_inputs_vec.size() != PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH) { + throw_or_abort("Public inputs vector is not of PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH"); + } auto instructions = Deserialization::parse(bytecode); std::vector returndata{}; - auto trace = gen_trace(instructions, returndata, calldata, getDefaultPublicInputs(), execution_hints); + auto trace = gen_trace(instructions, returndata, calldata, public_inputs_vec, execution_hints); auto circuit_builder = bb::AvmCircuitBuilder(); circuit_builder.set_trace(std::move(trace)); auto composer = AvmComposer(); auto prover = composer.create_prover(circuit_builder); auto verifier = composer.create_verifier(circuit_builder); - auto proof = prover.construct_proof(); + + // The proof starts with the serialized public inputs + HonkProof proof(public_inputs_vec); + auto raw_proof = prover.construct_proof(); + // append the raw proof after the public inputs + proof.insert(proof.end(), raw_proof.begin(), raw_proof.end()); // TODO(#4887): Might need to return PCS vk when full verify is supported return std::make_tuple(*verifier.key, proof); } @@ -130,8 +136,8 @@ VmPublicInputs Execution::convert_public_inputs(std::vector const& public_in // Transaction fee kernel_inputs[TRANSACTION_FEE_SELECTOR] = public_inputs_vec[TRANSACTION_FEE_OFFSET]; - kernel_inputs[DA_GAS_LEFT_CONTEXT_INPUTS_OFFSET] = public_inputs_vec[DA_GAS_LEFT_CONTEXT_INPUTS_OFFSET]; - kernel_inputs[L2_GAS_LEFT_CONTEXT_INPUTS_OFFSET] = public_inputs_vec[L2_GAS_LEFT_CONTEXT_INPUTS_OFFSET]; + kernel_inputs[DA_GAS_LEFT_CONTEXT_INPUTS_OFFSET] = public_inputs_vec[DA_START_GAS_LEFT_PCPI_OFFSET]; + kernel_inputs[L2_GAS_LEFT_CONTEXT_INPUTS_OFFSET] = public_inputs_vec[L2_START_GAS_LEFT_PCPI_OFFSET]; return public_inputs; } @@ -146,10 +152,15 @@ bool Execution::verify(AvmFlavor::VerificationKey vk, HonkProof const& proof) // crs_factory_); // output_state.pcs_verification_key = std::move(pcs_verification_key); - // TODO: We hardcode public inputs for now - VmPublicInputs public_inputs = convert_public_inputs(getDefaultPublicInputs()); - std::vector> public_inputs_vec = copy_public_inputs_columns(public_inputs); - return verifier.verify_proof(proof, public_inputs_vec); + std::vector public_inputs_vec; + std::vector raw_proof; + std::copy( + proof.begin(), proof.begin() + PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH, std::back_inserter(public_inputs_vec)); + std::copy(proof.begin() + PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH, proof.end(), std::back_inserter(raw_proof)); + + VmPublicInputs public_inputs = convert_public_inputs(public_inputs_vec); + std::vector> public_inputs_columns = copy_public_inputs_columns(public_inputs); + return verifier.verify_proof(raw_proof, public_inputs_columns); } /** diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp index aa4696f0aa6..2b6175febf1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp @@ -33,10 +33,11 @@ class Execution { std::vector const& public_inputs, ExecutionHints const& execution_hints); - static std::tuple prove(std::vector const& bytecode, - std::vector const& calldata = {}, - std::vector const& public_inputs_vec = {}, - ExecutionHints const& execution_hints = {}); + static std::tuple prove( + std::vector const& bytecode, + std::vector const& calldata = {}, + std::vector const& public_inputs_vec = getDefaultPublicInputs(), + ExecutionHints const& execution_hints = {}); static bool verify(AvmFlavor::VerificationKey vk, HonkProof const& proof); }; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/constants.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/constants.hpp index 9a38bfee590..7dcc8b5bbe4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/constants.hpp @@ -31,8 +31,8 @@ inline const uint32_t FEE_PER_DA_GAS_OFFSET = PCPI_GLOBALS_START + 6; inline const uint32_t FEE_PER_L2_GAS_OFFSET = PCPI_GLOBALS_START + 7; inline const uint32_t TRANSACTION_FEE_OFFSET = PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH - 1; -inline const uint32_t DA_GAS_LEFT_PCPI_OFFSET = PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH - 3 - GAS_LENGTH; -inline const uint32_t L2_GAS_LEFT_PCPI_OFFSET = PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH - 2 - GAS_LENGTH; +inline const uint32_t DA_START_GAS_LEFT_PCPI_OFFSET = PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH - 3 - GAS_LENGTH; +inline const uint32_t L2_START_GAS_LEFT_PCPI_OFFSET = PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH - 2 - GAS_LENGTH; // Kernel output pil offset (Where update objects are inlined) diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp index a18b0b5403f..06515d77ef0 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp @@ -33,8 +33,8 @@ class AvmExecutionTests : public ::testing::Test { void SetUp() override { srs::init_crs_factory("../srs_db/ignition"); - public_inputs_vec.at(DA_GAS_LEFT_CONTEXT_INPUTS_OFFSET) = DEFAULT_INITIAL_DA_GAS; - public_inputs_vec.at(L2_GAS_LEFT_CONTEXT_INPUTS_OFFSET) = DEFAULT_INITIAL_L2_GAS; + public_inputs_vec.at(DA_START_GAS_LEFT_PCPI_OFFSET) = DEFAULT_INITIAL_DA_GAS; + public_inputs_vec.at(L2_START_GAS_LEFT_PCPI_OFFSET) = DEFAULT_INITIAL_L2_GAS; }; /**