From d7edd24e76a2ab87ac490c8c97f0c344190f646b Mon Sep 17 00:00:00 2001 From: Facundo Date: Mon, 19 Aug 2024 12:10:32 +0100 Subject: [PATCH] refactor(avm): kernel trace and finalization (#8049) The original objective of this PR was to just remove kernel `finalize()` from `trace.cpp`. Other things were done on top but I do not claim to have solved or constrained everything. Something that I realized while working on this: right now gas is broken for SLOAD/SSTORE/UNENCRYPTEDLOG because they still either use SET or take multiple lines (or should). However, if they take multiple lines, we have to move them to their own gadget, and if we do so, then their kernel accesses (1 per item) will make the kernel trace not be 1-1 anymore. So, we might need to rethink this whole trace. ----- PIL * Made kernel trace officially virtual * Moved most constraints, lookups, etc from main to kernel * Changed a few constraints; now we will constrain all rows of the execution trace (this bleeds to "last + 1" using the shifts, on purpose) * Changed some names and added some comments to make it more understandable, but still needs love CPP * Encapsulated kernel finalization in its own finalize * Changed `sel_last` to actually be the last row of the execution trace, as PIL says. (in any case, it's not used now) * Other misc changes: * error reporting in check circuit now only reports first failure for each subrelation (otherwise rows were spammed, but it didn't mean that the actual row didn't satisfy it, just that the accumulator was already "dirty") * Moved execution hints to their own hpp --- barretenberg/cpp/pil/avm/gas.pil | 3 +- barretenberg/cpp/pil/avm/kernel.pil | 167 ++++- barretenberg/cpp/pil/avm/main.pil | 112 --- .../vm/avm/generated/circuit_builder.cpp | 48 +- .../barretenberg/vm/avm/generated/flavor.cpp | 652 +++++++++--------- .../barretenberg/vm/avm/generated/flavor.hpp | 18 +- .../vm/avm/generated/full_row.cpp | 92 +-- .../vm/avm/generated/full_row.hpp | 46 +- .../barretenberg/vm/avm/generated/prover.cpp | 1 - .../vm/avm/generated/relations/kernel.hpp | 390 ++++++++++- .../relations/kernel_output_lookup.hpp | 28 +- .../relations/lookup_into_kernel.hpp | 16 +- .../vm/avm/generated/relations/main.hpp | 443 ++---------- .../vm/avm/generated/verifier.cpp | 17 +- .../vm/avm/tests/execution.test.cpp | 114 +-- .../vm/avm/tests/helpers.test.cpp | 1 - .../barretenberg/vm/avm/tests/kernel.test.cpp | 40 +- .../src/barretenberg/vm/avm/trace/common.hpp | 160 ----- .../vm/avm/trace/execution_hints.hpp | 164 +++++ .../vm/avm/trace/finalization.hpp | 39 ++ .../vm/avm/trace/kernel_trace.cpp | 323 +++++++-- .../vm/avm/trace/kernel_trace.hpp | 86 ++- .../barretenberg/vm/avm/trace/mem_trace.cpp | 9 - .../barretenberg/vm/avm/trace/mem_trace.hpp | 2 +- .../src/barretenberg/vm/avm/trace/trace.cpp | 286 ++------ .../src/barretenberg/vm/avm/trace/trace.hpp | 25 +- .../templates/circuit_builder.cpp.hbs | 13 +- 27 files changed, 1731 insertions(+), 1564 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/vm/avm/trace/execution_hints.hpp create mode 100644 barretenberg/cpp/src/barretenberg/vm/avm/trace/finalization.hpp diff --git a/barretenberg/cpp/pil/avm/gas.pil b/barretenberg/cpp/pil/avm/gas.pil index ec344c393ee..ef680830f78 100644 --- a/barretenberg/cpp/pil/avm/gas.pil +++ b/barretenberg/cpp/pil/avm/gas.pil @@ -1,6 +1,7 @@ include "fixed/gas.pil"; -// Gas is a "virtual" trace. Things are only in a separate file for modularity. +// This is a "virtual" trace. Things are only in a separate file for modularity. +// That is, this trace is expected to be in 1-1 relation with the main trace. // However, the columns and relations are set on the "main" namespace. namespace main(256); //===== GAS ACCOUNTING ======================================================== diff --git a/barretenberg/cpp/pil/avm/kernel.pil b/barretenberg/cpp/pil/avm/kernel.pil index 9cc48c6da6c..9763bcaaa42 100644 --- a/barretenberg/cpp/pil/avm/kernel.pil +++ b/barretenberg/cpp/pil/avm/kernel.pil @@ -1,9 +1,14 @@ -include "main.pil"; include "constants_gen.pil"; -namespace kernel(256); - pol public kernel_inputs; +// The kernel trace is divided into two parts: +// - A 1-1 virtual trace +// - The public inputs which are looked up from the virtual trace +// This is a "virtual" trace. Things are only in a separate file for modularity. +// That is, this trace is expected to be in 1-1 relation with the main trace. +// However, the columns and relations are set on the "main" namespace. +namespace main(256); + pol public kernel_inputs; pol public kernel_value_out; pol public kernel_side_effect_out; pol public kernel_metadata_out; @@ -12,10 +17,9 @@ namespace kernel(256); pol commit kernel_in_offset; pol commit kernel_out_offset; - // Note: in the future, with some codegen adjustments, this column will not be needed - // as we can just add every entry in the public kernel_inputs to the lookup table - pol commit q_public_input_kernel_add_to_table; - pol commit q_public_input_kernel_out_add_to_table; + // These are selectors for the lookups on the public inputs. + pol commit sel_kernel_inputs; + pol commit sel_kernel_out; // Kernel Outputs // @@ -24,7 +28,8 @@ namespace kernel(256); // Global side effect counter; incremented after each side effect is produced. pol commit side_effect_counter; - // TODO(https://github.com/AztecProtocol/aztec-packages/issues/6465): Must constrain write_offset counters to be less than side effect MAX + // TODO(https://github.com/AztecProtocol/aztec-packages/issues/6465): Must constrain write_offset + // counters to be less than side effect MAX // Current write offsets for each opcode pol commit note_hash_exist_write_offset; pol commit nullifier_exists_write_offset; @@ -39,30 +44,146 @@ namespace kernel(256); pol commit emit_unencrypted_log_write_offset; pol commit emit_l2_to_l1_msg_write_offset; - - pol NOT_LAST = (1 - main.sel_last); - // Constraints to increase the offsets when the opcodes are found #[NOTE_HASH_EXISTS_INC_CONSISTENCY_CHECK] - NOT_LAST * (note_hash_exist_write_offset' - (note_hash_exist_write_offset + main.sel_op_note_hash_exists)) = 0; + sel_execution_row * (note_hash_exist_write_offset' - (note_hash_exist_write_offset + sel_op_note_hash_exists)) = 0; #[EMIT_NOTE_HASH_INC_CONSISTENCY_CHECK] - NOT_LAST * (emit_note_hash_write_offset' - (emit_note_hash_write_offset + main.sel_op_emit_note_hash)) = 0; - // if main.ib is set on op_nullifier_exists, then the nullifier_exists_write_offset will be incremented by 1, otherwise non_exists will be incremented + sel_execution_row * (emit_note_hash_write_offset' - (emit_note_hash_write_offset + sel_op_emit_note_hash)) = 0; + + // if ib is set on op_nullifier_exists, then the nullifier_exists_write_offset + // will be incremented by 1, otherwise non_exists will be incremented. #[NULLIFIER_EXISTS_INC_CONSISTENCY_CHECK] - NOT_LAST * (nullifier_exists_write_offset' - (nullifier_exists_write_offset + (main.sel_op_nullifier_exists * main.ib))) = 0; + sel_execution_row * (nullifier_exists_write_offset' - (nullifier_exists_write_offset + (sel_op_nullifier_exists * ib))) = 0; #[NULLIFIER_NON_EXISTS_INC_CONSISTENCY_CHECK] - NOT_LAST * (nullifier_non_exists_write_offset' - (nullifier_non_exists_write_offset + (main.sel_op_nullifier_exists * (1 - main.ib)))) = 0; + sel_execution_row * (nullifier_non_exists_write_offset' - (nullifier_non_exists_write_offset + (sel_op_nullifier_exists * (1 - ib)))) = 0; + #[EMIT_NULLIFIER_INC_CONSISTENCY_CHECK] - NOT_LAST * (emit_nullifier_write_offset' - (emit_nullifier_write_offset + main.sel_op_emit_nullifier)) = 0; + sel_execution_row * (emit_nullifier_write_offset' - (emit_nullifier_write_offset + sel_op_emit_nullifier)) = 0; + #[L1_TO_L2_MSG_EXISTS_INC_CONSISTENCY_CHECK] - NOT_LAST * (l1_to_l2_msg_exists_write_offset' - (l1_to_l2_msg_exists_write_offset + main.sel_op_l1_to_l2_msg_exists)) = 0; + sel_execution_row * (l1_to_l2_msg_exists_write_offset' - (l1_to_l2_msg_exists_write_offset + sel_op_l1_to_l2_msg_exists)) = 0; + #[EMIT_UNENCRYPTED_LOG_INC_CONSISTENCY_CHECK] - NOT_LAST * (emit_unencrypted_log_write_offset' - (emit_unencrypted_log_write_offset + main.sel_op_emit_unencrypted_log)) = 0; - #[EMIT_L2_TO_L1_MSG_INC_CONSISTENCY_CHECK] - NOT_LAST * (emit_l2_to_l1_msg_write_offset' - (emit_l2_to_l1_msg_write_offset + main.sel_op_emit_l2_to_l1_msg)) = 0; + sel_execution_row * (emit_unencrypted_log_write_offset' - (emit_unencrypted_log_write_offset + sel_op_emit_unencrypted_log)) = 0; + #[EMIT_L2_TO_L1_MSG_INC_CONSISTENCY_CHECK] + sel_execution_row * (emit_l2_to_l1_msg_write_offset' - (emit_l2_to_l1_msg_write_offset + sel_op_emit_l2_to_l1_msg)) = 0; #[SLOAD_INC_CONSISTENCY_CHECK] - NOT_LAST * (sload_write_offset' - (sload_write_offset + main.sel_op_sload)) = 0; + sel_execution_row * (sload_write_offset' - (sload_write_offset + sel_op_sload)) = 0; + #[SSTORE_INC_CONSISTENCY_CHECK] - NOT_LAST * (sstore_write_offset' - (sstore_write_offset + main.sel_op_sstore)) = 0; + sel_execution_row * (sstore_write_offset' - (sstore_write_offset + sel_op_sstore)) = 0; + + //===== KERNEL INPUTS CONSTRAINTS =========================================== + // The general pattern for environment lookups is as follows: + // Each kernel opcode related to some fixed positions in the `public kernel_inputs` polynomial + // We can lookup into a fixed index of this polynomial by including constraints that force the value + // of kernel_in_offset to the value relevant to the given opcode that is active + + // TODO: I think we can replace all these (IN) with a single lookup. + // CONTEXT - ENVIRONMENT + #[ADDRESS_KERNEL] + sel_op_address * (kernel_in_offset - constants.ADDRESS_SELECTOR) = 0; + + #[STORAGE_ADDRESS_KERNEL] + sel_op_storage_address * (kernel_in_offset - constants.STORAGE_ADDRESS_SELECTOR) = 0; + + #[SENDER_KERNEL] + sel_op_sender * (kernel_in_offset - constants.SENDER_SELECTOR) = 0; + + #[FUNCTION_SELECTOR_KERNEL] + sel_op_function_selector * (kernel_in_offset - constants.FUNCTION_SELECTOR_SELECTOR) = 0; + + #[FEE_TRANSACTION_FEE_KERNEL] + sel_op_transaction_fee * (kernel_in_offset - constants.TRANSACTION_FEE_SELECTOR) = 0; + + // CONTEXT - ENVIRONMENT - GLOBALS + #[CHAIN_ID_KERNEL] + sel_op_chain_id * (kernel_in_offset - constants.CHAIN_ID_SELECTOR) = 0; + + #[VERSION_KERNEL] + sel_op_version * (kernel_in_offset - constants.VERSION_SELECTOR) = 0; + + #[BLOCK_NUMBER_KERNEL] + sel_op_block_number * (kernel_in_offset - constants.BLOCK_NUMBER_SELECTOR) = 0; + + #[TIMESTAMP_KERNEL] + sel_op_timestamp * (kernel_in_offset - constants.TIMESTAMP_SELECTOR) = 0; + + #[COINBASE_KERNEL] + sel_op_coinbase * (kernel_in_offset - constants.COINBASE_SELECTOR) = 0; + + // CONTEXT - ENVIRONMENT - GLOBALS - FEES + #[FEE_DA_GAS_KERNEL] + sel_op_fee_per_da_gas * (kernel_in_offset - constants.FEE_PER_DA_GAS_SELECTOR) = 0; + + #[FEE_L2_GAS_KERNEL] + sel_op_fee_per_l2_gas * (kernel_in_offset - constants.FEE_PER_L2_GAS_SELECTOR) = 0; + + // OUTPUTS LOOKUPS + // Constrain the value of kernel_out_offset to be the correct offset for the operation being performed + #[NOTE_HASH_KERNEL_OUTPUT] + sel_op_note_hash_exists * (kernel_out_offset - (constants.START_NOTE_HASH_EXISTS_WRITE_OFFSET + note_hash_exist_write_offset)) = 0; + sel_first * note_hash_exist_write_offset = 0; + + #[EMIT_NOTE_HASH_KERNEL_OUTPUT] + sel_op_emit_note_hash * (kernel_out_offset - (constants.START_EMIT_NOTE_HASH_WRITE_OFFSET + emit_note_hash_write_offset)) = 0; + sel_first * emit_note_hash_write_offset = 0; + + #[NULLIFIER_EXISTS_KERNEL_OUTPUT] + sel_op_nullifier_exists * (kernel_out_offset - ((ib * (constants.START_NULLIFIER_EXISTS_OFFSET + nullifier_exists_write_offset)) + ((1 - ib) * (constants.START_NULLIFIER_NON_EXISTS_OFFSET + nullifier_non_exists_write_offset)))) = 0; + sel_first * nullifier_exists_write_offset = 0; + sel_first * nullifier_non_exists_write_offset = 0; + + #[EMIT_NULLIFIER_KERNEL_OUTPUT] + sel_op_emit_nullifier * (kernel_out_offset - (constants.START_EMIT_NULLIFIER_WRITE_OFFSET + emit_nullifier_write_offset)) = 0; + sel_first * emit_nullifier_write_offset = 0; + + #[L1_TO_L2_MSG_EXISTS_KERNEL_OUTPUT] + sel_op_l1_to_l2_msg_exists * (kernel_out_offset - (constants.START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + l1_to_l2_msg_exists_write_offset)) = 0; + sel_first * l1_to_l2_msg_exists_write_offset = 0; + + #[EMIT_UNENCRYPTED_LOG_KERNEL_OUTPUT] + sel_op_emit_unencrypted_log * (kernel_out_offset - (constants.START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET + emit_unencrypted_log_write_offset)) = 0; + sel_first * emit_unencrypted_log_write_offset = 0; + + // TODO: Add the equivalent for GETCONTRACTINSTANCE? + + #[EMIT_L2_TO_L1_MSGS_KERNEL_OUTPUT] + sel_op_emit_l2_to_l1_msg * (kernel_out_offset - (constants.START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET + emit_l2_to_l1_msg_write_offset)) = 0; + sel_first * emit_l2_to_l1_msg_write_offset = 0; + + #[SLOAD_KERNEL_OUTPUT] + sel_op_sload * (kernel_out_offset - (constants.START_SLOAD_WRITE_OFFSET + sload_write_offset)) = 0; + sel_first * sload_write_offset = 0; + + #[SSTORE_KERNEL_OUTPUT] + sel_op_sstore * (kernel_out_offset - (constants.START_SSTORE_WRITE_OFFSET + sstore_write_offset)) = 0; + sel_first * sstore_write_offset = 0; + + // When we encounter a state writing opcode + // We increment the side effect counter by 1 + #[SIDE_EFFECT_COUNTER_INCREMENT] + KERNEL_OUTPUT_SELECTORS * (side_effect_counter' - (side_effect_counter + 1)) = 0; + + //===== LOOKUPS INTO THE PUBLIC INPUTS =========================================== + pol KERNEL_INPUT_SELECTORS = sel_op_address + sel_op_storage_address + sel_op_sender + + sel_op_function_selector + sel_op_transaction_fee + sel_op_chain_id + + sel_op_version + sel_op_block_number + sel_op_coinbase + sel_op_timestamp + + sel_op_fee_per_l2_gas + sel_op_fee_per_da_gas; + // Ensure that only one kernel lookup is active when the kernel_in_offset is active + #[KERNEL_INPUT_ACTIVE_CHECK] + KERNEL_INPUT_SELECTORS * (1 - sel_q_kernel_lookup) = 0; + + pol KERNEL_OUTPUT_SELECTORS = sel_op_note_hash_exists + sel_op_emit_note_hash + sel_op_nullifier_exists + + sel_op_emit_nullifier + sel_op_l1_to_l2_msg_exists + sel_op_emit_unencrypted_log + + sel_op_emit_l2_to_l1_msg + sel_op_sload + sel_op_sstore; + #[KERNEL_OUTPUT_ACTIVE_CHECK] + KERNEL_OUTPUT_SELECTORS * (1 - sel_q_kernel_output_lookup) = 0; + + #[KERNEL_OUTPUT_LOOKUP] + sel_q_kernel_output_lookup {kernel_out_offset, ia, side_effect_counter, ib} in sel_kernel_out {clk, kernel_value_out, kernel_side_effect_out, kernel_metadata_out}; + + #[LOOKUP_INTO_KERNEL] + sel_q_kernel_lookup { main.ia, kernel_in_offset } in sel_kernel_inputs { kernel_inputs, clk }; diff --git a/barretenberg/cpp/pil/avm/main.pil b/barretenberg/cpp/pil/avm/main.pil index 634f53bd7fa..f1b03e37c3a 100644 --- a/barretenberg/cpp/pil/avm/main.pil +++ b/barretenberg/cpp/pil/avm/main.pil @@ -370,21 +370,6 @@ namespace main(256); // This works in combination with op_fdiv_err * (sel_op_fdiv - 1) = 0; // Drawback is the need to paralllelize the latter. - //===== KERNEL LOOKUPS ======================================================= - pol KERNEL_INPUT_SELECTORS = sel_op_address + sel_op_storage_address + sel_op_sender - + sel_op_function_selector + sel_op_transaction_fee + sel_op_chain_id - + sel_op_version + sel_op_block_number + sel_op_coinbase + sel_op_timestamp - + sel_op_fee_per_l2_gas + sel_op_fee_per_da_gas; - // Ensure that only one kernel lookup is active when the kernel_in_offset is active - #[KERNEL_INPUT_ACTIVE_CHECK] - KERNEL_INPUT_SELECTORS * (1 - sel_q_kernel_lookup) = 0; - - pol KERNEL_OUTPUT_SELECTORS = sel_op_note_hash_exists + sel_op_emit_note_hash + sel_op_nullifier_exists - + sel_op_emit_nullifier + sel_op_l1_to_l2_msg_exists + sel_op_emit_unencrypted_log - + sel_op_emit_l2_to_l1_msg + sel_op_sload + sel_op_sstore; - #[KERNEL_OUTPUT_ACTIVE_CHECK] - KERNEL_OUTPUT_SELECTORS * (1 - sel_q_kernel_output_lookup) = 0; - //===== CONTROL FLOW ======================================================= // pol commit sel_halted; // sel_halted * (1 - sel_halted) = 0; @@ -517,97 +502,6 @@ namespace main(256); #[DAGASLEFT] sel_op_dagasleft * (ia - da_gas_remaining') = 0; - //===== KERNEL INPUTS CONSTRAINTS =========================================== - // The general pattern for environment lookups is as follows: - // Each kernel opcode related to some fixed positions in the `public kernel_inputs` polynomial - // We can lookup into a fixed index of this polynomial by including constraints that force the value - // of kernel_in_offset to the value relevant to the given opcode that is active - - // CONTEXT - ENVIRONMENT - #[ADDRESS_KERNEL] - sel_op_address * (kernel.kernel_in_offset - constants.ADDRESS_SELECTOR) = 0; - - #[STORAGE_ADDRESS_KERNEL] - sel_op_storage_address * (kernel.kernel_in_offset - constants.STORAGE_ADDRESS_SELECTOR) = 0; - - #[SENDER_KERNEL] - sel_op_sender * (kernel.kernel_in_offset - constants.SENDER_SELECTOR) = 0; - - #[FUNCTION_SELECTOR_KERNEL] - sel_op_function_selector * (kernel.kernel_in_offset - constants.FUNCTION_SELECTOR_SELECTOR) = 0; - - #[FEE_TRANSACTION_FEE_KERNEL] - sel_op_transaction_fee * (kernel.kernel_in_offset - constants.TRANSACTION_FEE_SELECTOR) = 0; - - // CONTEXT - ENVIRONMENT - GLOBALS - #[CHAIN_ID_KERNEL] - sel_op_chain_id * (kernel.kernel_in_offset - constants.CHAIN_ID_SELECTOR) = 0; - - #[VERSION_KERNEL] - sel_op_version * (kernel.kernel_in_offset - constants.VERSION_SELECTOR) = 0; - - #[BLOCK_NUMBER_KERNEL] - sel_op_block_number * (kernel.kernel_in_offset - constants.BLOCK_NUMBER_SELECTOR) = 0; - - #[TIMESTAMP_KERNEL] - sel_op_timestamp * (kernel.kernel_in_offset - constants.TIMESTAMP_SELECTOR) = 0; - - #[COINBASE_KERNEL] - sel_op_coinbase * (kernel.kernel_in_offset - constants.COINBASE_SELECTOR) = 0; - - // CONTEXT - ENVIRONMENT - GLOBALS - FEES - #[FEE_DA_GAS_KERNEL] - sel_op_fee_per_da_gas * (kernel.kernel_in_offset - constants.FEE_PER_DA_GAS_SELECTOR) = 0; - - #[FEE_L2_GAS_KERNEL] - sel_op_fee_per_l2_gas * (kernel.kernel_in_offset - constants.FEE_PER_L2_GAS_SELECTOR) = 0; - - // OUTPUTS LOOKUPS - // Constrain the value of kernel_out_offset to be the correct offset for the operation being performed - #[NOTE_HASH_KERNEL_OUTPUT] - sel_op_note_hash_exists * (kernel.kernel_out_offset - (constants.START_NOTE_HASH_EXISTS_WRITE_OFFSET + kernel.note_hash_exist_write_offset)) = 0; - sel_first * kernel.note_hash_exist_write_offset = 0; - - - #[EMIT_NOTE_HASH_KERNEL_OUTPUT] - sel_op_emit_note_hash * (kernel.kernel_out_offset - (constants.START_EMIT_NOTE_HASH_WRITE_OFFSET + kernel.emit_note_hash_write_offset)) = 0; - sel_first * kernel.emit_note_hash_write_offset = 0; - - #[NULLIFIER_EXISTS_KERNEL_OUTPUT] - sel_op_nullifier_exists * (kernel.kernel_out_offset - ((ib * (constants.START_NULLIFIER_EXISTS_OFFSET + kernel.nullifier_exists_write_offset)) + ((1 - ib) * (constants.START_NULLIFIER_NON_EXISTS_OFFSET + kernel.nullifier_non_exists_write_offset)))) = 0; - sel_first * kernel.nullifier_exists_write_offset = 0; - sel_first * kernel.nullifier_non_exists_write_offset = 0; - - #[EMIT_NULLIFIER_KERNEL_OUTPUT] - sel_op_emit_nullifier * (kernel.kernel_out_offset - (constants.START_EMIT_NULLIFIER_WRITE_OFFSET + kernel.emit_nullifier_write_offset)) = 0; - sel_first * kernel.emit_nullifier_write_offset = 0; - - #[L1_TO_L2_MSG_EXISTS_KERNEL_OUTPUT] - sel_op_l1_to_l2_msg_exists * (kernel.kernel_out_offset - (constants.START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + kernel.l1_to_l2_msg_exists_write_offset)) = 0; - sel_first * kernel.l1_to_l2_msg_exists_write_offset = 0; - - #[EMIT_UNENCRYPTED_LOG_KERNEL_OUTPUT] - sel_op_emit_unencrypted_log * (kernel.kernel_out_offset - (constants.START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET + kernel.emit_unencrypted_log_write_offset)) = 0; - sel_first * kernel.emit_unencrypted_log_write_offset = 0; - - // TODO: Add the equivalent for GETCONTRACTINSTANCE? - - #[EMIT_L2_TO_L1_MSGS_KERNEL_OUTPUT] - sel_op_emit_l2_to_l1_msg * (kernel.kernel_out_offset - (constants.START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET + kernel.emit_l2_to_l1_msg_write_offset)) = 0; - sel_first * kernel.emit_l2_to_l1_msg_write_offset = 0; - - #[SLOAD_KERNEL_OUTPUT] - sel_op_sload * (kernel.kernel_out_offset - (constants.START_SLOAD_WRITE_OFFSET + kernel.sload_write_offset)) = 0; - sel_first * kernel.sload_write_offset = 0; - - #[SSTORE_KERNEL_OUTPUT] - sel_op_sstore * (kernel.kernel_out_offset - (constants.START_SSTORE_WRITE_OFFSET + kernel.sstore_write_offset)) = 0; - sel_first * kernel.sstore_write_offset = 0; - - // When we encounter a state writing opcode - // We increment the side effect counter by 1 - KERNEL_OUTPUT_SELECTORS * (kernel.side_effect_counter' - (kernel.side_effect_counter + 1)) = 0; - //===== Memory Slice Constraints ============================================ pol commit sel_slice_gadget; // Selector to activate a slice gadget operation in the gadget (#[PERM_MAIN_SLICE]). @@ -616,12 +510,6 @@ namespace main(256); //====== Inter-table Constraints ============================================ - #[KERNEL_OUTPUT_LOOKUP] - sel_q_kernel_output_lookup {kernel.kernel_out_offset, ia, kernel.side_effect_counter, ib} in kernel.q_public_input_kernel_out_add_to_table {clk, kernel.kernel_value_out, kernel.kernel_side_effect_out, kernel.kernel_metadata_out}; - - #[LOOKUP_INTO_KERNEL] - sel_q_kernel_lookup { main.ia, kernel.kernel_in_offset } in kernel.q_public_input_kernel_add_to_table { kernel.kernel_inputs, clk }; - #[INCL_MAIN_TAG_ERR] mem.tag_err {mem.clk} in tag_err {clk}; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp index 5ddd018b6d6..7db313939c4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp @@ -40,10 +40,10 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co polys.main_sel_first[i] = rows[i].main_sel_first; polys.main_zeroes[i] = rows[i].main_zeroes; polys.powers_power_of_2[i] = rows[i].powers_power_of_2; - polys.kernel_kernel_inputs[i] = rows[i].kernel_kernel_inputs; - polys.kernel_kernel_value_out[i] = rows[i].kernel_kernel_value_out; - polys.kernel_kernel_side_effect_out[i] = rows[i].kernel_kernel_side_effect_out; - polys.kernel_kernel_metadata_out[i] = rows[i].kernel_kernel_metadata_out; + polys.main_kernel_inputs[i] = rows[i].main_kernel_inputs; + polys.main_kernel_value_out[i] = rows[i].main_kernel_value_out; + polys.main_kernel_side_effect_out[i] = rows[i].main_kernel_side_effect_out; + polys.main_kernel_metadata_out[i] = rows[i].main_kernel_metadata_out; polys.main_calldata[i] = rows[i].main_calldata; polys.main_returndata[i] = rows[i].main_returndata; polys.alu_a_hi[i] = rows[i].alu_a_hi; @@ -151,21 +151,6 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co polys.keccakf1600_input[i] = rows[i].keccakf1600_input; polys.keccakf1600_output[i] = rows[i].keccakf1600_output; polys.keccakf1600_sel_keccakf1600[i] = rows[i].keccakf1600_sel_keccakf1600; - polys.kernel_emit_l2_to_l1_msg_write_offset[i] = rows[i].kernel_emit_l2_to_l1_msg_write_offset; - polys.kernel_emit_note_hash_write_offset[i] = rows[i].kernel_emit_note_hash_write_offset; - polys.kernel_emit_nullifier_write_offset[i] = rows[i].kernel_emit_nullifier_write_offset; - polys.kernel_emit_unencrypted_log_write_offset[i] = rows[i].kernel_emit_unencrypted_log_write_offset; - polys.kernel_kernel_in_offset[i] = rows[i].kernel_kernel_in_offset; - polys.kernel_kernel_out_offset[i] = rows[i].kernel_kernel_out_offset; - polys.kernel_l1_to_l2_msg_exists_write_offset[i] = rows[i].kernel_l1_to_l2_msg_exists_write_offset; - polys.kernel_note_hash_exist_write_offset[i] = rows[i].kernel_note_hash_exist_write_offset; - polys.kernel_nullifier_exists_write_offset[i] = rows[i].kernel_nullifier_exists_write_offset; - polys.kernel_nullifier_non_exists_write_offset[i] = rows[i].kernel_nullifier_non_exists_write_offset; - polys.kernel_q_public_input_kernel_add_to_table[i] = rows[i].kernel_q_public_input_kernel_add_to_table; - polys.kernel_q_public_input_kernel_out_add_to_table[i] = rows[i].kernel_q_public_input_kernel_out_add_to_table; - polys.kernel_side_effect_counter[i] = rows[i].kernel_side_effect_counter; - polys.kernel_sload_write_offset[i] = rows[i].kernel_sload_write_offset; - polys.kernel_sstore_write_offset[i] = rows[i].kernel_sstore_write_offset; polys.main_abs_da_rem_gas_hi[i] = rows[i].main_abs_da_rem_gas_hi; polys.main_abs_da_rem_gas_lo[i] = rows[i].main_abs_da_rem_gas_lo; polys.main_abs_l2_rem_gas_hi[i] = rows[i].main_abs_l2_rem_gas_hi; @@ -180,6 +165,10 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co polys.main_dyn_da_gas_op_cost[i] = rows[i].main_dyn_da_gas_op_cost; polys.main_dyn_gas_multiplier[i] = rows[i].main_dyn_gas_multiplier; polys.main_dyn_l2_gas_op_cost[i] = rows[i].main_dyn_l2_gas_op_cost; + polys.main_emit_l2_to_l1_msg_write_offset[i] = rows[i].main_emit_l2_to_l1_msg_write_offset; + polys.main_emit_note_hash_write_offset[i] = rows[i].main_emit_note_hash_write_offset; + polys.main_emit_nullifier_write_offset[i] = rows[i].main_emit_nullifier_write_offset; + polys.main_emit_unencrypted_log_write_offset[i] = rows[i].main_emit_unencrypted_log_write_offset; polys.main_ia[i] = rows[i].main_ia; polys.main_ib[i] = rows[i].main_ib; polys.main_ic[i] = rows[i].main_ic; @@ -191,12 +180,18 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co polys.main_ind_addr_d[i] = rows[i].main_ind_addr_d; polys.main_internal_return_ptr[i] = rows[i].main_internal_return_ptr; polys.main_inv[i] = rows[i].main_inv; + polys.main_kernel_in_offset[i] = rows[i].main_kernel_in_offset; + polys.main_kernel_out_offset[i] = rows[i].main_kernel_out_offset; + polys.main_l1_to_l2_msg_exists_write_offset[i] = rows[i].main_l1_to_l2_msg_exists_write_offset; polys.main_l2_gas_remaining[i] = rows[i].main_l2_gas_remaining; polys.main_l2_out_of_gas[i] = rows[i].main_l2_out_of_gas; polys.main_mem_addr_a[i] = rows[i].main_mem_addr_a; polys.main_mem_addr_b[i] = rows[i].main_mem_addr_b; polys.main_mem_addr_c[i] = rows[i].main_mem_addr_c; polys.main_mem_addr_d[i] = rows[i].main_mem_addr_d; + polys.main_note_hash_exist_write_offset[i] = rows[i].main_note_hash_exist_write_offset; + polys.main_nullifier_exists_write_offset[i] = rows[i].main_nullifier_exists_write_offset; + polys.main_nullifier_non_exists_write_offset[i] = rows[i].main_nullifier_non_exists_write_offset; polys.main_op_err[i] = rows[i].main_op_err; polys.main_opcode_val[i] = rows[i].main_opcode_val; polys.main_pc[i] = rows[i].main_pc; @@ -209,6 +204,8 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co polys.main_sel_bin[i] = rows[i].main_sel_bin; polys.main_sel_calldata[i] = rows[i].main_sel_calldata; polys.main_sel_execution_row[i] = rows[i].main_sel_execution_row; + polys.main_sel_kernel_inputs[i] = rows[i].main_sel_kernel_inputs; + polys.main_sel_kernel_out[i] = rows[i].main_sel_kernel_out; polys.main_sel_last[i] = rows[i].main_sel_last; polys.main_sel_mem_op_a[i] = rows[i].main_sel_mem_op_a; polys.main_sel_mem_op_b[i] = rows[i].main_sel_mem_op_b; @@ -284,7 +281,10 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co polys.main_sel_rng_16[i] = rows[i].main_sel_rng_16; polys.main_sel_rng_8[i] = rows[i].main_sel_rng_8; polys.main_sel_slice_gadget[i] = rows[i].main_sel_slice_gadget; + polys.main_side_effect_counter[i] = rows[i].main_side_effect_counter; + polys.main_sload_write_offset[i] = rows[i].main_sload_write_offset; polys.main_space_id[i] = rows[i].main_space_id; + polys.main_sstore_write_offset[i] = rows[i].main_sstore_write_offset; polys.main_tag_err[i] = rows[i].main_tag_err; polys.main_w_in_tag[i] = rows[i].main_w_in_tag; polys.mem_addr[i] = rows[i].mem_addr; @@ -634,10 +634,10 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co polys.range_check_l2_gas_lo_counts[i] = rows[i].range_check_l2_gas_lo_counts; polys.range_check_da_gas_hi_counts[i] = rows[i].range_check_da_gas_hi_counts; polys.range_check_da_gas_lo_counts[i] = rows[i].range_check_da_gas_lo_counts; - polys.lookup_cd_value_counts[i] = rows[i].lookup_cd_value_counts; - polys.lookup_ret_value_counts[i] = rows[i].lookup_ret_value_counts; polys.kernel_output_lookup_counts[i] = rows[i].kernel_output_lookup_counts; polys.lookup_into_kernel_counts[i] = rows[i].lookup_into_kernel_counts; + polys.lookup_cd_value_counts[i] = rows[i].lookup_cd_value_counts; + polys.lookup_ret_value_counts[i] = rows[i].lookup_ret_value_counts; polys.incl_main_tag_err_counts[i] = rows[i].incl_main_tag_err_counts; polys.incl_mem_tag_err_counts[i] = rows[i].incl_mem_tag_err_counts; polys.lookup_mem_rng_chk_lo_counts[i] = rows[i].lookup_mem_rng_chk_lo_counts; @@ -710,16 +710,20 @@ bool AvmCircuitBuilder::check_circuit() const r = 0; } + std::array subrelation_failed = { false }; for (size_t r = 0; r < num_rows; ++r) { Relation::accumulate(result, polys.get_row(r), {}, 1); for (size_t j = 0; j < result.size(); ++j) { - if (result[j] != 0) { + if (!subrelation_failed[j] && result[j] != 0) { signal_error(format("Relation ", Relation::NAME, ", subrelation ", Relation::get_subrelation_label(j), " failed at row ", r)); + // We will not check this subrelation for any other rows. + // Since the accumulation will keep being != 0. + subrelation_failed[j] = true; } } } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp index da053ff6338..9cf8f248f46 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp @@ -21,10 +21,10 @@ AvmFlavor::AllConstRefValues::AllConstRefValues( , main_sel_first(il[13]) , main_zeroes(il[14]) , powers_power_of_2(il[15]) - , kernel_kernel_inputs(il[16]) - , kernel_kernel_value_out(il[17]) - , kernel_kernel_side_effect_out(il[18]) - , kernel_kernel_metadata_out(il[19]) + , main_kernel_inputs(il[16]) + , main_kernel_value_out(il[17]) + , main_kernel_side_effect_out(il[18]) + , main_kernel_metadata_out(il[19]) , main_calldata(il[20]) , main_returndata(il[21]) , alu_a_hi(il[22]) @@ -132,140 +132,140 @@ AvmFlavor::AllConstRefValues::AllConstRefValues( , keccakf1600_input(il[124]) , keccakf1600_output(il[125]) , keccakf1600_sel_keccakf1600(il[126]) - , kernel_emit_l2_to_l1_msg_write_offset(il[127]) - , kernel_emit_note_hash_write_offset(il[128]) - , kernel_emit_nullifier_write_offset(il[129]) - , kernel_emit_unencrypted_log_write_offset(il[130]) - , kernel_kernel_in_offset(il[131]) - , kernel_kernel_out_offset(il[132]) - , kernel_l1_to_l2_msg_exists_write_offset(il[133]) - , kernel_note_hash_exist_write_offset(il[134]) - , kernel_nullifier_exists_write_offset(il[135]) - , kernel_nullifier_non_exists_write_offset(il[136]) - , kernel_q_public_input_kernel_add_to_table(il[137]) - , kernel_q_public_input_kernel_out_add_to_table(il[138]) - , kernel_side_effect_counter(il[139]) - , kernel_sload_write_offset(il[140]) - , kernel_sstore_write_offset(il[141]) - , main_abs_da_rem_gas_hi(il[142]) - , main_abs_da_rem_gas_lo(il[143]) - , main_abs_l2_rem_gas_hi(il[144]) - , main_abs_l2_rem_gas_lo(il[145]) - , main_alu_in_tag(il[146]) - , main_base_da_gas_op_cost(il[147]) - , main_base_l2_gas_op_cost(il[148]) - , main_bin_op_id(il[149]) - , main_call_ptr(il[150]) - , main_da_gas_remaining(il[151]) - , main_da_out_of_gas(il[152]) - , main_dyn_da_gas_op_cost(il[153]) - , main_dyn_gas_multiplier(il[154]) - , main_dyn_l2_gas_op_cost(il[155]) - , main_ia(il[156]) - , main_ib(il[157]) - , main_ic(il[158]) - , main_id(il[159]) - , main_id_zero(il[160]) - , main_ind_addr_a(il[161]) - , main_ind_addr_b(il[162]) - , main_ind_addr_c(il[163]) - , main_ind_addr_d(il[164]) - , main_internal_return_ptr(il[165]) - , main_inv(il[166]) - , main_l2_gas_remaining(il[167]) - , main_l2_out_of_gas(il[168]) - , main_mem_addr_a(il[169]) - , main_mem_addr_b(il[170]) - , main_mem_addr_c(il[171]) - , main_mem_addr_d(il[172]) - , main_op_err(il[173]) - , main_opcode_val(il[174]) - , main_pc(il[175]) - , main_r_in_tag(il[176]) - , main_rwa(il[177]) - , main_rwb(il[178]) - , main_rwc(il[179]) - , main_rwd(il[180]) - , main_sel_alu(il[181]) - , main_sel_bin(il[182]) - , main_sel_calldata(il[183]) - , main_sel_execution_row(il[184]) - , main_sel_last(il[185]) - , main_sel_mem_op_a(il[186]) - , main_sel_mem_op_b(il[187]) - , main_sel_mem_op_c(il[188]) - , main_sel_mem_op_d(il[189]) - , main_sel_mov_ia_to_ic(il[190]) - , main_sel_mov_ib_to_ic(il[191]) - , main_sel_op_add(il[192]) - , main_sel_op_address(il[193]) - , main_sel_op_and(il[194]) - , main_sel_op_block_number(il[195]) - , main_sel_op_calldata_copy(il[196]) - , main_sel_op_cast(il[197]) - , main_sel_op_chain_id(il[198]) - , main_sel_op_cmov(il[199]) - , main_sel_op_coinbase(il[200]) - , main_sel_op_dagasleft(il[201]) - , main_sel_op_div(il[202]) - , main_sel_op_ecadd(il[203]) - , main_sel_op_emit_l2_to_l1_msg(il[204]) - , main_sel_op_emit_note_hash(il[205]) - , main_sel_op_emit_nullifier(il[206]) - , main_sel_op_emit_unencrypted_log(il[207]) - , main_sel_op_eq(il[208]) - , main_sel_op_external_call(il[209]) - , main_sel_op_external_return(il[210]) - , main_sel_op_external_revert(il[211]) - , main_sel_op_fdiv(il[212]) - , main_sel_op_fee_per_da_gas(il[213]) - , main_sel_op_fee_per_l2_gas(il[214]) - , main_sel_op_function_selector(il[215]) - , main_sel_op_get_contract_instance(il[216]) - , main_sel_op_internal_call(il[217]) - , main_sel_op_internal_return(il[218]) - , main_sel_op_jump(il[219]) - , main_sel_op_jumpi(il[220]) - , main_sel_op_keccak(il[221]) - , main_sel_op_l1_to_l2_msg_exists(il[222]) - , main_sel_op_l2gasleft(il[223]) - , main_sel_op_lt(il[224]) - , main_sel_op_lte(il[225]) - , main_sel_op_mov(il[226]) - , main_sel_op_msm(il[227]) - , main_sel_op_mul(il[228]) - , main_sel_op_not(il[229]) - , main_sel_op_note_hash_exists(il[230]) - , main_sel_op_nullifier_exists(il[231]) - , main_sel_op_or(il[232]) - , main_sel_op_pedersen(il[233]) - , main_sel_op_pedersen_commit(il[234]) - , main_sel_op_poseidon2(il[235]) - , main_sel_op_radix_le(il[236]) - , main_sel_op_sender(il[237]) - , main_sel_op_set(il[238]) - , main_sel_op_sha256(il[239]) - , main_sel_op_shl(il[240]) - , main_sel_op_shr(il[241]) - , main_sel_op_sload(il[242]) - , main_sel_op_sstore(il[243]) - , main_sel_op_storage_address(il[244]) - , main_sel_op_sub(il[245]) - , main_sel_op_timestamp(il[246]) - , main_sel_op_transaction_fee(il[247]) - , main_sel_op_version(il[248]) - , main_sel_op_xor(il[249]) - , main_sel_q_kernel_lookup(il[250]) - , main_sel_q_kernel_output_lookup(il[251]) - , main_sel_resolve_ind_addr_a(il[252]) - , main_sel_resolve_ind_addr_b(il[253]) - , main_sel_resolve_ind_addr_c(il[254]) - , main_sel_resolve_ind_addr_d(il[255]) - , main_sel_returndata(il[256]) - , main_sel_rng_16(il[257]) - , main_sel_rng_8(il[258]) - , main_sel_slice_gadget(il[259]) - , main_space_id(il[260]) + , main_abs_da_rem_gas_hi(il[127]) + , main_abs_da_rem_gas_lo(il[128]) + , main_abs_l2_rem_gas_hi(il[129]) + , main_abs_l2_rem_gas_lo(il[130]) + , main_alu_in_tag(il[131]) + , main_base_da_gas_op_cost(il[132]) + , main_base_l2_gas_op_cost(il[133]) + , main_bin_op_id(il[134]) + , main_call_ptr(il[135]) + , main_da_gas_remaining(il[136]) + , main_da_out_of_gas(il[137]) + , main_dyn_da_gas_op_cost(il[138]) + , main_dyn_gas_multiplier(il[139]) + , main_dyn_l2_gas_op_cost(il[140]) + , main_emit_l2_to_l1_msg_write_offset(il[141]) + , main_emit_note_hash_write_offset(il[142]) + , main_emit_nullifier_write_offset(il[143]) + , main_emit_unencrypted_log_write_offset(il[144]) + , main_ia(il[145]) + , main_ib(il[146]) + , main_ic(il[147]) + , main_id(il[148]) + , main_id_zero(il[149]) + , main_ind_addr_a(il[150]) + , main_ind_addr_b(il[151]) + , main_ind_addr_c(il[152]) + , main_ind_addr_d(il[153]) + , main_internal_return_ptr(il[154]) + , main_inv(il[155]) + , main_kernel_in_offset(il[156]) + , main_kernel_out_offset(il[157]) + , main_l1_to_l2_msg_exists_write_offset(il[158]) + , main_l2_gas_remaining(il[159]) + , main_l2_out_of_gas(il[160]) + , main_mem_addr_a(il[161]) + , main_mem_addr_b(il[162]) + , main_mem_addr_c(il[163]) + , main_mem_addr_d(il[164]) + , main_note_hash_exist_write_offset(il[165]) + , main_nullifier_exists_write_offset(il[166]) + , main_nullifier_non_exists_write_offset(il[167]) + , main_op_err(il[168]) + , main_opcode_val(il[169]) + , main_pc(il[170]) + , main_r_in_tag(il[171]) + , main_rwa(il[172]) + , main_rwb(il[173]) + , main_rwc(il[174]) + , main_rwd(il[175]) + , main_sel_alu(il[176]) + , main_sel_bin(il[177]) + , main_sel_calldata(il[178]) + , main_sel_execution_row(il[179]) + , main_sel_kernel_inputs(il[180]) + , main_sel_kernel_out(il[181]) + , main_sel_last(il[182]) + , main_sel_mem_op_a(il[183]) + , main_sel_mem_op_b(il[184]) + , main_sel_mem_op_c(il[185]) + , main_sel_mem_op_d(il[186]) + , main_sel_mov_ia_to_ic(il[187]) + , main_sel_mov_ib_to_ic(il[188]) + , main_sel_op_add(il[189]) + , main_sel_op_address(il[190]) + , main_sel_op_and(il[191]) + , main_sel_op_block_number(il[192]) + , main_sel_op_calldata_copy(il[193]) + , main_sel_op_cast(il[194]) + , main_sel_op_chain_id(il[195]) + , main_sel_op_cmov(il[196]) + , main_sel_op_coinbase(il[197]) + , main_sel_op_dagasleft(il[198]) + , main_sel_op_div(il[199]) + , main_sel_op_ecadd(il[200]) + , main_sel_op_emit_l2_to_l1_msg(il[201]) + , main_sel_op_emit_note_hash(il[202]) + , main_sel_op_emit_nullifier(il[203]) + , main_sel_op_emit_unencrypted_log(il[204]) + , main_sel_op_eq(il[205]) + , main_sel_op_external_call(il[206]) + , main_sel_op_external_return(il[207]) + , main_sel_op_external_revert(il[208]) + , main_sel_op_fdiv(il[209]) + , main_sel_op_fee_per_da_gas(il[210]) + , main_sel_op_fee_per_l2_gas(il[211]) + , main_sel_op_function_selector(il[212]) + , main_sel_op_get_contract_instance(il[213]) + , main_sel_op_internal_call(il[214]) + , main_sel_op_internal_return(il[215]) + , main_sel_op_jump(il[216]) + , main_sel_op_jumpi(il[217]) + , main_sel_op_keccak(il[218]) + , main_sel_op_l1_to_l2_msg_exists(il[219]) + , main_sel_op_l2gasleft(il[220]) + , main_sel_op_lt(il[221]) + , main_sel_op_lte(il[222]) + , main_sel_op_mov(il[223]) + , main_sel_op_msm(il[224]) + , main_sel_op_mul(il[225]) + , main_sel_op_not(il[226]) + , main_sel_op_note_hash_exists(il[227]) + , main_sel_op_nullifier_exists(il[228]) + , main_sel_op_or(il[229]) + , main_sel_op_pedersen(il[230]) + , main_sel_op_pedersen_commit(il[231]) + , main_sel_op_poseidon2(il[232]) + , main_sel_op_radix_le(il[233]) + , main_sel_op_sender(il[234]) + , main_sel_op_set(il[235]) + , main_sel_op_sha256(il[236]) + , main_sel_op_shl(il[237]) + , main_sel_op_shr(il[238]) + , main_sel_op_sload(il[239]) + , main_sel_op_sstore(il[240]) + , main_sel_op_storage_address(il[241]) + , main_sel_op_sub(il[242]) + , main_sel_op_timestamp(il[243]) + , main_sel_op_transaction_fee(il[244]) + , main_sel_op_version(il[245]) + , main_sel_op_xor(il[246]) + , main_sel_q_kernel_lookup(il[247]) + , main_sel_q_kernel_output_lookup(il[248]) + , main_sel_resolve_ind_addr_a(il[249]) + , main_sel_resolve_ind_addr_b(il[250]) + , main_sel_resolve_ind_addr_c(il[251]) + , main_sel_resolve_ind_addr_d(il[252]) + , main_sel_returndata(il[253]) + , main_sel_rng_16(il[254]) + , main_sel_rng_8(il[255]) + , main_sel_slice_gadget(il[256]) + , main_side_effect_counter(il[257]) + , main_sload_write_offset(il[258]) + , main_space_id(il[259]) + , main_sstore_write_offset(il[260]) , main_tag_err(il[261]) , main_w_in_tag(il[262]) , mem_addr(il[263]) @@ -615,10 +615,10 @@ AvmFlavor::AllConstRefValues::AllConstRefValues( , range_check_l2_gas_lo_counts(il[607]) , range_check_da_gas_hi_counts(il[608]) , range_check_da_gas_lo_counts(il[609]) - , lookup_cd_value_counts(il[610]) - , lookup_ret_value_counts(il[611]) - , kernel_output_lookup_counts(il[612]) - , lookup_into_kernel_counts(il[613]) + , kernel_output_lookup_counts(il[610]) + , lookup_into_kernel_counts(il[611]) + , lookup_cd_value_counts(il[612]) + , lookup_ret_value_counts(il[613]) , incl_main_tag_err_counts(il[614]) , incl_mem_tag_err_counts(il[615]) , lookup_mem_rng_chk_lo_counts(il[616]) @@ -681,10 +681,10 @@ AvmFlavor::AllConstRefValues::AllConstRefValues( , range_check_l2_gas_lo_inv(il[673]) , range_check_da_gas_hi_inv(il[674]) , range_check_da_gas_lo_inv(il[675]) - , lookup_cd_value_inv(il[676]) - , lookup_ret_value_inv(il[677]) - , kernel_output_lookup_inv(il[678]) - , lookup_into_kernel_inv(il[679]) + , kernel_output_lookup_inv(il[676]) + , lookup_into_kernel_inv(il[677]) + , lookup_cd_value_inv(il[678]) + , lookup_ret_value_inv(il[679]) , incl_main_tag_err_inv(il[680]) , incl_mem_tag_err_inv(il[681]) , lookup_mem_rng_chk_lo_inv(il[682]) @@ -717,81 +717,81 @@ AvmFlavor::AllConstRefValues::AllConstRefValues( , lookup_div_u16_5_inv(il[709]) , lookup_div_u16_6_inv(il[710]) , lookup_div_u16_7_inv(il[711]) - , alu_div_u16_r1_shift(il[712]) - , slice_clk_shift(il[713]) - , alu_div_u16_r6_shift(il[714]) - , kernel_nullifier_exists_write_offset_shift(il[715]) - , mem_tsp_shift(il[716]) - , main_internal_return_ptr_shift(il[717]) - , main_sel_execution_row_shift(il[718]) - , alu_sel_rng_chk_shift(il[719]) + , alu_a_hi_shift(il[712]) + , alu_a_lo_shift(il[713]) + , alu_b_hi_shift(il[714]) + , alu_b_lo_shift(il[715]) + , alu_cmp_rng_ctr_shift(il[716]) + , alu_div_u16_r0_shift(il[717]) + , alu_div_u16_r1_shift(il[718]) + , alu_div_u16_r2_shift(il[719]) , alu_div_u16_r3_shift(il[720]) - , kernel_emit_note_hash_write_offset_shift(il[721]) - , alu_p_sub_b_hi_shift(il[722]) - , slice_sel_return_shift(il[723]) - , kernel_side_effect_counter_shift(il[724]) + , alu_div_u16_r4_shift(il[721]) + , alu_div_u16_r5_shift(il[722]) + , alu_div_u16_r6_shift(il[723]) + , alu_div_u16_r7_shift(il[724]) , alu_op_add_shift(il[725]) , alu_op_cast_shift(il[726]) - , kernel_emit_nullifier_write_offset_shift(il[727]) - , slice_cnt_shift(il[728]) - , alu_sel_cmp_shift(il[729]) - , alu_u16_r1_shift(il[730]) - , binary_acc_ia_shift(il[731]) - , alu_div_u16_r0_shift(il[732]) - , kernel_l1_to_l2_msg_exists_write_offset_shift(il[733]) - , alu_a_hi_shift(il[734]) - , alu_div_u16_r5_shift(il[735]) - , kernel_emit_unencrypted_log_write_offset_shift(il[736]) - , mem_val_shift(il[737]) - , slice_sel_start_shift(il[738]) - , binary_acc_ic_shift(il[739]) - , alu_sel_div_rng_chk_shift(il[740]) - , alu_u16_r6_shift(il[741]) - , alu_op_shr_shift(il[742]) - , slice_space_id_shift(il[743]) - , mem_tag_shift(il[744]) - , alu_op_mul_shift(il[745]) - , binary_mem_tag_ctr_shift(il[746]) - , kernel_emit_l2_to_l1_msg_write_offset_shift(il[747]) - , alu_sel_alu_shift(il[748]) - , mem_rw_shift(il[749]) - , mem_glob_addr_shift(il[750]) - , alu_u16_r3_shift(il[751]) - , kernel_sstore_write_offset_shift(il[752]) - , mem_sel_mem_shift(il[753]) - , slice_sel_mem_active_shift(il[754]) - , alu_op_shl_shift(il[755]) - , alu_b_hi_shift(il[756]) - , alu_cmp_rng_ctr_shift(il[757]) - , alu_op_cast_prev_shift(il[758]) - , alu_sel_rng_chk_lookup_shift(il[759]) - , slice_sel_cd_cpy_shift(il[760]) - , main_pc_shift(il[761]) - , alu_u8_r1_shift(il[762]) - , alu_p_sub_a_lo_shift(il[763]) - , main_da_gas_remaining_shift(il[764]) - , alu_b_lo_shift(il[765]) - , alu_u8_r0_shift(il[766]) - , alu_p_sub_b_lo_shift(il[767]) - , kernel_nullifier_non_exists_write_offset_shift(il[768]) - , alu_u16_r4_shift(il[769]) - , binary_acc_ib_shift(il[770]) - , alu_u16_r0_shift(il[771]) - , alu_div_u16_r2_shift(il[772]) - , alu_op_div_shift(il[773]) - , alu_a_lo_shift(il[774]) - , alu_op_sub_shift(il[775]) - , alu_div_u16_r7_shift(il[776]) - , alu_u16_r5_shift(il[777]) - , alu_u16_r2_shift(il[778]) - , kernel_note_hash_exist_write_offset_shift(il[779]) - , main_l2_gas_remaining_shift(il[780]) - , kernel_sload_write_offset_shift(il[781]) - , slice_addr_shift(il[782]) - , binary_op_id_shift(il[783]) - , alu_p_sub_a_hi_shift(il[784]) - , slice_col_offset_shift(il[785]) - , alu_div_u16_r4_shift(il[786]) + , alu_op_cast_prev_shift(il[727]) + , alu_op_div_shift(il[728]) + , alu_op_mul_shift(il[729]) + , alu_op_shl_shift(il[730]) + , alu_op_shr_shift(il[731]) + , alu_op_sub_shift(il[732]) + , alu_p_sub_a_hi_shift(il[733]) + , alu_p_sub_a_lo_shift(il[734]) + , alu_p_sub_b_hi_shift(il[735]) + , alu_p_sub_b_lo_shift(il[736]) + , alu_sel_alu_shift(il[737]) + , alu_sel_cmp_shift(il[738]) + , alu_sel_div_rng_chk_shift(il[739]) + , alu_sel_rng_chk_shift(il[740]) + , alu_sel_rng_chk_lookup_shift(il[741]) + , alu_u16_r0_shift(il[742]) + , alu_u16_r1_shift(il[743]) + , alu_u16_r2_shift(il[744]) + , alu_u16_r3_shift(il[745]) + , alu_u16_r4_shift(il[746]) + , alu_u16_r5_shift(il[747]) + , alu_u16_r6_shift(il[748]) + , alu_u8_r0_shift(il[749]) + , alu_u8_r1_shift(il[750]) + , binary_acc_ia_shift(il[751]) + , binary_acc_ib_shift(il[752]) + , binary_acc_ic_shift(il[753]) + , binary_mem_tag_ctr_shift(il[754]) + , binary_op_id_shift(il[755]) + , main_da_gas_remaining_shift(il[756]) + , main_emit_l2_to_l1_msg_write_offset_shift(il[757]) + , main_emit_note_hash_write_offset_shift(il[758]) + , main_emit_nullifier_write_offset_shift(il[759]) + , main_emit_unencrypted_log_write_offset_shift(il[760]) + , main_internal_return_ptr_shift(il[761]) + , main_l1_to_l2_msg_exists_write_offset_shift(il[762]) + , main_l2_gas_remaining_shift(il[763]) + , main_note_hash_exist_write_offset_shift(il[764]) + , main_nullifier_exists_write_offset_shift(il[765]) + , main_nullifier_non_exists_write_offset_shift(il[766]) + , main_pc_shift(il[767]) + , main_sel_execution_row_shift(il[768]) + , main_side_effect_counter_shift(il[769]) + , main_sload_write_offset_shift(il[770]) + , main_sstore_write_offset_shift(il[771]) + , mem_glob_addr_shift(il[772]) + , mem_rw_shift(il[773]) + , mem_sel_mem_shift(il[774]) + , mem_tag_shift(il[775]) + , mem_tsp_shift(il[776]) + , mem_val_shift(il[777]) + , slice_addr_shift(il[778]) + , slice_clk_shift(il[779]) + , slice_cnt_shift(il[780]) + , slice_col_offset_shift(il[781]) + , slice_sel_cd_cpy_shift(il[782]) + , slice_sel_mem_active_shift(il[783]) + , slice_sel_return_shift(il[784]) + , slice_sel_start_shift(il[785]) + , slice_space_id_shift(il[786]) {} AvmFlavor::ProverPolynomials::ProverPolynomials(ProvingKey& proving_key) @@ -824,10 +824,10 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id main_sel_first[row_idx], main_zeroes[row_idx], powers_power_of_2[row_idx], - kernel_kernel_inputs[row_idx], - kernel_kernel_value_out[row_idx], - kernel_kernel_side_effect_out[row_idx], - kernel_kernel_metadata_out[row_idx], + main_kernel_inputs[row_idx], + main_kernel_value_out[row_idx], + main_kernel_side_effect_out[row_idx], + main_kernel_metadata_out[row_idx], main_calldata[row_idx], main_returndata[row_idx], alu_a_hi[row_idx], @@ -935,21 +935,6 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id keccakf1600_input[row_idx], keccakf1600_output[row_idx], keccakf1600_sel_keccakf1600[row_idx], - kernel_emit_l2_to_l1_msg_write_offset[row_idx], - kernel_emit_note_hash_write_offset[row_idx], - kernel_emit_nullifier_write_offset[row_idx], - kernel_emit_unencrypted_log_write_offset[row_idx], - kernel_kernel_in_offset[row_idx], - kernel_kernel_out_offset[row_idx], - kernel_l1_to_l2_msg_exists_write_offset[row_idx], - kernel_note_hash_exist_write_offset[row_idx], - kernel_nullifier_exists_write_offset[row_idx], - kernel_nullifier_non_exists_write_offset[row_idx], - kernel_q_public_input_kernel_add_to_table[row_idx], - kernel_q_public_input_kernel_out_add_to_table[row_idx], - kernel_side_effect_counter[row_idx], - kernel_sload_write_offset[row_idx], - kernel_sstore_write_offset[row_idx], main_abs_da_rem_gas_hi[row_idx], main_abs_da_rem_gas_lo[row_idx], main_abs_l2_rem_gas_hi[row_idx], @@ -964,6 +949,10 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id main_dyn_da_gas_op_cost[row_idx], main_dyn_gas_multiplier[row_idx], main_dyn_l2_gas_op_cost[row_idx], + main_emit_l2_to_l1_msg_write_offset[row_idx], + main_emit_note_hash_write_offset[row_idx], + main_emit_nullifier_write_offset[row_idx], + main_emit_unencrypted_log_write_offset[row_idx], main_ia[row_idx], main_ib[row_idx], main_ic[row_idx], @@ -975,12 +964,18 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id main_ind_addr_d[row_idx], main_internal_return_ptr[row_idx], main_inv[row_idx], + main_kernel_in_offset[row_idx], + main_kernel_out_offset[row_idx], + main_l1_to_l2_msg_exists_write_offset[row_idx], main_l2_gas_remaining[row_idx], main_l2_out_of_gas[row_idx], main_mem_addr_a[row_idx], main_mem_addr_b[row_idx], main_mem_addr_c[row_idx], main_mem_addr_d[row_idx], + main_note_hash_exist_write_offset[row_idx], + main_nullifier_exists_write_offset[row_idx], + main_nullifier_non_exists_write_offset[row_idx], main_op_err[row_idx], main_opcode_val[row_idx], main_pc[row_idx], @@ -993,6 +988,8 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id main_sel_bin[row_idx], main_sel_calldata[row_idx], main_sel_execution_row[row_idx], + main_sel_kernel_inputs[row_idx], + main_sel_kernel_out[row_idx], main_sel_last[row_idx], main_sel_mem_op_a[row_idx], main_sel_mem_op_b[row_idx], @@ -1068,7 +1065,10 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id main_sel_rng_16[row_idx], main_sel_rng_8[row_idx], main_sel_slice_gadget[row_idx], + main_side_effect_counter[row_idx], + main_sload_write_offset[row_idx], main_space_id[row_idx], + main_sstore_write_offset[row_idx], main_tag_err[row_idx], main_w_in_tag[row_idx], mem_addr[row_idx], @@ -1418,10 +1418,10 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id range_check_l2_gas_lo_counts[row_idx], range_check_da_gas_hi_counts[row_idx], range_check_da_gas_lo_counts[row_idx], - lookup_cd_value_counts[row_idx], - lookup_ret_value_counts[row_idx], kernel_output_lookup_counts[row_idx], lookup_into_kernel_counts[row_idx], + lookup_cd_value_counts[row_idx], + lookup_ret_value_counts[row_idx], incl_main_tag_err_counts[row_idx], incl_mem_tag_err_counts[row_idx], lookup_mem_rng_chk_lo_counts[row_idx], @@ -1484,10 +1484,10 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id range_check_l2_gas_lo_inv[row_idx], range_check_da_gas_hi_inv[row_idx], range_check_da_gas_lo_inv[row_idx], - lookup_cd_value_inv[row_idx], - lookup_ret_value_inv[row_idx], kernel_output_lookup_inv[row_idx], lookup_into_kernel_inv[row_idx], + lookup_cd_value_inv[row_idx], + lookup_ret_value_inv[row_idx], incl_main_tag_err_inv[row_idx], incl_mem_tag_err_inv[row_idx], lookup_mem_rng_chk_lo_inv[row_idx], @@ -1520,81 +1520,81 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id lookup_div_u16_5_inv[row_idx], lookup_div_u16_6_inv[row_idx], lookup_div_u16_7_inv[row_idx], + alu_a_hi_shift[row_idx], + alu_a_lo_shift[row_idx], + alu_b_hi_shift[row_idx], + alu_b_lo_shift[row_idx], + alu_cmp_rng_ctr_shift[row_idx], + alu_div_u16_r0_shift[row_idx], alu_div_u16_r1_shift[row_idx], - slice_clk_shift[row_idx], - alu_div_u16_r6_shift[row_idx], - kernel_nullifier_exists_write_offset_shift[row_idx], - mem_tsp_shift[row_idx], - main_internal_return_ptr_shift[row_idx], - main_sel_execution_row_shift[row_idx], - alu_sel_rng_chk_shift[row_idx], + alu_div_u16_r2_shift[row_idx], alu_div_u16_r3_shift[row_idx], - kernel_emit_note_hash_write_offset_shift[row_idx], - alu_p_sub_b_hi_shift[row_idx], - slice_sel_return_shift[row_idx], - kernel_side_effect_counter_shift[row_idx], + alu_div_u16_r4_shift[row_idx], + alu_div_u16_r5_shift[row_idx], + alu_div_u16_r6_shift[row_idx], + alu_div_u16_r7_shift[row_idx], alu_op_add_shift[row_idx], alu_op_cast_shift[row_idx], - kernel_emit_nullifier_write_offset_shift[row_idx], - slice_cnt_shift[row_idx], - alu_sel_cmp_shift[row_idx], - alu_u16_r1_shift[row_idx], - binary_acc_ia_shift[row_idx], - alu_div_u16_r0_shift[row_idx], - kernel_l1_to_l2_msg_exists_write_offset_shift[row_idx], - alu_a_hi_shift[row_idx], - alu_div_u16_r5_shift[row_idx], - kernel_emit_unencrypted_log_write_offset_shift[row_idx], - mem_val_shift[row_idx], - slice_sel_start_shift[row_idx], - binary_acc_ic_shift[row_idx], - alu_sel_div_rng_chk_shift[row_idx], - alu_u16_r6_shift[row_idx], - alu_op_shr_shift[row_idx], - slice_space_id_shift[row_idx], - mem_tag_shift[row_idx], + alu_op_cast_prev_shift[row_idx], + alu_op_div_shift[row_idx], alu_op_mul_shift[row_idx], - binary_mem_tag_ctr_shift[row_idx], - kernel_emit_l2_to_l1_msg_write_offset_shift[row_idx], - alu_sel_alu_shift[row_idx], - mem_rw_shift[row_idx], - mem_glob_addr_shift[row_idx], - alu_u16_r3_shift[row_idx], - kernel_sstore_write_offset_shift[row_idx], - mem_sel_mem_shift[row_idx], - slice_sel_mem_active_shift[row_idx], alu_op_shl_shift[row_idx], - alu_b_hi_shift[row_idx], - alu_cmp_rng_ctr_shift[row_idx], - alu_op_cast_prev_shift[row_idx], - alu_sel_rng_chk_lookup_shift[row_idx], - slice_sel_cd_cpy_shift[row_idx], - main_pc_shift[row_idx], - alu_u8_r1_shift[row_idx], + alu_op_shr_shift[row_idx], + alu_op_sub_shift[row_idx], + alu_p_sub_a_hi_shift[row_idx], alu_p_sub_a_lo_shift[row_idx], - main_da_gas_remaining_shift[row_idx], - alu_b_lo_shift[row_idx], - alu_u8_r0_shift[row_idx], + alu_p_sub_b_hi_shift[row_idx], alu_p_sub_b_lo_shift[row_idx], - kernel_nullifier_non_exists_write_offset_shift[row_idx], - alu_u16_r4_shift[row_idx], - binary_acc_ib_shift[row_idx], + alu_sel_alu_shift[row_idx], + alu_sel_cmp_shift[row_idx], + alu_sel_div_rng_chk_shift[row_idx], + alu_sel_rng_chk_shift[row_idx], + alu_sel_rng_chk_lookup_shift[row_idx], alu_u16_r0_shift[row_idx], - alu_div_u16_r2_shift[row_idx], - alu_op_div_shift[row_idx], - alu_a_lo_shift[row_idx], - alu_op_sub_shift[row_idx], - alu_div_u16_r7_shift[row_idx], - alu_u16_r5_shift[row_idx], + alu_u16_r1_shift[row_idx], alu_u16_r2_shift[row_idx], - kernel_note_hash_exist_write_offset_shift[row_idx], + alu_u16_r3_shift[row_idx], + alu_u16_r4_shift[row_idx], + alu_u16_r5_shift[row_idx], + alu_u16_r6_shift[row_idx], + alu_u8_r0_shift[row_idx], + alu_u8_r1_shift[row_idx], + binary_acc_ia_shift[row_idx], + binary_acc_ib_shift[row_idx], + binary_acc_ic_shift[row_idx], + binary_mem_tag_ctr_shift[row_idx], + binary_op_id_shift[row_idx], + main_da_gas_remaining_shift[row_idx], + main_emit_l2_to_l1_msg_write_offset_shift[row_idx], + main_emit_note_hash_write_offset_shift[row_idx], + main_emit_nullifier_write_offset_shift[row_idx], + main_emit_unencrypted_log_write_offset_shift[row_idx], + main_internal_return_ptr_shift[row_idx], + main_l1_to_l2_msg_exists_write_offset_shift[row_idx], main_l2_gas_remaining_shift[row_idx], - kernel_sload_write_offset_shift[row_idx], + main_note_hash_exist_write_offset_shift[row_idx], + main_nullifier_exists_write_offset_shift[row_idx], + main_nullifier_non_exists_write_offset_shift[row_idx], + main_pc_shift[row_idx], + main_sel_execution_row_shift[row_idx], + main_side_effect_counter_shift[row_idx], + main_sload_write_offset_shift[row_idx], + main_sstore_write_offset_shift[row_idx], + mem_glob_addr_shift[row_idx], + mem_rw_shift[row_idx], + mem_sel_mem_shift[row_idx], + mem_tag_shift[row_idx], + mem_tsp_shift[row_idx], + mem_val_shift[row_idx], slice_addr_shift[row_idx], - binary_op_id_shift[row_idx], - alu_p_sub_a_hi_shift[row_idx], + slice_clk_shift[row_idx], + slice_cnt_shift[row_idx], slice_col_offset_shift[row_idx], - alu_div_u16_r4_shift[row_idx] }; + slice_sel_cd_cpy_shift[row_idx], + slice_sel_mem_active_shift[row_idx], + slice_sel_return_shift[row_idx], + slice_sel_start_shift[row_idx], + slice_space_id_shift[row_idx] }; } AvmFlavor::CommitmentLabels::CommitmentLabels() @@ -1615,10 +1615,10 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::main_sel_first = "MAIN_SEL_FIRST"; Base::main_zeroes = "MAIN_ZEROES"; Base::powers_power_of_2 = "POWERS_POWER_OF_2"; - Base::kernel_kernel_inputs = "KERNEL_KERNEL_INPUTS"; - Base::kernel_kernel_value_out = "KERNEL_KERNEL_VALUE_OUT"; - Base::kernel_kernel_side_effect_out = "KERNEL_KERNEL_SIDE_EFFECT_OUT"; - Base::kernel_kernel_metadata_out = "KERNEL_KERNEL_METADATA_OUT"; + Base::main_kernel_inputs = "MAIN_KERNEL_INPUTS"; + Base::main_kernel_value_out = "MAIN_KERNEL_VALUE_OUT"; + Base::main_kernel_side_effect_out = "MAIN_KERNEL_SIDE_EFFECT_OUT"; + Base::main_kernel_metadata_out = "MAIN_KERNEL_METADATA_OUT"; Base::main_calldata = "MAIN_CALLDATA"; Base::main_returndata = "MAIN_RETURNDATA"; Base::alu_a_hi = "ALU_A_HI"; @@ -1726,21 +1726,6 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::keccakf1600_input = "KECCAKF1600_INPUT"; Base::keccakf1600_output = "KECCAKF1600_OUTPUT"; Base::keccakf1600_sel_keccakf1600 = "KECCAKF1600_SEL_KECCAKF1600"; - Base::kernel_emit_l2_to_l1_msg_write_offset = "KERNEL_EMIT_L2_TO_L1_MSG_WRITE_OFFSET"; - Base::kernel_emit_note_hash_write_offset = "KERNEL_EMIT_NOTE_HASH_WRITE_OFFSET"; - Base::kernel_emit_nullifier_write_offset = "KERNEL_EMIT_NULLIFIER_WRITE_OFFSET"; - Base::kernel_emit_unencrypted_log_write_offset = "KERNEL_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET"; - Base::kernel_kernel_in_offset = "KERNEL_KERNEL_IN_OFFSET"; - Base::kernel_kernel_out_offset = "KERNEL_KERNEL_OUT_OFFSET"; - Base::kernel_l1_to_l2_msg_exists_write_offset = "KERNEL_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET"; - Base::kernel_note_hash_exist_write_offset = "KERNEL_NOTE_HASH_EXIST_WRITE_OFFSET"; - Base::kernel_nullifier_exists_write_offset = "KERNEL_NULLIFIER_EXISTS_WRITE_OFFSET"; - Base::kernel_nullifier_non_exists_write_offset = "KERNEL_NULLIFIER_NON_EXISTS_WRITE_OFFSET"; - Base::kernel_q_public_input_kernel_add_to_table = "KERNEL_Q_PUBLIC_INPUT_KERNEL_ADD_TO_TABLE"; - Base::kernel_q_public_input_kernel_out_add_to_table = "KERNEL_Q_PUBLIC_INPUT_KERNEL_OUT_ADD_TO_TABLE"; - Base::kernel_side_effect_counter = "KERNEL_SIDE_EFFECT_COUNTER"; - Base::kernel_sload_write_offset = "KERNEL_SLOAD_WRITE_OFFSET"; - Base::kernel_sstore_write_offset = "KERNEL_SSTORE_WRITE_OFFSET"; Base::main_abs_da_rem_gas_hi = "MAIN_ABS_DA_REM_GAS_HI"; Base::main_abs_da_rem_gas_lo = "MAIN_ABS_DA_REM_GAS_LO"; Base::main_abs_l2_rem_gas_hi = "MAIN_ABS_L2_REM_GAS_HI"; @@ -1755,6 +1740,10 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::main_dyn_da_gas_op_cost = "MAIN_DYN_DA_GAS_OP_COST"; Base::main_dyn_gas_multiplier = "MAIN_DYN_GAS_MULTIPLIER"; Base::main_dyn_l2_gas_op_cost = "MAIN_DYN_L2_GAS_OP_COST"; + Base::main_emit_l2_to_l1_msg_write_offset = "MAIN_EMIT_L2_TO_L1_MSG_WRITE_OFFSET"; + Base::main_emit_note_hash_write_offset = "MAIN_EMIT_NOTE_HASH_WRITE_OFFSET"; + Base::main_emit_nullifier_write_offset = "MAIN_EMIT_NULLIFIER_WRITE_OFFSET"; + Base::main_emit_unencrypted_log_write_offset = "MAIN_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET"; Base::main_ia = "MAIN_IA"; Base::main_ib = "MAIN_IB"; Base::main_ic = "MAIN_IC"; @@ -1766,12 +1755,18 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::main_ind_addr_d = "MAIN_IND_ADDR_D"; Base::main_internal_return_ptr = "MAIN_INTERNAL_RETURN_PTR"; Base::main_inv = "MAIN_INV"; + Base::main_kernel_in_offset = "MAIN_KERNEL_IN_OFFSET"; + Base::main_kernel_out_offset = "MAIN_KERNEL_OUT_OFFSET"; + Base::main_l1_to_l2_msg_exists_write_offset = "MAIN_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET"; Base::main_l2_gas_remaining = "MAIN_L2_GAS_REMAINING"; Base::main_l2_out_of_gas = "MAIN_L2_OUT_OF_GAS"; Base::main_mem_addr_a = "MAIN_MEM_ADDR_A"; Base::main_mem_addr_b = "MAIN_MEM_ADDR_B"; Base::main_mem_addr_c = "MAIN_MEM_ADDR_C"; Base::main_mem_addr_d = "MAIN_MEM_ADDR_D"; + Base::main_note_hash_exist_write_offset = "MAIN_NOTE_HASH_EXIST_WRITE_OFFSET"; + Base::main_nullifier_exists_write_offset = "MAIN_NULLIFIER_EXISTS_WRITE_OFFSET"; + Base::main_nullifier_non_exists_write_offset = "MAIN_NULLIFIER_NON_EXISTS_WRITE_OFFSET"; Base::main_op_err = "MAIN_OP_ERR"; Base::main_opcode_val = "MAIN_OPCODE_VAL"; Base::main_pc = "MAIN_PC"; @@ -1784,6 +1779,8 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::main_sel_bin = "MAIN_SEL_BIN"; Base::main_sel_calldata = "MAIN_SEL_CALLDATA"; Base::main_sel_execution_row = "MAIN_SEL_EXECUTION_ROW"; + Base::main_sel_kernel_inputs = "MAIN_SEL_KERNEL_INPUTS"; + Base::main_sel_kernel_out = "MAIN_SEL_KERNEL_OUT"; Base::main_sel_last = "MAIN_SEL_LAST"; Base::main_sel_mem_op_a = "MAIN_SEL_MEM_OP_A"; Base::main_sel_mem_op_b = "MAIN_SEL_MEM_OP_B"; @@ -1859,7 +1856,10 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::main_sel_rng_16 = "MAIN_SEL_RNG_16"; Base::main_sel_rng_8 = "MAIN_SEL_RNG_8"; Base::main_sel_slice_gadget = "MAIN_SEL_SLICE_GADGET"; + Base::main_side_effect_counter = "MAIN_SIDE_EFFECT_COUNTER"; + Base::main_sload_write_offset = "MAIN_SLOAD_WRITE_OFFSET"; Base::main_space_id = "MAIN_SPACE_ID"; + Base::main_sstore_write_offset = "MAIN_SSTORE_WRITE_OFFSET"; Base::main_tag_err = "MAIN_TAG_ERR"; Base::main_w_in_tag = "MAIN_W_IN_TAG"; Base::mem_addr = "MEM_ADDR"; @@ -2232,10 +2232,10 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::range_check_l2_gas_lo_inv = "RANGE_CHECK_L2_GAS_LO_INV"; Base::range_check_da_gas_hi_inv = "RANGE_CHECK_DA_GAS_HI_INV"; Base::range_check_da_gas_lo_inv = "RANGE_CHECK_DA_GAS_LO_INV"; - Base::lookup_cd_value_inv = "LOOKUP_CD_VALUE_INV"; - Base::lookup_ret_value_inv = "LOOKUP_RET_VALUE_INV"; Base::kernel_output_lookup_inv = "KERNEL_OUTPUT_LOOKUP_INV"; Base::lookup_into_kernel_inv = "LOOKUP_INTO_KERNEL_INV"; + Base::lookup_cd_value_inv = "LOOKUP_CD_VALUE_INV"; + Base::lookup_ret_value_inv = "LOOKUP_RET_VALUE_INV"; Base::incl_main_tag_err_inv = "INCL_MAIN_TAG_ERR_INV"; Base::incl_mem_tag_err_inv = "INCL_MEM_TAG_ERR_INV"; Base::lookup_mem_rng_chk_lo_inv = "LOOKUP_MEM_RNG_CHK_LO_INV"; @@ -2275,10 +2275,10 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::range_check_l2_gas_lo_counts = "RANGE_CHECK_L2_GAS_LO_COUNTS"; Base::range_check_da_gas_hi_counts = "RANGE_CHECK_DA_GAS_HI_COUNTS"; Base::range_check_da_gas_lo_counts = "RANGE_CHECK_DA_GAS_LO_COUNTS"; - Base::lookup_cd_value_counts = "LOOKUP_CD_VALUE_COUNTS"; - Base::lookup_ret_value_counts = "LOOKUP_RET_VALUE_COUNTS"; Base::kernel_output_lookup_counts = "KERNEL_OUTPUT_LOOKUP_COUNTS"; Base::lookup_into_kernel_counts = "LOOKUP_INTO_KERNEL_COUNTS"; + Base::lookup_cd_value_counts = "LOOKUP_CD_VALUE_COUNTS"; + Base::lookup_ret_value_counts = "LOOKUP_RET_VALUE_COUNTS"; Base::incl_main_tag_err_counts = "INCL_MAIN_TAG_ERR_COUNTS"; Base::incl_mem_tag_err_counts = "INCL_MEM_TAG_ERR_COUNTS"; Base::lookup_mem_rng_chk_lo_counts = "LOOKUP_MEM_RNG_CHK_LO_COUNTS"; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp index 739a85d4cef..a88d98f21a2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp @@ -10,7 +10,6 @@ #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" -#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" #include "barretenberg/vm/avm/generated/flavor_settings.hpp" @@ -103,10 +102,10 @@ template using tuple_cat_t = decltype(std::tuple_cat(std:: // The entities that will be used in the flavor. // clang-format off #define PRECOMPUTED_ENTITIES byte_lookup_sel_bin, byte_lookup_table_byte_lengths, byte_lookup_table_in_tags, byte_lookup_table_input_a, byte_lookup_table_input_b, byte_lookup_table_op_id, byte_lookup_table_output, gas_base_da_gas_fixed_table, gas_base_l2_gas_fixed_table, gas_dyn_da_gas_fixed_table, gas_dyn_l2_gas_fixed_table, gas_sel_gas_cost, main_clk, main_sel_first, main_zeroes, powers_power_of_2 -#define WIRE_ENTITIES kernel_kernel_inputs, kernel_kernel_value_out, kernel_kernel_side_effect_out, kernel_kernel_metadata_out, main_calldata, main_returndata, alu_a_hi, alu_a_lo, alu_b_hi, alu_b_lo, alu_borrow, alu_cf, alu_clk, alu_cmp_rng_ctr, alu_div_u16_r0, alu_div_u16_r1, alu_div_u16_r2, alu_div_u16_r3, alu_div_u16_r4, alu_div_u16_r5, alu_div_u16_r6, alu_div_u16_r7, alu_divisor_hi, alu_divisor_lo, alu_ff_tag, alu_ia, alu_ib, alu_ic, alu_in_tag, alu_op_add, alu_op_cast, alu_op_cast_prev, alu_op_div, alu_op_div_a_lt_b, alu_op_div_std, alu_op_eq, alu_op_eq_diff_inv, alu_op_lt, alu_op_lte, alu_op_mul, alu_op_not, alu_op_shl, alu_op_shr, alu_op_sub, alu_p_a_borrow, alu_p_b_borrow, alu_p_sub_a_hi, alu_p_sub_a_lo, alu_p_sub_b_hi, alu_p_sub_b_lo, alu_partial_prod_hi, alu_partial_prod_lo, alu_quotient_hi, alu_quotient_lo, alu_remainder, alu_res_hi, alu_res_lo, alu_sel_alu, alu_sel_cmp, alu_sel_div_rng_chk, alu_sel_rng_chk, alu_sel_rng_chk_lookup, alu_sel_shift_which, alu_shift_lt_bit_len, alu_t_sub_s_bits, alu_two_pow_s, alu_two_pow_t_sub_s, alu_u128_tag, alu_u16_r0, alu_u16_r1, alu_u16_r10, alu_u16_r11, alu_u16_r12, alu_u16_r13, alu_u16_r14, alu_u16_r2, alu_u16_r3, alu_u16_r4, alu_u16_r5, alu_u16_r6, alu_u16_r7, alu_u16_r8, alu_u16_r9, alu_u16_tag, alu_u32_tag, alu_u64_tag, alu_u8_r0, alu_u8_r1, alu_u8_tag, binary_acc_ia, binary_acc_ib, binary_acc_ic, binary_clk, binary_ia_bytes, binary_ib_bytes, binary_ic_bytes, binary_in_tag, binary_mem_tag_ctr, binary_mem_tag_ctr_inv, binary_op_id, binary_sel_bin, binary_start, conversion_clk, conversion_input, conversion_num_limbs, conversion_radix, conversion_sel_to_radix_le, keccakf1600_clk, keccakf1600_input, keccakf1600_output, keccakf1600_sel_keccakf1600, kernel_emit_l2_to_l1_msg_write_offset, kernel_emit_note_hash_write_offset, kernel_emit_nullifier_write_offset, kernel_emit_unencrypted_log_write_offset, kernel_kernel_in_offset, kernel_kernel_out_offset, kernel_l1_to_l2_msg_exists_write_offset, kernel_note_hash_exist_write_offset, kernel_nullifier_exists_write_offset, kernel_nullifier_non_exists_write_offset, kernel_q_public_input_kernel_add_to_table, kernel_q_public_input_kernel_out_add_to_table, kernel_side_effect_counter, kernel_sload_write_offset, kernel_sstore_write_offset, main_abs_da_rem_gas_hi, main_abs_da_rem_gas_lo, main_abs_l2_rem_gas_hi, main_abs_l2_rem_gas_lo, main_alu_in_tag, main_base_da_gas_op_cost, main_base_l2_gas_op_cost, main_bin_op_id, main_call_ptr, main_da_gas_remaining, main_da_out_of_gas, main_dyn_da_gas_op_cost, main_dyn_gas_multiplier, main_dyn_l2_gas_op_cost, main_ia, main_ib, main_ic, main_id, main_id_zero, main_ind_addr_a, main_ind_addr_b, main_ind_addr_c, main_ind_addr_d, main_internal_return_ptr, main_inv, main_l2_gas_remaining, main_l2_out_of_gas, main_mem_addr_a, main_mem_addr_b, main_mem_addr_c, main_mem_addr_d, main_op_err, main_opcode_val, main_pc, main_r_in_tag, main_rwa, main_rwb, main_rwc, main_rwd, main_sel_alu, main_sel_bin, main_sel_calldata, main_sel_execution_row, main_sel_last, main_sel_mem_op_a, main_sel_mem_op_b, main_sel_mem_op_c, main_sel_mem_op_d, main_sel_mov_ia_to_ic, main_sel_mov_ib_to_ic, main_sel_op_add, main_sel_op_address, main_sel_op_and, main_sel_op_block_number, main_sel_op_calldata_copy, main_sel_op_cast, main_sel_op_chain_id, main_sel_op_cmov, main_sel_op_coinbase, main_sel_op_dagasleft, main_sel_op_div, main_sel_op_ecadd, main_sel_op_emit_l2_to_l1_msg, main_sel_op_emit_note_hash, main_sel_op_emit_nullifier, main_sel_op_emit_unencrypted_log, main_sel_op_eq, main_sel_op_external_call, main_sel_op_external_return, main_sel_op_external_revert, main_sel_op_fdiv, main_sel_op_fee_per_da_gas, main_sel_op_fee_per_l2_gas, main_sel_op_function_selector, main_sel_op_get_contract_instance, main_sel_op_internal_call, main_sel_op_internal_return, main_sel_op_jump, main_sel_op_jumpi, main_sel_op_keccak, main_sel_op_l1_to_l2_msg_exists, main_sel_op_l2gasleft, main_sel_op_lt, main_sel_op_lte, main_sel_op_mov, main_sel_op_msm, main_sel_op_mul, main_sel_op_not, main_sel_op_note_hash_exists, main_sel_op_nullifier_exists, main_sel_op_or, main_sel_op_pedersen, main_sel_op_pedersen_commit, main_sel_op_poseidon2, main_sel_op_radix_le, main_sel_op_sender, main_sel_op_set, main_sel_op_sha256, main_sel_op_shl, main_sel_op_shr, main_sel_op_sload, main_sel_op_sstore, main_sel_op_storage_address, main_sel_op_sub, main_sel_op_timestamp, main_sel_op_transaction_fee, main_sel_op_version, main_sel_op_xor, main_sel_q_kernel_lookup, main_sel_q_kernel_output_lookup, main_sel_resolve_ind_addr_a, main_sel_resolve_ind_addr_b, main_sel_resolve_ind_addr_c, main_sel_resolve_ind_addr_d, main_sel_returndata, main_sel_rng_16, main_sel_rng_8, main_sel_slice_gadget, main_space_id, main_tag_err, main_w_in_tag, mem_addr, mem_clk, mem_diff_hi, mem_diff_lo, mem_diff_mid, mem_glob_addr, mem_last, mem_lastAccess, mem_one_min_inv, mem_r_in_tag, mem_rw, mem_sel_mem, mem_sel_mov_ia_to_ic, mem_sel_mov_ib_to_ic, mem_sel_op_a, mem_sel_op_b, mem_sel_op_c, mem_sel_op_cmov, mem_sel_op_d, mem_sel_op_poseidon_read_a, mem_sel_op_poseidon_read_b, mem_sel_op_poseidon_read_c, mem_sel_op_poseidon_read_d, mem_sel_op_poseidon_write_a, mem_sel_op_poseidon_write_b, mem_sel_op_poseidon_write_c, mem_sel_op_poseidon_write_d, mem_sel_op_slice, mem_sel_resolve_ind_addr_a, mem_sel_resolve_ind_addr_b, mem_sel_resolve_ind_addr_c, mem_sel_resolve_ind_addr_d, mem_sel_rng_chk, mem_skip_check_tag, mem_space_id, mem_tag, mem_tag_err, mem_tsp, mem_val, mem_w_in_tag, pedersen_clk, pedersen_input, pedersen_output, pedersen_sel_pedersen, poseidon2_B_10_0, poseidon2_B_10_1, poseidon2_B_10_2, poseidon2_B_10_3, poseidon2_B_11_0, poseidon2_B_11_1, poseidon2_B_11_2, poseidon2_B_11_3, poseidon2_B_12_0, poseidon2_B_12_1, poseidon2_B_12_2, poseidon2_B_12_3, poseidon2_B_13_0, poseidon2_B_13_1, poseidon2_B_13_2, poseidon2_B_13_3, poseidon2_B_14_0, poseidon2_B_14_1, poseidon2_B_14_2, poseidon2_B_14_3, poseidon2_B_15_0, poseidon2_B_15_1, poseidon2_B_15_2, poseidon2_B_15_3, poseidon2_B_16_0, poseidon2_B_16_1, poseidon2_B_16_2, poseidon2_B_16_3, poseidon2_B_17_0, poseidon2_B_17_1, poseidon2_B_17_2, poseidon2_B_17_3, poseidon2_B_18_0, poseidon2_B_18_1, poseidon2_B_18_2, poseidon2_B_18_3, poseidon2_B_19_0, poseidon2_B_19_1, poseidon2_B_19_2, poseidon2_B_19_3, poseidon2_B_20_0, poseidon2_B_20_1, poseidon2_B_20_2, poseidon2_B_20_3, poseidon2_B_21_0, poseidon2_B_21_1, poseidon2_B_21_2, poseidon2_B_21_3, poseidon2_B_22_0, poseidon2_B_22_1, poseidon2_B_22_2, poseidon2_B_22_3, poseidon2_B_23_0, poseidon2_B_23_1, poseidon2_B_23_2, poseidon2_B_23_3, poseidon2_B_24_0, poseidon2_B_24_1, poseidon2_B_24_2, poseidon2_B_24_3, poseidon2_B_25_0, poseidon2_B_25_1, poseidon2_B_25_2, poseidon2_B_25_3, poseidon2_B_26_0, poseidon2_B_26_1, poseidon2_B_26_2, poseidon2_B_26_3, poseidon2_B_27_0, poseidon2_B_27_1, poseidon2_B_27_2, poseidon2_B_27_3, poseidon2_B_28_0, poseidon2_B_28_1, poseidon2_B_28_2, poseidon2_B_28_3, poseidon2_B_29_0, poseidon2_B_29_1, poseidon2_B_29_2, poseidon2_B_29_3, poseidon2_B_30_0, poseidon2_B_30_1, poseidon2_B_30_2, poseidon2_B_30_3, poseidon2_B_31_0, poseidon2_B_31_1, poseidon2_B_31_2, poseidon2_B_31_3, poseidon2_B_32_0, poseidon2_B_32_1, poseidon2_B_32_2, poseidon2_B_32_3, poseidon2_B_33_0, poseidon2_B_33_1, poseidon2_B_33_2, poseidon2_B_33_3, poseidon2_B_34_0, poseidon2_B_34_1, poseidon2_B_34_2, poseidon2_B_34_3, poseidon2_B_35_0, poseidon2_B_35_1, poseidon2_B_35_2, poseidon2_B_35_3, poseidon2_B_36_0, poseidon2_B_36_1, poseidon2_B_36_2, poseidon2_B_36_3, poseidon2_B_37_0, poseidon2_B_37_1, poseidon2_B_37_2, poseidon2_B_37_3, poseidon2_B_38_0, poseidon2_B_38_1, poseidon2_B_38_2, poseidon2_B_38_3, poseidon2_B_39_0, poseidon2_B_39_1, poseidon2_B_39_2, poseidon2_B_39_3, poseidon2_B_40_0, poseidon2_B_40_1, poseidon2_B_40_2, poseidon2_B_40_3, poseidon2_B_41_0, poseidon2_B_41_1, poseidon2_B_41_2, poseidon2_B_41_3, poseidon2_B_42_0, poseidon2_B_42_1, poseidon2_B_42_2, poseidon2_B_42_3, poseidon2_B_43_0, poseidon2_B_43_1, poseidon2_B_43_2, poseidon2_B_43_3, poseidon2_B_44_0, poseidon2_B_44_1, poseidon2_B_44_2, poseidon2_B_44_3, poseidon2_B_45_0, poseidon2_B_45_1, poseidon2_B_45_2, poseidon2_B_45_3, poseidon2_B_46_0, poseidon2_B_46_1, poseidon2_B_46_2, poseidon2_B_46_3, poseidon2_B_47_0, poseidon2_B_47_1, poseidon2_B_47_2, poseidon2_B_47_3, poseidon2_B_48_0, poseidon2_B_48_1, poseidon2_B_48_2, poseidon2_B_48_3, poseidon2_B_49_0, poseidon2_B_49_1, poseidon2_B_49_2, poseidon2_B_49_3, poseidon2_B_4_0, poseidon2_B_4_1, poseidon2_B_4_2, poseidon2_B_4_3, poseidon2_B_50_0, poseidon2_B_50_1, poseidon2_B_50_2, poseidon2_B_50_3, poseidon2_B_51_0, poseidon2_B_51_1, poseidon2_B_51_2, poseidon2_B_51_3, poseidon2_B_52_0, poseidon2_B_52_1, poseidon2_B_52_2, poseidon2_B_52_3, poseidon2_B_53_0, poseidon2_B_53_1, poseidon2_B_53_2, poseidon2_B_53_3, poseidon2_B_54_0, poseidon2_B_54_1, poseidon2_B_54_2, poseidon2_B_54_3, poseidon2_B_55_0, poseidon2_B_55_1, poseidon2_B_55_2, poseidon2_B_55_3, poseidon2_B_56_0, poseidon2_B_56_1, poseidon2_B_56_2, poseidon2_B_56_3, poseidon2_B_57_0, poseidon2_B_57_1, poseidon2_B_57_2, poseidon2_B_57_3, poseidon2_B_58_0, poseidon2_B_58_1, poseidon2_B_58_2, poseidon2_B_58_3, poseidon2_B_59_0, poseidon2_B_59_1, poseidon2_B_59_2, poseidon2_B_59_3, poseidon2_B_5_0, poseidon2_B_5_1, poseidon2_B_5_2, poseidon2_B_5_3, poseidon2_B_6_0, poseidon2_B_6_1, poseidon2_B_6_2, poseidon2_B_6_3, poseidon2_B_7_0, poseidon2_B_7_1, poseidon2_B_7_2, poseidon2_B_7_3, poseidon2_B_8_0, poseidon2_B_8_1, poseidon2_B_8_2, poseidon2_B_8_3, poseidon2_B_9_0, poseidon2_B_9_1, poseidon2_B_9_2, poseidon2_B_9_3, poseidon2_EXT_LAYER_4, poseidon2_EXT_LAYER_5, poseidon2_EXT_LAYER_6, poseidon2_EXT_LAYER_7, poseidon2_T_0_4, poseidon2_T_0_5, poseidon2_T_0_6, poseidon2_T_0_7, poseidon2_T_1_4, poseidon2_T_1_5, poseidon2_T_1_6, poseidon2_T_1_7, poseidon2_T_2_4, poseidon2_T_2_5, poseidon2_T_2_6, poseidon2_T_2_7, poseidon2_T_3_4, poseidon2_T_3_5, poseidon2_T_3_6, poseidon2_T_3_7, poseidon2_T_60_4, poseidon2_T_60_5, poseidon2_T_60_6, poseidon2_T_60_7, poseidon2_T_61_4, poseidon2_T_61_5, poseidon2_T_61_6, poseidon2_T_61_7, poseidon2_T_62_4, poseidon2_T_62_5, poseidon2_T_62_6, poseidon2_T_62_7, poseidon2_T_63_4, poseidon2_T_63_5, poseidon2_T_63_6, poseidon2_T_63_7, poseidon2_a_0, poseidon2_a_1, poseidon2_a_2, poseidon2_a_3, poseidon2_b_0, poseidon2_b_1, poseidon2_b_2, poseidon2_b_3, poseidon2_clk, poseidon2_input_addr, poseidon2_mem_addr_read_a, poseidon2_mem_addr_read_b, poseidon2_mem_addr_read_c, poseidon2_mem_addr_read_d, poseidon2_mem_addr_write_a, poseidon2_mem_addr_write_b, poseidon2_mem_addr_write_c, poseidon2_mem_addr_write_d, poseidon2_output_addr, poseidon2_sel_poseidon_perm, sha256_clk, sha256_input, sha256_output, sha256_sel_sha256_compression, sha256_state, slice_addr, slice_clk, slice_cnt, slice_col_offset, slice_one_min_inv, slice_sel_cd_cpy, slice_sel_mem_active, slice_sel_return, slice_sel_start, slice_space_id, slice_val, lookup_byte_lengths_counts, lookup_byte_operations_counts, lookup_opcode_gas_counts, range_check_l2_gas_hi_counts, range_check_l2_gas_lo_counts, range_check_da_gas_hi_counts, range_check_da_gas_lo_counts, lookup_cd_value_counts, lookup_ret_value_counts, kernel_output_lookup_counts, lookup_into_kernel_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts, lookup_mem_rng_chk_lo_counts, lookup_mem_rng_chk_mid_counts, lookup_mem_rng_chk_hi_counts, lookup_pow_2_0_counts, lookup_pow_2_1_counts, lookup_u8_0_counts, lookup_u8_1_counts, lookup_u16_0_counts, lookup_u16_1_counts, lookup_u16_2_counts, lookup_u16_3_counts, lookup_u16_4_counts, lookup_u16_5_counts, lookup_u16_6_counts, lookup_u16_7_counts, lookup_u16_8_counts, lookup_u16_9_counts, lookup_u16_10_counts, lookup_u16_11_counts, lookup_u16_12_counts, lookup_u16_13_counts, lookup_u16_14_counts, lookup_div_u16_0_counts, lookup_div_u16_1_counts, lookup_div_u16_2_counts, lookup_div_u16_3_counts, lookup_div_u16_4_counts, lookup_div_u16_5_counts, lookup_div_u16_6_counts, lookup_div_u16_7_counts -#define DERIVED_WITNESS_ENTITIES perm_pos_mem_read_a_inv, perm_pos_mem_read_b_inv, perm_pos_mem_read_c_inv, perm_pos_mem_read_d_inv, perm_pos_mem_write_a_inv, perm_pos_mem_write_b_inv, perm_pos_mem_write_c_inv, perm_pos_mem_write_d_inv, perm_slice_mem_inv, perm_main_alu_inv, perm_main_bin_inv, perm_main_conv_inv, perm_main_pos2_perm_inv, perm_main_pedersen_inv, perm_main_slice_inv, perm_main_mem_a_inv, perm_main_mem_b_inv, perm_main_mem_c_inv, perm_main_mem_d_inv, perm_main_mem_ind_addr_a_inv, perm_main_mem_ind_addr_b_inv, perm_main_mem_ind_addr_c_inv, perm_main_mem_ind_addr_d_inv, lookup_byte_lengths_inv, lookup_byte_operations_inv, lookup_opcode_gas_inv, range_check_l2_gas_hi_inv, range_check_l2_gas_lo_inv, range_check_da_gas_hi_inv, range_check_da_gas_lo_inv, lookup_cd_value_inv, lookup_ret_value_inv, kernel_output_lookup_inv, lookup_into_kernel_inv, incl_main_tag_err_inv, incl_mem_tag_err_inv, lookup_mem_rng_chk_lo_inv, lookup_mem_rng_chk_mid_inv, lookup_mem_rng_chk_hi_inv, lookup_pow_2_0_inv, lookup_pow_2_1_inv, lookup_u8_0_inv, lookup_u8_1_inv, lookup_u16_0_inv, lookup_u16_1_inv, lookup_u16_2_inv, lookup_u16_3_inv, lookup_u16_4_inv, lookup_u16_5_inv, lookup_u16_6_inv, lookup_u16_7_inv, lookup_u16_8_inv, lookup_u16_9_inv, lookup_u16_10_inv, lookup_u16_11_inv, lookup_u16_12_inv, lookup_u16_13_inv, lookup_u16_14_inv, lookup_div_u16_0_inv, lookup_div_u16_1_inv, lookup_div_u16_2_inv, lookup_div_u16_3_inv, lookup_div_u16_4_inv, lookup_div_u16_5_inv, lookup_div_u16_6_inv, lookup_div_u16_7_inv -#define SHIFTED_ENTITIES alu_div_u16_r1_shift, slice_clk_shift, alu_div_u16_r6_shift, kernel_nullifier_exists_write_offset_shift, mem_tsp_shift, main_internal_return_ptr_shift, main_sel_execution_row_shift, alu_sel_rng_chk_shift, alu_div_u16_r3_shift, kernel_emit_note_hash_write_offset_shift, alu_p_sub_b_hi_shift, slice_sel_return_shift, kernel_side_effect_counter_shift, alu_op_add_shift, alu_op_cast_shift, kernel_emit_nullifier_write_offset_shift, slice_cnt_shift, alu_sel_cmp_shift, alu_u16_r1_shift, binary_acc_ia_shift, alu_div_u16_r0_shift, kernel_l1_to_l2_msg_exists_write_offset_shift, alu_a_hi_shift, alu_div_u16_r5_shift, kernel_emit_unencrypted_log_write_offset_shift, mem_val_shift, slice_sel_start_shift, binary_acc_ic_shift, alu_sel_div_rng_chk_shift, alu_u16_r6_shift, alu_op_shr_shift, slice_space_id_shift, mem_tag_shift, alu_op_mul_shift, binary_mem_tag_ctr_shift, kernel_emit_l2_to_l1_msg_write_offset_shift, alu_sel_alu_shift, mem_rw_shift, mem_glob_addr_shift, alu_u16_r3_shift, kernel_sstore_write_offset_shift, mem_sel_mem_shift, slice_sel_mem_active_shift, alu_op_shl_shift, alu_b_hi_shift, alu_cmp_rng_ctr_shift, alu_op_cast_prev_shift, alu_sel_rng_chk_lookup_shift, slice_sel_cd_cpy_shift, main_pc_shift, alu_u8_r1_shift, alu_p_sub_a_lo_shift, main_da_gas_remaining_shift, alu_b_lo_shift, alu_u8_r0_shift, alu_p_sub_b_lo_shift, kernel_nullifier_non_exists_write_offset_shift, alu_u16_r4_shift, binary_acc_ib_shift, alu_u16_r0_shift, alu_div_u16_r2_shift, alu_op_div_shift, alu_a_lo_shift, alu_op_sub_shift, alu_div_u16_r7_shift, alu_u16_r5_shift, alu_u16_r2_shift, kernel_note_hash_exist_write_offset_shift, main_l2_gas_remaining_shift, kernel_sload_write_offset_shift, slice_addr_shift, binary_op_id_shift, alu_p_sub_a_hi_shift, slice_col_offset_shift, alu_div_u16_r4_shift -#define TO_BE_SHIFTED(e) e.alu_div_u16_r1, e.slice_clk, e.alu_div_u16_r6, e.kernel_nullifier_exists_write_offset, e.mem_tsp, e.main_internal_return_ptr, e.main_sel_execution_row, e.alu_sel_rng_chk, e.alu_div_u16_r3, e.kernel_emit_note_hash_write_offset, e.alu_p_sub_b_hi, e.slice_sel_return, e.kernel_side_effect_counter, e.alu_op_add, e.alu_op_cast, e.kernel_emit_nullifier_write_offset, e.slice_cnt, e.alu_sel_cmp, e.alu_u16_r1, e.binary_acc_ia, e.alu_div_u16_r0, e.kernel_l1_to_l2_msg_exists_write_offset, e.alu_a_hi, e.alu_div_u16_r5, e.kernel_emit_unencrypted_log_write_offset, e.mem_val, e.slice_sel_start, e.binary_acc_ic, e.alu_sel_div_rng_chk, e.alu_u16_r6, e.alu_op_shr, e.slice_space_id, e.mem_tag, e.alu_op_mul, e.binary_mem_tag_ctr, e.kernel_emit_l2_to_l1_msg_write_offset, e.alu_sel_alu, e.mem_rw, e.mem_glob_addr, e.alu_u16_r3, e.kernel_sstore_write_offset, e.mem_sel_mem, e.slice_sel_mem_active, e.alu_op_shl, e.alu_b_hi, e.alu_cmp_rng_ctr, e.alu_op_cast_prev, e.alu_sel_rng_chk_lookup, e.slice_sel_cd_cpy, e.main_pc, e.alu_u8_r1, e.alu_p_sub_a_lo, e.main_da_gas_remaining, e.alu_b_lo, e.alu_u8_r0, e.alu_p_sub_b_lo, e.kernel_nullifier_non_exists_write_offset, e.alu_u16_r4, e.binary_acc_ib, e.alu_u16_r0, e.alu_div_u16_r2, e.alu_op_div, e.alu_a_lo, e.alu_op_sub, e.alu_div_u16_r7, e.alu_u16_r5, e.alu_u16_r2, e.kernel_note_hash_exist_write_offset, e.main_l2_gas_remaining, e.kernel_sload_write_offset, e.slice_addr, e.binary_op_id, e.alu_p_sub_a_hi, e.slice_col_offset, e.alu_div_u16_r4 +#define WIRE_ENTITIES main_kernel_inputs, main_kernel_value_out, main_kernel_side_effect_out, main_kernel_metadata_out, main_calldata, main_returndata, alu_a_hi, alu_a_lo, alu_b_hi, alu_b_lo, alu_borrow, alu_cf, alu_clk, alu_cmp_rng_ctr, alu_div_u16_r0, alu_div_u16_r1, alu_div_u16_r2, alu_div_u16_r3, alu_div_u16_r4, alu_div_u16_r5, alu_div_u16_r6, alu_div_u16_r7, alu_divisor_hi, alu_divisor_lo, alu_ff_tag, alu_ia, alu_ib, alu_ic, alu_in_tag, alu_op_add, alu_op_cast, alu_op_cast_prev, alu_op_div, alu_op_div_a_lt_b, alu_op_div_std, alu_op_eq, alu_op_eq_diff_inv, alu_op_lt, alu_op_lte, alu_op_mul, alu_op_not, alu_op_shl, alu_op_shr, alu_op_sub, alu_p_a_borrow, alu_p_b_borrow, alu_p_sub_a_hi, alu_p_sub_a_lo, alu_p_sub_b_hi, alu_p_sub_b_lo, alu_partial_prod_hi, alu_partial_prod_lo, alu_quotient_hi, alu_quotient_lo, alu_remainder, alu_res_hi, alu_res_lo, alu_sel_alu, alu_sel_cmp, alu_sel_div_rng_chk, alu_sel_rng_chk, alu_sel_rng_chk_lookup, alu_sel_shift_which, alu_shift_lt_bit_len, alu_t_sub_s_bits, alu_two_pow_s, alu_two_pow_t_sub_s, alu_u128_tag, alu_u16_r0, alu_u16_r1, alu_u16_r10, alu_u16_r11, alu_u16_r12, alu_u16_r13, alu_u16_r14, alu_u16_r2, alu_u16_r3, alu_u16_r4, alu_u16_r5, alu_u16_r6, alu_u16_r7, alu_u16_r8, alu_u16_r9, alu_u16_tag, alu_u32_tag, alu_u64_tag, alu_u8_r0, alu_u8_r1, alu_u8_tag, binary_acc_ia, binary_acc_ib, binary_acc_ic, binary_clk, binary_ia_bytes, binary_ib_bytes, binary_ic_bytes, binary_in_tag, binary_mem_tag_ctr, binary_mem_tag_ctr_inv, binary_op_id, binary_sel_bin, binary_start, conversion_clk, conversion_input, conversion_num_limbs, conversion_radix, conversion_sel_to_radix_le, keccakf1600_clk, keccakf1600_input, keccakf1600_output, keccakf1600_sel_keccakf1600, main_abs_da_rem_gas_hi, main_abs_da_rem_gas_lo, main_abs_l2_rem_gas_hi, main_abs_l2_rem_gas_lo, main_alu_in_tag, main_base_da_gas_op_cost, main_base_l2_gas_op_cost, main_bin_op_id, main_call_ptr, main_da_gas_remaining, main_da_out_of_gas, main_dyn_da_gas_op_cost, main_dyn_gas_multiplier, main_dyn_l2_gas_op_cost, main_emit_l2_to_l1_msg_write_offset, main_emit_note_hash_write_offset, main_emit_nullifier_write_offset, main_emit_unencrypted_log_write_offset, main_ia, main_ib, main_ic, main_id, main_id_zero, main_ind_addr_a, main_ind_addr_b, main_ind_addr_c, main_ind_addr_d, main_internal_return_ptr, main_inv, main_kernel_in_offset, main_kernel_out_offset, main_l1_to_l2_msg_exists_write_offset, main_l2_gas_remaining, main_l2_out_of_gas, main_mem_addr_a, main_mem_addr_b, main_mem_addr_c, main_mem_addr_d, main_note_hash_exist_write_offset, main_nullifier_exists_write_offset, main_nullifier_non_exists_write_offset, main_op_err, main_opcode_val, main_pc, main_r_in_tag, main_rwa, main_rwb, main_rwc, main_rwd, main_sel_alu, main_sel_bin, main_sel_calldata, main_sel_execution_row, main_sel_kernel_inputs, main_sel_kernel_out, main_sel_last, main_sel_mem_op_a, main_sel_mem_op_b, main_sel_mem_op_c, main_sel_mem_op_d, main_sel_mov_ia_to_ic, main_sel_mov_ib_to_ic, main_sel_op_add, main_sel_op_address, main_sel_op_and, main_sel_op_block_number, main_sel_op_calldata_copy, main_sel_op_cast, main_sel_op_chain_id, main_sel_op_cmov, main_sel_op_coinbase, main_sel_op_dagasleft, main_sel_op_div, main_sel_op_ecadd, main_sel_op_emit_l2_to_l1_msg, main_sel_op_emit_note_hash, main_sel_op_emit_nullifier, main_sel_op_emit_unencrypted_log, main_sel_op_eq, main_sel_op_external_call, main_sel_op_external_return, main_sel_op_external_revert, main_sel_op_fdiv, main_sel_op_fee_per_da_gas, main_sel_op_fee_per_l2_gas, main_sel_op_function_selector, main_sel_op_get_contract_instance, main_sel_op_internal_call, main_sel_op_internal_return, main_sel_op_jump, main_sel_op_jumpi, main_sel_op_keccak, main_sel_op_l1_to_l2_msg_exists, main_sel_op_l2gasleft, main_sel_op_lt, main_sel_op_lte, main_sel_op_mov, main_sel_op_msm, main_sel_op_mul, main_sel_op_not, main_sel_op_note_hash_exists, main_sel_op_nullifier_exists, main_sel_op_or, main_sel_op_pedersen, main_sel_op_pedersen_commit, main_sel_op_poseidon2, main_sel_op_radix_le, main_sel_op_sender, main_sel_op_set, main_sel_op_sha256, main_sel_op_shl, main_sel_op_shr, main_sel_op_sload, main_sel_op_sstore, main_sel_op_storage_address, main_sel_op_sub, main_sel_op_timestamp, main_sel_op_transaction_fee, main_sel_op_version, main_sel_op_xor, main_sel_q_kernel_lookup, main_sel_q_kernel_output_lookup, main_sel_resolve_ind_addr_a, main_sel_resolve_ind_addr_b, main_sel_resolve_ind_addr_c, main_sel_resolve_ind_addr_d, main_sel_returndata, main_sel_rng_16, main_sel_rng_8, main_sel_slice_gadget, main_side_effect_counter, main_sload_write_offset, main_space_id, main_sstore_write_offset, main_tag_err, main_w_in_tag, mem_addr, mem_clk, mem_diff_hi, mem_diff_lo, mem_diff_mid, mem_glob_addr, mem_last, mem_lastAccess, mem_one_min_inv, mem_r_in_tag, mem_rw, mem_sel_mem, mem_sel_mov_ia_to_ic, mem_sel_mov_ib_to_ic, mem_sel_op_a, mem_sel_op_b, mem_sel_op_c, mem_sel_op_cmov, mem_sel_op_d, mem_sel_op_poseidon_read_a, mem_sel_op_poseidon_read_b, mem_sel_op_poseidon_read_c, mem_sel_op_poseidon_read_d, mem_sel_op_poseidon_write_a, mem_sel_op_poseidon_write_b, mem_sel_op_poseidon_write_c, mem_sel_op_poseidon_write_d, mem_sel_op_slice, mem_sel_resolve_ind_addr_a, mem_sel_resolve_ind_addr_b, mem_sel_resolve_ind_addr_c, mem_sel_resolve_ind_addr_d, mem_sel_rng_chk, mem_skip_check_tag, mem_space_id, mem_tag, mem_tag_err, mem_tsp, mem_val, mem_w_in_tag, pedersen_clk, pedersen_input, pedersen_output, pedersen_sel_pedersen, poseidon2_B_10_0, poseidon2_B_10_1, poseidon2_B_10_2, poseidon2_B_10_3, poseidon2_B_11_0, poseidon2_B_11_1, poseidon2_B_11_2, poseidon2_B_11_3, poseidon2_B_12_0, poseidon2_B_12_1, poseidon2_B_12_2, poseidon2_B_12_3, poseidon2_B_13_0, poseidon2_B_13_1, poseidon2_B_13_2, poseidon2_B_13_3, poseidon2_B_14_0, poseidon2_B_14_1, poseidon2_B_14_2, poseidon2_B_14_3, poseidon2_B_15_0, poseidon2_B_15_1, poseidon2_B_15_2, poseidon2_B_15_3, poseidon2_B_16_0, poseidon2_B_16_1, poseidon2_B_16_2, poseidon2_B_16_3, poseidon2_B_17_0, poseidon2_B_17_1, poseidon2_B_17_2, poseidon2_B_17_3, poseidon2_B_18_0, poseidon2_B_18_1, poseidon2_B_18_2, poseidon2_B_18_3, poseidon2_B_19_0, poseidon2_B_19_1, poseidon2_B_19_2, poseidon2_B_19_3, poseidon2_B_20_0, poseidon2_B_20_1, poseidon2_B_20_2, poseidon2_B_20_3, poseidon2_B_21_0, poseidon2_B_21_1, poseidon2_B_21_2, poseidon2_B_21_3, poseidon2_B_22_0, poseidon2_B_22_1, poseidon2_B_22_2, poseidon2_B_22_3, poseidon2_B_23_0, poseidon2_B_23_1, poseidon2_B_23_2, poseidon2_B_23_3, poseidon2_B_24_0, poseidon2_B_24_1, poseidon2_B_24_2, poseidon2_B_24_3, poseidon2_B_25_0, poseidon2_B_25_1, poseidon2_B_25_2, poseidon2_B_25_3, poseidon2_B_26_0, poseidon2_B_26_1, poseidon2_B_26_2, poseidon2_B_26_3, poseidon2_B_27_0, poseidon2_B_27_1, poseidon2_B_27_2, poseidon2_B_27_3, poseidon2_B_28_0, poseidon2_B_28_1, poseidon2_B_28_2, poseidon2_B_28_3, poseidon2_B_29_0, poseidon2_B_29_1, poseidon2_B_29_2, poseidon2_B_29_3, poseidon2_B_30_0, poseidon2_B_30_1, poseidon2_B_30_2, poseidon2_B_30_3, poseidon2_B_31_0, poseidon2_B_31_1, poseidon2_B_31_2, poseidon2_B_31_3, poseidon2_B_32_0, poseidon2_B_32_1, poseidon2_B_32_2, poseidon2_B_32_3, poseidon2_B_33_0, poseidon2_B_33_1, poseidon2_B_33_2, poseidon2_B_33_3, poseidon2_B_34_0, poseidon2_B_34_1, poseidon2_B_34_2, poseidon2_B_34_3, poseidon2_B_35_0, poseidon2_B_35_1, poseidon2_B_35_2, poseidon2_B_35_3, poseidon2_B_36_0, poseidon2_B_36_1, poseidon2_B_36_2, poseidon2_B_36_3, poseidon2_B_37_0, poseidon2_B_37_1, poseidon2_B_37_2, poseidon2_B_37_3, poseidon2_B_38_0, poseidon2_B_38_1, poseidon2_B_38_2, poseidon2_B_38_3, poseidon2_B_39_0, poseidon2_B_39_1, poseidon2_B_39_2, poseidon2_B_39_3, poseidon2_B_40_0, poseidon2_B_40_1, poseidon2_B_40_2, poseidon2_B_40_3, poseidon2_B_41_0, poseidon2_B_41_1, poseidon2_B_41_2, poseidon2_B_41_3, poseidon2_B_42_0, poseidon2_B_42_1, poseidon2_B_42_2, poseidon2_B_42_3, poseidon2_B_43_0, poseidon2_B_43_1, poseidon2_B_43_2, poseidon2_B_43_3, poseidon2_B_44_0, poseidon2_B_44_1, poseidon2_B_44_2, poseidon2_B_44_3, poseidon2_B_45_0, poseidon2_B_45_1, poseidon2_B_45_2, poseidon2_B_45_3, poseidon2_B_46_0, poseidon2_B_46_1, poseidon2_B_46_2, poseidon2_B_46_3, poseidon2_B_47_0, poseidon2_B_47_1, poseidon2_B_47_2, poseidon2_B_47_3, poseidon2_B_48_0, poseidon2_B_48_1, poseidon2_B_48_2, poseidon2_B_48_3, poseidon2_B_49_0, poseidon2_B_49_1, poseidon2_B_49_2, poseidon2_B_49_3, poseidon2_B_4_0, poseidon2_B_4_1, poseidon2_B_4_2, poseidon2_B_4_3, poseidon2_B_50_0, poseidon2_B_50_1, poseidon2_B_50_2, poseidon2_B_50_3, poseidon2_B_51_0, poseidon2_B_51_1, poseidon2_B_51_2, poseidon2_B_51_3, poseidon2_B_52_0, poseidon2_B_52_1, poseidon2_B_52_2, poseidon2_B_52_3, poseidon2_B_53_0, poseidon2_B_53_1, poseidon2_B_53_2, poseidon2_B_53_3, poseidon2_B_54_0, poseidon2_B_54_1, poseidon2_B_54_2, poseidon2_B_54_3, poseidon2_B_55_0, poseidon2_B_55_1, poseidon2_B_55_2, poseidon2_B_55_3, poseidon2_B_56_0, poseidon2_B_56_1, poseidon2_B_56_2, poseidon2_B_56_3, poseidon2_B_57_0, poseidon2_B_57_1, poseidon2_B_57_2, poseidon2_B_57_3, poseidon2_B_58_0, poseidon2_B_58_1, poseidon2_B_58_2, poseidon2_B_58_3, poseidon2_B_59_0, poseidon2_B_59_1, poseidon2_B_59_2, poseidon2_B_59_3, poseidon2_B_5_0, poseidon2_B_5_1, poseidon2_B_5_2, poseidon2_B_5_3, poseidon2_B_6_0, poseidon2_B_6_1, poseidon2_B_6_2, poseidon2_B_6_3, poseidon2_B_7_0, poseidon2_B_7_1, poseidon2_B_7_2, poseidon2_B_7_3, poseidon2_B_8_0, poseidon2_B_8_1, poseidon2_B_8_2, poseidon2_B_8_3, poseidon2_B_9_0, poseidon2_B_9_1, poseidon2_B_9_2, poseidon2_B_9_3, poseidon2_EXT_LAYER_4, poseidon2_EXT_LAYER_5, poseidon2_EXT_LAYER_6, poseidon2_EXT_LAYER_7, poseidon2_T_0_4, poseidon2_T_0_5, poseidon2_T_0_6, poseidon2_T_0_7, poseidon2_T_1_4, poseidon2_T_1_5, poseidon2_T_1_6, poseidon2_T_1_7, poseidon2_T_2_4, poseidon2_T_2_5, poseidon2_T_2_6, poseidon2_T_2_7, poseidon2_T_3_4, poseidon2_T_3_5, poseidon2_T_3_6, poseidon2_T_3_7, poseidon2_T_60_4, poseidon2_T_60_5, poseidon2_T_60_6, poseidon2_T_60_7, poseidon2_T_61_4, poseidon2_T_61_5, poseidon2_T_61_6, poseidon2_T_61_7, poseidon2_T_62_4, poseidon2_T_62_5, poseidon2_T_62_6, poseidon2_T_62_7, poseidon2_T_63_4, poseidon2_T_63_5, poseidon2_T_63_6, poseidon2_T_63_7, poseidon2_a_0, poseidon2_a_1, poseidon2_a_2, poseidon2_a_3, poseidon2_b_0, poseidon2_b_1, poseidon2_b_2, poseidon2_b_3, poseidon2_clk, poseidon2_input_addr, poseidon2_mem_addr_read_a, poseidon2_mem_addr_read_b, poseidon2_mem_addr_read_c, poseidon2_mem_addr_read_d, poseidon2_mem_addr_write_a, poseidon2_mem_addr_write_b, poseidon2_mem_addr_write_c, poseidon2_mem_addr_write_d, poseidon2_output_addr, poseidon2_sel_poseidon_perm, sha256_clk, sha256_input, sha256_output, sha256_sel_sha256_compression, sha256_state, slice_addr, slice_clk, slice_cnt, slice_col_offset, slice_one_min_inv, slice_sel_cd_cpy, slice_sel_mem_active, slice_sel_return, slice_sel_start, slice_space_id, slice_val, lookup_byte_lengths_counts, lookup_byte_operations_counts, lookup_opcode_gas_counts, range_check_l2_gas_hi_counts, range_check_l2_gas_lo_counts, range_check_da_gas_hi_counts, range_check_da_gas_lo_counts, kernel_output_lookup_counts, lookup_into_kernel_counts, lookup_cd_value_counts, lookup_ret_value_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts, lookup_mem_rng_chk_lo_counts, lookup_mem_rng_chk_mid_counts, lookup_mem_rng_chk_hi_counts, lookup_pow_2_0_counts, lookup_pow_2_1_counts, lookup_u8_0_counts, lookup_u8_1_counts, lookup_u16_0_counts, lookup_u16_1_counts, lookup_u16_2_counts, lookup_u16_3_counts, lookup_u16_4_counts, lookup_u16_5_counts, lookup_u16_6_counts, lookup_u16_7_counts, lookup_u16_8_counts, lookup_u16_9_counts, lookup_u16_10_counts, lookup_u16_11_counts, lookup_u16_12_counts, lookup_u16_13_counts, lookup_u16_14_counts, lookup_div_u16_0_counts, lookup_div_u16_1_counts, lookup_div_u16_2_counts, lookup_div_u16_3_counts, lookup_div_u16_4_counts, lookup_div_u16_5_counts, lookup_div_u16_6_counts, lookup_div_u16_7_counts +#define DERIVED_WITNESS_ENTITIES perm_pos_mem_read_a_inv, perm_pos_mem_read_b_inv, perm_pos_mem_read_c_inv, perm_pos_mem_read_d_inv, perm_pos_mem_write_a_inv, perm_pos_mem_write_b_inv, perm_pos_mem_write_c_inv, perm_pos_mem_write_d_inv, perm_slice_mem_inv, perm_main_alu_inv, perm_main_bin_inv, perm_main_conv_inv, perm_main_pos2_perm_inv, perm_main_pedersen_inv, perm_main_slice_inv, perm_main_mem_a_inv, perm_main_mem_b_inv, perm_main_mem_c_inv, perm_main_mem_d_inv, perm_main_mem_ind_addr_a_inv, perm_main_mem_ind_addr_b_inv, perm_main_mem_ind_addr_c_inv, perm_main_mem_ind_addr_d_inv, lookup_byte_lengths_inv, lookup_byte_operations_inv, lookup_opcode_gas_inv, range_check_l2_gas_hi_inv, range_check_l2_gas_lo_inv, range_check_da_gas_hi_inv, range_check_da_gas_lo_inv, kernel_output_lookup_inv, lookup_into_kernel_inv, lookup_cd_value_inv, lookup_ret_value_inv, incl_main_tag_err_inv, incl_mem_tag_err_inv, lookup_mem_rng_chk_lo_inv, lookup_mem_rng_chk_mid_inv, lookup_mem_rng_chk_hi_inv, lookup_pow_2_0_inv, lookup_pow_2_1_inv, lookup_u8_0_inv, lookup_u8_1_inv, lookup_u16_0_inv, lookup_u16_1_inv, lookup_u16_2_inv, lookup_u16_3_inv, lookup_u16_4_inv, lookup_u16_5_inv, lookup_u16_6_inv, lookup_u16_7_inv, lookup_u16_8_inv, lookup_u16_9_inv, lookup_u16_10_inv, lookup_u16_11_inv, lookup_u16_12_inv, lookup_u16_13_inv, lookup_u16_14_inv, lookup_div_u16_0_inv, lookup_div_u16_1_inv, lookup_div_u16_2_inv, lookup_div_u16_3_inv, lookup_div_u16_4_inv, lookup_div_u16_5_inv, lookup_div_u16_6_inv, lookup_div_u16_7_inv +#define SHIFTED_ENTITIES alu_a_hi_shift, alu_a_lo_shift, alu_b_hi_shift, alu_b_lo_shift, alu_cmp_rng_ctr_shift, alu_div_u16_r0_shift, alu_div_u16_r1_shift, alu_div_u16_r2_shift, alu_div_u16_r3_shift, alu_div_u16_r4_shift, alu_div_u16_r5_shift, alu_div_u16_r6_shift, alu_div_u16_r7_shift, alu_op_add_shift, alu_op_cast_shift, alu_op_cast_prev_shift, alu_op_div_shift, alu_op_mul_shift, alu_op_shl_shift, alu_op_shr_shift, alu_op_sub_shift, alu_p_sub_a_hi_shift, alu_p_sub_a_lo_shift, alu_p_sub_b_hi_shift, alu_p_sub_b_lo_shift, alu_sel_alu_shift, alu_sel_cmp_shift, alu_sel_div_rng_chk_shift, alu_sel_rng_chk_shift, alu_sel_rng_chk_lookup_shift, alu_u16_r0_shift, alu_u16_r1_shift, alu_u16_r2_shift, alu_u16_r3_shift, alu_u16_r4_shift, alu_u16_r5_shift, alu_u16_r6_shift, alu_u8_r0_shift, alu_u8_r1_shift, binary_acc_ia_shift, binary_acc_ib_shift, binary_acc_ic_shift, binary_mem_tag_ctr_shift, binary_op_id_shift, main_da_gas_remaining_shift, main_emit_l2_to_l1_msg_write_offset_shift, main_emit_note_hash_write_offset_shift, main_emit_nullifier_write_offset_shift, main_emit_unencrypted_log_write_offset_shift, main_internal_return_ptr_shift, main_l1_to_l2_msg_exists_write_offset_shift, main_l2_gas_remaining_shift, main_note_hash_exist_write_offset_shift, main_nullifier_exists_write_offset_shift, main_nullifier_non_exists_write_offset_shift, main_pc_shift, main_sel_execution_row_shift, main_side_effect_counter_shift, main_sload_write_offset_shift, main_sstore_write_offset_shift, mem_glob_addr_shift, mem_rw_shift, mem_sel_mem_shift, mem_tag_shift, mem_tsp_shift, mem_val_shift, slice_addr_shift, slice_clk_shift, slice_cnt_shift, slice_col_offset_shift, slice_sel_cd_cpy_shift, slice_sel_mem_active_shift, slice_sel_return_shift, slice_sel_start_shift, slice_space_id_shift +#define TO_BE_SHIFTED(e) e.alu_a_hi, e.alu_a_lo, e.alu_b_hi, e.alu_b_lo, e.alu_cmp_rng_ctr, e.alu_div_u16_r0, e.alu_div_u16_r1, e.alu_div_u16_r2, e.alu_div_u16_r3, e.alu_div_u16_r4, e.alu_div_u16_r5, e.alu_div_u16_r6, e.alu_div_u16_r7, e.alu_op_add, e.alu_op_cast, e.alu_op_cast_prev, e.alu_op_div, e.alu_op_mul, e.alu_op_shl, e.alu_op_shr, e.alu_op_sub, e.alu_p_sub_a_hi, e.alu_p_sub_a_lo, e.alu_p_sub_b_hi, e.alu_p_sub_b_lo, e.alu_sel_alu, e.alu_sel_cmp, e.alu_sel_div_rng_chk, e.alu_sel_rng_chk, e.alu_sel_rng_chk_lookup, e.alu_u16_r0, e.alu_u16_r1, e.alu_u16_r2, e.alu_u16_r3, e.alu_u16_r4, e.alu_u16_r5, e.alu_u16_r6, e.alu_u8_r0, e.alu_u8_r1, e.binary_acc_ia, e.binary_acc_ib, e.binary_acc_ic, e.binary_mem_tag_ctr, e.binary_op_id, e.main_da_gas_remaining, e.main_emit_l2_to_l1_msg_write_offset, e.main_emit_note_hash_write_offset, e.main_emit_nullifier_write_offset, e.main_emit_unencrypted_log_write_offset, e.main_internal_return_ptr, e.main_l1_to_l2_msg_exists_write_offset, e.main_l2_gas_remaining, e.main_note_hash_exist_write_offset, e.main_nullifier_exists_write_offset, e.main_nullifier_non_exists_write_offset, e.main_pc, e.main_sel_execution_row, e.main_side_effect_counter, e.main_sload_write_offset, e.main_sstore_write_offset, e.mem_glob_addr, e.mem_rw, e.mem_sel_mem, e.mem_tag, e.mem_tsp, e.mem_val, e.slice_addr, e.slice_clk, e.slice_cnt, e.slice_col_offset, e.slice_sel_cd_cpy, e.slice_sel_mem_active, e.slice_sel_return, e.slice_sel_start, e.slice_space_id #define ALL_ENTITIES PRECOMPUTED_ENTITIES, WIRE_ENTITIES, DERIVED_WITNESS_ENTITIES, SHIFTED_ENTITIES // clang-format on @@ -128,6 +127,9 @@ class AvmFlavor { using VerifierCommitmentKey = AvmFlavorSettings::VerifierCommitmentKey; using RelationSeparator = AvmFlavorSettings::RelationSeparator; + // This flavor would not be used with ZK Sumcheck + static constexpr bool HasZK = false; + static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 16; static constexpr size_t NUM_WITNESS_ENTITIES = 696; static constexpr size_t NUM_SHIFTED_ENTITIES = 75; @@ -135,6 +137,8 @@ class AvmFlavor { // 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 = 787; + // The total number of witnesses including shifts and derived entities. + static constexpr size_t NUM_ALL_WITNESS_ENTITIES = NUM_WITNESS_ENTITIES + NUM_SHIFTED_ENTITIES; using MainRelations = std::tuple< // Relations @@ -337,7 +341,7 @@ class AvmFlavor { ProverPolynomials(ProvingKey& proving_key); - [[nodiscard]] size_t get_polynomial_size() const { return kernel_kernel_inputs.size(); } + [[nodiscard]] size_t get_polynomial_size() const { return main_kernel_inputs.size(); } /** * @brief Returns the evaluations of all prover polynomials at one point on the boolean hypercube, which * represents one row in the execution trace. @@ -415,4 +419,4 @@ class AvmFlavor { }; }; -} // namespace bb \ No newline at end of file +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp index b06fa434c4d..8a9e2d32c81 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp @@ -35,10 +35,10 @@ template std::vector AvmFullRow::names() "main_sel_first", "main_zeroes", "powers_power_of_2", - "kernel_kernel_inputs", - "kernel_kernel_value_out", - "kernel_kernel_side_effect_out", - "kernel_kernel_metadata_out", + "main_kernel_inputs", + "main_kernel_value_out", + "main_kernel_side_effect_out", + "main_kernel_metadata_out", "main_calldata", "main_returndata", "alu_a_hi", @@ -146,21 +146,6 @@ template std::vector AvmFullRow::names() "keccakf1600_input", "keccakf1600_output", "keccakf1600_sel_keccakf1600", - "kernel_emit_l2_to_l1_msg_write_offset", - "kernel_emit_note_hash_write_offset", - "kernel_emit_nullifier_write_offset", - "kernel_emit_unencrypted_log_write_offset", - "kernel_kernel_in_offset", - "kernel_kernel_out_offset", - "kernel_l1_to_l2_msg_exists_write_offset", - "kernel_note_hash_exist_write_offset", - "kernel_nullifier_exists_write_offset", - "kernel_nullifier_non_exists_write_offset", - "kernel_q_public_input_kernel_add_to_table", - "kernel_q_public_input_kernel_out_add_to_table", - "kernel_side_effect_counter", - "kernel_sload_write_offset", - "kernel_sstore_write_offset", "main_abs_da_rem_gas_hi", "main_abs_da_rem_gas_lo", "main_abs_l2_rem_gas_hi", @@ -175,6 +160,10 @@ template std::vector AvmFullRow::names() "main_dyn_da_gas_op_cost", "main_dyn_gas_multiplier", "main_dyn_l2_gas_op_cost", + "main_emit_l2_to_l1_msg_write_offset", + "main_emit_note_hash_write_offset", + "main_emit_nullifier_write_offset", + "main_emit_unencrypted_log_write_offset", "main_ia", "main_ib", "main_ic", @@ -186,12 +175,18 @@ template std::vector AvmFullRow::names() "main_ind_addr_d", "main_internal_return_ptr", "main_inv", + "main_kernel_in_offset", + "main_kernel_out_offset", + "main_l1_to_l2_msg_exists_write_offset", "main_l2_gas_remaining", "main_l2_out_of_gas", "main_mem_addr_a", "main_mem_addr_b", "main_mem_addr_c", "main_mem_addr_d", + "main_note_hash_exist_write_offset", + "main_nullifier_exists_write_offset", + "main_nullifier_non_exists_write_offset", "main_op_err", "main_opcode_val", "main_pc", @@ -204,6 +199,8 @@ template std::vector AvmFullRow::names() "main_sel_bin", "main_sel_calldata", "main_sel_execution_row", + "main_sel_kernel_inputs", + "main_sel_kernel_out", "main_sel_last", "main_sel_mem_op_a", "main_sel_mem_op_b", @@ -279,7 +276,10 @@ template std::vector AvmFullRow::names() "main_sel_rng_16", "main_sel_rng_8", "main_sel_slice_gadget", + "main_side_effect_counter", + "main_sload_write_offset", "main_space_id", + "main_sstore_write_offset", "main_tag_err", "main_w_in_tag", "mem_addr", @@ -652,10 +652,10 @@ template std::vector AvmFullRow::names() "range_check_l2_gas_lo_inv", "range_check_da_gas_hi_inv", "range_check_da_gas_lo_inv", - "lookup_cd_value_inv", - "lookup_ret_value_inv", "kernel_output_lookup_inv", "lookup_into_kernel_inv", + "lookup_cd_value_inv", + "lookup_ret_value_inv", "incl_main_tag_err_inv", "incl_mem_tag_err_inv", "lookup_mem_rng_chk_lo_inv", @@ -695,10 +695,10 @@ template std::vector AvmFullRow::names() "range_check_l2_gas_lo_counts", "range_check_da_gas_hi_counts", "range_check_da_gas_lo_counts", - "lookup_cd_value_counts", - "lookup_ret_value_counts", "kernel_output_lookup_counts", "lookup_into_kernel_counts", + "lookup_cd_value_counts", + "lookup_ret_value_counts", "incl_main_tag_err_counts", "incl_mem_tag_err_counts", "lookup_mem_rng_chk_lo_counts", @@ -752,10 +752,10 @@ template RefVector AvmFullRow::as_vector() const main_sel_first, main_zeroes, powers_power_of_2, - kernel_kernel_inputs, - kernel_kernel_value_out, - kernel_kernel_side_effect_out, - kernel_kernel_metadata_out, + main_kernel_inputs, + main_kernel_value_out, + main_kernel_side_effect_out, + main_kernel_metadata_out, main_calldata, main_returndata, alu_a_hi, @@ -863,21 +863,6 @@ template RefVector AvmFullRow::as_vector() const keccakf1600_input, keccakf1600_output, keccakf1600_sel_keccakf1600, - kernel_emit_l2_to_l1_msg_write_offset, - kernel_emit_note_hash_write_offset, - kernel_emit_nullifier_write_offset, - kernel_emit_unencrypted_log_write_offset, - kernel_kernel_in_offset, - kernel_kernel_out_offset, - kernel_l1_to_l2_msg_exists_write_offset, - kernel_note_hash_exist_write_offset, - kernel_nullifier_exists_write_offset, - kernel_nullifier_non_exists_write_offset, - kernel_q_public_input_kernel_add_to_table, - kernel_q_public_input_kernel_out_add_to_table, - kernel_side_effect_counter, - kernel_sload_write_offset, - kernel_sstore_write_offset, main_abs_da_rem_gas_hi, main_abs_da_rem_gas_lo, main_abs_l2_rem_gas_hi, @@ -892,6 +877,10 @@ template RefVector AvmFullRow::as_vector() const main_dyn_da_gas_op_cost, main_dyn_gas_multiplier, main_dyn_l2_gas_op_cost, + main_emit_l2_to_l1_msg_write_offset, + main_emit_note_hash_write_offset, + main_emit_nullifier_write_offset, + main_emit_unencrypted_log_write_offset, main_ia, main_ib, main_ic, @@ -903,12 +892,18 @@ template RefVector AvmFullRow::as_vector() const main_ind_addr_d, main_internal_return_ptr, main_inv, + main_kernel_in_offset, + main_kernel_out_offset, + main_l1_to_l2_msg_exists_write_offset, main_l2_gas_remaining, main_l2_out_of_gas, main_mem_addr_a, main_mem_addr_b, main_mem_addr_c, main_mem_addr_d, + main_note_hash_exist_write_offset, + main_nullifier_exists_write_offset, + main_nullifier_non_exists_write_offset, main_op_err, main_opcode_val, main_pc, @@ -921,6 +916,8 @@ template RefVector AvmFullRow::as_vector() const main_sel_bin, main_sel_calldata, main_sel_execution_row, + main_sel_kernel_inputs, + main_sel_kernel_out, main_sel_last, main_sel_mem_op_a, main_sel_mem_op_b, @@ -996,7 +993,10 @@ template RefVector AvmFullRow::as_vector() const main_sel_rng_16, main_sel_rng_8, main_sel_slice_gadget, + main_side_effect_counter, + main_sload_write_offset, main_space_id, + main_sstore_write_offset, main_tag_err, main_w_in_tag, mem_addr, @@ -1369,10 +1369,10 @@ template RefVector AvmFullRow::as_vector() const range_check_l2_gas_lo_inv, range_check_da_gas_hi_inv, range_check_da_gas_lo_inv, - lookup_cd_value_inv, - lookup_ret_value_inv, kernel_output_lookup_inv, lookup_into_kernel_inv, + lookup_cd_value_inv, + lookup_ret_value_inv, incl_main_tag_err_inv, incl_mem_tag_err_inv, lookup_mem_rng_chk_lo_inv, @@ -1412,10 +1412,10 @@ template RefVector AvmFullRow::as_vector() const range_check_l2_gas_lo_counts, range_check_da_gas_hi_counts, range_check_da_gas_lo_counts, - lookup_cd_value_counts, - lookup_ret_value_counts, kernel_output_lookup_counts, lookup_into_kernel_counts, + lookup_cd_value_counts, + lookup_ret_value_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts, lookup_mem_rng_chk_lo_counts, diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp index 5b4b63b6b26..07e82e9798f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp @@ -26,10 +26,10 @@ template struct AvmFullRow { FF main_sel_first{}; FF main_zeroes{}; FF powers_power_of_2{}; - FF kernel_kernel_inputs{}; - FF kernel_kernel_value_out{}; - FF kernel_kernel_side_effect_out{}; - FF kernel_kernel_metadata_out{}; + FF main_kernel_inputs{}; + FF main_kernel_value_out{}; + FF main_kernel_side_effect_out{}; + FF main_kernel_metadata_out{}; FF main_calldata{}; FF main_returndata{}; FF alu_a_hi{}; @@ -137,21 +137,6 @@ template struct AvmFullRow { FF keccakf1600_input{}; FF keccakf1600_output{}; FF keccakf1600_sel_keccakf1600{}; - FF kernel_emit_l2_to_l1_msg_write_offset{}; - FF kernel_emit_note_hash_write_offset{}; - FF kernel_emit_nullifier_write_offset{}; - FF kernel_emit_unencrypted_log_write_offset{}; - FF kernel_kernel_in_offset{}; - FF kernel_kernel_out_offset{}; - FF kernel_l1_to_l2_msg_exists_write_offset{}; - FF kernel_note_hash_exist_write_offset{}; - FF kernel_nullifier_exists_write_offset{}; - FF kernel_nullifier_non_exists_write_offset{}; - FF kernel_q_public_input_kernel_add_to_table{}; - FF kernel_q_public_input_kernel_out_add_to_table{}; - FF kernel_side_effect_counter{}; - FF kernel_sload_write_offset{}; - FF kernel_sstore_write_offset{}; FF main_abs_da_rem_gas_hi{}; FF main_abs_da_rem_gas_lo{}; FF main_abs_l2_rem_gas_hi{}; @@ -166,6 +151,10 @@ template struct AvmFullRow { FF main_dyn_da_gas_op_cost{}; FF main_dyn_gas_multiplier{}; FF main_dyn_l2_gas_op_cost{}; + FF main_emit_l2_to_l1_msg_write_offset{}; + FF main_emit_note_hash_write_offset{}; + FF main_emit_nullifier_write_offset{}; + FF main_emit_unencrypted_log_write_offset{}; FF main_ia{}; FF main_ib{}; FF main_ic{}; @@ -177,12 +166,18 @@ template struct AvmFullRow { FF main_ind_addr_d{}; FF main_internal_return_ptr{}; FF main_inv{}; + FF main_kernel_in_offset{}; + FF main_kernel_out_offset{}; + FF main_l1_to_l2_msg_exists_write_offset{}; FF main_l2_gas_remaining{}; FF main_l2_out_of_gas{}; FF main_mem_addr_a{}; FF main_mem_addr_b{}; FF main_mem_addr_c{}; FF main_mem_addr_d{}; + FF main_note_hash_exist_write_offset{}; + FF main_nullifier_exists_write_offset{}; + FF main_nullifier_non_exists_write_offset{}; FF main_op_err{}; FF main_opcode_val{}; FF main_pc{}; @@ -195,6 +190,8 @@ template struct AvmFullRow { FF main_sel_bin{}; FF main_sel_calldata{}; FF main_sel_execution_row{}; + FF main_sel_kernel_inputs{}; + FF main_sel_kernel_out{}; FF main_sel_last{}; FF main_sel_mem_op_a{}; FF main_sel_mem_op_b{}; @@ -270,7 +267,10 @@ template struct AvmFullRow { FF main_sel_rng_16{}; FF main_sel_rng_8{}; FF main_sel_slice_gadget{}; + FF main_side_effect_counter{}; + FF main_sload_write_offset{}; FF main_space_id{}; + FF main_sstore_write_offset{}; FF main_tag_err{}; FF main_w_in_tag{}; FF mem_addr{}; @@ -643,10 +643,10 @@ template struct AvmFullRow { FF range_check_l2_gas_lo_inv{}; FF range_check_da_gas_hi_inv{}; FF range_check_da_gas_lo_inv{}; - FF lookup_cd_value_inv{}; - FF lookup_ret_value_inv{}; FF kernel_output_lookup_inv{}; FF lookup_into_kernel_inv{}; + FF lookup_cd_value_inv{}; + FF lookup_ret_value_inv{}; FF incl_main_tag_err_inv{}; FF incl_mem_tag_err_inv{}; FF lookup_mem_rng_chk_lo_inv{}; @@ -686,10 +686,10 @@ template struct AvmFullRow { FF range_check_l2_gas_lo_counts{}; FF range_check_da_gas_hi_counts{}; FF range_check_da_gas_lo_counts{}; - FF lookup_cd_value_counts{}; - FF lookup_ret_value_counts{}; FF kernel_output_lookup_counts{}; FF lookup_into_kernel_counts{}; + FF lookup_cd_value_counts{}; + FF lookup_ret_value_counts{}; FF incl_main_tag_err_counts{}; FF incl_mem_tag_err_counts{}; FF lookup_mem_rng_chk_lo_counts{}; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/prover.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/prover.cpp index d5cbab1767e..41e801b4c83 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/prover.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/prover.cpp @@ -8,7 +8,6 @@ #include "barretenberg/honk/proof_system/logderivative_library.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" -#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp index b75bec675d7..6fa15bbad85 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp @@ -10,7 +10,9 @@ template class kernelImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 4, 4, 3, 3, 3, 3, 3, 3 }; + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; template void static accumulate(ContainerOverSubrelations& evals, @@ -18,88 +20,366 @@ template class kernelImpl { [[maybe_unused]] const RelationParameters&, [[maybe_unused]] const FF& scaling_factor) { - const auto kernel_NOT_LAST = (FF(1) - new_term.main_sel_last); + const auto constants_SENDER_SELECTOR = FF(0); + const auto constants_ADDRESS_SELECTOR = FF(1); + const auto constants_STORAGE_ADDRESS_SELECTOR = FF(1); + const auto constants_FUNCTION_SELECTOR_SELECTOR = FF(2); + const auto constants_CHAIN_ID_SELECTOR = FF(29); + const auto constants_VERSION_SELECTOR = FF(30); + const auto constants_BLOCK_NUMBER_SELECTOR = FF(31); + const auto constants_TIMESTAMP_SELECTOR = FF(33); + const auto constants_COINBASE_SELECTOR = FF(34); + const auto constants_FEE_PER_DA_GAS_SELECTOR = FF(36); + const auto constants_FEE_PER_L2_GAS_SELECTOR = FF(37); + const auto constants_TRANSACTION_FEE_SELECTOR = FF(41); + const auto constants_START_NOTE_HASH_EXISTS_WRITE_OFFSET = FF(0); + const auto constants_START_NULLIFIER_EXISTS_OFFSET = FF(16); + const auto constants_START_NULLIFIER_NON_EXISTS_OFFSET = FF(32); + const auto constants_START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET = FF(48); + const auto constants_START_SSTORE_WRITE_OFFSET = FF(64); + const auto constants_START_SLOAD_WRITE_OFFSET = FF(96); + const auto constants_START_EMIT_NOTE_HASH_WRITE_OFFSET = FF(128); + const auto constants_START_EMIT_NULLIFIER_WRITE_OFFSET = FF(144); + const auto constants_START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET = FF(160); + const auto constants_START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = FF(162); + const auto main_KERNEL_INPUT_SELECTORS = + (((((((((((new_term.main_sel_op_address + new_term.main_sel_op_storage_address) + + new_term.main_sel_op_sender) + + new_term.main_sel_op_function_selector) + + new_term.main_sel_op_transaction_fee) + + new_term.main_sel_op_chain_id) + + new_term.main_sel_op_version) + + new_term.main_sel_op_block_number) + + new_term.main_sel_op_coinbase) + + new_term.main_sel_op_timestamp) + + new_term.main_sel_op_fee_per_l2_gas) + + new_term.main_sel_op_fee_per_da_gas); + const auto main_KERNEL_OUTPUT_SELECTORS = + ((((((((new_term.main_sel_op_note_hash_exists + new_term.main_sel_op_emit_note_hash) + + new_term.main_sel_op_nullifier_exists) + + new_term.main_sel_op_emit_nullifier) + + new_term.main_sel_op_l1_to_l2_msg_exists) + + new_term.main_sel_op_emit_unencrypted_log) + + new_term.main_sel_op_emit_l2_to_l1_msg) + + new_term.main_sel_op_sload) + + new_term.main_sel_op_sstore); { using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; - auto tmp = (kernel_NOT_LAST * - (new_term.kernel_note_hash_exist_write_offset_shift - - (new_term.kernel_note_hash_exist_write_offset + new_term.main_sel_op_note_hash_exists))); + auto tmp = (new_term.main_sel_execution_row * + (new_term.main_note_hash_exist_write_offset_shift - + (new_term.main_note_hash_exist_write_offset + new_term.main_sel_op_note_hash_exists))); tmp *= scaling_factor; std::get<0>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<1, ContainerOverSubrelations>; - auto tmp = (kernel_NOT_LAST * - (new_term.kernel_emit_note_hash_write_offset_shift - - (new_term.kernel_emit_note_hash_write_offset + new_term.main_sel_op_emit_note_hash))); + auto tmp = (new_term.main_sel_execution_row * + (new_term.main_emit_note_hash_write_offset_shift - + (new_term.main_emit_note_hash_write_offset + new_term.main_sel_op_emit_note_hash))); tmp *= scaling_factor; std::get<1>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<2, ContainerOverSubrelations>; - auto tmp = (kernel_NOT_LAST * (new_term.kernel_nullifier_exists_write_offset_shift - - (new_term.kernel_nullifier_exists_write_offset + - (new_term.main_sel_op_nullifier_exists * new_term.main_ib)))); + auto tmp = + (new_term.main_sel_execution_row * (new_term.main_nullifier_exists_write_offset_shift - + (new_term.main_nullifier_exists_write_offset + + (new_term.main_sel_op_nullifier_exists * new_term.main_ib)))); tmp *= scaling_factor; std::get<2>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<3, ContainerOverSubrelations>; - auto tmp = (kernel_NOT_LAST * (new_term.kernel_nullifier_non_exists_write_offset_shift - - (new_term.kernel_nullifier_non_exists_write_offset + - (new_term.main_sel_op_nullifier_exists * (FF(1) - new_term.main_ib))))); + auto tmp = (new_term.main_sel_execution_row * + (new_term.main_nullifier_non_exists_write_offset_shift - + (new_term.main_nullifier_non_exists_write_offset + + (new_term.main_sel_op_nullifier_exists * (FF(1) - new_term.main_ib))))); tmp *= scaling_factor; std::get<3>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<4, ContainerOverSubrelations>; - auto tmp = (kernel_NOT_LAST * - (new_term.kernel_emit_nullifier_write_offset_shift - - (new_term.kernel_emit_nullifier_write_offset + new_term.main_sel_op_emit_nullifier))); + auto tmp = (new_term.main_sel_execution_row * + (new_term.main_emit_nullifier_write_offset_shift - + (new_term.main_emit_nullifier_write_offset + new_term.main_sel_op_emit_nullifier))); tmp *= scaling_factor; std::get<4>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<5, ContainerOverSubrelations>; - auto tmp = - (kernel_NOT_LAST * - (new_term.kernel_l1_to_l2_msg_exists_write_offset_shift - - (new_term.kernel_l1_to_l2_msg_exists_write_offset + new_term.main_sel_op_l1_to_l2_msg_exists))); + auto tmp = (new_term.main_sel_execution_row * + (new_term.main_l1_to_l2_msg_exists_write_offset_shift - + (new_term.main_l1_to_l2_msg_exists_write_offset + new_term.main_sel_op_l1_to_l2_msg_exists))); tmp *= scaling_factor; std::get<5>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<6, ContainerOverSubrelations>; auto tmp = - (kernel_NOT_LAST * - (new_term.kernel_emit_unencrypted_log_write_offset_shift - - (new_term.kernel_emit_unencrypted_log_write_offset + new_term.main_sel_op_emit_unencrypted_log))); + (new_term.main_sel_execution_row * + (new_term.main_emit_unencrypted_log_write_offset_shift - + (new_term.main_emit_unencrypted_log_write_offset + new_term.main_sel_op_emit_unencrypted_log))); tmp *= scaling_factor; std::get<6>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<7, ContainerOverSubrelations>; - auto tmp = (kernel_NOT_LAST * - (new_term.kernel_emit_l2_to_l1_msg_write_offset_shift - - (new_term.kernel_emit_l2_to_l1_msg_write_offset + new_term.main_sel_op_emit_l2_to_l1_msg))); + auto tmp = (new_term.main_sel_execution_row * + (new_term.main_emit_l2_to_l1_msg_write_offset_shift - + (new_term.main_emit_l2_to_l1_msg_write_offset + new_term.main_sel_op_emit_l2_to_l1_msg))); tmp *= scaling_factor; std::get<7>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<8, ContainerOverSubrelations>; - auto tmp = (kernel_NOT_LAST * (new_term.kernel_sload_write_offset_shift - - (new_term.kernel_sload_write_offset + new_term.main_sel_op_sload))); + auto tmp = + (new_term.main_sel_execution_row * (new_term.main_sload_write_offset_shift - + (new_term.main_sload_write_offset + new_term.main_sel_op_sload))); tmp *= scaling_factor; std::get<8>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<9, ContainerOverSubrelations>; - auto tmp = (kernel_NOT_LAST * (new_term.kernel_sstore_write_offset_shift - - (new_term.kernel_sstore_write_offset + new_term.main_sel_op_sstore))); + auto tmp = + (new_term.main_sel_execution_row * (new_term.main_sstore_write_offset_shift - + (new_term.main_sstore_write_offset + new_term.main_sel_op_sstore))); tmp *= scaling_factor; std::get<9>(evals) += typename Accumulator::View(tmp); } + { + using Accumulator = typename std::tuple_element_t<10, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_address * (new_term.main_kernel_in_offset - constants_ADDRESS_SELECTOR)); + tmp *= scaling_factor; + std::get<10>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<11, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_storage_address * + (new_term.main_kernel_in_offset - constants_STORAGE_ADDRESS_SELECTOR)); + tmp *= scaling_factor; + std::get<11>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<12, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_sender * (new_term.main_kernel_in_offset - constants_SENDER_SELECTOR)); + tmp *= scaling_factor; + std::get<12>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<13, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_function_selector * + (new_term.main_kernel_in_offset - constants_FUNCTION_SELECTOR_SELECTOR)); + tmp *= scaling_factor; + std::get<13>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<14, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_transaction_fee * + (new_term.main_kernel_in_offset - constants_TRANSACTION_FEE_SELECTOR)); + tmp *= scaling_factor; + std::get<14>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<15, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_chain_id * (new_term.main_kernel_in_offset - constants_CHAIN_ID_SELECTOR)); + tmp *= scaling_factor; + std::get<15>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<16, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_version * (new_term.main_kernel_in_offset - constants_VERSION_SELECTOR)); + tmp *= scaling_factor; + std::get<16>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<17, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_block_number * + (new_term.main_kernel_in_offset - constants_BLOCK_NUMBER_SELECTOR)); + tmp *= scaling_factor; + std::get<17>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<18, ContainerOverSubrelations>; + auto tmp = + (new_term.main_sel_op_timestamp * (new_term.main_kernel_in_offset - constants_TIMESTAMP_SELECTOR)); + tmp *= scaling_factor; + std::get<18>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<19, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_coinbase * (new_term.main_kernel_in_offset - constants_COINBASE_SELECTOR)); + tmp *= scaling_factor; + std::get<19>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<20, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_fee_per_da_gas * + (new_term.main_kernel_in_offset - constants_FEE_PER_DA_GAS_SELECTOR)); + tmp *= scaling_factor; + std::get<20>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<21, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_fee_per_l2_gas * + (new_term.main_kernel_in_offset - constants_FEE_PER_L2_GAS_SELECTOR)); + tmp *= scaling_factor; + std::get<21>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<22, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_note_hash_exists * + (new_term.main_kernel_out_offset - + (constants_START_NOTE_HASH_EXISTS_WRITE_OFFSET + new_term.main_note_hash_exist_write_offset))); + tmp *= scaling_factor; + std::get<22>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<23, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_first * new_term.main_note_hash_exist_write_offset); + tmp *= scaling_factor; + std::get<23>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<24, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_emit_note_hash * + (new_term.main_kernel_out_offset - + (constants_START_EMIT_NOTE_HASH_WRITE_OFFSET + new_term.main_emit_note_hash_write_offset))); + tmp *= scaling_factor; + std::get<24>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<25, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_first * new_term.main_emit_note_hash_write_offset); + tmp *= scaling_factor; + std::get<25>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<26, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_nullifier_exists * + (new_term.main_kernel_out_offset - + ((new_term.main_ib * + (constants_START_NULLIFIER_EXISTS_OFFSET + new_term.main_nullifier_exists_write_offset)) + + ((FF(1) - new_term.main_ib) * (constants_START_NULLIFIER_NON_EXISTS_OFFSET + + new_term.main_nullifier_non_exists_write_offset))))); + tmp *= scaling_factor; + std::get<26>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<27, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_first * new_term.main_nullifier_exists_write_offset); + tmp *= scaling_factor; + std::get<27>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<28, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_first * new_term.main_nullifier_non_exists_write_offset); + tmp *= scaling_factor; + std::get<28>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<29, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_emit_nullifier * + (new_term.main_kernel_out_offset - + (constants_START_EMIT_NULLIFIER_WRITE_OFFSET + new_term.main_emit_nullifier_write_offset))); + tmp *= scaling_factor; + std::get<29>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<30, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_first * new_term.main_emit_nullifier_write_offset); + tmp *= scaling_factor; + std::get<30>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<31, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_l1_to_l2_msg_exists * + (new_term.main_kernel_out_offset - (constants_START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + + new_term.main_l1_to_l2_msg_exists_write_offset))); + tmp *= scaling_factor; + std::get<31>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<32, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_first * new_term.main_l1_to_l2_msg_exists_write_offset); + tmp *= scaling_factor; + std::get<32>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<33, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_emit_unencrypted_log * + (new_term.main_kernel_out_offset - (constants_START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET + + new_term.main_emit_unencrypted_log_write_offset))); + tmp *= scaling_factor; + std::get<33>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<34, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_first * new_term.main_emit_unencrypted_log_write_offset); + tmp *= scaling_factor; + std::get<34>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<35, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_emit_l2_to_l1_msg * + (new_term.main_kernel_out_offset - (constants_START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET + + new_term.main_emit_l2_to_l1_msg_write_offset))); + tmp *= scaling_factor; + std::get<35>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<36, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_first * new_term.main_emit_l2_to_l1_msg_write_offset); + tmp *= scaling_factor; + std::get<36>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<37, ContainerOverSubrelations>; + auto tmp = + (new_term.main_sel_op_sload * (new_term.main_kernel_out_offset - (constants_START_SLOAD_WRITE_OFFSET + + new_term.main_sload_write_offset))); + tmp *= scaling_factor; + std::get<37>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<38, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_first * new_term.main_sload_write_offset); + tmp *= scaling_factor; + std::get<38>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<39, ContainerOverSubrelations>; + auto tmp = + (new_term.main_sel_op_sstore * (new_term.main_kernel_out_offset - (constants_START_SSTORE_WRITE_OFFSET + + new_term.main_sstore_write_offset))); + tmp *= scaling_factor; + std::get<39>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<40, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_first * new_term.main_sstore_write_offset); + tmp *= scaling_factor; + std::get<40>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<41, ContainerOverSubrelations>; + auto tmp = (main_KERNEL_OUTPUT_SELECTORS * + (new_term.main_side_effect_counter_shift - (new_term.main_side_effect_counter + FF(1)))); + tmp *= scaling_factor; + std::get<41>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<42, ContainerOverSubrelations>; + auto tmp = (main_KERNEL_INPUT_SELECTORS * (FF(1) - new_term.main_sel_q_kernel_lookup)); + tmp *= scaling_factor; + std::get<42>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<43, ContainerOverSubrelations>; + auto tmp = (main_KERNEL_OUTPUT_SELECTORS * (FF(1) - new_term.main_sel_q_kernel_output_lookup)); + tmp *= scaling_factor; + std::get<43>(evals) += typename Accumulator::View(tmp); + } } }; @@ -130,6 +410,54 @@ template class kernel : public Relation> { return "SLOAD_INC_CONSISTENCY_CHECK"; case 9: return "SSTORE_INC_CONSISTENCY_CHECK"; + case 10: + return "ADDRESS_KERNEL"; + case 11: + return "STORAGE_ADDRESS_KERNEL"; + case 12: + return "SENDER_KERNEL"; + case 13: + return "FUNCTION_SELECTOR_KERNEL"; + case 14: + return "FEE_TRANSACTION_FEE_KERNEL"; + case 15: + return "CHAIN_ID_KERNEL"; + case 16: + return "VERSION_KERNEL"; + case 17: + return "BLOCK_NUMBER_KERNEL"; + case 18: + return "TIMESTAMP_KERNEL"; + case 19: + return "COINBASE_KERNEL"; + case 20: + return "FEE_DA_GAS_KERNEL"; + case 21: + return "FEE_L2_GAS_KERNEL"; + case 22: + return "NOTE_HASH_KERNEL_OUTPUT"; + case 24: + return "EMIT_NOTE_HASH_KERNEL_OUTPUT"; + case 26: + return "NULLIFIER_EXISTS_KERNEL_OUTPUT"; + case 29: + return "EMIT_NULLIFIER_KERNEL_OUTPUT"; + case 31: + return "L1_TO_L2_MSG_EXISTS_KERNEL_OUTPUT"; + case 33: + return "EMIT_UNENCRYPTED_LOG_KERNEL_OUTPUT"; + case 35: + return "EMIT_L2_TO_L1_MSGS_KERNEL_OUTPUT"; + case 37: + return "SLOAD_KERNEL_OUTPUT"; + case 39: + return "SSTORE_KERNEL_OUTPUT"; + case 41: + return "SIDE_EFFECT_COUNTER_INCREMENT"; + case 42: + return "KERNEL_INPUT_ACTIVE_CHECK"; + case 43: + return "KERNEL_OUTPUT_ACTIVE_CHECK"; } return std::to_string(index); } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel_output_lookup.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel_output_lookup.hpp index e64c3dbb75b..27ab2deb718 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel_output_lookup.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel_output_lookup.hpp @@ -21,7 +21,7 @@ class kernel_output_lookup_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.main_sel_q_kernel_output_lookup == 1 || in.kernel_q_public_input_kernel_out_add_to_table == 1); + return (in.main_sel_q_kernel_output_lookup == 1 || in.main_sel_kernel_out == 1); } template @@ -29,7 +29,7 @@ class kernel_output_lookup_lookup_settings { { using View = typename Accumulator::View; const auto is_operation = View(in.main_sel_q_kernel_output_lookup); - const auto is_table_entry = View(in.kernel_q_public_input_kernel_out_add_to_table); + const auto is_table_entry = View(in.main_sel_kernel_out); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -38,15 +38,15 @@ class kernel_output_lookup_lookup_settings { return std::forward_as_tuple(in.kernel_output_lookup_inv, in.kernel_output_lookup_counts, in.main_sel_q_kernel_output_lookup, - in.kernel_q_public_input_kernel_out_add_to_table, - in.kernel_kernel_out_offset, + in.main_sel_kernel_out, + in.main_kernel_out_offset, in.main_ia, - in.kernel_side_effect_counter, + in.main_side_effect_counter, in.main_ib, in.main_clk, - in.kernel_kernel_value_out, - in.kernel_kernel_side_effect_out, - in.kernel_kernel_metadata_out); + in.main_kernel_value_out, + in.main_kernel_side_effect_out, + in.main_kernel_metadata_out); } template static inline auto get_nonconst_entities(AllEntities& in) @@ -54,15 +54,15 @@ class kernel_output_lookup_lookup_settings { return std::forward_as_tuple(in.kernel_output_lookup_inv, in.kernel_output_lookup_counts, in.main_sel_q_kernel_output_lookup, - in.kernel_q_public_input_kernel_out_add_to_table, - in.kernel_kernel_out_offset, + in.main_sel_kernel_out, + in.main_kernel_out_offset, in.main_ia, - in.kernel_side_effect_counter, + in.main_side_effect_counter, in.main_ib, in.main_clk, - in.kernel_kernel_value_out, - in.kernel_kernel_side_effect_out, - in.kernel_kernel_metadata_out); + in.main_kernel_value_out, + in.main_kernel_side_effect_out, + in.main_kernel_metadata_out); } }; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/lookup_into_kernel.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/lookup_into_kernel.hpp index a2d199b598f..0de10ad7e32 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/lookup_into_kernel.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/lookup_into_kernel.hpp @@ -21,7 +21,7 @@ class lookup_into_kernel_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.main_sel_q_kernel_lookup == 1 || in.kernel_q_public_input_kernel_add_to_table == 1); + return (in.main_sel_q_kernel_lookup == 1 || in.main_sel_kernel_inputs == 1); } template @@ -29,7 +29,7 @@ class lookup_into_kernel_lookup_settings { { using View = typename Accumulator::View; const auto is_operation = View(in.main_sel_q_kernel_lookup); - const auto is_table_entry = View(in.kernel_q_public_input_kernel_add_to_table); + const auto is_table_entry = View(in.main_sel_kernel_inputs); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -38,10 +38,10 @@ class lookup_into_kernel_lookup_settings { return std::forward_as_tuple(in.lookup_into_kernel_inv, in.lookup_into_kernel_counts, in.main_sel_q_kernel_lookup, - in.kernel_q_public_input_kernel_add_to_table, + in.main_sel_kernel_inputs, in.main_ia, - in.kernel_kernel_in_offset, - in.kernel_kernel_inputs, + in.main_kernel_in_offset, + in.main_kernel_inputs, in.main_clk); } @@ -50,10 +50,10 @@ class lookup_into_kernel_lookup_settings { return std::forward_as_tuple(in.lookup_into_kernel_inv, in.lookup_into_kernel_counts, in.main_sel_q_kernel_lookup, - in.kernel_q_public_input_kernel_add_to_table, + in.main_sel_kernel_inputs, in.main_ia, - in.kernel_kernel_in_offset, - in.kernel_kernel_inputs, + in.main_kernel_in_offset, + in.main_kernel_inputs, in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp index c9be4eb33fd..0c62e3d4004 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp @@ -10,11 +10,11 @@ template class mainImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { - 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 5, 4, 4, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 3, 3, 4, 4, 3, 3, 3, 3, 3, 4, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 2, 2 + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { + 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 4, 3, 3, 3, 3, 4, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 3, 3, 4, 4, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 4, 2, 2 }; template @@ -23,28 +23,6 @@ template class mainImpl { [[maybe_unused]] const RelationParameters&, [[maybe_unused]] const FF& scaling_factor) { - const auto constants_SENDER_SELECTOR = FF(0); - const auto constants_ADDRESS_SELECTOR = FF(1); - const auto constants_STORAGE_ADDRESS_SELECTOR = FF(1); - const auto constants_FUNCTION_SELECTOR_SELECTOR = FF(2); - const auto constants_CHAIN_ID_SELECTOR = FF(29); - const auto constants_VERSION_SELECTOR = FF(30); - const auto constants_BLOCK_NUMBER_SELECTOR = FF(31); - const auto constants_TIMESTAMP_SELECTOR = FF(33); - const auto constants_COINBASE_SELECTOR = FF(34); - const auto constants_FEE_PER_DA_GAS_SELECTOR = FF(36); - const auto constants_FEE_PER_L2_GAS_SELECTOR = FF(37); - const auto constants_TRANSACTION_FEE_SELECTOR = FF(41); - const auto constants_START_NOTE_HASH_EXISTS_WRITE_OFFSET = FF(0); - const auto constants_START_NULLIFIER_EXISTS_OFFSET = FF(16); - const auto constants_START_NULLIFIER_NON_EXISTS_OFFSET = FF(32); - const auto constants_START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET = FF(48); - const auto constants_START_SSTORE_WRITE_OFFSET = FF(64); - const auto constants_START_SLOAD_WRITE_OFFSET = FF(96); - const auto constants_START_EMIT_NOTE_HASH_WRITE_OFFSET = FF(128); - const auto constants_START_EMIT_NULLIFIER_WRITE_OFFSET = FF(144); - const auto constants_START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET = FF(160); - const auto constants_START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = FF(162); const auto constants_misc_INTERNAL_CALL_SPACE_ID = FF(255); const auto main_KERNEL_INPUT_SELECTORS = (((((((((((new_term.main_sel_op_address + new_term.main_sel_op_storage_address) + @@ -608,448 +586,213 @@ template class mainImpl { } { using Accumulator = typename std::tuple_element_t<82, ContainerOverSubrelations>; - auto tmp = (main_KERNEL_INPUT_SELECTORS * (FF(1) - new_term.main_sel_q_kernel_lookup)); + auto tmp = (new_term.main_sel_op_jump * (new_term.main_pc_shift - new_term.main_ia)); tmp *= scaling_factor; std::get<82>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<83, ContainerOverSubrelations>; - auto tmp = (main_KERNEL_OUTPUT_SELECTORS * (FF(1) - new_term.main_sel_q_kernel_output_lookup)); + auto tmp = (new_term.main_sel_op_jumpi * + (((FF(1) - new_term.main_id_zero) * (new_term.main_pc_shift - new_term.main_ia)) + + (new_term.main_id_zero * ((new_term.main_pc_shift - new_term.main_pc) - FF(1))))); tmp *= scaling_factor; std::get<83>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<84, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_jump * (new_term.main_pc_shift - new_term.main_ia)); + auto tmp = (new_term.main_sel_op_internal_call * + (new_term.main_internal_return_ptr_shift - (new_term.main_internal_return_ptr + FF(1)))); tmp *= scaling_factor; std::get<84>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<85, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_jumpi * - (((FF(1) - new_term.main_id_zero) * (new_term.main_pc_shift - new_term.main_ia)) + - (new_term.main_id_zero * ((new_term.main_pc_shift - new_term.main_pc) - FF(1))))); + auto tmp = + (new_term.main_sel_op_internal_call * (new_term.main_internal_return_ptr - new_term.main_mem_addr_b)); tmp *= scaling_factor; std::get<85>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<86, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_call * - (new_term.main_internal_return_ptr_shift - (new_term.main_internal_return_ptr + FF(1)))); + auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_pc_shift - new_term.main_ia)); tmp *= scaling_factor; std::get<86>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<87, ContainerOverSubrelations>; - auto tmp = - (new_term.main_sel_op_internal_call * (new_term.main_internal_return_ptr - new_term.main_mem_addr_b)); + auto tmp = (new_term.main_sel_op_internal_call * ((new_term.main_pc + FF(1)) - new_term.main_ib)); tmp *= scaling_factor; std::get<87>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<88, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_pc_shift - new_term.main_ia)); + auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_rwb - FF(1))); tmp *= scaling_factor; std::get<88>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<89, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_call * ((new_term.main_pc + FF(1)) - new_term.main_ib)); + auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_sel_mem_op_b - FF(1))); tmp *= scaling_factor; std::get<89>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<90, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_rwb - FF(1))); + auto tmp = (new_term.main_sel_op_internal_return * + (new_term.main_internal_return_ptr_shift - (new_term.main_internal_return_ptr - FF(1)))); tmp *= scaling_factor; std::get<90>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<91, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_sel_mem_op_b - FF(1))); + auto tmp = (new_term.main_sel_op_internal_return * + ((new_term.main_internal_return_ptr - FF(1)) - new_term.main_mem_addr_a)); tmp *= scaling_factor; std::get<91>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<92, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_return * - (new_term.main_internal_return_ptr_shift - (new_term.main_internal_return_ptr - FF(1)))); + auto tmp = (new_term.main_sel_op_internal_return * (new_term.main_pc_shift - new_term.main_ia)); tmp *= scaling_factor; std::get<92>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<93, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_return * - ((new_term.main_internal_return_ptr - FF(1)) - new_term.main_mem_addr_a)); + auto tmp = (new_term.main_sel_op_internal_return * new_term.main_rwa); tmp *= scaling_factor; std::get<93>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<94, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_return * (new_term.main_pc_shift - new_term.main_ia)); + auto tmp = (new_term.main_sel_op_internal_return * (new_term.main_sel_mem_op_a - FF(1))); tmp *= scaling_factor; std::get<94>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<95, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_return * new_term.main_rwa); + auto tmp = ((main_CUR_AND_NEXT_ARE_MAIN * (FF(1) - main_SEL_ALL_CTRL_FLOW)) * + (new_term.main_pc_shift - (new_term.main_pc + FF(1)))); tmp *= scaling_factor; std::get<95>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<96, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_return * (new_term.main_sel_mem_op_a - FF(1))); + auto tmp = ((main_CUR_AND_NEXT_ARE_MAIN * (FF(1) - main_SEL_ALL_CTRL_FLOW)) * + (new_term.main_internal_return_ptr_shift - new_term.main_internal_return_ptr)); tmp *= scaling_factor; std::get<96>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<97, ContainerOverSubrelations>; - auto tmp = ((main_CUR_AND_NEXT_ARE_MAIN * (FF(1) - main_SEL_ALL_CTRL_FLOW)) * - (new_term.main_pc_shift - (new_term.main_pc + FF(1)))); + auto tmp = ((new_term.main_sel_op_internal_call + new_term.main_sel_op_internal_return) * + (new_term.main_space_id - constants_misc_INTERNAL_CALL_SPACE_ID)); tmp *= scaling_factor; std::get<97>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<98, ContainerOverSubrelations>; - auto tmp = ((main_CUR_AND_NEXT_ARE_MAIN * (FF(1) - main_SEL_ALL_CTRL_FLOW)) * - (new_term.main_internal_return_ptr_shift - new_term.main_internal_return_ptr)); + auto tmp = (((FF(1) - new_term.main_sel_op_internal_call) - new_term.main_sel_op_internal_return) * + (new_term.main_call_ptr - new_term.main_space_id)); tmp *= scaling_factor; std::get<98>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<99, ContainerOverSubrelations>; - auto tmp = ((new_term.main_sel_op_internal_call + new_term.main_sel_op_internal_return) * - (new_term.main_space_id - constants_misc_INTERNAL_CALL_SPACE_ID)); + auto tmp = ((new_term.main_sel_op_cmov + new_term.main_sel_op_jumpi) * + (((new_term.main_id * new_term.main_inv) - FF(1)) + new_term.main_id_zero)); tmp *= scaling_factor; std::get<99>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<100, ContainerOverSubrelations>; - auto tmp = (((FF(1) - new_term.main_sel_op_internal_call) - new_term.main_sel_op_internal_return) * - (new_term.main_call_ptr - new_term.main_space_id)); + auto tmp = (((new_term.main_sel_op_cmov + new_term.main_sel_op_jumpi) * new_term.main_id_zero) * + (FF(1) - new_term.main_inv)); tmp *= scaling_factor; std::get<100>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<101, ContainerOverSubrelations>; - auto tmp = ((new_term.main_sel_op_cmov + new_term.main_sel_op_jumpi) * - (((new_term.main_id * new_term.main_inv) - FF(1)) + new_term.main_id_zero)); + auto tmp = (new_term.main_sel_mov_ia_to_ic - + (new_term.main_sel_op_mov + (new_term.main_sel_op_cmov * (FF(1) - new_term.main_id_zero)))); tmp *= scaling_factor; std::get<101>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<102, ContainerOverSubrelations>; - auto tmp = (((new_term.main_sel_op_cmov + new_term.main_sel_op_jumpi) * new_term.main_id_zero) * - (FF(1) - new_term.main_inv)); + auto tmp = (new_term.main_sel_mov_ib_to_ic - (new_term.main_sel_op_cmov * new_term.main_id_zero)); tmp *= scaling_factor; std::get<102>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<103, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mov_ia_to_ic - - (new_term.main_sel_op_mov + (new_term.main_sel_op_cmov * (FF(1) - new_term.main_id_zero)))); + auto tmp = (new_term.main_sel_mov_ia_to_ic * (new_term.main_ia - new_term.main_ic)); tmp *= scaling_factor; std::get<103>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<104, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mov_ib_to_ic - (new_term.main_sel_op_cmov * new_term.main_id_zero)); + auto tmp = (new_term.main_sel_mov_ib_to_ic * (new_term.main_ib - new_term.main_ic)); tmp *= scaling_factor; std::get<104>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<105, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mov_ia_to_ic * (new_term.main_ia - new_term.main_ic)); + auto tmp = ((new_term.main_sel_op_mov + new_term.main_sel_op_cmov) * + (new_term.main_r_in_tag - new_term.main_w_in_tag)); tmp *= scaling_factor; std::get<105>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<106, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mov_ib_to_ic * (new_term.main_ib - new_term.main_ic)); + auto tmp = (new_term.main_sel_alu - + ((main_SEL_ALL_ALU * (FF(1) - new_term.main_tag_err)) * (FF(1) - new_term.main_op_err))); tmp *= scaling_factor; std::get<106>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<107, ContainerOverSubrelations>; - auto tmp = ((new_term.main_sel_op_mov + new_term.main_sel_op_cmov) * - (new_term.main_r_in_tag - new_term.main_w_in_tag)); + auto tmp = (main_SEL_ALU_R_TAG * (new_term.main_alu_in_tag - new_term.main_r_in_tag)); tmp *= scaling_factor; std::get<107>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<108, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_alu - - ((main_SEL_ALL_ALU * (FF(1) - new_term.main_tag_err)) * (FF(1) - new_term.main_op_err))); + auto tmp = (main_SEL_ALU_W_TAG * (new_term.main_alu_in_tag - new_term.main_w_in_tag)); tmp *= scaling_factor; std::get<108>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<109, ContainerOverSubrelations>; - auto tmp = (main_SEL_ALU_R_TAG * (new_term.main_alu_in_tag - new_term.main_r_in_tag)); + auto tmp = (new_term.main_sel_op_l2gasleft * (new_term.main_ia - new_term.main_l2_gas_remaining_shift)); tmp *= scaling_factor; std::get<109>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<110, ContainerOverSubrelations>; - auto tmp = (main_SEL_ALU_W_TAG * (new_term.main_alu_in_tag - new_term.main_w_in_tag)); + auto tmp = (new_term.main_sel_op_dagasleft * (new_term.main_ia - new_term.main_da_gas_remaining_shift)); tmp *= scaling_factor; std::get<110>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<111, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_l2gasleft * (new_term.main_ia - new_term.main_l2_gas_remaining_shift)); - tmp *= scaling_factor; - std::get<111>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<112, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_dagasleft * (new_term.main_ia - new_term.main_da_gas_remaining_shift)); - tmp *= scaling_factor; - std::get<112>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<113, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_address * (new_term.kernel_kernel_in_offset - constants_ADDRESS_SELECTOR)); - tmp *= scaling_factor; - std::get<113>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<114, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_storage_address * - (new_term.kernel_kernel_in_offset - constants_STORAGE_ADDRESS_SELECTOR)); - tmp *= scaling_factor; - std::get<114>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<115, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_sender * (new_term.kernel_kernel_in_offset - constants_SENDER_SELECTOR)); - tmp *= scaling_factor; - std::get<115>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<116, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_function_selector * - (new_term.kernel_kernel_in_offset - constants_FUNCTION_SELECTOR_SELECTOR)); - tmp *= scaling_factor; - std::get<116>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<117, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_transaction_fee * - (new_term.kernel_kernel_in_offset - constants_TRANSACTION_FEE_SELECTOR)); - tmp *= scaling_factor; - std::get<117>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<118, ContainerOverSubrelations>; - auto tmp = - (new_term.main_sel_op_chain_id * (new_term.kernel_kernel_in_offset - constants_CHAIN_ID_SELECTOR)); - tmp *= scaling_factor; - std::get<118>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<119, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_version * (new_term.kernel_kernel_in_offset - constants_VERSION_SELECTOR)); - tmp *= scaling_factor; - std::get<119>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<120, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_block_number * - (new_term.kernel_kernel_in_offset - constants_BLOCK_NUMBER_SELECTOR)); - tmp *= scaling_factor; - std::get<120>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<121, ContainerOverSubrelations>; - auto tmp = - (new_term.main_sel_op_timestamp * (new_term.kernel_kernel_in_offset - constants_TIMESTAMP_SELECTOR)); - tmp *= scaling_factor; - std::get<121>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<122, ContainerOverSubrelations>; - auto tmp = - (new_term.main_sel_op_coinbase * (new_term.kernel_kernel_in_offset - constants_COINBASE_SELECTOR)); - tmp *= scaling_factor; - std::get<122>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<123, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_fee_per_da_gas * - (new_term.kernel_kernel_in_offset - constants_FEE_PER_DA_GAS_SELECTOR)); - tmp *= scaling_factor; - std::get<123>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<124, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_fee_per_l2_gas * - (new_term.kernel_kernel_in_offset - constants_FEE_PER_L2_GAS_SELECTOR)); - tmp *= scaling_factor; - std::get<124>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<125, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_note_hash_exists * - (new_term.kernel_kernel_out_offset - (constants_START_NOTE_HASH_EXISTS_WRITE_OFFSET + - new_term.kernel_note_hash_exist_write_offset))); - tmp *= scaling_factor; - std::get<125>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<126, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_note_hash_exist_write_offset); - tmp *= scaling_factor; - std::get<126>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<127, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_emit_note_hash * - (new_term.kernel_kernel_out_offset - - (constants_START_EMIT_NOTE_HASH_WRITE_OFFSET + new_term.kernel_emit_note_hash_write_offset))); - tmp *= scaling_factor; - std::get<127>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<128, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_emit_note_hash_write_offset); - tmp *= scaling_factor; - std::get<128>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<129, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_nullifier_exists * - (new_term.kernel_kernel_out_offset - - ((new_term.main_ib * - (constants_START_NULLIFIER_EXISTS_OFFSET + new_term.kernel_nullifier_exists_write_offset)) + - ((FF(1) - new_term.main_ib) * (constants_START_NULLIFIER_NON_EXISTS_OFFSET + - new_term.kernel_nullifier_non_exists_write_offset))))); - tmp *= scaling_factor; - std::get<129>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<130, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_nullifier_exists_write_offset); - tmp *= scaling_factor; - std::get<130>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<131, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_nullifier_non_exists_write_offset); - tmp *= scaling_factor; - std::get<131>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<132, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_emit_nullifier * - (new_term.kernel_kernel_out_offset - - (constants_START_EMIT_NULLIFIER_WRITE_OFFSET + new_term.kernel_emit_nullifier_write_offset))); - tmp *= scaling_factor; - std::get<132>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<133, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_emit_nullifier_write_offset); - tmp *= scaling_factor; - std::get<133>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<134, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_l1_to_l2_msg_exists * - (new_term.kernel_kernel_out_offset - (constants_START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + - new_term.kernel_l1_to_l2_msg_exists_write_offset))); - tmp *= scaling_factor; - std::get<134>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<135, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_l1_to_l2_msg_exists_write_offset); - tmp *= scaling_factor; - std::get<135>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<136, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_emit_unencrypted_log * - (new_term.kernel_kernel_out_offset - (constants_START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET + - new_term.kernel_emit_unencrypted_log_write_offset))); - tmp *= scaling_factor; - std::get<136>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<137, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_emit_unencrypted_log_write_offset); - tmp *= scaling_factor; - std::get<137>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<138, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_emit_l2_to_l1_msg * - (new_term.kernel_kernel_out_offset - (constants_START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET + - new_term.kernel_emit_l2_to_l1_msg_write_offset))); - tmp *= scaling_factor; - std::get<138>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<139, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_emit_l2_to_l1_msg_write_offset); - tmp *= scaling_factor; - std::get<139>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<140, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_sload * - (new_term.kernel_kernel_out_offset - - (constants_START_SLOAD_WRITE_OFFSET + new_term.kernel_sload_write_offset))); - tmp *= scaling_factor; - std::get<140>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<141, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_sload_write_offset); - tmp *= scaling_factor; - std::get<141>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<142, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_sstore * - (new_term.kernel_kernel_out_offset - - (constants_START_SSTORE_WRITE_OFFSET + new_term.kernel_sstore_write_offset))); - tmp *= scaling_factor; - std::get<142>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<143, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_sstore_write_offset); - tmp *= scaling_factor; - std::get<143>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<144, ContainerOverSubrelations>; - auto tmp = (main_KERNEL_OUTPUT_SELECTORS * - (new_term.kernel_side_effect_counter_shift - (new_term.kernel_side_effect_counter + FF(1)))); - tmp *= scaling_factor; - std::get<144>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<145, ContainerOverSubrelations>; auto tmp = ((new_term.main_ib * (FF(1) - new_term.main_tag_err)) * ((new_term.main_sel_op_calldata_copy + new_term.main_sel_op_external_return) - new_term.main_sel_slice_gadget)); tmp *= scaling_factor; - std::get<145>(evals) += typename Accumulator::View(tmp); + std::get<111>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<146, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<112, ContainerOverSubrelations>; auto tmp = (new_term.main_bin_op_id - (new_term.main_sel_op_or + (FF(2) * new_term.main_sel_op_xor))); tmp *= scaling_factor; - std::get<146>(evals) += typename Accumulator::View(tmp); + std::get<112>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<147, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<113, ContainerOverSubrelations>; auto tmp = (new_term.main_sel_bin - ((new_term.main_sel_op_and + new_term.main_sel_op_or) + new_term.main_sel_op_xor)); tmp *= scaling_factor; - std::get<147>(evals) += typename Accumulator::View(tmp); + std::get<113>(evals) += typename Accumulator::View(tmp); } } }; @@ -1078,84 +821,38 @@ template class main : public Relation> { case 81: return "SUBOP_ERROR_RELEVANT_OP"; case 82: - return "KERNEL_INPUT_ACTIVE_CHECK"; - case 83: - return "KERNEL_OUTPUT_ACTIVE_CHECK"; - case 84: return "PC_JUMP"; - case 85: + case 83: return "PC_JUMPI"; - case 86: + case 84: return "RETURN_POINTER_INCREMENT"; - case 92: + case 90: return "RETURN_POINTER_DECREMENT"; - case 97: + case 95: return "PC_INCREMENT"; - case 98: + case 96: return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - case 99: + case 97: return "SPACE_ID_INTERNAL"; - case 100: + case 98: return "SPACE_ID_STANDARD_OPCODES"; - case 101: + case 99: return "CMOV_CONDITION_RES_1"; - case 102: + case 100: return "CMOV_CONDITION_RES_2"; - case 105: + case 103: return "MOV_SAME_VALUE_A"; - case 106: + case 104: return "MOV_SAME_VALUE_B"; - case 107: + case 105: return "MOV_MAIN_SAME_TAG"; - case 111: + case 109: return "L2GASLEFT"; - case 112: + case 110: return "DAGASLEFT"; - case 113: - return "ADDRESS_KERNEL"; - case 114: - return "STORAGE_ADDRESS_KERNEL"; - case 115: - return "SENDER_KERNEL"; - case 116: - return "FUNCTION_SELECTOR_KERNEL"; - case 117: - return "FEE_TRANSACTION_FEE_KERNEL"; - case 118: - return "CHAIN_ID_KERNEL"; - case 119: - return "VERSION_KERNEL"; - case 120: - return "BLOCK_NUMBER_KERNEL"; - case 121: - return "TIMESTAMP_KERNEL"; - case 122: - return "COINBASE_KERNEL"; - case 123: - return "FEE_DA_GAS_KERNEL"; - case 124: - return "FEE_L2_GAS_KERNEL"; - case 125: - return "NOTE_HASH_KERNEL_OUTPUT"; - case 127: - return "EMIT_NOTE_HASH_KERNEL_OUTPUT"; - case 129: - return "NULLIFIER_EXISTS_KERNEL_OUTPUT"; - case 132: - return "EMIT_NULLIFIER_KERNEL_OUTPUT"; - case 134: - return "L1_TO_L2_MSG_EXISTS_KERNEL_OUTPUT"; - case 136: - return "EMIT_UNENCRYPTED_LOG_KERNEL_OUTPUT"; - case 138: - return "EMIT_L2_TO_L1_MSGS_KERNEL_OUTPUT"; - case 140: - return "SLOAD_KERNEL_OUTPUT"; - case 142: - return "SSTORE_KERNEL_OUTPUT"; - case 146: + case 112: return "BIN_SEL_1"; - case 147: + case 113: return "BIN_SEL_2"; } return std::to_string(index); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/verifier.cpp index e1375bc8b1b..d452c718c44 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/verifier.cpp @@ -5,7 +5,6 @@ #include "barretenberg/commitment_schemes/zeromorph/zeromorph.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" -#include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" namespace bb { @@ -110,22 +109,22 @@ bool AvmVerifier::verify_proof(const HonkProof& proof, std::vector mle_challenge(multivariate_challenge.begin(), multivariate_challenge.begin() + static_cast(log_circuit_size)); - FF kernel_kernel_inputs_evaluation = evaluate_public_input_column(public_inputs[0], circuit_size, mle_challenge); - if (kernel_kernel_inputs_evaluation != claimed_evaluations.kernel_kernel_inputs) { + FF main_kernel_inputs_evaluation = evaluate_public_input_column(public_inputs[0], circuit_size, mle_challenge); + if (main_kernel_inputs_evaluation != claimed_evaluations.main_kernel_inputs) { return false; } - FF kernel_kernel_value_out_evaluation = evaluate_public_input_column(public_inputs[1], circuit_size, mle_challenge); - if (kernel_kernel_value_out_evaluation != claimed_evaluations.kernel_kernel_value_out) { + FF main_kernel_value_out_evaluation = evaluate_public_input_column(public_inputs[1], circuit_size, mle_challenge); + if (main_kernel_value_out_evaluation != claimed_evaluations.main_kernel_value_out) { return false; } - FF kernel_kernel_side_effect_out_evaluation = + FF main_kernel_side_effect_out_evaluation = evaluate_public_input_column(public_inputs[2], circuit_size, mle_challenge); - if (kernel_kernel_side_effect_out_evaluation != claimed_evaluations.kernel_kernel_side_effect_out) { + if (main_kernel_side_effect_out_evaluation != claimed_evaluations.main_kernel_side_effect_out) { return false; } - FF kernel_kernel_metadata_out_evaluation = + FF main_kernel_metadata_out_evaluation = evaluate_public_input_column(public_inputs[3], circuit_size, mle_challenge); - if (kernel_kernel_metadata_out_evaluation != claimed_evaluations.kernel_kernel_metadata_out) { + if (main_kernel_metadata_out_evaluation != claimed_evaluations.main_kernel_metadata_out) { return false; } FF main_calldata_evaluation = evaluate_public_input_column(public_inputs[4], circuit_size, mle_challenge); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp index e07ef47d37f..43f95355e80 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp @@ -1764,40 +1764,40 @@ TEST_F(AvmExecutionTests, kernelOutputEmitOpcodes) auto emit_note_hash_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_emit_note_hash == 1; }); EXPECT_EQ(emit_note_hash_row->main_ia, 1); - EXPECT_EQ(emit_note_hash_row->kernel_side_effect_counter, 0); + EXPECT_EQ(emit_note_hash_row->main_side_effect_counter, 0); // Get the row of the first note hash out uint32_t emit_note_hash_out_offset = START_EMIT_NOTE_HASH_WRITE_OFFSET; auto emit_note_hash_kernel_out_row = std::ranges::find_if( trace.begin(), trace.end(), [&](Row r) { return r.main_clk == emit_note_hash_out_offset; }); - EXPECT_EQ(emit_note_hash_kernel_out_row->kernel_kernel_value_out, 1); - EXPECT_EQ(emit_note_hash_kernel_out_row->kernel_kernel_side_effect_out, 0); + EXPECT_EQ(emit_note_hash_kernel_out_row->main_kernel_value_out, 1); + EXPECT_EQ(emit_note_hash_kernel_out_row->main_kernel_side_effect_out, 0); feed_output(emit_note_hash_out_offset, 1, 0, 0); // CHECK EMIT NULLIFIER auto emit_nullifier_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_emit_nullifier == 1; }); EXPECT_EQ(emit_nullifier_row->main_ia, 1); - EXPECT_EQ(emit_nullifier_row->kernel_side_effect_counter, 1); + EXPECT_EQ(emit_nullifier_row->main_side_effect_counter, 1); uint32_t emit_nullifier_out_offset = START_EMIT_NULLIFIER_WRITE_OFFSET; auto emit_nullifier_kernel_out_row = std::ranges::find_if( trace.begin(), trace.end(), [&](Row r) { return r.main_clk == emit_nullifier_out_offset; }); - EXPECT_EQ(emit_nullifier_kernel_out_row->kernel_kernel_value_out, 1); - EXPECT_EQ(emit_nullifier_kernel_out_row->kernel_kernel_side_effect_out, 1); + EXPECT_EQ(emit_nullifier_kernel_out_row->main_kernel_value_out, 1); + EXPECT_EQ(emit_nullifier_kernel_out_row->main_kernel_side_effect_out, 1); feed_output(emit_nullifier_out_offset, 1, 1, 0); // CHECK EMIT UNENCRYPTED LOG auto emit_log_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_emit_unencrypted_log == 1; }); EXPECT_EQ(emit_log_row->main_ia, 1); - EXPECT_EQ(emit_log_row->kernel_side_effect_counter, 2); + EXPECT_EQ(emit_log_row->main_side_effect_counter, 2); uint32_t emit_log_out_offset = START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET; auto emit_log_kernel_out_row = std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == emit_log_out_offset; }); - EXPECT_EQ(emit_log_kernel_out_row->kernel_kernel_value_out, 1); - EXPECT_EQ(emit_log_kernel_out_row->kernel_kernel_side_effect_out, 2); + EXPECT_EQ(emit_log_kernel_out_row->main_kernel_value_out, 1); + EXPECT_EQ(emit_log_kernel_out_row->main_kernel_side_effect_out, 2); feed_output(emit_log_out_offset, 1, 2, 0); // CHECK SEND L2 TO L1 MSG @@ -1805,13 +1805,13 @@ TEST_F(AvmExecutionTests, kernelOutputEmitOpcodes) std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_emit_l2_to_l1_msg == 1; }); EXPECT_EQ(send_row->main_ia, 1); EXPECT_EQ(send_row->main_ib, 1); - EXPECT_EQ(send_row->kernel_side_effect_counter, 3); + EXPECT_EQ(send_row->main_side_effect_counter, 3); auto msg_out_row = std::ranges::find_if( trace.begin(), trace.end(), [&](Row r) { return r.main_clk == START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET; }); - EXPECT_EQ(msg_out_row->kernel_kernel_value_out, 1); - EXPECT_EQ(msg_out_row->kernel_kernel_side_effect_out, 3); - EXPECT_EQ(msg_out_row->kernel_kernel_metadata_out, 1); + EXPECT_EQ(msg_out_row->main_kernel_value_out, 1); + EXPECT_EQ(msg_out_row->main_kernel_side_effect_out, 3); + EXPECT_EQ(msg_out_row->main_kernel_metadata_out, 1); feed_output(START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET, 1, 3, 1); validate_trace(std::move(trace), public_inputs); @@ -1860,15 +1860,15 @@ TEST_F(AvmExecutionTests, kernelOutputStorageLoadOpcodeSimple) auto sload_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sload == 1; }); EXPECT_EQ(sload_row->main_ia, 42); // Read value EXPECT_EQ(sload_row->main_ib, 9); // Storage slot - EXPECT_EQ(sload_row->kernel_side_effect_counter, 0); + EXPECT_EQ(sload_row->main_side_effect_counter, 0); // Get the row of the first read storage read out uint32_t sload_out_offset = START_SLOAD_WRITE_OFFSET; auto sload_kernel_out_row = std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == sload_out_offset; }); - EXPECT_EQ(sload_kernel_out_row->kernel_kernel_value_out, 42); // value - EXPECT_EQ(sload_kernel_out_row->kernel_kernel_side_effect_out, 0); - EXPECT_EQ(sload_kernel_out_row->kernel_kernel_metadata_out, 9); // slot + EXPECT_EQ(sload_kernel_out_row->main_kernel_value_out, 42); // value + EXPECT_EQ(sload_kernel_out_row->main_kernel_side_effect_out, 0); + EXPECT_EQ(sload_kernel_out_row->main_kernel_metadata_out, 9); // slot feed_output(sload_out_offset, 42, 0, 9); validate_trace(std::move(trace), public_inputs); } @@ -1917,23 +1917,23 @@ TEST_F(AvmExecutionTests, kernelOutputStorageLoadOpcodeComplex) auto sload_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sload == 1; }); EXPECT_EQ(sload_row->main_ia, 42); // Read value EXPECT_EQ(sload_row->main_ib, 9); // Storage slot - EXPECT_EQ(sload_row->kernel_side_effect_counter, 0); + EXPECT_EQ(sload_row->main_side_effect_counter, 0); sload_row++; EXPECT_EQ(sload_row->main_ia, 123); // Read value EXPECT_EQ(sload_row->main_ib, 10); // Storage slot - EXPECT_EQ(sload_row->kernel_side_effect_counter, 1); + EXPECT_EQ(sload_row->main_side_effect_counter, 1); // Get the row of the first read storage read out uint32_t sload_out_offset = START_SLOAD_WRITE_OFFSET; auto sload_kernel_out_row = std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == sload_out_offset; }); - EXPECT_EQ(sload_kernel_out_row->kernel_kernel_value_out, 42); // value - EXPECT_EQ(sload_kernel_out_row->kernel_kernel_side_effect_out, 0); - EXPECT_EQ(sload_kernel_out_row->kernel_kernel_metadata_out, 9); // slot + EXPECT_EQ(sload_kernel_out_row->main_kernel_value_out, 42); // value + EXPECT_EQ(sload_kernel_out_row->main_kernel_side_effect_out, 0); + EXPECT_EQ(sload_kernel_out_row->main_kernel_metadata_out, 9); // slot sload_kernel_out_row++; - EXPECT_EQ(sload_kernel_out_row->kernel_kernel_value_out, 123); // value - EXPECT_EQ(sload_kernel_out_row->kernel_kernel_side_effect_out, 1); - EXPECT_EQ(sload_kernel_out_row->kernel_kernel_metadata_out, 10); // slot + EXPECT_EQ(sload_kernel_out_row->main_kernel_value_out, 123); // value + EXPECT_EQ(sload_kernel_out_row->main_kernel_side_effect_out, 1); + EXPECT_EQ(sload_kernel_out_row->main_kernel_metadata_out, 10); // slot feed_output(sload_out_offset, 42, 0, 9); feed_output(sload_out_offset + 1, 123, 1, 10); @@ -1973,16 +1973,16 @@ TEST_F(AvmExecutionTests, kernelOutputStorageStoreOpcodeSimple) auto sstore_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sstore == 1; }); EXPECT_EQ(sstore_row->main_ia, 42); // Read value EXPECT_EQ(sstore_row->main_ib, 9); // Storage slot - EXPECT_EQ(sstore_row->kernel_side_effect_counter, 0); + EXPECT_EQ(sstore_row->main_side_effect_counter, 0); // Get the row of the first storage write out uint32_t sstore_out_offset = START_SSTORE_WRITE_OFFSET; auto sstore_kernel_out_row = std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == sstore_out_offset; }); - auto value_out = sstore_kernel_out_row->kernel_kernel_value_out; - auto side_effect_out = sstore_kernel_out_row->kernel_kernel_side_effect_out; - auto metadata_out = sstore_kernel_out_row->kernel_kernel_metadata_out; + auto value_out = sstore_kernel_out_row->main_kernel_value_out; + auto side_effect_out = sstore_kernel_out_row->main_kernel_side_effect_out; + auto metadata_out = sstore_kernel_out_row->main_kernel_metadata_out; EXPECT_EQ(value_out, 42); // value EXPECT_EQ(side_effect_out, 0); EXPECT_EQ(metadata_out, 9); // slot @@ -2028,24 +2028,24 @@ TEST_F(AvmExecutionTests, kernelOutputStorageStoreOpcodeComplex) auto sstore_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sstore == 1; }); EXPECT_EQ(sstore_row->main_ia, 42); // Read value EXPECT_EQ(sstore_row->main_ib, 9); // Storage slot - EXPECT_EQ(sstore_row->kernel_side_effect_counter, 0); + EXPECT_EQ(sstore_row->main_side_effect_counter, 0); sstore_row++; EXPECT_EQ(sstore_row->main_ia, 123); // Read value EXPECT_EQ(sstore_row->main_ib, 10); // Storage slot - EXPECT_EQ(sstore_row->kernel_side_effect_counter, 1); + EXPECT_EQ(sstore_row->main_side_effect_counter, 1); // Get the row of the first storage write out uint32_t sstore_out_offset = START_SSTORE_WRITE_OFFSET; auto sstore_kernel_out_row = std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == sstore_out_offset; }); - EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_value_out, 42); // value - EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_side_effect_out, 0); - EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_metadata_out, 9); // slot + EXPECT_EQ(sstore_kernel_out_row->main_kernel_value_out, 42); // value + EXPECT_EQ(sstore_kernel_out_row->main_kernel_side_effect_out, 0); + EXPECT_EQ(sstore_kernel_out_row->main_kernel_metadata_out, 9); // slot sstore_kernel_out_row++; - EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_value_out, 123); // value - EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_side_effect_out, 1); - EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_metadata_out, 10); // slot + EXPECT_EQ(sstore_kernel_out_row->main_kernel_value_out, 123); // value + EXPECT_EQ(sstore_kernel_out_row->main_kernel_side_effect_out, 1); + EXPECT_EQ(sstore_kernel_out_row->main_kernel_metadata_out, 10); // slot feed_output(sstore_out_offset, 42, 0, 9); feed_output(sstore_out_offset + 1, 123, 1, 10); @@ -2102,30 +2102,30 @@ TEST_F(AvmExecutionTests, kernelOutputStorageOpcodes) auto sload_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sload == 1; }); EXPECT_EQ(sload_row->main_ia, 42); // Read value EXPECT_EQ(sload_row->main_ib, 9); // Storage slot - EXPECT_EQ(sload_row->kernel_side_effect_counter, 0); + EXPECT_EQ(sload_row->main_side_effect_counter, 0); // Get the row of the first storage read out uint32_t sload_out_offset = START_SLOAD_WRITE_OFFSET; auto sload_kernel_out_row = std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == sload_out_offset; }); - EXPECT_EQ(sload_kernel_out_row->kernel_kernel_value_out, 42); // value - EXPECT_EQ(sload_kernel_out_row->kernel_kernel_side_effect_out, 0); - EXPECT_EQ(sload_kernel_out_row->kernel_kernel_metadata_out, 9); // slot + EXPECT_EQ(sload_kernel_out_row->main_kernel_value_out, 42); // value + EXPECT_EQ(sload_kernel_out_row->main_kernel_side_effect_out, 0); + EXPECT_EQ(sload_kernel_out_row->main_kernel_metadata_out, 9); // slot feed_output(sload_out_offset, 42, 0, 9); // CHECK SSTORE auto sstore_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sstore == 1; }); EXPECT_EQ(sstore_row->main_ia, 42); // Read value EXPECT_EQ(sstore_row->main_ib, 9); // Storage slot - EXPECT_EQ(sstore_row->kernel_side_effect_counter, 1); + EXPECT_EQ(sstore_row->main_side_effect_counter, 1); // Get the row of the first storage write out uint32_t sstore_out_offset = START_SSTORE_WRITE_OFFSET; auto sstore_kernel_out_row = std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == sstore_out_offset; }); - EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_value_out, 42); // value - EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_side_effect_out, 1); - EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_metadata_out, 9); // slot + EXPECT_EQ(sstore_kernel_out_row->main_kernel_value_out, 42); // value + EXPECT_EQ(sstore_kernel_out_row->main_kernel_side_effect_out, 1); + EXPECT_EQ(sstore_kernel_out_row->main_kernel_metadata_out, 9); // slot feed_output(sstore_out_offset, 42, 1, 9); validate_trace(std::move(trace), public_inputs); @@ -2183,13 +2183,13 @@ TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes) std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_note_hash_exists == 1; }); EXPECT_EQ(note_hash_row->main_ia, 1); // Read value EXPECT_EQ(note_hash_row->main_ib, 1); // Storage slot - EXPECT_EQ(note_hash_row->kernel_side_effect_counter, 0); + EXPECT_EQ(note_hash_row->main_side_effect_counter, 0); auto note_hash_out_row = std::ranges::find_if( trace.begin(), trace.end(), [&](Row r) { return r.main_clk == START_NOTE_HASH_EXISTS_WRITE_OFFSET; }); - EXPECT_EQ(note_hash_out_row->kernel_kernel_value_out, 1); // value - EXPECT_EQ(note_hash_out_row->kernel_kernel_side_effect_out, 0); - EXPECT_EQ(note_hash_out_row->kernel_kernel_metadata_out, 1); // exists + EXPECT_EQ(note_hash_out_row->main_kernel_value_out, 1); // value + EXPECT_EQ(note_hash_out_row->main_kernel_side_effect_out, 0); + EXPECT_EQ(note_hash_out_row->main_kernel_metadata_out, 1); // exists feed_output(START_NOTE_HASH_EXISTS_WRITE_OFFSET, 1, 0, 1); // CHECK NULLIFIEREXISTS @@ -2197,13 +2197,13 @@ TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes) std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_nullifier_exists == 1; }); EXPECT_EQ(nullifier_row->main_ia, 1); // Read value EXPECT_EQ(nullifier_row->main_ib, 1); // Storage slot - EXPECT_EQ(nullifier_row->kernel_side_effect_counter, 1); + EXPECT_EQ(nullifier_row->main_side_effect_counter, 1); auto nullifier_out_row = std::ranges::find_if( trace.begin(), trace.end(), [&](Row r) { return r.main_clk == START_NULLIFIER_EXISTS_OFFSET; }); - EXPECT_EQ(nullifier_out_row->kernel_kernel_value_out, 1); // value - EXPECT_EQ(nullifier_out_row->kernel_kernel_side_effect_out, 1); - EXPECT_EQ(nullifier_out_row->kernel_kernel_metadata_out, 1); // exists + EXPECT_EQ(nullifier_out_row->main_kernel_value_out, 1); // value + EXPECT_EQ(nullifier_out_row->main_kernel_side_effect_out, 1); + EXPECT_EQ(nullifier_out_row->main_kernel_metadata_out, 1); // exists feed_output(START_NULLIFIER_EXISTS_OFFSET, 1, 1, 1); // CHECK L1TOL2MSGEXISTS @@ -2211,13 +2211,13 @@ TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes) std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_l1_to_l2_msg_exists == 1; }); EXPECT_EQ(l1_to_l2_row->main_ia, 1); // Read value EXPECT_EQ(l1_to_l2_row->main_ib, 1); // Storage slot - EXPECT_EQ(l1_to_l2_row->kernel_side_effect_counter, 2); + EXPECT_EQ(l1_to_l2_row->main_side_effect_counter, 2); auto msg_out_row = std::ranges::find_if( trace.begin(), trace.end(), [&](Row r) { return r.main_clk == START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET; }); - EXPECT_EQ(msg_out_row->kernel_kernel_value_out, 1); // value - EXPECT_EQ(msg_out_row->kernel_kernel_side_effect_out, 2); - EXPECT_EQ(msg_out_row->kernel_kernel_metadata_out, 1); // exists + EXPECT_EQ(msg_out_row->main_kernel_value_out, 1); // value + EXPECT_EQ(msg_out_row->main_kernel_side_effect_out, 2); + EXPECT_EQ(msg_out_row->main_kernel_metadata_out, 1); // exists feed_output(START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET, 1, 2, 1); validate_trace(std::move(trace), public_inputs); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/tests/helpers.test.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/tests/helpers.test.cpp index b3458589489..26851bc304e 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/tests/helpers.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/tests/helpers.test.cpp @@ -41,7 +41,6 @@ void validate_trace(std::vector&& trace, bool with_proof, bool expect_proof_failure) { - setenv("AVM_VERBOSE_ERRORS", "1", 1); const std::string avm_dump_trace_path = std::getenv("AVM_DUMP_TRACE_PATH") != nullptr ? std::getenv("AVM_DUMP_TRACE_PATH") : ""; if (!avm_dump_trace_path.empty()) { diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/tests/kernel.test.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/tests/kernel.test.cpp index 6dc5b273d6a..15277be8c48 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/tests/kernel.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/tests/kernel.test.cpp @@ -83,7 +83,7 @@ void test_kernel_lookup(bool indirect, void expect_row(auto row, FF selector, FF ia, FF ind_a, FF mem_addr_a, AvmMemoryTag w_in_tag) { // Checks dependent on the opcode - EXPECT_EQ(row->kernel_kernel_in_offset, selector); + EXPECT_EQ(row->main_kernel_in_offset, selector); EXPECT_EQ(row->main_ia, ia); EXPECT_EQ(row->main_mem_addr_a, mem_addr_a); @@ -106,7 +106,7 @@ void expect_output_table_row(auto row, uint32_t rwa = 0) { // Checks dependent on the opcode - EXPECT_EQ(row->kernel_kernel_out_offset, selector); + EXPECT_EQ(row->main_kernel_out_offset, selector); EXPECT_EQ(row->main_ia, ia); EXPECT_EQ(row->main_mem_addr_a, mem_addr_a); @@ -118,7 +118,7 @@ void expect_output_table_row(auto row, EXPECT_EQ(row->main_r_in_tag, static_cast(r_in_tag)); EXPECT_EQ(row->main_sel_q_kernel_output_lookup, FF(1)); - EXPECT_EQ(row->kernel_side_effect_counter, FF(side_effect_counter)); + EXPECT_EQ(row->main_side_effect_counter, FF(side_effect_counter)); } void expect_output_table_row_with_metadata(auto row, @@ -174,9 +174,9 @@ void expect_output_table_row_with_exists_metadata(auto row, void check_kernel_outputs(const Row& row, FF value, FF side_effect_counter, FF metadata) { - EXPECT_EQ(row.kernel_kernel_value_out, value); - EXPECT_EQ(row.kernel_kernel_side_effect_out, side_effect_counter); - EXPECT_EQ(row.kernel_kernel_metadata_out, metadata); + EXPECT_EQ(row.main_kernel_value_out, value); + EXPECT_EQ(row.main_kernel_side_effect_out, side_effect_counter); + EXPECT_EQ(row.main_kernel_metadata_out, metadata); } TEST_F(AvmKernelPositiveTests, kernelSender) @@ -951,12 +951,12 @@ TEST_F(AvmKernelOutputPositiveTests, kernelEmitNoteHash) // We write the note hash into memory auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, 1234, direct_offset, AvmMemoryTag::FF); - trace_builder.op_emit_note_hash(/*indirect=*/false, direct_offset); + trace_builder.op_emit_note_hash(/*indirect=*/0, direct_offset); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, 1234, direct_offset, AvmMemoryTag::FF); trace_builder.op_set(0, direct_offset, indirect_offset, AvmMemoryTag::U32); - trace_builder.op_emit_note_hash(/*indirect=*/true, indirect_offset); + trace_builder.op_emit_note_hash(/*indirect=*/1, indirect_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -993,12 +993,12 @@ TEST_F(AvmKernelOutputPositiveTests, kernelEmitNullifier) // We write the note hash into memory auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, 1234, direct_offset, AvmMemoryTag::FF); - trace_builder.op_emit_nullifier(/*indirect=*/false, direct_offset); + trace_builder.op_emit_nullifier(/*indirect=*/0, direct_offset); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, 1234, direct_offset, AvmMemoryTag::FF); trace_builder.op_set(0, direct_offset, indirect_offset, AvmMemoryTag::U32); - trace_builder.op_emit_nullifier(/*indirect=*/true, indirect_offset); + trace_builder.op_emit_nullifier(/*indirect=*/1, indirect_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -1038,11 +1038,11 @@ TEST_F(AvmKernelOutputPositiveTests, kernelEmitL2ToL1Msg) uint32_t recipient = 420; uint32_t output_offset = START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET; - // auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - // trace_builder.op_set(0, 1234, msg_offset, AvmMemoryTag::FF); - // trace_builder.op_set(0, 420, recipient_offset, AvmMemoryTag::FF); - // trace_builder.op_emit_l2_to_l1_msg(false, recipient_offset, msg_offset); - // }; + auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { + trace_builder.op_set(0, 1234, msg_offset, AvmMemoryTag::FF); + trace_builder.op_set(0, 420, recipient_offset, AvmMemoryTag::FF); + trace_builder.op_emit_l2_to_l1_msg(0, recipient_offset, msg_offset); + }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, 1234, msg_offset, AvmMemoryTag::FF); trace_builder.op_set(0, msg_offset, indirect_msg_offset, AvmMemoryTag::U32); @@ -1071,9 +1071,9 @@ TEST_F(AvmKernelOutputPositiveTests, kernelEmitL2ToL1Msg) check_kernel_outputs(trace.at(output_offset), value, /*side_effect_counter=*/0, /*metadata=*/recipient); }; - // test_kernel_lookup(false, direct_apply_opcodes, checks); VmPublicInputs public_inputs = get_public_inputs_with_output(output_offset, value, /*side_effect_counter=*/0, recipient); + test_kernel_lookup(false, direct_apply_opcodes, checks, std::move(public_inputs)); test_kernel_lookup(true, indirect_apply_opcodes, checks, std::move(public_inputs)); } @@ -1088,12 +1088,12 @@ TEST_F(AvmKernelOutputPositiveTests, kernelEmitUnencryptedLog) // We write the note hash into memory auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, 1234, direct_offset, AvmMemoryTag::FF); - trace_builder.op_emit_unencrypted_log(/*indirect=*/false, direct_offset, /*log_size_offset=*/0); + trace_builder.op_emit_unencrypted_log(/*indirect=*/0, direct_offset, /*log_size_offset=*/0); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, 1234, direct_offset, AvmMemoryTag::FF); trace_builder.op_set(0, direct_offset, indirect_offset, AvmMemoryTag::U32); - trace_builder.op_emit_unencrypted_log(/*indirect=*/true, indirect_offset, /*log_size_offset=*/0); + trace_builder.op_emit_unencrypted_log(/*indirect=*/1, indirect_offset, /*log_size_offset=*/0); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -1264,7 +1264,7 @@ TEST_F(AvmKernelOutputPositiveTests, kernelNullifierExists) auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, static_cast(value), value_offset, AvmMemoryTag::FF); - trace_builder.op_nullifier_exists(/*indirect=*/false, value_offset, metadata_offset); + trace_builder.op_nullifier_exists(/*indirect=*/0, value_offset, metadata_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( @@ -1303,7 +1303,7 @@ TEST_F(AvmKernelOutputPositiveTests, kernelNullifierNonExists) auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, static_cast(value), value_offset, AvmMemoryTag::FF); - trace_builder.op_nullifier_exists(/*indirect=*/false, value_offset, metadata_offset); + trace_builder.op_nullifier_exists(/*indirect=*/0, value_offset, metadata_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/common.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/common.hpp index 1710120b7dc..18d7019e229 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/common.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/common.hpp @@ -1,7 +1,6 @@ #pragma once #include "barretenberg/common/throw_or_abort.hpp" -#include "barretenberg/serialize/msgpack.hpp" #include "barretenberg/vm/constants.hpp" #include "barretenberg/vm/avm/generated/flavor_settings.hpp" @@ -9,8 +8,6 @@ #include #include -#include -#include namespace bb::avm_trace { @@ -35,8 +32,6 @@ constexpr size_t L2_LO_GAS_COUNTS_IDX = 1; constexpr size_t DA_HI_GAS_COUNTS_IDX = 2; constexpr size_t DA_LO_GAS_COUNTS_IDX = 3; -// Number of rows -static const size_t AVM_TRACE_SIZE = 1 << 18; enum class IntermRegister : uint32_t { IA = 0, IB = 1, IC = 2, ID = 3 }; enum class IndirectRegister : uint32_t { IND_A = 0, IND_B = 1, IND_C = 2, IND_D = 3 }; @@ -48,159 +43,4 @@ static const size_t NUM_MEM_SPACES = 256; static const uint8_t INTERNAL_CALL_SPACE_ID = 255; static const uint32_t MAX_SIZE_INTERNAL_STACK = 1 << 16; -struct ExternalCallHint { - FF success; - std::vector return_data; - uint32_t l2_gas_used; - uint32_t da_gas_used; - FF end_side_effect_counter; -}; - -// Add support for deserialization of ExternalCallHint. This is implicitly used by serialize::read -// when trying to read std::vector. -inline void read(uint8_t const*& it, ExternalCallHint& hint) -{ - using serialize::read; - read(it, hint.success); - read(it, hint.return_data); - read(it, hint.l2_gas_used); - read(it, hint.da_gas_used); - read(it, hint.end_side_effect_counter); -} - -struct ContractInstanceHint { - FF address; - FF instance_found_in_address; - FF salt; - FF deployer_addr; - FF contract_class_id; - FF initialisation_hash; - FF public_key_hash; -}; - -// Add support for deserialization of ContractInstanceHint. -inline void read(uint8_t const*& it, ContractInstanceHint& hint) -{ - using serialize::read; - read(it, hint.address); - read(it, hint.instance_found_in_address); - read(it, hint.salt); - read(it, hint.deployer_addr); - read(it, hint.contract_class_id); - read(it, hint.initialisation_hash); - read(it, hint.public_key_hash); -} - -struct ExecutionHints { - std::vector> storage_value_hints; - std::vector> note_hash_exists_hints; - std::vector> nullifier_exists_hints; - std::vector> l1_to_l2_message_exists_hints; - std::vector externalcall_hints; - std::map contract_instance_hints; - - ExecutionHints() = default; - - // Builder. - ExecutionHints& with_storage_value_hints(std::vector> storage_value_hints) - { - this->storage_value_hints = std::move(storage_value_hints); - return *this; - } - ExecutionHints& with_note_hash_exists_hints(std::vector> note_hash_exists_hints) - { - this->note_hash_exists_hints = std::move(note_hash_exists_hints); - return *this; - } - ExecutionHints& with_nullifier_exists_hints(std::vector> nullifier_exists_hints) - { - this->nullifier_exists_hints = std::move(nullifier_exists_hints); - return *this; - } - ExecutionHints& with_l1_to_l2_message_exists_hints(std::vector> l1_to_l2_message_exists_hints) - { - this->l1_to_l2_message_exists_hints = std::move(l1_to_l2_message_exists_hints); - return *this; - } - ExecutionHints& with_externalcall_hints(std::vector externalcall_hints) - { - this->externalcall_hints = std::move(externalcall_hints); - return *this; - } - ExecutionHints& with_contract_instance_hints(std::map contract_instance_hints) - { - this->contract_instance_hints = std::move(contract_instance_hints); - return *this; - } - - static void push_vec_into_map(std::unordered_map& into_map, - const std::vector>& from_pair_vec) - { - for (const auto& pair : from_pair_vec) { - into_map[static_cast(pair.first)] = pair.second; - } - } - - // TODO: Cache. - // Side effect counter -> value - std::unordered_map get_side_effect_hints() const - { - std::unordered_map hints_map; - push_vec_into_map(hints_map, storage_value_hints); - push_vec_into_map(hints_map, note_hash_exists_hints); - push_vec_into_map(hints_map, nullifier_exists_hints); - push_vec_into_map(hints_map, l1_to_l2_message_exists_hints); - return hints_map; - } - - static ExecutionHints from(const std::vector& data) - { - std::vector> storage_value_hints; - std::vector> note_hash_exists_hints; - std::vector> nullifier_exists_hints; - std::vector> l1_to_l2_message_exists_hints; - - using serialize::read; - const auto* it = data.data(); - read(it, storage_value_hints); - read(it, note_hash_exists_hints); - read(it, nullifier_exists_hints); - read(it, l1_to_l2_message_exists_hints); - - std::vector externalcall_hints; - read(it, externalcall_hints); - - std::vector contract_instance_hints_vec; - read(it, contract_instance_hints_vec); - std::map contract_instance_hints; - for (const auto& instance : contract_instance_hints_vec) { - contract_instance_hints[instance.address] = instance; - } - - if (it != data.data() + data.size()) { - throw_or_abort("Failed to deserialize ExecutionHints: only read" + std::to_string(it - data.data()) + - " bytes out of " + std::to_string(data.size()) + " bytes"); - } - - return { std::move(storage_value_hints), std::move(note_hash_exists_hints), - std::move(nullifier_exists_hints), std::move(l1_to_l2_message_exists_hints), - std::move(externalcall_hints), std::move(contract_instance_hints) }; - } - - private: - ExecutionHints(std::vector> storage_value_hints, - std::vector> note_hash_exists_hints, - std::vector> nullifier_exists_hints, - std::vector> l1_to_l2_message_exists_hints, - std::vector externalcall_hints, - std::map contract_instance_hints) - : storage_value_hints(std::move(storage_value_hints)) - , note_hash_exists_hints(std::move(note_hash_exists_hints)) - , nullifier_exists_hints(std::move(nullifier_exists_hints)) - , l1_to_l2_message_exists_hints(std::move(l1_to_l2_message_exists_hints)) - , externalcall_hints(std::move(externalcall_hints)) - , contract_instance_hints(std::move(contract_instance_hints)) - {} -}; - } // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution_hints.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution_hints.hpp new file mode 100644 index 00000000000..df54b770f05 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution_hints.hpp @@ -0,0 +1,164 @@ +#pragma once + +#include "barretenberg/vm/avm/generated/flavor_settings.hpp" + +namespace bb::avm_trace { + +using FF = AvmFlavorSettings::FF; + +struct ExternalCallHint { + FF success; + std::vector return_data; + uint32_t l2_gas_used; + uint32_t da_gas_used; + FF end_side_effect_counter; +}; + +// Add support for deserialization of ExternalCallHint. This is implicitly used by serialize::read +// when trying to read std::vector. +inline void read(uint8_t const*& it, ExternalCallHint& hint) +{ + using serialize::read; + read(it, hint.success); + read(it, hint.return_data); + read(it, hint.l2_gas_used); + read(it, hint.da_gas_used); + read(it, hint.end_side_effect_counter); +} + +struct ContractInstanceHint { + FF address; + FF instance_found_in_address; + FF salt; + FF deployer_addr; + FF contract_class_id; + FF initialisation_hash; + FF public_key_hash; +}; + +// Add support for deserialization of ContractInstanceHint. +inline void read(uint8_t const*& it, ContractInstanceHint& hint) +{ + using serialize::read; + read(it, hint.address); + read(it, hint.instance_found_in_address); + read(it, hint.salt); + read(it, hint.deployer_addr); + read(it, hint.contract_class_id); + read(it, hint.initialisation_hash); + read(it, hint.public_key_hash); +} + +struct ExecutionHints { + std::vector> storage_value_hints; + std::vector> note_hash_exists_hints; + std::vector> nullifier_exists_hints; + std::vector> l1_to_l2_message_exists_hints; + std::vector externalcall_hints; + std::map contract_instance_hints; + + ExecutionHints() = default; + + // Builder. + ExecutionHints& with_storage_value_hints(std::vector> storage_value_hints) + { + this->storage_value_hints = std::move(storage_value_hints); + return *this; + } + ExecutionHints& with_note_hash_exists_hints(std::vector> note_hash_exists_hints) + { + this->note_hash_exists_hints = std::move(note_hash_exists_hints); + return *this; + } + ExecutionHints& with_nullifier_exists_hints(std::vector> nullifier_exists_hints) + { + this->nullifier_exists_hints = std::move(nullifier_exists_hints); + return *this; + } + ExecutionHints& with_l1_to_l2_message_exists_hints(std::vector> l1_to_l2_message_exists_hints) + { + this->l1_to_l2_message_exists_hints = std::move(l1_to_l2_message_exists_hints); + return *this; + } + ExecutionHints& with_externalcall_hints(std::vector externalcall_hints) + { + this->externalcall_hints = std::move(externalcall_hints); + return *this; + } + ExecutionHints& with_contract_instance_hints(std::map contract_instance_hints) + { + this->contract_instance_hints = std::move(contract_instance_hints); + return *this; + } + + static void push_vec_into_map(std::unordered_map& into_map, + const std::vector>& from_pair_vec) + { + for (const auto& pair : from_pair_vec) { + into_map[static_cast(pair.first)] = pair.second; + } + } + + // TODO: Cache. + // Side effect counter -> value + std::unordered_map get_side_effect_hints() const + { + std::unordered_map hints_map; + push_vec_into_map(hints_map, storage_value_hints); + push_vec_into_map(hints_map, note_hash_exists_hints); + push_vec_into_map(hints_map, nullifier_exists_hints); + push_vec_into_map(hints_map, l1_to_l2_message_exists_hints); + return hints_map; + } + + static ExecutionHints from(const std::vector& data) + { + std::vector> storage_value_hints; + std::vector> note_hash_exists_hints; + std::vector> nullifier_exists_hints; + std::vector> l1_to_l2_message_exists_hints; + + using serialize::read; + const auto* it = data.data(); + read(it, storage_value_hints); + read(it, note_hash_exists_hints); + read(it, nullifier_exists_hints); + read(it, l1_to_l2_message_exists_hints); + + std::vector externalcall_hints; + read(it, externalcall_hints); + + std::vector contract_instance_hints_vec; + read(it, contract_instance_hints_vec); + std::map contract_instance_hints; + for (const auto& instance : contract_instance_hints_vec) { + contract_instance_hints[instance.address] = instance; + } + + if (it != data.data() + data.size()) { + throw_or_abort("Failed to deserialize ExecutionHints: only read" + std::to_string(it - data.data()) + + " bytes out of " + std::to_string(data.size()) + " bytes"); + } + + return { std::move(storage_value_hints), std::move(note_hash_exists_hints), + std::move(nullifier_exists_hints), std::move(l1_to_l2_message_exists_hints), + std::move(externalcall_hints), std::move(contract_instance_hints) }; + } + + private: + ExecutionHints(std::vector> storage_value_hints, + std::vector> note_hash_exists_hints, + std::vector> nullifier_exists_hints, + std::vector> l1_to_l2_message_exists_hints, + std::vector externalcall_hints, + std::map contract_instance_hints) + : storage_value_hints(std::move(storage_value_hints)) + , note_hash_exists_hints(std::move(note_hash_exists_hints)) + , nullifier_exists_hints(std::move(nullifier_exists_hints)) + , l1_to_l2_message_exists_hints(std::move(l1_to_l2_message_exists_hints)) + , externalcall_hints(std::move(externalcall_hints)) + , contract_instance_hints(std::move(contract_instance_hints)) + {} +}; + +} // namespace bb::avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/finalization.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/finalization.hpp new file mode 100644 index 00000000000..52bcde8b638 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/finalization.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include "barretenberg/common/assert.hpp" +#include "barretenberg/vm/avm/generated/full_row.hpp" +#include "barretenberg/vm/avm/trace/common.hpp" + +#include +#include + +namespace bb::avm_trace { + +/** + * @brief Iterates over the main trace and an event trace and performs an action. + * @details This function iterates on the main trace and an event trace and applies: + * - `func_map` when the main trace clk matches the event trace clk. + * - `func_all` for all rows that are EXECUTION trace rows. + * This function assumes that the clks in the traces are monotonically increasing. + */ +template +void iterate_with_actions(const S& src, std::vector>& main_trace, M&& func_map, A&& func_all) +{ + size_t src_idx = 0; + size_t dst_idx = 0; + while (src_idx < src.size() && dst_idx < main_trace.size()) { + if (FF(src.at(src_idx).clk) == main_trace.at(dst_idx).main_clk) { + func_map(src_idx, dst_idx); + ++src_idx; + } + ++dst_idx; + } + + for (size_t dst_idx = 0; dst_idx < main_trace.size(); ++dst_idx) { + if (main_trace.at(dst_idx).main_sel_execution_row == 1) { + func_all(dst_idx); + } + } +} + +} // namespace bb::avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.cpp index d5b03da2395..8564a7eed2b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.cpp @@ -1,5 +1,8 @@ #include "barretenberg/vm/avm/trace/kernel_trace.hpp" +#include "barretenberg/common/throw_or_abort.hpp" +#include "barretenberg/vm/avm/generated/full_row.hpp" #include "barretenberg/vm/avm/trace/common.hpp" +#include "barretenberg/vm/avm/trace/finalization.hpp" #include "barretenberg/vm/avm/trace/trace.hpp" #include "barretenberg/vm/constants.hpp" @@ -11,21 +14,13 @@ namespace bb::avm_trace { -AvmKernelTraceBuilder::AvmKernelTraceBuilder(VmPublicInputs public_inputs) - : public_inputs(std::move(public_inputs)) -{} - void AvmKernelTraceBuilder::reset() { + kernel_trace.clear(); kernel_input_selector_counter.clear(); kernel_output_selector_counter.clear(); } -std::vector AvmKernelTraceBuilder::finalize() -{ - return std::move(kernel_trace); -} - FF AvmKernelTraceBuilder::perform_kernel_input_lookup(uint32_t selector) { FF result = std::get<0>(public_inputs)[selector]; @@ -49,62 +44,123 @@ void AvmKernelTraceBuilder::perform_kernel_output_lookup(uint32_t write_offset, // We want to be able to get the return value from the public inputs column // Get the return value, this will be places in ia // We read from the public inputs that were provided to the kernel -FF AvmKernelTraceBuilder::op_address() +FF AvmKernelTraceBuilder::op_address(uint32_t clk) { + KernelTraceEntry entry = { + .clk = clk, + .operation = KernelTraceOpType::ADDRESS, + }; + kernel_trace.push_back(entry); return perform_kernel_input_lookup(ADDRESS_SELECTOR); } -FF AvmKernelTraceBuilder::op_storage_address() + +FF AvmKernelTraceBuilder::op_storage_address(uint32_t clk) { + KernelTraceEntry entry = { + .clk = clk, + .operation = KernelTraceOpType::STORAGE_ADDRESS, + }; + kernel_trace.push_back(entry); return perform_kernel_input_lookup(STORAGE_ADDRESS_SELECTOR); } -FF AvmKernelTraceBuilder::op_sender() +FF AvmKernelTraceBuilder::op_sender(uint32_t clk) { + KernelTraceEntry entry = { + .clk = clk, + .operation = KernelTraceOpType::SENDER, + }; + kernel_trace.push_back(entry); return perform_kernel_input_lookup(SENDER_SELECTOR); } -FF AvmKernelTraceBuilder::op_function_selector() +FF AvmKernelTraceBuilder::op_function_selector(uint32_t clk) { + KernelTraceEntry entry = { + .clk = clk, + .operation = KernelTraceOpType::FUNCTION_SELECTOR, + }; + kernel_trace.push_back(entry); return perform_kernel_input_lookup(FUNCTION_SELECTOR_SELECTOR); } -FF AvmKernelTraceBuilder::op_transaction_fee() +FF AvmKernelTraceBuilder::op_transaction_fee(uint32_t clk) { + KernelTraceEntry entry = { + .clk = clk, + .operation = KernelTraceOpType::TRANSACTION_FEE, + }; + kernel_trace.push_back(entry); return perform_kernel_input_lookup(TRANSACTION_FEE_SELECTOR); } -FF AvmKernelTraceBuilder::op_chain_id() +FF AvmKernelTraceBuilder::op_chain_id(uint32_t clk) { + KernelTraceEntry entry = { + .clk = clk, + .operation = KernelTraceOpType::CHAIN_ID, + }; + kernel_trace.push_back(entry); return perform_kernel_input_lookup(CHAIN_ID_SELECTOR); } -FF AvmKernelTraceBuilder::op_version() +FF AvmKernelTraceBuilder::op_version(uint32_t clk) { + KernelTraceEntry entry = { + .clk = clk, + .operation = KernelTraceOpType::VERSION, + }; + kernel_trace.push_back(entry); return perform_kernel_input_lookup(VERSION_SELECTOR); } -FF AvmKernelTraceBuilder::op_block_number() +FF AvmKernelTraceBuilder::op_block_number(uint32_t clk) { + KernelTraceEntry entry = { + .clk = clk, + .operation = KernelTraceOpType::BLOCK_NUMBER, + }; + kernel_trace.push_back(entry); return perform_kernel_input_lookup(BLOCK_NUMBER_SELECTOR); } -FF AvmKernelTraceBuilder::op_coinbase() +FF AvmKernelTraceBuilder::op_coinbase(uint32_t clk) { + KernelTraceEntry entry = { + .clk = clk, + .operation = KernelTraceOpType::COINBASE, + }; + kernel_trace.push_back(entry); return perform_kernel_input_lookup(COINBASE_SELECTOR); } -FF AvmKernelTraceBuilder::op_timestamp() +FF AvmKernelTraceBuilder::op_timestamp(uint32_t clk) { + KernelTraceEntry entry = { + .clk = clk, + .operation = KernelTraceOpType::TIMESTAMP, + }; + kernel_trace.push_back(entry); return perform_kernel_input_lookup(TIMESTAMP_SELECTOR); } -FF AvmKernelTraceBuilder::op_fee_per_da_gas() +FF AvmKernelTraceBuilder::op_fee_per_da_gas(uint32_t clk) { + KernelTraceEntry entry = { + .clk = clk, + .operation = KernelTraceOpType::FEE_PER_DA_GAS, + }; + kernel_trace.push_back(entry); return perform_kernel_input_lookup(FEE_PER_DA_GAS_SELECTOR); } -FF AvmKernelTraceBuilder::op_fee_per_l2_gas() +FF AvmKernelTraceBuilder::op_fee_per_l2_gas(uint32_t clk) { + KernelTraceEntry entry = { + .clk = clk, + .operation = KernelTraceOpType::FEE_PER_L2_GAS, + }; + kernel_trace.push_back(entry); return perform_kernel_input_lookup(FEE_PER_L2_GAS_SELECTOR); } @@ -123,8 +179,7 @@ void AvmKernelTraceBuilder::op_note_hash_exists(uint32_t clk, KernelTraceEntry entry = { .clk = clk, .kernel_out_offset = offset, - .q_kernel_output_lookup = true, - .op_note_hash_exists = true, + .operation = KernelTraceOpType::NOTE_HASH_EXISTS, }; kernel_trace.push_back(entry); } @@ -138,8 +193,7 @@ void AvmKernelTraceBuilder::op_emit_note_hash(uint32_t clk, uint32_t side_effect KernelTraceEntry entry = { .clk = clk, .kernel_out_offset = offset, - .q_kernel_output_lookup = true, - .op_emit_note_hash = true, + .operation = KernelTraceOpType::EMIT_NOTE_HASH, }; kernel_trace.push_back(entry); } @@ -164,8 +218,7 @@ void AvmKernelTraceBuilder::op_nullifier_exists(uint32_t clk, KernelTraceEntry entry = { .clk = clk, .kernel_out_offset = offset, - .q_kernel_output_lookup = true, - .op_nullifier_exists = true, + .operation = KernelTraceOpType::NULLIFIER_EXISTS, }; kernel_trace.push_back(entry); } @@ -179,8 +232,7 @@ void AvmKernelTraceBuilder::op_emit_nullifier(uint32_t clk, uint32_t side_effect KernelTraceEntry entry = { .clk = clk, .kernel_out_offset = offset, - .q_kernel_output_lookup = true, - .op_emit_nullifier = true, + .operation = KernelTraceOpType::EMIT_NULLIFIER, }; kernel_trace.push_back(entry); } @@ -199,8 +251,7 @@ void AvmKernelTraceBuilder::op_l1_to_l2_msg_exists(uint32_t clk, KernelTraceEntry entry = { .clk = clk, .kernel_out_offset = offset, - .q_kernel_output_lookup = true, - .op_l1_to_l2_msg_exists = true, + .operation = KernelTraceOpType::L1_TO_L2_MSG_EXISTS, }; kernel_trace.push_back(entry); } @@ -214,8 +265,7 @@ void AvmKernelTraceBuilder::op_emit_unencrypted_log(uint32_t clk, uint32_t side_ KernelTraceEntry entry = { .clk = clk, .kernel_out_offset = offset, - .q_kernel_output_lookup = true, - .op_emit_unencrypted_log = true, + .operation = KernelTraceOpType::EMIT_UNENCRYPTED_LOG, }; kernel_trace.push_back(entry); } @@ -232,8 +282,7 @@ void AvmKernelTraceBuilder::op_emit_l2_to_l1_msg(uint32_t clk, KernelTraceEntry entry = { .clk = clk, .kernel_out_offset = offset, - .q_kernel_output_lookup = true, - .op_emit_l2_to_l1_msg = true, + .operation = KernelTraceOpType::EMIT_L2_TO_L1_MSG, }; kernel_trace.push_back(entry); } @@ -247,8 +296,7 @@ void AvmKernelTraceBuilder::op_sload(uint32_t clk, uint32_t side_effect_counter, KernelTraceEntry entry = { .clk = clk, .kernel_out_offset = offset, - .q_kernel_output_lookup = true, - .op_sload = true, + .operation = KernelTraceOpType::SLOAD, }; kernel_trace.push_back(entry); } @@ -262,10 +310,207 @@ void AvmKernelTraceBuilder::op_sstore(uint32_t clk, uint32_t side_effect_counter KernelTraceEntry entry = { .clk = clk, .kernel_out_offset = offset, - .q_kernel_output_lookup = true, - .op_sstore = true, + .operation = KernelTraceOpType::SSTORE, }; kernel_trace.push_back(entry); } +void AvmKernelTraceBuilder::finalize(std::vector>& main_trace) +{ + // Write the kernel trace into the main trace + // 1. The write offsets are constrained to be non changing over the entire trace, so we fill in the values + // until we hit an operation that changes one of the write_offsets (a relevant opcode) + // 2. Upon hitting the clk of each kernel operation we copy the values into the main trace + // 3. When an increment is required, we increment the value in the next row, then continue the process until + // the end + // 4. Whenever we hit the last row, we zero all write_offsets such that the shift relation will succeed + + // Index 0 corresponds here to the first active row of the main execution trace. + // Initialization of side_effect_counter occurs occurs on this row. + main_trace.at(0).main_side_effect_counter = initial_side_effect_counter; + + // This index is required to retrieve the right side effect counter after an external call. + size_t external_call_cnt = 0; + + iterate_with_actions( + kernel_trace, + main_trace, + // Action to be performed on each kernel trace entry + // and its corresponding row in the main trace (clk match) + [&](size_t src_idx, size_t dst_idx) { + const auto& src = kernel_trace.at(src_idx); + auto& dest = main_trace.at(dst_idx); + + switch (src.operation) { + // IN + case KernelTraceOpType::ADDRESS: + dest.main_kernel_in_offset = ADDRESS_SELECTOR; + dest.main_sel_q_kernel_lookup = 1; + break; + case KernelTraceOpType::STORAGE_ADDRESS: + dest.main_kernel_in_offset = STORAGE_ADDRESS_SELECTOR; + dest.main_sel_q_kernel_lookup = 1; + break; + case KernelTraceOpType::SENDER: + dest.main_kernel_in_offset = SENDER_SELECTOR; + dest.main_sel_q_kernel_lookup = 1; + break; + case KernelTraceOpType::FUNCTION_SELECTOR: + dest.main_kernel_in_offset = FUNCTION_SELECTOR_SELECTOR; + dest.main_sel_q_kernel_lookup = 1; + break; + case KernelTraceOpType::TRANSACTION_FEE: + dest.main_kernel_in_offset = TRANSACTION_FEE_SELECTOR; + dest.main_sel_q_kernel_lookup = 1; + break; + case KernelTraceOpType::CHAIN_ID: + dest.main_kernel_in_offset = CHAIN_ID_SELECTOR; + dest.main_sel_q_kernel_lookup = 1; + break; + case KernelTraceOpType::VERSION: + dest.main_kernel_in_offset = VERSION_SELECTOR; + dest.main_sel_q_kernel_lookup = 1; + break; + case KernelTraceOpType::BLOCK_NUMBER: + dest.main_kernel_in_offset = BLOCK_NUMBER_SELECTOR; + dest.main_sel_q_kernel_lookup = 1; + break; + case KernelTraceOpType::COINBASE: + dest.main_kernel_in_offset = COINBASE_SELECTOR; + dest.main_sel_q_kernel_lookup = 1; + break; + case KernelTraceOpType::TIMESTAMP: + dest.main_kernel_in_offset = TIMESTAMP_SELECTOR; + dest.main_sel_q_kernel_lookup = 1; + break; + case KernelTraceOpType::FEE_PER_DA_GAS: + dest.main_kernel_in_offset = FEE_PER_DA_GAS_SELECTOR; + dest.main_sel_q_kernel_lookup = 1; + break; + case KernelTraceOpType::FEE_PER_L2_GAS: + dest.main_kernel_in_offset = FEE_PER_L2_GAS_SELECTOR; + dest.main_sel_q_kernel_lookup = 1; + break; + // OUT + case KernelTraceOpType::NOTE_HASH_EXISTS: + dest.main_kernel_out_offset = src.kernel_out_offset; + dest.main_sel_q_kernel_output_lookup = 1; + break; + case KernelTraceOpType::EMIT_NOTE_HASH: + dest.main_kernel_out_offset = src.kernel_out_offset; + dest.main_sel_q_kernel_output_lookup = 1; + break; + case KernelTraceOpType::NULLIFIER_EXISTS: + dest.main_kernel_out_offset = src.kernel_out_offset; + dest.main_sel_q_kernel_output_lookup = 1; + break; + case KernelTraceOpType::EMIT_NULLIFIER: + dest.main_kernel_out_offset = src.kernel_out_offset; + dest.main_sel_q_kernel_output_lookup = 1; + break; + case KernelTraceOpType::L1_TO_L2_MSG_EXISTS: + dest.main_kernel_out_offset = src.kernel_out_offset; + dest.main_sel_q_kernel_output_lookup = 1; + break; + case KernelTraceOpType::EMIT_UNENCRYPTED_LOG: + dest.main_kernel_out_offset = src.kernel_out_offset; + dest.main_sel_q_kernel_output_lookup = 1; + break; + case KernelTraceOpType::EMIT_L2_TO_L1_MSG: + dest.main_kernel_out_offset = src.kernel_out_offset; + dest.main_sel_q_kernel_output_lookup = 1; + break; + case KernelTraceOpType::SLOAD: + dest.main_kernel_out_offset = src.kernel_out_offset; + dest.main_sel_q_kernel_output_lookup = 1; + break; + case KernelTraceOpType::SSTORE: + dest.main_kernel_out_offset = src.kernel_out_offset; + dest.main_sel_q_kernel_output_lookup = 1; + break; + default: + throw_or_abort("Invalid operation selector"); + } + }, + // Action to be performed on every execution trace row. + [&](size_t dst_idx) { + const auto& curr = main_trace.at(dst_idx); + auto& next = main_trace.at(dst_idx + 1); + + next.main_note_hash_exist_write_offset = + curr.main_note_hash_exist_write_offset + curr.main_sel_op_note_hash_exists; + next.main_emit_note_hash_write_offset = + curr.main_emit_note_hash_write_offset + curr.main_sel_op_emit_note_hash; + next.main_emit_nullifier_write_offset = + curr.main_emit_nullifier_write_offset + curr.main_sel_op_emit_nullifier; + next.main_nullifier_exists_write_offset = + curr.main_nullifier_exists_write_offset + (curr.main_sel_op_nullifier_exists * curr.main_ib); + next.main_nullifier_non_exists_write_offset = curr.main_nullifier_non_exists_write_offset + + (curr.main_sel_op_nullifier_exists * (FF(1) - curr.main_ib)); + next.main_l1_to_l2_msg_exists_write_offset = + curr.main_l1_to_l2_msg_exists_write_offset + curr.main_sel_op_l1_to_l2_msg_exists; + next.main_emit_l2_to_l1_msg_write_offset = + curr.main_emit_l2_to_l1_msg_write_offset + curr.main_sel_op_emit_l2_to_l1_msg; + next.main_emit_unencrypted_log_write_offset = + curr.main_emit_unencrypted_log_write_offset + curr.main_sel_op_emit_unencrypted_log; + next.main_sload_write_offset = curr.main_sload_write_offset + curr.main_sel_op_sload; + next.main_sstore_write_offset = curr.main_sstore_write_offset + curr.main_sel_op_sstore; + + // Adjust side effect counter after an external call + if (curr.main_sel_op_external_call == 1) { + next.main_side_effect_counter = hints.externalcall_hints.at(external_call_cnt).end_side_effect_counter; + external_call_cnt++; + } else { + // The side effect counter will increment regardless of the offset value + // (as long as the operation is an OUTPUT operation). + next.main_side_effect_counter = curr.main_side_effect_counter + curr.main_sel_q_kernel_output_lookup; + } + }); +} + +// Public Input Columns Inclusion ("fixed" part of the trace). +// Crucial to add these columns after the extra row was added. +void AvmKernelTraceBuilder::finalize_columns(std::vector>& main_trace) const +{ + // Copy the kernel input public inputs + for (size_t i = 0; i < KERNEL_INPUTS_LENGTH; i++) { + auto& dest = main_trace.at(i); + dest.main_kernel_inputs = std::get(public_inputs).at(i); + dest.main_sel_kernel_inputs = FF(1); + } + + // Copy the kernel outputs counts into the main trace + for (size_t i = 0; i < KERNEL_OUTPUTS_LENGTH; i++) { + auto& dest = main_trace.at(i); + dest.main_kernel_value_out = std::get(public_inputs).at(i); + dest.main_kernel_side_effect_out = std::get(public_inputs).at(i); + dest.main_kernel_metadata_out = std::get(public_inputs).at(i); + dest.main_sel_kernel_out = FF(1); + } + + // Write lookup counts for inputs + for (auto const& [selector, count] : kernel_input_selector_counter) { + main_trace.at(selector).lookup_into_kernel_counts = FF(count); + } + // for (uint32_t i = 0; i < KERNEL_INPUTS_LENGTH; i++) { + // auto value = kernel_input_selector_counter.find(i); + // if (value != kernel_input_selector_counter.end()) { + // auto& dest = main_trace.at(i); + // dest.lookup_into_kernel_counts = FF(value->second); + // } + // } + + // Write lookup counts for outputs + for (auto const& [selector, count] : kernel_output_selector_counter) { + main_trace.at(selector).kernel_output_lookup_counts = FF(count); + } + // for (uint32_t i = 0; i < KERNEL_OUTPUTS_LENGTH; i++) { + // auto value = kernel_output_selector_counter.find(i); + // if (value != kernel_output_selector_counter.end()) { + // auto& dest = main_trace.at(i); + // dest.kernel_output_lookup_counts = FF(value->second); + // } + // } +} + } // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.hpp index e5a4b747744..773d68bba3f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.hpp @@ -2,6 +2,7 @@ #include "barretenberg/numeric/uint128/uint128.hpp" #include "barretenberg/vm/avm/trace/common.hpp" +#include "barretenberg/vm/avm/trace/execution_hints.hpp" #include "barretenberg/vm/constants.hpp" @@ -13,28 +14,42 @@ namespace bb::avm_trace { class AvmKernelTraceBuilder { public: + enum class KernelTraceOpType { + // IN + ADDRESS, + STORAGE_ADDRESS, + SENDER, + FUNCTION_SELECTOR, + TRANSACTION_FEE, + CHAIN_ID, + VERSION, + BLOCK_NUMBER, + COINBASE, + TIMESTAMP, + FEE_PER_DA_GAS, + FEE_PER_L2_GAS, + // OUT + SLOAD, + SSTORE, + NOTE_HASH_EXISTS, + EMIT_NOTE_HASH, + NULLIFIER_EXISTS, + EMIT_NULLIFIER, + L1_TO_L2_MSG_EXISTS, + EMIT_UNENCRYPTED_LOG, + EMIT_L2_TO_L1_MSG + }; + + // While the kernel trace is expected to be 1-1 with the main trace, + // we store it in "compressed form". That is, only actual operations are stored. + // Then, in finalize things are padded for in between clks. struct KernelTraceEntry { - // Clk - to join black onto the main trace uint32_t clk = 0; - uint32_t kernel_in_offset = 0; uint32_t kernel_out_offset = 0; - bool q_kernel_lookup = false; - bool q_kernel_output_lookup = false; - // In finalise, the main trace writes the correct write_offset for each operation based appearing selectors - bool op_note_hash_exists = false; - bool op_emit_note_hash = false; - bool op_nullifier_exists = false; - bool op_emit_nullifier = false; - bool op_l1_to_l2_msg_exists = false; - bool op_emit_unencrypted_log = false; - bool op_emit_l2_to_l1_msg = false; - bool op_sload = false; - bool op_sstore = false; + KernelTraceOpType operation; }; - VmPublicInputs public_inputs; - // Counts the number of accesses into each SELECTOR for the environment selector lookups; std::unordered_map kernel_input_selector_counter; @@ -42,28 +57,32 @@ class AvmKernelTraceBuilder { // optimise this to just hardcode the counter to be the same as the lookup selector value!!! std::unordered_map kernel_output_selector_counter; - // Constructor receives copy of kernel_inputs from the main trace builder - AvmKernelTraceBuilder(VmPublicInputs public_inputs); + AvmKernelTraceBuilder(uint32_t initial_side_effect_counter, VmPublicInputs public_inputs, ExecutionHints hints) + : initial_side_effect_counter(initial_side_effect_counter) + , public_inputs(std::move(public_inputs)) + , hints(std::move(hints)) + {} void reset(); - std::vector finalize(); + void finalize(std::vector>& main_trace); + void finalize_columns(std::vector>& main_trace) const; // Context - FF op_address(); - FF op_storage_address(); - FF op_sender(); - FF op_function_selector(); - FF op_transaction_fee(); + FF op_address(uint32_t clk); + FF op_storage_address(uint32_t clk); + FF op_sender(uint32_t clk); + FF op_function_selector(uint32_t clk); + FF op_transaction_fee(uint32_t clk); // Globals - FF op_chain_id(); - FF op_version(); - FF op_block_number(); - FF op_coinbase(); - FF op_timestamp(); + FF op_chain_id(uint32_t clk); + FF op_version(uint32_t clk); + FF op_block_number(uint32_t clk); + FF op_coinbase(uint32_t clk); + FF op_timestamp(uint32_t clk); // Globals - Gas - FF op_fee_per_da_gas(); - FF op_fee_per_l2_gas(); + FF op_fee_per_da_gas(uint32_t clk); + FF op_fee_per_l2_gas(uint32_t clk); // Outputs // Each returns the selector that was used @@ -80,6 +99,10 @@ class AvmKernelTraceBuilder { private: std::vector kernel_trace; + uint32_t initial_side_effect_counter; + VmPublicInputs public_inputs; + ExecutionHints hints; + // Output index counters uint32_t note_hash_exists_offset = 0; uint32_t emit_note_hash_offset = 0; @@ -89,7 +112,6 @@ class AvmKernelTraceBuilder { uint32_t l1_to_l2_msg_exists_offset = 0; uint32_t emit_unencrypted_log_offset = 0; uint32_t emit_l2_to_l1_msg_offset = 0; - uint32_t sload_write_offset = 0; uint32_t sstore_write_offset = 0; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/mem_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/mem_trace.cpp index c9f0731757e..cbe1ef4890b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/mem_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/mem_trace.cpp @@ -6,15 +6,6 @@ namespace bb::avm_trace { -/** - * @brief Constructor of a memory trace builder of AVM. Only serves to set the capacity of the - * underlying traces. - */ -AvmMemTraceBuilder::AvmMemTraceBuilder() -{ - mem_trace.reserve(AVM_TRACE_SIZE); -} - /** * @brief Resetting the internal state so that a new memory trace can be rebuilt using the same object. * diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/mem_trace.hpp index 0bdd8cc9ed4..56835aa77f5 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/mem_trace.hpp @@ -73,7 +73,7 @@ class AvmMemTraceBuilder { POSEIDON2, }; - AvmMemTraceBuilder(); + AvmMemTraceBuilder() = default; void reset(); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp index 680a61995d8..a1bcdb2b3c1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp @@ -286,23 +286,19 @@ void AvmTraceBuilder::finalise_mem_trace_lookup_counts() * underlying traces and initialize gas values. */ AvmTraceBuilder::AvmTraceBuilder(VmPublicInputs public_inputs, - ExecutionHints execution_hints, + ExecutionHints execution_hints_, uint32_t side_effect_counter, std::vector calldata) // NOTE: we initialise the environment builder here as it requires public inputs - : kernel_trace_builder(std::move(public_inputs)) - , calldata(std::move(calldata)) + : calldata(std::move(calldata)) , side_effect_counter(side_effect_counter) - , initial_side_effect_counter(side_effect_counter) - , execution_hints(std::move(execution_hints)) + , execution_hints(std::move(execution_hints_)) + , kernel_trace_builder(side_effect_counter, public_inputs, execution_hints) { - main_trace.reserve(AVM_TRACE_SIZE); - // TODO: think about cast - gas_trace_builder.set_initial_gas(static_cast(std::get( - kernel_trace_builder.public_inputs)[L2_GAS_LEFT_CONTEXT_INPUTS_OFFSET]), - static_cast(std::get( - kernel_trace_builder.public_inputs)[DA_GAS_LEFT_CONTEXT_INPUTS_OFFSET])); + gas_trace_builder.set_initial_gas( + static_cast(std::get(public_inputs)[L2_GAS_LEFT_CONTEXT_INPUTS_OFFSET]), + static_cast(std::get(public_inputs)[DA_GAS_LEFT_CONTEXT_INPUTS_OFFSET])); } /************************************************************************************************** @@ -1259,8 +1255,7 @@ void AvmTraceBuilder::op_cast(uint8_t indirect, uint32_t a_offset, uint32_t dst_ * @param w_tag - The memory tag of the value read * @return Row */ -Row AvmTraceBuilder::create_kernel_lookup_opcode( - uint8_t indirect, uint32_t dst_offset, uint32_t selector, FF value, AvmMemoryTag w_tag) +Row AvmTraceBuilder::create_kernel_lookup_opcode(uint8_t indirect, uint32_t dst_offset, FF value, AvmMemoryTag w_tag) { auto const clk = static_cast(main_trace.size()) + 1; @@ -1270,7 +1265,6 @@ Row AvmTraceBuilder::create_kernel_lookup_opcode( return Row{ .main_clk = clk, - .kernel_kernel_in_offset = selector, .main_call_ptr = call_ptr, .main_ia = value, .main_ind_addr_a = FF(write_dst.indirect_address), @@ -1279,7 +1273,6 @@ Row AvmTraceBuilder::create_kernel_lookup_opcode( .main_pc = pc++, .main_rwa = 1, .main_sel_mem_op_a = 1, - .main_sel_q_kernel_lookup = 1, .main_sel_resolve_ind_addr_a = FF(static_cast(write_dst.is_indirect)), .main_tag_err = FF(static_cast(!write_dst.tag_match)), .main_w_in_tag = static_cast(w_tag), @@ -1288,8 +1281,9 @@ Row AvmTraceBuilder::create_kernel_lookup_opcode( void AvmTraceBuilder::op_address(uint8_t indirect, uint32_t dst_offset) { - FF ia_value = kernel_trace_builder.op_address(); - Row row = create_kernel_lookup_opcode(indirect, dst_offset, ADDRESS_SELECTOR, ia_value, AvmMemoryTag::FF); + auto const clk = static_cast(main_trace.size()) + 1; + FF ia_value = kernel_trace_builder.op_address(clk); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::FF); row.main_sel_op_address = FF(1); // Constrain gas cost @@ -1300,8 +1294,9 @@ void AvmTraceBuilder::op_address(uint8_t indirect, uint32_t dst_offset) void AvmTraceBuilder::op_storage_address(uint8_t indirect, uint32_t dst_offset) { - FF ia_value = kernel_trace_builder.op_storage_address(); - Row row = create_kernel_lookup_opcode(indirect, dst_offset, STORAGE_ADDRESS_SELECTOR, ia_value, AvmMemoryTag::FF); + auto const clk = static_cast(main_trace.size()) + 1; + FF ia_value = kernel_trace_builder.op_storage_address(clk); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::FF); row.main_sel_op_storage_address = FF(1); // Constrain gas cost @@ -1312,8 +1307,9 @@ void AvmTraceBuilder::op_storage_address(uint8_t indirect, uint32_t dst_offset) void AvmTraceBuilder::op_sender(uint8_t indirect, uint32_t dst_offset) { - FF ia_value = kernel_trace_builder.op_sender(); - Row row = create_kernel_lookup_opcode(indirect, dst_offset, SENDER_SELECTOR, ia_value, AvmMemoryTag::FF); + auto const clk = static_cast(main_trace.size()) + 1; + FF ia_value = kernel_trace_builder.op_sender(clk); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::FF); row.main_sel_op_sender = FF(1); // Constrain gas cost @@ -1324,9 +1320,9 @@ void AvmTraceBuilder::op_sender(uint8_t indirect, uint32_t dst_offset) void AvmTraceBuilder::op_function_selector(uint8_t indirect, uint32_t dst_offset) { - FF ia_value = kernel_trace_builder.op_function_selector(); - Row row = - create_kernel_lookup_opcode(indirect, dst_offset, FUNCTION_SELECTOR_SELECTOR, ia_value, AvmMemoryTag::U32); + auto const clk = static_cast(main_trace.size()) + 1; + FF ia_value = kernel_trace_builder.op_function_selector(clk); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::U32); row.main_sel_op_function_selector = FF(1); // Constrain gas cost @@ -1337,8 +1333,9 @@ void AvmTraceBuilder::op_function_selector(uint8_t indirect, uint32_t dst_offset void AvmTraceBuilder::op_transaction_fee(uint8_t indirect, uint32_t dst_offset) { - FF ia_value = kernel_trace_builder.op_transaction_fee(); - Row row = create_kernel_lookup_opcode(indirect, dst_offset, TRANSACTION_FEE_SELECTOR, ia_value, AvmMemoryTag::FF); + auto const clk = static_cast(main_trace.size()) + 1; + FF ia_value = kernel_trace_builder.op_transaction_fee(clk); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::FF); row.main_sel_op_transaction_fee = FF(1); // Constrain gas cost @@ -1353,8 +1350,9 @@ void AvmTraceBuilder::op_transaction_fee(uint8_t indirect, uint32_t dst_offset) void AvmTraceBuilder::op_chain_id(uint8_t indirect, uint32_t dst_offset) { - FF ia_value = kernel_trace_builder.op_chain_id(); - Row row = create_kernel_lookup_opcode(indirect, dst_offset, CHAIN_ID_SELECTOR, ia_value, AvmMemoryTag::FF); + auto const clk = static_cast(main_trace.size()) + 1; + FF ia_value = kernel_trace_builder.op_chain_id(clk); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::FF); row.main_sel_op_chain_id = FF(1); // Constrain gas cost @@ -1365,8 +1363,9 @@ void AvmTraceBuilder::op_chain_id(uint8_t indirect, uint32_t dst_offset) void AvmTraceBuilder::op_version(uint8_t indirect, uint32_t dst_offset) { - FF ia_value = kernel_trace_builder.op_version(); - Row row = create_kernel_lookup_opcode(indirect, dst_offset, VERSION_SELECTOR, ia_value, AvmMemoryTag::FF); + auto const clk = static_cast(main_trace.size()) + 1; + FF ia_value = kernel_trace_builder.op_version(clk); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::FF); row.main_sel_op_version = FF(1); // Constrain gas cost @@ -1377,8 +1376,9 @@ void AvmTraceBuilder::op_version(uint8_t indirect, uint32_t dst_offset) void AvmTraceBuilder::op_block_number(uint8_t indirect, uint32_t dst_offset) { - FF ia_value = kernel_trace_builder.op_block_number(); - Row row = create_kernel_lookup_opcode(indirect, dst_offset, BLOCK_NUMBER_SELECTOR, ia_value, AvmMemoryTag::FF); + auto const clk = static_cast(main_trace.size()) + 1; + FF ia_value = kernel_trace_builder.op_block_number(clk); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::FF); row.main_sel_op_block_number = FF(1); // Constrain gas cost @@ -1389,8 +1389,9 @@ void AvmTraceBuilder::op_block_number(uint8_t indirect, uint32_t dst_offset) void AvmTraceBuilder::op_timestamp(uint8_t indirect, uint32_t dst_offset) { - FF ia_value = kernel_trace_builder.op_timestamp(); - Row row = create_kernel_lookup_opcode(indirect, dst_offset, TIMESTAMP_SELECTOR, ia_value, AvmMemoryTag::U64); + auto const clk = static_cast(main_trace.size()) + 1; + FF ia_value = kernel_trace_builder.op_timestamp(clk); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::U64); row.main_sel_op_timestamp = FF(1); // Constrain gas cost @@ -1401,8 +1402,9 @@ void AvmTraceBuilder::op_timestamp(uint8_t indirect, uint32_t dst_offset) void AvmTraceBuilder::op_coinbase(uint8_t indirect, uint32_t dst_offset) { - FF ia_value = kernel_trace_builder.op_coinbase(); - Row row = create_kernel_lookup_opcode(indirect, dst_offset, COINBASE_SELECTOR, ia_value, AvmMemoryTag::FF); + auto const clk = static_cast(main_trace.size()) + 1; + FF ia_value = kernel_trace_builder.op_coinbase(clk); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::FF); row.main_sel_op_coinbase = FF(1); // Constrain gas cost @@ -1413,8 +1415,9 @@ void AvmTraceBuilder::op_coinbase(uint8_t indirect, uint32_t dst_offset) void AvmTraceBuilder::op_fee_per_l2_gas(uint8_t indirect, uint32_t dst_offset) { - FF ia_value = kernel_trace_builder.op_fee_per_l2_gas(); - Row row = create_kernel_lookup_opcode(indirect, dst_offset, FEE_PER_L2_GAS_SELECTOR, ia_value, AvmMemoryTag::FF); + auto const clk = static_cast(main_trace.size()) + 1; + FF ia_value = kernel_trace_builder.op_fee_per_l2_gas(clk); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::FF); row.main_sel_op_fee_per_l2_gas = FF(1); // Constrain gas cost @@ -1425,8 +1428,9 @@ void AvmTraceBuilder::op_fee_per_l2_gas(uint8_t indirect, uint32_t dst_offset) void AvmTraceBuilder::op_fee_per_da_gas(uint8_t indirect, uint32_t dst_offset) { - FF ia_value = kernel_trace_builder.op_fee_per_da_gas(); - Row row = create_kernel_lookup_opcode(indirect, dst_offset, FEE_PER_DA_GAS_SELECTOR, ia_value, AvmMemoryTag::FF); + auto const clk = static_cast(main_trace.size()) + 1; + FF ia_value = kernel_trace_builder.op_fee_per_da_gas(clk); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::FF); row.main_sel_op_fee_per_da_gas = FF(1); // Constrain gas cost @@ -2005,7 +2009,6 @@ Row AvmTraceBuilder::create_kernel_output_opcode(uint8_t indirect, uint32_t clk, .main_r_in_tag = static_cast(AvmMemoryTag::FF), .main_rwa = 0, .main_sel_mem_op_a = 1, - .main_sel_q_kernel_output_lookup = 1, .main_sel_resolve_ind_addr_a = FF(static_cast(read_a.is_indirect)), .main_tag_err = FF(static_cast(!tag_match)), }; @@ -2054,7 +2057,6 @@ Row AvmTraceBuilder::create_kernel_output_opcode_with_metadata(uint8_t indirect, .main_rwb = 0, .main_sel_mem_op_a = 1, .main_sel_mem_op_b = 1, - .main_sel_q_kernel_output_lookup = 1, .main_sel_resolve_ind_addr_a = FF(static_cast(read_a.is_indirect)), .main_sel_resolve_ind_addr_b = FF(static_cast(read_b.is_indirect)), .main_tag_err = FF(static_cast(!tag_match)), @@ -2218,7 +2220,6 @@ void AvmTraceBuilder::op_sload(uint8_t indirect, uint32_t slot_offset, uint32_t .main_rwa = 1, .main_sel_mem_op_a = 1, .main_sel_op_sload = FF(1), - .main_sel_q_kernel_output_lookup = 1, .main_sel_resolve_ind_addr_a = FF(static_cast(write_a.is_indirect)), .main_tag_err = FF(static_cast(!write_a.tag_match)), .main_w_in_tag = static_cast(AvmMemoryTag::FF), @@ -3440,7 +3441,7 @@ std::vector AvmTraceBuilder::finalize(bool range_check_required) // Range check size is 1 less than it needs to be since we insert a "first row" at the top of the trace at the // end, with clk 0 (this doubles as our range check) size_t const range_check_size = range_check_required ? UINT16_MAX : 0; - std::vector trace_sizes = { mem_trace_size, main_trace_size, alu_trace_size, + std::vector trace_sizes = { mem_trace_size, main_trace_size + 1, alu_trace_size, range_check_size, conv_trace_size, sha256_trace_size, poseidon2_trace_size, pedersen_trace_size, gas_trace_size + 1, KERNEL_INPUTS_LENGTH, KERNEL_OUTPUTS_LENGTH, fixed_gas_table.size(), @@ -3476,14 +3477,14 @@ std::vector AvmTraceBuilder::finalize(bool range_check_required) for (size_t i = 0; i < main_trace_size; i++) { main_trace[i].main_sel_execution_row = FF(1); } + // This selector corresponds to the last row of the EXECUTION trace. + main_trace.back().main_sel_last = FF(1); - // We only need to pad with zeroes to the size to the largest trace here, pow_2 padding is handled in the - // subgroup_size check in bb + // We only need to pad with zeroes to the size to the largest trace here, + // pow_2 padding is handled in the subgroup_size check in BB. // Resize the main_trace to accomodate a potential lookup, filling with default empty rows. main_trace_size = *trace_size; - main_trace.resize(*trace_size, {}); - - main_trace.at(*trace_size - 1).main_sel_last = FF(1); + main_trace.resize(*trace_size); /********************************************************************************************** * MEMORY TRACE INCLUSION @@ -3832,6 +3833,12 @@ std::vector AvmTraceBuilder::finalize(bool range_check_required) gas_trace_builder.finalize(main_trace); const auto& rem_gas_rng_check_counts = gas_trace_builder.rem_gas_rng_check_counts; + /********************************************************************************************** + * KERNEL TRACE INCLUSION + **********************************************************************************************/ + + kernel_trace_builder.finalize(main_trace); + /********************************************************************************************** * ONLY FIXED TABLES FROM HERE ON **********************************************************************************************/ @@ -3951,186 +3958,11 @@ std::vector AvmTraceBuilder::finalize(bool range_check_required) } /********************************************************************************************** - * KERNEL TRACE INCLUSION + * OTHER STUFF **********************************************************************************************/ - // Write the kernel trace into the main trace - // 1. The write offsets are constrained to be non changing over the entire trace, so we fill in the values - // until we - // hit an operation that changes one of the write_offsets (a relevant opcode) - // 2. Upon hitting the clk of each kernel operation we copy the values into the main trace - // 3. When an increment is required, we increment the value in the next row, then continue the process until - // the end - // 4. Whenever we hit the last row, we zero all write_offsets such that the shift relation will succeed - std::vector kernel_trace = kernel_trace_builder.finalize(); - size_t kernel_padding_main_trace_bottom = 1; - - // Index 1 corresponds here to the first active row of the main execution trace, as - // we already prepended the extra row for shifted columns. Therefore, initialization - // of side_effect_counter occurs occurs on this row. - main_trace.at(1).kernel_side_effect_counter = initial_side_effect_counter; - // This index is required to retrieve the right side effect counter after an external call. - size_t external_call_cnt = 0; - - // External loop iterates over the kernel entries which are sorted by increasing clk. - // Internal loop iterates to fill the gap in main trace between each kernel entries. - for (auto const& src : kernel_trace) { - // Check the clock and iterate through the main trace until we hit the clock - auto clk = src.clk; - - // Until the next kernel changing instruction is encountered we set all of the values of the offset - // arrays to be the same as the previous row This satisfies the `offset' - (offset + operation_selector) - // = 0` constraints - for (size_t j = kernel_padding_main_trace_bottom; j < clk; j++) { - auto const& prev = main_trace.at(j); - auto& dest = main_trace.at(j + 1); - - dest.kernel_note_hash_exist_write_offset = prev.kernel_note_hash_exist_write_offset; - dest.kernel_emit_note_hash_write_offset = prev.kernel_emit_note_hash_write_offset; - dest.kernel_nullifier_exists_write_offset = prev.kernel_nullifier_exists_write_offset; - dest.kernel_nullifier_non_exists_write_offset = prev.kernel_nullifier_non_exists_write_offset; - dest.kernel_emit_nullifier_write_offset = prev.kernel_emit_nullifier_write_offset; - dest.kernel_emit_l2_to_l1_msg_write_offset = prev.kernel_emit_l2_to_l1_msg_write_offset; - dest.kernel_emit_unencrypted_log_write_offset = prev.kernel_emit_unencrypted_log_write_offset; - dest.kernel_l1_to_l2_msg_exists_write_offset = prev.kernel_l1_to_l2_msg_exists_write_offset; - dest.kernel_sload_write_offset = prev.kernel_sload_write_offset; - dest.kernel_sstore_write_offset = prev.kernel_sstore_write_offset; - - // Adjust side effect counter after an external call - if (prev.main_sel_op_external_call == 1) { - dest.kernel_side_effect_counter = - execution_hints.externalcall_hints.at(external_call_cnt).end_side_effect_counter; - external_call_cnt++; - } else { - dest.kernel_side_effect_counter = prev.kernel_side_effect_counter; - } - } - - Row& curr = main_trace.at(clk); - - // Read in values from kernel trace - // Lookup values - curr.kernel_kernel_in_offset = src.kernel_in_offset; - curr.kernel_kernel_out_offset = src.kernel_out_offset; - curr.main_sel_q_kernel_lookup = static_cast(src.q_kernel_lookup); - curr.main_sel_q_kernel_output_lookup = static_cast(src.q_kernel_output_lookup); - - // Operation selectors - curr.main_sel_op_note_hash_exists = static_cast(src.op_note_hash_exists); - curr.main_sel_op_emit_note_hash = static_cast(src.op_emit_note_hash); - curr.main_sel_op_nullifier_exists = static_cast(src.op_nullifier_exists); - curr.main_sel_op_emit_nullifier = static_cast(src.op_emit_nullifier); - curr.main_sel_op_l1_to_l2_msg_exists = static_cast(src.op_l1_to_l2_msg_exists); - curr.main_sel_op_emit_unencrypted_log = static_cast(src.op_emit_unencrypted_log); - curr.main_sel_op_emit_l2_to_l1_msg = static_cast(src.op_emit_l2_to_l1_msg); - curr.main_sel_op_sload = static_cast(src.op_sload); - curr.main_sel_op_sstore = static_cast(src.op_sstore); - - if (clk < old_trace_size) { - Row& next = main_trace.at(clk + 1); - - // Increment the write offset counter for the following row - next.kernel_note_hash_exist_write_offset = - curr.kernel_note_hash_exist_write_offset + static_cast(src.op_note_hash_exists); - next.kernel_emit_note_hash_write_offset = - curr.kernel_emit_note_hash_write_offset + static_cast(src.op_emit_note_hash); - next.kernel_emit_nullifier_write_offset = - curr.kernel_emit_nullifier_write_offset + static_cast(src.op_emit_nullifier); - next.kernel_nullifier_exists_write_offset = - curr.kernel_nullifier_exists_write_offset + (static_cast(src.op_nullifier_exists) * curr.main_ib); - next.kernel_nullifier_non_exists_write_offset = - curr.kernel_nullifier_non_exists_write_offset + - (static_cast(src.op_nullifier_exists) * (FF(1) - curr.main_ib)); - next.kernel_l1_to_l2_msg_exists_write_offset = - curr.kernel_l1_to_l2_msg_exists_write_offset + static_cast(src.op_l1_to_l2_msg_exists); - next.kernel_emit_l2_to_l1_msg_write_offset = - curr.kernel_emit_l2_to_l1_msg_write_offset + static_cast(src.op_emit_l2_to_l1_msg); - next.kernel_emit_unencrypted_log_write_offset = - curr.kernel_emit_unencrypted_log_write_offset + static_cast(src.op_emit_unencrypted_log); - next.kernel_sload_write_offset = curr.kernel_sload_write_offset + static_cast(src.op_sload); - next.kernel_sstore_write_offset = curr.kernel_sstore_write_offset + static_cast(src.op_sstore); - - // The side effect counter will increment regardless of the offset value - next.kernel_side_effect_counter = curr.kernel_side_effect_counter + 1; - } - - kernel_padding_main_trace_bottom = clk + 1; - } - - // Pad out the main trace from the bottom of the main trace until the end - for (size_t i = kernel_padding_main_trace_bottom + 1; i < old_trace_size; ++i) { - - Row const& prev = main_trace.at(i - 1); - Row& dest = main_trace.at(i); - - // Setting all of the counters to 0 after the IS_LAST check so we can satisfy the constraints until the - // end - if (i == old_trace_size) { - dest.kernel_note_hash_exist_write_offset = 0; - dest.kernel_emit_note_hash_write_offset = 0; - dest.kernel_nullifier_exists_write_offset = 0; - dest.kernel_nullifier_non_exists_write_offset = 0; - dest.kernel_emit_nullifier_write_offset = 0; - dest.kernel_l1_to_l2_msg_exists_write_offset = 0; - dest.kernel_emit_unencrypted_log_write_offset = 0; - dest.kernel_emit_l2_to_l1_msg_write_offset = 0; - dest.kernel_sload_write_offset = 0; - dest.kernel_sstore_write_offset = 0; - dest.kernel_side_effect_counter = 0; - } else { - dest.kernel_note_hash_exist_write_offset = prev.kernel_note_hash_exist_write_offset; - dest.kernel_emit_note_hash_write_offset = prev.kernel_emit_note_hash_write_offset; - dest.kernel_nullifier_exists_write_offset = prev.kernel_nullifier_exists_write_offset; - dest.kernel_nullifier_non_exists_write_offset = prev.kernel_nullifier_non_exists_write_offset; - dest.kernel_emit_nullifier_write_offset = prev.kernel_emit_nullifier_write_offset; - dest.kernel_l1_to_l2_msg_exists_write_offset = prev.kernel_l1_to_l2_msg_exists_write_offset; - dest.kernel_emit_unencrypted_log_write_offset = prev.kernel_emit_unencrypted_log_write_offset; - dest.kernel_emit_l2_to_l1_msg_write_offset = prev.kernel_emit_l2_to_l1_msg_write_offset; - dest.kernel_sload_write_offset = prev.kernel_sload_write_offset; - dest.kernel_sstore_write_offset = prev.kernel_sstore_write_offset; - dest.kernel_side_effect_counter = prev.kernel_side_effect_counter; - } - } - - // Public Input Columns Inclusion - // Crucial to add these columns after the extra row was added. - - // Write lookup counts for inputs - for (uint32_t i = 0; i < KERNEL_INPUTS_LENGTH; i++) { - auto value = kernel_trace_builder.kernel_input_selector_counter.find(i); - if (value != kernel_trace_builder.kernel_input_selector_counter.end()) { - auto& dest = main_trace.at(i); - dest.lookup_into_kernel_counts = FF(value->second); - dest.kernel_q_public_input_kernel_add_to_table = FF(1); - } - } - - // Copy the kernel input public inputs - for (size_t i = 0; i < KERNEL_INPUTS_LENGTH; i++) { - main_trace.at(i).kernel_kernel_inputs = std::get(kernel_trace_builder.public_inputs).at(i); - } - - // Write lookup counts for outputs - for (uint32_t i = 0; i < KERNEL_OUTPUTS_LENGTH; i++) { - auto value = kernel_trace_builder.kernel_output_selector_counter.find(i); - if (value != kernel_trace_builder.kernel_output_selector_counter.end()) { - auto& dest = main_trace.at(i); - dest.kernel_output_lookup_counts = FF(value->second); - dest.kernel_q_public_input_kernel_out_add_to_table = FF(1); - } - } - - // Copy the kernel outputs counts into the main trace - for (size_t i = 0; i < KERNEL_OUTPUTS_LENGTH; i++) { - main_trace.at(i).kernel_kernel_value_out = - std::get(kernel_trace_builder.public_inputs).at(i); - - main_trace.at(i).kernel_kernel_side_effect_out = - std::get(kernel_trace_builder.public_inputs).at(i); - - main_trace.at(i).kernel_kernel_metadata_out = - std::get(kernel_trace_builder.public_inputs).at(i); - } + // Add the kernel inputs and outputs + kernel_trace_builder.finalize_columns(main_trace); // calldata column inclusion and selector for (size_t i = 0; i < calldata.size(); i++) { diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp index 406d840ccf1..5e5c3fdec2e 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp @@ -5,6 +5,7 @@ #include "barretenberg/vm/avm/trace/alu_trace.hpp" #include "barretenberg/vm/avm/trace/binary_trace.hpp" #include "barretenberg/vm/avm/trace/common.hpp" +#include "barretenberg/vm/avm/trace/execution_hints.hpp" #include "barretenberg/vm/avm/trace/gadgets/conversion_trace.hpp" #include "barretenberg/vm/avm/trace/gadgets/ecc.hpp" #include "barretenberg/vm/avm/trace/gadgets/keccak.hpp" @@ -193,6 +194,14 @@ class AvmTraceBuilder { private: std::vector main_trace; + + std::vector calldata; + std::vector returndata; + // Side effect counter will increment when any state writing values are encountered. + uint32_t side_effect_counter = 0; + uint32_t external_call_counter = 0; + ExecutionHints execution_hints; + AvmMemTraceBuilder mem_trace_builder; AvmAluTraceBuilder alu_trace_builder; AvmBinaryTraceBuilder bin_trace_builder; @@ -206,11 +215,7 @@ class AvmTraceBuilder { AvmEccTraceBuilder ecc_trace_builder; AvmSliceTraceBuilder slice_trace_builder; - std::vector calldata{}; - std::vector returndata{}; - - Row create_kernel_lookup_opcode( - uint8_t indirect, uint32_t dst_offset, uint32_t selector, FF value, AvmMemoryTag w_tag); + Row create_kernel_lookup_opcode(uint8_t indirect, uint32_t dst_offset, FF value, AvmMemoryTag w_tag); Row create_kernel_output_opcode(uint8_t indirect, uint32_t clk, uint32_t data_offset); @@ -240,16 +245,6 @@ class AvmTraceBuilder { 0; // After a nested call, it should be initialized with MAX_SIZE_INTERNAL_STACK * call_ptr uint8_t call_ptr = 0; - // Side effect counter will increment when any state writing values are - // encountered - uint32_t side_effect_counter = 0; - uint32_t initial_side_effect_counter; // This one is constant. - uint32_t external_call_counter = 0; - - // Execution hints aid witness solving for instructions that require auxiliary information to construct - // Mapping of side effect counter -> value - ExecutionHints execution_hints; - MemOp constrained_read_from_memory(uint8_t space_id, uint32_t clk, AddressWithMode addr, diff --git a/bb-pilcom/bb-pil-backend/templates/circuit_builder.cpp.hbs b/bb-pilcom/bb-pil-backend/templates/circuit_builder.cpp.hbs index 1762970adc0..4ac476e2c67 100644 --- a/bb-pilcom/bb-pil-backend/templates/circuit_builder.cpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/circuit_builder.cpp.hbs @@ -65,16 +65,20 @@ bool {{name}}CircuitBuilder::check_circuit() const { r = 0; } + std::array subrelation_failed = { false }; for (size_t r = 0; r < num_rows; ++r) { Relation::accumulate(result, polys.get_row(r), {}, 1); for (size_t j = 0; j < result.size(); ++j) { - if (result[j] != 0) { + if (!subrelation_failed[j] && result[j] != 0) { signal_error(format("Relation ", Relation::NAME, ", subrelation ", Relation::get_subrelation_label(j), " failed at row ", r)); + // We will not check this subrelation for any other rows. + // Since the accumulation will keep being != 0. + subrelation_failed[j] = true; } } } @@ -106,14 +110,9 @@ bool {{name}}CircuitBuilder::check_circuit() const { std::string errors; std::mutex m; - const bool verbose_errors = std::getenv("AVM_VERBOSE_ERRORS") != nullptr; auto signal_error = [&](const std::string& error) { std::lock_guard lock(m); - if (verbose_errors) { - errors += error + "\n"; - } else if (errors.empty()) { - errors = "Circuit check failed. Use AVM_VERBOSE_ERRORS=1 to see more details."; - } + errors += error + "\n"; }; bb::parallel_for(checks.size(), [&](size_t i) { checks[i](signal_error); }); if (!errors.empty()) {