diff --git a/barretenberg/cpp/pil/avm/gadgets/merkle_tree.pil b/barretenberg/cpp/pil/avm/gadgets/merkle_tree.pil new file mode 100644 index 00000000000..bd39fcbb9b4 --- /dev/null +++ b/barretenberg/cpp/pil/avm/gadgets/merkle_tree.pil @@ -0,0 +1,76 @@ +include "./poseidon2_full.pil"; + +// Handles membership and insertion into a merkle tree +namespace merkle_tree(256); + + pol commit sel_merkle_tree; + sel_merkle_tree * (1 - sel_merkle_tree) = 0; + // Will probably used in permutation with other traces + pol commit sel_update_op; + sel_update_op * (1 - sel_update_op) = 0; + pol commit sel_membership_op; + sel_membership_op * (1 - sel_membership_op) = 0; + // Gotta stop using clk for things that are more like foreign keys + pol commit clk; + // Inputs to the gadget + pol commit leaf_value; + pol commit leaf_index; + pol commit path_len; + pol commit expected_tree_root; + // Output of the gadget + // Boolean result of the membership check + pol commit is_member; + is_member * (1 - is_member) = 0; + + // These are all hinted + pol commit sibling_value; + + // If we are not done, the path_len decrements by 1 + sel_merkle_tree * (1 - latch) * (path_len' - path_len + 1) = 0; + + pol commit latch; + latch * (1 - latch) = 0; + pol commit path_len_inv; + // latch == 1 when the path_len == 0 + sel_merkle_tree * (path_len * (latch * (1 - path_len_inv) + path_len_inv) - 1 + latch) = 0; + + pol commit leaf_index_is_even; + leaf_index_is_even * (1 - leaf_index_is_even) = 0; + pol LEAF_INDEX_IS_ODD = (1 - leaf_index_is_even); + // If we are not done, the next leaf index is half the current leaf index; + sel_merkle_tree * (1 - latch) * (leaf_index' * 2 + LEAF_INDEX_IS_ODD - leaf_index) = 0; + + // These are what are sent to poseidon2 + // These arrange the leaf_value and sibling_value in the correct order + pol commit left_hash; + pol commit right_hash; + // I dont think these can be safely combined + // if the leaf index is even, the leaf value is the left hash and the sibling value is the right hash + // vice-versa + sel_merkle_tree * (leaf_index_is_even * (left_hash - leaf_value) + LEAF_INDEX_IS_ODD * (right_hash - leaf_value)) = 0; + sel_merkle_tree * (leaf_index_is_even * (right_hash - sibling_value) + LEAF_INDEX_IS_ODD * (left_hash - sibling_value)) = 0; + pol commit output_hash; + + // If we are not done, the output hash is the next value in + sel_merkle_tree * (1 - latch) * (leaf_value' - output_hash) = 0; + + pol LAST_COMPUTE = sel_merkle_tree * latch; + + // Membership check + pol ROOT_DIFF = output_hash - expected_tree_root; + // Need an additional helper that holds the inverse of the difference; + pol commit diff_inv; + // is_member == 1 if ROOT_DIFF == 0 + sel_membership_op * LAST_COMPUTE * (ROOT_DIFF * (is_member * (1 - diff_inv) + diff_inv) - 1 + is_member) = 0; + + // Permutation to the full poseidon2 gadget + #[PERM_MERKLE_POSEIDON2] + sel_merkle_tree { clk, left_hash, right_hash, output_hash } is + poseidon2_full.sel_merkle_tree {poseidon2_full.clk, poseidon2_full.input_0, poseidon2_full.input_1, poseidon2_full.output }; + + + + + + + diff --git a/barretenberg/cpp/pil/avm/gadgets/poseidon2_full.pil b/barretenberg/cpp/pil/avm/gadgets/poseidon2_full.pil index 97f2eaeca0a..ad2240b7fba 100644 --- a/barretenberg/cpp/pil/avm/gadgets/poseidon2_full.pil +++ b/barretenberg/cpp/pil/avm/gadgets/poseidon2_full.pil @@ -87,3 +87,5 @@ namespace poseidon2_full(256); { poseidon2.clk, poseidon2.a_0, poseidon2.a_1, poseidon2.a_2, poseidon2.a_3, poseidon2.b_0, poseidon2.b_1, poseidon2.b_2, poseidon2.b_3 }; + // ======== Merkle Tree Selector ====================== + pol commit sel_merkle_tree; diff --git a/barretenberg/cpp/pil/avm/main.pil b/barretenberg/cpp/pil/avm/main.pil index 188f8dacca2..5e5163130dc 100644 --- a/barretenberg/cpp/pil/avm/main.pil +++ b/barretenberg/cpp/pil/avm/main.pil @@ -12,6 +12,7 @@ include "gadgets/poseidon2.pil"; include "gadgets/poseidon2_full.pil"; include "gadgets/keccakf1600.pil"; include "gadgets/mem_slice.pil"; +include "gadgets/merkle_tree.pil"; namespace main(256); //===== CONSTANT POLYNOMIALS ================================================== diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp index 99e3cad57ac..06c1f40b545 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp @@ -348,6 +348,23 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co polys.mem_tsp.set_if_valid_index(i, rows[i].mem_tsp); polys.mem_val.set_if_valid_index(i, rows[i].mem_val); polys.mem_w_in_tag.set_if_valid_index(i, rows[i].mem_w_in_tag); + polys.merkle_tree_clk.set_if_valid_index(i, rows[i].merkle_tree_clk); + polys.merkle_tree_diff_inv.set_if_valid_index(i, rows[i].merkle_tree_diff_inv); + polys.merkle_tree_expected_tree_root.set_if_valid_index(i, rows[i].merkle_tree_expected_tree_root); + polys.merkle_tree_is_member.set_if_valid_index(i, rows[i].merkle_tree_is_member); + polys.merkle_tree_latch.set_if_valid_index(i, rows[i].merkle_tree_latch); + polys.merkle_tree_leaf_index.set_if_valid_index(i, rows[i].merkle_tree_leaf_index); + polys.merkle_tree_leaf_index_is_even.set_if_valid_index(i, rows[i].merkle_tree_leaf_index_is_even); + polys.merkle_tree_leaf_value.set_if_valid_index(i, rows[i].merkle_tree_leaf_value); + polys.merkle_tree_left_hash.set_if_valid_index(i, rows[i].merkle_tree_left_hash); + polys.merkle_tree_output_hash.set_if_valid_index(i, rows[i].merkle_tree_output_hash); + polys.merkle_tree_path_len.set_if_valid_index(i, rows[i].merkle_tree_path_len); + polys.merkle_tree_path_len_inv.set_if_valid_index(i, rows[i].merkle_tree_path_len_inv); + polys.merkle_tree_right_hash.set_if_valid_index(i, rows[i].merkle_tree_right_hash); + polys.merkle_tree_sel_membership_op.set_if_valid_index(i, rows[i].merkle_tree_sel_membership_op); + polys.merkle_tree_sel_merkle_tree.set_if_valid_index(i, rows[i].merkle_tree_sel_merkle_tree); + polys.merkle_tree_sel_update_op.set_if_valid_index(i, rows[i].merkle_tree_sel_update_op); + polys.merkle_tree_sibling_value.set_if_valid_index(i, rows[i].merkle_tree_sibling_value); polys.poseidon2_B_10_0.set_if_valid_index(i, rows[i].poseidon2_B_10_0); polys.poseidon2_B_10_1.set_if_valid_index(i, rows[i].poseidon2_B_10_1); polys.poseidon2_B_10_2.set_if_valid_index(i, rows[i].poseidon2_B_10_2); @@ -639,6 +656,7 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co i, rows[i].poseidon2_full_num_perm_rounds_rem_inv); polys.poseidon2_full_output.set_if_valid_index(i, rows[i].poseidon2_full_output); polys.poseidon2_full_padding.set_if_valid_index(i, rows[i].poseidon2_full_padding); + polys.poseidon2_full_sel_merkle_tree.set_if_valid_index(i, rows[i].poseidon2_full_sel_merkle_tree); polys.poseidon2_full_sel_poseidon.set_if_valid_index(i, rows[i].poseidon2_full_sel_poseidon); polys.poseidon2_full_start_poseidon.set_if_valid_index(i, rows[i].poseidon2_full_start_poseidon); polys.poseidon2_input_addr.set_if_valid_index(i, rows[i].poseidon2_input_addr); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp index d9faa840e83..489d5472b3d 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp @@ -298,497 +298,519 @@ AvmFlavor::AllConstRefValues::AllConstRefValues( , mem_tsp(il[290]) , mem_val(il[291]) , mem_w_in_tag(il[292]) - , poseidon2_B_10_0(il[293]) - , poseidon2_B_10_1(il[294]) - , poseidon2_B_10_2(il[295]) - , poseidon2_B_10_3(il[296]) - , poseidon2_B_11_0(il[297]) - , poseidon2_B_11_1(il[298]) - , poseidon2_B_11_2(il[299]) - , poseidon2_B_11_3(il[300]) - , poseidon2_B_12_0(il[301]) - , poseidon2_B_12_1(il[302]) - , poseidon2_B_12_2(il[303]) - , poseidon2_B_12_3(il[304]) - , poseidon2_B_13_0(il[305]) - , poseidon2_B_13_1(il[306]) - , poseidon2_B_13_2(il[307]) - , poseidon2_B_13_3(il[308]) - , poseidon2_B_14_0(il[309]) - , poseidon2_B_14_1(il[310]) - , poseidon2_B_14_2(il[311]) - , poseidon2_B_14_3(il[312]) - , poseidon2_B_15_0(il[313]) - , poseidon2_B_15_1(il[314]) - , poseidon2_B_15_2(il[315]) - , poseidon2_B_15_3(il[316]) - , poseidon2_B_16_0(il[317]) - , poseidon2_B_16_1(il[318]) - , poseidon2_B_16_2(il[319]) - , poseidon2_B_16_3(il[320]) - , poseidon2_B_17_0(il[321]) - , poseidon2_B_17_1(il[322]) - , poseidon2_B_17_2(il[323]) - , poseidon2_B_17_3(il[324]) - , poseidon2_B_18_0(il[325]) - , poseidon2_B_18_1(il[326]) - , poseidon2_B_18_2(il[327]) - , poseidon2_B_18_3(il[328]) - , poseidon2_B_19_0(il[329]) - , poseidon2_B_19_1(il[330]) - , poseidon2_B_19_2(il[331]) - , poseidon2_B_19_3(il[332]) - , poseidon2_B_20_0(il[333]) - , poseidon2_B_20_1(il[334]) - , poseidon2_B_20_2(il[335]) - , poseidon2_B_20_3(il[336]) - , poseidon2_B_21_0(il[337]) - , poseidon2_B_21_1(il[338]) - , poseidon2_B_21_2(il[339]) - , poseidon2_B_21_3(il[340]) - , poseidon2_B_22_0(il[341]) - , poseidon2_B_22_1(il[342]) - , poseidon2_B_22_2(il[343]) - , poseidon2_B_22_3(il[344]) - , poseidon2_B_23_0(il[345]) - , poseidon2_B_23_1(il[346]) - , poseidon2_B_23_2(il[347]) - , poseidon2_B_23_3(il[348]) - , poseidon2_B_24_0(il[349]) - , poseidon2_B_24_1(il[350]) - , poseidon2_B_24_2(il[351]) - , poseidon2_B_24_3(il[352]) - , poseidon2_B_25_0(il[353]) - , poseidon2_B_25_1(il[354]) - , poseidon2_B_25_2(il[355]) - , poseidon2_B_25_3(il[356]) - , poseidon2_B_26_0(il[357]) - , poseidon2_B_26_1(il[358]) - , poseidon2_B_26_2(il[359]) - , poseidon2_B_26_3(il[360]) - , poseidon2_B_27_0(il[361]) - , poseidon2_B_27_1(il[362]) - , poseidon2_B_27_2(il[363]) - , poseidon2_B_27_3(il[364]) - , poseidon2_B_28_0(il[365]) - , poseidon2_B_28_1(il[366]) - , poseidon2_B_28_2(il[367]) - , poseidon2_B_28_3(il[368]) - , poseidon2_B_29_0(il[369]) - , poseidon2_B_29_1(il[370]) - , poseidon2_B_29_2(il[371]) - , poseidon2_B_29_3(il[372]) - , poseidon2_B_30_0(il[373]) - , poseidon2_B_30_1(il[374]) - , poseidon2_B_30_2(il[375]) - , poseidon2_B_30_3(il[376]) - , poseidon2_B_31_0(il[377]) - , poseidon2_B_31_1(il[378]) - , poseidon2_B_31_2(il[379]) - , poseidon2_B_31_3(il[380]) - , poseidon2_B_32_0(il[381]) - , poseidon2_B_32_1(il[382]) - , poseidon2_B_32_2(il[383]) - , poseidon2_B_32_3(il[384]) - , poseidon2_B_33_0(il[385]) - , poseidon2_B_33_1(il[386]) - , poseidon2_B_33_2(il[387]) - , poseidon2_B_33_3(il[388]) - , poseidon2_B_34_0(il[389]) - , poseidon2_B_34_1(il[390]) - , poseidon2_B_34_2(il[391]) - , poseidon2_B_34_3(il[392]) - , poseidon2_B_35_0(il[393]) - , poseidon2_B_35_1(il[394]) - , poseidon2_B_35_2(il[395]) - , poseidon2_B_35_3(il[396]) - , poseidon2_B_36_0(il[397]) - , poseidon2_B_36_1(il[398]) - , poseidon2_B_36_2(il[399]) - , poseidon2_B_36_3(il[400]) - , poseidon2_B_37_0(il[401]) - , poseidon2_B_37_1(il[402]) - , poseidon2_B_37_2(il[403]) - , poseidon2_B_37_3(il[404]) - , poseidon2_B_38_0(il[405]) - , poseidon2_B_38_1(il[406]) - , poseidon2_B_38_2(il[407]) - , poseidon2_B_38_3(il[408]) - , poseidon2_B_39_0(il[409]) - , poseidon2_B_39_1(il[410]) - , poseidon2_B_39_2(il[411]) - , poseidon2_B_39_3(il[412]) - , poseidon2_B_40_0(il[413]) - , poseidon2_B_40_1(il[414]) - , poseidon2_B_40_2(il[415]) - , poseidon2_B_40_3(il[416]) - , poseidon2_B_41_0(il[417]) - , poseidon2_B_41_1(il[418]) - , poseidon2_B_41_2(il[419]) - , poseidon2_B_41_3(il[420]) - , poseidon2_B_42_0(il[421]) - , poseidon2_B_42_1(il[422]) - , poseidon2_B_42_2(il[423]) - , poseidon2_B_42_3(il[424]) - , poseidon2_B_43_0(il[425]) - , poseidon2_B_43_1(il[426]) - , poseidon2_B_43_2(il[427]) - , poseidon2_B_43_3(il[428]) - , poseidon2_B_44_0(il[429]) - , poseidon2_B_44_1(il[430]) - , poseidon2_B_44_2(il[431]) - , poseidon2_B_44_3(il[432]) - , poseidon2_B_45_0(il[433]) - , poseidon2_B_45_1(il[434]) - , poseidon2_B_45_2(il[435]) - , poseidon2_B_45_3(il[436]) - , poseidon2_B_46_0(il[437]) - , poseidon2_B_46_1(il[438]) - , poseidon2_B_46_2(il[439]) - , poseidon2_B_46_3(il[440]) - , poseidon2_B_47_0(il[441]) - , poseidon2_B_47_1(il[442]) - , poseidon2_B_47_2(il[443]) - , poseidon2_B_47_3(il[444]) - , poseidon2_B_48_0(il[445]) - , poseidon2_B_48_1(il[446]) - , poseidon2_B_48_2(il[447]) - , poseidon2_B_48_3(il[448]) - , poseidon2_B_49_0(il[449]) - , poseidon2_B_49_1(il[450]) - , poseidon2_B_49_2(il[451]) - , poseidon2_B_49_3(il[452]) - , poseidon2_B_4_0(il[453]) - , poseidon2_B_4_1(il[454]) - , poseidon2_B_4_2(il[455]) - , poseidon2_B_4_3(il[456]) - , poseidon2_B_50_0(il[457]) - , poseidon2_B_50_1(il[458]) - , poseidon2_B_50_2(il[459]) - , poseidon2_B_50_3(il[460]) - , poseidon2_B_51_0(il[461]) - , poseidon2_B_51_1(il[462]) - , poseidon2_B_51_2(il[463]) - , poseidon2_B_51_3(il[464]) - , poseidon2_B_52_0(il[465]) - , poseidon2_B_52_1(il[466]) - , poseidon2_B_52_2(il[467]) - , poseidon2_B_52_3(il[468]) - , poseidon2_B_53_0(il[469]) - , poseidon2_B_53_1(il[470]) - , poseidon2_B_53_2(il[471]) - , poseidon2_B_53_3(il[472]) - , poseidon2_B_54_0(il[473]) - , poseidon2_B_54_1(il[474]) - , poseidon2_B_54_2(il[475]) - , poseidon2_B_54_3(il[476]) - , poseidon2_B_55_0(il[477]) - , poseidon2_B_55_1(il[478]) - , poseidon2_B_55_2(il[479]) - , poseidon2_B_55_3(il[480]) - , poseidon2_B_56_0(il[481]) - , poseidon2_B_56_1(il[482]) - , poseidon2_B_56_2(il[483]) - , poseidon2_B_56_3(il[484]) - , poseidon2_B_57_0(il[485]) - , poseidon2_B_57_1(il[486]) - , poseidon2_B_57_2(il[487]) - , poseidon2_B_57_3(il[488]) - , poseidon2_B_58_0(il[489]) - , poseidon2_B_58_1(il[490]) - , poseidon2_B_58_2(il[491]) - , poseidon2_B_58_3(il[492]) - , poseidon2_B_59_0(il[493]) - , poseidon2_B_59_1(il[494]) - , poseidon2_B_59_2(il[495]) - , poseidon2_B_59_3(il[496]) - , poseidon2_B_5_0(il[497]) - , poseidon2_B_5_1(il[498]) - , poseidon2_B_5_2(il[499]) - , poseidon2_B_5_3(il[500]) - , poseidon2_B_6_0(il[501]) - , poseidon2_B_6_1(il[502]) - , poseidon2_B_6_2(il[503]) - , poseidon2_B_6_3(il[504]) - , poseidon2_B_7_0(il[505]) - , poseidon2_B_7_1(il[506]) - , poseidon2_B_7_2(il[507]) - , poseidon2_B_7_3(il[508]) - , poseidon2_B_8_0(il[509]) - , poseidon2_B_8_1(il[510]) - , poseidon2_B_8_2(il[511]) - , poseidon2_B_8_3(il[512]) - , poseidon2_B_9_0(il[513]) - , poseidon2_B_9_1(il[514]) - , poseidon2_B_9_2(il[515]) - , poseidon2_B_9_3(il[516]) - , poseidon2_EXT_LAYER_4(il[517]) - , poseidon2_EXT_LAYER_5(il[518]) - , poseidon2_EXT_LAYER_6(il[519]) - , poseidon2_EXT_LAYER_7(il[520]) - , poseidon2_T_0_4(il[521]) - , poseidon2_T_0_5(il[522]) - , poseidon2_T_0_6(il[523]) - , poseidon2_T_0_7(il[524]) - , poseidon2_T_1_4(il[525]) - , poseidon2_T_1_5(il[526]) - , poseidon2_T_1_6(il[527]) - , poseidon2_T_1_7(il[528]) - , poseidon2_T_2_4(il[529]) - , poseidon2_T_2_5(il[530]) - , poseidon2_T_2_6(il[531]) - , poseidon2_T_2_7(il[532]) - , poseidon2_T_3_4(il[533]) - , poseidon2_T_3_5(il[534]) - , poseidon2_T_3_6(il[535]) - , poseidon2_T_3_7(il[536]) - , poseidon2_T_60_4(il[537]) - , poseidon2_T_60_5(il[538]) - , poseidon2_T_60_6(il[539]) - , poseidon2_T_60_7(il[540]) - , poseidon2_T_61_4(il[541]) - , poseidon2_T_61_5(il[542]) - , poseidon2_T_61_6(il[543]) - , poseidon2_T_61_7(il[544]) - , poseidon2_T_62_4(il[545]) - , poseidon2_T_62_5(il[546]) - , poseidon2_T_62_6(il[547]) - , poseidon2_T_62_7(il[548]) - , poseidon2_T_63_4(il[549]) - , poseidon2_T_63_5(il[550]) - , poseidon2_T_63_6(il[551]) - , poseidon2_T_63_7(il[552]) - , poseidon2_a_0(il[553]) - , poseidon2_a_1(il[554]) - , poseidon2_a_2(il[555]) - , poseidon2_a_3(il[556]) - , poseidon2_b_0(il[557]) - , poseidon2_b_1(il[558]) - , poseidon2_b_2(il[559]) - , poseidon2_b_3(il[560]) - , poseidon2_clk(il[561]) - , poseidon2_full_a_0(il[562]) - , poseidon2_full_a_1(il[563]) - , poseidon2_full_a_2(il[564]) - , poseidon2_full_a_3(il[565]) - , poseidon2_full_b_0(il[566]) - , poseidon2_full_b_1(il[567]) - , poseidon2_full_b_2(il[568]) - , poseidon2_full_b_3(il[569]) - , poseidon2_full_clk(il[570]) - , poseidon2_full_end_poseidon(il[571]) - , poseidon2_full_execute_poseidon_perm(il[572]) - , poseidon2_full_input_0(il[573]) - , poseidon2_full_input_1(il[574]) - , poseidon2_full_input_2(il[575]) - , poseidon2_full_input_len(il[576]) - , poseidon2_full_num_perm_rounds_rem(il[577]) - , poseidon2_full_num_perm_rounds_rem_inv(il[578]) - , poseidon2_full_output(il[579]) - , poseidon2_full_padding(il[580]) - , poseidon2_full_sel_poseidon(il[581]) - , poseidon2_full_start_poseidon(il[582]) - , poseidon2_input_addr(il[583]) - , poseidon2_mem_addr_read_a(il[584]) - , poseidon2_mem_addr_read_b(il[585]) - , poseidon2_mem_addr_read_c(il[586]) - , poseidon2_mem_addr_read_d(il[587]) - , poseidon2_mem_addr_write_a(il[588]) - , poseidon2_mem_addr_write_b(il[589]) - , poseidon2_mem_addr_write_c(il[590]) - , poseidon2_mem_addr_write_d(il[591]) - , poseidon2_output_addr(il[592]) - , poseidon2_sel_poseidon_perm(il[593]) - , poseidon2_sel_poseidon_perm_immediate(il[594]) - , poseidon2_sel_poseidon_perm_mem_op(il[595]) - , poseidon2_space_id(il[596]) - , range_check_alu_rng_chk(il[597]) - , range_check_clk(il[598]) - , range_check_cmp_hi_bits_rng_chk(il[599]) - , range_check_cmp_lo_bits_rng_chk(il[600]) - , range_check_dyn_diff(il[601]) - , range_check_dyn_rng_chk_bits(il[602]) - , range_check_dyn_rng_chk_pow_2(il[603]) - , range_check_gas_da_rng_chk(il[604]) - , range_check_gas_l2_rng_chk(il[605]) - , range_check_is_lte_u112(il[606]) - , range_check_is_lte_u128(il[607]) - , range_check_is_lte_u16(il[608]) - , range_check_is_lte_u32(il[609]) - , range_check_is_lte_u48(il[610]) - , range_check_is_lte_u64(il[611]) - , range_check_is_lte_u80(il[612]) - , range_check_is_lte_u96(il[613]) - , range_check_mem_rng_chk(il[614]) - , range_check_rng_chk_bits(il[615]) - , range_check_sel_lookup_0(il[616]) - , range_check_sel_lookup_1(il[617]) - , range_check_sel_lookup_2(il[618]) - , range_check_sel_lookup_3(il[619]) - , range_check_sel_lookup_4(il[620]) - , range_check_sel_lookup_5(il[621]) - , range_check_sel_lookup_6(il[622]) - , range_check_sel_rng_chk(il[623]) - , range_check_u16_r0(il[624]) - , range_check_u16_r1(il[625]) - , range_check_u16_r2(il[626]) - , range_check_u16_r3(il[627]) - , range_check_u16_r4(il[628]) - , range_check_u16_r5(il[629]) - , range_check_u16_r6(il[630]) - , range_check_u16_r7(il[631]) - , range_check_value(il[632]) - , sha256_clk(il[633]) - , sha256_input(il[634]) - , sha256_output(il[635]) - , sha256_sel_sha256_compression(il[636]) - , sha256_state(il[637]) - , slice_addr(il[638]) - , slice_clk(il[639]) - , slice_cnt(il[640]) - , slice_col_offset(il[641]) - , slice_one_min_inv(il[642]) - , slice_sel_cd_cpy(il[643]) - , slice_sel_mem_active(il[644]) - , slice_sel_return(il[645]) - , slice_sel_start(il[646]) - , slice_space_id(il[647]) - , slice_val(il[648]) - , lookup_rng_chk_pow_2_counts(il[649]) - , lookup_rng_chk_diff_counts(il[650]) - , lookup_rng_chk_0_counts(il[651]) - , lookup_rng_chk_1_counts(il[652]) - , lookup_rng_chk_2_counts(il[653]) - , lookup_rng_chk_3_counts(il[654]) - , lookup_rng_chk_4_counts(il[655]) - , lookup_rng_chk_5_counts(il[656]) - , lookup_rng_chk_6_counts(il[657]) - , lookup_rng_chk_7_counts(il[658]) - , lookup_pow_2_0_counts(il[659]) - , lookup_pow_2_1_counts(il[660]) - , lookup_byte_lengths_counts(il[661]) - , lookup_byte_operations_counts(il[662]) - , lookup_opcode_gas_counts(il[663]) - , kernel_output_lookup_counts(il[664]) - , lookup_into_kernel_counts(il[665]) - , lookup_cd_value_counts(il[666]) - , lookup_ret_value_counts(il[667]) - , incl_main_tag_err_counts(il[668]) - , incl_mem_tag_err_counts(il[669]) - , perm_rng_mem_inv(il[670]) - , perm_rng_cmp_lo_inv(il[671]) - , perm_rng_cmp_hi_inv(il[672]) - , perm_rng_alu_inv(il[673]) - , perm_cmp_alu_inv(il[674]) - , perm_rng_gas_l2_inv(il[675]) - , perm_rng_gas_da_inv(il[676]) - , perm_l2_start_gas_inv(il[677]) - , perm_da_start_gas_inv(il[678]) - , perm_l2_end_gas_inv(il[679]) - , perm_da_end_gas_inv(il[680]) - , perm_pos_mem_read_a_inv(il[681]) - , perm_pos_mem_read_b_inv(il[682]) - , perm_pos_mem_read_c_inv(il[683]) - , perm_pos_mem_read_d_inv(il[684]) - , perm_pos_mem_write_a_inv(il[685]) - , perm_pos_mem_write_b_inv(il[686]) - , perm_pos_mem_write_c_inv(il[687]) - , perm_pos_mem_write_d_inv(il[688]) - , perm_pos2_fixed_pos2_perm_inv(il[689]) - , perm_slice_mem_inv(il[690]) - , perm_main_alu_inv(il[691]) - , perm_main_bin_inv(il[692]) - , perm_main_conv_inv(il[693]) - , perm_main_sha256_inv(il[694]) - , perm_main_pos2_perm_inv(il[695]) - , perm_main_slice_inv(il[696]) - , perm_main_mem_a_inv(il[697]) - , perm_main_mem_b_inv(il[698]) - , perm_main_mem_c_inv(il[699]) - , perm_main_mem_d_inv(il[700]) - , perm_main_mem_ind_addr_a_inv(il[701]) - , perm_main_mem_ind_addr_b_inv(il[702]) - , perm_main_mem_ind_addr_c_inv(il[703]) - , perm_main_mem_ind_addr_d_inv(il[704]) - , lookup_rng_chk_pow_2_inv(il[705]) - , lookup_rng_chk_diff_inv(il[706]) - , lookup_rng_chk_0_inv(il[707]) - , lookup_rng_chk_1_inv(il[708]) - , lookup_rng_chk_2_inv(il[709]) - , lookup_rng_chk_3_inv(il[710]) - , lookup_rng_chk_4_inv(il[711]) - , lookup_rng_chk_5_inv(il[712]) - , lookup_rng_chk_6_inv(il[713]) - , lookup_rng_chk_7_inv(il[714]) - , lookup_pow_2_0_inv(il[715]) - , lookup_pow_2_1_inv(il[716]) - , lookup_byte_lengths_inv(il[717]) - , lookup_byte_operations_inv(il[718]) - , lookup_opcode_gas_inv(il[719]) - , kernel_output_lookup_inv(il[720]) - , lookup_into_kernel_inv(il[721]) - , lookup_cd_value_inv(il[722]) - , lookup_ret_value_inv(il[723]) - , incl_main_tag_err_inv(il[724]) - , incl_mem_tag_err_inv(il[725]) - , binary_acc_ia_shift(il[726]) - , binary_acc_ib_shift(il[727]) - , binary_acc_ic_shift(il[728]) - , binary_mem_tag_ctr_shift(il[729]) - , binary_op_id_shift(il[730]) - , cmp_a_hi_shift(il[731]) - , cmp_a_lo_shift(il[732]) - , cmp_b_hi_shift(il[733]) - , cmp_b_lo_shift(il[734]) - , cmp_cmp_rng_ctr_shift(il[735]) - , cmp_op_gt_shift(il[736]) - , cmp_p_sub_a_hi_shift(il[737]) - , cmp_p_sub_a_lo_shift(il[738]) - , cmp_p_sub_b_hi_shift(il[739]) - , cmp_p_sub_b_lo_shift(il[740]) - , cmp_sel_rng_chk_shift(il[741]) - , main_da_gas_remaining_shift(il[742]) - , main_emit_l2_to_l1_msg_write_offset_shift(il[743]) - , main_emit_note_hash_write_offset_shift(il[744]) - , main_emit_nullifier_write_offset_shift(il[745]) - , main_emit_unencrypted_log_write_offset_shift(il[746]) - , main_internal_return_ptr_shift(il[747]) - , main_l1_to_l2_msg_exists_write_offset_shift(il[748]) - , main_l2_gas_remaining_shift(il[749]) - , main_note_hash_exist_write_offset_shift(il[750]) - , main_nullifier_exists_write_offset_shift(il[751]) - , main_nullifier_non_exists_write_offset_shift(il[752]) - , main_pc_shift(il[753]) - , main_sel_execution_end_shift(il[754]) - , main_sel_execution_row_shift(il[755]) - , main_sload_write_offset_shift(il[756]) - , main_sstore_write_offset_shift(il[757]) - , mem_glob_addr_shift(il[758]) - , mem_rw_shift(il[759]) - , mem_sel_mem_shift(il[760]) - , mem_tag_shift(il[761]) - , mem_tsp_shift(il[762]) - , mem_val_shift(il[763]) - , poseidon2_full_a_0_shift(il[764]) - , poseidon2_full_a_1_shift(il[765]) - , poseidon2_full_a_2_shift(il[766]) - , poseidon2_full_a_3_shift(il[767]) - , poseidon2_full_execute_poseidon_perm_shift(il[768]) - , poseidon2_full_input_0_shift(il[769]) - , poseidon2_full_input_1_shift(il[770]) - , poseidon2_full_input_2_shift(il[771]) - , poseidon2_full_num_perm_rounds_rem_shift(il[772]) - , poseidon2_full_sel_poseidon_shift(il[773]) - , poseidon2_full_start_poseidon_shift(il[774]) - , slice_addr_shift(il[775]) - , slice_clk_shift(il[776]) - , slice_cnt_shift(il[777]) - , slice_col_offset_shift(il[778]) - , slice_sel_cd_cpy_shift(il[779]) - , slice_sel_mem_active_shift(il[780]) - , slice_sel_return_shift(il[781]) - , slice_sel_start_shift(il[782]) - , slice_space_id_shift(il[783]) + , merkle_tree_clk(il[293]) + , merkle_tree_diff_inv(il[294]) + , merkle_tree_expected_tree_root(il[295]) + , merkle_tree_is_member(il[296]) + , merkle_tree_latch(il[297]) + , merkle_tree_leaf_index(il[298]) + , merkle_tree_leaf_index_is_even(il[299]) + , merkle_tree_leaf_value(il[300]) + , merkle_tree_left_hash(il[301]) + , merkle_tree_output_hash(il[302]) + , merkle_tree_path_len(il[303]) + , merkle_tree_path_len_inv(il[304]) + , merkle_tree_right_hash(il[305]) + , merkle_tree_sel_membership_op(il[306]) + , merkle_tree_sel_merkle_tree(il[307]) + , merkle_tree_sel_update_op(il[308]) + , merkle_tree_sibling_value(il[309]) + , poseidon2_B_10_0(il[310]) + , poseidon2_B_10_1(il[311]) + , poseidon2_B_10_2(il[312]) + , poseidon2_B_10_3(il[313]) + , poseidon2_B_11_0(il[314]) + , poseidon2_B_11_1(il[315]) + , poseidon2_B_11_2(il[316]) + , poseidon2_B_11_3(il[317]) + , poseidon2_B_12_0(il[318]) + , poseidon2_B_12_1(il[319]) + , poseidon2_B_12_2(il[320]) + , poseidon2_B_12_3(il[321]) + , poseidon2_B_13_0(il[322]) + , poseidon2_B_13_1(il[323]) + , poseidon2_B_13_2(il[324]) + , poseidon2_B_13_3(il[325]) + , poseidon2_B_14_0(il[326]) + , poseidon2_B_14_1(il[327]) + , poseidon2_B_14_2(il[328]) + , poseidon2_B_14_3(il[329]) + , poseidon2_B_15_0(il[330]) + , poseidon2_B_15_1(il[331]) + , poseidon2_B_15_2(il[332]) + , poseidon2_B_15_3(il[333]) + , poseidon2_B_16_0(il[334]) + , poseidon2_B_16_1(il[335]) + , poseidon2_B_16_2(il[336]) + , poseidon2_B_16_3(il[337]) + , poseidon2_B_17_0(il[338]) + , poseidon2_B_17_1(il[339]) + , poseidon2_B_17_2(il[340]) + , poseidon2_B_17_3(il[341]) + , poseidon2_B_18_0(il[342]) + , poseidon2_B_18_1(il[343]) + , poseidon2_B_18_2(il[344]) + , poseidon2_B_18_3(il[345]) + , poseidon2_B_19_0(il[346]) + , poseidon2_B_19_1(il[347]) + , poseidon2_B_19_2(il[348]) + , poseidon2_B_19_3(il[349]) + , poseidon2_B_20_0(il[350]) + , poseidon2_B_20_1(il[351]) + , poseidon2_B_20_2(il[352]) + , poseidon2_B_20_3(il[353]) + , poseidon2_B_21_0(il[354]) + , poseidon2_B_21_1(il[355]) + , poseidon2_B_21_2(il[356]) + , poseidon2_B_21_3(il[357]) + , poseidon2_B_22_0(il[358]) + , poseidon2_B_22_1(il[359]) + , poseidon2_B_22_2(il[360]) + , poseidon2_B_22_3(il[361]) + , poseidon2_B_23_0(il[362]) + , poseidon2_B_23_1(il[363]) + , poseidon2_B_23_2(il[364]) + , poseidon2_B_23_3(il[365]) + , poseidon2_B_24_0(il[366]) + , poseidon2_B_24_1(il[367]) + , poseidon2_B_24_2(il[368]) + , poseidon2_B_24_3(il[369]) + , poseidon2_B_25_0(il[370]) + , poseidon2_B_25_1(il[371]) + , poseidon2_B_25_2(il[372]) + , poseidon2_B_25_3(il[373]) + , poseidon2_B_26_0(il[374]) + , poseidon2_B_26_1(il[375]) + , poseidon2_B_26_2(il[376]) + , poseidon2_B_26_3(il[377]) + , poseidon2_B_27_0(il[378]) + , poseidon2_B_27_1(il[379]) + , poseidon2_B_27_2(il[380]) + , poseidon2_B_27_3(il[381]) + , poseidon2_B_28_0(il[382]) + , poseidon2_B_28_1(il[383]) + , poseidon2_B_28_2(il[384]) + , poseidon2_B_28_3(il[385]) + , poseidon2_B_29_0(il[386]) + , poseidon2_B_29_1(il[387]) + , poseidon2_B_29_2(il[388]) + , poseidon2_B_29_3(il[389]) + , poseidon2_B_30_0(il[390]) + , poseidon2_B_30_1(il[391]) + , poseidon2_B_30_2(il[392]) + , poseidon2_B_30_3(il[393]) + , poseidon2_B_31_0(il[394]) + , poseidon2_B_31_1(il[395]) + , poseidon2_B_31_2(il[396]) + , poseidon2_B_31_3(il[397]) + , poseidon2_B_32_0(il[398]) + , poseidon2_B_32_1(il[399]) + , poseidon2_B_32_2(il[400]) + , poseidon2_B_32_3(il[401]) + , poseidon2_B_33_0(il[402]) + , poseidon2_B_33_1(il[403]) + , poseidon2_B_33_2(il[404]) + , poseidon2_B_33_3(il[405]) + , poseidon2_B_34_0(il[406]) + , poseidon2_B_34_1(il[407]) + , poseidon2_B_34_2(il[408]) + , poseidon2_B_34_3(il[409]) + , poseidon2_B_35_0(il[410]) + , poseidon2_B_35_1(il[411]) + , poseidon2_B_35_2(il[412]) + , poseidon2_B_35_3(il[413]) + , poseidon2_B_36_0(il[414]) + , poseidon2_B_36_1(il[415]) + , poseidon2_B_36_2(il[416]) + , poseidon2_B_36_3(il[417]) + , poseidon2_B_37_0(il[418]) + , poseidon2_B_37_1(il[419]) + , poseidon2_B_37_2(il[420]) + , poseidon2_B_37_3(il[421]) + , poseidon2_B_38_0(il[422]) + , poseidon2_B_38_1(il[423]) + , poseidon2_B_38_2(il[424]) + , poseidon2_B_38_3(il[425]) + , poseidon2_B_39_0(il[426]) + , poseidon2_B_39_1(il[427]) + , poseidon2_B_39_2(il[428]) + , poseidon2_B_39_3(il[429]) + , poseidon2_B_40_0(il[430]) + , poseidon2_B_40_1(il[431]) + , poseidon2_B_40_2(il[432]) + , poseidon2_B_40_3(il[433]) + , poseidon2_B_41_0(il[434]) + , poseidon2_B_41_1(il[435]) + , poseidon2_B_41_2(il[436]) + , poseidon2_B_41_3(il[437]) + , poseidon2_B_42_0(il[438]) + , poseidon2_B_42_1(il[439]) + , poseidon2_B_42_2(il[440]) + , poseidon2_B_42_3(il[441]) + , poseidon2_B_43_0(il[442]) + , poseidon2_B_43_1(il[443]) + , poseidon2_B_43_2(il[444]) + , poseidon2_B_43_3(il[445]) + , poseidon2_B_44_0(il[446]) + , poseidon2_B_44_1(il[447]) + , poseidon2_B_44_2(il[448]) + , poseidon2_B_44_3(il[449]) + , poseidon2_B_45_0(il[450]) + , poseidon2_B_45_1(il[451]) + , poseidon2_B_45_2(il[452]) + , poseidon2_B_45_3(il[453]) + , poseidon2_B_46_0(il[454]) + , poseidon2_B_46_1(il[455]) + , poseidon2_B_46_2(il[456]) + , poseidon2_B_46_3(il[457]) + , poseidon2_B_47_0(il[458]) + , poseidon2_B_47_1(il[459]) + , poseidon2_B_47_2(il[460]) + , poseidon2_B_47_3(il[461]) + , poseidon2_B_48_0(il[462]) + , poseidon2_B_48_1(il[463]) + , poseidon2_B_48_2(il[464]) + , poseidon2_B_48_3(il[465]) + , poseidon2_B_49_0(il[466]) + , poseidon2_B_49_1(il[467]) + , poseidon2_B_49_2(il[468]) + , poseidon2_B_49_3(il[469]) + , poseidon2_B_4_0(il[470]) + , poseidon2_B_4_1(il[471]) + , poseidon2_B_4_2(il[472]) + , poseidon2_B_4_3(il[473]) + , poseidon2_B_50_0(il[474]) + , poseidon2_B_50_1(il[475]) + , poseidon2_B_50_2(il[476]) + , poseidon2_B_50_3(il[477]) + , poseidon2_B_51_0(il[478]) + , poseidon2_B_51_1(il[479]) + , poseidon2_B_51_2(il[480]) + , poseidon2_B_51_3(il[481]) + , poseidon2_B_52_0(il[482]) + , poseidon2_B_52_1(il[483]) + , poseidon2_B_52_2(il[484]) + , poseidon2_B_52_3(il[485]) + , poseidon2_B_53_0(il[486]) + , poseidon2_B_53_1(il[487]) + , poseidon2_B_53_2(il[488]) + , poseidon2_B_53_3(il[489]) + , poseidon2_B_54_0(il[490]) + , poseidon2_B_54_1(il[491]) + , poseidon2_B_54_2(il[492]) + , poseidon2_B_54_3(il[493]) + , poseidon2_B_55_0(il[494]) + , poseidon2_B_55_1(il[495]) + , poseidon2_B_55_2(il[496]) + , poseidon2_B_55_3(il[497]) + , poseidon2_B_56_0(il[498]) + , poseidon2_B_56_1(il[499]) + , poseidon2_B_56_2(il[500]) + , poseidon2_B_56_3(il[501]) + , poseidon2_B_57_0(il[502]) + , poseidon2_B_57_1(il[503]) + , poseidon2_B_57_2(il[504]) + , poseidon2_B_57_3(il[505]) + , poseidon2_B_58_0(il[506]) + , poseidon2_B_58_1(il[507]) + , poseidon2_B_58_2(il[508]) + , poseidon2_B_58_3(il[509]) + , poseidon2_B_59_0(il[510]) + , poseidon2_B_59_1(il[511]) + , poseidon2_B_59_2(il[512]) + , poseidon2_B_59_3(il[513]) + , poseidon2_B_5_0(il[514]) + , poseidon2_B_5_1(il[515]) + , poseidon2_B_5_2(il[516]) + , poseidon2_B_5_3(il[517]) + , poseidon2_B_6_0(il[518]) + , poseidon2_B_6_1(il[519]) + , poseidon2_B_6_2(il[520]) + , poseidon2_B_6_3(il[521]) + , poseidon2_B_7_0(il[522]) + , poseidon2_B_7_1(il[523]) + , poseidon2_B_7_2(il[524]) + , poseidon2_B_7_3(il[525]) + , poseidon2_B_8_0(il[526]) + , poseidon2_B_8_1(il[527]) + , poseidon2_B_8_2(il[528]) + , poseidon2_B_8_3(il[529]) + , poseidon2_B_9_0(il[530]) + , poseidon2_B_9_1(il[531]) + , poseidon2_B_9_2(il[532]) + , poseidon2_B_9_3(il[533]) + , poseidon2_EXT_LAYER_4(il[534]) + , poseidon2_EXT_LAYER_5(il[535]) + , poseidon2_EXT_LAYER_6(il[536]) + , poseidon2_EXT_LAYER_7(il[537]) + , poseidon2_T_0_4(il[538]) + , poseidon2_T_0_5(il[539]) + , poseidon2_T_0_6(il[540]) + , poseidon2_T_0_7(il[541]) + , poseidon2_T_1_4(il[542]) + , poseidon2_T_1_5(il[543]) + , poseidon2_T_1_6(il[544]) + , poseidon2_T_1_7(il[545]) + , poseidon2_T_2_4(il[546]) + , poseidon2_T_2_5(il[547]) + , poseidon2_T_2_6(il[548]) + , poseidon2_T_2_7(il[549]) + , poseidon2_T_3_4(il[550]) + , poseidon2_T_3_5(il[551]) + , poseidon2_T_3_6(il[552]) + , poseidon2_T_3_7(il[553]) + , poseidon2_T_60_4(il[554]) + , poseidon2_T_60_5(il[555]) + , poseidon2_T_60_6(il[556]) + , poseidon2_T_60_7(il[557]) + , poseidon2_T_61_4(il[558]) + , poseidon2_T_61_5(il[559]) + , poseidon2_T_61_6(il[560]) + , poseidon2_T_61_7(il[561]) + , poseidon2_T_62_4(il[562]) + , poseidon2_T_62_5(il[563]) + , poseidon2_T_62_6(il[564]) + , poseidon2_T_62_7(il[565]) + , poseidon2_T_63_4(il[566]) + , poseidon2_T_63_5(il[567]) + , poseidon2_T_63_6(il[568]) + , poseidon2_T_63_7(il[569]) + , poseidon2_a_0(il[570]) + , poseidon2_a_1(il[571]) + , poseidon2_a_2(il[572]) + , poseidon2_a_3(il[573]) + , poseidon2_b_0(il[574]) + , poseidon2_b_1(il[575]) + , poseidon2_b_2(il[576]) + , poseidon2_b_3(il[577]) + , poseidon2_clk(il[578]) + , poseidon2_full_a_0(il[579]) + , poseidon2_full_a_1(il[580]) + , poseidon2_full_a_2(il[581]) + , poseidon2_full_a_3(il[582]) + , poseidon2_full_b_0(il[583]) + , poseidon2_full_b_1(il[584]) + , poseidon2_full_b_2(il[585]) + , poseidon2_full_b_3(il[586]) + , poseidon2_full_clk(il[587]) + , poseidon2_full_end_poseidon(il[588]) + , poseidon2_full_execute_poseidon_perm(il[589]) + , poseidon2_full_input_0(il[590]) + , poseidon2_full_input_1(il[591]) + , poseidon2_full_input_2(il[592]) + , poseidon2_full_input_len(il[593]) + , poseidon2_full_num_perm_rounds_rem(il[594]) + , poseidon2_full_num_perm_rounds_rem_inv(il[595]) + , poseidon2_full_output(il[596]) + , poseidon2_full_padding(il[597]) + , poseidon2_full_sel_merkle_tree(il[598]) + , poseidon2_full_sel_poseidon(il[599]) + , poseidon2_full_start_poseidon(il[600]) + , poseidon2_input_addr(il[601]) + , poseidon2_mem_addr_read_a(il[602]) + , poseidon2_mem_addr_read_b(il[603]) + , poseidon2_mem_addr_read_c(il[604]) + , poseidon2_mem_addr_read_d(il[605]) + , poseidon2_mem_addr_write_a(il[606]) + , poseidon2_mem_addr_write_b(il[607]) + , poseidon2_mem_addr_write_c(il[608]) + , poseidon2_mem_addr_write_d(il[609]) + , poseidon2_output_addr(il[610]) + , poseidon2_sel_poseidon_perm(il[611]) + , poseidon2_sel_poseidon_perm_immediate(il[612]) + , poseidon2_sel_poseidon_perm_mem_op(il[613]) + , poseidon2_space_id(il[614]) + , range_check_alu_rng_chk(il[615]) + , range_check_clk(il[616]) + , range_check_cmp_hi_bits_rng_chk(il[617]) + , range_check_cmp_lo_bits_rng_chk(il[618]) + , range_check_dyn_diff(il[619]) + , range_check_dyn_rng_chk_bits(il[620]) + , range_check_dyn_rng_chk_pow_2(il[621]) + , range_check_gas_da_rng_chk(il[622]) + , range_check_gas_l2_rng_chk(il[623]) + , range_check_is_lte_u112(il[624]) + , range_check_is_lte_u128(il[625]) + , range_check_is_lte_u16(il[626]) + , range_check_is_lte_u32(il[627]) + , range_check_is_lte_u48(il[628]) + , range_check_is_lte_u64(il[629]) + , range_check_is_lte_u80(il[630]) + , range_check_is_lte_u96(il[631]) + , range_check_mem_rng_chk(il[632]) + , range_check_rng_chk_bits(il[633]) + , range_check_sel_lookup_0(il[634]) + , range_check_sel_lookup_1(il[635]) + , range_check_sel_lookup_2(il[636]) + , range_check_sel_lookup_3(il[637]) + , range_check_sel_lookup_4(il[638]) + , range_check_sel_lookup_5(il[639]) + , range_check_sel_lookup_6(il[640]) + , range_check_sel_rng_chk(il[641]) + , range_check_u16_r0(il[642]) + , range_check_u16_r1(il[643]) + , range_check_u16_r2(il[644]) + , range_check_u16_r3(il[645]) + , range_check_u16_r4(il[646]) + , range_check_u16_r5(il[647]) + , range_check_u16_r6(il[648]) + , range_check_u16_r7(il[649]) + , range_check_value(il[650]) + , sha256_clk(il[651]) + , sha256_input(il[652]) + , sha256_output(il[653]) + , sha256_sel_sha256_compression(il[654]) + , sha256_state(il[655]) + , slice_addr(il[656]) + , slice_clk(il[657]) + , slice_cnt(il[658]) + , slice_col_offset(il[659]) + , slice_one_min_inv(il[660]) + , slice_sel_cd_cpy(il[661]) + , slice_sel_mem_active(il[662]) + , slice_sel_return(il[663]) + , slice_sel_start(il[664]) + , slice_space_id(il[665]) + , slice_val(il[666]) + , lookup_rng_chk_pow_2_counts(il[667]) + , lookup_rng_chk_diff_counts(il[668]) + , lookup_rng_chk_0_counts(il[669]) + , lookup_rng_chk_1_counts(il[670]) + , lookup_rng_chk_2_counts(il[671]) + , lookup_rng_chk_3_counts(il[672]) + , lookup_rng_chk_4_counts(il[673]) + , lookup_rng_chk_5_counts(il[674]) + , lookup_rng_chk_6_counts(il[675]) + , lookup_rng_chk_7_counts(il[676]) + , lookup_pow_2_0_counts(il[677]) + , lookup_pow_2_1_counts(il[678]) + , lookup_byte_lengths_counts(il[679]) + , lookup_byte_operations_counts(il[680]) + , lookup_opcode_gas_counts(il[681]) + , kernel_output_lookup_counts(il[682]) + , lookup_into_kernel_counts(il[683]) + , lookup_cd_value_counts(il[684]) + , lookup_ret_value_counts(il[685]) + , incl_main_tag_err_counts(il[686]) + , incl_mem_tag_err_counts(il[687]) + , perm_rng_mem_inv(il[688]) + , perm_rng_cmp_lo_inv(il[689]) + , perm_rng_cmp_hi_inv(il[690]) + , perm_rng_alu_inv(il[691]) + , perm_cmp_alu_inv(il[692]) + , perm_rng_gas_l2_inv(il[693]) + , perm_rng_gas_da_inv(il[694]) + , perm_l2_start_gas_inv(il[695]) + , perm_da_start_gas_inv(il[696]) + , perm_l2_end_gas_inv(il[697]) + , perm_da_end_gas_inv(il[698]) + , perm_pos_mem_read_a_inv(il[699]) + , perm_pos_mem_read_b_inv(il[700]) + , perm_pos_mem_read_c_inv(il[701]) + , perm_pos_mem_read_d_inv(il[702]) + , perm_pos_mem_write_a_inv(il[703]) + , perm_pos_mem_write_b_inv(il[704]) + , perm_pos_mem_write_c_inv(il[705]) + , perm_pos_mem_write_d_inv(il[706]) + , perm_pos2_fixed_pos2_perm_inv(il[707]) + , perm_slice_mem_inv(il[708]) + , perm_merkle_poseidon2_inv(il[709]) + , perm_main_alu_inv(il[710]) + , perm_main_bin_inv(il[711]) + , perm_main_conv_inv(il[712]) + , perm_main_sha256_inv(il[713]) + , perm_main_pos2_perm_inv(il[714]) + , perm_main_slice_inv(il[715]) + , perm_main_mem_a_inv(il[716]) + , perm_main_mem_b_inv(il[717]) + , perm_main_mem_c_inv(il[718]) + , perm_main_mem_d_inv(il[719]) + , perm_main_mem_ind_addr_a_inv(il[720]) + , perm_main_mem_ind_addr_b_inv(il[721]) + , perm_main_mem_ind_addr_c_inv(il[722]) + , perm_main_mem_ind_addr_d_inv(il[723]) + , lookup_rng_chk_pow_2_inv(il[724]) + , lookup_rng_chk_diff_inv(il[725]) + , lookup_rng_chk_0_inv(il[726]) + , lookup_rng_chk_1_inv(il[727]) + , lookup_rng_chk_2_inv(il[728]) + , lookup_rng_chk_3_inv(il[729]) + , lookup_rng_chk_4_inv(il[730]) + , lookup_rng_chk_5_inv(il[731]) + , lookup_rng_chk_6_inv(il[732]) + , lookup_rng_chk_7_inv(il[733]) + , lookup_pow_2_0_inv(il[734]) + , lookup_pow_2_1_inv(il[735]) + , lookup_byte_lengths_inv(il[736]) + , lookup_byte_operations_inv(il[737]) + , lookup_opcode_gas_inv(il[738]) + , kernel_output_lookup_inv(il[739]) + , lookup_into_kernel_inv(il[740]) + , lookup_cd_value_inv(il[741]) + , lookup_ret_value_inv(il[742]) + , incl_main_tag_err_inv(il[743]) + , incl_mem_tag_err_inv(il[744]) + , binary_acc_ia_shift(il[745]) + , binary_acc_ib_shift(il[746]) + , binary_acc_ic_shift(il[747]) + , binary_mem_tag_ctr_shift(il[748]) + , binary_op_id_shift(il[749]) + , cmp_a_hi_shift(il[750]) + , cmp_a_lo_shift(il[751]) + , cmp_b_hi_shift(il[752]) + , cmp_b_lo_shift(il[753]) + , cmp_cmp_rng_ctr_shift(il[754]) + , cmp_op_gt_shift(il[755]) + , cmp_p_sub_a_hi_shift(il[756]) + , cmp_p_sub_a_lo_shift(il[757]) + , cmp_p_sub_b_hi_shift(il[758]) + , cmp_p_sub_b_lo_shift(il[759]) + , cmp_sel_rng_chk_shift(il[760]) + , main_da_gas_remaining_shift(il[761]) + , main_emit_l2_to_l1_msg_write_offset_shift(il[762]) + , main_emit_note_hash_write_offset_shift(il[763]) + , main_emit_nullifier_write_offset_shift(il[764]) + , main_emit_unencrypted_log_write_offset_shift(il[765]) + , main_internal_return_ptr_shift(il[766]) + , main_l1_to_l2_msg_exists_write_offset_shift(il[767]) + , main_l2_gas_remaining_shift(il[768]) + , main_note_hash_exist_write_offset_shift(il[769]) + , main_nullifier_exists_write_offset_shift(il[770]) + , main_nullifier_non_exists_write_offset_shift(il[771]) + , main_pc_shift(il[772]) + , main_sel_execution_end_shift(il[773]) + , main_sel_execution_row_shift(il[774]) + , main_sload_write_offset_shift(il[775]) + , main_sstore_write_offset_shift(il[776]) + , mem_glob_addr_shift(il[777]) + , mem_rw_shift(il[778]) + , mem_sel_mem_shift(il[779]) + , mem_tag_shift(il[780]) + , mem_tsp_shift(il[781]) + , mem_val_shift(il[782]) + , merkle_tree_leaf_index_shift(il[783]) + , merkle_tree_leaf_value_shift(il[784]) + , merkle_tree_path_len_shift(il[785]) + , poseidon2_full_a_0_shift(il[786]) + , poseidon2_full_a_1_shift(il[787]) + , poseidon2_full_a_2_shift(il[788]) + , poseidon2_full_a_3_shift(il[789]) + , poseidon2_full_execute_poseidon_perm_shift(il[790]) + , poseidon2_full_input_0_shift(il[791]) + , poseidon2_full_input_1_shift(il[792]) + , poseidon2_full_input_2_shift(il[793]) + , poseidon2_full_num_perm_rounds_rem_shift(il[794]) + , poseidon2_full_sel_poseidon_shift(il[795]) + , poseidon2_full_start_poseidon_shift(il[796]) + , slice_addr_shift(il[797]) + , slice_clk_shift(il[798]) + , slice_cnt_shift(il[799]) + , slice_col_offset_shift(il[800]) + , slice_sel_cd_cpy_shift(il[801]) + , slice_sel_mem_active_shift(il[802]) + , slice_sel_return_shift(il[803]) + , slice_sel_start_shift(il[804]) + , slice_space_id_shift(il[805]) {} AvmFlavor::ProverPolynomials::ProverPolynomials(ProvingKey& proving_key) @@ -1098,6 +1120,23 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id mem_tsp[row_idx], mem_val[row_idx], mem_w_in_tag[row_idx], + merkle_tree_clk[row_idx], + merkle_tree_diff_inv[row_idx], + merkle_tree_expected_tree_root[row_idx], + merkle_tree_is_member[row_idx], + merkle_tree_latch[row_idx], + merkle_tree_leaf_index[row_idx], + merkle_tree_leaf_index_is_even[row_idx], + merkle_tree_leaf_value[row_idx], + merkle_tree_left_hash[row_idx], + merkle_tree_output_hash[row_idx], + merkle_tree_path_len[row_idx], + merkle_tree_path_len_inv[row_idx], + merkle_tree_right_hash[row_idx], + merkle_tree_sel_membership_op[row_idx], + merkle_tree_sel_merkle_tree[row_idx], + merkle_tree_sel_update_op[row_idx], + merkle_tree_sibling_value[row_idx], poseidon2_B_10_0[row_idx], poseidon2_B_10_1[row_idx], poseidon2_B_10_2[row_idx], @@ -1386,6 +1425,7 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id poseidon2_full_num_perm_rounds_rem_inv[row_idx], poseidon2_full_output[row_idx], poseidon2_full_padding[row_idx], + poseidon2_full_sel_merkle_tree[row_idx], poseidon2_full_sel_poseidon[row_idx], poseidon2_full_start_poseidon[row_idx], poseidon2_input_addr[row_idx], @@ -1496,6 +1536,7 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id perm_pos_mem_write_d_inv[row_idx], perm_pos2_fixed_pos2_perm_inv[row_idx], perm_slice_mem_inv[row_idx], + perm_merkle_poseidon2_inv[row_idx], perm_main_alu_inv[row_idx], perm_main_bin_inv[row_idx], perm_main_conv_inv[row_idx], @@ -1569,6 +1610,9 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id mem_tag_shift[row_idx], mem_tsp_shift[row_idx], mem_val_shift[row_idx], + merkle_tree_leaf_index_shift[row_idx], + merkle_tree_leaf_value_shift[row_idx], + merkle_tree_path_len_shift[row_idx], poseidon2_full_a_0_shift[row_idx], poseidon2_full_a_1_shift[row_idx], poseidon2_full_a_2_shift[row_idx], @@ -1886,6 +1930,23 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::mem_tsp = "MEM_TSP"; Base::mem_val = "MEM_VAL"; Base::mem_w_in_tag = "MEM_W_IN_TAG"; + Base::merkle_tree_clk = "MERKLE_TREE_CLK"; + Base::merkle_tree_diff_inv = "MERKLE_TREE_DIFF_INV"; + Base::merkle_tree_expected_tree_root = "MERKLE_TREE_EXPECTED_TREE_ROOT"; + Base::merkle_tree_is_member = "MERKLE_TREE_IS_MEMBER"; + Base::merkle_tree_latch = "MERKLE_TREE_LATCH"; + Base::merkle_tree_leaf_index = "MERKLE_TREE_LEAF_INDEX"; + Base::merkle_tree_leaf_index_is_even = "MERKLE_TREE_LEAF_INDEX_IS_EVEN"; + Base::merkle_tree_leaf_value = "MERKLE_TREE_LEAF_VALUE"; + Base::merkle_tree_left_hash = "MERKLE_TREE_LEFT_HASH"; + Base::merkle_tree_output_hash = "MERKLE_TREE_OUTPUT_HASH"; + Base::merkle_tree_path_len = "MERKLE_TREE_PATH_LEN"; + Base::merkle_tree_path_len_inv = "MERKLE_TREE_PATH_LEN_INV"; + Base::merkle_tree_right_hash = "MERKLE_TREE_RIGHT_HASH"; + Base::merkle_tree_sel_membership_op = "MERKLE_TREE_SEL_MEMBERSHIP_OP"; + Base::merkle_tree_sel_merkle_tree = "MERKLE_TREE_SEL_MERKLE_TREE"; + Base::merkle_tree_sel_update_op = "MERKLE_TREE_SEL_UPDATE_OP"; + Base::merkle_tree_sibling_value = "MERKLE_TREE_SIBLING_VALUE"; Base::poseidon2_B_10_0 = "POSEIDON2_B_10_0"; Base::poseidon2_B_10_1 = "POSEIDON2_B_10_1"; Base::poseidon2_B_10_2 = "POSEIDON2_B_10_2"; @@ -2174,6 +2235,7 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::poseidon2_full_num_perm_rounds_rem_inv = "POSEIDON2_FULL_NUM_PERM_ROUNDS_REM_INV"; Base::poseidon2_full_output = "POSEIDON2_FULL_OUTPUT"; Base::poseidon2_full_padding = "POSEIDON2_FULL_PADDING"; + Base::poseidon2_full_sel_merkle_tree = "POSEIDON2_FULL_SEL_MERKLE_TREE"; Base::poseidon2_full_sel_poseidon = "POSEIDON2_FULL_SEL_POSEIDON"; Base::poseidon2_full_start_poseidon = "POSEIDON2_FULL_START_POSEIDON"; Base::poseidon2_input_addr = "POSEIDON2_INPUT_ADDR"; @@ -2263,6 +2325,7 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::perm_pos_mem_write_d_inv = "PERM_POS_MEM_WRITE_D_INV"; Base::perm_pos2_fixed_pos2_perm_inv = "PERM_POS2_FIXED_POS2_PERM_INV"; Base::perm_slice_mem_inv = "PERM_SLICE_MEM_INV"; + Base::perm_merkle_poseidon2_inv = "PERM_MERKLE_POSEIDON2_INV"; Base::perm_main_alu_inv = "PERM_MAIN_ALU_INV"; Base::perm_main_bin_inv = "PERM_MAIN_BIN_INV"; Base::perm_main_conv_inv = "PERM_MAIN_CONV_INV"; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp index a6fd7a9331e..ba130193efd 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp @@ -26,6 +26,7 @@ #include "barretenberg/vm/avm/generated/relations/main.hpp" #include "barretenberg/vm/avm/generated/relations/mem.hpp" #include "barretenberg/vm/avm/generated/relations/mem_slice.hpp" +#include "barretenberg/vm/avm/generated/relations/merkle_tree.hpp" #include "barretenberg/vm/avm/generated/relations/poseidon2.hpp" #include "barretenberg/vm/avm/generated/relations/poseidon2_full.hpp" #include "barretenberg/vm/avm/generated/relations/range_check.hpp" @@ -72,6 +73,7 @@ #include "barretenberg/vm/avm/generated/relations/perm_main_pos2_perm.hpp" #include "barretenberg/vm/avm/generated/relations/perm_main_sha256.hpp" #include "barretenberg/vm/avm/generated/relations/perm_main_slice.hpp" +#include "barretenberg/vm/avm/generated/relations/perm_merkle_poseidon2.hpp" #include "barretenberg/vm/avm/generated/relations/perm_pos2_fixed_pos2_perm.hpp" #include "barretenberg/vm/avm/generated/relations/perm_pos_mem_read_a.hpp" #include "barretenberg/vm/avm/generated/relations/perm_pos_mem_read_b.hpp" @@ -95,10 +97,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 -#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_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, cmp_a_hi, cmp_a_lo, cmp_b_hi, cmp_b_lo, cmp_borrow, cmp_clk, cmp_cmp_rng_ctr, cmp_input_a, cmp_input_b, cmp_op_eq, cmp_op_eq_diff_inv, cmp_op_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_le, 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_out_of_gas, main_dyn_da_gas_op_cost, main_dyn_gas_multiplier, main_dyn_l2_gas_op_cost, main_emit_l2_to_l1_msg_write_offset, main_emit_note_hash_write_offset, main_emit_nullifier_write_offset, main_emit_unencrypted_log_write_offset, main_ia, main_ib, main_ic, main_id, main_id_zero, main_ind_addr_a, main_ind_addr_b, main_ind_addr_c, main_ind_addr_d, main_internal_return_ptr, main_inv, main_is_fake_row, main_is_gas_accounted, main_kernel_in_offset, main_kernel_out_offset, main_l1_to_l2_msg_exists_write_offset, main_l2_gas_remaining, main_l2_out_of_gas, main_mem_addr_a, main_mem_addr_b, main_mem_addr_c, main_mem_addr_d, main_note_hash_exist_write_offset, main_nullifier_exists_write_offset, main_nullifier_non_exists_write_offset, main_op_err, main_opcode_val, main_pc, main_r_in_tag, main_rwa, main_rwb, main_rwc, main_rwd, main_sel_alu, main_sel_bin, main_sel_calldata, main_sel_execution_end, main_sel_execution_row, main_sel_kernel_inputs, main_sel_kernel_out, 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_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_le, main_sel_op_sender, main_sel_op_set, main_sel_op_sha256, main_sel_op_shl, main_sel_op_shr, main_sel_op_sload, main_sel_op_sstore, main_sel_op_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_side_effect_counter, main_sload_write_offset, main_space_id, main_sstore_write_offset, main_tag_err, main_w_in_tag, mem_addr, mem_clk, mem_diff, 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_val, mem_w_in_tag, 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_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_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_mem_rng_chk, 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_pow_2_0_counts, lookup_pow_2_1_counts, lookup_byte_lengths_counts, lookup_byte_operations_counts, lookup_opcode_gas_counts, kernel_output_lookup_counts, lookup_into_kernel_counts, lookup_cd_value_counts, lookup_ret_value_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts -#define DERIVED_WITNESS_ENTITIES perm_rng_mem_inv, perm_rng_cmp_lo_inv, perm_rng_cmp_hi_inv, perm_rng_alu_inv, perm_cmp_alu_inv, perm_rng_gas_l2_inv, perm_rng_gas_da_inv, perm_l2_start_gas_inv, perm_da_start_gas_inv, perm_l2_end_gas_inv, perm_da_end_gas_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_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_pow_2_0_inv, lookup_pow_2_1_inv, lookup_byte_lengths_inv, lookup_byte_operations_inv, lookup_opcode_gas_inv, kernel_output_lookup_inv, lookup_into_kernel_inv, lookup_cd_value_inv, lookup_ret_value_inv, incl_main_tag_err_inv, incl_mem_tag_err_inv -#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_emit_l2_to_l1_msg_write_offset_shift, main_emit_note_hash_write_offset_shift, main_emit_nullifier_write_offset_shift, main_emit_unencrypted_log_write_offset_shift, main_internal_return_ptr_shift, main_l1_to_l2_msg_exists_write_offset_shift, main_l2_gas_remaining_shift, main_note_hash_exist_write_offset_shift, main_nullifier_exists_write_offset_shift, main_nullifier_non_exists_write_offset_shift, main_pc_shift, main_sel_execution_end_shift, main_sel_execution_row_shift, main_sload_write_offset_shift, main_sstore_write_offset_shift, mem_glob_addr_shift, mem_rw_shift, mem_sel_mem_shift, mem_tag_shift, mem_tsp_shift, mem_val_shift, 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_emit_l2_to_l1_msg_write_offset, e.main_emit_note_hash_write_offset, e.main_emit_nullifier_write_offset, e.main_emit_unencrypted_log_write_offset, e.main_internal_return_ptr, e.main_l1_to_l2_msg_exists_write_offset, e.main_l2_gas_remaining, e.main_note_hash_exist_write_offset, e.main_nullifier_exists_write_offset, e.main_nullifier_non_exists_write_offset, e.main_pc, e.main_sel_execution_end, e.main_sel_execution_row, e.main_sload_write_offset, e.main_sstore_write_offset, e.mem_glob_addr, e.mem_rw, e.mem_sel_mem, e.mem_tag, e.mem_tsp, e.mem_val, e.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 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_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, cmp_a_hi, cmp_a_lo, cmp_b_hi, cmp_b_lo, cmp_borrow, cmp_clk, cmp_cmp_rng_ctr, cmp_input_a, cmp_input_b, cmp_op_eq, cmp_op_eq_diff_inv, cmp_op_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_le, 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_out_of_gas, main_dyn_da_gas_op_cost, main_dyn_gas_multiplier, main_dyn_l2_gas_op_cost, main_emit_l2_to_l1_msg_write_offset, main_emit_note_hash_write_offset, main_emit_nullifier_write_offset, main_emit_unencrypted_log_write_offset, main_ia, main_ib, main_ic, main_id, main_id_zero, main_ind_addr_a, main_ind_addr_b, main_ind_addr_c, main_ind_addr_d, main_internal_return_ptr, main_inv, main_is_fake_row, main_is_gas_accounted, main_kernel_in_offset, main_kernel_out_offset, main_l1_to_l2_msg_exists_write_offset, main_l2_gas_remaining, main_l2_out_of_gas, main_mem_addr_a, main_mem_addr_b, main_mem_addr_c, main_mem_addr_d, main_note_hash_exist_write_offset, main_nullifier_exists_write_offset, main_nullifier_non_exists_write_offset, main_op_err, main_opcode_val, main_pc, main_r_in_tag, main_rwa, main_rwb, main_rwc, main_rwd, main_sel_alu, main_sel_bin, main_sel_calldata, main_sel_execution_end, main_sel_execution_row, main_sel_kernel_inputs, main_sel_kernel_out, 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_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_le, main_sel_op_sender, main_sel_op_set, main_sel_op_sha256, main_sel_op_shl, main_sel_op_shr, main_sel_op_sload, main_sel_op_sstore, main_sel_op_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_side_effect_counter, main_sload_write_offset, main_space_id, main_sstore_write_offset, main_tag_err, main_w_in_tag, mem_addr, mem_clk, mem_diff, 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_val, mem_w_in_tag, merkle_tree_clk, merkle_tree_diff_inv, merkle_tree_expected_tree_root, merkle_tree_is_member, 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_membership_op, merkle_tree_sel_merkle_tree, merkle_tree_sel_update_op, 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_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_mem_rng_chk, 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_pow_2_0_counts, lookup_pow_2_1_counts, lookup_byte_lengths_counts, lookup_byte_operations_counts, lookup_opcode_gas_counts, kernel_output_lookup_counts, lookup_into_kernel_counts, lookup_cd_value_counts, lookup_ret_value_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts +#define DERIVED_WITNESS_ENTITIES perm_rng_mem_inv, perm_rng_cmp_lo_inv, perm_rng_cmp_hi_inv, perm_rng_alu_inv, perm_cmp_alu_inv, perm_rng_gas_l2_inv, perm_rng_gas_da_inv, perm_l2_start_gas_inv, perm_da_start_gas_inv, perm_l2_end_gas_inv, perm_da_end_gas_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_pow_2_0_inv, lookup_pow_2_1_inv, lookup_byte_lengths_inv, lookup_byte_operations_inv, lookup_opcode_gas_inv, kernel_output_lookup_inv, lookup_into_kernel_inv, lookup_cd_value_inv, lookup_ret_value_inv, incl_main_tag_err_inv, incl_mem_tag_err_inv +#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_emit_l2_to_l1_msg_write_offset_shift, main_emit_note_hash_write_offset_shift, main_emit_nullifier_write_offset_shift, main_emit_unencrypted_log_write_offset_shift, main_internal_return_ptr_shift, main_l1_to_l2_msg_exists_write_offset_shift, main_l2_gas_remaining_shift, main_note_hash_exist_write_offset_shift, main_nullifier_exists_write_offset_shift, main_nullifier_non_exists_write_offset_shift, main_pc_shift, main_sel_execution_end_shift, main_sel_execution_row_shift, main_sload_write_offset_shift, main_sstore_write_offset_shift, mem_glob_addr_shift, mem_rw_shift, mem_sel_mem_shift, mem_tag_shift, mem_tsp_shift, mem_val_shift, 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_emit_l2_to_l1_msg_write_offset, e.main_emit_note_hash_write_offset, e.main_emit_nullifier_write_offset, e.main_emit_unencrypted_log_write_offset, e.main_internal_return_ptr, e.main_l1_to_l2_msg_exists_write_offset, e.main_l2_gas_remaining, e.main_note_hash_exist_write_offset, e.main_nullifier_exists_write_offset, e.main_nullifier_non_exists_write_offset, e.main_pc, e.main_sel_execution_end, e.main_sel_execution_row, e.main_sload_write_offset, e.main_sstore_write_offset, e.mem_glob_addr, e.mem_rw, e.mem_sel_mem, e.mem_tag, e.mem_tsp, e.mem_val, e.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 ALL_ENTITIES PRECOMPUTED_ENTITIES, WIRE_ENTITIES, DERIVED_WITNESS_ENTITIES, SHIFTED_ENTITIES // clang-format on @@ -124,12 +126,12 @@ class AvmFlavor { static constexpr bool HasZK = false; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 21; - static constexpr size_t NUM_WITNESS_ENTITIES = 705; - static constexpr size_t NUM_SHIFTED_ENTITIES = 58; + static constexpr size_t NUM_WITNESS_ENTITIES = 724; + static constexpr size_t NUM_SHIFTED_ENTITIES = 61; 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 = 784; + static constexpr size_t NUM_ALL_ENTITIES = 806; // The total number of witnesses including shifts and derived entities. static constexpr size_t NUM_ALL_WITNESS_ENTITIES = NUM_WITNESS_ENTITIES + NUM_SHIFTED_ENTITIES; @@ -147,6 +149,7 @@ class AvmFlavor { Avm_vm::main, Avm_vm::mem, Avm_vm::mem_slice, + Avm_vm::merkle_tree, Avm_vm::poseidon2, Avm_vm::poseidon2_full, Avm_vm::range_check, @@ -198,6 +201,7 @@ class AvmFlavor { perm_main_pos2_perm_relation, perm_main_sha256_relation, perm_main_slice_relation, + perm_merkle_poseidon2_relation, perm_pos2_fixed_pos2_perm_relation, perm_pos_mem_read_a_relation, perm_pos_mem_read_b_relation, diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp index f27062c3865..98ba682068c 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp @@ -312,6 +312,23 @@ template std::vector AvmFullRow::names() "mem_tsp", "mem_val", "mem_w_in_tag", + "merkle_tree_clk", + "merkle_tree_diff_inv", + "merkle_tree_expected_tree_root", + "merkle_tree_is_member", + "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_membership_op", + "merkle_tree_sel_merkle_tree", + "merkle_tree_sel_update_op", + "merkle_tree_sibling_value", "poseidon2_B_10_0", "poseidon2_B_10_1", "poseidon2_B_10_2", @@ -600,6 +617,7 @@ template std::vector AvmFullRow::names() "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", @@ -689,6 +707,7 @@ template std::vector AvmFullRow::names() "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", @@ -1043,6 +1062,23 @@ template RefVector AvmFullRow::as_vector() const mem_tsp, mem_val, mem_w_in_tag, + merkle_tree_clk, + merkle_tree_diff_inv, + merkle_tree_expected_tree_root, + merkle_tree_is_member, + 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_membership_op, + merkle_tree_sel_merkle_tree, + merkle_tree_sel_update_op, + merkle_tree_sibling_value, poseidon2_B_10_0, poseidon2_B_10_1, poseidon2_B_10_2, @@ -1331,6 +1367,7 @@ template RefVector AvmFullRow::as_vector() const 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, @@ -1420,6 +1457,7 @@ template RefVector AvmFullRow::as_vector() const 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, 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 b2775561aac..048516e97f7 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp @@ -303,6 +303,23 @@ template struct AvmFullRow { FF mem_tsp{}; FF mem_val{}; FF mem_w_in_tag{}; + FF merkle_tree_clk{}; + FF merkle_tree_diff_inv{}; + FF merkle_tree_expected_tree_root{}; + FF merkle_tree_is_member{}; + FF merkle_tree_latch{}; + FF merkle_tree_leaf_index{}; + FF merkle_tree_leaf_index_is_even{}; + FF merkle_tree_leaf_value{}; + FF merkle_tree_left_hash{}; + FF merkle_tree_output_hash{}; + FF merkle_tree_path_len{}; + FF merkle_tree_path_len_inv{}; + FF merkle_tree_right_hash{}; + FF merkle_tree_sel_membership_op{}; + FF merkle_tree_sel_merkle_tree{}; + FF merkle_tree_sel_update_op{}; + FF merkle_tree_sibling_value{}; FF poseidon2_B_10_0{}; FF poseidon2_B_10_1{}; FF poseidon2_B_10_2{}; @@ -591,6 +608,7 @@ template struct AvmFullRow { FF poseidon2_full_num_perm_rounds_rem_inv{}; FF poseidon2_full_output{}; FF poseidon2_full_padding{}; + FF poseidon2_full_sel_merkle_tree{}; FF poseidon2_full_sel_poseidon{}; FF poseidon2_full_start_poseidon{}; FF poseidon2_input_addr{}; @@ -680,6 +698,7 @@ template struct AvmFullRow { FF perm_pos_mem_write_d_inv{}; FF perm_pos2_fixed_pos2_perm_inv{}; FF perm_slice_mem_inv{}; + FF perm_merkle_poseidon2_inv{}; FF perm_main_alu_inv{}; FF perm_main_bin_inv{}; FF perm_main_conv_inv{}; @@ -740,7 +759,7 @@ template struct AvmFullRow { RefVector as_vector() const; static std::vector names(); - static constexpr size_t SIZE = 726; + static constexpr size_t SIZE = 745; }; template std::ostream& operator<<(std::ostream& os, AvmFullRow const& row); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/merkle_tree.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/merkle_tree.hpp new file mode 100644 index 00000000000..24be467fd4a --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/merkle_tree.hpp @@ -0,0 +1,139 @@ +// AUTOGENERATED FILE +#pragma once + +#include "barretenberg/relations/relation_parameters.hpp" +#include "barretenberg/relations/relation_types.hpp" + +namespace bb::Avm_vm { + +template class merkle_treeImpl { + public: + using FF = FF_; + + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 3, 3, 4, 3, 5, 3, 4, 4, 4, 4, 7 }; + + template + void static accumulate(ContainerOverSubrelations& evals, + const AllEntities& new_term, + [[maybe_unused]] const RelationParameters&, + [[maybe_unused]] const FF& scaling_factor) + { + const auto merkle_tree_LEAF_INDEX_IS_ODD = (FF(1) - new_term.merkle_tree_leaf_index_is_even); + const auto merkle_tree_LAST_COMPUTE = (new_term.merkle_tree_sel_merkle_tree * new_term.merkle_tree_latch); + const auto merkle_tree_ROOT_DIFF = (new_term.merkle_tree_output_hash - new_term.merkle_tree_expected_tree_root); + + { + using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; + auto tmp = (new_term.merkle_tree_sel_merkle_tree * (FF(1) - new_term.merkle_tree_sel_merkle_tree)); + tmp *= scaling_factor; + std::get<0>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<1, ContainerOverSubrelations>; + auto tmp = (new_term.merkle_tree_sel_update_op * (FF(1) - new_term.merkle_tree_sel_update_op)); + tmp *= scaling_factor; + std::get<1>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<2, ContainerOverSubrelations>; + auto tmp = (new_term.merkle_tree_sel_membership_op * (FF(1) - new_term.merkle_tree_sel_membership_op)); + tmp *= scaling_factor; + std::get<2>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<3, ContainerOverSubrelations>; + auto tmp = (new_term.merkle_tree_is_member * (FF(1) - new_term.merkle_tree_is_member)); + tmp *= scaling_factor; + std::get<3>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<4, ContainerOverSubrelations>; + auto tmp = ((new_term.merkle_tree_sel_merkle_tree * (FF(1) - new_term.merkle_tree_latch)) * + ((new_term.merkle_tree_path_len_shift - new_term.merkle_tree_path_len) + FF(1))); + tmp *= scaling_factor; + std::get<4>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<5, ContainerOverSubrelations>; + auto tmp = (new_term.merkle_tree_latch * (FF(1) - new_term.merkle_tree_latch)); + tmp *= scaling_factor; + std::get<5>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<6, ContainerOverSubrelations>; + auto tmp = (new_term.merkle_tree_sel_merkle_tree * + (((new_term.merkle_tree_path_len * + ((new_term.merkle_tree_latch * (FF(1) - new_term.merkle_tree_path_len_inv)) + + new_term.merkle_tree_path_len_inv)) - + FF(1)) + + new_term.merkle_tree_latch)); + tmp *= scaling_factor; + std::get<6>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<7, ContainerOverSubrelations>; + auto tmp = (new_term.merkle_tree_leaf_index_is_even * (FF(1) - new_term.merkle_tree_leaf_index_is_even)); + tmp *= scaling_factor; + std::get<7>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<8, ContainerOverSubrelations>; + auto tmp = ((new_term.merkle_tree_sel_merkle_tree * (FF(1) - new_term.merkle_tree_latch)) * + (((new_term.merkle_tree_leaf_index_shift * FF(2)) + merkle_tree_LEAF_INDEX_IS_ODD) - + new_term.merkle_tree_leaf_index)); + tmp *= scaling_factor; + std::get<8>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<9, ContainerOverSubrelations>; + auto tmp = (new_term.merkle_tree_sel_merkle_tree * + ((new_term.merkle_tree_leaf_index_is_even * + (new_term.merkle_tree_left_hash - new_term.merkle_tree_leaf_value)) + + (merkle_tree_LEAF_INDEX_IS_ODD * + (new_term.merkle_tree_right_hash - new_term.merkle_tree_leaf_value)))); + tmp *= scaling_factor; + std::get<9>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<10, ContainerOverSubrelations>; + auto tmp = (new_term.merkle_tree_sel_merkle_tree * + ((new_term.merkle_tree_leaf_index_is_even * + (new_term.merkle_tree_right_hash - new_term.merkle_tree_sibling_value)) + + (merkle_tree_LEAF_INDEX_IS_ODD * + (new_term.merkle_tree_left_hash - new_term.merkle_tree_sibling_value)))); + tmp *= scaling_factor; + std::get<10>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<11, ContainerOverSubrelations>; + auto tmp = ((new_term.merkle_tree_sel_merkle_tree * (FF(1) - new_term.merkle_tree_latch)) * + (new_term.merkle_tree_leaf_value_shift - new_term.merkle_tree_output_hash)); + tmp *= scaling_factor; + std::get<11>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<12, ContainerOverSubrelations>; + auto tmp = ((new_term.merkle_tree_sel_membership_op * merkle_tree_LAST_COMPUTE) * + (((merkle_tree_ROOT_DIFF * + ((new_term.merkle_tree_is_member * (FF(1) - new_term.merkle_tree_diff_inv)) + + new_term.merkle_tree_diff_inv)) - + FF(1)) + + new_term.merkle_tree_is_member)); + tmp *= scaling_factor; + std::get<12>(evals) += typename Accumulator::View(tmp); + } + } +}; + +template class merkle_tree : public Relation> { + public: + static constexpr const char* NAME = "merkle_tree"; + + static std::string get_subrelation_label(size_t index) + { + switch (index) {} + return std::to_string(index); + } +}; + +} // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/perm_merkle_poseidon2.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/perm_merkle_poseidon2.hpp new file mode 100644 index 00000000000..ea7208428ff --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/perm_merkle_poseidon2.hpp @@ -0,0 +1,63 @@ +// AUTOGENERATED FILE +#pragma once + +#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" + +#include +#include + +namespace bb { + +class perm_merkle_poseidon2_permutation_settings { + public: + // This constant defines how many columns are bundled together to form each set. + constexpr static size_t COLUMNS_PER_SET = 4; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in.merkle_tree_sel_merkle_tree == 1 || in.poseidon2_full_sel_merkle_tree == 1); + } + + template static inline auto get_const_entities(const AllEntities& in) + { + return std::forward_as_tuple(in.perm_merkle_poseidon2_inv, + in.merkle_tree_sel_merkle_tree, + in.merkle_tree_sel_merkle_tree, + in.poseidon2_full_sel_merkle_tree, + in.merkle_tree_clk, + in.merkle_tree_left_hash, + in.merkle_tree_right_hash, + in.merkle_tree_output_hash, + in.poseidon2_full_clk, + in.poseidon2_full_input_0, + in.poseidon2_full_input_1, + in.poseidon2_full_output); + } + + template static inline auto get_nonconst_entities(AllEntities& in) + { + return std::forward_as_tuple(in.perm_merkle_poseidon2_inv, + in.merkle_tree_sel_merkle_tree, + in.merkle_tree_sel_merkle_tree, + in.poseidon2_full_sel_merkle_tree, + in.merkle_tree_clk, + in.merkle_tree_left_hash, + in.merkle_tree_right_hash, + in.merkle_tree_output_hash, + in.poseidon2_full_clk, + in.poseidon2_full_input_0, + in.poseidon2_full_input_1, + in.poseidon2_full_output); + } +}; + +template +class perm_merkle_poseidon2_relation + : public GenericPermutationRelation { + public: + static constexpr const char* NAME = "PERM_MERKLE_POSEIDON2"; +}; +template +using perm_merkle_poseidon2 = GenericPermutation; + +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/tests/full_poseidon2.test.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/tests/full_poseidon2.test.cpp index 3083fc6d610..e98a924aa7e 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/tests/full_poseidon2.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/tests/full_poseidon2.test.cpp @@ -29,13 +29,15 @@ TEST(AvmFullPoseidon2, shouldHashCorrectly) // Create a bunch of random elements and hash them. size_t num_elems = 10; std::vector random_elems; + uint32_t clk = 0; for (uint32_t i = 0; i < 8; ++i) { for (size_t i = 0; i < num_elems; ++i) { random_elems.push_back(FF::random_element()); } - FF builder_result = poseidon2_builder.poseidon2_hash(random_elems, i); + FF builder_result = poseidon2_builder.poseidon2_hash(random_elems, static_cast(clk)); FF expected_result = crypto::Poseidon2::hash(random_elems); EXPECT_EQ(builder_result, expected_result); + clk += i + (static_cast(random_elems.size()) + 2) / 3 * 3; } poseidon2_builder.finalize_full(trace); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/tests/merkle_tree.test.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/tests/merkle_tree.test.cpp new file mode 100644 index 00000000000..38cf9fac7ae --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm/tests/merkle_tree.test.cpp @@ -0,0 +1,130 @@ +#include "barretenberg/common/thread.hpp" +#include "barretenberg/crypto/poseidon2/poseidon2.hpp" +#include "barretenberg/crypto/poseidon2/poseidon2_params.hpp" +#include "barretenberg/vm/avm/generated/circuit_builder.hpp" +#include "barretenberg/vm/avm/generated/flavor.hpp" +#include "barretenberg/vm/avm/generated/full_row.hpp" +#include "barretenberg/vm/avm/generated/relations/poseidon2.hpp" +#include "barretenberg/vm/avm/generated/relations/poseidon2_full.hpp" + +#include "barretenberg/vm/avm/trace/gadgets/merkle_tree.hpp" +#include +#include +#include + +namespace tests_avm { +using namespace bb; +using namespace bb::Avm_vm; + +TEST(AvmMerkleTree, shouldCheckMembership) +{ + + using FF = AvmFlavor::FF; + constexpr size_t TRACE_SIZE = 1 << 8; + + std::vector> trace(TRACE_SIZE); + + bb::avm_trace::AvmMerkleTreeTraceBuilder merkle_tree_builder; + std::cerr << "Generating trace of size " << TRACE_SIZE << "..." << std::endl; + + /* MEMBERSHIP CHECK */ + // Create a bunch of random elements and hash them. + size_t depth = 32; + std::vector sibling_path; + FF initial_value = FF::random_element(); + uint32_t leaf_index = 2000; + for (size_t i = 0; i < depth; ++i) { + sibling_path.push_back(FF::random_element()); + } + FF root = initial_value; + uint32_t leaf_index_copy = leaf_index; + for (size_t i = 0; i < depth; ++i) { + root = leaf_index_copy % 2 == 0 + ? crypto::Poseidon2::hash({ root, sibling_path[i] }) + : crypto::Poseidon2::hash({ sibling_path[i], root }); + leaf_index_copy /= 2; + } + + // Check membership + bool found = merkle_tree_builder.check_membership(0, initial_value, leaf_index, sibling_path, root); + ASSERT_TRUE(found); + bool not_found = merkle_tree_builder.check_membership(1, initial_value, leaf_index + 1, sibling_path, root); + ASSERT_FALSE(not_found); + + /* UPDATE ROOT */ + FF new_value = FF::random_element(); + FF new_root = merkle_tree_builder.update_leaf_index(2, new_value, leaf_index, sibling_path); + bool new_found = merkle_tree_builder.check_membership(3, new_value, leaf_index, sibling_path, new_root); + ASSERT_TRUE(new_found); + + merkle_tree_builder.poseidon2_builder.finalize_full(trace); + auto finalised_builder = merkle_tree_builder.poseidon2_builder.finalize(); + for (size_t i = 0; i < finalised_builder.size(); i++) { + auto& dest = trace.at(i); + auto const& src = finalised_builder.at(i); + dest.poseidon2_clk = FF(src.clk); + merge_into(dest, src); + } + + merkle_tree_builder.finalize(trace); + + trace.insert(trace.begin(), bb::AvmFullRow{ .main_sel_first = FF(1), .mem_lastAccess = FF(1) }); + // We build the polynomials needed to run "sumcheck". + AvmCircuitBuilder cb; + cb.set_trace(std::move(trace)); + auto polys = cb.compute_polynomials(); + const size_t num_rows = polys.get_polynomial_size(); + std::cerr << "Done computing polynomials..." << std::endl; + + std::cerr << "Accumulating relations..." << std::endl; + using AllRelations = std::tuple, Avm_vm::poseidon2_full, Avm_vm::poseidon2>; + + bb::constexpr_for<0, std::tuple_size_v, 1>([&]() { + using Relation = std::tuple_element_t; + typename Relation::SumcheckArrayOfValuesOverSubrelations result; + for (auto& r : result) { + r = 0; + } + + // We set the conditions up there. + for (size_t r = 0; r < num_rows; ++r) { + Relation::accumulate(result, polys.get_row(r), {}, 1); + } + + for (size_t j = 0; j < result.size(); ++j) { + if (result[j] != 0) { + EXPECT_EQ(result[j], 0) << "Relation " << Relation::NAME << " subrelation " + << Relation::get_subrelation_label(j) << " was expected to be zero."; + } + } + }); + + std::cerr << "Accumulating permutation relations..." << std::endl; + + const FF gamma = FF::random_element(); + const FF beta = FF::random_element(); + bb::RelationParameters params{ + .beta = beta, + .gamma = gamma, + }; + using PermRelations = perm_merkle_poseidon2_relation; + + // Check the logderivative relation + bb::compute_logderivative_inverse(polys, params, num_rows); + + typename PermRelations::SumcheckArrayOfValuesOverSubrelations lookup_result; + + for (auto& r : lookup_result) { + r = 0; + } + for (size_t r = 0; r < num_rows; ++r) { + PermRelations::accumulate(lookup_result, polys.get_row(r), params, 1); + } + for (const auto& j : lookup_result) { + if (j != 0) { + EXPECT_EQ(j, 0) << "Lookup Relation " << PermRelations::NAME << " subrelation "; + } + } +} + +} // namespace tests_avm diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/merkle_tree.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/merkle_tree.cpp new file mode 100644 index 00000000000..6a6c0b727ec --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/merkle_tree.cpp @@ -0,0 +1,103 @@ +#include "barretenberg/vm/avm/trace/gadgets/merkle_tree.hpp" + +namespace bb::avm_trace { + +AvmMerkleTreeTraceBuilder::MerkleEntry AvmMerkleTreeTraceBuilder::compute_root_from_path(uint32_t clk, + const FF leaf_value, + const uint32_t leaf_index, + const std::vector& path) +{ + uint32_t path_length = static_cast(path.size()); + FF curr_value = leaf_value; + uint32_t curr_index = leaf_index; + std::vector path_bits; + std::vector path_values; + // These will be eventually stored somewhere as a "clock speed" + auto entry_id = clk << 6; + for (uint32_t i = 0; i < path_length; i++) { + bool path_parity = (curr_index % 2 == 0); + + curr_value = + path_parity + ? poseidon2_builder.poseidon2_hash({ curr_value, path[i] }, entry_id + i, Poseidon2Caller::MERKLE_TREE) + : poseidon2_builder.poseidon2_hash({ path[i], curr_value }, entry_id + i, Poseidon2Caller::MERKLE_TREE); + path_values.push_back(curr_value); + curr_index >>= 1; + } + return MerkleEntry{ .clk = clk, + .leaf_value = leaf_value, + .leaf_index = leaf_index, + .path = path, + .path_bits = path_bits, + .path_values = path_values, + .root = curr_value }; +} + +bool AvmMerkleTreeTraceBuilder::check_membership( + uint32_t clk, const FF leaf_value, const uint32_t leaf_index, const std::vector& path, const FF& root) +{ + MerkleEntry entry = compute_root_from_path(clk, leaf_value, leaf_index, path); + entry.is_membership_op = true; + // If the computed root is the same as the expected then the leaf is a member + bool is_member = entry.root == root; + entry.is_member = is_member; + // If the leaf is not a member then we should replace the computed root with the expected root + entry.root = is_member ? entry.root : root; + merkle_check_trace.push_back(entry); + return entry.is_member; +} + +FF AvmMerkleTreeTraceBuilder::update_leaf_index(uint32_t clk, + const FF leaf_value, + const uint32_t leaf_index, + const std::vector& path) +{ + MerkleEntry entry = compute_root_from_path(clk, leaf_value, leaf_index, path); + entry.is_update_op = true; + merkle_check_trace.push_back(entry); + return entry.root; +} + +void AvmMerkleTreeTraceBuilder::finalize(std::vector>& main_trace) +{ + size_t main_trace_counter = 0; + + for (const auto& src : merkle_check_trace) { + uint32_t path_length = static_cast(src.path.size()); + uint32_t leaf_index = src.leaf_index; + auto curr_value = src.leaf_value; + for (size_t i = 0; i < path_length; i++) { + auto sibling_value = src.path[i]; + auto& dest = main_trace.at(main_trace_counter++); + + dest.merkle_tree_clk = (src.clk << 6) + i; + dest.merkle_tree_leaf_index = leaf_index; + dest.merkle_tree_leaf_value = curr_value; + dest.merkle_tree_expected_tree_root = src.root; + + dest.merkle_tree_leaf_index_is_even = (leaf_index % 2 == 0) ? FF::one() : FF::zero(); + dest.merkle_tree_left_hash = leaf_index % 2 == 0 ? curr_value : sibling_value; + dest.merkle_tree_right_hash = leaf_index % 2 == 0 ? sibling_value : curr_value; + dest.merkle_tree_output_hash = src.path_values[i]; + dest.merkle_tree_sibling_value = sibling_value; + + dest.merkle_tree_path_len = path_length - i - 1; + dest.merkle_tree_path_len_inv = (path_length - i - 1) == 0 ? 0 : FF(path_length - i - 1).invert(); + dest.merkle_tree_sel_merkle_tree = FF::one(); + dest.merkle_tree_diff_inv = + (src.path_values[i] - src.root) == FF::zero() ? FF::zero() : (src.path_values[i] - src.root).invert(); + + if (i == (path_length - 1)) { + dest.merkle_tree_latch = FF::one(); + dest.merkle_tree_is_member = src.is_member ? FF::one() : FF::zero(); + dest.merkle_tree_sel_membership_op = src.is_membership_op ? FF::one() : FF::zero(); + dest.merkle_tree_sel_update_op = src.is_update_op ? FF::one() : FF::zero(); + } + + curr_value = src.path_values[i]; + leaf_index >>= 1; + } + } +} + +} // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/merkle_tree.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/merkle_tree.hpp new file mode 100644 index 00000000000..7a664e2b5aa --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/merkle_tree.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include "barretenberg/vm/avm/generated/relations/poseidon2.hpp" +#include "barretenberg/vm/avm/trace/common.hpp" +#include "barretenberg/vm/avm/trace/gadgets/poseidon2.hpp" + +#include +namespace bb::avm_trace { + +class AvmMerkleTreeTraceBuilder { + public: + struct MerkleEntry { + uint32_t clk; + FF leaf_value{}; + uint32_t leaf_index; + std::vector path; + std::vector path_bits; + // Could probably get away with not having this and computing in finalize + std::vector path_values; + FF root{}; + bool is_member = false; + bool is_update_op = false; + bool is_membership_op = false; + }; + + AvmMerkleTreeTraceBuilder() = default; + void reset(); + + bool check_membership( + uint32_t clk, const FF leaf_value, const uint32_t leaf_index, const std::vector& path, const FF& root); + + FF update_leaf_index(uint32_t clk, const FF leaf_value, const uint32_t leaf_index, const std::vector& path); + + void finalize(std::vector>& main_trace); + // We need access to the poseidon2 gadget + AvmPoseidon2TraceBuilder poseidon2_builder; + + private: + std::vector merkle_check_trace; + MerkleEntry compute_root_from_path(uint32_t clk, + const FF leaf_value, + const uint32_t leaf_index, + const std::vector& path); +}; +}; // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/poseidon2.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/poseidon2.cpp index 4f73557b105..bc224093285 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/poseidon2.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/poseidon2.cpp @@ -82,22 +82,18 @@ std::array AvmPoseidon2TraceBuilder::poseidon2_permutation( return entry.output; } -FF AvmPoseidon2TraceBuilder::poseidon2_hash(std::vector input, uint32_t clk) +FF AvmPoseidon2TraceBuilder::poseidon2_hash(std::vector input, uint32_t clk, Poseidon2Caller caller) { using Poseidon2 = crypto::Poseidon2; FF output = Poseidon2::hash(input); - // 64 rounds of hashing should be enough (1 << 6 == 64) per full hash invocation - // This completely arbitrary and we might change this in the future - // But we need a way to allow multiple rows of poseidon2 permutation per poseidon2 full call - auto entry_clk = clk << 6; // Add the full hash trace event poseidon2_hash_trace.push_back(Poseidon2FullTraceEntry{ - .clk = entry_clk, + .clk = clk, .input = input, .output = output, .input_length = input.size(), + .caller = caller, }); - const FF iv = (static_cast(input.size()) << 64); std::array input_array = { 0, 0, 0, iv }; @@ -108,7 +104,7 @@ FF AvmPoseidon2TraceBuilder::poseidon2_hash(std::vector input, uint32_t clk) input_array[1] += input[i + 1]; input_array[2] += input[i + 2]; - auto entry_idx = entry_clk + (i / 3); + auto entry_idx = clk + (i / 3); auto entry = gen_poseidon_perm_entry(input_array, static_cast(entry_idx)); entry.is_immediate = true; poseidon2_trace.push_back(entry); @@ -135,9 +131,9 @@ void AvmPoseidon2TraceBuilder::finalize_full(std::vector>& main_t dest.poseidon2_full_input_len = src.input_length; dest.poseidon2_full_sel_poseidon = FF::one(); dest.poseidon2_full_clk = src.clk + j; - dest.poseidon2_full_input_0 = src.input[3 * j]; - dest.poseidon2_full_input_1 = src.input[3 * j + 1]; - dest.poseidon2_full_input_2 = src.input[3 * j + 2]; + dest.poseidon2_full_input_0 = 3 * j < src.input.size() ? src.input[3 * j] : FF::zero(); + dest.poseidon2_full_input_1 = 3 * j + 1 < src.input.size() ? src.input[3 * j + 1] : FF::zero(); + dest.poseidon2_full_input_2 = 3 * j + 2 < src.input.size() ? src.input[3 * j + 2] : FF::zero(); dest.poseidon2_full_output = src.output; dest.poseidon2_full_num_perm_rounds_rem = num_rounds_rem; dest.poseidon2_full_padding = padded_size - src.input_length; @@ -161,6 +157,16 @@ void AvmPoseidon2TraceBuilder::finalize_full(std::vector>& main_t dest.poseidon2_full_execute_poseidon_perm = FF::one(); num_rounds_rem--; } + + switch (src.caller) { + case Poseidon2Caller::NONE: + case Poseidon2Caller::BYTECODE_HASHING: + break; + case Poseidon2Caller::MERKLE_TREE: { + dest.poseidon2_full_sel_merkle_tree = FF::one(); + break; + } + } // Careful - we assume here that the permutation events are in order perm_event++; } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/poseidon2.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/poseidon2.hpp index 0f68c641eb0..284e5338592 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/poseidon2.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/gadgets/poseidon2.hpp @@ -9,6 +9,12 @@ namespace bb::avm_trace { +enum Poseidon2Caller { + NONE = 0, + BYTECODE_HASHING = 1, + MERKLE_TREE = 2, +}; + class AvmPoseidon2TraceBuilder { public: struct Poseidon2FullTraceEntry { @@ -16,6 +22,7 @@ class AvmPoseidon2TraceBuilder { std::vector input; FF output{}; size_t input_length = 0; + Poseidon2Caller caller = Poseidon2Caller::NONE; }; struct Poseidon2TraceEntry { uint32_t space_id = 0; @@ -39,7 +46,7 @@ class AvmPoseidon2TraceBuilder { std::array poseidon2_permutation( const std::array& input, uint32_t space_id, uint32_t clk, uint32_t input_addr, uint32_t output_addr); - FF poseidon2_hash(std::vector input, uint32_t clk); + FF poseidon2_hash(std::vector input, uint32_t clk, Poseidon2Caller caller = Poseidon2Caller::NONE); // Finalize for the full poseidon hash void finalize_full(std::vector>& main_trace); diff --git a/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp b/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp index aa35d864f5e..78475c6759a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp @@ -35,7 +35,7 @@ #define PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH 674 #define PUBLIC_CONTEXT_INPUTS_LENGTH 41 #define AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS 86 -#define AVM_PROOF_LENGTH_IN_FIELDS 3949 +#define AVM_PROOF_LENGTH_IN_FIELDS 4047 #define AVM_PUBLIC_COLUMN_MAX_SIZE 1024 #define AVM_PUBLIC_INPUTS_FLATTENED_SIZE 2722 #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 0049afc6156..dc710071915 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -491,7 +491,7 @@ 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 -global AVM_PROOF_LENGTH_IN_FIELDS: u32 = 3949; +global AVM_PROOF_LENGTH_IN_FIELDS: u32 = 4047; global AVM_PUBLIC_COLUMN_MAX_SIZE: u32 = 1024; 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 de32b6c7b5c..bef952e5736 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -224,7 +224,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 = 145; export const AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS = 86; -export const AVM_PROOF_LENGTH_IN_FIELDS = 3949; +export const AVM_PROOF_LENGTH_IN_FIELDS = 4047; export const AVM_PUBLIC_COLUMN_MAX_SIZE = 1024; export const AVM_PUBLIC_INPUTS_FLATTENED_SIZE = 2722; export const MEM_TAG_FF = 0;