From f3ed39bf7be6f08bcfcabf6c04eb570f4d06ed27 Mon Sep 17 00:00:00 2001 From: Ilyas Ridhuan Date: Thu, 10 Oct 2024 16:57:58 +0100 Subject: [PATCH] refactor(avm): type aliasing for VmPublicInputs (#8884) Please read [contributing guidelines](CONTRIBUTING.md) and remove this line. --- .../dsl/acir_format/avm_recursion_constraint.cpp | 3 ++- .../src/barretenberg/vm/avm/tests/helpers.test.hpp | 2 +- .../cpp/src/barretenberg/vm/avm/trace/common.hpp | 11 +++++++---- .../cpp/src/barretenberg/vm/avm/trace/execution.cpp | 6 +++--- .../cpp/src/barretenberg/vm/avm/trace/execution.hpp | 2 +- .../cpp/src/barretenberg/vm/avm/trace/helper.cpp | 2 +- .../cpp/src/barretenberg/vm/avm/trace/helper.hpp | 8 ++++---- .../src/barretenberg/vm/avm/trace/kernel_trace.hpp | 4 ++-- .../cpp/src/barretenberg/vm/avm/trace/trace.cpp | 2 +- .../cpp/src/barretenberg/vm/avm/trace/trace.hpp | 2 +- 10 files changed, 23 insertions(+), 19 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/avm_recursion_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/avm_recursion_constraint.cpp index f6224f8b398..f963380dd8a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/avm_recursion_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/avm_recursion_constraint.cpp @@ -20,6 +20,7 @@ using namespace bb; using field_ct = stdlib::field_t; using bn254 = stdlib::bn254; using aggregation_state_ct = bb::stdlib::recursion::aggregation_state; +using VmPublicInputs = avm_trace::VmPublicInputs_; namespace { /** @@ -184,7 +185,7 @@ AggregationObjectIndices create_avm_recursion_constraints(Builder& builder, const auto public_inputs_flattened = fields_from_witnesses(input.public_inputs); auto it = public_inputs_flattened.begin(); - avm_trace::VmPublicInputs vm_public_inputs = + VmPublicInputs vm_public_inputs = avm_trace::convert_public_inputs(std::vector(it, it + PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH)); it += PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH; std::vector calldata(it, it + AVM_PUBLIC_COLUMN_MAX_SIZE); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/tests/helpers.test.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/tests/helpers.test.hpp index b881588de1d..248dfa88022 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/tests/helpers.test.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/tests/helpers.test.hpp @@ -25,7 +25,7 @@ using FF = bb::AvmFlavorSettings::FF; using Row = bb::AvmFullRow; using ThreeOpParam = std::array; using ThreeOpParamRow = std::tuple; -using VmPublicInputsNT = bb::avm_trace::VmPublicInputs; +using VmPublicInputsNT = bb::avm_trace::VmPublicInputs_; // If the test is expecting a relation to fail, then use validate_trace_check_circuit. // Otherwise, use validate_trace with a single argument. If the proving needs to be diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/common.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/common.hpp index 6f838cf9557..9796b79eb2a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/common.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/common.hpp @@ -15,10 +15,13 @@ using FF = AvmFlavorSettings::FF; // There are 4 public input columns, 1 for context inputs, and 3 for emitting side effects template -using VmPublicInputs = std::tuple, // Input: Kernel context inputs - std::array, // Output: Kernel outputs data - std::array, // Output: Kernel outputs side effects - std::array>; // Output: Kernel outputs metadata +using VmPublicInputs_ = std::tuple, // Input: Kernel context inputs + std::array, // Output: Kernel outputs data + std::array, // Output: Kernel outputs side effects + std::array>; // Output: Kernel outputs metadata + +// This is the VmPublicInputs type for the current AVM flavor +using VmPublicInputs = VmPublicInputs_; // Constants for indexing into the tuple above static const size_t KERNEL_INPUTS = 0; static const size_t KERNEL_OUTPUTS_VALUE = 1; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp index 9b64c0c1965..31cc2fbf543 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp @@ -146,7 +146,7 @@ void show_trace_info(const auto& trace) } // namespace // Needed for dependency injection in tests. -Execution::TraceBuilderConstructor Execution::trace_builder_constructor = [](VmPublicInputs public_inputs, +Execution::TraceBuilderConstructor Execution::trace_builder_constructor = [](VmPublicInputs public_inputs, ExecutionHints execution_hints, uint32_t side_effect_counter, std::vector calldata) { @@ -252,7 +252,7 @@ bool Execution::verify(AvmFlavor::VerificationKey vk, HonkProof const& proof) std::copy(returndata_offset, raw_proof_offset, std::back_inserter(returndata)); std::copy(raw_proof_offset, proof.end(), std::back_inserter(raw_proof)); - VmPublicInputs public_inputs = convert_public_inputs(public_inputs_vec); + VmPublicInputs public_inputs = convert_public_inputs(public_inputs_vec); std::vector> public_inputs_columns = copy_public_inputs_columns(public_inputs, calldata, returndata); return verifier.verify_proof(raw_proof, public_inputs_columns); @@ -291,7 +291,7 @@ std::vector Execution::gen_trace(std::vector const& instructio vinfo("------- GENERATING TRACE -------"); // TODO(https://github.com/AztecProtocol/aztec-packages/issues/6718): construction of the public input columns // should be done in the kernel - this is stubbed and underconstrained - VmPublicInputs public_inputs = convert_public_inputs(public_inputs_vec); + VmPublicInputs public_inputs = convert_public_inputs(public_inputs_vec); uint32_t start_side_effect_counter = !public_inputs_vec.empty() ? static_cast(public_inputs_vec[START_SIDE_EFFECT_COUNTER_PCPI_OFFSET]) : 0; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.hpp index 7c7c0ddf4ec..17f696e6043 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.hpp @@ -15,7 +15,7 @@ namespace bb::avm_trace { class Execution { public: static constexpr size_t SRS_SIZE = 1 << 22; - using TraceBuilderConstructor = std::function public_inputs, + using TraceBuilderConstructor = std::function calldata)>; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.cpp index 3adea143890..4789191094b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.cpp @@ -85,7 +85,7 @@ std::string to_hex(bb::avm_trace::AvmMemoryTag tag) * @param public_inputs Public inputs structure * @param trace The execution trace */ -void inject_end_gas_values(VmPublicInputs& public_inputs, std::vector& trace) +void inject_end_gas_values(VmPublicInputs& public_inputs, std::vector& trace) { auto execution_end_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_execution_end == FF(1); }); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.hpp index a3051d91235..5cc04964bf8 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.hpp @@ -22,9 +22,9 @@ bool is_operand_indirect(uint8_t ind_value, uint8_t operand_idx); * @param public_inputs_vec * @return VmPublicInputs */ -template VmPublicInputs convert_public_inputs(std::vector const& public_inputs_vec) +template VmPublicInputs_ convert_public_inputs(std::vector const& public_inputs_vec) { - VmPublicInputs public_inputs; + VmPublicInputs_ public_inputs; // Case where we pass in empty public inputs - this will be used in tests where they are not required if (public_inputs_vec.empty()) { @@ -188,7 +188,7 @@ template VmPublicInputs convert_public_inputs(std::vector -std::vector> copy_public_inputs_columns(VmPublicInputs const& public_inputs, +std::vector> copy_public_inputs_columns(VmPublicInputs_ const& public_inputs, std::vector const& calldata, std::vector const& returndata) { @@ -234,6 +234,6 @@ std::string to_hex(T value) std::string to_hex(bb::avm_trace::AvmMemoryTag tag); // Mutate the inputs -void inject_end_gas_values(VmPublicInputs& public_inputs, std::vector& trace); +void inject_end_gas_values(VmPublicInputs& public_inputs, std::vector& trace); } // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.hpp index 95f2815597b..49979bca3cd 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.hpp @@ -57,7 +57,7 @@ class AvmKernelTraceBuilder { // optimise this to just hardcode the counter to be the same as the lookup selector value!!! std::unordered_map kernel_output_selector_counter; - AvmKernelTraceBuilder(uint32_t initial_side_effect_counter, VmPublicInputs public_inputs, ExecutionHints hints) + AvmKernelTraceBuilder(uint32_t initial_side_effect_counter, VmPublicInputs public_inputs, ExecutionHints hints) : public_inputs(std::move(public_inputs)) , initial_side_effect_counter(initial_side_effect_counter) , hints(std::move(hints)) @@ -98,7 +98,7 @@ class AvmKernelTraceBuilder { void op_emit_l2_to_l1_msg(uint32_t clk, uint32_t side_effect_counter, const FF& l2_to_l1_msg, const FF& recipient); // This is temporarily made public so we can access PIs - VmPublicInputs public_inputs; + VmPublicInputs public_inputs; private: std::vector kernel_trace; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp index f7f518c112b..1e849869e5b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp @@ -276,7 +276,7 @@ void AvmTraceBuilder::finalise_mem_trace_lookup_counts() * @brief Constructor of a trace builder of AVM. Only serves to set the capacity of the * underlying traces and initialize gas values. */ -AvmTraceBuilder::AvmTraceBuilder(VmPublicInputs public_inputs, +AvmTraceBuilder::AvmTraceBuilder(VmPublicInputs public_inputs, ExecutionHints execution_hints_, uint32_t side_effect_counter, std::vector calldata) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp index 5ec4ae79499..d52ba0817cb 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp @@ -52,7 +52,7 @@ struct AddressWithMode { class AvmTraceBuilder { public: - AvmTraceBuilder(VmPublicInputs public_inputs = {}, + AvmTraceBuilder(VmPublicInputs public_inputs = {}, ExecutionHints execution_hints = {}, uint32_t side_effect_counter = 0, std::vector calldata = {});