diff --git a/barretenberg/cpp/pil/avm/avm_alu.pil b/barretenberg/cpp/pil/avm/avm_alu.pil index 89ca4c3b83c..2d4c91d8709 100644 --- a/barretenberg/cpp/pil/avm/avm_alu.pil +++ b/barretenberg/cpp/pil/avm/avm_alu.pil @@ -16,6 +16,7 @@ namespace avm_alu(256); pol commit alu_op_mul; pol commit alu_op_div; pol commit alu_op_not; + pol commit alu_op_eq; // Flattened boolean instruction tags pol commit alu_ff_tag; @@ -223,4 +224,31 @@ namespace avm_alu(256); #[ALU_OP_NOT] alu_op_not * (alu_ia + alu_ic - UINT_MAX) = 0; + // ========= EQUALITY Operation Constraints =============================== + // TODO: Note this method differs from the approach taken for "equality to zero" checks + // in handling the error tags found in avm_main and avm_mem files. The predicted relation difference + // is minor and when we optimise we will harmonise the methods based on actual performance. + + // Equality of two elements is found by performing an "equality to zero" check. + // This relies on the fact that the inverse of a field element exists for all elements except zero + // 1) Given two values x & y, find the difference z = x - y + // 2) If x & y are equal, z == 0 otherwise z != 0 + // 3) Field equality to zero can be done as follows + // a) z(e(x - w) + w) - 1 + e = 0; + // b) where w = z^-1 and e is a boolean value indicating if z == 0 + // c) if e == 0; zw = 1 && z has an inverse. If e == 1; z == 0 and we set w = 0; + + // Registers Ia and Ib hold the values that equality is to be tested on + pol DIFF = alu_ia - alu_ib; + + // Need an additional helper that holds the inverse of the difference; + pol commit alu_op_eq_diff_inv; + + // If EQ selector is set, ic needs to be boolean + #[ALU_RES_IS_BOOL] + alu_op_eq * (alu_ic * (1 - alu_ic)) = 0; + + #[ALU_OP_EQ] + alu_op_eq * (DIFF * (alu_ic * (1 - alu_op_eq_diff_inv) + alu_op_eq_diff_inv) - 1 + alu_ic) = 0; + diff --git a/barretenberg/cpp/pil/avm/avm_main.pil b/barretenberg/cpp/pil/avm/avm_main.pil index 8ad5256b0d5..473fe5b70fd 100644 --- a/barretenberg/cpp/pil/avm/avm_main.pil +++ b/barretenberg/cpp/pil/avm/avm_main.pil @@ -36,6 +36,8 @@ namespace avm_main(256); pol commit sel_op_div; // NOT pol commit sel_op_not; + // EQ + pol commit sel_op_eq; // Instruction memory tag (0: uninitialized, 1: u8, 2: u16, 3: u32, 4: u64, 5: u128, 6:field) pol commit in_tag; @@ -64,7 +66,7 @@ namespace avm_main(256); pol commit rwc; // Memory index involved into a memory operation per pertaining intermediate register - // We should range constrain it to 32 bits ultimately. For first mini-AVM, + // We should range constrain it to 32 bits ultimately. For first version of the AVM, // we will assume that these columns are of the right type. pol commit mem_idx_a; pol commit mem_idx_b; @@ -82,6 +84,7 @@ namespace avm_main(256); sel_op_mul * (1 - sel_op_mul) = 0; sel_op_div * (1 - sel_op_div) = 0; sel_op_not * (1 - sel_op_not) = 0; + sel_op_eq * (1 - sel_op_eq) = 0; sel_internal_call * (1 - sel_internal_call) = 0; sel_internal_return * (1 - sel_internal_return) = 0; @@ -175,7 +178,7 @@ namespace avm_main(256); //===== CONTROL_FLOW_CONSISTENCY ============================================ pol INTERNAL_CALL_STACK_SELECTORS = (first + sel_internal_call + sel_internal_return + sel_halt); - pol OPCODE_SELECTORS = (sel_op_add + sel_op_sub + sel_op_div + sel_op_mul + sel_op_not); + pol OPCODE_SELECTORS = (sel_op_add + sel_op_sub + sel_op_div + sel_op_mul + sel_op_not + sel_op_eq); // Program counter must increment if not jumping or returning #[PC_INCREMENT] diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp new file mode 100644 index 00000000000..9a45ec39ed6 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -0,0 +1,946 @@ + + +#pragma once +#include "../relation_definitions.hpp" +#include "barretenberg/commitment_schemes/kzg/kzg.hpp" +#include "barretenberg/ecc/curves/bn254/g1.hpp" +#include "barretenberg/polynomials/barycentric.hpp" +#include "barretenberg/polynomials/univariate.hpp" + +#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" + +#include "barretenberg/flavor/flavor.hpp" +#include "barretenberg/flavor/flavor_macros.hpp" +#include "barretenberg/polynomials/evaluation_domain.hpp" +#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/relations/generated/AvmMini/alu_chip.hpp" +#include "barretenberg/relations/generated/AvmMini/avm_mini.hpp" +#include "barretenberg/relations/generated/AvmMini/mem_trace.hpp" +#include "barretenberg/transcript/transcript.hpp" + +namespace bb { + +class AvmMiniFlavor { + public: + using Curve = curve::BN254; + using G1 = Curve::Group; + using PCS = KZG; + + using FF = G1::subgroup_field; + using Polynomial = bb::Polynomial; + using PolynomialHandle = std::span; + using GroupElement = G1::element; + using Commitment = G1::affine_element; + using CommitmentHandle = G1::affine_element; + using CommitmentKey = bb::CommitmentKey; + using VerifierCommitmentKey = bb::VerifierCommitmentKey; + using RelationSeparator = FF; + + static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; + static constexpr size_t NUM_WITNESS_ENTITIES = 69; + 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 = 85; + + 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(); + + // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` + // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation + // length = 3 + static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; + static constexpr size_t NUM_RELATIONS = std::tuple_size::value; + + template + using ProtogalaxyTupleOfTuplesOfUnivariates = + decltype(create_protogalaxy_tuple_of_tuples_of_univariates()); + using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates()); + using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); + + static constexpr bool has_zero_row = true; + + private: + template class PrecomputedEntities : public PrecomputedEntitiesBase { + public: + using DataType = DataType_; + + DEFINE_FLAVOR_MEMBERS(DataType, avmMini_clk, avmMini_first) + + RefVector get_selectors() { return { avmMini_clk, avmMini_first }; }; + RefVector get_sigma_polynomials() { return {}; }; + RefVector get_id_polynomials() { return {}; }; + RefVector get_table_polynomials() { return {}; }; + }; + + template class WitnessEntities { + public: + DEFINE_FLAVOR_MEMBERS(DataType, + memTrace_m_clk, + memTrace_m_sub_clk, + memTrace_m_addr, + memTrace_m_tag, + memTrace_m_val, + memTrace_m_lastAccess, + memTrace_m_last, + memTrace_m_rw, + memTrace_m_in_tag, + memTrace_m_tag_err, + memTrace_m_one_min_inv, + aluChip_alu_clk, + aluChip_alu_ia, + aluChip_alu_ib, + aluChip_alu_ic, + aluChip_alu_op_add, + aluChip_alu_op_sub, + aluChip_alu_op_mul, + aluChip_alu_op_div, + aluChip_alu_op_not, + aluChip_alu_op_eq, + aluChip_alu_ff_tag, + aluChip_alu_u8_tag, + aluChip_alu_u16_tag, + aluChip_alu_u32_tag, + aluChip_alu_u64_tag, + aluChip_alu_u128_tag, + aluChip_alu_u8_r0, + aluChip_alu_u8_r1, + aluChip_alu_u16_r0, + aluChip_alu_u16_r1, + aluChip_alu_u16_r2, + aluChip_alu_u16_r3, + aluChip_alu_u16_r4, + aluChip_alu_u16_r5, + aluChip_alu_u16_r6, + aluChip_alu_u16_r7, + aluChip_alu_u64_r0, + aluChip_alu_cf, + aluChip_alu_inv_diff, + avmMini_pc, + avmMini_internal_return_ptr, + avmMini_sel_internal_call, + avmMini_sel_internal_return, + avmMini_sel_jump, + avmMini_sel_halt, + avmMini_sel_op_add, + avmMini_sel_op_sub, + avmMini_sel_op_mul, + avmMini_sel_op_div, + avmMini_sel_op_not, + avmMini_sel_op_eq, + avmMini_in_tag, + avmMini_op_err, + avmMini_tag_err, + avmMini_inv, + avmMini_ia, + avmMini_ib, + avmMini_ic, + avmMini_mem_op_a, + avmMini_mem_op_b, + avmMini_mem_op_c, + avmMini_rwa, + avmMini_rwb, + avmMini_rwc, + avmMini_mem_idx_a, + avmMini_mem_idx_b, + avmMini_mem_idx_c, + avmMini_last) + + RefVector get_wires() + { + return { memTrace_m_clk, + memTrace_m_sub_clk, + memTrace_m_addr, + memTrace_m_tag, + memTrace_m_val, + memTrace_m_lastAccess, + memTrace_m_last, + memTrace_m_rw, + memTrace_m_in_tag, + memTrace_m_tag_err, + memTrace_m_one_min_inv, + aluChip_alu_clk, + aluChip_alu_ia, + aluChip_alu_ib, + aluChip_alu_ic, + aluChip_alu_op_add, + aluChip_alu_op_sub, + aluChip_alu_op_mul, + aluChip_alu_op_div, + aluChip_alu_op_not, + aluChip_alu_op_eq, + aluChip_alu_ff_tag, + aluChip_alu_u8_tag, + aluChip_alu_u16_tag, + aluChip_alu_u32_tag, + aluChip_alu_u64_tag, + aluChip_alu_u128_tag, + aluChip_alu_u8_r0, + aluChip_alu_u8_r1, + aluChip_alu_u16_r0, + aluChip_alu_u16_r1, + aluChip_alu_u16_r2, + aluChip_alu_u16_r3, + aluChip_alu_u16_r4, + aluChip_alu_u16_r5, + aluChip_alu_u16_r6, + aluChip_alu_u16_r7, + aluChip_alu_u64_r0, + aluChip_alu_cf, + aluChip_alu_inv_diff, + avmMini_pc, + avmMini_internal_return_ptr, + avmMini_sel_internal_call, + avmMini_sel_internal_return, + avmMini_sel_jump, + avmMini_sel_halt, + avmMini_sel_op_add, + avmMini_sel_op_sub, + avmMini_sel_op_mul, + avmMini_sel_op_div, + avmMini_sel_op_not, + avmMini_sel_op_eq, + avmMini_in_tag, + avmMini_op_err, + avmMini_tag_err, + avmMini_inv, + avmMini_ia, + avmMini_ib, + avmMini_ic, + avmMini_mem_op_a, + avmMini_mem_op_b, + avmMini_mem_op_c, + avmMini_rwa, + avmMini_rwb, + avmMini_rwc, + avmMini_mem_idx_a, + avmMini_mem_idx_b, + avmMini_mem_idx_c, + avmMini_last }; + }; + RefVector get_sorted_polynomials() { return {}; }; + }; + + template class AllEntities { + public: + DEFINE_FLAVOR_MEMBERS(DataType, + avmMini_clk, + avmMini_first, + memTrace_m_clk, + memTrace_m_sub_clk, + memTrace_m_addr, + memTrace_m_tag, + memTrace_m_val, + memTrace_m_lastAccess, + memTrace_m_last, + memTrace_m_rw, + memTrace_m_in_tag, + memTrace_m_tag_err, + memTrace_m_one_min_inv, + aluChip_alu_clk, + aluChip_alu_ia, + aluChip_alu_ib, + aluChip_alu_ic, + aluChip_alu_op_add, + aluChip_alu_op_sub, + aluChip_alu_op_mul, + aluChip_alu_op_div, + aluChip_alu_op_not, + aluChip_alu_op_eq, + aluChip_alu_ff_tag, + aluChip_alu_u8_tag, + aluChip_alu_u16_tag, + aluChip_alu_u32_tag, + aluChip_alu_u64_tag, + aluChip_alu_u128_tag, + aluChip_alu_u8_r0, + aluChip_alu_u8_r1, + aluChip_alu_u16_r0, + aluChip_alu_u16_r1, + aluChip_alu_u16_r2, + aluChip_alu_u16_r3, + aluChip_alu_u16_r4, + aluChip_alu_u16_r5, + aluChip_alu_u16_r6, + aluChip_alu_u16_r7, + aluChip_alu_u64_r0, + aluChip_alu_cf, + aluChip_alu_inv_diff, + avmMini_pc, + avmMini_internal_return_ptr, + avmMini_sel_internal_call, + avmMini_sel_internal_return, + avmMini_sel_jump, + avmMini_sel_halt, + avmMini_sel_op_add, + avmMini_sel_op_sub, + avmMini_sel_op_mul, + avmMini_sel_op_div, + avmMini_sel_op_not, + avmMini_sel_op_eq, + avmMini_in_tag, + avmMini_op_err, + avmMini_tag_err, + avmMini_inv, + avmMini_ia, + avmMini_ib, + avmMini_ic, + avmMini_mem_op_a, + avmMini_mem_op_b, + avmMini_mem_op_c, + avmMini_rwa, + avmMini_rwb, + avmMini_rwc, + avmMini_mem_idx_a, + avmMini_mem_idx_b, + avmMini_mem_idx_c, + avmMini_last, + 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_r3_shift, + aluChip_alu_u16_r4_shift, + avmMini_pc_shift, + avmMini_internal_return_ptr_shift, + memTrace_m_tag_shift, + memTrace_m_rw_shift, + memTrace_m_addr_shift, + memTrace_m_val_shift) + + RefVector get_wires() + { + return { avmMini_clk, + avmMini_first, + memTrace_m_clk, + memTrace_m_sub_clk, + memTrace_m_addr, + memTrace_m_tag, + memTrace_m_val, + memTrace_m_lastAccess, + memTrace_m_last, + memTrace_m_rw, + memTrace_m_in_tag, + memTrace_m_tag_err, + memTrace_m_one_min_inv, + aluChip_alu_clk, + aluChip_alu_ia, + aluChip_alu_ib, + aluChip_alu_ic, + aluChip_alu_op_add, + aluChip_alu_op_sub, + aluChip_alu_op_mul, + aluChip_alu_op_div, + aluChip_alu_op_not, + aluChip_alu_op_eq, + aluChip_alu_ff_tag, + aluChip_alu_u8_tag, + aluChip_alu_u16_tag, + aluChip_alu_u32_tag, + aluChip_alu_u64_tag, + aluChip_alu_u128_tag, + aluChip_alu_u8_r0, + aluChip_alu_u8_r1, + aluChip_alu_u16_r0, + aluChip_alu_u16_r1, + aluChip_alu_u16_r2, + aluChip_alu_u16_r3, + aluChip_alu_u16_r4, + aluChip_alu_u16_r5, + aluChip_alu_u16_r6, + aluChip_alu_u16_r7, + aluChip_alu_u64_r0, + aluChip_alu_cf, + aluChip_alu_inv_diff, + avmMini_pc, + avmMini_internal_return_ptr, + avmMini_sel_internal_call, + avmMini_sel_internal_return, + avmMini_sel_jump, + avmMini_sel_halt, + avmMini_sel_op_add, + avmMini_sel_op_sub, + avmMini_sel_op_mul, + avmMini_sel_op_div, + avmMini_sel_op_not, + avmMini_sel_op_eq, + avmMini_in_tag, + avmMini_op_err, + avmMini_tag_err, + avmMini_inv, + avmMini_ia, + avmMini_ib, + avmMini_ic, + avmMini_mem_op_a, + avmMini_mem_op_b, + avmMini_mem_op_c, + avmMini_rwa, + avmMini_rwb, + avmMini_rwc, + avmMini_mem_idx_a, + avmMini_mem_idx_b, + avmMini_mem_idx_c, + avmMini_last, + 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_r3_shift, + aluChip_alu_u16_r4_shift, + avmMini_pc_shift, + avmMini_internal_return_ptr_shift, + memTrace_m_tag_shift, + memTrace_m_rw_shift, + memTrace_m_addr_shift, + memTrace_m_val_shift }; + }; + RefVector get_unshifted() + { + return { avmMini_clk, + avmMini_first, + memTrace_m_clk, + memTrace_m_sub_clk, + memTrace_m_addr, + memTrace_m_tag, + memTrace_m_val, + memTrace_m_lastAccess, + memTrace_m_last, + memTrace_m_rw, + memTrace_m_in_tag, + memTrace_m_tag_err, + memTrace_m_one_min_inv, + aluChip_alu_clk, + aluChip_alu_ia, + aluChip_alu_ib, + aluChip_alu_ic, + aluChip_alu_op_add, + aluChip_alu_op_sub, + aluChip_alu_op_mul, + aluChip_alu_op_div, + aluChip_alu_op_not, + aluChip_alu_op_eq, + aluChip_alu_ff_tag, + aluChip_alu_u8_tag, + aluChip_alu_u16_tag, + aluChip_alu_u32_tag, + aluChip_alu_u64_tag, + aluChip_alu_u128_tag, + aluChip_alu_u8_r0, + aluChip_alu_u8_r1, + aluChip_alu_u16_r0, + aluChip_alu_u16_r1, + aluChip_alu_u16_r2, + aluChip_alu_u16_r3, + aluChip_alu_u16_r4, + aluChip_alu_u16_r5, + aluChip_alu_u16_r6, + aluChip_alu_u16_r7, + aluChip_alu_u64_r0, + aluChip_alu_cf, + aluChip_alu_inv_diff, + avmMini_pc, + avmMini_internal_return_ptr, + avmMini_sel_internal_call, + avmMini_sel_internal_return, + avmMini_sel_jump, + avmMini_sel_halt, + avmMini_sel_op_add, + avmMini_sel_op_sub, + avmMini_sel_op_mul, + avmMini_sel_op_div, + avmMini_sel_op_not, + avmMini_sel_op_eq, + avmMini_in_tag, + avmMini_op_err, + avmMini_tag_err, + avmMini_inv, + avmMini_ia, + avmMini_ib, + avmMini_ic, + avmMini_mem_op_a, + avmMini_mem_op_b, + avmMini_mem_op_c, + avmMini_rwa, + avmMini_rwb, + avmMini_rwc, + avmMini_mem_idx_a, + avmMini_mem_idx_b, + avmMini_mem_idx_c, + avmMini_last }; + }; + RefVector get_to_be_shifted() + { + return { 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_r3, aluChip_alu_u16_r4, + avmMini_pc, avmMini_internal_return_ptr, + memTrace_m_tag, memTrace_m_rw, + memTrace_m_addr, memTrace_m_val }; + }; + RefVector get_shifted() + { + return { 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_r3_shift, aluChip_alu_u16_r4_shift, + avmMini_pc_shift, avmMini_internal_return_ptr_shift, + memTrace_m_tag_shift, memTrace_m_rw_shift, + memTrace_m_addr_shift, memTrace_m_val_shift }; + }; + }; + + public: + class ProvingKey : public ProvingKey_, WitnessEntities> { + public: + // Expose constructors on the base class + using Base = ProvingKey_, WitnessEntities>; + using Base::Base; + + RefVector get_to_be_shifted() + { + return { 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_r3, aluChip_alu_u16_r4, + avmMini_pc, avmMini_internal_return_ptr, + memTrace_m_tag, memTrace_m_rw, + memTrace_m_addr, memTrace_m_val }; + }; + + // The plookup wires that store plookup read data. + std::array get_table_column_wires() { return {}; }; + }; + + using VerificationKey = VerificationKey_>; + + using FoldedPolynomials = AllEntities>; + + class AllValues : public AllEntities { + public: + using Base = AllEntities; + using Base::Base; + }; + + /** + * @brief A container for the prover polynomials handles. + */ + class ProverPolynomials : public AllEntities { + public: + // Define all operations as default, except move construction/assignment + ProverPolynomials() = default; + ProverPolynomials& operator=(const ProverPolynomials&) = delete; + ProverPolynomials(const ProverPolynomials& o) = delete; + ProverPolynomials(ProverPolynomials&& o) noexcept = default; + ProverPolynomials& operator=(ProverPolynomials&& o) noexcept = default; + ~ProverPolynomials() = default; + [[nodiscard]] size_t get_polynomial_size() const { return memTrace_m_clk.size(); } + /** + * @brief Returns the evaluations of all prover polynomials at one point on the boolean hypercube, which + * represents one row in the execution trace. + */ + [[nodiscard]] AllValues get_row(size_t row_idx) const + { + AllValues result; + for (auto [result_field, polynomial] : zip_view(result.get_all(), this->get_all())) { + result_field = polynomial[row_idx]; + } + return result; + } + }; + + using RowPolynomials = AllEntities; + + class PartiallyEvaluatedMultivariates : public AllEntities { + public: + PartiallyEvaluatedMultivariates() = default; + PartiallyEvaluatedMultivariates(const size_t circuit_size) + { + // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2) + for (auto& poly : get_all()) { + poly = Polynomial(circuit_size / 2); + } + } + }; + + /** + * @brief A container for univariates used during Protogalaxy folding and sumcheck. + * @details During folding and sumcheck, the prover evaluates the relations on these univariates. + */ + template using ProverUnivariates = AllEntities>; + + /** + * @brief A container for univariates produced during the hot loop in sumcheck. + */ + using ExtendedEdges = ProverUnivariates; + + class CommitmentLabels : public AllEntities { + private: + using Base = AllEntities; + + public: + CommitmentLabels() + : AllEntities() + { + Base::avmMini_clk = "AVMMINI_CLK"; + Base::avmMini_first = "AVMMINI_FIRST"; + Base::memTrace_m_clk = "MEMTRACE_M_CLK"; + Base::memTrace_m_sub_clk = "MEMTRACE_M_SUB_CLK"; + Base::memTrace_m_addr = "MEMTRACE_M_ADDR"; + Base::memTrace_m_tag = "MEMTRACE_M_TAG"; + Base::memTrace_m_val = "MEMTRACE_M_VAL"; + Base::memTrace_m_lastAccess = "MEMTRACE_M_LASTACCESS"; + Base::memTrace_m_last = "MEMTRACE_M_LAST"; + Base::memTrace_m_rw = "MEMTRACE_M_RW"; + Base::memTrace_m_in_tag = "MEMTRACE_M_IN_TAG"; + Base::memTrace_m_tag_err = "MEMTRACE_M_TAG_ERR"; + Base::memTrace_m_one_min_inv = "MEMTRACE_M_ONE_MIN_INV"; + Base::aluChip_alu_clk = "ALUCHIP_ALU_CLK"; + Base::aluChip_alu_ia = "ALUCHIP_ALU_IA"; + Base::aluChip_alu_ib = "ALUCHIP_ALU_IB"; + Base::aluChip_alu_ic = "ALUCHIP_ALU_IC"; + Base::aluChip_alu_op_add = "ALUCHIP_ALU_OP_ADD"; + Base::aluChip_alu_op_sub = "ALUCHIP_ALU_OP_SUB"; + Base::aluChip_alu_op_mul = "ALUCHIP_ALU_OP_MUL"; + Base::aluChip_alu_op_div = "ALUCHIP_ALU_OP_DIV"; + Base::aluChip_alu_op_not = "ALUCHIP_ALU_OP_NOT"; + Base::aluChip_alu_op_eq = "ALUCHIP_ALU_OP_EQ"; + Base::aluChip_alu_ff_tag = "ALUCHIP_ALU_FF_TAG"; + Base::aluChip_alu_u8_tag = "ALUCHIP_ALU_U8_TAG"; + Base::aluChip_alu_u16_tag = "ALUCHIP_ALU_U16_TAG"; + Base::aluChip_alu_u32_tag = "ALUCHIP_ALU_U32_TAG"; + Base::aluChip_alu_u64_tag = "ALUCHIP_ALU_U64_TAG"; + Base::aluChip_alu_u128_tag = "ALUCHIP_ALU_U128_TAG"; + Base::aluChip_alu_u8_r0 = "ALUCHIP_ALU_U8_R0"; + Base::aluChip_alu_u8_r1 = "ALUCHIP_ALU_U8_R1"; + Base::aluChip_alu_u16_r0 = "ALUCHIP_ALU_U16_R0"; + Base::aluChip_alu_u16_r1 = "ALUCHIP_ALU_U16_R1"; + Base::aluChip_alu_u16_r2 = "ALUCHIP_ALU_U16_R2"; + Base::aluChip_alu_u16_r3 = "ALUCHIP_ALU_U16_R3"; + Base::aluChip_alu_u16_r4 = "ALUCHIP_ALU_U16_R4"; + Base::aluChip_alu_u16_r5 = "ALUCHIP_ALU_U16_R5"; + Base::aluChip_alu_u16_r6 = "ALUCHIP_ALU_U16_R6"; + Base::aluChip_alu_u16_r7 = "ALUCHIP_ALU_U16_R7"; + Base::aluChip_alu_u64_r0 = "ALUCHIP_ALU_U64_R0"; + Base::aluChip_alu_cf = "ALUCHIP_ALU_CF"; + Base::aluChip_alu_inv_diff = "ALUCHIP_ALU_INV_DIFF"; + Base::avmMini_pc = "AVMMINI_PC"; + Base::avmMini_internal_return_ptr = "AVMMINI_INTERNAL_RETURN_PTR"; + Base::avmMini_sel_internal_call = "AVMMINI_SEL_INTERNAL_CALL"; + Base::avmMini_sel_internal_return = "AVMMINI_SEL_INTERNAL_RETURN"; + Base::avmMini_sel_jump = "AVMMINI_SEL_JUMP"; + Base::avmMini_sel_halt = "AVMMINI_SEL_HALT"; + Base::avmMini_sel_op_add = "AVMMINI_SEL_OP_ADD"; + Base::avmMini_sel_op_sub = "AVMMINI_SEL_OP_SUB"; + Base::avmMini_sel_op_mul = "AVMMINI_SEL_OP_MUL"; + Base::avmMini_sel_op_div = "AVMMINI_SEL_OP_DIV"; + Base::avmMini_sel_op_not = "AVMMINI_SEL_OP_NOT"; + Base::avmMini_sel_op_eq = "AVMMINI_SEL_OP_EQ"; + Base::avmMini_in_tag = "AVMMINI_IN_TAG"; + Base::avmMini_op_err = "AVMMINI_OP_ERR"; + Base::avmMini_tag_err = "AVMMINI_TAG_ERR"; + Base::avmMini_inv = "AVMMINI_INV"; + Base::avmMini_ia = "AVMMINI_IA"; + Base::avmMini_ib = "AVMMINI_IB"; + Base::avmMini_ic = "AVMMINI_IC"; + Base::avmMini_mem_op_a = "AVMMINI_MEM_OP_A"; + Base::avmMini_mem_op_b = "AVMMINI_MEM_OP_B"; + Base::avmMini_mem_op_c = "AVMMINI_MEM_OP_C"; + Base::avmMini_rwa = "AVMMINI_RWA"; + Base::avmMini_rwb = "AVMMINI_RWB"; + Base::avmMini_rwc = "AVMMINI_RWC"; + Base::avmMini_mem_idx_a = "AVMMINI_MEM_IDX_A"; + Base::avmMini_mem_idx_b = "AVMMINI_MEM_IDX_B"; + Base::avmMini_mem_idx_c = "AVMMINI_MEM_IDX_C"; + Base::avmMini_last = "AVMMINI_LAST"; + }; + }; + + class VerifierCommitments : public AllEntities { + private: + using Base = AllEntities; + + public: + VerifierCommitments(const std::shared_ptr& verification_key) + { + avmMini_clk = verification_key->avmMini_clk; + avmMini_first = verification_key->avmMini_first; + } + }; + + class Transcript : public NativeTranscript { + public: + uint32_t circuit_size; + + Commitment memTrace_m_clk; + Commitment memTrace_m_sub_clk; + Commitment memTrace_m_addr; + Commitment memTrace_m_tag; + Commitment memTrace_m_val; + Commitment memTrace_m_lastAccess; + Commitment memTrace_m_last; + Commitment memTrace_m_rw; + Commitment memTrace_m_in_tag; + Commitment memTrace_m_tag_err; + Commitment memTrace_m_one_min_inv; + Commitment aluChip_alu_clk; + Commitment aluChip_alu_ia; + Commitment aluChip_alu_ib; + Commitment aluChip_alu_ic; + Commitment aluChip_alu_op_add; + Commitment aluChip_alu_op_sub; + Commitment aluChip_alu_op_mul; + Commitment aluChip_alu_op_div; + Commitment aluChip_alu_op_not; + Commitment aluChip_alu_op_eq; + Commitment aluChip_alu_ff_tag; + Commitment aluChip_alu_u8_tag; + Commitment aluChip_alu_u16_tag; + Commitment aluChip_alu_u32_tag; + Commitment aluChip_alu_u64_tag; + Commitment aluChip_alu_u128_tag; + Commitment aluChip_alu_u8_r0; + Commitment aluChip_alu_u8_r1; + Commitment aluChip_alu_u16_r0; + Commitment aluChip_alu_u16_r1; + Commitment aluChip_alu_u16_r2; + Commitment aluChip_alu_u16_r3; + Commitment aluChip_alu_u16_r4; + Commitment aluChip_alu_u16_r5; + Commitment aluChip_alu_u16_r6; + Commitment aluChip_alu_u16_r7; + Commitment aluChip_alu_u64_r0; + Commitment aluChip_alu_cf; + Commitment aluChip_alu_inv_diff; + Commitment avmMini_pc; + Commitment avmMini_internal_return_ptr; + Commitment avmMini_sel_internal_call; + Commitment avmMini_sel_internal_return; + Commitment avmMini_sel_jump; + Commitment avmMini_sel_halt; + Commitment avmMini_sel_op_add; + Commitment avmMini_sel_op_sub; + Commitment avmMini_sel_op_mul; + Commitment avmMini_sel_op_div; + Commitment avmMini_sel_op_not; + Commitment avmMini_sel_op_eq; + Commitment avmMini_in_tag; + Commitment avmMini_op_err; + Commitment avmMini_tag_err; + Commitment avmMini_inv; + Commitment avmMini_ia; + Commitment avmMini_ib; + Commitment avmMini_ic; + Commitment avmMini_mem_op_a; + Commitment avmMini_mem_op_b; + Commitment avmMini_mem_op_c; + Commitment avmMini_rwa; + Commitment avmMini_rwb; + Commitment avmMini_rwc; + Commitment avmMini_mem_idx_a; + Commitment avmMini_mem_idx_b; + Commitment avmMini_mem_idx_c; + Commitment avmMini_last; + + std::vector> sumcheck_univariates; + std::array sumcheck_evaluations; + std::vector zm_cq_comms; + Commitment zm_cq_comm; + Commitment zm_pi_comm; + + Transcript() = default; + + Transcript(const std::vector& proof) + : NativeTranscript(proof) + {} + + void deserialize_full_transcript() + { + size_t num_frs_read = 0; + circuit_size = deserialize_from_buffer(proof_data, num_frs_read); + size_t log_n = numeric::get_msb(circuit_size); + + memTrace_m_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + memTrace_m_sub_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + memTrace_m_addr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + memTrace_m_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + memTrace_m_val = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + memTrace_m_lastAccess = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + memTrace_m_last = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + memTrace_m_rw = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + memTrace_m_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + memTrace_m_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + memTrace_m_one_min_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_ia = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_ib = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_op_add = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_op_sub = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_op_not = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_op_eq = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_ff_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u8_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u16_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u32_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u64_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u128_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u8_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u8_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u16_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u16_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u16_r2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u16_r3 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u16_r4 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u16_r5 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u16_r6 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u16_r7 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_u64_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_cf = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + aluChip_alu_inv_diff = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_pc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_internal_return_ptr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_sel_internal_call = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_sel_internal_return = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_sel_jump = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_sel_halt = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_sel_op_add = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_sel_op_sub = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_sel_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_sel_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_sel_op_not = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_sel_op_eq = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_op_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_ia = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_ib = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_mem_op_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_mem_op_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_mem_op_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_rwa = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_rwb = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_rwc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_mem_idx_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_mem_idx_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_mem_idx_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avmMini_last = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + + for (size_t i = 0; i < log_n; ++i) { + sumcheck_univariates.emplace_back( + deserialize_from_buffer>(Transcript::proof_data, + num_frs_read)); + } + sumcheck_evaluations = + deserialize_from_buffer>(Transcript::proof_data, num_frs_read); + for (size_t i = 0; i < log_n; ++i) { + zm_cq_comms.push_back(deserialize_from_buffer(proof_data, num_frs_read)); + } + zm_cq_comm = deserialize_from_buffer(proof_data, num_frs_read); + zm_pi_comm = deserialize_from_buffer(proof_data, num_frs_read); + } + + void serialize_full_transcript() + { + size_t old_proof_length = proof_data.size(); + Transcript::proof_data.clear(); + size_t log_n = numeric::get_msb(circuit_size); + + serialize_to_buffer(circuit_size, Transcript::proof_data); + + serialize_to_buffer(memTrace_m_clk, Transcript::proof_data); + serialize_to_buffer(memTrace_m_sub_clk, Transcript::proof_data); + serialize_to_buffer(memTrace_m_addr, Transcript::proof_data); + serialize_to_buffer(memTrace_m_tag, Transcript::proof_data); + serialize_to_buffer(memTrace_m_val, Transcript::proof_data); + serialize_to_buffer(memTrace_m_lastAccess, Transcript::proof_data); + serialize_to_buffer(memTrace_m_last, Transcript::proof_data); + serialize_to_buffer(memTrace_m_rw, Transcript::proof_data); + serialize_to_buffer(memTrace_m_in_tag, Transcript::proof_data); + serialize_to_buffer(memTrace_m_tag_err, Transcript::proof_data); + serialize_to_buffer(memTrace_m_one_min_inv, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_clk, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_ia, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_ib, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_ic, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_op_add, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_op_sub, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_op_mul, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_op_div, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_op_not, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_op_eq, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_ff_tag, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u8_tag, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u16_tag, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u32_tag, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u64_tag, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u128_tag, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u8_r0, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u8_r1, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u16_r0, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u16_r1, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u16_r2, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u16_r3, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u16_r4, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u16_r5, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u16_r6, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u16_r7, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_u64_r0, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_cf, Transcript::proof_data); + serialize_to_buffer(aluChip_alu_inv_diff, Transcript::proof_data); + serialize_to_buffer(avmMini_pc, Transcript::proof_data); + serialize_to_buffer(avmMini_internal_return_ptr, Transcript::proof_data); + serialize_to_buffer(avmMini_sel_internal_call, Transcript::proof_data); + serialize_to_buffer(avmMini_sel_internal_return, Transcript::proof_data); + serialize_to_buffer(avmMini_sel_jump, Transcript::proof_data); + serialize_to_buffer(avmMini_sel_halt, Transcript::proof_data); + serialize_to_buffer(avmMini_sel_op_add, Transcript::proof_data); + serialize_to_buffer(avmMini_sel_op_sub, Transcript::proof_data); + serialize_to_buffer(avmMini_sel_op_mul, Transcript::proof_data); + serialize_to_buffer(avmMini_sel_op_div, Transcript::proof_data); + serialize_to_buffer(avmMini_sel_op_not, Transcript::proof_data); + serialize_to_buffer(avmMini_sel_op_eq, Transcript::proof_data); + serialize_to_buffer(avmMini_in_tag, Transcript::proof_data); + serialize_to_buffer(avmMini_op_err, Transcript::proof_data); + serialize_to_buffer(avmMini_tag_err, Transcript::proof_data); + serialize_to_buffer(avmMini_inv, Transcript::proof_data); + serialize_to_buffer(avmMini_ia, Transcript::proof_data); + serialize_to_buffer(avmMini_ib, Transcript::proof_data); + serialize_to_buffer(avmMini_ic, Transcript::proof_data); + serialize_to_buffer(avmMini_mem_op_a, Transcript::proof_data); + serialize_to_buffer(avmMini_mem_op_b, Transcript::proof_data); + serialize_to_buffer(avmMini_mem_op_c, Transcript::proof_data); + serialize_to_buffer(avmMini_rwa, Transcript::proof_data); + serialize_to_buffer(avmMini_rwb, Transcript::proof_data); + serialize_to_buffer(avmMini_rwc, Transcript::proof_data); + serialize_to_buffer(avmMini_mem_idx_a, Transcript::proof_data); + serialize_to_buffer(avmMini_mem_idx_b, Transcript::proof_data); + serialize_to_buffer(avmMini_mem_idx_c, Transcript::proof_data); + serialize_to_buffer(avmMini_last, Transcript::proof_data); + + for (size_t i = 0; i < log_n; ++i) { + serialize_to_buffer(sumcheck_univariates[i], Transcript::proof_data); + } + serialize_to_buffer(sumcheck_evaluations, Transcript::proof_data); + for (size_t i = 0; i < log_n; ++i) { + serialize_to_buffer(zm_cq_comms[i], proof_data); + } + serialize_to_buffer(zm_cq_comm, proof_data); + serialize_to_buffer(zm_pi_comm, proof_data); + + // sanity check to make sure we generate the same length of proof as before. + ASSERT(proof_data.size() == old_proof_length); + } + }; +}; + +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp index 65d42b3903d..a43887cd19d 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp @@ -37,13 +37,13 @@ class AvmFlavor { using RelationSeparator = FF; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; - static constexpr size_t NUM_WITNESS_ENTITIES = 66; + static constexpr size_t NUM_WITNESS_ENTITIES = 69; static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES; // We have two copies of the witness entities, so we subtract the number of fixed ones (they have no shift), one for // the unshifted and one for the shifted - static constexpr size_t NUM_ALL_ENTITIES = 82; + static constexpr size_t NUM_ALL_ENTITIES = 85; - using Relations = std::tuple, Avm_vm::avm_mem, Avm_vm::avm_alu>; + using Relations = std::tuple, Avm_vm::avm_main, Avm_vm::avm_alu>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -97,6 +97,7 @@ class AvmFlavor { avm_alu_alu_op_mul, avm_alu_alu_op_div, avm_alu_alu_op_not, + avm_alu_alu_op_eq, avm_alu_alu_ff_tag, avm_alu_alu_u8_tag, avm_alu_alu_u16_tag, @@ -115,6 +116,7 @@ class AvmFlavor { avm_alu_alu_u16_r7, avm_alu_alu_u64_r0, avm_alu_alu_cf, + avm_alu_alu_op_eq_diff_inv, avm_main_pc, avm_main_internal_return_ptr, avm_main_sel_internal_call, @@ -126,6 +128,7 @@ class AvmFlavor { avm_main_sel_op_mul, avm_main_sel_op_div, avm_main_sel_op_not, + avm_main_sel_op_eq, avm_main_in_tag, avm_main_op_err, avm_main_tag_err, @@ -166,6 +169,7 @@ class AvmFlavor { avm_alu_alu_op_mul, avm_alu_alu_op_div, avm_alu_alu_op_not, + avm_alu_alu_op_eq, avm_alu_alu_ff_tag, avm_alu_alu_u8_tag, avm_alu_alu_u16_tag, @@ -184,6 +188,7 @@ class AvmFlavor { avm_alu_alu_u16_r7, avm_alu_alu_u64_r0, avm_alu_alu_cf, + avm_alu_alu_op_eq_diff_inv, avm_main_pc, avm_main_internal_return_ptr, avm_main_sel_internal_call, @@ -195,6 +200,7 @@ class AvmFlavor { avm_main_sel_op_mul, avm_main_sel_op_div, avm_main_sel_op_not, + avm_main_sel_op_eq, avm_main_in_tag, avm_main_op_err, avm_main_tag_err, @@ -241,6 +247,7 @@ class AvmFlavor { avm_alu_alu_op_mul, avm_alu_alu_op_div, avm_alu_alu_op_not, + avm_alu_alu_op_eq, avm_alu_alu_ff_tag, avm_alu_alu_u8_tag, avm_alu_alu_u16_tag, @@ -259,6 +266,7 @@ class AvmFlavor { avm_alu_alu_u16_r7, avm_alu_alu_u64_r0, avm_alu_alu_cf, + avm_alu_alu_op_eq_diff_inv, avm_main_pc, avm_main_internal_return_ptr, avm_main_sel_internal_call, @@ -270,6 +278,7 @@ class AvmFlavor { avm_main_sel_op_mul, avm_main_sel_op_div, avm_main_sel_op_not, + avm_main_sel_op_eq, avm_main_in_tag, avm_main_op_err, avm_main_tag_err, @@ -287,20 +296,20 @@ class AvmFlavor { avm_main_mem_idx_b, avm_main_mem_idx_c, avm_main_last, - avm_main_pc_shift, - avm_main_internal_return_ptr_shift, avm_mem_m_rw_shift, - avm_mem_m_addr_shift, - avm_mem_m_val_shift, avm_mem_m_tag_shift, + avm_mem_m_val_shift, + avm_mem_m_addr_shift, + avm_main_internal_return_ptr_shift, + avm_main_pc_shift, avm_alu_alu_u16_r6_shift, - avm_alu_alu_u16_r4_shift, - avm_alu_alu_u16_r1_shift, + avm_alu_alu_u16_r0_shift, avm_alu_alu_u16_r2_shift, avm_alu_alu_u16_r7_shift, - avm_alu_alu_u16_r0_shift, avm_alu_alu_u16_r3_shift, - avm_alu_alu_u16_r5_shift) + avm_alu_alu_u16_r1_shift, + avm_alu_alu_u16_r5_shift, + avm_alu_alu_u16_r4_shift) RefVector get_wires() { @@ -326,6 +335,7 @@ class AvmFlavor { avm_alu_alu_op_mul, avm_alu_alu_op_div, avm_alu_alu_op_not, + avm_alu_alu_op_eq, avm_alu_alu_ff_tag, avm_alu_alu_u8_tag, avm_alu_alu_u16_tag, @@ -344,6 +354,7 @@ class AvmFlavor { avm_alu_alu_u16_r7, avm_alu_alu_u64_r0, avm_alu_alu_cf, + avm_alu_alu_op_eq_diff_inv, avm_main_pc, avm_main_internal_return_ptr, avm_main_sel_internal_call, @@ -355,6 +366,7 @@ class AvmFlavor { avm_main_sel_op_mul, avm_main_sel_op_div, avm_main_sel_op_not, + avm_main_sel_op_eq, avm_main_in_tag, avm_main_op_err, avm_main_tag_err, @@ -372,20 +384,20 @@ class AvmFlavor { avm_main_mem_idx_b, avm_main_mem_idx_c, avm_main_last, - avm_main_pc_shift, - avm_main_internal_return_ptr_shift, avm_mem_m_rw_shift, - avm_mem_m_addr_shift, - avm_mem_m_val_shift, avm_mem_m_tag_shift, + avm_mem_m_val_shift, + avm_mem_m_addr_shift, + avm_main_internal_return_ptr_shift, + avm_main_pc_shift, avm_alu_alu_u16_r6_shift, - avm_alu_alu_u16_r4_shift, - avm_alu_alu_u16_r1_shift, + avm_alu_alu_u16_r0_shift, avm_alu_alu_u16_r2_shift, avm_alu_alu_u16_r7_shift, - avm_alu_alu_u16_r0_shift, avm_alu_alu_u16_r3_shift, - avm_alu_alu_u16_r5_shift }; + avm_alu_alu_u16_r1_shift, + avm_alu_alu_u16_r5_shift, + avm_alu_alu_u16_r4_shift }; }; RefVector get_unshifted() { @@ -411,6 +423,7 @@ class AvmFlavor { avm_alu_alu_op_mul, avm_alu_alu_op_div, avm_alu_alu_op_not, + avm_alu_alu_op_eq, avm_alu_alu_ff_tag, avm_alu_alu_u8_tag, avm_alu_alu_u16_tag, @@ -429,6 +442,7 @@ class AvmFlavor { avm_alu_alu_u16_r7, avm_alu_alu_u64_r0, avm_alu_alu_cf, + avm_alu_alu_op_eq_diff_inv, avm_main_pc, avm_main_internal_return_ptr, avm_main_sel_internal_call, @@ -440,6 +454,7 @@ class AvmFlavor { avm_main_sel_op_mul, avm_main_sel_op_div, avm_main_sel_op_not, + avm_main_sel_op_eq, avm_main_in_tag, avm_main_op_err, avm_main_tag_err, @@ -460,23 +475,37 @@ class AvmFlavor { }; RefVector get_to_be_shifted() { - return { avm_main_pc, avm_main_internal_return_ptr, - avm_mem_m_rw, avm_mem_m_addr, - avm_mem_m_val, avm_mem_m_tag, - avm_alu_alu_u16_r6, avm_alu_alu_u16_r4, - avm_alu_alu_u16_r1, avm_alu_alu_u16_r2, - avm_alu_alu_u16_r7, avm_alu_alu_u16_r0, - avm_alu_alu_u16_r3, avm_alu_alu_u16_r5 }; + return { avm_mem_m_rw, + avm_mem_m_tag, + avm_mem_m_val, + avm_mem_m_addr, + avm_main_internal_return_ptr, + avm_main_pc, + avm_alu_alu_u16_r6, + avm_alu_alu_u16_r0, + avm_alu_alu_u16_r2, + avm_alu_alu_u16_r7, + avm_alu_alu_u16_r3, + avm_alu_alu_u16_r1, + avm_alu_alu_u16_r5, + avm_alu_alu_u16_r4 }; }; RefVector get_shifted() { - return { avm_main_pc_shift, avm_main_internal_return_ptr_shift, - avm_mem_m_rw_shift, avm_mem_m_addr_shift, - avm_mem_m_val_shift, avm_mem_m_tag_shift, - avm_alu_alu_u16_r6_shift, avm_alu_alu_u16_r4_shift, - avm_alu_alu_u16_r1_shift, avm_alu_alu_u16_r2_shift, - avm_alu_alu_u16_r7_shift, avm_alu_alu_u16_r0_shift, - avm_alu_alu_u16_r3_shift, avm_alu_alu_u16_r5_shift }; + return { avm_mem_m_rw_shift, + avm_mem_m_tag_shift, + avm_mem_m_val_shift, + avm_mem_m_addr_shift, + avm_main_internal_return_ptr_shift, + avm_main_pc_shift, + avm_alu_alu_u16_r6_shift, + avm_alu_alu_u16_r0_shift, + avm_alu_alu_u16_r2_shift, + avm_alu_alu_u16_r7_shift, + avm_alu_alu_u16_r3_shift, + avm_alu_alu_u16_r1_shift, + avm_alu_alu_u16_r5_shift, + avm_alu_alu_u16_r4_shift }; }; }; @@ -489,13 +518,20 @@ class AvmFlavor { RefVector get_to_be_shifted() { - return { avm_main_pc, avm_main_internal_return_ptr, - avm_mem_m_rw, avm_mem_m_addr, - avm_mem_m_val, avm_mem_m_tag, - avm_alu_alu_u16_r6, avm_alu_alu_u16_r4, - avm_alu_alu_u16_r1, avm_alu_alu_u16_r2, - avm_alu_alu_u16_r7, avm_alu_alu_u16_r0, - avm_alu_alu_u16_r3, avm_alu_alu_u16_r5 }; + return { avm_mem_m_rw, + avm_mem_m_tag, + avm_mem_m_val, + avm_mem_m_addr, + avm_main_internal_return_ptr, + avm_main_pc, + avm_alu_alu_u16_r6, + avm_alu_alu_u16_r0, + avm_alu_alu_u16_r2, + avm_alu_alu_u16_r7, + avm_alu_alu_u16_r3, + avm_alu_alu_u16_r1, + avm_alu_alu_u16_r5, + avm_alu_alu_u16_r4 }; }; // The plookup wires that store plookup read data. @@ -594,6 +630,7 @@ class AvmFlavor { Base::avm_alu_alu_op_mul = "AVM_ALU_ALU_OP_MUL"; Base::avm_alu_alu_op_div = "AVM_ALU_ALU_OP_DIV"; Base::avm_alu_alu_op_not = "AVM_ALU_ALU_OP_NOT"; + Base::avm_alu_alu_op_eq = "AVM_ALU_ALU_OP_EQ"; Base::avm_alu_alu_ff_tag = "AVM_ALU_ALU_FF_TAG"; Base::avm_alu_alu_u8_tag = "AVM_ALU_ALU_U8_TAG"; Base::avm_alu_alu_u16_tag = "AVM_ALU_ALU_U16_TAG"; @@ -612,6 +649,7 @@ class AvmFlavor { Base::avm_alu_alu_u16_r7 = "AVM_ALU_ALU_U16_R7"; Base::avm_alu_alu_u64_r0 = "AVM_ALU_ALU_U64_R0"; Base::avm_alu_alu_cf = "AVM_ALU_ALU_CF"; + Base::avm_alu_alu_op_eq_diff_inv = "AVM_ALU_ALU_OP_EQ_DIFF_INV"; Base::avm_main_pc = "AVM_MAIN_PC"; Base::avm_main_internal_return_ptr = "AVM_MAIN_INTERNAL_RETURN_PTR"; Base::avm_main_sel_internal_call = "AVM_MAIN_SEL_INTERNAL_CALL"; @@ -623,6 +661,7 @@ class AvmFlavor { Base::avm_main_sel_op_mul = "AVM_MAIN_SEL_OP_MUL"; Base::avm_main_sel_op_div = "AVM_MAIN_SEL_OP_DIV"; Base::avm_main_sel_op_not = "AVM_MAIN_SEL_OP_NOT"; + Base::avm_main_sel_op_eq = "AVM_MAIN_SEL_OP_EQ"; Base::avm_main_in_tag = "AVM_MAIN_IN_TAG"; Base::avm_main_op_err = "AVM_MAIN_OP_ERR"; Base::avm_main_tag_err = "AVM_MAIN_TAG_ERR"; @@ -679,6 +718,7 @@ class AvmFlavor { Commitment avm_alu_alu_op_mul; Commitment avm_alu_alu_op_div; Commitment avm_alu_alu_op_not; + Commitment avm_alu_alu_op_eq; Commitment avm_alu_alu_ff_tag; Commitment avm_alu_alu_u8_tag; Commitment avm_alu_alu_u16_tag; @@ -697,6 +737,7 @@ class AvmFlavor { Commitment avm_alu_alu_u16_r7; Commitment avm_alu_alu_u64_r0; Commitment avm_alu_alu_cf; + Commitment avm_alu_alu_op_eq_diff_inv; Commitment avm_main_pc; Commitment avm_main_internal_return_ptr; Commitment avm_main_sel_internal_call; @@ -708,6 +749,7 @@ class AvmFlavor { Commitment avm_main_sel_op_mul; Commitment avm_main_sel_op_div; Commitment avm_main_sel_op_not; + Commitment avm_main_sel_op_eq; Commitment avm_main_in_tag; Commitment avm_main_op_err; Commitment avm_main_tag_err; @@ -764,6 +806,7 @@ class AvmFlavor { avm_alu_alu_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_alu_alu_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_alu_alu_op_not = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_op_eq = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_alu_alu_ff_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_alu_alu_u8_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_alu_alu_u16_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -782,6 +825,7 @@ class AvmFlavor { avm_alu_alu_u16_r7 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_alu_alu_u64_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_alu_alu_cf = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_alu_alu_op_eq_diff_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_pc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_internal_return_ptr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_internal_call = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -793,6 +837,7 @@ class AvmFlavor { avm_main_sel_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_not = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_eq = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_op_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -853,6 +898,7 @@ class AvmFlavor { serialize_to_buffer(avm_alu_alu_op_mul, Transcript::proof_data); serialize_to_buffer(avm_alu_alu_op_div, Transcript::proof_data); serialize_to_buffer(avm_alu_alu_op_not, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_op_eq, Transcript::proof_data); serialize_to_buffer(avm_alu_alu_ff_tag, Transcript::proof_data); serialize_to_buffer(avm_alu_alu_u8_tag, Transcript::proof_data); serialize_to_buffer(avm_alu_alu_u16_tag, Transcript::proof_data); @@ -871,6 +917,7 @@ class AvmFlavor { serialize_to_buffer(avm_alu_alu_u16_r7, Transcript::proof_data); serialize_to_buffer(avm_alu_alu_u64_r0, Transcript::proof_data); serialize_to_buffer(avm_alu_alu_cf, Transcript::proof_data); + serialize_to_buffer(avm_alu_alu_op_eq_diff_inv, Transcript::proof_data); serialize_to_buffer(avm_main_pc, Transcript::proof_data); serialize_to_buffer(avm_main_internal_return_ptr, Transcript::proof_data); serialize_to_buffer(avm_main_sel_internal_call, Transcript::proof_data); @@ -882,6 +929,7 @@ class AvmFlavor { serialize_to_buffer(avm_main_sel_op_mul, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_div, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_not, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_eq, Transcript::proof_data); serialize_to_buffer(avm_main_in_tag, Transcript::proof_data); serialize_to_buffer(avm_main_op_err, Transcript::proof_data); serialize_to_buffer(avm_main_tag_err, Transcript::proof_data); 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 new file mode 100644 index 00000000000..42416b1254b --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp @@ -0,0 +1,288 @@ + + +// AUTOGENERATED FILE +#pragma once + +#include "barretenberg/common/constexpr_utils.hpp" +#include "barretenberg/common/throw_or_abort.hpp" +#include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/honk/proof_system/logderivative_library.hpp" +#include "barretenberg/proof_system/circuit_builder/circuit_builder_base.hpp" +#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp" +#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" + +#include "barretenberg/flavor/generated/AvmMini_flavor.hpp" +#include "barretenberg/relations/generated/AvmMini/alu_chip.hpp" +#include "barretenberg/relations/generated/AvmMini/avm_mini.hpp" +#include "barretenberg/relations/generated/AvmMini/mem_trace.hpp" + +using namespace bb; + +namespace bb { + +template struct AvmMiniFullRow { + FF avmMini_clk{}; + FF avmMini_first{}; + FF memTrace_m_clk{}; + FF memTrace_m_sub_clk{}; + FF memTrace_m_addr{}; + FF memTrace_m_tag{}; + FF memTrace_m_val{}; + FF memTrace_m_lastAccess{}; + FF memTrace_m_last{}; + FF memTrace_m_rw{}; + FF memTrace_m_in_tag{}; + FF memTrace_m_tag_err{}; + FF memTrace_m_one_min_inv{}; + FF aluChip_alu_clk{}; + FF aluChip_alu_ia{}; + FF aluChip_alu_ib{}; + FF aluChip_alu_ic{}; + FF aluChip_alu_op_add{}; + FF aluChip_alu_op_sub{}; + FF aluChip_alu_op_mul{}; + FF aluChip_alu_op_div{}; + FF aluChip_alu_op_not{}; + FF aluChip_alu_op_eq{}; + FF aluChip_alu_ff_tag{}; + FF aluChip_alu_u8_tag{}; + FF aluChip_alu_u16_tag{}; + FF aluChip_alu_u32_tag{}; + FF aluChip_alu_u64_tag{}; + FF aluChip_alu_u128_tag{}; + FF aluChip_alu_u8_r0{}; + FF aluChip_alu_u8_r1{}; + FF aluChip_alu_u16_r0{}; + FF aluChip_alu_u16_r1{}; + FF aluChip_alu_u16_r2{}; + FF aluChip_alu_u16_r3{}; + FF aluChip_alu_u16_r4{}; + FF aluChip_alu_u16_r5{}; + FF aluChip_alu_u16_r6{}; + FF aluChip_alu_u16_r7{}; + FF aluChip_alu_u64_r0{}; + FF aluChip_alu_cf{}; + FF aluChip_alu_inv_diff{}; + FF avmMini_pc{}; + FF avmMini_internal_return_ptr{}; + FF avmMini_sel_internal_call{}; + FF avmMini_sel_internal_return{}; + FF avmMini_sel_jump{}; + FF avmMini_sel_halt{}; + FF avmMini_sel_op_add{}; + FF avmMini_sel_op_sub{}; + FF avmMini_sel_op_mul{}; + FF avmMini_sel_op_div{}; + FF avmMini_sel_op_not{}; + FF avmMini_sel_op_eq{}; + FF avmMini_in_tag{}; + FF avmMini_op_err{}; + FF avmMini_tag_err{}; + FF avmMini_inv{}; + FF avmMini_ia{}; + FF avmMini_ib{}; + FF avmMini_ic{}; + FF avmMini_mem_op_a{}; + FF avmMini_mem_op_b{}; + FF avmMini_mem_op_c{}; + FF avmMini_rwa{}; + FF avmMini_rwb{}; + FF avmMini_rwc{}; + FF avmMini_mem_idx_a{}; + FF avmMini_mem_idx_b{}; + FF avmMini_mem_idx_c{}; + FF avmMini_last{}; + FF 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_r3_shift{}; + FF aluChip_alu_u16_r4_shift{}; + FF avmMini_pc_shift{}; + FF avmMini_internal_return_ptr_shift{}; + FF memTrace_m_tag_shift{}; + FF memTrace_m_rw_shift{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_val_shift{}; +}; + +class AvmMiniCircuitBuilder { + public: + using Flavor = bb::AvmMiniFlavor; + using FF = Flavor::FF; + using Row = AvmMiniFullRow; + + // TODO: template + using Polynomial = Flavor::Polynomial; + using ProverPolynomials = Flavor::ProverPolynomials; + + static constexpr size_t num_fixed_columns = 85; + static constexpr size_t num_polys = 71; + std::vector rows; + + void set_trace(std::vector&& trace) { rows = std::move(trace); } + + ProverPolynomials compute_polynomials() + { + const auto num_rows = get_circuit_subgroup_size(); + ProverPolynomials polys; + + // Allocate mem for each column + for (auto& poly : polys.get_all()) { + poly = Polynomial(num_rows); + } + + for (size_t i = 0; i < rows.size(); i++) { + polys.avmMini_clk[i] = rows[i].avmMini_clk; + polys.avmMini_first[i] = rows[i].avmMini_first; + polys.memTrace_m_clk[i] = rows[i].memTrace_m_clk; + polys.memTrace_m_sub_clk[i] = rows[i].memTrace_m_sub_clk; + polys.memTrace_m_addr[i] = rows[i].memTrace_m_addr; + polys.memTrace_m_tag[i] = rows[i].memTrace_m_tag; + polys.memTrace_m_val[i] = rows[i].memTrace_m_val; + polys.memTrace_m_lastAccess[i] = rows[i].memTrace_m_lastAccess; + polys.memTrace_m_last[i] = rows[i].memTrace_m_last; + polys.memTrace_m_rw[i] = rows[i].memTrace_m_rw; + polys.memTrace_m_in_tag[i] = rows[i].memTrace_m_in_tag; + polys.memTrace_m_tag_err[i] = rows[i].memTrace_m_tag_err; + polys.memTrace_m_one_min_inv[i] = rows[i].memTrace_m_one_min_inv; + polys.aluChip_alu_clk[i] = rows[i].aluChip_alu_clk; + polys.aluChip_alu_ia[i] = rows[i].aluChip_alu_ia; + polys.aluChip_alu_ib[i] = rows[i].aluChip_alu_ib; + polys.aluChip_alu_ic[i] = rows[i].aluChip_alu_ic; + polys.aluChip_alu_op_add[i] = rows[i].aluChip_alu_op_add; + polys.aluChip_alu_op_sub[i] = rows[i].aluChip_alu_op_sub; + polys.aluChip_alu_op_mul[i] = rows[i].aluChip_alu_op_mul; + polys.aluChip_alu_op_div[i] = rows[i].aluChip_alu_op_div; + polys.aluChip_alu_op_not[i] = rows[i].aluChip_alu_op_not; + polys.aluChip_alu_op_eq[i] = rows[i].aluChip_alu_op_eq; + polys.aluChip_alu_ff_tag[i] = rows[i].aluChip_alu_ff_tag; + polys.aluChip_alu_u8_tag[i] = rows[i].aluChip_alu_u8_tag; + polys.aluChip_alu_u16_tag[i] = rows[i].aluChip_alu_u16_tag; + polys.aluChip_alu_u32_tag[i] = rows[i].aluChip_alu_u32_tag; + polys.aluChip_alu_u64_tag[i] = rows[i].aluChip_alu_u64_tag; + polys.aluChip_alu_u128_tag[i] = rows[i].aluChip_alu_u128_tag; + polys.aluChip_alu_u8_r0[i] = rows[i].aluChip_alu_u8_r0; + polys.aluChip_alu_u8_r1[i] = rows[i].aluChip_alu_u8_r1; + polys.aluChip_alu_u16_r0[i] = rows[i].aluChip_alu_u16_r0; + polys.aluChip_alu_u16_r1[i] = rows[i].aluChip_alu_u16_r1; + polys.aluChip_alu_u16_r2[i] = rows[i].aluChip_alu_u16_r2; + polys.aluChip_alu_u16_r3[i] = rows[i].aluChip_alu_u16_r3; + polys.aluChip_alu_u16_r4[i] = rows[i].aluChip_alu_u16_r4; + polys.aluChip_alu_u16_r5[i] = rows[i].aluChip_alu_u16_r5; + polys.aluChip_alu_u16_r6[i] = rows[i].aluChip_alu_u16_r6; + polys.aluChip_alu_u16_r7[i] = rows[i].aluChip_alu_u16_r7; + polys.aluChip_alu_u64_r0[i] = rows[i].aluChip_alu_u64_r0; + polys.aluChip_alu_cf[i] = rows[i].aluChip_alu_cf; + polys.aluChip_alu_inv_diff[i] = rows[i].aluChip_alu_inv_diff; + polys.avmMini_pc[i] = rows[i].avmMini_pc; + polys.avmMini_internal_return_ptr[i] = rows[i].avmMini_internal_return_ptr; + polys.avmMini_sel_internal_call[i] = rows[i].avmMini_sel_internal_call; + polys.avmMini_sel_internal_return[i] = rows[i].avmMini_sel_internal_return; + polys.avmMini_sel_jump[i] = rows[i].avmMini_sel_jump; + polys.avmMini_sel_halt[i] = rows[i].avmMini_sel_halt; + polys.avmMini_sel_op_add[i] = rows[i].avmMini_sel_op_add; + polys.avmMini_sel_op_sub[i] = rows[i].avmMini_sel_op_sub; + polys.avmMini_sel_op_mul[i] = rows[i].avmMini_sel_op_mul; + polys.avmMini_sel_op_div[i] = rows[i].avmMini_sel_op_div; + polys.avmMini_sel_op_not[i] = rows[i].avmMini_sel_op_not; + polys.avmMini_sel_op_eq[i] = rows[i].avmMini_sel_op_eq; + polys.avmMini_in_tag[i] = rows[i].avmMini_in_tag; + polys.avmMini_op_err[i] = rows[i].avmMini_op_err; + polys.avmMini_tag_err[i] = rows[i].avmMini_tag_err; + polys.avmMini_inv[i] = rows[i].avmMini_inv; + polys.avmMini_ia[i] = rows[i].avmMini_ia; + polys.avmMini_ib[i] = rows[i].avmMini_ib; + polys.avmMini_ic[i] = rows[i].avmMini_ic; + polys.avmMini_mem_op_a[i] = rows[i].avmMini_mem_op_a; + polys.avmMini_mem_op_b[i] = rows[i].avmMini_mem_op_b; + polys.avmMini_mem_op_c[i] = rows[i].avmMini_mem_op_c; + polys.avmMini_rwa[i] = rows[i].avmMini_rwa; + polys.avmMini_rwb[i] = rows[i].avmMini_rwb; + polys.avmMini_rwc[i] = rows[i].avmMini_rwc; + polys.avmMini_mem_idx_a[i] = rows[i].avmMini_mem_idx_a; + polys.avmMini_mem_idx_b[i] = rows[i].avmMini_mem_idx_b; + polys.avmMini_mem_idx_c[i] = rows[i].avmMini_mem_idx_c; + polys.avmMini_last[i] = rows[i].avmMini_last; + } + + polys.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_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); + polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.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_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; + } + + [[maybe_unused]] bool check_circuit() + { + + auto polys = compute_polynomials(); + const size_t num_rows = polys.get_polynomial_size(); + + const auto evaluate_relation = [&](const std::string& relation_name, + std::string (*debug_label)(int)) { + typename Relation::SumcheckArrayOfValuesOverSubrelations result; + for (auto& r : result) { + r = 0; + } + constexpr size_t NUM_SUBRELATIONS = result.size(); + + for (size_t i = 0; i < num_rows; ++i) { + Relation::accumulate(result, polys.get_row(i), {}, 1); + + bool x = true; + for (size_t j = 0; j < NUM_SUBRELATIONS; ++j) { + if (result[j] != 0) { + std::string row_name = debug_label(static_cast(j)); + throw_or_abort( + format("Relation ", relation_name, ", subrelation index ", row_name, " failed at row ", i)); + x = false; + } + } + if (!x) { + return false; + } + } + return true; + }; + + if (!evaluate_relation.template operator()>("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; + } + + return true; + } + + [[nodiscard]] size_t get_num_gates() const { return rows.size(); } + + [[nodiscard]] size_t get_circuit_subgroup_size() const + { + const size_t num_rows = get_num_gates(); + const auto num_rows_log2 = static_cast(numeric::get_msb64(num_rows)); + size_t num_rows_pow2 = 1UL << (num_rows_log2 + (1UL << num_rows_log2 == num_rows ? 0 : 1)); + return num_rows_pow2; + } +}; +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/avm_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/avm_circuit_builder.hpp index 987a0d62ed6..59b53d25c61 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/avm_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/avm_circuit_builder.hpp @@ -41,6 +41,7 @@ template struct AvmFullRow { FF avm_alu_alu_op_mul{}; FF avm_alu_alu_op_div{}; FF avm_alu_alu_op_not{}; + FF avm_alu_alu_op_eq{}; FF avm_alu_alu_ff_tag{}; FF avm_alu_alu_u8_tag{}; FF avm_alu_alu_u16_tag{}; @@ -59,6 +60,7 @@ template struct AvmFullRow { FF avm_alu_alu_u16_r7{}; FF avm_alu_alu_u64_r0{}; FF avm_alu_alu_cf{}; + FF avm_alu_alu_op_eq_diff_inv{}; FF avm_main_pc{}; FF avm_main_internal_return_ptr{}; FF avm_main_sel_internal_call{}; @@ -70,6 +72,7 @@ template struct AvmFullRow { FF avm_main_sel_op_mul{}; FF avm_main_sel_op_div{}; FF avm_main_sel_op_not{}; + FF avm_main_sel_op_eq{}; FF avm_main_in_tag{}; FF avm_main_op_err{}; FF avm_main_tag_err{}; @@ -87,20 +90,20 @@ template struct AvmFullRow { FF avm_main_mem_idx_b{}; FF avm_main_mem_idx_c{}; FF avm_main_last{}; - FF avm_main_pc_shift{}; - FF avm_main_internal_return_ptr_shift{}; FF avm_mem_m_rw_shift{}; - FF avm_mem_m_addr_shift{}; - FF avm_mem_m_val_shift{}; FF avm_mem_m_tag_shift{}; + FF avm_mem_m_val_shift{}; + FF avm_mem_m_addr_shift{}; + FF avm_main_internal_return_ptr_shift{}; + FF avm_main_pc_shift{}; FF avm_alu_alu_u16_r6_shift{}; - FF avm_alu_alu_u16_r4_shift{}; - FF avm_alu_alu_u16_r1_shift{}; + FF avm_alu_alu_u16_r0_shift{}; FF avm_alu_alu_u16_r2_shift{}; FF avm_alu_alu_u16_r7_shift{}; - FF avm_alu_alu_u16_r0_shift{}; FF avm_alu_alu_u16_r3_shift{}; + FF avm_alu_alu_u16_r1_shift{}; FF avm_alu_alu_u16_r5_shift{}; + FF avm_alu_alu_u16_r4_shift{}; }; class AvmCircuitBuilder { @@ -113,8 +116,8 @@ class AvmCircuitBuilder { using Polynomial = Flavor::Polynomial; using ProverPolynomials = Flavor::ProverPolynomials; - static constexpr size_t num_fixed_columns = 82; - static constexpr size_t num_polys = 68; + static constexpr size_t num_fixed_columns = 85; + static constexpr size_t num_polys = 71; std::vector rows; void set_trace(std::vector&& trace) { rows = std::move(trace); } @@ -152,6 +155,7 @@ class AvmCircuitBuilder { polys.avm_alu_alu_op_mul[i] = rows[i].avm_alu_alu_op_mul; polys.avm_alu_alu_op_div[i] = rows[i].avm_alu_alu_op_div; polys.avm_alu_alu_op_not[i] = rows[i].avm_alu_alu_op_not; + polys.avm_alu_alu_op_eq[i] = rows[i].avm_alu_alu_op_eq; polys.avm_alu_alu_ff_tag[i] = rows[i].avm_alu_alu_ff_tag; polys.avm_alu_alu_u8_tag[i] = rows[i].avm_alu_alu_u8_tag; polys.avm_alu_alu_u16_tag[i] = rows[i].avm_alu_alu_u16_tag; @@ -170,6 +174,7 @@ class AvmCircuitBuilder { polys.avm_alu_alu_u16_r7[i] = rows[i].avm_alu_alu_u16_r7; polys.avm_alu_alu_u64_r0[i] = rows[i].avm_alu_alu_u64_r0; polys.avm_alu_alu_cf[i] = rows[i].avm_alu_alu_cf; + polys.avm_alu_alu_op_eq_diff_inv[i] = rows[i].avm_alu_alu_op_eq_diff_inv; polys.avm_main_pc[i] = rows[i].avm_main_pc; polys.avm_main_internal_return_ptr[i] = rows[i].avm_main_internal_return_ptr; polys.avm_main_sel_internal_call[i] = rows[i].avm_main_sel_internal_call; @@ -181,6 +186,7 @@ class AvmCircuitBuilder { polys.avm_main_sel_op_mul[i] = rows[i].avm_main_sel_op_mul; polys.avm_main_sel_op_div[i] = rows[i].avm_main_sel_op_div; polys.avm_main_sel_op_not[i] = rows[i].avm_main_sel_op_not; + polys.avm_main_sel_op_eq[i] = rows[i].avm_main_sel_op_eq; polys.avm_main_in_tag[i] = rows[i].avm_main_in_tag; polys.avm_main_op_err[i] = rows[i].avm_main_op_err; polys.avm_main_tag_err[i] = rows[i].avm_main_tag_err; @@ -200,20 +206,20 @@ class AvmCircuitBuilder { polys.avm_main_last[i] = rows[i].avm_main_last; } - polys.avm_main_pc_shift = Polynomial(polys.avm_main_pc.shifted()); - polys.avm_main_internal_return_ptr_shift = Polynomial(polys.avm_main_internal_return_ptr.shifted()); polys.avm_mem_m_rw_shift = Polynomial(polys.avm_mem_m_rw.shifted()); - polys.avm_mem_m_addr_shift = Polynomial(polys.avm_mem_m_addr.shifted()); - polys.avm_mem_m_val_shift = Polynomial(polys.avm_mem_m_val.shifted()); polys.avm_mem_m_tag_shift = Polynomial(polys.avm_mem_m_tag.shifted()); + polys.avm_mem_m_val_shift = Polynomial(polys.avm_mem_m_val.shifted()); + polys.avm_mem_m_addr_shift = Polynomial(polys.avm_mem_m_addr.shifted()); + polys.avm_main_internal_return_ptr_shift = Polynomial(polys.avm_main_internal_return_ptr.shifted()); + polys.avm_main_pc_shift = Polynomial(polys.avm_main_pc.shifted()); polys.avm_alu_alu_u16_r6_shift = Polynomial(polys.avm_alu_alu_u16_r6.shifted()); - polys.avm_alu_alu_u16_r4_shift = Polynomial(polys.avm_alu_alu_u16_r4.shifted()); - polys.avm_alu_alu_u16_r1_shift = Polynomial(polys.avm_alu_alu_u16_r1.shifted()); + polys.avm_alu_alu_u16_r0_shift = Polynomial(polys.avm_alu_alu_u16_r0.shifted()); polys.avm_alu_alu_u16_r2_shift = Polynomial(polys.avm_alu_alu_u16_r2.shifted()); polys.avm_alu_alu_u16_r7_shift = Polynomial(polys.avm_alu_alu_u16_r7.shifted()); - polys.avm_alu_alu_u16_r0_shift = Polynomial(polys.avm_alu_alu_u16_r0.shifted()); polys.avm_alu_alu_u16_r3_shift = Polynomial(polys.avm_alu_alu_u16_r3.shifted()); + polys.avm_alu_alu_u16_r1_shift = Polynomial(polys.avm_alu_alu_u16_r1.shifted()); polys.avm_alu_alu_u16_r5_shift = Polynomial(polys.avm_alu_alu_u16_r5.shifted()); + polys.avm_alu_alu_u16_r4_shift = Polynomial(polys.avm_alu_alu_u16_r4.shifted()); return polys; } @@ -251,14 +257,14 @@ class AvmCircuitBuilder { return true; }; - if (!evaluate_relation.template operator()>("avm_main", - Avm_vm::get_relation_label_avm_main)) { - return false; - } if (!evaluate_relation.template operator()>("avm_mem", Avm_vm::get_relation_label_avm_mem)) { return false; } + if (!evaluate_relation.template operator()>("avm_main", + Avm_vm::get_relation_label_avm_main)) { + return false; + } if (!evaluate_relation.template operator()>("avm_alu", Avm_vm::get_relation_label_avm_alu)) { 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..ec24125e8f2 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -0,0 +1,336 @@ + +#pragma once +#include "../../relation_parameters.hpp" +#include "../../relation_types.hpp" +#include "./declare_views.hpp" + +namespace bb::AvmMini_vm { + +template struct Alu_chipRow { + FF aluChip_alu_ic{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_op_not{}; + FF aluChip_alu_op_add{}; + FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_u8_r1{}; + FF aluChip_alu_u16_r6{}; + FF aluChip_alu_cf{}; + FF aluChip_alu_u16_r7{}; + FF aluChip_alu_u16_r5{}; + FF aluChip_alu_inv_diff{}; + FF aluChip_alu_op_eq{}; + FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r1{}; + FF aluChip_alu_u16_r3{}; + FF aluChip_alu_u8_tag{}; + FF aluChip_alu_u64_tag{}; + FF aluChip_alu_ib{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u16_r2{}; + FF aluChip_alu_u8_r0{}; + FF aluChip_alu_u16_r4{}; + FF aluChip_alu_u32_tag{}; + FF aluChip_alu_op_mul{}; + FF aluChip_alu_u16_r1_shift{}; + FF aluChip_alu_u16_tag{}; + FF aluChip_alu_op_sub{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_ff_tag{}; + FF aluChip_alu_u64_r0{}; + FF aluChip_alu_u16_r0{}; + FF aluChip_alu_u128_tag{}; + FF aluChip_alu_ia{}; + FF aluChip_alu_u16_r4_shift{}; +}; + +inline std::string get_relation_label_alu_chip(int index) +{ + switch (index) { + case 16: + return "ALU_RES_IS_BOOL"; + + case 14: + return "ALU_FF_NOT_XOR"; + + case 6: + return "ALU_ADD_SUB_1"; + + case 10: + return "ALU_MUL_COMMON_2"; + + case 8: + return "ALU_MULTIPLICATION_FF"; + + case 7: + return "ALU_ADD_SUB_2"; + + case 9: + return "ALU_MUL_COMMON_1"; + + case 13: + return "ALU_MULTIPLICATION_OUT_U128"; + + case 15: + return "ALU_OP_NOT"; + + case 17: + return "ALU_OP_EQ"; + } + return std::to_string(index); +} + +template class alu_chipImpl { + public: + using FF = FF_; + + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 6, 6, 8, 3, 4, 4, 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_ff_tag * (-aluChip_alu_ff_tag + FF(1))); + tmp *= scaling_factor; + std::get<0>(evals) += tmp; + } + // Contribution 1 + { + AvmMini_DECLARE_VIEWS(1); + + auto tmp = (aluChip_alu_u8_tag * (-aluChip_alu_u8_tag + FF(1))); + tmp *= scaling_factor; + std::get<1>(evals) += tmp; + } + // Contribution 2 + { + AvmMini_DECLARE_VIEWS(2); + + auto tmp = (aluChip_alu_u16_tag * (-aluChip_alu_u16_tag + FF(1))); + tmp *= scaling_factor; + std::get<2>(evals) += tmp; + } + // Contribution 3 + { + AvmMini_DECLARE_VIEWS(3); + + auto tmp = (aluChip_alu_u32_tag * (-aluChip_alu_u32_tag + FF(1))); + tmp *= scaling_factor; + std::get<3>(evals) += tmp; + } + // Contribution 4 + { + AvmMini_DECLARE_VIEWS(4); + + auto tmp = (aluChip_alu_u64_tag * (-aluChip_alu_u64_tag + FF(1))); + tmp *= scaling_factor; + std::get<4>(evals) += tmp; + } + // Contribution 5 + { + AvmMini_DECLARE_VIEWS(5); + + auto tmp = (aluChip_alu_u128_tag * (-aluChip_alu_u128_tag + FF(1))); + tmp *= scaling_factor; + std::get<5>(evals) += tmp; + } + // Contribution 6 + { + AvmMini_DECLARE_VIEWS(6); + + auto tmp = + (((aluChip_alu_op_add + aluChip_alu_op_sub) * + ((((((((((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))) + + (aluChip_alu_u16_r1 * FF(4294967296UL))) + + (aluChip_alu_u16_r2 * FF(281474976710656UL))) + + (aluChip_alu_u16_r3 * FF(uint256_t{ 0, 1, 0, 0 }))) + + (aluChip_alu_u16_r4 * FF(uint256_t{ 0, 65536, 0, 0 }))) + + (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + + (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - + aluChip_alu_ia) + + (aluChip_alu_ff_tag * aluChip_alu_ic))) + + ((aluChip_alu_op_add - aluChip_alu_op_sub) * + ((aluChip_alu_cf * FF(uint256_t{ 0, 0, 1, 0 })) - aluChip_alu_ib))); + tmp *= scaling_factor; + std::get<6>(evals) += tmp; + } + // Contribution 7 + { + AvmMini_DECLARE_VIEWS(7); + + auto tmp = + (((aluChip_alu_op_add + aluChip_alu_op_sub) * + (((((((aluChip_alu_u8_tag * aluChip_alu_u8_r0) + + (aluChip_alu_u16_tag * (aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))))) + + (aluChip_alu_u32_tag * + ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))))) + + (aluChip_alu_u64_tag * + ((((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))) + + (aluChip_alu_u16_r1 * FF(4294967296UL))) + + (aluChip_alu_u16_r2 * FF(281474976710656UL))))) + + (aluChip_alu_u128_tag * + ((((((((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))) + + (aluChip_alu_u16_r1 * FF(4294967296UL))) + + (aluChip_alu_u16_r2 * FF(281474976710656UL))) + + (aluChip_alu_u16_r3 * FF(uint256_t{ 0, 1, 0, 0 }))) + + (aluChip_alu_u16_r4 * FF(uint256_t{ 0, 65536, 0, 0 }))) + + (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + + (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))))) + + (aluChip_alu_ff_tag * aluChip_alu_ia)) - + aluChip_alu_ic)) + + ((aluChip_alu_ff_tag * (aluChip_alu_op_add - aluChip_alu_op_sub)) * aluChip_alu_ib)); + tmp *= scaling_factor; + std::get<7>(evals) += tmp; + } + // Contribution 8 + { + AvmMini_DECLARE_VIEWS(8); + + auto tmp = + ((aluChip_alu_ff_tag * aluChip_alu_op_mul) * ((aluChip_alu_ia * aluChip_alu_ib) - aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<8>(evals) += tmp; + } + // Contribution 9 + { + AvmMini_DECLARE_VIEWS(9); + + auto tmp = + ((((-aluChip_alu_ff_tag + FF(1)) - aluChip_alu_u128_tag) * aluChip_alu_op_mul) * + (((((((((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))) + + (aluChip_alu_u16_r1 * FF(4294967296UL))) + + (aluChip_alu_u16_r2 * FF(281474976710656UL))) + + (aluChip_alu_u16_r3 * FF(uint256_t{ 0, 1, 0, 0 }))) + + (aluChip_alu_u16_r4 * FF(uint256_t{ 0, 65536, 0, 0 }))) + + (aluChip_alu_u16_r5 * FF(uint256_t{ 0, 4294967296, 0, 0 }))) + + (aluChip_alu_u16_r6 * FF(uint256_t{ 0, 281474976710656, 0, 0 }))) - + (aluChip_alu_ia * aluChip_alu_ib))); + tmp *= scaling_factor; + std::get<9>(evals) += tmp; + } + // Contribution 10 + { + AvmMini_DECLARE_VIEWS(10); + + auto tmp = (aluChip_alu_op_mul * + (((((aluChip_alu_u8_tag * aluChip_alu_u8_r0) + + (aluChip_alu_u16_tag * (aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))))) + + (aluChip_alu_u32_tag * + ((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))))) + + (aluChip_alu_u64_tag * + ((((aluChip_alu_u8_r0 + (aluChip_alu_u8_r1 * FF(256))) + (aluChip_alu_u16_r0 * FF(65536))) + + (aluChip_alu_u16_r1 * FF(4294967296UL))) + + (aluChip_alu_u16_r2 * FF(281474976710656UL))))) - + (((-aluChip_alu_ff_tag + FF(1)) - aluChip_alu_u128_tag) * aluChip_alu_ic))); + tmp *= scaling_factor; + std::get<10>(evals) += tmp; + } + // Contribution 11 + { + AvmMini_DECLARE_VIEWS(11); + + auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * + (((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + + (aluChip_alu_u16_r2 * FF(4294967296UL))) + + (aluChip_alu_u16_r3 * FF(281474976710656UL))) + + ((((aluChip_alu_u16_r4 + (aluChip_alu_u16_r5 * FF(65536))) + + (aluChip_alu_u16_r6 * FF(4294967296UL))) + + (aluChip_alu_u16_r7 * FF(281474976710656UL))) * + FF(uint256_t{ 0, 1, 0, 0 }))) - + aluChip_alu_ia)); + tmp *= scaling_factor; + std::get<11>(evals) += tmp; + } + // Contribution 12 + { + AvmMini_DECLARE_VIEWS(12); + + auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * + (((((aluChip_alu_u16_r0_shift + (aluChip_alu_u16_r1_shift * FF(65536))) + + (aluChip_alu_u16_r2_shift * FF(4294967296UL))) + + (aluChip_alu_u16_r3_shift * FF(281474976710656UL))) + + ((((aluChip_alu_u16_r4_shift + (aluChip_alu_u16_r5_shift * FF(65536))) + + (aluChip_alu_u16_r6_shift * FF(4294967296UL))) + + (aluChip_alu_u16_r7_shift * FF(281474976710656UL))) * + FF(uint256_t{ 0, 1, 0, 0 }))) - + aluChip_alu_ib)); + tmp *= scaling_factor; + std::get<12>(evals) += tmp; + } + // Contribution 13 + { + AvmMini_DECLARE_VIEWS(13); + + auto tmp = ((aluChip_alu_u128_tag * aluChip_alu_op_mul) * + ((((aluChip_alu_ia * (((aluChip_alu_u16_r0_shift + (aluChip_alu_u16_r1_shift * FF(65536))) + + (aluChip_alu_u16_r2_shift * FF(4294967296UL))) + + (aluChip_alu_u16_r3_shift * FF(281474976710656UL)))) + + (((((aluChip_alu_u16_r0 + (aluChip_alu_u16_r1 * FF(65536))) + + (aluChip_alu_u16_r2 * FF(4294967296UL))) + + (aluChip_alu_u16_r3 * FF(281474976710656UL))) * + (((aluChip_alu_u16_r4_shift + (aluChip_alu_u16_r5_shift * FF(65536))) + + (aluChip_alu_u16_r6_shift * FF(4294967296UL))) + + (aluChip_alu_u16_r7_shift * FF(281474976710656UL)))) * + FF(uint256_t{ 0, 1, 0, 0 }))) - + (((aluChip_alu_cf * FF(uint256_t{ 0, 1, 0, 0 })) + aluChip_alu_u64_r0) * + FF(uint256_t{ 0, 0, 1, 0 }))) - + aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<13>(evals) += tmp; + } + // Contribution 14 + { + AvmMini_DECLARE_VIEWS(14); + + auto tmp = (aluChip_alu_op_not * aluChip_alu_ff_tag); + tmp *= scaling_factor; + std::get<14>(evals) += tmp; + } + // Contribution 15 + { + AvmMini_DECLARE_VIEWS(15); + + auto tmp = (aluChip_alu_op_not * ((aluChip_alu_ia + aluChip_alu_ic) - + ((((((aluChip_alu_u8_tag * FF(256)) + (aluChip_alu_u16_tag * FF(65536))) + + (aluChip_alu_u32_tag * FF(4294967296UL))) + + (aluChip_alu_u64_tag * FF(uint256_t{ 0, 1, 0, 0 }))) + + (aluChip_alu_u128_tag * FF(uint256_t{ 0, 0, 1, 0 }))) - + FF(1)))); + tmp *= scaling_factor; + std::get<15>(evals) += tmp; + } + // Contribution 16 + { + AvmMini_DECLARE_VIEWS(16); + + auto tmp = (aluChip_alu_op_eq * (aluChip_alu_ic * (-aluChip_alu_ic + FF(1)))); + tmp *= scaling_factor; + std::get<16>(evals) += tmp; + } + // Contribution 17 + { + AvmMini_DECLARE_VIEWS(17); + + auto tmp = + (aluChip_alu_op_eq * ((((aluChip_alu_ia - aluChip_alu_ib) * + ((aluChip_alu_ic * (-aluChip_alu_inv_diff + FF(1))) + aluChip_alu_inv_diff)) - + FF(1)) + + aluChip_alu_ic)); + tmp *= scaling_factor; + std::get<17>(evals) += tmp; + } + } +}; + +template using alu_chip = Relation>; + +} // namespace bb::AvmMini_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp new file mode 100644 index 00000000000..82b7ef3fa54 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -0,0 +1,413 @@ + +#pragma once +#include "../../relation_parameters.hpp" +#include "../../relation_types.hpp" +#include "./declare_views.hpp" + +namespace bb::AvmMini_vm { + +template struct Avm_miniRow { + FF avmMini_pc{}; + FF avmMini_mem_op_a{}; + FF avmMini_mem_idx_b{}; + FF avmMini_sel_internal_call{}; + FF avmMini_sel_internal_return{}; + FF avmMini_rwc{}; + FF avmMini_mem_idx_a{}; + FF avmMini_sel_op_div{}; + FF avmMini_sel_op_sub{}; + FF avmMini_tag_err{}; + FF avmMini_op_err{}; + FF avmMini_sel_halt{}; + FF avmMini_rwb{}; + FF avmMini_inv{}; + FF avmMini_pc_shift{}; + FF avmMini_sel_op_add{}; + FF avmMini_first{}; + FF avmMini_sel_jump{}; + FF avmMini_ic{}; + FF avmMini_internal_return_ptr_shift{}; + FF avmMini_ia{}; + FF avmMini_rwa{}; + FF avmMini_mem_op_b{}; + FF avmMini_sel_op_not{}; + FF avmMini_sel_op_eq{}; + FF avmMini_internal_return_ptr{}; + FF avmMini_ib{}; + FF avmMini_mem_op_c{}; + FF avmMini_sel_op_mul{}; +}; + +inline std::string get_relation_label_avm_mini(int index) +{ + switch (index) { + case 37: + return "PC_INCREMENT"; + + case 21: + return "SUBOP_DIVISION_FF"; + + case 22: + return "SUBOP_DIVISION_ZERO_ERR1"; + + case 26: + return "RETURN_POINTER_INCREMENT"; + + case 32: + return "RETURN_POINTER_DECREMENT"; + + case 23: + return "SUBOP_DIVISION_ZERO_ERR2"; + + case 24: + return "SUBOP_ERROR_RELEVANT_OP"; + + case 38: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + } + return std::to_string(index); +} + +template class avm_miniImpl { + public: + using FF = FF_; + + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, + }; + + template + void static accumulate(ContainerOverSubrelations& evals, + const AllEntities& new_term, + [[maybe_unused]] const RelationParameters&, + [[maybe_unused]] const FF& scaling_factor) + { + + // Contribution 0 + { + AvmMini_DECLARE_VIEWS(0); + + auto tmp = (avmMini_sel_op_add * (-avmMini_sel_op_add + FF(1))); + tmp *= scaling_factor; + std::get<0>(evals) += tmp; + } + // Contribution 1 + { + AvmMini_DECLARE_VIEWS(1); + + auto tmp = (avmMini_sel_op_sub * (-avmMini_sel_op_sub + FF(1))); + tmp *= scaling_factor; + std::get<1>(evals) += tmp; + } + // Contribution 2 + { + AvmMini_DECLARE_VIEWS(2); + + auto tmp = (avmMini_sel_op_mul * (-avmMini_sel_op_mul + FF(1))); + tmp *= scaling_factor; + std::get<2>(evals) += tmp; + } + // Contribution 3 + { + AvmMini_DECLARE_VIEWS(3); + + auto tmp = (avmMini_sel_op_div * (-avmMini_sel_op_div + FF(1))); + tmp *= scaling_factor; + std::get<3>(evals) += tmp; + } + // Contribution 4 + { + AvmMini_DECLARE_VIEWS(4); + + auto tmp = (avmMini_sel_op_not * (-avmMini_sel_op_not + FF(1))); + tmp *= scaling_factor; + std::get<4>(evals) += tmp; + } + // Contribution 5 + { + AvmMini_DECLARE_VIEWS(5); + + auto tmp = (avmMini_sel_op_eq * (-avmMini_sel_op_eq + FF(1))); + tmp *= scaling_factor; + std::get<5>(evals) += tmp; + } + // Contribution 6 + { + AvmMini_DECLARE_VIEWS(6); + + auto tmp = (avmMini_sel_internal_call * (-avmMini_sel_internal_call + FF(1))); + tmp *= scaling_factor; + std::get<6>(evals) += tmp; + } + // Contribution 7 + { + AvmMini_DECLARE_VIEWS(7); + + auto tmp = (avmMini_sel_internal_return * (-avmMini_sel_internal_return + FF(1))); + tmp *= scaling_factor; + std::get<7>(evals) += tmp; + } + // Contribution 8 + { + AvmMini_DECLARE_VIEWS(8); + + auto tmp = (avmMini_sel_jump * (-avmMini_sel_jump + FF(1))); + tmp *= scaling_factor; + std::get<8>(evals) += tmp; + } + // Contribution 9 + { + AvmMini_DECLARE_VIEWS(9); + + auto tmp = (avmMini_sel_halt * (-avmMini_sel_halt + FF(1))); + tmp *= scaling_factor; + std::get<9>(evals) += tmp; + } + // Contribution 10 + { + AvmMini_DECLARE_VIEWS(10); + + auto tmp = (avmMini_op_err * (-avmMini_op_err + FF(1))); + tmp *= scaling_factor; + std::get<10>(evals) += tmp; + } + // Contribution 11 + { + AvmMini_DECLARE_VIEWS(11); + + auto tmp = (avmMini_tag_err * (-avmMini_tag_err + FF(1))); + tmp *= scaling_factor; + std::get<11>(evals) += tmp; + } + // Contribution 12 + { + AvmMini_DECLARE_VIEWS(12); + + auto tmp = (avmMini_mem_op_a * (-avmMini_mem_op_a + FF(1))); + tmp *= scaling_factor; + std::get<12>(evals) += tmp; + } + // Contribution 13 + { + AvmMini_DECLARE_VIEWS(13); + + auto tmp = (avmMini_mem_op_b * (-avmMini_mem_op_b + FF(1))); + tmp *= scaling_factor; + std::get<13>(evals) += tmp; + } + // Contribution 14 + { + AvmMini_DECLARE_VIEWS(14); + + auto tmp = (avmMini_mem_op_c * (-avmMini_mem_op_c + FF(1))); + tmp *= scaling_factor; + std::get<14>(evals) += tmp; + } + // Contribution 15 + { + AvmMini_DECLARE_VIEWS(15); + + auto tmp = (avmMini_rwa * (-avmMini_rwa + FF(1))); + tmp *= scaling_factor; + std::get<15>(evals) += tmp; + } + // Contribution 16 + { + AvmMini_DECLARE_VIEWS(16); + + auto tmp = (avmMini_rwb * (-avmMini_rwb + FF(1))); + tmp *= scaling_factor; + std::get<16>(evals) += tmp; + } + // Contribution 17 + { + AvmMini_DECLARE_VIEWS(17); + + auto tmp = (avmMini_rwc * (-avmMini_rwc + FF(1))); + tmp *= scaling_factor; + std::get<17>(evals) += tmp; + } + // Contribution 18 + { + AvmMini_DECLARE_VIEWS(18); + + auto tmp = (avmMini_tag_err * avmMini_ia); + tmp *= scaling_factor; + std::get<18>(evals) += tmp; + } + // Contribution 19 + { + AvmMini_DECLARE_VIEWS(19); + + auto tmp = (avmMini_tag_err * avmMini_ib); + tmp *= scaling_factor; + std::get<19>(evals) += tmp; + } + // Contribution 20 + { + AvmMini_DECLARE_VIEWS(20); + + auto tmp = (avmMini_tag_err * avmMini_ic); + tmp *= scaling_factor; + std::get<20>(evals) += tmp; + } + // Contribution 21 + { + AvmMini_DECLARE_VIEWS(21); + + 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; + } + // Contribution 22 + { + AvmMini_DECLARE_VIEWS(22); + + auto tmp = (avmMini_sel_op_div * (((avmMini_ib * avmMini_inv) - FF(1)) + avmMini_op_err)); + tmp *= scaling_factor; + std::get<22>(evals) += tmp; + } + // Contribution 23 + { + AvmMini_DECLARE_VIEWS(23); + + auto tmp = ((avmMini_sel_op_div * avmMini_op_err) * (-avmMini_inv + FF(1))); + tmp *= scaling_factor; + std::get<23>(evals) += tmp; + } + // Contribution 24 + { + AvmMini_DECLARE_VIEWS(24); + + auto tmp = (avmMini_op_err * (avmMini_sel_op_div - FF(1))); + tmp *= scaling_factor; + std::get<24>(evals) += tmp; + } + // Contribution 25 + { + AvmMini_DECLARE_VIEWS(25); + + auto tmp = (avmMini_sel_jump * (avmMini_pc_shift - avmMini_ia)); + tmp *= scaling_factor; + std::get<25>(evals) += tmp; + } + // Contribution 26 + { + AvmMini_DECLARE_VIEWS(26); + + 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; + } + // Contribution 27 + { + AvmMini_DECLARE_VIEWS(27); + + auto tmp = (avmMini_sel_internal_call * (avmMini_internal_return_ptr - avmMini_mem_idx_b)); + tmp *= scaling_factor; + std::get<27>(evals) += tmp; + } + // Contribution 28 + { + AvmMini_DECLARE_VIEWS(28); + + auto tmp = (avmMini_sel_internal_call * (avmMini_pc_shift - avmMini_ia)); + tmp *= scaling_factor; + std::get<28>(evals) += tmp; + } + // Contribution 29 + { + AvmMini_DECLARE_VIEWS(29); + + auto tmp = (avmMini_sel_internal_call * ((avmMini_pc + FF(1)) - avmMini_ib)); + tmp *= scaling_factor; + std::get<29>(evals) += tmp; + } + // Contribution 30 + { + AvmMini_DECLARE_VIEWS(30); + + auto tmp = (avmMini_sel_internal_call * (avmMini_rwb - FF(1))); + tmp *= scaling_factor; + std::get<30>(evals) += tmp; + } + // Contribution 31 + { + AvmMini_DECLARE_VIEWS(31); + + auto tmp = (avmMini_sel_internal_call * (avmMini_mem_op_b - FF(1))); + tmp *= scaling_factor; + std::get<31>(evals) += tmp; + } + // Contribution 32 + { + AvmMini_DECLARE_VIEWS(32); + + auto tmp = (avmMini_sel_internal_return * + (avmMini_internal_return_ptr_shift - (avmMini_internal_return_ptr - FF(1)))); + tmp *= scaling_factor; + std::get<32>(evals) += tmp; + } + // Contribution 33 + { + AvmMini_DECLARE_VIEWS(33); + + auto tmp = (avmMini_sel_internal_return * ((avmMini_internal_return_ptr - FF(1)) - avmMini_mem_idx_a)); + tmp *= scaling_factor; + std::get<33>(evals) += tmp; + } + // Contribution 34 + { + AvmMini_DECLARE_VIEWS(34); + + auto tmp = (avmMini_sel_internal_return * (avmMini_pc_shift - avmMini_ia)); + tmp *= scaling_factor; + std::get<34>(evals) += tmp; + } + // Contribution 35 + { + AvmMini_DECLARE_VIEWS(35); + + auto tmp = (avmMini_sel_internal_return * avmMini_rwa); + tmp *= scaling_factor; + std::get<35>(evals) += tmp; + } + // Contribution 36 + { + 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_sel_op_not) + + avmMini_sel_op_eq)) * + (avmMini_pc_shift - (avmMini_pc + FF(1)))); + tmp *= scaling_factor; + std::get<37>(evals) += tmp; + } + // Contribution 38 + { + 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<38>(evals) += tmp; + } + } +}; + +template using avm_mini = Relation>; + +} // namespace bb::AvmMini_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp new file mode 100644 index 00000000000..e2cd5edde8a --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -0,0 +1,89 @@ + +#define AvmMini_DECLARE_VIEWS(index) \ + using Accumulator = typename std::tuple_element::type; \ + using View = typename Accumulator::View; \ + [[maybe_unused]] auto avmMini_clk = View(new_term.avmMini_clk); \ + [[maybe_unused]] auto avmMini_first = View(new_term.avmMini_first); \ + [[maybe_unused]] auto memTrace_m_clk = View(new_term.memTrace_m_clk); \ + [[maybe_unused]] auto memTrace_m_sub_clk = View(new_term.memTrace_m_sub_clk); \ + [[maybe_unused]] auto memTrace_m_addr = View(new_term.memTrace_m_addr); \ + [[maybe_unused]] auto memTrace_m_tag = View(new_term.memTrace_m_tag); \ + [[maybe_unused]] auto memTrace_m_val = View(new_term.memTrace_m_val); \ + [[maybe_unused]] auto memTrace_m_lastAccess = View(new_term.memTrace_m_lastAccess); \ + [[maybe_unused]] auto memTrace_m_last = View(new_term.memTrace_m_last); \ + [[maybe_unused]] auto memTrace_m_rw = View(new_term.memTrace_m_rw); \ + [[maybe_unused]] auto memTrace_m_in_tag = View(new_term.memTrace_m_in_tag); \ + [[maybe_unused]] auto memTrace_m_tag_err = View(new_term.memTrace_m_tag_err); \ + [[maybe_unused]] auto memTrace_m_one_min_inv = View(new_term.memTrace_m_one_min_inv); \ + [[maybe_unused]] auto aluChip_alu_clk = View(new_term.aluChip_alu_clk); \ + [[maybe_unused]] auto aluChip_alu_ia = View(new_term.aluChip_alu_ia); \ + [[maybe_unused]] auto aluChip_alu_ib = View(new_term.aluChip_alu_ib); \ + [[maybe_unused]] auto aluChip_alu_ic = View(new_term.aluChip_alu_ic); \ + [[maybe_unused]] auto aluChip_alu_op_add = View(new_term.aluChip_alu_op_add); \ + [[maybe_unused]] auto aluChip_alu_op_sub = View(new_term.aluChip_alu_op_sub); \ + [[maybe_unused]] auto aluChip_alu_op_mul = View(new_term.aluChip_alu_op_mul); \ + [[maybe_unused]] auto aluChip_alu_op_div = View(new_term.aluChip_alu_op_div); \ + [[maybe_unused]] auto aluChip_alu_op_not = View(new_term.aluChip_alu_op_not); \ + [[maybe_unused]] auto aluChip_alu_op_eq = View(new_term.aluChip_alu_op_eq); \ + [[maybe_unused]] auto aluChip_alu_ff_tag = View(new_term.aluChip_alu_ff_tag); \ + [[maybe_unused]] auto aluChip_alu_u8_tag = View(new_term.aluChip_alu_u8_tag); \ + [[maybe_unused]] auto aluChip_alu_u16_tag = View(new_term.aluChip_alu_u16_tag); \ + [[maybe_unused]] auto aluChip_alu_u32_tag = View(new_term.aluChip_alu_u32_tag); \ + [[maybe_unused]] auto aluChip_alu_u64_tag = View(new_term.aluChip_alu_u64_tag); \ + [[maybe_unused]] auto aluChip_alu_u128_tag = View(new_term.aluChip_alu_u128_tag); \ + [[maybe_unused]] auto aluChip_alu_u8_r0 = View(new_term.aluChip_alu_u8_r0); \ + [[maybe_unused]] auto aluChip_alu_u8_r1 = View(new_term.aluChip_alu_u8_r1); \ + [[maybe_unused]] auto aluChip_alu_u16_r0 = View(new_term.aluChip_alu_u16_r0); \ + [[maybe_unused]] auto aluChip_alu_u16_r1 = View(new_term.aluChip_alu_u16_r1); \ + [[maybe_unused]] auto aluChip_alu_u16_r2 = View(new_term.aluChip_alu_u16_r2); \ + [[maybe_unused]] auto aluChip_alu_u16_r3 = View(new_term.aluChip_alu_u16_r3); \ + [[maybe_unused]] auto aluChip_alu_u16_r4 = View(new_term.aluChip_alu_u16_r4); \ + [[maybe_unused]] auto aluChip_alu_u16_r5 = View(new_term.aluChip_alu_u16_r5); \ + [[maybe_unused]] auto aluChip_alu_u16_r6 = View(new_term.aluChip_alu_u16_r6); \ + [[maybe_unused]] auto aluChip_alu_u16_r7 = View(new_term.aluChip_alu_u16_r7); \ + [[maybe_unused]] auto aluChip_alu_u64_r0 = View(new_term.aluChip_alu_u64_r0); \ + [[maybe_unused]] auto aluChip_alu_cf = View(new_term.aluChip_alu_cf); \ + [[maybe_unused]] auto aluChip_alu_inv_diff = View(new_term.aluChip_alu_inv_diff); \ + [[maybe_unused]] auto avmMini_pc = View(new_term.avmMini_pc); \ + [[maybe_unused]] auto avmMini_internal_return_ptr = View(new_term.avmMini_internal_return_ptr); \ + [[maybe_unused]] auto avmMini_sel_internal_call = View(new_term.avmMini_sel_internal_call); \ + [[maybe_unused]] auto avmMini_sel_internal_return = View(new_term.avmMini_sel_internal_return); \ + [[maybe_unused]] auto avmMini_sel_jump = View(new_term.avmMini_sel_jump); \ + [[maybe_unused]] auto avmMini_sel_halt = View(new_term.avmMini_sel_halt); \ + [[maybe_unused]] auto avmMini_sel_op_add = View(new_term.avmMini_sel_op_add); \ + [[maybe_unused]] auto avmMini_sel_op_sub = View(new_term.avmMini_sel_op_sub); \ + [[maybe_unused]] auto avmMini_sel_op_mul = View(new_term.avmMini_sel_op_mul); \ + [[maybe_unused]] auto avmMini_sel_op_div = View(new_term.avmMini_sel_op_div); \ + [[maybe_unused]] auto avmMini_sel_op_not = View(new_term.avmMini_sel_op_not); \ + [[maybe_unused]] auto avmMini_sel_op_eq = View(new_term.avmMini_sel_op_eq); \ + [[maybe_unused]] auto avmMini_in_tag = View(new_term.avmMini_in_tag); \ + [[maybe_unused]] auto avmMini_op_err = View(new_term.avmMini_op_err); \ + [[maybe_unused]] auto avmMini_tag_err = View(new_term.avmMini_tag_err); \ + [[maybe_unused]] auto avmMini_inv = View(new_term.avmMini_inv); \ + [[maybe_unused]] auto avmMini_ia = View(new_term.avmMini_ia); \ + [[maybe_unused]] auto avmMini_ib = View(new_term.avmMini_ib); \ + [[maybe_unused]] auto avmMini_ic = View(new_term.avmMini_ic); \ + [[maybe_unused]] auto avmMini_mem_op_a = View(new_term.avmMini_mem_op_a); \ + [[maybe_unused]] auto avmMini_mem_op_b = View(new_term.avmMini_mem_op_b); \ + [[maybe_unused]] auto avmMini_mem_op_c = View(new_term.avmMini_mem_op_c); \ + [[maybe_unused]] auto avmMini_rwa = View(new_term.avmMini_rwa); \ + [[maybe_unused]] auto avmMini_rwb = View(new_term.avmMini_rwb); \ + [[maybe_unused]] auto avmMini_rwc = View(new_term.avmMini_rwc); \ + [[maybe_unused]] auto avmMini_mem_idx_a = View(new_term.avmMini_mem_idx_a); \ + [[maybe_unused]] auto avmMini_mem_idx_b = View(new_term.avmMini_mem_idx_b); \ + [[maybe_unused]] auto avmMini_mem_idx_c = View(new_term.avmMini_mem_idx_c); \ + [[maybe_unused]] auto avmMini_last = View(new_term.avmMini_last); \ + [[maybe_unused]] auto 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_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_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_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/avm/avm_alu.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp index 9d14ec93e7f..f46c80ce482 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp @@ -7,67 +7,75 @@ namespace bb::Avm_vm { template struct Avm_aluRow { + FF avm_alu_alu_u64_tag{}; + FF avm_alu_alu_ic{}; + FF avm_alu_alu_ia{}; FF avm_alu_alu_ff_tag{}; - FF avm_alu_alu_u8_tag{}; - FF avm_alu_alu_u32_tag{}; - FF avm_alu_alu_u16_r6_shift{}; - FF avm_alu_alu_u16_tag{}; - FF avm_alu_alu_u16_r4{}; - FF avm_alu_alu_ib{}; - FF avm_alu_alu_u8_r0{}; - FF avm_alu_alu_op_not{}; - FF avm_alu_alu_u16_r7{}; FF avm_alu_alu_u128_tag{}; + FF avm_alu_alu_u16_tag{}; + FF avm_alu_alu_u16_r6_shift{}; + FF avm_alu_alu_u8_tag{}; FF avm_alu_alu_u16_r0{}; - FF avm_alu_alu_u16_r2{}; - FF avm_alu_alu_u16_r4_shift{}; - FF avm_alu_alu_cf{}; - FF avm_alu_alu_u16_r1_shift{}; + FF avm_alu_alu_op_sub{}; + FF avm_alu_alu_op_add{}; + FF avm_alu_alu_u16_r0_shift{}; FF avm_alu_alu_u16_r2_shift{}; - FF avm_alu_alu_u16_r3{}; - FF avm_alu_alu_ia{}; - FF avm_alu_alu_u16_r5{}; - FF avm_alu_alu_u16_r6{}; FF avm_alu_alu_u16_r7_shift{}; FF avm_alu_alu_u64_r0{}; - FF avm_alu_alu_u64_tag{}; - FF avm_alu_alu_op_add{}; + FF avm_alu_alu_u16_r7{}; + FF avm_alu_alu_u8_r0{}; + FF avm_alu_alu_u16_r2{}; + FF avm_alu_alu_op_eq{}; + FF avm_alu_alu_u16_r4{}; + FF avm_alu_alu_op_eq_diff_inv{}; + FF avm_alu_alu_ib{}; + FF avm_alu_alu_u16_r1{}; FF avm_alu_alu_u8_r1{}; - FF avm_alu_alu_u16_r0_shift{}; - FF avm_alu_alu_u16_r3_shift{}; FF avm_alu_alu_op_mul{}; + FF avm_alu_alu_u16_r6{}; + FF avm_alu_alu_u16_r3_shift{}; + FF avm_alu_alu_op_not{}; + FF avm_alu_alu_u16_r5{}; + FF avm_alu_alu_cf{}; + FF avm_alu_alu_u16_r1_shift{}; + FF avm_alu_alu_u32_tag{}; + FF avm_alu_alu_u16_r3{}; FF avm_alu_alu_u16_r5_shift{}; - FF avm_alu_alu_ic{}; - FF avm_alu_alu_op_sub{}; - FF avm_alu_alu_u16_r1{}; + FF avm_alu_alu_u16_r4_shift{}; }; inline std::string get_relation_label_avm_alu(int index) { switch (index) { - case 8: - return "ALU_MULTIPLICATION_FF"; + case 15: + return "ALU_OP_NOT"; + + case 7: + return "ALU_ADD_SUB_2"; case 10: return "ALU_MUL_COMMON_2"; - case 15: - return "ALU_OP_NOT"; + case 14: + return "ALU_FF_NOT_XOR"; + + case 9: + return "ALU_MUL_COMMON_1"; 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 16: + return "ALU_RES_IS_BOOL"; - case 14: - return "ALU_FF_NOT_XOR"; + case 17: + return "ALU_OP_EQ"; - case 7: - return "ALU_ADD_SUB_2"; + case 6: + return "ALU_ADD_SUB_1"; } return std::to_string(index); } @@ -76,8 +84,8 @@ template class avm_aluImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 6, 6, 8, 3, 4, + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 6, 6, 8, 3, 4, 4, 5, }; template @@ -300,6 +308,26 @@ template class avm_aluImpl { tmp *= scaling_factor; std::get<15>(evals) += tmp; } + // Contribution 16 + { + Avm_DECLARE_VIEWS(16); + + auto tmp = (avm_alu_alu_op_eq * (avm_alu_alu_ic * (-avm_alu_alu_ic + FF(1)))); + tmp *= scaling_factor; + std::get<16>(evals) += tmp; + } + // Contribution 17 + { + Avm_DECLARE_VIEWS(17); + + auto tmp = (avm_alu_alu_op_eq * + ((((avm_alu_alu_ia - avm_alu_alu_ib) * + ((avm_alu_alu_ic * (-avm_alu_alu_op_eq_diff_inv + FF(1))) + avm_alu_alu_op_eq_diff_inv)) - + FF(1)) + + avm_alu_alu_ic)); + tmp *= scaling_factor; + std::get<17>(evals) += tmp; + } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp index 304942fe8cd..40aef030283 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp @@ -7,62 +7,63 @@ namespace bb::Avm_vm { template struct Avm_mainRow { + FF avm_main_op_err{}; + FF avm_main_tag_err{}; + FF avm_main_sel_op_mul{}; + FF avm_main_mem_op_a{}; + FF avm_main_mem_idx_a{}; + FF avm_main_first{}; + FF avm_main_sel_jump{}; FF avm_main_sel_internal_return{}; + FF avm_main_rwa{}; + FF avm_main_mem_op_c{}; FF avm_main_rwc{}; - FF avm_main_ia{}; - FF avm_main_first{}; + FF avm_main_internal_return_ptr_shift{}; + FF avm_main_inv{}; + FF avm_main_rwb{}; + FF avm_main_mem_idx_b{}; FF avm_main_sel_op_sub{}; - FF avm_main_pc_shift{}; - FF avm_main_tag_err{}; + FF avm_main_sel_halt{}; + FF avm_main_ia{}; + FF avm_main_sel_op_div{}; + FF avm_main_pc{}; FF avm_main_ib{}; - FF avm_main_ic{}; - FF avm_main_mem_op_c{}; - FF avm_main_mem_idx_a{}; - FF avm_main_mem_idx_b{}; - FF avm_main_op_err{}; - FF avm_main_rwb{}; - FF avm_main_inv{}; - FF avm_main_sel_jump{}; FF avm_main_sel_op_not{}; - FF avm_main_sel_halt{}; + FF avm_main_internal_return_ptr{}; FF avm_main_sel_op_add{}; - FF avm_main_rwa{}; - FF avm_main_pc{}; - FF avm_main_sel_internal_call{}; - FF avm_main_sel_op_mul{}; - FF avm_main_sel_op_div{}; FF avm_main_mem_op_b{}; - FF avm_main_internal_return_ptr_shift{}; - FF avm_main_internal_return_ptr{}; - FF avm_main_mem_op_a{}; + FF avm_main_ic{}; + FF avm_main_sel_op_eq{}; + FF avm_main_sel_internal_call{}; + FF avm_main_pc_shift{}; }; inline std::string get_relation_label_avm_main(int index) { switch (index) { - case 36: - return "PC_INCREMENT"; - - case 20: + case 21: return "SUBOP_DIVISION_FF"; - case 25: - return "RETURN_POINTER_INCREMENT"; - - case 21: - return "SUBOP_DIVISION_ZERO_ERR1"; + case 38: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - case 31: + case 32: return "RETURN_POINTER_DECREMENT"; - case 37: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - case 23: - return "SUBOP_ERROR_RELEVANT_OP"; + return "SUBOP_DIVISION_ZERO_ERR2"; + + case 26: + return "RETURN_POINTER_INCREMENT"; + + case 37: + return "PC_INCREMENT"; case 22: - return "SUBOP_DIVISION_ZERO_ERR2"; + return "SUBOP_DIVISION_ZERO_ERR1"; + + case 24: + return "SUBOP_ERROR_RELEVANT_OP"; } return std::to_string(index); } @@ -71,8 +72,8 @@ template class avm_mainImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 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, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, }; @@ -127,7 +128,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(5); - auto tmp = (avm_main_sel_internal_call * (-avm_main_sel_internal_call + FF(1))); + auto tmp = (avm_main_sel_op_eq * (-avm_main_sel_op_eq + FF(1))); tmp *= scaling_factor; std::get<5>(evals) += tmp; } @@ -135,7 +136,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(6); - auto tmp = (avm_main_sel_internal_return * (-avm_main_sel_internal_return + FF(1))); + auto tmp = (avm_main_sel_internal_call * (-avm_main_sel_internal_call + FF(1))); tmp *= scaling_factor; std::get<6>(evals) += tmp; } @@ -143,7 +144,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(7); - auto tmp = (avm_main_sel_jump * (-avm_main_sel_jump + FF(1))); + auto tmp = (avm_main_sel_internal_return * (-avm_main_sel_internal_return + FF(1))); tmp *= scaling_factor; std::get<7>(evals) += tmp; } @@ -151,7 +152,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(8); - auto tmp = (avm_main_sel_halt * (-avm_main_sel_halt + FF(1))); + auto tmp = (avm_main_sel_jump * (-avm_main_sel_jump + FF(1))); tmp *= scaling_factor; std::get<8>(evals) += tmp; } @@ -159,7 +160,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(9); - auto tmp = (avm_main_op_err * (-avm_main_op_err + FF(1))); + auto tmp = (avm_main_sel_halt * (-avm_main_sel_halt + FF(1))); tmp *= scaling_factor; std::get<9>(evals) += tmp; } @@ -167,7 +168,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(10); - auto tmp = (avm_main_tag_err * (-avm_main_tag_err + FF(1))); + auto tmp = (avm_main_op_err * (-avm_main_op_err + FF(1))); tmp *= scaling_factor; std::get<10>(evals) += tmp; } @@ -175,7 +176,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(11); - auto tmp = (avm_main_mem_op_a * (-avm_main_mem_op_a + FF(1))); + auto tmp = (avm_main_tag_err * (-avm_main_tag_err + FF(1))); tmp *= scaling_factor; std::get<11>(evals) += tmp; } @@ -183,7 +184,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(12); - auto tmp = (avm_main_mem_op_b * (-avm_main_mem_op_b + FF(1))); + auto tmp = (avm_main_mem_op_a * (-avm_main_mem_op_a + FF(1))); tmp *= scaling_factor; std::get<12>(evals) += tmp; } @@ -191,7 +192,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(13); - auto tmp = (avm_main_mem_op_c * (-avm_main_mem_op_c + FF(1))); + auto tmp = (avm_main_mem_op_b * (-avm_main_mem_op_b + FF(1))); tmp *= scaling_factor; std::get<13>(evals) += tmp; } @@ -199,7 +200,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(14); - auto tmp = (avm_main_rwa * (-avm_main_rwa + FF(1))); + auto tmp = (avm_main_mem_op_c * (-avm_main_mem_op_c + FF(1))); tmp *= scaling_factor; std::get<14>(evals) += tmp; } @@ -207,7 +208,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(15); - auto tmp = (avm_main_rwb * (-avm_main_rwb + FF(1))); + auto tmp = (avm_main_rwa * (-avm_main_rwa + FF(1))); tmp *= scaling_factor; std::get<15>(evals) += tmp; } @@ -215,7 +216,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(16); - auto tmp = (avm_main_rwc * (-avm_main_rwc + FF(1))); + auto tmp = (avm_main_rwb * (-avm_main_rwb + FF(1))); tmp *= scaling_factor; std::get<16>(evals) += tmp; } @@ -223,7 +224,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(17); - auto tmp = (avm_main_tag_err * avm_main_ia); + auto tmp = (avm_main_rwc * (-avm_main_rwc + FF(1))); tmp *= scaling_factor; std::get<17>(evals) += tmp; } @@ -231,7 +232,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(18); - auto tmp = (avm_main_tag_err * avm_main_ib); + auto tmp = (avm_main_tag_err * avm_main_ia); tmp *= scaling_factor; std::get<18>(evals) += tmp; } @@ -239,7 +240,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(19); - auto tmp = (avm_main_tag_err * avm_main_ic); + auto tmp = (avm_main_tag_err * avm_main_ib); tmp *= scaling_factor; std::get<19>(evals) += tmp; } @@ -247,8 +248,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(20); - auto tmp = - ((avm_main_sel_op_div * (-avm_main_op_err + FF(1))) * ((avm_main_ic * avm_main_ib) - avm_main_ia)); + auto tmp = (avm_main_tag_err * avm_main_ic); tmp *= scaling_factor; std::get<20>(evals) += tmp; } @@ -256,7 +256,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(21); - auto tmp = (avm_main_sel_op_div * (((avm_main_ib * avm_main_inv) - FF(1)) + avm_main_op_err)); + auto tmp = + ((avm_main_sel_op_div * (-avm_main_op_err + FF(1))) * ((avm_main_ic * avm_main_ib) - avm_main_ia)); tmp *= scaling_factor; std::get<21>(evals) += tmp; } @@ -264,7 +265,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(22); - auto tmp = ((avm_main_sel_op_div * avm_main_op_err) * (-avm_main_inv + FF(1))); + auto tmp = (avm_main_sel_op_div * (((avm_main_ib * avm_main_inv) - FF(1)) + avm_main_op_err)); tmp *= scaling_factor; std::get<22>(evals) += tmp; } @@ -272,7 +273,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(23); - auto tmp = (avm_main_op_err * (avm_main_sel_op_div - FF(1))); + auto tmp = ((avm_main_sel_op_div * avm_main_op_err) * (-avm_main_inv + FF(1))); tmp *= scaling_factor; std::get<23>(evals) += tmp; } @@ -280,7 +281,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(24); - auto tmp = (avm_main_sel_jump * (avm_main_pc_shift - avm_main_ia)); + auto tmp = (avm_main_op_err * (avm_main_sel_op_div - FF(1))); tmp *= scaling_factor; std::get<24>(evals) += tmp; } @@ -288,8 +289,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(25); - auto tmp = (avm_main_sel_internal_call * - (avm_main_internal_return_ptr_shift - (avm_main_internal_return_ptr + FF(1)))); + auto tmp = (avm_main_sel_jump * (avm_main_pc_shift - avm_main_ia)); tmp *= scaling_factor; std::get<25>(evals) += tmp; } @@ -297,7 +297,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(26); - auto tmp = (avm_main_sel_internal_call * (avm_main_internal_return_ptr - avm_main_mem_idx_b)); + auto tmp = (avm_main_sel_internal_call * + (avm_main_internal_return_ptr_shift - (avm_main_internal_return_ptr + FF(1)))); tmp *= scaling_factor; std::get<26>(evals) += tmp; } @@ -305,7 +306,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(27); - auto tmp = (avm_main_sel_internal_call * (avm_main_pc_shift - avm_main_ia)); + auto tmp = (avm_main_sel_internal_call * (avm_main_internal_return_ptr - avm_main_mem_idx_b)); tmp *= scaling_factor; std::get<27>(evals) += tmp; } @@ -313,7 +314,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(28); - auto tmp = (avm_main_sel_internal_call * ((avm_main_pc + FF(1)) - avm_main_ib)); + auto tmp = (avm_main_sel_internal_call * (avm_main_pc_shift - avm_main_ia)); tmp *= scaling_factor; std::get<28>(evals) += tmp; } @@ -321,7 +322,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(29); - auto tmp = (avm_main_sel_internal_call * (avm_main_rwb - FF(1))); + auto tmp = (avm_main_sel_internal_call * ((avm_main_pc + FF(1)) - avm_main_ib)); tmp *= scaling_factor; std::get<29>(evals) += tmp; } @@ -329,7 +330,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(30); - auto tmp = (avm_main_sel_internal_call * (avm_main_mem_op_b - FF(1))); + auto tmp = (avm_main_sel_internal_call * (avm_main_rwb - FF(1))); tmp *= scaling_factor; std::get<30>(evals) += tmp; } @@ -337,8 +338,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(31); - auto tmp = (avm_main_sel_internal_return * - (avm_main_internal_return_ptr_shift - (avm_main_internal_return_ptr - FF(1)))); + auto tmp = (avm_main_sel_internal_call * (avm_main_mem_op_b - FF(1))); tmp *= scaling_factor; std::get<31>(evals) += tmp; } @@ -346,7 +346,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(32); - auto tmp = (avm_main_sel_internal_return * ((avm_main_internal_return_ptr - FF(1)) - avm_main_mem_idx_a)); + auto tmp = (avm_main_sel_internal_return * + (avm_main_internal_return_ptr_shift - (avm_main_internal_return_ptr - FF(1)))); tmp *= scaling_factor; std::get<32>(evals) += tmp; } @@ -354,7 +355,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(33); - auto tmp = (avm_main_sel_internal_return * (avm_main_pc_shift - avm_main_ia)); + auto tmp = (avm_main_sel_internal_return * ((avm_main_internal_return_ptr - FF(1)) - avm_main_mem_idx_a)); tmp *= scaling_factor; std::get<33>(evals) += tmp; } @@ -362,7 +363,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(34); - auto tmp = (avm_main_sel_internal_return * avm_main_rwa); + auto tmp = (avm_main_sel_internal_return * (avm_main_pc_shift - avm_main_ia)); tmp *= scaling_factor; std::get<34>(evals) += tmp; } @@ -370,7 +371,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(35); - auto tmp = (avm_main_sel_internal_return * (avm_main_mem_op_a - FF(1))); + auto tmp = (avm_main_sel_internal_return * avm_main_rwa); tmp *= scaling_factor; std::get<35>(evals) += tmp; } @@ -378,10 +379,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(36); - auto tmp = ((((-avm_main_first + FF(1)) * (-avm_main_sel_halt + FF(1))) * - ((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_div) + avm_main_sel_op_mul) + - avm_main_sel_op_not)) * - (avm_main_pc_shift - (avm_main_pc + FF(1)))); + auto tmp = (avm_main_sel_internal_return * (avm_main_mem_op_a - FF(1))); tmp *= scaling_factor; std::get<36>(evals) += tmp; } @@ -389,12 +387,24 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(37); + auto tmp = ((((-avm_main_first + FF(1)) * (-avm_main_sel_halt + FF(1))) * + (((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_div) + avm_main_sel_op_mul) + + avm_main_sel_op_not) + + avm_main_sel_op_eq)) * + (avm_main_pc_shift - (avm_main_pc + FF(1)))); + tmp *= scaling_factor; + std::get<37>(evals) += tmp; + } + // Contribution 38 + { + Avm_DECLARE_VIEWS(38); + auto tmp = ((-(((avm_main_first + avm_main_sel_internal_call) + avm_main_sel_internal_return) + avm_main_sel_halt) + FF(1)) * (avm_main_internal_return_ptr_shift - avm_main_internal_return_ptr)); tmp *= scaling_factor; - std::get<37>(evals) += tmp; + std::get<38>(evals) += tmp; } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp index eefca81ba77..fe909be0a47 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp @@ -8,40 +8,40 @@ namespace bb::Avm_vm { template struct Avm_memRow { FF avm_mem_m_rw_shift{}; - FF avm_mem_m_addr_shift{}; - FF avm_mem_m_addr{}; - FF avm_mem_m_val_shift{}; - FF avm_mem_m_tag{}; FF avm_mem_m_rw{}; - FF avm_mem_m_last{}; - FF avm_mem_m_tag_err{}; FF avm_mem_m_val{}; + FF avm_mem_m_tag_shift{}; + FF avm_mem_m_val_shift{}; + FF avm_mem_m_tag{}; FF avm_mem_m_in_tag{}; + FF avm_mem_m_last{}; FF avm_mem_m_one_min_inv{}; + FF avm_mem_m_addr_shift{}; FF avm_mem_m_lastAccess{}; - FF avm_mem_m_tag_shift{}; + FF avm_mem_m_tag_err{}; + FF avm_mem_m_addr{}; }; inline std::string get_relation_label_avm_mem(int index) { switch (index) { - case 8: - return "MEM_IN_TAG_CONSISTENCY_1"; + case 7: + return "MEM_ZERO_INIT"; 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 9: return "MEM_IN_TAG_CONSISTENCY_2"; case 6: return "MEM_READ_WRITE_TAG_CONSISTENCY"; + + case 5: + return "MEM_READ_WRITE_VAL_CONSISTENCY"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp index d428a3c96f6..d16fe0b41e1 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp @@ -24,6 +24,7 @@ [[maybe_unused]] auto avm_alu_alu_op_mul = View(new_term.avm_alu_alu_op_mul); \ [[maybe_unused]] auto avm_alu_alu_op_div = View(new_term.avm_alu_alu_op_div); \ [[maybe_unused]] auto avm_alu_alu_op_not = View(new_term.avm_alu_alu_op_not); \ + [[maybe_unused]] auto avm_alu_alu_op_eq = View(new_term.avm_alu_alu_op_eq); \ [[maybe_unused]] auto avm_alu_alu_ff_tag = View(new_term.avm_alu_alu_ff_tag); \ [[maybe_unused]] auto avm_alu_alu_u8_tag = View(new_term.avm_alu_alu_u8_tag); \ [[maybe_unused]] auto avm_alu_alu_u16_tag = View(new_term.avm_alu_alu_u16_tag); \ @@ -42,6 +43,7 @@ [[maybe_unused]] auto avm_alu_alu_u16_r7 = View(new_term.avm_alu_alu_u16_r7); \ [[maybe_unused]] auto avm_alu_alu_u64_r0 = View(new_term.avm_alu_alu_u64_r0); \ [[maybe_unused]] auto avm_alu_alu_cf = View(new_term.avm_alu_alu_cf); \ + [[maybe_unused]] auto avm_alu_alu_op_eq_diff_inv = View(new_term.avm_alu_alu_op_eq_diff_inv); \ [[maybe_unused]] auto avm_main_pc = View(new_term.avm_main_pc); \ [[maybe_unused]] auto avm_main_internal_return_ptr = View(new_term.avm_main_internal_return_ptr); \ [[maybe_unused]] auto avm_main_sel_internal_call = View(new_term.avm_main_sel_internal_call); \ @@ -53,6 +55,7 @@ [[maybe_unused]] auto avm_main_sel_op_mul = View(new_term.avm_main_sel_op_mul); \ [[maybe_unused]] auto avm_main_sel_op_div = View(new_term.avm_main_sel_op_div); \ [[maybe_unused]] auto avm_main_sel_op_not = View(new_term.avm_main_sel_op_not); \ + [[maybe_unused]] auto avm_main_sel_op_eq = View(new_term.avm_main_sel_op_eq); \ [[maybe_unused]] auto avm_main_in_tag = View(new_term.avm_main_in_tag); \ [[maybe_unused]] auto avm_main_op_err = View(new_term.avm_main_op_err); \ [[maybe_unused]] auto avm_main_tag_err = View(new_term.avm_main_tag_err); \ @@ -70,17 +73,17 @@ [[maybe_unused]] auto avm_main_mem_idx_b = View(new_term.avm_main_mem_idx_b); \ [[maybe_unused]] auto avm_main_mem_idx_c = View(new_term.avm_main_mem_idx_c); \ [[maybe_unused]] auto avm_main_last = View(new_term.avm_main_last); \ - [[maybe_unused]] auto avm_main_pc_shift = View(new_term.avm_main_pc_shift); \ - [[maybe_unused]] auto avm_main_internal_return_ptr_shift = View(new_term.avm_main_internal_return_ptr_shift); \ [[maybe_unused]] auto avm_mem_m_rw_shift = View(new_term.avm_mem_m_rw_shift); \ - [[maybe_unused]] auto avm_mem_m_addr_shift = View(new_term.avm_mem_m_addr_shift); \ - [[maybe_unused]] auto avm_mem_m_val_shift = View(new_term.avm_mem_m_val_shift); \ [[maybe_unused]] auto avm_mem_m_tag_shift = View(new_term.avm_mem_m_tag_shift); \ + [[maybe_unused]] auto avm_mem_m_val_shift = View(new_term.avm_mem_m_val_shift); \ + [[maybe_unused]] auto avm_mem_m_addr_shift = View(new_term.avm_mem_m_addr_shift); \ + [[maybe_unused]] auto avm_main_internal_return_ptr_shift = View(new_term.avm_main_internal_return_ptr_shift); \ + [[maybe_unused]] auto avm_main_pc_shift = View(new_term.avm_main_pc_shift); \ [[maybe_unused]] auto avm_alu_alu_u16_r6_shift = View(new_term.avm_alu_alu_u16_r6_shift); \ - [[maybe_unused]] auto avm_alu_alu_u16_r4_shift = View(new_term.avm_alu_alu_u16_r4_shift); \ - [[maybe_unused]] auto avm_alu_alu_u16_r1_shift = View(new_term.avm_alu_alu_u16_r1_shift); \ + [[maybe_unused]] auto avm_alu_alu_u16_r0_shift = View(new_term.avm_alu_alu_u16_r0_shift); \ [[maybe_unused]] auto avm_alu_alu_u16_r2_shift = View(new_term.avm_alu_alu_u16_r2_shift); \ [[maybe_unused]] auto avm_alu_alu_u16_r7_shift = View(new_term.avm_alu_alu_u16_r7_shift); \ - [[maybe_unused]] auto avm_alu_alu_u16_r0_shift = View(new_term.avm_alu_alu_u16_r0_shift); \ [[maybe_unused]] auto avm_alu_alu_u16_r3_shift = View(new_term.avm_alu_alu_u16_r3_shift); \ - [[maybe_unused]] auto avm_alu_alu_u16_r5_shift = View(new_term.avm_alu_alu_u16_r5_shift); + [[maybe_unused]] auto avm_alu_alu_u16_r1_shift = View(new_term.avm_alu_alu_u16_r1_shift); \ + [[maybe_unused]] auto avm_alu_alu_u16_r5_shift = View(new_term.avm_alu_alu_u16_r5_shift); \ + [[maybe_unused]] auto avm_alu_alu_u16_r4_shift = View(new_term.avm_alu_alu_u16_r4_shift); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp index a3ccf09b886..65371cffbe3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp @@ -395,4 +395,40 @@ FF AvmAluTraceBuilder::op_not(FF const& a, AvmMemoryTag in_tag, uint32_t const c return c; } +/** + * @brief Build Alu trace and return a boolean based on equality of operands of type defined by in_tag. + * + * @param a Left operand of the equality + * @param b Right operand of the equality + * @param in_tag Instruction tag defining the number of bits for equality + * @param clk Clock referring to the operation in the main trace. + * + * @return FF The boolean result of equality casted to a finite field element + */ + +FF AvmAluTraceBuilder::op_eq(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t const clk) +{ + FF c = a - b; + // Don't invert 0 as it will throw + FF inv_c = c != FF::zero() ? c.invert() : FF::zero(); + FF res = c == FF::zero() ? FF::one() : FF::zero(); + + alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ + .alu_clk = clk, + .alu_op_eq = 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 = res, + .alu_op_eq_diff_inv = inv_c, + }); + + return res; +} + } // namespace avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp index cde22e2b14b..7505a1f5030 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp @@ -14,6 +14,7 @@ class AvmAluTraceBuilder { bool alu_op_sub = false; bool alu_op_mul = false; bool alu_op_not = false; + bool alu_op_eq = false; bool alu_ff_tag = false; bool alu_u8_tag = false; @@ -34,6 +35,8 @@ class AvmAluTraceBuilder { std::array alu_u16_reg{}; uint64_t alu_u64_r0{}; + + FF alu_op_eq_diff_inv{}; }; AvmAluTraceBuilder(); @@ -44,6 +47,7 @@ class AvmAluTraceBuilder { FF op_sub(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t clk); FF op_mul(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t clk); FF op_not(FF const& a, AvmMemoryTag in_tag, uint32_t clk); + FF op_eq(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/avm_deserialization.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp index 7a3fe0198ff..f47680adc04 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp @@ -29,6 +29,8 @@ const std::unordered_map> OPCODE_WIRE_FORMAT = { OpCode::SUB, three_operand_format }, { OpCode::MUL, three_operand_format }, { OpCode::DIV, three_operand_format }, + // Compute - Comparators + { OpCode::EQ, three_operand_format }, // Compute - Bitwise { OpCode::NOT, { OperandType::TAG, OperandType::UINT32, OperandType::UINT32 } }, // Execution Environment - Calldata diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp index 53e73e53ee9..0de230ff0de 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp @@ -644,6 +644,7 @@ std::vector AvmTraceBuilder::finalize() dest.avm_alu_alu_op_sub = FF(static_cast(src.alu_op_sub)); dest.avm_alu_alu_op_mul = FF(static_cast(src.alu_op_mul)); dest.avm_alu_alu_op_not = FF(static_cast(src.alu_op_not)); + dest.avm_alu_alu_op_eq = FF(static_cast(src.alu_op_eq)); dest.avm_alu_alu_ff_tag = FF(static_cast(src.alu_ff_tag)); dest.avm_alu_alu_u8_tag = FF(static_cast(src.alu_u8_tag)); @@ -671,6 +672,7 @@ std::vector AvmTraceBuilder::finalize() dest.avm_alu_alu_u16_r7 = FF(src.alu_u16_reg.at(7)); dest.avm_alu_alu_u64_r0 = FF(src.alu_u64_r0); + dest.avm_alu_alu_op_eq_diff_inv = FF(src.alu_op_eq_diff_inv); } // Adding extra row for the shifted values at the top of the execution trace. @@ -698,7 +700,8 @@ void AvmTraceBuilder::op_not(uint32_t a_offset, uint32_t dst_offset, AvmMemoryTa auto read_a = mem_trace_builder.read_and_load_from_memory(clk, IntermRegister::IA, a_offset, in_tag); // ~a = c - FF c = alu_trace_builder.op_not(read_a.val, in_tag, clk); + FF a = read_a.tag_match ? read_a.val : FF(0); + FF c = alu_trace_builder.op_not(a, 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); @@ -709,7 +712,8 @@ void AvmTraceBuilder::op_not(uint32_t a_offset, uint32_t dst_offset, AvmMemoryTa .avm_main_internal_return_ptr = FF(internal_return_ptr), .avm_main_sel_op_not = FF(1), .avm_main_in_tag = FF(static_cast(in_tag)), - .avm_main_ia = read_a.val, + .avm_main_tag_err = FF(static_cast(!read_a.tag_match)), + .avm_main_ia = a, .avm_main_ic = c, .avm_main_mem_op_a = FF(1), .avm_main_mem_op_c = FF(1), @@ -719,4 +723,48 @@ void AvmTraceBuilder::op_not(uint32_t a_offset, uint32_t dst_offset, AvmMemoryTa }); }; +/** + * @brief Equality with direct memory access. + * + * @param a_offset An index in memory pointing to the first operand of the equality. + * @param b_offset An index in memory pointing to the second operand of the equality. + * @param dst_offset An index in memory pointing to the output of the equality. + * @param in_tag The instruction memory tag of the operands. + */ +void AvmTraceBuilder::op_eq(uint32_t a_offset, uint32_t b_offset, uint32_t dst_offset, AvmMemoryTag in_tag) +{ + 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); + bool tag_match = read_a.tag_match && read_b.tag_match; + + // c = a == b ? 1 : 0 + FF a = tag_match ? read_a.val : FF(0); + FF b = tag_match ? read_b.val : FF(0); + FF c = alu_trace_builder.op_eq(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); + + main_trace.push_back(Row{ + .avm_main_clk = clk, + .avm_main_pc = FF(pc++), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_sel_op_eq = FF(1), + .avm_main_in_tag = FF(static_cast(in_tag)), + .avm_main_tag_err = FF(static_cast(!tag_match)), + .avm_main_ia = a, + .avm_main_ib = b, + .avm_main_ic = c, + .avm_main_mem_op_a = FF(1), + .avm_main_mem_op_b = FF(1), + .avm_main_mem_op_c = FF(1), + .avm_main_rwc = FF(1), + .avm_main_mem_idx_a = FF(a_offset), + .avm_main_mem_idx_b = FF(b_offset), + .avm_main_mem_idx_c = FF(dst_offset), + }); +} } // namespace avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp index 5a4e389e41a..d205c98214d 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp @@ -43,6 +43,9 @@ class AvmTraceBuilder { // Bitwise not with direct memory access. void op_not(uint32_t a_offset, uint32_t dst_offset, AvmMemoryTag in_tag); + // Equality with direct memory access. + void op_eq(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); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp index 46fe5e32c86..6229a31ad1b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp @@ -82,6 +82,8 @@ bool AvmVerifier::verify_proof(const HonkProof& proof) transcript->template receive_from_prover(commitment_labels.avm_alu_alu_op_div); commitments.avm_alu_alu_op_not = transcript->template receive_from_prover(commitment_labels.avm_alu_alu_op_not); + commitments.avm_alu_alu_op_eq = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_op_eq); commitments.avm_alu_alu_ff_tag = transcript->template receive_from_prover(commitment_labels.avm_alu_alu_ff_tag); commitments.avm_alu_alu_u8_tag = @@ -117,6 +119,8 @@ bool AvmVerifier::verify_proof(const HonkProof& proof) commitments.avm_alu_alu_u64_r0 = transcript->template receive_from_prover(commitment_labels.avm_alu_alu_u64_r0); commitments.avm_alu_alu_cf = transcript->template receive_from_prover(commitment_labels.avm_alu_alu_cf); + commitments.avm_alu_alu_op_eq_diff_inv = + transcript->template receive_from_prover(commitment_labels.avm_alu_alu_op_eq_diff_inv); commitments.avm_main_pc = transcript->template receive_from_prover(commitment_labels.avm_main_pc); commitments.avm_main_internal_return_ptr = transcript->template receive_from_prover(commitment_labels.avm_main_internal_return_ptr); @@ -138,6 +142,8 @@ bool AvmVerifier::verify_proof(const HonkProof& proof) transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_div); commitments.avm_main_sel_op_not = transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_not); + commitments.avm_main_sel_op_eq = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_eq); commitments.avm_main_in_tag = transcript->template receive_from_prover(commitment_labels.avm_main_in_tag); commitments.avm_main_op_err = diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp index d7b8816bf22..71178fbf277 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp @@ -128,6 +128,34 @@ size_t common_validate_mul(std::vector const& trace, return static_cast(alu_row - trace.begin()); } +size_t common_validate_eq(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 equality selector + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_eq == FF(1); }); + + // Find the corresponding Alu trace row + auto clk = row->avm_main_clk; + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_alu_clk == clk; }); + + // Check that both rows were found + EXPECT_TRUE(row != trace.end()); + 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 equality selector is set. + EXPECT_EQ(row->avm_main_sel_op_eq, FF(1)); + EXPECT_EQ(alu_row->avm_alu_alu_op_eq, FF(1)); + + 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 @@ -183,6 +211,34 @@ std::vector gen_mutated_trace_mul(FF const& a, FF const& b, FF const& c_mut return trace; } +// This function generates a mutated trace of an equality check where a and b are the passed inputs. +// a and b are stored in memory indices 0 and 1 and c contains the boolean value of the equality check. +// Here we mutate c to be an incorrect evaluation of the equality and the memory and alu trace are +// created consistently with the wrong value c_mutated. +// Additionally, we can also mutate the value stored in inv_diff where inv_diff is (a - b)^-1 +std::vector gen_mutated_trace_eq( + FF const& a, FF const& b, FF const& c_mutated, FF const& mutated_inv_diff, avm_trace::AvmMemoryTag tag) +{ + auto trace_builder = avm_trace::AvmTraceBuilder(); + trace_builder.set(uint128_t{ a }, 0, tag); + trace_builder.set(uint128_t{ b }, 1, tag); + trace_builder.op_eq(0, 1, 2, tag); + trace_builder.halt(); + auto trace = trace_builder.finalize(); + + auto select_row = [](Row r) { return r.avm_main_sel_op_eq == FF(1); }; + mutate_ic_in_trace(trace, select_row, c_mutated, true); + + auto main_trace_row = std::ranges::find_if(trace.begin(), trace.end(), select_row); + auto main_clk = main_trace_row->avm_main_clk; + auto alu_row = + std::ranges::find_if(trace.begin(), trace.end(), [main_clk](Row r) { return r.avm_alu_alu_clk == main_clk; }); + + main_trace_row->avm_alu_alu_op_eq_diff_inv = mutated_inv_diff; + alu_row->avm_alu_alu_op_eq_diff_inv = mutated_inv_diff; + + return trace; +} } // anonymous namespace namespace tests_avm { @@ -441,6 +497,41 @@ TEST_F(AvmArithmeticTestsFF, mixedOperationsWithError) validate_trace_proof(std::move(trace)); } +// Test of equality on FF elements +TEST_F(AvmArithmeticTestsFF, equality) +{ + // Pick a field-sized number + FF elem = FF::modulus - FF(1); + trace_builder.calldata_copy(0, 3, 0, std::vector{ elem, elem, 1 }); + trace_builder.op_eq(0, 1, 2, AvmMemoryTag::FF); // Memory Layout [q - 1, q -1, 1,0..] + trace_builder.return_op(0, 3); + auto trace = trace_builder.finalize(); + + auto alu_row_index = common_validate_eq(trace, elem, elem, FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::FF); + auto alu_row = trace.at(alu_row_index); + + EXPECT_EQ(alu_row.avm_alu_alu_ff_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_op_eq_diff_inv, FF(0)); // Expect 0 as inv of (q-1) - (q-1) + validate_trace_proof(std::move(trace)); +} + +// Test correct non-equality of FF elements +TEST_F(AvmArithmeticTestsFF, nonEquality) +{ + FF elem = FF::modulus - FF(1); + trace_builder.calldata_copy(0, 3, 0, std::vector{ elem, elem + FF(1), 0 }); + trace_builder.op_eq(0, 1, 2, AvmMemoryTag::FF); // Memory Layout [q - 1, q, 1,0..] + trace_builder.return_op(0, 3); + auto trace = trace_builder.finalize(); + + auto alu_row_index = common_validate_eq(trace, elem, FF(0), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::FF); + auto alu_row = trace.at(alu_row_index); + + EXPECT_EQ(alu_row.avm_alu_alu_ff_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_op_eq_diff_inv, FF(-1).invert()); + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * Positive Tests - U8 ******************************************************************************/ @@ -585,6 +676,40 @@ TEST_F(AvmArithmeticTestsU8, multiplicationOverflow) validate_trace_proof(std::move(trace)); } +// Test of equality on u8 elements +TEST_F(AvmArithmeticTestsU8, equality) +{ + trace_builder.set(128, 0, AvmMemoryTag::U8); + trace_builder.set(128, 1, AvmMemoryTag::U8); + trace_builder.op_eq(0, 1, 2, AvmMemoryTag::U8); // Memory layout: [128,128,1,0,..,0] + trace_builder.return_op(0, 3); + auto trace = trace_builder.finalize(); + + auto alu_row_index = common_validate_eq(trace, FF(128), FF(128), FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::U8); + auto alu_row = trace.at(alu_row_index); + + EXPECT_EQ(alu_row.avm_alu_alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_op_eq_diff_inv, FF(0)); + validate_trace_proof(std::move(trace)); +} + +// Test correct non-equality of U8 elements +TEST_F(AvmArithmeticTestsU8, nonEquality) +{ + trace_builder.set(84, 0, AvmMemoryTag::U8); + trace_builder.set(200, 1, AvmMemoryTag::U8); + trace_builder.op_eq(0, 1, 2, AvmMemoryTag::U8); // Memory layout: [84,200,0,0,..,0] + trace_builder.return_op(0, 3); + auto trace = trace_builder.finalize(); + + auto alu_row_index = common_validate_eq(trace, 84, 200, FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::U8); + auto alu_row = trace.at(alu_row_index); + + EXPECT_EQ(alu_row.avm_alu_alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_op_eq_diff_inv, FF(-116).invert()); + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * Positive Tests - U16 ******************************************************************************/ @@ -737,6 +862,40 @@ TEST_F(AvmArithmeticTestsU16, multiplicationOverflow) validate_trace_proof(std::move(trace)); } +// Test of equality on U16 elements +TEST_F(AvmArithmeticTestsU16, equality) +{ + trace_builder.set(35823, 0, AvmMemoryTag::U16); + trace_builder.set(35823, 1, AvmMemoryTag::U16); + trace_builder.op_eq(0, 1, 2, AvmMemoryTag::U16); + trace_builder.return_op(0, 3); + auto trace = trace_builder.finalize(); + + auto alu_row_index = common_validate_eq(trace, FF(35823), FF(35823), FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::U16); + auto alu_row = trace.at(alu_row_index); + + EXPECT_EQ(alu_row.avm_alu_alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_op_eq_diff_inv, FF(0)); + validate_trace_proof(std::move(trace)); +} + +// Test correct non-equality of U16 elements +TEST_F(AvmArithmeticTestsU16, nonEquality) +{ + trace_builder.set(35'823, 0, AvmMemoryTag::U16); + trace_builder.set(50'123, 1, AvmMemoryTag::U16); + trace_builder.op_eq(0, 1, 2, AvmMemoryTag::U16); + trace_builder.return_op(0, 3); + auto trace = trace_builder.finalize(); + + auto alu_row_index = common_validate_eq(trace, 35'823, 50'123, FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::U16); + auto alu_row = trace.at(alu_row_index); + + EXPECT_EQ(alu_row.avm_alu_alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_op_eq_diff_inv, FF(-14'300).invert()); + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * Positive Tests - U32 ******************************************************************************/ @@ -902,6 +1061,42 @@ TEST_F(AvmArithmeticTestsU32, multiplicationOverflow) validate_trace_proof(std::move(trace)); } +// Test of equality on U32 elements +TEST_F(AvmArithmeticTestsU32, equality) +{ + trace_builder.set(0xb435e9c1, 0, AvmMemoryTag::U32); + trace_builder.set(0xb435e9c1, 1, AvmMemoryTag::U32); + trace_builder.op_eq(0, 1, 2, AvmMemoryTag::U32); + trace_builder.return_op(0, 3); + auto trace = trace_builder.finalize(); + + auto alu_row_index = + common_validate_eq(trace, 0xb435e9c1, 0xb435e9c1, FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::U32); + auto alu_row = trace.at(alu_row_index); + + EXPECT_EQ(alu_row.avm_alu_alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_op_eq_diff_inv, FF(0)); + validate_trace_proof(std::move(trace)); +} + +// Test correct non-equality of U32 elements +TEST_F(AvmArithmeticTestsU32, nonEquality) +{ + trace_builder.set(0xb435e9c1, 0, AvmMemoryTag::U32); + trace_builder.set(0xb435e9c0, 1, AvmMemoryTag::U32); + trace_builder.op_eq(0, 1, 2, AvmMemoryTag::U32); + trace_builder.return_op(0, 3); + auto trace = trace_builder.finalize(); + + auto alu_row_index = + common_validate_eq(trace, 0xb435e9c1, 0xb435e9c0, FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::U32); + auto alu_row = trace.at(alu_row_index); + + EXPECT_EQ(alu_row.avm_alu_alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_op_eq_diff_inv, FF(1).invert()); + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * Positive Tests - U64 ******************************************************************************/ @@ -1092,6 +1287,41 @@ TEST_F(AvmArithmeticTestsU64, multiplicationOverflow) validate_trace_proof(std::move(trace)); } +TEST_F(AvmArithmeticTestsU64, equality) +{ + trace_builder.set(0xffffffffffffffe0LLU, 0, AvmMemoryTag::U64); + trace_builder.set(0xffffffffffffffe0LLU, 1, AvmMemoryTag::U64); + trace_builder.op_eq(0, 1, 2, AvmMemoryTag::U64); + trace_builder.return_op(0, 3); + auto trace = trace_builder.finalize(); + + auto alu_row_index = common_validate_eq( + trace, 0xffffffffffffffe0LLU, 0xffffffffffffffe0LLU, FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::U64); + auto alu_row = trace.at(alu_row_index); + + EXPECT_EQ(alu_row.avm_alu_alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_op_eq_diff_inv, FF(0)); + validate_trace_proof(std::move(trace)); +} + +// Test correct non-equality of U64 elements +TEST_F(AvmArithmeticTestsU64, nonEquality) +{ + trace_builder.set(0xffffffffffffffe0LLU, 0, AvmMemoryTag::U64); + trace_builder.set(0xffffffffffaeffe0LLU, 1, AvmMemoryTag::U64); + trace_builder.op_eq(0, 1, 2, AvmMemoryTag::U64); + trace_builder.return_op(0, 3); + auto trace = trace_builder.finalize(); + + auto alu_row_index = common_validate_eq( + trace, 0xffffffffffffffe0LLU, 0xffffffffffaeffe0LLU, FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::U64); + auto alu_row = trace.at(alu_row_index); + + EXPECT_EQ(alu_row.avm_alu_alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_op_eq_diff_inv, FF(0x510000).invert()); + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * Positive Tests - U128 ******************************************************************************/ @@ -1351,6 +1581,56 @@ TEST_F(AvmArithmeticTestsU128, multiplicationOverflow) validate_trace_proof(std::move(trace)); } +TEST_F(AvmArithmeticTestsU128, equality) +{ + uint128_t const elem = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; + trace_builder.set(elem, 0, AvmMemoryTag::U128); + trace_builder.set(elem, 1, AvmMemoryTag::U128); + trace_builder.op_eq(0, 1, 2, AvmMemoryTag::U128); + trace_builder.return_op(0, 3); + auto trace = trace_builder.finalize(); + + auto alu_row_index = common_validate_eq(trace, + FF(uint256_t::from_uint128(elem)), + FF(uint256_t::from_uint128(elem)), + FF(1), + FF(0), + FF(1), + FF(2), + AvmMemoryTag::U128); + auto alu_row = trace.at(alu_row_index); + + EXPECT_EQ(alu_row.avm_alu_alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_op_eq_diff_inv, FF(0)); + validate_trace_proof(std::move(trace)); +} + +// Test correct non-equality of U128 elements +TEST_F(AvmArithmeticTestsU128, nonEquality) +{ + uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; + uint128_t const b = a - (0xdeadbeefLLU << 32); + trace_builder.set(a, 0, AvmMemoryTag::U128); + trace_builder.set(b, 1, AvmMemoryTag::U128); + trace_builder.op_eq(0, 1, 2, AvmMemoryTag::U128); + trace_builder.return_op(0, 3); + auto trace = trace_builder.finalize(); + + auto alu_row_index = common_validate_eq(trace, + FF(uint256_t::from_uint128(a)), + FF(uint256_t::from_uint128(b)), + FF(0), + FF(0), + FF(1), + FF(2), + AvmMemoryTag::U128); + auto alu_row = trace.at(alu_row_index); + + EXPECT_EQ(alu_row.avm_alu_alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.avm_alu_alu_op_eq_diff_inv, FF(0xdeadbeefLLU << 32).invert()); + validate_trace_proof(std::move(trace)); +} + /****************************************************************************** * * NEGATIVE TESTS - Finite Field Type @@ -1531,6 +1811,38 @@ TEST_F(AvmArithmeticNegativeTestsFF, operationWithErrorFlag) EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "SUBOP_ERROR_RELEVANT_OP"); } +// Tests a situation for field elements where a != b but c == 1; +TEST_F(AvmArithmeticNegativeTestsFF, invalidEquality) +{ + std::vector trace = gen_mutated_trace_eq(FF::modulus_minus_two, FF(0), FF(1), FF(0), AvmMemoryTag::FF); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + +// Tests a situation for field elements where a == b but c == 0; +TEST_F(AvmArithmeticNegativeTestsFF, invalidInequality) +{ + std::vector trace = + gen_mutated_trace_eq(FF::modulus_minus_two, FF::modulus_minus_two, FF(0), FF(0), AvmMemoryTag::FF); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + +// Tests a situation for field elements where c is non-boolean, i,e, c!= {0,1}; +TEST_F(AvmArithmeticNegativeTestsFF, nonBooleanEq) +{ + std::vector trace = + gen_mutated_trace_eq(FF::modulus_minus_two, FF::modulus_minus_two, FF(10), FF(0), AvmMemoryTag::FF); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_RES_IS_BOOL"); +} + +// Tests a situation for field elements the (a-b)^1 is incorrect. i.e. (a-b) * (a-b)^1 != 1 for (a-b) != 0; +TEST_F(AvmArithmeticNegativeTestsFF, invalidInverseDifference) +{ + // The a, b and c registers contain the correct information, only the inversion of differences is wrong. + std::vector trace = + gen_mutated_trace_eq(FF::modulus_minus_two, FF(0), FF(0), FF(5).invert(), AvmMemoryTag::FF); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + /****************************************************************************** * Negative Tests - U8 ******************************************************************************/ @@ -1556,6 +1868,35 @@ TEST_F(AvmArithmeticNegativeTestsU8, multiplication) EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MUL_COMMON_2"); } +// Tests a situation for field elements where a != b but c == 1; +TEST_F(AvmArithmeticNegativeTestsU8, invalidEquality) +{ + std::vector trace = gen_mutated_trace_eq(FF(10), FF(255), FF(1), FF(0), AvmMemoryTag::U8); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + +// Tests a situation for U8 elements where a == b but c == 0; +TEST_F(AvmArithmeticNegativeTestsU8, invalidInequality) +{ + std::vector trace = gen_mutated_trace_eq(FF(128), FF(128), FF(0), FF(0), AvmMemoryTag::U8); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + +// Tests a situation for U8 elements where c is non-boolean, i,e, c!= {0,1}; +TEST_F(AvmArithmeticNegativeTestsU8, nonBooleanEq) +{ + std::vector trace = gen_mutated_trace_eq(FF(128), FF(128), FF(200), FF(0), AvmMemoryTag::U8); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_RES_IS_BOOL"); +} + +// Tests a situation for U8 elements the (a-b)^1 is incorrect. i.e. (a-b) * (a-b)^1 != 1 for (a-b) != 0; +TEST_F(AvmArithmeticNegativeTestsU8, invalidInverseDifference) +{ + // The a, b and c registers contain the correct information, only the inversion of differences is wrong. + std::vector trace = gen_mutated_trace_eq(FF(130), FF(0), FF(0), FF(1000).invert(), AvmMemoryTag::U8); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + /****************************************************************************** * Negative Tests - U16 ******************************************************************************/ @@ -1581,6 +1922,34 @@ TEST_F(AvmArithmeticNegativeTestsU16, multiplication) EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MUL_COMMON_2"); } +// Tests a situation for U16 elements where a != b but c == 1; +TEST_F(AvmArithmeticNegativeTestsU16, invalidEquality) +{ + std::vector trace = gen_mutated_trace_eq(FF(10), FF(255), FF(1), FF(0), AvmMemoryTag::U16); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + +// Tests a situation for U16 elements where a == b but c == 0; +TEST_F(AvmArithmeticNegativeTestsU16, invalidInequality) +{ + std::vector trace = gen_mutated_trace_eq(FF(128), FF(128), FF(0), FF(0), AvmMemoryTag::U16); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + +// Tests a situation for U16 elements where c is non-boolean, i,e, c!= {0,1}; +TEST_F(AvmArithmeticNegativeTestsU16, nonBooleanEq) +{ + std::vector trace = gen_mutated_trace_eq(FF(128), FF(128), FF(200), FF(0), AvmMemoryTag::U16); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_RES_IS_BOOL"); +} + +// Tests a situation for U16 elements the (a-b)^1 is incorrect. i.e. (a-b) * (a-b)^1 != 1 for (a-b) != 0; +TEST_F(AvmArithmeticNegativeTestsU16, invalidInverseDifference) +{ + // The a, b and c registers contain the correct information, only the inversion of differences is wrong. + std::vector trace = gen_mutated_trace_eq(FF(130), FF(0), FF(0), FF(1000).invert(), AvmMemoryTag::U16); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} /****************************************************************************** * Negative Tests - U32 ******************************************************************************/ @@ -1606,6 +1975,37 @@ TEST_F(AvmArithmeticNegativeTestsU32, multiplication) EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MUL_COMMON_2"); } +// Tests a situation for U32 elements where a != b but c == 1; +TEST_F(AvmArithmeticNegativeTestsU32, invalidEquality) +{ + std::vector trace = gen_mutated_trace_eq(FF(UINT32_MAX - 10), FF(UINT32_MAX), FF(1), FF(0), AvmMemoryTag::U32); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + +// Tests a situation for U32 elements where a == b but c == 0; +TEST_F(AvmArithmeticNegativeTestsU32, invalidInequality) +{ + std::vector trace = gen_mutated_trace_eq(FF(73934721LLU), FF(73934721LLU), FF(0), FF(0), AvmMemoryTag::U32); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + +// Tests a situation for U32 elements where c is non-boolean, i,e, c!= {0,1}; +TEST_F(AvmArithmeticNegativeTestsU32, nonBooleanEq) +{ + std::vector trace = + gen_mutated_trace_eq(FF(623138LLU), FF(623138LLU), FF(8728342LLU), FF(0), AvmMemoryTag::U32); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_RES_IS_BOOL"); +} + +// Tests a situation for U32 elements the (a-b)^1 is incorrect. i.e. (a-b) * (a-b)^1 != 1 for (a-b) != 0; +TEST_F(AvmArithmeticNegativeTestsU32, invalidInverseDifference) +{ + // The a, b and c registers contain the correct information, only the inversion of differences is wrong. + std::vector trace = + gen_mutated_trace_eq(FF(74329231LLU), FF(74329231LLU), FF(0), FF(7432701LLU).invert(), AvmMemoryTag::U32); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + /****************************************************************************** * Negative Tests - U64 ******************************************************************************/ @@ -1634,6 +2034,39 @@ TEST_F(AvmArithmeticNegativeTestsU64, multiplication) EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MUL_COMMON_2"); } +// Tests a situation for U64 elements where a != b but c == 1; +TEST_F(AvmArithmeticNegativeTestsU64, invalidEquality) +{ + std::vector trace = + gen_mutated_trace_eq(FF(3999888777231234LLU), FF(3999882177231234LLU), FF(1), FF(0), AvmMemoryTag::U64); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + +// Tests a situation for U64 elements where a == b but c == 0; +TEST_F(AvmArithmeticNegativeTestsU64, invalidInequality) +{ + std::vector trace = + gen_mutated_trace_eq(FF(9998887772343LLU), FF(73934721LLU), FF(0), FF(0), AvmMemoryTag::U64); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + +// Tests a situation for U64 elements where c is non-boolean, i,e, c!= {0,1}; +TEST_F(AvmArithmeticNegativeTestsU64, nonBooleanEq) +{ + std::vector trace = + gen_mutated_trace_eq(FF(9998887772343LLU), FF(9998887772343LLU), FF(2), FF(0), AvmMemoryTag::U64); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_RES_IS_BOOL"); +} + +// Tests a situation for U64 elements the (a-b)^1 is incorrect. i.e. (a-b) * (a-b)^1 != 1 for (a-b) != 0; +TEST_F(AvmArithmeticNegativeTestsU64, invalidInverseDifference) +{ + // The a, b and c registers contain the correct information, only the inversion of differences is wrong. + std::vector trace = gen_mutated_trace_eq( + FF(9998887772343LLU), FF(9998887772343LLU), FF(0), FF(0x373428).invert(), AvmMemoryTag::U64); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + /****************************************************************************** * Negative Tests - U128 ******************************************************************************/ @@ -1680,4 +2113,45 @@ TEST_F(AvmArithmeticNegativeTestsU128, multiplication) EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MULTIPLICATION_OUT_U128"); } +// Tests a situation for U128 elements where a != b but c == 1; +TEST_F(AvmArithmeticNegativeTestsU128, invalidEquality) +{ + uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; + FF const ff_a = FF{ uint256_t::from_uint128(a) }; + uint128_t const b = (uint128_t{ 0x5555222313334444LLU } << 64) + uint128_t{ 0x88889998AAABBBBLLU }; + FF const ff_b = FF{ uint256_t::from_uint128(b) }; + + std::vector trace = gen_mutated_trace_eq(ff_a, ff_b, FF(1), FF(0), AvmMemoryTag::U128); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + +// Tests a situation for U128 elements where a == b but c == 0; +TEST_F(AvmArithmeticNegativeTestsU128, invalidInequality) +{ + uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; + FF const ff_a = FF{ uint256_t::from_uint128(a) }; + + std::vector trace = gen_mutated_trace_eq(ff_a, ff_a, FF(0), FF(0), AvmMemoryTag::U128); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + +// Tests a situation for U128 elements where c is non-boolean, i,e, c!= {0,1}; +TEST_F(AvmArithmeticNegativeTestsU128, nonBooleanEq) +{ + uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; + FF const ff_a = FF{ uint256_t::from_uint128(a) }; + std::vector trace = gen_mutated_trace_eq(ff_a, ff_a, FF::modulus - FF(1), FF(0), AvmMemoryTag::U128); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_RES_IS_BOOL"); +} + +// Tests a situation for U128 elements the (a-b)^1 is incorrect. i.e. (a-b) * (a-b)^1 != 1 for (a-b) != 0; +TEST_F(AvmArithmeticNegativeTestsU128, invalidInverseDifference) +{ + uint128_t const a = (uint128_t{ 0x5555222233334444LLU } << 64) + uint128_t{ 0x88889999AAAABBBBLLU }; + FF const ff_a = FF{ uint256_t::from_uint128(a) }; + // The a, b and c registers contain the correct information, only the inversion of differences is wrong. + std::vector trace = gen_mutated_trace_eq(ff_a, ff_a, FF(0), FF(0x8efaddd292LLU).invert(), AvmMemoryTag::U128); + EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_OP_EQ"); +} + } // namespace tests_avm