diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index f8a7ae2576e6..eed1cc5937ac 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -25,7 +25,7 @@ library Constants { uint256 internal constant MAX_PUBLIC_DATA_READS_PER_CALL = 16; uint256 internal constant MAX_READ_REQUESTS_PER_CALL = 32; uint256 internal constant MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL = 1; - uint256 internal constant MAX_NEW_COMMITMENTS_PER_TX = 64; + uint256 internal constant MAX_NEW_NOTE_HASHES_PER_TX = 64; uint256 internal constant MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX = 8; uint256 internal constant MAX_REVERTIBLE_COMMITMENTS_PER_TX = 56; uint256 internal constant MAX_NEW_NULLIFIERS_PER_TX = 64; diff --git a/l1-contracts/src/core/libraries/decoders/Decoder.sol b/l1-contracts/src/core/libraries/decoders/Decoder.sol index 39efa07f04d3..81d41999b84a 100644 --- a/l1-contracts/src/core/libraries/decoders/Decoder.sol +++ b/l1-contracts/src/core/libraries/decoders/Decoder.sol @@ -174,7 +174,7 @@ library Decoder { // Commitments uint256 count = read4(_body, offset); - vars.baseLeaves = new bytes32[](count / Constants.MAX_NEW_COMMITMENTS_PER_TX); + vars.baseLeaves = new bytes32[](count / Constants.MAX_NEW_NOTE_HASHES_PER_TX); offset += 0x4; offsets.commitment = offset; offset += count * 0x20; diff --git a/l1-contracts/src/core/libraries/decoders/TxsDecoder.sol b/l1-contracts/src/core/libraries/decoders/TxsDecoder.sol index 93bb8d922d4f..79c6595fd287 100644 --- a/l1-contracts/src/core/libraries/decoders/TxsDecoder.sol +++ b/l1-contracts/src/core/libraries/decoders/TxsDecoder.sol @@ -77,7 +77,7 @@ library TxsDecoder { // Commitments uint256 count = read4(_body, offset); - vars.baseLeaves = new bytes32[](count / Constants.MAX_NEW_COMMITMENTS_PER_TX); + vars.baseLeaves = new bytes32[](count / Constants.MAX_NEW_NOTE_HASHES_PER_TX); offsets.commitment = 0x4; offset += 0x4 + count * 0x20; offsets.nullifier = offset + 0x4; // + 0x4 to offset by next read4 diff --git a/noir-projects/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr b/noir-projects/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr index d91407955f99..870eeac8bb23 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr @@ -85,7 +85,7 @@ impl PrivateKernelInnerCircuitPrivateInputs { mod tests { use crate::private_kernel_inner::PrivateKernelInnerCircuitPrivateInputs; - use dep::types::constants::{MAX_READ_REQUESTS_PER_CALL, MAX_NEW_COMMITMENTS_PER_TX}; + use dep::types::constants::{MAX_READ_REQUESTS_PER_CALL, MAX_NEW_NOTE_HASHES_PER_TX}; use dep::types::{ abis::{ kernel_circuit_public_inputs::PrivateKernelInnerCircuitPublicInputs, @@ -519,8 +519,8 @@ mod tests { builder.private_call.public_inputs.new_commitments.push(SideEffect { value: 4321, counter: 0 }); // Mock the previous new commitments to be full, therefore no more commitments can be added. - let mut full_new_commitments = [SideEffect::empty(); MAX_NEW_COMMITMENTS_PER_TX]; - for i in 0..MAX_NEW_COMMITMENTS_PER_TX { + let mut full_new_commitments = [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_TX]; + for i in 0..MAX_NEW_NOTE_HASHES_PER_TX { full_new_commitments[i] = SideEffect { value: i + 1, counter: i as u32, diff --git a/noir-projects/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_tail.nr b/noir-projects/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_tail.nr index 1569820df9ab..8bb8196ca015 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_tail.nr @@ -8,7 +8,7 @@ use dep::types::{ side_effect::{SideEffect, SideEffectLinkedToNoteHash, Ordered} }, constants::{ - MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_READ_REQUESTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX }, @@ -19,8 +19,8 @@ use dep::types::{ struct PrivateKernelTailCircuitPrivateInputs { previous_kernel: PrivateKernelInnerData, - sorted_new_commitments: [SideEffect; MAX_NEW_COMMITMENTS_PER_TX], - sorted_new_commitments_indexes: [u32; MAX_NEW_COMMITMENTS_PER_TX], + sorted_new_commitments: [SideEffect; MAX_NEW_NOTE_HASHES_PER_TX], + sorted_new_commitments_indexes: [u32; MAX_NEW_NOTE_HASHES_PER_TX], read_commitment_hints: [Field; MAX_READ_REQUESTS_PER_TX], sorted_new_nullifiers: [SideEffectLinkedToNoteHash; MAX_NEW_NULLIFIERS_PER_TX], sorted_new_nullifiers_indexes: [u32; MAX_NEW_NULLIFIERS_PER_TX], @@ -136,7 +136,7 @@ impl PrivateKernelTailCircuitPrivateInputs { // 0-valued nullified_commitment is empty and will be ignored if nullified_commitment != 0 { assert( - hint_pos < MAX_NEW_COMMITMENTS_PER_TX as u64, "New nullifier is transient but hint is invalid" + hint_pos < MAX_NEW_NOTE_HASHES_PER_TX as u64, "New nullifier is transient but hint is invalid" ); let commitment = new_commitments[hint_pos]; assert_eq(nullified_commitment, commitment.value, "Hinted commitment does not match"); @@ -157,7 +157,7 @@ impl PrivateKernelTailCircuitPrivateInputs { let mut new_commitments_vec = BoundedVec::new(SideEffect::empty()); - for c_idx in 0..MAX_NEW_COMMITMENTS_PER_TX { + for c_idx in 0..MAX_NEW_NOTE_HASHES_PER_TX { if new_commitments[c_idx].value != 0 { new_commitments_vec.push(new_commitments[c_idx]); } @@ -182,7 +182,7 @@ impl PrivateKernelTailCircuitPrivateInputs { let first_nullifier = public_inputs.end.new_nullifiers.get(0); let mut unique_commitments = public_inputs.end.new_commitments.storage; - for c_idx in 0..MAX_NEW_COMMITMENTS_PER_TX { + for c_idx in 0..MAX_NEW_NOTE_HASHES_PER_TX { // Apply nonce to all non-zero/non-empty commitments // Nonce is the hash of the first (0th) nullifier and the commitment's index into new_commitments array let nonce = compute_commitment_nonce(first_nullifier.value, c_idx); @@ -228,7 +228,7 @@ mod tests { use dep::std::cmp::Eq; use crate::private_kernel_tail::PrivateKernelTailCircuitPrivateInputs; use dep::types::constants::{ - MAX_READ_REQUESTS_PER_TX, MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, + MAX_READ_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX, MAX_REVERTIBLE_COMMITMENTS_PER_TX }; use dep::types::{ @@ -255,7 +255,7 @@ mod tests { } } - pub fn get_new_commitments(self) -> [SideEffect; MAX_NEW_COMMITMENTS_PER_TX] { + pub fn get_new_commitments(self) -> [SideEffect; MAX_NEW_NOTE_HASHES_PER_TX] { self.previous_kernel.end.new_commitments.storage } @@ -263,7 +263,7 @@ mod tests { self.previous_kernel.end.new_nullifiers.storage } - pub fn get_unique_siloed_commitments(self) -> [SideEffect; MAX_NEW_COMMITMENTS_PER_TX] { + pub fn get_unique_siloed_commitments(self) -> [SideEffect; MAX_NEW_NOTE_HASHES_PER_TX] { self.compute_unique_siloed_commitments(self.previous_kernel.end.new_commitments.storage) } @@ -375,7 +375,7 @@ mod tests { #[test] unconstrained fn native_matching_some_read_requests_to_commitments_works() { let mut builder = PrivateKernelOrderingInputsBuilder::new(); - builder.append_transient_commitments(MAX_NEW_COMMITMENTS_PER_TX); + builder.append_transient_commitments(MAX_NEW_NOTE_HASHES_PER_TX); // prepare for the split: first MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX are added to end_non_revertible_accumulted_data // neeed to take the counter of the side effect at the given index because builder.previous_kernel.min_revertible_side_effect_counter = builder.previous_kernel.end.new_commitments.get(MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX).counter; @@ -543,7 +543,7 @@ mod tests { // The nullifier at index 1 is nullifying the commitment at index 0; builder.nullify_transient_commitment(1, 0); // Change the hint to be out of bounds. - builder.nullifier_commitment_hints[1] = MAX_NEW_COMMITMENTS_PER_TX; + builder.nullifier_commitment_hints[1] = MAX_NEW_NOTE_HASHES_PER_TX; builder.failed(); } diff --git a/noir-projects/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr index d6f86134c407..7c9840c01904 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -21,7 +21,7 @@ use dep::types::{ NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH, NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH, CONTRACT_SUBTREE_SIBLING_PATH_LENGTH, PUBLIC_DATA_TREE_HEIGHT, MAX_NEW_CONTRACTS_PER_TX, NOTE_HASH_SUBTREE_HEIGHT, CONTRACT_SUBTREE_HEIGHT, NUM_FIELDS_PER_SHA256, - MAX_NEW_COMMITMENTS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, NUM_ENCRYPTED_LOGS_HASHES_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, NUM_UNENCRYPTED_LOGS_HASHES_PER_TX, NULLIFIER_SUBTREE_HEIGHT, NULLIFIER_TREE_HEIGHT, PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH, PUBLIC_DATA_SUBTREE_HEIGHT, @@ -256,7 +256,7 @@ impl BaseRollupInputs { fn components_compute_kernel_calldata_hash(combined: CombinedAccumulatedData) -> [Field; NUM_FIELDS_PER_SHA256] { // Compute calldata hashes // Consist of - // MAX_NEW_COMMITMENTS_PER_TX fields for commitments + // MAX_NEW_NOTE_HASHES_PER_TX fields for commitments // MAX_NEW_NULLIFIERS_PER_TX fields for nullifiers // 32 public data update requests -> 64 fields // 2 l2 -> l1 messages -> 2 fields @@ -274,10 +274,10 @@ impl BaseRollupInputs { let mut offset = 0; - for j in 0..MAX_NEW_COMMITMENTS_PER_TX { + for j in 0..MAX_NEW_NOTE_HASHES_PER_TX { calldata_hash_inputs[offset + j] = new_commitments[j].value; } - offset += MAX_NEW_COMMITMENTS_PER_TX ; + offset += MAX_NEW_NOTE_HASHES_PER_TX ; for j in 0..MAX_NEW_NULLIFIERS_PER_TX { calldata_hash_inputs[offset + j] = new_nullifiers[j].value; @@ -493,7 +493,7 @@ fn validate_public_data_reads( #[test] fn consistent_not_hash_subtree_width() { assert_eq( - MAX_NEW_COMMITMENTS_PER_TX, 2.pow_32(NOTE_HASH_SUBTREE_HEIGHT), "note hash subtree width is incorrect" + MAX_NEW_NOTE_HASHES_PER_TX, 2.pow_32(NOTE_HASH_SUBTREE_HEIGHT), "note hash subtree width is incorrect" ); } @@ -501,7 +501,7 @@ global CALLDATA_HASH_INPUT_SIZE = 201; #[test] fn consistent_calldata_hash_input_size() { - let expected_size = MAX_NEW_COMMITMENTS_PER_TX + let expected_size = MAX_NEW_NOTE_HASHES_PER_TX + MAX_NEW_NULLIFIERS_PER_TX + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * 2 + MAX_NEW_L2_TO_L1_MSGS_PER_TX @@ -574,7 +574,7 @@ mod tests { constants::{ CONTRACT_SUBTREE_SIBLING_PATH_LENGTH, CONTRACT_TREE_HEIGHT, CONTRACT_SUBTREE_HEIGHT, ARCHIVE_HEIGHT, MAX_PUBLIC_DATA_READS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NEW_CONTRACTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NEW_CONTRACTS_PER_TX, NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH, NOTE_HASH_TREE_HEIGHT, NOTE_HASH_SUBTREE_HEIGHT, NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH, NULLIFIER_TREE_HEIGHT, NULLIFIER_SUBTREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT, PUBLIC_DATA_SUBTREE_HEIGHT, PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH, @@ -697,7 +697,7 @@ mod tests { struct BaseRollupInputsBuilder { kernel_data: PreviousKernelDataBuilder, - pre_existing_notes: [Field; MAX_NEW_COMMITMENTS_PER_TX], + pre_existing_notes: [Field; MAX_NEW_NOTE_HASHES_PER_TX], pre_existing_nullifiers: [NullifierLeafPreimage; MAX_NEW_NULLIFIERS_PER_TX], pre_existing_contracts: [Field; 2], pre_existing_public_data: [PublicDataTreeLeafPreimage; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], @@ -1028,7 +1028,7 @@ mod tests { } builder.kernel_data.end.new_commitments = new_commitments_vec; let mut expected_commitments_tree = NonEmptyMerkleTree::new( - [0; MAX_NEW_COMMITMENTS_PER_TX * 2], + [0; MAX_NEW_NOTE_HASHES_PER_TX * 2], [0; NOTE_HASH_TREE_HEIGHT], [0; NOTE_HASH_TREE_HEIGHT - NOTE_HASH_SUBTREE_HEIGHT - 1], [0; NOTE_HASH_SUBTREE_HEIGHT + 1] @@ -1037,19 +1037,19 @@ mod tests { let outputs = builder.execute(); let expected_start_note_hash_tree_snapshot = AppendOnlyTreeSnapshot { root: expected_commitments_tree.get_root(), - next_available_leaf_index: MAX_NEW_COMMITMENTS_PER_TX as u32 + next_available_leaf_index: MAX_NEW_NOTE_HASHES_PER_TX as u32 }; assert(outputs.start.note_hash_tree.eq(expected_start_note_hash_tree_snapshot)); for i in 0..new_commitments.len() { expected_commitments_tree.update_leaf( - (i as u64) + (MAX_NEW_COMMITMENTS_PER_TX as u64), + (i as u64) + (MAX_NEW_NOTE_HASHES_PER_TX as u64), new_commitments[i] ); } let expected_end_note_hash_tree_snapshot = AppendOnlyTreeSnapshot { root: expected_commitments_tree.get_root(), - next_available_leaf_index: (MAX_NEW_COMMITMENTS_PER_TX * 2) as u32 + next_available_leaf_index: (MAX_NEW_NOTE_HASHES_PER_TX * 2) as u32 }; assert(outputs.end.note_hash_tree.eq(expected_end_note_hash_tree_snapshot)); } diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr index 330e003ceb9b..6c948e8ca6fe 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr @@ -11,7 +11,7 @@ use crate::{ } }; use crate::constants::{ - MAX_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NEW_COMMITMENTS_PER_TX, + MAX_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_CONTRACTS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, NUM_FIELDS_PER_SHA256, @@ -31,7 +31,7 @@ struct CombinedAccumulatedData { read_requests: [SideEffect; MAX_READ_REQUESTS_PER_TX], nullifier_key_validation_requests: [NullifierKeyValidationRequestContext; MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], - new_commitments: [SideEffect; MAX_NEW_COMMITMENTS_PER_TX], + new_commitments: [SideEffect; MAX_NEW_NOTE_HASHES_PER_TX], new_nullifiers: [SideEffectLinkedToNoteHash; MAX_NEW_NULLIFIERS_PER_TX], private_call_stack: [CallRequest; MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr index 69fc1ccffbab..f89362374bb8 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr @@ -16,7 +16,7 @@ use crate::{ } }; use crate::constants::{ - MAX_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NEW_COMMITMENTS_PER_TX, + MAX_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_CONTRACTS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, NUM_FIELDS_PER_SHA256, @@ -36,7 +36,7 @@ struct CombinedAccumulatedDataBuilder { read_requests: BoundedVec, nullifier_key_validation_requests: BoundedVec, - new_commitments: BoundedVec, + new_commitments: BoundedVec, new_nullifiers: BoundedVec, private_call_stack: BoundedVec, @@ -156,7 +156,7 @@ impl CombinedAccumulatedDataBuilder { let mut non_revertible_builder: AccumulatedNonRevertibleDataBuilder = unsafe::zeroed(); let mut revertible_builder: AccumulatedRevertibleDataBuilder = unsafe::zeroed(); - for i in 0..MAX_NEW_COMMITMENTS_PER_TX { + for i in 0..MAX_NEW_NOTE_HASHES_PER_TX { let commitment = self.new_commitments.storage[i]; // TODO(fees) we shouldn't need to check is_empty here, // but we do because new_commitments is bounded to MAX_REVERTIBLE_COMMITMENTS_PER_TX diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr index 2a2fab60fb07..cec0e44dacc5 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr @@ -9,14 +9,14 @@ global RETURN_VALUES_LENGTH: Field = 4; * 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 + * - MAX_NEW_NOTE_HASHES_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_NOTE_HASHES_PER_TX ≥ MAX_NEW_COMMITMENTS_PER_CALL * MAX_NEW_NULLIFIERS_PER_TX ≥ MAX_NEW_NULLIFIERS_PER_CALL * */ @@ -34,7 +34,7 @@ global MAX_READ_REQUESTS_PER_CALL: Field = 32; global MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL: Field = 1; // "PER TRANSACTION" CONSTANTS -global MAX_NEW_COMMITMENTS_PER_TX: Field = 64; +global MAX_NEW_NOTE_HASHES_PER_TX: Field = 64; global MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX: Field = 8; global MAX_REVERTIBLE_COMMITMENTS_PER_TX: Field = 56; diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/tests/kernel_data_builder.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/tests/kernel_data_builder.nr index 7eb785d088e1..27e12108be08 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/tests/kernel_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/tests/kernel_data_builder.nr @@ -16,7 +16,7 @@ use crate::{ tests::{fixtures, testing_harness::build_tx_context}, transaction::tx_context::TxContext }; use crate::constants::{ - MAX_NEW_COMMITMENTS_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NUM_FIELDS_PER_SHA256, VK_TREE_HEIGHT }; @@ -122,7 +122,7 @@ impl PreviousKernelDataBuilder { pub fn append_new_commitments(&mut self, num_new_commitments: Field) { let mocked_value_offset = self.end.new_commitments.len() + 1; - for i in 0..MAX_NEW_COMMITMENTS_PER_TX { + for i in 0..MAX_NEW_NOTE_HASHES_PER_TX { if i as u64 < num_new_commitments as u64 { // The default value is its index + 1. self.end.new_commitments.push( diff --git a/noir/test_programs/execution_success/brillig_cow_regression/src/main.nr b/noir/test_programs/execution_success/brillig_cow_regression/src/main.nr index 974c17dfbc91..2bcbea156b17 100644 --- a/noir/test_programs/execution_success/brillig_cow_regression/src/main.nr +++ b/noir/test_programs/execution_success/brillig_cow_regression/src/main.nr @@ -1,6 +1,6 @@ // Tests a performance regression found in aztec-packages with brillig cow optimization -global MAX_NEW_COMMITMENTS_PER_TX: Field = 64; +global MAX_NEW_NOTE_HASHES_PER_TX: Field = 64; global MAX_NEW_NULLIFIERS_PER_TX: Field = 64; global MAX_NEW_L2_TO_L1_MSGS_PER_TX: Field = 2; global MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX: Field = 16; @@ -30,7 +30,7 @@ impl NewContractData { } struct DataToHash { - new_commitments: [Field; MAX_NEW_COMMITMENTS_PER_TX], + new_commitments: [Field; MAX_NEW_NOTE_HASHES_PER_TX], new_nullifiers: [Field; MAX_NEW_NULLIFIERS_PER_TX], public_data_update_requests: [PublicDataUpdateRequest; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], new_l2_to_l1_msgs: [Field; MAX_NEW_L2_TO_L1_MSGS_PER_TX], @@ -47,54 +47,54 @@ struct U256 { } impl U256 { - pub fn from_bytes32(bytes : [u8;32]) -> U256 { + pub fn from_bytes32(bytes: [u8; 32]) -> U256 { // We use addition rather than a bitwise OR as the bitshifts ensure that none of the bytes overlap each other. let high_0 = ((bytes[0] as u64) << 56) - + ((bytes[1] as u64) << 48) - + ((bytes[2] as u64) << 40) - + ((bytes[3] as u64) << 32) - + ((bytes[4] as u64) << 24) - + ((bytes[5] as u64) << 16) - + ((bytes[6] as u64) << 8) - + (bytes[7] as u64); - + + ((bytes[1] as u64) << 48) + + ((bytes[2] as u64) << 40) + + ((bytes[3] as u64) << 32) + + ((bytes[4] as u64) << 24) + + ((bytes[5] as u64) << 16) + + ((bytes[6] as u64) << 8) + + (bytes[7] as u64); + let high_1 = ((bytes[8] as u64) << 56) - + ((bytes[9] as u64) << 48) - + ((bytes[10] as u64) << 40) - + ((bytes[11] as u64) << 32) - + ((bytes[12] as u64) << 24) - + ((bytes[13] as u64) << 16) - + ((bytes[14] as u64) << 8) - + (bytes[15] as u64); - + + ((bytes[9] as u64) << 48) + + ((bytes[10] as u64) << 40) + + ((bytes[11] as u64) << 32) + + ((bytes[12] as u64) << 24) + + ((bytes[13] as u64) << 16) + + ((bytes[14] as u64) << 8) + + (bytes[15] as u64); + let low_0 = ((bytes[16] as u64) << 56) - + ((bytes[17] as u64) << 48) - + ((bytes[18] as u64) << 40) - + ((bytes[19] as u64) << 32) - + ((bytes[20] as u64) << 24) - + ((bytes[21] as u64) << 16) - + ((bytes[22] as u64) << 8) - + (bytes[23] as u64); - + + ((bytes[17] as u64) << 48) + + ((bytes[18] as u64) << 40) + + ((bytes[19] as u64) << 32) + + ((bytes[20] as u64) << 24) + + ((bytes[21] as u64) << 16) + + ((bytes[22] as u64) << 8) + + (bytes[23] as u64); + let low_1 = ((bytes[24] as u64) << 56) - + ((bytes[25] as u64) << 48) - + ((bytes[26] as u64) << 40) - + ((bytes[27] as u64) << 32) - + ((bytes[28] as u64) << 24) - + ((bytes[29] as u64) << 16) - + ((bytes[30] as u64) << 8) - + (bytes[31] as u64); - - U256{inner : [high_0, high_1, low_0, low_1]} + + ((bytes[25] as u64) << 48) + + ((bytes[26] as u64) << 40) + + ((bytes[27] as u64) << 32) + + ((bytes[28] as u64) << 24) + + ((bytes[29] as u64) << 16) + + ((bytes[30] as u64) << 8) + + (bytes[31] as u64); + + U256 { inner: [high_0, high_1, low_0, low_1] } } - pub fn to_u128_limbs(self) -> [Field;2] { + pub fn to_u128_limbs(self) -> [Field; 2] { let two_pow_64 = 2.pow_32(64); let high = (self.inner[0] as Field) * two_pow_64 + self.inner[1] as Field; let low = (self.inner[2] as Field) * two_pow_64 + self.inner[3] as Field; - - [high,low] + + [high, low] } } @@ -110,10 +110,10 @@ unconstrained fn main(kernel_data: DataToHash) -> pub [Field; NUM_FIELDS_PER_SHA let mut offset = 0; - for j in 0..MAX_NEW_COMMITMENTS_PER_TX { + for j in 0..MAX_NEW_NOTE_HASHES_PER_TX { calldata_hash_inputs[offset + j] = new_commitments[j]; } - offset += MAX_NEW_COMMITMENTS_PER_TX ; + offset += MAX_NEW_NOTE_HASHES_PER_TX ; for j in 0..MAX_NEW_NULLIFIERS_PER_TX { calldata_hash_inputs[offset + j] = new_nullifiers[j]; diff --git a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts index 46e31cac9245..5562b919cd47 100644 --- a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts +++ b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts @@ -369,8 +369,6 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch await expect(store.getContractData(block.body.txEffects[0].contractData[0].contractAddress)).resolves.toEqual( block.body.txEffects[0].contractData[0], ); - - expect(block.body.txEffects[0].contractData[1]).toBe(undefined); }); it('returns undefined if contract data is not found', async () => { diff --git a/yarn-project/circuit-types/src/body.ts b/yarn-project/circuit-types/src/body.ts index b82cf11e7f64..985ed87729eb 100644 --- a/yarn-project/circuit-types/src/body.ts +++ b/yarn-project/circuit-types/src/body.ts @@ -1,6 +1,6 @@ import { ContractData, L2BlockL2Logs, PublicDataWrite, TxEffect } from '@aztec/circuit-types'; import { - MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_CONTRACTS_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, @@ -8,7 +8,7 @@ import { } from '@aztec/circuits.js'; import { sha256 } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; -import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; +import { BufferReader, Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; export class Body { constructor(public l1ToL2Messages: Fr[], public txEffects: TxEffect[]) {} @@ -81,19 +81,20 @@ export class Body { const numberOfTxsIncludingEmpty = newNullifiers.length / MAX_NEW_NULLIFIERS_PER_TX; for (let i = 0; i < numberOfTxsIncludingEmpty; i += 1) { + // TODO(benesjan): this should use TxEffect.fromBuffer txEffects.push( new TxEffect( - newNoteHashes.slice(i * MAX_NEW_COMMITMENTS_PER_TX, (i + 1) * MAX_NEW_COMMITMENTS_PER_TX), - newNullifiers.slice(i * MAX_NEW_NULLIFIERS_PER_TX, (i + 1) * MAX_NEW_NULLIFIERS_PER_TX), - newL2ToL1Msgs.slice(i * MAX_NEW_L2_TO_L1_MSGS_PER_TX, (i + 1) * MAX_NEW_L2_TO_L1_MSGS_PER_TX), + newNoteHashes.slice(i * MAX_NEW_NOTE_HASHES_PER_TX, (i + 1) * MAX_NEW_NOTE_HASHES_PER_TX) as Tuple, + newNullifiers.slice(i * MAX_NEW_NULLIFIERS_PER_TX, (i + 1) * MAX_NEW_NULLIFIERS_PER_TX) as Tuple, + newL2ToL1Msgs.slice(i * MAX_NEW_L2_TO_L1_MSGS_PER_TX, (i + 1) * MAX_NEW_L2_TO_L1_MSGS_PER_TX) as Tuple, newPublicDataWrites.slice( i * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, (i + 1) * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - ), - newContracts.slice(i * MAX_NEW_CONTRACTS_PER_TX, (i + 1) * MAX_NEW_CONTRACTS_PER_TX), - newContractData.slice(i * MAX_NEW_CONTRACTS_PER_TX, (i + 1) * MAX_NEW_CONTRACTS_PER_TX), - newEncryptedLogs!.txLogs[i], - newUnencryptedLogs!.txLogs[i], + ) as Tuple, + newContracts.slice(i * MAX_NEW_CONTRACTS_PER_TX, (i + 1) * MAX_NEW_CONTRACTS_PER_TX) as Tuple, + newContractData.slice(i * MAX_NEW_CONTRACTS_PER_TX, (i + 1) * MAX_NEW_CONTRACTS_PER_TX) as Tuple, + newEncryptedLogs.txLogs[i], + newUnencryptedLogs.txLogs[i], ), ); } diff --git a/yarn-project/circuit-types/src/l2_block.ts b/yarn-project/circuit-types/src/l2_block.ts index 93e115f9e282..9d83c056619b 100644 --- a/yarn-project/circuit-types/src/l2_block.ts +++ b/yarn-project/circuit-types/src/l2_block.ts @@ -2,7 +2,7 @@ import { Body, ContractData, L2Tx, LogType, PublicDataWrite, TxEffect, TxHash, T import { AppendOnlyTreeSnapshot, Header, - MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_CONTRACTS_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, @@ -16,6 +16,7 @@ import { sha256 } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; +import { makeTuple } from '@aztec/foundation/array'; /** * The data that makes up the rollup proof, with encoder decoder functions. @@ -127,12 +128,12 @@ export class L2Block { const txEffects = [...new Array(txsPerBlock)].map( _ => new TxEffect( - times(MAX_NEW_COMMITMENTS_PER_TX, Fr.random), - times(MAX_NEW_NULLIFIERS_PER_TX, Fr.random), - times(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.random), - times(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite.random), - times(MAX_NEW_CONTRACTS_PER_TX, Fr.random), - times(MAX_NEW_CONTRACTS_PER_TX, ContractData.random), + makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, Fr.random), + makeTuple(MAX_NEW_NULLIFIERS_PER_TX, Fr.random), + makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.random), + makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite.random), + makeTuple(MAX_NEW_CONTRACTS_PER_TX, Fr.random), + makeTuple(MAX_NEW_CONTRACTS_PER_TX, ContractData.random), TxL2Logs.random(numPrivateCallsPerTx, numEncryptedLogsPerCall, LogType.ENCRYPTED), TxL2Logs.random(numPublicCallsPerTx, numUnencryptedLogsPerCall, LogType.UNENCRYPTED), ), diff --git a/yarn-project/circuit-types/src/l2_tx.ts b/yarn-project/circuit-types/src/l2_tx.ts index 593f85d7b816..8df7457de44f 100644 --- a/yarn-project/circuit-types/src/l2_tx.ts +++ b/yarn-project/circuit-types/src/l2_tx.ts @@ -1,5 +1,5 @@ import { - MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_CONTRACTS_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, @@ -121,7 +121,7 @@ export class L2Tx { static random() { const rand = (min: number, max: number) => Math.floor(Math.random() * max) + min; return new L2Tx( - times(rand(0, MAX_NEW_COMMITMENTS_PER_TX), Fr.random), + times(rand(0, MAX_NEW_NOTE_HASHES_PER_TX), Fr.random), times(rand(1, MAX_NEW_NULLIFIERS_PER_TX), Fr.random), times(rand(0, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX), PublicDataWrite.random), times(rand(0, MAX_NEW_L2_TO_L1_MSGS_PER_TX), Fr.random), diff --git a/yarn-project/circuit-types/src/tx_effect.ts b/yarn-project/circuit-types/src/tx_effect.ts index 89a18aa25a8e..77b495526733 100644 --- a/yarn-project/circuit-types/src/tx_effect.ts +++ b/yarn-project/circuit-types/src/tx_effect.ts @@ -1,43 +1,47 @@ import { ContractData, PublicDataWrite, TxL2Logs } from '@aztec/circuit-types'; -import { Fr, MAX_NEW_COMMITMENTS_PER_TX } from '@aztec/circuits.js'; +import { + Fr, + MAX_NEW_CONTRACTS_PER_TX, + MAX_NEW_L2_TO_L1_MSGS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, + MAX_NEW_NULLIFIERS_PER_TX, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, +} from '@aztec/circuits.js'; import { sha256 } from '@aztec/foundation/crypto'; +import { Tuple } from '@aztec/foundation/serialize'; export class TxEffect { constructor( /** - * The commitments to be inserted into the note hash tree. + * The note hashes to be inserted into the note hash tree. */ - public newNoteHashes: Fr[], + public newNoteHashes: Tuple, /** * The nullifiers to be inserted into the nullifier tree. */ - public newNullifiers: Fr[], + public newNullifiers: Tuple, /** * The L2 to L1 messages to be inserted into the messagebox on L1. */ - public newL2ToL1Msgs: Fr[], + public newL2ToL1Msgs: Tuple, /** * The public data writes to be inserted into the public data tree. */ - public newPublicDataWrites: PublicDataWrite[], + public newPublicDataWrites: Tuple, /** * The leaves of the new contract data that will be inserted into the contracts tree. */ - public contractLeaves: Fr[], + public contractLeaves: Tuple, /** - * The the contracts data of the new contracts. + * The contract data of the new contracts. */ - public contractData: ContractData[], + public contractData: Tuple, /** * The logs of the txEffect */ public encryptedLogs: TxL2Logs, public unencryptedLogs: TxL2Logs, - ) { - if (newNoteHashes.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}.`); - } - } + ) {} hash() { const noteHashesBuffer = Buffer.concat(this.newNoteHashes.map(x => x.toBuffer())); @@ -47,11 +51,8 @@ export class TxEffect { const encryptedLogsHashKernel0 = this.encryptedLogs.hash(); const unencryptedLogsHashKernel0 = this.unencryptedLogs.hash(); - if ( - (this.contractLeaves.length > 1 && !this.contractLeaves[1].isZero()) || - (this.contractData.length > 1 && !this.contractData[1].isEmpty()) - ) { - throw new Error('We only support max one new contract per tx'); + if (MAX_NEW_CONTRACTS_PER_TX !== 1) { + throw new Error('Only one contract per transaction is supported for now.'); } const inputValue = Buffer.concat([ diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 317ea220c432..0bbc6214601e 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -11,7 +11,7 @@ export const MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL = 16; export const MAX_PUBLIC_DATA_READS_PER_CALL = 16; export const MAX_READ_REQUESTS_PER_CALL = 32; export const MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL = 1; -export const MAX_NEW_COMMITMENTS_PER_TX = 64; +export const MAX_NEW_NOTE_HASHES_PER_TX = 64; export const MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX = 8; export const MAX_REVERTIBLE_COMMITMENTS_PER_TX = 56; export const MAX_NEW_NULLIFIERS_PER_TX = 64; 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 811685523c08..2e1b49e29ba8 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 @@ -4,7 +4,7 @@ import { Fr } from '@aztec/foundation/fields'; import { BufferReader, Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; import { - MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_CONTRACTS_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_NEW_L2_TO_L1_MSGS_PER_TX, @@ -163,7 +163,7 @@ export class CombinedAccumulatedData { /** * The new commitments made in this transaction. */ - public newCommitments: Tuple, + public newCommitments: Tuple, /** * The new nullifiers made in this transaction. */ @@ -245,7 +245,7 @@ export class CombinedAccumulatedData { return new CombinedAccumulatedData( reader.readArray(MAX_READ_REQUESTS_PER_TX, SideEffect), reader.readArray(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, NullifierKeyValidationRequestContext), - reader.readArray(MAX_NEW_COMMITMENTS_PER_TX, SideEffect), + reader.readArray(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect), reader.readArray(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash), reader.readArray(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, CallRequest), reader.readArray(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest), @@ -273,7 +273,7 @@ export class CombinedAccumulatedData { return new CombinedAccumulatedData( makeTuple(MAX_READ_REQUESTS_PER_TX, SideEffect.empty), makeTuple(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, NullifierKeyValidationRequestContext.empty), - makeTuple(MAX_NEW_COMMITMENTS_PER_TX, SideEffect.empty), + makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.empty), makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.empty), makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, CallRequest.empty), makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.empty), @@ -301,7 +301,7 @@ export class CombinedAccumulatedData { const newCommitments = padArrayEnd( [...nonRevertible.newCommitments, ...revertible.newCommitments].filter(x => !x.isEmpty()), SideEffect.empty(), - MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, ); const newNullifiers = padArrayEnd( diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_private_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_private_inputs.ts index a3e2a3edc7bd..e7de614fa31c 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_private_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_private_inputs.ts @@ -1,7 +1,7 @@ import { BufferReader, Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; import { - MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_READ_REQUESTS_PER_TX, @@ -23,11 +23,11 @@ export class PrivateKernelTailCircuitPrivateInputs { /** * The sorted new commitments. */ - public sortedNewCommitments: Tuple, + public sortedNewCommitments: Tuple, /** * The sorted new commitments indexes. Maps original to sorted. */ - public sortedNewCommitmentsIndexes: Tuple, + public sortedNewCommitmentsIndexes: Tuple, /** * Contains hints for the transient read requests to localize corresponding commitments. */ @@ -76,8 +76,8 @@ export class PrivateKernelTailCircuitPrivateInputs { const reader = BufferReader.asReader(buffer); return new PrivateKernelTailCircuitPrivateInputs( reader.readObject(PrivateKernelInnerData), - reader.readArray(MAX_NEW_COMMITMENTS_PER_TX, SideEffect), - reader.readNumbers(MAX_NEW_COMMITMENTS_PER_TX), + reader.readArray(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect), + reader.readNumbers(MAX_NEW_NOTE_HASHES_PER_TX), reader.readArray(MAX_READ_REQUESTS_PER_TX, Fr), reader.readArray(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash), reader.readNumbers(MAX_NEW_NULLIFIERS_PER_TX), diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 3bd6887749b8..9b0cece6c48e 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -35,7 +35,7 @@ import { L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, L2ToL1Message, MAX_NEW_COMMITMENTS_PER_CALL, - MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_CONTRACTS_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_NEW_L2_TO_L1_MSGS_PER_TX, @@ -262,7 +262,7 @@ export function makeAccumulatedData(seed = 1, full = false): CombinedAccumulated makeNullifierKeyValidationRequestContext, seed + 0x100, ), - tupleGenerator(MAX_NEW_COMMITMENTS_PER_TX, sideEffectFromNumber, seed + 0x120), + tupleGenerator(MAX_NEW_NOTE_HASHES_PER_TX, sideEffectFromNumber, seed + 0x120), tupleGenerator(MAX_NEW_NULLIFIERS_PER_TX, sideEffectLinkedFromNumber, seed + 0x200), tupleGenerator(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, makeCallRequest, seed + 0x400), tupleGenerator(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, makeCallRequest, seed + 0x500), diff --git a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts index 218fe5adbfc4..ddb5a411dfaf 100644 --- a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts @@ -25,7 +25,7 @@ import { GrumpkinScalar, Header, L2ToL1Message, - MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_CONTRACTS_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, @@ -879,7 +879,7 @@ export function mapCombinedAccumulatedDataFromNoir( MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, mapNullifierKeyValidationRequestContextFromNoir, ), - mapTupleFromNoir(combinedAccumulatedData.new_commitments, MAX_NEW_COMMITMENTS_PER_TX, mapSideEffectFromNoir), + mapTupleFromNoir(combinedAccumulatedData.new_commitments, MAX_NEW_NOTE_HASHES_PER_TX, mapSideEffectFromNoir), mapTupleFromNoir(combinedAccumulatedData.new_nullifiers, MAX_NEW_NULLIFIERS_PER_TX, mapSideEffectLinkedFromNoir), mapTupleFromNoir( combinedAccumulatedData.private_call_stack, diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts index c52785c4743b..935080c6e35f 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts @@ -3,7 +3,7 @@ import { FunctionData, FunctionSelector, MAX_NEW_COMMITMENTS_PER_CALL, - MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_READ_REQUESTS_PER_CALL, MAX_REVERTIBLE_COMMITMENTS_PER_TX, MembershipWitness, @@ -83,7 +83,7 @@ describe('Kernel Prover', () => { const createProofOutput = (newNoteIndices: number[]) => { const publicInputs = PrivateKernelInnerCircuitPublicInputs.empty(); - const commitments = makeTuple(MAX_NEW_COMMITMENTS_PER_TX, () => SideEffect.empty()); + const commitments = makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, () => SideEffect.empty()); for (let i = 0; i < newNoteIndices.length; i++) { commitments[i] = new SideEffect(generateFakeSiloedCommitment(notesAndSlots[newNoteIndices[i]]), Fr.ZERO); } diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts index bf5d2c72ade9..c9996541622f 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -3,7 +3,7 @@ import { CallRequest, Fr, GrumpkinScalar, - MAX_NEW_COMMITMENTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, @@ -177,7 +177,7 @@ export class KernelProver { const [sortedCommitments, sortedCommitmentsIndexes] = this.sortSideEffects< SideEffect, - typeof MAX_NEW_COMMITMENTS_PER_TX + typeof MAX_NEW_NOTE_HASHES_PER_TX >(output.publicInputs.end.newCommitments); const [sortedNullifiers, sortedNullifiersIndexes] = this.sortSideEffects< @@ -328,7 +328,7 @@ export class KernelProver { */ private getReadRequestHints( readRequests: Tuple, - commitments: Tuple, + commitments: Tuple, ): Tuple { const hints = makeTuple(MAX_READ_REQUESTS_PER_TX, Fr.zero); for (let i = 0; i < MAX_READ_REQUESTS_PER_TX && !readRequests[i].isEmpty(); i++) { @@ -357,7 +357,7 @@ export class KernelProver { */ private getNullifierHints( nullifiedCommitments: Tuple, - commitments: Tuple, + commitments: Tuple, ): Tuple { const hints = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, Fr.zero); const alreadyUsed = new Set(); diff --git a/yarn-project/pxe/src/note_processor/note_processor.test.ts b/yarn-project/pxe/src/note_processor/note_processor.test.ts index 6c66111c2b08..87c08b286a90 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.test.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.test.ts @@ -11,7 +11,7 @@ import { Note, TxL2Logs, } from '@aztec/circuit-types'; -import { Fr, MAX_NEW_COMMITMENTS_PER_TX } from '@aztec/circuits.js'; +import { Fr, MAX_NEW_NOTE_HASHES_PER_TX } from '@aztec/circuits.js'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; import { pedersenHash } from '@aztec/foundation/crypto'; import { Point } from '@aztec/foundation/fields'; @@ -26,6 +26,7 @@ import { PxeDatabase } from '../database/index.js'; import { KVPxeDatabase } from '../database/kv_pxe_database.js'; import { NoteDao } from '../database/note_dao.js'; import { NoteProcessor } from './note_processor.js'; +import { Tuple } from '@aztec/foundation/serialize'; const TXS_PER_BLOCK = 4; @@ -39,7 +40,7 @@ describe('Note Processor', () => { let keyStore: MockProxy; let simulator: MockProxy; const firstBlockNum = 123; - const numCommitmentsPerBlock = TXS_PER_BLOCK * MAX_NEW_COMMITMENTS_PER_TX; + const numCommitmentsPerBlock = TXS_PER_BLOCK * MAX_NEW_NOTE_HASHES_PER_TX; const firstBlockDataStartIndex = (firstBlockNum - 1) * numCommitmentsPerBlock; const firstBlockDataEndIndex = firstBlockNum * numCommitmentsPerBlock; @@ -53,12 +54,12 @@ describe('Note Processor', () => { let usedOwnedNote = 0; for (let i = 0; i < TXS_PER_BLOCK; ++i) { const ownedDataIndices = ownedData[i] || []; - if (ownedDataIndices.some(index => index >= MAX_NEW_COMMITMENTS_PER_TX)) { - throw new Error(`Data index should be less than ${MAX_NEW_COMMITMENTS_PER_TX}.`); + if (ownedDataIndices.some(index => index >= MAX_NEW_NOTE_HASHES_PER_TX)) { + throw new Error(`Data index should be less than ${MAX_NEW_NOTE_HASHES_PER_TX}.`); } const logs: FunctionL2Logs[] = []; - for (let noteIndex = 0; noteIndex < MAX_NEW_COMMITMENTS_PER_TX; ++noteIndex) { + for (let noteIndex = 0; noteIndex < MAX_NEW_NOTE_HASHES_PER_TX; ++noteIndex) { const isOwner = ownedDataIndices.includes(noteIndex); const publicKey = isOwner ? owner.getPublicKey() : Point.random(); const note = (isOwner && ownedNotes[usedOwnedNote]) || L1NotePayload.random(); @@ -108,7 +109,7 @@ describe('Note Processor', () => { for (let i = 0; i < TXS_PER_BLOCK; i++) { block.body.txEffects[i].newNoteHashes = newNotes .map(n => computeMockNoteHash(n.note)) - .slice(i * MAX_NEW_COMMITMENTS_PER_TX, (i + 1) * MAX_NEW_COMMITMENTS_PER_TX); + .slice(i * MAX_NEW_NOTE_HASHES_PER_TX, (i + 1) * MAX_NEW_NOTE_HASHES_PER_TX) as Tuple; } const randomBlockContext = new L2BlockContext(block); @@ -183,17 +184,17 @@ describe('Note Processor', () => { expect.objectContaining({ ...ownedL1NotePayloads[0], // Index 1 log in the 2nd tx. - index: BigInt(thisBlockDataStartIndex + MAX_NEW_COMMITMENTS_PER_TX * (2 - 1) + 1), + index: BigInt(thisBlockDataStartIndex + MAX_NEW_NOTE_HASHES_PER_TX * (2 - 1) + 1), }), expect.objectContaining({ ...ownedL1NotePayloads[1], // Index 0 log in the 4th tx. - index: BigInt(thisBlockDataStartIndex + MAX_NEW_COMMITMENTS_PER_TX * (4 - 1) + 0), + index: BigInt(thisBlockDataStartIndex + MAX_NEW_NOTE_HASHES_PER_TX * (4 - 1) + 0), }), expect.objectContaining({ ...ownedL1NotePayloads[2], // Index 2 log in the 4th tx. - index: BigInt(thisBlockDataStartIndex + MAX_NEW_COMMITMENTS_PER_TX * (4 - 1) + 2), + index: BigInt(thisBlockDataStartIndex + MAX_NEW_NOTE_HASHES_PER_TX * (4 - 1) + 2), }), ]); }, 30_000); diff --git a/yarn-project/pxe/src/note_processor/note_processor.ts b/yarn-project/pxe/src/note_processor/note_processor.ts index 31ce051d2ac5..b64e60cbfc28 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.ts @@ -7,7 +7,7 @@ import { L2BlockL2Logs, } from '@aztec/circuit-types'; import { NoteProcessorStats } from '@aztec/circuit-types/stats'; -import { MAX_NEW_COMMITMENTS_PER_TX, PublicKey } from '@aztec/circuits.js'; +import { MAX_NEW_NOTE_HASHES_PER_TX, PublicKey } from '@aztec/circuits.js'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; import { Fr } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; @@ -123,7 +123,7 @@ export class NoteProcessor { for (let indexOfTxInABlock = 0; indexOfTxInABlock < txLogs.length; ++indexOfTxInABlock) { this.stats.txs++; const dataStartIndexForTx = - dataEndIndexForBlock - (txLogs.length - indexOfTxInABlock) * MAX_NEW_COMMITMENTS_PER_TX; + dataEndIndexForBlock - (txLogs.length - indexOfTxInABlock) * MAX_NEW_NOTE_HASHES_PER_TX; const newCommitments = block.body.txEffects[indexOfTxInABlock].newNoteHashes; // Note: Each tx generates a `TxL2Logs` object and for this reason we can rely on its index corresponding // to the index of a tx in a block. 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 6196bc528798..d490a08ab71a 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 @@ -19,12 +19,15 @@ import { Fr, GlobalVariables, Header, + MAX_NEW_CONTRACTS_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_REVERTIBLE_COMMITMENTS_PER_TX, MAX_REVERTIBLE_NULLIFIERS_PER_TX, MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, @@ -39,7 +42,7 @@ import { RootRollupPublicInputs, SideEffect, SideEffectLinkedToNoteHash, - StateReference, + StateReference } from '@aztec/circuits.js'; import { fr, @@ -55,12 +58,12 @@ import { import { makeTuple, range } from '@aztec/foundation/array'; import { toBufferBE } from '@aztec/foundation/bigint-buffer'; import { times } from '@aztec/foundation/collection'; -import { to2Fields } from '@aztec/foundation/serialize'; +import { Tuple, to2Fields } from '@aztec/foundation/serialize'; import { openTmpStore } from '@aztec/kv-store/utils'; import { MerkleTreeOperations, MerkleTrees } from '@aztec/world-state'; import { MockProxy, mock } from 'jest-mock-extended'; -import { type MemDown, default as memdown } from 'memdown'; +import { default as memdown, type MemDown } from 'memdown'; import { VerificationKeys, getVerificationKeys } from '../mocks/verification_keys.js'; import { EmptyRollupProver } from '../prover/empty.js'; @@ -231,12 +234,12 @@ describe('sequencer/solo_block_builder', () => { const txEffects: TxEffect[] = txs.map( tx => new TxEffect( - tx.data.combinedData.newCommitments.map((c: SideEffect) => c.value), - tx.data.combinedData.newNullifiers.map((n: SideEffectLinkedToNoteHash) => n.value), + tx.data.combinedData.newCommitments.map((c: SideEffect) => c.value) as Tuple, + tx.data.combinedData.newNullifiers.map((n: SideEffectLinkedToNoteHash) => n.value) as Tuple, tx.data.combinedData.newL2ToL1Msgs, - tx.data.combinedData.publicDataUpdateRequests.map(t => new PublicDataWrite(t.leafSlot, t.newValue)), - tx.data.combinedData.newContracts.map(cd => cd.hash()), - tx.data.combinedData.newContracts.map(cd => new ContractData(cd.contractAddress, cd.portalContractAddress)), + tx.data.combinedData.publicDataUpdateRequests.map(t => new PublicDataWrite(t.leafSlot, t.newValue)) as Tuple, + tx.data.combinedData.newContracts.map(cd => cd.hash()) as Tuple, + tx.data.combinedData.newContracts.map(cd => new ContractData(cd.contractAddress, cd.portalContractAddress)) as Tuple, tx.encryptedLogs || new TxL2Logs([]), tx.unencryptedLogs || new TxL2Logs([]), ), 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 903b51a40d69..17f86272f4a1 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 @@ -10,6 +10,8 @@ import { GlobalVariables, L1_TO_L2_MSG_SUBTREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, + MAX_NEW_CONTRACTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, @@ -103,13 +105,14 @@ export class SoloBlockBuilder implements BlockBuilder { // Collect all new nullifiers, commitments, and contracts from all txs in this block const txEffects: TxEffect[] = txs.map( tx => + // TODO(benesjan): Combined data should most likely contain the tx effect directly new TxEffect( - tx.data.combinedData.newCommitments.map((c: SideEffect) => c.value), - tx.data.combinedData.newNullifiers.map((n: SideEffectLinkedToNoteHash) => n.value), + tx.data.combinedData.newCommitments.map((c: SideEffect) => c.value) as Tuple, + tx.data.combinedData.newNullifiers.map((n: SideEffectLinkedToNoteHash) => n.value) as Tuple, tx.data.combinedData.newL2ToL1Msgs, - tx.data.combinedData.publicDataUpdateRequests.map(t => new PublicDataWrite(t.leafSlot, t.newValue)), - tx.data.combinedData.newContracts.map(cd => cd.hash()), - tx.data.combinedData.newContracts.map(cd => new ContractData(cd.contractAddress, cd.portalContractAddress)), + tx.data.combinedData.publicDataUpdateRequests.map(t => new PublicDataWrite(t.leafSlot, t.newValue)) as Tuple, + tx.data.combinedData.newContracts.map(cd => cd.hash()) as Tuple, + tx.data.combinedData.newContracts.map(cd => new ContractData(cd.contractAddress, cd.portalContractAddress)) as Tuple, tx.encryptedLogs || new TxL2Logs([]), tx.unencryptedLogs || new TxL2Logs([]), ), diff --git a/yellow-paper/docs/constants.md b/yellow-paper/docs/constants.md index 496eb93b1c58..0e1789ae22c4 100644 --- a/yellow-paper/docs/constants.md +++ b/yellow-paper/docs/constants.md @@ -56,7 +56,7 @@ The statically-sized nature the kernel & rollup circuits will restrict the quant | Name | Value | Description | |---|---|---| -| `MAX_NEW_COMMITMENTS_PER_TX` | 128 | +| `MAX_NEW_NOTE_HASHES_PER_TX` | 128 | | `MAX_NEW_NULLIFIERS_PER_TX` | 128 | | `MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX` | 32 | | `MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX` | 32 |