diff --git a/barretenberg/cpp/pil/avm/avm_kernel.pil b/barretenberg/cpp/pil/avm/avm_kernel.pil new file mode 100644 index 00000000000..2339ff5715e --- /dev/null +++ b/barretenberg/cpp/pil/avm/avm_kernel.pil @@ -0,0 +1,10 @@ +include "avm_main.pil"; +include "constants.pil"; + +namespace avm_kernel(256); + pol public kernel_inputs; + pol commit kernel_sel; + + // 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; diff --git a/barretenberg/cpp/pil/avm/avm_main.pil b/barretenberg/cpp/pil/avm/avm_main.pil index 8d9f3010ec4..2ead092ce20 100644 --- a/barretenberg/cpp/pil/avm/avm_main.pil +++ b/barretenberg/cpp/pil/avm/avm_main.pil @@ -2,8 +2,28 @@ include "avm_mem.pil"; include "avm_alu.pil"; include "avm_binary.pil"; +include "avm_kernel.pil"; namespace avm_main(256); + // Kernel lookup selector opcodes + pol commit q_kernel_lookup; + + // CALL CONTEXT + pol commit sel_op_sender; + pol commit sel_op_address; + pol commit sel_op_portal; + + // FEES + pol commit sel_op_fee_per_l2_gas; + pol commit sel_op_fee_per_da_gas; + pol commit sel_op_transaction_fee; + + // GLOBALS + pol commit sel_op_chain_id; + pol commit sel_op_version; + pol commit sel_op_block_number; + pol commit sel_op_coinbase; + pol commit sel_op_timestamp; //===== CONSTANT POLYNOMIALS ================================================== pol constant clk(i) { i }; @@ -135,6 +155,18 @@ namespace avm_main(256); // Relations on type constraints // TODO: Very likely, we can remove these constraints as the selectors should be derived during // opcode decomposition. + sel_op_sender * (1 - sel_op_sender) = 0; + sel_op_address * (1 - sel_op_address) = 0; + sel_op_portal * (1 - sel_op_portal) = 0; + sel_op_chain_id * (1 - sel_op_chain_id) = 0; + sel_op_version * (1 - sel_op_version) = 0; + sel_op_block_number * (1 - sel_op_block_number) = 0; + sel_op_coinbase * (1 - sel_op_coinbase) = 0; + sel_op_timestamp * (1 - sel_op_timestamp) = 0; + sel_op_fee_per_l2_gas * (1 - sel_op_fee_per_l2_gas) = 0; + sel_op_fee_per_da_gas * (1 - sel_op_fee_per_da_gas) = 0; + sel_op_transaction_fee * (1 - sel_op_transaction_fee) = 0; + sel_op_add * (1 - sel_op_add) = 0; sel_op_sub * (1 - sel_op_sub) = 0; sel_op_mul * (1 - sel_op_mul) = 0; @@ -235,6 +267,15 @@ namespace avm_main(256); // (ib * inv - 1 + op_fdiv_err) = 0 && op_err * (1 - inv) = 0 // 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_SELECTORS = ( + sel_op_sender + sel_op_address + sel_op_portal + 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 + sel_op_transaction_fee + ); + // Ensure that only one kernel lookup is active when the kernel_sel is active + #[KERNEL_ACTIVE_CHECK] + KERNEL_SELECTORS * (1 - q_kernel_lookup) = 0; //===== CONTROL FLOW ======================================================= //===== JUMP =============================================================== @@ -271,7 +312,7 @@ namespace avm_main(256); //===== CONTROL_FLOW_CONSISTENCY ============================================ pol INTERNAL_CALL_STACK_SELECTORS = (first + sel_internal_call + sel_internal_return + sel_halt); pol OPCODE_SELECTORS = (sel_op_add + sel_op_sub + sel_op_div + sel_op_fdiv + sel_op_mul + sel_op_not - + sel_op_eq + sel_op_and + sel_op_or + sel_op_xor + sel_op_cast); + + sel_op_eq + sel_op_and + sel_op_or + sel_op_xor + sel_op_cast + KERNEL_SELECTORS); // Program counter must increment if not jumping or returning #[PC_INCREMENT] @@ -329,6 +370,53 @@ namespace avm_main(256); ALU_R_TAG_SEL * (alu_in_tag - r_in_tag) = 0; ALU_W_TAG_SEL * (alu_in_tag - w_in_tag) = 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_sel to the value relevant to the given opcode that is active + + // CALL CONTEXT + #[SENDER_KERNEL] + sel_op_sender * (avm_kernel.kernel_sel - constants.SENDER_SELECTOR) = 0; + + #[ADDRESS_KERNEL] + sel_op_address * (avm_kernel.kernel_sel - constants.ADDRESS_SELECTOR) = 0; + + #[PORTAL_KERNEL] + sel_op_portal * (avm_kernel.kernel_sel - constants.PORTAL_SELECTOR) = 0; + + // FEES + #[FEE_DA_GAS_KERNEL] + sel_op_fee_per_da_gas * (avm_kernel.kernel_sel - constants.FEE_PER_DA_GAS_SELECTOR) = 0; + + #[FEE_L2_GAS_KERNEL] + sel_op_fee_per_l2_gas * (avm_kernel.kernel_sel - constants.FEE_PER_L2_GAS_SELECTOR) = 0; + + #[FEE_TRANSACTION_FEE_KERNEL] + sel_op_transaction_fee * (avm_kernel.kernel_sel - constants.TRANSACTION_FEE_SELECTOR) = 0; + + // GLOBALS + #[CHAIN_ID_KERNEL] + sel_op_chain_id * (avm_kernel.kernel_sel - constants.CHAIN_ID_SELECTOR) = 0; + + #[VERSION_KERNEL] + sel_op_version * (avm_kernel.kernel_sel - constants.VERSION_SELECTOR) = 0; + + #[BLOCK_NUMBER_KERNEL] + sel_op_block_number * (avm_kernel.kernel_sel - constants.BLOCK_NUMBER_SELECTOR) = 0; + + #[COINBASE_KERNEL] + sel_op_coinbase * (avm_kernel.kernel_sel - constants.COINBASE_SELECTOR) = 0; + + #[TIMESTAMP_KERNEL] + sel_op_timestamp * (avm_kernel.kernel_sel - constants.TIMESTAMP_SELECTOR) = 0; + + #[LOOKUP_INTO_KERNEL] + // TODO: FIX not having the trailing is_public breaking compilation :( + q_kernel_lookup { avm_main.ia, avm_kernel.kernel_sel } in avm_kernel.q_public_input_kernel_add_to_table { avm_kernel.kernel_inputs__is_public, clk }; + //====== Inter-table Constraints ============================================ #[INCL_MAIN_TAG_ERR] avm_mem.tag_err {avm_mem.clk} in tag_err {clk}; diff --git a/barretenberg/cpp/pil/avm/constants.pil b/barretenberg/cpp/pil/avm/constants.pil new file mode 100644 index 00000000000..d5985545280 --- /dev/null +++ b/barretenberg/cpp/pil/avm/constants.pil @@ -0,0 +1,29 @@ + +// NOTE: the constants in this file line up to the indexes of values in the +// `PublicKernelInputs.nr` object +namespace constants(256); + // From Public Context Inputs + pol SENDER_SELECTOR = 0; + pol ADDRESS_SELECTOR = 1; + pol PORTAL_SELECTOR = 2; + + // NOTE: constant expression evaluation does not seem to be supported yet in pil + // pol START_GLOBAL_VARIABLES = CALL_CONTEXT_LENGTH + HEADER_LENGTH = 6 + 22 = 28 + + // Global Variables + pol CHAIN_ID_SELECTOR = 28; + pol VERSION_SELECTOR = 29; + pol BLOCK_NUMBER_SELECTOR = 30; + pol TIMESTAMP_SELECTOR = 31; + pol COINBASE_SELECTOR = 32; + + pol END_GLOBAL_VARIABLES = 28 + 8; // We only use the first 5 of 8 global variables for now + + pol START_SIDE_EFFECT_COUNTER = 36; + + // Gas + pol FEE_PER_DA_GAS_SELECTOR = 37; + pol FEE_PER_L2_GAS_SELECTOR = 38; + + pol TRANSACTION_FEE_SELECTOR = 39; + diff --git a/barretenberg/cpp/scripts/compile_avm.sh b/barretenberg/cpp/scripts/compile_avm.sh new file mode 100755 index 00000000000..01f422e229f --- /dev/null +++ b/barretenberg/cpp/scripts/compile_avm.sh @@ -0,0 +1,23 @@ +#!/bin/bash +use_zsh_alias() { + # Run Zsh command, source .zshrc, and then execute the alias + zsh -i -c "$1" +} + +# Compile +use_zsh_alias "bb_pil pil/avm/avm_main.pil --name Avm" + +# Format generated folders +root_dir="src" + +# Find all directories named 'generate' under the specified root directory +find "$root_dir" -type d -name 'generate' | while read dir_path; do + echo "Processing directory: $dir_path" + + # Find all C/C++ source files in these directories and format them + find "$dir_path" -type f \( -iname '*.hpp' -o -iname '*.cpp' \) -exec clang-format -i {} + +done + + +# Build vm tests +cmake --build --preset clang16 --target vm_tests \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp index 27319832d00..d5c60d139de 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp @@ -7,6 +7,7 @@ namespace bb::Avm_vm { template struct Avm_mainRow { + FF avm_kernel_kernel_sel{}; FF avm_main_alu_in_tag{}; FF avm_main_alu_sel{}; FF avm_main_bin_op_id{}; @@ -33,6 +34,7 @@ template struct Avm_mainRow { FF avm_main_op_err{}; FF avm_main_pc{}; FF avm_main_pc_shift{}; + FF avm_main_q_kernel_lookup{}; FF avm_main_r_in_tag{}; FF avm_main_rwa{}; FF avm_main_rwb{}; @@ -47,19 +49,30 @@ template struct Avm_mainRow { FF avm_main_sel_mov_a{}; FF avm_main_sel_mov_b{}; FF avm_main_sel_op_add{}; + FF avm_main_sel_op_address{}; FF avm_main_sel_op_and{}; + FF avm_main_sel_op_block_number{}; FF avm_main_sel_op_cast{}; + FF avm_main_sel_op_chain_id{}; + FF avm_main_sel_op_coinbase{}; FF avm_main_sel_op_div{}; FF avm_main_sel_op_eq{}; FF avm_main_sel_op_fdiv{}; + FF avm_main_sel_op_fee_per_da_gas{}; + FF avm_main_sel_op_fee_per_l2_gas{}; FF avm_main_sel_op_lt{}; FF avm_main_sel_op_lte{}; FF avm_main_sel_op_mul{}; FF avm_main_sel_op_not{}; FF avm_main_sel_op_or{}; + FF avm_main_sel_op_portal{}; + FF avm_main_sel_op_sender{}; FF avm_main_sel_op_shl{}; FF avm_main_sel_op_shr{}; FF avm_main_sel_op_sub{}; + FF avm_main_sel_op_timestamp{}; + FF avm_main_sel_op_transaction_fee{}; + FF avm_main_sel_op_version{}; FF avm_main_sel_op_xor{}; FF avm_main_tag_err{}; FF avm_main_w_in_tag{}; @@ -68,58 +81,94 @@ template struct Avm_mainRow { inline std::string get_relation_label_avm_main(int index) { switch (index) { - case 36: + case 47: return "OUTPUT_U8"; - case 37: + case 48: return "SUBOP_FDIV"; - case 38: + case 49: return "SUBOP_FDIV_ZERO_ERR1"; - case 39: + case 50: return "SUBOP_FDIV_ZERO_ERR2"; - case 40: + case 51: return "SUBOP_FDIV_R_IN_TAG_FF"; - case 41: + case 52: return "SUBOP_FDIV_W_IN_TAG_FF"; - case 42: + case 53: return "SUBOP_ERROR_RELEVANT_OP"; - case 44: + case 54: + return "KERNEL_ACTIVE_CHECK"; + + case 56: return "RETURN_POINTER_INCREMENT"; - case 50: + case 62: return "RETURN_POINTER_DECREMENT"; - case 55: + case 67: return "PC_INCREMENT"; - case 56: + case 68: return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - case 57: + case 69: return "CMOV_CONDITION_RES_1"; - case 58: + case 70: return "CMOV_CONDITION_RES_2"; - case 61: + case 73: return "MOV_SAME_VALUE_A"; - case 62: + case 74: return "MOV_SAME_VALUE_B"; - case 63: + case 75: return "MOV_MAIN_SAME_TAG"; - case 67: + case 79: + return "SENDER_KERNEL"; + + case 80: + return "ADDRESS_KERNEL"; + + case 81: + return "PORTAL_KERNEL"; + + case 82: + return "FEE_DA_GAS_KERNEL"; + + case 83: + return "FEE_L2_GAS_KERNEL"; + + case 84: + return "FEE_TRANSACTION_FEE_KERNEL"; + + case 85: + return "CHAIN_ID_KERNEL"; + + case 86: + return "VERSION_KERNEL"; + + case 87: + return "BLOCK_NUMBER_KERNEL"; + + case 88: + return "COINBASE_KERNEL"; + + case 89: + return "TIMESTAMP_KERNEL"; + + case 90: return "BIN_SEL_1"; - case 68: + case 91: return "BIN_SEL_2"; } return std::to_string(index); @@ -129,9 +178,10 @@ template class avm_mainImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 5, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 4, 4, 3, 3, 3, 3, 3, 4, 3, 3, 3, 2, + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 5, 3, 4, 4, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, }; template @@ -145,7 +195,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(0); - auto tmp = (avm_main_sel_op_add * (-avm_main_sel_op_add + FF(1))); + auto tmp = (avm_main_sel_op_sender * (-avm_main_sel_op_sender + FF(1))); tmp *= scaling_factor; std::get<0>(evals) += tmp; } @@ -153,7 +203,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(1); - auto tmp = (avm_main_sel_op_sub * (-avm_main_sel_op_sub + FF(1))); + auto tmp = (avm_main_sel_op_address * (-avm_main_sel_op_address + FF(1))); tmp *= scaling_factor; std::get<1>(evals) += tmp; } @@ -161,7 +211,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(2); - auto tmp = (avm_main_sel_op_mul * (-avm_main_sel_op_mul + FF(1))); + auto tmp = (avm_main_sel_op_portal * (-avm_main_sel_op_portal + FF(1))); tmp *= scaling_factor; std::get<2>(evals) += tmp; } @@ -169,7 +219,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(3); - auto tmp = (avm_main_sel_op_div * (-avm_main_sel_op_div + FF(1))); + auto tmp = (avm_main_sel_op_chain_id * (-avm_main_sel_op_chain_id + FF(1))); tmp *= scaling_factor; std::get<3>(evals) += tmp; } @@ -177,7 +227,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(4); - auto tmp = (avm_main_sel_op_fdiv * (-avm_main_sel_op_fdiv + FF(1))); + auto tmp = (avm_main_sel_op_version * (-avm_main_sel_op_version + FF(1))); tmp *= scaling_factor; std::get<4>(evals) += tmp; } @@ -185,7 +235,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(5); - auto tmp = (avm_main_sel_op_not * (-avm_main_sel_op_not + FF(1))); + auto tmp = (avm_main_sel_op_block_number * (-avm_main_sel_op_block_number + FF(1))); tmp *= scaling_factor; std::get<5>(evals) += tmp; } @@ -193,7 +243,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(6); - auto tmp = (avm_main_sel_op_eq * (-avm_main_sel_op_eq + FF(1))); + auto tmp = (avm_main_sel_op_coinbase * (-avm_main_sel_op_coinbase + FF(1))); tmp *= scaling_factor; std::get<6>(evals) += tmp; } @@ -201,7 +251,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(7); - auto tmp = (avm_main_sel_op_and * (-avm_main_sel_op_and + FF(1))); + auto tmp = (avm_main_sel_op_timestamp * (-avm_main_sel_op_timestamp + FF(1))); tmp *= scaling_factor; std::get<7>(evals) += tmp; } @@ -209,7 +259,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(8); - auto tmp = (avm_main_sel_op_or * (-avm_main_sel_op_or + FF(1))); + auto tmp = (avm_main_sel_op_fee_per_l2_gas * (-avm_main_sel_op_fee_per_l2_gas + FF(1))); tmp *= scaling_factor; std::get<8>(evals) += tmp; } @@ -217,7 +267,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(9); - auto tmp = (avm_main_sel_op_xor * (-avm_main_sel_op_xor + FF(1))); + auto tmp = (avm_main_sel_op_fee_per_da_gas * (-avm_main_sel_op_fee_per_da_gas + FF(1))); tmp *= scaling_factor; std::get<9>(evals) += tmp; } @@ -225,7 +275,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(10); - auto tmp = (avm_main_sel_op_cast * (-avm_main_sel_op_cast + FF(1))); + auto tmp = (avm_main_sel_op_transaction_fee * (-avm_main_sel_op_transaction_fee + FF(1))); tmp *= scaling_factor; std::get<10>(evals) += tmp; } @@ -233,7 +283,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(11); - auto tmp = (avm_main_sel_op_lt * (-avm_main_sel_op_lt + FF(1))); + auto tmp = (avm_main_sel_op_add * (-avm_main_sel_op_add + FF(1))); tmp *= scaling_factor; std::get<11>(evals) += tmp; } @@ -241,7 +291,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(12); - auto tmp = (avm_main_sel_op_lte * (-avm_main_sel_op_lte + FF(1))); + auto tmp = (avm_main_sel_op_sub * (-avm_main_sel_op_sub + FF(1))); tmp *= scaling_factor; std::get<12>(evals) += tmp; } @@ -249,7 +299,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(13); - auto tmp = (avm_main_sel_op_shl * (-avm_main_sel_op_shl + FF(1))); + auto tmp = (avm_main_sel_op_mul * (-avm_main_sel_op_mul + FF(1))); tmp *= scaling_factor; std::get<13>(evals) += tmp; } @@ -257,7 +307,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(14); - auto tmp = (avm_main_sel_op_shr * (-avm_main_sel_op_shr + FF(1))); + auto tmp = (avm_main_sel_op_div * (-avm_main_sel_op_div + FF(1))); tmp *= scaling_factor; std::get<14>(evals) += tmp; } @@ -265,7 +315,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(15); - auto tmp = (avm_main_sel_internal_call * (-avm_main_sel_internal_call + FF(1))); + auto tmp = (avm_main_sel_op_fdiv * (-avm_main_sel_op_fdiv + FF(1))); tmp *= scaling_factor; std::get<15>(evals) += tmp; } @@ -273,7 +323,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(16); - auto tmp = (avm_main_sel_internal_return * (-avm_main_sel_internal_return + FF(1))); + auto tmp = (avm_main_sel_op_not * (-avm_main_sel_op_not + FF(1))); tmp *= scaling_factor; std::get<16>(evals) += tmp; } @@ -281,7 +331,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(17); - auto tmp = (avm_main_sel_jump * (-avm_main_sel_jump + FF(1))); + auto tmp = (avm_main_sel_op_eq * (-avm_main_sel_op_eq + FF(1))); tmp *= scaling_factor; std::get<17>(evals) += tmp; } @@ -289,7 +339,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(18); - auto tmp = (avm_main_sel_halt * (-avm_main_sel_halt + FF(1))); + auto tmp = (avm_main_sel_op_and * (-avm_main_sel_op_and + FF(1))); tmp *= scaling_factor; std::get<18>(evals) += tmp; } @@ -297,7 +347,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(19); - auto tmp = (avm_main_sel_mov * (-avm_main_sel_mov + FF(1))); + auto tmp = (avm_main_sel_op_or * (-avm_main_sel_op_or + FF(1))); tmp *= scaling_factor; std::get<19>(evals) += tmp; } @@ -305,7 +355,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(20); - auto tmp = (avm_main_sel_cmov * (-avm_main_sel_cmov + FF(1))); + auto tmp = (avm_main_sel_op_xor * (-avm_main_sel_op_xor + FF(1))); tmp *= scaling_factor; std::get<20>(evals) += tmp; } @@ -313,7 +363,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(21); - auto tmp = (avm_main_op_err * (-avm_main_op_err + FF(1))); + auto tmp = (avm_main_sel_op_cast * (-avm_main_sel_op_cast + FF(1))); tmp *= scaling_factor; std::get<21>(evals) += tmp; } @@ -321,7 +371,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(22); - auto tmp = (avm_main_tag_err * (-avm_main_tag_err + FF(1))); + auto tmp = (avm_main_sel_op_lt * (-avm_main_sel_op_lt + FF(1))); tmp *= scaling_factor; std::get<22>(evals) += tmp; } @@ -329,7 +379,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(23); - auto tmp = (avm_main_id_zero * (-avm_main_id_zero + FF(1))); + auto tmp = (avm_main_sel_op_lte * (-avm_main_sel_op_lte + FF(1))); tmp *= scaling_factor; std::get<23>(evals) += tmp; } @@ -337,7 +387,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(24); - auto tmp = (avm_main_mem_op_a * (-avm_main_mem_op_a + FF(1))); + auto tmp = (avm_main_sel_op_shl * (-avm_main_sel_op_shl + FF(1))); tmp *= scaling_factor; std::get<24>(evals) += tmp; } @@ -345,7 +395,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(25); - auto tmp = (avm_main_mem_op_b * (-avm_main_mem_op_b + FF(1))); + auto tmp = (avm_main_sel_op_shr * (-avm_main_sel_op_shr + FF(1))); tmp *= scaling_factor; std::get<25>(evals) += tmp; } @@ -353,7 +403,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(26); - auto tmp = (avm_main_mem_op_c * (-avm_main_mem_op_c + FF(1))); + auto tmp = (avm_main_sel_internal_call * (-avm_main_sel_internal_call + FF(1))); tmp *= scaling_factor; std::get<26>(evals) += tmp; } @@ -361,7 +411,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(27); - auto tmp = (avm_main_mem_op_d * (-avm_main_mem_op_d + FF(1))); + auto tmp = (avm_main_sel_internal_return * (-avm_main_sel_internal_return + FF(1))); tmp *= scaling_factor; std::get<27>(evals) += tmp; } @@ -369,7 +419,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(28); - auto tmp = (avm_main_rwa * (-avm_main_rwa + FF(1))); + auto tmp = (avm_main_sel_jump * (-avm_main_sel_jump + FF(1))); tmp *= scaling_factor; std::get<28>(evals) += tmp; } @@ -377,7 +427,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(29); - auto tmp = (avm_main_rwb * (-avm_main_rwb + FF(1))); + auto tmp = (avm_main_sel_halt * (-avm_main_sel_halt + FF(1))); tmp *= scaling_factor; std::get<29>(evals) += tmp; } @@ -385,7 +435,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(30); - auto tmp = (avm_main_rwc * (-avm_main_rwc + FF(1))); + auto tmp = (avm_main_sel_mov * (-avm_main_sel_mov + FF(1))); tmp *= scaling_factor; std::get<30>(evals) += tmp; } @@ -393,7 +443,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(31); - auto tmp = (avm_main_rwd * (-avm_main_rwd + FF(1))); + auto tmp = (avm_main_sel_cmov * (-avm_main_sel_cmov + FF(1))); tmp *= scaling_factor; std::get<31>(evals) += tmp; } @@ -401,7 +451,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(32); - auto tmp = (avm_main_ind_op_a * (-avm_main_ind_op_a + FF(1))); + auto tmp = (avm_main_op_err * (-avm_main_op_err + FF(1))); tmp *= scaling_factor; std::get<32>(evals) += tmp; } @@ -409,7 +459,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(33); - auto tmp = (avm_main_ind_op_b * (-avm_main_ind_op_b + FF(1))); + auto tmp = (avm_main_tag_err * (-avm_main_tag_err + FF(1))); tmp *= scaling_factor; std::get<33>(evals) += tmp; } @@ -417,7 +467,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(34); - auto tmp = (avm_main_ind_op_c * (-avm_main_ind_op_c + FF(1))); + auto tmp = (avm_main_id_zero * (-avm_main_id_zero + FF(1))); tmp *= scaling_factor; std::get<34>(evals) += tmp; } @@ -425,7 +475,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(35); - auto tmp = (avm_main_ind_op_d * (-avm_main_ind_op_d + FF(1))); + auto tmp = (avm_main_mem_op_a * (-avm_main_mem_op_a + FF(1))); tmp *= scaling_factor; std::get<35>(evals) += tmp; } @@ -433,8 +483,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(36); - auto tmp = - (((avm_main_sel_op_eq + avm_main_sel_op_lte) + avm_main_sel_op_lt) * (avm_main_w_in_tag - FF(1))); + auto tmp = (avm_main_mem_op_b * (-avm_main_mem_op_b + FF(1))); tmp *= scaling_factor; std::get<36>(evals) += tmp; } @@ -442,8 +491,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(37); - auto tmp = - ((avm_main_sel_op_fdiv * (-avm_main_op_err + FF(1))) * ((avm_main_ic * avm_main_ib) - avm_main_ia)); + auto tmp = (avm_main_mem_op_c * (-avm_main_mem_op_c + FF(1))); tmp *= scaling_factor; std::get<37>(evals) += tmp; } @@ -451,8 +499,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(38); - auto tmp = ((avm_main_sel_op_fdiv + avm_main_sel_op_div) * - (((avm_main_ib * avm_main_inv) - FF(1)) + avm_main_op_err)); + auto tmp = (avm_main_mem_op_d * (-avm_main_mem_op_d + FF(1))); tmp *= scaling_factor; std::get<38>(evals) += tmp; } @@ -460,7 +507,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(39); - auto tmp = (((avm_main_sel_op_fdiv + avm_main_sel_op_div) * avm_main_op_err) * (-avm_main_inv + FF(1))); + auto tmp = (avm_main_rwa * (-avm_main_rwa + FF(1))); tmp *= scaling_factor; std::get<39>(evals) += tmp; } @@ -468,7 +515,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(40); - auto tmp = (avm_main_sel_op_fdiv * (avm_main_r_in_tag - FF(6))); + auto tmp = (avm_main_rwb * (-avm_main_rwb + FF(1))); tmp *= scaling_factor; std::get<40>(evals) += tmp; } @@ -476,7 +523,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(41); - auto tmp = (avm_main_sel_op_fdiv * (avm_main_w_in_tag - FF(6))); + auto tmp = (avm_main_rwc * (-avm_main_rwc + FF(1))); tmp *= scaling_factor; std::get<41>(evals) += tmp; } @@ -484,7 +531,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(42); - auto tmp = (avm_main_op_err * ((avm_main_sel_op_fdiv + avm_main_sel_op_div) - FF(1))); + auto tmp = (avm_main_rwd * (-avm_main_rwd + FF(1))); tmp *= scaling_factor; std::get<42>(evals) += tmp; } @@ -492,7 +539,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(43); - auto tmp = (avm_main_sel_jump * (avm_main_pc_shift - avm_main_ia)); + auto tmp = (avm_main_ind_op_a * (-avm_main_ind_op_a + FF(1))); tmp *= scaling_factor; std::get<43>(evals) += tmp; } @@ -500,8 +547,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(44); - auto tmp = (avm_main_sel_internal_call * - (avm_main_internal_return_ptr_shift - (avm_main_internal_return_ptr + FF(1)))); + auto tmp = (avm_main_ind_op_b * (-avm_main_ind_op_b + FF(1))); tmp *= scaling_factor; std::get<44>(evals) += tmp; } @@ -509,7 +555,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(45); - auto tmp = (avm_main_sel_internal_call * (avm_main_internal_return_ptr - avm_main_mem_idx_b)); + auto tmp = (avm_main_ind_op_c * (-avm_main_ind_op_c + FF(1))); tmp *= scaling_factor; std::get<45>(evals) += tmp; } @@ -517,7 +563,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(46); - auto tmp = (avm_main_sel_internal_call * (avm_main_pc_shift - avm_main_ia)); + auto tmp = (avm_main_ind_op_d * (-avm_main_ind_op_d + FF(1))); tmp *= scaling_factor; std::get<46>(evals) += tmp; } @@ -525,7 +571,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(47); - auto tmp = (avm_main_sel_internal_call * ((avm_main_pc + FF(1)) - avm_main_ib)); + auto tmp = + (((avm_main_sel_op_eq + avm_main_sel_op_lte) + avm_main_sel_op_lt) * (avm_main_w_in_tag - FF(1))); tmp *= scaling_factor; std::get<47>(evals) += tmp; } @@ -533,7 +580,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(48); - auto tmp = (avm_main_sel_internal_call * (avm_main_rwb - FF(1))); + auto tmp = + ((avm_main_sel_op_fdiv * (-avm_main_op_err + FF(1))) * ((avm_main_ic * avm_main_ib) - avm_main_ia)); tmp *= scaling_factor; std::get<48>(evals) += tmp; } @@ -541,7 +589,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(49); - auto tmp = (avm_main_sel_internal_call * (avm_main_mem_op_b - FF(1))); + auto tmp = ((avm_main_sel_op_fdiv + avm_main_sel_op_div) * + (((avm_main_ib * avm_main_inv) - FF(1)) + avm_main_op_err)); tmp *= scaling_factor; std::get<49>(evals) += tmp; } @@ -549,8 +598,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(50); - auto tmp = (avm_main_sel_internal_return * - (avm_main_internal_return_ptr_shift - (avm_main_internal_return_ptr - FF(1)))); + auto tmp = (((avm_main_sel_op_fdiv + avm_main_sel_op_div) * avm_main_op_err) * (-avm_main_inv + FF(1))); tmp *= scaling_factor; std::get<50>(evals) += tmp; } @@ -558,7 +606,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(51); - auto tmp = (avm_main_sel_internal_return * ((avm_main_internal_return_ptr - FF(1)) - avm_main_mem_idx_a)); + auto tmp = (avm_main_sel_op_fdiv * (avm_main_r_in_tag - FF(6))); tmp *= scaling_factor; std::get<51>(evals) += tmp; } @@ -566,7 +614,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(52); - auto tmp = (avm_main_sel_internal_return * (avm_main_pc_shift - avm_main_ia)); + auto tmp = (avm_main_sel_op_fdiv * (avm_main_w_in_tag - FF(6))); tmp *= scaling_factor; std::get<52>(evals) += tmp; } @@ -574,7 +622,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(53); - auto tmp = (avm_main_sel_internal_return * avm_main_rwa); + auto tmp = (avm_main_op_err * ((avm_main_sel_op_fdiv + avm_main_sel_op_div) - FF(1))); tmp *= scaling_factor; std::get<53>(evals) += tmp; } @@ -582,7 +630,16 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(54); - auto tmp = (avm_main_sel_internal_return * (avm_main_mem_op_a - FF(1))); + auto tmp = (((((((((((avm_main_sel_op_sender + avm_main_sel_op_address) + avm_main_sel_op_portal) + + avm_main_sel_op_chain_id) + + avm_main_sel_op_version) + + avm_main_sel_op_block_number) + + avm_main_sel_op_coinbase) + + avm_main_sel_op_timestamp) + + avm_main_sel_op_fee_per_l2_gas) + + avm_main_sel_op_fee_per_da_gas) + + avm_main_sel_op_transaction_fee) * + (-avm_main_q_kernel_lookup + FF(1))); tmp *= scaling_factor; std::get<54>(evals) += tmp; } @@ -590,17 +647,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(55); - auto tmp = - ((((-avm_main_first + FF(1)) * (-avm_main_sel_halt + FF(1))) * - ((((((((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_div) + avm_main_sel_op_fdiv) + - avm_main_sel_op_mul) + - avm_main_sel_op_not) + - avm_main_sel_op_eq) + - avm_main_sel_op_and) + - avm_main_sel_op_or) + - avm_main_sel_op_xor) + - avm_main_sel_op_cast)) * - (avm_main_pc_shift - (avm_main_pc + FF(1)))); + auto tmp = (avm_main_sel_jump * (avm_main_pc_shift - avm_main_ia)); tmp *= scaling_factor; std::get<55>(evals) += tmp; } @@ -608,10 +655,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(56); - auto tmp = ((-(((avm_main_first + avm_main_sel_internal_call) + avm_main_sel_internal_return) + - avm_main_sel_halt) + - FF(1)) * - (avm_main_internal_return_ptr_shift - avm_main_internal_return_ptr)); + auto tmp = (avm_main_sel_internal_call * + (avm_main_internal_return_ptr_shift - (avm_main_internal_return_ptr + FF(1)))); tmp *= scaling_factor; std::get<56>(evals) += tmp; } @@ -619,7 +664,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(57); - auto tmp = (avm_main_sel_cmov * (((avm_main_id * avm_main_inv) - FF(1)) + avm_main_id_zero)); + auto tmp = (avm_main_sel_internal_call * (avm_main_internal_return_ptr - avm_main_mem_idx_b)); tmp *= scaling_factor; std::get<57>(evals) += tmp; } @@ -627,7 +672,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(58); - auto tmp = ((avm_main_sel_cmov * avm_main_id_zero) * (-avm_main_inv + FF(1))); + auto tmp = (avm_main_sel_internal_call * (avm_main_pc_shift - avm_main_ia)); tmp *= scaling_factor; std::get<58>(evals) += tmp; } @@ -635,7 +680,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(59); - auto tmp = (avm_main_sel_mov_a - (avm_main_sel_mov + (avm_main_sel_cmov * (-avm_main_id_zero + FF(1))))); + auto tmp = (avm_main_sel_internal_call * ((avm_main_pc + FF(1)) - avm_main_ib)); tmp *= scaling_factor; std::get<59>(evals) += tmp; } @@ -643,7 +688,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(60); - auto tmp = (avm_main_sel_mov_b - (avm_main_sel_cmov * avm_main_id_zero)); + auto tmp = (avm_main_sel_internal_call * (avm_main_rwb - FF(1))); tmp *= scaling_factor; std::get<60>(evals) += tmp; } @@ -651,7 +696,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(61); - auto tmp = (avm_main_sel_mov_a * (avm_main_ia - avm_main_ic)); + auto tmp = (avm_main_sel_internal_call * (avm_main_mem_op_b - FF(1))); tmp *= scaling_factor; std::get<61>(evals) += tmp; } @@ -659,7 +704,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(62); - auto tmp = (avm_main_sel_mov_b * (avm_main_ib - avm_main_ic)); + auto tmp = (avm_main_sel_internal_return * + (avm_main_internal_return_ptr_shift - (avm_main_internal_return_ptr - FF(1)))); tmp *= scaling_factor; std::get<62>(evals) += tmp; } @@ -667,7 +713,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(63); - auto tmp = ((avm_main_sel_mov + avm_main_sel_cmov) * (avm_main_r_in_tag - avm_main_w_in_tag)); + auto tmp = (avm_main_sel_internal_return * ((avm_main_internal_return_ptr - FF(1)) - avm_main_mem_idx_a)); tmp *= scaling_factor; std::get<63>(evals) += tmp; } @@ -675,6 +721,124 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(64); + auto tmp = (avm_main_sel_internal_return * (avm_main_pc_shift - avm_main_ia)); + tmp *= scaling_factor; + std::get<64>(evals) += tmp; + } + // Contribution 65 + { + Avm_DECLARE_VIEWS(65); + + auto tmp = (avm_main_sel_internal_return * avm_main_rwa); + tmp *= scaling_factor; + std::get<65>(evals) += tmp; + } + // Contribution 66 + { + Avm_DECLARE_VIEWS(66); + + auto tmp = (avm_main_sel_internal_return * (avm_main_mem_op_a - FF(1))); + tmp *= scaling_factor; + std::get<66>(evals) += tmp; + } + // Contribution 67 + { + Avm_DECLARE_VIEWS(67); + + auto tmp = + ((((-avm_main_first + FF(1)) * (-avm_main_sel_halt + FF(1))) * + (((((((((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_div) + avm_main_sel_op_fdiv) + + avm_main_sel_op_mul) + + avm_main_sel_op_not) + + avm_main_sel_op_eq) + + avm_main_sel_op_and) + + avm_main_sel_op_or) + + avm_main_sel_op_xor) + + avm_main_sel_op_cast) + + ((((((((((avm_main_sel_op_sender + avm_main_sel_op_address) + avm_main_sel_op_portal) + + avm_main_sel_op_chain_id) + + avm_main_sel_op_version) + + avm_main_sel_op_block_number) + + avm_main_sel_op_coinbase) + + avm_main_sel_op_timestamp) + + avm_main_sel_op_fee_per_l2_gas) + + avm_main_sel_op_fee_per_da_gas) + + avm_main_sel_op_transaction_fee))) * + (avm_main_pc_shift - (avm_main_pc + FF(1)))); + tmp *= scaling_factor; + std::get<67>(evals) += tmp; + } + // Contribution 68 + { + Avm_DECLARE_VIEWS(68); + + auto tmp = ((-(((avm_main_first + avm_main_sel_internal_call) + avm_main_sel_internal_return) + + avm_main_sel_halt) + + FF(1)) * + (avm_main_internal_return_ptr_shift - avm_main_internal_return_ptr)); + tmp *= scaling_factor; + std::get<68>(evals) += tmp; + } + // Contribution 69 + { + Avm_DECLARE_VIEWS(69); + + auto tmp = (avm_main_sel_cmov * (((avm_main_id * avm_main_inv) - FF(1)) + avm_main_id_zero)); + tmp *= scaling_factor; + std::get<69>(evals) += tmp; + } + // Contribution 70 + { + Avm_DECLARE_VIEWS(70); + + auto tmp = ((avm_main_sel_cmov * avm_main_id_zero) * (-avm_main_inv + FF(1))); + tmp *= scaling_factor; + std::get<70>(evals) += tmp; + } + // Contribution 71 + { + Avm_DECLARE_VIEWS(71); + + auto tmp = (avm_main_sel_mov_a - (avm_main_sel_mov + (avm_main_sel_cmov * (-avm_main_id_zero + FF(1))))); + tmp *= scaling_factor; + std::get<71>(evals) += tmp; + } + // Contribution 72 + { + Avm_DECLARE_VIEWS(72); + + auto tmp = (avm_main_sel_mov_b - (avm_main_sel_cmov * avm_main_id_zero)); + tmp *= scaling_factor; + std::get<72>(evals) += tmp; + } + // Contribution 73 + { + Avm_DECLARE_VIEWS(73); + + auto tmp = (avm_main_sel_mov_a * (avm_main_ia - avm_main_ic)); + tmp *= scaling_factor; + std::get<73>(evals) += tmp; + } + // Contribution 74 + { + Avm_DECLARE_VIEWS(74); + + auto tmp = (avm_main_sel_mov_b * (avm_main_ib - avm_main_ic)); + tmp *= scaling_factor; + std::get<74>(evals) += tmp; + } + // Contribution 75 + { + Avm_DECLARE_VIEWS(75); + + auto tmp = ((avm_main_sel_mov + avm_main_sel_cmov) * (avm_main_r_in_tag - avm_main_w_in_tag)); + tmp *= scaling_factor; + std::get<75>(evals) += tmp; + } + // Contribution 76 + { + Avm_DECLARE_VIEWS(76); + auto tmp = (avm_main_alu_sel - ((((((((((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_mul) + avm_main_sel_op_div) + @@ -688,11 +852,11 @@ template class avm_mainImpl { (-avm_main_tag_err + FF(1))) * (-avm_main_op_err + FF(1)))); tmp *= scaling_factor; - std::get<64>(evals) += tmp; + std::get<76>(evals) += tmp; } - // Contribution 65 + // Contribution 77 { - Avm_DECLARE_VIEWS(65); + Avm_DECLARE_VIEWS(77); auto tmp = ((((((((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_mul) + avm_main_sel_op_div) + @@ -704,31 +868,119 @@ template class avm_mainImpl { avm_main_sel_op_shl) * (avm_main_alu_in_tag - avm_main_r_in_tag)); tmp *= scaling_factor; - std::get<65>(evals) += tmp; + std::get<77>(evals) += tmp; } - // Contribution 66 + // Contribution 78 { - Avm_DECLARE_VIEWS(66); + Avm_DECLARE_VIEWS(78); auto tmp = (avm_main_sel_op_cast * (avm_main_alu_in_tag - avm_main_w_in_tag)); tmp *= scaling_factor; - std::get<66>(evals) += tmp; + std::get<78>(evals) += tmp; } - // Contribution 67 + // Contribution 79 { - Avm_DECLARE_VIEWS(67); + Avm_DECLARE_VIEWS(79); + + auto tmp = (avm_main_sel_op_sender * (avm_kernel_kernel_sel - FF(0))); + tmp *= scaling_factor; + std::get<79>(evals) += tmp; + } + // Contribution 80 + { + Avm_DECLARE_VIEWS(80); + + auto tmp = (avm_main_sel_op_address * (avm_kernel_kernel_sel - FF(1))); + tmp *= scaling_factor; + std::get<80>(evals) += tmp; + } + // Contribution 81 + { + Avm_DECLARE_VIEWS(81); + + auto tmp = (avm_main_sel_op_portal * (avm_kernel_kernel_sel - FF(2))); + tmp *= scaling_factor; + std::get<81>(evals) += tmp; + } + // Contribution 82 + { + Avm_DECLARE_VIEWS(82); + + auto tmp = (avm_main_sel_op_fee_per_da_gas * (avm_kernel_kernel_sel - FF(37))); + tmp *= scaling_factor; + std::get<82>(evals) += tmp; + } + // Contribution 83 + { + Avm_DECLARE_VIEWS(83); + + auto tmp = (avm_main_sel_op_fee_per_l2_gas * (avm_kernel_kernel_sel - FF(38))); + tmp *= scaling_factor; + std::get<83>(evals) += tmp; + } + // Contribution 84 + { + Avm_DECLARE_VIEWS(84); + + auto tmp = (avm_main_sel_op_transaction_fee * (avm_kernel_kernel_sel - FF(39))); + tmp *= scaling_factor; + std::get<84>(evals) += tmp; + } + // Contribution 85 + { + Avm_DECLARE_VIEWS(85); + + auto tmp = (avm_main_sel_op_chain_id * (avm_kernel_kernel_sel - FF(28))); + tmp *= scaling_factor; + std::get<85>(evals) += tmp; + } + // Contribution 86 + { + Avm_DECLARE_VIEWS(86); + + auto tmp = (avm_main_sel_op_version * (avm_kernel_kernel_sel - FF(29))); + tmp *= scaling_factor; + std::get<86>(evals) += tmp; + } + // Contribution 87 + { + Avm_DECLARE_VIEWS(87); + + auto tmp = (avm_main_sel_op_block_number * (avm_kernel_kernel_sel - FF(30))); + tmp *= scaling_factor; + std::get<87>(evals) += tmp; + } + // Contribution 88 + { + Avm_DECLARE_VIEWS(88); + + auto tmp = (avm_main_sel_op_coinbase * (avm_kernel_kernel_sel - FF(32))); + tmp *= scaling_factor; + std::get<88>(evals) += tmp; + } + // Contribution 89 + { + Avm_DECLARE_VIEWS(89); + + auto tmp = (avm_main_sel_op_timestamp * (avm_kernel_kernel_sel - FF(31))); + tmp *= scaling_factor; + std::get<89>(evals) += tmp; + } + // Contribution 90 + { + Avm_DECLARE_VIEWS(90); auto tmp = (avm_main_bin_op_id - (avm_main_sel_op_or + (avm_main_sel_op_xor * FF(2)))); tmp *= scaling_factor; - std::get<67>(evals) += tmp; + std::get<90>(evals) += tmp; } - // Contribution 68 + // Contribution 91 { - Avm_DECLARE_VIEWS(68); + Avm_DECLARE_VIEWS(91); auto tmp = (avm_main_bin_sel - ((avm_main_sel_op_and + avm_main_sel_op_or) + avm_main_sel_op_xor)); tmp *= scaling_factor; - std::get<68>(evals) += tmp; + std::get<91>(evals) += tmp; } } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp index 8b595c5ab27..04ed0e23448 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp @@ -107,6 +107,10 @@ [[maybe_unused]] auto avm_byte_lookup_table_input_b = View(new_term.avm_byte_lookup_table_input_b); \ [[maybe_unused]] auto avm_byte_lookup_table_op_id = View(new_term.avm_byte_lookup_table_op_id); \ [[maybe_unused]] auto avm_byte_lookup_table_output = View(new_term.avm_byte_lookup_table_output); \ + [[maybe_unused]] auto avm_kernel_kernel_inputs__is_public = View(new_term.avm_kernel_kernel_inputs__is_public); \ + [[maybe_unused]] auto avm_kernel_kernel_sel = View(new_term.avm_kernel_kernel_sel); \ + [[maybe_unused]] auto avm_kernel_q_public_input_kernel_add_to_table = \ + View(new_term.avm_kernel_q_public_input_kernel_add_to_table); \ [[maybe_unused]] auto avm_main_alu_in_tag = View(new_term.avm_main_alu_in_tag); \ [[maybe_unused]] auto avm_main_alu_sel = View(new_term.avm_main_alu_sel); \ [[maybe_unused]] auto avm_main_bin_op_id = View(new_term.avm_main_bin_op_id); \ @@ -137,6 +141,7 @@ [[maybe_unused]] auto avm_main_mem_op_d = View(new_term.avm_main_mem_op_d); \ [[maybe_unused]] auto avm_main_op_err = View(new_term.avm_main_op_err); \ [[maybe_unused]] auto avm_main_pc = View(new_term.avm_main_pc); \ + [[maybe_unused]] auto avm_main_q_kernel_lookup = View(new_term.avm_main_q_kernel_lookup); \ [[maybe_unused]] auto avm_main_r_in_tag = View(new_term.avm_main_r_in_tag); \ [[maybe_unused]] auto avm_main_rwa = View(new_term.avm_main_rwa); \ [[maybe_unused]] auto avm_main_rwb = View(new_term.avm_main_rwb); \ @@ -151,19 +156,30 @@ [[maybe_unused]] auto avm_main_sel_mov_a = View(new_term.avm_main_sel_mov_a); \ [[maybe_unused]] auto avm_main_sel_mov_b = View(new_term.avm_main_sel_mov_b); \ [[maybe_unused]] auto avm_main_sel_op_add = View(new_term.avm_main_sel_op_add); \ + [[maybe_unused]] auto avm_main_sel_op_address = View(new_term.avm_main_sel_op_address); \ [[maybe_unused]] auto avm_main_sel_op_and = View(new_term.avm_main_sel_op_and); \ + [[maybe_unused]] auto avm_main_sel_op_block_number = View(new_term.avm_main_sel_op_block_number); \ [[maybe_unused]] auto avm_main_sel_op_cast = View(new_term.avm_main_sel_op_cast); \ + [[maybe_unused]] auto avm_main_sel_op_chain_id = View(new_term.avm_main_sel_op_chain_id); \ + [[maybe_unused]] auto avm_main_sel_op_coinbase = View(new_term.avm_main_sel_op_coinbase); \ [[maybe_unused]] auto avm_main_sel_op_div = View(new_term.avm_main_sel_op_div); \ [[maybe_unused]] auto avm_main_sel_op_eq = View(new_term.avm_main_sel_op_eq); \ [[maybe_unused]] auto avm_main_sel_op_fdiv = View(new_term.avm_main_sel_op_fdiv); \ + [[maybe_unused]] auto avm_main_sel_op_fee_per_da_gas = View(new_term.avm_main_sel_op_fee_per_da_gas); \ + [[maybe_unused]] auto avm_main_sel_op_fee_per_l2_gas = View(new_term.avm_main_sel_op_fee_per_l2_gas); \ [[maybe_unused]] auto avm_main_sel_op_lt = View(new_term.avm_main_sel_op_lt); \ [[maybe_unused]] auto avm_main_sel_op_lte = View(new_term.avm_main_sel_op_lte); \ [[maybe_unused]] auto avm_main_sel_op_mul = View(new_term.avm_main_sel_op_mul); \ [[maybe_unused]] auto avm_main_sel_op_not = View(new_term.avm_main_sel_op_not); \ [[maybe_unused]] auto avm_main_sel_op_or = View(new_term.avm_main_sel_op_or); \ + [[maybe_unused]] auto avm_main_sel_op_portal = View(new_term.avm_main_sel_op_portal); \ + [[maybe_unused]] auto avm_main_sel_op_sender = View(new_term.avm_main_sel_op_sender); \ [[maybe_unused]] auto avm_main_sel_op_shl = View(new_term.avm_main_sel_op_shl); \ [[maybe_unused]] auto avm_main_sel_op_shr = View(new_term.avm_main_sel_op_shr); \ [[maybe_unused]] auto avm_main_sel_op_sub = View(new_term.avm_main_sel_op_sub); \ + [[maybe_unused]] auto avm_main_sel_op_timestamp = View(new_term.avm_main_sel_op_timestamp); \ + [[maybe_unused]] auto avm_main_sel_op_transaction_fee = View(new_term.avm_main_sel_op_transaction_fee); \ + [[maybe_unused]] auto avm_main_sel_op_version = View(new_term.avm_main_sel_op_version); \ [[maybe_unused]] auto avm_main_sel_op_xor = View(new_term.avm_main_sel_op_xor); \ [[maybe_unused]] auto avm_main_sel_rng_16 = View(new_term.avm_main_sel_rng_16); \ [[maybe_unused]] auto avm_main_sel_rng_8 = View(new_term.avm_main_sel_rng_8); \ @@ -210,6 +226,7 @@ [[maybe_unused]] auto perm_main_mem_ind_d = View(new_term.perm_main_mem_ind_d); \ [[maybe_unused]] auto lookup_byte_lengths = View(new_term.lookup_byte_lengths); \ [[maybe_unused]] auto lookup_byte_operations = View(new_term.lookup_byte_operations); \ + [[maybe_unused]] auto lookup_into_kernel = View(new_term.lookup_into_kernel); \ [[maybe_unused]] auto incl_main_tag_err = View(new_term.incl_main_tag_err); \ [[maybe_unused]] auto incl_mem_tag_err = View(new_term.incl_mem_tag_err); \ [[maybe_unused]] auto lookup_mem_rng_chk_lo = View(new_term.lookup_mem_rng_chk_lo); \ @@ -243,6 +260,7 @@ [[maybe_unused]] auto lookup_div_u16_7 = View(new_term.lookup_div_u16_7); \ [[maybe_unused]] auto lookup_byte_lengths_counts = View(new_term.lookup_byte_lengths_counts); \ [[maybe_unused]] auto lookup_byte_operations_counts = View(new_term.lookup_byte_operations_counts); \ + [[maybe_unused]] auto lookup_into_kernel_counts = View(new_term.lookup_into_kernel_counts); \ [[maybe_unused]] auto incl_main_tag_err_counts = View(new_term.incl_main_tag_err_counts); \ [[maybe_unused]] auto incl_mem_tag_err_counts = View(new_term.incl_mem_tag_err_counts); \ [[maybe_unused]] auto lookup_mem_rng_chk_lo_counts = View(new_term.lookup_mem_rng_chk_lo_counts); \ diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_into_kernel.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_into_kernel.hpp new file mode 100644 index 00000000000..ac4eae2c174 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_into_kernel.hpp @@ -0,0 +1,171 @@ + + +#pragma once + +#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp" + +#include +#include + +namespace bb { + +/** + * @brief This class contains an example of how to set LookupSettings classes used by the + * GenericLookupRelationImpl class to specify a scaled lookup + * + * @details To create your own lookup: + * 1) Create a copy of this class and rename it + * 2) Update all the values with the ones needed for your lookup + * 3) Update "DECLARE_LOOKUP_IMPLEMENTATIONS_FOR_ALL_SETTINGS" and "DEFINE_LOOKUP_IMPLEMENTATIONS_FOR_ALL_SETTINGS" to + * include the new settings + * 4) Add the relation with the chosen settings to Relations in the flavor (for example,"` + * using Relations = std::tuple>;)` + * + */ +class lookup_into_kernel_lookup_settings { + public: + /** + * @brief The number of read terms (how many lookups we perform) in each row + * + */ + static constexpr size_t READ_TERMS = 1; + /** + * @brief The number of write terms (how many additions to the lookup table we make) in each row + * + */ + static constexpr size_t WRITE_TERMS = 1; + + /** + * @brief The type of READ_TERM used for each read index (basic and scaled) + * + */ + static constexpr size_t READ_TERM_TYPES[READ_TERMS] = { 0 }; + + /** + * @brief They type of WRITE_TERM used for each write index + * + */ + static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = { 0 }; + + /** + * @brief How many values represent a single lookup object. This value is used by the automatic read term + * implementation in the relation in case the lookup is a basic or scaled tuple and in the write term if it's a + * basic tuple + * + */ + static constexpr size_t LOOKUP_TUPLE_SIZE = 2; + + /** + * @brief The polynomial degree of the relation telling us if the inverse polynomial value needs to be computed + * + */ + static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4; + + /** + * @brief The degree of the read term if implemented arbitrarily. This value is not used by basic and scaled read + * terms, but will cause compilation error if not defined + * + */ + static constexpr size_t READ_TERM_DEGREE = 0; + + /** + * @brief The degree of the write term if implemented arbitrarily. This value is not used by the basic write + * term, but will cause compilation error if not defined + * + */ + + static constexpr size_t WRITE_TERM_DEGREE = 0; + + /** + * @brief If this method returns true on a row of values, then the inverse polynomial exists at this index. + * Otherwise the value needs to be set to zero. + * + * @details If this is true then the lookup takes place in this row + * + */ + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in.avm_main_q_kernel_lookup == 1 || in.avm_kernel_q_public_input_kernel_add_to_table == 1); + } + + /** + * @brief Subprocedure for computing the value deciding if the inverse polynomial value needs to be checked in this + * row + * + * @tparam Accumulator Type specified by the lookup relation + * @tparam AllEntities Values/Univariates of all entities row + * @param in Value/Univariate of all entities at row/edge + * @return Accumulator + */ + + template + static inline auto compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + const auto is_operation = View(in.avm_main_q_kernel_lookup); + const auto is_table_entry = View(in.avm_kernel_q_public_input_kernel_add_to_table); + return (is_operation + is_table_entry - is_operation * is_table_entry); + } + + /** + * @brief Get all the entities for the lookup when need to update them + * + * @details The generic structure of this tuple is described in ./generic_lookup_relation.hpp . The following is + description for the current case: + The entities are returned as a tuple of references in the following order (this is for ): + * - The entity/polynomial used to store the product of the inverse values + * - The entity/polynomial that specifies how many times the lookup table entry at this row has been looked up + * - READ_TERMS entities/polynomials that enable individual lookup operations + * - The entity/polynomial that enables adding an entry to the lookup table in this row + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the basic tuple being looked up as the first read term + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the previous accumulators in the second read term + (scaled tuple) + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the shifts in the second read term (scaled tuple) + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the current accumulators in the second read term + (scaled tuple) + * - LOOKUP_TUPLE_SIZE entities/polynomials representing basic tuples added to the table + * + * @return All the entities needed for the lookup + */ + + template static inline auto get_const_entities(const AllEntities& in) + { + + return std::forward_as_tuple(in.lookup_into_kernel, + in.lookup_into_kernel_counts, + in.avm_main_q_kernel_lookup, + in.avm_kernel_q_public_input_kernel_add_to_table, + in.avm_main_ia, + in.avm_kernel_kernel_sel, + in.avm_kernel_kernel_inputs__is_public, + in.avm_main_clk); + } + + /** + * @brief Get all the entities for the lookup when we only need to read them + * @details Same as in get_const_entities, but nonconst + * + * @return All the entities needed for the lookup + */ + + template static inline auto get_nonconst_entities(AllEntities& in) + { + + return std::forward_as_tuple(in.lookup_into_kernel, + in.lookup_into_kernel_counts, + in.avm_main_q_kernel_lookup, + in.avm_kernel_q_public_input_kernel_add_to_table, + in.avm_main_ia, + in.avm_kernel_kernel_sel, + in.avm_kernel_kernel_inputs__is_public, + in.avm_main_clk); + } +}; + +template +using lookup_into_kernel_relation = GenericLookupRelation; +template using lookup_into_kernel = GenericLookup; + +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/spike/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/spike/declare_views.hpp index df901e8d155..290d0a4077e 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/spike/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/spike/declare_views.hpp @@ -3,5 +3,5 @@ using Accumulator = typename std::tuple_element::type; \ using View = typename Accumulator::View; \ [[maybe_unused]] auto Spike_first = View(new_term.Spike_first); \ - [[maybe_unused]] auto Spike_kernel_inputs = View(new_term.Spike_kernel_inputs); \ + [[maybe_unused]] auto Spike_kernel_inputs__is_public = View(new_term.Spike_kernel_inputs__is_public); \ [[maybe_unused]] auto Spike_x = View(new_term.Spike_x); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp index e3c4e90d01b..1dd2eac108a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp @@ -2,6 +2,7 @@ #include "barretenberg/stdlib_circuit_builders/circuit_builder_base.hpp" #include "barretenberg/vm/generated/avm_circuit_builder.hpp" +#include "constants.hpp" #include namespace bb::avm_trace { diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp index c472af776a3..0ebf977df75 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp @@ -55,7 +55,9 @@ bool Execution::verify(AvmFlavor::VerificationKey vk, HonkProof const& proof) // crs_factory_); // output_state.pcs_verification_key = std::move(pcs_verification_key); - return verifier.verify_proof(proof); + // TODO: We hardcode public inputs for now + std::vector public_inputs = {}; + return verifier.verify_proof(proof, public_inputs); } /** diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_kernel_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_kernel_trace.cpp new file mode 100644 index 00000000000..7df78488b35 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_kernel_trace.cpp @@ -0,0 +1,86 @@ +#include "avm_kernel_trace.hpp" +#include "barretenberg/vm/avm_trace/avm_common.hpp" +#include "barretenberg/vm/avm_trace/avm_trace.hpp" +#include "constants.hpp" +#include + +// For the meantime, we do not fire around the public inputs as a vector or otherwise +// Instead we fire them around as a fixed length array from the kernel, as that is how they will be + +namespace bb::avm_trace { + +AvmKernelTraceBuilder::AvmKernelTraceBuilder(std::array kernel_inputs) + : kernel_inputs(kernel_inputs) +{} + +void AvmKernelTraceBuilder::reset() +{ + kernel_selector_counter.clear(); +} + +FF AvmKernelTraceBuilder::perform_kernel_lookup(uint32_t selector) +{ + FF result = kernel_inputs[selector]; + kernel_selector_counter[selector]++; + return result; +} + +// 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_sender() +{ + return perform_kernel_lookup(SENDER_SELECTOR); +} + +FF AvmKernelTraceBuilder::op_address() +{ + return perform_kernel_lookup(ADDRESS_SELECTOR); +} + +FF AvmKernelTraceBuilder::op_portal() +{ + return perform_kernel_lookup(PORTAL_SELECTOR); +} + +FF AvmKernelTraceBuilder::op_fee_per_da_gas() +{ + return perform_kernel_lookup(FEE_PER_DA_GAS_SELECTOR); +} + +FF AvmKernelTraceBuilder::op_fee_per_l2_gas() +{ + return perform_kernel_lookup(FEE_PER_L2_GAS_SELECTOR); +} + +FF AvmKernelTraceBuilder::op_transaction_fee() +{ + return perform_kernel_lookup(TRANSACTION_FEE_SELECTOR); +} + +FF AvmKernelTraceBuilder::op_chain_id() +{ + return perform_kernel_lookup(CHAIN_ID_SELECTOR); +} + +FF AvmKernelTraceBuilder::op_version() +{ + return perform_kernel_lookup(VERSION_SELECTOR); +} + +FF AvmKernelTraceBuilder::op_block_number() +{ + return perform_kernel_lookup(BLOCK_NUMBER_SELECTOR); +} + +FF AvmKernelTraceBuilder::op_coinbase() +{ + return perform_kernel_lookup(COINBASE_SELECTOR); +} + +FF AvmKernelTraceBuilder::op_timestamp() +{ + return perform_kernel_lookup(TIMESTAMP_SELECTOR); +} + +} // namespace bb::avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_kernel_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_kernel_trace.hpp new file mode 100644 index 00000000000..dd06765131b --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_kernel_trace.hpp @@ -0,0 +1,75 @@ +#pragma once + +#include "avm_common.hpp" +#include "barretenberg/numeric/uint128/uint128.hpp" +#include "constants.hpp" +#include +#include + +inline const uint32_t SENDER_SELECTOR = 0; +inline const uint32_t ADDRESS_SELECTOR = 1; +inline const uint32_t PORTAL_SELECTOR = 2; + +inline const uint32_t START_GLOBAL_VARIABLES = CALL_CONTEXT_LENGTH + HEADER_LENGTH; + +inline const uint32_t CHAIN_ID_SELECTOR = START_GLOBAL_VARIABLES; +inline const uint32_t VERSION_SELECTOR = START_GLOBAL_VARIABLES + 1; +inline const uint32_t BLOCK_NUMBER_SELECTOR = START_GLOBAL_VARIABLES + 2; +inline const uint32_t TIMESTAMP_SELECTOR = START_GLOBAL_VARIABLES + 3; +inline const uint32_t COINBASE_SELECTOR = START_GLOBAL_VARIABLES + 4; + +inline const uint32_t END_GLOBAL_VARIABLES = START_GLOBAL_VARIABLES + GLOBAL_VARIABLES_LENGTH; +inline const uint32_t START_SIDE_EFFECT_COUNTER = END_GLOBAL_VARIABLES; + +inline const uint32_t FEE_PER_DA_GAS_SELECTOR = START_SIDE_EFFECT_COUNTER + 1; +inline const uint32_t FEE_PER_L2_GAS_SELECTOR = FEE_PER_DA_GAS_SELECTOR + 1; +inline const uint32_t TRANSACTION_FEE_SELECTOR = FEE_PER_L2_GAS_SELECTOR + 1; + +const std::array KERNEL_INPUTS_SELECTORS = { + SENDER_SELECTOR, ADDRESS_SELECTOR, PORTAL_SELECTOR, FEE_PER_DA_GAS_SELECTOR, + FEE_PER_L2_GAS_SELECTOR, TRANSACTION_FEE_SELECTOR, CHAIN_ID_SELECTOR, VERSION_SELECTOR, + BLOCK_NUMBER_SELECTOR, COINBASE_SELECTOR, TIMESTAMP_SELECTOR +}; + +namespace bb::avm_trace { + +class AvmKernelTraceBuilder { + public: + struct KernelTraceEntry { + uint32_t kernel_selector = 0; + bool q_kernel_lookup = false; + }; + + std::array kernel_inputs{}; + + // Counts the number of accesses into each SELECTOR for the environment selector lookups; + std::unordered_map kernel_selector_counter; + + // Constructor receives copy of kernel_inputs from the main trace builder + AvmKernelTraceBuilder(std::array kernel_inputs); + + void reset(); + + // Context + FF op_sender(); + FF op_address(); + FF op_portal(); + + // Fees + FF op_fee_per_da_gas(); + FF op_fee_per_l2_gas(); + FF op_transaction_fee(); + + // Globals + FF op_chain_id(); + FF op_version(); + FF op_block_number(); + FF op_coinbase(); + FF op_timestamp(); + + private: + std::vector kernel_trace; + + FF perform_kernel_lookup(uint32_t selector); +}; +} // namespace bb::avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp index 6ec6782aa6a..c82f2cbec74 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp @@ -14,6 +14,8 @@ #include "avm_helper.hpp" #include "avm_mem_trace.hpp" #include "avm_trace.hpp" +#include "barretenberg/vm/avm_trace/avm_kernel_trace.hpp" +#include "barretenberg/vm/avm_trace/aztec_constants.hpp" namespace bb::avm_trace { @@ -21,7 +23,9 @@ namespace bb::avm_trace { * @brief Constructor of a trace builder of AVM. Only serves to set the capacity of the * underlying traces. */ -AvmTraceBuilder::AvmTraceBuilder() +AvmTraceBuilder::AvmTraceBuilder(std::array kernel_inputs) + // NOTE: we initialise the environment builder here as it requires public inputs + : kernel_trace_builder(kernel_inputs) { main_trace.reserve(AVM_TRACE_SIZE); } @@ -36,6 +40,7 @@ void AvmTraceBuilder::reset() mem_trace_builder.reset(); alu_trace_builder.reset(); bin_trace_builder.reset(); + kernel_trace_builder.reset(); } AvmTraceBuilder::IndirectThreeResolution AvmTraceBuilder::resolve_ind_three( @@ -1052,6 +1057,128 @@ void AvmTraceBuilder::op_cmov( }); } +// Helper function to add kernel lookup operations into the main trace +Row AvmTraceBuilder::create_kernel_lookup_opcode(uint32_t dst_offset, uint32_t selector, FF value, AvmMemoryTag w_tag) +{ + auto const clk = static_cast(main_trace.size()); + + AvmMemoryTag r_tag = AvmMemoryTag::U0; + mem_trace_builder.write_into_memory(clk, IntermRegister::IA, dst_offset, value, r_tag, w_tag); + + return Row{ + .avm_main_clk = clk, + .avm_kernel_kernel_sel = selector, + .avm_main_ia = value, + .avm_main_ind_a = 0, + .avm_main_internal_return_ptr = internal_return_ptr, + .avm_main_mem_idx_a = dst_offset, + .avm_main_mem_op_a = 1, + .avm_main_pc = pc++, + .avm_main_q_kernel_lookup = 1, + .avm_main_rwa = 1, + .avm_main_w_in_tag = static_cast(w_tag), + }; +} + +void AvmTraceBuilder::op_sender(uint32_t dst_offset) +{ + FF ia_value = kernel_trace_builder.op_sender(); + Row row = create_kernel_lookup_opcode(dst_offset, SENDER_SELECTOR, ia_value, AvmMemoryTag::FF); + row.avm_main_sel_op_sender = FF(1); + + main_trace.push_back(row); +} + +void AvmTraceBuilder::op_address(uint32_t dst_offset) +{ + FF ia_value = kernel_trace_builder.op_address(); + Row row = create_kernel_lookup_opcode(dst_offset, ADDRESS_SELECTOR, ia_value, AvmMemoryTag::FF); + row.avm_main_sel_op_address = FF(1); + + main_trace.push_back(row); +} + +void AvmTraceBuilder::op_portal(uint32_t dst_offset) +{ + FF ia_value = kernel_trace_builder.op_portal(); + Row row = create_kernel_lookup_opcode(dst_offset, PORTAL_SELECTOR, ia_value, AvmMemoryTag::FF); + row.avm_main_sel_op_portal = FF(1); + + main_trace.push_back(row); +} + +void AvmTraceBuilder::op_fee_per_da_gas(uint32_t dst_offset) +{ + FF ia_value = kernel_trace_builder.op_fee_per_da_gas(); + Row row = create_kernel_lookup_opcode(dst_offset, FEE_PER_DA_GAS_SELECTOR, ia_value, AvmMemoryTag::FF); + row.avm_main_sel_op_fee_per_da_gas = FF(1); + + main_trace.push_back(row); +} + +void AvmTraceBuilder::op_fee_per_l2_gas(uint32_t dst_offset) +{ + FF ia_value = kernel_trace_builder.op_fee_per_l2_gas(); + Row row = create_kernel_lookup_opcode(dst_offset, FEE_PER_L2_GAS_SELECTOR, ia_value, AvmMemoryTag::FF); + row.avm_main_sel_op_fee_per_l2_gas = FF(1); + + main_trace.push_back(row); +} + +void AvmTraceBuilder::op_transaction_fee(uint32_t dst_offset) +{ + FF ia_value = kernel_trace_builder.op_transaction_fee(); + Row row = create_kernel_lookup_opcode(dst_offset, TRANSACTION_FEE_SELECTOR, ia_value, AvmMemoryTag::FF); + row.avm_main_sel_op_transaction_fee = FF(1); + + main_trace.push_back(row); +} + +void AvmTraceBuilder::op_chain_id(uint32_t dst_offset) +{ + FF ia_value = kernel_trace_builder.op_chain_id(); + Row row = create_kernel_lookup_opcode(dst_offset, CHAIN_ID_SELECTOR, ia_value, AvmMemoryTag::FF); + row.avm_main_sel_op_chain_id = FF(1); + + main_trace.push_back(row); +} + +void AvmTraceBuilder::op_version(uint32_t dst_offset) +{ + FF ia_value = kernel_trace_builder.op_version(); + Row row = create_kernel_lookup_opcode(dst_offset, VERSION_SELECTOR, ia_value, AvmMemoryTag::FF); + row.avm_main_sel_op_version = FF(1); + + main_trace.push_back(row); +} + +void AvmTraceBuilder::op_block_number(uint32_t dst_offset) +{ + FF ia_value = kernel_trace_builder.op_block_number(); + Row row = create_kernel_lookup_opcode(dst_offset, BLOCK_NUMBER_SELECTOR, ia_value, AvmMemoryTag::FF); + row.avm_main_sel_op_block_number = FF(1); + + main_trace.push_back(row); +} + +void AvmTraceBuilder::op_coinbase(uint32_t dst_offset) +{ + FF ia_value = kernel_trace_builder.op_coinbase(); + Row row = create_kernel_lookup_opcode(dst_offset, COINBASE_SELECTOR, ia_value, AvmMemoryTag::FF); + row.avm_main_sel_op_coinbase = FF(1); + + main_trace.push_back(row); +} + +void AvmTraceBuilder::op_timestamp(uint32_t dst_offset) +{ + FF ia_value = kernel_trace_builder.op_timestamp(); + Row row = create_kernel_lookup_opcode(dst_offset, TIMESTAMP_SELECTOR, ia_value, AvmMemoryTag::U64); + row.avm_main_sel_op_timestamp = FF(1); + + main_trace.push_back(row); +} + /** * @brief Cast an element pointed by the address a_offset into type specified by dst_tag and store the result in address given by dst_offset. @@ -1605,9 +1732,8 @@ std::vector AvmTraceBuilder::finalize() // long) size_t const lookup_table_size = bin_trace_size > 0 ? 3 * (1 << 16) : 0; size_t const range_check_size = range_check_required ? UINT16_MAX + 1 : 0; - std::vector trace_sizes = { - mem_trace_size, main_trace_size, alu_trace_size, lookup_table_size, range_check_size - }; + std::vector trace_sizes = { mem_trace_size, main_trace_size, alu_trace_size, + lookup_table_size, range_check_size, KERNEL_INPUTS_LENGTH }; auto trace_size = std::max_element(trace_sizes.begin(), trace_sizes.end()); // We only need to pad with zeroes to the size to the largest trace here, pow_2 padding is handled in the @@ -1978,6 +2104,21 @@ std::vector AvmTraceBuilder::finalize() } } + // 1. Calculate the lookup counts for each environment access + // 2. Add public inputs into the kernel column + + // We add the lookup counts in the index of the kernel inputs selectors that are active + for (uint32_t selector_index : KERNEL_INPUTS_SELECTORS) { + auto& dest = main_trace.at(selector_index); + dest.lookup_into_kernel_counts = + FF(kernel_trace_builder.kernel_selector_counter[static_cast(selector_index)]); + dest.avm_kernel_q_public_input_kernel_add_to_table = FF(1); + } + + for (size_t i = 0; i < KERNEL_INPUTS_LENGTH; i++) { + main_trace.at(i).avm_kernel_kernel_inputs__is_public = kernel_trace_builder.kernel_inputs.at(i); + } + // Adding extra row for the shifted values at the top of the execution trace. Row first_row = Row{ .avm_main_first = FF(1), .avm_mem_lastAccess = FF(1) }; main_trace.insert(main_trace.begin(), first_row); @@ -1988,4 +2129,4 @@ std::vector AvmTraceBuilder::finalize() return trace; } -} // namespace bb::avm_trace +} // namespace bb::avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp index 88b3ced5578..ebf8cbc5435 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp @@ -8,8 +8,10 @@ #include "avm_instructions.hpp" #include "avm_mem_trace.hpp" #include "barretenberg/common/throw_or_abort.hpp" +#include "constants.hpp" #include "barretenberg/relations/generated/avm/avm_main.hpp" +#include "barretenberg/vm/avm_trace/avm_kernel_trace.hpp" namespace bb::avm_trace { @@ -22,7 +24,7 @@ class AvmTraceBuilder { public: static const size_t CALLSTACK_OFFSET = 896; // TODO(md): Temporary reserved area 896 - 1024 - AvmTraceBuilder(); + AvmTraceBuilder(std::array kernel_inputs = {}); std::vector finalize(); void reset(); @@ -78,6 +80,23 @@ class AvmTraceBuilder { // is determined conditionally based on a conditional value determined by cond_offset. void op_cmov(uint8_t indirect, uint32_t a_offset, uint32_t b_offset, uint32_t cond_offset, uint32_t dst_offset); + // Call Context + void op_sender(uint32_t dst_offset); + void op_address(uint32_t dst_offset); + void op_portal(uint32_t dst_offset); + + // Fees + void op_fee_per_da_gas(uint32_t dst_offset); + void op_fee_per_l2_gas(uint32_t dst_offset); + void op_transaction_fee(uint32_t dst_offset); + + // Globals + void op_chain_id(uint32_t dst_offset); + void op_version(uint32_t dst_offset); + void op_block_number(uint32_t dst_offset); + void op_coinbase(uint32_t dst_offset); + void op_timestamp(uint32_t dst_offset); + // Cast an element pointed by the address a_offset into type specified by dst_tag and // store the result in address given by dst_offset. void op_cast(uint8_t indirect, uint32_t a_offset, uint32_t dst_offset, AvmMemoryTag dst_tag); @@ -129,7 +148,9 @@ class AvmTraceBuilder { AvmMemTraceBuilder mem_trace_builder; AvmAluTraceBuilder alu_trace_builder; AvmBinaryTraceBuilder bin_trace_builder; + AvmKernelTraceBuilder kernel_trace_builder; + Row create_kernel_lookup_opcode(uint32_t dst_offset, uint32_t selector, FF value, AvmMemoryTag w_tag); void finalise_mem_trace_lookup_counts(); IndirectThreeResolution resolve_ind_three( diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp new file mode 100644 index 00000000000..060d6776cb1 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp @@ -0,0 +1,141 @@ +// GENERATED FILE - DO NOT EDIT, RUN yarn remake-constants in circuits.js +#pragma once +#include + +const size_t ARGS_LENGTH = 16; +const size_t MAX_NEW_NOTE_HASHES_PER_CALL = 16; +const size_t MAX_NEW_NULLIFIERS_PER_CALL = 16; +const size_t MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL = 4; +const size_t MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL = 16; +const size_t MAX_NEW_L2_TO_L1_MSGS_PER_CALL = 2; +const size_t MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL = 16; +const size_t MAX_PUBLIC_DATA_READS_PER_CALL = 16; +const size_t MAX_NOTE_HASH_READ_REQUESTS_PER_CALL = 32; +const size_t MAX_NULLIFIER_READ_REQUESTS_PER_CALL = 2; +const size_t MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL = 2; +const size_t MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL = 1; +const size_t MAX_ENCRYPTED_LOGS_PER_CALL = 4; +const size_t MAX_UNENCRYPTED_LOGS_PER_CALL = 4; +const size_t MAX_NEW_NOTE_HASHES_PER_TX = 64; +const size_t MAX_NEW_NULLIFIERS_PER_TX = 64; +const size_t MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX = 8; +const size_t MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX = 32; +const size_t MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX = 32; +const size_t MAX_PUBLIC_DATA_READS_PER_TX = 32; +const size_t MAX_NEW_L2_TO_L1_MSGS_PER_TX = 2; +const size_t MAX_NOTE_HASH_READ_REQUESTS_PER_TX = 128; +const size_t MAX_NULLIFIER_READ_REQUESTS_PER_TX = 8; +const size_t MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX = 8; +const size_t MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 4; +const size_t MAX_ENCRYPTED_LOGS_PER_TX = 8; +const size_t MAX_UNENCRYPTED_LOGS_PER_TX = 8; +const size_t NUM_ENCRYPTED_LOGS_HASHES_PER_TX = 1; +const size_t NUM_UNENCRYPTED_LOGS_HASHES_PER_TX = 1; +const size_t MAX_PUBLIC_DATA_HINTS = 64; +const size_t NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16; +const size_t VK_TREE_HEIGHT = 3; +const size_t FUNCTION_TREE_HEIGHT = 5; +const size_t NOTE_HASH_TREE_HEIGHT = 32; +const size_t PUBLIC_DATA_TREE_HEIGHT = 40; +const size_t NULLIFIER_TREE_HEIGHT = 20; +const size_t L1_TO_L2_MSG_TREE_HEIGHT = 16; +const size_t ROLLUP_VK_TREE_HEIGHT = 8; +const size_t ARTIFACT_FUNCTION_TREE_MAX_HEIGHT = 5; +const size_t NULLIFIER_TREE_ID = 0; +const size_t NOTE_HASH_TREE_ID = 1; +const size_t PUBLIC_DATA_TREE_ID = 2; +const size_t L1_TO_L2_MESSAGE_TREE_ID = 3; +const size_t ARCHIVE_TREE_ID = 4; +const size_t NOTE_HASH_SUBTREE_HEIGHT = 6; +const size_t NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH = 26; +const size_t NULLIFIER_SUBTREE_HEIGHT = 6; +const size_t PUBLIC_DATA_SUBTREE_HEIGHT = 5; +const size_t ARCHIVE_HEIGHT = 16; +const size_t NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH = 14; +const size_t PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH = 35; +const size_t L1_TO_L2_MSG_SUBTREE_HEIGHT = 4; +const size_t L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH = 12; +const size_t FUNCTION_SELECTOR_NUM_BYTES = 4; +const size_t ARGS_HASH_CHUNK_LENGTH = 64; +const size_t ARGS_HASH_CHUNK_COUNT = 64; +const size_t MAX_ARGS_LENGTH = ARGS_HASH_CHUNK_COUNT * ARGS_HASH_CHUNK_LENGTH; +const size_t INITIAL_L2_BLOCK_NUM = 1; +const size_t BLOB_SIZE_IN_BYTES = 31 * 4096; +const size_t NESTED_CALL_L2_GAS_BUFFER = 20000; +const size_t MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 16200; +const size_t MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000; +const size_t MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS = 3000; +const size_t REGISTERER_PRIVATE_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS = 19; +const size_t REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS = 12; +const size_t DEFAULT_MAX_FEE_PER_GAS = 10; +const size_t DEFAULT_INCLUSION_FEE = 0; +const size_t DA_BYTES_PER_FIELD = 32; +const size_t DA_GAS_PER_BYTE = 16; +const size_t FIXED_DA_GAS = 512; +const size_t AZTEC_ADDRESS_LENGTH = 1; +const size_t GAS_FEES_LENGTH = 2; +const size_t GAS_LENGTH = 2; +const size_t GAS_SETTINGS_LENGTH = GAS_LENGTH * 2 + GAS_FEES_LENGTH + /* inclusion_fee */ 1; +const size_t CALL_CONTEXT_LENGTH = 6; +const size_t CONTENT_COMMITMENT_LENGTH = 4; +const size_t CONTRACT_INSTANCE_LENGTH = 5; +const size_t CONTRACT_STORAGE_READ_LENGTH = 2; +const size_t CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 2; +const size_t ETH_ADDRESS_LENGTH = 1; +const size_t FUNCTION_DATA_LENGTH = 2; +const size_t FUNCTION_LEAF_PREIMAGE_LENGTH = 5; +const size_t GLOBAL_VARIABLES_LENGTH = 6 + GAS_FEES_LENGTH; +const size_t APPEND_ONLY_TREE_SNAPSHOT_LENGTH = 2; +const size_t L1_TO_L2_MESSAGE_LENGTH = 6; +const size_t L2_TO_L1_MESSAGE_LENGTH = 2; +const size_t MAX_BLOCK_NUMBER_LENGTH = 2; +const size_t NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH = 3; +const size_t NULLIFIER_KEY_VALIDATION_REQUEST_CONTEXT_LENGTH = 4; +const size_t PARTIAL_STATE_REFERENCE_LENGTH = 6; +const size_t READ_REQUEST_LENGTH = 2; +const size_t NOTE_HASH_LENGTH = 2; +const size_t NOTE_HASH_CONTEXT_LENGTH = 3; +const size_t NULLIFIER_LENGTH = 3; +const size_t SIDE_EFFECT_LENGTH = 2; +const size_t STATE_REFERENCE_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH; +const size_t TX_CONTEXT_LENGTH = 2 + GAS_SETTINGS_LENGTH; +const size_t TX_REQUEST_LENGTH = 2 + TX_CONTEXT_LENGTH + FUNCTION_DATA_LENGTH; +const size_t HEADER_LENGTH = + APPEND_ONLY_TREE_SNAPSHOT_LENGTH + CONTENT_COMMITMENT_LENGTH + STATE_REFERENCE_LENGTH + GLOBAL_VARIABLES_LENGTH; +const size_t PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = + CALL_CONTEXT_LENGTH + 3 + MAX_BLOCK_NUMBER_LENGTH + (READ_REQUEST_LENGTH * MAX_NOTE_HASH_READ_REQUESTS_PER_CALL) + + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + + (NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL) + + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + 1 + + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + + (SIDE_EFFECT_LENGTH * MAX_ENCRYPTED_LOGS_PER_CALL) + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 2 + + HEADER_LENGTH + TX_CONTEXT_LENGTH; +const size_t PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = + CALL_CONTEXT_LENGTH + 2 + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + + (READ_REQUEST_LENGTH * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL) + + (CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL) + + (CONTRACT_STORAGE_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_CALL) + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 1 + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + + AZTEC_ADDRESS_LENGTH + /* revert_code */ 1 + 2 * GAS_LENGTH + /* transaction_fee */ 1; +const size_t PRIVATE_CALL_STACK_ITEM_LENGTH = + AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH; +const size_t PUBLIC_CONTEXT_INPUTS_LENGTH = + CALL_CONTEXT_LENGTH + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + GAS_LENGTH + 2; +const size_t ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH = 2 + FUNCTION_DATA_LENGTH + CALL_CONTEXT_LENGTH; +const size_t GET_NOTES_ORACLE_RETURN_LENGTH = 674; +const size_t NOTE_HASHES_NUM_BYTES_PER_BASE_ROLLUP = 2048; +const size_t NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 2048; +const size_t PUBLIC_DATA_WRITES_NUM_BYTES_PER_BASE_ROLLUP = 2048; +const size_t CONTRACTS_NUM_BYTES_PER_BASE_ROLLUP = 32; +const size_t CONTRACT_DATA_NUM_BYTES_PER_BASE_ROLLUP = 64; +const size_t CONTRACT_DATA_NUM_BYTES_PER_BASE_ROLLUP_UNPADDED = 52; +const size_t L2_TO_L1_MSGS_NUM_BYTES_PER_BASE_ROLLUP = 64; +const size_t LOGS_HASHES_NUM_BYTES_PER_BASE_ROLLUP = 64; +const size_t NUM_MSGS_PER_BASE_PARITY = 4; +const size_t NUM_BASE_PARITY_PER_ROOT_PARITY = 4; +const size_t RECURSIVE_PROOF_LENGTH = 93; +const size_t NESTED_RECURSIVE_PROOF_LENGTH = 109; +const size_t VERIFICATION_KEY_LENGTH_IN_FIELDS = 114; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/constants.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/constants.hpp new file mode 100644 index 00000000000..6b0acc1c3df --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/constants.hpp @@ -0,0 +1,8 @@ +#pragma once +#include "aztec_constants.hpp" +#include + +// NOTE(MD): for now we will only include the public inputs that are included in call_context +// With more being added in subsequent prs +// KERNEL_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + +inline const std::size_t KERNEL_INPUTS_LENGTH = PUBLIC_CONTEXT_INPUTS_LENGTH; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp index f8b40095206..fe495ae8c09 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp @@ -3,6 +3,11 @@ // AUTOGENERATED FILE #pragma once +#include +#ifndef __wasm__ +#include +#endif + #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" @@ -27,6 +32,7 @@ #include "barretenberg/relations/generated/avm/lookup_div_u16_5.hpp" #include "barretenberg/relations/generated/avm/lookup_div_u16_6.hpp" #include "barretenberg/relations/generated/avm/lookup_div_u16_7.hpp" +#include "barretenberg/relations/generated/avm/lookup_into_kernel.hpp" #include "barretenberg/relations/generated/avm/lookup_mem_rng_chk_hi.hpp" #include "barretenberg/relations/generated/avm/lookup_mem_rng_chk_lo.hpp" #include "barretenberg/relations/generated/avm/lookup_pow_2_0.hpp" @@ -168,6 +174,9 @@ template struct AvmFullRow { FF avm_byte_lookup_table_input_b{}; FF avm_byte_lookup_table_op_id{}; FF avm_byte_lookup_table_output{}; + FF avm_kernel_kernel_inputs__is_public{}; + FF avm_kernel_kernel_sel{}; + FF avm_kernel_q_public_input_kernel_add_to_table{}; FF avm_main_alu_in_tag{}; FF avm_main_alu_sel{}; FF avm_main_bin_op_id{}; @@ -198,6 +207,7 @@ template struct AvmFullRow { FF avm_main_mem_op_d{}; FF avm_main_op_err{}; FF avm_main_pc{}; + FF avm_main_q_kernel_lookup{}; FF avm_main_r_in_tag{}; FF avm_main_rwa{}; FF avm_main_rwb{}; @@ -212,19 +222,30 @@ template struct AvmFullRow { FF avm_main_sel_mov_a{}; FF avm_main_sel_mov_b{}; FF avm_main_sel_op_add{}; + FF avm_main_sel_op_address{}; FF avm_main_sel_op_and{}; + FF avm_main_sel_op_block_number{}; FF avm_main_sel_op_cast{}; + FF avm_main_sel_op_chain_id{}; + FF avm_main_sel_op_coinbase{}; FF avm_main_sel_op_div{}; FF avm_main_sel_op_eq{}; FF avm_main_sel_op_fdiv{}; + FF avm_main_sel_op_fee_per_da_gas{}; + FF avm_main_sel_op_fee_per_l2_gas{}; FF avm_main_sel_op_lt{}; FF avm_main_sel_op_lte{}; FF avm_main_sel_op_mul{}; FF avm_main_sel_op_not{}; FF avm_main_sel_op_or{}; + FF avm_main_sel_op_portal{}; + FF avm_main_sel_op_sender{}; FF avm_main_sel_op_shl{}; FF avm_main_sel_op_shr{}; FF avm_main_sel_op_sub{}; + FF avm_main_sel_op_timestamp{}; + FF avm_main_sel_op_transaction_fee{}; + FF avm_main_sel_op_version{}; FF avm_main_sel_op_xor{}; FF avm_main_sel_rng_16{}; FF avm_main_sel_rng_8{}; @@ -271,6 +292,7 @@ template struct AvmFullRow { FF perm_main_mem_ind_d{}; FF lookup_byte_lengths{}; FF lookup_byte_operations{}; + FF lookup_into_kernel{}; FF incl_main_tag_err{}; FF incl_mem_tag_err{}; FF lookup_mem_rng_chk_lo{}; @@ -304,6 +326,7 @@ template struct AvmFullRow { FF lookup_div_u16_7{}; FF lookup_byte_lengths_counts{}; FF lookup_byte_operations_counts{}; + FF lookup_into_kernel_counts{}; FF incl_main_tag_err_counts{}; FF incl_mem_tag_err_counts{}; FF lookup_mem_rng_chk_lo_counts{}; @@ -399,8 +422,8 @@ class AvmCircuitBuilder { using Polynomial = Flavor::Polynomial; using ProverPolynomials = Flavor::ProverPolynomials; - static constexpr size_t num_fixed_columns = 324; - static constexpr size_t num_polys = 272; + static constexpr size_t num_fixed_columns = 341; + static constexpr size_t num_polys = 289; std::vector rows; void set_trace(std::vector&& trace) { rows = std::move(trace); } @@ -521,6 +544,10 @@ class AvmCircuitBuilder { polys.avm_byte_lookup_table_input_b[i] = rows[i].avm_byte_lookup_table_input_b; polys.avm_byte_lookup_table_op_id[i] = rows[i].avm_byte_lookup_table_op_id; polys.avm_byte_lookup_table_output[i] = rows[i].avm_byte_lookup_table_output; + polys.avm_kernel_kernel_inputs__is_public[i] = rows[i].avm_kernel_kernel_inputs__is_public; + polys.avm_kernel_kernel_sel[i] = rows[i].avm_kernel_kernel_sel; + polys.avm_kernel_q_public_input_kernel_add_to_table[i] = + rows[i].avm_kernel_q_public_input_kernel_add_to_table; polys.avm_main_alu_in_tag[i] = rows[i].avm_main_alu_in_tag; polys.avm_main_alu_sel[i] = rows[i].avm_main_alu_sel; polys.avm_main_bin_op_id[i] = rows[i].avm_main_bin_op_id; @@ -551,6 +578,7 @@ class AvmCircuitBuilder { polys.avm_main_mem_op_d[i] = rows[i].avm_main_mem_op_d; polys.avm_main_op_err[i] = rows[i].avm_main_op_err; polys.avm_main_pc[i] = rows[i].avm_main_pc; + polys.avm_main_q_kernel_lookup[i] = rows[i].avm_main_q_kernel_lookup; polys.avm_main_r_in_tag[i] = rows[i].avm_main_r_in_tag; polys.avm_main_rwa[i] = rows[i].avm_main_rwa; polys.avm_main_rwb[i] = rows[i].avm_main_rwb; @@ -565,19 +593,30 @@ class AvmCircuitBuilder { polys.avm_main_sel_mov_a[i] = rows[i].avm_main_sel_mov_a; polys.avm_main_sel_mov_b[i] = rows[i].avm_main_sel_mov_b; polys.avm_main_sel_op_add[i] = rows[i].avm_main_sel_op_add; + polys.avm_main_sel_op_address[i] = rows[i].avm_main_sel_op_address; polys.avm_main_sel_op_and[i] = rows[i].avm_main_sel_op_and; + polys.avm_main_sel_op_block_number[i] = rows[i].avm_main_sel_op_block_number; polys.avm_main_sel_op_cast[i] = rows[i].avm_main_sel_op_cast; + polys.avm_main_sel_op_chain_id[i] = rows[i].avm_main_sel_op_chain_id; + polys.avm_main_sel_op_coinbase[i] = rows[i].avm_main_sel_op_coinbase; polys.avm_main_sel_op_div[i] = rows[i].avm_main_sel_op_div; polys.avm_main_sel_op_eq[i] = rows[i].avm_main_sel_op_eq; polys.avm_main_sel_op_fdiv[i] = rows[i].avm_main_sel_op_fdiv; + polys.avm_main_sel_op_fee_per_da_gas[i] = rows[i].avm_main_sel_op_fee_per_da_gas; + polys.avm_main_sel_op_fee_per_l2_gas[i] = rows[i].avm_main_sel_op_fee_per_l2_gas; polys.avm_main_sel_op_lt[i] = rows[i].avm_main_sel_op_lt; polys.avm_main_sel_op_lte[i] = rows[i].avm_main_sel_op_lte; polys.avm_main_sel_op_mul[i] = rows[i].avm_main_sel_op_mul; polys.avm_main_sel_op_not[i] = rows[i].avm_main_sel_op_not; polys.avm_main_sel_op_or[i] = rows[i].avm_main_sel_op_or; + polys.avm_main_sel_op_portal[i] = rows[i].avm_main_sel_op_portal; + polys.avm_main_sel_op_sender[i] = rows[i].avm_main_sel_op_sender; polys.avm_main_sel_op_shl[i] = rows[i].avm_main_sel_op_shl; polys.avm_main_sel_op_shr[i] = rows[i].avm_main_sel_op_shr; polys.avm_main_sel_op_sub[i] = rows[i].avm_main_sel_op_sub; + polys.avm_main_sel_op_timestamp[i] = rows[i].avm_main_sel_op_timestamp; + polys.avm_main_sel_op_transaction_fee[i] = rows[i].avm_main_sel_op_transaction_fee; + polys.avm_main_sel_op_version[i] = rows[i].avm_main_sel_op_version; polys.avm_main_sel_op_xor[i] = rows[i].avm_main_sel_op_xor; polys.avm_main_sel_rng_16[i] = rows[i].avm_main_sel_rng_16; polys.avm_main_sel_rng_8[i] = rows[i].avm_main_sel_rng_8; @@ -614,6 +653,7 @@ class AvmCircuitBuilder { polys.avm_mem_w_in_tag[i] = rows[i].avm_mem_w_in_tag; polys.lookup_byte_lengths_counts[i] = rows[i].lookup_byte_lengths_counts; polys.lookup_byte_operations_counts[i] = rows[i].lookup_byte_operations_counts; + polys.lookup_into_kernel_counts[i] = rows[i].lookup_into_kernel_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; @@ -770,153 +810,412 @@ class AvmCircuitBuilder { return true; }; - if (!evaluate_relation.template operator()>("avm_alu", - Avm_vm::get_relation_label_avm_alu)) { - return false; - } - if (!evaluate_relation.template operator()>("avm_binary", - Avm_vm::get_relation_label_avm_binary)) { - return false; - } - if (!evaluate_relation.template operator()>("avm_main", - Avm_vm::get_relation_label_avm_main)) { - return false; - } - if (!evaluate_relation.template operator()>("avm_mem", - Avm_vm::get_relation_label_avm_mem)) { - return false; - } + auto avm_alu = [=]() { + return evaluate_relation.template operator()>("avm_alu", + Avm_vm::get_relation_label_avm_alu); + }; - if (!evaluate_logderivative.template operator()>("PERM_MAIN_ALU")) { - return false; - } - if (!evaluate_logderivative.template operator()>("PERM_MAIN_BIN")) { - return false; - } - if (!evaluate_logderivative.template operator()>("PERM_MAIN_MEM_A")) { - return false; - } - if (!evaluate_logderivative.template operator()>("PERM_MAIN_MEM_B")) { - return false; - } - if (!evaluate_logderivative.template operator()>("PERM_MAIN_MEM_C")) { - return false; - } - if (!evaluate_logderivative.template operator()>("PERM_MAIN_MEM_D")) { - return false; - } - if (!evaluate_logderivative.template operator()>("PERM_MAIN_MEM_IND_A")) { - return false; - } - if (!evaluate_logderivative.template operator()>("PERM_MAIN_MEM_IND_B")) { - return false; - } - if (!evaluate_logderivative.template operator()>("PERM_MAIN_MEM_IND_C")) { - return false; - } - if (!evaluate_logderivative.template operator()>("PERM_MAIN_MEM_IND_D")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_BYTE_LENGTHS")) { - return false; - } - if (!evaluate_logderivative.template operator()>( - "LOOKUP_BYTE_OPERATIONS")) { - return false; - } - if (!evaluate_logderivative.template operator()>("INCL_MAIN_TAG_ERR")) { - return false; - } - if (!evaluate_logderivative.template operator()>("INCL_MEM_TAG_ERR")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_MEM_RNG_CHK_LO")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_MEM_RNG_CHK_HI")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_POW_2_0")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_POW_2_1")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U8_0")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U8_1")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_0")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_1")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_2")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_3")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_4")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_5")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_6")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_7")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_8")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_9")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_10")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_11")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_12")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_13")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_U16_14")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_0")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_1")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_2")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_3")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_4")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_5")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_6")) { - return false; - } - if (!evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_7")) { - return false; + auto avm_binary = [=]() { + return evaluate_relation.template operator()>("avm_binary", + Avm_vm::get_relation_label_avm_binary); + }; + + auto avm_main = [=]() { + return evaluate_relation.template operator()>("avm_main", + Avm_vm::get_relation_label_avm_main); + }; + + auto avm_mem = [=]() { + return evaluate_relation.template operator()>("avm_mem", + Avm_vm::get_relation_label_avm_mem); + }; + + auto perm_main_alu = [=]() { + return evaluate_logderivative.template operator()>("PERM_MAIN_ALU"); + }; + + auto perm_main_bin = [=]() { + return evaluate_logderivative.template operator()>("PERM_MAIN_BIN"); + }; + + auto perm_main_mem_a = [=]() { + return evaluate_logderivative.template operator()>("PERM_MAIN_MEM_A"); + }; + + auto perm_main_mem_b = [=]() { + return evaluate_logderivative.template operator()>("PERM_MAIN_MEM_B"); + }; + + auto perm_main_mem_c = [=]() { + return evaluate_logderivative.template operator()>("PERM_MAIN_MEM_C"); + }; + + auto perm_main_mem_d = [=]() { + return evaluate_logderivative.template operator()>("PERM_MAIN_MEM_D"); + }; + + auto perm_main_mem_ind_a = [=]() { + return evaluate_logderivative.template operator()>("PERM_MAIN_MEM_IND_A"); + }; + + auto perm_main_mem_ind_b = [=]() { + return evaluate_logderivative.template operator()>("PERM_MAIN_MEM_IND_B"); + }; + + auto perm_main_mem_ind_c = [=]() { + return evaluate_logderivative.template operator()>("PERM_MAIN_MEM_IND_C"); + }; + + auto perm_main_mem_ind_d = [=]() { + return evaluate_logderivative.template operator()>("PERM_MAIN_MEM_IND_D"); + }; + + auto lookup_byte_lengths = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_BYTE_LENGTHS"); + }; + + auto lookup_byte_operations = [=]() { + return evaluate_logderivative.template operator()>( + "LOOKUP_BYTE_OPERATIONS"); + }; + + auto lookup_into_kernel = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_INTO_KERNEL"); + }; + + auto incl_main_tag_err = [=]() { + return evaluate_logderivative.template operator()>("INCL_MAIN_TAG_ERR"); + }; + + auto incl_mem_tag_err = [=]() { + return evaluate_logderivative.template operator()>("INCL_MEM_TAG_ERR"); + }; + + auto lookup_mem_rng_chk_lo = [=]() { + return evaluate_logderivative.template operator()>( + "LOOKUP_MEM_RNG_CHK_LO"); + }; + + auto lookup_mem_rng_chk_hi = [=]() { + return evaluate_logderivative.template operator()>( + "LOOKUP_MEM_RNG_CHK_HI"); + }; + + auto lookup_pow_2_0 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_POW_2_0"); + }; + + auto lookup_pow_2_1 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_POW_2_1"); + }; + + auto lookup_u8_0 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U8_0"); + }; + + auto lookup_u8_1 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U8_1"); + }; + + auto lookup_u16_0 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_0"); + }; + + auto lookup_u16_1 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_1"); + }; + + auto lookup_u16_2 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_2"); + }; + + auto lookup_u16_3 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_3"); + }; + + auto lookup_u16_4 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_4"); + }; + + auto lookup_u16_5 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_5"); + }; + + auto lookup_u16_6 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_6"); + }; + + auto lookup_u16_7 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_7"); + }; + + auto lookup_u16_8 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_8"); + }; + + auto lookup_u16_9 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_9"); + }; + + auto lookup_u16_10 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_10"); + }; + + auto lookup_u16_11 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_11"); + }; + + auto lookup_u16_12 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_12"); + }; + + auto lookup_u16_13 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_13"); + }; + + auto lookup_u16_14 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_U16_14"); + }; + + auto lookup_div_u16_0 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_0"); + }; + + auto lookup_div_u16_1 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_1"); + }; + + auto lookup_div_u16_2 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_2"); + }; + + auto lookup_div_u16_3 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_3"); + }; + + auto lookup_div_u16_4 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_4"); + }; + + auto lookup_div_u16_5 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_5"); + }; + + auto lookup_div_u16_6 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_6"); + }; + + auto lookup_div_u16_7 = [=]() { + return evaluate_logderivative.template operator()>("LOOKUP_DIV_U16_7"); + }; + +#ifndef __wasm__ + + // Evaluate check circuit closures as futures + std::vector> relation_futures; + + relation_futures.emplace_back(std::async(std::launch::async, avm_alu)); + + relation_futures.emplace_back(std::async(std::launch::async, avm_binary)); + + relation_futures.emplace_back(std::async(std::launch::async, avm_main)); + + relation_futures.emplace_back(std::async(std::launch::async, avm_mem)); + + relation_futures.emplace_back(std::async(std::launch::async, perm_main_alu)); + + relation_futures.emplace_back(std::async(std::launch::async, perm_main_bin)); + + relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_a)); + + relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_b)); + + relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_c)); + + relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_d)); + + relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_ind_a)); + + relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_ind_b)); + + relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_ind_c)); + + relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_ind_d)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_byte_lengths)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_byte_operations)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_into_kernel)); + + relation_futures.emplace_back(std::async(std::launch::async, incl_main_tag_err)); + + relation_futures.emplace_back(std::async(std::launch::async, incl_mem_tag_err)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_mem_rng_chk_lo)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_mem_rng_chk_hi)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_pow_2_0)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_pow_2_1)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u8_0)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u8_1)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_0)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_1)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_2)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_3)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_4)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_5)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_6)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_7)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_8)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_9)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_10)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_11)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_12)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_13)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_u16_14)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_div_u16_0)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_div_u16_1)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_div_u16_2)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_div_u16_3)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_div_u16_4)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_div_u16_5)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_div_u16_6)); + + relation_futures.emplace_back(std::async(std::launch::async, lookup_div_u16_7)); + + // Wait for lookup evaluations to complete + for (auto& future : relation_futures) { + int result = future.get(); + if (!result) { + return false; + } } +#else + + avm_alu(); + + avm_binary(); + + avm_main(); + + avm_mem(); + + perm_main_alu(); + + perm_main_bin(); + + perm_main_mem_a(); + + perm_main_mem_b(); + + perm_main_mem_c(); + + perm_main_mem_d(); + + perm_main_mem_ind_a(); + + perm_main_mem_ind_b(); + + perm_main_mem_ind_c(); + + perm_main_mem_ind_d(); + + lookup_byte_lengths(); + + lookup_byte_operations(); + + lookup_into_kernel(); + + incl_main_tag_err(); + + incl_mem_tag_err(); + + lookup_mem_rng_chk_lo(); + + lookup_mem_rng_chk_hi(); + + lookup_pow_2_0(); + + lookup_pow_2_1(); + + lookup_u8_0(); + + lookup_u8_1(); + + lookup_u16_0(); + + lookup_u16_1(); + + lookup_u16_2(); + + lookup_u16_3(); + + lookup_u16_4(); + + lookup_u16_5(); + + lookup_u16_6(); + + lookup_u16_7(); + + lookup_u16_8(); + + lookup_u16_9(); + + lookup_u16_10(); + + lookup_u16_11(); + + lookup_u16_12(); + + lookup_u16_13(); + + lookup_u16_14(); + + lookup_div_u16_0(); + + lookup_div_u16_1(); + + lookup_div_u16_2(); + + lookup_div_u16_3(); + + lookup_div_u16_4(); + + lookup_div_u16_5(); + + lookup_div_u16_6(); + + lookup_div_u16_7(); + +#endif return true; } diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp index bb97c6808e4..bf208bc727e 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp @@ -29,6 +29,7 @@ #include "barretenberg/relations/generated/avm/lookup_div_u16_5.hpp" #include "barretenberg/relations/generated/avm/lookup_div_u16_6.hpp" #include "barretenberg/relations/generated/avm/lookup_div_u16_7.hpp" +#include "barretenberg/relations/generated/avm/lookup_into_kernel.hpp" #include "barretenberg/relations/generated/avm/lookup_mem_rng_chk_hi.hpp" #include "barretenberg/relations/generated/avm/lookup_mem_rng_chk_lo.hpp" #include "barretenberg/relations/generated/avm/lookup_pow_2_0.hpp" @@ -81,11 +82,11 @@ class AvmFlavor { using RelationSeparator = FF; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; - static constexpr size_t NUM_WITNESS_ENTITIES = 270; + static constexpr size_t NUM_WITNESS_ENTITIES = 287; static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES; // We have two copies of the witness entities, so we subtract the number of fixed ones (they have no shift), one for // the unshifted and one for the shifted - static constexpr size_t NUM_ALL_ENTITIES = 324; + static constexpr size_t NUM_ALL_ENTITIES = 341; using GrandProductRelations = std::tuple, perm_main_bin_relation, @@ -99,6 +100,7 @@ class AvmFlavor { perm_main_mem_ind_d_relation, lookup_byte_lengths_relation, lookup_byte_operations_relation, + lookup_into_kernel_relation, incl_main_tag_err_relation, incl_mem_tag_err_relation, lookup_mem_rng_chk_lo_relation, @@ -147,6 +149,7 @@ class AvmFlavor { perm_main_mem_ind_d_relation, lookup_byte_lengths_relation, lookup_byte_operations_relation, + lookup_into_kernel_relation, incl_main_tag_err_relation, incl_mem_tag_err_relation, lookup_mem_rng_chk_lo_relation, @@ -314,6 +317,9 @@ class AvmFlavor { avm_byte_lookup_table_input_b, avm_byte_lookup_table_op_id, avm_byte_lookup_table_output, + avm_kernel_kernel_inputs__is_public, + avm_kernel_kernel_sel, + avm_kernel_q_public_input_kernel_add_to_table, avm_main_alu_in_tag, avm_main_alu_sel, avm_main_bin_op_id, @@ -344,6 +350,7 @@ class AvmFlavor { avm_main_mem_op_d, avm_main_op_err, avm_main_pc, + avm_main_q_kernel_lookup, avm_main_r_in_tag, avm_main_rwa, avm_main_rwb, @@ -358,19 +365,30 @@ class AvmFlavor { avm_main_sel_mov_a, avm_main_sel_mov_b, avm_main_sel_op_add, + avm_main_sel_op_address, avm_main_sel_op_and, + avm_main_sel_op_block_number, avm_main_sel_op_cast, + avm_main_sel_op_chain_id, + avm_main_sel_op_coinbase, avm_main_sel_op_div, avm_main_sel_op_eq, avm_main_sel_op_fdiv, + avm_main_sel_op_fee_per_da_gas, + avm_main_sel_op_fee_per_l2_gas, avm_main_sel_op_lt, avm_main_sel_op_lte, avm_main_sel_op_mul, avm_main_sel_op_not, avm_main_sel_op_or, + avm_main_sel_op_portal, + avm_main_sel_op_sender, avm_main_sel_op_shl, avm_main_sel_op_shr, avm_main_sel_op_sub, + avm_main_sel_op_timestamp, + avm_main_sel_op_transaction_fee, + avm_main_sel_op_version, avm_main_sel_op_xor, avm_main_sel_rng_16, avm_main_sel_rng_8, @@ -417,6 +435,7 @@ class AvmFlavor { perm_main_mem_ind_d, lookup_byte_lengths, lookup_byte_operations, + lookup_into_kernel, incl_main_tag_err, incl_mem_tag_err, lookup_mem_rng_chk_lo, @@ -450,6 +469,7 @@ class AvmFlavor { lookup_div_u16_7, lookup_byte_lengths_counts, lookup_byte_operations_counts, + lookup_into_kernel_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts, lookup_mem_rng_chk_lo_counts, @@ -587,6 +607,9 @@ class AvmFlavor { avm_byte_lookup_table_input_b, avm_byte_lookup_table_op_id, avm_byte_lookup_table_output, + avm_kernel_kernel_inputs__is_public, + avm_kernel_kernel_sel, + avm_kernel_q_public_input_kernel_add_to_table, avm_main_alu_in_tag, avm_main_alu_sel, avm_main_bin_op_id, @@ -617,6 +640,7 @@ class AvmFlavor { avm_main_mem_op_d, avm_main_op_err, avm_main_pc, + avm_main_q_kernel_lookup, avm_main_r_in_tag, avm_main_rwa, avm_main_rwb, @@ -631,19 +655,30 @@ class AvmFlavor { avm_main_sel_mov_a, avm_main_sel_mov_b, avm_main_sel_op_add, + avm_main_sel_op_address, avm_main_sel_op_and, + avm_main_sel_op_block_number, avm_main_sel_op_cast, + avm_main_sel_op_chain_id, + avm_main_sel_op_coinbase, avm_main_sel_op_div, avm_main_sel_op_eq, avm_main_sel_op_fdiv, + avm_main_sel_op_fee_per_da_gas, + avm_main_sel_op_fee_per_l2_gas, avm_main_sel_op_lt, avm_main_sel_op_lte, avm_main_sel_op_mul, avm_main_sel_op_not, avm_main_sel_op_or, + avm_main_sel_op_portal, + avm_main_sel_op_sender, avm_main_sel_op_shl, avm_main_sel_op_shr, avm_main_sel_op_sub, + avm_main_sel_op_timestamp, + avm_main_sel_op_transaction_fee, + avm_main_sel_op_version, avm_main_sel_op_xor, avm_main_sel_rng_16, avm_main_sel_rng_8, @@ -690,6 +725,7 @@ class AvmFlavor { perm_main_mem_ind_d, lookup_byte_lengths, lookup_byte_operations, + lookup_into_kernel, incl_main_tag_err, incl_mem_tag_err, lookup_mem_rng_chk_lo, @@ -723,6 +759,7 @@ class AvmFlavor { lookup_div_u16_7, lookup_byte_lengths_counts, lookup_byte_operations_counts, + lookup_into_kernel_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts, lookup_mem_rng_chk_lo_counts, @@ -865,6 +902,9 @@ class AvmFlavor { avm_byte_lookup_table_input_b, avm_byte_lookup_table_op_id, avm_byte_lookup_table_output, + avm_kernel_kernel_inputs__is_public, + avm_kernel_kernel_sel, + avm_kernel_q_public_input_kernel_add_to_table, avm_main_alu_in_tag, avm_main_alu_sel, avm_main_bin_op_id, @@ -895,6 +935,7 @@ class AvmFlavor { avm_main_mem_op_d, avm_main_op_err, avm_main_pc, + avm_main_q_kernel_lookup, avm_main_r_in_tag, avm_main_rwa, avm_main_rwb, @@ -909,19 +950,30 @@ class AvmFlavor { avm_main_sel_mov_a, avm_main_sel_mov_b, avm_main_sel_op_add, + avm_main_sel_op_address, avm_main_sel_op_and, + avm_main_sel_op_block_number, avm_main_sel_op_cast, + avm_main_sel_op_chain_id, + avm_main_sel_op_coinbase, avm_main_sel_op_div, avm_main_sel_op_eq, avm_main_sel_op_fdiv, + avm_main_sel_op_fee_per_da_gas, + avm_main_sel_op_fee_per_l2_gas, avm_main_sel_op_lt, avm_main_sel_op_lte, avm_main_sel_op_mul, avm_main_sel_op_not, avm_main_sel_op_or, + avm_main_sel_op_portal, + avm_main_sel_op_sender, avm_main_sel_op_shl, avm_main_sel_op_shr, avm_main_sel_op_sub, + avm_main_sel_op_timestamp, + avm_main_sel_op_transaction_fee, + avm_main_sel_op_version, avm_main_sel_op_xor, avm_main_sel_rng_16, avm_main_sel_rng_8, @@ -968,6 +1020,7 @@ class AvmFlavor { perm_main_mem_ind_d, lookup_byte_lengths, lookup_byte_operations, + lookup_into_kernel, incl_main_tag_err, incl_mem_tag_err, lookup_mem_rng_chk_lo, @@ -1001,6 +1054,7 @@ class AvmFlavor { lookup_div_u16_7, lookup_byte_lengths_counts, lookup_byte_operations_counts, + lookup_into_kernel_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts, lookup_mem_rng_chk_lo_counts, @@ -1192,6 +1246,9 @@ class AvmFlavor { avm_byte_lookup_table_input_b, avm_byte_lookup_table_op_id, avm_byte_lookup_table_output, + avm_kernel_kernel_inputs__is_public, + avm_kernel_kernel_sel, + avm_kernel_q_public_input_kernel_add_to_table, avm_main_alu_in_tag, avm_main_alu_sel, avm_main_bin_op_id, @@ -1222,6 +1279,7 @@ class AvmFlavor { avm_main_mem_op_d, avm_main_op_err, avm_main_pc, + avm_main_q_kernel_lookup, avm_main_r_in_tag, avm_main_rwa, avm_main_rwb, @@ -1236,19 +1294,30 @@ class AvmFlavor { avm_main_sel_mov_a, avm_main_sel_mov_b, avm_main_sel_op_add, + avm_main_sel_op_address, avm_main_sel_op_and, + avm_main_sel_op_block_number, avm_main_sel_op_cast, + avm_main_sel_op_chain_id, + avm_main_sel_op_coinbase, avm_main_sel_op_div, avm_main_sel_op_eq, avm_main_sel_op_fdiv, + avm_main_sel_op_fee_per_da_gas, + avm_main_sel_op_fee_per_l2_gas, avm_main_sel_op_lt, avm_main_sel_op_lte, avm_main_sel_op_mul, avm_main_sel_op_not, avm_main_sel_op_or, + avm_main_sel_op_portal, + avm_main_sel_op_sender, avm_main_sel_op_shl, avm_main_sel_op_shr, avm_main_sel_op_sub, + avm_main_sel_op_timestamp, + avm_main_sel_op_transaction_fee, + avm_main_sel_op_version, avm_main_sel_op_xor, avm_main_sel_rng_16, avm_main_sel_rng_8, @@ -1295,6 +1364,7 @@ class AvmFlavor { perm_main_mem_ind_d, lookup_byte_lengths, lookup_byte_operations, + lookup_into_kernel, incl_main_tag_err, incl_mem_tag_err, lookup_mem_rng_chk_lo, @@ -1328,6 +1398,7 @@ class AvmFlavor { lookup_div_u16_7, lookup_byte_lengths_counts, lookup_byte_operations_counts, + lookup_into_kernel_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts, lookup_mem_rng_chk_lo_counts, @@ -1519,6 +1590,9 @@ class AvmFlavor { avm_byte_lookup_table_input_b, avm_byte_lookup_table_op_id, avm_byte_lookup_table_output, + avm_kernel_kernel_inputs__is_public, + avm_kernel_kernel_sel, + avm_kernel_q_public_input_kernel_add_to_table, avm_main_alu_in_tag, avm_main_alu_sel, avm_main_bin_op_id, @@ -1549,6 +1623,7 @@ class AvmFlavor { avm_main_mem_op_d, avm_main_op_err, avm_main_pc, + avm_main_q_kernel_lookup, avm_main_r_in_tag, avm_main_rwa, avm_main_rwb, @@ -1563,19 +1638,30 @@ class AvmFlavor { avm_main_sel_mov_a, avm_main_sel_mov_b, avm_main_sel_op_add, + avm_main_sel_op_address, avm_main_sel_op_and, + avm_main_sel_op_block_number, avm_main_sel_op_cast, + avm_main_sel_op_chain_id, + avm_main_sel_op_coinbase, avm_main_sel_op_div, avm_main_sel_op_eq, avm_main_sel_op_fdiv, + avm_main_sel_op_fee_per_da_gas, + avm_main_sel_op_fee_per_l2_gas, avm_main_sel_op_lt, avm_main_sel_op_lte, avm_main_sel_op_mul, avm_main_sel_op_not, avm_main_sel_op_or, + avm_main_sel_op_portal, + avm_main_sel_op_sender, avm_main_sel_op_shl, avm_main_sel_op_shr, avm_main_sel_op_sub, + avm_main_sel_op_timestamp, + avm_main_sel_op_transaction_fee, + avm_main_sel_op_version, avm_main_sel_op_xor, avm_main_sel_rng_16, avm_main_sel_rng_8, @@ -1622,6 +1708,7 @@ class AvmFlavor { perm_main_mem_ind_d, lookup_byte_lengths, lookup_byte_operations, + lookup_into_kernel, incl_main_tag_err, incl_mem_tag_err, lookup_mem_rng_chk_lo, @@ -1655,6 +1742,7 @@ class AvmFlavor { lookup_div_u16_7, lookup_byte_lengths_counts, lookup_byte_operations_counts, + lookup_into_kernel_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts, lookup_mem_rng_chk_lo_counts, @@ -1891,6 +1979,8 @@ class AvmFlavor { prover_polynomials, relation_parameters, this->circuit_size); bb::compute_logderivative_inverse>( prover_polynomials, relation_parameters, this->circuit_size); + bb::compute_logderivative_inverse>( + prover_polynomials, relation_parameters, this->circuit_size); bb::compute_logderivative_inverse>( prover_polynomials, relation_parameters, this->circuit_size); bb::compute_logderivative_inverse>( @@ -2158,6 +2248,9 @@ class AvmFlavor { Base::avm_byte_lookup_table_input_b = "AVM_BYTE_LOOKUP_TABLE_INPUT_B"; Base::avm_byte_lookup_table_op_id = "AVM_BYTE_LOOKUP_TABLE_OP_ID"; Base::avm_byte_lookup_table_output = "AVM_BYTE_LOOKUP_TABLE_OUTPUT"; + Base::avm_kernel_kernel_inputs__is_public = "AVM_KERNEL_KERNEL_INPUTS__IS_PUBLIC"; + Base::avm_kernel_kernel_sel = "AVM_KERNEL_KERNEL_SEL"; + Base::avm_kernel_q_public_input_kernel_add_to_table = "AVM_KERNEL_Q_PUBLIC_INPUT_KERNEL_ADD_TO_TABLE"; Base::avm_main_alu_in_tag = "AVM_MAIN_ALU_IN_TAG"; Base::avm_main_alu_sel = "AVM_MAIN_ALU_SEL"; Base::avm_main_bin_op_id = "AVM_MAIN_BIN_OP_ID"; @@ -2188,6 +2281,7 @@ class AvmFlavor { Base::avm_main_mem_op_d = "AVM_MAIN_MEM_OP_D"; Base::avm_main_op_err = "AVM_MAIN_OP_ERR"; Base::avm_main_pc = "AVM_MAIN_PC"; + Base::avm_main_q_kernel_lookup = "AVM_MAIN_Q_KERNEL_LOOKUP"; Base::avm_main_r_in_tag = "AVM_MAIN_R_IN_TAG"; Base::avm_main_rwa = "AVM_MAIN_RWA"; Base::avm_main_rwb = "AVM_MAIN_RWB"; @@ -2202,19 +2296,30 @@ class AvmFlavor { Base::avm_main_sel_mov_a = "AVM_MAIN_SEL_MOV_A"; Base::avm_main_sel_mov_b = "AVM_MAIN_SEL_MOV_B"; Base::avm_main_sel_op_add = "AVM_MAIN_SEL_OP_ADD"; + Base::avm_main_sel_op_address = "AVM_MAIN_SEL_OP_ADDRESS"; Base::avm_main_sel_op_and = "AVM_MAIN_SEL_OP_AND"; + Base::avm_main_sel_op_block_number = "AVM_MAIN_SEL_OP_BLOCK_NUMBER"; Base::avm_main_sel_op_cast = "AVM_MAIN_SEL_OP_CAST"; + Base::avm_main_sel_op_chain_id = "AVM_MAIN_SEL_OP_CHAIN_ID"; + Base::avm_main_sel_op_coinbase = "AVM_MAIN_SEL_OP_COINBASE"; Base::avm_main_sel_op_div = "AVM_MAIN_SEL_OP_DIV"; Base::avm_main_sel_op_eq = "AVM_MAIN_SEL_OP_EQ"; Base::avm_main_sel_op_fdiv = "AVM_MAIN_SEL_OP_FDIV"; + Base::avm_main_sel_op_fee_per_da_gas = "AVM_MAIN_SEL_OP_FEE_PER_DA_GAS"; + Base::avm_main_sel_op_fee_per_l2_gas = "AVM_MAIN_SEL_OP_FEE_PER_L2_GAS"; Base::avm_main_sel_op_lt = "AVM_MAIN_SEL_OP_LT"; Base::avm_main_sel_op_lte = "AVM_MAIN_SEL_OP_LTE"; Base::avm_main_sel_op_mul = "AVM_MAIN_SEL_OP_MUL"; Base::avm_main_sel_op_not = "AVM_MAIN_SEL_OP_NOT"; Base::avm_main_sel_op_or = "AVM_MAIN_SEL_OP_OR"; + Base::avm_main_sel_op_portal = "AVM_MAIN_SEL_OP_PORTAL"; + Base::avm_main_sel_op_sender = "AVM_MAIN_SEL_OP_SENDER"; Base::avm_main_sel_op_shl = "AVM_MAIN_SEL_OP_SHL"; Base::avm_main_sel_op_shr = "AVM_MAIN_SEL_OP_SHR"; Base::avm_main_sel_op_sub = "AVM_MAIN_SEL_OP_SUB"; + Base::avm_main_sel_op_timestamp = "AVM_MAIN_SEL_OP_TIMESTAMP"; + Base::avm_main_sel_op_transaction_fee = "AVM_MAIN_SEL_OP_TRANSACTION_FEE"; + Base::avm_main_sel_op_version = "AVM_MAIN_SEL_OP_VERSION"; Base::avm_main_sel_op_xor = "AVM_MAIN_SEL_OP_XOR"; Base::avm_main_sel_rng_16 = "AVM_MAIN_SEL_RNG_16"; Base::avm_main_sel_rng_8 = "AVM_MAIN_SEL_RNG_8"; @@ -2261,6 +2366,7 @@ class AvmFlavor { Base::perm_main_mem_ind_d = "PERM_MAIN_MEM_IND_D"; Base::lookup_byte_lengths = "LOOKUP_BYTE_LENGTHS"; Base::lookup_byte_operations = "LOOKUP_BYTE_OPERATIONS"; + Base::lookup_into_kernel = "LOOKUP_INTO_KERNEL"; Base::incl_main_tag_err = "INCL_MAIN_TAG_ERR"; Base::incl_mem_tag_err = "INCL_MEM_TAG_ERR"; Base::lookup_mem_rng_chk_lo = "LOOKUP_MEM_RNG_CHK_LO"; @@ -2294,6 +2400,7 @@ class AvmFlavor { Base::lookup_div_u16_7 = "LOOKUP_DIV_U16_7"; Base::lookup_byte_lengths_counts = "LOOKUP_BYTE_LENGTHS_COUNTS"; Base::lookup_byte_operations_counts = "LOOKUP_BYTE_OPERATIONS_COUNTS"; + Base::lookup_into_kernel_counts = "LOOKUP_INTO_KERNEL_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"; @@ -2447,6 +2554,9 @@ class AvmFlavor { Commitment avm_byte_lookup_table_input_b; Commitment avm_byte_lookup_table_op_id; Commitment avm_byte_lookup_table_output; + Commitment avm_kernel_kernel_inputs__is_public; + Commitment avm_kernel_kernel_sel; + Commitment avm_kernel_q_public_input_kernel_add_to_table; Commitment avm_main_alu_in_tag; Commitment avm_main_alu_sel; Commitment avm_main_bin_op_id; @@ -2477,6 +2587,7 @@ class AvmFlavor { Commitment avm_main_mem_op_d; Commitment avm_main_op_err; Commitment avm_main_pc; + Commitment avm_main_q_kernel_lookup; Commitment avm_main_r_in_tag; Commitment avm_main_rwa; Commitment avm_main_rwb; @@ -2491,19 +2602,30 @@ class AvmFlavor { Commitment avm_main_sel_mov_a; Commitment avm_main_sel_mov_b; Commitment avm_main_sel_op_add; + Commitment avm_main_sel_op_address; Commitment avm_main_sel_op_and; + Commitment avm_main_sel_op_block_number; Commitment avm_main_sel_op_cast; + Commitment avm_main_sel_op_chain_id; + Commitment avm_main_sel_op_coinbase; Commitment avm_main_sel_op_div; Commitment avm_main_sel_op_eq; Commitment avm_main_sel_op_fdiv; + Commitment avm_main_sel_op_fee_per_da_gas; + Commitment avm_main_sel_op_fee_per_l2_gas; Commitment avm_main_sel_op_lt; Commitment avm_main_sel_op_lte; Commitment avm_main_sel_op_mul; Commitment avm_main_sel_op_not; Commitment avm_main_sel_op_or; + Commitment avm_main_sel_op_portal; + Commitment avm_main_sel_op_sender; Commitment avm_main_sel_op_shl; Commitment avm_main_sel_op_shr; Commitment avm_main_sel_op_sub; + Commitment avm_main_sel_op_timestamp; + Commitment avm_main_sel_op_transaction_fee; + Commitment avm_main_sel_op_version; Commitment avm_main_sel_op_xor; Commitment avm_main_sel_rng_16; Commitment avm_main_sel_rng_8; @@ -2550,6 +2672,7 @@ class AvmFlavor { Commitment perm_main_mem_ind_d; Commitment lookup_byte_lengths; Commitment lookup_byte_operations; + Commitment lookup_into_kernel; Commitment incl_main_tag_err; Commitment incl_mem_tag_err; Commitment lookup_mem_rng_chk_lo; @@ -2583,6 +2706,7 @@ class AvmFlavor { Commitment lookup_div_u16_7; Commitment lookup_byte_lengths_counts; Commitment lookup_byte_operations_counts; + Commitment lookup_into_kernel_counts; Commitment incl_main_tag_err_counts; Commitment incl_mem_tag_err_counts; Commitment lookup_mem_rng_chk_lo_counts; @@ -2737,6 +2861,11 @@ class AvmFlavor { avm_byte_lookup_table_input_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_byte_lookup_table_op_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_byte_lookup_table_output = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_kernel_kernel_inputs__is_public = + deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_kernel_kernel_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_kernel_q_public_input_kernel_add_to_table = + deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_alu_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_alu_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_bin_op_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -2767,6 +2896,7 @@ class AvmFlavor { avm_main_mem_op_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_op_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_pc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_q_kernel_lookup = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_r_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_rwa = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_rwb = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -2781,19 +2911,30 @@ class AvmFlavor { avm_main_sel_mov_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_mov_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_add = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_address = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_and = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_block_number = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_cast = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_chain_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_coinbase = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_eq = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_fdiv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_fee_per_da_gas = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_fee_per_l2_gas = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_lt = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_lte = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_not = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_or = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_portal = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_sender = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_shl = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_shr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_sub = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_timestamp = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_transaction_fee = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_op_version = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_op_xor = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_rng_16 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_rng_8 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -2840,6 +2981,7 @@ class AvmFlavor { perm_main_mem_ind_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_byte_lengths = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_byte_operations = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + lookup_into_kernel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); incl_main_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); incl_mem_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_mem_rng_chk_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -2873,6 +3015,7 @@ class AvmFlavor { lookup_div_u16_7 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_byte_lengths_counts = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_byte_operations_counts = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + lookup_into_kernel_counts = deserialize_from_buffer(Transcript::proof_data, num_frs_read); incl_main_tag_err_counts = deserialize_from_buffer(Transcript::proof_data, num_frs_read); incl_mem_tag_err_counts = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_mem_rng_chk_lo_counts = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -3030,6 +3173,9 @@ class AvmFlavor { serialize_to_buffer(avm_byte_lookup_table_input_b, Transcript::proof_data); serialize_to_buffer(avm_byte_lookup_table_op_id, Transcript::proof_data); serialize_to_buffer(avm_byte_lookup_table_output, Transcript::proof_data); + serialize_to_buffer(avm_kernel_kernel_inputs__is_public, Transcript::proof_data); + serialize_to_buffer(avm_kernel_kernel_sel, Transcript::proof_data); + serialize_to_buffer(avm_kernel_q_public_input_kernel_add_to_table, Transcript::proof_data); serialize_to_buffer(avm_main_alu_in_tag, Transcript::proof_data); serialize_to_buffer(avm_main_alu_sel, Transcript::proof_data); serialize_to_buffer(avm_main_bin_op_id, Transcript::proof_data); @@ -3060,6 +3206,7 @@ class AvmFlavor { serialize_to_buffer(avm_main_mem_op_d, Transcript::proof_data); serialize_to_buffer(avm_main_op_err, Transcript::proof_data); serialize_to_buffer(avm_main_pc, Transcript::proof_data); + serialize_to_buffer(avm_main_q_kernel_lookup, Transcript::proof_data); serialize_to_buffer(avm_main_r_in_tag, Transcript::proof_data); serialize_to_buffer(avm_main_rwa, Transcript::proof_data); serialize_to_buffer(avm_main_rwb, Transcript::proof_data); @@ -3074,19 +3221,30 @@ class AvmFlavor { serialize_to_buffer(avm_main_sel_mov_a, Transcript::proof_data); serialize_to_buffer(avm_main_sel_mov_b, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_add, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_address, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_and, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_block_number, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_cast, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_chain_id, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_coinbase, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_div, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_eq, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_fdiv, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_fee_per_da_gas, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_fee_per_l2_gas, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_lt, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_lte, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_mul, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_not, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_or, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_portal, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_sender, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_shl, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_shr, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_sub, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_timestamp, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_transaction_fee, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_op_version, Transcript::proof_data); serialize_to_buffer(avm_main_sel_op_xor, Transcript::proof_data); serialize_to_buffer(avm_main_sel_rng_16, Transcript::proof_data); serialize_to_buffer(avm_main_sel_rng_8, Transcript::proof_data); @@ -3133,6 +3291,7 @@ class AvmFlavor { serialize_to_buffer(perm_main_mem_ind_d, Transcript::proof_data); serialize_to_buffer(lookup_byte_lengths, Transcript::proof_data); serialize_to_buffer(lookup_byte_operations, Transcript::proof_data); + serialize_to_buffer(lookup_into_kernel, Transcript::proof_data); serialize_to_buffer(incl_main_tag_err, Transcript::proof_data); serialize_to_buffer(incl_mem_tag_err, Transcript::proof_data); serialize_to_buffer(lookup_mem_rng_chk_lo, Transcript::proof_data); @@ -3166,6 +3325,7 @@ class AvmFlavor { serialize_to_buffer(lookup_div_u16_7, Transcript::proof_data); serialize_to_buffer(lookup_byte_lengths_counts, Transcript::proof_data); serialize_to_buffer(lookup_byte_operations_counts, Transcript::proof_data); + serialize_to_buffer(lookup_into_kernel_counts, Transcript::proof_data); serialize_to_buffer(incl_main_tag_err_counts, Transcript::proof_data); serialize_to_buffer(incl_mem_tag_err_counts, Transcript::proof_data); serialize_to_buffer(lookup_mem_rng_chk_lo_counts, Transcript::proof_data); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp index feb378a1326..6f5fd5a27fd 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp @@ -163,6 +163,11 @@ void AvmProver::execute_wire_commitments_round() witness_commitments.avm_byte_lookup_table_input_b = commitment_key->commit(key->avm_byte_lookup_table_input_b); witness_commitments.avm_byte_lookup_table_op_id = commitment_key->commit(key->avm_byte_lookup_table_op_id); witness_commitments.avm_byte_lookup_table_output = commitment_key->commit(key->avm_byte_lookup_table_output); + witness_commitments.avm_kernel_kernel_inputs__is_public = + commitment_key->commit(key->avm_kernel_kernel_inputs__is_public); + witness_commitments.avm_kernel_kernel_sel = commitment_key->commit(key->avm_kernel_kernel_sel); + witness_commitments.avm_kernel_q_public_input_kernel_add_to_table = + commitment_key->commit(key->avm_kernel_q_public_input_kernel_add_to_table); witness_commitments.avm_main_alu_in_tag = commitment_key->commit(key->avm_main_alu_in_tag); witness_commitments.avm_main_alu_sel = commitment_key->commit(key->avm_main_alu_sel); witness_commitments.avm_main_bin_op_id = commitment_key->commit(key->avm_main_bin_op_id); @@ -193,6 +198,7 @@ void AvmProver::execute_wire_commitments_round() witness_commitments.avm_main_mem_op_d = commitment_key->commit(key->avm_main_mem_op_d); witness_commitments.avm_main_op_err = commitment_key->commit(key->avm_main_op_err); witness_commitments.avm_main_pc = commitment_key->commit(key->avm_main_pc); + witness_commitments.avm_main_q_kernel_lookup = commitment_key->commit(key->avm_main_q_kernel_lookup); witness_commitments.avm_main_r_in_tag = commitment_key->commit(key->avm_main_r_in_tag); witness_commitments.avm_main_rwa = commitment_key->commit(key->avm_main_rwa); witness_commitments.avm_main_rwb = commitment_key->commit(key->avm_main_rwb); @@ -207,19 +213,30 @@ void AvmProver::execute_wire_commitments_round() witness_commitments.avm_main_sel_mov_a = commitment_key->commit(key->avm_main_sel_mov_a); witness_commitments.avm_main_sel_mov_b = commitment_key->commit(key->avm_main_sel_mov_b); witness_commitments.avm_main_sel_op_add = commitment_key->commit(key->avm_main_sel_op_add); + witness_commitments.avm_main_sel_op_address = commitment_key->commit(key->avm_main_sel_op_address); witness_commitments.avm_main_sel_op_and = commitment_key->commit(key->avm_main_sel_op_and); + witness_commitments.avm_main_sel_op_block_number = commitment_key->commit(key->avm_main_sel_op_block_number); witness_commitments.avm_main_sel_op_cast = commitment_key->commit(key->avm_main_sel_op_cast); + witness_commitments.avm_main_sel_op_chain_id = commitment_key->commit(key->avm_main_sel_op_chain_id); + witness_commitments.avm_main_sel_op_coinbase = commitment_key->commit(key->avm_main_sel_op_coinbase); witness_commitments.avm_main_sel_op_div = commitment_key->commit(key->avm_main_sel_op_div); witness_commitments.avm_main_sel_op_eq = commitment_key->commit(key->avm_main_sel_op_eq); witness_commitments.avm_main_sel_op_fdiv = commitment_key->commit(key->avm_main_sel_op_fdiv); + witness_commitments.avm_main_sel_op_fee_per_da_gas = commitment_key->commit(key->avm_main_sel_op_fee_per_da_gas); + witness_commitments.avm_main_sel_op_fee_per_l2_gas = commitment_key->commit(key->avm_main_sel_op_fee_per_l2_gas); witness_commitments.avm_main_sel_op_lt = commitment_key->commit(key->avm_main_sel_op_lt); witness_commitments.avm_main_sel_op_lte = commitment_key->commit(key->avm_main_sel_op_lte); witness_commitments.avm_main_sel_op_mul = commitment_key->commit(key->avm_main_sel_op_mul); witness_commitments.avm_main_sel_op_not = commitment_key->commit(key->avm_main_sel_op_not); witness_commitments.avm_main_sel_op_or = commitment_key->commit(key->avm_main_sel_op_or); + witness_commitments.avm_main_sel_op_portal = commitment_key->commit(key->avm_main_sel_op_portal); + witness_commitments.avm_main_sel_op_sender = commitment_key->commit(key->avm_main_sel_op_sender); witness_commitments.avm_main_sel_op_shl = commitment_key->commit(key->avm_main_sel_op_shl); witness_commitments.avm_main_sel_op_shr = commitment_key->commit(key->avm_main_sel_op_shr); witness_commitments.avm_main_sel_op_sub = commitment_key->commit(key->avm_main_sel_op_sub); + witness_commitments.avm_main_sel_op_timestamp = commitment_key->commit(key->avm_main_sel_op_timestamp); + witness_commitments.avm_main_sel_op_transaction_fee = commitment_key->commit(key->avm_main_sel_op_transaction_fee); + witness_commitments.avm_main_sel_op_version = commitment_key->commit(key->avm_main_sel_op_version); witness_commitments.avm_main_sel_op_xor = commitment_key->commit(key->avm_main_sel_op_xor); witness_commitments.avm_main_sel_rng_16 = commitment_key->commit(key->avm_main_sel_rng_16); witness_commitments.avm_main_sel_rng_8 = commitment_key->commit(key->avm_main_sel_rng_8); @@ -256,6 +273,7 @@ void AvmProver::execute_wire_commitments_round() witness_commitments.avm_mem_w_in_tag = commitment_key->commit(key->avm_mem_w_in_tag); witness_commitments.lookup_byte_lengths_counts = commitment_key->commit(key->lookup_byte_lengths_counts); witness_commitments.lookup_byte_operations_counts = commitment_key->commit(key->lookup_byte_operations_counts); + witness_commitments.lookup_into_kernel_counts = commitment_key->commit(key->lookup_into_kernel_counts); witness_commitments.incl_main_tag_err_counts = commitment_key->commit(key->incl_main_tag_err_counts); witness_commitments.incl_mem_tag_err_counts = commitment_key->commit(key->incl_mem_tag_err_counts); witness_commitments.lookup_mem_rng_chk_lo_counts = commitment_key->commit(key->lookup_mem_rng_chk_lo_counts); @@ -406,6 +424,11 @@ void AvmProver::execute_wire_commitments_round() witness_commitments.avm_byte_lookup_table_op_id); transcript->send_to_verifier(commitment_labels.avm_byte_lookup_table_output, witness_commitments.avm_byte_lookup_table_output); + transcript->send_to_verifier(commitment_labels.avm_kernel_kernel_inputs__is_public, + witness_commitments.avm_kernel_kernel_inputs__is_public); + transcript->send_to_verifier(commitment_labels.avm_kernel_kernel_sel, witness_commitments.avm_kernel_kernel_sel); + transcript->send_to_verifier(commitment_labels.avm_kernel_q_public_input_kernel_add_to_table, + witness_commitments.avm_kernel_q_public_input_kernel_add_to_table); transcript->send_to_verifier(commitment_labels.avm_main_alu_in_tag, witness_commitments.avm_main_alu_in_tag); transcript->send_to_verifier(commitment_labels.avm_main_alu_sel, witness_commitments.avm_main_alu_sel); transcript->send_to_verifier(commitment_labels.avm_main_bin_op_id, witness_commitments.avm_main_bin_op_id); @@ -437,6 +460,8 @@ void AvmProver::execute_wire_commitments_round() transcript->send_to_verifier(commitment_labels.avm_main_mem_op_d, witness_commitments.avm_main_mem_op_d); transcript->send_to_verifier(commitment_labels.avm_main_op_err, witness_commitments.avm_main_op_err); transcript->send_to_verifier(commitment_labels.avm_main_pc, witness_commitments.avm_main_pc); + transcript->send_to_verifier(commitment_labels.avm_main_q_kernel_lookup, + witness_commitments.avm_main_q_kernel_lookup); transcript->send_to_verifier(commitment_labels.avm_main_r_in_tag, witness_commitments.avm_main_r_in_tag); transcript->send_to_verifier(commitment_labels.avm_main_rwa, witness_commitments.avm_main_rwa); transcript->send_to_verifier(commitment_labels.avm_main_rwb, witness_commitments.avm_main_rwb); @@ -453,19 +478,39 @@ void AvmProver::execute_wire_commitments_round() transcript->send_to_verifier(commitment_labels.avm_main_sel_mov_a, witness_commitments.avm_main_sel_mov_a); transcript->send_to_verifier(commitment_labels.avm_main_sel_mov_b, witness_commitments.avm_main_sel_mov_b); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_add, witness_commitments.avm_main_sel_op_add); + transcript->send_to_verifier(commitment_labels.avm_main_sel_op_address, + witness_commitments.avm_main_sel_op_address); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_and, witness_commitments.avm_main_sel_op_and); + transcript->send_to_verifier(commitment_labels.avm_main_sel_op_block_number, + witness_commitments.avm_main_sel_op_block_number); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_cast, witness_commitments.avm_main_sel_op_cast); + transcript->send_to_verifier(commitment_labels.avm_main_sel_op_chain_id, + witness_commitments.avm_main_sel_op_chain_id); + transcript->send_to_verifier(commitment_labels.avm_main_sel_op_coinbase, + witness_commitments.avm_main_sel_op_coinbase); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_div, witness_commitments.avm_main_sel_op_div); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_eq, witness_commitments.avm_main_sel_op_eq); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_fdiv, witness_commitments.avm_main_sel_op_fdiv); + transcript->send_to_verifier(commitment_labels.avm_main_sel_op_fee_per_da_gas, + witness_commitments.avm_main_sel_op_fee_per_da_gas); + transcript->send_to_verifier(commitment_labels.avm_main_sel_op_fee_per_l2_gas, + witness_commitments.avm_main_sel_op_fee_per_l2_gas); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_lt, witness_commitments.avm_main_sel_op_lt); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_lte, witness_commitments.avm_main_sel_op_lte); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_mul, witness_commitments.avm_main_sel_op_mul); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_not, witness_commitments.avm_main_sel_op_not); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_or, witness_commitments.avm_main_sel_op_or); + transcript->send_to_verifier(commitment_labels.avm_main_sel_op_portal, witness_commitments.avm_main_sel_op_portal); + transcript->send_to_verifier(commitment_labels.avm_main_sel_op_sender, witness_commitments.avm_main_sel_op_sender); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_shl, witness_commitments.avm_main_sel_op_shl); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_shr, witness_commitments.avm_main_sel_op_shr); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_sub, witness_commitments.avm_main_sel_op_sub); + transcript->send_to_verifier(commitment_labels.avm_main_sel_op_timestamp, + witness_commitments.avm_main_sel_op_timestamp); + transcript->send_to_verifier(commitment_labels.avm_main_sel_op_transaction_fee, + witness_commitments.avm_main_sel_op_transaction_fee); + transcript->send_to_verifier(commitment_labels.avm_main_sel_op_version, + witness_commitments.avm_main_sel_op_version); transcript->send_to_verifier(commitment_labels.avm_main_sel_op_xor, witness_commitments.avm_main_sel_op_xor); transcript->send_to_verifier(commitment_labels.avm_main_sel_rng_16, witness_commitments.avm_main_sel_rng_16); transcript->send_to_verifier(commitment_labels.avm_main_sel_rng_8, witness_commitments.avm_main_sel_rng_8); @@ -504,6 +549,8 @@ void AvmProver::execute_wire_commitments_round() witness_commitments.lookup_byte_lengths_counts); transcript->send_to_verifier(commitment_labels.lookup_byte_operations_counts, witness_commitments.lookup_byte_operations_counts); + transcript->send_to_verifier(commitment_labels.lookup_into_kernel_counts, + witness_commitments.lookup_into_kernel_counts); transcript->send_to_verifier(commitment_labels.incl_main_tag_err_counts, witness_commitments.incl_main_tag_err_counts); transcript->send_to_verifier(commitment_labels.incl_mem_tag_err_counts, @@ -571,6 +618,7 @@ void AvmProver::execute_log_derivative_inverse_round() witness_commitments.perm_main_mem_ind_d = commitment_key->commit(key->perm_main_mem_ind_d); witness_commitments.lookup_byte_lengths = commitment_key->commit(key->lookup_byte_lengths); witness_commitments.lookup_byte_operations = commitment_key->commit(key->lookup_byte_operations); + witness_commitments.lookup_into_kernel = commitment_key->commit(key->lookup_into_kernel); witness_commitments.incl_main_tag_err = commitment_key->commit(key->incl_main_tag_err); witness_commitments.incl_mem_tag_err = commitment_key->commit(key->incl_mem_tag_err); witness_commitments.lookup_mem_rng_chk_lo = commitment_key->commit(key->lookup_mem_rng_chk_lo); @@ -616,6 +664,7 @@ void AvmProver::execute_log_derivative_inverse_round() transcript->send_to_verifier(commitment_labels.perm_main_mem_ind_d, witness_commitments.perm_main_mem_ind_d); transcript->send_to_verifier(commitment_labels.lookup_byte_lengths, witness_commitments.lookup_byte_lengths); transcript->send_to_verifier(commitment_labels.lookup_byte_operations, witness_commitments.lookup_byte_operations); + transcript->send_to_verifier(commitment_labels.lookup_into_kernel, witness_commitments.lookup_into_kernel); transcript->send_to_verifier(commitment_labels.incl_main_tag_err, witness_commitments.incl_main_tag_err); transcript->send_to_verifier(commitment_labels.incl_mem_tag_err, witness_commitments.incl_mem_tag_err); transcript->send_to_verifier(commitment_labels.lookup_mem_rng_chk_lo, witness_commitments.lookup_mem_rng_chk_lo); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp index ba34ca33fd0..75984868e88 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp @@ -25,11 +25,28 @@ AvmVerifier& AvmVerifier::operator=(AvmVerifier&& other) noexcept return *this; } +using FF = AvmFlavor::FF; + +// Evaluate the given public input column over the multivariate challenge points +[[maybe_unused]] inline FF evaluate_public_input_column(std::vector points, + const size_t circuit_size, + std::vector challenges) +{ + + // TODO: we pad the points to the circuit size in order to get the correct evaluation + // This is not efficient, and will not be valid in production + std::vector new_points(circuit_size, 0); + std::copy(points.begin(), points.end(), new_points.data()); + + Polynomial polynomial(new_points); + return polynomial.evaluate_mle(challenges); +} + /** * @brief This function verifies an Avm Honk proof for given program settings. * */ -bool AvmVerifier::verify_proof(const HonkProof& proof) +bool AvmVerifier::verify_proof(const HonkProof& proof, const std::vector& public_inputs) { using Flavor = AvmFlavor; using FF = Flavor::FF; @@ -221,6 +238,12 @@ bool AvmVerifier::verify_proof(const HonkProof& proof) transcript->template receive_from_prover(commitment_labels.avm_byte_lookup_table_op_id); commitments.avm_byte_lookup_table_output = transcript->template receive_from_prover(commitment_labels.avm_byte_lookup_table_output); + commitments.avm_kernel_kernel_inputs__is_public = + transcript->template receive_from_prover(commitment_labels.avm_kernel_kernel_inputs__is_public); + commitments.avm_kernel_kernel_sel = + transcript->template receive_from_prover(commitment_labels.avm_kernel_kernel_sel); + commitments.avm_kernel_q_public_input_kernel_add_to_table = transcript->template receive_from_prover( + commitment_labels.avm_kernel_q_public_input_kernel_add_to_table); commitments.avm_main_alu_in_tag = transcript->template receive_from_prover(commitment_labels.avm_main_alu_in_tag); commitments.avm_main_alu_sel = @@ -270,6 +293,8 @@ bool AvmVerifier::verify_proof(const HonkProof& proof) commitments.avm_main_op_err = transcript->template receive_from_prover(commitment_labels.avm_main_op_err); commitments.avm_main_pc = transcript->template receive_from_prover(commitment_labels.avm_main_pc); + commitments.avm_main_q_kernel_lookup = + transcript->template receive_from_prover(commitment_labels.avm_main_q_kernel_lookup); commitments.avm_main_r_in_tag = transcript->template receive_from_prover(commitment_labels.avm_main_r_in_tag); commitments.avm_main_rwa = transcript->template receive_from_prover(commitment_labels.avm_main_rwa); @@ -294,16 +319,28 @@ bool AvmVerifier::verify_proof(const HonkProof& proof) transcript->template receive_from_prover(commitment_labels.avm_main_sel_mov_b); commitments.avm_main_sel_op_add = transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_add); + commitments.avm_main_sel_op_address = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_address); commitments.avm_main_sel_op_and = transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_and); + commitments.avm_main_sel_op_block_number = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_block_number); commitments.avm_main_sel_op_cast = transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_cast); + commitments.avm_main_sel_op_chain_id = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_chain_id); + commitments.avm_main_sel_op_coinbase = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_coinbase); commitments.avm_main_sel_op_div = transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_div); commitments.avm_main_sel_op_eq = transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_eq); commitments.avm_main_sel_op_fdiv = transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_fdiv); + commitments.avm_main_sel_op_fee_per_da_gas = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_fee_per_da_gas); + commitments.avm_main_sel_op_fee_per_l2_gas = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_fee_per_l2_gas); commitments.avm_main_sel_op_lt = transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_lt); commitments.avm_main_sel_op_lte = @@ -314,12 +351,22 @@ bool AvmVerifier::verify_proof(const HonkProof& proof) transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_not); commitments.avm_main_sel_op_or = transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_or); + commitments.avm_main_sel_op_portal = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_portal); + commitments.avm_main_sel_op_sender = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_sender); commitments.avm_main_sel_op_shl = transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_shl); commitments.avm_main_sel_op_shr = transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_shr); commitments.avm_main_sel_op_sub = transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_sub); + commitments.avm_main_sel_op_timestamp = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_timestamp); + commitments.avm_main_sel_op_transaction_fee = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_transaction_fee); + commitments.avm_main_sel_op_version = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_version); commitments.avm_main_sel_op_xor = transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_xor); commitments.avm_main_sel_rng_16 = @@ -381,6 +428,8 @@ bool AvmVerifier::verify_proof(const HonkProof& proof) transcript->template receive_from_prover(commitment_labels.lookup_byte_lengths_counts); commitments.lookup_byte_operations_counts = transcript->template receive_from_prover(commitment_labels.lookup_byte_operations_counts); + commitments.lookup_into_kernel_counts = + transcript->template receive_from_prover(commitment_labels.lookup_into_kernel_counts); commitments.incl_main_tag_err_counts = transcript->template receive_from_prover(commitment_labels.incl_main_tag_err_counts); commitments.incl_mem_tag_err_counts = @@ -471,6 +520,8 @@ bool AvmVerifier::verify_proof(const HonkProof& proof) transcript->template receive_from_prover(commitment_labels.lookup_byte_lengths); commitments.lookup_byte_operations = transcript->template receive_from_prover(commitment_labels.lookup_byte_operations); + commitments.lookup_into_kernel = + transcript->template receive_from_prover(commitment_labels.lookup_into_kernel); commitments.incl_main_tag_err = transcript->template receive_from_prover(commitment_labels.incl_main_tag_err); commitments.incl_mem_tag_err = @@ -534,6 +585,11 @@ bool AvmVerifier::verify_proof(const HonkProof& proof) return false; } + FF public_column_evaluation = evaluate_public_input_column(public_inputs, circuit_size, multivariate_challenge); + if (public_column_evaluation != claimed_evaluations.avm_kernel_kernel_inputs__is_public) { + return false; + } + // Execute ZeroMorph rounds. See https://hackmd.io/dlf9xEwhTQyE3hiGbq4FsA?view for a complete description of the // unrolled protocol. // NOTE: temporarily disabled - facing integration issues diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.hpp index 866eee52b19..6a1a09e82b8 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.hpp @@ -3,6 +3,7 @@ #pragma once #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" +#include "barretenberg/vm/avm_trace/constants.hpp" #include "barretenberg/vm/generated/avm_flavor.hpp" namespace bb { @@ -22,7 +23,7 @@ class AvmVerifier { AvmVerifier& operator=(const AvmVerifier& other) = delete; AvmVerifier& operator=(AvmVerifier&& other) noexcept; - bool verify_proof(const HonkProof& proof); + bool verify_proof(const HonkProof& proof, const std::vector& public_inputs); std::shared_ptr key; std::map commitments; diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/spike_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/spike_circuit_builder.hpp index 255ceed71c8..b1fe88f72f7 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/spike_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/spike_circuit_builder.hpp @@ -3,6 +3,11 @@ // AUTOGENERATED FILE #pragma once +#include +#ifndef __wasm__ +#include +#endif + #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" @@ -18,7 +23,7 @@ namespace bb { template struct SpikeFullRow { FF Spike_first{}; - FF Spike_kernel_inputs{}; + FF Spike_kernel_inputs__is_public{}; FF Spike_x{}; }; @@ -50,7 +55,7 @@ class SpikeCircuitBuilder { for (size_t i = 0; i < rows.size(); i++) { polys.Spike_first[i] = rows[i].Spike_first; - polys.Spike_kernel_inputs[i] = rows[i].Spike_kernel_inputs; + polys.Spike_kernel_inputs__is_public[i] = rows[i].Spike_kernel_inputs__is_public; polys.Spike_x[i] = rows[i].Spike_x; } @@ -90,9 +95,30 @@ class SpikeCircuitBuilder { return true; }; - if (!evaluate_relation.template operator()>("spike", Spike_vm::get_relation_label_spike)) { - return false; + auto spike = [=]() { + return evaluate_relation.template operator()>("spike", + Spike_vm::get_relation_label_spike); + }; + +#ifndef __wasm__ + + // Evaluate check circuit closures as futures + std::vector> relation_futures; + + relation_futures.emplace_back(std::async(std::launch::async, spike)); + + // Wait for lookup evaluations to complete + for (auto& future : relation_futures) { + int result = future.get(); + if (!result) { + return false; + } } +#else + + spike(); + +#endif return true; } diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/spike_flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/spike_flavor.hpp index b841904764d..14e81c04dda 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/spike_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/spike_flavor.hpp @@ -74,17 +74,17 @@ class SpikeFlavor { template class WitnessEntities { public: - DEFINE_FLAVOR_MEMBERS(DataType, Spike_kernel_inputs, Spike_x) + DEFINE_FLAVOR_MEMBERS(DataType, Spike_kernel_inputs__is_public, Spike_x) - RefVector get_wires() { return { Spike_kernel_inputs, Spike_x }; }; + RefVector get_wires() { return { Spike_kernel_inputs__is_public, Spike_x }; }; }; template class AllEntities { public: - DEFINE_FLAVOR_MEMBERS(DataType, Spike_first, Spike_kernel_inputs, Spike_x) + DEFINE_FLAVOR_MEMBERS(DataType, Spike_first, Spike_kernel_inputs__is_public, Spike_x) - RefVector get_wires() { return { Spike_first, Spike_kernel_inputs, Spike_x }; }; - RefVector get_unshifted() { return { Spike_first, Spike_kernel_inputs, Spike_x }; }; + RefVector get_wires() { return { Spike_first, Spike_kernel_inputs__is_public, Spike_x }; }; + RefVector get_unshifted() { return { Spike_first, Spike_kernel_inputs__is_public, Spike_x }; }; RefVector get_to_be_shifted() { return {}; }; RefVector get_shifted() { return {}; }; }; @@ -135,7 +135,7 @@ class SpikeFlavor { } } - [[nodiscard]] size_t get_polynomial_size() const { return Spike_kernel_inputs.size(); } + [[nodiscard]] size_t get_polynomial_size() const { return Spike_kernel_inputs__is_public.size(); } /** * @brief Returns the evaluations of all prover polynomials at one point on the boolean hypercube, which * represents one row in the execution trace. @@ -198,7 +198,7 @@ class SpikeFlavor { : AllEntities() { Base::Spike_first = "SPIKE_FIRST"; - Base::Spike_kernel_inputs = "SPIKE_KERNEL_INPUTS"; + Base::Spike_kernel_inputs__is_public = "SPIKE_KERNEL_INPUTS__IS_PUBLIC"; Base::Spike_x = "SPIKE_X"; }; }; @@ -218,7 +218,7 @@ class SpikeFlavor { public: uint32_t circuit_size; - Commitment Spike_kernel_inputs; + Commitment Spike_kernel_inputs__is_public; Commitment Spike_x; std::vector> sumcheck_univariates; @@ -239,7 +239,7 @@ class SpikeFlavor { circuit_size = deserialize_from_buffer(proof_data, num_frs_read); size_t log_n = numeric::get_msb(circuit_size); - Spike_kernel_inputs = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + Spike_kernel_inputs__is_public = deserialize_from_buffer(Transcript::proof_data, num_frs_read); Spike_x = deserialize_from_buffer(Transcript::proof_data, num_frs_read); for (size_t i = 0; i < log_n; ++i) { @@ -264,7 +264,7 @@ class SpikeFlavor { serialize_to_buffer(circuit_size, Transcript::proof_data); - serialize_to_buffer(Spike_kernel_inputs, Transcript::proof_data); + serialize_to_buffer(Spike_kernel_inputs__is_public, Transcript::proof_data); serialize_to_buffer(Spike_x, Transcript::proof_data); for (size_t i = 0; i < log_n; ++i) { diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/spike_prover.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/spike_prover.cpp index 1f2925eecd1..bc0759df84a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/spike_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/spike_prover.cpp @@ -60,11 +60,12 @@ void SpikeProver::execute_wire_commitments_round() // Commit to all polynomials (apart from logderivative inverse polynomials, which are committed to in the later // logderivative phase) - witness_commitments.Spike_kernel_inputs = commitment_key->commit(key->Spike_kernel_inputs); + witness_commitments.Spike_kernel_inputs__is_public = commitment_key->commit(key->Spike_kernel_inputs__is_public); witness_commitments.Spike_x = commitment_key->commit(key->Spike_x); // Send all commitments to the verifier - transcript->send_to_verifier(commitment_labels.Spike_kernel_inputs, witness_commitments.Spike_kernel_inputs); + transcript->send_to_verifier(commitment_labels.Spike_kernel_inputs__is_public, + witness_commitments.Spike_kernel_inputs__is_public); transcript->send_to_verifier(commitment_labels.Spike_x, witness_commitments.Spike_x); } diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/spike_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/spike_verifier.cpp index 52660b91ed9..98fd8905aa5 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/spike_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/spike_verifier.cpp @@ -28,9 +28,17 @@ SpikeVerifier& SpikeVerifier::operator=(SpikeVerifier&& other) noexcept using FF = SpikeFlavor::FF; // Evaluate the given public input column over the multivariate challenge points -[[maybe_unused]] FF evaluate_public_input_column(std::vector points, std::vector challenges) +[[maybe_unused]] inline FF evaluate_public_input_column(std::vector points, + const size_t circuit_size, + std::vector challenges) { - Polynomial polynomial(points); + + // TODO: we pad the points to the circuit size in order to get the correct evaluation + // This is not efficient, and will not be valid in production + std::vector new_points(circuit_size, 0); + std::copy(points.begin(), points.end(), new_points.data()); + + Polynomial polynomial(new_points); return polynomial.evaluate_mle(challenges); } @@ -62,8 +70,8 @@ bool SpikeVerifier::verify_proof(const HonkProof& proof, const std::vector& } // Get commitments to VM wires - commitments.Spike_kernel_inputs = - transcript->template receive_from_prover(commitment_labels.Spike_kernel_inputs); + commitments.Spike_kernel_inputs__is_public = + transcript->template receive_from_prover(commitment_labels.Spike_kernel_inputs__is_public); commitments.Spike_x = transcript->template receive_from_prover(commitment_labels.Spike_x); // Get commitments to inverses @@ -87,8 +95,8 @@ bool SpikeVerifier::verify_proof(const HonkProof& proof, const std::vector& return false; } - FF public_column_evaluation = evaluate_public_input_column(public_inputs, multivariate_challenge); - if (public_column_evaluation != claimed_evaluations.Spike_kernel_inputs) { + FF public_column_evaluation = evaluate_public_input_column(public_inputs, circuit_size, multivariate_challenge); + if (public_column_evaluation != claimed_evaluations.Spike_kernel_inputs__is_public) { return false; } diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/spike_verifier.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/spike_verifier.hpp index c4fb767455a..eaa66be201c 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/spike_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/spike_verifier.hpp @@ -3,6 +3,7 @@ #pragma once #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" +#include "barretenberg/vm/avm_trace/constants.hpp" #include "barretenberg/vm/generated/spike_flavor.hpp" namespace bb { diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp index c0754b31d4c..ca6ce95391f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp @@ -377,7 +377,7 @@ TEST_F(AvmArithmeticTestsFF, addition) EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0)); - validate_trace(std::move(trace), true); + validate_trace(std::move(trace), {}, true); } // Test on basic subtraction over finite field type. @@ -554,7 +554,7 @@ TEST_F(AvmArithmeticTestsFF, mixedOperationsWithError) trace_builder.halt(); auto trace = trace_builder.finalize(); - validate_trace(std::move(trace), true); + validate_trace(std::move(trace), {}, true); } // Test of equality on FF elements diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp index bbe1ef3e5b0..dffedfa9d11 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp @@ -488,7 +488,7 @@ TEST_P(AvmBitwiseTestsAnd, AllAndTest) auto trace = trace_builder.finalize(); common_validate_bit_op(trace, 0, a, b, output, FF(0), FF(1), FF(2), mem_tag); - validate_trace(std::move(trace), true); + validate_trace(std::move(trace), {}, true); } INSTANTIATE_TEST_SUITE_P(AvmBitwiseTests, AvmBitwiseTestsAnd, diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_cast.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_cast.test.cpp index 634370471c2..bcdeceeb360 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_cast.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_cast.test.cpp @@ -106,7 +106,7 @@ class AvmCastTests : public ::testing::Test { // We still want the ability to enable proving through the environment variable and therefore we do not pass // the boolean variable force_proof to validate_trace second argument. if (force_proof) { - validate_trace(std::move(trace), true); + validate_trace(std::move(trace), {}, true); } else { validate_trace(std::move(trace)); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp index b944655160e..764ec0ef589 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp @@ -54,7 +54,7 @@ TEST_F(AvmControlFlowTests, simpleCall) EXPECT_EQ(halt_row->avm_main_pc, FF(CALL_ADDRESS)); EXPECT_EQ(halt_row->avm_main_internal_return_ptr, FF(AvmTraceBuilder::CALLSTACK_OFFSET + 1)); } - validate_trace(std::move(trace), true); + validate_trace(std::move(trace), {}, true); } TEST_F(AvmControlFlowTests, simpleJump) diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp index 118a802e365..63b54ce4c72 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp @@ -59,7 +59,7 @@ TEST_F(AvmExecutionTests, basicAddReturn) ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); auto trace = Execution::gen_trace(instructions); - validate_trace(std::move(trace), true); + validate_trace(std::move(trace), {}, true); } // Positive test for SET and SUB opcodes @@ -124,7 +124,7 @@ TEST_F(AvmExecutionTests, setAndSubOpcodes) // Find the first row enabling the subtraction selector auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == 1; }); EXPECT_EQ(row->avm_main_ic, 10000); // 47123 - 37123 = 10000 - validate_trace(std::move(trace), true); + validate_trace(std::move(trace), {}, true); } // Positive test for multiple MUL opcodes diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_indirect_mem.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_indirect_mem.test.cpp index 4c09d701d3c..4305b62b181 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_indirect_mem.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_indirect_mem.test.cpp @@ -63,7 +63,7 @@ TEST_F(AvmIndirectMemTests, allIndirectAdd) EXPECT_EQ(row->avm_main_mem_op_b, FF(1)); EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); - validate_trace(std::move(trace), true); + validate_trace(std::move(trace), {}, true); } // Testing a subtraction operation with direct input operands a, b, and an indirect diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_kernel.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_kernel.test.cpp new file mode 100644 index 00000000000..8628b02ecdb --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_kernel.test.cpp @@ -0,0 +1,564 @@ + +#include "avm_common.test.hpp" +#include "barretenberg/vm/avm_trace/avm_common.hpp" +#include "barretenberg/vm/avm_trace/avm_kernel_trace.hpp" +#include "barretenberg/vm/avm_trace/constants.hpp" + +namespace tests_avm { +using namespace bb::avm_trace; + +class AvmKernelTests : public ::testing::Test { + + protected: + // TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialised for every test. + void SetUp() override { srs::init_crs_factory("../srs_db/ignition"); }; +}; + +class AvmKernelPositiveTests : public ::testing::Test {}; +class AvmKernelNegativeTests : public ::testing::Test {}; + +using KernelInputs = std::array; +KernelInputs get_kernel_inputs() +{ + std::array kernel_inputs; + for (size_t i = 0; i < KERNEL_INPUTS_LENGTH; i++) { + kernel_inputs[i] = FF(i + 1); + } + return kernel_inputs; +} + +// Template helper function to apply boilerplate around the kernel lookup tests +template +void test_kernel_lookup(OpcodesFunc apply_opcodes, CheckFunc check_trace) +{ + KernelInputs kernel_inputs = get_kernel_inputs(); + AvmTraceBuilder trace_builder(kernel_inputs); + + // We should return a value of 1 for the sender, as it exists at index 0 + apply_opcodes(trace_builder); + + trace_builder.halt(); + + auto trace = trace_builder.finalize(); + + check_trace(trace); + + validate_trace(std::move(trace), kernel_inputs); +} + +/* + * Helper function to assert row values for a kernel lookup opcode + */ +void expect_row(std::vector::const_iterator row, FF selector, FF ia, FF mem_idx_a, AvmMemoryTag w_in_tag) +{ + // Checks dependent on the opcode + EXPECT_EQ(row->avm_kernel_kernel_sel, selector); + EXPECT_EQ(row->avm_main_ia, ia); + EXPECT_EQ(row->avm_main_mem_idx_a, mem_idx_a); + + // Checks that are fixed for kernel inputs + EXPECT_EQ(row->avm_main_rwa, FF(1)); + EXPECT_EQ(row->avm_main_ind_a, FF(0)); + EXPECT_EQ(row->avm_mem_op_a, FF(1)); + // TODO: below should really be a field element for each type + EXPECT_EQ(row->avm_main_w_in_tag, static_cast(w_in_tag)); + EXPECT_EQ(row->avm_main_q_kernel_lookup, FF(1)); +} + +TEST_F(AvmKernelPositiveTests, kernelSender) +{ + uint32_t dst_offset = 42; + // We test that the sender opcode is included at index 0 in the public inputs + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_sender(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator sender_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sender == FF(1); }); + EXPECT_TRUE(sender_row != trace.end()); + + expect_row(sender_row, + /*kernel_sel=*/SENDER_SELECTOR, + /*ia=*/SENDER_SELECTOR + + 1, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + + test_kernel_lookup(apply_opcodes, checks); +} + +TEST_F(AvmKernelPositiveTests, kernelAddress) +{ + uint32_t dst_offset = 42; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_address(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator address_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_address == FF(1); }); + EXPECT_TRUE(address_row != trace.end()); + + expect_row(address_row, + /*kernel_sel=*/ADDRESS_SELECTOR, + /*ia=*/ADDRESS_SELECTOR + + 1, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + test_kernel_lookup(apply_opcodes, checks); +} + +TEST_F(AvmKernelPositiveTests, kernelPortal) +{ + uint32_t dst_offset = 42; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_portal(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator portal_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_portal == FF(1); }); + EXPECT_TRUE(portal_row != trace.end()); + + expect_row(portal_row, + /*kernel_sel=*/PORTAL_SELECTOR, + /*ia=*/PORTAL_SELECTOR + + 1, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + test_kernel_lookup(apply_opcodes, checks); +} + +TEST_F(AvmKernelPositiveTests, kernelFeePerDa) +{ + uint32_t dst_offset = 42; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_fee_per_da_gas(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator fee_row = std::ranges::find_if( + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fee_per_da_gas == FF(1); }); + EXPECT_TRUE(fee_row != trace.end()); + + expect_row(fee_row, + /*kernel_sel=*/FEE_PER_DA_GAS_SELECTOR, + /*ia=*/FEE_PER_DA_GAS_SELECTOR + + 1, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + test_kernel_lookup(apply_opcodes, checks); +} + +TEST_F(AvmKernelPositiveTests, kernelFeePerL2) +{ + uint32_t dst_offset = 42; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_fee_per_l2_gas(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator fee_row = std::ranges::find_if( + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fee_per_l2_gas == FF(1); }); + EXPECT_TRUE(fee_row != trace.end()); + + expect_row(fee_row, + /*kernel_sel=*/FEE_PER_L2_GAS_SELECTOR, + /*ia=*/FEE_PER_L2_GAS_SELECTOR + + 1, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + test_kernel_lookup(apply_opcodes, checks); +} + +TEST_F(AvmKernelPositiveTests, kernelTransactionFee) +{ + uint32_t dst_offset = 42; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_transaction_fee(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator fee_row = std::ranges::find_if( + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_transaction_fee == FF(1); }); + EXPECT_TRUE(fee_row != trace.end()); + + expect_row(fee_row, + /*kernel_sel=*/TRANSACTION_FEE_SELECTOR, + /*ia=*/TRANSACTION_FEE_SELECTOR + + 1, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + test_kernel_lookup(apply_opcodes, checks); +} + +TEST_F(AvmKernelPositiveTests, kernelChainId) +{ + uint32_t dst_offset = 42; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_chain_id(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator fee_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_chain_id == FF(1); }); + EXPECT_TRUE(fee_row != trace.end()); + + expect_row(fee_row, + /*kernel_sel=*/CHAIN_ID_SELECTOR, + /*ia=*/CHAIN_ID_SELECTOR + + 1, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + test_kernel_lookup(apply_opcodes, checks); +} + +TEST_F(AvmKernelPositiveTests, kernelVersion) +{ + uint32_t dst_offset = 42; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_version(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator fee_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_version == FF(1); }); + EXPECT_TRUE(fee_row != trace.end()); + + expect_row(fee_row, + /*kernel_sel=*/VERSION_SELECTOR, + /*ia=*/VERSION_SELECTOR + + 1, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + test_kernel_lookup(apply_opcodes, checks); +} + +TEST_F(AvmKernelPositiveTests, kernelBlockNumber) +{ + uint32_t dst_offset = 42; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_block_number(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator fee_row = std::ranges::find_if( + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_block_number == FF(1); }); + EXPECT_TRUE(fee_row != trace.end()); + + expect_row(fee_row, + /*kernel_sel=*/BLOCK_NUMBER_SELECTOR, + /*ia=*/BLOCK_NUMBER_SELECTOR + + 1, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + test_kernel_lookup(apply_opcodes, checks); +} + +TEST_F(AvmKernelPositiveTests, kernelCoinbase) +{ + uint32_t dst_offset = 42; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_coinbase(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator fee_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_coinbase == FF(1); }); + EXPECT_TRUE(fee_row != trace.end()); + + expect_row(fee_row, + /*kernel_sel=*/COINBASE_SELECTOR, + /*ia=*/COINBASE_SELECTOR + + 1, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a*/ dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + test_kernel_lookup(apply_opcodes, checks); +} + +TEST_F(AvmKernelPositiveTests, kernelTimestamp) +{ + uint32_t dst_offset = 42; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_timestamp(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator fee_row = std::ranges::find_if( + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_timestamp == FF(1); }); + EXPECT_TRUE(fee_row != trace.end()); + + expect_row(fee_row, + /*kernel_sel=*/TIMESTAMP_SELECTOR, + /*ia=*/TIMESTAMP_SELECTOR + + 1, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a*/ dst_offset, + /*w_in_tag=*/AvmMemoryTag::U64); + }; + test_kernel_lookup(apply_opcodes, checks); +} + +/** + * Negative Tests + */ + +// Template helper function to apply boilerplate +template +void negative_test_incorrect_ia_kernel_lookup(OpcodesFunc apply_opcodes, + CheckFunc check_trace, + FF incorrect_ia, + auto expected_message) +{ + KernelInputs kernel_inputs = get_kernel_inputs(); + AvmTraceBuilder trace_builder(kernel_inputs); + + // We should return a value of 1 for the sender, as it exists at index 0 + apply_opcodes(trace_builder); + + trace_builder.halt(); + + auto trace = trace_builder.finalize(); + + // Change IA to be a value not in the lookup + // Change the first row, as that will be where each of the opcodes are in the test + auto& ta = trace.at(1); + + ta.avm_main_ia = incorrect_ia; + + check_trace(trace); + + EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace), kernel_inputs), expected_message); +} + +TEST_F(AvmKernelNegativeTests, incorrectIaSender) +{ + uint32_t dst_offset = 42; + FF incorrect_ia = FF(69); + + // We test that the sender opcode is inlcuded at index x in the public inputs + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_sender(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator sender_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sender == FF(1); }); + EXPECT_TRUE(sender_row != trace.end()); + + expect_row( + sender_row, + /*kernel_sel=*/SENDER_SELECTOR, + /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + + negative_test_incorrect_ia_kernel_lookup(apply_opcodes, checks, incorrect_ia, "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmKernelNegativeTests, incorrectIaAddress) +{ + uint32_t dst_offset = 42; + FF incorrect_ia = FF(69); + + // We test that the sender opcode is inlcuded at index x in the public inputs + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_address(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator sender_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_address == FF(1); }); + EXPECT_TRUE(sender_row != trace.end()); + + expect_row( + sender_row, + /*kernel_sel=*/ADDRESS_SELECTOR, + /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + + negative_test_incorrect_ia_kernel_lookup(apply_opcodes, checks, incorrect_ia, "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmKernelNegativeTests, incorrectIaPortal) +{ + uint32_t dst_offset = 42; + FF incorrect_ia = FF(69); + + // We test that the sender opcode is inlcuded at index x in the public inputs + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_portal(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator sender_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_portal == FF(1); }); + EXPECT_TRUE(sender_row != trace.end()); + + expect_row( + sender_row, + /*kernel_sel=*/PORTAL_SELECTOR, + /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + + negative_test_incorrect_ia_kernel_lookup(apply_opcodes, checks, incorrect_ia, "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmKernelNegativeTests, incorrectIaDaGas) +{ + uint32_t dst_offset = 42; + FF incorrect_ia = FF(69); + + // We test that the sender opcode is inlcuded at index x in the public inputs + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_fee_per_da_gas(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator sender_row = std::ranges::find_if( + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fee_per_da_gas == FF(1); }); + EXPECT_TRUE(sender_row != trace.end()); + + expect_row( + sender_row, + /*kernel_sel=*/FEE_PER_DA_GAS_SELECTOR, + /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + + negative_test_incorrect_ia_kernel_lookup(apply_opcodes, checks, incorrect_ia, "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmKernelNegativeTests, incorrectIal2Gas) +{ + uint32_t dst_offset = 42; + FF incorrect_ia = FF(69); + + // We test that the sender opcode is inlcuded at index x in the public inputs + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_fee_per_l2_gas(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator sender_row = std::ranges::find_if( + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fee_per_l2_gas == FF(1); }); + EXPECT_TRUE(sender_row != trace.end()); + + expect_row( + sender_row, + /*kernel_sel=*/FEE_PER_L2_GAS_SELECTOR, + /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + + negative_test_incorrect_ia_kernel_lookup(apply_opcodes, checks, incorrect_ia, "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmKernelNegativeTests, incorrectIaTransactionFee) +{ + uint32_t dst_offset = 42; + FF incorrect_ia = FF(69); + + // We test that the sender opcode is inlcuded at index x in the public inputs + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_transaction_fee(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator sender_row = std::ranges::find_if( + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_transaction_fee == FF(1); }); + EXPECT_TRUE(sender_row != trace.end()); + + expect_row( + sender_row, + /*kernel_sel=*/TRANSACTION_FEE_SELECTOR, + /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + + negative_test_incorrect_ia_kernel_lookup(apply_opcodes, checks, incorrect_ia, "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmKernelNegativeTests, incorrectIaChainId) +{ + uint32_t dst_offset = 42; + FF incorrect_ia = FF(69); + + // We test that the sender opcode is inlcuded at index x in the public inputs + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_chain_id(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator sender_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_chain_id == FF(1); }); + EXPECT_TRUE(sender_row != trace.end()); + + expect_row( + sender_row, + /*kernel_sel=*/CHAIN_ID_SELECTOR, + /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + + negative_test_incorrect_ia_kernel_lookup(apply_opcodes, checks, incorrect_ia, "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmKernelNegativeTests, incorrectIaVersion) +{ + uint32_t dst_offset = 42; + FF incorrect_ia = FF(69); + + // We test that the sender opcode is inlcuded at index x in the public inputs + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_version(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator sender_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_version == FF(1); }); + EXPECT_TRUE(sender_row != trace.end()); + + expect_row( + sender_row, + /*kernel_sel=*/VERSION_SELECTOR, + /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + + negative_test_incorrect_ia_kernel_lookup(apply_opcodes, checks, incorrect_ia, "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmKernelNegativeTests, incorrectIaBlockNumber) +{ + uint32_t dst_offset = 42; + FF incorrect_ia = FF(69); + + // We test that the sender opcode is inlcuded at index x in the public inputs + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_block_number(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator sender_row = std::ranges::find_if( + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_block_number == FF(1); }); + EXPECT_TRUE(sender_row != trace.end()); + + expect_row( + sender_row, + /*kernel_sel=*/BLOCK_NUMBER_SELECTOR, + /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + + negative_test_incorrect_ia_kernel_lookup(apply_opcodes, checks, incorrect_ia, "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmKernelNegativeTests, incorrectIaTimestamp) +{ + uint32_t dst_offset = 42; + FF incorrect_ia = FF(69); + + // We test that the sender opcode is inlcuded at index x in the public inputs + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_timestamp(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator sender_row = std::ranges::find_if( + trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_timestamp == FF(1); }); + EXPECT_TRUE(sender_row != trace.end()); + + expect_row( + sender_row, + /*kernel_sel=*/TIMESTAMP_SELECTOR, + /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a*/ dst_offset, + /*w_in_tag=*/AvmMemoryTag::U64); + }; + + negative_test_incorrect_ia_kernel_lookup(apply_opcodes, checks, incorrect_ia, "PERM_MAIN_MEM_A"); +} + +TEST_F(AvmKernelNegativeTests, incorrectIaCoinbase) +{ + uint32_t dst_offset = 42; + FF incorrect_ia = FF(69); + + // We test that the sender opcode is inlcuded at index x in the public inputs + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_coinbase(dst_offset); }; + auto checks = [=](const std::vector& trace) { + std::vector::const_iterator sender_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_coinbase == FF(1); }); + EXPECT_TRUE(sender_row != trace.end()); + + expect_row( + sender_row, + /*kernel_sel=*/COINBASE_SELECTOR, + /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 + /*mem_idx_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + + negative_test_incorrect_ia_kernel_lookup(apply_opcodes, checks, incorrect_ia, "PERM_MAIN_MEM_A"); +} + +} // namespace tests_avm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_mem_opcodes.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_mem_opcodes.test.cpp index 6d5f3544922..069c0922b57 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_mem_opcodes.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_mem_opcodes.test.cpp @@ -391,7 +391,7 @@ TEST_F(AvmMemOpcodeTests, indirectMovInvalidAddressTag) Field(&Row::avm_mem_r_in_tag, static_cast(AvmMemoryTag::U32)), Field(&Row::avm_mem_ind_op_c, 1))); - validate_trace(std::move(trace), true); + validate_trace(std::move(trace), {}, true); } /****************************************************************************** diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp index aed1f0ac079..252c639177a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp @@ -69,7 +69,7 @@ TEST_F(AvmMemoryTests, mismatchedTagAddOperation) EXPECT_EQ(row->avm_mem_r_in_tag, FF(static_cast(AvmMemoryTag::U8))); EXPECT_EQ(row->avm_mem_tag, FF(static_cast(AvmMemoryTag::FF))); - validate_trace(std::move(trace), true); + validate_trace(std::move(trace), {}, true); } // Testing an equality operation with a mismatched memory tag. diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp index b0dc065027d..5f5cac0afeb 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp @@ -1,5 +1,6 @@ #include "barretenberg/vm/tests/helpers.test.hpp" #include "avm_common.test.hpp" +#include "barretenberg/vm/avm_trace/constants.hpp" #include "barretenberg/vm/generated/avm_flavor.hpp" namespace tests_avm { @@ -18,9 +19,9 @@ std::vector gen_three_op_params(std::vector opera * * @param trace The execution trace */ -void validate_trace_check_circuit(std::vector&& trace) +void validate_trace_check_circuit(std::vector&& trace, std::array public_inputs) { - validate_trace(std::move(trace), false); + validate_trace(std::move(trace), public_inputs, false); }; /** @@ -29,7 +30,7 @@ void validate_trace_check_circuit(std::vector&& trace) * * @param trace The execution trace */ -void validate_trace(std::vector&& trace, bool with_proof) +void validate_trace(std::vector&& trace, std::array public_inputs, bool with_proof) { auto circuit_builder = AvmCircuitBuilder(); circuit_builder.set_trace(std::move(trace)); @@ -37,12 +38,17 @@ void validate_trace(std::vector&& trace, bool with_proof) if (with_proof) { info("With proof"); - auto composer = AvmComposer(); - auto prover = composer.create_prover(circuit_builder); - auto proof = prover.construct_proof(); + AvmComposer composer = AvmComposer(); + AvmProver prover = composer.create_prover(circuit_builder); + HonkProof proof = prover.construct_proof(); - auto verifier = composer.create_verifier(circuit_builder); - bool verified = verifier.verify_proof(proof); + AvmVerifier verifier = composer.create_verifier(circuit_builder); + + // We convert to a vector as the pil generated verifier is generic and unaware of the KERNEL_INPUTS_LENGTH + std::vector public_inputs_as_vec(KERNEL_INPUTS_LENGTH); + std::copy(public_inputs.begin(), public_inputs.end(), public_inputs_as_vec.data()); + + bool verified = verifier.verify_proof(proof, public_inputs_as_vec); EXPECT_TRUE(verified); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp index 5df14f93cd7..6715ec52ef1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp @@ -1,6 +1,8 @@ #pragma once #include "barretenberg/vm/avm_trace/avm_trace.hpp" +#include "barretenberg/vm/avm_trace/constants.hpp" +#include #define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage) \ try { \ @@ -24,8 +26,10 @@ static const bool ENABLE_PROVING = std::getenv("AVM_TESTS_ENABLE_PROVING") != nu // If the test is expecting a relation to fail, then use validate_trace_check_circuit. // Otherwise, use validate_trace with a single argument. If the proving needs to be // enabled all the time in a given test, use validate_trace with setting with_proof = true. -void validate_trace_check_circuit(std::vector&& trace); -void validate_trace(std::vector&& trace, bool with_proof = ENABLE_PROVING); +void validate_trace_check_circuit(std::vector&& trace, std::array kernel_inputs = {}); +void validate_trace(std::vector&& trace, + std::array kernel_inputs = {}, + bool with_proof = ENABLE_PROVING); void mutate_ic_in_trace(std::vector& trace, std::function&& selectRow, FF const& newValue, diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/spike.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/spike.test.cpp index 1b30f1f4a6c..53bf8e31bbf 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/spike.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/spike.test.cpp @@ -40,7 +40,7 @@ bool verify_spike_with_public_with_public_inputs(std::vector ve // Add to the public input column that is increasing for (size_t i = 0; i < circuit_size; i++) { // Make sure the external and trace public inputs are the same - Row row{ .Spike_kernel_inputs = i + 1 }; + Row row{ .Spike_kernel_inputs__is_public = i + 1 }; rows.push_back(row); } diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index ac060def61e..a83864c78a4 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -158,6 +158,8 @@ library Constants { + 1; uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH; + uint256 internal constant PUBLIC_CONTEXT_INPUTS_LENGTH = + CALL_CONTEXT_LENGTH + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + GAS_LENGTH + 2; uint256 internal constant SCOPED_READ_REQUEST_LEN = READ_REQUEST_LENGTH + 1; uint256 internal constant PUBLIC_DATA_READ_LENGTH = 2; uint256 internal constant VALIDATION_REQUESTS_LENGTH = ROLLUP_VALIDATION_REQUESTS_LENGTH diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 84f47f12d87..24fc5fd9509 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -175,6 +175,7 @@ global HEADER_LENGTH: u64 = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + CONTENT_COMMITMEN global PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH: u64 = CALL_CONTEXT_LENGTH + 3 + MAX_BLOCK_NUMBER_LENGTH + (READ_REQUEST_LENGTH * MAX_NOTE_HASH_READ_REQUESTS_PER_CALL) + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + (NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL) + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + 1 + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + (SIDE_EFFECT_LENGTH * MAX_ENCRYPTED_LOGS_PER_CALL) + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 2 + HEADER_LENGTH + TX_CONTEXT_LENGTH; global PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH: u64 = CALL_CONTEXT_LENGTH + 2 + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + (READ_REQUEST_LENGTH * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL) + (CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL) + (CONTRACT_STORAGE_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_CALL) + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 1 + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + AZTEC_ADDRESS_LENGTH + /* revert_code */ 1 + 2 * GAS_LENGTH + /* transaction_fee */ 1; global PRIVATE_CALL_STACK_ITEM_LENGTH: u64 = AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH; +global PUBLIC_CONTEXT_INPUTS_LENGTH: u64 = CALL_CONTEXT_LENGTH + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + GAS_LENGTH + 2; global SCOPED_READ_REQUEST_LEN = READ_REQUEST_LENGTH + 1; global PUBLIC_DATA_READ_LENGTH = 2; diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index e15a83aa388..3683f80761e 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -157,6 +157,8 @@ export const PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = /* transaction_fee */ 1; export const PRIVATE_CALL_STACK_ITEM_LENGTH = AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH; +export const PUBLIC_CONTEXT_INPUTS_LENGTH = + CALL_CONTEXT_LENGTH + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + GAS_LENGTH + 2; export const SCOPED_READ_REQUEST_LEN = READ_REQUEST_LENGTH + 1; export const PUBLIC_DATA_READ_LENGTH = 2; export const VALIDATION_REQUESTS_LENGTH = diff --git a/yarn-project/circuits.js/src/scripts/constants.in.ts b/yarn-project/circuits.js/src/scripts/constants.in.ts index 33ede0eded4..e5f969e228b 100644 --- a/yarn-project/circuits.js/src/scripts/constants.in.ts +++ b/yarn-project/circuits.js/src/scripts/constants.in.ts @@ -4,6 +4,7 @@ import { fileURLToPath } from 'url'; const NOIR_CONSTANTS_FILE = '../../../../noir-projects/noir-protocol-circuits/crates/types/src/constants.nr'; const TS_CONSTANTS_FILE = '../constants.gen.ts'; +const CPP_AZTEC_CONSTANTS_FILE = '../../../../barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp'; const SOLIDITY_CONSTANTS_FILE = '../../../../l1-contracts/src/core/libraries/ConstantsGen.sol'; /** @@ -34,6 +35,24 @@ function processConstantsTS(constants: { [key: string]: string }): string { return code.join('\n'); } +/** + * Processes a collection of constants and generates code to export them as cpp constants. + * Required to ensure consistency between the constants used in pil and used in the vm witness generator. + * + * @param constants - An object containing key-value pairs representing constants. + * @returns A string containing code that exports the constants as cpp constants. + */ +function processConstantsCpp(constants: { [key: string]: string }): string { + const code: string[] = []; + Object.entries(constants).forEach(([key, value]) => { + // We exclude large numbers + if (!(value.startsWith('0x') || value.includes('0_0'))) { + code.push(`const size_t ${key} = ${value};`); + } + }); + return code.join('\n'); +} + /** * Processes an enum and generates code to export it as a TypeScript enum. * @@ -83,6 +102,20 @@ function generateTypescriptConstants({ constants, generatorIndexEnum }: ParsedCo fs.writeFileSync(targetPath, result); } +/** + * Generate the constants file in C++. + */ +function generateCppConstants({ constants }: ParsedContent, targetPath: string) { + const resultCpp: string = `// GENERATED FILE - DO NOT EDIT, RUN yarn remake-constants in circuits.js +#pragma once +#include + +${processConstantsCpp(constants)} +\n`; + + fs.writeFileSync(targetPath, resultCpp); +} + /** * Generate the constants file in Solidity. */ @@ -155,6 +188,10 @@ function main(): void { const tsTargetPath = join(__dirname, TS_CONSTANTS_FILE); generateTypescriptConstants(parsedContent, tsTargetPath); + // Cpp + const cppTargetPath = join(__dirname, CPP_AZTEC_CONSTANTS_FILE); + generateCppConstants(parsedContent, cppTargetPath); + // Solidity const solidityTargetPath = join(__dirname, SOLIDITY_CONSTANTS_FILE); fs.mkdirSync(dirname(solidityTargetPath), { recursive: true });