diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp index 4bd6f4c34daf..5bd8b8f0afbc 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp @@ -25,12 +25,12 @@ template struct CombinedAccumulatedData { AggregationObject aggregation_object{}; - std::array new_commitments{}; - std::array new_nullifiers{}; + std::array new_commitments{}; + std::array new_nullifiers{}; - std::array private_call_stack{}; - std::array public_call_stack{}; - std::array new_l2_to_l1_msgs{}; + std::array private_call_stack{}; + std::array public_call_stack{}; + std::array new_l2_to_l1_msgs{}; std::array encrypted_logs_hash{}; std::array unencrypted_logs_hash{}; @@ -40,12 +40,12 @@ template struct CombinedAccumulatedData { fr encrypted_log_preimages_length = 0; fr unencrypted_log_preimages_length = 0; - std::array, KERNEL_NEW_CONTRACTS_LENGTH> new_contracts{}; + std::array, MAX_NEW_CONTRACTS_PER_TX> new_contracts{}; - std::array, KERNEL_OPTIONALLY_REVEALED_DATA_LENGTH> optionally_revealed_data{}; + std::array, MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX> optionally_revealed_data{}; - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> public_data_update_requests{}; - std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> public_data_reads{}; + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX> public_data_update_requests{}; + std::array, MAX_PUBLIC_DATA_READS_PER_TX> public_data_reads{}; // for serialization, update with new fields MSGPACK_FIELDS(aggregation_object, diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp index 2215ebfe6f46..b80438208fbe 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp @@ -29,12 +29,12 @@ template class PrivateCircuitPublicInputs { std::array read_requests{}; - std::array new_commitments{}; - std::array new_nullifiers{}; + std::array new_commitments{}; + std::array new_nullifiers{}; - std::array private_call_stack{}; - std::array public_call_stack{}; - std::array new_l2_to_l1_msgs{}; + std::array private_call_stack{}; + std::array public_call_stack{}; + std::array new_l2_to_l1_msgs{}; std::array encrypted_logs_hash{}; std::array unencrypted_logs_hash{}; @@ -303,12 +303,12 @@ template class OptionalPrivateCircuitPublicInputs { std::array read_requests; - std::array new_commitments; - std::array new_nullifiers; + std::array new_commitments; + std::array new_nullifiers; - std::array private_call_stack; - std::array public_call_stack; - std::array new_l2_to_l1_msgs; + std::array private_call_stack; + std::array public_call_stack; + std::array new_l2_to_l1_msgs; std::array encrypted_logs_hash; std::array unencrypted_logs_hash; @@ -328,35 +328,36 @@ template class OptionalPrivateCircuitPublicInputs { OptionalPrivateCircuitPublicInputs() = default; - OptionalPrivateCircuitPublicInputs(std::optional> const& call_context, + OptionalPrivateCircuitPublicInputs( + std::optional> const& call_context, - opt_fr const& args_hash, - std::array const& return_values, + opt_fr const& args_hash, + std::array const& return_values, - std::array const& read_requests, + std::array const& read_requests, - std::array const& new_commitments, - std::array const& new_nullifiers, + std::array const& new_commitments, + std::array const& new_nullifiers, - std::array const& private_call_stack, - std::array const& public_call_stack, - std::array const& new_l2_to_l1_msgs, + std::array const& private_call_stack, + std::array const& public_call_stack, + std::array const& new_l2_to_l1_msgs, - std::array const& encrypted_logs_hash, - std::array const& unencrypted_logs_hash, + std::array const& encrypted_logs_hash, + std::array const& unencrypted_logs_hash, - opt_fr const& encrypted_log_preimages_length, - opt_fr const& unencrypted_log_preimages_length, + opt_fr const& encrypted_log_preimages_length, + opt_fr const& unencrypted_log_preimages_length, - opt_fr const& historic_private_data_tree_root, - opt_fr const& historic_nullifier_tree_root, - opt_fr const& historic_contract_tree_root, - opt_fr const& historic_l1_to_l2_messages_tree_root, + opt_fr const& historic_private_data_tree_root, + opt_fr const& historic_nullifier_tree_root, + opt_fr const& historic_contract_tree_root, + opt_fr const& historic_l1_to_l2_messages_tree_root, - std::optional> const& contract_deployment_data, + std::optional> const& contract_deployment_data, - opt_fr const& chain_id, - opt_fr const& version) + opt_fr const& chain_id, + opt_fr const& version) : call_context(call_context) , args_hash(args_hash) , return_values(return_values) diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp index 1a527f39c745..7889c49b6419 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp @@ -22,16 +22,16 @@ // * This class needs an explanation... // * // */ -// std::array, PRIVATE_CALL_STACK_LENGTH> private_call_contexts; -// std::array private_counterparts; +// std::array, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL> private_call_contexts; +// std::array private_counterparts; -// std::array, PUBLIC_CALL_STACK_LENGTH> public_call_contexts; -// std::array public_counterparts; +// std::array, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL> public_call_contexts; +// std::array public_counterparts; // // std::array contract_deployment_call_stack; -// std::array, NEW_L2_TO_L1_MSGS_LENGTH> l1_call_contexts; -// std::array l1_counterparts; // TODO: this is probably wrong. +// std::array, MAX_NEW_L2_TO_L1_MSGS_PER_CALL> l1_call_contexts; +// std::array l1_counterparts; // TODO: this is probably wrong. // template // CallContextReconciliationData> to_circuit_type(Builder& builder) const diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp index b9887739eb21..50aaf1cec066 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp @@ -26,9 +26,10 @@ template struct PrivateCallData { CallStackItem call_stack_item{}; - std::array, PRIVATE_CALL_STACK_LENGTH> private_call_stack_preimages{}; + std::array, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL> private_call_stack_preimages{}; - // std::array, PUBLIC_CALL_STACK_LENGTH> public_call_stack_preimages; + // std::array, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL> + // public_call_stack_preimages; NativeTypes::Proof proof{}; // TODO: how to express proof as native/circuit type when it gets used as a buffer? std::shared_ptr vk; diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp index 839c90b41377..6e8363e8f3e3 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp @@ -26,14 +26,14 @@ template struct PublicCircuitPublicInputs { fr args_hash = 0; std::array return_values{}; - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL> contract_storage_update_requests{}; - std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> contract_storage_reads{}; + std::array, MAX_PUBLIC_DATA_READS_PER_CALL> contract_storage_reads{}; - std::array public_call_stack{}; - std::array new_commitments{}; - std::array new_nullifiers{}; - std::array new_l2_to_l1_msgs{}; + std::array public_call_stack{}; + std::array new_commitments{}; + std::array new_nullifiers{}; + std::array new_l2_to_l1_msgs{}; std::array unencrypted_logs_hash{}; diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp index 3a69895231f5..85849beb877d 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp @@ -24,7 +24,7 @@ template struct PublicCallData { CallStackItem call_stack_item{}; - std::array, PUBLIC_CALL_STACK_LENGTH> public_call_stack_preimages{}; + std::array, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL> public_call_stack_preimages{}; NativeTypes::Proof proof{}; // TODO: how to express proof as native/circuit type when it gets used as a buffer? diff --git a/circuits/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp index e0740f761a9a..0d73150af0b4 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp @@ -21,18 +21,18 @@ template struct BaseRollupInputs { AppendOnlyTreeSnapshot start_contract_tree_snapshot; fr start_public_data_tree_root; - std::array, 2 * KERNEL_NEW_NULLIFIERS_LENGTH> low_nullifier_leaf_preimages; - std::array, 2 * KERNEL_NEW_NULLIFIERS_LENGTH> + std::array, 2 * MAX_NEW_NULLIFIERS_PER_TX> low_nullifier_leaf_preimages; + std::array, 2 * MAX_NEW_NULLIFIERS_PER_TX> low_nullifier_membership_witness; // For inserting the new subtrees into their respective trees: // Note: the insertion leaf index can be derived from the above snapshots' `next_available_leaf_index` values. - std::array new_commitments_subtree_sibling_path; - std::array new_nullifiers_subtree_sibling_path; - std::array new_contracts_subtree_sibling_path; - std::array, 2 * KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> + std::array new_commitments_subtree_sibling_path; + std::array new_nullifiers_subtree_sibling_path; + std::array new_contracts_subtree_sibling_path; + std::array, 2 * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX> new_public_data_update_requests_sibling_paths; - std::array, 2 * KERNEL_PUBLIC_DATA_READS_LENGTH> + std::array, 2 * MAX_PUBLIC_DATA_READS_PER_TX> new_public_data_reads_sibling_paths; std::array, 2> diff --git a/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp index 5bb089f66d22..0fff9bd59813 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp @@ -23,7 +23,7 @@ template struct RootRollupInputs { // inputs required to process l1 to l2 messages std::array l1_to_l2_messages; - std::array new_l1_to_l2_message_tree_root_sibling_path; + std::array new_l1_to_l2_message_tree_root_sibling_path; std::array new_historic_l1_to_l2_message_roots_tree_sibling_path; AppendOnlyTreeSnapshot start_l1_to_l2_message_tree_snapshot; diff --git a/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp b/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp index f44ff1cbc71a..b3e466de22a3 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp @@ -50,7 +50,7 @@ template class FunctionExecutionContext { Contract* contract = nullptr; - std::array>, PRIVATE_CALL_STACK_LENGTH> + std::array>, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL> nested_private_call_exec_ctxs; // TODO: make this private! @@ -124,9 +124,9 @@ template class FunctionExecutionContext { /** * @brief Get the call_stack_items of any nested function calls made by this exec_ctx's function. */ - std::array, PRIVATE_CALL_STACK_LENGTH> get_private_call_stack_items() + std::array, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL> get_private_call_stack_items() { - std::array, PRIVATE_CALL_STACK_LENGTH> result; + std::array, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL> result; for (size_t i = 0; i < result.size(); ++i) { auto& nested_exec_ctx = nested_private_call_exec_ctxs[i]; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp index 0a0770502f04..b5200a4e784b 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp @@ -141,13 +141,13 @@ void common_update_end_values(DummyBuilder& builder, // Enhance commitments and nullifiers with domain separation whereby domain is the contract. { // commitments & nullifiers - std::array siloed_new_commitments{}; + std::array siloed_new_commitments{}; for (size_t i = 0; i < new_commitments.size(); ++i) { siloed_new_commitments[i] = new_commitments[i] == 0 ? 0 : silo_commitment(storage_contract_address, new_commitments[i]); } - std::array siloed_new_nullifiers{}; + std::array siloed_new_nullifiers{}; for (size_t i = 0; i < new_nullifiers.size(); ++i) { siloed_new_nullifiers[i] = new_nullifiers[i] == 0 ? 0 : silo_nullifier(storage_contract_address, new_nullifiers[i]); @@ -168,7 +168,7 @@ void common_update_end_values(DummyBuilder& builder, { // new l2 to l1 messages const auto& portal_contract_address = private_call.portal_contract_address; const auto& new_l2_to_l1_msgs = private_call_public_inputs.new_l2_to_l1_msgs; - std::array new_l2_to_l1_msgs_to_insert{}; + std::array new_l2_to_l1_msgs_to_insert{}; for (size_t i = 0; i < new_l2_to_l1_msgs.size(); ++i) { if (!new_l2_to_l1_msgs[i].is_zero()) { new_l2_to_l1_msgs_to_insert[i] = compute_l2_to_l1_hash(storage_contract_address, diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp index 98a380b127e1..6d06b5b046bf 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp @@ -190,8 +190,8 @@ TEST_F(native_private_kernel_inner_tests, private_kernel_should_fail_if_aggregat do_private_call_get_kernel_inputs_inner(false, deposit, standard_test_args()); // Mock the previous new commitments to be full, therefore no need commitments can be added - std::array full_new_commitments{}; - for (size_t i = 0; i < KERNEL_NEW_COMMITMENTS_LENGTH; ++i) { + std::array full_new_commitments{}; + for (size_t i = 0; i < MAX_NEW_COMMITMENTS_PER_TX; ++i) { full_new_commitments[i] = i + 1; } private_inputs.previous_kernel.public_inputs.end.new_commitments = full_new_commitments; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp index d55e29cf0df1..e8ed8ec54573 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp @@ -26,7 +26,7 @@ void chop_pending_commitments(DummyBuilder& builder, std::array const& read_requests, std::array, READ_REQUESTS_LENGTH> const& read_request_membership_witnesses, - std::array& new_commitments) + std::array& new_commitments) { // chop commitments from the previous call(s) for (size_t i = 0; i < READ_REQUESTS_LENGTH; i++) { @@ -34,13 +34,13 @@ void chop_pending_commitments(DummyBuilder& builder, const auto is_transient_read = (read_request_membership_witnesses[i].leaf_index == NT::fr(-1)); if (is_transient_read) { - size_t match_pos = KERNEL_NEW_COMMITMENTS_LENGTH; - for (size_t j = 0; j < KERNEL_NEW_COMMITMENTS_LENGTH; j++) { + size_t match_pos = MAX_NEW_COMMITMENTS_PER_TX; + for (size_t j = 0; j < MAX_NEW_COMMITMENTS_PER_TX; j++) { match_pos = (read_request == new_commitments[j]) ? j : match_pos; } // chop the pending commitment, i.e., replacing with 0. - if (match_pos != KERNEL_NEW_COMMITMENTS_LENGTH) { + if (match_pos != MAX_NEW_COMMITMENTS_PER_TX) { new_commitments[match_pos] = fr(0); } else { builder.do_assert( @@ -52,7 +52,7 @@ void chop_pending_commitments(DummyBuilder& builder, } // Move all zero entries of this array to the end and preserve ordering of other entries - utils::array_rearrange(new_commitments); + utils::array_rearrange(new_commitments); } KernelCircuitPublicInputs native_private_kernel_circuit_ordering( diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp index a61fef88068b..97f6bdec398c 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp @@ -33,7 +33,7 @@ TEST_F(native_private_kernel_ordering_tests, native_one_read_request_choping_com { auto private_inputs = do_private_call_get_kernel_inputs_inner(false, deposit, standard_test_args()); - std::array new_commitments{}; + std::array new_commitments{}; std::array read_requests{}; std::array, READ_REQUESTS_LENGTH> read_request_membership_witnesses{}; @@ -61,7 +61,7 @@ TEST_F(native_private_kernel_ordering_tests, native_read_requests_choping_commit { auto private_inputs = do_private_call_get_kernel_inputs_inner(false, deposit, standard_test_args()); - std::array new_commitments{}; + std::array new_commitments{}; std::array read_requests{}; std::array, READ_REQUESTS_LENGTH> read_request_membership_witnesses{}; @@ -98,7 +98,7 @@ TEST_F(native_private_kernel_ordering_tests, native_read_request_unknown_fails) { auto private_inputs = do_private_call_get_kernel_inputs_inner(false, deposit, standard_test_args()); - std::array new_commitments{}; + std::array new_commitments{}; std::array read_requests{}; std::array, READ_REQUESTS_LENGTH> read_request_membership_witnesses{}; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp index 8af328b9bfed..77a6f9549a6a 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp @@ -144,17 +144,17 @@ void update_end_values(PrivateKernelInputsInner const& private_inputs, Kerne .function_tree_root = contract_deployment_data.function_tree_root, }; - array_push, KERNEL_NEW_CONTRACTS_LENGTH>(public_inputs.end.new_contracts, - new_contract_data); + array_push, MAX_NEW_CONTRACTS_PER_TX>(public_inputs.end.new_contracts, + new_contract_data); } { // commitments, nullifiers, and contracts - std::array siloed_new_commitments; + std::array siloed_new_commitments; for (size_t i = 0; i < new_commitments.size(); ++i) { siloed_new_commitments[i] = CT::fr::conditional_assign( new_commitments[i] == 0, 0, silo_commitment(storage_contract_address, new_commitments[i])); } - std::array siloed_new_nullifiers; + std::array siloed_new_nullifiers; for (size_t i = 0; i < new_nullifiers.size(); ++i) { siloed_new_nullifiers[i] = CT::fr::conditional_assign( new_nullifiers[i] == 0, 0, silo_nullifier(storage_contract_address, new_nullifiers[i])); @@ -173,7 +173,7 @@ void update_end_values(PrivateKernelInputsInner const& private_inputs, Kerne // { // const auto& new_l2_to_l1_msgs = private_call_public_inputs.new_l2_to_l1_msgs; - // std::array l1_call_stack; + // std::array l1_call_stack; // for (size_t i = 0; i < new_l2_to_l1_msgs.size(); ++i) { // l1_call_stack[i] = CT::fr::conditional_assign( diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp index b4128ea12c9f..7a93358a9065 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp @@ -447,7 +447,7 @@ PrivateKernelInputsInner do_private_call_get_kernel_inputs_inner( // We mock a kernel circuit proof to initialize ipnut required by an inner call //*************************************************************************** - std::array initial_kernel_private_call_stack{}; + std::array initial_kernel_private_call_stack{}; initial_kernel_private_call_stack[0] = private_call_data.call_stack_item.hash(); auto const& private_circuit_public_inputs = private_call_data.call_stack_item.public_inputs; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp index 2e010cc6633d..a98cf7a923f0 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp @@ -70,11 +70,11 @@ template std::array empty_array_of_values() return values; } -std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> +std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL> generate_contract_storage_update_requests(NT::uint32& count, - NT::uint32 num_values_required = KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH) + NT::uint32 num_values_required = MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL) { - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> values; + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL> values; for (size_t i = 0; i < num_values_required; i++) { const auto prev = count++; values[i] = ContractStorageUpdateRequest{ @@ -86,10 +86,10 @@ generate_contract_storage_update_requests(NT::uint32& count, return values; } -std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> generate_contract_storage_reads( - NT::uint32& count, NT::uint32 num_values_required = KERNEL_PUBLIC_DATA_READS_LENGTH) +std::array, MAX_PUBLIC_DATA_READS_PER_CALL> generate_contract_storage_reads( + NT::uint32& count, NT::uint32 num_values_required = MAX_PUBLIC_DATA_READS_PER_CALL) { - std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> values; + std::array, MAX_PUBLIC_DATA_READS_PER_CALL> values; for (size_t i = 0; i < num_values_required; i++) { const auto prev = count++; values[i] = ContractStorageRead{ @@ -123,15 +123,17 @@ PublicCallStackItem generate_call_stack_item(NT::fr contract_address, }; fr const args_hash = count; std::array const return_values = array_of_values(count); - std::array const public_call_stack = - array_of_values(count); - std::array const new_commitments = array_of_values(count); - std::array const new_nullifiers = array_of_values(count); - std::array const new_l2_to_l1_msgs = - array_of_values(count); - std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> const reads = + std::array const public_call_stack = + array_of_values(count); + std::array const new_commitments = + array_of_values(count); + std::array const new_nullifiers = + array_of_values(count); + std::array const new_l2_to_l1_msgs = + array_of_values(count); + std::array, MAX_PUBLIC_DATA_READS_PER_CALL> const reads = generate_contract_storage_reads(count); - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> const update_requests = + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL> const update_requests = generate_contract_storage_update_requests(count); // create the public circuit public inputs @@ -175,12 +177,12 @@ PublicDataUpdateRequest public_data_update_request_from_contract_storage_upd }; } -std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> public_data_reads_from_contract_storage_reads( - std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> const& public_data_reads, +std::array, MAX_PUBLIC_DATA_READS_PER_CALL> public_data_reads_from_contract_storage_reads( + std::array, MAX_PUBLIC_DATA_READS_PER_CALL> const& public_data_reads, NT::fr const& contract_address) { - std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> values; - for (size_t i = 0; i < KERNEL_PUBLIC_DATA_READS_LENGTH; i++) { + std::array, MAX_PUBLIC_DATA_READS_PER_CALL> values; + for (size_t i = 0; i < MAX_PUBLIC_DATA_READS_PER_CALL; i++) { const auto& read = public_data_reads[i]; if (read.is_empty()) { continue; @@ -190,13 +192,13 @@ std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> public_data_read return values; } -std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> +std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL> public_data_update_requests_from_contract_storage_update_requests( - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> const& update_requests, + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL> const& update_requests, NT::fr const& contract_address) { - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> values; - for (size_t i = 0; i < KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH; i++) { + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL> values; + for (size_t i = 0; i < MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX; i++) { const auto& update_request = update_requests[i]; if (update_request.is_empty()) { continue; @@ -206,11 +208,11 @@ public_data_update_requests_from_contract_storage_update_requests( return values; } -std::array new_commitments_as_siloed_commitments( - std::array const& new_commitments, NT::fr const& contract_address) +std::array new_commitments_as_siloed_commitments( + std::array const& new_commitments, NT::fr const& contract_address) { - std::array siloed_commitments{}; - for (size_t i = 0; i < NEW_COMMITMENTS_LENGTH; ++i) { + std::array siloed_commitments{}; + for (size_t i = 0; i < MAX_NEW_COMMITMENTS_PER_CALL; ++i) { if (!new_commitments[i].is_zero()) { siloed_commitments[i] = silo_commitment(contract_address, new_commitments[i]); } @@ -218,11 +220,11 @@ std::array new_commitments_as_siloed_commitments( return siloed_commitments; } -std::array new_nullifiers_as_siloed_nullifiers( - std::array const& new_nullifiers, NT::fr const& contract_address) +std::array new_nullifiers_as_siloed_nullifiers( + std::array const& new_nullifiers, NT::fr const& contract_address) { - std::array siloed_nullifiers{}; - for (size_t i = 0; i < NEW_NULLIFIERS_LENGTH; ++i) { + std::array siloed_nullifiers{}; + for (size_t i = 0; i < MAX_NEW_NULLIFIERS_PER_CALL; ++i) { if (!new_nullifiers[i].is_zero()) { siloed_nullifiers[i] = silo_nullifier(contract_address, new_nullifiers[i]); } @@ -230,15 +232,15 @@ std::array new_nullifiers_as_siloed_nullifiers( return siloed_nullifiers; } -std::array new_l2_messages_from_message( - std::array const& new_messages, +std::array new_l2_messages_from_message( + std::array const& new_messages, NT::fr const& contract_address, fr const& portal_contract_address, fr const& chain_id, fr const& version) { - std::array formatted_msgs{}; - for (size_t i = 0; i < NEW_L2_TO_L1_MSGS_LENGTH; ++i) { + std::array formatted_msgs{}; + for (size_t i = 0; i < MAX_NEW_L2_TO_L1_MSGS_PER_CALL; ++i) { if (!new_messages[i].is_zero()) { formatted_msgs[i] = compute_l2_to_l1_hash( contract_address, version, portal_contract_address, chain_id, new_messages[i]); @@ -294,11 +296,11 @@ PublicKernelInputs get_kernel_inputs_with_previous_kernel(NT::boolean privat .chain_id = 1, } }; - std::array child_call_stacks; + std::array child_call_stacks; NT::fr child_contract_address = 100000; NT::fr child_portal_contract_address = 200000; - std::array call_stack_hashes{}; - for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { + std::array call_stack_hashes{}; + for (size_t i = 0; i < MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL; i++) { // NOLINTNEXTLINE(readability-suspicious-call-argument) child_call_stacks[i] = generate_call_stack_item(child_contract_address, contract_address, @@ -313,16 +315,16 @@ PublicKernelInputs get_kernel_inputs_with_previous_kernel(NT::boolean privat std::array const return_values = array_of_values(seed, RETURN_VALUES_LENGTH / 2); - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> const update_requests = - generate_contract_storage_update_requests(seed, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH / 2); - std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> const reads = - generate_contract_storage_reads(seed, KERNEL_PUBLIC_DATA_READS_LENGTH / 2); - std::array const new_commitments = - array_of_values(seed, NEW_COMMITMENTS_LENGTH / 2); - std::array const new_nullifiers = - array_of_values(seed, NEW_NULLIFIERS_LENGTH / 2); - std::array const new_l2_to_l1_msgs = - array_of_values(seed, NEW_L2_TO_L1_MSGS_LENGTH / 2); + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL> const update_requests = + generate_contract_storage_update_requests(seed, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL / 2); + std::array, MAX_PUBLIC_DATA_READS_PER_CALL> const reads = + generate_contract_storage_reads(seed, MAX_PUBLIC_DATA_READS_PER_CALL / 2); + std::array const new_commitments = + array_of_values(seed, MAX_NEW_COMMITMENTS_PER_CALL / 2); + std::array const new_nullifiers = + array_of_values(seed, MAX_NEW_NULLIFIERS_PER_CALL / 2); + std::array const new_l2_to_l1_msgs = + array_of_values(seed, MAX_NEW_L2_TO_L1_MSGS_PER_CALL / 2); std::array const unencrypted_logs_hash = array_of_values(seed, NUM_FIELDS_PER_SHA256); fr const unencrypted_log_preimages_length = ++seed; @@ -383,28 +385,29 @@ PublicKernelInputs get_kernel_inputs_with_previous_kernel(NT::boolean privat } }; - std::array public_call_stack{}; + std::array public_call_stack{}; public_call_stack[0] = public_call_data.call_stack_item.hash(); CombinedAccumulatedData const end_accumulated_data = { - .new_commitments = array_of_values( - seed, private_previous ? KERNEL_NEW_COMMITMENTS_LENGTH / 2 : 0), - .new_nullifiers = array_of_values( - seed, private_previous ? KERNEL_NEW_NULLIFIERS_LENGTH / 2 : 0), - .private_call_stack = array_of_values(seed, 0), + .new_commitments = + array_of_values(seed, private_previous ? MAX_NEW_COMMITMENTS_PER_TX / 2 : 0), + .new_nullifiers = + array_of_values(seed, private_previous ? MAX_NEW_NULLIFIERS_PER_TX / 2 : 0), + .private_call_stack = array_of_values(seed, 0), .public_call_stack = public_call_stack, - .new_l2_to_l1_msgs = array_of_values( - seed, private_previous ? KERNEL_NEW_L2_TO_L1_MSGS_LENGTH / 2 : 0), + .new_l2_to_l1_msgs = array_of_values( + seed, private_previous ? MAX_NEW_L2_TO_L1_MSGS_PER_TX / 2 : 0), .encrypted_logs_hash = array_of_values( seed, private_previous ? 2 : 0), // only private kernel is producing encrypted logs .unencrypted_logs_hash = array_of_values(seed, NUM_FIELDS_PER_SHA256), .encrypted_log_preimages_length = private_previous ? ++seed : 0, .unencrypted_log_preimages_length = ++seed, - .new_contracts = std::array, KERNEL_NEW_CONTRACTS_LENGTH>(), - .optionally_revealed_data = std::array, KERNEL_OPTIONALLY_REVEALED_DATA_LENGTH>(), + .new_contracts = std::array, MAX_NEW_CONTRACTS_PER_TX>(), + .optionally_revealed_data = + std::array, MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX>(), .public_data_update_requests = - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH>(), - .public_data_reads = std::array, KERNEL_PUBLIC_DATA_READS_LENGTH>() + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>(), + .public_data_reads = std::array, MAX_PUBLIC_DATA_READS_PER_TX>() }; const KernelCircuitPublicInputs public_inputs = { @@ -429,14 +432,14 @@ template void validate_public_kernel_outputs_correctly_propagated(const KernelInput& inputs, const KernelCircuitPublicInputs& public_inputs) { - for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { + for (size_t i = 0; i < MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL; i++) { ASSERT_EQ(public_inputs.end.public_call_stack[i], inputs.public_call.call_stack_item.public_inputs.public_call_stack[i]); } const auto contract_address = inputs.public_call.call_stack_item.contract_address; size_t st_index = 0; - for (size_t i = 0; i < KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH; i++) { + for (size_t i = 0; i < MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX; i++) { const auto& contract_storage_update_request = inputs.public_call.call_stack_item.public_inputs.contract_storage_update_requests[i]; if (contract_storage_update_request.is_empty()) { @@ -448,7 +451,7 @@ void validate_public_kernel_outputs_correctly_propagated(const KernelInput& inpu } size_t sr_index = 0; - for (size_t i = 0; i < KERNEL_PUBLIC_DATA_READS_LENGTH; i++) { + for (size_t i = 0; i < MAX_PUBLIC_DATA_READS_PER_TX; i++) { const auto& read = inputs.public_call.call_stack_item.public_inputs.contract_storage_reads[i]; if (read.is_empty()) { continue; @@ -462,11 +465,11 @@ void validate_private_data_propagation(const PublicKernelInputs& inputs, const KernelCircuitPublicInputs& public_inputs) { ASSERT_TRUE(source_arrays_are_in_target(inputs.previous_kernel.public_inputs.end.private_call_stack, - std::array{}, + std::array{}, public_inputs.end.private_call_stack)); ASSERT_TRUE(source_arrays_are_in_target(inputs.previous_kernel.public_inputs.end.new_contracts, - std::array, KERNEL_NEW_CONTRACTS_LENGTH>(), + std::array, MAX_NEW_CONTRACTS_PER_TX>(), public_inputs.end.new_contracts)); ASSERT_EQ(inputs.previous_kernel.public_inputs.end.encrypted_logs_hash, @@ -492,8 +495,8 @@ TEST(public_kernel_tests, only_valid_public_data_reads_should_be_propagated) .storage_slot = 123456789, .current_value = 76543, }; - std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> reads = - std::array, KERNEL_PUBLIC_DATA_READS_LENGTH>(); + std::array, MAX_PUBLIC_DATA_READS_PER_CALL> reads = + std::array, MAX_PUBLIC_DATA_READS_PER_CALL>(); reads[1] = first_valid; reads[3] = second_valid; inputs.public_call.call_stack_item.public_inputs.contract_storage_reads = reads; @@ -508,7 +511,7 @@ TEST(public_kernel_tests, only_valid_public_data_reads_should_be_propagated) ASSERT_FALSE(public_inputs.is_private); ASSERT_EQ(public_inputs.constants.tx_context, inputs.previous_kernel.public_inputs.constants.tx_context); - for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { + for (size_t i = 0; i < MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL; i++) { ASSERT_EQ(public_inputs.end.public_call_stack[i], inputs.public_call.call_stack_item.public_inputs.public_call_stack[i]); } @@ -537,8 +540,8 @@ TEST(public_kernel_tests, only_valid_update_requests_should_be_propagated) .old_value = 86543, .new_value = 86544, }; - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> update_requests = - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH>(); + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL> update_requests = + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL>(); update_requests[1] = first_valid; update_requests[3] = second_valid; inputs.public_call.call_stack_item.public_inputs.contract_storage_update_requests = update_requests; @@ -553,7 +556,7 @@ TEST(public_kernel_tests, only_valid_update_requests_should_be_propagated) ASSERT_FALSE(public_inputs.is_private); ASSERT_EQ(public_inputs.constants.tx_context, inputs.previous_kernel.public_inputs.constants.tx_context); - for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { + for (size_t i = 0; i < MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL; i++) { ASSERT_EQ(public_inputs.end.public_call_stack[i], inputs.public_call.call_stack_item.public_inputs.public_call_stack[i]); } @@ -636,7 +639,7 @@ TEST(public_kernel_tests, private_call_should_fail) TEST(public_kernel_tests, inconsistent_call_hash_should_fail) { - for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { + for (size_t i = 0; i < MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL; i++) { DummyBuilder dummyBuilder = DummyBuilder(format("public_kernel_tests__inconsistent_call_hash_should_fail-", i)); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); @@ -650,7 +653,7 @@ TEST(public_kernel_tests, inconsistent_call_hash_should_fail) TEST(public_kernel_tests, incorrect_storage_contract_address_fails_for_regular_calls) { - for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { + for (size_t i = 0; i < MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL; i++) { DummyBuilder dummyBuilder = DummyBuilder(format("public_kernel_tests__incorrect_storage_contract_address_fails_for_regular_calls-", i)); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); @@ -669,7 +672,7 @@ TEST(public_kernel_tests, incorrect_storage_contract_address_fails_for_regular_c TEST(public_kernel_tests, incorrect_msg_sender_fails_for_regular_calls) { - for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { + for (size_t i = 0; i < MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL; i++) { DummyBuilder dummyBuilder = DummyBuilder(format("public_kernel_tests__incorrect_msg_sender_fails_for_regular_calls-", i)); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); @@ -695,13 +698,13 @@ TEST(public_kernel_tests, public_kernel_circuit_succeeds_for_mixture_of_regular_ const auto contract_portal_address = NT::fr(inputs.public_call.portal_contract_address); // redefine the child calls/stacks to use some delegate calls - std::array child_call_stacks; + std::array child_call_stacks; NT::uint32 const seed = 1000; NT::fr child_contract_address = 100000; NT::fr child_portal_contract_address = 200000; NT::boolean is_delegate_call = false; - std::array call_stack_hashes{}; - for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { + std::array call_stack_hashes{}; + for (size_t i = 0; i < MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL; i++) { child_call_stacks[i] = // NOLINTNEXTLINE(readability-suspicious-call-argument) generate_call_stack_item(child_contract_address, @@ -734,10 +737,10 @@ TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_msg_sender_in const auto contract_portal_address = NT::fr(inputs.public_call.portal_contract_address); // set the first call stack item to be a delegate call - std::array child_call_stacks; + std::array child_call_stacks; NT::uint32 const seed = 1000; NT::fr const child_contract_address = 100000; - std::array call_stack_hashes{}; + std::array call_stack_hashes{}; child_call_stacks[0] = // NOLINTNEXTLINE(readability-suspicious-call-argument) generate_call_stack_item(child_contract_address, @@ -767,10 +770,10 @@ TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_storage_contr const auto contract_portal_address = NT::fr(inputs.public_call.portal_contract_address); // set the first call stack item to be a delegate call - std::array child_call_stacks; + std::array child_call_stacks; NT::uint32 const seed = 1000; NT::fr const child_contract_address = 100000; - std::array call_stack_hashes{}; + std::array call_stack_hashes{}; child_call_stacks[0] = generate_call_stack_item(child_contract_address, origin_msg_sender, child_contract_address, // this should be contract_address @@ -798,11 +801,11 @@ TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_portal_contra // const auto contract_portal_address = NT::fr(inputs.public_call.portal_contract_address); // set the first call stack item to be a delegate call - std::array child_call_stacks; + std::array child_call_stacks; NT::uint32 const seed = 1000; NT::fr const child_contract_address = 100000; NT::fr const child_portal_contract = 200000; - std::array call_stack_hashes{}; + std::array call_stack_hashes{}; // NOLINTNEXTLINE(readability-suspicious-call-argument) child_call_stacks[0] = generate_call_stack_item(child_contract_address, origin_msg_sender, @@ -832,14 +835,14 @@ TEST(public_kernel_tests, public_kernel_circuit_only_checks_non_empty_call_stack // set all but the first call stack item to have a zero call stack hash // these call stack items will have an contract portal address but will be ignored as the call stack will be ignored - std::array& child_call_stacks = + std::array& child_call_stacks = inputs.public_call.public_call_stack_preimages; - std::array& call_stack_hashes = + std::array& call_stack_hashes = inputs.public_call.call_stack_item.public_inputs.public_call_stack; NT::uint32 const seed = 1000; NT::fr const child_contract_address = 100000; NT::fr const child_portal_contract = 200000; - for (size_t i = 1; i < PUBLIC_CALL_STACK_LENGTH; i++) { + for (size_t i = 1; i < MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL; i++) { // NOLINTNEXTLINE(readability-suspicious-call-argument) child_call_stacks[i] = generate_call_stack_item(child_contract_address, origin_msg_sender, @@ -897,7 +900,8 @@ TEST(public_kernel_tests, private_previous_kernel_empty_public_call_stack_should DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__private_previous_kernel_empty_public_call_stack_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); - inputs.previous_kernel.public_inputs.end.public_call_stack = std::array{}; + inputs.previous_kernel.public_inputs.end.public_call_stack = + std::array{}; auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); ASSERT_TRUE(dummyBuilder.failed()); ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__EMPTY_PUBLIC_CALL_STACK); @@ -960,7 +964,8 @@ TEST(public_kernel_tests, public_previous_kernel_empty_public_call_stack_should_ DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__public_previous_kernel_empty_public_call_stack_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); - inputs.previous_kernel.public_inputs.end.public_call_stack = std::array{}; + inputs.previous_kernel.public_inputs.end.public_call_stack = + std::array{}; auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); ASSERT_TRUE(dummyBuilder.failed()); ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__EMPTY_PUBLIC_CALL_STACK); @@ -994,8 +999,8 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre .old_value = 86543, .new_value = 86544, }; - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> initial_writes = - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH>(); + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX> initial_writes = + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>(); initial_writes[0] = first_write; initial_writes[1] = second_write; inputs.previous_kernel.public_inputs.end.public_data_update_requests = initial_writes; @@ -1009,26 +1014,26 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre .leaf_index = 987654321, .value = 96544, }; - std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> initial_reads = - std::array, KERNEL_PUBLIC_DATA_READS_LENGTH>(); + std::array, MAX_PUBLIC_DATA_READS_PER_TX> initial_reads = + std::array, MAX_PUBLIC_DATA_READS_PER_TX>(); initial_reads[0] = first_read; initial_reads[1] = second_read; inputs.previous_kernel.public_inputs.end.public_data_reads = initial_reads; // setup 2 previous new commitments - std::array initial_commitments{}; + std::array initial_commitments{}; initial_commitments[0] = fr(1); initial_commitments[1] = fr(2); inputs.previous_kernel.public_inputs.end.new_commitments = initial_commitments; // setup 2 previous new nullifiers - std::array initial_nullifiers{}; + std::array initial_nullifiers{}; initial_nullifiers[0] = fr(12345); initial_nullifiers[1] = fr(67890); inputs.previous_kernel.public_inputs.end.new_nullifiers = initial_nullifiers; // setup 1 new l2 to l1 messages - std::array initial_l2_to_l1_messages{}; + std::array initial_l2_to_l1_messages{}; initial_l2_to_l1_messages[0] = fr(1); inputs.previous_kernel.public_inputs.end.new_l2_to_l1_msgs = initial_l2_to_l1_messages; @@ -1038,7 +1043,7 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre validate_private_data_propagation(inputs, public_inputs); // this call should have been popped from the public call stack and the stack of call pre images pushed on - for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { + for (size_t i = 0; i < MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL; i++) { ASSERT_EQ(public_inputs.end.public_call_stack[i], inputs.public_call.call_stack_item.public_inputs.public_call_stack[i]); } @@ -1064,7 +1069,7 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre const auto contract_address = inputs.public_call.call_stack_item.contract_address; const auto portal_contract_address = inputs.public_call.portal_contract_address; - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> const expected_new_writes = + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL> const expected_new_writes = public_data_update_requests_from_contract_storage_update_requests( inputs.public_call.call_stack_item.public_inputs.contract_storage_update_requests, contract_address); @@ -1089,7 +1094,7 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre expected_new_writes, public_inputs.end.public_data_update_requests)); - std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> const expected_new_reads = + std::array, MAX_PUBLIC_DATA_READS_PER_CALL> const expected_new_reads = public_data_reads_from_contract_storage_reads( inputs.public_call.call_stack_item.public_inputs.contract_storage_reads, contract_address); @@ -1097,14 +1102,15 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre expected_new_reads, public_inputs.end.public_data_reads)); - std::array const expected_new_commitments = new_commitments_as_siloed_commitments( - inputs.public_call.call_stack_item.public_inputs.new_commitments, contract_address); + std::array const expected_new_commitments = + new_commitments_as_siloed_commitments(inputs.public_call.call_stack_item.public_inputs.new_commitments, + contract_address); ASSERT_TRUE(source_arrays_are_in_target(inputs.previous_kernel.public_inputs.end.new_commitments, expected_new_commitments, public_inputs.end.new_commitments)); - std::array const expected_new_nullifiers = new_nullifiers_as_siloed_nullifiers( + std::array const expected_new_nullifiers = new_nullifiers_as_siloed_nullifiers( inputs.public_call.call_stack_item.public_inputs.new_nullifiers, contract_address); ASSERT_TRUE(source_arrays_are_in_target(inputs.previous_kernel.public_inputs.end.new_nullifiers, @@ -1115,7 +1121,7 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre fr const chain_id = inputs.previous_kernel.public_inputs.constants.tx_context.chain_id; fr const version = inputs.previous_kernel.public_inputs.constants.tx_context.version; - std::array const expected_new_messages = + std::array const expected_new_messages = new_l2_messages_from_message(inputs.public_call.call_stack_item.public_inputs.new_l2_to_l1_msgs, contract_address, portal_contract_address, @@ -1172,7 +1178,7 @@ TEST(public_kernel_tests, public_kernel_fails_creating_new_commitments_on_static // set previously set items to 0 inputs.public_call.call_stack_item.public_inputs.contract_storage_update_requests = - empty_array_of_values, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH>(); + empty_array_of_values, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL>(); // regenerate call data hash inputs.previous_kernel.public_inputs.end.public_call_stack[0] = @@ -1196,9 +1202,9 @@ TEST(public_kernel_tests, public_kernel_fails_creating_new_nullifiers_on_static_ // set previously set items to 0 inputs.public_call.call_stack_item.public_inputs.contract_storage_update_requests = - empty_array_of_values, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH>(); + empty_array_of_values, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL>(); inputs.public_call.call_stack_item.public_inputs.new_commitments = - empty_array_of_values(); + empty_array_of_values(); // regenerate call data hash inputs.previous_kernel.public_inputs.end.public_call_stack[0] = diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp index 1b9bb343ee16..0f610df737ff 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp @@ -228,7 +228,7 @@ void propagate_valid_public_data_update_requests(Builder& builder, const auto& contract_address = public_kernel_inputs.public_call.call_stack_item.contract_address; const auto& update_requests = public_kernel_inputs.public_call.call_stack_item.public_inputs.contract_storage_update_requests; - for (size_t i = 0; i < KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH; ++i) { + for (size_t i = 0; i < MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX; ++i) { const auto& update_request = update_requests[i]; if (update_request.is_empty()) { continue; @@ -255,7 +255,7 @@ void propagate_valid_public_data_reads(Builder& builder, { const auto& contract_address = public_kernel_inputs.public_call.call_stack_item.contract_address; const auto& reads = public_kernel_inputs.public_call.call_stack_item.public_inputs.contract_storage_reads; - for (size_t i = 0; i < KERNEL_PUBLIC_DATA_READS_LENGTH; ++i) { + for (size_t i = 0; i < MAX_PUBLIC_DATA_READS_PER_TX; ++i) { const auto& contract_storage_read = reads[i]; if (contract_storage_read.is_empty()) { continue; @@ -287,7 +287,7 @@ void propagate_new_commitments(Builder& builder, const auto& new_commitments = public_call_public_inputs.new_commitments; const auto& storage_contract_address = public_call_public_inputs.call_context.storage_contract_address; - std::array siloed_new_commitments{}; + std::array siloed_new_commitments{}; for (size_t i = 0; i < new_commitments.size(); ++i) { if (!new_commitments[i].is_zero()) { siloed_new_commitments[i] = silo_commitment(storage_contract_address, new_commitments[i]); @@ -316,7 +316,7 @@ void propagate_new_nullifiers(Builder& builder, const auto& new_nullifiers = public_call_public_inputs.new_nullifiers; const auto& storage_contract_address = public_call_public_inputs.call_context.storage_contract_address; - std::array siloed_new_nullifiers{}; + std::array siloed_new_nullifiers{}; for (size_t i = 0; i < new_nullifiers.size(); ++i) { if (!new_nullifiers[i].is_zero()) { siloed_new_nullifiers[i] = silo_nullifier(storage_contract_address, new_nullifiers[i]); @@ -345,7 +345,7 @@ void propagate_new_l2_to_l1_messages(Builder& builder, const auto& storage_contract_address = public_call_public_inputs.call_context.storage_contract_address; const auto& new_l2_to_l1_msgs = public_call_public_inputs.new_l2_to_l1_msgs; - std::array new_l2_to_l1_msgs_to_insert{}; + std::array new_l2_to_l1_msgs_to_insert{}; for (size_t i = 0; i < new_l2_to_l1_msgs.size(); ++i) { if (!new_l2_to_l1_msgs[i].is_zero()) { const auto chain_id = public_kernel_inputs.previous_kernel.public_inputs.constants.tx_context.chain_id; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp index 4c9c6f877278..30dd57971d4a 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -224,8 +224,8 @@ TEST_F(base_rollup_tests, native_contract_leaf_inserted_in_non_empty_snapshot_tr }; // Set the new_contracts_subtree_sibling_path - auto sibling_path = get_sibling_path( - start_contract_tree_snapshot, 12, CONTRACT_SUBTREE_DEPTH); + auto sibling_path = get_sibling_path( + start_contract_tree_snapshot, 12, CONTRACT_SUBTREE_HEIGHT); inputs.new_contracts_subtree_sibling_path = sibling_path; // create expected end contract tree snapshot @@ -255,11 +255,11 @@ TEST_F(base_rollup_tests, native_new_commitments_tree) // Then get sibling path so we can verify insert them into the tree. std::array, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() }; - std::array new_commitments = { 0, 1, 2, 3, 4, 5, 6, 7 }; + std::array new_commitments = { 0, 1, 2, 3, 4, 5, 6, 7 }; for (uint8_t i = 0; i < 2; i++) { - std::array kernel_commitments; - for (uint8_t j = 0; j < KERNEL_NEW_COMMITMENTS_LENGTH; j++) { - kernel_commitments[j] = new_commitments[i * KERNEL_NEW_COMMITMENTS_LENGTH + j]; + std::array kernel_commitments; + for (uint8_t j = 0; j < MAX_NEW_COMMITMENTS_PER_TX; j++) { + kernel_commitments[j] = new_commitments[i * MAX_NEW_COMMITMENTS_PER_TX + j]; } kernel_data[i].public_inputs.end.new_commitments = kernel_commitments; } @@ -275,7 +275,7 @@ TEST_F(base_rollup_tests, native_new_commitments_tree) } AppendOnlyTreeSnapshot const expected_end_commitments_snapshot = { .root = private_data_tree.root(), - .next_available_leaf_index = 2 * KERNEL_NEW_COMMITMENTS_LENGTH, + .next_available_leaf_index = 2 * MAX_NEW_COMMITMENTS_PER_TX, }; auto inputs = base_rollup_inputs_from_kernels(kernel_data); @@ -312,8 +312,8 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_empty) // This is because 0 values are not actually inserted into the tree, rather the inserted subtree is left // empty to begin with. - std::array const new_nullifiers{}; - std::vector initial_values(2 * KERNEL_NEW_NULLIFIERS_LENGTH - 1); + std::array const new_nullifiers{}; + std::vector initial_values(2 * MAX_NEW_NULLIFIERS_PER_TX - 1); for (size_t i = 0; i < initial_values.size(); i++) { initial_values[i] = i + 1; @@ -346,16 +346,16 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_empty) ASSERT_EQ(outputs.end_nullifier_tree_snapshot, end_nullifier_tree_snapshot); ASSERT_EQ(outputs.end_nullifier_tree_snapshot.root, outputs.start_nullifier_tree_snapshot.root); ASSERT_EQ(outputs.end_nullifier_tree_snapshot.next_available_leaf_index, - outputs.start_nullifier_tree_snapshot.next_available_leaf_index + 2 * KERNEL_NEW_NULLIFIERS_LENGTH); + outputs.start_nullifier_tree_snapshot.next_available_leaf_index + 2 * MAX_NEW_NULLIFIERS_PER_TX); ASSERT_FALSE(builder.failed()) << builder.failure_msgs; } -void nullifier_insertion_test(std::array new_nullifiers) +void nullifier_insertion_test(std::array new_nullifiers) { // @todo We can probably reuse this more than we are already doing. // Regression test caught when testing the typescript nullifier tree implementation - std::vector initial_values(2 * KERNEL_NEW_NULLIFIERS_LENGTH - 1); + std::vector initial_values(2 * MAX_NEW_NULLIFIERS_PER_TX - 1); for (size_t i = 0; i < initial_values.size(); i++) { initial_values[i] = i + 1; } @@ -370,9 +370,9 @@ void nullifier_insertion_test(std::array n DummyBuilder builder = DummyBuilder("base_rollup_tests__nullifier_insertion_test"); std::array, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() }; for (uint8_t i = 0; i < 2; i++) { - std::array kernel_nullifiers; - for (uint8_t j = 0; j < KERNEL_NEW_NULLIFIERS_LENGTH; j++) { - kernel_nullifiers[j] = new_nullifiers[i * KERNEL_NEW_NULLIFIERS_LENGTH + j]; + std::array kernel_nullifiers; + for (uint8_t j = 0; j < MAX_NEW_NULLIFIERS_PER_TX; j++) { + kernel_nullifiers[j] = new_nullifiers[i * MAX_NEW_NULLIFIERS_PER_TX + j]; } kernel_data[i].public_inputs.end.new_nullifiers = kernel_nullifiers; } @@ -386,16 +386,16 @@ void nullifier_insertion_test(std::array n ASSERT_EQ(outputs.start_nullifier_tree_snapshot, start_nullifier_tree_snapshot); ASSERT_EQ(outputs.end_nullifier_tree_snapshot, end_nullifier_tree_snapshot); ASSERT_EQ(outputs.end_nullifier_tree_snapshot.next_available_leaf_index, - outputs.start_nullifier_tree_snapshot.next_available_leaf_index + KERNEL_NEW_NULLIFIERS_LENGTH * 2); + outputs.start_nullifier_tree_snapshot.next_available_leaf_index + MAX_NEW_NULLIFIERS_PER_TX * 2); ASSERT_FALSE(builder.failed()) << builder.failure_msgs; } TEST_F(base_rollup_tests, native_new_nullifier_tree_all_larger) { - std::array initial_values; + std::array initial_values; for (size_t i = 0; i < initial_values.size(); i++) { - initial_values[i] = 2 * KERNEL_NEW_NULLIFIERS_LENGTH + i; + initial_values[i] = 2 * MAX_NEW_NULLIFIERS_PER_TX + i; } nullifier_insertion_test(initial_values); @@ -403,23 +403,23 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_all_larger) TEST_F(base_rollup_tests, native_new_nullifier_tree_sparse_insertions) { - std::array initial_values; + std::array initial_values; for (size_t i = 0; i < initial_values.size(); i++) { - initial_values[i] = 2 * KERNEL_NEW_NULLIFIERS_LENGTH + 5 * i + 1; + initial_values[i] = 2 * MAX_NEW_NULLIFIERS_PER_TX + 5 * i + 1; } nullifier_insertion_test(initial_values); } TEST_F(base_rollup_tests, native_new_nullifier_tree_sparse) { - std::array nullifiers; + std::array nullifiers; for (size_t i = 0; i < nullifiers.size(); i++) { - nullifiers[i] = 2 * KERNEL_NEW_NULLIFIERS_LENGTH + 5 * i + 1; + nullifiers[i] = 2 * MAX_NEW_NULLIFIERS_PER_TX + 5 * i + 1; } - std::vector initial_values(2 * KERNEL_NEW_NULLIFIERS_LENGTH - 1); + std::vector initial_values(2 * MAX_NEW_NULLIFIERS_PER_TX - 1); for (size_t i = 0; i < initial_values.size(); i++) { initial_values[i] = 5 * (i + 1); @@ -468,15 +468,15 @@ TEST_F(base_rollup_tests, native_nullifier_tree_regression) // KERNEL_NEW_NULLILFIERS_LENGTH -1 more) simulating that a rollup inserting two random values has already // succeeded. Note that this corresponds to 3 (1 already initialized and 2 new ones) base rollups. This rollup then // adds two further random values that will end up having their low nullifiers point at each other - std::vector initial_values(6 * KERNEL_NEW_NULLIFIERS_LENGTH - 1, 0); - for (size_t i = 0; i < 2 * KERNEL_NEW_NULLIFIERS_LENGTH - 1; i++) { + std::vector initial_values(6 * MAX_NEW_NULLIFIERS_PER_TX - 1, 0); + for (size_t i = 0; i < 2 * MAX_NEW_NULLIFIERS_PER_TX - 1; i++) { initial_values[i] = i + 1; } // Note these are hex representations initial_values[7] = uint256_t("2bb9aa4a22a6ae7204f2c67abaab59cead6558cde4ee25ce3464704cb2e38136"); initial_values[8] = uint256_t("16a732095298ccca828c4d747813f8bd46e188079ed17904e2c9de50760833c8"); - std::array new_nullifiers = { 0 }; + std::array new_nullifiers = { 0 }; new_nullifiers[0] = uint256_t("16da4f27fb78de7e0db4c5a04b569bc46382c5f471da2f7d670beff1614e0118"), new_nullifiers[1] = uint256_t("26ab07ce103a55e29f11478eaa36cebd10c4834b143a7debcc7ef53bfdb547dd"); @@ -514,7 +514,7 @@ TEST_F(base_rollup_tests, native_nullifier_tree_regression) TEST_F(base_rollup_tests, nullifier_tree_regression_2) { // Regression test caught when testing the typescript nullifier tree implementation - std::array new_nullifiers = { 0 }; + std::array new_nullifiers = { 0 }; new_nullifiers[0] = uint256_t("2a7d956c1365d259646d2d85babe1abb793bb8789e98df7e2336a29a0c91fd01"); new_nullifiers[1] = uint256_t("236bf2d113f9ffee89df1a7a04890c9ad3583c6773eb9cdec484184f66abd4c6"); new_nullifiers[4] = uint256_t("2f5c8a1ee33c7104b244e22a3e481637cd501c9eae868cfab6b16e3b4ef3d635"); @@ -525,7 +525,7 @@ TEST_F(base_rollup_tests, nullifier_tree_regression_2) TEST_F(base_rollup_tests, nullifier_tree_regression_3) { - std::array new_nullifiers = { 0 }; + std::array new_nullifiers = { 0 }; new_nullifiers[0] = uint256_t("0740a17aa6437e71836d2adcdcb3f52879bb869cdd9c8fb8dc39a12846cd17f2"); new_nullifiers[1] = uint256_t("282e0e2f38310a7c7c98b636830b66f3276294560e26ef2499da10892f00af8f"); new_nullifiers[4] = uint256_t("0f117936e888bd3befb4435f4d65300d25609e95a3d1563f62ef7e58c294f578"); @@ -544,8 +544,8 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_double_spend) BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); fr const nullifier_to_insert = - 2 * KERNEL_NEW_NULLIFIERS_LENGTH + 4; // arbitrary value greater than 2 * KERNEL_NEW_NULLIFIERS_LENGTH - std::array new_nullifiers{}; + 2 * MAX_NEW_NULLIFIERS_PER_TX + 4; // arbitrary value greater than 2 * MAX_NEW_NULLIFIERS_PER_TX + std::array new_nullifiers{}; new_nullifiers[0] = nullifier_to_insert; new_nullifiers[2] = nullifier_to_insert; @@ -586,9 +586,9 @@ TEST_F(base_rollup_tests, native_calldata_hash) // Commitments inserted are [1,2,3,4,5,6,7,8 ...]. Nullifiers inserted are [8,9,10,11,12,13,14,15 ...] for (size_t i = 0; i < 2; ++i) { - for (size_t j = 0; j < KERNEL_NEW_NULLIFIERS_LENGTH; j++) { - kernel_data[i].public_inputs.end.new_commitments[j] = fr(i * KERNEL_NEW_NULLIFIERS_LENGTH + j + 1); - kernel_data[i].public_inputs.end.new_nullifiers[j] = fr((2 + i) * KERNEL_NEW_NULLIFIERS_LENGTH + j); + for (size_t j = 0; j < MAX_NEW_NULLIFIERS_PER_TX; j++) { + kernel_data[i].public_inputs.end.new_commitments[j] = fr(i * MAX_NEW_NULLIFIERS_PER_TX + j + 1); + kernel_data[i].public_inputs.end.new_nullifiers[j] = fr((2 + i) * MAX_NEW_NULLIFIERS_PER_TX + j); } } diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp index 137245dbe1df..27f857499ae3 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp @@ -84,7 +84,7 @@ std::vector calculate_contract_leaves(BaseRollupInputs const& baseRollup NT::fr calculate_contract_subtree(std::vector contract_leaves) { - MerkleTree contracts_tree = MerkleTree(CONTRACT_SUBTREE_DEPTH); + MerkleTree contracts_tree = MerkleTree(CONTRACT_SUBTREE_HEIGHT); // Compute the merkle root of a contract subtree // Contracts subtree @@ -96,19 +96,19 @@ NT::fr calculate_contract_subtree(std::vector contract_leaves) NT::fr calculate_commitments_subtree(DummyBuilder& builder, BaseRollupInputs const& baseRollupInputs) { - MerkleTree commitments_tree = MerkleTree(PRIVATE_DATA_SUBTREE_DEPTH); + MerkleTree commitments_tree = MerkleTree(PRIVATE_DATA_SUBTREE_HEIGHT); for (size_t i = 0; i < 2; i++) { auto new_commitments = baseRollupInputs.kernel_data[i].public_inputs.end.new_commitments; // Our commitments size MUST be 4 to calculate our subtrees correctly - builder.do_assert(new_commitments.size() == KERNEL_NEW_COMMITMENTS_LENGTH, + builder.do_assert(new_commitments.size() == MAX_NEW_COMMITMENTS_PER_TX, "New commitments in kernel data must be 4", CircuitErrorCode::BASE__INCORRECT_NUM_OF_NEW_COMMITMENTS); for (size_t j = 0; j < new_commitments.size(); j++) { // todo: batch insert - commitments_tree.update_element(i * KERNEL_NEW_COMMITMENTS_LENGTH + j, new_commitments[j]); + commitments_tree.update_element(i * MAX_NEW_COMMITMENTS_PER_TX + j, new_commitments[j]); } } @@ -188,10 +188,10 @@ void perform_historical_l1_to_l2_message_tree_membership_checks(DummyBuilder& bu } NT::fr create_nullifier_subtree( - std::array const& nullifier_leaves) + std::array const& nullifier_leaves) { // Build a merkle tree of the nullifiers - MerkleTree nullifier_subtree = MerkleTree(NULLIFIER_SUBTREE_DEPTH); + MerkleTree nullifier_subtree = MerkleTree(NULLIFIER_SUBTREE_HEIGHT); for (size_t i = 0; i < nullifier_leaves.size(); i++) { // hash() checks if nullifier is empty (and if so returns 0) nullifier_subtree.update_element(i, nullifier_leaves[i].hash()); @@ -223,7 +223,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB // 2. If we receive the 0 nullifier leaf (where all values are 0, we skip insertion and leave a sparse subtree) // New nullifier subtree - std::array nullifier_insertion_subtree; + std::array nullifier_insertion_subtree; // This will update on each iteration auto current_nullifier_tree_root = baseRollupInputs.start_nullifier_tree_snapshot.root; @@ -236,9 +236,9 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB for (size_t i = 0; i < 2; i++) { auto new_nullifiers = baseRollupInputs.kernel_data[i].public_inputs.end.new_nullifiers; // For each of our nullifiers - for (size_t j = 0; j < KERNEL_NEW_NULLIFIERS_LENGTH; j++) { + for (size_t j = 0; j < MAX_NEW_NULLIFIERS_PER_TX; j++) { // Witness containing index and path - auto nullifier_index = i * KERNEL_NEW_NULLIFIERS_LENGTH + j; + auto nullifier_index = i * MAX_NEW_NULLIFIERS_PER_TX + j; auto witness = baseRollupInputs.low_nullifier_membership_witness[nullifier_index]; // Preimage of the lo-index required for a non-membership proof @@ -348,9 +348,9 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB } // Check that the new subtree is to be inserted at the next location, and is empty currently - const auto empty_nullifier_subtree_root = components::calculate_empty_tree_root(NULLIFIER_SUBTREE_DEPTH); + const auto empty_nullifier_subtree_root = components::calculate_empty_tree_root(NULLIFIER_SUBTREE_HEIGHT); auto leafIndexNullifierSubtreeDepth = - baseRollupInputs.start_nullifier_tree_snapshot.next_available_leaf_index >> NULLIFIER_SUBTREE_DEPTH; + baseRollupInputs.start_nullifier_tree_snapshot.next_available_leaf_index >> NULLIFIER_SUBTREE_HEIGHT; check_membership(builder, empty_nullifier_subtree_root, leafIndexNullifierSubtreeDepth, @@ -364,7 +364,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB // Calculate the new root // We are inserting a subtree rather than a full tree here - auto subtree_index = start_insertion_index >> (NULLIFIER_SUBTREE_DEPTH); + auto subtree_index = start_insertion_index >> (NULLIFIER_SUBTREE_HEIGHT); auto new_root = root_from_sibling_path(nullifier_subtree_root, subtree_index, nullifier_sibling_path); // Return the new state of the nullifier tree @@ -377,14 +377,14 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB fr insert_public_data_update_requests( DummyBuilder& builder, fr tree_root, - std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> const& + std::array, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX> const& public_data_update_requests, size_t witnesses_offset, - std::array, 2 * KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> const& witnesses) + std::array, 2 * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX> const& witnesses) { auto root = tree_root; - for (size_t i = 0; i < KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH; ++i) { + for (size_t i = 0; i < MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX; ++i) { const auto& state_write = public_data_update_requests[i]; const auto& witness = witnesses[i + witnesses_offset]; @@ -408,11 +408,11 @@ fr insert_public_data_update_requests( void validate_public_data_reads( DummyBuilder& builder, fr tree_root, - std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> const& public_data_reads, + std::array, MAX_PUBLIC_DATA_READS_PER_TX> const& public_data_reads, size_t witnesses_offset, - std::array, 2 * KERNEL_PUBLIC_DATA_READS_LENGTH> const& witnesses) + std::array, 2 * MAX_PUBLIC_DATA_READS_PER_TX> const& witnesses) { - for (size_t i = 0; i < KERNEL_PUBLIC_DATA_READS_LENGTH; ++i) { + for (size_t i = 0; i < MAX_PUBLIC_DATA_READS_PER_TX; ++i) { const auto& public_data_read = public_data_reads[i]; const auto& witness = witnesses[i + witnesses_offset]; @@ -450,14 +450,14 @@ fr validate_and_process_public_state(DummyBuilder& builder, BaseRollupInputs con validate_public_data_reads(builder, mid_public_data_tree_root, baseRollupInputs.kernel_data[1].public_inputs.end.public_data_reads, - KERNEL_PUBLIC_DATA_READS_LENGTH, + MAX_PUBLIC_DATA_READS_PER_TX, baseRollupInputs.new_public_data_reads_sibling_paths); auto end_public_data_tree_root = insert_public_data_update_requests( builder, mid_public_data_tree_root, baseRollupInputs.kernel_data[1].public_inputs.end.public_data_update_requests, - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, baseRollupInputs.new_public_data_update_requests_sibling_paths); return end_public_data_tree_root; @@ -493,25 +493,25 @@ BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& builder, BaseRol NT::fr const commitments_tree_subroot = calculate_commitments_subtree(builder, baseRollupInputs); // Insert commitment subtrees: - const auto empty_commitments_subtree_root = components::calculate_empty_tree_root(PRIVATE_DATA_SUBTREE_DEPTH); + const auto empty_commitments_subtree_root = components::calculate_empty_tree_root(PRIVATE_DATA_SUBTREE_HEIGHT); auto end_private_data_tree_snapshot = components::insert_subtree_to_snapshot_tree(builder, baseRollupInputs.start_private_data_tree_snapshot, baseRollupInputs.new_commitments_subtree_sibling_path, empty_commitments_subtree_root, commitments_tree_subroot, - PRIVATE_DATA_SUBTREE_DEPTH, + PRIVATE_DATA_SUBTREE_HEIGHT, "empty commitment subtree membership check"); // Insert contract subtrees: - const auto empty_contracts_subtree_root = components::calculate_empty_tree_root(CONTRACT_SUBTREE_DEPTH); + const auto empty_contracts_subtree_root = components::calculate_empty_tree_root(CONTRACT_SUBTREE_HEIGHT); auto end_contract_tree_snapshot = components::insert_subtree_to_snapshot_tree(builder, baseRollupInputs.start_contract_tree_snapshot, baseRollupInputs.new_contracts_subtree_sibling_path, empty_contracts_subtree_root, contracts_tree_subroot, - CONTRACT_SUBTREE_DEPTH, + CONTRACT_SUBTREE_HEIGHT, "empty contract subtree membership check"); // Insert nullifiers: diff --git a/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp b/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp index 2f706bde379f..da3b4c2149b2 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp @@ -103,18 +103,18 @@ std::array compute_kernels_calldata_hash( { // Compute calldata hashes // Consist of 2 kernels - // 2 * KERNEL_NEW_COMMITMENTS_LENGTH fields for commitments - // 2 * KERNEL_NEW_NULLIFIERS_LENGTH fields for nullifiers + // 2 * MAX_NEW_COMMITMENTS_PER_TX fields for commitments + // 2 * MAX_NEW_NULLIFIERS_PER_TX fields for nullifiers // 8 public data update requests (4 per kernel) -> 16 fields // 4 l2 -> l1 messages (2 per kernel) -> 4 fields // 2 contract deployments (1 per kernel) -> 6 fields // 2 encrypted logs hashes (1 per kernel) -> 4 fields --> 2 sha256 hashes --> 64 bytes // 2 unencrypted logs hashes (1 per kernel) -> 4 fields --> 2 sha256 hashes --> 64 bytes auto const number_of_inputs = - (KERNEL_NEW_COMMITMENTS_LENGTH + KERNEL_NEW_NULLIFIERS_LENGTH + KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH * 2 + - KERNEL_NEW_L2_TO_L1_MSGS_LENGTH + KERNEL_NEW_CONTRACTS_LENGTH * 3 + - KERNEL_NUM_ENCRYPTED_LOGS_HASHES * NUM_FIELDS_PER_SHA256 + - KERNEL_NUM_UNENCRYPTED_LOGS_HASHES * NUM_FIELDS_PER_SHA256) * + (MAX_NEW_COMMITMENTS_PER_TX + MAX_NEW_NULLIFIERS_PER_TX + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * 2 + + MAX_NEW_L2_TO_L1_MSGS_PER_TX + MAX_NEW_CONTRACTS_PER_TX * 3 + + NUM_ENCRYPTED_LOGS_HASHES_PER_TX * NUM_FIELDS_PER_SHA256 + + NUM_UNENCRYPTED_LOGS_HASHES_PER_TX * NUM_FIELDS_PER_SHA256) * 2; std::array calldata_hash_inputs{}; @@ -128,45 +128,45 @@ std::array compute_kernels_calldata_hash( size_t offset = 0; - for (size_t j = 0; j < KERNEL_NEW_COMMITMENTS_LENGTH; j++) { - calldata_hash_inputs[offset + i * KERNEL_NEW_COMMITMENTS_LENGTH + j] = new_commitments[j]; + for (size_t j = 0; j < MAX_NEW_COMMITMENTS_PER_TX; j++) { + calldata_hash_inputs[offset + i * MAX_NEW_COMMITMENTS_PER_TX + j] = new_commitments[j]; } - offset += KERNEL_NEW_COMMITMENTS_LENGTH * 2; + offset += MAX_NEW_COMMITMENTS_PER_TX * 2; - for (size_t j = 0; j < KERNEL_NEW_NULLIFIERS_LENGTH; j++) { - calldata_hash_inputs[offset + i * KERNEL_NEW_NULLIFIERS_LENGTH + j] = new_nullifiers[j]; + for (size_t j = 0; j < MAX_NEW_NULLIFIERS_PER_TX; j++) { + calldata_hash_inputs[offset + i * MAX_NEW_NULLIFIERS_PER_TX + j] = new_nullifiers[j]; } - offset += KERNEL_NEW_NULLIFIERS_LENGTH * 2; + offset += MAX_NEW_NULLIFIERS_PER_TX * 2; - for (size_t j = 0; j < KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH; j++) { - calldata_hash_inputs[offset + i * KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH * 2 + j * 2] = + for (size_t j = 0; j < MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX; j++) { + calldata_hash_inputs[offset + i * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * 2 + j * 2] = public_data_update_requests[j].leaf_index; - calldata_hash_inputs[offset + i * KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH * 2 + j * 2 + 1] = + calldata_hash_inputs[offset + i * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * 2 + j * 2 + 1] = public_data_update_requests[j].new_value; } - offset += KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH * 2 * 2; + offset += MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * 2 * 2; - for (size_t j = 0; j < KERNEL_NEW_L2_TO_L1_MSGS_LENGTH; j++) { - calldata_hash_inputs[offset + i * KERNEL_NEW_L2_TO_L1_MSGS_LENGTH + j] = newL2ToL1msgs[j]; + for (size_t j = 0; j < MAX_NEW_L2_TO_L1_MSGS_PER_TX; j++) { + calldata_hash_inputs[offset + i * MAX_NEW_L2_TO_L1_MSGS_PER_TX + j] = newL2ToL1msgs[j]; } - offset += KERNEL_NEW_L2_TO_L1_MSGS_LENGTH * 2; + offset += MAX_NEW_L2_TO_L1_MSGS_PER_TX * 2; auto const contract_leaf = kernel_data[i].public_inputs.end.new_contracts[0]; calldata_hash_inputs[offset + i] = contract_leaf.hash(); - offset += KERNEL_NEW_CONTRACTS_LENGTH * 2; + offset += MAX_NEW_CONTRACTS_PER_TX * 2; auto new_contracts = kernel_data[i].public_inputs.end.new_contracts; calldata_hash_inputs[offset + i * 2] = new_contracts[0].contract_address; calldata_hash_inputs[offset + i * 2 + 1] = new_contracts[0].portal_contract_address; - offset += KERNEL_NEW_CONTRACTS_LENGTH * 2 * 2; + offset += MAX_NEW_CONTRACTS_PER_TX * 2 * 2; for (size_t j = 0; j < NUM_FIELDS_PER_SHA256; j++) { calldata_hash_inputs[offset + i * 2 + j] = encryptedLogsHash[j]; } - offset += KERNEL_NUM_ENCRYPTED_LOGS_HASHES * NUM_FIELDS_PER_SHA256 * 2; + offset += NUM_ENCRYPTED_LOGS_HASHES_PER_TX * NUM_FIELDS_PER_SHA256 * 2; for (size_t j = 0; j < NUM_FIELDS_PER_SHA256; j++) { calldata_hash_inputs[offset + i * 2 + j] = unencryptedLogsHash[j]; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp index bec64e1093ac..678bed199ceb 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp @@ -183,17 +183,17 @@ TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) // Create commitments for (uint8_t kernel_j = 0; kernel_j < 4; kernel_j++) { - std::array new_commitments; - for (uint8_t commitment_k = 0; commitment_k < KERNEL_NEW_COMMITMENTS_LENGTH; commitment_k++) { - auto val = fr(kernel_j * KERNEL_NEW_COMMITMENTS_LENGTH + commitment_k + 1); + std::array new_commitments; + for (uint8_t commitment_k = 0; commitment_k < MAX_NEW_COMMITMENTS_PER_TX; commitment_k++) { + auto val = fr(kernel_j * MAX_NEW_COMMITMENTS_PER_TX + commitment_k + 1); new_commitments[commitment_k] = val; - data_tree.update_element(kernel_j * KERNEL_NEW_COMMITMENTS_LENGTH + commitment_k, val); + data_tree.update_element(kernel_j * MAX_NEW_COMMITMENTS_PER_TX + commitment_k, val); } kernels[kernel_j].public_inputs.end.new_commitments = new_commitments; - std::array new_l2_to_l1_messages; - for (uint8_t i = 0; i < KERNEL_NEW_L2_TO_L1_MSGS_LENGTH; i++) { - auto val = fr(kernel_j * KERNEL_NEW_L2_TO_L1_MSGS_LENGTH + i + 1); + std::array new_l2_to_l1_messages; + for (uint8_t i = 0; i < MAX_NEW_L2_TO_L1_MSGS_PER_TX; i++) { + auto val = fr(kernel_j * MAX_NEW_L2_TO_L1_MSGS_PER_TX + i + 1); new_l2_to_l1_messages[i] = val; } kernels[kernel_j].public_inputs.end.new_l2_to_l1_msgs = new_l2_to_l1_messages; @@ -258,7 +258,7 @@ TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) rootRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_private_data_tree_snapshot); AppendOnlyTreeSnapshot const expected_private_data_tree_snapshot = { .root = data_tree.root(), .next_available_leaf_index = - 4 * KERNEL_NEW_COMMITMENTS_LENGTH }; + 4 * MAX_NEW_COMMITMENTS_PER_TX }; ASSERT_EQ(outputs.end_private_data_tree_snapshot, expected_private_data_tree_snapshot); // Check public data trees diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp index 945d3bcbbdd6..f6f7f9a2c6a9 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp @@ -26,7 +26,7 @@ namespace aztec3::circuits::rollup::native_root_rollup { */ NT::fr calculate_subtree(std::array leaves) { - MerkleTree merkle_tree = MerkleTree(L1_TO_L2_MSG_SUBTREE_DEPTH); + MerkleTree merkle_tree = MerkleTree(L1_TO_L2_MSG_SUBTREE_HEIGHT); for (size_t i = 0; i < NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP; i++) { merkle_tree.update_element(i, leaves[i]); @@ -109,14 +109,14 @@ RootRollupPublicInputs root_rollup_circuit(DummyBuilder& builder, RootRollupInpu auto l1_to_l2_subtree_root = calculate_subtree(rootRollupInputs.l1_to_l2_messages); // // Insert subtree into the l1 to l2 data tree - const auto empty_l1_to_l2_subtree_root = components::calculate_empty_tree_root(L1_TO_L2_MSG_SUBTREE_DEPTH); + const auto empty_l1_to_l2_subtree_root = components::calculate_empty_tree_root(L1_TO_L2_MSG_SUBTREE_HEIGHT); auto new_l1_to_l2_messages_tree_snapshot = components::insert_subtree_to_snapshot_tree(builder, rootRollupInputs.start_l1_to_l2_message_tree_snapshot, rootRollupInputs.new_l1_to_l2_message_tree_root_sibling_path, empty_l1_to_l2_subtree_root, l1_to_l2_subtree_root, - L1_TO_L2_MSG_SUBTREE_DEPTH, + L1_TO_L2_MSG_SUBTREE_HEIGHT, "l1 to l2 message tree insertion"); // Update the historic l1 to l2 data tree diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp index cd531d85473f..c9f4821122fb 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp @@ -52,9 +52,9 @@ namespace aztec3::circuits::rollup::test_utils::utils { std::vector get_empty_calldata_leaf() { auto const number_of_inputs = - (KERNEL_NEW_COMMITMENTS_LENGTH + KERNEL_NEW_NULLIFIERS_LENGTH + KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH * 2 + - KERNEL_NEW_L2_TO_L1_MSGS_LENGTH + KERNEL_NEW_CONTRACTS_LENGTH * 3 + KERNEL_NUM_ENCRYPTED_LOGS_HASHES * 2 + - KERNEL_NUM_UNENCRYPTED_LOGS_HASHES * 2) * + (MAX_NEW_COMMITMENTS_PER_TX + MAX_NEW_NULLIFIERS_PER_TX + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * 2 + + MAX_NEW_L2_TO_L1_MSGS_PER_TX + MAX_NEW_CONTRACTS_PER_TX * 3 + NUM_ENCRYPTED_LOGS_HASHES_PER_TX * 2 + + NUM_UNENCRYPTED_LOGS_HASHES_PER_TX * 2) * 2; // We subtract 4 from inputs size because 1 logs hash is stored in 2 fields and those 2 fields get converted only @@ -128,16 +128,16 @@ BaseRollupInputs base_rollup_inputs_from_kernels(std::array kerne }, .constants = constantRollupData }; - std::vector initial_values(2 * KERNEL_NEW_NULLIFIERS_LENGTH - 1); + std::vector initial_values(2 * MAX_NEW_NULLIFIERS_PER_TX - 1); for (size_t i = 0; i < initial_values.size(); i++) { initial_values[i] = i + 1; } - std::array nullifiers; + std::array nullifiers; for (size_t i = 0; i < 2; i++) { - for (size_t j = 0; j < KERNEL_NEW_NULLIFIERS_LENGTH; j++) { - nullifiers[i * KERNEL_NEW_NULLIFIERS_LENGTH + j] = kernel_data[i].public_inputs.end.new_nullifiers[j]; + for (size_t j = 0; j < MAX_NEW_NULLIFIERS_PER_TX; j++) { + nullifiers[i * MAX_NEW_NULLIFIERS_PER_TX + j] = kernel_data[i].public_inputs.end.new_nullifiers[j]; } } @@ -147,10 +147,10 @@ BaseRollupInputs base_rollup_inputs_from_kernels(std::array kerne baseRollupInputs = std::get<0>(temp); baseRollupInputs.new_contracts_subtree_sibling_path = - get_sibling_path(contract_tree, 0, CONTRACT_SUBTREE_DEPTH); + get_sibling_path(contract_tree, 0, CONTRACT_SUBTREE_HEIGHT); baseRollupInputs.new_commitments_subtree_sibling_path = - get_sibling_path(private_data_tree, 0, PRIVATE_DATA_SUBTREE_DEPTH); + get_sibling_path(private_data_tree, 0, PRIVATE_DATA_SUBTREE_HEIGHT); // Update public data tree to generate sibling paths: we first set the initial public data tree to the result of all @@ -183,17 +183,17 @@ BaseRollupInputs base_rollup_inputs_from_kernels(std::array kerne // Then we collect all sibling paths for the reads in the left tx, and then apply the update requests while // collecting their paths. And then repeat for the right tx. for (size_t i = 0; i < 2; i++) { - for (size_t j = 0; j < KERNEL_PUBLIC_DATA_READS_LENGTH; j++) { + for (size_t j = 0; j < MAX_PUBLIC_DATA_READS_PER_TX; j++) { auto public_data_read = kernel_data[i].public_inputs.end.public_data_reads[j]; if (public_data_read.is_empty()) { continue; } auto leaf_index = uint256_t(public_data_read.leaf_index); - baseRollupInputs.new_public_data_reads_sibling_paths[i * KERNEL_PUBLIC_DATA_READS_LENGTH + j] = + baseRollupInputs.new_public_data_reads_sibling_paths[i * MAX_PUBLIC_DATA_READS_PER_TX + j] = get_sibling_path(public_data_tree, leaf_index); } - for (size_t j = 0; j < KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH; j++) { + for (size_t j = 0; j < MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX; j++) { auto public_data_update_request = kernel_data[i].public_inputs.end.public_data_update_requests[j]; if (public_data_update_request.is_empty()) { continue; @@ -201,7 +201,7 @@ BaseRollupInputs base_rollup_inputs_from_kernels(std::array kerne auto leaf_index = uint256_t(public_data_update_request.leaf_index); public_data_tree.update_element(leaf_index, public_data_update_request.new_value); baseRollupInputs - .new_public_data_update_requests_sibling_paths[i * KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH + j] = + .new_public_data_update_requests_sibling_paths[i * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX + j] = get_sibling_path(public_data_tree, leaf_index); } } @@ -254,25 +254,25 @@ std::array, 2> get_previous_rollup_data(DummyBuilder& bui // Build the trees based on inputs in base_rollup_input_1. MerkleTree private_data_tree = MerkleTree(PRIVATE_DATA_TREE_HEIGHT); MerkleTree contract_tree = MerkleTree(CONTRACT_TREE_HEIGHT); - std::vector initial_values(2 * KERNEL_NEW_NULLIFIERS_LENGTH - 1); + std::vector initial_values(2 * MAX_NEW_NULLIFIERS_PER_TX - 1); for (size_t i = 0; i < initial_values.size(); i++) { initial_values[i] = i + 1; } - std::array nullifiers; + std::array nullifiers; for (size_t i = 0; i < 2; i++) { - for (size_t j = 0; j < KERNEL_NEW_COMMITMENTS_LENGTH; j++) { - private_data_tree.update_element(i * KERNEL_NEW_COMMITMENTS_LENGTH + j, + for (size_t j = 0; j < MAX_NEW_COMMITMENTS_PER_TX; j++) { + private_data_tree.update_element(i * MAX_NEW_COMMITMENTS_PER_TX + j, kernel_data[i].public_inputs.end.new_commitments[j]); } auto contract_data = kernel_data[i].public_inputs.end.new_contracts[0]; if (!contract_data.is_empty()) { contract_tree.update_element(i, contract_data.hash()); } - for (size_t j = 0; j < KERNEL_NEW_NULLIFIERS_LENGTH; j++) { + for (size_t j = 0; j < MAX_NEW_NULLIFIERS_PER_TX; j++) { initial_values.push_back(kernel_data[i].public_inputs.end.new_nullifiers[j]); - nullifiers[i * KERNEL_NEW_NULLIFIERS_LENGTH + j] = kernel_data[2 + i].public_inputs.end.new_nullifiers[j]; + nullifiers[i * MAX_NEW_NULLIFIERS_PER_TX + j] = kernel_data[2 + i].public_inputs.end.new_nullifiers[j]; } } @@ -285,10 +285,10 @@ std::array, 2> get_previous_rollup_data(DummyBuilder& bui base_rollup_input_2.start_contract_tree_snapshot = base_public_input_1.end_contract_tree_snapshot; base_rollup_input_2.new_contracts_subtree_sibling_path = - get_sibling_path(contract_tree, 2, CONTRACT_SUBTREE_DEPTH); + get_sibling_path(contract_tree, 2, CONTRACT_SUBTREE_HEIGHT); base_rollup_input_2.new_commitments_subtree_sibling_path = - get_sibling_path( - private_data_tree, 2 * KERNEL_NEW_COMMITMENTS_LENGTH, PRIVATE_DATA_SUBTREE_DEPTH); + get_sibling_path( + private_data_tree, 2 * MAX_NEW_COMMITMENTS_PER_TX, PRIVATE_DATA_SUBTREE_HEIGHT); auto base_public_input_2 = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, base_rollup_input_2); @@ -343,7 +343,7 @@ RootRollupInputs get_root_rollup_inputs(utils::DummyBuilder& builder, get_sibling_path(historic_l1_to_l2_msg_tree, 1, 0); // l1 to l2 tree auto l1_to_l2_tree_sibling_path = - get_sibling_path(l1_to_l2_msg_tree, 0, L1_TO_L2_MSG_SUBTREE_DEPTH); + get_sibling_path(l1_to_l2_msg_tree, 0, L1_TO_L2_MSG_SUBTREE_HEIGHT); // l1_to_l2_message tree snapshots AppendOnlyTreeSnapshot const start_l1_to_l2_msg_tree_snapshot = { @@ -392,7 +392,7 @@ nullifier_tree_testing_values generate_nullifier_tree_testing_values(BaseRollupI size_t starting_insertion_value = 0, size_t spacing = 5) { - const size_t NUMBER_OF_NULLIFIERS = KERNEL_NEW_NULLIFIERS_LENGTH * 2; + const size_t NUMBER_OF_NULLIFIERS = MAX_NEW_NULLIFIERS_PER_TX * 2; std::array nullifiers; for (size_t i = 0; i < NUMBER_OF_NULLIFIERS; ++i) { auto insertion_val = (starting_insertion_value + i * spacing); @@ -409,11 +409,11 @@ nullifier_tree_testing_values generate_nullifier_tree_testing_values(BaseRollupI } nullifier_tree_testing_values generate_nullifier_tree_testing_values( - BaseRollupInputs inputs, std::array new_nullifiers, size_t spacing = 5) + BaseRollupInputs inputs, std::array new_nullifiers, size_t spacing = 5) { // Generate initial values lin spaced std::vector initial_values; - for (size_t i = 1; i < 2 * KERNEL_NEW_NULLIFIERS_LENGTH; ++i) { + for (size_t i = 1; i < 2 * MAX_NEW_NULLIFIERS_PER_TX; ++i) { initial_values.emplace_back(i * spacing); } @@ -422,7 +422,7 @@ nullifier_tree_testing_values generate_nullifier_tree_testing_values( nullifier_tree_testing_values generate_nullifier_tree_testing_values_explicit( BaseRollupInputs rollupInputs, - std::array new_nullifiers, + std::array new_nullifiers, const std::vector& initial_values) { size_t const start_tree_size = initial_values.size() + 1; @@ -435,21 +435,21 @@ nullifier_tree_testing_values generate_nullifier_tree_testing_values_explicit( .next_available_leaf_index = static_cast(start_tree_size), }; - const size_t NUMBER_OF_NULLIFIERS = KERNEL_NEW_NULLIFIERS_LENGTH * 2; + const size_t NUMBER_OF_NULLIFIERS = MAX_NEW_NULLIFIERS_PER_TX * 2; std::array new_nullifier_leaves{}; // Calculate the predecessor nullifier pre-images // Get insertion values std::vector insertion_values; - std::array new_nullifiers_kernel_1{}; - std::array new_nullifiers_kernel_2{}; + std::array new_nullifiers_kernel_1{}; + std::array new_nullifiers_kernel_2{}; for (size_t i = 0; i < NUMBER_OF_NULLIFIERS; ++i) { auto insertion_val = new_nullifiers[i]; - if (i < KERNEL_NEW_NULLIFIERS_LENGTH) { + if (i < MAX_NEW_NULLIFIERS_PER_TX) { new_nullifiers_kernel_1[i] = insertion_val; } else { - new_nullifiers_kernel_2[i - KERNEL_NEW_NULLIFIERS_LENGTH] = insertion_val; + new_nullifiers_kernel_2[i - MAX_NEW_NULLIFIERS_PER_TX] = insertion_val; } insertion_values.push_back(insertion_val); reference_tree.update_element(insertion_val); @@ -494,10 +494,10 @@ nullifier_tree_testing_values generate_nullifier_tree_testing_values_explicit( }; std::vector sibling_path = reference_tree.get_sibling_path(start_tree_size); - std::array sibling_path_array; + std::array sibling_path_array; // Chop the first NULLIFIER-SUBTREE-DEPTH levels from the sibling_path - sibling_path.erase(sibling_path.begin(), sibling_path.begin() + NULLIFIER_SUBTREE_DEPTH); + sibling_path.erase(sibling_path.begin(), sibling_path.begin() + NULLIFIER_SUBTREE_HEIGHT); std::copy(sibling_path.begin(), sibling_path.end(), sibling_path_array.begin()); // Update our start state diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp index eff8c73caaf4..14fcd2461e5b 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp @@ -71,7 +71,7 @@ abis::AppendOnlyTreeSnapshot get_snapshot_of_tree_state(NullifierMemoryTreeT nullifier_tree_testing_values generate_nullifier_tree_testing_values_explicit( BaseRollupInputs inputs, - std::array new_nullifiers, + std::array new_nullifiers, const std::vector& initial_values); nullifier_tree_testing_values generate_nullifier_tree_testing_values(BaseRollupInputs inputs, @@ -81,7 +81,7 @@ nullifier_tree_testing_values generate_nullifier_tree_testing_values(BaseRollupI std::array get_empty_l1_to_l2_messages(); nullifier_tree_testing_values generate_nullifier_tree_testing_values( - BaseRollupInputs inputs, std::array new_nullifiers, size_t spacing); + BaseRollupInputs inputs, std::array new_nullifiers, size_t spacing); NullifierMemoryTreeTestingHarness get_initial_nullifier_tree(const std::vector& initial_values); diff --git a/circuits/cpp/src/aztec3/constants.hpp b/circuits/cpp/src/aztec3/constants.hpp index 2153ba84a7b5..113fc12d480d 100644 --- a/circuits/cpp/src/aztec3/constants.hpp +++ b/circuits/cpp/src/aztec3/constants.hpp @@ -14,76 +14,87 @@ constexpr size_t log2(size_t input) return (input < 2) ? 0 : 1 + log2(input / 2); } - // Note: must be kept in sync with ts/structs/constants.ts constexpr size_t ARGS_LENGTH = 16; constexpr size_t RETURN_VALUES_LENGTH = 4; - constexpr size_t READ_REQUESTS_LENGTH = 4; - /** - * Note: The number of commitments that 1 function call can output is: NEW_COMMITMENTS_LENGTH = 4. The number of - * nullifiers that 1 function call can output is: NEW_NULLIFIERS_LENGTH = 4. This is different from - * KERNEL_NEW_COMMITMENTS_LENGTH and KERNEL_NEW_NULLIFIERS_LENGTH because, in the kernel circuits, we accumulate the - * commitments and the nullifiers from all functions calls in a transaction. Therefore, we always must have: + * Convention for constant array lengths are mainly divided in 2 classes: + * - FUNCTION CALL + * - TRANSACTION * - * KERNEL_NEW_COMMITMENTS_LENGTH ≥ NEW_COMMITMENTS_LENGTH - * KERNEL_NEW_NULLIFIERS_LENGTH ≥ NEW_NULLIFIERS_LENGTH + * Agreed convention is to use MAX_XXX_PER_CALL resp. MAX_XXX_PER_TX, where XXX denotes a type of element such as + * commitment, or nullifier, e.g.,: + * - MAX_NEW_NULLIFIERS_PER_CALL + * - MAX_NEW_COMMITMENTS_PER_TX + * + * In the kernel circuits, we accumulate elements such as commitments and the nullifiers from all functions calls in a + * transaction. Therefore, we always must have: + * MAX_XXX_PER_TX ≥ MAX_XXX_PER_CALL + * + * For instance: + * MAX_NEW_COMMITMENTS_PER_TX ≥ MAX_NEW_COMMITMENTS_PER_CALL + * MAX_NEW_NULLIFIERS_PER_TX ≥ MAX_NEW_NULLIFIERS_PER_CALL * */ -// TODO(962): Rename this to `COMMITMENTS_PER_KERNEL` and make it consistent across the codebase. -constexpr size_t NEW_COMMITMENTS_LENGTH = 4; -constexpr size_t NEW_NULLIFIERS_LENGTH = 4; - -constexpr size_t PRIVATE_CALL_STACK_LENGTH = 4; -constexpr size_t PUBLIC_CALL_STACK_LENGTH = 4; -constexpr size_t NEW_L2_TO_L1_MSGS_LENGTH = 2; - -constexpr size_t KERNEL_NEW_COMMITMENTS_LENGTH = PRIVATE_CALL_STACK_LENGTH * NEW_COMMITMENTS_LENGTH; -constexpr size_t KERNEL_NEW_NULLIFIERS_LENGTH = PRIVATE_CALL_STACK_LENGTH * NEW_NULLIFIERS_LENGTH; -constexpr size_t KERNEL_NEW_CONTRACTS_LENGTH = 1; -constexpr size_t KERNEL_PRIVATE_CALL_STACK_LENGTH = 8; -constexpr size_t KERNEL_PUBLIC_CALL_STACK_LENGTH = 8; -constexpr size_t KERNEL_NEW_L2_TO_L1_MSGS_LENGTH = 2; -constexpr size_t KERNEL_OPTIONALLY_REVEALED_DATA_LENGTH = 4; -constexpr size_t KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH = 4; -constexpr size_t KERNEL_PUBLIC_DATA_READS_LENGTH = 4; -constexpr size_t KERNEL_NUM_ENCRYPTED_LOGS_HASHES = 1; -constexpr size_t KERNEL_NUM_UNENCRYPTED_LOGS_HASHES = 1; +// "PER CALL" CONSTANTS +constexpr size_t MAX_NEW_COMMITMENTS_PER_CALL = 4; +constexpr size_t MAX_NEW_NULLIFIERS_PER_CALL = 4; +constexpr size_t MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL = 4; +constexpr size_t MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL = 4; +constexpr size_t MAX_NEW_L2_TO_L1_MSGS_PER_CALL = 2; +constexpr size_t MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL = 4; +constexpr size_t MAX_PUBLIC_DATA_READS_PER_CALL = 4; + +// "PER TRANSACTION" CONSTANTS +constexpr size_t MAX_NEW_COMMITMENTS_PER_TX = MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL * MAX_NEW_COMMITMENTS_PER_CALL; +constexpr size_t MAX_NEW_NULLIFIERS_PER_TX = MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL * MAX_NEW_NULLIFIERS_PER_CALL; +constexpr size_t MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX = 8; +constexpr size_t MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX = 8; +constexpr size_t MAX_NEW_L2_TO_L1_MSGS_PER_TX = 2; +constexpr size_t MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX = 4; +constexpr size_t MAX_PUBLIC_DATA_READS_PER_TX = 4; +constexpr size_t MAX_NEW_CONTRACTS_PER_TX = 1; +constexpr size_t MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX = 4; +constexpr size_t NUM_ENCRYPTED_LOGS_HASHES_PER_TX = 1; +constexpr size_t NUM_UNENCRYPTED_LOGS_HASHES_PER_TX = 1; + +// ROLLUP CONSTANTS +constexpr size_t NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16; +// TODO(961): Use this constant everywhere instead of hard-coded "2". +constexpr size_t KERNELS_PER_ROLLUP = 2; + + +// TREES RELATED CONSTANTS constexpr size_t VK_TREE_HEIGHT = 3; constexpr size_t FUNCTION_TREE_HEIGHT = 4; constexpr size_t CONTRACT_TREE_HEIGHT = 8; constexpr size_t PRIVATE_DATA_TREE_HEIGHT = 16; -constexpr size_t NULLIFIER_TREE_HEIGHT = 16; constexpr size_t PUBLIC_DATA_TREE_HEIGHT = 254; +constexpr size_t NULLIFIER_TREE_HEIGHT = 16; constexpr size_t L1_TO_L2_MSG_TREE_HEIGHT = 8; - -constexpr size_t CONTRACT_SUBTREE_DEPTH = 1; -constexpr size_t CONTRACT_SUBTREE_INCLUSION_CHECK_DEPTH = CONTRACT_TREE_HEIGHT - CONTRACT_SUBTREE_DEPTH; - -// TODO(961): Use this constant everywhere instead of hard-coded "2". -constexpr size_t KERNELS_PER_ROLLUP = 2; -constexpr size_t PRIVATE_DATA_SUBTREE_DEPTH = - static_cast(log2(KERNELS_PER_ROLLUP * KERNEL_NEW_COMMITMENTS_LENGTH)); -constexpr size_t PRIVATE_DATA_SUBTREE_INCLUSION_CHECK_DEPTH = PRIVATE_DATA_TREE_HEIGHT - PRIVATE_DATA_SUBTREE_DEPTH; - -constexpr size_t NULLIFIER_SUBTREE_DEPTH = static_cast(log2(KERNELS_PER_ROLLUP * KERNEL_NEW_NULLIFIERS_LENGTH)); -constexpr size_t NULLIFIER_SUBTREE_INCLUSION_CHECK_DEPTH = NULLIFIER_TREE_HEIGHT - NULLIFIER_SUBTREE_DEPTH; - -// NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP must equal 2^L1_TO_L2_MSG_SUBTREE_DEPTH for subtree insertions. -constexpr size_t L1_TO_L2_MSG_SUBTREE_DEPTH = 4; -constexpr size_t NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16; -constexpr size_t L1_TO_L2_MSG_SUBTREE_INCLUSION_CHECK_DEPTH = L1_TO_L2_MSG_TREE_HEIGHT - L1_TO_L2_MSG_SUBTREE_DEPTH; - constexpr size_t PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT = 8; constexpr size_t CONTRACT_TREE_ROOTS_TREE_HEIGHT = 8; constexpr size_t L1_TO_L2_MSG_TREE_ROOTS_TREE_HEIGHT = 8; constexpr size_t ROLLUP_VK_TREE_HEIGHT = 8; // TODO: update -constexpr size_t FUNCTION_SELECTOR_NUM_BYTES = 4; // must be <= 31 +// SUB-TREES RELATED CONSTANTS +constexpr size_t CONTRACT_SUBTREE_HEIGHT = 1; +constexpr size_t CONTRACT_SUBTREE_SIBLING_PATH_LENGTH = CONTRACT_TREE_HEIGHT - CONTRACT_SUBTREE_HEIGHT; +constexpr size_t PRIVATE_DATA_SUBTREE_HEIGHT = + static_cast(log2(KERNELS_PER_ROLLUP * MAX_NEW_COMMITMENTS_PER_TX)); +constexpr size_t PRIVATE_DATA_SUBTREE_SIBLING_PATH_LENGTH = PRIVATE_DATA_TREE_HEIGHT - PRIVATE_DATA_SUBTREE_HEIGHT; +constexpr size_t NULLIFIER_SUBTREE_HEIGHT = static_cast(log2(KERNELS_PER_ROLLUP * MAX_NEW_NULLIFIERS_PER_TX)); +constexpr size_t NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH = NULLIFIER_TREE_HEIGHT - NULLIFIER_SUBTREE_HEIGHT; +constexpr size_t L1_TO_L2_MSG_SUBTREE_HEIGHT = static_cast(log2(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP)); +constexpr size_t L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH = L1_TO_L2_MSG_TREE_HEIGHT - L1_TO_L2_MSG_SUBTREE_HEIGHT; + + +// MISC CONSTANTS +constexpr size_t FUNCTION_SELECTOR_NUM_BYTES = 4; // must be <= 31 // sha256 hash is stored in two fields to accommodate all 256-bits of the hash constexpr size_t NUM_FIELDS_PER_SHA256 = 2; diff --git a/circuits/cpp/src/aztec3/utils/circuit_errors.hpp b/circuits/cpp/src/aztec3/utils/circuit_errors.hpp index 6c7947dc9668..b9788442332f 100644 --- a/circuits/cpp/src/aztec3/utils/circuit_errors.hpp +++ b/circuits/cpp/src/aztec3/utils/circuit_errors.hpp @@ -20,7 +20,7 @@ enum CircuitErrorCode : uint16_t { PRIVATE_KERNEL__CALCULATED_PRIVATE_CALL_HASH_AND_PROVIDED_PRIVATE_CALL_HASH_MISMATCH = 2007, PRIVATE_KERNEL__PRIVATE_CALL_STACK_ITEM_HASH_MISMATCH = 2008, PRIVATE_KERNEL__NON_PRIVATE_FUNCTION_EXECUTED_WITH_PRIVATE_KERNEL = 2009, - PRIVATE_KERNEL__PRIVATE_CALL_STACK_LENGTH_MISMATCH = 2010, + PRIVATE_KERNEL__MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL_MISMATCH = 2010, PRIVATE_KERNEL__UNSUPPORTED_OP = 2011, PRIVATE_KERNEL__CONTRACT_ADDRESS_MISMATCH = 2012, PRIVATE_KERNEL__NON_PRIVATE_KERNEL_VERIFIED_WITH_PRIVATE_KERNEL = 2013, diff --git a/yarn-project/acir-simulator/src/acvm/deserialize.ts b/yarn-project/acir-simulator/src/acvm/deserialize.ts index 09660529f9ea..36b38e4eabc0 100644 --- a/yarn-project/acir-simulator/src/acvm/deserialize.ts +++ b/yarn-project/acir-simulator/src/acvm/deserialize.ts @@ -1,12 +1,12 @@ import { CallContext, ContractDeploymentData, - NEW_COMMITMENTS_LENGTH, - NEW_L2_TO_L1_MSGS_LENGTH, - NEW_NULLIFIERS_LENGTH, + MAX_NEW_COMMITMENTS_PER_CALL, + MAX_NEW_L2_TO_L1_MSGS_PER_CALL, + MAX_NEW_NULLIFIERS_PER_CALL, NUM_FIELDS_PER_SHA256, - PRIVATE_CALL_STACK_LENGTH, - PUBLIC_CALL_STACK_LENGTH, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, PrivateCircuitPublicInputs, READ_REQUESTS_LENGTH, RETURN_VALUES_LENGTH, @@ -124,11 +124,11 @@ export function extractPublicInputs(partialWitness: ACVMWitness, acir: Buffer): const argsHash = witnessReader.readField(); const returnValues = witnessReader.readFieldArray(RETURN_VALUES_LENGTH); const readRequests = witnessReader.readFieldArray(READ_REQUESTS_LENGTH); - const newCommitments = witnessReader.readFieldArray(NEW_COMMITMENTS_LENGTH); - const newNullifiers = witnessReader.readFieldArray(NEW_NULLIFIERS_LENGTH); - const privateCallStack = witnessReader.readFieldArray(PRIVATE_CALL_STACK_LENGTH); - const publicCallStack = witnessReader.readFieldArray(PUBLIC_CALL_STACK_LENGTH); - const newL2ToL1Msgs = witnessReader.readFieldArray(NEW_L2_TO_L1_MSGS_LENGTH); + const newCommitments = witnessReader.readFieldArray(MAX_NEW_COMMITMENTS_PER_CALL); + const newNullifiers = witnessReader.readFieldArray(MAX_NEW_NULLIFIERS_PER_CALL); + const privateCallStack = witnessReader.readFieldArray(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL); + const publicCallStack = witnessReader.readFieldArray(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL); + const newL2ToL1Msgs = witnessReader.readFieldArray(MAX_NEW_L2_TO_L1_MSGS_PER_CALL); const encryptedLogsHash = witnessReader.readFieldArray(NUM_FIELDS_PER_SHA256); const unencryptedLogsHash = witnessReader.readFieldArray(NUM_FIELDS_PER_SHA256); diff --git a/yarn-project/acir-simulator/src/client/private_execution.test.ts b/yarn-project/acir-simulator/src/client/private_execution.test.ts index 2a811e5f594d..463ca599100e 100644 --- a/yarn-project/acir-simulator/src/client/private_execution.test.ts +++ b/yarn-project/acir-simulator/src/client/private_execution.test.ts @@ -3,8 +3,8 @@ import { CircuitsWasm, ContractDeploymentData, FunctionData, - L1_TO_L2_MESSAGES_TREE_HEIGHT, - NEW_COMMITMENTS_LENGTH, + L1_TO_L2_MSG_TREE_HEIGHT, + MAX_NEW_COMMITMENTS_PER_CALL, PRIVATE_DATA_TREE_HEIGHT, PrivateHistoricTreeRoots, PublicCallRequest, @@ -47,7 +47,7 @@ describe('Private Execution test suite', () => { const treeHeights: { [name: string]: number } = { privateData: PRIVATE_DATA_TREE_HEIGHT, - l1ToL2Messages: L1_TO_L2_MESSAGES_TREE_HEIGHT, + l1ToL2Messages: L1_TO_L2_MSG_TREE_HEIGHT, }; const trees: { [name: keyof typeof treeHeights]: AppendOnlyTree } = {}; const txContext = new TxContext(false, false, false, ContractDeploymentData.empty(), new Fr(69), new Fr(420)); @@ -120,7 +120,9 @@ describe('Private Execution test suite', () => { it('should run the empty constructor', async () => { const abi = TestContractAbi.functions[0]; const result = await runSimulator({ abi, isConstructor: true }); - expect(result.callStackItem.publicInputs.newCommitments).toEqual(new Array(NEW_COMMITMENTS_LENGTH).fill(Fr.ZERO)); + expect(result.callStackItem.publicInputs.newCommitments).toEqual( + new Array(MAX_NEW_COMMITMENTS_PER_CALL).fill(Fr.ZERO), + ); }); }); diff --git a/yarn-project/acir-simulator/src/client/private_execution.ts b/yarn-project/acir-simulator/src/client/private_execution.ts index fd0672efcf04..d1016f8f4c60 100644 --- a/yarn-project/acir-simulator/src/client/private_execution.ts +++ b/yarn-project/acir-simulator/src/client/private_execution.ts @@ -3,7 +3,7 @@ import { CircuitsWasm, ContractDeploymentData, FunctionData, - PUBLIC_CALL_STACK_LENGTH, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, PrivateCallStackItem, PublicCallRequest, } from '@aztec/circuits.js'; @@ -192,7 +192,11 @@ export class PrivateFunctionExecution { // TODO(#499): Noir fails to compute the enqueued calls preimages properly, since it cannot use pedersen generators, so we patch those values here. const publicCallStackItems = await Promise.all(enqueuedPublicFunctionCalls.map(c => c.toPublicCallStackItem())); const publicStack = await Promise.all(publicCallStackItems.map(c => computeCallStackItemHash(wasm, c))); - callStackItem.publicInputs.publicCallStack = padArrayEnd(publicStack, Fr.ZERO, PUBLIC_CALL_STACK_LENGTH); + callStackItem.publicInputs.publicCallStack = padArrayEnd( + publicStack, + Fr.ZERO, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, + ); // TODO: This should be set manually by the circuit publicInputs.contractDeploymentData.deployerPublicKey = diff --git a/yarn-project/acir-simulator/src/public/index.test.ts b/yarn-project/acir-simulator/src/public/index.test.ts index e63f4b0e8dec..0182d9993408 100644 --- a/yarn-project/acir-simulator/src/public/index.test.ts +++ b/yarn-project/acir-simulator/src/public/index.test.ts @@ -4,7 +4,7 @@ import { FunctionData, CircuitsWasm, PrivateHistoricTreeRoots, - L1_TO_L2_MESSAGES_TREE_HEIGHT, + L1_TO_L2_MSG_TREE_HEIGHT, GlobalVariables, } from '@aztec/circuits.js'; import { AztecAddress } from '@aztec/foundation/aztec-address'; @@ -364,7 +364,7 @@ describe('ACIR public execution simulator', () => { return await Promise.resolve({ message: preimage.toFieldArray(), index: 0n, - siblingPath: Array(L1_TO_L2_MESSAGES_TREE_HEIGHT).fill(Fr.random()), + siblingPath: Array(L1_TO_L2_MSG_TREE_HEIGHT).fill(Fr.random()), }); }); diff --git a/yarn-project/aztec-cli/tsconfig.json b/yarn-project/aztec-cli/tsconfig.json index acaee34074f4..dd0ea8ffb33d 100644 --- a/yarn-project/aztec-cli/tsconfig.json +++ b/yarn-project/aztec-cli/tsconfig.json @@ -18,4 +18,4 @@ ], "include": ["src"], "exclude": ["contracts"] -} \ No newline at end of file +} diff --git a/yarn-project/aztec-node/src/aztec-node/aztec-node.ts b/yarn-project/aztec-node/src/aztec-node/aztec-node.ts index 31141be438d6..6f3c818414f0 100644 --- a/yarn-project/aztec-node/src/aztec-node/aztec-node.ts +++ b/yarn-project/aztec-node/src/aztec-node/aztec-node.ts @@ -1,4 +1,4 @@ -import { CONTRACT_TREE_HEIGHT, L1_TO_L2_MESSAGES_TREE_HEIGHT, PRIVATE_DATA_TREE_HEIGHT } from '@aztec/circuits.js'; +import { CONTRACT_TREE_HEIGHT, L1_TO_L2_MSG_TREE_HEIGHT, PRIVATE_DATA_TREE_HEIGHT } from '@aztec/circuits.js'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { ContractPublicData, @@ -141,7 +141,7 @@ export interface AztecNode { * @param leafIndex - Index of the leaf in the tree. * @returns The sibling path. */ - getL1ToL2MessagesTreePath(leafIndex: bigint): Promise>; + getL1ToL2MessagesTreePath(leafIndex: bigint): Promise>; /** * Gets the storage value at the given contract slot. Our version of eth_getStorageAt. diff --git a/yarn-project/aztec-node/src/aztec-node/http-node.ts b/yarn-project/aztec-node/src/aztec-node/http-node.ts index cf362ca41a04..dd7202691fa9 100644 --- a/yarn-project/aztec-node/src/aztec-node/http-node.ts +++ b/yarn-project/aztec-node/src/aztec-node/http-node.ts @@ -4,7 +4,7 @@ import { CONTRACT_TREE_HEIGHT, Fr, KernelCircuitPublicInputs, - L1_TO_L2_MESSAGES_TREE_HEIGHT, + L1_TO_L2_MSG_TREE_HEIGHT, PRIVATE_DATA_TREE_HEIGHT, Proof, PublicCallRequest, @@ -313,7 +313,7 @@ export class HttpNode implements AztecNode { * @param leafIndex - Index of the leaf in the tree. * @returns The sibling path. */ - async getL1ToL2MessagesTreePath(leafIndex: bigint): Promise> { + async getL1ToL2MessagesTreePath(leafIndex: bigint): Promise> { const url = new URL(`${this.baseUrl}/l1-l2-path`); url.searchParams.append('leaf', leafIndex.toString()); const response = await (await fetch(url.toString())).json(); diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index d172a4d55215..55a8dd1c7753 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -3,7 +3,7 @@ import { CONTRACT_TREE_HEIGHT, CircuitsWasm, Fr, - L1_TO_L2_MESSAGES_TREE_HEIGHT, + L1_TO_L2_MSG_TREE_HEIGHT, PRIVATE_DATA_TREE_HEIGHT, } from '@aztec/circuits.js'; import { AztecAddress } from '@aztec/foundation/aztec-address'; @@ -283,7 +283,7 @@ export class AztecNodeService implements AztecNode { * @param leafIndex - Index of the leaf in the tree. * @returns The sibling path. */ - public getL1ToL2MessagesTreePath(leafIndex: bigint): Promise> { + public getL1ToL2MessagesTreePath(leafIndex: bigint): Promise> { return this.merkleTreeDB.getSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGES_TREE, leafIndex, false); } diff --git a/yarn-project/aztec-rpc/src/account_state/account_state.test.ts b/yarn-project/aztec-rpc/src/account_state/account_state.test.ts index beab72a07d16..3a4879f5cf82 100644 --- a/yarn-project/aztec-rpc/src/account_state/account_state.test.ts +++ b/yarn-project/aztec-rpc/src/account_state/account_state.test.ts @@ -1,6 +1,6 @@ import { AztecNode } from '@aztec/aztec-node'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; -import { AztecAddress, CircuitsWasm, KERNEL_NEW_COMMITMENTS_LENGTH } from '@aztec/circuits.js'; +import { AztecAddress, CircuitsWasm, MAX_NEW_COMMITMENTS_PER_TX } from '@aztec/circuits.js'; import { Fr, Point } from '@aztec/foundation/fields'; import { ConstantKeyPair, KeyPair, KeyStore } from '@aztec/key-store'; import { FunctionL2Logs, L2Block, L2BlockContext, L2BlockL2Logs, NoteSpendingInfo, TxL2Logs } from '@aztec/types'; @@ -22,14 +22,14 @@ describe('Account State', () => { const createEncryptedLogsAndOwnedNoteSpendingInfo = (ownedDataIndices: number[] = []) => { ownedDataIndices.forEach(index => { - if (index >= KERNEL_NEW_COMMITMENTS_LENGTH) { - throw new Error(`Data index should be less than ${KERNEL_NEW_COMMITMENTS_LENGTH}.`); + if (index >= MAX_NEW_COMMITMENTS_PER_TX) { + throw new Error(`Data index should be less than ${MAX_NEW_COMMITMENTS_PER_TX}.`); } }); const txLogs: TxL2Logs[] = []; const ownedNoteSpendingInfo: NoteSpendingInfo[] = []; - for (let i = 0; i < KERNEL_NEW_COMMITMENTS_LENGTH; ++i) { + for (let i = 0; i < MAX_NEW_COMMITMENTS_PER_TX; ++i) { const noteSpendingInfo = NoteSpendingInfo.random(); const isOwner = ownedDataIndices.includes(i); const publicKey = isOwner ? owner.getPublicKey() : Point.random(); @@ -140,15 +140,15 @@ describe('Account State', () => { expect(addNoteSpendingInfoBatchSpy).toHaveBeenCalledWith([ expect.objectContaining({ ...ownedNoteSpendingInfos[0], - index: BigInt(KERNEL_NEW_COMMITMENTS_LENGTH + 1), + index: BigInt(MAX_NEW_COMMITMENTS_PER_TX + 1), }), expect.objectContaining({ ...ownedNoteSpendingInfos[1], - index: BigInt(KERNEL_NEW_COMMITMENTS_LENGTH * 4), + index: BigInt(MAX_NEW_COMMITMENTS_PER_TX * 4), }), expect.objectContaining({ ...ownedNoteSpendingInfos[2], - index: BigInt(KERNEL_NEW_COMMITMENTS_LENGTH * 4 + 2), + index: BigInt(MAX_NEW_COMMITMENTS_PER_TX * 4 + 2), }), ]); }); diff --git a/yarn-project/aztec-rpc/src/account_state/account_state.ts b/yarn-project/aztec-rpc/src/account_state/account_state.ts index bc3e90c6b99c..1e68e55a4d30 100644 --- a/yarn-project/aztec-rpc/src/account_state/account_state.ts +++ b/yarn-project/aztec-rpc/src/account_state/account_state.ts @@ -1,6 +1,6 @@ import { AcirSimulator, collectEncryptedLogs, collectEnqueuedPublicFunctionCalls } from '@aztec/acir-simulator'; import { AztecNode } from '@aztec/aztec-node'; -import { CircuitsWasm, KERNEL_NEW_COMMITMENTS_LENGTH, PrivateHistoricTreeRoots } from '@aztec/circuits.js'; +import { CircuitsWasm, MAX_NEW_COMMITMENTS_PER_TX, PrivateHistoricTreeRoots } from '@aztec/circuits.js'; import { ContractAbi, FunctionType } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; @@ -326,7 +326,7 @@ export class AccountState { // TODO(Maddiaa): this calculation is brittle. // https://github.com/AztecProtocol/aztec-packages/issues/788 let dataStartIndex = - (l2BlockContexts[0].block.number - INITIAL_L2_BLOCK_NUM) * this.TXS_PER_BLOCK * KERNEL_NEW_COMMITMENTS_LENGTH; + (l2BlockContexts[0].block.number - INITIAL_L2_BLOCK_NUM) * this.TXS_PER_BLOCK * MAX_NEW_COMMITMENTS_PER_TX; const blocksAndNoteSpendingInfo: ProcessedData[] = []; // Iterate over both blocks and encrypted logs. diff --git a/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.test.ts b/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.test.ts index 2e8d4b5bd8f8..8e9def4a21b1 100644 --- a/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.test.ts +++ b/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.test.ts @@ -1,9 +1,9 @@ import { ExecutionResult, NewNoteData } from '@aztec/acir-simulator'; import { - KERNEL_NEW_COMMITMENTS_LENGTH, + MAX_NEW_COMMITMENTS_PER_TX, KernelCircuitPublicInputs, MembershipWitness, - PRIVATE_CALL_STACK_LENGTH, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, PrivateCallStackItem, PrivateCircuitPublicInputs, READ_REQUESTS_LENGTH, @@ -64,7 +64,7 @@ describe('Kernel Prover', () => { const publicInputs = KernelCircuitPublicInputs.empty(); const commitments = newNoteIndices.map(idx => generateFakeSiloedCommitment(notes[idx])); // TODO(AD) FIXME(AD) This cast is bad. Why is this not the correct length when this is called? - publicInputs.end.newCommitments = commitments as Tuple; + publicInputs.end.newCommitments = commitments as Tuple; return { publicInputs, proof: makeEmptyProof(), @@ -141,7 +141,7 @@ describe('Kernel Prover', () => { }); it('should throw if call stack is too deep', async () => { - dependencies.a = Array(PRIVATE_CALL_STACK_LENGTH + 1) + dependencies.a = Array(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + 1) .fill(0) .map((_, i) => `${i}`); const executionResult = createExecutionResult('a'); diff --git a/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts b/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts index c394fcfadf35..aad942e953b4 100644 --- a/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts @@ -5,7 +5,7 @@ import { Fr, KernelCircuitPublicInputs, MembershipWitness, - PRIVATE_CALL_STACK_LENGTH, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, PRIVATE_DATA_TREE_HEIGHT, PreviousKernelData, PrivateCallData, @@ -85,14 +85,14 @@ export class KernelProver { const currentExecution = executionStack.pop()!; executionStack.push(...currentExecution.nestedExecutions); const privateCallStackPreimages = currentExecution.nestedExecutions.map(result => result.callStackItem); - if (privateCallStackPreimages.length > PRIVATE_CALL_STACK_LENGTH) { + if (privateCallStackPreimages.length > MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL) { throw new Error( - `Too many items in the call stack. Maximum amount is ${PRIVATE_CALL_STACK_LENGTH}. Got ${privateCallStackPreimages.length}.`, + `Too many items in the call stack. Maximum amount is ${MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL}. Got ${privateCallStackPreimages.length}.`, ); } // Pad with empty items to reach max/const length expected by circuit. privateCallStackPreimages.push( - ...Array(PRIVATE_CALL_STACK_LENGTH - privateCallStackPreimages.length) + ...Array(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL - privateCallStackPreimages.length) .fill(0) .map(() => PrivateCallStackItem.empty()), ); diff --git a/yarn-project/circuits.js/src/kernel/public_kernel.test.ts b/yarn-project/circuits.js/src/kernel/public_kernel.test.ts index 6b553a976162..e8ffc4487457 100644 --- a/yarn-project/circuits.js/src/kernel/public_kernel.test.ts +++ b/yarn-project/circuits.js/src/kernel/public_kernel.test.ts @@ -1,4 +1,4 @@ -import { CircuitError, KERNEL_PUBLIC_DATA_READS_LENGTH, makeTuple, simulatePublicKernelCircuit } from '../index.js'; +import { CircuitError, MAX_PUBLIC_DATA_READS_PER_TX, makeTuple, simulatePublicKernelCircuit } from '../index.js'; import { makePublicDataRead, makePublicKernelInputsWithEmptyOutput } from '../tests/factories.js'; describe('kernel/public_kernel', () => { @@ -27,7 +27,7 @@ describe('kernel/public_kernel', () => { input.previousKernel.publicInputs.isPrivate = false; // Cause array overflow - const fullStateReadsObject = makeTuple(KERNEL_PUBLIC_DATA_READS_LENGTH, makePublicDataRead, 0x01); + const fullStateReadsObject = makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, makePublicDataRead, 0x01); input.previousKernel.publicInputs.end.publicDataReads = fullStateReadsObject; await expect(simulatePublicKernelCircuit(input)).rejects.toThrow( diff --git a/yarn-project/circuits.js/src/structs/constants.ts b/yarn-project/circuits.js/src/structs/constants.ts index 5c3a7abce4fc..34fb6c6d677b 100644 --- a/yarn-project/circuits.js/src/structs/constants.ts +++ b/yarn-project/circuits.js/src/structs/constants.ts @@ -3,45 +3,50 @@ // In future: structured serialization? export const ARGS_LENGTH = 16; // MAX_ARGS in Noir export const RETURN_VALUES_LENGTH = 4; - export const READ_REQUESTS_LENGTH = 4; -export const NEW_COMMITMENTS_LENGTH = 4; -export const NEW_NULLIFIERS_LENGTH = 4; -export const NEW_L2_TO_L1_MSGS_LENGTH = 2; - -export const PRIVATE_CALL_STACK_LENGTH = 4; -export const PUBLIC_CALL_STACK_LENGTH = 4; - -export const KERNEL_NEW_COMMITMENTS_LENGTH = 16; // PRIVATE_CALL_STACK_LENGTH * NEW_COMMITMENTS_LENGTH -export const KERNEL_NEW_NULLIFIERS_LENGTH = 16; // PRIVATE_CALL_STACK_LENGTH * NEW_NULLIFIERS_LENGTH -export const KERNEL_NEW_CONTRACTS_LENGTH = 1; -export const KERNEL_PRIVATE_CALL_STACK_LENGTH = 8; -export const KERNEL_PUBLIC_CALL_STACK_LENGTH = 8; -export const KERNEL_NEW_L2_TO_L1_MSGS_LENGTH = 2; -export const KERNEL_OPTIONALLY_REVEALED_DATA_LENGTH = 4; -export const KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH = 4; -export const KERNEL_PUBLIC_DATA_READS_LENGTH = 4; +// "PER CALL" CONSTANTS +export const MAX_NEW_COMMITMENTS_PER_CALL = 4; +export const MAX_NEW_NULLIFIERS_PER_CALL = 4; +export const MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL = 4; +export const MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL = 4; +export const MAX_NEW_L2_TO_L1_MSGS_PER_CALL = 2; +export const MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL = 4; +export const MAX_PUBLIC_DATA_READS_PER_CALL = 4; + +// "PER TRANSACTION" CONSTANTS +export const MAX_NEW_COMMITMENTS_PER_TX = 16; // MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL * MAX_NEW_COMMITMENTS_PER_CALL +export const MAX_NEW_NULLIFIERS_PER_TX = 16; // MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL * MAX_NEW_NULLIFIERS_PER_CALL +export const MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX = 8; +export const MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX = 8; +export const MAX_NEW_L2_TO_L1_MSGS_PER_TX = 2; +export const MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX = 4; +export const MAX_PUBLIC_DATA_READS_PER_TX = 4; +export const MAX_NEW_CONTRACTS_PER_TX = 1; +export const MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX = 4; + +// ROLLUP CONSTANTS +export const NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16; +// TREES RELATED CONSTANTS export const VK_TREE_HEIGHT = 3; export const FUNCTION_TREE_HEIGHT = 4; export const CONTRACT_TREE_HEIGHT = 8; export const PRIVATE_DATA_TREE_HEIGHT = 16; export const PUBLIC_DATA_TREE_HEIGHT = 254; export const NULLIFIER_TREE_HEIGHT = 16; -export const NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16; -export const L1_TO_L2_MESSAGES_TREE_HEIGHT = 8; -export const L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT = 8; -export const L1_TO_L2_MESSAGES_SUBTREE_HEIGHT = Math.ceil(Math.log2(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP)); -export const L1_TO_L2_MESSAGES_SIBLING_PATH_LENGTH = L1_TO_L2_MESSAGES_TREE_HEIGHT - L1_TO_L2_MESSAGES_SUBTREE_HEIGHT; - +export const L1_TO_L2_MSG_TREE_HEIGHT = 8; export const PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT = 8; export const CONTRACT_TREE_ROOTS_TREE_HEIGHT = 8; +export const L1_TO_L2_MSG_ROOTS_TREE_HEIGHT = 8; export const ROLLUP_VK_TREE_HEIGHT = 8; -export const FUNCTION_SELECTOR_NUM_BYTES = 4; +// SUB-TREES RELATED CONSTANTS +export const L1_TO_L2_MSG_SUBTREE_HEIGHT = Math.ceil(Math.log2(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP)); +export const L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH = L1_TO_L2_MSG_TREE_HEIGHT - L1_TO_L2_MSG_SUBTREE_HEIGHT; +// MISC CONSTANTS +export const FUNCTION_SELECTOR_NUM_BYTES = 4; export const MAPPING_SLOT_PEDERSEN_SEPARATOR = 4; - // sha256 hash is stored in two fields to accommodate all 256-bits of the hash export const NUM_FIELDS_PER_SHA256 = 2; diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts index 846a41f42be4..1effffde3fea 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts @@ -1,16 +1,16 @@ import { serializeToBuffer } from '../../utils/serialize.js'; import { AggregationObject } from '../aggregation_object.js'; import { - KERNEL_NEW_L2_TO_L1_MSGS_LENGTH, - KERNEL_NEW_COMMITMENTS_LENGTH, - KERNEL_NEW_CONTRACTS_LENGTH, - KERNEL_NEW_NULLIFIERS_LENGTH, - KERNEL_OPTIONALLY_REVEALED_DATA_LENGTH, - KERNEL_PRIVATE_CALL_STACK_LENGTH, - KERNEL_PUBLIC_CALL_STACK_LENGTH, - KERNEL_PUBLIC_DATA_READS_LENGTH, - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, - NEW_L2_TO_L1_MSGS_LENGTH, + MAX_NEW_L2_TO_L1_MSGS_PER_TX, + MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_CONTRACTS_PER_TX, + MAX_NEW_NULLIFIERS_PER_TX, + MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, + MAX_PUBLIC_DATA_READS_PER_TX, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, + MAX_NEW_L2_TO_L1_MSGS_PER_CALL, NUM_FIELDS_PER_SHA256, } from '../constants.js'; import { FunctionData } from '../function_data.js'; @@ -278,23 +278,23 @@ export class CombinedAccumulatedData { /** * The number of new commitments made in this transaction. */ - public newCommitments: Tuple, + public newCommitments: Tuple, /** * The number of new nullifiers made in this transaction. */ - public newNullifiers: Tuple, + public newNullifiers: Tuple, /** * Current private call stack. */ - public privateCallStack: Tuple, + public privateCallStack: Tuple, /** * Current public call stack. */ - public publicCallStack: Tuple, + public publicCallStack: Tuple, /** * All the new L2 to L1 messages created in this transaction. */ - public newL2ToL1Msgs: Tuple, + public newL2ToL1Msgs: Tuple, /** * Accumulated encrypted logs hash from all the previous kernel iterations. * Note: Represented as a tuple of 2 fields in order to fit in all of the 256 bits of sha256 hash. @@ -316,31 +316,31 @@ export class CombinedAccumulatedData { /** * All the new contracts deployed in this transaction. */ - public newContracts: Tuple, + public newContracts: Tuple, /** * All the optionally revealed data in this transaction. */ - public optionallyRevealedData: Tuple, + public optionallyRevealedData: Tuple, /** * All the public data update requests made in this transaction. */ - public publicDataUpdateRequests: Tuple, + public publicDataUpdateRequests: Tuple, /** * All the public data reads made in this transaction. */ - public publicDataReads: Tuple, + public publicDataReads: Tuple, ) { - assertMemberLength(this, 'newCommitments', KERNEL_NEW_COMMITMENTS_LENGTH); - assertMemberLength(this, 'newNullifiers', KERNEL_NEW_NULLIFIERS_LENGTH); - assertMemberLength(this, 'privateCallStack', KERNEL_PRIVATE_CALL_STACK_LENGTH); - assertMemberLength(this, 'publicCallStack', KERNEL_PUBLIC_CALL_STACK_LENGTH); - assertMemberLength(this, 'newL2ToL1Msgs', KERNEL_NEW_L2_TO_L1_MSGS_LENGTH); + assertMemberLength(this, 'newCommitments', MAX_NEW_COMMITMENTS_PER_TX); + assertMemberLength(this, 'newNullifiers', MAX_NEW_NULLIFIERS_PER_TX); + assertMemberLength(this, 'privateCallStack', MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX); + assertMemberLength(this, 'publicCallStack', MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX); + assertMemberLength(this, 'newL2ToL1Msgs', MAX_NEW_L2_TO_L1_MSGS_PER_TX); assertMemberLength(this, 'encryptedLogsHash', NUM_FIELDS_PER_SHA256); assertMemberLength(this, 'unencryptedLogsHash', NUM_FIELDS_PER_SHA256); - assertMemberLength(this, 'newContracts', KERNEL_NEW_CONTRACTS_LENGTH); - assertMemberLength(this, 'optionallyRevealedData', KERNEL_OPTIONALLY_REVEALED_DATA_LENGTH); - assertMemberLength(this, 'publicDataUpdateRequests', KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH); - assertMemberLength(this, 'publicDataReads', KERNEL_PUBLIC_DATA_READS_LENGTH); + assertMemberLength(this, 'newContracts', MAX_NEW_CONTRACTS_PER_TX); + assertMemberLength(this, 'optionallyRevealedData', MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX); + assertMemberLength(this, 'publicDataUpdateRequests', MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX); + assertMemberLength(this, 'publicDataReads', MAX_PUBLIC_DATA_READS_PER_TX); } toBuffer() { @@ -375,19 +375,19 @@ export class CombinedAccumulatedData { const reader = BufferReader.asReader(buffer); return new CombinedAccumulatedData( reader.readObject(AggregationObject), - reader.readArray(KERNEL_NEW_COMMITMENTS_LENGTH, Fr), - reader.readArray(KERNEL_NEW_NULLIFIERS_LENGTH, Fr), - reader.readArray(KERNEL_PRIVATE_CALL_STACK_LENGTH, Fr), - reader.readArray(KERNEL_PUBLIC_CALL_STACK_LENGTH, Fr), - reader.readArray(KERNEL_NEW_L2_TO_L1_MSGS_LENGTH, Fr), + reader.readArray(MAX_NEW_COMMITMENTS_PER_TX, Fr), + reader.readArray(MAX_NEW_NULLIFIERS_PER_TX, Fr), + reader.readArray(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, Fr), + reader.readArray(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, Fr), + reader.readArray(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr), reader.readArray(2, Fr), reader.readArray(2, Fr), reader.readFr(), reader.readFr(), - reader.readArray(KERNEL_NEW_CONTRACTS_LENGTH, NewContractData), - reader.readArray(KERNEL_OPTIONALLY_REVEALED_DATA_LENGTH, OptionallyRevealedData), - reader.readArray(KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, PublicDataUpdateRequest), - reader.readArray(KERNEL_PUBLIC_DATA_READS_LENGTH, PublicDataRead), + reader.readArray(MAX_NEW_CONTRACTS_PER_TX, NewContractData), + reader.readArray(MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX, OptionallyRevealedData), + reader.readArray(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest), + reader.readArray(MAX_PUBLIC_DATA_READS_PER_TX, PublicDataRead), ); } @@ -403,19 +403,19 @@ export class CombinedAccumulatedData { static empty() { return new CombinedAccumulatedData( AggregationObject.makeFake(), - makeTuple(KERNEL_NEW_COMMITMENTS_LENGTH, Fr.zero), - makeTuple(KERNEL_NEW_NULLIFIERS_LENGTH, Fr.zero), - makeTuple(KERNEL_PRIVATE_CALL_STACK_LENGTH, Fr.zero), - makeTuple(KERNEL_PUBLIC_CALL_STACK_LENGTH, Fr.zero), - makeTuple(KERNEL_NEW_L2_TO_L1_MSGS_LENGTH, Fr.zero), + makeTuple(MAX_NEW_COMMITMENTS_PER_TX, Fr.zero), + makeTuple(MAX_NEW_NULLIFIERS_PER_TX, Fr.zero), + makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, Fr.zero), + makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, Fr.zero), + makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), makeTuple(2, Fr.zero), makeTuple(2, Fr.zero), Fr.zero(), Fr.zero(), - makeTuple(KERNEL_NEW_CONTRACTS_LENGTH, NewContractData.empty), - makeTuple(KERNEL_OPTIONALLY_REVEALED_DATA_LENGTH, OptionallyRevealedData.empty), - makeTuple(KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, PublicDataUpdateRequest.empty), - makeTuple(KERNEL_PUBLIC_DATA_READS_LENGTH, PublicDataRead.empty), + makeTuple(MAX_NEW_CONTRACTS_PER_TX, NewContractData.empty), + makeTuple(MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX, OptionallyRevealedData.empty), + makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.empty), + makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, PublicDataRead.empty), ); } } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel.ts index bf8e947af1b1..3f0e2f61cd26 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel.ts @@ -5,7 +5,7 @@ import { PrivateCallStackItem } from '../call_stack_item.js'; import { CONTRACT_TREE_HEIGHT, FUNCTION_TREE_HEIGHT, - PRIVATE_CALL_STACK_LENGTH, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, PRIVATE_DATA_TREE_HEIGHT, READ_REQUESTS_LENGTH, } from '../constants.js'; @@ -60,7 +60,7 @@ export class PrivateCallData { */ public acirHash: Fr, ) { - assertMemberLength(this, 'privateCallStackPreimages', PRIVATE_CALL_STACK_LENGTH); + assertMemberLength(this, 'privateCallStackPreimages', MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL); assertMemberLength(this, 'readRequestMembershipWitnesses', READ_REQUESTS_LENGTH); } diff --git a/yarn-project/circuits.js/src/structs/kernel/public_kernel.ts b/yarn-project/circuits.js/src/structs/kernel/public_kernel.ts index cb676b7cb9fd..f1ff09d66aef 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_kernel.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_kernel.ts @@ -4,9 +4,9 @@ import { assertMemberLength } from '../../utils/jsUtils.js'; import { serializeToBuffer } from '../../utils/serialize.js'; import { PublicCallStackItem } from '../call_stack_item.js'; import { - KERNEL_PUBLIC_DATA_READS_LENGTH, - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, - PUBLIC_CALL_STACK_LENGTH, + MAX_PUBLIC_DATA_READS_PER_TX, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, PUBLIC_DATA_TREE_HEIGHT, } from '../constants.js'; import { MembershipWitness } from '../membership_witness.js'; @@ -56,8 +56,8 @@ export class WitnessedPublicCallData { */ public readonly publicDataTreeRoot: Fr, ) { - assertMemberLength(this, 'updateRequestsHashPaths', KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH); - assertMemberLength(this, 'readsHashPaths', KERNEL_PUBLIC_DATA_READS_LENGTH); + assertMemberLength(this, 'updateRequestsHashPaths', MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX); + assertMemberLength(this, 'readsHashPaths', MAX_PUBLIC_DATA_READS_PER_TX); } toBuffer() { @@ -82,7 +82,7 @@ export class PublicCallData { /** * Children call stack items. */ - public readonly publicCallStackPreimages: Tuple, + public readonly publicCallStackPreimages: Tuple, /** * Proof of the call stack item execution. */ @@ -96,7 +96,7 @@ export class PublicCallData { */ public readonly bytecodeHash: Fr, ) { - assertMemberLength(this, 'publicCallStackPreimages', PUBLIC_CALL_STACK_LENGTH); + assertMemberLength(this, 'publicCallStackPreimages', MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL); } toBuffer() { diff --git a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts index 6d7f8b51aaaf..f6bc57c0ca94 100644 --- a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts @@ -3,12 +3,12 @@ import { assertMemberLength, FieldsOf } from '../utils/jsUtils.js'; import { serializeToBuffer } from '../utils/serialize.js'; import { CallContext } from './call_context.js'; import { - NEW_COMMITMENTS_LENGTH, - NEW_L2_TO_L1_MSGS_LENGTH, - NEW_NULLIFIERS_LENGTH, + MAX_NEW_COMMITMENTS_PER_CALL, + MAX_NEW_L2_TO_L1_MSGS_PER_CALL, + MAX_NEW_NULLIFIERS_PER_CALL, NUM_FIELDS_PER_SHA256, - PRIVATE_CALL_STACK_LENGTH, - PUBLIC_CALL_STACK_LENGTH, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, READ_REQUESTS_LENGTH, RETURN_VALUES_LENGTH, } from './constants.js'; @@ -107,11 +107,11 @@ export class PrivateCircuitPublicInputs { ) { assertMemberLength(this, 'returnValues', RETURN_VALUES_LENGTH); assertMemberLength(this, 'readRequests', READ_REQUESTS_LENGTH); - assertMemberLength(this, 'newCommitments', NEW_COMMITMENTS_LENGTH); - assertMemberLength(this, 'newNullifiers', NEW_NULLIFIERS_LENGTH); - assertMemberLength(this, 'privateCallStack', PRIVATE_CALL_STACK_LENGTH); - assertMemberLength(this, 'publicCallStack', PUBLIC_CALL_STACK_LENGTH); - assertMemberLength(this, 'newL2ToL1Msgs', NEW_L2_TO_L1_MSGS_LENGTH); + assertMemberLength(this, 'newCommitments', MAX_NEW_COMMITMENTS_PER_CALL); + assertMemberLength(this, 'newNullifiers', MAX_NEW_NULLIFIERS_PER_CALL); + assertMemberLength(this, 'privateCallStack', MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL); + assertMemberLength(this, 'publicCallStack', MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL); + assertMemberLength(this, 'newL2ToL1Msgs', MAX_NEW_L2_TO_L1_MSGS_PER_CALL); assertMemberLength(this, 'encryptedLogsHash', NUM_FIELDS_PER_SHA256); assertMemberLength(this, 'unencryptedLogsHash', NUM_FIELDS_PER_SHA256); } @@ -138,11 +138,11 @@ export class PrivateCircuitPublicInputs { Fr.ZERO, frArray(RETURN_VALUES_LENGTH), frArray(READ_REQUESTS_LENGTH), - frArray(NEW_COMMITMENTS_LENGTH), - frArray(NEW_NULLIFIERS_LENGTH), - frArray(PRIVATE_CALL_STACK_LENGTH), - frArray(PUBLIC_CALL_STACK_LENGTH), - frArray(NEW_L2_TO_L1_MSGS_LENGTH), + frArray(MAX_NEW_COMMITMENTS_PER_CALL), + frArray(MAX_NEW_NULLIFIERS_PER_CALL), + frArray(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL), + frArray(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL), + frArray(MAX_NEW_L2_TO_L1_MSGS_PER_CALL), frArray(NUM_FIELDS_PER_SHA256), frArray(NUM_FIELDS_PER_SHA256), Fr.ZERO, diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts index 73506efa334e..091333bb4528 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts @@ -6,13 +6,13 @@ import { FieldsOf, assertMemberLength, makeTuple } from '../utils/jsUtils.js'; import { serializeToBuffer } from '../utils/serialize.js'; import { CallContext } from './call_context.js'; import { - KERNEL_PUBLIC_DATA_READS_LENGTH, - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, - NEW_COMMITMENTS_LENGTH, - NEW_L2_TO_L1_MSGS_LENGTH, - NEW_NULLIFIERS_LENGTH, + MAX_PUBLIC_DATA_READS_PER_CALL, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, + MAX_NEW_COMMITMENTS_PER_CALL, + MAX_NEW_L2_TO_L1_MSGS_PER_CALL, + MAX_NEW_NULLIFIERS_PER_CALL, NUM_FIELDS_PER_SHA256, - PUBLIC_CALL_STACK_LENGTH, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, RETURN_VALUES_LENGTH, } from './constants.js'; @@ -152,28 +152,28 @@ export class PublicCircuitPublicInputs { */ public contractStorageUpdateRequests: Tuple< ContractStorageUpdateRequest, - typeof KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH + typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL >, /** * Contract storage reads executed during the call. */ - public contractStorageReads: Tuple, + public contractStorageReads: Tuple, /** * Public call stack of the current kernel iteration. */ - public publicCallStack: Tuple, + public publicCallStack: Tuple, /** * New commitments created within a public execution call */ - public newCommitments: Tuple, + public newCommitments: Tuple, /** * New nullifiers created within a public execution call */ - public newNullifiers: Tuple, + public newNullifiers: Tuple, /** * New L2 to L1 messages generated during the call. */ - public newL2ToL1Msgs: Tuple, + public newL2ToL1Msgs: Tuple, /** * Hash of the unencrypted logs emitted in this function call. * Note: Represented as an array of 2 fields in order to fit in all of the 256 bits of sha256 hash. @@ -193,12 +193,12 @@ export class PublicCircuitPublicInputs { public proverAddress: AztecAddress, ) { assertMemberLength(this, 'returnValues', RETURN_VALUES_LENGTH); - assertMemberLength(this, 'publicCallStack', PUBLIC_CALL_STACK_LENGTH); - assertMemberLength(this, 'newCommitments', NEW_COMMITMENTS_LENGTH); - assertMemberLength(this, 'newNullifiers', NEW_NULLIFIERS_LENGTH); - assertMemberLength(this, 'newL2ToL1Msgs', NEW_L2_TO_L1_MSGS_LENGTH); - assertMemberLength(this, 'contractStorageUpdateRequests', KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH); - assertMemberLength(this, 'contractStorageReads', KERNEL_PUBLIC_DATA_READS_LENGTH); + assertMemberLength(this, 'publicCallStack', MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL); + assertMemberLength(this, 'newCommitments', MAX_NEW_COMMITMENTS_PER_CALL); + assertMemberLength(this, 'newNullifiers', MAX_NEW_NULLIFIERS_PER_CALL); + assertMemberLength(this, 'newL2ToL1Msgs', MAX_NEW_L2_TO_L1_MSGS_PER_CALL); + assertMemberLength(this, 'contractStorageUpdateRequests', MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL); + assertMemberLength(this, 'contractStorageReads', MAX_PUBLIC_DATA_READS_PER_CALL); assertMemberLength(this, 'unencryptedLogsHash', NUM_FIELDS_PER_SHA256); } @@ -220,12 +220,12 @@ export class PublicCircuitPublicInputs { CallContext.empty(), Fr.ZERO, makeTuple(RETURN_VALUES_LENGTH, Fr.zero), - makeTuple(KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, ContractStorageUpdateRequest.empty), - makeTuple(KERNEL_PUBLIC_DATA_READS_LENGTH, ContractStorageRead.empty), - makeTuple(PUBLIC_CALL_STACK_LENGTH, Fr.zero), - makeTuple(NEW_COMMITMENTS_LENGTH, Fr.zero), - makeTuple(NEW_NULLIFIERS_LENGTH, Fr.zero), - makeTuple(NEW_L2_TO_L1_MSGS_LENGTH, Fr.zero), + makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, ContractStorageUpdateRequest.empty), + makeTuple(MAX_PUBLIC_DATA_READS_PER_CALL, ContractStorageRead.empty), + makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, Fr.zero), + makeTuple(MAX_NEW_COMMITMENTS_PER_CALL, Fr.zero), + makeTuple(MAX_NEW_NULLIFIERS_PER_CALL, Fr.zero), + makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, Fr.zero), makeTuple(2, Fr.zero), Fr.ZERO, Fr.ZERO, diff --git a/yarn-project/circuits.js/src/structs/rollup/base_rollup.ts b/yarn-project/circuits.js/src/structs/rollup/base_rollup.ts index 15a520ce0eb5..3949528b383c 100644 --- a/yarn-project/circuits.js/src/structs/rollup/base_rollup.ts +++ b/yarn-project/circuits.js/src/structs/rollup/base_rollup.ts @@ -5,12 +5,12 @@ import { serializeToBuffer } from '../../utils/serialize.js'; import { CONTRACT_TREE_HEIGHT, CONTRACT_TREE_ROOTS_TREE_HEIGHT, - KERNEL_NEW_COMMITMENTS_LENGTH, - KERNEL_NEW_CONTRACTS_LENGTH, - KERNEL_NEW_NULLIFIERS_LENGTH, - KERNEL_PUBLIC_DATA_READS_LENGTH, - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, - L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT, + MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_CONTRACTS_PER_TX, + MAX_NEW_NULLIFIERS_PER_TX, + MAX_PUBLIC_DATA_READS_PER_TX, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, + L1_TO_L2_MSG_ROOTS_TREE_HEIGHT, NULLIFIER_TREE_HEIGHT, PRIVATE_DATA_TREE_HEIGHT, PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT, @@ -135,15 +135,15 @@ export class BaseRollupInputs { * Height of the private data subtree which is to be inserted into the private data tree. * Note: There are notes from 2 kernels being processed here so kernel new commitments length is multiplied by 2. */ - public static PRIVATE_DATA_SUBTREE_HEIGHT = Math.log2(KERNEL_NEW_COMMITMENTS_LENGTH * 2); + public static PRIVATE_DATA_SUBTREE_HEIGHT = Math.log2(MAX_NEW_COMMITMENTS_PER_TX * 2); /** * Height of the contract subtree which is to be inserted into the contract tree. */ - public static CONTRACT_SUBTREE_HEIGHT = Math.log2(KERNEL_NEW_CONTRACTS_LENGTH * 2); + public static CONTRACT_SUBTREE_HEIGHT = Math.log2(MAX_NEW_CONTRACTS_PER_TX * 2); /** * Height of the nullifier subtree which is to be inserted into the nullifier tree. */ - public static NULLIFIER_SUBTREE_HEIGHT = Math.log2(KERNEL_NEW_NULLIFIERS_LENGTH * 2); + public static NULLIFIER_SUBTREE_HEIGHT = Math.log2(MAX_NEW_NULLIFIERS_PER_TX * 2); constructor( /** @@ -221,8 +221,8 @@ export class BaseRollupInputs { * Membership witnesses of L1-to-L2 message tree roots referred by each of the 2 kernels. */ public historicL1ToL2MsgTreeRootMembershipWitnesses: [ - MembershipWitness, - MembershipWitness, + MembershipWitness, + MembershipWitness, ], /** @@ -230,8 +230,8 @@ export class BaseRollupInputs { */ public constants: ConstantBaseRollupData, ) { - assertMemberLength(this, 'lowNullifierLeafPreimages', 2 * KERNEL_NEW_NULLIFIERS_LENGTH); - assertMemberLength(this, 'lowNullifierMembershipWitness', 2 * KERNEL_NEW_NULLIFIERS_LENGTH); + assertMemberLength(this, 'lowNullifierLeafPreimages', 2 * MAX_NEW_NULLIFIERS_PER_TX); + assertMemberLength(this, 'lowNullifierMembershipWitness', 2 * MAX_NEW_NULLIFIERS_PER_TX); assertMemberLength( this, 'newCommitmentsSubtreeSiblingPath', @@ -247,8 +247,8 @@ export class BaseRollupInputs { 'newContractsSubtreeSiblingPath', CONTRACT_TREE_HEIGHT - BaseRollupInputs.CONTRACT_SUBTREE_HEIGHT, ); - assertMemberLength(this, 'newPublicDataUpdateRequestsSiblingPaths', 2 * KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH); - assertMemberLength(this, 'newPublicDataReadsSiblingPaths', 2 * KERNEL_PUBLIC_DATA_READS_LENGTH); + assertMemberLength(this, 'newPublicDataUpdateRequestsSiblingPaths', 2 * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX); + assertMemberLength(this, 'newPublicDataReadsSiblingPaths', 2 * MAX_PUBLIC_DATA_READS_PER_TX); assertItemsLength(this, 'newPublicDataUpdateRequestsSiblingPaths', PUBLIC_DATA_TREE_HEIGHT); assertItemsLength(this, 'newPublicDataReadsSiblingPaths', PUBLIC_DATA_TREE_HEIGHT); } diff --git a/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts b/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts index afd8a55da21f..ecdbabb1f02e 100644 --- a/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts +++ b/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts @@ -3,8 +3,8 @@ import { serializeToBuffer } from '../../utils/serialize.js'; import { AppendOnlyTreeSnapshot } from './append_only_tree_snapshot.js'; import { CONTRACT_TREE_ROOTS_TREE_HEIGHT, - L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT, - L1_TO_L2_MESSAGES_SIBLING_PATH_LENGTH, + L1_TO_L2_MSG_ROOTS_TREE_HEIGHT, + L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT, } from '../constants.js'; @@ -56,8 +56,8 @@ export class RootRollupInputs { ) { assertMemberLength(this, 'newHistoricPrivateDataTreeRootSiblingPath', PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT); assertMemberLength(this, 'newHistoricContractDataTreeRootSiblingPath', CONTRACT_TREE_ROOTS_TREE_HEIGHT); - assertMemberLength(this, 'newL1ToL2MessageTreeRootSiblingPath', L1_TO_L2_MESSAGES_SIBLING_PATH_LENGTH); - assertMemberLength(this, 'newHistoricL1ToL2MessageTreeRootSiblingPath', L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT); + assertMemberLength(this, 'newL1ToL2MessageTreeRootSiblingPath', L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH); + assertMemberLength(this, 'newHistoricL1ToL2MessageTreeRootSiblingPath', L1_TO_L2_MSG_ROOTS_TREE_HEIGHT); assertMemberLength(this, 'newL1ToL2Messages', NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP); } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 0365f75cc24d..b6d0903c37ac 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -26,33 +26,35 @@ import { Fr, FunctionData, G1AffineElement, - KERNEL_NEW_COMMITMENTS_LENGTH, - KERNEL_NEW_CONTRACTS_LENGTH, - KERNEL_NEW_L2_TO_L1_MSGS_LENGTH, - KERNEL_NEW_NULLIFIERS_LENGTH, - KERNEL_OPTIONALLY_REVEALED_DATA_LENGTH, - KERNEL_PRIVATE_CALL_STACK_LENGTH, - KERNEL_PUBLIC_CALL_STACK_LENGTH, - KERNEL_PUBLIC_DATA_READS_LENGTH, - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, + MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_CONTRACTS_PER_TX, + MAX_NEW_L2_TO_L1_MSGS_PER_TX, + MAX_NEW_NULLIFIERS_PER_TX, + MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, + MAX_PUBLIC_DATA_READS_PER_TX, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, + MAX_PUBLIC_DATA_READS_PER_CALL, KernelCircuitPublicInputs, - L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT, - L1_TO_L2_MESSAGES_SIBLING_PATH_LENGTH, + L1_TO_L2_MSG_ROOTS_TREE_HEIGHT, + L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, MembershipWitness, MergeRollupInputs, - NEW_COMMITMENTS_LENGTH, - NEW_L2_TO_L1_MSGS_LENGTH, - NEW_NULLIFIERS_LENGTH, + MAX_NEW_COMMITMENTS_PER_CALL, + MAX_NEW_L2_TO_L1_MSGS_PER_CALL, + MAX_NEW_NULLIFIERS_PER_CALL, NULLIFIER_TREE_HEIGHT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, NUM_FIELDS_PER_SHA256, NewContractData, NullifierLeafPreimage, OptionallyRevealedData, - PRIVATE_CALL_STACK_LENGTH, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, PRIVATE_DATA_TREE_HEIGHT, PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT, - PUBLIC_CALL_STACK_LENGTH, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, PUBLIC_DATA_TREE_HEIGHT, Point, PreviousKernelData, @@ -201,19 +203,19 @@ export function makeEmptyAccumulatedData(seed = 1, full = false): CombinedAccumu return new CombinedAccumulatedData( makeAggregationObject(seed), - tupleGenerator(KERNEL_NEW_COMMITMENTS_LENGTH, fr, seed + 0x100), - tupleGenerator(KERNEL_NEW_NULLIFIERS_LENGTH, fr, seed + 0x200), - tupleGenerator(KERNEL_PRIVATE_CALL_STACK_LENGTH, Fr.zero), // private call stack must be empty - tupleGenerator(KERNEL_PUBLIC_CALL_STACK_LENGTH, fr, seed + 0x400), - tupleGenerator(KERNEL_NEW_L2_TO_L1_MSGS_LENGTH, fr, seed + 0x500), + tupleGenerator(MAX_NEW_COMMITMENTS_PER_TX, fr, seed + 0x100), + tupleGenerator(MAX_NEW_NULLIFIERS_PER_TX, fr, seed + 0x200), + tupleGenerator(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, Fr.zero), // private call stack must be empty + tupleGenerator(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, fr, seed + 0x400), + tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x500), tupleGenerator(2, fr, seed + 0x600), // encrypted logs hash tupleGenerator(2, fr, seed + 0x700), // unencrypted logs hash fr(seed + 0x800), // encrypted_log_preimages_length fr(seed + 0x900), // unencrypted_log_preimages_length - tupleGenerator(KERNEL_NEW_CONTRACTS_LENGTH, makeNewContractData, seed + 0xa00), - tupleGenerator(KERNEL_OPTIONALLY_REVEALED_DATA_LENGTH, makeOptionallyRevealedData, seed + 0xb00), - tupleGenerator(KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, makeEmptyPublicDataUpdateRequest, seed + 0xc00), - tupleGenerator(KERNEL_PUBLIC_DATA_READS_LENGTH, makeEmptyPublicDataRead, seed + 0xd00), + tupleGenerator(MAX_NEW_CONTRACTS_PER_TX, makeNewContractData, seed + 0xa00), + tupleGenerator(MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX, makeOptionallyRevealedData, seed + 0xb00), + tupleGenerator(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, makeEmptyPublicDataUpdateRequest, seed + 0xc00), + tupleGenerator(MAX_PUBLIC_DATA_READS_PER_TX, makeEmptyPublicDataRead, seed + 0xd00), ); } @@ -227,19 +229,19 @@ export function makeAccumulatedData(seed = 1, full = false): CombinedAccumulated return new CombinedAccumulatedData( makeAggregationObject(seed), - tupleGenerator(KERNEL_NEW_COMMITMENTS_LENGTH, fr, seed + 0x100), - tupleGenerator(KERNEL_NEW_NULLIFIERS_LENGTH, fr, seed + 0x200), - tupleGenerator(KERNEL_PRIVATE_CALL_STACK_LENGTH, fr, seed + 0x300), - tupleGenerator(KERNEL_PUBLIC_CALL_STACK_LENGTH, fr, seed + 0x400), - tupleGenerator(KERNEL_NEW_L2_TO_L1_MSGS_LENGTH, fr, seed + 0x500), + tupleGenerator(MAX_NEW_COMMITMENTS_PER_TX, fr, seed + 0x100), + tupleGenerator(MAX_NEW_NULLIFIERS_PER_TX, fr, seed + 0x200), + tupleGenerator(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, fr, seed + 0x300), + tupleGenerator(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, fr, seed + 0x400), + tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x500), tupleGenerator(2, fr, seed + 0x600), // encrypted logs hash tupleGenerator(2, fr, seed + 0x700), // unencrypted logs hash fr(seed + 0x800), // encrypted_log_preimages_length fr(seed + 0x900), // unencrypted_log_preimages_length - tupleGenerator(KERNEL_NEW_CONTRACTS_LENGTH, makeNewContractData, seed + 0xa00), - tupleGenerator(KERNEL_OPTIONALLY_REVEALED_DATA_LENGTH, makeOptionallyRevealedData, seed + 0xb00), - tupleGenerator(KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, makePublicDataUpdateRequest, seed + 0xc00), - tupleGenerator(KERNEL_PUBLIC_DATA_READS_LENGTH, makePublicDataRead, seed + 0xd00), + tupleGenerator(MAX_NEW_CONTRACTS_PER_TX, makeNewContractData, seed + 0xa00), + tupleGenerator(MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX, makeOptionallyRevealedData, seed + 0xb00), + tupleGenerator(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, makePublicDataUpdateRequest, seed + 0xc00), + tupleGenerator(MAX_PUBLIC_DATA_READS_PER_TX, makePublicDataRead, seed + 0xd00), ); } @@ -311,12 +313,12 @@ export function makePublicCircuitPublicInputs( makeCallContext(seed, storageContractAddress), fr(seed + 0x100), tupleGenerator(RETURN_VALUES_LENGTH, fr, seed + 0x200), - tupleGenerator(KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, makeContractStorageUpdateRequest, seed + 0x400), - tupleGenerator(KERNEL_PUBLIC_DATA_READS_LENGTH, makeContractStorageRead, seed + 0x500), - tupleGenerator(PUBLIC_CALL_STACK_LENGTH, fr, seed + 0x600), - tupleGenerator(NEW_COMMITMENTS_LENGTH, fr, seed + 0x700), - tupleGenerator(NEW_NULLIFIERS_LENGTH, fr, seed + 0x800), - tupleGenerator(NEW_L2_TO_L1_MSGS_LENGTH, fr, seed + 0x900), + tupleGenerator(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, makeContractStorageUpdateRequest, seed + 0x400), + tupleGenerator(MAX_PUBLIC_DATA_READS_PER_CALL, makeContractStorageRead, seed + 0x500), + tupleGenerator(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, fr, seed + 0x600), + tupleGenerator(MAX_NEW_COMMITMENTS_PER_CALL, fr, seed + 0x700), + tupleGenerator(MAX_NEW_NULLIFIERS_PER_CALL, fr, seed + 0x800), + tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, fr, seed + 0x900), tupleGenerator(2, fr, seed + 0x901), fr(seed + 0x902), fr(seed + 0xa00), @@ -470,7 +472,7 @@ export function makePublicCallStackItem(seed = 1, full = false): PublicCallStack export async function makePublicCallData(seed = 1, full = false): Promise { const publicCallData = new PublicCallData( makePublicCallStackItem(seed, full), - makeTuple(PUBLIC_CALL_STACK_LENGTH, makePublicCallStackItem, seed + 0x300), + makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, makePublicCallStackItem, seed + 0x300), makeProof(), fr(seed + 1), fr(seed + 2), @@ -509,10 +511,10 @@ export async function makePublicCallData(seed = 1, full = false): Promise { return new WitnessedPublicCallData( await makePublicCallData(seed), - range(KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, seed + 0x100).map(x => + range(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, seed + 0x100).map(x => makeMembershipWitness(PUBLIC_DATA_TREE_HEIGHT, x), ), - makeTuple(KERNEL_PUBLIC_DATA_READS_LENGTH, x => makeMembershipWitness(PUBLIC_DATA_TREE_HEIGHT, x), seed + 0x200), + makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, x => makeMembershipWitness(PUBLIC_DATA_TREE_HEIGHT, x), seed + 0x200), fr(seed + 0x300), ); } @@ -539,7 +541,7 @@ export async function makePublicKernelInputsWithEmptyOutput(seed = 1): Promise

new NullifierLeafPreimage(fr(x), fr(x + 0x100), x + 0x200), ); - const lowNullifierMembershipWitness = range(2 * KERNEL_NEW_NULLIFIERS_LENGTH, seed + 0x2000).map(x => + const lowNullifierMembershipWitness = range(2 * MAX_NEW_NULLIFIERS_PER_TX, seed + 0x2000).map(x => makeMembershipWitness(NULLIFIER_TREE_HEIGHT, x), ); @@ -871,12 +873,11 @@ export function makeBaseRollupInputs(seed = 0): BaseRollupInputs { seed + 0x5000, ).map(x => fr(x)); - const newPublicDataUpdateRequestsSiblingPaths = range( - 2 * KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, - seed + 0x6000, - ).map(x => range(PUBLIC_DATA_TREE_HEIGHT, x).map(fr)); + const newPublicDataUpdateRequestsSiblingPaths = range(2 * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, seed + 0x6000).map( + x => range(PUBLIC_DATA_TREE_HEIGHT, x).map(fr), + ); - const newPublicDataReadsSiblingPaths = range(2 * KERNEL_PUBLIC_DATA_READS_LENGTH, seed + 0x6000).map(x => + const newPublicDataReadsSiblingPaths = range(2 * MAX_PUBLIC_DATA_READS_PER_TX, seed + 0x6000).map(x => range(PUBLIC_DATA_TREE_HEIGHT, x).map(fr), ); @@ -893,8 +894,8 @@ export function makeBaseRollupInputs(seed = 0): BaseRollupInputs { ]; const historicL1ToL2MsgTreeRootMembershipWitnesses: BaseRollupInputs['historicL1ToL2MsgTreeRootMembershipWitnesses'] = [ - makeMembershipWitness(L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT, seed + 0xa000), - makeMembershipWitness(L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT, seed + 0xb000), + makeMembershipWitness(L1_TO_L2_MSG_ROOTS_TREE_HEIGHT, seed + 0xa000), + makeMembershipWitness(L1_TO_L2_MSG_ROOTS_TREE_HEIGHT, seed + 0xb000), ]; const constants = makeConstantBaseRollupData(0x100); diff --git a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts index bf5ee0025c49..734ae02d66fe 100644 --- a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts @@ -2,10 +2,10 @@ import { createMemDown, getConfigEnvVars } from '@aztec/aztec-node'; import { AztecAddress, GlobalVariables, - KERNEL_NEW_COMMITMENTS_LENGTH, - KERNEL_NEW_L2_TO_L1_MSGS_LENGTH, - KERNEL_NEW_NULLIFIERS_LENGTH, - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, + MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_L2_TO_L1_MSGS_PER_TX, + MAX_NEW_NULLIFIERS_PER_TX, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, KernelCircuitPublicInputs, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, PublicDataUpdateRequest, @@ -164,17 +164,17 @@ describe('L1Publisher integration', () => { kernelOutput.constants.txContext.version = fr(config.version); kernelOutput.constants.historicTreeRoots = await getCombinedHistoricTreeRoots(builderDb); kernelOutput.end.publicDataUpdateRequests = makeTuple( - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, i => new PublicDataUpdateRequest(fr(i), fr(0), fr(i + 10)), seed + 0x500, ); const processedTx = await makeProcessedTx(tx, kernelOutput, makeProof()); - processedTx.data.end.newCommitments = makeTuple(KERNEL_NEW_COMMITMENTS_LENGTH, fr, seed + 0x100); - processedTx.data.end.newNullifiers = makeTuple(KERNEL_NEW_NULLIFIERS_LENGTH, fr, seed + 0x200); + processedTx.data.end.newCommitments = makeTuple(MAX_NEW_COMMITMENTS_PER_TX, fr, seed + 0x100); + processedTx.data.end.newNullifiers = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, fr, seed + 0x200); processedTx.data.end.newNullifiers[processedTx.data.end.newNullifiers.length - 1] = Fr.ZERO; - processedTx.data.end.newL2ToL1Msgs = makeTuple(KERNEL_NEW_L2_TO_L1_MSGS_LENGTH, fr, seed + 0x300); + processedTx.data.end.newL2ToL1Msgs = makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x300); processedTx.data.end.newContracts = [makeNewContractData(seed + 0x1000)]; processedTx.data.end.encryptedLogsHash = to2Fields(L2Block.computeKernelLogsHash(processedTx.encryptedLogs)); processedTx.data.end.unencryptedLogsHash = to2Fields(L2Block.computeKernelLogsHash(processedTx.unencryptedLogs)); diff --git a/yarn-project/noir-contracts/src/libs/noir-aztec/src/lib.nr b/yarn-project/noir-contracts/src/libs/noir-aztec/src/lib.nr index 69efc59288e1..1992533f7f7e 100644 --- a/yarn-project/noir-contracts/src/libs/noir-aztec/src/lib.nr +++ b/yarn-project/noir-contracts/src/libs/noir-aztec/src/lib.nr @@ -13,4 +13,4 @@ mod oracle; mod entrypoint; global PRIVATE_DATA_TREE_HEIGHT: comptime Field = 16; -global L1_TO_L2_MESSAGES_TREE_HEIGHT: comptime Field = 8; +global L1_TO_L2_MSG_TREE_HEIGHT: comptime Field = 8; diff --git a/yarn-project/noir-contracts/src/libs/noir-aztec/src/messaging/l1_to_l2_message_getter_data.nr b/yarn-project/noir-contracts/src/libs/noir-aztec/src/messaging/l1_to_l2_message_getter_data.nr index 124c5bfc7746..f6befeccd1f2 100644 --- a/yarn-project/noir-contracts/src/libs/noir-aztec/src/messaging/l1_to_l2_message_getter_data.nr +++ b/yarn-project/noir-contracts/src/libs/noir-aztec/src/messaging/l1_to_l2_message_getter_data.nr @@ -4,20 +4,20 @@ use crate::utils::arr_copy_slice; struct L1ToL2MessageGetterData { message: L1ToL2Message, - sibling_path: [Field; crate::L1_TO_L2_MESSAGES_TREE_HEIGHT], + sibling_path: [Field; crate::L1_TO_L2_MSG_TREE_HEIGHT], leaf_index: Field, root: Field, } fn l1_to_l2_message_getter_len() -> comptime Field { - L1_TO_L2_MESSAGE_LEN + 1 + crate::L1_TO_L2_MESSAGES_TREE_HEIGHT + 1 + L1_TO_L2_MESSAGE_LEN + 1 + crate::L1_TO_L2_MSG_TREE_HEIGHT + 1 } fn make_l1_to_l2_message_getter_data(fields: [Field], start: comptime Field, secret: Field) -> L1ToL2MessageGetterData { L1ToL2MessageGetterData { message: L1ToL2Message::deserialize(arr_copy_slice(fields, [0; L1_TO_L2_MESSAGE_LEN], start), secret, fields[start + L1_TO_L2_MESSAGE_LEN]), leaf_index: fields[start + L1_TO_L2_MESSAGE_LEN], - sibling_path: arr_copy_slice(fields, [0; crate::L1_TO_L2_MESSAGES_TREE_HEIGHT], L1_TO_L2_MESSAGE_LEN + 1), - root: fields[start + L1_TO_L2_MESSAGE_LEN + crate::L1_TO_L2_MESSAGES_TREE_HEIGHT + 1], + sibling_path: arr_copy_slice(fields, [0; crate::L1_TO_L2_MSG_TREE_HEIGHT], L1_TO_L2_MESSAGE_LEN + 1), + root: fields[start + L1_TO_L2_MESSAGE_LEN + crate::L1_TO_L2_MSG_TREE_HEIGHT + 1], } } \ No newline at end of file diff --git a/yarn-project/p2p/src/client/mocks.ts b/yarn-project/p2p/src/client/mocks.ts index 410bda5c7ec7..66d663ab9d6e 100644 --- a/yarn-project/p2p/src/client/mocks.ts +++ b/yarn-project/p2p/src/client/mocks.ts @@ -1,4 +1,4 @@ -import { KERNEL_PUBLIC_CALL_STACK_LENGTH, Proof } from '@aztec/circuits.js'; +import { MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, Proof } from '@aztec/circuits.js'; import { makeKernelPublicInputs, makePublicCallRequest } from '@aztec/circuits.js/factories'; import { Tx, TxL2Logs, L2BlockSource, L2Block } from '@aztec/types'; import times from 'lodash.times'; @@ -10,7 +10,7 @@ export const MockTx = () => { TxL2Logs.random(8, 3), // 8 priv function invocations creating 3 encrypted logs each TxL2Logs.random(11, 2), // 8 priv + 3 pub function invocations creating 2 unencrypted logs each [], - times(KERNEL_PUBLIC_CALL_STACK_LENGTH, makePublicCallRequest), + times(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, makePublicCallRequest), ); }; diff --git a/yarn-project/p2p/src/service/tx_messages.test.ts b/yarn-project/p2p/src/service/tx_messages.test.ts index d7743631025f..a70a33ec0db6 100644 --- a/yarn-project/p2p/src/service/tx_messages.test.ts +++ b/yarn-project/p2p/src/service/tx_messages.test.ts @@ -1,4 +1,4 @@ -import { KERNEL_PUBLIC_CALL_STACK_LENGTH, Proof } from '@aztec/circuits.js'; +import { MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, Proof } from '@aztec/circuits.js'; import { makeKernelPublicInputs, makePublicCallRequest } from '@aztec/circuits.js/factories'; import { EncodedContractFunction, Tx, TxHash, TxL2Logs } from '@aztec/types'; import { expect } from '@jest/globals'; @@ -20,7 +20,7 @@ import { const makeTx = () => { const encodedPublicFunctions = [EncodedContractFunction.random(), EncodedContractFunction.random()]; - const enqueuedPublicFunctionCalls = times(KERNEL_PUBLIC_CALL_STACK_LENGTH, i => makePublicCallRequest(i)); + const enqueuedPublicFunctionCalls = times(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, i => makePublicCallRequest(i)); return new Tx( makeKernelPublicInputs(), Proof.fromBuffer(Buffer.alloc(10, 9)), diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts index 206dc58090ad..a4d71a66be63 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts @@ -5,11 +5,11 @@ import { CircuitsWasm, Fr, GlobalVariables, - KERNEL_NEW_COMMITMENTS_LENGTH, - KERNEL_NEW_L2_TO_L1_MSGS_LENGTH, - KERNEL_NEW_NULLIFIERS_LENGTH, - KERNEL_PUBLIC_CALL_STACK_LENGTH, - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, + MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_L2_TO_L1_MSGS_PER_TX, + MAX_NEW_NULLIFIERS_PER_TX, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, KernelCircuitPublicInputs, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, Proof, @@ -154,7 +154,7 @@ describe('sequencer/solo_block_builder', () => { makeEmptyLogs(), makeEmptyLogs(), [], - times(KERNEL_PUBLIC_CALL_STACK_LENGTH, makePublicCallRequest), + times(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, makePublicCallRequest), ), ); @@ -292,17 +292,17 @@ describe('sequencer/solo_block_builder', () => { const kernelOutput = KernelCircuitPublicInputs.empty(); kernelOutput.constants.historicTreeRoots = await getCombinedHistoricTreeRoots(builderDb); kernelOutput.end.publicDataUpdateRequests = makeTuple( - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, i => new PublicDataUpdateRequest(fr(i), fr(0), fr(i + 10)), seed + 0x500, ); const processedTx = await makeProcessedTx(tx, kernelOutput, makeProof()); - processedTx.data.end.newCommitments = makeTuple(KERNEL_NEW_COMMITMENTS_LENGTH, fr, seed + 0x100); - processedTx.data.end.newNullifiers = makeTuple(KERNEL_NEW_NULLIFIERS_LENGTH, fr, seed + 0x200); + processedTx.data.end.newCommitments = makeTuple(MAX_NEW_COMMITMENTS_PER_TX, fr, seed + 0x100); + processedTx.data.end.newNullifiers = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, fr, seed + 0x200); processedTx.data.end.newNullifiers[tx.data.end.newNullifiers.length - 1] = Fr.ZERO; - processedTx.data.end.newL2ToL1Msgs = makeTuple(KERNEL_NEW_L2_TO_L1_MSGS_LENGTH, fr, seed + 0x300); + processedTx.data.end.newL2ToL1Msgs = makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x300); processedTx.data.end.newContracts = [makeNewContractData(seed + 0x1000)]; processedTx.data.end.encryptedLogsHash = to2Fields(L2Block.computeKernelLogsHash(processedTx.encryptedLogs)); processedTx.data.end.unencryptedLogsHash = to2Fields(L2Block.computeKernelLogsHash(processedTx.unencryptedLogs)); @@ -375,7 +375,7 @@ describe('sequencer/solo_block_builder', () => { const prover = new EmptyRollupProver(); builder = new SoloBlockBuilder(builderDb, vks, simulator, prover); // update the starting tree - const updateVals = Array(4 * KERNEL_NEW_NULLIFIERS_LENGTH).fill(0n); + const updateVals = Array(4 * MAX_NEW_NULLIFIERS_PER_TX).fill(0n); updateVals[0] = 19777494491628650244807463906174285795660759352776418619064841306523677458742n; updateVals[1] = 10246291467305176436335175657884940686778521321101740385288169037814567547848n; diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts index 8b60ba254891..f5199900d5ab 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts @@ -6,8 +6,8 @@ import { CircuitsWasm, ConstantBaseRollupData, GlobalVariables, - L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT, - L1_TO_L2_MESSAGES_SUBTREE_HEIGHT, + L1_TO_L2_MSG_ROOTS_TREE_HEIGHT, + L1_TO_L2_MSG_SUBTREE_HEIGHT, MembershipWitness, MergeRollupInputs, NULLIFIER_TREE_HEIGHT, @@ -426,7 +426,7 @@ export class SoloBlockBuilder implements BlockBuilder { ); const newL1ToL2MessageTreeRootSiblingPath = await this.getSubtreeSiblingPath( MerkleTreeId.L1_TO_L2_MESSAGES_TREE, - L1_TO_L2_MESSAGES_SUBTREE_HEIGHT, + L1_TO_L2_MSG_SUBTREE_HEIGHT, ); // Get tree snapshots @@ -518,7 +518,7 @@ export class SoloBlockBuilder implements BlockBuilder { return this.getMembershipWitnessFor( tx.data.constants.historicTreeRoots.privateHistoricTreeRoots.l1ToL2MessagesTreeRoot, MerkleTreeId.L1_TO_L2_MESSAGES_ROOTS_TREE, - L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT, + L1_TO_L2_MSG_ROOTS_TREE_HEIGHT, ); } diff --git a/yarn-project/sequencer-client/src/mocks/tx.ts b/yarn-project/sequencer-client/src/mocks/tx.ts index 8352e95e393b..ed7456b21c10 100644 --- a/yarn-project/sequencer-client/src/mocks/tx.ts +++ b/yarn-project/sequencer-client/src/mocks/tx.ts @@ -1,4 +1,4 @@ -import { KERNEL_PUBLIC_CALL_STACK_LENGTH, makeEmptyProof } from '@aztec/circuits.js'; +import { MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, makeEmptyProof } from '@aztec/circuits.js'; import { makeKernelPublicInputs, makePublicCallRequest } from '@aztec/circuits.js/factories'; import { FunctionL2Logs, Tx, TxL2Logs } from '@aztec/types'; import times from 'lodash.times'; @@ -21,6 +21,6 @@ export function makeTx(seed = 0) { TxL2Logs.random(2, 3), TxL2Logs.random(3, 0), [], - times(KERNEL_PUBLIC_CALL_STACK_LENGTH, makePublicCallRequest), + times(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, makePublicCallRequest), ); } diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts index 5f1547f27f82..a1c4cce618f6 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts @@ -7,8 +7,8 @@ import { Fr, FunctionData, GlobalVariables, - KERNEL_PRIVATE_CALL_STACK_LENGTH, - KERNEL_PUBLIC_CALL_STACK_LENGTH, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, PUBLIC_DATA_TREE_HEIGHT, Proof, PublicCallRequest, @@ -84,7 +84,7 @@ describe('public_processor', () => { it('skips txs without public execution requests', async function () { const tx = makeTx(); - tx.data.end.publicCallStack = makeTuple(KERNEL_PUBLIC_CALL_STACK_LENGTH, Fr.zero); + tx.data.end.publicCallStack = makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, Fr.zero); const hash = await tx.getTxHash(); const [processed, failed] = await processor.process([tx], GlobalVariables.empty()); @@ -132,8 +132,8 @@ describe('public_processor', () => { const callStackHashes = callStackItems.map(call => computeCallStackItemHash(wasm, call)); const kernelOutput = makeKernelPublicInputs(0x10); - kernelOutput.end.publicCallStack = padArrayEnd(callStackHashes, Fr.ZERO, KERNEL_PUBLIC_CALL_STACK_LENGTH); - kernelOutput.end.privateCallStack = padArrayEnd([], Fr.ZERO, KERNEL_PRIVATE_CALL_STACK_LENGTH); + kernelOutput.end.publicCallStack = padArrayEnd(callStackHashes, Fr.ZERO, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX); + kernelOutput.end.privateCallStack = padArrayEnd([], Fr.ZERO, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX); const tx = new Tx(kernelOutput, proof, TxL2Logs.random(2, 3), TxL2Logs.random(3, 2), [], callRequests); @@ -160,8 +160,8 @@ describe('public_processor', () => { const callStackHash = computeCallStackItemHash(wasm, callStackItem); const kernelOutput = makeKernelPublicInputs(0x10); - kernelOutput.end.publicCallStack = padArrayEnd([callStackHash], Fr.ZERO, KERNEL_PUBLIC_CALL_STACK_LENGTH); - kernelOutput.end.privateCallStack = padArrayEnd([], Fr.ZERO, KERNEL_PRIVATE_CALL_STACK_LENGTH); + kernelOutput.end.publicCallStack = padArrayEnd([callStackHash], Fr.ZERO, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX); + kernelOutput.end.privateCallStack = padArrayEnd([], Fr.ZERO, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX); const tx = new Tx(kernelOutput, proof, TxL2Logs.random(2, 3), TxL2Logs.random(3, 2), [], [callRequest]); diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.ts index 80edc504c16e..6e57986eaba5 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.ts @@ -6,14 +6,14 @@ import { ContractStorageUpdateRequest, Fr, GlobalVariables, - KERNEL_PUBLIC_DATA_READS_LENGTH, - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, + MAX_PUBLIC_DATA_READS_PER_CALL, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, KernelCircuitPublicInputs, MembershipWitness, - NEW_COMMITMENTS_LENGTH, - NEW_L2_TO_L1_MSGS_LENGTH, - NEW_NULLIFIERS_LENGTH, - PUBLIC_CALL_STACK_LENGTH, + MAX_NEW_COMMITMENTS_PER_CALL, + MAX_NEW_L2_TO_L1_MSGS_PER_CALL, + MAX_NEW_NULLIFIERS_PER_CALL, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, PreviousKernelData, Proof, PublicCallData, @@ -210,19 +210,19 @@ export class PublicProcessor { callContext: result.execution.callContext, proverAddress: AztecAddress.random(), argsHash: await computeVarArgsHash(wasm, result.execution.args), - newCommitments: padArrayEnd(result.newCommitments, Fr.ZERO, NEW_COMMITMENTS_LENGTH), - newNullifiers: padArrayEnd(result.newNullifiers, Fr.ZERO, NEW_NULLIFIERS_LENGTH), - newL2ToL1Msgs: padArrayEnd(result.newL2ToL1Messages, Fr.ZERO, NEW_L2_TO_L1_MSGS_LENGTH), + newCommitments: padArrayEnd(result.newCommitments, Fr.ZERO, MAX_NEW_COMMITMENTS_PER_CALL), + newNullifiers: padArrayEnd(result.newNullifiers, Fr.ZERO, MAX_NEW_NULLIFIERS_PER_CALL), + newL2ToL1Msgs: padArrayEnd(result.newL2ToL1Messages, Fr.ZERO, MAX_NEW_L2_TO_L1_MSGS_PER_CALL), returnValues: padArrayEnd(result.returnValues, Fr.ZERO, RETURN_VALUES_LENGTH), contractStorageReads: padArrayEnd( result.contractStorageReads, ContractStorageRead.empty(), - KERNEL_PUBLIC_DATA_READS_LENGTH, + MAX_PUBLIC_DATA_READS_PER_CALL, ), contractStorageUpdateRequests: padArrayEnd( result.contractStorageUpdateRequests, ContractStorageUpdateRequest.empty(), - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, ), publicCallStack, unencryptedLogsHash, @@ -243,12 +243,14 @@ export class PublicProcessor { protected async getPublicCallStackPreimages(result: PublicExecutionResult) { const nested = result.nestedExecutions; const preimages: PublicCallStackItem[] = await Promise.all(nested.map(n => this.getPublicCallStackItem(n))); - if (preimages.length > PUBLIC_CALL_STACK_LENGTH) { - throw new Error(`Public call stack size exceeded (max ${PUBLIC_CALL_STACK_LENGTH}, got ${preimages.length})`); + if (preimages.length > MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL) { + throw new Error( + `Public call stack size exceeded (max ${MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL}, got ${preimages.length})`, + ); } // Top of the stack is at the end of the array, so we padStart - return padArrayStart(preimages, PublicCallStackItem.empty(), PUBLIC_CALL_STACK_LENGTH); + return padArrayStart(preimages, PublicCallStackItem.empty(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL); } protected getBytecodeHash(_result: PublicExecutionResult) { @@ -268,7 +270,7 @@ export class PublicProcessor { */ protected async getPublicCallData( result: PublicExecutionResult, - preimages: Tuple, + preimages: Tuple, isExecutionRequest = false, ) { const bytecodeHash = await this.getBytecodeHash(result); diff --git a/yarn-project/types/src/l2_block.ts b/yarn-project/types/src/l2_block.ts index 00f4589ec0c8..eac4b1bb32c0 100644 --- a/yarn-project/types/src/l2_block.ts +++ b/yarn-project/types/src/l2_block.ts @@ -1,11 +1,11 @@ import { AppendOnlyTreeSnapshot, - KERNEL_NEW_COMMITMENTS_LENGTH, - KERNEL_NEW_CONTRACTS_LENGTH, - KERNEL_NEW_NULLIFIERS_LENGTH, - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, + MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_CONTRACTS_PER_TX, + MAX_NEW_NULLIFIERS_PER_TX, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, - KERNEL_NEW_L2_TO_L1_MSGS_LENGTH, + MAX_NEW_L2_TO_L1_MSGS_PER_TX, GlobalVariables, } from '@aztec/circuits.js'; import { makeAppendOnlyTreeSnapshot, makeGlobalVariables } from '@aztec/circuits.js/factories'; @@ -146,8 +146,8 @@ export class L2Block { newEncryptedLogs?: L2BlockL2Logs, newUnencryptedLogs?: L2BlockL2Logs, ) { - if (newCommitments.length % KERNEL_NEW_COMMITMENTS_LENGTH !== 0) { - throw new Error(`The number of new commitments must be a multiple of ${KERNEL_NEW_COMMITMENTS_LENGTH}.`); + if (newCommitments.length % MAX_NEW_COMMITMENTS_PER_TX !== 0) { + throw new Error(`The number of new commitments must be a multiple of ${MAX_NEW_COMMITMENTS_PER_TX}.`); } if (newEncryptedLogs) { @@ -176,13 +176,13 @@ export class L2Block { numEncryptedLogs = 2, numUnencryptedLogs = 1, ): L2Block { - const newNullifiers = times(KERNEL_NEW_NULLIFIERS_LENGTH * txsPerBlock, Fr.random); - const newCommitments = times(KERNEL_NEW_COMMITMENTS_LENGTH * txsPerBlock, Fr.random); - const newContracts = times(KERNEL_NEW_CONTRACTS_LENGTH * txsPerBlock, Fr.random); - const newContractData = times(KERNEL_NEW_CONTRACTS_LENGTH * txsPerBlock, ContractData.random); - const newPublicDataWrites = times(KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH * txsPerBlock, PublicDataWrite.random); + const newNullifiers = times(MAX_NEW_NULLIFIERS_PER_TX * txsPerBlock, Fr.random); + const newCommitments = times(MAX_NEW_COMMITMENTS_PER_TX * txsPerBlock, Fr.random); + const newContracts = times(MAX_NEW_CONTRACTS_PER_TX * txsPerBlock, Fr.random); + const newContractData = times(MAX_NEW_CONTRACTS_PER_TX * txsPerBlock, ContractData.random); + const newPublicDataWrites = times(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * txsPerBlock, PublicDataWrite.random); const newL1ToL2Messages = times(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, Fr.random); - const newL2ToL1Msgs = times(KERNEL_NEW_L2_TO_L1_MSGS_LENGTH, Fr.random); + const newL2ToL1Msgs = times(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.random); const newEncryptedLogs = L2BlockL2Logs.random(txsPerBlock, numPrivateFunctionCalls, numEncryptedLogs); const newUnencryptedLogs = L2BlockL2Logs.random(txsPerBlock, numPublicFunctionCalls, numUnencryptedLogs); @@ -493,7 +493,7 @@ export class L2Block { throw new Error(`L2 block already has ${logType} attached.`); } - const numTxs = this.newCommitments.length / KERNEL_NEW_COMMITMENTS_LENGTH; + const numTxs = this.newCommitments.length / MAX_NEW_COMMITMENTS_PER_TX; if (numTxs !== logs.txLogs.length) { throw new Error( @@ -611,14 +611,14 @@ export class L2Block { return layers[layers.length - 1][0]; }; - const leafCount = this.newCommitments.length / (KERNEL_NEW_COMMITMENTS_LENGTH * 2); + const leafCount = this.newCommitments.length / (MAX_NEW_COMMITMENTS_PER_TX * 2); const leafs: Buffer[] = []; for (let i = 0; i < leafCount; i++) { - const commitmentsPerBase = KERNEL_NEW_COMMITMENTS_LENGTH * 2; - const nullifiersPerBase = KERNEL_NEW_NULLIFIERS_LENGTH * 2; - const publicDataUpdateRequestsPerBase = KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH * 2; - const l2ToL1MsgsPerBase = KERNEL_NEW_L2_TO_L1_MSGS_LENGTH * 2; + const commitmentsPerBase = MAX_NEW_COMMITMENTS_PER_TX * 2; + const nullifiersPerBase = MAX_NEW_NULLIFIERS_PER_TX * 2; + const publicDataUpdateRequestsPerBase = MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * 2; + const l2ToL1MsgsPerBase = MAX_NEW_L2_TO_L1_MSGS_PER_TX * 2; const commitmentsBuffer = Buffer.concat( this.newCommitments.slice(i * commitmentsPerBase, (i + 1) * commitmentsPerBase).map(x => x.toBuffer()), ); @@ -677,34 +677,34 @@ export class L2Block { * @returns The tx. */ getTx(txIndex: number) { - const numTxs = Math.floor(this.newCommitments.length / KERNEL_NEW_COMMITMENTS_LENGTH); + const numTxs = Math.floor(this.newCommitments.length / MAX_NEW_COMMITMENTS_PER_TX); if (txIndex >= numTxs) { throw new Error(`Failed to get tx ${txIndex}. Block ${this.globalVariables.blockNumber} only has ${numTxs} txs.`); } const newCommitments = this.newCommitments.slice( - KERNEL_NEW_COMMITMENTS_LENGTH * txIndex, - KERNEL_NEW_COMMITMENTS_LENGTH * (txIndex + 1), + MAX_NEW_COMMITMENTS_PER_TX * txIndex, + MAX_NEW_COMMITMENTS_PER_TX * (txIndex + 1), ); const newNullifiers = this.newNullifiers.slice( - KERNEL_NEW_NULLIFIERS_LENGTH * txIndex, - KERNEL_NEW_NULLIFIERS_LENGTH * (txIndex + 1), + MAX_NEW_NULLIFIERS_PER_TX * txIndex, + MAX_NEW_NULLIFIERS_PER_TX * (txIndex + 1), ); const newPublicDataWrites = this.newPublicDataWrites.slice( - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH * txIndex, - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH * (txIndex + 1), + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * txIndex, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * (txIndex + 1), ); const newL2ToL1Msgs = this.newL2ToL1Msgs.slice( - KERNEL_NEW_L2_TO_L1_MSGS_LENGTH * txIndex, - KERNEL_NEW_L2_TO_L1_MSGS_LENGTH * (txIndex + 1), + MAX_NEW_L2_TO_L1_MSGS_PER_TX * txIndex, + MAX_NEW_L2_TO_L1_MSGS_PER_TX * (txIndex + 1), ); const newContracts = this.newContracts.slice( - KERNEL_NEW_CONTRACTS_LENGTH * txIndex, - KERNEL_NEW_CONTRACTS_LENGTH * (txIndex + 1), + MAX_NEW_CONTRACTS_PER_TX * txIndex, + MAX_NEW_CONTRACTS_PER_TX * (txIndex + 1), ); const newContractData = this.newContractData.slice( - KERNEL_NEW_CONTRACTS_LENGTH * txIndex, - KERNEL_NEW_CONTRACTS_LENGTH * (txIndex + 1), + MAX_NEW_CONTRACTS_PER_TX * txIndex, + MAX_NEW_CONTRACTS_PER_TX * (txIndex + 1), ); return new L2Tx(newCommitments, newNullifiers, newPublicDataWrites, newL2ToL1Msgs, newContracts, newContractData); diff --git a/yarn-project/types/src/l2_block_context.ts b/yarn-project/types/src/l2_block_context.ts index 2d88244aab82..13753513d110 100644 --- a/yarn-project/types/src/l2_block_context.ts +++ b/yarn-project/types/src/l2_block_context.ts @@ -1,4 +1,4 @@ -import { KERNEL_NEW_COMMITMENTS_LENGTH } from '@aztec/circuits.js'; +import { MAX_NEW_COMMITMENTS_PER_TX } from '@aztec/circuits.js'; import { L2Block } from './l2_block.js'; import { TxHash } from './tx_hash.js'; @@ -17,7 +17,7 @@ export class L2BlockContext { */ public readonly block: L2Block, ) { - this.txHashes = new Array(Math.floor(block.newCommitments.length / KERNEL_NEW_COMMITMENTS_LENGTH)); + this.txHashes = new Array(Math.floor(block.newCommitments.length / MAX_NEW_COMMITMENTS_PER_TX)); } /** diff --git a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.test.ts b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.test.ts index cd2a01168da4..bb4a50708698 100644 --- a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.test.ts +++ b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.test.ts @@ -2,11 +2,11 @@ import { AppendOnlyTreeSnapshot, CircuitsWasm, GlobalVariables, - KERNEL_NEW_COMMITMENTS_LENGTH, - KERNEL_NEW_CONTRACTS_LENGTH, - KERNEL_NEW_NULLIFIERS_LENGTH, - KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, - NEW_L2_TO_L1_MSGS_LENGTH, + MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_CONTRACTS_PER_TX, + MAX_NEW_NULLIFIERS_PER_TX, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, + MAX_NEW_L2_TO_L1_MSGS_PER_CALL, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, } from '@aztec/circuits.js'; import { INITIAL_LEAF, Pedersen, SiblingPath } from '@aztec/merkle-tree'; @@ -78,13 +78,13 @@ const getMockBlock = (blockNumber: number, newContractsCommitments?: Buffer[]) = endPublicDataTreeRoot: Fr.random(), endL1ToL2MessageTreeSnapshot: getMockTreeSnapshot(), endTreeOfHistoricL1ToL2MessageTreeRootsSnapshot: getMockTreeSnapshot(), - newCommitments: times(KERNEL_NEW_COMMITMENTS_LENGTH, Fr.random), - newNullifiers: times(KERNEL_NEW_NULLIFIERS_LENGTH, Fr.random), + newCommitments: times(MAX_NEW_COMMITMENTS_PER_TX, Fr.random), + newNullifiers: times(MAX_NEW_NULLIFIERS_PER_TX, Fr.random), newContracts: newContractsCommitments?.map(x => Fr.fromBuffer(x)) ?? [Fr.random()], - newContractData: times(KERNEL_NEW_CONTRACTS_LENGTH, getMockContractData), - newPublicDataWrites: times(KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, PublicDataWrite.random), + newContractData: times(MAX_NEW_CONTRACTS_PER_TX, getMockContractData), + newPublicDataWrites: times(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite.random), newL1ToL2Messages: getMockL1ToL2MessagesData(), - newL2ToL1Msgs: times(NEW_L2_TO_L1_MSGS_LENGTH, Fr.random), + newL2ToL1Msgs: times(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, Fr.random), newEncryptedLogs, }); return block; diff --git a/yarn-project/world-state/src/world-state-db/index.ts b/yarn-project/world-state/src/world-state-db/index.ts index 11f7958b5c8b..5b5f51e8904a 100644 --- a/yarn-project/world-state/src/world-state-db/index.ts +++ b/yarn-project/world-state/src/world-state-db/index.ts @@ -1,7 +1,7 @@ import { LeafData, SiblingPath, LowLeafWitnessData } from '@aztec/merkle-tree'; import { L2Block, MerkleTreeId } from '@aztec/types'; import { createDebugLogger } from '@aztec/foundation/log'; -import { KERNEL_NEW_NULLIFIERS_LENGTH } from '@aztec/circuits.js'; +import { MAX_NEW_NULLIFIERS_PER_TX } from '@aztec/circuits.js'; export * from './merkle_trees.js'; export { LeafData } from '@aztec/merkle-tree'; @@ -31,7 +31,7 @@ export type PublicTreeId = MerkleTreeId.PUBLIC_DATA_TREE; * 1024 leaves for the first block, because there's only neat space for 1023 leaves after 0. By padding with 1023 * more leaves, we can then insert the first block of 1024 leaves into indices 1024:2047. */ -export const INITIAL_NULLIFIER_TREE_SIZE = 2 * KERNEL_NEW_NULLIFIERS_LENGTH; +export const INITIAL_NULLIFIER_TREE_SIZE = 2 * MAX_NEW_NULLIFIERS_PER_TX; /** * Defines tree information. diff --git a/yarn-project/world-state/src/world-state-db/merkle_trees.ts b/yarn-project/world-state/src/world-state-db/merkle_trees.ts index 3892673f392a..89703cd74d45 100644 --- a/yarn-project/world-state/src/world-state-db/merkle_trees.ts +++ b/yarn-project/world-state/src/world-state-db/merkle_trees.ts @@ -4,8 +4,8 @@ import { CONTRACT_TREE_ROOTS_TREE_HEIGHT, CircuitsWasm, Fr, - L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT, - L1_TO_L2_MESSAGES_TREE_HEIGHT, + L1_TO_L2_MSG_ROOTS_TREE_HEIGHT, + L1_TO_L2_MSG_TREE_HEIGHT, NULLIFIER_TREE_HEIGHT, PRIVATE_DATA_TREE_HEIGHT, PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT, @@ -104,14 +104,14 @@ export class MerkleTrees implements MerkleTreeDb { this.db, hasher, `${MerkleTreeId[MerkleTreeId.L1_TO_L2_MESSAGES_TREE]}`, - L1_TO_L2_MESSAGES_TREE_HEIGHT, + L1_TO_L2_MSG_TREE_HEIGHT, ); const l1Tol2MessagesRootsTree: AppendOnlyTree = await newTree( StandardTree, this.db, hasher, `${MerkleTreeId[MerkleTreeId.L1_TO_L2_MESSAGES_ROOTS_TREE]}`, - L1_TO_L2_MESSAGES_ROOTS_TREE_HEIGHT, + L1_TO_L2_MSG_ROOTS_TREE_HEIGHT, ); this.trees = [ contractTree,