diff --git a/barretenberg/cpp/format.sh b/barretenberg/cpp/format.sh index 3bbfd4b59fc..0b1deb05615 100755 --- a/barretenberg/cpp/format.sh +++ b/barretenberg/cpp/format.sh @@ -13,6 +13,12 @@ if [ "$1" == "staged" ]; then sed -i.bak 's/\r$//' $FILE && rm ${FILE}.bak git add $FILE done +elif [ "$1" == "changed" ]; then + echo Formatting barretenberg changed files... + for FILE in $(git diff-index --diff-filter=d --relative --name-only HEAD | grep -e '\.\(cpp\|hpp\|tcc\)$'); do + clang-format-16 -i $FILE + sed -i.bak 's/\r$//' $FILE && rm ${FILE}.bak + done elif [ "$1" == "check" ]; then for FILE in $(find ./src -iname *.hpp -o -iname *.cpp -o -iname *.tcc | grep -v src/msgpack-c); do clang-format-16 --dry-run --Werror $FILE diff --git a/barretenberg/cpp/pil/avm/main.pil b/barretenberg/cpp/pil/avm/main.pil index 0f6b67549b7..7757cc5e99d 100644 --- a/barretenberg/cpp/pil/avm/main.pil +++ b/barretenberg/cpp/pil/avm/main.pil @@ -100,10 +100,11 @@ namespace main(256); da_out_of_gas * (1 - da_out_of_gas) = 0; // Constrain that the gas decrements correctly per instruction + // TODO: Special-case for external call. #[L2_GAS_REMAINING_DECREMENT] - sel_gas_accounting_active * (l2_gas_remaining' - l2_gas_remaining + l2_gas_op_cost) = 0; + sel_gas_accounting_active * (1 - sel_op_external_call) * (l2_gas_remaining' - l2_gas_remaining + l2_gas_op_cost) = 0; #[DA_GAS_REMAINING_DECREMENT] - sel_gas_accounting_active * (da_gas_remaining' - da_gas_remaining + da_gas_op_cost) = 0; + sel_gas_accounting_active * (1 - sel_op_external_call) * (da_gas_remaining' - da_gas_remaining + da_gas_op_cost) = 0; // Constrain that the remaining gas is unchanged otherwise (multi-line operations) #[L2_GAS_INACTIVE] @@ -497,11 +498,11 @@ namespace main(256); // Alternatively, we introduce a boolean selector for the three opcodes mentioned above. // Note: External call gas cost is not constrained pol commit sel_gas_accounting_active; - pol commit sel_mem_op_activate_gas; // TODO: remove this one // TODO: remove sload and sstore from here // This temporarily disables gas tracking for sload and sstore because our gas // tracking doesn't work properly for instructions that span multiple rows - sel_gas_accounting_active - OPCODE_SELECTORS - SEL_ALL_CTRL_FLOW - sel_op_sload - sel_op_sstore - sel_mem_op_activate_gas = 0; + // TODO: disabling this until PR in stack. + // sel_gas_accounting_active - OPCODE_SELECTORS - SEL_ALL_CTRL_FLOW - sel_op_sload - sel_op_sstore - sel_mem_op_activate_gas = 0; // Program counter must increment if not jumping or returning // TODO: support for muli-rows opcode in execution trace such as diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp index f2cb4c04cc8..58a8a8079d2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp @@ -206,7 +206,6 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co polys.main_sel_gas_accounting_active[i] = rows[i].main_sel_gas_accounting_active; polys.main_sel_last[i] = rows[i].main_sel_last; polys.main_sel_mem_op_a[i] = rows[i].main_sel_mem_op_a; - polys.main_sel_mem_op_activate_gas[i] = rows[i].main_sel_mem_op_activate_gas; polys.main_sel_mem_op_b[i] = rows[i].main_sel_mem_op_b; polys.main_sel_mem_op_c[i] = rows[i].main_sel_mem_op_c; polys.main_sel_mem_op_d[i] = rows[i].main_sel_mem_op_d; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.hpp index 0f5cf53fb5d..bb20eb74617 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.hpp @@ -20,8 +20,8 @@ class AvmCircuitBuilder { using Polynomial = Flavor::Polynomial; using ProverPolynomials = Flavor::ProverPolynomials; - static constexpr size_t num_fixed_columns = 704; - static constexpr size_t num_polys = 704 + 74; + static constexpr size_t num_fixed_columns = 703; + static constexpr size_t num_polys = 703 + 74; std::vector rows; void set_trace(std::vector&& trace) { rows = std::move(trace); } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp index 481de9fb1b2..418314f4fd1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp @@ -187,602 +187,601 @@ AvmFlavor::AllConstRefValues::AllConstRefValues( , main_sel_gas_accounting_active(il[179]) , main_sel_last(il[180]) , main_sel_mem_op_a(il[181]) - , main_sel_mem_op_activate_gas(il[182]) - , main_sel_mem_op_b(il[183]) - , main_sel_mem_op_c(il[184]) - , main_sel_mem_op_d(il[185]) - , main_sel_mov_ia_to_ic(il[186]) - , main_sel_mov_ib_to_ic(il[187]) - , main_sel_op_add(il[188]) - , main_sel_op_address(il[189]) - , main_sel_op_and(il[190]) - , main_sel_op_block_number(il[191]) - , main_sel_op_calldata_copy(il[192]) - , main_sel_op_cast(il[193]) - , main_sel_op_chain_id(il[194]) - , main_sel_op_cmov(il[195]) - , main_sel_op_coinbase(il[196]) - , main_sel_op_dagasleft(il[197]) - , main_sel_op_div(il[198]) - , main_sel_op_emit_l2_to_l1_msg(il[199]) - , main_sel_op_emit_note_hash(il[200]) - , main_sel_op_emit_nullifier(il[201]) - , main_sel_op_emit_unencrypted_log(il[202]) - , main_sel_op_eq(il[203]) - , main_sel_op_external_call(il[204]) - , main_sel_op_external_return(il[205]) - , main_sel_op_fdiv(il[206]) - , main_sel_op_fee_per_da_gas(il[207]) - , main_sel_op_fee_per_l2_gas(il[208]) - , main_sel_op_function_selector(il[209]) - , main_sel_op_get_contract_instance(il[210]) - , main_sel_op_halt(il[211]) - , main_sel_op_internal_call(il[212]) - , main_sel_op_internal_return(il[213]) - , main_sel_op_jump(il[214]) - , main_sel_op_jumpi(il[215]) - , main_sel_op_keccak(il[216]) - , main_sel_op_l1_to_l2_msg_exists(il[217]) - , main_sel_op_l2gasleft(il[218]) - , main_sel_op_lt(il[219]) - , main_sel_op_lte(il[220]) - , main_sel_op_mov(il[221]) - , main_sel_op_mul(il[222]) - , main_sel_op_not(il[223]) - , main_sel_op_note_hash_exists(il[224]) - , main_sel_op_nullifier_exists(il[225]) - , main_sel_op_or(il[226]) - , main_sel_op_pedersen(il[227]) - , main_sel_op_poseidon2(il[228]) - , main_sel_op_radix_le(il[229]) - , main_sel_op_sender(il[230]) - , main_sel_op_sha256(il[231]) - , main_sel_op_shl(il[232]) - , main_sel_op_shr(il[233]) - , main_sel_op_sload(il[234]) - , main_sel_op_sstore(il[235]) - , main_sel_op_storage_address(il[236]) - , main_sel_op_sub(il[237]) - , main_sel_op_timestamp(il[238]) - , main_sel_op_transaction_fee(il[239]) - , main_sel_op_version(il[240]) - , main_sel_op_xor(il[241]) - , main_sel_q_kernel_lookup(il[242]) - , main_sel_q_kernel_output_lookup(il[243]) - , main_sel_resolve_ind_addr_a(il[244]) - , main_sel_resolve_ind_addr_b(il[245]) - , main_sel_resolve_ind_addr_c(il[246]) - , main_sel_resolve_ind_addr_d(il[247]) - , main_sel_returndata(il[248]) - , main_sel_rng_16(il[249]) - , main_sel_rng_8(il[250]) - , main_sel_slice_gadget(il[251]) - , main_space_id(il[252]) - , main_tag_err(il[253]) - , main_w_in_tag(il[254]) - , mem_addr(il[255]) - , mem_clk(il[256]) - , mem_diff_hi(il[257]) - , mem_diff_lo(il[258]) - , mem_diff_mid(il[259]) - , mem_glob_addr(il[260]) - , mem_last(il[261]) - , mem_lastAccess(il[262]) - , mem_one_min_inv(il[263]) - , mem_r_in_tag(il[264]) - , mem_rw(il[265]) - , mem_sel_mem(il[266]) - , mem_sel_mov_ia_to_ic(il[267]) - , mem_sel_mov_ib_to_ic(il[268]) - , mem_sel_op_a(il[269]) - , mem_sel_op_b(il[270]) - , mem_sel_op_c(il[271]) - , mem_sel_op_cmov(il[272]) - , mem_sel_op_d(il[273]) - , mem_sel_op_poseidon_read_a(il[274]) - , mem_sel_op_poseidon_read_b(il[275]) - , mem_sel_op_poseidon_read_c(il[276]) - , mem_sel_op_poseidon_read_d(il[277]) - , mem_sel_op_poseidon_write_a(il[278]) - , mem_sel_op_poseidon_write_b(il[279]) - , mem_sel_op_poseidon_write_c(il[280]) - , mem_sel_op_poseidon_write_d(il[281]) - , mem_sel_op_slice(il[282]) - , mem_sel_resolve_ind_addr_a(il[283]) - , mem_sel_resolve_ind_addr_b(il[284]) - , mem_sel_resolve_ind_addr_c(il[285]) - , mem_sel_resolve_ind_addr_d(il[286]) - , mem_sel_rng_chk(il[287]) - , mem_skip_check_tag(il[288]) - , mem_space_id(il[289]) - , mem_tag(il[290]) - , mem_tag_err(il[291]) - , mem_tsp(il[292]) - , mem_val(il[293]) - , mem_w_in_tag(il[294]) - , pedersen_clk(il[295]) - , pedersen_input(il[296]) - , pedersen_output(il[297]) - , pedersen_sel_pedersen(il[298]) - , poseidon2_B_10_0(il[299]) - , poseidon2_B_10_1(il[300]) - , poseidon2_B_10_2(il[301]) - , poseidon2_B_10_3(il[302]) - , poseidon2_B_11_0(il[303]) - , poseidon2_B_11_1(il[304]) - , poseidon2_B_11_2(il[305]) - , poseidon2_B_11_3(il[306]) - , poseidon2_B_12_0(il[307]) - , poseidon2_B_12_1(il[308]) - , poseidon2_B_12_2(il[309]) - , poseidon2_B_12_3(il[310]) - , poseidon2_B_13_0(il[311]) - , poseidon2_B_13_1(il[312]) - , poseidon2_B_13_2(il[313]) - , poseidon2_B_13_3(il[314]) - , poseidon2_B_14_0(il[315]) - , poseidon2_B_14_1(il[316]) - , poseidon2_B_14_2(il[317]) - , poseidon2_B_14_3(il[318]) - , poseidon2_B_15_0(il[319]) - , poseidon2_B_15_1(il[320]) - , poseidon2_B_15_2(il[321]) - , poseidon2_B_15_3(il[322]) - , poseidon2_B_16_0(il[323]) - , poseidon2_B_16_1(il[324]) - , poseidon2_B_16_2(il[325]) - , poseidon2_B_16_3(il[326]) - , poseidon2_B_17_0(il[327]) - , poseidon2_B_17_1(il[328]) - , poseidon2_B_17_2(il[329]) - , poseidon2_B_17_3(il[330]) - , poseidon2_B_18_0(il[331]) - , poseidon2_B_18_1(il[332]) - , poseidon2_B_18_2(il[333]) - , poseidon2_B_18_3(il[334]) - , poseidon2_B_19_0(il[335]) - , poseidon2_B_19_1(il[336]) - , poseidon2_B_19_2(il[337]) - , poseidon2_B_19_3(il[338]) - , poseidon2_B_20_0(il[339]) - , poseidon2_B_20_1(il[340]) - , poseidon2_B_20_2(il[341]) - , poseidon2_B_20_3(il[342]) - , poseidon2_B_21_0(il[343]) - , poseidon2_B_21_1(il[344]) - , poseidon2_B_21_2(il[345]) - , poseidon2_B_21_3(il[346]) - , poseidon2_B_22_0(il[347]) - , poseidon2_B_22_1(il[348]) - , poseidon2_B_22_2(il[349]) - , poseidon2_B_22_3(il[350]) - , poseidon2_B_23_0(il[351]) - , poseidon2_B_23_1(il[352]) - , poseidon2_B_23_2(il[353]) - , poseidon2_B_23_3(il[354]) - , poseidon2_B_24_0(il[355]) - , poseidon2_B_24_1(il[356]) - , poseidon2_B_24_2(il[357]) - , poseidon2_B_24_3(il[358]) - , poseidon2_B_25_0(il[359]) - , poseidon2_B_25_1(il[360]) - , poseidon2_B_25_2(il[361]) - , poseidon2_B_25_3(il[362]) - , poseidon2_B_26_0(il[363]) - , poseidon2_B_26_1(il[364]) - , poseidon2_B_26_2(il[365]) - , poseidon2_B_26_3(il[366]) - , poseidon2_B_27_0(il[367]) - , poseidon2_B_27_1(il[368]) - , poseidon2_B_27_2(il[369]) - , poseidon2_B_27_3(il[370]) - , poseidon2_B_28_0(il[371]) - , poseidon2_B_28_1(il[372]) - , poseidon2_B_28_2(il[373]) - , poseidon2_B_28_3(il[374]) - , poseidon2_B_29_0(il[375]) - , poseidon2_B_29_1(il[376]) - , poseidon2_B_29_2(il[377]) - , poseidon2_B_29_3(il[378]) - , poseidon2_B_30_0(il[379]) - , poseidon2_B_30_1(il[380]) - , poseidon2_B_30_2(il[381]) - , poseidon2_B_30_3(il[382]) - , poseidon2_B_31_0(il[383]) - , poseidon2_B_31_1(il[384]) - , poseidon2_B_31_2(il[385]) - , poseidon2_B_31_3(il[386]) - , poseidon2_B_32_0(il[387]) - , poseidon2_B_32_1(il[388]) - , poseidon2_B_32_2(il[389]) - , poseidon2_B_32_3(il[390]) - , poseidon2_B_33_0(il[391]) - , poseidon2_B_33_1(il[392]) - , poseidon2_B_33_2(il[393]) - , poseidon2_B_33_3(il[394]) - , poseidon2_B_34_0(il[395]) - , poseidon2_B_34_1(il[396]) - , poseidon2_B_34_2(il[397]) - , poseidon2_B_34_3(il[398]) - , poseidon2_B_35_0(il[399]) - , poseidon2_B_35_1(il[400]) - , poseidon2_B_35_2(il[401]) - , poseidon2_B_35_3(il[402]) - , poseidon2_B_36_0(il[403]) - , poseidon2_B_36_1(il[404]) - , poseidon2_B_36_2(il[405]) - , poseidon2_B_36_3(il[406]) - , poseidon2_B_37_0(il[407]) - , poseidon2_B_37_1(il[408]) - , poseidon2_B_37_2(il[409]) - , poseidon2_B_37_3(il[410]) - , poseidon2_B_38_0(il[411]) - , poseidon2_B_38_1(il[412]) - , poseidon2_B_38_2(il[413]) - , poseidon2_B_38_3(il[414]) - , poseidon2_B_39_0(il[415]) - , poseidon2_B_39_1(il[416]) - , poseidon2_B_39_2(il[417]) - , poseidon2_B_39_3(il[418]) - , poseidon2_B_40_0(il[419]) - , poseidon2_B_40_1(il[420]) - , poseidon2_B_40_2(il[421]) - , poseidon2_B_40_3(il[422]) - , poseidon2_B_41_0(il[423]) - , poseidon2_B_41_1(il[424]) - , poseidon2_B_41_2(il[425]) - , poseidon2_B_41_3(il[426]) - , poseidon2_B_42_0(il[427]) - , poseidon2_B_42_1(il[428]) - , poseidon2_B_42_2(il[429]) - , poseidon2_B_42_3(il[430]) - , poseidon2_B_43_0(il[431]) - , poseidon2_B_43_1(il[432]) - , poseidon2_B_43_2(il[433]) - , poseidon2_B_43_3(il[434]) - , poseidon2_B_44_0(il[435]) - , poseidon2_B_44_1(il[436]) - , poseidon2_B_44_2(il[437]) - , poseidon2_B_44_3(il[438]) - , poseidon2_B_45_0(il[439]) - , poseidon2_B_45_1(il[440]) - , poseidon2_B_45_2(il[441]) - , poseidon2_B_45_3(il[442]) - , poseidon2_B_46_0(il[443]) - , poseidon2_B_46_1(il[444]) - , poseidon2_B_46_2(il[445]) - , poseidon2_B_46_3(il[446]) - , poseidon2_B_47_0(il[447]) - , poseidon2_B_47_1(il[448]) - , poseidon2_B_47_2(il[449]) - , poseidon2_B_47_3(il[450]) - , poseidon2_B_48_0(il[451]) - , poseidon2_B_48_1(il[452]) - , poseidon2_B_48_2(il[453]) - , poseidon2_B_48_3(il[454]) - , poseidon2_B_49_0(il[455]) - , poseidon2_B_49_1(il[456]) - , poseidon2_B_49_2(il[457]) - , poseidon2_B_49_3(il[458]) - , poseidon2_B_4_0(il[459]) - , poseidon2_B_4_1(il[460]) - , poseidon2_B_4_2(il[461]) - , poseidon2_B_4_3(il[462]) - , poseidon2_B_50_0(il[463]) - , poseidon2_B_50_1(il[464]) - , poseidon2_B_50_2(il[465]) - , poseidon2_B_50_3(il[466]) - , poseidon2_B_51_0(il[467]) - , poseidon2_B_51_1(il[468]) - , poseidon2_B_51_2(il[469]) - , poseidon2_B_51_3(il[470]) - , poseidon2_B_52_0(il[471]) - , poseidon2_B_52_1(il[472]) - , poseidon2_B_52_2(il[473]) - , poseidon2_B_52_3(il[474]) - , poseidon2_B_53_0(il[475]) - , poseidon2_B_53_1(il[476]) - , poseidon2_B_53_2(il[477]) - , poseidon2_B_53_3(il[478]) - , poseidon2_B_54_0(il[479]) - , poseidon2_B_54_1(il[480]) - , poseidon2_B_54_2(il[481]) - , poseidon2_B_54_3(il[482]) - , poseidon2_B_55_0(il[483]) - , poseidon2_B_55_1(il[484]) - , poseidon2_B_55_2(il[485]) - , poseidon2_B_55_3(il[486]) - , poseidon2_B_56_0(il[487]) - , poseidon2_B_56_1(il[488]) - , poseidon2_B_56_2(il[489]) - , poseidon2_B_56_3(il[490]) - , poseidon2_B_57_0(il[491]) - , poseidon2_B_57_1(il[492]) - , poseidon2_B_57_2(il[493]) - , poseidon2_B_57_3(il[494]) - , poseidon2_B_58_0(il[495]) - , poseidon2_B_58_1(il[496]) - , poseidon2_B_58_2(il[497]) - , poseidon2_B_58_3(il[498]) - , poseidon2_B_59_0(il[499]) - , poseidon2_B_59_1(il[500]) - , poseidon2_B_59_2(il[501]) - , poseidon2_B_59_3(il[502]) - , poseidon2_B_5_0(il[503]) - , poseidon2_B_5_1(il[504]) - , poseidon2_B_5_2(il[505]) - , poseidon2_B_5_3(il[506]) - , poseidon2_B_6_0(il[507]) - , poseidon2_B_6_1(il[508]) - , poseidon2_B_6_2(il[509]) - , poseidon2_B_6_3(il[510]) - , poseidon2_B_7_0(il[511]) - , poseidon2_B_7_1(il[512]) - , poseidon2_B_7_2(il[513]) - , poseidon2_B_7_3(il[514]) - , poseidon2_B_8_0(il[515]) - , poseidon2_B_8_1(il[516]) - , poseidon2_B_8_2(il[517]) - , poseidon2_B_8_3(il[518]) - , poseidon2_B_9_0(il[519]) - , poseidon2_B_9_1(il[520]) - , poseidon2_B_9_2(il[521]) - , poseidon2_B_9_3(il[522]) - , poseidon2_EXT_LAYER_4(il[523]) - , poseidon2_EXT_LAYER_5(il[524]) - , poseidon2_EXT_LAYER_6(il[525]) - , poseidon2_EXT_LAYER_7(il[526]) - , poseidon2_T_0_4(il[527]) - , poseidon2_T_0_5(il[528]) - , poseidon2_T_0_6(il[529]) - , poseidon2_T_0_7(il[530]) - , poseidon2_T_1_4(il[531]) - , poseidon2_T_1_5(il[532]) - , poseidon2_T_1_6(il[533]) - , poseidon2_T_1_7(il[534]) - , poseidon2_T_2_4(il[535]) - , poseidon2_T_2_5(il[536]) - , poseidon2_T_2_6(il[537]) - , poseidon2_T_2_7(il[538]) - , poseidon2_T_3_4(il[539]) - , poseidon2_T_3_5(il[540]) - , poseidon2_T_3_6(il[541]) - , poseidon2_T_3_7(il[542]) - , poseidon2_T_60_4(il[543]) - , poseidon2_T_60_5(il[544]) - , poseidon2_T_60_6(il[545]) - , poseidon2_T_60_7(il[546]) - , poseidon2_T_61_4(il[547]) - , poseidon2_T_61_5(il[548]) - , poseidon2_T_61_6(il[549]) - , poseidon2_T_61_7(il[550]) - , poseidon2_T_62_4(il[551]) - , poseidon2_T_62_5(il[552]) - , poseidon2_T_62_6(il[553]) - , poseidon2_T_62_7(il[554]) - , poseidon2_T_63_4(il[555]) - , poseidon2_T_63_5(il[556]) - , poseidon2_T_63_6(il[557]) - , poseidon2_T_63_7(il[558]) - , poseidon2_a_0(il[559]) - , poseidon2_a_1(il[560]) - , poseidon2_a_2(il[561]) - , poseidon2_a_3(il[562]) - , poseidon2_b_0(il[563]) - , poseidon2_b_1(il[564]) - , poseidon2_b_2(il[565]) - , poseidon2_b_3(il[566]) - , poseidon2_clk(il[567]) - , poseidon2_input_addr(il[568]) - , poseidon2_mem_addr_read_a(il[569]) - , poseidon2_mem_addr_read_b(il[570]) - , poseidon2_mem_addr_read_c(il[571]) - , poseidon2_mem_addr_read_d(il[572]) - , poseidon2_mem_addr_write_a(il[573]) - , poseidon2_mem_addr_write_b(il[574]) - , poseidon2_mem_addr_write_c(il[575]) - , poseidon2_mem_addr_write_d(il[576]) - , poseidon2_output_addr(il[577]) - , poseidon2_sel_poseidon_perm(il[578]) - , sha256_clk(il[579]) - , sha256_input(il[580]) - , sha256_output(il[581]) - , sha256_sel_sha256_compression(il[582]) - , sha256_state(il[583]) - , slice_addr(il[584]) - , slice_clk(il[585]) - , slice_cnt(il[586]) - , slice_col_offset(il[587]) - , slice_one_min_inv(il[588]) - , slice_sel_cd_cpy(il[589]) - , slice_sel_mem_active(il[590]) - , slice_sel_return(il[591]) - , slice_sel_start(il[592]) - , slice_space_id(il[593]) - , slice_val(il[594]) - , lookup_byte_lengths_counts(il[595]) - , lookup_byte_operations_counts(il[596]) - , lookup_cd_value_counts(il[597]) - , lookup_ret_value_counts(il[598]) - , lookup_opcode_gas_counts(il[599]) - , range_check_l2_gas_hi_counts(il[600]) - , range_check_l2_gas_lo_counts(il[601]) - , range_check_da_gas_hi_counts(il[602]) - , range_check_da_gas_lo_counts(il[603]) - , kernel_output_lookup_counts(il[604]) - , lookup_into_kernel_counts(il[605]) - , incl_main_tag_err_counts(il[606]) - , incl_mem_tag_err_counts(il[607]) - , lookup_mem_rng_chk_lo_counts(il[608]) - , lookup_mem_rng_chk_mid_counts(il[609]) - , lookup_mem_rng_chk_hi_counts(il[610]) - , lookup_pow_2_0_counts(il[611]) - , lookup_pow_2_1_counts(il[612]) - , lookup_u8_0_counts(il[613]) - , lookup_u8_1_counts(il[614]) - , lookup_u16_0_counts(il[615]) - , lookup_u16_1_counts(il[616]) - , lookup_u16_2_counts(il[617]) - , lookup_u16_3_counts(il[618]) - , lookup_u16_4_counts(il[619]) - , lookup_u16_5_counts(il[620]) - , lookup_u16_6_counts(il[621]) - , lookup_u16_7_counts(il[622]) - , lookup_u16_8_counts(il[623]) - , lookup_u16_9_counts(il[624]) - , lookup_u16_10_counts(il[625]) - , lookup_u16_11_counts(il[626]) - , lookup_u16_12_counts(il[627]) - , lookup_u16_13_counts(il[628]) - , lookup_u16_14_counts(il[629]) - , lookup_div_u16_0_counts(il[630]) - , lookup_div_u16_1_counts(il[631]) - , lookup_div_u16_2_counts(il[632]) - , lookup_div_u16_3_counts(il[633]) - , lookup_div_u16_4_counts(il[634]) - , lookup_div_u16_5_counts(il[635]) - , lookup_div_u16_6_counts(il[636]) - , lookup_div_u16_7_counts(il[637]) - , perm_pos_mem_read_a(il[638]) - , perm_pos_mem_read_b(il[639]) - , perm_pos_mem_read_c(il[640]) - , perm_pos_mem_read_d(il[641]) - , perm_pos_mem_write_a(il[642]) - , perm_pos_mem_write_b(il[643]) - , perm_pos_mem_write_c(il[644]) - , perm_pos_mem_write_d(il[645]) - , perm_slice_mem(il[646]) - , perm_main_alu(il[647]) - , perm_main_bin(il[648]) - , perm_main_conv(il[649]) - , perm_main_pos2_perm(il[650]) - , perm_main_pedersen(il[651]) - , perm_main_slice(il[652]) - , perm_main_mem_a(il[653]) - , perm_main_mem_b(il[654]) - , perm_main_mem_c(il[655]) - , perm_main_mem_d(il[656]) - , perm_main_mem_ind_addr_a(il[657]) - , perm_main_mem_ind_addr_b(il[658]) - , perm_main_mem_ind_addr_c(il[659]) - , perm_main_mem_ind_addr_d(il[660]) - , lookup_byte_lengths(il[661]) - , lookup_byte_operations(il[662]) - , lookup_cd_value(il[663]) - , lookup_ret_value(il[664]) - , lookup_opcode_gas(il[665]) - , range_check_l2_gas_hi(il[666]) - , range_check_l2_gas_lo(il[667]) - , range_check_da_gas_hi(il[668]) - , range_check_da_gas_lo(il[669]) - , kernel_output_lookup(il[670]) - , lookup_into_kernel(il[671]) - , incl_main_tag_err(il[672]) - , incl_mem_tag_err(il[673]) - , lookup_mem_rng_chk_lo(il[674]) - , lookup_mem_rng_chk_mid(il[675]) - , lookup_mem_rng_chk_hi(il[676]) - , lookup_pow_2_0(il[677]) - , lookup_pow_2_1(il[678]) - , lookup_u8_0(il[679]) - , lookup_u8_1(il[680]) - , lookup_u16_0(il[681]) - , lookup_u16_1(il[682]) - , lookup_u16_2(il[683]) - , lookup_u16_3(il[684]) - , lookup_u16_4(il[685]) - , lookup_u16_5(il[686]) - , lookup_u16_6(il[687]) - , lookup_u16_7(il[688]) - , lookup_u16_8(il[689]) - , lookup_u16_9(il[690]) - , lookup_u16_10(il[691]) - , lookup_u16_11(il[692]) - , lookup_u16_12(il[693]) - , lookup_u16_13(il[694]) - , lookup_u16_14(il[695]) - , lookup_div_u16_0(il[696]) - , lookup_div_u16_1(il[697]) - , lookup_div_u16_2(il[698]) - , lookup_div_u16_3(il[699]) - , lookup_div_u16_4(il[700]) - , lookup_div_u16_5(il[701]) - , lookup_div_u16_6(il[702]) - , lookup_div_u16_7(il[703]) - , alu_a_hi_shift(il[704]) - , alu_a_lo_shift(il[705]) - , alu_b_hi_shift(il[706]) - , alu_b_lo_shift(il[707]) - , alu_cmp_rng_ctr_shift(il[708]) - , alu_div_u16_r0_shift(il[709]) - , alu_div_u16_r1_shift(il[710]) - , alu_div_u16_r2_shift(il[711]) - , alu_div_u16_r3_shift(il[712]) - , alu_div_u16_r4_shift(il[713]) - , alu_div_u16_r5_shift(il[714]) - , alu_div_u16_r6_shift(il[715]) - , alu_div_u16_r7_shift(il[716]) - , alu_op_add_shift(il[717]) - , alu_op_cast_prev_shift(il[718]) - , alu_op_cast_shift(il[719]) - , alu_op_div_shift(il[720]) - , alu_op_mul_shift(il[721]) - , alu_op_shl_shift(il[722]) - , alu_op_shr_shift(il[723]) - , alu_op_sub_shift(il[724]) - , alu_p_sub_a_hi_shift(il[725]) - , alu_p_sub_a_lo_shift(il[726]) - , alu_p_sub_b_hi_shift(il[727]) - , alu_p_sub_b_lo_shift(il[728]) - , alu_sel_alu_shift(il[729]) - , alu_sel_cmp_shift(il[730]) - , alu_sel_div_rng_chk_shift(il[731]) - , alu_sel_rng_chk_lookup_shift(il[732]) - , alu_sel_rng_chk_shift(il[733]) - , alu_u16_r0_shift(il[734]) - , alu_u16_r1_shift(il[735]) - , alu_u16_r2_shift(il[736]) - , alu_u16_r3_shift(il[737]) - , alu_u16_r4_shift(il[738]) - , alu_u16_r5_shift(il[739]) - , alu_u16_r6_shift(il[740]) - , alu_u8_r0_shift(il[741]) - , alu_u8_r1_shift(il[742]) - , binary_acc_ia_shift(il[743]) - , binary_acc_ib_shift(il[744]) - , binary_acc_ic_shift(il[745]) - , binary_mem_tag_ctr_shift(il[746]) - , binary_op_id_shift(il[747]) - , kernel_emit_l2_to_l1_msg_write_offset_shift(il[748]) - , kernel_emit_note_hash_write_offset_shift(il[749]) - , kernel_emit_nullifier_write_offset_shift(il[750]) - , kernel_emit_unencrypted_log_write_offset_shift(il[751]) - , kernel_l1_to_l2_msg_exists_write_offset_shift(il[752]) - , kernel_note_hash_exist_write_offset_shift(il[753]) - , kernel_nullifier_exists_write_offset_shift(il[754]) - , kernel_nullifier_non_exists_write_offset_shift(il[755]) - , kernel_side_effect_counter_shift(il[756]) - , kernel_sload_write_offset_shift(il[757]) - , kernel_sstore_write_offset_shift(il[758]) - , main_da_gas_remaining_shift(il[759]) - , main_internal_return_ptr_shift(il[760]) - , main_l2_gas_remaining_shift(il[761]) - , main_pc_shift(il[762]) - , mem_glob_addr_shift(il[763]) - , mem_rw_shift(il[764]) - , mem_sel_mem_shift(il[765]) - , mem_tag_shift(il[766]) - , mem_tsp_shift(il[767]) - , mem_val_shift(il[768]) - , slice_addr_shift(il[769]) - , slice_clk_shift(il[770]) - , slice_cnt_shift(il[771]) - , slice_col_offset_shift(il[772]) - , slice_sel_cd_cpy_shift(il[773]) - , slice_sel_mem_active_shift(il[774]) - , slice_sel_return_shift(il[775]) - , slice_sel_start_shift(il[776]) - , slice_space_id_shift(il[777]) + , main_sel_mem_op_b(il[182]) + , main_sel_mem_op_c(il[183]) + , main_sel_mem_op_d(il[184]) + , main_sel_mov_ia_to_ic(il[185]) + , main_sel_mov_ib_to_ic(il[186]) + , main_sel_op_add(il[187]) + , main_sel_op_address(il[188]) + , main_sel_op_and(il[189]) + , main_sel_op_block_number(il[190]) + , main_sel_op_calldata_copy(il[191]) + , main_sel_op_cast(il[192]) + , main_sel_op_chain_id(il[193]) + , main_sel_op_cmov(il[194]) + , main_sel_op_coinbase(il[195]) + , main_sel_op_dagasleft(il[196]) + , main_sel_op_div(il[197]) + , main_sel_op_emit_l2_to_l1_msg(il[198]) + , main_sel_op_emit_note_hash(il[199]) + , main_sel_op_emit_nullifier(il[200]) + , main_sel_op_emit_unencrypted_log(il[201]) + , main_sel_op_eq(il[202]) + , main_sel_op_external_call(il[203]) + , main_sel_op_external_return(il[204]) + , main_sel_op_fdiv(il[205]) + , main_sel_op_fee_per_da_gas(il[206]) + , main_sel_op_fee_per_l2_gas(il[207]) + , main_sel_op_function_selector(il[208]) + , main_sel_op_get_contract_instance(il[209]) + , main_sel_op_halt(il[210]) + , main_sel_op_internal_call(il[211]) + , main_sel_op_internal_return(il[212]) + , main_sel_op_jump(il[213]) + , main_sel_op_jumpi(il[214]) + , main_sel_op_keccak(il[215]) + , main_sel_op_l1_to_l2_msg_exists(il[216]) + , main_sel_op_l2gasleft(il[217]) + , main_sel_op_lt(il[218]) + , main_sel_op_lte(il[219]) + , main_sel_op_mov(il[220]) + , main_sel_op_mul(il[221]) + , main_sel_op_not(il[222]) + , main_sel_op_note_hash_exists(il[223]) + , main_sel_op_nullifier_exists(il[224]) + , main_sel_op_or(il[225]) + , main_sel_op_pedersen(il[226]) + , main_sel_op_poseidon2(il[227]) + , main_sel_op_radix_le(il[228]) + , main_sel_op_sender(il[229]) + , main_sel_op_sha256(il[230]) + , main_sel_op_shl(il[231]) + , main_sel_op_shr(il[232]) + , main_sel_op_sload(il[233]) + , main_sel_op_sstore(il[234]) + , main_sel_op_storage_address(il[235]) + , main_sel_op_sub(il[236]) + , main_sel_op_timestamp(il[237]) + , main_sel_op_transaction_fee(il[238]) + , main_sel_op_version(il[239]) + , main_sel_op_xor(il[240]) + , main_sel_q_kernel_lookup(il[241]) + , main_sel_q_kernel_output_lookup(il[242]) + , main_sel_resolve_ind_addr_a(il[243]) + , main_sel_resolve_ind_addr_b(il[244]) + , main_sel_resolve_ind_addr_c(il[245]) + , main_sel_resolve_ind_addr_d(il[246]) + , main_sel_returndata(il[247]) + , main_sel_rng_16(il[248]) + , main_sel_rng_8(il[249]) + , main_sel_slice_gadget(il[250]) + , main_space_id(il[251]) + , main_tag_err(il[252]) + , main_w_in_tag(il[253]) + , mem_addr(il[254]) + , mem_clk(il[255]) + , mem_diff_hi(il[256]) + , mem_diff_lo(il[257]) + , mem_diff_mid(il[258]) + , mem_glob_addr(il[259]) + , mem_last(il[260]) + , mem_lastAccess(il[261]) + , mem_one_min_inv(il[262]) + , mem_r_in_tag(il[263]) + , mem_rw(il[264]) + , mem_sel_mem(il[265]) + , mem_sel_mov_ia_to_ic(il[266]) + , mem_sel_mov_ib_to_ic(il[267]) + , mem_sel_op_a(il[268]) + , mem_sel_op_b(il[269]) + , mem_sel_op_c(il[270]) + , mem_sel_op_cmov(il[271]) + , mem_sel_op_d(il[272]) + , mem_sel_op_poseidon_read_a(il[273]) + , mem_sel_op_poseidon_read_b(il[274]) + , mem_sel_op_poseidon_read_c(il[275]) + , mem_sel_op_poseidon_read_d(il[276]) + , mem_sel_op_poseidon_write_a(il[277]) + , mem_sel_op_poseidon_write_b(il[278]) + , mem_sel_op_poseidon_write_c(il[279]) + , mem_sel_op_poseidon_write_d(il[280]) + , mem_sel_op_slice(il[281]) + , mem_sel_resolve_ind_addr_a(il[282]) + , mem_sel_resolve_ind_addr_b(il[283]) + , mem_sel_resolve_ind_addr_c(il[284]) + , mem_sel_resolve_ind_addr_d(il[285]) + , mem_sel_rng_chk(il[286]) + , mem_skip_check_tag(il[287]) + , mem_space_id(il[288]) + , mem_tag(il[289]) + , mem_tag_err(il[290]) + , mem_tsp(il[291]) + , mem_val(il[292]) + , mem_w_in_tag(il[293]) + , pedersen_clk(il[294]) + , pedersen_input(il[295]) + , pedersen_output(il[296]) + , pedersen_sel_pedersen(il[297]) + , poseidon2_B_10_0(il[298]) + , poseidon2_B_10_1(il[299]) + , poseidon2_B_10_2(il[300]) + , poseidon2_B_10_3(il[301]) + , poseidon2_B_11_0(il[302]) + , poseidon2_B_11_1(il[303]) + , poseidon2_B_11_2(il[304]) + , poseidon2_B_11_3(il[305]) + , poseidon2_B_12_0(il[306]) + , poseidon2_B_12_1(il[307]) + , poseidon2_B_12_2(il[308]) + , poseidon2_B_12_3(il[309]) + , poseidon2_B_13_0(il[310]) + , poseidon2_B_13_1(il[311]) + , poseidon2_B_13_2(il[312]) + , poseidon2_B_13_3(il[313]) + , poseidon2_B_14_0(il[314]) + , poseidon2_B_14_1(il[315]) + , poseidon2_B_14_2(il[316]) + , poseidon2_B_14_3(il[317]) + , poseidon2_B_15_0(il[318]) + , poseidon2_B_15_1(il[319]) + , poseidon2_B_15_2(il[320]) + , poseidon2_B_15_3(il[321]) + , poseidon2_B_16_0(il[322]) + , poseidon2_B_16_1(il[323]) + , poseidon2_B_16_2(il[324]) + , poseidon2_B_16_3(il[325]) + , poseidon2_B_17_0(il[326]) + , poseidon2_B_17_1(il[327]) + , poseidon2_B_17_2(il[328]) + , poseidon2_B_17_3(il[329]) + , poseidon2_B_18_0(il[330]) + , poseidon2_B_18_1(il[331]) + , poseidon2_B_18_2(il[332]) + , poseidon2_B_18_3(il[333]) + , poseidon2_B_19_0(il[334]) + , poseidon2_B_19_1(il[335]) + , poseidon2_B_19_2(il[336]) + , poseidon2_B_19_3(il[337]) + , poseidon2_B_20_0(il[338]) + , poseidon2_B_20_1(il[339]) + , poseidon2_B_20_2(il[340]) + , poseidon2_B_20_3(il[341]) + , poseidon2_B_21_0(il[342]) + , poseidon2_B_21_1(il[343]) + , poseidon2_B_21_2(il[344]) + , poseidon2_B_21_3(il[345]) + , poseidon2_B_22_0(il[346]) + , poseidon2_B_22_1(il[347]) + , poseidon2_B_22_2(il[348]) + , poseidon2_B_22_3(il[349]) + , poseidon2_B_23_0(il[350]) + , poseidon2_B_23_1(il[351]) + , poseidon2_B_23_2(il[352]) + , poseidon2_B_23_3(il[353]) + , poseidon2_B_24_0(il[354]) + , poseidon2_B_24_1(il[355]) + , poseidon2_B_24_2(il[356]) + , poseidon2_B_24_3(il[357]) + , poseidon2_B_25_0(il[358]) + , poseidon2_B_25_1(il[359]) + , poseidon2_B_25_2(il[360]) + , poseidon2_B_25_3(il[361]) + , poseidon2_B_26_0(il[362]) + , poseidon2_B_26_1(il[363]) + , poseidon2_B_26_2(il[364]) + , poseidon2_B_26_3(il[365]) + , poseidon2_B_27_0(il[366]) + , poseidon2_B_27_1(il[367]) + , poseidon2_B_27_2(il[368]) + , poseidon2_B_27_3(il[369]) + , poseidon2_B_28_0(il[370]) + , poseidon2_B_28_1(il[371]) + , poseidon2_B_28_2(il[372]) + , poseidon2_B_28_3(il[373]) + , poseidon2_B_29_0(il[374]) + , poseidon2_B_29_1(il[375]) + , poseidon2_B_29_2(il[376]) + , poseidon2_B_29_3(il[377]) + , poseidon2_B_30_0(il[378]) + , poseidon2_B_30_1(il[379]) + , poseidon2_B_30_2(il[380]) + , poseidon2_B_30_3(il[381]) + , poseidon2_B_31_0(il[382]) + , poseidon2_B_31_1(il[383]) + , poseidon2_B_31_2(il[384]) + , poseidon2_B_31_3(il[385]) + , poseidon2_B_32_0(il[386]) + , poseidon2_B_32_1(il[387]) + , poseidon2_B_32_2(il[388]) + , poseidon2_B_32_3(il[389]) + , poseidon2_B_33_0(il[390]) + , poseidon2_B_33_1(il[391]) + , poseidon2_B_33_2(il[392]) + , poseidon2_B_33_3(il[393]) + , poseidon2_B_34_0(il[394]) + , poseidon2_B_34_1(il[395]) + , poseidon2_B_34_2(il[396]) + , poseidon2_B_34_3(il[397]) + , poseidon2_B_35_0(il[398]) + , poseidon2_B_35_1(il[399]) + , poseidon2_B_35_2(il[400]) + , poseidon2_B_35_3(il[401]) + , poseidon2_B_36_0(il[402]) + , poseidon2_B_36_1(il[403]) + , poseidon2_B_36_2(il[404]) + , poseidon2_B_36_3(il[405]) + , poseidon2_B_37_0(il[406]) + , poseidon2_B_37_1(il[407]) + , poseidon2_B_37_2(il[408]) + , poseidon2_B_37_3(il[409]) + , poseidon2_B_38_0(il[410]) + , poseidon2_B_38_1(il[411]) + , poseidon2_B_38_2(il[412]) + , poseidon2_B_38_3(il[413]) + , poseidon2_B_39_0(il[414]) + , poseidon2_B_39_1(il[415]) + , poseidon2_B_39_2(il[416]) + , poseidon2_B_39_3(il[417]) + , poseidon2_B_40_0(il[418]) + , poseidon2_B_40_1(il[419]) + , poseidon2_B_40_2(il[420]) + , poseidon2_B_40_3(il[421]) + , poseidon2_B_41_0(il[422]) + , poseidon2_B_41_1(il[423]) + , poseidon2_B_41_2(il[424]) + , poseidon2_B_41_3(il[425]) + , poseidon2_B_42_0(il[426]) + , poseidon2_B_42_1(il[427]) + , poseidon2_B_42_2(il[428]) + , poseidon2_B_42_3(il[429]) + , poseidon2_B_43_0(il[430]) + , poseidon2_B_43_1(il[431]) + , poseidon2_B_43_2(il[432]) + , poseidon2_B_43_3(il[433]) + , poseidon2_B_44_0(il[434]) + , poseidon2_B_44_1(il[435]) + , poseidon2_B_44_2(il[436]) + , poseidon2_B_44_3(il[437]) + , poseidon2_B_45_0(il[438]) + , poseidon2_B_45_1(il[439]) + , poseidon2_B_45_2(il[440]) + , poseidon2_B_45_3(il[441]) + , poseidon2_B_46_0(il[442]) + , poseidon2_B_46_1(il[443]) + , poseidon2_B_46_2(il[444]) + , poseidon2_B_46_3(il[445]) + , poseidon2_B_47_0(il[446]) + , poseidon2_B_47_1(il[447]) + , poseidon2_B_47_2(il[448]) + , poseidon2_B_47_3(il[449]) + , poseidon2_B_48_0(il[450]) + , poseidon2_B_48_1(il[451]) + , poseidon2_B_48_2(il[452]) + , poseidon2_B_48_3(il[453]) + , poseidon2_B_49_0(il[454]) + , poseidon2_B_49_1(il[455]) + , poseidon2_B_49_2(il[456]) + , poseidon2_B_49_3(il[457]) + , poseidon2_B_4_0(il[458]) + , poseidon2_B_4_1(il[459]) + , poseidon2_B_4_2(il[460]) + , poseidon2_B_4_3(il[461]) + , poseidon2_B_50_0(il[462]) + , poseidon2_B_50_1(il[463]) + , poseidon2_B_50_2(il[464]) + , poseidon2_B_50_3(il[465]) + , poseidon2_B_51_0(il[466]) + , poseidon2_B_51_1(il[467]) + , poseidon2_B_51_2(il[468]) + , poseidon2_B_51_3(il[469]) + , poseidon2_B_52_0(il[470]) + , poseidon2_B_52_1(il[471]) + , poseidon2_B_52_2(il[472]) + , poseidon2_B_52_3(il[473]) + , poseidon2_B_53_0(il[474]) + , poseidon2_B_53_1(il[475]) + , poseidon2_B_53_2(il[476]) + , poseidon2_B_53_3(il[477]) + , poseidon2_B_54_0(il[478]) + , poseidon2_B_54_1(il[479]) + , poseidon2_B_54_2(il[480]) + , poseidon2_B_54_3(il[481]) + , poseidon2_B_55_0(il[482]) + , poseidon2_B_55_1(il[483]) + , poseidon2_B_55_2(il[484]) + , poseidon2_B_55_3(il[485]) + , poseidon2_B_56_0(il[486]) + , poseidon2_B_56_1(il[487]) + , poseidon2_B_56_2(il[488]) + , poseidon2_B_56_3(il[489]) + , poseidon2_B_57_0(il[490]) + , poseidon2_B_57_1(il[491]) + , poseidon2_B_57_2(il[492]) + , poseidon2_B_57_3(il[493]) + , poseidon2_B_58_0(il[494]) + , poseidon2_B_58_1(il[495]) + , poseidon2_B_58_2(il[496]) + , poseidon2_B_58_3(il[497]) + , poseidon2_B_59_0(il[498]) + , poseidon2_B_59_1(il[499]) + , poseidon2_B_59_2(il[500]) + , poseidon2_B_59_3(il[501]) + , poseidon2_B_5_0(il[502]) + , poseidon2_B_5_1(il[503]) + , poseidon2_B_5_2(il[504]) + , poseidon2_B_5_3(il[505]) + , poseidon2_B_6_0(il[506]) + , poseidon2_B_6_1(il[507]) + , poseidon2_B_6_2(il[508]) + , poseidon2_B_6_3(il[509]) + , poseidon2_B_7_0(il[510]) + , poseidon2_B_7_1(il[511]) + , poseidon2_B_7_2(il[512]) + , poseidon2_B_7_3(il[513]) + , poseidon2_B_8_0(il[514]) + , poseidon2_B_8_1(il[515]) + , poseidon2_B_8_2(il[516]) + , poseidon2_B_8_3(il[517]) + , poseidon2_B_9_0(il[518]) + , poseidon2_B_9_1(il[519]) + , poseidon2_B_9_2(il[520]) + , poseidon2_B_9_3(il[521]) + , poseidon2_EXT_LAYER_4(il[522]) + , poseidon2_EXT_LAYER_5(il[523]) + , poseidon2_EXT_LAYER_6(il[524]) + , poseidon2_EXT_LAYER_7(il[525]) + , poseidon2_T_0_4(il[526]) + , poseidon2_T_0_5(il[527]) + , poseidon2_T_0_6(il[528]) + , poseidon2_T_0_7(il[529]) + , poseidon2_T_1_4(il[530]) + , poseidon2_T_1_5(il[531]) + , poseidon2_T_1_6(il[532]) + , poseidon2_T_1_7(il[533]) + , poseidon2_T_2_4(il[534]) + , poseidon2_T_2_5(il[535]) + , poseidon2_T_2_6(il[536]) + , poseidon2_T_2_7(il[537]) + , poseidon2_T_3_4(il[538]) + , poseidon2_T_3_5(il[539]) + , poseidon2_T_3_6(il[540]) + , poseidon2_T_3_7(il[541]) + , poseidon2_T_60_4(il[542]) + , poseidon2_T_60_5(il[543]) + , poseidon2_T_60_6(il[544]) + , poseidon2_T_60_7(il[545]) + , poseidon2_T_61_4(il[546]) + , poseidon2_T_61_5(il[547]) + , poseidon2_T_61_6(il[548]) + , poseidon2_T_61_7(il[549]) + , poseidon2_T_62_4(il[550]) + , poseidon2_T_62_5(il[551]) + , poseidon2_T_62_6(il[552]) + , poseidon2_T_62_7(il[553]) + , poseidon2_T_63_4(il[554]) + , poseidon2_T_63_5(il[555]) + , poseidon2_T_63_6(il[556]) + , poseidon2_T_63_7(il[557]) + , poseidon2_a_0(il[558]) + , poseidon2_a_1(il[559]) + , poseidon2_a_2(il[560]) + , poseidon2_a_3(il[561]) + , poseidon2_b_0(il[562]) + , poseidon2_b_1(il[563]) + , poseidon2_b_2(il[564]) + , poseidon2_b_3(il[565]) + , poseidon2_clk(il[566]) + , poseidon2_input_addr(il[567]) + , poseidon2_mem_addr_read_a(il[568]) + , poseidon2_mem_addr_read_b(il[569]) + , poseidon2_mem_addr_read_c(il[570]) + , poseidon2_mem_addr_read_d(il[571]) + , poseidon2_mem_addr_write_a(il[572]) + , poseidon2_mem_addr_write_b(il[573]) + , poseidon2_mem_addr_write_c(il[574]) + , poseidon2_mem_addr_write_d(il[575]) + , poseidon2_output_addr(il[576]) + , poseidon2_sel_poseidon_perm(il[577]) + , sha256_clk(il[578]) + , sha256_input(il[579]) + , sha256_output(il[580]) + , sha256_sel_sha256_compression(il[581]) + , sha256_state(il[582]) + , slice_addr(il[583]) + , slice_clk(il[584]) + , slice_cnt(il[585]) + , slice_col_offset(il[586]) + , slice_one_min_inv(il[587]) + , slice_sel_cd_cpy(il[588]) + , slice_sel_mem_active(il[589]) + , slice_sel_return(il[590]) + , slice_sel_start(il[591]) + , slice_space_id(il[592]) + , slice_val(il[593]) + , lookup_byte_lengths_counts(il[594]) + , lookup_byte_operations_counts(il[595]) + , lookup_cd_value_counts(il[596]) + , lookup_ret_value_counts(il[597]) + , lookup_opcode_gas_counts(il[598]) + , range_check_l2_gas_hi_counts(il[599]) + , range_check_l2_gas_lo_counts(il[600]) + , range_check_da_gas_hi_counts(il[601]) + , range_check_da_gas_lo_counts(il[602]) + , kernel_output_lookup_counts(il[603]) + , lookup_into_kernel_counts(il[604]) + , incl_main_tag_err_counts(il[605]) + , incl_mem_tag_err_counts(il[606]) + , lookup_mem_rng_chk_lo_counts(il[607]) + , lookup_mem_rng_chk_mid_counts(il[608]) + , lookup_mem_rng_chk_hi_counts(il[609]) + , lookup_pow_2_0_counts(il[610]) + , lookup_pow_2_1_counts(il[611]) + , lookup_u8_0_counts(il[612]) + , lookup_u8_1_counts(il[613]) + , lookup_u16_0_counts(il[614]) + , lookup_u16_1_counts(il[615]) + , lookup_u16_2_counts(il[616]) + , lookup_u16_3_counts(il[617]) + , lookup_u16_4_counts(il[618]) + , lookup_u16_5_counts(il[619]) + , lookup_u16_6_counts(il[620]) + , lookup_u16_7_counts(il[621]) + , lookup_u16_8_counts(il[622]) + , lookup_u16_9_counts(il[623]) + , lookup_u16_10_counts(il[624]) + , lookup_u16_11_counts(il[625]) + , lookup_u16_12_counts(il[626]) + , lookup_u16_13_counts(il[627]) + , lookup_u16_14_counts(il[628]) + , lookup_div_u16_0_counts(il[629]) + , lookup_div_u16_1_counts(il[630]) + , lookup_div_u16_2_counts(il[631]) + , lookup_div_u16_3_counts(il[632]) + , lookup_div_u16_4_counts(il[633]) + , lookup_div_u16_5_counts(il[634]) + , lookup_div_u16_6_counts(il[635]) + , lookup_div_u16_7_counts(il[636]) + , perm_pos_mem_read_a(il[637]) + , perm_pos_mem_read_b(il[638]) + , perm_pos_mem_read_c(il[639]) + , perm_pos_mem_read_d(il[640]) + , perm_pos_mem_write_a(il[641]) + , perm_pos_mem_write_b(il[642]) + , perm_pos_mem_write_c(il[643]) + , perm_pos_mem_write_d(il[644]) + , perm_slice_mem(il[645]) + , perm_main_alu(il[646]) + , perm_main_bin(il[647]) + , perm_main_conv(il[648]) + , perm_main_pos2_perm(il[649]) + , perm_main_pedersen(il[650]) + , perm_main_slice(il[651]) + , perm_main_mem_a(il[652]) + , perm_main_mem_b(il[653]) + , perm_main_mem_c(il[654]) + , perm_main_mem_d(il[655]) + , perm_main_mem_ind_addr_a(il[656]) + , perm_main_mem_ind_addr_b(il[657]) + , perm_main_mem_ind_addr_c(il[658]) + , perm_main_mem_ind_addr_d(il[659]) + , lookup_byte_lengths(il[660]) + , lookup_byte_operations(il[661]) + , lookup_cd_value(il[662]) + , lookup_ret_value(il[663]) + , lookup_opcode_gas(il[664]) + , range_check_l2_gas_hi(il[665]) + , range_check_l2_gas_lo(il[666]) + , range_check_da_gas_hi(il[667]) + , range_check_da_gas_lo(il[668]) + , kernel_output_lookup(il[669]) + , lookup_into_kernel(il[670]) + , incl_main_tag_err(il[671]) + , incl_mem_tag_err(il[672]) + , lookup_mem_rng_chk_lo(il[673]) + , lookup_mem_rng_chk_mid(il[674]) + , lookup_mem_rng_chk_hi(il[675]) + , lookup_pow_2_0(il[676]) + , lookup_pow_2_1(il[677]) + , lookup_u8_0(il[678]) + , lookup_u8_1(il[679]) + , lookup_u16_0(il[680]) + , lookup_u16_1(il[681]) + , lookup_u16_2(il[682]) + , lookup_u16_3(il[683]) + , lookup_u16_4(il[684]) + , lookup_u16_5(il[685]) + , lookup_u16_6(il[686]) + , lookup_u16_7(il[687]) + , lookup_u16_8(il[688]) + , lookup_u16_9(il[689]) + , lookup_u16_10(il[690]) + , lookup_u16_11(il[691]) + , lookup_u16_12(il[692]) + , lookup_u16_13(il[693]) + , lookup_u16_14(il[694]) + , lookup_div_u16_0(il[695]) + , lookup_div_u16_1(il[696]) + , lookup_div_u16_2(il[697]) + , lookup_div_u16_3(il[698]) + , lookup_div_u16_4(il[699]) + , lookup_div_u16_5(il[700]) + , lookup_div_u16_6(il[701]) + , lookup_div_u16_7(il[702]) + , alu_a_hi_shift(il[703]) + , alu_a_lo_shift(il[704]) + , alu_b_hi_shift(il[705]) + , alu_b_lo_shift(il[706]) + , alu_cmp_rng_ctr_shift(il[707]) + , alu_div_u16_r0_shift(il[708]) + , alu_div_u16_r1_shift(il[709]) + , alu_div_u16_r2_shift(il[710]) + , alu_div_u16_r3_shift(il[711]) + , alu_div_u16_r4_shift(il[712]) + , alu_div_u16_r5_shift(il[713]) + , alu_div_u16_r6_shift(il[714]) + , alu_div_u16_r7_shift(il[715]) + , alu_op_add_shift(il[716]) + , alu_op_cast_prev_shift(il[717]) + , alu_op_cast_shift(il[718]) + , alu_op_div_shift(il[719]) + , alu_op_mul_shift(il[720]) + , alu_op_shl_shift(il[721]) + , alu_op_shr_shift(il[722]) + , alu_op_sub_shift(il[723]) + , alu_p_sub_a_hi_shift(il[724]) + , alu_p_sub_a_lo_shift(il[725]) + , alu_p_sub_b_hi_shift(il[726]) + , alu_p_sub_b_lo_shift(il[727]) + , alu_sel_alu_shift(il[728]) + , alu_sel_cmp_shift(il[729]) + , alu_sel_div_rng_chk_shift(il[730]) + , alu_sel_rng_chk_lookup_shift(il[731]) + , alu_sel_rng_chk_shift(il[732]) + , alu_u16_r0_shift(il[733]) + , alu_u16_r1_shift(il[734]) + , alu_u16_r2_shift(il[735]) + , alu_u16_r3_shift(il[736]) + , alu_u16_r4_shift(il[737]) + , alu_u16_r5_shift(il[738]) + , alu_u16_r6_shift(il[739]) + , alu_u8_r0_shift(il[740]) + , alu_u8_r1_shift(il[741]) + , binary_acc_ia_shift(il[742]) + , binary_acc_ib_shift(il[743]) + , binary_acc_ic_shift(il[744]) + , binary_mem_tag_ctr_shift(il[745]) + , binary_op_id_shift(il[746]) + , kernel_emit_l2_to_l1_msg_write_offset_shift(il[747]) + , kernel_emit_note_hash_write_offset_shift(il[748]) + , kernel_emit_nullifier_write_offset_shift(il[749]) + , kernel_emit_unencrypted_log_write_offset_shift(il[750]) + , kernel_l1_to_l2_msg_exists_write_offset_shift(il[751]) + , kernel_note_hash_exist_write_offset_shift(il[752]) + , kernel_nullifier_exists_write_offset_shift(il[753]) + , kernel_nullifier_non_exists_write_offset_shift(il[754]) + , kernel_side_effect_counter_shift(il[755]) + , kernel_sload_write_offset_shift(il[756]) + , kernel_sstore_write_offset_shift(il[757]) + , main_da_gas_remaining_shift(il[758]) + , main_internal_return_ptr_shift(il[759]) + , main_l2_gas_remaining_shift(il[760]) + , main_pc_shift(il[761]) + , mem_glob_addr_shift(il[762]) + , mem_rw_shift(il[763]) + , mem_sel_mem_shift(il[764]) + , mem_tag_shift(il[765]) + , mem_tsp_shift(il[766]) + , mem_val_shift(il[767]) + , slice_addr_shift(il[768]) + , slice_clk_shift(il[769]) + , slice_cnt_shift(il[770]) + , slice_col_offset_shift(il[771]) + , slice_sel_cd_cpy_shift(il[772]) + , slice_sel_mem_active_shift(il[773]) + , slice_sel_return_shift(il[774]) + , slice_sel_start_shift(il[775]) + , slice_space_id_shift(il[776]) {} AvmFlavor::ProverPolynomials::ProverPolynomials(ProvingKey& proving_key) @@ -981,7 +980,6 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id main_sel_gas_accounting_active[row_idx], main_sel_last[row_idx], main_sel_mem_op_a[row_idx], - main_sel_mem_op_activate_gas[row_idx], main_sel_mem_op_b[row_idx], main_sel_mem_op_c[row_idx], main_sel_mem_op_d[row_idx], @@ -1763,7 +1761,6 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::main_sel_gas_accounting_active = "MAIN_SEL_GAS_ACCOUNTING_ACTIVE"; Base::main_sel_last = "MAIN_SEL_LAST"; Base::main_sel_mem_op_a = "MAIN_SEL_MEM_OP_A"; - Base::main_sel_mem_op_activate_gas = "MAIN_SEL_MEM_OP_ACTIVATE_GAS"; Base::main_sel_mem_op_b = "MAIN_SEL_MEM_OP_B"; Base::main_sel_mem_op_c = "MAIN_SEL_MEM_OP_C"; Base::main_sel_mem_op_d = "MAIN_SEL_MEM_OP_D"; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp index da7999d51b3..7661951fbda 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp @@ -102,7 +102,7 @@ template using tuple_cat_t = decltype(std::tuple_cat(std:: // The entities that will be used in the flavor. // clang-format off #define PRECOMPUTED_ENTITIES byte_lookup_sel_bin, byte_lookup_table_byte_lengths, byte_lookup_table_in_tags, byte_lookup_table_input_a, byte_lookup_table_input_b, byte_lookup_table_op_id, byte_lookup_table_output, gas_da_gas_fixed_table, gas_l2_gas_fixed_table, gas_sel_gas_cost, main_clk, main_sel_first, main_zeroes, powers_power_of_2 -#define WIRE_ENTITIES kernel_kernel_inputs, kernel_kernel_value_out, kernel_kernel_side_effect_out, kernel_kernel_metadata_out, main_calldata, main_returndata, alu_a_hi, alu_a_lo, alu_b_hi, alu_b_lo, alu_borrow, alu_cf, alu_clk, alu_cmp_rng_ctr, alu_div_u16_r0, alu_div_u16_r1, alu_div_u16_r2, alu_div_u16_r3, alu_div_u16_r4, alu_div_u16_r5, alu_div_u16_r6, alu_div_u16_r7, alu_divisor_hi, alu_divisor_lo, alu_ff_tag, alu_ia, alu_ib, alu_ic, alu_in_tag, alu_op_add, alu_op_cast, alu_op_cast_prev, alu_op_div, alu_op_div_a_lt_b, alu_op_div_std, alu_op_eq, alu_op_eq_diff_inv, alu_op_lt, alu_op_lte, alu_op_mul, alu_op_not, alu_op_shl, alu_op_shr, alu_op_sub, alu_p_a_borrow, alu_p_b_borrow, alu_p_sub_a_hi, alu_p_sub_a_lo, alu_p_sub_b_hi, alu_p_sub_b_lo, alu_partial_prod_hi, alu_partial_prod_lo, alu_quotient_hi, alu_quotient_lo, alu_remainder, alu_res_hi, alu_res_lo, alu_sel_alu, alu_sel_cmp, alu_sel_div_rng_chk, alu_sel_rng_chk, alu_sel_rng_chk_lookup, alu_sel_shift_which, alu_shift_lt_bit_len, alu_t_sub_s_bits, alu_two_pow_s, alu_two_pow_t_sub_s, alu_u128_tag, alu_u16_r0, alu_u16_r1, alu_u16_r10, alu_u16_r11, alu_u16_r12, alu_u16_r13, alu_u16_r14, alu_u16_r2, alu_u16_r3, alu_u16_r4, alu_u16_r5, alu_u16_r6, alu_u16_r7, alu_u16_r8, alu_u16_r9, alu_u16_tag, alu_u32_tag, alu_u64_tag, alu_u8_r0, alu_u8_r1, alu_u8_tag, binary_acc_ia, binary_acc_ib, binary_acc_ic, binary_clk, binary_ia_bytes, binary_ib_bytes, binary_ic_bytes, binary_in_tag, binary_mem_tag_ctr, binary_mem_tag_ctr_inv, binary_op_id, binary_sel_bin, binary_start, conversion_clk, conversion_input, conversion_num_limbs, conversion_radix, conversion_sel_to_radix_le, keccakf1600_clk, keccakf1600_input, keccakf1600_output, keccakf1600_sel_keccakf1600, kernel_emit_l2_to_l1_msg_write_offset, kernel_emit_note_hash_write_offset, kernel_emit_nullifier_write_offset, kernel_emit_unencrypted_log_write_offset, kernel_kernel_in_offset, kernel_kernel_out_offset, kernel_l1_to_l2_msg_exists_write_offset, kernel_note_hash_exist_write_offset, kernel_nullifier_exists_write_offset, kernel_nullifier_non_exists_write_offset, kernel_q_public_input_kernel_add_to_table, kernel_q_public_input_kernel_out_add_to_table, kernel_side_effect_counter, kernel_sload_write_offset, kernel_sstore_write_offset, main_abs_da_rem_gas_hi, main_abs_da_rem_gas_lo, main_abs_l2_rem_gas_hi, main_abs_l2_rem_gas_lo, main_alu_in_tag, main_bin_op_id, main_call_ptr, main_da_gas_op_cost, main_da_gas_remaining, main_da_out_of_gas, main_ia, main_ib, main_ic, main_id, main_id_zero, main_ind_addr_a, main_ind_addr_b, main_ind_addr_c, main_ind_addr_d, main_internal_return_ptr, main_inv, main_l2_gas_op_cost, main_l2_gas_remaining, main_l2_out_of_gas, main_mem_addr_a, main_mem_addr_b, main_mem_addr_c, main_mem_addr_d, main_op_err, main_opcode_val, main_pc, main_r_in_tag, main_rwa, main_rwb, main_rwc, main_rwd, main_sel_alu, main_sel_bin, main_sel_calldata, main_sel_gas_accounting_active, main_sel_last, main_sel_mem_op_a, main_sel_mem_op_activate_gas, main_sel_mem_op_b, main_sel_mem_op_c, main_sel_mem_op_d, main_sel_mov_ia_to_ic, main_sel_mov_ib_to_ic, main_sel_op_add, main_sel_op_address, main_sel_op_and, main_sel_op_block_number, main_sel_op_calldata_copy, main_sel_op_cast, main_sel_op_chain_id, main_sel_op_cmov, main_sel_op_coinbase, main_sel_op_dagasleft, main_sel_op_div, main_sel_op_emit_l2_to_l1_msg, main_sel_op_emit_note_hash, main_sel_op_emit_nullifier, main_sel_op_emit_unencrypted_log, main_sel_op_eq, main_sel_op_external_call, main_sel_op_external_return, main_sel_op_fdiv, main_sel_op_fee_per_da_gas, main_sel_op_fee_per_l2_gas, main_sel_op_function_selector, main_sel_op_get_contract_instance, main_sel_op_halt, main_sel_op_internal_call, main_sel_op_internal_return, main_sel_op_jump, main_sel_op_jumpi, main_sel_op_keccak, main_sel_op_l1_to_l2_msg_exists, main_sel_op_l2gasleft, main_sel_op_lt, main_sel_op_lte, main_sel_op_mov, main_sel_op_mul, main_sel_op_not, main_sel_op_note_hash_exists, main_sel_op_nullifier_exists, main_sel_op_or, main_sel_op_pedersen, main_sel_op_poseidon2, main_sel_op_radix_le, main_sel_op_sender, main_sel_op_sha256, main_sel_op_shl, main_sel_op_shr, main_sel_op_sload, main_sel_op_sstore, main_sel_op_storage_address, main_sel_op_sub, main_sel_op_timestamp, main_sel_op_transaction_fee, main_sel_op_version, main_sel_op_xor, main_sel_q_kernel_lookup, main_sel_q_kernel_output_lookup, main_sel_resolve_ind_addr_a, main_sel_resolve_ind_addr_b, main_sel_resolve_ind_addr_c, main_sel_resolve_ind_addr_d, main_sel_returndata, main_sel_rng_16, main_sel_rng_8, main_sel_slice_gadget, main_space_id, main_tag_err, main_w_in_tag, mem_addr, mem_clk, mem_diff_hi, mem_diff_lo, mem_diff_mid, mem_glob_addr, mem_last, mem_lastAccess, mem_one_min_inv, mem_r_in_tag, mem_rw, mem_sel_mem, mem_sel_mov_ia_to_ic, mem_sel_mov_ib_to_ic, mem_sel_op_a, mem_sel_op_b, mem_sel_op_c, mem_sel_op_cmov, mem_sel_op_d, mem_sel_op_poseidon_read_a, mem_sel_op_poseidon_read_b, mem_sel_op_poseidon_read_c, mem_sel_op_poseidon_read_d, mem_sel_op_poseidon_write_a, mem_sel_op_poseidon_write_b, mem_sel_op_poseidon_write_c, mem_sel_op_poseidon_write_d, mem_sel_op_slice, mem_sel_resolve_ind_addr_a, mem_sel_resolve_ind_addr_b, mem_sel_resolve_ind_addr_c, mem_sel_resolve_ind_addr_d, mem_sel_rng_chk, mem_skip_check_tag, mem_space_id, mem_tag, mem_tag_err, mem_tsp, mem_val, mem_w_in_tag, pedersen_clk, pedersen_input, pedersen_output, pedersen_sel_pedersen, poseidon2_B_10_0, poseidon2_B_10_1, poseidon2_B_10_2, poseidon2_B_10_3, poseidon2_B_11_0, poseidon2_B_11_1, poseidon2_B_11_2, poseidon2_B_11_3, poseidon2_B_12_0, poseidon2_B_12_1, poseidon2_B_12_2, poseidon2_B_12_3, poseidon2_B_13_0, poseidon2_B_13_1, poseidon2_B_13_2, poseidon2_B_13_3, poseidon2_B_14_0, poseidon2_B_14_1, poseidon2_B_14_2, poseidon2_B_14_3, poseidon2_B_15_0, poseidon2_B_15_1, poseidon2_B_15_2, poseidon2_B_15_3, poseidon2_B_16_0, poseidon2_B_16_1, poseidon2_B_16_2, poseidon2_B_16_3, poseidon2_B_17_0, poseidon2_B_17_1, poseidon2_B_17_2, poseidon2_B_17_3, poseidon2_B_18_0, poseidon2_B_18_1, poseidon2_B_18_2, poseidon2_B_18_3, poseidon2_B_19_0, poseidon2_B_19_1, poseidon2_B_19_2, poseidon2_B_19_3, poseidon2_B_20_0, poseidon2_B_20_1, poseidon2_B_20_2, poseidon2_B_20_3, poseidon2_B_21_0, poseidon2_B_21_1, poseidon2_B_21_2, poseidon2_B_21_3, poseidon2_B_22_0, poseidon2_B_22_1, poseidon2_B_22_2, poseidon2_B_22_3, poseidon2_B_23_0, poseidon2_B_23_1, poseidon2_B_23_2, poseidon2_B_23_3, poseidon2_B_24_0, poseidon2_B_24_1, poseidon2_B_24_2, poseidon2_B_24_3, poseidon2_B_25_0, poseidon2_B_25_1, poseidon2_B_25_2, poseidon2_B_25_3, poseidon2_B_26_0, poseidon2_B_26_1, poseidon2_B_26_2, poseidon2_B_26_3, poseidon2_B_27_0, poseidon2_B_27_1, poseidon2_B_27_2, poseidon2_B_27_3, poseidon2_B_28_0, poseidon2_B_28_1, poseidon2_B_28_2, poseidon2_B_28_3, poseidon2_B_29_0, poseidon2_B_29_1, poseidon2_B_29_2, poseidon2_B_29_3, poseidon2_B_30_0, poseidon2_B_30_1, poseidon2_B_30_2, poseidon2_B_30_3, poseidon2_B_31_0, poseidon2_B_31_1, poseidon2_B_31_2, poseidon2_B_31_3, poseidon2_B_32_0, poseidon2_B_32_1, poseidon2_B_32_2, poseidon2_B_32_3, poseidon2_B_33_0, poseidon2_B_33_1, poseidon2_B_33_2, poseidon2_B_33_3, poseidon2_B_34_0, poseidon2_B_34_1, poseidon2_B_34_2, poseidon2_B_34_3, poseidon2_B_35_0, poseidon2_B_35_1, poseidon2_B_35_2, poseidon2_B_35_3, poseidon2_B_36_0, poseidon2_B_36_1, poseidon2_B_36_2, poseidon2_B_36_3, poseidon2_B_37_0, poseidon2_B_37_1, poseidon2_B_37_2, poseidon2_B_37_3, poseidon2_B_38_0, poseidon2_B_38_1, poseidon2_B_38_2, poseidon2_B_38_3, poseidon2_B_39_0, poseidon2_B_39_1, poseidon2_B_39_2, poseidon2_B_39_3, poseidon2_B_40_0, poseidon2_B_40_1, poseidon2_B_40_2, poseidon2_B_40_3, poseidon2_B_41_0, poseidon2_B_41_1, poseidon2_B_41_2, poseidon2_B_41_3, poseidon2_B_42_0, poseidon2_B_42_1, poseidon2_B_42_2, poseidon2_B_42_3, poseidon2_B_43_0, poseidon2_B_43_1, poseidon2_B_43_2, poseidon2_B_43_3, poseidon2_B_44_0, poseidon2_B_44_1, poseidon2_B_44_2, poseidon2_B_44_3, poseidon2_B_45_0, poseidon2_B_45_1, poseidon2_B_45_2, poseidon2_B_45_3, poseidon2_B_46_0, poseidon2_B_46_1, poseidon2_B_46_2, poseidon2_B_46_3, poseidon2_B_47_0, poseidon2_B_47_1, poseidon2_B_47_2, poseidon2_B_47_3, poseidon2_B_48_0, poseidon2_B_48_1, poseidon2_B_48_2, poseidon2_B_48_3, poseidon2_B_49_0, poseidon2_B_49_1, poseidon2_B_49_2, poseidon2_B_49_3, poseidon2_B_4_0, poseidon2_B_4_1, poseidon2_B_4_2, poseidon2_B_4_3, poseidon2_B_50_0, poseidon2_B_50_1, poseidon2_B_50_2, poseidon2_B_50_3, poseidon2_B_51_0, poseidon2_B_51_1, poseidon2_B_51_2, poseidon2_B_51_3, poseidon2_B_52_0, poseidon2_B_52_1, poseidon2_B_52_2, poseidon2_B_52_3, poseidon2_B_53_0, poseidon2_B_53_1, poseidon2_B_53_2, poseidon2_B_53_3, poseidon2_B_54_0, poseidon2_B_54_1, poseidon2_B_54_2, poseidon2_B_54_3, poseidon2_B_55_0, poseidon2_B_55_1, poseidon2_B_55_2, poseidon2_B_55_3, poseidon2_B_56_0, poseidon2_B_56_1, poseidon2_B_56_2, poseidon2_B_56_3, poseidon2_B_57_0, poseidon2_B_57_1, poseidon2_B_57_2, poseidon2_B_57_3, poseidon2_B_58_0, poseidon2_B_58_1, poseidon2_B_58_2, poseidon2_B_58_3, poseidon2_B_59_0, poseidon2_B_59_1, poseidon2_B_59_2, poseidon2_B_59_3, poseidon2_B_5_0, poseidon2_B_5_1, poseidon2_B_5_2, poseidon2_B_5_3, poseidon2_B_6_0, poseidon2_B_6_1, poseidon2_B_6_2, poseidon2_B_6_3, poseidon2_B_7_0, poseidon2_B_7_1, poseidon2_B_7_2, poseidon2_B_7_3, poseidon2_B_8_0, poseidon2_B_8_1, poseidon2_B_8_2, poseidon2_B_8_3, poseidon2_B_9_0, poseidon2_B_9_1, poseidon2_B_9_2, poseidon2_B_9_3, poseidon2_EXT_LAYER_4, poseidon2_EXT_LAYER_5, poseidon2_EXT_LAYER_6, poseidon2_EXT_LAYER_7, poseidon2_T_0_4, poseidon2_T_0_5, poseidon2_T_0_6, poseidon2_T_0_7, poseidon2_T_1_4, poseidon2_T_1_5, poseidon2_T_1_6, poseidon2_T_1_7, poseidon2_T_2_4, poseidon2_T_2_5, poseidon2_T_2_6, poseidon2_T_2_7, poseidon2_T_3_4, poseidon2_T_3_5, poseidon2_T_3_6, poseidon2_T_3_7, poseidon2_T_60_4, poseidon2_T_60_5, poseidon2_T_60_6, poseidon2_T_60_7, poseidon2_T_61_4, poseidon2_T_61_5, poseidon2_T_61_6, poseidon2_T_61_7, poseidon2_T_62_4, poseidon2_T_62_5, poseidon2_T_62_6, poseidon2_T_62_7, poseidon2_T_63_4, poseidon2_T_63_5, poseidon2_T_63_6, poseidon2_T_63_7, poseidon2_a_0, poseidon2_a_1, poseidon2_a_2, poseidon2_a_3, poseidon2_b_0, poseidon2_b_1, poseidon2_b_2, poseidon2_b_3, poseidon2_clk, poseidon2_input_addr, poseidon2_mem_addr_read_a, poseidon2_mem_addr_read_b, poseidon2_mem_addr_read_c, poseidon2_mem_addr_read_d, poseidon2_mem_addr_write_a, poseidon2_mem_addr_write_b, poseidon2_mem_addr_write_c, poseidon2_mem_addr_write_d, poseidon2_output_addr, poseidon2_sel_poseidon_perm, sha256_clk, sha256_input, sha256_output, sha256_sel_sha256_compression, sha256_state, slice_addr, slice_clk, slice_cnt, slice_col_offset, slice_one_min_inv, slice_sel_cd_cpy, slice_sel_mem_active, slice_sel_return, slice_sel_start, slice_space_id, slice_val, lookup_byte_lengths_counts, lookup_byte_operations_counts, lookup_cd_value_counts, lookup_ret_value_counts, lookup_opcode_gas_counts, range_check_l2_gas_hi_counts, range_check_l2_gas_lo_counts, range_check_da_gas_hi_counts, range_check_da_gas_lo_counts, kernel_output_lookup_counts, lookup_into_kernel_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts, lookup_mem_rng_chk_lo_counts, lookup_mem_rng_chk_mid_counts, lookup_mem_rng_chk_hi_counts, lookup_pow_2_0_counts, lookup_pow_2_1_counts, lookup_u8_0_counts, lookup_u8_1_counts, lookup_u16_0_counts, lookup_u16_1_counts, lookup_u16_2_counts, lookup_u16_3_counts, lookup_u16_4_counts, lookup_u16_5_counts, lookup_u16_6_counts, lookup_u16_7_counts, lookup_u16_8_counts, lookup_u16_9_counts, lookup_u16_10_counts, lookup_u16_11_counts, lookup_u16_12_counts, lookup_u16_13_counts, lookup_u16_14_counts, lookup_div_u16_0_counts, lookup_div_u16_1_counts, lookup_div_u16_2_counts, lookup_div_u16_3_counts, lookup_div_u16_4_counts, lookup_div_u16_5_counts, lookup_div_u16_6_counts, lookup_div_u16_7_counts +#define WIRE_ENTITIES kernel_kernel_inputs, kernel_kernel_value_out, kernel_kernel_side_effect_out, kernel_kernel_metadata_out, main_calldata, main_returndata, alu_a_hi, alu_a_lo, alu_b_hi, alu_b_lo, alu_borrow, alu_cf, alu_clk, alu_cmp_rng_ctr, alu_div_u16_r0, alu_div_u16_r1, alu_div_u16_r2, alu_div_u16_r3, alu_div_u16_r4, alu_div_u16_r5, alu_div_u16_r6, alu_div_u16_r7, alu_divisor_hi, alu_divisor_lo, alu_ff_tag, alu_ia, alu_ib, alu_ic, alu_in_tag, alu_op_add, alu_op_cast, alu_op_cast_prev, alu_op_div, alu_op_div_a_lt_b, alu_op_div_std, alu_op_eq, alu_op_eq_diff_inv, alu_op_lt, alu_op_lte, alu_op_mul, alu_op_not, alu_op_shl, alu_op_shr, alu_op_sub, alu_p_a_borrow, alu_p_b_borrow, alu_p_sub_a_hi, alu_p_sub_a_lo, alu_p_sub_b_hi, alu_p_sub_b_lo, alu_partial_prod_hi, alu_partial_prod_lo, alu_quotient_hi, alu_quotient_lo, alu_remainder, alu_res_hi, alu_res_lo, alu_sel_alu, alu_sel_cmp, alu_sel_div_rng_chk, alu_sel_rng_chk, alu_sel_rng_chk_lookup, alu_sel_shift_which, alu_shift_lt_bit_len, alu_t_sub_s_bits, alu_two_pow_s, alu_two_pow_t_sub_s, alu_u128_tag, alu_u16_r0, alu_u16_r1, alu_u16_r10, alu_u16_r11, alu_u16_r12, alu_u16_r13, alu_u16_r14, alu_u16_r2, alu_u16_r3, alu_u16_r4, alu_u16_r5, alu_u16_r6, alu_u16_r7, alu_u16_r8, alu_u16_r9, alu_u16_tag, alu_u32_tag, alu_u64_tag, alu_u8_r0, alu_u8_r1, alu_u8_tag, binary_acc_ia, binary_acc_ib, binary_acc_ic, binary_clk, binary_ia_bytes, binary_ib_bytes, binary_ic_bytes, binary_in_tag, binary_mem_tag_ctr, binary_mem_tag_ctr_inv, binary_op_id, binary_sel_bin, binary_start, conversion_clk, conversion_input, conversion_num_limbs, conversion_radix, conversion_sel_to_radix_le, keccakf1600_clk, keccakf1600_input, keccakf1600_output, keccakf1600_sel_keccakf1600, kernel_emit_l2_to_l1_msg_write_offset, kernel_emit_note_hash_write_offset, kernel_emit_nullifier_write_offset, kernel_emit_unencrypted_log_write_offset, kernel_kernel_in_offset, kernel_kernel_out_offset, kernel_l1_to_l2_msg_exists_write_offset, kernel_note_hash_exist_write_offset, kernel_nullifier_exists_write_offset, kernel_nullifier_non_exists_write_offset, kernel_q_public_input_kernel_add_to_table, kernel_q_public_input_kernel_out_add_to_table, kernel_side_effect_counter, kernel_sload_write_offset, kernel_sstore_write_offset, main_abs_da_rem_gas_hi, main_abs_da_rem_gas_lo, main_abs_l2_rem_gas_hi, main_abs_l2_rem_gas_lo, main_alu_in_tag, main_bin_op_id, main_call_ptr, main_da_gas_op_cost, main_da_gas_remaining, main_da_out_of_gas, main_ia, main_ib, main_ic, main_id, main_id_zero, main_ind_addr_a, main_ind_addr_b, main_ind_addr_c, main_ind_addr_d, main_internal_return_ptr, main_inv, main_l2_gas_op_cost, main_l2_gas_remaining, main_l2_out_of_gas, main_mem_addr_a, main_mem_addr_b, main_mem_addr_c, main_mem_addr_d, main_op_err, main_opcode_val, main_pc, main_r_in_tag, main_rwa, main_rwb, main_rwc, main_rwd, main_sel_alu, main_sel_bin, main_sel_calldata, main_sel_gas_accounting_active, main_sel_last, main_sel_mem_op_a, main_sel_mem_op_b, main_sel_mem_op_c, main_sel_mem_op_d, main_sel_mov_ia_to_ic, main_sel_mov_ib_to_ic, main_sel_op_add, main_sel_op_address, main_sel_op_and, main_sel_op_block_number, main_sel_op_calldata_copy, main_sel_op_cast, main_sel_op_chain_id, main_sel_op_cmov, main_sel_op_coinbase, main_sel_op_dagasleft, main_sel_op_div, main_sel_op_emit_l2_to_l1_msg, main_sel_op_emit_note_hash, main_sel_op_emit_nullifier, main_sel_op_emit_unencrypted_log, main_sel_op_eq, main_sel_op_external_call, main_sel_op_external_return, main_sel_op_fdiv, main_sel_op_fee_per_da_gas, main_sel_op_fee_per_l2_gas, main_sel_op_function_selector, main_sel_op_get_contract_instance, main_sel_op_halt, main_sel_op_internal_call, main_sel_op_internal_return, main_sel_op_jump, main_sel_op_jumpi, main_sel_op_keccak, main_sel_op_l1_to_l2_msg_exists, main_sel_op_l2gasleft, main_sel_op_lt, main_sel_op_lte, main_sel_op_mov, main_sel_op_mul, main_sel_op_not, main_sel_op_note_hash_exists, main_sel_op_nullifier_exists, main_sel_op_or, main_sel_op_pedersen, main_sel_op_poseidon2, main_sel_op_radix_le, main_sel_op_sender, main_sel_op_sha256, main_sel_op_shl, main_sel_op_shr, main_sel_op_sload, main_sel_op_sstore, main_sel_op_storage_address, main_sel_op_sub, main_sel_op_timestamp, main_sel_op_transaction_fee, main_sel_op_version, main_sel_op_xor, main_sel_q_kernel_lookup, main_sel_q_kernel_output_lookup, main_sel_resolve_ind_addr_a, main_sel_resolve_ind_addr_b, main_sel_resolve_ind_addr_c, main_sel_resolve_ind_addr_d, main_sel_returndata, main_sel_rng_16, main_sel_rng_8, main_sel_slice_gadget, main_space_id, main_tag_err, main_w_in_tag, mem_addr, mem_clk, mem_diff_hi, mem_diff_lo, mem_diff_mid, mem_glob_addr, mem_last, mem_lastAccess, mem_one_min_inv, mem_r_in_tag, mem_rw, mem_sel_mem, mem_sel_mov_ia_to_ic, mem_sel_mov_ib_to_ic, mem_sel_op_a, mem_sel_op_b, mem_sel_op_c, mem_sel_op_cmov, mem_sel_op_d, mem_sel_op_poseidon_read_a, mem_sel_op_poseidon_read_b, mem_sel_op_poseidon_read_c, mem_sel_op_poseidon_read_d, mem_sel_op_poseidon_write_a, mem_sel_op_poseidon_write_b, mem_sel_op_poseidon_write_c, mem_sel_op_poseidon_write_d, mem_sel_op_slice, mem_sel_resolve_ind_addr_a, mem_sel_resolve_ind_addr_b, mem_sel_resolve_ind_addr_c, mem_sel_resolve_ind_addr_d, mem_sel_rng_chk, mem_skip_check_tag, mem_space_id, mem_tag, mem_tag_err, mem_tsp, mem_val, mem_w_in_tag, pedersen_clk, pedersen_input, pedersen_output, pedersen_sel_pedersen, poseidon2_B_10_0, poseidon2_B_10_1, poseidon2_B_10_2, poseidon2_B_10_3, poseidon2_B_11_0, poseidon2_B_11_1, poseidon2_B_11_2, poseidon2_B_11_3, poseidon2_B_12_0, poseidon2_B_12_1, poseidon2_B_12_2, poseidon2_B_12_3, poseidon2_B_13_0, poseidon2_B_13_1, poseidon2_B_13_2, poseidon2_B_13_3, poseidon2_B_14_0, poseidon2_B_14_1, poseidon2_B_14_2, poseidon2_B_14_3, poseidon2_B_15_0, poseidon2_B_15_1, poseidon2_B_15_2, poseidon2_B_15_3, poseidon2_B_16_0, poseidon2_B_16_1, poseidon2_B_16_2, poseidon2_B_16_3, poseidon2_B_17_0, poseidon2_B_17_1, poseidon2_B_17_2, poseidon2_B_17_3, poseidon2_B_18_0, poseidon2_B_18_1, poseidon2_B_18_2, poseidon2_B_18_3, poseidon2_B_19_0, poseidon2_B_19_1, poseidon2_B_19_2, poseidon2_B_19_3, poseidon2_B_20_0, poseidon2_B_20_1, poseidon2_B_20_2, poseidon2_B_20_3, poseidon2_B_21_0, poseidon2_B_21_1, poseidon2_B_21_2, poseidon2_B_21_3, poseidon2_B_22_0, poseidon2_B_22_1, poseidon2_B_22_2, poseidon2_B_22_3, poseidon2_B_23_0, poseidon2_B_23_1, poseidon2_B_23_2, poseidon2_B_23_3, poseidon2_B_24_0, poseidon2_B_24_1, poseidon2_B_24_2, poseidon2_B_24_3, poseidon2_B_25_0, poseidon2_B_25_1, poseidon2_B_25_2, poseidon2_B_25_3, poseidon2_B_26_0, poseidon2_B_26_1, poseidon2_B_26_2, poseidon2_B_26_3, poseidon2_B_27_0, poseidon2_B_27_1, poseidon2_B_27_2, poseidon2_B_27_3, poseidon2_B_28_0, poseidon2_B_28_1, poseidon2_B_28_2, poseidon2_B_28_3, poseidon2_B_29_0, poseidon2_B_29_1, poseidon2_B_29_2, poseidon2_B_29_3, poseidon2_B_30_0, poseidon2_B_30_1, poseidon2_B_30_2, poseidon2_B_30_3, poseidon2_B_31_0, poseidon2_B_31_1, poseidon2_B_31_2, poseidon2_B_31_3, poseidon2_B_32_0, poseidon2_B_32_1, poseidon2_B_32_2, poseidon2_B_32_3, poseidon2_B_33_0, poseidon2_B_33_1, poseidon2_B_33_2, poseidon2_B_33_3, poseidon2_B_34_0, poseidon2_B_34_1, poseidon2_B_34_2, poseidon2_B_34_3, poseidon2_B_35_0, poseidon2_B_35_1, poseidon2_B_35_2, poseidon2_B_35_3, poseidon2_B_36_0, poseidon2_B_36_1, poseidon2_B_36_2, poseidon2_B_36_3, poseidon2_B_37_0, poseidon2_B_37_1, poseidon2_B_37_2, poseidon2_B_37_3, poseidon2_B_38_0, poseidon2_B_38_1, poseidon2_B_38_2, poseidon2_B_38_3, poseidon2_B_39_0, poseidon2_B_39_1, poseidon2_B_39_2, poseidon2_B_39_3, poseidon2_B_40_0, poseidon2_B_40_1, poseidon2_B_40_2, poseidon2_B_40_3, poseidon2_B_41_0, poseidon2_B_41_1, poseidon2_B_41_2, poseidon2_B_41_3, poseidon2_B_42_0, poseidon2_B_42_1, poseidon2_B_42_2, poseidon2_B_42_3, poseidon2_B_43_0, poseidon2_B_43_1, poseidon2_B_43_2, poseidon2_B_43_3, poseidon2_B_44_0, poseidon2_B_44_1, poseidon2_B_44_2, poseidon2_B_44_3, poseidon2_B_45_0, poseidon2_B_45_1, poseidon2_B_45_2, poseidon2_B_45_3, poseidon2_B_46_0, poseidon2_B_46_1, poseidon2_B_46_2, poseidon2_B_46_3, poseidon2_B_47_0, poseidon2_B_47_1, poseidon2_B_47_2, poseidon2_B_47_3, poseidon2_B_48_0, poseidon2_B_48_1, poseidon2_B_48_2, poseidon2_B_48_3, poseidon2_B_49_0, poseidon2_B_49_1, poseidon2_B_49_2, poseidon2_B_49_3, poseidon2_B_4_0, poseidon2_B_4_1, poseidon2_B_4_2, poseidon2_B_4_3, poseidon2_B_50_0, poseidon2_B_50_1, poseidon2_B_50_2, poseidon2_B_50_3, poseidon2_B_51_0, poseidon2_B_51_1, poseidon2_B_51_2, poseidon2_B_51_3, poseidon2_B_52_0, poseidon2_B_52_1, poseidon2_B_52_2, poseidon2_B_52_3, poseidon2_B_53_0, poseidon2_B_53_1, poseidon2_B_53_2, poseidon2_B_53_3, poseidon2_B_54_0, poseidon2_B_54_1, poseidon2_B_54_2, poseidon2_B_54_3, poseidon2_B_55_0, poseidon2_B_55_1, poseidon2_B_55_2, poseidon2_B_55_3, poseidon2_B_56_0, poseidon2_B_56_1, poseidon2_B_56_2, poseidon2_B_56_3, poseidon2_B_57_0, poseidon2_B_57_1, poseidon2_B_57_2, poseidon2_B_57_3, poseidon2_B_58_0, poseidon2_B_58_1, poseidon2_B_58_2, poseidon2_B_58_3, poseidon2_B_59_0, poseidon2_B_59_1, poseidon2_B_59_2, poseidon2_B_59_3, poseidon2_B_5_0, poseidon2_B_5_1, poseidon2_B_5_2, poseidon2_B_5_3, poseidon2_B_6_0, poseidon2_B_6_1, poseidon2_B_6_2, poseidon2_B_6_3, poseidon2_B_7_0, poseidon2_B_7_1, poseidon2_B_7_2, poseidon2_B_7_3, poseidon2_B_8_0, poseidon2_B_8_1, poseidon2_B_8_2, poseidon2_B_8_3, poseidon2_B_9_0, poseidon2_B_9_1, poseidon2_B_9_2, poseidon2_B_9_3, poseidon2_EXT_LAYER_4, poseidon2_EXT_LAYER_5, poseidon2_EXT_LAYER_6, poseidon2_EXT_LAYER_7, poseidon2_T_0_4, poseidon2_T_0_5, poseidon2_T_0_6, poseidon2_T_0_7, poseidon2_T_1_4, poseidon2_T_1_5, poseidon2_T_1_6, poseidon2_T_1_7, poseidon2_T_2_4, poseidon2_T_2_5, poseidon2_T_2_6, poseidon2_T_2_7, poseidon2_T_3_4, poseidon2_T_3_5, poseidon2_T_3_6, poseidon2_T_3_7, poseidon2_T_60_4, poseidon2_T_60_5, poseidon2_T_60_6, poseidon2_T_60_7, poseidon2_T_61_4, poseidon2_T_61_5, poseidon2_T_61_6, poseidon2_T_61_7, poseidon2_T_62_4, poseidon2_T_62_5, poseidon2_T_62_6, poseidon2_T_62_7, poseidon2_T_63_4, poseidon2_T_63_5, poseidon2_T_63_6, poseidon2_T_63_7, poseidon2_a_0, poseidon2_a_1, poseidon2_a_2, poseidon2_a_3, poseidon2_b_0, poseidon2_b_1, poseidon2_b_2, poseidon2_b_3, poseidon2_clk, poseidon2_input_addr, poseidon2_mem_addr_read_a, poseidon2_mem_addr_read_b, poseidon2_mem_addr_read_c, poseidon2_mem_addr_read_d, poseidon2_mem_addr_write_a, poseidon2_mem_addr_write_b, poseidon2_mem_addr_write_c, poseidon2_mem_addr_write_d, poseidon2_output_addr, poseidon2_sel_poseidon_perm, sha256_clk, sha256_input, sha256_output, sha256_sel_sha256_compression, sha256_state, slice_addr, slice_clk, slice_cnt, slice_col_offset, slice_one_min_inv, slice_sel_cd_cpy, slice_sel_mem_active, slice_sel_return, slice_sel_start, slice_space_id, slice_val, lookup_byte_lengths_counts, lookup_byte_operations_counts, lookup_cd_value_counts, lookup_ret_value_counts, lookup_opcode_gas_counts, range_check_l2_gas_hi_counts, range_check_l2_gas_lo_counts, range_check_da_gas_hi_counts, range_check_da_gas_lo_counts, kernel_output_lookup_counts, lookup_into_kernel_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts, lookup_mem_rng_chk_lo_counts, lookup_mem_rng_chk_mid_counts, lookup_mem_rng_chk_hi_counts, lookup_pow_2_0_counts, lookup_pow_2_1_counts, lookup_u8_0_counts, lookup_u8_1_counts, lookup_u16_0_counts, lookup_u16_1_counts, lookup_u16_2_counts, lookup_u16_3_counts, lookup_u16_4_counts, lookup_u16_5_counts, lookup_u16_6_counts, lookup_u16_7_counts, lookup_u16_8_counts, lookup_u16_9_counts, lookup_u16_10_counts, lookup_u16_11_counts, lookup_u16_12_counts, lookup_u16_13_counts, lookup_u16_14_counts, lookup_div_u16_0_counts, lookup_div_u16_1_counts, lookup_div_u16_2_counts, lookup_div_u16_3_counts, lookup_div_u16_4_counts, lookup_div_u16_5_counts, lookup_div_u16_6_counts, lookup_div_u16_7_counts #define DERIVED_WITNESS_ENTITIES perm_pos_mem_read_a, perm_pos_mem_read_b, perm_pos_mem_read_c, perm_pos_mem_read_d, perm_pos_mem_write_a, perm_pos_mem_write_b, perm_pos_mem_write_c, perm_pos_mem_write_d, perm_slice_mem, perm_main_alu, perm_main_bin, perm_main_conv, perm_main_pos2_perm, perm_main_pedersen, perm_main_slice, perm_main_mem_a, perm_main_mem_b, perm_main_mem_c, perm_main_mem_d, perm_main_mem_ind_addr_a, perm_main_mem_ind_addr_b, perm_main_mem_ind_addr_c, perm_main_mem_ind_addr_d, lookup_byte_lengths, lookup_byte_operations, lookup_cd_value, lookup_ret_value, lookup_opcode_gas, range_check_l2_gas_hi, range_check_l2_gas_lo, range_check_da_gas_hi, range_check_da_gas_lo, kernel_output_lookup, lookup_into_kernel, incl_main_tag_err, incl_mem_tag_err, lookup_mem_rng_chk_lo, lookup_mem_rng_chk_mid, 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 #define SHIFTED_ENTITIES alu_a_hi_shift, alu_a_lo_shift, alu_b_hi_shift, alu_b_lo_shift, alu_cmp_rng_ctr_shift, alu_div_u16_r0_shift, alu_div_u16_r1_shift, alu_div_u16_r2_shift, alu_div_u16_r3_shift, alu_div_u16_r4_shift, alu_div_u16_r5_shift, alu_div_u16_r6_shift, alu_div_u16_r7_shift, alu_op_add_shift, alu_op_cast_prev_shift, alu_op_cast_shift, alu_op_div_shift, alu_op_mul_shift, alu_op_shl_shift, alu_op_shr_shift, alu_op_sub_shift, alu_p_sub_a_hi_shift, alu_p_sub_a_lo_shift, alu_p_sub_b_hi_shift, alu_p_sub_b_lo_shift, alu_sel_alu_shift, alu_sel_cmp_shift, alu_sel_div_rng_chk_shift, alu_sel_rng_chk_lookup_shift, alu_sel_rng_chk_shift, alu_u16_r0_shift, alu_u16_r1_shift, alu_u16_r2_shift, alu_u16_r3_shift, alu_u16_r4_shift, alu_u16_r5_shift, alu_u16_r6_shift, alu_u8_r0_shift, alu_u8_r1_shift, binary_acc_ia_shift, binary_acc_ib_shift, binary_acc_ic_shift, binary_mem_tag_ctr_shift, binary_op_id_shift, kernel_emit_l2_to_l1_msg_write_offset_shift, kernel_emit_note_hash_write_offset_shift, kernel_emit_nullifier_write_offset_shift, kernel_emit_unencrypted_log_write_offset_shift, kernel_l1_to_l2_msg_exists_write_offset_shift, kernel_note_hash_exist_write_offset_shift, kernel_nullifier_exists_write_offset_shift, kernel_nullifier_non_exists_write_offset_shift, kernel_side_effect_counter_shift, kernel_sload_write_offset_shift, kernel_sstore_write_offset_shift, main_da_gas_remaining_shift, main_internal_return_ptr_shift, main_l2_gas_remaining_shift, main_pc_shift, mem_glob_addr_shift, mem_rw_shift, mem_sel_mem_shift, mem_tag_shift, mem_tsp_shift, mem_val_shift, slice_addr_shift, slice_clk_shift, slice_cnt_shift, slice_col_offset_shift, slice_sel_cd_cpy_shift, slice_sel_mem_active_shift, slice_sel_return_shift, slice_sel_start_shift, slice_space_id_shift #define TO_BE_SHIFTED(e) e.alu_a_hi, e.alu_a_lo, e.alu_b_hi, e.alu_b_lo, e.alu_cmp_rng_ctr, e.alu_div_u16_r0, e.alu_div_u16_r1, e.alu_div_u16_r2, e.alu_div_u16_r3, e.alu_div_u16_r4, e.alu_div_u16_r5, e.alu_div_u16_r6, e.alu_div_u16_r7, e.alu_op_add, e.alu_op_cast_prev, e.alu_op_cast, e.alu_op_div, e.alu_op_mul, e.alu_op_shl, e.alu_op_shr, e.alu_op_sub, e.alu_p_sub_a_hi, e.alu_p_sub_a_lo, e.alu_p_sub_b_hi, e.alu_p_sub_b_lo, e.alu_sel_alu, e.alu_sel_cmp, e.alu_sel_div_rng_chk, e.alu_sel_rng_chk_lookup, e.alu_sel_rng_chk, e.alu_u16_r0, e.alu_u16_r1, e.alu_u16_r2, e.alu_u16_r3, e.alu_u16_r4, e.alu_u16_r5, e.alu_u16_r6, e.alu_u8_r0, e.alu_u8_r1, e.binary_acc_ia, e.binary_acc_ib, e.binary_acc_ic, e.binary_mem_tag_ctr, e.binary_op_id, e.kernel_emit_l2_to_l1_msg_write_offset, e.kernel_emit_note_hash_write_offset, e.kernel_emit_nullifier_write_offset, e.kernel_emit_unencrypted_log_write_offset, e.kernel_l1_to_l2_msg_exists_write_offset, e.kernel_note_hash_exist_write_offset, e.kernel_nullifier_exists_write_offset, e.kernel_nullifier_non_exists_write_offset, e.kernel_side_effect_counter, e.kernel_sload_write_offset, e.kernel_sstore_write_offset, e.main_da_gas_remaining, e.main_internal_return_ptr, e.main_l2_gas_remaining, e.main_pc, e.mem_glob_addr, e.mem_rw, e.mem_sel_mem, e.mem_tag, e.mem_tsp, e.mem_val, e.slice_addr, e.slice_clk, e.slice_cnt, e.slice_col_offset, e.slice_sel_cd_cpy, e.slice_sel_mem_active, e.slice_sel_return, e.slice_sel_start, e.slice_space_id @@ -128,11 +128,11 @@ class AvmFlavor { using RelationSeparator = AvmFlavorSettings::RelationSeparator; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 14; - static constexpr size_t NUM_WITNESS_ENTITIES = 690; + static constexpr size_t NUM_WITNESS_ENTITIES = 689; 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 = 778; + static constexpr size_t NUM_ALL_ENTITIES = 777; using MainRelations = std::tuple< // Relations diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp index eb57c0bd310..f4e669998ab 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp @@ -201,7 +201,6 @@ template std::vector AvmFullRow::names() "main_sel_gas_accounting_active", "main_sel_last", "main_sel_mem_op_a", - "main_sel_mem_op_activate_gas", "main_sel_mem_op_b", "main_sel_mem_op_c", "main_sel_mem_op_d", @@ -910,7 +909,6 @@ template RefVector AvmFullRow::as_vector() const main_sel_gas_accounting_active, main_sel_last, main_sel_mem_op_a, - main_sel_mem_op_activate_gas, main_sel_mem_op_b, main_sel_mem_op_c, main_sel_mem_op_d, diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp index 278ce258c3c..13e075cf7b9 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp @@ -192,7 +192,6 @@ template struct AvmFullRow { FF main_sel_gas_accounting_active{}; FF main_sel_last{}; FF main_sel_mem_op_a{}; - FF main_sel_mem_op_activate_gas{}; FF main_sel_mem_op_b{}; FF main_sel_mem_op_c{}; FF main_sel_mem_op_d{}; @@ -718,7 +717,7 @@ template struct AvmFullRow { RefVector as_vector() const; static std::vector names(); - static constexpr size_t SIZE = 704; + static constexpr size_t SIZE = 703; }; template std::ostream& operator<<(std::ostream& os, AvmFullRow const& row); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp index a1e07822a12..25fc0d01cc3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp @@ -59,7 +59,6 @@ template struct MainRow { FF main_sel_first{}; FF main_sel_gas_accounting_active{}; FF main_sel_mem_op_a{}; - FF main_sel_mem_op_activate_gas{}; FF main_sel_mem_op_b{}; FF main_sel_mem_op_c{}; FF main_sel_mem_op_d{}; @@ -135,12 +134,12 @@ template class mainImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { - 3, 3, 3, 3, 3, 3, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 4, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 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, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2 + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { + 3, 3, 4, 4, 3, 3, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 4, 3, 3, 3, 3, 3, 3, 4, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 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, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2 }; template @@ -163,7 +162,7 @@ template class mainImpl { } { using Accumulator = typename std::tuple_element_t<2, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_gas_accounting_active * + auto tmp = ((new_term.main_sel_gas_accounting_active * (-new_term.main_sel_op_external_call + FF(1))) * ((new_term.main_l2_gas_remaining_shift - new_term.main_l2_gas_remaining) + new_term.main_l2_gas_op_cost)); tmp *= scaling_factor; @@ -171,7 +170,7 @@ template class mainImpl { } { using Accumulator = typename std::tuple_element_t<3, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_gas_accounting_active * + auto tmp = ((new_term.main_sel_gas_accounting_active * (-new_term.main_sel_op_external_call + FF(1))) * ((new_term.main_da_gas_remaining_shift - new_term.main_da_gas_remaining) + new_term.main_da_gas_op_cost)); tmp *= scaling_factor; @@ -784,54 +783,6 @@ template class mainImpl { } { using Accumulator = typename std::tuple_element_t<99, ContainerOverSubrelations>; - auto tmp = - (((((new_term.main_sel_gas_accounting_active - - ((((((((new_term.main_sel_op_fdiv + - ((((((((((new_term.main_sel_op_add + new_term.main_sel_op_sub) + - new_term.main_sel_op_mul) + - new_term.main_sel_op_div) + - new_term.main_sel_op_not) + - new_term.main_sel_op_eq) + - new_term.main_sel_op_lt) + - new_term.main_sel_op_lte) + - new_term.main_sel_op_shr) + - new_term.main_sel_op_shl) + - new_term.main_sel_op_cast)) + - ((new_term.main_sel_op_and + new_term.main_sel_op_or) + new_term.main_sel_op_xor)) + - (new_term.main_sel_op_cmov + new_term.main_sel_op_mov)) + - ((((new_term.main_sel_op_radix_le + new_term.main_sel_op_sha256) + - new_term.main_sel_op_poseidon2) + - new_term.main_sel_op_keccak) + - new_term.main_sel_op_pedersen)) + - (((((((((((new_term.main_sel_op_address + new_term.main_sel_op_storage_address) + - new_term.main_sel_op_sender) + - new_term.main_sel_op_function_selector) + - new_term.main_sel_op_transaction_fee) + - new_term.main_sel_op_chain_id) + - new_term.main_sel_op_version) + - new_term.main_sel_op_block_number) + - new_term.main_sel_op_coinbase) + - new_term.main_sel_op_timestamp) + - new_term.main_sel_op_fee_per_l2_gas) + - new_term.main_sel_op_fee_per_da_gas)) + - ((((((new_term.main_sel_op_note_hash_exists + new_term.main_sel_op_emit_note_hash) + - new_term.main_sel_op_nullifier_exists) + - new_term.main_sel_op_emit_nullifier) + - new_term.main_sel_op_l1_to_l2_msg_exists) + - new_term.main_sel_op_emit_unencrypted_log) + - new_term.main_sel_op_emit_l2_to_l1_msg)) + - (new_term.main_sel_op_dagasleft + new_term.main_sel_op_l2gasleft)) + - (new_term.main_sel_op_calldata_copy + new_term.main_sel_op_external_return))) - - (((new_term.main_sel_op_jump + new_term.main_sel_op_jumpi) + new_term.main_sel_op_internal_call) + - new_term.main_sel_op_internal_return)) - - new_term.main_sel_op_sload) - - new_term.main_sel_op_sstore) - - new_term.main_sel_mem_op_activate_gas); - tmp *= scaling_factor; - std::get<99>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<100, ContainerOverSubrelations>; auto tmp = ((((-new_term.main_sel_first + FF(1)) * (-new_term.main_sel_op_halt + FF(1))) * ((((((((new_term.main_sel_op_fdiv + @@ -871,27 +822,27 @@ template class mainImpl { (new_term.main_sel_op_calldata_copy + new_term.main_sel_op_external_return))) * (new_term.main_pc_shift - (new_term.main_pc + FF(1)))); tmp *= scaling_factor; - std::get<100>(evals) += typename Accumulator::View(tmp); + std::get<99>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<101, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<100, ContainerOverSubrelations>; auto tmp = ((-(((new_term.main_sel_first + new_term.main_sel_op_internal_call) + new_term.main_sel_op_internal_return) + new_term.main_sel_op_halt) + FF(1)) * (new_term.main_internal_return_ptr_shift - new_term.main_internal_return_ptr)); tmp *= scaling_factor; - std::get<101>(evals) += typename Accumulator::View(tmp); + std::get<100>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<102, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<101, ContainerOverSubrelations>; auto tmp = ((new_term.main_sel_op_internal_call + new_term.main_sel_op_internal_return) * (new_term.main_space_id - FF(255))); tmp *= scaling_factor; - std::get<102>(evals) += typename Accumulator::View(tmp); + std::get<101>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<103, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<102, ContainerOverSubrelations>; auto tmp = (((((((((new_term.main_sel_op_fdiv + ((((((((((new_term.main_sel_op_add + new_term.main_sel_op_sub) + new_term.main_sel_op_mul) + @@ -930,56 +881,56 @@ template class mainImpl { (new_term.main_sel_op_calldata_copy + new_term.main_sel_op_external_return)) * (new_term.main_call_ptr - new_term.main_space_id)); tmp *= scaling_factor; - std::get<103>(evals) += typename Accumulator::View(tmp); + std::get<102>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<104, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<103, ContainerOverSubrelations>; auto tmp = ((new_term.main_sel_op_cmov + new_term.main_sel_op_jumpi) * (((new_term.main_id * new_term.main_inv) - FF(1)) + new_term.main_id_zero)); tmp *= scaling_factor; - std::get<104>(evals) += typename Accumulator::View(tmp); + std::get<103>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<105, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<104, ContainerOverSubrelations>; auto tmp = (((new_term.main_sel_op_cmov + new_term.main_sel_op_jumpi) * new_term.main_id_zero) * (-new_term.main_inv + FF(1))); tmp *= scaling_factor; - std::get<105>(evals) += typename Accumulator::View(tmp); + std::get<104>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<106, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<105, ContainerOverSubrelations>; auto tmp = (new_term.main_sel_mov_ia_to_ic - (new_term.main_sel_op_mov + (new_term.main_sel_op_cmov * (-new_term.main_id_zero + FF(1))))); tmp *= scaling_factor; - std::get<106>(evals) += typename Accumulator::View(tmp); + std::get<105>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<107, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<106, ContainerOverSubrelations>; auto tmp = (new_term.main_sel_mov_ib_to_ic - (new_term.main_sel_op_cmov * new_term.main_id_zero)); tmp *= scaling_factor; - std::get<107>(evals) += typename Accumulator::View(tmp); + std::get<106>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<108, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<107, ContainerOverSubrelations>; auto tmp = (new_term.main_sel_mov_ia_to_ic * (new_term.main_ia - new_term.main_ic)); tmp *= scaling_factor; - std::get<108>(evals) += typename Accumulator::View(tmp); + std::get<107>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<109, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<108, ContainerOverSubrelations>; auto tmp = (new_term.main_sel_mov_ib_to_ic * (new_term.main_ib - new_term.main_ic)); tmp *= scaling_factor; - std::get<109>(evals) += typename Accumulator::View(tmp); + std::get<108>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<110, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<109, ContainerOverSubrelations>; auto tmp = ((new_term.main_sel_op_mov + new_term.main_sel_op_cmov) * (new_term.main_r_in_tag - new_term.main_w_in_tag)); tmp *= scaling_factor; - std::get<110>(evals) += typename Accumulator::View(tmp); + std::get<109>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<111, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<110, ContainerOverSubrelations>; auto tmp = (new_term.main_sel_alu - ((((((((((((new_term.main_sel_op_add + new_term.main_sel_op_sub) + new_term.main_sel_op_mul) + new_term.main_sel_op_div) + @@ -993,10 +944,10 @@ template class mainImpl { (-new_term.main_tag_err + FF(1))) * (-new_term.main_op_err + FF(1)))); tmp *= scaling_factor; - std::get<111>(evals) += typename Accumulator::View(tmp); + std::get<110>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<112, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<111, ContainerOverSubrelations>; auto tmp = ((((((((((new_term.main_sel_op_add + new_term.main_sel_op_sub) + new_term.main_sel_op_mul) + new_term.main_sel_op_div) + new_term.main_sel_op_not) + @@ -1007,229 +958,229 @@ template class mainImpl { new_term.main_sel_op_shl) * (new_term.main_alu_in_tag - new_term.main_r_in_tag)); tmp *= scaling_factor; + std::get<111>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<112, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_op_cast * (new_term.main_alu_in_tag - new_term.main_w_in_tag)); + tmp *= scaling_factor; std::get<112>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<113, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_cast * (new_term.main_alu_in_tag - new_term.main_w_in_tag)); + auto tmp = (new_term.main_sel_op_l2gasleft * (new_term.main_ia - new_term.main_l2_gas_remaining_shift)); tmp *= scaling_factor; std::get<113>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<114, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_l2gasleft * (new_term.main_ia - new_term.main_l2_gas_remaining_shift)); + auto tmp = (new_term.main_sel_op_dagasleft * (new_term.main_ia - new_term.main_da_gas_remaining_shift)); tmp *= scaling_factor; std::get<114>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<115, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_dagasleft * (new_term.main_ia - new_term.main_da_gas_remaining_shift)); + auto tmp = (new_term.main_sel_op_address * (new_term.kernel_kernel_in_offset - FF(1))); tmp *= scaling_factor; std::get<115>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<116, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_address * (new_term.kernel_kernel_in_offset - FF(1))); + auto tmp = (new_term.main_sel_op_storage_address * (new_term.kernel_kernel_in_offset - FF(1))); tmp *= scaling_factor; std::get<116>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<117, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_storage_address * (new_term.kernel_kernel_in_offset - FF(1))); + auto tmp = (new_term.main_sel_op_sender * new_term.kernel_kernel_in_offset); tmp *= scaling_factor; std::get<117>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<118, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_sender * new_term.kernel_kernel_in_offset); + auto tmp = (new_term.main_sel_op_function_selector * (new_term.kernel_kernel_in_offset - FF(2))); tmp *= scaling_factor; std::get<118>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<119, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_function_selector * (new_term.kernel_kernel_in_offset - FF(2))); + auto tmp = (new_term.main_sel_op_transaction_fee * (new_term.kernel_kernel_in_offset - FF(41))); tmp *= scaling_factor; std::get<119>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<120, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_transaction_fee * (new_term.kernel_kernel_in_offset - FF(41))); + auto tmp = (new_term.main_sel_op_chain_id * (new_term.kernel_kernel_in_offset - FF(29))); tmp *= scaling_factor; std::get<120>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<121, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_chain_id * (new_term.kernel_kernel_in_offset - FF(29))); + auto tmp = (new_term.main_sel_op_version * (new_term.kernel_kernel_in_offset - FF(30))); tmp *= scaling_factor; std::get<121>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<122, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_version * (new_term.kernel_kernel_in_offset - FF(30))); + auto tmp = (new_term.main_sel_op_block_number * (new_term.kernel_kernel_in_offset - FF(31))); tmp *= scaling_factor; std::get<122>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<123, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_block_number * (new_term.kernel_kernel_in_offset - FF(31))); + auto tmp = (new_term.main_sel_op_timestamp * (new_term.kernel_kernel_in_offset - FF(33))); tmp *= scaling_factor; std::get<123>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<124, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_timestamp * (new_term.kernel_kernel_in_offset - FF(33))); + auto tmp = (new_term.main_sel_op_coinbase * (new_term.kernel_kernel_in_offset - FF(34))); tmp *= scaling_factor; std::get<124>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<125, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_coinbase * (new_term.kernel_kernel_in_offset - FF(34))); + auto tmp = (new_term.main_sel_op_fee_per_da_gas * (new_term.kernel_kernel_in_offset - FF(36))); tmp *= scaling_factor; std::get<125>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<126, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_fee_per_da_gas * (new_term.kernel_kernel_in_offset - FF(36))); + auto tmp = (new_term.main_sel_op_fee_per_l2_gas * (new_term.kernel_kernel_in_offset - FF(37))); tmp *= scaling_factor; std::get<126>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<127, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_fee_per_l2_gas * (new_term.kernel_kernel_in_offset - FF(37))); + auto tmp = (new_term.main_sel_op_note_hash_exists * + (new_term.kernel_kernel_out_offset - (new_term.kernel_note_hash_exist_write_offset + FF(0)))); tmp *= scaling_factor; std::get<127>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<128, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_note_hash_exists * - (new_term.kernel_kernel_out_offset - (new_term.kernel_note_hash_exist_write_offset + FF(0)))); + auto tmp = (new_term.main_sel_first * new_term.kernel_note_hash_exist_write_offset); tmp *= scaling_factor; std::get<128>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<129, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_note_hash_exist_write_offset); + auto tmp = (new_term.main_sel_op_emit_note_hash * + (new_term.kernel_kernel_out_offset - (new_term.kernel_emit_note_hash_write_offset + FF(128)))); tmp *= scaling_factor; std::get<129>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<130, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_emit_note_hash * - (new_term.kernel_kernel_out_offset - (new_term.kernel_emit_note_hash_write_offset + FF(128)))); + auto tmp = (new_term.main_sel_first * new_term.kernel_emit_note_hash_write_offset); tmp *= scaling_factor; std::get<130>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<131, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_emit_note_hash_write_offset); - tmp *= scaling_factor; - std::get<131>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<132, ContainerOverSubrelations>; auto tmp = (new_term.main_sel_op_nullifier_exists * (new_term.kernel_kernel_out_offset - ((new_term.main_ib * (new_term.kernel_nullifier_exists_write_offset + FF(16))) + ((-new_term.main_ib + FF(1)) * (new_term.kernel_nullifier_non_exists_write_offset + FF(32)))))); tmp *= scaling_factor; + std::get<131>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<132, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_first * new_term.kernel_nullifier_exists_write_offset); + tmp *= scaling_factor; std::get<132>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<133, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_nullifier_exists_write_offset); + auto tmp = (new_term.main_sel_first * new_term.kernel_nullifier_non_exists_write_offset); tmp *= scaling_factor; std::get<133>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<134, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_nullifier_non_exists_write_offset); + auto tmp = (new_term.main_sel_op_emit_nullifier * + (new_term.kernel_kernel_out_offset - (new_term.kernel_emit_nullifier_write_offset + FF(144)))); tmp *= scaling_factor; std::get<134>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<135, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_emit_nullifier * - (new_term.kernel_kernel_out_offset - (new_term.kernel_emit_nullifier_write_offset + FF(144)))); + auto tmp = (new_term.main_sel_first * new_term.kernel_emit_nullifier_write_offset); tmp *= scaling_factor; std::get<135>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<136, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_emit_nullifier_write_offset); + auto tmp = + (new_term.main_sel_op_l1_to_l2_msg_exists * + (new_term.kernel_kernel_out_offset - (new_term.kernel_l1_to_l2_msg_exists_write_offset + FF(48)))); tmp *= scaling_factor; std::get<136>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<137, ContainerOverSubrelations>; - auto tmp = - (new_term.main_sel_op_l1_to_l2_msg_exists * - (new_term.kernel_kernel_out_offset - (new_term.kernel_l1_to_l2_msg_exists_write_offset + FF(48)))); + auto tmp = (new_term.main_sel_first * new_term.kernel_l1_to_l2_msg_exists_write_offset); tmp *= scaling_factor; std::get<137>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<138, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_l1_to_l2_msg_exists_write_offset); + auto tmp = + (new_term.main_sel_op_emit_unencrypted_log * + (new_term.kernel_kernel_out_offset - (new_term.kernel_emit_unencrypted_log_write_offset + FF(162)))); tmp *= scaling_factor; std::get<138>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<139, ContainerOverSubrelations>; - auto tmp = - (new_term.main_sel_op_emit_unencrypted_log * - (new_term.kernel_kernel_out_offset - (new_term.kernel_emit_unencrypted_log_write_offset + FF(162)))); + auto tmp = (new_term.main_sel_first * new_term.kernel_emit_unencrypted_log_write_offset); tmp *= scaling_factor; std::get<139>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<140, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_emit_unencrypted_log_write_offset); + auto tmp = + (new_term.main_sel_op_emit_l2_to_l1_msg * + (new_term.kernel_kernel_out_offset - (new_term.kernel_emit_l2_to_l1_msg_write_offset + FF(160)))); tmp *= scaling_factor; std::get<140>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<141, ContainerOverSubrelations>; - auto tmp = - (new_term.main_sel_op_emit_l2_to_l1_msg * - (new_term.kernel_kernel_out_offset - (new_term.kernel_emit_l2_to_l1_msg_write_offset + FF(160)))); + auto tmp = (new_term.main_sel_first * new_term.kernel_emit_l2_to_l1_msg_write_offset); tmp *= scaling_factor; std::get<141>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<142, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_emit_l2_to_l1_msg_write_offset); + auto tmp = (new_term.main_sel_op_sload * + (new_term.kernel_kernel_out_offset - (new_term.kernel_sload_write_offset + FF(96)))); tmp *= scaling_factor; std::get<142>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<143, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_sload * - (new_term.kernel_kernel_out_offset - (new_term.kernel_sload_write_offset + FF(96)))); + auto tmp = (new_term.main_sel_first * new_term.kernel_sload_write_offset); tmp *= scaling_factor; std::get<143>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<144, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_sload_write_offset); + auto tmp = (new_term.main_sel_op_sstore * + (new_term.kernel_kernel_out_offset - (new_term.kernel_sstore_write_offset + FF(64)))); tmp *= scaling_factor; std::get<144>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<145, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_sstore * - (new_term.kernel_kernel_out_offset - (new_term.kernel_sstore_write_offset + FF(64)))); + auto tmp = (new_term.main_sel_first * new_term.kernel_sstore_write_offset); tmp *= scaling_factor; std::get<145>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<146, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.kernel_sstore_write_offset); - tmp *= scaling_factor; - std::get<146>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<147, ContainerOverSubrelations>; auto tmp = (((((((new_term.main_sel_op_note_hash_exists + new_term.main_sel_op_emit_note_hash) + new_term.main_sel_op_nullifier_exists) + new_term.main_sel_op_emit_nullifier) + @@ -1238,28 +1189,28 @@ template class mainImpl { new_term.main_sel_op_emit_l2_to_l1_msg) * (new_term.kernel_side_effect_counter_shift - (new_term.kernel_side_effect_counter + FF(1)))); tmp *= scaling_factor; - std::get<147>(evals) += typename Accumulator::View(tmp); + std::get<146>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<148, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<147, ContainerOverSubrelations>; auto tmp = (new_term.main_sel_slice_gadget - ((new_term.main_sel_op_calldata_copy + new_term.main_sel_op_external_return) * (-new_term.main_tag_err + FF(1)))); tmp *= scaling_factor; - std::get<148>(evals) += typename Accumulator::View(tmp); + std::get<147>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<149, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<148, ContainerOverSubrelations>; auto tmp = (new_term.main_bin_op_id - (new_term.main_sel_op_or + (new_term.main_sel_op_xor * FF(2)))); tmp *= scaling_factor; - std::get<149>(evals) += typename Accumulator::View(tmp); + std::get<148>(evals) += typename Accumulator::View(tmp); } { - using Accumulator = typename std::tuple_element_t<150, ContainerOverSubrelations>; + using Accumulator = typename std::tuple_element_t<149, ContainerOverSubrelations>; auto tmp = (new_term.main_sel_bin - ((new_term.main_sel_op_and + new_term.main_sel_op_or) + new_term.main_sel_op_xor)); tmp *= scaling_factor; - std::get<150>(evals) += typename Accumulator::View(tmp); + std::get<149>(evals) += typename Accumulator::View(tmp); } } }; @@ -1305,73 +1256,73 @@ template class main : public Relation> { return "RETURN_POINTER_INCREMENT"; case 94: return "RETURN_POINTER_DECREMENT"; - case 100: + case 99: return "PC_INCREMENT"; - case 101: + case 100: return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - case 102: + case 101: return "SPACE_ID_INTERNAL"; - case 103: + case 102: return "SPACE_ID_STANDARD_OPCODES"; - case 104: + case 103: return "CMOV_CONDITION_RES_1"; - case 105: + case 104: return "CMOV_CONDITION_RES_2"; - case 108: + case 107: return "MOV_SAME_VALUE_A"; - case 109: + case 108: return "MOV_SAME_VALUE_B"; - case 110: + case 109: return "MOV_MAIN_SAME_TAG"; - case 114: + case 113: return "L2GASLEFT"; - case 115: + case 114: return "DAGASLEFT"; - case 116: + case 115: return "ADDRESS_KERNEL"; - case 117: + case 116: return "STORAGE_ADDRESS_KERNEL"; - case 118: + case 117: return "SENDER_KERNEL"; - case 119: + case 118: return "FUNCTION_SELECTOR_KERNEL"; - case 120: + case 119: return "FEE_TRANSACTION_FEE_KERNEL"; - case 121: + case 120: return "CHAIN_ID_KERNEL"; - case 122: + case 121: return "VERSION_KERNEL"; - case 123: + case 122: return "BLOCK_NUMBER_KERNEL"; - case 124: + case 123: return "TIMESTAMP_KERNEL"; - case 125: + case 124: return "COINBASE_KERNEL"; - case 126: + case 125: return "FEE_DA_GAS_KERNEL"; - case 127: + case 126: return "FEE_L2_GAS_KERNEL"; - case 128: + case 127: return "NOTE_HASH_KERNEL_OUTPUT"; - case 130: + case 129: return "EMIT_NOTE_HASH_KERNEL_OUTPUT"; - case 132: + case 131: return "NULLIFIER_EXISTS_KERNEL_OUTPUT"; - case 135: + case 134: return "EMIT_NULLIFIER_KERNEL_OUTPUT"; - case 137: + case 136: return "L1_TO_L2_MSG_EXISTS_KERNEL_OUTPUT"; - case 139: + case 138: return "EMIT_UNENCRYPTED_LOG_KERNEL_OUTPUT"; - case 141: + case 140: return "EMIT_L2_TO_L1_MSGS_KERNEL_OUTPUT"; - case 143: + case 142: return "SLOAD_KERNEL_OUTPUT"; - case 145: + case 144: return "SSTORE_KERNEL_OUTPUT"; - case 149: + case 148: return "BIN_SEL_1"; - case 150: + case 149: return "BIN_SEL_2"; } return std::to_string(index); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/gas_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/gas_trace.cpp index 55c04d355c9..fe0b1040c83 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/gas_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/gas_trace.cpp @@ -38,7 +38,7 @@ uint32_t AvmGasTraceBuilder::get_da_gas_left() return gas_trace.back().remaining_da_gas; } -void AvmGasTraceBuilder::constrain_gas_lookup(uint32_t clk, OpCode opcode) +void AvmGasTraceBuilder::constrain_gas(uint32_t clk, OpCode opcode, [[maybe_unused]] uint32_t dyn_gas_multiplier) { // TODO: increase lookup counter for the opcode we are looking up into gas_opcode_lookup_counter[opcode]++; @@ -72,7 +72,7 @@ void AvmGasTraceBuilder::constrain_gas_for_external_call(uint32_t clk, const OpCode opcode = OpCode::CALL; // TODO: increase lookup counter for the opcode we are looking up into - // gas_opcode_lookup_counter[opcode]++; + gas_opcode_lookup_counter[opcode]++; // Get the gas prices for this opcode const auto& GAS_COST_TABLE = FixedGasTable::get(); @@ -87,10 +87,8 @@ void AvmGasTraceBuilder::constrain_gas_for_external_call(uint32_t clk, GasTraceEntry entry = { .clk = clk, .opcode = OpCode::CALL, - .l2_gas_cost = 0, // We need 0 in this case because we do not activate the gas_cost_active selector to satisfy - // #[L2_GAS_INACTIVE]. - .da_gas_cost = 0, // We need 0 in this case because we do not activate the gas_cost_active selector to satisfy - // #[DA_GAS_INACTIVE]. + .l2_gas_cost = opcode_l2_gas_cost, + .da_gas_cost = opcode_da_gas_cost, .remaining_l2_gas = remaining_l2_gas, .remaining_da_gas = remaining_da_gas, }; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/gas_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/gas_trace.hpp index 8653b93b18d..88033a75416 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/gas_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/gas_trace.hpp @@ -27,7 +27,7 @@ class AvmGasTraceBuilder { void reset(); std::vector finalize(); - void constrain_gas_lookup(uint32_t clk, OpCode opcode); + void constrain_gas(uint32_t clk, OpCode opcode, uint32_t dyn_gas_multiplier = 0); void constrain_gas_for_external_call(uint32_t clk, uint32_t nested_l2_gas_cost, uint32_t nested_da_gas_cost); void set_initial_gas(uint32_t l2_gas, uint32_t da_gas); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.cpp index 13ab95d3b9c..5b2a496f33d 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.cpp @@ -85,7 +85,6 @@ void log_avm_trace([[maybe_unused]] std::vector const& trace, info("diff_lo: ", trace.at(i).mem_diff_lo); info("=======GAS ACCOUNTING================================================================"); - info("opcode active: ", trace.at(i).main_sel_mem_op_activate_gas); info("l2_gas_remaining: ", trace.at(i).main_l2_gas_remaining); info("da_gas_remaining: ", trace.at(i).main_da_gas_remaining); info("l2_gas_op_cost: ", trace.at(i).main_l2_gas_op_cost); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/mem_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/mem_trace.hpp index 10124892b7c..0bdd8cc9ed4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/mem_trace.hpp @@ -108,6 +108,9 @@ class AvmMemTraceBuilder { uint32_t direct_dst_offset); std::vector read_return_opcode(uint32_t clk, uint8_t space_id, uint32_t direct_ret_offset, uint32_t ret_size); + // DO NOT USE FOR REAL OPERATIONS + FF unconstrained_read(uint8_t space_id, uint32_t addr) { return memory[space_id][addr].val; } + private: std::vector mem_trace; // Entries will be sorted by m_clk, m_sub_clk after finalize(). diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp index 4d83635b8a8..ab3b4d2d550 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp @@ -13,6 +13,7 @@ #include #include +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/crypto/pedersen_commitment/pedersen.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" @@ -289,167 +290,46 @@ AvmTraceBuilder::MemOp AvmTraceBuilder::constrained_write_to_memory(uint8_t spac .val = value }; } -// TODO(ilyas: #6383): Temporary way to bulk read slices -template -uint32_t AvmTraceBuilder::read_slice_to_memory(uint8_t space_id, - uint32_t clk, - AddressWithMode addr, - AvmMemoryTag r_tag, - AvmMemoryTag w_tag, - FF internal_return_ptr, - size_t slice_len, - std::vector& slice) +FF AvmTraceBuilder::unconstrained_read_from_memory(AddressWithMode addr) { - // If the mem_op is indirect, it goes into register A - bool is_indirect = addr.mode == AddressingMode::INDIRECT; - auto src_offset = addr.offset; - // We have 4 registers that we are able to use to read from memory within a single main trace row - auto register_order = std::array{ IntermRegister::IA, IntermRegister::IB, IntermRegister::IC, IntermRegister::ID }; - // If the slice size isnt a multiple of 4, we still need an extra row to write the remainder - uint32_t const num_main_rows = static_cast(slice_len) / 4 + static_cast(slice_len % 4 != 0); - for (uint32_t i = 0; i < num_main_rows; i++) { - Row main_row{ - .main_clk = clk + i, - .main_internal_return_ptr = FF(internal_return_ptr), - .main_pc = FF(pc), - .main_r_in_tag = FF(static_cast(r_tag)), - .main_w_in_tag = FF(static_cast(w_tag)), - }; - // Write 4 values to memory in each_row - for (uint32_t j = 0; j < 4; j++) { - auto offset = i * 4 + j; - // If we exceed the slice size, we break - if (offset >= slice_len) { - break; - } - MemOp mem_read; - if (is_indirect) { - // If the first address is indirect we read it into register A, this can only happen once per slice read - mem_read = constrained_read_from_memory(space_id, clk + i, addr, r_tag, w_tag, IntermRegister::IA); - // Set this to false for the rest of the reads - is_indirect = false; - src_offset = mem_read.direct_address; - } else { - auto mem_load = mem_trace_builder.read_and_load_from_memory( - space_id, clk + i, register_order[j], src_offset + offset, r_tag, w_tag); - mem_read = MemOp{ - .is_indirect = false, - .indirect_address = 0, - .direct_address = src_offset + offset, - .tag = r_tag, - .tag_match = mem_load.tag_match, - .val = MEM(mem_load.val), - }; - } - slice.emplace_back(MEM(mem_read.val)); - // This looks a bit gross, but it is fine for now. - if (j == 0) { - main_row.main_ia = slice.at(offset); - main_row.main_ind_addr_a = FF(mem_read.indirect_address); - main_row.main_sel_resolve_ind_addr_a = FF(static_cast(mem_read.is_indirect)); - main_row.main_mem_addr_a = FF(mem_read.direct_address); - main_row.main_sel_mem_op_a = FF(1); - main_row.main_tag_err = FF(static_cast(!mem_read.tag_match)); - } else if (j == 1) { - main_row.main_ib = slice.at(offset); - main_row.main_mem_addr_b = FF(mem_read.direct_address); - main_row.main_sel_mem_op_b = FF(1); - main_row.main_tag_err = FF(static_cast(!mem_read.tag_match)); - } else if (j == 2) { - main_row.main_ic = slice.at(offset); - main_row.main_mem_addr_c = FF(mem_read.direct_address); - main_row.main_sel_mem_op_c = FF(1); - main_row.main_tag_err = FF(static_cast(!mem_read.tag_match)); - } else { - main_row.main_id = slice.at(offset); - main_row.main_mem_addr_d = FF(mem_read.direct_address); - main_row.main_sel_mem_op_d = FF(1); - main_row.main_tag_err = FF(static_cast(!mem_read.tag_match)); - } - } - main_trace.emplace_back(main_row); + auto offset = addr.offset; + if (addr.mode == AddressingMode::INDIRECT) { + offset = static_cast(mem_trace_builder.unconstrained_read(call_ptr, offset)); } - return num_main_rows; + return mem_trace_builder.unconstrained_read(call_ptr, offset); } -// TODO(ilyas: #6383): Temporary way to bulk write slices -uint32_t AvmTraceBuilder::write_slice_to_memory(uint8_t space_id, - uint32_t clk, - AddressWithMode addr, - AvmMemoryTag r_tag, - AvmMemoryTag w_tag, - FF internal_return_ptr, - std::vector const& slice) +void AvmTraceBuilder::write_to_memory(AddressWithMode addr, FF val, AvmMemoryTag w_tag) { - bool is_indirect = addr.mode == AddressingMode::INDIRECT; - auto dst_offset = addr.offset; - // We have 4 registers that we are able to use to write to memory within a single main trace row - auto register_order = std::array{ IntermRegister::IA, IntermRegister::IB, IntermRegister::IC, IntermRegister::ID }; - // If the slice size isnt a multiple of 4, we still need an extra row to write the remainder - uint32_t const num_main_rows = - static_cast(slice.size()) / 4 + static_cast(slice.size() % 4 != 0); - for (uint32_t i = 0; i < num_main_rows; i++) { - Row main_row{ - .main_clk = clk + i, - .main_internal_return_ptr = FF(internal_return_ptr), - .main_pc = FF(pc), - .main_r_in_tag = FF(static_cast(r_tag)), - .main_w_in_tag = FF(static_cast(w_tag)), - }; - // Write 4 values to memory in each_row - for (uint32_t j = 0; j < 4; j++) { - auto offset = i * 4 + j; - // If we exceed the slice size, we break - if (offset >= slice.size()) { - break; - } - MemOp mem_write; - if (is_indirect) { - mem_write = constrained_write_to_memory( - space_id, clk + i, addr, slice.at(offset), r_tag, w_tag, IntermRegister::IA); - // Ensure futures calls are direct - is_indirect = false; - dst_offset = mem_write.direct_address; - } else { - mem_trace_builder.write_into_memory( - space_id, clk + i, register_order[j], dst_offset + offset, slice.at(offset), r_tag, w_tag); - mem_write = MemOp{ - .is_indirect = false, - .indirect_address = 0, - .direct_address = dst_offset + offset, - .tag = w_tag, - .tag_match = true, - .val = slice.at(offset), - }; - } - // This looks a bit gross, but it is fine for now. - if (j == 0) { - main_row.main_ia = slice.at(offset); - main_row.main_ind_addr_a = FF(mem_write.indirect_address); - main_row.main_sel_resolve_ind_addr_a = FF(static_cast(mem_write.is_indirect)); - main_row.main_mem_addr_a = FF(mem_write.direct_address); - main_row.main_sel_mem_op_a = FF(1); - main_row.main_rwa = FF(1); - } else if (j == 1) { - main_row.main_ib = slice.at(offset); - main_row.main_mem_addr_b = FF(mem_write.direct_address); - main_row.main_sel_mem_op_b = FF(1); - main_row.main_rwb = FF(1); - } else if (j == 2) { - main_row.main_ic = slice.at(offset); - main_row.main_mem_addr_c = FF(mem_write.direct_address); - main_row.main_sel_mem_op_c = FF(1); - main_row.main_rwc = FF(1); - } else { - main_row.main_id = slice.at(offset); - main_row.main_mem_addr_d = FF(mem_write.direct_address); - main_row.main_sel_mem_op_d = FF(1); - main_row.main_rwd = FF(1); - } - } - main_trace.emplace_back(main_row); + // op_set_internal increments the pc, so we need to store the current pc and then jump back to it + // to legaly reset the pc. + auto current_pc = pc; + op_set_internal(static_cast(addr.mode), val, addr.offset, w_tag); + op_jump(current_pc); +} + +template +void AvmTraceBuilder::read_slice_from_memory(AddressWithMode addr, size_t slice_len, std::vector& slice) +{ + uint32_t base_addr = addr.offset; + if (addr.mode == AddressingMode::INDIRECT) { + base_addr = static_cast(mem_trace_builder.unconstrained_read(call_ptr, base_addr)); + } + + for (uint32_t i = 0; i < slice_len; i++) { + slice.push_back(static_cast(mem_trace_builder.unconstrained_read(call_ptr, base_addr + i))); + } +} + +template +void AvmTraceBuilder::write_slice_to_memory(AddressWithMode addr, AvmMemoryTag w_tag, const T& slice) +{ + auto base_addr = addr.mode == AddressingMode::INDIRECT + ? static_cast(mem_trace_builder.unconstrained_read(call_ptr, addr.offset)) + : addr.offset; + for (uint32_t i = 0; i < slice.size(); i++) { + write_to_memory(base_addr + i, slice[i], w_tag); } - return num_main_rows; } // Finalise Lookup Counts @@ -530,7 +410,7 @@ void AvmTraceBuilder::op_add( auto write_c = constrained_write_to_memory(call_ptr, clk, resolved_c, c, in_tag, in_tag, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::ADD); + gas_trace_builder.constrain_gas(clk, OpCode::ADD); main_trace.push_back(Row{ .main_clk = clk, @@ -597,7 +477,7 @@ void AvmTraceBuilder::op_sub( auto write_c = constrained_write_to_memory(call_ptr, clk, resolved_c, c, in_tag, in_tag, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::SUB); + gas_trace_builder.constrain_gas(clk, OpCode::SUB); main_trace.push_back(Row{ .main_clk = clk, @@ -664,7 +544,7 @@ void AvmTraceBuilder::op_mul( auto write_c = constrained_write_to_memory(call_ptr, clk, resolved_c, c, in_tag, in_tag, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::MUL); + gas_trace_builder.constrain_gas(clk, OpCode::MUL); main_trace.push_back(Row{ .main_clk = clk, @@ -742,7 +622,7 @@ void AvmTraceBuilder::op_div( auto write_dst = constrained_write_to_memory(call_ptr, clk, resolved_dst, c, in_tag, in_tag, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::DIV); + gas_trace_builder.constrain_gas(clk, OpCode::DIV); main_trace.push_back(Row{ .main_clk = clk, @@ -822,7 +702,7 @@ void AvmTraceBuilder::op_fdiv(uint8_t indirect, uint32_t a_offset, uint32_t b_of call_ptr, clk, resolved_c, c, AvmMemoryTag::FF, AvmMemoryTag::FF, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::FDIV); + gas_trace_builder.constrain_gas(clk, OpCode::FDIV); main_trace.push_back(Row{ .main_clk = clk, @@ -892,7 +772,7 @@ void AvmTraceBuilder::op_eq( constrained_write_to_memory(call_ptr, clk, resolved_c, c, in_tag, AvmMemoryTag::U8, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::EQ); + gas_trace_builder.constrain_gas(clk, OpCode::EQ); main_trace.push_back(Row{ .main_clk = clk, @@ -944,7 +824,7 @@ void AvmTraceBuilder::op_lt( constrained_write_to_memory(call_ptr, clk, resolved_c, c, in_tag, AvmMemoryTag::U8, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::LT); + gas_trace_builder.constrain_gas(clk, OpCode::LT); main_trace.push_back(Row{ .main_clk = clk, @@ -997,7 +877,7 @@ void AvmTraceBuilder::op_lte( constrained_write_to_memory(call_ptr, clk, resolved_c, c, in_tag, AvmMemoryTag::U8, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::LTE); + gas_trace_builder.constrain_gas(clk, OpCode::LTE); main_trace.push_back(Row{ .main_clk = clk, @@ -1053,7 +933,7 @@ void AvmTraceBuilder::op_and( auto write_c = constrained_write_to_memory(call_ptr, clk, resolved_c, c, in_tag, in_tag, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::AND); + gas_trace_builder.constrain_gas(clk, OpCode::AND); main_trace.push_back(Row{ .main_clk = clk, @@ -1105,7 +985,7 @@ void AvmTraceBuilder::op_or( auto write_c = constrained_write_to_memory(call_ptr, clk, resolved_c, c, in_tag, in_tag, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::OR); + gas_trace_builder.constrain_gas(clk, OpCode::OR); main_trace.push_back(Row{ .main_clk = clk, @@ -1158,7 +1038,7 @@ void AvmTraceBuilder::op_xor( auto write_c = constrained_write_to_memory(call_ptr, clk, resolved_c, c, in_tag, in_tag, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::XOR); + gas_trace_builder.constrain_gas(clk, OpCode::XOR); main_trace.push_back(Row{ .main_clk = clk, @@ -1221,7 +1101,7 @@ void AvmTraceBuilder::op_not(uint8_t indirect, uint32_t a_offset, uint32_t dst_o auto write_c = constrained_write_to_memory(call_ptr, clk, resolved_c, c, in_tag, in_tag, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::NOT); + gas_trace_builder.constrain_gas(clk, OpCode::NOT); main_trace.push_back(Row{ .main_clk = clk, @@ -1267,7 +1147,7 @@ void AvmTraceBuilder::op_shl( // Write into memory value c from intermediate register ic. auto write_c = constrained_write_to_memory(call_ptr, clk, resolved_c, c, in_tag, in_tag, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::SHL); + gas_trace_builder.constrain_gas(clk, OpCode::SHL); main_trace.push_back(Row{ .main_clk = clk, @@ -1319,7 +1199,7 @@ void AvmTraceBuilder::op_shr( // Write into memory value c from intermediate register ic. auto write_c = constrained_write_to_memory(call_ptr, clk, resolved_c, c, in_tag, in_tag, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::SHR); + gas_trace_builder.constrain_gas(clk, OpCode::SHR); main_trace.push_back(Row{ .main_clk = clk, @@ -1400,7 +1280,7 @@ void AvmTraceBuilder::op_cast(uint8_t indirect, uint32_t a_offset, uint32_t dst_ mem_trace_builder.write_into_memory(call_ptr, clk, IntermRegister::IC, direct_dst_offset, c, memEntry.tag, dst_tag); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::CAST); + gas_trace_builder.constrain_gas(clk, OpCode::CAST); main_trace.push_back(Row{ .main_clk = clk, @@ -1478,7 +1358,7 @@ void AvmTraceBuilder::op_address(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_address = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::ADDRESS); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::ADDRESS); main_trace.push_back(row); } @@ -1490,7 +1370,7 @@ void AvmTraceBuilder::op_storage_address(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_storage_address = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::STORAGEADDRESS); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::STORAGEADDRESS); main_trace.push_back(row); } @@ -1502,7 +1382,7 @@ void AvmTraceBuilder::op_sender(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_sender = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::SENDER); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::SENDER); main_trace.push_back(row); } @@ -1515,7 +1395,7 @@ void AvmTraceBuilder::op_function_selector(uint8_t indirect, uint32_t dst_offset row.main_sel_op_function_selector = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::FUNCTIONSELECTOR); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::FUNCTIONSELECTOR); main_trace.push_back(row); } @@ -1527,7 +1407,7 @@ void AvmTraceBuilder::op_transaction_fee(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_transaction_fee = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::TRANSACTIONFEE); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::TRANSACTIONFEE); main_trace.push_back(row); } @@ -1543,7 +1423,7 @@ void AvmTraceBuilder::op_chain_id(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_chain_id = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::CHAINID); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::CHAINID); main_trace.push_back(row); } @@ -1555,7 +1435,7 @@ void AvmTraceBuilder::op_version(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_version = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::VERSION); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::VERSION); main_trace.push_back(row); } @@ -1567,7 +1447,7 @@ void AvmTraceBuilder::op_block_number(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_block_number = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::BLOCKNUMBER); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::BLOCKNUMBER); main_trace.push_back(row); } @@ -1579,7 +1459,7 @@ void AvmTraceBuilder::op_timestamp(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_timestamp = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::TIMESTAMP); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::TIMESTAMP); main_trace.push_back(row); } @@ -1591,7 +1471,7 @@ void AvmTraceBuilder::op_coinbase(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_coinbase = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::COINBASE); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::COINBASE); main_trace.push_back(row); } @@ -1603,7 +1483,7 @@ void AvmTraceBuilder::op_fee_per_l2_gas(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_fee_per_l2_gas = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::FEEPERL2GAS); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::FEEPERL2GAS); main_trace.push_back(row); } @@ -1615,7 +1495,7 @@ void AvmTraceBuilder::op_fee_per_da_gas(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_fee_per_da_gas = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::FEEPERDAGAS); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::FEEPERDAGAS); main_trace.push_back(row); } @@ -1670,7 +1550,7 @@ void AvmTraceBuilder::op_calldata_copy(uint8_t indirect, uint32_t cd_offset, uin } // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::CALLDATACOPY); + gas_trace_builder.constrain_gas(clk, OpCode::CALLDATACOPY, copy_size); main_trace.push_back(Row{ .main_clk = clk, @@ -1704,7 +1584,7 @@ void AvmTraceBuilder::execute_gasleft(OpCode opcode, uint8_t indirect, uint32_t auto [resolved_dst] = unpack_indirects<1>(indirect, { dst_offset }); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, opcode); + gas_trace_builder.constrain_gas(clk, opcode); uint32_t gas_remaining = 0; @@ -1766,7 +1646,7 @@ void AvmTraceBuilder::op_jump(uint32_t jmp_dest) auto clk = static_cast(main_trace.size()) + 1; // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::JUMP); + gas_trace_builder.constrain_gas(clk, OpCode::JUMP); main_trace.push_back(Row{ .main_clk = clk, @@ -1815,7 +1695,7 @@ void AvmTraceBuilder::op_jumpi(uint8_t indirect, uint32_t jmp_dest, uint32_t con uint32_t next_pc = !id_zero ? jmp_dest : pc + 1; // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::JUMPI); + gas_trace_builder.constrain_gas(clk, OpCode::JUMPI); main_trace.push_back(Row{ .main_clk = clk, @@ -1867,7 +1747,7 @@ void AvmTraceBuilder::op_internal_call(uint32_t jmp_dest) AvmMemoryTag::U32); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::INTERNALCALL); + gas_trace_builder.constrain_gas(clk, OpCode::INTERNALCALL); main_trace.push_back(Row{ .main_clk = clk, @@ -1909,7 +1789,7 @@ void AvmTraceBuilder::op_internal_return() INTERNAL_CALL_SPACE_ID, clk, IntermRegister::IA, internal_return_ptr - 1, AvmMemoryTag::U32, AvmMemoryTag::U0); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::INTERNALRETURN); + gas_trace_builder.constrain_gas(clk, OpCode::INTERNALRETURN); main_trace.push_back(Row{ .main_clk = clk, @@ -1949,15 +1829,20 @@ void AvmTraceBuilder::op_internal_return() */ void AvmTraceBuilder::op_set(uint8_t indirect, uint128_t val, uint32_t dst_offset, AvmMemoryTag in_tag) { - auto const clk = static_cast(main_trace.size()) + 1; auto const val_ff = FF{ uint256_t::from_uint128(val) }; + op_set_internal(indirect, val_ff, dst_offset, in_tag); +} + +void AvmTraceBuilder::op_set_internal(uint8_t indirect, FF val_ff, uint32_t dst_offset, AvmMemoryTag in_tag) +{ + auto const clk = static_cast(main_trace.size()) + 1; auto [resolved_c] = unpack_indirects<1>(indirect, { dst_offset }); auto write_c = constrained_write_to_memory(call_ptr, clk, resolved_c, val_ff, AvmMemoryTag::U0, in_tag, IntermRegister::IC); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::SET); + gas_trace_builder.constrain_gas(clk, OpCode::SET); main_trace.push_back(Row{ .main_clk = clk, @@ -1968,7 +1853,6 @@ void AvmTraceBuilder::op_set(uint8_t indirect, uint128_t val, uint32_t dst_offse .main_mem_addr_c = FF(write_c.direct_address), .main_pc = pc++, .main_rwc = 1, - .main_sel_mem_op_activate_gas = 1, // TODO: remove in the long term .main_sel_mem_op_c = 1, .main_sel_resolve_ind_addr_c = FF(static_cast(write_c.is_indirect)), .main_tag_err = static_cast(!write_c.tag_match), @@ -2015,7 +1899,7 @@ void AvmTraceBuilder::op_mov(uint8_t indirect, uint32_t src_offset, uint32_t dst mem_trace_builder.write_into_memory(call_ptr, clk, IntermRegister::IC, direct_dst_offset, val, tag, tag); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::MOV); + gas_trace_builder.constrain_gas(clk, OpCode::MOV); main_trace.push_back(Row{ .main_clk = clk, @@ -2115,7 +1999,7 @@ void AvmTraceBuilder::op_cmov( FF const inv = !id_zero ? cond_mem_entry.val.invert() : 1; // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::CMOV); + gas_trace_builder.constrain_gas(clk, OpCode::CMOV); main_trace.push_back(Row{ .main_clk = clk, @@ -2367,6 +2251,7 @@ void AvmTraceBuilder::op_sload(uint8_t indirect, uint32_t slot_offset, uint32_t .main_sel_resolve_ind_addr_a = FF(static_cast(read_slot.is_indirect)), .main_tag_err = FF(static_cast(!read_slot.tag_match)), }); + gas_trace_builder.constrain_gas(clk, OpCode::SLOAD); clk++; AddressWithMode write_dst = resolved_dest; @@ -2399,7 +2284,9 @@ void AvmTraceBuilder::op_sload(uint8_t indirect, uint32_t slot_offset, uint32_t kernel_trace_builder.op_sload(clk, side_effect_counter, row.main_ib, row.main_ia); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::SLOAD); + // TODO: when/if we move this to its own gadget, and we have 1 row only, we should pass the size as + // n_multiplier here. + gas_trace_builder.constrain_gas(clk, OpCode::SLOAD); main_trace.push_back(row); @@ -2435,6 +2322,7 @@ void AvmTraceBuilder::op_sstore(uint8_t indirect, uint32_t src_offset, uint32_t .main_tag_err = FF(static_cast(!read_slot.tag_match)), .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), }); + gas_trace_builder.constrain_gas(clk, OpCode::SSTORE); clk++; AddressWithMode read_src = resolved_src; @@ -2463,7 +2351,9 @@ void AvmTraceBuilder::op_sstore(uint8_t indirect, uint32_t src_offset, uint32_t kernel_trace_builder.op_sstore(clk, side_effect_counter, row.main_ib, row.main_ia); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::SSTORE); + // TODO: when/if we move this to its own gadget, and we have 1 row only, we should pass the size as + // n_multiplier here. + gas_trace_builder.constrain_gas(clk, OpCode::SSTORE); main_trace.push_back(row); @@ -2487,7 +2377,7 @@ void AvmTraceBuilder::op_note_hash_exists(uint8_t indirect, uint32_t note_hash_o row.main_sel_op_note_hash_exists = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::NOTEHASHEXISTS); + gas_trace_builder.constrain_gas(clk, OpCode::NOTEHASHEXISTS); main_trace.push_back(row); @@ -2504,7 +2394,7 @@ void AvmTraceBuilder::op_emit_note_hash(uint8_t indirect, uint32_t note_hash_off row.main_sel_op_emit_note_hash = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::EMITNOTEHASH); + gas_trace_builder.constrain_gas(clk, OpCode::EMITNOTEHASH); main_trace.push_back(row); @@ -2523,7 +2413,7 @@ void AvmTraceBuilder::op_nullifier_exists(uint8_t indirect, uint32_t nullifier_o row.main_sel_op_nullifier_exists = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::NULLIFIEREXISTS); + gas_trace_builder.constrain_gas(clk, OpCode::NULLIFIEREXISTS); main_trace.push_back(row); @@ -2540,7 +2430,7 @@ void AvmTraceBuilder::op_emit_nullifier(uint8_t indirect, uint32_t nullifier_off row.main_sel_op_emit_nullifier = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::EMITNULLIFIER); + gas_trace_builder.constrain_gas(clk, OpCode::EMITNULLIFIER); main_trace.push_back(row); @@ -2558,7 +2448,7 @@ void AvmTraceBuilder::op_l1_to_l2_msg_exists(uint8_t indirect, uint32_t log_offs row.main_sel_op_l1_to_l2_msg_exists = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::L1TOL2MSGEXISTS); + gas_trace_builder.constrain_gas(clk, OpCode::L1TOL2MSGEXISTS); main_trace.push_back(row); @@ -2576,7 +2466,7 @@ void AvmTraceBuilder::op_get_contract_instance(uint8_t indirect, uint32_t addres bool tag_match = read_address.tag_match; // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::GETCONTRACTINSTANCE); + gas_trace_builder.constrain_gas(clk, OpCode::GETCONTRACTINSTANCE); main_trace.push_back(Row{ .main_clk = clk, @@ -2587,12 +2477,11 @@ void AvmTraceBuilder::op_get_contract_instance(uint8_t indirect, uint32_t addres .main_pc = FF(pc++), .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), .main_sel_mem_op_a = FF(1), - .main_sel_mem_op_activate_gas = FF(1), // TODO: remove in the long term .main_sel_op_get_contract_instance = FF(1), .main_sel_resolve_ind_addr_a = FF(static_cast(read_address.is_indirect)), .main_tag_err = FF(static_cast(!tag_match)), }); - clk++; + // Read the contract instance ContractInstanceHint contract_instance = execution_hints.contract_instance_hints.at(read_address.val); @@ -2603,13 +2492,7 @@ void AvmTraceBuilder::op_get_contract_instance(uint8_t indirect, uint32_t addres contract_instance.contract_class_id, contract_instance.initialisation_hash, contract_instance.public_key_hash }; - write_slice_to_memory(call_ptr, - clk, - resolved_dst_offset, - AvmMemoryTag::U0, - AvmMemoryTag::FF, - internal_return_ptr, - contract_instance_vec); + write_slice_to_memory(resolved_dst_offset, AvmMemoryTag::FF, contract_instance_vec); debug("contract_instance cnt: ", side_effect_counter); side_effect_counter++; @@ -2626,13 +2509,19 @@ void AvmTraceBuilder::op_emit_unencrypted_log(uint8_t indirect, auto const clk = static_cast(main_trace.size()) + 1; // FIXME: read (and constrain) log_size_offset + auto [resolved_log_offset, resolved_log_size_offset] = + unpack_indirects<2>(indirect, { log_offset, log_size_offset }); + auto log_size = unconstrained_read_from_memory(resolved_log_size_offset); + // FIXME: we need to constrain the log_size_offset mem read (and tag check), not just one field! - Row row = create_kernel_output_opcode(indirect, clk, log_offset); + // FIXME: we shouldn't pass resolved_log_offset.offset; we should modify create_kernel_output_opcode to take an + // addresswithmode. + Row row = create_kernel_output_opcode(indirect, clk, resolved_log_offset.offset); kernel_trace_builder.op_emit_unencrypted_log(clk, side_effect_counter, row.main_ia); row.main_sel_op_emit_unencrypted_log = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::EMITUNENCRYPTEDLOG); + gas_trace_builder.constrain_gas(clk, OpCode::EMITUNENCRYPTEDLOG, static_cast(log_size)); main_trace.push_back(row); @@ -2644,14 +2533,14 @@ void AvmTraceBuilder::op_emit_l2_to_l1_msg(uint8_t indirect, uint32_t recipient_ { auto const clk = static_cast(main_trace.size()) + 1; - // Note: unorthadox order - as seen in L2ToL1Message struct in TS + // Note: unorthodox order - as seen in L2ToL1Message struct in TS Row row = create_kernel_output_opcode_with_metadata( indirect, clk, content_offset, AvmMemoryTag::FF, recipient_offset, AvmMemoryTag::FF); kernel_trace_builder.op_emit_l2_to_l1_msg(clk, side_effect_counter, row.main_ia, row.main_ib); row.main_sel_op_emit_l2_to_l1_msg = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::SENDL2TOL1MSG); + gas_trace_builder.constrain_gas(clk, OpCode::SENDL2TOL1MSG); main_trace.push_back(row); @@ -2731,7 +2620,7 @@ void AvmTraceBuilder::op_call(uint8_t indirect, .main_mem_addr_b = FF(read_gas_l2.direct_address + 1), .main_mem_addr_c = FF(read_addr.direct_address), .main_mem_addr_d = FF(read_args.direct_address), - .main_pc = FF(pc), + .main_pc = FF(pc++), .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), .main_sel_mem_op_a = FF(1), .main_sel_mem_op_b = FF(1), @@ -2743,23 +2632,15 @@ void AvmTraceBuilder::op_call(uint8_t indirect, .main_sel_resolve_ind_addr_d = FF(static_cast(read_args.is_indirect)), .main_tag_err = FF(static_cast(!tag_match)), }); - clk++; + // The return data hint is used for now, we check it has the same length as the ret_size ASSERT(hint.return_data.size() == ret_size); // Write the return data to memory - uint32_t num_rows = write_slice_to_memory( - call_ptr, clk, resolved_ret_offset, AvmMemoryTag::U0, AvmMemoryTag::FF, internal_return_ptr, hint.return_data); - clk += num_rows; + write_slice_to_memory(resolved_ret_offset, AvmMemoryTag::FF, hint.return_data); // Write the success flag to memory - write_slice_to_memory(call_ptr, - clk, - resolved_success_offset, - AvmMemoryTag::U0, - AvmMemoryTag::U8, - internal_return_ptr, - { hint.success }); + write_slice_to_memory(resolved_success_offset, AvmMemoryTag::U8, std::vector{ hint.success }); external_call_counter++; - pc++; + // Adjust the side_effect_counter to the value at the end of the external call. side_effect_counter = static_cast(hint.end_side_effect_counter); } @@ -2781,6 +2662,7 @@ void AvmTraceBuilder::op_call(uint8_t indirect, */ std::vector AvmTraceBuilder::op_return(uint8_t indirect, uint32_t ret_offset, uint32_t ret_size) { + // FIXME: this is wrong. E.g., we wouldn't be charging gas. if (ret_size == 0) { halt(); return {}; @@ -2796,7 +2678,6 @@ std::vector AvmTraceBuilder::op_return(uint8_t indirect, uint32_t ret_offset // The only memory operation performed from the main trace is a possible indirect load for resolving the // direct destination offset stored in main_mem_addr_c. // All the other memory operations are triggered by the slice gadget. - if (is_operand_indirect(indirect, 0)) { indirect_flag = true; auto ind_read = @@ -2811,7 +2692,7 @@ std::vector AvmTraceBuilder::op_return(uint8_t indirect, uint32_t ret_offset } // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::RETURN); + gas_trace_builder.constrain_gas(clk, OpCode::RETURN, ret_size); main_trace.push_back(Row{ .main_clk = clk, @@ -2862,7 +2743,7 @@ void AvmTraceBuilder::op_keccak(uint8_t indirect, unpack_indirects<3>(indirect, { output_offset, input_offset, input_size_offset }); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::KECCAK); + gas_trace_builder.constrain_gas(clk, OpCode::KECCAK); // Read the input length first auto input_length_read = constrained_read_from_memory( @@ -2888,16 +2769,7 @@ void AvmTraceBuilder::op_keccak(uint8_t indirect, std::vector input; input.reserve(uint32_t(input_length_read.val)); // Read the slice length from memory - uint32_t num_main_rows = read_slice_to_memory(call_ptr, - clk, - resolved_input_offset, - AvmMemoryTag::U8, - AvmMemoryTag::U8, - FF(internal_return_ptr), - uint32_t(input_length_read.val), - input); - - clk += num_main_rows; + read_slice_from_memory(resolved_input_offset, uint32_t(input_length_read.val), input); std::array result = keccak_trace_builder.keccak(keccak_op_clk, input, uint32_t(input_length_read.val)); // We convert the results to field elements here @@ -2906,8 +2778,7 @@ void AvmTraceBuilder::op_keccak(uint8_t indirect, ff_result.emplace_back(result[i]); } // Write the result to memory after - write_slice_to_memory( - call_ptr, clk, resolved_output_offset, AvmMemoryTag::U8, AvmMemoryTag::U8, FF(internal_return_ptr), ff_result); + write_slice_to_memory(resolved_output_offset, AvmMemoryTag::U8, ff_result); } /** @@ -2948,7 +2819,7 @@ void AvmTraceBuilder::op_poseidon2_permutation(uint8_t indirect, uint32_t input_ } // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::POSEIDON2); + gas_trace_builder.constrain_gas(clk, OpCode::POSEIDON2); // Main trace contains on operand values from the bytecode and resolved indirects main_trace.push_back(Row{ @@ -3063,7 +2934,7 @@ void AvmTraceBuilder::op_sha256(uint8_t indirect, auto [resolved_output_offset, resolved_input_offset, resolved_input_size_offset] = unpack_indirects<3>(indirect, { output_offset, input_offset, input_size_offset }); - gas_trace_builder.constrain_gas_lookup(clk, OpCode::SHA256); + gas_trace_builder.constrain_gas(clk, OpCode::SHA256); auto input_length_read = constrained_read_from_memory( call_ptr, clk, resolved_input_size_offset, AvmMemoryTag::U32, AvmMemoryTag::U0, IntermRegister::IB); @@ -3087,16 +2958,8 @@ void AvmTraceBuilder::op_sha256(uint8_t indirect, std::vector input; input.reserve(uint32_t(input_length_read.val)); - uint32_t num_main_rows = read_slice_to_memory(call_ptr, - clk, - resolved_input_offset, - AvmMemoryTag::U8, - AvmMemoryTag::U0, - FF(internal_return_ptr), - uint32_t(input_length_read.val), - input); - clk += num_main_rows; - // + read_slice_from_memory(resolved_input_offset, uint32_t(input_length_read.val), input); + std::array result = sha256_trace_builder.sha256(input, sha256_op_clk); std::vector ff_result; @@ -3104,12 +2967,11 @@ void AvmTraceBuilder::op_sha256(uint8_t indirect, ff_result.emplace_back(result[i]); } // Write the result to memory after - write_slice_to_memory( - call_ptr, clk, resolved_output_offset, AvmMemoryTag::U0, AvmMemoryTag::U8, FF(internal_return_ptr), ff_result); + write_slice_to_memory(resolved_output_offset, AvmMemoryTag::U8, ff_result); } /** - * @brief Pedersen Hash with direct or indirect memory access. + * @brief Pedersen Hash with direct or indirect memory access. * @param indirect byte encoding information about indirect/direct memory access. * @param gen_ctx_offset An index in memory pointing to where the u32 offset for the pedersen hash generators. * @param input_offset An index in memory pointing to the first FF value of the input array to be used in the next @@ -3124,13 +2986,19 @@ void AvmTraceBuilder::op_pedersen_hash(uint8_t indirect, auto clk = static_cast(main_trace.size()) + 1; auto [resolved_gen_ctx_offset, resolved_output_offset, resolved_input_offset, resolved_input_size_offset] = unpack_indirects<4>(indirect, { gen_ctx_offset, output_offset, input_offset, input_size_offset }); + auto input_read = constrained_read_from_memory( call_ptr, clk, resolved_input_offset, AvmMemoryTag::FF, AvmMemoryTag::U0, IntermRegister::IA); + // auto input_size_read = constrained_read_from_memory( + // call_ptr, clk, resolved_input_size_offset, AvmMemoryTag::U32, AvmMemoryTag::U0, IntermRegister::IB); + // auto gen_ctx_read = constrained_read_from_memory( + // call_ptr, clk, resolved_gen_ctx_offset, AvmMemoryTag::U32, AvmMemoryTag::U0, IntermRegister::IC); + auto input_size_read = unconstrained_read_from_memory(resolved_input_size_offset); + auto gen_ctx_read = unconstrained_read_from_memory(resolved_gen_ctx_offset); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::PEDERSEN); + gas_trace_builder.constrain_gas(clk, OpCode::PEDERSEN); - uint32_t pedersen_clk = clk; // We read the input and output addresses in one row as they should contain FF elements main_trace.push_back(Row{ .main_clk = clk, @@ -3145,43 +3013,11 @@ void AvmTraceBuilder::op_pedersen_hash(uint8_t indirect, .main_sel_resolve_ind_addr_a = FF(static_cast(input_read.is_indirect)), .main_tag_err = FF(static_cast(!input_read.tag_match)), }); - clk++; - // We read the input size and gen_ctx addresses in one row as they should contain U32 elements - auto input_size_read = constrained_read_from_memory( - call_ptr, clk, resolved_input_size_offset, AvmMemoryTag::U32, AvmMemoryTag::U0, IntermRegister::IA); - auto gen_ctx_read = constrained_read_from_memory( - call_ptr, clk, resolved_gen_ctx_offset, AvmMemoryTag::U32, AvmMemoryTag::U0, IntermRegister::IB); - main_trace.push_back(Row{ - .main_clk = clk, - .main_ia = input_size_read.val, - .main_ib = gen_ctx_read.val, - .main_ind_addr_a = FF(input_size_read.indirect_address), - .main_ind_addr_b = FF(gen_ctx_read.indirect_address), - .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_a = FF(input_size_read.direct_address), - .main_mem_addr_b = FF(gen_ctx_read.direct_address), - .main_pc = FF(pc), - .main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), - .main_sel_mem_op_a = FF(1), - .main_sel_mem_op_b = FF(1), - .main_sel_resolve_ind_addr_a = FF(static_cast(input_size_read.is_indirect)), - .main_sel_resolve_ind_addr_b = FF(static_cast(gen_ctx_read.is_indirect)), - }); - clk++; std::vector inputs; - uint32_t num_main_rows = read_slice_to_memory(call_ptr, - clk, - resolved_input_offset, - AvmMemoryTag::FF, - AvmMemoryTag::FF, - FF(internal_return_ptr), - uint32_t(input_size_read.val), - inputs); - clk += num_main_rows; - FF output = pedersen_trace_builder.pedersen_hash(inputs, uint32_t(gen_ctx_read.val), pedersen_clk); - write_slice_to_memory( - call_ptr, clk, resolved_output_offset, AvmMemoryTag::FF, AvmMemoryTag::FF, FF(internal_return_ptr), { output }); + read_slice_from_memory(resolved_input_offset, uint32_t(input_size_read), inputs); + FF output = pedersen_trace_builder.pedersen_hash(inputs, uint32_t(gen_ctx_read), clk); + write_slice_to_memory(resolved_output_offset, AvmMemoryTag::FF, std::vector{ output }); } void AvmTraceBuilder::op_ec_add(uint8_t indirect, @@ -3209,117 +3045,40 @@ void AvmTraceBuilder::op_ec_add(uint8_t indirect, rhs_is_inf_offset, output_offset }); // Load lhs point - auto lhs_x_read = constrained_read_from_memory( - call_ptr, clk, resolved_lhs_x_offset, AvmMemoryTag::FF, AvmMemoryTag::U0, IntermRegister::IA); - auto lhs_y_read = constrained_read_from_memory( - call_ptr, clk, resolved_lhs_y_offset, AvmMemoryTag::FF, AvmMemoryTag::U0, IntermRegister::IB); + auto lhs_x_read = unconstrained_read_from_memory(resolved_lhs_x_offset); + auto lhs_y_read = unconstrained_read_from_memory(resolved_lhs_y_offset); // Load rhs point - auto rhs_x_read = constrained_read_from_memory( - call_ptr, clk, resolved_rhs_x_offset, AvmMemoryTag::FF, AvmMemoryTag::U0, IntermRegister::IC); - auto rhs_y_read = constrained_read_from_memory( - call_ptr, clk, resolved_rhs_y_offset, AvmMemoryTag::FF, AvmMemoryTag::U0, IntermRegister::ID); - bool tag_match = lhs_x_read.tag_match && lhs_y_read.tag_match && rhs_x_read.tag_match && rhs_y_read.tag_match; - - // Save this clk time to line up with the gadget op. - auto ecc_clk = clk; - main_trace.push_back(Row{ - .main_clk = clk, - .main_ia = lhs_x_read.val, - .main_ib = lhs_y_read.val, - .main_ic = rhs_x_read.val, - .main_id = rhs_y_read.val, - .main_ind_addr_a = FF(lhs_x_read.indirect_address), - .main_ind_addr_b = FF(lhs_y_read.indirect_address), - .main_ind_addr_c = FF(rhs_x_read.indirect_address), - .main_ind_addr_d = FF(rhs_y_read.indirect_address), - .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_a = FF(lhs_x_read.direct_address), - .main_mem_addr_b = FF(lhs_y_read.direct_address), - .main_mem_addr_c = FF(rhs_x_read.direct_address), - .main_mem_addr_d = FF(rhs_y_read.direct_address), - .main_pc = FF(pc++), - .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), - .main_sel_mem_op_a = FF(1), - .main_sel_mem_op_b = FF(1), - .main_sel_mem_op_c = FF(1), - .main_sel_mem_op_d = FF(1), - .main_sel_resolve_ind_addr_a = FF(static_cast(lhs_x_read.is_indirect)), - .main_sel_resolve_ind_addr_b = FF(static_cast(lhs_y_read.is_indirect)), - .main_sel_resolve_ind_addr_c = FF(static_cast(rhs_x_read.is_indirect)), - .main_sel_resolve_ind_addr_d = FF(static_cast(rhs_y_read.is_indirect)), - .main_tag_err = FF(static_cast(!tag_match)), - }); - clk++; + auto rhs_x_read = unconstrained_read_from_memory(resolved_rhs_x_offset); + auto rhs_y_read = unconstrained_read_from_memory(resolved_rhs_y_offset); // Load the infinite bools separately since they have a different memory tag - auto lhs_is_inf_read = constrained_read_from_memory( - call_ptr, clk, resolved_lhs_is_inf_offset, AvmMemoryTag::U8, AvmMemoryTag::U0, IntermRegister::IA); - auto rhs_is_inf_read = constrained_read_from_memory( - call_ptr, clk, resolved_rhs_is_inf_offset, AvmMemoryTag::U8, AvmMemoryTag::U0, IntermRegister::IB); - bool tag_match_inf = lhs_is_inf_read.tag_match && rhs_is_inf_read.tag_match; + auto lhs_is_inf_read = unconstrained_read_from_memory(resolved_lhs_is_inf_offset); + auto rhs_is_inf_read = unconstrained_read_from_memory(resolved_rhs_is_inf_offset); - main_trace.push_back(Row{ - .main_clk = clk, - .main_ia = lhs_is_inf_read.val, - .main_ib = rhs_is_inf_read.val, - .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_a = FF(lhs_is_inf_offset), - .main_mem_addr_b = FF(rhs_is_inf_offset), - .main_pc = FF(pc), - .main_r_in_tag = FF(static_cast(AvmMemoryTag::U8)), - .main_sel_mem_op_a = FF(1), - .main_sel_mem_op_b = FF(1), - .main_tag_err = FF(static_cast(!tag_match_inf)), - }); - clk++; - grumpkin::g1::affine_element lhs = uint8_t(lhs_is_inf_read.val) == 1 + grumpkin::g1::affine_element lhs = uint8_t(lhs_is_inf_read) == 1 ? grumpkin::g1::affine_element::infinity() - : grumpkin::g1::affine_element{ lhs_x_read.val, lhs_y_read.val }; - grumpkin::g1::affine_element rhs = uint8_t(rhs_is_inf_read.val) == 1 + : grumpkin::g1::affine_element{ lhs_x_read, lhs_y_read }; + grumpkin::g1::affine_element rhs = uint8_t(rhs_is_inf_read) == 1 ? grumpkin::g1::affine_element::infinity() - : grumpkin::g1::affine_element{ rhs_x_read.val, rhs_y_read.val }; - auto result = ecc_trace_builder.embedded_curve_add(lhs, rhs, ecc_clk); + : grumpkin::g1::affine_element{ rhs_x_read, rhs_y_read }; + auto result = ecc_trace_builder.embedded_curve_add(lhs, rhs, clk); - // Write point coordinates - auto write_x = constrained_write_to_memory( - call_ptr, clk, resolved_output_offset, result.x, AvmMemoryTag::U0, AvmMemoryTag::FF, IntermRegister::IA); - // Write y (directly) using the write_x.direct_address + 1 - mem_trace_builder.write_into_memory( - call_ptr, clk, IntermRegister::IB, write_x.direct_address + 1, result.y, AvmMemoryTag::U0, AvmMemoryTag::FF); main_trace.push_back(Row{ .main_clk = clk, - .main_ia = result.x, - .main_ib = result.y, - .main_ind_addr_a = FF(write_x.indirect_address), .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_a = FF(write_x.direct_address), - .main_mem_addr_b = FF(write_x.direct_address + 1), - .main_pc = FF(pc), - .main_rwa = FF(1), - .main_rwb = FF(1), - .main_sel_mem_op_a = FF(1), - .main_sel_mem_op_b = FF(1), - .main_sel_resolve_ind_addr_a = FF(static_cast(write_x.is_indirect)), - .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_pc = FF(pc++), + .main_tag_err = FF(0), }); - clk++; - mem_trace_builder.write_into_memory(call_ptr, - clk, - IntermRegister::IA, - write_x.direct_address + 2, - result.is_point_at_infinity(), - AvmMemoryTag::U0, - AvmMemoryTag::U8); - main_trace.push_back(Row{ - .main_clk = clk, - .main_ia = result.is_point_at_infinity(), - .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_a = FF(write_x.direct_address + 2), - .main_pc = FF(pc), - .main_rwa = FF(1), - .main_sel_mem_op_a = FF(1), - .main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), - }); + gas_trace_builder.constrain_gas(clk, OpCode::ECADD); + + // Write point coordinates + auto out_addr_direct = + resolved_output_offset.mode == AddressingMode::DIRECT + ? resolved_output_offset.offset + : static_cast(mem_trace_builder.unconstrained_read(call_ptr, resolved_output_offset.offset)); + write_to_memory(out_addr_direct, result.x, AvmMemoryTag::FF); + write_to_memory(out_addr_direct + 1, result.y, AvmMemoryTag::FF); + write_to_memory(out_addr_direct + 2, result.is_point_at_infinity(), AvmMemoryTag::U8); } void AvmTraceBuilder::op_variable_msm(uint8_t indirect, @@ -3332,28 +3091,20 @@ void AvmTraceBuilder::op_variable_msm(uint8_t indirect, auto [resolved_points_offset, resolved_scalars_offset, resolved_output_offset] = unpack_indirects<3>(indirect, { points_offset, scalars_offset, output_offset }); - auto points_length_read = mem_trace_builder.read_and_load_from_memory( - call_ptr, clk, IntermRegister::IA, point_length_offset, AvmMemoryTag::U32, AvmMemoryTag::U0); - - main_trace.push_back(Row{ - .main_clk = clk, - .main_ia = points_length_read.val, - .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_a = FF(point_length_offset), - .main_pc = FF(pc), - .main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), - .main_sel_mem_op_a = FF(1), - .main_tag_err = FF(static_cast(!points_length_read.tag_match)), - }); - clk++; + auto points_length = unconstrained_read_from_memory(point_length_offset); // Points are stored as [x1, y1, inf1, x2, y2, inf2, ...] with the types [FF, FF, U8, FF, FF, U8, ...] - uint32_t num_points = uint32_t(points_length_read.val) / 3; // 3 elements per point + uint32_t num_points = uint32_t(points_length) / 3; // 3 elements per point // We need to split up the reads due to the memory tags, std::vector points_coords_vec; std::vector points_inf_vec; std::vector scalars_vec; - AddressWithMode coords_offset = resolved_points_offset; + + AddressWithMode coords_offset_direct = + resolved_points_offset.mode == AddressingMode::DIRECT + ? resolved_points_offset + : static_cast(mem_trace_builder.unconstrained_read(call_ptr, resolved_points_offset.offset)); + // Loading the points is a bit more complex since we need to read the coordinates and the infinity flags // separately The current circuit constraints does not allow for multiple memory tags to be loaded from within // the same row. If we could we would be able to replace the following loops with a single read_slice_to_memory @@ -3362,67 +3113,18 @@ void AvmTraceBuilder::op_variable_msm(uint8_t indirect, // Read the coordinates first, +2 since we read 2 points per row, the first load could be indirect for (uint32_t i = 0; i < num_points; i++) { - auto point_x1_read = constrained_read_from_memory( - call_ptr, clk, coords_offset, AvmMemoryTag::FF, AvmMemoryTag::U0, IntermRegister::IA); - auto point_y1_read = mem_trace_builder.read_and_load_from_memory( - call_ptr, clk, IntermRegister::IB, point_x1_read.direct_address + 1, AvmMemoryTag::FF, AvmMemoryTag::U0); - - bool tag_match = point_x1_read.tag_match && point_y1_read.tag_match; - points_coords_vec.insert(points_coords_vec.end(), { point_x1_read.val, point_y1_read.val }); - main_trace.push_back(Row{ - .main_clk = clk, - .main_ia = point_x1_read.val, - .main_ib = point_y1_read.val, - .main_ind_addr_a = FF(point_x1_read.indirect_address), - .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_a = FF(point_x1_read.direct_address), - .main_mem_addr_b = FF(point_x1_read.direct_address + 1), - .main_pc = FF(pc), - .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), - .main_sel_mem_op_a = FF(1), - .main_sel_mem_op_b = FF(1), - .main_sel_resolve_ind_addr_a = FF(static_cast(point_x1_read.is_indirect)), - .main_tag_err = FF(static_cast(!tag_match)), - }); - clk++; - // Update the coords offset to read the next point (subsequent points are always direct and separated by 3 - // addresses) - coords_offset = { AddressingMode::DIRECT, point_x1_read.direct_address + 3 }; - } - uint32_t inf_direct_address = resolved_points_offset.offset + 2; - // Read the Infinities flags - for (uint32_t i = 0; i < num_points; i++) { - auto point_inf_read = mem_trace_builder.read_and_load_from_memory( - call_ptr, clk, IntermRegister::IA, inf_direct_address, AvmMemoryTag::U8, AvmMemoryTag::U0); - points_inf_vec.emplace_back(point_inf_read.val); - - main_trace.push_back(Row{ - .main_clk = clk, - .main_ia = point_inf_read.val, - .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_a = FF(inf_direct_address), - .main_pc = FF(pc), - .main_r_in_tag = FF(static_cast(AvmMemoryTag::U8)), - .main_sel_mem_op_a = FF(1), - .main_tag_err = FF(static_cast(!point_inf_read.tag_match)), - }); - clk++; - // Update the inf offset to read the next point (subsequent points are always direct and separated by 3 - inf_direct_address += 3; + auto point_x1 = unconstrained_read_from_memory(coords_offset_direct + 3 * i); + auto point_y1 = unconstrained_read_from_memory(coords_offset_direct + 3 * i + 1); + auto infty = unconstrained_read_from_memory(coords_offset_direct + 3 * i + 2); + points_coords_vec.insert(points_coords_vec.end(), { point_x1, point_y1 }); + points_inf_vec.emplace_back(infty); } // Scalar read length is num_points* 2 since scalars are stored as lo and hi limbs uint32_t scalar_read_length = num_points * 2; // Scalars are easy to read since they are stored as [lo1, hi1, lo2, hi2, ...] with the types [FF, FF, FF,FF, // ...] - auto num_scalar_rows = read_slice_to_memory(call_ptr, - clk, - resolved_scalars_offset, - AvmMemoryTag::FF, - AvmMemoryTag::U0, - FF(internal_return_ptr), - scalar_read_length, - scalars_vec); - clk += num_scalar_rows; + read_slice_from_memory(resolved_scalars_offset, scalar_read_length, scalars_vec); + // Reconstruct Grumpkin points std::vector points; for (size_t i = 0; i < num_points; i++) { @@ -3447,49 +3149,24 @@ void AvmTraceBuilder::op_variable_msm(uint8_t indirect, } // Perform the variable MSM - could just put the logic in here since there are no constraints. auto result = ecc_trace_builder.variable_msm(points, scalars, clk); - // Write the result back to memory [x, y, inf] with tags [FF, FF, U8] - auto write_x = constrained_write_to_memory( - call_ptr, clk, resolved_output_offset, result.x, AvmMemoryTag::U0, AvmMemoryTag::FF, IntermRegister::IA); - mem_trace_builder.write_into_memory( - call_ptr, clk, IntermRegister::IB, write_x.direct_address + 1, result.y, AvmMemoryTag::U0, AvmMemoryTag::FF); main_trace.push_back(Row{ .main_clk = clk, - .main_ia = result.x, - .main_ib = result.y, - .main_ind_addr_a = FF(write_x.indirect_address), .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_a = FF(write_x.direct_address), - .main_mem_addr_b = FF(write_x.direct_address + 1), - .main_pc = FF(pc), - .main_rwa = FF(1), - .main_rwb = FF(1), - .main_sel_mem_op_a = FF(1), - .main_sel_mem_op_b = FF(1), - .main_sel_resolve_ind_addr_a = FF(static_cast(write_x.is_indirect)), - .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), - }); - clk++; - // Write the infinity - mem_trace_builder.write_into_memory(call_ptr, - clk, - IntermRegister::IA, - write_x.direct_address + 2, - result.is_point_at_infinity(), - AvmMemoryTag::U0, - AvmMemoryTag::U8); - main_trace.push_back(Row{ - .main_clk = clk, - .main_ia = static_cast(result.is_point_at_infinity()), - .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_a = FF(write_x.direct_address + 2), - .main_pc = FF(pc), - .main_rwa = FF(1), - .main_sel_mem_op_a = FF(1), - .main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_pc = FF(pc++), + .main_tag_err = FF(0), }); - pc++; + gas_trace_builder.constrain_gas(clk, OpCode::MSM); + + // Write the result back to memory [x, y, inf] with tags [FF, FF, U8] + AddressWithMode output_offset_direct = + resolved_output_offset.mode == AddressingMode::DIRECT + ? resolved_output_offset + : static_cast(mem_trace_builder.unconstrained_read(call_ptr, resolved_output_offset.offset)); + write_to_memory(output_offset_direct, result.x, AvmMemoryTag::FF); + write_to_memory(output_offset_direct + 1, result.y, AvmMemoryTag::FF); + write_to_memory(output_offset_direct + 2, result.is_point_at_infinity(), AvmMemoryTag::U8); } void AvmTraceBuilder::op_pedersen_commit(uint8_t indirect, @@ -3502,85 +3179,31 @@ void AvmTraceBuilder::op_pedersen_commit(uint8_t indirect, auto [resolved_input_offset, resolved_output_offset, resolved_input_size_offset, resolved_gen_ctx_offset] = unpack_indirects<4>(indirect, { input_offset, output_offset, input_size_offset, gen_ctx_offset }); - auto input_length_read = constrained_read_from_memory( - call_ptr, clk, resolved_input_size_offset, AvmMemoryTag::U32, AvmMemoryTag::U0, IntermRegister::IA); - auto gen_ctx_read = constrained_read_from_memory( - call_ptr, clk, resolved_gen_ctx_offset, AvmMemoryTag::U32, AvmMemoryTag::U0, IntermRegister::IB); - - main_trace.push_back(Row{ - .main_clk = clk, - .main_ia = input_length_read.val, - .main_ib = gen_ctx_read.val, - .main_ind_addr_a = FF(input_length_read.indirect_address), - .main_ind_addr_b = FF(gen_ctx_read.indirect_address), - .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_a = FF(input_length_read.direct_address), - .main_mem_addr_b = FF(gen_ctx_read.direct_address), - .main_pc = FF(pc), - .main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), - .main_sel_mem_op_a = FF(1), - .main_sel_mem_op_b = FF(1), - .main_sel_resolve_ind_addr_a = FF(static_cast(input_length_read.is_indirect)), - .main_sel_resolve_ind_addr_b = FF(static_cast(gen_ctx_read.is_indirect)), - }); - clk++; + auto input_length_read = unconstrained_read_from_memory(resolved_input_size_offset); + auto gen_ctx_read = unconstrained_read_from_memory(resolved_gen_ctx_offset); std::vector inputs; - auto num_rows = read_slice_to_memory(call_ptr, - clk, - resolved_input_offset, - AvmMemoryTag::FF, - AvmMemoryTag::U0, - FF(internal_return_ptr), - uint32_t(input_length_read.val), - inputs); - clk += num_rows; - - grumpkin::g1::affine_element result = - crypto::pedersen_commitment::commit_native(inputs, uint32_t(gen_ctx_read.val)); + read_slice_from_memory(resolved_input_offset, uint32_t(input_length_read), inputs); - auto write_x = constrained_write_to_memory( - call_ptr, clk, resolved_output_offset, result.x, AvmMemoryTag::U0, AvmMemoryTag::FF, IntermRegister::IA); - - mem_trace_builder.write_into_memory( - call_ptr, clk, IntermRegister::IB, write_x.direct_address + 1, result.y, AvmMemoryTag::U0, AvmMemoryTag::FF); + grumpkin::g1::affine_element result = crypto::pedersen_commitment::commit_native(inputs, uint32_t(gen_ctx_read)); main_trace.push_back(Row{ .main_clk = clk, - .main_ia = result.x, - .main_ib = result.y, - .main_ind_addr_a = FF(write_x.indirect_address), .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_a = FF(write_x.direct_address), - .main_mem_addr_b = FF(write_x.direct_address + 1), - .main_pc = FF(pc), - .main_rwa = FF(1), - .main_rwb = FF(1), - .main_sel_mem_op_a = FF(1), - .main_sel_mem_op_b = FF(1), - .main_sel_resolve_ind_addr_a = FF(static_cast(write_x.is_indirect)), - .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_pc = FF(pc++), + .main_tag_err = FF(0), }); - clk++; - mem_trace_builder.write_into_memory(call_ptr, - clk, - IntermRegister::IA, - write_x.direct_address + 2, - result.is_point_at_infinity(), - AvmMemoryTag::U0, - AvmMemoryTag::U8); - main_trace.push_back(Row{ - .main_clk = clk, - .main_ia = static_cast(result.is_point_at_infinity()), - .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_a = FF(write_x.direct_address + 2), - .main_pc = FF(pc), - .main_rwa = FF(1), - .main_sel_mem_op_a = FF(1), - .main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), - }); - pc++; + gas_trace_builder.constrain_gas(clk, OpCode::PEDERSENCOMMITMENT); + + // Write the result back to memory [x, y, inf] with tags [FF, FF, U8] + AddressWithMode output_offset_direct = + resolved_output_offset.mode == AddressingMode::DIRECT + ? resolved_output_offset + : static_cast(mem_trace_builder.unconstrained_read(call_ptr, resolved_output_offset.offset)); + write_to_memory(output_offset_direct, result.x, AvmMemoryTag::FF); + write_to_memory(output_offset_direct + 1, result.y, AvmMemoryTag::FF); + write_to_memory(output_offset_direct + 2, result.is_point_at_infinity(), AvmMemoryTag::U8); } /************************************************************************************************** @@ -3617,7 +3240,7 @@ void AvmTraceBuilder::op_to_radix_le( : std::vector(num_limbs, 0); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::TORADIXLE); + gas_trace_builder.constrain_gas(clk, OpCode::TORADIXLE, num_limbs); // This is the row that contains the selector to trigger the sel_op_radix_le // In this row, we read the input value and the destination address into register A and B respectively @@ -3642,18 +3265,8 @@ void AvmTraceBuilder::op_to_radix_le( .main_sel_resolve_ind_addr_b = FF(static_cast(read_dst.is_indirect)), .main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), }); - // Increment the clock so we dont write at the same clock cycle - // Instead we temporarily encode the writes into the subsequent rows of the main trace - clk++; - // MemTrace, write into memory value b from intermediate register ib. - std::vector ff_res = {}; - ff_res.reserve(res.size()); - for (auto const& limb : res) { - ff_res.emplace_back(limb); - } - write_slice_to_memory( - call_ptr, clk, resolved_dst_offset, AvmMemoryTag::FF, AvmMemoryTag::U8, FF(internal_return_ptr), ff_res); + write_slice_to_memory(resolved_dst_offset, AvmMemoryTag::U8, res); } /************************************************************************************************** @@ -3691,7 +3304,7 @@ void AvmTraceBuilder::op_sha256_compression(uint8_t indirect, bool tag_match = read_a.tag_match && read_b.tag_match; // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::SHA256COMPRESSION); + gas_trace_builder.constrain_gas(clk, OpCode::SHA256COMPRESSION); // Since the above adds mem_reads in the mem_trace_builder at clk, we need to follow up resolving the reads in // the main trace at the same clk cycle to preserve the cross-table permutation @@ -3729,28 +3342,9 @@ void AvmTraceBuilder::op_sha256_compression(uint8_t indirect, // Input for hash is expanded to 512 bits std::vector input_vec; // Read results are written to h_init array. - read_slice_to_memory(call_ptr, - clk, - resolved_h_init_offset, - AvmMemoryTag::U32, - AvmMemoryTag::U32, - FF(internal_return_ptr), - 8, - h_init_vec); - - // Increment the clock by 2 since (8 reads / 4 reads per row = 2) - clk += 2; + read_slice_from_memory(resolved_h_init_offset, 8, h_init_vec); // Read results are written to input array - read_slice_to_memory(call_ptr, - clk, - resolved_input_offset, - AvmMemoryTag::U32, - AvmMemoryTag::U32, - FF(internal_return_ptr), - 16, - input_vec); - // Increment the clock by 4 since (16 / 4 = 4) - clk += 4; + read_slice_from_memory(resolved_input_offset, 16, input_vec); // Now that we have read all the values, we can perform the operation to get the resulting witness. // Note: We use the sha_op_clk to ensure that the sha256 operation is performed at the same clock cycle as the @@ -3766,13 +3360,7 @@ void AvmTraceBuilder::op_sha256_compression(uint8_t indirect, } // Write the result to memory after - write_slice_to_memory(call_ptr, - clk, - resolved_output_offset, - AvmMemoryTag::U32, - AvmMemoryTag::U32, - FF(internal_return_ptr), - ff_result); + write_slice_to_memory(resolved_output_offset, AvmMemoryTag::U32, ff_result); } /** @@ -3791,7 +3379,7 @@ void AvmTraceBuilder::op_sha256_compression(uint8_t indirect, void AvmTraceBuilder::op_keccakf1600(uint8_t indirect, uint32_t output_offset, uint32_t input_offset, - uint32_t input_size_offset) + [[maybe_unused]] uint32_t input_size_offset) { // What happens if the input_size_offset is > 25 when the state is more that that? auto clk = static_cast(main_trace.size()) + 1; @@ -3804,7 +3392,7 @@ void AvmTraceBuilder::op_keccakf1600(uint8_t indirect, bool tag_match = input_read.tag_match && output_read.tag_match; // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(clk, OpCode::KECCAKF1600); + gas_trace_builder.constrain_gas(clk, OpCode::KECCAKF1600); main_trace.push_back(Row{ .main_clk = clk, @@ -3824,53 +3412,19 @@ void AvmTraceBuilder::op_keccakf1600(uint8_t indirect, .main_sel_resolve_ind_addr_c = FF(static_cast(output_read.is_indirect)), .main_tag_err = FF(static_cast(!tag_match)), }); - // We store the current clk this main trace row occurred so that we can line up the keccak gadget operation - // at the same clk later. - auto keccak_op_clk = clk; - // We need to increment the clk - clk++; - auto input_length_read = mem_trace_builder.read_and_load_from_memory( - call_ptr, clk, IntermRegister::IB, input_size_offset, AvmMemoryTag::U32, AvmMemoryTag::U0); - main_trace.push_back(Row{ - .main_clk = clk, - .main_ib = input_length_read.val, // Message Length - .main_internal_return_ptr = FF(internal_return_ptr), - .main_mem_addr_b = FF(input_size_offset), // length - .main_pc = FF(pc), - .main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), - .main_sel_mem_op_b = FF(1), - .main_tag_err = FF(static_cast(!input_length_read.tag_match)), - }); - clk++; + // Array input is fixed to 1600 bits std::vector input_vec; // Read results are written to input array - uint32_t num_main_rows = read_slice_to_memory(call_ptr, - clk, - resolved_input_offset, - AvmMemoryTag::U64, - AvmMemoryTag::U0, - FF(internal_return_ptr), - 25, - input_vec); - + read_slice_from_memory(resolved_input_offset, 25, input_vec); std::array input = vec_to_arr(input_vec); - // Increment the clock by 7 since (25 reads / 4 reads per row = 7) - clk += num_main_rows; // Now that we have read all the values, we can perform the operation to get the resulting witness. // Note: We use the keccak_op_clk to ensure that the keccakf1600 operation is performed at the same clock cycle // as the main trace that has the selector - std::array result = keccak_trace_builder.keccakf1600(keccak_op_clk, input); - // We convert the results to field elements here - std::vector ff_result; - for (uint32_t i = 0; i < 25; i++) { - ff_result.emplace_back(result[i]); - } - + std::array result = keccak_trace_builder.keccakf1600(clk, input); // Write the result to memory after - write_slice_to_memory( - call_ptr, clk, resolved_output_offset, AvmMemoryTag::U0, AvmMemoryTag::U64, FF(internal_return_ptr), ff_result); + write_slice_to_memory(resolved_output_offset, AvmMemoryTag::U64, result); } /************************************************************************************************** @@ -3919,8 +3473,8 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c // If the bin_trace_size has entries, we need the main_trace to be as big as our byte lookup table (3 * // 2**16 long) size_t const lookup_table_size = (bin_trace_size > 0 && range_check_required) ? 3 * (1 << 16) : 0; - // Range check size is 1 less than it needs to be since we insert a "first row" at the top of the trace at the end, - // with clk 0 (this doubles as our range check) + // Range check size is 1 less than it needs to be since we insert a "first row" at the top of the trace at the + // end, with clk 0 (this doubles as our range check) size_t const range_check_size = range_check_required ? UINT16_MAX : 0; std::vector trace_sizes = { mem_trace_size, main_trace_size, alu_trace_size, range_check_size, conv_trace_size, lookup_table_size, @@ -4398,14 +3952,9 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c // Assume that gas_trace entries are ordered by a strictly increasing clk sequence. for (auto const& gas_entry : gas_trace) { - // Filling potential gap between two gas_trace entries - // Remaining gas values remain unchanged. - while (gas_entry.clk > current_clk) { - auto& next = main_trace.at(current_clk); - next.main_l2_gas_remaining = current_l2_gas_remaining; - next.main_da_gas_remaining = current_da_gas_remaining; - current_clk++; - } + // There should be no gaps in the gas_trace. + ASSERT(gas_entry.clk == current_clk); + // << "No gas entry for opcode" << next.main_opcode_val << "at clk" << current_clk; auto& dest = main_trace.at(gas_entry.clk - 1); auto& next = main_trace.at(gas_entry.clk); @@ -4426,17 +3975,13 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c dest.main_abs_da_rem_gas_hi = abs_da_gas_remaining >> 16; dest.main_abs_l2_rem_gas_lo = static_cast(abs_l2_gas_remaining); dest.main_abs_da_rem_gas_lo = static_cast(abs_da_gas_remaining); + dest.main_sel_gas_accounting_active = FF(1); - // TODO: gas is not constrained for external call at this time - if (gas_entry.opcode != OpCode::CALL) { - dest.main_sel_gas_accounting_active = FF(1); - - // lookups counting - rem_gas_rng_check_counts[L2_HI_GAS_COUNTS_IDX][static_cast(dest.main_abs_l2_rem_gas_hi)]++; - rem_gas_rng_check_counts[L2_LO_GAS_COUNTS_IDX][static_cast(dest.main_abs_l2_rem_gas_lo)]++; - rem_gas_rng_check_counts[DA_HI_GAS_COUNTS_IDX][static_cast(dest.main_abs_da_rem_gas_hi)]++; - rem_gas_rng_check_counts[DA_LO_GAS_COUNTS_IDX][static_cast(dest.main_abs_da_rem_gas_lo)]++; - } + // lookups counting + rem_gas_rng_check_counts[L2_HI_GAS_COUNTS_IDX][static_cast(dest.main_abs_l2_rem_gas_hi)]++; + rem_gas_rng_check_counts[L2_LO_GAS_COUNTS_IDX][static_cast(dest.main_abs_l2_rem_gas_lo)]++; + rem_gas_rng_check_counts[DA_HI_GAS_COUNTS_IDX][static_cast(dest.main_abs_da_rem_gas_hi)]++; + rem_gas_rng_check_counts[DA_LO_GAS_COUNTS_IDX][static_cast(dest.main_abs_da_rem_gas_lo)]++; dest.main_l2_out_of_gas = static_cast(l2_out_of_gas); dest.main_da_out_of_gas = static_cast(da_out_of_gas); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp index ff06295cc39..c5404ec1a03 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp @@ -29,8 +29,18 @@ struct AddressWithMode { AddressingMode mode; uint32_t offset; + AddressWithMode() = default; + AddressWithMode(uint32_t offset) + : mode(AddressingMode::DIRECT) + , offset(offset) + {} + AddressWithMode(AddressingMode mode, uint32_t offset) + : mode(mode) + , offset(offset) + {} + // Dont mutate - AddressWithMode operator+(uint val) { return { mode, offset + val }; } + AddressWithMode operator+(uint val) const noexcept { return { mode, offset + val }; } }; // This is the internal context that we keep along the lifecycle of bytecode execution @@ -102,6 +112,8 @@ class AvmTraceBuilder { // Machine State - Memory void op_set(uint8_t indirect, uint128_t val, uint32_t dst_offset, AvmMemoryTag in_tag); + // TODO: only used for write_slice_to_memory. Remove. + void op_set_internal(uint8_t indirect, FF val_ff, uint32_t dst_offset, AvmMemoryTag in_tag); void op_mov(uint8_t indirect, uint32_t src_offset, uint32_t dst_offset); void op_cmov(uint8_t indirect, uint32_t a_offset, uint32_t b_offset, uint32_t cond_offset, uint32_t dst_offset); @@ -256,23 +268,11 @@ class AvmTraceBuilder { IntermRegister reg, AvmMemTraceBuilder::MemOpOwner mem_op_owner = AvmMemTraceBuilder::MAIN); - // TODO(ilyas: #6383): Temporary way to bulk read slices - template - uint32_t read_slice_to_memory(uint8_t space_id, - uint32_t clk, - AddressWithMode addr, - AvmMemoryTag r_tag, - AvmMemoryTag w_tag, - FF internal_return_ptr, - size_t slice_len, - std::vector& slice); - uint32_t write_slice_to_memory(uint8_t space_id, - uint32_t clk, - AddressWithMode addr, - AvmMemoryTag r_tag, - AvmMemoryTag w_tag, - FF internal_return_ptr, - std::vector const& slice); + // TODO: remove these once everything is constrained. + FF unconstrained_read_from_memory(AddressWithMode addr); + template void read_slice_from_memory(AddressWithMode addr, size_t slice_len, std::vector& slice); + void write_to_memory(AddressWithMode addr, FF val, AvmMemoryTag w_tag); + template void write_slice_to_memory(AddressWithMode addr, AvmMemoryTag w_tag, const T& slice); }; } // namespace bb::avm_trace diff --git a/bb-pilcom/bb-pil-backend/src/relation_builder.rs b/bb-pilcom/bb-pil-backend/src/relation_builder.rs index f1be69f0ba8..1d5f069dd67 100644 --- a/bb-pilcom/bb-pil-backend/src/relation_builder.rs +++ b/bb-pilcom/bb-pil-backend/src/relation_builder.rs @@ -131,6 +131,8 @@ impl RelationBuilder for BBFiles { .enumerate() .filter(|(_, id)| id.label.is_some()) .map(|(idx, id)| (idx, id.label.clone().unwrap())) + // Useful for debugging + // .map(|(idx, id)| (idx, id.label.as_ref().unwrap_or(&id.identity).clone())) .collect_vec(); let data = &json!({