From 5896a920bc4f5fd239d69795872567af6ccbe803 Mon Sep 17 00:00:00 2001 From: Jean M <132435771+jeanmon@users.noreply.github.com> Date: Tue, 13 Feb 2024 14:51:13 +0100 Subject: [PATCH] chore: rename avm_mini to avm (#4580) Resolves #4533 --- .../cpp/pil/avm/{alu_chip.pil => avm_alu.pil} | 4 +- .../pil/avm/{avm_mini.pil => avm_main.pil} | 12 +- .../pil/avm/{mem_trace.pil => avm_mem.pil} | 16 +- barretenberg/cpp/src/barretenberg/bb/main.cpp | 2 +- .../flavor/generated/AvmMini_flavor.hpp | 940 ------------------ .../flavor/generated/avm_flavor.hpp | 919 +++++++++++++++++ .../generated/AvmMini_circuit_builder.hpp | 282 ------ .../generated/avm_circuit_builder.hpp | 280 ++++++ .../relations/generated/AvmMini/alu_chip.hpp | 308 ------ .../relations/generated/AvmMini/avm_mini.hpp | 403 -------- .../generated/AvmMini/declare_views.hpp | 86 -- .../relations/generated/avm/avm_alu.hpp | 308 ++++++ .../relations/generated/avm/avm_main.hpp | 404 ++++++++ .../mem_trace.hpp => avm/avm_mem.hpp} | 101 +- .../relations/generated/avm/declare_views.hpp | 86 ++ .../vm/avm_trace/AvmMini_helper.cpp | 74 -- .../vm/avm_trace/AvmMini_helper.hpp | 9 - ...vmMini_alu_trace.cpp => avm_alu_trace.cpp} | 30 +- ...vmMini_alu_trace.hpp => avm_alu_trace.hpp} | 6 +- .../{AvmMini_common.hpp => avm_common.hpp} | 6 +- ...ialization.cpp => avm_deserialization.cpp} | 8 +- ...ialization.hpp => avm_deserialization.hpp} | 6 +- ...vmMini_execution.cpp => avm_execution.cpp} | 22 +- ...vmMini_execution.hpp => avm_execution.hpp} | 6 +- .../barretenberg/vm/avm_trace/avm_helper.cpp | 74 ++ .../barretenberg/vm/avm_trace/avm_helper.hpp | 9 + ..._instructions.hpp => avm_instructions.hpp} | 4 +- ...vmMini_mem_trace.cpp => avm_mem_trace.cpp} | 48 +- ...vmMini_mem_trace.hpp => avm_mem_trace.hpp} | 6 +- .../{AvmMini_opcode.cpp => avm_opcode.cpp} | 2 +- .../{AvmMini_opcode.hpp => avm_opcode.hpp} | 0 .../{AvmMini_trace.cpp => avm_trace.cpp} | 402 ++++---- .../{AvmMini_trace.hpp => avm_trace.hpp} | 22 +- .../vm/generated/AvmMini_verifier.cpp | 202 ---- ...{AvmMini_composer.cpp => avm_composer.cpp} | 23 +- ...{AvmMini_composer.hpp => avm_composer.hpp} | 32 +- .../{AvmMini_prover.cpp => avm_prover.cpp} | 21 +- .../{AvmMini_prover.hpp => avm_prover.hpp} | 8 +- .../vm/generated/avm_verifier.cpp | 202 ++++ ...{AvmMini_verifier.hpp => avm_verifier.hpp} | 16 +- .../vm/tests/AvmMini_common.test.hpp | 13 - ...metic.test.cpp => avm_arithmetic.test.cpp} | 776 +++++++-------- ..._bitwise.test.cpp => avm_bitwise.test.cpp} | 117 +-- .../barretenberg/vm/tests/avm_common.test.hpp | 13 + ...low.test.cpp => avm_control_flow.test.cpp} | 147 +-- ...cution.test.cpp => avm_execution.test.cpp} | 76 +- ...ni_memory.test.cpp => avm_memory.test.cpp} | 100 +- .../barretenberg/vm/tests/helpers.test.cpp | 27 +- .../barretenberg/vm/tests/helpers.test.hpp | 6 +- .../instruction_serialization.ts | 4 +- 50 files changed, 3322 insertions(+), 3346 deletions(-) rename barretenberg/cpp/pil/avm/{alu_chip.pil => avm_alu.pil} (99%) rename barretenberg/cpp/pil/avm/{avm_mini.pil => avm_main.pil} (96%) rename barretenberg/cpp/pil/avm/{mem_trace.pil => avm_mem.pil} (92%) delete mode 100644 barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp create mode 100644 barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp delete mode 100644 barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp create mode 100644 barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/avm_circuit_builder.hpp delete mode 100644 barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp delete mode 100644 barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp delete mode 100644 barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp create mode 100644 barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp create mode 100644 barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp rename barretenberg/cpp/src/barretenberg/relations/generated/{AvmMini/mem_trace.hpp => avm/avm_mem.hpp} (52%) create mode 100644 barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp delete mode 100644 barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp delete mode 100644 barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.hpp rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_alu_trace.cpp => avm_alu_trace.cpp} (91%) rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_alu_trace.hpp => avm_alu_trace.hpp} (92%) rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_common.hpp => avm_common.hpp} (75%) rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_deserialization.cpp => avm_deserialization.cpp} (97%) rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_deserialization.hpp => avm_deserialization.hpp} (79%) rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_execution.cpp => avm_execution.cpp} (90%) rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_execution.hpp => avm_execution.hpp} (74%) create mode 100644 barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.cpp create mode 100644 barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.hpp rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_instructions.hpp => avm_instructions.hpp} (81%) rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_mem_trace.cpp => avm_mem_trace.cpp} (79%) rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_mem_trace.hpp => avm_mem_trace.hpp} (97%) rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_opcode.cpp => avm_opcode.cpp} (99%) rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_opcode.hpp => avm_opcode.hpp} (100%) rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_trace.cpp => avm_trace.cpp} (65%) rename barretenberg/cpp/src/barretenberg/vm/avm_trace/{AvmMini_trace.hpp => avm_trace.hpp} (85%) delete mode 100644 barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp rename barretenberg/cpp/src/barretenberg/vm/generated/{AvmMini_composer.cpp => avm_composer.cpp} (67%) rename barretenberg/cpp/src/barretenberg/vm/generated/{AvmMini_composer.hpp => avm_composer.hpp} (63%) rename barretenberg/cpp/src/barretenberg/vm/generated/{AvmMini_prover.cpp => avm_prover.cpp} (87%) rename barretenberg/cpp/src/barretenberg/vm/generated/{AvmMini_prover.hpp => avm_prover.hpp} (87%) create mode 100644 barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp rename barretenberg/cpp/src/barretenberg/vm/generated/{AvmMini_verifier.hpp => avm_verifier.hpp} (58%) delete mode 100644 barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_common.test.hpp rename barretenberg/cpp/src/barretenberg/vm/tests/{AvmMini_arithmetic.test.cpp => avm_arithmetic.test.cpp} (70%) rename barretenberg/cpp/src/barretenberg/vm/tests/{AvmMini_bitwise.test.cpp => avm_bitwise.test.cpp} (69%) create mode 100644 barretenberg/cpp/src/barretenberg/vm/tests/avm_common.test.hpp rename barretenberg/cpp/src/barretenberg/vm/tests/{AvmMini_control_flow.test.cpp => avm_control_flow.test.cpp} (53%) rename barretenberg/cpp/src/barretenberg/vm/tests/{AvmMini_execution.test.cpp => avm_execution.test.cpp} (91%) rename barretenberg/cpp/src/barretenberg/vm/tests/{AvmMini_memory.test.cpp => avm_memory.test.cpp} (68%) diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/avm_alu.pil similarity index 99% rename from barretenberg/cpp/pil/avm/alu_chip.pil rename to barretenberg/cpp/pil/avm/avm_alu.pil index 05ff63cb574..89ca4c3b83c 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/avm_alu.pil @@ -1,6 +1,6 @@ -include "avm_mini.pil"; +include "avm_main.pil"; -namespace aluChip(256); +namespace avm_alu(256); // ========= Table ALU-TR ================================================= diff --git a/barretenberg/cpp/pil/avm/avm_mini.pil b/barretenberg/cpp/pil/avm/avm_main.pil similarity index 96% rename from barretenberg/cpp/pil/avm/avm_mini.pil rename to barretenberg/cpp/pil/avm/avm_main.pil index c7421de63b8..8ad5256b0d5 100644 --- a/barretenberg/cpp/pil/avm/avm_mini.pil +++ b/barretenberg/cpp/pil/avm/avm_main.pil @@ -1,8 +1,8 @@ -include "mem_trace.pil"; -include "alu_chip.pil"; +include "avm_mem.pil"; +include "avm_alu.pil"; -namespace avmMini(256); +namespace avm_main(256); //===== CONSTANT POLYNOMIALS ================================================== pol constant clk(i) { i }; @@ -42,7 +42,7 @@ namespace avmMini(256); // Errors pol commit op_err; // Boolean flag pertaining to an operation error - pol commit tag_err; // Boolean flag (foreign key to memTrace.m_tag_err) + pol commit tag_err; // Boolean flag (foreign key to avm_mem.m_tag_err) // A helper witness being the inverse of some value // to show a non-zero equality @@ -89,7 +89,7 @@ namespace avmMini(256); sel_halt * (1 - sel_halt) = 0; op_err * (1 - op_err) = 0; - tag_err * (1 - tag_err) = 0; // Potential optimization (boolean constraint derivation from equivalence check to memTrace)? + tag_err * (1 - tag_err) = 0; // Potential optimization (boolean constraint derivation from equivalence check to avm_mem)? mem_op_a * (1 - mem_op_a) = 0; mem_op_b * (1 - mem_op_b) = 0; @@ -189,6 +189,6 @@ namespace avmMini(256); // Inter-table Constraints - // TODO: tag_err {clk} IS memTrace.m_tag_err {memTrace.m_clk} + // TODO: tag_err {clk} IS avm_mem.m_tag_err {avm_mem.m_clk} // TODO: Map memory trace with intermediate register values whenever there is no tag error, sthg like: // mem_op_a * (1 - tag_err) {mem_idx_a, clk, ia, rwa} IS m_sub_clk == 0 && 1 - m_tag_err {m_addr, m_clk, m_val, m_rw} diff --git a/barretenberg/cpp/pil/avm/mem_trace.pil b/barretenberg/cpp/pil/avm/avm_mem.pil similarity index 92% rename from barretenberg/cpp/pil/avm/mem_trace.pil rename to barretenberg/cpp/pil/avm/avm_mem.pil index 33a8a20ad06..a974351dcf5 100644 --- a/barretenberg/cpp/pil/avm/mem_trace.pil +++ b/barretenberg/cpp/pil/avm/avm_mem.pil @@ -1,8 +1,8 @@ -include "avm_mini.pil"; +include "avm_main.pil"; -namespace memTrace(256); +namespace avm_mem(256); // ========= Table MEM-TR ================= pol commit m_clk; pol commit m_sub_clk; @@ -13,7 +13,7 @@ namespace memTrace(256); pol commit m_last; // Boolean indicating the last row of the memory trace (not execution trace) pol commit m_rw; // Enum: 0 (read), 1 (write) - pol commit m_in_tag; // Instruction memory tag ("foreign key" pointing to avmMini.in_tag) + pol commit m_in_tag; // Instruction memory tag ("foreign key" pointing to avm_main.in_tag) // Error columns pol commit m_tag_err; // Boolean (1 if m_in_tag != m_tag is detected) @@ -31,11 +31,11 @@ namespace memTrace(256); // (m_in_tag will be constrained through inclusion check to main trace) // Remark: m_lastAccess == 1 on first row and therefore any relation with the - // multiplicative term (1 - m_lastAccess) implicitly includes (1 - avmMini.first) + // multiplicative term (1 - m_lastAccess) implicitly includes (1 - avm_main.first) // Similarly, this includes (1 - m_last) as well. // m_lastAccess == 0 ==> m_addr' == m_addr - // Optimization: We removed the term (1 - avmMini.first) + // Optimization: We removed the term (1 - avm_main.first) #[MEM_LAST_ACCESS_DELIMITER] (1 - m_lastAccess) * (m_addr' - m_addr) = 0; @@ -61,12 +61,12 @@ namespace memTrace(256); // Note: in barretenberg, a shifted polynomial will be 0 on the last row (shift is not cyclic) // Note2: in barretenberg, if a poynomial is shifted, its non-shifted equivalent must be 0 on the first row - // Optimization: We removed the term (1 - avmMini.first) and (1 - m_last) + // Optimization: We removed the term (1 - avm_main.first) and (1 - m_last) #[MEM_READ_WRITE_VAL_CONSISTENCY] (1 - m_lastAccess) * (1 - m_rw') * (m_val' - m_val) = 0; // m_lastAccess == 0 && m_rw' == 0 ==> m_tag == m_tag' - // Optimization: We removed the term (1 - avmMini.first) and (1 - m_last) + // Optimization: We removed the term (1 - avm_main.first) and (1 - m_last) #[MEM_READ_WRITE_TAG_CONSISTENCY] (1 - m_lastAccess) * (1 - m_rw') * (m_tag' - m_tag) = 0; @@ -103,4 +103,4 @@ namespace memTrace(256); // Inter-table Constraints - // TODO: {m_clk, m_in_tag} IN {avmMini.clk, avmMini.in_tag} \ No newline at end of file + // TODO: {m_clk, m_in_tag} IN {avm_main.clk, avm_main.in_tag} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index fa91f8f3667..1bb6b32f93e 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -3,7 +3,7 @@ #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 "barretenberg/vm/avm_trace/avm_execution.hpp" #include "config.hpp" #include "get_bn254_crs.hpp" #include "get_bytecode.hpp" diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp deleted file mode 100644 index 5cd19997c69..00000000000 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ /dev/null @@ -1,940 +0,0 @@ - - -#pragma once -#include "../relation_definitions.hpp" -#include "barretenberg/commitment_schemes/kzg/kzg.hpp" -#include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "barretenberg/polynomials/barycentric.hpp" -#include "barretenberg/polynomials/univariate.hpp" - -#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" - -#include "barretenberg/flavor/flavor.hpp" -#include "barretenberg/flavor/flavor_macros.hpp" -#include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" -#include "barretenberg/relations/generated/AvmMini/alu_chip.hpp" -#include "barretenberg/relations/generated/AvmMini/avm_mini.hpp" -#include "barretenberg/relations/generated/AvmMini/mem_trace.hpp" -#include "barretenberg/transcript/transcript.hpp" - -namespace bb { - -class AvmMiniFlavor { - public: - using Curve = curve::BN254; - using G1 = Curve::Group; - using PCS = KZG; - - using FF = G1::subgroup_field; - using Polynomial = bb::Polynomial; - using PolynomialHandle = std::span; - using GroupElement = G1::element; - using Commitment = G1::affine_element; - using CommitmentHandle = G1::affine_element; - using CommitmentKey = bb::CommitmentKey; - using VerifierCommitmentKey = bb::VerifierCommitmentKey; - using RelationSeparator = FF; - - static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; - static constexpr size_t NUM_WITNESS_ENTITIES = 66; - static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES; - // We have two copies of the witness entities, so we subtract the number of fixed ones (they have no shift), one for - // the unshifted and one for the shifted - static constexpr size_t NUM_ALL_ENTITIES = 82; - - using Relations = std::tuple, AvmMini_vm::alu_chip, AvmMini_vm::avm_mini>; - - static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); - - // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` - // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation - // length = 3 - static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; - static constexpr size_t NUM_RELATIONS = std::tuple_size::value; - - template - using ProtogalaxyTupleOfTuplesOfUnivariates = - decltype(create_protogalaxy_tuple_of_tuples_of_univariates()); - using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates()); - using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); - - static constexpr bool has_zero_row = true; - - private: - template class PrecomputedEntities : public PrecomputedEntitiesBase { - public: - using DataType = DataType_; - - DEFINE_FLAVOR_MEMBERS(DataType, avmMini_clk, avmMini_first) - - RefVector get_selectors() { return { avmMini_clk, avmMini_first }; }; - RefVector get_sigma_polynomials() { return {}; }; - RefVector get_id_polynomials() { return {}; }; - RefVector get_table_polynomials() { return {}; }; - }; - - template class WitnessEntities { - public: - DEFINE_FLAVOR_MEMBERS(DataType, - memTrace_m_clk, - memTrace_m_sub_clk, - memTrace_m_addr, - memTrace_m_tag, - memTrace_m_val, - memTrace_m_lastAccess, - memTrace_m_last, - memTrace_m_rw, - memTrace_m_in_tag, - memTrace_m_tag_err, - memTrace_m_one_min_inv, - aluChip_alu_clk, - aluChip_alu_ia, - aluChip_alu_ib, - aluChip_alu_ic, - aluChip_alu_op_add, - aluChip_alu_op_sub, - aluChip_alu_op_mul, - aluChip_alu_op_div, - aluChip_alu_op_not, - aluChip_alu_ff_tag, - aluChip_alu_u8_tag, - aluChip_alu_u16_tag, - aluChip_alu_u32_tag, - aluChip_alu_u64_tag, - aluChip_alu_u128_tag, - aluChip_alu_u8_r0, - aluChip_alu_u8_r1, - aluChip_alu_u16_r0, - aluChip_alu_u16_r1, - aluChip_alu_u16_r2, - aluChip_alu_u16_r3, - aluChip_alu_u16_r4, - aluChip_alu_u16_r5, - aluChip_alu_u16_r6, - aluChip_alu_u16_r7, - aluChip_alu_u64_r0, - aluChip_alu_cf, - avmMini_pc, - avmMini_internal_return_ptr, - avmMini_sel_internal_call, - avmMini_sel_internal_return, - avmMini_sel_jump, - avmMini_sel_halt, - avmMini_sel_op_add, - avmMini_sel_op_sub, - avmMini_sel_op_mul, - avmMini_sel_op_div, - avmMini_sel_op_not, - avmMini_in_tag, - avmMini_op_err, - avmMini_tag_err, - avmMini_inv, - avmMini_ia, - avmMini_ib, - avmMini_ic, - avmMini_mem_op_a, - avmMini_mem_op_b, - avmMini_mem_op_c, - avmMini_rwa, - avmMini_rwb, - avmMini_rwc, - avmMini_mem_idx_a, - avmMini_mem_idx_b, - avmMini_mem_idx_c, - avmMini_last) - - RefVector get_wires() - { - return { memTrace_m_clk, - memTrace_m_sub_clk, - memTrace_m_addr, - memTrace_m_tag, - memTrace_m_val, - memTrace_m_lastAccess, - memTrace_m_last, - memTrace_m_rw, - memTrace_m_in_tag, - memTrace_m_tag_err, - memTrace_m_one_min_inv, - aluChip_alu_clk, - aluChip_alu_ia, - aluChip_alu_ib, - aluChip_alu_ic, - aluChip_alu_op_add, - aluChip_alu_op_sub, - aluChip_alu_op_mul, - aluChip_alu_op_div, - aluChip_alu_op_not, - aluChip_alu_ff_tag, - aluChip_alu_u8_tag, - aluChip_alu_u16_tag, - aluChip_alu_u32_tag, - aluChip_alu_u64_tag, - aluChip_alu_u128_tag, - aluChip_alu_u8_r0, - aluChip_alu_u8_r1, - aluChip_alu_u16_r0, - aluChip_alu_u16_r1, - aluChip_alu_u16_r2, - aluChip_alu_u16_r3, - aluChip_alu_u16_r4, - aluChip_alu_u16_r5, - aluChip_alu_u16_r6, - aluChip_alu_u16_r7, - aluChip_alu_u64_r0, - aluChip_alu_cf, - avmMini_pc, - avmMini_internal_return_ptr, - avmMini_sel_internal_call, - avmMini_sel_internal_return, - avmMini_sel_jump, - avmMini_sel_halt, - avmMini_sel_op_add, - avmMini_sel_op_sub, - avmMini_sel_op_mul, - avmMini_sel_op_div, - avmMini_sel_op_not, - avmMini_in_tag, - avmMini_op_err, - avmMini_tag_err, - avmMini_inv, - avmMini_ia, - avmMini_ib, - avmMini_ic, - avmMini_mem_op_a, - avmMini_mem_op_b, - avmMini_mem_op_c, - avmMini_rwa, - avmMini_rwb, - avmMini_rwc, - avmMini_mem_idx_a, - avmMini_mem_idx_b, - avmMini_mem_idx_c, - avmMini_last }; - }; - RefVector get_sorted_polynomials() { return {}; }; - }; - - template class AllEntities { - public: - DEFINE_FLAVOR_MEMBERS(DataType, - avmMini_clk, - avmMini_first, - memTrace_m_clk, - memTrace_m_sub_clk, - memTrace_m_addr, - memTrace_m_tag, - memTrace_m_val, - memTrace_m_lastAccess, - memTrace_m_last, - memTrace_m_rw, - memTrace_m_in_tag, - memTrace_m_tag_err, - memTrace_m_one_min_inv, - aluChip_alu_clk, - aluChip_alu_ia, - aluChip_alu_ib, - aluChip_alu_ic, - aluChip_alu_op_add, - aluChip_alu_op_sub, - aluChip_alu_op_mul, - aluChip_alu_op_div, - aluChip_alu_op_not, - aluChip_alu_ff_tag, - aluChip_alu_u8_tag, - aluChip_alu_u16_tag, - aluChip_alu_u32_tag, - aluChip_alu_u64_tag, - aluChip_alu_u128_tag, - aluChip_alu_u8_r0, - aluChip_alu_u8_r1, - aluChip_alu_u16_r0, - aluChip_alu_u16_r1, - aluChip_alu_u16_r2, - aluChip_alu_u16_r3, - aluChip_alu_u16_r4, - aluChip_alu_u16_r5, - aluChip_alu_u16_r6, - aluChip_alu_u16_r7, - aluChip_alu_u64_r0, - aluChip_alu_cf, - avmMini_pc, - avmMini_internal_return_ptr, - avmMini_sel_internal_call, - avmMini_sel_internal_return, - avmMini_sel_jump, - avmMini_sel_halt, - avmMini_sel_op_add, - avmMini_sel_op_sub, - avmMini_sel_op_mul, - avmMini_sel_op_div, - avmMini_sel_op_not, - avmMini_in_tag, - avmMini_op_err, - avmMini_tag_err, - avmMini_inv, - avmMini_ia, - avmMini_ib, - avmMini_ic, - avmMini_mem_op_a, - avmMini_mem_op_b, - avmMini_mem_op_c, - avmMini_rwa, - avmMini_rwb, - avmMini_rwc, - avmMini_mem_idx_a, - avmMini_mem_idx_b, - avmMini_mem_idx_c, - avmMini_last, - memTrace_m_rw_shift, - memTrace_m_val_shift, - memTrace_m_addr_shift, - memTrace_m_tag_shift, - aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r3_shift, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift) - - RefVector get_wires() - { - return { avmMini_clk, - avmMini_first, - memTrace_m_clk, - memTrace_m_sub_clk, - memTrace_m_addr, - memTrace_m_tag, - memTrace_m_val, - memTrace_m_lastAccess, - memTrace_m_last, - memTrace_m_rw, - memTrace_m_in_tag, - memTrace_m_tag_err, - memTrace_m_one_min_inv, - aluChip_alu_clk, - aluChip_alu_ia, - aluChip_alu_ib, - aluChip_alu_ic, - aluChip_alu_op_add, - aluChip_alu_op_sub, - aluChip_alu_op_mul, - aluChip_alu_op_div, - aluChip_alu_op_not, - aluChip_alu_ff_tag, - aluChip_alu_u8_tag, - aluChip_alu_u16_tag, - aluChip_alu_u32_tag, - aluChip_alu_u64_tag, - aluChip_alu_u128_tag, - aluChip_alu_u8_r0, - aluChip_alu_u8_r1, - aluChip_alu_u16_r0, - aluChip_alu_u16_r1, - aluChip_alu_u16_r2, - aluChip_alu_u16_r3, - aluChip_alu_u16_r4, - aluChip_alu_u16_r5, - aluChip_alu_u16_r6, - aluChip_alu_u16_r7, - aluChip_alu_u64_r0, - aluChip_alu_cf, - avmMini_pc, - avmMini_internal_return_ptr, - avmMini_sel_internal_call, - avmMini_sel_internal_return, - avmMini_sel_jump, - avmMini_sel_halt, - avmMini_sel_op_add, - avmMini_sel_op_sub, - avmMini_sel_op_mul, - avmMini_sel_op_div, - avmMini_sel_op_not, - avmMini_in_tag, - avmMini_op_err, - avmMini_tag_err, - avmMini_inv, - avmMini_ia, - avmMini_ib, - avmMini_ic, - avmMini_mem_op_a, - avmMini_mem_op_b, - avmMini_mem_op_c, - avmMini_rwa, - avmMini_rwb, - avmMini_rwc, - avmMini_mem_idx_a, - avmMini_mem_idx_b, - avmMini_mem_idx_c, - avmMini_last, - memTrace_m_rw_shift, - memTrace_m_val_shift, - memTrace_m_addr_shift, - memTrace_m_tag_shift, - aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r3_shift, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift }; - }; - RefVector get_unshifted() - { - return { avmMini_clk, - avmMini_first, - memTrace_m_clk, - memTrace_m_sub_clk, - memTrace_m_addr, - memTrace_m_tag, - memTrace_m_val, - memTrace_m_lastAccess, - memTrace_m_last, - memTrace_m_rw, - memTrace_m_in_tag, - memTrace_m_tag_err, - memTrace_m_one_min_inv, - aluChip_alu_clk, - aluChip_alu_ia, - aluChip_alu_ib, - aluChip_alu_ic, - aluChip_alu_op_add, - aluChip_alu_op_sub, - aluChip_alu_op_mul, - aluChip_alu_op_div, - aluChip_alu_op_not, - aluChip_alu_ff_tag, - aluChip_alu_u8_tag, - aluChip_alu_u16_tag, - aluChip_alu_u32_tag, - aluChip_alu_u64_tag, - aluChip_alu_u128_tag, - aluChip_alu_u8_r0, - aluChip_alu_u8_r1, - aluChip_alu_u16_r0, - aluChip_alu_u16_r1, - aluChip_alu_u16_r2, - aluChip_alu_u16_r3, - aluChip_alu_u16_r4, - aluChip_alu_u16_r5, - aluChip_alu_u16_r6, - aluChip_alu_u16_r7, - aluChip_alu_u64_r0, - aluChip_alu_cf, - avmMini_pc, - avmMini_internal_return_ptr, - avmMini_sel_internal_call, - avmMini_sel_internal_return, - avmMini_sel_jump, - avmMini_sel_halt, - avmMini_sel_op_add, - avmMini_sel_op_sub, - avmMini_sel_op_mul, - avmMini_sel_op_div, - avmMini_sel_op_not, - avmMini_in_tag, - avmMini_op_err, - avmMini_tag_err, - avmMini_inv, - avmMini_ia, - avmMini_ib, - avmMini_ic, - avmMini_mem_op_a, - avmMini_mem_op_b, - avmMini_mem_op_c, - avmMini_rwa, - avmMini_rwb, - avmMini_rwc, - avmMini_mem_idx_a, - avmMini_mem_idx_b, - avmMini_mem_idx_c, - avmMini_last }; - }; - RefVector get_to_be_shifted() - { - return { memTrace_m_rw, - memTrace_m_val, - memTrace_m_addr, - memTrace_m_tag, - aluChip_alu_u16_r1, - aluChip_alu_u16_r4, - aluChip_alu_u16_r7, - aluChip_alu_u16_r0, - aluChip_alu_u16_r5, - aluChip_alu_u16_r6, - aluChip_alu_u16_r2, - aluChip_alu_u16_r3, - avmMini_internal_return_ptr, - avmMini_pc }; - }; - RefVector get_shifted() - { - return { memTrace_m_rw_shift, - memTrace_m_val_shift, - memTrace_m_addr_shift, - memTrace_m_tag_shift, - aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r3_shift, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift }; - }; - }; - - public: - class ProvingKey : public ProvingKey_, WitnessEntities> { - public: - // Expose constructors on the base class - using Base = ProvingKey_, WitnessEntities>; - using Base::Base; - - RefVector get_to_be_shifted() - { - return { memTrace_m_rw, - memTrace_m_val, - memTrace_m_addr, - memTrace_m_tag, - aluChip_alu_u16_r1, - aluChip_alu_u16_r4, - aluChip_alu_u16_r7, - aluChip_alu_u16_r0, - aluChip_alu_u16_r5, - aluChip_alu_u16_r6, - aluChip_alu_u16_r2, - aluChip_alu_u16_r3, - avmMini_internal_return_ptr, - avmMini_pc }; - }; - - // The plookup wires that store plookup read data. - std::array get_table_column_wires() { return {}; }; - }; - - using VerificationKey = VerificationKey_>; - - using FoldedPolynomials = AllEntities>; - - class AllValues : public AllEntities { - public: - using Base = AllEntities; - using Base::Base; - }; - - /** - * @brief A container for the prover polynomials handles. - */ - class ProverPolynomials : public AllEntities { - public: - // Define all operations as default, except move construction/assignment - ProverPolynomials() = default; - ProverPolynomials& operator=(const ProverPolynomials&) = delete; - ProverPolynomials(const ProverPolynomials& o) = delete; - ProverPolynomials(ProverPolynomials&& o) noexcept = default; - ProverPolynomials& operator=(ProverPolynomials&& o) noexcept = default; - ~ProverPolynomials() = default; - [[nodiscard]] size_t get_polynomial_size() const { return memTrace_m_clk.size(); } - /** - * @brief Returns the evaluations of all prover polynomials at one point on the boolean hypercube, which - * represents one row in the execution trace. - */ - [[nodiscard]] AllValues get_row(size_t row_idx) const - { - AllValues result; - for (auto [result_field, polynomial] : zip_view(result.get_all(), this->get_all())) { - result_field = polynomial[row_idx]; - } - return result; - } - }; - - using RowPolynomials = AllEntities; - - class PartiallyEvaluatedMultivariates : public AllEntities { - public: - PartiallyEvaluatedMultivariates() = default; - PartiallyEvaluatedMultivariates(const size_t circuit_size) - { - // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2) - for (auto& poly : get_all()) { - poly = Polynomial(circuit_size / 2); - } - } - }; - - /** - * @brief A container for univariates used during Protogalaxy folding and sumcheck. - * @details During folding and sumcheck, the prover evaluates the relations on these univariates. - */ - template using ProverUnivariates = AllEntities>; - - /** - * @brief A container for univariates produced during the hot loop in sumcheck. - */ - using ExtendedEdges = ProverUnivariates; - - class CommitmentLabels : public AllEntities { - private: - using Base = AllEntities; - - public: - CommitmentLabels() - : AllEntities() - { - Base::avmMini_clk = "AVMMINI_CLK"; - Base::avmMini_first = "AVMMINI_FIRST"; - Base::memTrace_m_clk = "MEMTRACE_M_CLK"; - Base::memTrace_m_sub_clk = "MEMTRACE_M_SUB_CLK"; - Base::memTrace_m_addr = "MEMTRACE_M_ADDR"; - Base::memTrace_m_tag = "MEMTRACE_M_TAG"; - Base::memTrace_m_val = "MEMTRACE_M_VAL"; - Base::memTrace_m_lastAccess = "MEMTRACE_M_LASTACCESS"; - Base::memTrace_m_last = "MEMTRACE_M_LAST"; - Base::memTrace_m_rw = "MEMTRACE_M_RW"; - Base::memTrace_m_in_tag = "MEMTRACE_M_IN_TAG"; - Base::memTrace_m_tag_err = "MEMTRACE_M_TAG_ERR"; - Base::memTrace_m_one_min_inv = "MEMTRACE_M_ONE_MIN_INV"; - Base::aluChip_alu_clk = "ALUCHIP_ALU_CLK"; - Base::aluChip_alu_ia = "ALUCHIP_ALU_IA"; - Base::aluChip_alu_ib = "ALUCHIP_ALU_IB"; - Base::aluChip_alu_ic = "ALUCHIP_ALU_IC"; - Base::aluChip_alu_op_add = "ALUCHIP_ALU_OP_ADD"; - Base::aluChip_alu_op_sub = "ALUCHIP_ALU_OP_SUB"; - Base::aluChip_alu_op_mul = "ALUCHIP_ALU_OP_MUL"; - Base::aluChip_alu_op_div = "ALUCHIP_ALU_OP_DIV"; - Base::aluChip_alu_op_not = "ALUCHIP_ALU_OP_NOT"; - Base::aluChip_alu_ff_tag = "ALUCHIP_ALU_FF_TAG"; - Base::aluChip_alu_u8_tag = "ALUCHIP_ALU_U8_TAG"; - Base::aluChip_alu_u16_tag = "ALUCHIP_ALU_U16_TAG"; - Base::aluChip_alu_u32_tag = "ALUCHIP_ALU_U32_TAG"; - Base::aluChip_alu_u64_tag = "ALUCHIP_ALU_U64_TAG"; - Base::aluChip_alu_u128_tag = "ALUCHIP_ALU_U128_TAG"; - Base::aluChip_alu_u8_r0 = "ALUCHIP_ALU_U8_R0"; - Base::aluChip_alu_u8_r1 = "ALUCHIP_ALU_U8_R1"; - Base::aluChip_alu_u16_r0 = "ALUCHIP_ALU_U16_R0"; - Base::aluChip_alu_u16_r1 = "ALUCHIP_ALU_U16_R1"; - Base::aluChip_alu_u16_r2 = "ALUCHIP_ALU_U16_R2"; - Base::aluChip_alu_u16_r3 = "ALUCHIP_ALU_U16_R3"; - Base::aluChip_alu_u16_r4 = "ALUCHIP_ALU_U16_R4"; - Base::aluChip_alu_u16_r5 = "ALUCHIP_ALU_U16_R5"; - Base::aluChip_alu_u16_r6 = "ALUCHIP_ALU_U16_R6"; - Base::aluChip_alu_u16_r7 = "ALUCHIP_ALU_U16_R7"; - Base::aluChip_alu_u64_r0 = "ALUCHIP_ALU_U64_R0"; - Base::aluChip_alu_cf = "ALUCHIP_ALU_CF"; - Base::avmMini_pc = "AVMMINI_PC"; - Base::avmMini_internal_return_ptr = "AVMMINI_INTERNAL_RETURN_PTR"; - Base::avmMini_sel_internal_call = "AVMMINI_SEL_INTERNAL_CALL"; - Base::avmMini_sel_internal_return = "AVMMINI_SEL_INTERNAL_RETURN"; - Base::avmMini_sel_jump = "AVMMINI_SEL_JUMP"; - Base::avmMini_sel_halt = "AVMMINI_SEL_HALT"; - Base::avmMini_sel_op_add = "AVMMINI_SEL_OP_ADD"; - Base::avmMini_sel_op_sub = "AVMMINI_SEL_OP_SUB"; - Base::avmMini_sel_op_mul = "AVMMINI_SEL_OP_MUL"; - Base::avmMini_sel_op_div = "AVMMINI_SEL_OP_DIV"; - Base::avmMini_sel_op_not = "AVMMINI_SEL_OP_NOT"; - Base::avmMini_in_tag = "AVMMINI_IN_TAG"; - Base::avmMini_op_err = "AVMMINI_OP_ERR"; - Base::avmMini_tag_err = "AVMMINI_TAG_ERR"; - Base::avmMini_inv = "AVMMINI_INV"; - Base::avmMini_ia = "AVMMINI_IA"; - Base::avmMini_ib = "AVMMINI_IB"; - Base::avmMini_ic = "AVMMINI_IC"; - Base::avmMini_mem_op_a = "AVMMINI_MEM_OP_A"; - Base::avmMini_mem_op_b = "AVMMINI_MEM_OP_B"; - Base::avmMini_mem_op_c = "AVMMINI_MEM_OP_C"; - Base::avmMini_rwa = "AVMMINI_RWA"; - Base::avmMini_rwb = "AVMMINI_RWB"; - Base::avmMini_rwc = "AVMMINI_RWC"; - Base::avmMini_mem_idx_a = "AVMMINI_MEM_IDX_A"; - Base::avmMini_mem_idx_b = "AVMMINI_MEM_IDX_B"; - Base::avmMini_mem_idx_c = "AVMMINI_MEM_IDX_C"; - Base::avmMini_last = "AVMMINI_LAST"; - }; - }; - - class VerifierCommitments : public AllEntities { - private: - using Base = AllEntities; - - public: - VerifierCommitments(const std::shared_ptr& verification_key) - { - avmMini_clk = verification_key->avmMini_clk; - avmMini_first = verification_key->avmMini_first; - } - }; - - class Transcript : public NativeTranscript { - public: - uint32_t circuit_size; - - Commitment memTrace_m_clk; - Commitment memTrace_m_sub_clk; - Commitment memTrace_m_addr; - Commitment memTrace_m_tag; - Commitment memTrace_m_val; - Commitment memTrace_m_lastAccess; - Commitment memTrace_m_last; - Commitment memTrace_m_rw; - Commitment memTrace_m_in_tag; - Commitment memTrace_m_tag_err; - Commitment memTrace_m_one_min_inv; - Commitment aluChip_alu_clk; - Commitment aluChip_alu_ia; - Commitment aluChip_alu_ib; - Commitment aluChip_alu_ic; - Commitment aluChip_alu_op_add; - Commitment aluChip_alu_op_sub; - Commitment aluChip_alu_op_mul; - Commitment aluChip_alu_op_div; - Commitment aluChip_alu_op_not; - Commitment aluChip_alu_ff_tag; - Commitment aluChip_alu_u8_tag; - Commitment aluChip_alu_u16_tag; - Commitment aluChip_alu_u32_tag; - Commitment aluChip_alu_u64_tag; - Commitment aluChip_alu_u128_tag; - Commitment aluChip_alu_u8_r0; - Commitment aluChip_alu_u8_r1; - Commitment aluChip_alu_u16_r0; - Commitment aluChip_alu_u16_r1; - Commitment aluChip_alu_u16_r2; - Commitment aluChip_alu_u16_r3; - Commitment aluChip_alu_u16_r4; - Commitment aluChip_alu_u16_r5; - Commitment aluChip_alu_u16_r6; - Commitment aluChip_alu_u16_r7; - Commitment aluChip_alu_u64_r0; - Commitment aluChip_alu_cf; - Commitment avmMini_pc; - Commitment avmMini_internal_return_ptr; - Commitment avmMini_sel_internal_call; - Commitment avmMini_sel_internal_return; - Commitment avmMini_sel_jump; - Commitment avmMini_sel_halt; - Commitment avmMini_sel_op_add; - Commitment avmMini_sel_op_sub; - Commitment avmMini_sel_op_mul; - Commitment avmMini_sel_op_div; - Commitment avmMini_sel_op_not; - Commitment avmMini_in_tag; - Commitment avmMini_op_err; - Commitment avmMini_tag_err; - Commitment avmMini_inv; - Commitment avmMini_ia; - Commitment avmMini_ib; - Commitment avmMini_ic; - Commitment avmMini_mem_op_a; - Commitment avmMini_mem_op_b; - Commitment avmMini_mem_op_c; - Commitment avmMini_rwa; - Commitment avmMini_rwb; - Commitment avmMini_rwc; - Commitment avmMini_mem_idx_a; - Commitment avmMini_mem_idx_b; - Commitment avmMini_mem_idx_c; - Commitment avmMini_last; - - std::vector> sumcheck_univariates; - std::array sumcheck_evaluations; - std::vector zm_cq_comms; - Commitment zm_cq_comm; - Commitment zm_pi_comm; - - Transcript() = default; - - Transcript(const std::vector& proof) - : NativeTranscript(proof) - {} - - void deserialize_full_transcript() - { - size_t num_frs_read = 0; - circuit_size = deserialize_from_buffer(proof_data, num_frs_read); - size_t log_n = numeric::get_msb(circuit_size); - - memTrace_m_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - memTrace_m_sub_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - memTrace_m_addr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - memTrace_m_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - memTrace_m_val = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - memTrace_m_lastAccess = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - memTrace_m_last = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - memTrace_m_rw = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - memTrace_m_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - memTrace_m_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - memTrace_m_one_min_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_ia = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_ib = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_op_add = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_op_sub = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_op_not = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_ff_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u8_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u32_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u64_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u128_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u8_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u8_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r3 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r4 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r5 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r6 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r7 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u64_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_cf = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_pc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_internal_return_ptr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_internal_call = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_internal_return = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_jump = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_halt = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_op_add = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_op_sub = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_op_not = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_op_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_ia = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_ib = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_mem_op_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_mem_op_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_mem_op_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_rwa = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_rwb = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_rwc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_mem_idx_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_mem_idx_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_mem_idx_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_last = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - - for (size_t i = 0; i < log_n; ++i) { - sumcheck_univariates.emplace_back( - deserialize_from_buffer>(Transcript::proof_data, - num_frs_read)); - } - sumcheck_evaluations = - deserialize_from_buffer>(Transcript::proof_data, num_frs_read); - for (size_t i = 0; i < log_n; ++i) { - zm_cq_comms.push_back(deserialize_from_buffer(proof_data, num_frs_read)); - } - zm_cq_comm = deserialize_from_buffer(proof_data, num_frs_read); - zm_pi_comm = deserialize_from_buffer(proof_data, num_frs_read); - } - - void serialize_full_transcript() - { - size_t old_proof_length = proof_data.size(); - Transcript::proof_data.clear(); - size_t log_n = numeric::get_msb(circuit_size); - - serialize_to_buffer(circuit_size, Transcript::proof_data); - - serialize_to_buffer(memTrace_m_clk, Transcript::proof_data); - serialize_to_buffer(memTrace_m_sub_clk, Transcript::proof_data); - serialize_to_buffer(memTrace_m_addr, Transcript::proof_data); - serialize_to_buffer(memTrace_m_tag, Transcript::proof_data); - serialize_to_buffer(memTrace_m_val, Transcript::proof_data); - serialize_to_buffer(memTrace_m_lastAccess, Transcript::proof_data); - serialize_to_buffer(memTrace_m_last, Transcript::proof_data); - serialize_to_buffer(memTrace_m_rw, Transcript::proof_data); - serialize_to_buffer(memTrace_m_in_tag, Transcript::proof_data); - serialize_to_buffer(memTrace_m_tag_err, Transcript::proof_data); - serialize_to_buffer(memTrace_m_one_min_inv, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_clk, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_ia, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_ib, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_ic, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_op_add, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_op_sub, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_op_mul, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_op_div, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_op_not, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_ff_tag, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u8_tag, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_tag, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u32_tag, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u64_tag, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u128_tag, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u8_r0, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u8_r1, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r0, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r1, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r2, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r3, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r4, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r5, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r6, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r7, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u64_r0, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_cf, Transcript::proof_data); - serialize_to_buffer(avmMini_pc, Transcript::proof_data); - serialize_to_buffer(avmMini_internal_return_ptr, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_internal_call, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_internal_return, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_jump, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_halt, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_op_add, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_op_sub, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_op_mul, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_op_div, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_op_not, Transcript::proof_data); - serialize_to_buffer(avmMini_in_tag, Transcript::proof_data); - serialize_to_buffer(avmMini_op_err, Transcript::proof_data); - serialize_to_buffer(avmMini_tag_err, Transcript::proof_data); - serialize_to_buffer(avmMini_inv, Transcript::proof_data); - serialize_to_buffer(avmMini_ia, Transcript::proof_data); - serialize_to_buffer(avmMini_ib, Transcript::proof_data); - serialize_to_buffer(avmMini_ic, Transcript::proof_data); - serialize_to_buffer(avmMini_mem_op_a, Transcript::proof_data); - serialize_to_buffer(avmMini_mem_op_b, Transcript::proof_data); - serialize_to_buffer(avmMini_mem_op_c, Transcript::proof_data); - serialize_to_buffer(avmMini_rwa, Transcript::proof_data); - serialize_to_buffer(avmMini_rwb, Transcript::proof_data); - serialize_to_buffer(avmMini_rwc, Transcript::proof_data); - serialize_to_buffer(avmMini_mem_idx_a, Transcript::proof_data); - serialize_to_buffer(avmMini_mem_idx_b, Transcript::proof_data); - serialize_to_buffer(avmMini_mem_idx_c, Transcript::proof_data); - serialize_to_buffer(avmMini_last, Transcript::proof_data); - - for (size_t i = 0; i < log_n; ++i) { - serialize_to_buffer(sumcheck_univariates[i], Transcript::proof_data); - } - serialize_to_buffer(sumcheck_evaluations, Transcript::proof_data); - for (size_t i = 0; i < log_n; ++i) { - serialize_to_buffer(zm_cq_comms[i], proof_data); - } - serialize_to_buffer(zm_cq_comm, proof_data); - serialize_to_buffer(zm_pi_comm, proof_data); - - // sanity check to make sure we generate the same length of proof as before. - ASSERT(proof_data.size() == old_proof_length); - } - }; -}; - -} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp new file mode 100644 index 00000000000..65d42b3903d --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp @@ -0,0 +1,919 @@ + + +#pragma once +#include "../relation_definitions.hpp" +#include "barretenberg/commitment_schemes/kzg/kzg.hpp" +#include "barretenberg/ecc/curves/bn254/g1.hpp" +#include "barretenberg/polynomials/barycentric.hpp" +#include "barretenberg/polynomials/univariate.hpp" + +#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" + +#include "barretenberg/flavor/flavor.hpp" +#include "barretenberg/flavor/flavor_macros.hpp" +#include "barretenberg/polynomials/evaluation_domain.hpp" +#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/relations/generated/avm/avm_alu.hpp" +#include "barretenberg/relations/generated/avm/avm_main.hpp" +#include "barretenberg/relations/generated/avm/avm_mem.hpp" +#include "barretenberg/transcript/transcript.hpp" + +namespace bb { + +class AvmFlavor { + public: + using Curve = curve::BN254; + using G1 = Curve::Group; + using PCS = KZG; + + using FF = G1::subgroup_field; + using Polynomial = bb::Polynomial; + using PolynomialHandle = std::span; + using GroupElement = G1::element; + using Commitment = G1::affine_element; + using CommitmentHandle = G1::affine_element; + using CommitmentKey = bb::CommitmentKey; + using VerifierCommitmentKey = bb::VerifierCommitmentKey; + using RelationSeparator = FF; + + static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; + static constexpr size_t NUM_WITNESS_ENTITIES = 66; + static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES; + // We have two copies of the witness entities, so we subtract the number of fixed ones (they have no shift), one for + // the unshifted and one for the shifted + static constexpr size_t NUM_ALL_ENTITIES = 82; + + using Relations = std::tuple, Avm_vm::avm_mem, Avm_vm::avm_alu>; + + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); + + // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` + // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation + // length = 3 + static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; + static constexpr size_t NUM_RELATIONS = std::tuple_size::value; + + template + using ProtogalaxyTupleOfTuplesOfUnivariates = + decltype(create_protogalaxy_tuple_of_tuples_of_univariates()); + using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates()); + using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); + + static constexpr bool has_zero_row = true; + + private: + template class PrecomputedEntities : public PrecomputedEntitiesBase { + public: + using DataType = DataType_; + + DEFINE_FLAVOR_MEMBERS(DataType, avm_main_clk, avm_main_first) + + RefVector get_selectors() { return { avm_main_clk, avm_main_first }; }; + RefVector get_sigma_polynomials() { return {}; }; + RefVector get_id_polynomials() { return {}; }; + RefVector get_table_polynomials() { return {}; }; + }; + + template class WitnessEntities { + public: + DEFINE_FLAVOR_MEMBERS(DataType, + avm_mem_m_clk, + avm_mem_m_sub_clk, + avm_mem_m_addr, + avm_mem_m_tag, + avm_mem_m_val, + avm_mem_m_lastAccess, + avm_mem_m_last, + avm_mem_m_rw, + avm_mem_m_in_tag, + avm_mem_m_tag_err, + avm_mem_m_one_min_inv, + avm_alu_alu_clk, + avm_alu_alu_ia, + avm_alu_alu_ib, + avm_alu_alu_ic, + avm_alu_alu_op_add, + avm_alu_alu_op_sub, + avm_alu_alu_op_mul, + avm_alu_alu_op_div, + avm_alu_alu_op_not, + avm_alu_alu_ff_tag, + avm_alu_alu_u8_tag, + avm_alu_alu_u16_tag, + avm_alu_alu_u32_tag, + avm_alu_alu_u64_tag, + avm_alu_alu_u128_tag, + avm_alu_alu_u8_r0, + avm_alu_alu_u8_r1, + avm_alu_alu_u16_r0, + avm_alu_alu_u16_r1, + avm_alu_alu_u16_r2, + avm_alu_alu_u16_r3, + avm_alu_alu_u16_r4, + avm_alu_alu_u16_r5, + avm_alu_alu_u16_r6, + avm_alu_alu_u16_r7, + avm_alu_alu_u64_r0, + avm_alu_alu_cf, + avm_main_pc, + avm_main_internal_return_ptr, + avm_main_sel_internal_call, + avm_main_sel_internal_return, + avm_main_sel_jump, + avm_main_sel_halt, + avm_main_sel_op_add, + avm_main_sel_op_sub, + avm_main_sel_op_mul, + avm_main_sel_op_div, + avm_main_sel_op_not, + avm_main_in_tag, + avm_main_op_err, + avm_main_tag_err, + avm_main_inv, + avm_main_ia, + avm_main_ib, + avm_main_ic, + avm_main_mem_op_a, + avm_main_mem_op_b, + avm_main_mem_op_c, + avm_main_rwa, + avm_main_rwb, + avm_main_rwc, + avm_main_mem_idx_a, + avm_main_mem_idx_b, + avm_main_mem_idx_c, + avm_main_last) + + RefVector get_wires() + { + return { avm_mem_m_clk, + avm_mem_m_sub_clk, + avm_mem_m_addr, + avm_mem_m_tag, + avm_mem_m_val, + avm_mem_m_lastAccess, + avm_mem_m_last, + avm_mem_m_rw, + avm_mem_m_in_tag, + avm_mem_m_tag_err, + avm_mem_m_one_min_inv, + avm_alu_alu_clk, + avm_alu_alu_ia, + avm_alu_alu_ib, + avm_alu_alu_ic, + avm_alu_alu_op_add, + avm_alu_alu_op_sub, + avm_alu_alu_op_mul, + avm_alu_alu_op_div, + avm_alu_alu_op_not, + avm_alu_alu_ff_tag, + avm_alu_alu_u8_tag, + avm_alu_alu_u16_tag, + avm_alu_alu_u32_tag, + avm_alu_alu_u64_tag, + avm_alu_alu_u128_tag, + avm_alu_alu_u8_r0, + avm_alu_alu_u8_r1, + avm_alu_alu_u16_r0, + avm_alu_alu_u16_r1, + avm_alu_alu_u16_r2, + avm_alu_alu_u16_r3, + avm_alu_alu_u16_r4, + avm_alu_alu_u16_r5, + avm_alu_alu_u16_r6, + avm_alu_alu_u16_r7, + avm_alu_alu_u64_r0, + avm_alu_alu_cf, + avm_main_pc, + avm_main_internal_return_ptr, + avm_main_sel_internal_call, + avm_main_sel_internal_return, + avm_main_sel_jump, + avm_main_sel_halt, + avm_main_sel_op_add, + avm_main_sel_op_sub, + avm_main_sel_op_mul, + avm_main_sel_op_div, + avm_main_sel_op_not, + avm_main_in_tag, + avm_main_op_err, + avm_main_tag_err, + avm_main_inv, + avm_main_ia, + avm_main_ib, + avm_main_ic, + avm_main_mem_op_a, + avm_main_mem_op_b, + avm_main_mem_op_c, + avm_main_rwa, + avm_main_rwb, + avm_main_rwc, + avm_main_mem_idx_a, + avm_main_mem_idx_b, + avm_main_mem_idx_c, + avm_main_last }; + }; + RefVector get_sorted_polynomials() { return {}; }; + }; + + template class AllEntities { + public: + DEFINE_FLAVOR_MEMBERS(DataType, + avm_main_clk, + avm_main_first, + avm_mem_m_clk, + avm_mem_m_sub_clk, + avm_mem_m_addr, + avm_mem_m_tag, + avm_mem_m_val, + avm_mem_m_lastAccess, + avm_mem_m_last, + avm_mem_m_rw, + avm_mem_m_in_tag, + avm_mem_m_tag_err, + avm_mem_m_one_min_inv, + avm_alu_alu_clk, + avm_alu_alu_ia, + avm_alu_alu_ib, + avm_alu_alu_ic, + avm_alu_alu_op_add, + avm_alu_alu_op_sub, + avm_alu_alu_op_mul, + avm_alu_alu_op_div, + avm_alu_alu_op_not, + avm_alu_alu_ff_tag, + avm_alu_alu_u8_tag, + avm_alu_alu_u16_tag, + avm_alu_alu_u32_tag, + avm_alu_alu_u64_tag, + avm_alu_alu_u128_tag, + avm_alu_alu_u8_r0, + avm_alu_alu_u8_r1, + avm_alu_alu_u16_r0, + avm_alu_alu_u16_r1, + avm_alu_alu_u16_r2, + avm_alu_alu_u16_r3, + avm_alu_alu_u16_r4, + avm_alu_alu_u16_r5, + avm_alu_alu_u16_r6, + avm_alu_alu_u16_r7, + avm_alu_alu_u64_r0, + avm_alu_alu_cf, + avm_main_pc, + avm_main_internal_return_ptr, + avm_main_sel_internal_call, + avm_main_sel_internal_return, + avm_main_sel_jump, + avm_main_sel_halt, + avm_main_sel_op_add, + avm_main_sel_op_sub, + avm_main_sel_op_mul, + avm_main_sel_op_div, + avm_main_sel_op_not, + avm_main_in_tag, + avm_main_op_err, + avm_main_tag_err, + avm_main_inv, + avm_main_ia, + avm_main_ib, + avm_main_ic, + avm_main_mem_op_a, + avm_main_mem_op_b, + avm_main_mem_op_c, + avm_main_rwa, + avm_main_rwb, + avm_main_rwc, + avm_main_mem_idx_a, + avm_main_mem_idx_b, + avm_main_mem_idx_c, + avm_main_last, + avm_main_pc_shift, + avm_main_internal_return_ptr_shift, + avm_mem_m_rw_shift, + avm_mem_m_addr_shift, + avm_mem_m_val_shift, + avm_mem_m_tag_shift, + avm_alu_alu_u16_r6_shift, + avm_alu_alu_u16_r4_shift, + avm_alu_alu_u16_r1_shift, + avm_alu_alu_u16_r2_shift, + avm_alu_alu_u16_r7_shift, + avm_alu_alu_u16_r0_shift, + avm_alu_alu_u16_r3_shift, + avm_alu_alu_u16_r5_shift) + + RefVector get_wires() + { + return { avm_main_clk, + avm_main_first, + avm_mem_m_clk, + avm_mem_m_sub_clk, + avm_mem_m_addr, + avm_mem_m_tag, + avm_mem_m_val, + avm_mem_m_lastAccess, + avm_mem_m_last, + avm_mem_m_rw, + avm_mem_m_in_tag, + avm_mem_m_tag_err, + avm_mem_m_one_min_inv, + avm_alu_alu_clk, + avm_alu_alu_ia, + avm_alu_alu_ib, + avm_alu_alu_ic, + avm_alu_alu_op_add, + avm_alu_alu_op_sub, + avm_alu_alu_op_mul, + avm_alu_alu_op_div, + avm_alu_alu_op_not, + avm_alu_alu_ff_tag, + avm_alu_alu_u8_tag, + avm_alu_alu_u16_tag, + avm_alu_alu_u32_tag, + avm_alu_alu_u64_tag, + avm_alu_alu_u128_tag, + avm_alu_alu_u8_r0, + avm_alu_alu_u8_r1, + avm_alu_alu_u16_r0, + avm_alu_alu_u16_r1, + avm_alu_alu_u16_r2, + avm_alu_alu_u16_r3, + avm_alu_alu_u16_r4, + avm_alu_alu_u16_r5, + avm_alu_alu_u16_r6, + avm_alu_alu_u16_r7, + avm_alu_alu_u64_r0, + avm_alu_alu_cf, + avm_main_pc, + avm_main_internal_return_ptr, + avm_main_sel_internal_call, + avm_main_sel_internal_return, + avm_main_sel_jump, + avm_main_sel_halt, + avm_main_sel_op_add, + avm_main_sel_op_sub, + avm_main_sel_op_mul, + avm_main_sel_op_div, + avm_main_sel_op_not, + avm_main_in_tag, + avm_main_op_err, + avm_main_tag_err, + avm_main_inv, + avm_main_ia, + avm_main_ib, + avm_main_ic, + avm_main_mem_op_a, + avm_main_mem_op_b, + avm_main_mem_op_c, + avm_main_rwa, + avm_main_rwb, + avm_main_rwc, + avm_main_mem_idx_a, + avm_main_mem_idx_b, + avm_main_mem_idx_c, + avm_main_last, + avm_main_pc_shift, + avm_main_internal_return_ptr_shift, + avm_mem_m_rw_shift, + avm_mem_m_addr_shift, + avm_mem_m_val_shift, + avm_mem_m_tag_shift, + avm_alu_alu_u16_r6_shift, + avm_alu_alu_u16_r4_shift, + avm_alu_alu_u16_r1_shift, + avm_alu_alu_u16_r2_shift, + avm_alu_alu_u16_r7_shift, + avm_alu_alu_u16_r0_shift, + avm_alu_alu_u16_r3_shift, + avm_alu_alu_u16_r5_shift }; + }; + RefVector get_unshifted() + { + return { avm_main_clk, + avm_main_first, + avm_mem_m_clk, + avm_mem_m_sub_clk, + avm_mem_m_addr, + avm_mem_m_tag, + avm_mem_m_val, + avm_mem_m_lastAccess, + avm_mem_m_last, + avm_mem_m_rw, + avm_mem_m_in_tag, + avm_mem_m_tag_err, + avm_mem_m_one_min_inv, + avm_alu_alu_clk, + avm_alu_alu_ia, + avm_alu_alu_ib, + avm_alu_alu_ic, + avm_alu_alu_op_add, + avm_alu_alu_op_sub, + avm_alu_alu_op_mul, + avm_alu_alu_op_div, + avm_alu_alu_op_not, + avm_alu_alu_ff_tag, + avm_alu_alu_u8_tag, + avm_alu_alu_u16_tag, + avm_alu_alu_u32_tag, + avm_alu_alu_u64_tag, + avm_alu_alu_u128_tag, + avm_alu_alu_u8_r0, + avm_alu_alu_u8_r1, + avm_alu_alu_u16_r0, + avm_alu_alu_u16_r1, + avm_alu_alu_u16_r2, + avm_alu_alu_u16_r3, + avm_alu_alu_u16_r4, + avm_alu_alu_u16_r5, + avm_alu_alu_u16_r6, + avm_alu_alu_u16_r7, + avm_alu_alu_u64_r0, + avm_alu_alu_cf, + avm_main_pc, + avm_main_internal_return_ptr, + avm_main_sel_internal_call, + avm_main_sel_internal_return, + avm_main_sel_jump, + avm_main_sel_halt, + avm_main_sel_op_add, + avm_main_sel_op_sub, + avm_main_sel_op_mul, + avm_main_sel_op_div, + avm_main_sel_op_not, + avm_main_in_tag, + avm_main_op_err, + avm_main_tag_err, + avm_main_inv, + avm_main_ia, + avm_main_ib, + avm_main_ic, + avm_main_mem_op_a, + avm_main_mem_op_b, + avm_main_mem_op_c, + avm_main_rwa, + avm_main_rwb, + avm_main_rwc, + avm_main_mem_idx_a, + avm_main_mem_idx_b, + avm_main_mem_idx_c, + avm_main_last }; + }; + RefVector get_to_be_shifted() + { + return { avm_main_pc, avm_main_internal_return_ptr, + avm_mem_m_rw, avm_mem_m_addr, + avm_mem_m_val, avm_mem_m_tag, + avm_alu_alu_u16_r6, avm_alu_alu_u16_r4, + avm_alu_alu_u16_r1, avm_alu_alu_u16_r2, + avm_alu_alu_u16_r7, avm_alu_alu_u16_r0, + avm_alu_alu_u16_r3, avm_alu_alu_u16_r5 }; + }; + RefVector get_shifted() + { + return { avm_main_pc_shift, avm_main_internal_return_ptr_shift, + avm_mem_m_rw_shift, avm_mem_m_addr_shift, + avm_mem_m_val_shift, avm_mem_m_tag_shift, + avm_alu_alu_u16_r6_shift, avm_alu_alu_u16_r4_shift, + avm_alu_alu_u16_r1_shift, avm_alu_alu_u16_r2_shift, + avm_alu_alu_u16_r7_shift, avm_alu_alu_u16_r0_shift, + avm_alu_alu_u16_r3_shift, avm_alu_alu_u16_r5_shift }; + }; + }; + + public: + class ProvingKey : public ProvingKey_, WitnessEntities> { + public: + // Expose constructors on the base class + using Base = ProvingKey_, WitnessEntities>; + using Base::Base; + + RefVector get_to_be_shifted() + { + return { avm_main_pc, avm_main_internal_return_ptr, + avm_mem_m_rw, avm_mem_m_addr, + avm_mem_m_val, avm_mem_m_tag, + avm_alu_alu_u16_r6, avm_alu_alu_u16_r4, + avm_alu_alu_u16_r1, avm_alu_alu_u16_r2, + avm_alu_alu_u16_r7, avm_alu_alu_u16_r0, + avm_alu_alu_u16_r3, avm_alu_alu_u16_r5 }; + }; + + // The plookup wires that store plookup read data. + std::array get_table_column_wires() { return {}; }; + }; + + using VerificationKey = VerificationKey_>; + + using FoldedPolynomials = AllEntities>; + + class AllValues : public AllEntities { + public: + using Base = AllEntities; + using Base::Base; + }; + + /** + * @brief A container for the prover polynomials handles. + */ + class ProverPolynomials : public AllEntities { + public: + // Define all operations as default, except move construction/assignment + ProverPolynomials() = default; + ProverPolynomials& operator=(const ProverPolynomials&) = delete; + ProverPolynomials(const ProverPolynomials& o) = delete; + ProverPolynomials(ProverPolynomials&& o) noexcept = default; + ProverPolynomials& operator=(ProverPolynomials&& o) noexcept = default; + ~ProverPolynomials() = default; + [[nodiscard]] size_t get_polynomial_size() const { return avm_mem_m_clk.size(); } + /** + * @brief Returns the evaluations of all prover polynomials at one point on the boolean hypercube, which + * represents one row in the execution trace. + */ + [[nodiscard]] AllValues get_row(size_t row_idx) const + { + AllValues result; + for (auto [result_field, polynomial] : zip_view(result.get_all(), this->get_all())) { + result_field = polynomial[row_idx]; + } + return result; + } + }; + + using RowPolynomials = AllEntities; + + class PartiallyEvaluatedMultivariates : public AllEntities { + public: + PartiallyEvaluatedMultivariates() = default; + PartiallyEvaluatedMultivariates(const size_t circuit_size) + { + // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2) + for (auto& poly : get_all()) { + poly = Polynomial(circuit_size / 2); + } + } + }; + + /** + * @brief A container for univariates used during Protogalaxy folding and sumcheck. + * @details During folding and sumcheck, the prover evaluates the relations on these univariates. + */ + template using ProverUnivariates = AllEntities>; + + /** + * @brief A container for univariates produced during the hot loop in sumcheck. + */ + using ExtendedEdges = ProverUnivariates; + + class CommitmentLabels : public AllEntities { + private: + using Base = AllEntities; + + public: + CommitmentLabels() + : AllEntities() + { + Base::avm_main_clk = "AVM_MAIN_CLK"; + Base::avm_main_first = "AVM_MAIN_FIRST"; + Base::avm_mem_m_clk = "AVM_MEM_M_CLK"; + Base::avm_mem_m_sub_clk = "AVM_MEM_M_SUB_CLK"; + Base::avm_mem_m_addr = "AVM_MEM_M_ADDR"; + Base::avm_mem_m_tag = "AVM_MEM_M_TAG"; + Base::avm_mem_m_val = "AVM_MEM_M_VAL"; + Base::avm_mem_m_lastAccess = "AVM_MEM_M_LASTACCESS"; + Base::avm_mem_m_last = "AVM_MEM_M_LAST"; + Base::avm_mem_m_rw = "AVM_MEM_M_RW"; + Base::avm_mem_m_in_tag = "AVM_MEM_M_IN_TAG"; + Base::avm_mem_m_tag_err = "AVM_MEM_M_TAG_ERR"; + Base::avm_mem_m_one_min_inv = "AVM_MEM_M_ONE_MIN_INV"; + Base::avm_alu_alu_clk = "AVM_ALU_ALU_CLK"; + Base::avm_alu_alu_ia = "AVM_ALU_ALU_IA"; + Base::avm_alu_alu_ib = "AVM_ALU_ALU_IB"; + Base::avm_alu_alu_ic = "AVM_ALU_ALU_IC"; + Base::avm_alu_alu_op_add = "AVM_ALU_ALU_OP_ADD"; + Base::avm_alu_alu_op_sub = "AVM_ALU_ALU_OP_SUB"; + Base::avm_alu_alu_op_mul = "AVM_ALU_ALU_OP_MUL"; + Base::avm_alu_alu_op_div = "AVM_ALU_ALU_OP_DIV"; + Base::avm_alu_alu_op_not = "AVM_ALU_ALU_OP_NOT"; + Base::avm_alu_alu_ff_tag = "AVM_ALU_ALU_FF_TAG"; + Base::avm_alu_alu_u8_tag = "AVM_ALU_ALU_U8_TAG"; + Base::avm_alu_alu_u16_tag = "AVM_ALU_ALU_U16_TAG"; + Base::avm_alu_alu_u32_tag = "AVM_ALU_ALU_U32_TAG"; + Base::avm_alu_alu_u64_tag = "AVM_ALU_ALU_U64_TAG"; + Base::avm_alu_alu_u128_tag = "AVM_ALU_ALU_U128_TAG"; + Base::avm_alu_alu_u8_r0 = "AVM_ALU_ALU_U8_R0"; + Base::avm_alu_alu_u8_r1 = "AVM_ALU_ALU_U8_R1"; + Base::avm_alu_alu_u16_r0 = "AVM_ALU_ALU_U16_R0"; + Base::avm_alu_alu_u16_r1 = "AVM_ALU_ALU_U16_R1"; + Base::avm_alu_alu_u16_r2 = "AVM_ALU_ALU_U16_R2"; + Base::avm_alu_alu_u16_r3 = "AVM_ALU_ALU_U16_R3"; + Base::avm_alu_alu_u16_r4 = "AVM_ALU_ALU_U16_R4"; + Base::avm_alu_alu_u16_r5 = "AVM_ALU_ALU_U16_R5"; + Base::avm_alu_alu_u16_r6 = "AVM_ALU_ALU_U16_R6"; + Base::avm_alu_alu_u16_r7 = "AVM_ALU_ALU_U16_R7"; + Base::avm_alu_alu_u64_r0 = "AVM_ALU_ALU_U64_R0"; + Base::avm_alu_alu_cf = "AVM_ALU_ALU_CF"; + Base::avm_main_pc = "AVM_MAIN_PC"; + Base::avm_main_internal_return_ptr = "AVM_MAIN_INTERNAL_RETURN_PTR"; + Base::avm_main_sel_internal_call = "AVM_MAIN_SEL_INTERNAL_CALL"; + Base::avm_main_sel_internal_return = "AVM_MAIN_SEL_INTERNAL_RETURN"; + Base::avm_main_sel_jump = "AVM_MAIN_SEL_JUMP"; + Base::avm_main_sel_halt = "AVM_MAIN_SEL_HALT"; + Base::avm_main_sel_op_add = "AVM_MAIN_SEL_OP_ADD"; + Base::avm_main_sel_op_sub = "AVM_MAIN_SEL_OP_SUB"; + Base::avm_main_sel_op_mul = "AVM_MAIN_SEL_OP_MUL"; + Base::avm_main_sel_op_div = "AVM_MAIN_SEL_OP_DIV"; + Base::avm_main_sel_op_not = "AVM_MAIN_SEL_OP_NOT"; + Base::avm_main_in_tag = "AVM_MAIN_IN_TAG"; + Base::avm_main_op_err = "AVM_MAIN_OP_ERR"; + Base::avm_main_tag_err = "AVM_MAIN_TAG_ERR"; + Base::avm_main_inv = "AVM_MAIN_INV"; + Base::avm_main_ia = "AVM_MAIN_IA"; + Base::avm_main_ib = "AVM_MAIN_IB"; + Base::avm_main_ic = "AVM_MAIN_IC"; + Base::avm_main_mem_op_a = "AVM_MAIN_MEM_OP_A"; + Base::avm_main_mem_op_b = "AVM_MAIN_MEM_OP_B"; + Base::avm_main_mem_op_c = "AVM_MAIN_MEM_OP_C"; + Base::avm_main_rwa = "AVM_MAIN_RWA"; + Base::avm_main_rwb = "AVM_MAIN_RWB"; + Base::avm_main_rwc = "AVM_MAIN_RWC"; + Base::avm_main_mem_idx_a = "AVM_MAIN_MEM_IDX_A"; + Base::avm_main_mem_idx_b = "AVM_MAIN_MEM_IDX_B"; + Base::avm_main_mem_idx_c = "AVM_MAIN_MEM_IDX_C"; + Base::avm_main_last = "AVM_MAIN_LAST"; + }; + }; + + class VerifierCommitments : public AllEntities { + private: + using Base = AllEntities; + + public: + VerifierCommitments(const std::shared_ptr& verification_key) + { + avm_main_clk = verification_key->avm_main_clk; + avm_main_first = verification_key->avm_main_first; + } + }; + + class Transcript : public NativeTranscript { + public: + uint32_t circuit_size; + + Commitment avm_mem_m_clk; + Commitment avm_mem_m_sub_clk; + Commitment avm_mem_m_addr; + Commitment avm_mem_m_tag; + Commitment avm_mem_m_val; + Commitment avm_mem_m_lastAccess; + Commitment avm_mem_m_last; + Commitment avm_mem_m_rw; + Commitment avm_mem_m_in_tag; + Commitment avm_mem_m_tag_err; + Commitment avm_mem_m_one_min_inv; + Commitment avm_alu_alu_clk; + Commitment avm_alu_alu_ia; + Commitment avm_alu_alu_ib; + Commitment avm_alu_alu_ic; + Commitment avm_alu_alu_op_add; + Commitment avm_alu_alu_op_sub; + Commitment avm_alu_alu_op_mul; + Commitment avm_alu_alu_op_div; + Commitment avm_alu_alu_op_not; + Commitment avm_alu_alu_ff_tag; + Commitment avm_alu_alu_u8_tag; + Commitment avm_alu_alu_u16_tag; + Commitment avm_alu_alu_u32_tag; + Commitment avm_alu_alu_u64_tag; + Commitment avm_alu_alu_u128_tag; + Commitment avm_alu_alu_u8_r0; + Commitment avm_alu_alu_u8_r1; + Commitment avm_alu_alu_u16_r0; + Commitment avm_alu_alu_u16_r1; + Commitment avm_alu_alu_u16_r2; + Commitment avm_alu_alu_u16_r3; + Commitment avm_alu_alu_u16_r4; + Commitment avm_alu_alu_u16_r5; + Commitment avm_alu_alu_u16_r6; + Commitment avm_alu_alu_u16_r7; + Commitment avm_alu_alu_u64_r0; + Commitment avm_alu_alu_cf; + Commitment avm_main_pc; + Commitment avm_main_internal_return_ptr; + Commitment avm_main_sel_internal_call; + Commitment avm_main_sel_internal_return; + Commitment avm_main_sel_jump; + Commitment avm_main_sel_halt; + Commitment avm_main_sel_op_add; + Commitment avm_main_sel_op_sub; + Commitment avm_main_sel_op_mul; + Commitment avm_main_sel_op_div; + Commitment avm_main_sel_op_not; + Commitment avm_main_in_tag; + Commitment avm_main_op_err; + Commitment avm_main_tag_err; + Commitment avm_main_inv; + Commitment avm_main_ia; + Commitment avm_main_ib; + Commitment avm_main_ic; + Commitment avm_main_mem_op_a; + Commitment avm_main_mem_op_b; + Commitment avm_main_mem_op_c; + Commitment avm_main_rwa; + Commitment avm_main_rwb; + Commitment avm_main_rwc; + Commitment avm_main_mem_idx_a; + Commitment avm_main_mem_idx_b; + Commitment avm_main_mem_idx_c; + Commitment avm_main_last; + + std::vector> sumcheck_univariates; + std::array sumcheck_evaluations; + std::vector zm_cq_comms; + Commitment zm_cq_comm; + Commitment zm_pi_comm; + + Transcript() = default; + + Transcript(const std::vector& proof) + : NativeTranscript(proof) + {} + + void deserialize_full_transcript() + { + size_t num_frs_read = 0; + circuit_size = deserialize_from_buffer(proof_data, num_frs_read); + size_t log_n = numeric::get_msb(circuit_size); + + avm_mem_m_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_mem_m_sub_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_mem_m_addr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_mem_m_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_mem_m_val = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_mem_m_lastAccess = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_mem_m_last = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_mem_m_rw = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_mem_m_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_mem_m_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_mem_m_one_min_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_ia = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_ib = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_op_add = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_op_sub = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_op_not = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_ff_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u8_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u16_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u32_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u64_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u128_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u8_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u8_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u16_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u16_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u16_r2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u16_r3 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u16_r4 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u16_r5 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u16_r6 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u16_r7 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_u64_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_cf = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_pc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_internal_return_ptr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_internal_call = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_internal_return = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_jump = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_halt = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_add = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_sub = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_not = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_op_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_ia = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_ib = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_mem_op_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_mem_op_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_mem_op_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_rwa = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_rwb = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_rwc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_mem_idx_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_mem_idx_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_mem_idx_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_last = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + + for (size_t i = 0; i < log_n; ++i) { + sumcheck_univariates.emplace_back( + deserialize_from_buffer>(Transcript::proof_data, + num_frs_read)); + } + sumcheck_evaluations = + deserialize_from_buffer>(Transcript::proof_data, num_frs_read); + for (size_t i = 0; i < log_n; ++i) { + zm_cq_comms.push_back(deserialize_from_buffer(proof_data, num_frs_read)); + } + zm_cq_comm = deserialize_from_buffer(proof_data, num_frs_read); + zm_pi_comm = deserialize_from_buffer(proof_data, num_frs_read); + } + + void serialize_full_transcript() + { + size_t old_proof_length = proof_data.size(); + Transcript::proof_data.clear(); + size_t log_n = numeric::get_msb(circuit_size); + + serialize_to_buffer(circuit_size, Transcript::proof_data); + + serialize_to_buffer(avm_mem_m_clk, Transcript::proof_data); + serialize_to_buffer(avm_mem_m_sub_clk, Transcript::proof_data); + serialize_to_buffer(avm_mem_m_addr, Transcript::proof_data); + serialize_to_buffer(avm_mem_m_tag, Transcript::proof_data); + serialize_to_buffer(avm_mem_m_val, Transcript::proof_data); + serialize_to_buffer(avm_mem_m_lastAccess, Transcript::proof_data); + serialize_to_buffer(avm_mem_m_last, Transcript::proof_data); + serialize_to_buffer(avm_mem_m_rw, Transcript::proof_data); + serialize_to_buffer(avm_mem_m_in_tag, Transcript::proof_data); + serialize_to_buffer(avm_mem_m_tag_err, Transcript::proof_data); + serialize_to_buffer(avm_mem_m_one_min_inv, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_clk, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_ia, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_ib, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_ic, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_op_add, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_op_sub, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_op_mul, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_op_div, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_op_not, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_ff_tag, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u8_tag, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u16_tag, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u32_tag, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u64_tag, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u128_tag, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u8_r0, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u8_r1, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u16_r0, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u16_r1, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u16_r2, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u16_r3, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u16_r4, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u16_r5, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u16_r6, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u16_r7, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_u64_r0, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_cf, Transcript::proof_data); + serialize_to_buffer(avm_main_pc, Transcript::proof_data); + serialize_to_buffer(avm_main_internal_return_ptr, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_internal_call, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_internal_return, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_jump, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_halt, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_add, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_sub, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_mul, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_div, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_not, Transcript::proof_data); + serialize_to_buffer(avm_main_in_tag, Transcript::proof_data); + serialize_to_buffer(avm_main_op_err, Transcript::proof_data); + serialize_to_buffer(avm_main_tag_err, Transcript::proof_data); + serialize_to_buffer(avm_main_inv, Transcript::proof_data); + serialize_to_buffer(avm_main_ia, Transcript::proof_data); + serialize_to_buffer(avm_main_ib, Transcript::proof_data); + serialize_to_buffer(avm_main_ic, Transcript::proof_data); + serialize_to_buffer(avm_main_mem_op_a, Transcript::proof_data); + serialize_to_buffer(avm_main_mem_op_b, Transcript::proof_data); + serialize_to_buffer(avm_main_mem_op_c, Transcript::proof_data); + serialize_to_buffer(avm_main_rwa, Transcript::proof_data); + serialize_to_buffer(avm_main_rwb, Transcript::proof_data); + serialize_to_buffer(avm_main_rwc, Transcript::proof_data); + serialize_to_buffer(avm_main_mem_idx_a, Transcript::proof_data); + serialize_to_buffer(avm_main_mem_idx_b, Transcript::proof_data); + serialize_to_buffer(avm_main_mem_idx_c, Transcript::proof_data); + serialize_to_buffer(avm_main_last, Transcript::proof_data); + + for (size_t i = 0; i < log_n; ++i) { + serialize_to_buffer(sumcheck_univariates[i], Transcript::proof_data); + } + serialize_to_buffer(sumcheck_evaluations, Transcript::proof_data); + for (size_t i = 0; i < log_n; ++i) { + serialize_to_buffer(zm_cq_comms[i], proof_data); + } + serialize_to_buffer(zm_cq_comm, proof_data); + serialize_to_buffer(zm_pi_comm, proof_data); + + // sanity check to make sure we generate the same length of proof as before. + ASSERT(proof_data.size() == old_proof_length); + } + }; +}; + +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp deleted file mode 100644 index d5f3d1e5786..00000000000 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp +++ /dev/null @@ -1,282 +0,0 @@ - - -// AUTOGENERATED FILE -#pragma once - -#include "barretenberg/common/constexpr_utils.hpp" -#include "barretenberg/common/throw_or_abort.hpp" -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/honk/proof_system/logderivative_library.hpp" -#include "barretenberg/proof_system/circuit_builder/circuit_builder_base.hpp" -#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp" -#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" - -#include "barretenberg/flavor/generated/AvmMini_flavor.hpp" -#include "barretenberg/relations/generated/AvmMini/alu_chip.hpp" -#include "barretenberg/relations/generated/AvmMini/avm_mini.hpp" -#include "barretenberg/relations/generated/AvmMini/mem_trace.hpp" - -using namespace bb; - -namespace bb { - -template struct AvmMiniFullRow { - FF avmMini_clk{}; - FF avmMini_first{}; - FF memTrace_m_clk{}; - FF memTrace_m_sub_clk{}; - FF memTrace_m_addr{}; - FF memTrace_m_tag{}; - FF memTrace_m_val{}; - FF memTrace_m_lastAccess{}; - FF memTrace_m_last{}; - FF memTrace_m_rw{}; - FF memTrace_m_in_tag{}; - FF memTrace_m_tag_err{}; - FF memTrace_m_one_min_inv{}; - FF aluChip_alu_clk{}; - FF aluChip_alu_ia{}; - FF aluChip_alu_ib{}; - FF aluChip_alu_ic{}; - FF aluChip_alu_op_add{}; - FF aluChip_alu_op_sub{}; - FF aluChip_alu_op_mul{}; - FF aluChip_alu_op_div{}; - FF aluChip_alu_op_not{}; - FF aluChip_alu_ff_tag{}; - FF aluChip_alu_u8_tag{}; - FF aluChip_alu_u16_tag{}; - FF aluChip_alu_u32_tag{}; - FF aluChip_alu_u64_tag{}; - FF aluChip_alu_u128_tag{}; - FF aluChip_alu_u8_r0{}; - FF aluChip_alu_u8_r1{}; - FF aluChip_alu_u16_r0{}; - FF aluChip_alu_u16_r1{}; - FF aluChip_alu_u16_r2{}; - FF aluChip_alu_u16_r3{}; - FF aluChip_alu_u16_r4{}; - FF aluChip_alu_u16_r5{}; - FF aluChip_alu_u16_r6{}; - FF aluChip_alu_u16_r7{}; - FF aluChip_alu_u64_r0{}; - FF aluChip_alu_cf{}; - FF avmMini_pc{}; - FF avmMini_internal_return_ptr{}; - FF avmMini_sel_internal_call{}; - FF avmMini_sel_internal_return{}; - FF avmMini_sel_jump{}; - FF avmMini_sel_halt{}; - FF avmMini_sel_op_add{}; - FF avmMini_sel_op_sub{}; - FF avmMini_sel_op_mul{}; - FF avmMini_sel_op_div{}; - FF avmMini_sel_op_not{}; - FF avmMini_in_tag{}; - FF avmMini_op_err{}; - FF avmMini_tag_err{}; - FF avmMini_inv{}; - FF avmMini_ia{}; - FF avmMini_ib{}; - FF avmMini_ic{}; - FF avmMini_mem_op_a{}; - FF avmMini_mem_op_b{}; - FF avmMini_mem_op_c{}; - FF avmMini_rwa{}; - FF avmMini_rwb{}; - FF avmMini_rwc{}; - FF avmMini_mem_idx_a{}; - FF avmMini_mem_idx_b{}; - FF avmMini_mem_idx_c{}; - FF avmMini_last{}; - FF memTrace_m_rw_shift{}; - FF memTrace_m_val_shift{}; - FF memTrace_m_addr_shift{}; - FF memTrace_m_tag_shift{}; - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u16_r3_shift{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_pc_shift{}; -}; - -class AvmMiniCircuitBuilder { - public: - using Flavor = bb::AvmMiniFlavor; - using FF = Flavor::FF; - using Row = AvmMiniFullRow; - - // TODO: template - using Polynomial = Flavor::Polynomial; - using ProverPolynomials = Flavor::ProverPolynomials; - - static constexpr size_t num_fixed_columns = 82; - static constexpr size_t num_polys = 68; - std::vector rows; - - void set_trace(std::vector&& trace) { rows = std::move(trace); } - - ProverPolynomials compute_polynomials() - { - const auto num_rows = get_circuit_subgroup_size(); - ProverPolynomials polys; - - // Allocate mem for each column - for (auto& poly : polys.get_all()) { - poly = Polynomial(num_rows); - } - - for (size_t i = 0; i < rows.size(); i++) { - polys.avmMini_clk[i] = rows[i].avmMini_clk; - polys.avmMini_first[i] = rows[i].avmMini_first; - polys.memTrace_m_clk[i] = rows[i].memTrace_m_clk; - polys.memTrace_m_sub_clk[i] = rows[i].memTrace_m_sub_clk; - polys.memTrace_m_addr[i] = rows[i].memTrace_m_addr; - polys.memTrace_m_tag[i] = rows[i].memTrace_m_tag; - polys.memTrace_m_val[i] = rows[i].memTrace_m_val; - polys.memTrace_m_lastAccess[i] = rows[i].memTrace_m_lastAccess; - polys.memTrace_m_last[i] = rows[i].memTrace_m_last; - polys.memTrace_m_rw[i] = rows[i].memTrace_m_rw; - polys.memTrace_m_in_tag[i] = rows[i].memTrace_m_in_tag; - polys.memTrace_m_tag_err[i] = rows[i].memTrace_m_tag_err; - polys.memTrace_m_one_min_inv[i] = rows[i].memTrace_m_one_min_inv; - polys.aluChip_alu_clk[i] = rows[i].aluChip_alu_clk; - polys.aluChip_alu_ia[i] = rows[i].aluChip_alu_ia; - polys.aluChip_alu_ib[i] = rows[i].aluChip_alu_ib; - polys.aluChip_alu_ic[i] = rows[i].aluChip_alu_ic; - polys.aluChip_alu_op_add[i] = rows[i].aluChip_alu_op_add; - polys.aluChip_alu_op_sub[i] = rows[i].aluChip_alu_op_sub; - polys.aluChip_alu_op_mul[i] = rows[i].aluChip_alu_op_mul; - polys.aluChip_alu_op_div[i] = rows[i].aluChip_alu_op_div; - polys.aluChip_alu_op_not[i] = rows[i].aluChip_alu_op_not; - polys.aluChip_alu_ff_tag[i] = rows[i].aluChip_alu_ff_tag; - polys.aluChip_alu_u8_tag[i] = rows[i].aluChip_alu_u8_tag; - polys.aluChip_alu_u16_tag[i] = rows[i].aluChip_alu_u16_tag; - polys.aluChip_alu_u32_tag[i] = rows[i].aluChip_alu_u32_tag; - polys.aluChip_alu_u64_tag[i] = rows[i].aluChip_alu_u64_tag; - polys.aluChip_alu_u128_tag[i] = rows[i].aluChip_alu_u128_tag; - polys.aluChip_alu_u8_r0[i] = rows[i].aluChip_alu_u8_r0; - polys.aluChip_alu_u8_r1[i] = rows[i].aluChip_alu_u8_r1; - polys.aluChip_alu_u16_r0[i] = rows[i].aluChip_alu_u16_r0; - polys.aluChip_alu_u16_r1[i] = rows[i].aluChip_alu_u16_r1; - polys.aluChip_alu_u16_r2[i] = rows[i].aluChip_alu_u16_r2; - polys.aluChip_alu_u16_r3[i] = rows[i].aluChip_alu_u16_r3; - polys.aluChip_alu_u16_r4[i] = rows[i].aluChip_alu_u16_r4; - polys.aluChip_alu_u16_r5[i] = rows[i].aluChip_alu_u16_r5; - polys.aluChip_alu_u16_r6[i] = rows[i].aluChip_alu_u16_r6; - polys.aluChip_alu_u16_r7[i] = rows[i].aluChip_alu_u16_r7; - polys.aluChip_alu_u64_r0[i] = rows[i].aluChip_alu_u64_r0; - polys.aluChip_alu_cf[i] = rows[i].aluChip_alu_cf; - polys.avmMini_pc[i] = rows[i].avmMini_pc; - polys.avmMini_internal_return_ptr[i] = rows[i].avmMini_internal_return_ptr; - polys.avmMini_sel_internal_call[i] = rows[i].avmMini_sel_internal_call; - polys.avmMini_sel_internal_return[i] = rows[i].avmMini_sel_internal_return; - polys.avmMini_sel_jump[i] = rows[i].avmMini_sel_jump; - polys.avmMini_sel_halt[i] = rows[i].avmMini_sel_halt; - polys.avmMini_sel_op_add[i] = rows[i].avmMini_sel_op_add; - polys.avmMini_sel_op_sub[i] = rows[i].avmMini_sel_op_sub; - polys.avmMini_sel_op_mul[i] = rows[i].avmMini_sel_op_mul; - polys.avmMini_sel_op_div[i] = rows[i].avmMini_sel_op_div; - polys.avmMini_sel_op_not[i] = rows[i].avmMini_sel_op_not; - polys.avmMini_in_tag[i] = rows[i].avmMini_in_tag; - polys.avmMini_op_err[i] = rows[i].avmMini_op_err; - polys.avmMini_tag_err[i] = rows[i].avmMini_tag_err; - polys.avmMini_inv[i] = rows[i].avmMini_inv; - polys.avmMini_ia[i] = rows[i].avmMini_ia; - polys.avmMini_ib[i] = rows[i].avmMini_ib; - polys.avmMini_ic[i] = rows[i].avmMini_ic; - polys.avmMini_mem_op_a[i] = rows[i].avmMini_mem_op_a; - polys.avmMini_mem_op_b[i] = rows[i].avmMini_mem_op_b; - polys.avmMini_mem_op_c[i] = rows[i].avmMini_mem_op_c; - polys.avmMini_rwa[i] = rows[i].avmMini_rwa; - polys.avmMini_rwb[i] = rows[i].avmMini_rwb; - polys.avmMini_rwc[i] = rows[i].avmMini_rwc; - polys.avmMini_mem_idx_a[i] = rows[i].avmMini_mem_idx_a; - polys.avmMini_mem_idx_b[i] = rows[i].avmMini_mem_idx_b; - polys.avmMini_mem_idx_c[i] = rows[i].avmMini_mem_idx_c; - polys.avmMini_last[i] = rows[i].avmMini_last; - } - - polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); - polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); - polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); - polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); - polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); - polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); - polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); - polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); - polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); - polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); - polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); - polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); - polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); - - return polys; - } - - [[maybe_unused]] bool check_circuit() - { - - auto polys = compute_polynomials(); - const size_t num_rows = polys.get_polynomial_size(); - - const auto evaluate_relation = [&](const std::string& relation_name, - std::string (*debug_label)(int)) { - typename Relation::SumcheckArrayOfValuesOverSubrelations result; - for (auto& r : result) { - r = 0; - } - constexpr size_t NUM_SUBRELATIONS = result.size(); - - for (size_t i = 0; i < num_rows; ++i) { - Relation::accumulate(result, polys.get_row(i), {}, 1); - - bool x = true; - for (size_t j = 0; j < NUM_SUBRELATIONS; ++j) { - if (result[j] != 0) { - std::string row_name = debug_label(static_cast(j)); - throw_or_abort( - format("Relation ", relation_name, ", subrelation index ", row_name, " failed at row ", i)); - x = false; - } - } - if (!x) { - return false; - } - } - return true; - }; - - if (!evaluate_relation.template operator()>( - "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { - return false; - } - if (!evaluate_relation.template operator()>("alu_chip", - AvmMini_vm::get_relation_label_alu_chip)) { - return false; - } - if (!evaluate_relation.template operator()>("avm_mini", - AvmMini_vm::get_relation_label_avm_mini)) { - return false; - } - - return true; - } - - [[nodiscard]] size_t get_num_gates() const { return rows.size(); } - - [[nodiscard]] size_t get_circuit_subgroup_size() const - { - const size_t num_rows = get_num_gates(); - const auto num_rows_log2 = static_cast(numeric::get_msb64(num_rows)); - size_t num_rows_pow2 = 1UL << (num_rows_log2 + (1UL << num_rows_log2 == num_rows ? 0 : 1)); - return num_rows_pow2; - } -}; -} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/avm_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/avm_circuit_builder.hpp new file mode 100644 index 00000000000..987a0d62ed6 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/avm_circuit_builder.hpp @@ -0,0 +1,280 @@ + + +// AUTOGENERATED FILE +#pragma once + +#include "barretenberg/common/constexpr_utils.hpp" +#include "barretenberg/common/throw_or_abort.hpp" +#include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/honk/proof_system/logderivative_library.hpp" +#include "barretenberg/proof_system/circuit_builder/circuit_builder_base.hpp" +#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp" +#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" + +#include "barretenberg/flavor/generated/avm_flavor.hpp" +#include "barretenberg/relations/generated/avm/avm_alu.hpp" +#include "barretenberg/relations/generated/avm/avm_main.hpp" +#include "barretenberg/relations/generated/avm/avm_mem.hpp" + +namespace bb { + +template struct AvmFullRow { + FF avm_main_clk{}; + FF avm_main_first{}; + FF avm_mem_m_clk{}; + FF avm_mem_m_sub_clk{}; + FF avm_mem_m_addr{}; + FF avm_mem_m_tag{}; + FF avm_mem_m_val{}; + FF avm_mem_m_lastAccess{}; + FF avm_mem_m_last{}; + FF avm_mem_m_rw{}; + FF avm_mem_m_in_tag{}; + FF avm_mem_m_tag_err{}; + FF avm_mem_m_one_min_inv{}; + FF avm_alu_alu_clk{}; + FF avm_alu_alu_ia{}; + FF avm_alu_alu_ib{}; + FF avm_alu_alu_ic{}; + FF avm_alu_alu_op_add{}; + FF avm_alu_alu_op_sub{}; + FF avm_alu_alu_op_mul{}; + FF avm_alu_alu_op_div{}; + FF avm_alu_alu_op_not{}; + FF avm_alu_alu_ff_tag{}; + FF avm_alu_alu_u8_tag{}; + FF avm_alu_alu_u16_tag{}; + FF avm_alu_alu_u32_tag{}; + FF avm_alu_alu_u64_tag{}; + FF avm_alu_alu_u128_tag{}; + FF avm_alu_alu_u8_r0{}; + FF avm_alu_alu_u8_r1{}; + FF avm_alu_alu_u16_r0{}; + FF avm_alu_alu_u16_r1{}; + FF avm_alu_alu_u16_r2{}; + FF avm_alu_alu_u16_r3{}; + FF avm_alu_alu_u16_r4{}; + FF avm_alu_alu_u16_r5{}; + FF avm_alu_alu_u16_r6{}; + FF avm_alu_alu_u16_r7{}; + FF avm_alu_alu_u64_r0{}; + FF avm_alu_alu_cf{}; + FF avm_main_pc{}; + FF avm_main_internal_return_ptr{}; + FF avm_main_sel_internal_call{}; + FF avm_main_sel_internal_return{}; + FF avm_main_sel_jump{}; + FF avm_main_sel_halt{}; + FF avm_main_sel_op_add{}; + FF avm_main_sel_op_sub{}; + FF avm_main_sel_op_mul{}; + FF avm_main_sel_op_div{}; + FF avm_main_sel_op_not{}; + FF avm_main_in_tag{}; + FF avm_main_op_err{}; + FF avm_main_tag_err{}; + FF avm_main_inv{}; + FF avm_main_ia{}; + FF avm_main_ib{}; + FF avm_main_ic{}; + FF avm_main_mem_op_a{}; + FF avm_main_mem_op_b{}; + FF avm_main_mem_op_c{}; + FF avm_main_rwa{}; + FF avm_main_rwb{}; + FF avm_main_rwc{}; + FF avm_main_mem_idx_a{}; + FF avm_main_mem_idx_b{}; + FF avm_main_mem_idx_c{}; + FF avm_main_last{}; + FF avm_main_pc_shift{}; + FF avm_main_internal_return_ptr_shift{}; + FF avm_mem_m_rw_shift{}; + FF avm_mem_m_addr_shift{}; + FF avm_mem_m_val_shift{}; + FF avm_mem_m_tag_shift{}; + FF avm_alu_alu_u16_r6_shift{}; + FF avm_alu_alu_u16_r4_shift{}; + FF avm_alu_alu_u16_r1_shift{}; + FF avm_alu_alu_u16_r2_shift{}; + FF avm_alu_alu_u16_r7_shift{}; + FF avm_alu_alu_u16_r0_shift{}; + FF avm_alu_alu_u16_r3_shift{}; + FF avm_alu_alu_u16_r5_shift{}; +}; + +class AvmCircuitBuilder { + public: + using Flavor = bb::AvmFlavor; + using FF = Flavor::FF; + using Row = AvmFullRow; + + // TODO: template + using Polynomial = Flavor::Polynomial; + using ProverPolynomials = Flavor::ProverPolynomials; + + static constexpr size_t num_fixed_columns = 82; + static constexpr size_t num_polys = 68; + std::vector rows; + + void set_trace(std::vector&& trace) { rows = std::move(trace); } + + ProverPolynomials compute_polynomials() + { + const auto num_rows = get_circuit_subgroup_size(); + ProverPolynomials polys; + + // Allocate mem for each column + for (auto& poly : polys.get_all()) { + poly = Polynomial(num_rows); + } + + for (size_t i = 0; i < rows.size(); i++) { + polys.avm_main_clk[i] = rows[i].avm_main_clk; + polys.avm_main_first[i] = rows[i].avm_main_first; + polys.avm_mem_m_clk[i] = rows[i].avm_mem_m_clk; + polys.avm_mem_m_sub_clk[i] = rows[i].avm_mem_m_sub_clk; + polys.avm_mem_m_addr[i] = rows[i].avm_mem_m_addr; + polys.avm_mem_m_tag[i] = rows[i].avm_mem_m_tag; + polys.avm_mem_m_val[i] = rows[i].avm_mem_m_val; + polys.avm_mem_m_lastAccess[i] = rows[i].avm_mem_m_lastAccess; + polys.avm_mem_m_last[i] = rows[i].avm_mem_m_last; + polys.avm_mem_m_rw[i] = rows[i].avm_mem_m_rw; + polys.avm_mem_m_in_tag[i] = rows[i].avm_mem_m_in_tag; + polys.avm_mem_m_tag_err[i] = rows[i].avm_mem_m_tag_err; + polys.avm_mem_m_one_min_inv[i] = rows[i].avm_mem_m_one_min_inv; + polys.avm_alu_alu_clk[i] = rows[i].avm_alu_alu_clk; + polys.avm_alu_alu_ia[i] = rows[i].avm_alu_alu_ia; + polys.avm_alu_alu_ib[i] = rows[i].avm_alu_alu_ib; + polys.avm_alu_alu_ic[i] = rows[i].avm_alu_alu_ic; + polys.avm_alu_alu_op_add[i] = rows[i].avm_alu_alu_op_add; + polys.avm_alu_alu_op_sub[i] = rows[i].avm_alu_alu_op_sub; + polys.avm_alu_alu_op_mul[i] = rows[i].avm_alu_alu_op_mul; + polys.avm_alu_alu_op_div[i] = rows[i].avm_alu_alu_op_div; + polys.avm_alu_alu_op_not[i] = rows[i].avm_alu_alu_op_not; + polys.avm_alu_alu_ff_tag[i] = rows[i].avm_alu_alu_ff_tag; + polys.avm_alu_alu_u8_tag[i] = rows[i].avm_alu_alu_u8_tag; + polys.avm_alu_alu_u16_tag[i] = rows[i].avm_alu_alu_u16_tag; + polys.avm_alu_alu_u32_tag[i] = rows[i].avm_alu_alu_u32_tag; + polys.avm_alu_alu_u64_tag[i] = rows[i].avm_alu_alu_u64_tag; + polys.avm_alu_alu_u128_tag[i] = rows[i].avm_alu_alu_u128_tag; + polys.avm_alu_alu_u8_r0[i] = rows[i].avm_alu_alu_u8_r0; + polys.avm_alu_alu_u8_r1[i] = rows[i].avm_alu_alu_u8_r1; + polys.avm_alu_alu_u16_r0[i] = rows[i].avm_alu_alu_u16_r0; + polys.avm_alu_alu_u16_r1[i] = rows[i].avm_alu_alu_u16_r1; + polys.avm_alu_alu_u16_r2[i] = rows[i].avm_alu_alu_u16_r2; + polys.avm_alu_alu_u16_r3[i] = rows[i].avm_alu_alu_u16_r3; + polys.avm_alu_alu_u16_r4[i] = rows[i].avm_alu_alu_u16_r4; + polys.avm_alu_alu_u16_r5[i] = rows[i].avm_alu_alu_u16_r5; + polys.avm_alu_alu_u16_r6[i] = rows[i].avm_alu_alu_u16_r6; + polys.avm_alu_alu_u16_r7[i] = rows[i].avm_alu_alu_u16_r7; + polys.avm_alu_alu_u64_r0[i] = rows[i].avm_alu_alu_u64_r0; + polys.avm_alu_alu_cf[i] = rows[i].avm_alu_alu_cf; + polys.avm_main_pc[i] = rows[i].avm_main_pc; + polys.avm_main_internal_return_ptr[i] = rows[i].avm_main_internal_return_ptr; + polys.avm_main_sel_internal_call[i] = rows[i].avm_main_sel_internal_call; + polys.avm_main_sel_internal_return[i] = rows[i].avm_main_sel_internal_return; + polys.avm_main_sel_jump[i] = rows[i].avm_main_sel_jump; + polys.avm_main_sel_halt[i] = rows[i].avm_main_sel_halt; + polys.avm_main_sel_op_add[i] = rows[i].avm_main_sel_op_add; + polys.avm_main_sel_op_sub[i] = rows[i].avm_main_sel_op_sub; + polys.avm_main_sel_op_mul[i] = rows[i].avm_main_sel_op_mul; + polys.avm_main_sel_op_div[i] = rows[i].avm_main_sel_op_div; + polys.avm_main_sel_op_not[i] = rows[i].avm_main_sel_op_not; + polys.avm_main_in_tag[i] = rows[i].avm_main_in_tag; + polys.avm_main_op_err[i] = rows[i].avm_main_op_err; + polys.avm_main_tag_err[i] = rows[i].avm_main_tag_err; + polys.avm_main_inv[i] = rows[i].avm_main_inv; + polys.avm_main_ia[i] = rows[i].avm_main_ia; + polys.avm_main_ib[i] = rows[i].avm_main_ib; + polys.avm_main_ic[i] = rows[i].avm_main_ic; + polys.avm_main_mem_op_a[i] = rows[i].avm_main_mem_op_a; + polys.avm_main_mem_op_b[i] = rows[i].avm_main_mem_op_b; + polys.avm_main_mem_op_c[i] = rows[i].avm_main_mem_op_c; + polys.avm_main_rwa[i] = rows[i].avm_main_rwa; + polys.avm_main_rwb[i] = rows[i].avm_main_rwb; + polys.avm_main_rwc[i] = rows[i].avm_main_rwc; + polys.avm_main_mem_idx_a[i] = rows[i].avm_main_mem_idx_a; + polys.avm_main_mem_idx_b[i] = rows[i].avm_main_mem_idx_b; + polys.avm_main_mem_idx_c[i] = rows[i].avm_main_mem_idx_c; + polys.avm_main_last[i] = rows[i].avm_main_last; + } + + polys.avm_main_pc_shift = Polynomial(polys.avm_main_pc.shifted()); + polys.avm_main_internal_return_ptr_shift = Polynomial(polys.avm_main_internal_return_ptr.shifted()); + polys.avm_mem_m_rw_shift = Polynomial(polys.avm_mem_m_rw.shifted()); + polys.avm_mem_m_addr_shift = Polynomial(polys.avm_mem_m_addr.shifted()); + polys.avm_mem_m_val_shift = Polynomial(polys.avm_mem_m_val.shifted()); + polys.avm_mem_m_tag_shift = Polynomial(polys.avm_mem_m_tag.shifted()); + polys.avm_alu_alu_u16_r6_shift = Polynomial(polys.avm_alu_alu_u16_r6.shifted()); + polys.avm_alu_alu_u16_r4_shift = Polynomial(polys.avm_alu_alu_u16_r4.shifted()); + polys.avm_alu_alu_u16_r1_shift = Polynomial(polys.avm_alu_alu_u16_r1.shifted()); + polys.avm_alu_alu_u16_r2_shift = Polynomial(polys.avm_alu_alu_u16_r2.shifted()); + polys.avm_alu_alu_u16_r7_shift = Polynomial(polys.avm_alu_alu_u16_r7.shifted()); + polys.avm_alu_alu_u16_r0_shift = Polynomial(polys.avm_alu_alu_u16_r0.shifted()); + polys.avm_alu_alu_u16_r3_shift = Polynomial(polys.avm_alu_alu_u16_r3.shifted()); + polys.avm_alu_alu_u16_r5_shift = Polynomial(polys.avm_alu_alu_u16_r5.shifted()); + + return polys; + } + + [[maybe_unused]] bool check_circuit() + { + + auto polys = compute_polynomials(); + const size_t num_rows = polys.get_polynomial_size(); + + const auto evaluate_relation = [&](const std::string& relation_name, + std::string (*debug_label)(int)) { + typename Relation::SumcheckArrayOfValuesOverSubrelations result; + for (auto& r : result) { + r = 0; + } + constexpr size_t NUM_SUBRELATIONS = result.size(); + + for (size_t i = 0; i < num_rows; ++i) { + Relation::accumulate(result, polys.get_row(i), {}, 1); + + bool x = true; + for (size_t j = 0; j < NUM_SUBRELATIONS; ++j) { + if (result[j] != 0) { + std::string row_name = debug_label(static_cast(j)); + throw_or_abort( + format("Relation ", relation_name, ", subrelation index ", row_name, " failed at row ", i)); + x = false; + } + } + if (!x) { + return false; + } + } + return true; + }; + + if (!evaluate_relation.template operator()>("avm_main", + Avm_vm::get_relation_label_avm_main)) { + return false; + } + if (!evaluate_relation.template operator()>("avm_mem", + Avm_vm::get_relation_label_avm_mem)) { + return false; + } + if (!evaluate_relation.template operator()>("avm_alu", + Avm_vm::get_relation_label_avm_alu)) { + return false; + } + + return true; + } + + [[nodiscard]] size_t get_num_gates() const { return rows.size(); } + + [[nodiscard]] size_t get_circuit_subgroup_size() const + { + const size_t num_rows = get_num_gates(); + const auto num_rows_log2 = static_cast(numeric::get_msb64(num_rows)); + size_t num_rows_pow2 = 1UL << (num_rows_log2 + (1UL << num_rows_log2 == num_rows ? 0 : 1)); + return num_rows_pow2; + } +}; +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp deleted file mode 100644 index 4c14d6617b4..00000000000 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ /dev/null @@ -1,308 +0,0 @@ - -#pragma once -#include "../../relation_parameters.hpp" -#include "../../relation_types.hpp" -#include "./declare_views.hpp" - -namespace bb::AvmMini_vm { - -template struct Alu_chipRow { - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r1{}; - FF aluChip_alu_u16_r6{}; - FF aluChip_alu_op_add{}; - FF aluChip_alu_u8_r1{}; - FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_op_sub{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_ib{}; - FF aluChip_alu_u16_tag{}; - FF aluChip_alu_u16_r7{}; - FF aluChip_alu_u8_r0{}; - FF aluChip_alu_u16_r2{}; - FF aluChip_alu_op_mul{}; - FF aluChip_alu_u8_tag{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u64_tag{}; - FF aluChip_alu_ia{}; - FF aluChip_alu_u16_r0{}; - FF aluChip_alu_ic{}; - FF aluChip_alu_u32_tag{}; - FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_ff_tag{}; - FF aluChip_alu_u16_r4{}; - FF aluChip_alu_u16_r5{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u64_r0{}; - FF aluChip_alu_op_not{}; - FF aluChip_alu_u128_tag{}; - FF aluChip_alu_cf{}; - FF aluChip_alu_u16_r3{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u16_r3_shift{}; -}; - -inline std::string get_relation_label_alu_chip(int index) -{ - switch (index) { - case 14: - return "ALU_FF_NOT_XOR"; - - case 6: - return "ALU_ADD_SUB_1"; - - case 13: - return "ALU_MULTIPLICATION_OUT_U128"; - - case 15: - return "ALU_OP_NOT"; - - case 7: - return "ALU_ADD_SUB_2"; - - case 8: - return "ALU_MULTIPLICATION_FF"; - - case 9: - return "ALU_MUL_COMMON_1"; - - case 10: - return "ALU_MUL_COMMON_2"; - } - return std::to_string(index); -} - -template class alu_chipImpl { - public: - using FF = FF_; - - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 6, 6, 8, 3, 4, - }; - - template - void static accumulate(ContainerOverSubrelations& evals, - const AllEntities& new_term, - [[maybe_unused]] const RelationParameters&, - [[maybe_unused]] const FF& scaling_factor) - { - - // Contribution 0 - { - AvmMini_DECLARE_VIEWS(0); - - auto tmp = (aluChip_alu_ff_tag * (-aluChip_alu_ff_tag + FF(1))); - tmp *= scaling_factor; - std::get<0>(evals) += tmp; - } - // Contribution 1 - { - AvmMini_DECLARE_VIEWS(1); - - auto tmp = (aluChip_alu_u8_tag * (-aluChip_alu_u8_tag + FF(1))); - tmp *= scaling_factor; - std::get<1>(evals) += tmp; - } - // Contribution 2 - { - AvmMini_DECLARE_VIEWS(2); - - auto tmp = (aluChip_alu_u16_tag * (-aluChip_alu_u16_tag + FF(1))); - tmp *= scaling_factor; - std::get<2>(evals) += tmp; - } - // Contribution 3 - { - AvmMini_DECLARE_VIEWS(3); - - auto tmp = (aluChip_alu_u32_tag * (-aluChip_alu_u32_tag + FF(1))); - tmp *= scaling_factor; - std::get<3>(evals) += tmp; - } - // Contribution 4 - { - AvmMini_DECLARE_VIEWS(4); - - auto tmp = (aluChip_alu_u64_tag * (-aluChip_alu_u64_tag + FF(1))); - tmp *= scaling_factor; - std::get<4>(evals) += tmp; - } - // Contribution 5 - { - AvmMini_DECLARE_VIEWS(5); - - auto tmp = (aluChip_alu_u128_tag * (-aluChip_alu_u128_tag + FF(1))); - tmp *= scaling_factor; - std::get<5>(evals) += tmp; - } - // Contribution 6 - { - AvmMini_DECLARE_VIEWS(6); - - auto tmp = - (((aluChip_alu_op_add + aluChip_alu_op_sub) * - ((((((((((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))) + - (aluChip_alu_u16_r1 * FF(4294967296UL))) + - (aluChip_alu_u16_r2 * FF(281474976710656UL))) + - (aluChip_alu_u16_r3 * FF(uint256_t{ 0, 1, 0, 0 }))) + - (aluChip_alu_u16_r4 * FF(uint256_t{ 0, 65536, 0, 0 }))) + - (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + - (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - - aluChip_alu_ia) + - (aluChip_alu_ff_tag * aluChip_alu_ic))) + - ((aluChip_alu_op_add - aluChip_alu_op_sub) * - ((aluChip_alu_cf * FF(uint256_t{ 0, 0, 1, 0 })) - aluChip_alu_ib))); - tmp *= scaling_factor; - std::get<6>(evals) += tmp; - } - // Contribution 7 - { - AvmMini_DECLARE_VIEWS(7); - - auto tmp = - (((aluChip_alu_op_add + aluChip_alu_op_sub) * - (((((((aluChip_alu_u8_tag * aluChip_alu_u8_r0) + - (aluChip_alu_u16_tag * (aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))))) + - (aluChip_alu_u32_tag * - ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))))) + - (aluChip_alu_u64_tag * - ((((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))) + - (aluChip_alu_u16_r1 * FF(4294967296UL))) + - (aluChip_alu_u16_r2 * FF(281474976710656UL))))) + - (aluChip_alu_u128_tag * - ((((((((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))) + - (aluChip_alu_u16_r1 * FF(4294967296UL))) + - (aluChip_alu_u16_r2 * FF(281474976710656UL))) + - (aluChip_alu_u16_r3 * FF(uint256_t{ 0, 1, 0, 0 }))) + - (aluChip_alu_u16_r4 * FF(uint256_t{ 0, 65536, 0, 0 }))) + - (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + - (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))))) + - (aluChip_alu_ff_tag * aluChip_alu_ia)) - - aluChip_alu_ic)) + - ((aluChip_alu_ff_tag * (aluChip_alu_op_add - aluChip_alu_op_sub)) * aluChip_alu_ib)); - tmp *= scaling_factor; - std::get<7>(evals) += tmp; - } - // Contribution 8 - { - AvmMini_DECLARE_VIEWS(8); - - auto tmp = - ((aluChip_alu_ff_tag * aluChip_alu_op_mul) * ((aluChip_alu_ia * aluChip_alu_ib) - aluChip_alu_ic)); - tmp *= scaling_factor; - std::get<8>(evals) += tmp; - } - // Contribution 9 - { - AvmMini_DECLARE_VIEWS(9); - - auto tmp = - ((((-aluChip_alu_ff_tag + FF(1)) - aluChip_alu_u128_tag) * aluChip_alu_op_mul) * - (((((((((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))) + - (aluChip_alu_u16_r1 * FF(4294967296UL))) + - (aluChip_alu_u16_r2 * FF(281474976710656UL))) + - (aluChip_alu_u16_r3 * FF(uint256_t{ 0, 1, 0, 0 }))) + - (aluChip_alu_u16_r4 * FF(uint256_t{ 0, 65536, 0, 0 }))) + - (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + - (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - - (aluChip_alu_ia * aluChip_alu_ib))); - tmp *= scaling_factor; - std::get<9>(evals) += tmp; - } - // Contribution 10 - { - AvmMini_DECLARE_VIEWS(10); - - auto tmp = (aluChip_alu_op_mul * - (((((aluChip_alu_u8_tag * aluChip_alu_u8_r0) + - (aluChip_alu_u16_tag * (aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))))) + - (aluChip_alu_u32_tag * - ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))))) + - (aluChip_alu_u64_tag * - ((((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))) + - (aluChip_alu_u16_r1 * FF(4294967296UL))) + - (aluChip_alu_u16_r2 * FF(281474976710656UL))))) - - (((-aluChip_alu_ff_tag + FF(1)) - aluChip_alu_u128_tag) * aluChip_alu_ic))); - tmp *= scaling_factor; - std::get<10>(evals) += tmp; - } - // Contribution 11 - { - AvmMini_DECLARE_VIEWS(11); - - auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * - (((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + - (aluChip_alu_u16_r2 * FF(4294967296UL))) + - (aluChip_alu_u16_r3 * FF(281474976710656UL))) + - ((((aluChip_alu_u16_r4 + (aluChip_alu_u16_r5 * FF(65536))) + - (aluChip_alu_u16_r6 * FF(4294967296UL))) + - (aluChip_alu_u16_r7 * FF(281474976710656UL))) * - FF(uint256_t{ 0, 1, 0, 0 }))) - - aluChip_alu_ia)); - tmp *= scaling_factor; - std::get<11>(evals) += tmp; - } - // Contribution 12 - { - AvmMini_DECLARE_VIEWS(12); - - auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * - (((((aluChip_alu_u16_r0_shift + (aluChip_alu_u16_r1_shift * FF(65536))) + - (aluChip_alu_u16_r2_shift * FF(4294967296UL))) + - (aluChip_alu_u16_r3_shift * FF(281474976710656UL))) + - ((((aluChip_alu_u16_r4_shift + (aluChip_alu_u16_r5_shift * FF(65536))) + - (aluChip_alu_u16_r6_shift * FF(4294967296UL))) + - (aluChip_alu_u16_r7_shift * FF(281474976710656UL))) * - FF(uint256_t{ 0, 1, 0, 0 }))) - - aluChip_alu_ib)); - tmp *= scaling_factor; - std::get<12>(evals) += tmp; - } - // Contribution 13 - { - AvmMini_DECLARE_VIEWS(13); - - auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * - ((((aluChip_alu_ia * (((aluChip_alu_u16_r0_shift + (aluChip_alu_u16_r1_shift * FF(65536))) + - (aluChip_alu_u16_r2_shift * FF(4294967296UL))) + - (aluChip_alu_u16_r3_shift * FF(281474976710656UL)))) + - (((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + - (aluChip_alu_u16_r2 * FF(4294967296UL))) + - (aluChip_alu_u16_r3 * FF(281474976710656UL))) * - (((aluChip_alu_u16_r4_shift + (aluChip_alu_u16_r5_shift * FF(65536))) + - (aluChip_alu_u16_r6_shift * FF(4294967296UL))) + - (aluChip_alu_u16_r7_shift * FF(281474976710656UL)))) * - FF(uint256_t{ 0, 1, 0, 0 }))) - - (((aluChip_alu_cf * FF(uint256_t{ 0, 1, 0, 0 })) + aluChip_alu_u64_r0) * - FF(uint256_t{ 0, 0, 1, 0 }))) - - aluChip_alu_ic)); - tmp *= scaling_factor; - std::get<13>(evals) += tmp; - } - // Contribution 14 - { - AvmMini_DECLARE_VIEWS(14); - - auto tmp = (aluChip_alu_op_not * aluChip_alu_ff_tag); - tmp *= scaling_factor; - std::get<14>(evals) += tmp; - } - // Contribution 15 - { - AvmMini_DECLARE_VIEWS(15); - - auto tmp = (aluChip_alu_op_not * ((aluChip_alu_ia + aluChip_alu_ic) - - ((((((aluChip_alu_u8_tag * FF(256)) + (aluChip_alu_u16_tag * FF(65536))) + - (aluChip_alu_u32_tag * FF(4294967296UL))) + - (aluChip_alu_u64_tag * FF(uint256_t{ 0, 1, 0, 0 }))) + - (aluChip_alu_u128_tag * FF(uint256_t{ 0, 0, 1, 0 }))) - - FF(1)))); - tmp *= scaling_factor; - std::get<15>(evals) += tmp; - } - } -}; - -template using alu_chip = Relation>; - -} // namespace bb::AvmMini_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp deleted file mode 100644 index 7f883d2a0bc..00000000000 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ /dev/null @@ -1,403 +0,0 @@ - -#pragma once -#include "../../relation_parameters.hpp" -#include "../../relation_types.hpp" -#include "./declare_views.hpp" - -namespace bb::AvmMini_vm { - -template struct Avm_miniRow { - FF avmMini_sel_op_div{}; - FF avmMini_ic{}; - FF avmMini_sel_internal_call{}; - FF avmMini_mem_idx_b{}; - FF avmMini_rwc{}; - FF avmMini_mem_idx_a{}; - FF avmMini_sel_op_sub{}; - FF avmMini_rwa{}; - FF avmMini_sel_halt{}; - FF avmMini_tag_err{}; - FF avmMini_sel_jump{}; - FF avmMini_ib{}; - FF avmMini_pc{}; - FF avmMini_sel_internal_return{}; - FF avmMini_inv{}; - FF avmMini_sel_op_mul{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_rwb{}; - FF avmMini_op_err{}; - FF avmMini_internal_return_ptr{}; - FF avmMini_sel_op_add{}; - FF avmMini_mem_op_b{}; - FF avmMini_pc_shift{}; - FF avmMini_sel_op_not{}; - FF avmMini_ia{}; - FF avmMini_first{}; - FF avmMini_mem_op_c{}; - FF avmMini_mem_op_a{}; -}; - -inline std::string get_relation_label_avm_mini(int index) -{ - switch (index) { - case 20: - return "SUBOP_DIVISION_FF"; - - case 37: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - - case 36: - return "PC_INCREMENT"; - - case 21: - return "SUBOP_DIVISION_ZERO_ERR1"; - - case 25: - return "RETURN_POINTER_INCREMENT"; - - case 23: - return "SUBOP_ERROR_RELEVANT_OP"; - - case 22: - return "SUBOP_DIVISION_ZERO_ERR2"; - - case 31: - return "RETURN_POINTER_DECREMENT"; - } - return std::to_string(index); -} - -template class avm_miniImpl { - public: - using FF = FF_; - - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, - }; - - template - void static accumulate(ContainerOverSubrelations& evals, - const AllEntities& new_term, - [[maybe_unused]] const RelationParameters&, - [[maybe_unused]] const FF& scaling_factor) - { - - // Contribution 0 - { - AvmMini_DECLARE_VIEWS(0); - - auto tmp = (avmMini_sel_op_add * (-avmMini_sel_op_add + FF(1))); - tmp *= scaling_factor; - std::get<0>(evals) += tmp; - } - // Contribution 1 - { - AvmMini_DECLARE_VIEWS(1); - - auto tmp = (avmMini_sel_op_sub * (-avmMini_sel_op_sub + FF(1))); - tmp *= scaling_factor; - std::get<1>(evals) += tmp; - } - // Contribution 2 - { - AvmMini_DECLARE_VIEWS(2); - - auto tmp = (avmMini_sel_op_mul * (-avmMini_sel_op_mul + FF(1))); - tmp *= scaling_factor; - std::get<2>(evals) += tmp; - } - // Contribution 3 - { - AvmMini_DECLARE_VIEWS(3); - - auto tmp = (avmMini_sel_op_div * (-avmMini_sel_op_div + FF(1))); - tmp *= scaling_factor; - std::get<3>(evals) += tmp; - } - // Contribution 4 - { - AvmMini_DECLARE_VIEWS(4); - - auto tmp = (avmMini_sel_op_not * (-avmMini_sel_op_not + FF(1))); - tmp *= scaling_factor; - std::get<4>(evals) += tmp; - } - // Contribution 5 - { - AvmMini_DECLARE_VIEWS(5); - - auto tmp = (avmMini_sel_internal_call * (-avmMini_sel_internal_call + FF(1))); - tmp *= scaling_factor; - std::get<5>(evals) += tmp; - } - // Contribution 6 - { - AvmMini_DECLARE_VIEWS(6); - - auto tmp = (avmMini_sel_internal_return * (-avmMini_sel_internal_return + FF(1))); - tmp *= scaling_factor; - std::get<6>(evals) += tmp; - } - // Contribution 7 - { - AvmMini_DECLARE_VIEWS(7); - - auto tmp = (avmMini_sel_jump * (-avmMini_sel_jump + FF(1))); - tmp *= scaling_factor; - std::get<7>(evals) += tmp; - } - // Contribution 8 - { - AvmMini_DECLARE_VIEWS(8); - - auto tmp = (avmMini_sel_halt * (-avmMini_sel_halt + FF(1))); - tmp *= scaling_factor; - std::get<8>(evals) += tmp; - } - // Contribution 9 - { - AvmMini_DECLARE_VIEWS(9); - - auto tmp = (avmMini_op_err * (-avmMini_op_err + FF(1))); - tmp *= scaling_factor; - std::get<9>(evals) += tmp; - } - // Contribution 10 - { - AvmMini_DECLARE_VIEWS(10); - - auto tmp = (avmMini_tag_err * (-avmMini_tag_err + FF(1))); - tmp *= scaling_factor; - std::get<10>(evals) += tmp; - } - // Contribution 11 - { - AvmMini_DECLARE_VIEWS(11); - - auto tmp = (avmMini_mem_op_a * (-avmMini_mem_op_a + FF(1))); - tmp *= scaling_factor; - std::get<11>(evals) += tmp; - } - // Contribution 12 - { - AvmMini_DECLARE_VIEWS(12); - - auto tmp = (avmMini_mem_op_b * (-avmMini_mem_op_b + FF(1))); - tmp *= scaling_factor; - std::get<12>(evals) += tmp; - } - // Contribution 13 - { - AvmMini_DECLARE_VIEWS(13); - - auto tmp = (avmMini_mem_op_c * (-avmMini_mem_op_c + FF(1))); - tmp *= scaling_factor; - std::get<13>(evals) += tmp; - } - // Contribution 14 - { - AvmMini_DECLARE_VIEWS(14); - - auto tmp = (avmMini_rwa * (-avmMini_rwa + FF(1))); - tmp *= scaling_factor; - std::get<14>(evals) += tmp; - } - // Contribution 15 - { - AvmMini_DECLARE_VIEWS(15); - - auto tmp = (avmMini_rwb * (-avmMini_rwb + FF(1))); - tmp *= scaling_factor; - std::get<15>(evals) += tmp; - } - // Contribution 16 - { - AvmMini_DECLARE_VIEWS(16); - - auto tmp = (avmMini_rwc * (-avmMini_rwc + FF(1))); - tmp *= scaling_factor; - std::get<16>(evals) += tmp; - } - // Contribution 17 - { - AvmMini_DECLARE_VIEWS(17); - - auto tmp = (avmMini_tag_err * avmMini_ia); - tmp *= scaling_factor; - std::get<17>(evals) += tmp; - } - // Contribution 18 - { - AvmMini_DECLARE_VIEWS(18); - - auto tmp = (avmMini_tag_err * avmMini_ib); - tmp *= scaling_factor; - std::get<18>(evals) += tmp; - } - // Contribution 19 - { - AvmMini_DECLARE_VIEWS(19); - - auto tmp = (avmMini_tag_err * avmMini_ic); - tmp *= scaling_factor; - std::get<19>(evals) += tmp; - } - // Contribution 20 - { - AvmMini_DECLARE_VIEWS(20); - - auto tmp = ((avmMini_sel_op_div * (-avmMini_op_err + FF(1))) * ((avmMini_ic * avmMini_ib) - avmMini_ia)); - tmp *= scaling_factor; - std::get<20>(evals) += tmp; - } - // Contribution 21 - { - AvmMini_DECLARE_VIEWS(21); - - auto tmp = (avmMini_sel_op_div * (((avmMini_ib * avmMini_inv) - FF(1)) + avmMini_op_err)); - tmp *= scaling_factor; - std::get<21>(evals) += tmp; - } - // Contribution 22 - { - AvmMini_DECLARE_VIEWS(22); - - auto tmp = ((avmMini_sel_op_div * avmMini_op_err) * (-avmMini_inv + FF(1))); - tmp *= scaling_factor; - std::get<22>(evals) += tmp; - } - // Contribution 23 - { - AvmMini_DECLARE_VIEWS(23); - - auto tmp = (avmMini_op_err * (avmMini_sel_op_div - FF(1))); - tmp *= scaling_factor; - std::get<23>(evals) += tmp; - } - // Contribution 24 - { - AvmMini_DECLARE_VIEWS(24); - - auto tmp = (avmMini_sel_jump * (avmMini_pc_shift - avmMini_ia)); - tmp *= scaling_factor; - std::get<24>(evals) += tmp; - } - // Contribution 25 - { - AvmMini_DECLARE_VIEWS(25); - - auto tmp = (avmMini_sel_internal_call * - (avmMini_internal_return_ptr_shift - (avmMini_internal_return_ptr + FF(1)))); - tmp *= scaling_factor; - std::get<25>(evals) += tmp; - } - // Contribution 26 - { - AvmMini_DECLARE_VIEWS(26); - - auto tmp = (avmMini_sel_internal_call * (avmMini_internal_return_ptr - avmMini_mem_idx_b)); - tmp *= scaling_factor; - std::get<26>(evals) += tmp; - } - // Contribution 27 - { - AvmMini_DECLARE_VIEWS(27); - - auto tmp = (avmMini_sel_internal_call * (avmMini_pc_shift - avmMini_ia)); - tmp *= scaling_factor; - std::get<27>(evals) += tmp; - } - // Contribution 28 - { - AvmMini_DECLARE_VIEWS(28); - - auto tmp = (avmMini_sel_internal_call * ((avmMini_pc + FF(1)) - avmMini_ib)); - tmp *= scaling_factor; - std::get<28>(evals) += tmp; - } - // Contribution 29 - { - AvmMini_DECLARE_VIEWS(29); - - auto tmp = (avmMini_sel_internal_call * (avmMini_rwb - FF(1))); - tmp *= scaling_factor; - std::get<29>(evals) += tmp; - } - // Contribution 30 - { - AvmMini_DECLARE_VIEWS(30); - - auto tmp = (avmMini_sel_internal_call * (avmMini_mem_op_b - FF(1))); - tmp *= scaling_factor; - std::get<30>(evals) += tmp; - } - // Contribution 31 - { - AvmMini_DECLARE_VIEWS(31); - - auto tmp = (avmMini_sel_internal_return * - (avmMini_internal_return_ptr_shift - (avmMini_internal_return_ptr - FF(1)))); - tmp *= scaling_factor; - std::get<31>(evals) += tmp; - } - // Contribution 32 - { - AvmMini_DECLARE_VIEWS(32); - - auto tmp = (avmMini_sel_internal_return * ((avmMini_internal_return_ptr - FF(1)) - avmMini_mem_idx_a)); - tmp *= scaling_factor; - std::get<32>(evals) += tmp; - } - // Contribution 33 - { - AvmMini_DECLARE_VIEWS(33); - - auto tmp = (avmMini_sel_internal_return * (avmMini_pc_shift - avmMini_ia)); - tmp *= scaling_factor; - std::get<33>(evals) += tmp; - } - // Contribution 34 - { - AvmMini_DECLARE_VIEWS(34); - - auto tmp = (avmMini_sel_internal_return * avmMini_rwa); - tmp *= scaling_factor; - std::get<34>(evals) += tmp; - } - // Contribution 35 - { - AvmMini_DECLARE_VIEWS(35); - - auto tmp = (avmMini_sel_internal_return * (avmMini_mem_op_a - FF(1))); - tmp *= scaling_factor; - std::get<35>(evals) += tmp; - } - // Contribution 36 - { - AvmMini_DECLARE_VIEWS(36); - - auto tmp = ((((-avmMini_first + FF(1)) * (-avmMini_sel_halt + FF(1))) * - ((((avmMini_sel_op_add + avmMini_sel_op_sub) + avmMini_sel_op_div) + avmMini_sel_op_mul) + - avmMini_sel_op_not)) * - (avmMini_pc_shift - (avmMini_pc + FF(1)))); - tmp *= scaling_factor; - std::get<36>(evals) += tmp; - } - // Contribution 37 - { - AvmMini_DECLARE_VIEWS(37); - - auto tmp = - ((-(((avmMini_first + avmMini_sel_internal_call) + avmMini_sel_internal_return) + avmMini_sel_halt) + - FF(1)) * - (avmMini_internal_return_ptr_shift - avmMini_internal_return_ptr)); - tmp *= scaling_factor; - std::get<37>(evals) += tmp; - } - } -}; - -template using avm_mini = Relation>; - -} // namespace bb::AvmMini_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp deleted file mode 100644 index 00bea658bd9..00000000000 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ /dev/null @@ -1,86 +0,0 @@ - -#define AvmMini_DECLARE_VIEWS(index) \ - using Accumulator = typename std::tuple_element::type; \ - using View = typename Accumulator::View; \ - [[maybe_unused]] auto avmMini_clk = View(new_term.avmMini_clk); \ - [[maybe_unused]] auto avmMini_first = View(new_term.avmMini_first); \ - [[maybe_unused]] auto memTrace_m_clk = View(new_term.memTrace_m_clk); \ - [[maybe_unused]] auto memTrace_m_sub_clk = View(new_term.memTrace_m_sub_clk); \ - [[maybe_unused]] auto memTrace_m_addr = View(new_term.memTrace_m_addr); \ - [[maybe_unused]] auto memTrace_m_tag = View(new_term.memTrace_m_tag); \ - [[maybe_unused]] auto memTrace_m_val = View(new_term.memTrace_m_val); \ - [[maybe_unused]] auto memTrace_m_lastAccess = View(new_term.memTrace_m_lastAccess); \ - [[maybe_unused]] auto memTrace_m_last = View(new_term.memTrace_m_last); \ - [[maybe_unused]] auto memTrace_m_rw = View(new_term.memTrace_m_rw); \ - [[maybe_unused]] auto memTrace_m_in_tag = View(new_term.memTrace_m_in_tag); \ - [[maybe_unused]] auto memTrace_m_tag_err = View(new_term.memTrace_m_tag_err); \ - [[maybe_unused]] auto memTrace_m_one_min_inv = View(new_term.memTrace_m_one_min_inv); \ - [[maybe_unused]] auto aluChip_alu_clk = View(new_term.aluChip_alu_clk); \ - [[maybe_unused]] auto aluChip_alu_ia = View(new_term.aluChip_alu_ia); \ - [[maybe_unused]] auto aluChip_alu_ib = View(new_term.aluChip_alu_ib); \ - [[maybe_unused]] auto aluChip_alu_ic = View(new_term.aluChip_alu_ic); \ - [[maybe_unused]] auto aluChip_alu_op_add = View(new_term.aluChip_alu_op_add); \ - [[maybe_unused]] auto aluChip_alu_op_sub = View(new_term.aluChip_alu_op_sub); \ - [[maybe_unused]] auto aluChip_alu_op_mul = View(new_term.aluChip_alu_op_mul); \ - [[maybe_unused]] auto aluChip_alu_op_div = View(new_term.aluChip_alu_op_div); \ - [[maybe_unused]] auto aluChip_alu_op_not = View(new_term.aluChip_alu_op_not); \ - [[maybe_unused]] auto aluChip_alu_ff_tag = View(new_term.aluChip_alu_ff_tag); \ - [[maybe_unused]] auto aluChip_alu_u8_tag = View(new_term.aluChip_alu_u8_tag); \ - [[maybe_unused]] auto aluChip_alu_u16_tag = View(new_term.aluChip_alu_u16_tag); \ - [[maybe_unused]] auto aluChip_alu_u32_tag = View(new_term.aluChip_alu_u32_tag); \ - [[maybe_unused]] auto aluChip_alu_u64_tag = View(new_term.aluChip_alu_u64_tag); \ - [[maybe_unused]] auto aluChip_alu_u128_tag = View(new_term.aluChip_alu_u128_tag); \ - [[maybe_unused]] auto aluChip_alu_u8_r0 = View(new_term.aluChip_alu_u8_r0); \ - [[maybe_unused]] auto aluChip_alu_u8_r1 = View(new_term.aluChip_alu_u8_r1); \ - [[maybe_unused]] auto aluChip_alu_u16_r0 = View(new_term.aluChip_alu_u16_r0); \ - [[maybe_unused]] auto aluChip_alu_u16_r1 = View(new_term.aluChip_alu_u16_r1); \ - [[maybe_unused]] auto aluChip_alu_u16_r2 = View(new_term.aluChip_alu_u16_r2); \ - [[maybe_unused]] auto aluChip_alu_u16_r3 = View(new_term.aluChip_alu_u16_r3); \ - [[maybe_unused]] auto aluChip_alu_u16_r4 = View(new_term.aluChip_alu_u16_r4); \ - [[maybe_unused]] auto aluChip_alu_u16_r5 = View(new_term.aluChip_alu_u16_r5); \ - [[maybe_unused]] auto aluChip_alu_u16_r6 = View(new_term.aluChip_alu_u16_r6); \ - [[maybe_unused]] auto aluChip_alu_u16_r7 = View(new_term.aluChip_alu_u16_r7); \ - [[maybe_unused]] auto aluChip_alu_u64_r0 = View(new_term.aluChip_alu_u64_r0); \ - [[maybe_unused]] auto aluChip_alu_cf = View(new_term.aluChip_alu_cf); \ - [[maybe_unused]] auto avmMini_pc = View(new_term.avmMini_pc); \ - [[maybe_unused]] auto avmMini_internal_return_ptr = View(new_term.avmMini_internal_return_ptr); \ - [[maybe_unused]] auto avmMini_sel_internal_call = View(new_term.avmMini_sel_internal_call); \ - [[maybe_unused]] auto avmMini_sel_internal_return = View(new_term.avmMini_sel_internal_return); \ - [[maybe_unused]] auto avmMini_sel_jump = View(new_term.avmMini_sel_jump); \ - [[maybe_unused]] auto avmMini_sel_halt = View(new_term.avmMini_sel_halt); \ - [[maybe_unused]] auto avmMini_sel_op_add = View(new_term.avmMini_sel_op_add); \ - [[maybe_unused]] auto avmMini_sel_op_sub = View(new_term.avmMini_sel_op_sub); \ - [[maybe_unused]] auto avmMini_sel_op_mul = View(new_term.avmMini_sel_op_mul); \ - [[maybe_unused]] auto avmMini_sel_op_div = View(new_term.avmMini_sel_op_div); \ - [[maybe_unused]] auto avmMini_sel_op_not = View(new_term.avmMini_sel_op_not); \ - [[maybe_unused]] auto avmMini_in_tag = View(new_term.avmMini_in_tag); \ - [[maybe_unused]] auto avmMini_op_err = View(new_term.avmMini_op_err); \ - [[maybe_unused]] auto avmMini_tag_err = View(new_term.avmMini_tag_err); \ - [[maybe_unused]] auto avmMini_inv = View(new_term.avmMini_inv); \ - [[maybe_unused]] auto avmMini_ia = View(new_term.avmMini_ia); \ - [[maybe_unused]] auto avmMini_ib = View(new_term.avmMini_ib); \ - [[maybe_unused]] auto avmMini_ic = View(new_term.avmMini_ic); \ - [[maybe_unused]] auto avmMini_mem_op_a = View(new_term.avmMini_mem_op_a); \ - [[maybe_unused]] auto avmMini_mem_op_b = View(new_term.avmMini_mem_op_b); \ - [[maybe_unused]] auto avmMini_mem_op_c = View(new_term.avmMini_mem_op_c); \ - [[maybe_unused]] auto avmMini_rwa = View(new_term.avmMini_rwa); \ - [[maybe_unused]] auto avmMini_rwb = View(new_term.avmMini_rwb); \ - [[maybe_unused]] auto avmMini_rwc = View(new_term.avmMini_rwc); \ - [[maybe_unused]] auto avmMini_mem_idx_a = View(new_term.avmMini_mem_idx_a); \ - [[maybe_unused]] auto avmMini_mem_idx_b = View(new_term.avmMini_mem_idx_b); \ - [[maybe_unused]] auto avmMini_mem_idx_c = View(new_term.avmMini_mem_idx_c); \ - [[maybe_unused]] auto avmMini_last = View(new_term.avmMini_last); \ - [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ - [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ - [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ - [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ - [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); \ - [[maybe_unused]] auto avmMini_pc_shift = View(new_term.avmMini_pc_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp new file mode 100644 index 00000000000..9d14ec93e7f --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp @@ -0,0 +1,308 @@ + +#pragma once +#include "../../relation_parameters.hpp" +#include "../../relation_types.hpp" +#include "./declare_views.hpp" + +namespace bb::Avm_vm { + +template struct Avm_aluRow { + FF avm_alu_alu_ff_tag{}; + FF avm_alu_alu_u8_tag{}; + FF avm_alu_alu_u32_tag{}; + FF avm_alu_alu_u16_r6_shift{}; + FF avm_alu_alu_u16_tag{}; + FF avm_alu_alu_u16_r4{}; + FF avm_alu_alu_ib{}; + FF avm_alu_alu_u8_r0{}; + FF avm_alu_alu_op_not{}; + FF avm_alu_alu_u16_r7{}; + FF avm_alu_alu_u128_tag{}; + FF avm_alu_alu_u16_r0{}; + FF avm_alu_alu_u16_r2{}; + FF avm_alu_alu_u16_r4_shift{}; + FF avm_alu_alu_cf{}; + FF avm_alu_alu_u16_r1_shift{}; + FF avm_alu_alu_u16_r2_shift{}; + FF avm_alu_alu_u16_r3{}; + FF avm_alu_alu_ia{}; + FF avm_alu_alu_u16_r5{}; + FF avm_alu_alu_u16_r6{}; + FF avm_alu_alu_u16_r7_shift{}; + FF avm_alu_alu_u64_r0{}; + FF avm_alu_alu_u64_tag{}; + FF avm_alu_alu_op_add{}; + FF avm_alu_alu_u8_r1{}; + FF avm_alu_alu_u16_r0_shift{}; + FF avm_alu_alu_u16_r3_shift{}; + FF avm_alu_alu_op_mul{}; + FF avm_alu_alu_u16_r5_shift{}; + FF avm_alu_alu_ic{}; + FF avm_alu_alu_op_sub{}; + FF avm_alu_alu_u16_r1{}; +}; + +inline std::string get_relation_label_avm_alu(int index) +{ + switch (index) { + case 8: + return "ALU_MULTIPLICATION_FF"; + + case 10: + return "ALU_MUL_COMMON_2"; + + case 15: + return "ALU_OP_NOT"; + + case 13: + return "ALU_MULTIPLICATION_OUT_U128"; + + case 9: + return "ALU_MUL_COMMON_1"; + + case 6: + return "ALU_ADD_SUB_1"; + + case 14: + return "ALU_FF_NOT_XOR"; + + case 7: + return "ALU_ADD_SUB_2"; + } + return std::to_string(index); +} + +template class avm_aluImpl { + public: + using FF = FF_; + + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 6, 6, 8, 3, 4, + }; + + template + void static accumulate(ContainerOverSubrelations& evals, + const AllEntities& new_term, + [[maybe_unused]] const RelationParameters&, + [[maybe_unused]] const FF& scaling_factor) + { + + // Contribution 0 + { + Avm_DECLARE_VIEWS(0); + + auto tmp = (avm_alu_alu_ff_tag * (-avm_alu_alu_ff_tag + FF(1))); + tmp *= scaling_factor; + std::get<0>(evals) += tmp; + } + // Contribution 1 + { + Avm_DECLARE_VIEWS(1); + + auto tmp = (avm_alu_alu_u8_tag * (-avm_alu_alu_u8_tag + FF(1))); + tmp *= scaling_factor; + std::get<1>(evals) += tmp; + } + // Contribution 2 + { + Avm_DECLARE_VIEWS(2); + + auto tmp = (avm_alu_alu_u16_tag * (-avm_alu_alu_u16_tag + FF(1))); + tmp *= scaling_factor; + std::get<2>(evals) += tmp; + } + // Contribution 3 + { + Avm_DECLARE_VIEWS(3); + + auto tmp = (avm_alu_alu_u32_tag * (-avm_alu_alu_u32_tag + FF(1))); + tmp *= scaling_factor; + std::get<3>(evals) += tmp; + } + // Contribution 4 + { + Avm_DECLARE_VIEWS(4); + + auto tmp = (avm_alu_alu_u64_tag * (-avm_alu_alu_u64_tag + FF(1))); + tmp *= scaling_factor; + std::get<4>(evals) += tmp; + } + // Contribution 5 + { + Avm_DECLARE_VIEWS(5); + + auto tmp = (avm_alu_alu_u128_tag * (-avm_alu_alu_u128_tag + FF(1))); + tmp *= scaling_factor; + std::get<5>(evals) += tmp; + } + // Contribution 6 + { + Avm_DECLARE_VIEWS(6); + + auto tmp = + (((avm_alu_alu_op_add + avm_alu_alu_op_sub) * + ((((((((((avm_alu_alu_u8_r0 + (avm_alu_alu_u8_r1 * FF(256))) + (avm_alu_alu_u16_r0 * FF(65536))) + + (avm_alu_alu_u16_r1 * FF(4294967296UL))) + + (avm_alu_alu_u16_r2 * FF(281474976710656UL))) + + (avm_alu_alu_u16_r3 * FF(uint256_t{ 0, 1, 0, 0 }))) + + (avm_alu_alu_u16_r4 * FF(uint256_t{ 0, 65536, 0, 0 }))) + + (avm_alu_alu_u16_r5 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + + (avm_alu_alu_u16_r6 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - + avm_alu_alu_ia) + + (avm_alu_alu_ff_tag * avm_alu_alu_ic))) + + ((avm_alu_alu_op_add - avm_alu_alu_op_sub) * + ((avm_alu_alu_cf * FF(uint256_t{ 0, 0, 1, 0 })) - avm_alu_alu_ib))); + tmp *= scaling_factor; + std::get<6>(evals) += tmp; + } + // Contribution 7 + { + Avm_DECLARE_VIEWS(7); + + auto tmp = + (((avm_alu_alu_op_add + avm_alu_alu_op_sub) * + (((((((avm_alu_alu_u8_tag * avm_alu_alu_u8_r0) + + (avm_alu_alu_u16_tag * (avm_alu_alu_u8_r0 + (avm_alu_alu_u8_r1 * FF(256))))) + + (avm_alu_alu_u32_tag * + ((avm_alu_alu_u8_r0 + (avm_alu_alu_u8_r1 * FF(256))) + (avm_alu_alu_u16_r0 * FF(65536))))) + + (avm_alu_alu_u64_tag * + ((((avm_alu_alu_u8_r0 + (avm_alu_alu_u8_r1 * FF(256))) + (avm_alu_alu_u16_r0 * FF(65536))) + + (avm_alu_alu_u16_r1 * FF(4294967296UL))) + + (avm_alu_alu_u16_r2 * FF(281474976710656UL))))) + + (avm_alu_alu_u128_tag * + ((((((((avm_alu_alu_u8_r0 + (avm_alu_alu_u8_r1 * FF(256))) + (avm_alu_alu_u16_r0 * FF(65536))) + + (avm_alu_alu_u16_r1 * FF(4294967296UL))) + + (avm_alu_alu_u16_r2 * FF(281474976710656UL))) + + (avm_alu_alu_u16_r3 * FF(uint256_t{ 0, 1, 0, 0 }))) + + (avm_alu_alu_u16_r4 * FF(uint256_t{ 0, 65536, 0, 0 }))) + + (avm_alu_alu_u16_r5 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + + (avm_alu_alu_u16_r6 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))))) + + (avm_alu_alu_ff_tag * avm_alu_alu_ia)) - + avm_alu_alu_ic)) + + ((avm_alu_alu_ff_tag * (avm_alu_alu_op_add - avm_alu_alu_op_sub)) * avm_alu_alu_ib)); + tmp *= scaling_factor; + std::get<7>(evals) += tmp; + } + // Contribution 8 + { + Avm_DECLARE_VIEWS(8); + + auto tmp = + ((avm_alu_alu_ff_tag * avm_alu_alu_op_mul) * ((avm_alu_alu_ia * avm_alu_alu_ib) - avm_alu_alu_ic)); + tmp *= scaling_factor; + std::get<8>(evals) += tmp; + } + // Contribution 9 + { + Avm_DECLARE_VIEWS(9); + + auto tmp = + ((((-avm_alu_alu_ff_tag + FF(1)) - avm_alu_alu_u128_tag) * avm_alu_alu_op_mul) * + (((((((((avm_alu_alu_u8_r0 + (avm_alu_alu_u8_r1 * FF(256))) + (avm_alu_alu_u16_r0 * FF(65536))) + + (avm_alu_alu_u16_r1 * FF(4294967296UL))) + + (avm_alu_alu_u16_r2 * FF(281474976710656UL))) + + (avm_alu_alu_u16_r3 * FF(uint256_t{ 0, 1, 0, 0 }))) + + (avm_alu_alu_u16_r4 * FF(uint256_t{ 0, 65536, 0, 0 }))) + + (avm_alu_alu_u16_r5 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + + (avm_alu_alu_u16_r6 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - + (avm_alu_alu_ia * avm_alu_alu_ib))); + tmp *= scaling_factor; + std::get<9>(evals) += tmp; + } + // Contribution 10 + { + Avm_DECLARE_VIEWS(10); + + auto tmp = (avm_alu_alu_op_mul * + (((((avm_alu_alu_u8_tag * avm_alu_alu_u8_r0) + + (avm_alu_alu_u16_tag * (avm_alu_alu_u8_r0 + (avm_alu_alu_u8_r1 * FF(256))))) + + (avm_alu_alu_u32_tag * + ((avm_alu_alu_u8_r0 + (avm_alu_alu_u8_r1 * FF(256))) + (avm_alu_alu_u16_r0 * FF(65536))))) + + (avm_alu_alu_u64_tag * + ((((avm_alu_alu_u8_r0 + (avm_alu_alu_u8_r1 * FF(256))) + (avm_alu_alu_u16_r0 * FF(65536))) + + (avm_alu_alu_u16_r1 * FF(4294967296UL))) + + (avm_alu_alu_u16_r2 * FF(281474976710656UL))))) - + (((-avm_alu_alu_ff_tag + FF(1)) - avm_alu_alu_u128_tag) * avm_alu_alu_ic))); + tmp *= scaling_factor; + std::get<10>(evals) += tmp; + } + // Contribution 11 + { + Avm_DECLARE_VIEWS(11); + + auto tmp = ((avm_alu_alu_u128_tag * avm_alu_alu_op_mul) * + (((((avm_alu_alu_u16_r0 + (avm_alu_alu_u16_r1 * FF(65536))) + + (avm_alu_alu_u16_r2 * FF(4294967296UL))) + + (avm_alu_alu_u16_r3 * FF(281474976710656UL))) + + ((((avm_alu_alu_u16_r4 + (avm_alu_alu_u16_r5 * FF(65536))) + + (avm_alu_alu_u16_r6 * FF(4294967296UL))) + + (avm_alu_alu_u16_r7 * FF(281474976710656UL))) * + FF(uint256_t{ 0, 1, 0, 0 }))) - + avm_alu_alu_ia)); + tmp *= scaling_factor; + std::get<11>(evals) += tmp; + } + // Contribution 12 + { + Avm_DECLARE_VIEWS(12); + + auto tmp = ((avm_alu_alu_u128_tag * avm_alu_alu_op_mul) * + (((((avm_alu_alu_u16_r0_shift + (avm_alu_alu_u16_r1_shift * FF(65536))) + + (avm_alu_alu_u16_r2_shift * FF(4294967296UL))) + + (avm_alu_alu_u16_r3_shift * FF(281474976710656UL))) + + ((((avm_alu_alu_u16_r4_shift + (avm_alu_alu_u16_r5_shift * FF(65536))) + + (avm_alu_alu_u16_r6_shift * FF(4294967296UL))) + + (avm_alu_alu_u16_r7_shift * FF(281474976710656UL))) * + FF(uint256_t{ 0, 1, 0, 0 }))) - + avm_alu_alu_ib)); + tmp *= scaling_factor; + std::get<12>(evals) += tmp; + } + // Contribution 13 + { + Avm_DECLARE_VIEWS(13); + + auto tmp = ((avm_alu_alu_u128_tag * avm_alu_alu_op_mul) * + ((((avm_alu_alu_ia * (((avm_alu_alu_u16_r0_shift + (avm_alu_alu_u16_r1_shift * FF(65536))) + + (avm_alu_alu_u16_r2_shift * FF(4294967296UL))) + + (avm_alu_alu_u16_r3_shift * FF(281474976710656UL)))) + + (((((avm_alu_alu_u16_r0 + (avm_alu_alu_u16_r1 * FF(65536))) + + (avm_alu_alu_u16_r2 * FF(4294967296UL))) + + (avm_alu_alu_u16_r3 * FF(281474976710656UL))) * + (((avm_alu_alu_u16_r4_shift + (avm_alu_alu_u16_r5_shift * FF(65536))) + + (avm_alu_alu_u16_r6_shift * FF(4294967296UL))) + + (avm_alu_alu_u16_r7_shift * FF(281474976710656UL)))) * + FF(uint256_t{ 0, 1, 0, 0 }))) - + (((avm_alu_alu_cf * FF(uint256_t{ 0, 1, 0, 0 })) + avm_alu_alu_u64_r0) * + FF(uint256_t{ 0, 0, 1, 0 }))) - + avm_alu_alu_ic)); + tmp *= scaling_factor; + std::get<13>(evals) += tmp; + } + // Contribution 14 + { + Avm_DECLARE_VIEWS(14); + + auto tmp = (avm_alu_alu_op_not * avm_alu_alu_ff_tag); + tmp *= scaling_factor; + std::get<14>(evals) += tmp; + } + // Contribution 15 + { + Avm_DECLARE_VIEWS(15); + + auto tmp = (avm_alu_alu_op_not * ((avm_alu_alu_ia + avm_alu_alu_ic) - + ((((((avm_alu_alu_u8_tag * FF(256)) + (avm_alu_alu_u16_tag * FF(65536))) + + (avm_alu_alu_u32_tag * FF(4294967296UL))) + + (avm_alu_alu_u64_tag * FF(uint256_t{ 0, 1, 0, 0 }))) + + (avm_alu_alu_u128_tag * FF(uint256_t{ 0, 0, 1, 0 }))) - + FF(1)))); + tmp *= scaling_factor; + std::get<15>(evals) += tmp; + } + } +}; + +template using avm_alu = Relation>; + +} // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp new file mode 100644 index 00000000000..304942fe8cd --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp @@ -0,0 +1,404 @@ + +#pragma once +#include "../../relation_parameters.hpp" +#include "../../relation_types.hpp" +#include "./declare_views.hpp" + +namespace bb::Avm_vm { + +template struct Avm_mainRow { + FF avm_main_sel_internal_return{}; + FF avm_main_rwc{}; + FF avm_main_ia{}; + FF avm_main_first{}; + FF avm_main_sel_op_sub{}; + FF avm_main_pc_shift{}; + FF avm_main_tag_err{}; + FF avm_main_ib{}; + FF avm_main_ic{}; + FF avm_main_mem_op_c{}; + FF avm_main_mem_idx_a{}; + FF avm_main_mem_idx_b{}; + FF avm_main_op_err{}; + FF avm_main_rwb{}; + FF avm_main_inv{}; + FF avm_main_sel_jump{}; + FF avm_main_sel_op_not{}; + FF avm_main_sel_halt{}; + FF avm_main_sel_op_add{}; + FF avm_main_rwa{}; + FF avm_main_pc{}; + FF avm_main_sel_internal_call{}; + FF avm_main_sel_op_mul{}; + FF avm_main_sel_op_div{}; + FF avm_main_mem_op_b{}; + FF avm_main_internal_return_ptr_shift{}; + FF avm_main_internal_return_ptr{}; + FF avm_main_mem_op_a{}; +}; + +inline std::string get_relation_label_avm_main(int index) +{ + switch (index) { + case 36: + return "PC_INCREMENT"; + + case 20: + return "SUBOP_DIVISION_FF"; + + case 25: + return "RETURN_POINTER_INCREMENT"; + + case 21: + return "SUBOP_DIVISION_ZERO_ERR1"; + + case 31: + return "RETURN_POINTER_DECREMENT"; + + case 37: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + + case 23: + return "SUBOP_ERROR_RELEVANT_OP"; + + case 22: + return "SUBOP_DIVISION_ZERO_ERR2"; + } + return std::to_string(index); +} + +template class avm_mainImpl { + public: + using FF = FF_; + + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, + }; + + template + void static accumulate(ContainerOverSubrelations& evals, + const AllEntities& new_term, + [[maybe_unused]] const RelationParameters&, + [[maybe_unused]] const FF& scaling_factor) + { + + // Contribution 0 + { + Avm_DECLARE_VIEWS(0); + + auto tmp = (avm_main_sel_op_add * (-avm_main_sel_op_add + FF(1))); + tmp *= scaling_factor; + std::get<0>(evals) += tmp; + } + // Contribution 1 + { + Avm_DECLARE_VIEWS(1); + + auto tmp = (avm_main_sel_op_sub * (-avm_main_sel_op_sub + FF(1))); + tmp *= scaling_factor; + std::get<1>(evals) += tmp; + } + // Contribution 2 + { + Avm_DECLARE_VIEWS(2); + + auto tmp = (avm_main_sel_op_mul * (-avm_main_sel_op_mul + FF(1))); + tmp *= scaling_factor; + std::get<2>(evals) += tmp; + } + // Contribution 3 + { + Avm_DECLARE_VIEWS(3); + + auto tmp = (avm_main_sel_op_div * (-avm_main_sel_op_div + FF(1))); + tmp *= scaling_factor; + std::get<3>(evals) += tmp; + } + // Contribution 4 + { + Avm_DECLARE_VIEWS(4); + + auto tmp = (avm_main_sel_op_not * (-avm_main_sel_op_not + FF(1))); + tmp *= scaling_factor; + std::get<4>(evals) += tmp; + } + // Contribution 5 + { + Avm_DECLARE_VIEWS(5); + + auto tmp = (avm_main_sel_internal_call * (-avm_main_sel_internal_call + FF(1))); + tmp *= scaling_factor; + std::get<5>(evals) += tmp; + } + // Contribution 6 + { + Avm_DECLARE_VIEWS(6); + + auto tmp = (avm_main_sel_internal_return * (-avm_main_sel_internal_return + FF(1))); + tmp *= scaling_factor; + std::get<6>(evals) += tmp; + } + // Contribution 7 + { + Avm_DECLARE_VIEWS(7); + + auto tmp = (avm_main_sel_jump * (-avm_main_sel_jump + FF(1))); + tmp *= scaling_factor; + std::get<7>(evals) += tmp; + } + // Contribution 8 + { + Avm_DECLARE_VIEWS(8); + + auto tmp = (avm_main_sel_halt * (-avm_main_sel_halt + FF(1))); + tmp *= scaling_factor; + std::get<8>(evals) += tmp; + } + // Contribution 9 + { + Avm_DECLARE_VIEWS(9); + + auto tmp = (avm_main_op_err * (-avm_main_op_err + FF(1))); + tmp *= scaling_factor; + std::get<9>(evals) += tmp; + } + // Contribution 10 + { + Avm_DECLARE_VIEWS(10); + + auto tmp = (avm_main_tag_err * (-avm_main_tag_err + FF(1))); + tmp *= scaling_factor; + std::get<10>(evals) += tmp; + } + // Contribution 11 + { + Avm_DECLARE_VIEWS(11); + + auto tmp = (avm_main_mem_op_a * (-avm_main_mem_op_a + FF(1))); + tmp *= scaling_factor; + std::get<11>(evals) += tmp; + } + // Contribution 12 + { + Avm_DECLARE_VIEWS(12); + + auto tmp = (avm_main_mem_op_b * (-avm_main_mem_op_b + FF(1))); + tmp *= scaling_factor; + std::get<12>(evals) += tmp; + } + // Contribution 13 + { + Avm_DECLARE_VIEWS(13); + + auto tmp = (avm_main_mem_op_c * (-avm_main_mem_op_c + FF(1))); + tmp *= scaling_factor; + std::get<13>(evals) += tmp; + } + // Contribution 14 + { + Avm_DECLARE_VIEWS(14); + + auto tmp = (avm_main_rwa * (-avm_main_rwa + FF(1))); + tmp *= scaling_factor; + std::get<14>(evals) += tmp; + } + // Contribution 15 + { + Avm_DECLARE_VIEWS(15); + + auto tmp = (avm_main_rwb * (-avm_main_rwb + FF(1))); + tmp *= scaling_factor; + std::get<15>(evals) += tmp; + } + // Contribution 16 + { + Avm_DECLARE_VIEWS(16); + + auto tmp = (avm_main_rwc * (-avm_main_rwc + FF(1))); + tmp *= scaling_factor; + std::get<16>(evals) += tmp; + } + // Contribution 17 + { + Avm_DECLARE_VIEWS(17); + + auto tmp = (avm_main_tag_err * avm_main_ia); + tmp *= scaling_factor; + std::get<17>(evals) += tmp; + } + // Contribution 18 + { + Avm_DECLARE_VIEWS(18); + + auto tmp = (avm_main_tag_err * avm_main_ib); + tmp *= scaling_factor; + std::get<18>(evals) += tmp; + } + // Contribution 19 + { + Avm_DECLARE_VIEWS(19); + + auto tmp = (avm_main_tag_err * avm_main_ic); + tmp *= scaling_factor; + std::get<19>(evals) += tmp; + } + // Contribution 20 + { + Avm_DECLARE_VIEWS(20); + + auto tmp = + ((avm_main_sel_op_div * (-avm_main_op_err + FF(1))) * ((avm_main_ic * avm_main_ib) - avm_main_ia)); + tmp *= scaling_factor; + std::get<20>(evals) += tmp; + } + // Contribution 21 + { + Avm_DECLARE_VIEWS(21); + + auto tmp = (avm_main_sel_op_div * (((avm_main_ib * avm_main_inv) - FF(1)) + avm_main_op_err)); + tmp *= scaling_factor; + std::get<21>(evals) += tmp; + } + // Contribution 22 + { + Avm_DECLARE_VIEWS(22); + + auto tmp = ((avm_main_sel_op_div * avm_main_op_err) * (-avm_main_inv + FF(1))); + tmp *= scaling_factor; + std::get<22>(evals) += tmp; + } + // Contribution 23 + { + Avm_DECLARE_VIEWS(23); + + auto tmp = (avm_main_op_err * (avm_main_sel_op_div - FF(1))); + tmp *= scaling_factor; + std::get<23>(evals) += tmp; + } + // Contribution 24 + { + Avm_DECLARE_VIEWS(24); + + auto tmp = (avm_main_sel_jump * (avm_main_pc_shift - avm_main_ia)); + tmp *= scaling_factor; + std::get<24>(evals) += tmp; + } + // Contribution 25 + { + Avm_DECLARE_VIEWS(25); + + auto tmp = (avm_main_sel_internal_call * + (avm_main_internal_return_ptr_shift - (avm_main_internal_return_ptr + FF(1)))); + tmp *= scaling_factor; + std::get<25>(evals) += tmp; + } + // Contribution 26 + { + Avm_DECLARE_VIEWS(26); + + auto tmp = (avm_main_sel_internal_call * (avm_main_internal_return_ptr - avm_main_mem_idx_b)); + tmp *= scaling_factor; + std::get<26>(evals) += tmp; + } + // Contribution 27 + { + Avm_DECLARE_VIEWS(27); + + auto tmp = (avm_main_sel_internal_call * (avm_main_pc_shift - avm_main_ia)); + tmp *= scaling_factor; + std::get<27>(evals) += tmp; + } + // Contribution 28 + { + Avm_DECLARE_VIEWS(28); + + auto tmp = (avm_main_sel_internal_call * ((avm_main_pc + FF(1)) - avm_main_ib)); + tmp *= scaling_factor; + std::get<28>(evals) += tmp; + } + // Contribution 29 + { + Avm_DECLARE_VIEWS(29); + + auto tmp = (avm_main_sel_internal_call * (avm_main_rwb - FF(1))); + tmp *= scaling_factor; + std::get<29>(evals) += tmp; + } + // Contribution 30 + { + Avm_DECLARE_VIEWS(30); + + auto tmp = (avm_main_sel_internal_call * (avm_main_mem_op_b - FF(1))); + tmp *= scaling_factor; + std::get<30>(evals) += tmp; + } + // Contribution 31 + { + Avm_DECLARE_VIEWS(31); + + auto tmp = (avm_main_sel_internal_return * + (avm_main_internal_return_ptr_shift - (avm_main_internal_return_ptr - FF(1)))); + tmp *= scaling_factor; + std::get<31>(evals) += tmp; + } + // Contribution 32 + { + Avm_DECLARE_VIEWS(32); + + auto tmp = (avm_main_sel_internal_return * ((avm_main_internal_return_ptr - FF(1)) - avm_main_mem_idx_a)); + tmp *= scaling_factor; + std::get<32>(evals) += tmp; + } + // Contribution 33 + { + Avm_DECLARE_VIEWS(33); + + auto tmp = (avm_main_sel_internal_return * (avm_main_pc_shift - avm_main_ia)); + tmp *= scaling_factor; + std::get<33>(evals) += tmp; + } + // Contribution 34 + { + Avm_DECLARE_VIEWS(34); + + auto tmp = (avm_main_sel_internal_return * avm_main_rwa); + tmp *= scaling_factor; + std::get<34>(evals) += tmp; + } + // Contribution 35 + { + Avm_DECLARE_VIEWS(35); + + auto tmp = (avm_main_sel_internal_return * (avm_main_mem_op_a - FF(1))); + tmp *= scaling_factor; + std::get<35>(evals) += tmp; + } + // Contribution 36 + { + Avm_DECLARE_VIEWS(36); + + auto tmp = ((((-avm_main_first + FF(1)) * (-avm_main_sel_halt + FF(1))) * + ((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_div) + avm_main_sel_op_mul) + + avm_main_sel_op_not)) * + (avm_main_pc_shift - (avm_main_pc + FF(1)))); + tmp *= scaling_factor; + std::get<36>(evals) += tmp; + } + // Contribution 37 + { + Avm_DECLARE_VIEWS(37); + + auto tmp = ((-(((avm_main_first + avm_main_sel_internal_call) + avm_main_sel_internal_return) + + avm_main_sel_halt) + + FF(1)) * + (avm_main_internal_return_ptr_shift - avm_main_internal_return_ptr)); + tmp *= scaling_factor; + std::get<37>(evals) += tmp; + } + } +}; + +template using avm_main = Relation>; + +} // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp similarity index 52% rename from barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp index e5ece879c11..eefca81ba77 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp @@ -4,49 +4,49 @@ #include "../../relation_types.hpp" #include "./declare_views.hpp" -namespace bb::AvmMini_vm { - -template struct Mem_traceRow { - FF memTrace_m_rw_shift{}; - FF memTrace_m_in_tag{}; - FF memTrace_m_last{}; - FF memTrace_m_val_shift{}; - FF memTrace_m_lastAccess{}; - FF memTrace_m_addr_shift{}; - FF memTrace_m_tag_err{}; - FF memTrace_m_val{}; - FF memTrace_m_tag{}; - FF memTrace_m_addr{}; - FF memTrace_m_one_min_inv{}; - FF memTrace_m_tag_shift{}; - FF memTrace_m_rw{}; +namespace bb::Avm_vm { + +template struct Avm_memRow { + FF avm_mem_m_rw_shift{}; + FF avm_mem_m_addr_shift{}; + FF avm_mem_m_addr{}; + FF avm_mem_m_val_shift{}; + FF avm_mem_m_tag{}; + FF avm_mem_m_rw{}; + FF avm_mem_m_last{}; + FF avm_mem_m_tag_err{}; + FF avm_mem_m_val{}; + FF avm_mem_m_in_tag{}; + FF avm_mem_m_one_min_inv{}; + FF avm_mem_m_lastAccess{}; + FF avm_mem_m_tag_shift{}; }; -inline std::string get_relation_label_mem_trace(int index) +inline std::string get_relation_label_avm_mem(int index) { switch (index) { + case 8: + return "MEM_IN_TAG_CONSISTENCY_1"; + case 4: return "MEM_LAST_ACCESS_DELIMITER"; - case 8: - return "MEM_IN_TAG_CONSISTENCY_1"; + case 5: + return "MEM_READ_WRITE_VAL_CONSISTENCY"; + + case 7: + return "MEM_ZERO_INIT"; case 9: return "MEM_IN_TAG_CONSISTENCY_2"; case 6: return "MEM_READ_WRITE_TAG_CONSISTENCY"; - - case 7: - return "MEM_ZERO_INIT"; - - case 5: - return "MEM_READ_WRITE_VAL_CONSISTENCY"; } return std::to_string(index); } -template class mem_traceImpl { +template class avm_memImpl { public: using FF = FF_; @@ -63,90 +63,89 @@ template class mem_traceImpl { // Contribution 0 { - AvmMini_DECLARE_VIEWS(0); + Avm_DECLARE_VIEWS(0); - auto tmp = (memTrace_m_lastAccess * (-memTrace_m_lastAccess + FF(1))); + auto tmp = (avm_mem_m_lastAccess * (-avm_mem_m_lastAccess + FF(1))); tmp *= scaling_factor; std::get<0>(evals) += tmp; } // Contribution 1 { - AvmMini_DECLARE_VIEWS(1); + Avm_DECLARE_VIEWS(1); - auto tmp = (memTrace_m_last * (-memTrace_m_last + FF(1))); + auto tmp = (avm_mem_m_last * (-avm_mem_m_last + FF(1))); tmp *= scaling_factor; std::get<1>(evals) += tmp; } // Contribution 2 { - AvmMini_DECLARE_VIEWS(2); + Avm_DECLARE_VIEWS(2); - auto tmp = (memTrace_m_rw * (-memTrace_m_rw + FF(1))); + auto tmp = (avm_mem_m_rw * (-avm_mem_m_rw + FF(1))); tmp *= scaling_factor; std::get<2>(evals) += tmp; } // Contribution 3 { - AvmMini_DECLARE_VIEWS(3); + Avm_DECLARE_VIEWS(3); - auto tmp = (memTrace_m_tag_err * (-memTrace_m_tag_err + FF(1))); + auto tmp = (avm_mem_m_tag_err * (-avm_mem_m_tag_err + FF(1))); tmp *= scaling_factor; std::get<3>(evals) += tmp; } // Contribution 4 { - AvmMini_DECLARE_VIEWS(4); + Avm_DECLARE_VIEWS(4); - auto tmp = ((-memTrace_m_lastAccess + FF(1)) * (memTrace_m_addr_shift - memTrace_m_addr)); + auto tmp = ((-avm_mem_m_lastAccess + FF(1)) * (avm_mem_m_addr_shift - avm_mem_m_addr)); tmp *= scaling_factor; std::get<4>(evals) += tmp; } // Contribution 5 { - AvmMini_DECLARE_VIEWS(5); + Avm_DECLARE_VIEWS(5); - auto tmp = (((-memTrace_m_lastAccess + FF(1)) * (-memTrace_m_rw_shift + FF(1))) * - (memTrace_m_val_shift - memTrace_m_val)); + auto tmp = (((-avm_mem_m_lastAccess + FF(1)) * (-avm_mem_m_rw_shift + FF(1))) * + (avm_mem_m_val_shift - avm_mem_m_val)); tmp *= scaling_factor; std::get<5>(evals) += tmp; } // Contribution 6 { - AvmMini_DECLARE_VIEWS(6); + Avm_DECLARE_VIEWS(6); - auto tmp = (((-memTrace_m_lastAccess + FF(1)) * (-memTrace_m_rw_shift + FF(1))) * - (memTrace_m_tag_shift - memTrace_m_tag)); + auto tmp = (((-avm_mem_m_lastAccess + FF(1)) * (-avm_mem_m_rw_shift + FF(1))) * + (avm_mem_m_tag_shift - avm_mem_m_tag)); tmp *= scaling_factor; std::get<6>(evals) += tmp; } // Contribution 7 { - AvmMini_DECLARE_VIEWS(7); + Avm_DECLARE_VIEWS(7); - auto tmp = ((memTrace_m_lastAccess * (-memTrace_m_rw_shift + FF(1))) * memTrace_m_val_shift); + auto tmp = ((avm_mem_m_lastAccess * (-avm_mem_m_rw_shift + FF(1))) * avm_mem_m_val_shift); tmp *= scaling_factor; std::get<7>(evals) += tmp; } // Contribution 8 { - AvmMini_DECLARE_VIEWS(8); + Avm_DECLARE_VIEWS(8); - auto tmp = - (((memTrace_m_in_tag - memTrace_m_tag) * (-memTrace_m_one_min_inv + FF(1))) - memTrace_m_tag_err); + auto tmp = (((avm_mem_m_in_tag - avm_mem_m_tag) * (-avm_mem_m_one_min_inv + FF(1))) - avm_mem_m_tag_err); tmp *= scaling_factor; std::get<8>(evals) += tmp; } // Contribution 9 { - AvmMini_DECLARE_VIEWS(9); + Avm_DECLARE_VIEWS(9); - auto tmp = ((-memTrace_m_tag_err + FF(1)) * memTrace_m_one_min_inv); + auto tmp = ((-avm_mem_m_tag_err + FF(1)) * avm_mem_m_one_min_inv); tmp *= scaling_factor; std::get<9>(evals) += tmp; } } }; -template using mem_trace = Relation>; +template using avm_mem = Relation>; -} // namespace bb::AvmMini_vm \ No newline at end of file +} // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp new file mode 100644 index 00000000000..d428a3c96f6 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp @@ -0,0 +1,86 @@ + +#define Avm_DECLARE_VIEWS(index) \ + using Accumulator = typename std::tuple_element::type; \ + using View = typename Accumulator::View; \ + [[maybe_unused]] auto avm_main_clk = View(new_term.avm_main_clk); \ + [[maybe_unused]] auto avm_main_first = View(new_term.avm_main_first); \ + [[maybe_unused]] auto avm_mem_m_clk = View(new_term.avm_mem_m_clk); \ + [[maybe_unused]] auto avm_mem_m_sub_clk = View(new_term.avm_mem_m_sub_clk); \ + [[maybe_unused]] auto avm_mem_m_addr = View(new_term.avm_mem_m_addr); \ + [[maybe_unused]] auto avm_mem_m_tag = View(new_term.avm_mem_m_tag); \ + [[maybe_unused]] auto avm_mem_m_val = View(new_term.avm_mem_m_val); \ + [[maybe_unused]] auto avm_mem_m_lastAccess = View(new_term.avm_mem_m_lastAccess); \ + [[maybe_unused]] auto avm_mem_m_last = View(new_term.avm_mem_m_last); \ + [[maybe_unused]] auto avm_mem_m_rw = View(new_term.avm_mem_m_rw); \ + [[maybe_unused]] auto avm_mem_m_in_tag = View(new_term.avm_mem_m_in_tag); \ + [[maybe_unused]] auto avm_mem_m_tag_err = View(new_term.avm_mem_m_tag_err); \ + [[maybe_unused]] auto avm_mem_m_one_min_inv = View(new_term.avm_mem_m_one_min_inv); \ + [[maybe_unused]] auto avm_alu_alu_clk = View(new_term.avm_alu_alu_clk); \ + [[maybe_unused]] auto avm_alu_alu_ia = View(new_term.avm_alu_alu_ia); \ + [[maybe_unused]] auto avm_alu_alu_ib = View(new_term.avm_alu_alu_ib); \ + [[maybe_unused]] auto avm_alu_alu_ic = View(new_term.avm_alu_alu_ic); \ + [[maybe_unused]] auto avm_alu_alu_op_add = View(new_term.avm_alu_alu_op_add); \ + [[maybe_unused]] auto avm_alu_alu_op_sub = View(new_term.avm_alu_alu_op_sub); \ + [[maybe_unused]] auto avm_alu_alu_op_mul = View(new_term.avm_alu_alu_op_mul); \ + [[maybe_unused]] auto avm_alu_alu_op_div = View(new_term.avm_alu_alu_op_div); \ + [[maybe_unused]] auto avm_alu_alu_op_not = View(new_term.avm_alu_alu_op_not); \ + [[maybe_unused]] auto avm_alu_alu_ff_tag = View(new_term.avm_alu_alu_ff_tag); \ + [[maybe_unused]] auto avm_alu_alu_u8_tag = View(new_term.avm_alu_alu_u8_tag); \ + [[maybe_unused]] auto avm_alu_alu_u16_tag = View(new_term.avm_alu_alu_u16_tag); \ + [[maybe_unused]] auto avm_alu_alu_u32_tag = View(new_term.avm_alu_alu_u32_tag); \ + [[maybe_unused]] auto avm_alu_alu_u64_tag = View(new_term.avm_alu_alu_u64_tag); \ + [[maybe_unused]] auto avm_alu_alu_u128_tag = View(new_term.avm_alu_alu_u128_tag); \ + [[maybe_unused]] auto avm_alu_alu_u8_r0 = View(new_term.avm_alu_alu_u8_r0); \ + [[maybe_unused]] auto avm_alu_alu_u8_r1 = View(new_term.avm_alu_alu_u8_r1); \ + [[maybe_unused]] auto avm_alu_alu_u16_r0 = View(new_term.avm_alu_alu_u16_r0); \ + [[maybe_unused]] auto avm_alu_alu_u16_r1 = View(new_term.avm_alu_alu_u16_r1); \ + [[maybe_unused]] auto avm_alu_alu_u16_r2 = View(new_term.avm_alu_alu_u16_r2); \ + [[maybe_unused]] auto avm_alu_alu_u16_r3 = View(new_term.avm_alu_alu_u16_r3); \ + [[maybe_unused]] auto avm_alu_alu_u16_r4 = View(new_term.avm_alu_alu_u16_r4); \ + [[maybe_unused]] auto avm_alu_alu_u16_r5 = View(new_term.avm_alu_alu_u16_r5); \ + [[maybe_unused]] auto avm_alu_alu_u16_r6 = View(new_term.avm_alu_alu_u16_r6); \ + [[maybe_unused]] auto avm_alu_alu_u16_r7 = View(new_term.avm_alu_alu_u16_r7); \ + [[maybe_unused]] auto avm_alu_alu_u64_r0 = View(new_term.avm_alu_alu_u64_r0); \ + [[maybe_unused]] auto avm_alu_alu_cf = View(new_term.avm_alu_alu_cf); \ + [[maybe_unused]] auto avm_main_pc = View(new_term.avm_main_pc); \ + [[maybe_unused]] auto avm_main_internal_return_ptr = View(new_term.avm_main_internal_return_ptr); \ + [[maybe_unused]] auto avm_main_sel_internal_call = View(new_term.avm_main_sel_internal_call); \ + [[maybe_unused]] auto avm_main_sel_internal_return = View(new_term.avm_main_sel_internal_return); \ + [[maybe_unused]] auto avm_main_sel_jump = View(new_term.avm_main_sel_jump); \ + [[maybe_unused]] auto avm_main_sel_halt = View(new_term.avm_main_sel_halt); \ + [[maybe_unused]] auto avm_main_sel_op_add = View(new_term.avm_main_sel_op_add); \ + [[maybe_unused]] auto avm_main_sel_op_sub = View(new_term.avm_main_sel_op_sub); \ + [[maybe_unused]] auto avm_main_sel_op_mul = View(new_term.avm_main_sel_op_mul); \ + [[maybe_unused]] auto avm_main_sel_op_div = View(new_term.avm_main_sel_op_div); \ + [[maybe_unused]] auto avm_main_sel_op_not = View(new_term.avm_main_sel_op_not); \ + [[maybe_unused]] auto avm_main_in_tag = View(new_term.avm_main_in_tag); \ + [[maybe_unused]] auto avm_main_op_err = View(new_term.avm_main_op_err); \ + [[maybe_unused]] auto avm_main_tag_err = View(new_term.avm_main_tag_err); \ + [[maybe_unused]] auto avm_main_inv = View(new_term.avm_main_inv); \ + [[maybe_unused]] auto avm_main_ia = View(new_term.avm_main_ia); \ + [[maybe_unused]] auto avm_main_ib = View(new_term.avm_main_ib); \ + [[maybe_unused]] auto avm_main_ic = View(new_term.avm_main_ic); \ + [[maybe_unused]] auto avm_main_mem_op_a = View(new_term.avm_main_mem_op_a); \ + [[maybe_unused]] auto avm_main_mem_op_b = View(new_term.avm_main_mem_op_b); \ + [[maybe_unused]] auto avm_main_mem_op_c = View(new_term.avm_main_mem_op_c); \ + [[maybe_unused]] auto avm_main_rwa = View(new_term.avm_main_rwa); \ + [[maybe_unused]] auto avm_main_rwb = View(new_term.avm_main_rwb); \ + [[maybe_unused]] auto avm_main_rwc = View(new_term.avm_main_rwc); \ + [[maybe_unused]] auto avm_main_mem_idx_a = View(new_term.avm_main_mem_idx_a); \ + [[maybe_unused]] auto avm_main_mem_idx_b = View(new_term.avm_main_mem_idx_b); \ + [[maybe_unused]] auto avm_main_mem_idx_c = View(new_term.avm_main_mem_idx_c); \ + [[maybe_unused]] auto avm_main_last = View(new_term.avm_main_last); \ + [[maybe_unused]] auto avm_main_pc_shift = View(new_term.avm_main_pc_shift); \ + [[maybe_unused]] auto avm_main_internal_return_ptr_shift = View(new_term.avm_main_internal_return_ptr_shift); \ + [[maybe_unused]] auto avm_mem_m_rw_shift = View(new_term.avm_mem_m_rw_shift); \ + [[maybe_unused]] auto avm_mem_m_addr_shift = View(new_term.avm_mem_m_addr_shift); \ + [[maybe_unused]] auto avm_mem_m_val_shift = View(new_term.avm_mem_m_val_shift); \ + [[maybe_unused]] auto avm_mem_m_tag_shift = View(new_term.avm_mem_m_tag_shift); \ + [[maybe_unused]] auto avm_alu_alu_u16_r6_shift = View(new_term.avm_alu_alu_u16_r6_shift); \ + [[maybe_unused]] auto avm_alu_alu_u16_r4_shift = View(new_term.avm_alu_alu_u16_r4_shift); \ + [[maybe_unused]] auto avm_alu_alu_u16_r1_shift = View(new_term.avm_alu_alu_u16_r1_shift); \ + [[maybe_unused]] auto avm_alu_alu_u16_r2_shift = View(new_term.avm_alu_alu_u16_r2_shift); \ + [[maybe_unused]] auto avm_alu_alu_u16_r7_shift = View(new_term.avm_alu_alu_u16_r7_shift); \ + [[maybe_unused]] auto avm_alu_alu_u16_r0_shift = View(new_term.avm_alu_alu_u16_r0_shift); \ + [[maybe_unused]] auto avm_alu_alu_u16_r3_shift = View(new_term.avm_alu_alu_u16_r3_shift); \ + [[maybe_unused]] auto avm_alu_alu_u16_r5_shift = View(new_term.avm_alu_alu_u16_r5_shift); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp deleted file mode 100644 index 2e084f6f3b8..00000000000 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "AvmMini_helper.hpp" - -namespace avm_trace { - -/** - * @brief Routine to log some slice of a trace of the AVM. Used to debug or in some unit tests. - * - * @param trace The whole trace for AVM as a vector of rows. - * @param beg The index of the beginning of the slice. (included) - * @param end The index of the end of the slice (not included). - */ -void log_avmMini_trace(std::vector const& trace, size_t beg, size_t end) -{ - info("Built circuit with ", trace.size(), " rows"); - - for (size_t i = beg; i < end; i++) { - info("====================================================================================="); - info("== ROW ", i); - info("====================================================================================="); - - info("=======MEMORY TRACE=================================================================="); - info("m_addr: ", trace.at(i).memTrace_m_addr); - info("m_clk: ", trace.at(i).memTrace_m_clk); - info("m_sub_clk: ", trace.at(i).memTrace_m_sub_clk); - info("m_val: ", trace.at(i).memTrace_m_val); - info("m_rw: ", trace.at(i).memTrace_m_rw); - info("m_tag: ", trace.at(i).memTrace_m_tag); - info("m_in_tag: ", trace.at(i).memTrace_m_in_tag); - info("m_tag_err: ", trace.at(i).memTrace_m_tag_err); - info("m_one_min_inv: ", trace.at(i).memTrace_m_one_min_inv); - - info("m_lastAccess: ", trace.at(i).memTrace_m_lastAccess); - info("m_last: ", trace.at(i).memTrace_m_last); - info("m_val_shift: ", trace.at(i).memTrace_m_val_shift); - - info("=======CONTROL_FLOW==================================================================="); - info("pc: ", trace.at(i).avmMini_pc); - info("internal_call: ", trace.at(i).avmMini_sel_internal_call); - info("internal_return: ", trace.at(i).avmMini_sel_internal_return); - info("internal_return_ptr:", trace.at(i).avmMini_internal_return_ptr); - - info("=======ALU TRACE====================================================================="); - info("alu_clk ", trace.at(i).aluChip_alu_clk); - info("alu_ia ", trace.at(i).aluChip_alu_ia); - info("alu_ib ", trace.at(i).aluChip_alu_ib); - info("alu_ic ", trace.at(i).aluChip_alu_ic); - - info("=======MAIN TRACE===================================================================="); - info("ia: ", trace.at(i).avmMini_ia); - info("ib: ", trace.at(i).avmMini_ib); - info("ic: ", trace.at(i).avmMini_ic); - info("first: ", trace.at(i).avmMini_first); - info("last: ", trace.at(i).avmMini_last); - - info("=======MEM_OP_A======================================================================"); - info("clk: ", trace.at(i).avmMini_clk); - info("mem_op_a: ", trace.at(i).avmMini_mem_op_a); - info("mem_idx_a: ", trace.at(i).avmMini_mem_idx_a); - info("rwa: ", trace.at(i).avmMini_rwa); - - info("=======MEM_OP_B======================================================================"); - info("mem_op_b: ", trace.at(i).avmMini_mem_op_b); - info("mem_idx_b: ", trace.at(i).avmMini_mem_idx_b); - info("rwb: ", trace.at(i).avmMini_rwb); - - info("=======MEM_OP_C======================================================================"); - info("mem_op_c: ", trace.at(i).avmMini_mem_op_c); - info("mem_idx_c: ", trace.at(i).avmMini_mem_idx_c); - info("rwc: ", trace.at(i).avmMini_rwc); - info("\n"); - } -} - -} // namespace avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.hpp deleted file mode 100644 index eda2b5c89a6..00000000000 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "AvmMini_common.hpp" - -namespace avm_trace { - -void log_avmMini_trace(std::vector const& trace, size_t beg, size_t end); - -} // namespace avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp similarity index 91% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp index ca8fae2cda1..a3ccf09b886 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp @@ -1,4 +1,4 @@ -#include "AvmMini_alu_trace.hpp" +#include "avm_alu_trace.hpp" namespace avm_trace { @@ -6,7 +6,7 @@ namespace avm_trace { * @brief Constructor of Alu trace builder of AVM. Only serves to set the capacity of the * underlying trace. */ -AvmMiniAluTraceBuilder::AvmMiniAluTraceBuilder() +AvmAluTraceBuilder::AvmAluTraceBuilder() { alu_trace.reserve(AVM_TRACE_SIZE); } @@ -15,7 +15,7 @@ AvmMiniAluTraceBuilder::AvmMiniAluTraceBuilder() * @brief Resetting the internal state so that a new Alu trace can be rebuilt using the same object. * */ -void AvmMiniAluTraceBuilder::reset() +void AvmAluTraceBuilder::reset() { alu_trace.clear(); } @@ -25,7 +25,7 @@ void AvmMiniAluTraceBuilder::reset() * * @return The Alu trace (which is moved). */ -std::vector AvmMiniAluTraceBuilder::finalize() +std::vector AvmAluTraceBuilder::finalize() { return std::move(alu_trace); } @@ -45,7 +45,7 @@ std::vector AvmMiniAluTraceBuilder::final * * @return FF The result of the addition casted in a finite field element */ -FF AvmMiniAluTraceBuilder::op_add(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t const clk) +FF AvmAluTraceBuilder::op_add(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t const clk) { FF c = 0; bool carry = false; @@ -98,7 +98,7 @@ FF AvmMiniAluTraceBuilder::op_add(FF const& a, FF const& b, AvmMemoryTag in_tag, } } - alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ + alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, .alu_op_add = true, .alu_ff_tag = in_tag == AvmMemoryTag::FF, @@ -134,7 +134,7 @@ FF AvmMiniAluTraceBuilder::op_add(FF const& a, FF const& b, AvmMemoryTag in_tag, * * @return FF The result of the subtraction casted in a finite field element */ -FF AvmMiniAluTraceBuilder::op_sub(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t const clk) +FF AvmAluTraceBuilder::op_sub(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t const clk) { FF c = 0; bool carry = false; @@ -186,7 +186,7 @@ FF AvmMiniAluTraceBuilder::op_sub(FF const& a, FF const& b, AvmMemoryTag in_tag, } } - alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ + alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, .alu_op_sub = true, .alu_ff_tag = in_tag == AvmMemoryTag::FF, @@ -218,7 +218,7 @@ FF AvmMiniAluTraceBuilder::op_sub(FF const& a, FF const& b, AvmMemoryTag in_tag, * * @return FF The result of the multiplication casted in a finite field element */ -FF AvmMiniAluTraceBuilder::op_mul(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t const clk) +FF AvmAluTraceBuilder::op_mul(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t const clk) { FF c = 0; bool carry = false; @@ -274,7 +274,7 @@ FF AvmMiniAluTraceBuilder::op_mul(FF const& a, FF const& b, AvmMemoryTag in_tag, // c_high := 2^128 * a_h * b_h uint256_t c_high = ((a_u256 >> 64) * (b_u256 >> 64)) << 128; - // From PIL relation in alu_chip.pil, we need to determine the bit CF and 64-bit value R' in + // From PIL relation in avm_alu.pil, we need to determine the bit CF and 64-bit value R' in // a * b_l + a_l * b_h * 2^64 = (CF * 2^64 + R') * 2^128 + c // LHS is c_u256 - c_high @@ -285,7 +285,7 @@ FF AvmMiniAluTraceBuilder::op_mul(FF const& a, FF const& b, AvmMemoryTag in_tag, c = FF{ uint256_t::from_uint128(c_u128) }; - alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ + alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, .alu_op_mul = true, .alu_u128_tag = in_tag == AvmMemoryTag::U128, @@ -297,7 +297,7 @@ FF AvmMiniAluTraceBuilder::op_mul(FF const& a, FF const& b, AvmMemoryTag in_tag, .alu_u64_r0 = alu_u64_r0, }); - alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ + alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_u16_reg = alu_u16_reg_b, }); @@ -324,7 +324,7 @@ FF AvmMiniAluTraceBuilder::op_mul(FF const& a, FF const& b, AvmMemoryTag in_tag, } // Following code executed for: ff, u8, u16, u32, u64 (u128 returned handled specifically) - alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ + alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, .alu_op_mul = true, .alu_ff_tag = in_tag == AvmMemoryTag::FF, @@ -353,7 +353,7 @@ FF AvmMiniAluTraceBuilder::op_mul(FF const& a, FF const& b, AvmMemoryTag in_tag, * * @return FF The result of the not casted in a finite field element */ -FF AvmMiniAluTraceBuilder::op_not(FF const& a, AvmMemoryTag in_tag, uint32_t const clk) +FF AvmAluTraceBuilder::op_not(FF const& a, AvmMemoryTag in_tag, uint32_t const clk) { FF c = 0; uint128_t a_u128{ a }; @@ -380,7 +380,7 @@ FF AvmMiniAluTraceBuilder::op_not(FF const& a, AvmMemoryTag in_tag, uint32_t con return FF{ 0 }; } - alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ + alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, .alu_op_not = true, .alu_u8_tag = in_tag == AvmMemoryTag::U8, diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp similarity index 92% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp index d567bf8ab1d..cde22e2b14b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp @@ -1,10 +1,10 @@ #pragma once -#include "AvmMini_common.hpp" +#include "avm_common.hpp" namespace avm_trace { -class AvmMiniAluTraceBuilder { +class AvmAluTraceBuilder { public: struct AluTraceEntry { @@ -36,7 +36,7 @@ class AvmMiniAluTraceBuilder { uint64_t alu_u64_r0{}; }; - AvmMiniAluTraceBuilder(); + AvmAluTraceBuilder(); void reset(); std::vector finalize(); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_common.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp similarity index 75% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_common.hpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp index c0ddae1a869..8f163717ee2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_common.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp @@ -1,14 +1,14 @@ #pragma once #include "barretenberg/proof_system/circuit_builder/circuit_builder_base.hpp" -#include "barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp" +#include "barretenberg/proof_system/circuit_builder/generated/avm_circuit_builder.hpp" #include namespace avm_trace { -using Flavor = bb::AvmMiniFlavor; +using Flavor = bb::AvmFlavor; using FF = Flavor::FF; -using Row = bb::AvmMiniFullRow; +using Row = bb::AvmFullRow; // Number of rows static const size_t AVM_TRACE_SIZE = 256; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_deserialization.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp similarity index 97% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_deserialization.cpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp index 5c5d60118bb..7a3fe0198ff 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_deserialization.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp @@ -1,7 +1,7 @@ -#include "AvmMini_deserialization.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_common.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_instructions.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_opcode.hpp" +#include "avm_deserialization.hpp" +#include "barretenberg/vm/avm_trace/avm_common.hpp" +#include "barretenberg/vm/avm_trace/avm_instructions.hpp" +#include "barretenberg/vm/avm_trace/avm_opcode.hpp" #include #include #include diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_deserialization.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.hpp similarity index 79% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_deserialization.hpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.hpp index 91a52eaf41b..97853629c72 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_deserialization.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.hpp @@ -1,9 +1,9 @@ #pragma once #include "barretenberg/numeric/uint128/uint128.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_common.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_instructions.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_opcode.hpp" +#include "barretenberg/vm/avm_trace/avm_common.hpp" +#include "barretenberg/vm/avm_trace/avm_instructions.hpp" +#include "barretenberg/vm/avm_trace/avm_opcode.hpp" #include #include #include diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp similarity index 90% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.cpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp index 1bf1056301a..70963e630cc 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp @@ -1,12 +1,12 @@ -#include "AvmMini_execution.hpp" +#include "avm_execution.hpp" #include "barretenberg/common/serialize.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_deserialization.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_instructions.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_opcode.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_trace.hpp" -#include "barretenberg/vm/generated/AvmMini_composer.hpp" +#include "barretenberg/proof_system/circuit_builder/generated/avm_circuit_builder.hpp" +#include "barretenberg/vm/avm_trace/avm_common.hpp" +#include "barretenberg/vm/avm_trace/avm_deserialization.hpp" +#include "barretenberg/vm/avm_trace/avm_instructions.hpp" +#include "barretenberg/vm/avm_trace/avm_opcode.hpp" +#include "barretenberg/vm/avm_trace/avm_trace.hpp" +#include "barretenberg/vm/generated/avm_composer.hpp" #include #include #include @@ -30,10 +30,10 @@ HonkProof Execution::run_and_prove(std::vector const& bytecode, std::ve { auto instructions = Deserialization::parse(bytecode); auto trace = gen_trace(instructions, calldata); - auto circuit_builder = bb::AvmMiniCircuitBuilder(); + auto circuit_builder = bb::AvmCircuitBuilder(); circuit_builder.set_trace(std::move(trace)); - auto composer = AvmMiniComposer(); + auto composer = AvmComposer(); auto prover = composer.create_prover(circuit_builder); return prover.construct_proof(); } @@ -47,7 +47,7 @@ HonkProof Execution::run_and_prove(std::vector const& bytecode, std::ve */ std::vector Execution::gen_trace(std::vector const& instructions, std::vector const& calldata) { - AvmMiniTraceBuilder trace_builder; + AvmTraceBuilder trace_builder; // Copied version of pc maintained in trace builder. The value of pc is evolving based // on opcode logic and therefore is not maintained here. However, the next opcode in the execution diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp similarity index 74% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.hpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp index 40c75d186e2..9450bad4bbe 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_execution.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp @@ -1,9 +1,9 @@ #pragma once #include "barretenberg/honk/proof_system/types/proof.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_common.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_instructions.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_trace.hpp" +#include "barretenberg/vm/avm_trace/avm_common.hpp" +#include "barretenberg/vm/avm_trace/avm_instructions.hpp" +#include "barretenberg/vm/avm_trace/avm_trace.hpp" #include #include #include diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.cpp new file mode 100644 index 00000000000..2129c0a3e77 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.cpp @@ -0,0 +1,74 @@ +#include "avm_helper.hpp" + +namespace avm_trace { + +/** + * @brief Routine to log some slice of a trace of the AVM. Used to debug or in some unit tests. + * + * @param trace The whole trace for AVM as a vector of rows. + * @param beg The index of the beginning of the slice. (included) + * @param end The index of the end of the slice (not included). + */ +void log_avm_trace(std::vector const& trace, size_t beg, size_t end) +{ + info("Built circuit with ", trace.size(), " rows"); + + for (size_t i = beg; i < end; i++) { + info("====================================================================================="); + info("== ROW ", i); + info("====================================================================================="); + + info("=======MEMORY TRACE=================================================================="); + info("m_addr: ", trace.at(i).avm_mem_m_addr); + info("m_clk: ", trace.at(i).avm_mem_m_clk); + info("m_sub_clk: ", trace.at(i).avm_mem_m_sub_clk); + info("m_val: ", trace.at(i).avm_mem_m_val); + info("m_rw: ", trace.at(i).avm_mem_m_rw); + info("m_tag: ", trace.at(i).avm_mem_m_tag); + info("m_in_tag: ", trace.at(i).avm_mem_m_in_tag); + info("m_tag_err: ", trace.at(i).avm_mem_m_tag_err); + info("m_one_min_inv: ", trace.at(i).avm_mem_m_one_min_inv); + + info("m_lastAccess: ", trace.at(i).avm_mem_m_lastAccess); + info("m_last: ", trace.at(i).avm_mem_m_last); + info("m_val_shift: ", trace.at(i).avm_mem_m_val_shift); + + info("=======CONTROL_FLOW==================================================================="); + info("pc: ", trace.at(i).avm_main_pc); + info("internal_call: ", trace.at(i).avm_main_sel_internal_call); + info("internal_return: ", trace.at(i).avm_main_sel_internal_return); + info("internal_return_ptr:", trace.at(i).avm_main_internal_return_ptr); + + info("=======ALU TRACE====================================================================="); + info("alu_clk ", trace.at(i).avm_alu_alu_clk); + info("alu_ia ", trace.at(i).avm_alu_alu_ia); + info("alu_ib ", trace.at(i).avm_alu_alu_ib); + info("alu_ic ", trace.at(i).avm_alu_alu_ic); + + info("=======MAIN TRACE===================================================================="); + info("ia: ", trace.at(i).avm_main_ia); + info("ib: ", trace.at(i).avm_main_ib); + info("ic: ", trace.at(i).avm_main_ic); + info("first: ", trace.at(i).avm_main_first); + info("last: ", trace.at(i).avm_main_last); + + info("=======MEM_OP_A======================================================================"); + info("clk: ", trace.at(i).avm_main_clk); + info("mem_op_a: ", trace.at(i).avm_main_mem_op_a); + info("mem_idx_a: ", trace.at(i).avm_main_mem_idx_a); + info("rwa: ", trace.at(i).avm_main_rwa); + + info("=======MEM_OP_B======================================================================"); + info("mem_op_b: ", trace.at(i).avm_main_mem_op_b); + info("mem_idx_b: ", trace.at(i).avm_main_mem_idx_b); + info("rwb: ", trace.at(i).avm_main_rwb); + + info("=======MEM_OP_C======================================================================"); + info("mem_op_c: ", trace.at(i).avm_main_mem_op_c); + info("mem_idx_c: ", trace.at(i).avm_main_mem_idx_c); + info("rwc: ", trace.at(i).avm_main_rwc); + info("\n"); + } +} + +} // namespace avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.hpp new file mode 100644 index 00000000000..db262658bf6 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include "avm_common.hpp" + +namespace avm_trace { + +void log_avm_trace(std::vector const& trace, size_t beg, size_t end); + +} // namespace avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_instructions.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_instructions.hpp similarity index 81% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_instructions.hpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_instructions.hpp index 497961685ea..01cfdd4b80f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_instructions.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_instructions.hpp @@ -1,8 +1,8 @@ #pragma once #include "barretenberg/numeric/uint128/uint128.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_common.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_opcode.hpp" +#include "barretenberg/vm/avm_trace/avm_common.hpp" +#include "barretenberg/vm/avm_trace/avm_opcode.hpp" #include #include diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp similarity index 79% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp index 557244116b1..0d9f8495983 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp @@ -1,4 +1,4 @@ -#include "AvmMini_mem_trace.hpp" +#include "avm_mem_trace.hpp" namespace avm_trace { @@ -6,7 +6,7 @@ namespace avm_trace { * @brief Constructor of a memory trace builder of AVM. Only serves to set the capacity of the * underlying traces. */ -AvmMiniMemTraceBuilder::AvmMiniMemTraceBuilder() +AvmMemTraceBuilder::AvmMemTraceBuilder() { mem_trace.reserve(AVM_TRACE_SIZE); } @@ -15,7 +15,7 @@ AvmMiniMemTraceBuilder::AvmMiniMemTraceBuilder() * @brief Resetting the internal state so that a new memory trace can be rebuilt using the same object. * */ -void AvmMiniMemTraceBuilder::reset() +void AvmMemTraceBuilder::reset() { mem_trace.clear(); memory.fill(FF(0)); @@ -26,9 +26,9 @@ void AvmMiniMemTraceBuilder::reset() * * @return The memory trace (which is moved). */ -std::vector AvmMiniMemTraceBuilder::finalize() +std::vector AvmMemTraceBuilder::finalize() { - // Sort memTrace + // Sort avm_mem std::sort(mem_trace.begin(), mem_trace.end()); return std::move(mem_trace); } @@ -43,12 +43,12 @@ std::vector AvmMiniMemTraceBuilder::fi * @param m_in_tag Memory tag pertaining to the instruction * @param m_rw Boolean telling whether it is a load (false) or store operation (true). */ -void AvmMiniMemTraceBuilder::insert_in_mem_trace(uint32_t const m_clk, - uint32_t const m_sub_clk, - uint32_t const m_addr, - FF const& m_val, - AvmMemoryTag const m_in_tag, - bool const m_rw) +void AvmMemTraceBuilder::insert_in_mem_trace(uint32_t const m_clk, + uint32_t const m_sub_clk, + uint32_t const m_addr, + FF const& m_val, + AvmMemoryTag const m_in_tag, + bool const m_rw) { mem_trace.emplace_back(MemoryTraceEntry{ .m_clk = m_clk, @@ -76,12 +76,12 @@ void AvmMiniMemTraceBuilder::insert_in_mem_trace(uint32_t const m_clk, * @param m_in_tag Memory tag pertaining to the instruction * @param m_tag Memory tag pertaining to the address */ -void AvmMiniMemTraceBuilder::load_mismatch_tag_in_mem_trace(uint32_t const m_clk, - uint32_t const m_sub_clk, - uint32_t const m_addr, - FF const& m_val, - AvmMemoryTag const m_in_tag, - AvmMemoryTag const m_tag) +void AvmMemTraceBuilder::load_mismatch_tag_in_mem_trace(uint32_t const m_clk, + uint32_t const m_sub_clk, + uint32_t const m_addr, + FF const& m_val, + AvmMemoryTag const m_in_tag, + AvmMemoryTag const m_tag) { FF one_min_inv = FF(1) - (FF(static_cast(m_in_tag)) - FF(static_cast(m_tag))).invert(); mem_trace.emplace_back(MemoryTraceEntry{ .m_clk = m_clk, @@ -107,7 +107,7 @@ void AvmMiniMemTraceBuilder::load_mismatch_tag_in_mem_trace(uint32_t const m_clk * @return A boolean indicating that memory tag matches (resp. does not match) the * instruction tag. Set to false in case of a mismatch. */ -bool AvmMiniMemTraceBuilder::load_in_mem_trace( +bool AvmMemTraceBuilder::load_in_mem_trace( uint32_t clk, IntermRegister interm_reg, uint32_t addr, FF const& val, AvmMemoryTag m_in_tag) { uint32_t sub_clk = 0; @@ -144,7 +144,7 @@ bool AvmMiniMemTraceBuilder::load_in_mem_trace( * @param val The value to be stored * @param m_in_tag The memory tag of the instruction */ -void AvmMiniMemTraceBuilder::store_in_mem_trace( +void AvmMemTraceBuilder::store_in_mem_trace( uint32_t clk, IntermRegister interm_reg, uint32_t addr, FF const& val, AvmMemoryTag m_in_tag) { uint32_t sub_clk = 0; @@ -176,10 +176,10 @@ void AvmMiniMemTraceBuilder::store_in_mem_trace( * @return Result of the read operation containing the value and a boolean telling * potential mismatch between instruction tag and memory tag of the address. */ -AvmMiniMemTraceBuilder::MemRead AvmMiniMemTraceBuilder::read_and_load_from_memory(uint32_t const clk, - IntermRegister const interm_reg, - uint32_t const addr, - AvmMemoryTag const m_in_tag) +AvmMemTraceBuilder::MemRead AvmMemTraceBuilder::read_and_load_from_memory(uint32_t const clk, + IntermRegister const interm_reg, + uint32_t const addr, + AvmMemoryTag const m_in_tag) { FF val = memory.at(addr); bool tagMatch = load_in_mem_trace(clk, interm_reg, addr, val, m_in_tag); @@ -201,7 +201,7 @@ AvmMiniMemTraceBuilder::MemRead AvmMiniMemTraceBuilder::read_and_load_from_memor * @param val Value to be written into memory * @param m_in_tag Memory instruction tag */ -void AvmMiniMemTraceBuilder::write_into_memory( +void AvmMemTraceBuilder::write_into_memory( uint32_t const clk, IntermRegister interm_reg, uint32_t addr, FF const& val, AvmMemoryTag m_in_tag) { memory.at(addr) = val; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.hpp similarity index 97% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.hpp index 0cf1bcaca48..404c0ce7dc3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.hpp @@ -1,10 +1,10 @@ #pragma once -#include "AvmMini_common.hpp" +#include "avm_common.hpp" namespace avm_trace { -class AvmMiniMemTraceBuilder { +class AvmMemTraceBuilder { public: static const size_t MEM_SIZE = 1024; @@ -60,7 +60,7 @@ class AvmMiniMemTraceBuilder { FF val{}; }; - AvmMiniMemTraceBuilder(); + AvmMemTraceBuilder(); void reset(); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_opcode.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.cpp similarity index 99% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_opcode.cpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.cpp index d7225e38dca..dbf9a76a741 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_opcode.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.cpp @@ -1,4 +1,4 @@ -#include "AvmMini_opcode.hpp" +#include "avm_opcode.hpp" #include #include diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_opcode.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.hpp similarity index 100% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_opcode.hpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.hpp diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp similarity index 65% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp index 944183a8826..53e73e53ee9 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp @@ -8,7 +8,7 @@ #include #include -#include "AvmMini_trace.hpp" +#include "avm_trace.hpp" namespace avm_trace { @@ -16,7 +16,7 @@ namespace avm_trace { * @brief Constructor of a trace builder of AVM. Only serves to set the capacity of the * underlying traces. */ -AvmMiniTraceBuilder::AvmMiniTraceBuilder() +AvmTraceBuilder::AvmTraceBuilder() { main_trace.reserve(AVM_TRACE_SIZE); } @@ -25,7 +25,7 @@ AvmMiniTraceBuilder::AvmMiniTraceBuilder() * @brief Resetting the internal state so that a new trace can be rebuilt using the same object. * */ -void AvmMiniTraceBuilder::reset() +void AvmTraceBuilder::reset() { main_trace.clear(); mem_trace_builder.reset(); @@ -40,7 +40,7 @@ void AvmMiniTraceBuilder::reset() * @param dst_offset An index in memory pointing to the output of the addition. * @param in_tag The instruction memory tag of the operands. */ -void AvmMiniTraceBuilder::op_add(uint32_t a_offset, uint32_t b_offset, uint32_t dst_offset, AvmMemoryTag in_tag) +void AvmTraceBuilder::op_add(uint32_t a_offset, uint32_t b_offset, uint32_t dst_offset, AvmMemoryTag in_tag) { auto clk = static_cast(main_trace.size()); @@ -58,22 +58,22 @@ void AvmMiniTraceBuilder::op_add(uint32_t a_offset, uint32_t b_offset, uint32_t mem_trace_builder.write_into_memory(clk, IntermRegister::IC, dst_offset, c, in_tag); main_trace.push_back(Row{ - .avmMini_clk = clk, - .avmMini_pc = FF(pc++), - .avmMini_internal_return_ptr = FF(internal_return_ptr), - .avmMini_sel_op_add = FF(1), - .avmMini_in_tag = FF(static_cast(in_tag)), - .avmMini_tag_err = FF(static_cast(!tag_match)), - .avmMini_ia = a, - .avmMini_ib = b, - .avmMini_ic = c, - .avmMini_mem_op_a = FF(1), - .avmMini_mem_op_b = FF(1), - .avmMini_mem_op_c = FF(1), - .avmMini_rwc = FF(1), - .avmMini_mem_idx_a = FF(a_offset), - .avmMini_mem_idx_b = FF(b_offset), - .avmMini_mem_idx_c = FF(dst_offset), + .avm_main_clk = clk, + .avm_main_pc = FF(pc++), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_sel_op_add = FF(1), + .avm_main_in_tag = FF(static_cast(in_tag)), + .avm_main_tag_err = FF(static_cast(!tag_match)), + .avm_main_ia = a, + .avm_main_ib = b, + .avm_main_ic = c, + .avm_main_mem_op_a = FF(1), + .avm_main_mem_op_b = FF(1), + .avm_main_mem_op_c = FF(1), + .avm_main_rwc = FF(1), + .avm_main_mem_idx_a = FF(a_offset), + .avm_main_mem_idx_b = FF(b_offset), + .avm_main_mem_idx_c = FF(dst_offset), }); }; @@ -85,7 +85,7 @@ void AvmMiniTraceBuilder::op_add(uint32_t a_offset, uint32_t b_offset, uint32_t * @param dst_offset An index in memory pointing to the output of the subtraction. * @param in_tag The instruction memory tag of the operands. */ -void AvmMiniTraceBuilder::op_sub(uint32_t a_offset, uint32_t b_offset, uint32_t dst_offset, AvmMemoryTag in_tag) +void AvmTraceBuilder::op_sub(uint32_t a_offset, uint32_t b_offset, uint32_t dst_offset, AvmMemoryTag in_tag) { auto clk = static_cast(main_trace.size()); @@ -103,22 +103,22 @@ void AvmMiniTraceBuilder::op_sub(uint32_t a_offset, uint32_t b_offset, uint32_t mem_trace_builder.write_into_memory(clk, IntermRegister::IC, dst_offset, c, in_tag); main_trace.push_back(Row{ - .avmMini_clk = clk, - .avmMini_pc = FF(pc++), - .avmMini_internal_return_ptr = FF(internal_return_ptr), - .avmMini_sel_op_sub = FF(1), - .avmMini_in_tag = FF(static_cast(in_tag)), - .avmMini_tag_err = FF(static_cast(!tag_match)), - .avmMini_ia = a, - .avmMini_ib = b, - .avmMini_ic = c, - .avmMini_mem_op_a = FF(1), - .avmMini_mem_op_b = FF(1), - .avmMini_mem_op_c = FF(1), - .avmMini_rwc = FF(1), - .avmMini_mem_idx_a = FF(a_offset), - .avmMini_mem_idx_b = FF(b_offset), - .avmMini_mem_idx_c = FF(dst_offset), + .avm_main_clk = clk, + .avm_main_pc = FF(pc++), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_sel_op_sub = FF(1), + .avm_main_in_tag = FF(static_cast(in_tag)), + .avm_main_tag_err = FF(static_cast(!tag_match)), + .avm_main_ia = a, + .avm_main_ib = b, + .avm_main_ic = c, + .avm_main_mem_op_a = FF(1), + .avm_main_mem_op_b = FF(1), + .avm_main_mem_op_c = FF(1), + .avm_main_rwc = FF(1), + .avm_main_mem_idx_a = FF(a_offset), + .avm_main_mem_idx_b = FF(b_offset), + .avm_main_mem_idx_c = FF(dst_offset), }); }; @@ -130,7 +130,7 @@ void AvmMiniTraceBuilder::op_sub(uint32_t a_offset, uint32_t b_offset, uint32_t * @param dst_offset An index in memory pointing to the output of the multiplication. * @param in_tag The instruction memory tag of the operands. */ -void AvmMiniTraceBuilder::op_mul(uint32_t a_offset, uint32_t b_offset, uint32_t dst_offset, AvmMemoryTag in_tag) +void AvmTraceBuilder::op_mul(uint32_t a_offset, uint32_t b_offset, uint32_t dst_offset, AvmMemoryTag in_tag) { auto clk = static_cast(main_trace.size()); @@ -148,22 +148,22 @@ void AvmMiniTraceBuilder::op_mul(uint32_t a_offset, uint32_t b_offset, uint32_t mem_trace_builder.write_into_memory(clk, IntermRegister::IC, dst_offset, c, in_tag); main_trace.push_back(Row{ - .avmMini_clk = clk, - .avmMini_pc = FF(pc++), - .avmMini_internal_return_ptr = FF(internal_return_ptr), - .avmMini_sel_op_mul = FF(1), - .avmMini_in_tag = FF(static_cast(in_tag)), - .avmMini_tag_err = FF(static_cast(!tag_match)), - .avmMini_ia = a, - .avmMini_ib = b, - .avmMini_ic = c, - .avmMini_mem_op_a = FF(1), - .avmMini_mem_op_b = FF(1), - .avmMini_mem_op_c = FF(1), - .avmMini_rwc = FF(1), - .avmMini_mem_idx_a = FF(a_offset), - .avmMini_mem_idx_b = FF(b_offset), - .avmMini_mem_idx_c = FF(dst_offset), + .avm_main_clk = clk, + .avm_main_pc = FF(pc++), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_sel_op_mul = FF(1), + .avm_main_in_tag = FF(static_cast(in_tag)), + .avm_main_tag_err = FF(static_cast(!tag_match)), + .avm_main_ia = a, + .avm_main_ib = b, + .avm_main_ic = c, + .avm_main_mem_op_a = FF(1), + .avm_main_mem_op_b = FF(1), + .avm_main_mem_op_c = FF(1), + .avm_main_rwc = FF(1), + .avm_main_mem_idx_a = FF(a_offset), + .avm_main_mem_idx_b = FF(b_offset), + .avm_main_mem_idx_c = FF(dst_offset), }); } @@ -175,7 +175,7 @@ void AvmMiniTraceBuilder::op_mul(uint32_t a_offset, uint32_t b_offset, uint32_t * @param dst_offset An index in memory pointing to the output of the division. * @param in_tag The instruction memory tag of the operands. */ -void AvmMiniTraceBuilder::op_div(uint32_t a_offset, uint32_t b_offset, uint32_t dst_offset, AvmMemoryTag in_tag) +void AvmTraceBuilder::op_div(uint32_t a_offset, uint32_t b_offset, uint32_t dst_offset, AvmMemoryTag in_tag) { auto clk = static_cast(main_trace.size()); @@ -206,24 +206,24 @@ void AvmMiniTraceBuilder::op_div(uint32_t a_offset, uint32_t b_offset, uint32_t mem_trace_builder.write_into_memory(clk, IntermRegister::IC, dst_offset, c, in_tag); main_trace.push_back(Row{ - .avmMini_clk = clk, - .avmMini_pc = FF(pc++), - .avmMini_internal_return_ptr = FF(internal_return_ptr), - .avmMini_sel_op_div = FF(1), - .avmMini_in_tag = FF(static_cast(in_tag)), - .avmMini_op_err = tag_match ? error : FF(1), - .avmMini_tag_err = FF(static_cast(!tag_match)), - .avmMini_inv = tag_match ? inv : FF(1), - .avmMini_ia = tag_match ? a : FF(0), - .avmMini_ib = tag_match ? b : FF(0), - .avmMini_ic = tag_match ? c : FF(0), - .avmMini_mem_op_a = FF(1), - .avmMini_mem_op_b = FF(1), - .avmMini_mem_op_c = FF(1), - .avmMini_rwc = FF(1), - .avmMini_mem_idx_a = FF(a_offset), - .avmMini_mem_idx_b = FF(b_offset), - .avmMini_mem_idx_c = FF(dst_offset), + .avm_main_clk = clk, + .avm_main_pc = FF(pc++), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_sel_op_div = FF(1), + .avm_main_in_tag = FF(static_cast(in_tag)), + .avm_main_op_err = tag_match ? error : FF(1), + .avm_main_tag_err = FF(static_cast(!tag_match)), + .avm_main_inv = tag_match ? inv : FF(1), + .avm_main_ia = tag_match ? a : FF(0), + .avm_main_ib = tag_match ? b : FF(0), + .avm_main_ic = tag_match ? c : FF(0), + .avm_main_mem_op_a = FF(1), + .avm_main_mem_op_b = FF(1), + .avm_main_mem_op_c = FF(1), + .avm_main_rwc = FF(1), + .avm_main_mem_idx_a = FF(a_offset), + .avm_main_mem_idx_b = FF(b_offset), + .avm_main_mem_idx_c = FF(dst_offset), }); } @@ -240,7 +240,7 @@ void AvmMiniTraceBuilder::op_div(uint32_t a_offset, uint32_t b_offset, uint32_t * @param dst_offset Memory destination offset where val is written to * @param in_tag The instruction memory tag */ -void AvmMiniTraceBuilder::set(uint128_t val, uint32_t dst_offset, AvmMemoryTag in_tag) +void AvmTraceBuilder::set(uint128_t val, uint32_t dst_offset, AvmMemoryTag in_tag) { auto clk = static_cast(main_trace.size()); auto val_ff = FF{ uint256_t::from_uint128(val) }; @@ -248,14 +248,14 @@ void AvmMiniTraceBuilder::set(uint128_t val, uint32_t dst_offset, AvmMemoryTag i mem_trace_builder.write_into_memory(clk, IntermRegister::IC, dst_offset, val_ff, in_tag); main_trace.push_back(Row{ - .avmMini_clk = clk, - .avmMini_pc = FF(pc++), - .avmMini_internal_return_ptr = FF(internal_return_ptr), - .avmMini_in_tag = FF(static_cast(in_tag)), - .avmMini_ic = val_ff, - .avmMini_mem_op_c = FF(1), - .avmMini_rwc = FF(1), - .avmMini_mem_idx_c = FF(dst_offset), + .avm_main_clk = clk, + .avm_main_pc = FF(pc++), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_in_tag = FF(static_cast(in_tag)), + .avm_main_ic = val_ff, + .avm_main_mem_op_c = FF(1), + .avm_main_rwc = FF(1), + .avm_main_mem_idx_c = FF(dst_offset), }); } @@ -279,10 +279,10 @@ void AvmMiniTraceBuilder::set(uint128_t val, uint32_t dst_offset, AvmMemoryTag i * @param dst_offset The starting index of memory where calldata will be copied to. * @param call_data_mem The vector containing calldata. */ -void AvmMiniTraceBuilder::calldata_copy(uint32_t cd_offset, - uint32_t copy_size, - uint32_t dst_offset, - std::vector const& call_data_mem) +void AvmTraceBuilder::calldata_copy(uint32_t cd_offset, + uint32_t copy_size, + uint32_t dst_offset, + std::vector const& call_data_mem) { // We parallelize storing memory operations in chunk of 3, i.e., 1 per intermediate register. // The variable pos is an index pointing to the first storing operation (pertaining to intermediate @@ -333,22 +333,22 @@ void AvmMiniTraceBuilder::calldata_copy(uint32_t cd_offset, } main_trace.push_back(Row{ - .avmMini_clk = clk, - .avmMini_pc = FF(pc++), - .avmMini_internal_return_ptr = FF(internal_return_ptr), - .avmMini_in_tag = FF(static_cast(AvmMemoryTag::FF)), - .avmMini_ia = ia, - .avmMini_ib = ib, - .avmMini_ic = ic, - .avmMini_mem_op_a = FF(mem_op_a), - .avmMini_mem_op_b = FF(mem_op_b), - .avmMini_mem_op_c = FF(mem_op_c), - .avmMini_rwa = FF(rwa), - .avmMini_rwb = FF(rwb), - .avmMini_rwc = FF(rwc), - .avmMini_mem_idx_a = FF(mem_idx_a), - .avmMini_mem_idx_b = FF(mem_idx_b), - .avmMini_mem_idx_c = FF(mem_idx_c), + .avm_main_clk = clk, + .avm_main_pc = FF(pc++), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .avm_main_ia = ia, + .avm_main_ib = ib, + .avm_main_ic = ic, + .avm_main_mem_op_a = FF(mem_op_a), + .avm_main_mem_op_b = FF(mem_op_b), + .avm_main_mem_op_c = FF(mem_op_c), + .avm_main_rwa = FF(rwa), + .avm_main_rwb = FF(rwb), + .avm_main_rwc = FF(rwc), + .avm_main_mem_idx_a = FF(mem_idx_a), + .avm_main_mem_idx_b = FF(mem_idx_b), + .avm_main_mem_idx_c = FF(mem_idx_c), }); if (copy_size - pos > 2) { // Guard to prevent overflow if copy_size is close to uint32_t maximum value. @@ -373,7 +373,7 @@ void AvmMiniTraceBuilder::calldata_copy(uint32_t cd_offset, * @param ret_size The number of elements to be returned. * @return The returned memory region as a std::vector. */ -std::vector AvmMiniTraceBuilder::return_op(uint32_t ret_offset, uint32_t ret_size) +std::vector AvmTraceBuilder::return_op(uint32_t ret_offset, uint32_t ret_size) { if (ret_size == 0) { halt(); @@ -430,20 +430,20 @@ std::vector AvmMiniTraceBuilder::return_op(uint32_t ret_offset, uint32_t ret } main_trace.push_back(Row{ - .avmMini_clk = clk, - .avmMini_pc = FF(pc), - .avmMini_internal_return_ptr = FF(internal_return_ptr), - .avmMini_sel_halt = FF(1), - .avmMini_in_tag = FF(static_cast(AvmMemoryTag::FF)), - .avmMini_ia = ia, - .avmMini_ib = ib, - .avmMini_ic = ic, - .avmMini_mem_op_a = FF(mem_op_a), - .avmMini_mem_op_b = FF(mem_op_b), - .avmMini_mem_op_c = FF(mem_op_c), - .avmMini_mem_idx_a = FF(mem_idx_a), - .avmMini_mem_idx_b = FF(mem_idx_b), - .avmMini_mem_idx_c = FF(mem_idx_c), + .avm_main_clk = clk, + .avm_main_pc = FF(pc), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_sel_halt = FF(1), + .avm_main_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .avm_main_ia = ia, + .avm_main_ib = ib, + .avm_main_ic = ic, + .avm_main_mem_op_a = FF(mem_op_a), + .avm_main_mem_op_b = FF(mem_op_b), + .avm_main_mem_op_c = FF(mem_op_c), + .avm_main_mem_idx_a = FF(mem_idx_a), + .avm_main_mem_idx_b = FF(mem_idx_b), + .avm_main_mem_idx_c = FF(mem_idx_c), }); if (ret_size - pos > 2) { // Guard to prevent overflow if ret_size is close to uint32_t maximum value. @@ -462,15 +462,15 @@ std::vector AvmMiniTraceBuilder::return_op(uint32_t ret_offset, uint32_t ret * ensures the program counter increments on each opcode. * i.e. the program counter should freeze and the halt flag is set to 1. */ -void AvmMiniTraceBuilder::halt() +void AvmTraceBuilder::halt() { auto clk = main_trace.size(); main_trace.push_back(Row{ - .avmMini_clk = clk, - .avmMini_pc = FF(pc), - .avmMini_internal_return_ptr = FF(internal_return_ptr), - .avmMini_sel_halt = FF(1), + .avm_main_clk = clk, + .avm_main_pc = FF(pc), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_sel_halt = FF(1), }); pc = UINT32_MAX; // This ensures that no subsequent opcode will be executed. @@ -484,16 +484,16 @@ void AvmMiniTraceBuilder::halt() * * @param jmp_dest - The destination to jump to */ -void AvmMiniTraceBuilder::jump(uint32_t jmp_dest) +void AvmTraceBuilder::jump(uint32_t jmp_dest) { auto clk = main_trace.size(); main_trace.push_back(Row{ - .avmMini_clk = clk, - .avmMini_pc = FF(pc), - .avmMini_internal_return_ptr = FF(internal_return_ptr), - .avmMini_sel_jump = FF(1), - .avmMini_ia = FF(jmp_dest), + .avm_main_clk = clk, + .avm_main_pc = FF(pc), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_sel_jump = FF(1), + .avm_main_ia = FF(jmp_dest), }); // Adjust parameters for the next row @@ -513,7 +513,7 @@ void AvmMiniTraceBuilder::jump(uint32_t jmp_dest) * * @param jmp_dest - The destination to jump to */ -void AvmMiniTraceBuilder::internal_call(uint32_t jmp_dest) +void AvmTraceBuilder::internal_call(uint32_t jmp_dest) { auto clk = static_cast(main_trace.size()); @@ -525,15 +525,15 @@ void AvmMiniTraceBuilder::internal_call(uint32_t jmp_dest) mem_trace_builder.write_into_memory(clk, IntermRegister::IB, internal_return_ptr, FF(stored_pc), AvmMemoryTag::FF); main_trace.push_back(Row{ - .avmMini_clk = clk, - .avmMini_pc = FF(pc), - .avmMini_internal_return_ptr = FF(internal_return_ptr), - .avmMini_sel_internal_call = FF(1), - .avmMini_ia = FF(jmp_dest), - .avmMini_ib = stored_pc, - .avmMini_mem_op_b = FF(1), - .avmMini_rwb = FF(1), - .avmMini_mem_idx_b = FF(internal_return_ptr), + .avm_main_clk = clk, + .avm_main_pc = FF(pc), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_sel_internal_call = FF(1), + .avm_main_ia = FF(jmp_dest), + .avm_main_ib = stored_pc, + .avm_main_mem_op_b = FF(1), + .avm_main_rwb = FF(1), + .avm_main_mem_idx_b = FF(internal_return_ptr), }); // Adjust parameters for the next row @@ -551,7 +551,7 @@ void AvmMiniTraceBuilder::internal_call(uint32_t jmp_dest) * * TODO(https://github.com/AztecProtocol/aztec-packages/issues/3740): This function MUST come after a call instruction. */ -void AvmMiniTraceBuilder::internal_return() +void AvmTraceBuilder::internal_return() { auto clk = static_cast(main_trace.size()); @@ -561,14 +561,14 @@ void AvmMiniTraceBuilder::internal_return() mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::IA, internal_return_ptr - 1, AvmMemoryTag::FF); main_trace.push_back(Row{ - .avmMini_clk = clk, - .avmMini_pc = pc, - .avmMini_internal_return_ptr = FF(internal_return_ptr), - .avmMini_sel_internal_return = FF(1), - .avmMini_ia = read_a.val, - .avmMini_mem_op_a = FF(1), - .avmMini_rwa = FF(0), - .avmMini_mem_idx_a = FF(internal_return_ptr - 1), + .avm_main_clk = clk, + .avm_main_pc = pc, + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_sel_internal_return = FF(1), + .avm_main_ia = read_a.val, + .avm_main_mem_op_a = FF(1), + .avm_main_rwa = FF(0), + .avm_main_mem_idx_a = FF(internal_return_ptr - 1), }); // We want the next row to be the one pointed by jmp_dest @@ -586,7 +586,7 @@ void AvmMiniTraceBuilder::internal_return() * * @return The main trace */ -std::vector AvmMiniTraceBuilder::finalize() +std::vector AvmTraceBuilder::finalize() { auto mem_trace = mem_trace_builder.finalize(); auto alu_trace = alu_trace_builder.finalize(); @@ -607,29 +607,29 @@ std::vector AvmMiniTraceBuilder::finalize() main_trace.push_back({}); } - main_trace.at(main_trace_size - 1).avmMini_last = FF(1); + main_trace.at(main_trace_size - 1).avm_main_last = FF(1); // Memory trace inclusion for (size_t i = 0; i < mem_trace_size; i++) { auto const& src = mem_trace.at(i); auto& dest = main_trace.at(i); - dest.memTrace_m_clk = FF(src.m_clk); - dest.memTrace_m_sub_clk = FF(src.m_sub_clk); - dest.memTrace_m_addr = FF(src.m_addr); - dest.memTrace_m_val = src.m_val; - dest.memTrace_m_rw = FF(static_cast(src.m_rw)); - dest.memTrace_m_in_tag = FF(static_cast(src.m_in_tag)); - dest.memTrace_m_tag = FF(static_cast(src.m_tag)); - dest.memTrace_m_tag_err = FF(static_cast(src.m_tag_err)); - dest.memTrace_m_one_min_inv = src.m_one_min_inv; + dest.avm_mem_m_clk = FF(src.m_clk); + dest.avm_mem_m_sub_clk = FF(src.m_sub_clk); + dest.avm_mem_m_addr = FF(src.m_addr); + dest.avm_mem_m_val = src.m_val; + dest.avm_mem_m_rw = FF(static_cast(src.m_rw)); + dest.avm_mem_m_in_tag = FF(static_cast(src.m_in_tag)); + dest.avm_mem_m_tag = FF(static_cast(src.m_tag)); + dest.avm_mem_m_tag_err = FF(static_cast(src.m_tag_err)); + dest.avm_mem_m_one_min_inv = src.m_one_min_inv; if (i + 1 < mem_trace_size) { auto const& next = mem_trace.at(i + 1); - dest.memTrace_m_lastAccess = FF(static_cast(src.m_addr != next.m_addr)); + dest.avm_mem_m_lastAccess = FF(static_cast(src.m_addr != next.m_addr)); } else { - dest.memTrace_m_lastAccess = FF(1); - dest.memTrace_m_last = FF(1); + dest.avm_mem_m_lastAccess = FF(1); + dest.avm_mem_m_last = FF(1); } } @@ -638,43 +638,43 @@ std::vector AvmMiniTraceBuilder::finalize() auto const& src = alu_trace.at(i); auto& dest = main_trace.at(i); - dest.aluChip_alu_clk = FF(static_cast(src.alu_clk)); + dest.avm_alu_alu_clk = FF(static_cast(src.alu_clk)); - dest.aluChip_alu_op_add = FF(static_cast(src.alu_op_add)); - dest.aluChip_alu_op_sub = FF(static_cast(src.alu_op_sub)); - dest.aluChip_alu_op_mul = FF(static_cast(src.alu_op_mul)); - dest.aluChip_alu_op_not = FF(static_cast(src.alu_op_not)); + dest.avm_alu_alu_op_add = FF(static_cast(src.alu_op_add)); + dest.avm_alu_alu_op_sub = FF(static_cast(src.alu_op_sub)); + dest.avm_alu_alu_op_mul = FF(static_cast(src.alu_op_mul)); + dest.avm_alu_alu_op_not = FF(static_cast(src.alu_op_not)); - dest.aluChip_alu_ff_tag = FF(static_cast(src.alu_ff_tag)); - dest.aluChip_alu_u8_tag = FF(static_cast(src.alu_u8_tag)); - dest.aluChip_alu_u16_tag = FF(static_cast(src.alu_u16_tag)); - dest.aluChip_alu_u32_tag = FF(static_cast(src.alu_u32_tag)); - dest.aluChip_alu_u64_tag = FF(static_cast(src.alu_u64_tag)); - dest.aluChip_alu_u128_tag = FF(static_cast(src.alu_u128_tag)); + dest.avm_alu_alu_ff_tag = FF(static_cast(src.alu_ff_tag)); + dest.avm_alu_alu_u8_tag = FF(static_cast(src.alu_u8_tag)); + dest.avm_alu_alu_u16_tag = FF(static_cast(src.alu_u16_tag)); + dest.avm_alu_alu_u32_tag = FF(static_cast(src.alu_u32_tag)); + dest.avm_alu_alu_u64_tag = FF(static_cast(src.alu_u64_tag)); + dest.avm_alu_alu_u128_tag = FF(static_cast(src.alu_u128_tag)); - dest.aluChip_alu_ia = src.alu_ia; - dest.aluChip_alu_ib = src.alu_ib; - dest.aluChip_alu_ic = src.alu_ic; + dest.avm_alu_alu_ia = src.alu_ia; + dest.avm_alu_alu_ib = src.alu_ib; + dest.avm_alu_alu_ic = src.alu_ic; - dest.aluChip_alu_cf = FF(static_cast(src.alu_cf)); + dest.avm_alu_alu_cf = FF(static_cast(src.alu_cf)); - dest.aluChip_alu_u8_r0 = FF(src.alu_u8_r0); - dest.aluChip_alu_u8_r1 = FF(src.alu_u8_r1); + dest.avm_alu_alu_u8_r0 = FF(src.alu_u8_r0); + dest.avm_alu_alu_u8_r1 = FF(src.alu_u8_r1); - dest.aluChip_alu_u16_r0 = FF(src.alu_u16_reg.at(0)); - dest.aluChip_alu_u16_r1 = FF(src.alu_u16_reg.at(1)); - dest.aluChip_alu_u16_r2 = FF(src.alu_u16_reg.at(2)); - dest.aluChip_alu_u16_r3 = FF(src.alu_u16_reg.at(3)); - dest.aluChip_alu_u16_r4 = FF(src.alu_u16_reg.at(4)); - dest.aluChip_alu_u16_r5 = FF(src.alu_u16_reg.at(5)); - dest.aluChip_alu_u16_r6 = FF(src.alu_u16_reg.at(6)); - dest.aluChip_alu_u16_r7 = FF(src.alu_u16_reg.at(7)); + dest.avm_alu_alu_u16_r0 = FF(src.alu_u16_reg.at(0)); + dest.avm_alu_alu_u16_r1 = FF(src.alu_u16_reg.at(1)); + dest.avm_alu_alu_u16_r2 = FF(src.alu_u16_reg.at(2)); + dest.avm_alu_alu_u16_r3 = FF(src.alu_u16_reg.at(3)); + dest.avm_alu_alu_u16_r4 = FF(src.alu_u16_reg.at(4)); + dest.avm_alu_alu_u16_r5 = FF(src.alu_u16_reg.at(5)); + dest.avm_alu_alu_u16_r6 = FF(src.alu_u16_reg.at(6)); + dest.avm_alu_alu_u16_r7 = FF(src.alu_u16_reg.at(7)); - dest.aluChip_alu_u64_r0 = FF(src.alu_u64_r0); + dest.avm_alu_alu_u64_r0 = FF(src.alu_u64_r0); } // Adding extra row for the shifted values at the top of the execution trace. - Row first_row = Row{ .avmMini_first = FF(1), .memTrace_m_lastAccess = FF(1) }; + Row first_row = Row{ .avm_main_first = FF(1), .avm_mem_m_lastAccess = FF(1) }; main_trace.insert(main_trace.begin(), first_row); auto trace = std::move(main_trace); @@ -690,7 +690,7 @@ std::vector AvmMiniTraceBuilder::finalize() * @param dst_offset An index in memory pointing to the output of Not. * @param in_tag The instruction memory tag of the operands. */ -void AvmMiniTraceBuilder::op_not(uint32_t a_offset, uint32_t dst_offset, AvmMemoryTag in_tag) +void AvmTraceBuilder::op_not(uint32_t a_offset, uint32_t dst_offset, AvmMemoryTag in_tag) { auto clk = static_cast(main_trace.size()); @@ -704,18 +704,18 @@ void AvmMiniTraceBuilder::op_not(uint32_t a_offset, uint32_t dst_offset, AvmMemo mem_trace_builder.write_into_memory(clk, IntermRegister::IC, dst_offset, c, in_tag); main_trace.push_back(Row{ - .avmMini_clk = clk, - .avmMini_pc = FF(pc++), - .avmMini_internal_return_ptr = FF(internal_return_ptr), - .avmMini_sel_op_not = FF(1), - .avmMini_in_tag = FF(static_cast(in_tag)), - .avmMini_ia = read_a.val, - .avmMini_ic = c, - .avmMini_mem_op_a = FF(1), - .avmMini_mem_op_c = FF(1), - .avmMini_rwc = FF(1), - .avmMini_mem_idx_a = FF(a_offset), - .avmMini_mem_idx_c = FF(dst_offset), + .avm_main_clk = clk, + .avm_main_pc = FF(pc++), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_sel_op_not = FF(1), + .avm_main_in_tag = FF(static_cast(in_tag)), + .avm_main_ia = read_a.val, + .avm_main_ic = c, + .avm_main_mem_op_a = FF(1), + .avm_main_mem_op_c = FF(1), + .avm_main_rwc = FF(1), + .avm_main_mem_idx_a = FF(a_offset), + .avm_main_mem_idx_c = FF(dst_offset), }); }; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp similarity index 85% rename from barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp rename to barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp index b700caf7ac2..5a4e389e41a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp @@ -2,26 +2,26 @@ #include -#include "AvmMini_alu_trace.hpp" -#include "AvmMini_common.hpp" -#include "AvmMini_instructions.hpp" -#include "AvmMini_mem_trace.hpp" +#include "avm_alu_trace.hpp" +#include "avm_common.hpp" +#include "avm_instructions.hpp" +#include "avm_mem_trace.hpp" #include "barretenberg/common/throw_or_abort.hpp" -#include "barretenberg/relations/generated/AvmMini/avm_mini.hpp" +#include "barretenberg/relations/generated/avm/avm_main.hpp" namespace avm_trace { // This is the internal context that we keep along the lifecycle of bytecode execution // to iteratively build the whole trace. This is effectively performing witness generation. -// At the end of circuit building, mainTrace can be moved to AvmMiniCircuitBuilder by calling -// AvmMiniCircuitBuilder::set_trace(rows). -class AvmMiniTraceBuilder { +// At the end of circuit building, mainTrace can be moved to AvmCircuitBuilder by calling +// AvmCircuitBuilder::set_trace(rows). +class AvmTraceBuilder { public: static const size_t CALLSTACK_OFFSET = 896; // TODO(md): Temporary reserved area 896 - 1024 - AvmMiniTraceBuilder(); + AvmTraceBuilder(); std::vector finalize(); void reset(); @@ -72,8 +72,8 @@ class AvmMiniTraceBuilder { private: std::vector main_trace; - AvmMiniMemTraceBuilder mem_trace_builder; - AvmMiniAluTraceBuilder alu_trace_builder; + AvmMemTraceBuilder mem_trace_builder; + AvmAluTraceBuilder alu_trace_builder; uint32_t pc = 0; uint32_t internal_return_ptr = CALLSTACK_OFFSET; diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp deleted file mode 100644 index 34ad124fa92..00000000000 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp +++ /dev/null @@ -1,202 +0,0 @@ - - -#include "./AvmMini_verifier.hpp" -#include "barretenberg/commitment_schemes/zeromorph/zeromorph.hpp" -#include "barretenberg/numeric/bitop/get_msb.hpp" -#include "barretenberg/transcript/transcript.hpp" - -namespace bb { -AvmMiniVerifier::AvmMiniVerifier(std::shared_ptr verifier_key) - : key(verifier_key) -{} - -AvmMiniVerifier::AvmMiniVerifier(AvmMiniVerifier&& other) noexcept - : key(std::move(other.key)) - , pcs_verification_key(std::move(other.pcs_verification_key)) -{} - -AvmMiniVerifier& AvmMiniVerifier::operator=(AvmMiniVerifier&& other) noexcept -{ - key = other.key; - pcs_verification_key = (std::move(other.pcs_verification_key)); - commitments.clear(); - return *this; -} - -/** - * @brief This function verifies an AvmMini Honk proof for given program settings. - * - */ -bool AvmMiniVerifier::verify_proof(const HonkProof& proof) -{ - using Flavor = AvmMiniFlavor; - using FF = Flavor::FF; - using Commitment = Flavor::Commitment; - // using Curve = Flavor::Curve; - // using ZeroMorph = ZeroMorphVerifier_; - using VerifierCommitments = Flavor::VerifierCommitments; - using CommitmentLabels = Flavor::CommitmentLabels; - - RelationParameters relation_parameters; - - transcript = std::make_shared(proof); - - VerifierCommitments commitments{ key }; - CommitmentLabels commitment_labels; - - const auto circuit_size = transcript->template receive_from_prover("circuit_size"); - - if (circuit_size != key->circuit_size) { - return false; - } - - // Get commitments to VM wires - commitments.memTrace_m_clk = transcript->template receive_from_prover(commitment_labels.memTrace_m_clk); - commitments.memTrace_m_sub_clk = - transcript->template receive_from_prover(commitment_labels.memTrace_m_sub_clk); - commitments.memTrace_m_addr = - transcript->template receive_from_prover(commitment_labels.memTrace_m_addr); - commitments.memTrace_m_tag = transcript->template receive_from_prover(commitment_labels.memTrace_m_tag); - commitments.memTrace_m_val = transcript->template receive_from_prover(commitment_labels.memTrace_m_val); - commitments.memTrace_m_lastAccess = - transcript->template receive_from_prover(commitment_labels.memTrace_m_lastAccess); - commitments.memTrace_m_last = - transcript->template receive_from_prover(commitment_labels.memTrace_m_last); - commitments.memTrace_m_rw = transcript->template receive_from_prover(commitment_labels.memTrace_m_rw); - commitments.memTrace_m_in_tag = - transcript->template receive_from_prover(commitment_labels.memTrace_m_in_tag); - commitments.memTrace_m_tag_err = - transcript->template receive_from_prover(commitment_labels.memTrace_m_tag_err); - commitments.memTrace_m_one_min_inv = - transcript->template receive_from_prover(commitment_labels.memTrace_m_one_min_inv); - commitments.aluChip_alu_clk = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_clk); - commitments.aluChip_alu_ia = transcript->template receive_from_prover(commitment_labels.aluChip_alu_ia); - commitments.aluChip_alu_ib = transcript->template receive_from_prover(commitment_labels.aluChip_alu_ib); - commitments.aluChip_alu_ic = transcript->template receive_from_prover(commitment_labels.aluChip_alu_ic); - commitments.aluChip_alu_op_add = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_op_add); - commitments.aluChip_alu_op_sub = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_op_sub); - commitments.aluChip_alu_op_mul = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_op_mul); - commitments.aluChip_alu_op_div = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_op_div); - commitments.aluChip_alu_op_not = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_op_not); - commitments.aluChip_alu_ff_tag = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_ff_tag); - commitments.aluChip_alu_u8_tag = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u8_tag); - commitments.aluChip_alu_u16_tag = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u16_tag); - commitments.aluChip_alu_u32_tag = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u32_tag); - commitments.aluChip_alu_u64_tag = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u64_tag); - commitments.aluChip_alu_u128_tag = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u128_tag); - commitments.aluChip_alu_u8_r0 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u8_r0); - commitments.aluChip_alu_u8_r1 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u8_r1); - commitments.aluChip_alu_u16_r0 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u16_r0); - commitments.aluChip_alu_u16_r1 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u16_r1); - commitments.aluChip_alu_u16_r2 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u16_r2); - commitments.aluChip_alu_u16_r3 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u16_r3); - commitments.aluChip_alu_u16_r4 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u16_r4); - commitments.aluChip_alu_u16_r5 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u16_r5); - commitments.aluChip_alu_u16_r6 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u16_r6); - commitments.aluChip_alu_u16_r7 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u16_r7); - commitments.aluChip_alu_u64_r0 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u64_r0); - commitments.aluChip_alu_cf = transcript->template receive_from_prover(commitment_labels.aluChip_alu_cf); - commitments.avmMini_pc = transcript->template receive_from_prover(commitment_labels.avmMini_pc); - commitments.avmMini_internal_return_ptr = - transcript->template receive_from_prover(commitment_labels.avmMini_internal_return_ptr); - commitments.avmMini_sel_internal_call = - transcript->template receive_from_prover(commitment_labels.avmMini_sel_internal_call); - commitments.avmMini_sel_internal_return = - transcript->template receive_from_prover(commitment_labels.avmMini_sel_internal_return); - commitments.avmMini_sel_jump = - transcript->template receive_from_prover(commitment_labels.avmMini_sel_jump); - commitments.avmMini_sel_halt = - transcript->template receive_from_prover(commitment_labels.avmMini_sel_halt); - commitments.avmMini_sel_op_add = - transcript->template receive_from_prover(commitment_labels.avmMini_sel_op_add); - commitments.avmMini_sel_op_sub = - transcript->template receive_from_prover(commitment_labels.avmMini_sel_op_sub); - commitments.avmMini_sel_op_mul = - transcript->template receive_from_prover(commitment_labels.avmMini_sel_op_mul); - commitments.avmMini_sel_op_div = - transcript->template receive_from_prover(commitment_labels.avmMini_sel_op_div); - commitments.avmMini_sel_op_not = - transcript->template receive_from_prover(commitment_labels.avmMini_sel_op_not); - commitments.avmMini_in_tag = transcript->template receive_from_prover(commitment_labels.avmMini_in_tag); - commitments.avmMini_op_err = transcript->template receive_from_prover(commitment_labels.avmMini_op_err); - commitments.avmMini_tag_err = - transcript->template receive_from_prover(commitment_labels.avmMini_tag_err); - commitments.avmMini_inv = transcript->template receive_from_prover(commitment_labels.avmMini_inv); - commitments.avmMini_ia = transcript->template receive_from_prover(commitment_labels.avmMini_ia); - commitments.avmMini_ib = transcript->template receive_from_prover(commitment_labels.avmMini_ib); - commitments.avmMini_ic = transcript->template receive_from_prover(commitment_labels.avmMini_ic); - commitments.avmMini_mem_op_a = - transcript->template receive_from_prover(commitment_labels.avmMini_mem_op_a); - commitments.avmMini_mem_op_b = - transcript->template receive_from_prover(commitment_labels.avmMini_mem_op_b); - commitments.avmMini_mem_op_c = - transcript->template receive_from_prover(commitment_labels.avmMini_mem_op_c); - commitments.avmMini_rwa = transcript->template receive_from_prover(commitment_labels.avmMini_rwa); - commitments.avmMini_rwb = transcript->template receive_from_prover(commitment_labels.avmMini_rwb); - commitments.avmMini_rwc = transcript->template receive_from_prover(commitment_labels.avmMini_rwc); - commitments.avmMini_mem_idx_a = - transcript->template receive_from_prover(commitment_labels.avmMini_mem_idx_a); - commitments.avmMini_mem_idx_b = - transcript->template receive_from_prover(commitment_labels.avmMini_mem_idx_b); - commitments.avmMini_mem_idx_c = - transcript->template receive_from_prover(commitment_labels.avmMini_mem_idx_c); - commitments.avmMini_last = transcript->template receive_from_prover(commitment_labels.avmMini_last); - - // Execute Sumcheck Verifier - const size_t log_circuit_size = numeric::get_msb(circuit_size); - auto sumcheck = SumcheckVerifier(log_circuit_size, transcript); - - FF alpha = transcript->template get_challenge("Sumcheck:alpha"); - - auto gate_challenges = std::vector(log_circuit_size); - for (size_t idx = 0; idx < log_circuit_size; idx++) { - gate_challenges[idx] = transcript->template get_challenge("Sumcheck:gate_challenge_" + std::to_string(idx)); - } - - auto [multivariate_challenge, claimed_evaluations, sumcheck_verified] = - sumcheck.verify(relation_parameters, alpha, gate_challenges); - - // If Sumcheck did not verify, return false - if (sumcheck_verified.has_value() && !sumcheck_verified.value()) { - return false; - } - - // Execute ZeroMorph rounds. See https://hackmd.io/dlf9xEwhTQyE3hiGbq4FsA?view for a complete description of the - // unrolled protocol. - // NOTE: temporarily disabled - facing integration issues - // auto pairing_points = ZeroMorph::verify(commitments.get_unshifted(), - // commitments.get_to_be_shifted(), - // claimed_evaluations.get_unshifted(), - // claimed_evaluations.get_shifted(), - // multivariate_challenge, - // transcript); - - // auto verified = pcs_verification_key->pairing_check(pairing_points[0], pairing_points[1]); - // return sumcheck_verified.value() && verified; - return sumcheck_verified.value(); -} - -} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_composer.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_composer.cpp similarity index 67% rename from barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_composer.cpp rename to barretenberg/cpp/src/barretenberg/vm/generated/avm_composer.cpp index a27776eabea..e0d075cc5bf 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_composer.cpp @@ -1,15 +1,15 @@ -#include "./AvmMini_composer.hpp" -#include "barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp" +#include "./avm_composer.hpp" +#include "barretenberg/proof_system/circuit_builder/generated/avm_circuit_builder.hpp" #include "barretenberg/proof_system/composer/composer_lib.hpp" #include "barretenberg/proof_system/composer/permutation_lib.hpp" -#include "barretenberg/vm/generated/AvmMini_verifier.hpp" +#include "barretenberg/vm/generated/avm_verifier.hpp" namespace bb { -using Flavor = AvmMiniFlavor; -void AvmMiniComposer::compute_witness(CircuitConstructor& circuit) +using Flavor = AvmFlavor; +void AvmComposer::compute_witness(CircuitConstructor& circuit) { if (computed_witness) { return; @@ -25,22 +25,22 @@ void AvmMiniComposer::compute_witness(CircuitConstructor& circuit) computed_witness = true; } -AvmMiniProver AvmMiniComposer::create_prover(CircuitConstructor& circuit_constructor) +AvmProver AvmComposer::create_prover(CircuitConstructor& circuit_constructor) { compute_proving_key(circuit_constructor); compute_witness(circuit_constructor); compute_commitment_key(circuit_constructor.get_circuit_subgroup_size()); - AvmMiniProver output_state(proving_key, commitment_key); + AvmProver output_state(proving_key, commitment_key); return output_state; } -AvmMiniVerifier AvmMiniComposer::create_verifier(CircuitConstructor& circuit_constructor) +AvmVerifier AvmComposer::create_verifier(CircuitConstructor& circuit_constructor) { auto verification_key = compute_verification_key(circuit_constructor); - AvmMiniVerifier output_state(verification_key); + AvmVerifier output_state(verification_key); auto pcs_verification_key = std::make_unique(verification_key->circuit_size, crs_factory_); @@ -49,7 +49,7 @@ AvmMiniVerifier AvmMiniComposer::create_verifier(CircuitConstructor& circuit_con return output_state; } -std::shared_ptr AvmMiniComposer::compute_proving_key(CircuitConstructor& circuit_constructor) +std::shared_ptr AvmComposer::compute_proving_key(CircuitConstructor& circuit_constructor) { if (proving_key) { return proving_key; @@ -66,8 +66,7 @@ std::shared_ptr AvmMiniComposer::compute_proving_key(Circuit return proving_key; } -std::shared_ptr AvmMiniComposer::compute_verification_key( - CircuitConstructor& circuit_constructor) +std::shared_ptr AvmComposer::compute_verification_key(CircuitConstructor& circuit_constructor) { if (verification_key) { return verification_key; diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_composer.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_composer.hpp similarity index 63% rename from barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_composer.hpp rename to barretenberg/cpp/src/barretenberg/vm/generated/avm_composer.hpp index 61a6fbfa622..1db659f2797 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_composer.hpp @@ -2,17 +2,17 @@ #pragma once -#include "barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp" +#include "barretenberg/proof_system/circuit_builder/generated/avm_circuit_builder.hpp" #include "barretenberg/proof_system/composer/composer_lib.hpp" #include "barretenberg/srs/global_crs.hpp" -#include "barretenberg/vm/generated/AvmMini_prover.hpp" -#include "barretenberg/vm/generated/AvmMini_verifier.hpp" +#include "barretenberg/vm/generated/avm_prover.hpp" +#include "barretenberg/vm/generated/avm_verifier.hpp" namespace bb { -class AvmMiniComposer { +class AvmComposer { public: - using Flavor = AvmMiniFlavor; - using CircuitConstructor = AvmMiniCircuitBuilder; + using Flavor = AvmFlavor; + using CircuitConstructor = AvmCircuitBuilder; using ProvingKey = Flavor::ProvingKey; using VerificationKey = Flavor::VerificationKey; using PCS = Flavor::PCS; @@ -20,7 +20,7 @@ class AvmMiniComposer { using VerifierCommitmentKey = Flavor::VerifierCommitmentKey; // TODO: which of these will we really need - static constexpr std::string_view NAME_STRING = "AvmMini"; + static constexpr std::string_view NAME_STRING = "Avm"; static constexpr size_t NUM_RESERVED_GATES = 0; static constexpr size_t NUM_WIRES = Flavor::NUM_WIRES; @@ -37,26 +37,26 @@ class AvmMiniComposer { bool contains_recursive_proof = false; bool computed_witness = false; - AvmMiniComposer() { crs_factory_ = bb::srs::get_crs_factory(); } + AvmComposer() { crs_factory_ = bb::srs::get_crs_factory(); } - AvmMiniComposer(std::shared_ptr p_key, std::shared_ptr v_key) + AvmComposer(std::shared_ptr p_key, std::shared_ptr v_key) : proving_key(std::move(p_key)) , verification_key(std::move(v_key)) {} - AvmMiniComposer(AvmMiniComposer&& other) noexcept = default; - AvmMiniComposer(AvmMiniComposer const& other) noexcept = default; - AvmMiniComposer& operator=(AvmMiniComposer&& other) noexcept = default; - AvmMiniComposer& operator=(AvmMiniComposer const& other) noexcept = default; - ~AvmMiniComposer() = default; + AvmComposer(AvmComposer&& other) noexcept = default; + AvmComposer(AvmComposer const& other) noexcept = default; + AvmComposer& operator=(AvmComposer&& other) noexcept = default; + AvmComposer& operator=(AvmComposer const& other) noexcept = default; + ~AvmComposer() = default; std::shared_ptr compute_proving_key(CircuitConstructor& circuit_constructor); std::shared_ptr compute_verification_key(CircuitConstructor& circuit_constructor); void compute_witness(CircuitConstructor& circuit_constructor); - AvmMiniProver create_prover(CircuitConstructor& circuit_constructor); - AvmMiniVerifier create_verifier(CircuitConstructor& circuit_constructor); + AvmProver create_prover(CircuitConstructor& circuit_constructor); + AvmVerifier create_verifier(CircuitConstructor& circuit_constructor); void add_table_column_selector_poly_to_proving_key(bb::polynomial& small, const std::string& tag); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp similarity index 87% rename from barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.cpp rename to barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp index 420a06956fb..8a5dd977b6b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp @@ -1,6 +1,6 @@ -#include "AvmMini_prover.hpp" +#include "avm_prover.hpp" #include "barretenberg/commitment_schemes/claim.hpp" #include "barretenberg/commitment_schemes/commitment_key.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" @@ -13,19 +13,18 @@ namespace bb { -using Flavor = AvmMiniFlavor; +using Flavor = AvmFlavor; using FF = Flavor::FF; /** - * Create AvmMiniProver from proving key, witness and manifest. + * Create AvmProver from proving key, witness and manifest. * * @param input_key Proving key. * @param input_manifest Input manifest * * @tparam settings Settings class. * */ -AvmMiniProver::AvmMiniProver(std::shared_ptr input_key, - std::shared_ptr commitment_key) +AvmProver::AvmProver(std::shared_ptr input_key, std::shared_ptr commitment_key) : key(input_key) , commitment_key(commitment_key) { @@ -44,7 +43,7 @@ AvmMiniProver::AvmMiniProver(std::shared_ptr input_key, * @brief Add circuit size, public input size, and public inputs to transcript * */ -void AvmMiniProver::execute_preamble_round() +void AvmProver::execute_preamble_round() { const auto circuit_size = static_cast(key->circuit_size); @@ -55,7 +54,7 @@ void AvmMiniProver::execute_preamble_round() * @brief Compute commitments to the first three wires * */ -void AvmMiniProver::execute_wire_commitments_round() +void AvmProver::execute_wire_commitments_round() { auto wire_polys = key->get_wires(); auto labels = commitment_labels.get_wires(); @@ -68,7 +67,7 @@ void AvmMiniProver::execute_wire_commitments_round() * @brief Run Sumcheck resulting in u = (u_1,...,u_d) challenges and all evaluations at u being calculated. * */ -void AvmMiniProver::execute_relation_check_rounds() +void AvmProver::execute_relation_check_rounds() { using Sumcheck = SumcheckProver; @@ -88,7 +87,7 @@ void AvmMiniProver::execute_relation_check_rounds() * @details See https://hackmd.io/dlf9xEwhTQyE3hiGbq4FsA?view for a complete description of the unrolled protocol. * * */ -void AvmMiniProver::execute_zeromorph_rounds() +void AvmProver::execute_zeromorph_rounds() { ZeroMorph::prove(prover_polynomials.get_unshifted(), prover_polynomials.get_to_be_shifted(), @@ -99,13 +98,13 @@ void AvmMiniProver::execute_zeromorph_rounds() transcript); } -HonkProof& AvmMiniProver::export_proof() +HonkProof& AvmProver::export_proof() { proof = transcript->proof_data; return proof; } -HonkProof& AvmMiniProver::construct_proof() +HonkProof& AvmProver::construct_proof() { // Add circuit size public input size and public inputs to transcript. execute_preamble_round(); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.hpp similarity index 87% rename from barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.hpp rename to barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.hpp index c1aec1a2f9a..d0fe0046c9a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.hpp @@ -2,7 +2,7 @@ #pragma once #include "barretenberg/commitment_schemes/zeromorph/zeromorph.hpp" -#include "barretenberg/flavor/generated/AvmMini_flavor.hpp" +#include "barretenberg/flavor/generated/avm_flavor.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/sumcheck/sumcheck_output.hpp" @@ -10,9 +10,9 @@ namespace bb { -class AvmMiniProver { +class AvmProver { - using Flavor = AvmMiniFlavor; + using Flavor = AvmFlavor; using FF = Flavor::FF; using PCS = Flavor::PCS; using PCSCommitmentKey = Flavor::CommitmentKey; @@ -24,7 +24,7 @@ class AvmMiniProver { using Transcript = Flavor::Transcript; public: - explicit AvmMiniProver(std::shared_ptr input_key, std::shared_ptr commitment_key); + explicit AvmProver(std::shared_ptr input_key, std::shared_ptr commitment_key); void execute_preamble_round(); void execute_wire_commitments_round(); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp new file mode 100644 index 00000000000..46fe5e32c86 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp @@ -0,0 +1,202 @@ + + +#include "./avm_verifier.hpp" +#include "barretenberg/commitment_schemes/zeromorph/zeromorph.hpp" +#include "barretenberg/numeric/bitop/get_msb.hpp" +#include "barretenberg/transcript/transcript.hpp" + +namespace bb { +AvmVerifier::AvmVerifier(std::shared_ptr verifier_key) + : key(verifier_key) +{} + +AvmVerifier::AvmVerifier(AvmVerifier&& other) noexcept + : key(std::move(other.key)) + , pcs_verification_key(std::move(other.pcs_verification_key)) +{} + +AvmVerifier& AvmVerifier::operator=(AvmVerifier&& other) noexcept +{ + key = other.key; + pcs_verification_key = (std::move(other.pcs_verification_key)); + commitments.clear(); + return *this; +} + +/** + * @brief This function verifies an Avm Honk proof for given program settings. + * + */ +bool AvmVerifier::verify_proof(const HonkProof& proof) +{ + using Flavor = AvmFlavor; + using FF = Flavor::FF; + using Commitment = Flavor::Commitment; + // using Curve = Flavor::Curve; + // using ZeroMorph = ZeroMorphVerifier_; + using VerifierCommitments = Flavor::VerifierCommitments; + using CommitmentLabels = Flavor::CommitmentLabels; + + RelationParameters relation_parameters; + + transcript = std::make_shared(proof); + + VerifierCommitments commitments{ key }; + CommitmentLabels commitment_labels; + + const auto circuit_size = transcript->template receive_from_prover("circuit_size"); + + if (circuit_size != key->circuit_size) { + return false; + } + + // Get commitments to VM wires + commitments.avm_mem_m_clk = transcript->template receive_from_prover(commitment_labels.avm_mem_m_clk); + commitments.avm_mem_m_sub_clk = + transcript->template receive_from_prover(commitment_labels.avm_mem_m_sub_clk); + commitments.avm_mem_m_addr = transcript->template receive_from_prover(commitment_labels.avm_mem_m_addr); + commitments.avm_mem_m_tag = transcript->template receive_from_prover(commitment_labels.avm_mem_m_tag); + commitments.avm_mem_m_val = transcript->template receive_from_prover(commitment_labels.avm_mem_m_val); + commitments.avm_mem_m_lastAccess = + transcript->template receive_from_prover(commitment_labels.avm_mem_m_lastAccess); + commitments.avm_mem_m_last = transcript->template receive_from_prover(commitment_labels.avm_mem_m_last); + commitments.avm_mem_m_rw = transcript->template receive_from_prover(commitment_labels.avm_mem_m_rw); + commitments.avm_mem_m_in_tag = + transcript->template receive_from_prover(commitment_labels.avm_mem_m_in_tag); + commitments.avm_mem_m_tag_err = + transcript->template receive_from_prover(commitment_labels.avm_mem_m_tag_err); + commitments.avm_mem_m_one_min_inv = + transcript->template receive_from_prover(commitment_labels.avm_mem_m_one_min_inv); + commitments.avm_alu_alu_clk = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_clk); + commitments.avm_alu_alu_ia = transcript->template receive_from_prover(commitment_labels.avm_alu_alu_ia); + commitments.avm_alu_alu_ib = transcript->template receive_from_prover(commitment_labels.avm_alu_alu_ib); + commitments.avm_alu_alu_ic = transcript->template receive_from_prover(commitment_labels.avm_alu_alu_ic); + commitments.avm_alu_alu_op_add = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_op_add); + commitments.avm_alu_alu_op_sub = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_op_sub); + commitments.avm_alu_alu_op_mul = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_op_mul); + commitments.avm_alu_alu_op_div = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_op_div); + commitments.avm_alu_alu_op_not = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_op_not); + commitments.avm_alu_alu_ff_tag = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_ff_tag); + commitments.avm_alu_alu_u8_tag = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u8_tag); + commitments.avm_alu_alu_u16_tag = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u16_tag); + commitments.avm_alu_alu_u32_tag = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u32_tag); + commitments.avm_alu_alu_u64_tag = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u64_tag); + commitments.avm_alu_alu_u128_tag = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u128_tag); + commitments.avm_alu_alu_u8_r0 = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u8_r0); + commitments.avm_alu_alu_u8_r1 = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u8_r1); + commitments.avm_alu_alu_u16_r0 = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u16_r0); + commitments.avm_alu_alu_u16_r1 = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u16_r1); + commitments.avm_alu_alu_u16_r2 = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u16_r2); + commitments.avm_alu_alu_u16_r3 = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u16_r3); + commitments.avm_alu_alu_u16_r4 = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u16_r4); + commitments.avm_alu_alu_u16_r5 = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u16_r5); + commitments.avm_alu_alu_u16_r6 = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u16_r6); + commitments.avm_alu_alu_u16_r7 = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u16_r7); + commitments.avm_alu_alu_u64_r0 = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u64_r0); + commitments.avm_alu_alu_cf = transcript->template receive_from_prover(commitment_labels.avm_alu_alu_cf); + commitments.avm_main_pc = transcript->template receive_from_prover(commitment_labels.avm_main_pc); + commitments.avm_main_internal_return_ptr = + transcript->template receive_from_prover(commitment_labels.avm_main_internal_return_ptr); + commitments.avm_main_sel_internal_call = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_internal_call); + commitments.avm_main_sel_internal_return = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_internal_return); + commitments.avm_main_sel_jump = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_jump); + commitments.avm_main_sel_halt = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_halt); + commitments.avm_main_sel_op_add = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_add); + commitments.avm_main_sel_op_sub = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_sub); + commitments.avm_main_sel_op_mul = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_mul); + commitments.avm_main_sel_op_div = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_div); + commitments.avm_main_sel_op_not = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_not); + commitments.avm_main_in_tag = + transcript->template receive_from_prover(commitment_labels.avm_main_in_tag); + commitments.avm_main_op_err = + transcript->template receive_from_prover(commitment_labels.avm_main_op_err); + commitments.avm_main_tag_err = + transcript->template receive_from_prover(commitment_labels.avm_main_tag_err); + commitments.avm_main_inv = transcript->template receive_from_prover(commitment_labels.avm_main_inv); + commitments.avm_main_ia = transcript->template receive_from_prover(commitment_labels.avm_main_ia); + commitments.avm_main_ib = transcript->template receive_from_prover(commitment_labels.avm_main_ib); + commitments.avm_main_ic = transcript->template receive_from_prover(commitment_labels.avm_main_ic); + commitments.avm_main_mem_op_a = + transcript->template receive_from_prover(commitment_labels.avm_main_mem_op_a); + commitments.avm_main_mem_op_b = + transcript->template receive_from_prover(commitment_labels.avm_main_mem_op_b); + commitments.avm_main_mem_op_c = + transcript->template receive_from_prover(commitment_labels.avm_main_mem_op_c); + commitments.avm_main_rwa = transcript->template receive_from_prover(commitment_labels.avm_main_rwa); + commitments.avm_main_rwb = transcript->template receive_from_prover(commitment_labels.avm_main_rwb); + commitments.avm_main_rwc = transcript->template receive_from_prover(commitment_labels.avm_main_rwc); + commitments.avm_main_mem_idx_a = + transcript->template receive_from_prover(commitment_labels.avm_main_mem_idx_a); + commitments.avm_main_mem_idx_b = + transcript->template receive_from_prover(commitment_labels.avm_main_mem_idx_b); + commitments.avm_main_mem_idx_c = + transcript->template receive_from_prover(commitment_labels.avm_main_mem_idx_c); + commitments.avm_main_last = transcript->template receive_from_prover(commitment_labels.avm_main_last); + + // Execute Sumcheck Verifier + const size_t log_circuit_size = numeric::get_msb(circuit_size); + auto sumcheck = SumcheckVerifier(log_circuit_size, transcript); + + FF alpha = transcript->template get_challenge("Sumcheck:alpha"); + + auto gate_challenges = std::vector(log_circuit_size); + for (size_t idx = 0; idx < log_circuit_size; idx++) { + gate_challenges[idx] = transcript->template get_challenge("Sumcheck:gate_challenge_" + std::to_string(idx)); + } + + auto [multivariate_challenge, claimed_evaluations, sumcheck_verified] = + sumcheck.verify(relation_parameters, alpha, gate_challenges); + + // If Sumcheck did not verify, return false + if (sumcheck_verified.has_value() && !sumcheck_verified.value()) { + return false; + } + + // Execute ZeroMorph rounds. See https://hackmd.io/dlf9xEwhTQyE3hiGbq4FsA?view for a complete description of the + // unrolled protocol. + // NOTE: temporarily disabled - facing integration issues + // auto pairing_points = ZeroMorph::verify(commitments.get_unshifted(), + // commitments.get_to_be_shifted(), + // claimed_evaluations.get_unshifted(), + // claimed_evaluations.get_shifted(), + // multivariate_challenge, + // transcript); + + // auto verified = pcs_verification_key->pairing_check(pairing_points[0], pairing_points[1]); + // return sumcheck_verified.value() && verified; + return sumcheck_verified.value(); +} + +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.hpp similarity index 58% rename from barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.hpp rename to barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.hpp index 8250b37c64e..c0ecba92fcd 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.hpp @@ -1,13 +1,13 @@ #pragma once -#include "barretenberg/flavor/generated/AvmMini_flavor.hpp" +#include "barretenberg/flavor/generated/avm_flavor.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" namespace bb { -class AvmMiniVerifier { - using Flavor = AvmMiniFlavor; +class AvmVerifier { + using Flavor = AvmFlavor; using FF = Flavor::FF; using Commitment = Flavor::Commitment; using VerificationKey = Flavor::VerificationKey; @@ -15,12 +15,12 @@ class AvmMiniVerifier { using Transcript = Flavor::Transcript; public: - explicit AvmMiniVerifier(std::shared_ptr verifier_key = nullptr); - AvmMiniVerifier(AvmMiniVerifier&& other) noexcept; - AvmMiniVerifier(const AvmMiniVerifier& other) = delete; + explicit AvmVerifier(std::shared_ptr verifier_key = nullptr); + AvmVerifier(AvmVerifier&& other) noexcept; + AvmVerifier(const AvmVerifier& other) = delete; - AvmMiniVerifier& operator=(const AvmMiniVerifier& other) = delete; - AvmMiniVerifier& operator=(AvmMiniVerifier&& other) noexcept; + AvmVerifier& operator=(const AvmVerifier& other) = delete; + AvmVerifier& operator=(AvmVerifier&& other) noexcept; bool verify_proof(const HonkProof& proof); diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_common.test.hpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_common.test.hpp deleted file mode 100644 index 4d7154552af..00000000000 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_common.test.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "barretenberg/vm/avm_trace/AvmMini_helper.hpp" -#include "barretenberg/vm/generated/AvmMini_composer.hpp" -#include "barretenberg/vm/generated/AvmMini_prover.hpp" -#include "barretenberg/vm/generated/AvmMini_verifier.hpp" -#include "helpers.test.hpp" - -#include -#include -#include -#include -#include \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp similarity index 70% rename from barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp rename to barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp index a0d821c933f..d7b8816bf22 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp @@ -1,4 +1,4 @@ -#include "AvmMini_common.test.hpp" +#include "avm_common.test.hpp" #include "barretenberg/numeric/uint128/uint128.hpp" @@ -18,28 +18,28 @@ void common_validate_arithmetic_op(Row const& main_row, avm_trace::AvmMemoryTag const tag) { // Check that the correct result is stored at the expected memory location. - EXPECT_EQ(main_row.avmMini_ic, c); - EXPECT_EQ(main_row.avmMini_mem_idx_c, addr_c); - EXPECT_EQ(main_row.avmMini_mem_op_c, FF(1)); - EXPECT_EQ(main_row.avmMini_rwc, FF(1)); + EXPECT_EQ(main_row.avm_main_ic, c); + EXPECT_EQ(main_row.avm_main_mem_idx_c, addr_c); + EXPECT_EQ(main_row.avm_main_mem_op_c, FF(1)); + EXPECT_EQ(main_row.avm_main_rwc, FF(1)); // Check that ia and ib registers are correctly set with memory load operations. - EXPECT_EQ(main_row.avmMini_ia, a); - EXPECT_EQ(main_row.avmMini_mem_idx_a, addr_a); - EXPECT_EQ(main_row.avmMini_mem_op_a, FF(1)); - EXPECT_EQ(main_row.avmMini_rwa, FF(0)); - EXPECT_EQ(main_row.avmMini_ib, b); - EXPECT_EQ(main_row.avmMini_mem_idx_b, addr_b); - EXPECT_EQ(main_row.avmMini_mem_op_b, FF(1)); - EXPECT_EQ(main_row.avmMini_rwb, FF(0)); + EXPECT_EQ(main_row.avm_main_ia, a); + EXPECT_EQ(main_row.avm_main_mem_idx_a, addr_a); + EXPECT_EQ(main_row.avm_main_mem_op_a, FF(1)); + EXPECT_EQ(main_row.avm_main_rwa, FF(0)); + EXPECT_EQ(main_row.avm_main_ib, b); + EXPECT_EQ(main_row.avm_main_mem_idx_b, addr_b); + EXPECT_EQ(main_row.avm_main_mem_op_b, FF(1)); + EXPECT_EQ(main_row.avm_main_rwb, FF(0)); // Check the instruction tag - EXPECT_EQ(main_row.avmMini_in_tag, FF(static_cast(tag))); + EXPECT_EQ(main_row.avm_main_in_tag, FF(static_cast(tag))); // Check that intermediate registers are correctly copied in Alu trace - EXPECT_EQ(alu_row.aluChip_alu_ia, a); - EXPECT_EQ(alu_row.aluChip_alu_ib, b); - EXPECT_EQ(alu_row.aluChip_alu_ic, c); + EXPECT_EQ(alu_row.avm_alu_alu_ia, a); + EXPECT_EQ(alu_row.avm_alu_alu_ib, b); + EXPECT_EQ(alu_row.avm_alu_alu_ic, c); } Row common_validate_add(std::vector const& trace, @@ -52,11 +52,11 @@ Row common_validate_add(std::vector const& trace, avm_trace::AvmMemoryTag const tag) { // Find the first row enabling the addition selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_add == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_add == FF(1); }); // Find the corresponding Alu trace row - auto clk = row->avmMini_clk; - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.aluChip_alu_clk == clk; }); + auto clk = row->avm_main_clk; + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_alu_clk == clk; }); // Check that both rows were found EXPECT_TRUE(row != trace.end()); @@ -65,8 +65,8 @@ Row common_validate_add(std::vector const& trace, common_validate_arithmetic_op(*row, *alu_row, a, b, c, addr_a, addr_b, addr_c, tag); // Check that addition selector is set. - EXPECT_EQ(row->avmMini_sel_op_add, FF(1)); - EXPECT_EQ(alu_row->aluChip_alu_op_add, FF(1)); + EXPECT_EQ(row->avm_main_sel_op_add, FF(1)); + EXPECT_EQ(alu_row->avm_alu_alu_op_add, FF(1)); return *alu_row; } @@ -81,11 +81,11 @@ Row common_validate_sub(std::vector const& trace, avm_trace::AvmMemoryTag const tag) { // Find the first row enabling the subtraction selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_sub == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == FF(1); }); // Find the corresponding Alu trace row - auto clk = row->avmMini_clk; - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.aluChip_alu_clk == clk; }); + auto clk = row->avm_main_clk; + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_alu_clk == clk; }); // Check that both rows were found EXPECT_TRUE(row != trace.end()); @@ -94,8 +94,8 @@ Row common_validate_sub(std::vector const& trace, common_validate_arithmetic_op(*row, *alu_row, a, b, c, addr_a, addr_b, addr_c, tag); // Check that subtraction selector is set. - EXPECT_EQ(row->avmMini_sel_op_sub, FF(1)); - EXPECT_EQ(alu_row->aluChip_alu_op_sub, FF(1)); + EXPECT_EQ(row->avm_main_sel_op_sub, FF(1)); + EXPECT_EQ(alu_row->avm_alu_alu_op_sub, FF(1)); return *alu_row; } @@ -110,11 +110,11 @@ size_t common_validate_mul(std::vector const& trace, avm_trace::AvmMemoryTag const tag) { // Find the first row enabling the multiplication selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_mul == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == FF(1); }); // Find the corresponding Alu trace row - auto clk = row->avmMini_clk; - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.aluChip_alu_clk == clk; }); + auto clk = row->avm_main_clk; + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_alu_clk == clk; }); // Check that both rows were found EXPECT_TRUE(row != trace.end()); @@ -123,8 +123,8 @@ size_t common_validate_mul(std::vector const& trace, common_validate_arithmetic_op(*row, *alu_row, a, b, c, addr_a, addr_b, addr_c, tag); // Check that multiplication selector is set. - EXPECT_EQ(row->avmMini_sel_op_mul, FF(1)); - EXPECT_EQ(alu_row->aluChip_alu_op_mul, FF(1)); + EXPECT_EQ(row->avm_main_sel_op_mul, FF(1)); + EXPECT_EQ(alu_row->avm_alu_alu_op_mul, FF(1)); return static_cast(alu_row - trace.begin()); } @@ -134,14 +134,14 @@ size_t common_validate_mul(std::vector const& trace, // and the memory and alu trace are created consistently with the wrong value c_mutated. std::vector gen_mutated_trace_add(FF const& a, FF const& b, FF const& c_mutated, avm_trace::AvmMemoryTag tag) { - auto trace_builder = avm_trace::AvmMiniTraceBuilder(); + auto trace_builder = avm_trace::AvmTraceBuilder(); trace_builder.set(uint128_t{ a }, 0, tag); trace_builder.set(uint128_t{ b }, 1, tag); trace_builder.op_add(0, 1, 2, tag); trace_builder.halt(); auto trace = trace_builder.finalize(); - auto select_row = [](Row r) { return r.avmMini_sel_op_add == FF(1); }; + auto select_row = [](Row r) { return r.avm_main_sel_op_add == FF(1); }; mutate_ic_in_trace(trace, select_row, c_mutated, true); return trace; @@ -152,14 +152,14 @@ std::vector gen_mutated_trace_add(FF const& a, FF const& b, FF const& c_mut // and the memory and alu trace are created consistently with the wrong value c_mutated. std::vector gen_mutated_trace_sub(FF const& a, FF const& b, FF const& c_mutated, avm_trace::AvmMemoryTag tag) { - auto trace_builder = avm_trace::AvmMiniTraceBuilder(); + auto trace_builder = avm_trace::AvmTraceBuilder(); trace_builder.set(uint128_t{ a }, 0, tag); trace_builder.set(uint128_t{ b }, 1, tag); trace_builder.op_sub(0, 1, 2, tag); trace_builder.halt(); auto trace = trace_builder.finalize(); - auto select_row = [](Row r) { return r.avmMini_sel_op_sub == FF(1); }; + auto select_row = [](Row r) { return r.avm_main_sel_op_sub == FF(1); }; mutate_ic_in_trace(trace, select_row, c_mutated, true); return trace; @@ -170,14 +170,14 @@ std::vector gen_mutated_trace_sub(FF const& a, FF const& b, FF const& c_mut // and the memory and alu trace are created consistently with the wrong value c_mutated. std::vector gen_mutated_trace_mul(FF const& a, FF const& b, FF const& c_mutated, avm_trace::AvmMemoryTag tag) { - auto trace_builder = avm_trace::AvmMiniTraceBuilder(); + auto trace_builder = avm_trace::AvmTraceBuilder(); trace_builder.set(uint128_t{ a }, 0, tag); trace_builder.set(uint128_t{ b }, 1, tag); trace_builder.op_mul(0, 1, 2, tag); trace_builder.halt(); auto trace = trace_builder.finalize(); - auto select_row = [](Row r) { return r.avmMini_sel_op_mul == FF(1); }; + auto select_row = [](Row r) { return r.avm_main_sel_op_mul == FF(1); }; mutate_ic_in_trace(trace, select_row, c_mutated, true); return trace; @@ -188,32 +188,32 @@ std::vector gen_mutated_trace_mul(FF const& a, FF const& b, FF const& c_mut namespace tests_avm { using namespace avm_trace; -class AvmMiniArithmeticTests : public ::testing::Test { +class AvmArithmeticTests : public ::testing::Test { public: - AvmMiniTraceBuilder trace_builder; + AvmTraceBuilder trace_builder; protected: // TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialised for every test. void SetUp() override { srs::init_crs_factory("../srs_db/ignition"); - trace_builder = AvmMiniTraceBuilder(); // Clean instance for every run. + trace_builder = AvmTraceBuilder(); // Clean instance for every run. }; }; -class AvmMiniArithmeticTestsFF : public AvmMiniArithmeticTests {}; -class AvmMiniArithmeticTestsU8 : public AvmMiniArithmeticTests {}; -class AvmMiniArithmeticTestsU16 : public AvmMiniArithmeticTests {}; -class AvmMiniArithmeticTestsU32 : public AvmMiniArithmeticTests {}; -class AvmMiniArithmeticTestsU64 : public AvmMiniArithmeticTests {}; -class AvmMiniArithmeticTestsU128 : public AvmMiniArithmeticTests {}; +class AvmArithmeticTestsFF : public AvmArithmeticTests {}; +class AvmArithmeticTestsU8 : public AvmArithmeticTests {}; +class AvmArithmeticTestsU16 : public AvmArithmeticTests {}; +class AvmArithmeticTestsU32 : public AvmArithmeticTests {}; +class AvmArithmeticTestsU64 : public AvmArithmeticTests {}; +class AvmArithmeticTestsU128 : public AvmArithmeticTests {}; -class AvmMiniArithmeticNegativeTestsFF : public AvmMiniArithmeticTests {}; -class AvmMiniArithmeticNegativeTestsU8 : public AvmMiniArithmeticTests {}; -class AvmMiniArithmeticNegativeTestsU16 : public AvmMiniArithmeticTests {}; -class AvmMiniArithmeticNegativeTestsU32 : public AvmMiniArithmeticTests {}; -class AvmMiniArithmeticNegativeTestsU64 : public AvmMiniArithmeticTests {}; -class AvmMiniArithmeticNegativeTestsU128 : public AvmMiniArithmeticTests {}; +class AvmArithmeticNegativeTestsFF : public AvmArithmeticTests {}; +class AvmArithmeticNegativeTestsU8 : public AvmArithmeticTests {}; +class AvmArithmeticNegativeTestsU16 : public AvmArithmeticTests {}; +class AvmArithmeticNegativeTestsU32 : public AvmArithmeticTests {}; +class AvmArithmeticNegativeTestsU64 : public AvmArithmeticTests {}; +class AvmArithmeticNegativeTestsU128 : public AvmArithmeticTests {}; /****************************************************************************** * @@ -244,7 +244,7 @@ class AvmMiniArithmeticNegativeTestsU128 : public AvmMiniArithmeticTests {}; ******************************************************************************/ // Test on basic addition over finite field type. -TEST_F(AvmMiniArithmeticTestsFF, addition) +TEST_F(AvmArithmeticTestsFF, addition) { // trace_builder trace_builder.calldata_copy(0, 3, 0, std::vector{ 37, 4, 11 }); @@ -256,15 +256,15 @@ TEST_F(AvmMiniArithmeticTestsFF, addition) auto alu_row = common_validate_add(trace, FF(37), FF(4), FF(41), FF(0), FF(1), FF(4), AvmMemoryTag::FF); - EXPECT_EQ(alu_row.aluChip_alu_ff_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_ff_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0)); validate_trace_proof(std::move(trace)); } // Test on basic subtraction over finite field type. -TEST_F(AvmMiniArithmeticTestsFF, subtraction) +TEST_F(AvmArithmeticTestsFF, subtraction) { trace_builder.calldata_copy(0, 3, 0, std::vector{ 8, 4, 17 }); @@ -275,15 +275,15 @@ TEST_F(AvmMiniArithmeticTestsFF, subtraction) auto alu_row = common_validate_sub(trace, FF(17), FF(8), FF(9), FF(2), FF(0), FF(1), AvmMemoryTag::FF); - EXPECT_EQ(alu_row.aluChip_alu_ff_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_ff_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0)); validate_trace_proof(std::move(trace)); } // Test on basic multiplication over finite field type. -TEST_F(AvmMiniArithmeticTestsFF, multiplication) +TEST_F(AvmArithmeticTestsFF, multiplication) { trace_builder.calldata_copy(0, 3, 0, std::vector{ 5, 0, 20 }); @@ -295,15 +295,15 @@ TEST_F(AvmMiniArithmeticTestsFF, multiplication) auto alu_row_index = common_validate_mul(trace, FF(20), FF(5), FF(100), FF(2), FF(0), FF(1), AvmMemoryTag::FF); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.aluChip_alu_ff_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_ff_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0)); validate_trace_proof(std::move(trace)); } // Test on multiplication by zero over finite field type. -TEST_F(AvmMiniArithmeticTestsFF, multiplicationByZero) +TEST_F(AvmArithmeticTestsFF, multiplicationByZero) { trace_builder.calldata_copy(0, 1, 0, std::vector{ 127 }); @@ -315,15 +315,15 @@ TEST_F(AvmMiniArithmeticTestsFF, multiplicationByZero) auto alu_row_index = common_validate_mul(trace, FF(127), FF(0), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::FF); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.aluChip_alu_ff_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_ff_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0)); validate_trace_proof(std::move(trace)); } // Test on basic division over finite field type. -TEST_F(AvmMiniArithmeticTestsFF, division) +TEST_F(AvmArithmeticTestsFF, division) { trace_builder.calldata_copy(0, 2, 0, std::vector{ 15, 315 }); @@ -333,20 +333,20 @@ TEST_F(AvmMiniArithmeticTestsFF, division) auto trace = trace_builder.finalize(); // Find the first row enabling the division selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_div == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_div == FF(1); }); // Check that the correct result is stored at the expected memory location. EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avmMini_ic, FF(21)); - EXPECT_EQ(row->avmMini_mem_idx_c, FF(2)); - EXPECT_EQ(row->avmMini_mem_op_c, FF(1)); - EXPECT_EQ(row->avmMini_rwc, FF(1)); + EXPECT_EQ(row->avm_main_ic, FF(21)); + EXPECT_EQ(row->avm_main_mem_idx_c, FF(2)); + EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); + EXPECT_EQ(row->avm_main_rwc, FF(1)); validate_trace_proof(std::move(trace)); } // Test on division with zero numerator over finite field type. -TEST_F(AvmMiniArithmeticTestsFF, divisionNumeratorZero) +TEST_F(AvmArithmeticTestsFF, divisionNumeratorZero) { trace_builder.calldata_copy(0, 1, 0, std::vector{ 15 }); @@ -356,21 +356,21 @@ TEST_F(AvmMiniArithmeticTestsFF, divisionNumeratorZero) auto trace = trace_builder.finalize(); // Find the first row enabling the division selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_div == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_div == FF(1); }); // Check that the correct result is stored at the expected memory location. EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avmMini_ic, FF(0)); - EXPECT_EQ(row->avmMini_mem_idx_c, FF(0)); - EXPECT_EQ(row->avmMini_mem_op_c, FF(1)); - EXPECT_EQ(row->avmMini_rwc, FF(1)); + EXPECT_EQ(row->avm_main_ic, FF(0)); + EXPECT_EQ(row->avm_main_mem_idx_c, FF(0)); + EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); + EXPECT_EQ(row->avm_main_rwc, FF(1)); validate_trace_proof(std::move(trace)); } // Test on division by zero over finite field type. // We check that the operator error flag is raised. -TEST_F(AvmMiniArithmeticTestsFF, divisionByZeroError) +TEST_F(AvmArithmeticTestsFF, divisionByZeroError) { trace_builder.calldata_copy(0, 1, 0, std::vector{ 15 }); @@ -380,22 +380,22 @@ TEST_F(AvmMiniArithmeticTestsFF, divisionByZeroError) auto trace = trace_builder.finalize(); // Find the first row enabling the division selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_div == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_div == FF(1); }); // Check that the correct result is stored at the expected memory location. EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avmMini_ic, FF(0)); - EXPECT_EQ(row->avmMini_mem_idx_c, FF(2)); - EXPECT_EQ(row->avmMini_mem_op_c, FF(1)); - EXPECT_EQ(row->avmMini_rwc, FF(1)); - EXPECT_EQ(row->avmMini_op_err, FF(1)); + EXPECT_EQ(row->avm_main_ic, FF(0)); + EXPECT_EQ(row->avm_main_mem_idx_c, FF(2)); + EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); + EXPECT_EQ(row->avm_main_rwc, FF(1)); + EXPECT_EQ(row->avm_main_op_err, FF(1)); validate_trace_proof(std::move(trace)); } // Test on division of zero by zero over finite field type. // We check that the operator error flag is raised. -TEST_F(AvmMiniArithmeticTestsFF, divisionZeroByZeroError) +TEST_F(AvmArithmeticTestsFF, divisionZeroByZeroError) { // Memory layout: [0,0,0,0,0,0,....] trace_builder.op_div(0, 1, 2, AvmMemoryTag::FF); // [0,0,0,0,0,0....] @@ -403,15 +403,15 @@ TEST_F(AvmMiniArithmeticTestsFF, divisionZeroByZeroError) auto trace = trace_builder.finalize(); // Find the first row enabling the division selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_div == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_div == FF(1); }); // Check that the correct result is stored at the expected memory location. EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avmMini_ic, FF(0)); - EXPECT_EQ(row->avmMini_mem_idx_c, FF(2)); - EXPECT_EQ(row->avmMini_mem_op_c, FF(1)); - EXPECT_EQ(row->avmMini_rwc, FF(1)); - EXPECT_EQ(row->avmMini_op_err, FF(1)); + EXPECT_EQ(row->avm_main_ic, FF(0)); + EXPECT_EQ(row->avm_main_mem_idx_c, FF(2)); + EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); + EXPECT_EQ(row->avm_main_rwc, FF(1)); + EXPECT_EQ(row->avm_main_op_err, FF(1)); validate_trace_proof(std::move(trace)); } @@ -420,7 +420,7 @@ TEST_F(AvmMiniArithmeticTestsFF, divisionZeroByZeroError) // and finishing with a division by zero. The chosen combination is arbitrary. // We only test that the proof can be correctly generated and verified. // No check on the evaluation is performed here. -TEST_F(AvmMiniArithmeticTestsFF, mixedOperationsWithError) +TEST_F(AvmArithmeticTestsFF, mixedOperationsWithError) { trace_builder.calldata_copy(0, 3, 2, std::vector{ 45, 23, 12 }); @@ -446,7 +446,7 @@ TEST_F(AvmMiniArithmeticTestsFF, mixedOperationsWithError) ******************************************************************************/ // Test on basic addition over u8 type. -TEST_F(AvmMiniArithmeticTestsU8, addition) +TEST_F(AvmArithmeticTestsU8, addition) { // trace_builder trace_builder.set(62, 0, AvmMemoryTag::U8); @@ -459,14 +459,14 @@ TEST_F(AvmMiniArithmeticTestsU8, addition) auto alu_row = common_validate_add(trace, FF(62), FF(29), FF(91), FF(0), FF(1), FF(2), AvmMemoryTag::U8); - EXPECT_EQ(alu_row.aluChip_alu_u8_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(91)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(91)); validate_trace_proof(std::move(trace)); } // Test on basic addition over u8 type with carry. -TEST_F(AvmMiniArithmeticTestsU8, additionCarry) +TEST_F(AvmArithmeticTestsU8, additionCarry) { // trace_builder trace_builder.set(159, 0, AvmMemoryTag::U8); @@ -479,16 +479,16 @@ TEST_F(AvmMiniArithmeticTestsU8, additionCarry) auto alu_row = common_validate_add(trace, FF(159), FF(100), FF(3), FF(0), FF(1), FF(2), AvmMemoryTag::U8); - EXPECT_EQ(alu_row.aluChip_alu_u8_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(3)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(3)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(1)); validate_trace_proof(std::move(trace)); } // Test on basic subtraction over u8 type. -TEST_F(AvmMiniArithmeticTestsU8, subtraction) +TEST_F(AvmArithmeticTestsU8, subtraction) { // trace_builder trace_builder.set(162, 0, AvmMemoryTag::U8); @@ -501,16 +501,16 @@ TEST_F(AvmMiniArithmeticTestsU8, subtraction) auto alu_row = common_validate_sub(trace, FF(162), FF(29), FF(133), FF(0), FF(1), FF(2), AvmMemoryTag::U8); - EXPECT_EQ(alu_row.aluChip_alu_u8_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(133)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(133)); validate_trace_proof(std::move(trace)); } // Test on subtraction over u8 type with carry. // For a subtraction a - b = c, there is a carry flag iff a < b (equivalent to a < c) -TEST_F(AvmMiniArithmeticTestsU8, subtractionCarry) +TEST_F(AvmArithmeticTestsU8, subtractionCarry) { // trace_builder trace_builder.set(5, 0, AvmMemoryTag::U8); @@ -523,23 +523,23 @@ TEST_F(AvmMiniArithmeticTestsU8, subtractionCarry) auto alu_row = common_validate_sub(trace, FF(5), FF(29), FF(232), FF(0), FF(1), FF(2), AvmMemoryTag::U8); - EXPECT_EQ(alu_row.aluChip_alu_u8_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(232)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(UINT8_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(232)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(UINT8_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r3, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r6, FF(UINT16_MAX)); validate_trace_proof(std::move(trace)); } // Test on basic multiplication over u8 type. -TEST_F(AvmMiniArithmeticTestsU8, multiplication) +TEST_F(AvmArithmeticTestsU8, multiplication) { // trace_builder trace_builder.set(13, 0, AvmMemoryTag::U8); @@ -552,17 +552,17 @@ TEST_F(AvmMiniArithmeticTestsU8, multiplication) auto alu_row_index = common_validate_mul(trace, FF(13), FF(15), FF(195), FF(0), FF(1), FF(2), AvmMemoryTag::U8); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.aluChip_alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_tag, FF(1)); // Decomposition of integer multiplication in 8-bit registers - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(195)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(195)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0)); validate_trace_proof(std::move(trace)); } // Test on multiplication over u8 type with overflow. -TEST_F(AvmMiniArithmeticTestsU8, multiplicationOverflow) +TEST_F(AvmArithmeticTestsU8, multiplicationOverflow) { // trace_builder trace_builder.set(200, 0, AvmMemoryTag::U8); @@ -575,12 +575,12 @@ TEST_F(AvmMiniArithmeticTestsU8, multiplicationOverflow) auto alu_row_index = common_validate_mul(trace, FF(200), FF(170), FF(208), FF(0), FF(1), FF(2), AvmMemoryTag::U8); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.aluChip_alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_tag, FF(1)); // Decomposition of integer multiplication in 8-bit registers // 34'000 = 208 + 132 * 256 - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(208)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(132)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(208)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(132)); validate_trace_proof(std::move(trace)); } @@ -590,7 +590,7 @@ TEST_F(AvmMiniArithmeticTestsU8, multiplicationOverflow) ******************************************************************************/ // Test on basic addition over u16 type. -TEST_F(AvmMiniArithmeticTestsU16, addition) +TEST_F(AvmArithmeticTestsU16, addition) { // trace_builder trace_builder.set(1775, 119, AvmMemoryTag::U16); @@ -603,16 +603,16 @@ TEST_F(AvmMiniArithmeticTestsU16, addition) auto alu_row = common_validate_add(trace, FF(33005), FF(1775), FF(34780), FF(546), FF(119), FF(5), AvmMemoryTag::U16); - EXPECT_EQ(alu_row.aluChip_alu_u16_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0xDC)); // 34780 = 0x87DC - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0x87)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0xDC)); // 34780 = 0x87DC + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0x87)); validate_trace_proof(std::move(trace)); } // Test on basic addition over u16 type with carry. -TEST_F(AvmMiniArithmeticTestsU16, additionCarry) +TEST_F(AvmArithmeticTestsU16, additionCarry) { // trace_builder trace_builder.set(UINT16_MAX - 982, 0, AvmMemoryTag::U16); @@ -625,16 +625,16 @@ TEST_F(AvmMiniArithmeticTestsU16, additionCarry) auto alu_row = common_validate_add(trace, FF(1000), FF(UINT16_MAX - 982), FF(17), FF(1), FF(0), FF(0), AvmMemoryTag::U16); - EXPECT_EQ(alu_row.aluChip_alu_u16_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(17)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(17)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0)); validate_trace_proof(std::move(trace)); } // Test on basic subtraction over u16 type. -TEST_F(AvmMiniArithmeticTestsU16, subtraction) +TEST_F(AvmArithmeticTestsU16, subtraction) { // trace_builder trace_builder.set(1775, 119, AvmMemoryTag::U16); @@ -647,18 +647,18 @@ TEST_F(AvmMiniArithmeticTestsU16, subtraction) auto alu_row = common_validate_sub(trace, FF(33005), FF(1775), FF(31230), FF(546), FF(119), FF(5), AvmMemoryTag::U16); - EXPECT_EQ(alu_row.aluChip_alu_u16_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0xFE)); // 31230 in Hex: 79FE - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0x79)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0xFE)); // 31230 in Hex: 79FE + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0x79)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0)); validate_trace_proof(std::move(trace)); } // Test on basic subtraction over u16 type with carry. // For a subtraction a - b = c, there is a carry flag iff a < b (equivalent to a < c) -TEST_F(AvmMiniArithmeticTestsU16, subtractionCarry) +TEST_F(AvmArithmeticTestsU16, subtractionCarry) { // trace_builder trace_builder.set(UINT16_MAX - 982, 0, AvmMemoryTag::U16); @@ -671,23 +671,23 @@ TEST_F(AvmMiniArithmeticTestsU16, subtractionCarry) auto alu_row = common_validate_sub(trace, FF(1000), FF(UINT16_MAX - 982), FF(1983), FF(1), FF(0), FF(0), AvmMemoryTag::U16); - EXPECT_EQ(alu_row.aluChip_alu_u16_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0xBF)); // 1983 = 0x7BF - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(7)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0xBF)); // 1983 = 0x7BF + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(7)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r3, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r6, FF(UINT16_MAX)); validate_trace_proof(std::move(trace)); } // Test on basic multiplication over u16 type. -TEST_F(AvmMiniArithmeticTestsU16, multiplication) +TEST_F(AvmArithmeticTestsU16, multiplication) { // trace_builder trace_builder.set(200, 0, AvmMemoryTag::U16); @@ -701,18 +701,18 @@ TEST_F(AvmMiniArithmeticTestsU16, multiplication) common_validate_mul(trace, FF(200), FF(245), FF(49000), FF(0), FF(1), FF(2), AvmMemoryTag::U16); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.aluChip_alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_tag, FF(1)); // Decomposition of integer multiplication in 8-bit and 16-bit registers - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0x68)); // 49000 = 0xBF68 - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0xBF)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0x68)); // 49000 = 0xBF68 + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0xBF)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0)); validate_trace_proof(std::move(trace)); } // Test on multiplication over u16 type with overflow. -TEST_F(AvmMiniArithmeticTestsU16, multiplicationOverflow) +TEST_F(AvmArithmeticTestsU16, multiplicationOverflow) { // trace_builder trace_builder.set(512, 0, AvmMemoryTag::U16); @@ -725,14 +725,14 @@ TEST_F(AvmMiniArithmeticTestsU16, multiplicationOverflow) auto alu_row_index = common_validate_mul(trace, FF(512), FF(1024), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::U16); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.aluChip_alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_tag, FF(1)); // Decomposition of integer multiplication in 8-bit and 16-bit registers // 512 * 1024 = 0 + 8 * 2^16 - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(8)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(8)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(0)); validate_trace_proof(std::move(trace)); } @@ -742,7 +742,7 @@ TEST_F(AvmMiniArithmeticTestsU16, multiplicationOverflow) ******************************************************************************/ // Test on basic addition over u32 type. -TEST_F(AvmMiniArithmeticTestsU32, addition) +TEST_F(AvmArithmeticTestsU32, addition) { // trace_builder trace_builder.set(1000000000, 8, AvmMemoryTag::U32); @@ -755,17 +755,17 @@ TEST_F(AvmMiniArithmeticTestsU32, addition) auto alu_row = common_validate_add( trace, FF(1000000000), FF(1234567891), FF(2234567891LLU), FF(8), FF(9), FF(0), AvmMemoryTag::U32); - EXPECT_EQ(alu_row.aluChip_alu_u32_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(2234567891LLU & UINT8_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF((2234567891LLU >> 8) & UINT8_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(2234567891LLU >> 16)); + EXPECT_EQ(alu_row.avm_alu_alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(2234567891LLU & UINT8_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF((2234567891LLU >> 8) & UINT8_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(2234567891LLU >> 16)); validate_trace_proof(std::move(trace)); } // Test on basic addition over u32 type with carry. -TEST_F(AvmMiniArithmeticTestsU32, additionCarry) +TEST_F(AvmArithmeticTestsU32, additionCarry) { // trace_builder trace_builder.set(UINT32_MAX - 1293, 8, AvmMemoryTag::U32); @@ -778,16 +778,16 @@ TEST_F(AvmMiniArithmeticTestsU32, additionCarry) auto alu_row = common_validate_add(trace, FF(UINT32_MAX - 1293), FF(2293), FF(999), FF(8), FF(9), FF(0), AvmMemoryTag::U32); - EXPECT_EQ(alu_row.aluChip_alu_u32_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(231)); // 999 = 3 * 256 + 231 - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(3)); + EXPECT_EQ(alu_row.avm_alu_alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(231)); // 999 = 3 * 256 + 231 + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(3)); validate_trace_proof(std::move(trace)); } // Test on basic subtraction over u32 type. -TEST_F(AvmMiniArithmeticTestsU32, subtraction) +TEST_F(AvmArithmeticTestsU32, subtraction) { // trace_builder trace_builder.set(1345678991, 8, AvmMemoryTag::U32); @@ -800,21 +800,21 @@ TEST_F(AvmMiniArithmeticTestsU32, subtraction) auto alu_row = common_validate_sub( trace, FF(1345678991), FF(1234567891), FF(111111100), FF(8), FF(9), FF(0), AvmMemoryTag::U32); - EXPECT_EQ(alu_row.aluChip_alu_u32_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); // 111111100 = 0x69F6BBC - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0xBC)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0x6B)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0x69F)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0xBC)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0x6B)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0x69F)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(0)); validate_trace_proof(std::move(trace)); } // Test on basic subtraction over u32 type with carry. // For a subtraction a - b = c, there is a carry flag iff a < b (equivalent to a < c) -TEST_F(AvmMiniArithmeticTestsU32, subtractionCarry) +TEST_F(AvmArithmeticTestsU32, subtractionCarry) { // trace_builder trace_builder.set(UINT32_MAX - 99, 8, AvmMemoryTag::U32); @@ -827,25 +827,25 @@ TEST_F(AvmMiniArithmeticTestsU32, subtractionCarry) auto alu_row = common_validate_sub( trace, FF(3210987654LLU), FF(UINT32_MAX - 99), FF(3210987754LLU), FF(9), FF(8), FF(0), AvmMemoryTag::U32); - EXPECT_EQ(alu_row.aluChip_alu_u32_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(1)); // 3210987754 = 0xBF63C8EA - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0xEA)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0xC8)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0xBF63)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0xEA)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0xC8)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0xBF63)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r3, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r6, FF(UINT16_MAX)); validate_trace_proof(std::move(trace)); } // Test on basic multiplication over u32 type. -TEST_F(AvmMiniArithmeticTestsU32, multiplication) +TEST_F(AvmArithmeticTestsU32, multiplication) { // trace_builder trace_builder.set(11111, 0, AvmMemoryTag::U32); @@ -859,22 +859,22 @@ TEST_F(AvmMiniArithmeticTestsU32, multiplication) common_validate_mul(trace, FF(11111), FF(11111), FF(123454321), FF(0), FF(1), FF(2), AvmMemoryTag::U32); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.aluChip_alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u32_tag, FF(1)); // Decomposition of integer multiplication in 8-bit and 16-bit registers // 123454321 = 0x75BC371 - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0x71)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0xC3)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0x75B)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0x71)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0xC3)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0x75B)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r3, FF(0)); validate_trace_proof(std::move(trace)); } // Test on multiplication over u32 type with overflow. -TEST_F(AvmMiniArithmeticTestsU32, multiplicationOverflow) +TEST_F(AvmArithmeticTestsU32, multiplicationOverflow) { // trace_builder trace_builder.set(11 << 25, 0, AvmMemoryTag::U32); @@ -888,16 +888,16 @@ TEST_F(AvmMiniArithmeticTestsU32, multiplicationOverflow) common_validate_mul(trace, FF(11 << 25), FF(13 << 22), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::U32); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.aluChip_alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u32_tag, FF(1)); // Decomposition of integer multiplication in 8-bit and 16-bit registers // 143 * 2^47 = 0 + 0 * 2^16 + 2^15 * 2^32 + 71 * 2^48 - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(32768)); // 2^15 - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(71)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(32768)); // 2^15 + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(71)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r3, FF(0)); validate_trace_proof(std::move(trace)); } @@ -907,7 +907,7 @@ TEST_F(AvmMiniArithmeticTestsU32, multiplicationOverflow) ******************************************************************************/ // Test on basic addition over u64 type. -TEST_F(AvmMiniArithmeticTestsU64, addition) +TEST_F(AvmArithmeticTestsU64, addition) { uint64_t const a = 7813981340746672LLU; uint64_t const b = 2379061066771309LLU; @@ -923,21 +923,21 @@ TEST_F(AvmMiniArithmeticTestsU64, addition) auto alu_row = common_validate_add(trace, FF(a), FF(b), FF(c), FF(8), FF(9), FF(9), AvmMemoryTag::U64); - EXPECT_EQ(alu_row.aluChip_alu_u64_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); // c in HEX: 2436849FE16F1D - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0x1D)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0x6F)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0x9FE1)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0x3684)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0x24)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0x1D)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0x6F)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0x9FE1)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(0x3684)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(0x24)); validate_trace_proof(std::move(trace)); } // Test on basic addition over u64 type with carry. -TEST_F(AvmMiniArithmeticTestsU64, additionCarry) +TEST_F(AvmArithmeticTestsU64, additionCarry) { uint64_t const a = UINT64_MAX - 77LLU; uint64_t const b = UINT64_MAX - 123LLU; @@ -953,19 +953,19 @@ TEST_F(AvmMiniArithmeticTestsU64, additionCarry) auto alu_row = common_validate_add(trace, FF(a), FF(b), FF(c), FF(0), FF(1), FF(0), AvmMemoryTag::U64); - EXPECT_EQ(alu_row.aluChip_alu_u64_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(UINT8_MAX - 201)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(UINT8_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(UINT8_MAX - 201)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(UINT8_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(UINT16_MAX)); validate_trace_proof(std::move(trace)); } // Test on basic subtraction over u64 type. -TEST_F(AvmMiniArithmeticTestsU64, subtraction) +TEST_F(AvmArithmeticTestsU64, subtraction) { uint64_t const a = 9876543210123456789LLU; uint64_t const b = 9866543210123456789LLU; @@ -981,23 +981,23 @@ TEST_F(AvmMiniArithmeticTestsU64, subtraction) auto alu_row = common_validate_sub(trace, FF(a), FF(b), FF(c), FF(8), FF(9), FF(9), AvmMemoryTag::U64); - EXPECT_EQ(alu_row.aluChip_alu_u64_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); // 10000000000000000 = 0x2386F26FC10000 - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0X6FC1)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0X86F2)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0X23)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0X6FC1)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(0X86F2)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(0X23)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r3, FF(0)); validate_trace_proof(std::move(trace)); } // Test on basic subtraction over u64 type with carry. // For a subtraction a - b = c, there is a carry flag iff a < b (equivalent to a < c) -TEST_F(AvmMiniArithmeticTestsU64, subtractionCarry) +TEST_F(AvmArithmeticTestsU64, subtractionCarry) { uint64_t const a = UINT64_MAX - 77LLU; uint64_t const b = UINT64_MAX - 2LLU; @@ -1013,23 +1013,23 @@ TEST_F(AvmMiniArithmeticTestsU64, subtractionCarry) auto alu_row = common_validate_sub(trace, FF(a), FF(b), FF(c), FF(0), FF(1), FF(0), AvmMemoryTag::U64); - EXPECT_EQ(alu_row.aluChip_alu_u64_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(1)); - - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(UINT8_MAX - 74)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(UINT8_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(1)); + + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(UINT8_MAX - 74)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(UINT8_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r3, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r6, FF(UINT16_MAX)); validate_trace_proof(std::move(trace)); } // Test on basic multiplication over u64 type. -TEST_F(AvmMiniArithmeticTestsU64, multiplication) +TEST_F(AvmArithmeticTestsU64, multiplication) { // trace_builder trace_builder.set(999888777, 0, AvmMemoryTag::U64); @@ -1043,22 +1043,22 @@ TEST_F(AvmMiniArithmeticTestsU64, multiplication) trace, FF(999888777), FF(555444333), FF(555382554814950741LLU), FF(0), FF(1), FF(2), AvmMemoryTag::U64); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.aluChip_alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u64_tag, FF(1)); // Decomposition of integer multiplication in 8-bit and 16-bit registers // 555,382,554,814,950,741 = 0x 7B5 1D7D B631 AD55 - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0x55)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0xAD)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0xB631)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0x1D7D)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0x7B5)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0x55)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0xAD)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0xB631)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(0x1D7D)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(0x7B5)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r3, FF(0)); validate_trace_proof(std::move(trace)); } // Test on multiplication over u64 type with overflow. -TEST_F(AvmMiniArithmeticTestsU64, multiplicationOverflow) +TEST_F(AvmArithmeticTestsU64, multiplicationOverflow) { uint64_t const a = UINT64_MAX; uint64_t const b = UINT64_MAX; @@ -1075,19 +1075,19 @@ TEST_F(AvmMiniArithmeticTestsU64, multiplicationOverflow) auto alu_row_index = common_validate_mul(trace, FF(a), FF(b), FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::U64); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.aluChip_alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u64_tag, FF(1)); // Decomposition of integer multiplication in 8-bit and 16-bit registers // 2^128 - 2^65 + 1 - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(UINT16_MAX - 1)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r3, FF(UINT16_MAX - 1)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r6, FF(UINT16_MAX)); validate_trace_proof(std::move(trace)); } @@ -1097,7 +1097,7 @@ TEST_F(AvmMiniArithmeticTestsU64, multiplicationOverflow) ******************************************************************************/ // Test on basic addition over u128 type. -TEST_F(AvmMiniArithmeticTestsU128, addition) +TEST_F(AvmArithmeticTestsU128, addition) { uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; uint128_t const b = (uint128_t{ 0x3333222233331111LLU } << 64) + uint128_t{ 0x5555111155553333LLU }; @@ -1120,23 +1120,23 @@ TEST_F(AvmMiniArithmeticTestsU128, addition) FF(9), AvmMemoryTag::U128); - EXPECT_EQ(alu_row.aluChip_alu_u128_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0xEE)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0xEE)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0xFFFF)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0xAAAA)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0xDDDD)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0x5555)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(0x6666)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(0x4444)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(0x8888)); + EXPECT_EQ(alu_row.avm_alu_alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0xEE)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0xEE)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0xFFFF)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(0xAAAA)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(0xDDDD)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r3, FF(0x5555)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r4, FF(0x6666)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r5, FF(0x4444)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r6, FF(0x8888)); validate_trace_proof(std::move(trace)); } // Test on basic addition over u128 type with carry. -TEST_F(AvmMiniArithmeticTestsU128, additionCarry) +TEST_F(AvmArithmeticTestsU128, additionCarry) { uint128_t const a = (uint128_t{ UINT64_MAX } << 64) + uint128_t{ UINT64_MAX } - uint128_t{ 72948899 }; uint128_t const b = (uint128_t{ UINT64_MAX } << 64) + uint128_t{ UINT64_MAX } - uint128_t{ 36177344 }; @@ -1160,23 +1160,23 @@ TEST_F(AvmMiniArithmeticTestsU128, additionCarry) FF(9), AvmMemoryTag::U128); - EXPECT_EQ(alu_row.aluChip_alu_u128_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0x9B)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0xDD)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0xF97E)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0xFFFF)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0xFFFF)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0xFFFF)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(0xFFFF)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(0xFFFF)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(0xFFFF)); + EXPECT_EQ(alu_row.avm_alu_alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0x9B)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0xDD)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0xF97E)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(0xFFFF)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(0xFFFF)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r3, FF(0xFFFF)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r4, FF(0xFFFF)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r5, FF(0xFFFF)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r6, FF(0xFFFF)); validate_trace_proof(std::move(trace)); } // Test on basic subtraction over u128 type. -TEST_F(AvmMiniArithmeticTestsU128, subtraction) +TEST_F(AvmArithmeticTestsU128, subtraction) { uint128_t const a = (uint128_t{ UINT64_MAX } << 64) + uint128_t{ UINT64_MAX } - uint128_t{ 36177344 }; uint128_t const b = (uint128_t{ UINT64_MAX } << 64) + uint128_t{ UINT64_MAX } - uint128_t{ 72948899 }; @@ -1199,26 +1199,26 @@ TEST_F(AvmMiniArithmeticTestsU128, subtraction) FF(9), AvmMemoryTag::U128); - EXPECT_EQ(alu_row.aluChip_alu_u128_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); // 36771555 = 23116E3 - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0xE3)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0x16)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0x231)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r7, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0xE3)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0x16)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0x231)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r3, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r4, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r5, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r6, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r7, FF(0)); validate_trace_proof(std::move(trace)); } // Test on basic subtraction over u128 type with carry. -TEST_F(AvmMiniArithmeticTestsU128, subtractionCarry) +TEST_F(AvmArithmeticTestsU128, subtractionCarry) { uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; uint128_t const b = (uint128_t{ 0x3333222233331111LLU } << 64) + uint128_t{ 0x5555111155553333LLU }; @@ -1241,24 +1241,24 @@ TEST_F(AvmMiniArithmeticTestsU128, subtractionCarry) FF(9), AvmMemoryTag::U128); - EXPECT_EQ(alu_row.aluChip_alu_u128_tag, FF(1)); - EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0x88)); - EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0x88)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0x5555)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0x8888)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0x3333)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0x3333)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(0x2222)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(0x88)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_r1, FF(0x88)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r0, FF(0x5555)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r1, FF(0x8888)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r2, FF(0x3333)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r3, FF(0x3333)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r4, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r5, FF(0)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_r6, FF(0x2222)); validate_trace_proof(std::move(trace)); } // Test on basic multiplication over u128 type. -TEST_F(AvmMiniArithmeticTestsU128, multiplication) +TEST_F(AvmArithmeticTestsU128, multiplication) { // trace_builder trace_builder.set(0x38D64BF685FFBLLU, 0, AvmMemoryTag::U128); @@ -1274,25 +1274,25 @@ TEST_F(AvmMiniArithmeticTestsU128, multiplication) trace, FF(0x38D64BF685FFBLLU), FF(555444333222111LLU), c, FF(0), FF(1), FF(2), AvmMemoryTag::U128); auto alu_row_first = trace.at(alu_row_index); - EXPECT_EQ(alu_row_first.aluChip_alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u128_tag, FF(1)); // Decomposition of the first operand in 16-bit registers - EXPECT_EQ(alu_row_first.aluChip_alu_u16_r0, FF(0x5FFB)); - EXPECT_EQ(alu_row_first.aluChip_alu_u16_r1, FF(0xBF68)); - EXPECT_EQ(alu_row_first.aluChip_alu_u16_r2, FF(0x8D64)); - EXPECT_EQ(alu_row_first.aluChip_alu_u16_r3, FF(0x3)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u16_r0, FF(0x5FFB)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u16_r1, FF(0xBF68)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u16_r2, FF(0x8D64)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u16_r3, FF(0x3)); // Decomposition of the second operand in 16-bit registers auto alu_row_second = trace.at(alu_row_index + 1); - EXPECT_EQ(alu_row_second.aluChip_alu_u16_r0, FF(0x98DF)); - EXPECT_EQ(alu_row_second.aluChip_alu_u16_r1, FF(0x762C)); - EXPECT_EQ(alu_row_second.aluChip_alu_u16_r2, FF(0xF92C)); - EXPECT_EQ(alu_row_second.aluChip_alu_u16_r3, FF(0x1)); + EXPECT_EQ(alu_row_second.avm_alu_alu_u16_r0, FF(0x98DF)); + EXPECT_EQ(alu_row_second.avm_alu_alu_u16_r1, FF(0x762C)); + EXPECT_EQ(alu_row_second.avm_alu_alu_u16_r2, FF(0xF92C)); + EXPECT_EQ(alu_row_second.avm_alu_alu_u16_r3, FF(0x1)); validate_trace_proof(std::move(trace)); } // Test on multiplication over u128 type with overflow. -TEST_F(AvmMiniArithmeticTestsU128, multiplicationOverflow) +TEST_F(AvmArithmeticTestsU128, multiplicationOverflow) { // (2^128 - 2) * (2^128 - 4) = 2^256 - 2^130 - 2^129 + 2^3 // The above modulo 2^128 = 8 @@ -1317,36 +1317,36 @@ TEST_F(AvmMiniArithmeticTestsU128, multiplicationOverflow) AvmMemoryTag::U128); auto alu_row_first = trace.at(alu_row_index); - EXPECT_EQ(alu_row_first.aluChip_alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u128_tag, FF(1)); // Decomposition of the first operand in 16-bit registers - EXPECT_EQ(alu_row_first.aluChip_alu_u16_r0, FF(0xFFFE)); - EXPECT_EQ(alu_row_first.aluChip_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.aluChip_alu_u16_r2, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.aluChip_alu_u16_r3, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.aluChip_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.aluChip_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.aluChip_alu_u16_r6, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.aluChip_alu_u16_r7, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u16_r0, FF(0xFFFE)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u16_r3, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u16_r6, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u16_r7, FF(UINT16_MAX)); // Decomposition of the second operand in 16-bit registers auto alu_row_second = trace.at(alu_row_index + 1); - EXPECT_EQ(alu_row_second.aluChip_alu_u16_r0, FF(0xFFFC)); - EXPECT_EQ(alu_row_second.aluChip_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_second.aluChip_alu_u16_r2, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_second.aluChip_alu_u16_r3, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_second.aluChip_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_second.aluChip_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_second.aluChip_alu_u16_r6, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_second.aluChip_alu_u16_r7, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.avm_alu_alu_u16_r0, FF(0xFFFC)); + EXPECT_EQ(alu_row_second.avm_alu_alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.avm_alu_alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.avm_alu_alu_u16_r3, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.avm_alu_alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.avm_alu_alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.avm_alu_alu_u16_r6, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.avm_alu_alu_u16_r7, FF(UINT16_MAX)); // Other registers involved in the relevant relations - // PIL relation (alu_chip.pil): a * b_l + a_l * b_h * 2^64 = (CF * 2^64 + R') * 2^128 + c + // PIL relation (avm_alu.pil): a * b_l + a_l * b_h * 2^64 = (CF * 2^64 + R') * 2^128 + c // (2^128 - 2) * (2^64 - 4) + (2^64 - 2) * (2^64 - 1) * 2^64 = // 2 * 2^192 + (- 4 - 2 - 1) * 2^128 + (-2 + 2) * 2^64 + 8 = (2^65 - 7) * 2^128 + 8 // Therefore, CF = 1 and R' = 2^64 - 7 - EXPECT_EQ(alu_row_first.aluChip_alu_u64_r0, FF{ UINT64_MAX - 6 }); // 2^64 - 7 - EXPECT_EQ(alu_row_first.aluChip_alu_cf, FF(1)); + EXPECT_EQ(alu_row_first.avm_alu_alu_u64_r0, FF{ UINT64_MAX - 6 }); // 2^64 - 7 + EXPECT_EQ(alu_row_first.avm_alu_alu_cf, FF(1)); validate_trace_proof(std::move(trace)); } @@ -1377,28 +1377,28 @@ TEST_F(AvmMiniArithmeticTestsU128, multiplicationOverflow) ******************************************************************************/ // Test on basic incorrect addition over finite field type. -TEST_F(AvmMiniArithmeticNegativeTestsFF, addition) +TEST_F(AvmArithmeticNegativeTestsFF, addition) { auto trace = gen_mutated_trace_add(FF(37), FF(4), FF(40), AvmMemoryTag::FF); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_1"); } // Test on basic incorrect subtraction over finite field type. -TEST_F(AvmMiniArithmeticNegativeTestsFF, subtraction) +TEST_F(AvmArithmeticNegativeTestsFF, subtraction) { auto trace = gen_mutated_trace_sub(FF(17), FF(8), FF(-9), AvmMemoryTag::FF); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_1"); } // Test on basic incorrect multiplication over finite field type. -TEST_F(AvmMiniArithmeticNegativeTestsFF, multiplication) +TEST_F(AvmArithmeticNegativeTestsFF, multiplication) { auto trace = gen_mutated_trace_mul(FF(9), FF(100), FF(9000000), AvmMemoryTag::FF); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MULTIPLICATION_FF"); } // Test on basic incorrect division over finite field type. -TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionFF) +TEST_F(AvmArithmeticNegativeTestsFF, divisionFF) { trace_builder.calldata_copy(0, 2, 0, std::vector{ 15, 315 }); @@ -1407,7 +1407,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionFF) trace_builder.halt(); auto trace = trace_builder.finalize(); - auto select_row = [](Row r) { return r.avmMini_sel_op_div == FF(1); }; + auto select_row = [](Row r) { return r.avm_main_sel_op_div == FF(1); }; mutate_ic_in_trace(trace, std::move(select_row), FF(0)); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_DIVISION_FF"); @@ -1415,7 +1415,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionFF) // Test where division is not by zero but an operation error is wrongly raised // in the trace. -TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionNoZeroButError) +TEST_F(AvmArithmeticNegativeTestsFF, divisionNoZeroButError) { trace_builder.calldata_copy(0, 2, 0, std::vector{ 15, 315 }); @@ -1425,23 +1425,23 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionNoZeroButError) auto trace = trace_builder.finalize(); // Find the first row enabling the division selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_div == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_div == FF(1); }); size_t const index = static_cast(row - trace.begin()); // Activate the operator error - trace[index].avmMini_op_err = FF(1); + trace[index].avm_main_op_err = FF(1); auto trace2 = trace; EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_DIVISION_ZERO_ERR1"); // Even more malicious, one makes the first relation passes by setting the inverse to zero. - trace2[index].avmMini_inv = FF(0); + trace2[index].avm_main_inv = FF(0); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace2)), "SUBOP_DIVISION_ZERO_ERR2"); } // Test with division by zero occurs and no error is raised (remove error flag) -TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionByZeroNoError) +TEST_F(AvmArithmeticNegativeTestsFF, divisionByZeroNoError) { trace_builder.calldata_copy(0, 1, 0, std::vector{ 15 }); @@ -1451,16 +1451,16 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionByZeroNoError) auto trace = trace_builder.finalize(); // Find the first row enabling the division selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_div == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_div == FF(1); }); // Remove the operator error flag - row->avmMini_op_err = FF(0); + row->avm_main_op_err = FF(0); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_DIVISION_FF"); } // Test with division of zero by zero occurs and no error is raised (remove error flag) -TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionZeroByZeroNoError) +TEST_F(AvmArithmeticNegativeTestsFF, divisionZeroByZeroNoError) { // Memory layout: [0,0,0,0,0,0,....] trace_builder.op_div(0, 1, 2, AvmMemoryTag::FF); // [0,0,0,0,0,0....] @@ -1468,17 +1468,17 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionZeroByZeroNoError) auto trace = trace_builder.finalize(); // Find the first row enabling the division selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_div == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_div == FF(1); }); // Remove the operator error flag - row->avmMini_op_err = FF(0); + row->avm_main_op_err = FF(0); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_DIVISION_ZERO_ERR1"); } // Test that error flag cannot be raised for a non-relevant operation such as // the addition, subtraction, multiplication. -TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) +TEST_F(AvmArithmeticNegativeTestsFF, operationWithErrorFlag) { trace_builder.calldata_copy(0, 3, 0, std::vector{ 37, 4, 11 }); @@ -1489,10 +1489,10 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) auto trace = trace_builder.finalize(); // Find the first row enabling the addition selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_add == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_add == FF(1); }); // Activate the operator error - row->avmMini_op_err = FF(1); + row->avm_main_op_err = FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_ERROR_RELEVANT_OP"); @@ -1506,10 +1506,10 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) trace = trace_builder.finalize(); // Find the first row enabling the subtraction selector - row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_sub == FF(1); }); + row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == FF(1); }); // Activate the operator error - row->avmMini_op_err = FF(1); + row->avm_main_op_err = FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_ERROR_RELEVANT_OP"); @@ -1523,10 +1523,10 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) trace = trace_builder.finalize(); // Find the first row enabling the multiplication selector - row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_mul == FF(1); }); + row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == FF(1); }); // Activate the operator error - row->avmMini_op_err = FF(1); + row->avm_main_op_err = FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_ERROR_RELEVANT_OP"); } @@ -1536,21 +1536,21 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) ******************************************************************************/ // Test on basic incorrect addition over U8. -TEST_F(AvmMiniArithmeticNegativeTestsU8, addition) +TEST_F(AvmArithmeticNegativeTestsU8, addition) { auto trace = gen_mutated_trace_add(FF(234), FF(22), FF(1), AvmMemoryTag::U8); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } // Test on basic incorrect subtraction over U8. -TEST_F(AvmMiniArithmeticNegativeTestsU8, subtraction) +TEST_F(AvmArithmeticNegativeTestsU8, subtraction) { auto trace = gen_mutated_trace_sub(FF(100), FF(104), FF(253), AvmMemoryTag::U8); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } // Test on basic incorrect multiplication over U8. -TEST_F(AvmMiniArithmeticNegativeTestsU8, multiplication) +TEST_F(AvmArithmeticNegativeTestsU8, multiplication) { auto trace = gen_mutated_trace_mul(FF(9), FF(100), FF(55), AvmMemoryTag::U8); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MUL_COMMON_2"); @@ -1561,21 +1561,21 @@ TEST_F(AvmMiniArithmeticNegativeTestsU8, multiplication) ******************************************************************************/ // Test on basic incorrect addition over U16. -TEST_F(AvmMiniArithmeticNegativeTestsU16, addition) +TEST_F(AvmArithmeticNegativeTestsU16, addition) { auto trace = gen_mutated_trace_add(FF(8234), FF(7428), FF(653), AvmMemoryTag::U16); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } // Test on basic incorrect subtraction over U16. -TEST_F(AvmMiniArithmeticNegativeTestsU16, subtraction) +TEST_F(AvmArithmeticNegativeTestsU16, subtraction) { auto trace = gen_mutated_trace_sub(FF(100), FF(932), FF(25373), AvmMemoryTag::U16); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } // Test on basic incorrect multiplication over U16. -TEST_F(AvmMiniArithmeticNegativeTestsU16, multiplication) +TEST_F(AvmArithmeticNegativeTestsU16, multiplication) { auto trace = gen_mutated_trace_mul(FF(8096), FF(1024), FF(1), AvmMemoryTag::U16); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MUL_COMMON_2"); @@ -1586,21 +1586,21 @@ TEST_F(AvmMiniArithmeticNegativeTestsU16, multiplication) ******************************************************************************/ // Test on basic incorrect addition over U32. -TEST_F(AvmMiniArithmeticNegativeTestsU32, addition) +TEST_F(AvmArithmeticNegativeTestsU32, addition) { auto trace = gen_mutated_trace_add(FF(1972382341), FF(1111133221), FF(1222222222), AvmMemoryTag::U32); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } // Test on basic incorrect subtraction over U32. -TEST_F(AvmMiniArithmeticNegativeTestsU32, subtraction) +TEST_F(AvmArithmeticNegativeTestsU32, subtraction) { auto trace = gen_mutated_trace_sub(FF(3999888777LLU), FF(UINT32_MAX), FF(2537332433LLU), AvmMemoryTag::U32); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } // Test on basic incorrect multiplication over U32. -TEST_F(AvmMiniArithmeticNegativeTestsU32, multiplication) +TEST_F(AvmArithmeticNegativeTestsU32, multiplication) { auto trace = gen_mutated_trace_mul(FF(UINT32_MAX), FF(UINT32_MAX), FF(0), AvmMemoryTag::U32); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MUL_COMMON_2"); @@ -1611,7 +1611,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU32, multiplication) ******************************************************************************/ // Test on basic incorrect addition over U64. -TEST_F(AvmMiniArithmeticNegativeTestsU64, addition) +TEST_F(AvmArithmeticNegativeTestsU64, addition) { auto trace = gen_mutated_trace_add( FF(3324236423198282341LLU), FF(999999991111133221LLU), FF(1222222222236LLU), AvmMemoryTag::U64); @@ -1619,7 +1619,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU64, addition) } // Test on basic incorrect subtraction over U64. -TEST_F(AvmMiniArithmeticNegativeTestsU64, subtraction) +TEST_F(AvmArithmeticNegativeTestsU64, subtraction) { auto trace = gen_mutated_trace_sub(FF(399988877723434LLU), FF(UINT64_MAX), FF(25373324332342LLU), AvmMemoryTag::U64); @@ -1627,7 +1627,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU64, subtraction) } // Test on basic incorrect multiplication over U64. -TEST_F(AvmMiniArithmeticNegativeTestsU64, multiplication) +TEST_F(AvmArithmeticNegativeTestsU64, multiplication) { auto trace = gen_mutated_trace_mul(FF(399988877723434LLU), FF(9998887772343LLU), FF(9283674827534LLU), AvmMemoryTag::U64); @@ -1639,7 +1639,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU64, multiplication) ******************************************************************************/ // Test on basic incorrect addition over U128. -TEST_F(AvmMiniArithmeticNegativeTestsU128, addition) +TEST_F(AvmArithmeticNegativeTestsU128, addition) { uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; uint128_t const b = (uint128_t{ 0x3333222233331111LLU } << 64) + uint128_t{ 0x5555111155553333LLU }; @@ -1653,7 +1653,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU128, addition) } // Test on basic incorrect subtraction over U128. -TEST_F(AvmMiniArithmeticNegativeTestsU128, subtraction) +TEST_F(AvmArithmeticNegativeTestsU128, subtraction) { uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; uint128_t const b = (uint128_t{ 0x7333222233331111LLU } << 64) + uint128_t{ 0x5555111155553333LLU }; @@ -1667,7 +1667,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU128, subtraction) } // Test on basic incorrect multiplication over U128. -TEST_F(AvmMiniArithmeticNegativeTestsU128, multiplication) +TEST_F(AvmArithmeticNegativeTestsU128, multiplication) { uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; uint128_t const b = (uint128_t{ 0x7333222233331111LLU } << 64) + uint128_t{ 0x5555111155553333LLU }; diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_bitwise.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp similarity index 69% rename from barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_bitwise.test.cpp rename to barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp index 9292667e0ed..58760e5a6f6 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_bitwise.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp @@ -1,4 +1,4 @@ -#include "AvmMini_common.test.hpp" +#include "avm_common.test.hpp" #include "barretenberg/numeric/uint128/uint128.hpp" #include @@ -20,52 +20,52 @@ Row common_validate_op_not(std::vector const& trace, { // Find the first row enabling the not selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_not == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_not == FF(1); }); // Use the row in the main trace to find the same operation in the alu trace. - FF clk = row->avmMini_clk; - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.aluChip_alu_clk == clk; }); + FF clk = row->avm_main_clk; + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_alu_clk == clk; }); // Check that both rows were found EXPECT_TRUE(row != trace.end()); EXPECT_TRUE(alu_row != trace.end()); // Check that the correct result is stored at the expected memory location. - EXPECT_EQ(row->avmMini_ic, c); - EXPECT_EQ(row->avmMini_mem_idx_c, addr_c); - EXPECT_EQ(row->avmMini_mem_op_c, FF(1)); - EXPECT_EQ(row->avmMini_rwc, FF(1)); + EXPECT_EQ(row->avm_main_ic, c); + EXPECT_EQ(row->avm_main_mem_idx_c, addr_c); + EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); + EXPECT_EQ(row->avm_main_rwc, FF(1)); // Check that ia register is correctly set with memory load operations. - EXPECT_EQ(row->avmMini_ia, a); - EXPECT_EQ(row->avmMini_mem_idx_a, addr_a); - EXPECT_EQ(row->avmMini_mem_op_a, FF(1)); - EXPECT_EQ(row->avmMini_rwa, FF(0)); + EXPECT_EQ(row->avm_main_ia, a); + EXPECT_EQ(row->avm_main_mem_idx_a, addr_a); + EXPECT_EQ(row->avm_main_mem_op_a, FF(1)); + EXPECT_EQ(row->avm_main_rwa, FF(0)); // Check the instruction tag - EXPECT_EQ(row->avmMini_in_tag, FF(static_cast(tag))); + EXPECT_EQ(row->avm_main_in_tag, FF(static_cast(tag))); // Check that intermediate registers are correctly copied in Alu trace - EXPECT_EQ(alu_row->aluChip_alu_ia, a); - EXPECT_EQ(alu_row->aluChip_alu_ib, FF(0)); - EXPECT_EQ(alu_row->aluChip_alu_ic, c); + EXPECT_EQ(alu_row->avm_alu_alu_ia, a); + EXPECT_EQ(alu_row->avm_alu_alu_ib, FF(0)); + EXPECT_EQ(alu_row->avm_alu_alu_ic, c); // Check that not selector is set. - EXPECT_EQ(row->avmMini_sel_op_not, FF(1)); - EXPECT_EQ(alu_row->aluChip_alu_op_not, FF(1)); + EXPECT_EQ(row->avm_main_sel_op_not, FF(1)); + EXPECT_EQ(alu_row->avm_alu_alu_op_not, FF(1)); return *alu_row; } std::vector gen_mutated_trace_not(FF const& a, FF const& c_mutated, avm_trace::AvmMemoryTag tag) { - auto trace_builder = avm_trace::AvmMiniTraceBuilder(); + auto trace_builder = avm_trace::AvmTraceBuilder(); trace_builder.set(uint128_t{ a }, 0, tag); trace_builder.op_not(0, 1, tag); trace_builder.halt(); auto trace = trace_builder.finalize(); - auto select_row = [](Row r) { return r.avmMini_sel_op_not == FF(1); }; + auto select_row = [](Row r) { return r.avm_main_sel_op_not == FF(1); }; mutate_ic_in_trace(trace, select_row, c_mutated, true); return trace; @@ -75,45 +75,45 @@ std::vector gen_mutated_trace_not(FF const& a, FF const& c_mutated, avm_tra namespace tests_avm { using namespace avm_trace; -class AvmMiniBitwiseTests : public ::testing::Test { +class AvmBitwiseTests : public ::testing::Test { public: - AvmMiniTraceBuilder trace_builder; + AvmTraceBuilder trace_builder; protected: // TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialised for every test. void SetUp() override { srs::init_crs_factory("../srs_db/ignition"); - trace_builder = AvmMiniTraceBuilder(); // Clean instance for every run. + trace_builder = AvmTraceBuilder(); // Clean instance for every run. }; }; -class AvmMiniBitwiseTestsU8 : public AvmMiniBitwiseTests {}; -class AvmMiniBitwiseTestsU16 : public AvmMiniBitwiseTests {}; -class AvmMiniBitwiseTestsU32 : public AvmMiniBitwiseTests {}; -class AvmMiniBitwiseTestsU64 : public AvmMiniBitwiseTests {}; -class AvmMiniBitwiseTestsU128 : public AvmMiniBitwiseTests {}; +class AvmBitwiseTestsU8 : public AvmBitwiseTests {}; +class AvmBitwiseTestsU16 : public AvmBitwiseTests {}; +class AvmBitwiseTestsU32 : public AvmBitwiseTests {}; +class AvmBitwiseTestsU64 : public AvmBitwiseTests {}; +class AvmBitwiseTestsU128 : public AvmBitwiseTests {}; -class AvmMiniBitwiseNegativeTestsFF : public AvmMiniBitwiseTests {}; -class AvmMiniBitwiseNegativeTestsU8 : public AvmMiniBitwiseTests {}; -class AvmMiniBitwiseNegativeTestsU16 : public AvmMiniBitwiseTests {}; -class AvmMiniBitwiseNegativeTestsU32 : public AvmMiniBitwiseTests {}; -class AvmMiniBitwiseNegativeTestsU64 : public AvmMiniBitwiseTests {}; -class AvmMiniBitwiseNegativeTestsU128 : public AvmMiniBitwiseTests {}; +class AvmBitwiseNegativeTestsFF : public AvmBitwiseTests {}; +class AvmBitwiseNegativeTestsU8 : public AvmBitwiseTests {}; +class AvmBitwiseNegativeTestsU16 : public AvmBitwiseTests {}; +class AvmBitwiseNegativeTestsU32 : public AvmBitwiseTests {}; +class AvmBitwiseNegativeTestsU64 : public AvmBitwiseTests {}; +class AvmBitwiseNegativeTestsU128 : public AvmBitwiseTests {}; /****************************************************************************** * * POSITIVE TESTS * ****************************************************************************** - * See AvmMini_arithmetic.cpp for explanation of positive tests + * See Avm_arithmetic.cpp for explanation of positive tests ******************************************************************************/ /****************************************************************************** * Positive Tests - U8 ******************************************************************************/ -TEST_F(AvmMiniBitwiseTestsU8, BitwiseNot) +TEST_F(AvmBitwiseTestsU8, BitwiseNot) { trace_builder.set(1, 0, AvmMemoryTag::U8); // Memory Layout: [1,0,0,...] trace_builder.op_not(0, 1, AvmMemoryTag::U8); // [1,254,0,0,....] @@ -122,11 +122,11 @@ TEST_F(AvmMiniBitwiseTestsU8, BitwiseNot) auto alu_row = common_validate_op_not(trace, FF(1), FF(254), FF(0), FF(1), AvmMemoryTag::U8); - EXPECT_EQ(alu_row.aluChip_alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u8_tag, FF(1)); validate_trace_proof(std::move(trace)); } -TEST_F(AvmMiniBitwiseTestsU16, BitwiseNot) +TEST_F(AvmBitwiseTestsU16, BitwiseNot) { trace_builder.set(512, 0, AvmMemoryTag::U16); // Memory Layout: [512,0,0,...] trace_builder.op_not(0, 1, AvmMemoryTag::U16); // [512,65023,0,0,0,....] @@ -135,11 +135,11 @@ TEST_F(AvmMiniBitwiseTestsU16, BitwiseNot) auto alu_row = common_validate_op_not(trace, FF(512), FF(65'023), FF(0), FF(1), AvmMemoryTag::U16); - EXPECT_EQ(alu_row.aluChip_alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u16_tag, FF(1)); validate_trace_proof(std::move(trace)); } -TEST_F(AvmMiniBitwiseTestsU32, BitwiseNot) +TEST_F(AvmBitwiseTestsU32, BitwiseNot) { trace_builder.set(131'072, 0, AvmMemoryTag::U32); // Memory Layout: [131072,0,0,...] trace_builder.op_not(0, 1, AvmMemoryTag::U32); // [131072,4294836223,,0,0,....] @@ -148,11 +148,11 @@ TEST_F(AvmMiniBitwiseTestsU32, BitwiseNot) auto alu_row = common_validate_op_not(trace, FF(131'072), FF(4'294'836'223LLU), FF(0), FF(1), AvmMemoryTag::U32); - EXPECT_EQ(alu_row.aluChip_alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u32_tag, FF(1)); validate_trace_proof(std::move(trace)); } -TEST_F(AvmMiniBitwiseTestsU64, BitwiseNot) +TEST_F(AvmBitwiseTestsU64, BitwiseNot) { trace_builder.set(0x100000000LLU, 0, AvmMemoryTag::U64); // Memory Layout: [8589934592,0,0,...] trace_builder.op_not(0, 1, AvmMemoryTag::U64); // [8589934592,18446744069414584319,0,0,....] @@ -162,11 +162,11 @@ TEST_F(AvmMiniBitwiseTestsU64, BitwiseNot) auto alu_row = common_validate_op_not(trace, FF(0x100000000LLU), FF(0xfffffffeffffffffLLU), FF(0), FF(1), AvmMemoryTag::U64); - EXPECT_EQ(alu_row.aluChip_alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u64_tag, FF(1)); validate_trace_proof(std::move(trace)); } -TEST_F(AvmMiniBitwiseTestsU128, BitwiseNot) +TEST_F(AvmBitwiseTestsU128, BitwiseNot) { uint128_t const a = uint128_t{ 0x4000000000000 } << 64; @@ -179,7 +179,7 @@ TEST_F(AvmMiniBitwiseTestsU128, BitwiseNot) auto alu_row = common_validate_op_not( trace, FF(uint256_t::from_uint128(a)), FF(uint256_t::from_uint128(res)), FF(0), FF(1), AvmMemoryTag::U128); - EXPECT_EQ(alu_row.aluChip_alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_u128_tag, FF(1)); validate_trace_proof(std::move(trace)); } @@ -188,63 +188,64 @@ TEST_F(AvmMiniBitwiseTestsU128, BitwiseNot) * NEGATIVE TESTS - Finite Field Type * ****************************************************************************** - * See AvmMini_arithmetic.cpp for explanation of negative tests + * See Avm_arithmetic.cpp for explanation of negative tests ******************************************************************************/ /****************************************************************************** * Negative Tests - FF ******************************************************************************/ -TEST_F(AvmMiniBitwiseNegativeTestsFF, UndefinedOverFF) +TEST_F(AvmBitwiseNegativeTestsFF, UndefinedOverFF) { - auto trace_builder = avm_trace::AvmMiniTraceBuilder(); + auto trace_builder = avm_trace::AvmTraceBuilder(); // Triggers a write row 1 of mem_trace and alu_trace trace_builder.set(10, 0, AvmMemoryTag::U8); // Triggers a write in row 2 of alu_trace trace_builder.op_not(0, 1, AvmMemoryTag::U8); // Finally, we will have a write in row 3 of the mem_trace to copy the result // from the op_not operation. + trace_builder.return_op(0, 0); // Manually update the memory tags in the relevant trace; auto trace = trace_builder.finalize(); // TODO(ilyas): When the SET opcodes applies relational constraints, this will fail // we will need to look at a new way of doing this test. for (size_t i = 1; i < 4; i++) { - trace.at(i).memTrace_m_tag = FF(6); - trace.at(i).memTrace_m_in_tag = FF(6); - trace.at(i).aluChip_alu_ff_tag = FF::one(); - trace.at(i).aluChip_alu_u8_tag = FF::zero(); - trace.at(i).avmMini_in_tag = FF(6); + trace.at(i).avm_mem_m_tag = FF(6); + trace.at(i).avm_mem_m_in_tag = FF(6); + trace.at(i).avm_alu_alu_ff_tag = FF::one(); + trace.at(i).avm_alu_alu_u8_tag = FF::zero(); + trace.at(i).avm_main_in_tag = FF(6); } EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_FF_NOT_XOR"); } -TEST_F(AvmMiniBitwiseNegativeTestsU8, BitwiseNot) +TEST_F(AvmBitwiseNegativeTestsU8, BitwiseNot) { std::vector trace = gen_mutated_trace_not(FF{ 1 }, FF{ 2 }, AvmMemoryTag::U8); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_NOT"); } -TEST_F(AvmMiniBitwiseNegativeTestsU16, BitwiseNot) +TEST_F(AvmBitwiseNegativeTestsU16, BitwiseNot) { std::vector trace = gen_mutated_trace_not(FF{ 32'768 }, FF{ 8'192 }, AvmMemoryTag::U16); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_NOT"); } -TEST_F(AvmMiniBitwiseNegativeTestsU32, BitwiseNot) +TEST_F(AvmBitwiseNegativeTestsU32, BitwiseNot) { std::vector trace = gen_mutated_trace_not(FF{ 0xdeadbeef }, FF{ 0x20020af }, AvmMemoryTag::U64); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_NOT"); } -TEST_F(AvmMiniBitwiseNegativeTestsU64, BitwiseNot) +TEST_F(AvmBitwiseNegativeTestsU64, BitwiseNot) { std::vector trace = gen_mutated_trace_not(FF{ 0x10000000000000LLU }, FF{ 0x10000fed0100000LLU }, AvmMemoryTag::U64); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_NOT"); } -TEST_F(AvmMiniBitwiseNegativeTestsU128, BitwiseNot) +TEST_F(AvmBitwiseNegativeTestsU128, BitwiseNot) { uint128_t const a = uint128_t{ 0x4000000000000 } << 64; uint128_t const b = uint128_t{ 0x300000ae921000 } << 64; diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_common.test.hpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_common.test.hpp new file mode 100644 index 00000000000..710082b8f4b --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_common.test.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "barretenberg/vm/avm_trace/avm_helper.hpp" +#include "barretenberg/vm/generated/avm_composer.hpp" +#include "barretenberg/vm/generated/avm_prover.hpp" +#include "barretenberg/vm/generated/avm_verifier.hpp" +#include "helpers.test.hpp" + +#include +#include +#include +#include +#include \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_control_flow.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp similarity index 53% rename from barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_control_flow.test.cpp rename to barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp index a5eeeadb817..99a47bc1332 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_control_flow.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp @@ -1,20 +1,20 @@ -#include "AvmMini_common.test.hpp" +#include "avm_common.test.hpp" using namespace bb; namespace tests_avm { using namespace avm_trace; -class AvmMiniControlFlowTests : public ::testing::Test { +class AvmControlFlowTests : public ::testing::Test { public: - AvmMiniTraceBuilder trace_builder; + AvmTraceBuilder trace_builder; protected: // TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialised for every test. void SetUp() override { srs::init_crs_factory("../srs_db/ignition"); - trace_builder = AvmMiniTraceBuilder(); // Clean instance for every run. + trace_builder = AvmTraceBuilder(); // Clean instance for every run. }; }; @@ -24,7 +24,7 @@ class AvmMiniControlFlowTests : public ::testing::Test { * *****************************************************************************/ -TEST_F(AvmMiniControlFlowTests, simpleCall) +TEST_F(AvmControlFlowTests, simpleCall) { uint32_t const CALL_ADDRESS = 4; @@ -40,30 +40,30 @@ TEST_F(AvmMiniControlFlowTests, simpleCall) // Check call { auto call_row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_internal_call == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_internal_call == FF(1); }); EXPECT_TRUE(call_row != trace.end()); - EXPECT_EQ(call_row->avmMini_pc, FF(0)); - EXPECT_EQ(call_row->avmMini_ia, FF(CALL_ADDRESS)); - EXPECT_EQ(call_row->avmMini_internal_return_ptr, FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET)); - EXPECT_EQ(call_row->avmMini_ib, FF(1)); - EXPECT_EQ(call_row->avmMini_mem_idx_b, - FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET)); // Store the return address (0) in memory + EXPECT_EQ(call_row->avm_main_pc, FF(0)); + EXPECT_EQ(call_row->avm_main_ia, FF(CALL_ADDRESS)); + EXPECT_EQ(call_row->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET)); + EXPECT_EQ(call_row->avm_main_ib, FF(1)); + EXPECT_EQ(call_row->avm_main_mem_idx_b, + FF(AvmTraceBuilder::CALLSTACK_OFFSET)); // Store the return address (0) in memory } // Check halt { auto halt_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_halt == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_halt == FF(1); }); // Check that the correct result is stored at the expected memory location. EXPECT_TRUE(halt_row != trace.end()); - EXPECT_EQ(halt_row->avmMini_pc, FF(CALL_ADDRESS)); - EXPECT_EQ(halt_row->avmMini_internal_return_ptr, FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET + 1)); + EXPECT_EQ(halt_row->avm_main_pc, FF(CALL_ADDRESS)); + EXPECT_EQ(halt_row->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET + 1)); } validate_trace_proof(std::move(trace)); } -TEST_F(AvmMiniControlFlowTests, simpleJump) +TEST_F(AvmControlFlowTests, simpleJump) { uint32_t const JUMP_ADDRESS = 4; @@ -79,24 +79,24 @@ TEST_F(AvmMiniControlFlowTests, simpleJump) // Check jump { auto call_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_jump == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_jump == FF(1); }); EXPECT_TRUE(call_row != trace.end()); - EXPECT_EQ(call_row->avmMini_pc, FF(0)); - EXPECT_EQ(call_row->avmMini_ia, FF(JUMP_ADDRESS)); + EXPECT_EQ(call_row->avm_main_pc, FF(0)); + EXPECT_EQ(call_row->avm_main_ia, FF(JUMP_ADDRESS)); } // Check halt { auto halt_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_halt == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_halt == FF(1); }); EXPECT_TRUE(halt_row != trace.end()); - EXPECT_EQ(halt_row->avmMini_pc, FF(JUMP_ADDRESS)); + EXPECT_EQ(halt_row->avm_main_pc, FF(JUMP_ADDRESS)); } validate_trace_proof(std::move(trace)); } -TEST_F(AvmMiniControlFlowTests, simpleCallAndReturn) +TEST_F(AvmControlFlowTests, simpleCallAndReturn) { uint32_t const CALL_ADDRESS = 20; uint32_t const RETURN_ADDRESS = 1; @@ -114,39 +114,39 @@ TEST_F(AvmMiniControlFlowTests, simpleCallAndReturn) // Check call { auto call_row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_internal_call == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_internal_call == FF(1); }); EXPECT_TRUE(call_row != trace.end()); - EXPECT_EQ(call_row->avmMini_pc, FF(0)); - EXPECT_EQ(call_row->avmMini_internal_return_ptr, FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET)); - EXPECT_EQ(call_row->avmMini_ib, FF(1)); - EXPECT_EQ(call_row->avmMini_mem_idx_b, - FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET)); // Store the return address (0) in memory + EXPECT_EQ(call_row->avm_main_pc, FF(0)); + EXPECT_EQ(call_row->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET)); + EXPECT_EQ(call_row->avm_main_ib, FF(1)); + EXPECT_EQ(call_row->avm_main_mem_idx_b, + FF(AvmTraceBuilder::CALLSTACK_OFFSET)); // Store the return address (0) in memory } // Check return { auto return_row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_internal_return == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_internal_return == FF(1); }); // Check that the correct result is stored at the expected memory location. EXPECT_TRUE(return_row != trace.end()); - EXPECT_EQ(return_row->avmMini_pc, FF(CALL_ADDRESS)); - EXPECT_EQ(return_row->avmMini_internal_return_ptr, FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET + 1)); + EXPECT_EQ(return_row->avm_main_pc, FF(CALL_ADDRESS)); + EXPECT_EQ(return_row->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET + 1)); } // Check halt { auto halt_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_halt == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_halt == FF(1); }); EXPECT_TRUE(halt_row != trace.end()); - EXPECT_EQ(halt_row->avmMini_pc, FF(RETURN_ADDRESS)); + EXPECT_EQ(halt_row->avm_main_pc, FF(RETURN_ADDRESS)); } validate_trace_proof(std::move(trace)); } -TEST_F(AvmMiniControlFlowTests, multipleCallsAndReturns) +TEST_F(AvmControlFlowTests, multipleCallsAndReturns) { uint32_t const CALL_ADDRESS_1 = 420; uint32_t const CALL_ADDRESS_2 = 69; @@ -183,107 +183,108 @@ TEST_F(AvmMiniControlFlowTests, multipleCallsAndReturns) // Check call 1 { auto call_1 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avmMini_sel_internal_call == FF(1) && r.avmMini_ib == FF(1); + return r.avm_main_sel_internal_call == FF(1) && r.avm_main_ib == FF(1); }); EXPECT_TRUE(call_1 != trace.end()); - EXPECT_EQ(call_1->avmMini_pc, FF(0)); - EXPECT_EQ(call_1->avmMini_ia, FF(CALL_ADDRESS_1)); - EXPECT_EQ(call_1->avmMini_internal_return_ptr, FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET)); - EXPECT_EQ(call_1->avmMini_mem_idx_b, - FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET)); // Store the return address (0) in memory + EXPECT_EQ(call_1->avm_main_pc, FF(0)); + EXPECT_EQ(call_1->avm_main_ia, FF(CALL_ADDRESS_1)); + EXPECT_EQ(call_1->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET)); + EXPECT_EQ(call_1->avm_main_mem_idx_b, + FF(AvmTraceBuilder::CALLSTACK_OFFSET)); // Store the return address (0) in memory } // Call 2 { auto call_2 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avmMini_sel_internal_call == FF(1) && r.avmMini_pc == FF(CALL_ADDRESS_1); + return r.avm_main_sel_internal_call == FF(1) && r.avm_main_pc == FF(CALL_ADDRESS_1); }); EXPECT_TRUE(call_2 != trace.end()); - EXPECT_EQ(call_2->avmMini_ib, FF(CALL_ADDRESS_1 + 1)); - EXPECT_EQ(call_2->avmMini_ia, FF(CALL_ADDRESS_2)); - EXPECT_EQ(call_2->avmMini_internal_return_ptr, FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET + 1)); - EXPECT_EQ(call_2->avmMini_mem_idx_b, - FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET + 1)); // Store the return address (0) in memory + EXPECT_EQ(call_2->avm_main_ib, FF(CALL_ADDRESS_1 + 1)); + EXPECT_EQ(call_2->avm_main_ia, FF(CALL_ADDRESS_2)); + EXPECT_EQ(call_2->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET + 1)); + EXPECT_EQ(call_2->avm_main_mem_idx_b, + FF(AvmTraceBuilder::CALLSTACK_OFFSET + 1)); // Store the return address (0) in memory } // Call 3 { auto call_3 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avmMini_sel_internal_call == FF(1) && r.avmMini_pc == FF(CALL_ADDRESS_2); + return r.avm_main_sel_internal_call == FF(1) && r.avm_main_pc == FF(CALL_ADDRESS_2); }); EXPECT_TRUE(call_3 != trace.end()); - EXPECT_EQ(call_3->avmMini_ib, FF(CALL_ADDRESS_2 + 1)); - EXPECT_EQ(call_3->avmMini_internal_return_ptr, FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET + 2)); - EXPECT_EQ(call_3->avmMini_mem_idx_b, - FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET + 2)); // Store the return address (0) in memory + EXPECT_EQ(call_3->avm_main_ib, FF(CALL_ADDRESS_2 + 1)); + EXPECT_EQ(call_3->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET + 2)); + EXPECT_EQ(call_3->avm_main_mem_idx_b, + FF(AvmTraceBuilder::CALLSTACK_OFFSET + 2)); // Store the return address (0) in memory } // Return 1 { auto return_1 = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_internal_return == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_internal_return == FF(1); }); EXPECT_TRUE(return_1 != trace.end()); - EXPECT_EQ(return_1->avmMini_pc, FF(CALL_ADDRESS_3)); - EXPECT_EQ(return_1->avmMini_internal_return_ptr, FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET + 3)); + EXPECT_EQ(return_1->avm_main_pc, FF(CALL_ADDRESS_3)); + EXPECT_EQ(return_1->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET + 3)); } // Call 4 { auto call_4 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avmMini_sel_internal_call == FF(1) && r.avmMini_pc == FF(CALL_ADDRESS_2 + 1); + return r.avm_main_sel_internal_call == FF(1) && r.avm_main_pc == FF(CALL_ADDRESS_2 + 1); }); EXPECT_TRUE(call_4 != trace.end()); - EXPECT_EQ(call_4->avmMini_ib, FF(CALL_ADDRESS_2 + 2)); - EXPECT_EQ(call_4->avmMini_internal_return_ptr, FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET + 2)); - EXPECT_EQ(call_4->avmMini_mem_idx_b, - FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET + 2)); // Store the return address (0) in memory + EXPECT_EQ(call_4->avm_main_ib, FF(CALL_ADDRESS_2 + 2)); + EXPECT_EQ(call_4->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET + 2)); + EXPECT_EQ(call_4->avm_main_mem_idx_b, + FF(AvmTraceBuilder::CALLSTACK_OFFSET + 2)); // Store the return address (0) in memory } // Return 2 { auto return_2 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avmMini_sel_internal_return == FF(1) && r.avmMini_pc == FF(CALL_ADDRESS_4); + return r.avm_main_sel_internal_return == FF(1) && r.avm_main_pc == FF(CALL_ADDRESS_4); }); EXPECT_TRUE(return_2 != trace.end()); - EXPECT_EQ(return_2->avmMini_ia, FF(CALL_ADDRESS_2 + 2)); - EXPECT_EQ(return_2->avmMini_internal_return_ptr, FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET + 3)); + EXPECT_EQ(return_2->avm_main_ia, FF(CALL_ADDRESS_2 + 2)); + EXPECT_EQ(return_2->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET + 3)); } // Jump 1 { auto jump_1 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avmMini_sel_jump == FF(1) && r.avmMini_pc == FF(CALL_ADDRESS_2 + 2); + return r.avm_main_sel_jump == FF(1) && r.avm_main_pc == FF(CALL_ADDRESS_2 + 2); }); EXPECT_TRUE(jump_1 != trace.end()); - EXPECT_EQ(jump_1->avmMini_ia, FF(JUMP_ADDRESS_1)); - EXPECT_EQ(jump_1->avmMini_internal_return_ptr, FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET + 2)); + EXPECT_EQ(jump_1->avm_main_ia, FF(JUMP_ADDRESS_1)); + EXPECT_EQ(jump_1->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET + 2)); } // Return 3 { auto return_3 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avmMini_sel_internal_return == FF(1) && r.avmMini_pc == FF(JUMP_ADDRESS_1); + return r.avm_main_sel_internal_return == FF(1) && r.avm_main_pc == FF(JUMP_ADDRESS_1); }); EXPECT_TRUE(return_3 != trace.end()); - EXPECT_EQ(return_3->avmMini_ia, FF(CALL_ADDRESS_1 + 1)); - EXPECT_EQ(return_3->avmMini_internal_return_ptr, FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET + 2)); + EXPECT_EQ(return_3->avm_main_ia, FF(CALL_ADDRESS_1 + 1)); + EXPECT_EQ(return_3->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET + 2)); } // Return 4 { auto return_4 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avmMini_sel_internal_return == FF(1) && r.avmMini_pc == FF(CALL_ADDRESS_1 + 1); + return r.avm_main_sel_internal_return == FF(1) && r.avm_main_pc == FF(CALL_ADDRESS_1 + 1); }); EXPECT_TRUE(return_4 != trace.end()); - EXPECT_EQ(return_4->avmMini_ia, FF(1)); - EXPECT_EQ(return_4->avmMini_internal_return_ptr, FF(AvmMiniTraceBuilder::CALLSTACK_OFFSET + 1)); + EXPECT_EQ(return_4->avm_main_ia, FF(1)); + EXPECT_EQ(return_4->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET + 1)); } // Halt row - auto halt_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_halt == FF(1); }); + auto halt_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_halt == FF(1); }); EXPECT_TRUE(halt_row != trace.end()); - EXPECT_EQ(halt_row->avmMini_pc, FF(1)); + EXPECT_EQ(halt_row->avm_main_pc, FF(1)); validate_trace_proof(std::move(trace)); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp similarity index 91% rename from barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_execution.test.cpp rename to barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp index 8ec81212d12..eb17c7b69ac 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp @@ -1,10 +1,10 @@ -#include "barretenberg/vm/avm_trace/AvmMini_execution.hpp" -#include "AvmMini_common.test.hpp" +#include "barretenberg/vm/avm_trace/avm_execution.hpp" +#include "avm_common.test.hpp" #include "barretenberg/common/utils.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_common.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_deserialization.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_helper.hpp" -#include "barretenberg/vm/avm_trace/AvmMini_opcode.hpp" +#include "barretenberg/vm/avm_trace/avm_common.hpp" +#include "barretenberg/vm/avm_trace/avm_deserialization.hpp" +#include "barretenberg/vm/avm_trace/avm_helper.hpp" +#include "barretenberg/vm/avm_trace/avm_opcode.hpp" #include "barretenberg/vm/tests/helpers.test.hpp" #include "gmock/gmock.h" #include @@ -26,11 +26,11 @@ void gen_proof_and_validate(std::vector const& bytecode, std::vector&& trace, std::vector const& calldata) { - auto circuit_builder = AvmMiniCircuitBuilder(); + auto circuit_builder = AvmCircuitBuilder(); circuit_builder.set_trace(std::move(trace)); EXPECT_TRUE(circuit_builder.check_circuit()); - auto composer = AvmMiniComposer(); + auto composer = AvmComposer(); auto verifier = composer.create_verifier(circuit_builder); auto proof = avm_trace::Execution::run_and_prove(bytecode, calldata); @@ -39,22 +39,22 @@ void gen_proof_and_validate(std::vector const& bytecode, } } // namespace -class AvmMiniExecutionTests : public ::testing::Test { +class AvmExecutionTests : public ::testing::Test { public: - AvmMiniTraceBuilder trace_builder; + AvmTraceBuilder trace_builder; protected: // TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialised for every test. void SetUp() override { srs::init_crs_factory("../srs_db/ignition"); - trace_builder = AvmMiniTraceBuilder(); // Clean instance for every run. + trace_builder = AvmTraceBuilder(); // Clean instance for every run. }; }; // Basic positive test with an ADD and RETURN opcode. // Parsing, trace generation and proving is verified. -TEST_F(AvmMiniExecutionTests, basicAddReturn) +TEST_F(AvmExecutionTests, basicAddReturn) { std::string bytecode_hex = to_hex(OpCode::ADD) + // opcode ADD "01" // U8 @@ -90,7 +90,7 @@ TEST_F(AvmMiniExecutionTests, basicAddReturn) } // Positive test for SET and SUB opcodes -TEST_F(AvmMiniExecutionTests, setAndSubOpcodes) +TEST_F(AvmExecutionTests, setAndSubOpcodes) { std::string bytecode_hex = to_hex(OpCode::SET) + // opcode SET "02" // U16 @@ -142,8 +142,8 @@ TEST_F(AvmMiniExecutionTests, setAndSubOpcodes) auto trace = Execution::gen_trace(instructions); // Find the first row enabling the subtraction selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_sub == 1; }); - EXPECT_EQ(row->avmMini_ic, 10000); // 47123 - 37123 = 10000 + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == 1; }); + EXPECT_EQ(row->avm_main_ic, 10000); // 47123 - 37123 = 10000 gen_proof_and_validate(bytecode, std::move(trace), {}); } @@ -154,7 +154,7 @@ TEST_F(AvmMiniExecutionTests, setAndSubOpcodes) // Repeat 12 times a multiplication of value // at offset 0 (5) with value at offset 1 and store // the result at offset 1. -TEST_F(AvmMiniExecutionTests, powerWithMulOpcodes) +TEST_F(AvmExecutionTests, powerWithMulOpcodes) { std::string bytecode_hex = to_hex(OpCode::SET) + // opcode SET "04" // U64 @@ -215,8 +215,8 @@ TEST_F(AvmMiniExecutionTests, powerWithMulOpcodes) // Find the first row enabling the multiplication selector and pc = 13 auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_mul == 1 && r.avmMini_pc == 13; }); - EXPECT_EQ(row->avmMini_ic, 244140625); // 5^12 = 244140625 + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == 1 && r.avm_main_pc == 13; }); + EXPECT_EQ(row->avm_main_ic, 244140625); // 5^12 = 244140625 gen_proof_and_validate(bytecode, std::move(trace), {}); } @@ -230,7 +230,7 @@ TEST_F(AvmMiniExecutionTests, powerWithMulOpcodes) // Internal routine bytecode is at the end. // Bytecode layout: SET INTERNAL_CALL ADD RETURN SET INTERNAL_RETURN // 0 1 2 3 4 5 -TEST_F(AvmMiniExecutionTests, simpleInternalCall) +TEST_F(AvmExecutionTests, simpleInternalCall) { std::string bytecode_hex = to_hex(OpCode::SET) + // opcode SET "03" // U32 @@ -274,12 +274,12 @@ TEST_F(AvmMiniExecutionTests, simpleInternalCall) std::vector pc_sequence{ 0, 1, 4, 5, 2, 3 }; for (size_t i = 0; i < 6; i++) { - EXPECT_EQ(trace.at(i + 1).avmMini_pc, pc_sequence.at(i)); + EXPECT_EQ(trace.at(i + 1).avm_main_pc, pc_sequence.at(i)); } // Find the first row enabling the addition selector. - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_add == 1; }); - EXPECT_EQ(row->avmMini_ic, 345567789); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_add == 1; }); + EXPECT_EQ(row->avm_main_ic, 345567789); gen_proof_and_validate(bytecode, std::move(trace), {}); } @@ -296,7 +296,7 @@ TEST_F(AvmMiniExecutionTests, simpleInternalCall) // BYTECODE(F1): ADD(2,3,2) INTERNAL_RETURN // BYTECODE(F2): MUL(2,3,2) INTERNAL_RETURN // BYTECODE(G): INTERNAL_CALL(6) SET(17,3) INTERNAL_CALL(4) INTERNAL_RETURN -TEST_F(AvmMiniExecutionTests, nestedInternalCalls) +TEST_F(AvmExecutionTests, nestedInternalCalls) { auto internalCallInstructionHex = [](std::string const& dst_offset) { return to_hex(OpCode::INTERNALCALL) // opcode INTERNALCALL @@ -350,13 +350,13 @@ TEST_F(AvmMiniExecutionTests, nestedInternalCalls) std::vector pc_sequence{ 0, 1, 2, 8, 6, 7, 9, 10, 4, 5, 11, 3 }; for (size_t i = 0; i < 6; i++) { - EXPECT_EQ(trace.at(i + 1).avmMini_pc, pc_sequence.at(i)); + EXPECT_EQ(trace.at(i + 1).avm_main_pc, pc_sequence.at(i)); } // Find the first row enabling the multiplication selector. - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_mul == 1; }); - EXPECT_EQ(row->avmMini_ic, 187); - EXPECT_EQ(row->avmMini_pc, 4); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == 1; }); + EXPECT_EQ(row->avm_main_ic, 187); + EXPECT_EQ(row->avm_main_pc, 4); gen_proof_and_validate(bytecode, std::move(trace), {}); } @@ -367,7 +367,7 @@ TEST_F(AvmMiniExecutionTests, nestedInternalCalls) // Calldata: [13, 156] // Bytecode layout: CALLDATACOPY JUMP SUB DIV RETURN // 0 1 2 3 4 -TEST_F(AvmMiniExecutionTests, jumpAndCalldatacopy) +TEST_F(AvmExecutionTests, jumpAndCalldatacopy) { std::string bytecode_hex = to_hex(OpCode::CALLDATACOPY) + // opcode CALLDATACOPY (no in tag) "00000000" // cd_offset @@ -415,15 +415,15 @@ TEST_F(AvmMiniExecutionTests, jumpAndCalldatacopy) std::vector pc_sequence{ 0, 1, 3, 4 }; for (size_t i = 0; i < 4; i++) { - EXPECT_EQ(trace.at(i + 1).avmMini_pc, pc_sequence.at(i)); + EXPECT_EQ(trace.at(i + 1).avm_main_pc, pc_sequence.at(i)); } // Find the first row enabling the division selector. - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_div == 1; }); - EXPECT_EQ(row->avmMini_ic, 12); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_div == 1; }); + EXPECT_EQ(row->avm_main_ic, 12); // Find the first row enabling the subtraction selector. - row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_sub == 1; }); + row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == 1; }); // It must have failed as subtraction was "jumped over". EXPECT_EQ(row, trace.end()); @@ -431,7 +431,7 @@ TEST_F(AvmMiniExecutionTests, jumpAndCalldatacopy) } // Negative test detecting an invalid opcode byte. -TEST_F(AvmMiniExecutionTests, invalidOpcode) +TEST_F(AvmExecutionTests, invalidOpcode) { std::string bytecode_hex = to_hex(OpCode::ADD) + // opcode ADD "02" // U16 @@ -447,7 +447,7 @@ TEST_F(AvmMiniExecutionTests, invalidOpcode) } // Negative test detecting an invalid memmory instruction tag. -TEST_F(AvmMiniExecutionTests, invalidInstructionTag) +TEST_F(AvmExecutionTests, invalidInstructionTag) { std::string bytecode_hex = to_hex(OpCode::ADD) + // opcode ADD "00" // Wrong type @@ -463,7 +463,7 @@ TEST_F(AvmMiniExecutionTests, invalidInstructionTag) } // Negative test detecting SET opcode with instruction memory tag set to FF. -TEST_F(AvmMiniExecutionTests, ffInstructionTagSetOpcode) +TEST_F(AvmExecutionTests, ffInstructionTagSetOpcode) { std::string bytecode_hex = "00" // ADD "05" // U128 @@ -479,7 +479,7 @@ TEST_F(AvmMiniExecutionTests, ffInstructionTagSetOpcode) } // Negative test detecting SET opcode without any operand. -TEST_F(AvmMiniExecutionTests, SetOpcodeNoOperand) +TEST_F(AvmExecutionTests, SetOpcodeNoOperand) { std::string bytecode_hex = "00" // ADD "05" // U128 @@ -493,7 +493,7 @@ TEST_F(AvmMiniExecutionTests, SetOpcodeNoOperand) } // Negative test detecting an incomplete instruction: missing instruction tag -TEST_F(AvmMiniExecutionTests, truncatedInstructionNoTag) +TEST_F(AvmExecutionTests, truncatedInstructionNoTag) { std::string bytecode_hex = to_hex(OpCode::ADD) + // opcode ADD "02" // U16 @@ -507,7 +507,7 @@ TEST_F(AvmMiniExecutionTests, truncatedInstructionNoTag) } // Negative test detecting an incomplete instruction: instruction tag present but an operand is missing -TEST_F(AvmMiniExecutionTests, truncatedInstructionNoOperand) +TEST_F(AvmExecutionTests, truncatedInstructionNoOperand) { std::string bytecode_hex = to_hex(OpCode::ADD) + // opcode ADD "02" // U16 diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp similarity index 68% rename from barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp rename to barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp index ec82799eb71..5c357d1bad7 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp @@ -1,20 +1,20 @@ -#include "AvmMini_common.test.hpp" +#include "avm_common.test.hpp" using namespace bb; namespace tests_avm { using namespace avm_trace; -class AvmMiniMemoryTests : public ::testing::Test { +class AvmMemoryTests : public ::testing::Test { public: - AvmMiniTraceBuilder trace_builder; + AvmTraceBuilder trace_builder; protected: // TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialised for every test. void SetUp() override { srs::init_crs_factory("../srs_db/ignition"); - trace_builder = AvmMiniTraceBuilder(); // Clean instance for every run. + trace_builder = AvmTraceBuilder(); // Clean instance for every run. }; }; @@ -24,7 +24,7 @@ class AvmMiniMemoryTests : public ::testing::Test { * ****************************************************************************** * This test suite focuses on non-trivial memory-related tests which are - * not implicitly covered by other tests such as AvmMiniArithmeticTests. + * not implicitly covered by other tests such as AvmArithmeticTests. * * For instance, tests on checking error conditions related to memory or * violation of memory-related relations in malicious/malformed execution @@ -33,7 +33,7 @@ class AvmMiniMemoryTests : public ::testing::Test { // Testing an operation with a mismatched memory tag. // The proof must pass and we check that the AVM error is raised. -TEST_F(AvmMiniMemoryTests, mismatchedTag) +TEST_F(AvmMemoryTests, mismatchedTag) { trace_builder.calldata_copy(0, 2, 0, std::vector{ 98, 12 }); @@ -42,45 +42,45 @@ TEST_F(AvmMiniMemoryTests, mismatchedTag) auto trace = trace_builder.finalize(); // Find the first row enabling the addition selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_add == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_add == FF(1); }); EXPECT_TRUE(row != trace.end()); // All intermediate registers should be set to zero. - EXPECT_EQ(row->avmMini_ia, FF(0)); - EXPECT_EQ(row->avmMini_ib, FF(0)); - EXPECT_EQ(row->avmMini_ic, FF(0)); + EXPECT_EQ(row->avm_main_ia, FF(0)); + EXPECT_EQ(row->avm_main_ib, FF(0)); + EXPECT_EQ(row->avm_main_ic, FF(0)); - auto clk = row->avmMini_clk; + auto clk = row->avm_main_clk; // Find the memory trace position corresponding to the add sub-operation of register ia. row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.memTrace_m_clk == clk && r.memTrace_m_sub_clk == AvmMiniMemTraceBuilder::SUB_CLK_LOAD_A; + return r.avm_mem_m_clk == clk && r.avm_mem_m_sub_clk == AvmMemTraceBuilder::SUB_CLK_LOAD_A; }); EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->memTrace_m_tag_err, FF(1)); // Error is raised - EXPECT_EQ(row->memTrace_m_in_tag, FF(static_cast(AvmMemoryTag::U8))); - EXPECT_EQ(row->memTrace_m_tag, FF(static_cast(AvmMemoryTag::FF))); + EXPECT_EQ(row->avm_mem_m_tag_err, FF(1)); // Error is raised + EXPECT_EQ(row->avm_mem_m_in_tag, FF(static_cast(AvmMemoryTag::U8))); + EXPECT_EQ(row->avm_mem_m_tag, FF(static_cast(AvmMemoryTag::FF))); // Find the memory trace position corresponding to the add sub-operation of register ib. row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.memTrace_m_clk == clk && r.memTrace_m_sub_clk == AvmMiniMemTraceBuilder::SUB_CLK_LOAD_B; + return r.avm_mem_m_clk == clk && r.avm_mem_m_sub_clk == AvmMemTraceBuilder::SUB_CLK_LOAD_B; }); EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->memTrace_m_tag_err, FF(1)); // Error is raised - EXPECT_EQ(row->memTrace_m_in_tag, FF(static_cast(AvmMemoryTag::U8))); - EXPECT_EQ(row->memTrace_m_tag, FF(static_cast(AvmMemoryTag::FF))); + EXPECT_EQ(row->avm_mem_m_tag_err, FF(1)); // Error is raised + EXPECT_EQ(row->avm_mem_m_in_tag, FF(static_cast(AvmMemoryTag::U8))); + EXPECT_EQ(row->avm_mem_m_tag, FF(static_cast(AvmMemoryTag::FF))); validate_trace_proof(std::move(trace)); } // Testing violation that m_lastAccess is a delimiter for two different addresses // in the memory trace -TEST_F(AvmMiniMemoryTests, mLastAccessViolation) +TEST_F(AvmMemoryTests, mLastAccessViolation) { trace_builder.calldata_copy(0, 2, 0, std::vector{ 4, 9 }); @@ -90,27 +90,27 @@ TEST_F(AvmMiniMemoryTests, mLastAccessViolation) auto trace = trace_builder.finalize(); // Find the row with subtraction operation - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_sub == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == FF(1); }); EXPECT_TRUE(row != trace.end()); - auto clk = row->avmMini_clk; + auto clk = row->avm_main_clk; // Find the row for memory trace with last memory entry for address 1 (read for subtraction) row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.memTrace_m_clk == clk && r.memTrace_m_addr == FF(1) && - r.memTrace_m_sub_clk == AvmMiniMemTraceBuilder::SUB_CLK_LOAD_A; + return r.avm_mem_m_clk == clk && r.avm_mem_m_addr == FF(1) && + r.avm_mem_m_sub_clk == AvmMemTraceBuilder::SUB_CLK_LOAD_A; }); EXPECT_TRUE(row != trace.end()); - row->memTrace_m_lastAccess = FF(0); + row->avm_mem_m_lastAccess = FF(0); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "MEM_LAST_ACCESS_DELIMITER"); } // Testing violation that a memory read operation must read the same value which was // written into memory -TEST_F(AvmMiniMemoryTests, readWriteConsistencyValViolation) +TEST_F(AvmMemoryTests, readWriteConsistencyValViolation) { trace_builder.calldata_copy(0, 2, 0, std::vector{ 4, 9 }); @@ -120,27 +120,27 @@ TEST_F(AvmMiniMemoryTests, readWriteConsistencyValViolation) auto trace = trace_builder.finalize(); // Find the row with multiplication operation - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_mul == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == FF(1); }); EXPECT_TRUE(row != trace.end()); - auto clk = row->avmMini_clk + 1; // return operation is just after the multiplication + auto clk = row->avm_main_clk + 1; // return operation is just after the multiplication // Find the row for memory trace with last memory entry for address 2 (read for multiplication) row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.memTrace_m_clk == clk && r.memTrace_m_addr == FF(2) && - r.memTrace_m_sub_clk == AvmMiniMemTraceBuilder::SUB_CLK_LOAD_A; + return r.avm_mem_m_clk == clk && r.avm_mem_m_addr == FF(2) && + r.avm_mem_m_sub_clk == AvmMemTraceBuilder::SUB_CLK_LOAD_A; }); EXPECT_TRUE(row != trace.end()); - row->memTrace_m_val = FF(35); + row->avm_mem_m_val = FF(35); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "MEM_READ_WRITE_VAL_CONSISTENCY"); } // Testing violation that memory read operation must read the same tag which was // written into memory -TEST_F(AvmMiniMemoryTests, readWriteConsistencyTagViolation) +TEST_F(AvmMemoryTests, readWriteConsistencyTagViolation) { trace_builder.calldata_copy(0, 2, 0, std::vector{ 4, 9 }); @@ -150,38 +150,38 @@ TEST_F(AvmMiniMemoryTests, readWriteConsistencyTagViolation) auto trace = trace_builder.finalize(); // Find the row with multiplication operation - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_mul == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == FF(1); }); EXPECT_TRUE(row != trace.end()); - auto clk = row->avmMini_clk + 1; // return operation is just after the multiplication + auto clk = row->avm_main_clk + 1; // return operation is just after the multiplication // Find the row for memory trace with last memory entry for address 2 (read for multiplication) row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.memTrace_m_clk == clk && r.memTrace_m_addr == FF(2) && - r.memTrace_m_sub_clk == AvmMiniMemTraceBuilder::SUB_CLK_LOAD_A; + return r.avm_mem_m_clk == clk && r.avm_mem_m_addr == FF(2) && + r.avm_mem_m_sub_clk == AvmMemTraceBuilder::SUB_CLK_LOAD_A; }); EXPECT_TRUE(row != trace.end()); - row->memTrace_m_tag = static_cast(AvmMemoryTag::U16); + row->avm_mem_m_tag = static_cast(AvmMemoryTag::U16); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "MEM_READ_WRITE_TAG_CONSISTENCY"); } // Testing violation that a memory read at uninitialized location must have value 0. -TEST_F(AvmMiniMemoryTests, readUninitializedMemoryViolation) +TEST_F(AvmMemoryTests, readUninitializedMemoryViolation) { trace_builder.return_op(1, 1); // Return single memory word at position 1 auto trace = trace_builder.finalize(); - trace[1].memTrace_m_val = 9; + trace[1].avm_mem_m_val = 9; EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "MEM_ZERO_INIT"); } // Testing violation that an operation with a mismatched memory tag // must raise a VM error. -TEST_F(AvmMiniMemoryTests, mismatchedTagErrorViolation) +TEST_F(AvmMemoryTests, mismatchedTagErrorViolation) { trace_builder.calldata_copy(0, 2, 0, std::vector{ 98, 12 }); @@ -190,32 +190,32 @@ TEST_F(AvmMiniMemoryTests, mismatchedTagErrorViolation) auto trace = trace_builder.finalize(); // Find the first row enabling the subtraction selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_sub == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == FF(1); }); EXPECT_TRUE(row != trace.end()); - auto clk = row->avmMini_clk; + auto clk = row->avm_main_clk; // Find the memory trace position corresponding to the subtraction sub-operation of register ia. row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.memTrace_m_clk == clk && r.memTrace_m_sub_clk == AvmMiniMemTraceBuilder::SUB_CLK_LOAD_A; + return r.avm_mem_m_clk == clk && r.avm_mem_m_sub_clk == AvmMemTraceBuilder::SUB_CLK_LOAD_A; }); - row->memTrace_m_tag_err = FF(0); + row->avm_mem_m_tag_err = FF(0); auto index = static_cast(row - trace.begin()); auto trace2 = trace; EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "MEM_IN_TAG_CONSISTENCY_1"); // More sophisticated attempt by adapting witness "on_min_inv" to make pass the above constraint - trace2[index].memTrace_m_one_min_inv = FF(1); + trace2[index].avm_mem_m_one_min_inv = FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace2)), "MEM_IN_TAG_CONSISTENCY_2"); } // Testing violation that an operation with a consistent memory tag // must not set a VM error. -TEST_F(AvmMiniMemoryTests, consistentTagNoErrorViolation) +TEST_F(AvmMemoryTests, consistentTagNoErrorViolation) { trace_builder.calldata_copy(0, 2, 0, std::vector{ 84, 7 }); @@ -224,18 +224,18 @@ TEST_F(AvmMiniMemoryTests, consistentTagNoErrorViolation) auto trace = trace_builder.finalize(); // Find the first row enabling the division selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avmMini_sel_op_div == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_div == FF(1); }); EXPECT_TRUE(row != trace.end()); - auto clk = row->avmMini_clk; + auto clk = row->avm_main_clk; // Find the memory trace position corresponding to the div sub-operation of register ia. row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.memTrace_m_clk == clk && r.memTrace_m_sub_clk == AvmMiniMemTraceBuilder::SUB_CLK_LOAD_A; + return r.avm_mem_m_clk == clk && r.avm_mem_m_sub_clk == AvmMemTraceBuilder::SUB_CLK_LOAD_A; }); - row->memTrace_m_tag_err = FF(1); + row->avm_mem_m_tag_err = FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "MEM_IN_TAG_CONSISTENCY_1"); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp index 28e82af7643..9cf2a3b334e 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp @@ -1,4 +1,4 @@ -#include "AvmMini_common.test.hpp" +#include "avm_common.test.hpp" using namespace bb; @@ -10,12 +10,12 @@ namespace tests_avm { */ void validate_trace_proof(std::vector&& trace) { - auto circuit_builder = AvmMiniCircuitBuilder(); + auto circuit_builder = AvmCircuitBuilder(); circuit_builder.set_trace(std::move(trace)); EXPECT_TRUE(circuit_builder.check_circuit()); - auto composer = AvmMiniComposer(); + auto composer = AvmComposer(); auto prover = composer.create_prover(circuit_builder); auto proof = prover.construct_proof(); @@ -23,7 +23,7 @@ void validate_trace_proof(std::vector&& trace) bool verified = verifier.verify_proof(proof); if (!verified) { - avm_trace::log_avmMini_trace(circuit_builder.rows, 0, 10); + avm_trace::log_avm_trace(circuit_builder.rows, 0, 10); } }; @@ -45,29 +45,28 @@ void mutate_ic_in_trace(std::vector& trace, std::function&& sele EXPECT_TRUE(row != trace.end()); // Mutate the correct result in the main trace - row->avmMini_ic = newValue; + row->avm_main_ic = newValue; // Optionally mutate the corresponding ic value in alu if (alu) { - auto const clk = row->avmMini_clk; + auto const clk = row->avm_main_clk; // Find the relevant alu trace entry. auto alu_row = - std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.aluChip_alu_clk == clk; }); + std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_alu_clk == clk; }); EXPECT_TRUE(alu_row != trace.end()); - alu_row->aluChip_alu_ic = newValue; + alu_row->avm_alu_alu_ic = newValue; } // Adapt the memory trace to be consistent with the wrong result - auto const clk = row->avmMini_clk; - auto const addr = row->avmMini_mem_idx_c; + auto const clk = row->avm_main_clk; + auto const addr = row->avm_main_mem_idx_c; // Find the relevant memory trace entry. - auto mem_row = std::ranges::find_if(trace.begin(), trace.end(), [clk, addr](Row r) { - return r.memTrace_m_clk == clk && r.memTrace_m_addr == addr; - }); + auto mem_row = std::ranges::find_if( + trace.begin(), trace.end(), [clk, addr](Row r) { return r.avm_mem_m_clk == clk && r.avm_mem_m_addr == addr; }); EXPECT_TRUE(mem_row != trace.end()); - mem_row->memTrace_m_val = newValue; + mem_row->avm_mem_m_val = newValue; }; } // namespace tests_avm diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp index d6071fe421e..c794f7c5e13 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp @@ -1,6 +1,6 @@ #pragma once -#include "barretenberg/vm/avm_trace/AvmMini_trace.hpp" +#include "barretenberg/vm/avm_trace/avm_trace.hpp" #define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage) \ try { \ @@ -12,9 +12,9 @@ } namespace tests_avm { -using Flavor = bb::AvmMiniFlavor; +using Flavor = bb::AvmFlavor; using FF = Flavor::FF; -using Row = bb::AvmMiniFullRow; +using Row = bb::AvmFullRow; void validate_trace_proof(std::vector&& trace); void mutate_ic_in_trace(std::vector& trace, diff --git a/yarn-project/simulator/src/avm/serialization/instruction_serialization.ts b/yarn-project/simulator/src/avm/serialization/instruction_serialization.ts index 565fda5a832..d4d2a3a32c6 100644 --- a/yarn-project/simulator/src/avm/serialization/instruction_serialization.ts +++ b/yarn-project/simulator/src/avm/serialization/instruction_serialization.ts @@ -3,7 +3,7 @@ import { strict as assert } from 'assert'; import { BufferCursor } from './buffer_cursor.js'; /** - * All AVM opcodes. (Keep in sync with cpp counterpart code AvmMini_opcode.hpp). + * All AVM opcodes. (Keep in sync with cpp counterpart code avm_opcode.hpp). * Source: https://yp-aztec.netlify.app/docs/public-vm/instruction-set */ export enum Opcode { @@ -70,7 +70,7 @@ export enum Opcode { } // Possible types for an instruction's operand in its wire format. (Keep in sync with CPP code. -// See vm/avm_trace/AvmMini_deserialization.cpp) +// See vm/avm_trace/avm_deserialization.cpp) // Note that cpp code introduced an additional enum value TAG to express the instruction tag. In TS, // this one is parsed as UINT8. export enum OperandType {