Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(avm): Add 15 additional 16-bit registers in ALU trace of AVM circuit #5503

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions barretenberg/cpp/pil/avm/avm_alu.pil
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ namespace avm_alu(256);
pol commit u16_r5;
pol commit u16_r6;
pol commit u16_r7;
pol commit u16_r8;
pol commit u16_r9;
pol commit u16_r10;
pol commit u16_r11;
pol commit u16_r12;
pol commit u16_r13;
pol commit u16_r14;

// 64-bit slice register
pol commit u64_r0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@
[[maybe_unused]] auto avm_alu_u128_tag = View(new_term.avm_alu_u128_tag); \
[[maybe_unused]] auto avm_alu_u16_r0 = View(new_term.avm_alu_u16_r0); \
[[maybe_unused]] auto avm_alu_u16_r1 = View(new_term.avm_alu_u16_r1); \
[[maybe_unused]] auto avm_alu_u16_r10 = View(new_term.avm_alu_u16_r10); \
[[maybe_unused]] auto avm_alu_u16_r11 = View(new_term.avm_alu_u16_r11); \
[[maybe_unused]] auto avm_alu_u16_r12 = View(new_term.avm_alu_u16_r12); \
[[maybe_unused]] auto avm_alu_u16_r13 = View(new_term.avm_alu_u16_r13); \
[[maybe_unused]] auto avm_alu_u16_r14 = View(new_term.avm_alu_u16_r14); \
[[maybe_unused]] auto avm_alu_u16_r2 = View(new_term.avm_alu_u16_r2); \
[[maybe_unused]] auto avm_alu_u16_r3 = View(new_term.avm_alu_u16_r3); \
[[maybe_unused]] auto avm_alu_u16_r4 = View(new_term.avm_alu_u16_r4); \
[[maybe_unused]] auto avm_alu_u16_r5 = View(new_term.avm_alu_u16_r5); \
[[maybe_unused]] auto avm_alu_u16_r6 = View(new_term.avm_alu_u16_r6); \
[[maybe_unused]] auto avm_alu_u16_r7 = View(new_term.avm_alu_u16_r7); \
[[maybe_unused]] auto avm_alu_u16_r8 = View(new_term.avm_alu_u16_r8); \
[[maybe_unused]] auto avm_alu_u16_r9 = View(new_term.avm_alu_u16_r9); \
[[maybe_unused]] auto avm_alu_u16_tag = View(new_term.avm_alu_u16_tag); \
[[maybe_unused]] auto avm_alu_u32_tag = View(new_term.avm_alu_u32_tag); \
[[maybe_unused]] auto avm_alu_u64_r0 = View(new_term.avm_alu_u64_r0); \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ FF AvmAluTraceBuilder::op_add(FF const& a, FF const& b, AvmMemoryTag in_tag, uin
bool carry = false;
uint8_t alu_u8_r0 = 0;
uint8_t alu_u8_r1 = 0;
std::array<uint16_t, 8> alu_u16_reg{}; // Must be zero-initialized (FF tag case)
std::array<uint16_t, 15> alu_u16_reg{}; // Must be zero-initialized (FF tag case)

uint128_t a_u128{ a };
uint128_t b_u128{ b };
Expand Down Expand Up @@ -140,7 +140,7 @@ FF AvmAluTraceBuilder::op_sub(FF const& a, FF const& b, AvmMemoryTag in_tag, uin
bool carry = false;
uint8_t alu_u8_r0 = 0;
uint8_t alu_u8_r1 = 0;
std::array<uint16_t, 8> alu_u16_reg{}; // Must be zero-initialized (FF tag case)
std::array<uint16_t, 15> alu_u16_reg{}; // Must be zero-initialized (FF tag case)
uint128_t a_u128{ a };
uint128_t b_u128{ b };
uint128_t c_u128 = a_u128 - b_u128;
Expand Down Expand Up @@ -225,7 +225,7 @@ FF AvmAluTraceBuilder::op_mul(FF const& a, FF const& b, AvmMemoryTag in_tag, uin
uint8_t alu_u8_r0 = 0;
uint8_t alu_u8_r1 = 0;

std::array<uint16_t, 8> alu_u16_reg{}; // Must be zero-initialized (FF tag case)
std::array<uint16_t, 15> alu_u16_reg{}; // Must be zero-initialized (FF tag case)

uint128_t a_u128{ a };
uint128_t b_u128{ b };
Expand Down Expand Up @@ -258,8 +258,8 @@ FF AvmAluTraceBuilder::op_mul(FF const& a, FF const& b, AvmMemoryTag in_tag, uin
uint128_t c_u128 = a_u128 * b_u128;

// Decompose a_u128 and b_u128 over 8 16-bit registers.
std::array<uint16_t, 8> alu_u16_reg_a; // Will be initialized in for loop below.
std::array<uint16_t, 8> alu_u16_reg_b; // Will be initialized in for loop below.
std::array<uint16_t, 15> alu_u16_reg_a; // Will be initialized in for loop below.
std::array<uint16_t, 15> alu_u16_reg_b; // Will be initialized in for loop below.
uint128_t a_trunc_128 = a_u128;
uint128_t b_trunc_128 = b_u128;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AvmAluTraceBuilder {
uint8_t alu_u8_r0{};
uint8_t alu_u8_r1{};

std::array<uint16_t, 8> alu_u16_reg{};
std::array<uint16_t, 15> alu_u16_reg{};

uint64_t alu_u64_r0{};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,13 @@ std::vector<Row> AvmTraceBuilder::finalize()
dest.avm_alu_u16_r5 = FF(src.alu_u16_reg.at(5));
dest.avm_alu_u16_r6 = FF(src.alu_u16_reg.at(6));
dest.avm_alu_u16_r7 = FF(src.alu_u16_reg.at(7));
dest.avm_alu_u16_r8 = FF(src.alu_u16_reg.at(8));
dest.avm_alu_u16_r9 = FF(src.alu_u16_reg.at(9));
dest.avm_alu_u16_r10 = FF(src.alu_u16_reg.at(10));
dest.avm_alu_u16_r11 = FF(src.alu_u16_reg.at(11));
dest.avm_alu_u16_r12 = FF(src.alu_u16_reg.at(12));
dest.avm_alu_u16_r13 = FF(src.alu_u16_reg.at(13));
dest.avm_alu_u16_r14 = FF(src.alu_u16_reg.at(14));

dest.avm_alu_u64_r0 = FF(src.alu_u64_r0);
dest.avm_alu_op_eq_diff_inv = FF(src.alu_op_eq_diff_inv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ template <typename FF> struct AvmFullRow {
FF avm_alu_u128_tag{};
FF avm_alu_u16_r0{};
FF avm_alu_u16_r1{};
FF avm_alu_u16_r10{};
FF avm_alu_u16_r11{};
FF avm_alu_u16_r12{};
FF avm_alu_u16_r13{};
FF avm_alu_u16_r14{};
FF avm_alu_u16_r2{};
FF avm_alu_u16_r3{};
FF avm_alu_u16_r4{};
FF avm_alu_u16_r5{};
FF avm_alu_u16_r6{};
FF avm_alu_u16_r7{};
FF avm_alu_u16_r8{};
FF avm_alu_u16_r9{};
FF avm_alu_u16_tag{};
FF avm_alu_u32_tag{};
FF avm_alu_u64_r0{};
Expand Down Expand Up @@ -196,8 +203,8 @@ class AvmCircuitBuilder {
using Polynomial = Flavor::Polynomial;
using ProverPolynomials = Flavor::ProverPolynomials;

static constexpr size_t num_fixed_columns = 152;
static constexpr size_t num_polys = 133;
static constexpr size_t num_fixed_columns = 159;
static constexpr size_t num_polys = 140;
std::vector<Row> rows;

void set_trace(std::vector<Row>&& trace) { rows = std::move(trace); }
Expand Down Expand Up @@ -233,12 +240,19 @@ class AvmCircuitBuilder {
polys.avm_alu_u128_tag[i] = rows[i].avm_alu_u128_tag;
polys.avm_alu_u16_r0[i] = rows[i].avm_alu_u16_r0;
polys.avm_alu_u16_r1[i] = rows[i].avm_alu_u16_r1;
polys.avm_alu_u16_r10[i] = rows[i].avm_alu_u16_r10;
polys.avm_alu_u16_r11[i] = rows[i].avm_alu_u16_r11;
polys.avm_alu_u16_r12[i] = rows[i].avm_alu_u16_r12;
polys.avm_alu_u16_r13[i] = rows[i].avm_alu_u16_r13;
polys.avm_alu_u16_r14[i] = rows[i].avm_alu_u16_r14;
polys.avm_alu_u16_r2[i] = rows[i].avm_alu_u16_r2;
polys.avm_alu_u16_r3[i] = rows[i].avm_alu_u16_r3;
polys.avm_alu_u16_r4[i] = rows[i].avm_alu_u16_r4;
polys.avm_alu_u16_r5[i] = rows[i].avm_alu_u16_r5;
polys.avm_alu_u16_r6[i] = rows[i].avm_alu_u16_r6;
polys.avm_alu_u16_r7[i] = rows[i].avm_alu_u16_r7;
polys.avm_alu_u16_r8[i] = rows[i].avm_alu_u16_r8;
polys.avm_alu_u16_r9[i] = rows[i].avm_alu_u16_r9;
polys.avm_alu_u16_tag[i] = rows[i].avm_alu_u16_tag;
polys.avm_alu_u32_tag[i] = rows[i].avm_alu_u32_tag;
polys.avm_alu_u64_r0[i] = rows[i].avm_alu_u64_r0;
Expand Down
67 changes: 65 additions & 2 deletions barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class AvmFlavor {
using RelationSeparator = FF;

static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2;
static constexpr size_t NUM_WITNESS_ENTITIES = 131;
static constexpr size_t NUM_WITNESS_ENTITIES = 138;
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 = 152;
static constexpr size_t NUM_ALL_ENTITIES = 159;

using Relations = std::tuple<Avm_vm::avm_alu<FF>,
Avm_vm::avm_binary<FF>,
Expand Down Expand Up @@ -115,12 +115,19 @@ class AvmFlavor {
avm_alu_u128_tag,
avm_alu_u16_r0,
avm_alu_u16_r1,
avm_alu_u16_r10,
avm_alu_u16_r11,
avm_alu_u16_r12,
avm_alu_u16_r13,
avm_alu_u16_r14,
avm_alu_u16_r2,
avm_alu_u16_r3,
avm_alu_u16_r4,
avm_alu_u16_r5,
avm_alu_u16_r6,
avm_alu_u16_r7,
avm_alu_u16_r8,
avm_alu_u16_r9,
avm_alu_u16_tag,
avm_alu_u32_tag,
avm_alu_u64_r0,
Expand Down Expand Up @@ -249,12 +256,19 @@ class AvmFlavor {
avm_alu_u128_tag,
avm_alu_u16_r0,
avm_alu_u16_r1,
avm_alu_u16_r10,
avm_alu_u16_r11,
avm_alu_u16_r12,
avm_alu_u16_r13,
avm_alu_u16_r14,
avm_alu_u16_r2,
avm_alu_u16_r3,
avm_alu_u16_r4,
avm_alu_u16_r5,
avm_alu_u16_r6,
avm_alu_u16_r7,
avm_alu_u16_r8,
avm_alu_u16_r9,
avm_alu_u16_tag,
avm_alu_u32_tag,
avm_alu_u64_r0,
Expand Down Expand Up @@ -389,12 +403,19 @@ class AvmFlavor {
avm_alu_u128_tag,
avm_alu_u16_r0,
avm_alu_u16_r1,
avm_alu_u16_r10,
avm_alu_u16_r11,
avm_alu_u16_r12,
avm_alu_u16_r13,
avm_alu_u16_r14,
avm_alu_u16_r2,
avm_alu_u16_r3,
avm_alu_u16_r4,
avm_alu_u16_r5,
avm_alu_u16_r6,
avm_alu_u16_r7,
avm_alu_u16_r8,
avm_alu_u16_r9,
avm_alu_u16_tag,
avm_alu_u32_tag,
avm_alu_u64_r0,
Expand Down Expand Up @@ -544,12 +565,19 @@ class AvmFlavor {
avm_alu_u128_tag,
avm_alu_u16_r0,
avm_alu_u16_r1,
avm_alu_u16_r10,
avm_alu_u16_r11,
avm_alu_u16_r12,
avm_alu_u16_r13,
avm_alu_u16_r14,
avm_alu_u16_r2,
avm_alu_u16_r3,
avm_alu_u16_r4,
avm_alu_u16_r5,
avm_alu_u16_r6,
avm_alu_u16_r7,
avm_alu_u16_r8,
avm_alu_u16_r9,
avm_alu_u16_tag,
avm_alu_u32_tag,
avm_alu_u64_r0,
Expand Down Expand Up @@ -699,12 +727,19 @@ class AvmFlavor {
avm_alu_u128_tag,
avm_alu_u16_r0,
avm_alu_u16_r1,
avm_alu_u16_r10,
avm_alu_u16_r11,
avm_alu_u16_r12,
avm_alu_u16_r13,
avm_alu_u16_r14,
avm_alu_u16_r2,
avm_alu_u16_r3,
avm_alu_u16_r4,
avm_alu_u16_r5,
avm_alu_u16_r6,
avm_alu_u16_r7,
avm_alu_u16_r8,
avm_alu_u16_r9,
avm_alu_u16_tag,
avm_alu_u32_tag,
avm_alu_u64_r0,
Expand Down Expand Up @@ -956,12 +991,19 @@ class AvmFlavor {
Base::avm_alu_u128_tag = "AVM_ALU_U128_TAG";
Base::avm_alu_u16_r0 = "AVM_ALU_U16_R0";
Base::avm_alu_u16_r1 = "AVM_ALU_U16_R1";
Base::avm_alu_u16_r10 = "AVM_ALU_U16_R10";
Base::avm_alu_u16_r11 = "AVM_ALU_U16_R11";
Base::avm_alu_u16_r12 = "AVM_ALU_U16_R12";
Base::avm_alu_u16_r13 = "AVM_ALU_U16_R13";
Base::avm_alu_u16_r14 = "AVM_ALU_U16_R14";
Base::avm_alu_u16_r2 = "AVM_ALU_U16_R2";
Base::avm_alu_u16_r3 = "AVM_ALU_U16_R3";
Base::avm_alu_u16_r4 = "AVM_ALU_U16_R4";
Base::avm_alu_u16_r5 = "AVM_ALU_U16_R5";
Base::avm_alu_u16_r6 = "AVM_ALU_U16_R6";
Base::avm_alu_u16_r7 = "AVM_ALU_U16_R7";
Base::avm_alu_u16_r8 = "AVM_ALU_U16_R8";
Base::avm_alu_u16_r9 = "AVM_ALU_U16_R9";
Base::avm_alu_u16_tag = "AVM_ALU_U16_TAG";
Base::avm_alu_u32_tag = "AVM_ALU_U32_TAG";
Base::avm_alu_u64_r0 = "AVM_ALU_U64_R0";
Expand Down Expand Up @@ -1106,12 +1148,19 @@ class AvmFlavor {
Commitment avm_alu_u128_tag;
Commitment avm_alu_u16_r0;
Commitment avm_alu_u16_r1;
Commitment avm_alu_u16_r10;
Commitment avm_alu_u16_r11;
Commitment avm_alu_u16_r12;
Commitment avm_alu_u16_r13;
Commitment avm_alu_u16_r14;
Commitment avm_alu_u16_r2;
Commitment avm_alu_u16_r3;
Commitment avm_alu_u16_r4;
Commitment avm_alu_u16_r5;
Commitment avm_alu_u16_r6;
Commitment avm_alu_u16_r7;
Commitment avm_alu_u16_r8;
Commitment avm_alu_u16_r9;
Commitment avm_alu_u16_tag;
Commitment avm_alu_u32_tag;
Commitment avm_alu_u64_r0;
Expand Down Expand Up @@ -1256,12 +1305,19 @@ class AvmFlavor {
avm_alu_u128_tag = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r0 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r1 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r10 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r11 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r12 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r13 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r14 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r2 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r3 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r4 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r5 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r6 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r7 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r8 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_r9 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u16_tag = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u32_tag = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
avm_alu_u64_r0 = deserialize_from_buffer<Commitment>(Transcript::proof_data, num_frs_read);
Expand Down Expand Up @@ -1411,12 +1467,19 @@ class AvmFlavor {
serialize_to_buffer<Commitment>(avm_alu_u128_tag, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r0, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r1, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r10, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r11, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r12, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r13, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r14, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r2, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r3, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r4, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r5, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r6, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r7, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r8, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_r9, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u16_tag, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u32_tag, Transcript::proof_data);
serialize_to_buffer<Commitment>(avm_alu_u64_r0, Transcript::proof_data);
Expand Down
Loading
Loading