From 87d67f4f831956840ba57ff495b600488f6d0753 Mon Sep 17 00:00:00 2001 From: IlyasRidhuan Date: Mon, 9 Dec 2024 10:52:08 +0000 Subject: [PATCH] fix: rebase --- .../barretenberg/vm/avm/generated/flavor.cpp | 678 ++------- .../barretenberg/vm/avm/generated/flavor.hpp | 14 +- .../vm/avm/generated/full_row.hpp | 2 +- .../vm/avm/generated/relations/main.hpp | 240 +-- .../src/barretenberg/vm/avm/trace/trace.cpp | 19 +- .../src/barretenberg/vm/aztec_constants.hpp | 2 +- .../crates/types/src/constants.nr | 2 +- yarn-project/circuits.js/src/constants.gen.ts | 2 +- .../simulator/src/avm/avm_simulator.test.ts | 18 +- .../simulator/src/avm/journal/journal.ts | 1298 ++++++++--------- 10 files changed, 778 insertions(+), 1497 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp index 77ccec608ca..ff71f710172 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp @@ -230,7 +230,6 @@ AvmFlavor::AllConstRefValues::AllConstRefValues( , main_sel_op_fdiv(il[222]) , main_sel_op_fee_per_da_gas(il[223]) , main_sel_op_fee_per_l2_gas(il[224]) -<<<<<<< HEAD , main_sel_op_get_contract_instance(il[225]) , main_sel_op_internal_call(il[226]) , main_sel_op_internal_return(il[227]) @@ -736,599 +735,90 @@ AvmFlavor::AllConstRefValues::AllConstRefValues( , perm_main_conv_inv(il[727]) , perm_main_sha256_inv(il[728]) , perm_main_pos2_perm_inv(il[729]) - , perm_main_slice_inv(il[730]) -======= - , main_sel_op_function_selector(il[225]) - , main_sel_op_get_contract_instance(il[226]) - , main_sel_op_internal_call(il[227]) - , main_sel_op_internal_return(il[228]) - , main_sel_op_is_static_call(il[229]) - , main_sel_op_jump(il[230]) - , main_sel_op_jumpi(il[231]) - , main_sel_op_keccak(il[232]) - , main_sel_op_l1_to_l2_msg_exists(il[233]) - , main_sel_op_l2gasleft(il[234]) - , main_sel_op_lt(il[235]) - , main_sel_op_lte(il[236]) - , main_sel_op_mov(il[237]) - , main_sel_op_msm(il[238]) - , main_sel_op_mul(il[239]) - , main_sel_op_not(il[240]) - , main_sel_op_note_hash_exists(il[241]) - , main_sel_op_nullifier_exists(il[242]) - , main_sel_op_or(il[243]) - , main_sel_op_poseidon2(il[244]) - , main_sel_op_radix_be(il[245]) - , main_sel_op_returndata_copy(il[246]) - , main_sel_op_returndata_size(il[247]) - , main_sel_op_sender(il[248]) - , main_sel_op_set(il[249]) - , main_sel_op_sha256(il[250]) - , main_sel_op_shl(il[251]) - , main_sel_op_shr(il[252]) - , main_sel_op_sload(il[253]) - , main_sel_op_sstore(il[254]) - , main_sel_op_static_call(il[255]) - , main_sel_op_sub(il[256]) - , main_sel_op_timestamp(il[257]) - , main_sel_op_transaction_fee(il[258]) - , main_sel_op_version(il[259]) - , main_sel_op_xor(il[260]) - , main_sel_q_kernel_lookup(il[261]) - , main_sel_q_kernel_output_lookup(il[262]) - , main_sel_resolve_ind_addr_a(il[263]) - , main_sel_resolve_ind_addr_b(il[264]) - , main_sel_resolve_ind_addr_c(il[265]) - , main_sel_resolve_ind_addr_d(il[266]) - , main_sel_returndata(il[267]) - , main_sel_rng_16(il[268]) - , main_sel_rng_8(il[269]) - , main_sel_slice_gadget(il[270]) - , main_space_id(il[271]) - , main_tag_err(il[272]) - , main_w_in_tag(il[273]) - , mem_addr(il[274]) - , mem_clk(il[275]) - , mem_diff(il[276]) - , mem_glob_addr(il[277]) - , mem_last(il[278]) - , mem_lastAccess(il[279]) - , mem_one_min_inv(il[280]) - , mem_r_in_tag(il[281]) - , mem_rw(il[282]) - , mem_sel_mem(il[283]) - , mem_sel_mov_ia_to_ic(il[284]) - , mem_sel_mov_ib_to_ic(il[285]) - , mem_sel_op_a(il[286]) - , mem_sel_op_b(il[287]) - , mem_sel_op_c(il[288]) - , mem_sel_op_d(il[289]) - , mem_sel_op_poseidon_read_a(il[290]) - , mem_sel_op_poseidon_read_b(il[291]) - , mem_sel_op_poseidon_read_c(il[292]) - , mem_sel_op_poseidon_read_d(il[293]) - , mem_sel_op_poseidon_write_a(il[294]) - , mem_sel_op_poseidon_write_b(il[295]) - , mem_sel_op_poseidon_write_c(il[296]) - , mem_sel_op_poseidon_write_d(il[297]) - , mem_sel_op_slice(il[298]) - , mem_sel_resolve_ind_addr_a(il[299]) - , mem_sel_resolve_ind_addr_b(il[300]) - , mem_sel_resolve_ind_addr_c(il[301]) - , mem_sel_resolve_ind_addr_d(il[302]) - , mem_sel_rng_chk(il[303]) - , mem_skip_check_tag(il[304]) - , mem_space_id(il[305]) - , mem_tag(il[306]) - , mem_tag_err(il[307]) - , mem_tsp(il[308]) - , mem_u16_r0(il[309]) - , mem_u16_r1(il[310]) - , mem_u8_r0(il[311]) - , mem_val(il[312]) - , mem_w_in_tag(il[313]) - , merkle_tree_clk(il[314]) - , merkle_tree_expected_tree_root(il[315]) - , merkle_tree_latch(il[316]) - , merkle_tree_leaf_index(il[317]) - , merkle_tree_leaf_index_is_even(il[318]) - , merkle_tree_leaf_value(il[319]) - , merkle_tree_left_hash(il[320]) - , merkle_tree_output_hash(il[321]) - , merkle_tree_path_len(il[322]) - , merkle_tree_path_len_inv(il[323]) - , merkle_tree_right_hash(il[324]) - , merkle_tree_sel_merkle_tree(il[325]) - , merkle_tree_sibling_value(il[326]) - , poseidon2_B_10_0(il[327]) - , poseidon2_B_10_1(il[328]) - , poseidon2_B_10_2(il[329]) - , poseidon2_B_10_3(il[330]) - , poseidon2_B_11_0(il[331]) - , poseidon2_B_11_1(il[332]) - , poseidon2_B_11_2(il[333]) - , poseidon2_B_11_3(il[334]) - , poseidon2_B_12_0(il[335]) - , poseidon2_B_12_1(il[336]) - , poseidon2_B_12_2(il[337]) - , poseidon2_B_12_3(il[338]) - , poseidon2_B_13_0(il[339]) - , poseidon2_B_13_1(il[340]) - , poseidon2_B_13_2(il[341]) - , poseidon2_B_13_3(il[342]) - , poseidon2_B_14_0(il[343]) - , poseidon2_B_14_1(il[344]) - , poseidon2_B_14_2(il[345]) - , poseidon2_B_14_3(il[346]) - , poseidon2_B_15_0(il[347]) - , poseidon2_B_15_1(il[348]) - , poseidon2_B_15_2(il[349]) - , poseidon2_B_15_3(il[350]) - , poseidon2_B_16_0(il[351]) - , poseidon2_B_16_1(il[352]) - , poseidon2_B_16_2(il[353]) - , poseidon2_B_16_3(il[354]) - , poseidon2_B_17_0(il[355]) - , poseidon2_B_17_1(il[356]) - , poseidon2_B_17_2(il[357]) - , poseidon2_B_17_3(il[358]) - , poseidon2_B_18_0(il[359]) - , poseidon2_B_18_1(il[360]) - , poseidon2_B_18_2(il[361]) - , poseidon2_B_18_3(il[362]) - , poseidon2_B_19_0(il[363]) - , poseidon2_B_19_1(il[364]) - , poseidon2_B_19_2(il[365]) - , poseidon2_B_19_3(il[366]) - , poseidon2_B_20_0(il[367]) - , poseidon2_B_20_1(il[368]) - , poseidon2_B_20_2(il[369]) - , poseidon2_B_20_3(il[370]) - , poseidon2_B_21_0(il[371]) - , poseidon2_B_21_1(il[372]) - , poseidon2_B_21_2(il[373]) - , poseidon2_B_21_3(il[374]) - , poseidon2_B_22_0(il[375]) - , poseidon2_B_22_1(il[376]) - , poseidon2_B_22_2(il[377]) - , poseidon2_B_22_3(il[378]) - , poseidon2_B_23_0(il[379]) - , poseidon2_B_23_1(il[380]) - , poseidon2_B_23_2(il[381]) - , poseidon2_B_23_3(il[382]) - , poseidon2_B_24_0(il[383]) - , poseidon2_B_24_1(il[384]) - , poseidon2_B_24_2(il[385]) - , poseidon2_B_24_3(il[386]) - , poseidon2_B_25_0(il[387]) - , poseidon2_B_25_1(il[388]) - , poseidon2_B_25_2(il[389]) - , poseidon2_B_25_3(il[390]) - , poseidon2_B_26_0(il[391]) - , poseidon2_B_26_1(il[392]) - , poseidon2_B_26_2(il[393]) - , poseidon2_B_26_3(il[394]) - , poseidon2_B_27_0(il[395]) - , poseidon2_B_27_1(il[396]) - , poseidon2_B_27_2(il[397]) - , poseidon2_B_27_3(il[398]) - , poseidon2_B_28_0(il[399]) - , poseidon2_B_28_1(il[400]) - , poseidon2_B_28_2(il[401]) - , poseidon2_B_28_3(il[402]) - , poseidon2_B_29_0(il[403]) - , poseidon2_B_29_1(il[404]) - , poseidon2_B_29_2(il[405]) - , poseidon2_B_29_3(il[406]) - , poseidon2_B_30_0(il[407]) - , poseidon2_B_30_1(il[408]) - , poseidon2_B_30_2(il[409]) - , poseidon2_B_30_3(il[410]) - , poseidon2_B_31_0(il[411]) - , poseidon2_B_31_1(il[412]) - , poseidon2_B_31_2(il[413]) - , poseidon2_B_31_3(il[414]) - , poseidon2_B_32_0(il[415]) - , poseidon2_B_32_1(il[416]) - , poseidon2_B_32_2(il[417]) - , poseidon2_B_32_3(il[418]) - , poseidon2_B_33_0(il[419]) - , poseidon2_B_33_1(il[420]) - , poseidon2_B_33_2(il[421]) - , poseidon2_B_33_3(il[422]) - , poseidon2_B_34_0(il[423]) - , poseidon2_B_34_1(il[424]) - , poseidon2_B_34_2(il[425]) - , poseidon2_B_34_3(il[426]) - , poseidon2_B_35_0(il[427]) - , poseidon2_B_35_1(il[428]) - , poseidon2_B_35_2(il[429]) - , poseidon2_B_35_3(il[430]) - , poseidon2_B_36_0(il[431]) - , poseidon2_B_36_1(il[432]) - , poseidon2_B_36_2(il[433]) - , poseidon2_B_36_3(il[434]) - , poseidon2_B_37_0(il[435]) - , poseidon2_B_37_1(il[436]) - , poseidon2_B_37_2(il[437]) - , poseidon2_B_37_3(il[438]) - , poseidon2_B_38_0(il[439]) - , poseidon2_B_38_1(il[440]) - , poseidon2_B_38_2(il[441]) - , poseidon2_B_38_3(il[442]) - , poseidon2_B_39_0(il[443]) - , poseidon2_B_39_1(il[444]) - , poseidon2_B_39_2(il[445]) - , poseidon2_B_39_3(il[446]) - , poseidon2_B_40_0(il[447]) - , poseidon2_B_40_1(il[448]) - , poseidon2_B_40_2(il[449]) - , poseidon2_B_40_3(il[450]) - , poseidon2_B_41_0(il[451]) - , poseidon2_B_41_1(il[452]) - , poseidon2_B_41_2(il[453]) - , poseidon2_B_41_3(il[454]) - , poseidon2_B_42_0(il[455]) - , poseidon2_B_42_1(il[456]) - , poseidon2_B_42_2(il[457]) - , poseidon2_B_42_3(il[458]) - , poseidon2_B_43_0(il[459]) - , poseidon2_B_43_1(il[460]) - , poseidon2_B_43_2(il[461]) - , poseidon2_B_43_3(il[462]) - , poseidon2_B_44_0(il[463]) - , poseidon2_B_44_1(il[464]) - , poseidon2_B_44_2(il[465]) - , poseidon2_B_44_3(il[466]) - , poseidon2_B_45_0(il[467]) - , poseidon2_B_45_1(il[468]) - , poseidon2_B_45_2(il[469]) - , poseidon2_B_45_3(il[470]) - , poseidon2_B_46_0(il[471]) - , poseidon2_B_46_1(il[472]) - , poseidon2_B_46_2(il[473]) - , poseidon2_B_46_3(il[474]) - , poseidon2_B_47_0(il[475]) - , poseidon2_B_47_1(il[476]) - , poseidon2_B_47_2(il[477]) - , poseidon2_B_47_3(il[478]) - , poseidon2_B_48_0(il[479]) - , poseidon2_B_48_1(il[480]) - , poseidon2_B_48_2(il[481]) - , poseidon2_B_48_3(il[482]) - , poseidon2_B_49_0(il[483]) - , poseidon2_B_49_1(il[484]) - , poseidon2_B_49_2(il[485]) - , poseidon2_B_49_3(il[486]) - , poseidon2_B_4_0(il[487]) - , poseidon2_B_4_1(il[488]) - , poseidon2_B_4_2(il[489]) - , poseidon2_B_4_3(il[490]) - , poseidon2_B_50_0(il[491]) - , poseidon2_B_50_1(il[492]) - , poseidon2_B_50_2(il[493]) - , poseidon2_B_50_3(il[494]) - , poseidon2_B_51_0(il[495]) - , poseidon2_B_51_1(il[496]) - , poseidon2_B_51_2(il[497]) - , poseidon2_B_51_3(il[498]) - , poseidon2_B_52_0(il[499]) - , poseidon2_B_52_1(il[500]) - , poseidon2_B_52_2(il[501]) - , poseidon2_B_52_3(il[502]) - , poseidon2_B_53_0(il[503]) - , poseidon2_B_53_1(il[504]) - , poseidon2_B_53_2(il[505]) - , poseidon2_B_53_3(il[506]) - , poseidon2_B_54_0(il[507]) - , poseidon2_B_54_1(il[508]) - , poseidon2_B_54_2(il[509]) - , poseidon2_B_54_3(il[510]) - , poseidon2_B_55_0(il[511]) - , poseidon2_B_55_1(il[512]) - , poseidon2_B_55_2(il[513]) - , poseidon2_B_55_3(il[514]) - , poseidon2_B_56_0(il[515]) - , poseidon2_B_56_1(il[516]) - , poseidon2_B_56_2(il[517]) - , poseidon2_B_56_3(il[518]) - , poseidon2_B_57_0(il[519]) - , poseidon2_B_57_1(il[520]) - , poseidon2_B_57_2(il[521]) - , poseidon2_B_57_3(il[522]) - , poseidon2_B_58_0(il[523]) - , poseidon2_B_58_1(il[524]) - , poseidon2_B_58_2(il[525]) - , poseidon2_B_58_3(il[526]) - , poseidon2_B_59_0(il[527]) - , poseidon2_B_59_1(il[528]) - , poseidon2_B_59_2(il[529]) - , poseidon2_B_59_3(il[530]) - , poseidon2_B_5_0(il[531]) - , poseidon2_B_5_1(il[532]) - , poseidon2_B_5_2(il[533]) - , poseidon2_B_5_3(il[534]) - , poseidon2_B_6_0(il[535]) - , poseidon2_B_6_1(il[536]) - , poseidon2_B_6_2(il[537]) - , poseidon2_B_6_3(il[538]) - , poseidon2_B_7_0(il[539]) - , poseidon2_B_7_1(il[540]) - , poseidon2_B_7_2(il[541]) - , poseidon2_B_7_3(il[542]) - , poseidon2_B_8_0(il[543]) - , poseidon2_B_8_1(il[544]) - , poseidon2_B_8_2(il[545]) - , poseidon2_B_8_3(il[546]) - , poseidon2_B_9_0(il[547]) - , poseidon2_B_9_1(il[548]) - , poseidon2_B_9_2(il[549]) - , poseidon2_B_9_3(il[550]) - , poseidon2_EXT_LAYER_4(il[551]) - , poseidon2_EXT_LAYER_5(il[552]) - , poseidon2_EXT_LAYER_6(il[553]) - , poseidon2_EXT_LAYER_7(il[554]) - , poseidon2_T_0_4(il[555]) - , poseidon2_T_0_5(il[556]) - , poseidon2_T_0_6(il[557]) - , poseidon2_T_0_7(il[558]) - , poseidon2_T_1_4(il[559]) - , poseidon2_T_1_5(il[560]) - , poseidon2_T_1_6(il[561]) - , poseidon2_T_1_7(il[562]) - , poseidon2_T_2_4(il[563]) - , poseidon2_T_2_5(il[564]) - , poseidon2_T_2_6(il[565]) - , poseidon2_T_2_7(il[566]) - , poseidon2_T_3_4(il[567]) - , poseidon2_T_3_5(il[568]) - , poseidon2_T_3_6(il[569]) - , poseidon2_T_3_7(il[570]) - , poseidon2_T_60_4(il[571]) - , poseidon2_T_60_5(il[572]) - , poseidon2_T_60_6(il[573]) - , poseidon2_T_60_7(il[574]) - , poseidon2_T_61_4(il[575]) - , poseidon2_T_61_5(il[576]) - , poseidon2_T_61_6(il[577]) - , poseidon2_T_61_7(il[578]) - , poseidon2_T_62_4(il[579]) - , poseidon2_T_62_5(il[580]) - , poseidon2_T_62_6(il[581]) - , poseidon2_T_62_7(il[582]) - , poseidon2_T_63_4(il[583]) - , poseidon2_T_63_5(il[584]) - , poseidon2_T_63_6(il[585]) - , poseidon2_T_63_7(il[586]) - , poseidon2_a_0(il[587]) - , poseidon2_a_1(il[588]) - , poseidon2_a_2(il[589]) - , poseidon2_a_3(il[590]) - , poseidon2_b_0(il[591]) - , poseidon2_b_1(il[592]) - , poseidon2_b_2(il[593]) - , poseidon2_b_3(il[594]) - , poseidon2_clk(il[595]) - , poseidon2_full_a_0(il[596]) - , poseidon2_full_a_1(il[597]) - , poseidon2_full_a_2(il[598]) - , poseidon2_full_a_3(il[599]) - , poseidon2_full_b_0(il[600]) - , poseidon2_full_b_1(il[601]) - , poseidon2_full_b_2(il[602]) - , poseidon2_full_b_3(il[603]) - , poseidon2_full_clk(il[604]) - , poseidon2_full_end_poseidon(il[605]) - , poseidon2_full_execute_poseidon_perm(il[606]) - , poseidon2_full_input_0(il[607]) - , poseidon2_full_input_1(il[608]) - , poseidon2_full_input_2(il[609]) - , poseidon2_full_input_len(il[610]) - , poseidon2_full_num_perm_rounds_rem(il[611]) - , poseidon2_full_num_perm_rounds_rem_inv(il[612]) - , poseidon2_full_output(il[613]) - , poseidon2_full_padding(il[614]) - , poseidon2_full_sel_merkle_tree(il[615]) - , poseidon2_full_sel_poseidon(il[616]) - , poseidon2_full_start_poseidon(il[617]) - , poseidon2_input_addr(il[618]) - , poseidon2_mem_addr_read_a(il[619]) - , poseidon2_mem_addr_read_b(il[620]) - , poseidon2_mem_addr_read_c(il[621]) - , poseidon2_mem_addr_read_d(il[622]) - , poseidon2_mem_addr_write_a(il[623]) - , poseidon2_mem_addr_write_b(il[624]) - , poseidon2_mem_addr_write_c(il[625]) - , poseidon2_mem_addr_write_d(il[626]) - , poseidon2_output_addr(il[627]) - , poseidon2_sel_poseidon_perm(il[628]) - , poseidon2_sel_poseidon_perm_immediate(il[629]) - , poseidon2_sel_poseidon_perm_mem_op(il[630]) - , poseidon2_space_id(il[631]) - , range_check_alu_rng_chk(il[632]) - , range_check_clk(il[633]) - , range_check_cmp_hi_bits_rng_chk(il[634]) - , range_check_cmp_lo_bits_rng_chk(il[635]) - , range_check_cmp_non_ff_rng_chk(il[636]) - , range_check_dyn_diff(il[637]) - , range_check_dyn_rng_chk_bits(il[638]) - , range_check_dyn_rng_chk_pow_2(il[639]) - , range_check_gas_da_rng_chk(il[640]) - , range_check_gas_l2_rng_chk(il[641]) - , range_check_is_lte_u112(il[642]) - , range_check_is_lte_u128(il[643]) - , range_check_is_lte_u16(il[644]) - , range_check_is_lte_u32(il[645]) - , range_check_is_lte_u48(il[646]) - , range_check_is_lte_u64(il[647]) - , range_check_is_lte_u80(il[648]) - , range_check_is_lte_u96(il[649]) - , range_check_rng_chk_bits(il[650]) - , range_check_sel_lookup_0(il[651]) - , range_check_sel_lookup_1(il[652]) - , range_check_sel_lookup_2(il[653]) - , range_check_sel_lookup_3(il[654]) - , range_check_sel_lookup_4(il[655]) - , range_check_sel_lookup_5(il[656]) - , range_check_sel_lookup_6(il[657]) - , range_check_sel_rng_chk(il[658]) - , range_check_u16_r0(il[659]) - , range_check_u16_r1(il[660]) - , range_check_u16_r2(il[661]) - , range_check_u16_r3(il[662]) - , range_check_u16_r4(il[663]) - , range_check_u16_r5(il[664]) - , range_check_u16_r6(il[665]) - , range_check_u16_r7(il[666]) - , range_check_value(il[667]) - , sha256_clk(il[668]) - , sha256_input(il[669]) - , sha256_output(il[670]) - , sha256_sel_sha256_compression(il[671]) - , sha256_state(il[672]) - , slice_addr(il[673]) - , slice_clk(il[674]) - , slice_cnt(il[675]) - , slice_col_offset(il[676]) - , slice_one_min_inv(il[677]) - , slice_sel_cd_cpy(il[678]) - , slice_sel_mem_active(il[679]) - , slice_sel_return(il[680]) - , slice_sel_start(il[681]) - , slice_space_id(il[682]) - , slice_val(il[683]) - , lookup_rng_chk_pow_2_counts(il[684]) - , lookup_rng_chk_diff_counts(il[685]) - , lookup_rng_chk_0_counts(il[686]) - , lookup_rng_chk_1_counts(il[687]) - , lookup_rng_chk_2_counts(il[688]) - , lookup_rng_chk_3_counts(il[689]) - , lookup_rng_chk_4_counts(il[690]) - , lookup_rng_chk_5_counts(il[691]) - , lookup_rng_chk_6_counts(il[692]) - , lookup_rng_chk_7_counts(il[693]) - , lookup_mem_rng_chk_0_counts(il[694]) - , lookup_mem_rng_chk_1_counts(il[695]) - , lookup_mem_rng_chk_2_counts(il[696]) - , lookup_pow_2_0_counts(il[697]) - , lookup_pow_2_1_counts(il[698]) - , lookup_byte_lengths_counts(il[699]) - , lookup_byte_operations_counts(il[700]) - , lookup_opcode_gas_counts(il[701]) - , lookup_l2_gas_rng_chk_0_counts(il[702]) - , lookup_l2_gas_rng_chk_1_counts(il[703]) - , lookup_da_gas_rng_chk_0_counts(il[704]) - , lookup_da_gas_rng_chk_1_counts(il[705]) - , lookup_cd_value_counts(il[706]) - , lookup_ret_value_counts(il[707]) - , incl_main_tag_err_counts(il[708]) - , incl_mem_tag_err_counts(il[709]) - , perm_rng_non_ff_cmp_inv(il[710]) - , perm_rng_cmp_lo_inv(il[711]) - , perm_rng_cmp_hi_inv(il[712]) - , perm_rng_alu_inv(il[713]) - , perm_cmp_alu_inv(il[714]) - , perm_pos_mem_read_a_inv(il[715]) - , perm_pos_mem_read_b_inv(il[716]) - , perm_pos_mem_read_c_inv(il[717]) - , perm_pos_mem_read_d_inv(il[718]) - , perm_pos_mem_write_a_inv(il[719]) - , perm_pos_mem_write_b_inv(il[720]) - , perm_pos_mem_write_c_inv(il[721]) - , perm_pos_mem_write_d_inv(il[722]) - , perm_pos2_fixed_pos2_perm_inv(il[723]) - , perm_slice_mem_inv(il[724]) - , perm_merkle_poseidon2_inv(il[725]) - , perm_main_alu_inv(il[726]) - , perm_main_bin_inv(il[727]) - , perm_main_conv_inv(il[728]) - , perm_main_sha256_inv(il[729]) - , perm_main_pos2_perm_inv(il[730]) ->>>>>>> c8d4add49d (feat: nested call handling) - , perm_main_mem_a_inv(il[731]) - , perm_main_mem_b_inv(il[732]) - , perm_main_mem_c_inv(il[733]) - , perm_main_mem_d_inv(il[734]) - , perm_main_mem_ind_addr_a_inv(il[735]) - , perm_main_mem_ind_addr_b_inv(il[736]) - , perm_main_mem_ind_addr_c_inv(il[737]) - , perm_main_mem_ind_addr_d_inv(il[738]) - , lookup_rng_chk_pow_2_inv(il[739]) - , lookup_rng_chk_diff_inv(il[740]) - , lookup_rng_chk_0_inv(il[741]) - , lookup_rng_chk_1_inv(il[742]) - , lookup_rng_chk_2_inv(il[743]) - , lookup_rng_chk_3_inv(il[744]) - , lookup_rng_chk_4_inv(il[745]) - , lookup_rng_chk_5_inv(il[746]) - , lookup_rng_chk_6_inv(il[747]) - , lookup_rng_chk_7_inv(il[748]) - , lookup_mem_rng_chk_0_inv(il[749]) - , lookup_mem_rng_chk_1_inv(il[750]) - , lookup_mem_rng_chk_2_inv(il[751]) - , lookup_pow_2_0_inv(il[752]) - , lookup_pow_2_1_inv(il[753]) - , lookup_byte_lengths_inv(il[754]) - , lookup_byte_operations_inv(il[755]) - , lookup_opcode_gas_inv(il[756]) - , lookup_l2_gas_rng_chk_0_inv(il[757]) - , lookup_l2_gas_rng_chk_1_inv(il[758]) - , lookup_da_gas_rng_chk_0_inv(il[759]) - , lookup_da_gas_rng_chk_1_inv(il[760]) - , lookup_cd_value_inv(il[761]) - , lookup_ret_value_inv(il[762]) - , incl_main_tag_err_inv(il[763]) - , incl_mem_tag_err_inv(il[764]) - , binary_acc_ia_shift(il[765]) - , binary_acc_ib_shift(il[766]) - , binary_acc_ic_shift(il[767]) - , binary_mem_tag_ctr_shift(il[768]) - , binary_op_id_shift(il[769]) - , cmp_a_hi_shift(il[770]) - , cmp_a_lo_shift(il[771]) - , cmp_b_hi_shift(il[772]) - , cmp_b_lo_shift(il[773]) - , cmp_cmp_rng_ctr_shift(il[774]) - , cmp_op_gt_shift(il[775]) - , cmp_p_sub_a_hi_shift(il[776]) - , cmp_p_sub_a_lo_shift(il[777]) - , cmp_p_sub_b_hi_shift(il[778]) - , cmp_p_sub_b_lo_shift(il[779]) - , cmp_sel_rng_chk_shift(il[780]) - , main_da_gas_remaining_shift(il[781]) - , main_l2_gas_remaining_shift(il[782]) - , main_pc_shift(il[783]) - , main_sel_execution_end_shift(il[784]) - , main_sel_execution_row_shift(il[785]) - , mem_glob_addr_shift(il[786]) - , mem_rw_shift(il[787]) - , mem_sel_mem_shift(il[788]) - , mem_tag_shift(il[789]) - , mem_tsp_shift(il[790]) - , mem_val_shift(il[791]) - , merkle_tree_leaf_index_shift(il[792]) - , merkle_tree_leaf_value_shift(il[793]) - , merkle_tree_path_len_shift(il[794]) - , poseidon2_full_a_0_shift(il[795]) - , poseidon2_full_a_1_shift(il[796]) - , poseidon2_full_a_2_shift(il[797]) - , poseidon2_full_a_3_shift(il[798]) - , poseidon2_full_execute_poseidon_perm_shift(il[799]) - , poseidon2_full_input_0_shift(il[800]) - , poseidon2_full_input_1_shift(il[801]) - , poseidon2_full_input_2_shift(il[802]) - , poseidon2_full_num_perm_rounds_rem_shift(il[803]) - , poseidon2_full_sel_poseidon_shift(il[804]) - , poseidon2_full_start_poseidon_shift(il[805]) - , slice_addr_shift(il[806]) - , slice_clk_shift(il[807]) - , slice_cnt_shift(il[808]) - , slice_col_offset_shift(il[809]) - , slice_sel_cd_cpy_shift(il[810]) - , slice_sel_mem_active_shift(il[811]) - , slice_sel_return_shift(il[812]) - , slice_sel_start_shift(il[813]) - , slice_space_id_shift(il[814]) + , perm_main_mem_a_inv(il[730]) + , perm_main_mem_b_inv(il[731]) + , perm_main_mem_c_inv(il[732]) + , perm_main_mem_d_inv(il[733]) + , perm_main_mem_ind_addr_a_inv(il[734]) + , perm_main_mem_ind_addr_b_inv(il[735]) + , perm_main_mem_ind_addr_c_inv(il[736]) + , perm_main_mem_ind_addr_d_inv(il[737]) + , lookup_rng_chk_pow_2_inv(il[738]) + , lookup_rng_chk_diff_inv(il[739]) + , lookup_rng_chk_0_inv(il[740]) + , lookup_rng_chk_1_inv(il[741]) + , lookup_rng_chk_2_inv(il[742]) + , lookup_rng_chk_3_inv(il[743]) + , lookup_rng_chk_4_inv(il[744]) + , lookup_rng_chk_5_inv(il[745]) + , lookup_rng_chk_6_inv(il[746]) + , lookup_rng_chk_7_inv(il[747]) + , lookup_mem_rng_chk_0_inv(il[748]) + , lookup_mem_rng_chk_1_inv(il[749]) + , lookup_mem_rng_chk_2_inv(il[750]) + , lookup_pow_2_0_inv(il[751]) + , lookup_pow_2_1_inv(il[752]) + , lookup_byte_lengths_inv(il[753]) + , lookup_byte_operations_inv(il[754]) + , lookup_opcode_gas_inv(il[755]) + , lookup_l2_gas_rng_chk_0_inv(il[756]) + , lookup_l2_gas_rng_chk_1_inv(il[757]) + , lookup_da_gas_rng_chk_0_inv(il[758]) + , lookup_da_gas_rng_chk_1_inv(il[759]) + , lookup_cd_value_inv(il[760]) + , lookup_ret_value_inv(il[761]) + , incl_main_tag_err_inv(il[762]) + , incl_mem_tag_err_inv(il[763]) + , binary_acc_ia_shift(il[764]) + , binary_acc_ib_shift(il[765]) + , binary_acc_ic_shift(il[766]) + , binary_mem_tag_ctr_shift(il[767]) + , binary_op_id_shift(il[768]) + , cmp_a_hi_shift(il[769]) + , cmp_a_lo_shift(il[770]) + , cmp_b_hi_shift(il[771]) + , cmp_b_lo_shift(il[772]) + , cmp_cmp_rng_ctr_shift(il[773]) + , cmp_op_gt_shift(il[774]) + , cmp_p_sub_a_hi_shift(il[775]) + , cmp_p_sub_a_lo_shift(il[776]) + , cmp_p_sub_b_hi_shift(il[777]) + , cmp_p_sub_b_lo_shift(il[778]) + , cmp_sel_rng_chk_shift(il[779]) + , main_da_gas_remaining_shift(il[780]) + , main_l2_gas_remaining_shift(il[781]) + , main_pc_shift(il[782]) + , main_sel_execution_end_shift(il[783]) + , main_sel_execution_row_shift(il[784]) + , mem_glob_addr_shift(il[785]) + , mem_rw_shift(il[786]) + , mem_sel_mem_shift(il[787]) + , mem_tag_shift(il[788]) + , mem_tsp_shift(il[789]) + , mem_val_shift(il[790]) + , merkle_tree_leaf_index_shift(il[791]) + , merkle_tree_leaf_value_shift(il[792]) + , merkle_tree_path_len_shift(il[793]) + , poseidon2_full_a_0_shift(il[794]) + , poseidon2_full_a_1_shift(il[795]) + , poseidon2_full_a_2_shift(il[796]) + , poseidon2_full_a_3_shift(il[797]) + , poseidon2_full_execute_poseidon_perm_shift(il[798]) + , poseidon2_full_input_0_shift(il[799]) + , poseidon2_full_input_1_shift(il[800]) + , poseidon2_full_input_2_shift(il[801]) + , poseidon2_full_num_perm_rounds_rem_shift(il[802]) + , poseidon2_full_sel_poseidon_shift(il[803]) + , poseidon2_full_start_poseidon_shift(il[804]) + , slice_addr_shift(il[805]) + , slice_clk_shift(il[806]) + , slice_cnt_shift(il[807]) + , slice_col_offset_shift(il[808]) + , slice_sel_cd_cpy_shift(il[809]) + , slice_sel_mem_active_shift(il[810]) + , slice_sel_return_shift(il[811]) + , slice_sel_start_shift(il[812]) + , slice_space_id_shift(il[813]) {} AvmFlavor::ProverPolynomials::ProverPolynomials(ProvingKey& proving_key) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp index 735da35de12..ca55350407a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp @@ -95,20 +95,10 @@ template using tuple_cat_t = decltype(std::tuple_cat(std:: // The entities that will be used in the flavor. // clang-format off #define PRECOMPUTED_ENTITIES byte_lookup_sel_bin, byte_lookup_table_byte_lengths, byte_lookup_table_in_tags, byte_lookup_table_input_a, byte_lookup_table_input_b, byte_lookup_table_op_id, byte_lookup_table_output, gas_base_da_gas_fixed_table, gas_base_l2_gas_fixed_table, gas_dyn_da_gas_fixed_table, gas_dyn_l2_gas_fixed_table, gas_sel_gas_cost, main_clk, main_sel_da_end_gas_kernel_input, main_sel_da_start_gas_kernel_input, main_sel_first, main_sel_l2_end_gas_kernel_input, main_sel_l2_start_gas_kernel_input, main_sel_start_exec, main_zeroes, powers_power_of_2 -<<<<<<< HEAD #define WIRE_ENTITIES main_kernel_inputs, main_kernel_value_out, main_kernel_side_effect_out, main_kernel_metadata_out, main_calldata, main_returndata, alu_a_hi, alu_a_lo, alu_b_hi, alu_b_lo, alu_b_pow, alu_c_hi, alu_c_lo, alu_cf, alu_clk, alu_cmp_gadget_gt, alu_cmp_gadget_input_a, alu_cmp_gadget_input_b, alu_cmp_gadget_non_ff_gt, alu_cmp_gadget_result, alu_cmp_gadget_sel, alu_ff_tag, alu_ia, alu_ib, alu_ic, alu_in_tag, alu_max_bits_sub_b_bits, alu_max_bits_sub_b_pow, alu_op_add, alu_op_cast, alu_op_div, alu_op_eq, alu_op_lt, alu_op_lte, alu_op_mul, alu_op_not, alu_op_shl, alu_op_shr, alu_op_sub, alu_partial_prod_hi, alu_partial_prod_lo, alu_range_check_input_value, alu_range_check_num_bits, alu_range_check_sel, alu_remainder, alu_sel_alu, alu_sel_cmp, alu_sel_shift_which, alu_u128_tag, alu_u16_tag, alu_u1_tag, alu_u32_tag, alu_u64_tag, alu_u8_tag, alu_zero_shift, 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, bytecode_arifact_hash, bytecode_as_fields, bytecode_bytes, bytecode_bytes_pc, bytecode_class_id, bytecode_contract_address, bytecode_decomposed, bytecode_deployer_addr, bytecode_end_latch, bytecode_incoming_viewing_key_x, bytecode_incoming_viewing_key_y, bytecode_initialization_hash, bytecode_length_remaining, bytecode_nullifier_key_x, bytecode_nullifier_key_y, bytecode_outgoing_viewing_key_x, bytecode_outgoing_viewing_key_y, bytecode_private_fn_root, bytecode_public_key_hash, bytecode_running_hash, bytecode_salt, bytecode_tagging_key_x, bytecode_tagging_key_y, cmp_a_hi, cmp_a_lo, cmp_b_hi, cmp_b_lo, cmp_borrow, cmp_clk, cmp_cmp_rng_ctr, cmp_diff, cmp_input_a, cmp_input_b, cmp_op_eq, cmp_op_eq_diff_inv, cmp_op_gt, cmp_op_non_ff_gt, cmp_p_a_borrow, cmp_p_b_borrow, cmp_p_sub_a_hi, cmp_p_sub_a_lo, cmp_p_sub_b_hi, cmp_p_sub_b_lo, cmp_range_chk_clk, cmp_res_hi, cmp_res_lo, cmp_result, cmp_sel_cmp, cmp_sel_rng_chk, cmp_shift_sel, conversion_clk, conversion_input, conversion_num_limbs, conversion_output_bits, conversion_radix, conversion_sel_to_radix_be, keccakf1600_clk, keccakf1600_input, keccakf1600_output, keccakf1600_sel_keccakf1600, main_abs_da_rem_gas, main_abs_l2_rem_gas, main_alu_in_tag, main_base_da_gas_op_cost, main_base_l2_gas_op_cost, main_bin_op_id, main_call_ptr, main_da_gas_remaining, main_da_gas_u16_r0, main_da_gas_u16_r1, main_da_out_of_gas, main_dyn_da_gas_op_cost, main_dyn_gas_multiplier, main_dyn_l2_gas_op_cost, main_ia, main_ib, main_ic, main_id, main_id_zero, main_ind_addr_a, main_ind_addr_b, main_ind_addr_c, main_ind_addr_d, main_internal_return_ptr, main_inv, main_is_fake_row, main_is_gas_accounted, main_l2_gas_remaining, main_l2_gas_u16_r0, main_l2_gas_u16_r1, main_l2_out_of_gas, main_mem_addr_a, main_mem_addr_b, main_mem_addr_c, main_mem_addr_d, main_op_err, main_opcode_val, main_pc, main_r_in_tag, main_rwa, main_rwb, main_rwc, main_rwd, main_sel_alu, main_sel_bin, main_sel_calldata, main_sel_execution_end, main_sel_execution_row, 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_dagasleft, main_sel_op_debug_log, main_sel_op_div, main_sel_op_ecadd, main_sel_op_emit_l2_to_l1_msg, main_sel_op_emit_note_hash, main_sel_op_emit_nullifier, main_sel_op_emit_unencrypted_log, main_sel_op_eq, main_sel_op_external_call, main_sel_op_external_return, main_sel_op_external_revert, main_sel_op_fdiv, main_sel_op_fee_per_da_gas, main_sel_op_fee_per_l2_gas, main_sel_op_get_contract_instance, main_sel_op_internal_call, main_sel_op_internal_return, main_sel_op_is_static_call, main_sel_op_jump, main_sel_op_jumpi, main_sel_op_keccak, main_sel_op_l1_to_l2_msg_exists, main_sel_op_l2gasleft, main_sel_op_lt, main_sel_op_lte, main_sel_op_mov, main_sel_op_msm, main_sel_op_mul, main_sel_op_not, main_sel_op_note_hash_exists, main_sel_op_nullifier_exists, main_sel_op_or, main_sel_op_poseidon2, main_sel_op_radix_be, main_sel_op_returndata_copy, main_sel_op_returndata_size, main_sel_op_sender, main_sel_op_set, main_sel_op_sha256, main_sel_op_shl, main_sel_op_shr, main_sel_op_sload, main_sel_op_sstore, main_sel_op_static_call, 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, 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_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_u16_r0, mem_u16_r1, mem_u8_r0, mem_val, mem_w_in_tag, merkle_tree_clk, merkle_tree_expected_tree_root, merkle_tree_latch, merkle_tree_leaf_index, merkle_tree_leaf_index_is_even, merkle_tree_leaf_value, merkle_tree_left_hash, merkle_tree_output_hash, merkle_tree_path_len, merkle_tree_path_len_inv, merkle_tree_right_hash, merkle_tree_sel_merkle_tree, merkle_tree_sibling_value, 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_full_a_0, poseidon2_full_a_1, poseidon2_full_a_2, poseidon2_full_a_3, poseidon2_full_b_0, poseidon2_full_b_1, poseidon2_full_b_2, poseidon2_full_b_3, poseidon2_full_clk, poseidon2_full_end_poseidon, poseidon2_full_execute_poseidon_perm, poseidon2_full_input_0, poseidon2_full_input_1, poseidon2_full_input_2, poseidon2_full_input_len, poseidon2_full_num_perm_rounds_rem, poseidon2_full_num_perm_rounds_rem_inv, poseidon2_full_output, poseidon2_full_padding, poseidon2_full_sel_merkle_tree, poseidon2_full_sel_poseidon, poseidon2_full_start_poseidon, 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, poseidon2_sel_poseidon_perm_immediate, poseidon2_sel_poseidon_perm_mem_op, poseidon2_space_id, range_check_alu_rng_chk, range_check_clk, range_check_cmp_hi_bits_rng_chk, range_check_cmp_lo_bits_rng_chk, range_check_cmp_non_ff_rng_chk, range_check_dyn_diff, range_check_dyn_rng_chk_bits, range_check_dyn_rng_chk_pow_2, range_check_gas_da_rng_chk, range_check_gas_l2_rng_chk, range_check_is_lte_u112, range_check_is_lte_u128, range_check_is_lte_u16, range_check_is_lte_u32, range_check_is_lte_u48, range_check_is_lte_u64, range_check_is_lte_u80, range_check_is_lte_u96, range_check_rng_chk_bits, range_check_sel_lookup_0, range_check_sel_lookup_1, range_check_sel_lookup_2, range_check_sel_lookup_3, range_check_sel_lookup_4, range_check_sel_lookup_5, range_check_sel_lookup_6, range_check_sel_rng_chk, range_check_u16_r0, range_check_u16_r1, range_check_u16_r2, range_check_u16_r3, range_check_u16_r4, range_check_u16_r5, range_check_u16_r6, range_check_u16_r7, range_check_value, sha256_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_rng_chk_pow_2_counts, lookup_rng_chk_diff_counts, lookup_rng_chk_0_counts, lookup_rng_chk_1_counts, lookup_rng_chk_2_counts, lookup_rng_chk_3_counts, lookup_rng_chk_4_counts, lookup_rng_chk_5_counts, lookup_rng_chk_6_counts, lookup_rng_chk_7_counts, lookup_mem_rng_chk_0_counts, lookup_mem_rng_chk_1_counts, lookup_mem_rng_chk_2_counts, lookup_pow_2_0_counts, lookup_pow_2_1_counts, lookup_byte_lengths_counts, lookup_byte_operations_counts, lookup_opcode_gas_counts, lookup_l2_gas_rng_chk_0_counts, lookup_l2_gas_rng_chk_1_counts, lookup_da_gas_rng_chk_0_counts, lookup_da_gas_rng_chk_1_counts, lookup_cd_value_counts, lookup_ret_value_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts -#define DERIVED_WITNESS_ENTITIES perm_rng_non_ff_cmp_inv, perm_rng_cmp_lo_inv, perm_rng_cmp_hi_inv, perm_rng_alu_inv, perm_cmp_alu_inv, perm_pos_mem_read_a_inv, perm_pos_mem_read_b_inv, perm_pos_mem_read_c_inv, perm_pos_mem_read_d_inv, perm_pos_mem_write_a_inv, perm_pos_mem_write_b_inv, perm_pos_mem_write_c_inv, perm_pos_mem_write_d_inv, perm_pos2_fixed_pos2_perm_inv, perm_slice_mem_inv, perm_merkle_poseidon2_inv, perm_main_alu_inv, perm_main_bin_inv, perm_main_conv_inv, perm_main_sha256_inv, perm_main_pos2_perm_inv, perm_main_slice_inv, perm_main_mem_a_inv, perm_main_mem_b_inv, perm_main_mem_c_inv, perm_main_mem_d_inv, perm_main_mem_ind_addr_a_inv, perm_main_mem_ind_addr_b_inv, perm_main_mem_ind_addr_c_inv, perm_main_mem_ind_addr_d_inv, lookup_rng_chk_pow_2_inv, lookup_rng_chk_diff_inv, lookup_rng_chk_0_inv, lookup_rng_chk_1_inv, lookup_rng_chk_2_inv, lookup_rng_chk_3_inv, lookup_rng_chk_4_inv, lookup_rng_chk_5_inv, lookup_rng_chk_6_inv, lookup_rng_chk_7_inv, lookup_mem_rng_chk_0_inv, lookup_mem_rng_chk_1_inv, lookup_mem_rng_chk_2_inv, lookup_pow_2_0_inv, lookup_pow_2_1_inv, lookup_byte_lengths_inv, lookup_byte_operations_inv, lookup_opcode_gas_inv, lookup_l2_gas_rng_chk_0_inv, lookup_l2_gas_rng_chk_1_inv, lookup_da_gas_rng_chk_0_inv, lookup_da_gas_rng_chk_1_inv, lookup_cd_value_inv, lookup_ret_value_inv, incl_main_tag_err_inv, incl_mem_tag_err_inv -======= -#define WIRE_ENTITIES main_kernel_inputs, main_kernel_value_out, main_kernel_side_effect_out, main_kernel_metadata_out, main_calldata, main_returndata, alu_a_hi, alu_a_lo, alu_b_hi, alu_b_lo, alu_b_pow, alu_c_hi, alu_c_lo, alu_cf, alu_clk, alu_cmp_gadget_gt, alu_cmp_gadget_input_a, alu_cmp_gadget_input_b, alu_cmp_gadget_non_ff_gt, alu_cmp_gadget_result, alu_cmp_gadget_sel, alu_ff_tag, alu_ia, alu_ib, alu_ic, alu_in_tag, alu_max_bits_sub_b_bits, alu_max_bits_sub_b_pow, alu_op_add, alu_op_cast, alu_op_div, alu_op_eq, alu_op_lt, alu_op_lte, alu_op_mul, alu_op_not, alu_op_shl, alu_op_shr, alu_op_sub, alu_partial_prod_hi, alu_partial_prod_lo, alu_range_check_input_value, alu_range_check_num_bits, alu_range_check_sel, alu_remainder, alu_sel_alu, alu_sel_cmp, alu_sel_shift_which, alu_u128_tag, alu_u16_tag, alu_u1_tag, alu_u32_tag, alu_u64_tag, alu_u8_tag, alu_zero_shift, 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, bytecode_arifact_hash, bytecode_as_fields, bytecode_bytes, bytecode_bytes_pc, bytecode_class_id, bytecode_contract_address, bytecode_decomposed, bytecode_deployer_addr, bytecode_end_latch, bytecode_incoming_viewing_key_x, bytecode_incoming_viewing_key_y, bytecode_initialization_hash, bytecode_length_remaining, bytecode_nullifier_key_x, bytecode_nullifier_key_y, bytecode_outgoing_viewing_key_x, bytecode_outgoing_viewing_key_y, bytecode_private_fn_root, bytecode_public_key_hash, bytecode_running_hash, bytecode_salt, bytecode_tagging_key_x, bytecode_tagging_key_y, cmp_a_hi, cmp_a_lo, cmp_b_hi, cmp_b_lo, cmp_borrow, cmp_clk, cmp_cmp_rng_ctr, cmp_diff, cmp_input_a, cmp_input_b, cmp_op_eq, cmp_op_eq_diff_inv, cmp_op_gt, cmp_op_non_ff_gt, cmp_p_a_borrow, cmp_p_b_borrow, cmp_p_sub_a_hi, cmp_p_sub_a_lo, cmp_p_sub_b_hi, cmp_p_sub_b_lo, cmp_range_chk_clk, cmp_res_hi, cmp_res_lo, cmp_result, cmp_sel_cmp, cmp_sel_rng_chk, cmp_shift_sel, conversion_clk, conversion_input, conversion_num_limbs, conversion_output_bits, conversion_radix, conversion_sel_to_radix_be, keccakf1600_clk, keccakf1600_input, keccakf1600_output, keccakf1600_sel_keccakf1600, main_abs_da_rem_gas, main_abs_l2_rem_gas, main_alu_in_tag, main_base_da_gas_op_cost, main_base_l2_gas_op_cost, main_bin_op_id, main_call_ptr, main_da_gas_remaining, main_da_gas_u16_r0, main_da_gas_u16_r1, main_da_out_of_gas, main_dyn_da_gas_op_cost, main_dyn_gas_multiplier, main_dyn_l2_gas_op_cost, main_ia, main_ib, main_ic, main_id, main_id_zero, main_ind_addr_a, main_ind_addr_b, main_ind_addr_c, main_ind_addr_d, main_internal_return_ptr, main_inv, main_is_fake_row, main_is_gas_accounted, main_l2_gas_remaining, main_l2_gas_u16_r0, main_l2_gas_u16_r1, main_l2_out_of_gas, main_mem_addr_a, main_mem_addr_b, main_mem_addr_c, main_mem_addr_d, main_op_err, main_opcode_val, main_pc, main_r_in_tag, main_rwa, main_rwb, main_rwc, main_rwd, main_sel_alu, main_sel_bin, main_sel_calldata, main_sel_execution_end, main_sel_execution_row, 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_dagasleft, main_sel_op_debug_log, main_sel_op_div, main_sel_op_ecadd, main_sel_op_emit_l2_to_l1_msg, main_sel_op_emit_note_hash, main_sel_op_emit_nullifier, main_sel_op_emit_unencrypted_log, main_sel_op_eq, main_sel_op_external_call, main_sel_op_external_return, main_sel_op_external_revert, main_sel_op_fdiv, main_sel_op_fee_per_da_gas, main_sel_op_fee_per_l2_gas, main_sel_op_function_selector, main_sel_op_get_contract_instance, main_sel_op_internal_call, main_sel_op_internal_return, main_sel_op_is_static_call, main_sel_op_jump, main_sel_op_jumpi, main_sel_op_keccak, main_sel_op_l1_to_l2_msg_exists, main_sel_op_l2gasleft, main_sel_op_lt, main_sel_op_lte, main_sel_op_mov, main_sel_op_msm, main_sel_op_mul, main_sel_op_not, main_sel_op_note_hash_exists, main_sel_op_nullifier_exists, main_sel_op_or, main_sel_op_poseidon2, main_sel_op_radix_be, main_sel_op_returndata_copy, main_sel_op_returndata_size, main_sel_op_sender, main_sel_op_set, main_sel_op_sha256, main_sel_op_shl, main_sel_op_shr, main_sel_op_sload, main_sel_op_sstore, main_sel_op_static_call, 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, 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_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_u16_r0, mem_u16_r1, mem_u8_r0, mem_val, mem_w_in_tag, merkle_tree_clk, merkle_tree_expected_tree_root, merkle_tree_latch, merkle_tree_leaf_index, merkle_tree_leaf_index_is_even, merkle_tree_leaf_value, merkle_tree_left_hash, merkle_tree_output_hash, merkle_tree_path_len, merkle_tree_path_len_inv, merkle_tree_right_hash, merkle_tree_sel_merkle_tree, merkle_tree_sibling_value, 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_full_a_0, poseidon2_full_a_1, poseidon2_full_a_2, poseidon2_full_a_3, poseidon2_full_b_0, poseidon2_full_b_1, poseidon2_full_b_2, poseidon2_full_b_3, poseidon2_full_clk, poseidon2_full_end_poseidon, poseidon2_full_execute_poseidon_perm, poseidon2_full_input_0, poseidon2_full_input_1, poseidon2_full_input_2, poseidon2_full_input_len, poseidon2_full_num_perm_rounds_rem, poseidon2_full_num_perm_rounds_rem_inv, poseidon2_full_output, poseidon2_full_padding, poseidon2_full_sel_merkle_tree, poseidon2_full_sel_poseidon, poseidon2_full_start_poseidon, 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, poseidon2_sel_poseidon_perm_immediate, poseidon2_sel_poseidon_perm_mem_op, poseidon2_space_id, range_check_alu_rng_chk, range_check_clk, range_check_cmp_hi_bits_rng_chk, range_check_cmp_lo_bits_rng_chk, range_check_cmp_non_ff_rng_chk, range_check_dyn_diff, range_check_dyn_rng_chk_bits, range_check_dyn_rng_chk_pow_2, range_check_gas_da_rng_chk, range_check_gas_l2_rng_chk, range_check_is_lte_u112, range_check_is_lte_u128, range_check_is_lte_u16, range_check_is_lte_u32, range_check_is_lte_u48, range_check_is_lte_u64, range_check_is_lte_u80, range_check_is_lte_u96, range_check_rng_chk_bits, range_check_sel_lookup_0, range_check_sel_lookup_1, range_check_sel_lookup_2, range_check_sel_lookup_3, range_check_sel_lookup_4, range_check_sel_lookup_5, range_check_sel_lookup_6, range_check_sel_rng_chk, range_check_u16_r0, range_check_u16_r1, range_check_u16_r2, range_check_u16_r3, range_check_u16_r4, range_check_u16_r5, range_check_u16_r6, range_check_u16_r7, range_check_value, sha256_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_rng_chk_pow_2_counts, lookup_rng_chk_diff_counts, lookup_rng_chk_0_counts, lookup_rng_chk_1_counts, lookup_rng_chk_2_counts, lookup_rng_chk_3_counts, lookup_rng_chk_4_counts, lookup_rng_chk_5_counts, lookup_rng_chk_6_counts, lookup_rng_chk_7_counts, lookup_mem_rng_chk_0_counts, lookup_mem_rng_chk_1_counts, lookup_mem_rng_chk_2_counts, lookup_pow_2_0_counts, lookup_pow_2_1_counts, lookup_byte_lengths_counts, lookup_byte_operations_counts, lookup_opcode_gas_counts, lookup_l2_gas_rng_chk_0_counts, lookup_l2_gas_rng_chk_1_counts, lookup_da_gas_rng_chk_0_counts, lookup_da_gas_rng_chk_1_counts, lookup_cd_value_counts, lookup_ret_value_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts #define DERIVED_WITNESS_ENTITIES perm_rng_non_ff_cmp_inv, perm_rng_cmp_lo_inv, perm_rng_cmp_hi_inv, perm_rng_alu_inv, perm_cmp_alu_inv, perm_pos_mem_read_a_inv, perm_pos_mem_read_b_inv, perm_pos_mem_read_c_inv, perm_pos_mem_read_d_inv, perm_pos_mem_write_a_inv, perm_pos_mem_write_b_inv, perm_pos_mem_write_c_inv, perm_pos_mem_write_d_inv, perm_pos2_fixed_pos2_perm_inv, perm_slice_mem_inv, perm_merkle_poseidon2_inv, perm_main_alu_inv, perm_main_bin_inv, perm_main_conv_inv, perm_main_sha256_inv, perm_main_pos2_perm_inv, perm_main_mem_a_inv, perm_main_mem_b_inv, perm_main_mem_c_inv, perm_main_mem_d_inv, perm_main_mem_ind_addr_a_inv, perm_main_mem_ind_addr_b_inv, perm_main_mem_ind_addr_c_inv, perm_main_mem_ind_addr_d_inv, lookup_rng_chk_pow_2_inv, lookup_rng_chk_diff_inv, lookup_rng_chk_0_inv, lookup_rng_chk_1_inv, lookup_rng_chk_2_inv, lookup_rng_chk_3_inv, lookup_rng_chk_4_inv, lookup_rng_chk_5_inv, lookup_rng_chk_6_inv, lookup_rng_chk_7_inv, lookup_mem_rng_chk_0_inv, lookup_mem_rng_chk_1_inv, lookup_mem_rng_chk_2_inv, lookup_pow_2_0_inv, lookup_pow_2_1_inv, lookup_byte_lengths_inv, lookup_byte_operations_inv, lookup_opcode_gas_inv, lookup_l2_gas_rng_chk_0_inv, lookup_l2_gas_rng_chk_1_inv, lookup_da_gas_rng_chk_0_inv, lookup_da_gas_rng_chk_1_inv, lookup_cd_value_inv, lookup_ret_value_inv, incl_main_tag_err_inv, incl_mem_tag_err_inv -<<<<<<< HEAD ->>>>>>> c8d4add49d (feat: nested call handling) -#define SHIFTED_ENTITIES binary_acc_ia_shift, binary_acc_ib_shift, binary_acc_ic_shift, binary_mem_tag_ctr_shift, binary_op_id_shift, cmp_a_hi_shift, cmp_a_lo_shift, cmp_b_hi_shift, cmp_b_lo_shift, cmp_cmp_rng_ctr_shift, cmp_op_gt_shift, cmp_p_sub_a_hi_shift, cmp_p_sub_a_lo_shift, cmp_p_sub_b_hi_shift, cmp_p_sub_b_lo_shift, cmp_sel_rng_chk_shift, main_da_gas_remaining_shift, main_internal_return_ptr_shift, main_l2_gas_remaining_shift, main_pc_shift, main_sel_execution_end_shift, main_sel_execution_row_shift, mem_glob_addr_shift, mem_rw_shift, mem_sel_mem_shift, mem_tag_shift, mem_tsp_shift, mem_val_shift, merkle_tree_leaf_index_shift, merkle_tree_leaf_value_shift, merkle_tree_path_len_shift, poseidon2_full_a_0_shift, poseidon2_full_a_1_shift, poseidon2_full_a_2_shift, poseidon2_full_a_3_shift, poseidon2_full_execute_poseidon_perm_shift, poseidon2_full_input_0_shift, poseidon2_full_input_1_shift, poseidon2_full_input_2_shift, poseidon2_full_num_perm_rounds_rem_shift, poseidon2_full_sel_poseidon_shift, poseidon2_full_start_poseidon_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.binary_acc_ia, e.binary_acc_ib, e.binary_acc_ic, e.binary_mem_tag_ctr, e.binary_op_id, e.cmp_a_hi, e.cmp_a_lo, e.cmp_b_hi, e.cmp_b_lo, e.cmp_cmp_rng_ctr, e.cmp_op_gt, e.cmp_p_sub_a_hi, e.cmp_p_sub_a_lo, e.cmp_p_sub_b_hi, e.cmp_p_sub_b_lo, e.cmp_sel_rng_chk, e.main_da_gas_remaining, e.main_internal_return_ptr, e.main_l2_gas_remaining, e.main_pc, e.main_sel_execution_end, e.main_sel_execution_row, e.mem_glob_addr, e.mem_rw, e.mem_sel_mem, e.mem_tag, e.mem_tsp, e.mem_val, e.merkle_tree_leaf_index, e.merkle_tree_leaf_value, e.merkle_tree_path_len, e.poseidon2_full_a_0, e.poseidon2_full_a_1, e.poseidon2_full_a_2, e.poseidon2_full_a_3, e.poseidon2_full_execute_poseidon_perm, e.poseidon2_full_input_0, e.poseidon2_full_input_1, e.poseidon2_full_input_2, e.poseidon2_full_num_perm_rounds_rem, e.poseidon2_full_sel_poseidon, e.poseidon2_full_start_poseidon, e.slice_addr, e.slice_clk, e.slice_cnt, e.slice_col_offset, e.slice_sel_cd_cpy, e.slice_sel_mem_active, e.slice_sel_return, e.slice_sel_start, e.slice_space_id -======= #define SHIFTED_ENTITIES binary_acc_ia_shift, binary_acc_ib_shift, binary_acc_ic_shift, binary_mem_tag_ctr_shift, binary_op_id_shift, cmp_a_hi_shift, cmp_a_lo_shift, cmp_b_hi_shift, cmp_b_lo_shift, cmp_cmp_rng_ctr_shift, cmp_op_gt_shift, cmp_p_sub_a_hi_shift, cmp_p_sub_a_lo_shift, cmp_p_sub_b_hi_shift, cmp_p_sub_b_lo_shift, cmp_sel_rng_chk_shift, main_da_gas_remaining_shift, main_l2_gas_remaining_shift, main_pc_shift, main_sel_execution_end_shift, main_sel_execution_row_shift, mem_glob_addr_shift, mem_rw_shift, mem_sel_mem_shift, mem_tag_shift, mem_tsp_shift, mem_val_shift, merkle_tree_leaf_index_shift, merkle_tree_leaf_value_shift, merkle_tree_path_len_shift, poseidon2_full_a_0_shift, poseidon2_full_a_1_shift, poseidon2_full_a_2_shift, poseidon2_full_a_3_shift, poseidon2_full_execute_poseidon_perm_shift, poseidon2_full_input_0_shift, poseidon2_full_input_1_shift, poseidon2_full_input_2_shift, poseidon2_full_num_perm_rounds_rem_shift, poseidon2_full_sel_poseidon_shift, poseidon2_full_start_poseidon_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.binary_acc_ia, e.binary_acc_ib, e.binary_acc_ic, e.binary_mem_tag_ctr, e.binary_op_id, e.cmp_a_hi, e.cmp_a_lo, e.cmp_b_hi, e.cmp_b_lo, e.cmp_cmp_rng_ctr, e.cmp_op_gt, e.cmp_p_sub_a_hi, e.cmp_p_sub_a_lo, e.cmp_p_sub_b_hi, e.cmp_p_sub_b_lo, e.cmp_sel_rng_chk, e.main_da_gas_remaining, e.main_l2_gas_remaining, e.main_pc, e.main_sel_execution_end, e.main_sel_execution_row, e.mem_glob_addr, e.mem_rw, e.mem_sel_mem, e.mem_tag, e.mem_tsp, e.mem_val, e.merkle_tree_leaf_index, e.merkle_tree_leaf_value, e.merkle_tree_path_len, e.poseidon2_full_a_0, e.poseidon2_full_a_1, e.poseidon2_full_a_2, e.poseidon2_full_a_3, e.poseidon2_full_execute_poseidon_perm, e.poseidon2_full_input_0, e.poseidon2_full_input_1, e.poseidon2_full_input_2, e.poseidon2_full_num_perm_rounds_rem, e.poseidon2_full_sel_poseidon, e.poseidon2_full_start_poseidon, 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 ->>>>>>> 8e18d2694f (feat: get nested calls working) #define ALL_ENTITIES PRECOMPUTED_ENTITIES, WIRE_ENTITIES, DERIVED_WITNESS_ENTITIES, SHIFTED_ENTITIES // clang-format on @@ -134,12 +124,12 @@ class AvmFlavor { static constexpr bool HasZK = false; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 21; - static constexpr size_t NUM_WITNESS_ENTITIES = 744; + static constexpr size_t NUM_WITNESS_ENTITIES = 743; static constexpr size_t NUM_SHIFTED_ENTITIES = 50; 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 = 815; + static constexpr size_t NUM_ALL_ENTITIES = 814; // The total number of witnesses including shifts and derived entities. static constexpr size_t NUM_ALL_WITNESS_ENTITIES = NUM_WITNESS_ENTITIES + NUM_SHIFTED_ENTITIES; 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 29735d5164e..8da7a889d75 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp @@ -778,7 +778,7 @@ template struct AvmFullRow { RefVector as_vector() const; static std::vector names(); - static constexpr size_t SIZE = 765; + static constexpr size_t SIZE = 764; }; 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 1428daf5208..d493e1604f7 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp @@ -10,23 +10,10 @@ template class mainImpl { public: using FF = FF_; -<<<<<<< HEAD - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { - 2, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, -<<<<<<< HEAD - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 4, 3, 3, 3, 3, 4, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 2, 3 -======= - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 4, 3, 3, 3, 3, - 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3 ->>>>>>> c8d4add49d (feat: nested call handling) -======= - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { 2, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 4, 3, 3, 3, 3, 4, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3 ->>>>>>> 8e18d2694f (feat: get nested calls working) + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 4, 3, 3, 3, 3, 4, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3 }; template @@ -613,240 +600,91 @@ template class mainImpl { } { using Accumulator = typename std::tuple_element_t<84, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_call * - (new_term.main_internal_return_ptr_shift - (new_term.main_internal_return_ptr + FF(1)))); + auto tmp = (((FF(1) - new_term.main_sel_op_internal_call) - new_term.main_sel_op_internal_return) * + (new_term.main_call_ptr - new_term.main_space_id)); tmp *= scaling_factor; std::get<84>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<85, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = - (new_term.main_sel_op_internal_call * (new_term.main_internal_return_ptr - new_term.main_mem_addr_b)); -======= - auto tmp = (((FF(1) - new_term.main_sel_op_internal_call) - new_term.main_sel_op_internal_return) * - (new_term.main_call_ptr - new_term.main_space_id)); ->>>>>>> 8e18d2694f (feat: get nested calls working) + auto tmp = (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<85>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<86, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_pc_shift - new_term.main_ia)); -======= - auto tmp = (new_term.main_sel_op_jumpi * - (((new_term.main_id * new_term.main_inv) - FF(1)) + new_term.main_id_zero)); ->>>>>>> 8e18d2694f (feat: get nested calls working) + auto tmp = ((new_term.main_sel_op_jumpi * new_term.main_id_zero) * (FF(1) - new_term.main_inv)); tmp *= scaling_factor; std::get<86>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<87, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = (new_term.main_sel_op_internal_call * ((new_term.main_pc + FF(5)) - new_term.main_ib)); -======= - auto tmp = ((new_term.main_sel_op_jumpi * new_term.main_id_zero) * (FF(1) - new_term.main_inv)); ->>>>>>> 8e18d2694f (feat: get nested calls working) + auto tmp = (new_term.main_sel_mov_ia_to_ic - (new_term.main_sel_op_mov * (FF(1) - new_term.main_id_zero))); tmp *= scaling_factor; std::get<87>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<88, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_rwb - FF(1))); -======= - auto tmp = (new_term.main_sel_mov_ia_to_ic - (new_term.main_sel_op_mov * (FF(1) - new_term.main_id_zero))); ->>>>>>> 8e18d2694f (feat: get nested calls working) + auto tmp = (new_term.main_sel_mov_ia_to_ic * (new_term.main_ia - new_term.main_ic)); tmp *= scaling_factor; std::get<88>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<89, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_sel_mem_op_b - FF(1))); -======= - auto tmp = (new_term.main_sel_mov_ia_to_ic * (new_term.main_ia - new_term.main_ic)); ->>>>>>> 8e18d2694f (feat: get nested calls working) + auto tmp = (new_term.main_sel_mov_ib_to_ic * (new_term.main_ib - new_term.main_ic)); tmp *= scaling_factor; std::get<89>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<90, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = (new_term.main_sel_op_internal_return * - (new_term.main_internal_return_ptr_shift - (new_term.main_internal_return_ptr - FF(1)))); -======= - auto tmp = (new_term.main_sel_mov_ib_to_ic * (new_term.main_ib - new_term.main_ic)); ->>>>>>> 8e18d2694f (feat: get nested calls working) + auto tmp = (new_term.main_sel_op_mov * (new_term.main_r_in_tag - new_term.main_w_in_tag)); tmp *= scaling_factor; std::get<90>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<91, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = (new_term.main_sel_op_internal_return * - ((new_term.main_internal_return_ptr - FF(1)) - new_term.main_mem_addr_a)); -======= - auto tmp = (new_term.main_sel_op_mov * (new_term.main_r_in_tag - new_term.main_w_in_tag)); ->>>>>>> 8e18d2694f (feat: get nested calls working) + auto tmp = (new_term.main_sel_alu - (main_SEL_ALL_ALU * (FF(1) - new_term.main_op_err))); tmp *= scaling_factor; std::get<91>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<92, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = (new_term.main_sel_op_internal_return * (new_term.main_pc_shift - new_term.main_ia)); -======= - auto tmp = (new_term.main_sel_alu - (main_SEL_ALL_ALU * (FF(1) - new_term.main_op_err))); ->>>>>>> 8e18d2694f (feat: get nested calls working) + auto tmp = (main_SEL_ALU_R_TAG * (new_term.main_alu_in_tag - new_term.main_r_in_tag)); tmp *= scaling_factor; std::get<92>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<93, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = (new_term.main_sel_op_internal_return * new_term.main_rwa); -======= - auto tmp = (main_SEL_ALU_R_TAG * (new_term.main_alu_in_tag - new_term.main_r_in_tag)); ->>>>>>> 8e18d2694f (feat: get nested calls working) + auto tmp = (main_SEL_ALU_W_TAG * (new_term.main_alu_in_tag - new_term.main_w_in_tag)); tmp *= scaling_factor; std::get<93>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<94, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = (new_term.main_sel_op_internal_return * (new_term.main_sel_mem_op_a - FF(1))); -======= - auto tmp = (main_SEL_ALU_W_TAG * (new_term.main_alu_in_tag - new_term.main_w_in_tag)); ->>>>>>> 8e18d2694f (feat: get nested calls working) + auto tmp = (new_term.main_sel_op_l2gasleft * (new_term.main_ia - new_term.main_l2_gas_remaining_shift)); tmp *= scaling_factor; std::get<94>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<95, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = ((main_CUR_AND_NEXT_ARE_MAIN * (FF(1) - main_SEL_ALL_CTRL_FLOW)) * - (new_term.main_internal_return_ptr_shift - new_term.main_internal_return_ptr)); -======= - auto tmp = (new_term.main_sel_op_l2gasleft * (new_term.main_ia - new_term.main_l2_gas_remaining_shift)); ->>>>>>> 8e18d2694f (feat: get nested calls working) + auto tmp = (new_term.main_sel_op_dagasleft * (new_term.main_ia - new_term.main_da_gas_remaining_shift)); tmp *= scaling_factor; std::get<95>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<96, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = ((new_term.main_sel_op_internal_call + new_term.main_sel_op_internal_return) * - (new_term.main_space_id - constants_misc_INTERNAL_CALL_SPACE_ID)); -======= - auto tmp = (new_term.main_sel_op_dagasleft * (new_term.main_ia - new_term.main_da_gas_remaining_shift)); ->>>>>>> 8e18d2694f (feat: get nested calls working) + auto tmp = (new_term.main_bin_op_id - (new_term.main_sel_op_or + (FF(2) * new_term.main_sel_op_xor))); tmp *= scaling_factor; std::get<96>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<97, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = (((FF(1) - new_term.main_sel_op_internal_call) - new_term.main_sel_op_internal_return) * - (new_term.main_call_ptr - new_term.main_space_id)); -======= - auto tmp = (new_term.main_bin_op_id - (new_term.main_sel_op_or + (FF(2) * new_term.main_sel_op_xor))); ->>>>>>> 8e18d2694f (feat: get nested calls working) - tmp *= scaling_factor; - std::get<97>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<98, ContainerOverSubrelations>; -<<<<<<< HEAD - auto tmp = (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<98>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<99, ContainerOverSubrelations>; - auto tmp = ((new_term.main_sel_op_jumpi * new_term.main_id_zero) * (FF(1) - new_term.main_inv)); - 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_mov_ia_to_ic - (new_term.main_sel_op_mov * (FF(1) - new_term.main_id_zero))); - tmp *= scaling_factor; - std::get<100>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<101, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mov_ia_to_ic * (new_term.main_ia - new_term.main_ic)); - tmp *= scaling_factor; - std::get<101>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<102, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mov_ib_to_ic * (new_term.main_ib - new_term.main_ic)); - tmp *= scaling_factor; - std::get<102>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<103, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_mov * (new_term.main_r_in_tag - new_term.main_w_in_tag)); - tmp *= scaling_factor; - std::get<103>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<104, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_alu - (main_SEL_ALL_ALU * (FF(1) - new_term.main_op_err))); - tmp *= scaling_factor; - std::get<104>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<105, ContainerOverSubrelations>; - auto tmp = (main_SEL_ALU_R_TAG * (new_term.main_alu_in_tag - new_term.main_r_in_tag)); - tmp *= scaling_factor; - std::get<105>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<106, ContainerOverSubrelations>; - auto tmp = (main_SEL_ALU_W_TAG * (new_term.main_alu_in_tag - new_term.main_w_in_tag)); - tmp *= scaling_factor; - std::get<106>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<107, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_l2gasleft * (new_term.main_ia - new_term.main_l2_gas_remaining_shift)); - tmp *= scaling_factor; - std::get<107>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<108, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_dagasleft * (new_term.main_ia - new_term.main_da_gas_remaining_shift)); - tmp *= scaling_factor; - std::get<108>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<109, ContainerOverSubrelations>; - auto tmp = ((new_term.main_ib * (FF(1) - new_term.main_op_err)) * - ((new_term.main_sel_op_calldata_copy + new_term.main_sel_op_external_return) - - new_term.main_sel_slice_gadget)); - tmp *= scaling_factor; - std::get<109>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<110, ContainerOverSubrelations>; - auto tmp = (new_term.main_bin_op_id - (new_term.main_sel_op_or + (FF(2) * new_term.main_sel_op_xor))); - tmp *= scaling_factor; - std::get<110>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<111, ContainerOverSubrelations>; -======= ->>>>>>> 8e18d2694f (feat: get nested calls working) 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) * (FF(1) - new_term.main_op_err))); tmp *= scaling_factor; - std::get<98>(evals) += typename Accumulator::View(tmp); + std::get<97>(evals) += typename Accumulator::View(tmp); } } }; @@ -878,51 +716,25 @@ template class main : public Relation> { return "PC_JUMP"; case 83: return "PC_JUMPI"; -<<<<<<< HEAD case 84: - return "RETURN_POINTER_INCREMENT"; - case 90: - return "RETURN_POINTER_DECREMENT"; - case 95: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; - case 96: - return "SPACE_ID_INTERNAL"; - case 97: return "SPACE_ID_STANDARD_OPCODES"; - case 98: - return "JMP_CONDITION_RES_1"; - case 99: - return "JMP_CONDITION_RES_2"; - case 101: - return "MOV_SAME_VALUE_A"; - case 102: - return "MOV_SAME_VALUE_B"; - case 103: - return "MOV_MAIN_SAME_TAG"; - case 107: - return "L2GASLEFT"; - case 108: -======= case 85: - return "SPACE_ID_STANDARD_OPCODES"; - case 86: return "JMP_CONDITION_RES_1"; - case 87: + case 86: return "JMP_CONDITION_RES_2"; - case 89: + case 88: return "MOV_SAME_VALUE_A"; - case 90: + case 89: return "MOV_SAME_VALUE_B"; - case 91: + case 90: return "MOV_MAIN_SAME_TAG"; - case 95: + case 94: return "L2GASLEFT"; - case 96: ->>>>>>> 8e18d2694f (feat: get nested calls working) + case 95: return "DAGASLEFT"; - case 97: + case 96: return "BIN_SEL_1"; - case 98: + case 97: return "BIN_SEL_2"; } return std::to_string(index); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp index 57227bb8dab..c7247f64871 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp @@ -165,6 +165,12 @@ std::vector AvmTraceBuilder::get_bytecode(const FF contract_address, bo bool exists = true; if (check_membership && !isCanonical(contract_address)) { + if (bytecode_membership_cache.find(contract_address) != bytecode_membership_cache.end()) { + // If we have already seen the contract address, we can skip the membership check and used the cached + // membership proof + vinfo("Found bytecode for contract address in cache: ", contract_address); + return bytecode_hint.bytecode; + } const auto contract_address_nullifier = AvmMerkleTreeTraceBuilder::unconstrained_silo_nullifier( DEPLOYER_CONTRACT_ADDRESS, /*nullifier=*/contract_address); // nullifier read hint for the contract address @@ -185,6 +191,7 @@ std::vector AvmTraceBuilder::get_bytecode(const FF contract_address, bo // This was a membership proof! // Assert that the hint's exists flag matches. The flag isn't really necessary... ASSERT(bytecode_hint.contract_instance.exists); + bytecode_membership_cache.insert(contract_address); } else { // This was a non-membership proof! // Enforce that the tree access membership checked a low-leaf that skips the contract address nullifier. @@ -2863,18 +2870,6 @@ AvmError AvmTraceBuilder::op_emit_note_hash(uint8_t indirect, uint32_t note_hash row.main_sel_op_emit_note_hash = FF(1); row.main_op_err = FF(static_cast(!is_ok(error))); - AppendTreeHint note_hash_write_hint = execution_hints.note_hash_write_hints.at(note_hash_write_counter++); - auto siloed_note_hash = - AvmMerkleTreeTraceBuilder::unconstrained_silo_note_hash(current_ext_call_ctx.contract_address, row.main_ia); - ASSERT(row.main_ia == note_hash_write_hint.leaf_value); - // We first check that the index is currently empty - bool insert_index_is_empty = merkle_tree_trace_builder.perform_note_hash_read( - clk, FF::zero(), note_hash_write_hint.leaf_index, note_hash_write_hint.sibling_path); - ASSERT(insert_index_is_empty); - - // Update the root with the new leaf that is appended - merkle_tree_trace_builder.perform_note_hash_append(clk, siloed_note_hash, note_hash_write_hint.sibling_path); - AppendTreeHint note_hash_write_hint = execution_hints.note_hash_write_hints.at(note_hash_write_counter++); auto siloed_note_hash = AvmMerkleTreeTraceBuilder::unconstrained_silo_note_hash( current_public_call_request.contract_address, row.main_ia); diff --git a/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp b/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp index b5d162e80ce..23b1cfc86f1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp @@ -48,7 +48,7 @@ #define AVM_ACCUMULATED_DATA_LENGTH 318 #define AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH 1006 #define AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS 86 -#define AVM_PROOF_LENGTH_IN_FIELDS 4160 +#define AVM_PROOF_LENGTH_IN_FIELDS 4155 #define AVM_PUBLIC_COLUMN_MAX_SIZE 1024 #define AVM_PUBLIC_INPUTS_FLATTENED_SIZE 2915 #define MEM_TAG_FF 0 diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 75739f90db6..aee6a3d9127 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -502,7 +502,7 @@ pub global AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 2 + 21 * 4; // `AVM_PROOF_LENGTH_IN_FIELDS` must be updated when AVM circuit changes. // To determine latest value, hover `COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS` // in barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp -pub global AVM_PROOF_LENGTH_IN_FIELDS: u32 = 4160; +pub global AVM_PROOF_LENGTH_IN_FIELDS: u32 = 4155; pub global AVM_PUBLIC_COLUMN_MAX_SIZE: u32 = 1024; pub global AVM_PUBLIC_INPUTS_FLATTENED_SIZE: u32 = 2 * AVM_PUBLIC_COLUMN_MAX_SIZE + PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH; diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index c27d24a57f1..63d2e2779d2 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -220,7 +220,7 @@ export const TUBE_PROOF_LENGTH = 463; export const HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS = 128; export const CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS = 143; export const AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS = 86; -export const AVM_PROOF_LENGTH_IN_FIELDS = 4160; +export const AVM_PROOF_LENGTH_IN_FIELDS = 4155; export const AVM_PUBLIC_COLUMN_MAX_SIZE = 1024; export const AVM_PUBLIC_INPUTS_FLATTENED_SIZE = 2915; export const MEM_TAG_FF = 0; diff --git a/yarn-project/simulator/src/avm/avm_simulator.test.ts b/yarn-project/simulator/src/avm/avm_simulator.test.ts index 78b7e22d61c..fced3916963 100644 --- a/yarn-project/simulator/src/avm/avm_simulator.test.ts +++ b/yarn-project/simulator/src/avm/avm_simulator.test.ts @@ -864,9 +864,9 @@ describe('AVM simulator: transpiled Noir contracts', () => { mockGetContractInstance(worldStateDB, contractInstanceWithAddress); mockGetContractInstance(worldStateDB, contractInstanceWithAddress); mockGetContractInstance(worldStateDB, contractInstanceWithAddress); - mockNullifierExists(worldStateDB, contractInstanceWithAddress.address.toField()); - mockNullifierExists(worldStateDB, contractInstanceWithAddress.address.toField()); - mockNullifierExists(worldStateDB, contractInstanceWithAddress.address.toField()); + mockNullifierExists(worldStateDB, siloAddress(contractInstanceWithAddress.address)); + mockNullifierExists(worldStateDB, siloAddress(contractInstanceWithAddress.address)); + mockNullifierExists(worldStateDB, siloAddress(contractInstanceWithAddress.address)); const bytecode = getAvmTestContractBytecode('test_get_contract_instance'); @@ -935,7 +935,7 @@ describe('AVM simulator: transpiled Noir contracts', () => { mockGetContractClass(worldStateDB, contractClass); const contractInstance = makeContractInstanceFromClassId(contractClass.id); mockGetContractInstance(worldStateDB, contractInstance); - mockNullifierExists(worldStateDB, contractInstance.address.toField()); + mockNullifierExists(worldStateDB, siloAddress(contractInstance.address)); const nestedTrace = mock(); mockTraceFork(trace, nestedTrace); @@ -961,7 +961,7 @@ describe('AVM simulator: transpiled Noir contracts', () => { mockGetContractClass(worldStateDB, contractClass); const contractInstance = makeContractInstanceFromClassId(contractClass.id); mockGetContractInstance(worldStateDB, contractInstance); - mockNullifierExists(worldStateDB, contractInstance.address.toField()); + mockNullifierExists(worldStateDB, siloAddress(contractInstance.address)); const nestedTrace = mock(); mockTraceFork(trace, nestedTrace); @@ -990,7 +990,7 @@ describe('AVM simulator: transpiled Noir contracts', () => { mockGetContractClass(worldStateDB, contractClass); const contractInstance = makeContractInstanceFromClassId(contractClass.id); mockGetContractInstance(worldStateDB, contractInstance); - mockNullifierExists(worldStateDB, contractInstance.address.toField()); + mockNullifierExists(worldStateDB, siloAddress(contractInstance.address)); mockTraceFork(trace); @@ -1015,7 +1015,7 @@ describe('AVM simulator: transpiled Noir contracts', () => { mockGetContractClass(worldStateDB, contractClass); const contractInstance = makeContractInstanceFromClassId(contractClass.id); mockGetContractInstance(worldStateDB, contractInstance); - mockNullifierExists(worldStateDB, contractInstance.address.toField()); + mockNullifierExists(worldStateDB, siloAddress(contractInstance.address)); const nestedTrace = mock(); mockTraceFork(trace, nestedTrace); @@ -1047,7 +1047,7 @@ describe('AVM simulator: transpiled Noir contracts', () => { mockGetContractClass(worldStateDB, contractClass); const contractInstance = makeContractInstanceFromClassId(contractClass.id); mockGetContractInstance(worldStateDB, contractInstance); - mockNullifierExists(worldStateDB, contractInstance.address.toField()); + mockNullifierExists(worldStateDB, siloAddress(contractInstance.address)); mockTraceFork(trace); @@ -1072,7 +1072,7 @@ describe('AVM simulator: transpiled Noir contracts', () => { mockGetContractClass(worldStateDB, contractClass); const contractInstance = makeContractInstanceFromClassId(contractClass.id); mockGetContractInstance(worldStateDB, contractInstance); - mockNullifierExists(worldStateDB, contractInstance.address.toField()); + mockNullifierExists(worldStateDB, siloAddress(contractInstance.address)); mockTraceFork(trace); diff --git a/yarn-project/simulator/src/avm/journal/journal.ts b/yarn-project/simulator/src/avm/journal/journal.ts index 64529ea9f8a..7d27597a30e 100644 --- a/yarn-project/simulator/src/avm/journal/journal.ts +++ b/yarn-project/simulator/src/avm/journal/journal.ts @@ -1,17 +1,17 @@ import { MerkleTreeId } from '@aztec/circuit-types'; import { - AztecAddress, - CANONICAL_AUTH_REGISTRY_ADDRESS, - DEPLOYER_CONTRACT_ADDRESS, - FEE_JUICE_ADDRESS, - type Gas, - MULTI_CALL_ENTRYPOINT_ADDRESS, - NullifierLeafPreimage, - type PublicCallRequest, - type PublicDataTreeLeafPreimage, - REGISTERER_CONTRACT_ADDRESS, - ROUTER_ADDRESS, - SerializableContractInstance, + AztecAddress, + CANONICAL_AUTH_REGISTRY_ADDRESS, + DEPLOYER_CONTRACT_ADDRESS, + FEE_JUICE_ADDRESS, + type Gas, + MULTI_CALL_ENTRYPOINT_ADDRESS, + NullifierLeafPreimage, + type PublicCallRequest, + type PublicDataTreeLeafPreimage, + REGISTERER_CONTRACT_ADDRESS, + ROUTER_ADDRESS, + SerializableContractInstance, } from '@aztec/circuits.js'; import { computePublicDataTreeLeafSlot, siloNoteHash, siloNullifier } from '@aztec/circuits.js/hash'; import { Fr } from '@aztec/foundation/fields'; @@ -39,688 +39,682 @@ import { PublicStorage } from './public_storage.js'; * Manages merging of successful/reverted child state into current state. */ export class AvmPersistableStateManager { - private readonly log = createDebugLogger('aztec:avm_simulator:state_manager'); - - /** Make sure a forked state is never merged twice. */ - private alreadyMergedIntoParent = false; - - constructor( - /** Reference to node storage */ - private readonly worldStateDB: WorldStateDB, - /** Side effect trace */ - // TODO(5818): make private once no longer accessed in executor - public readonly trace: PublicSideEffectTraceInterface, - /** Public storage, including cached writes */ - private readonly publicStorage: PublicStorage = new PublicStorage(worldStateDB), - /** Nullifier set, including cached/recently-emitted nullifiers */ - private readonly nullifiers: NullifierManager = new NullifierManager(worldStateDB), - private readonly doMerkleOperations: boolean = false, - /** Ephmeral forest for merkle tree operations */ - public merkleTrees: AvmEphemeralForest, - ) { } - - /** - * Create a new state manager with some preloaded pending siloed nullifiers - */ - public static async newWithPendingSiloedNullifiers( - worldStateDB: WorldStateDB, - trace: PublicSideEffectTraceInterface, - pendingSiloedNullifiers: Fr[], - doMerkleOperations: boolean = false, - ) { - const parentNullifiers = NullifierManager.newWithPendingSiloedNullifiers(worldStateDB, pendingSiloedNullifiers); - const ephemeralForest = await AvmEphemeralForest.create(worldStateDB.getMerkleInterface()); - return new AvmPersistableStateManager( - worldStateDB, - trace, + private readonly log = createDebugLogger('aztec:avm_simulator:state_manager'); + + /** Make sure a forked state is never merged twice. */ + private alreadyMergedIntoParent = false; + + constructor( + /** Reference to node storage */ + private readonly worldStateDB: WorldStateDB, + /** Side effect trace */ + // TODO(5818): make private once no longer accessed in executor + public readonly trace: PublicSideEffectTraceInterface, + /** Public storage, including cached writes */ + private readonly publicStorage: PublicStorage = new PublicStorage(worldStateDB), + /** Nullifier set, including cached/recently-emitted nullifiers */ + private readonly nullifiers: NullifierManager = new NullifierManager(worldStateDB), + private readonly doMerkleOperations: boolean = false, + /** Ephmeral forest for merkle tree operations */ + public merkleTrees: AvmEphemeralForest, + ) {} + + /** + * Create a new state manager with some preloaded pending siloed nullifiers + */ + public static async newWithPendingSiloedNullifiers( + worldStateDB: WorldStateDB, + trace: PublicSideEffectTraceInterface, + pendingSiloedNullifiers: Fr[], + doMerkleOperations: boolean = false, + ) { + const parentNullifiers = NullifierManager.newWithPendingSiloedNullifiers(worldStateDB, pendingSiloedNullifiers); + const ephemeralForest = await AvmEphemeralForest.create(worldStateDB.getMerkleInterface()); + return new AvmPersistableStateManager( + worldStateDB, + trace, /*publicStorage=*/ new PublicStorage(worldStateDB), /*nullifiers=*/ parentNullifiers.fork(), - doMerkleOperations, - ephemeralForest, - ); - } - - /** - * Create a new state manager - */ - public static async create( - worldStateDB: WorldStateDB, - trace: PublicSideEffectTraceInterface, - doMerkleOperations: boolean = false, - ) { - const ephemeralForest = await AvmEphemeralForest.create(worldStateDB.getMerkleInterface()); - return new AvmPersistableStateManager( - worldStateDB, - trace, + doMerkleOperations, + ephemeralForest, + ); + } + + /** + * Create a new state manager + */ + public static async create( + worldStateDB: WorldStateDB, + trace: PublicSideEffectTraceInterface, + doMerkleOperations: boolean = false, + ) { + const ephemeralForest = await AvmEphemeralForest.create(worldStateDB.getMerkleInterface()); + return new AvmPersistableStateManager( + worldStateDB, + trace, /*publicStorage=*/ new PublicStorage(worldStateDB), /*nullifiers=*/ new NullifierManager(worldStateDB), /*doMerkleOperations=*/ doMerkleOperations, - ephemeralForest, - ); - } - - /** - * Create a new state manager forked from this one - */ - public fork() { - return new AvmPersistableStateManager( - this.worldStateDB, - this.trace.fork(), - this.publicStorage.fork(), - this.nullifiers.fork(), - this.doMerkleOperations, - this.merkleTrees.fork(), + ephemeralForest, + ); + } + + /** + * Create a new state manager forked from this one + */ + public fork() { + return new AvmPersistableStateManager( + this.worldStateDB, + this.trace.fork(), + this.publicStorage.fork(), + this.nullifiers.fork(), + this.doMerkleOperations, + this.merkleTrees.fork(), + ); + } + + /** + * Accept forked world state modifications & traced side effects / hints + */ + public merge(forkedState: AvmPersistableStateManager) { + this._merge(forkedState, /*reverted=*/ false); + } + + /** + * Reject forked world state modifications & traced side effects, keep traced hints + */ + public reject(forkedState: AvmPersistableStateManager) { + this._merge(forkedState, /*reverted=*/ true); + } + + private _merge(forkedState: AvmPersistableStateManager, reverted: boolean) { + // sanity check to avoid merging the same forked trace twice + assert( + !forkedState.alreadyMergedIntoParent, + 'Cannot merge forked state that has already been merged into its parent!', + ); + forkedState.alreadyMergedIntoParent = true; + this.publicStorage.acceptAndMerge(forkedState.publicStorage); + this.nullifiers.acceptAndMerge(forkedState.nullifiers); + this.trace.merge(forkedState.trace, reverted); + if (!reverted) { + this.merkleTrees = forkedState.merkleTrees; + if (this.doMerkleOperations) { + this.log.debug( + `Rolled back nullifier tree to root ${this.merkleTrees.treeMap.get(MerkleTreeId.NULLIFIER_TREE)!.getRoot()}`, ); + } } - - /** - * Accept forked world state modifications & traced side effects / hints - */ - public merge(forkedState: AvmPersistableStateManager) { - this._merge(forkedState, /*reverted=*/ false); - } - - /** - * Reject forked world state modifications & traced side effects, keep traced hints - */ - public reject(forkedState: AvmPersistableStateManager) { - this._merge(forkedState, /*reverted=*/ true); + } + + /** + * Write to public storage, journal/trace the write. + * + * @param contractAddress - the address of the contract whose storage is being written to + * @param slot - the slot in the contract's storage being written to + * @param value - the value being written to the slot + */ + public async writeStorage(contractAddress: AztecAddress, slot: Fr, value: Fr): Promise { + this.log.debug(`Storage write (address=${contractAddress}, slot=${slot}): value=${value}`); + // Cache storage writes for later reference/reads + this.publicStorage.write(contractAddress, slot, value); + const leafSlot = computePublicDataTreeLeafSlot(contractAddress, slot); + if (this.doMerkleOperations) { + const result = await this.merkleTrees.writePublicStorage(leafSlot, value); + assert(result !== undefined, 'Public data tree insertion error. You might want to disable doMerkleOperations.'); + this.log.debug(`Inserted public data tree leaf at leafSlot ${leafSlot}, value: ${value}`); + + const lowLeafInfo = result.lowWitness; + const lowLeafPreimage = result.lowWitness.preimage as PublicDataTreeLeafPreimage; + const lowLeafIndex = lowLeafInfo.index; + const lowLeafPath = lowLeafInfo.siblingPath; + + const newLeafPreimage = result.element as PublicDataTreeLeafPreimage; + let insertionPath; + + if (!result.update) { + insertionPath = result.insertionPath; + } + + this.trace.tracePublicStorageWrite( + contractAddress, + slot, + value, + lowLeafPreimage, + new Fr(lowLeafIndex), + lowLeafPath, + newLeafPreimage, + insertionPath, + ); + } else { + this.trace.tracePublicStorageWrite(contractAddress, slot, value); } - - private _merge(forkedState: AvmPersistableStateManager, reverted: boolean) { - // sanity check to avoid merging the same forked trace twice + } + + /** + * Read from public storage, trace the read. + * + * @param contractAddress - the address of the contract whose storage is being read from + * @param slot - the slot in the contract's storage being read from + * @returns the latest value written to slot, or 0 if never written to before + */ + public async readStorage(contractAddress: AztecAddress, slot: Fr): Promise { + const { value, cached } = await this.publicStorage.read(contractAddress, slot); + this.log.debug(`Storage read (address=${contractAddress}, slot=${slot}): value=${value}, cached=${cached}`); + + const leafSlot = computePublicDataTreeLeafSlot(contractAddress, slot); + + if (this.doMerkleOperations) { + // Get leaf if present, low leaf if absent + // If leaf is present, hint/trace it. Otherwise, hint/trace the low leaf. + const { + preimage, + index: leafIndex, + alreadyPresent, + } = await this.merkleTrees.getLeafOrLowLeafInfo(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot); + // The index and preimage here is either the low leaf or the leaf itself (depending on the value of update flag) + // In either case, we just want the sibling path to this leaf - it's up to the avm to distinguish if it's a low leaf or not + const leafPath = await this.merkleTrees.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex); + const leafPreimage = preimage as PublicDataTreeLeafPreimage; + + this.log.debug( + `leafPreimage.nextSlot: ${leafPreimage.nextSlot}, leafPreimage.nextIndex: ${Number(leafPreimage.nextIndex)}`, + ); + this.log.debug(`leafPreimage.slot: ${leafPreimage.slot}, leafPreimage.value: ${leafPreimage.value}`); + + if (!alreadyPresent) { + // Sanity check that the leaf slot is skipped by low leaf when it doesn't exist assert( - !forkedState.alreadyMergedIntoParent, - 'Cannot merge forked state that has already been merged into its parent!', + leafPreimage.slot.toBigInt() < leafSlot.toBigInt() && + (leafPreimage.nextIndex === 0n || leafPreimage.nextSlot.toBigInt() > leafSlot.toBigInt()), + 'Public data tree low leaf should skip the target leaf slot when the target leaf does not exist or is the max value.', ); - forkedState.alreadyMergedIntoParent = true; - this.publicStorage.acceptAndMerge(forkedState.publicStorage); - this.nullifiers.acceptAndMerge(forkedState.nullifiers); - this.trace.merge(forkedState.trace, reverted); - if (!reverted) { - this.merkleTrees = forkedState.merkleTrees; - if (this.doMerkleOperations) { - this.log.debug( - `Rolled back nullifier tree to root ${this.merkleTrees.treeMap.get(MerkleTreeId.NULLIFIER_TREE)!.getRoot()}`, - ); - } - } - } - - /** - * Write to public storage, journal/trace the write. - * - * @param contractAddress - the address of the contract whose storage is being written to - * @param slot - the slot in the contract's storage being written to - * @param value - the value being written to the slot - */ - public async writeStorage(contractAddress: AztecAddress, slot: Fr, value: Fr): Promise { - this.log.debug(`Storage write (address=${contractAddress}, slot=${slot}): value=${value}`); - // Cache storage writes for later reference/reads - this.publicStorage.write(contractAddress, slot, value); - const leafSlot = computePublicDataTreeLeafSlot(contractAddress, slot); - if (this.doMerkleOperations) { - const result = await this.merkleTrees.writePublicStorage(leafSlot, value); - assert(result !== undefined, 'Public data tree insertion error. You might want to disable doMerkleOperations.'); - this.log.debug(`Inserted public data tree leaf at leafSlot ${leafSlot}, value: ${value}`); - - const lowLeafInfo = result.lowWitness; - const lowLeafPreimage = result.lowWitness.preimage as PublicDataTreeLeafPreimage; - const lowLeafIndex = lowLeafInfo.index; - const lowLeafPath = lowLeafInfo.siblingPath; - - const newLeafPreimage = result.element as PublicDataTreeLeafPreimage; - let insertionPath; - - if (!result.update) { - insertionPath = result.insertionPath; - } - - this.trace.tracePublicStorageWrite( - contractAddress, - slot, - value, - lowLeafPreimage, - new Fr(lowLeafIndex), - lowLeafPath, - newLeafPreimage, - insertionPath, - ); - } else { - this.trace.tracePublicStorageWrite(contractAddress, slot, value); - } + } + this.log.debug( + `Tracing storage leaf preimage slot=${slot}, leafSlot=${leafSlot}, value=${value}, nextKey=${leafPreimage.nextSlot}, nextIndex=${leafPreimage.nextIndex}`, + ); + // On non-existence, AVM circuit will need to recognize that leafPreimage.slot != leafSlot, + // prove that this is a low leaf that skips leafSlot, and then prove membership of the leaf. + this.trace.tracePublicStorageRead(contractAddress, slot, value, leafPreimage, new Fr(leafIndex), leafPath); + } else { + this.trace.tracePublicStorageRead(contractAddress, slot, value); } - /** - * Read from public storage, trace the read. - * - * @param contractAddress - the address of the contract whose storage is being read from - * @param slot - the slot in the contract's storage being read from - * @returns the latest value written to slot, or 0 if never written to before - */ - public async readStorage(contractAddress: AztecAddress, slot: Fr): Promise { - const { value, cached } = await this.publicStorage.read(contractAddress, slot); - this.log.debug(`Storage read (address=${contractAddress}, slot=${slot}): value=${value}, cached=${cached}`); - - const leafSlot = computePublicDataTreeLeafSlot(contractAddress, slot); - - if (this.doMerkleOperations) { - // Get leaf if present, low leaf if absent - // If leaf is present, hint/trace it. Otherwise, hint/trace the low leaf. - const { - preimage, - index: leafIndex, - alreadyPresent, - } = await this.merkleTrees.getLeafOrLowLeafInfo(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot); - // The index and preimage here is either the low leaf or the leaf itself (depending on the value of update flag) - // In either case, we just want the sibling path to this leaf - it's up to the avm to distinguish if it's a low leaf or not - const leafPath = await this.merkleTrees.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex); - const leafPreimage = preimage as PublicDataTreeLeafPreimage; - - this.log.debug( - `leafPreimage.nextSlot: ${leafPreimage.nextSlot}, leafPreimage.nextIndex: ${Number(leafPreimage.nextIndex)}`, - ); - this.log.debug(`leafPreimage.slot: ${leafPreimage.slot}, leafPreimage.value: ${leafPreimage.value}`); - - if (!alreadyPresent) { - // Sanity check that the leaf slot is skipped by low leaf when it doesn't exist - assert( - leafPreimage.slot.toBigInt() < leafSlot.toBigInt() && - (leafPreimage.nextIndex === 0n || leafPreimage.nextSlot.toBigInt() > leafSlot.toBigInt()), - 'Public data tree low leaf should skip the target leaf slot when the target leaf does not exist or is the max value.', - ); - } - this.log.debug( - `Tracing storage leaf preimage slot=${slot}, leafSlot=${leafSlot}, value=${value}, nextKey=${leafPreimage.nextSlot}, nextIndex=${leafPreimage.nextIndex}`, - ); - // On non-existence, AVM circuit will need to recognize that leafPreimage.slot != leafSlot, - // prove that this is a low leaf that skips leafSlot, and then prove membership of the leaf. - this.trace.tracePublicStorageRead(contractAddress, slot, value, leafPreimage, new Fr(leafIndex), leafPath); - } else { - this.trace.tracePublicStorageRead(contractAddress, slot, value); - } - - return Promise.resolve(value); - } - - /** - * Read from public storage, don't trace the read. - * - * @param contractAddress - the address of the contract whose storage is being read from - * @param slot - the slot in the contract's storage being read from - * @returns the latest value written to slot, or 0 if never written to before - */ - public async peekStorage(contractAddress: AztecAddress, slot: Fr): Promise { - const { value, cached } = await this.publicStorage.read(contractAddress, slot); - this.log.debug(`Storage peek (address=${contractAddress}, slot=${slot}): value=${value}, cached=${cached}`); - return Promise.resolve(value); - } - - // TODO(4886): We currently don't silo note hashes. - /** - * Check if a note hash exists at the given leaf index, trace the check. - * - * @param contractAddress - the address of the contract whose storage is being read from - * @param noteHash - the unsiloed note hash being checked - * @param leafIndex - the leaf index being checked - * @returns true if the note hash exists at the given leaf index, false otherwise - */ - public async checkNoteHashExists(contractAddress: AztecAddress, noteHash: Fr, leafIndex: Fr): Promise { - const gotLeafValue = (await this.worldStateDB.getCommitmentValue(leafIndex.toBigInt())) ?? Fr.ZERO; - const exists = gotLeafValue.equals(noteHash); - this.log.debug( - `noteHashes(${contractAddress})@${noteHash} ?? leafIndex: ${leafIndex} | gotLeafValue: ${gotLeafValue}, exists: ${exists}.`, - ); - if (this.doMerkleOperations) { - // TODO(8287): We still return exists here, but we need to transmit both the requested noteHash and the gotLeafValue - // such that the VM can constrain the equality and decide on exists based on that. - const path = await this.merkleTrees.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex.toBigInt()); - this.trace.traceNoteHashCheck(contractAddress, gotLeafValue, leafIndex, exists, path); - } else { - this.trace.traceNoteHashCheck(contractAddress, gotLeafValue, leafIndex, exists); - } - return Promise.resolve(exists); + return Promise.resolve(value); + } + + /** + * Read from public storage, don't trace the read. + * + * @param contractAddress - the address of the contract whose storage is being read from + * @param slot - the slot in the contract's storage being read from + * @returns the latest value written to slot, or 0 if never written to before + */ + public async peekStorage(contractAddress: AztecAddress, slot: Fr): Promise { + const { value, cached } = await this.publicStorage.read(contractAddress, slot); + this.log.debug(`Storage peek (address=${contractAddress}, slot=${slot}): value=${value}, cached=${cached}`); + return Promise.resolve(value); + } + + // TODO(4886): We currently don't silo note hashes. + /** + * Check if a note hash exists at the given leaf index, trace the check. + * + * @param contractAddress - the address of the contract whose storage is being read from + * @param noteHash - the unsiloed note hash being checked + * @param leafIndex - the leaf index being checked + * @returns true if the note hash exists at the given leaf index, false otherwise + */ + public async checkNoteHashExists(contractAddress: AztecAddress, noteHash: Fr, leafIndex: Fr): Promise { + const gotLeafValue = (await this.worldStateDB.getCommitmentValue(leafIndex.toBigInt())) ?? Fr.ZERO; + const exists = gotLeafValue.equals(noteHash); + this.log.debug( + `noteHashes(${contractAddress})@${noteHash} ?? leafIndex: ${leafIndex} | gotLeafValue: ${gotLeafValue}, exists: ${exists}.`, + ); + if (this.doMerkleOperations) { + // TODO(8287): We still return exists here, but we need to transmit both the requested noteHash and the gotLeafValue + // such that the VM can constrain the equality and decide on exists based on that. + const path = await this.merkleTrees.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex.toBigInt()); + this.trace.traceNoteHashCheck(contractAddress, gotLeafValue, leafIndex, exists, path); + } else { + this.trace.traceNoteHashCheck(contractAddress, gotLeafValue, leafIndex, exists); } - - /** - * Write a note hash, trace the write. - * @param noteHash - the unsiloed note hash to write - */ - public writeNoteHash(contractAddress: AztecAddress, noteHash: Fr): void { - this.log.debug(`noteHashes(${contractAddress}) += @${noteHash}.`); - - if (this.doMerkleOperations) { - // Should write a helper for this - const leafIndex = new Fr(this.merkleTrees.treeMap.get(MerkleTreeId.NOTE_HASH_TREE)!.leafCount); - const siloedNoteHash = siloNoteHash(contractAddress, noteHash); - const insertionPath = this.merkleTrees.appendNoteHash(siloedNoteHash); - this.trace.traceNewNoteHash(contractAddress, noteHash, leafIndex, insertionPath); - } else { - this.trace.traceNewNoteHash(contractAddress, noteHash); - } + return Promise.resolve(exists); + } + + /** + * Write a note hash, trace the write. + * @param noteHash - the unsiloed note hash to write + */ + public writeNoteHash(contractAddress: AztecAddress, noteHash: Fr): void { + this.log.debug(`noteHashes(${contractAddress}) += @${noteHash}.`); + + if (this.doMerkleOperations) { + // Should write a helper for this + const leafIndex = new Fr(this.merkleTrees.treeMap.get(MerkleTreeId.NOTE_HASH_TREE)!.leafCount); + const siloedNoteHash = siloNoteHash(contractAddress, noteHash); + const insertionPath = this.merkleTrees.appendNoteHash(siloedNoteHash); + this.trace.traceNewNoteHash(contractAddress, noteHash, leafIndex, insertionPath); + } else { + this.trace.traceNewNoteHash(contractAddress, noteHash); } + } + + /** + * Check if a nullifier exists, trace the check. + * @param contractAddress - address of the contract that the nullifier is associated with + * @param nullifier - the unsiloed nullifier to check + * @returns exists - whether the nullifier exists in the nullifier set + */ + public async checkNullifierExists(contractAddress: AztecAddress, nullifier: Fr): Promise { + this.log.debug(`Checking existence of nullifier (address=${contractAddress}, nullifier=${nullifier})`); + const siloedNullifier = siloNullifier(contractAddress, nullifier); + const [exists, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = await this.getNullifierMembership( + siloedNullifier, + ); - /** - * Check if a nullifier exists, trace the check. - * @param contractAddress - address of the contract that the nullifier is associated with - * @param nullifier - the unsiloed nullifier to check - * @returns exists - whether the nullifier exists in the nullifier set - */ - public async checkNullifierExists(contractAddress: AztecAddress, nullifier: Fr): Promise { - this.log.debug(`Checking existence of nullifier (address=${contractAddress}, nullifier=${nullifier})`); - const siloedNullifier = siloNullifier(contractAddress, nullifier); - const [exists, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = await this.getNullifierMembership( - siloedNullifier, - ); - - if (this.doMerkleOperations) { - this.trace.traceNullifierCheck( - siloedNullifier, - exists, - leafOrLowLeafPreimage, - leafOrLowLeafIndex, - leafOrLowLeafPath, - ); - } else { - this.trace.traceNullifierCheck(siloedNullifier, exists); - } - return Promise.resolve(exists); + if (this.doMerkleOperations) { + this.trace.traceNullifierCheck( + siloedNullifier, + exists, + leafOrLowLeafPreimage, + leafOrLowLeafIndex, + leafOrLowLeafPath, + ); + } else { + this.trace.traceNullifierCheck(siloedNullifier, exists); } - - /** - * Helper to get membership information for a siloed nullifier when checking its existence. - * Optionally trace the nullifier check. - * - * @param siloedNullifier - the siloed nullifier to get membership information for - * @returns - * - exists - whether the nullifier exists in the nullifier set - * - leafOrLowLeafPreimage - the preimage of the nullifier leaf or its low-leaf if it doesn't exist - * - leafOrLowLeafIndex - the leaf index of the nullifier leaf or its low-leaf if it doesn't exist - * - leafOrLowLeafPath - the sibling path of the nullifier leaf or its low-leaf if it doesn't exist - */ - private async getNullifierMembership( - siloedNullifier: Fr, - ): Promise< - [ + return Promise.resolve(exists); + } + + /** + * Helper to get membership information for a siloed nullifier when checking its existence. + * Optionally trace the nullifier check. + * + * @param siloedNullifier - the siloed nullifier to get membership information for + * @returns + * - exists - whether the nullifier exists in the nullifier set + * - leafOrLowLeafPreimage - the preimage of the nullifier leaf or its low-leaf if it doesn't exist + * - leafOrLowLeafIndex - the leaf index of the nullifier leaf or its low-leaf if it doesn't exist + * - leafOrLowLeafPath - the sibling path of the nullifier leaf or its low-leaf if it doesn't exist + */ + private async getNullifierMembership( + siloedNullifier: Fr, + ): Promise< + [ /*exists=*/ boolean, /*leafOrLowLeafPreimage=*/ NullifierLeafPreimage, /*leafOrLowLeafIndex=*/ Fr, /*leafOrLowLeafIndexPath=*/ Fr[], - ] - > { - const [exists, isPending, _] = await this.nullifiers.checkExists(siloedNullifier); - this.log.debug(`Checked siloed nullifier ${siloedNullifier} (exists=${exists}), pending=${isPending}`); - - if (this.doMerkleOperations) { - // Get leaf if present, low leaf if absent - // If leaf is present, hint/trace it. Otherwise, hint/trace the low leaf. - const { - preimage, - index: leafIndex, - alreadyPresent, - } = await this.merkleTrees.getLeafOrLowLeafInfo(MerkleTreeId.NULLIFIER_TREE, siloedNullifier); - const leafPreimage = preimage as NullifierLeafPreimage; - const leafPath = await this.merkleTrees.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex); - - assert( - alreadyPresent == exists, - 'WorldStateDB contains nullifier leaf, but merkle tree does not (or vice versa).... This is a bug!', - ); - - if (exists) { - this.log.debug(`Siloed nullifier ${siloedNullifier} exists at leafIndex=${leafIndex}`); - } else { - // Sanity check that the leaf value is skipped by low leaf when it doesn't exist - assert( - siloedNullifier.toBigInt() > leafPreimage.nullifier.toBigInt() && - siloedNullifier.toBigInt() < leafPreimage.nextNullifier.toBigInt(), - 'Nullifier tree low leaf should skip the target leaf nullifier when the target leaf does not exist.', - ); - } - return [exists, leafPreimage, new Fr(leafIndex), leafPath]; - } else { - return [exists, NullifierLeafPreimage.empty(), Fr.ZERO, []]; - } - } - - /** - * Write a nullifier to the nullifier set, trace the write. - * @param contractAddress - address of the contract that the nullifier is associated with - * @param nullifier - the unsiloed nullifier to write - */ - public async writeNullifier(contractAddress: AztecAddress, nullifier: Fr) { - this.log.debug(`Inserting new nullifier (address=${nullifier}, nullifier=${contractAddress})`); - const siloedNullifier = siloNullifier(contractAddress, nullifier); - await this.writeSiloedNullifier(siloedNullifier); + ] + > { + const [exists, isPending, _] = await this.nullifiers.checkExists(siloedNullifier); + this.log.debug(`Checked siloed nullifier ${siloedNullifier} (exists=${exists}), pending=${isPending}`); + + if (this.doMerkleOperations) { + // Get leaf if present, low leaf if absent + // If leaf is present, hint/trace it. Otherwise, hint/trace the low leaf. + const { + preimage, + index: leafIndex, + alreadyPresent, + } = await this.merkleTrees.getLeafOrLowLeafInfo(MerkleTreeId.NULLIFIER_TREE, siloedNullifier); + const leafPreimage = preimage as NullifierLeafPreimage; + const leafPath = await this.merkleTrees.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex); + + assert( + alreadyPresent == exists, + 'WorldStateDB contains nullifier leaf, but merkle tree does not (or vice versa).... This is a bug!', + ); + + if (exists) { + this.log.debug(`Siloed nullifier ${siloedNullifier} exists at leafIndex=${leafIndex}`); + } else { + // Sanity check that the leaf value is skipped by low leaf when it doesn't exist + assert( + siloedNullifier.toBigInt() > leafPreimage.nullifier.toBigInt() && + siloedNullifier.toBigInt() < leafPreimage.nextNullifier.toBigInt(), + 'Nullifier tree low leaf should skip the target leaf nullifier when the target leaf does not exist.', + ); + } + return [exists, leafPreimage, new Fr(leafIndex), leafPath]; + } else { + return [exists, NullifierLeafPreimage.empty(), Fr.ZERO, []]; } - - /** - * Write a nullifier to the nullifier set, trace the write. - * @param siloedNullifier - the siloed nullifier to write - */ - public async writeSiloedNullifier(siloedNullifier: Fr) { - this.log.debug(`Inserting siloed nullifier=${siloedNullifier}`); - - if (this.doMerkleOperations) { - // Maybe overkill, but we should check if the nullifier is already present in the tree before attempting to insert - // It might be better to catch the error from the insert operation - // Trace all nullifier creations, even duplicate insertions that fail - const { preimage, index, alreadyPresent } = await this.merkleTrees.getLeafOrLowLeafInfo( - MerkleTreeId.NULLIFIER_TREE, - siloedNullifier, - ); - if (alreadyPresent) { - this.log.verbose(`Siloed nullifier ${siloedNullifier} already present in tree at index ${index}!`); - // If the nullifier is already present, we should not insert it again - // instead we provide the direct membership path - const path = await this.merkleTrees.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, index); - // This just becomes a nullifier read hint - this.trace.traceNullifierCheck( - siloedNullifier, + } + + /** + * Write a nullifier to the nullifier set, trace the write. + * @param contractAddress - address of the contract that the nullifier is associated with + * @param nullifier - the unsiloed nullifier to write + */ + public async writeNullifier(contractAddress: AztecAddress, nullifier: Fr) { + this.log.debug(`Inserting new nullifier (address=${nullifier}, nullifier=${contractAddress})`); + const siloedNullifier = siloNullifier(contractAddress, nullifier); + await this.writeSiloedNullifier(siloedNullifier); + } + + /** + * Write a nullifier to the nullifier set, trace the write. + * @param siloedNullifier - the siloed nullifier to write + */ + public async writeSiloedNullifier(siloedNullifier: Fr) { + this.log.debug(`Inserting siloed nullifier=${siloedNullifier}`); + + if (this.doMerkleOperations) { + // Maybe overkill, but we should check if the nullifier is already present in the tree before attempting to insert + // It might be better to catch the error from the insert operation + // Trace all nullifier creations, even duplicate insertions that fail + const { preimage, index, alreadyPresent } = await this.merkleTrees.getLeafOrLowLeafInfo( + MerkleTreeId.NULLIFIER_TREE, + siloedNullifier, + ); + if (alreadyPresent) { + this.log.verbose(`Siloed nullifier ${siloedNullifier} already present in tree at index ${index}!`); + // If the nullifier is already present, we should not insert it again + // instead we provide the direct membership path + const path = await this.merkleTrees.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, index); + // This just becomes a nullifier read hint + this.trace.traceNullifierCheck( + siloedNullifier, /*exists=*/ alreadyPresent, - preimage as NullifierLeafPreimage, - new Fr(index), - path, - ); - throw new NullifierCollisionError( - `Siloed nullifier ${siloedNullifier} already exists in parent cache or host.`, - ); - } else { - // Cache pending nullifiers for later access - await this.nullifiers.append(siloedNullifier); - // We append the new nullifier - this.log.debug( - `Nullifier tree root before insertion ${this.merkleTrees.treeMap - .get(MerkleTreeId.NULLIFIER_TREE)! - .getRoot()}`, - ); - const appendResult = await this.merkleTrees.appendNullifier(siloedNullifier); - this.log.debug( - `Nullifier tree root after insertion ${this.merkleTrees.treeMap.get(MerkleTreeId.NULLIFIER_TREE)!.getRoot()}`, - ); - const lowLeafPreimage = appendResult.lowWitness.preimage as NullifierLeafPreimage; - const lowLeafIndex = appendResult.lowWitness.index; - const lowLeafPath = appendResult.lowWitness.siblingPath; - const insertionPath = appendResult.insertionPath; - this.trace.traceNewNullifier( - siloedNullifier, - lowLeafPreimage, - new Fr(lowLeafIndex), - lowLeafPath, - insertionPath, - ); - } - } else { - // Cache pending nullifiers for later access - await this.nullifiers.append(siloedNullifier); - this.trace.traceNewNullifier(siloedNullifier); - } - } - - public async writeSiloedNullifiersFromPrivate(siloedNullifiers: Fr[]) { - for (const siloedNullifier of siloedNullifiers.filter(n => !n.isEmpty())) { - await this.writeSiloedNullifier(siloedNullifier); - } - } - - /** - * Check if an L1 to L2 message exists, trace the check. - * @param msgHash - the message hash to check existence of - * @param msgLeafIndex - the message leaf index to use in the check - * @returns exists - whether the message exists in the L1 to L2 Messages tree - */ - public async checkL1ToL2MessageExists( - contractAddress: AztecAddress, - msgHash: Fr, - msgLeafIndex: Fr, - ): Promise { - const valueAtIndex = (await this.worldStateDB.getL1ToL2LeafValue(msgLeafIndex.toBigInt())) ?? Fr.ZERO; - const exists = valueAtIndex.equals(msgHash); + preimage as NullifierLeafPreimage, + new Fr(index), + path, + ); + throw new NullifierCollisionError( + `Siloed nullifier ${siloedNullifier} already exists in parent cache or host.`, + ); + } else { + // Cache pending nullifiers for later access + await this.nullifiers.append(siloedNullifier); + // We append the new nullifier this.log.debug( - `l1ToL2Messages(@${msgLeafIndex}) ?? exists: ${exists}, expected: ${msgHash}, found: ${valueAtIndex}.`, + `Nullifier tree root before insertion ${this.merkleTrees.treeMap + .get(MerkleTreeId.NULLIFIER_TREE)! + .getRoot()}`, ); - - if (this.doMerkleOperations) { - // TODO(8287): We still return exists here, but we need to transmit both the requested msgHash and the value - // such that the VM can constrain the equality and decide on exists based on that. - // We should defintely add a helper here - const path = await this.merkleTrees.treeDb.getSiblingPath( - MerkleTreeId.L1_TO_L2_MESSAGE_TREE, - msgLeafIndex.toBigInt(), - ); - this.trace.traceL1ToL2MessageCheck(contractAddress, valueAtIndex, msgLeafIndex, exists, path.toFields()); - } else { - this.trace.traceL1ToL2MessageCheck(contractAddress, valueAtIndex, msgLeafIndex, exists); - } - return Promise.resolve(exists); + const appendResult = await this.merkleTrees.appendNullifier(siloedNullifier); + this.log.debug( + `Nullifier tree root after insertion ${this.merkleTrees.treeMap.get(MerkleTreeId.NULLIFIER_TREE)!.getRoot()}`, + ); + const lowLeafPreimage = appendResult.lowWitness.preimage as NullifierLeafPreimage; + const lowLeafIndex = appendResult.lowWitness.index; + const lowLeafPath = appendResult.lowWitness.siblingPath; + const insertionPath = appendResult.insertionPath; + this.trace.traceNewNullifier( + siloedNullifier, + lowLeafPreimage, + new Fr(lowLeafIndex), + lowLeafPath, + insertionPath, + ); + } + } else { + // Cache pending nullifiers for later access + await this.nullifiers.append(siloedNullifier); + this.trace.traceNewNullifier(siloedNullifier); } + } - /** - * Write an L2 to L1 message. - * @param contractAddress - L2 contract address that created this message - * @param recipient - L1 contract address to send the message to. - * @param content - Message content. - */ - public writeL2ToL1Message(contractAddress: AztecAddress, recipient: Fr, content: Fr) { - this.log.debug(`L2ToL1Messages(${contractAddress}) += (recipient: ${recipient}, content: ${content}).`); - this.trace.traceNewL2ToL1Message(contractAddress, recipient, content); + public async writeSiloedNullifiersFromPrivate(siloedNullifiers: Fr[]) { + for (const siloedNullifier of siloedNullifiers.filter(n => !n.isEmpty())) { + await this.writeSiloedNullifier(siloedNullifier); } + } + + /** + * Check if an L1 to L2 message exists, trace the check. + * @param msgHash - the message hash to check existence of + * @param msgLeafIndex - the message leaf index to use in the check + * @returns exists - whether the message exists in the L1 to L2 Messages tree + */ + public async checkL1ToL2MessageExists( + contractAddress: AztecAddress, + msgHash: Fr, + msgLeafIndex: Fr, + ): Promise { + const valueAtIndex = (await this.worldStateDB.getL1ToL2LeafValue(msgLeafIndex.toBigInt())) ?? Fr.ZERO; + const exists = valueAtIndex.equals(msgHash); + this.log.debug( + `l1ToL2Messages(@${msgLeafIndex}) ?? exists: ${exists}, expected: ${msgHash}, found: ${valueAtIndex}.`, + ); - /** - * Write an unencrypted log - * @param contractAddress - address of the contract that emitted the log - * @param event - log event selector - * @param log - log contents - */ - public writeUnencryptedLog(contractAddress: AztecAddress, log: Fr[]) { - this.log.debug(`UnencryptedL2Log(${contractAddress}) += event with ${log.length} fields.`); - this.trace.traceUnencryptedLog(contractAddress, log); + if (this.doMerkleOperations) { + // TODO(8287): We still return exists here, but we need to transmit both the requested msgHash and the value + // such that the VM can constrain the equality and decide on exists based on that. + // We should defintely add a helper here + const path = await this.merkleTrees.treeDb.getSiblingPath( + MerkleTreeId.L1_TO_L2_MESSAGE_TREE, + msgLeafIndex.toBigInt(), + ); + this.trace.traceL1ToL2MessageCheck(contractAddress, valueAtIndex, msgLeafIndex, exists, path.toFields()); + } else { + this.trace.traceL1ToL2MessageCheck(contractAddress, valueAtIndex, msgLeafIndex, exists); } - - /** - * Get a contract instance. - * @param contractAddress - address of the contract instance to retrieve. - * @returns the contract instance or undefined if it does not exist. - */ - public async getContractInstance(contractAddress: AztecAddress): Promise { - this.log.debug(`Getting contract instance for address ${contractAddress}`); - const instanceWithAddress = await this.worldStateDB.getContractInstance(contractAddress); - const exists = instanceWithAddress !== undefined; - - let [existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = [ - exists, - NullifierLeafPreimage.empty(), - Fr.ZERO, - new Array(), - ]; - if (!contractAddressIsCanonical(contractAddress)) { - const contractAddressNullifier = siloNullifier( - AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS), - contractAddress.toField(), - ); - [existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = await this.getNullifierMembership( + return Promise.resolve(exists); + } + + /** + * Write an L2 to L1 message. + * @param contractAddress - L2 contract address that created this message + * @param recipient - L1 contract address to send the message to. + * @param content - Message content. + */ + public writeL2ToL1Message(contractAddress: AztecAddress, recipient: Fr, content: Fr) { + this.log.debug(`L2ToL1Messages(${contractAddress}) += (recipient: ${recipient}, content: ${content}).`); + this.trace.traceNewL2ToL1Message(contractAddress, recipient, content); + } + + /** + * Write an unencrypted log + * @param contractAddress - address of the contract that emitted the log + * @param event - log event selector + * @param log - log contents + */ + public writeUnencryptedLog(contractAddress: AztecAddress, log: Fr[]) { + this.log.debug(`UnencryptedL2Log(${contractAddress}) += event with ${log.length} fields.`); + this.trace.traceUnencryptedLog(contractAddress, log); + } + + /** + * Get a contract instance. + * @param contractAddress - address of the contract instance to retrieve. + * @returns the contract instance or undefined if it does not exist. + */ + public async getContractInstance(contractAddress: AztecAddress): Promise { + this.log.debug(`Getting contract instance for address ${contractAddress}`); + const instanceWithAddress = await this.worldStateDB.getContractInstance(contractAddress); + const exists = instanceWithAddress !== undefined; + + let [existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = [ + exists, + NullifierLeafPreimage.empty(), + Fr.ZERO, + new Array(), + ]; + if (!contractAddressIsCanonical(contractAddress)) { + const contractAddressNullifier = siloNullifier( + AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS), + contractAddress.toField(), + ); + [existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = await this.getNullifierMembership( /*siloedNullifier=*/ contractAddressNullifier, - ); - assert( - exists == existsInTree, - 'WorldStateDB contains contract instance, but nullifier tree does not contain contract address (or vice versa).... This is a bug!', - ); - } - - if (exists) { - const instance = new SerializableContractInstance(instanceWithAddress); - this.log.debug( - `Got contract instance (address=${contractAddress}): exists=${exists}, instance=${jsonStringify(instance)}`, - ); - if (this.doMerkleOperations) { - this.trace.traceGetContractInstance( - contractAddress, - exists, - instance, - leafOrLowLeafPreimage, - leafOrLowLeafIndex, - leafOrLowLeafPath, - ); - } else { - this.trace.traceGetContractInstance(contractAddress, exists, instance); - } - - return Promise.resolve(instance); - } else { - this.log.debug(`Contract instance NOT FOUND (address=${contractAddress})`); - if (this.doMerkleOperations) { - this.trace.traceGetContractInstance( - contractAddress, - exists, - /*instance=*/ undefined, - leafOrLowLeafPreimage, - leafOrLowLeafIndex, - leafOrLowLeafPath, - ); - } else { - this.trace.traceGetContractInstance(contractAddress, exists); - } - return Promise.resolve(undefined); - } + ); + assert( + exists == existsInTree, + 'WorldStateDB contains contract instance, but nullifier tree does not contain contract address (or vice versa).... This is a bug!', + ); } - /** - * Get a contract's bytecode from the contracts DB, also trace the contract class and instance - */ - public async getBytecode(contractAddress: AztecAddress): Promise { - this.log.debug(`Getting bytecode for contract address ${contractAddress}`); - const instanceWithAddress = await this.worldStateDB.getContractInstance(contractAddress); - const exists = instanceWithAddress !== undefined; - const [existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = - await this.getNullifierMembership(/*siloedNullifier=*/ contractAddress.toField()); - assert( - exists == existsInTree, - 'WorldStateDB contains contract instance, but nullifier tree does not contain contract address (or vice versa).... This is a bug!', + if (exists) { + const instance = new SerializableContractInstance(instanceWithAddress); + this.log.debug( + `Got contract instance (address=${contractAddress}): exists=${exists}, instance=${jsonStringify(instance)}`, + ); + if (this.doMerkleOperations) { + this.trace.traceGetContractInstance( + contractAddress, + exists, + instance, + leafOrLowLeafPreimage, + leafOrLowLeafIndex, + leafOrLowLeafPath, ); - - let [existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = [ - exists, - NullifierLeafPreimage.empty(), - Fr.ZERO, - new Array(), - ]; - if (!contractAddressIsCanonical(contractAddress)) { - const contractAddressNullifier = siloNullifier( - AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS), - contractAddress.toField(), - ); - [existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = await this.getNullifierMembership( + } else { + this.trace.traceGetContractInstance(contractAddress, exists, instance); + } + + return Promise.resolve(instance); + } else { + this.log.debug(`Contract instance NOT FOUND (address=${contractAddress})`); + if (this.doMerkleOperations) { + this.trace.traceGetContractInstance( + contractAddress, + exists, + /*instance=*/ undefined, + leafOrLowLeafPreimage, + leafOrLowLeafIndex, + leafOrLowLeafPath, + ); + } else { + this.trace.traceGetContractInstance(contractAddress, exists); + } + return Promise.resolve(undefined); + } + } + + /** + * Get a contract's bytecode from the contracts DB, also trace the contract class and instance + */ + public async getBytecode(contractAddress: AztecAddress): Promise { + this.log.debug(`Getting bytecode for contract address ${contractAddress}`); + const instanceWithAddress = await this.worldStateDB.getContractInstance(contractAddress); + const exists = instanceWithAddress !== undefined; + + let [existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = [ + exists, + NullifierLeafPreimage.empty(), + Fr.ZERO, + new Array(), + ]; + if (!contractAddressIsCanonical(contractAddress)) { + const contractAddressNullifier = siloNullifier( + AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS), + contractAddress.toField(), + ); + [existsInTree, leafOrLowLeafPreimage, leafOrLowLeafIndex, leafOrLowLeafPath] = await this.getNullifierMembership( /*siloedNullifier=*/ contractAddressNullifier, - ); - assert( - exists == existsInTree, - 'WorldStateDB contains contract instance, but nullifier tree does not contain contract address (or vice versa).... This is a bug!', - ); - } - - if (exists) { - const instance = new SerializableContractInstance(instanceWithAddress); - const contractClass = await this.worldStateDB.getContractClass(instance.contractClassId); - const bytecodeCommitment = await this.worldStateDB.getBytecodeCommitment(instance.contractClassId); - - assert( - contractClass, - `Contract class not found in DB, but a contract instance was found with this class ID (${instance.contractClassId}). This should not happen!`, - ); - - assert( - bytecodeCommitment, - `Bytecode commitment was not found in DB for contract class (${instance.contractClassId}). This should not happen!`, - ); - - const contractClassPreimage = { - artifactHash: contractClass.artifactHash, - privateFunctionsRoot: contractClass.privateFunctionsRoot, - publicBytecodeCommitment: bytecodeCommitment, - }; - - if (this.doMerkleOperations) { - this.trace.traceGetBytecode( - contractAddress, - exists, - contractClass.packedBytecode, - instance, - contractClassPreimage, - leafOrLowLeafPreimage, - leafOrLowLeafIndex, - leafOrLowLeafPath, - ); - } else { - this.trace.traceGetBytecode( - contractAddress, - exists, - contractClass.packedBytecode, - instance, - contractClassPreimage, - ); - } - - return contractClass.packedBytecode; - } else { - // If the contract instance is not found, we assume it has not been deployed. - // It doesnt matter what the values of the contract instance are in this case, as long as we tag it with exists=false. - // This will hint to the avm circuit to just perform the non-membership check on the address and disregard the bytecode hash - if (this.doMerkleOperations) { - this.trace.traceGetBytecode( - contractAddress, - exists, + ); + assert( + exists == existsInTree, + 'WorldStateDB contains contract instance, but nullifier tree does not contain contract address (or vice versa).... This is a bug!', + ); + } + + if (exists) { + const instance = new SerializableContractInstance(instanceWithAddress); + const contractClass = await this.worldStateDB.getContractClass(instance.contractClassId); + const bytecodeCommitment = await this.worldStateDB.getBytecodeCommitment(instance.contractClassId); + + assert( + contractClass, + `Contract class not found in DB, but a contract instance was found with this class ID (${instance.contractClassId}). This should not happen!`, + ); + + assert( + bytecodeCommitment, + `Bytecode commitment was not found in DB for contract class (${instance.contractClassId}). This should not happen!`, + ); + + const contractClassPreimage = { + artifactHash: contractClass.artifactHash, + privateFunctionsRoot: contractClass.privateFunctionsRoot, + publicBytecodeCommitment: bytecodeCommitment, + }; + + if (this.doMerkleOperations) { + this.trace.traceGetBytecode( + contractAddress, + exists, + contractClass.packedBytecode, + instance, + contractClassPreimage, + leafOrLowLeafPreimage, + leafOrLowLeafIndex, + leafOrLowLeafPath, + ); + } else { + this.trace.traceGetBytecode( + contractAddress, + exists, + contractClass.packedBytecode, + instance, + contractClassPreimage, + ); + } + + return contractClass.packedBytecode; + } else { + // If the contract instance is not found, we assume it has not been deployed. + // It doesnt matter what the values of the contract instance are in this case, as long as we tag it with exists=false. + // This will hint to the avm circuit to just perform the non-membership check on the address and disregard the bytecode hash + if (this.doMerkleOperations) { + this.trace.traceGetBytecode( + contractAddress, + exists, /*instance=*/ undefined, /*contractClass=*/ undefined, /*bytecode=*/ undefined, - leafOrLowLeafPreimage, - leafOrLowLeafIndex, - leafOrLowLeafPath, - ); - } else { - this.trace.traceGetBytecode(contractAddress, exists); // bytecode, instance, class undefined - } - return undefined; - } - } - - public async traceNestedCall( - forkedState: AvmPersistableStateManager, - nestedEnvironment: AvmExecutionEnvironment, - startGasLeft: Gas, - bytecode: Buffer, - avmCallResults: AvmContractCallResult, - ) { - const functionName = await getPublicFunctionDebugName( - this.worldStateDB, - nestedEnvironment.address, - nestedEnvironment.functionSelector, - nestedEnvironment.calldata, + leafOrLowLeafPreimage, + leafOrLowLeafIndex, + leafOrLowLeafPath, ); + } else { + this.trace.traceGetBytecode(contractAddress, exists); // bytecode, instance, class undefined + } + return undefined; + } + } + + public async traceNestedCall( + forkedState: AvmPersistableStateManager, + nestedEnvironment: AvmExecutionEnvironment, + startGasLeft: Gas, + bytecode: Buffer, + avmCallResults: AvmContractCallResult, + ) { + const functionName = await getPublicFunctionDebugName( + this.worldStateDB, + nestedEnvironment.address, + nestedEnvironment.functionSelector, + nestedEnvironment.calldata, + ); - this.log.verbose(`[AVM] Tracing nested external contract call ${functionName}`); + this.log.verbose(`[AVM] Tracing nested external contract call ${functionName}`); - this.trace.traceNestedCall( - forkedState.trace, - nestedEnvironment, - startGasLeft, - bytecode, - avmCallResults, - functionName, - ); - } + this.trace.traceNestedCall( + forkedState.trace, + nestedEnvironment, + startGasLeft, + bytecode, + avmCallResults, + functionName, + ); + } - public traceEnqueuedCall(publicCallRequest: PublicCallRequest, calldata: Fr[], reverted: boolean) { - this.trace.traceEnqueuedCall(publicCallRequest, calldata, reverted); - } + public traceEnqueuedCall(publicCallRequest: PublicCallRequest, calldata: Fr[], reverted: boolean) { + this.trace.traceEnqueuedCall(publicCallRequest, calldata, reverted); + } } function contractAddressIsCanonical(contractAddress: AztecAddress): boolean { - return ( - contractAddress.equals(AztecAddress.fromNumber(CANONICAL_AUTH_REGISTRY_ADDRESS)) || - contractAddress.equals(AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS)) || - contractAddress.equals(AztecAddress.fromNumber(REGISTERER_CONTRACT_ADDRESS)) || - contractAddress.equals(AztecAddress.fromNumber(MULTI_CALL_ENTRYPOINT_ADDRESS)) || - contractAddress.equals(AztecAddress.fromNumber(FEE_JUICE_ADDRESS)) || - contractAddress.equals(AztecAddress.fromNumber(ROUTER_ADDRESS)) - ); + return ( + contractAddress.equals(AztecAddress.fromNumber(CANONICAL_AUTH_REGISTRY_ADDRESS)) || + contractAddress.equals(AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS)) || + contractAddress.equals(AztecAddress.fromNumber(REGISTERER_CONTRACT_ADDRESS)) || + contractAddress.equals(AztecAddress.fromNumber(MULTI_CALL_ENTRYPOINT_ADDRESS)) || + contractAddress.equals(AztecAddress.fromNumber(FEE_JUICE_ADDRESS)) || + contractAddress.equals(AztecAddress.fromNumber(ROUTER_ADDRESS)) + ); }