From 8ff73158b7e96e280df768ac67c777fed20db2c5 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Wed, 20 Dec 2023 09:55:49 +0000 Subject: [PATCH 01/28] PIL relations for u8, u16, u32, u64, u128 additions --- barretenberg/cpp/pil/avm/alu_chip.pil | 95 ++++++ barretenberg/cpp/pil/avm/avm_mini.pil | 1 + .../flavor/generated/AvmMini_flavor.hpp | 293 +++++++++++++++++- .../generated/AvmMini_circuit_builder.hpp | 77 ++++- .../relations/generated/AvmMini/alu_chip.hpp | 245 +++++++++++++++ .../relations/generated/AvmMini/avm_mini.hpp | 62 ++-- .../generated/AvmMini/declare_views.hpp | 34 +- .../relations/generated/AvmMini/mem_trace.hpp | 30 +- .../vm/generated/AvmMini_verifier.cpp | 46 +++ 9 files changed, 818 insertions(+), 65 deletions(-) create mode 100644 barretenberg/cpp/pil/avm/alu_chip.pil create mode 100644 barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil new file mode 100644 index 00000000000..7c00b392fae --- /dev/null +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -0,0 +1,95 @@ +include "avm_mini.pil"; + +namespace aluChip(256); + + // ========= Table ALU-TR ================================================= + + // References to main trace table of sub-operations, clk, intermediate + // registers, operation selectors. + // TODO: Think on optimizations to decrease the number of such "copied" columns + pol commit alu_clk; + pol commit alu_ia; // Intermediate registers + pol commit alu_ib; + pol commit alu_ic; + pol commit alu_op_add; // Operation selectors + pol commit alu_op_sub; + pol commit alu_op_mul; + pol commit alu_op_div; + + // Flattened boolean instruction tags + pol commit alu_u8; + pol commit alu_u16; + pol commit alu_u32; + pol commit alu_u64; + pol commit alu_u128; + + // 8-bit slice registers + pol commit alu_s1; + pol commit alu_s2; + pol commit alu_s3; + pol commit alu_s4; + pol commit alu_s5; + pol commit alu_s6; + pol commit alu_s7; + pol commit alu_s8; + pol commit alu_s9; + pol commit alu_s10; + pol commit alu_s11; + pol commit alu_s12; + pol commit alu_s13; + pol commit alu_s14; + pol commit alu_s15; + pol commit alu_s16; + + // Carry flag + pol commit alu_cf; + + // ========= Type Constraints ============================================= + // TODO: Range constraints for slice registers + // intermediate registers ia and ib (inputs) depending on flag + // Carry flag: We will have to constraint to ensure that the + // arithmetic expressions are not overflowing finite field size + + // Boolean flattened instructions tags + alu_u8 * (1 - alu_u8) = 0; + alu_u16 * (1 - alu_u16) = 0; + alu_u32 * (1 - alu_u32) = 0; + alu_u64 * (1 - alu_u64) = 0; + alu_u128 * (1 - alu_u128) = 0; + + // Operation selectors are copied from main table and do not need to be constrained here. + + // ========= Inter-table Constraints ====================================== + // TODO: Equivalence between intermediate registers, clk, type flag, operation + // An ALU chiplet flag will be introduced in main trace to select relevant rows. + + // ========= ADDITION Operation Constraints =============================== + + // Intermediate polynomial terms + // 8-bit slice partial sums + pol sum_8 = alu_s1; + pol sum_16 = sum_8 + 2**8 * alu_s2; + pol sum_32 = sum_16 + 2**16 * alu_s3 + 2**24 * alu_s4; + pol sum_64 = sum_32 + 2**32 * alu_s5 + 2**40 * alu_s6 + 2**48 * alu_s7 + 2**56 * alu_s8; + pol sum_96 = sum_64 + 2**64 * alu_s9 + 2**72 * alu_s10 + 2**80 * alu_s11 + 2**88 * alu_s12; + pol sum_128 = sum_96 + 2**96 * alu_s13 + 2**104 * alu_s14 + 2**112 * alu_s15 + 2**120 * alu_s16; + + // u8 addition + alu_u8 * alu_op_add * (sum_8 + 2**8 * alu_cf - alu_ia - alu_ib) = 0; + alu_u8 * alu_op_add * (sum_8 - alu_ic) = 0; + + // u16 addition + alu_u16 * alu_op_add * (sum_16 + 2**16 * alu_cf - alu_ia - alu_ib) = 0; + alu_u16 * alu_op_add * (sum_16 - alu_ic) = 0; + + // u32 addition + alu_u32 * alu_op_add * (sum_32 + 2**32 * alu_cf - alu_ia - alu_ib) = 0; + alu_u32 * alu_op_add * (sum_32 - alu_ic) = 0; + + // u64 addition + alu_u64 * alu_op_add * (sum_64 + 2**64 * alu_cf - alu_ia - alu_ib) = 0; + alu_u64 * alu_op_add * (sum_64 - alu_ic) = 0; + + // u128 addition + alu_u128 * alu_op_add * (sum_128 + 2**128 * alu_cf - alu_ia - alu_ib) = 0; + alu_u128 * alu_op_add * (sum_128 - alu_ic) = 0; \ No newline at end of file diff --git a/barretenberg/cpp/pil/avm/avm_mini.pil b/barretenberg/cpp/pil/avm/avm_mini.pil index b2e10e30cca..9bd2b8d8222 100644 --- a/barretenberg/cpp/pil/avm/avm_mini.pil +++ b/barretenberg/cpp/pil/avm/avm_mini.pil @@ -1,5 +1,6 @@ include "mem_trace.pil"; +include "alu_chip.pil"; namespace avmMini(256); diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index d9b5edb8c61..c7c61695866 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -13,6 +13,7 @@ #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" @@ -36,13 +37,13 @@ class AvmMiniFlavor { using VerifierCommitmentKey = pcs::VerifierCommitmentKey; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; - static constexpr size_t NUM_WITNESS_ENTITIES = 37; + static constexpr size_t NUM_WITNESS_ENTITIES = 67; 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 = 45; + static constexpr size_t NUM_ALL_ENTITIES = 75; - using Relations = std::tuple, AvmMini_vm::mem_trace>; + using Relations = std::tuple, AvmMini_vm::avm_mini, AvmMini_vm::mem_trace>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -87,6 +88,36 @@ class AvmMiniFlavor { 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_u8, + aluChip_alu_u16, + aluChip_alu_u32, + aluChip_alu_u64, + aluChip_alu_u128, + aluChip_alu_s1, + aluChip_alu_s2, + aluChip_alu_s3, + aluChip_alu_s4, + aluChip_alu_s5, + aluChip_alu_s6, + aluChip_alu_s7, + aluChip_alu_s8, + aluChip_alu_s9, + aluChip_alu_s10, + aluChip_alu_s11, + aluChip_alu_s12, + aluChip_alu_s13, + aluChip_alu_s14, + aluChip_alu_s15, + aluChip_alu_s16, + aluChip_alu_cf, avmMini_pc, avmMini_internal_return_ptr, avmMini_sel_internal_call, @@ -127,6 +158,36 @@ class AvmMiniFlavor { 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_u8, + aluChip_alu_u16, + aluChip_alu_u32, + aluChip_alu_u64, + aluChip_alu_u128, + aluChip_alu_s1, + aluChip_alu_s2, + aluChip_alu_s3, + aluChip_alu_s4, + aluChip_alu_s5, + aluChip_alu_s6, + aluChip_alu_s7, + aluChip_alu_s8, + aluChip_alu_s9, + aluChip_alu_s10, + aluChip_alu_s11, + aluChip_alu_s12, + aluChip_alu_s13, + aluChip_alu_s14, + aluChip_alu_s15, + aluChip_alu_s16, + aluChip_alu_cf, avmMini_pc, avmMini_internal_return_ptr, avmMini_sel_internal_call, @@ -173,6 +234,36 @@ class AvmMiniFlavor { 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_u8, + aluChip_alu_u16, + aluChip_alu_u32, + aluChip_alu_u64, + aluChip_alu_u128, + aluChip_alu_s1, + aluChip_alu_s2, + aluChip_alu_s3, + aluChip_alu_s4, + aluChip_alu_s5, + aluChip_alu_s6, + aluChip_alu_s7, + aluChip_alu_s8, + aluChip_alu_s9, + aluChip_alu_s10, + aluChip_alu_s11, + aluChip_alu_s12, + aluChip_alu_s13, + aluChip_alu_s14, + aluChip_alu_s15, + aluChip_alu_s16, + aluChip_alu_cf, avmMini_pc, avmMini_internal_return_ptr, avmMini_sel_internal_call, @@ -201,10 +292,10 @@ class AvmMiniFlavor { avmMini_last, avmMini_internal_return_ptr_shift, avmMini_pc_shift, + memTrace_m_addr_shift, memTrace_m_tag_shift, - memTrace_m_val_shift, memTrace_m_rw_shift, - memTrace_m_addr_shift) + memTrace_m_val_shift) RefVector get_wires() { @@ -221,6 +312,36 @@ class AvmMiniFlavor { 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_u8, + aluChip_alu_u16, + aluChip_alu_u32, + aluChip_alu_u64, + aluChip_alu_u128, + aluChip_alu_s1, + aluChip_alu_s2, + aluChip_alu_s3, + aluChip_alu_s4, + aluChip_alu_s5, + aluChip_alu_s6, + aluChip_alu_s7, + aluChip_alu_s8, + aluChip_alu_s9, + aluChip_alu_s10, + aluChip_alu_s11, + aluChip_alu_s12, + aluChip_alu_s13, + aluChip_alu_s14, + aluChip_alu_s15, + aluChip_alu_s16, + aluChip_alu_cf, avmMini_pc, avmMini_internal_return_ptr, avmMini_sel_internal_call, @@ -249,10 +370,10 @@ class AvmMiniFlavor { avmMini_last, avmMini_internal_return_ptr_shift, avmMini_pc_shift, + memTrace_m_addr_shift, memTrace_m_tag_shift, - memTrace_m_val_shift, memTrace_m_rw_shift, - memTrace_m_addr_shift }; + memTrace_m_val_shift }; }; RefVector get_unshifted() { @@ -269,6 +390,36 @@ class AvmMiniFlavor { 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_u8, + aluChip_alu_u16, + aluChip_alu_u32, + aluChip_alu_u64, + aluChip_alu_u128, + aluChip_alu_s1, + aluChip_alu_s2, + aluChip_alu_s3, + aluChip_alu_s4, + aluChip_alu_s5, + aluChip_alu_s6, + aluChip_alu_s7, + aluChip_alu_s8, + aluChip_alu_s9, + aluChip_alu_s10, + aluChip_alu_s11, + aluChip_alu_s12, + aluChip_alu_s13, + aluChip_alu_s14, + aluChip_alu_s15, + aluChip_alu_s16, + aluChip_alu_cf, avmMini_pc, avmMini_internal_return_ptr, avmMini_sel_internal_call, @@ -299,17 +450,17 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { return { - avmMini_internal_return_ptr, avmMini_pc, memTrace_m_tag, memTrace_m_val, memTrace_m_rw, memTrace_m_addr + avmMini_internal_return_ptr, avmMini_pc, memTrace_m_addr, memTrace_m_tag, memTrace_m_rw, memTrace_m_val }; }; RefVector get_shifted() { return { avmMini_internal_return_ptr_shift, avmMini_pc_shift, + memTrace_m_addr_shift, memTrace_m_tag_shift, - memTrace_m_val_shift, memTrace_m_rw_shift, - memTrace_m_addr_shift }; + memTrace_m_val_shift }; }; }; @@ -323,7 +474,7 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { return { - avmMini_internal_return_ptr, avmMini_pc, memTrace_m_tag, memTrace_m_val, memTrace_m_rw, memTrace_m_addr + avmMini_internal_return_ptr, avmMini_pc, memTrace_m_addr, memTrace_m_tag, memTrace_m_rw, memTrace_m_val }; }; @@ -414,6 +565,36 @@ class AvmMiniFlavor { 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_u8 = "ALUCHIP_ALU_U8"; + Base::aluChip_alu_u16 = "ALUCHIP_ALU_U16"; + Base::aluChip_alu_u32 = "ALUCHIP_ALU_U32"; + Base::aluChip_alu_u64 = "ALUCHIP_ALU_U64"; + Base::aluChip_alu_u128 = "ALUCHIP_ALU_U128"; + Base::aluChip_alu_s1 = "ALUCHIP_ALU_S1"; + Base::aluChip_alu_s2 = "ALUCHIP_ALU_S2"; + Base::aluChip_alu_s3 = "ALUCHIP_ALU_S3"; + Base::aluChip_alu_s4 = "ALUCHIP_ALU_S4"; + Base::aluChip_alu_s5 = "ALUCHIP_ALU_S5"; + Base::aluChip_alu_s6 = "ALUCHIP_ALU_S6"; + Base::aluChip_alu_s7 = "ALUCHIP_ALU_S7"; + Base::aluChip_alu_s8 = "ALUCHIP_ALU_S8"; + Base::aluChip_alu_s9 = "ALUCHIP_ALU_S9"; + Base::aluChip_alu_s10 = "ALUCHIP_ALU_S10"; + Base::aluChip_alu_s11 = "ALUCHIP_ALU_S11"; + Base::aluChip_alu_s12 = "ALUCHIP_ALU_S12"; + Base::aluChip_alu_s13 = "ALUCHIP_ALU_S13"; + Base::aluChip_alu_s14 = "ALUCHIP_ALU_S14"; + Base::aluChip_alu_s15 = "ALUCHIP_ALU_S15"; + Base::aluChip_alu_s16 = "ALUCHIP_ALU_S16"; + 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"; @@ -470,6 +651,36 @@ class AvmMiniFlavor { 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_u8; + Commitment aluChip_alu_u16; + Commitment aluChip_alu_u32; + Commitment aluChip_alu_u64; + Commitment aluChip_alu_u128; + Commitment aluChip_alu_s1; + Commitment aluChip_alu_s2; + Commitment aluChip_alu_s3; + Commitment aluChip_alu_s4; + Commitment aluChip_alu_s5; + Commitment aluChip_alu_s6; + Commitment aluChip_alu_s7; + Commitment aluChip_alu_s8; + Commitment aluChip_alu_s9; + Commitment aluChip_alu_s10; + Commitment aluChip_alu_s11; + Commitment aluChip_alu_s12; + Commitment aluChip_alu_s13; + Commitment aluChip_alu_s14; + Commitment aluChip_alu_s15; + Commitment aluChip_alu_s16; + Commitment aluChip_alu_cf; Commitment avmMini_pc; Commitment avmMini_internal_return_ptr; Commitment avmMini_sel_internal_call; @@ -526,6 +737,36 @@ class AvmMiniFlavor { memTrace_m_in_tag = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); memTrace_m_tag_err = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); memTrace_m_one_min_inv = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_clk = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_ia = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_ib = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_ic = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_op_add = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_op_sub = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_op_mul = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_op_div = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u8 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u16 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u32 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u64 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u128 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s1 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s2 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s3 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s4 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s5 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s6 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s7 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s8 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s9 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s10 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s11 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s12 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s13 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s14 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s15 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_s16 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_cf = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); avmMini_pc = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); avmMini_internal_return_ptr = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); avmMini_sel_internal_call = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); @@ -586,6 +827,36 @@ class AvmMiniFlavor { 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_u8, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u16, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u32, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u64, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u128, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s1, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s2, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s3, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s4, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s5, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s6, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s7, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s8, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s9, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s10, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s11, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s12, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s13, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s14, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s15, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_s16, 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); 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 index a41fb694b9c..9ae8430594b 100644 --- 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 @@ -11,6 +11,7 @@ #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" @@ -32,6 +33,36 @@ template struct AvmMiniFullRow { 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_u8{}; + FF aluChip_alu_u16{}; + FF aluChip_alu_u32{}; + FF aluChip_alu_u64{}; + FF aluChip_alu_u128{}; + FF aluChip_alu_s1{}; + FF aluChip_alu_s2{}; + FF aluChip_alu_s3{}; + FF aluChip_alu_s4{}; + FF aluChip_alu_s5{}; + FF aluChip_alu_s6{}; + FF aluChip_alu_s7{}; + FF aluChip_alu_s8{}; + FF aluChip_alu_s9{}; + FF aluChip_alu_s10{}; + FF aluChip_alu_s11{}; + FF aluChip_alu_s12{}; + FF aluChip_alu_s13{}; + FF aluChip_alu_s14{}; + FF aluChip_alu_s15{}; + FF aluChip_alu_s16{}; + FF aluChip_alu_cf{}; FF avmMini_pc{}; FF avmMini_internal_return_ptr{}; FF avmMini_sel_internal_call{}; @@ -60,10 +91,10 @@ template struct AvmMiniFullRow { FF avmMini_last{}; FF avmMini_internal_return_ptr_shift{}; FF avmMini_pc_shift{}; + FF memTrace_m_addr_shift{}; FF memTrace_m_tag_shift{}; - FF memTrace_m_val_shift{}; FF memTrace_m_rw_shift{}; - FF memTrace_m_addr_shift{}; + FF memTrace_m_val_shift{}; }; class AvmMiniCircuitBuilder { @@ -76,8 +107,8 @@ class AvmMiniCircuitBuilder { using Polynomial = Flavor::Polynomial; using ProverPolynomials = Flavor::ProverPolynomials; - static constexpr size_t num_fixed_columns = 45; - static constexpr size_t num_polys = 39; + static constexpr size_t num_fixed_columns = 75; + static constexpr size_t num_polys = 69; std::vector rows; void set_trace(std::vector&& trace) { rows = std::move(trace); } @@ -106,6 +137,36 @@ class AvmMiniCircuitBuilder { 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_u8[i] = rows[i].aluChip_alu_u8; + polys.aluChip_alu_u16[i] = rows[i].aluChip_alu_u16; + polys.aluChip_alu_u32[i] = rows[i].aluChip_alu_u32; + polys.aluChip_alu_u64[i] = rows[i].aluChip_alu_u64; + polys.aluChip_alu_u128[i] = rows[i].aluChip_alu_u128; + polys.aluChip_alu_s1[i] = rows[i].aluChip_alu_s1; + polys.aluChip_alu_s2[i] = rows[i].aluChip_alu_s2; + polys.aluChip_alu_s3[i] = rows[i].aluChip_alu_s3; + polys.aluChip_alu_s4[i] = rows[i].aluChip_alu_s4; + polys.aluChip_alu_s5[i] = rows[i].aluChip_alu_s5; + polys.aluChip_alu_s6[i] = rows[i].aluChip_alu_s6; + polys.aluChip_alu_s7[i] = rows[i].aluChip_alu_s7; + polys.aluChip_alu_s8[i] = rows[i].aluChip_alu_s8; + polys.aluChip_alu_s9[i] = rows[i].aluChip_alu_s9; + polys.aluChip_alu_s10[i] = rows[i].aluChip_alu_s10; + polys.aluChip_alu_s11[i] = rows[i].aluChip_alu_s11; + polys.aluChip_alu_s12[i] = rows[i].aluChip_alu_s12; + polys.aluChip_alu_s13[i] = rows[i].aluChip_alu_s13; + polys.aluChip_alu_s14[i] = rows[i].aluChip_alu_s14; + polys.aluChip_alu_s15[i] = rows[i].aluChip_alu_s15; + polys.aluChip_alu_s16[i] = rows[i].aluChip_alu_s16; + 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; @@ -136,10 +197,10 @@ class AvmMiniCircuitBuilder { polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); + polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); - polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); + polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); return polys; } @@ -177,6 +238,10 @@ class AvmMiniCircuitBuilder { return true; }; + 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; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp new file mode 100644 index 00000000000..fa90a756f97 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -0,0 +1,245 @@ + +#pragma once +#include "../../relation_parameters.hpp" +#include "../../relation_types.hpp" +#include "./declare_views.hpp" + +namespace proof_system::AvmMini_vm { + +template struct Alu_chipRow { + FF aluChip_alu_s3{}; + FF aluChip_alu_s16{}; + FF aluChip_alu_s9{}; + FF aluChip_alu_op_add{}; + FF aluChip_alu_u32{}; + FF aluChip_alu_s5{}; + FF aluChip_alu_s6{}; + FF aluChip_alu_s1{}; + FF aluChip_alu_u64{}; + FF aluChip_alu_cf{}; + FF aluChip_alu_u16{}; + FF aluChip_alu_s4{}; + FF aluChip_alu_u128{}; + FF aluChip_alu_ia{}; + FF aluChip_alu_s2{}; + FF aluChip_alu_s8{}; + FF aluChip_alu_u8{}; + FF aluChip_alu_s10{}; + FF aluChip_alu_ib{}; + FF aluChip_alu_s11{}; + FF aluChip_alu_s12{}; + FF aluChip_alu_ic{}; + FF aluChip_alu_s14{}; + FF aluChip_alu_s13{}; + FF aluChip_alu_s15{}; + FF aluChip_alu_s7{}; +}; + +inline std::string get_relation_label_alu_chip(int index) +{ + switch (index) {} + 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, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, + }; + + 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_u8 * (-aluChip_alu_u8 + FF(1))); + tmp *= scaling_factor; + std::get<0>(evals) += tmp; + } + // Contribution 1 + { + AvmMini_DECLARE_VIEWS(1); + + auto tmp = (aluChip_alu_u16 * (-aluChip_alu_u16 + FF(1))); + tmp *= scaling_factor; + std::get<1>(evals) += tmp; + } + // Contribution 2 + { + AvmMini_DECLARE_VIEWS(2); + + auto tmp = (aluChip_alu_u32 * (-aluChip_alu_u32 + FF(1))); + tmp *= scaling_factor; + std::get<2>(evals) += tmp; + } + // Contribution 3 + { + AvmMini_DECLARE_VIEWS(3); + + auto tmp = (aluChip_alu_u64 * (-aluChip_alu_u64 + FF(1))); + tmp *= scaling_factor; + std::get<3>(evals) += tmp; + } + // Contribution 4 + { + AvmMini_DECLARE_VIEWS(4); + + auto tmp = (aluChip_alu_u128 * (-aluChip_alu_u128 + FF(1))); + tmp *= scaling_factor; + std::get<4>(evals) += tmp; + } + // Contribution 5 + { + AvmMini_DECLARE_VIEWS(5); + + auto tmp = ((aluChip_alu_u8 * aluChip_alu_op_add) * + (((aluChip_alu_s1 + (FF(256) * aluChip_alu_cf)) - aluChip_alu_ia) - aluChip_alu_ib)); + tmp *= scaling_factor; + std::get<5>(evals) += tmp; + } + // Contribution 6 + { + AvmMini_DECLARE_VIEWS(6); + + auto tmp = ((aluChip_alu_u8 * aluChip_alu_op_add) * (aluChip_alu_s1 - aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<6>(evals) += tmp; + } + // Contribution 7 + { + AvmMini_DECLARE_VIEWS(7); + + auto tmp = + ((aluChip_alu_u16 * aluChip_alu_op_add) * + ((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_cf)) - aluChip_alu_ia) - + aluChip_alu_ib)); + tmp *= scaling_factor; + std::get<7>(evals) += tmp; + } + // Contribution 8 + { + AvmMini_DECLARE_VIEWS(8); + + auto tmp = ((aluChip_alu_u16 * aluChip_alu_op_add) * + ((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) - aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<8>(evals) += tmp; + } + // Contribution 9 + { + AvmMini_DECLARE_VIEWS(9); + + auto tmp = ((aluChip_alu_u32 * aluChip_alu_op_add) * + ((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + + (FF(16777216) * aluChip_alu_s4)) + + (FF(4294967296UL) * aluChip_alu_cf)) - + aluChip_alu_ia) - + aluChip_alu_ib)); + tmp *= scaling_factor; + std::get<9>(evals) += tmp; + } + // Contribution 10 + { + AvmMini_DECLARE_VIEWS(10); + + auto tmp = ((aluChip_alu_u32 * aluChip_alu_op_add) * + ((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + + (FF(16777216) * aluChip_alu_s4)) - + aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<10>(evals) += tmp; + } + // Contribution 11 + { + AvmMini_DECLARE_VIEWS(11); + + auto tmp = ((aluChip_alu_u64 * aluChip_alu_op_add) * + ((((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + + (FF(16777216) * aluChip_alu_s4)) + + (FF(4294967296UL) * aluChip_alu_s5)) + + (FF(1099511627776UL) * aluChip_alu_s6)) + + (FF(281474976710656UL) * aluChip_alu_s7)) + + (FF(72057594037927936UL) * aluChip_alu_s8)) + + (FF(uint256_t{ 0, 1, 0, 0 }) * aluChip_alu_cf)) - + aluChip_alu_ia) - + aluChip_alu_ib)); + tmp *= scaling_factor; + std::get<11>(evals) += tmp; + } + // Contribution 12 + { + AvmMini_DECLARE_VIEWS(12); + + auto tmp = ((aluChip_alu_u64 * aluChip_alu_op_add) * + ((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + + (FF(16777216) * aluChip_alu_s4)) + + (FF(4294967296UL) * aluChip_alu_s5)) + + (FF(1099511627776UL) * aluChip_alu_s6)) + + (FF(281474976710656UL) * aluChip_alu_s7)) + + (FF(72057594037927936UL) * aluChip_alu_s8)) - + aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<12>(evals) += tmp; + } + // Contribution 13 + { + AvmMini_DECLARE_VIEWS(13); + + auto tmp = ((aluChip_alu_u128 * aluChip_alu_op_add) * + ((((((((((((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + + (FF(16777216) * aluChip_alu_s4)) + + (FF(4294967296UL) * aluChip_alu_s5)) + + (FF(1099511627776UL) * aluChip_alu_s6)) + + (FF(281474976710656UL) * aluChip_alu_s7)) + + (FF(72057594037927936UL) * aluChip_alu_s8)) + + (FF(uint256_t{ 0, 1, 0, 0 }) * aluChip_alu_s9)) + + (FF(uint256_t{ 0, 256, 0, 0 }) * aluChip_alu_s10)) + + (FF(uint256_t{ 0, 65536, 0, 0 }) * aluChip_alu_s11)) + + (FF(uint256_t{ 0, 16777216, 0, 0 }) * aluChip_alu_s12)) + + (FF(uint256_t{ 0, 4294967296, 0, 0 }) * aluChip_alu_s13)) + + (FF(uint256_t{ 0, 1099511627776, 0, 0 }) * aluChip_alu_s14)) + + (FF(uint256_t{ 0, 281474976710656, 0, 0 }) * aluChip_alu_s15)) + + (FF(uint256_t{ 0, 72057594037927936, 0, 0 }) * aluChip_alu_s16)) + + (FF(uint256_t{ 0, 0, 1, 0 }) * aluChip_alu_cf)) - + aluChip_alu_ia) - + aluChip_alu_ib)); + tmp *= scaling_factor; + std::get<13>(evals) += tmp; + } + // Contribution 14 + { + AvmMini_DECLARE_VIEWS(14); + + auto tmp = ((aluChip_alu_u128 * aluChip_alu_op_add) * + ((((((((((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + + (FF(16777216) * aluChip_alu_s4)) + + (FF(4294967296UL) * aluChip_alu_s5)) + + (FF(1099511627776UL) * aluChip_alu_s6)) + + (FF(281474976710656UL) * aluChip_alu_s7)) + + (FF(72057594037927936UL) * aluChip_alu_s8)) + + (FF(uint256_t{ 0, 1, 0, 0 }) * aluChip_alu_s9)) + + (FF(uint256_t{ 0, 256, 0, 0 }) * aluChip_alu_s10)) + + (FF(uint256_t{ 0, 65536, 0, 0 }) * aluChip_alu_s11)) + + (FF(uint256_t{ 0, 16777216, 0, 0 }) * aluChip_alu_s12)) + + (FF(uint256_t{ 0, 4294967296, 0, 0 }) * aluChip_alu_s13)) + + (FF(uint256_t{ 0, 1099511627776, 0, 0 }) * aluChip_alu_s14)) + + (FF(uint256_t{ 0, 281474976710656, 0, 0 }) * aluChip_alu_s15)) + + (FF(uint256_t{ 0, 72057594037927936, 0, 0 }) * aluChip_alu_s16)) - + aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<14>(evals) += tmp; + } + } +}; + +template using alu_chip = Relation>; + +} // namespace proof_system::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 index 46d9a5bc9e9..e05a4e149bd 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,38 +7,38 @@ namespace proof_system::AvmMini_vm { template struct Avm_miniRow { - FF avmMini_rwa{}; - FF avmMini_sel_op_div{}; + FF avmMini_sel_op_mul{}; + FF avmMini_sel_internal_return{}; + FF avmMini_mem_op_b{}; FF avmMini_inv{}; - FF avmMini_internal_return_ptr{}; FF avmMini_sel_internal_call{}; - FF avmMini_ic{}; - FF avmMini_rwb{}; - FF avmMini_sel_halt{}; - FF avmMini_sel_op_add{}; - FF avmMini_mem_op_b{}; - FF avmMini_op_err{}; FF avmMini_rwc{}; - FF avmMini_ib{}; - FF avmMini_mem_idx_a{}; - FF avmMini_sel_op_sub{}; - FF avmMini_sel_op_mul{}; - FF avmMini_ia{}; FF avmMini_internal_return_ptr_shift{}; - FF avmMini_pc{}; - FF avmMini_pc_shift{}; + FF avmMini_sel_op_add{}; + FF avmMini_mem_op_a{}; + FF avmMini_mem_idx_a{}; + FF avmMini_ib{}; + FF avmMini_internal_return_ptr{}; FF avmMini_tag_err{}; + FF avmMini_pc_shift{}; + FF avmMini_pc{}; + FF avmMini_op_err{}; + FF avmMini_rwa{}; + FF avmMini_sel_op_div{}; FF avmMini_mem_op_c{}; - FF avmMini_mem_op_a{}; - FF avmMini_sel_internal_return{}; + FF avmMini_sel_op_sub{}; + FF avmMini_ic{}; FF avmMini_first{}; + FF avmMini_rwb{}; + FF avmMini_sel_halt{}; + FF avmMini_ia{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { - case 20: - return "SUBOP_MULTIPLICATION_FF"; + case 19: + return "SUBOP_SUBTRACTION_FF"; case 22: return "SUBOP_DIVISION_ZERO_ERR1"; @@ -46,29 +46,29 @@ inline std::string get_relation_label_avm_mini(int index) case 23: return "SUBOP_DIVISION_ZERO_ERR2"; - case 24: - return "SUBOP_ERROR_RELEVANT_OP"; + case 18: + return "SUBOP_ADDITION_FF"; case 25: return "RETURN_POINTER_INCREMENT"; + case 24: + return "SUBOP_ERROR_RELEVANT_OP"; + case 30: return "RETURN_POINTER_DECREMENT"; - case 35: - return "PC_INCREMENT"; - - case 19: - return "SUBOP_SUBTRACTION_FF"; + case 36: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; case 21: return "SUBOP_DIVISION_FF"; - case 36: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + case 35: + return "PC_INCREMENT"; - case 18: - return "SUBOP_ADDITION_FF"; + case 20: + return "SUBOP_MULTIPLICATION_FF"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index 0c711d83429..917b455f060 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -15,6 +15,36 @@ [[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_u8 = View(new_term.aluChip_alu_u8); \ + [[maybe_unused]] auto aluChip_alu_u16 = View(new_term.aluChip_alu_u16); \ + [[maybe_unused]] auto aluChip_alu_u32 = View(new_term.aluChip_alu_u32); \ + [[maybe_unused]] auto aluChip_alu_u64 = View(new_term.aluChip_alu_u64); \ + [[maybe_unused]] auto aluChip_alu_u128 = View(new_term.aluChip_alu_u128); \ + [[maybe_unused]] auto aluChip_alu_s1 = View(new_term.aluChip_alu_s1); \ + [[maybe_unused]] auto aluChip_alu_s2 = View(new_term.aluChip_alu_s2); \ + [[maybe_unused]] auto aluChip_alu_s3 = View(new_term.aluChip_alu_s3); \ + [[maybe_unused]] auto aluChip_alu_s4 = View(new_term.aluChip_alu_s4); \ + [[maybe_unused]] auto aluChip_alu_s5 = View(new_term.aluChip_alu_s5); \ + [[maybe_unused]] auto aluChip_alu_s6 = View(new_term.aluChip_alu_s6); \ + [[maybe_unused]] auto aluChip_alu_s7 = View(new_term.aluChip_alu_s7); \ + [[maybe_unused]] auto aluChip_alu_s8 = View(new_term.aluChip_alu_s8); \ + [[maybe_unused]] auto aluChip_alu_s9 = View(new_term.aluChip_alu_s9); \ + [[maybe_unused]] auto aluChip_alu_s10 = View(new_term.aluChip_alu_s10); \ + [[maybe_unused]] auto aluChip_alu_s11 = View(new_term.aluChip_alu_s11); \ + [[maybe_unused]] auto aluChip_alu_s12 = View(new_term.aluChip_alu_s12); \ + [[maybe_unused]] auto aluChip_alu_s13 = View(new_term.aluChip_alu_s13); \ + [[maybe_unused]] auto aluChip_alu_s14 = View(new_term.aluChip_alu_s14); \ + [[maybe_unused]] auto aluChip_alu_s15 = View(new_term.aluChip_alu_s15); \ + [[maybe_unused]] auto aluChip_alu_s16 = View(new_term.aluChip_alu_s16); \ + [[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); \ @@ -43,7 +73,7 @@ [[maybe_unused]] auto avmMini_last = View(new_term.avmMini_last); \ [[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); \ + [[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 memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ - [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); + [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 2adc17baf9f..0a28e198ffd 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,41 +7,41 @@ namespace proof_system::AvmMini_vm { template struct Mem_traceRow { - FF memTrace_m_tag_shift{}; - FF memTrace_m_tag{}; - FF memTrace_m_rw{}; + FF memTrace_m_val{}; FF memTrace_m_lastAccess{}; FF memTrace_m_last{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_rw{}; FF memTrace_m_tag_err{}; - FF memTrace_m_val{}; + FF memTrace_m_tag_shift{}; FF memTrace_m_one_min_inv{}; - FF memTrace_m_val_shift{}; - FF memTrace_m_addr{}; FF memTrace_m_rw_shift{}; - FF memTrace_m_addr_shift{}; + FF memTrace_m_val_shift{}; + FF memTrace_m_tag{}; FF memTrace_m_in_tag{}; + FF memTrace_m_addr{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { + case 6: + return "MEM_READ_WRITE_TAG_CONSISTENCY"; + case 5: return "MEM_READ_WRITE_VAL_CONSISTENCY"; + case 4: + return "MEM_LAST_ACCESS_DELIMITER"; + case 7: return "MEM_ZERO_INIT"; - case 9: - return "MEM_IN_TAG_CONSISTENCY_2"; - case 8: return "MEM_IN_TAG_CONSISTENCY_1"; - case 4: - return "MEM_LAST_ACCESS_DELIMITER"; - - case 6: - return "MEM_READ_WRITE_TAG_CONSISTENCY"; + case 9: + return "MEM_IN_TAG_CONSISTENCY_2"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp index 5673710fa24..6a44bbc45f9 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp @@ -73,6 +73,52 @@ bool AvmMiniVerifier::verify_proof(const plonk::proof& proof) 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_u8 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_u8); + commitments.aluChip_alu_u16 = + transcript->template receive_from_prover(commitment_labels.aluChip_alu_u16); + commitments.aluChip_alu_u32 = + transcript->template receive_from_prover(commitment_labels.aluChip_alu_u32); + commitments.aluChip_alu_u64 = + transcript->template receive_from_prover(commitment_labels.aluChip_alu_u64); + commitments.aluChip_alu_u128 = + transcript->template receive_from_prover(commitment_labels.aluChip_alu_u128); + commitments.aluChip_alu_s1 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s1); + commitments.aluChip_alu_s2 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s2); + commitments.aluChip_alu_s3 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s3); + commitments.aluChip_alu_s4 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s4); + commitments.aluChip_alu_s5 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s5); + commitments.aluChip_alu_s6 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s6); + commitments.aluChip_alu_s7 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s7); + commitments.aluChip_alu_s8 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s8); + commitments.aluChip_alu_s9 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s9); + commitments.aluChip_alu_s10 = + transcript->template receive_from_prover(commitment_labels.aluChip_alu_s10); + commitments.aluChip_alu_s11 = + transcript->template receive_from_prover(commitment_labels.aluChip_alu_s11); + commitments.aluChip_alu_s12 = + transcript->template receive_from_prover(commitment_labels.aluChip_alu_s12); + commitments.aluChip_alu_s13 = + transcript->template receive_from_prover(commitment_labels.aluChip_alu_s13); + commitments.aluChip_alu_s14 = + transcript->template receive_from_prover(commitment_labels.aluChip_alu_s14); + commitments.aluChip_alu_s15 = + transcript->template receive_from_prover(commitment_labels.aluChip_alu_s15); + commitments.aluChip_alu_s16 = + transcript->template receive_from_prover(commitment_labels.aluChip_alu_s16); + 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); From 0258f344fe3318ccb520b2696b44c97061424a7e Mon Sep 17 00:00:00 2001 From: jeanmon Date: Thu, 21 Dec 2023 12:13:23 +0000 Subject: [PATCH 02/28] PIL relations for subtraction of u8, u16, u32, u64, 128 types --- barretenberg/cpp/pil/avm/alu_chip.pil | 39 +++- .../flavor/generated/AvmMini_flavor.hpp | 36 ++-- .../generated/AvmMini_circuit_builder.hpp | 24 +-- .../relations/generated/AvmMini/alu_chip.hpp | 180 ++++++++++++++++-- .../relations/generated/AvmMini/avm_mini.hpp | 62 +++--- .../generated/AvmMini/declare_views.hpp | 8 +- .../relations/generated/AvmMini/mem_trace.hpp | 32 ++-- 7 files changed, 276 insertions(+), 105 deletions(-) diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil index 7c00b392fae..6fd3fa39429 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -63,9 +63,12 @@ namespace aluChip(256); // TODO: Equivalence between intermediate registers, clk, type flag, operation // An ALU chiplet flag will be introduced in main trace to select relevant rows. - // ========= ADDITION Operation Constraints =============================== - - // Intermediate polynomial terms + + + // ============= Helper polynomial terms ============================ + // These are intermediate polynomial terms which are not commited but + // serves to express commited polynomials in a more concise way. + // 8-bit slice partial sums pol sum_8 = alu_s1; pol sum_16 = sum_8 + 2**8 * alu_s2; @@ -74,6 +77,9 @@ namespace aluChip(256); pol sum_96 = sum_64 + 2**64 * alu_s9 + 2**72 * alu_s10 + 2**80 * alu_s11 + 2**88 * alu_s12; pol sum_128 = sum_96 + 2**96 * alu_s13 + 2**104 * alu_s14 + 2**112 * alu_s15 + 2**120 * alu_s16; + + // ========= ADDITION Operation Constraints =============================== + // u8 addition alu_u8 * alu_op_add * (sum_8 + 2**8 * alu_cf - alu_ia - alu_ib) = 0; alu_u8 * alu_op_add * (sum_8 - alu_ic) = 0; @@ -92,4 +98,29 @@ namespace aluChip(256); // u128 addition alu_u128 * alu_op_add * (sum_128 + 2**128 * alu_cf - alu_ia - alu_ib) = 0; - alu_u128 * alu_op_add * (sum_128 - alu_ic) = 0; \ No newline at end of file + alu_u128 * alu_op_add * (sum_128 - alu_ic) = 0; + + // ========= SUBTRACTION Operation Constraints =============================== + + // a - b = c <==> c + b = a (mod 2^k) + // Same constraints as for addition but we swap alu_ia with alu_ic + + // u8 subtraction + alu_u8 * alu_op_sub * (sum_8 + 2**8 * alu_cf - alu_ic - alu_ib) = 0; + alu_u8 * alu_op_sub * (sum_8 - alu_ia) = 0; + + // u16 subtraction + alu_u16 * alu_op_sub * (sum_16 + 2**16 * alu_cf - alu_ic - alu_ib) = 0; + alu_u16 * alu_op_sub * (sum_16 - alu_ia) = 0; + + // u32 subtraction + alu_u32 * alu_op_sub * (sum_32 + 2**32 * alu_cf - alu_ic - alu_ib) = 0; + alu_u32 * alu_op_sub * (sum_32 - alu_ia) = 0; + + // u64 subtraction + alu_u64 * alu_op_sub * (sum_64 + 2**64 * alu_cf - alu_ic - alu_ib) = 0; + alu_u64 * alu_op_sub * (sum_64 - alu_ia) = 0; + + // u128 subtraction + alu_u128 * alu_op_sub * (sum_128 + 2**128 * alu_cf - alu_ic - alu_ib) = 0; + alu_u128 * alu_op_sub * (sum_128 - alu_ia) = 0; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index c7c61695866..2f9e2d12060 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -43,7 +43,7 @@ class AvmMiniFlavor { // the unshifted and one for the shifted static constexpr size_t NUM_ALL_ENTITIES = 75; - using Relations = std::tuple, AvmMini_vm::avm_mini, AvmMini_vm::mem_trace>; + 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(); @@ -290,12 +290,12 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift, + memTrace_m_rw_shift, memTrace_m_addr_shift, + memTrace_m_val_shift, memTrace_m_tag_shift, - memTrace_m_rw_shift, - memTrace_m_val_shift) + avmMini_internal_return_ptr_shift, + avmMini_pc_shift) RefVector get_wires() { @@ -368,12 +368,12 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift, + memTrace_m_rw_shift, memTrace_m_addr_shift, + memTrace_m_val_shift, memTrace_m_tag_shift, - memTrace_m_rw_shift, - memTrace_m_val_shift }; + avmMini_internal_return_ptr_shift, + avmMini_pc_shift }; }; RefVector get_unshifted() { @@ -449,18 +449,17 @@ class AvmMiniFlavor { }; RefVector get_to_be_shifted() { - return { - avmMini_internal_return_ptr, avmMini_pc, memTrace_m_addr, memTrace_m_tag, memTrace_m_rw, memTrace_m_val - }; + return { memTrace_m_rw, memTrace_m_addr, memTrace_m_val, memTrace_m_tag, avmMini_internal_return_ptr, + avmMini_pc }; }; RefVector get_shifted() { - return { avmMini_internal_return_ptr_shift, - avmMini_pc_shift, + return { memTrace_m_rw_shift, memTrace_m_addr_shift, + memTrace_m_val_shift, memTrace_m_tag_shift, - memTrace_m_rw_shift, - memTrace_m_val_shift }; + avmMini_internal_return_ptr_shift, + avmMini_pc_shift }; }; }; @@ -473,9 +472,8 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { - avmMini_internal_return_ptr, avmMini_pc, memTrace_m_addr, memTrace_m_tag, memTrace_m_rw, memTrace_m_val - }; + return { memTrace_m_rw, memTrace_m_addr, memTrace_m_val, memTrace_m_tag, avmMini_internal_return_ptr, + avmMini_pc }; }; // The plookup wires that store plookup read data. 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 index 9ae8430594b..ede4fff5449 100644 --- 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 @@ -89,12 +89,12 @@ template struct AvmMiniFullRow { FF avmMini_mem_idx_b{}; FF avmMini_mem_idx_c{}; FF avmMini_last{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_pc_shift{}; - FF memTrace_m_addr_shift{}; - FF memTrace_m_tag_shift{}; FF memTrace_m_rw_shift{}; + FF memTrace_m_addr_shift{}; FF memTrace_m_val_shift{}; + FF memTrace_m_tag_shift{}; + FF avmMini_internal_return_ptr_shift{}; + FF avmMini_pc_shift{}; }; class AvmMiniCircuitBuilder { @@ -195,12 +195,12 @@ class AvmMiniCircuitBuilder { polys.avmMini_last[i] = rows[i].avmMini_last; } - polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); - polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); - polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); + polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); + polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.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; } @@ -238,6 +238,10 @@ class AvmMiniCircuitBuilder { 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; @@ -246,10 +250,6 @@ class AvmMiniCircuitBuilder { AvmMini_vm::get_relation_label_avm_mini)) { return false; } - if (!evaluate_relation.template operator()>( - "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { - return false; - } return true; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index fa90a756f97..aee7603ac65 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,32 +7,33 @@ namespace proof_system::AvmMini_vm { template struct Alu_chipRow { - FF aluChip_alu_s3{}; - FF aluChip_alu_s16{}; + FF aluChip_alu_ib{}; + FF aluChip_alu_s7{}; FF aluChip_alu_s9{}; + FF aluChip_alu_ic{}; FF aluChip_alu_op_add{}; - FF aluChip_alu_u32{}; - FF aluChip_alu_s5{}; + FF aluChip_alu_u128{}; FF aluChip_alu_s6{}; + FF aluChip_alu_s15{}; FF aluChip_alu_s1{}; - FF aluChip_alu_u64{}; - FF aluChip_alu_cf{}; - FF aluChip_alu_u16{}; - FF aluChip_alu_s4{}; - FF aluChip_alu_u128{}; - FF aluChip_alu_ia{}; + FF aluChip_alu_u32{}; FF aluChip_alu_s2{}; FF aluChip_alu_s8{}; - FF aluChip_alu_u8{}; - FF aluChip_alu_s10{}; - FF aluChip_alu_ib{}; + FF aluChip_alu_s16{}; FF aluChip_alu_s11{}; + FF aluChip_alu_u8{}; + FF aluChip_alu_s4{}; FF aluChip_alu_s12{}; - FF aluChip_alu_ic{}; - FF aluChip_alu_s14{}; + FF aluChip_alu_s10{}; FF aluChip_alu_s13{}; - FF aluChip_alu_s15{}; - FF aluChip_alu_s7{}; + FF aluChip_alu_op_sub{}; + FF aluChip_alu_cf{}; + FF aluChip_alu_ia{}; + FF aluChip_alu_s5{}; + FF aluChip_alu_s14{}; + FF aluChip_alu_u64{}; + FF aluChip_alu_u16{}; + FF aluChip_alu_s3{}; }; inline std::string get_relation_label_alu_chip(int index) @@ -45,8 +46,8 @@ template class alu_chipImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, 3, 3, 3, 3, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 3, 3, 3, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, }; template @@ -237,6 +238,147 @@ template class alu_chipImpl { tmp *= scaling_factor; std::get<14>(evals) += tmp; } + // Contribution 15 + { + AvmMini_DECLARE_VIEWS(15); + + auto tmp = ((aluChip_alu_u8 * aluChip_alu_op_sub) * + (((aluChip_alu_s1 + (FF(256) * aluChip_alu_cf)) - aluChip_alu_ic) - aluChip_alu_ib)); + tmp *= scaling_factor; + std::get<15>(evals) += tmp; + } + // Contribution 16 + { + AvmMini_DECLARE_VIEWS(16); + + auto tmp = ((aluChip_alu_u8 * aluChip_alu_op_sub) * (aluChip_alu_s1 - aluChip_alu_ia)); + tmp *= scaling_factor; + std::get<16>(evals) += tmp; + } + // Contribution 17 + { + AvmMini_DECLARE_VIEWS(17); + + auto tmp = + ((aluChip_alu_u16 * aluChip_alu_op_sub) * + ((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_cf)) - aluChip_alu_ic) - + aluChip_alu_ib)); + tmp *= scaling_factor; + std::get<17>(evals) += tmp; + } + // Contribution 18 + { + AvmMini_DECLARE_VIEWS(18); + + auto tmp = ((aluChip_alu_u16 * aluChip_alu_op_sub) * + ((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) - aluChip_alu_ia)); + tmp *= scaling_factor; + std::get<18>(evals) += tmp; + } + // Contribution 19 + { + AvmMini_DECLARE_VIEWS(19); + + auto tmp = ((aluChip_alu_u32 * aluChip_alu_op_sub) * + ((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + + (FF(16777216) * aluChip_alu_s4)) + + (FF(4294967296UL) * aluChip_alu_cf)) - + aluChip_alu_ic) - + aluChip_alu_ib)); + tmp *= scaling_factor; + std::get<19>(evals) += tmp; + } + // Contribution 20 + { + AvmMini_DECLARE_VIEWS(20); + + auto tmp = ((aluChip_alu_u32 * aluChip_alu_op_sub) * + ((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + + (FF(16777216) * aluChip_alu_s4)) - + aluChip_alu_ia)); + tmp *= scaling_factor; + std::get<20>(evals) += tmp; + } + // Contribution 21 + { + AvmMini_DECLARE_VIEWS(21); + + auto tmp = ((aluChip_alu_u64 * aluChip_alu_op_sub) * + ((((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + + (FF(16777216) * aluChip_alu_s4)) + + (FF(4294967296UL) * aluChip_alu_s5)) + + (FF(1099511627776UL) * aluChip_alu_s6)) + + (FF(281474976710656UL) * aluChip_alu_s7)) + + (FF(72057594037927936UL) * aluChip_alu_s8)) + + (FF(uint256_t{ 0, 1, 0, 0 }) * aluChip_alu_cf)) - + aluChip_alu_ic) - + aluChip_alu_ib)); + tmp *= scaling_factor; + std::get<21>(evals) += tmp; + } + // Contribution 22 + { + AvmMini_DECLARE_VIEWS(22); + + auto tmp = ((aluChip_alu_u64 * aluChip_alu_op_sub) * + ((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + + (FF(16777216) * aluChip_alu_s4)) + + (FF(4294967296UL) * aluChip_alu_s5)) + + (FF(1099511627776UL) * aluChip_alu_s6)) + + (FF(281474976710656UL) * aluChip_alu_s7)) + + (FF(72057594037927936UL) * aluChip_alu_s8)) - + aluChip_alu_ia)); + tmp *= scaling_factor; + std::get<22>(evals) += tmp; + } + // Contribution 23 + { + AvmMini_DECLARE_VIEWS(23); + + auto tmp = ((aluChip_alu_u128 * aluChip_alu_op_sub) * + ((((((((((((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + + (FF(16777216) * aluChip_alu_s4)) + + (FF(4294967296UL) * aluChip_alu_s5)) + + (FF(1099511627776UL) * aluChip_alu_s6)) + + (FF(281474976710656UL) * aluChip_alu_s7)) + + (FF(72057594037927936UL) * aluChip_alu_s8)) + + (FF(uint256_t{ 0, 1, 0, 0 }) * aluChip_alu_s9)) + + (FF(uint256_t{ 0, 256, 0, 0 }) * aluChip_alu_s10)) + + (FF(uint256_t{ 0, 65536, 0, 0 }) * aluChip_alu_s11)) + + (FF(uint256_t{ 0, 16777216, 0, 0 }) * aluChip_alu_s12)) + + (FF(uint256_t{ 0, 4294967296, 0, 0 }) * aluChip_alu_s13)) + + (FF(uint256_t{ 0, 1099511627776, 0, 0 }) * aluChip_alu_s14)) + + (FF(uint256_t{ 0, 281474976710656, 0, 0 }) * aluChip_alu_s15)) + + (FF(uint256_t{ 0, 72057594037927936, 0, 0 }) * aluChip_alu_s16)) + + (FF(uint256_t{ 0, 0, 1, 0 }) * aluChip_alu_cf)) - + aluChip_alu_ic) - + aluChip_alu_ib)); + tmp *= scaling_factor; + std::get<23>(evals) += tmp; + } + // Contribution 24 + { + AvmMini_DECLARE_VIEWS(24); + + auto tmp = ((aluChip_alu_u128 * aluChip_alu_op_sub) * + ((((((((((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + + (FF(16777216) * aluChip_alu_s4)) + + (FF(4294967296UL) * aluChip_alu_s5)) + + (FF(1099511627776UL) * aluChip_alu_s6)) + + (FF(281474976710656UL) * aluChip_alu_s7)) + + (FF(72057594037927936UL) * aluChip_alu_s8)) + + (FF(uint256_t{ 0, 1, 0, 0 }) * aluChip_alu_s9)) + + (FF(uint256_t{ 0, 256, 0, 0 }) * aluChip_alu_s10)) + + (FF(uint256_t{ 0, 65536, 0, 0 }) * aluChip_alu_s11)) + + (FF(uint256_t{ 0, 16777216, 0, 0 }) * aluChip_alu_s12)) + + (FF(uint256_t{ 0, 4294967296, 0, 0 }) * aluChip_alu_s13)) + + (FF(uint256_t{ 0, 1099511627776, 0, 0 }) * aluChip_alu_s14)) + + (FF(uint256_t{ 0, 281474976710656, 0, 0 }) * aluChip_alu_s15)) + + (FF(uint256_t{ 0, 72057594037927936, 0, 0 }) * aluChip_alu_s16)) - + aluChip_alu_ia)); + tmp *= scaling_factor; + std::get<24>(evals) += tmp; + } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index e05a4e149bd..ed1f7efc9da 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,38 +7,38 @@ namespace proof_system::AvmMini_vm { template struct Avm_miniRow { - FF avmMini_sel_op_mul{}; + FF avmMini_ic{}; + FF avmMini_rwa{}; FF avmMini_sel_internal_return{}; + FF avmMini_op_err{}; + FF avmMini_internal_return_ptr_shift{}; + FF avmMini_internal_return_ptr{}; + FF avmMini_sel_internal_call{}; + FF avmMini_pc_shift{}; FF avmMini_mem_op_b{}; + FF avmMini_rwb{}; + FF avmMini_sel_op_sub{}; FF avmMini_inv{}; - FF avmMini_sel_internal_call{}; - FF avmMini_rwc{}; - FF avmMini_internal_return_ptr_shift{}; + FF avmMini_ia{}; + FF avmMini_sel_op_mul{}; + FF avmMini_sel_op_div{}; + FF avmMini_mem_idx_a{}; + FF avmMini_sel_halt{}; FF avmMini_sel_op_add{}; + FF avmMini_tag_err{}; FF avmMini_mem_op_a{}; - FF avmMini_mem_idx_a{}; FF avmMini_ib{}; - FF avmMini_internal_return_ptr{}; - FF avmMini_tag_err{}; - FF avmMini_pc_shift{}; FF avmMini_pc{}; - FF avmMini_op_err{}; - FF avmMini_rwa{}; - FF avmMini_sel_op_div{}; + FF avmMini_rwc{}; FF avmMini_mem_op_c{}; - FF avmMini_sel_op_sub{}; - FF avmMini_ic{}; FF avmMini_first{}; - FF avmMini_rwb{}; - FF avmMini_sel_halt{}; - FF avmMini_ia{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { - case 19: - return "SUBOP_SUBTRACTION_FF"; + case 20: + return "SUBOP_MULTIPLICATION_FF"; case 22: return "SUBOP_DIVISION_ZERO_ERR1"; @@ -46,29 +46,29 @@ inline std::string get_relation_label_avm_mini(int index) case 23: return "SUBOP_DIVISION_ZERO_ERR2"; - case 18: - return "SUBOP_ADDITION_FF"; + case 24: + return "SUBOP_ERROR_RELEVANT_OP"; + + case 21: + return "SUBOP_DIVISION_FF"; case 25: return "RETURN_POINTER_INCREMENT"; - case 24: - return "SUBOP_ERROR_RELEVANT_OP"; + case 35: + return "PC_INCREMENT"; + + case 18: + return "SUBOP_ADDITION_FF"; + + case 19: + return "SUBOP_SUBTRACTION_FF"; case 30: return "RETURN_POINTER_DECREMENT"; case 36: return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - - case 21: - return "SUBOP_DIVISION_FF"; - - case 35: - return "PC_INCREMENT"; - - case 20: - return "SUBOP_MULTIPLICATION_FF"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index 917b455f060..64e24477ada 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -71,9 +71,9 @@ [[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 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); \ + [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ + [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ - [[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 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/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 0a28e198ffd..342c917c455 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,41 +7,41 @@ namespace proof_system::AvmMini_vm { template struct Mem_traceRow { - FF memTrace_m_val{}; - FF memTrace_m_lastAccess{}; - FF memTrace_m_last{}; - FF memTrace_m_addr_shift{}; FF memTrace_m_rw{}; - FF memTrace_m_tag_err{}; - FF memTrace_m_tag_shift{}; - FF memTrace_m_one_min_inv{}; FF memTrace_m_rw_shift{}; + FF memTrace_m_one_min_inv{}; + FF memTrace_m_addr_shift{}; FF memTrace_m_val_shift{}; - FF memTrace_m_tag{}; FF memTrace_m_in_tag{}; + FF memTrace_m_lastAccess{}; + FF memTrace_m_tag_shift{}; + FF memTrace_m_last{}; + FF memTrace_m_tag{}; + FF memTrace_m_val{}; FF memTrace_m_addr{}; + FF memTrace_m_tag_err{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { - case 6: - return "MEM_READ_WRITE_TAG_CONSISTENCY"; - case 5: return "MEM_READ_WRITE_VAL_CONSISTENCY"; - case 4: - return "MEM_LAST_ACCESS_DELIMITER"; + case 6: + return "MEM_READ_WRITE_TAG_CONSISTENCY"; case 7: return "MEM_ZERO_INIT"; - case 8: - return "MEM_IN_TAG_CONSISTENCY_1"; - case 9: return "MEM_IN_TAG_CONSISTENCY_2"; + + case 4: + return "MEM_LAST_ACCESS_DELIMITER"; + + case 8: + return "MEM_IN_TAG_CONSISTENCY_1"; } return std::to_string(index); } From 8594bfcddc4548fe101841054ef547e4cc870019 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Tue, 2 Jan 2024 11:09:59 +0000 Subject: [PATCH 03/28] 3738 - explanations on arithmetic operations PIL relations --- barretenberg/cpp/pil/avm/alu_chip.pil | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil index 6fd3fa39429..c51b67a9d84 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -77,6 +77,26 @@ namespace aluChip(256); pol sum_96 = sum_64 + 2**64 * alu_s9 + 2**72 * alu_s10 + 2**80 * alu_s11 + 2**88 * alu_s12; pol sum_128 = sum_96 + 2**96 * alu_s13 + 2**104 * alu_s14 + 2**112 * alu_s15 + 2**120 * alu_s16; + // ========= EXPLANATIONS ================================================= + // Main trick for arithmetic operations modulo 2^k is to perform the operation + // over the integers and expressing the result as low + high * 2^k with low + // smaller than 2^k. low is used as the output. This works as long this does + // not overflow the underlying finite field order (u128 multiplication will be + // handled differently). If we want to prove that c = OP(a,b) where OP denotes + // an arithmetic operation modulo 2^k, we need two relations: + // (1) low + high * 2^k - OP(a,b) = 0 + // (2) low - c = 0 + // + // We support u8, u16, u32, u64, u128 types and decompose low into + // smaller bit slices, e.g., 16. For instance, low = s_0 + s_1 * 2^16 + s_2 * 2^32 + ... + // The slices have to be range constrained and there is a trade-off between the + // number of regiesters and complexity of the range constraints. + // TODO: Determine the best slice size allocation. Note that we might choose different + // slice sizes for the different types. At this stage, it is still unknown how this + // allocation affects the performance. + // + // Preliminary choice: We use one u8 register to support u8 operations and up to 8 u16 + // registers for the other types. // ========= ADDITION Operation Constraints =============================== From d3f0a13ec36e3a36dbf251bc1cb23ce243f11bc3 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Tue, 2 Jan 2024 12:06:13 +0000 Subject: [PATCH 04/28] 3738 - additions and subtractions re-visited with 16-bit registers --- barretenberg/cpp/pil/avm/alu_chip.pil | 113 +++--- .../flavor/generated/AvmMini_flavor.hpp | 329 +++++++----------- .../generated/AvmMini_circuit_builder.hpp | 78 ++--- .../relations/generated/AvmMini/alu_chip.hpp | 265 ++++++-------- .../relations/generated/AvmMini/avm_mini.hpp | 64 ++-- .../generated/AvmMini/declare_views.hpp | 37 +- .../relations/generated/AvmMini/mem_trace.hpp | 22 +- .../vm/generated/AvmMini_verifier.cpp | 60 ++-- 8 files changed, 408 insertions(+), 560 deletions(-) diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil index c51b67a9d84..cccb32a406e 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -17,29 +17,24 @@ namespace aluChip(256); pol commit alu_op_div; // Flattened boolean instruction tags - pol commit alu_u8; - pol commit alu_u16; - pol commit alu_u32; - pol commit alu_u64; - pol commit alu_u128; + pol commit alu_u8_tag; + pol commit alu_u16_tag; + pol commit alu_u32_tag; + pol commit alu_u64_tag; + pol commit alu_u128_tag; // 8-bit slice registers - pol commit alu_s1; - pol commit alu_s2; - pol commit alu_s3; - pol commit alu_s4; - pol commit alu_s5; - pol commit alu_s6; - pol commit alu_s7; - pol commit alu_s8; - pol commit alu_s9; - pol commit alu_s10; - pol commit alu_s11; - pol commit alu_s12; - pol commit alu_s13; - pol commit alu_s14; - pol commit alu_s15; - pol commit alu_s16; + pol commit alu_u8_r0; + + // 16-bit slice registers + pol commit alu_u16_r0; + pol commit alu_u16_r1; + pol commit alu_u16_r2; + pol commit alu_u16_r3; + pol commit alu_u16_r4; + pol commit alu_u16_r5; + pol commit alu_u16_r6; + pol commit alu_u16_r7; // Carry flag pol commit alu_cf; @@ -51,11 +46,11 @@ namespace aluChip(256); // arithmetic expressions are not overflowing finite field size // Boolean flattened instructions tags - alu_u8 * (1 - alu_u8) = 0; - alu_u16 * (1 - alu_u16) = 0; - alu_u32 * (1 - alu_u32) = 0; - alu_u64 * (1 - alu_u64) = 0; - alu_u128 * (1 - alu_u128) = 0; + alu_u8_tag * (1 - alu_u8_tag) = 0; + alu_u16_tag * (1 - alu_u16_tag) = 0; + alu_u32_tag * (1 - alu_u32_tag) = 0; + alu_u64_tag * (1 - alu_u64_tag) = 0; + alu_u128_tag * (1 - alu_u128_tag) = 0; // Operation selectors are copied from main table and do not need to be constrained here. @@ -64,19 +59,6 @@ namespace aluChip(256); // An ALU chiplet flag will be introduced in main trace to select relevant rows. - - // ============= Helper polynomial terms ============================ - // These are intermediate polynomial terms which are not commited but - // serves to express commited polynomials in a more concise way. - - // 8-bit slice partial sums - pol sum_8 = alu_s1; - pol sum_16 = sum_8 + 2**8 * alu_s2; - pol sum_32 = sum_16 + 2**16 * alu_s3 + 2**24 * alu_s4; - pol sum_64 = sum_32 + 2**32 * alu_s5 + 2**40 * alu_s6 + 2**48 * alu_s7 + 2**56 * alu_s8; - pol sum_96 = sum_64 + 2**64 * alu_s9 + 2**72 * alu_s10 + 2**80 * alu_s11 + 2**88 * alu_s12; - pol sum_128 = sum_96 + 2**96 * alu_s13 + 2**104 * alu_s14 + 2**112 * alu_s15 + 2**120 * alu_s16; - // ========= EXPLANATIONS ================================================= // Main trick for arithmetic operations modulo 2^k is to perform the operation // over the integers and expressing the result as low + high * 2^k with low @@ -98,27 +80,40 @@ namespace aluChip(256); // Preliminary choice: We use one u8 register to support u8 operations and up to 8 u16 // registers for the other types. + + // ============= Helper polynomial terms ============================ + // These are intermediate polynomial terms which are not commited but + // serves to express commited polynomials in a more concise way. + + // 16-bit slice partial sums + pol sum_16 = alu_u16_r0; + pol sum_32 = sum_16 + alu_u16_r1 * 2**16; + pol sum_64 = sum_32 + alu_u16_r2 * 2**32 + alu_u16_r3 * 2**48; + pol sum_96 = sum_64 + alu_u16_r4 * 2**64 + alu_u16_r5 * 2**80; + pol sum_128 = sum_96 + alu_u16_r6 * 2**96 + alu_u16_r7 * 2**112; + + // ========= ADDITION Operation Constraints =============================== // u8 addition - alu_u8 * alu_op_add * (sum_8 + 2**8 * alu_cf - alu_ia - alu_ib) = 0; - alu_u8 * alu_op_add * (sum_8 - alu_ic) = 0; + alu_u8_tag * alu_op_add * (alu_u8_r0 + alu_cf * 2**8 - alu_ia - alu_ib) = 0; + alu_u8_tag * alu_op_add * (alu_u8_r0 - alu_ic) = 0; // u16 addition - alu_u16 * alu_op_add * (sum_16 + 2**16 * alu_cf - alu_ia - alu_ib) = 0; - alu_u16 * alu_op_add * (sum_16 - alu_ic) = 0; + alu_u16_tag * alu_op_add * (sum_16 + alu_cf * 2**16 - alu_ia - alu_ib) = 0; + alu_u16_tag * alu_op_add * (sum_16 - alu_ic) = 0; // u32 addition - alu_u32 * alu_op_add * (sum_32 + 2**32 * alu_cf - alu_ia - alu_ib) = 0; - alu_u32 * alu_op_add * (sum_32 - alu_ic) = 0; + alu_u32_tag * alu_op_add * (sum_32 + alu_cf * 2**32 - alu_ia - alu_ib) = 0; + alu_u32_tag * alu_op_add * (sum_32 - alu_ic) = 0; // u64 addition - alu_u64 * alu_op_add * (sum_64 + 2**64 * alu_cf - alu_ia - alu_ib) = 0; - alu_u64 * alu_op_add * (sum_64 - alu_ic) = 0; + alu_u64_tag * alu_op_add * (sum_64 + alu_cf * 2**64 - alu_ia - alu_ib) = 0; + alu_u64_tag * alu_op_add * (sum_64 - alu_ic) = 0; // u128 addition - alu_u128 * alu_op_add * (sum_128 + 2**128 * alu_cf - alu_ia - alu_ib) = 0; - alu_u128 * alu_op_add * (sum_128 - alu_ic) = 0; + alu_u128_tag * alu_op_add * (sum_128 + alu_cf * 2**128 - alu_ia - alu_ib) = 0; + alu_u128_tag * alu_op_add * (sum_128 - alu_ic) = 0; // ========= SUBTRACTION Operation Constraints =============================== @@ -126,21 +121,21 @@ namespace aluChip(256); // Same constraints as for addition but we swap alu_ia with alu_ic // u8 subtraction - alu_u8 * alu_op_sub * (sum_8 + 2**8 * alu_cf - alu_ic - alu_ib) = 0; - alu_u8 * alu_op_sub * (sum_8 - alu_ia) = 0; + alu_u8_tag * alu_op_sub * (alu_u8_r0 + alu_cf * 2**8 - alu_ic - alu_ib) = 0; + alu_u8_tag * alu_op_sub * (alu_u8_r0 - alu_ia) = 0; // u16 subtraction - alu_u16 * alu_op_sub * (sum_16 + 2**16 * alu_cf - alu_ic - alu_ib) = 0; - alu_u16 * alu_op_sub * (sum_16 - alu_ia) = 0; + alu_u16_tag * alu_op_sub * (sum_16 + alu_cf * 2**16 - alu_ic - alu_ib) = 0; + alu_u16_tag * alu_op_sub * (sum_16 - alu_ia) = 0; // u32 subtraction - alu_u32 * alu_op_sub * (sum_32 + 2**32 * alu_cf - alu_ic - alu_ib) = 0; - alu_u32 * alu_op_sub * (sum_32 - alu_ia) = 0; + alu_u32_tag * alu_op_sub * (sum_32 + alu_cf * 2**32 - alu_ic - alu_ib) = 0; + alu_u32_tag * alu_op_sub * (sum_32 - alu_ia) = 0; // u64 subtraction - alu_u64 * alu_op_sub * (sum_64 + 2**64 * alu_cf - alu_ic - alu_ib) = 0; - alu_u64 * alu_op_sub * (sum_64 - alu_ia) = 0; + alu_u64_tag * alu_op_sub * (sum_64 + alu_cf * 2**64 - alu_ic - alu_ib) = 0; + alu_u64_tag * alu_op_sub * (sum_64 - alu_ia) = 0; // u128 subtraction - alu_u128 * alu_op_sub * (sum_128 + 2**128 * alu_cf - alu_ic - alu_ib) = 0; - alu_u128 * alu_op_sub * (sum_128 - alu_ia) = 0; \ No newline at end of file + alu_u128_tag * alu_op_sub * (sum_128 + alu_cf * 2**128 - alu_ic - alu_ib) = 0; + alu_u128_tag * alu_op_sub * (sum_128 - alu_ia) = 0; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index 2f9e2d12060..bd33cc1aaff 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -37,11 +37,11 @@ class AvmMiniFlavor { using VerifierCommitmentKey = pcs::VerifierCommitmentKey; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; - static constexpr size_t NUM_WITNESS_ENTITIES = 67; + static constexpr size_t NUM_WITNESS_ENTITIES = 60; 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 = 75; + static constexpr size_t NUM_ALL_ENTITIES = 68; using Relations = std::tuple, AvmMini_vm::alu_chip, AvmMini_vm::avm_mini>; @@ -96,27 +96,20 @@ class AvmMiniFlavor { aluChip_alu_op_sub, aluChip_alu_op_mul, aluChip_alu_op_div, - aluChip_alu_u8, - aluChip_alu_u16, - aluChip_alu_u32, - aluChip_alu_u64, - aluChip_alu_u128, - aluChip_alu_s1, - aluChip_alu_s2, - aluChip_alu_s3, - aluChip_alu_s4, - aluChip_alu_s5, - aluChip_alu_s6, - aluChip_alu_s7, - aluChip_alu_s8, - aluChip_alu_s9, - aluChip_alu_s10, - aluChip_alu_s11, - aluChip_alu_s12, - aluChip_alu_s13, - aluChip_alu_s14, - aluChip_alu_s15, - aluChip_alu_s16, + 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_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_cf, avmMini_pc, avmMini_internal_return_ptr, @@ -166,27 +159,20 @@ class AvmMiniFlavor { aluChip_alu_op_sub, aluChip_alu_op_mul, aluChip_alu_op_div, - aluChip_alu_u8, - aluChip_alu_u16, - aluChip_alu_u32, - aluChip_alu_u64, - aluChip_alu_u128, - aluChip_alu_s1, - aluChip_alu_s2, - aluChip_alu_s3, - aluChip_alu_s4, - aluChip_alu_s5, - aluChip_alu_s6, - aluChip_alu_s7, - aluChip_alu_s8, - aluChip_alu_s9, - aluChip_alu_s10, - aluChip_alu_s11, - aluChip_alu_s12, - aluChip_alu_s13, - aluChip_alu_s14, - aluChip_alu_s15, - aluChip_alu_s16, + 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_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_cf, avmMini_pc, avmMini_internal_return_ptr, @@ -242,27 +228,20 @@ class AvmMiniFlavor { aluChip_alu_op_sub, aluChip_alu_op_mul, aluChip_alu_op_div, - aluChip_alu_u8, - aluChip_alu_u16, - aluChip_alu_u32, - aluChip_alu_u64, - aluChip_alu_u128, - aluChip_alu_s1, - aluChip_alu_s2, - aluChip_alu_s3, - aluChip_alu_s4, - aluChip_alu_s5, - aluChip_alu_s6, - aluChip_alu_s7, - aluChip_alu_s8, - aluChip_alu_s9, - aluChip_alu_s10, - aluChip_alu_s11, - aluChip_alu_s12, - aluChip_alu_s13, - aluChip_alu_s14, - aluChip_alu_s15, - aluChip_alu_s16, + 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_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_cf, avmMini_pc, avmMini_internal_return_ptr, @@ -291,9 +270,9 @@ class AvmMiniFlavor { avmMini_mem_idx_c, avmMini_last, memTrace_m_rw_shift, - memTrace_m_addr_shift, memTrace_m_val_shift, memTrace_m_tag_shift, + memTrace_m_addr_shift, avmMini_internal_return_ptr_shift, avmMini_pc_shift) @@ -320,27 +299,20 @@ class AvmMiniFlavor { aluChip_alu_op_sub, aluChip_alu_op_mul, aluChip_alu_op_div, - aluChip_alu_u8, - aluChip_alu_u16, - aluChip_alu_u32, - aluChip_alu_u64, - aluChip_alu_u128, - aluChip_alu_s1, - aluChip_alu_s2, - aluChip_alu_s3, - aluChip_alu_s4, - aluChip_alu_s5, - aluChip_alu_s6, - aluChip_alu_s7, - aluChip_alu_s8, - aluChip_alu_s9, - aluChip_alu_s10, - aluChip_alu_s11, - aluChip_alu_s12, - aluChip_alu_s13, - aluChip_alu_s14, - aluChip_alu_s15, - aluChip_alu_s16, + 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_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_cf, avmMini_pc, avmMini_internal_return_ptr, @@ -369,9 +341,9 @@ class AvmMiniFlavor { avmMini_mem_idx_c, avmMini_last, memTrace_m_rw_shift, - memTrace_m_addr_shift, memTrace_m_val_shift, memTrace_m_tag_shift, + memTrace_m_addr_shift, avmMini_internal_return_ptr_shift, avmMini_pc_shift }; }; @@ -398,27 +370,20 @@ class AvmMiniFlavor { aluChip_alu_op_sub, aluChip_alu_op_mul, aluChip_alu_op_div, - aluChip_alu_u8, - aluChip_alu_u16, - aluChip_alu_u32, - aluChip_alu_u64, - aluChip_alu_u128, - aluChip_alu_s1, - aluChip_alu_s2, - aluChip_alu_s3, - aluChip_alu_s4, - aluChip_alu_s5, - aluChip_alu_s6, - aluChip_alu_s7, - aluChip_alu_s8, - aluChip_alu_s9, - aluChip_alu_s10, - aluChip_alu_s11, - aluChip_alu_s12, - aluChip_alu_s13, - aluChip_alu_s14, - aluChip_alu_s15, - aluChip_alu_s16, + 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_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_cf, avmMini_pc, avmMini_internal_return_ptr, @@ -449,15 +414,15 @@ class AvmMiniFlavor { }; RefVector get_to_be_shifted() { - return { memTrace_m_rw, memTrace_m_addr, memTrace_m_val, memTrace_m_tag, avmMini_internal_return_ptr, + return { memTrace_m_rw, memTrace_m_val, memTrace_m_tag, memTrace_m_addr, avmMini_internal_return_ptr, avmMini_pc }; }; RefVector get_shifted() { return { memTrace_m_rw_shift, - memTrace_m_addr_shift, memTrace_m_val_shift, memTrace_m_tag_shift, + memTrace_m_addr_shift, avmMini_internal_return_ptr_shift, avmMini_pc_shift }; }; @@ -472,7 +437,7 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { memTrace_m_rw, memTrace_m_addr, memTrace_m_val, memTrace_m_tag, avmMini_internal_return_ptr, + return { memTrace_m_rw, memTrace_m_val, memTrace_m_tag, memTrace_m_addr, avmMini_internal_return_ptr, avmMini_pc }; }; @@ -571,27 +536,20 @@ class AvmMiniFlavor { 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_u8 = "ALUCHIP_ALU_U8"; - Base::aluChip_alu_u16 = "ALUCHIP_ALU_U16"; - Base::aluChip_alu_u32 = "ALUCHIP_ALU_U32"; - Base::aluChip_alu_u64 = "ALUCHIP_ALU_U64"; - Base::aluChip_alu_u128 = "ALUCHIP_ALU_U128"; - Base::aluChip_alu_s1 = "ALUCHIP_ALU_S1"; - Base::aluChip_alu_s2 = "ALUCHIP_ALU_S2"; - Base::aluChip_alu_s3 = "ALUCHIP_ALU_S3"; - Base::aluChip_alu_s4 = "ALUCHIP_ALU_S4"; - Base::aluChip_alu_s5 = "ALUCHIP_ALU_S5"; - Base::aluChip_alu_s6 = "ALUCHIP_ALU_S6"; - Base::aluChip_alu_s7 = "ALUCHIP_ALU_S7"; - Base::aluChip_alu_s8 = "ALUCHIP_ALU_S8"; - Base::aluChip_alu_s9 = "ALUCHIP_ALU_S9"; - Base::aluChip_alu_s10 = "ALUCHIP_ALU_S10"; - Base::aluChip_alu_s11 = "ALUCHIP_ALU_S11"; - Base::aluChip_alu_s12 = "ALUCHIP_ALU_S12"; - Base::aluChip_alu_s13 = "ALUCHIP_ALU_S13"; - Base::aluChip_alu_s14 = "ALUCHIP_ALU_S14"; - Base::aluChip_alu_s15 = "ALUCHIP_ALU_S15"; - Base::aluChip_alu_s16 = "ALUCHIP_ALU_S16"; + 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_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_cf = "ALUCHIP_ALU_CF"; Base::avmMini_pc = "AVMMINI_PC"; Base::avmMini_internal_return_ptr = "AVMMINI_INTERNAL_RETURN_PTR"; @@ -657,27 +615,20 @@ class AvmMiniFlavor { Commitment aluChip_alu_op_sub; Commitment aluChip_alu_op_mul; Commitment aluChip_alu_op_div; - Commitment aluChip_alu_u8; - Commitment aluChip_alu_u16; - Commitment aluChip_alu_u32; - Commitment aluChip_alu_u64; - Commitment aluChip_alu_u128; - Commitment aluChip_alu_s1; - Commitment aluChip_alu_s2; - Commitment aluChip_alu_s3; - Commitment aluChip_alu_s4; - Commitment aluChip_alu_s5; - Commitment aluChip_alu_s6; - Commitment aluChip_alu_s7; - Commitment aluChip_alu_s8; - Commitment aluChip_alu_s9; - Commitment aluChip_alu_s10; - Commitment aluChip_alu_s11; - Commitment aluChip_alu_s12; - Commitment aluChip_alu_s13; - Commitment aluChip_alu_s14; - Commitment aluChip_alu_s15; - Commitment aluChip_alu_s16; + 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_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_cf; Commitment avmMini_pc; Commitment avmMini_internal_return_ptr; @@ -743,27 +694,20 @@ class AvmMiniFlavor { aluChip_alu_op_sub = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_op_mul = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_op_div = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_u8 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_u16 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_u32 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_u64 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_u128 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s1 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s2 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s3 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s4 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s5 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s6 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s7 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s8 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s9 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s10 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s11 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s12 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s13 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s14 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s15 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); - aluChip_alu_s16 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u8_tag = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u16_tag = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u32_tag = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u64_tag = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u128_tag = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u8_r0 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u16_r0 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u16_r1 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u16_r2 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u16_r3 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u16_r4 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u16_r5 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u16_r6 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u16_r7 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_cf = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); avmMini_pc = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); avmMini_internal_return_ptr = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); @@ -833,27 +777,20 @@ class AvmMiniFlavor { 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_u8, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u32, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u64, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u128, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s1, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s2, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s3, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s4, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s5, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s6, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s7, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s8, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s9, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s10, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s11, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s12, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s13, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s14, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s15, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_s16, 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_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_cf, Transcript::proof_data); serialize_to_buffer(avmMini_pc, Transcript::proof_data); serialize_to_buffer(avmMini_internal_return_ptr, Transcript::proof_data); 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 index ede4fff5449..13d97e6fba6 100644 --- 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 @@ -41,27 +41,20 @@ template struct AvmMiniFullRow { FF aluChip_alu_op_sub{}; FF aluChip_alu_op_mul{}; FF aluChip_alu_op_div{}; - FF aluChip_alu_u8{}; - FF aluChip_alu_u16{}; - FF aluChip_alu_u32{}; - FF aluChip_alu_u64{}; - FF aluChip_alu_u128{}; - FF aluChip_alu_s1{}; - FF aluChip_alu_s2{}; - FF aluChip_alu_s3{}; - FF aluChip_alu_s4{}; - FF aluChip_alu_s5{}; - FF aluChip_alu_s6{}; - FF aluChip_alu_s7{}; - FF aluChip_alu_s8{}; - FF aluChip_alu_s9{}; - FF aluChip_alu_s10{}; - FF aluChip_alu_s11{}; - FF aluChip_alu_s12{}; - FF aluChip_alu_s13{}; - FF aluChip_alu_s14{}; - FF aluChip_alu_s15{}; - FF aluChip_alu_s16{}; + 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_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_cf{}; FF avmMini_pc{}; FF avmMini_internal_return_ptr{}; @@ -90,9 +83,9 @@ template struct AvmMiniFullRow { FF avmMini_mem_idx_c{}; FF avmMini_last{}; FF memTrace_m_rw_shift{}; - FF memTrace_m_addr_shift{}; FF memTrace_m_val_shift{}; FF memTrace_m_tag_shift{}; + FF memTrace_m_addr_shift{}; FF avmMini_internal_return_ptr_shift{}; FF avmMini_pc_shift{}; }; @@ -107,8 +100,8 @@ class AvmMiniCircuitBuilder { using Polynomial = Flavor::Polynomial; using ProverPolynomials = Flavor::ProverPolynomials; - static constexpr size_t num_fixed_columns = 75; - static constexpr size_t num_polys = 69; + static constexpr size_t num_fixed_columns = 68; + static constexpr size_t num_polys = 62; std::vector rows; void set_trace(std::vector&& trace) { rows = std::move(trace); } @@ -145,27 +138,20 @@ class AvmMiniCircuitBuilder { 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_u8[i] = rows[i].aluChip_alu_u8; - polys.aluChip_alu_u16[i] = rows[i].aluChip_alu_u16; - polys.aluChip_alu_u32[i] = rows[i].aluChip_alu_u32; - polys.aluChip_alu_u64[i] = rows[i].aluChip_alu_u64; - polys.aluChip_alu_u128[i] = rows[i].aluChip_alu_u128; - polys.aluChip_alu_s1[i] = rows[i].aluChip_alu_s1; - polys.aluChip_alu_s2[i] = rows[i].aluChip_alu_s2; - polys.aluChip_alu_s3[i] = rows[i].aluChip_alu_s3; - polys.aluChip_alu_s4[i] = rows[i].aluChip_alu_s4; - polys.aluChip_alu_s5[i] = rows[i].aluChip_alu_s5; - polys.aluChip_alu_s6[i] = rows[i].aluChip_alu_s6; - polys.aluChip_alu_s7[i] = rows[i].aluChip_alu_s7; - polys.aluChip_alu_s8[i] = rows[i].aluChip_alu_s8; - polys.aluChip_alu_s9[i] = rows[i].aluChip_alu_s9; - polys.aluChip_alu_s10[i] = rows[i].aluChip_alu_s10; - polys.aluChip_alu_s11[i] = rows[i].aluChip_alu_s11; - polys.aluChip_alu_s12[i] = rows[i].aluChip_alu_s12; - polys.aluChip_alu_s13[i] = rows[i].aluChip_alu_s13; - polys.aluChip_alu_s14[i] = rows[i].aluChip_alu_s14; - polys.aluChip_alu_s15[i] = rows[i].aluChip_alu_s15; - polys.aluChip_alu_s16[i] = rows[i].aluChip_alu_s16; + 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_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_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; @@ -196,9 +182,9 @@ class AvmMiniCircuitBuilder { } polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); + polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index aee7603ac65..09e083f5aa8 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,33 +7,26 @@ namespace proof_system::AvmMini_vm { template struct Alu_chipRow { + FF aluChip_alu_u8_r0{}; + FF aluChip_alu_u16_r0{}; + FF aluChip_alu_u16_r2{}; + FF aluChip_alu_u16_r1{}; + FF aluChip_alu_u16_tag{}; + FF aluChip_alu_ia{}; FF aluChip_alu_ib{}; - FF aluChip_alu_s7{}; - FF aluChip_alu_s9{}; - FF aluChip_alu_ic{}; - FF aluChip_alu_op_add{}; - FF aluChip_alu_u128{}; - FF aluChip_alu_s6{}; - FF aluChip_alu_s15{}; - FF aluChip_alu_s1{}; - FF aluChip_alu_u32{}; - FF aluChip_alu_s2{}; - FF aluChip_alu_s8{}; - FF aluChip_alu_s16{}; - FF aluChip_alu_s11{}; - FF aluChip_alu_u8{}; - FF aluChip_alu_s4{}; - FF aluChip_alu_s12{}; - FF aluChip_alu_s10{}; - FF aluChip_alu_s13{}; + FF aluChip_alu_u16_r3{}; + FF aluChip_alu_u16_r5{}; FF aluChip_alu_op_sub{}; + FF aluChip_alu_u16_r7{}; + FF aluChip_alu_u16_r6{}; + FF aluChip_alu_u32_tag{}; + FF aluChip_alu_u64_tag{}; FF aluChip_alu_cf{}; - FF aluChip_alu_ia{}; - FF aluChip_alu_s5{}; - FF aluChip_alu_s14{}; - FF aluChip_alu_u64{}; - FF aluChip_alu_u16{}; - FF aluChip_alu_s3{}; + FF aluChip_alu_u128_tag{}; + FF aluChip_alu_u8_tag{}; + FF aluChip_alu_op_add{}; + FF aluChip_alu_ic{}; + FF aluChip_alu_u16_r4{}; }; inline std::string get_relation_label_alu_chip(int index) @@ -47,7 +40,7 @@ template class alu_chipImpl { using FF = FF_; static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, 3, 3, 3, 3, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, + 3, 3, 3, 3, 3, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, }; template @@ -61,7 +54,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(0); - auto tmp = (aluChip_alu_u8 * (-aluChip_alu_u8 + FF(1))); + auto tmp = (aluChip_alu_u8_tag * (-aluChip_alu_u8_tag + FF(1))); tmp *= scaling_factor; std::get<0>(evals) += tmp; } @@ -69,7 +62,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(1); - auto tmp = (aluChip_alu_u16 * (-aluChip_alu_u16 + FF(1))); + auto tmp = (aluChip_alu_u16_tag * (-aluChip_alu_u16_tag + FF(1))); tmp *= scaling_factor; std::get<1>(evals) += tmp; } @@ -77,7 +70,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(2); - auto tmp = (aluChip_alu_u32 * (-aluChip_alu_u32 + FF(1))); + auto tmp = (aluChip_alu_u32_tag * (-aluChip_alu_u32_tag + FF(1))); tmp *= scaling_factor; std::get<2>(evals) += tmp; } @@ -85,7 +78,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(3); - auto tmp = (aluChip_alu_u64 * (-aluChip_alu_u64 + FF(1))); + auto tmp = (aluChip_alu_u64_tag * (-aluChip_alu_u64_tag + FF(1))); tmp *= scaling_factor; std::get<3>(evals) += tmp; } @@ -93,7 +86,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(4); - auto tmp = (aluChip_alu_u128 * (-aluChip_alu_u128 + FF(1))); + auto tmp = (aluChip_alu_u128_tag * (-aluChip_alu_u128_tag + FF(1))); tmp *= scaling_factor; std::get<4>(evals) += tmp; } @@ -101,8 +94,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(5); - auto tmp = ((aluChip_alu_u8 * aluChip_alu_op_add) * - (((aluChip_alu_s1 + (FF(256) * aluChip_alu_cf)) - aluChip_alu_ia) - aluChip_alu_ib)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_add) * + (((aluChip_alu_u8_r0 + (aluChip_alu_cf * FF(256))) - aluChip_alu_ia) - aluChip_alu_ib)); tmp *= scaling_factor; std::get<5>(evals) += tmp; } @@ -110,7 +103,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(6); - auto tmp = ((aluChip_alu_u8 * aluChip_alu_op_add) * (aluChip_alu_s1 - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_add) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); tmp *= scaling_factor; std::get<6>(evals) += tmp; } @@ -118,10 +111,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(7); - auto tmp = - ((aluChip_alu_u16 * aluChip_alu_op_add) * - ((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_cf)) - aluChip_alu_ia) - - aluChip_alu_ib)); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_add) * + (((aluChip_alu_u16_r0 + (aluChip_alu_cf * FF(65536))) - aluChip_alu_ia) - aluChip_alu_ib)); tmp *= scaling_factor; std::get<7>(evals) += tmp; } @@ -129,8 +120,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(8); - auto tmp = ((aluChip_alu_u16 * aluChip_alu_op_add) * - ((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_add) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); tmp *= scaling_factor; std::get<8>(evals) += tmp; } @@ -138,12 +128,11 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(9); - auto tmp = ((aluChip_alu_u32 * aluChip_alu_op_add) * - ((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + - (FF(16777216) * aluChip_alu_s4)) + - (FF(4294967296UL) * aluChip_alu_cf)) - - aluChip_alu_ia) - - aluChip_alu_ib)); + auto tmp = + ((aluChip_alu_u32_tag * aluChip_alu_op_add) * + ((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + (aluChip_alu_cf * FF(4294967296UL))) - + aluChip_alu_ia) - + aluChip_alu_ib)); tmp *= scaling_factor; std::get<9>(evals) += tmp; } @@ -151,10 +140,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(10); - auto tmp = ((aluChip_alu_u32 * aluChip_alu_op_add) * - ((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + - (FF(16777216) * aluChip_alu_s4)) - - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_add) * + ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ic)); tmp *= scaling_factor; std::get<10>(evals) += tmp; } @@ -162,14 +149,11 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(11); - auto tmp = ((aluChip_alu_u64 * aluChip_alu_op_add) * - ((((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + - (FF(16777216) * aluChip_alu_s4)) + - (FF(4294967296UL) * aluChip_alu_s5)) + - (FF(1099511627776UL) * aluChip_alu_s6)) + - (FF(281474976710656UL) * aluChip_alu_s7)) + - (FF(72057594037927936UL) * aluChip_alu_s8)) + - (FF(uint256_t{ 0, 1, 0, 0 }) * aluChip_alu_cf)) - + auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_add) * + ((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + + (aluChip_alu_u16_r2 * FF(4294967296UL))) + + (aluChip_alu_u16_r3 * FF(281474976710656UL))) + + (aluChip_alu_cf * FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ia) - aluChip_alu_ib)); tmp *= scaling_factor; @@ -179,14 +163,11 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(12); - auto tmp = ((aluChip_alu_u64 * aluChip_alu_op_add) * - ((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + - (FF(16777216) * aluChip_alu_s4)) + - (FF(4294967296UL) * aluChip_alu_s5)) + - (FF(1099511627776UL) * aluChip_alu_s6)) + - (FF(281474976710656UL) * aluChip_alu_s7)) + - (FF(72057594037927936UL) * aluChip_alu_s8)) - - aluChip_alu_ic)); + auto tmp = + ((aluChip_alu_u64_tag * aluChip_alu_op_add) * + ((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + (aluChip_alu_u16_r2 * FF(4294967296UL))) + + (aluChip_alu_u16_r3 * FF(281474976710656UL))) - + aluChip_alu_ic)); tmp *= scaling_factor; std::get<12>(evals) += tmp; } @@ -194,22 +175,15 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(13); - auto tmp = ((aluChip_alu_u128 * aluChip_alu_op_add) * - ((((((((((((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + - (FF(16777216) * aluChip_alu_s4)) + - (FF(4294967296UL) * aluChip_alu_s5)) + - (FF(1099511627776UL) * aluChip_alu_s6)) + - (FF(281474976710656UL) * aluChip_alu_s7)) + - (FF(72057594037927936UL) * aluChip_alu_s8)) + - (FF(uint256_t{ 0, 1, 0, 0 }) * aluChip_alu_s9)) + - (FF(uint256_t{ 0, 256, 0, 0 }) * aluChip_alu_s10)) + - (FF(uint256_t{ 0, 65536, 0, 0 }) * aluChip_alu_s11)) + - (FF(uint256_t{ 0, 16777216, 0, 0 }) * aluChip_alu_s12)) + - (FF(uint256_t{ 0, 4294967296, 0, 0 }) * aluChip_alu_s13)) + - (FF(uint256_t{ 0, 1099511627776, 0, 0 }) * aluChip_alu_s14)) + - (FF(uint256_t{ 0, 281474976710656, 0, 0 }) * aluChip_alu_s15)) + - (FF(uint256_t{ 0, 72057594037927936, 0, 0 }) * aluChip_alu_s16)) + - (FF(uint256_t{ 0, 0, 1, 0 }) * aluChip_alu_cf)) - + auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_add) * + ((((((((((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 * FF(uint256_t{ 0, 1, 0, 0 }))) + + (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 65536, 0, 0 }))) + + (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + + (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) + + (aluChip_alu_cf * FF(uint256_t{ 0, 0, 1, 0 }))) - aluChip_alu_ia) - aluChip_alu_ib)); tmp *= scaling_factor; @@ -219,21 +193,14 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(14); - auto tmp = ((aluChip_alu_u128 * aluChip_alu_op_add) * - ((((((((((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + - (FF(16777216) * aluChip_alu_s4)) + - (FF(4294967296UL) * aluChip_alu_s5)) + - (FF(1099511627776UL) * aluChip_alu_s6)) + - (FF(281474976710656UL) * aluChip_alu_s7)) + - (FF(72057594037927936UL) * aluChip_alu_s8)) + - (FF(uint256_t{ 0, 1, 0, 0 }) * aluChip_alu_s9)) + - (FF(uint256_t{ 0, 256, 0, 0 }) * aluChip_alu_s10)) + - (FF(uint256_t{ 0, 65536, 0, 0 }) * aluChip_alu_s11)) + - (FF(uint256_t{ 0, 16777216, 0, 0 }) * aluChip_alu_s12)) + - (FF(uint256_t{ 0, 4294967296, 0, 0 }) * aluChip_alu_s13)) + - (FF(uint256_t{ 0, 1099511627776, 0, 0 }) * aluChip_alu_s14)) + - (FF(uint256_t{ 0, 281474976710656, 0, 0 }) * aluChip_alu_s15)) + - (FF(uint256_t{ 0, 72057594037927936, 0, 0 }) * aluChip_alu_s16)) - + auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_add) * + ((((((((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 * FF(uint256_t{ 0, 1, 0, 0 }))) + + (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 65536, 0, 0 }))) + + (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + + (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - aluChip_alu_ic)); tmp *= scaling_factor; std::get<14>(evals) += tmp; @@ -242,8 +209,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(15); - auto tmp = ((aluChip_alu_u8 * aluChip_alu_op_sub) * - (((aluChip_alu_s1 + (FF(256) * aluChip_alu_cf)) - aluChip_alu_ic) - aluChip_alu_ib)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_sub) * + (((aluChip_alu_u8_r0 + (aluChip_alu_cf * FF(256))) - aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; std::get<15>(evals) += tmp; } @@ -251,7 +218,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(16); - auto tmp = ((aluChip_alu_u8 * aluChip_alu_op_sub) * (aluChip_alu_s1 - aluChip_alu_ia)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_sub) * (aluChip_alu_u8_r0 - aluChip_alu_ia)); tmp *= scaling_factor; std::get<16>(evals) += tmp; } @@ -259,10 +226,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(17); - auto tmp = - ((aluChip_alu_u16 * aluChip_alu_op_sub) * - ((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_cf)) - aluChip_alu_ic) - - aluChip_alu_ib)); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_sub) * + (((aluChip_alu_u16_r0 + (aluChip_alu_cf * FF(65536))) - aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; std::get<17>(evals) += tmp; } @@ -270,8 +235,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(18); - auto tmp = ((aluChip_alu_u16 * aluChip_alu_op_sub) * - ((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) - aluChip_alu_ia)); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_sub) * (aluChip_alu_u16_r0 - aluChip_alu_ia)); tmp *= scaling_factor; std::get<18>(evals) += tmp; } @@ -279,12 +243,11 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(19); - auto tmp = ((aluChip_alu_u32 * aluChip_alu_op_sub) * - ((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + - (FF(16777216) * aluChip_alu_s4)) + - (FF(4294967296UL) * aluChip_alu_cf)) - - aluChip_alu_ic) - - aluChip_alu_ib)); + auto tmp = + ((aluChip_alu_u32_tag * aluChip_alu_op_sub) * + ((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + (aluChip_alu_cf * FF(4294967296UL))) - + aluChip_alu_ic) - + aluChip_alu_ib)); tmp *= scaling_factor; std::get<19>(evals) += tmp; } @@ -292,10 +255,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(20); - auto tmp = ((aluChip_alu_u32 * aluChip_alu_op_sub) * - ((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + - (FF(16777216) * aluChip_alu_s4)) - - aluChip_alu_ia)); + auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_sub) * + ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ia)); tmp *= scaling_factor; std::get<20>(evals) += tmp; } @@ -303,14 +264,11 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(21); - auto tmp = ((aluChip_alu_u64 * aluChip_alu_op_sub) * - ((((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + - (FF(16777216) * aluChip_alu_s4)) + - (FF(4294967296UL) * aluChip_alu_s5)) + - (FF(1099511627776UL) * aluChip_alu_s6)) + - (FF(281474976710656UL) * aluChip_alu_s7)) + - (FF(72057594037927936UL) * aluChip_alu_s8)) + - (FF(uint256_t{ 0, 1, 0, 0 }) * aluChip_alu_cf)) - + auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_sub) * + ((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + + (aluChip_alu_u16_r2 * FF(4294967296UL))) + + (aluChip_alu_u16_r3 * FF(281474976710656UL))) + + (aluChip_alu_cf * FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; @@ -320,14 +278,11 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(22); - auto tmp = ((aluChip_alu_u64 * aluChip_alu_op_sub) * - ((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + - (FF(16777216) * aluChip_alu_s4)) + - (FF(4294967296UL) * aluChip_alu_s5)) + - (FF(1099511627776UL) * aluChip_alu_s6)) + - (FF(281474976710656UL) * aluChip_alu_s7)) + - (FF(72057594037927936UL) * aluChip_alu_s8)) - - aluChip_alu_ia)); + auto tmp = + ((aluChip_alu_u64_tag * aluChip_alu_op_sub) * + ((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + (aluChip_alu_u16_r2 * FF(4294967296UL))) + + (aluChip_alu_u16_r3 * FF(281474976710656UL))) - + aluChip_alu_ia)); tmp *= scaling_factor; std::get<22>(evals) += tmp; } @@ -335,22 +290,15 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(23); - auto tmp = ((aluChip_alu_u128 * aluChip_alu_op_sub) * - ((((((((((((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + - (FF(16777216) * aluChip_alu_s4)) + - (FF(4294967296UL) * aluChip_alu_s5)) + - (FF(1099511627776UL) * aluChip_alu_s6)) + - (FF(281474976710656UL) * aluChip_alu_s7)) + - (FF(72057594037927936UL) * aluChip_alu_s8)) + - (FF(uint256_t{ 0, 1, 0, 0 }) * aluChip_alu_s9)) + - (FF(uint256_t{ 0, 256, 0, 0 }) * aluChip_alu_s10)) + - (FF(uint256_t{ 0, 65536, 0, 0 }) * aluChip_alu_s11)) + - (FF(uint256_t{ 0, 16777216, 0, 0 }) * aluChip_alu_s12)) + - (FF(uint256_t{ 0, 4294967296, 0, 0 }) * aluChip_alu_s13)) + - (FF(uint256_t{ 0, 1099511627776, 0, 0 }) * aluChip_alu_s14)) + - (FF(uint256_t{ 0, 281474976710656, 0, 0 }) * aluChip_alu_s15)) + - (FF(uint256_t{ 0, 72057594037927936, 0, 0 }) * aluChip_alu_s16)) + - (FF(uint256_t{ 0, 0, 1, 0 }) * aluChip_alu_cf)) - + auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_sub) * + ((((((((((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 * FF(uint256_t{ 0, 1, 0, 0 }))) + + (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 65536, 0, 0 }))) + + (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + + (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) + + (aluChip_alu_cf * FF(uint256_t{ 0, 0, 1, 0 }))) - aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; @@ -360,21 +308,14 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(24); - auto tmp = ((aluChip_alu_u128 * aluChip_alu_op_sub) * - ((((((((((((((((aluChip_alu_s1 + (FF(256) * aluChip_alu_s2)) + (FF(65536) * aluChip_alu_s3)) + - (FF(16777216) * aluChip_alu_s4)) + - (FF(4294967296UL) * aluChip_alu_s5)) + - (FF(1099511627776UL) * aluChip_alu_s6)) + - (FF(281474976710656UL) * aluChip_alu_s7)) + - (FF(72057594037927936UL) * aluChip_alu_s8)) + - (FF(uint256_t{ 0, 1, 0, 0 }) * aluChip_alu_s9)) + - (FF(uint256_t{ 0, 256, 0, 0 }) * aluChip_alu_s10)) + - (FF(uint256_t{ 0, 65536, 0, 0 }) * aluChip_alu_s11)) + - (FF(uint256_t{ 0, 16777216, 0, 0 }) * aluChip_alu_s12)) + - (FF(uint256_t{ 0, 4294967296, 0, 0 }) * aluChip_alu_s13)) + - (FF(uint256_t{ 0, 1099511627776, 0, 0 }) * aluChip_alu_s14)) + - (FF(uint256_t{ 0, 281474976710656, 0, 0 }) * aluChip_alu_s15)) + - (FF(uint256_t{ 0, 72057594037927936, 0, 0 }) * aluChip_alu_s16)) - + auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_sub) * + ((((((((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 * FF(uint256_t{ 0, 1, 0, 0 }))) + + (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 65536, 0, 0 }))) + + (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + + (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - aluChip_alu_ia)); tmp *= scaling_factor; std::get<24>(evals) += tmp; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index ed1f7efc9da..4231902f227 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,68 +7,68 @@ namespace proof_system::AvmMini_vm { template struct Avm_miniRow { - FF avmMini_ic{}; - FF avmMini_rwa{}; - FF avmMini_sel_internal_return{}; + FF avmMini_sel_internal_call{}; + FF avmMini_sel_op_div{}; + FF avmMini_internal_return_ptr{}; + FF avmMini_mem_idx_a{}; FF avmMini_op_err{}; + FF avmMini_mem_op_b{}; + FF avmMini_ic{}; + FF avmMini_inv{}; FF avmMini_internal_return_ptr_shift{}; - FF avmMini_internal_return_ptr{}; - FF avmMini_sel_internal_call{}; FF avmMini_pc_shift{}; - FF avmMini_mem_op_b{}; + FF avmMini_mem_op_c{}; + FF avmMini_rwa{}; FF avmMini_rwb{}; + FF avmMini_pc{}; + FF avmMini_first{}; + FF avmMini_tag_err{}; FF avmMini_sel_op_sub{}; - FF avmMini_inv{}; + FF avmMini_rwc{}; FF avmMini_ia{}; - FF avmMini_sel_op_mul{}; - FF avmMini_sel_op_div{}; - FF avmMini_mem_idx_a{}; - FF avmMini_sel_halt{}; - FF avmMini_sel_op_add{}; - FF avmMini_tag_err{}; FF avmMini_mem_op_a{}; + FF avmMini_sel_op_mul{}; FF avmMini_ib{}; - FF avmMini_pc{}; - FF avmMini_rwc{}; - FF avmMini_mem_op_c{}; - FF avmMini_first{}; + FF avmMini_sel_internal_return{}; + FF avmMini_sel_op_add{}; + FF avmMini_sel_halt{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { - case 20: - return "SUBOP_MULTIPLICATION_FF"; - - case 22: - return "SUBOP_DIVISION_ZERO_ERR1"; + case 25: + return "RETURN_POINTER_INCREMENT"; case 23: return "SUBOP_DIVISION_ZERO_ERR2"; + case 30: + return "RETURN_POINTER_DECREMENT"; + case 24: return "SUBOP_ERROR_RELEVANT_OP"; - case 21: - return "SUBOP_DIVISION_FF"; - - case 25: - return "RETURN_POINTER_INCREMENT"; - case 35: return "PC_INCREMENT"; + case 21: + return "SUBOP_DIVISION_FF"; + case 18: return "SUBOP_ADDITION_FF"; - case 19: - return "SUBOP_SUBTRACTION_FF"; + case 20: + return "SUBOP_MULTIPLICATION_FF"; - case 30: - return "RETURN_POINTER_DECREMENT"; + case 22: + return "SUBOP_DIVISION_ZERO_ERR1"; case 36: return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + + case 19: + return "SUBOP_SUBTRACTION_FF"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index 64e24477ada..def06b5b32e 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -23,27 +23,20 @@ [[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_u8 = View(new_term.aluChip_alu_u8); \ - [[maybe_unused]] auto aluChip_alu_u16 = View(new_term.aluChip_alu_u16); \ - [[maybe_unused]] auto aluChip_alu_u32 = View(new_term.aluChip_alu_u32); \ - [[maybe_unused]] auto aluChip_alu_u64 = View(new_term.aluChip_alu_u64); \ - [[maybe_unused]] auto aluChip_alu_u128 = View(new_term.aluChip_alu_u128); \ - [[maybe_unused]] auto aluChip_alu_s1 = View(new_term.aluChip_alu_s1); \ - [[maybe_unused]] auto aluChip_alu_s2 = View(new_term.aluChip_alu_s2); \ - [[maybe_unused]] auto aluChip_alu_s3 = View(new_term.aluChip_alu_s3); \ - [[maybe_unused]] auto aluChip_alu_s4 = View(new_term.aluChip_alu_s4); \ - [[maybe_unused]] auto aluChip_alu_s5 = View(new_term.aluChip_alu_s5); \ - [[maybe_unused]] auto aluChip_alu_s6 = View(new_term.aluChip_alu_s6); \ - [[maybe_unused]] auto aluChip_alu_s7 = View(new_term.aluChip_alu_s7); \ - [[maybe_unused]] auto aluChip_alu_s8 = View(new_term.aluChip_alu_s8); \ - [[maybe_unused]] auto aluChip_alu_s9 = View(new_term.aluChip_alu_s9); \ - [[maybe_unused]] auto aluChip_alu_s10 = View(new_term.aluChip_alu_s10); \ - [[maybe_unused]] auto aluChip_alu_s11 = View(new_term.aluChip_alu_s11); \ - [[maybe_unused]] auto aluChip_alu_s12 = View(new_term.aluChip_alu_s12); \ - [[maybe_unused]] auto aluChip_alu_s13 = View(new_term.aluChip_alu_s13); \ - [[maybe_unused]] auto aluChip_alu_s14 = View(new_term.aluChip_alu_s14); \ - [[maybe_unused]] auto aluChip_alu_s15 = View(new_term.aluChip_alu_s15); \ - [[maybe_unused]] auto aluChip_alu_s16 = View(new_term.aluChip_alu_s16); \ + [[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_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_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); \ @@ -72,8 +65,8 @@ [[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_addr_shift = View(new_term.memTrace_m_addr_shift); \ [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ + [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_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/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 342c917c455..8dbd739aea5 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,24 +7,27 @@ namespace proof_system::AvmMini_vm { template struct Mem_traceRow { - FF memTrace_m_rw{}; FF memTrace_m_rw_shift{}; - FF memTrace_m_one_min_inv{}; - FF memTrace_m_addr_shift{}; + FF memTrace_m_val{}; + FF memTrace_m_rw{}; FF memTrace_m_val_shift{}; - FF memTrace_m_in_tag{}; - FF memTrace_m_lastAccess{}; FF memTrace_m_tag_shift{}; - FF memTrace_m_last{}; FF memTrace_m_tag{}; - FF memTrace_m_val{}; - FF memTrace_m_addr{}; + FF memTrace_m_lastAccess{}; + FF memTrace_m_in_tag{}; + FF memTrace_m_last{}; + FF memTrace_m_one_min_inv{}; + FF memTrace_m_addr_shift{}; FF memTrace_m_tag_err{}; + FF memTrace_m_addr{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { + case 9: + return "MEM_IN_TAG_CONSISTENCY_2"; + case 5: return "MEM_READ_WRITE_VAL_CONSISTENCY"; @@ -34,9 +37,6 @@ inline std::string get_relation_label_mem_trace(int index) case 7: return "MEM_ZERO_INIT"; - case 9: - return "MEM_IN_TAG_CONSISTENCY_2"; - case 4: return "MEM_LAST_ACCESS_DELIMITER"; diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp index 6a44bbc45f9..84534ef47e9 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp @@ -86,38 +86,34 @@ bool AvmMiniVerifier::verify_proof(const plonk::proof& proof) 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_u8 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_u8); - commitments.aluChip_alu_u16 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u16); - commitments.aluChip_alu_u32 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u32); - commitments.aluChip_alu_u64 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u64); - commitments.aluChip_alu_u128 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_u128); - commitments.aluChip_alu_s1 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s1); - commitments.aluChip_alu_s2 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s2); - commitments.aluChip_alu_s3 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s3); - commitments.aluChip_alu_s4 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s4); - commitments.aluChip_alu_s5 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s5); - commitments.aluChip_alu_s6 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s6); - commitments.aluChip_alu_s7 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s7); - commitments.aluChip_alu_s8 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s8); - commitments.aluChip_alu_s9 = transcript->template receive_from_prover(commitment_labels.aluChip_alu_s9); - commitments.aluChip_alu_s10 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_s10); - commitments.aluChip_alu_s11 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_s11); - commitments.aluChip_alu_s12 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_s12); - commitments.aluChip_alu_s13 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_s13); - commitments.aluChip_alu_s14 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_s14); - commitments.aluChip_alu_s15 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_s15); - commitments.aluChip_alu_s16 = - transcript->template receive_from_prover(commitment_labels.aluChip_alu_s16); + 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_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_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 = From 2300f966364bf5f9311d69c1afa6a3fa62a2ae24 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Wed, 3 Jan 2024 10:56:13 +0000 Subject: [PATCH 05/28] 3738 - pil relations for multiplication types u8, u16, u32, u64 --- barretenberg/cpp/pil/avm/alu_chip.pil | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil index cccb32a406e..78aceede9f5 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -25,6 +25,7 @@ namespace aluChip(256); // 8-bit slice registers pol commit alu_u8_r0; + pol commit alu_u8_r1; // 16-bit slice registers pol commit alu_u16_r0; @@ -72,7 +73,7 @@ namespace aluChip(256); // We support u8, u16, u32, u64, u128 types and decompose low into // smaller bit slices, e.g., 16. For instance, low = s_0 + s_1 * 2^16 + s_2 * 2^32 + ... // The slices have to be range constrained and there is a trade-off between the - // number of regiesters and complexity of the range constraints. + // number of registers and complexity of the range constraints. // TODO: Determine the best slice size allocation. Note that we might choose different // slice sizes for the different types. At this stage, it is still unknown how this // allocation affects the performance. @@ -138,4 +139,25 @@ namespace aluChip(256); // u128 subtraction alu_u128_tag * alu_op_sub * (sum_128 + alu_cf * 2**128 - alu_ic - alu_ib) = 0; - alu_u128_tag * alu_op_sub * (sum_128 - alu_ia) = 0; \ No newline at end of file + alu_u128_tag * alu_op_sub * (sum_128 - alu_ia) = 0; + + // ========= MULTIPLICATION Operation Constraints =============================== + + // We need 2k bits to express the product (a*b) over the integer, i.e., for type uk + // we express the product as sum_k (u8 is an exception as we need 8-bit registers) + + // u8 multiplication + alu_u8_tag * alu_op_mul * (alu_u8_r0 + alu_u8_r1 * 2**8 - alu_ia * alu_ib) = 0; + alu_u8_tag * alu_op_mul * (alu_u8_r0 - alu_ic) = 0; + + // u16 multiplication + alu_u16_tag * alu_op_mul * (sum_32 - alu_ia * alu_ib) = 0; + alu_u16_tag * alu_op_mul * (sum_16 - alu_ic) = 0; + + // u32 multiplication + alu_u32_tag * alu_op_mul * (sum_64 - alu_ia * alu_ib) = 0; + alu_u32_tag * alu_op_mul * (sum_32 - alu_ic) = 0; + + // u64 multiplication + alu_u64_tag * alu_op_mul * (sum_128 - alu_ia * alu_ib) = 0; + alu_u64_tag * alu_op_mul * (sum_64 - alu_ic) = 0; \ No newline at end of file From 87b873bef356cb52f499937adbb6918b7c5133a4 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Wed, 3 Jan 2024 13:11:57 +0000 Subject: [PATCH 06/28] 3738 - pil relations for u128 multiplication --- barretenberg/cpp/pil/avm/alu_chip.pil | 39 +++- .../flavor/generated/AvmMini_flavor.hpp | 83 +++++--- .../generated/AvmMini_circuit_builder.hpp | 48 +++-- .../relations/generated/AvmMini/alu_chip.hpp | 177 ++++++++++++++++-- .../relations/generated/AvmMini/avm_mini.hpp | 68 +++---- .../generated/AvmMini/declare_views.hpp | 18 +- .../relations/generated/AvmMini/mem_trace.hpp | 32 ++-- .../vm/generated/AvmMini_verifier.cpp | 4 + 8 files changed, 361 insertions(+), 108 deletions(-) diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil index 78aceede9f5..6023cec1530 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -37,6 +37,9 @@ namespace aluChip(256); pol commit alu_u16_r6; pol commit alu_u16_r7; + // 64-bit slice register + pol commit alu_u64_r0; + // Carry flag pol commit alu_cf; @@ -93,7 +96,6 @@ namespace aluChip(256); pol sum_96 = sum_64 + alu_u16_r4 * 2**64 + alu_u16_r5 * 2**80; pol sum_128 = sum_96 + alu_u16_r6 * 2**96 + alu_u16_r7 * 2**112; - // ========= ADDITION Operation Constraints =============================== // u8 addition @@ -160,4 +162,37 @@ namespace aluChip(256); // u64 multiplication alu_u64_tag * alu_op_mul * (sum_128 - alu_ia * alu_ib) = 0; - alu_u64_tag * alu_op_mul * (sum_64 - alu_ic) = 0; \ No newline at end of file + alu_u64_tag * alu_op_mul * (sum_64 - alu_ic) = 0; + + // ========= u128 MULTIPLICATION Operation Constraints =============================== + // + // We express a, b in 64-bit slices: a = a_l + a_h * 2^64 + // b = b_l + b_h * 2^64 + // We show that c satisfies: a_l * b_l + (a_h * b_l + a_l * b_h) * 2^64 = R * 2^128 + c + // for a R < 2^65. Equivalently: + // a * b_l + a_l * b_h * 2^64 = (CF * 2^65 + R') * 2^128 + c + // for a bit carry flag CF and R' range constrained to 64 bits. + // We use two lines in the execution trace. First line represents a + // as decomposed over 16-bit registers. Second line represents b. + // Selector flag is only toggled in the first line and we access b through + // shifted polynomials. + // R' is stored in alu_u64_r0 + + // 64-bit higher limb + pol sum_high_64 = alu_u16_r4 + alu_u16_r5 * 2**16 + alu_u16_r6 * 2**32 + alu_u16_r7 * 2**48; + + // 64-bit lower limb for next row + pol sum_shifted_64 = alu_u16_r0' + alu_u16_r1' * 2**16 + alu_u16_r2' * 2**32 + alu_u16_r3' * 2**48; + + // 64-bit higher limb for next row + pol sum_high_shifted_64 = alu_u16_r4' + alu_u16_r5' * 2**16 + alu_u16_r6' * 2**32 + alu_u16_r7' * 2**48; + + // Arithmetic relations + alu_u128_tag * alu_op_mul * (sum_64 + sum_high_64 * 2**64 - alu_ia) = 0; + alu_u128_tag * alu_op_mul * (sum_shifted_64 + sum_high_shifted_64 * 2**64 - alu_ib) = 0; + alu_u128_tag * alu_op_mul * ( + alu_ia * sum_shifted_64 + + sum_64 * sum_high_shifted_64 * 2**64 + - (alu_cf * 2**65 + alu_u64_r0) * 2**128 + - alu_ic + ) = 0; diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index ae0ab67ac8f..c6b63861d6c 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -37,13 +37,13 @@ class AvmMiniFlavor { using VerifierCommitmentKey = pcs::VerifierCommitmentKey; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; - static constexpr size_t NUM_WITNESS_ENTITIES = 61; + static constexpr size_t NUM_WITNESS_ENTITIES = 63; 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 = 69; + static constexpr size_t NUM_ALL_ENTITIES = 79; - using Relations = std::tuple, AvmMini_vm::mem_trace, AvmMini_vm::alu_chip>; + using Relations = std::tuple, AvmMini_vm::avm_mini, AvmMini_vm::alu_chip>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -102,6 +102,7 @@ class AvmMiniFlavor { 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, @@ -110,6 +111,7 @@ class AvmMiniFlavor { 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, @@ -166,6 +168,7 @@ class AvmMiniFlavor { 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, @@ -174,6 +177,7 @@ class AvmMiniFlavor { 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, @@ -236,6 +240,7 @@ class AvmMiniFlavor { 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, @@ -244,6 +249,7 @@ class AvmMiniFlavor { 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, @@ -272,12 +278,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift, memTrace_m_tag_shift, - memTrace_m_val_shift, + memTrace_m_rw_shift, memTrace_m_addr_shift, - memTrace_m_rw_shift) + memTrace_m_val_shift, + avmMini_pc_shift, + avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r1_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r4_shift, + aluChip_alu_u16_r3_shift) RefVector get_wires() { @@ -308,6 +322,7 @@ class AvmMiniFlavor { 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, @@ -316,6 +331,7 @@ class AvmMiniFlavor { 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, @@ -344,12 +360,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift, memTrace_m_tag_shift, - memTrace_m_val_shift, + memTrace_m_rw_shift, memTrace_m_addr_shift, - memTrace_m_rw_shift }; + memTrace_m_val_shift, + avmMini_pc_shift, + avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r1_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r4_shift, + aluChip_alu_u16_r3_shift }; }; RefVector get_unshifted() { @@ -380,6 +404,7 @@ class AvmMiniFlavor { 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, @@ -388,6 +413,7 @@ class AvmMiniFlavor { 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, @@ -419,18 +445,19 @@ class AvmMiniFlavor { }; RefVector get_to_be_shifted() { - return { - avmMini_internal_return_ptr, avmMini_pc, memTrace_m_tag, memTrace_m_val, memTrace_m_addr, memTrace_m_rw - }; + return { memTrace_m_tag, memTrace_m_rw, memTrace_m_addr, + memTrace_m_val, avmMini_pc, avmMini_internal_return_ptr, + aluChip_alu_u16_r2, aluChip_alu_u16_r0, aluChip_alu_u16_r5, + aluChip_alu_u16_r6, aluChip_alu_u16_r1, aluChip_alu_u16_r7, + aluChip_alu_u16_r4, aluChip_alu_u16_r3 }; }; RefVector get_shifted() { - return { avmMini_internal_return_ptr_shift, - avmMini_pc_shift, - memTrace_m_tag_shift, - memTrace_m_val_shift, - memTrace_m_addr_shift, - memTrace_m_rw_shift }; + return { memTrace_m_tag_shift, memTrace_m_rw_shift, memTrace_m_addr_shift, + memTrace_m_val_shift, avmMini_pc_shift, avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r2_shift, aluChip_alu_u16_r0_shift, aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r6_shift, aluChip_alu_u16_r1_shift, aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r4_shift, aluChip_alu_u16_r3_shift }; }; }; @@ -443,9 +470,11 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { - avmMini_internal_return_ptr, avmMini_pc, memTrace_m_tag, memTrace_m_val, memTrace_m_addr, memTrace_m_rw - }; + return { memTrace_m_tag, memTrace_m_rw, memTrace_m_addr, + memTrace_m_val, avmMini_pc, avmMini_internal_return_ptr, + aluChip_alu_u16_r2, aluChip_alu_u16_r0, aluChip_alu_u16_r5, + aluChip_alu_u16_r6, aluChip_alu_u16_r1, aluChip_alu_u16_r7, + aluChip_alu_u16_r4, aluChip_alu_u16_r3 }; }; // The plookup wires that store plookup read data. @@ -549,6 +578,7 @@ class AvmMiniFlavor { 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"; @@ -557,6 +587,7 @@ class AvmMiniFlavor { 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"; @@ -629,6 +660,7 @@ class AvmMiniFlavor { 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; @@ -637,6 +669,7 @@ class AvmMiniFlavor { 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; @@ -709,6 +742,7 @@ class AvmMiniFlavor { aluChip_alu_u64_tag = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_u128_tag = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_u8_r0 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u8_r1 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_u16_r0 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_u16_r1 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_u16_r2 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); @@ -717,6 +751,7 @@ class AvmMiniFlavor { aluChip_alu_u16_r5 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_u16_r6 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_u16_r7 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_u64_r0 = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_cf = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); avmMini_pc = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); avmMini_internal_return_ptr = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); @@ -793,6 +828,7 @@ class AvmMiniFlavor { 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); @@ -801,6 +837,7 @@ class AvmMiniFlavor { 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); 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 index 09b685f2fb7..8fbf67a79e2 100644 --- 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 @@ -47,6 +47,7 @@ template struct AvmMiniFullRow { 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{}; @@ -55,6 +56,7 @@ template struct AvmMiniFullRow { 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{}; @@ -83,12 +85,20 @@ template struct AvmMiniFullRow { FF avmMini_mem_idx_b{}; FF avmMini_mem_idx_c{}; FF avmMini_last{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_pc_shift{}; FF memTrace_m_tag_shift{}; - FF memTrace_m_val_shift{}; - FF memTrace_m_addr_shift{}; FF memTrace_m_rw_shift{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_val_shift{}; + FF avmMini_pc_shift{}; + FF avmMini_internal_return_ptr_shift{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u16_r1_shift{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r4_shift{}; + FF aluChip_alu_u16_r3_shift{}; }; class AvmMiniCircuitBuilder { @@ -101,8 +111,8 @@ class AvmMiniCircuitBuilder { using Polynomial = Flavor::Polynomial; using ProverPolynomials = Flavor::ProverPolynomials; - static constexpr size_t num_fixed_columns = 69; - static constexpr size_t num_polys = 63; + static constexpr size_t num_fixed_columns = 79; + static constexpr size_t num_polys = 65; std::vector rows; void set_trace(std::vector&& trace) { rows = std::move(trace); } @@ -145,6 +155,7 @@ class AvmMiniCircuitBuilder { 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; @@ -153,6 +164,7 @@ class AvmMiniCircuitBuilder { 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; @@ -183,12 +195,20 @@ class AvmMiniCircuitBuilder { polys.avmMini_last[i] = rows[i].avmMini_last; } - polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); - polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.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_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); + polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); + polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); + polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); + polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); + polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.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_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); + polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); + polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); + polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); return polys; } @@ -226,14 +246,14 @@ class AvmMiniCircuitBuilder { return true; }; - if (!evaluate_relation.template operator()>("avm_mini", - AvmMini_vm::get_relation_label_avm_mini)) { - return false; - } if (!evaluate_relation.template operator()>( "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { return false; } + if (!evaluate_relation.template operator()>("avm_mini", + AvmMini_vm::get_relation_label_avm_mini)) { + return false; + } if (!evaluate_relation.template operator()>("alu_chip", AvmMini_vm::get_relation_label_alu_chip)) { return false; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index 4af36b2da20..bc638a31742 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,26 +7,37 @@ namespace proof_system::AvmMini_vm { template struct Alu_chipRow { + FF aluChip_alu_u16_r6{}; + FF aluChip_alu_u16_r4{}; + FF aluChip_alu_cf{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_u16_r5_shift{}; FF aluChip_alu_u16_r7{}; - FF aluChip_alu_op_sub{}; - FF aluChip_alu_u16_r2{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u64_r0{}; FF aluChip_alu_ib{}; - FF aluChip_alu_ic{}; - FF aluChip_alu_u16_r6{}; - FF aluChip_alu_u16_tag{}; - FF aluChip_alu_u32_tag{}; FF aluChip_alu_u16_r1{}; - FF aluChip_alu_u16_r5{}; - FF aluChip_alu_ia{}; + FF aluChip_alu_u64_tag{}; FF aluChip_alu_u128_tag{}; - FF aluChip_alu_op_add{}; - FF aluChip_alu_cf{}; - FF aluChip_alu_u16_r4{}; + FF aluChip_alu_u16_r0{}; FF aluChip_alu_u16_r3{}; + FF aluChip_alu_u16_r5{}; + FF aluChip_alu_u8_r1{}; FF aluChip_alu_u8_tag{}; - FF aluChip_alu_u16_r0{}; + FF aluChip_alu_u16_tag{}; + FF aluChip_alu_u32_tag{}; + FF aluChip_alu_op_add{}; FF aluChip_alu_u8_r0{}; - FF aluChip_alu_u64_tag{}; + FF aluChip_alu_op_mul{}; + FF aluChip_alu_ia{}; + FF aluChip_alu_ic{}; + FF aluChip_alu_op_sub{}; + FF aluChip_alu_u16_r1_shift{}; + FF aluChip_alu_u16_r2{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r4_shift{}; + FF aluChip_alu_u16_r3_shift{}; }; inline std::string get_relation_label_alu_chip(int index) @@ -39,8 +50,8 @@ template class alu_chipImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, 3, 3, 3, 3, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 3, 3, 3, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 6, 6, 8, }; template @@ -320,6 +331,142 @@ template class alu_chipImpl { tmp *= scaling_factor; std::get<24>(evals) += tmp; } + // Contribution 25 + { + AvmMini_DECLARE_VIEWS(25); + + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * + ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) - (aluChip_alu_ia * aluChip_alu_ib))); + tmp *= scaling_factor; + std::get<25>(evals) += tmp; + } + // Contribution 26 + { + AvmMini_DECLARE_VIEWS(26); + + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<26>(evals) += tmp; + } + // Contribution 27 + { + AvmMini_DECLARE_VIEWS(27); + + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * + ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - (aluChip_alu_ia * aluChip_alu_ib))); + tmp *= scaling_factor; + std::get<27>(evals) += tmp; + } + // Contribution 28 + { + AvmMini_DECLARE_VIEWS(28); + + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<28>(evals) += tmp; + } + // Contribution 29 + { + AvmMini_DECLARE_VIEWS(29); + + auto tmp = + ((aluChip_alu_u32_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_ia * aluChip_alu_ib))); + tmp *= scaling_factor; + std::get<29>(evals) += tmp; + } + // Contribution 30 + { + AvmMini_DECLARE_VIEWS(30); + + auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_mul) * + ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<30>(evals) += tmp; + } + // Contribution 31 + { + AvmMini_DECLARE_VIEWS(31); + + auto tmp = ((aluChip_alu_u64_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 * FF(uint256_t{ 0, 1, 0, 0 }))) + + (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 65536, 0, 0 }))) + + (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + + (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - + (aluChip_alu_ia * aluChip_alu_ib))); + tmp *= scaling_factor; + std::get<31>(evals) += tmp; + } + // Contribution 32 + { + AvmMini_DECLARE_VIEWS(32); + + auto tmp = + ((aluChip_alu_u64_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_ic)); + tmp *= scaling_factor; + std::get<32>(evals) += tmp; + } + // Contribution 33 + { + AvmMini_DECLARE_VIEWS(33); + + 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<33>(evals) += tmp; + } + // Contribution 34 + { + AvmMini_DECLARE_VIEWS(34); + + 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<34>(evals) += tmp; + } + // Contribution 35 + { + AvmMini_DECLARE_VIEWS(35); + + 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, 2, 0, 0 })) + aluChip_alu_u64_r0) * + FF(uint256_t{ 0, 0, 1, 0 }))) - + aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<35>(evals) += tmp; + } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index 2468c27a2ec..934f2d5e71a 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,33 +7,33 @@ namespace proof_system::AvmMini_vm { template struct Avm_miniRow { - FF avmMini_sel_op_div{}; - FF avmMini_mem_idx_a{}; - FF avmMini_internal_return_ptr{}; - FF avmMini_mem_op_a{}; - FF avmMini_rwb{}; - FF avmMini_ib{}; - FF avmMini_sel_internal_return{}; - FF avmMini_tag_err{}; FF avmMini_sel_op_sub{}; - FF avmMini_mem_idx_b{}; - FF avmMini_op_err{}; - FF avmMini_sel_op_mul{}; - FF avmMini_mem_op_b{}; + FF avmMini_sel_op_div{}; FF avmMini_rwc{}; - FF avmMini_ia{}; - FF avmMini_inv{}; - FF avmMini_internal_return_ptr_shift{}; + FF avmMini_pc_shift{}; + FF avmMini_ic{}; + FF avmMini_internal_return_ptr{}; FF avmMini_first{}; + FF avmMini_pc{}; + FF avmMini_ib{}; FF avmMini_sel_internal_call{}; - FF avmMini_sel_halt{}; FF avmMini_sel_jump{}; - FF avmMini_ic{}; + FF avmMini_rwb{}; + FF avmMini_mem_op_a{}; + FF avmMini_ia{}; + FF avmMini_mem_idx_a{}; FF avmMini_mem_op_c{}; - FF avmMini_pc_shift{}; - FF avmMini_pc{}; + FF avmMini_inv{}; FF avmMini_sel_op_add{}; + FF avmMini_sel_internal_return{}; + FF avmMini_op_err{}; + FF avmMini_sel_op_mul{}; + FF avmMini_tag_err{}; FF avmMini_rwa{}; + FF avmMini_sel_halt{}; + FF avmMini_internal_return_ptr_shift{}; + FF avmMini_mem_idx_b{}; + FF avmMini_mem_op_b{}; }; inline std::string get_relation_label_avm_mini(int index) @@ -42,35 +42,35 @@ inline std::string get_relation_label_avm_mini(int index) case 38: return "PC_INCREMENT"; - case 21: - return "SUBOP_MULTIPLICATION_FF"; - - case 22: - return "SUBOP_DIVISION_FF"; - - case 24: - return "SUBOP_DIVISION_ZERO_ERR2"; - - case 39: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - - case 27: - return "RETURN_POINTER_INCREMENT"; - case 19: return "SUBOP_ADDITION_FF"; case 33: return "RETURN_POINTER_DECREMENT"; + case 39: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + case 20: return "SUBOP_SUBTRACTION_FF"; + case 27: + return "RETURN_POINTER_INCREMENT"; + case 23: return "SUBOP_DIVISION_ZERO_ERR1"; + case 22: + return "SUBOP_DIVISION_FF"; + + case 21: + return "SUBOP_MULTIPLICATION_FF"; + case 25: return "SUBOP_ERROR_RELEVANT_OP"; + + case 24: + return "SUBOP_DIVISION_ZERO_ERR2"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index aa407463a26..dec970cc38b 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -29,6 +29,7 @@ [[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); \ @@ -37,6 +38,7 @@ [[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); \ @@ -65,9 +67,17 @@ [[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 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); \ [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ - [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ + [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ - [[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 avmMini_pc_shift = View(new_term.avmMini_pc_shift); \ + [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_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_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index b3297502b23..0e321047807 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,24 +7,33 @@ namespace proof_system::AvmMini_vm { template struct Mem_traceRow { - FF memTrace_m_addr{}; + FF memTrace_m_one_min_inv{}; FF memTrace_m_lastAccess{}; + FF memTrace_m_tag_err{}; + FF memTrace_m_tag_shift{}; + FF memTrace_m_rw_shift{}; + FF memTrace_m_val{}; FF memTrace_m_tag{}; - FF memTrace_m_one_min_inv{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_addr{}; FF memTrace_m_rw{}; - FF memTrace_m_val{}; - FF memTrace_m_tag_shift{}; FF memTrace_m_val_shift{}; FF memTrace_m_last{}; FF memTrace_m_in_tag{}; - FF memTrace_m_addr_shift{}; - FF memTrace_m_rw_shift{}; - FF memTrace_m_tag_err{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { + case 9: + return "MEM_IN_TAG_CONSISTENCY_2"; + + case 8: + return "MEM_IN_TAG_CONSISTENCY_1"; + + case 6: + return "MEM_READ_WRITE_TAG_CONSISTENCY"; + case 4: return "MEM_LAST_ACCESS_DELIMITER"; @@ -33,15 +42,6 @@ inline std::string get_relation_label_mem_trace(int index) case 5: return "MEM_READ_WRITE_VAL_CONSISTENCY"; - - case 8: - return "MEM_IN_TAG_CONSISTENCY_1"; - - case 9: - return "MEM_IN_TAG_CONSISTENCY_2"; - - case 6: - return "MEM_READ_WRITE_TAG_CONSISTENCY"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp index c993f1b86b2..043994db574 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp @@ -98,6 +98,8 @@ bool AvmMiniVerifier::verify_proof(const plonk::proof& proof) 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 = @@ -114,6 +116,8 @@ bool AvmMiniVerifier::verify_proof(const plonk::proof& proof) 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 = From 55fab702628366e8bd1a8e7871699702c32fd565 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Fri, 5 Jan 2024 14:27:58 +0000 Subject: [PATCH 07/28] 3738 - First version of Alu trace files --- .../vm/avm_trace/AvmMini_alu_trace.cpp | 14 +++++++++++++ .../vm/avm_trace/AvmMini_alu_trace.hpp | 21 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp create mode 100644 barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp new file mode 100644 index 00000000000..99efd93388e --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp @@ -0,0 +1,14 @@ +#include "AvmMini_alu_trace.hpp" + +namespace avm_trace { + +/** + * @brief Constructor of Alu trace builder of AVM. Only serves to set the capacity of the + * underlying trace. + */ +AvmMiniAluTraceBuilder::AvmMiniAluTraceBuilder() +{ + alu_trace.reserve(AVM_TRACE_SIZE); +} + +} // namespace avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp new file mode 100644 index 00000000000..a1468bccce5 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "AvmMini_common.hpp" + +namespace avm_trace { + +class AvmMiniAluTraceBuilder { + + public: + struct AluTraceEntry {}; + + AvmMiniAluTraceBuilder(); + + void reset(); + + std::vector finalize(); + + private: + std::vector alu_trace; +}; +} // namespace avm_trace \ No newline at end of file From 650eec353bbde3aa869e1e7023d4a26775764db5 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Mon, 8 Jan 2024 15:17:29 +0000 Subject: [PATCH 08/28] 3738 - witness generation for addition --- .../vm/avm_trace/AvmMini_alu_trace.cpp | 140 ++++++++++++++++++ .../vm/avm_trace/AvmMini_alu_trace.hpp | 24 ++- .../vm/avm_trace/AvmMini_mem_trace.hpp | 14 +- .../vm/avm_trace/AvmMini_trace.cpp | 36 +++++ .../vm/avm_trace/AvmMini_trace.hpp | 2 + 5 files changed, 206 insertions(+), 10 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp index 99efd93388e..a05eeceb2dd 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp @@ -11,4 +11,144 @@ AvmMiniAluTraceBuilder::AvmMiniAluTraceBuilder() alu_trace.reserve(AVM_TRACE_SIZE); } +/** + * @brief Resetting the internal state so that a new Alu trace can be rebuilt using the same object. + * + */ +void AvmMiniAluTraceBuilder::reset() +{ + alu_trace.clear(); +} + +/** + * @brief Prepare the Alu trace to be incorporated into the main trace. + * + * @return The Alu trace (which is moved). + */ +std::vector AvmMiniAluTraceBuilder::finalize() +{ + return std::move(alu_trace); +} + +/** + * @brief Build Alu trace and compute the result of an addition of type defined by in_tag. + * + * @param a Left operand of the additon + * @param b Right operand of the addition + * @param in_tag Instruction tag defining the number of bits on which the addition applies. + * It is assumed that the caller never uses the type u0. + * + * @return FF The result of the addition casted in a finite field element + */ +FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag) +{ + FF c{}; + bool carry = false; + uint8_t alu_u8_r0{}; + std::array alu_u16_reg{}; + + switch (in_tag) { + case AvmMemoryTag::ff: + return a + b; + case AvmMemoryTag::u8: { + uint8_t a_u8 = static_cast(uint256_t(a).data[0]); + uint8_t b_u8 = static_cast(uint256_t(b).data[0]); + uint8_t c_u8 = a_u8 + b_u8; + c = FF{ uint256_t{ c_u8 } }; + + // a_u8 + b_u8 >= 2^8 <==> c_u8 < a_u8 + if (c_u8 < a_u8) { + carry = true; + } + + alu_u8_r0 = c_u8; + break; + } + case AvmMemoryTag::u16: { + uint16_t a_u16 = static_cast(uint256_t(a).data[0]); + uint16_t b_u16 = static_cast(uint256_t(b).data[0]); + uint16_t c_u16 = a_u16 + b_u16; + c = FF{ uint256_t{ c_u16 } }; + + // a_u16 + b_u16 >= 2^16 <==> c_u16 < a_u16 + if (c_u16 < a_u16) { + carry = true; + } + + alu_u16_reg.at(0) = c_u16; + break; + } + case AvmMemoryTag::u32: { + uint32_t a_u32 = static_cast(uint256_t(a).data[0]); + uint32_t b_u32 = static_cast(uint256_t(b).data[0]); + uint32_t c_u32 = a_u32 + b_u32; + c = FF{ uint256_t{ c_u32 } }; + + // a_u32 + b_u32 >= 2^32 <==> c_u32 < a_u32 + if (c_u32 < a_u32) { + carry = true; + } + + alu_u16_reg.at(0) = static_cast(c_u32); + alu_u16_reg.at(1) = static_cast(c_u32 >> 16); + break; + } + case AvmMemoryTag::u64: { + uint64_t a_u64 = static_cast(uint256_t(a).data[0]); + uint64_t b_u64 = static_cast(uint256_t(b).data[0]); + uint64_t c_u64 = a_u64 + b_u64; + c = FF{ uint256_t{ c_u64 } }; + + // a_u64 + b_u64 >= 2^64 <==> c_u64 < a_u64 + if (c_u64 < a_u64) { + carry = true; + } + + uint64_t c_trunc_64 = c_u64; + for (size_t i = 0; i < 4; i++) { + alu_u16_reg.at(i) = static_cast(c_trunc_64); + c_trunc_64 >>= 16; + } + break; + } + case AvmMemoryTag::u128: { + auto a_u128 = uint128_t(a); + auto b_u128 = uint128_t(b); + uint128_t c_u128 = a_u128 + b_u128; + c = FF{ uint256_t::from_uint128(c_u128) }; + + // a_u128 + b_u128 >= 2^128 <==> c_u128 < a_u128 + if (c_u128 < a_u128) { + carry = true; + } + + uint128_t c_trunc_128 = c_u128; + for (size_t i = 0; i < 8; i++) { + alu_u16_reg.at(i) = static_cast(c_trunc_128); + c_trunc_128 >>= 16; + } + break; + } + case AvmMemoryTag::u0: // Unsupported as instruction tag + return FF{ 0 }; + } + + alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ + .alu_op_add = true, + .alu_u8_tag = in_tag == AvmMemoryTag::u8, + .alu_u16_tag = in_tag == AvmMemoryTag::u16, + .alu_u32_tag = in_tag == AvmMemoryTag::u32, + .alu_u64_tag = in_tag == AvmMemoryTag::u64, + .alu_u128_tag = in_tag == AvmMemoryTag::u128, + .alu_ia = a, + .alu_ib = b, + .alu_ic = c, + .alu_cf = carry, + .alu_u8_r0 = alu_u8_r0, + .alu_u16_reg = alu_u16_reg, + }); + + return c; +} + } // namespace avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp index a1468bccce5..b83ca341f6b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp @@ -7,14 +7,32 @@ namespace avm_trace { class AvmMiniAluTraceBuilder { public: - struct AluTraceEntry {}; + struct AluTraceEntry { + bool alu_op_add = false; - AvmMiniAluTraceBuilder(); + bool alu_u8_tag = false; + bool alu_u16_tag = false; + bool alu_u32_tag = false; + bool alu_u64_tag = false; + bool alu_u128_tag = false; - void reset(); + FF alu_ia{}; + FF alu_ib{}; + FF alu_ic{}; + + bool alu_cf = false; + + uint8_t alu_u8_r0{}; + std::array alu_u16_reg{}; + }; + + AvmMiniAluTraceBuilder(); + void reset(); std::vector finalize(); + FF add(FF const& a, FF const& b, AvmMemoryTag in_tag); + private: std::vector alu_trace; }; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp index 6a06dcee1fb..6b9f1afefb8 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp @@ -16,12 +16,12 @@ class AvmMiniMemTraceBuilder { static const uint32_t SUB_CLK_STORE_C = 5; struct MemoryTraceEntry { - uint32_t m_clk; - uint32_t m_sub_clk; - uint32_t m_addr; + uint32_t m_clk{}; + uint32_t m_sub_clk{}; + uint32_t m_addr{}; FF m_val{}; - AvmMemoryTag m_tag; - AvmMemoryTag m_in_tag; + AvmMemoryTag m_tag{}; + AvmMemoryTag m_in_tag{}; bool m_rw = false; bool m_tag_err = false; FF m_one_min_inv{}; @@ -29,8 +29,8 @@ class AvmMiniMemTraceBuilder { // Structure to return value and tag matching boolean after a memory read. struct MemRead { - bool tag_match; - FF val; + bool tag_match = false; + FF val{}; }; AvmMiniMemTraceBuilder(); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp index c38a615560f..92aba948c7b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp @@ -29,6 +29,7 @@ void AvmMiniTraceBuilder::reset() { main_trace.clear(); mem_trace_builder.reset(); + alu_trace_builder.reset(); } /** TODO: Implement for non finite field types @@ -544,14 +545,17 @@ void AvmMiniTraceBuilder::internal_return() std::vector AvmMiniTraceBuilder::finalize() { auto mem_trace = mem_trace_builder.finalize(); + auto alu_trace = alu_trace_builder.finalize(); size_t mem_trace_size = mem_trace.size(); size_t main_trace_size = main_trace.size(); + size_t alu_trace_size = alu_trace.size(); // TODO: We will have to handle this through error handling and not an assertion // Smaller than N because we have to add an extra initial row to support shifted // elements assert(mem_trace_size < AVM_TRACE_SIZE); assert(main_trace_size < AVM_TRACE_SIZE); + assert(alu_trace_size < AVM_TRACE_SIZE); // Fill the rest with zeros. size_t zero_rows_num = AVM_TRACE_SIZE - main_trace_size - 1; @@ -561,6 +565,7 @@ std::vector AvmMiniTraceBuilder::finalize() main_trace.at(main_trace_size - 1).avmMini_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); @@ -584,6 +589,37 @@ std::vector AvmMiniTraceBuilder::finalize() } } + // Alu trace inclusion + for (size_t i = 0; i < alu_trace_size; i++) { + auto const& src = alu_trace.at(i); + auto& dest = main_trace.at(i); + + dest.aluChip_alu_op_add = FF(static_cast(src.alu_op_add)); + + 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.aluChip_alu_ia = src.alu_ia; + dest.aluChip_alu_ib = src.alu_ib; + dest.aluChip_alu_ic = src.alu_ic; + + dest.aluChip_alu_cf = FF(static_cast(src.alu_cf)); + + dest.aluChip_alu_u8_r0 = FF(src.alu_u8_r0); + + 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)); + } + // 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) }; main_trace.insert(main_trace.begin(), first_row); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp index ef8e51b65bf..f361d8319ef 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp @@ -2,6 +2,7 @@ #include +#include "AvmMini_alu_trace.hpp" #include "AvmMini_common.hpp" #include "AvmMini_mem_trace.hpp" #include "barretenberg/common/throw_or_abort.hpp" @@ -63,6 +64,7 @@ class AvmMiniTraceBuilder { private: std::vector main_trace; AvmMiniMemTraceBuilder mem_trace_builder; + AvmMiniAluTraceBuilder alu_trace_builder; uint32_t pc = 0; uint32_t internal_return_ptr = CALLSTACK_OFFSET; From 115a40a7b881f2303b73796966722740abef34e0 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Tue, 9 Jan 2024 10:13:43 +0000 Subject: [PATCH 09/28] 3738 - create common header file for tests --- .../vm/tests/AvmMini_arithmetic.test.cpp | 12 +----------- .../barretenberg/vm/tests/AvmMini_common.test.hpp | 13 +++++++++++++ .../vm/tests/AvmMini_control_flow.test.cpp | 12 +----------- .../barretenberg/vm/tests/AvmMini_memory.test.cpp | 12 +----------- .../cpp/src/barretenberg/vm/tests/helpers.test.cpp | 7 +------ 5 files changed, 17 insertions(+), 39 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_common.test.hpp diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index c8f61b2dc59..325c44428a4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -1,14 +1,4 @@ -#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 +#include "AvmMini_common.test.hpp" namespace tests_avm { using namespace avm_trace; diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_common.test.hpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_common.test.hpp new file mode 100644 index 00000000000..4d7154552af --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_common.test.hpp @@ -0,0 +1,13 @@ +#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_control_flow.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_control_flow.test.cpp index 36673853057..8d93f05864c 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_control_flow.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_control_flow.test.cpp @@ -1,14 +1,4 @@ -#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 +#include "AvmMini_common.test.hpp" namespace tests_avm { using namespace avm_trace; diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp index e3798357e15..177df0fb5dd 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp @@ -1,14 +1,4 @@ -#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 +#include "AvmMini_common.test.hpp" namespace tests_avm { using namespace 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 2a761b69a47..04aa992c766 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp @@ -1,9 +1,4 @@ -#include "helpers.test.hpp" -#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 +#include "AvmMini_common.test.hpp" namespace tests_avm { using namespace avm_trace; From b9d878f8971d9d8e5fda6d08f1bca7253e464389 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Tue, 9 Jan 2024 10:26:12 +0000 Subject: [PATCH 10/28] 3738 - rename arithmetic test suite specific for FF --- .../vm/tests/AvmMini_arithmetic.test.cpp | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index 325c44428a4..e18f1f666b2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -16,11 +16,12 @@ class AvmMiniArithmeticTests : public ::testing::Test { }; }; -class AvmMiniArithmeticNegativeTests : public AvmMiniArithmeticTests {}; +class AvmMiniArithmeticTestsFF : public AvmMiniArithmeticTests {}; +class AvmMiniArithmeticNegativeTestsFF : public AvmMiniArithmeticTests {}; /****************************************************************************** * - * POSITIVE TESTS - Finite Field Type + * POSITIVE TESTS * ****************************************************************************** * The positive tests aim at testing that a genuinely generated execution trace @@ -43,7 +44,7 @@ class AvmMiniArithmeticNegativeTests : public AvmMiniArithmeticTests {}; ******************************************************************************/ // Test on basic addition over finite field type. -TEST_F(AvmMiniArithmeticTests, additionFF) +TEST_F(AvmMiniArithmeticTestsFF, addition) { // trace_builder trace_builder.call_data_copy(0, 3, 0, std::vector{ 37, 4, 11 }); @@ -67,7 +68,7 @@ TEST_F(AvmMiniArithmeticTests, additionFF) } // Test on basic subtraction over finite field type. -TEST_F(AvmMiniArithmeticTests, subtractionFF) +TEST_F(AvmMiniArithmeticTestsFF, subtraction) { trace_builder.call_data_copy(0, 3, 0, std::vector{ 8, 4, 17 }); @@ -90,7 +91,7 @@ TEST_F(AvmMiniArithmeticTests, subtractionFF) } // Test on basic multiplication over finite field type. -TEST_F(AvmMiniArithmeticTests, multiplicationFF) +TEST_F(AvmMiniArithmeticTestsFF, multiplication) { trace_builder.call_data_copy(0, 3, 0, std::vector{ 5, 0, 20 }); @@ -113,7 +114,7 @@ TEST_F(AvmMiniArithmeticTests, multiplicationFF) } // Test on multiplication by zero over finite field type. -TEST_F(AvmMiniArithmeticTests, multiplicationByZeroFF) +TEST_F(AvmMiniArithmeticTestsFF, multiplicationByZero) { trace_builder.call_data_copy(0, 1, 0, std::vector{ 127 }); @@ -136,7 +137,7 @@ TEST_F(AvmMiniArithmeticTests, multiplicationByZeroFF) } // Test on basic division over finite field type. -TEST_F(AvmMiniArithmeticTests, divisionFF) +TEST_F(AvmMiniArithmeticTestsFF, division) { trace_builder.call_data_copy(0, 2, 0, std::vector{ 15, 315 }); @@ -159,7 +160,7 @@ TEST_F(AvmMiniArithmeticTests, divisionFF) } // Test on division with zero numerator over finite field type. -TEST_F(AvmMiniArithmeticTests, divisionNumeratorZeroFF) +TEST_F(AvmMiniArithmeticTestsFF, divisionNumeratorZero) { trace_builder.call_data_copy(0, 1, 0, std::vector{ 15 }); @@ -183,7 +184,7 @@ TEST_F(AvmMiniArithmeticTests, divisionNumeratorZeroFF) // Test on division by zero over finite field type. // We check that the operator error flag is raised. -TEST_F(AvmMiniArithmeticTests, divisionByZeroErrorFF) +TEST_F(AvmMiniArithmeticTestsFF, divisionByZeroError) { trace_builder.call_data_copy(0, 1, 0, std::vector{ 15 }); @@ -208,7 +209,7 @@ TEST_F(AvmMiniArithmeticTests, divisionByZeroErrorFF) // Test on division of zero by zero over finite field type. // We check that the operator error flag is raised. -TEST_F(AvmMiniArithmeticTests, divisionZeroByZeroErrorFF) +TEST_F(AvmMiniArithmeticTestsFF, divisionZeroByZeroError) { // Memory layout: [0,0,0,0,0,0,....] trace_builder.div(0, 1, 2, AvmMemoryTag::ff); // [0,0,0,0,0,0....] @@ -233,7 +234,7 @@ TEST_F(AvmMiniArithmeticTests, divisionZeroByZeroErrorFF) // 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(AvmMiniArithmeticTests, arithmeticFFWithError) +TEST_F(AvmMiniArithmeticTestsFF, mixedOperationsWithError) { trace_builder.call_data_copy(0, 3, 2, std::vector{ 45, 23, 12 }); @@ -276,7 +277,7 @@ TEST_F(AvmMiniArithmeticTests, arithmeticFFWithError) ******************************************************************************/ // Test on basic incorrect addition over finite field type. -TEST_F(AvmMiniArithmeticNegativeTests, additionFF) +TEST_F(AvmMiniArithmeticNegativeTestsFF, addition) { trace_builder.call_data_copy(0, 3, 0, std::vector{ 37, 4, 11 }); @@ -291,7 +292,7 @@ TEST_F(AvmMiniArithmeticNegativeTests, additionFF) } // Test on basic incorrect subtraction over finite field type. -TEST_F(AvmMiniArithmeticNegativeTests, subtractionFF) +TEST_F(AvmMiniArithmeticNegativeTestsFF, subtraction) { trace_builder.call_data_copy(0, 3, 0, std::vector{ 8, 4, 17 }); @@ -306,7 +307,7 @@ TEST_F(AvmMiniArithmeticNegativeTests, subtractionFF) } // Test on basic incorrect multiplication over finite field type. -TEST_F(AvmMiniArithmeticNegativeTests, multiplicationFF) +TEST_F(AvmMiniArithmeticNegativeTestsFF, multiplication) { trace_builder.call_data_copy(0, 3, 0, std::vector{ 5, 0, 20 }); @@ -321,7 +322,7 @@ TEST_F(AvmMiniArithmeticNegativeTests, multiplicationFF) } // Test on basic incorrect division over finite field type. -TEST_F(AvmMiniArithmeticNegativeTests, divisionFF) +TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionFF) { trace_builder.call_data_copy(0, 2, 0, std::vector{ 15, 315 }); @@ -337,7 +338,7 @@ TEST_F(AvmMiniArithmeticNegativeTests, divisionFF) // Test where division is not by zero but an operation error is wrongly raised // in the trace. -TEST_F(AvmMiniArithmeticNegativeTests, divisionNoZeroButErrorFF) +TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionNoZeroButError) { trace_builder.call_data_copy(0, 2, 0, std::vector{ 15, 315 }); @@ -362,7 +363,7 @@ TEST_F(AvmMiniArithmeticNegativeTests, divisionNoZeroButErrorFF) } // Test with division by zero occurs and no error is raised (remove error flag) -TEST_F(AvmMiniArithmeticNegativeTests, divisionByZeroNoErrorFF) +TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionByZeroNoError) { trace_builder.call_data_copy(0, 1, 0, std::vector{ 15 }); @@ -381,7 +382,7 @@ TEST_F(AvmMiniArithmeticNegativeTests, divisionByZeroNoErrorFF) } // Test with division of zero by zero occurs and no error is raised (remove error flag) -TEST_F(AvmMiniArithmeticNegativeTests, divisionZeroByZeroNoErrorFF) +TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionZeroByZeroNoError) { // Memory layout: [0,0,0,0,0,0,....] trace_builder.div(0, 1, 2, AvmMemoryTag::ff); // [0,0,0,0,0,0....] @@ -398,7 +399,7 @@ TEST_F(AvmMiniArithmeticNegativeTests, divisionZeroByZeroNoErrorFF) // Test that error flag cannot be raised for a non-relevant operation such as // the addition, subtraction, multiplication. -TEST_F(AvmMiniArithmeticNegativeTests, operationWithErrorFlagFF) +TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) { trace_builder.call_data_copy(0, 3, 0, std::vector{ 37, 4, 11 }); From ee534364779d26258a81383835ef5dc096defe24 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Tue, 9 Jan 2024 12:47:47 +0000 Subject: [PATCH 11/28] 3738 - move FF addition to alu chip and create a unit test for u8 addition --- barretenberg/cpp/pil/avm/alu_chip.pil | 6 + barretenberg/cpp/pil/avm/avm_mini.pil | 4 - .../flavor/generated/AvmMini_flavor.hpp | 112 +++++--- .../generated/AvmMini_circuit_builder.hpp | 54 ++-- .../relations/generated/AvmMini/alu_chip.hpp | 252 ++++++++++-------- .../relations/generated/AvmMini/avm_mini.hpp | 135 +++++----- .../generated/AvmMini/declare_views.hpp | 21 +- .../relations/generated/AvmMini/mem_trace.hpp | 34 +-- .../vm/avm_trace/AvmMini_alu_trace.cpp | 7 +- .../vm/avm_trace/AvmMini_alu_trace.hpp | 5 +- .../vm/avm_trace/AvmMini_trace.cpp | 19 +- .../vm/generated/AvmMini_verifier.cpp | 2 + .../vm/tests/AvmMini_arithmetic.test.cpp | 35 ++- .../barretenberg/vm/tests/helpers.test.cpp | 16 +- .../barretenberg/vm/tests/helpers.test.hpp | 5 +- 15 files changed, 408 insertions(+), 299 deletions(-) diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil index 6023cec1530..200f7b9fea4 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -17,6 +17,7 @@ namespace aluChip(256); pol commit alu_op_div; // Flattened boolean instruction tags + pol commit alu_ff_tag; pol commit alu_u8_tag; pol commit alu_u16_tag; pol commit alu_u32_tag; @@ -50,6 +51,7 @@ namespace aluChip(256); // arithmetic expressions are not overflowing finite field size // Boolean flattened instructions tags + alu_ff_tag * (1 - alu_ff_tag) = 0; alu_u8_tag * (1 - alu_u8_tag) = 0; alu_u16_tag * (1 - alu_u16_tag) = 0; alu_u32_tag * (1 - alu_u32_tag) = 0; @@ -98,6 +100,10 @@ namespace aluChip(256); // ========= ADDITION Operation Constraints =============================== + // ff addition + #[SUBOP_ADDITION_FF] + alu_ff_tag * alu_op_add * (alu_ia + alu_ib - alu_ic) = 0; + // u8 addition alu_u8_tag * alu_op_add * (alu_u8_r0 + alu_cf * 2**8 - alu_ia - alu_ib) = 0; alu_u8_tag * alu_op_add * (alu_u8_r0 - alu_ic) = 0; diff --git a/barretenberg/cpp/pil/avm/avm_mini.pil b/barretenberg/cpp/pil/avm/avm_mini.pil index deea21a3980..b9c82480e5b 100644 --- a/barretenberg/cpp/pil/avm/avm_mini.pil +++ b/barretenberg/cpp/pil/avm/avm_mini.pil @@ -103,10 +103,6 @@ namespace avmMini(256); tag_err * ib = 0; tag_err * ic = 0; - // Relation for addition over the finite field - #[SUBOP_ADDITION_FF] - sel_op_add * (ia + ib - ic) = 0; - // Relation for subtraction over the finite field #[SUBOP_SUBTRACTION_FF] sel_op_sub * (ia - ib - ic) = 0; diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index c6b63861d6c..8bee47084e1 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -37,13 +37,13 @@ class AvmMiniFlavor { using VerifierCommitmentKey = pcs::VerifierCommitmentKey; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; - static constexpr size_t NUM_WITNESS_ENTITIES = 63; + static constexpr size_t NUM_WITNESS_ENTITIES = 64; 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 = 79; + static constexpr size_t NUM_ALL_ENTITIES = 80; - using Relations = std::tuple, AvmMini_vm::avm_mini, AvmMini_vm::alu_chip>; + using Relations = std::tuple, AvmMini_vm::alu_chip, AvmMini_vm::mem_trace>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -96,6 +96,7 @@ class AvmMiniFlavor { aluChip_alu_op_sub, aluChip_alu_op_mul, aluChip_alu_op_div, + aluChip_alu_ff_tag, aluChip_alu_u8_tag, aluChip_alu_u16_tag, aluChip_alu_u32_tag, @@ -162,6 +163,7 @@ class AvmMiniFlavor { aluChip_alu_op_sub, aluChip_alu_op_mul, aluChip_alu_op_div, + aluChip_alu_ff_tag, aluChip_alu_u8_tag, aluChip_alu_u16_tag, aluChip_alu_u32_tag, @@ -234,6 +236,7 @@ class AvmMiniFlavor { aluChip_alu_op_sub, aluChip_alu_op_mul, aluChip_alu_op_div, + aluChip_alu_ff_tag, aluChip_alu_u8_tag, aluChip_alu_u16_tag, aluChip_alu_u32_tag, @@ -278,20 +281,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - memTrace_m_tag_shift, - memTrace_m_rw_shift, - memTrace_m_addr_shift, - memTrace_m_val_shift, - avmMini_pc_shift, avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r2_shift, + avmMini_pc_shift, aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r4_shift, + aluChip_alu_u16_r3_shift, aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r1_shift, aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r3_shift) + aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r1_shift, + memTrace_m_rw_shift, + memTrace_m_addr_shift, + memTrace_m_val_shift, + memTrace_m_tag_shift) RefVector get_wires() { @@ -316,6 +319,7 @@ class AvmMiniFlavor { aluChip_alu_op_sub, aluChip_alu_op_mul, aluChip_alu_op_div, + aluChip_alu_ff_tag, aluChip_alu_u8_tag, aluChip_alu_u16_tag, aluChip_alu_u32_tag, @@ -360,20 +364,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - memTrace_m_tag_shift, - memTrace_m_rw_shift, - memTrace_m_addr_shift, - memTrace_m_val_shift, - avmMini_pc_shift, avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r2_shift, + avmMini_pc_shift, aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r4_shift, + aluChip_alu_u16_r3_shift, aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r1_shift, aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r3_shift }; + aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r1_shift, + memTrace_m_rw_shift, + memTrace_m_addr_shift, + memTrace_m_val_shift, + memTrace_m_tag_shift }; }; RefVector get_unshifted() { @@ -398,6 +402,7 @@ class AvmMiniFlavor { aluChip_alu_op_sub, aluChip_alu_op_mul, aluChip_alu_op_div, + aluChip_alu_ff_tag, aluChip_alu_u8_tag, aluChip_alu_u16_tag, aluChip_alu_u32_tag, @@ -445,19 +450,37 @@ class AvmMiniFlavor { }; RefVector get_to_be_shifted() { - return { memTrace_m_tag, memTrace_m_rw, memTrace_m_addr, - memTrace_m_val, avmMini_pc, avmMini_internal_return_ptr, - aluChip_alu_u16_r2, aluChip_alu_u16_r0, aluChip_alu_u16_r5, - aluChip_alu_u16_r6, aluChip_alu_u16_r1, aluChip_alu_u16_r7, - aluChip_alu_u16_r4, aluChip_alu_u16_r3 }; + return { avmMini_internal_return_ptr, + avmMini_pc, + aluChip_alu_u16_r0, + aluChip_alu_u16_r4, + aluChip_alu_u16_r3, + aluChip_alu_u16_r6, + aluChip_alu_u16_r7, + aluChip_alu_u16_r5, + aluChip_alu_u16_r2, + aluChip_alu_u16_r1, + memTrace_m_rw, + memTrace_m_addr, + memTrace_m_val, + memTrace_m_tag }; }; RefVector get_shifted() { - return { memTrace_m_tag_shift, memTrace_m_rw_shift, memTrace_m_addr_shift, - memTrace_m_val_shift, avmMini_pc_shift, avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r2_shift, aluChip_alu_u16_r0_shift, aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r6_shift, aluChip_alu_u16_r1_shift, aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r4_shift, aluChip_alu_u16_r3_shift }; + return { avmMini_internal_return_ptr_shift, + avmMini_pc_shift, + aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r4_shift, + aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r1_shift, + memTrace_m_rw_shift, + memTrace_m_addr_shift, + memTrace_m_val_shift, + memTrace_m_tag_shift }; }; }; @@ -470,11 +493,20 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { memTrace_m_tag, memTrace_m_rw, memTrace_m_addr, - memTrace_m_val, avmMini_pc, avmMini_internal_return_ptr, - aluChip_alu_u16_r2, aluChip_alu_u16_r0, aluChip_alu_u16_r5, - aluChip_alu_u16_r6, aluChip_alu_u16_r1, aluChip_alu_u16_r7, - aluChip_alu_u16_r4, aluChip_alu_u16_r3 }; + return { avmMini_internal_return_ptr, + avmMini_pc, + aluChip_alu_u16_r0, + aluChip_alu_u16_r4, + aluChip_alu_u16_r3, + aluChip_alu_u16_r6, + aluChip_alu_u16_r7, + aluChip_alu_u16_r5, + aluChip_alu_u16_r2, + aluChip_alu_u16_r1, + memTrace_m_rw, + memTrace_m_addr, + memTrace_m_val, + memTrace_m_tag }; }; // The plookup wires that store plookup read data. @@ -572,6 +604,7 @@ class AvmMiniFlavor { 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_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"; @@ -654,6 +687,7 @@ class AvmMiniFlavor { Commitment aluChip_alu_op_sub; Commitment aluChip_alu_op_mul; Commitment aluChip_alu_op_div; + Commitment aluChip_alu_ff_tag; Commitment aluChip_alu_u8_tag; Commitment aluChip_alu_u16_tag; Commitment aluChip_alu_u32_tag; @@ -736,6 +770,7 @@ class AvmMiniFlavor { aluChip_alu_op_sub = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_op_mul = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_op_div = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); + aluChip_alu_ff_tag = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_u8_tag = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_u16_tag = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); aluChip_alu_u32_tag = deserialize_from_buffer(Transcript::proof_data, num_bytes_read); @@ -822,6 +857,7 @@ class AvmMiniFlavor { 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_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); 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 index 8fbf67a79e2..471a9db3c19 100644 --- 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 @@ -41,6 +41,7 @@ template struct AvmMiniFullRow { FF aluChip_alu_op_sub{}; FF aluChip_alu_op_mul{}; FF aluChip_alu_op_div{}; + FF aluChip_alu_ff_tag{}; FF aluChip_alu_u8_tag{}; FF aluChip_alu_u16_tag{}; FF aluChip_alu_u32_tag{}; @@ -85,20 +86,20 @@ template struct AvmMiniFullRow { FF avmMini_mem_idx_b{}; FF avmMini_mem_idx_c{}; FF avmMini_last{}; - FF memTrace_m_tag_shift{}; - FF memTrace_m_rw_shift{}; - FF memTrace_m_addr_shift{}; - FF memTrace_m_val_shift{}; - FF avmMini_pc_shift{}; FF avmMini_internal_return_ptr_shift{}; - FF aluChip_alu_u16_r2_shift{}; + FF avmMini_pc_shift{}; FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r7_shift{}; FF aluChip_alu_u16_r4_shift{}; FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r1_shift{}; + FF memTrace_m_rw_shift{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_val_shift{}; + FF memTrace_m_tag_shift{}; }; class AvmMiniCircuitBuilder { @@ -111,8 +112,8 @@ class AvmMiniCircuitBuilder { using Polynomial = Flavor::Polynomial; using ProverPolynomials = Flavor::ProverPolynomials; - static constexpr size_t num_fixed_columns = 79; - static constexpr size_t num_polys = 65; + static constexpr size_t num_fixed_columns = 80; + static constexpr size_t num_polys = 66; std::vector rows; void set_trace(std::vector&& trace) { rows = std::move(trace); } @@ -149,6 +150,7 @@ class AvmMiniCircuitBuilder { 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_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; @@ -195,20 +197,20 @@ class AvmMiniCircuitBuilder { polys.avmMini_last[i] = rows[i].avmMini_last; } - polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); - polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); - polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); - polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); - polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); + polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.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_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); - polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); + polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); + polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); + polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); + polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); + polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); + polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); + polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); + polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); + polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); return polys; } @@ -246,10 +248,6 @@ class AvmMiniCircuitBuilder { return true; }; - if (!evaluate_relation.template operator()>( - "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { - return false; - } if (!evaluate_relation.template operator()>("avm_mini", AvmMini_vm::get_relation_label_avm_mini)) { return false; @@ -258,6 +256,10 @@ class AvmMiniCircuitBuilder { AvmMini_vm::get_relation_label_alu_chip)) { return false; } + if (!evaluate_relation.template operator()>( + "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { + return false; + } return true; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index bc638a31742..423c5c32e4c 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,42 +7,46 @@ namespace proof_system::AvmMini_vm { template struct Alu_chipRow { + FF aluChip_alu_u16_r0_shift{}; FF aluChip_alu_u16_r6{}; - FF aluChip_alu_u16_r4{}; + FF aluChip_alu_u16_r0{}; + FF aluChip_alu_u16_r1{}; + FF aluChip_alu_u64_r0{}; FF aluChip_alu_cf{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r4_shift{}; + FF aluChip_alu_u8_r1{}; + FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_ff_tag{}; + FF aluChip_alu_u16_r2{}; FF aluChip_alu_u16_r7{}; + FF aluChip_alu_ic{}; + FF aluChip_alu_u16_r3{}; FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u64_r0{}; - FF aluChip_alu_ib{}; - FF aluChip_alu_u16_r1{}; - FF aluChip_alu_u64_tag{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u32_tag{}; + FF aluChip_alu_u16_tag{}; FF aluChip_alu_u128_tag{}; - FF aluChip_alu_u16_r0{}; - FF aluChip_alu_u16_r3{}; + FF aluChip_alu_u16_r4{}; + FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_op_sub{}; + FF aluChip_alu_ib{}; FF aluChip_alu_u16_r5{}; - FF aluChip_alu_u8_r1{}; + FF aluChip_alu_ia{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r1_shift{}; FF aluChip_alu_u8_tag{}; - FF aluChip_alu_u16_tag{}; - FF aluChip_alu_u32_tag{}; FF aluChip_alu_op_add{}; - FF aluChip_alu_u8_r0{}; FF aluChip_alu_op_mul{}; - FF aluChip_alu_ia{}; - FF aluChip_alu_ic{}; - FF aluChip_alu_op_sub{}; - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r2{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_u8_r0{}; + FF aluChip_alu_u64_tag{}; }; inline std::string get_relation_label_alu_chip(int index) { - switch (index) {} + switch (index) { + case 6: + return "SUBOP_ADDITION_FF"; + } return std::to_string(index); } @@ -50,8 +54,9 @@ template class alu_chipImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, 3, 3, 3, 3, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 6, 6, 8, + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 3, 3, 3, 3, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 5, 4, + 5, 4, 5, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 6, 6, 8, }; template @@ -65,7 +70,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(0); - auto tmp = (aluChip_alu_u8_tag * (-aluChip_alu_u8_tag + FF(1))); + auto tmp = (aluChip_alu_ff_tag * (-aluChip_alu_ff_tag + FF(1))); tmp *= scaling_factor; std::get<0>(evals) += tmp; } @@ -73,7 +78,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(1); - auto tmp = (aluChip_alu_u16_tag * (-aluChip_alu_u16_tag + FF(1))); + auto tmp = (aluChip_alu_u8_tag * (-aluChip_alu_u8_tag + FF(1))); tmp *= scaling_factor; std::get<1>(evals) += tmp; } @@ -81,7 +86,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(2); - auto tmp = (aluChip_alu_u32_tag * (-aluChip_alu_u32_tag + FF(1))); + auto tmp = (aluChip_alu_u16_tag * (-aluChip_alu_u16_tag + FF(1))); tmp *= scaling_factor; std::get<2>(evals) += tmp; } @@ -89,7 +94,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(3); - auto tmp = (aluChip_alu_u64_tag * (-aluChip_alu_u64_tag + FF(1))); + auto tmp = (aluChip_alu_u32_tag * (-aluChip_alu_u32_tag + FF(1))); tmp *= scaling_factor; std::get<3>(evals) += tmp; } @@ -97,7 +102,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(4); - auto tmp = (aluChip_alu_u128_tag * (-aluChip_alu_u128_tag + FF(1))); + auto tmp = (aluChip_alu_u64_tag * (-aluChip_alu_u64_tag + FF(1))); tmp *= scaling_factor; std::get<4>(evals) += tmp; } @@ -105,8 +110,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(5); - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_add) * - (((aluChip_alu_u8_r0 + (aluChip_alu_cf * FF(256))) - aluChip_alu_ia) - aluChip_alu_ib)); + auto tmp = (aluChip_alu_u128_tag * (-aluChip_alu_u128_tag + FF(1))); tmp *= scaling_factor; std::get<5>(evals) += tmp; } @@ -114,7 +118,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(6); - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_add) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); + auto tmp = + ((aluChip_alu_ff_tag * aluChip_alu_op_add) * ((aluChip_alu_ia + aluChip_alu_ib) - aluChip_alu_ic)); tmp *= scaling_factor; std::get<6>(evals) += tmp; } @@ -122,8 +127,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(7); - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_add) * - (((aluChip_alu_u16_r0 + (aluChip_alu_cf * FF(65536))) - aluChip_alu_ia) - aluChip_alu_ib)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_add) * + (((aluChip_alu_u8_r0 + (aluChip_alu_cf * FF(256))) - aluChip_alu_ia) - aluChip_alu_ib)); tmp *= scaling_factor; std::get<7>(evals) += tmp; } @@ -131,7 +136,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(8); - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_add) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_add) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); tmp *= scaling_factor; std::get<8>(evals) += tmp; } @@ -139,26 +144,43 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(9); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_add) * + (((aluChip_alu_u16_r0 + (aluChip_alu_cf * FF(65536))) - aluChip_alu_ia) - aluChip_alu_ib)); + tmp *= scaling_factor; + std::get<9>(evals) += tmp; + } + // Contribution 10 + { + AvmMini_DECLARE_VIEWS(10); + + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_add) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<10>(evals) += tmp; + } + // Contribution 11 + { + AvmMini_DECLARE_VIEWS(11); + auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_add) * ((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + (aluChip_alu_cf * FF(4294967296UL))) - aluChip_alu_ia) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<9>(evals) += tmp; + std::get<11>(evals) += tmp; } - // Contribution 10 + // Contribution 12 { - AvmMini_DECLARE_VIEWS(10); + AvmMini_DECLARE_VIEWS(12); auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_add) * ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<10>(evals) += tmp; + std::get<12>(evals) += tmp; } - // Contribution 11 + // Contribution 13 { - AvmMini_DECLARE_VIEWS(11); + AvmMini_DECLARE_VIEWS(13); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_add) * ((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -168,11 +190,11 @@ template class alu_chipImpl { aluChip_alu_ia) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<11>(evals) += tmp; + std::get<13>(evals) += tmp; } - // Contribution 12 + // Contribution 14 { - AvmMini_DECLARE_VIEWS(12); + AvmMini_DECLARE_VIEWS(14); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_add) * @@ -180,11 +202,11 @@ template class alu_chipImpl { (aluChip_alu_u16_r3 * FF(281474976710656UL))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<12>(evals) += tmp; + std::get<14>(evals) += tmp; } - // Contribution 13 + // Contribution 15 { - AvmMini_DECLARE_VIEWS(13); + AvmMini_DECLARE_VIEWS(15); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_add) * ((((((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -198,11 +220,11 @@ template class alu_chipImpl { aluChip_alu_ia) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<13>(evals) += tmp; + std::get<15>(evals) += tmp; } - // Contribution 14 + // Contribution 16 { - AvmMini_DECLARE_VIEWS(14); + AvmMini_DECLARE_VIEWS(16); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_add) * ((((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -214,45 +236,45 @@ template class alu_chipImpl { (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<14>(evals) += tmp; + std::get<16>(evals) += tmp; } - // Contribution 15 + // Contribution 17 { - AvmMini_DECLARE_VIEWS(15); + AvmMini_DECLARE_VIEWS(17); auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_sub) * (((aluChip_alu_u8_r0 + (aluChip_alu_cf * FF(256))) - aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<15>(evals) += tmp; + std::get<17>(evals) += tmp; } - // Contribution 16 + // Contribution 18 { - AvmMini_DECLARE_VIEWS(16); + AvmMini_DECLARE_VIEWS(18); auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_sub) * (aluChip_alu_u8_r0 - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<16>(evals) += tmp; + std::get<18>(evals) += tmp; } - // Contribution 17 + // Contribution 19 { - AvmMini_DECLARE_VIEWS(17); + AvmMini_DECLARE_VIEWS(19); auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_sub) * (((aluChip_alu_u16_r0 + (aluChip_alu_cf * FF(65536))) - aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<17>(evals) += tmp; + std::get<19>(evals) += tmp; } - // Contribution 18 + // Contribution 20 { - AvmMini_DECLARE_VIEWS(18); + AvmMini_DECLARE_VIEWS(20); auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_sub) * (aluChip_alu_u16_r0 - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<18>(evals) += tmp; + std::get<20>(evals) += tmp; } - // Contribution 19 + // Contribution 21 { - AvmMini_DECLARE_VIEWS(19); + AvmMini_DECLARE_VIEWS(21); auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_sub) * @@ -260,20 +282,20 @@ template class alu_chipImpl { aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<19>(evals) += tmp; + std::get<21>(evals) += tmp; } - // Contribution 20 + // Contribution 22 { - AvmMini_DECLARE_VIEWS(20); + AvmMini_DECLARE_VIEWS(22); auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_sub) * ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<20>(evals) += tmp; + std::get<22>(evals) += tmp; } - // Contribution 21 + // Contribution 23 { - AvmMini_DECLARE_VIEWS(21); + AvmMini_DECLARE_VIEWS(23); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_sub) * ((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -283,11 +305,11 @@ template class alu_chipImpl { aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<21>(evals) += tmp; + std::get<23>(evals) += tmp; } - // Contribution 22 + // Contribution 24 { - AvmMini_DECLARE_VIEWS(22); + AvmMini_DECLARE_VIEWS(24); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_sub) * @@ -295,11 +317,11 @@ template class alu_chipImpl { (aluChip_alu_u16_r3 * FF(281474976710656UL))) - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<22>(evals) += tmp; + std::get<24>(evals) += tmp; } - // Contribution 23 + // Contribution 25 { - AvmMini_DECLARE_VIEWS(23); + AvmMini_DECLARE_VIEWS(25); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_sub) * ((((((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -313,11 +335,11 @@ template class alu_chipImpl { aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<23>(evals) += tmp; + std::get<25>(evals) += tmp; } - // Contribution 24 + // Contribution 26 { - AvmMini_DECLARE_VIEWS(24); + AvmMini_DECLARE_VIEWS(26); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_sub) * ((((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -329,45 +351,45 @@ template class alu_chipImpl { (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<24>(evals) += tmp; + std::get<26>(evals) += tmp; } - // Contribution 25 + // Contribution 27 { - AvmMini_DECLARE_VIEWS(25); + AvmMini_DECLARE_VIEWS(27); auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; - std::get<25>(evals) += tmp; + std::get<27>(evals) += tmp; } - // Contribution 26 + // Contribution 28 { - AvmMini_DECLARE_VIEWS(26); + AvmMini_DECLARE_VIEWS(28); auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<26>(evals) += tmp; + std::get<28>(evals) += tmp; } - // Contribution 27 + // Contribution 29 { - AvmMini_DECLARE_VIEWS(27); + AvmMini_DECLARE_VIEWS(29); auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; - std::get<27>(evals) += tmp; + std::get<29>(evals) += tmp; } - // Contribution 28 + // Contribution 30 { - AvmMini_DECLARE_VIEWS(28); + AvmMini_DECLARE_VIEWS(30); auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<28>(evals) += tmp; + std::get<30>(evals) += tmp; } - // Contribution 29 + // Contribution 31 { - AvmMini_DECLARE_VIEWS(29); + AvmMini_DECLARE_VIEWS(31); auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_mul) * @@ -375,20 +397,20 @@ template class alu_chipImpl { (aluChip_alu_u16_r3 * FF(281474976710656UL))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; - std::get<29>(evals) += tmp; + std::get<31>(evals) += tmp; } - // Contribution 30 + // Contribution 32 { - AvmMini_DECLARE_VIEWS(30); + AvmMini_DECLARE_VIEWS(32); auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_mul) * ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<30>(evals) += tmp; + std::get<32>(evals) += tmp; } - // Contribution 31 + // Contribution 33 { - AvmMini_DECLARE_VIEWS(31); + AvmMini_DECLARE_VIEWS(33); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_mul) * ((((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -400,11 +422,11 @@ template class alu_chipImpl { (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; - std::get<31>(evals) += tmp; + std::get<33>(evals) += tmp; } - // Contribution 32 + // Contribution 34 { - AvmMini_DECLARE_VIEWS(32); + AvmMini_DECLARE_VIEWS(34); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_mul) * @@ -412,11 +434,11 @@ template class alu_chipImpl { (aluChip_alu_u16_r3 * FF(281474976710656UL))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<32>(evals) += tmp; + std::get<34>(evals) += tmp; } - // Contribution 33 + // Contribution 35 { - AvmMini_DECLARE_VIEWS(33); + AvmMini_DECLARE_VIEWS(35); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * (((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -428,11 +450,11 @@ template class alu_chipImpl { FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<33>(evals) += tmp; + std::get<35>(evals) += tmp; } - // Contribution 34 + // Contribution 36 { - AvmMini_DECLARE_VIEWS(34); + AvmMini_DECLARE_VIEWS(36); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * (((((aluChip_alu_u16_r0_shift + (aluChip_alu_u16_r1_shift * FF(65536))) + @@ -444,11 +466,11 @@ template class alu_chipImpl { FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<34>(evals) += tmp; + std::get<36>(evals) += tmp; } - // Contribution 35 + // Contribution 37 { - AvmMini_DECLARE_VIEWS(35); + AvmMini_DECLARE_VIEWS(37); 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))) + @@ -465,7 +487,7 @@ template class alu_chipImpl { FF(uint256_t{ 0, 0, 1, 0 }))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<35>(evals) += tmp; + std::get<37>(evals) += tmp; } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index 934f2d5e71a..89c03208507 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,70 +7,67 @@ namespace proof_system::AvmMini_vm { template struct Avm_miniRow { - FF avmMini_sel_op_sub{}; - FF avmMini_sel_op_div{}; - FF avmMini_rwc{}; - FF avmMini_pc_shift{}; - FF avmMini_ic{}; - FF avmMini_internal_return_ptr{}; FF avmMini_first{}; - FF avmMini_pc{}; + FF avmMini_internal_return_ptr{}; + FF avmMini_tag_err{}; FF avmMini_ib{}; - FF avmMini_sel_internal_call{}; + FF avmMini_sel_internal_return{}; + FF avmMini_ic{}; FF avmMini_sel_jump{}; + FF avmMini_sel_op_sub{}; FF avmMini_rwb{}; - FF avmMini_mem_op_a{}; - FF avmMini_ia{}; - FF avmMini_mem_idx_a{}; - FF avmMini_mem_op_c{}; - FF avmMini_inv{}; - FF avmMini_sel_op_add{}; - FF avmMini_sel_internal_return{}; - FF avmMini_op_err{}; - FF avmMini_sel_op_mul{}; - FF avmMini_tag_err{}; + FF avmMini_rwc{}; FF avmMini_rwa{}; + FF avmMini_sel_op_div{}; + FF avmMini_sel_op_mul{}; + FF avmMini_op_err{}; + FF avmMini_mem_op_b{}; + FF avmMini_mem_op_c{}; FF avmMini_sel_halt{}; + FF avmMini_ia{}; FF avmMini_internal_return_ptr_shift{}; + FF avmMini_sel_internal_call{}; + FF avmMini_sel_op_add{}; FF avmMini_mem_idx_b{}; - FF avmMini_mem_op_b{}; + FF avmMini_pc_shift{}; + FF avmMini_pc{}; + FF avmMini_inv{}; + FF avmMini_mem_op_a{}; + FF avmMini_mem_idx_a{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { + case 32: + return "RETURN_POINTER_DECREMENT"; + case 38: - return "PC_INCREMENT"; + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - case 19: - return "SUBOP_ADDITION_FF"; + case 24: + return "SUBOP_ERROR_RELEVANT_OP"; - case 33: - return "RETURN_POINTER_DECREMENT"; + case 23: + return "SUBOP_DIVISION_ZERO_ERR2"; - case 39: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + case 37: + return "PC_INCREMENT"; case 20: - return "SUBOP_SUBTRACTION_FF"; - - case 27: - return "RETURN_POINTER_INCREMENT"; + return "SUBOP_MULTIPLICATION_FF"; - case 23: + case 22: return "SUBOP_DIVISION_ZERO_ERR1"; - case 22: - return "SUBOP_DIVISION_FF"; + case 26: + return "RETURN_POINTER_INCREMENT"; case 21: - return "SUBOP_MULTIPLICATION_FF"; - - case 25: - return "SUBOP_ERROR_RELEVANT_OP"; + return "SUBOP_DIVISION_FF"; - case 24: - return "SUBOP_DIVISION_ZERO_ERR2"; + case 19: + return "SUBOP_SUBTRACTION_FF"; } return std::to_string(index); } @@ -79,9 +76,9 @@ template class avm_miniImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 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, - 3, 4, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, + 4, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, }; template @@ -247,7 +244,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(19); - auto tmp = (avmMini_sel_op_add * ((avmMini_ia + avmMini_ib) - avmMini_ic)); + auto tmp = (avmMini_sel_op_sub * ((avmMini_ia - avmMini_ib) - avmMini_ic)); tmp *= scaling_factor; std::get<19>(evals) += tmp; } @@ -255,7 +252,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(20); - auto tmp = (avmMini_sel_op_sub * ((avmMini_ia - avmMini_ib) - avmMini_ic)); + auto tmp = (avmMini_sel_op_mul * ((avmMini_ia * avmMini_ib) - avmMini_ic)); tmp *= scaling_factor; std::get<20>(evals) += tmp; } @@ -263,7 +260,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(21); - auto tmp = (avmMini_sel_op_mul * ((avmMini_ia * avmMini_ib) - avmMini_ic)); + auto tmp = ((avmMini_sel_op_div * (-avmMini_op_err + FF(1))) * ((avmMini_ic * avmMini_ib) - avmMini_ia)); tmp *= scaling_factor; std::get<21>(evals) += tmp; } @@ -271,7 +268,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(22); - auto tmp = ((avmMini_sel_op_div * (-avmMini_op_err + FF(1))) * ((avmMini_ic * avmMini_ib) - avmMini_ia)); + auto tmp = (avmMini_sel_op_div * (((avmMini_ib * avmMini_inv) - FF(1)) + avmMini_op_err)); tmp *= scaling_factor; std::get<22>(evals) += tmp; } @@ -279,7 +276,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(23); - auto tmp = (avmMini_sel_op_div * (((avmMini_ib * avmMini_inv) - FF(1)) + avmMini_op_err)); + auto tmp = ((avmMini_sel_op_div * avmMini_op_err) * (-avmMini_inv + FF(1))); tmp *= scaling_factor; std::get<23>(evals) += tmp; } @@ -287,7 +284,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(24); - auto tmp = ((avmMini_sel_op_div * avmMini_op_err) * (-avmMini_inv + FF(1))); + auto tmp = (avmMini_op_err * (avmMini_sel_op_div - FF(1))); tmp *= scaling_factor; std::get<24>(evals) += tmp; } @@ -295,7 +292,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(25); - auto tmp = (avmMini_op_err * (avmMini_sel_op_div - FF(1))); + auto tmp = (avmMini_sel_jump * (avmMini_pc_shift - avmMini_ia)); tmp *= scaling_factor; std::get<25>(evals) += tmp; } @@ -303,7 +300,8 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(26); - auto tmp = (avmMini_sel_jump * (avmMini_pc_shift - avmMini_ia)); + auto tmp = (avmMini_sel_internal_call * + (avmMini_internal_return_ptr_shift - (avmMini_internal_return_ptr + FF(1)))); tmp *= scaling_factor; std::get<26>(evals) += tmp; } @@ -311,8 +309,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(27); - auto tmp = (avmMini_sel_internal_call * - (avmMini_internal_return_ptr_shift - (avmMini_internal_return_ptr + FF(1)))); + auto tmp = (avmMini_sel_internal_call * (avmMini_internal_return_ptr - avmMini_mem_idx_b)); tmp *= scaling_factor; std::get<27>(evals) += tmp; } @@ -320,7 +317,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(28); - auto tmp = (avmMini_sel_internal_call * (avmMini_internal_return_ptr - avmMini_mem_idx_b)); + auto tmp = (avmMini_sel_internal_call * (avmMini_pc_shift - avmMini_ia)); tmp *= scaling_factor; std::get<28>(evals) += tmp; } @@ -328,7 +325,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(29); - auto tmp = (avmMini_sel_internal_call * (avmMini_pc_shift - avmMini_ia)); + auto tmp = (avmMini_sel_internal_call * ((avmMini_pc + FF(1)) - avmMini_ib)); tmp *= scaling_factor; std::get<29>(evals) += tmp; } @@ -336,7 +333,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(30); - auto tmp = (avmMini_sel_internal_call * ((avmMini_pc + FF(1)) - avmMini_ib)); + auto tmp = (avmMini_sel_internal_call * (avmMini_rwb - FF(1))); tmp *= scaling_factor; std::get<30>(evals) += tmp; } @@ -344,7 +341,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(31); - auto tmp = (avmMini_sel_internal_call * (avmMini_rwb - FF(1))); + auto tmp = (avmMini_sel_internal_call * (avmMini_mem_op_b - FF(1))); tmp *= scaling_factor; std::get<31>(evals) += tmp; } @@ -352,7 +349,8 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(32); - auto tmp = (avmMini_sel_internal_call * (avmMini_mem_op_b - FF(1))); + auto tmp = (avmMini_sel_internal_return * + (avmMini_internal_return_ptr_shift - (avmMini_internal_return_ptr - FF(1)))); tmp *= scaling_factor; std::get<32>(evals) += tmp; } @@ -360,8 +358,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(33); - auto tmp = (avmMini_sel_internal_return * - (avmMini_internal_return_ptr_shift - (avmMini_internal_return_ptr - FF(1)))); + auto tmp = (avmMini_sel_internal_return * ((avmMini_internal_return_ptr - FF(1)) - avmMini_mem_idx_a)); tmp *= scaling_factor; std::get<33>(evals) += tmp; } @@ -369,7 +366,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(34); - auto tmp = (avmMini_sel_internal_return * ((avmMini_internal_return_ptr - FF(1)) - avmMini_mem_idx_a)); + auto tmp = (avmMini_sel_internal_return * (avmMini_pc_shift - avmMini_ia)); tmp *= scaling_factor; std::get<34>(evals) += tmp; } @@ -377,7 +374,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(35); - auto tmp = (avmMini_sel_internal_return * (avmMini_pc_shift - avmMini_ia)); + auto tmp = (avmMini_sel_internal_return * avmMini_rwa); tmp *= scaling_factor; std::get<35>(evals) += tmp; } @@ -385,7 +382,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(36); - auto tmp = (avmMini_sel_internal_return * avmMini_rwa); + auto tmp = (avmMini_sel_internal_return * (avmMini_mem_op_a - FF(1))); tmp *= scaling_factor; std::get<36>(evals) += tmp; } @@ -393,30 +390,22 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(37); - auto tmp = (avmMini_sel_internal_return * (avmMini_mem_op_a - FF(1))); - tmp *= scaling_factor; - std::get<37>(evals) += tmp; - } - // Contribution 38 - { - AvmMini_DECLARE_VIEWS(38); - 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_pc_shift - (avmMini_pc + FF(1)))); tmp *= scaling_factor; - std::get<38>(evals) += tmp; + std::get<37>(evals) += tmp; } - // Contribution 39 + // Contribution 38 { - AvmMini_DECLARE_VIEWS(39); + AvmMini_DECLARE_VIEWS(38); 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<39>(evals) += tmp; + std::get<38>(evals) += tmp; } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index dec970cc38b..c596399689a 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -23,6 +23,7 @@ [[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_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); \ @@ -67,17 +68,17 @@ [[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_tag_shift = View(new_term.memTrace_m_tag_shift); \ - [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ - [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ - [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ - [[maybe_unused]] auto avmMini_pc_shift = View(new_term.avmMini_pc_shift); \ [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ + [[maybe_unused]] auto avmMini_pc_shift = View(new_term.avmMini_pc_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_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); + [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ + [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ + [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ + [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ + [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 0e321047807..4b9910b0fad 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,41 +7,41 @@ namespace proof_system::AvmMini_vm { template struct Mem_traceRow { - FF memTrace_m_one_min_inv{}; - FF memTrace_m_lastAccess{}; - FF memTrace_m_tag_err{}; - FF memTrace_m_tag_shift{}; FF memTrace_m_rw_shift{}; - FF memTrace_m_val{}; - FF memTrace_m_tag{}; FF memTrace_m_addr_shift{}; - FF memTrace_m_addr{}; - FF memTrace_m_rw{}; + FF memTrace_m_val{}; FF memTrace_m_val_shift{}; - FF memTrace_m_last{}; FF memTrace_m_in_tag{}; + FF memTrace_m_one_min_inv{}; + FF memTrace_m_addr{}; + FF memTrace_m_last{}; + FF memTrace_m_lastAccess{}; + FF memTrace_m_tag{}; + FF memTrace_m_tag_shift{}; + FF memTrace_m_rw{}; + FF memTrace_m_tag_err{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { + case 7: + return "MEM_ZERO_INIT"; + case 9: return "MEM_IN_TAG_CONSISTENCY_2"; - case 8: - return "MEM_IN_TAG_CONSISTENCY_1"; - case 6: return "MEM_READ_WRITE_TAG_CONSISTENCY"; + case 5: + return "MEM_READ_WRITE_VAL_CONSISTENCY"; + case 4: return "MEM_LAST_ACCESS_DELIMITER"; - case 7: - return "MEM_ZERO_INIT"; - - case 5: - return "MEM_READ_WRITE_VAL_CONSISTENCY"; + case 8: + return "MEM_IN_TAG_CONSISTENCY_1"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp index a05eeceb2dd..bf41b4826b9 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp @@ -37,10 +37,11 @@ std::vector AvmMiniAluTraceBuilder::final * @param b Right operand of the addition * @param in_tag Instruction tag defining the number of bits on which the addition applies. * It is assumed that the caller never uses the type u0. + * @param clk Clock referring to the operation in the main trace. * * @return FF The result of the addition casted in a finite field element */ -FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag) +FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t const clk) { FF c{}; bool carry = false; @@ -49,7 +50,7 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag) switch (in_tag) { case AvmMemoryTag::ff: - return a + b; + c = a + b; case AvmMemoryTag::u8: { uint8_t a_u8 = static_cast(uint256_t(a).data[0]); uint8_t b_u8 = static_cast(uint256_t(b).data[0]); @@ -134,7 +135,9 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag) } alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ + .alu_clk = clk, .alu_op_add = true, + .alu_ff_tag = in_tag == AvmMemoryTag::ff, .alu_u8_tag = in_tag == AvmMemoryTag::u8, .alu_u16_tag = in_tag == AvmMemoryTag::u16, .alu_u32_tag = in_tag == AvmMemoryTag::u32, diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp index b83ca341f6b..aa5a5684d47 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp @@ -8,8 +8,11 @@ class AvmMiniAluTraceBuilder { public: struct AluTraceEntry { + uint32_t alu_clk{}; + bool alu_op_add = false; + bool alu_ff_tag = false; bool alu_u8_tag = false; bool alu_u16_tag = false; bool alu_u32_tag = false; @@ -31,7 +34,7 @@ class AvmMiniAluTraceBuilder { void reset(); std::vector finalize(); - FF add(FF const& a, FF const& b, AvmMemoryTag in_tag); + FF add(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t clk); private: std::vector alu_trace; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp index 92aba948c7b..22982b1e067 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp @@ -32,7 +32,7 @@ void AvmMiniTraceBuilder::reset() alu_trace_builder.reset(); } -/** TODO: Implement for non finite field types +/** * @brief Addition with direct memory access. * * @param a_offset An index in memory pointing to the first operand of the addition. @@ -50,9 +50,9 @@ void AvmMiniTraceBuilder::add(uint32_t a_offset, uint32_t b_offset, uint32_t dst bool tag_match = read_a.tag_match && read_b.tag_match; // a + b = c - FF a = read_a.val; - FF b = read_b.val; - FF c = a + b; + FF a = tag_match ? read_a.val : FF(0); + FF b = tag_match ? read_b.val : FF(0); + FF c = alu_trace_builder.add(a, b, in_tag, clk); // Write into memory value c from intermediate register ic. mem_trace_builder.write_into_memory(clk, IntermRegister::ic, dst_offset, c, in_tag); @@ -64,9 +64,9 @@ void AvmMiniTraceBuilder::add(uint32_t a_offset, uint32_t b_offset, uint32_t dst .avmMini_sel_op_add = FF(1), .avmMini_in_tag = FF(static_cast(in_tag)), .avmMini_tag_err = FF(static_cast(!tag_match)), - .avmMini_ia = tag_match ? a : FF(0), - .avmMini_ib = tag_match ? b : FF(0), - .avmMini_ic = tag_match ? c : FF(0), + .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), @@ -418,7 +418,7 @@ std::vector AvmMiniTraceBuilder::return_op(uint32_t ret_offset, uint32_t ret * @brief HALT opcode * This opcode effectively stops program execution, and is used in the relation that * ensures the program counter increments on each opcode. - * i.e.ythe program counter should freeze and the halt flag is set to 1. + * i.e. the program counter should freeze and the halt flag is set to 1. */ void AvmMiniTraceBuilder::halt() { @@ -594,8 +594,11 @@ 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.aluChip_alu_op_add = FF(static_cast(src.alu_op_add)); + 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)); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp index 043994db574..9758f404ce2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp @@ -86,6 +86,8 @@ bool AvmMiniVerifier::verify_proof(const plonk::proof& proof) 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_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 = diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index e18f1f666b2..802c1ad2210 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -17,6 +17,7 @@ class AvmMiniArithmeticTests : public ::testing::Test { }; class AvmMiniArithmeticTestsFF : public AvmMiniArithmeticTests {}; +class AvmMiniArithmeticTestsU8 : public AvmMiniArithmeticTests {}; class AvmMiniArithmeticNegativeTestsFF : public AvmMiniArithmeticTests {}; /****************************************************************************** @@ -43,6 +44,10 @@ class AvmMiniArithmeticNegativeTestsFF : public AvmMiniArithmeticTests {}; * will still correctly work along the development of the AVM. ******************************************************************************/ +/****************************************************************************** + * Positive Tests - FF + ******************************************************************************/ + // Test on basic addition over finite field type. TEST_F(AvmMiniArithmeticTestsFF, addition) { @@ -255,6 +260,32 @@ TEST_F(AvmMiniArithmeticTestsFF, mixedOperationsWithError) validate_trace_proof(std::move(trace)); } +/****************************************************************************** + * Positive Tests - U8 + ******************************************************************************/ + +// Test on basic addition over u8 type. +TEST_F(AvmMiniArithmeticTestsU8, addition) +{ + // trace_builder + trace_builder.call_data_copy(0, 2, 0, std::vector{ 62, 29 }); + + // Memory layout: [62,29,0,0,0,....] + trace_builder.add(0, 1, 2, AvmMemoryTag::u8); // [62,29,91,0,0,....] + trace_builder.return_op(2, 1); + 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); }); + + // Check that the correct result is computed. + EXPECT_TRUE(row != trace.end()); + EXPECT_EQ(row->avmMini_ic, FF(91)); + // EXPECT_EQ(row->aluChip_alu_u8_tag, FF(1)); + + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * * NEGATIVE TESTS - Finite Field Type @@ -283,11 +314,11 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, addition) // Memory layout: [37,4,11,0,0,0,....] trace_builder.add(0, 1, 4, AvmMemoryTag::ff); // [37,4,11,0,41,0,....] + trace_builder.halt(); auto trace = trace_builder.finalize(); auto select_row = [](Row r) { return r.avmMini_sel_op_add == FF(1); }; - mutate_ic_in_trace(trace, std::move(select_row), FF(40)); - + mutate_ic_in_trace(trace, std::move(select_row), FF(40), true); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_ADDITION_FF"); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp index 04aa992c766..a8f16a9ea4a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp @@ -34,8 +34,9 @@ void validate_trace_proof(std::vector&& trace) * @param trace Execution trace * @param selectRow Lambda serving to select the row in trace * @param newValue The value that will be written in intermediate register Ic at the selected row. + * @param alu A boolean telling whether we mutate the ic value in alu as well. */ -void mutate_ic_in_trace(std::vector& trace, std::function&& selectRow, FF const& newValue) +void mutate_ic_in_trace(std::vector& trace, std::function&& selectRow, FF const& newValue, bool alu) { // Find the first row matching the criteria defined by selectRow auto row = std::ranges::find_if(trace.begin(), trace.end(), selectRow); @@ -46,7 +47,18 @@ void mutate_ic_in_trace(std::vector& trace, std::function&& sele // Mutate the correct result in the main trace row->avmMini_ic = newValue; - // Adapt the memory trace to be consistent with the wrongly computed addition + // Optionally mutate the corresponding ic value in alu + if (alu) { + auto const clk = row->avmMini_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; }); + + EXPECT_TRUE(alu_row != trace.end()); + alu_row->aluChip_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; diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp index 145eb171457..10debc85891 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp @@ -14,6 +14,9 @@ namespace tests_avm { void validate_trace_proof(std::vector&& trace); -void mutate_ic_in_trace(std::vector& trace, std::function&& selectRow, FF const& newValue); +void mutate_ic_in_trace(std::vector& trace, + std::function&& selectRow, + FF const& newValue, + bool alu = false); } // namespace tests_avm \ No newline at end of file From 95e9e9f428b9054d2f29cbc3320b25e6c1f6d919 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Tue, 9 Jan 2024 16:39:06 +0000 Subject: [PATCH 12/28] 3738 - first unit tests for u8 --- .../vm/avm_trace/AvmMini_trace.cpp | 31 ++++++ .../vm/avm_trace/AvmMini_trace.hpp | 3 + .../vm/tests/AvmMini_arithmetic.test.cpp | 94 ++++++++++++++++--- 3 files changed, 113 insertions(+), 15 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp index 22982b1e067..3f012341a4b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp @@ -227,6 +227,37 @@ void AvmMiniTraceBuilder::div(uint32_t a_offset, uint32_t b_offset, uint32_t dst }); } +// TODO: Finish SET opcode implementation. This is a partial implementation +// facilitating testing of arithmetic operations over non finite field types. +// We add an entry in the memory trace and a simplified one in the main trace +// without operation selector. +// No check is performed that val pertains to type defined by in_tag. +/** + * @brief Set a constant from bytecode with direct memory access. + * + * @param val The constant to be written upcasted to u128 + * @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) +{ + auto clk = static_cast(main_trace.size()); + auto val_ff = FF{ uint256_t::from_uint128(val) }; + + 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), + }); +} + /** * @brief CALLDATACOPY opcode with direct memory access, i.e., * M[dst_offset:dst_offset+copy_size] = calldata[cd_offset:cd_offset+copy_size] diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp index f361d8319ef..af09f2e4d14 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp @@ -37,6 +37,9 @@ class AvmMiniTraceBuilder { // Division with direct memory access. void div(uint32_t a_offset, uint32_t b_offset, uint32_t dst_offset, AvmMemoryTag in_tag); + // Set a constant from bytecode with direct memory access. + void set(uint128_t val, uint32_t dst_offset, AvmMemoryTag in_tag); + // Jump to a given program counter. void jump(uint32_t jmp_dest); diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index 802c1ad2210..5043b753529 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -1,5 +1,55 @@ #include "AvmMini_common.test.hpp" +namespace { + +Row common_validate_add(std::vector const& trace, + FF const& a, + FF const& b, + FF const& c, + FF const& addr_a, + FF const& addr_b, + FF const& addr_c, + 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); }); + + // Check that the correct result is stored at the expected memory location. + EXPECT_TRUE(row != trace.end()); + 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)); + + // Check that ia and ib registers are 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->avmMini_ib, b); + EXPECT_EQ(row->avmMini_mem_idx_b, addr_b); + EXPECT_EQ(row->avmMini_mem_op_b, FF(1)); + EXPECT_EQ(row->avmMini_rwb, FF(0)); + + // Check instruction tag and add selector are set. + EXPECT_EQ(row->avmMini_in_tag, FF(static_cast(tag))); + EXPECT_EQ(row->avmMini_sel_op_add, FF(1)); + + // Check that Alu trace is as expected. + 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; }); + + EXPECT_TRUE(alu_row != trace.end()); + EXPECT_EQ(alu_row->aluChip_alu_op_add, FF(1)); + EXPECT_EQ(alu_row->aluChip_alu_ia, a); + EXPECT_EQ(alu_row->aluChip_alu_ib, b); + EXPECT_EQ(alu_row->aluChip_alu_ic, c); + + return *alu_row; +} + +} // anonymous namespace + namespace tests_avm { using namespace avm_trace; @@ -59,15 +109,9 @@ TEST_F(AvmMiniArithmeticTestsFF, addition) trace_builder.return_op(0, 5); 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 alu_row = common_validate_add(trace, FF(37), FF(4), FF(41), FF(0), FF(1), FF(4), AvmMemoryTag::ff); - // Check that the correct result is stored at the expected memory location. - EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avmMini_ic, FF(41)); - EXPECT_EQ(row->avmMini_mem_idx_c, FF(4)); - EXPECT_EQ(row->avmMini_mem_op_c, FF(1)); - EXPECT_EQ(row->avmMini_rwc, FF(1)); + EXPECT_EQ(alu_row.aluChip_alu_ff_tag, FF(1)); validate_trace_proof(std::move(trace)); } @@ -268,20 +312,40 @@ TEST_F(AvmMiniArithmeticTestsFF, mixedOperationsWithError) TEST_F(AvmMiniArithmeticTestsU8, addition) { // trace_builder - trace_builder.call_data_copy(0, 2, 0, std::vector{ 62, 29 }); + trace_builder.set(62, 0, AvmMemoryTag::u8); + trace_builder.set(29, 1, AvmMemoryTag::u8); // Memory layout: [62,29,0,0,0,....] trace_builder.add(0, 1, 2, AvmMemoryTag::u8); // [62,29,91,0,0,....] trace_builder.return_op(2, 1); 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 alu_row = common_validate_add(trace, FF(62), FF(29), FF(91), FF(0), FF(1), FF(2), AvmMemoryTag::u8); - // Check that the correct result is computed. - EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avmMini_ic, FF(91)); - // EXPECT_EQ(row->aluChip_alu_u8_tag, FF(1)); + 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)); + + validate_trace_proof(std::move(trace)); +} + +// Test on basic addition over u8 type with carry. +TEST_F(AvmMiniArithmeticTestsU8, additionCarry) +{ + // trace_builder + trace_builder.set(159, 0, AvmMemoryTag::u8); + trace_builder.set(100, 1, AvmMemoryTag::u8); + + // Memory layout: [159,100,0,0,0,....] + trace_builder.add(0, 1, 2, AvmMemoryTag::u8); // [159,100,3,0,0,....] + trace_builder.return_op(2, 1); + auto trace = trace_builder.finalize(); + + 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(1)); + EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(3)); validate_trace_proof(std::move(trace)); } From d365314a71fc688d2e6f799cf7d3a8c1b3652ffa Mon Sep 17 00:00:00 2001 From: jeanmon Date: Wed, 10 Jan 2024 10:20:41 +0000 Subject: [PATCH 13/28] 3738 - positive unit tests for addition --- .../vm/tests/AvmMini_arithmetic.test.cpp | 241 ++++++++++++++++++ 1 file changed, 241 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index 5043b753529..318243db36b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -1,5 +1,8 @@ #include "AvmMini_common.test.hpp" +#include "barretenberg/numeric/uint128/uint128.hpp" + +using namespace numeric; namespace { Row common_validate_add(std::vector const& trace, @@ -68,6 +71,11 @@ class AvmMiniArithmeticTests : public ::testing::Test { 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 AvmMiniArithmeticNegativeTestsFF : public AvmMiniArithmeticTests {}; /****************************************************************************** @@ -350,6 +358,239 @@ TEST_F(AvmMiniArithmeticTestsU8, additionCarry) validate_trace_proof(std::move(trace)); } +/****************************************************************************** + * Positive Tests - U16 + ******************************************************************************/ + +// Test on basic addition over u16 type. +TEST_F(AvmMiniArithmeticTestsU16, addition) +{ + // trace_builder + trace_builder.set(1775, 119, AvmMemoryTag::u16); + trace_builder.set(33005, 546, AvmMemoryTag::u16); + + trace_builder.add(546, 119, 5, AvmMemoryTag::u16); + trace_builder.return_op(5, 1); + auto trace = trace_builder.finalize(); + + 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_u16_r0, FF(34780)); + + validate_trace_proof(std::move(trace)); +} + +// Test on basic addition over u16 type with carry. +TEST_F(AvmMiniArithmeticTestsU16, additionCarry) +{ + // trace_builder + trace_builder.set(UINT16_MAX - 982, 0, AvmMemoryTag::u16); + trace_builder.set(1000, 1, AvmMemoryTag::u16); + + trace_builder.add(1, 0, 0, AvmMemoryTag::u16); + trace_builder.return_op(0, 1); + auto trace = trace_builder.finalize(); + + 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(1)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(17)); + + validate_trace_proof(std::move(trace)); +} + +/****************************************************************************** + * Positive Tests - U32 + ******************************************************************************/ + +// Test on basic addition over u32 type. +TEST_F(AvmMiniArithmeticTestsU32, addition) +{ + // trace_builder + trace_builder.set(1000000000, 8, AvmMemoryTag::u32); + trace_builder.set(1234567891, 9, AvmMemoryTag::u32); + + trace_builder.add(8, 9, 0, AvmMemoryTag::u32); + trace_builder.return_op(0, 1); + auto trace = trace_builder.finalize(); + + 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_u16_r0, FF(2234567891LLU & UINT16_MAX)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(2234567891LLU >> 16)); + + validate_trace_proof(std::move(trace)); +} + +// Test on basic addition over u32 type with carry. +TEST_F(AvmMiniArithmeticTestsU32, additionCarry) +{ + // trace_builder + trace_builder.set(UINT32_MAX - 1293, 8, AvmMemoryTag::u32); + trace_builder.set(2293, 9, AvmMemoryTag::u32); + + trace_builder.add(8, 9, 0, AvmMemoryTag::u32); + trace_builder.return_op(0, 1); + auto trace = trace_builder.finalize(); + + 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(1)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(999)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0)); + + validate_trace_proof(std::move(trace)); +} + +/****************************************************************************** + * Positive Tests - U64 + ******************************************************************************/ + +// Test on basic addition over u64 type. +TEST_F(AvmMiniArithmeticTestsU64, addition) +{ + uint64_t const a = 7813981340746672LLU; + uint64_t const b = 2379061066771309LLU; + uint64_t const c = 10193042407517981LLU; + + // trace_builder + trace_builder.set(a, 8, AvmMemoryTag::u64); + trace_builder.set(b, 9, AvmMemoryTag::u64); + + trace_builder.add(8, 9, 9, AvmMemoryTag::u64); + trace_builder.return_op(9, 1); + auto trace = trace_builder.finalize(); + + 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.aluChip_alu_u16_r0, FF(28445)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(40929)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(13956)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(36)); + + validate_trace_proof(std::move(trace)); +} + +// Test on basic addition over u64 type with carry. +TEST_F(AvmMiniArithmeticTestsU64, additionCarry) +{ + uint64_t const a = UINT64_MAX - 77LLU; + uint64_t const b = UINT64_MAX - 123LLU; + uint64_t const c = UINT64_MAX - 201LLU; + + // trace_builder + trace_builder.set(a, 0, AvmMemoryTag::u64); + trace_builder.set(b, 1, AvmMemoryTag::u64); + + trace_builder.add(0, 1, 0, AvmMemoryTag::u64); + trace_builder.return_op(0, 1); + auto trace = trace_builder.finalize(); + + 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(1)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(UINT16_MAX - 201)); + 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)); + + validate_trace_proof(std::move(trace)); +} + +/****************************************************************************** + * Positive Tests - U128 + ******************************************************************************/ + +// Test on basic addition over u128 type. +TEST_F(AvmMiniArithmeticTestsU128, addition) +{ + 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); + uint128_t const c = + (uint128_t(UINT64_MAX) << 64) + uint128_t(UINT64_MAX) - uint128_t(36177345) - uint128_t(72948899); + + // trace_builder + trace_builder.set(a, 8, AvmMemoryTag::u128); + trace_builder.set(b, 9, AvmMemoryTag::u128); + + trace_builder.add(8, 9, 9, AvmMemoryTag::u128); + trace_builder.return_op(9, 1); + auto trace = trace_builder.finalize(); + + auto alu_row = common_validate_add(trace, + FF(uint256_t::from_uint128(a)), + FF(uint256_t::from_uint128(b)), + FF(uint256_t::from_uint128(c)), + FF(8), + FF(9), + 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_u16_r0, FF(0xDD9B)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0xF97E)); + 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.aluChip_alu_u16_r7, FF(0xFFFF)); + + validate_trace_proof(std::move(trace)); +} + +// Test on basic addition over u128 type with carry. +TEST_F(AvmMiniArithmeticTestsU128, additionCarry) +{ + uint128_t const a = (uint128_t(0x5555222233334444LLU) << 64) + uint128_t(0x88889999AAAABBBBLLU); + uint128_t const b = (uint128_t(0x3333222233331111LLU) << 64) + uint128_t(0x5555111155553333LLU); + uint128_t const c = (uint128_t(0x8888444466665555LLU) << 64) + uint128_t(0xDDDDAAAAFFFFEEEELLU); + + // trace_builder + trace_builder.set(a, 8, AvmMemoryTag::u128); + trace_builder.set(b, 9, AvmMemoryTag::u128); + + trace_builder.add(8, 9, 9, AvmMemoryTag::u128); + trace_builder.return_op(9, 1); + auto trace = trace_builder.finalize(); + + auto alu_row = common_validate_add(trace, + FF(uint256_t::from_uint128(a)), + FF(uint256_t::from_uint128(b)), + FF(uint256_t::from_uint128(c)), + FF(8), + FF(9), + 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_u16_r0, FF(0xEEEE)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0xFFFF)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0xAAAA)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0xDDDD)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(0x5555)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(0x6666)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(0x4444)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r7, FF(0x8888)); + + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * * NEGATIVE TESTS - Finite Field Type From a93c9b4965caa07b5b79a0a658658f4169b066b0 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Wed, 10 Jan 2024 12:40:32 +0000 Subject: [PATCH 14/28] 3738 - witness generation for subtraction and move ff pil relation to alu_chip.pil --- barretenberg/cpp/pil/avm/alu_chip.pil | 6 + barretenberg/cpp/pil/avm/avm_mini.pil | 4 - .../flavor/generated/AvmMini_flavor.hpp | 122 ++++++------- .../generated/AvmMini_circuit_builder.hpp | 52 +++--- .../relations/generated/AvmMini/alu_chip.hpp | 170 ++++++++++-------- .../relations/generated/AvmMini/avm_mini.hpp | 129 ++++++------- .../generated/AvmMini/declare_views.hpp | 24 +-- .../relations/generated/AvmMini/mem_trace.hpp | 40 ++--- .../vm/avm_trace/AvmMini_alu_trace.cpp | 134 ++++++++++++++ .../vm/avm_trace/AvmMini_alu_trace.hpp | 2 + .../vm/avm_trace/AvmMini_trace.cpp | 13 +- .../vm/tests/AvmMini_arithmetic.test.cpp | 2 +- 12 files changed, 419 insertions(+), 279 deletions(-) diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil index 200f7b9fea4..8a95d3ad454 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -49,6 +49,8 @@ namespace aluChip(256); // intermediate registers ia and ib (inputs) depending on flag // Carry flag: We will have to constraint to ensure that the // arithmetic expressions are not overflowing finite field size + // Remark: Operation selectors are constrained in the main trace. + // TODO: Enforce the equivalence check for the selectors between both tables. // Boolean flattened instructions tags alu_ff_tag * (1 - alu_ff_tag) = 0; @@ -129,6 +131,10 @@ namespace aluChip(256); // a - b = c <==> c + b = a (mod 2^k) // Same constraints as for addition but we swap alu_ia with alu_ic + // ff subtraction + #[SUBOP_SUBTRACTION_FF] + alu_ff_tag * alu_op_sub * (alu_ia - alu_ib - alu_ic) = 0; + // u8 subtraction alu_u8_tag * alu_op_sub * (alu_u8_r0 + alu_cf * 2**8 - alu_ic - alu_ib) = 0; alu_u8_tag * alu_op_sub * (alu_u8_r0 - alu_ia) = 0; diff --git a/barretenberg/cpp/pil/avm/avm_mini.pil b/barretenberg/cpp/pil/avm/avm_mini.pil index b9c82480e5b..ad9374dcc46 100644 --- a/barretenberg/cpp/pil/avm/avm_mini.pil +++ b/barretenberg/cpp/pil/avm/avm_mini.pil @@ -103,10 +103,6 @@ namespace avmMini(256); tag_err * ib = 0; tag_err * ic = 0; - // Relation for subtraction over the finite field - #[SUBOP_SUBTRACTION_FF] - sel_op_sub * (ia - ib - ic) = 0; - // Relation for multiplication over the finite field #[SUBOP_MULTIPLICATION_FF] sel_op_mul * (ia * ib - ic) = 0; diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index 8bee47084e1..7bcf828cfa0 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -43,7 +43,7 @@ class AvmMiniFlavor { // the unshifted and one for the shifted static constexpr size_t NUM_ALL_ENTITIES = 80; - using Relations = std::tuple, AvmMini_vm::alu_chip, AvmMini_vm::mem_trace>; + 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(); @@ -281,20 +281,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r1_shift, memTrace_m_rw_shift, - memTrace_m_addr_shift, memTrace_m_val_shift, - memTrace_m_tag_shift) + memTrace_m_addr_shift, + memTrace_m_tag_shift, + aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r1_shift, + aluChip_alu_u16_r4_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r3_shift, + avmMini_internal_return_ptr_shift, + avmMini_pc_shift) RefVector get_wires() { @@ -364,20 +364,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r1_shift, memTrace_m_rw_shift, - memTrace_m_addr_shift, memTrace_m_val_shift, - memTrace_m_tag_shift }; + memTrace_m_addr_shift, + memTrace_m_tag_shift, + aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r1_shift, + aluChip_alu_u16_r4_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r3_shift, + avmMini_internal_return_ptr_shift, + avmMini_pc_shift }; }; RefVector get_unshifted() { @@ -450,37 +450,37 @@ class AvmMiniFlavor { }; RefVector get_to_be_shifted() { - return { avmMini_internal_return_ptr, - avmMini_pc, - aluChip_alu_u16_r0, - aluChip_alu_u16_r4, - aluChip_alu_u16_r3, + return { memTrace_m_rw, + memTrace_m_val, + memTrace_m_addr, + memTrace_m_tag, aluChip_alu_u16_r6, - aluChip_alu_u16_r7, - aluChip_alu_u16_r5, - aluChip_alu_u16_r2, aluChip_alu_u16_r1, - memTrace_m_rw, - memTrace_m_addr, - memTrace_m_val, - memTrace_m_tag }; + aluChip_alu_u16_r4, + aluChip_alu_u16_r2, + aluChip_alu_u16_r5, + aluChip_alu_u16_r0, + aluChip_alu_u16_r7, + aluChip_alu_u16_r3, + avmMini_internal_return_ptr, + avmMini_pc }; }; RefVector get_shifted() { - return { avmMini_internal_return_ptr_shift, - avmMini_pc_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r3_shift, + return { memTrace_m_rw_shift, + memTrace_m_val_shift, + memTrace_m_addr_shift, + memTrace_m_tag_shift, aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r2_shift, aluChip_alu_u16_r1_shift, - memTrace_m_rw_shift, - memTrace_m_addr_shift, - memTrace_m_val_shift, - memTrace_m_tag_shift }; + aluChip_alu_u16_r4_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r3_shift, + avmMini_internal_return_ptr_shift, + avmMini_pc_shift }; }; }; @@ -493,20 +493,20 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { avmMini_internal_return_ptr, - avmMini_pc, - aluChip_alu_u16_r0, - aluChip_alu_u16_r4, - aluChip_alu_u16_r3, + return { memTrace_m_rw, + memTrace_m_val, + memTrace_m_addr, + memTrace_m_tag, aluChip_alu_u16_r6, - aluChip_alu_u16_r7, - aluChip_alu_u16_r5, - aluChip_alu_u16_r2, aluChip_alu_u16_r1, - memTrace_m_rw, - memTrace_m_addr, - memTrace_m_val, - memTrace_m_tag }; + aluChip_alu_u16_r4, + aluChip_alu_u16_r2, + aluChip_alu_u16_r5, + aluChip_alu_u16_r0, + aluChip_alu_u16_r7, + aluChip_alu_u16_r3, + avmMini_internal_return_ptr, + avmMini_pc }; }; // The plookup wires that store plookup read data. 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 index 471a9db3c19..bc246a5152d 100644 --- 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 @@ -86,20 +86,20 @@ template struct AvmMiniFullRow { FF avmMini_mem_idx_b{}; FF avmMini_mem_idx_c{}; FF avmMini_last{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_pc_shift{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_u16_r3_shift{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u16_r1_shift{}; FF memTrace_m_rw_shift{}; - FF memTrace_m_addr_shift{}; FF memTrace_m_val_shift{}; + FF memTrace_m_addr_shift{}; FF memTrace_m_tag_shift{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u16_r1_shift{}; + FF aluChip_alu_u16_r4_shift{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r3_shift{}; + FF avmMini_internal_return_ptr_shift{}; + FF avmMini_pc_shift{}; }; class AvmMiniCircuitBuilder { @@ -197,20 +197,20 @@ class AvmMiniCircuitBuilder { polys.avmMini_last[i] = rows[i].avmMini_last; } - polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); - polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); - polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); - polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); - polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); - polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); - polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); - polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); - polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); - polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.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_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.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_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); + polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); + polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); + polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.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; } @@ -248,16 +248,16 @@ class AvmMiniCircuitBuilder { return true; }; - if (!evaluate_relation.template operator()>("avm_mini", - AvmMini_vm::get_relation_label_avm_mini)) { + 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()>( - "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { + if (!evaluate_relation.template operator()>("avm_mini", + AvmMini_vm::get_relation_label_avm_mini)) { return false; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index 423c5c32e4c..602789b8182 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,38 +7,38 @@ namespace proof_system::AvmMini_vm { template struct Alu_chipRow { - FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_op_mul{}; + FF aluChip_alu_ia{}; + FF aluChip_alu_u16_r3{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u16_r1_shift{}; + FF aluChip_alu_u8_r0{}; + FF aluChip_alu_ib{}; + FF aluChip_alu_u16_r7{}; + FF aluChip_alu_u16_r2{}; + FF aluChip_alu_u8_r1{}; + FF aluChip_alu_u128_tag{}; FF aluChip_alu_u16_r6{}; - FF aluChip_alu_u16_r0{}; + FF aluChip_alu_u8_tag{}; + FF aluChip_alu_u16_tag{}; + FF aluChip_alu_ff_tag{}; + FF aluChip_alu_u16_r4_shift{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u32_tag{}; FF aluChip_alu_u16_r1{}; - FF aluChip_alu_u64_r0{}; FF aluChip_alu_cf{}; - FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_u8_r1{}; - FF aluChip_alu_u16_r3_shift{}; - FF aluChip_alu_ff_tag{}; - FF aluChip_alu_u16_r2{}; - FF aluChip_alu_u16_r7{}; FF aluChip_alu_ic{}; - FF aluChip_alu_u16_r3{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u32_tag{}; - FF aluChip_alu_u16_tag{}; - FF aluChip_alu_u128_tag{}; - FF aluChip_alu_u16_r4{}; + FF aluChip_alu_u16_r0{}; FF aluChip_alu_u16_r5_shift{}; FF aluChip_alu_op_sub{}; - FF aluChip_alu_ib{}; - FF aluChip_alu_u16_r5{}; - FF aluChip_alu_ia{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u8_tag{}; FF aluChip_alu_op_add{}; - FF aluChip_alu_op_mul{}; - FF aluChip_alu_u8_r0{}; + FF aluChip_alu_u16_r5{}; + FF aluChip_alu_u16_r4{}; FF aluChip_alu_u64_tag{}; + FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u64_r0{}; + FF aluChip_alu_u16_r3_shift{}; }; inline std::string get_relation_label_alu_chip(int index) @@ -46,6 +46,9 @@ inline std::string get_relation_label_alu_chip(int index) switch (index) { case 6: return "SUBOP_ADDITION_FF"; + + case 17: + return "SUBOP_SUBTRACTION_FF"; } return std::to_string(index); } @@ -54,8 +57,8 @@ template class alu_chipImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, 3, 3, 3, 3, 3, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 5, 4, + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 3, 3, 3, 3, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 6, 6, 8, }; @@ -242,8 +245,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(17); - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_sub) * - (((aluChip_alu_u8_r0 + (aluChip_alu_cf * FF(256))) - aluChip_alu_ic) - aluChip_alu_ib)); + auto tmp = + ((aluChip_alu_ff_tag * aluChip_alu_op_sub) * ((aluChip_alu_ia - aluChip_alu_ib) - aluChip_alu_ic)); tmp *= scaling_factor; std::get<17>(evals) += tmp; } @@ -251,7 +254,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(18); - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_sub) * (aluChip_alu_u8_r0 - aluChip_alu_ia)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_sub) * + (((aluChip_alu_u8_r0 + (aluChip_alu_cf * FF(256))) - aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; std::get<18>(evals) += tmp; } @@ -259,8 +263,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(19); - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_sub) * - (((aluChip_alu_u16_r0 + (aluChip_alu_cf * FF(65536))) - aluChip_alu_ic) - aluChip_alu_ib)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_sub) * (aluChip_alu_u8_r0 - aluChip_alu_ia)); tmp *= scaling_factor; std::get<19>(evals) += tmp; } @@ -268,7 +271,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(20); - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_sub) * (aluChip_alu_u16_r0 - aluChip_alu_ia)); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_sub) * + (((aluChip_alu_u16_r0 + (aluChip_alu_cf * FF(65536))) - aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; std::get<20>(evals) += tmp; } @@ -276,26 +280,34 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(21); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_sub) * (aluChip_alu_u16_r0 - aluChip_alu_ia)); + tmp *= scaling_factor; + std::get<21>(evals) += tmp; + } + // Contribution 22 + { + AvmMini_DECLARE_VIEWS(22); + auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_sub) * ((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + (aluChip_alu_cf * FF(4294967296UL))) - aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<21>(evals) += tmp; + std::get<22>(evals) += tmp; } - // Contribution 22 + // Contribution 23 { - AvmMini_DECLARE_VIEWS(22); + AvmMini_DECLARE_VIEWS(23); auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_sub) * ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<22>(evals) += tmp; + std::get<23>(evals) += tmp; } - // Contribution 23 + // Contribution 24 { - AvmMini_DECLARE_VIEWS(23); + AvmMini_DECLARE_VIEWS(24); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_sub) * ((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -305,11 +317,11 @@ template class alu_chipImpl { aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<23>(evals) += tmp; + std::get<24>(evals) += tmp; } - // Contribution 24 + // Contribution 25 { - AvmMini_DECLARE_VIEWS(24); + AvmMini_DECLARE_VIEWS(25); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_sub) * @@ -317,11 +329,11 @@ template class alu_chipImpl { (aluChip_alu_u16_r3 * FF(281474976710656UL))) - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<24>(evals) += tmp; + std::get<25>(evals) += tmp; } - // Contribution 25 + // Contribution 26 { - AvmMini_DECLARE_VIEWS(25); + AvmMini_DECLARE_VIEWS(26); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_sub) * ((((((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -335,11 +347,11 @@ template class alu_chipImpl { aluChip_alu_ic) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<25>(evals) += tmp; + std::get<26>(evals) += tmp; } - // Contribution 26 + // Contribution 27 { - AvmMini_DECLARE_VIEWS(26); + AvmMini_DECLARE_VIEWS(27); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_sub) * ((((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -351,22 +363,14 @@ template class alu_chipImpl { (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<26>(evals) += tmp; - } - // Contribution 27 - { - AvmMini_DECLARE_VIEWS(27); - - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * - ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) - (aluChip_alu_ia * aluChip_alu_ib))); - tmp *= scaling_factor; std::get<27>(evals) += tmp; } // Contribution 28 { AvmMini_DECLARE_VIEWS(28); - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * + ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; std::get<28>(evals) += tmp; } @@ -374,8 +378,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(29); - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * - ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - (aluChip_alu_ia * aluChip_alu_ib))); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); tmp *= scaling_factor; std::get<29>(evals) += tmp; } @@ -383,7 +386,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(30); - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * + ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; std::get<30>(evals) += tmp; } @@ -391,26 +395,34 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(31); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<31>(evals) += tmp; + } + // Contribution 32 + { + AvmMini_DECLARE_VIEWS(32); + auto tmp = ((aluChip_alu_u32_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_ia * aluChip_alu_ib))); tmp *= scaling_factor; - std::get<31>(evals) += tmp; + std::get<32>(evals) += tmp; } - // Contribution 32 + // Contribution 33 { - AvmMini_DECLARE_VIEWS(32); + AvmMini_DECLARE_VIEWS(33); auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_mul) * ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<32>(evals) += tmp; + std::get<33>(evals) += tmp; } - // Contribution 33 + // Contribution 34 { - AvmMini_DECLARE_VIEWS(33); + AvmMini_DECLARE_VIEWS(34); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_mul) * ((((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -422,11 +434,11 @@ template class alu_chipImpl { (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; - std::get<33>(evals) += tmp; + std::get<34>(evals) += tmp; } - // Contribution 34 + // Contribution 35 { - AvmMini_DECLARE_VIEWS(34); + AvmMini_DECLARE_VIEWS(35); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_mul) * @@ -434,11 +446,11 @@ template class alu_chipImpl { (aluChip_alu_u16_r3 * FF(281474976710656UL))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<34>(evals) += tmp; + std::get<35>(evals) += tmp; } - // Contribution 35 + // Contribution 36 { - AvmMini_DECLARE_VIEWS(35); + AvmMini_DECLARE_VIEWS(36); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * (((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -450,11 +462,11 @@ template class alu_chipImpl { FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<35>(evals) += tmp; + std::get<36>(evals) += tmp; } - // Contribution 36 + // Contribution 37 { - AvmMini_DECLARE_VIEWS(36); + AvmMini_DECLARE_VIEWS(37); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * (((((aluChip_alu_u16_r0_shift + (aluChip_alu_u16_r1_shift * FF(65536))) + @@ -466,11 +478,11 @@ template class alu_chipImpl { FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<36>(evals) += tmp; + std::get<37>(evals) += tmp; } - // Contribution 37 + // Contribution 38 { - AvmMini_DECLARE_VIEWS(37); + AvmMini_DECLARE_VIEWS(38); 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))) + @@ -487,7 +499,7 @@ template class alu_chipImpl { FF(uint256_t{ 0, 0, 1, 0 }))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<37>(evals) += tmp; + std::get<38>(evals) += tmp; } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index 89c03208507..540adee863c 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,67 +7,64 @@ namespace proof_system::AvmMini_vm { template struct Avm_miniRow { - FF avmMini_first{}; FF avmMini_internal_return_ptr{}; - FF avmMini_tag_err{}; - FF avmMini_ib{}; FF avmMini_sel_internal_return{}; - FF avmMini_ic{}; - FF avmMini_sel_jump{}; - FF avmMini_sel_op_sub{}; + FF avmMini_internal_return_ptr_shift{}; + FF avmMini_mem_op_a{}; FF avmMini_rwb{}; + FF avmMini_sel_op_sub{}; + FF avmMini_mem_op_b{}; FF avmMini_rwc{}; + FF avmMini_mem_idx_b{}; + FF avmMini_sel_internal_call{}; + FF avmMini_ic{}; + FF avmMini_tag_err{}; + FF avmMini_mem_op_c{}; + FF avmMini_inv{}; + FF avmMini_sel_op_add{}; + FF avmMini_pc_shift{}; + FF avmMini_sel_jump{}; + FF avmMini_sel_halt{}; FF avmMini_rwa{}; + FF avmMini_ia{}; + FF avmMini_first{}; FF avmMini_sel_op_div{}; FF avmMini_sel_op_mul{}; FF avmMini_op_err{}; - FF avmMini_mem_op_b{}; - FF avmMini_mem_op_c{}; - FF avmMini_sel_halt{}; - FF avmMini_ia{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_sel_internal_call{}; - FF avmMini_sel_op_add{}; - FF avmMini_mem_idx_b{}; - FF avmMini_pc_shift{}; FF avmMini_pc{}; - FF avmMini_inv{}; - FF avmMini_mem_op_a{}; + FF avmMini_ib{}; FF avmMini_mem_idx_a{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { - case 32: - return "RETURN_POINTER_DECREMENT"; - - case 38: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + case 21: + return "SUBOP_DIVISION_ZERO_ERR1"; - case 24: - return "SUBOP_ERROR_RELEVANT_OP"; + case 20: + return "SUBOP_DIVISION_FF"; - case 23: - return "SUBOP_DIVISION_ZERO_ERR2"; + case 19: + return "SUBOP_MULTIPLICATION_FF"; - case 37: + case 36: return "PC_INCREMENT"; - case 20: - return "SUBOP_MULTIPLICATION_FF"; - - case 22: - return "SUBOP_DIVISION_ZERO_ERR1"; + case 37: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - case 26: + case 25: return "RETURN_POINTER_INCREMENT"; - case 21: - return "SUBOP_DIVISION_FF"; + case 31: + return "RETURN_POINTER_DECREMENT"; - case 19: - return "SUBOP_SUBTRACTION_FF"; + case 23: + return "SUBOP_ERROR_RELEVANT_OP"; + + case 22: + return "SUBOP_DIVISION_ZERO_ERR2"; } return std::to_string(index); } @@ -76,8 +73,8 @@ 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, + 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, 4, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, }; @@ -244,7 +241,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(19); - auto tmp = (avmMini_sel_op_sub * ((avmMini_ia - avmMini_ib) - avmMini_ic)); + auto tmp = (avmMini_sel_op_mul * ((avmMini_ia * avmMini_ib) - avmMini_ic)); tmp *= scaling_factor; std::get<19>(evals) += tmp; } @@ -252,7 +249,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(20); - auto tmp = (avmMini_sel_op_mul * ((avmMini_ia * avmMini_ib) - avmMini_ic)); + 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; } @@ -260,7 +257,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(21); - auto tmp = ((avmMini_sel_op_div * (-avmMini_op_err + FF(1))) * ((avmMini_ic * avmMini_ib) - avmMini_ia)); + auto tmp = (avmMini_sel_op_div * (((avmMini_ib * avmMini_inv) - FF(1)) + avmMini_op_err)); tmp *= scaling_factor; std::get<21>(evals) += tmp; } @@ -268,7 +265,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(22); - auto tmp = (avmMini_sel_op_div * (((avmMini_ib * avmMini_inv) - FF(1)) + avmMini_op_err)); + auto tmp = ((avmMini_sel_op_div * avmMini_op_err) * (-avmMini_inv + FF(1))); tmp *= scaling_factor; std::get<22>(evals) += tmp; } @@ -276,7 +273,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(23); - auto tmp = ((avmMini_sel_op_div * avmMini_op_err) * (-avmMini_inv + FF(1))); + auto tmp = (avmMini_op_err * (avmMini_sel_op_div - FF(1))); tmp *= scaling_factor; std::get<23>(evals) += tmp; } @@ -284,7 +281,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(24); - auto tmp = (avmMini_op_err * (avmMini_sel_op_div - FF(1))); + auto tmp = (avmMini_sel_jump * (avmMini_pc_shift - avmMini_ia)); tmp *= scaling_factor; std::get<24>(evals) += tmp; } @@ -292,7 +289,8 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(25); - auto tmp = (avmMini_sel_jump * (avmMini_pc_shift - avmMini_ia)); + 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; } @@ -300,8 +298,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(26); - auto tmp = (avmMini_sel_internal_call * - (avmMini_internal_return_ptr_shift - (avmMini_internal_return_ptr + FF(1)))); + auto tmp = (avmMini_sel_internal_call * (avmMini_internal_return_ptr - avmMini_mem_idx_b)); tmp *= scaling_factor; std::get<26>(evals) += tmp; } @@ -309,7 +306,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(27); - auto tmp = (avmMini_sel_internal_call * (avmMini_internal_return_ptr - avmMini_mem_idx_b)); + auto tmp = (avmMini_sel_internal_call * (avmMini_pc_shift - avmMini_ia)); tmp *= scaling_factor; std::get<27>(evals) += tmp; } @@ -317,7 +314,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(28); - auto tmp = (avmMini_sel_internal_call * (avmMini_pc_shift - avmMini_ia)); + auto tmp = (avmMini_sel_internal_call * ((avmMini_pc + FF(1)) - avmMini_ib)); tmp *= scaling_factor; std::get<28>(evals) += tmp; } @@ -325,7 +322,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(29); - auto tmp = (avmMini_sel_internal_call * ((avmMini_pc + FF(1)) - avmMini_ib)); + auto tmp = (avmMini_sel_internal_call * (avmMini_rwb - FF(1))); tmp *= scaling_factor; std::get<29>(evals) += tmp; } @@ -333,7 +330,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(30); - auto tmp = (avmMini_sel_internal_call * (avmMini_rwb - FF(1))); + auto tmp = (avmMini_sel_internal_call * (avmMini_mem_op_b - FF(1))); tmp *= scaling_factor; std::get<30>(evals) += tmp; } @@ -341,7 +338,8 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(31); - auto tmp = (avmMini_sel_internal_call * (avmMini_mem_op_b - FF(1))); + 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; } @@ -349,8 +347,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(32); - auto tmp = (avmMini_sel_internal_return * - (avmMini_internal_return_ptr_shift - (avmMini_internal_return_ptr - FF(1)))); + auto tmp = (avmMini_sel_internal_return * ((avmMini_internal_return_ptr - FF(1)) - avmMini_mem_idx_a)); tmp *= scaling_factor; std::get<32>(evals) += tmp; } @@ -358,7 +355,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(33); - auto tmp = (avmMini_sel_internal_return * ((avmMini_internal_return_ptr - FF(1)) - avmMini_mem_idx_a)); + auto tmp = (avmMini_sel_internal_return * (avmMini_pc_shift - avmMini_ia)); tmp *= scaling_factor; std::get<33>(evals) += tmp; } @@ -366,7 +363,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(34); - auto tmp = (avmMini_sel_internal_return * (avmMini_pc_shift - avmMini_ia)); + auto tmp = (avmMini_sel_internal_return * avmMini_rwa); tmp *= scaling_factor; std::get<34>(evals) += tmp; } @@ -374,7 +371,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(35); - auto tmp = (avmMini_sel_internal_return * avmMini_rwa); + auto tmp = (avmMini_sel_internal_return * (avmMini_mem_op_a - FF(1))); tmp *= scaling_factor; std::get<35>(evals) += tmp; } @@ -382,30 +379,22 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(36); - auto tmp = (avmMini_sel_internal_return * (avmMini_mem_op_a - FF(1))); - tmp *= scaling_factor; - std::get<36>(evals) += tmp; - } - // Contribution 37 - { - AvmMini_DECLARE_VIEWS(37); - 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_pc_shift - (avmMini_pc + FF(1)))); tmp *= scaling_factor; - std::get<37>(evals) += tmp; + std::get<36>(evals) += tmp; } - // Contribution 38 + // Contribution 37 { - AvmMini_DECLARE_VIEWS(38); + 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<38>(evals) += tmp; + std::get<37>(evals) += tmp; } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index c596399689a..37df4bbab68 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -68,17 +68,17 @@ [[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 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); \ - [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ - [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ - [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_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_r6_shift = View(new_term.aluChip_alu_u16_r6_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_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_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/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 4b9910b0fad..4de2e1cc3b6 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,41 +7,41 @@ namespace proof_system::AvmMini_vm { template struct Mem_traceRow { - FF memTrace_m_rw_shift{}; - FF memTrace_m_addr_shift{}; - FF memTrace_m_val{}; - FF memTrace_m_val_shift{}; - FF memTrace_m_in_tag{}; - FF memTrace_m_one_min_inv{}; + FF memTrace_m_rw{}; + FF memTrace_m_tag_err{}; FF memTrace_m_addr{}; FF memTrace_m_last{}; - FF memTrace_m_lastAccess{}; + FF memTrace_m_rw_shift{}; FF memTrace_m_tag{}; + FF memTrace_m_one_min_inv{}; + FF memTrace_m_val_shift{}; + FF memTrace_m_val{}; + FF memTrace_m_addr_shift{}; FF memTrace_m_tag_shift{}; - FF memTrace_m_rw{}; - FF memTrace_m_tag_err{}; + FF memTrace_m_in_tag{}; + FF memTrace_m_lastAccess{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { - case 7: - return "MEM_ZERO_INIT"; - - case 9: - return "MEM_IN_TAG_CONSISTENCY_2"; - - case 6: - return "MEM_READ_WRITE_TAG_CONSISTENCY"; - case 5: return "MEM_READ_WRITE_VAL_CONSISTENCY"; + case 8: + return "MEM_IN_TAG_CONSISTENCY_1"; + case 4: return "MEM_LAST_ACCESS_DELIMITER"; - case 8: - return "MEM_IN_TAG_CONSISTENCY_1"; + case 9: + return "MEM_IN_TAG_CONSISTENCY_2"; + + case 7: + return "MEM_ZERO_INIT"; + + case 6: + return "MEM_READ_WRITE_TAG_CONSISTENCY"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp index bf41b4826b9..708ecbe1f45 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp @@ -154,4 +154,138 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag, ui return c; } +/** + * @brief Build Alu trace and compute the result of a subtraction of type defined by in_tag. + * + * @param a Left operand of the subtraction + * @param b Right operand of the subtraction + * @param in_tag Instruction tag defining the number of bits on which the subtracttion applies. + * It is assumed that the caller never uses the type u0. + * @param clk Clock referring to the operation in the main trace. + * + * @return FF The result of the subtraction casted in a finite field element + */ +FF AvmMiniAluTraceBuilder::sub(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t const clk) +{ + FF c{}; + bool carry = false; + uint8_t alu_u8_r0{}; + std::array alu_u16_reg{}; + + switch (in_tag) { + case AvmMemoryTag::ff: + c = a - b; + case AvmMemoryTag::u8: { + uint8_t a_u8 = static_cast(uint256_t(a).data[0]); + uint8_t b_u8 = static_cast(uint256_t(b).data[0]); + uint8_t c_u8 = a_u8 - b_u8; + c = FF{ uint256_t{ c_u8 } }; + + // We show that c_u8 + b_u8 == a_u8 and use "addition relation" + // where we swap a_u8 and c_u8. + // c_u8 + b_u8 >= 2^8 <==> a_u8 < c_u8 + if (a_u8 < c_u8) { + carry = true; + } + + alu_u8_r0 = a_u8; + break; + } + case AvmMemoryTag::u16: { + uint16_t a_u16 = static_cast(uint256_t(a).data[0]); + uint16_t b_u16 = static_cast(uint256_t(b).data[0]); + uint16_t c_u16 = a_u16 - b_u16; + c = FF{ uint256_t{ c_u16 } }; + + // We show that c_u16 + b_u16 == a_u16 and use "addition relation" + // where we swap a_u16 and c_u16. + // c_u16 + b_u16 >= 2^16 <==> a_u16 < c_u16 + if (a_u16 < c_u16) { + carry = true; + } + + alu_u16_reg.at(0) = a_u16; + break; + } + case AvmMemoryTag::u32: { + uint32_t a_u32 = static_cast(uint256_t(a).data[0]); + uint32_t b_u32 = static_cast(uint256_t(b).data[0]); + uint32_t c_u32 = a_u32 - b_u32; + c = FF{ uint256_t{ c_u32 } }; + + // We show that c_u32 + b_u32 == a_u32 and use "addition relation" + // where we swap a_u32 and c_u32. + // c_u32 + b_u32 >= 2^32 <==> a_u32 < c_u32 + if (a_u32 < c_u32) { + carry = true; + } + + alu_u16_reg.at(0) = static_cast(a_u32); + alu_u16_reg.at(1) = static_cast(a_u32 >> 16); + break; + } + case AvmMemoryTag::u64: { + uint64_t a_u64 = static_cast(uint256_t(a).data[0]); + uint64_t b_u64 = static_cast(uint256_t(b).data[0]); + uint64_t c_u64 = a_u64 - b_u64; + c = FF{ uint256_t{ c_u64 } }; + + // We show that c_u64 + b_u64 == a_u64 and use "addition relation" + // where we swap a_u64 and c_u64. + // c_u64 + b_u64 >= 2^64 <==> a_u64 < c_u64 + if (a_u64 < c_u64) { + carry = true; + } + + uint64_t a_trunc_64 = a_u64; + for (size_t i = 0; i < 4; i++) { + alu_u16_reg.at(i) = static_cast(a_trunc_64); + a_trunc_64 >>= 16; + } + break; + } + case AvmMemoryTag::u128: { + auto a_u128 = uint128_t(a); + auto b_u128 = uint128_t(b); + uint128_t c_u128 = a_u128 - b_u128; + c = FF{ uint256_t::from_uint128(c_u128) }; + + // We show that c_u128 + b_u128 == a_u128 and use "addition relation" + // where we swap a_u128 and c_u128. + // c_u128 + b_u128 >= 2^128 <==> a_u128 < c_u128 + if (a_u128 < c_u128) { + carry = true; + } + + uint128_t a_trunc_128 = a_u128; + for (size_t i = 0; i < 8; i++) { + alu_u16_reg.at(i) = static_cast(a_trunc_128); + a_trunc_128 >>= 16; + } + break; + } + case AvmMemoryTag::u0: // Unsupported as instruction tag + return FF{ 0 }; + } + + alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ + .alu_clk = clk, + .alu_op_sub = true, + .alu_ff_tag = in_tag == AvmMemoryTag::ff, + .alu_u8_tag = in_tag == AvmMemoryTag::u8, + .alu_u16_tag = in_tag == AvmMemoryTag::u16, + .alu_u32_tag = in_tag == AvmMemoryTag::u32, + .alu_u64_tag = in_tag == AvmMemoryTag::u64, + .alu_u128_tag = in_tag == AvmMemoryTag::u128, + .alu_ia = a, + .alu_ib = b, + .alu_ic = c, + .alu_cf = carry, + .alu_u8_r0 = alu_u8_r0, + .alu_u16_reg = alu_u16_reg, + }); + + return c; +} + } // namespace avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp index aa5a5684d47..977e51949f0 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp @@ -11,6 +11,7 @@ class AvmMiniAluTraceBuilder { uint32_t alu_clk{}; bool alu_op_add = false; + bool alu_op_sub = false; bool alu_ff_tag = false; bool alu_u8_tag = false; @@ -35,6 +36,7 @@ class AvmMiniAluTraceBuilder { std::vector finalize(); FF add(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t clk); + FF sub(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t clk); private: std::vector alu_trace; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp index 3f012341a4b..fc840867c0a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp @@ -95,9 +95,9 @@ void AvmMiniTraceBuilder::sub(uint32_t a_offset, uint32_t b_offset, uint32_t dst bool tag_match = read_a.tag_match && read_b.tag_match; // a - b = c - FF a = read_a.val; - FF b = read_b.val; - FF c = a - b; + FF a = tag_match ? read_a.val : FF(0); + FF b = tag_match ? read_b.val : FF(0); + FF c = alu_trace_builder.sub(a, b, in_tag, clk); // Write into memory value c from intermediate register ic. mem_trace_builder.write_into_memory(clk, IntermRegister::ic, dst_offset, c, in_tag); @@ -109,9 +109,9 @@ void AvmMiniTraceBuilder::sub(uint32_t a_offset, uint32_t b_offset, uint32_t dst .avmMini_sel_op_sub = FF(1), .avmMini_in_tag = FF(static_cast(in_tag)), .avmMini_tag_err = FF(static_cast(!tag_match)), - .avmMini_ia = tag_match ? a : FF(0), - .avmMini_ib = tag_match ? b : FF(0), - .avmMini_ic = tag_match ? c : FF(0), + .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), @@ -628,6 +628,7 @@ std::vector AvmMiniTraceBuilder::finalize() dest.aluChip_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_ff_tag = FF(static_cast(src.alu_ff_tag)); dest.aluChip_alu_u8_tag = FF(static_cast(src.alu_u8_tag)); diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index 318243db36b..7a7dd926625 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -637,7 +637,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, subtraction) auto trace = trace_builder.finalize(); auto select_row = [](Row r) { return r.avmMini_sel_op_sub == FF(1); }; - mutate_ic_in_trace(trace, std::move(select_row), FF(-9)); + mutate_ic_in_trace(trace, std::move(select_row), FF(-9), true); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_SUBTRACTION_FF"); } From 74e87148a094b13ad753cda5ed0747917d5765f5 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Thu, 11 Jan 2024 09:51:21 +0000 Subject: [PATCH 15/28] 3738 - add unit tests for subtraction and swap u128 addition unit tests (carry vs standard addition) --- .../vm/avm_trace/AvmMini_trace.cpp | 2 +- .../vm/tests/AvmMini_arithmetic.test.cpp | 406 ++++++++++++++++-- 2 files changed, 364 insertions(+), 44 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp index fc840867c0a..411a335dd19 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp @@ -77,7 +77,7 @@ void AvmMiniTraceBuilder::add(uint32_t a_offset, uint32_t b_offset, uint32_t dst }); }; -/** TODO: Implement for non finite field types +/** * @brief Subtraction with direct memory access. * * @param a_offset An index in memory pointing to the first operand of the subtraction. diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index 7a7dd926625..feb58ee9c97 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -5,6 +5,41 @@ using namespace numeric; namespace { +void common_validate_arithmetic_op(Row const& main_row, + Row const& alu_row, + FF const& a, + FF const& b, + FF const& c, + FF const& addr_a, + FF const& addr_b, + FF const& addr_c, + 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)); + + // 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)); + + // Check the instruction tag + EXPECT_EQ(main_row.avmMini_in_tag, FF(static_cast(tag))); + + // Check that intermediate rgiesters 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); +} + Row common_validate_add(std::vector const& trace, FF const& a, FF const& b, @@ -17,36 +52,48 @@ Row common_validate_add(std::vector const& trace, // 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); }); - // Check that the correct result is stored at the expected memory location. + // 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; }); + + // Check that both rows were found EXPECT_TRUE(row != trace.end()); - 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_TRUE(alu_row != trace.end()); - // Check that ia and ib registers are 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->avmMini_ib, b); - EXPECT_EQ(row->avmMini_mem_idx_b, addr_b); - EXPECT_EQ(row->avmMini_mem_op_b, FF(1)); - EXPECT_EQ(row->avmMini_rwb, FF(0)); - - // Check instruction tag and add selector are set. - EXPECT_EQ(row->avmMini_in_tag, FF(static_cast(tag))); + 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)); - // Check that Alu trace is as expected. + return *alu_row; +} + +Row common_validate_sub(std::vector const& trace, + FF const& a, + FF const& b, + FF const& c, + FF const& addr_a, + FF const& addr_b, + FF const& addr_c, + 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); }); + + // 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; }); + // Check that both rows were found + EXPECT_TRUE(row != trace.end()); EXPECT_TRUE(alu_row != trace.end()); - EXPECT_EQ(alu_row->aluChip_alu_op_add, FF(1)); - EXPECT_EQ(alu_row->aluChip_alu_ia, a); - EXPECT_EQ(alu_row->aluChip_alu_ib, b); - EXPECT_EQ(alu_row->aluChip_alu_ic, c); + + 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_sub, FF(1)); + EXPECT_EQ(alu_row->aluChip_alu_op_sub, FF(1)); return *alu_row; } @@ -120,6 +167,8 @@ 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(41)); validate_trace_proof(std::move(trace)); } @@ -134,15 +183,11 @@ TEST_F(AvmMiniArithmeticTestsFF, subtraction) trace_builder.return_op(0, 3); 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 alu_row = common_validate_sub(trace, FF(17), FF(8), FF(9), FF(2), FF(0), FF(1), AvmMemoryTag::ff); - // Check that the correct result is stored at the expected memory location. - EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avmMini_ic, FF(9)); - EXPECT_EQ(row->avmMini_mem_idx_c, FF(1)); - EXPECT_EQ(row->avmMini_mem_op_c, FF(1)); - EXPECT_EQ(row->avmMini_rwc, FF(1)); + 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(17)); validate_trace_proof(std::move(trace)); } @@ -358,6 +403,49 @@ TEST_F(AvmMiniArithmeticTestsU8, additionCarry) validate_trace_proof(std::move(trace)); } +// Test on basic subtraction over u8 type. +TEST_F(AvmMiniArithmeticTestsU8, subtraction) +{ + // trace_builder + trace_builder.set(162, 0, AvmMemoryTag::u8); + trace_builder.set(29, 1, AvmMemoryTag::u8); + + // Memory layout: [162,29,0,0,0,....] + trace_builder.sub(0, 1, 2, AvmMemoryTag::u8); // [162,29,133,0,0,....] + trace_builder.return_op(2, 1); + auto trace = trace_builder.finalize(); + + 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(162)); // First operand (a) for subtraction + + 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) +{ + // trace_builder + trace_builder.set(5, 0, AvmMemoryTag::u8); + trace_builder.set(29, 1, AvmMemoryTag::u8); + + // Memory layout: [5,29,0,0,0,....] + trace_builder.sub(0, 1, 2, AvmMemoryTag::u8); // [5,29,232,0,0,....] + trace_builder.return_op(2, 1); + auto trace = trace_builder.finalize(); + + 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(5)); // First operand (a) for subtraction + + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * Positive Tests - U16 ******************************************************************************/ @@ -404,6 +492,49 @@ TEST_F(AvmMiniArithmeticTestsU16, additionCarry) validate_trace_proof(std::move(trace)); } +// Test on basic subtraction over u16 type. +TEST_F(AvmMiniArithmeticTestsU16, subtraction) +{ + // trace_builder + trace_builder.set(1775, 119, AvmMemoryTag::u16); + trace_builder.set(33005, 546, AvmMemoryTag::u16); + + trace_builder.sub(546, 119, 5, AvmMemoryTag::u16); + trace_builder.return_op(5, 1); + auto trace = trace_builder.finalize(); + + 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_u16_r0, FF(33005)); // First operand (a) for subtraction + + 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) +{ + // trace_builder + trace_builder.set(UINT16_MAX - 982, 0, AvmMemoryTag::u16); + trace_builder.set(1000, 1, AvmMemoryTag::u16); + + trace_builder.sub(1, 0, 0, AvmMemoryTag::u16); + trace_builder.return_op(0, 1); + auto trace = trace_builder.finalize(); + + 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_u16_r0, FF(1000)); // First operand (a) for subtraction + + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * Positive Tests - U32 ******************************************************************************/ @@ -452,6 +583,55 @@ TEST_F(AvmMiniArithmeticTestsU32, additionCarry) validate_trace_proof(std::move(trace)); } +// Test on basic subtraction over u32 type. +TEST_F(AvmMiniArithmeticTestsU32, subtraction) +{ + // trace_builder + trace_builder.set(1345678991, 8, AvmMemoryTag::u32); + trace_builder.set(1234567891, 9, AvmMemoryTag::u32); + + trace_builder.sub(8, 9, 0, AvmMemoryTag::u32); + trace_builder.return_op(0, 1); + auto trace = trace_builder.finalize(); + + 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)); + + // First operand (a) for subtraction decomposed in u16 registers + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(1345678991 & UINT16_MAX)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(1345678991 >> 16)); + + 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) +{ + // trace_builder + trace_builder.set(UINT32_MAX - 99, 8, AvmMemoryTag::u32); + trace_builder.set(3210987654, 9, AvmMemoryTag::u32); + + trace_builder.sub(9, 8, 0, AvmMemoryTag::u32); + trace_builder.return_op(0, 1); + auto trace = trace_builder.finalize(); + + 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)); + + // First operand (a) for subtraction decomposed in u16 registers + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(3210987654LLU & UINT16_MAX)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(3210987654LLU >> 16)); + + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * Positive Tests - U64 ******************************************************************************/ @@ -510,12 +690,109 @@ TEST_F(AvmMiniArithmeticTestsU64, additionCarry) validate_trace_proof(std::move(trace)); } +// Test on basic subtraction over u64 type. +TEST_F(AvmMiniArithmeticTestsU64, subtraction) +{ + uint64_t const a = 9876543210123456789LLU; // HEX: 891087B8B0347115 + uint64_t const b = 9866543210123456789LLU; + uint64_t const c = 10000000000000000LLU; + + // trace_builder + trace_builder.set(a, 8, AvmMemoryTag::u64); + trace_builder.set(b, 9, AvmMemoryTag::u64); + + trace_builder.sub(8, 9, 9, AvmMemoryTag::u64); + trace_builder.return_op(9, 1); + auto trace = trace_builder.finalize(); + + 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)); + + // First operand (891087B8B0347115) for subtraction decomposed in u16 registers + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0X7115)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0XB034)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0X87B8)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0X8910)); + + 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) +{ + uint64_t const a = UINT64_MAX - 77LLU; + uint64_t const b = UINT64_MAX - 2LLU; + uint64_t const c = UINT64_MAX - 74; + + // trace_builder + trace_builder.set(a, 0, AvmMemoryTag::u64); + trace_builder.set(b, 1, AvmMemoryTag::u64); + + trace_builder.sub(0, 1, 0, AvmMemoryTag::u64); + trace_builder.return_op(0, 1); + auto trace = trace_builder.finalize(); + + 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)); + + // First operand (a) for subtraction decomposed in u16 registers + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(UINT16_MAX - 77)); + 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)); + + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * Positive Tests - U128 ******************************************************************************/ // Test on basic addition over u128 type. TEST_F(AvmMiniArithmeticTestsU128, addition) +{ + uint128_t const a = (uint128_t(0x5555222233334444LLU) << 64) + uint128_t(0x88889999AAAABBBBLLU); + uint128_t const b = (uint128_t(0x3333222233331111LLU) << 64) + uint128_t(0x5555111155553333LLU); + uint128_t const c = (uint128_t(0x8888444466665555LLU) << 64) + uint128_t(0xDDDDAAAAFFFFEEEELLU); + + // trace_builder + trace_builder.set(a, 8, AvmMemoryTag::u128); + trace_builder.set(b, 9, AvmMemoryTag::u128); + + trace_builder.add(8, 9, 9, AvmMemoryTag::u128); + trace_builder.return_op(9, 1); + auto trace = trace_builder.finalize(); + + auto alu_row = common_validate_add(trace, + FF(uint256_t::from_uint128(a)), + FF(uint256_t::from_uint128(b)), + FF(uint256_t::from_uint128(c)), + FF(8), + FF(9), + 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_u16_r0, FF(0xEEEE)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0xFFFF)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0xAAAA)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0xDDDD)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(0x5555)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(0x6666)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(0x4444)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r7, FF(0x8888)); + + validate_trace_proof(std::move(trace)); +} + +// Test on basic addition over u128 type with carry. +TEST_F(AvmMiniArithmeticTestsU128, 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); @@ -553,22 +830,63 @@ TEST_F(AvmMiniArithmeticTestsU128, addition) validate_trace_proof(std::move(trace)); } -// Test on basic addition over u128 type with carry. -TEST_F(AvmMiniArithmeticTestsU128, additionCarry) +// Test on basic subtraction over u128 type. +TEST_F(AvmMiniArithmeticTestsU128, 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); + uint128_t const c = 36771555; // 72948899 - 36177344 + + // trace_builder + trace_builder.set(a, 8, AvmMemoryTag::u128); + trace_builder.set(b, 9, AvmMemoryTag::u128); + + trace_builder.sub(8, 9, 9, AvmMemoryTag::u128); + trace_builder.return_op(9, 1); + auto trace = trace_builder.finalize(); + + auto alu_row = common_validate_sub(trace, + FF(uint256_t::from_uint128(a)), + FF(uint256_t::from_uint128(b)), + FF(uint256_t::from_uint128(c)), + FF(8), + FF(9), + FF(9), + AvmMemoryTag::u128); + + EXPECT_EQ(alu_row.aluChip_alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); + + // First operand (a) for subtraction decomposed in u16 registers + // 2^32 - 1 - 36177344 = 4258789951 == 0xFDD7FA3F + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0xFA3F)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0xFDD7)); + 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.aluChip_alu_u16_r7, FF(0xFFFF)); + + validate_trace_proof(std::move(trace)); +} + +// Test on basic subtraction over u128 type with carry. +TEST_F(AvmMiniArithmeticTestsU128, subtractionCarry) { uint128_t const a = (uint128_t(0x5555222233334444LLU) << 64) + uint128_t(0x88889999AAAABBBBLLU); uint128_t const b = (uint128_t(0x3333222233331111LLU) << 64) + uint128_t(0x5555111155553333LLU); - uint128_t const c = (uint128_t(0x8888444466665555LLU) << 64) + uint128_t(0xDDDDAAAAFFFFEEEELLU); + uint128_t const c = (uint128_t(0x2222000000003333LLU) << 64) + uint128_t(0x3333888855558888LLU); // trace_builder trace_builder.set(a, 8, AvmMemoryTag::u128); trace_builder.set(b, 9, AvmMemoryTag::u128); - trace_builder.add(8, 9, 9, AvmMemoryTag::u128); + trace_builder.sub(8, 9, 9, AvmMemoryTag::u128); trace_builder.return_op(9, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_add(trace, + auto alu_row = common_validate_sub(trace, FF(uint256_t::from_uint128(a)), FF(uint256_t::from_uint128(b)), FF(uint256_t::from_uint128(c)), @@ -579,14 +897,16 @@ TEST_F(AvmMiniArithmeticTestsU128, additionCarry) 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_u16_r0, FF(0xEEEE)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0xFFFF)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0xAAAA)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0xDDDD)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(0x5555)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(0x6666)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(0x4444)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r7, FF(0x8888)); + + // First operand (a) for subtraction decomposed in u16 registers + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0xBBBB)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0xAAAA)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0x9999)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0x8888)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(0x4444)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(0x3333)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(0x2222)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r7, FF(0x5555)); validate_trace_proof(std::move(trace)); } From 8e4f29988e5adcbf424b5a45916e44ad7b3fcac9 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Thu, 11 Jan 2024 12:58:52 +0000 Subject: [PATCH 16/28] 3738 - add witness generation for multiplication with types u8, u16, u32, u64 --- barretenberg/cpp/pil/avm/alu_chip.pil | 4 + barretenberg/cpp/pil/avm/avm_mini.pil | 4 - .../flavor/generated/AvmMini_flavor.hpp | 105 ++++++-------- .../generated/AvmMini_circuit_builder.hpp | 48 +++---- .../relations/generated/AvmMini/alu_chip.hpp | 122 +++++++++-------- .../relations/generated/AvmMini/avm_mini.hpp | 128 ++++++++---------- .../generated/AvmMini/declare_views.hpp | 20 +-- .../relations/generated/AvmMini/mem_trace.hpp | 34 ++--- .../vm/avm_trace/AvmMini_alu_trace.cpp | 113 +++++++++++++++- .../vm/avm_trace/AvmMini_alu_trace.hpp | 3 + .../vm/avm_trace/AvmMini_helper.cpp | 6 + .../vm/avm_trace/AvmMini_trace.cpp | 16 ++- .../vm/tests/AvmMini_arithmetic.test.cpp | 13 +- 13 files changed, 362 insertions(+), 254 deletions(-) diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil index 8a95d3ad454..c3eaa6f5fc2 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -157,6 +157,10 @@ namespace aluChip(256); // ========= MULTIPLICATION Operation Constraints =============================== + // ff multiplication + #[SUBOP_MULTIPLICATION_FF] + alu_ff_tag * alu_op_mul * (alu_ia * alu_ib - alu_ic) = 0; + // We need 2k bits to express the product (a*b) over the integer, i.e., for type uk // we express the product as sum_k (u8 is an exception as we need 8-bit registers) diff --git a/barretenberg/cpp/pil/avm/avm_mini.pil b/barretenberg/cpp/pil/avm/avm_mini.pil index ad9374dcc46..26268fe25cd 100644 --- a/barretenberg/cpp/pil/avm/avm_mini.pil +++ b/barretenberg/cpp/pil/avm/avm_mini.pil @@ -103,10 +103,6 @@ namespace avmMini(256); tag_err * ib = 0; tag_err * ic = 0; - // Relation for multiplication over the finite field - #[SUBOP_MULTIPLICATION_FF] - sel_op_mul * (ia * ib - ic) = 0; - // Relation for division over the finite field // If tag_err == 1 in a division, then ib == 0 and op_err == 1. #[SUBOP_DIVISION_FF] diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index 7bcf828cfa0..5b97550ac3a 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -43,7 +43,7 @@ class AvmMiniFlavor { // the unshifted and one for the shifted static constexpr size_t NUM_ALL_ENTITIES = 80; - using Relations = std::tuple, AvmMini_vm::alu_chip, AvmMini_vm::avm_mini>; + using Relations = std::tuple, AvmMini_vm::alu_chip, AvmMini_vm::mem_trace>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -281,20 +281,20 @@ class AvmMiniFlavor { 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, + avmMini_pc_shift, + avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r7_shift, aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r1_shift, + aluChip_alu_u16_r3_shift, aluChip_alu_u16_r4_shift, aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r1_shift, aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r3_shift, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift) + memTrace_m_addr_shift, + memTrace_m_val_shift, + memTrace_m_tag_shift, + memTrace_m_rw_shift) RefVector get_wires() { @@ -364,20 +364,20 @@ class AvmMiniFlavor { 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, + avmMini_pc_shift, + avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r7_shift, aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r1_shift, + aluChip_alu_u16_r3_shift, aluChip_alu_u16_r4_shift, aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r1_shift, aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r3_shift, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift }; + memTrace_m_addr_shift, + memTrace_m_val_shift, + memTrace_m_tag_shift, + memTrace_m_rw_shift }; }; RefVector get_unshifted() { @@ -450,37 +450,23 @@ class AvmMiniFlavor { }; RefVector get_to_be_shifted() { - return { memTrace_m_rw, - memTrace_m_val, - memTrace_m_addr, - memTrace_m_tag, - aluChip_alu_u16_r6, - aluChip_alu_u16_r1, - aluChip_alu_u16_r4, - aluChip_alu_u16_r2, - aluChip_alu_u16_r5, - aluChip_alu_u16_r0, - aluChip_alu_u16_r7, - aluChip_alu_u16_r3, - avmMini_internal_return_ptr, - avmMini_pc }; + return { avmMini_pc, avmMini_internal_return_ptr, + aluChip_alu_u16_r0, aluChip_alu_u16_r7, + aluChip_alu_u16_r6, aluChip_alu_u16_r3, + aluChip_alu_u16_r4, aluChip_alu_u16_r2, + aluChip_alu_u16_r1, aluChip_alu_u16_r5, + memTrace_m_addr, memTrace_m_val, + memTrace_m_tag, memTrace_m_rw }; }; RefVector get_shifted() { - return { memTrace_m_rw_shift, - memTrace_m_val_shift, - memTrace_m_addr_shift, - memTrace_m_tag_shift, - aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r3_shift, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift }; + return { avmMini_pc_shift, avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r6_shift, aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r4_shift, aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r1_shift, aluChip_alu_u16_r5_shift, + memTrace_m_addr_shift, memTrace_m_val_shift, + memTrace_m_tag_shift, memTrace_m_rw_shift }; }; }; @@ -493,20 +479,13 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { memTrace_m_rw, - memTrace_m_val, - memTrace_m_addr, - memTrace_m_tag, - aluChip_alu_u16_r6, - aluChip_alu_u16_r1, - aluChip_alu_u16_r4, - aluChip_alu_u16_r2, - aluChip_alu_u16_r5, - aluChip_alu_u16_r0, - aluChip_alu_u16_r7, - aluChip_alu_u16_r3, - avmMini_internal_return_ptr, - avmMini_pc }; + return { avmMini_pc, avmMini_internal_return_ptr, + aluChip_alu_u16_r0, aluChip_alu_u16_r7, + aluChip_alu_u16_r6, aluChip_alu_u16_r3, + aluChip_alu_u16_r4, aluChip_alu_u16_r2, + aluChip_alu_u16_r1, aluChip_alu_u16_r5, + memTrace_m_addr, memTrace_m_val, + memTrace_m_tag, memTrace_m_rw }; }; // The plookup wires that store plookup read data. 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 index bc246a5152d..48a77acbb64 100644 --- 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 @@ -86,20 +86,20 @@ template struct AvmMiniFullRow { 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 avmMini_pc_shift{}; + FF avmMini_internal_return_ptr_shift{}; + FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_u16_r7_shift{}; FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r1_shift{}; + FF aluChip_alu_u16_r3_shift{}; FF aluChip_alu_u16_r4_shift{}; FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r1_shift{}; FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r3_shift{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_pc_shift{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_val_shift{}; + FF memTrace_m_tag_shift{}; + FF memTrace_m_rw_shift{}; }; class AvmMiniCircuitBuilder { @@ -197,20 +197,20 @@ class AvmMiniCircuitBuilder { 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.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); + polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); + polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); + polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); - polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); + polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); + polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); - polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); - polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.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()); + polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); + polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); + polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); + polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); return polys; } @@ -248,16 +248,16 @@ class AvmMiniCircuitBuilder { return true; }; - if (!evaluate_relation.template operator()>( - "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { + if (!evaluate_relation.template operator()>("avm_mini", + AvmMini_vm::get_relation_label_avm_mini)) { 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)) { + if (!evaluate_relation.template operator()>( + "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { return false; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index 602789b8182..13c95170b5f 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,48 +7,51 @@ namespace proof_system::AvmMini_vm { template struct Alu_chipRow { - FF aluChip_alu_op_mul{}; - FF aluChip_alu_ia{}; - FF aluChip_alu_u16_r3{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r1_shift{}; + FF aluChip_alu_op_sub{}; FF aluChip_alu_u8_r0{}; - FF aluChip_alu_ib{}; - FF aluChip_alu_u16_r7{}; - FF aluChip_alu_u16_r2{}; - FF aluChip_alu_u8_r1{}; + FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_cf{}; + FF aluChip_alu_ic{}; + FF aluChip_alu_u16_r7_shift{}; FF aluChip_alu_u128_tag{}; + FF aluChip_alu_u16_r1{}; + FF aluChip_alu_u16_r4{}; FF aluChip_alu_u16_r6{}; - FF aluChip_alu_u8_tag{}; - FF aluChip_alu_u16_tag{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_op_add{}; + FF aluChip_alu_u64_tag{}; FF aluChip_alu_ff_tag{}; + FF aluChip_alu_u16_r3{}; + FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_u16_r7{}; + FF aluChip_alu_u16_tag{}; + FF aluChip_alu_op_mul{}; + FF aluChip_alu_u16_r5{}; + FF aluChip_alu_u8_tag{}; + FF aluChip_alu_u32_tag{}; + FF aluChip_alu_ia{}; + FF aluChip_alu_u64_r0{}; FF aluChip_alu_u16_r4_shift{}; FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u32_tag{}; - FF aluChip_alu_u16_r1{}; - FF aluChip_alu_cf{}; - FF aluChip_alu_ic{}; - FF aluChip_alu_u16_r0{}; + FF aluChip_alu_u16_r2{}; + FF aluChip_alu_ib{}; + FF aluChip_alu_u8_r1{}; + FF aluChip_alu_u16_r1_shift{}; FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_op_sub{}; - FF aluChip_alu_op_add{}; - FF aluChip_alu_u16_r5{}; - FF aluChip_alu_u16_r4{}; - FF aluChip_alu_u64_tag{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u64_r0{}; - FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_u16_r0{}; }; inline std::string get_relation_label_alu_chip(int index) { switch (index) { - case 6: - return "SUBOP_ADDITION_FF"; - case 17: return "SUBOP_SUBTRACTION_FF"; + + case 28: + return "SUBOP_MULTIPLICATION_FF"; + + case 6: + return "SUBOP_ADDITION_FF"; } return std::to_string(index); } @@ -57,9 +60,9 @@ template class alu_chipImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 3, 3, 3, 3, 3, 3, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 4, 5, 4, - 5, 4, 5, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 6, 6, 8, + 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 6, 6, 8, }; template @@ -369,8 +372,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(28); - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * - ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) - (aluChip_alu_ia * aluChip_alu_ib))); + auto tmp = + ((aluChip_alu_ff_tag * aluChip_alu_op_mul) * ((aluChip_alu_ia * aluChip_alu_ib) - aluChip_alu_ic)); tmp *= scaling_factor; std::get<28>(evals) += tmp; } @@ -378,7 +381,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(29); - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * + ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; std::get<29>(evals) += tmp; } @@ -386,8 +390,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(30); - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * - ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - (aluChip_alu_ia * aluChip_alu_ib))); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); tmp *= scaling_factor; std::get<30>(evals) += tmp; } @@ -395,7 +398,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(31); - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * + ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; std::get<31>(evals) += tmp; } @@ -403,26 +407,34 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(32); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<32>(evals) += tmp; + } + // Contribution 33 + { + AvmMini_DECLARE_VIEWS(33); + auto tmp = ((aluChip_alu_u32_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_ia * aluChip_alu_ib))); tmp *= scaling_factor; - std::get<32>(evals) += tmp; + std::get<33>(evals) += tmp; } - // Contribution 33 + // Contribution 34 { - AvmMini_DECLARE_VIEWS(33); + AvmMini_DECLARE_VIEWS(34); auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_mul) * ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<33>(evals) += tmp; + std::get<34>(evals) += tmp; } - // Contribution 34 + // Contribution 35 { - AvmMini_DECLARE_VIEWS(34); + AvmMini_DECLARE_VIEWS(35); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_mul) * ((((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -434,11 +446,11 @@ template class alu_chipImpl { (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; - std::get<34>(evals) += tmp; + std::get<35>(evals) += tmp; } - // Contribution 35 + // Contribution 36 { - AvmMini_DECLARE_VIEWS(35); + AvmMini_DECLARE_VIEWS(36); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_mul) * @@ -446,11 +458,11 @@ template class alu_chipImpl { (aluChip_alu_u16_r3 * FF(281474976710656UL))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<35>(evals) += tmp; + std::get<36>(evals) += tmp; } - // Contribution 36 + // Contribution 37 { - AvmMini_DECLARE_VIEWS(36); + AvmMini_DECLARE_VIEWS(37); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * (((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -462,11 +474,11 @@ template class alu_chipImpl { FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<36>(evals) += tmp; + std::get<37>(evals) += tmp; } - // Contribution 37 + // Contribution 38 { - AvmMini_DECLARE_VIEWS(37); + AvmMini_DECLARE_VIEWS(38); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * (((((aluChip_alu_u16_r0_shift + (aluChip_alu_u16_r1_shift * FF(65536))) + @@ -478,11 +490,11 @@ template class alu_chipImpl { FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<37>(evals) += tmp; + std::get<38>(evals) += tmp; } - // Contribution 38 + // Contribution 39 { - AvmMini_DECLARE_VIEWS(38); + AvmMini_DECLARE_VIEWS(39); 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))) + @@ -499,7 +511,7 @@ template class alu_chipImpl { FF(uint256_t{ 0, 0, 1, 0 }))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<38>(evals) += tmp; + std::get<39>(evals) += tmp; } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index 540adee863c..f4b48ef9ab8 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,63 +7,60 @@ namespace proof_system::AvmMini_vm { template struct Avm_miniRow { - FF avmMini_internal_return_ptr{}; - FF avmMini_sel_internal_return{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_mem_op_a{}; - FF avmMini_rwb{}; + FF avmMini_mem_idx_a{}; + FF avmMini_tag_err{}; FF avmMini_sel_op_sub{}; - FF avmMini_mem_op_b{}; FF avmMini_rwc{}; - FF avmMini_mem_idx_b{}; - FF avmMini_sel_internal_call{}; - FF avmMini_ic{}; - FF avmMini_tag_err{}; + FF avmMini_internal_return_ptr{}; + FF avmMini_first{}; + FF avmMini_ib{}; FF avmMini_mem_op_c{}; - FF avmMini_inv{}; - FF avmMini_sel_op_add{}; - FF avmMini_pc_shift{}; - FF avmMini_sel_jump{}; + FF avmMini_mem_op_a{}; + FF avmMini_sel_internal_return{}; FF avmMini_sel_halt{}; - FF avmMini_rwa{}; - FF avmMini_ia{}; - FF avmMini_first{}; + FF avmMini_mem_idx_b{}; + FF avmMini_pc{}; FF avmMini_sel_op_div{}; FF avmMini_sel_op_mul{}; + FF avmMini_sel_op_add{}; + FF avmMini_rwa{}; + FF avmMini_ia{}; + FF avmMini_sel_internal_call{}; + FF avmMini_mem_op_b{}; + FF avmMini_sel_jump{}; FF avmMini_op_err{}; - FF avmMini_pc{}; - FF avmMini_ib{}; - FF avmMini_mem_idx_a{}; + FF avmMini_ic{}; + FF avmMini_rwb{}; + FF avmMini_inv{}; + FF avmMini_pc_shift{}; + FF avmMini_internal_return_ptr_shift{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { - case 21: - return "SUBOP_DIVISION_ZERO_ERR1"; - - case 20: - return "SUBOP_DIVISION_FF"; + case 24: + return "RETURN_POINTER_INCREMENT"; - case 19: - return "SUBOP_MULTIPLICATION_FF"; + case 30: + return "RETURN_POINTER_DECREMENT"; - case 36: + case 35: return "PC_INCREMENT"; - case 37: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - - case 25: - return "RETURN_POINTER_INCREMENT"; + case 19: + return "SUBOP_DIVISION_FF"; - case 31: - return "RETURN_POINTER_DECREMENT"; + case 20: + return "SUBOP_DIVISION_ZERO_ERR1"; - case 23: + case 22: return "SUBOP_ERROR_RELEVANT_OP"; - case 22: + case 36: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + + case 21: return "SUBOP_DIVISION_ZERO_ERR2"; } return std::to_string(index); @@ -73,9 +70,8 @@ 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, - 4, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, + 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, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, }; template @@ -241,7 +237,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(19); - auto tmp = (avmMini_sel_op_mul * ((avmMini_ia * avmMini_ib) - avmMini_ic)); + auto tmp = ((avmMini_sel_op_div * (-avmMini_op_err + FF(1))) * ((avmMini_ic * avmMini_ib) - avmMini_ia)); tmp *= scaling_factor; std::get<19>(evals) += tmp; } @@ -249,7 +245,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(20); - auto tmp = ((avmMini_sel_op_div * (-avmMini_op_err + FF(1))) * ((avmMini_ic * avmMini_ib) - avmMini_ia)); + auto tmp = (avmMini_sel_op_div * (((avmMini_ib * avmMini_inv) - FF(1)) + avmMini_op_err)); tmp *= scaling_factor; std::get<20>(evals) += tmp; } @@ -257,7 +253,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(21); - auto tmp = (avmMini_sel_op_div * (((avmMini_ib * avmMini_inv) - FF(1)) + avmMini_op_err)); + auto tmp = ((avmMini_sel_op_div * avmMini_op_err) * (-avmMini_inv + FF(1))); tmp *= scaling_factor; std::get<21>(evals) += tmp; } @@ -265,7 +261,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(22); - auto tmp = ((avmMini_sel_op_div * avmMini_op_err) * (-avmMini_inv + FF(1))); + auto tmp = (avmMini_op_err * (avmMini_sel_op_div - FF(1))); tmp *= scaling_factor; std::get<22>(evals) += tmp; } @@ -273,7 +269,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(23); - auto tmp = (avmMini_op_err * (avmMini_sel_op_div - FF(1))); + auto tmp = (avmMini_sel_jump * (avmMini_pc_shift - avmMini_ia)); tmp *= scaling_factor; std::get<23>(evals) += tmp; } @@ -281,7 +277,8 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(24); - auto tmp = (avmMini_sel_jump * (avmMini_pc_shift - avmMini_ia)); + auto tmp = (avmMini_sel_internal_call * + (avmMini_internal_return_ptr_shift - (avmMini_internal_return_ptr + FF(1)))); tmp *= scaling_factor; std::get<24>(evals) += tmp; } @@ -289,8 +286,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(25); - auto tmp = (avmMini_sel_internal_call * - (avmMini_internal_return_ptr_shift - (avmMini_internal_return_ptr + FF(1)))); + auto tmp = (avmMini_sel_internal_call * (avmMini_internal_return_ptr - avmMini_mem_idx_b)); tmp *= scaling_factor; std::get<25>(evals) += tmp; } @@ -298,7 +294,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(26); - auto tmp = (avmMini_sel_internal_call * (avmMini_internal_return_ptr - avmMini_mem_idx_b)); + auto tmp = (avmMini_sel_internal_call * (avmMini_pc_shift - avmMini_ia)); tmp *= scaling_factor; std::get<26>(evals) += tmp; } @@ -306,7 +302,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(27); - auto tmp = (avmMini_sel_internal_call * (avmMini_pc_shift - avmMini_ia)); + auto tmp = (avmMini_sel_internal_call * ((avmMini_pc + FF(1)) - avmMini_ib)); tmp *= scaling_factor; std::get<27>(evals) += tmp; } @@ -314,7 +310,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(28); - auto tmp = (avmMini_sel_internal_call * ((avmMini_pc + FF(1)) - avmMini_ib)); + auto tmp = (avmMini_sel_internal_call * (avmMini_rwb - FF(1))); tmp *= scaling_factor; std::get<28>(evals) += tmp; } @@ -322,7 +318,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(29); - auto tmp = (avmMini_sel_internal_call * (avmMini_rwb - FF(1))); + auto tmp = (avmMini_sel_internal_call * (avmMini_mem_op_b - FF(1))); tmp *= scaling_factor; std::get<29>(evals) += tmp; } @@ -330,7 +326,8 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(30); - auto tmp = (avmMini_sel_internal_call * (avmMini_mem_op_b - FF(1))); + auto tmp = (avmMini_sel_internal_return * + (avmMini_internal_return_ptr_shift - (avmMini_internal_return_ptr - FF(1)))); tmp *= scaling_factor; std::get<30>(evals) += tmp; } @@ -338,8 +335,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(31); - auto tmp = (avmMini_sel_internal_return * - (avmMini_internal_return_ptr_shift - (avmMini_internal_return_ptr - FF(1)))); + auto tmp = (avmMini_sel_internal_return * ((avmMini_internal_return_ptr - FF(1)) - avmMini_mem_idx_a)); tmp *= scaling_factor; std::get<31>(evals) += tmp; } @@ -347,7 +343,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(32); - auto tmp = (avmMini_sel_internal_return * ((avmMini_internal_return_ptr - FF(1)) - avmMini_mem_idx_a)); + auto tmp = (avmMini_sel_internal_return * (avmMini_pc_shift - avmMini_ia)); tmp *= scaling_factor; std::get<32>(evals) += tmp; } @@ -355,7 +351,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(33); - auto tmp = (avmMini_sel_internal_return * (avmMini_pc_shift - avmMini_ia)); + auto tmp = (avmMini_sel_internal_return * avmMini_rwa); tmp *= scaling_factor; std::get<33>(evals) += tmp; } @@ -363,7 +359,7 @@ template class avm_miniImpl { { AvmMini_DECLARE_VIEWS(34); - auto tmp = (avmMini_sel_internal_return * avmMini_rwa); + auto tmp = (avmMini_sel_internal_return * (avmMini_mem_op_a - FF(1))); tmp *= scaling_factor; std::get<34>(evals) += tmp; } @@ -371,30 +367,22 @@ template class avm_miniImpl { { 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_pc_shift - (avmMini_pc + FF(1)))); tmp *= scaling_factor; - std::get<36>(evals) += tmp; + std::get<35>(evals) += tmp; } - // Contribution 37 + // Contribution 36 { - AvmMini_DECLARE_VIEWS(37); + AvmMini_DECLARE_VIEWS(36); 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; + std::get<36>(evals) += tmp; } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index 37df4bbab68..32e3626e5ee 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -68,17 +68,17 @@ [[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 avmMini_pc_shift = View(new_term.avmMini_pc_shift); \ + [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_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); + [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ + [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ + [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ + [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 4de2e1cc3b6..62a871802cb 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,24 +7,33 @@ namespace proof_system::AvmMini_vm { template struct Mem_traceRow { - FF memTrace_m_rw{}; - FF memTrace_m_tag_err{}; - FF memTrace_m_addr{}; FF memTrace_m_last{}; - FF memTrace_m_rw_shift{}; + FF memTrace_m_rw{}; FF memTrace_m_tag{}; + FF memTrace_m_lastAccess{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_in_tag{}; FF memTrace_m_one_min_inv{}; FF memTrace_m_val_shift{}; - FF memTrace_m_val{}; - FF memTrace_m_addr_shift{}; FF memTrace_m_tag_shift{}; - FF memTrace_m_in_tag{}; - FF memTrace_m_lastAccess{}; + FF memTrace_m_addr{}; + FF memTrace_m_val{}; + FF memTrace_m_tag_err{}; + FF memTrace_m_rw_shift{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { + case 6: + return "MEM_READ_WRITE_TAG_CONSISTENCY"; + + case 9: + return "MEM_IN_TAG_CONSISTENCY_2"; + + case 7: + return "MEM_ZERO_INIT"; + case 5: return "MEM_READ_WRITE_VAL_CONSISTENCY"; @@ -33,15 +42,6 @@ inline std::string get_relation_label_mem_trace(int index) case 4: return "MEM_LAST_ACCESS_DELIMITER"; - - case 9: - return "MEM_IN_TAG_CONSISTENCY_2"; - - case 7: - return "MEM_ZERO_INIT"; - - case 6: - return "MEM_READ_WRITE_TAG_CONSISTENCY"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp index 708ecbe1f45..92dc198ed09 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp @@ -33,7 +33,7 @@ std::vector AvmMiniAluTraceBuilder::final /** * @brief Build Alu trace and compute the result of an addition of type defined by in_tag. * - * @param a Left operand of the additon + * @param a Left operand of the addition * @param b Right operand of the addition * @param in_tag Instruction tag defining the number of bits on which the addition applies. * It is assumed that the caller never uses the type u0. @@ -51,6 +51,7 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag, ui switch (in_tag) { case AvmMemoryTag::ff: c = a + b; + break; case AvmMemoryTag::u8: { uint8_t a_u8 = static_cast(uint256_t(a).data[0]); uint8_t b_u8 = static_cast(uint256_t(b).data[0]); @@ -175,6 +176,7 @@ FF AvmMiniAluTraceBuilder::sub(FF const& a, FF const& b, AvmMemoryTag in_tag, ui switch (in_tag) { case AvmMemoryTag::ff: c = a - b; + break; case AvmMemoryTag::u8: { uint8_t a_u8 = static_cast(uint256_t(a).data[0]); uint8_t b_u8 = static_cast(uint256_t(b).data[0]); @@ -288,4 +290,113 @@ FF AvmMiniAluTraceBuilder::sub(FF const& a, FF const& b, AvmMemoryTag in_tag, ui return c; } +/** + * @brief Build Alu trace and compute the result of an multiplication of type defined by in_tag. + * + * @param a Left operand of the multiplication + * @param b Right operand of the multiplication + * @param in_tag Instruction tag defining the number of bits on which the multiplication applies. + * It is assumed that the caller never uses the type u0. + * @param clk Clock referring to the operation in the main trace. + * + * @return FF The result of the multiplication casted in a finite field element + */ +FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t const clk) +{ + FF c{}; + bool carry = false; + uint8_t alu_u8_r0{}; + uint8_t alu_u8_r1{}; + + std::array alu_u16_reg{}; + + switch (in_tag) { + case AvmMemoryTag::ff: + c = a * b; + break; + case AvmMemoryTag::u8: { + uint16_t a_u16 = static_cast(uint256_t(a).data[0]); + uint16_t b_u16 = static_cast(uint256_t(b).data[0]); + uint16_t c_u16 = a_u16 * b_u16; // Multiplication over the integers (not mod. 2^8) + + // Decompose c_u16 = r0 + 2^8 * r1 with r0, r1 8-bit registers + alu_u8_r0 = static_cast(c_u16); + alu_u8_r1 = static_cast(c_u16 >> 8); + + c = FF{ uint256_t{ alu_u8_r0 } }; + break; + } + case AvmMemoryTag::u16: { + uint32_t a_u32 = static_cast(uint256_t(a).data[0]); + uint32_t b_u32 = static_cast(uint256_t(b).data[0]); + uint32_t c_u32 = a_u32 * b_u32; // Multiplication over the integers (not mod. 2^16) + + // Decompose c_u32 = r0 + 2^16 * r1 with r0, r1 16-bit registers + alu_u16_reg.at(0) = static_cast(c_u32); + alu_u16_reg.at(1) = static_cast(c_u32 >> 16); + + c = FF{ uint256_t{ alu_u16_reg.at(0) } }; + break; + } + case AvmMemoryTag::u32: { + uint64_t a_u64 = static_cast(uint256_t(a).data[0]); + uint64_t b_u64 = static_cast(uint256_t(b).data[0]); + uint64_t c_u64 = a_u64 * b_u64; // Multiplication over the integers (not mod. 2^32) + + // Decompose c_u64 = r0 + 2^16 * r1 + 2^32 * r2 + 2^48 * r3 with r0, r1, r2, r3 16-bit registers + uint64_t c_trunc_64 = c_u64; + for (size_t i = 0; i < 4; i++) { + alu_u16_reg.at(i) = static_cast(c_trunc_64); + c_trunc_64 >>= 16; + } + + c = FF{ uint256_t{ static_cast(c_u64) } }; + + break; + } + case AvmMemoryTag::u64: { + uint128_t a_u128 = static_cast(uint256_t(a).data[0]); + uint128_t b_u128 = static_cast(uint256_t(b).data[0]); + uint128_t c_u128 = a_u128 * b_u128; // Multiplication over the integers (not mod. 2^64) + + // Decompose c_u128 = r0 + 2^16 * r1 + .. + 2^112 r7 with r0, r1 ... r7 16-bit registers + uint128_t c_trunc_128 = c_u128; + for (size_t i = 0; i < 8; i++) { + alu_u16_reg.at(i) = static_cast(c_trunc_128); + c_trunc_128 >>= 16; + } + + c = FF{ uint256_t{ static_cast(c_u128) } }; + + break; + } + case AvmMemoryTag::u128: { + break; + // TODO + } + case AvmMemoryTag::u0: // Unsupported as instruction tag + return FF{ 0 }; + } + + alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ + .alu_clk = clk, + .alu_op_mul = true, + .alu_ff_tag = in_tag == AvmMemoryTag::ff, + .alu_u8_tag = in_tag == AvmMemoryTag::u8, + .alu_u16_tag = in_tag == AvmMemoryTag::u16, + .alu_u32_tag = in_tag == AvmMemoryTag::u32, + .alu_u64_tag = in_tag == AvmMemoryTag::u64, + .alu_u128_tag = in_tag == AvmMemoryTag::u128, + .alu_ia = a, + .alu_ib = b, + .alu_ic = c, + .alu_cf = carry, + .alu_u8_r0 = alu_u8_r0, + .alu_u8_r1 = alu_u8_r1, + .alu_u16_reg = alu_u16_reg, + }); + + return c; +} + } // namespace avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp index 977e51949f0..c8715710ed5 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp @@ -12,6 +12,7 @@ class AvmMiniAluTraceBuilder { bool alu_op_add = false; bool alu_op_sub = false; + bool alu_op_mul = false; bool alu_ff_tag = false; bool alu_u8_tag = false; @@ -27,6 +28,7 @@ class AvmMiniAluTraceBuilder { bool alu_cf = false; uint8_t alu_u8_r0{}; + uint8_t alu_u8_r1{}; std::array alu_u16_reg{}; }; @@ -37,6 +39,7 @@ class AvmMiniAluTraceBuilder { FF add(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t clk); FF sub(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t clk); + FF mul(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t clk); private: std::vector alu_trace; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp index 207485ac63d..9e1fd096c89 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp @@ -39,6 +39,12 @@ void log_avmMini_trace(std::vector const& trace, size_t beg, size_t end) 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); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp index 411a335dd19..b112a01be02 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp @@ -122,7 +122,7 @@ void AvmMiniTraceBuilder::sub(uint32_t a_offset, uint32_t b_offset, uint32_t dst }); }; -/** TODO: Implement for non finite field types +/** * @brief Multiplication with direct memory access. * * @param a_offset An index in memory pointing to the first operand of the multiplication. @@ -140,9 +140,9 @@ void AvmMiniTraceBuilder::mul(uint32_t a_offset, uint32_t b_offset, uint32_t dst bool tag_match = read_a.tag_match && read_b.tag_match; // a * b = c - FF a = read_a.val; - FF b = read_b.val; - FF c = a * b; + FF a = tag_match ? read_a.val : FF(0); + FF b = tag_match ? read_b.val : FF(0); + FF c = alu_trace_builder.mul(a, b, in_tag, clk); // Write into memory value c from intermediate register ic. mem_trace_builder.write_into_memory(clk, IntermRegister::ic, dst_offset, c, in_tag); @@ -154,9 +154,9 @@ void AvmMiniTraceBuilder::mul(uint32_t a_offset, uint32_t b_offset, uint32_t dst .avmMini_sel_op_mul = FF(1), .avmMini_in_tag = FF(static_cast(in_tag)), .avmMini_tag_err = FF(static_cast(!tag_match)), - .avmMini_ia = tag_match ? a : FF(0), - .avmMini_ib = tag_match ? b : FF(0), - .avmMini_ic = tag_match ? c : FF(0), + .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), @@ -629,6 +629,7 @@ std::vector AvmMiniTraceBuilder::finalize() 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_ff_tag = FF(static_cast(src.alu_ff_tag)); dest.aluChip_alu_u8_tag = FF(static_cast(src.alu_u8_tag)); @@ -644,6 +645,7 @@ std::vector AvmMiniTraceBuilder::finalize() dest.aluChip_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.aluChip_alu_u16_r0 = FF(src.alu_u16_reg.at(0)); dest.aluChip_alu_u16_r1 = FF(src.alu_u16_reg.at(1)); diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index feb58ee9c97..c4ac9ab809a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -168,7 +168,7 @@ TEST_F(AvmMiniArithmeticTestsFF, addition) 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(41)); + EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0)); validate_trace_proof(std::move(trace)); } @@ -187,7 +187,7 @@ TEST_F(AvmMiniArithmeticTestsFF, subtraction) 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(17)); + EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0)); validate_trace_proof(std::move(trace)); } @@ -954,6 +954,8 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, subtraction) // Memory layout: [8,4,17,0,0,0,....] trace_builder.sub(2, 0, 1, AvmMemoryTag::ff); // [8,9,17,0,0,0....] + trace_builder.halt(); + auto trace = trace_builder.finalize(); auto select_row = [](Row r) { return r.avmMini_sel_op_sub == FF(1); }; @@ -969,10 +971,11 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, multiplication) // Memory layout: [5,0,20,0,0,0,....] trace_builder.mul(2, 0, 1, AvmMemoryTag::ff); // [5,100,20,0,0,0....] + trace_builder.halt(); auto trace = trace_builder.finalize(); auto select_row = [](Row r) { return r.avmMini_sel_op_mul == FF(1); }; - mutate_ic_in_trace(trace, std::move(select_row), FF(1000)); + mutate_ic_in_trace(trace, std::move(select_row), FF(1000), true); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_MULTIPLICATION_FF"); } @@ -984,6 +987,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionFF) // Memory layout: [15,315,0,0,0,0,....] trace_builder.div(1, 0, 2, AvmMemoryTag::ff); // [15,315,21,0,0,0....] + trace_builder.halt(); auto trace = trace_builder.finalize(); auto select_row = [](Row r) { return r.avmMini_sel_op_div == FF(1); }; @@ -1000,6 +1004,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionNoZeroButError) // Memory layout: [15,315,0,0,0,0,....] trace_builder.div(1, 0, 2, AvmMemoryTag::ff); // [15,315,21,0,0,0....] + trace_builder.halt(); auto trace = trace_builder.finalize(); // Find the first row enabling the division selector @@ -1042,6 +1047,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionZeroByZeroNoError) { // Memory layout: [0,0,0,0,0,0,....] trace_builder.div(0, 1, 2, AvmMemoryTag::ff); // [0,0,0,0,0,0....] + trace_builder.halt(); auto trace = trace_builder.finalize(); // Find the first row enabling the division selector @@ -1062,6 +1068,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) // Memory layout: [37,4,11,0,0,0,....] trace_builder.add(0, 1, 4, AvmMemoryTag::ff); // [37,4,11,0,41,0,....] trace_builder.return_op(0, 5); + trace_builder.halt(); auto trace = trace_builder.finalize(); // Find the first row enabling the addition selector From 0a65b54c3978463f27007d3569940548439a37e8 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Thu, 11 Jan 2024 16:57:49 +0000 Subject: [PATCH 17/28] 3738 - add positive unit tests for addition with type u8, u16, u32, u64 --- .../vm/tests/AvmMini_arithmetic.test.cpp | 256 ++++++++++++++++-- 1 file changed, 239 insertions(+), 17 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index c4ac9ab809a..09341399934 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -91,13 +91,42 @@ 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 addition selector is set. + // 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)); return *alu_row; } +Row common_validate_mul(std::vector const& trace, + FF const& a, + FF const& b, + FF const& c, + FF const& addr_a, + FF const& addr_b, + FF const& addr_c, + 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); }); + + // 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; }); + + // Check that both rows were found + EXPECT_TRUE(row != trace.end()); + EXPECT_TRUE(alu_row != trace.end()); + + 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)); + + return *alu_row; +} + } // anonymous namespace namespace tests_avm { @@ -202,15 +231,11 @@ TEST_F(AvmMiniArithmeticTestsFF, multiplication) trace_builder.return_op(0, 3); auto trace = trace_builder.finalize(); - // 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 alu_row = common_validate_mul(trace, FF(20), FF(5), FF(100), FF(2), FF(0), FF(1), AvmMemoryTag::ff); - // Check that the correct result is stored at the expected memory location. - EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avmMini_ic, FF(100)); - EXPECT_EQ(row->avmMini_mem_idx_c, FF(1)); - EXPECT_EQ(row->avmMini_mem_op_c, FF(1)); - EXPECT_EQ(row->avmMini_rwc, FF(1)); + 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)); validate_trace_proof(std::move(trace)); } @@ -225,15 +250,11 @@ TEST_F(AvmMiniArithmeticTestsFF, multiplicationByZero) trace_builder.return_op(0, 3); auto trace = trace_builder.finalize(); - // 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 alu_row = common_validate_mul(trace, FF(127), FF(0), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::ff); - // 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(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)); validate_trace_proof(std::move(trace)); } @@ -446,6 +467,51 @@ TEST_F(AvmMiniArithmeticTestsU8, subtractionCarry) validate_trace_proof(std::move(trace)); } +// Test on basic multiplication over u8 type. +TEST_F(AvmMiniArithmeticTestsU8, multiplication) +{ + // trace_builder + trace_builder.set(13, 0, AvmMemoryTag::u8); + trace_builder.set(15, 1, AvmMemoryTag::u8); + + trace_builder.mul(0, 1, 2, AvmMemoryTag::u8); + trace_builder.return_op(2, 1); + auto trace = trace_builder.finalize(); + + auto alu_row = common_validate_mul(trace, FF(13), FF(15), FF(195), FF(0), FF(1), FF(2), AvmMemoryTag::u8); + + EXPECT_EQ(alu_row.aluChip_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)); + + validate_trace_proof(std::move(trace)); +} + +// Test on multiplication over u8 type with overflow. +TEST_F(AvmMiniArithmeticTestsU8, multiplicationOverflow) +{ + // trace_builder + trace_builder.set(200, 0, AvmMemoryTag::u8); + trace_builder.set(170, 1, AvmMemoryTag::u8); + + trace_builder.mul(0, 1, 2, AvmMemoryTag::u8); + trace_builder.return_op(2, 1); + auto trace = trace_builder.finalize(); + + auto alu_row = common_validate_mul(trace, FF(200), FF(170), FF(208), FF(0), FF(1), FF(2), AvmMemoryTag::u8); + + EXPECT_EQ(alu_row.aluChip_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)); + + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * Positive Tests - U16 ******************************************************************************/ @@ -535,6 +601,51 @@ TEST_F(AvmMiniArithmeticTestsU16, subtractionCarry) validate_trace_proof(std::move(trace)); } +// Test on basic multiplication over u16 type. +TEST_F(AvmMiniArithmeticTestsU16, multiplication) +{ + // trace_builder + trace_builder.set(200, 0, AvmMemoryTag::u16); + trace_builder.set(245, 1, AvmMemoryTag::u16); + + trace_builder.mul(0, 1, 2, AvmMemoryTag::u16); + trace_builder.return_op(2, 1); + auto trace = trace_builder.finalize(); + + auto alu_row = common_validate_mul(trace, FF(200), FF(245), FF(49000), FF(0), FF(1), FF(2), AvmMemoryTag::u16); + + EXPECT_EQ(alu_row.aluChip_alu_u16_tag, FF(1)); + + // Decomposition of integer multiplication in 16-bit registers + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(49000)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0)); + + validate_trace_proof(std::move(trace)); +} + +// Test on multiplication over u16 type with overflow. +TEST_F(AvmMiniArithmeticTestsU16, multiplicationOverflow) +{ + // trace_builder + trace_builder.set(512, 0, AvmMemoryTag::u16); + trace_builder.set(1024, 1, AvmMemoryTag::u16); + + trace_builder.mul(0, 1, 2, AvmMemoryTag::u16); + trace_builder.return_op(2, 1); + auto trace = trace_builder.finalize(); + + auto alu_row = common_validate_mul(trace, FF(512), FF(1024), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::u16); + + EXPECT_EQ(alu_row.aluChip_alu_u16_tag, FF(1)); + + // Decomposition of integer multiplication in 16-bit registers + // 512 * 1024 = 0 + 8 * 2^16 + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(8)); + + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * Positive Tests - U32 ******************************************************************************/ @@ -632,6 +743,58 @@ TEST_F(AvmMiniArithmeticTestsU32, subtractionCarry) validate_trace_proof(std::move(trace)); } +// Test on basic multiplication over u32 type. +TEST_F(AvmMiniArithmeticTestsU32, multiplication) +{ + // trace_builder + trace_builder.set(11111, 0, AvmMemoryTag::u32); + trace_builder.set(11111, 1, AvmMemoryTag::u32); + + trace_builder.mul(0, 1, 2, AvmMemoryTag::u32); + trace_builder.return_op(2, 1); + auto trace = trace_builder.finalize(); + + auto alu_row = + common_validate_mul(trace, FF(11111), FF(11111), FF(123454321), FF(0), FF(1), FF(2), AvmMemoryTag::u32); + + EXPECT_EQ(alu_row.aluChip_alu_u32_tag, FF(1)); + + // Decomposition of integer multiplication in 16-bit registers + // 123454321 = 50033 + 1883 * 2^16 + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(50033)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(1883)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0)); + + validate_trace_proof(std::move(trace)); +} + +// Test on multiplication over u32 type with overflow. +TEST_F(AvmMiniArithmeticTestsU32, multiplicationOverflow) +{ + // trace_builder + trace_builder.set(11 << 25, 0, AvmMemoryTag::u32); + trace_builder.set(13 << 22, 1, AvmMemoryTag::u32); + + trace_builder.mul(0, 1, 2, AvmMemoryTag::u32); + trace_builder.return_op(2, 1); + auto trace = trace_builder.finalize(); + + auto alu_row = + common_validate_mul(trace, FF(11 << 25), FF(13 << 22), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::u32); + + EXPECT_EQ(alu_row.aluChip_alu_u32_tag, FF(1)); + + // Decomposition of integer multiplication in 16-bit registers + // 143 * 2^47 = 0 + 0 * 2^16 + 2^15 * 2^32 + 71 * 2^48 + 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(32768)); // 2^15 + EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(71)); + + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * Positive Tests - U64 ******************************************************************************/ @@ -749,6 +912,65 @@ TEST_F(AvmMiniArithmeticTestsU64, subtractionCarry) validate_trace_proof(std::move(trace)); } +// Test on basic multiplication over u64 type. +TEST_F(AvmMiniArithmeticTestsU64, multiplication) +{ + // trace_builder + trace_builder.set(999888777, 0, AvmMemoryTag::u64); + trace_builder.set(555444333, 1, AvmMemoryTag::u64); + + trace_builder.mul(0, 1, 2, AvmMemoryTag::u64); + trace_builder.return_op(2, 1); + auto trace = trace_builder.finalize(); + + auto alu_row = common_validate_mul( + trace, FF(999888777), FF(555444333), FF(555382554814950741LLU), FF(0), FF(1), FF(2), AvmMemoryTag::u64); + + EXPECT_EQ(alu_row.aluChip_alu_u64_tag, FF(1)); + + // Decomposition of integer multiplication in 16-bit registers + // 555,382,554,814,950,741 = 44,373 + 46,641 * 2^16 + 7,549 * 2^32 + 1,973 * 2^48 + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(44373)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(46641)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(7549)); + EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(1973)); + + validate_trace_proof(std::move(trace)); +} + +// Test on multiplication over u64 type with overflow. +TEST_F(AvmMiniArithmeticTestsU64, multiplicationOverflow) +{ + uint64_t const a = UINT64_MAX; + uint64_t const b = UINT64_MAX; + // (2^64 - 1)^2 = 2^128 - 2^65 + 1 (mod. 2^64) = 1 + + // trace_builder + trace_builder.set(a, 0, AvmMemoryTag::u64); + trace_builder.set(b, 1, AvmMemoryTag::u64); + + trace_builder.mul(0, 1, 2, AvmMemoryTag::u64); + trace_builder.return_op(2, 1); + auto trace = trace_builder.finalize(); + + auto alu_row = common_validate_mul(trace, FF(a), FF(b), FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::u64); + + EXPECT_EQ(alu_row.aluChip_alu_u64_tag, FF(1)); + + // Decomposition of integer multiplication in 16-bit registers + // 2^128 - 2^65 + 1 + EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(1)); + 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(UINT16_MAX - 1)); + 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.aluChip_alu_u16_r7, FF(UINT16_MAX)); + + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * Positive Tests - U128 ******************************************************************************/ From fab58b9d0a3d985841d2c0e90eeb40291b2c775a Mon Sep 17 00:00:00 2001 From: jeanmon Date: Thu, 11 Jan 2024 21:43:23 +0000 Subject: [PATCH 18/28] 3738 - witness generation for addition over u128 --- .../vm/avm_trace/AvmMini_alu_trace.cpp | 48 ++++++++++++++++++- .../vm/avm_trace/AvmMini_alu_trace.hpp | 2 + .../vm/avm_trace/AvmMini_trace.cpp | 2 + 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp index 92dc198ed09..75e34d9b4c2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp @@ -371,8 +371,52 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui break; } case AvmMemoryTag::u128: { - break; - // TODO + auto a_u256 = uint256_t(a); + auto b_u256 = uint256_t(b); + uint256_t c_u256 = a_u256 * b_u256; // Multiplication over the integers (not mod. 2^128) + + auto a_u128 = static_cast(a_u256); + auto b_u128 = static_cast(b_u256); + + uint128_t c_u128 = a_u128 * b_u128; + + // Decompose a_u128 and b_u128 over 8 16-bit registers. + std::array alu_u16_reg_a{}; + std::array alu_u16_reg_b{}; + uint128_t a_trunc_128 = a_u128; + uint128_t b_trunc_128 = b_u128; + + for (size_t i = 0; i < 8; i++) { + alu_u16_reg_a.at(i) = static_cast(a_trunc_128); + alu_u16_reg_b.at(i) = static_cast(b_trunc_128); + a_trunc_128 >>= 16; + b_trunc_128 >>= 16; + } + + uint256_t c_high = ((a_u256 >> 64) * (b_u256 >> 64)) << 128; + + carry = ((c_u256 - c_high) >> 193) > 0; + uint64_t alu_u64_r0 = static_cast(((c_u256 - c_high) >> 128) & uint256_t(UINT64_MAX)); + + c = FF{ uint256_t::from_uint128(c_u128) }; + + alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ + .alu_clk = clk, + .alu_op_mul = true, + .alu_u128_tag = in_tag == AvmMemoryTag::u128, + .alu_ia = a, + .alu_ib = b, + .alu_ic = c, + .alu_cf = carry, + .alu_u16_reg = alu_u16_reg_a, + .alu_u64_r0 = alu_u64_r0, + }); + + alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ + .alu_u16_reg = alu_u16_reg_b, + }); + + return c; } case AvmMemoryTag::u0: // Unsupported as instruction tag return FF{ 0 }; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp index c8715710ed5..cda0263cb8d 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.hpp @@ -31,6 +31,8 @@ class AvmMiniAluTraceBuilder { uint8_t alu_u8_r1{}; std::array alu_u16_reg{}; + + uint64_t alu_u64_r0{}; }; AvmMiniAluTraceBuilder(); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp index b112a01be02..f8bb7d9bcf6 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp @@ -655,6 +655,8 @@ std::vector AvmMiniTraceBuilder::finalize() 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.aluChip_alu_u64_r0 = FF(src.alu_u64_r0); } // Adding extra row for the shifted values at the top of the execution trace. From 1536b2857874bc81e65fba51b2b777448df834c1 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Fri, 12 Jan 2024 10:02:16 +0000 Subject: [PATCH 19/28] 3738: style improvement and comments --- .../vm/avm_trace/AvmMini_alu_trace.cpp | 74 ++++++++++--------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp index 75e34d9b4c2..9167405cbde 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp @@ -53,8 +53,8 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag, ui c = a + b; break; case AvmMemoryTag::u8: { - uint8_t a_u8 = static_cast(uint256_t(a).data[0]); - uint8_t b_u8 = static_cast(uint256_t(b).data[0]); + auto a_u8 = static_cast(uint32_t{ a }); + auto b_u8 = static_cast(uint32_t{ b }); uint8_t c_u8 = a_u8 + b_u8; c = FF{ uint256_t{ c_u8 } }; @@ -67,8 +67,8 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag, ui break; } case AvmMemoryTag::u16: { - uint16_t a_u16 = static_cast(uint256_t(a).data[0]); - uint16_t b_u16 = static_cast(uint256_t(b).data[0]); + auto a_u16 = static_cast(uint32_t{ a }); + auto b_u16 = static_cast(uint32_t{ b }); uint16_t c_u16 = a_u16 + b_u16; c = FF{ uint256_t{ c_u16 } }; @@ -81,8 +81,8 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag, ui break; } case AvmMemoryTag::u32: { - uint32_t a_u32 = static_cast(uint256_t(a).data[0]); - uint32_t b_u32 = static_cast(uint256_t(b).data[0]); + uint32_t a_u32{ a }; + uint32_t b_u32{ b }; uint32_t c_u32 = a_u32 + b_u32; c = FF{ uint256_t{ c_u32 } }; @@ -96,8 +96,8 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag, ui break; } case AvmMemoryTag::u64: { - uint64_t a_u64 = static_cast(uint256_t(a).data[0]); - uint64_t b_u64 = static_cast(uint256_t(b).data[0]); + uint64_t a_u64{ a }; + uint64_t b_u64{ b }; uint64_t c_u64 = a_u64 + b_u64; c = FF{ uint256_t{ c_u64 } }; @@ -114,8 +114,8 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag, ui break; } case AvmMemoryTag::u128: { - auto a_u128 = uint128_t(a); - auto b_u128 = uint128_t(b); + uint128_t a_u128{ a }; + uint128_t b_u128{ b }; uint128_t c_u128 = a_u128 + b_u128; c = FF{ uint256_t::from_uint128(c_u128) }; @@ -178,8 +178,8 @@ FF AvmMiniAluTraceBuilder::sub(FF const& a, FF const& b, AvmMemoryTag in_tag, ui c = a - b; break; case AvmMemoryTag::u8: { - uint8_t a_u8 = static_cast(uint256_t(a).data[0]); - uint8_t b_u8 = static_cast(uint256_t(b).data[0]); + auto a_u8 = static_cast(uint32_t{ a }); + auto b_u8 = static_cast(uint32_t{ b }); uint8_t c_u8 = a_u8 - b_u8; c = FF{ uint256_t{ c_u8 } }; @@ -194,8 +194,8 @@ FF AvmMiniAluTraceBuilder::sub(FF const& a, FF const& b, AvmMemoryTag in_tag, ui break; } case AvmMemoryTag::u16: { - uint16_t a_u16 = static_cast(uint256_t(a).data[0]); - uint16_t b_u16 = static_cast(uint256_t(b).data[0]); + auto a_u16 = static_cast(uint32_t{ a }); + auto b_u16 = static_cast(uint32_t{ b }); uint16_t c_u16 = a_u16 - b_u16; c = FF{ uint256_t{ c_u16 } }; @@ -210,8 +210,8 @@ FF AvmMiniAluTraceBuilder::sub(FF const& a, FF const& b, AvmMemoryTag in_tag, ui break; } case AvmMemoryTag::u32: { - uint32_t a_u32 = static_cast(uint256_t(a).data[0]); - uint32_t b_u32 = static_cast(uint256_t(b).data[0]); + uint32_t a_u32{ a }; + uint32_t b_u32{ b }; uint32_t c_u32 = a_u32 - b_u32; c = FF{ uint256_t{ c_u32 } }; @@ -227,8 +227,8 @@ FF AvmMiniAluTraceBuilder::sub(FF const& a, FF const& b, AvmMemoryTag in_tag, ui break; } case AvmMemoryTag::u64: { - uint64_t a_u64 = static_cast(uint256_t(a).data[0]); - uint64_t b_u64 = static_cast(uint256_t(b).data[0]); + uint64_t a_u64{ a }; + uint64_t b_u64{ b }; uint64_t c_u64 = a_u64 - b_u64; c = FF{ uint256_t{ c_u64 } }; @@ -247,8 +247,8 @@ FF AvmMiniAluTraceBuilder::sub(FF const& a, FF const& b, AvmMemoryTag in_tag, ui break; } case AvmMemoryTag::u128: { - auto a_u128 = uint128_t(a); - auto b_u128 = uint128_t(b); + uint128_t a_u128{ a }; + uint128_t b_u128{ b }; uint128_t c_u128 = a_u128 - b_u128; c = FF{ uint256_t::from_uint128(c_u128) }; @@ -315,8 +315,8 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui c = a * b; break; case AvmMemoryTag::u8: { - uint16_t a_u16 = static_cast(uint256_t(a).data[0]); - uint16_t b_u16 = static_cast(uint256_t(b).data[0]); + auto a_u16 = static_cast(uint32_t{ a }); + auto b_u16 = static_cast(uint32_t{ b }); uint16_t c_u16 = a_u16 * b_u16; // Multiplication over the integers (not mod. 2^8) // Decompose c_u16 = r0 + 2^8 * r1 with r0, r1 8-bit registers @@ -327,8 +327,8 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui break; } case AvmMemoryTag::u16: { - uint32_t a_u32 = static_cast(uint256_t(a).data[0]); - uint32_t b_u32 = static_cast(uint256_t(b).data[0]); + uint32_t a_u32{ a }; + uint32_t b_u32{ b }; uint32_t c_u32 = a_u32 * b_u32; // Multiplication over the integers (not mod. 2^16) // Decompose c_u32 = r0 + 2^16 * r1 with r0, r1 16-bit registers @@ -339,8 +339,8 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui break; } case AvmMemoryTag::u32: { - uint64_t a_u64 = static_cast(uint256_t(a).data[0]); - uint64_t b_u64 = static_cast(uint256_t(b).data[0]); + uint64_t a_u64{ a }; + uint64_t b_u64{ b }; uint64_t c_u64 = a_u64 * b_u64; // Multiplication over the integers (not mod. 2^32) // Decompose c_u64 = r0 + 2^16 * r1 + 2^32 * r2 + 2^48 * r3 with r0, r1, r2, r3 16-bit registers @@ -355,8 +355,8 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui break; } case AvmMemoryTag::u64: { - uint128_t a_u128 = static_cast(uint256_t(a).data[0]); - uint128_t b_u128 = static_cast(uint256_t(b).data[0]); + uint128_t a_u128{ a }; + uint128_t b_u128{ b }; uint128_t c_u128 = a_u128 * b_u128; // Multiplication over the integers (not mod. 2^64) // Decompose c_u128 = r0 + 2^16 * r1 + .. + 2^112 r7 with r0, r1 ... r7 16-bit registers @@ -371,12 +371,12 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui break; } case AvmMemoryTag::u128: { - auto a_u256 = uint256_t(a); - auto b_u256 = uint256_t(b); + uint256_t a_u256{ a }; + uint256_t b_u256{ b }; uint256_t c_u256 = a_u256 * b_u256; // Multiplication over the integers (not mod. 2^128) - auto a_u128 = static_cast(a_u256); - auto b_u128 = static_cast(b_u256); + uint128_t a_u128{ a_u256 }; + uint128_t b_u128{ b_u256 }; uint128_t c_u128 = a_u128 * b_u128; @@ -393,9 +393,17 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui b_trunc_128 >>= 16; } + // Represent a, b with 64-bit limbs: a = a_l + 2^64 * a_h, b = b_l + 2^64 * b_h, + // 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 + // a * b_l + a_l * b_h * 2^64 = (CF * 2^65 + R') * 2^128 + c + // LHS is c_u256 - c_high + + // CF bit carry = ((c_u256 - c_high) >> 193) > 0; + // R' value uint64_t alu_u64_r0 = static_cast(((c_u256 - c_high) >> 128) & uint256_t(UINT64_MAX)); c = FF{ uint256_t::from_uint128(c_u128) }; @@ -422,6 +430,7 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui return FF{ 0 }; } + // Following code executed for: ff, u8, u16, u32, u64 (u128 returned handled specifically) alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, .alu_op_mul = true, @@ -430,7 +439,6 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui .alu_u16_tag = in_tag == AvmMemoryTag::u16, .alu_u32_tag = in_tag == AvmMemoryTag::u32, .alu_u64_tag = in_tag == AvmMemoryTag::u64, - .alu_u128_tag = in_tag == AvmMemoryTag::u128, .alu_ia = a, .alu_ib = b, .alu_ic = c, From 5d9bda5f38a0dd0fbf078d2b1f52cd222c7ebcc5 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Fri, 12 Jan 2024 16:05:39 +0000 Subject: [PATCH 20/28] 3738 - bugfixing PIL relation for u128 multiplication and unit tests --- barretenberg/cpp/pil/avm/alu_chip.pil | 4 +- .../flavor/generated/AvmMini_flavor.hpp | 62 +++---- .../generated/AvmMini_circuit_builder.hpp | 32 ++-- .../relations/generated/AvmMini/alu_chip.hpp | 52 +++--- .../relations/generated/AvmMini/avm_mini.hpp | 62 +++---- .../generated/AvmMini/declare_views.hpp | 12 +- .../relations/generated/AvmMini/mem_trace.hpp | 30 ++-- .../vm/avm_trace/AvmMini_alu_trace.cpp | 4 +- .../vm/tests/AvmMini_arithmetic.test.cpp | 165 ++++++++++++++---- 9 files changed, 261 insertions(+), 162 deletions(-) diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil index c3eaa6f5fc2..0de5c559681 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -186,7 +186,7 @@ namespace aluChip(256); // b = b_l + b_h * 2^64 // We show that c satisfies: a_l * b_l + (a_h * b_l + a_l * b_h) * 2^64 = R * 2^128 + c // for a R < 2^65. Equivalently: - // a * b_l + a_l * b_h * 2^64 = (CF * 2^65 + R') * 2^128 + c + // a * b_l + a_l * b_h * 2^64 = (CF * 2^64 + R') * 2^128 + c // for a bit carry flag CF and R' range constrained to 64 bits. // We use two lines in the execution trace. First line represents a // as decomposed over 16-bit registers. Second line represents b. @@ -209,6 +209,6 @@ namespace aluChip(256); alu_u128_tag * alu_op_mul * ( alu_ia * sum_shifted_64 + sum_64 * sum_high_shifted_64 * 2**64 - - (alu_cf * 2**65 + alu_u64_r0) * 2**128 + - (alu_cf * 2**64 + alu_u64_r0) * 2**128 - alu_ic ) = 0; diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index 5b97550ac3a..05e7de9640f 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -43,7 +43,7 @@ class AvmMiniFlavor { // the unshifted and one for the shifted static constexpr size_t NUM_ALL_ENTITIES = 80; - using Relations = std::tuple, AvmMini_vm::alu_chip, AvmMini_vm::mem_trace>; + using Relations = std::tuple, AvmMini_vm::avm_mini, AvmMini_vm::mem_trace>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -281,19 +281,19 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - avmMini_pc_shift, - avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r7_shift, aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r2_shift, aluChip_alu_u16_r3_shift, aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r1_shift, aluChip_alu_u16_r5_shift, - memTrace_m_addr_shift, + aluChip_alu_u16_r7_shift, + avmMini_internal_return_ptr_shift, + avmMini_pc_shift, memTrace_m_val_shift, memTrace_m_tag_shift, + memTrace_m_addr_shift, memTrace_m_rw_shift) RefVector get_wires() @@ -364,19 +364,19 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - avmMini_pc_shift, - avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r7_shift, aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r2_shift, aluChip_alu_u16_r3_shift, aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r1_shift, aluChip_alu_u16_r5_shift, - memTrace_m_addr_shift, + aluChip_alu_u16_r7_shift, + avmMini_internal_return_ptr_shift, + avmMini_pc_shift, memTrace_m_val_shift, memTrace_m_tag_shift, + memTrace_m_addr_shift, memTrace_m_rw_shift }; }; RefVector get_unshifted() @@ -450,23 +450,19 @@ class AvmMiniFlavor { }; RefVector get_to_be_shifted() { - return { avmMini_pc, avmMini_internal_return_ptr, - aluChip_alu_u16_r0, aluChip_alu_u16_r7, - aluChip_alu_u16_r6, aluChip_alu_u16_r3, - aluChip_alu_u16_r4, aluChip_alu_u16_r2, - aluChip_alu_u16_r1, aluChip_alu_u16_r5, - memTrace_m_addr, memTrace_m_val, - memTrace_m_tag, memTrace_m_rw }; + return { aluChip_alu_u16_r6, aluChip_alu_u16_r2, aluChip_alu_u16_r3, + aluChip_alu_u16_r4, aluChip_alu_u16_r0, aluChip_alu_u16_r1, + aluChip_alu_u16_r5, aluChip_alu_u16_r7, avmMini_internal_return_ptr, + avmMini_pc, memTrace_m_val, memTrace_m_tag, + memTrace_m_addr, memTrace_m_rw }; }; RefVector get_shifted() { - return { avmMini_pc_shift, avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r0_shift, aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r6_shift, aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r4_shift, aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r1_shift, aluChip_alu_u16_r5_shift, - memTrace_m_addr_shift, memTrace_m_val_shift, - memTrace_m_tag_shift, memTrace_m_rw_shift }; + return { aluChip_alu_u16_r6_shift, aluChip_alu_u16_r2_shift, aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r4_shift, aluChip_alu_u16_r0_shift, aluChip_alu_u16_r1_shift, + aluChip_alu_u16_r5_shift, aluChip_alu_u16_r7_shift, avmMini_internal_return_ptr_shift, + avmMini_pc_shift, memTrace_m_val_shift, memTrace_m_tag_shift, + memTrace_m_addr_shift, memTrace_m_rw_shift }; }; }; @@ -479,13 +475,11 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { avmMini_pc, avmMini_internal_return_ptr, - aluChip_alu_u16_r0, aluChip_alu_u16_r7, - aluChip_alu_u16_r6, aluChip_alu_u16_r3, - aluChip_alu_u16_r4, aluChip_alu_u16_r2, - aluChip_alu_u16_r1, aluChip_alu_u16_r5, - memTrace_m_addr, memTrace_m_val, - memTrace_m_tag, memTrace_m_rw }; + return { aluChip_alu_u16_r6, aluChip_alu_u16_r2, aluChip_alu_u16_r3, + aluChip_alu_u16_r4, aluChip_alu_u16_r0, aluChip_alu_u16_r1, + aluChip_alu_u16_r5, aluChip_alu_u16_r7, avmMini_internal_return_ptr, + avmMini_pc, memTrace_m_val, memTrace_m_tag, + memTrace_m_addr, memTrace_m_rw }; }; // The plookup wires that store plookup read data. 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 index 48a77acbb64..e7ac9b48c96 100644 --- 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 @@ -86,19 +86,19 @@ template struct AvmMiniFullRow { FF avmMini_mem_idx_b{}; FF avmMini_mem_idx_c{}; FF avmMini_last{}; - FF avmMini_pc_shift{}; - FF avmMini_internal_return_ptr_shift{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r7_shift{}; FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u16_r2_shift{}; FF aluChip_alu_u16_r3_shift{}; FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r0_shift{}; FF aluChip_alu_u16_r1_shift{}; FF aluChip_alu_u16_r5_shift{}; - FF memTrace_m_addr_shift{}; + FF aluChip_alu_u16_r7_shift{}; + FF avmMini_internal_return_ptr_shift{}; + FF avmMini_pc_shift{}; FF memTrace_m_val_shift{}; FF memTrace_m_tag_shift{}; + FF memTrace_m_addr_shift{}; FF memTrace_m_rw_shift{}; }; @@ -197,19 +197,19 @@ class AvmMiniCircuitBuilder { polys.avmMini_last[i] = rows[i].avmMini_last; } - polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); - polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); - polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); - polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.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.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); - polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); + polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); + polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); + polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); + polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); + polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); return polys; @@ -248,14 +248,14 @@ class AvmMiniCircuitBuilder { return true; }; - if (!evaluate_relation.template operator()>("avm_mini", - AvmMini_vm::get_relation_label_avm_mini)) { - 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; + } if (!evaluate_relation.template operator()>( "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { return false; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index 13c95170b5f..9cf23c14ff1 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,51 +7,51 @@ namespace proof_system::AvmMini_vm { template struct Alu_chipRow { - FF aluChip_alu_op_sub{}; - FF aluChip_alu_u8_r0{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_cf{}; - FF aluChip_alu_ic{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u128_tag{}; - FF aluChip_alu_u16_r1{}; FF aluChip_alu_u16_r4{}; + FF aluChip_alu_u16_r1{}; + FF aluChip_alu_u16_tag{}; + FF aluChip_alu_u8_tag{}; + FF aluChip_alu_u8_r0{}; FF aluChip_alu_u16_r6{}; + FF aluChip_alu_u8_r1{}; + FF aluChip_alu_u16_r5{}; FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_op_add{}; - FF aluChip_alu_u64_tag{}; - FF aluChip_alu_ff_tag{}; - FF aluChip_alu_u16_r3{}; + FF aluChip_alu_u16_r0{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_ib{}; + FF aluChip_alu_ic{}; FF aluChip_alu_u16_r3_shift{}; FF aluChip_alu_u16_r7{}; - FF aluChip_alu_u16_tag{}; - FF aluChip_alu_op_mul{}; - FF aluChip_alu_u16_r5{}; - FF aluChip_alu_u8_tag{}; + FF aluChip_alu_op_sub{}; + FF aluChip_alu_ff_tag{}; + FF aluChip_alu_u16_r2{}; + FF aluChip_alu_u16_r4_shift{}; + FF aluChip_alu_u64_tag{}; FF aluChip_alu_u32_tag{}; FF aluChip_alu_ia{}; FF aluChip_alu_u64_r0{}; - FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u16_r2{}; - FF aluChip_alu_ib{}; - FF aluChip_alu_u8_r1{}; + FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_u16_r3{}; + FF aluChip_alu_op_mul{}; FF aluChip_alu_u16_r1_shift{}; + FF aluChip_alu_u128_tag{}; FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_u16_r0{}; + FF aluChip_alu_op_add{}; + FF aluChip_alu_cf{}; + FF aluChip_alu_u16_r7_shift{}; }; inline std::string get_relation_label_alu_chip(int index) { switch (index) { + case 6: + return "SUBOP_ADDITION_FF"; + case 17: return "SUBOP_SUBTRACTION_FF"; case 28: return "SUBOP_MULTIPLICATION_FF"; - - case 6: - return "SUBOP_ADDITION_FF"; } return std::to_string(index); } @@ -507,7 +507,7 @@ template class alu_chipImpl { (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, 2, 0, 0 })) + aluChip_alu_u64_r0) * + (((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; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index f4b48ef9ab8..414370a3dd7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,61 +7,61 @@ namespace proof_system::AvmMini_vm { template struct Avm_miniRow { - FF avmMini_mem_idx_a{}; - FF avmMini_tag_err{}; - FF avmMini_sel_op_sub{}; - FF avmMini_rwc{}; + FF avmMini_ia{}; + FF avmMini_pc{}; + FF avmMini_inv{}; FF avmMini_internal_return_ptr{}; FF avmMini_first{}; - FF avmMini_ib{}; - FF avmMini_mem_op_c{}; - FF avmMini_mem_op_a{}; - FF avmMini_sel_internal_return{}; - FF avmMini_sel_halt{}; - FF avmMini_mem_idx_b{}; - FF avmMini_pc{}; FF avmMini_sel_op_div{}; - FF avmMini_sel_op_mul{}; - FF avmMini_sel_op_add{}; - FF avmMini_rwa{}; - FF avmMini_ia{}; - FF avmMini_sel_internal_call{}; + FF avmMini_internal_return_ptr_shift{}; + FF avmMini_mem_idx_a{}; + FF avmMini_mem_op_a{}; FF avmMini_mem_op_b{}; - FF avmMini_sel_jump{}; FF avmMini_op_err{}; + FF avmMini_sel_op_add{}; + FF avmMini_rwa{}; + FF avmMini_rwc{}; FF avmMini_ic{}; + FF avmMini_sel_internal_call{}; FF avmMini_rwb{}; - FF avmMini_inv{}; + FF avmMini_ib{}; + FF avmMini_sel_op_sub{}; + FF avmMini_sel_op_mul{}; + FF avmMini_sel_internal_return{}; + FF avmMini_tag_err{}; + FF avmMini_sel_jump{}; + FF avmMini_mem_op_c{}; FF avmMini_pc_shift{}; - FF avmMini_internal_return_ptr_shift{}; + FF avmMini_mem_idx_b{}; + FF avmMini_sel_halt{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { - case 24: - return "RETURN_POINTER_INCREMENT"; + case 20: + return "SUBOP_DIVISION_ZERO_ERR1"; - case 30: - return "RETURN_POINTER_DECREMENT"; + case 21: + return "SUBOP_DIVISION_ZERO_ERR2"; + + case 36: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; case 35: return "PC_INCREMENT"; + case 24: + return "RETURN_POINTER_INCREMENT"; + case 19: return "SUBOP_DIVISION_FF"; - case 20: - return "SUBOP_DIVISION_ZERO_ERR1"; - case 22: return "SUBOP_ERROR_RELEVANT_OP"; - case 36: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - - case 21: - return "SUBOP_DIVISION_ZERO_ERR2"; + case 30: + return "RETURN_POINTER_DECREMENT"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index 32e3626e5ee..a4c0c2355da 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -68,17 +68,17 @@ [[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 avmMini_pc_shift = View(new_term.avmMini_pc_shift); \ - [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_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 aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ - [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_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); \ [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ + [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 62a871802cb..0d3b2804c07 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -8,40 +8,40 @@ namespace proof_system::AvmMini_vm { template struct Mem_traceRow { FF memTrace_m_last{}; - FF memTrace_m_rw{}; + FF memTrace_m_tag_err{}; + FF memTrace_m_val_shift{}; + FF memTrace_m_val{}; FF memTrace_m_tag{}; FF memTrace_m_lastAccess{}; - FF memTrace_m_addr_shift{}; - FF memTrace_m_in_tag{}; FF memTrace_m_one_min_inv{}; - FF memTrace_m_val_shift{}; FF memTrace_m_tag_shift{}; + FF memTrace_m_in_tag{}; + FF memTrace_m_rw{}; + FF memTrace_m_addr_shift{}; FF memTrace_m_addr{}; - FF memTrace_m_val{}; - FF memTrace_m_tag_err{}; FF memTrace_m_rw_shift{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { - case 6: - return "MEM_READ_WRITE_TAG_CONSISTENCY"; + case 8: + return "MEM_IN_TAG_CONSISTENCY_1"; + + case 4: + return "MEM_LAST_ACCESS_DELIMITER"; case 9: return "MEM_IN_TAG_CONSISTENCY_2"; - case 7: - return "MEM_ZERO_INIT"; - case 5: return "MEM_READ_WRITE_VAL_CONSISTENCY"; - case 8: - return "MEM_IN_TAG_CONSISTENCY_1"; + case 7: + return "MEM_ZERO_INIT"; - case 4: - return "MEM_LAST_ACCESS_DELIMITER"; + case 6: + return "MEM_READ_WRITE_TAG_CONSISTENCY"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp index 9167405cbde..50979a08ba1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp @@ -398,11 +398,11 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui 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 - // a * b_l + a_l * b_h * 2^64 = (CF * 2^65 + R') * 2^128 + c + // a * b_l + a_l * b_h * 2^64 = (CF * 2^64 + R') * 2^128 + c // LHS is c_u256 - c_high // CF bit - carry = ((c_u256 - c_high) >> 193) > 0; + carry = ((c_u256 - c_high) >> 192) > 0; // R' value uint64_t alu_u64_r0 = static_cast(((c_u256 - c_high) >> 128) & uint256_t(UINT64_MAX)); diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index 09341399934..9248cbb8519 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -98,14 +98,14 @@ Row common_validate_sub(std::vector const& trace, return *alu_row; } -Row common_validate_mul(std::vector const& trace, - FF const& a, - FF const& b, - FF const& c, - FF const& addr_a, - FF const& addr_b, - FF const& addr_c, - avm_trace::AvmMemoryTag const tag) +size_t common_validate_mul(std::vector const& trace, + FF const& a, + FF const& b, + FF const& c, + FF const& addr_a, + FF const& addr_b, + FF const& addr_c, + 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); }); @@ -124,7 +124,7 @@ Row common_validate_mul(std::vector const& trace, EXPECT_EQ(row->avmMini_sel_op_mul, FF(1)); EXPECT_EQ(alu_row->aluChip_alu_op_mul, FF(1)); - return *alu_row; + return static_cast(alu_row - trace.begin()); } } // anonymous namespace @@ -231,7 +231,8 @@ TEST_F(AvmMiniArithmeticTestsFF, multiplication) trace_builder.return_op(0, 3); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_mul(trace, FF(20), FF(5), FF(100), FF(2), FF(0), FF(1), AvmMemoryTag::ff); + 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)); @@ -250,7 +251,8 @@ TEST_F(AvmMiniArithmeticTestsFF, multiplicationByZero) trace_builder.return_op(0, 3); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_mul(trace, FF(127), FF(0), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::ff); + 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)); @@ -478,7 +480,8 @@ TEST_F(AvmMiniArithmeticTestsU8, multiplication) trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_mul(trace, FF(13), FF(15), FF(195), FF(0), FF(1), FF(2), AvmMemoryTag::u8); + 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)); @@ -500,7 +503,8 @@ TEST_F(AvmMiniArithmeticTestsU8, multiplicationOverflow) trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_mul(trace, FF(200), FF(170), FF(208), FF(0), FF(1), FF(2), AvmMemoryTag::u8); + 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)); @@ -612,7 +616,9 @@ TEST_F(AvmMiniArithmeticTestsU16, multiplication) trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_mul(trace, FF(200), FF(245), FF(49000), FF(0), FF(1), FF(2), AvmMemoryTag::u16); + auto alu_row_index = + 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)); @@ -634,7 +640,8 @@ TEST_F(AvmMiniArithmeticTestsU16, multiplicationOverflow) trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_mul(trace, FF(512), FF(1024), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::u16); + 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)); @@ -754,8 +761,9 @@ TEST_F(AvmMiniArithmeticTestsU32, multiplication) trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - auto alu_row = + auto alu_row_index = 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)); @@ -780,8 +788,9 @@ TEST_F(AvmMiniArithmeticTestsU32, multiplicationOverflow) trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - auto alu_row = + auto alu_row_index = 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)); @@ -923,8 +932,9 @@ TEST_F(AvmMiniArithmeticTestsU64, multiplication) trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_mul( + auto alu_row_index = common_validate_mul( 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)); @@ -953,7 +963,8 @@ TEST_F(AvmMiniArithmeticTestsU64, multiplicationOverflow) trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_mul(trace, FF(a), FF(b), FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::u64); + 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)); @@ -978,9 +989,9 @@ TEST_F(AvmMiniArithmeticTestsU64, multiplicationOverflow) // Test on basic addition over u128 type. TEST_F(AvmMiniArithmeticTestsU128, addition) { - uint128_t const a = (uint128_t(0x5555222233334444LLU) << 64) + uint128_t(0x88889999AAAABBBBLLU); - uint128_t const b = (uint128_t(0x3333222233331111LLU) << 64) + uint128_t(0x5555111155553333LLU); - uint128_t const c = (uint128_t(0x8888444466665555LLU) << 64) + uint128_t(0xDDDDAAAAFFFFEEEELLU); + uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; + uint128_t const b = (uint128_t{ 0x3333222233331111LLU } << 64) + uint128_t{ 0x5555111155553333LLU }; + uint128_t const c = (uint128_t{ 0x8888444466665555LLU } << 64) + uint128_t{ 0xDDDDAAAAFFFFEEEELLU }; // trace_builder trace_builder.set(a, 8, AvmMemoryTag::u128); @@ -1016,10 +1027,10 @@ TEST_F(AvmMiniArithmeticTestsU128, addition) // Test on basic addition over u128 type with carry. TEST_F(AvmMiniArithmeticTestsU128, 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); + 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 }; uint128_t const c = - (uint128_t(UINT64_MAX) << 64) + uint128_t(UINT64_MAX) - uint128_t(36177345) - uint128_t(72948899); + (uint128_t{ UINT64_MAX } << 64) + uint128_t{ UINT64_MAX } - uint128_t{ 36177345 } - uint128_t{ 72948899 }; // trace_builder trace_builder.set(a, 8, AvmMemoryTag::u128); @@ -1055,8 +1066,8 @@ TEST_F(AvmMiniArithmeticTestsU128, additionCarry) // Test on basic subtraction over u128 type. TEST_F(AvmMiniArithmeticTestsU128, 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); + 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 }; uint128_t const c = 36771555; // 72948899 - 36177344 // trace_builder @@ -1096,9 +1107,9 @@ TEST_F(AvmMiniArithmeticTestsU128, subtraction) // Test on basic subtraction over u128 type with carry. TEST_F(AvmMiniArithmeticTestsU128, subtractionCarry) { - uint128_t const a = (uint128_t(0x5555222233334444LLU) << 64) + uint128_t(0x88889999AAAABBBBLLU); - uint128_t const b = (uint128_t(0x3333222233331111LLU) << 64) + uint128_t(0x5555111155553333LLU); - uint128_t const c = (uint128_t(0x2222000000003333LLU) << 64) + uint128_t(0x3333888855558888LLU); + uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; + uint128_t const b = (uint128_t{ 0x3333222233331111LLU } << 64) + uint128_t{ 0x5555111155553333LLU }; + uint128_t const c = (uint128_t{ 0x2222000000003333LLU } << 64) + uint128_t{ 0x3333888855558888LLU }; // trace_builder trace_builder.set(a, 8, AvmMemoryTag::u128); @@ -1133,6 +1144,100 @@ TEST_F(AvmMiniArithmeticTestsU128, subtractionCarry) validate_trace_proof(std::move(trace)); } +// Test on basic multiplication over u128 type. +TEST_F(AvmMiniArithmeticTestsU128, multiplication) +{ + // trace_builder + trace_builder.set(0x38D64BF685FFBLLU, 0, AvmMemoryTag::u128); + trace_builder.set(0x1F92C762C98DFLLU, 1, AvmMemoryTag::u128); + // Integer multiplication output in HEX: 70289AEB0A7DDA0BAE60CA3A5 + FF c{ uint256_t{ 0xA7DDA0BAE60CA3A5, 0x70289AEB0, 0, 0 } }; + + trace_builder.mul(0, 1, 2, AvmMemoryTag::u128); + trace_builder.return_op(2, 1); + auto trace = trace_builder.finalize(); + + auto alu_row_index = common_validate_mul( + 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)); + + // 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)); + + // 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)); + validate_trace_proof(std::move(trace)); +} + +// Test on multiplication over u128 type with overflow. +TEST_F(AvmMiniArithmeticTestsU128, multiplicationOverflow) +{ + // (2^128 - 2) * (2^128 - 4) = 2^256 - 2^130 - 2^129 + 2^3 + // The above modulo 2^128 = 8 + uint128_t const a = (uint128_t{ UINT64_MAX } << 64) + uint128_t{ UINT64_MAX - 1 }; + uint128_t const b = (uint128_t{ UINT64_MAX } << 64) + uint128_t{ UINT64_MAX - 3 }; + + // trace_builder + trace_builder.set(a, 0, AvmMemoryTag::u128); + trace_builder.set(b, 1, AvmMemoryTag::u128); + + trace_builder.mul(0, 1, 2, AvmMemoryTag::u128); + trace_builder.return_op(2, 1); + auto trace = trace_builder.finalize(); + + auto alu_row_index = common_validate_mul(trace, + FF{ uint256_t::from_uint128(a) }, + FF{ uint256_t::from_uint128(b) }, + FF{ 8 }, + 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)); + + // 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)); + + // 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)); + + // 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 + // (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)); + + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * * NEGATIVE TESTS - Finite Field Type From 5ab8ffce7517ce24fce14874eab1324599d6bb1e Mon Sep 17 00:00:00 2001 From: jeanmon Date: Mon, 15 Jan 2024 14:45:51 +0000 Subject: [PATCH 21/28] 3738 - add basic negative unit tests for each operation and type combination --- barretenberg/cpp/pil/avm/alu_chip.pil | 21 +- .../flavor/generated/AvmMini_flavor.hpp | 74 +++-- .../generated/AvmMini_circuit_builder.hpp | 44 +-- .../relations/generated/AvmMini/alu_chip.hpp | 95 +++++-- .../relations/generated/AvmMini/avm_mini.hpp | 40 +-- .../generated/AvmMini/declare_views.hpp | 18 +- .../relations/generated/AvmMini/mem_trace.hpp | 28 +- .../vm/tests/AvmMini_arithmetic.test.cpp | 253 +++++++++++++++--- 8 files changed, 406 insertions(+), 167 deletions(-) diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil index 0de5c559681..c3df45f2893 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -103,27 +103,32 @@ namespace aluChip(256); // ========= ADDITION Operation Constraints =============================== // ff addition - #[SUBOP_ADDITION_FF] + #[ALU_ADDITION_FF] alu_ff_tag * alu_op_add * (alu_ia + alu_ib - alu_ic) = 0; // u8 addition alu_u8_tag * alu_op_add * (alu_u8_r0 + alu_cf * 2**8 - alu_ia - alu_ib) = 0; + #[ALU_ADDITION_OUT_U8] alu_u8_tag * alu_op_add * (alu_u8_r0 - alu_ic) = 0; // u16 addition alu_u16_tag * alu_op_add * (sum_16 + alu_cf * 2**16 - alu_ia - alu_ib) = 0; + #[ALU_ADDITION_OUT_U16] alu_u16_tag * alu_op_add * (sum_16 - alu_ic) = 0; // u32 addition alu_u32_tag * alu_op_add * (sum_32 + alu_cf * 2**32 - alu_ia - alu_ib) = 0; + #[ALU_ADDITION_OUT_U32] alu_u32_tag * alu_op_add * (sum_32 - alu_ic) = 0; // u64 addition alu_u64_tag * alu_op_add * (sum_64 + alu_cf * 2**64 - alu_ia - alu_ib) = 0; + #[ALU_ADDITION_OUT_U64] alu_u64_tag * alu_op_add * (sum_64 - alu_ic) = 0; // u128 addition alu_u128_tag * alu_op_add * (sum_128 + alu_cf * 2**128 - alu_ia - alu_ib) = 0; + #[ALU_ADDITION_OUT_U128] alu_u128_tag * alu_op_add * (sum_128 - alu_ic) = 0; // ========= SUBTRACTION Operation Constraints =============================== @@ -132,33 +137,38 @@ namespace aluChip(256); // Same constraints as for addition but we swap alu_ia with alu_ic // ff subtraction - #[SUBOP_SUBTRACTION_FF] + #[ALU_SUBTRACTION_FF] alu_ff_tag * alu_op_sub * (alu_ia - alu_ib - alu_ic) = 0; // u8 subtraction + #[ALU_SUBTRACTION_OUT_U8] alu_u8_tag * alu_op_sub * (alu_u8_r0 + alu_cf * 2**8 - alu_ic - alu_ib) = 0; alu_u8_tag * alu_op_sub * (alu_u8_r0 - alu_ia) = 0; // u16 subtraction + #[ALU_SUBTRACTION_OUT_U16] alu_u16_tag * alu_op_sub * (sum_16 + alu_cf * 2**16 - alu_ic - alu_ib) = 0; alu_u16_tag * alu_op_sub * (sum_16 - alu_ia) = 0; // u32 subtraction + #[ALU_SUBTRACTION_OUT_U32] alu_u32_tag * alu_op_sub * (sum_32 + alu_cf * 2**32 - alu_ic - alu_ib) = 0; alu_u32_tag * alu_op_sub * (sum_32 - alu_ia) = 0; // u64 subtraction + #[ALU_SUBTRACTION_OUT_U64] alu_u64_tag * alu_op_sub * (sum_64 + alu_cf * 2**64 - alu_ic - alu_ib) = 0; alu_u64_tag * alu_op_sub * (sum_64 - alu_ia) = 0; // u128 subtraction + #[ALU_SUBTRACTION_OUT_U128] alu_u128_tag * alu_op_sub * (sum_128 + alu_cf * 2**128 - alu_ic - alu_ib) = 0; alu_u128_tag * alu_op_sub * (sum_128 - alu_ia) = 0; // ========= MULTIPLICATION Operation Constraints =============================== // ff multiplication - #[SUBOP_MULTIPLICATION_FF] + #[ALU_MULTIPLICATION_FF] alu_ff_tag * alu_op_mul * (alu_ia * alu_ib - alu_ic) = 0; // We need 2k bits to express the product (a*b) over the integer, i.e., for type uk @@ -166,18 +176,22 @@ namespace aluChip(256); // u8 multiplication alu_u8_tag * alu_op_mul * (alu_u8_r0 + alu_u8_r1 * 2**8 - alu_ia * alu_ib) = 0; + #[ALU_MULTIPLICATION_OUT_U8] alu_u8_tag * alu_op_mul * (alu_u8_r0 - alu_ic) = 0; // u16 multiplication alu_u16_tag * alu_op_mul * (sum_32 - alu_ia * alu_ib) = 0; + #[ALU_MULTIPLICATION_OUT_U16] alu_u16_tag * alu_op_mul * (sum_16 - alu_ic) = 0; // u32 multiplication alu_u32_tag * alu_op_mul * (sum_64 - alu_ia * alu_ib) = 0; + #[ALU_MULTIPLICATION_OUT_U32] alu_u32_tag * alu_op_mul * (sum_32 - alu_ic) = 0; // u64 multiplication alu_u64_tag * alu_op_mul * (sum_128 - alu_ia * alu_ib) = 0; + #[ALU_MULTIPLICATION_OUT_U64] alu_u64_tag * alu_op_mul * (sum_64 - alu_ic) = 0; // ========= u128 MULTIPLICATION Operation Constraints =============================== @@ -206,6 +220,7 @@ namespace aluChip(256); // Arithmetic relations alu_u128_tag * alu_op_mul * (sum_64 + sum_high_64 * 2**64 - alu_ia) = 0; alu_u128_tag * alu_op_mul * (sum_shifted_64 + sum_high_shifted_64 * 2**64 - alu_ib) = 0; + #[ALU_MULTIPLICATION_OUT_U128] alu_u128_tag * alu_op_mul * ( alu_ia * sum_shifted_64 + sum_64 * sum_high_shifted_64 * 2**64 diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index 0073d399975..858ce96e3f1 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -43,7 +43,7 @@ class AvmMiniFlavor { // the unshifted and one for the shifted static constexpr size_t NUM_ALL_ENTITIES = 80; - using Relations = std::tuple, AvmMini_vm::alu_chip, AvmMini_vm::mem_trace>; + using Relations = std::tuple, AvmMini_vm::avm_mini, AvmMini_vm::mem_trace>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -281,20 +281,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - avmMini_pc_shift, - avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r4_shift, aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r0_shift, aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r4_shift, + avmMini_internal_return_ptr_shift, + avmMini_pc_shift, memTrace_m_val_shift, - memTrace_m_addr_shift, + memTrace_m_tag_shift, memTrace_m_rw_shift, - memTrace_m_tag_shift) + memTrace_m_addr_shift) RefVector get_wires() { @@ -364,20 +364,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - avmMini_pc_shift, - avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r4_shift, aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r0_shift, aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r4_shift, + avmMini_internal_return_ptr_shift, + avmMini_pc_shift, memTrace_m_val_shift, - memTrace_m_addr_shift, + memTrace_m_tag_shift, memTrace_m_rw_shift, - memTrace_m_tag_shift }; + memTrace_m_addr_shift }; }; RefVector get_unshifted() { @@ -450,23 +450,19 @@ class AvmMiniFlavor { }; RefVector get_to_be_shifted() { - return { avmMini_pc, avmMini_internal_return_ptr, - aluChip_alu_u16_r7, aluChip_alu_u16_r3, - aluChip_alu_u16_r6, aluChip_alu_u16_r4, - aluChip_alu_u16_r1, aluChip_alu_u16_r0, - aluChip_alu_u16_r2, aluChip_alu_u16_r5, - memTrace_m_val, memTrace_m_addr, - memTrace_m_rw, memTrace_m_tag }; + return { aluChip_alu_u16_r1, aluChip_alu_u16_r2, aluChip_alu_u16_r0, + aluChip_alu_u16_r5, aluChip_alu_u16_r7, aluChip_alu_u16_r6, + aluChip_alu_u16_r3, aluChip_alu_u16_r4, avmMini_internal_return_ptr, + avmMini_pc, memTrace_m_val, memTrace_m_tag, + memTrace_m_rw, memTrace_m_addr }; }; RefVector get_shifted() { - return { avmMini_pc_shift, avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r7_shift, aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r6_shift, aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r1_shift, aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r2_shift, aluChip_alu_u16_r5_shift, - memTrace_m_val_shift, memTrace_m_addr_shift, - memTrace_m_rw_shift, memTrace_m_tag_shift }; + return { aluChip_alu_u16_r1_shift, aluChip_alu_u16_r2_shift, aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r5_shift, aluChip_alu_u16_r7_shift, aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r3_shift, aluChip_alu_u16_r4_shift, avmMini_internal_return_ptr_shift, + avmMini_pc_shift, memTrace_m_val_shift, memTrace_m_tag_shift, + memTrace_m_rw_shift, memTrace_m_addr_shift }; }; }; @@ -479,13 +475,11 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { avmMini_pc, avmMini_internal_return_ptr, - aluChip_alu_u16_r7, aluChip_alu_u16_r3, - aluChip_alu_u16_r6, aluChip_alu_u16_r4, - aluChip_alu_u16_r1, aluChip_alu_u16_r0, - aluChip_alu_u16_r2, aluChip_alu_u16_r5, - memTrace_m_val, memTrace_m_addr, - memTrace_m_rw, memTrace_m_tag }; + return { aluChip_alu_u16_r1, aluChip_alu_u16_r2, aluChip_alu_u16_r0, + aluChip_alu_u16_r5, aluChip_alu_u16_r7, aluChip_alu_u16_r6, + aluChip_alu_u16_r3, aluChip_alu_u16_r4, avmMini_internal_return_ptr, + avmMini_pc, memTrace_m_val, memTrace_m_tag, + memTrace_m_rw, memTrace_m_addr }; }; // The plookup wires that store plookup read data. 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 index 4286d584cc2..e45bdf43598 100644 --- 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 @@ -87,20 +87,20 @@ template struct AvmMiniFullRow { FF avmMini_mem_idx_b{}; FF avmMini_mem_idx_c{}; FF avmMini_last{}; - FF avmMini_pc_shift{}; - FF avmMini_internal_return_ptr_shift{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r3_shift{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r4_shift{}; FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r0_shift{}; FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r0_shift{}; FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_u16_r4_shift{}; + FF avmMini_internal_return_ptr_shift{}; + FF avmMini_pc_shift{}; FF memTrace_m_val_shift{}; - FF memTrace_m_addr_shift{}; - FF memTrace_m_rw_shift{}; FF memTrace_m_tag_shift{}; + FF memTrace_m_rw_shift{}; + FF memTrace_m_addr_shift{}; }; class AvmMiniCircuitBuilder { @@ -198,20 +198,20 @@ class AvmMiniCircuitBuilder { polys.avmMini_last[i] = rows[i].avmMini_last; } - polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); - polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); - polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); - polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); - polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); - polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); - polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.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_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); + polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); + polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); + polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); + polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); + polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.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_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); + polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); + polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); return polys; } @@ -249,14 +249,14 @@ class AvmMiniCircuitBuilder { return true; }; - if (!evaluate_relation.template operator()>("avm_mini", - AvmMini_vm::get_relation_label_avm_mini)) { - 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; + } if (!evaluate_relation.template operator()>( "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { return false; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index 9d43b11f0cf..42081891229 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,51 +7,96 @@ namespace proof_system::AvmMini_vm { template struct Alu_chipRow { - FF aluChip_alu_u16_r7{}; - FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r1_shift{}; + FF aluChip_alu_u16_r6{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u8_tag{}; + FF aluChip_alu_op_mul{}; FF aluChip_alu_u16_r0{}; - FF aluChip_alu_u16_r3_shift{}; - FF aluChip_alu_u32_tag{}; + FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_op_sub{}; + FF aluChip_alu_ff_tag{}; + FF aluChip_alu_u16_r5_shift{}; FF aluChip_alu_ic{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r3{}; + FF aluChip_alu_u32_tag{}; + FF aluChip_alu_u16_r7_shift{}; FF aluChip_alu_u8_r0{}; - FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_cf{}; - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r0_shift{}; FF aluChip_alu_u16_tag{}; + FF aluChip_alu_u16_r6_shift{}; FF aluChip_alu_u16_r5{}; - FF aluChip_alu_op_mul{}; - FF aluChip_alu_u8_tag{}; FF aluChip_alu_ia{}; + FF aluChip_alu_u64_tag{}; FF aluChip_alu_u16_r1{}; - FF aluChip_alu_u128_tag{}; - FF aluChip_alu_u64_r0{}; + FF aluChip_alu_cf{}; FF aluChip_alu_op_add{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_ff_tag{}; - FF aluChip_alu_u64_tag{}; - FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r7{}; + FF aluChip_alu_u16_r3_shift{}; FF aluChip_alu_ib{}; - FF aluChip_alu_op_sub{}; - FF aluChip_alu_u16_r4{}; + FF aluChip_alu_u64_r0{}; + FF aluChip_alu_u128_tag{}; + FF aluChip_alu_u16_r3{}; FF aluChip_alu_u8_r1{}; - FF aluChip_alu_u16_r6{}; FF aluChip_alu_u16_r2{}; + FF aluChip_alu_u16_r4_shift{}; + FF aluChip_alu_u16_r4{}; }; inline std::string get_relation_label_alu_chip(int index) { switch (index) { + case 28: + return "ALU_MULTIPLICATION_FF"; + + case 34: + return "ALU_MULTIPLICATION_OUT_U32"; + + case 20: + return "ALU_SUBTRACTION_OUT_U16"; + + case 26: + return "ALU_SUBTRACTION_OUT_U128"; + + case 32: + return "ALU_MULTIPLICATION_OUT_U16"; + + case 8: + return "ALU_ADDITION_OUT_U8"; + + case 16: + return "ALU_ADDITION_OUT_U128"; + + case 22: + return "ALU_SUBTRACTION_OUT_U32"; + + case 14: + return "ALU_ADDITION_OUT_U64"; + + case 12: + return "ALU_ADDITION_OUT_U32"; + + case 18: + return "ALU_SUBTRACTION_OUT_U8"; + + case 36: + return "ALU_MULTIPLICATION_OUT_U64"; + case 17: - return "SUBOP_SUBTRACTION_FF"; + return "ALU_SUBTRACTION_FF"; case 6: - return "SUBOP_ADDITION_FF"; + return "ALU_ADDITION_FF"; - case 28: - return "SUBOP_MULTIPLICATION_FF"; + case 39: + return "ALU_MULTIPLICATION_OUT_U128"; + + case 10: + return "ALU_ADDITION_OUT_U16"; + + case 24: + return "ALU_SUBTRACTION_OUT_U64"; + + case 30: + return "ALU_MULTIPLICATION_OUT_U8"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index 61d91603172..d41af9f2b90 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -8,32 +8,32 @@ namespace proof_system::AvmMini_vm { template struct Avm_miniRow { FF avmMini_mem_op_b{}; - FF avmMini_ib{}; + FF avmMini_internal_return_ptr{}; + FF avmMini_first{}; + FF avmMini_pc{}; + FF avmMini_ia{}; + FF avmMini_mem_idx_a{}; + FF avmMini_sel_op_div{}; + FF avmMini_sel_halt{}; + FF avmMini_sel_jump{}; + FF avmMini_sel_op_add{}; + FF avmMini_rwb{}; FF avmMini_mem_op_a{}; + FF avmMini_ib{}; FF avmMini_ic{}; + FF avmMini_internal_return_ptr_shift{}; FF avmMini_sel_internal_return{}; FF avmMini_mem_op_c{}; + FF avmMini_rwc{}; + FF avmMini_sel_internal_call{}; FF avmMini_op_err{}; FF avmMini_pc_shift{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_internal_return_ptr{}; FF avmMini_mem_idx_b{}; - FF avmMini_mem_idx_a{}; - FF avmMini_pc{}; - FF avmMini_inv{}; - FF avmMini_first{}; + FF avmMini_sel_op_mul{}; FF avmMini_sel_op_sub{}; - FF avmMini_sel_halt{}; - FF avmMini_sel_internal_call{}; + FF avmMini_inv{}; FF avmMini_tag_err{}; - FF avmMini_rwb{}; - FF avmMini_sel_jump{}; - FF avmMini_ia{}; - FF avmMini_rwc{}; - FF avmMini_sel_op_div{}; - FF avmMini_sel_op_mul{}; FF avmMini_rwa{}; - FF avmMini_sel_op_add{}; }; inline std::string get_relation_label_avm_mini(int index) @@ -42,8 +42,8 @@ inline std::string get_relation_label_avm_mini(int index) case 30: return "RETURN_POINTER_DECREMENT"; - case 20: - return "SUBOP_DIVISION_ZERO_ERR1"; + case 22: + return "SUBOP_ERROR_RELEVANT_OP"; case 21: return "SUBOP_DIVISION_ZERO_ERR2"; @@ -54,8 +54,8 @@ inline std::string get_relation_label_avm_mini(int index) case 36: return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - case 22: - return "SUBOP_ERROR_RELEVANT_OP"; + case 20: + return "SUBOP_DIVISION_ZERO_ERR1"; case 24: return "RETURN_POINTER_INCREMENT"; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index cab59e56efc..57d9ea496ed 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -68,17 +68,17 @@ [[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 avmMini_pc_shift = View(new_term.avmMini_pc_shift); \ - [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_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_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_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); \ [[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 memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ - [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); + [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 94e72196363..1e8ad76f7c0 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,41 +7,41 @@ namespace proof_system::AvmMini_vm { template struct Mem_traceRow { + FF memTrace_m_last{}; FF memTrace_m_rw{}; FF memTrace_m_tag_err{}; FF memTrace_m_val_shift{}; - FF memTrace_m_tag{}; + FF memTrace_m_val{}; + FF memTrace_m_tag_shift{}; FF memTrace_m_in_tag{}; FF memTrace_m_one_min_inv{}; - FF memTrace_m_lastAccess{}; - FF memTrace_m_val{}; - FF memTrace_m_addr_shift{}; FF memTrace_m_rw_shift{}; - FF memTrace_m_tag_shift{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_lastAccess{}; + FF memTrace_m_tag{}; FF memTrace_m_addr{}; - FF memTrace_m_last{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { - case 7: - return "MEM_ZERO_INIT"; - case 9: return "MEM_IN_TAG_CONSISTENCY_2"; - case 8: - return "MEM_IN_TAG_CONSISTENCY_1"; - case 4: return "MEM_LAST_ACCESS_DELIMITER"; + case 5: + return "MEM_READ_WRITE_VAL_CONSISTENCY"; + + case 7: + return "MEM_ZERO_INIT"; + case 6: return "MEM_READ_WRITE_TAG_CONSISTENCY"; - case 5: - return "MEM_READ_WRITE_VAL_CONSISTENCY"; + case 8: + return "MEM_IN_TAG_CONSISTENCY_1"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index 9248cbb8519..6fd76ce33aa 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -127,6 +127,60 @@ size_t common_validate_mul(std::vector const& trace, return static_cast(alu_row - trace.begin()); } +// This function generates a mutated trace of an addition where a and b are the passed inputs. +// a and b are stored in memory indices 0 and 1. c_mutated is the wrong result of the addition +// 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(); + trace_builder.set(uint128_t{ a }, 0, tag); + trace_builder.set(uint128_t{ b }, 1, tag); + trace_builder.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); }; + tests_avm::mutate_ic_in_trace(trace, select_row, c_mutated, true); + + return trace; +} + +// This function generates a mutated trace of a subtraction where a and b are the passed inputs. +// a and b are stored in memory indices 0 and 1. c_mutated is the wrong result of the subtraction +// 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(); + trace_builder.set(uint128_t{ a }, 0, tag); + trace_builder.set(uint128_t{ b }, 1, tag); + trace_builder.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); }; + tests_avm::mutate_ic_in_trace(trace, select_row, c_mutated, true); + + return trace; +} + +// This function generates a mutated trace of a multiplication where a and b are the passed inputs. +// a and b are stored in memory indices 0 and 1. c_mutated is the wrong result of the multiplication +// 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(); + trace_builder.set(uint128_t{ a }, 0, tag); + trace_builder.set(uint128_t{ b }, 1, tag); + trace_builder.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); }; + tests_avm::mutate_ic_in_trace(trace, select_row, c_mutated, true); + + return trace; +} + } // anonymous namespace namespace tests_avm { @@ -153,6 +207,11 @@ class AvmMiniArithmeticTestsU64 : public AvmMiniArithmeticTests {}; class AvmMiniArithmeticTestsU128 : public AvmMiniArithmeticTests {}; class AvmMiniArithmeticNegativeTestsFF : public AvmMiniArithmeticTests {}; +class AvmMiniArithmeticNegativeTestsU8 : public AvmMiniArithmeticTests {}; +class AvmMiniArithmeticNegativeTestsU16 : public AvmMiniArithmeticTests {}; +class AvmMiniArithmeticNegativeTestsU32 : public AvmMiniArithmeticTests {}; +class AvmMiniArithmeticNegativeTestsU64 : public AvmMiniArithmeticTests {}; +class AvmMiniArithmeticNegativeTestsU128 : public AvmMiniArithmeticTests {}; /****************************************************************************** * @@ -1251,7 +1310,7 @@ TEST_F(AvmMiniArithmeticTestsU128, multiplicationOverflow) * and division by having dedicated unit test for each of them. * A typical pattern is to wrongly mutate the result of the operation. The memory trace * is consistently adapted so that the negative test is applying to the relation - * if the arithmetic operation and not the layout of the memory trace. + * of the arithmetic operation and not the layout of the memory trace. * * Finding the row pertaining to the arithmetic operation is done through * a scan of all rows and stopping at the first one with the corresponding @@ -1259,52 +1318,29 @@ TEST_F(AvmMiniArithmeticTestsU128, multiplicationOverflow) * will still correctly work along the development of the AVM. ******************************************************************************/ +/****************************************************************************** + * Negative Tests - FF + ******************************************************************************/ + // Test on basic incorrect addition over finite field type. TEST_F(AvmMiniArithmeticNegativeTestsFF, addition) { - trace_builder.call_data_copy(0, 3, 0, std::vector{ 37, 4, 11 }); - - // Memory layout: [37,4,11,0,0,0,....] - trace_builder.add(0, 1, 4, AvmMemoryTag::ff); // [37,4,11,0,41,0,....] - trace_builder.halt(); - auto trace = trace_builder.finalize(); - - auto select_row = [](Row r) { return r.avmMini_sel_op_add == FF(1); }; - mutate_ic_in_trace(trace, std::move(select_row), FF(40), true); - EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_ADDITION_FF"); + 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_ADDITION_FF"); } // Test on basic incorrect subtraction over finite field type. TEST_F(AvmMiniArithmeticNegativeTestsFF, subtraction) { - trace_builder.call_data_copy(0, 3, 0, std::vector{ 8, 4, 17 }); - - // Memory layout: [8,4,17,0,0,0,....] - trace_builder.sub(2, 0, 1, AvmMemoryTag::ff); // [8,9,17,0,0,0....] - trace_builder.halt(); - - auto trace = trace_builder.finalize(); - - auto select_row = [](Row r) { return r.avmMini_sel_op_sub == FF(1); }; - mutate_ic_in_trace(trace, std::move(select_row), FF(-9), true); - - EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_SUBTRACTION_FF"); + 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_SUBTRACTION_FF"); } // Test on basic incorrect multiplication over finite field type. TEST_F(AvmMiniArithmeticNegativeTestsFF, multiplication) { - trace_builder.call_data_copy(0, 3, 0, std::vector{ 5, 0, 20 }); - - // Memory layout: [5,0,20,0,0,0,....] - trace_builder.mul(2, 0, 1, AvmMemoryTag::ff); // [5,100,20,0,0,0....] - trace_builder.halt(); - auto trace = trace_builder.finalize(); - - auto select_row = [](Row r) { return r.avmMini_sel_op_mul == FF(1); }; - mutate_ic_in_trace(trace, std::move(select_row), FF(1000), true); - - EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_MULTIPLICATION_FF"); + 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. @@ -1441,4 +1477,153 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_ERROR_RELEVANT_OP"); } +/****************************************************************************** + * Negative Tests - U8 + ******************************************************************************/ + +// Test on basic incorrect addition over U8. +TEST_F(AvmMiniArithmeticNegativeTestsU8, 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_ADDITION_OUT_U8"); +} + +// Test on basic incorrect subtraction over U8. +TEST_F(AvmMiniArithmeticNegativeTestsU8, 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_SUBTRACTION_OUT_U8"); +} + +// Test on basic incorrect multiplication over U8. +TEST_F(AvmMiniArithmeticNegativeTestsU8, 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_MULTIPLICATION_OUT_U8"); +} + +/****************************************************************************** + * Negative Tests - U16 + ******************************************************************************/ + +// Test on basic incorrect addition over U16. +TEST_F(AvmMiniArithmeticNegativeTestsU16, 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_ADDITION_OUT_U16"); +} + +// Test on basic incorrect subtraction over U16. +TEST_F(AvmMiniArithmeticNegativeTestsU16, 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_SUBTRACTION_OUT_U16"); +} + +// Test on basic incorrect multiplication over U16. +TEST_F(AvmMiniArithmeticNegativeTestsU16, 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_MULTIPLICATION_OUT_U16"); +} + +/****************************************************************************** + * Negative Tests - U32 + ******************************************************************************/ + +// Test on basic incorrect addition over U32. +TEST_F(AvmMiniArithmeticNegativeTestsU32, 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_ADDITION_OUT_U32"); +} + +// Test on basic incorrect subtraction over U32. +TEST_F(AvmMiniArithmeticNegativeTestsU32, 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_SUBTRACTION_OUT_U32"); +} + +// Test on basic incorrect multiplication over U32. +TEST_F(AvmMiniArithmeticNegativeTestsU32, 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_MULTIPLICATION_OUT_U32"); +} + +/****************************************************************************** + * Negative Tests - U64 + ******************************************************************************/ + +// Test on basic incorrect addition over U64. +TEST_F(AvmMiniArithmeticNegativeTestsU64, addition) +{ + auto trace = gen_mutated_trace_add( + FF(3324236423198282341LLU), FF(999999991111133221LLU), FF(1222222222236LLU), AvmMemoryTag::u64); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADDITION_OUT_U64"); +} + +// Test on basic incorrect subtraction over U64. +TEST_F(AvmMiniArithmeticNegativeTestsU64, subtraction) +{ + auto trace = + gen_mutated_trace_sub(FF(399988877723434LLU), FF(UINT64_MAX), FF(25373324332342LLU), AvmMemoryTag::u64); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_SUBTRACTION_OUT_U64"); +} + +// Test on basic incorrect multiplication over U64. +TEST_F(AvmMiniArithmeticNegativeTestsU64, multiplication) +{ + auto trace = + gen_mutated_trace_mul(FF(399988877723434LLU), FF(9998887772343LLU), FF(9283674827534LLU), AvmMemoryTag::u64); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MULTIPLICATION_OUT_U64"); +} + +/****************************************************************************** + * Negative Tests - U128 + ******************************************************************************/ + +// Test on basic incorrect addition over U128. +TEST_F(AvmMiniArithmeticNegativeTestsU128, addition) +{ + uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; + uint128_t const b = (uint128_t{ 0x3333222233331111LLU } << 64) + uint128_t{ 0x5555111155553333LLU }; + uint128_t const c = (uint128_t{ 0x8888444466665555LLU } << 64) + uint128_t{ 0xDDDDAAAAFFFFEEEFLLU }; + + auto trace = gen_mutated_trace_add(FF{ uint256_t::from_uint128(a) }, + FF{ uint256_t::from_uint128(b) }, + FF{ uint256_t::from_uint128(c) }, + AvmMemoryTag::u128); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADDITION_OUT_U128"); +} + +// Test on basic incorrect subtraction over U128. +TEST_F(AvmMiniArithmeticNegativeTestsU128, subtraction) +{ + uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; + uint128_t const b = (uint128_t{ 0x7333222233331111LLU } << 64) + uint128_t{ 0x5555111155553333LLU }; + uint128_t const c = (uint128_t{ 0x8888444466665555LLU } << 64) + uint128_t{ 0xDDDDALLU }; + + auto trace = gen_mutated_trace_sub(FF{ uint256_t::from_uint128(a) }, + FF{ uint256_t::from_uint128(b) }, + FF{ uint256_t::from_uint128(c) }, + AvmMemoryTag::u128); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_SUBTRACTION_OUT_U128"); +} + +// Test on basic incorrect multiplication over U128. +TEST_F(AvmMiniArithmeticNegativeTestsU128, multiplication) +{ + uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; + uint128_t const b = (uint128_t{ 0x7333222233331111LLU } << 64) + uint128_t{ 0x5555111155553333LLU }; + uint128_t const c = (uint128_t{ 0x8888444466665555LLU } << 64) + uint128_t{ 0xDDDDALLU }; + + auto trace = gen_mutated_trace_mul(FF{ uint256_t::from_uint128(a) }, + FF{ uint256_t::from_uint128(b) }, + FF{ uint256_t::from_uint128(c) }, + AvmMemoryTag::u128); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MULTIPLICATION_OUT_U128"); +} + } // namespace tests_avm \ No newline at end of file From 394d18ca6e05591f92893eadaf36da550eb73f04 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Wed, 17 Jan 2024 09:22:24 +0000 Subject: [PATCH 22/28] 3738 - rewrite addition and subtraction relations according to Zac's feedback. Witnesss generation and unit tests were adapted accordingly. --- barretenberg/cpp/pil/avm/alu_chip.pil | 179 ++++---- .../flavor/generated/AvmMini_flavor.hpp | 99 +++-- .../generated/AvmMini_circuit_builder.hpp | 44 +- .../relations/generated/AvmMini/alu_chip.hpp | 403 +++++------------- .../relations/generated/AvmMini/avm_mini.hpp | 66 +-- .../generated/AvmMini/declare_views.hpp | 20 +- .../relations/generated/AvmMini/mem_trace.hpp | 32 +- .../vm/avm_trace/AvmMini_alu_trace.cpp | 211 +++------ .../vm/avm_trace/AvmMini_trace.cpp | 1 + .../vm/tests/AvmMini_arithmetic.test.cpp | 196 +++++---- 10 files changed, 529 insertions(+), 722 deletions(-) diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil index c3df45f2893..83d60257903 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -61,6 +61,8 @@ namespace aluChip(256); alu_u128_tag * (1 - alu_u128_tag) = 0; // Operation selectors are copied from main table and do not need to be constrained here. + // TODO: Ensure mutual exclusion of alu_op_add and alu_op_sub as some relations below + // requires it. // ========= Inter-table Constraints ====================================== // TODO: Equivalence between intermediate registers, clk, type flag, operation @@ -71,99 +73,94 @@ namespace aluChip(256); // Main trick for arithmetic operations modulo 2^k is to perform the operation // over the integers and expressing the result as low + high * 2^k with low // smaller than 2^k. low is used as the output. This works as long this does - // not overflow the underlying finite field order (u128 multiplication will be - // handled differently). If we want to prove that c = OP(a,b) where OP denotes - // an arithmetic operation modulo 2^k, we need two relations: - // (1) low + high * 2^k - OP(a,b) = 0 + // not underflow/overflow the underlying finite field order (u128 multiplication + // will be handled differently). If we want to prove that c = OP(a,b) where OP + // denotes an arithmetic operation modulo 2^k, we can achieve this with two relations: + // (1) low + high * 2^k - OP'(a,b) = 0 // (2) low - c = 0 // + // where OP' denotes the same operation as OP but over the integers (not mod 2^k). // We support u8, u16, u32, u64, u128 types and decompose low into // smaller bit slices, e.g., 16. For instance, low = s_0 + s_1 * 2^16 + s_2 * 2^32 + ... // The slices have to be range constrained and there is a trade-off between the // number of registers and complexity of the range constraints. - // TODO: Determine the best slice size allocation. Note that we might choose different - // slice sizes for the different types. At this stage, it is still unknown how this - // allocation affects the performance. // - // Preliminary choice: We use one u8 register to support u8 operations and up to 8 u16 - // registers for the other types. - + // Optimization: We will capture the relation (1) for all types under the same umbrella + // by re-using the decomposition used for u128 type for the lower types. + // This works because any larger power of 2^k divides 2^l whenever k <= l. + // To be able to express "low" for u8, we need a 8-bit limb for the lowest + // bits. A bit decomposition covering all types is: + // s8_0 + s8_1 * 2^8 + s16_0 * 2^16 + s16_1 * 2^32 ... + s16_6 * 2^112 + carry * 2^128 - OP'(a,b) = 0 + // where s8_i's are 8-bit registers and s16's 16-bit registers. + // For type uk, we set low to the k-bit truncated part of register decomposition. + // As example, for u32: low = s8_0 + s8_1 * 2^8 + s16_0 * 2^16 + // and for u8: low = s8_0 + // + // TODO: It is open whether we might get efficiency gain to use larger registers for the higher + // parts of the bit decomposition. // ============= Helper polynomial terms ============================ // These are intermediate polynomial terms which are not commited but - // serves to express commited polynomials in a more concise way. - - // 16-bit slice partial sums - pol sum_16 = alu_u16_r0; - pol sum_32 = sum_16 + alu_u16_r1 * 2**16; - pol sum_64 = sum_32 + alu_u16_r2 * 2**32 + alu_u16_r3 * 2**48; - pol sum_96 = sum_64 + alu_u16_r4 * 2**64 + alu_u16_r5 * 2**80; - pol sum_128 = sum_96 + alu_u16_r6 * 2**96 + alu_u16_r7 * 2**112; - - // ========= ADDITION Operation Constraints =============================== - - // ff addition - #[ALU_ADDITION_FF] - alu_ff_tag * alu_op_add * (alu_ia + alu_ib - alu_ic) = 0; - - // u8 addition - alu_u8_tag * alu_op_add * (alu_u8_r0 + alu_cf * 2**8 - alu_ia - alu_ib) = 0; - #[ALU_ADDITION_OUT_U8] - alu_u8_tag * alu_op_add * (alu_u8_r0 - alu_ic) = 0; - - // u16 addition - alu_u16_tag * alu_op_add * (sum_16 + alu_cf * 2**16 - alu_ia - alu_ib) = 0; - #[ALU_ADDITION_OUT_U16] - alu_u16_tag * alu_op_add * (sum_16 - alu_ic) = 0; - - // u32 addition - alu_u32_tag * alu_op_add * (sum_32 + alu_cf * 2**32 - alu_ia - alu_ib) = 0; - #[ALU_ADDITION_OUT_U32] - alu_u32_tag * alu_op_add * (sum_32 - alu_ic) = 0; - - // u64 addition - alu_u64_tag * alu_op_add * (sum_64 + alu_cf * 2**64 - alu_ia - alu_ib) = 0; - #[ALU_ADDITION_OUT_U64] - alu_u64_tag * alu_op_add * (sum_64 - alu_ic) = 0; - - // u128 addition - alu_u128_tag * alu_op_add * (sum_128 + alu_cf * 2**128 - alu_ia - alu_ib) = 0; - #[ALU_ADDITION_OUT_U128] - alu_u128_tag * alu_op_add * (sum_128 - alu_ic) = 0; - - // ========= SUBTRACTION Operation Constraints =============================== - - // a - b = c <==> c + b = a (mod 2^k) - // Same constraints as for addition but we swap alu_ia with alu_ic - - // ff subtraction - #[ALU_SUBTRACTION_FF] - alu_ff_tag * alu_op_sub * (alu_ia - alu_ib - alu_ic) = 0; - - // u8 subtraction - #[ALU_SUBTRACTION_OUT_U8] - alu_u8_tag * alu_op_sub * (alu_u8_r0 + alu_cf * 2**8 - alu_ic - alu_ib) = 0; - alu_u8_tag * alu_op_sub * (alu_u8_r0 - alu_ia) = 0; - - // u16 subtraction - #[ALU_SUBTRACTION_OUT_U16] - alu_u16_tag * alu_op_sub * (sum_16 + alu_cf * 2**16 - alu_ic - alu_ib) = 0; - alu_u16_tag * alu_op_sub * (sum_16 - alu_ia) = 0; - - // u32 subtraction - #[ALU_SUBTRACTION_OUT_U32] - alu_u32_tag * alu_op_sub * (sum_32 + alu_cf * 2**32 - alu_ic - alu_ib) = 0; - alu_u32_tag * alu_op_sub * (sum_32 - alu_ia) = 0; - - // u64 subtraction - #[ALU_SUBTRACTION_OUT_U64] - alu_u64_tag * alu_op_sub * (sum_64 + alu_cf * 2**64 - alu_ic - alu_ib) = 0; - alu_u64_tag * alu_op_sub * (sum_64 - alu_ia) = 0; - - // u128 subtraction - #[ALU_SUBTRACTION_OUT_U128] - alu_u128_tag * alu_op_sub * (sum_128 + alu_cf * 2**128 - alu_ic - alu_ib) = 0; - alu_u128_tag * alu_op_sub * (sum_128 - alu_ia) = 0; + // serves to an algebraic expression of commited polynomials in a more concise way. + + // Bit slices partial sums + pol sum_8 = alu_u8_r0; + pol sum_16 = sum_8 + alu_u8_r1 * 2**8; + pol sum_32 = sum_16 + alu_u16_r0 * 2**16; + pol sum_64 = sum_32 + alu_u16_r1 * 2**32 + alu_u16_r2 * 2**48; + pol sum_96 = sum_64 + alu_u16_r3 * 2**64 + alu_u16_r4 * 2**80; + pol sum_128 = sum_96 + alu_u16_r5 * 2**96 + alu_u16_r6 * 2**112; + + // TODO(clean): 16-bit slice partial sums for legacy multiplication + pol mul_sum_16 = alu_u16_r0; + pol mul_sum_32 = mul_sum_16 + alu_u16_r1 * 2**16; + pol mul_sum_64 = mul_sum_32 + alu_u16_r2 * 2**32 + alu_u16_r3 * 2**48; + pol mul_sum_96 = mul_sum_64 + alu_u16_r4 * 2**64 + alu_u16_r5 * 2**80; + pol mul_sum_128 = mul_sum_96 + alu_u16_r6 * 2**96 + alu_u16_r7 * 2**112; + + // ========= ADDITION/SUBTRACTION Operation Constraints =============================== + // + // Addition and subtraction relations are very similar and will be consolidated. + // For the addition we have to replace OP'(a,b) in the above relation by a+b and + // for subtraction by a-b. Using operation selector values to toggle "+b" vs. "-b" + // makes the deal with the adaptation that the carry term needs to be subtracted + // instead of being added. To sumarize, for the first relation, addition needs to + // satisfy: + // sum_128 + carry * 2^128 - a - b = 0 + // while the subtraction satisfies: + // sum_128 - carry * 2^128 - a + b = 0 + // + // Finally, we would like this relation to also satisfy the addition over the finite field. + // For this, we add c in the relation conditoned by the ff type selector alu_ff_tag. We emphasize + // that this relation alone for FF will not imply correctness of the FF addition. We only want + // it to be satisfied. A separate relation will ensure correctness of it. + + #[ALU_ADD_SUB_COMMON] + (alu_op_add + alu_op_sub) * (sum_128 - alu_ia + alu_ff_tag * alu_ic) + (alu_op_add - alu_op_sub) * (alu_cf * 2**128 - alu_ib) = 0; + + // ff addition/subtraction + #[ALU_ADD_SUB_FF] + alu_ff_tag * (alu_op_add + alu_op_sub) * (alu_ia - alu_ic + (alu_op_add - alu_op_sub) * alu_ib) = 0; + + // u8 addition/subtraction + #[ALU_ADD_SUB_U8] + alu_u8_tag * (alu_op_add + alu_op_sub) * (sum_8 - alu_ic) = 0; + + // u16 addition/subtraction + #[ALU_ADD_SUB_U16] + alu_u16_tag * (alu_op_add + alu_op_sub) * (sum_16 - alu_ic) = 0; + + // u32 addition/subtraction + #[ALU_ADD_SUB_U32] + alu_u32_tag * (alu_op_add + alu_op_sub) * (sum_32 - alu_ic) = 0; + + // u64 addition/subtraction + #[ALU_ADD_SUB_U64] + alu_u64_tag * (alu_op_add + alu_op_sub) * (sum_64 - alu_ic) = 0; + + // u128 addition/subtraction + #[ALU_ADD_SUB_U128] + alu_u128_tag * (alu_op_add + alu_op_sub) * (sum_128 - alu_ic) = 0; // ========= MULTIPLICATION Operation Constraints =============================== @@ -180,19 +177,19 @@ namespace aluChip(256); alu_u8_tag * alu_op_mul * (alu_u8_r0 - alu_ic) = 0; // u16 multiplication - alu_u16_tag * alu_op_mul * (sum_32 - alu_ia * alu_ib) = 0; + alu_u16_tag * alu_op_mul * (mul_sum_32 - alu_ia * alu_ib) = 0; #[ALU_MULTIPLICATION_OUT_U16] - alu_u16_tag * alu_op_mul * (sum_16 - alu_ic) = 0; + alu_u16_tag * alu_op_mul * (mul_sum_16 - alu_ic) = 0; // u32 multiplication - alu_u32_tag * alu_op_mul * (sum_64 - alu_ia * alu_ib) = 0; + alu_u32_tag * alu_op_mul * (mul_sum_64 - alu_ia * alu_ib) = 0; #[ALU_MULTIPLICATION_OUT_U32] - alu_u32_tag * alu_op_mul * (sum_32 - alu_ic) = 0; + alu_u32_tag * alu_op_mul * (mul_sum_32 - alu_ic) = 0; // u64 multiplication - alu_u64_tag * alu_op_mul * (sum_128 - alu_ia * alu_ib) = 0; + alu_u64_tag * alu_op_mul * (mul_sum_128 - alu_ia * alu_ib) = 0; #[ALU_MULTIPLICATION_OUT_U64] - alu_u64_tag * alu_op_mul * (sum_64 - alu_ic) = 0; + alu_u64_tag * alu_op_mul * (mul_sum_64 - alu_ic) = 0; // ========= u128 MULTIPLICATION Operation Constraints =============================== // @@ -218,12 +215,12 @@ namespace aluChip(256); pol sum_high_shifted_64 = alu_u16_r4' + alu_u16_r5' * 2**16 + alu_u16_r6' * 2**32 + alu_u16_r7' * 2**48; // Arithmetic relations - alu_u128_tag * alu_op_mul * (sum_64 + sum_high_64 * 2**64 - alu_ia) = 0; + alu_u128_tag * alu_op_mul * (mul_sum_64 + sum_high_64 * 2**64 - alu_ia) = 0; alu_u128_tag * alu_op_mul * (sum_shifted_64 + sum_high_shifted_64 * 2**64 - alu_ib) = 0; #[ALU_MULTIPLICATION_OUT_U128] alu_u128_tag * alu_op_mul * ( alu_ia * sum_shifted_64 - + sum_64 * sum_high_shifted_64 * 2**64 + + mul_sum_64 * sum_high_shifted_64 * 2**64 - (alu_cf * 2**64 + alu_u64_r0) * 2**128 - alu_ic ) = 0; diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index 858ce96e3f1..d3869ca5247 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -43,7 +43,7 @@ class AvmMiniFlavor { // the unshifted and one for the shifted static constexpr size_t NUM_ALL_ENTITIES = 80; - using Relations = std::tuple, AvmMini_vm::avm_mini, AvmMini_vm::mem_trace>; + 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(); @@ -281,20 +281,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r7_shift, + memTrace_m_val_shift, + memTrace_m_tag_shift, + memTrace_m_addr_shift, + memTrace_m_rw_shift, aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r1_shift, + aluChip_alu_u16_r5_shift, aluChip_alu_u16_r4_shift, avmMini_internal_return_ptr_shift, - avmMini_pc_shift, - memTrace_m_val_shift, - memTrace_m_tag_shift, - memTrace_m_rw_shift, - memTrace_m_addr_shift) + avmMini_pc_shift) RefVector get_wires() { @@ -364,20 +364,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r7_shift, + memTrace_m_val_shift, + memTrace_m_tag_shift, + memTrace_m_addr_shift, + memTrace_m_rw_shift, aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r1_shift, + aluChip_alu_u16_r5_shift, aluChip_alu_u16_r4_shift, avmMini_internal_return_ptr_shift, - avmMini_pc_shift, - memTrace_m_val_shift, - memTrace_m_tag_shift, - memTrace_m_rw_shift, - memTrace_m_addr_shift }; + avmMini_pc_shift }; }; RefVector get_unshifted() { @@ -450,19 +450,37 @@ class AvmMiniFlavor { }; RefVector get_to_be_shifted() { - return { aluChip_alu_u16_r1, aluChip_alu_u16_r2, aluChip_alu_u16_r0, - aluChip_alu_u16_r5, aluChip_alu_u16_r7, aluChip_alu_u16_r6, - aluChip_alu_u16_r3, aluChip_alu_u16_r4, avmMini_internal_return_ptr, - avmMini_pc, memTrace_m_val, memTrace_m_tag, - memTrace_m_rw, memTrace_m_addr }; + return { memTrace_m_val, + memTrace_m_tag, + memTrace_m_addr, + memTrace_m_rw, + aluChip_alu_u16_r6, + aluChip_alu_u16_r0, + aluChip_alu_u16_r3, + aluChip_alu_u16_r7, + aluChip_alu_u16_r2, + aluChip_alu_u16_r1, + aluChip_alu_u16_r5, + aluChip_alu_u16_r4, + avmMini_internal_return_ptr, + avmMini_pc }; }; RefVector get_shifted() { - return { aluChip_alu_u16_r1_shift, aluChip_alu_u16_r2_shift, aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r5_shift, aluChip_alu_u16_r7_shift, aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r3_shift, aluChip_alu_u16_r4_shift, avmMini_internal_return_ptr_shift, - avmMini_pc_shift, memTrace_m_val_shift, memTrace_m_tag_shift, - memTrace_m_rw_shift, memTrace_m_addr_shift }; + return { memTrace_m_val_shift, + memTrace_m_tag_shift, + memTrace_m_addr_shift, + memTrace_m_rw_shift, + aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r1_shift, + aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r4_shift, + avmMini_internal_return_ptr_shift, + avmMini_pc_shift }; }; }; @@ -475,11 +493,20 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { aluChip_alu_u16_r1, aluChip_alu_u16_r2, aluChip_alu_u16_r0, - aluChip_alu_u16_r5, aluChip_alu_u16_r7, aluChip_alu_u16_r6, - aluChip_alu_u16_r3, aluChip_alu_u16_r4, avmMini_internal_return_ptr, - avmMini_pc, memTrace_m_val, memTrace_m_tag, - memTrace_m_rw, memTrace_m_addr }; + return { memTrace_m_val, + memTrace_m_tag, + memTrace_m_addr, + memTrace_m_rw, + aluChip_alu_u16_r6, + aluChip_alu_u16_r0, + aluChip_alu_u16_r3, + aluChip_alu_u16_r7, + aluChip_alu_u16_r2, + aluChip_alu_u16_r1, + aluChip_alu_u16_r5, + aluChip_alu_u16_r4, + avmMini_internal_return_ptr, + avmMini_pc }; }; // The plookup wires that store plookup read data. 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 index e45bdf43598..b3bb16c5b99 100644 --- 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 @@ -87,20 +87,20 @@ template struct AvmMiniFullRow { FF avmMini_mem_idx_b{}; FF avmMini_mem_idx_c{}; FF avmMini_last{}; - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_u16_r7_shift{}; + FF memTrace_m_val_shift{}; + FF memTrace_m_tag_shift{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_rw_shift{}; FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u16_r0_shift{}; FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r1_shift{}; + FF aluChip_alu_u16_r5_shift{}; FF aluChip_alu_u16_r4_shift{}; FF avmMini_internal_return_ptr_shift{}; FF avmMini_pc_shift{}; - FF memTrace_m_val_shift{}; - FF memTrace_m_tag_shift{}; - FF memTrace_m_rw_shift{}; - FF memTrace_m_addr_shift{}; }; class AvmMiniCircuitBuilder { @@ -198,20 +198,20 @@ class AvmMiniCircuitBuilder { polys.avmMini_last[i] = rows[i].avmMini_last; } - polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); - polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.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_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); + polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); + polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); + polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); + polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); + polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); + polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); + polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); + polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); + polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); - polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); - polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); - polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); return polys; } @@ -249,6 +249,10 @@ class AvmMiniCircuitBuilder { 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; @@ -257,10 +261,6 @@ class AvmMiniCircuitBuilder { AvmMini_vm::get_relation_label_avm_mini)) { return false; } - if (!evaluate_relation.template operator()>( - "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { - return false; - } return true; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index 42081891229..f248151f0cd 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,96 +7,81 @@ namespace proof_system::AvmMini_vm { template struct Alu_chipRow { - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r6{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u8_tag{}; - FF aluChip_alu_op_mul{}; + FF aluChip_alu_u16_r5{}; + FF aluChip_alu_u64_tag{}; + FF aluChip_alu_u8_r0{}; + FF aluChip_alu_u16_r2{}; FF aluChip_alu_u16_r0{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_op_sub{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u128_tag{}; FF aluChip_alu_ff_tag{}; - FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_ic{}; FF aluChip_alu_u32_tag{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u8_r0{}; - FF aluChip_alu_u16_tag{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r5{}; - FF aluChip_alu_ia{}; - FF aluChip_alu_u64_tag{}; + FF aluChip_alu_u16_r3{}; FF aluChip_alu_u16_r1{}; - FF aluChip_alu_cf{}; + FF aluChip_alu_op_mul{}; + FF aluChip_alu_u16_r0_shift{}; FF aluChip_alu_op_add{}; - FF aluChip_alu_u16_r7{}; FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r7{}; FF aluChip_alu_ib{}; + FF aluChip_alu_u16_r6{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_cf{}; + FF aluChip_alu_u16_tag{}; + FF aluChip_alu_op_sub{}; + FF aluChip_alu_u16_r4{}; + FF aluChip_alu_u16_r1_shift{}; + FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_ia{}; + FF aluChip_alu_u8_tag{}; + FF aluChip_alu_u16_r4_shift{}; FF aluChip_alu_u64_r0{}; - FF aluChip_alu_u128_tag{}; - FF aluChip_alu_u16_r3{}; FF aluChip_alu_u8_r1{}; - FF aluChip_alu_u16_r2{}; - FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_u16_r4{}; + FF aluChip_alu_ic{}; }; inline std::string get_relation_label_alu_chip(int index) { switch (index) { - case 28: - return "ALU_MULTIPLICATION_FF"; - - case 34: + case 19: return "ALU_MULTIPLICATION_OUT_U32"; - case 20: - return "ALU_SUBTRACTION_OUT_U16"; + case 15: + return "ALU_MULTIPLICATION_OUT_U8"; - case 26: - return "ALU_SUBTRACTION_OUT_U128"; + case 21: + return "ALU_MULTIPLICATION_OUT_U64"; - case 32: - return "ALU_MULTIPLICATION_OUT_U16"; + case 12: + return "ALU_ADD_SUB_U128"; - case 8: - return "ALU_ADDITION_OUT_U8"; + case 10: + return "ALU_ADD_SUB_U32"; - case 16: - return "ALU_ADDITION_OUT_U128"; + case 17: + return "ALU_MULTIPLICATION_OUT_U16"; - case 22: - return "ALU_SUBTRACTION_OUT_U32"; + case 24: + return "ALU_MULTIPLICATION_OUT_U128"; - case 14: - return "ALU_ADDITION_OUT_U64"; + case 11: + return "ALU_ADD_SUB_U64"; - case 12: - return "ALU_ADDITION_OUT_U32"; + case 8: + return "ALU_ADD_SUB_U8"; - case 18: - return "ALU_SUBTRACTION_OUT_U8"; + case 7: + return "ALU_ADD_SUB_FF"; - case 36: - return "ALU_MULTIPLICATION_OUT_U64"; + case 9: + return "ALU_ADD_SUB_U16"; - case 17: - return "ALU_SUBTRACTION_FF"; + case 13: + return "ALU_MULTIPLICATION_FF"; case 6: - return "ALU_ADDITION_FF"; - - case 39: - return "ALU_MULTIPLICATION_OUT_U128"; - - case 10: - return "ALU_ADDITION_OUT_U16"; - - case 24: - return "ALU_SUBTRACTION_OUT_U64"; - - case 30: - return "ALU_MULTIPLICATION_OUT_U8"; + return "ALU_ADD_SUB_COMMON"; } return std::to_string(index); } @@ -105,9 +90,8 @@ template class alu_chipImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, 3, 3, 3, 3, 3, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 4, 5, 4, - 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 6, 6, 8, + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 3, 3, 3, 3, 4, 5, 4, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 6, 6, 8, }; template @@ -170,7 +154,18 @@ template class alu_chipImpl { AvmMini_DECLARE_VIEWS(6); auto tmp = - ((aluChip_alu_ff_tag * aluChip_alu_op_add) * ((aluChip_alu_ia + aluChip_alu_ib) - aluChip_alu_ic)); + (((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; } @@ -178,8 +173,9 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(7); - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_add) * - (((aluChip_alu_u8_r0 + (aluChip_alu_cf * FF(256))) - aluChip_alu_ia) - aluChip_alu_ib)); + auto tmp = + ((aluChip_alu_ff_tag * (aluChip_alu_op_add + aluChip_alu_op_sub)) * + ((aluChip_alu_ia - aluChip_alu_ic) + ((aluChip_alu_op_add - aluChip_alu_op_sub) * aluChip_alu_ib))); tmp *= scaling_factor; std::get<7>(evals) += tmp; } @@ -187,7 +183,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(8); - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_add) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u8_tag * (aluChip_alu_op_add + aluChip_alu_op_sub)) * + (aluChip_alu_u8_r0 - aluChip_alu_ic)); tmp *= scaling_factor; std::get<8>(evals) += tmp; } @@ -195,8 +192,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(9); - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_add) * - (((aluChip_alu_u16_r0 + (aluChip_alu_cf * FF(65536))) - aluChip_alu_ia) - aluChip_alu_ib)); + auto tmp = ((aluChip_alu_u16_tag * (aluChip_alu_op_add + aluChip_alu_op_sub)) * + ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) - aluChip_alu_ic)); tmp *= scaling_factor; std::get<9>(evals) += tmp; } @@ -204,7 +201,9 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(10); - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_add) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u32_tag * (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_ic)); tmp *= scaling_factor; std::get<10>(evals) += tmp; } @@ -212,11 +211,11 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(11); - auto tmp = - ((aluChip_alu_u32_tag * aluChip_alu_op_add) * - ((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + (aluChip_alu_cf * FF(4294967296UL))) - - aluChip_alu_ia) - - aluChip_alu_ib)); + auto tmp = ((aluChip_alu_u64_tag * (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_ic)); tmp *= scaling_factor; std::get<11>(evals) += tmp; } @@ -224,8 +223,16 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(12); - auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_add) * - ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ic)); + auto tmp = + ((aluChip_alu_u128_tag * (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_ic)); tmp *= scaling_factor; std::get<12>(evals) += tmp; } @@ -233,13 +240,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(13); - auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_add) * - ((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + - (aluChip_alu_u16_r2 * FF(4294967296UL))) + - (aluChip_alu_u16_r3 * FF(281474976710656UL))) + - (aluChip_alu_cf * FF(uint256_t{ 0, 1, 0, 0 }))) - - aluChip_alu_ia) - - aluChip_alu_ib)); + auto tmp = + ((aluChip_alu_ff_tag * aluChip_alu_op_mul) * ((aluChip_alu_ia * aluChip_alu_ib) - aluChip_alu_ic)); tmp *= scaling_factor; std::get<13>(evals) += tmp; } @@ -247,11 +249,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(14); - auto tmp = - ((aluChip_alu_u64_tag * aluChip_alu_op_add) * - ((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + (aluChip_alu_u16_r2 * FF(4294967296UL))) + - (aluChip_alu_u16_r3 * FF(281474976710656UL))) - - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * + ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; std::get<14>(evals) += tmp; } @@ -259,17 +258,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(15); - auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_add) * - ((((((((((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 * FF(uint256_t{ 0, 1, 0, 0 }))) + - (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 65536, 0, 0 }))) + - (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + - (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) + - (aluChip_alu_cf * FF(uint256_t{ 0, 0, 1, 0 }))) - - aluChip_alu_ia) - - aluChip_alu_ib)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); tmp *= scaling_factor; std::get<15>(evals) += tmp; } @@ -277,15 +266,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(16); - auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_add) * - ((((((((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 * FF(uint256_t{ 0, 1, 0, 0 }))) + - (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 65536, 0, 0 }))) + - (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + - (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * + ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; std::get<16>(evals) += tmp; } @@ -293,8 +275,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(17); - auto tmp = - ((aluChip_alu_ff_tag * aluChip_alu_op_sub) * ((aluChip_alu_ia - aluChip_alu_ib) - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); tmp *= scaling_factor; std::get<17>(evals) += tmp; } @@ -302,184 +283,26 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(18); - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_sub) * - (((aluChip_alu_u8_r0 + (aluChip_alu_cf * FF(256))) - aluChip_alu_ic) - aluChip_alu_ib)); - tmp *= scaling_factor; - std::get<18>(evals) += tmp; - } - // Contribution 19 - { - AvmMini_DECLARE_VIEWS(19); - - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_sub) * (aluChip_alu_u8_r0 - aluChip_alu_ia)); - tmp *= scaling_factor; - std::get<19>(evals) += tmp; - } - // Contribution 20 - { - AvmMini_DECLARE_VIEWS(20); - - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_sub) * - (((aluChip_alu_u16_r0 + (aluChip_alu_cf * FF(65536))) - aluChip_alu_ic) - aluChip_alu_ib)); - tmp *= scaling_factor; - std::get<20>(evals) += tmp; - } - // Contribution 21 - { - AvmMini_DECLARE_VIEWS(21); - - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_sub) * (aluChip_alu_u16_r0 - aluChip_alu_ia)); - tmp *= scaling_factor; - std::get<21>(evals) += tmp; - } - // Contribution 22 - { - AvmMini_DECLARE_VIEWS(22); - - auto tmp = - ((aluChip_alu_u32_tag * aluChip_alu_op_sub) * - ((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + (aluChip_alu_cf * FF(4294967296UL))) - - aluChip_alu_ic) - - aluChip_alu_ib)); - tmp *= scaling_factor; - std::get<22>(evals) += tmp; - } - // Contribution 23 - { - AvmMini_DECLARE_VIEWS(23); - - auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_sub) * - ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ia)); - tmp *= scaling_factor; - std::get<23>(evals) += tmp; - } - // Contribution 24 - { - AvmMini_DECLARE_VIEWS(24); - - auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_sub) * - ((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + - (aluChip_alu_u16_r2 * FF(4294967296UL))) + - (aluChip_alu_u16_r3 * FF(281474976710656UL))) + - (aluChip_alu_cf * FF(uint256_t{ 0, 1, 0, 0 }))) - - aluChip_alu_ic) - - aluChip_alu_ib)); - tmp *= scaling_factor; - std::get<24>(evals) += tmp; - } - // Contribution 25 - { - AvmMini_DECLARE_VIEWS(25); - - auto tmp = - ((aluChip_alu_u64_tag * aluChip_alu_op_sub) * - ((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + (aluChip_alu_u16_r2 * FF(4294967296UL))) + - (aluChip_alu_u16_r3 * FF(281474976710656UL))) - - aluChip_alu_ia)); - tmp *= scaling_factor; - std::get<25>(evals) += tmp; - } - // Contribution 26 - { - AvmMini_DECLARE_VIEWS(26); - - auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_sub) * - ((((((((((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 * FF(uint256_t{ 0, 1, 0, 0 }))) + - (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 65536, 0, 0 }))) + - (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + - (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) + - (aluChip_alu_cf * FF(uint256_t{ 0, 0, 1, 0 }))) - - aluChip_alu_ic) - - aluChip_alu_ib)); - tmp *= scaling_factor; - std::get<26>(evals) += tmp; - } - // Contribution 27 - { - AvmMini_DECLARE_VIEWS(27); - - auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_sub) * - ((((((((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 * FF(uint256_t{ 0, 1, 0, 0 }))) + - (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 65536, 0, 0 }))) + - (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + - (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - - aluChip_alu_ia)); - tmp *= scaling_factor; - std::get<27>(evals) += tmp; - } - // Contribution 28 - { - AvmMini_DECLARE_VIEWS(28); - - auto tmp = - ((aluChip_alu_ff_tag * aluChip_alu_op_mul) * ((aluChip_alu_ia * aluChip_alu_ib) - aluChip_alu_ic)); - tmp *= scaling_factor; - std::get<28>(evals) += tmp; - } - // Contribution 29 - { - AvmMini_DECLARE_VIEWS(29); - - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * - ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) - (aluChip_alu_ia * aluChip_alu_ib))); - tmp *= scaling_factor; - std::get<29>(evals) += tmp; - } - // Contribution 30 - { - AvmMini_DECLARE_VIEWS(30); - - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); - tmp *= scaling_factor; - std::get<30>(evals) += tmp; - } - // Contribution 31 - { - AvmMini_DECLARE_VIEWS(31); - - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * - ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - (aluChip_alu_ia * aluChip_alu_ib))); - tmp *= scaling_factor; - std::get<31>(evals) += tmp; - } - // Contribution 32 - { - AvmMini_DECLARE_VIEWS(32); - - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); - tmp *= scaling_factor; - std::get<32>(evals) += tmp; - } - // Contribution 33 - { - AvmMini_DECLARE_VIEWS(33); - auto tmp = ((aluChip_alu_u32_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_ia * aluChip_alu_ib))); tmp *= scaling_factor; - std::get<33>(evals) += tmp; + std::get<18>(evals) += tmp; } - // Contribution 34 + // Contribution 19 { - AvmMini_DECLARE_VIEWS(34); + AvmMini_DECLARE_VIEWS(19); auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_mul) * ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<34>(evals) += tmp; + std::get<19>(evals) += tmp; } - // Contribution 35 + // Contribution 20 { - AvmMini_DECLARE_VIEWS(35); + AvmMini_DECLARE_VIEWS(20); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_mul) * ((((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -491,11 +314,11 @@ template class alu_chipImpl { (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; - std::get<35>(evals) += tmp; + std::get<20>(evals) += tmp; } - // Contribution 36 + // Contribution 21 { - AvmMini_DECLARE_VIEWS(36); + AvmMini_DECLARE_VIEWS(21); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_mul) * @@ -503,11 +326,11 @@ template class alu_chipImpl { (aluChip_alu_u16_r3 * FF(281474976710656UL))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<36>(evals) += tmp; + std::get<21>(evals) += tmp; } - // Contribution 37 + // Contribution 22 { - AvmMini_DECLARE_VIEWS(37); + AvmMini_DECLARE_VIEWS(22); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * (((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -519,11 +342,11 @@ template class alu_chipImpl { FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<37>(evals) += tmp; + std::get<22>(evals) += tmp; } - // Contribution 38 + // Contribution 23 { - AvmMini_DECLARE_VIEWS(38); + AvmMini_DECLARE_VIEWS(23); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * (((((aluChip_alu_u16_r0_shift + (aluChip_alu_u16_r1_shift * FF(65536))) + @@ -535,11 +358,11 @@ template class alu_chipImpl { FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<38>(evals) += tmp; + std::get<23>(evals) += tmp; } - // Contribution 39 + // Contribution 24 { - AvmMini_DECLARE_VIEWS(39); + AvmMini_DECLARE_VIEWS(24); 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))) + @@ -556,7 +379,7 @@ template class alu_chipImpl { FF(uint256_t{ 0, 0, 1, 0 }))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<39>(evals) += tmp; + std::get<24>(evals) += tmp; } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index d41af9f2b90..2bd1e67e1a2 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,61 +7,61 @@ namespace proof_system::AvmMini_vm { template struct Avm_miniRow { - FF avmMini_mem_op_b{}; - FF avmMini_internal_return_ptr{}; - FF avmMini_first{}; FF avmMini_pc{}; - FF avmMini_ia{}; - FF avmMini_mem_idx_a{}; + FF avmMini_internal_return_ptr_shift{}; + FF avmMini_rwa{}; + FF avmMini_sel_internal_return{}; FF avmMini_sel_op_div{}; - FF avmMini_sel_halt{}; FF avmMini_sel_jump{}; - FF avmMini_sel_op_add{}; - FF avmMini_rwb{}; - FF avmMini_mem_op_a{}; FF avmMini_ib{}; - FF avmMini_ic{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_sel_internal_return{}; - FF avmMini_mem_op_c{}; - FF avmMini_rwc{}; + FF avmMini_sel_op_add{}; FF avmMini_sel_internal_call{}; - FF avmMini_op_err{}; - FF avmMini_pc_shift{}; - FF avmMini_mem_idx_b{}; + FF avmMini_ic{}; + FF avmMini_mem_op_b{}; + FF avmMini_sel_halt{}; + FF avmMini_tag_err{}; FF avmMini_sel_op_mul{}; + FF avmMini_pc_shift{}; FF avmMini_sel_op_sub{}; + FF avmMini_ia{}; + FF avmMini_first{}; + FF avmMini_op_err{}; + FF avmMini_mem_op_a{}; + FF avmMini_rwb{}; + FF avmMini_rwc{}; + FF avmMini_mem_op_c{}; FF avmMini_inv{}; - FF avmMini_tag_err{}; - FF avmMini_rwa{}; + FF avmMini_internal_return_ptr{}; + FF avmMini_mem_idx_b{}; + FF avmMini_mem_idx_a{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { - case 30: - return "RETURN_POINTER_DECREMENT"; - - case 22: - return "SUBOP_ERROR_RELEVANT_OP"; - - case 21: - return "SUBOP_DIVISION_ZERO_ERR2"; + case 24: + return "RETURN_POINTER_INCREMENT"; case 19: return "SUBOP_DIVISION_FF"; - case 36: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + case 35: + return "PC_INCREMENT"; case 20: return "SUBOP_DIVISION_ZERO_ERR1"; - case 24: - return "RETURN_POINTER_INCREMENT"; + case 22: + return "SUBOP_ERROR_RELEVANT_OP"; - case 35: - return "PC_INCREMENT"; + case 30: + return "RETURN_POINTER_DECREMENT"; + + case 36: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + + case 21: + return "SUBOP_DIVISION_ZERO_ERR2"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index 57d9ea496ed..623a5c8dd46 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -68,17 +68,17 @@ [[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 aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_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_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ + [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ + [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ + [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ + [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_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); \ - [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ - [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ - [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ - [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); + [[maybe_unused]] auto avmMini_pc_shift = View(new_term.avmMini_pc_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 1e8ad76f7c0..b5009c27ac7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,41 +7,41 @@ namespace proof_system::AvmMini_vm { template struct Mem_traceRow { - FF memTrace_m_last{}; - FF memTrace_m_rw{}; - FF memTrace_m_tag_err{}; - FF memTrace_m_val_shift{}; + FF memTrace_m_lastAccess{}; + FF memTrace_m_addr{}; FF memTrace_m_val{}; + FF memTrace_m_val_shift{}; FF memTrace_m_tag_shift{}; + FF memTrace_m_tag{}; FF memTrace_m_in_tag{}; FF memTrace_m_one_min_inv{}; - FF memTrace_m_rw_shift{}; + FF memTrace_m_rw{}; + FF memTrace_m_tag_err{}; FF memTrace_m_addr_shift{}; - FF memTrace_m_lastAccess{}; - FF memTrace_m_tag{}; - FF memTrace_m_addr{}; + FF memTrace_m_rw_shift{}; + FF memTrace_m_last{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { + case 7: + return "MEM_ZERO_INIT"; + + case 5: + return "MEM_READ_WRITE_VAL_CONSISTENCY"; + case 9: return "MEM_IN_TAG_CONSISTENCY_2"; case 4: return "MEM_LAST_ACCESS_DELIMITER"; - case 5: - return "MEM_READ_WRITE_VAL_CONSISTENCY"; - - case 7: - return "MEM_ZERO_INIT"; + case 8: + return "MEM_IN_TAG_CONSISTENCY_1"; case 6: return "MEM_READ_WRITE_TAG_CONSISTENCY"; - - case 8: - return "MEM_IN_TAG_CONSISTENCY_1"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp index 50979a08ba1..2c5117d3556 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp @@ -32,6 +32,10 @@ std::vector AvmMiniAluTraceBuilder::final /** * @brief Build Alu trace and compute the result of an addition of type defined by in_tag. + * Besides the addition calculation, for the types u8, u16, u32, u64, and u128, we + * have to store the result of the addition modulo 2^128 decomposed into 8-bit and + * 16-bit registers, i.e., + * a+b mod. 2^128 = alu_u8_r0 + alu_u8_r1 * 2^8 + alu_u16_r0 * 2^16 ... + alu_u16_r6 * 2^112 * * @param a Left operand of the addition * @param b Right operand of the addition @@ -46,93 +50,52 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag, ui FF c{}; bool carry = false; uint8_t alu_u8_r0{}; + uint8_t alu_u8_r1{}; std::array alu_u16_reg{}; + uint128_t a_u128{ a }; + uint128_t b_u128{ b }; + uint128_t c_u128 = a_u128 + b_u128; + switch (in_tag) { case AvmMemoryTag::ff: c = a + b; break; - case AvmMemoryTag::u8: { - auto a_u8 = static_cast(uint32_t{ a }); - auto b_u8 = static_cast(uint32_t{ b }); - uint8_t c_u8 = a_u8 + b_u8; - c = FF{ uint256_t{ c_u8 } }; - - // a_u8 + b_u8 >= 2^8 <==> c_u8 < a_u8 - if (c_u8 < a_u8) { - carry = true; - } - - alu_u8_r0 = c_u8; + case AvmMemoryTag::u8: + c = FF{ static_cast(c_u128) }; break; - } - case AvmMemoryTag::u16: { - auto a_u16 = static_cast(uint32_t{ a }); - auto b_u16 = static_cast(uint32_t{ b }); - uint16_t c_u16 = a_u16 + b_u16; - c = FF{ uint256_t{ c_u16 } }; - - // a_u16 + b_u16 >= 2^16 <==> c_u16 < a_u16 - if (c_u16 < a_u16) { - carry = true; - } - - alu_u16_reg.at(0) = c_u16; + case AvmMemoryTag::u16: + c = FF{ static_cast(c_u128) }; break; - } - case AvmMemoryTag::u32: { - uint32_t a_u32{ a }; - uint32_t b_u32{ b }; - uint32_t c_u32 = a_u32 + b_u32; - c = FF{ uint256_t{ c_u32 } }; - - // a_u32 + b_u32 >= 2^32 <==> c_u32 < a_u32 - if (c_u32 < a_u32) { - carry = true; - } - - alu_u16_reg.at(0) = static_cast(c_u32); - alu_u16_reg.at(1) = static_cast(c_u32 >> 16); + case AvmMemoryTag::u32: + c = FF{ static_cast(c_u128) }; break; - } - case AvmMemoryTag::u64: { - uint64_t a_u64{ a }; - uint64_t b_u64{ b }; - uint64_t c_u64 = a_u64 + b_u64; - c = FF{ uint256_t{ c_u64 } }; - - // a_u64 + b_u64 >= 2^64 <==> c_u64 < a_u64 - if (c_u64 < a_u64) { - carry = true; - } - - uint64_t c_trunc_64 = c_u64; - for (size_t i = 0; i < 4; i++) { - alu_u16_reg.at(i) = static_cast(c_trunc_64); - c_trunc_64 >>= 16; - } + case AvmMemoryTag::u64: + c = FF{ static_cast(c_u128) }; break; - } - case AvmMemoryTag::u128: { - uint128_t a_u128{ a }; - uint128_t b_u128{ b }; - uint128_t c_u128 = a_u128 + b_u128; + case AvmMemoryTag::u128: c = FF{ uint256_t::from_uint128(c_u128) }; + break; + case AvmMemoryTag::u0: // Unsupported as instruction tag + return FF{ 0 }; + } + if (in_tag != AvmMemoryTag::ff) { // a_u128 + b_u128 >= 2^128 <==> c_u128 < a_u128 if (c_u128 < a_u128) { carry = true; } uint128_t c_trunc_128 = c_u128; - for (size_t i = 0; i < 8; i++) { + alu_u8_r0 = static_cast(c_trunc_128); + c_trunc_128 >>= 8; + alu_u8_r1 = static_cast(c_trunc_128); + c_trunc_128 >>= 8; + + for (size_t i = 0; i < 7; i++) { alu_u16_reg.at(i) = static_cast(c_trunc_128); c_trunc_128 >>= 16; } - break; - } - case AvmMemoryTag::u0: // Unsupported as instruction tag - return FF{ 0 }; } alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ @@ -149,6 +112,7 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag, ui .alu_ic = c, .alu_cf = carry, .alu_u8_r0 = alu_u8_r0, + .alu_u8_r1 = alu_u8_r1, .alu_u16_reg = alu_u16_reg, }); @@ -157,6 +121,10 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag, ui /** * @brief Build Alu trace and compute the result of a subtraction of type defined by in_tag. + * Besides the subtraction calculation, for the types u8, u16, u32, u64, and u128, we + * have to store the result of the subtraction modulo 2^128 decomposed into 8-bit and + * 16-bit registers, i.e., + * a-b mod. 2^128 = alu_u8_r0 + alu_u8_r1 * 2^8 + alu_u16_r0 * 2^16 ... + alu_u16_r6 * 2^112 * * @param a Left operand of the subtraction * @param b Right operand of the subtraction @@ -171,103 +139,51 @@ FF AvmMiniAluTraceBuilder::sub(FF const& a, FF const& b, AvmMemoryTag in_tag, ui FF c{}; bool carry = false; uint8_t alu_u8_r0{}; + uint8_t alu_u8_r1{}; std::array alu_u16_reg{}; + uint128_t a_u128{ a }; + uint128_t b_u128{ b }; + uint128_t c_u128 = a_u128 - b_u128; switch (in_tag) { case AvmMemoryTag::ff: c = a - b; break; - case AvmMemoryTag::u8: { - auto a_u8 = static_cast(uint32_t{ a }); - auto b_u8 = static_cast(uint32_t{ b }); - uint8_t c_u8 = a_u8 - b_u8; - c = FF{ uint256_t{ c_u8 } }; - - // We show that c_u8 + b_u8 == a_u8 and use "addition relation" - // where we swap a_u8 and c_u8. - // c_u8 + b_u8 >= 2^8 <==> a_u8 < c_u8 - if (a_u8 < c_u8) { - carry = true; - } - - alu_u8_r0 = a_u8; + case AvmMemoryTag::u8: + c = FF{ static_cast(c_u128) }; break; - } - case AvmMemoryTag::u16: { - auto a_u16 = static_cast(uint32_t{ a }); - auto b_u16 = static_cast(uint32_t{ b }); - uint16_t c_u16 = a_u16 - b_u16; - c = FF{ uint256_t{ c_u16 } }; - - // We show that c_u16 + b_u16 == a_u16 and use "addition relation" - // where we swap a_u16 and c_u16. - // c_u16 + b_u16 >= 2^16 <==> a_u16 < c_u16 - if (a_u16 < c_u16) { - carry = true; - } - - alu_u16_reg.at(0) = a_u16; + case AvmMemoryTag::u16: + c = FF{ static_cast(c_u128) }; break; - } - case AvmMemoryTag::u32: { - uint32_t a_u32{ a }; - uint32_t b_u32{ b }; - uint32_t c_u32 = a_u32 - b_u32; - c = FF{ uint256_t{ c_u32 } }; - - // We show that c_u32 + b_u32 == a_u32 and use "addition relation" - // where we swap a_u32 and c_u32. - // c_u32 + b_u32 >= 2^32 <==> a_u32 < c_u32 - if (a_u32 < c_u32) { - carry = true; - } - - alu_u16_reg.at(0) = static_cast(a_u32); - alu_u16_reg.at(1) = static_cast(a_u32 >> 16); + case AvmMemoryTag::u32: + c = FF{ static_cast(c_u128) }; break; - } - case AvmMemoryTag::u64: { - uint64_t a_u64{ a }; - uint64_t b_u64{ b }; - uint64_t c_u64 = a_u64 - b_u64; - c = FF{ uint256_t{ c_u64 } }; - - // We show that c_u64 + b_u64 == a_u64 and use "addition relation" - // where we swap a_u64 and c_u64. - // c_u64 + b_u64 >= 2^64 <==> a_u64 < c_u64 - if (a_u64 < c_u64) { - carry = true; - } - - uint64_t a_trunc_64 = a_u64; - for (size_t i = 0; i < 4; i++) { - alu_u16_reg.at(i) = static_cast(a_trunc_64); - a_trunc_64 >>= 16; - } + case AvmMemoryTag::u64: + c = FF{ static_cast(c_u128) }; break; - } - case AvmMemoryTag::u128: { - uint128_t a_u128{ a }; - uint128_t b_u128{ b }; - uint128_t c_u128 = a_u128 - b_u128; + case AvmMemoryTag::u128: c = FF{ uint256_t::from_uint128(c_u128) }; + break; + case AvmMemoryTag::u0: // Unsupported as instruction tag + return FF{ 0 }; + } - // We show that c_u128 + b_u128 == a_u128 and use "addition relation" - // where we swap a_u128 and c_u128. - // c_u128 + b_u128 >= 2^128 <==> a_u128 < c_u128 - if (a_u128 < c_u128) { + if (in_tag != AvmMemoryTag::ff) { + // Underflow when a_u128 < b_u128 + if (a_u128 < b_u128) { carry = true; } - uint128_t a_trunc_128 = a_u128; - for (size_t i = 0; i < 8; i++) { - alu_u16_reg.at(i) = static_cast(a_trunc_128); - a_trunc_128 >>= 16; + uint128_t c_trunc_128 = c_u128; + alu_u8_r0 = static_cast(c_trunc_128); + c_trunc_128 >>= 8; + alu_u8_r1 = static_cast(c_trunc_128); + c_trunc_128 >>= 8; + + for (size_t i = 0; i < 7; i++) { + alu_u16_reg.at(i) = static_cast(c_trunc_128); + c_trunc_128 >>= 16; } - break; - } - case AvmMemoryTag::u0: // Unsupported as instruction tag - return FF{ 0 }; } alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ @@ -284,6 +200,7 @@ FF AvmMiniAluTraceBuilder::sub(FF const& a, FF const& b, AvmMemoryTag in_tag, ui .alu_ic = c, .alu_cf = carry, .alu_u8_r0 = alu_u8_r0, + .alu_u8_r1 = alu_u8_r1, .alu_u16_reg = alu_u16_reg, }); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp index f8bb7d9bcf6..fe58de5a9f2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp @@ -231,6 +231,7 @@ void AvmMiniTraceBuilder::div(uint32_t a_offset, uint32_t b_offset, uint32_t dst // facilitating testing of arithmetic operations over non finite field types. // We add an entry in the memory trace and a simplified one in the main trace // without operation selector. +// TODO: PIL relations for the SET opcode need to be implemented. // No check is performed that val pertains to type defined by in_tag. /** * @brief Set a constant from bytecode with direct memory access. diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index 6fd76ce33aa..1d53e4b5d8b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -460,7 +460,6 @@ TEST_F(AvmMiniArithmeticTestsU8, addition) 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)); - validate_trace_proof(std::move(trace)); } @@ -479,8 +478,9 @@ 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(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)); validate_trace_proof(std::move(trace)); } @@ -501,7 +501,7 @@ TEST_F(AvmMiniArithmeticTestsU8, subtraction) 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(162)); // First operand (a) for subtraction + EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(133)); validate_trace_proof(std::move(trace)); } @@ -523,7 +523,15 @@ TEST_F(AvmMiniArithmeticTestsU8, subtractionCarry) 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(5)); // First operand (a) for subtraction + 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)); validate_trace_proof(std::move(trace)); } @@ -595,7 +603,8 @@ TEST_F(AvmMiniArithmeticTestsU16, addition) 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_u16_r0, FF(34780)); + EXPECT_EQ(alu_row.aluChip_alu_u8_r0, FF(0xDC)); // 34780 = 0x87DC + EXPECT_EQ(alu_row.aluChip_alu_u8_r1, FF(0x87)); validate_trace_proof(std::move(trace)); } @@ -615,8 +624,9 @@ TEST_F(AvmMiniArithmeticTestsU16, additionCarry) 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(1)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(17)); + 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)); validate_trace_proof(std::move(trace)); } @@ -637,7 +647,9 @@ TEST_F(AvmMiniArithmeticTestsU16, subtraction) 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_u16_r0, FF(33005)); // First operand (a) for subtraction + 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)); validate_trace_proof(std::move(trace)); } @@ -659,7 +671,15 @@ TEST_F(AvmMiniArithmeticTestsU16, subtractionCarry) 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_u16_r0, FF(1000)); // First operand (a) for subtraction + 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)); validate_trace_proof(std::move(trace)); } @@ -732,8 +752,9 @@ TEST_F(AvmMiniArithmeticTestsU32, addition) 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_u16_r0, FF(2234567891LLU & UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(2234567891LLU >> 16)); + 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)); validate_trace_proof(std::move(trace)); } @@ -753,9 +774,9 @@ TEST_F(AvmMiniArithmeticTestsU32, additionCarry) 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(1)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(999)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0)); + 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)); validate_trace_proof(std::move(trace)); } @@ -777,9 +798,11 @@ TEST_F(AvmMiniArithmeticTestsU32, subtraction) EXPECT_EQ(alu_row.aluChip_alu_u32_tag, FF(1)); EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - // First operand (a) for subtraction decomposed in u16 registers - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(1345678991 & UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(1345678991 >> 16)); + // 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)); validate_trace_proof(std::move(trace)); } @@ -802,9 +825,16 @@ TEST_F(AvmMiniArithmeticTestsU32, subtractionCarry) EXPECT_EQ(alu_row.aluChip_alu_u32_tag, FF(1)); EXPECT_EQ(alu_row.aluChip_alu_cf, FF(1)); - // First operand (a) for subtraction decomposed in u16 registers - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(3210987654LLU & UINT16_MAX)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(3210987654LLU >> 16)); + // 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)); validate_trace_proof(std::move(trace)); } @@ -886,10 +916,13 @@ TEST_F(AvmMiniArithmeticTestsU64, addition) 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_u16_r0, FF(28445)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(40929)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(13956)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(36)); + + // 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)); validate_trace_proof(std::move(trace)); } @@ -912,11 +945,12 @@ 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(1)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(UINT16_MAX - 201)); + 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.aluChip_alu_u16_r3, FF(UINT16_MAX)); validate_trace_proof(std::move(trace)); } @@ -924,7 +958,7 @@ TEST_F(AvmMiniArithmeticTestsU64, additionCarry) // Test on basic subtraction over u64 type. TEST_F(AvmMiniArithmeticTestsU64, subtraction) { - uint64_t const a = 9876543210123456789LLU; // HEX: 891087B8B0347115 + uint64_t const a = 9876543210123456789LLU; uint64_t const b = 9866543210123456789LLU; uint64_t const c = 10000000000000000LLU; @@ -941,11 +975,13 @@ TEST_F(AvmMiniArithmeticTestsU64, subtraction) EXPECT_EQ(alu_row.aluChip_alu_u64_tag, FF(1)); EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - // First operand (891087B8B0347115) for subtraction decomposed in u16 registers - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0X7115)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0XB034)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0X87B8)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0X8910)); + // 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)); validate_trace_proof(std::move(trace)); } @@ -971,12 +1007,15 @@ TEST_F(AvmMiniArithmeticTestsU64, subtractionCarry) EXPECT_EQ(alu_row.aluChip_alu_u64_tag, FF(1)); EXPECT_EQ(alu_row.aluChip_alu_cf, FF(1)); - // First operand (a) for subtraction decomposed in u16 registers - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(UINT16_MAX - 77)); + 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)); validate_trace_proof(std::move(trace)); } @@ -1071,14 +1110,15 @@ TEST_F(AvmMiniArithmeticTestsU128, addition) 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_u16_r0, FF(0xEEEE)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0xFFFF)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0xAAAA)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0xDDDD)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(0x5555)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(0x6666)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r6, FF(0x4444)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r7, FF(0x8888)); + 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)); validate_trace_proof(std::move(trace)); } @@ -1110,14 +1150,15 @@ TEST_F(AvmMiniArithmeticTestsU128, additionCarry) 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_u16_r0, FF(0xDD9B)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0xF97E)); + 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.aluChip_alu_u16_r7, FF(0xFFFF)); validate_trace_proof(std::move(trace)); } @@ -1149,16 +1190,17 @@ TEST_F(AvmMiniArithmeticTestsU128, subtraction) EXPECT_EQ(alu_row.aluChip_alu_u128_tag, FF(1)); EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - // First operand (a) for subtraction decomposed in u16 registers - // 2^32 - 1 - 36177344 = 4258789951 == 0xFDD7FA3F - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0xFA3F)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0xFDD7)); - 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.aluChip_alu_u16_r7, FF(0xFFFF)); + // 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)); validate_trace_proof(std::move(trace)); } @@ -1190,15 +1232,15 @@ TEST_F(AvmMiniArithmeticTestsU128, subtractionCarry) EXPECT_EQ(alu_row.aluChip_alu_u128_tag, FF(1)); EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); - // First operand (a) for subtraction decomposed in u16 registers - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0xBBBB)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0xAAAA)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(0x9999)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(0x8888)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(0x4444)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r5, FF(0x3333)); + 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.aluChip_alu_u16_r7, FF(0x5555)); validate_trace_proof(std::move(trace)); } @@ -1326,14 +1368,14 @@ TEST_F(AvmMiniArithmeticTestsU128, multiplicationOverflow) TEST_F(AvmMiniArithmeticNegativeTestsFF, 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_ADDITION_FF"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_COMMON"); } // Test on basic incorrect subtraction over finite field type. TEST_F(AvmMiniArithmeticNegativeTestsFF, 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_SUBTRACTION_FF"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_COMMON"); } // Test on basic incorrect multiplication over finite field type. @@ -1485,14 +1527,14 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) TEST_F(AvmMiniArithmeticNegativeTestsU8, 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_ADDITION_OUT_U8"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U8"); } // Test on basic incorrect subtraction over U8. TEST_F(AvmMiniArithmeticNegativeTestsU8, 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_SUBTRACTION_OUT_U8"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U8"); } // Test on basic incorrect multiplication over U8. @@ -1510,14 +1552,14 @@ TEST_F(AvmMiniArithmeticNegativeTestsU8, multiplication) TEST_F(AvmMiniArithmeticNegativeTestsU16, 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_ADDITION_OUT_U16"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U16"); } // Test on basic incorrect subtraction over U16. TEST_F(AvmMiniArithmeticNegativeTestsU16, 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_SUBTRACTION_OUT_U16"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U16"); } // Test on basic incorrect multiplication over U16. @@ -1535,14 +1577,14 @@ TEST_F(AvmMiniArithmeticNegativeTestsU16, multiplication) TEST_F(AvmMiniArithmeticNegativeTestsU32, 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_ADDITION_OUT_U32"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U32"); } // Test on basic incorrect subtraction over U32. TEST_F(AvmMiniArithmeticNegativeTestsU32, 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_SUBTRACTION_OUT_U32"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U32"); } // Test on basic incorrect multiplication over U32. @@ -1561,7 +1603,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU64, addition) { auto trace = gen_mutated_trace_add( FF(3324236423198282341LLU), FF(999999991111133221LLU), FF(1222222222236LLU), AvmMemoryTag::u64); - EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADDITION_OUT_U64"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U64"); } // Test on basic incorrect subtraction over U64. @@ -1569,7 +1611,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU64, subtraction) { auto trace = gen_mutated_trace_sub(FF(399988877723434LLU), FF(UINT64_MAX), FF(25373324332342LLU), AvmMemoryTag::u64); - EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_SUBTRACTION_OUT_U64"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U64"); } // Test on basic incorrect multiplication over U64. @@ -1595,7 +1637,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU128, addition) FF{ uint256_t::from_uint128(b) }, FF{ uint256_t::from_uint128(c) }, AvmMemoryTag::u128); - EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADDITION_OUT_U128"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U128"); } // Test on basic incorrect subtraction over U128. @@ -1609,7 +1651,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU128, subtraction) FF{ uint256_t::from_uint128(b) }, FF{ uint256_t::from_uint128(c) }, AvmMemoryTag::u128); - EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_SUBTRACTION_OUT_U128"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U128"); } // Test on basic incorrect multiplication over U128. From b2ed4f31c0db064f0b0363406a7e5131fb66e1d7 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Wed, 17 Jan 2024 13:43:15 +0000 Subject: [PATCH 23/28] 3738 - further PIL relation consolidation for add/sub --- barretenberg/cpp/pil/avm/README.txt | 18 ++ barretenberg/cpp/pil/avm/alu_chip.pil | 31 +-- .../flavor/generated/AvmMini_flavor.hpp | 105 ++++----- .../generated/AvmMini_circuit_builder.hpp | 48 ++-- .../relations/generated/AvmMini/alu_chip.hpp | 218 +++++++----------- .../relations/generated/AvmMini/avm_mini.hpp | 68 +++--- .../generated/AvmMini/declare_views.hpp | 20 +- .../relations/generated/AvmMini/mem_trace.hpp | 28 +-- .../vm/tests/AvmMini_arithmetic.test.cpp | 24 +- 9 files changed, 244 insertions(+), 316 deletions(-) create mode 100644 barretenberg/cpp/pil/avm/README.txt diff --git a/barretenberg/cpp/pil/avm/README.txt b/barretenberg/cpp/pil/avm/README.txt new file mode 100644 index 00000000000..ba7d102fab9 --- /dev/null +++ b/barretenberg/cpp/pil/avm/README.txt @@ -0,0 +1,18 @@ +This folder contains PIL relations for the AVM. + +Applied heuristic to assess the cost of a relation is given below. +This will be used to determine whether it is worth to merge some +relations into one. + +N_mul = number of mulitplication in the relation +N_add = number of additions/subtraction in the relation +deg = degree of the relation (total degree of the polynomial) + +Relation cost: degree * (N_mul + N_add/4) + +Remark: For edge case, we prefer keep a good readability rather than merging. + +Future: There is an optimization in sumcheck protocol allowing to skip some + rows for relations which are not enabled for them. However, this is + not yet enabled for the AVM. This might change the decision on whether + some relations should be merged or not. \ No newline at end of file diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil index 83d60257903..d99098c50b7 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -63,6 +63,7 @@ namespace aluChip(256); // Operation selectors are copied from main table and do not need to be constrained here. // TODO: Ensure mutual exclusion of alu_op_add and alu_op_sub as some relations below // requires it. + // TODO: Similarly, ensure the mutual exclusion of instruction tags // ========= Inter-table Constraints ====================================== // TODO: Equivalence between intermediate registers, clk, type flag, operation @@ -134,33 +135,17 @@ namespace aluChip(256); // For this, we add c in the relation conditoned by the ff type selector alu_ff_tag. We emphasize // that this relation alone for FF will not imply correctness of the FF addition. We only want // it to be satisfied. A separate relation will ensure correctness of it. + // + // The second relation will consist in showing that sum_N - c = 0 for N = 8, 16, 32, 64, 128. - #[ALU_ADD_SUB_COMMON] + #[ALU_ADD_SUB_1] (alu_op_add + alu_op_sub) * (sum_128 - alu_ia + alu_ff_tag * alu_ic) + (alu_op_add - alu_op_sub) * (alu_cf * 2**128 - alu_ib) = 0; - // ff addition/subtraction - #[ALU_ADD_SUB_FF] - alu_ff_tag * (alu_op_add + alu_op_sub) * (alu_ia - alu_ic + (alu_op_add - alu_op_sub) * alu_ib) = 0; - - // u8 addition/subtraction - #[ALU_ADD_SUB_U8] - alu_u8_tag * (alu_op_add + alu_op_sub) * (sum_8 - alu_ic) = 0; - - // u16 addition/subtraction - #[ALU_ADD_SUB_U16] - alu_u16_tag * (alu_op_add + alu_op_sub) * (sum_16 - alu_ic) = 0; - - // u32 addition/subtraction - #[ALU_ADD_SUB_U32] - alu_u32_tag * (alu_op_add + alu_op_sub) * (sum_32 - alu_ic) = 0; - - // u64 addition/subtraction - #[ALU_ADD_SUB_U64] - alu_u64_tag * (alu_op_add + alu_op_sub) * (sum_64 - alu_ic) = 0; + // Helper polynomial + pol sum_tag = alu_u8_tag * sum_8 + alu_u16_tag * sum_16 + alu_u32_tag * sum_32 + alu_u64_tag * sum_64 + alu_u128_tag * sum_128; - // u128 addition/subtraction - #[ALU_ADD_SUB_U128] - alu_u128_tag * (alu_op_add + alu_op_sub) * (sum_128 - alu_ic) = 0; + #[ALU_ADD_SUB_2] + (alu_op_add + alu_op_sub) * (sum_tag + alu_ff_tag * alu_ia - alu_ic) + alu_ff_tag * (alu_op_add - alu_op_sub) * alu_ib = 0; // ========= MULTIPLICATION Operation Constraints =============================== diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index d3869ca5247..9d3df05c1dc 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -43,7 +43,7 @@ class AvmMiniFlavor { // the unshifted and one for the shifted static constexpr size_t NUM_ALL_ENTITIES = 80; - using Relations = std::tuple, AvmMini_vm::alu_chip, AvmMini_vm::avm_mini>; + using Relations = std::tuple, AvmMini_vm::alu_chip, AvmMini_vm::mem_trace>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -281,20 +281,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - memTrace_m_val_shift, - memTrace_m_tag_shift, - memTrace_m_addr_shift, - memTrace_m_rw_shift, + avmMini_pc_shift, + avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r5_shift, aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r3_shift, aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r2_shift, aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r4_shift, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift) + memTrace_m_addr_shift, + memTrace_m_val_shift, + memTrace_m_tag_shift, + memTrace_m_rw_shift) RefVector get_wires() { @@ -364,20 +364,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - memTrace_m_val_shift, - memTrace_m_tag_shift, - memTrace_m_addr_shift, - memTrace_m_rw_shift, + avmMini_pc_shift, + avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r5_shift, aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r3_shift, aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r2_shift, aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r4_shift, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift }; + memTrace_m_addr_shift, + memTrace_m_val_shift, + memTrace_m_tag_shift, + memTrace_m_rw_shift }; }; RefVector get_unshifted() { @@ -450,37 +450,23 @@ class AvmMiniFlavor { }; RefVector get_to_be_shifted() { - return { memTrace_m_val, - memTrace_m_tag, - memTrace_m_addr, - memTrace_m_rw, - aluChip_alu_u16_r6, - aluChip_alu_u16_r0, - aluChip_alu_u16_r3, - aluChip_alu_u16_r7, - aluChip_alu_u16_r2, - aluChip_alu_u16_r1, - aluChip_alu_u16_r5, - aluChip_alu_u16_r4, - avmMini_internal_return_ptr, - avmMini_pc }; + return { avmMini_pc, avmMini_internal_return_ptr, + aluChip_alu_u16_r2, aluChip_alu_u16_r5, + aluChip_alu_u16_r6, aluChip_alu_u16_r7, + aluChip_alu_u16_r1, aluChip_alu_u16_r3, + aluChip_alu_u16_r0, aluChip_alu_u16_r4, + memTrace_m_addr, memTrace_m_val, + memTrace_m_tag, memTrace_m_rw }; }; RefVector get_shifted() { - return { memTrace_m_val_shift, - memTrace_m_tag_shift, - memTrace_m_addr_shift, - memTrace_m_rw_shift, - aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r4_shift, - avmMini_internal_return_ptr_shift, - avmMini_pc_shift }; + return { avmMini_pc_shift, avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r2_shift, aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r6_shift, aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r1_shift, aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r4_shift, + memTrace_m_addr_shift, memTrace_m_val_shift, + memTrace_m_tag_shift, memTrace_m_rw_shift }; }; }; @@ -493,20 +479,13 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { memTrace_m_val, - memTrace_m_tag, - memTrace_m_addr, - memTrace_m_rw, - aluChip_alu_u16_r6, - aluChip_alu_u16_r0, - aluChip_alu_u16_r3, - aluChip_alu_u16_r7, - aluChip_alu_u16_r2, - aluChip_alu_u16_r1, - aluChip_alu_u16_r5, - aluChip_alu_u16_r4, - avmMini_internal_return_ptr, - avmMini_pc }; + return { avmMini_pc, avmMini_internal_return_ptr, + aluChip_alu_u16_r2, aluChip_alu_u16_r5, + aluChip_alu_u16_r6, aluChip_alu_u16_r7, + aluChip_alu_u16_r1, aluChip_alu_u16_r3, + aluChip_alu_u16_r0, aluChip_alu_u16_r4, + memTrace_m_addr, memTrace_m_val, + memTrace_m_tag, memTrace_m_rw }; }; // The plookup wires that store plookup read data. 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 index b3bb16c5b99..74e156c41a1 100644 --- 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 @@ -87,20 +87,20 @@ template struct AvmMiniFullRow { FF avmMini_mem_idx_b{}; FF avmMini_mem_idx_c{}; FF avmMini_last{}; - FF memTrace_m_val_shift{}; - FF memTrace_m_tag_shift{}; - FF memTrace_m_addr_shift{}; - FF memTrace_m_rw_shift{}; + FF avmMini_pc_shift{}; + FF avmMini_internal_return_ptr_shift{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r5_shift{}; FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r3_shift{}; FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r2_shift{}; FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_u16_r0_shift{}; FF aluChip_alu_u16_r4_shift{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_pc_shift{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_val_shift{}; + FF memTrace_m_tag_shift{}; + FF memTrace_m_rw_shift{}; }; class AvmMiniCircuitBuilder { @@ -198,20 +198,20 @@ class AvmMiniCircuitBuilder { polys.avmMini_last[i] = rows[i].avmMini_last; } - polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); - polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); - polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); + polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); + polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); + polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.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_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); - polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); - polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); - polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); + polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); + polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); - polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); - polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); + polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); + polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); + polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); + polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); return polys; } @@ -249,16 +249,16 @@ class AvmMiniCircuitBuilder { return true; }; - if (!evaluate_relation.template operator()>( - "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { + if (!evaluate_relation.template operator()>("avm_mini", + AvmMini_vm::get_relation_label_avm_mini)) { 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)) { + if (!evaluate_relation.template operator()>( + "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { return false; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index f248151f0cd..11eb45b1caf 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,81 +7,66 @@ namespace proof_system::AvmMini_vm { template struct Alu_chipRow { - FF aluChip_alu_u16_r5{}; + FF aluChip_alu_u8_r1{}; + FF aluChip_alu_u16_r2_shift{}; FF aluChip_alu_u64_tag{}; - FF aluChip_alu_u8_r0{}; - FF aluChip_alu_u16_r2{}; + FF aluChip_alu_ic{}; + FF aluChip_alu_u16_r3{}; + FF aluChip_alu_op_add{}; + FF aluChip_alu_u16_r5{}; FF aluChip_alu_u16_r0{}; + FF aluChip_alu_u16_r5_shift{}; FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u128_tag{}; + FF aluChip_alu_u16_r4{}; + FF aluChip_alu_u16_r6{}; + FF aluChip_alu_u8_tag{}; FF aluChip_alu_ff_tag{}; + FF aluChip_alu_u128_tag{}; + FF aluChip_alu_ib{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r2{}; + FF aluChip_alu_u16_r7{}; + FF aluChip_alu_u16_r1_shift{}; + FF aluChip_alu_op_mul{}; + FF aluChip_alu_u64_r0{}; FF aluChip_alu_u32_tag{}; - FF aluChip_alu_u16_r3{}; FF aluChip_alu_u16_r1{}; - FF aluChip_alu_op_mul{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_op_add{}; + FF aluChip_alu_op_sub{}; FF aluChip_alu_u16_r3_shift{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r7{}; - FF aluChip_alu_ib{}; - FF aluChip_alu_u16_r6{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_cf{}; + FF aluChip_alu_u8_r0{}; FF aluChip_alu_u16_tag{}; - FF aluChip_alu_op_sub{}; - FF aluChip_alu_u16_r4{}; - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r5_shift{}; FF aluChip_alu_ia{}; - FF aluChip_alu_u8_tag{}; + FF aluChip_alu_u16_r0_shift{}; FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_u64_r0{}; - FF aluChip_alu_u8_r1{}; - FF aluChip_alu_ic{}; + FF aluChip_alu_cf{}; }; inline std::string get_relation_label_alu_chip(int index) { switch (index) { - case 19: + case 14: return "ALU_MULTIPLICATION_OUT_U32"; - case 15: - return "ALU_MULTIPLICATION_OUT_U8"; - - case 21: - return "ALU_MULTIPLICATION_OUT_U64"; + case 7: + return "ALU_ADD_SUB_2"; case 12: - return "ALU_ADD_SUB_U128"; + return "ALU_MULTIPLICATION_OUT_U16"; case 10: - return "ALU_ADD_SUB_U32"; - - case 17: - return "ALU_MULTIPLICATION_OUT_U16"; + return "ALU_MULTIPLICATION_OUT_U8"; - case 24: - return "ALU_MULTIPLICATION_OUT_U128"; + case 6: + return "ALU_ADD_SUB_1"; - case 11: - return "ALU_ADD_SUB_U64"; + case 16: + return "ALU_MULTIPLICATION_OUT_U64"; case 8: - return "ALU_ADD_SUB_U8"; - - case 7: - return "ALU_ADD_SUB_FF"; - - case 9: - return "ALU_ADD_SUB_U16"; - - case 13: return "ALU_MULTIPLICATION_FF"; - case 6: - return "ALU_ADD_SUB_COMMON"; + case 19: + return "ALU_MULTIPLICATION_OUT_U128"; } return std::to_string(index); } @@ -90,8 +75,8 @@ template class alu_chipImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, 3, 3, 3, 3, 3, 4, 5, 4, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 6, 6, 8, + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 6, 6, 8, }; template @@ -174,8 +159,26 @@ template class alu_chipImpl { AvmMini_DECLARE_VIEWS(7); auto tmp = - ((aluChip_alu_ff_tag * (aluChip_alu_op_add + aluChip_alu_op_sub)) * - ((aluChip_alu_ia - aluChip_alu_ic) + ((aluChip_alu_op_add - aluChip_alu_op_sub) * aluChip_alu_ib))); + (((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; } @@ -183,8 +186,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(8); - auto tmp = ((aluChip_alu_u8_tag * (aluChip_alu_op_add + aluChip_alu_op_sub)) * - (aluChip_alu_u8_r0 - aluChip_alu_ic)); + 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; } @@ -192,8 +195,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(9); - auto tmp = ((aluChip_alu_u16_tag * (aluChip_alu_op_add + aluChip_alu_op_sub)) * - ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) - aluChip_alu_ic)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * + ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; std::get<9>(evals) += tmp; } @@ -201,9 +204,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(10); - auto tmp = ((aluChip_alu_u32_tag * (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_ic)); + auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); tmp *= scaling_factor; std::get<10>(evals) += tmp; } @@ -211,11 +212,8 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(11); - auto tmp = ((aluChip_alu_u64_tag * (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_ic)); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * + ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; std::get<11>(evals) += tmp; } @@ -223,16 +221,7 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(12); - auto tmp = - ((aluChip_alu_u128_tag * (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_ic)); + auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); tmp *= scaling_factor; std::get<12>(evals) += tmp; } @@ -240,69 +229,26 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(13); - auto tmp = - ((aluChip_alu_ff_tag * aluChip_alu_op_mul) * ((aluChip_alu_ia * aluChip_alu_ib) - aluChip_alu_ic)); - tmp *= scaling_factor; - std::get<13>(evals) += tmp; - } - // Contribution 14 - { - AvmMini_DECLARE_VIEWS(14); - - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * - ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) - (aluChip_alu_ia * aluChip_alu_ib))); - tmp *= scaling_factor; - std::get<14>(evals) += tmp; - } - // Contribution 15 - { - AvmMini_DECLARE_VIEWS(15); - - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); - tmp *= scaling_factor; - std::get<15>(evals) += tmp; - } - // Contribution 16 - { - AvmMini_DECLARE_VIEWS(16); - - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * - ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - (aluChip_alu_ia * aluChip_alu_ib))); - tmp *= scaling_factor; - std::get<16>(evals) += tmp; - } - // Contribution 17 - { - AvmMini_DECLARE_VIEWS(17); - - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); - tmp *= scaling_factor; - std::get<17>(evals) += tmp; - } - // Contribution 18 - { - AvmMini_DECLARE_VIEWS(18); - auto tmp = ((aluChip_alu_u32_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_ia * aluChip_alu_ib))); tmp *= scaling_factor; - std::get<18>(evals) += tmp; + std::get<13>(evals) += tmp; } - // Contribution 19 + // Contribution 14 { - AvmMini_DECLARE_VIEWS(19); + AvmMini_DECLARE_VIEWS(14); auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_mul) * ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<19>(evals) += tmp; + std::get<14>(evals) += tmp; } - // Contribution 20 + // Contribution 15 { - AvmMini_DECLARE_VIEWS(20); + AvmMini_DECLARE_VIEWS(15); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_mul) * ((((((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -314,11 +260,11 @@ template class alu_chipImpl { (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - (aluChip_alu_ia * aluChip_alu_ib))); tmp *= scaling_factor; - std::get<20>(evals) += tmp; + std::get<15>(evals) += tmp; } - // Contribution 21 + // Contribution 16 { - AvmMini_DECLARE_VIEWS(21); + AvmMini_DECLARE_VIEWS(16); auto tmp = ((aluChip_alu_u64_tag * aluChip_alu_op_mul) * @@ -326,11 +272,11 @@ template class alu_chipImpl { (aluChip_alu_u16_r3 * FF(281474976710656UL))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<21>(evals) += tmp; + std::get<16>(evals) += tmp; } - // Contribution 22 + // Contribution 17 { - AvmMini_DECLARE_VIEWS(22); + AvmMini_DECLARE_VIEWS(17); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * (((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + @@ -342,11 +288,11 @@ template class alu_chipImpl { FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<22>(evals) += tmp; + std::get<17>(evals) += tmp; } - // Contribution 23 + // Contribution 18 { - AvmMini_DECLARE_VIEWS(23); + AvmMini_DECLARE_VIEWS(18); auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * (((((aluChip_alu_u16_r0_shift + (aluChip_alu_u16_r1_shift * FF(65536))) + @@ -358,11 +304,11 @@ template class alu_chipImpl { FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<23>(evals) += tmp; + std::get<18>(evals) += tmp; } - // Contribution 24 + // Contribution 19 { - AvmMini_DECLARE_VIEWS(24); + AvmMini_DECLARE_VIEWS(19); 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))) + @@ -379,7 +325,7 @@ template class alu_chipImpl { FF(uint256_t{ 0, 0, 1, 0 }))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<24>(evals) += tmp; + std::get<19>(evals) += tmp; } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index 2bd1e67e1a2..931bb46a8d8 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,61 +7,61 @@ namespace proof_system::AvmMini_vm { template struct Avm_miniRow { - FF avmMini_pc{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_rwa{}; - FF avmMini_sel_internal_return{}; - FF avmMini_sel_op_div{}; + FF avmMini_op_err{}; FF avmMini_sel_jump{}; - FF avmMini_ib{}; - FF avmMini_sel_op_add{}; - FF avmMini_sel_internal_call{}; - FF avmMini_ic{}; - FF avmMini_mem_op_b{}; + FF avmMini_mem_op_c{}; + FF avmMini_rwa{}; + FF avmMini_rwc{}; + FF avmMini_mem_idx_b{}; FF avmMini_sel_halt{}; + FF avmMini_ia{}; + FF avmMini_sel_op_sub{}; + FF avmMini_inv{}; + FF avmMini_sel_internal_return{}; FF avmMini_tag_err{}; - FF avmMini_sel_op_mul{}; + FF avmMini_ic{}; FF avmMini_pc_shift{}; - FF avmMini_sel_op_sub{}; - FF avmMini_ia{}; - FF avmMini_first{}; - FF avmMini_op_err{}; - FF avmMini_mem_op_a{}; + FF avmMini_pc{}; + FF avmMini_sel_op_mul{}; + FF avmMini_sel_internal_call{}; + FF avmMini_mem_op_b{}; + FF avmMini_sel_op_add{}; FF avmMini_rwb{}; - FF avmMini_rwc{}; - FF avmMini_mem_op_c{}; - FF avmMini_inv{}; - FF avmMini_internal_return_ptr{}; - FF avmMini_mem_idx_b{}; + FF avmMini_mem_op_a{}; + FF avmMini_sel_op_div{}; + FF avmMini_ib{}; + FF avmMini_internal_return_ptr_shift{}; FF avmMini_mem_idx_a{}; + FF avmMini_first{}; + FF avmMini_internal_return_ptr{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { - case 24: - return "RETURN_POINTER_INCREMENT"; - - case 19: - return "SUBOP_DIVISION_FF"; - - case 35: - return "PC_INCREMENT"; - case 20: return "SUBOP_DIVISION_ZERO_ERR1"; - case 22: - return "SUBOP_ERROR_RELEVANT_OP"; + case 21: + return "SUBOP_DIVISION_ZERO_ERR2"; case 30: return "RETURN_POINTER_DECREMENT"; + case 22: + return "SUBOP_ERROR_RELEVANT_OP"; + case 36: return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - case 21: - return "SUBOP_DIVISION_ZERO_ERR2"; + case 24: + return "RETURN_POINTER_INCREMENT"; + + case 19: + return "SUBOP_DIVISION_FF"; + + case 35: + return "PC_INCREMENT"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index 623a5c8dd46..67e0d447bb1 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -68,17 +68,17 @@ [[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_val_shift = View(new_term.memTrace_m_val_shift); \ - [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ - [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ - [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ + [[maybe_unused]] auto avmMini_pc_shift = View(new_term.avmMini_pc_shift); \ + [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_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_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_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); + [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ + [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ + [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ + [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index b5009c27ac7..3d2b4e40163 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -8,40 +8,40 @@ namespace proof_system::AvmMini_vm { template struct Mem_traceRow { FF memTrace_m_lastAccess{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_rw{}; + FF memTrace_m_tag_err{}; + FF memTrace_m_val_shift{}; FF memTrace_m_addr{}; FF memTrace_m_val{}; - FF memTrace_m_val_shift{}; FF memTrace_m_tag_shift{}; + FF memTrace_m_last{}; + FF memTrace_m_rw_shift{}; FF memTrace_m_tag{}; - FF memTrace_m_in_tag{}; FF memTrace_m_one_min_inv{}; - FF memTrace_m_rw{}; - FF memTrace_m_tag_err{}; - FF memTrace_m_addr_shift{}; - FF memTrace_m_rw_shift{}; - FF memTrace_m_last{}; + FF memTrace_m_in_tag{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { + case 6: + return "MEM_READ_WRITE_TAG_CONSISTENCY"; + case 7: return "MEM_ZERO_INIT"; - case 5: - return "MEM_READ_WRITE_VAL_CONSISTENCY"; + case 4: + return "MEM_LAST_ACCESS_DELIMITER"; case 9: return "MEM_IN_TAG_CONSISTENCY_2"; - case 4: - return "MEM_LAST_ACCESS_DELIMITER"; + case 5: + return "MEM_READ_WRITE_VAL_CONSISTENCY"; case 8: return "MEM_IN_TAG_CONSISTENCY_1"; - - case 6: - return "MEM_READ_WRITE_TAG_CONSISTENCY"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index 1d53e4b5d8b..f0012ac96cd 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -1368,14 +1368,14 @@ TEST_F(AvmMiniArithmeticTestsU128, multiplicationOverflow) TEST_F(AvmMiniArithmeticNegativeTestsFF, 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_COMMON"); + 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) { 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_COMMON"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_1"); } // Test on basic incorrect multiplication over finite field type. @@ -1527,14 +1527,14 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) TEST_F(AvmMiniArithmeticNegativeTestsU8, 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_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) { 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_U8"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } // Test on basic incorrect multiplication over U8. @@ -1552,14 +1552,14 @@ TEST_F(AvmMiniArithmeticNegativeTestsU8, multiplication) TEST_F(AvmMiniArithmeticNegativeTestsU16, 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_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) { 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_U16"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } // Test on basic incorrect multiplication over U16. @@ -1577,14 +1577,14 @@ TEST_F(AvmMiniArithmeticNegativeTestsU16, multiplication) TEST_F(AvmMiniArithmeticNegativeTestsU32, 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_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) { 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_U32"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } // Test on basic incorrect multiplication over U32. @@ -1603,7 +1603,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU64, addition) { auto trace = gen_mutated_trace_add( FF(3324236423198282341LLU), FF(999999991111133221LLU), FF(1222222222236LLU), AvmMemoryTag::u64); - EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U64"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } // Test on basic incorrect subtraction over U64. @@ -1611,7 +1611,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU64, subtraction) { auto trace = gen_mutated_trace_sub(FF(399988877723434LLU), FF(UINT64_MAX), FF(25373324332342LLU), AvmMemoryTag::u64); - EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U64"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } // Test on basic incorrect multiplication over U64. @@ -1637,7 +1637,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU128, addition) FF{ uint256_t::from_uint128(b) }, FF{ uint256_t::from_uint128(c) }, AvmMemoryTag::u128); - EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U128"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } // Test on basic incorrect subtraction over U128. @@ -1651,7 +1651,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU128, subtraction) FF{ uint256_t::from_uint128(b) }, FF{ uint256_t::from_uint128(c) }, AvmMemoryTag::u128); - EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_U128"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } // Test on basic incorrect multiplication over U128. From 41391f61928dc91d957990612aeee21bc7e61373 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Thu, 18 Jan 2024 10:44:29 +0000 Subject: [PATCH 24/28] 3738 - consolidate multiplication relations for u8, u16, u32, u64 --- barretenberg/cpp/pil/avm/README.txt | 9 +- barretenberg/cpp/pil/avm/alu_chip.pil | 50 ++--- .../flavor/generated/AvmMini_flavor.hpp | 54 +++--- .../generated/AvmMini_circuit_builder.hpp | 20 +- .../relations/generated/AvmMini/alu_chip.hpp | 175 ++++++------------ .../relations/generated/AvmMini/avm_mini.hpp | 52 +++--- .../generated/AvmMini/declare_views.hpp | 12 +- .../relations/generated/AvmMini/mem_trace.hpp | 26 +-- .../vm/avm_trace/AvmMini_alu_trace.cpp | 80 +++----- .../vm/tests/AvmMini_arithmetic.test.cpp | 68 ++++--- 10 files changed, 235 insertions(+), 311 deletions(-) diff --git a/barretenberg/cpp/pil/avm/README.txt b/barretenberg/cpp/pil/avm/README.txt index ba7d102fab9..cf63996a3c2 100644 --- a/barretenberg/cpp/pil/avm/README.txt +++ b/barretenberg/cpp/pil/avm/README.txt @@ -10,9 +10,12 @@ deg = degree of the relation (total degree of the polynomial) Relation cost: degree * (N_mul + N_add/4) +Remark: addition/multiplication with a constant counts as well in the above metrics Remark: For edge case, we prefer keep a good readability rather than merging. Future: There is an optimization in sumcheck protocol allowing to skip some - rows for relations which are not enabled for them. However, this is - not yet enabled for the AVM. This might change the decision on whether - some relations should be merged or not. \ No newline at end of file + rows for relations which are not enabled for them (applies when not + enabled over 2 adjacent rows). However, this feature is not yet enabled + in the AVM context. This might change the decision on whether some relations + should be merged or not. Basically, merging relations would decrease the + likelihood to be disabled over adjacent rows. \ No newline at end of file diff --git a/barretenberg/cpp/pil/avm/alu_chip.pil b/barretenberg/cpp/pil/avm/alu_chip.pil index d99098c50b7..09cf037b016 100644 --- a/barretenberg/cpp/pil/avm/alu_chip.pil +++ b/barretenberg/cpp/pil/avm/alu_chip.pil @@ -45,8 +45,10 @@ namespace aluChip(256); pol commit alu_cf; // ========= Type Constraints ============================================= - // TODO: Range constraints for slice registers - // intermediate registers ia and ib (inputs) depending on flag + // TODO: Range constraints + // - for slice registers + // - intermediate registers ia and ib (inputs) depending on flag (or inherited from previous ops?) + // - intermediate register ic (in some operations it might be inherited based on ia and ib ranges. To be checked.) // Carry flag: We will have to constraint to ensure that the // arithmetic expressions are not overflowing finite field size // Remark: Operation selectors are constrained in the main trace. @@ -111,13 +113,6 @@ namespace aluChip(256); pol sum_64 = sum_32 + alu_u16_r1 * 2**32 + alu_u16_r2 * 2**48; pol sum_96 = sum_64 + alu_u16_r3 * 2**64 + alu_u16_r4 * 2**80; pol sum_128 = sum_96 + alu_u16_r5 * 2**96 + alu_u16_r6 * 2**112; - - // TODO(clean): 16-bit slice partial sums for legacy multiplication - pol mul_sum_16 = alu_u16_r0; - pol mul_sum_32 = mul_sum_16 + alu_u16_r1 * 2**16; - pol mul_sum_64 = mul_sum_32 + alu_u16_r2 * 2**32 + alu_u16_r3 * 2**48; - pol mul_sum_96 = mul_sum_64 + alu_u16_r4 * 2**64 + alu_u16_r5 * 2**80; - pol mul_sum_128 = mul_sum_96 + alu_u16_r6 * 2**96 + alu_u16_r7 * 2**112; // ========= ADDITION/SUBTRACTION Operation Constraints =============================== // @@ -153,28 +148,20 @@ namespace aluChip(256); #[ALU_MULTIPLICATION_FF] alu_ff_tag * alu_op_mul * (alu_ia * alu_ib - alu_ic) = 0; + // We need 2k bits to express the product (a*b) over the integer, i.e., for type uk // we express the product as sum_k (u8 is an exception as we need 8-bit registers) - // u8 multiplication - alu_u8_tag * alu_op_mul * (alu_u8_r0 + alu_u8_r1 * 2**8 - alu_ia * alu_ib) = 0; - #[ALU_MULTIPLICATION_OUT_U8] - alu_u8_tag * alu_op_mul * (alu_u8_r0 - alu_ic) = 0; + // We group relations for u8, u16, u32, u64 together. - // u16 multiplication - alu_u16_tag * alu_op_mul * (mul_sum_32 - alu_ia * alu_ib) = 0; - #[ALU_MULTIPLICATION_OUT_U16] - alu_u16_tag * alu_op_mul * (mul_sum_16 - alu_ic) = 0; + // Helper polynomial + pol sum_tag_no_128 = alu_u8_tag * sum_8 + alu_u16_tag * sum_16 + alu_u32_tag * sum_32 + alu_u64_tag * sum_64; - // u32 multiplication - alu_u32_tag * alu_op_mul * (mul_sum_64 - alu_ia * alu_ib) = 0; - #[ALU_MULTIPLICATION_OUT_U32] - alu_u32_tag * alu_op_mul * (mul_sum_32 - alu_ic) = 0; + #[ALU_MUL_COMMON_1] + (1 - alu_ff_tag - alu_u128_tag) * alu_op_mul * (sum_128 - alu_ia * alu_ib) = 0; - // u64 multiplication - alu_u64_tag * alu_op_mul * (mul_sum_128 - alu_ia * alu_ib) = 0; - #[ALU_MULTIPLICATION_OUT_U64] - alu_u64_tag * alu_op_mul * (mul_sum_64 - alu_ic) = 0; + #[ALU_MUL_COMMON_2] + alu_op_mul * (sum_tag_no_128 - (1 - alu_ff_tag - alu_u128_tag) * alu_ic) = 0; // ========= u128 MULTIPLICATION Operation Constraints =============================== // @@ -190,22 +177,25 @@ namespace aluChip(256); // shifted polynomials. // R' is stored in alu_u64_r0 + // 64-bit lower limb + pol sum_low_64 = alu_u16_r0 + alu_u16_r1 * 2**16 + alu_u16_r2 * 2**32 + alu_u16_r3 * 2**48; + // 64-bit higher limb pol sum_high_64 = alu_u16_r4 + alu_u16_r5 * 2**16 + alu_u16_r6 * 2**32 + alu_u16_r7 * 2**48; // 64-bit lower limb for next row - pol sum_shifted_64 = alu_u16_r0' + alu_u16_r1' * 2**16 + alu_u16_r2' * 2**32 + alu_u16_r3' * 2**48; + pol sum_low_shifted_64 = alu_u16_r0' + alu_u16_r1' * 2**16 + alu_u16_r2' * 2**32 + alu_u16_r3' * 2**48; // 64-bit higher limb for next row pol sum_high_shifted_64 = alu_u16_r4' + alu_u16_r5' * 2**16 + alu_u16_r6' * 2**32 + alu_u16_r7' * 2**48; // Arithmetic relations - alu_u128_tag * alu_op_mul * (mul_sum_64 + sum_high_64 * 2**64 - alu_ia) = 0; - alu_u128_tag * alu_op_mul * (sum_shifted_64 + sum_high_shifted_64 * 2**64 - alu_ib) = 0; + alu_u128_tag * alu_op_mul * (sum_low_64 + sum_high_64 * 2**64 - alu_ia) = 0; + alu_u128_tag * alu_op_mul * (sum_low_shifted_64 + sum_high_shifted_64 * 2**64 - alu_ib) = 0; #[ALU_MULTIPLICATION_OUT_U128] alu_u128_tag * alu_op_mul * ( - alu_ia * sum_shifted_64 - + mul_sum_64 * sum_high_shifted_64 * 2**64 + alu_ia * sum_low_shifted_64 + + sum_low_64 * sum_high_shifted_64 * 2**64 - (alu_cf * 2**64 + alu_u64_r0) * 2**128 - alu_ic ) = 0; diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index 9d3df05c1dc..0e6b69dd6ee 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -283,18 +283,18 @@ class AvmMiniFlavor { avmMini_last, avmMini_pc_shift, avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r2_shift, aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r4_shift, aluChip_alu_u16_r7_shift, aluChip_alu_u16_r1_shift, aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r4_shift, - memTrace_m_addr_shift, + memTrace_m_rw_shift, memTrace_m_val_shift, - memTrace_m_tag_shift, - memTrace_m_rw_shift) + memTrace_m_addr_shift, + memTrace_m_tag_shift) RefVector get_wires() { @@ -366,18 +366,18 @@ class AvmMiniFlavor { avmMini_last, avmMini_pc_shift, avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r2_shift, aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r4_shift, aluChip_alu_u16_r7_shift, aluChip_alu_u16_r1_shift, aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r4_shift, - memTrace_m_addr_shift, + memTrace_m_rw_shift, memTrace_m_val_shift, - memTrace_m_tag_shift, - memTrace_m_rw_shift }; + memTrace_m_addr_shift, + memTrace_m_tag_shift }; }; RefVector get_unshifted() { @@ -451,22 +451,22 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { return { avmMini_pc, avmMini_internal_return_ptr, - aluChip_alu_u16_r2, aluChip_alu_u16_r5, - aluChip_alu_u16_r6, aluChip_alu_u16_r7, + aluChip_alu_u16_r5, aluChip_alu_u16_r2, + aluChip_alu_u16_r0, aluChip_alu_u16_r6, + aluChip_alu_u16_r4, aluChip_alu_u16_r7, aluChip_alu_u16_r1, aluChip_alu_u16_r3, - aluChip_alu_u16_r0, aluChip_alu_u16_r4, - memTrace_m_addr, memTrace_m_val, - memTrace_m_tag, memTrace_m_rw }; + memTrace_m_rw, memTrace_m_val, + memTrace_m_addr, memTrace_m_tag }; }; RefVector get_shifted() { return { avmMini_pc_shift, avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r2_shift, aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r6_shift, aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r5_shift, aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r4_shift, aluChip_alu_u16_r7_shift, aluChip_alu_u16_r1_shift, aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r0_shift, aluChip_alu_u16_r4_shift, - memTrace_m_addr_shift, memTrace_m_val_shift, - memTrace_m_tag_shift, memTrace_m_rw_shift }; + memTrace_m_rw_shift, memTrace_m_val_shift, + memTrace_m_addr_shift, memTrace_m_tag_shift }; }; }; @@ -480,12 +480,12 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { return { avmMini_pc, avmMini_internal_return_ptr, - aluChip_alu_u16_r2, aluChip_alu_u16_r5, - aluChip_alu_u16_r6, aluChip_alu_u16_r7, + aluChip_alu_u16_r5, aluChip_alu_u16_r2, + aluChip_alu_u16_r0, aluChip_alu_u16_r6, + aluChip_alu_u16_r4, aluChip_alu_u16_r7, aluChip_alu_u16_r1, aluChip_alu_u16_r3, - aluChip_alu_u16_r0, aluChip_alu_u16_r4, - memTrace_m_addr, memTrace_m_val, - memTrace_m_tag, memTrace_m_rw }; + memTrace_m_rw, memTrace_m_val, + memTrace_m_addr, memTrace_m_tag }; }; // The plookup wires that store plookup read data. 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 index 74e156c41a1..57c501fae69 100644 --- 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 @@ -89,18 +89,18 @@ template struct AvmMiniFullRow { FF avmMini_last{}; FF avmMini_pc_shift{}; FF avmMini_internal_return_ptr_shift{}; - FF aluChip_alu_u16_r2_shift{}; FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r0_shift{}; FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u16_r4_shift{}; FF aluChip_alu_u16_r7_shift{}; FF aluChip_alu_u16_r1_shift{}; FF aluChip_alu_u16_r3_shift{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r4_shift{}; - FF memTrace_m_addr_shift{}; + FF memTrace_m_rw_shift{}; FF memTrace_m_val_shift{}; + FF memTrace_m_addr_shift{}; FF memTrace_m_tag_shift{}; - FF memTrace_m_rw_shift{}; }; class AvmMiniCircuitBuilder { @@ -200,18 +200,18 @@ class AvmMiniCircuitBuilder { polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); - polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); + polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); + polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.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_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); - polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); - polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); + 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.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); return polys; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index 11eb45b1caf..fd4d835998e 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,66 +7,60 @@ namespace proof_system::AvmMini_vm { template struct Alu_chipRow { - FF aluChip_alu_u8_r1{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u64_tag{}; - FF aluChip_alu_ic{}; + FF aluChip_alu_u8_r0{}; + FF aluChip_alu_u128_tag{}; + FF aluChip_alu_u16_r5_shift{}; FF aluChip_alu_u16_r3{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u32_tag{}; FF aluChip_alu_op_add{}; - FF aluChip_alu_u16_r5{}; + FF aluChip_alu_u8_r1{}; + FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_u16_tag{}; + FF aluChip_alu_u16_r1{}; FF aluChip_alu_u16_r0{}; - FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u64_r0{}; FF aluChip_alu_u16_r4{}; - FF aluChip_alu_u16_r6{}; - FF aluChip_alu_u8_tag{}; - FF aluChip_alu_ff_tag{}; - FF aluChip_alu_u128_tag{}; FF aluChip_alu_ib{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r2{}; + FF aluChip_alu_cf{}; FF aluChip_alu_u16_r7{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u16_r4_shift{}; + FF aluChip_alu_u16_r7_shift{}; FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_op_mul{}; - FF aluChip_alu_u64_r0{}; - FF aluChip_alu_u32_tag{}; - FF aluChip_alu_u16_r1{}; - FF aluChip_alu_op_sub{}; + FF aluChip_alu_ff_tag{}; FF aluChip_alu_u16_r3_shift{}; - FF aluChip_alu_u8_r0{}; - FF aluChip_alu_u16_tag{}; + FF aluChip_alu_op_mul{}; + FF aluChip_alu_u8_tag{}; + FF aluChip_alu_u64_tag{}; + FF aluChip_alu_ic{}; + FF aluChip_alu_u16_r6{}; FF aluChip_alu_ia{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_cf{}; + FF aluChip_alu_u16_r5{}; + FF aluChip_alu_u16_r2{}; + FF aluChip_alu_op_sub{}; }; inline std::string get_relation_label_alu_chip(int index) { switch (index) { - case 14: - return "ALU_MULTIPLICATION_OUT_U32"; - - case 7: - return "ALU_ADD_SUB_2"; - - case 12: - return "ALU_MULTIPLICATION_OUT_U16"; + case 13: + return "ALU_MULTIPLICATION_OUT_U128"; - case 10: - return "ALU_MULTIPLICATION_OUT_U8"; + case 9: + return "ALU_MUL_COMMON_1"; case 6: return "ALU_ADD_SUB_1"; - case 16: - return "ALU_MULTIPLICATION_OUT_U64"; + case 7: + return "ALU_ADD_SUB_2"; case 8: return "ALU_MULTIPLICATION_FF"; - case 19: - return "ALU_MULTIPLICATION_OUT_U128"; + case 10: + return "ALU_MUL_COMMON_2"; } return std::to_string(index); } @@ -75,8 +69,8 @@ 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, 4, 5, 4, 5, 5, 5, 5, 6, 6, 8, + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 6, 6, 8, }; template @@ -195,8 +189,16 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(9); - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * - ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) - (aluChip_alu_ia * aluChip_alu_ib))); + 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; } @@ -204,7 +206,16 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(10); - auto tmp = ((aluChip_alu_u8_tag * aluChip_alu_op_mul) * (aluChip_alu_u8_r0 - aluChip_alu_ic)); + 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; } @@ -212,72 +223,6 @@ template class alu_chipImpl { { AvmMini_DECLARE_VIEWS(11); - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * - ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - (aluChip_alu_ia * aluChip_alu_ib))); - tmp *= scaling_factor; - std::get<11>(evals) += tmp; - } - // Contribution 12 - { - AvmMini_DECLARE_VIEWS(12); - - auto tmp = ((aluChip_alu_u16_tag * aluChip_alu_op_mul) * (aluChip_alu_u16_r0 - aluChip_alu_ic)); - tmp *= scaling_factor; - std::get<12>(evals) += tmp; - } - // Contribution 13 - { - AvmMini_DECLARE_VIEWS(13); - - auto tmp = - ((aluChip_alu_u32_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_ia * aluChip_alu_ib))); - tmp *= scaling_factor; - std::get<13>(evals) += tmp; - } - // Contribution 14 - { - AvmMini_DECLARE_VIEWS(14); - - auto tmp = ((aluChip_alu_u32_tag * aluChip_alu_op_mul) * - ((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) - aluChip_alu_ic)); - tmp *= scaling_factor; - std::get<14>(evals) += tmp; - } - // Contribution 15 - { - AvmMini_DECLARE_VIEWS(15); - - auto tmp = ((aluChip_alu_u64_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 * FF(uint256_t{ 0, 1, 0, 0 }))) + - (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 65536, 0, 0 }))) + - (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + - (aluChip_alu_u16_r7 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - - (aluChip_alu_ia * aluChip_alu_ib))); - tmp *= scaling_factor; - std::get<15>(evals) += tmp; - } - // Contribution 16 - { - AvmMini_DECLARE_VIEWS(16); - - auto tmp = - ((aluChip_alu_u64_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_ic)); - tmp *= scaling_factor; - std::get<16>(evals) += tmp; - } - // Contribution 17 - { - AvmMini_DECLARE_VIEWS(17); - 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))) + @@ -288,11 +233,11 @@ template class alu_chipImpl { FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ia)); tmp *= scaling_factor; - std::get<17>(evals) += tmp; + std::get<11>(evals) += tmp; } - // Contribution 18 + // Contribution 12 { - AvmMini_DECLARE_VIEWS(18); + 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))) + @@ -304,11 +249,11 @@ template class alu_chipImpl { FF(uint256_t{ 0, 1, 0, 0 }))) - aluChip_alu_ib)); tmp *= scaling_factor; - std::get<18>(evals) += tmp; + std::get<12>(evals) += tmp; } - // Contribution 19 + // Contribution 13 { - AvmMini_DECLARE_VIEWS(19); + 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))) + @@ -325,7 +270,7 @@ template class alu_chipImpl { FF(uint256_t{ 0, 0, 1, 0 }))) - aluChip_alu_ic)); tmp *= scaling_factor; - std::get<19>(evals) += tmp; + std::get<13>(evals) += tmp; } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index 931bb46a8d8..063f5187733 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,43 +7,40 @@ namespace proof_system::AvmMini_vm { template struct Avm_miniRow { - FF avmMini_op_err{}; - FF avmMini_sel_jump{}; - FF avmMini_mem_op_c{}; - FF avmMini_rwa{}; - FF avmMini_rwc{}; + FF avmMini_sel_op_add{}; FF avmMini_mem_idx_b{}; - FF avmMini_sel_halt{}; + FF avmMini_mem_idx_a{}; + FF avmMini_op_err{}; + FF avmMini_rwb{}; + FF avmMini_sel_internal_return{}; FF avmMini_ia{}; + FF avmMini_rwc{}; FF avmMini_sel_op_sub{}; - FF avmMini_inv{}; - FF avmMini_sel_internal_return{}; - FF avmMini_tag_err{}; + FF avmMini_sel_op_div{}; FF avmMini_ic{}; FF avmMini_pc_shift{}; - FF avmMini_pc{}; + FF avmMini_mem_op_b{}; FF avmMini_sel_op_mul{}; + FF avmMini_sel_halt{}; + FF avmMini_tag_err{}; + FF avmMini_internal_return_ptr_shift{}; + FF avmMini_pc{}; + FF avmMini_rwa{}; FF avmMini_sel_internal_call{}; - FF avmMini_mem_op_b{}; - FF avmMini_sel_op_add{}; - FF avmMini_rwb{}; - FF avmMini_mem_op_a{}; - FF avmMini_sel_op_div{}; + FF avmMini_sel_jump{}; FF avmMini_ib{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_mem_idx_a{}; FF avmMini_first{}; + FF avmMini_inv{}; FF avmMini_internal_return_ptr{}; + FF avmMini_mem_op_a{}; + FF avmMini_mem_op_c{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { - case 20: - return "SUBOP_DIVISION_ZERO_ERR1"; - - case 21: - return "SUBOP_DIVISION_ZERO_ERR2"; + case 36: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; case 30: return "RETURN_POINTER_DECREMENT"; @@ -51,17 +48,20 @@ inline std::string get_relation_label_avm_mini(int index) case 22: return "SUBOP_ERROR_RELEVANT_OP"; - case 36: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + case 35: + return "PC_INCREMENT"; case 24: return "RETURN_POINTER_INCREMENT"; + case 21: + return "SUBOP_DIVISION_ZERO_ERR2"; + case 19: return "SUBOP_DIVISION_FF"; - case 35: - return "PC_INCREMENT"; + case 20: + return "SUBOP_DIVISION_ZERO_ERR1"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index 67e0d447bb1..34b21bbf434 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -70,15 +70,15 @@ [[maybe_unused]] auto avmMini_last = View(new_term.avmMini_last); \ [[maybe_unused]] auto avmMini_pc_shift = View(new_term.avmMini_pc_shift); \ [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_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_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ - [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ + [[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_tag_shift = View(new_term.memTrace_m_tag_shift); \ - [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_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); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 3d2b4e40163..50335cb4625 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,29 +7,32 @@ namespace proof_system::AvmMini_vm { template struct Mem_traceRow { + FF memTrace_m_in_tag{}; + FF memTrace_m_one_min_inv{}; + FF memTrace_m_tag{}; FF memTrace_m_lastAccess{}; - FF memTrace_m_addr_shift{}; + FF memTrace_m_val{}; + FF memTrace_m_rw_shift{}; + FF memTrace_m_val_shift{}; FF memTrace_m_rw{}; + FF memTrace_m_last{}; FF memTrace_m_tag_err{}; - FF memTrace_m_val_shift{}; + FF memTrace_m_addr_shift{}; FF memTrace_m_addr{}; - FF memTrace_m_val{}; FF memTrace_m_tag_shift{}; - FF memTrace_m_last{}; - FF memTrace_m_rw_shift{}; - FF memTrace_m_tag{}; - FF memTrace_m_one_min_inv{}; - FF memTrace_m_in_tag{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { + case 7: + return "MEM_ZERO_INIT"; + case 6: return "MEM_READ_WRITE_TAG_CONSISTENCY"; - case 7: - return "MEM_ZERO_INIT"; + case 5: + return "MEM_READ_WRITE_VAL_CONSISTENCY"; case 4: return "MEM_LAST_ACCESS_DELIMITER"; @@ -37,9 +40,6 @@ inline std::string get_relation_label_mem_trace(int index) case 9: return "MEM_IN_TAG_CONSISTENCY_2"; - case 5: - return "MEM_READ_WRITE_VAL_CONSISTENCY"; - case 8: return "MEM_IN_TAG_CONSISTENCY_1"; } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp index 2c5117d3556..a0045b089fe 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp @@ -227,66 +227,26 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui std::array alu_u16_reg{}; + uint128_t a_u128{ a }; + uint128_t b_u128{ b }; + uint128_t c_u128 = a_u128 * b_u128; // Multiplication over the integers (not mod. 2^64) + switch (in_tag) { case AvmMemoryTag::ff: c = a * b; break; - case AvmMemoryTag::u8: { - auto a_u16 = static_cast(uint32_t{ a }); - auto b_u16 = static_cast(uint32_t{ b }); - uint16_t c_u16 = a_u16 * b_u16; // Multiplication over the integers (not mod. 2^8) - - // Decompose c_u16 = r0 + 2^8 * r1 with r0, r1 8-bit registers - alu_u8_r0 = static_cast(c_u16); - alu_u8_r1 = static_cast(c_u16 >> 8); - - c = FF{ uint256_t{ alu_u8_r0 } }; + case AvmMemoryTag::u8: + c = FF{ static_cast(c_u128) }; break; - } - case AvmMemoryTag::u16: { - uint32_t a_u32{ a }; - uint32_t b_u32{ b }; - uint32_t c_u32 = a_u32 * b_u32; // Multiplication over the integers (not mod. 2^16) - - // Decompose c_u32 = r0 + 2^16 * r1 with r0, r1 16-bit registers - alu_u16_reg.at(0) = static_cast(c_u32); - alu_u16_reg.at(1) = static_cast(c_u32 >> 16); - - c = FF{ uint256_t{ alu_u16_reg.at(0) } }; + case AvmMemoryTag::u16: + c = FF{ static_cast(c_u128) }; break; - } - case AvmMemoryTag::u32: { - uint64_t a_u64{ a }; - uint64_t b_u64{ b }; - uint64_t c_u64 = a_u64 * b_u64; // Multiplication over the integers (not mod. 2^32) - - // Decompose c_u64 = r0 + 2^16 * r1 + 2^32 * r2 + 2^48 * r3 with r0, r1, r2, r3 16-bit registers - uint64_t c_trunc_64 = c_u64; - for (size_t i = 0; i < 4; i++) { - alu_u16_reg.at(i) = static_cast(c_trunc_64); - c_trunc_64 >>= 16; - } - - c = FF{ uint256_t{ static_cast(c_u64) } }; - + case AvmMemoryTag::u32: + c = FF{ static_cast(c_u128) }; break; - } - case AvmMemoryTag::u64: { - uint128_t a_u128{ a }; - uint128_t b_u128{ b }; - uint128_t c_u128 = a_u128 * b_u128; // Multiplication over the integers (not mod. 2^64) - - // Decompose c_u128 = r0 + 2^16 * r1 + .. + 2^112 r7 with r0, r1 ... r7 16-bit registers - uint128_t c_trunc_128 = c_u128; - for (size_t i = 0; i < 8; i++) { - alu_u16_reg.at(i) = static_cast(c_trunc_128); - c_trunc_128 >>= 16; - } - - c = FF{ uint256_t{ static_cast(c_u128) } }; - + case AvmMemoryTag::u64: + c = FF{ static_cast(c_u128) }; break; - } case AvmMemoryTag::u128: { uint256_t a_u256{ a }; uint256_t b_u256{ b }; @@ -347,6 +307,22 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui return FF{ 0 }; } + // Following code executed for: u8, u16, u32, u64 (u128 returned handled specifically) + if (in_tag != AvmMemoryTag::ff) { + // Decomposition of c_u128 into 8-bit and 16-bit registers as follows: + // alu_u8_r0 + alu_u8_r1 * 2^8 + alu_u16_r0 * 2^16 ... + alu_u16_r6 * 2^112 + uint128_t c_trunc_128 = c_u128; + alu_u8_r0 = static_cast(c_trunc_128); + c_trunc_128 >>= 8; + alu_u8_r1 = static_cast(c_trunc_128); + c_trunc_128 >>= 8; + + for (size_t i = 0; i < 7; i++) { + alu_u16_reg.at(i) = static_cast(c_trunc_128); + c_trunc_128 >>= 16; + } + } + // Following code executed for: ff, u8, u16, u32, u64 (u128 returned handled specifically) alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index f0012ac96cd..938a723c077 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -701,9 +701,10 @@ TEST_F(AvmMiniArithmeticTestsU16, multiplication) EXPECT_EQ(alu_row.aluChip_alu_u16_tag, FF(1)); - // Decomposition of integer multiplication in 16-bit registers - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(49000)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(0)); + // 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)); validate_trace_proof(std::move(trace)); } @@ -724,10 +725,12 @@ TEST_F(AvmMiniArithmeticTestsU16, multiplicationOverflow) EXPECT_EQ(alu_row.aluChip_alu_u16_tag, FF(1)); - // Decomposition of integer multiplication in 16-bit registers + // Decomposition of integer multiplication in 8-bit and 16-bit registers // 512 * 1024 = 0 + 8 * 2^16 - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(8)); + 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)); validate_trace_proof(std::move(trace)); } @@ -856,10 +859,12 @@ TEST_F(AvmMiniArithmeticTestsU32, multiplication) EXPECT_EQ(alu_row.aluChip_alu_u32_tag, FF(1)); - // Decomposition of integer multiplication in 16-bit registers - // 123454321 = 50033 + 1883 * 2^16 - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(50033)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(1883)); + // 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)); @@ -883,12 +888,14 @@ TEST_F(AvmMiniArithmeticTestsU32, multiplicationOverflow) EXPECT_EQ(alu_row.aluChip_alu_u32_tag, FF(1)); - // Decomposition of integer multiplication in 16-bit registers + // 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(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(32768)); // 2^15 - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(71)); + 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)); validate_trace_proof(std::move(trace)); } @@ -1036,12 +1043,14 @@ TEST_F(AvmMiniArithmeticTestsU64, multiplication) EXPECT_EQ(alu_row.aluChip_alu_u64_tag, FF(1)); - // Decomposition of integer multiplication in 16-bit registers - // 555,382,554,814,950,741 = 44,373 + 46,641 * 2^16 + 7,549 * 2^32 + 1,973 * 2^48 - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(44373)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r1, FF(46641)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r2, FF(7549)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r3, FF(1973)); + // 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)); validate_trace_proof(std::move(trace)); } @@ -1066,16 +1075,17 @@ TEST_F(AvmMiniArithmeticTestsU64, multiplicationOverflow) EXPECT_EQ(alu_row.aluChip_alu_u64_tag, FF(1)); - // Decomposition of integer multiplication in 16-bit registers + // Decomposition of integer multiplication in 8-bit and 16-bit registers // 2^128 - 2^65 + 1 - EXPECT_EQ(alu_row.aluChip_alu_u16_r0, FF(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(0)); - EXPECT_EQ(alu_row.aluChip_alu_u16_r4, FF(UINT16_MAX - 1)); + 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.aluChip_alu_u16_r7, FF(UINT16_MAX)); validate_trace_proof(std::move(trace)); } @@ -1541,7 +1551,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU8, subtraction) TEST_F(AvmMiniArithmeticNegativeTestsU8, 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_MULTIPLICATION_OUT_U8"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MUL_COMMON_2"); } /****************************************************************************** @@ -1566,7 +1576,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU16, subtraction) TEST_F(AvmMiniArithmeticNegativeTestsU16, 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_MULTIPLICATION_OUT_U16"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MUL_COMMON_2"); } /****************************************************************************** @@ -1591,7 +1601,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU32, subtraction) TEST_F(AvmMiniArithmeticNegativeTestsU32, 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_MULTIPLICATION_OUT_U32"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MUL_COMMON_2"); } /****************************************************************************** @@ -1619,7 +1629,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU64, multiplication) { auto trace = gen_mutated_trace_mul(FF(399988877723434LLU), FF(9998887772343LLU), FF(9283674827534LLU), AvmMemoryTag::u64); - EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MULTIPLICATION_OUT_U64"); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MUL_COMMON_2"); } /****************************************************************************** From 3feb72e6c6abd3856fc904224f04887e9e1c4f86 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Thu, 18 Jan 2024 11:08:09 +0000 Subject: [PATCH 25/28] 3738 - comparator for memory traces migrated as < operator overload --- .../vm/avm_trace/AvmMini_mem_trace.cpp | 34 +------------------ .../vm/avm_trace/AvmMini_mem_trace.hpp | 29 ++++++++++++++-- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp index f55d7e9d8b6..e3bcb8c23f4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp @@ -21,38 +21,6 @@ void AvmMiniMemTraceBuilder::reset() memory.fill(FF(0)); } -/** - * @brief A comparator on MemoryTraceEntry to be used by sorting algorithm. We sort first by - * ascending address (m_addr), then by clock (m_clk) and finally sub-clock (m_sub_clk). - * - * @param left The left hand side memory trace entry - * @param right The right hand side memory trace entry - * - * @return A boolean indicating whether left member is smaller than right member. - */ -bool AvmMiniMemTraceBuilder::compare_mem_entries(const MemoryTraceEntry& left, const MemoryTraceEntry& right) -{ - if (left.m_addr < right.m_addr) { - return true; - } - - if (left.m_addr > right.m_addr) { - return false; - } - - if (left.m_clk < right.m_clk) { - return true; - } - - if (left.m_clk > right.m_clk) { - return false; - } - - // No safeguard in case they are equal. The caller should ensure this property. - // Otherwise, relation will not be satisfied. - return left.m_sub_clk < right.m_sub_clk; -} - /** * @brief Prepare the memory trace to be incorporated into the main trace. * @@ -61,7 +29,7 @@ bool AvmMiniMemTraceBuilder::compare_mem_entries(const MemoryTraceEntry& left, c std::vector AvmMiniMemTraceBuilder::finalize() { // Sort memTrace - std::sort(mem_trace.begin(), mem_trace.end(), compare_mem_entries); + std::sort(mem_trace.begin(), mem_trace.end()); return std::move(mem_trace); } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp index 6b9f1afefb8..0cf1bcaca48 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp @@ -25,6 +25,33 @@ class AvmMiniMemTraceBuilder { bool m_rw = false; bool m_tag_err = false; FF m_one_min_inv{}; + + /** + * @brief A comparator on MemoryTraceEntry to be used by sorting algorithm. We sort first by + * ascending address (m_addr), then by clock (m_clk) and finally sub-clock (m_sub_clk). + */ + bool operator<(const MemoryTraceEntry& other) const + { + if (m_addr < other.m_addr) { + return true; + } + + if (m_addr > other.m_addr) { + return false; + } + + if (m_clk < other.m_clk) { + return true; + } + + if (m_clk > other.m_clk) { + return false; + } + + // No safeguard in case they are equal. The caller should ensure this property. + // Otherwise, relation will not be satisfied. + return m_sub_clk < other.m_sub_clk; + } }; // Structure to return value and tag matching boolean after a memory read. @@ -49,8 +76,6 @@ class AvmMiniMemTraceBuilder { std::array memory_tag{}; // The tag of the corresponding memory // entry (aligned with the memory array). - static bool compare_mem_entries(const MemoryTraceEntry& left, const MemoryTraceEntry& right); - void insert_in_mem_trace( uint32_t m_clk, uint32_t m_sub_clk, uint32_t m_addr, FF const& m_val, AvmMemoryTag m_in_tag, bool m_rw); void load_mismatch_tag_in_mem_trace(uint32_t m_clk, From 10eebde3f11c04779125f42e515d3ed39686486e Mon Sep 17 00:00:00 2001 From: jeanmon Date: Thu, 18 Jan 2024 12:54:06 +0000 Subject: [PATCH 26/28] 3738 - adding some TODO in comments --- .../cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp index fe58de5a9f2..ba56aec9094 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp @@ -270,6 +270,9 @@ void AvmMiniTraceBuilder::set(uint128_t val, uint32_t dst_offset, AvmMemoryTag i * TODO: Implement the indirect memory version (maybe not required) * TODO: taking care of intermediate register values consistency and propagating their * values to the next row when not overwritten. + * TODO: error handling if dst_offset + copy_size > 2^32 which would lead to + * out-of-bound memory write. Similarly, if cd_offset + copy_size is larger + * than call_data_mem.size() * * @param cd_offset The starting index of the region in calldata to be copied. * @param copy_size The number of finite field elements to be copied into memory. @@ -363,12 +366,13 @@ void AvmMiniTraceBuilder::call_data_copy(uint32_t cd_offset, * intermediate registers and then values are copied to the returned vector. * TODO: Implement the indirect memory version (maybe not required) * TODO: taking care of flagging this row as the last one? Special STOP flag? + * TODO: error handling if ret_offset + ret_size > 2^32 which would lead to + * out-of-bound memory read. * * @param ret_offset The starting index of the memory region to be returned. * @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) { // We parallelize loading memory operations in chunk of 3, i.e., 1 per intermediate register. From 23e2dcd1e501b47957488ee6096cee147a52c072 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Fri, 19 Jan 2024 10:01:45 +0000 Subject: [PATCH 27/28] 3738 - Re-generate AVM related files with new namespace (after master merge) --- .../flavor/generated/AvmMini_flavor.hpp | 74 +++++++++---------- .../generated/AvmMini_circuit_builder.hpp | 44 +++++------ .../relations/generated/AvmMini/alu_chip.hpp | 64 ++++++++-------- .../relations/generated/AvmMini/avm_mini.hpp | 62 ++++++++-------- .../generated/AvmMini/declare_views.hpp | 18 ++--- .../relations/generated/AvmMini/mem_trace.hpp | 32 ++++---- 6 files changed, 147 insertions(+), 147 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index 783881e74f6..c1f672eb177 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -43,7 +43,7 @@ class AvmMiniFlavor { // the unshifted and one for the shifted static constexpr size_t NUM_ALL_ENTITIES = 80; - using Relations = std::tuple, AvmMini_vm::alu_chip, AvmMini_vm::mem_trace>; + using Relations = std::tuple, AvmMini_vm::avm_mini, AvmMini_vm::mem_trace>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -281,20 +281,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - avmMini_pc_shift, - avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r1_shift, aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r6_shift, aluChip_alu_u16_r4_shift, aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r1_shift, + aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r6_shift, aluChip_alu_u16_r3_shift, - memTrace_m_rw_shift, - memTrace_m_val_shift, + avmMini_pc_shift, + avmMini_internal_return_ptr_shift, + memTrace_m_tag_shift, memTrace_m_addr_shift, - memTrace_m_tag_shift) + memTrace_m_val_shift, + memTrace_m_rw_shift) RefVector get_wires() { @@ -364,20 +364,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - avmMini_pc_shift, - avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r1_shift, aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r6_shift, aluChip_alu_u16_r4_shift, aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r1_shift, + aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r6_shift, aluChip_alu_u16_r3_shift, - memTrace_m_rw_shift, - memTrace_m_val_shift, + avmMini_pc_shift, + avmMini_internal_return_ptr_shift, + memTrace_m_tag_shift, memTrace_m_addr_shift, - memTrace_m_tag_shift }; + memTrace_m_val_shift, + memTrace_m_rw_shift }; }; RefVector get_unshifted() { @@ -450,23 +450,23 @@ class AvmMiniFlavor { }; RefVector get_to_be_shifted() { - return { avmMini_pc, avmMini_internal_return_ptr, - aluChip_alu_u16_r5, aluChip_alu_u16_r2, - aluChip_alu_u16_r0, aluChip_alu_u16_r6, + return { aluChip_alu_u16_r1, aluChip_alu_u16_r0, aluChip_alu_u16_r4, aluChip_alu_u16_r7, - aluChip_alu_u16_r1, aluChip_alu_u16_r3, - memTrace_m_rw, memTrace_m_val, - memTrace_m_addr, memTrace_m_tag }; + aluChip_alu_u16_r5, aluChip_alu_u16_r2, + aluChip_alu_u16_r6, aluChip_alu_u16_r3, + avmMini_pc, avmMini_internal_return_ptr, + memTrace_m_tag, memTrace_m_addr, + memTrace_m_val, memTrace_m_rw }; }; RefVector get_shifted() { - return { avmMini_pc_shift, avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r5_shift, aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r0_shift, aluChip_alu_u16_r6_shift, + return { aluChip_alu_u16_r1_shift, aluChip_alu_u16_r0_shift, aluChip_alu_u16_r4_shift, aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r1_shift, aluChip_alu_u16_r3_shift, - memTrace_m_rw_shift, memTrace_m_val_shift, - memTrace_m_addr_shift, memTrace_m_tag_shift }; + aluChip_alu_u16_r5_shift, aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r6_shift, aluChip_alu_u16_r3_shift, + avmMini_pc_shift, avmMini_internal_return_ptr_shift, + memTrace_m_tag_shift, memTrace_m_addr_shift, + memTrace_m_val_shift, memTrace_m_rw_shift }; }; }; @@ -479,13 +479,13 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { avmMini_pc, avmMini_internal_return_ptr, - aluChip_alu_u16_r5, aluChip_alu_u16_r2, - aluChip_alu_u16_r0, aluChip_alu_u16_r6, + return { aluChip_alu_u16_r1, aluChip_alu_u16_r0, aluChip_alu_u16_r4, aluChip_alu_u16_r7, - aluChip_alu_u16_r1, aluChip_alu_u16_r3, - memTrace_m_rw, memTrace_m_val, - memTrace_m_addr, memTrace_m_tag }; + aluChip_alu_u16_r5, aluChip_alu_u16_r2, + aluChip_alu_u16_r6, aluChip_alu_u16_r3, + avmMini_pc, avmMini_internal_return_ptr, + memTrace_m_tag, memTrace_m_addr, + memTrace_m_val, memTrace_m_rw }; }; // The plookup wires that store plookup read data. 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 index f406950b88a..baef5adc856 100644 --- 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 @@ -87,20 +87,20 @@ template struct AvmMiniFullRow { FF avmMini_mem_idx_b{}; FF avmMini_mem_idx_c{}; FF avmMini_last{}; - FF avmMini_pc_shift{}; - FF avmMini_internal_return_ptr_shift{}; - FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r1_shift{}; FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r6_shift{}; FF aluChip_alu_u16_r4_shift{}; FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r1_shift{}; + FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r6_shift{}; FF aluChip_alu_u16_r3_shift{}; - FF memTrace_m_rw_shift{}; - FF memTrace_m_val_shift{}; - FF memTrace_m_addr_shift{}; + FF avmMini_pc_shift{}; + FF avmMini_internal_return_ptr_shift{}; FF memTrace_m_tag_shift{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_val_shift{}; + FF memTrace_m_rw_shift{}; }; class AvmMiniCircuitBuilder { @@ -198,20 +198,20 @@ class AvmMiniCircuitBuilder { polys.avmMini_last[i] = rows[i].avmMini_last; } - polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); - polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); - polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); - polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); + polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); - polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.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_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); + polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); + polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); + polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); - 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.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); + polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); + polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); + polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); + polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); return polys; } @@ -249,14 +249,14 @@ class AvmMiniCircuitBuilder { return true; }; - if (!evaluate_relation.template operator()>("avm_mini", - AvmMini_vm::get_relation_label_avm_mini)) { - 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; + } if (!evaluate_relation.template operator()>( "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { return false; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index fd4d835998e..c1cd8a6e970 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -4,63 +4,63 @@ #include "../../relation_types.hpp" #include "./declare_views.hpp" -namespace proof_system::AvmMini_vm { +namespace bb::AvmMini_vm { template struct Alu_chipRow { - FF aluChip_alu_u8_r0{}; - FF aluChip_alu_u128_tag{}; - FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r0{}; FF aluChip_alu_u16_r3{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u32_tag{}; - FF aluChip_alu_op_add{}; - FF aluChip_alu_u8_r1{}; + FF aluChip_alu_u16_r5{}; + FF aluChip_alu_u16_r1_shift{}; FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_tag{}; - FF aluChip_alu_u16_r1{}; - FF aluChip_alu_u16_r0{}; - FF aluChip_alu_u64_r0{}; - FF aluChip_alu_u16_r4{}; + FF aluChip_alu_op_add{}; + FF aluChip_alu_ia{}; + FF aluChip_alu_u16_r4_shift{}; FF aluChip_alu_ib{}; - FF aluChip_alu_cf{}; FF aluChip_alu_u16_r7{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r4_shift{}; + FF aluChip_alu_u8_r0{}; FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_ff_tag{}; - FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_op_sub{}; + FF aluChip_alu_u16_r6{}; + FF aluChip_alu_u16_r5_shift{}; FF aluChip_alu_op_mul{}; - FF aluChip_alu_u8_tag{}; FF aluChip_alu_u64_tag{}; - FF aluChip_alu_ic{}; - FF aluChip_alu_u16_r6{}; - FF aluChip_alu_ia{}; - FF aluChip_alu_u16_r5{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u64_r0{}; + FF aluChip_alu_ff_tag{}; + FF aluChip_alu_u32_tag{}; + FF aluChip_alu_u16_tag{}; + FF aluChip_alu_u16_r4{}; + FF aluChip_alu_u16_r6_shift{}; FF aluChip_alu_u16_r2{}; - FF aluChip_alu_op_sub{}; + FF aluChip_alu_ic{}; + FF aluChip_alu_u8_tag{}; + FF aluChip_alu_cf{}; + FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_u8_r1{}; + FF aluChip_alu_u16_r1{}; + FF aluChip_alu_u128_tag{}; }; inline std::string get_relation_label_alu_chip(int index) { switch (index) { - case 13: - return "ALU_MULTIPLICATION_OUT_U128"; - case 9: return "ALU_MUL_COMMON_1"; + case 8: + return "ALU_MULTIPLICATION_FF"; + case 6: return "ALU_ADD_SUB_1"; case 7: return "ALU_ADD_SUB_2"; - case 8: - return "ALU_MULTIPLICATION_FF"; - case 10: return "ALU_MUL_COMMON_2"; + + case 13: + return "ALU_MULTIPLICATION_OUT_U128"; } return std::to_string(index); } @@ -277,4 +277,4 @@ template class alu_chipImpl { template using alu_chip = Relation>; -} // namespace proof_system::AvmMini_vm \ No newline at end of file +} // 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 index a109cb8662b..3347e38ff96 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,46 +7,52 @@ namespace bb::AvmMini_vm { template struct Avm_miniRow { - FF avmMini_sel_op_add{}; - FF avmMini_mem_idx_b{}; - FF avmMini_mem_idx_a{}; - FF avmMini_op_err{}; + FF avmMini_sel_op_sub{}; + FF avmMini_inv{}; + FF avmMini_first{}; + FF avmMini_tag_err{}; + FF avmMini_pc_shift{}; + FF avmMini_mem_op_a{}; FF avmMini_rwb{}; - FF avmMini_sel_internal_return{}; - FF avmMini_ia{}; + FF avmMini_mem_op_c{}; + FF avmMini_internal_return_ptr_shift{}; FF avmMini_rwc{}; - FF avmMini_sel_op_sub{}; FF avmMini_sel_op_div{}; - FF avmMini_ic{}; - FF avmMini_pc_shift{}; - FF avmMini_mem_op_b{}; + FF avmMini_internal_return_ptr{}; + FF avmMini_pc{}; + FF avmMini_ia{}; FF avmMini_sel_op_mul{}; + FF avmMini_mem_op_b{}; + FF avmMini_ib{}; + FF avmMini_sel_jump{}; FF avmMini_sel_halt{}; - FF avmMini_tag_err{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_pc{}; - FF avmMini_rwa{}; + FF avmMini_sel_internal_return{}; + FF avmMini_op_err{}; + FF avmMini_mem_idx_a{}; + FF avmMini_mem_idx_b{}; FF avmMini_sel_internal_call{}; - FF avmMini_sel_jump{}; - FF avmMini_ib{}; - FF avmMini_first{}; - FF avmMini_inv{}; - FF avmMini_internal_return_ptr{}; - FF avmMini_mem_op_a{}; - FF avmMini_mem_op_c{}; + FF avmMini_sel_op_add{}; + FF avmMini_rwa{}; + FF avmMini_ic{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { - case 36: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + case 20: + return "SUBOP_DIVISION_ZERO_ERR1"; + + case 22: + return "SUBOP_ERROR_RELEVANT_OP"; case 30: return "RETURN_POINTER_DECREMENT"; - case 22: - return "SUBOP_ERROR_RELEVANT_OP"; + case 36: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + + case 21: + return "SUBOP_DIVISION_ZERO_ERR2"; case 35: return "PC_INCREMENT"; @@ -54,14 +60,8 @@ inline std::string get_relation_label_avm_mini(int index) case 24: return "RETURN_POINTER_INCREMENT"; - case 21: - return "SUBOP_DIVISION_ZERO_ERR2"; - case 19: return "SUBOP_DIVISION_FF"; - - case 20: - return "SUBOP_DIVISION_ZERO_ERR1"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index 34b21bbf434..1b036e25919 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -68,17 +68,17 @@ [[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 avmMini_pc_shift = View(new_term.avmMini_pc_shift); \ - [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_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_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ - [[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 avmMini_pc_shift = View(new_term.avmMini_pc_shift); \ + [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); \ + [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_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 memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ + [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 8bbbc4f254b..49cc8062e82 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,29 +7,29 @@ namespace bb::AvmMini_vm { template struct Mem_traceRow { + FF memTrace_m_val{}; + FF memTrace_m_last{}; FF memTrace_m_in_tag{}; - FF memTrace_m_one_min_inv{}; FF memTrace_m_tag{}; - FF memTrace_m_lastAccess{}; - FF memTrace_m_val{}; - FF memTrace_m_rw_shift{}; - FF memTrace_m_val_shift{}; FF memTrace_m_rw{}; - FF memTrace_m_last{}; - FF memTrace_m_tag_err{}; + FF memTrace_m_tag_shift{}; FF memTrace_m_addr_shift{}; + FF memTrace_m_tag_err{}; + FF memTrace_m_one_min_inv{}; + FF memTrace_m_val_shift{}; + FF memTrace_m_lastAccess{}; FF memTrace_m_addr{}; - FF memTrace_m_tag_shift{}; + FF memTrace_m_rw_shift{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { - case 7: - return "MEM_ZERO_INIT"; + case 8: + return "MEM_IN_TAG_CONSISTENCY_1"; - case 6: - return "MEM_READ_WRITE_TAG_CONSISTENCY"; + case 9: + return "MEM_IN_TAG_CONSISTENCY_2"; case 5: return "MEM_READ_WRITE_VAL_CONSISTENCY"; @@ -37,11 +37,11 @@ inline std::string get_relation_label_mem_trace(int index) case 4: return "MEM_LAST_ACCESS_DELIMITER"; - case 9: - return "MEM_IN_TAG_CONSISTENCY_2"; + case 6: + return "MEM_READ_WRITE_TAG_CONSISTENCY"; - case 8: - return "MEM_IN_TAG_CONSISTENCY_1"; + case 7: + return "MEM_ZERO_INIT"; } return std::to_string(index); } From b0d262de6198ec87fb02cfc80e388b849b98a193 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Mon, 22 Jan 2024 08:37:56 +0000 Subject: [PATCH 28/28] 3738 - capitalize enum values --- .../vm/avm_trace/AvmMini_alu_trace.cpp | 84 ++--- .../vm/avm_trace/AvmMini_common.hpp | 4 +- .../vm/avm_trace/AvmMini_mem_trace.cpp | 14 +- .../vm/avm_trace/AvmMini_trace.cpp | 46 +-- .../vm/tests/AvmMini_arithmetic.test.cpp | 332 +++++++++--------- .../vm/tests/AvmMini_memory.test.cpp | 22 +- 6 files changed, 251 insertions(+), 251 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp index a0045b089fe..7da44d916bd 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_alu_trace.cpp @@ -58,29 +58,29 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag, ui uint128_t c_u128 = a_u128 + b_u128; switch (in_tag) { - case AvmMemoryTag::ff: + case AvmMemoryTag::FF: c = a + b; break; - case AvmMemoryTag::u8: + case AvmMemoryTag::U8: c = FF{ static_cast(c_u128) }; break; - case AvmMemoryTag::u16: + case AvmMemoryTag::U16: c = FF{ static_cast(c_u128) }; break; - case AvmMemoryTag::u32: + case AvmMemoryTag::U32: c = FF{ static_cast(c_u128) }; break; - case AvmMemoryTag::u64: + case AvmMemoryTag::U64: c = FF{ static_cast(c_u128) }; break; - case AvmMemoryTag::u128: + case AvmMemoryTag::U128: c = FF{ uint256_t::from_uint128(c_u128) }; break; - case AvmMemoryTag::u0: // Unsupported as instruction tag + case AvmMemoryTag::U0: // Unsupported as instruction tag return FF{ 0 }; } - if (in_tag != AvmMemoryTag::ff) { + if (in_tag != AvmMemoryTag::FF) { // a_u128 + b_u128 >= 2^128 <==> c_u128 < a_u128 if (c_u128 < a_u128) { carry = true; @@ -101,12 +101,12 @@ FF AvmMiniAluTraceBuilder::add(FF const& a, FF const& b, AvmMemoryTag in_tag, ui alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, .alu_op_add = true, - .alu_ff_tag = in_tag == AvmMemoryTag::ff, - .alu_u8_tag = in_tag == AvmMemoryTag::u8, - .alu_u16_tag = in_tag == AvmMemoryTag::u16, - .alu_u32_tag = in_tag == AvmMemoryTag::u32, - .alu_u64_tag = in_tag == AvmMemoryTag::u64, - .alu_u128_tag = in_tag == AvmMemoryTag::u128, + .alu_ff_tag = in_tag == AvmMemoryTag::FF, + .alu_u8_tag = in_tag == AvmMemoryTag::U8, + .alu_u16_tag = in_tag == AvmMemoryTag::U16, + .alu_u32_tag = in_tag == AvmMemoryTag::U32, + .alu_u64_tag = in_tag == AvmMemoryTag::U64, + .alu_u128_tag = in_tag == AvmMemoryTag::U128, .alu_ia = a, .alu_ib = b, .alu_ic = c, @@ -146,29 +146,29 @@ FF AvmMiniAluTraceBuilder::sub(FF const& a, FF const& b, AvmMemoryTag in_tag, ui uint128_t c_u128 = a_u128 - b_u128; switch (in_tag) { - case AvmMemoryTag::ff: + case AvmMemoryTag::FF: c = a - b; break; - case AvmMemoryTag::u8: + case AvmMemoryTag::U8: c = FF{ static_cast(c_u128) }; break; - case AvmMemoryTag::u16: + case AvmMemoryTag::U16: c = FF{ static_cast(c_u128) }; break; - case AvmMemoryTag::u32: + case AvmMemoryTag::U32: c = FF{ static_cast(c_u128) }; break; - case AvmMemoryTag::u64: + case AvmMemoryTag::U64: c = FF{ static_cast(c_u128) }; break; - case AvmMemoryTag::u128: + case AvmMemoryTag::U128: c = FF{ uint256_t::from_uint128(c_u128) }; break; - case AvmMemoryTag::u0: // Unsupported as instruction tag + case AvmMemoryTag::U0: // Unsupported as instruction tag return FF{ 0 }; } - if (in_tag != AvmMemoryTag::ff) { + if (in_tag != AvmMemoryTag::FF) { // Underflow when a_u128 < b_u128 if (a_u128 < b_u128) { carry = true; @@ -189,12 +189,12 @@ FF AvmMiniAluTraceBuilder::sub(FF const& a, FF const& b, AvmMemoryTag in_tag, ui alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, .alu_op_sub = true, - .alu_ff_tag = in_tag == AvmMemoryTag::ff, - .alu_u8_tag = in_tag == AvmMemoryTag::u8, - .alu_u16_tag = in_tag == AvmMemoryTag::u16, - .alu_u32_tag = in_tag == AvmMemoryTag::u32, - .alu_u64_tag = in_tag == AvmMemoryTag::u64, - .alu_u128_tag = in_tag == AvmMemoryTag::u128, + .alu_ff_tag = in_tag == AvmMemoryTag::FF, + .alu_u8_tag = in_tag == AvmMemoryTag::U8, + .alu_u16_tag = in_tag == AvmMemoryTag::U16, + .alu_u32_tag = in_tag == AvmMemoryTag::U32, + .alu_u64_tag = in_tag == AvmMemoryTag::U64, + .alu_u128_tag = in_tag == AvmMemoryTag::U128, .alu_ia = a, .alu_ib = b, .alu_ic = c, @@ -232,22 +232,22 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui uint128_t c_u128 = a_u128 * b_u128; // Multiplication over the integers (not mod. 2^64) switch (in_tag) { - case AvmMemoryTag::ff: + case AvmMemoryTag::FF: c = a * b; break; - case AvmMemoryTag::u8: + case AvmMemoryTag::U8: c = FF{ static_cast(c_u128) }; break; - case AvmMemoryTag::u16: + case AvmMemoryTag::U16: c = FF{ static_cast(c_u128) }; break; - case AvmMemoryTag::u32: + case AvmMemoryTag::U32: c = FF{ static_cast(c_u128) }; break; - case AvmMemoryTag::u64: + case AvmMemoryTag::U64: c = FF{ static_cast(c_u128) }; break; - case AvmMemoryTag::u128: { + case AvmMemoryTag::U128: { uint256_t a_u256{ a }; uint256_t b_u256{ b }; uint256_t c_u256 = a_u256 * b_u256; // Multiplication over the integers (not mod. 2^128) @@ -288,7 +288,7 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, .alu_op_mul = true, - .alu_u128_tag = in_tag == AvmMemoryTag::u128, + .alu_u128_tag = in_tag == AvmMemoryTag::U128, .alu_ia = a, .alu_ib = b, .alu_ic = c, @@ -303,12 +303,12 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui return c; } - case AvmMemoryTag::u0: // Unsupported as instruction tag + case AvmMemoryTag::U0: // Unsupported as instruction tag return FF{ 0 }; } // Following code executed for: u8, u16, u32, u64 (u128 returned handled specifically) - if (in_tag != AvmMemoryTag::ff) { + if (in_tag != AvmMemoryTag::FF) { // Decomposition of c_u128 into 8-bit and 16-bit registers as follows: // alu_u8_r0 + alu_u8_r1 * 2^8 + alu_u16_r0 * 2^16 ... + alu_u16_r6 * 2^112 uint128_t c_trunc_128 = c_u128; @@ -327,11 +327,11 @@ FF AvmMiniAluTraceBuilder::mul(FF const& a, FF const& b, AvmMemoryTag in_tag, ui alu_trace.push_back(AvmMiniAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, .alu_op_mul = true, - .alu_ff_tag = in_tag == AvmMemoryTag::ff, - .alu_u8_tag = in_tag == AvmMemoryTag::u8, - .alu_u16_tag = in_tag == AvmMemoryTag::u16, - .alu_u32_tag = in_tag == AvmMemoryTag::u32, - .alu_u64_tag = in_tag == AvmMemoryTag::u64, + .alu_ff_tag = in_tag == AvmMemoryTag::FF, + .alu_u8_tag = in_tag == AvmMemoryTag::U8, + .alu_u16_tag = in_tag == AvmMemoryTag::U16, + .alu_u32_tag = in_tag == AvmMemoryTag::U32, + .alu_u64_tag = in_tag == AvmMemoryTag::U64, .alu_ia = a, .alu_ib = b, .alu_ic = c, diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_common.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_common.hpp index 8588b632b87..10b3c347330 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_common.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_common.hpp @@ -11,7 +11,7 @@ namespace avm_trace { // Number of rows static const size_t AVM_TRACE_SIZE = 256; -enum class IntermRegister : uint32_t { ia = 0, ib = 1, ic = 2 }; -enum class AvmMemoryTag : uint32_t { u0 = 0, u8 = 1, u16 = 2, u32 = 3, u64 = 4, u128 = 5, ff = 6 }; +enum class IntermRegister : uint32_t { IA = 0, IB = 1, IC = 2 }; +enum class AvmMemoryTag : uint32_t { U0 = 0, U8 = 1, U16 = 2, U32 = 3, U64 = 4, U128 = 5, FF = 6 }; } // namespace avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp index e3bcb8c23f4..557244116b1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp @@ -112,19 +112,19 @@ bool AvmMiniMemTraceBuilder::load_in_mem_trace( { uint32_t sub_clk = 0; switch (interm_reg) { - case IntermRegister::ia: + case IntermRegister::IA: sub_clk = SUB_CLK_LOAD_A; break; - case IntermRegister::ib: + case IntermRegister::IB: sub_clk = SUB_CLK_LOAD_B; break; - case IntermRegister::ic: + case IntermRegister::IC: sub_clk = SUB_CLK_LOAD_C; break; } auto m_tag = memory_tag.at(addr); - if (m_tag == AvmMemoryTag::u0 || m_tag == m_in_tag) { + if (m_tag == AvmMemoryTag::U0 || m_tag == m_in_tag) { insert_in_mem_trace(clk, sub_clk, addr, val, m_in_tag, false); return true; } @@ -149,13 +149,13 @@ void AvmMiniMemTraceBuilder::store_in_mem_trace( { uint32_t sub_clk = 0; switch (interm_reg) { - case IntermRegister::ia: + case IntermRegister::IA: sub_clk = SUB_CLK_STORE_A; break; - case IntermRegister::ib: + case IntermRegister::IB: sub_clk = SUB_CLK_STORE_B; break; - case IntermRegister::ic: + case IntermRegister::IC: sub_clk = SUB_CLK_STORE_C; break; } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp index ba56aec9094..771a1590ea1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp @@ -45,8 +45,8 @@ void AvmMiniTraceBuilder::add(uint32_t a_offset, uint32_t b_offset, uint32_t dst auto clk = static_cast(main_trace.size()); // Reading from memory and loading into ia resp. ib. - auto read_a = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::ia, a_offset, in_tag); - auto read_b = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::ib, b_offset, in_tag); + auto read_a = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::IA, a_offset, in_tag); + auto read_b = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::IB, b_offset, in_tag); bool tag_match = read_a.tag_match && read_b.tag_match; // a + b = c @@ -55,7 +55,7 @@ void AvmMiniTraceBuilder::add(uint32_t a_offset, uint32_t b_offset, uint32_t dst FF c = alu_trace_builder.add(a, b, in_tag, clk); // Write into memory value c from intermediate register ic. - mem_trace_builder.write_into_memory(clk, IntermRegister::ic, dst_offset, c, in_tag); + mem_trace_builder.write_into_memory(clk, IntermRegister::IC, dst_offset, c, in_tag); main_trace.push_back(Row{ .avmMini_clk = clk, @@ -90,8 +90,8 @@ void AvmMiniTraceBuilder::sub(uint32_t a_offset, uint32_t b_offset, uint32_t dst auto clk = static_cast(main_trace.size()); // Reading from memory and loading into ia resp. ib. - auto read_a = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::ia, a_offset, in_tag); - auto read_b = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::ib, b_offset, in_tag); + auto read_a = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::IA, a_offset, in_tag); + auto read_b = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::IB, b_offset, in_tag); bool tag_match = read_a.tag_match && read_b.tag_match; // a - b = c @@ -100,7 +100,7 @@ void AvmMiniTraceBuilder::sub(uint32_t a_offset, uint32_t b_offset, uint32_t dst FF c = alu_trace_builder.sub(a, b, in_tag, clk); // Write into memory value c from intermediate register ic. - mem_trace_builder.write_into_memory(clk, IntermRegister::ic, dst_offset, c, in_tag); + mem_trace_builder.write_into_memory(clk, IntermRegister::IC, dst_offset, c, in_tag); main_trace.push_back(Row{ .avmMini_clk = clk, @@ -135,8 +135,8 @@ void AvmMiniTraceBuilder::mul(uint32_t a_offset, uint32_t b_offset, uint32_t dst auto clk = static_cast(main_trace.size()); // Reading from memory and loading into ia resp. ib. - auto read_a = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::ia, a_offset, in_tag); - auto read_b = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::ib, b_offset, in_tag); + auto read_a = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::IA, a_offset, in_tag); + auto read_b = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::IB, b_offset, in_tag); bool tag_match = read_a.tag_match && read_b.tag_match; // a * b = c @@ -145,7 +145,7 @@ void AvmMiniTraceBuilder::mul(uint32_t a_offset, uint32_t b_offset, uint32_t dst FF c = alu_trace_builder.mul(a, b, in_tag, clk); // Write into memory value c from intermediate register ic. - mem_trace_builder.write_into_memory(clk, IntermRegister::ic, dst_offset, c, in_tag); + mem_trace_builder.write_into_memory(clk, IntermRegister::IC, dst_offset, c, in_tag); main_trace.push_back(Row{ .avmMini_clk = clk, @@ -180,8 +180,8 @@ void AvmMiniTraceBuilder::div(uint32_t a_offset, uint32_t b_offset, uint32_t dst auto clk = static_cast(main_trace.size()); // Reading from memory and loading into ia resp. ib. - auto read_a = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::ia, a_offset, in_tag); - auto read_b = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::ib, b_offset, in_tag); + auto read_a = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::IA, a_offset, in_tag); + auto read_b = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::IB, b_offset, in_tag); bool tag_match = read_a.tag_match && read_b.tag_match; // a * b^(-1) = c @@ -203,7 +203,7 @@ void AvmMiniTraceBuilder::div(uint32_t a_offset, uint32_t b_offset, uint32_t dst } // Write into memory value c from intermediate register ic. - mem_trace_builder.write_into_memory(clk, IntermRegister::ic, dst_offset, c, in_tag); + mem_trace_builder.write_into_memory(clk, IntermRegister::IC, dst_offset, c, in_tag); main_trace.push_back(Row{ .avmMini_clk = clk, @@ -245,7 +245,7 @@ void AvmMiniTraceBuilder::set(uint128_t val, uint32_t dst_offset, AvmMemoryTag i auto clk = static_cast(main_trace.size()); auto val_ff = FF{ uint256_t::from_uint128(val) }; - mem_trace_builder.write_into_memory(clk, IntermRegister::ic, dst_offset, val_ff, in_tag); + mem_trace_builder.write_into_memory(clk, IntermRegister::IC, dst_offset, val_ff, in_tag); main_trace.push_back(Row{ .avmMini_clk = clk, @@ -310,7 +310,7 @@ void AvmMiniTraceBuilder::call_data_copy(uint32_t cd_offset, uint32_t rwa = 1; // Storing from Ia - mem_trace_builder.write_into_memory(clk, IntermRegister::ia, mem_idx_a, ia, AvmMemoryTag::ff); + mem_trace_builder.write_into_memory(clk, IntermRegister::IA, mem_idx_a, ia, AvmMemoryTag::FF); if (copy_size - pos > 1) { ib = call_data_mem.at(cd_offset + pos + 1); @@ -319,7 +319,7 @@ void AvmMiniTraceBuilder::call_data_copy(uint32_t cd_offset, rwb = 1; // Storing from Ib - mem_trace_builder.write_into_memory(clk, IntermRegister::ib, mem_idx_b, ib, AvmMemoryTag::ff); + mem_trace_builder.write_into_memory(clk, IntermRegister::IB, mem_idx_b, ib, AvmMemoryTag::FF); } if (copy_size - pos > 2) { @@ -329,14 +329,14 @@ void AvmMiniTraceBuilder::call_data_copy(uint32_t cd_offset, rwc = 1; // Storing from Ic - mem_trace_builder.write_into_memory(clk, IntermRegister::ic, mem_idx_c, ic, AvmMemoryTag::ff); + mem_trace_builder.write_into_memory(clk, IntermRegister::IC, mem_idx_c, ic, AvmMemoryTag::FF); } 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_in_tag = FF(static_cast(AvmMemoryTag::FF)), .avmMini_ia = ia, .avmMini_ib = ib, .avmMini_ic = ic, @@ -398,7 +398,7 @@ std::vector AvmMiniTraceBuilder::return_op(uint32_t ret_offset, uint32_t ret uint32_t mem_idx_a = ret_offset + pos; // Reading and loading to Ia - auto read_a = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::ia, mem_idx_a, AvmMemoryTag::ff); + auto read_a = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::IA, mem_idx_a, AvmMemoryTag::FF); FF ia = read_a.val; returnMem.push_back(ia); @@ -408,7 +408,7 @@ std::vector AvmMiniTraceBuilder::return_op(uint32_t ret_offset, uint32_t ret // Reading and loading to Ib auto read_b = - mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::ib, mem_idx_b, AvmMemoryTag::ff); + mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::IB, mem_idx_b, AvmMemoryTag::FF); FF ib = read_b.val; returnMem.push_back(ib); } @@ -419,7 +419,7 @@ std::vector AvmMiniTraceBuilder::return_op(uint32_t ret_offset, uint32_t ret // Reading and loading to Ic auto read_c = - mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::ic, mem_idx_c, AvmMemoryTag::ff); + mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::IC, mem_idx_c, AvmMemoryTag::FF); FF ic = read_c.val; returnMem.push_back(ic); } @@ -429,7 +429,7 @@ std::vector AvmMiniTraceBuilder::return_op(uint32_t ret_offset, uint32_t ret .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_in_tag = FF(static_cast(AvmMemoryTag::FF)), .avmMini_ia = ia, .avmMini_ib = ib, .avmMini_ic = ic, @@ -514,7 +514,7 @@ void AvmMiniTraceBuilder::internal_call(uint32_t jmp_dest) internal_call_stack.push(stored_pc); // Add the return location to the memory trace - mem_trace_builder.write_into_memory(clk, IntermRegister::ib, internal_return_ptr, FF(stored_pc), AvmMemoryTag::ff); + 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, @@ -550,7 +550,7 @@ void AvmMiniTraceBuilder::internal_return() // Internal return pointer is decremented // We want to load the value pointed by the internal pointer auto read_a = - mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::ia, internal_return_ptr - 1, AvmMemoryTag::ff); + 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, diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index e69071f992a..57060f411e1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -248,11 +248,11 @@ TEST_F(AvmMiniArithmeticTestsFF, addition) trace_builder.call_data_copy(0, 3, 0, std::vector{ 37, 4, 11 }); // Memory layout: [37,4,11,0,0,0,....] - trace_builder.add(0, 1, 4, AvmMemoryTag::ff); // [37,4,11,0,41,0,....] + trace_builder.add(0, 1, 4, AvmMemoryTag::FF); // [37,4,11,0,41,0,....] trace_builder.return_op(0, 5); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_add(trace, FF(37), FF(4), FF(41), FF(0), FF(1), FF(4), AvmMemoryTag::ff); + 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)); @@ -267,11 +267,11 @@ TEST_F(AvmMiniArithmeticTestsFF, subtraction) trace_builder.call_data_copy(0, 3, 0, std::vector{ 8, 4, 17 }); // Memory layout: [8,4,17,0,0,0,....] - trace_builder.sub(2, 0, 1, AvmMemoryTag::ff); // [8,9,17,0,0,0....] + trace_builder.sub(2, 0, 1, AvmMemoryTag::FF); // [8,9,17,0,0,0....] trace_builder.return_op(0, 3); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_sub(trace, FF(17), FF(8), FF(9), FF(2), FF(0), FF(1), AvmMemoryTag::ff); + 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)); @@ -286,11 +286,11 @@ TEST_F(AvmMiniArithmeticTestsFF, multiplication) trace_builder.call_data_copy(0, 3, 0, std::vector{ 5, 0, 20 }); // Memory layout: [5,0,20,0,0,0,....] - trace_builder.mul(2, 0, 1, AvmMemoryTag::ff); // [5,100,20,0,0,0....] + trace_builder.mul(2, 0, 1, AvmMemoryTag::FF); // [5,100,20,0,0,0....] trace_builder.return_op(0, 3); auto trace = trace_builder.finalize(); - 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_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)); @@ -306,11 +306,11 @@ TEST_F(AvmMiniArithmeticTestsFF, multiplicationByZero) trace_builder.call_data_copy(0, 1, 0, std::vector{ 127 }); // Memory layout: [127,0,0,0,0,0,....] - trace_builder.mul(0, 1, 2, AvmMemoryTag::ff); // [127,0,0,0,0,0....] + trace_builder.mul(0, 1, 2, AvmMemoryTag::FF); // [127,0,0,0,0,0....] trace_builder.return_op(0, 3); auto trace = trace_builder.finalize(); - 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_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)); @@ -326,7 +326,7 @@ TEST_F(AvmMiniArithmeticTestsFF, division) trace_builder.call_data_copy(0, 2, 0, std::vector{ 15, 315 }); // Memory layout: [15,315,0,0,0,0,....] - trace_builder.div(1, 0, 2, AvmMemoryTag::ff); // [15,315,21,0,0,0....] + trace_builder.div(1, 0, 2, AvmMemoryTag::FF); // [15,315,21,0,0,0....] trace_builder.return_op(0, 3); auto trace = trace_builder.finalize(); @@ -349,7 +349,7 @@ TEST_F(AvmMiniArithmeticTestsFF, divisionNumeratorZero) trace_builder.call_data_copy(0, 1, 0, std::vector{ 15 }); // Memory layout: [15,0,0,0,0,0,....] - trace_builder.div(1, 0, 0, AvmMemoryTag::ff); // [0,0,0,0,0,0....] + trace_builder.div(1, 0, 0, AvmMemoryTag::FF); // [0,0,0,0,0,0....] trace_builder.return_op(0, 3); auto trace = trace_builder.finalize(); @@ -373,7 +373,7 @@ TEST_F(AvmMiniArithmeticTestsFF, divisionByZeroError) trace_builder.call_data_copy(0, 1, 0, std::vector{ 15 }); // Memory layout: [15,0,0,0,0,0,....] - trace_builder.div(0, 1, 2, AvmMemoryTag::ff); // [15,0,0,0,0,0....] + trace_builder.div(0, 1, 2, AvmMemoryTag::FF); // [15,0,0,0,0,0....] trace_builder.halt(); auto trace = trace_builder.finalize(); @@ -396,7 +396,7 @@ TEST_F(AvmMiniArithmeticTestsFF, divisionByZeroError) TEST_F(AvmMiniArithmeticTestsFF, divisionZeroByZeroError) { // Memory layout: [0,0,0,0,0,0,....] - trace_builder.div(0, 1, 2, AvmMemoryTag::ff); // [0,0,0,0,0,0....] + trace_builder.div(0, 1, 2, AvmMemoryTag::FF); // [0,0,0,0,0,0....] trace_builder.halt(); auto trace = trace_builder.finalize(); @@ -423,16 +423,16 @@ TEST_F(AvmMiniArithmeticTestsFF, mixedOperationsWithError) trace_builder.call_data_copy(0, 3, 2, std::vector{ 45, 23, 12 }); // Memory layout: [0,0,45,23,12,0,0,0,....] - trace_builder.add(2, 3, 4, AvmMemoryTag::ff); // [0,0,45,23,68,0,0,0,....] - trace_builder.add(4, 5, 5, AvmMemoryTag::ff); // [0,0,45,23,68,68,0,0,....] - trace_builder.add(5, 5, 5, AvmMemoryTag::ff); // [0,0,45,23,68,136,0,0,....] - trace_builder.add(5, 6, 7, AvmMemoryTag::ff); // [0,0,45,23,68,136,0,136,0....] - trace_builder.sub(7, 6, 8, AvmMemoryTag::ff); // [0,0,45,23,68,136,0,136,136,0....] - trace_builder.mul(8, 8, 8, AvmMemoryTag::ff); // [0,0,45,23,68,136,0,136,136^2,0....] - trace_builder.div(3, 5, 1, AvmMemoryTag::ff); // [0,23*136^(-1),45,23,68,136,0,136,136^2,0....] - trace_builder.div(1, 1, 9, AvmMemoryTag::ff); // [0,23*136^(-1),45,23,68,136,0,136,136^2,1,0....] + trace_builder.add(2, 3, 4, AvmMemoryTag::FF); // [0,0,45,23,68,0,0,0,....] + trace_builder.add(4, 5, 5, AvmMemoryTag::FF); // [0,0,45,23,68,68,0,0,....] + trace_builder.add(5, 5, 5, AvmMemoryTag::FF); // [0,0,45,23,68,136,0,0,....] + trace_builder.add(5, 6, 7, AvmMemoryTag::FF); // [0,0,45,23,68,136,0,136,0....] + trace_builder.sub(7, 6, 8, AvmMemoryTag::FF); // [0,0,45,23,68,136,0,136,136,0....] + trace_builder.mul(8, 8, 8, AvmMemoryTag::FF); // [0,0,45,23,68,136,0,136,136^2,0....] + trace_builder.div(3, 5, 1, AvmMemoryTag::FF); // [0,23*136^(-1),45,23,68,136,0,136,136^2,0....] + trace_builder.div(1, 1, 9, AvmMemoryTag::FF); // [0,23*136^(-1),45,23,68,136,0,136,136^2,1,0....] trace_builder.div( - 9, 0, 4, AvmMemoryTag::ff); // [0,23*136^(-1),45,23,1/0,136,0,136,136^2,1,0....] Error: division by 0 + 9, 0, 4, AvmMemoryTag::FF); // [0,23*136^(-1),45,23,1/0,136,0,136,136^2,1,0....] Error: division by 0 trace_builder.halt(); auto trace = trace_builder.finalize(); @@ -447,15 +447,15 @@ TEST_F(AvmMiniArithmeticTestsFF, mixedOperationsWithError) TEST_F(AvmMiniArithmeticTestsU8, addition) { // trace_builder - trace_builder.set(62, 0, AvmMemoryTag::u8); - trace_builder.set(29, 1, AvmMemoryTag::u8); + trace_builder.set(62, 0, AvmMemoryTag::U8); + trace_builder.set(29, 1, AvmMemoryTag::U8); // Memory layout: [62,29,0,0,0,....] - trace_builder.add(0, 1, 2, AvmMemoryTag::u8); // [62,29,91,0,0,....] + trace_builder.add(0, 1, 2, AvmMemoryTag::U8); // [62,29,91,0,0,....] trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_add(trace, FF(62), FF(29), FF(91), FF(0), FF(1), FF(2), AvmMemoryTag::u8); + 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)); @@ -467,15 +467,15 @@ TEST_F(AvmMiniArithmeticTestsU8, addition) TEST_F(AvmMiniArithmeticTestsU8, additionCarry) { // trace_builder - trace_builder.set(159, 0, AvmMemoryTag::u8); - trace_builder.set(100, 1, AvmMemoryTag::u8); + trace_builder.set(159, 0, AvmMemoryTag::U8); + trace_builder.set(100, 1, AvmMemoryTag::U8); // Memory layout: [159,100,0,0,0,....] - trace_builder.add(0, 1, 2, AvmMemoryTag::u8); // [159,100,3,0,0,....] + trace_builder.add(0, 1, 2, AvmMemoryTag::U8); // [159,100,3,0,0,....] trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_add(trace, FF(159), FF(100), FF(3), FF(0), FF(1), FF(2), AvmMemoryTag::u8); + 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)); @@ -489,15 +489,15 @@ TEST_F(AvmMiniArithmeticTestsU8, additionCarry) TEST_F(AvmMiniArithmeticTestsU8, subtraction) { // trace_builder - trace_builder.set(162, 0, AvmMemoryTag::u8); - trace_builder.set(29, 1, AvmMemoryTag::u8); + trace_builder.set(162, 0, AvmMemoryTag::U8); + trace_builder.set(29, 1, AvmMemoryTag::U8); // Memory layout: [162,29,0,0,0,....] - trace_builder.sub(0, 1, 2, AvmMemoryTag::u8); // [162,29,133,0,0,....] + trace_builder.sub(0, 1, 2, AvmMemoryTag::U8); // [162,29,133,0,0,....] trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_sub(trace, FF(162), FF(29), FF(133), FF(0), FF(1), FF(2), AvmMemoryTag::u8); + 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)); @@ -511,15 +511,15 @@ TEST_F(AvmMiniArithmeticTestsU8, subtraction) TEST_F(AvmMiniArithmeticTestsU8, subtractionCarry) { // trace_builder - trace_builder.set(5, 0, AvmMemoryTag::u8); - trace_builder.set(29, 1, AvmMemoryTag::u8); + trace_builder.set(5, 0, AvmMemoryTag::U8); + trace_builder.set(29, 1, AvmMemoryTag::U8); // Memory layout: [5,29,0,0,0,....] - trace_builder.sub(0, 1, 2, AvmMemoryTag::u8); // [5,29,232,0,0,....] + trace_builder.sub(0, 1, 2, AvmMemoryTag::U8); // [5,29,232,0,0,....] trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_sub(trace, FF(5), FF(29), FF(232), FF(0), FF(1), FF(2), AvmMemoryTag::u8); + 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)); @@ -540,14 +540,14 @@ TEST_F(AvmMiniArithmeticTestsU8, subtractionCarry) TEST_F(AvmMiniArithmeticTestsU8, multiplication) { // trace_builder - trace_builder.set(13, 0, AvmMemoryTag::u8); - trace_builder.set(15, 1, AvmMemoryTag::u8); + trace_builder.set(13, 0, AvmMemoryTag::U8); + trace_builder.set(15, 1, AvmMemoryTag::U8); - trace_builder.mul(0, 1, 2, AvmMemoryTag::u8); + trace_builder.mul(0, 1, 2, AvmMemoryTag::U8); trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - 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_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)); @@ -563,14 +563,14 @@ TEST_F(AvmMiniArithmeticTestsU8, multiplication) TEST_F(AvmMiniArithmeticTestsU8, multiplicationOverflow) { // trace_builder - trace_builder.set(200, 0, AvmMemoryTag::u8); - trace_builder.set(170, 1, AvmMemoryTag::u8); + trace_builder.set(200, 0, AvmMemoryTag::U8); + trace_builder.set(170, 1, AvmMemoryTag::U8); - trace_builder.mul(0, 1, 2, AvmMemoryTag::u8); + trace_builder.mul(0, 1, 2, AvmMemoryTag::U8); trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - 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_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)); @@ -591,15 +591,15 @@ TEST_F(AvmMiniArithmeticTestsU8, multiplicationOverflow) TEST_F(AvmMiniArithmeticTestsU16, addition) { // trace_builder - trace_builder.set(1775, 119, AvmMemoryTag::u16); - trace_builder.set(33005, 546, AvmMemoryTag::u16); + trace_builder.set(1775, 119, AvmMemoryTag::U16); + trace_builder.set(33005, 546, AvmMemoryTag::U16); - trace_builder.add(546, 119, 5, AvmMemoryTag::u16); + trace_builder.add(546, 119, 5, AvmMemoryTag::U16); trace_builder.return_op(5, 1); auto trace = trace_builder.finalize(); auto alu_row = - common_validate_add(trace, FF(33005), FF(1775), FF(34780), FF(546), FF(119), FF(5), AvmMemoryTag::u16); + 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)); @@ -613,15 +613,15 @@ TEST_F(AvmMiniArithmeticTestsU16, addition) TEST_F(AvmMiniArithmeticTestsU16, additionCarry) { // trace_builder - trace_builder.set(UINT16_MAX - 982, 0, AvmMemoryTag::u16); - trace_builder.set(1000, 1, AvmMemoryTag::u16); + trace_builder.set(UINT16_MAX - 982, 0, AvmMemoryTag::U16); + trace_builder.set(1000, 1, AvmMemoryTag::U16); - trace_builder.add(1, 0, 0, AvmMemoryTag::u16); + trace_builder.add(1, 0, 0, AvmMemoryTag::U16); trace_builder.return_op(0, 1); auto trace = trace_builder.finalize(); auto alu_row = - common_validate_add(trace, FF(1000), FF(UINT16_MAX - 982), FF(17), FF(1), FF(0), FF(0), AvmMemoryTag::u16); + 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)); @@ -635,15 +635,15 @@ TEST_F(AvmMiniArithmeticTestsU16, additionCarry) TEST_F(AvmMiniArithmeticTestsU16, subtraction) { // trace_builder - trace_builder.set(1775, 119, AvmMemoryTag::u16); - trace_builder.set(33005, 546, AvmMemoryTag::u16); + trace_builder.set(1775, 119, AvmMemoryTag::U16); + trace_builder.set(33005, 546, AvmMemoryTag::U16); - trace_builder.sub(546, 119, 5, AvmMemoryTag::u16); + trace_builder.sub(546, 119, 5, AvmMemoryTag::U16); trace_builder.return_op(5, 1); auto trace = trace_builder.finalize(); auto alu_row = - common_validate_sub(trace, FF(33005), FF(1775), FF(31230), FF(546), FF(119), FF(5), AvmMemoryTag::u16); + 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)); @@ -659,15 +659,15 @@ TEST_F(AvmMiniArithmeticTestsU16, subtraction) TEST_F(AvmMiniArithmeticTestsU16, subtractionCarry) { // trace_builder - trace_builder.set(UINT16_MAX - 982, 0, AvmMemoryTag::u16); - trace_builder.set(1000, 1, AvmMemoryTag::u16); + trace_builder.set(UINT16_MAX - 982, 0, AvmMemoryTag::U16); + trace_builder.set(1000, 1, AvmMemoryTag::U16); - trace_builder.sub(1, 0, 0, AvmMemoryTag::u16); + trace_builder.sub(1, 0, 0, AvmMemoryTag::U16); trace_builder.return_op(0, 1); auto trace = trace_builder.finalize(); auto alu_row = - common_validate_sub(trace, FF(1000), FF(UINT16_MAX - 982), FF(1983), FF(1), FF(0), FF(0), AvmMemoryTag::u16); + 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)); @@ -688,15 +688,15 @@ TEST_F(AvmMiniArithmeticTestsU16, subtractionCarry) TEST_F(AvmMiniArithmeticTestsU16, multiplication) { // trace_builder - trace_builder.set(200, 0, AvmMemoryTag::u16); - trace_builder.set(245, 1, AvmMemoryTag::u16); + trace_builder.set(200, 0, AvmMemoryTag::U16); + trace_builder.set(245, 1, AvmMemoryTag::U16); - trace_builder.mul(0, 1, 2, AvmMemoryTag::u16); + trace_builder.mul(0, 1, 2, AvmMemoryTag::U16); trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); auto alu_row_index = - common_validate_mul(trace, FF(200), FF(245), FF(49000), FF(0), FF(1), FF(2), AvmMemoryTag::u16); + 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)); @@ -713,14 +713,14 @@ TEST_F(AvmMiniArithmeticTestsU16, multiplication) TEST_F(AvmMiniArithmeticTestsU16, multiplicationOverflow) { // trace_builder - trace_builder.set(512, 0, AvmMemoryTag::u16); - trace_builder.set(1024, 1, AvmMemoryTag::u16); + trace_builder.set(512, 0, AvmMemoryTag::U16); + trace_builder.set(1024, 1, AvmMemoryTag::U16); - trace_builder.mul(0, 1, 2, AvmMemoryTag::u16); + trace_builder.mul(0, 1, 2, AvmMemoryTag::U16); trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - 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_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)); @@ -743,15 +743,15 @@ TEST_F(AvmMiniArithmeticTestsU16, multiplicationOverflow) TEST_F(AvmMiniArithmeticTestsU32, addition) { // trace_builder - trace_builder.set(1000000000, 8, AvmMemoryTag::u32); - trace_builder.set(1234567891, 9, AvmMemoryTag::u32); + trace_builder.set(1000000000, 8, AvmMemoryTag::U32); + trace_builder.set(1234567891, 9, AvmMemoryTag::U32); - trace_builder.add(8, 9, 0, AvmMemoryTag::u32); + trace_builder.add(8, 9, 0, AvmMemoryTag::U32); trace_builder.return_op(0, 1); auto trace = trace_builder.finalize(); auto alu_row = common_validate_add( - trace, FF(1000000000), FF(1234567891), FF(2234567891LLU), FF(8), FF(9), FF(0), AvmMemoryTag::u32); + 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)); @@ -766,15 +766,15 @@ TEST_F(AvmMiniArithmeticTestsU32, addition) TEST_F(AvmMiniArithmeticTestsU32, additionCarry) { // trace_builder - trace_builder.set(UINT32_MAX - 1293, 8, AvmMemoryTag::u32); - trace_builder.set(2293, 9, AvmMemoryTag::u32); + trace_builder.set(UINT32_MAX - 1293, 8, AvmMemoryTag::U32); + trace_builder.set(2293, 9, AvmMemoryTag::U32); - trace_builder.add(8, 9, 0, AvmMemoryTag::u32); + trace_builder.add(8, 9, 0, AvmMemoryTag::U32); trace_builder.return_op(0, 1); auto trace = trace_builder.finalize(); auto alu_row = - common_validate_add(trace, FF(UINT32_MAX - 1293), FF(2293), FF(999), FF(8), FF(9), FF(0), AvmMemoryTag::u32); + 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)); @@ -788,15 +788,15 @@ TEST_F(AvmMiniArithmeticTestsU32, additionCarry) TEST_F(AvmMiniArithmeticTestsU32, subtraction) { // trace_builder - trace_builder.set(1345678991, 8, AvmMemoryTag::u32); - trace_builder.set(1234567891, 9, AvmMemoryTag::u32); + trace_builder.set(1345678991, 8, AvmMemoryTag::U32); + trace_builder.set(1234567891, 9, AvmMemoryTag::U32); - trace_builder.sub(8, 9, 0, AvmMemoryTag::u32); + trace_builder.sub(8, 9, 0, AvmMemoryTag::U32); trace_builder.return_op(0, 1); auto trace = trace_builder.finalize(); auto alu_row = common_validate_sub( - trace, FF(1345678991), FF(1234567891), FF(111111100), FF(8), FF(9), FF(0), AvmMemoryTag::u32); + 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)); @@ -815,15 +815,15 @@ TEST_F(AvmMiniArithmeticTestsU32, subtraction) TEST_F(AvmMiniArithmeticTestsU32, subtractionCarry) { // trace_builder - trace_builder.set(UINT32_MAX - 99, 8, AvmMemoryTag::u32); - trace_builder.set(3210987654, 9, AvmMemoryTag::u32); + trace_builder.set(UINT32_MAX - 99, 8, AvmMemoryTag::U32); + trace_builder.set(3210987654, 9, AvmMemoryTag::U32); - trace_builder.sub(9, 8, 0, AvmMemoryTag::u32); + trace_builder.sub(9, 8, 0, AvmMemoryTag::U32); trace_builder.return_op(0, 1); auto trace = trace_builder.finalize(); auto alu_row = common_validate_sub( - trace, FF(3210987654LLU), FF(UINT32_MAX - 99), FF(3210987754LLU), FF(9), FF(8), FF(0), AvmMemoryTag::u32); + 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)); @@ -846,15 +846,15 @@ TEST_F(AvmMiniArithmeticTestsU32, subtractionCarry) TEST_F(AvmMiniArithmeticTestsU32, multiplication) { // trace_builder - trace_builder.set(11111, 0, AvmMemoryTag::u32); - trace_builder.set(11111, 1, AvmMemoryTag::u32); + trace_builder.set(11111, 0, AvmMemoryTag::U32); + trace_builder.set(11111, 1, AvmMemoryTag::U32); - trace_builder.mul(0, 1, 2, AvmMemoryTag::u32); + trace_builder.mul(0, 1, 2, AvmMemoryTag::U32); trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); auto alu_row_index = - common_validate_mul(trace, FF(11111), FF(11111), FF(123454321), FF(0), FF(1), FF(2), AvmMemoryTag::u32); + 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)); @@ -875,15 +875,15 @@ TEST_F(AvmMiniArithmeticTestsU32, multiplication) TEST_F(AvmMiniArithmeticTestsU32, multiplicationOverflow) { // trace_builder - trace_builder.set(11 << 25, 0, AvmMemoryTag::u32); - trace_builder.set(13 << 22, 1, AvmMemoryTag::u32); + trace_builder.set(11 << 25, 0, AvmMemoryTag::U32); + trace_builder.set(13 << 22, 1, AvmMemoryTag::U32); - trace_builder.mul(0, 1, 2, AvmMemoryTag::u32); + trace_builder.mul(0, 1, 2, AvmMemoryTag::U32); trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); auto alu_row_index = - common_validate_mul(trace, FF(11 << 25), FF(13 << 22), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::u32); + 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)); @@ -912,14 +912,14 @@ TEST_F(AvmMiniArithmeticTestsU64, addition) uint64_t const c = 10193042407517981LLU; // trace_builder - trace_builder.set(a, 8, AvmMemoryTag::u64); - trace_builder.set(b, 9, AvmMemoryTag::u64); + trace_builder.set(a, 8, AvmMemoryTag::U64); + trace_builder.set(b, 9, AvmMemoryTag::U64); - trace_builder.add(8, 9, 9, AvmMemoryTag::u64); + trace_builder.add(8, 9, 9, AvmMemoryTag::U64); trace_builder.return_op(9, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_add(trace, FF(a), FF(b), FF(c), FF(8), FF(9), FF(9), AvmMemoryTag::u64); + 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)); @@ -942,14 +942,14 @@ TEST_F(AvmMiniArithmeticTestsU64, additionCarry) uint64_t const c = UINT64_MAX - 201LLU; // trace_builder - trace_builder.set(a, 0, AvmMemoryTag::u64); - trace_builder.set(b, 1, AvmMemoryTag::u64); + trace_builder.set(a, 0, AvmMemoryTag::U64); + trace_builder.set(b, 1, AvmMemoryTag::U64); - trace_builder.add(0, 1, 0, AvmMemoryTag::u64); + trace_builder.add(0, 1, 0, AvmMemoryTag::U64); trace_builder.return_op(0, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_add(trace, FF(a), FF(b), FF(c), FF(0), FF(1), FF(0), AvmMemoryTag::u64); + 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)); @@ -970,14 +970,14 @@ TEST_F(AvmMiniArithmeticTestsU64, subtraction) uint64_t const c = 10000000000000000LLU; // trace_builder - trace_builder.set(a, 8, AvmMemoryTag::u64); - trace_builder.set(b, 9, AvmMemoryTag::u64); + trace_builder.set(a, 8, AvmMemoryTag::U64); + trace_builder.set(b, 9, AvmMemoryTag::U64); - trace_builder.sub(8, 9, 9, AvmMemoryTag::u64); + trace_builder.sub(8, 9, 9, AvmMemoryTag::U64); trace_builder.return_op(9, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_sub(trace, FF(a), FF(b), FF(c), FF(8), FF(9), FF(9), AvmMemoryTag::u64); + 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)); @@ -1002,14 +1002,14 @@ TEST_F(AvmMiniArithmeticTestsU64, subtractionCarry) uint64_t const c = UINT64_MAX - 74; // trace_builder - trace_builder.set(a, 0, AvmMemoryTag::u64); - trace_builder.set(b, 1, AvmMemoryTag::u64); + trace_builder.set(a, 0, AvmMemoryTag::U64); + trace_builder.set(b, 1, AvmMemoryTag::U64); - trace_builder.sub(0, 1, 0, AvmMemoryTag::u64); + trace_builder.sub(0, 1, 0, AvmMemoryTag::U64); trace_builder.return_op(0, 1); auto trace = trace_builder.finalize(); - auto alu_row = common_validate_sub(trace, FF(a), FF(b), FF(c), FF(0), FF(1), FF(0), AvmMemoryTag::u64); + 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)); @@ -1030,15 +1030,15 @@ TEST_F(AvmMiniArithmeticTestsU64, subtractionCarry) TEST_F(AvmMiniArithmeticTestsU64, multiplication) { // trace_builder - trace_builder.set(999888777, 0, AvmMemoryTag::u64); - trace_builder.set(555444333, 1, AvmMemoryTag::u64); + trace_builder.set(999888777, 0, AvmMemoryTag::U64); + trace_builder.set(555444333, 1, AvmMemoryTag::U64); - trace_builder.mul(0, 1, 2, AvmMemoryTag::u64); + trace_builder.mul(0, 1, 2, AvmMemoryTag::U64); trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); auto alu_row_index = common_validate_mul( - trace, FF(999888777), FF(555444333), FF(555382554814950741LLU), FF(0), FF(1), FF(2), AvmMemoryTag::u64); + 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)); @@ -1063,14 +1063,14 @@ TEST_F(AvmMiniArithmeticTestsU64, multiplicationOverflow) // (2^64 - 1)^2 = 2^128 - 2^65 + 1 (mod. 2^64) = 1 // trace_builder - trace_builder.set(a, 0, AvmMemoryTag::u64); - trace_builder.set(b, 1, AvmMemoryTag::u64); + trace_builder.set(a, 0, AvmMemoryTag::U64); + trace_builder.set(b, 1, AvmMemoryTag::U64); - trace_builder.mul(0, 1, 2, AvmMemoryTag::u64); + trace_builder.mul(0, 1, 2, AvmMemoryTag::U64); trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); - 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_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)); @@ -1102,10 +1102,10 @@ TEST_F(AvmMiniArithmeticTestsU128, addition) uint128_t const c = (uint128_t{ 0x8888444466665555LLU } << 64) + uint128_t{ 0xDDDDAAAAFFFFEEEELLU }; // trace_builder - trace_builder.set(a, 8, AvmMemoryTag::u128); - trace_builder.set(b, 9, AvmMemoryTag::u128); + trace_builder.set(a, 8, AvmMemoryTag::U128); + trace_builder.set(b, 9, AvmMemoryTag::U128); - trace_builder.add(8, 9, 9, AvmMemoryTag::u128); + trace_builder.add(8, 9, 9, AvmMemoryTag::U128); trace_builder.return_op(9, 1); auto trace = trace_builder.finalize(); @@ -1116,7 +1116,7 @@ TEST_F(AvmMiniArithmeticTestsU128, addition) FF(8), FF(9), FF(9), - AvmMemoryTag::u128); + AvmMemoryTag::U128); EXPECT_EQ(alu_row.aluChip_alu_u128_tag, FF(1)); EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); @@ -1142,10 +1142,10 @@ TEST_F(AvmMiniArithmeticTestsU128, additionCarry) (uint128_t{ UINT64_MAX } << 64) + uint128_t{ UINT64_MAX } - uint128_t{ 36177345 } - uint128_t{ 72948899 }; // trace_builder - trace_builder.set(a, 8, AvmMemoryTag::u128); - trace_builder.set(b, 9, AvmMemoryTag::u128); + trace_builder.set(a, 8, AvmMemoryTag::U128); + trace_builder.set(b, 9, AvmMemoryTag::U128); - trace_builder.add(8, 9, 9, AvmMemoryTag::u128); + trace_builder.add(8, 9, 9, AvmMemoryTag::U128); trace_builder.return_op(9, 1); auto trace = trace_builder.finalize(); @@ -1156,7 +1156,7 @@ TEST_F(AvmMiniArithmeticTestsU128, additionCarry) FF(8), FF(9), FF(9), - AvmMemoryTag::u128); + AvmMemoryTag::U128); EXPECT_EQ(alu_row.aluChip_alu_u128_tag, FF(1)); EXPECT_EQ(alu_row.aluChip_alu_cf, FF(1)); @@ -1181,10 +1181,10 @@ TEST_F(AvmMiniArithmeticTestsU128, subtraction) uint128_t const c = 36771555; // 72948899 - 36177344 // trace_builder - trace_builder.set(a, 8, AvmMemoryTag::u128); - trace_builder.set(b, 9, AvmMemoryTag::u128); + trace_builder.set(a, 8, AvmMemoryTag::U128); + trace_builder.set(b, 9, AvmMemoryTag::U128); - trace_builder.sub(8, 9, 9, AvmMemoryTag::u128); + trace_builder.sub(8, 9, 9, AvmMemoryTag::U128); trace_builder.return_op(9, 1); auto trace = trace_builder.finalize(); @@ -1195,7 +1195,7 @@ TEST_F(AvmMiniArithmeticTestsU128, subtraction) FF(8), FF(9), FF(9), - AvmMemoryTag::u128); + AvmMemoryTag::U128); EXPECT_EQ(alu_row.aluChip_alu_u128_tag, FF(1)); EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); @@ -1223,10 +1223,10 @@ TEST_F(AvmMiniArithmeticTestsU128, subtractionCarry) uint128_t const c = (uint128_t{ 0x2222000000003333LLU } << 64) + uint128_t{ 0x3333888855558888LLU }; // trace_builder - trace_builder.set(a, 8, AvmMemoryTag::u128); - trace_builder.set(b, 9, AvmMemoryTag::u128); + trace_builder.set(a, 8, AvmMemoryTag::U128); + trace_builder.set(b, 9, AvmMemoryTag::U128); - trace_builder.sub(8, 9, 9, AvmMemoryTag::u128); + trace_builder.sub(8, 9, 9, AvmMemoryTag::U128); trace_builder.return_op(9, 1); auto trace = trace_builder.finalize(); @@ -1237,7 +1237,7 @@ TEST_F(AvmMiniArithmeticTestsU128, subtractionCarry) FF(8), FF(9), FF(9), - AvmMemoryTag::u128); + AvmMemoryTag::U128); EXPECT_EQ(alu_row.aluChip_alu_u128_tag, FF(1)); EXPECT_EQ(alu_row.aluChip_alu_cf, FF(0)); @@ -1259,17 +1259,17 @@ TEST_F(AvmMiniArithmeticTestsU128, subtractionCarry) TEST_F(AvmMiniArithmeticTestsU128, multiplication) { // trace_builder - trace_builder.set(0x38D64BF685FFBLLU, 0, AvmMemoryTag::u128); - trace_builder.set(0x1F92C762C98DFLLU, 1, AvmMemoryTag::u128); + trace_builder.set(0x38D64BF685FFBLLU, 0, AvmMemoryTag::U128); + trace_builder.set(0x1F92C762C98DFLLU, 1, AvmMemoryTag::U128); // Integer multiplication output in HEX: 70289AEB0A7DDA0BAE60CA3A5 FF c{ uint256_t{ 0xA7DDA0BAE60CA3A5, 0x70289AEB0, 0, 0 } }; - trace_builder.mul(0, 1, 2, AvmMemoryTag::u128); + trace_builder.mul(0, 1, 2, AvmMemoryTag::U128); trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); auto alu_row_index = common_validate_mul( - trace, FF(0x38D64BF685FFBLLU), FF(555444333222111LLU), c, FF(0), FF(1), FF(2), AvmMemoryTag::u128); + 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)); @@ -1298,10 +1298,10 @@ TEST_F(AvmMiniArithmeticTestsU128, multiplicationOverflow) uint128_t const b = (uint128_t{ UINT64_MAX } << 64) + uint128_t{ UINT64_MAX - 3 }; // trace_builder - trace_builder.set(a, 0, AvmMemoryTag::u128); - trace_builder.set(b, 1, AvmMemoryTag::u128); + trace_builder.set(a, 0, AvmMemoryTag::U128); + trace_builder.set(b, 1, AvmMemoryTag::U128); - trace_builder.mul(0, 1, 2, AvmMemoryTag::u128); + trace_builder.mul(0, 1, 2, AvmMemoryTag::U128); trace_builder.return_op(2, 1); auto trace = trace_builder.finalize(); @@ -1312,7 +1312,7 @@ TEST_F(AvmMiniArithmeticTestsU128, multiplicationOverflow) FF(0), FF(1), FF(2), - AvmMemoryTag::u128); + AvmMemoryTag::U128); auto alu_row_first = trace.at(alu_row_index); EXPECT_EQ(alu_row_first.aluChip_alu_u128_tag, FF(1)); @@ -1377,21 +1377,21 @@ TEST_F(AvmMiniArithmeticTestsU128, multiplicationOverflow) // Test on basic incorrect addition over finite field type. TEST_F(AvmMiniArithmeticNegativeTestsFF, addition) { - auto trace = gen_mutated_trace_add(FF(37), FF(4), FF(40), AvmMemoryTag::ff); + 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) { - auto trace = gen_mutated_trace_sub(FF(17), FF(8), FF(-9), AvmMemoryTag::ff); + 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) { - auto trace = gen_mutated_trace_mul(FF(9), FF(100), FF(9000000), AvmMemoryTag::ff); + 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"); } @@ -1401,7 +1401,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionFF) trace_builder.call_data_copy(0, 2, 0, std::vector{ 15, 315 }); // Memory layout: [15,315,0,0,0,0,....] - trace_builder.div(1, 0, 2, AvmMemoryTag::ff); // [15,315,21,0,0,0....] + trace_builder.div(1, 0, 2, AvmMemoryTag::FF); // [15,315,21,0,0,0....] trace_builder.halt(); auto trace = trace_builder.finalize(); @@ -1418,7 +1418,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionNoZeroButError) trace_builder.call_data_copy(0, 2, 0, std::vector{ 15, 315 }); // Memory layout: [15,315,0,0,0,0,....] - trace_builder.div(1, 0, 2, AvmMemoryTag::ff); // [15,315,21,0,0,0....] + trace_builder.div(1, 0, 2, AvmMemoryTag::FF); // [15,315,21,0,0,0....] trace_builder.halt(); auto trace = trace_builder.finalize(); @@ -1444,7 +1444,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionByZeroNoError) trace_builder.call_data_copy(0, 1, 0, std::vector{ 15 }); // Memory layout: [15,0,0,0,0,0,....] - trace_builder.div(0, 1, 2, AvmMemoryTag::ff); // [15,0,0,0,0,0....] + trace_builder.div(0, 1, 2, AvmMemoryTag::FF); // [15,0,0,0,0,0....] trace_builder.halt(); auto trace = trace_builder.finalize(); @@ -1461,7 +1461,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionByZeroNoError) TEST_F(AvmMiniArithmeticNegativeTestsFF, divisionZeroByZeroNoError) { // Memory layout: [0,0,0,0,0,0,....] - trace_builder.div(0, 1, 2, AvmMemoryTag::ff); // [0,0,0,0,0,0....] + trace_builder.div(0, 1, 2, AvmMemoryTag::FF); // [0,0,0,0,0,0....] trace_builder.halt(); auto trace = trace_builder.finalize(); @@ -1481,7 +1481,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) trace_builder.call_data_copy(0, 3, 0, std::vector{ 37, 4, 11 }); // Memory layout: [37,4,11,0,0,0,....] - trace_builder.add(0, 1, 4, AvmMemoryTag::ff); // [37,4,11,0,41,0,....] + trace_builder.add(0, 1, 4, AvmMemoryTag::FF); // [37,4,11,0,41,0,....] trace_builder.return_op(0, 5); trace_builder.halt(); auto trace = trace_builder.finalize(); @@ -1499,7 +1499,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) trace_builder.call_data_copy(0, 3, 0, std::vector{ 8, 4, 17 }); // Memory layout: [8,4,17,0,0,0,....] - trace_builder.sub(2, 0, 1, AvmMemoryTag::ff); // [8,9,17,0,0,0....] + trace_builder.sub(2, 0, 1, AvmMemoryTag::FF); // [8,9,17,0,0,0....] trace_builder.return_op(0, 3); trace = trace_builder.finalize(); @@ -1516,7 +1516,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) trace_builder.call_data_copy(0, 3, 0, std::vector{ 5, 0, 20 }); // Memory layout: [5,0,20,0,0,0,....] - trace_builder.mul(2, 0, 1, AvmMemoryTag::ff); // [5,100,20,0,0,0....] + trace_builder.mul(2, 0, 1, AvmMemoryTag::FF); // [5,100,20,0,0,0....] trace_builder.return_op(0, 3); trace = trace_builder.finalize(); @@ -1536,21 +1536,21 @@ TEST_F(AvmMiniArithmeticNegativeTestsFF, operationWithErrorFlag) // Test on basic incorrect addition over U8. TEST_F(AvmMiniArithmeticNegativeTestsU8, addition) { - auto trace = gen_mutated_trace_add(FF(234), FF(22), FF(1), AvmMemoryTag::u8); + 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) { - auto trace = gen_mutated_trace_sub(FF(100), FF(104), FF(253), AvmMemoryTag::u8); + 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) { - auto trace = gen_mutated_trace_mul(FF(9), FF(100), FF(55), AvmMemoryTag::u8); + 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) { - auto trace = gen_mutated_trace_add(FF(8234), FF(7428), FF(653), AvmMemoryTag::u16); + 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) { - auto trace = gen_mutated_trace_sub(FF(100), FF(932), FF(25373), AvmMemoryTag::u16); + 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) { - auto trace = gen_mutated_trace_mul(FF(8096), FF(1024), FF(1), AvmMemoryTag::u16); + 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) { - auto trace = gen_mutated_trace_add(FF(1972382341), FF(1111133221), FF(1222222222), AvmMemoryTag::u32); + 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) { - auto trace = gen_mutated_trace_sub(FF(3999888777LLU), FF(UINT32_MAX), FF(2537332433LLU), AvmMemoryTag::u32); + 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) { - auto trace = gen_mutated_trace_mul(FF(UINT32_MAX), FF(UINT32_MAX), FF(0), AvmMemoryTag::u32); + 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"); } @@ -1612,7 +1612,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU32, multiplication) TEST_F(AvmMiniArithmeticNegativeTestsU64, addition) { auto trace = gen_mutated_trace_add( - FF(3324236423198282341LLU), FF(999999991111133221LLU), FF(1222222222236LLU), AvmMemoryTag::u64); + FF(3324236423198282341LLU), FF(999999991111133221LLU), FF(1222222222236LLU), AvmMemoryTag::U64); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } @@ -1620,7 +1620,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU64, addition) TEST_F(AvmMiniArithmeticNegativeTestsU64, subtraction) { auto trace = - gen_mutated_trace_sub(FF(399988877723434LLU), FF(UINT64_MAX), FF(25373324332342LLU), AvmMemoryTag::u64); + gen_mutated_trace_sub(FF(399988877723434LLU), FF(UINT64_MAX), FF(25373324332342LLU), AvmMemoryTag::U64); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } @@ -1628,7 +1628,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU64, subtraction) TEST_F(AvmMiniArithmeticNegativeTestsU64, multiplication) { auto trace = - gen_mutated_trace_mul(FF(399988877723434LLU), FF(9998887772343LLU), FF(9283674827534LLU), AvmMemoryTag::u64); + gen_mutated_trace_mul(FF(399988877723434LLU), FF(9998887772343LLU), FF(9283674827534LLU), AvmMemoryTag::U64); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MUL_COMMON_2"); } @@ -1646,7 +1646,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU128, addition) auto trace = gen_mutated_trace_add(FF{ uint256_t::from_uint128(a) }, FF{ uint256_t::from_uint128(b) }, FF{ uint256_t::from_uint128(c) }, - AvmMemoryTag::u128); + AvmMemoryTag::U128); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } @@ -1660,7 +1660,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU128, subtraction) auto trace = gen_mutated_trace_sub(FF{ uint256_t::from_uint128(a) }, FF{ uint256_t::from_uint128(b) }, FF{ uint256_t::from_uint128(c) }, - AvmMemoryTag::u128); + AvmMemoryTag::U128); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_ADD_SUB_2"); } @@ -1674,7 +1674,7 @@ TEST_F(AvmMiniArithmeticNegativeTestsU128, multiplication) auto trace = gen_mutated_trace_mul(FF{ uint256_t::from_uint128(a) }, FF{ uint256_t::from_uint128(b) }, FF{ uint256_t::from_uint128(c) }, - AvmMemoryTag::u128); + AvmMemoryTag::U128); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MULTIPLICATION_OUT_U128"); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp index 659dce13725..0f709e6ba20 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp @@ -35,7 +35,7 @@ TEST_F(AvmMiniMemoryTests, mismatchedTag) { trace_builder.call_data_copy(0, 2, 0, std::vector{ 98, 12 }); - trace_builder.add(0, 1, 4, AvmMemoryTag::u8); + trace_builder.add(0, 1, 4, AvmMemoryTag::U8); trace_builder.halt(); auto trace = trace_builder.finalize(); @@ -59,8 +59,8 @@ TEST_F(AvmMiniMemoryTests, mismatchedTag) 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->memTrace_m_in_tag, FF(static_cast(AvmMemoryTag::U8))); + EXPECT_EQ(row->memTrace_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) { @@ -70,8 +70,8 @@ TEST_F(AvmMiniMemoryTests, mismatchedTag) 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->memTrace_m_in_tag, FF(static_cast(AvmMemoryTag::U8))); + EXPECT_EQ(row->memTrace_m_tag, FF(static_cast(AvmMemoryTag::FF))); validate_trace_proof(std::move(trace)); } @@ -83,7 +83,7 @@ TEST_F(AvmMiniMemoryTests, mLastAccessViolation) trace_builder.call_data_copy(0, 2, 0, std::vector{ 4, 9 }); // Memory layout: [4,9,0,0,0,0,....] - trace_builder.sub(1, 0, 2, AvmMemoryTag::u8); // [4,9,5,0,0,0.....] + trace_builder.sub(1, 0, 2, AvmMemoryTag::U8); // [4,9,5,0,0,0.....] trace_builder.halt(); auto trace = trace_builder.finalize(); @@ -113,7 +113,7 @@ TEST_F(AvmMiniMemoryTests, readWriteConsistencyValViolation) trace_builder.call_data_copy(0, 2, 0, std::vector{ 4, 9 }); // Memory layout: [4,9,0,0,0,0,....] - trace_builder.mul(1, 0, 2, AvmMemoryTag::u8); // [4,9,36,0,0,0.....] + trace_builder.mul(1, 0, 2, AvmMemoryTag::U8); // [4,9,36,0,0,0.....] trace_builder.return_op(2, 1); // Return single memory word at position 2 (36) auto trace = trace_builder.finalize(); @@ -143,7 +143,7 @@ TEST_F(AvmMiniMemoryTests, readWriteConsistencyTagViolation) trace_builder.call_data_copy(0, 2, 0, std::vector{ 4, 9 }); // Memory layout: [4,9,0,0,0,0,....] - trace_builder.mul(1, 0, 2, AvmMemoryTag::u8); // [4,9,36,0,0,0.....] + trace_builder.mul(1, 0, 2, AvmMemoryTag::U8); // [4,9,36,0,0,0.....] trace_builder.return_op(2, 1); // Return single memory word at position 2 (36) auto trace = trace_builder.finalize(); @@ -161,7 +161,7 @@ TEST_F(AvmMiniMemoryTests, readWriteConsistencyTagViolation) EXPECT_TRUE(row != trace.end()); - row->memTrace_m_tag = static_cast(AvmMemoryTag::u16); + row->memTrace_m_tag = static_cast(AvmMemoryTag::U16); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "MEM_READ_WRITE_TAG_CONSISTENCY"); } @@ -183,7 +183,7 @@ TEST_F(AvmMiniMemoryTests, mismatchedTagErrorViolation) { trace_builder.call_data_copy(0, 2, 0, std::vector{ 98, 12 }); - trace_builder.sub(0, 1, 4, AvmMemoryTag::u8); + trace_builder.sub(0, 1, 4, AvmMemoryTag::U8); trace_builder.halt(); auto trace = trace_builder.finalize(); @@ -217,7 +217,7 @@ TEST_F(AvmMiniMemoryTests, consistentTagNoErrorViolation) { trace_builder.call_data_copy(0, 2, 0, std::vector{ 84, 7 }); - trace_builder.div(0, 1, 4, AvmMemoryTag::ff); + trace_builder.div(0, 1, 4, AvmMemoryTag::FF); trace_builder.halt(); auto trace = trace_builder.finalize();