diff --git a/barretenberg/cpp/pil/vm2/bitwise.pil b/barretenberg/cpp/pil/vm2/bitwise.pil new file mode 100644 index 000000000000..f943121870d3 --- /dev/null +++ b/barretenberg/cpp/pil/vm2/bitwise.pil @@ -0,0 +1,135 @@ +namespace bitwise; + +// Trace example for a AND b == c of type u32 +// a = 0x52488425 +// b = 0xC684486C (We omit acc_ib and ic_byte as it follows the very same behavior as for a and c) +// c = 0x42000024 +// +// ctr sel start last acc_ia acc_ic ia_byte ic_byte +// 4 1 1 0 0x52488425 0x42000024 0x25 0x24 +// 3 1 0 0 0x524884 0x420000 0x84 0x00 +// 2 1 0 0 0x5248 0x4200 0x48 0x00 +// 1 1 0 1 0x52 0x42 0x52 0x42 + +// Selector for Bitwise Operation +pol commit sel; +sel * (1 - sel) = 0; + +// No relations will be checked if this identity is satisfied. +#[skippable_if] +sel + last = 0; // They are both boolean so it corresponds to sel == 0 AND last == 0. + +pol commit start; // Identifies when we want to capture the output to the main trace. + // No need to constrain start to be a boolean, we only need it to select + // the row to pass values with execution trace. + +// To support dynamically sized memory operands we use a counter against a lookup +// This decrementing counter goes from [TAG_LEN, 0] where TAG_LEN is the number of bytes in the +// corresponding integer. i.e. TAG_LEN is between 1 (U1/U8) and 16 (U128). +// Consistency can be achieved with a lookup table between the tag and precomputed.integral_tag_length +pol commit ctr; + +// last is a boolean which serves to mark the end of the computation (end of latch) +pol commit last; +last * (1 - last) = 0; + +// This is the tag {1,2,3,4,5,6} (restricted to not be a field) +// Operations over FF are not supported, it is assumed this exclusion is handled +// outside of this subtrace. +// Constraints come from equiv to main_trace +pol commit tag; + +// Byte recomposition column, the value in these columns are part of the equivalence +// check to main wherever Start is set to 1. +pol commit acc_ia; +pol commit acc_ib; +pol commit acc_ic; + +// Little Endian bitwise decomposition of accumulators (which are processed top-down), +// constrained to be U8 given by the lookup to the byte_lookup +pol commit ia_byte; +pol commit ib_byte; +pol commit ic_byte; + +// Selectors for bitwise operations, correctness checked by permutation to the main trace. +// Op Id is restricted to be the same during the same computation (i.e. between Starts) +pol commit op_id; + +#[BITW_OP_ID_REL] +(op_id' - op_id) * (1 - last) = 0; + +#[BITW_CTR_DECREMENT] +// Note: sel factor is required for an empty row to satisfy this relation +sel * (ctr' - ctr + 1) * (1 - last) = 0; + +// sel is set to 1 if and only if ctr != 0. (and sel == 0 <==> ctr == 0) +// sel is a boolean that is set to 1 if ctr != 0. +// This is checked by following relation and utilising inverse of ctr: ctr_inv +pol commit ctr_inv; + +#[BITW_SEL_CTR_NON_ZERO] +ctr * ((1 - sel) * (1 - ctr_inv) + ctr_inv) - sel = 0; + +// Similarly, we prove that last == 1 <==> ctr - 1 == 0 <==> ctr == 1 +// Note: sel factor is required for an empty row to satisfy this relation +pol commit ctr_min_one_inv; +#[BITW_LAST_FOR_CTR_ONE] +sel * ((ctr - 1) * (last * (1 - ctr_min_one_inv) + ctr_min_one_inv) + last - 1) = 0; + +// Forces accumulator to initialize with ia_byte, ib_byte, and ic_byte +#[BITW_INIT_A] +last * (acc_ia - ia_byte) = 0; +#[BITW_INIT_B] +last * (acc_ib - ib_byte) = 0; +#[BITW_INIT_C] +last * (acc_ic - ic_byte) = 0; + +#[BITW_ACC_REL_A] +(acc_ia - ia_byte - 256 * acc_ia') * (1 - last) = 0; +#[BITW_ACC_REL_B] +(acc_ib - ib_byte - 256 * acc_ib') * (1 - last) = 0; +#[BITW_ACC_REL_C] +(acc_ic - ic_byte - 256 * acc_ic') * (1 - last) = 0; + +#[LOOKUP_BITW_BYTE_LENGTHS] +start {tag, ctr} +in +precomputed.sel_integral_tag {precomputed.clk, precomputed.integral_tag_length}; + +#[LOOKUP_BITW_BYTE_OPERATIONS] +sel {op_id, ia_byte, ib_byte, ic_byte} +in +precomputed.sel_bitwise {precomputed.bitwise_op_id, precomputed.bitwise_input_a, precomputed.bitwise_input_b, precomputed.bitwise_output}; + +// TODOs: See two following paragraphs + +// ################################################ +// Alternative implementation as potential speed-up +// ################################################ +// +// In vm1, we had an approach which requires one extra row per bitwise operation but +// had 2 less columns and #[BITW_CTR_DECREMENT] would have degree 0 and the degree 4 relation +// #[BITW_LAST_FOR_CTR_ONE] is not present. +// The main difference is that we decrement ctr down to zero (extra line) and impose an initialization +// condition for acc_ia, acc_ib, acc_ic to be zero on this last row. +// Column last can be removed and sel is used instead of (1 - last). +// Note that sel == 0 on last row of each operation, but the skippable condition +// remains valid as the last row will be empty with our witness generator. +// +// It might be worth to measure the difference among both approaches. + + +// ################################################ +// Recycling of bitwise operations of prefixes +// ################################################ +// +// Observation: If two inputs are prefixes of other inputs which are already present in the +// trace, then we could retrieve the result as a truncated trace of the larger. +// +// For instance, re-using example at the top, we consider the U16 and computation over +// a = 0x5248 +// b = 0xC684 +// c = 0x4200 +// Then, we should activate the start selector where ctr == 2, and the following rows +// represent a valid trace for this computation. +// It is not clear if this would lead to some speed-up in practice. diff --git a/barretenberg/cpp/pil/vm2/execution.pil b/barretenberg/cpp/pil/vm2/execution.pil index 348bee40a1d5..62294de8ecc6 100644 --- a/barretenberg/cpp/pil/vm2/execution.pil +++ b/barretenberg/cpp/pil/vm2/execution.pil @@ -5,6 +5,7 @@ include "bc_hashing.pil"; include "bc_retrieval.pil"; include "instr_fetching.pil"; include "range_check.pil"; +include "bitwise.pil"; include "precomputed.pil"; include "sha256.pil"; diff --git a/barretenberg/cpp/pil/vm2/precomputed.pil b/barretenberg/cpp/pil/vm2/precomputed.pil index 5f9a3c17d24f..ba56ba45df29 100644 --- a/barretenberg/cpp/pil/vm2/precomputed.pil +++ b/barretenberg/cpp/pil/vm2/precomputed.pil @@ -37,4 +37,14 @@ pol constant sha256_compression_round_constant; // 3 -> 111 // You get it. It can be extended up to 254 bits if needed. pol constant sel_unary; -pol constant as_unary; \ No newline at end of file +pol constant as_unary; + +// A mapping between a non-FF MemoryTag value and their respective byte lengths: +// {U1: 1, U8: 1, U16: 2, ... , U128: 16} +// The enum values of MemoryTag are present in column clk. +pol constant sel_integral_tag; // Toggle row with clk == U1,U8,U16,...,U128 +pol constant integral_tag_length; // Columns for the byte length 1,1,2,...,16; + +// Remark: A potential optimization may consist in using sel_bitwise instead of sel_integral_mem_tag. +// However, it would extend this lookup table with pairs such as (0,0), (7,0), (8,0) which is +// not without any danger. \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp b/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp index 0e31cfa833c5..faf646505f7e 100644 --- a/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp @@ -188,7 +188,7 @@ template class Relation : public RelationImpl { NUM_KEYS - 1>; using SumcheckTupleOfUnivariatesOverSubrelations = TupleOfUnivariates; - // The containter constructor for sumcheck univariates corresponding to each subrelation in ZK Flavor's relations + // The container constructor for sumcheck univariates corresponding to each subrelation in ZK Flavor's relations using ZKSumcheckTupleOfUnivariatesOverSubrelations = TupleOfUnivariates()>; diff --git a/barretenberg/cpp/src/barretenberg/vm2/common/constants.hpp b/barretenberg/cpp/src/barretenberg/vm2/common/constants.hpp index c1d1b56bfac6..8e36f8cf4e6a 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/common/constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/common/constants.hpp @@ -6,4 +6,11 @@ namespace bb::avm2 { constexpr uint32_t CIRCUIT_SUBGROUP_SIZE = 1 << 21; +// Also used for op_id in the circuit trace +enum class BitwiseOperation : uint8_t { + AND = 0, + OR = 1, + XOR = 2, +}; + } // namespace bb::avm2 \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/common/memory_types.cpp b/barretenberg/cpp/src/barretenberg/vm2/common/memory_types.cpp new file mode 100644 index 000000000000..ddca3f725f72 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/common/memory_types.cpp @@ -0,0 +1,27 @@ +#include "barretenberg/vm2/common/memory_types.hpp" + +namespace bb::avm2 { + +uint8_t integral_tag_length(MemoryTag tag) +{ + switch (tag) { + case MemoryTag::U1: + case MemoryTag::U8: + return 1; + case MemoryTag::U16: + return 2; + case MemoryTag::U32: + return 4; + case MemoryTag::U64: + return 8; + case MemoryTag::U128: + return 16; + case MemoryTag::FF: + throw std::runtime_error("FF is not an integral tag"); + } + + assert(false && "This should not happen"); + return 0; // Should never happen. To please the compiler. +} + +} // namespace bb::avm2 \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/common/memory_types.hpp b/barretenberg/cpp/src/barretenberg/vm2/common/memory_types.hpp index 3b99ddef1357..d3ba454fbb06 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/common/memory_types.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/common/memory_types.hpp @@ -20,4 +20,6 @@ using MemoryAddress = uint32_t; using MemoryValue = FF; constexpr auto MemoryAddressTag = MemoryTag::U32; +uint8_t integral_tag_length(MemoryTag tag); + } // namespace bb::avm2 \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/bitwise.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/bitwise.test.cpp new file mode 100644 index 000000000000..61b5b878eeca --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/bitwise.test.cpp @@ -0,0 +1,285 @@ +#include +#include + +#include + +#include "barretenberg/vm2/common/constants.hpp" +#include "barretenberg/vm2/common/memory_types.hpp" +#include "barretenberg/vm2/constraining/testing/check_relation.hpp" +#include "barretenberg/vm2/generated/flavor_settings.hpp" +#include "barretenberg/vm2/generated/relations/bitwise.hpp" +#include "barretenberg/vm2/testing/macros.hpp" +#include "barretenberg/vm2/tracegen/bitwise_trace.hpp" +#include "barretenberg/vm2/tracegen/test_trace_container.hpp" + +namespace bb::avm2::constraining { +namespace { + +using tracegen::BitwiseTraceBuilder; +using tracegen::TestTraceContainer; +using FF = AvmFlavorSettings::FF; +using C = Column; +using bitwise = bb::avm2::bitwise; + +TEST(BitwiseConstrainingTest, EmptyRow) +{ + TestTraceContainer trace({ + { { C::precomputed_first_row, 1 } }, + }); + + check_relation(trace); +} + +// Testing a positive AND operation for each integral type (U1, U8, ... U128) +TEST(BitwiseConstrainingTest, AndWithTracegen) +{ + TestTraceContainer trace; + BitwiseTraceBuilder builder; + + builder.process( + { + { .operation = BitwiseOperation::AND, .tag = MemoryTag::U1, .a = 1, .b = 1, .res = 1 }, + { .operation = BitwiseOperation::AND, .tag = MemoryTag::U8, .a = 85, .b = 175, .res = 5 }, + { .operation = BitwiseOperation::AND, .tag = MemoryTag::U16, .a = 5323, .b = 321, .res = 65 }, + { .operation = BitwiseOperation::AND, .tag = MemoryTag::U32, .a = 13793, .b = 10590617, .res = 4481 }, + { .operation = BitwiseOperation::AND, + .tag = MemoryTag::U64, + .a = 0x7bff744e3cdf79LLU, + .b = 0x14ccccccccb6LLU, + .res = 0x14444c0ccc30LLU }, + { .operation = BitwiseOperation::AND, + .tag = MemoryTag::U128, + .a = uint128_t{ 0xb900000000000001 } << 64, + .b = (uint128_t{ 0x1006021301080000 } << 64) + uint128_t{ 0x000000000000001080876844827 }, + .res = uint128_t{ 0x1000000000000000 } << 64 }, + }, + trace); + + EXPECT_EQ(trace.get_num_rows(), 33); // 33 = 1 + 1 + 1 + 2 + 4 + 8 + 16 (extra_shift_row U1 U8 U16 U32 U64 U128) + check_relation(trace); +} + +// Testing a positive OR operation for each integral type (U1, U8, ... U128) +TEST(BitwiseConstrainingTest, OrWithTracegen) +{ + TestTraceContainer trace; + BitwiseTraceBuilder builder; + + builder.process( + { + { .operation = BitwiseOperation::OR, .tag = MemoryTag::U1, .a = 1, .b = 0, .res = 1 }, + { .operation = BitwiseOperation::OR, .tag = MemoryTag::U8, .a = 128, .b = 127, .res = 255 }, + { .operation = BitwiseOperation::OR, .tag = MemoryTag::U16, .a = 5323, .b = 321, .res = 5579 }, + { .operation = BitwiseOperation::OR, .tag = MemoryTag::U32, .a = 13793, .b = 10590617, .res = 10599929 }, + { .operation = BitwiseOperation::OR, + .tag = MemoryTag::U64, + .a = 0x7bff744e3cdf79LLU, + .b = 0x14ccccccccb6LLU, + .res = 0x7bfffccefcdfffLLU }, + { .operation = BitwiseOperation::OR, + .tag = MemoryTag::U128, + .a = uint128_t{ 0xb900000000000000 } << 64, + .b = (uint128_t{ 0x1006021301080000 } << 64) + uint128_t{ 0x000000000000001080876844827 }, + .res = (uint128_t{ 0xb906021301080000 } << 64) + uint128_t{ 0x0001080876844827 } }, + }, + trace); + + EXPECT_EQ(trace.get_num_rows(), 33); // 33 = 1 + 1 + 1 + 2 + 4 + 8 + 16 (extra_shift_row U1 U8 U16 U32 U64 U128) + check_relation(trace); +} + +// Testing a positive XOR operation for each integral type (U1, U8, ... U128) +TEST(BitwiseConstrainingTest, XorWithTracegen) +{ + TestTraceContainer trace; + BitwiseTraceBuilder builder; + + builder.process( + { + { .operation = BitwiseOperation::XOR, .tag = MemoryTag::U1, .a = 1, .b = 1, .res = 0 }, + { .operation = BitwiseOperation::XOR, .tag = MemoryTag::U8, .a = 85, .b = 175, .res = 250 }, + { .operation = BitwiseOperation::XOR, .tag = MemoryTag::U16, .a = 5323, .b = 321, .res = 5514 }, + { .operation = BitwiseOperation::XOR, .tag = MemoryTag::U32, .a = 13793, .b = 10590617, .res = 10595448 }, + { .operation = BitwiseOperation::XOR, + .tag = MemoryTag::U64, + .a = 0x7bff744e3cdf79LLU, + .b = 0x14ccccccccb6LLU, + .res = 0x7bebb882f013cfLLU }, + { + .operation = BitwiseOperation::XOR, + .tag = MemoryTag::U128, + .a = uint128_t{ 0xb900000000000001 } << 64, + .b = (uint128_t{ 0x1006021301080000 } << 64) + uint128_t{ 0x000000000000001080876844827 }, + .res = (uint128_t{ 0xa906021301080001 } << 64) + uint128_t{ 0x0001080876844827 }, + }, + }, + trace); + + EXPECT_EQ(trace.get_num_rows(), 33); // 33 = 1 + 1 + 1 + 2 + 4 + 8 + 16 (extra_shift_row U1 U8 U16 U32 U64 U128) + check_relation(trace); +} + +TEST(BitwiseConstrainingTest, MixedOperationsWithTracegen) +{ + TestTraceContainer trace; + BitwiseTraceBuilder builder; + + builder.process( + { + { .operation = BitwiseOperation::OR, .tag = MemoryTag::U1, .a = 1, .b = 0, .res = 1 }, + { .operation = BitwiseOperation::AND, .tag = MemoryTag::U32, .a = 13793, .b = 10590617, .res = 4481 }, + { .operation = BitwiseOperation::XOR, .tag = MemoryTag::U16, .a = 5323, .b = 321, .res = 5514 }, + { .operation = BitwiseOperation::XOR, .tag = MemoryTag::U32, .a = 13793, .b = 10590617, .res = 10595448 }, + { .operation = BitwiseOperation::AND, .tag = MemoryTag::U8, .a = 85, .b = 175, .res = 5 }, + { .operation = BitwiseOperation::AND, .tag = MemoryTag::U8, .a = 85, .b = 175, .res = 5 }, + }, + trace); + + EXPECT_EQ(trace.get_num_rows(), 14); // 14 = 1 + 3 * 1 + 1 * 2 + 2 * 4 (extra_shift_row + 2U1 + 1U8 + 1U16 + 2U32) + check_relation(trace); +} + +TEST(BitwiseConstrainingTest, NegativeWrongInit) +{ + TestTraceContainer trace = TestTraceContainer::from_rows({ + { + .bitwise_acc_ia = 25, + .bitwise_acc_ib = 25, + .bitwise_acc_ic = 25, + .bitwise_ia_byte = 24, + .bitwise_ib_byte = 27, + .bitwise_ic_byte = 28, + .bitwise_last = 1, + }, + }); + + EXPECT_THROW_WITH_MESSAGE(check_relation(trace, bitwise::SR_BITW_INIT_A), "BITW_INIT_A"); + EXPECT_THROW_WITH_MESSAGE(check_relation(trace, bitwise::SR_BITW_INIT_B), "BITW_INIT_B"); + EXPECT_THROW_WITH_MESSAGE(check_relation(trace, bitwise::SR_BITW_INIT_C), "BITW_INIT_C"); +} + +TEST(BitwiseConstrainingTest, NegativeTruncateCtr) +{ + TestTraceContainer trace = TestTraceContainer::from_rows({ + { + .bitwise_ctr = 4, + .bitwise_sel = 1, + }, + { + .bitwise_ctr = 3, + .bitwise_sel = 1, + }, + { + .bitwise_ctr = 2, + .bitwise_sel = 1, + }, + }); + + EXPECT_THROW_WITH_MESSAGE(check_relation(trace, bitwise::SR_BITW_CTR_DECREMENT), "BITW_CTR_DECREMENT"); +} + +TEST(BitwiseConstrainingTest, NegativeGapCtr) +{ + TestTraceContainer trace = TestTraceContainer::from_rows({ + { + .bitwise_ctr = 4, + .bitwise_sel = 1, + }, + { + .bitwise_ctr = 2, + .bitwise_last = 1, + .bitwise_sel = 1, + }, + }); + + EXPECT_THROW_WITH_MESSAGE(check_relation(trace, bitwise::SR_BITW_CTR_DECREMENT), "BITW_CTR_DECREMENT"); +} + +TEST(BitwiseConstrainingTest, NegativeLastSetBeforeEnd) +{ + TestTraceContainer trace = TestTraceContainer::from_rows({ + { + .bitwise_ctr = 8, + .bitwise_sel = 1, + }, + { + .bitwise_ctr = 7, + .bitwise_sel = 1, + + }, + { + .bitwise_ctr = 6, + .bitwise_last = 1, + .bitwise_sel = 1, + }, + }); + + EXPECT_THROW_WITH_MESSAGE(check_relation(trace, bitwise::SR_BITW_LAST_FOR_CTR_ONE), + "BITW_LAST_FOR_CTR_ONE"); +} + +TEST(BitwiseConstrainingTest, NegativeDeactivateRow) +{ + TestTraceContainer trace = TestTraceContainer::from_rows({ + { + .bitwise_ctr = 8, + .bitwise_sel = 1, + }, + { + .bitwise_ctr = 7, + .bitwise_sel = 0, + }, + { + .bitwise_ctr = 6, + .bitwise_sel = 1, + }, + }); + + EXPECT_THROW_WITH_MESSAGE(check_relation(trace, bitwise::SR_BITW_SEL_CTR_NON_ZERO), + "BITW_SEL_CTR_NON_ZERO"); +} + +TEST(BitwiseConstrainingTest, NegativeChangeOpIDBeforeEnd) +{ + TestTraceContainer trace = TestTraceContainer::from_rows({ + { + .bitwise_op_id = static_cast(BitwiseOperation::XOR), + }, + { + .bitwise_op_id = static_cast(BitwiseOperation::AND), + }, + { + .bitwise_last = 1, + .bitwise_op_id = static_cast(BitwiseOperation::XOR), + }, + }); + + EXPECT_THROW_WITH_MESSAGE(check_relation(trace, bitwise::SR_BITW_OP_ID_REL), "BITW_OP_ID_REL"); +} + +TEST(BitwiseConstrainingTest, NegativeWrongAccumulation) +{ + TestTraceContainer trace = TestTraceContainer::from_rows({ + { + .bitwise_acc_ia = 0xaa1f, // Correct: 0xaa11 + .bitwise_acc_ib = 0xbb2f, // Correct: 0xbb22 + .bitwise_acc_ic = 0xcc3f, // Correct: 0xcc33 + .bitwise_ia_byte = 0x11, + .bitwise_ib_byte = 0x22, + .bitwise_ic_byte = 0x33, + }, + { + .bitwise_acc_ia = 0xaa, + .bitwise_acc_ib = 0xbb, + .bitwise_acc_ic = 0xcc, + .bitwise_last = 1, + }, + }); + + EXPECT_THROW_WITH_MESSAGE(check_relation(trace, bitwise::SR_BITW_ACC_REL_A), "BITW_ACC_REL_A"); + EXPECT_THROW_WITH_MESSAGE(check_relation(trace, bitwise::SR_BITW_ACC_REL_B), "BITW_ACC_REL_B"); + EXPECT_THROW_WITH_MESSAGE(check_relation(trace, bitwise::SR_BITW_ACC_REL_C), "BITW_ACC_REL_C"); +} + +} // namespace +} // namespace bb::avm2::constraining \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp index f8e26fc14eeb..29cd8798aaae 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp @@ -9,17 +9,17 @@ namespace bb::avm2 { // The entities that will be used in the flavor. // clang-format off -#define AVM2_PRECOMPUTED_ENTITIES precomputed_as_unary, precomputed_bitwise_input_a, precomputed_bitwise_input_b, precomputed_bitwise_op_id, precomputed_bitwise_output, precomputed_clk, precomputed_first_row, precomputed_power_of_2, precomputed_sel_bitwise, precomputed_sel_range_16, precomputed_sel_range_8, precomputed_sel_sha256_compression, precomputed_sel_unary, precomputed_sha256_compression_round_constant -#define AVM2_WIRE_ENTITIES execution_input, alu_dst_addr, alu_ia, alu_ia_addr, alu_ib, alu_ib_addr, alu_ic, alu_op, alu_sel_op_add, bc_decomposition_bytes, bc_decomposition_bytes_pc_plus_1, bc_decomposition_bytes_pc_plus_10, bc_decomposition_bytes_pc_plus_11, bc_decomposition_bytes_pc_plus_12, bc_decomposition_bytes_pc_plus_13, bc_decomposition_bytes_pc_plus_14, bc_decomposition_bytes_pc_plus_15, bc_decomposition_bytes_pc_plus_16, bc_decomposition_bytes_pc_plus_17, bc_decomposition_bytes_pc_plus_18, bc_decomposition_bytes_pc_plus_19, bc_decomposition_bytes_pc_plus_2, bc_decomposition_bytes_pc_plus_20, bc_decomposition_bytes_pc_plus_21, bc_decomposition_bytes_pc_plus_22, bc_decomposition_bytes_pc_plus_23, bc_decomposition_bytes_pc_plus_24, bc_decomposition_bytes_pc_plus_25, bc_decomposition_bytes_pc_plus_26, bc_decomposition_bytes_pc_plus_27, bc_decomposition_bytes_pc_plus_28, bc_decomposition_bytes_pc_plus_29, bc_decomposition_bytes_pc_plus_3, bc_decomposition_bytes_pc_plus_30, bc_decomposition_bytes_pc_plus_31, bc_decomposition_bytes_pc_plus_32, bc_decomposition_bytes_pc_plus_33, bc_decomposition_bytes_pc_plus_34, bc_decomposition_bytes_pc_plus_35, bc_decomposition_bytes_pc_plus_4, bc_decomposition_bytes_pc_plus_5, bc_decomposition_bytes_pc_plus_6, bc_decomposition_bytes_pc_plus_7, bc_decomposition_bytes_pc_plus_8, bc_decomposition_bytes_pc_plus_9, bc_decomposition_bytes_remaining, bc_decomposition_bytes_to_read, bc_decomposition_bytes_to_read_unary, bc_decomposition_id, bc_decomposition_last_of_contract, bc_decomposition_pc, bc_decomposition_sel, bc_decomposition_sel_overflow_correction_needed, bc_decomposition_sel_pc_plus_0, bc_decomposition_sel_pc_plus_1, bc_decomposition_sel_pc_plus_10, bc_decomposition_sel_pc_plus_11, bc_decomposition_sel_pc_plus_12, bc_decomposition_sel_pc_plus_13, bc_decomposition_sel_pc_plus_14, bc_decomposition_sel_pc_plus_15, bc_decomposition_sel_pc_plus_16, bc_decomposition_sel_pc_plus_17, bc_decomposition_sel_pc_plus_18, bc_decomposition_sel_pc_plus_19, bc_decomposition_sel_pc_plus_2, bc_decomposition_sel_pc_plus_20, bc_decomposition_sel_pc_plus_21, bc_decomposition_sel_pc_plus_22, bc_decomposition_sel_pc_plus_23, bc_decomposition_sel_pc_plus_24, bc_decomposition_sel_pc_plus_25, bc_decomposition_sel_pc_plus_26, bc_decomposition_sel_pc_plus_27, bc_decomposition_sel_pc_plus_28, bc_decomposition_sel_pc_plus_29, bc_decomposition_sel_pc_plus_3, bc_decomposition_sel_pc_plus_30, bc_decomposition_sel_pc_plus_31, bc_decomposition_sel_pc_plus_32, bc_decomposition_sel_pc_plus_33, bc_decomposition_sel_pc_plus_34, bc_decomposition_sel_pc_plus_35, bc_decomposition_sel_pc_plus_4, bc_decomposition_sel_pc_plus_5, bc_decomposition_sel_pc_plus_6, bc_decomposition_sel_pc_plus_7, bc_decomposition_sel_pc_plus_8, bc_decomposition_sel_pc_plus_9, bc_retrieval_address, bc_retrieval_artifact_hash, bc_retrieval_bytecode_id, bc_retrieval_class_id, bc_retrieval_deployer_addr, bc_retrieval_err, bc_retrieval_incoming_viewing_key_x, bc_retrieval_incoming_viewing_key_y, bc_retrieval_init_hash, bc_retrieval_nullifier_key_x, bc_retrieval_nullifier_key_y, bc_retrieval_outgoing_viewing_key_x, bc_retrieval_outgoing_viewing_key_y, bc_retrieval_private_function_root, bc_retrieval_public_bytecode_commitment, bc_retrieval_salt, bc_retrieval_sel, bc_retrieval_tagging_key_x, bc_retrieval_tagging_key_y, execution_addressing_error_idx, execution_addressing_error_kind, execution_base_address_tag, execution_base_address_val, execution_bytecode_id, execution_clk, execution_ex_opcode, execution_indirect, execution_last, execution_op1, execution_op1_after_relative, execution_op2, execution_op2_after_relative, execution_op3, execution_op3_after_relative, execution_op4, execution_op4_after_relative, execution_pc, execution_rop1, execution_rop2, execution_rop3, execution_rop4, execution_sel, execution_sel_addressing_error, execution_sel_op1_is_address, execution_sel_op2_is_address, execution_sel_op3_is_address, execution_sel_op4_is_address, instr_fetching_bd0, instr_fetching_bd1, instr_fetching_bd10, instr_fetching_bd11, instr_fetching_bd12, instr_fetching_bd13, instr_fetching_bd14, instr_fetching_bd15, instr_fetching_bd16, instr_fetching_bd17, instr_fetching_bd18, instr_fetching_bd19, instr_fetching_bd2, instr_fetching_bd20, instr_fetching_bd21, instr_fetching_bd22, instr_fetching_bd23, instr_fetching_bd24, instr_fetching_bd25, instr_fetching_bd26, instr_fetching_bd27, instr_fetching_bd28, instr_fetching_bd29, instr_fetching_bd3, instr_fetching_bd30, instr_fetching_bd31, instr_fetching_bd32, instr_fetching_bd33, instr_fetching_bd34, instr_fetching_bd35, instr_fetching_bd4, instr_fetching_bd5, instr_fetching_bd6, instr_fetching_bd7, instr_fetching_bd8, instr_fetching_bd9, instr_fetching_bytecode_id, instr_fetching_ex_opcode, instr_fetching_fmt_3_op_u8, instr_fetching_indirect, instr_fetching_op1, instr_fetching_op2, instr_fetching_op3, instr_fetching_op4, instr_fetching_pc, instr_fetching_sel, range_check_dyn_diff, range_check_dyn_rng_chk_bits, range_check_dyn_rng_chk_pow_2, range_check_is_lte_u112, range_check_is_lte_u128, range_check_is_lte_u16, range_check_is_lte_u32, range_check_is_lte_u48, range_check_is_lte_u64, range_check_is_lte_u80, range_check_is_lte_u96, range_check_rng_chk_bits, range_check_sel, range_check_sel_r0_16_bit_rng_lookup, range_check_sel_r1_16_bit_rng_lookup, range_check_sel_r2_16_bit_rng_lookup, range_check_sel_r3_16_bit_rng_lookup, range_check_sel_r4_16_bit_rng_lookup, range_check_sel_r5_16_bit_rng_lookup, range_check_sel_r6_16_bit_rng_lookup, range_check_u16_r0, range_check_u16_r1, range_check_u16_r2, range_check_u16_r3, range_check_u16_r4, range_check_u16_r5, range_check_u16_r6, range_check_u16_r7, range_check_value, sha256_a, sha256_a_and_b, sha256_a_and_b_xor_a_and_c, sha256_a_and_c, sha256_a_rotr_13, sha256_a_rotr_2, sha256_a_rotr_22, sha256_a_rotr_2_xor_a_rotr_13, sha256_and_sel, sha256_b, sha256_b_and_c, sha256_c, sha256_ch, sha256_clk, sha256_computed_w_lhs, sha256_computed_w_rhs, sha256_d, sha256_dummy_zero, sha256_e, sha256_e_and_f, sha256_e_rotr_11, sha256_e_rotr_25, sha256_e_rotr_6, sha256_e_rotr_6_xor_e_rotr_11, sha256_f, sha256_g, sha256_h, sha256_helper_w0, sha256_helper_w1, sha256_helper_w10, sha256_helper_w11, sha256_helper_w12, sha256_helper_w13, sha256_helper_w14, sha256_helper_w15, sha256_helper_w2, sha256_helper_w3, sha256_helper_w4, sha256_helper_w5, sha256_helper_w6, sha256_helper_w7, sha256_helper_w8, sha256_helper_w9, sha256_init_a, sha256_init_b, sha256_init_c, sha256_init_d, sha256_init_e, sha256_init_f, sha256_init_g, sha256_init_h, sha256_input_offset, sha256_is_input_round, sha256_latch, sha256_lhs_a_13, sha256_lhs_a_2, sha256_lhs_a_22, sha256_lhs_e_11, sha256_lhs_e_25, sha256_lhs_e_6, sha256_lhs_w_10, sha256_lhs_w_17, sha256_lhs_w_18, sha256_lhs_w_19, sha256_lhs_w_3, sha256_lhs_w_7, sha256_maj, sha256_next_a_lhs, sha256_next_a_rhs, sha256_next_e_lhs, sha256_next_e_rhs, sha256_not_e, sha256_not_e_and_g, sha256_output_a_lhs, sha256_output_a_rhs, sha256_output_b_lhs, sha256_output_b_rhs, sha256_output_c_lhs, sha256_output_c_rhs, sha256_output_d_lhs, sha256_output_d_rhs, sha256_output_e_lhs, sha256_output_e_rhs, sha256_output_f_lhs, sha256_output_f_rhs, sha256_output_g_lhs, sha256_output_g_rhs, sha256_output_h_lhs, sha256_output_h_rhs, sha256_output_offset, sha256_perform_round, sha256_rhs_a_13, sha256_rhs_a_2, sha256_rhs_a_22, sha256_rhs_e_11, sha256_rhs_e_25, sha256_rhs_e_6, sha256_rhs_w_10, sha256_rhs_w_17, sha256_rhs_w_18, sha256_rhs_w_19, sha256_rhs_w_3, sha256_rhs_w_7, sha256_round_constant, sha256_round_count, sha256_rounds_remaining, sha256_rounds_remaining_inv, sha256_s_0, sha256_s_1, sha256_sel, sha256_start, sha256_state_offset, sha256_w, sha256_w_15_rotr_18, sha256_w_15_rotr_7, sha256_w_15_rotr_7_xor_w_15_rotr_18, sha256_w_15_rshift_3, sha256_w_2_rotr_17, sha256_w_2_rotr_17_xor_w_2_rotr_19, sha256_w_2_rotr_19, sha256_w_2_rshift_10, sha256_w_s_0, sha256_w_s_1, sha256_xor_sel, lookup_bytecode_to_read_unary_counts, lookup_rng_chk_pow_2_counts, lookup_rng_chk_diff_counts, lookup_rng_chk_is_r0_16_bit_counts, lookup_rng_chk_is_r1_16_bit_counts, lookup_rng_chk_is_r2_16_bit_counts, lookup_rng_chk_is_r3_16_bit_counts, lookup_rng_chk_is_r4_16_bit_counts, lookup_rng_chk_is_r5_16_bit_counts, lookup_rng_chk_is_r6_16_bit_counts, lookup_rng_chk_is_r7_16_bit_counts, lookup_sha256_round_constant_counts, lookup_dummy_precomputed_counts, lookup_dummy_dynamic_counts -#define AVM2_DERIVED_WITNESS_ENTITIES perm_dummy_dynamic_inv, lookup_bytecode_to_read_unary_inv, lookup_rng_chk_pow_2_inv, lookup_rng_chk_diff_inv, lookup_rng_chk_is_r0_16_bit_inv, lookup_rng_chk_is_r1_16_bit_inv, lookup_rng_chk_is_r2_16_bit_inv, lookup_rng_chk_is_r3_16_bit_inv, lookup_rng_chk_is_r4_16_bit_inv, lookup_rng_chk_is_r5_16_bit_inv, lookup_rng_chk_is_r6_16_bit_inv, lookup_rng_chk_is_r7_16_bit_inv, lookup_sha256_round_constant_inv, lookup_dummy_precomputed_inv, lookup_dummy_dynamic_inv -#define AVM2_SHIFTED_ENTITIES bc_decomposition_bytes_shift, bc_decomposition_bytes_pc_plus_1_shift, bc_decomposition_bytes_pc_plus_10_shift, bc_decomposition_bytes_pc_plus_11_shift, bc_decomposition_bytes_pc_plus_12_shift, bc_decomposition_bytes_pc_plus_13_shift, bc_decomposition_bytes_pc_plus_14_shift, bc_decomposition_bytes_pc_plus_15_shift, bc_decomposition_bytes_pc_plus_16_shift, bc_decomposition_bytes_pc_plus_17_shift, bc_decomposition_bytes_pc_plus_18_shift, bc_decomposition_bytes_pc_plus_19_shift, bc_decomposition_bytes_pc_plus_2_shift, bc_decomposition_bytes_pc_plus_20_shift, bc_decomposition_bytes_pc_plus_21_shift, bc_decomposition_bytes_pc_plus_22_shift, bc_decomposition_bytes_pc_plus_23_shift, bc_decomposition_bytes_pc_plus_24_shift, bc_decomposition_bytes_pc_plus_25_shift, bc_decomposition_bytes_pc_plus_26_shift, bc_decomposition_bytes_pc_plus_27_shift, bc_decomposition_bytes_pc_plus_28_shift, bc_decomposition_bytes_pc_plus_29_shift, bc_decomposition_bytes_pc_plus_3_shift, bc_decomposition_bytes_pc_plus_30_shift, bc_decomposition_bytes_pc_plus_31_shift, bc_decomposition_bytes_pc_plus_32_shift, bc_decomposition_bytes_pc_plus_33_shift, bc_decomposition_bytes_pc_plus_34_shift, bc_decomposition_bytes_pc_plus_4_shift, bc_decomposition_bytes_pc_plus_5_shift, bc_decomposition_bytes_pc_plus_6_shift, bc_decomposition_bytes_pc_plus_7_shift, bc_decomposition_bytes_pc_plus_8_shift, bc_decomposition_bytes_pc_plus_9_shift, execution_sel_shift, sha256_a_shift, sha256_b_shift, sha256_c_shift, sha256_d_shift, sha256_e_shift, sha256_f_shift, sha256_g_shift, sha256_h_shift, sha256_helper_w0_shift, sha256_helper_w1_shift, sha256_helper_w10_shift, sha256_helper_w11_shift, sha256_helper_w12_shift, sha256_helper_w13_shift, sha256_helper_w14_shift, sha256_helper_w15_shift, sha256_helper_w2_shift, sha256_helper_w3_shift, sha256_helper_w4_shift, sha256_helper_w5_shift, sha256_helper_w6_shift, sha256_helper_w7_shift, sha256_helper_w8_shift, sha256_helper_w9_shift, sha256_rounds_remaining_shift, sha256_sel_shift, sha256_start_shift -#define AVM2_TO_BE_SHIFTED(e) e.bc_decomposition_bytes, e.bc_decomposition_bytes_pc_plus_1, e.bc_decomposition_bytes_pc_plus_10, e.bc_decomposition_bytes_pc_plus_11, e.bc_decomposition_bytes_pc_plus_12, e.bc_decomposition_bytes_pc_plus_13, e.bc_decomposition_bytes_pc_plus_14, e.bc_decomposition_bytes_pc_plus_15, e.bc_decomposition_bytes_pc_plus_16, e.bc_decomposition_bytes_pc_plus_17, e.bc_decomposition_bytes_pc_plus_18, e.bc_decomposition_bytes_pc_plus_19, e.bc_decomposition_bytes_pc_plus_2, e.bc_decomposition_bytes_pc_plus_20, e.bc_decomposition_bytes_pc_plus_21, e.bc_decomposition_bytes_pc_plus_22, e.bc_decomposition_bytes_pc_plus_23, e.bc_decomposition_bytes_pc_plus_24, e.bc_decomposition_bytes_pc_plus_25, e.bc_decomposition_bytes_pc_plus_26, e.bc_decomposition_bytes_pc_plus_27, e.bc_decomposition_bytes_pc_plus_28, e.bc_decomposition_bytes_pc_plus_29, e.bc_decomposition_bytes_pc_plus_3, e.bc_decomposition_bytes_pc_plus_30, e.bc_decomposition_bytes_pc_plus_31, e.bc_decomposition_bytes_pc_plus_32, e.bc_decomposition_bytes_pc_plus_33, e.bc_decomposition_bytes_pc_plus_34, e.bc_decomposition_bytes_pc_plus_4, e.bc_decomposition_bytes_pc_plus_5, e.bc_decomposition_bytes_pc_plus_6, e.bc_decomposition_bytes_pc_plus_7, e.bc_decomposition_bytes_pc_plus_8, e.bc_decomposition_bytes_pc_plus_9, e.execution_sel, e.sha256_a, e.sha256_b, e.sha256_c, e.sha256_d, e.sha256_e, e.sha256_f, e.sha256_g, e.sha256_h, e.sha256_helper_w0, e.sha256_helper_w1, e.sha256_helper_w10, e.sha256_helper_w11, e.sha256_helper_w12, e.sha256_helper_w13, e.sha256_helper_w14, e.sha256_helper_w15, e.sha256_helper_w2, e.sha256_helper_w3, e.sha256_helper_w4, e.sha256_helper_w5, e.sha256_helper_w6, e.sha256_helper_w7, e.sha256_helper_w8, e.sha256_helper_w9, e.sha256_rounds_remaining, e.sha256_sel, e.sha256_start +#define AVM2_PRECOMPUTED_ENTITIES precomputed_as_unary, precomputed_bitwise_input_a, precomputed_bitwise_input_b, precomputed_bitwise_op_id, precomputed_bitwise_output, precomputed_clk, precomputed_first_row, precomputed_integral_tag_length, precomputed_power_of_2, precomputed_sel_bitwise, precomputed_sel_integral_tag, precomputed_sel_range_16, precomputed_sel_range_8, precomputed_sel_sha256_compression, precomputed_sel_unary, precomputed_sha256_compression_round_constant +#define AVM2_WIRE_ENTITIES execution_input, alu_dst_addr, alu_ia, alu_ia_addr, alu_ib, alu_ib_addr, alu_ic, alu_op, alu_sel_op_add, bc_decomposition_bytes, bc_decomposition_bytes_pc_plus_1, bc_decomposition_bytes_pc_plus_10, bc_decomposition_bytes_pc_plus_11, bc_decomposition_bytes_pc_plus_12, bc_decomposition_bytes_pc_plus_13, bc_decomposition_bytes_pc_plus_14, bc_decomposition_bytes_pc_plus_15, bc_decomposition_bytes_pc_plus_16, bc_decomposition_bytes_pc_plus_17, bc_decomposition_bytes_pc_plus_18, bc_decomposition_bytes_pc_plus_19, bc_decomposition_bytes_pc_plus_2, bc_decomposition_bytes_pc_plus_20, bc_decomposition_bytes_pc_plus_21, bc_decomposition_bytes_pc_plus_22, bc_decomposition_bytes_pc_plus_23, bc_decomposition_bytes_pc_plus_24, bc_decomposition_bytes_pc_plus_25, bc_decomposition_bytes_pc_plus_26, bc_decomposition_bytes_pc_plus_27, bc_decomposition_bytes_pc_plus_28, bc_decomposition_bytes_pc_plus_29, bc_decomposition_bytes_pc_plus_3, bc_decomposition_bytes_pc_plus_30, bc_decomposition_bytes_pc_plus_31, bc_decomposition_bytes_pc_plus_32, bc_decomposition_bytes_pc_plus_33, bc_decomposition_bytes_pc_plus_34, bc_decomposition_bytes_pc_plus_35, bc_decomposition_bytes_pc_plus_4, bc_decomposition_bytes_pc_plus_5, bc_decomposition_bytes_pc_plus_6, bc_decomposition_bytes_pc_plus_7, bc_decomposition_bytes_pc_plus_8, bc_decomposition_bytes_pc_plus_9, bc_decomposition_bytes_remaining, bc_decomposition_bytes_to_read, bc_decomposition_bytes_to_read_unary, bc_decomposition_id, bc_decomposition_last_of_contract, bc_decomposition_pc, bc_decomposition_sel, bc_decomposition_sel_overflow_correction_needed, bc_decomposition_sel_pc_plus_0, bc_decomposition_sel_pc_plus_1, bc_decomposition_sel_pc_plus_10, bc_decomposition_sel_pc_plus_11, bc_decomposition_sel_pc_plus_12, bc_decomposition_sel_pc_plus_13, bc_decomposition_sel_pc_plus_14, bc_decomposition_sel_pc_plus_15, bc_decomposition_sel_pc_plus_16, bc_decomposition_sel_pc_plus_17, bc_decomposition_sel_pc_plus_18, bc_decomposition_sel_pc_plus_19, bc_decomposition_sel_pc_plus_2, bc_decomposition_sel_pc_plus_20, bc_decomposition_sel_pc_plus_21, bc_decomposition_sel_pc_plus_22, bc_decomposition_sel_pc_plus_23, bc_decomposition_sel_pc_plus_24, bc_decomposition_sel_pc_plus_25, bc_decomposition_sel_pc_plus_26, bc_decomposition_sel_pc_plus_27, bc_decomposition_sel_pc_plus_28, bc_decomposition_sel_pc_plus_29, bc_decomposition_sel_pc_plus_3, bc_decomposition_sel_pc_plus_30, bc_decomposition_sel_pc_plus_31, bc_decomposition_sel_pc_plus_32, bc_decomposition_sel_pc_plus_33, bc_decomposition_sel_pc_plus_34, bc_decomposition_sel_pc_plus_35, bc_decomposition_sel_pc_plus_4, bc_decomposition_sel_pc_plus_5, bc_decomposition_sel_pc_plus_6, bc_decomposition_sel_pc_plus_7, bc_decomposition_sel_pc_plus_8, bc_decomposition_sel_pc_plus_9, bc_retrieval_address, bc_retrieval_artifact_hash, bc_retrieval_bytecode_id, bc_retrieval_class_id, bc_retrieval_deployer_addr, bc_retrieval_err, bc_retrieval_incoming_viewing_key_x, bc_retrieval_incoming_viewing_key_y, bc_retrieval_init_hash, bc_retrieval_nullifier_key_x, bc_retrieval_nullifier_key_y, bc_retrieval_outgoing_viewing_key_x, bc_retrieval_outgoing_viewing_key_y, bc_retrieval_private_function_root, bc_retrieval_public_bytecode_commitment, bc_retrieval_salt, bc_retrieval_sel, bc_retrieval_tagging_key_x, bc_retrieval_tagging_key_y, bitwise_acc_ia, bitwise_acc_ib, bitwise_acc_ic, bitwise_ctr, bitwise_ctr_inv, bitwise_ctr_min_one_inv, bitwise_ia_byte, bitwise_ib_byte, bitwise_ic_byte, bitwise_last, bitwise_op_id, bitwise_sel, bitwise_start, bitwise_tag, execution_addressing_error_idx, execution_addressing_error_kind, execution_base_address_tag, execution_base_address_val, execution_bytecode_id, execution_clk, execution_ex_opcode, execution_indirect, execution_last, execution_op1, execution_op1_after_relative, execution_op2, execution_op2_after_relative, execution_op3, execution_op3_after_relative, execution_op4, execution_op4_after_relative, execution_pc, execution_rop1, execution_rop2, execution_rop3, execution_rop4, execution_sel, execution_sel_addressing_error, execution_sel_op1_is_address, execution_sel_op2_is_address, execution_sel_op3_is_address, execution_sel_op4_is_address, instr_fetching_bd0, instr_fetching_bd1, instr_fetching_bd10, instr_fetching_bd11, instr_fetching_bd12, instr_fetching_bd13, instr_fetching_bd14, instr_fetching_bd15, instr_fetching_bd16, instr_fetching_bd17, instr_fetching_bd18, instr_fetching_bd19, instr_fetching_bd2, instr_fetching_bd20, instr_fetching_bd21, instr_fetching_bd22, instr_fetching_bd23, instr_fetching_bd24, instr_fetching_bd25, instr_fetching_bd26, instr_fetching_bd27, instr_fetching_bd28, instr_fetching_bd29, instr_fetching_bd3, instr_fetching_bd30, instr_fetching_bd31, instr_fetching_bd32, instr_fetching_bd33, instr_fetching_bd34, instr_fetching_bd35, instr_fetching_bd4, instr_fetching_bd5, instr_fetching_bd6, instr_fetching_bd7, instr_fetching_bd8, instr_fetching_bd9, instr_fetching_bytecode_id, instr_fetching_ex_opcode, instr_fetching_fmt_3_op_u8, instr_fetching_indirect, instr_fetching_op1, instr_fetching_op2, instr_fetching_op3, instr_fetching_op4, instr_fetching_pc, instr_fetching_sel, range_check_dyn_diff, range_check_dyn_rng_chk_bits, range_check_dyn_rng_chk_pow_2, range_check_is_lte_u112, range_check_is_lte_u128, range_check_is_lte_u16, range_check_is_lte_u32, range_check_is_lte_u48, range_check_is_lte_u64, range_check_is_lte_u80, range_check_is_lte_u96, range_check_rng_chk_bits, range_check_sel, range_check_sel_r0_16_bit_rng_lookup, range_check_sel_r1_16_bit_rng_lookup, range_check_sel_r2_16_bit_rng_lookup, range_check_sel_r3_16_bit_rng_lookup, range_check_sel_r4_16_bit_rng_lookup, range_check_sel_r5_16_bit_rng_lookup, range_check_sel_r6_16_bit_rng_lookup, range_check_u16_r0, range_check_u16_r1, range_check_u16_r2, range_check_u16_r3, range_check_u16_r4, range_check_u16_r5, range_check_u16_r6, range_check_u16_r7, range_check_value, sha256_a, sha256_a_and_b, sha256_a_and_b_xor_a_and_c, sha256_a_and_c, sha256_a_rotr_13, sha256_a_rotr_2, sha256_a_rotr_22, sha256_a_rotr_2_xor_a_rotr_13, sha256_and_sel, sha256_b, sha256_b_and_c, sha256_c, sha256_ch, sha256_clk, sha256_computed_w_lhs, sha256_computed_w_rhs, sha256_d, sha256_dummy_zero, sha256_e, sha256_e_and_f, sha256_e_rotr_11, sha256_e_rotr_25, sha256_e_rotr_6, sha256_e_rotr_6_xor_e_rotr_11, sha256_f, sha256_g, sha256_h, sha256_helper_w0, sha256_helper_w1, sha256_helper_w10, sha256_helper_w11, sha256_helper_w12, sha256_helper_w13, sha256_helper_w14, sha256_helper_w15, sha256_helper_w2, sha256_helper_w3, sha256_helper_w4, sha256_helper_w5, sha256_helper_w6, sha256_helper_w7, sha256_helper_w8, sha256_helper_w9, sha256_init_a, sha256_init_b, sha256_init_c, sha256_init_d, sha256_init_e, sha256_init_f, sha256_init_g, sha256_init_h, sha256_input_offset, sha256_is_input_round, sha256_latch, sha256_lhs_a_13, sha256_lhs_a_2, sha256_lhs_a_22, sha256_lhs_e_11, sha256_lhs_e_25, sha256_lhs_e_6, sha256_lhs_w_10, sha256_lhs_w_17, sha256_lhs_w_18, sha256_lhs_w_19, sha256_lhs_w_3, sha256_lhs_w_7, sha256_maj, sha256_next_a_lhs, sha256_next_a_rhs, sha256_next_e_lhs, sha256_next_e_rhs, sha256_not_e, sha256_not_e_and_g, sha256_output_a_lhs, sha256_output_a_rhs, sha256_output_b_lhs, sha256_output_b_rhs, sha256_output_c_lhs, sha256_output_c_rhs, sha256_output_d_lhs, sha256_output_d_rhs, sha256_output_e_lhs, sha256_output_e_rhs, sha256_output_f_lhs, sha256_output_f_rhs, sha256_output_g_lhs, sha256_output_g_rhs, sha256_output_h_lhs, sha256_output_h_rhs, sha256_output_offset, sha256_perform_round, sha256_rhs_a_13, sha256_rhs_a_2, sha256_rhs_a_22, sha256_rhs_e_11, sha256_rhs_e_25, sha256_rhs_e_6, sha256_rhs_w_10, sha256_rhs_w_17, sha256_rhs_w_18, sha256_rhs_w_19, sha256_rhs_w_3, sha256_rhs_w_7, sha256_round_constant, sha256_round_count, sha256_rounds_remaining, sha256_rounds_remaining_inv, sha256_s_0, sha256_s_1, sha256_sel, sha256_start, sha256_state_offset, sha256_w, sha256_w_15_rotr_18, sha256_w_15_rotr_7, sha256_w_15_rotr_7_xor_w_15_rotr_18, sha256_w_15_rshift_3, sha256_w_2_rotr_17, sha256_w_2_rotr_17_xor_w_2_rotr_19, sha256_w_2_rotr_19, sha256_w_2_rshift_10, sha256_w_s_0, sha256_w_s_1, sha256_xor_sel, lookup_bytecode_to_read_unary_counts, lookup_rng_chk_pow_2_counts, lookup_rng_chk_diff_counts, lookup_rng_chk_is_r0_16_bit_counts, lookup_rng_chk_is_r1_16_bit_counts, lookup_rng_chk_is_r2_16_bit_counts, lookup_rng_chk_is_r3_16_bit_counts, lookup_rng_chk_is_r4_16_bit_counts, lookup_rng_chk_is_r5_16_bit_counts, lookup_rng_chk_is_r6_16_bit_counts, lookup_rng_chk_is_r7_16_bit_counts, lookup_bitw_byte_lengths_counts, lookup_bitw_byte_operations_counts, lookup_sha256_round_constant_counts, lookup_dummy_precomputed_counts, lookup_dummy_dynamic_counts +#define AVM2_DERIVED_WITNESS_ENTITIES perm_dummy_dynamic_inv, lookup_bytecode_to_read_unary_inv, lookup_rng_chk_pow_2_inv, lookup_rng_chk_diff_inv, lookup_rng_chk_is_r0_16_bit_inv, lookup_rng_chk_is_r1_16_bit_inv, lookup_rng_chk_is_r2_16_bit_inv, lookup_rng_chk_is_r3_16_bit_inv, lookup_rng_chk_is_r4_16_bit_inv, lookup_rng_chk_is_r5_16_bit_inv, lookup_rng_chk_is_r6_16_bit_inv, lookup_rng_chk_is_r7_16_bit_inv, lookup_bitw_byte_lengths_inv, lookup_bitw_byte_operations_inv, lookup_sha256_round_constant_inv, lookup_dummy_precomputed_inv, lookup_dummy_dynamic_inv +#define AVM2_SHIFTED_ENTITIES bc_decomposition_bytes_shift, bc_decomposition_bytes_pc_plus_1_shift, bc_decomposition_bytes_pc_plus_10_shift, bc_decomposition_bytes_pc_plus_11_shift, bc_decomposition_bytes_pc_plus_12_shift, bc_decomposition_bytes_pc_plus_13_shift, bc_decomposition_bytes_pc_plus_14_shift, bc_decomposition_bytes_pc_plus_15_shift, bc_decomposition_bytes_pc_plus_16_shift, bc_decomposition_bytes_pc_plus_17_shift, bc_decomposition_bytes_pc_plus_18_shift, bc_decomposition_bytes_pc_plus_19_shift, bc_decomposition_bytes_pc_plus_2_shift, bc_decomposition_bytes_pc_plus_20_shift, bc_decomposition_bytes_pc_plus_21_shift, bc_decomposition_bytes_pc_plus_22_shift, bc_decomposition_bytes_pc_plus_23_shift, bc_decomposition_bytes_pc_plus_24_shift, bc_decomposition_bytes_pc_plus_25_shift, bc_decomposition_bytes_pc_plus_26_shift, bc_decomposition_bytes_pc_plus_27_shift, bc_decomposition_bytes_pc_plus_28_shift, bc_decomposition_bytes_pc_plus_29_shift, bc_decomposition_bytes_pc_plus_3_shift, bc_decomposition_bytes_pc_plus_30_shift, bc_decomposition_bytes_pc_plus_31_shift, bc_decomposition_bytes_pc_plus_32_shift, bc_decomposition_bytes_pc_plus_33_shift, bc_decomposition_bytes_pc_plus_34_shift, bc_decomposition_bytes_pc_plus_4_shift, bc_decomposition_bytes_pc_plus_5_shift, bc_decomposition_bytes_pc_plus_6_shift, bc_decomposition_bytes_pc_plus_7_shift, bc_decomposition_bytes_pc_plus_8_shift, bc_decomposition_bytes_pc_plus_9_shift, bitwise_acc_ia_shift, bitwise_acc_ib_shift, bitwise_acc_ic_shift, bitwise_ctr_shift, bitwise_op_id_shift, execution_sel_shift, sha256_a_shift, sha256_b_shift, sha256_c_shift, sha256_d_shift, sha256_e_shift, sha256_f_shift, sha256_g_shift, sha256_h_shift, sha256_helper_w0_shift, sha256_helper_w1_shift, sha256_helper_w10_shift, sha256_helper_w11_shift, sha256_helper_w12_shift, sha256_helper_w13_shift, sha256_helper_w14_shift, sha256_helper_w15_shift, sha256_helper_w2_shift, sha256_helper_w3_shift, sha256_helper_w4_shift, sha256_helper_w5_shift, sha256_helper_w6_shift, sha256_helper_w7_shift, sha256_helper_w8_shift, sha256_helper_w9_shift, sha256_rounds_remaining_shift, sha256_sel_shift, sha256_start_shift +#define AVM2_TO_BE_SHIFTED(e) e.bc_decomposition_bytes, e.bc_decomposition_bytes_pc_plus_1, e.bc_decomposition_bytes_pc_plus_10, e.bc_decomposition_bytes_pc_plus_11, e.bc_decomposition_bytes_pc_plus_12, e.bc_decomposition_bytes_pc_plus_13, e.bc_decomposition_bytes_pc_plus_14, e.bc_decomposition_bytes_pc_plus_15, e.bc_decomposition_bytes_pc_plus_16, e.bc_decomposition_bytes_pc_plus_17, e.bc_decomposition_bytes_pc_plus_18, e.bc_decomposition_bytes_pc_plus_19, e.bc_decomposition_bytes_pc_plus_2, e.bc_decomposition_bytes_pc_plus_20, e.bc_decomposition_bytes_pc_plus_21, e.bc_decomposition_bytes_pc_plus_22, e.bc_decomposition_bytes_pc_plus_23, e.bc_decomposition_bytes_pc_plus_24, e.bc_decomposition_bytes_pc_plus_25, e.bc_decomposition_bytes_pc_plus_26, e.bc_decomposition_bytes_pc_plus_27, e.bc_decomposition_bytes_pc_plus_28, e.bc_decomposition_bytes_pc_plus_29, e.bc_decomposition_bytes_pc_plus_3, e.bc_decomposition_bytes_pc_plus_30, e.bc_decomposition_bytes_pc_plus_31, e.bc_decomposition_bytes_pc_plus_32, e.bc_decomposition_bytes_pc_plus_33, e.bc_decomposition_bytes_pc_plus_34, e.bc_decomposition_bytes_pc_plus_4, e.bc_decomposition_bytes_pc_plus_5, e.bc_decomposition_bytes_pc_plus_6, e.bc_decomposition_bytes_pc_plus_7, e.bc_decomposition_bytes_pc_plus_8, e.bc_decomposition_bytes_pc_plus_9, e.bitwise_acc_ia, e.bitwise_acc_ib, e.bitwise_acc_ic, e.bitwise_ctr, e.bitwise_op_id, e.execution_sel, e.sha256_a, e.sha256_b, e.sha256_c, e.sha256_d, e.sha256_e, e.sha256_f, e.sha256_g, e.sha256_h, e.sha256_helper_w0, e.sha256_helper_w1, e.sha256_helper_w10, e.sha256_helper_w11, e.sha256_helper_w12, e.sha256_helper_w13, e.sha256_helper_w14, e.sha256_helper_w15, e.sha256_helper_w2, e.sha256_helper_w3, e.sha256_helper_w4, e.sha256_helper_w5, e.sha256_helper_w6, e.sha256_helper_w7, e.sha256_helper_w8, e.sha256_helper_w9, e.sha256_rounds_remaining, e.sha256_sel, e.sha256_start #define AVM2_ALL_ENTITIES AVM2_PRECOMPUTED_ENTITIES, AVM2_WIRE_ENTITIES, AVM2_DERIVED_WITNESS_ENTITIES, AVM2_SHIFTED_ENTITIES #define AVM2_UNSHIFTED_ENTITIES AVM2_PRECOMPUTED_ENTITIES, AVM2_WIRE_ENTITIES, AVM2_DERIVED_WITNESS_ENTITIES #define AVM2_WITNESS_ENTITIES AVM2_WIRE_ENTITIES, AVM2_DERIVED_WITNESS_ENTITIES -#define AVM2_TO_BE_SHIFTED_COLUMNS Column::bc_decomposition_bytes, Column::bc_decomposition_bytes_pc_plus_1, Column::bc_decomposition_bytes_pc_plus_10, Column::bc_decomposition_bytes_pc_plus_11, Column::bc_decomposition_bytes_pc_plus_12, Column::bc_decomposition_bytes_pc_plus_13, Column::bc_decomposition_bytes_pc_plus_14, Column::bc_decomposition_bytes_pc_plus_15, Column::bc_decomposition_bytes_pc_plus_16, Column::bc_decomposition_bytes_pc_plus_17, Column::bc_decomposition_bytes_pc_plus_18, Column::bc_decomposition_bytes_pc_plus_19, Column::bc_decomposition_bytes_pc_plus_2, Column::bc_decomposition_bytes_pc_plus_20, Column::bc_decomposition_bytes_pc_plus_21, Column::bc_decomposition_bytes_pc_plus_22, Column::bc_decomposition_bytes_pc_plus_23, Column::bc_decomposition_bytes_pc_plus_24, Column::bc_decomposition_bytes_pc_plus_25, Column::bc_decomposition_bytes_pc_plus_26, Column::bc_decomposition_bytes_pc_plus_27, Column::bc_decomposition_bytes_pc_plus_28, Column::bc_decomposition_bytes_pc_plus_29, Column::bc_decomposition_bytes_pc_plus_3, Column::bc_decomposition_bytes_pc_plus_30, Column::bc_decomposition_bytes_pc_plus_31, Column::bc_decomposition_bytes_pc_plus_32, Column::bc_decomposition_bytes_pc_plus_33, Column::bc_decomposition_bytes_pc_plus_34, Column::bc_decomposition_bytes_pc_plus_4, Column::bc_decomposition_bytes_pc_plus_5, Column::bc_decomposition_bytes_pc_plus_6, Column::bc_decomposition_bytes_pc_plus_7, Column::bc_decomposition_bytes_pc_plus_8, Column::bc_decomposition_bytes_pc_plus_9, Column::execution_sel, Column::sha256_a, Column::sha256_b, Column::sha256_c, Column::sha256_d, Column::sha256_e, Column::sha256_f, Column::sha256_g, Column::sha256_h, Column::sha256_helper_w0, Column::sha256_helper_w1, Column::sha256_helper_w10, Column::sha256_helper_w11, Column::sha256_helper_w12, Column::sha256_helper_w13, Column::sha256_helper_w14, Column::sha256_helper_w15, Column::sha256_helper_w2, Column::sha256_helper_w3, Column::sha256_helper_w4, Column::sha256_helper_w5, Column::sha256_helper_w6, Column::sha256_helper_w7, Column::sha256_helper_w8, Column::sha256_helper_w9, Column::sha256_rounds_remaining, Column::sha256_sel, Column::sha256_start -#define AVM2_SHIFTED_COLUMNS ColumnAndShifts::bc_decomposition_bytes_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_1_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_10_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_11_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_12_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_13_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_14_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_15_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_16_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_17_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_18_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_19_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_2_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_20_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_21_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_22_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_23_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_24_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_25_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_26_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_27_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_28_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_29_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_3_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_30_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_31_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_32_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_33_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_34_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_4_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_5_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_6_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_7_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_8_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_9_shift, ColumnAndShifts::execution_sel_shift, ColumnAndShifts::sha256_a_shift, ColumnAndShifts::sha256_b_shift, ColumnAndShifts::sha256_c_shift, ColumnAndShifts::sha256_d_shift, ColumnAndShifts::sha256_e_shift, ColumnAndShifts::sha256_f_shift, ColumnAndShifts::sha256_g_shift, ColumnAndShifts::sha256_h_shift, ColumnAndShifts::sha256_helper_w0_shift, ColumnAndShifts::sha256_helper_w1_shift, ColumnAndShifts::sha256_helper_w10_shift, ColumnAndShifts::sha256_helper_w11_shift, ColumnAndShifts::sha256_helper_w12_shift, ColumnAndShifts::sha256_helper_w13_shift, ColumnAndShifts::sha256_helper_w14_shift, ColumnAndShifts::sha256_helper_w15_shift, ColumnAndShifts::sha256_helper_w2_shift, ColumnAndShifts::sha256_helper_w3_shift, ColumnAndShifts::sha256_helper_w4_shift, ColumnAndShifts::sha256_helper_w5_shift, ColumnAndShifts::sha256_helper_w6_shift, ColumnAndShifts::sha256_helper_w7_shift, ColumnAndShifts::sha256_helper_w8_shift, ColumnAndShifts::sha256_helper_w9_shift, ColumnAndShifts::sha256_rounds_remaining_shift, ColumnAndShifts::sha256_sel_shift, ColumnAndShifts::sha256_start_shift +#define AVM2_TO_BE_SHIFTED_COLUMNS Column::bc_decomposition_bytes, Column::bc_decomposition_bytes_pc_plus_1, Column::bc_decomposition_bytes_pc_plus_10, Column::bc_decomposition_bytes_pc_plus_11, Column::bc_decomposition_bytes_pc_plus_12, Column::bc_decomposition_bytes_pc_plus_13, Column::bc_decomposition_bytes_pc_plus_14, Column::bc_decomposition_bytes_pc_plus_15, Column::bc_decomposition_bytes_pc_plus_16, Column::bc_decomposition_bytes_pc_plus_17, Column::bc_decomposition_bytes_pc_plus_18, Column::bc_decomposition_bytes_pc_plus_19, Column::bc_decomposition_bytes_pc_plus_2, Column::bc_decomposition_bytes_pc_plus_20, Column::bc_decomposition_bytes_pc_plus_21, Column::bc_decomposition_bytes_pc_plus_22, Column::bc_decomposition_bytes_pc_plus_23, Column::bc_decomposition_bytes_pc_plus_24, Column::bc_decomposition_bytes_pc_plus_25, Column::bc_decomposition_bytes_pc_plus_26, Column::bc_decomposition_bytes_pc_plus_27, Column::bc_decomposition_bytes_pc_plus_28, Column::bc_decomposition_bytes_pc_plus_29, Column::bc_decomposition_bytes_pc_plus_3, Column::bc_decomposition_bytes_pc_plus_30, Column::bc_decomposition_bytes_pc_plus_31, Column::bc_decomposition_bytes_pc_plus_32, Column::bc_decomposition_bytes_pc_plus_33, Column::bc_decomposition_bytes_pc_plus_34, Column::bc_decomposition_bytes_pc_plus_4, Column::bc_decomposition_bytes_pc_plus_5, Column::bc_decomposition_bytes_pc_plus_6, Column::bc_decomposition_bytes_pc_plus_7, Column::bc_decomposition_bytes_pc_plus_8, Column::bc_decomposition_bytes_pc_plus_9, Column::bitwise_acc_ia, Column::bitwise_acc_ib, Column::bitwise_acc_ic, Column::bitwise_ctr, Column::bitwise_op_id, Column::execution_sel, Column::sha256_a, Column::sha256_b, Column::sha256_c, Column::sha256_d, Column::sha256_e, Column::sha256_f, Column::sha256_g, Column::sha256_h, Column::sha256_helper_w0, Column::sha256_helper_w1, Column::sha256_helper_w10, Column::sha256_helper_w11, Column::sha256_helper_w12, Column::sha256_helper_w13, Column::sha256_helper_w14, Column::sha256_helper_w15, Column::sha256_helper_w2, Column::sha256_helper_w3, Column::sha256_helper_w4, Column::sha256_helper_w5, Column::sha256_helper_w6, Column::sha256_helper_w7, Column::sha256_helper_w8, Column::sha256_helper_w9, Column::sha256_rounds_remaining, Column::sha256_sel, Column::sha256_start +#define AVM2_SHIFTED_COLUMNS ColumnAndShifts::bc_decomposition_bytes_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_1_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_10_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_11_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_12_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_13_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_14_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_15_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_16_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_17_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_18_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_19_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_2_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_20_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_21_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_22_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_23_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_24_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_25_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_26_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_27_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_28_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_29_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_3_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_30_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_31_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_32_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_33_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_34_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_4_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_5_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_6_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_7_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_8_shift, ColumnAndShifts::bc_decomposition_bytes_pc_plus_9_shift, ColumnAndShifts::bitwise_acc_ia_shift, ColumnAndShifts::bitwise_acc_ib_shift, ColumnAndShifts::bitwise_acc_ic_shift, ColumnAndShifts::bitwise_ctr_shift, ColumnAndShifts::bitwise_op_id_shift, ColumnAndShifts::execution_sel_shift, ColumnAndShifts::sha256_a_shift, ColumnAndShifts::sha256_b_shift, ColumnAndShifts::sha256_c_shift, ColumnAndShifts::sha256_d_shift, ColumnAndShifts::sha256_e_shift, ColumnAndShifts::sha256_f_shift, ColumnAndShifts::sha256_g_shift, ColumnAndShifts::sha256_h_shift, ColumnAndShifts::sha256_helper_w0_shift, ColumnAndShifts::sha256_helper_w1_shift, ColumnAndShifts::sha256_helper_w10_shift, ColumnAndShifts::sha256_helper_w11_shift, ColumnAndShifts::sha256_helper_w12_shift, ColumnAndShifts::sha256_helper_w13_shift, ColumnAndShifts::sha256_helper_w14_shift, ColumnAndShifts::sha256_helper_w15_shift, ColumnAndShifts::sha256_helper_w2_shift, ColumnAndShifts::sha256_helper_w3_shift, ColumnAndShifts::sha256_helper_w4_shift, ColumnAndShifts::sha256_helper_w5_shift, ColumnAndShifts::sha256_helper_w6_shift, ColumnAndShifts::sha256_helper_w7_shift, ColumnAndShifts::sha256_helper_w8_shift, ColumnAndShifts::sha256_helper_w9_shift, ColumnAndShifts::sha256_rounds_remaining_shift, ColumnAndShifts::sha256_sel_shift, ColumnAndShifts::sha256_start_shift // clang-format on // All columns minus shifts. @@ -31,8 +31,8 @@ enum class ColumnAndShifts { SENTINEL_DO_NOT_USE, }; -constexpr auto NUM_COLUMNS_WITH_SHIFTS = 441; -constexpr auto NUM_COLUMNS_WITHOUT_SHIFTS = 378; +constexpr auto NUM_COLUMNS_WITH_SHIFTS = 466; +constexpr auto NUM_COLUMNS_WITHOUT_SHIFTS = 398; constexpr auto TO_BE_SHIFTED_COLUMNS_ARRAY = []() { return std::array{ AVM2_TO_BE_SHIFTED_COLUMNS }; }(); constexpr auto SHIFTED_COLUMNS_ARRAY = []() { return std::array{ AVM2_SHIFTED_COLUMNS }; }(); static_assert(TO_BE_SHIFTED_COLUMNS_ARRAY.size() == SHIFTED_COLUMNS_ARRAY.size()); diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/flavor.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/flavor.hpp index ac8d40f66a64..b74d954b2754 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/flavor.hpp @@ -21,6 +21,7 @@ #include "relations/alu.hpp" #include "relations/bc_decomposition.hpp" #include "relations/bc_retrieval.hpp" +#include "relations/bitwise.hpp" #include "relations/execution.hpp" #include "relations/instr_fetching.hpp" #include "relations/range_check.hpp" @@ -28,6 +29,7 @@ // Lookup and permutation relations #include "relations/lookups_bc_decomposition.hpp" +#include "relations/lookups_bitwise.hpp" #include "relations/lookups_execution.hpp" #include "relations/lookups_range_check.hpp" #include "relations/lookups_sha256.hpp" @@ -73,13 +75,13 @@ class AvmFlavor { // This flavor would not be used with ZK Sumcheck static constexpr bool HasZK = false; - static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 14; - static constexpr size_t NUM_WITNESS_ENTITIES = 364; - static constexpr size_t NUM_SHIFTED_ENTITIES = 63; + static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 16; + static constexpr size_t NUM_WITNESS_ENTITIES = 382; + static constexpr size_t NUM_SHIFTED_ENTITIES = 68; 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 = 441; + static constexpr size_t NUM_ALL_ENTITIES = 466; // The total number of witnesses including shifts and derived entities. static constexpr size_t NUM_ALL_WITNESS_ENTITIES = NUM_WITNESS_ENTITIES + NUM_SHIFTED_ENTITIES; @@ -90,6 +92,7 @@ class AvmFlavor { avm2::alu, avm2::bc_decomposition, avm2::bc_retrieval, + avm2::bitwise, avm2::execution, avm2::instr_fetching, avm2::range_check, @@ -101,6 +104,8 @@ class AvmFlavor { template using LookupRelations_ = std::tuple< // Lookups + lookup_bitw_byte_lengths_relation, + lookup_bitw_byte_operations_relation, lookup_bytecode_to_read_unary_relation, lookup_dummy_dynamic_relation, lookup_dummy_precomputed_relation, @@ -368,8 +373,10 @@ class AvmFlavor { this->precomputed_bitwise_output = verification_key->precomputed_bitwise_output; this->precomputed_clk = verification_key->precomputed_clk; this->precomputed_first_row = verification_key->precomputed_first_row; + this->precomputed_integral_tag_length = verification_key->precomputed_integral_tag_length; this->precomputed_power_of_2 = verification_key->precomputed_power_of_2; this->precomputed_sel_bitwise = verification_key->precomputed_sel_bitwise; + this->precomputed_sel_integral_tag = verification_key->precomputed_sel_integral_tag; this->precomputed_sel_range_16 = verification_key->precomputed_sel_range_16; this->precomputed_sel_range_8 = verification_key->precomputed_sel_range_8; this->precomputed_sel_sha256_compression = verification_key->precomputed_sel_sha256_compression; diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/full_row.cpp b/barretenberg/cpp/src/barretenberg/vm2/generated/full_row.cpp index 4aa2a151307c..0f1864d9a530 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/generated/full_row.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/full_row.cpp @@ -6,7 +6,6 @@ namespace bb::avm2 { template std::ostream& operator<<(std::ostream& os, [[maybe_unused]] AvmFullRow const& row) { - assert(false); // unsupported. return os; } diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/full_row.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/full_row.hpp index f997b7edd907..7abc2c82c7e6 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/generated/full_row.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/full_row.hpp @@ -15,7 +15,7 @@ template struct AvmFullRow { FF AVM2_ALL_ENTITIES; - static constexpr size_t SIZE = 378; + static constexpr size_t SIZE = 398; // Risky but oh so efficient. FF& get_column(ColumnAndShifts col) diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/relations/bitwise.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/bitwise.hpp new file mode 100644 index 000000000000..47e371aa3e6e --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/bitwise.hpp @@ -0,0 +1,163 @@ +// AUTOGENERATED FILE +#pragma once + +#include + +#include "barretenberg/relations/relation_parameters.hpp" +#include "barretenberg/relations/relation_types.hpp" + +namespace bb::avm2 { + +template class bitwiseImpl { + public: + using FF = FF_; + + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 3, 4, 4, 5, 3, 3, 3, 3, 3, 3 }; + + template inline static bool skip(const AllEntities& in) + { + const auto& new_term = in; + return ((new_term.bitwise_sel + new_term.bitwise_last)).is_zero(); + } + + template + void static accumulate(ContainerOverSubrelations& evals, + const AllEntities& new_term, + [[maybe_unused]] const RelationParameters&, + [[maybe_unused]] const FF& scaling_factor) + { + + { + using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; + auto tmp = (new_term.bitwise_sel * (FF(1) - new_term.bitwise_sel)); + tmp *= scaling_factor; + std::get<0>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<1, ContainerOverSubrelations>; + auto tmp = (new_term.bitwise_last * (FF(1) - new_term.bitwise_last)); + tmp *= scaling_factor; + std::get<1>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<2, ContainerOverSubrelations>; + auto tmp = ((new_term.bitwise_op_id_shift - new_term.bitwise_op_id) * (FF(1) - new_term.bitwise_last)); + tmp *= scaling_factor; + std::get<2>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<3, ContainerOverSubrelations>; + auto tmp = ((new_term.bitwise_sel * ((new_term.bitwise_ctr_shift - new_term.bitwise_ctr) + FF(1))) * + (FF(1) - new_term.bitwise_last)); + tmp *= scaling_factor; + std::get<3>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<4, ContainerOverSubrelations>; + auto tmp = ((new_term.bitwise_ctr * (((FF(1) - new_term.bitwise_sel) * (FF(1) - new_term.bitwise_ctr_inv)) + + new_term.bitwise_ctr_inv)) - + new_term.bitwise_sel); + tmp *= scaling_factor; + std::get<4>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<5, ContainerOverSubrelations>; + auto tmp = + (new_term.bitwise_sel * ((((new_term.bitwise_ctr - FF(1)) * + ((new_term.bitwise_last * (FF(1) - new_term.bitwise_ctr_min_one_inv)) + + new_term.bitwise_ctr_min_one_inv)) + + new_term.bitwise_last) - + FF(1))); + tmp *= scaling_factor; + std::get<5>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<6, ContainerOverSubrelations>; + auto tmp = (new_term.bitwise_last * (new_term.bitwise_acc_ia - new_term.bitwise_ia_byte)); + tmp *= scaling_factor; + std::get<6>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<7, ContainerOverSubrelations>; + auto tmp = (new_term.bitwise_last * (new_term.bitwise_acc_ib - new_term.bitwise_ib_byte)); + tmp *= scaling_factor; + std::get<7>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<8, ContainerOverSubrelations>; + auto tmp = (new_term.bitwise_last * (new_term.bitwise_acc_ic - new_term.bitwise_ic_byte)); + tmp *= scaling_factor; + std::get<8>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<9, ContainerOverSubrelations>; + auto tmp = + (((new_term.bitwise_acc_ia - new_term.bitwise_ia_byte) - (FF(256) * new_term.bitwise_acc_ia_shift)) * + (FF(1) - new_term.bitwise_last)); + tmp *= scaling_factor; + std::get<9>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<10, ContainerOverSubrelations>; + auto tmp = + (((new_term.bitwise_acc_ib - new_term.bitwise_ib_byte) - (FF(256) * new_term.bitwise_acc_ib_shift)) * + (FF(1) - new_term.bitwise_last)); + tmp *= scaling_factor; + std::get<10>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<11, ContainerOverSubrelations>; + auto tmp = + (((new_term.bitwise_acc_ic - new_term.bitwise_ic_byte) - (FF(256) * new_term.bitwise_acc_ic_shift)) * + (FF(1) - new_term.bitwise_last)); + tmp *= scaling_factor; + std::get<11>(evals) += typename Accumulator::View(tmp); + } + } +}; + +template class bitwise : public Relation> { + public: + static constexpr const std::string_view NAME = "bitwise"; + + static std::string get_subrelation_label(size_t index) + { + switch (index) { + case 2: + return "BITW_OP_ID_REL"; + case 3: + return "BITW_CTR_DECREMENT"; + case 4: + return "BITW_SEL_CTR_NON_ZERO"; + case 5: + return "BITW_LAST_FOR_CTR_ONE"; + case 6: + return "BITW_INIT_A"; + case 7: + return "BITW_INIT_B"; + case 8: + return "BITW_INIT_C"; + case 9: + return "BITW_ACC_REL_A"; + case 10: + return "BITW_ACC_REL_B"; + case 11: + return "BITW_ACC_REL_C"; + } + return std::to_string(index); + } + + // Subrelation indices constants, to be used in tests. + static constexpr size_t SR_BITW_OP_ID_REL = 2; + static constexpr size_t SR_BITW_CTR_DECREMENT = 3; + static constexpr size_t SR_BITW_SEL_CTR_NON_ZERO = 4; + static constexpr size_t SR_BITW_LAST_FOR_CTR_ONE = 5; + static constexpr size_t SR_BITW_INIT_A = 6; + static constexpr size_t SR_BITW_INIT_B = 7; + static constexpr size_t SR_BITW_INIT_C = 8; + static constexpr size_t SR_BITW_ACC_REL_A = 9; + static constexpr size_t SR_BITW_ACC_REL_B = 10; + static constexpr size_t SR_BITW_ACC_REL_C = 11; +}; + +} // namespace bb::avm2 \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_bitwise.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_bitwise.hpp new file mode 100644 index 000000000000..07f24f2006b5 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_bitwise.hpp @@ -0,0 +1,155 @@ +// AUTOGENERATED FILE +#pragma once + +#include "../columns.hpp" +#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp" + +#include +#include +#include + +namespace bb::avm2 { + +/////////////////// lookup_bitw_byte_lengths /////////////////// + +class lookup_bitw_byte_lengths_lookup_settings { + public: + static constexpr size_t READ_TERMS = 1; + static constexpr size_t WRITE_TERMS = 1; + static constexpr size_t READ_TERM_TYPES[READ_TERMS] = { 0 }; + static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = { 0 }; + static constexpr size_t LOOKUP_TUPLE_SIZE = 2; + static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4; + static constexpr size_t READ_TERM_DEGREE = 0; + static constexpr size_t WRITE_TERM_DEGREE = 0; + + // Columns using the Column enum. + static constexpr Column SRC_SELECTOR = Column::bitwise_start; + static constexpr Column DST_SELECTOR = Column::precomputed_sel_integral_tag; + static constexpr Column COUNTS = Column::lookup_bitw_byte_lengths_counts; + static constexpr Column INVERSES = Column::lookup_bitw_byte_lengths_inv; + static constexpr std::array SRC_COLUMNS = { Column::bitwise_tag, Column::bitwise_ctr }; + static constexpr std::array DST_COLUMNS = { Column::precomputed_clk, + Column::precomputed_integral_tag_length }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._bitwise_start() == 1 || in._precomputed_sel_integral_tag() == 1); + } + + template + static inline auto compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + const auto is_operation = View(in._bitwise_start()); + const auto is_table_entry = View(in._precomputed_sel_integral_tag()); + return (is_operation + is_table_entry - is_operation * is_table_entry); + } + + template static inline auto get_const_entities(const AllEntities& in) + { + return get_entities(in); + } + + template static inline auto get_nonconst_entities(AllEntities& in) + { + return get_entities(in); + } + + template static inline auto get_entities(AllEntities&& in) + { + return std::forward_as_tuple(in._lookup_bitw_byte_lengths_inv(), + in._lookup_bitw_byte_lengths_counts(), + in._bitwise_start(), + in._precomputed_sel_integral_tag(), + in._bitwise_tag(), + in._bitwise_ctr(), + in._precomputed_clk(), + in._precomputed_integral_tag_length()); + } +}; + +template +class lookup_bitw_byte_lengths_relation : public GenericLookupRelation { + public: + static constexpr std::string_view NAME = "LOOKUP_BITW_BYTE_LENGTHS"; +}; +template using lookup_bitw_byte_lengths = GenericLookup; + +/////////////////// lookup_bitw_byte_operations /////////////////// + +class lookup_bitw_byte_operations_lookup_settings { + public: + static constexpr size_t READ_TERMS = 1; + static constexpr size_t WRITE_TERMS = 1; + static constexpr size_t READ_TERM_TYPES[READ_TERMS] = { 0 }; + static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = { 0 }; + static constexpr size_t LOOKUP_TUPLE_SIZE = 4; + static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4; + static constexpr size_t READ_TERM_DEGREE = 0; + static constexpr size_t WRITE_TERM_DEGREE = 0; + + // Columns using the Column enum. + static constexpr Column SRC_SELECTOR = Column::bitwise_sel; + static constexpr Column DST_SELECTOR = Column::precomputed_sel_bitwise; + static constexpr Column COUNTS = Column::lookup_bitw_byte_operations_counts; + static constexpr Column INVERSES = Column::lookup_bitw_byte_operations_inv; + static constexpr std::array SRC_COLUMNS = { + Column::bitwise_op_id, Column::bitwise_ia_byte, Column::bitwise_ib_byte, Column::bitwise_ic_byte + }; + static constexpr std::array DST_COLUMNS = { Column::precomputed_bitwise_op_id, + Column::precomputed_bitwise_input_a, + Column::precomputed_bitwise_input_b, + Column::precomputed_bitwise_output }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._bitwise_sel() == 1 || in._precomputed_sel_bitwise() == 1); + } + + template + static inline auto compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + const auto is_operation = View(in._bitwise_sel()); + const auto is_table_entry = View(in._precomputed_sel_bitwise()); + return (is_operation + is_table_entry - is_operation * is_table_entry); + } + + template static inline auto get_const_entities(const AllEntities& in) + { + return get_entities(in); + } + + template static inline auto get_nonconst_entities(AllEntities& in) + { + return get_entities(in); + } + + template static inline auto get_entities(AllEntities&& in) + { + return std::forward_as_tuple(in._lookup_bitw_byte_operations_inv(), + in._lookup_bitw_byte_operations_counts(), + in._bitwise_sel(), + in._precomputed_sel_bitwise(), + in._bitwise_op_id(), + in._bitwise_ia_byte(), + in._bitwise_ib_byte(), + in._bitwise_ic_byte(), + in._precomputed_bitwise_op_id(), + in._precomputed_bitwise_input_a(), + in._precomputed_bitwise_input_b(), + in._precomputed_bitwise_output()); + } +}; + +template +class lookup_bitw_byte_operations_relation + : public GenericLookupRelation { + public: + static constexpr std::string_view NAME = "LOOKUP_BITW_BYTE_OPERATIONS"; +}; +template +using lookup_bitw_byte_operations = GenericLookup; + +} // namespace bb::avm2 \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/bitwise.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/bitwise.cpp new file mode 100644 index 000000000000..2bf39697ab8d --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/bitwise.cpp @@ -0,0 +1,55 @@ +#include "barretenberg/vm2/simulation/bitwise.hpp" + +#include + +#include "barretenberg/numeric/uint256/uint256.hpp" +#include "barretenberg/vm2/common/memory_types.hpp" + +namespace bb::avm2::simulation { + +uint128_t Bitwise::and_op(MemoryTag tag, const uint128_t& a, const uint128_t& b) +{ + const uint128_t c = a & b; + + events.emit({ + .operation = BitwiseOperation::AND, + .tag = tag, + .a = a, + .b = b, + .res = c, + }); + + return c; +} + +uint128_t Bitwise::or_op(MemoryTag tag, const uint128_t& a, const uint128_t& b) +{ + const uint128_t c = a | b; + + events.emit({ + .operation = BitwiseOperation::OR, + .tag = tag, + .a = a, + .b = b, + .res = c, + }); + + return c; +} + +uint128_t Bitwise::xor_op(MemoryTag tag, const uint128_t& a, const uint128_t& b) +{ + const uint128_t c = a ^ b; + + events.emit({ + .operation = BitwiseOperation::XOR, + .tag = tag, + .a = a, + .b = b, + .res = c, + }); + + return c; +} + +} // namespace bb::avm2::simulation \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/bitwise.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/bitwise.hpp new file mode 100644 index 000000000000..3e9217d7a271 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/bitwise.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include + +#include "barretenberg/vm2/common/memory_types.hpp" +#include "barretenberg/vm2/simulation/context.hpp" +#include "barretenberg/vm2/simulation/events/bitwise_event.hpp" +#include "barretenberg/vm2/simulation/events/event_emitter.hpp" +#include "barretenberg/vm2/simulation/memory.hpp" + +namespace bb::avm2::simulation { + +// TODO(fcarreiro): think if it makes sense to have memory types like in TS with implicit tag +class BitwiseInterface { + public: + virtual ~BitwiseInterface() = default; + virtual uint128_t and_op(MemoryTag tag, const uint128_t& a, const uint128_t& b) = 0; + virtual uint128_t or_op(MemoryTag tag, const uint128_t& a, const uint128_t& b) = 0; + virtual uint128_t xor_op(MemoryTag tag, const uint128_t& a, const uint128_t& b) = 0; +}; + +class Bitwise : public BitwiseInterface { + public: + Bitwise(EventEmitterInterface& event_emitter) + : events(event_emitter) + {} + + // Operands are expected to be direct. + uint128_t and_op(MemoryTag tag, const uint128_t& a, const uint128_t& b) override; + uint128_t or_op(MemoryTag tag, const uint128_t& a, const uint128_t& b) override; + uint128_t xor_op(MemoryTag tag, const uint128_t& a, const uint128_t& b) override; + + private: + // TODO: Use deduplicating events + consider (see bottom paragraph of bitwise.pil) a further deduplocation + // when some inputs are prefixes of another ones (with a bigger tag). + EventEmitterInterface& events; +}; + +} // namespace bb::avm2::simulation \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/events/bitwise_event.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/events/bitwise_event.hpp new file mode 100644 index 000000000000..0be0861bb312 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/events/bitwise_event.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "barretenberg/vm2/common/constants.hpp" +#include "barretenberg/vm2/common/memory_types.hpp" + +#include + +namespace bb::avm2::simulation { + +struct BitwiseEvent { + BitwiseOperation operation; + MemoryTag tag; + uint128_t a; + uint128_t b; + uint128_t res; +}; + +} // namespace bb::avm2::simulation \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/events/events_container.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/events/events_container.hpp index cf91d0e29065..e34a3ba7278c 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/events/events_container.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/events/events_container.hpp @@ -3,6 +3,7 @@ #include "barretenberg/vm2/simulation/events/address_derivation_event.hpp" #include "barretenberg/vm2/simulation/events/addressing_event.hpp" #include "barretenberg/vm2/simulation/events/alu_event.hpp" +#include "barretenberg/vm2/simulation/events/bitwise_event.hpp" #include "barretenberg/vm2/simulation/events/bytecode_events.hpp" #include "barretenberg/vm2/simulation/events/class_id_derivation_event.hpp" #include "barretenberg/vm2/simulation/events/event_emitter.hpp" @@ -16,6 +17,7 @@ namespace bb::avm2::simulation { struct EventsContainer { EventEmitterInterface::Container execution; EventEmitterInterface::Container alu; + EventEmitterInterface::Container bitwise; EventEmitterInterface::Container memory; EventEmitterInterface::Container addressing; EventEmitterInterface::Container bytecode_retrieval; diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_bitwise.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_bitwise.hpp new file mode 100644 index 000000000000..17c64334e1ee --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_bitwise.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include "barretenberg/vm2/simulation/bitwise.hpp" + +namespace bb::avm2::simulation { + +class MockBitwise : public BitwiseInterface { + public: + // https://google.github.io/googletest/gmock_cook_book.html#making-the-compilation-faster + MockBitwise(); + ~MockBitwise() override; + + MOCK_METHOD(uint128_t, and_op, (MemoryTag tag, const uint128_t& a, const uint128_t& b), (override)); + MOCK_METHOD(uint128_t, or_op, (MemoryTag tag, const uint128_t& a, const uint128_t& b), (override)); + MOCK_METHOD(uint128_t, xor_op, (MemoryTag tag, const uint128_t& a, const uint128_t& b), (override)); +}; + +} // namespace bb::avm2::simulation \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_bitwise.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_bitwise.test.cpp new file mode 100644 index 000000000000..157703a85dbf --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_bitwise.test.cpp @@ -0,0 +1,9 @@ +// This is not a test file but we need to use .test.cpp so that it is not included in non-test builds. +#include "barretenberg/vm2/simulation/testing/mock_bitwise.hpp" + +namespace bb::avm2::simulation { + +MockBitwise::MockBitwise() = default; +MockBitwise::~MockBitwise() = default; + +} // namespace bb::avm2::simulation \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp index 29b3c3bbe698..ea27bc4415ff 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp @@ -12,6 +12,7 @@ #include "barretenberg/vm2/simulation/events/address_derivation_event.hpp" #include "barretenberg/vm2/simulation/events/addressing_event.hpp" #include "barretenberg/vm2/simulation/events/alu_event.hpp" +#include "barretenberg/vm2/simulation/events/bitwise_event.hpp" #include "barretenberg/vm2/simulation/events/bytecode_events.hpp" #include "barretenberg/vm2/simulation/events/class_id_derivation_event.hpp" #include "barretenberg/vm2/simulation/events/event_emitter.hpp" @@ -48,6 +49,7 @@ template EventsContainer AvmSimulationHelper::simulate_with_setting { typename S::template DefaultEventEmitter execution_emitter; typename S::template DefaultEventEmitter alu_emitter; + typename S::template DefaultEventEmitter bitwise_emitter; typename S::template DefaultEventEmitter memory_emitter; typename S::template DefaultEventEmitter addressing_emitter; typename S::template DefaultEventEmitter bytecode_retrieval_emitter; @@ -86,6 +88,7 @@ template EventsContainer AvmSimulationHelper::simulate_with_setting return { execution_emitter.dump_events(), alu_emitter.dump_events(), + bitwise_emitter.dump_events(), memory_emitter.dump_events(), addressing_emitter.dump_events(), bytecode_retrieval_emitter.dump_events(), diff --git a/barretenberg/cpp/src/barretenberg/vm2/testing/macros.hpp b/barretenberg/cpp/src/barretenberg/vm2/testing/macros.hpp index b7db1dc20978..9804d98fd095 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/testing/macros.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/testing/macros.hpp @@ -9,3 +9,5 @@ } catch (const std::exception& e) { \ EXPECT_THAT(e.what(), testing::ContainsRegex(expectedMessage)); \ } + +#define ROW_FIELD_EQ(row_id, field_name, expression) Field(#field_name, &row_id::field_name, expression) diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/alu_trace.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/alu_trace.test.cpp index cce74181f3e5..924b811c8889 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/tracegen/alu_trace.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/alu_trace.test.cpp @@ -5,6 +5,7 @@ #include "barretenberg/vm2/generated/flavor_settings.hpp" #include "barretenberg/vm2/generated/full_row.hpp" +#include "barretenberg/vm2/testing/macros.hpp" #include "barretenberg/vm2/tracegen/alu_trace.hpp" #include "barretenberg/vm2/tracegen/test_trace_container.hpp" @@ -32,14 +33,14 @@ TEST(AvmTraceGenAluTest, TraceGeneration) EXPECT_THAT(trace.as_rows(), ElementsAre( // Only one row. - AllOf(Field(&R::alu_op, static_cast(AluOperation::ADD)), - Field(&R::alu_sel_op_add, 1), - Field(&R::alu_ia_addr, 0), - Field(&R::alu_ib_addr, 1), - Field(&R::alu_dst_addr, 2), - Field(&R::alu_ia, 1), - Field(&R::alu_ib, 2), - Field(&R::alu_ic, 3)))); + AllOf(ROW_FIELD_EQ(R, alu_op, static_cast(AluOperation::ADD)), + ROW_FIELD_EQ(R, alu_sel_op_add, 1), + ROW_FIELD_EQ(R, alu_ia_addr, 0), + ROW_FIELD_EQ(R, alu_ib_addr, 1), + ROW_FIELD_EQ(R, alu_dst_addr, 2), + ROW_FIELD_EQ(R, alu_ia, 1), + ROW_FIELD_EQ(R, alu_ib, 2), + ROW_FIELD_EQ(R, alu_ic, 3)))); } } // namespace diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/bitwise_trace.cpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/bitwise_trace.cpp new file mode 100644 index 000000000000..8977e89b7faa --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/bitwise_trace.cpp @@ -0,0 +1,62 @@ +#include "barretenberg/vm2/tracegen/bitwise_trace.hpp" + +#include +#include +#include +#include + +#include "barretenberg/vm2/common/memory_types.hpp" +#include "barretenberg/vm2/simulation/events/bitwise_event.hpp" +#include "barretenberg/vm2/simulation/events/event_emitter.hpp" + +namespace bb::avm2::tracegen { + +void BitwiseTraceBuilder::process(const simulation::EventEmitterInterface::Container& events, + TraceContainer& trace) +{ + using C = Column; + + // We activate last selector in the extra pre-pended row (to support shift) + trace.set(C::bitwise_last, 0, 1); + + uint32_t row = 1; + for (const auto& event : events) { + const auto start_ctr = integral_tag_length(event.tag); + + // We start with full inputs and output and we shift + // them byte-per-byte to the right. + uint128_t input_a = static_cast(event.a); + uint128_t input_b = static_cast(event.b); + uint128_t output_c = static_cast(event.res); + + // Note that for tag U1, we take only one bit. This is correctly + // captured below since input_a/b and output_c are each a single bit + // and the byte mask correctly extracts it. + const uint128_t mask_low_byte = (1 << 8) - 1; + + for (int ctr = start_ctr; ctr > 0; ctr--) { + trace.set(row, + { { { C::bitwise_op_id, static_cast(event.operation) }, + { C::bitwise_acc_ia, uint256_t::from_uint128(input_a) }, + { C::bitwise_acc_ib, uint256_t::from_uint128(input_b) }, + { C::bitwise_acc_ic, uint256_t::from_uint128(output_c) }, + { C::bitwise_ia_byte, uint256_t::from_uint128(input_a & mask_low_byte) }, + { C::bitwise_ib_byte, uint256_t::from_uint128(input_b & mask_low_byte) }, + { C::bitwise_ic_byte, uint256_t::from_uint128(output_c & mask_low_byte) }, + { C::bitwise_tag, static_cast(event.tag) }, + { C::bitwise_ctr, ctr }, + { C::bitwise_ctr_inv, ctr != 0 ? MemoryValue(ctr).invert() : 1 }, + { C::bitwise_ctr_min_one_inv, ctr != 1 ? MemoryValue(ctr - 1).invert() : 1 }, + { C::bitwise_last, static_cast(ctr == 1) }, + { C::bitwise_sel, static_cast(ctr != 0) }, + { C::bitwise_start, static_cast(ctr == start_ctr) } } }); + + input_a >>= 8; + input_b >>= 8; + output_c >>= 8; + row++; + } + } +} + +} // namespace bb::avm2::tracegen \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/bitwise_trace.hpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/bitwise_trace.hpp new file mode 100644 index 000000000000..0972a5d2b85a --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/bitwise_trace.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "barretenberg/vm2/generated/columns.hpp" +#include "barretenberg/vm2/simulation/events/bitwise_event.hpp" +#include "barretenberg/vm2/simulation/events/event_emitter.hpp" +#include "barretenberg/vm2/tracegen/trace_container.hpp" + +namespace bb::avm2::tracegen { + +class BitwiseTraceBuilder final { + public: + void process(const simulation::EventEmitterInterface::Container& events, + TraceContainer& trace); +}; + +} // namespace bb::avm2::tracegen \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/bitwise_trace.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/bitwise_trace.test.cpp new file mode 100644 index 000000000000..0753f3fd6f37 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/bitwise_trace.test.cpp @@ -0,0 +1,164 @@ +#include +#include + +#include + +#include "barretenberg/vm2/generated/flavor_settings.hpp" +#include "barretenberg/vm2/generated/full_row.hpp" +#include "barretenberg/vm2/testing/macros.hpp" +#include "barretenberg/vm2/tracegen/bitwise_trace.hpp" +#include "barretenberg/vm2/tracegen/test_trace_container.hpp" + +namespace bb::avm2::tracegen { +namespace { + +using testing::ElementsAre; +using testing::Field; + +using R = TestTraceContainer::Row; +using FF = R::FF; + +TEST(AvmTraceGenBitwiseTest, U1And) +{ + TestTraceContainer trace; + BitwiseTraceBuilder builder; + + builder.process( + { + { + .operation = BitwiseOperation::AND, + .tag = MemoryTag::U1, + .a = 0, + .b = 1, + .res = 0, + }, + }, + trace); + + EXPECT_EQ(trace.as_rows().size(), 2); + + EXPECT_THAT(trace.as_rows(), + ElementsAre(AllOf(ROW_FIELD_EQ(R, bitwise_op_id, 0), + ROW_FIELD_EQ(R, bitwise_acc_ia, 0), + ROW_FIELD_EQ(R, bitwise_acc_ib, 0), + ROW_FIELD_EQ(R, bitwise_acc_ic, 0), + ROW_FIELD_EQ(R, bitwise_ia_byte, 0), + ROW_FIELD_EQ(R, bitwise_ib_byte, 0), + ROW_FIELD_EQ(R, bitwise_ic_byte, 0), + ROW_FIELD_EQ(R, bitwise_tag, 0), + ROW_FIELD_EQ(R, bitwise_ctr, 0), + ROW_FIELD_EQ(R, bitwise_ctr_inv, 0), + ROW_FIELD_EQ(R, bitwise_ctr_min_one_inv, 0), + ROW_FIELD_EQ(R, bitwise_last, 1), + ROW_FIELD_EQ(R, bitwise_sel, 0), + ROW_FIELD_EQ(R, bitwise_start, 0)), + AllOf(ROW_FIELD_EQ(R, bitwise_op_id, static_cast(BitwiseOperation::AND)), + ROW_FIELD_EQ(R, bitwise_acc_ia, 0), + ROW_FIELD_EQ(R, bitwise_acc_ib, 1), + ROW_FIELD_EQ(R, bitwise_acc_ic, 0), + ROW_FIELD_EQ(R, bitwise_ia_byte, 0), + ROW_FIELD_EQ(R, bitwise_ib_byte, 1), + ROW_FIELD_EQ(R, bitwise_ic_byte, 0), + ROW_FIELD_EQ(R, bitwise_tag, static_cast(MemoryTag::U1)), + ROW_FIELD_EQ(R, bitwise_ctr, 1), + ROW_FIELD_EQ(R, bitwise_ctr_inv, 1), + ROW_FIELD_EQ(R, bitwise_ctr_min_one_inv, 1), + ROW_FIELD_EQ(R, bitwise_last, 1), + ROW_FIELD_EQ(R, bitwise_sel, 1), + ROW_FIELD_EQ(R, bitwise_start, 1)))); +} + +TEST(AvmTraceGenBitwiseTest, U32And) +{ + TestTraceContainer trace; + BitwiseTraceBuilder builder; + + builder.process( + { + { + .operation = BitwiseOperation::AND, + .tag = MemoryTag::U32, + .a = 0x52488425, + .b = 0xC684486C, + .res = 0x42000024, + }, + }, + trace); + + EXPECT_EQ(trace.as_rows().size(), 5); + + EXPECT_THAT(trace.as_rows(), + ElementsAre(AllOf(ROW_FIELD_EQ(R, bitwise_op_id, 0), + ROW_FIELD_EQ(R, bitwise_acc_ia, 0), + ROW_FIELD_EQ(R, bitwise_acc_ib, 0), + ROW_FIELD_EQ(R, bitwise_acc_ic, 0), + ROW_FIELD_EQ(R, bitwise_ia_byte, 0), + ROW_FIELD_EQ(R, bitwise_ib_byte, 0), + ROW_FIELD_EQ(R, bitwise_ic_byte, 0), + ROW_FIELD_EQ(R, bitwise_tag, 0), + ROW_FIELD_EQ(R, bitwise_ctr, 0), + ROW_FIELD_EQ(R, bitwise_ctr_inv, 0), + ROW_FIELD_EQ(R, bitwise_ctr_min_one_inv, 0), + ROW_FIELD_EQ(R, bitwise_last, 1), + ROW_FIELD_EQ(R, bitwise_sel, 0), + ROW_FIELD_EQ(R, bitwise_start, 0)), + AllOf(ROW_FIELD_EQ(R, bitwise_op_id, static_cast(BitwiseOperation::AND)), + ROW_FIELD_EQ(R, bitwise_acc_ia, 0x52488425), + ROW_FIELD_EQ(R, bitwise_acc_ib, 0xC684486C), + ROW_FIELD_EQ(R, bitwise_acc_ic, 0x42000024), + ROW_FIELD_EQ(R, bitwise_ia_byte, 0x25), + ROW_FIELD_EQ(R, bitwise_ib_byte, 0x6C), + ROW_FIELD_EQ(R, bitwise_ic_byte, 0x24), + ROW_FIELD_EQ(R, bitwise_tag, static_cast(MemoryTag::U32)), + ROW_FIELD_EQ(R, bitwise_ctr, 4), + ROW_FIELD_EQ(R, bitwise_ctr_inv, FF(4).invert()), + ROW_FIELD_EQ(R, bitwise_ctr_min_one_inv, FF(3).invert()), + ROW_FIELD_EQ(R, bitwise_last, 0), + ROW_FIELD_EQ(R, bitwise_sel, 1), + ROW_FIELD_EQ(R, bitwise_start, 1)), + AllOf(ROW_FIELD_EQ(R, bitwise_op_id, static_cast(BitwiseOperation::AND)), + ROW_FIELD_EQ(R, bitwise_acc_ia, 0x524884), + ROW_FIELD_EQ(R, bitwise_acc_ib, 0xC68448), + ROW_FIELD_EQ(R, bitwise_acc_ic, 0x420000), + ROW_FIELD_EQ(R, bitwise_ia_byte, 0x84), + ROW_FIELD_EQ(R, bitwise_ib_byte, 0x48), + ROW_FIELD_EQ(R, bitwise_ic_byte, 0x00), + ROW_FIELD_EQ(R, bitwise_tag, static_cast(MemoryTag::U32)), + ROW_FIELD_EQ(R, bitwise_ctr, 3), + ROW_FIELD_EQ(R, bitwise_ctr_inv, FF(3).invert()), + ROW_FIELD_EQ(R, bitwise_ctr_min_one_inv, FF(2).invert()), + ROW_FIELD_EQ(R, bitwise_last, 0), + ROW_FIELD_EQ(R, bitwise_sel, 1), + ROW_FIELD_EQ(R, bitwise_start, 0)), + AllOf(ROW_FIELD_EQ(R, bitwise_op_id, static_cast(BitwiseOperation::AND)), + ROW_FIELD_EQ(R, bitwise_acc_ia, 0x5248), + ROW_FIELD_EQ(R, bitwise_acc_ib, 0xC684), + ROW_FIELD_EQ(R, bitwise_acc_ic, 0x4200), + ROW_FIELD_EQ(R, bitwise_ia_byte, 0x48), + ROW_FIELD_EQ(R, bitwise_ib_byte, 0x84), + ROW_FIELD_EQ(R, bitwise_ic_byte, 0x00), + ROW_FIELD_EQ(R, bitwise_tag, static_cast(MemoryTag::U32)), + ROW_FIELD_EQ(R, bitwise_ctr, 2), + ROW_FIELD_EQ(R, bitwise_ctr_inv, FF(2).invert()), + ROW_FIELD_EQ(R, bitwise_ctr_min_one_inv, 1), + ROW_FIELD_EQ(R, bitwise_last, 0), + ROW_FIELD_EQ(R, bitwise_sel, 1), + ROW_FIELD_EQ(R, bitwise_start, 0)), + AllOf(ROW_FIELD_EQ(R, bitwise_op_id, static_cast(BitwiseOperation::AND)), + ROW_FIELD_EQ(R, bitwise_acc_ia, 0x52), + ROW_FIELD_EQ(R, bitwise_acc_ib, 0xC6), + ROW_FIELD_EQ(R, bitwise_acc_ic, 0x42), + ROW_FIELD_EQ(R, bitwise_ia_byte, 0x52), + ROW_FIELD_EQ(R, bitwise_ib_byte, 0xC6), + ROW_FIELD_EQ(R, bitwise_ic_byte, 0x42), + ROW_FIELD_EQ(R, bitwise_tag, static_cast(MemoryTag::U32)), + ROW_FIELD_EQ(R, bitwise_ctr, 1), + ROW_FIELD_EQ(R, bitwise_ctr_inv, 1), + ROW_FIELD_EQ(R, bitwise_ctr_min_one_inv, 1), + ROW_FIELD_EQ(R, bitwise_last, 1), + ROW_FIELD_EQ(R, bitwise_sel, 1), + ROW_FIELD_EQ(R, bitwise_start, 0)))); +} + +} // namespace +} // namespace bb::avm2::tracegen \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_into_indexed_by_clk.hpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_into_indexed_by_clk.hpp new file mode 100644 index 000000000000..8cba38db1d5c --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_into_indexed_by_clk.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include "barretenberg/vm2/tracegen/lib/lookup_builder.hpp" + +namespace bb::avm2::tracegen { + +/** + * Lookup trace builder used for lookups that lookup into tuples which are indexed by clk, + * i.e., whose first tuple element is clk column. + * For instance, with a tuple of size 1 we have the basic 8 or 16 bit range checks. + * Example: `sel { dyn_diff } in precomputed.sel_range_16 {precomputed.clk };` + * An example with a size 2 tuple (p denotes precomputed): + * start {tag, ctr} in p.sel_integral_tag {p.clk, p.integral_tag_length}; + */ +template class LookupIntoIndexedByClk : public BaseLookupTraceBuilder { + private: + // This is an efficient implementation of indexing into the precomputed table. + uint32_t find_in_dst(const std::array& tup) const override + { + return static_cast(tup[0]); + } +}; + +} // namespace bb::avm2::tracegen diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_into_power_of_2.hpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_into_power_of_2.hpp deleted file mode 100644 index 402b7ac9b1de..000000000000 --- a/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_into_power_of_2.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include - -#include "barretenberg/vm2/tracegen/lib/lookup_builder.hpp" - -namespace bb::avm2::tracegen { - -template class LookupIntoPowerOf2 : public BaseLookupTraceBuilder { - private: - // This is an efficient implementation of indexing into the precomputed table. - uint32_t find_in_dst(const std::array& tup) const override - { - // clk/row-index is the exponent for power_of_2 (2^clk) - const auto& [clk, _] = tup; - return static_cast(clk); - } -}; - -} // namespace bb::avm2::tracegen diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_into_range.hpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_into_range.hpp deleted file mode 100644 index 8c8583f01f80..000000000000 --- a/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_into_range.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include - -#include "barretenberg/vm2/tracegen/lib/lookup_builder.hpp" - -namespace bb::avm2::tracegen { - -/** - * Lookup trace builder used for lookups that lookup into the clk column, only changing based on a selector. - * Like basic 8 or 16 bit range checks. Example: `sel { dyn_diff } in precomputed.sel_range_16 { precomputed.clk };` - */ -template class LookupIntoRange : public BaseLookupTraceBuilder { - private: - // This is an efficient implementation of indexing into the precomputed table. - uint32_t find_in_dst(const std::array& tup) const override - { - const auto& [clk] = tup; - return static_cast(clk); - } -}; - -} // namespace bb::avm2::tracegen diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_into_unary.hpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_into_unary.hpp deleted file mode 100644 index 0c9438c87ba8..000000000000 --- a/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_into_unary.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include - -#include "barretenberg/vm2/tracegen/lib/lookup_builder.hpp" - -namespace bb::avm2::tracegen { - -template class LookupIntoUnary : public BaseLookupTraceBuilder { - private: - // This is an efficient implementation of indexing into the precomputed table. - uint32_t find_in_dst(const std::array& tup) const override - { - // clk is the index - const auto& [clk, _] = tup; - return static_cast(clk); - } -}; - -} // namespace bb::avm2::tracegen diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/precomputed_trace.cpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/precomputed_trace.cpp index 45f9eef8d8b0..77c7a0485dbd 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/tracegen/precomputed_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/precomputed_trace.cpp @@ -1,10 +1,12 @@ #include "barretenberg/vm2/tracegen/precomputed_trace.hpp" -#include "barretenberg/vm2/common/constants.hpp" #include #include #include +#include "barretenberg/vm2/common/constants.hpp" +#include "barretenberg/vm2/common/memory_types.hpp" + namespace bb::avm2::tracegen { void PrecomputedTraceBuilder::process_misc(TraceContainer& trace) @@ -38,29 +40,30 @@ void PrecomputedTraceBuilder::process_bitwise(TraceContainer& trace) // - input_a: bits 8...15 // - op_id: bits 16... // In other words, the first 256*256 rows are for op_id 0. Next are for op_id 1, followed by op_id 2. - auto row_from_inputs = [](uint32_t op_id, uint32_t input_a, uint32_t input_b) -> uint32_t { - return (op_id << 16) | (input_a << 8) | input_b; + auto row_from_inputs = [](BitwiseOperation op_id, uint32_t input_a, uint32_t input_b) -> uint32_t { + return (static_cast(op_id) << 16) | (input_a << 8) | input_b; }; - auto compute_operation = [](int op_id, uint32_t a, uint32_t b) -> uint32_t { + auto compute_operation = [](BitwiseOperation op_id, uint32_t a, uint32_t b) -> uint32_t { switch (op_id) { - case 0: + case BitwiseOperation::AND: return a & b; - case 1: + case BitwiseOperation::OR: return a | b; - case 2: + case BitwiseOperation::XOR: return a ^ b; - default: - return 0; } + + assert(false && "This should not happen"); + return 0; // Should never happen. To please the compiler. }; - for (const auto op_id : { /*AND*/ 0, /*OR*/ 1, /*XOR*/ 2 }) { + for (const auto op_id : { BitwiseOperation::AND, BitwiseOperation::OR, BitwiseOperation::XOR }) { for (uint32_t a = 0; a < 256; a++) { for (uint32_t b = 0; b < 256; b++) { - trace.set(row_from_inputs(static_cast(op_id), a, b), + trace.set(row_from_inputs(op_id, a, b), { { { C::precomputed_sel_bitwise, 1 }, - { C::precomputed_bitwise_op_id, op_id }, + { C::precomputed_bitwise_op_id, static_cast(op_id) }, { C::precomputed_bitwise_input_a, FF(a) }, { C::precomputed_bitwise_input_b, FF(b) }, { C::precomputed_bitwise_output, FF(compute_operation(op_id, a, b)) }, @@ -158,4 +161,20 @@ void PrecomputedTraceBuilder::process_sha256_round_constants(TraceContainer& tra } } +void PrecomputedTraceBuilder::process_integral_tag_length(TraceContainer& trace) +{ + using C = Column; + using bb::avm2::MemoryTag; + + // Column number corresponds to MemoryTag enum value. + const auto integral_tags = { MemoryTag::U1, MemoryTag::U8, MemoryTag::U16, + MemoryTag::U32, MemoryTag::U64, MemoryTag::U128 }; + + for (const auto& tag : integral_tags) { + trace.set(static_cast(tag), + { { { C::precomputed_sel_integral_tag, 1 }, + { C::precomputed_integral_tag_length, integral_tag_length(tag) } } }); + } +} + } // namespace bb::avm2::tracegen diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/precomputed_trace.hpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/precomputed_trace.hpp index 81e2e68792fd..c7424592f3b8 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/tracegen/precomputed_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/precomputed_trace.hpp @@ -15,6 +15,7 @@ class PrecomputedTraceBuilder final { void process_power_of_2(TraceContainer& trace); void process_unary(TraceContainer& trace); void process_sha256_round_constants(TraceContainer& trace); + void process_integral_tag_length(TraceContainer& trace); }; } // namespace bb::avm2::tracegen diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp index f1153dc6db36..51c4f8e4a265 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp @@ -14,6 +14,7 @@ #include "barretenberg/vm2/generated/columns.hpp" #include "barretenberg/vm2/generated/flavor.hpp" #include "barretenberg/vm2/generated/relations/lookups_bc_decomposition.hpp" +#include "barretenberg/vm2/generated/relations/lookups_bitwise.hpp" #include "barretenberg/vm2/generated/relations/lookups_execution.hpp" #include "barretenberg/vm2/generated/relations/lookups_range_check.hpp" #include "barretenberg/vm2/generated/relations/lookups_sha256.hpp" @@ -24,10 +25,8 @@ #include "barretenberg/vm2/tracegen/lib/interaction_builder.hpp" #include "barretenberg/vm2/tracegen/lib/lookup_builder.hpp" #include "barretenberg/vm2/tracegen/lib/lookup_into_bitwise.hpp" -#include "barretenberg/vm2/tracegen/lib/lookup_into_power_of_2.hpp" -#include "barretenberg/vm2/tracegen/lib/lookup_into_range.hpp" +#include "barretenberg/vm2/tracegen/lib/lookup_into_indexed_by_clk.hpp" #include "barretenberg/vm2/tracegen/lib/lookup_into_sha256_params.hpp" -#include "barretenberg/vm2/tracegen/lib/lookup_into_unary.hpp" #include "barretenberg/vm2/tracegen/lib/permutation_builder.hpp" #include "barretenberg/vm2/tracegen/precomputed_trace.hpp" #include "barretenberg/vm2/tracegen/sha256_trace.hpp" @@ -59,6 +58,8 @@ auto build_precomputed_columns_jobs(TraceContainer& trace) AVM_TRACK_TIME("tracegen/precomputed/unary", precomputed_builder.process_unary(trace)); AVM_TRACK_TIME("tracegen/precomputed/sha256_round_constants", precomputed_builder.process_sha256_round_constants(trace)); + AVM_TRACK_TIME("tracegen/precomputed/integral_tag_length", + precomputed_builder.process_integral_tag_length(trace)); }, }; } @@ -185,17 +186,19 @@ TraceContainer AvmTraceGenHelper::generate_trace(EventsContainer&& events) std::make_unique>(), std::make_unique>(), std::make_unique>(), - std::make_unique>(), - std::make_unique>(), - std::make_unique>(), - std::make_unique>(), - std::make_unique>(), - std::make_unique>(), - std::make_unique>(), - std::make_unique>(), - std::make_unique>(), - std::make_unique>(), - std::make_unique>(), + std::make_unique>(), + std::make_unique>(), + std::make_unique>(), + std::make_unique>(), + std::make_unique>(), + std::make_unique>(), + std::make_unique>(), + std::make_unique>(), + std::make_unique>(), + std::make_unique>(), + std::make_unique>(), + std::make_unique>(), + std::make_unique>(), std::make_unique>()); AVM_TRACK_TIME("tracegen/interactions", parallel_for(jobs_interactions.size(), [&](size_t i) { jobs_interactions[i]->process(trace); })); diff --git a/bb-pilcom/bb-pil-backend/templates/full_row.cpp.hbs b/bb-pilcom/bb-pil-backend/templates/full_row.cpp.hbs index 5d1816c74006..0d96d4df8e50 100644 --- a/bb-pilcom/bb-pil-backend/templates/full_row.cpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/full_row.cpp.hbs @@ -6,7 +6,6 @@ namespace bb::{{snakeCase name}} { template std::ostream& operator<<(std::ostream& os, [[maybe_unused]] AvmFullRow const& row) { - assert(false); // unsupported. return os; } diff --git a/bb-pilcom/bootstrap.sh b/bb-pilcom/bootstrap.sh index 2b71dedd99f0..efd62bd6f086 100755 --- a/bb-pilcom/bootstrap.sh +++ b/bb-pilcom/bootstrap.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash - -cargo build --release +current_dir="$(dirname "$(readlink -f "$0")")" +cargo build --manifest-path=$current_dir/Cargo.toml --release