From 546ab3dd7ea72ffe6e5ba758cbeb06d223c3af51 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Mon, 12 Feb 2024 17:34:02 +0000 Subject: [PATCH 1/9] 4303: WIP - first equivalence check --- barretenberg/cpp/pil/avm/avm_mini.pil | 3 +- .../flavor/generated/AvmMini_flavor.hpp | 89 +++++++++--------- .../generated/AvmMini_circuit_builder.hpp | 73 +++++++++++---- .../relations/generated/AvmMini/alu_chip.hpp | 64 ++++++------- .../relations/generated/AvmMini/avm_mini.hpp | 58 ++++++------ .../generated/AvmMini/declare_views.hpp | 15 ++-- .../generated/AvmMini/equiv_tag_err.hpp | 90 +++++++++++++++++++ .../relations/generated/AvmMini/mem_trace.hpp | 30 +++---- .../vm/generated/AvmMini_prover.cpp | 1 + .../vm/generated/AvmMini_prover.hpp | 2 +- .../vm/generated/AvmMini_verifier.cpp | 3 + .../vm/generated/AvmMini_verifier.hpp | 2 +- .../barretenberg/vm/tests/helpers.test.cpp | 2 + 13 files changed, 289 insertions(+), 143 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/equiv_tag_err.hpp diff --git a/barretenberg/cpp/pil/avm/avm_mini.pil b/barretenberg/cpp/pil/avm/avm_mini.pil index 26268fe25cd..88729e98e26 100644 --- a/barretenberg/cpp/pil/avm/avm_mini.pil +++ b/barretenberg/cpp/pil/avm/avm_mini.pil @@ -186,6 +186,7 @@ namespace avmMini(256); // Inter-table Constraints - // TODO: tag_err {clk} IS memTrace.m_tag_err {memTrace.m_clk} + #[equiv_tag_err] + tag_err {clk} is memTrace.m_tag_err {memTrace.m_clk}; // TODO: Map memory trace with intermediate register values whenever there is no tag error, sthg like: // mem_op_a * (1 - tag_err) {mem_idx_a, clk, ia, rwa} IS m_sub_clk == 0 && 1 - m_tag_err {m_addr, m_clk, m_val, m_rw} diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index 1ee03bc93b8..0a7f856e736 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -15,6 +15,7 @@ #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/equiv_tag_err.hpp" #include "barretenberg/relations/generated/AvmMini/mem_trace.hpp" #include "barretenberg/transcript/transcript.hpp" @@ -37,13 +38,16 @@ class AvmMiniFlavor { using RelationSeparator = FF; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; - static constexpr size_t NUM_WITNESS_ENTITIES = 64; + static constexpr size_t NUM_WITNESS_ENTITIES = 65; 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 = 80; + static constexpr size_t NUM_ALL_ENTITIES = 81; - using Relations = std::tuple, AvmMini_vm::avm_mini, AvmMini_vm::mem_trace>; + using Relations = std::tuple, + AvmMini_vm::avm_mini, + AvmMini_vm::mem_trace, + equiv_tag_err_relation>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -140,7 +144,8 @@ class AvmMiniFlavor { avmMini_mem_idx_a, avmMini_mem_idx_b, avmMini_mem_idx_c, - avmMini_last) + avmMini_last, + equiv_tag_err) RefVector get_wires() { @@ -207,7 +212,8 @@ class AvmMiniFlavor { avmMini_mem_idx_a, avmMini_mem_idx_b, avmMini_mem_idx_c, - avmMini_last }; + avmMini_last, + equiv_tag_err }; }; RefVector get_sorted_polynomials() { return {}; }; }; @@ -281,19 +287,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - aluChip_alu_u16_r1_shift, + equiv_tag_err, + aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r7_shift, aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r1_shift, aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r6_shift, aluChip_alu_u16_r3_shift, - avmMini_pc_shift, + aluChip_alu_u16_r5_shift, avmMini_internal_return_ptr_shift, + avmMini_pc_shift, memTrace_m_tag_shift, - memTrace_m_addr_shift, memTrace_m_val_shift, + memTrace_m_addr_shift, memTrace_m_rw_shift) RefVector get_wires() @@ -364,19 +371,20 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - aluChip_alu_u16_r1_shift, + equiv_tag_err, + aluChip_alu_u16_r6_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r7_shift, aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r1_shift, aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r6_shift, aluChip_alu_u16_r3_shift, - avmMini_pc_shift, + aluChip_alu_u16_r5_shift, avmMini_internal_return_ptr_shift, + avmMini_pc_shift, memTrace_m_tag_shift, - memTrace_m_addr_shift, memTrace_m_val_shift, + memTrace_m_addr_shift, memTrace_m_rw_shift }; }; RefVector get_unshifted() @@ -446,27 +454,24 @@ class AvmMiniFlavor { avmMini_mem_idx_a, avmMini_mem_idx_b, avmMini_mem_idx_c, - avmMini_last }; + avmMini_last, + equiv_tag_err }; }; RefVector get_to_be_shifted() { - return { aluChip_alu_u16_r1, aluChip_alu_u16_r0, - aluChip_alu_u16_r4, aluChip_alu_u16_r7, - aluChip_alu_u16_r5, aluChip_alu_u16_r2, - aluChip_alu_u16_r6, aluChip_alu_u16_r3, - avmMini_pc, avmMini_internal_return_ptr, - memTrace_m_tag, memTrace_m_addr, - memTrace_m_val, memTrace_m_rw }; + return { aluChip_alu_u16_r6, aluChip_alu_u16_r2, aluChip_alu_u16_r7, + aluChip_alu_u16_r0, aluChip_alu_u16_r1, aluChip_alu_u16_r4, + aluChip_alu_u16_r3, aluChip_alu_u16_r5, avmMini_internal_return_ptr, + avmMini_pc, memTrace_m_tag, memTrace_m_val, + memTrace_m_addr, memTrace_m_rw }; }; RefVector get_shifted() { - return { aluChip_alu_u16_r1_shift, aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r4_shift, aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r5_shift, aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r6_shift, aluChip_alu_u16_r3_shift, - avmMini_pc_shift, avmMini_internal_return_ptr_shift, - memTrace_m_tag_shift, memTrace_m_addr_shift, - memTrace_m_val_shift, memTrace_m_rw_shift }; + return { aluChip_alu_u16_r6_shift, aluChip_alu_u16_r2_shift, aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r0_shift, aluChip_alu_u16_r1_shift, aluChip_alu_u16_r4_shift, + aluChip_alu_u16_r3_shift, aluChip_alu_u16_r5_shift, avmMini_internal_return_ptr_shift, + avmMini_pc_shift, memTrace_m_tag_shift, memTrace_m_val_shift, + memTrace_m_addr_shift, memTrace_m_rw_shift }; }; }; @@ -479,13 +484,11 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { aluChip_alu_u16_r1, aluChip_alu_u16_r0, - aluChip_alu_u16_r4, aluChip_alu_u16_r7, - aluChip_alu_u16_r5, aluChip_alu_u16_r2, - aluChip_alu_u16_r6, aluChip_alu_u16_r3, - avmMini_pc, avmMini_internal_return_ptr, - memTrace_m_tag, memTrace_m_addr, - memTrace_m_val, memTrace_m_rw }; + return { aluChip_alu_u16_r6, aluChip_alu_u16_r2, aluChip_alu_u16_r7, + aluChip_alu_u16_r0, aluChip_alu_u16_r1, aluChip_alu_u16_r4, + aluChip_alu_u16_r3, aluChip_alu_u16_r5, avmMini_internal_return_ptr, + avmMini_pc, memTrace_m_tag, memTrace_m_val, + memTrace_m_addr, memTrace_m_rw }; }; // The plookup wires that store plookup read data. @@ -628,6 +631,7 @@ class AvmMiniFlavor { Base::avmMini_mem_idx_b = "AVMMINI_MEM_IDX_B"; Base::avmMini_mem_idx_c = "AVMMINI_MEM_IDX_C"; Base::avmMini_last = "AVMMINI_LAST"; + Base::equiv_tag_err = "EQUIV_TAG_ERR"; }; }; @@ -711,6 +715,7 @@ class AvmMiniFlavor { Commitment avmMini_mem_idx_b; Commitment avmMini_mem_idx_c; Commitment avmMini_last; + Commitment equiv_tag_err; std::vector> sumcheck_univariates; std::array sumcheck_evaluations; @@ -794,6 +799,7 @@ class AvmMiniFlavor { 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); + equiv_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); for (size_t i = 0; i < log_n; ++i) { sumcheck_univariates.emplace_back( @@ -881,6 +887,7 @@ class AvmMiniFlavor { 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); + serialize_to_buffer(equiv_tag_err, Transcript::proof_data); for (size_t i = 0; i < log_n; ++i) { serialize_to_buffer(sumcheck_univariates[i], Transcript::proof_data); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp index 5392923eb1f..72c0d654278 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp @@ -14,6 +14,7 @@ #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/equiv_tag_err.hpp" #include "barretenberg/relations/generated/AvmMini/mem_trace.hpp" namespace bb { @@ -85,19 +86,20 @@ template struct AvmMiniFullRow { FF avmMini_mem_idx_b{}; FF avmMini_mem_idx_c{}; FF avmMini_last{}; - FF aluChip_alu_u16_r1_shift{}; + FF equiv_tag_err{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r7_shift{}; FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_u16_r1_shift{}; FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u16_r6_shift{}; FF aluChip_alu_u16_r3_shift{}; - FF avmMini_pc_shift{}; + FF aluChip_alu_u16_r5_shift{}; FF avmMini_internal_return_ptr_shift{}; + FF avmMini_pc_shift{}; FF memTrace_m_tag_shift{}; - FF memTrace_m_addr_shift{}; FF memTrace_m_val_shift{}; + FF memTrace_m_addr_shift{}; FF memTrace_m_rw_shift{}; }; @@ -111,8 +113,8 @@ class AvmMiniCircuitBuilder { using Polynomial = Flavor::Polynomial; using ProverPolynomials = Flavor::ProverPolynomials; - static constexpr size_t num_fixed_columns = 80; - static constexpr size_t num_polys = 66; + static constexpr size_t num_fixed_columns = 81; + static constexpr size_t num_polys = 67; std::vector rows; void set_trace(std::vector&& trace) { rows = std::move(trace); } @@ -194,21 +196,22 @@ class AvmMiniCircuitBuilder { 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.equiv_tag_err[i] = rows[i].equiv_tag_err; } - polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); + polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); + polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); + polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); + polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); - polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); - polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); - polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); - polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); - polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); + polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); + polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); + polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); return polys; @@ -217,6 +220,19 @@ class AvmMiniCircuitBuilder { [[maybe_unused]] bool check_circuit() { + const FF gamma = FF::random_element(); + const FF beta = FF::random_element(); + bb::RelationParameters params{ + .eta = 0, + .beta = beta, + .gamma = gamma, + .public_input_delta = 0, + .lookup_grand_product_delta = 0, + .beta_sqr = 0, + .beta_cube = 0, + .eccvm_set_permutation_delta = 0, + }; + auto polys = compute_polynomials(); const size_t num_rows = polys.get_polynomial_size(); @@ -247,6 +263,27 @@ class AvmMiniCircuitBuilder { return true; }; + const auto evaluate_logderivative = [&](const std::string& lookup_name) { + // Check the logderivative relation + bb::compute_logderivative_inverse(polys, params, num_rows); + + typename LogDerivativeSettings::SumcheckArrayOfValuesOverSubrelations lookup_result; + + for (auto& r : lookup_result) { + r = 0; + } + for (size_t i = 0; i < num_rows; ++i) { + LogDerivativeSettings::accumulate(lookup_result, polys.get_row(i), params, 1); + } + for (auto r : lookup_result) { + if (r != 0) { + info("Lookup ", lookup_name, " failed."); + return false; + } + } + return true; + }; + if (!evaluate_relation.template operator()>("alu_chip", AvmMini_vm::get_relation_label_alu_chip)) { return false; @@ -260,6 +297,10 @@ class AvmMiniCircuitBuilder { return false; } + if (!evaluate_logderivative.template operator()>("equiv_tag_err")) { + return false; + } + return true; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index c1cd8a6e970..2b4c4b80638 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,60 +7,60 @@ namespace bb::AvmMini_vm { template struct Alu_chipRow { - FF aluChip_alu_u16_r0{}; - FF aluChip_alu_u16_r3{}; - FF aluChip_alu_u16_r5{}; - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_op_add{}; - FF aluChip_alu_ia{}; - FF aluChip_alu_u16_r4_shift{}; FF aluChip_alu_ib{}; - FF aluChip_alu_u16_r7{}; - FF aluChip_alu_u8_r0{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_op_sub{}; - FF aluChip_alu_u16_r6{}; - FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_op_mul{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u16_r5{}; FF aluChip_alu_u64_tag{}; + FF aluChip_alu_u16_tag{}; + FF aluChip_alu_ic{}; + FF aluChip_alu_ia{}; FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r4{}; FF aluChip_alu_u64_r0{}; - FF aluChip_alu_ff_tag{}; + FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_u16_r1_shift{}; FF aluChip_alu_u32_tag{}; - FF aluChip_alu_u16_tag{}; - FF aluChip_alu_u16_r4{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r2{}; - FF aluChip_alu_ic{}; - FF aluChip_alu_u8_tag{}; - FF aluChip_alu_cf{}; + FF aluChip_alu_u16_r1{}; + FF aluChip_alu_u16_r4_shift{}; + FF aluChip_alu_ff_tag{}; FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_op_sub{}; + FF aluChip_alu_u16_r0{}; + FF aluChip_alu_u8_tag{}; + FF aluChip_alu_u16_r6{}; + FF aluChip_alu_u16_r3{}; + FF aluChip_alu_op_add{}; FF aluChip_alu_u8_r1{}; - FF aluChip_alu_u16_r1{}; + FF aluChip_alu_cf{}; + FF aluChip_alu_u16_r2{}; FF aluChip_alu_u128_tag{}; + FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r7{}; + FF aluChip_alu_op_mul{}; + FF aluChip_alu_u8_r0{}; }; inline std::string get_relation_label_alu_chip(int index) { switch (index) { + case 8: + return "ALU_MULTIPLICATION_FF"; + case 9: return "ALU_MUL_COMMON_1"; - case 8: - return "ALU_MULTIPLICATION_FF"; + case 13: + return "ALU_MULTIPLICATION_OUT_U128"; + + case 10: + return "ALU_MUL_COMMON_2"; case 6: return "ALU_ADD_SUB_1"; case 7: return "ALU_ADD_SUB_2"; - - case 10: - return "ALU_MUL_COMMON_2"; - - case 13: - return "ALU_MULTIPLICATION_OUT_U128"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index 3347e38ff96..36483cc8b2f 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,61 +7,61 @@ namespace bb::AvmMini_vm { template struct Avm_miniRow { + FF avmMini_mem_op_a{}; + FF avmMini_ia{}; + FF avmMini_pc{}; + FF avmMini_rwa{}; + FF avmMini_mem_idx_b{}; + FF avmMini_mem_idx_a{}; FF avmMini_sel_op_sub{}; + FF avmMini_op_err{}; + FF avmMini_mem_op_b{}; + FF avmMini_sel_internal_call{}; + FF avmMini_ib{}; + FF avmMini_internal_return_ptr_shift{}; + FF avmMini_ic{}; + FF avmMini_mem_op_c{}; FF avmMini_inv{}; FF avmMini_first{}; - FF avmMini_tag_err{}; + FF avmMini_sel_internal_return{}; + FF avmMini_rwc{}; FF avmMini_pc_shift{}; - FF avmMini_mem_op_a{}; FF avmMini_rwb{}; - FF avmMini_mem_op_c{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_rwc{}; - FF avmMini_sel_op_div{}; - FF avmMini_internal_return_ptr{}; - FF avmMini_pc{}; - FF avmMini_ia{}; - FF avmMini_sel_op_mul{}; - FF avmMini_mem_op_b{}; - FF avmMini_ib{}; FF avmMini_sel_jump{}; + FF avmMini_internal_return_ptr{}; FF avmMini_sel_halt{}; - FF avmMini_sel_internal_return{}; - FF avmMini_op_err{}; - FF avmMini_mem_idx_a{}; - FF avmMini_mem_idx_b{}; - FF avmMini_sel_internal_call{}; FF avmMini_sel_op_add{}; - FF avmMini_rwa{}; - FF avmMini_ic{}; + FF avmMini_sel_op_div{}; + FF avmMini_tag_err{}; + FF avmMini_sel_op_mul{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { - case 20: - return "SUBOP_DIVISION_ZERO_ERR1"; - case 22: return "SUBOP_ERROR_RELEVANT_OP"; + case 24: + return "RETURN_POINTER_INCREMENT"; + case 30: return "RETURN_POINTER_DECREMENT"; - case 36: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - case 21: return "SUBOP_DIVISION_ZERO_ERR2"; - case 35: - return "PC_INCREMENT"; + case 20: + return "SUBOP_DIVISION_ZERO_ERR1"; - case 24: - return "RETURN_POINTER_INCREMENT"; + case 36: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; case 19: return "SUBOP_DIVISION_FF"; + + case 35: + return "PC_INCREMENT"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index 1b036e25919..c928b2063e0 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -68,17 +68,18 @@ [[maybe_unused]] auto avmMini_mem_idx_b = View(new_term.avmMini_mem_idx_b); \ [[maybe_unused]] auto avmMini_mem_idx_c = View(new_term.avmMini_mem_idx_c); \ [[maybe_unused]] auto avmMini_last = View(new_term.avmMini_last); \ - [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ + [[maybe_unused]] auto equiv_tag_err = View(new_term.equiv_tag_err); \ + [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ - [[maybe_unused]] auto avmMini_pc_shift = View(new_term.avmMini_pc_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); \ + [[maybe_unused]] auto avmMini_pc_shift = View(new_term.avmMini_pc_shift); \ [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ - [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ + [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/equiv_tag_err.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/equiv_tag_err.hpp new file mode 100644 index 00000000000..b032975868e --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/equiv_tag_err.hpp @@ -0,0 +1,90 @@ + + +#pragma once + +#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" + +#include +#include + +namespace bb { + +class equiv_tag_err_permutation_settings { + public: + // This constant defines how many columns are bundled together to form each set. + constexpr static size_t COLUMNS_PER_SET = 1; + + /** + * @brief If this method returns true on a row of values, then the inverse polynomial at this index. Otherwise the + * value needs to be set to zero. + * + * @details If this is true then permutation takes place in this row + */ + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in.avmMini_tag_err == 1); + } + + /** + * @brief Get all the entities for the permutation when we don't need to update them + * + * @details The entities are returned as a tuple of references in the following order: + * - The entity/polynomial used to store the product of the inverse values + * - The entity/polynomial that switches on the subrelation of the permutation relation that ensures correctness of + * the inverse polynomial + * - The entity/polynomial that enables adding a tuple-generated value from the first set to the logderivative sum + * subrelation + * - The entity/polynomial that enables adding a tuple-generated value from the second set to the logderivative sum + * subrelation + * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the first set (N.B. ORDER IS IMPORTANT!) + * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the second set (N.B. ORDER IS IMPORTANT!) + * + * @return All the entities needed for the permutation + */ + + template static inline auto get_const_entities(const AllEntities& in) + { + + return std::forward_as_tuple(in.equiv_tag_err, + in.avmMini_tag_err, + in.avmMini_tag_err, + in.avmMini_tag_err, + in.avmMini_clk, + in.memTrace_m_clk); + } + + /** + * @brief Get all the entities for the permutation when need to update them + * + * @details The entities are returned as a tuple of references in the following order: + * - The entity/polynomial used to store the product of the inverse values + * - The entity/polynomial that switches on the subrelation of the permutation relation that ensures correctness of + * the inverse polynomial + * - The entity/polynomial that enables adding a tuple-generated value from the first set to the logderivative sum + * subrelation + * - The entity/polynomial that enables adding a tuple-generated value from the second set to the logderivative sum + * subrelation + * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the first set (N.B. ORDER IS IMPORTANT!) + * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the second set (N.B. ORDER IS IMPORTANT!) + * + * @return All the entities needed for the permutation + */ + + template static inline auto get_nonconst_entities(AllEntities& in) + { + + return std::forward_as_tuple(in.equiv_tag_err, + in.avmMini_tag_err, + in.avmMini_tag_err, + in.avmMini_tag_err, + in.avmMini_clk, + in.memTrace_m_clk); + } +}; + +template +using equiv_tag_err_relation = GenericPermutationRelation; +template using equiv_tag_err = GenericPermutation; + +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 49cc8062e82..16a858f969b 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,41 +7,41 @@ namespace bb::AvmMini_vm { template struct Mem_traceRow { - FF memTrace_m_val{}; - FF memTrace_m_last{}; - FF memTrace_m_in_tag{}; FF memTrace_m_tag{}; + FF memTrace_m_addr{}; FF memTrace_m_rw{}; + FF memTrace_m_val{}; FF memTrace_m_tag_shift{}; - FF memTrace_m_addr_shift{}; FF memTrace_m_tag_err{}; - FF memTrace_m_one_min_inv{}; + FF memTrace_m_in_tag{}; + FF memTrace_m_last{}; FF memTrace_m_val_shift{}; + FF memTrace_m_one_min_inv{}; FF memTrace_m_lastAccess{}; - FF memTrace_m_addr{}; + FF memTrace_m_addr_shift{}; FF memTrace_m_rw_shift{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { - case 8: - return "MEM_IN_TAG_CONSISTENCY_1"; + case 7: + return "MEM_ZERO_INIT"; - case 9: - return "MEM_IN_TAG_CONSISTENCY_2"; + case 4: + return "MEM_LAST_ACCESS_DELIMITER"; case 5: return "MEM_READ_WRITE_VAL_CONSISTENCY"; - case 4: - return "MEM_LAST_ACCESS_DELIMITER"; - case 6: return "MEM_READ_WRITE_TAG_CONSISTENCY"; - case 7: - return "MEM_ZERO_INIT"; + case 8: + return "MEM_IN_TAG_CONSISTENCY_1"; + + case 9: + return "MEM_IN_TAG_CONSISTENCY_2"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.cpp index 9e79beae75f..420a06956fb 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.cpp @@ -73,6 +73,7 @@ void AvmMiniProver::execute_relation_check_rounds() using Sumcheck = SumcheckProver; auto sumcheck = Sumcheck(key->circuit_size, transcript); + FF alpha = transcript->template get_challenge("Sumcheck:alpha"); std::vector gate_challenges(numeric::get_msb(key->circuit_size)); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.hpp index 726ea473bf2..c1aec1a2f9a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_prover.hpp @@ -3,7 +3,7 @@ #pragma once #include "barretenberg/commitment_schemes/zeromorph/zeromorph.hpp" #include "barretenberg/flavor/generated/AvmMini_flavor.hpp" -#include "barretenberg/honk/proof_system/types/proof.hpp" +#include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/sumcheck/sumcheck_output.hpp" #include "barretenberg/transcript/transcript.hpp" diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp index e73881458ce..3938a1b0dac 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp @@ -160,11 +160,14 @@ bool AvmMiniVerifier::verify_proof(const HonkProof& proof) commitments.avmMini_mem_idx_c = transcript->template receive_from_prover(commitment_labels.avmMini_mem_idx_c); commitments.avmMini_last = transcript->template receive_from_prover(commitment_labels.avmMini_last); + commitments.equiv_tag_err = transcript->template receive_from_prover(commitment_labels.equiv_tag_err); // Execute Sumcheck Verifier const size_t log_circuit_size = numeric::get_msb(circuit_size); auto sumcheck = SumcheckVerifier(log_circuit_size, transcript); + FF alpha = transcript->template get_challenge("Sumcheck:alpha"); + auto gate_challenges = std::vector(log_circuit_size); for (size_t idx = 0; idx < log_circuit_size; idx++) { gate_challenges[idx] = transcript->template get_challenge("Sumcheck:gate_challenge_" + std::to_string(idx)); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.hpp index 152950496c0..8250b37c64e 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.hpp @@ -2,7 +2,7 @@ #pragma once #include "barretenberg/flavor/generated/AvmMini_flavor.hpp" -#include "barretenberg/honk/proof_system/types/proof.hpp" +#include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" namespace bb { diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp index dc2a1e29b77..cc8fe01c629 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp @@ -22,6 +22,8 @@ void validate_trace_proof(std::vector&& trace) auto verifier = composer.create_verifier(circuit_builder); bool verified = verifier.verify_proof(proof); + EXPECT_TRUE(verified); + if (!verified) { avm_trace::log_avmMini_trace(circuit_builder.rows, 0, 10); } From 958f8454907e1f273e7fb3a0c64ec3f582118766 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:54:51 +0000 Subject: [PATCH 2/9] tmp --- .../flavor/generated/AvmMini_flavor.hpp | 80 ++++++++++--------- .../generated/AvmMini_circuit_builder.hpp | 48 +++++------ .../relations/generated/AvmMini/alu_chip.hpp | 68 ++++++++-------- .../relations/generated/AvmMini/avm_mini.hpp | 60 +++++++------- .../generated/AvmMini/declare_views.hpp | 20 ++--- .../generated/AvmMini/equiv_tag_err.hpp | 6 +- .../relations/generated/AvmMini/mem_trace.hpp | 32 ++++---- .../generic_permutation_relation.hpp | 11 ++- .../barretenberg/vm/generated/Toy_prover.cpp | 4 + .../vm/generated/Toy_verifier.cpp | 3 + .../vm/generated/Toy_verifier.hpp | 2 +- .../barretenberg/vm/tests/helpers.test.cpp | 8 +- 12 files changed, 183 insertions(+), 159 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index 0a7f856e736..8ff7a4f408a 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -44,9 +44,9 @@ class AvmMiniFlavor { // the unshifted and one for the shifted static constexpr size_t NUM_ALL_ENTITIES = 81; - using Relations = std::tuple, + using Relations = std::tuple, + AvmMini_vm::alu_chip, AvmMini_vm::avm_mini, - AvmMini_vm::mem_trace, equiv_tag_err_relation>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -288,20 +288,20 @@ class AvmMiniFlavor { avmMini_mem_idx_c, avmMini_last, equiv_tag_err, - aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r0_shift, + memTrace_m_val_shift, + memTrace_m_tag_shift, + memTrace_m_rw_shift, + memTrace_m_addr_shift, aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r4_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r2_shift, aluChip_alu_u16_r3_shift, aluChip_alu_u16_r5_shift, - avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r4_shift, + aluChip_alu_u16_r6_shift, avmMini_pc_shift, - memTrace_m_tag_shift, - memTrace_m_val_shift, - memTrace_m_addr_shift, - memTrace_m_rw_shift) + avmMini_internal_return_ptr_shift) RefVector get_wires() { @@ -372,20 +372,20 @@ class AvmMiniFlavor { avmMini_mem_idx_c, avmMini_last, equiv_tag_err, - aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r0_shift, + memTrace_m_val_shift, + memTrace_m_tag_shift, + memTrace_m_rw_shift, + memTrace_m_addr_shift, aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r4_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r2_shift, aluChip_alu_u16_r3_shift, aluChip_alu_u16_r5_shift, - avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r4_shift, + aluChip_alu_u16_r6_shift, avmMini_pc_shift, - memTrace_m_tag_shift, - memTrace_m_val_shift, - memTrace_m_addr_shift, - memTrace_m_rw_shift }; + avmMini_internal_return_ptr_shift }; }; RefVector get_unshifted() { @@ -459,19 +459,23 @@ class AvmMiniFlavor { }; RefVector get_to_be_shifted() { - return { aluChip_alu_u16_r6, aluChip_alu_u16_r2, aluChip_alu_u16_r7, - aluChip_alu_u16_r0, aluChip_alu_u16_r1, aluChip_alu_u16_r4, - aluChip_alu_u16_r3, aluChip_alu_u16_r5, avmMini_internal_return_ptr, - avmMini_pc, memTrace_m_tag, memTrace_m_val, - memTrace_m_addr, memTrace_m_rw }; + return { memTrace_m_val, memTrace_m_tag, + memTrace_m_rw, memTrace_m_addr, + aluChip_alu_u16_r1, aluChip_alu_u16_r7, + aluChip_alu_u16_r2, aluChip_alu_u16_r3, + aluChip_alu_u16_r5, aluChip_alu_u16_r0, + aluChip_alu_u16_r4, aluChip_alu_u16_r6, + avmMini_pc, avmMini_internal_return_ptr }; }; RefVector get_shifted() { - return { aluChip_alu_u16_r6_shift, aluChip_alu_u16_r2_shift, aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r0_shift, aluChip_alu_u16_r1_shift, aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r3_shift, aluChip_alu_u16_r5_shift, avmMini_internal_return_ptr_shift, - avmMini_pc_shift, memTrace_m_tag_shift, memTrace_m_val_shift, - memTrace_m_addr_shift, memTrace_m_rw_shift }; + return { memTrace_m_val_shift, memTrace_m_tag_shift, + memTrace_m_rw_shift, memTrace_m_addr_shift, + aluChip_alu_u16_r1_shift, aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r2_shift, aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r5_shift, aluChip_alu_u16_r0_shift, + aluChip_alu_u16_r4_shift, aluChip_alu_u16_r6_shift, + avmMini_pc_shift, avmMini_internal_return_ptr_shift }; }; }; @@ -484,11 +488,13 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { aluChip_alu_u16_r6, aluChip_alu_u16_r2, aluChip_alu_u16_r7, - aluChip_alu_u16_r0, aluChip_alu_u16_r1, aluChip_alu_u16_r4, - aluChip_alu_u16_r3, aluChip_alu_u16_r5, avmMini_internal_return_ptr, - avmMini_pc, memTrace_m_tag, memTrace_m_val, - memTrace_m_addr, memTrace_m_rw }; + return { memTrace_m_val, memTrace_m_tag, + memTrace_m_rw, memTrace_m_addr, + aluChip_alu_u16_r1, aluChip_alu_u16_r7, + aluChip_alu_u16_r2, aluChip_alu_u16_r3, + aluChip_alu_u16_r5, aluChip_alu_u16_r0, + aluChip_alu_u16_r4, aluChip_alu_u16_r6, + avmMini_pc, avmMini_internal_return_ptr }; }; // The plookup wires that store plookup read data. diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp index 72c0d654278..48e1f3ef18c 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp @@ -87,20 +87,20 @@ template struct AvmMiniFullRow { FF avmMini_mem_idx_c{}; FF avmMini_last{}; FF equiv_tag_err{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r0_shift{}; + FF memTrace_m_val_shift{}; + FF memTrace_m_tag_shift{}; + FF memTrace_m_rw_shift{}; + FF memTrace_m_addr_shift{}; FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r4_shift{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r2_shift{}; FF aluChip_alu_u16_r3_shift{}; FF aluChip_alu_u16_r5_shift{}; - FF avmMini_internal_return_ptr_shift{}; + FF aluChip_alu_u16_r0_shift{}; + FF aluChip_alu_u16_r4_shift{}; + FF aluChip_alu_u16_r6_shift{}; FF avmMini_pc_shift{}; - FF memTrace_m_tag_shift{}; - FF memTrace_m_val_shift{}; - FF memTrace_m_addr_shift{}; - FF memTrace_m_rw_shift{}; + FF avmMini_internal_return_ptr_shift{}; }; class AvmMiniCircuitBuilder { @@ -199,20 +199,20 @@ class AvmMiniCircuitBuilder { polys.equiv_tag_err[i] = rows[i].equiv_tag_err; } - polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); - polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); - polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); - polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); + polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); + polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); + polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); + polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); - polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); + polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); + polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); - polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); + polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); + polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); + polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); - polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); - polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); - polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); + polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); return polys; } @@ -284,6 +284,10 @@ class AvmMiniCircuitBuilder { return true; }; + if (!evaluate_relation.template operator()>( + "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { + return false; + } if (!evaluate_relation.template operator()>("alu_chip", AvmMini_vm::get_relation_label_alu_chip)) { return false; @@ -292,10 +296,6 @@ class AvmMiniCircuitBuilder { AvmMini_vm::get_relation_label_avm_mini)) { return false; } - if (!evaluate_relation.template operator()>( - "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { - return false; - } if (!evaluate_logderivative.template operator()>("equiv_tag_err")) { return false; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index 2b4c4b80638..0659f7b8dba 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,60 +7,60 @@ namespace bb::AvmMini_vm { template struct Alu_chipRow { - FF aluChip_alu_ib{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r5{}; + FF aluChip_alu_u16_r7{}; + FF aluChip_alu_u16_r1_shift{}; FF aluChip_alu_u64_tag{}; - FF aluChip_alu_u16_tag{}; - FF aluChip_alu_ic{}; - FF aluChip_alu_ia{}; - FF aluChip_alu_u16_r2_shift{}; FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r4{}; - FF aluChip_alu_u64_r0{}; - FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u32_tag{}; + FF aluChip_alu_u8_r0{}; FF aluChip_alu_u16_r1{}; - FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_ff_tag{}; + FF aluChip_alu_u16_r5{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u32_tag{}; + FF aluChip_alu_cf{}; + FF aluChip_alu_ia{}; + FF aluChip_alu_u16_r0{}; + FF aluChip_alu_ic{}; FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r4{}; + FF aluChip_alu_op_mul{}; + FF aluChip_alu_u16_r3{}; + FF aluChip_alu_u8_r1{}; FF aluChip_alu_op_sub{}; - FF aluChip_alu_u16_r0{}; + FF aluChip_alu_u16_r0_shift{}; FF aluChip_alu_u8_tag{}; - FF aluChip_alu_u16_r6{}; - FF aluChip_alu_u16_r3{}; + FF aluChip_alu_u16_r4_shift{}; FF aluChip_alu_op_add{}; - FF aluChip_alu_u8_r1{}; - FF aluChip_alu_cf{}; - FF aluChip_alu_u16_r2{}; FF aluChip_alu_u128_tag{}; - FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_u16_r7{}; - FF aluChip_alu_op_mul{}; - FF aluChip_alu_u8_r0{}; + FF aluChip_alu_u64_r0{}; + FF aluChip_alu_u16_r2{}; + FF aluChip_alu_ff_tag{}; + FF aluChip_alu_u16_tag{}; + FF aluChip_alu_u16_r6{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_ib{}; }; inline std::string get_relation_label_alu_chip(int index) { switch (index) { - case 8: - return "ALU_MULTIPLICATION_FF"; - - case 9: - return "ALU_MUL_COMMON_1"; + case 7: + return "ALU_ADD_SUB_2"; case 13: return "ALU_MULTIPLICATION_OUT_U128"; - case 10: - return "ALU_MUL_COMMON_2"; - case 6: return "ALU_ADD_SUB_1"; - case 7: - return "ALU_ADD_SUB_2"; + case 9: + return "ALU_MUL_COMMON_1"; + + case 8: + return "ALU_MULTIPLICATION_FF"; + + case 10: + return "ALU_MUL_COMMON_2"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index 36483cc8b2f..bcf0384b827 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,58 +7,58 @@ namespace bb::AvmMini_vm { template struct Avm_miniRow { + FF avmMini_first{}; + FF avmMini_rwc{}; + FF avmMini_rwa{}; + FF avmMini_sel_internal_return{}; + FF avmMini_tag_err{}; FF avmMini_mem_op_a{}; FF avmMini_ia{}; + FF avmMini_inv{}; + FF avmMini_mem_op_b{}; + FF avmMini_mem_op_c{}; + FF avmMini_sel_op_div{}; + FF avmMini_internal_return_ptr{}; FF avmMini_pc{}; - FF avmMini_rwa{}; FF avmMini_mem_idx_b{}; - FF avmMini_mem_idx_a{}; + FF avmMini_pc_shift{}; + FF avmMini_sel_op_add{}; FF avmMini_sel_op_sub{}; FF avmMini_op_err{}; - FF avmMini_mem_op_b{}; - FF avmMini_sel_internal_call{}; - FF avmMini_ib{}; FF avmMini_internal_return_ptr_shift{}; + FF avmMini_mem_idx_a{}; + FF avmMini_sel_op_mul{}; + FF avmMini_sel_halt{}; + FF avmMini_ib{}; + FF avmMini_sel_jump{}; FF avmMini_ic{}; - FF avmMini_mem_op_c{}; - FF avmMini_inv{}; - FF avmMini_first{}; - FF avmMini_sel_internal_return{}; - FF avmMini_rwc{}; - FF avmMini_pc_shift{}; + FF avmMini_sel_internal_call{}; FF avmMini_rwb{}; - FF avmMini_sel_jump{}; - FF avmMini_internal_return_ptr{}; - FF avmMini_sel_halt{}; - FF avmMini_sel_op_add{}; - FF avmMini_sel_op_div{}; - FF avmMini_tag_err{}; - FF avmMini_sel_op_mul{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { - case 22: - return "SUBOP_ERROR_RELEVANT_OP"; + case 19: + return "SUBOP_DIVISION_FF"; + + case 20: + return "SUBOP_DIVISION_ZERO_ERR1"; case 24: return "RETURN_POINTER_INCREMENT"; - case 30: - return "RETURN_POINTER_DECREMENT"; + case 36: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + + case 22: + return "SUBOP_ERROR_RELEVANT_OP"; case 21: return "SUBOP_DIVISION_ZERO_ERR2"; - case 20: - return "SUBOP_DIVISION_ZERO_ERR1"; - - case 36: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - - case 19: - return "SUBOP_DIVISION_FF"; + case 30: + return "RETURN_POINTER_DECREMENT"; case 35: return "PC_INCREMENT"; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index c928b2063e0..2cf1a7274ac 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -69,17 +69,17 @@ [[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 equiv_tag_err = View(new_term.equiv_tag_err); \ - [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ + [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ + [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ + [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ + [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ - [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_shift); \ [[maybe_unused]] auto avmMini_pc_shift = View(new_term.avmMini_pc_shift); \ - [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ - [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ - [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ - [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); + [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/equiv_tag_err.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/equiv_tag_err.hpp index b032975868e..9ab2e489aed 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/equiv_tag_err.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/equiv_tag_err.hpp @@ -23,7 +23,7 @@ class equiv_tag_err_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avmMini_tag_err == 1); + return (in.avmMini_tag_err == 1 || in.memTrace_m_tag_err == 1); } /** @@ -49,7 +49,7 @@ class equiv_tag_err_permutation_settings { return std::forward_as_tuple(in.equiv_tag_err, in.avmMini_tag_err, in.avmMini_tag_err, - in.avmMini_tag_err, + in.memTrace_m_tag_err, in.avmMini_clk, in.memTrace_m_clk); } @@ -77,7 +77,7 @@ class equiv_tag_err_permutation_settings { return std::forward_as_tuple(in.equiv_tag_err, in.avmMini_tag_err, in.avmMini_tag_err, - in.avmMini_tag_err, + in.memTrace_m_tag_err, in.avmMini_clk, in.memTrace_m_clk); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 16a858f969b..08354bf4029 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,41 +7,41 @@ namespace bb::AvmMini_vm { template struct Mem_traceRow { - FF memTrace_m_tag{}; + FF memTrace_m_last{}; FF memTrace_m_addr{}; - FF memTrace_m_rw{}; + FF memTrace_m_val_shift{}; FF memTrace_m_val{}; FF memTrace_m_tag_shift{}; - FF memTrace_m_tag_err{}; - FF memTrace_m_in_tag{}; - FF memTrace_m_last{}; - FF memTrace_m_val_shift{}; FF memTrace_m_one_min_inv{}; FF memTrace_m_lastAccess{}; - FF memTrace_m_addr_shift{}; + FF memTrace_m_tag_err{}; + FF memTrace_m_rw{}; FF memTrace_m_rw_shift{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_tag{}; + FF memTrace_m_in_tag{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { - case 7: - return "MEM_ZERO_INIT"; - - case 4: - return "MEM_LAST_ACCESS_DELIMITER"; - case 5: return "MEM_READ_WRITE_VAL_CONSISTENCY"; - case 6: - return "MEM_READ_WRITE_TAG_CONSISTENCY"; - case 8: return "MEM_IN_TAG_CONSISTENCY_1"; + case 6: + return "MEM_READ_WRITE_TAG_CONSISTENCY"; + case 9: return "MEM_IN_TAG_CONSISTENCY_2"; + + case 7: + return "MEM_ZERO_INIT"; + + case 4: + return "MEM_LAST_ACCESS_DELIMITER"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp index 084132abfa3..288501563a1 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp @@ -88,7 +88,16 @@ template class GenericPermutationRelationImpl { using View = typename Accumulator::View; - // WIRE/SELECTOR enabling the permutation used in the sumcheck computation. This affects the first subrelation + // TODO: Check with kesha that this is fine being a the two sets + + // // WIRE/SELECTOR enabling the permutation used in the sumcheck computation. This affects the first + // subrelation Accumulator const& first_set_enabled = Accumulator( + // View(std::get(Settings::get_const_entities(in)))); + + // Accumulator const& second_set_enabled = Accumulator( + // View(std::get(Settings::get_const_entities(in)))); + + // return first_set_enabled * second_set_enabled; return Accumulator( View(std::get(Settings::get_const_entities(in)))); } diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/Toy_prover.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/Toy_prover.cpp index 525726c645a..dbd275e07bd 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/Toy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/Toy_prover.cpp @@ -14,6 +14,7 @@ namespace bb { using Flavor = ToyFlavor; +using FF = Flavor::FF; /** * Create ToyProver from proving key, witness and manifest. @@ -69,9 +70,12 @@ void ToyProver::execute_wire_commitments_round() void ToyProver::execute_relation_check_rounds() { using Sumcheck = SumcheckProver; + auto sumcheck = Sumcheck(key->circuit_size, transcript); + FF alpha = transcript->template get_challenge("Sumcheck:alpha"); std::vector gate_challenges(numeric::get_msb(key->circuit_size)); + for (size_t idx = 0; idx < gate_challenges.size(); idx++) { gate_challenges[idx] = transcript->template get_challenge("Sumcheck:gate_challenge_" + std::to_string(idx)); } diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/Toy_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/Toy_verifier.cpp index 327822cfdd9..9ebb3713060 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/Toy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/Toy_verifier.cpp @@ -82,11 +82,14 @@ bool ToyVerifier::verify_proof(const HonkProof& proof) // Execute Sumcheck Verifier const size_t log_circuit_size = numeric::get_msb(circuit_size); auto sumcheck = SumcheckVerifier(log_circuit_size, transcript); + FF alpha = transcript->template get_challenge("Sumcheck:alpha"); + auto gate_challenges = std::vector(log_circuit_size); for (size_t idx = 0; idx < log_circuit_size; idx++) { gate_challenges[idx] = transcript->template get_challenge("Sumcheck:gate_challenge_" + std::to_string(idx)); } + auto [multivariate_challenge, claimed_evaluations, sumcheck_verified] = sumcheck.verify(relation_parameters, alpha, gate_challenges); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/Toy_verifier.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/Toy_verifier.hpp index d4bbdd2a998..115e91e2bb4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/Toy_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/Toy_verifier.hpp @@ -2,7 +2,7 @@ #pragma once #include "barretenberg/flavor/generated/Toy_flavor.hpp" -#include "barretenberg/honk/proof_system/types/proof.hpp" +#include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" namespace bb { diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp index cc8fe01c629..9fa1cabedaa 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp @@ -18,15 +18,17 @@ void validate_trace_proof(std::vector&& trace) auto composer = AvmMiniComposer(); auto prover = composer.create_prover(circuit_builder); auto proof = prover.construct_proof(); + info("proof created"); auto verifier = composer.create_verifier(circuit_builder); bool verified = verifier.verify_proof(proof); + info("proof verified"); EXPECT_TRUE(verified); - if (!verified) { - avm_trace::log_avmMini_trace(circuit_builder.rows, 0, 10); - } + // if (!verified) { + // avm_trace::log_avmMini_trace(circuit_builder.rows, 0, 10); + // } }; /** From e9cbc2e0604e4a8c27699e64bbf4f6456e116b2a Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 13 Feb 2024 17:53:26 +0000 Subject: [PATCH 3/9] fix --- barretenberg/cpp/pil/avm/avm_mini.pil | 3 +- barretenberg/cpp/pil/avm/toy_avm.pil | 9 +- .../flavor/generated/AvmMini_flavor.hpp | 111 ++++++------ .../flavor/generated/Toy_flavor.hpp | 71 ++++++-- .../generated/AvmMini_circuit_builder.hpp | 58 ++++--- .../generated/Toy_circuit_builder.hpp | 20 ++- .../toy_avm/toy_avm_circuit_builder.test.cpp | 40 +++++ .../relations/generated/AvmMini/alu_chip.hpp | 64 +++---- .../relations/generated/AvmMini/avm_mini.hpp | 72 ++++---- .../generated/AvmMini/declare_views.hpp | 23 +-- .../generated/AvmMini/equiv_tag_err.hpp | 162 +++++++++++++----- .../relations/generated/AvmMini/mem_trace.hpp | 32 ++-- .../relations/generated/Toy/declare_views.hpp | 8 +- .../relations/generated/Toy/lookup_err.hpp | 158 +++++++++++++++++ .../relations/generated/Toy/toy_avm.hpp | 2 +- .../generated/Toy/two_column_perm.hpp | 2 +- .../generic_permutation_relation.hpp | 19 +- .../vm/avm_trace/AvmMini_helper.cpp | 96 ++++++----- .../vm/avm_trace/AvmMini_mem_trace.cpp | 2 + .../vm/avm_trace/AvmMini_mem_trace.hpp | 4 + .../vm/avm_trace/AvmMini_trace.cpp | 13 ++ .../vm/avm_trace/AvmMini_trace.hpp | 1 + .../vm/generated/AvmMini_verifier.cpp | 2 + .../vm/generated/Toy_verifier.cpp | 8 + .../barretenberg/vm/tests/helpers.test.cpp | 9 +- 25 files changed, 691 insertions(+), 298 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/relations/generated/Toy/lookup_err.hpp diff --git a/barretenberg/cpp/pil/avm/avm_mini.pil b/barretenberg/cpp/pil/avm/avm_mini.pil index 88729e98e26..b638583ff7b 100644 --- a/barretenberg/cpp/pil/avm/avm_mini.pil +++ b/barretenberg/cpp/pil/avm/avm_mini.pil @@ -187,6 +187,7 @@ namespace avmMini(256); // Inter-table Constraints #[equiv_tag_err] - tag_err {clk} is memTrace.m_tag_err {memTrace.m_clk}; + memTrace.m_tag_err {memTrace.m_clk} in tag_err {clk}; + // TODO: Map memory trace with intermediate register values whenever there is no tag error, sthg like: // mem_op_a * (1 - tag_err) {mem_idx_a, clk, ia, rwa} IS m_sub_clk == 0 && 1 - m_tag_err {m_addr, m_clk, m_val, m_rw} diff --git a/barretenberg/cpp/pil/avm/toy_avm.pil b/barretenberg/cpp/pil/avm/toy_avm.pil index 422ff4d1a0e..434c380fd38 100644 --- a/barretenberg/cpp/pil/avm/toy_avm.pil +++ b/barretenberg/cpp/pil/avm/toy_avm.pil @@ -45,4 +45,11 @@ namespace toy(256); // Note - if no right hand side selector column is provided, then we will need to build the table ourselves // Note - we can also take advantage of pil creating the lookup columns for us here -> I may be able to do some codegen here ! #[lookup_xor] - q_xor { xor_a, xor_b, xor_c } in q_xor_table { table_xor_a, table_xor_b, table_xor_c }; \ No newline at end of file + q_xor { xor_a, xor_b, xor_c } in q_xor_table { table_xor_a, table_xor_b, table_xor_c }; + + // Minimum repro to try and fix jean's lookup issue + pol commit q_err, q_err_check; + pol commit clk, m_clk; + + #[lookup_err] + q_err_check {m_clk} in q_err {clk}; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index 8ff7a4f408a..49a26830f9b 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -15,7 +15,6 @@ #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/equiv_tag_err.hpp" #include "barretenberg/relations/generated/AvmMini/mem_trace.hpp" #include "barretenberg/transcript/transcript.hpp" @@ -38,16 +37,13 @@ class AvmMiniFlavor { using RelationSeparator = FF; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; - static constexpr size_t NUM_WITNESS_ENTITIES = 65; + static constexpr size_t NUM_WITNESS_ENTITIES = 66; static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES; // We have two copies of the witness entities, so we subtract the number of fixed ones (they have no shift), one for // the unshifted and one for the shifted - static constexpr size_t NUM_ALL_ENTITIES = 81; + static constexpr size_t NUM_ALL_ENTITIES = 82; - using Relations = std::tuple, - AvmMini_vm::alu_chip, - AvmMini_vm::avm_mini, - equiv_tag_err_relation>; + using Relations = std::tuple, AvmMini_vm::alu_chip, AvmMini_vm::mem_trace>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -145,7 +141,8 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - equiv_tag_err) + equiv_tag_err, + equiv_tag_err_counts) RefVector get_wires() { @@ -213,7 +210,8 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - equiv_tag_err }; + equiv_tag_err, + equiv_tag_err_counts }; }; RefVector get_sorted_polynomials() { return {}; }; }; @@ -288,20 +286,21 @@ class AvmMiniFlavor { avmMini_mem_idx_c, avmMini_last, equiv_tag_err, - memTrace_m_val_shift, - memTrace_m_tag_shift, - memTrace_m_rw_shift, - memTrace_m_addr_shift, - aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r2_shift, + equiv_tag_err_counts, + avmMini_pc_shift, + avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r6_shift, aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r4_shift, aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r1_shift, aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r6_shift, - avmMini_pc_shift, - avmMini_internal_return_ptr_shift) + memTrace_m_addr_shift, + memTrace_m_rw_shift, + memTrace_m_val_shift, + memTrace_m_tag_shift) RefVector get_wires() { @@ -372,20 +371,21 @@ class AvmMiniFlavor { avmMini_mem_idx_c, avmMini_last, equiv_tag_err, - memTrace_m_val_shift, - memTrace_m_tag_shift, - memTrace_m_rw_shift, - memTrace_m_addr_shift, - aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r2_shift, + equiv_tag_err_counts, + avmMini_pc_shift, + avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r6_shift, aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r2_shift, + aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r4_shift, aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r1_shift, aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r6_shift, - avmMini_pc_shift, - avmMini_internal_return_ptr_shift }; + memTrace_m_addr_shift, + memTrace_m_rw_shift, + memTrace_m_val_shift, + memTrace_m_tag_shift }; }; RefVector get_unshifted() { @@ -455,27 +455,28 @@ class AvmMiniFlavor { avmMini_mem_idx_b, avmMini_mem_idx_c, avmMini_last, - equiv_tag_err }; + equiv_tag_err, + equiv_tag_err_counts }; }; RefVector get_to_be_shifted() { - return { memTrace_m_val, memTrace_m_tag, - memTrace_m_rw, memTrace_m_addr, - aluChip_alu_u16_r1, aluChip_alu_u16_r7, - aluChip_alu_u16_r2, aluChip_alu_u16_r3, - aluChip_alu_u16_r5, aluChip_alu_u16_r0, - aluChip_alu_u16_r4, aluChip_alu_u16_r6, - avmMini_pc, avmMini_internal_return_ptr }; + return { avmMini_pc, avmMini_internal_return_ptr, + aluChip_alu_u16_r6, aluChip_alu_u16_r3, + aluChip_alu_u16_r2, aluChip_alu_u16_r7, + aluChip_alu_u16_r4, aluChip_alu_u16_r5, + aluChip_alu_u16_r1, aluChip_alu_u16_r0, + memTrace_m_addr, memTrace_m_rw, + memTrace_m_val, memTrace_m_tag }; }; RefVector get_shifted() { - return { memTrace_m_val_shift, memTrace_m_tag_shift, - memTrace_m_rw_shift, memTrace_m_addr_shift, - aluChip_alu_u16_r1_shift, aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r2_shift, aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r5_shift, aluChip_alu_u16_r0_shift, - aluChip_alu_u16_r4_shift, aluChip_alu_u16_r6_shift, - avmMini_pc_shift, avmMini_internal_return_ptr_shift }; + return { avmMini_pc_shift, avmMini_internal_return_ptr_shift, + aluChip_alu_u16_r6_shift, aluChip_alu_u16_r3_shift, + aluChip_alu_u16_r2_shift, aluChip_alu_u16_r7_shift, + aluChip_alu_u16_r4_shift, aluChip_alu_u16_r5_shift, + aluChip_alu_u16_r1_shift, aluChip_alu_u16_r0_shift, + memTrace_m_addr_shift, memTrace_m_rw_shift, + memTrace_m_val_shift, memTrace_m_tag_shift }; }; }; @@ -488,13 +489,13 @@ class AvmMiniFlavor { RefVector get_to_be_shifted() { - return { memTrace_m_val, memTrace_m_tag, - memTrace_m_rw, memTrace_m_addr, - aluChip_alu_u16_r1, aluChip_alu_u16_r7, - aluChip_alu_u16_r2, aluChip_alu_u16_r3, - aluChip_alu_u16_r5, aluChip_alu_u16_r0, - aluChip_alu_u16_r4, aluChip_alu_u16_r6, - avmMini_pc, avmMini_internal_return_ptr }; + return { avmMini_pc, avmMini_internal_return_ptr, + aluChip_alu_u16_r6, aluChip_alu_u16_r3, + aluChip_alu_u16_r2, aluChip_alu_u16_r7, + aluChip_alu_u16_r4, aluChip_alu_u16_r5, + aluChip_alu_u16_r1, aluChip_alu_u16_r0, + memTrace_m_addr, memTrace_m_rw, + memTrace_m_val, memTrace_m_tag }; }; // The plookup wires that store plookup read data. @@ -638,6 +639,7 @@ class AvmMiniFlavor { Base::avmMini_mem_idx_c = "AVMMINI_MEM_IDX_C"; Base::avmMini_last = "AVMMINI_LAST"; Base::equiv_tag_err = "EQUIV_TAG_ERR"; + Base::equiv_tag_err_counts = "EQUIV_TAG_ERR_COUNTS"; }; }; @@ -722,6 +724,7 @@ class AvmMiniFlavor { Commitment avmMini_mem_idx_c; Commitment avmMini_last; Commitment equiv_tag_err; + Commitment equiv_tag_err_counts; std::vector> sumcheck_univariates; std::array sumcheck_evaluations; @@ -806,6 +809,7 @@ class AvmMiniFlavor { avmMini_mem_idx_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avmMini_last = deserialize_from_buffer(Transcript::proof_data, num_frs_read); equiv_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + equiv_tag_err_counts = deserialize_from_buffer(Transcript::proof_data, num_frs_read); for (size_t i = 0; i < log_n; ++i) { sumcheck_univariates.emplace_back( @@ -894,6 +898,7 @@ class AvmMiniFlavor { serialize_to_buffer(avmMini_mem_idx_c, Transcript::proof_data); serialize_to_buffer(avmMini_last, Transcript::proof_data); serialize_to_buffer(equiv_tag_err, Transcript::proof_data); + serialize_to_buffer(equiv_tag_err_counts, Transcript::proof_data); for (size_t i = 0; i < log_n; ++i) { serialize_to_buffer(sumcheck_univariates[i], Transcript::proof_data); diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/Toy_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/Toy_flavor.hpp index 1d88605d122..c649bec437a 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/Toy_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/Toy_flavor.hpp @@ -36,11 +36,11 @@ class ToyFlavor { using RelationSeparator = FF; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 1; - static constexpr size_t NUM_WITNESS_ENTITIES = 16; + static constexpr size_t NUM_WITNESS_ENTITIES = 22; 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 = 17; + static constexpr size_t NUM_ALL_ENTITIES = 23; using Relations = std::tuple, two_column_perm_relation>; @@ -89,16 +89,23 @@ class ToyFlavor { toy_table_xor_c, toy_q_xor, toy_q_xor_table, + toy_q_err, + toy_q_err_check, + toy_clk, + toy_m_clk, two_column_perm, lookup_xor, - lookup_xor_counts) + lookup_err, + lookup_xor_counts, + lookup_err_counts) RefVector get_wires() { - return { toy_q_tuple_set, toy_set_1_column_1, toy_set_1_column_2, toy_set_2_column_1, - toy_set_2_column_2, toy_xor_a, toy_xor_b, toy_xor_c, - toy_table_xor_a, toy_table_xor_b, toy_table_xor_c, toy_q_xor, - toy_q_xor_table, two_column_perm, lookup_xor, lookup_xor_counts }; + return { toy_q_tuple_set, toy_set_1_column_1, toy_set_1_column_2, toy_set_2_column_1, toy_set_2_column_2, + toy_xor_a, toy_xor_b, toy_xor_c, toy_table_xor_a, toy_table_xor_b, + toy_table_xor_c, toy_q_xor, toy_q_xor_table, toy_q_err, toy_q_err_check, + toy_clk, toy_m_clk, two_column_perm, lookup_xor, lookup_err, + lookup_xor_counts, lookup_err_counts }; }; RefVector get_sorted_polynomials() { return {}; }; }; @@ -120,23 +127,31 @@ class ToyFlavor { toy_table_xor_c, toy_q_xor, toy_q_xor_table, + toy_q_err, + toy_q_err_check, + toy_clk, + toy_m_clk, two_column_perm, lookup_xor, - lookup_xor_counts) + lookup_err, + lookup_xor_counts, + lookup_err_counts) RefVector get_wires() { - return { toy_first, toy_q_tuple_set, toy_set_1_column_1, toy_set_1_column_2, toy_set_2_column_1, - toy_set_2_column_2, toy_xor_a, toy_xor_b, toy_xor_c, toy_table_xor_a, - toy_table_xor_b, toy_table_xor_c, toy_q_xor, toy_q_xor_table, two_column_perm, - lookup_xor, lookup_xor_counts }; + return { toy_first, toy_q_tuple_set, toy_set_1_column_1, toy_set_1_column_2, toy_set_2_column_1, + toy_set_2_column_2, toy_xor_a, toy_xor_b, toy_xor_c, toy_table_xor_a, + toy_table_xor_b, toy_table_xor_c, toy_q_xor, toy_q_xor_table, toy_q_err, + toy_q_err_check, toy_clk, toy_m_clk, two_column_perm, lookup_xor, + lookup_err, lookup_xor_counts, lookup_err_counts }; }; RefVector get_unshifted() { - return { toy_first, toy_q_tuple_set, toy_set_1_column_1, toy_set_1_column_2, toy_set_2_column_1, - toy_set_2_column_2, toy_xor_a, toy_xor_b, toy_xor_c, toy_table_xor_a, - toy_table_xor_b, toy_table_xor_c, toy_q_xor, toy_q_xor_table, two_column_perm, - lookup_xor, lookup_xor_counts }; + return { toy_first, toy_q_tuple_set, toy_set_1_column_1, toy_set_1_column_2, toy_set_2_column_1, + toy_set_2_column_2, toy_xor_a, toy_xor_b, toy_xor_c, toy_table_xor_a, + toy_table_xor_b, toy_table_xor_c, toy_q_xor, toy_q_xor_table, toy_q_err, + toy_q_err_check, toy_clk, toy_m_clk, two_column_perm, lookup_xor, + lookup_err, lookup_xor_counts, lookup_err_counts }; }; RefVector get_to_be_shifted() { return {}; }; RefVector get_shifted() { return {}; }; @@ -239,9 +254,15 @@ class ToyFlavor { Base::toy_table_xor_c = "TOY_TABLE_XOR_C"; Base::toy_q_xor = "TOY_Q_XOR"; Base::toy_q_xor_table = "TOY_Q_XOR_TABLE"; + Base::toy_q_err = "TOY_Q_ERR"; + Base::toy_q_err_check = "TOY_Q_ERR_CHECK"; + Base::toy_clk = "TOY_CLK"; + Base::toy_m_clk = "TOY_M_CLK"; Base::two_column_perm = "TWO_COLUMN_PERM"; Base::lookup_xor = "LOOKUP_XOR"; + Base::lookup_err = "LOOKUP_ERR"; Base::lookup_xor_counts = "LOOKUP_XOR_COUNTS"; + Base::lookup_err_counts = "LOOKUP_ERR_COUNTS"; }; }; @@ -273,9 +294,15 @@ class ToyFlavor { Commitment toy_table_xor_c; Commitment toy_q_xor; Commitment toy_q_xor_table; + Commitment toy_q_err; + Commitment toy_q_err_check; + Commitment toy_clk; + Commitment toy_m_clk; Commitment two_column_perm; Commitment lookup_xor; + Commitment lookup_err; Commitment lookup_xor_counts; + Commitment lookup_err_counts; std::vector> sumcheck_univariates; std::array sumcheck_evaluations; @@ -308,9 +335,15 @@ class ToyFlavor { toy_table_xor_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); toy_q_xor = deserialize_from_buffer(Transcript::proof_data, num_frs_read); toy_q_xor_table = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + toy_q_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + toy_q_err_check = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + toy_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + toy_m_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); two_column_perm = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_xor = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + lookup_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_xor_counts = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + lookup_err_counts = deserialize_from_buffer(Transcript::proof_data, num_frs_read); for (size_t i = 0; i < log_n; ++i) { sumcheck_univariates.emplace_back( @@ -347,9 +380,15 @@ class ToyFlavor { serialize_to_buffer(toy_table_xor_c, Transcript::proof_data); serialize_to_buffer(toy_q_xor, Transcript::proof_data); serialize_to_buffer(toy_q_xor_table, Transcript::proof_data); + serialize_to_buffer(toy_q_err, Transcript::proof_data); + serialize_to_buffer(toy_q_err_check, Transcript::proof_data); + serialize_to_buffer(toy_clk, Transcript::proof_data); + serialize_to_buffer(toy_m_clk, Transcript::proof_data); serialize_to_buffer(two_column_perm, Transcript::proof_data); serialize_to_buffer(lookup_xor, Transcript::proof_data); + serialize_to_buffer(lookup_err, Transcript::proof_data); serialize_to_buffer(lookup_xor_counts, Transcript::proof_data); + serialize_to_buffer(lookup_err_counts, Transcript::proof_data); for (size_t i = 0; i < log_n; ++i) { serialize_to_buffer(sumcheck_univariates[i], Transcript::proof_data); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp index 48e1f3ef18c..7f292e5b208 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp @@ -87,20 +87,21 @@ template struct AvmMiniFullRow { FF avmMini_mem_idx_c{}; FF avmMini_last{}; FF equiv_tag_err{}; - FF memTrace_m_val_shift{}; - FF memTrace_m_tag_shift{}; - FF memTrace_m_rw_shift{}; - FF memTrace_m_addr_shift{}; - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r2_shift{}; + FF equiv_tag_err_counts{}; + FF avmMini_pc_shift{}; + FF avmMini_internal_return_ptr_shift{}; + FF aluChip_alu_u16_r6_shift{}; FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_u16_r2_shift{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r4_shift{}; FF aluChip_alu_u16_r5_shift{}; + FF aluChip_alu_u16_r1_shift{}; FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_u16_r6_shift{}; - FF avmMini_pc_shift{}; - FF avmMini_internal_return_ptr_shift{}; + FF memTrace_m_addr_shift{}; + FF memTrace_m_rw_shift{}; + FF memTrace_m_val_shift{}; + FF memTrace_m_tag_shift{}; }; class AvmMiniCircuitBuilder { @@ -113,8 +114,8 @@ class AvmMiniCircuitBuilder { using Polynomial = Flavor::Polynomial; using ProverPolynomials = Flavor::ProverPolynomials; - static constexpr size_t num_fixed_columns = 81; - static constexpr size_t num_polys = 67; + static constexpr size_t num_fixed_columns = 82; + static constexpr size_t num_polys = 68; std::vector rows; void set_trace(std::vector&& trace) { rows = std::move(trace); } @@ -197,22 +198,23 @@ class AvmMiniCircuitBuilder { polys.avmMini_mem_idx_c[i] = rows[i].avmMini_mem_idx_c; polys.avmMini_last[i] = rows[i].avmMini_last; polys.equiv_tag_err[i] = rows[i].equiv_tag_err; + polys.equiv_tag_err_counts[i] = rows[i].equiv_tag_err_counts; } - polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); - polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); - polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); - 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_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); + polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); + polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); + polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); + polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); + polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); + polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); + polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); - polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); - polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.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_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); + polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); + polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); + polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); return polys; } @@ -284,16 +286,16 @@ class AvmMiniCircuitBuilder { return true; }; - if (!evaluate_relation.template operator()>( - "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { + if (!evaluate_relation.template operator()>("avm_mini", + AvmMini_vm::get_relation_label_avm_mini)) { return false; } if (!evaluate_relation.template operator()>("alu_chip", AvmMini_vm::get_relation_label_alu_chip)) { return false; } - if (!evaluate_relation.template operator()>("avm_mini", - AvmMini_vm::get_relation_label_avm_mini)) { + if (!evaluate_relation.template operator()>( + "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { return false; } diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Toy_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Toy_circuit_builder.hpp index 207b5a9e21e..7f3252d7e87 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Toy_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Toy_circuit_builder.hpp @@ -12,6 +12,7 @@ #include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" #include "barretenberg/flavor/generated/Toy_flavor.hpp" +#include "barretenberg/relations/generated/Toy/lookup_err.hpp" #include "barretenberg/relations/generated/Toy/lookup_xor.hpp" #include "barretenberg/relations/generated/Toy/toy_avm.hpp" #include "barretenberg/relations/generated/Toy/two_column_perm.hpp" @@ -33,9 +34,15 @@ template struct ToyFullRow { FF toy_table_xor_c{}; FF toy_q_xor{}; FF toy_q_xor_table{}; + FF toy_q_err{}; + FF toy_q_err_check{}; + FF toy_clk{}; + FF toy_m_clk{}; FF two_column_perm{}; FF lookup_xor{}; + FF lookup_err{}; FF lookup_xor_counts{}; + FF lookup_err_counts{}; }; class ToyCircuitBuilder { @@ -48,8 +55,8 @@ class ToyCircuitBuilder { using Polynomial = Flavor::Polynomial; using ProverPolynomials = Flavor::ProverPolynomials; - static constexpr size_t num_fixed_columns = 17; - static constexpr size_t num_polys = 17; + static constexpr size_t num_fixed_columns = 23; + static constexpr size_t num_polys = 23; std::vector rows; void set_trace(std::vector&& trace) { rows = std::move(trace); } @@ -79,9 +86,15 @@ class ToyCircuitBuilder { polys.toy_table_xor_c[i] = rows[i].toy_table_xor_c; polys.toy_q_xor[i] = rows[i].toy_q_xor; polys.toy_q_xor_table[i] = rows[i].toy_q_xor_table; + polys.toy_q_err[i] = rows[i].toy_q_err; + polys.toy_q_err_check[i] = rows[i].toy_q_err_check; + polys.toy_clk[i] = rows[i].toy_clk; + polys.toy_m_clk[i] = rows[i].toy_m_clk; polys.two_column_perm[i] = rows[i].two_column_perm; polys.lookup_xor[i] = rows[i].lookup_xor; + polys.lookup_err[i] = rows[i].lookup_err; polys.lookup_xor_counts[i] = rows[i].lookup_xor_counts; + polys.lookup_err_counts[i] = rows[i].lookup_err_counts; } return polys; @@ -165,6 +178,9 @@ class ToyCircuitBuilder { if (!evaluate_logderivative.template operator()>("lookup_xor")) { return false; } + if (!evaluate_logderivative.template operator()>("lookup_err")) { + return false; + } return true; } diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp index 7c395269104..27ef2a174c2 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp @@ -115,3 +115,43 @@ TEST(ToyAVMCircuitBuilder, BaseCase) circuit_builder.rows[2].toy_xor_a = tmp; EXPECT_EQ(circuit_builder.check_circuit(), true); } + +/** + * @brief Investigate circuit builder / proving issue + * + */ +TEST(ToyAVMCircuitBuilder, MultiLookup) +{ + using FF = ToyFlavor::FF; + using Builder = ToyCircuitBuilder; + using Row = Builder::Row; + Builder circuit_builder; + + const size_t circuit_size = 16; + std::vector rows; + // init empty rows + for (size_t i = 0; i < circuit_size; i++) { + Row row{}; + rows.push_back(row); + } + + // LOOKUPS + // Create clk mem access lookup table; + // We only want to turn on the mem write when clk is 1 + Row& row_1 = rows[0]; + row_1.toy_q_err = FF(1); + row_1.toy_clk = FF(1); + row_1.lookup_err_counts = FF(2); + + // Set the mem read on two different rows, we will then lookup into the clk + row_1.toy_m_clk = FF(1); + row_1.toy_q_err_check = FF(1); + + Row& row_3 = rows[2]; + row_3.toy_m_clk = FF(1); + row_3.toy_q_err_check = FF(1); + + // Check circuit passes + circuit_builder.set_trace(std::move(rows)); + EXPECT_EQ(circuit_builder.check_circuit(), true); +} diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp index 0659f7b8dba..001fb69bcf2 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/alu_chip.hpp @@ -7,60 +7,60 @@ namespace bb::AvmMini_vm { template struct Alu_chipRow { - FF aluChip_alu_u16_r7{}; - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u64_tag{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u8_r0{}; - FF aluChip_alu_u16_r1{}; + FF aluChip_alu_ff_tag{}; + FF aluChip_alu_op_add{}; + FF aluChip_alu_u16_r3{}; + FF aluChip_alu_ib{}; + FF aluChip_alu_u16_r6_shift{}; + FF aluChip_alu_u64_r0{}; + FF aluChip_alu_u8_r1{}; + FF aluChip_alu_u16_tag{}; + FF aluChip_alu_op_sub{}; + FF aluChip_alu_ic{}; + FF aluChip_alu_u128_tag{}; + FF aluChip_alu_u8_tag{}; + FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_u16_r2{}; FF aluChip_alu_u16_r5{}; FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u32_tag{}; - FF aluChip_alu_cf{}; + FF aluChip_alu_op_mul{}; + FF aluChip_alu_u16_r1{}; FF aluChip_alu_ia{}; FF aluChip_alu_u16_r0{}; - FF aluChip_alu_ic{}; - FF aluChip_alu_u16_r3_shift{}; + FF aluChip_alu_u16_r7_shift{}; + FF aluChip_alu_u16_r4_shift{}; FF aluChip_alu_u16_r5_shift{}; FF aluChip_alu_u16_r4{}; - FF aluChip_alu_op_mul{}; - FF aluChip_alu_u16_r3{}; - FF aluChip_alu_u8_r1{}; - FF aluChip_alu_op_sub{}; + FF aluChip_alu_u16_r7{}; + FF aluChip_alu_u16_r1_shift{}; FF aluChip_alu_u16_r0_shift{}; - FF aluChip_alu_u8_tag{}; - FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_op_add{}; - FF aluChip_alu_u128_tag{}; - FF aluChip_alu_u64_r0{}; - FF aluChip_alu_u16_r2{}; - FF aluChip_alu_ff_tag{}; - FF aluChip_alu_u16_tag{}; FF aluChip_alu_u16_r6{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_ib{}; + FF aluChip_alu_u64_tag{}; + FF aluChip_alu_u32_tag{}; + FF aluChip_alu_u8_r0{}; + FF aluChip_alu_cf{}; }; inline std::string get_relation_label_alu_chip(int index) { switch (index) { - case 7: - return "ALU_ADD_SUB_2"; + case 6: + return "ALU_ADD_SUB_1"; case 13: return "ALU_MULTIPLICATION_OUT_U128"; - case 6: - return "ALU_ADD_SUB_1"; + case 10: + return "ALU_MUL_COMMON_2"; - case 9: - return "ALU_MUL_COMMON_1"; + case 7: + return "ALU_ADD_SUB_2"; case 8: return "ALU_MULTIPLICATION_FF"; - case 10: - return "ALU_MUL_COMMON_2"; + case 9: + return "ALU_MUL_COMMON_1"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp index bcf0384b827..51713ffef6a 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/avm_mini.hpp @@ -7,61 +7,61 @@ namespace bb::AvmMini_vm { template struct Avm_miniRow { - FF avmMini_first{}; - FF avmMini_rwc{}; - FF avmMini_rwa{}; - FF avmMini_sel_internal_return{}; - FF avmMini_tag_err{}; - FF avmMini_mem_op_a{}; - FF avmMini_ia{}; - FF avmMini_inv{}; - FF avmMini_mem_op_b{}; - FF avmMini_mem_op_c{}; - FF avmMini_sel_op_div{}; - FF avmMini_internal_return_ptr{}; - FF avmMini_pc{}; - FF avmMini_mem_idx_b{}; FF avmMini_pc_shift{}; - FF avmMini_sel_op_add{}; FF avmMini_sel_op_sub{}; - FF avmMini_op_err{}; - FF avmMini_internal_return_ptr_shift{}; - FF avmMini_mem_idx_a{}; FF avmMini_sel_op_mul{}; - FF avmMini_sel_halt{}; + FF avmMini_ia{}; + FF avmMini_internal_return_ptr{}; + FF avmMini_rwa{}; + FF avmMini_sel_internal_call{}; FF avmMini_ib{}; + FF avmMini_mem_idx_a{}; FF avmMini_sel_jump{}; - FF avmMini_ic{}; - FF avmMini_sel_internal_call{}; + FF avmMini_sel_op_div{}; + FF avmMini_sel_op_add{}; + FF avmMini_tag_err{}; + FF avmMini_sel_halt{}; + FF avmMini_mem_op_b{}; + FF avmMini_sel_internal_return{}; FF avmMini_rwb{}; + FF avmMini_mem_op_c{}; + FF avmMini_mem_op_a{}; + FF avmMini_rwc{}; + FF avmMini_ic{}; + FF avmMini_inv{}; + FF avmMini_internal_return_ptr_shift{}; + FF avmMini_mem_idx_b{}; + FF avmMini_op_err{}; + FF avmMini_pc{}; + FF avmMini_first{}; }; inline std::string get_relation_label_avm_mini(int index) { switch (index) { - case 19: - return "SUBOP_DIVISION_FF"; - - case 20: - return "SUBOP_DIVISION_ZERO_ERR1"; + case 35: + return "PC_INCREMENT"; - case 24: - return "RETURN_POINTER_INCREMENT"; + case 21: + return "SUBOP_DIVISION_ZERO_ERR2"; - case 36: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + case 30: + return "RETURN_POINTER_DECREMENT"; case 22: return "SUBOP_ERROR_RELEVANT_OP"; - case 21: - return "SUBOP_DIVISION_ZERO_ERR2"; + case 36: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - case 30: - return "RETURN_POINTER_DECREMENT"; + case 24: + return "RETURN_POINTER_INCREMENT"; - case 35: - return "PC_INCREMENT"; + case 20: + return "SUBOP_DIVISION_ZERO_ERR1"; + + case 19: + return "SUBOP_DIVISION_FF"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp index 2cf1a7274ac..ea136b1ebbf 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/declare_views.hpp @@ -69,17 +69,18 @@ [[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 equiv_tag_err = View(new_term.equiv_tag_err); \ - [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ - [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); \ - [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ - [[maybe_unused]] auto memTrace_m_addr_shift = View(new_term.memTrace_m_addr_shift); \ - [[maybe_unused]] auto 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_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ + [[maybe_unused]] auto equiv_tag_err_counts = View(new_term.equiv_tag_err_counts); \ + [[maybe_unused]] auto avmMini_pc_shift = View(new_term.avmMini_pc_shift); \ + [[maybe_unused]] auto avmMini_internal_return_ptr_shift = View(new_term.avmMini_internal_return_ptr_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r3_shift = View(new_term.aluChip_alu_u16_r3_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r2_shift = View(new_term.aluChip_alu_u16_r2_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r7_shift = View(new_term.aluChip_alu_u16_r7_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r5_shift = View(new_term.aluChip_alu_u16_r5_shift); \ + [[maybe_unused]] auto aluChip_alu_u16_r1_shift = View(new_term.aluChip_alu_u16_r1_shift); \ [[maybe_unused]] auto aluChip_alu_u16_r0_shift = View(new_term.aluChip_alu_u16_r0_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r4_shift = View(new_term.aluChip_alu_u16_r4_shift); \ - [[maybe_unused]] auto aluChip_alu_u16_r6_shift = View(new_term.aluChip_alu_u16_r6_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_addr_shift = View(new_term.memTrace_m_addr_shift); \ + [[maybe_unused]] auto memTrace_m_rw_shift = View(new_term.memTrace_m_rw_shift); \ + [[maybe_unused]] auto memTrace_m_val_shift = View(new_term.memTrace_m_val_shift); \ + [[maybe_unused]] auto memTrace_m_tag_shift = View(new_term.memTrace_m_tag_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/equiv_tag_err.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/equiv_tag_err.hpp index 9ab2e489aed..eb533b1b710 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/equiv_tag_err.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/equiv_tag_err.hpp @@ -2,89 +2,165 @@ #pragma once -#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" +#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp" #include #include namespace bb { -class equiv_tag_err_permutation_settings { +/** + * @brief This class contains an example of how to set LookupSettings classes used by the + * GenericLookupRelationImpl class to specify a scaled lookup + * + * @details To create your own lookup: + * 1) Create a copy of this class and rename it + * 2) Update all the values with the ones needed for your lookup + * 3) Update "DECLARE_LOOKUP_IMPLEMENTATIONS_FOR_ALL_SETTINGS" and "DEFINE_LOOKUP_IMPLEMENTATIONS_FOR_ALL_SETTINGS" to + * include the new settings + * 4) Add the relation with the chosen settings to Relations in the flavor (for example,"` + * using Relations = std::tuple>;)` + * + */ +class equiv_tag_err_lookup_settings { public: - // This constant defines how many columns are bundled together to form each set. - constexpr static size_t COLUMNS_PER_SET = 1; + /** + * @brief The number of read terms (how many lookups we perform) in each row + * + */ + static constexpr size_t READ_TERMS = 1; + /** + * @brief The number of write terms (how many additions to the lookup table we make) in each row + * + */ + static constexpr size_t WRITE_TERMS = 1; + + /** + * @brief The type of READ_TERM used for each read index (basic and scaled) + * + */ + static constexpr size_t READ_TERM_TYPES[READ_TERMS] = { 0 }; + + /** + * @brief They type of WRITE_TERM used for each write index + * + */ + static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = { 0 }; + + /** + * @brief How many values represent a single lookup object. This value is used by the automatic read term + * implementation in the relation in case the lookup is a basic or scaled tuple and in the write term if it's a + * basic tuple + * + */ + static constexpr size_t LOOKUP_TUPLE_SIZE = 1; /** - * @brief If this method returns true on a row of values, then the inverse polynomial at this index. Otherwise the - * value needs to be set to zero. + * @brief The polynomial degree of the relation telling us if the inverse polynomial value needs to be computed + * + */ + static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 2; + + /** + * @brief The degree of the read term if implemented arbitrarily. This value is not used by basic and scaled read + * terms, but will cause compilation error if not defined + * + */ + static constexpr size_t READ_TERM_DEGREE = 0; + + /** + * @brief The degree of the write term if implemented arbitrarily. This value is not used by the basic write + * term, but will cause compilation error if not defined + * + */ + + static constexpr size_t WRITE_TERM_DEGREE = 0; + + /** + * @brief If this method returns true on a row of values, then the inverse polynomial exists at this index. + * Otherwise the value needs to be set to zero. + * + * @details If this is true then the lookup takes place in this row * - * @details If this is true then permutation takes place in this row */ template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avmMini_tag_err == 1 || in.memTrace_m_tag_err == 1); + return (in.memTrace_m_tag_err == 1 || in.avmMini_tag_err == 1); } /** - * @brief Get all the entities for the permutation when we don't need to update them + * @brief Subprocedure for computing the value deciding if the inverse polynomial value needs to be checked in this + * row * - * @details The entities are returned as a tuple of references in the following order: + * @tparam Accumulator Type specified by the lookup relation + * @tparam AllEntities Values/Univariates of all entities row + * @param in Value/Univariate of all entities at row/edge + * @return Accumulator + */ + + template + static inline auto compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + const auto is_operation = View(in.memTrace_m_tag_err); + const auto is_table_entry = View(in.avmMini_tag_err); + return (is_operation + is_table_entry - is_operation * is_table_entry); + } + + /** + * @brief Get all the entities for the lookup when need to update them + * + * @details The generic structure of this tuple is described in ./generic_lookup_relation.hpp . The following is + description for the current case: + The entities are returned as a tuple of references in the following order (this is for ): * - The entity/polynomial used to store the product of the inverse values - * - The entity/polynomial that switches on the subrelation of the permutation relation that ensures correctness of - * the inverse polynomial - * - The entity/polynomial that enables adding a tuple-generated value from the first set to the logderivative sum - * subrelation - * - The entity/polynomial that enables adding a tuple-generated value from the second set to the logderivative sum - * subrelation - * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the first set (N.B. ORDER IS IMPORTANT!) - * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the second set (N.B. ORDER IS IMPORTANT!) + * - The entity/polynomial that specifies how many times the lookup table entry at this row has been looked up + * - READ_TERMS entities/polynomials that enable individual lookup operations + * - The entity/polynomial that enables adding an entry to the lookup table in this row + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the basic tuple being looked up as the first read term + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the previous accumulators in the second read term + (scaled tuple) + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the shifts in the second read term (scaled tuple) + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the current accumulators in the second read term + (scaled tuple) + * - LOOKUP_TUPLE_SIZE entities/polynomials representing basic tuples added to the table * - * @return All the entities needed for the permutation + * @return All the entities needed for the lookup */ template static inline auto get_const_entities(const AllEntities& in) { return std::forward_as_tuple(in.equiv_tag_err, - in.avmMini_tag_err, - in.avmMini_tag_err, + in.equiv_tag_err_counts, in.memTrace_m_tag_err, - in.avmMini_clk, - in.memTrace_m_clk); + in.avmMini_tag_err, + in.memTrace_m_clk, + in.avmMini_clk); } /** - * @brief Get all the entities for the permutation when need to update them + * @brief Get all the entities for the lookup when we only need to read them + * @details Same as in get_const_entities, but nonconst * - * @details The entities are returned as a tuple of references in the following order: - * - The entity/polynomial used to store the product of the inverse values - * - The entity/polynomial that switches on the subrelation of the permutation relation that ensures correctness of - * the inverse polynomial - * - The entity/polynomial that enables adding a tuple-generated value from the first set to the logderivative sum - * subrelation - * - The entity/polynomial that enables adding a tuple-generated value from the second set to the logderivative sum - * subrelation - * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the first set (N.B. ORDER IS IMPORTANT!) - * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the second set (N.B. ORDER IS IMPORTANT!) - * - * @return All the entities needed for the permutation + * @return All the entities needed for the lookup */ template static inline auto get_nonconst_entities(AllEntities& in) { return std::forward_as_tuple(in.equiv_tag_err, - in.avmMini_tag_err, - in.avmMini_tag_err, + in.equiv_tag_err_counts, in.memTrace_m_tag_err, - in.avmMini_clk, - in.memTrace_m_clk); + in.avmMini_tag_err, + in.memTrace_m_clk, + in.avmMini_clk); } }; -template -using equiv_tag_err_relation = GenericPermutationRelation; -template using equiv_tag_err = GenericPermutation; +template using equiv_tag_err_relation = GenericLookupRelation; +template using equiv_tag_err = GenericLookup; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp index 08354bf4029..05ad5888bce 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/AvmMini/mem_trace.hpp @@ -7,41 +7,41 @@ namespace bb::AvmMini_vm { template struct Mem_traceRow { - FF memTrace_m_last{}; + FF memTrace_m_addr_shift{}; FF memTrace_m_addr{}; - FF memTrace_m_val_shift{}; + FF memTrace_m_rw_shift{}; + FF memTrace_m_in_tag{}; FF memTrace_m_val{}; + FF memTrace_m_tag_err{}; + FF memTrace_m_val_shift{}; FF memTrace_m_tag_shift{}; + FF memTrace_m_last{}; + FF memTrace_m_tag{}; FF memTrace_m_one_min_inv{}; FF memTrace_m_lastAccess{}; - FF memTrace_m_tag_err{}; FF memTrace_m_rw{}; - FF memTrace_m_rw_shift{}; - FF memTrace_m_addr_shift{}; - FF memTrace_m_tag{}; - FF memTrace_m_in_tag{}; }; inline std::string get_relation_label_mem_trace(int index) { switch (index) { + case 6: + return "MEM_READ_WRITE_TAG_CONSISTENCY"; + case 5: return "MEM_READ_WRITE_VAL_CONSISTENCY"; + case 4: + return "MEM_LAST_ACCESS_DELIMITER"; + + case 7: + return "MEM_ZERO_INIT"; + case 8: return "MEM_IN_TAG_CONSISTENCY_1"; - case 6: - return "MEM_READ_WRITE_TAG_CONSISTENCY"; - case 9: return "MEM_IN_TAG_CONSISTENCY_2"; - - case 7: - return "MEM_ZERO_INIT"; - - case 4: - return "MEM_LAST_ACCESS_DELIMITER"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/Toy/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/Toy/declare_views.hpp index 98e120768ea..04ea89bf3a1 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/Toy/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/Toy/declare_views.hpp @@ -16,6 +16,12 @@ [[maybe_unused]] auto toy_table_xor_c = View(new_term.toy_table_xor_c); \ [[maybe_unused]] auto toy_q_xor = View(new_term.toy_q_xor); \ [[maybe_unused]] auto toy_q_xor_table = View(new_term.toy_q_xor_table); \ + [[maybe_unused]] auto toy_q_err = View(new_term.toy_q_err); \ + [[maybe_unused]] auto toy_q_err_check = View(new_term.toy_q_err_check); \ + [[maybe_unused]] auto toy_clk = View(new_term.toy_clk); \ + [[maybe_unused]] auto toy_m_clk = View(new_term.toy_m_clk); \ [[maybe_unused]] auto two_column_perm = View(new_term.two_column_perm); \ [[maybe_unused]] auto lookup_xor = View(new_term.lookup_xor); \ - [[maybe_unused]] auto lookup_xor_counts = View(new_term.lookup_xor_counts); + [[maybe_unused]] auto lookup_err = View(new_term.lookup_err); \ + [[maybe_unused]] auto lookup_xor_counts = View(new_term.lookup_xor_counts); \ + [[maybe_unused]] auto lookup_err_counts = View(new_term.lookup_err_counts); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/Toy/lookup_err.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/Toy/lookup_err.hpp new file mode 100644 index 00000000000..3cbb30d718f --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/Toy/lookup_err.hpp @@ -0,0 +1,158 @@ + + +#pragma once + +#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp" + +#include +#include + +namespace bb { + +/** + * @brief This class contains an example of how to set LookupSettings classes used by the + * GenericLookupRelationImpl class to specify a scaled lookup + * + * @details To create your own lookup: + * 1) Create a copy of this class and rename it + * 2) Update all the values with the ones needed for your lookup + * 3) Update "DECLARE_LOOKUP_IMPLEMENTATIONS_FOR_ALL_SETTINGS" and "DEFINE_LOOKUP_IMPLEMENTATIONS_FOR_ALL_SETTINGS" to + * include the new settings + * 4) Add the relation with the chosen settings to Relations in the flavor (for example,"` + * using Relations = std::tuple>;)` + * + */ +class lookup_err_lookup_settings { + public: + /** + * @brief The number of read terms (how many lookups we perform) in each row + * + */ + static constexpr size_t READ_TERMS = 1; + /** + * @brief The number of write terms (how many additions to the lookup table we make) in each row + * + */ + static constexpr size_t WRITE_TERMS = 1; + + /** + * @brief The type of READ_TERM used for each read index (basic and scaled) + * + */ + static constexpr size_t READ_TERM_TYPES[READ_TERMS] = { 0 }; + + /** + * @brief They type of WRITE_TERM used for each write index + * + */ + static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = { 0 }; + + /** + * @brief How many values represent a single lookup object. This value is used by the automatic read term + * implementation in the relation in case the lookup is a basic or scaled tuple and in the write term if it's a + * basic tuple + * + */ + static constexpr size_t LOOKUP_TUPLE_SIZE = 1; + + /** + * @brief The polynomial degree of the relation telling us if the inverse polynomial value needs to be computed + * + */ + static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 2; + + /** + * @brief The degree of the read term if implemented arbitrarily. This value is not used by basic and scaled read + * terms, but will cause compilation error if not defined + * + */ + static constexpr size_t READ_TERM_DEGREE = 0; + + /** + * @brief The degree of the write term if implemented arbitrarily. This value is not used by the basic write + * term, but will cause compilation error if not defined + * + */ + + static constexpr size_t WRITE_TERM_DEGREE = 0; + + /** + * @brief If this method returns true on a row of values, then the inverse polynomial exists at this index. + * Otherwise the value needs to be set to zero. + * + * @details If this is true then the lookup takes place in this row + * + */ + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in.toy_q_err_check == 1 || in.toy_q_err == 1); + } + + /** + * @brief Subprocedure for computing the value deciding if the inverse polynomial value needs to be checked in this + * row + * + * @tparam Accumulator Type specified by the lookup relation + * @tparam AllEntities Values/Univariates of all entities row + * @param in Value/Univariate of all entities at row/edge + * @return Accumulator + */ + + template + static inline auto compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + const auto is_operation = View(in.toy_q_err_check); + const auto is_table_entry = View(in.toy_q_err); + return (is_operation + is_table_entry - is_operation * is_table_entry); + } + + /** + * @brief Get all the entities for the lookup when need to update them + * + * @details The generic structure of this tuple is described in ./generic_lookup_relation.hpp . The following is + description for the current case: + The entities are returned as a tuple of references in the following order (this is for ): + * - The entity/polynomial used to store the product of the inverse values + * - The entity/polynomial that specifies how many times the lookup table entry at this row has been looked up + * - READ_TERMS entities/polynomials that enable individual lookup operations + * - The entity/polynomial that enables adding an entry to the lookup table in this row + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the basic tuple being looked up as the first read term + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the previous accumulators in the second read term + (scaled tuple) + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the shifts in the second read term (scaled tuple) + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the current accumulators in the second read term + (scaled tuple) + * - LOOKUP_TUPLE_SIZE entities/polynomials representing basic tuples added to the table + * + * @return All the entities needed for the lookup + */ + + template static inline auto get_const_entities(const AllEntities& in) + { + + return std::forward_as_tuple( + in.lookup_err, in.lookup_err_counts, in.toy_q_err_check, in.toy_q_err, in.toy_m_clk, in.toy_clk); + } + + /** + * @brief Get all the entities for the lookup when we only need to read them + * @details Same as in get_const_entities, but nonconst + * + * @return All the entities needed for the lookup + */ + + template static inline auto get_nonconst_entities(AllEntities& in) + { + + return std::forward_as_tuple( + in.lookup_err, in.lookup_err_counts, in.toy_q_err_check, in.toy_q_err, in.toy_m_clk, in.toy_clk); + } +}; + +template using lookup_err_relation = GenericLookupRelation; +template using lookup_err = GenericLookup; + +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/Toy/toy_avm.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/Toy/toy_avm.hpp index 02b736fc92c..010fad5c2c5 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/Toy/toy_avm.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/Toy/toy_avm.hpp @@ -7,9 +7,9 @@ namespace bb::Toy_vm { template struct Toy_avmRow { - FF toy_q_xor_table{}; FF toy_q_tuple_set{}; FF toy_q_xor{}; + FF toy_q_xor_table{}; }; inline std::string get_relation_label_toy_avm(int index) diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/Toy/two_column_perm.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/Toy/two_column_perm.hpp index c9eb36311cb..5b6220e7f50 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/Toy/two_column_perm.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/Toy/two_column_perm.hpp @@ -23,7 +23,7 @@ class two_column_perm_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.toy_q_tuple_set == 1); + return (in.toy_q_tuple_set == 1 || in.toy_q_tuple_set == 1); } /** diff --git a/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp index 288501563a1..68f5a4aaa6b 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp @@ -91,15 +91,20 @@ template class GenericPermutationRelationImpl // TODO: Check with kesha that this is fine being a the two sets // // WIRE/SELECTOR enabling the permutation used in the sumcheck computation. This affects the first - // subrelation Accumulator const& first_set_enabled = Accumulator( - // View(std::get(Settings::get_const_entities(in)))); + // subrelation + Accumulator const& first_set_enabled = Accumulator( + View(std::get(Settings::get_const_entities(in)))); - // Accumulator const& second_set_enabled = Accumulator( - // View(std::get(Settings::get_const_entities(in)))); + Accumulator const& second_set_enabled = Accumulator( + View(std::get(Settings::get_const_entities(in)))); - // return first_set_enabled * second_set_enabled; - return Accumulator( - View(std::get(Settings::get_const_entities(in)))); + // This has the truth table of a logical OR + return (first_set_enabled + second_set_enabled - (first_set_enabled * second_set_enabled)); + + // assume that they are + + // return Accumulator( + // View(std::get(Settings::get_const_entities(in)))); } /** diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp index 9e1fd096c89..6929df4bf3d 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp @@ -14,59 +14,67 @@ void log_avmMini_trace(std::vector const& trace, size_t beg, size_t end) info("Built circuit with ", trace.size(), " rows"); for (size_t i = beg; i < end; i++) { - info("====================================================================================="); + Row row = trace.at(i); + // info("====================================================================================="); info("== ROW ", i); - info("====================================================================================="); + // info("====================================================================================="); - info("=======MEMORY TRACE=================================================================="); - info("m_addr: ", trace.at(i).memTrace_m_addr); - info("m_clk: ", trace.at(i).memTrace_m_clk); - info("m_sub_clk: ", trace.at(i).memTrace_m_sub_clk); - info("m_val: ", trace.at(i).memTrace_m_val); - info("m_rw: ", trace.at(i).memTrace_m_rw); - info("m_tag: ", trace.at(i).memTrace_m_tag); - info("m_in_tag: ", trace.at(i).memTrace_m_in_tag); - info("m_tag_err: ", trace.at(i).memTrace_m_tag_err); - info("m_one_min_inv: ", trace.at(i).memTrace_m_one_min_inv); + // info("=======MEMORY TRACE=================================================================="); + info("m_trace_m_tag_err: ", row.memTrace_m_tag_err); + info("m_clk: ", row.memTrace_m_clk); + info(""); + info("tag err: ", row.avmMini_tag_err); + info("clk: ", row.avmMini_clk); + // info("m_tag_err_trace_counts: ", row.equiv_tag_err_counts); - info("m_lastAccess: ", trace.at(i).memTrace_m_lastAccess); - info("m_last: ", trace.at(i).memTrace_m_last); - info("m_val_shift: ", trace.at(i).memTrace_m_val_shift); + // info("m_addr: ", row.memTrace_m_addr); + // info("m_clk: ", row.memTrace_m_clk); + // info("m_sub_clk: ", row.memTrace_m_sub_clk); + // info("m_val: ", row.memTrace_m_val); + // info("m_rw: ", row.memTrace_m_rw); + // info("m_tag: ", row.memTrace_m_tag); + // info("m_in_tag: ", row.memTrace_m_in_tag); + // info("m_tag_err: ", row.memTrace_m_tag_err); + // info("m_one_min_inv: ", row.memTrace_m_one_min_inv); - info("=======CONTROL_FLOW==================================================================="); - info("pc: ", trace.at(i).avmMini_pc); - info("internal_call: ", trace.at(i).avmMini_sel_internal_call); - info("internal_return: ", trace.at(i).avmMini_sel_internal_return); - info("internal_return_ptr:", trace.at(i).avmMini_internal_return_ptr); + // info("m_lastAccess: ", row.memTrace_m_lastAccess); + // info("m_last: ", row.memTrace_m_last); + // info("m_val_shift: ", row.memTrace_m_val_shift); - info("=======ALU TRACE====================================================================="); - info("alu_clk ", trace.at(i).aluChip_alu_clk); - info("alu_ia ", trace.at(i).aluChip_alu_ia); - info("alu_ib ", trace.at(i).aluChip_alu_ib); - info("alu_ic ", trace.at(i).aluChip_alu_ic); + // info("=======CONTROL_FLOW==================================================================="); + // info("pc: ", row.avmMini_pc); + // info("internal_call: ", row.avmMini_sel_internal_call); + // info("internal_return: ", row.avmMini_sel_internal_return); + // info("internal_return_ptr:", row.avmMini_internal_return_ptr); - info("=======MAIN TRACE===================================================================="); - info("ia: ", trace.at(i).avmMini_ia); - info("ib: ", trace.at(i).avmMini_ib); - info("ic: ", trace.at(i).avmMini_ic); - info("first: ", trace.at(i).avmMini_first); - info("last: ", trace.at(i).avmMini_last); + // info("=======ALU TRACE====================================================================="); + // info("alu_clk ", row.aluChip_alu_clk); + // info("alu_ia ", row.aluChip_alu_ia); + // info("alu_ib ", row.aluChip_alu_ib); + // info("alu_ic ", row.aluChip_alu_ic); - info("=======MEM_OP_A======================================================================"); - info("clk: ", trace.at(i).avmMini_clk); - info("mem_op_a: ", trace.at(i).avmMini_mem_op_a); - info("mem_idx_a: ", trace.at(i).avmMini_mem_idx_a); - info("rwa: ", trace.at(i).avmMini_rwa); + // info("=======MAIN TRACE===================================================================="); + // info("clk: ", row.avmMini_clk); + // info("ia: ", row.avmMini_ia); + // info("ib: ", row.avmMini_ib); + // info("ic: ", row.avmMini_ic); + // info("first: ", row.avmMini_first); + // info("last: ", row.avmMini_last); - info("=======MEM_OP_B======================================================================"); - info("mem_op_b: ", trace.at(i).avmMini_mem_op_b); - info("mem_idx_b: ", trace.at(i).avmMini_mem_idx_b); - info("rwb: ", trace.at(i).avmMini_rwb); + // info("=======MEM_OP_A======================================================================"); + // info("mem_op_a: ", row.avmMini_mem_op_a); + // info("mem_idx_a: ", row.avmMini_mem_idx_a); + // info("rwa: ", row.avmMini_rwa); - info("=======MEM_OP_C======================================================================"); - info("mem_op_c: ", trace.at(i).avmMini_mem_op_c); - info("mem_idx_c: ", trace.at(i).avmMini_mem_idx_c); - info("rwc: ", trace.at(i).avmMini_rwc); + // info("=======MEM_OP_B======================================================================"); + // info("mem_op_b: ", row.avmMini_mem_op_b); + // info("mem_idx_b: ", row.avmMini_mem_idx_b); + // info("rwb: ", row.avmMini_rwb); + + // info("=======MEM_OP_C======================================================================"); + // info("mem_op_c: ", row.avmMini_mem_op_c); + // info("mem_idx_c: ", row.avmMini_mem_idx_c); + // info("rwc: ", row.avmMini_rwc); info("\n"); } } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp index 557244116b1..3ac826f3878 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp @@ -84,6 +84,8 @@ void AvmMiniMemTraceBuilder::load_mismatch_tag_in_mem_trace(uint32_t const m_clk AvmMemoryTag const m_tag) { FF one_min_inv = FF(1) - (FF(static_cast(m_in_tag)) - FF(static_cast(m_tag))).invert(); + // TODO(md): add counts + m_tag_err_lookup_counts[m_clk]++; mem_trace.emplace_back(MemoryTraceEntry{ .m_clk = m_clk, .m_sub_clk = m_sub_clk, .m_addr = m_addr, diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp index 0cf1bcaca48..437c358c7a9 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.hpp @@ -15,6 +15,10 @@ class AvmMiniMemTraceBuilder { static const uint32_t SUB_CLK_STORE_B = 4; static const uint32_t SUB_CLK_STORE_C = 5; + // Keeps track of the number of times a mem tag err should appear in the trace + // clk -> count + std::map m_tag_err_lookup_counts; + struct MemoryTraceEntry { uint32_t m_clk{}; uint32_t m_sub_clk{}; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp index 85f9906533f..1953a1e6274 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp @@ -44,6 +44,9 @@ void AvmMiniTraceBuilder::add(uint32_t a_offset, uint32_t b_offset, uint32_t dst { auto clk = static_cast(main_trace.size()); + info(clk); + info(""); + // 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); @@ -578,6 +581,13 @@ void AvmMiniTraceBuilder::internal_return() internal_return_ptr--; } +void AvmMiniTraceBuilder::add_lookup_counts(std::map const& tag_err_lookup_counts) +{ + for (auto const& [clk, count] : tag_err_lookup_counts) { + main_trace.at(clk).equiv_tag_err_counts = count; + } +} + /** * @brief Finalisation of the memory trace and incorporating it to the main trace. * In particular, sorting the memory trace, setting .m_lastAccess and @@ -594,6 +604,9 @@ std::vector AvmMiniTraceBuilder::finalize() size_t main_trace_size = main_trace.size(); size_t alu_trace_size = alu_trace.size(); + // Get tag_err counts from the mem_trace_builder + this->add_lookup_counts(mem_trace_builder.m_tag_err_lookup_counts); + // TODO: We will have to handle this through error handling and not an assertion // Smaller than N because we have to add an extra initial row to support shifted // elements diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp index 381f8f1586b..fbb076a3c7e 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp @@ -71,6 +71,7 @@ class AvmMiniTraceBuilder { std::vector main_trace; AvmMiniMemTraceBuilder mem_trace_builder; AvmMiniAluTraceBuilder alu_trace_builder; + void add_lookup_counts(std::map const& tag_err_lookup_counts); uint32_t pc = 0; uint32_t internal_return_ptr = CALLSTACK_OFFSET; diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp index 3938a1b0dac..1e4588d5d5e 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/AvmMini_verifier.cpp @@ -161,6 +161,8 @@ bool AvmMiniVerifier::verify_proof(const HonkProof& proof) transcript->template receive_from_prover(commitment_labels.avmMini_mem_idx_c); commitments.avmMini_last = transcript->template receive_from_prover(commitment_labels.avmMini_last); commitments.equiv_tag_err = transcript->template receive_from_prover(commitment_labels.equiv_tag_err); + commitments.equiv_tag_err_counts = + transcript->template receive_from_prover(commitment_labels.equiv_tag_err_counts); // Execute Sumcheck Verifier const size_t log_circuit_size = numeric::get_msb(circuit_size); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/Toy_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/Toy_verifier.cpp index 9ebb3713060..269d59e4d5a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/Toy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/Toy_verifier.cpp @@ -73,11 +73,19 @@ bool ToyVerifier::verify_proof(const HonkProof& proof) commitments.toy_q_xor = transcript->template receive_from_prover(commitment_labels.toy_q_xor); commitments.toy_q_xor_table = transcript->template receive_from_prover(commitment_labels.toy_q_xor_table); + commitments.toy_q_err = transcript->template receive_from_prover(commitment_labels.toy_q_err); + commitments.toy_q_err_check = + transcript->template receive_from_prover(commitment_labels.toy_q_err_check); + commitments.toy_clk = transcript->template receive_from_prover(commitment_labels.toy_clk); + commitments.toy_m_clk = transcript->template receive_from_prover(commitment_labels.toy_m_clk); commitments.two_column_perm = transcript->template receive_from_prover(commitment_labels.two_column_perm); commitments.lookup_xor = transcript->template receive_from_prover(commitment_labels.lookup_xor); + commitments.lookup_err = transcript->template receive_from_prover(commitment_labels.lookup_err); commitments.lookup_xor_counts = transcript->template receive_from_prover(commitment_labels.lookup_xor_counts); + commitments.lookup_err_counts = + transcript->template receive_from_prover(commitment_labels.lookup_err_counts); // Execute Sumcheck Verifier const size_t log_circuit_size = numeric::get_msb(circuit_size); diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp index 9fa1cabedaa..a947a08c66f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp @@ -10,6 +10,7 @@ namespace tests_avm { */ void validate_trace_proof(std::vector&& trace) { + auto circuit_builder = AvmMiniCircuitBuilder(); circuit_builder.set_trace(std::move(trace)); @@ -18,17 +19,15 @@ void validate_trace_proof(std::vector&& trace) auto composer = AvmMiniComposer(); auto prover = composer.create_prover(circuit_builder); auto proof = prover.construct_proof(); - info("proof created"); auto verifier = composer.create_verifier(circuit_builder); bool verified = verifier.verify_proof(proof); - info("proof verified"); EXPECT_TRUE(verified); - // if (!verified) { - // avm_trace::log_avmMini_trace(circuit_builder.rows, 0, 10); - // } + if (!verified) { + avm_trace::log_avmMini_trace(circuit_builder.rows, 1, 10); + } }; /** From 569648035acb534821fffe21a72c9926ff8a1a46 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 13 Feb 2024 18:19:27 +0000 Subject: [PATCH 4/9] doc --- .../toy_avm/toy_avm_circuit_builder.test.cpp | 1 + .../generic_permutation_relation.hpp | 8 +------- .../src/barretenberg/vm/avm_trace/AvmMini_trace.cpp | 11 +++++++++-- .../src/barretenberg/vm/avm_trace/AvmMini_trace.hpp | 3 ++- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp index 27ef2a174c2..e89b3271dd4 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp @@ -141,6 +141,7 @@ TEST(ToyAVMCircuitBuilder, MultiLookup) Row& row_1 = rows[0]; row_1.toy_q_err = FF(1); row_1.toy_clk = FF(1); + // Below we lookup two occurances, so our counts is 2 row_1.lookup_err_counts = FF(2); // Set the mem read on two different rows, we will then lookup into the clk diff --git a/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp index 68f5a4aaa6b..60a8d492774 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp @@ -81,6 +81,7 @@ template class GenericPermutationRelationImpl /** * @brief Get selector/wire switching on(1) or off(0) inverse computation + * We turn it on if either of the permutation contribution selectors are active * */ template @@ -88,8 +89,6 @@ template class GenericPermutationRelationImpl { using View = typename Accumulator::View; - // TODO: Check with kesha that this is fine being a the two sets - // // WIRE/SELECTOR enabling the permutation used in the sumcheck computation. This affects the first // subrelation Accumulator const& first_set_enabled = Accumulator( @@ -100,11 +99,6 @@ template class GenericPermutationRelationImpl // This has the truth table of a logical OR return (first_set_enabled + second_set_enabled - (first_set_enabled * second_set_enabled)); - - // assume that they are - - // return Accumulator( - // View(std::get(Settings::get_const_entities(in)))); } /** diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp index 1953a1e6274..6290ac64609 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp @@ -581,7 +581,14 @@ void AvmMiniTraceBuilder::internal_return() internal_return_ptr--; } -void AvmMiniTraceBuilder::add_lookup_counts(std::map const& tag_err_lookup_counts) +// Finalise Lookup Counts +// +// For log derivative lookups, we require a column that contains the number of times each lookup is consumed +// As we build the trace, we keep track of the reads made in a mapping, so that they can be applied to the +// counts column here +// +// NOTE: its coupled to pil - this is not the final iteration +void AvmMiniTraceBuilder::finalise_mem_trace_lookup_counts(std::map const& tag_err_lookup_counts) { for (auto const& [clk, count] : tag_err_lookup_counts) { main_trace.at(clk).equiv_tag_err_counts = count; @@ -605,7 +612,7 @@ std::vector AvmMiniTraceBuilder::finalize() size_t alu_trace_size = alu_trace.size(); // Get tag_err counts from the mem_trace_builder - this->add_lookup_counts(mem_trace_builder.m_tag_err_lookup_counts); + this->finalise_mem_trace_lookup_counts(mem_trace_builder.m_tag_err_lookup_counts); // TODO: We will have to handle this through error handling and not an assertion // Smaller than N because we have to add an extra initial row to support shifted diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp index fbb076a3c7e..dd75e3d1f6f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.hpp @@ -71,7 +71,8 @@ class AvmMiniTraceBuilder { std::vector main_trace; AvmMiniMemTraceBuilder mem_trace_builder; AvmMiniAluTraceBuilder alu_trace_builder; - void add_lookup_counts(std::map const& tag_err_lookup_counts); + + void finalise_mem_trace_lookup_counts(std::map const& tag_err_lookup_counts); uint32_t pc = 0; uint32_t internal_return_ptr = CALLSTACK_OFFSET; From c3c287e99096dfc5292554980524d9bf2e7fe315 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 13 Feb 2024 18:36:45 +0000 Subject: [PATCH 5/9] fix: doc --- barretenberg/cpp/pil/avm/toy_avm.pil | 2 +- .../relations/generated/Toy/toy_avm.hpp | 2 +- .../generic_permutation_relation.hpp | 2 +- .../vm/avm_trace/AvmMini_helper.cpp | 96 +++++++++---------- .../vm/avm_trace/AvmMini_mem_trace.cpp | 4 +- .../vm/avm_trace/AvmMini_trace.cpp | 3 - .../barretenberg/vm/tests/helpers.test.cpp | 2 +- 7 files changed, 51 insertions(+), 60 deletions(-) diff --git a/barretenberg/cpp/pil/avm/toy_avm.pil b/barretenberg/cpp/pil/avm/toy_avm.pil index 434c380fd38..42f8b1e1340 100644 --- a/barretenberg/cpp/pil/avm/toy_avm.pil +++ b/barretenberg/cpp/pil/avm/toy_avm.pil @@ -47,7 +47,7 @@ namespace toy(256); #[lookup_xor] q_xor { xor_a, xor_b, xor_c } in q_xor_table { table_xor_a, table_xor_b, table_xor_c }; - // Minimum repro to try and fix jean's lookup issue + // Minimum repro testing multiple lookups pol commit q_err, q_err_check; pol commit clk, m_clk; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/Toy/toy_avm.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/Toy/toy_avm.hpp index 010fad5c2c5..a810f8c17c7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/Toy/toy_avm.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/Toy/toy_avm.hpp @@ -7,8 +7,8 @@ namespace bb::Toy_vm { template struct Toy_avmRow { - FF toy_q_tuple_set{}; FF toy_q_xor{}; + FF toy_q_tuple_set{}; FF toy_q_xor_table{}; }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp index 60a8d492774..a34290e7544 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generic_permutation/generic_permutation_relation.hpp @@ -89,7 +89,7 @@ template class GenericPermutationRelationImpl { using View = typename Accumulator::View; - // // WIRE/SELECTOR enabling the permutation used in the sumcheck computation. This affects the first + // WIRE/SELECTOR enabling the permutation used in the sumcheck computation. This affects the first // subrelation Accumulator const& first_set_enabled = Accumulator( View(std::get(Settings::get_const_entities(in)))); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp index 6929df4bf3d..9e1fd096c89 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_helper.cpp @@ -14,67 +14,59 @@ void log_avmMini_trace(std::vector const& trace, size_t beg, size_t end) info("Built circuit with ", trace.size(), " rows"); for (size_t i = beg; i < end; i++) { - Row row = trace.at(i); - // info("====================================================================================="); + info("====================================================================================="); info("== ROW ", i); - // info("====================================================================================="); + info("====================================================================================="); - // info("=======MEMORY TRACE=================================================================="); - info("m_trace_m_tag_err: ", row.memTrace_m_tag_err); - info("m_clk: ", row.memTrace_m_clk); - info(""); - info("tag err: ", row.avmMini_tag_err); - info("clk: ", row.avmMini_clk); - // info("m_tag_err_trace_counts: ", row.equiv_tag_err_counts); + info("=======MEMORY TRACE=================================================================="); + info("m_addr: ", trace.at(i).memTrace_m_addr); + info("m_clk: ", trace.at(i).memTrace_m_clk); + info("m_sub_clk: ", trace.at(i).memTrace_m_sub_clk); + info("m_val: ", trace.at(i).memTrace_m_val); + info("m_rw: ", trace.at(i).memTrace_m_rw); + info("m_tag: ", trace.at(i).memTrace_m_tag); + info("m_in_tag: ", trace.at(i).memTrace_m_in_tag); + info("m_tag_err: ", trace.at(i).memTrace_m_tag_err); + info("m_one_min_inv: ", trace.at(i).memTrace_m_one_min_inv); - // info("m_addr: ", row.memTrace_m_addr); - // info("m_clk: ", row.memTrace_m_clk); - // info("m_sub_clk: ", row.memTrace_m_sub_clk); - // info("m_val: ", row.memTrace_m_val); - // info("m_rw: ", row.memTrace_m_rw); - // info("m_tag: ", row.memTrace_m_tag); - // info("m_in_tag: ", row.memTrace_m_in_tag); - // info("m_tag_err: ", row.memTrace_m_tag_err); - // info("m_one_min_inv: ", row.memTrace_m_one_min_inv); + info("m_lastAccess: ", trace.at(i).memTrace_m_lastAccess); + info("m_last: ", trace.at(i).memTrace_m_last); + info("m_val_shift: ", trace.at(i).memTrace_m_val_shift); - // info("m_lastAccess: ", row.memTrace_m_lastAccess); - // info("m_last: ", row.memTrace_m_last); - // info("m_val_shift: ", row.memTrace_m_val_shift); + info("=======CONTROL_FLOW==================================================================="); + info("pc: ", trace.at(i).avmMini_pc); + info("internal_call: ", trace.at(i).avmMini_sel_internal_call); + info("internal_return: ", trace.at(i).avmMini_sel_internal_return); + info("internal_return_ptr:", trace.at(i).avmMini_internal_return_ptr); - // info("=======CONTROL_FLOW==================================================================="); - // info("pc: ", row.avmMini_pc); - // info("internal_call: ", row.avmMini_sel_internal_call); - // info("internal_return: ", row.avmMini_sel_internal_return); - // info("internal_return_ptr:", row.avmMini_internal_return_ptr); + info("=======ALU TRACE====================================================================="); + info("alu_clk ", trace.at(i).aluChip_alu_clk); + info("alu_ia ", trace.at(i).aluChip_alu_ia); + info("alu_ib ", trace.at(i).aluChip_alu_ib); + info("alu_ic ", trace.at(i).aluChip_alu_ic); - // info("=======ALU TRACE====================================================================="); - // info("alu_clk ", row.aluChip_alu_clk); - // info("alu_ia ", row.aluChip_alu_ia); - // info("alu_ib ", row.aluChip_alu_ib); - // info("alu_ic ", row.aluChip_alu_ic); + info("=======MAIN TRACE===================================================================="); + info("ia: ", trace.at(i).avmMini_ia); + info("ib: ", trace.at(i).avmMini_ib); + info("ic: ", trace.at(i).avmMini_ic); + info("first: ", trace.at(i).avmMini_first); + info("last: ", trace.at(i).avmMini_last); - // info("=======MAIN TRACE===================================================================="); - // info("clk: ", row.avmMini_clk); - // info("ia: ", row.avmMini_ia); - // info("ib: ", row.avmMini_ib); - // info("ic: ", row.avmMini_ic); - // info("first: ", row.avmMini_first); - // info("last: ", row.avmMini_last); + info("=======MEM_OP_A======================================================================"); + info("clk: ", trace.at(i).avmMini_clk); + info("mem_op_a: ", trace.at(i).avmMini_mem_op_a); + info("mem_idx_a: ", trace.at(i).avmMini_mem_idx_a); + info("rwa: ", trace.at(i).avmMini_rwa); - // info("=======MEM_OP_A======================================================================"); - // info("mem_op_a: ", row.avmMini_mem_op_a); - // info("mem_idx_a: ", row.avmMini_mem_idx_a); - // info("rwa: ", row.avmMini_rwa); + info("=======MEM_OP_B======================================================================"); + info("mem_op_b: ", trace.at(i).avmMini_mem_op_b); + info("mem_idx_b: ", trace.at(i).avmMini_mem_idx_b); + info("rwb: ", trace.at(i).avmMini_rwb); - // info("=======MEM_OP_B======================================================================"); - // info("mem_op_b: ", row.avmMini_mem_op_b); - // info("mem_idx_b: ", row.avmMini_mem_idx_b); - // info("rwb: ", row.avmMini_rwb); - - // info("=======MEM_OP_C======================================================================"); - // info("mem_op_c: ", row.avmMini_mem_op_c); - // info("mem_idx_c: ", row.avmMini_mem_idx_c); - // info("rwc: ", row.avmMini_rwc); + info("=======MEM_OP_C======================================================================"); + info("mem_op_c: ", trace.at(i).avmMini_mem_op_c); + info("mem_idx_c: ", trace.at(i).avmMini_mem_idx_c); + info("rwc: ", trace.at(i).avmMini_rwc); info("\n"); } } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp index 3ac826f3878..4423f309535 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_mem_trace.cpp @@ -84,8 +84,10 @@ void AvmMiniMemTraceBuilder::load_mismatch_tag_in_mem_trace(uint32_t const m_clk AvmMemoryTag const m_tag) { FF one_min_inv = FF(1) - (FF(static_cast(m_in_tag)) - FF(static_cast(m_tag))).invert(); - // TODO(md): add counts + + // Lookup counter hint, used for #[equiv_tag_err] lookup (joined on clk) m_tag_err_lookup_counts[m_clk]++; + mem_trace.emplace_back(MemoryTraceEntry{ .m_clk = m_clk, .m_sub_clk = m_sub_clk, .m_addr = m_addr, diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp index 6290ac64609..496239e31dc 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/AvmMini_trace.cpp @@ -44,9 +44,6 @@ void AvmMiniTraceBuilder::add(uint32_t a_offset, uint32_t b_offset, uint32_t dst { auto clk = static_cast(main_trace.size()); - info(clk); - info(""); - // 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); diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp index a947a08c66f..9511d0eeeaf 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp @@ -26,7 +26,7 @@ void validate_trace_proof(std::vector&& trace) EXPECT_TRUE(verified); if (!verified) { - avm_trace::log_avmMini_trace(circuit_builder.rows, 1, 10); + avm_trace::log_avmMini_trace(circuit_builder.rows, 0, 10); } }; From c839d17558944c8843145c175355551793d16765 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 13 Feb 2024 18:50:44 +0000 Subject: [PATCH 6/9] rm left over avmmini --- .../flavor/generated/AvmMini_flavor.hpp | 919 ------------------ .../generated/AvmMini_circuit_builder.hpp | 319 ------ 2 files changed, 1238 deletions(-) delete mode 100644 barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp delete mode 100644 barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp deleted file mode 100644 index 49a26830f9b..00000000000 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ /dev/null @@ -1,919 +0,0 @@ - - -#pragma once -#include "../relation_definitions.hpp" -#include "barretenberg/commitment_schemes/kzg/kzg.hpp" -#include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "barretenberg/polynomials/barycentric.hpp" -#include "barretenberg/polynomials/univariate.hpp" - -#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" - -#include "barretenberg/flavor/flavor.hpp" -#include "barretenberg/flavor/flavor_macros.hpp" -#include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" -#include "barretenberg/relations/generated/AvmMini/alu_chip.hpp" -#include "barretenberg/relations/generated/AvmMini/avm_mini.hpp" -#include "barretenberg/relations/generated/AvmMini/mem_trace.hpp" -#include "barretenberg/transcript/transcript.hpp" - -namespace bb { - -class AvmMiniFlavor { - public: - using Curve = curve::BN254; - using G1 = Curve::Group; - using PCS = KZG; - - using FF = G1::subgroup_field; - using Polynomial = bb::Polynomial; - using PolynomialHandle = std::span; - using GroupElement = G1::element; - using Commitment = G1::affine_element; - using CommitmentHandle = G1::affine_element; - using CommitmentKey = bb::CommitmentKey; - using VerifierCommitmentKey = bb::VerifierCommitmentKey; - using RelationSeparator = FF; - - static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; - static constexpr size_t NUM_WITNESS_ENTITIES = 66; - static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES; - // We have two copies of the witness entities, so we subtract the number of fixed ones (they have no shift), one for - // the unshifted and one for the shifted - static constexpr size_t NUM_ALL_ENTITIES = 82; - - using Relations = std::tuple, AvmMini_vm::alu_chip, AvmMini_vm::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_ff_tag, - aluChip_alu_u8_tag, - aluChip_alu_u16_tag, - aluChip_alu_u32_tag, - aluChip_alu_u64_tag, - aluChip_alu_u128_tag, - aluChip_alu_u8_r0, - aluChip_alu_u8_r1, - aluChip_alu_u16_r0, - aluChip_alu_u16_r1, - aluChip_alu_u16_r2, - aluChip_alu_u16_r3, - aluChip_alu_u16_r4, - aluChip_alu_u16_r5, - aluChip_alu_u16_r6, - aluChip_alu_u16_r7, - aluChip_alu_u64_r0, - aluChip_alu_cf, - avmMini_pc, - avmMini_internal_return_ptr, - avmMini_sel_internal_call, - avmMini_sel_internal_return, - avmMini_sel_jump, - avmMini_sel_halt, - avmMini_sel_op_add, - avmMini_sel_op_sub, - avmMini_sel_op_mul, - avmMini_sel_op_div, - avmMini_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, - equiv_tag_err, - equiv_tag_err_counts) - - 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_ff_tag, - aluChip_alu_u8_tag, - aluChip_alu_u16_tag, - aluChip_alu_u32_tag, - aluChip_alu_u64_tag, - aluChip_alu_u128_tag, - aluChip_alu_u8_r0, - aluChip_alu_u8_r1, - aluChip_alu_u16_r0, - aluChip_alu_u16_r1, - aluChip_alu_u16_r2, - aluChip_alu_u16_r3, - aluChip_alu_u16_r4, - aluChip_alu_u16_r5, - aluChip_alu_u16_r6, - aluChip_alu_u16_r7, - aluChip_alu_u64_r0, - aluChip_alu_cf, - avmMini_pc, - avmMini_internal_return_ptr, - avmMini_sel_internal_call, - avmMini_sel_internal_return, - avmMini_sel_jump, - avmMini_sel_halt, - avmMini_sel_op_add, - avmMini_sel_op_sub, - avmMini_sel_op_mul, - avmMini_sel_op_div, - avmMini_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, - equiv_tag_err, - equiv_tag_err_counts }; - }; - 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_ff_tag, - aluChip_alu_u8_tag, - aluChip_alu_u16_tag, - aluChip_alu_u32_tag, - aluChip_alu_u64_tag, - aluChip_alu_u128_tag, - aluChip_alu_u8_r0, - aluChip_alu_u8_r1, - aluChip_alu_u16_r0, - aluChip_alu_u16_r1, - aluChip_alu_u16_r2, - aluChip_alu_u16_r3, - aluChip_alu_u16_r4, - aluChip_alu_u16_r5, - aluChip_alu_u16_r6, - aluChip_alu_u16_r7, - aluChip_alu_u64_r0, - aluChip_alu_cf, - avmMini_pc, - avmMini_internal_return_ptr, - avmMini_sel_internal_call, - avmMini_sel_internal_return, - avmMini_sel_jump, - avmMini_sel_halt, - avmMini_sel_op_add, - avmMini_sel_op_sub, - avmMini_sel_op_mul, - avmMini_sel_op_div, - avmMini_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, - equiv_tag_err, - equiv_tag_err_counts, - avmMini_pc_shift, - avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r0_shift, - memTrace_m_addr_shift, - memTrace_m_rw_shift, - memTrace_m_val_shift, - memTrace_m_tag_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_ff_tag, - aluChip_alu_u8_tag, - aluChip_alu_u16_tag, - aluChip_alu_u32_tag, - aluChip_alu_u64_tag, - aluChip_alu_u128_tag, - aluChip_alu_u8_r0, - aluChip_alu_u8_r1, - aluChip_alu_u16_r0, - aluChip_alu_u16_r1, - aluChip_alu_u16_r2, - aluChip_alu_u16_r3, - aluChip_alu_u16_r4, - aluChip_alu_u16_r5, - aluChip_alu_u16_r6, - aluChip_alu_u16_r7, - aluChip_alu_u64_r0, - aluChip_alu_cf, - avmMini_pc, - avmMini_internal_return_ptr, - avmMini_sel_internal_call, - avmMini_sel_internal_return, - avmMini_sel_jump, - avmMini_sel_halt, - avmMini_sel_op_add, - avmMini_sel_op_sub, - avmMini_sel_op_mul, - avmMini_sel_op_div, - avmMini_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, - equiv_tag_err, - equiv_tag_err_counts, - avmMini_pc_shift, - avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r6_shift, - aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r2_shift, - aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r4_shift, - aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r1_shift, - aluChip_alu_u16_r0_shift, - memTrace_m_addr_shift, - memTrace_m_rw_shift, - memTrace_m_val_shift, - memTrace_m_tag_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_ff_tag, - aluChip_alu_u8_tag, - aluChip_alu_u16_tag, - aluChip_alu_u32_tag, - aluChip_alu_u64_tag, - aluChip_alu_u128_tag, - aluChip_alu_u8_r0, - aluChip_alu_u8_r1, - aluChip_alu_u16_r0, - aluChip_alu_u16_r1, - aluChip_alu_u16_r2, - aluChip_alu_u16_r3, - aluChip_alu_u16_r4, - aluChip_alu_u16_r5, - aluChip_alu_u16_r6, - aluChip_alu_u16_r7, - aluChip_alu_u64_r0, - aluChip_alu_cf, - avmMini_pc, - avmMini_internal_return_ptr, - avmMini_sel_internal_call, - avmMini_sel_internal_return, - avmMini_sel_jump, - avmMini_sel_halt, - avmMini_sel_op_add, - avmMini_sel_op_sub, - avmMini_sel_op_mul, - avmMini_sel_op_div, - avmMini_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, - equiv_tag_err, - equiv_tag_err_counts }; - }; - RefVector get_to_be_shifted() - { - return { avmMini_pc, avmMini_internal_return_ptr, - aluChip_alu_u16_r6, aluChip_alu_u16_r3, - aluChip_alu_u16_r2, aluChip_alu_u16_r7, - aluChip_alu_u16_r4, aluChip_alu_u16_r5, - aluChip_alu_u16_r1, aluChip_alu_u16_r0, - memTrace_m_addr, memTrace_m_rw, - memTrace_m_val, memTrace_m_tag }; - }; - RefVector get_shifted() - { - return { avmMini_pc_shift, avmMini_internal_return_ptr_shift, - aluChip_alu_u16_r6_shift, aluChip_alu_u16_r3_shift, - aluChip_alu_u16_r2_shift, aluChip_alu_u16_r7_shift, - aluChip_alu_u16_r4_shift, aluChip_alu_u16_r5_shift, - aluChip_alu_u16_r1_shift, aluChip_alu_u16_r0_shift, - memTrace_m_addr_shift, memTrace_m_rw_shift, - memTrace_m_val_shift, memTrace_m_tag_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 { avmMini_pc, avmMini_internal_return_ptr, - aluChip_alu_u16_r6, aluChip_alu_u16_r3, - aluChip_alu_u16_r2, aluChip_alu_u16_r7, - aluChip_alu_u16_r4, aluChip_alu_u16_r5, - aluChip_alu_u16_r1, aluChip_alu_u16_r0, - memTrace_m_addr, memTrace_m_rw, - memTrace_m_val, memTrace_m_tag }; - }; - - // 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_ff_tag = "ALUCHIP_ALU_FF_TAG"; - Base::aluChip_alu_u8_tag = "ALUCHIP_ALU_U8_TAG"; - Base::aluChip_alu_u16_tag = "ALUCHIP_ALU_U16_TAG"; - Base::aluChip_alu_u32_tag = "ALUCHIP_ALU_U32_TAG"; - Base::aluChip_alu_u64_tag = "ALUCHIP_ALU_U64_TAG"; - Base::aluChip_alu_u128_tag = "ALUCHIP_ALU_U128_TAG"; - Base::aluChip_alu_u8_r0 = "ALUCHIP_ALU_U8_R0"; - Base::aluChip_alu_u8_r1 = "ALUCHIP_ALU_U8_R1"; - Base::aluChip_alu_u16_r0 = "ALUCHIP_ALU_U16_R0"; - Base::aluChip_alu_u16_r1 = "ALUCHIP_ALU_U16_R1"; - Base::aluChip_alu_u16_r2 = "ALUCHIP_ALU_U16_R2"; - Base::aluChip_alu_u16_r3 = "ALUCHIP_ALU_U16_R3"; - Base::aluChip_alu_u16_r4 = "ALUCHIP_ALU_U16_R4"; - Base::aluChip_alu_u16_r5 = "ALUCHIP_ALU_U16_R5"; - Base::aluChip_alu_u16_r6 = "ALUCHIP_ALU_U16_R6"; - Base::aluChip_alu_u16_r7 = "ALUCHIP_ALU_U16_R7"; - Base::aluChip_alu_u64_r0 = "ALUCHIP_ALU_U64_R0"; - Base::aluChip_alu_cf = "ALUCHIP_ALU_CF"; - Base::avmMini_pc = "AVMMINI_PC"; - Base::avmMini_internal_return_ptr = "AVMMINI_INTERNAL_RETURN_PTR"; - Base::avmMini_sel_internal_call = "AVMMINI_SEL_INTERNAL_CALL"; - Base::avmMini_sel_internal_return = "AVMMINI_SEL_INTERNAL_RETURN"; - Base::avmMini_sel_jump = "AVMMINI_SEL_JUMP"; - Base::avmMini_sel_halt = "AVMMINI_SEL_HALT"; - Base::avmMini_sel_op_add = "AVMMINI_SEL_OP_ADD"; - Base::avmMini_sel_op_sub = "AVMMINI_SEL_OP_SUB"; - Base::avmMini_sel_op_mul = "AVMMINI_SEL_OP_MUL"; - Base::avmMini_sel_op_div = "AVMMINI_SEL_OP_DIV"; - Base::avmMini_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"; - Base::equiv_tag_err = "EQUIV_TAG_ERR"; - Base::equiv_tag_err_counts = "EQUIV_TAG_ERR_COUNTS"; - }; - }; - - 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_ff_tag; - Commitment aluChip_alu_u8_tag; - Commitment aluChip_alu_u16_tag; - Commitment aluChip_alu_u32_tag; - Commitment aluChip_alu_u64_tag; - Commitment aluChip_alu_u128_tag; - Commitment aluChip_alu_u8_r0; - Commitment aluChip_alu_u8_r1; - Commitment aluChip_alu_u16_r0; - Commitment aluChip_alu_u16_r1; - Commitment aluChip_alu_u16_r2; - Commitment aluChip_alu_u16_r3; - Commitment aluChip_alu_u16_r4; - Commitment aluChip_alu_u16_r5; - Commitment aluChip_alu_u16_r6; - Commitment aluChip_alu_u16_r7; - Commitment aluChip_alu_u64_r0; - Commitment aluChip_alu_cf; - Commitment avmMini_pc; - Commitment avmMini_internal_return_ptr; - Commitment avmMini_sel_internal_call; - Commitment avmMini_sel_internal_return; - Commitment avmMini_sel_jump; - Commitment avmMini_sel_halt; - Commitment avmMini_sel_op_add; - Commitment avmMini_sel_op_sub; - Commitment avmMini_sel_op_mul; - Commitment avmMini_sel_op_div; - Commitment avmMini_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; - Commitment equiv_tag_err; - Commitment equiv_tag_err_counts; - - 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_ff_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u8_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u32_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u64_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u128_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u8_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u8_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r3 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r4 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r5 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r6 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u16_r7 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_u64_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - aluChip_alu_cf = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_pc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_internal_return_ptr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_internal_call = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_internal_return = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_jump = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_halt = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_op_add = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_op_sub = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_sel_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avmMini_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); - equiv_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - equiv_tag_err_counts = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - - 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_ff_tag, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u8_tag, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_tag, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u32_tag, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u64_tag, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u128_tag, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u8_r0, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u8_r1, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r0, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r1, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r2, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r3, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r4, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r5, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r6, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u16_r7, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_u64_r0, Transcript::proof_data); - serialize_to_buffer(aluChip_alu_cf, Transcript::proof_data); - serialize_to_buffer(avmMini_pc, Transcript::proof_data); - serialize_to_buffer(avmMini_internal_return_ptr, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_internal_call, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_internal_return, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_jump, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_halt, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_op_add, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_op_sub, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_op_mul, Transcript::proof_data); - serialize_to_buffer(avmMini_sel_op_div, Transcript::proof_data); - serialize_to_buffer(avmMini_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); - serialize_to_buffer(equiv_tag_err, Transcript::proof_data); - serialize_to_buffer(equiv_tag_err_counts, Transcript::proof_data); - - for (size_t i = 0; i < log_n; ++i) { - serialize_to_buffer(sumcheck_univariates[i], Transcript::proof_data); - } - serialize_to_buffer(sumcheck_evaluations, Transcript::proof_data); - for (size_t i = 0; i < log_n; ++i) { - serialize_to_buffer(zm_cq_comms[i], proof_data); - } - serialize_to_buffer(zm_cq_comm, proof_data); - serialize_to_buffer(zm_pi_comm, proof_data); - - // sanity check to make sure we generate the same length of proof as before. - ASSERT(proof_data.size() == old_proof_length); - } - }; -}; - -} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp deleted file mode 100644 index 7f292e5b208..00000000000 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp +++ /dev/null @@ -1,319 +0,0 @@ - - -// AUTOGENERATED FILE -#pragma once - -#include "barretenberg/common/constexpr_utils.hpp" -#include "barretenberg/common/throw_or_abort.hpp" -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/honk/proof_system/logderivative_library.hpp" -#include "barretenberg/proof_system/circuit_builder/circuit_builder_base.hpp" -#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp" -#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" - -#include "barretenberg/flavor/generated/AvmMini_flavor.hpp" -#include "barretenberg/relations/generated/AvmMini/alu_chip.hpp" -#include "barretenberg/relations/generated/AvmMini/avm_mini.hpp" -#include "barretenberg/relations/generated/AvmMini/equiv_tag_err.hpp" -#include "barretenberg/relations/generated/AvmMini/mem_trace.hpp" - -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_ff_tag{}; - FF aluChip_alu_u8_tag{}; - FF aluChip_alu_u16_tag{}; - FF aluChip_alu_u32_tag{}; - FF aluChip_alu_u64_tag{}; - FF aluChip_alu_u128_tag{}; - FF aluChip_alu_u8_r0{}; - FF aluChip_alu_u8_r1{}; - FF aluChip_alu_u16_r0{}; - FF aluChip_alu_u16_r1{}; - FF aluChip_alu_u16_r2{}; - FF aluChip_alu_u16_r3{}; - FF aluChip_alu_u16_r4{}; - FF aluChip_alu_u16_r5{}; - FF aluChip_alu_u16_r6{}; - FF aluChip_alu_u16_r7{}; - FF aluChip_alu_u64_r0{}; - FF aluChip_alu_cf{}; - FF avmMini_pc{}; - FF avmMini_internal_return_ptr{}; - FF avmMini_sel_internal_call{}; - FF avmMini_sel_internal_return{}; - FF avmMini_sel_jump{}; - FF avmMini_sel_halt{}; - FF avmMini_sel_op_add{}; - FF avmMini_sel_op_sub{}; - FF avmMini_sel_op_mul{}; - FF avmMini_sel_op_div{}; - FF avmMini_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 equiv_tag_err{}; - FF equiv_tag_err_counts{}; - FF avmMini_pc_shift{}; - FF avmMini_internal_return_ptr_shift{}; - FF aluChip_alu_u16_r6_shift{}; - FF aluChip_alu_u16_r3_shift{}; - FF aluChip_alu_u16_r2_shift{}; - FF aluChip_alu_u16_r7_shift{}; - FF aluChip_alu_u16_r4_shift{}; - FF aluChip_alu_u16_r5_shift{}; - FF aluChip_alu_u16_r1_shift{}; - FF aluChip_alu_u16_r0_shift{}; - FF memTrace_m_addr_shift{}; - FF memTrace_m_rw_shift{}; - FF memTrace_m_val_shift{}; - FF memTrace_m_tag_shift{}; -}; - -class AvmMiniCircuitBuilder { - public: - using Flavor = bb::AvmMiniFlavor; - using FF = Flavor::FF; - using Row = AvmMiniFullRow; - - // TODO: template - using Polynomial = Flavor::Polynomial; - using ProverPolynomials = Flavor::ProverPolynomials; - - static constexpr size_t num_fixed_columns = 82; - static constexpr size_t num_polys = 68; - std::vector rows; - - void set_trace(std::vector&& trace) { rows = std::move(trace); } - - ProverPolynomials compute_polynomials() - { - const auto num_rows = get_circuit_subgroup_size(); - ProverPolynomials polys; - - // Allocate mem for each column - for (auto& poly : polys.get_all()) { - poly = Polynomial(num_rows); - } - - for (size_t i = 0; i < rows.size(); i++) { - polys.avmMini_clk[i] = rows[i].avmMini_clk; - polys.avmMini_first[i] = rows[i].avmMini_first; - polys.memTrace_m_clk[i] = rows[i].memTrace_m_clk; - polys.memTrace_m_sub_clk[i] = rows[i].memTrace_m_sub_clk; - polys.memTrace_m_addr[i] = rows[i].memTrace_m_addr; - polys.memTrace_m_tag[i] = rows[i].memTrace_m_tag; - polys.memTrace_m_val[i] = rows[i].memTrace_m_val; - polys.memTrace_m_lastAccess[i] = rows[i].memTrace_m_lastAccess; - polys.memTrace_m_last[i] = rows[i].memTrace_m_last; - polys.memTrace_m_rw[i] = rows[i].memTrace_m_rw; - polys.memTrace_m_in_tag[i] = rows[i].memTrace_m_in_tag; - polys.memTrace_m_tag_err[i] = rows[i].memTrace_m_tag_err; - polys.memTrace_m_one_min_inv[i] = rows[i].memTrace_m_one_min_inv; - polys.aluChip_alu_clk[i] = rows[i].aluChip_alu_clk; - polys.aluChip_alu_ia[i] = rows[i].aluChip_alu_ia; - polys.aluChip_alu_ib[i] = rows[i].aluChip_alu_ib; - polys.aluChip_alu_ic[i] = rows[i].aluChip_alu_ic; - polys.aluChip_alu_op_add[i] = rows[i].aluChip_alu_op_add; - polys.aluChip_alu_op_sub[i] = rows[i].aluChip_alu_op_sub; - polys.aluChip_alu_op_mul[i] = rows[i].aluChip_alu_op_mul; - polys.aluChip_alu_op_div[i] = rows[i].aluChip_alu_op_div; - polys.aluChip_alu_ff_tag[i] = rows[i].aluChip_alu_ff_tag; - polys.aluChip_alu_u8_tag[i] = rows[i].aluChip_alu_u8_tag; - polys.aluChip_alu_u16_tag[i] = rows[i].aluChip_alu_u16_tag; - polys.aluChip_alu_u32_tag[i] = rows[i].aluChip_alu_u32_tag; - polys.aluChip_alu_u64_tag[i] = rows[i].aluChip_alu_u64_tag; - polys.aluChip_alu_u128_tag[i] = rows[i].aluChip_alu_u128_tag; - polys.aluChip_alu_u8_r0[i] = rows[i].aluChip_alu_u8_r0; - polys.aluChip_alu_u8_r1[i] = rows[i].aluChip_alu_u8_r1; - polys.aluChip_alu_u16_r0[i] = rows[i].aluChip_alu_u16_r0; - polys.aluChip_alu_u16_r1[i] = rows[i].aluChip_alu_u16_r1; - polys.aluChip_alu_u16_r2[i] = rows[i].aluChip_alu_u16_r2; - polys.aluChip_alu_u16_r3[i] = rows[i].aluChip_alu_u16_r3; - polys.aluChip_alu_u16_r4[i] = rows[i].aluChip_alu_u16_r4; - polys.aluChip_alu_u16_r5[i] = rows[i].aluChip_alu_u16_r5; - polys.aluChip_alu_u16_r6[i] = rows[i].aluChip_alu_u16_r6; - polys.aluChip_alu_u16_r7[i] = rows[i].aluChip_alu_u16_r7; - polys.aluChip_alu_u64_r0[i] = rows[i].aluChip_alu_u64_r0; - polys.aluChip_alu_cf[i] = rows[i].aluChip_alu_cf; - polys.avmMini_pc[i] = rows[i].avmMini_pc; - polys.avmMini_internal_return_ptr[i] = rows[i].avmMini_internal_return_ptr; - polys.avmMini_sel_internal_call[i] = rows[i].avmMini_sel_internal_call; - polys.avmMini_sel_internal_return[i] = rows[i].avmMini_sel_internal_return; - polys.avmMini_sel_jump[i] = rows[i].avmMini_sel_jump; - polys.avmMini_sel_halt[i] = rows[i].avmMini_sel_halt; - polys.avmMini_sel_op_add[i] = rows[i].avmMini_sel_op_add; - polys.avmMini_sel_op_sub[i] = rows[i].avmMini_sel_op_sub; - polys.avmMini_sel_op_mul[i] = rows[i].avmMini_sel_op_mul; - polys.avmMini_sel_op_div[i] = rows[i].avmMini_sel_op_div; - polys.avmMini_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.equiv_tag_err[i] = rows[i].equiv_tag_err; - polys.equiv_tag_err_counts[i] = rows[i].equiv_tag_err_counts; - } - - polys.avmMini_pc_shift = Polynomial(polys.avmMini_pc.shifted()); - polys.avmMini_internal_return_ptr_shift = Polynomial(polys.avmMini_internal_return_ptr.shifted()); - polys.aluChip_alu_u16_r6_shift = Polynomial(polys.aluChip_alu_u16_r6.shifted()); - polys.aluChip_alu_u16_r3_shift = Polynomial(polys.aluChip_alu_u16_r3.shifted()); - polys.aluChip_alu_u16_r2_shift = Polynomial(polys.aluChip_alu_u16_r2.shifted()); - polys.aluChip_alu_u16_r7_shift = Polynomial(polys.aluChip_alu_u16_r7.shifted()); - polys.aluChip_alu_u16_r4_shift = Polynomial(polys.aluChip_alu_u16_r4.shifted()); - polys.aluChip_alu_u16_r5_shift = Polynomial(polys.aluChip_alu_u16_r5.shifted()); - polys.aluChip_alu_u16_r1_shift = Polynomial(polys.aluChip_alu_u16_r1.shifted()); - polys.aluChip_alu_u16_r0_shift = Polynomial(polys.aluChip_alu_u16_r0.shifted()); - polys.memTrace_m_addr_shift = Polynomial(polys.memTrace_m_addr.shifted()); - polys.memTrace_m_rw_shift = Polynomial(polys.memTrace_m_rw.shifted()); - polys.memTrace_m_val_shift = Polynomial(polys.memTrace_m_val.shifted()); - polys.memTrace_m_tag_shift = Polynomial(polys.memTrace_m_tag.shifted()); - - return polys; - } - - [[maybe_unused]] bool check_circuit() - { - - const FF gamma = FF::random_element(); - const FF beta = FF::random_element(); - bb::RelationParameters params{ - .eta = 0, - .beta = beta, - .gamma = gamma, - .public_input_delta = 0, - .lookup_grand_product_delta = 0, - .beta_sqr = 0, - .beta_cube = 0, - .eccvm_set_permutation_delta = 0, - }; - - 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; - }; - - const auto evaluate_logderivative = [&](const std::string& lookup_name) { - // Check the logderivative relation - bb::compute_logderivative_inverse(polys, params, num_rows); - - typename LogDerivativeSettings::SumcheckArrayOfValuesOverSubrelations lookup_result; - - for (auto& r : lookup_result) { - r = 0; - } - for (size_t i = 0; i < num_rows; ++i) { - LogDerivativeSettings::accumulate(lookup_result, polys.get_row(i), params, 1); - } - for (auto r : lookup_result) { - if (r != 0) { - info("Lookup ", lookup_name, " failed."); - return false; - } - } - return true; - }; - - if (!evaluate_relation.template operator()>("avm_mini", - AvmMini_vm::get_relation_label_avm_mini)) { - return false; - } - if (!evaluate_relation.template operator()>("alu_chip", - AvmMini_vm::get_relation_label_alu_chip)) { - return false; - } - if (!evaluate_relation.template operator()>( - "mem_trace", AvmMini_vm::get_relation_label_mem_trace)) { - return false; - } - - if (!evaluate_logderivative.template operator()>("equiv_tag_err")) { - 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 From 31a9dfc8ca78e2de52c9aeceaae97ac64e48ee84 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 13 Feb 2024 20:55:21 +0000 Subject: [PATCH 7/9] chore: add test case for permutation with distinct activation selectors --- barretenberg/cpp/pil/avm/toy_avm.pil | 12 ++- .../flavor/generated/toy_flavor.hpp | 100 ++++++++++++++---- .../generated/toy_circuit_builder.hpp | 19 +++- .../toy_avm/toy_avm_circuit_builder.test.cpp | 38 +++++++ .../relations/generated/toy/declare_views.hpp | 5 + .../generated/toy/two_column_sparse_perm.hpp | 91 ++++++++++++++++ .../vm/generated/toy_verifier.cpp | 8 ++ 7 files changed, 251 insertions(+), 22 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/relations/generated/toy/two_column_sparse_perm.hpp diff --git a/barretenberg/cpp/pil/avm/toy_avm.pil b/barretenberg/cpp/pil/avm/toy_avm.pil index 42f8b1e1340..375c29d8ac6 100644 --- a/barretenberg/cpp/pil/avm/toy_avm.pil +++ b/barretenberg/cpp/pil/avm/toy_avm.pil @@ -8,10 +8,18 @@ namespace toy(256); pol commit set_2_column_1; pol commit set_2_column_2; - // This is a column based tuple lookup + // This is a column based tuple lookup, one selector #[two_column_perm] // the name of the inverse q_tuple_set { set_1_column_1, set_1_column_2 } is { set_2_column_1, set_2_column_2 }; + + // Column based lookup, two selectors + pol commit sparse_column_1, sparse_column_2; + pol commit sparse_lhs, sparse_rhs; + + #[two_column_sparse_perm] // the name of the inverse + sparse_lhs { sparse_column_1 } is sparse_rhs { sparse_column_2 }; + // Relation not used -> we currently require a single relation for codegen q_tuple_set * (1 - q_tuple_set) = 0; @@ -52,4 +60,4 @@ namespace toy(256); pol commit clk, m_clk; #[lookup_err] - q_err_check {m_clk} in q_err {clk}; \ No newline at end of file + q_err_check {m_clk} in q_err {clk}; diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/toy_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/toy_flavor.hpp index 50a5ac4376f..d13ff8df281 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/toy_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/toy_flavor.hpp @@ -15,6 +15,7 @@ #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/relations/generated/toy/toy_avm.hpp" #include "barretenberg/relations/generated/toy/two_column_perm.hpp" +#include "barretenberg/relations/generated/toy/two_column_sparse_perm.hpp" #include "barretenberg/transcript/transcript.hpp" namespace bb { @@ -36,13 +37,14 @@ class ToyFlavor { using RelationSeparator = FF; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 1; - static constexpr size_t NUM_WITNESS_ENTITIES = 22; + static constexpr size_t NUM_WITNESS_ENTITIES = 27; 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 = 23; + static constexpr size_t NUM_ALL_ENTITIES = 28; - using Relations = std::tuple, two_column_perm_relation>; + using Relations = + std::tuple, two_column_perm_relation, two_column_sparse_perm_relation>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -81,6 +83,10 @@ class ToyFlavor { toy_set_1_column_2, toy_set_2_column_1, toy_set_2_column_2, + toy_sparse_column_1, + toy_sparse_column_2, + toy_sparse_lhs, + toy_sparse_rhs, toy_xor_a, toy_xor_b, toy_xor_c, @@ -94,6 +100,7 @@ class ToyFlavor { toy_clk, toy_m_clk, two_column_perm, + two_column_sparse_perm, lookup_xor, lookup_err, lookup_xor_counts, @@ -101,11 +108,33 @@ class ToyFlavor { RefVector get_wires() { - return { toy_q_tuple_set, toy_set_1_column_1, toy_set_1_column_2, toy_set_2_column_1, toy_set_2_column_2, - toy_xor_a, toy_xor_b, toy_xor_c, toy_table_xor_a, toy_table_xor_b, - toy_table_xor_c, toy_q_xor, toy_q_xor_table, toy_q_err, toy_q_err_check, - toy_clk, toy_m_clk, two_column_perm, lookup_xor, lookup_err, - lookup_xor_counts, lookup_err_counts }; + return { toy_q_tuple_set, + toy_set_1_column_1, + toy_set_1_column_2, + toy_set_2_column_1, + toy_set_2_column_2, + toy_sparse_column_1, + toy_sparse_column_2, + toy_sparse_lhs, + toy_sparse_rhs, + toy_xor_a, + toy_xor_b, + toy_xor_c, + toy_table_xor_a, + toy_table_xor_b, + toy_table_xor_c, + toy_q_xor, + toy_q_xor_table, + toy_q_err, + toy_q_err_check, + toy_clk, + toy_m_clk, + two_column_perm, + two_column_sparse_perm, + lookup_xor, + lookup_err, + lookup_xor_counts, + lookup_err_counts }; }; RefVector get_sorted_polynomials() { return {}; }; }; @@ -119,6 +148,10 @@ class ToyFlavor { toy_set_1_column_2, toy_set_2_column_1, toy_set_2_column_2, + toy_sparse_column_1, + toy_sparse_column_2, + toy_sparse_lhs, + toy_sparse_rhs, toy_xor_a, toy_xor_b, toy_xor_c, @@ -132,6 +165,7 @@ class ToyFlavor { toy_clk, toy_m_clk, two_column_perm, + two_column_sparse_perm, lookup_xor, lookup_err, lookup_xor_counts, @@ -139,19 +173,29 @@ class ToyFlavor { RefVector get_wires() { - return { toy_first, toy_q_tuple_set, toy_set_1_column_1, toy_set_1_column_2, toy_set_2_column_1, - toy_set_2_column_2, toy_xor_a, toy_xor_b, toy_xor_c, toy_table_xor_a, - toy_table_xor_b, toy_table_xor_c, toy_q_xor, toy_q_xor_table, toy_q_err, - toy_q_err_check, toy_clk, toy_m_clk, two_column_perm, lookup_xor, - lookup_err, lookup_xor_counts, lookup_err_counts }; + return { toy_first, toy_q_tuple_set, toy_set_1_column_1, + toy_set_1_column_2, toy_set_2_column_1, toy_set_2_column_2, + toy_sparse_column_1, toy_sparse_column_2, toy_sparse_lhs, + toy_sparse_rhs, toy_xor_a, toy_xor_b, + toy_xor_c, toy_table_xor_a, toy_table_xor_b, + toy_table_xor_c, toy_q_xor, toy_q_xor_table, + toy_q_err, toy_q_err_check, toy_clk, + toy_m_clk, two_column_perm, two_column_sparse_perm, + lookup_xor, lookup_err, lookup_xor_counts, + lookup_err_counts }; }; RefVector get_unshifted() { - return { toy_first, toy_q_tuple_set, toy_set_1_column_1, toy_set_1_column_2, toy_set_2_column_1, - toy_set_2_column_2, toy_xor_a, toy_xor_b, toy_xor_c, toy_table_xor_a, - toy_table_xor_b, toy_table_xor_c, toy_q_xor, toy_q_xor_table, toy_q_err, - toy_q_err_check, toy_clk, toy_m_clk, two_column_perm, lookup_xor, - lookup_err, lookup_xor_counts, lookup_err_counts }; + return { toy_first, toy_q_tuple_set, toy_set_1_column_1, + toy_set_1_column_2, toy_set_2_column_1, toy_set_2_column_2, + toy_sparse_column_1, toy_sparse_column_2, toy_sparse_lhs, + toy_sparse_rhs, toy_xor_a, toy_xor_b, + toy_xor_c, toy_table_xor_a, toy_table_xor_b, + toy_table_xor_c, toy_q_xor, toy_q_xor_table, + toy_q_err, toy_q_err_check, toy_clk, + toy_m_clk, two_column_perm, two_column_sparse_perm, + lookup_xor, lookup_err, lookup_xor_counts, + lookup_err_counts }; }; RefVector get_to_be_shifted() { return {}; }; RefVector get_shifted() { return {}; }; @@ -246,6 +290,10 @@ class ToyFlavor { Base::toy_set_1_column_2 = "TOY_SET_1_COLUMN_2"; Base::toy_set_2_column_1 = "TOY_SET_2_COLUMN_1"; Base::toy_set_2_column_2 = "TOY_SET_2_COLUMN_2"; + Base::toy_sparse_column_1 = "TOY_SPARSE_COLUMN_1"; + Base::toy_sparse_column_2 = "TOY_SPARSE_COLUMN_2"; + Base::toy_sparse_lhs = "TOY_SPARSE_LHS"; + Base::toy_sparse_rhs = "TOY_SPARSE_RHS"; Base::toy_xor_a = "TOY_XOR_A"; Base::toy_xor_b = "TOY_XOR_B"; Base::toy_xor_c = "TOY_XOR_C"; @@ -259,6 +307,7 @@ class ToyFlavor { Base::toy_clk = "TOY_CLK"; Base::toy_m_clk = "TOY_M_CLK"; Base::two_column_perm = "TWO_COLUMN_PERM"; + Base::two_column_sparse_perm = "TWO_COLUMN_SPARSE_PERM"; Base::lookup_xor = "LOOKUP_XOR"; Base::lookup_err = "LOOKUP_ERR"; Base::lookup_xor_counts = "LOOKUP_XOR_COUNTS"; @@ -286,6 +335,10 @@ class ToyFlavor { Commitment toy_set_1_column_2; Commitment toy_set_2_column_1; Commitment toy_set_2_column_2; + Commitment toy_sparse_column_1; + Commitment toy_sparse_column_2; + Commitment toy_sparse_lhs; + Commitment toy_sparse_rhs; Commitment toy_xor_a; Commitment toy_xor_b; Commitment toy_xor_c; @@ -299,6 +352,7 @@ class ToyFlavor { Commitment toy_clk; Commitment toy_m_clk; Commitment two_column_perm; + Commitment two_column_sparse_perm; Commitment lookup_xor; Commitment lookup_err; Commitment lookup_xor_counts; @@ -327,6 +381,10 @@ class ToyFlavor { toy_set_1_column_2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); toy_set_2_column_1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); toy_set_2_column_2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + toy_sparse_column_1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + toy_sparse_column_2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + toy_sparse_lhs = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + toy_sparse_rhs = deserialize_from_buffer(Transcript::proof_data, num_frs_read); toy_xor_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); toy_xor_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); toy_xor_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -340,6 +398,7 @@ class ToyFlavor { toy_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); toy_m_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); two_column_perm = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + two_column_sparse_perm = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_xor = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_xor_counts = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -372,6 +431,10 @@ class ToyFlavor { serialize_to_buffer(toy_set_1_column_2, Transcript::proof_data); serialize_to_buffer(toy_set_2_column_1, Transcript::proof_data); serialize_to_buffer(toy_set_2_column_2, Transcript::proof_data); + serialize_to_buffer(toy_sparse_column_1, Transcript::proof_data); + serialize_to_buffer(toy_sparse_column_2, Transcript::proof_data); + serialize_to_buffer(toy_sparse_lhs, Transcript::proof_data); + serialize_to_buffer(toy_sparse_rhs, Transcript::proof_data); serialize_to_buffer(toy_xor_a, Transcript::proof_data); serialize_to_buffer(toy_xor_b, Transcript::proof_data); serialize_to_buffer(toy_xor_c, Transcript::proof_data); @@ -385,6 +448,7 @@ class ToyFlavor { serialize_to_buffer(toy_clk, Transcript::proof_data); serialize_to_buffer(toy_m_clk, Transcript::proof_data); serialize_to_buffer(two_column_perm, Transcript::proof_data); + serialize_to_buffer(two_column_sparse_perm, Transcript::proof_data); serialize_to_buffer(lookup_xor, Transcript::proof_data); serialize_to_buffer(lookup_err, Transcript::proof_data); serialize_to_buffer(lookup_xor_counts, Transcript::proof_data); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/toy_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/toy_circuit_builder.hpp index 4db8fa00074..f6c1a2fa2dd 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/toy_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/toy_circuit_builder.hpp @@ -16,6 +16,7 @@ #include "barretenberg/relations/generated/toy/lookup_xor.hpp" #include "barretenberg/relations/generated/toy/toy_avm.hpp" #include "barretenberg/relations/generated/toy/two_column_perm.hpp" +#include "barretenberg/relations/generated/toy/two_column_sparse_perm.hpp" namespace bb { @@ -26,6 +27,10 @@ template struct ToyFullRow { FF toy_set_1_column_2{}; FF toy_set_2_column_1{}; FF toy_set_2_column_2{}; + FF toy_sparse_column_1{}; + FF toy_sparse_column_2{}; + FF toy_sparse_lhs{}; + FF toy_sparse_rhs{}; FF toy_xor_a{}; FF toy_xor_b{}; FF toy_xor_c{}; @@ -39,6 +44,7 @@ template struct ToyFullRow { FF toy_clk{}; FF toy_m_clk{}; FF two_column_perm{}; + FF two_column_sparse_perm{}; FF lookup_xor{}; FF lookup_err{}; FF lookup_xor_counts{}; @@ -55,8 +61,8 @@ class ToyCircuitBuilder { using Polynomial = Flavor::Polynomial; using ProverPolynomials = Flavor::ProverPolynomials; - static constexpr size_t num_fixed_columns = 23; - static constexpr size_t num_polys = 23; + static constexpr size_t num_fixed_columns = 28; + static constexpr size_t num_polys = 28; std::vector rows; void set_trace(std::vector&& trace) { rows = std::move(trace); } @@ -78,6 +84,10 @@ class ToyCircuitBuilder { polys.toy_set_1_column_2[i] = rows[i].toy_set_1_column_2; polys.toy_set_2_column_1[i] = rows[i].toy_set_2_column_1; polys.toy_set_2_column_2[i] = rows[i].toy_set_2_column_2; + polys.toy_sparse_column_1[i] = rows[i].toy_sparse_column_1; + polys.toy_sparse_column_2[i] = rows[i].toy_sparse_column_2; + polys.toy_sparse_lhs[i] = rows[i].toy_sparse_lhs; + polys.toy_sparse_rhs[i] = rows[i].toy_sparse_rhs; polys.toy_xor_a[i] = rows[i].toy_xor_a; polys.toy_xor_b[i] = rows[i].toy_xor_b; polys.toy_xor_c[i] = rows[i].toy_xor_c; @@ -91,6 +101,7 @@ class ToyCircuitBuilder { polys.toy_clk[i] = rows[i].toy_clk; polys.toy_m_clk[i] = rows[i].toy_m_clk; polys.two_column_perm[i] = rows[i].two_column_perm; + polys.two_column_sparse_perm[i] = rows[i].two_column_sparse_perm; polys.lookup_xor[i] = rows[i].lookup_xor; polys.lookup_err[i] = rows[i].lookup_err; polys.lookup_xor_counts[i] = rows[i].lookup_xor_counts; @@ -175,6 +186,10 @@ class ToyCircuitBuilder { if (!evaluate_logderivative.template operator()>("two_column_perm")) { return false; } + if (!evaluate_logderivative.template operator()>( + "two_column_sparse_perm")) { + return false; + } if (!evaluate_logderivative.template operator()>("lookup_xor")) { return false; } diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp index 6ca2bd59d1b..4e1a77810af 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp @@ -155,6 +155,10 @@ TEST(ToyAVMCircuitBuilder, MultiLookup) // Check circuit passes circuit_builder.set_trace(std::move(rows)); EXPECT_EQ(circuit_builder.check_circuit(), true); + + // Turn off row_3 lookup selector, expect failure + circuit_builder.rows[2].toy_m_clk = FF(0); + EXPECT_EQ(circuit_builder.check_circuit(), false); } TEST(ToyAVMCircuitBuilder, EmptyLookups) @@ -173,4 +177,38 @@ TEST(ToyAVMCircuitBuilder, EmptyLookups) circuit_builder.set_trace(std::move(rows)); EXPECT_EQ(circuit_builder.check_circuit(), true); +} + +TEST(ToyAVMCircuitBuilder, SparsePermutation) +{ + // Test sparse permutation, where the permutation check is not active on all rows + using FF = ToyFlavor::FF; + using Builder = ToyCircuitBuilder; + using Row = Builder::Row; + Builder circuit_builder; + + const size_t circuit_size = 16; + std::vector rows; + // init empty rows + for (size_t i = 0; i < circuit_size; i++) { + Row row{}; + rows.push_back(row); + } + + // Activate lhs on row 1 + Row& row_1 = rows[0]; + row_1.toy_sparse_lhs = FF(1); + row_1.toy_sparse_column_1 = FF(420); + + // Activate rhs on row 5 + Row& row_5 = rows[4]; + row_5.toy_sparse_rhs = FF(1); + row_5.toy_sparse_column_2 = FF(420); + + circuit_builder.set_trace(std::move(rows)); + EXPECT_EQ(circuit_builder.check_circuit(), true); + + // Expect it to break after changing row5 + circuit_builder.rows[4].toy_sparse_column_2 = FF(421); + EXPECT_EQ(circuit_builder.check_circuit(), false); } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/toy/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/toy/declare_views.hpp index 04ea89bf3a1..5b09589e950 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/toy/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/toy/declare_views.hpp @@ -8,6 +8,10 @@ [[maybe_unused]] auto toy_set_1_column_2 = View(new_term.toy_set_1_column_2); \ [[maybe_unused]] auto toy_set_2_column_1 = View(new_term.toy_set_2_column_1); \ [[maybe_unused]] auto toy_set_2_column_2 = View(new_term.toy_set_2_column_2); \ + [[maybe_unused]] auto toy_sparse_column_1 = View(new_term.toy_sparse_column_1); \ + [[maybe_unused]] auto toy_sparse_column_2 = View(new_term.toy_sparse_column_2); \ + [[maybe_unused]] auto toy_sparse_lhs = View(new_term.toy_sparse_lhs); \ + [[maybe_unused]] auto toy_sparse_rhs = View(new_term.toy_sparse_rhs); \ [[maybe_unused]] auto toy_xor_a = View(new_term.toy_xor_a); \ [[maybe_unused]] auto toy_xor_b = View(new_term.toy_xor_b); \ [[maybe_unused]] auto toy_xor_c = View(new_term.toy_xor_c); \ @@ -21,6 +25,7 @@ [[maybe_unused]] auto toy_clk = View(new_term.toy_clk); \ [[maybe_unused]] auto toy_m_clk = View(new_term.toy_m_clk); \ [[maybe_unused]] auto two_column_perm = View(new_term.two_column_perm); \ + [[maybe_unused]] auto two_column_sparse_perm = View(new_term.two_column_sparse_perm); \ [[maybe_unused]] auto lookup_xor = View(new_term.lookup_xor); \ [[maybe_unused]] auto lookup_err = View(new_term.lookup_err); \ [[maybe_unused]] auto lookup_xor_counts = View(new_term.lookup_xor_counts); \ diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/toy/two_column_sparse_perm.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/toy/two_column_sparse_perm.hpp new file mode 100644 index 00000000000..4ba979b2529 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/toy/two_column_sparse_perm.hpp @@ -0,0 +1,91 @@ + + +#pragma once + +#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" + +#include +#include + +namespace bb { + +class two_column_sparse_perm_permutation_settings { + public: + // This constant defines how many columns are bundled together to form each set. + constexpr static size_t COLUMNS_PER_SET = 1; + + /** + * @brief If this method returns true on a row of values, then the inverse polynomial at this index. Otherwise the + * value needs to be set to zero. + * + * @details If this is true then permutation takes place in this row + */ + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in.toy_sparse_lhs == 1 || in.toy_sparse_rhs == 1); + } + + /** + * @brief Get all the entities for the permutation when we don't need to update them + * + * @details The entities are returned as a tuple of references in the following order: + * - The entity/polynomial used to store the product of the inverse values + * - The entity/polynomial that switches on the subrelation of the permutation relation that ensures correctness of + * the inverse polynomial + * - The entity/polynomial that enables adding a tuple-generated value from the first set to the logderivative sum + * subrelation + * - The entity/polynomial that enables adding a tuple-generated value from the second set to the logderivative sum + * subrelation + * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the first set (N.B. ORDER IS IMPORTANT!) + * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the second set (N.B. ORDER IS IMPORTANT!) + * + * @return All the entities needed for the permutation + */ + + template static inline auto get_const_entities(const AllEntities& in) + { + + return std::forward_as_tuple(in.two_column_sparse_perm, + in.toy_sparse_lhs, + in.toy_sparse_lhs, + in.toy_sparse_rhs, + in.toy_sparse_column_1, + in.toy_sparse_column_2); + } + + /** + * @brief Get all the entities for the permutation when need to update them + * + * @details The entities are returned as a tuple of references in the following order: + * - The entity/polynomial used to store the product of the inverse values + * - The entity/polynomial that switches on the subrelation of the permutation relation that ensures correctness of + * the inverse polynomial + * - The entity/polynomial that enables adding a tuple-generated value from the first set to the logderivative sum + * subrelation + * - The entity/polynomial that enables adding a tuple-generated value from the second set to the logderivative sum + * subrelation + * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the first set (N.B. ORDER IS IMPORTANT!) + * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the second set (N.B. ORDER IS IMPORTANT!) + * + * @return All the entities needed for the permutation + */ + + template static inline auto get_nonconst_entities(AllEntities& in) + { + + return std::forward_as_tuple(in.two_column_sparse_perm, + in.toy_sparse_lhs, + in.toy_sparse_lhs, + in.toy_sparse_rhs, + in.toy_sparse_column_1, + in.toy_sparse_column_2); + } +}; + +template +using two_column_sparse_perm_relation = GenericPermutationRelation; +template +using two_column_sparse_perm = GenericPermutation; + +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/toy_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/toy_verifier.cpp index 25afb7b851d..f30cd4207e4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/toy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/toy_verifier.cpp @@ -61,6 +61,12 @@ bool ToyVerifier::verify_proof(const HonkProof& proof) transcript->template receive_from_prover(commitment_labels.toy_set_2_column_1); commitments.toy_set_2_column_2 = transcript->template receive_from_prover(commitment_labels.toy_set_2_column_2); + commitments.toy_sparse_column_1 = + transcript->template receive_from_prover(commitment_labels.toy_sparse_column_1); + commitments.toy_sparse_column_2 = + transcript->template receive_from_prover(commitment_labels.toy_sparse_column_2); + commitments.toy_sparse_lhs = transcript->template receive_from_prover(commitment_labels.toy_sparse_lhs); + commitments.toy_sparse_rhs = transcript->template receive_from_prover(commitment_labels.toy_sparse_rhs); commitments.toy_xor_a = transcript->template receive_from_prover(commitment_labels.toy_xor_a); commitments.toy_xor_b = transcript->template receive_from_prover(commitment_labels.toy_xor_b); commitments.toy_xor_c = transcript->template receive_from_prover(commitment_labels.toy_xor_c); @@ -80,6 +86,8 @@ bool ToyVerifier::verify_proof(const HonkProof& proof) commitments.toy_m_clk = transcript->template receive_from_prover(commitment_labels.toy_m_clk); commitments.two_column_perm = transcript->template receive_from_prover(commitment_labels.two_column_perm); + commitments.two_column_sparse_perm = + transcript->template receive_from_prover(commitment_labels.two_column_sparse_perm); commitments.lookup_xor = transcript->template receive_from_prover(commitment_labels.lookup_xor); commitments.lookup_err = transcript->template receive_from_prover(commitment_labels.lookup_err); commitments.lookup_xor_counts = From 2966933a22b8ad89ed374e7f67dcb40428459fd7 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Wed, 14 Feb 2024 12:19:51 +0000 Subject: [PATCH 8/9] 4303 - return_op mismatch tag for non-ff operations to be removed from unit tests --- .../flavor/generated/avm_flavor.hpp | 46 ++++++------ .../generated/avm_circuit_builder.hpp | 16 ++--- .../relations/generated/avm/avm_alu.hpp | 72 +++++++++---------- .../relations/generated/avm/avm_main.hpp | 62 ++++++++-------- .../relations/generated/avm/avm_mem.hpp | 28 ++++---- .../relations/generated/avm/declare_views.hpp | 8 +-- .../vm/avm_trace/avm_mem_trace.cpp | 1 + .../vm/tests/avm_arithmetic.test.cpp | 62 ++++++++-------- .../vm/tests/avm_bitwise.test.cpp | 10 +-- 9 files changed, 154 insertions(+), 151 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp index be2b324fb94..84bdf27d3f4 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/avm_flavor.hpp @@ -293,14 +293,14 @@ class AvmFlavor { avm_main_last, equiv_tag_err, equiv_tag_err_counts, + avm_alu_alu_u16_r7_shift, avm_alu_alu_u16_r0_shift, + avm_alu_alu_u16_r6_shift, + avm_alu_alu_u16_r3_shift, avm_alu_alu_u16_r2_shift, avm_alu_alu_u16_r4_shift, - avm_alu_alu_u16_r1_shift, avm_alu_alu_u16_r5_shift, - avm_alu_alu_u16_r3_shift, - avm_alu_alu_u16_r6_shift, - avm_alu_alu_u16_r7_shift, + avm_alu_alu_u16_r1_shift, avm_mem_m_tag_shift, avm_mem_m_val_shift, avm_mem_m_rw_shift, @@ -380,14 +380,14 @@ class AvmFlavor { avm_main_last, equiv_tag_err, equiv_tag_err_counts, + avm_alu_alu_u16_r7_shift, avm_alu_alu_u16_r0_shift, + avm_alu_alu_u16_r6_shift, + avm_alu_alu_u16_r3_shift, avm_alu_alu_u16_r2_shift, avm_alu_alu_u16_r4_shift, - avm_alu_alu_u16_r1_shift, avm_alu_alu_u16_r5_shift, - avm_alu_alu_u16_r3_shift, - avm_alu_alu_u16_r6_shift, - avm_alu_alu_u16_r7_shift, + avm_alu_alu_u16_r1_shift, avm_mem_m_tag_shift, avm_mem_m_val_shift, avm_mem_m_rw_shift, @@ -470,14 +470,14 @@ class AvmFlavor { }; RefVector get_to_be_shifted() { - return { avm_alu_alu_u16_r0, + return { avm_alu_alu_u16_r7, + avm_alu_alu_u16_r0, + avm_alu_alu_u16_r6, + avm_alu_alu_u16_r3, avm_alu_alu_u16_r2, avm_alu_alu_u16_r4, - avm_alu_alu_u16_r1, avm_alu_alu_u16_r5, - avm_alu_alu_u16_r3, - avm_alu_alu_u16_r6, - avm_alu_alu_u16_r7, + avm_alu_alu_u16_r1, avm_mem_m_tag, avm_mem_m_val, avm_mem_m_rw, @@ -487,14 +487,14 @@ class AvmFlavor { }; RefVector get_shifted() { - return { avm_alu_alu_u16_r0_shift, + return { avm_alu_alu_u16_r7_shift, + avm_alu_alu_u16_r0_shift, + avm_alu_alu_u16_r6_shift, + avm_alu_alu_u16_r3_shift, avm_alu_alu_u16_r2_shift, avm_alu_alu_u16_r4_shift, - avm_alu_alu_u16_r1_shift, avm_alu_alu_u16_r5_shift, - avm_alu_alu_u16_r3_shift, - avm_alu_alu_u16_r6_shift, - avm_alu_alu_u16_r7_shift, + avm_alu_alu_u16_r1_shift, avm_mem_m_tag_shift, avm_mem_m_val_shift, avm_mem_m_rw_shift, @@ -513,14 +513,14 @@ class AvmFlavor { RefVector get_to_be_shifted() { - return { avm_alu_alu_u16_r0, + return { avm_alu_alu_u16_r7, + avm_alu_alu_u16_r0, + avm_alu_alu_u16_r6, + avm_alu_alu_u16_r3, avm_alu_alu_u16_r2, avm_alu_alu_u16_r4, - avm_alu_alu_u16_r1, avm_alu_alu_u16_r5, - avm_alu_alu_u16_r3, - avm_alu_alu_u16_r6, - avm_alu_alu_u16_r7, + avm_alu_alu_u16_r1, avm_mem_m_tag, avm_mem_m_val, avm_mem_m_rw, 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 c712eb64a44..a3710975c90 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 @@ -90,14 +90,14 @@ template struct AvmFullRow { FF avm_main_last{}; FF equiv_tag_err{}; FF equiv_tag_err_counts{}; + FF avm_alu_alu_u16_r7_shift{}; FF avm_alu_alu_u16_r0_shift{}; + FF avm_alu_alu_u16_r6_shift{}; + FF avm_alu_alu_u16_r3_shift{}; FF avm_alu_alu_u16_r2_shift{}; FF avm_alu_alu_u16_r4_shift{}; - FF avm_alu_alu_u16_r1_shift{}; FF avm_alu_alu_u16_r5_shift{}; - FF avm_alu_alu_u16_r3_shift{}; - FF avm_alu_alu_u16_r6_shift{}; - FF avm_alu_alu_u16_r7_shift{}; + FF avm_alu_alu_u16_r1_shift{}; FF avm_mem_m_tag_shift{}; FF avm_mem_m_val_shift{}; FF avm_mem_m_rw_shift{}; @@ -205,14 +205,14 @@ class AvmCircuitBuilder { polys.equiv_tag_err_counts[i] = rows[i].equiv_tag_err_counts; } + 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_r6_shift = Polynomial(polys.avm_alu_alu_u16_r6.shifted()); + polys.avm_alu_alu_u16_r3_shift = Polynomial(polys.avm_alu_alu_u16_r3.shifted()); polys.avm_alu_alu_u16_r2_shift = Polynomial(polys.avm_alu_alu_u16_r2.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_r5_shift = Polynomial(polys.avm_alu_alu_u16_r5.shifted()); - polys.avm_alu_alu_u16_r3_shift = Polynomial(polys.avm_alu_alu_u16_r3.shifted()); - polys.avm_alu_alu_u16_r6_shift = Polynomial(polys.avm_alu_alu_u16_r6.shifted()); - polys.avm_alu_alu_u16_r7_shift = Polynomial(polys.avm_alu_alu_u16_r7.shifted()); + polys.avm_alu_alu_u16_r1_shift = Polynomial(polys.avm_alu_alu_u16_r1.shifted()); polys.avm_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_rw_shift = Polynomial(polys.avm_mem_m_rw.shifted()); 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 e58658ada59..b3f38902a97 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,67 @@ namespace bb::Avm_vm { template struct Avm_aluRow { - FF avm_alu_alu_ib{}; + FF avm_alu_alu_u8_r0{}; + FF avm_alu_alu_ff_tag{}; + FF avm_alu_alu_u16_r7_shift{}; FF avm_alu_alu_cf{}; - FF avm_alu_alu_u16_r6{}; - FF avm_alu_alu_u128_tag{}; - FF avm_alu_alu_u8_r1{}; - FF avm_alu_alu_u16_r0_shift{}; - FF avm_alu_alu_u16_r2_shift{}; + FF avm_alu_alu_op_sub{}; + FF avm_alu_alu_u16_r3{}; FF avm_alu_alu_ia{}; + FF avm_alu_alu_u16_r0_shift{}; + FF avm_alu_alu_u16_r6_shift{}; + FF avm_alu_alu_ic{}; + FF avm_alu_alu_u8_tag{}; + FF avm_alu_alu_u128_tag{}; + FF avm_alu_alu_u16_r2{}; FF avm_alu_alu_op_add{}; - FF avm_alu_alu_u16_r7{}; + FF avm_alu_alu_u8_r1{}; + FF avm_alu_alu_u16_tag{}; + FF avm_alu_alu_u64_tag{}; FF avm_alu_alu_u16_r4{}; + FF avm_alu_alu_u16_r7{}; + FF avm_alu_alu_u32_tag{}; + FF avm_alu_alu_u16_r1{}; + FF avm_alu_alu_u16_r3_shift{}; + FF avm_alu_alu_u16_r0{}; FF avm_alu_alu_u16_r5{}; + FF avm_alu_alu_u16_r6{}; + FF avm_alu_alu_ib{}; + FF avm_alu_alu_u16_r2_shift{}; FF avm_alu_alu_u16_r4_shift{}; - FF avm_alu_alu_u64_r0{}; - FF avm_alu_alu_op_sub{}; - FF avm_alu_alu_u16_r0{}; - FF avm_alu_alu_u16_r1_shift{}; FF avm_alu_alu_u16_r5_shift{}; - FF avm_alu_alu_u16_tag{}; - FF avm_alu_alu_u8_r0{}; - FF avm_alu_alu_u32_tag{}; - FF avm_alu_alu_ff_tag{}; - FF avm_alu_alu_u16_r3_shift{}; - FF avm_alu_alu_u16_r3{}; - FF avm_alu_alu_u8_tag{}; - FF avm_alu_alu_u16_r6_shift{}; + FF avm_alu_alu_u64_r0{}; FF avm_alu_alu_op_not{}; - FF avm_alu_alu_ic{}; - FF avm_alu_alu_u16_r7_shift{}; - FF avm_alu_alu_u16_r1{}; - FF avm_alu_alu_u16_r2{}; - FF avm_alu_alu_u64_tag{}; + FF avm_alu_alu_u16_r1_shift{}; FF avm_alu_alu_op_mul{}; }; inline std::string get_relation_label_avm_alu(int index) { switch (index) { - case 6: - return "ALU_ADD_SUB_1"; - - case 13: - return "ALU_MULTIPLICATION_OUT_U128"; - case 15: return "ALU_OP_NOT"; - case 8: - return "ALU_MULTIPLICATION_FF"; + case 9: + return "ALU_MUL_COMMON_1"; case 10: return "ALU_MUL_COMMON_2"; + case 7: + return "ALU_ADD_SUB_2"; + case 14: return "ALU_FF_NOT_XOR"; - case 9: - return "ALU_MUL_COMMON_1"; + case 6: + return "ALU_ADD_SUB_1"; - case 7: - return "ALU_ADD_SUB_2"; + case 13: + return "ALU_MULTIPLICATION_OUT_U128"; + + case 8: + return "ALU_MULTIPLICATION_FF"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp index 6050d97ef66..bfd8ca51672 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp @@ -7,50 +7,47 @@ namespace bb::Avm_vm { template struct Avm_mainRow { + FF avm_main_pc{}; + FF avm_main_rwa{}; + FF avm_main_internal_return_ptr_shift{}; + FF avm_main_internal_return_ptr{}; FF avm_main_mem_op_b{}; - FF avm_main_sel_jump{}; - FF avm_main_sel_op_not{}; - FF avm_main_rwb{}; - FF avm_main_op_err{}; - FF avm_main_ic{}; + FF avm_main_mem_idx_b{}; FF avm_main_mem_idx_a{}; - FF avm_main_internal_return_ptr_shift{}; + FF avm_main_ib{}; + FF avm_main_tag_err{}; + FF avm_main_inv{}; + FF avm_main_mem_op_a{}; + FF avm_main_op_err{}; FF avm_main_sel_internal_return{}; - FF avm_main_sel_op_add{}; - FF avm_main_mem_op_c{}; - FF avm_main_sel_halt{}; - FF avm_main_pc{}; FF avm_main_sel_internal_call{}; - FF avm_main_sel_op_sub{}; FF avm_main_rwc{}; - FF avm_main_mem_idx_b{}; - FF avm_main_mem_op_a{}; - FF avm_main_sel_op_div{}; - FF avm_main_first{}; + FF avm_main_mem_op_c{}; FF avm_main_sel_op_mul{}; + FF avm_main_sel_op_sub{}; + FF avm_main_rwb{}; + FF avm_main_sel_op_not{}; + FF avm_main_sel_halt{}; + FF avm_main_ic{}; + FF avm_main_sel_op_add{}; FF avm_main_ia{}; - FF avm_main_internal_return_ptr{}; - FF avm_main_ib{}; - FF avm_main_inv{}; - FF avm_main_tag_err{}; FF avm_main_pc_shift{}; - FF avm_main_rwa{}; + FF avm_main_sel_jump{}; + FF avm_main_first{}; + FF avm_main_sel_op_div{}; }; inline std::string get_relation_label_avm_main(int index) { switch (index) { - case 37: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - - case 36: - return "PC_INCREMENT"; - case 20: return "SUBOP_DIVISION_FF"; - case 22: - return "SUBOP_DIVISION_ZERO_ERR2"; + case 23: + return "SUBOP_ERROR_RELEVANT_OP"; + + case 37: + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; case 21: return "SUBOP_DIVISION_ZERO_ERR1"; @@ -58,11 +55,14 @@ inline std::string get_relation_label_avm_main(int index) case 31: return "RETURN_POINTER_DECREMENT"; + case 22: + return "SUBOP_DIVISION_ZERO_ERR2"; + + case 36: + return "PC_INCREMENT"; + case 25: return "RETURN_POINTER_INCREMENT"; - - case 23: - return "SUBOP_ERROR_RELEVANT_OP"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp index 7c8a0a1687a..4d8fd31d598 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp @@ -7,41 +7,41 @@ namespace bb::Avm_vm { template struct Avm_memRow { - FF avm_mem_m_addr{}; - FF avm_mem_m_tag_err{}; - FF avm_mem_m_in_tag{}; FF avm_mem_m_tag_shift{}; FF avm_mem_m_one_min_inv{}; - FF avm_mem_m_last{}; - FF avm_mem_m_val{}; FF avm_mem_m_tag{}; - FF avm_mem_m_lastAccess{}; + FF avm_mem_m_tag_err{}; FF avm_mem_m_val_shift{}; - FF avm_mem_m_rw{}; + FF avm_mem_m_lastAccess{}; FF avm_mem_m_rw_shift{}; + FF avm_mem_m_addr{}; + FF avm_mem_m_val{}; + FF avm_mem_m_last{}; + FF avm_mem_m_rw{}; FF avm_mem_m_addr_shift{}; + FF avm_mem_m_in_tag{}; }; inline std::string get_relation_label_avm_mem(int index) { switch (index) { - case 9: - return "MEM_IN_TAG_CONSISTENCY_2"; + case 7: + return "MEM_ZERO_INIT"; case 4: return "MEM_LAST_ACCESS_DELIMITER"; + case 8: + return "MEM_IN_TAG_CONSISTENCY_1"; + case 5: return "MEM_READ_WRITE_VAL_CONSISTENCY"; case 6: return "MEM_READ_WRITE_TAG_CONSISTENCY"; - case 7: - return "MEM_ZERO_INIT"; - - case 8: - return "MEM_IN_TAG_CONSISTENCY_1"; + case 9: + return "MEM_IN_TAG_CONSISTENCY_2"; } 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 717acfd2b65..9b1ec9c0d09 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp @@ -72,14 +72,14 @@ [[maybe_unused]] auto avm_main_last = View(new_term.avm_main_last); \ [[maybe_unused]] auto equiv_tag_err = View(new_term.equiv_tag_err); \ [[maybe_unused]] auto equiv_tag_err_counts = View(new_term.equiv_tag_err_counts); \ + [[maybe_unused]] auto avm_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_r6_shift = View(new_term.avm_alu_alu_u16_r6_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_r2_shift = View(new_term.avm_alu_alu_u16_r2_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_r5_shift = View(new_term.avm_alu_alu_u16_r5_shift); \ - [[maybe_unused]] auto avm_alu_alu_u16_r3_shift = View(new_term.avm_alu_alu_u16_r3_shift); \ - [[maybe_unused]] auto avm_alu_alu_u16_r6_shift = View(new_term.avm_alu_alu_u16_r6_shift); \ - [[maybe_unused]] auto avm_alu_alu_u16_r7_shift = View(new_term.avm_alu_alu_u16_r7_shift); \ + [[maybe_unused]] auto avm_alu_alu_u16_r1_shift = View(new_term.avm_alu_alu_u16_r1_shift); \ [[maybe_unused]] auto avm_mem_m_tag_shift = View(new_term.avm_mem_m_tag_shift); \ [[maybe_unused]] auto avm_mem_m_val_shift = View(new_term.avm_mem_m_val_shift); \ [[maybe_unused]] auto avm_mem_m_rw_shift = View(new_term.avm_mem_m_rw_shift); \ diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp index 058b74a3f81..b0746af1d29 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp @@ -1,4 +1,5 @@ #include "avm_mem_trace.hpp" +#include "barretenberg/vm/avm_trace/avm_common.hpp" namespace avm_trace { 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..26c13844c79 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp @@ -1,6 +1,7 @@ #include "avm_common.test.hpp" #include "barretenberg/numeric/uint128/uint128.hpp" +#include "barretenberg/vm/avm_trace/avm_helper.hpp" using namespace bb; using namespace bb::numeric; @@ -454,7 +455,7 @@ TEST_F(AvmArithmeticTestsU8, addition) // Memory layout: [62,29,0,0,0,....] trace_builder.op_add(0, 1, 2, AvmMemoryTag::U8); // [62,29,91,0,0,....] - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_add(trace, FF(62), FF(29), FF(91), FF(0), FF(1), FF(2), AvmMemoryTag::U8); @@ -462,6 +463,7 @@ TEST_F(AvmArithmeticTestsU8, addition) EXPECT_EQ(alu_row.avm_alu_alu_u8_tag, FF(1)); EXPECT_EQ(alu_row.avm_alu_alu_cf, FF(0)); EXPECT_EQ(alu_row.avm_alu_alu_u8_r0, FF(91)); + validate_trace_proof(std::move(trace)); } @@ -474,7 +476,7 @@ TEST_F(AvmArithmeticTestsU8, additionCarry) // Memory layout: [159,100,0,0,0,....] trace_builder.op_add(0, 1, 2, AvmMemoryTag::U8); // [159,100,3,0,0,....] - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_add(trace, FF(159), FF(100), FF(3), FF(0), FF(1), FF(2), AvmMemoryTag::U8); @@ -496,7 +498,7 @@ TEST_F(AvmArithmeticTestsU8, subtraction) // Memory layout: [162,29,0,0,0,....] trace_builder.op_sub(0, 1, 2, AvmMemoryTag::U8); // [162,29,133,0,0,....] - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_sub(trace, FF(162), FF(29), FF(133), FF(0), FF(1), FF(2), AvmMemoryTag::U8); @@ -518,7 +520,7 @@ TEST_F(AvmArithmeticTestsU8, subtractionCarry) // Memory layout: [5,29,0,0,0,....] trace_builder.op_sub(0, 1, 2, AvmMemoryTag::U8); // [5,29,232,0,0,....] - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_sub(trace, FF(5), FF(29), FF(232), FF(0), FF(1), FF(2), AvmMemoryTag::U8); @@ -546,7 +548,7 @@ TEST_F(AvmArithmeticTestsU8, multiplication) trace_builder.set(15, 1, AvmMemoryTag::U8); trace_builder.op_mul(0, 1, 2, AvmMemoryTag::U8); - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row_index = common_validate_mul(trace, FF(13), FF(15), FF(195), FF(0), FF(1), FF(2), AvmMemoryTag::U8); @@ -569,7 +571,7 @@ TEST_F(AvmArithmeticTestsU8, multiplicationOverflow) trace_builder.set(170, 1, AvmMemoryTag::U8); trace_builder.op_mul(0, 1, 2, AvmMemoryTag::U8); - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row_index = common_validate_mul(trace, FF(200), FF(170), FF(208), FF(0), FF(1), FF(2), AvmMemoryTag::U8); @@ -597,7 +599,7 @@ TEST_F(AvmArithmeticTestsU16, addition) trace_builder.set(33005, 546, AvmMemoryTag::U16); trace_builder.op_add(546, 119, 5, AvmMemoryTag::U16); - trace_builder.return_op(5, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = @@ -619,7 +621,7 @@ TEST_F(AvmArithmeticTestsU16, additionCarry) trace_builder.set(1000, 1, AvmMemoryTag::U16); trace_builder.op_add(1, 0, 0, AvmMemoryTag::U16); - trace_builder.return_op(0, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = @@ -641,7 +643,7 @@ TEST_F(AvmArithmeticTestsU16, subtraction) trace_builder.set(33005, 546, AvmMemoryTag::U16); trace_builder.op_sub(546, 119, 5, AvmMemoryTag::U16); - trace_builder.return_op(5, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = @@ -665,7 +667,7 @@ TEST_F(AvmArithmeticTestsU16, subtractionCarry) trace_builder.set(1000, 1, AvmMemoryTag::U16); trace_builder.op_sub(1, 0, 0, AvmMemoryTag::U16); - trace_builder.return_op(0, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = @@ -694,7 +696,7 @@ TEST_F(AvmArithmeticTestsU16, multiplication) trace_builder.set(245, 1, AvmMemoryTag::U16); trace_builder.op_mul(0, 1, 2, AvmMemoryTag::U16); - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row_index = @@ -719,7 +721,7 @@ TEST_F(AvmArithmeticTestsU16, multiplicationOverflow) trace_builder.set(1024, 1, AvmMemoryTag::U16); trace_builder.op_mul(0, 1, 2, AvmMemoryTag::U16); - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row_index = common_validate_mul(trace, FF(512), FF(1024), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::U16); @@ -749,7 +751,7 @@ TEST_F(AvmArithmeticTestsU32, addition) trace_builder.set(1234567891, 9, AvmMemoryTag::U32); trace_builder.op_add(8, 9, 0, AvmMemoryTag::U32); - trace_builder.return_op(0, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_add( @@ -772,7 +774,7 @@ TEST_F(AvmArithmeticTestsU32, additionCarry) trace_builder.set(2293, 9, AvmMemoryTag::U32); trace_builder.op_add(8, 9, 0, AvmMemoryTag::U32); - trace_builder.return_op(0, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = @@ -794,7 +796,7 @@ TEST_F(AvmArithmeticTestsU32, subtraction) trace_builder.set(1234567891, 9, AvmMemoryTag::U32); trace_builder.op_sub(8, 9, 0, AvmMemoryTag::U32); - trace_builder.return_op(0, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_sub( @@ -821,7 +823,7 @@ TEST_F(AvmArithmeticTestsU32, subtractionCarry) trace_builder.set(3210987654, 9, AvmMemoryTag::U32); trace_builder.op_sub(9, 8, 0, AvmMemoryTag::U32); - trace_builder.return_op(0, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_sub( @@ -852,7 +854,7 @@ TEST_F(AvmArithmeticTestsU32, multiplication) trace_builder.set(11111, 1, AvmMemoryTag::U32); trace_builder.op_mul(0, 1, 2, AvmMemoryTag::U32); - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row_index = @@ -881,7 +883,7 @@ TEST_F(AvmArithmeticTestsU32, multiplicationOverflow) trace_builder.set(13 << 22, 1, AvmMemoryTag::U32); trace_builder.op_mul(0, 1, 2, AvmMemoryTag::U32); - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row_index = @@ -918,7 +920,7 @@ TEST_F(AvmArithmeticTestsU64, addition) trace_builder.set(b, 9, AvmMemoryTag::U64); trace_builder.op_add(8, 9, 9, AvmMemoryTag::U64); - trace_builder.return_op(9, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_add(trace, FF(a), FF(b), FF(c), FF(8), FF(9), FF(9), AvmMemoryTag::U64); @@ -948,7 +950,7 @@ TEST_F(AvmArithmeticTestsU64, additionCarry) trace_builder.set(b, 1, AvmMemoryTag::U64); trace_builder.op_add(0, 1, 0, AvmMemoryTag::U64); - trace_builder.return_op(0, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_add(trace, FF(a), FF(b), FF(c), FF(0), FF(1), FF(0), AvmMemoryTag::U64); @@ -976,7 +978,7 @@ TEST_F(AvmArithmeticTestsU64, subtraction) trace_builder.set(b, 9, AvmMemoryTag::U64); trace_builder.op_sub(8, 9, 9, AvmMemoryTag::U64); - trace_builder.return_op(9, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_sub(trace, FF(a), FF(b), FF(c), FF(8), FF(9), FF(9), AvmMemoryTag::U64); @@ -1008,7 +1010,7 @@ TEST_F(AvmArithmeticTestsU64, subtractionCarry) trace_builder.set(b, 1, AvmMemoryTag::U64); trace_builder.op_sub(0, 1, 0, AvmMemoryTag::U64); - trace_builder.return_op(0, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_sub(trace, FF(a), FF(b), FF(c), FF(0), FF(1), FF(0), AvmMemoryTag::U64); @@ -1036,7 +1038,7 @@ TEST_F(AvmArithmeticTestsU64, multiplication) trace_builder.set(555444333, 1, AvmMemoryTag::U64); trace_builder.op_mul(0, 1, 2, AvmMemoryTag::U64); - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row_index = common_validate_mul( @@ -1069,7 +1071,7 @@ TEST_F(AvmArithmeticTestsU64, multiplicationOverflow) trace_builder.set(b, 1, AvmMemoryTag::U64); trace_builder.op_mul(0, 1, 2, AvmMemoryTag::U64); - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row_index = common_validate_mul(trace, FF(a), FF(b), FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::U64); @@ -1108,7 +1110,7 @@ TEST_F(AvmArithmeticTestsU128, addition) trace_builder.set(b, 9, AvmMemoryTag::U128); trace_builder.op_add(8, 9, 9, AvmMemoryTag::U128); - trace_builder.return_op(9, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_add(trace, @@ -1148,7 +1150,7 @@ TEST_F(AvmArithmeticTestsU128, additionCarry) trace_builder.set(b, 9, AvmMemoryTag::U128); trace_builder.op_add(8, 9, 9, AvmMemoryTag::U128); - trace_builder.return_op(9, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_add(trace, @@ -1187,7 +1189,7 @@ TEST_F(AvmArithmeticTestsU128, subtraction) trace_builder.set(b, 9, AvmMemoryTag::U128); trace_builder.op_sub(8, 9, 9, AvmMemoryTag::U128); - trace_builder.return_op(9, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_sub(trace, @@ -1229,7 +1231,7 @@ TEST_F(AvmArithmeticTestsU128, subtractionCarry) trace_builder.set(b, 9, AvmMemoryTag::U128); trace_builder.op_sub(8, 9, 9, AvmMemoryTag::U128); - trace_builder.return_op(9, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_sub(trace, @@ -1267,7 +1269,7 @@ TEST_F(AvmArithmeticTestsU128, multiplication) FF c{ uint256_t{ 0xA7DDA0BAE60CA3A5, 0x70289AEB0, 0, 0 } }; trace_builder.op_mul(0, 1, 2, AvmMemoryTag::U128); - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row_index = common_validate_mul( @@ -1304,7 +1306,7 @@ TEST_F(AvmArithmeticTestsU128, multiplicationOverflow) trace_builder.set(b, 1, AvmMemoryTag::U128); trace_builder.op_mul(0, 1, 2, AvmMemoryTag::U128); - trace_builder.return_op(2, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row_index = common_validate_mul(trace, diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp index 58760e5a6f6..3abc6645219 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp @@ -117,7 +117,7 @@ TEST_F(AvmBitwiseTestsU8, BitwiseNot) { trace_builder.set(1, 0, AvmMemoryTag::U8); // Memory Layout: [1,0,0,...] trace_builder.op_not(0, 1, AvmMemoryTag::U8); // [1,254,0,0,....] - trace_builder.return_op(1, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_op_not(trace, FF(1), FF(254), FF(0), FF(1), AvmMemoryTag::U8); @@ -130,7 +130,7 @@ TEST_F(AvmBitwiseTestsU16, BitwiseNot) { trace_builder.set(512, 0, AvmMemoryTag::U16); // Memory Layout: [512,0,0,...] trace_builder.op_not(0, 1, AvmMemoryTag::U16); // [512,65023,0,0,0,....] - trace_builder.return_op(1, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_op_not(trace, FF(512), FF(65'023), FF(0), FF(1), AvmMemoryTag::U16); @@ -143,7 +143,7 @@ TEST_F(AvmBitwiseTestsU32, BitwiseNot) { trace_builder.set(131'072, 0, AvmMemoryTag::U32); // Memory Layout: [131072,0,0,...] trace_builder.op_not(0, 1, AvmMemoryTag::U32); // [131072,4294836223,,0,0,....] - trace_builder.return_op(1, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = common_validate_op_not(trace, FF(131'072), FF(4'294'836'223LLU), FF(0), FF(1), AvmMemoryTag::U32); @@ -156,7 +156,7 @@ TEST_F(AvmBitwiseTestsU64, BitwiseNot) { trace_builder.set(0x100000000LLU, 0, AvmMemoryTag::U64); // Memory Layout: [8589934592,0,0,...] trace_builder.op_not(0, 1, AvmMemoryTag::U64); // [8589934592,18446744069414584319,0,0,....] - trace_builder.return_op(1, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); auto alu_row = @@ -172,7 +172,7 @@ TEST_F(AvmBitwiseTestsU128, BitwiseNot) uint128_t const a = uint128_t{ 0x4000000000000 } << 64; trace_builder.set(a, 0, AvmMemoryTag::U128); trace_builder.op_not(0, 1, AvmMemoryTag::U128); - trace_builder.return_op(1, 1); + trace_builder.return_op(0, 0); auto trace = trace_builder.finalize(); uint128_t const res = (uint128_t{ 0xfffbffffffffffff } << 64) + uint128_t{ 0xffffffffffffffff }; From 31d13cad078496d2f1e211c9e549486c74d02f09 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:50:39 +0000 Subject: [PATCH 9/9] fix: merge --- .../cpp/src/barretenberg/relations/generated/toy/toy_avm.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/toy/toy_avm.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/toy/toy_avm.hpp index 02b736fc92c..010fad5c2c5 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/toy/toy_avm.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/toy/toy_avm.hpp @@ -7,9 +7,9 @@ namespace bb::Toy_vm { template struct Toy_avmRow { - FF toy_q_xor_table{}; FF toy_q_tuple_set{}; FF toy_q_xor{}; + FF toy_q_xor_table{}; }; inline std::string get_relation_label_toy_avm(int index)