From a74dccbdef0939b77978ddec3875b1afc2d0b530 Mon Sep 17 00:00:00 2001 From: Jean M <132435771+jeanmon@users.noreply.github.com> Date: Tue, 12 Mar 2024 10:42:46 +0100 Subject: [PATCH] test(AVM): Negative unit tests for inter table relations (#5143) Resolves #5033 --- barretenberg/cpp/pil/avm/avm_main.pil | 10 +- .../flavor/generated/avm_flavor.hpp | 214 +++++----- .../generated/avm_circuit_builder.hpp | 98 ++--- .../relations/generated/avm/avm_alu.hpp | 74 ++-- .../relations/generated/avm/avm_main.hpp | 80 ++-- .../relations/generated/avm/avm_mem.hpp | 34 +- .../relations/generated/avm/declare_views.hpp | 34 +- ...quiv_tag_err.hpp => incl_main_tag_err.hpp} | 15 +- ...iv_inter_reg_alu.hpp => perm_main_alu.hpp} | 10 +- ...uiv_main_mem_a.hpp => perm_main_mem_a.hpp} | 10 +- ...uiv_main_mem_b.hpp => perm_main_mem_b.hpp} | 10 +- ...uiv_main_mem_c.hpp => perm_main_mem_c.hpp} | 10 +- .../barretenberg/vm/avm_trace/avm_trace.cpp | 2 +- .../vm/generated/avm_verifier.cpp | 22 +- .../vm/tests/avm_arithmetic.test.cpp | 11 +- .../vm/tests/avm_bitwise.test.cpp | 9 +- .../vm/tests/avm_control_flow.test.cpp | 2 - .../vm/tests/avm_execution.test.cpp | 5 +- .../vm/tests/avm_inter_table.test.cpp | 384 ++++++++++++++++++ .../barretenberg/vm/tests/avm_memory.test.cpp | 2 - .../barretenberg/vm/tests/helpers.test.cpp | 2 - 21 files changed, 702 insertions(+), 336 deletions(-) rename barretenberg/cpp/src/barretenberg/relations/generated/avm/{equiv_tag_err.hpp => incl_main_tag_err.hpp} (92%) rename barretenberg/cpp/src/barretenberg/relations/generated/avm/{equiv_inter_reg_alu.hpp => perm_main_alu.hpp} (93%) rename barretenberg/cpp/src/barretenberg/relations/generated/avm/{equiv_main_mem_a.hpp => perm_main_mem_a.hpp} (92%) rename barretenberg/cpp/src/barretenberg/relations/generated/avm/{equiv_main_mem_b.hpp => perm_main_mem_b.hpp} (92%) rename barretenberg/cpp/src/barretenberg/relations/generated/avm/{equiv_main_mem_c.hpp => perm_main_mem_c.hpp} (92%) create mode 100644 barretenberg/cpp/src/barretenberg/vm/tests/avm_inter_table.test.cpp diff --git a/barretenberg/cpp/pil/avm/avm_main.pil b/barretenberg/cpp/pil/avm/avm_main.pil index 4173f2eb1e9..37a32778bdb 100644 --- a/barretenberg/cpp/pil/avm/avm_main.pil +++ b/barretenberg/cpp/pil/avm/avm_main.pil @@ -190,7 +190,7 @@ namespace avm_main(256); // Inter-table Constraints - #[equiv_tag_err] + #[INCL_MAIN_TAG_ERR] avm_mem.m_tag_err {avm_mem.m_clk} in tag_err {clk}; // Predicate to activate the copy of intermediate registers to ALU table. If tag_err == 1, @@ -198,7 +198,7 @@ namespace avm_main(256); // TODO: when division is moved to the alu, we will need to add the selector in the list below: alu_sel = (sel_op_add + sel_op_sub + sel_op_mul + sel_op_not + sel_op_eq) * (1 - tag_err); - #[equiv_inter_reg_alu] + #[PERM_MAIN_ALU] alu_sel {clk, ia, ib, ic, sel_op_add, sel_op_sub, sel_op_mul, sel_op_eq, sel_op_not, in_tag} @@ -207,17 +207,17 @@ namespace avm_main(256); avm_alu.alu_op_add, avm_alu.alu_op_sub, avm_alu.alu_op_mul, avm_alu.alu_op_eq, avm_alu.alu_op_not, avm_alu.alu_in_tag}; - #[equiv_main_mem_a] + #[PERM_MAIN_MEM_A] mem_op_a {clk, mem_idx_a, ia, rwa, in_tag} is avm_mem.m_op_a {avm_mem.m_clk, avm_mem.m_addr, avm_mem.m_val, avm_mem.m_rw, avm_mem.m_in_tag}; - #[equiv_main_mem_b] + #[PERM_MAIN_MEM_B] mem_op_b {clk, mem_idx_b, ib, rwb, in_tag} is avm_mem.m_op_b {avm_mem.m_clk, avm_mem.m_addr, avm_mem.m_val, avm_mem.m_rw, avm_mem.m_in_tag}; - #[equiv_main_mem_c] + #[PERM_MAIN_MEM_C] mem_op_c {clk, mem_idx_c, ic, rwc, in_tag} is avm_mem.m_op_c {avm_mem.m_clk, avm_mem.m_addr, avm_mem.m_val, avm_mem.m_rw, avm_mem.m_in_tag}; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp index 1b5c5fd9e10..88ca63d463d 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp @@ -16,10 +16,10 @@ #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/relations/generated/avm/equiv_inter_reg_alu.hpp" -#include "barretenberg/relations/generated/avm/equiv_main_mem_a.hpp" -#include "barretenberg/relations/generated/avm/equiv_main_mem_b.hpp" -#include "barretenberg/relations/generated/avm/equiv_main_mem_c.hpp" +#include "barretenberg/relations/generated/avm/perm_main_alu.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_a.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_b.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_c.hpp" #include "barretenberg/transcript/transcript.hpp" namespace bb { @@ -47,13 +47,13 @@ class AvmFlavor { // the unshifted and one for the shifted static constexpr size_t NUM_ALL_ENTITIES = 97; - using Relations = std::tuple, + using Relations = std::tuple, Avm_vm::avm_alu, - Avm_vm::avm_mem, - equiv_inter_reg_alu_relation, - equiv_main_mem_a_relation, - equiv_main_mem_b_relation, - equiv_main_mem_c_relation>; + Avm_vm::avm_main, + perm_main_alu_relation, + perm_main_mem_a_relation, + perm_main_mem_b_relation, + perm_main_mem_c_relation>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -162,12 +162,12 @@ class AvmFlavor { avm_main_mem_idx_b, avm_main_mem_idx_c, avm_main_last, - equiv_inter_reg_alu, - equiv_main_mem_a, - equiv_main_mem_b, - equiv_main_mem_c, - equiv_tag_err, - equiv_tag_err_counts) + perm_main_alu, + perm_main_mem_a, + perm_main_mem_b, + perm_main_mem_c, + incl_main_tag_err, + incl_main_tag_err_counts) RefVector get_wires() { @@ -246,12 +246,12 @@ class AvmFlavor { avm_main_mem_idx_b, avm_main_mem_idx_c, avm_main_last, - equiv_inter_reg_alu, - equiv_main_mem_a, - equiv_main_mem_b, - equiv_main_mem_c, - equiv_tag_err, - equiv_tag_err_counts }; + perm_main_alu, + perm_main_mem_a, + perm_main_mem_b, + perm_main_mem_c, + incl_main_tag_err, + incl_main_tag_err_counts }; }; RefVector get_sorted_polynomials() { return {}; }; }; @@ -336,26 +336,26 @@ class AvmFlavor { avm_main_mem_idx_b, avm_main_mem_idx_c, avm_main_last, - equiv_inter_reg_alu, - equiv_main_mem_a, - equiv_main_mem_b, - equiv_main_mem_c, - equiv_tag_err, - equiv_tag_err_counts, - avm_main_pc_shift, - avm_main_internal_return_ptr_shift, - avm_alu_alu_u16_r7_shift, - avm_alu_alu_u16_r3_shift, - avm_alu_alu_u16_r0_shift, - avm_alu_alu_u16_r1_shift, - avm_alu_alu_u16_r2_shift, + perm_main_alu, + perm_main_mem_a, + perm_main_mem_b, + perm_main_mem_c, + incl_main_tag_err, + incl_main_tag_err_counts, + avm_mem_m_tag_shift, + avm_mem_m_val_shift, + avm_mem_m_rw_shift, + avm_mem_m_addr_shift, avm_alu_alu_u16_r5_shift, + avm_alu_alu_u16_r3_shift, avm_alu_alu_u16_r4_shift, + avm_alu_alu_u16_r7_shift, + avm_alu_alu_u16_r1_shift, + avm_alu_alu_u16_r0_shift, avm_alu_alu_u16_r6_shift, - avm_mem_m_tag_shift, - avm_mem_m_addr_shift, - avm_mem_m_val_shift, - avm_mem_m_rw_shift) + avm_alu_alu_u16_r2_shift, + avm_main_pc_shift, + avm_main_internal_return_ptr_shift) RefVector get_wires() { @@ -436,26 +436,26 @@ class AvmFlavor { avm_main_mem_idx_b, avm_main_mem_idx_c, avm_main_last, - equiv_inter_reg_alu, - equiv_main_mem_a, - equiv_main_mem_b, - equiv_main_mem_c, - equiv_tag_err, - equiv_tag_err_counts, - avm_main_pc_shift, - avm_main_internal_return_ptr_shift, - avm_alu_alu_u16_r7_shift, - avm_alu_alu_u16_r3_shift, - avm_alu_alu_u16_r0_shift, - avm_alu_alu_u16_r1_shift, - avm_alu_alu_u16_r2_shift, + perm_main_alu, + perm_main_mem_a, + perm_main_mem_b, + perm_main_mem_c, + incl_main_tag_err, + incl_main_tag_err_counts, + avm_mem_m_tag_shift, + avm_mem_m_val_shift, + avm_mem_m_rw_shift, + avm_mem_m_addr_shift, avm_alu_alu_u16_r5_shift, + avm_alu_alu_u16_r3_shift, avm_alu_alu_u16_r4_shift, + avm_alu_alu_u16_r7_shift, + avm_alu_alu_u16_r1_shift, + avm_alu_alu_u16_r0_shift, avm_alu_alu_u16_r6_shift, - avm_mem_m_tag_shift, - avm_mem_m_addr_shift, - avm_mem_m_val_shift, - avm_mem_m_rw_shift }; + avm_alu_alu_u16_r2_shift, + avm_main_pc_shift, + avm_main_internal_return_ptr_shift }; }; RefVector get_unshifted() { @@ -536,32 +536,32 @@ class AvmFlavor { avm_main_mem_idx_b, avm_main_mem_idx_c, avm_main_last, - equiv_inter_reg_alu, - equiv_main_mem_a, - equiv_main_mem_b, - equiv_main_mem_c, - equiv_tag_err, - equiv_tag_err_counts }; + perm_main_alu, + perm_main_mem_a, + perm_main_mem_b, + perm_main_mem_c, + incl_main_tag_err, + incl_main_tag_err_counts }; }; RefVector get_to_be_shifted() { - return { avm_main_pc, avm_main_internal_return_ptr, - avm_alu_alu_u16_r7, avm_alu_alu_u16_r3, - avm_alu_alu_u16_r0, avm_alu_alu_u16_r1, - avm_alu_alu_u16_r2, avm_alu_alu_u16_r5, - avm_alu_alu_u16_r4, avm_alu_alu_u16_r6, - avm_mem_m_tag, avm_mem_m_addr, - avm_mem_m_val, avm_mem_m_rw }; + return { avm_mem_m_tag, avm_mem_m_val, + avm_mem_m_rw, avm_mem_m_addr, + avm_alu_alu_u16_r5, avm_alu_alu_u16_r3, + avm_alu_alu_u16_r4, avm_alu_alu_u16_r7, + avm_alu_alu_u16_r1, avm_alu_alu_u16_r0, + avm_alu_alu_u16_r6, avm_alu_alu_u16_r2, + avm_main_pc, avm_main_internal_return_ptr }; }; RefVector get_shifted() { - return { avm_main_pc_shift, avm_main_internal_return_ptr_shift, - avm_alu_alu_u16_r7_shift, avm_alu_alu_u16_r3_shift, - avm_alu_alu_u16_r0_shift, avm_alu_alu_u16_r1_shift, - avm_alu_alu_u16_r2_shift, avm_alu_alu_u16_r5_shift, - avm_alu_alu_u16_r4_shift, avm_alu_alu_u16_r6_shift, - avm_mem_m_tag_shift, avm_mem_m_addr_shift, - avm_mem_m_val_shift, avm_mem_m_rw_shift }; + return { avm_mem_m_tag_shift, avm_mem_m_val_shift, + avm_mem_m_rw_shift, avm_mem_m_addr_shift, + avm_alu_alu_u16_r5_shift, avm_alu_alu_u16_r3_shift, + avm_alu_alu_u16_r4_shift, avm_alu_alu_u16_r7_shift, + avm_alu_alu_u16_r1_shift, avm_alu_alu_u16_r0_shift, + avm_alu_alu_u16_r6_shift, avm_alu_alu_u16_r2_shift, + avm_main_pc_shift, avm_main_internal_return_ptr_shift }; }; }; @@ -574,13 +574,13 @@ class AvmFlavor { RefVector get_to_be_shifted() { - return { avm_main_pc, avm_main_internal_return_ptr, - avm_alu_alu_u16_r7, avm_alu_alu_u16_r3, - avm_alu_alu_u16_r0, avm_alu_alu_u16_r1, - avm_alu_alu_u16_r2, avm_alu_alu_u16_r5, - avm_alu_alu_u16_r4, avm_alu_alu_u16_r6, - avm_mem_m_tag, avm_mem_m_addr, - avm_mem_m_val, avm_mem_m_rw }; + return { avm_mem_m_tag, avm_mem_m_val, + avm_mem_m_rw, avm_mem_m_addr, + avm_alu_alu_u16_r5, avm_alu_alu_u16_r3, + avm_alu_alu_u16_r4, avm_alu_alu_u16_r7, + avm_alu_alu_u16_r1, avm_alu_alu_u16_r0, + avm_alu_alu_u16_r6, avm_alu_alu_u16_r2, + avm_main_pc, avm_main_internal_return_ptr }; }; // The plookup wires that store plookup read data. @@ -734,12 +734,12 @@ class AvmFlavor { 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"; - Base::equiv_inter_reg_alu = "EQUIV_INTER_REG_ALU"; - Base::equiv_main_mem_a = "EQUIV_MAIN_MEM_A"; - Base::equiv_main_mem_b = "EQUIV_MAIN_MEM_B"; - Base::equiv_main_mem_c = "EQUIV_MAIN_MEM_C"; - Base::equiv_tag_err = "EQUIV_TAG_ERR"; - Base::equiv_tag_err_counts = "EQUIV_TAG_ERR_COUNTS"; + Base::perm_main_alu = "PERM_MAIN_ALU"; + Base::perm_main_mem_a = "PERM_MAIN_MEM_A"; + Base::perm_main_mem_b = "PERM_MAIN_MEM_B"; + Base::perm_main_mem_c = "PERM_MAIN_MEM_C"; + Base::incl_main_tag_err = "INCL_MAIN_TAG_ERR"; + Base::incl_main_tag_err_counts = "INCL_MAIN_TAG_ERR_COUNTS"; }; }; @@ -834,12 +834,12 @@ class AvmFlavor { Commitment avm_main_mem_idx_b; Commitment avm_main_mem_idx_c; Commitment avm_main_last; - Commitment equiv_inter_reg_alu; - Commitment equiv_main_mem_a; - Commitment equiv_main_mem_b; - Commitment equiv_main_mem_c; - Commitment equiv_tag_err; - Commitment equiv_tag_err_counts; + Commitment perm_main_alu; + Commitment perm_main_mem_a; + Commitment perm_main_mem_b; + Commitment perm_main_mem_c; + Commitment incl_main_tag_err; + Commitment incl_main_tag_err_counts; std::vector> sumcheck_univariates; std::array sumcheck_evaluations; @@ -934,12 +934,12 @@ class AvmFlavor { 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); - equiv_inter_reg_alu = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - equiv_main_mem_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - equiv_main_mem_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - equiv_main_mem_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - equiv_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - equiv_tag_err_counts = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + perm_main_alu = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + perm_main_mem_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + perm_main_mem_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + perm_main_mem_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + incl_main_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + incl_main_tag_err_counts = deserialize_from_buffer(Transcript::proof_data, num_frs_read); for (size_t i = 0; i < log_n; ++i) { sumcheck_univariates.emplace_back( @@ -1038,12 +1038,12 @@ class AvmFlavor { 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); - serialize_to_buffer(equiv_inter_reg_alu, Transcript::proof_data); - serialize_to_buffer(equiv_main_mem_a, Transcript::proof_data); - serialize_to_buffer(equiv_main_mem_b, Transcript::proof_data); - serialize_to_buffer(equiv_main_mem_c, Transcript::proof_data); - serialize_to_buffer(equiv_tag_err, Transcript::proof_data); - serialize_to_buffer(equiv_tag_err_counts, Transcript::proof_data); + serialize_to_buffer(perm_main_alu, Transcript::proof_data); + serialize_to_buffer(perm_main_mem_a, Transcript::proof_data); + serialize_to_buffer(perm_main_mem_b, Transcript::proof_data); + serialize_to_buffer(perm_main_mem_c, Transcript::proof_data); + serialize_to_buffer(incl_main_tag_err, Transcript::proof_data); + serialize_to_buffer(incl_main_tag_err_counts, Transcript::proof_data); for (size_t i = 0; i < log_n; ++i) { serialize_to_buffer(sumcheck_univariates[i], Transcript::proof_data); 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 index f38eb7884d9..7090216f452 100644 --- 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 @@ -15,11 +15,11 @@ #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/relations/generated/avm/equiv_inter_reg_alu.hpp" -#include "barretenberg/relations/generated/avm/equiv_main_mem_a.hpp" -#include "barretenberg/relations/generated/avm/equiv_main_mem_b.hpp" -#include "barretenberg/relations/generated/avm/equiv_main_mem_c.hpp" -#include "barretenberg/relations/generated/avm/equiv_tag_err.hpp" +#include "barretenberg/relations/generated/avm/incl_main_tag_err.hpp" +#include "barretenberg/relations/generated/avm/perm_main_alu.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_a.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_b.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_c.hpp" namespace bb { @@ -101,26 +101,26 @@ template struct AvmFullRow { FF avm_main_mem_idx_b{}; FF avm_main_mem_idx_c{}; FF avm_main_last{}; - FF equiv_inter_reg_alu{}; - FF equiv_main_mem_a{}; - FF equiv_main_mem_b{}; - FF equiv_main_mem_c{}; - FF equiv_tag_err{}; - FF equiv_tag_err_counts{}; - FF avm_main_pc_shift{}; - FF avm_main_internal_return_ptr_shift{}; - FF avm_alu_alu_u16_r7_shift{}; - FF avm_alu_alu_u16_r3_shift{}; - FF avm_alu_alu_u16_r0_shift{}; - FF avm_alu_alu_u16_r1_shift{}; - FF avm_alu_alu_u16_r2_shift{}; - FF avm_alu_alu_u16_r5_shift{}; - FF avm_alu_alu_u16_r4_shift{}; - FF avm_alu_alu_u16_r6_shift{}; + FF perm_main_alu{}; + FF perm_main_mem_a{}; + FF perm_main_mem_b{}; + FF perm_main_mem_c{}; + FF incl_main_tag_err{}; + FF incl_main_tag_err_counts{}; FF avm_mem_m_tag_shift{}; - FF avm_mem_m_addr_shift{}; FF avm_mem_m_val_shift{}; FF avm_mem_m_rw_shift{}; + FF avm_mem_m_addr_shift{}; + FF avm_alu_alu_u16_r5_shift{}; + FF avm_alu_alu_u16_r3_shift{}; + FF avm_alu_alu_u16_r4_shift{}; + FF avm_alu_alu_u16_r7_shift{}; + FF avm_alu_alu_u16_r1_shift{}; + FF avm_alu_alu_u16_r0_shift{}; + FF avm_alu_alu_u16_r6_shift{}; + FF avm_alu_alu_u16_r2_shift{}; + FF avm_main_pc_shift{}; + FF avm_main_internal_return_ptr_shift{}; }; class AvmCircuitBuilder { @@ -227,28 +227,28 @@ class AvmCircuitBuilder { 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.equiv_inter_reg_alu[i] = rows[i].equiv_inter_reg_alu; - polys.equiv_main_mem_a[i] = rows[i].equiv_main_mem_a; - polys.equiv_main_mem_b[i] = rows[i].equiv_main_mem_b; - polys.equiv_main_mem_c[i] = rows[i].equiv_main_mem_c; - polys.equiv_tag_err[i] = rows[i].equiv_tag_err; - polys.equiv_tag_err_counts[i] = rows[i].equiv_tag_err_counts; + polys.perm_main_alu[i] = rows[i].perm_main_alu; + polys.perm_main_mem_a[i] = rows[i].perm_main_mem_a; + polys.perm_main_mem_b[i] = rows[i].perm_main_mem_b; + polys.perm_main_mem_c[i] = rows[i].perm_main_mem_c; + polys.incl_main_tag_err[i] = rows[i].incl_main_tag_err; + polys.incl_main_tag_err_counts[i] = rows[i].incl_main_tag_err_counts; } - 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_alu_alu_u16_r7_shift = Polynomial(polys.avm_alu_alu_u16_r7.shifted()); - polys.avm_alu_alu_u16_r3_shift = Polynomial(polys.avm_alu_alu_u16_r3.shifted()); - polys.avm_alu_alu_u16_r0_shift = Polynomial(polys.avm_alu_alu_u16_r0.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_r5_shift = Polynomial(polys.avm_alu_alu_u16_r5.shifted()); - polys.avm_alu_alu_u16_r4_shift = Polynomial(polys.avm_alu_alu_u16_r4.shifted()); - polys.avm_alu_alu_u16_r6_shift = Polynomial(polys.avm_alu_alu_u16_r6.shifted()); polys.avm_mem_m_tag_shift = Polynomial(polys.avm_mem_m_tag.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_rw_shift = Polynomial(polys.avm_mem_m_rw.shifted()); + polys.avm_mem_m_addr_shift = Polynomial(polys.avm_mem_m_addr.shifted()); + polys.avm_alu_alu_u16_r5_shift = Polynomial(polys.avm_alu_alu_u16_r5.shifted()); + polys.avm_alu_alu_u16_r3_shift = Polynomial(polys.avm_alu_alu_u16_r3.shifted()); + polys.avm_alu_alu_u16_r4_shift = Polynomial(polys.avm_alu_alu_u16_r4.shifted()); + polys.avm_alu_alu_u16_r7_shift = Polynomial(polys.avm_alu_alu_u16_r7.shifted()); + polys.avm_alu_alu_u16_r1_shift = Polynomial(polys.avm_alu_alu_u16_r1.shifted()); + polys.avm_alu_alu_u16_r0_shift = Polynomial(polys.avm_alu_alu_u16_r0.shifted()); + polys.avm_alu_alu_u16_r6_shift = Polynomial(polys.avm_alu_alu_u16_r6.shifted()); + polys.avm_alu_alu_u16_r2_shift = Polynomial(polys.avm_alu_alu_u16_r2.shifted()); + 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()); return polys; } @@ -313,39 +313,39 @@ class AvmCircuitBuilder { } for (auto r : lookup_result) { if (r != 0) { - info("Lookup ", lookup_name, " failed."); + throw_or_abort(format("Lookup ", lookup_name, " failed.")); return false; } } return true; }; - if (!evaluate_relation.template operator()>("avm_main", - Avm_vm::get_relation_label_avm_main)) { + 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; } - if (!evaluate_relation.template operator()>("avm_mem", - Avm_vm::get_relation_label_avm_mem)) { + if (!evaluate_relation.template operator()>("avm_main", + Avm_vm::get_relation_label_avm_main)) { return false; } - if (!evaluate_logderivative.template operator()>("equiv_inter_reg_alu")) { + if (!evaluate_logderivative.template operator()>("PERM_MAIN_ALU")) { return false; } - if (!evaluate_logderivative.template operator()>("equiv_main_mem_a")) { + if (!evaluate_logderivative.template operator()>("PERM_MAIN_MEM_A")) { return false; } - if (!evaluate_logderivative.template operator()>("equiv_main_mem_b")) { + if (!evaluate_logderivative.template operator()>("PERM_MAIN_MEM_B")) { return false; } - if (!evaluate_logderivative.template operator()>("equiv_main_mem_c")) { + if (!evaluate_logderivative.template operator()>("PERM_MAIN_MEM_C")) { return false; } - if (!evaluate_logderivative.template operator()>("equiv_tag_err")) { + if (!evaluate_logderivative.template operator()>("INCL_MAIN_TAG_ERR")) { return false; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp index 3c417bd672e..3357e7144e5 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp @@ -7,57 +7,48 @@ namespace bb::Avm_vm { template struct Avm_aluRow { + FF avm_alu_alu_op_eq{}; + FF avm_alu_alu_u16_r5{}; FF avm_alu_alu_op_sub{}; - FF avm_alu_alu_ff_tag{}; + FF avm_alu_alu_u16_r5_shift{}; FF avm_alu_alu_u16_r4{}; - FF avm_alu_alu_ib{}; - FF avm_alu_alu_u64_r0{}; - FF avm_alu_alu_u16_r7_shift{}; - FF avm_alu_alu_op_eq{}; + FF avm_alu_alu_u16_r7{}; FF avm_alu_alu_u8_tag{}; - FF avm_alu_alu_cf{}; - FF avm_alu_alu_u16_r2{}; FF avm_alu_alu_u16_r3_shift{}; - FF avm_alu_alu_u16_r0_shift{}; + FF avm_alu_alu_u64_r0{}; FF avm_alu_alu_ia{}; FF avm_alu_alu_u32_tag{}; - FF avm_alu_alu_op_not{}; - FF avm_alu_alu_op_mul{}; - FF avm_alu_alu_sel{}; - FF avm_alu_alu_u64_tag{}; FF avm_alu_alu_in_tag{}; - FF avm_alu_alu_u16_r1{}; - FF avm_alu_alu_u16_r3{}; - FF avm_alu_alu_u16_r5{}; + FF avm_alu_alu_u16_r2{}; + FF avm_alu_alu_u128_tag{}; + FF avm_alu_alu_u16_r0{}; + FF avm_alu_alu_sel{}; + FF avm_alu_alu_ff_tag{}; + FF avm_alu_alu_op_eq_diff_inv{}; + FF avm_alu_alu_ic{}; + FF avm_alu_alu_op_mul{}; + FF avm_alu_alu_cf{}; + FF avm_alu_alu_u16_r4_shift{}; FF avm_alu_alu_u16_r6{}; + FF avm_alu_alu_ib{}; + FF avm_alu_alu_u16_r7_shift{}; + FF avm_alu_alu_op_add{}; FF avm_alu_alu_u16_r1_shift{}; - FF avm_alu_alu_u16_r2_shift{}; - FF avm_alu_alu_ic{}; FF avm_alu_alu_u8_r0{}; + FF avm_alu_alu_op_not{}; FF avm_alu_alu_u16_tag{}; - FF avm_alu_alu_u16_r5_shift{}; - FF avm_alu_alu_op_add{}; - FF avm_alu_alu_u16_r0{}; - FF avm_alu_alu_u16_r7{}; - FF avm_alu_alu_u128_tag{}; - FF avm_alu_alu_op_eq_diff_inv{}; - FF avm_alu_alu_u16_r4_shift{}; + FF avm_alu_alu_u16_r1{}; + FF avm_alu_alu_u16_r0_shift{}; FF avm_alu_alu_u16_r6_shift{}; + FF avm_alu_alu_u64_tag{}; FF avm_alu_alu_u8_r1{}; + FF avm_alu_alu_u16_r3{}; + FF avm_alu_alu_u16_r2_shift{}; }; inline std::string get_relation_label_avm_alu(int index) { switch (index) { - case 10: - return "ALU_ADD_SUB_2"; - - case 12: - return "ALU_MUL_COMMON_1"; - - case 13: - return "ALU_MUL_COMMON_2"; - case 18: return "ALU_OP_NOT"; @@ -67,17 +58,26 @@ inline std::string get_relation_label_avm_alu(int index) case 9: return "ALU_ADD_SUB_1"; - case 17: - return "ALU_FF_NOT_XOR"; + case 10: + return "ALU_ADD_SUB_2"; - case 16: - return "ALU_MULTIPLICATION_OUT_U128"; + case 13: + return "ALU_MUL_COMMON_2"; case 20: return "ALU_OP_EQ"; + case 17: + return "ALU_FF_NOT_XOR"; + case 11: return "ALU_MULTIPLICATION_FF"; + + case 12: + return "ALU_MUL_COMMON_1"; + + case 16: + return "ALU_MULTIPLICATION_OUT_U128"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp index a72f75fdf11..b48711ef2c7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp @@ -7,64 +7,64 @@ namespace bb::Avm_vm { template struct Avm_mainRow { - FF avm_main_sel_internal_return{}; - FF avm_main_sel_op_eq{}; - FF avm_main_inv{}; + FF avm_main_mem_idx_b{}; + FF avm_main_rwc{}; + FF avm_main_first{}; FF avm_main_sel_jump{}; - FF avm_main_sel_op_mul{}; - FF avm_main_ia{}; - FF avm_main_pc{}; - FF avm_main_alu_sel{}; - FF avm_main_sel_op_not{}; - FF avm_main_rwb{}; + FF avm_main_tag_err{}; + FF avm_main_mem_op_c{}; + FF avm_main_mem_op_b{}; FF avm_main_mem_op_a{}; - FF avm_main_ib{}; - FF avm_main_internal_return_ptr{}; - FF avm_main_mem_idx_a{}; - FF avm_main_sel_op_sub{}; + FF avm_main_sel_op_not{}; + FF avm_main_pc{}; FF avm_main_sel_op_add{}; - FF avm_main_mem_op_b{}; + FF avm_main_sel_internal_return{}; FF avm_main_pc_shift{}; - FF avm_main_mem_op_c{}; - FF avm_main_op_err{}; - FF avm_main_sel_op_div{}; - FF avm_main_sel_internal_call{}; - FF avm_main_mem_idx_b{}; - FF avm_main_internal_return_ptr_shift{}; FF avm_main_ic{}; - FF avm_main_sel_halt{}; - FF avm_main_tag_err{}; - FF avm_main_rwc{}; + FF avm_main_internal_return_ptr_shift{}; + FF avm_main_inv{}; + FF avm_main_sel_internal_call{}; FF avm_main_rwa{}; - FF avm_main_first{}; + FF avm_main_sel_halt{}; + FF avm_main_sel_op_mul{}; + FF avm_main_sel_op_div{}; + FF avm_main_sel_op_sub{}; + FF avm_main_mem_idx_a{}; + FF avm_main_rwb{}; + FF avm_main_op_err{}; + FF avm_main_ia{}; + FF avm_main_internal_return_ptr{}; + FF avm_main_alu_sel{}; + FF avm_main_sel_op_eq{}; + FF avm_main_ib{}; }; inline std::string get_relation_label_avm_main(int index) { switch (index) { - case 20: - return "SUBOP_DIVISION_ZERO_ERR2"; - - case 35: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - - case 21: - return "SUBOP_ERROR_RELEVANT_OP"; - - case 19: - return "SUBOP_DIVISION_ZERO_ERR1"; - case 34: return "PC_INCREMENT"; - case 18: - return "SUBOP_DIVISION_FF"; + case 23: + return "RETURN_POINTER_INCREMENT"; case 29: return "RETURN_POINTER_DECREMENT"; - case 23: - return "RETURN_POINTER_INCREMENT"; + case 18: + return "SUBOP_DIVISION_FF"; + + case 21: + return "SUBOP_ERROR_RELEVANT_OP"; + + case 35: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + + case 20: + return "SUBOP_DIVISION_ZERO_ERR2"; + + case 19: + return "SUBOP_DIVISION_ZERO_ERR1"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp index 8b8d97cceef..dafa996d6fa 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp @@ -7,45 +7,45 @@ namespace bb::Avm_vm { template struct Avm_memRow { + FF avm_mem_m_tag_shift{}; + FF avm_mem_m_val_shift{}; + FF avm_mem_m_op_a{}; + FF avm_mem_m_addr{}; FF avm_mem_m_lastAccess{}; - FF avm_mem_m_op_b{}; FF avm_mem_m_tag{}; - FF avm_mem_m_addr{}; + FF avm_mem_m_rw_shift{}; FF avm_mem_m_in_tag{}; - FF avm_mem_m_tag_shift{}; FF avm_mem_m_last{}; - FF avm_mem_m_one_min_inv{}; FF avm_mem_m_tag_err{}; FF avm_mem_m_addr_shift{}; + FF avm_mem_m_val{}; + FF avm_mem_m_one_min_inv{}; + FF avm_mem_m_op_b{}; FF avm_mem_m_sub_clk{}; - FF avm_mem_m_val_shift{}; FF avm_mem_m_op_c{}; - FF avm_mem_m_val{}; FF avm_mem_m_rw{}; - FF avm_mem_m_op_a{}; - FF avm_mem_m_rw_shift{}; }; inline std::string get_relation_label_avm_mem(int index) { switch (index) { - case 9: - return "MEM_LAST_ACCESS_DELIMITER"; + case 13: + return "MEM_IN_TAG_CONSISTENCY_1"; case 10: return "MEM_READ_WRITE_VAL_CONSISTENCY"; - case 14: - return "MEM_IN_TAG_CONSISTENCY_2"; + case 11: + return "MEM_READ_WRITE_TAG_CONSISTENCY"; + + case 9: + return "MEM_LAST_ACCESS_DELIMITER"; case 12: return "MEM_ZERO_INIT"; - case 11: - return "MEM_READ_WRITE_TAG_CONSISTENCY"; - - case 13: - return "MEM_IN_TAG_CONSISTENCY_1"; + case 14: + return "MEM_IN_TAG_CONSISTENCY_2"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp index 65f1974da2b..3cfe1455ce2 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp @@ -79,23 +79,23 @@ [[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 equiv_inter_reg_alu = View(new_term.equiv_inter_reg_alu); \ - [[maybe_unused]] auto equiv_main_mem_a = View(new_term.equiv_main_mem_a); \ - [[maybe_unused]] auto equiv_main_mem_b = View(new_term.equiv_main_mem_b); \ - [[maybe_unused]] auto equiv_main_mem_c = View(new_term.equiv_main_mem_c); \ - [[maybe_unused]] auto equiv_tag_err = View(new_term.equiv_tag_err); \ - [[maybe_unused]] auto equiv_tag_err_counts = View(new_term.equiv_tag_err_counts); \ - [[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_alu_alu_u16_r7_shift = View(new_term.avm_alu_alu_u16_r7_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_r0_shift = View(new_term.avm_alu_alu_u16_r0_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 perm_main_alu = View(new_term.perm_main_alu); \ + [[maybe_unused]] auto perm_main_mem_a = View(new_term.perm_main_mem_a); \ + [[maybe_unused]] auto perm_main_mem_b = View(new_term.perm_main_mem_b); \ + [[maybe_unused]] auto perm_main_mem_c = View(new_term.perm_main_mem_c); \ + [[maybe_unused]] auto incl_main_tag_err = View(new_term.incl_main_tag_err); \ + [[maybe_unused]] auto incl_main_tag_err_counts = View(new_term.incl_main_tag_err_counts); \ + [[maybe_unused]] auto avm_mem_m_tag_shift = View(new_term.avm_mem_m_tag_shift); \ + [[maybe_unused]] auto avm_mem_m_val_shift = View(new_term.avm_mem_m_val_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_alu_alu_u16_r5_shift = View(new_term.avm_alu_alu_u16_r5_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_r4_shift = View(new_term.avm_alu_alu_u16_r4_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_r1_shift = View(new_term.avm_alu_alu_u16_r1_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_r6_shift = View(new_term.avm_alu_alu_u16_r6_shift); \ - [[maybe_unused]] auto avm_mem_m_tag_shift = View(new_term.avm_mem_m_tag_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_rw_shift = View(new_term.avm_mem_m_rw_shift); + [[maybe_unused]] auto avm_alu_alu_u16_r2_shift = View(new_term.avm_alu_alu_u16_r2_shift); \ + [[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); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_tag_err.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/incl_main_tag_err.hpp similarity index 92% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_tag_err.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/incl_main_tag_err.hpp index 858ecfafa09..050f662d86b 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_tag_err.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/incl_main_tag_err.hpp @@ -23,7 +23,7 @@ namespace bb { * FF>>;)` * */ -class equiv_tag_err_lookup_settings { +class incl_main_tag_err_lookup_settings { public: /** * @brief The number of read terms (how many lookups we perform) in each row @@ -133,8 +133,8 @@ class equiv_tag_err_lookup_settings { template static inline auto get_const_entities(const AllEntities& in) { - return std::forward_as_tuple(in.equiv_tag_err, - in.equiv_tag_err_counts, + return std::forward_as_tuple(in.incl_main_tag_err, + in.incl_main_tag_err_counts, in.avm_mem_m_tag_err, in.avm_main_tag_err, in.avm_mem_m_clk, @@ -151,8 +151,8 @@ class equiv_tag_err_lookup_settings { template static inline auto get_nonconst_entities(AllEntities& in) { - return std::forward_as_tuple(in.equiv_tag_err, - in.equiv_tag_err_counts, + return std::forward_as_tuple(in.incl_main_tag_err, + in.incl_main_tag_err_counts, in.avm_mem_m_tag_err, in.avm_main_tag_err, in.avm_mem_m_clk, @@ -160,7 +160,8 @@ class equiv_tag_err_lookup_settings { } }; -template using equiv_tag_err_relation = GenericLookupRelation; -template using equiv_tag_err = GenericLookup; +template +using incl_main_tag_err_relation = GenericLookupRelation; +template using incl_main_tag_err = GenericLookup; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_inter_reg_alu.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_alu.hpp similarity index 93% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_inter_reg_alu.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_alu.hpp index e0c5b799aeb..a83ab5eafeb 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_inter_reg_alu.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_alu.hpp @@ -9,7 +9,7 @@ namespace bb { -class equiv_inter_reg_alu_permutation_settings { +class perm_main_alu_permutation_settings { public: // This constant defines how many columns are bundled together to form each set. constexpr static size_t COLUMNS_PER_SET = 10; @@ -46,7 +46,7 @@ class equiv_inter_reg_alu_permutation_settings { template static inline auto get_const_entities(const AllEntities& in) { - return std::forward_as_tuple(in.equiv_inter_reg_alu, + return std::forward_as_tuple(in.perm_main_alu, in.avm_main_alu_sel, in.avm_main_alu_sel, in.avm_alu_alu_sel, @@ -92,7 +92,7 @@ class equiv_inter_reg_alu_permutation_settings { template static inline auto get_nonconst_entities(AllEntities& in) { - return std::forward_as_tuple(in.equiv_inter_reg_alu, + return std::forward_as_tuple(in.perm_main_alu, in.avm_main_alu_sel, in.avm_main_alu_sel, in.avm_alu_alu_sel, @@ -120,7 +120,7 @@ class equiv_inter_reg_alu_permutation_settings { }; template -using equiv_inter_reg_alu_relation = GenericPermutationRelation; -template using equiv_inter_reg_alu = GenericPermutation; +using perm_main_alu_relation = GenericPermutationRelation; +template using perm_main_alu = GenericPermutation; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_main_mem_a.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_a.hpp similarity index 92% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_main_mem_a.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_a.hpp index cb308be26d0..5d52373810e 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_main_mem_a.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_a.hpp @@ -9,7 +9,7 @@ namespace bb { -class equiv_main_mem_a_permutation_settings { +class perm_main_mem_a_permutation_settings { public: // This constant defines how many columns are bundled together to form each set. constexpr static size_t COLUMNS_PER_SET = 5; @@ -46,7 +46,7 @@ class equiv_main_mem_a_permutation_settings { template static inline auto get_const_entities(const AllEntities& in) { - return std::forward_as_tuple(in.equiv_main_mem_a, + return std::forward_as_tuple(in.perm_main_mem_a, in.avm_main_mem_op_a, in.avm_main_mem_op_a, in.avm_mem_m_op_a, @@ -82,7 +82,7 @@ class equiv_main_mem_a_permutation_settings { template static inline auto get_nonconst_entities(AllEntities& in) { - return std::forward_as_tuple(in.equiv_main_mem_a, + return std::forward_as_tuple(in.perm_main_mem_a, in.avm_main_mem_op_a, in.avm_main_mem_op_a, in.avm_mem_m_op_a, @@ -100,7 +100,7 @@ class equiv_main_mem_a_permutation_settings { }; template -using equiv_main_mem_a_relation = GenericPermutationRelation; -template using equiv_main_mem_a = GenericPermutation; +using perm_main_mem_a_relation = GenericPermutationRelation; +template using perm_main_mem_a = GenericPermutation; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_main_mem_b.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_b.hpp similarity index 92% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_main_mem_b.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_b.hpp index 7350137dbac..071d5a6eb53 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_main_mem_b.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_b.hpp @@ -9,7 +9,7 @@ namespace bb { -class equiv_main_mem_b_permutation_settings { +class perm_main_mem_b_permutation_settings { public: // This constant defines how many columns are bundled together to form each set. constexpr static size_t COLUMNS_PER_SET = 5; @@ -46,7 +46,7 @@ class equiv_main_mem_b_permutation_settings { template static inline auto get_const_entities(const AllEntities& in) { - return std::forward_as_tuple(in.equiv_main_mem_b, + return std::forward_as_tuple(in.perm_main_mem_b, in.avm_main_mem_op_b, in.avm_main_mem_op_b, in.avm_mem_m_op_b, @@ -82,7 +82,7 @@ class equiv_main_mem_b_permutation_settings { template static inline auto get_nonconst_entities(AllEntities& in) { - return std::forward_as_tuple(in.equiv_main_mem_b, + return std::forward_as_tuple(in.perm_main_mem_b, in.avm_main_mem_op_b, in.avm_main_mem_op_b, in.avm_mem_m_op_b, @@ -100,7 +100,7 @@ class equiv_main_mem_b_permutation_settings { }; template -using equiv_main_mem_b_relation = GenericPermutationRelation; -template using equiv_main_mem_b = GenericPermutation; +using perm_main_mem_b_relation = GenericPermutationRelation; +template using perm_main_mem_b = GenericPermutation; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_main_mem_c.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_c.hpp similarity index 92% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_main_mem_c.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_c.hpp index 05e940c45b4..41f22dc0193 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/equiv_main_mem_c.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_c.hpp @@ -9,7 +9,7 @@ namespace bb { -class equiv_main_mem_c_permutation_settings { +class perm_main_mem_c_permutation_settings { public: // This constant defines how many columns are bundled together to form each set. constexpr static size_t COLUMNS_PER_SET = 5; @@ -46,7 +46,7 @@ class equiv_main_mem_c_permutation_settings { template static inline auto get_const_entities(const AllEntities& in) { - return std::forward_as_tuple(in.equiv_main_mem_c, + return std::forward_as_tuple(in.perm_main_mem_c, in.avm_main_mem_op_c, in.avm_main_mem_op_c, in.avm_mem_m_op_c, @@ -82,7 +82,7 @@ class equiv_main_mem_c_permutation_settings { template static inline auto get_nonconst_entities(AllEntities& in) { - return std::forward_as_tuple(in.equiv_main_mem_c, + return std::forward_as_tuple(in.perm_main_mem_c, in.avm_main_mem_op_c, in.avm_main_mem_op_c, in.avm_mem_m_op_c, @@ -100,7 +100,7 @@ class equiv_main_mem_c_permutation_settings { }; template -using equiv_main_mem_c_relation = GenericPermutationRelation; -template using equiv_main_mem_c = GenericPermutation; +using perm_main_mem_c_relation = GenericPermutationRelation; +template using perm_main_mem_c = GenericPermutation; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp index 2ccd60e8232..d4ec8c3ace1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp @@ -698,7 +698,7 @@ void AvmTraceBuilder::internal_return() void AvmTraceBuilder::finalise_mem_trace_lookup_counts(std::map const& tag_err_lookup_counts) { for (auto const& [clk, count] : tag_err_lookup_counts) { - main_trace.at(clk).equiv_tag_err_counts = count; + main_trace.at(clk).incl_main_tag_err_counts = count; } } diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp index 396b97dd4e3..0ee66fee2ad 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp @@ -179,17 +179,17 @@ bool AvmVerifier::verify_proof(const HonkProof& proof) 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); - commitments.equiv_inter_reg_alu = - transcript->template receive_from_prover(commitment_labels.equiv_inter_reg_alu); - commitments.equiv_main_mem_a = - transcript->template receive_from_prover(commitment_labels.equiv_main_mem_a); - commitments.equiv_main_mem_b = - transcript->template receive_from_prover(commitment_labels.equiv_main_mem_b); - commitments.equiv_main_mem_c = - transcript->template receive_from_prover(commitment_labels.equiv_main_mem_c); - commitments.equiv_tag_err = transcript->template receive_from_prover(commitment_labels.equiv_tag_err); - commitments.equiv_tag_err_counts = - transcript->template receive_from_prover(commitment_labels.equiv_tag_err_counts); + commitments.perm_main_alu = transcript->template receive_from_prover(commitment_labels.perm_main_alu); + commitments.perm_main_mem_a = + transcript->template receive_from_prover(commitment_labels.perm_main_mem_a); + commitments.perm_main_mem_b = + transcript->template receive_from_prover(commitment_labels.perm_main_mem_b); + commitments.perm_main_mem_c = + transcript->template receive_from_prover(commitment_labels.perm_main_mem_c); + commitments.incl_main_tag_err = + transcript->template receive_from_prover(commitment_labels.incl_main_tag_err); + commitments.incl_main_tag_err_counts = + transcript->template receive_from_prover(commitment_labels.incl_main_tag_err_counts); // Execute Sumcheck Verifier const size_t log_circuit_size = numeric::get_msb(circuit_size); diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp index 5f9f206f31f..d71343f2c97 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp @@ -1,12 +1,10 @@ #include "avm_common.test.hpp" - #include "barretenberg/numeric/uint128/uint128.hpp" -#include "barretenberg/vm/avm_trace/avm_helper.hpp" -using namespace bb; -using namespace bb::numeric; +namespace tests_avm { +using namespace bb::avm_trace; + namespace { -using namespace tests_avm; void common_validate_arithmetic_op(Row const& main_row, Row const& alu_row, @@ -246,9 +244,6 @@ std::vector gen_mutated_trace_eq( } } // anonymous namespace -namespace tests_avm { -using namespace bb::avm_trace; - class AvmArithmeticTests : public ::testing::Test { public: AvmTraceBuilder trace_builder; diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp index d4b2860e2d3..7fae3fa13cb 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp @@ -1,15 +1,13 @@ #include "avm_common.test.hpp" - #include "barretenberg/numeric/uint128/uint128.hpp" #include #include #include -using namespace bb; -using namespace bb::numeric; +namespace tests_avm { +using namespace bb::avm_trace; namespace { -using namespace tests_avm; Row common_validate_op_not(std::vector const& trace, FF const& a, @@ -72,9 +70,6 @@ std::vector gen_mutated_trace_not(FF const& a, FF const& c_mutated, avm_tra } } // namespace -namespace tests_avm { -using namespace bb::avm_trace; - class AvmBitwiseTests : public ::testing::Test { public: AvmTraceBuilder trace_builder; diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp index ed1c81377ab..8ac2da28f08 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp @@ -1,7 +1,5 @@ #include "avm_common.test.hpp" -using namespace bb; - namespace tests_avm { using namespace bb::avm_trace; diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp index 1e9028c6fcb..ecf10ed57e0 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp @@ -3,18 +3,15 @@ #include "barretenberg/common/utils.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 +#include #include #include #include namespace tests_avm { -using namespace bb; using namespace bb::avm_trace; using namespace testing; diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_inter_table.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_inter_table.test.cpp new file mode 100644 index 00000000000..9940e88eca0 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_inter_table.test.cpp @@ -0,0 +1,384 @@ +#include "avm_common.test.hpp" +#include "barretenberg/vm/avm_trace/avm_common.hpp" +#include "barretenberg/vm/avm_trace/avm_mem_trace.hpp" +#include "barretenberg/vm/tests/helpers.test.hpp" +#include +#include +#include + +using namespace bb; + +namespace tests_avm { +using namespace bb::avm_trace; + +class AvmInterTableTests : public ::testing::Test { + public: + 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"); }; +}; + +/****************************************************************************** + * + * INTER-TABLE NEGATIVE TESTS + * + ****************************************************************************** + * These negative unit tests aim to catch violations related to inter-table + * relations. Inter-table relations are implemented through permutation and + * lookup relations. Each permutation and lookup relation defined in the AVM + * has to be negatively tested in the current test suite. + * The built trace in each test needs to be as correct as possible except the + * relation being tested. + ******************************************************************************/ + +// Error tag propagation from memory trace back to the main trace. +TEST_F(AvmInterTableTests, tagErrNotCopiedInMain) +{ + // Equality operation on U128 and second operand is of type U16. + trace_builder.set(32, 18, AvmMemoryTag::U128); + trace_builder.set(32, 76, AvmMemoryTag::U16); + trace_builder.op_eq(18, 76, 65, AvmMemoryTag::U128); + trace_builder.halt(); + auto trace = trace_builder.finalize(); + + // Find the row with equality operation and mutate the error tag. + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_eq == 1; }); + ASSERT_EQ(row->avm_main_tag_err, FF(1)); // Sanity check that the error tag is set. + row->avm_main_tag_err = 0; + row->avm_main_alu_sel = 1; // We have to activate ALU trace if no error tag is present. + auto const clk = row->avm_main_clk; + + // Create a valid ALU entry for this equality operation. + auto& alu_row = trace.at(1); + alu_row.avm_alu_alu_clk = clk; + alu_row.avm_alu_alu_sel = 1; + alu_row.avm_alu_alu_ia = 32; + alu_row.avm_alu_alu_ib = 32; + alu_row.avm_alu_alu_ic = 1; + alu_row.avm_alu_alu_op_eq = 1; + alu_row.avm_alu_alu_in_tag = static_cast(AvmMemoryTag::U128); + alu_row.avm_alu_alu_u128_tag = 1; + + // Adjust the output of the computation as it would have been performed without tag check. + row->avm_main_ic = 1; + // Find the memory row pertaining to write operation from Ic. + auto mem_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { + return r.avm_mem_m_clk == clk && r.avm_mem_m_sub_clk == AvmMemTraceBuilder::SUB_CLK_STORE_C; + }); + + // Adjust the output in the memory trace. + mem_row->avm_mem_m_val = 1; + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "INCL_MAIN_TAG_ERR"); +} + +/****************************************************************************** + * MAIN <-------> ALU + ******************************************************************************/ +class AvmPermMainAluNegativeTests : public AvmInterTableTests { + protected: + std::vector trace; + size_t main_idx; + size_t mem_idx; + size_t alu_idx; + + void SetUp() override + { + AvmInterTableTests::SetUp(); + + trace_builder.set(19, 0, AvmMemoryTag::U64); + trace_builder.set(15, 1, AvmMemoryTag::U64); + trace_builder.op_add(0, 1, 1, AvmMemoryTag::U64); // 19 + 15 = 34 + trace_builder.op_add(0, 1, 1, AvmMemoryTag::U64); // 19 + 34 = 53 + trace_builder.op_mul(0, 1, 2, AvmMemoryTag::U64); // 19 * 53 = 1007 + trace_builder.return_op(0, 0); + + trace = trace_builder.finalize(); + + // Find the row with multiplication operation and retrieve clk. + auto row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == FF(1); }); + + ASSERT_TRUE(row != trace.end()); + ASSERT_EQ(row->avm_main_ic, 1007); // Sanity check + auto clk = row->avm_main_clk; + + // Find the corresponding Alu trace row + auto alu_row = + std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_alu_clk == clk; }); + ASSERT_TRUE(alu_row != trace.end()); + + // Find memory trace entry related to storing output (intermediate register Ic) in memory. + auto mem_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { + return r.avm_mem_m_clk == clk && r.avm_mem_m_op_c == FF(1) && r.avm_mem_m_rw == FF(1); + }); + ASSERT_TRUE(mem_row != trace.end()); + + main_idx = static_cast(row - trace.begin()); + alu_idx = static_cast(alu_row - trace.begin()); + mem_idx = static_cast(mem_row - trace.begin()); + } +}; + +TEST_F(AvmPermMainAluNegativeTests, wrongAluOutputCopyInMain) +{ + // Mutate the multiplication output. Note that the output alu counterpart is still valid + // and pass the multiplication relation. + trace.at(main_idx).avm_main_ic = 1008; + trace.at(mem_idx).avm_mem_m_val = 1008; + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_ALU"); +} + +TEST_F(AvmPermMainAluNegativeTests, wrongCopyToAluIaInput) +{ + // Mutate the input of alu_ia and adapt the output ic accordingly. + trace.at(alu_idx).avm_alu_alu_ia = 20; + trace.at(alu_idx).avm_alu_alu_ic = 1060; // 20 * 53; required to pass the alu mul relation + trace.at(alu_idx).avm_alu_alu_u8_r0 = 36; // 1060 % 256 = 36 + trace.at(alu_idx).avm_alu_alu_u8_r1 = 4; // 4 * 256 = 1024 + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_ALU"); +} + +TEST_F(AvmPermMainAluNegativeTests, wrongCopyToAluIbInput) +{ + // Mutate the input of alu_ia and adapt the output ic accordingly. + trace.at(alu_idx).avm_alu_alu_ib = 10; + trace.at(alu_idx).avm_alu_alu_ic = 190; // 19 * 10; required to pass the alu mul relation + trace.at(alu_idx).avm_alu_alu_u8_r0 = 190; + trace.at(alu_idx).avm_alu_alu_u8_r1 = 0; + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_ALU"); +} + +TEST_F(AvmPermMainAluNegativeTests, wrongCopyToAluOpSelector) +{ + trace.at(alu_idx).avm_alu_alu_op_mul = 0; + trace.at(alu_idx).avm_alu_alu_op_add = 1; + trace.at(alu_idx).avm_alu_alu_ic = 72; // 19 + 53 + trace.at(alu_idx).avm_alu_alu_u8_r0 = 72; + trace.at(alu_idx).avm_alu_alu_u8_r1 = 0; + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_ALU"); +} + +TEST_F(AvmPermMainAluNegativeTests, removeAluSelector) +{ + trace.at(alu_idx).avm_alu_alu_sel = 0; + trace.at(alu_idx).avm_alu_alu_op_mul = 0; + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_ALU"); +} + +/****************************************************************************** + * MAIN <-------> ALU + ******************************************************************************/ +class AvmPermMainMemNegativeTests : public AvmInterTableTests { + protected: + std::vector trace; + size_t main_idx; + size_t mem_idx_a; + size_t mem_idx_b; + size_t mem_idx_c; + size_t alu_idx; + + // Helper function to generate a trace with a subtraction + // for c = a - b at arbitray chosen addresses 52 (a), 11 (b), 55 (c). + void executeSub(uint128_t const a, uint128_t const b) + { + trace_builder.set(a, 52, AvmMemoryTag::U8); + trace_builder.set(b, 11, AvmMemoryTag::U8); + trace_builder.op_sub(52, 11, 55, AvmMemoryTag::U8); + trace_builder.return_op(0, 0); + + trace = trace_builder.finalize(); + + // Find the row with subtraction operation and retrieve clk. + auto row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == FF(1); }); + + ASSERT_TRUE(row != trace.end()); + auto clk = row->avm_main_clk; + + // Find the corresponding Alu trace row + auto alu_row = + std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_alu_clk == clk; }); + ASSERT_TRUE(alu_row != trace.end()); + + // Find memory trace entry related to storing output (intermediate register Ic) in memory. + auto mem_row_c = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { + return r.avm_mem_m_clk == clk && r.avm_mem_m_op_c == FF(1) && r.avm_mem_m_rw == FF(1); + }); + ASSERT_TRUE(mem_row_c != trace.end()); + + // Find memory trace entry related to loading first input (intermediate register Ia) in memory. + auto mem_row_a = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { + return r.avm_mem_m_clk == clk && r.avm_mem_m_op_a == FF(1) && r.avm_mem_m_rw == FF(0); + }); + ASSERT_TRUE(mem_row_a != trace.end()); + + // Find memory trace entry related to loading second input (intermediate register Ib) in memory. + auto mem_row_b = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { + return r.avm_mem_m_clk == clk && r.avm_mem_m_op_b == FF(1) && r.avm_mem_m_rw == FF(0); + }); + ASSERT_TRUE(mem_row_b != trace.end()); + + main_idx = static_cast(row - trace.begin()); + alu_idx = static_cast(alu_row - trace.begin()); + mem_idx_a = static_cast(mem_row_a - trace.begin()); + mem_idx_b = static_cast(mem_row_b - trace.begin()); + mem_idx_c = static_cast(mem_row_c - trace.begin()); + } +}; + +TEST_F(AvmPermMainMemNegativeTests, wrongValueIaInMem) +{ + executeSub(21, 3); + trace.at(mem_idx_a).avm_mem_m_val = 26; // Correct value: 21 + trace.at(mem_idx_a - 1).avm_mem_m_val = 26; // We need to adjust the write operation beforehand (set opcode). + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongValueIbInMem) +{ + executeSub(21, 3); + trace.at(mem_idx_b).avm_mem_m_val = 7; // Correct value: 3 + trace.at(mem_idx_b - 1).avm_mem_m_val = 7; // We need to adjust the write operation beforehand (set opcode). + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_B"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongValueIcInMem) +{ + executeSub(21, 3); + trace.at(mem_idx_c).avm_mem_m_val = 17; // Correct value: 18 = 21 - 3 + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_C"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongAddressIaInMain) +{ + executeSub(21, 3); + trace.at(main_idx).avm_main_mem_idx_a = 28; // Correct address: 52 + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongAddressIbInMain) +{ + executeSub(21, 3); + trace.at(main_idx).avm_main_mem_idx_b = 2; // Correct address: 11 + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_B"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongAddressIcInMain) +{ + executeSub(21, 3); + trace.at(main_idx).avm_main_mem_idx_c = 75; // Correct address: 55 + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_C"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongInTagIaInMem) +{ + executeSub(21, 3); + auto wrong_in_tag = static_cast(AvmMemoryTag::U32); + trace.at(mem_idx_a).avm_mem_m_in_tag = wrong_in_tag; // Correct value: AvmMemoryTag::U8 + trace.at(mem_idx_a).avm_mem_m_tag = wrong_in_tag; + + // We need to adjust the write operation beforehand (set opcode). + trace.at(mem_idx_a - 1).avm_mem_m_in_tag = wrong_in_tag; + trace.at(mem_idx_a - 1).avm_mem_m_tag = wrong_in_tag; + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongInTagIbInMem) +{ + executeSub(21, 3); + auto wrong_in_tag = static_cast(AvmMemoryTag::U16); + trace.at(mem_idx_b).avm_mem_m_in_tag = wrong_in_tag; // Correct value: AvmMemoryTag::U8 + trace.at(mem_idx_b).avm_mem_m_tag = wrong_in_tag; + + // We need to adjust the write operation beforehand (set opcode). + trace.at(mem_idx_b - 1).avm_mem_m_in_tag = wrong_in_tag; + trace.at(mem_idx_b - 1).avm_mem_m_tag = wrong_in_tag; + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_B"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongInTagIcInMem) +{ + executeSub(21, 3); + auto wrong_in_tag = static_cast(AvmMemoryTag::U128); + trace.at(mem_idx_c).avm_mem_m_in_tag = wrong_in_tag; // Correct value: AvmMemoryTag::U8 + trace.at(mem_idx_c).avm_mem_m_tag = wrong_in_tag; + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_C"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongRwIaInMem) +{ + executeSub(21, 3); + trace.at(mem_idx_a).avm_mem_m_rw = 1; // Write instead of read. + + // Adjust sub_clk value + trace.at(mem_idx_a).avm_mem_m_sub_clk = AvmMemTraceBuilder::SUB_CLK_STORE_A; + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongRwIbInMem) +{ + executeSub(21, 3); + trace.at(mem_idx_b).avm_mem_m_rw = 1; // Write instead of read. + + // Adjust sub_clk value + trace.at(mem_idx_b).avm_mem_m_sub_clk = AvmMemTraceBuilder::SUB_CLK_STORE_B; + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_B"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongRwIcInMem) +{ + // For this test, we need the result to be zero. Otherwise, swapping + // a write for a read of Ic below leads to a violation that the memory + // is initialized with zero values. + executeSub(11, 11); + trace.at(mem_idx_c).avm_mem_m_rw = 0; // Read instead of write. + + // Adjust sub_clk value + trace.at(mem_idx_c).avm_mem_m_sub_clk = AvmMemTraceBuilder::SUB_CLK_LOAD_C; + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_C"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongClkIaInMem) +{ + executeSub(87, 23); + trace.at(mem_idx_a).avm_mem_m_clk = 11; + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongClkIbInMem) +{ + executeSub(87, 23); + trace.at(mem_idx_b).avm_mem_m_clk = 21; + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_B"); +} + +TEST_F(AvmPermMainMemNegativeTests, wrongClkIcInMem) +{ + executeSub(87, 23); + trace.at(mem_idx_c).avm_mem_m_clk = 7; + + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "PERM_MAIN_MEM_C"); +} + +} // namespace tests_avm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp index 6ba06747f6f..d93dc15bddf 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp @@ -1,8 +1,6 @@ #include "avm_common.test.hpp" #include "barretenberg/vm/avm_trace/avm_common.hpp" -using namespace bb; - namespace tests_avm { using namespace bb::avm_trace; diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp index 3d8aa063d9a..55aca7f4bf3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp @@ -1,7 +1,5 @@ #include "avm_common.test.hpp" -using namespace bb; - namespace tests_avm { /** * @brief Helper routine proving and verifying a proof based on the supplied trace