diff --git a/barretenberg/cpp/pil/avm/avm_main.pil b/barretenberg/cpp/pil/avm/avm_main.pil index cdcc2054211..8d62d03e8e1 100644 --- a/barretenberg/cpp/pil/avm/avm_main.pil +++ b/barretenberg/cpp/pil/avm/avm_main.pil @@ -116,6 +116,7 @@ namespace avm_main(256); pol commit sel_internal_return; pol commit sel_jump; pol commit sel_jumpi; + pol commit sel_external_call; // Halt program execution pol commit sel_halt; @@ -276,6 +277,7 @@ namespace avm_main(256); sel_jump * (1 - sel_jump) = 0; sel_jumpi * (1 - sel_jumpi) = 0; sel_halt * (1 - sel_halt) = 0; + sel_external_call * (1 - sel_external_call) = 0; // Might be removed if derived from opcode based on a lookup of constants sel_mov * ( 1 - sel_mov) = 0; @@ -413,7 +415,7 @@ namespace avm_main(256); //===== CONTROL_FLOW_CONSISTENCY ============================================ pol INTERNAL_CALL_STACK_SELECTORS = (first + sel_internal_call + sel_internal_return + sel_halt); - pol ALL_CTRL_FLOW_SEL = sel_jump + sel_jumpi + sel_internal_call + sel_internal_return; + pol ALL_CTRL_FLOW_SEL = sel_jump + sel_jumpi + sel_internal_call + sel_internal_return + sel_external_call; pol ALL_BINARY_SEL = sel_op_and + sel_op_or + sel_op_xor; pol ALL_GADGET_SEL = sel_op_radix_le + sel_op_sha256 + sel_op_poseidon2 + sel_op_keccak + sel_op_pedersen; diff --git a/barretenberg/cpp/pil/avm/constants.pil b/barretenberg/cpp/pil/avm/constants.pil index cda546c6754..bfd243d2016 100644 --- a/barretenberg/cpp/pil/avm/constants.pil +++ b/barretenberg/cpp/pil/avm/constants.pil @@ -30,3 +30,14 @@ namespace constants(256); // Other AVM specific constants pol INTERNAL_CALL_SPACE_ID = 255; + // Lengths of kernel output vectors + // Read requests + pol MAX_NULLIFIER_READ_REQUESTS_PER_CALL = 32; + pol MAX_NOTE_HASH_READ_REQUESTS_PER_CALL = 32; + pol MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL = 32; + pol MAX_PUBLIC_DATA_READS_PER_CALL = 16; + + // Emitting Data + pol MAX_NEW_NOTE_HASHES_PER_CALL = 16; + pol MAX_NEW_NULLIIFIERS_PER_CALL = 16; + pol MAX_NEW_L2_TO_L1_MSGS_PER_CALL = 2; 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 0744e52c63f..73de46a4bb9 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp @@ -63,6 +63,7 @@ template struct Avm_mainRow { FF avm_main_rwc{}; FF avm_main_rwd{}; FF avm_main_sel_cmov{}; + FF avm_main_sel_external_call{}; FF avm_main_sel_halt{}; FF avm_main_sel_internal_call{}; FF avm_main_sel_internal_return{}; @@ -130,133 +131,133 @@ inline std::string get_relation_label_avm_main(int index) case 3: return "DA_GAS_INACTIVE"; - case 65: + case 66: return "OUTPUT_U8"; - case 66: + case 67: return "SUBOP_FDIV"; - case 67: + case 68: return "SUBOP_FDIV_ZERO_ERR1"; - case 68: + case 69: return "SUBOP_FDIV_ZERO_ERR2"; - case 69: + case 70: return "SUBOP_FDIV_R_IN_TAG_FF"; - case 70: + case 71: return "SUBOP_FDIV_W_IN_TAG_FF"; - case 71: + case 72: return "SUBOP_ERROR_RELEVANT_OP"; - case 72: + case 73: return "KERNEL_INPUT_ACTIVE_CHECK"; - case 73: + case 74: return "KERNEL_OUTPUT_ACTIVE_CHECK"; - case 74: + case 75: return "PC_JUMP"; - case 75: + case 76: return "PC_JUMPI"; - case 76: + case 77: return "RETURN_POINTER_INCREMENT"; - case 82: + case 83: return "RETURN_POINTER_DECREMENT"; - case 88: + case 89: return "PC_INCREMENT"; - case 89: + case 90: return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - case 90: + case 91: return "SPACE_ID_INTERNAL"; - case 91: + case 92: return "SPACE_ID_STANDARD_OPCODES"; - case 92: + case 93: return "CMOV_CONDITION_RES_1"; - case 93: + case 94: return "CMOV_CONDITION_RES_2"; - case 96: + case 97: return "MOV_SAME_VALUE_A"; - case 97: + case 98: return "MOV_SAME_VALUE_B"; - case 98: + case 99: return "MOV_MAIN_SAME_TAG"; - case 102: + case 103: return "SENDER_KERNEL"; - case 103: + case 104: return "ADDRESS_KERNEL"; - case 104: + case 105: return "FEE_DA_GAS_KERNEL"; - case 105: + case 106: return "FEE_L2_GAS_KERNEL"; - case 106: + case 107: return "FEE_TRANSACTION_FEE_KERNEL"; - case 107: + case 108: return "CHAIN_ID_KERNEL"; - case 108: + case 109: return "VERSION_KERNEL"; - case 109: + case 110: return "BLOCK_NUMBER_KERNEL"; - case 110: + case 111: return "COINBASE_KERNEL"; - case 111: + case 112: return "TIMESTAMP_KERNEL"; - case 112: + case 113: return "NOTE_HASH_KERNEL_OUTPUT"; - case 114: + case 115: return "EMIT_NOTE_HASH_KERNEL_OUTPUT"; - case 116: + case 117: return "NULLIFIER_EXISTS_KERNEL_OUTPUT"; - case 118: + case 119: return "EMIT_NULLIFIER_KERNEL_OUTPUT"; - case 120: + case 121: return "L1_TO_L2_MSG_EXISTS_KERNEL_OUTPUT"; - case 122: + case 123: return "EMIT_UNENCRYPTED_LOG_KERNEL_OUTPUT"; - case 124: + case 125: return "EMIT_L2_TO_L1_MSGS_KERNEL_OUTPUT"; - case 126: + case 127: return "SLOAD_KERNEL_OUTPUT"; - case 128: + case 129: return "SSTORE_KERNEL_OUTPUT"; - case 131: + case 132: return "BIN_SEL_1"; - case 132: + case 133: return "BIN_SEL_2"; } return std::to_string(index); @@ -266,11 +267,11 @@ template class avm_mainImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 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, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, - 4, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 5, 3, 3, 3, 4, 4, 3, 3, 3, 3, 3, 4, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, + 4, 4, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 5, 3, 3, 3, 4, 4, 3, 3, 3, 3, 3, 4, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, }; template @@ -670,7 +671,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(48); - auto tmp = (avm_main_sel_mov * (-avm_main_sel_mov + FF(1))); + auto tmp = (avm_main_sel_external_call * (-avm_main_sel_external_call + FF(1))); tmp *= scaling_factor; std::get<48>(evals) += tmp; } @@ -678,7 +679,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(49); - auto tmp = (avm_main_sel_cmov * (-avm_main_sel_cmov + FF(1))); + auto tmp = (avm_main_sel_mov * (-avm_main_sel_mov + FF(1))); tmp *= scaling_factor; std::get<49>(evals) += tmp; } @@ -686,7 +687,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(50); - auto tmp = (avm_main_op_err * (-avm_main_op_err + FF(1))); + auto tmp = (avm_main_sel_cmov * (-avm_main_sel_cmov + FF(1))); tmp *= scaling_factor; std::get<50>(evals) += tmp; } @@ -694,7 +695,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(51); - auto tmp = (avm_main_tag_err * (-avm_main_tag_err + FF(1))); + auto tmp = (avm_main_op_err * (-avm_main_op_err + FF(1))); tmp *= scaling_factor; std::get<51>(evals) += tmp; } @@ -702,7 +703,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(52); - auto tmp = (avm_main_id_zero * (-avm_main_id_zero + FF(1))); + auto tmp = (avm_main_tag_err * (-avm_main_tag_err + FF(1))); tmp *= scaling_factor; std::get<52>(evals) += tmp; } @@ -710,7 +711,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(53); - auto tmp = (avm_main_mem_op_a * (-avm_main_mem_op_a + FF(1))); + auto tmp = (avm_main_id_zero * (-avm_main_id_zero + FF(1))); tmp *= scaling_factor; std::get<53>(evals) += tmp; } @@ -718,7 +719,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(54); - auto tmp = (avm_main_mem_op_b * (-avm_main_mem_op_b + FF(1))); + auto tmp = (avm_main_mem_op_a * (-avm_main_mem_op_a + FF(1))); tmp *= scaling_factor; std::get<54>(evals) += tmp; } @@ -726,7 +727,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(55); - auto tmp = (avm_main_mem_op_c * (-avm_main_mem_op_c + FF(1))); + auto tmp = (avm_main_mem_op_b * (-avm_main_mem_op_b + FF(1))); tmp *= scaling_factor; std::get<55>(evals) += tmp; } @@ -734,7 +735,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(56); - auto tmp = (avm_main_mem_op_d * (-avm_main_mem_op_d + FF(1))); + auto tmp = (avm_main_mem_op_c * (-avm_main_mem_op_c + FF(1))); tmp *= scaling_factor; std::get<56>(evals) += tmp; } @@ -742,7 +743,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(57); - auto tmp = (avm_main_rwa * (-avm_main_rwa + FF(1))); + auto tmp = (avm_main_mem_op_d * (-avm_main_mem_op_d + FF(1))); tmp *= scaling_factor; std::get<57>(evals) += tmp; } @@ -750,7 +751,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(58); - auto tmp = (avm_main_rwb * (-avm_main_rwb + FF(1))); + auto tmp = (avm_main_rwa * (-avm_main_rwa + FF(1))); tmp *= scaling_factor; std::get<58>(evals) += tmp; } @@ -758,7 +759,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(59); - auto tmp = (avm_main_rwc * (-avm_main_rwc + FF(1))); + auto tmp = (avm_main_rwb * (-avm_main_rwb + FF(1))); tmp *= scaling_factor; std::get<59>(evals) += tmp; } @@ -766,7 +767,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(60); - auto tmp = (avm_main_rwd * (-avm_main_rwd + FF(1))); + auto tmp = (avm_main_rwc * (-avm_main_rwc + FF(1))); tmp *= scaling_factor; std::get<60>(evals) += tmp; } @@ -774,7 +775,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(61); - auto tmp = (avm_main_ind_op_a * (-avm_main_ind_op_a + FF(1))); + auto tmp = (avm_main_rwd * (-avm_main_rwd + FF(1))); tmp *= scaling_factor; std::get<61>(evals) += tmp; } @@ -782,7 +783,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(62); - auto tmp = (avm_main_ind_op_b * (-avm_main_ind_op_b + FF(1))); + auto tmp = (avm_main_ind_op_a * (-avm_main_ind_op_a + FF(1))); tmp *= scaling_factor; std::get<62>(evals) += tmp; } @@ -790,7 +791,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(63); - auto tmp = (avm_main_ind_op_c * (-avm_main_ind_op_c + FF(1))); + auto tmp = (avm_main_ind_op_b * (-avm_main_ind_op_b + FF(1))); tmp *= scaling_factor; std::get<63>(evals) += tmp; } @@ -798,7 +799,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(64); - auto tmp = (avm_main_ind_op_d * (-avm_main_ind_op_d + FF(1))); + auto tmp = (avm_main_ind_op_c * (-avm_main_ind_op_c + FF(1))); tmp *= scaling_factor; std::get<64>(evals) += tmp; } @@ -806,8 +807,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(65); - 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_ind_op_d * (-avm_main_ind_op_d + FF(1))); tmp *= scaling_factor; std::get<65>(evals) += tmp; } @@ -816,7 +816,7 @@ template class avm_mainImpl { Avm_DECLARE_VIEWS(66); auto tmp = - ((avm_main_sel_op_fdiv * (-avm_main_op_err + FF(1))) * ((avm_main_ic * avm_main_ib) - avm_main_ia)); + (((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<66>(evals) += tmp; } @@ -824,8 +824,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(67); - 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_sel_op_fdiv * (-avm_main_op_err + FF(1))) * ((avm_main_ic * avm_main_ib) - avm_main_ia)); tmp *= scaling_factor; std::get<67>(evals) += tmp; } @@ -833,7 +833,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(68); - 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_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<68>(evals) += tmp; } @@ -841,7 +842,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(69); - auto tmp = (avm_main_sel_op_fdiv * (avm_main_r_in_tag - FF(6))); + 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<69>(evals) += tmp; } @@ -849,7 +850,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(70); - auto tmp = (avm_main_sel_op_fdiv * (avm_main_w_in_tag - FF(6))); + auto tmp = (avm_main_sel_op_fdiv * (avm_main_r_in_tag - FF(6))); tmp *= scaling_factor; std::get<70>(evals) += tmp; } @@ -857,7 +858,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(71); - auto tmp = (avm_main_op_err * ((avm_main_sel_op_fdiv + avm_main_sel_op_div) - FF(1))); + auto tmp = (avm_main_sel_op_fdiv * (avm_main_w_in_tag - FF(6))); tmp *= scaling_factor; std::get<71>(evals) += tmp; } @@ -865,6 +866,14 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(72); + auto tmp = (avm_main_op_err * ((avm_main_sel_op_fdiv + avm_main_sel_op_div) - FF(1))); + tmp *= scaling_factor; + std::get<72>(evals) += tmp; + } + // Contribution 73 + { + Avm_DECLARE_VIEWS(73); + auto tmp = ((((((((((avm_main_sel_op_sender + avm_main_sel_op_address) + avm_main_sel_op_chain_id) + avm_main_sel_op_version) + avm_main_sel_op_block_number) + @@ -875,11 +884,11 @@ template class avm_mainImpl { avm_main_sel_op_transaction_fee) * (-avm_main_q_kernel_lookup + FF(1))); tmp *= scaling_factor; - std::get<72>(evals) += tmp; + std::get<73>(evals) += tmp; } - // Contribution 73 + // Contribution 74 { - Avm_DECLARE_VIEWS(73); + Avm_DECLARE_VIEWS(74); auto tmp = (((((((((avm_main_sel_op_note_hash_exists + avm_main_sel_op_emit_note_hash) + avm_main_sel_op_nullifier_exists) + @@ -891,22 +900,13 @@ template class avm_mainImpl { avm_main_sel_op_sstore) * (-avm_main_q_kernel_output_lookup + FF(1))); tmp *= scaling_factor; - std::get<73>(evals) += tmp; - } - // Contribution 74 - { - Avm_DECLARE_VIEWS(74); - - auto tmp = (avm_main_sel_jump * (avm_main_pc_shift - avm_main_ia)); - tmp *= scaling_factor; std::get<74>(evals) += tmp; } // Contribution 75 { Avm_DECLARE_VIEWS(75); - auto tmp = (avm_main_sel_jumpi * (((-avm_main_id_zero + FF(1)) * (avm_main_pc_shift - avm_main_ia)) + - (avm_main_id_zero * ((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<75>(evals) += tmp; } @@ -914,8 +914,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(76); - auto tmp = (avm_main_sel_internal_call * - (avm_main_internal_return_ptr_shift - (avm_main_internal_return_ptr + FF(1)))); + auto tmp = (avm_main_sel_jumpi * (((-avm_main_id_zero + FF(1)) * (avm_main_pc_shift - avm_main_ia)) + + (avm_main_id_zero * ((avm_main_pc_shift - avm_main_pc) - FF(1))))); tmp *= scaling_factor; std::get<76>(evals) += tmp; } @@ -923,7 +923,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(77); - auto tmp = (avm_main_sel_internal_call * (avm_main_internal_return_ptr - avm_main_mem_idx_b)); + 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<77>(evals) += tmp; } @@ -931,7 +932,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(78); - auto tmp = (avm_main_sel_internal_call * (avm_main_pc_shift - avm_main_ia)); + auto tmp = (avm_main_sel_internal_call * (avm_main_internal_return_ptr - avm_main_mem_idx_b)); tmp *= scaling_factor; std::get<78>(evals) += tmp; } @@ -939,7 +940,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(79); - auto tmp = (avm_main_sel_internal_call * ((avm_main_pc + FF(1)) - avm_main_ib)); + auto tmp = (avm_main_sel_internal_call * (avm_main_pc_shift - avm_main_ia)); tmp *= scaling_factor; std::get<79>(evals) += tmp; } @@ -947,7 +948,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(80); - auto tmp = (avm_main_sel_internal_call * (avm_main_rwb - FF(1))); + auto tmp = (avm_main_sel_internal_call * ((avm_main_pc + FF(1)) - avm_main_ib)); tmp *= scaling_factor; std::get<80>(evals) += tmp; } @@ -955,7 +956,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(81); - auto tmp = (avm_main_sel_internal_call * (avm_main_mem_op_b - FF(1))); + auto tmp = (avm_main_sel_internal_call * (avm_main_rwb - FF(1))); tmp *= scaling_factor; std::get<81>(evals) += tmp; } @@ -963,8 +964,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(82); - 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_internal_call * (avm_main_mem_op_b - FF(1))); tmp *= scaling_factor; std::get<82>(evals) += tmp; } @@ -972,7 +972,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(83); - auto tmp = (avm_main_sel_internal_return * ((avm_main_internal_return_ptr - FF(1)) - avm_main_mem_idx_a)); + 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<83>(evals) += tmp; } @@ -980,7 +981,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(84); - auto tmp = (avm_main_sel_internal_return * (avm_main_pc_shift - avm_main_ia)); + auto tmp = (avm_main_sel_internal_return * ((avm_main_internal_return_ptr - FF(1)) - avm_main_mem_idx_a)); tmp *= scaling_factor; std::get<84>(evals) += tmp; } @@ -988,7 +989,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(85); - auto tmp = (avm_main_sel_internal_return * avm_main_rwa); + auto tmp = (avm_main_sel_internal_return * (avm_main_pc_shift - avm_main_ia)); tmp *= scaling_factor; std::get<85>(evals) += tmp; } @@ -996,7 +997,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(86); - auto tmp = (avm_main_sel_internal_return * (avm_main_mem_op_a - FF(1))); + auto tmp = (avm_main_sel_internal_return * avm_main_rwa); tmp *= scaling_factor; std::get<86>(evals) += tmp; } @@ -1004,6 +1005,14 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(87); + auto tmp = (avm_main_sel_internal_return * (avm_main_mem_op_a - FF(1))); + tmp *= scaling_factor; + std::get<87>(evals) += tmp; + } + // Contribution 88 + { + Avm_DECLARE_VIEWS(88); + auto tmp = (((avm_main_gas_cost_active - ((((((avm_main_sel_op_fdiv + ((((((((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_mul) + @@ -1036,15 +1045,16 @@ template class avm_mainImpl { avm_main_sel_op_emit_l2_to_l1_msg) + avm_main_sel_op_sload) + avm_main_sel_op_sstore))) - - (((avm_main_sel_jump + avm_main_sel_jumpi) + avm_main_sel_internal_call) + - avm_main_sel_internal_return)) - + ((((avm_main_sel_jump + avm_main_sel_jumpi) + avm_main_sel_internal_call) + + avm_main_sel_internal_return) + + avm_main_sel_external_call)) - avm_main_mem_op_activate_gas); tmp *= scaling_factor; - std::get<87>(evals) += tmp; + std::get<88>(evals) += tmp; } - // Contribution 88 + // Contribution 89 { - Avm_DECLARE_VIEWS(88); + Avm_DECLARE_VIEWS(89); auto tmp = ((((-avm_main_first + FF(1)) * (-avm_main_sel_halt + FF(1))) * ((((((avm_main_sel_op_fdiv + @@ -1080,30 +1090,30 @@ template class avm_mainImpl { avm_main_sel_op_sstore))) * (avm_main_pc_shift - (avm_main_pc + FF(1)))); tmp *= scaling_factor; - std::get<88>(evals) += tmp; + std::get<89>(evals) += tmp; } - // Contribution 89 + // Contribution 90 { - Avm_DECLARE_VIEWS(89); + Avm_DECLARE_VIEWS(90); 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<89>(evals) += tmp; + std::get<90>(evals) += tmp; } - // Contribution 90 + // Contribution 91 { - Avm_DECLARE_VIEWS(90); + Avm_DECLARE_VIEWS(91); auto tmp = ((avm_main_sel_internal_call + avm_main_sel_internal_return) * (avm_main_space_id - FF(255))); tmp *= scaling_factor; - std::get<90>(evals) += tmp; + std::get<91>(evals) += tmp; } - // Contribution 91 + // Contribution 92 { - Avm_DECLARE_VIEWS(91); + Avm_DECLARE_VIEWS(92); auto tmp = (((((((avm_main_sel_op_fdiv + ((((((((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_mul) + @@ -1138,22 +1148,14 @@ template class avm_mainImpl { avm_main_sel_op_sstore)) * (avm_main_call_ptr - avm_main_space_id)); tmp *= scaling_factor; - std::get<91>(evals) += tmp; - } - // Contribution 92 - { - Avm_DECLARE_VIEWS(92); - - auto tmp = ((avm_main_sel_cmov + avm_main_sel_jumpi) * - (((avm_main_id * avm_main_inv) - FF(1)) + avm_main_id_zero)); - tmp *= scaling_factor; std::get<92>(evals) += tmp; } // Contribution 93 { Avm_DECLARE_VIEWS(93); - auto tmp = (((avm_main_sel_cmov + avm_main_sel_jumpi) * avm_main_id_zero) * (-avm_main_inv + FF(1))); + auto tmp = ((avm_main_sel_cmov + avm_main_sel_jumpi) * + (((avm_main_id * avm_main_inv) - FF(1)) + avm_main_id_zero)); tmp *= scaling_factor; std::get<93>(evals) += tmp; } @@ -1161,7 +1163,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(94); - 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_cmov + avm_main_sel_jumpi) * avm_main_id_zero) * (-avm_main_inv + FF(1))); tmp *= scaling_factor; std::get<94>(evals) += tmp; } @@ -1169,7 +1171,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(95); - auto tmp = (avm_main_sel_mov_b - (avm_main_sel_cmov * avm_main_id_zero)); + 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<95>(evals) += tmp; } @@ -1177,7 +1179,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(96); - auto tmp = (avm_main_sel_mov_a * (avm_main_ia - avm_main_ic)); + auto tmp = (avm_main_sel_mov_b - (avm_main_sel_cmov * avm_main_id_zero)); tmp *= scaling_factor; std::get<96>(evals) += tmp; } @@ -1185,7 +1187,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(97); - auto tmp = (avm_main_sel_mov_b * (avm_main_ib - avm_main_ic)); + auto tmp = (avm_main_sel_mov_a * (avm_main_ia - avm_main_ic)); tmp *= scaling_factor; std::get<97>(evals) += tmp; } @@ -1193,7 +1195,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(98); - 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_mov_b * (avm_main_ib - avm_main_ic)); tmp *= scaling_factor; std::get<98>(evals) += tmp; } @@ -1201,6 +1203,14 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(99); + 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<99>(evals) += tmp; + } + // Contribution 100 + { + Avm_DECLARE_VIEWS(100); + 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) + @@ -1214,11 +1224,11 @@ template class avm_mainImpl { (-avm_main_tag_err + FF(1))) * (-avm_main_op_err + FF(1)))); tmp *= scaling_factor; - std::get<99>(evals) += tmp; + std::get<100>(evals) += tmp; } - // Contribution 100 + // Contribution 101 { - Avm_DECLARE_VIEWS(100); + Avm_DECLARE_VIEWS(101); auto tmp = ((((((((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_mul) + avm_main_sel_op_div) + @@ -1230,21 +1240,13 @@ template class avm_mainImpl { avm_main_sel_op_shl) * (avm_main_alu_in_tag - avm_main_r_in_tag)); tmp *= scaling_factor; - std::get<100>(evals) += tmp; - } - // Contribution 101 - { - Avm_DECLARE_VIEWS(101); - - auto tmp = (avm_main_sel_op_cast * (avm_main_alu_in_tag - avm_main_w_in_tag)); - tmp *= scaling_factor; std::get<101>(evals) += tmp; } // Contribution 102 { Avm_DECLARE_VIEWS(102); - auto tmp = (avm_main_sel_op_sender * (avm_kernel_kernel_in_offset - FF(0))); + auto tmp = (avm_main_sel_op_cast * (avm_main_alu_in_tag - avm_main_w_in_tag)); tmp *= scaling_factor; std::get<102>(evals) += tmp; } @@ -1252,7 +1254,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(103); - auto tmp = (avm_main_sel_op_address * (avm_kernel_kernel_in_offset - FF(1))); + auto tmp = (avm_main_sel_op_sender * (avm_kernel_kernel_in_offset - FF(0))); tmp *= scaling_factor; std::get<103>(evals) += tmp; } @@ -1260,7 +1262,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(104); - auto tmp = (avm_main_sel_op_fee_per_da_gas * (avm_kernel_kernel_in_offset - FF(35))); + auto tmp = (avm_main_sel_op_address * (avm_kernel_kernel_in_offset - FF(1))); tmp *= scaling_factor; std::get<104>(evals) += tmp; } @@ -1268,7 +1270,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(105); - auto tmp = (avm_main_sel_op_fee_per_l2_gas * (avm_kernel_kernel_in_offset - FF(36))); + auto tmp = (avm_main_sel_op_fee_per_da_gas * (avm_kernel_kernel_in_offset - FF(35))); tmp *= scaling_factor; std::get<105>(evals) += tmp; } @@ -1276,7 +1278,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(106); - auto tmp = (avm_main_sel_op_transaction_fee * (avm_kernel_kernel_in_offset - FF(40))); + auto tmp = (avm_main_sel_op_fee_per_l2_gas * (avm_kernel_kernel_in_offset - FF(36))); tmp *= scaling_factor; std::get<106>(evals) += tmp; } @@ -1284,7 +1286,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(107); - auto tmp = (avm_main_sel_op_chain_id * (avm_kernel_kernel_in_offset - FF(29))); + auto tmp = (avm_main_sel_op_transaction_fee * (avm_kernel_kernel_in_offset - FF(40))); tmp *= scaling_factor; std::get<107>(evals) += tmp; } @@ -1292,7 +1294,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(108); - auto tmp = (avm_main_sel_op_version * (avm_kernel_kernel_in_offset - FF(30))); + auto tmp = (avm_main_sel_op_chain_id * (avm_kernel_kernel_in_offset - FF(29))); tmp *= scaling_factor; std::get<108>(evals) += tmp; } @@ -1300,7 +1302,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(109); - auto tmp = (avm_main_sel_op_block_number * (avm_kernel_kernel_in_offset - FF(31))); + auto tmp = (avm_main_sel_op_version * (avm_kernel_kernel_in_offset - FF(30))); tmp *= scaling_factor; std::get<109>(evals) += tmp; } @@ -1308,7 +1310,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(110); - auto tmp = (avm_main_sel_op_coinbase * (avm_kernel_kernel_in_offset - FF(33))); + auto tmp = (avm_main_sel_op_block_number * (avm_kernel_kernel_in_offset - FF(31))); tmp *= scaling_factor; std::get<110>(evals) += tmp; } @@ -1316,7 +1318,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(111); - auto tmp = (avm_main_sel_op_timestamp * (avm_kernel_kernel_in_offset - FF(32))); + auto tmp = (avm_main_sel_op_coinbase * (avm_kernel_kernel_in_offset - FF(33))); tmp *= scaling_factor; std::get<111>(evals) += tmp; } @@ -1324,8 +1326,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(112); - auto tmp = (avm_main_sel_op_note_hash_exists * - (avm_kernel_kernel_out_offset - (avm_kernel_note_hash_exist_write_offset + FF(0)))); + auto tmp = (avm_main_sel_op_timestamp * (avm_kernel_kernel_in_offset - FF(32))); tmp *= scaling_factor; std::get<112>(evals) += tmp; } @@ -1333,7 +1334,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(113); - auto tmp = (avm_main_first * avm_kernel_note_hash_exist_write_offset); + auto tmp = (avm_main_sel_op_note_hash_exists * + (avm_kernel_kernel_out_offset - (avm_kernel_note_hash_exist_write_offset + FF(0)))); tmp *= scaling_factor; std::get<113>(evals) += tmp; } @@ -1341,8 +1343,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(114); - auto tmp = (avm_main_sel_op_emit_note_hash * - (avm_kernel_kernel_out_offset - (avm_kernel_emit_note_hash_write_offset + FF(160)))); + auto tmp = (avm_main_first * avm_kernel_note_hash_exist_write_offset); tmp *= scaling_factor; std::get<114>(evals) += tmp; } @@ -1350,7 +1351,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(115); - auto tmp = (avm_main_first * avm_kernel_emit_note_hash_write_offset); + auto tmp = (avm_main_sel_op_emit_note_hash * + (avm_kernel_kernel_out_offset - (avm_kernel_emit_note_hash_write_offset + FF(160)))); tmp *= scaling_factor; std::get<115>(evals) += tmp; } @@ -1358,8 +1360,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(116); - auto tmp = (avm_main_sel_op_nullifier_exists * - (avm_kernel_kernel_out_offset - (avm_kernel_nullifier_exists_write_offset + FF(32)))); + auto tmp = (avm_main_first * avm_kernel_emit_note_hash_write_offset); tmp *= scaling_factor; std::get<116>(evals) += tmp; } @@ -1367,7 +1368,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(117); - auto tmp = (avm_main_first * avm_kernel_nullifier_exists_write_offset); + auto tmp = (avm_main_sel_op_nullifier_exists * + (avm_kernel_kernel_out_offset - (avm_kernel_nullifier_exists_write_offset + FF(32)))); tmp *= scaling_factor; std::get<117>(evals) += tmp; } @@ -1375,8 +1377,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(118); - auto tmp = (avm_main_sel_op_emit_nullifier * - (avm_kernel_kernel_out_offset - (avm_kernel_emit_nullifier_write_offset + FF(176)))); + auto tmp = (avm_main_first * avm_kernel_nullifier_exists_write_offset); tmp *= scaling_factor; std::get<118>(evals) += tmp; } @@ -1384,7 +1385,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(119); - auto tmp = (avm_main_first * avm_kernel_emit_nullifier_write_offset); + auto tmp = (avm_main_sel_op_emit_nullifier * + (avm_kernel_kernel_out_offset - (avm_kernel_emit_nullifier_write_offset + FF(176)))); tmp *= scaling_factor; std::get<119>(evals) += tmp; } @@ -1392,8 +1394,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(120); - auto tmp = (avm_main_sel_op_l1_to_l2_msg_exists * - (avm_kernel_kernel_out_offset - (avm_kernel_l1_to_l2_msg_exists_write_offset + FF(96)))); + auto tmp = (avm_main_first * avm_kernel_emit_nullifier_write_offset); tmp *= scaling_factor; std::get<120>(evals) += tmp; } @@ -1401,7 +1402,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(121); - auto tmp = (avm_main_first * avm_kernel_l1_to_l2_msg_exists_write_offset); + auto tmp = (avm_main_sel_op_l1_to_l2_msg_exists * + (avm_kernel_kernel_out_offset - (avm_kernel_l1_to_l2_msg_exists_write_offset + FF(96)))); tmp *= scaling_factor; std::get<121>(evals) += tmp; } @@ -1409,8 +1411,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(122); - auto tmp = (avm_main_sel_op_emit_unencrypted_log * - (avm_kernel_kernel_out_offset - (avm_kernel_emit_unencrypted_log_write_offset + FF(194)))); + auto tmp = (avm_main_first * avm_kernel_l1_to_l2_msg_exists_write_offset); tmp *= scaling_factor; std::get<122>(evals) += tmp; } @@ -1418,7 +1419,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(123); - auto tmp = (avm_main_first * avm_kernel_emit_unencrypted_log_write_offset); + auto tmp = (avm_main_sel_op_emit_unencrypted_log * + (avm_kernel_kernel_out_offset - (avm_kernel_emit_unencrypted_log_write_offset + FF(194)))); tmp *= scaling_factor; std::get<123>(evals) += tmp; } @@ -1426,8 +1428,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(124); - auto tmp = (avm_main_sel_op_emit_l2_to_l1_msg * - (avm_kernel_kernel_out_offset - (avm_kernel_emit_l2_to_l1_msg_write_offset + FF(192)))); + auto tmp = (avm_main_first * avm_kernel_emit_unencrypted_log_write_offset); tmp *= scaling_factor; std::get<124>(evals) += tmp; } @@ -1435,7 +1436,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(125); - auto tmp = (avm_main_first * avm_kernel_emit_l2_to_l1_msg_write_offset); + auto tmp = (avm_main_sel_op_emit_l2_to_l1_msg * + (avm_kernel_kernel_out_offset - (avm_kernel_emit_l2_to_l1_msg_write_offset + FF(192)))); tmp *= scaling_factor; std::get<125>(evals) += tmp; } @@ -1443,8 +1445,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(126); - auto tmp = - (avm_main_sel_op_sload * (avm_kernel_kernel_out_offset - (avm_kernel_sload_write_offset + FF(112)))); + auto tmp = (avm_main_first * avm_kernel_emit_l2_to_l1_msg_write_offset); tmp *= scaling_factor; std::get<126>(evals) += tmp; } @@ -1452,7 +1453,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(127); - auto tmp = (avm_main_first * avm_kernel_sload_write_offset); + auto tmp = + (avm_main_sel_op_sload * (avm_kernel_kernel_out_offset - (avm_kernel_sload_write_offset + FF(112)))); tmp *= scaling_factor; std::get<127>(evals) += tmp; } @@ -1460,8 +1462,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(128); - auto tmp = - (avm_main_sel_op_sstore * (avm_kernel_kernel_out_offset - (avm_kernel_sstore_write_offset + FF(144)))); + auto tmp = (avm_main_first * avm_kernel_sload_write_offset); tmp *= scaling_factor; std::get<128>(evals) += tmp; } @@ -1469,7 +1470,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(129); - auto tmp = (avm_main_first * avm_kernel_sstore_write_offset); + auto tmp = + (avm_main_sel_op_sstore * (avm_kernel_kernel_out_offset - (avm_kernel_sstore_write_offset + FF(144)))); tmp *= scaling_factor; std::get<129>(evals) += tmp; } @@ -1477,6 +1479,14 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(130); + auto tmp = (avm_main_first * avm_kernel_sstore_write_offset); + tmp *= scaling_factor; + std::get<130>(evals) += tmp; + } + // Contribution 131 + { + Avm_DECLARE_VIEWS(131); + auto tmp = (((((((((avm_main_sel_op_note_hash_exists + avm_main_sel_op_emit_note_hash) + avm_main_sel_op_nullifier_exists) + avm_main_sel_op_emit_nullifier) + @@ -1487,23 +1497,23 @@ template class avm_mainImpl { avm_main_sel_op_sstore) * (avm_kernel_side_effect_counter_shift - (avm_kernel_side_effect_counter + FF(1)))); tmp *= scaling_factor; - std::get<130>(evals) += tmp; + std::get<131>(evals) += tmp; } - // Contribution 131 + // Contribution 132 { - Avm_DECLARE_VIEWS(131); + Avm_DECLARE_VIEWS(132); auto tmp = (avm_main_bin_op_id - (avm_main_sel_op_or + (avm_main_sel_op_xor * FF(2)))); tmp *= scaling_factor; - std::get<131>(evals) += tmp; + std::get<132>(evals) += tmp; } - // Contribution 132 + // Contribution 133 { - Avm_DECLARE_VIEWS(132); + Avm_DECLARE_VIEWS(133); 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<132>(evals) += tmp; + std::get<133>(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 8fd2367fab7..4afab78909a 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp @@ -195,6 +195,7 @@ [[maybe_unused]] auto avm_main_rwc = View(new_term.avm_main_rwc); \ [[maybe_unused]] auto avm_main_rwd = View(new_term.avm_main_rwd); \ [[maybe_unused]] auto avm_main_sel_cmov = View(new_term.avm_main_sel_cmov); \ + [[maybe_unused]] auto avm_main_sel_external_call = View(new_term.avm_main_sel_external_call); \ [[maybe_unused]] auto avm_main_sel_halt = View(new_term.avm_main_sel_halt); \ [[maybe_unused]] auto avm_main_sel_internal_call = View(new_term.avm_main_sel_internal_call); \ [[maybe_unused]] auto avm_main_sel_internal_return = View(new_term.avm_main_sel_internal_return); \ 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 b27edb64782..d4c76018f39 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp @@ -41,6 +41,9 @@ static const uint8_t INTERNAL_CALL_SPACE_ID = 255; static const uint32_t MAX_SIZE_INTERNAL_STACK = 1 << 16; // Side effect counter -> value -using ExecutionHints = std::unordered_map; +struct ExecutionHints { + std::unordered_map side_effect_hints; + std::vector> returndata_hints; +}; } // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp index f932b7d2fa3..3354a071d4b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp @@ -24,6 +24,16 @@ const std::vector getter_format = { OperandType::UINT32, }; +const std::vector external_call_format = { OperandType::INDIRECT, + /*gasOffset=*/OperandType::UINT32, + /*addrOffset=*/OperandType::UINT32, + /*argsOffset=*/OperandType::UINT32, + /*argsSize=*/OperandType::UINT32, + /*retOffset=*/OperandType::UINT32, + /*retSize*/ OperandType::UINT32, + /*successOffset=*/OperandType::UINT32, + /*functionSelector=*/OperandType::UINT32 }; + // Contrary to TS, the format does not contain the opcode byte which prefixes any instruction. // The format for OpCode::SET has to be handled separately as it is variable based on the tag. const std::unordered_map> OPCODE_WIRE_FORMAT = { @@ -102,7 +112,7 @@ const std::unordered_map> OPCODE_WIRE_FORMAT = // EMITUNENCRYPTEDLOG, // SENDL2TOL1MSG, // Control Flow - Contract Calls - // CALL, + { OpCode::CALL, external_call_format }, // STATICCALL, // DELEGATECALL, -- not in simulator { OpCode::RETURN, { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32 } }, 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 15c3c7f7c12..e45b8f80afc 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp @@ -438,6 +438,7 @@ std::vector Execution::gen_trace(std::vector const& instructio std::get(inst.operands.at(1)), std::get(inst.operands.at(2))); returndata.insert(returndata.end(), ret.begin(), ret.end()); + break; } case OpCode::DEBUGLOG: @@ -445,6 +446,17 @@ std::vector Execution::gen_trace(std::vector const& instructio // and adds a valid row to the trace. trace_builder.jump(pc + 1); break; + case OpCode::CALL: + trace_builder.op_call(std::get(inst.operands.at(0)), + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2)), + std::get(inst.operands.at(3)), + std::get(inst.operands.at(4)), + std::get(inst.operands.at(5)), + std::get(inst.operands.at(6)), + std::get(inst.operands.at(7)), + std::get(inst.operands.at(8))); + break; case OpCode::TORADIXLE: trace_builder.op_to_radix_le(std::get(inst.operands.at(0)), std::get(inst.operands.at(1)), 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 c63a6a7e0ad..f01b3509cf9 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp @@ -47,6 +47,7 @@ void AvmTraceBuilder::reset() alu_trace_builder.reset(); bin_trace_builder.reset(); kernel_trace_builder.reset(); + return_data_counter = 0; } AvmTraceBuilder::IndirectThreeResolution AvmTraceBuilder::resolve_ind_three( @@ -1368,7 +1369,7 @@ Row AvmTraceBuilder::create_kernel_output_opcode_with_set_metadata_output_from_h AvmMemTraceBuilder::MemRead read_a = mem_trace_builder.read_and_load_from_memory( call_ptr, clk, IntermRegister::IA, data_offset, AvmMemoryTag::FF, AvmMemoryTag::U8); - FF exists = execution_hints.at(side_effect_counter); + FF exists = execution_hints.side_effect_hints.at(side_effect_counter); // TODO: throw error if incorrect mem_trace_builder.write_into_memory( @@ -1398,7 +1399,7 @@ Row AvmTraceBuilder::create_kernel_output_opcode_with_set_value_from_hint(uint32 uint32_t data_offset, uint32_t metadata_offset) { - FF value = execution_hints.at(side_effect_counter); + FF value = execution_hints.side_effect_hints.at(side_effect_counter); // TODO: throw error if incorrect mem_trace_builder.write_into_memory( @@ -2295,6 +2296,136 @@ uint32_t AvmTraceBuilder::read_slice_to_memory(uint8_t space_id, return num_main_rows; } +/** + * @brief External Call with direct or indirect memory access. + * + * TODO: Use the indirect later to support all the indirect accesses + * NOTE: we do not constrain this here as it's behaviour will change fully once we have a full enqueued function + * call in one vm circuit + * @param indirect byte encoding information about indirect/direct memory access. + * @param gas_offset An index in memory pointing to the first of the gas value tuple (l2Gas, daGas) + * @param addr_offset An index in memory pointing to the target contract address + * @param args_offset An index in memory pointing to the first value of the input array for the external call + * @param args_size The number of values in the input array for the external call + * @param ret_offset An index in memory pointing to where the first value of the external calls return value should be + * stored. + * @param ret_size The number of values in the return array + * @param success_offset An index in memory pointing to where the success flag (U8) of the external call should be + * stored + * @param function_selector_offset An index in memory pointing to the function selector of the external call (TEMP) + */ +void AvmTraceBuilder::op_call([[maybe_unused]] uint8_t indirect, + uint32_t gas_offset, + uint32_t addr_offset, + uint32_t args_offset, + uint32_t args_size, + uint32_t ret_offset, + uint32_t ret_size, + uint32_t success_offset, + uint32_t function_selector_offset) +{ + auto clk = static_cast(main_trace.size()) + 1; + // We can load up to 4 things per row + auto register_order = std::array{ IntermRegister::IA, IntermRegister::IB, IntermRegister::IC, IntermRegister::ID }; + // Constrain gas cost + gas_trace_builder.constrain_gas_lookup(clk, OpCode::CALL); + // Indirect is ZEROTH, SECOND and FOURTH bit COME BACK TO MAKING THIS ALL SUPPORTED + auto read_ind_gas_offset = + mem_trace_builder.indirect_read_and_load_from_memory(call_ptr, clk, IndirectRegister::IND_A, gas_offset); + auto read_ind_args_offset = + mem_trace_builder.indirect_read_and_load_from_memory(call_ptr, clk, IndirectRegister::IND_C, args_offset); + + std::vector first_row_load = { + uint32_t(read_ind_gas_offset.val), addr_offset, uint32_t(read_ind_args_offset.val), args_size + }; + std::vector first_row_values = {}; + for (uint32_t j = 0; j < first_row_load.size(); j++) { + // We just read and load to set up the constraints, we dont actually use these values for now. + auto mem_read = mem_trace_builder.read_and_load_from_memory(call_ptr, + clk, + register_order[j % register_order.size()], + first_row_load[j], + AvmMemoryTag::U32, + AvmMemoryTag::U0); + first_row_values.emplace_back(mem_read.val); + } + + // We read the input and output addresses in one row as they should contain FF elements + main_trace.push_back(Row{ + .avm_main_clk = clk, + .avm_main_ia = first_row_values[0], /* gas_offset */ + .avm_main_ib = first_row_values[1], /* addr_offset */ + .avm_main_ic = first_row_values[2], /* args_offset */ + .avm_main_id = first_row_values[3], /* args_size */ + .avm_main_ind_a = gas_offset, + .avm_main_ind_c = args_offset, + .avm_main_ind_op_a = FF(1), + .avm_main_ind_op_c = FF(1), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_mem_idx_a = read_ind_gas_offset.val, + .avm_main_mem_idx_b = addr_offset, + .avm_main_mem_idx_c = read_ind_args_offset.val, + .avm_main_mem_idx_d = args_size, + .avm_main_mem_op_a = FF(1), + .avm_main_mem_op_b = FF(1), + .avm_main_mem_op_c = FF(1), + .avm_main_mem_op_d = FF(1), + .avm_main_pc = FF(pc++), + .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .avm_main_sel_external_call = FF(1), + }); + clk++; + // Read the rest on a separate line, remember that the 4th operand is indirect + auto read_ind_ret_offset = + mem_trace_builder.indirect_read_and_load_from_memory(call_ptr, clk, IndirectRegister::IND_A, ret_offset); + std::vector second_row_values = {}; + std::vector second_row_load = { + uint32_t(read_ind_ret_offset.val), function_selector_offset, ret_size, success_offset + }; + for (uint32_t j = 0; j < second_row_load.size(); j++) { + // We just read and load to set up the constraints, we dont actually use these values for now. + auto mem_read = mem_trace_builder.read_and_load_from_memory(call_ptr, + clk, + register_order[j % register_order.size()], + second_row_load[j], + AvmMemoryTag::U32, + AvmMemoryTag::U0); + second_row_values.emplace_back(mem_read.val); + } + main_trace.push_back(Row{ + .avm_main_clk = clk, + .avm_main_ia = second_row_values[0], /* ret_offset */ + .avm_main_ib = second_row_values[1], /* function_selector_offset */ + .avm_main_ic = second_row_values[2], /* ret_size */ + .avm_main_id = second_row_values[3], /* success_offset */ + .avm_main_ind_a = ret_offset, + .avm_main_ind_op_a = FF(1), + .avm_main_internal_return_ptr = FF(internal_return_ptr), + .avm_main_mem_idx_a = read_ind_ret_offset.val, + .avm_main_mem_idx_b = function_selector_offset, + .avm_main_mem_idx_c = ret_size, + .avm_main_mem_idx_d = success_offset, + .avm_main_mem_op_a = FF(1), + .avm_main_mem_op_b = FF(1), + .avm_main_mem_op_c = FF(1), + .avm_main_mem_op_d = FF(1), + .avm_main_pc = FF(pc), + .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), + }); + clk++; + write_slice_to_memory(call_ptr, + clk, + uint32_t(read_ind_ret_offset.val), + AvmMemoryTag::U0, + AvmMemoryTag::FF, + internal_return_ptr, + execution_hints.returndata_hints.at(return_data_counter)); + return_data_counter++; + clk++; + write_slice_to_memory( + call_ptr, clk, success_offset, AvmMemoryTag::U0, AvmMemoryTag::U8, internal_return_ptr, { FF(1) }); +} + /** * @brief To_Radix_LE with direct or indirect memory access. * 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 dcb4c370b33..1bc54468ca2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp @@ -151,6 +151,17 @@ class AvmTraceBuilder { // indirect: return(M[M[ret_offset]:M[ret_offset]+ret_size]) std::vector return_op(uint8_t indirect, uint32_t ret_offset, uint32_t ret_size); + // Calls + void op_call(uint8_t indirect, + uint32_t gas_offset, + uint32_t addr_offset, + uint32_t args_offset, + uint32_t args_size, + uint32_t ret_offset, + uint32_t ret_size, + uint32_t success_offset, + uint32_t function_selector_offset); + // Gadgets // --- Conversions // To Radix LE conversion operation. @@ -283,6 +294,7 @@ class AvmTraceBuilder { // Side effect counter will incremenent when any state writing values are // encountered uint32_t side_effect_counter = 0; + uint32_t return_data_counter = 0; // Execution hints aid witness solving for instructions that require auxiliary information to construct // Mapping of side effect counter -> value diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/constants.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/constants.hpp index 06ff6677574..9a38bfee590 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/constants.hpp @@ -58,4 +58,4 @@ inline const uint32_t UNENCRYPTED_LOGS_OFFSET = // L2 and Da gas left are the 3rd last and 2nd last items in the context kernel inputs respectively inline const std::size_t DA_GAS_LEFT_CONTEXT_INPUTS_OFFSET = KERNEL_INPUTS_LENGTH - 3; -inline const std::size_t L2_GAS_LEFT_CONTEXT_INPUTS_OFFSET = KERNEL_INPUTS_LENGTH - 2; \ No newline at end of file +inline const std::size_t L2_GAS_LEFT_CONTEXT_INPUTS_OFFSET = KERNEL_INPUTS_LENGTH - 2; 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 f9e597143eb..0c990afecb4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp @@ -262,6 +262,7 @@ template struct AvmFullRow { FF avm_main_rwc{}; FF avm_main_rwd{}; FF avm_main_sel_cmov{}; + FF avm_main_sel_external_call{}; FF avm_main_sel_halt{}; FF avm_main_sel_internal_call{}; FF avm_main_sel_internal_return{}; @@ -522,8 +523,8 @@ class AvmCircuitBuilder { using Polynomial = Flavor::Polynomial; using ProverPolynomials = Flavor::ProverPolynomials; - static constexpr size_t num_fixed_columns = 429; - static constexpr size_t num_polys = 365; + static constexpr size_t num_fixed_columns = 430; + static constexpr size_t num_polys = 366; std::vector rows; void set_trace(std::vector&& trace) { rows = std::move(trace); } @@ -724,6 +725,7 @@ class AvmCircuitBuilder { polys.avm_main_rwc[i] = rows[i].avm_main_rwc; polys.avm_main_rwd[i] = rows[i].avm_main_rwd; polys.avm_main_sel_cmov[i] = rows[i].avm_main_sel_cmov; + polys.avm_main_sel_external_call[i] = rows[i].avm_main_sel_external_call; polys.avm_main_sel_halt[i] = rows[i].avm_main_sel_halt; polys.avm_main_sel_internal_call[i] = rows[i].avm_main_sel_internal_call; polys.avm_main_sel_internal_return[i] = rows[i].avm_main_sel_internal_return; diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp index 9465d14df18..d6f8497dcbc 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp @@ -94,11 +94,11 @@ class AvmFlavor { using RelationSeparator = FF; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; - static constexpr size_t NUM_WITNESS_ENTITIES = 363; + static constexpr size_t NUM_WITNESS_ENTITIES = 364; 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 = 429; + static constexpr size_t NUM_ALL_ENTITIES = 430; using GrandProductRelations = std::tuple, perm_main_bin_relation, @@ -423,6 +423,7 @@ class AvmFlavor { avm_main_rwc, avm_main_rwd, avm_main_sel_cmov, + avm_main_sel_external_call, avm_main_sel_halt, avm_main_sel_internal_call, avm_main_sel_internal_return, @@ -789,6 +790,7 @@ class AvmFlavor { avm_main_rwc, avm_main_rwd, avm_main_sel_cmov, + avm_main_sel_external_call, avm_main_sel_halt, avm_main_sel_internal_call, avm_main_sel_internal_return, @@ -1160,6 +1162,7 @@ class AvmFlavor { avm_main_rwc, avm_main_rwd, avm_main_sel_cmov, + avm_main_sel_external_call, avm_main_sel_halt, avm_main_sel_internal_call, avm_main_sel_internal_return, @@ -1592,6 +1595,7 @@ class AvmFlavor { avm_main_rwc, avm_main_rwd, avm_main_sel_cmov, + avm_main_sel_external_call, avm_main_sel_halt, avm_main_sel_internal_call, avm_main_sel_internal_return, @@ -2024,6 +2028,7 @@ class AvmFlavor { avm_main_rwc, avm_main_rwd, avm_main_sel_cmov, + avm_main_sel_external_call, avm_main_sel_halt, avm_main_sel_internal_call, avm_main_sel_internal_return, @@ -2803,6 +2808,7 @@ class AvmFlavor { Base::avm_main_rwc = "AVM_MAIN_RWC"; Base::avm_main_rwd = "AVM_MAIN_RWD"; Base::avm_main_sel_cmov = "AVM_MAIN_SEL_CMOV"; + Base::avm_main_sel_external_call = "AVM_MAIN_SEL_EXTERNAL_CALL"; Base::avm_main_sel_halt = "AVM_MAIN_SEL_HALT"; Base::avm_main_sel_internal_call = "AVM_MAIN_SEL_INTERNAL_CALL"; Base::avm_main_sel_internal_return = "AVM_MAIN_SEL_INTERNAL_RETURN"; @@ -3185,6 +3191,7 @@ class AvmFlavor { Commitment avm_main_rwc; Commitment avm_main_rwd; Commitment avm_main_sel_cmov; + Commitment avm_main_sel_external_call; Commitment avm_main_sel_halt; Commitment avm_main_sel_internal_call; Commitment avm_main_sel_internal_return; @@ -3581,6 +3588,7 @@ class AvmFlavor { avm_main_rwc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_rwd = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_cmov = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + avm_main_sel_external_call = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_halt = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_internal_call = deserialize_from_buffer(Transcript::proof_data, num_frs_read); avm_main_sel_internal_return = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -3973,6 +3981,7 @@ class AvmFlavor { serialize_to_buffer(avm_main_rwc, Transcript::proof_data); serialize_to_buffer(avm_main_rwd, Transcript::proof_data); serialize_to_buffer(avm_main_sel_cmov, Transcript::proof_data); + serialize_to_buffer(avm_main_sel_external_call, Transcript::proof_data); serialize_to_buffer(avm_main_sel_halt, Transcript::proof_data); serialize_to_buffer(avm_main_sel_internal_call, Transcript::proof_data); serialize_to_buffer(avm_main_sel_internal_return, 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 9d310a20005..480caa57aea 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp @@ -252,6 +252,7 @@ void AvmProver::execute_wire_commitments_round() witness_commitments.avm_main_rwc = commitment_key->commit(key->avm_main_rwc); witness_commitments.avm_main_rwd = commitment_key->commit(key->avm_main_rwd); witness_commitments.avm_main_sel_cmov = commitment_key->commit(key->avm_main_sel_cmov); + witness_commitments.avm_main_sel_external_call = commitment_key->commit(key->avm_main_sel_external_call); witness_commitments.avm_main_sel_halt = commitment_key->commit(key->avm_main_sel_halt); witness_commitments.avm_main_sel_internal_call = commitment_key->commit(key->avm_main_sel_internal_call); witness_commitments.avm_main_sel_internal_return = commitment_key->commit(key->avm_main_sel_internal_return); @@ -617,6 +618,8 @@ void AvmProver::execute_wire_commitments_round() transcript->send_to_verifier(commitment_labels.avm_main_rwc, witness_commitments.avm_main_rwc); transcript->send_to_verifier(commitment_labels.avm_main_rwd, witness_commitments.avm_main_rwd); transcript->send_to_verifier(commitment_labels.avm_main_sel_cmov, witness_commitments.avm_main_sel_cmov); + transcript->send_to_verifier(commitment_labels.avm_main_sel_external_call, + witness_commitments.avm_main_sel_external_call); transcript->send_to_verifier(commitment_labels.avm_main_sel_halt, witness_commitments.avm_main_sel_halt); transcript->send_to_verifier(commitment_labels.avm_main_sel_internal_call, witness_commitments.avm_main_sel_internal_call); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp index f659fb269a7..429fca41dc7 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp @@ -376,6 +376,8 @@ bool AvmVerifier::verify_proof(const HonkProof& proof, const std::vectortemplate receive_from_prover(commitment_labels.avm_main_rwd); commitments.avm_main_sel_cmov = transcript->template receive_from_prover(commitment_labels.avm_main_sel_cmov); + commitments.avm_main_sel_external_call = + transcript->template receive_from_prover(commitment_labels.avm_main_sel_external_call); commitments.avm_main_sel_halt = transcript->template receive_from_prover(commitment_labels.avm_main_sel_halt); commitments.avm_main_sel_internal_call = 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 6e6b1239423..a18b0b5403f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp @@ -1667,7 +1667,7 @@ TEST_F(AvmExecutionTests, kernelOutputStorageOpcodes) // Generate Hint for Sload operation ExecutionHints execution_hints = {}; - execution_hints[0] = FF(42); // side effect counter 0 = value 42 + execution_hints.side_effect_hints[0] = FF(42); // side effect counter 0 = value 42 auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec, execution_hints); @@ -1746,9 +1746,9 @@ TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes) // Generate Hint for Sload operation ExecutionHints execution_hints = {}; - execution_hints[0] = 1; // Side effect counter 0 = true - execution_hints[1] = 1; // Side effect counter 1 = true - execution_hints[2] = 1; // Side effect counter 2 = true + execution_hints.side_effect_hints[0] = 1; // Side effect counter 0 = true + execution_hints.side_effect_hints[1] = 1; // Side effect counter 1 = true + execution_hints.side_effect_hints[2] = 1; // Side effect counter 2 = true auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec, execution_hints); @@ -1797,6 +1797,74 @@ TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes) validate_trace(std::move(trace)); } +TEST_F(AvmExecutionTests, opCallOpcodes) +{ + std::string bytecode_preamble; + // Gas offset preamble + bytecode_preamble += to_hex(OpCode::SET) + // opcode SET for gas offset indirect + "00" // Indirect flag + "03" // U32 + "00000010" // val 16 (address where gas offset is located) + "00000011" + // dst_offset 17 + to_hex(OpCode::SET) + // opcode SET for value stored in gas offset + "00" // Indirect flag + "03" // U32 + "00000011" // val i + "00000000"; + // args offset preamble + bytecode_preamble += to_hex(OpCode::SET) + // opcode SET for args offset indirect + "00" // Indirect flag + "03" // U32 + "00000100" // val i + "00000012" + // dst_offset 0 + to_hex(OpCode::SET) + // opcode SET for value stored in args offset + "00" // Indirect flag + "03" // U32 + "00000012" // val i + "00000001"; + // ret offset preamble + bytecode_preamble += to_hex(OpCode::SET) + // opcode SET for ret offset indirect + "00" // Indirect flag + "03" // U32 + "00000008" // val i + "00000004" + // dst_offset 0 + to_hex(OpCode::SET) + // opcode SET for value stored in ret offset + "00" // Indirect flag + "03" // U32 + "00000002" // val i + "00000007"; + std::string bytecode_hex = bytecode_preamble // SET gas, addr, args size, ret offset, success, function selector + + to_hex(OpCode::CALL) + // opcode CALL + "15" // Indirect flag + "00000000" // gas offset + "00000001" // addr offset + "00000002" // args offset + "00000003" // args size offset + "00000004" // ret offset + "00000007" // ret size + "0000000a" // success offset + "00000006" // function_selector_offset + + to_hex(OpCode::RETURN) + // opcode RETURN + "00" // Indirect flag + "00000008" // ret offset 8 + "00000003"; // ret size 3 + + auto bytecode = hex_to_bytes(bytecode_hex); + auto instructions = Deserialization::parse(bytecode); + + std::vector calldata = {}; + std::vector returndata = {}; + + // Generate Hint for call operation + ExecutionHints execution_hints = {}; + execution_hints.returndata_hints.push_back({ 9, 8 }); // Return data + + auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec, execution_hints); + EXPECT_EQ(returndata, std::vector({ 9, 8, 1 })); // The 1 represents the success + + validate_trace(std::move(trace)); +} + // Negative test detecting an invalid opcode byte. TEST_F(AvmExecutionTests, invalidOpcode) { diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_kernel.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_kernel.test.cpp index b17cbc308a2..4776b01ac7c 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_kernel.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_kernel.test.cpp @@ -733,7 +733,7 @@ TEST_F(AvmKernelOutputPositiveTests, kernelSload) // Provide a hint for sload value slot ExecutionHints execution_hints; - execution_hints[0] = FF(value); // side effect counter -> value + execution_hints.side_effect_hints[0] = FF(value); // side effect counter -> value auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, static_cast(slot), slot_offset, AvmMemoryTag::FF); @@ -808,7 +808,7 @@ TEST_F(AvmKernelOutputPositiveTests, kernelNoteHashExists) auto exists = 1; ExecutionHints execution_hints = {}; - execution_hints[0] = exists; // side effect counter -> value + execution_hints.side_effect_hints[0] = exists; // side effect counter -> value auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, static_cast(value), value_offset, AvmMemoryTag::FF); @@ -847,7 +847,7 @@ TEST_F(AvmKernelOutputPositiveTests, kernelNullifierExists) auto exists = 1; ExecutionHints execution_hints = {}; - execution_hints[0] = exists; // side effect counter -> value + execution_hints.side_effect_hints[0] = exists; // side effect counter -> value auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, static_cast(value), value_offset, AvmMemoryTag::FF); @@ -886,7 +886,7 @@ TEST_F(AvmKernelOutputPositiveTests, kernelL1ToL2MsgExists) // Create an execution hints object with the result of the operation ExecutionHints execution_hints = {}; - execution_hints[0] = exists; + execution_hints.side_effect_hints[0] = exists; auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, static_cast(value), value_offset, AvmMemoryTag::FF); @@ -916,4 +916,4 @@ TEST_F(AvmKernelOutputPositiveTests, kernelL1ToL2MsgExists) test_kernel_lookup(apply_opcodes, checks, execution_hints); } -} // namespace tests_avm \ No newline at end of file +} // namespace tests_avm