diff --git a/cspell.json b/cspell.json index 8b9e5d15e7e..3059335afc2 100644 --- a/cspell.json +++ b/cspell.json @@ -55,6 +55,7 @@ "comlink", "composability", "composablity", + "comptime", "concat", "cond", "counterparty", @@ -245,6 +246,7 @@ "stdlib", "struct", "structs", + "subarray", "subarrays", "subdir", "sublabel", @@ -276,6 +278,8 @@ "unzipit", "updateable", "upperfirst", + "unshift", + "unshifted", "usecase", "usecases", "utxo", @@ -319,7 +323,5 @@ "lib", "*.cmake" ], - "flagWords": [ - "anonymous" - ] + "flagWords": ["anonymous"] } diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/base/mod.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/base/mod.nr index 1a89c4f17dd..60bd65e1926 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/base/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/base/mod.nr @@ -1 +1 @@ -mod base_parity_inputs; +pub mod base_parity_inputs; diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/parity_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/parity_public_inputs.nr index ae7c1263c4a..7b0887cd827 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/parity_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/parity_public_inputs.nr @@ -1,9 +1,9 @@ use dep::types::traits::{Deserialize, Empty, Serialize}; pub struct ParityPublicInputs { - sha_root: Field, - converted_root: Field, - vk_tree_root: Field, + pub sha_root: Field, + pub converted_root: Field, + pub vk_tree_root: Field, } impl Empty for ParityPublicInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/mod.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/mod.nr index d8e5a1853bb..27d2f9664bd 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/mod.nr @@ -1,3 +1,3 @@ -mod root_parity_input; -mod root_parity_inputs; -mod root_rollup_parity_input; +pub(crate) mod root_parity_input; +pub mod root_parity_inputs; +pub mod root_rollup_parity_input; diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_input.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_input.nr index d334b5348c1..2d0ce595218 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_input.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_input.nr @@ -11,10 +11,10 @@ use dep::types::{ }; pub struct RootParityInput { - proof: RecursiveProof, - verification_key: HonkVerificationKey, - vk_path: [Field; VK_TREE_HEIGHT], - public_inputs: ParityPublicInputs, + pub proof: RecursiveProof, + pub verification_key: HonkVerificationKey, + pub vk_path: [Field; VK_TREE_HEIGHT], + pub public_inputs: ParityPublicInputs, } impl Empty for RootParityInput { @@ -41,7 +41,7 @@ impl Verifiable for RootParityInput { } impl RootParityInput { - fn validate_in_vk_tree(self) { + pub fn validate_in_vk_tree(self) { self.verification_key.check_hash(); assert_check_membership( self.verification_key.hash, diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr index cbb08eb2fe9..b70561863b8 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr @@ -11,10 +11,10 @@ use dep::types::{ }; pub struct RootRollupParityInput { - proof: NestedRecursiveProof, - verification_key: HonkVerificationKey, - vk_path: [Field; VK_TREE_HEIGHT], - public_inputs: ParityPublicInputs, + pub proof: NestedRecursiveProof, + pub verification_key: HonkVerificationKey, + pub vk_path: [Field; VK_TREE_HEIGHT], + pub public_inputs: ParityPublicInputs, } impl Empty for RootRollupParityInput { @@ -41,7 +41,7 @@ impl Verifiable for RootRollupParityInput { } impl RootRollupParityInput { - fn validate_in_vk_tree(self) { + pub fn validate_in_vk_tree(self) { self.verification_key.check_hash(); assert_check_membership( self.verification_key.hash, diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/utils/mod.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/utils/mod.nr index a3a41d46166..e196f93af65 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/utils/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/utils/mod.nr @@ -1 +1 @@ -mod sha256_merkle_tree; +pub mod sha256_merkle_tree; diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/utils/sha256_merkle_tree.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/utils/sha256_merkle_tree.nr index 0d908e43e16..993adec8282 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/utils/sha256_merkle_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/utils/sha256_merkle_tree.nr @@ -30,7 +30,7 @@ impl Sha256MerkleTree { Sha256MerkleTree { leaves, nodes } } - fn get_root(self) -> Field { + pub fn get_root(self) -> Field { self.nodes[N - 2] } } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator.nr index fea9effd5ce..0a5021808b2 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator.nr @@ -1,12 +1,12 @@ mod previous_kernel_validator_hints; -use crate::components::previous_kernel_validator::previous_kernel_validator_hints::{ - generate_previous_kernel_validator_hints, PreviousKernelValidatorHints, -}; use dep::types::{ abis::private_kernel_data::PrivateKernelData, address::AztecAddress, traits::is_empty, utils::arrays::array_length, }; +use previous_kernel_validator_hints::{ + generate_previous_kernel_validator_hints, PreviousKernelValidatorHints, +}; pub struct PreviousKernelValidator { previous_kernel: PrivateKernelData, diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator/previous_kernel_validator_hints.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator/previous_kernel_validator_hints.nr index 23927a82882..8726775d615 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator/previous_kernel_validator_hints.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator/previous_kernel_validator_hints.nr @@ -7,7 +7,7 @@ use dep::types::{ }; pub struct PreviousKernelValidatorHints { - note_hash_indexes_for_nullifiers: [u32; MAX_NULLIFIERS_PER_TX], + pub note_hash_indexes_for_nullifiers: [u32; MAX_NULLIFIERS_PER_TX], } pub unconstrained fn generate_previous_kernel_validator_hints( diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator.nr index ebe27282cca..70de53f3f31 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator.nr @@ -2,11 +2,6 @@ mod find_first_revertible_item_index; mod validate_contract_address; mod validate_split_ranges; -use crate::components::private_call_data_validator::{ - find_first_revertible_item_index::find_first_revertible_item_index, - validate_contract_address::validate_contract_address, - validate_split_ranges::validate_split_ranges, -}; use dep::types::{ abis::{ kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs, @@ -22,6 +17,9 @@ use dep::types::{ transaction::tx_request::TxRequest, utils::arrays::find_index_hint, }; +use find_first_revertible_item_index::find_first_revertible_item_index; +use validate_contract_address::validate_contract_address; +use validate_split_ranges::validate_split_ranges; fn validate_incrementing_counters_within_range( counter_start: u32, @@ -82,7 +80,7 @@ where pub struct PrivateCallDataValidator { data: PrivateCallData, - array_lengths: PrivateCircuitPublicInputsArrayLengths, + pub array_lengths: PrivateCircuitPublicInputsArrayLengths, } impl PrivateCallDataValidator { diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator/validate_contract_address.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator/validate_contract_address.nr index 566cd989cbd..fe4fd6cc5f2 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator/validate_contract_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator/validate_contract_address.nr @@ -2,7 +2,6 @@ use dep::types::{ abis::private_kernel::private_call_data::PrivateCallData, address::AztecAddress, constants::MAX_PROTOCOL_CONTRACTS, merkle_tree::root::root_from_sibling_path, }; -use types::debug_log::debug_log_format; pub fn validate_contract_address( private_call_data: PrivateCallData, diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator/validate_split_ranges.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator/validate_split_ranges.nr index 12912206fb9..bde22a631f7 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator/validate_split_ranges.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator/validate_split_ranges.nr @@ -50,10 +50,10 @@ mod tests { pub fn add_private_call_request(&mut self, counter_start: u32, counter_end: u32) { let index = self.private_call.private_call_requests.len(); self.private_call.append_private_call_requests(1); - self.private_call.private_call_requests.storage[index].start_side_effect_counter = - counter_start; - self.private_call.private_call_requests.storage[index].end_side_effect_counter = - counter_end; + let mut call_request = self.private_call.private_call_requests.get(index); + call_request.start_side_effect_counter = counter_start; + call_request.end_side_effect_counter = counter_end; + self.private_call.private_call_requests.set(index, call_request); self.private_call.counter = counter_end + 1; } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_kernel_circuit_public_inputs_composer.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_kernel_circuit_public_inputs_composer.nr index 9527a685a43..78655c65d27 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_kernel_circuit_public_inputs_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_kernel_circuit_public_inputs_composer.nr @@ -6,10 +6,11 @@ use dep::types::{ max_block_number::MaxBlockNumber, nullifier::{Nullifier, ScopedNullifier}, private_circuit_public_inputs::PrivateCircuitPublicInputs, + side_effect::Ordered, tx_constant_data::TxConstantData, }, address::AztecAddress, - traits::is_empty, + traits::{Empty, is_empty}, transaction::tx_request::TxRequest, utils::arrays::{array_length, array_to_bounded_vec, sort_by_counter_asc, sort_by_counter_desc}, }; @@ -18,8 +19,26 @@ pub fn create_first_nullifier(tx_request: TxRequest) -> ScopedNullifier { Nullifier { value: tx_request.hash(), note_hash: 0, counter: 0 }.scope(AztecAddress::zero()) } +unconstrained fn transform_vec( + vec: BoundedVec, + f: unconstrained fn[Env]([T; N]) -> [T; N], +) -> BoundedVec +where + T: Ordered + Empty + Eq, +{ + let len = vec.len(); + let transformed = f(vec.storage()); + let mut transformed_vec = vec; + for i in 0..N { + if i < len { + transformed_vec.set_unchecked(i, transformed[i]); + } + } + transformed_vec +} + pub struct PrivateKernelCircuitPublicInputsComposer { - public_inputs: PrivateKernelCircuitPublicInputsBuilder, + pub public_inputs: PrivateKernelCircuitPublicInputsBuilder, } impl PrivateKernelCircuitPublicInputsComposer { @@ -47,7 +66,7 @@ impl PrivateKernelCircuitPublicInputsComposer { PrivateKernelCircuitPublicInputsComposer { public_inputs } } - pub fn new_from_previous_kernel( + pub unconstrained fn new_from_previous_kernel( previous_kernel_public_inputs: PrivateKernelCircuitPublicInputs, ) -> Self { let mut public_inputs = PrivateKernelCircuitPublicInputsBuilder::empty(); @@ -98,12 +117,16 @@ impl PrivateKernelCircuitPublicInputsComposer { pub unconstrained fn sort_ordered_values(&mut self) { // Note hashes, nullifiers, and private logs are sorted in the reset circuit. - self.public_inputs.end.l2_to_l1_msgs.storage = - sort_by_counter_asc(self.public_inputs.end.l2_to_l1_msgs.storage); - self.public_inputs.end.contract_class_logs_hashes.storage = - sort_by_counter_asc(self.public_inputs.end.contract_class_logs_hashes.storage); - self.public_inputs.end.public_call_requests.storage = - sort_by_counter_desc(self.public_inputs.end.public_call_requests.storage); + self.public_inputs.end.l2_to_l1_msgs = + transform_vec(self.public_inputs.end.l2_to_l1_msgs, sort_by_counter_asc); + self.public_inputs.end.contract_class_logs_hashes = transform_vec( + self.public_inputs.end.contract_class_logs_hashes, + sort_by_counter_asc, + ); + self.public_inputs.end.public_call_requests = transform_vec( + self.public_inputs.end.public_call_requests, + sort_by_counter_desc, + ); } pub fn finish(self) -> PrivateKernelCircuitPublicInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr index dd37b20866e..7e8d5b28ac9 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr @@ -45,15 +45,16 @@ impl TailOutputComposer { unconstrained fn build_combined_accumulated_data(self) -> CombinedAccumulatedData { let source = self.output_composer.public_inputs.end; let mut data = CombinedAccumulatedData::empty(); - data.note_hashes = source.note_hashes.storage.map(|n: ScopedNoteHash| n.note_hash.value); - data.nullifiers = source.nullifiers.storage.map(|n: ScopedNullifier| n.nullifier.value); + data.note_hashes = source.note_hashes.storage().map(|n: ScopedNoteHash| n.note_hash.value); + data.nullifiers = source.nullifiers.storage().map(|n: ScopedNullifier| n.nullifier.value); data.l2_to_l1_msgs = - source.l2_to_l1_msgs.storage.map(|m: ScopedL2ToL1Message| m.expose_to_public()); + source.l2_to_l1_msgs.storage().map(|m: ScopedL2ToL1Message| m.expose_to_public()); data.private_logs = - source.private_logs.storage.map(|l: Scoped| l.inner.log); - data.contract_class_logs_hashes = - source.contract_class_logs_hashes.storage.map(|l: ScopedLogHash| l.expose_to_public()); - data.contract_class_log_preimages_length = source.contract_class_logs_hashes.storage.fold( + source.private_logs.storage().map(|l: Scoped| l.inner.log); + data.contract_class_logs_hashes = source.contract_class_logs_hashes.storage().map( + |l: ScopedLogHash| l.expose_to_public(), + ); + data.contract_class_log_preimages_length = source.contract_class_logs_hashes.storage().fold( 0, |len, l: ScopedLogHash| len + l.log_hash.length, ); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator.nr index 693fe8b6a58..b8e22650ef4 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator.nr @@ -1,4 +1,4 @@ -mod tail_output_hints; +pub mod tail_output_hints; use crate::components::tail_output_composer::meter_gas_used; use dep::types::{ @@ -26,6 +26,14 @@ impl TailOutputValidator { previous_kernel: PrivateKernelCircuitPublicInputs, ) -> Self { let hints = unsafe { generate_tail_output_hints(previous_kernel) }; + TailOutputValidator::new_with_hints(output, previous_kernel, hints) + } + + pub fn new_with_hints( + output: KernelCircuitPublicInputs, + previous_kernel: PrivateKernelCircuitPublicInputs, + hints: TailOutputHints, + ) -> Self { TailOutputValidator { output, previous_kernel, hints } } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator/tail_output_hints.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator/tail_output_hints.nr index 73f199f7a74..d6f3a2095e4 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator/tail_output_hints.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator/tail_output_hints.nr @@ -6,10 +6,10 @@ use dep::types::{ pub struct TailOutputHints { // L2 to l1 msgs. - sorted_l2_to_l1_msg_hints: [OrderHint; MAX_L2_TO_L1_MSGS_PER_TX], + pub sorted_l2_to_l1_msg_hints: [OrderHint; MAX_L2_TO_L1_MSGS_PER_TX], // Contract class log hashes. - sorted_contract_class_log_hashes: [ScopedLogHash; MAX_CONTRACT_CLASS_LOGS_PER_TX], - sorted_contract_class_log_hash_hints: [OrderHint; MAX_CONTRACT_CLASS_LOGS_PER_TX], + pub sorted_contract_class_log_hashes: [ScopedLogHash; MAX_CONTRACT_CLASS_LOGS_PER_TX], + pub sorted_contract_class_log_hash_hints: [OrderHint; MAX_CONTRACT_CLASS_LOGS_PER_TX], } pub unconstrained fn generate_tail_output_hints( diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_composer.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_composer.nr index c4a1d85e924..9b992e14d87 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_composer.nr @@ -5,8 +5,8 @@ use crate::components::private_kernel_circuit_public_inputs_composer::PrivateKer use dep::types::abis::kernel_circuit_public_inputs::{ PrivateKernelCircuitPublicInputs, PrivateToPublicKernelCircuitPublicInputs, }; -use split_to_public::split_to_public; pub use meter_gas_used::meter_gas_used; +pub use split_to_public::split_to_public; pub struct TailToPublicOutputComposer { output_composer: PrivateKernelCircuitPublicInputsComposer, diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator/tail_to_public_output_hints.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator/tail_to_public_output_hints.nr index 231c175a269..0aa6444dca3 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator/tail_to_public_output_hints.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator/tail_to_public_output_hints.nr @@ -8,11 +8,11 @@ use dep::types::{ pub struct TailToPublicOutputHints { // L2 to l1 msgs. - sorted_l2_to_l1_msg_hints: SplitOrderHints, + pub sorted_l2_to_l1_msg_hints: SplitOrderHints, // Contract class log hashes. - sorted_contract_class_log_hash_hints: SplitOrderHints, + pub sorted_contract_class_log_hash_hints: SplitOrderHints, // Public call requests. - sorted_public_call_request_hints: SplitOrderHints, + pub sorted_public_call_request_hints: SplitOrderHints, } pub unconstrained fn generate_tail_to_public_output_hints( diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr index e226b38865d..4ac72fc4d6b 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr @@ -127,9 +127,10 @@ mod tests { // note_hash_read_requests builder.previous_kernel.append_note_hash_read_requests(1); - let prev_note_hash_read_requests = builder.previous_kernel.note_hash_read_requests.storage; + let prev_note_hash_read_requests = + builder.previous_kernel.note_hash_read_requests.storage(); builder.private_call.append_note_hash_read_requests(2); - let curr_note_hash_read_requests = builder.private_call.note_hash_read_requests.storage; + let curr_note_hash_read_requests = builder.private_call.note_hash_read_requests.storage(); // private_logs builder.previous_kernel.append_private_logs(2); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr index 4f1ca592194..154c12763ee 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr @@ -227,8 +227,9 @@ mod tests { pub fn nullify_pending_note_hash(&mut self, nullifier_index: u32, note_hash_index: u32) { let note_hash = self.previous_kernel.note_hashes.get(note_hash_index).note_hash; - self.previous_kernel.nullifiers.storage[nullifier_index].nullifier.note_hash = - note_hash.value; + let mut nullifier = self.previous_kernel.nullifiers.get(nullifier_index); + nullifier.nullifier.note_hash = note_hash.value; + self.previous_kernel.nullifiers.set(nullifier_index, nullifier); let num_hints = unsafe { find_index_hint( self.transient_data_index_hints, @@ -512,7 +513,7 @@ mod tests { builder.previous_kernel.note_hashes.set(2, tmp); builder.previous_kernel.append_nullifiers(3); - // Shuffle the nullifers so they will have to be re-ordered. + // Shuffle the nullifiers so they will have to be re-ordered. let tmp = builder.previous_kernel.nullifiers.get(1); builder.previous_kernel.nullifiers.set(1, builder.previous_kernel.nullifiers.get(3)); builder.previous_kernel.nullifiers.set(3, builder.previous_kernel.nullifiers.get(2)); @@ -584,7 +585,9 @@ mod tests { builder.previous_kernel.append_note_hashes(1); builder.previous_kernel.append_nullifiers(3); // The nullifier at index 2 is nullifying a note hash that doesn't exist yet. - builder.previous_kernel.nullifiers.storage[2].nullifier.note_hash = 9988; + let mut nullifier = builder.previous_kernel.nullifiers.get(2); + nullifier.nullifier.note_hash = 9988; + builder.previous_kernel.nullifiers.set(2, nullifier); // Get ordered items before shuffling. let note_hashes = builder.previous_kernel.note_hashes.storage(); let nullifiers = builder.previous_kernel.nullifiers.storage(); @@ -626,7 +629,9 @@ mod tests { builder.previous_kernel.append_note_hashes_with_logs(2); // The note hash at index 0 is siloed. - builder.previous_kernel.note_hashes.storage[0].contract_address = AztecAddress::zero(); + let mut note_hash = builder.previous_kernel.note_hashes.get(0); + note_hash.contract_address = AztecAddress::zero(); + builder.previous_kernel.note_hashes.set(0, note_hash); builder.failed(); } @@ -638,7 +643,9 @@ mod tests { builder.previous_kernel.append_nullifiers(2); // The nullifier at index 1 is siloed. - builder.previous_kernel.nullifiers.storage[1].contract_address = AztecAddress::zero(); + let mut nullifier = builder.previous_kernel.nullifiers.get(1); + nullifier.contract_address = AztecAddress::zero(); + builder.previous_kernel.nullifiers.set(1, nullifier); let nullifiers = builder.previous_kernel.nullifiers.storage(); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr index fab13095851..78ab6f77609 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr @@ -144,7 +144,7 @@ mod tests { builder.previous_kernel.append_l2_to_l1_msgs(2); // Reorder the msgs - let original_msgs = builder.previous_kernel.l2_to_l1_msgs.storage; + let original_msgs = builder.previous_kernel.l2_to_l1_msgs.storage(); let mut reversed_msgs = [ScopedL2ToL1Message::empty(); 2]; for i in 0..reversed_msgs.len() { reversed_msgs[i] = builder.previous_kernel.l2_to_l1_msgs.pop(); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr index 1e6ef6fc35f..6bc437e4601 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr @@ -156,8 +156,9 @@ mod tests { let public_inputs = builder.execute(); - let output_nullifiers = - builder.previous_kernel.nullifiers.storage.map(|n: ScopedNullifier| n.nullifier.value); + let output_nullifiers = builder.previous_kernel.nullifiers.storage().map( + |n: ScopedNullifier| n.nullifier.value, + ); assert_array_eq( public_inputs.non_revertible_accumulated_data.nullifiers, @@ -190,8 +191,9 @@ mod tests { let public_inputs = builder.execute(); - let exposed_note_hashes = - builder.previous_kernel.note_hashes.storage.map(|n: ScopedNoteHash| n.note_hash.value); + let exposed_note_hashes = builder.previous_kernel.note_hashes.storage().map( + |n: ScopedNoteHash| n.note_hash.value, + ); assert_array_eq( public_inputs.non_revertible_accumulated_data.note_hashes, diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/previous_kernel_validator_builder/validate_no_transient_data.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/previous_kernel_validator_builder/validate_no_transient_data.nr index 624f4179ed2..d74f3c3bafb 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/previous_kernel_validator_builder/validate_no_transient_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/previous_kernel_validator_builder/validate_no_transient_data.nr @@ -6,7 +6,8 @@ impl PreviousKernelValidatorBuilder { let inner_note_hash = 123123; for i in 0..siloed_note_hashes.len() { self.previous_kernel.add_siloed_note_hash(inner_note_hash); - siloed_note_hashes[i] = self.previous_kernel.note_hashes.storage[i].note_hash.value; + siloed_note_hashes[i] = + self.previous_kernel.note_hashes.get_unchecked(i).note_hash.value; } siloed_note_hashes } @@ -48,7 +49,9 @@ fn validate_no_transient_data_nullifiers_for_note_hashes_emitted_after_fails() { // Emit the note hashes after the nullifiers let siloed_note_hashes = builder.append_same_inner_note_hashes(); // Link a note hash to the nullifier at index 2. - builder.previous_kernel.nullifiers.storage[2].nullifier.note_hash = siloed_note_hashes[0]; + let mut nullifier = builder.previous_kernel.nullifiers.get(2); + nullifier.nullifier.note_hash = siloed_note_hashes[0]; + builder.previous_kernel.nullifiers.set(2, nullifier); builder.validate_for_private_tail(); } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_arrays.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_arrays.nr index 98aaa81fb68..ce965ce8ec6 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_arrays.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_arrays.nr @@ -1,11 +1,14 @@ use crate::tests::private_call_data_validator_builder::PrivateCallDataValidatorBuilder; +use dep::types::traits::Empty; -fn unshift_empty_item(vec: &mut BoundedVec) { - let len = vec.len(); - let empty_item = vec.storage[len]; +fn unshift_empty_item(vec: &mut BoundedVec) +where + T: Empty, +{ + let empty_item = T::empty(); let first_item = vec.get(0); vec.push(first_item); - vec.storage[0] = empty_item; + vec.set(0, empty_item); } #[test(should_fail_with = "invalid array")] diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_call_requests.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_call_requests.nr index b91bd56ef66..498186c3b8c 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_call_requests.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_call_requests.nr @@ -27,8 +27,9 @@ fn validate_public_call_requests_incorrect_msg_sender_for_regular_call_fails() { builder.private_call.append_public_call_requests(1); // Change the msg_sender to be the caller's msg_sender. - builder.private_call.public_call_requests.storage[0].inner.msg_sender = - builder.private_call.msg_sender; + let mut call_request = builder.private_call.public_call_requests.get(0); + call_request.inner.msg_sender = builder.private_call.msg_sender; + builder.private_call.public_call_requests.set(0, call_request); builder.validate(); } @@ -39,7 +40,9 @@ fn validate_public_call_requests_static_call_regular_call_fails() { builder.private_call.append_public_call_requests(1); // Tweak the request to be making a non-static call. - builder.private_call.public_call_requests.storage[0].inner.is_static_call = false; + let mut call_request = builder.private_call.public_call_requests.get(0); + call_request.inner.is_static_call = false; + builder.private_call.public_call_requests.set(0, call_request); builder.validate(); } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_counters.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_counters.nr index 0ee10d9b513..97a86c9017b 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_counters.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_counters.nr @@ -51,8 +51,9 @@ fn validate_counters_note_hash_counter_same_as_call_counter_start_fails() { builder.private_call.append_note_hashes(1); // Tweak the counter of the first note hash to EQUAL the start counter of the call. - builder.private_call.note_hashes.storage[0].note_hash.counter = - builder.private_call.counter_start; + let mut note_hash = builder.private_call.note_hashes.get(0); + note_hash.note_hash.counter = builder.private_call.counter_start; + builder.private_call.note_hashes.set(0, note_hash); builder.validate(); } @@ -63,8 +64,9 @@ fn validate_counters_note_hash_counter_smaller_than_call_fails() { builder.private_call.append_note_hashes(1); // Tweak the counter of the first note hash to be LESS than the start counter of the call. - builder.private_call.note_hashes.storage[0].note_hash.counter = - builder.private_call.counter_start - 1; + let mut note_hash = builder.private_call.note_hashes.get(0); + note_hash.note_hash.counter = builder.private_call.counter_start - 1; + builder.private_call.note_hashes.set(0, note_hash); builder.validate(); } @@ -76,8 +78,12 @@ fn validate_counters_note_hash_identical_counters_fails() { builder.private_call.append_note_hashes(2); let counter_start = builder.private_call.counter_start; // Tweak the counter of the second note hash to EQUAL the counter of the first note hash. - builder.private_call.note_hashes.storage[0].note_hash.counter = counter_start + 1; - builder.private_call.note_hashes.storage[1].note_hash.counter = counter_start + 1; + let mut note_hash_0 = builder.private_call.note_hashes.get(0); + note_hash_0.note_hash.counter = counter_start + 1; + builder.private_call.note_hashes.set(0, note_hash_0); + let mut note_hash_1 = builder.private_call.note_hashes.get(1); + note_hash_1.note_hash.counter = counter_start + 1; + builder.private_call.note_hashes.set(1, note_hash_1); builder.validate(); } @@ -89,8 +95,12 @@ fn validate_counters_note_hash_unordered_counters_fails() { builder.private_call.append_note_hashes(2); let counter_start = builder.private_call.counter_start; // Tweak the counter of the second note hash to be LESS than the counter of the first note hash. - builder.private_call.note_hashes.storage[0].note_hash.counter = counter_start + 2; - builder.private_call.note_hashes.storage[1].note_hash.counter = counter_start + 1; + let mut note_hash_0 = builder.private_call.note_hashes.get(0); + note_hash_0.note_hash.counter = counter_start + 2; + builder.private_call.note_hashes.set(0, note_hash_0); + let mut note_hash_1 = builder.private_call.note_hashes.get(1); + note_hash_1.note_hash.counter = counter_start + 1; + builder.private_call.note_hashes.set(1, note_hash_1); builder.validate(); } @@ -101,8 +111,9 @@ fn validate_counters_note_hash_counter_larger_than_call_fails() { builder.private_call.append_note_hashes(2); // Tweak the counter of the second note hash to be GREATER than the end counter of the call. - builder.private_call.note_hashes.storage[1].note_hash.counter = - builder.private_call.counter + 1; + let mut note_hash = builder.private_call.note_hashes.get(1); + note_hash.note_hash.counter = builder.private_call.counter + 1; + builder.private_call.note_hashes.set(1, note_hash); builder.validate(); } @@ -113,7 +124,9 @@ fn validate_counters_note_hash_counter_same_as_call_counter_end_fails() { builder.private_call.append_note_hashes(2); // Tweak the counter of the second note hash to EQUAL the end counter of the call. - builder.private_call.note_hashes.storage[1].note_hash.counter = builder.private_call.counter; + let mut note_hash = builder.private_call.note_hashes.get(1); + note_hash.note_hash.counter = builder.private_call.counter; + builder.private_call.note_hashes.set(1, note_hash); builder.validate(); } @@ -136,9 +149,9 @@ fn validate_counters_private_call_requests_less_than_call_start_fails() { builder.private_call.append_private_call_requests(1); // Tweak the start counter of the first nested call to be LESS than the start counter of the call. - let counter_start = builder.private_call.counter_start; - builder.private_call.private_call_requests.storage[0].start_side_effect_counter = - counter_start - 1; + let mut call_request = builder.private_call.private_call_requests.get(0); + call_request.start_side_effect_counter = builder.private_call.counter_start - 1; + builder.private_call.private_call_requests.set(0, call_request); builder.validate(); } @@ -149,8 +162,9 @@ fn validate_counters_private_call_requests_equal_call_start_fails() { builder.private_call.append_private_call_requests(1); // Tweak the start counter of the call to EQUAL the start counter of the first nested call. - let counter_start = builder.private_call.counter_start; - builder.private_call.private_call_requests.storage[0].start_side_effect_counter = counter_start; + let mut call_request = builder.private_call.private_call_requests.get(0); + call_request.start_side_effect_counter = builder.private_call.counter_start; + builder.private_call.private_call_requests.set(0, call_request); builder.validate(); } @@ -162,8 +176,9 @@ fn validate_counters_private_call_requests_less_than_previous_end_fails() { builder.private_call.append_private_call_requests(2); // Tweak the start counter of the second nested call to be LESS than the end counter of the first nested call. let counter_end = builder.private_call.private_call_requests.get(0).end_side_effect_counter; - builder.private_call.private_call_requests.storage[1].start_side_effect_counter = - counter_end - 1; + let mut call_request = builder.private_call.private_call_requests.get(1); + call_request.start_side_effect_counter = counter_end - 1; + builder.private_call.private_call_requests.set(1, call_request); builder.validate(); } @@ -175,7 +190,9 @@ fn validate_counters_private_call_requests_same_as_previous_end_fails() { builder.private_call.append_private_call_requests(2); // Tweak the start counter of the second nested call to EQUAL the end counter of the first nested call. let counter_end = builder.private_call.private_call_requests.get(0).end_side_effect_counter; - builder.private_call.private_call_requests.storage[1].start_side_effect_counter = counter_end; + let mut call_request = builder.private_call.private_call_requests.get(1); + call_request.start_side_effect_counter = counter_end; + builder.private_call.private_call_requests.set(1, call_request); builder.validate(); } @@ -186,9 +203,9 @@ fn validate_counters_private_call_requests_end_less_than_start_fails() { builder.private_call.append_private_call_requests(1); // Tweak the end counter of the first nested call to be LESS than its start counter. - let counter_start = builder.private_call.private_call_requests.get(0).start_side_effect_counter; - builder.private_call.private_call_requests.storage[0].end_side_effect_counter = - counter_start - 1; + let mut call_request = builder.private_call.private_call_requests.get(0); + call_request.end_side_effect_counter = call_request.start_side_effect_counter - 1; + builder.private_call.private_call_requests.set(0, call_request); builder.validate(); } @@ -199,8 +216,9 @@ fn validate_counters_private_call_requests_end_equal_start_fails() { builder.private_call.append_private_call_requests(1); // Tweak the end counter of the first nested call to EQUAL its start counter. - let counter_start = builder.private_call.private_call_requests.get(0).start_side_effect_counter; - builder.private_call.private_call_requests.storage[0].end_side_effect_counter = counter_start; + let mut call_request = builder.private_call.private_call_requests.get(0); + call_request.end_side_effect_counter = call_request.start_side_effect_counter; + builder.private_call.private_call_requests.set(0, call_request); builder.validate(); } @@ -212,7 +230,9 @@ fn validate_counters_private_call_requests_greater_than_call_end_fails() { builder.private_call.append_private_call_requests(1); // Tweak the end counter of the nested call to be GREATER than the end counter of the call. let counter_end = builder.private_call.counter; - builder.private_call.private_call_requests.storage[0].end_side_effect_counter = counter_end + 1; + let mut call_request = builder.private_call.private_call_requests.get(0); + call_request.end_side_effect_counter = counter_end + 1; + builder.private_call.private_call_requests.set(0, call_request); builder.validate(); } @@ -223,8 +243,9 @@ fn validate_counters_private_call_requests_equal_call_end_fails() { builder.private_call.append_private_call_requests(1); // Tweak the end counter of the nested call to EQUAL the end counter of the call. - builder.private_call.private_call_requests.storage[0].end_side_effect_counter = - builder.private_call.counter; + let mut call_request = builder.private_call.private_call_requests.get(0); + call_request.end_side_effect_counter = builder.private_call.counter; + builder.private_call.private_call_requests.set(0, call_request); builder.validate(); } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_note_logs.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_note_logs.nr index 7dc3b6adfae..b9ae0205ba3 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_note_logs.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_note_logs.nr @@ -16,7 +16,9 @@ fn validate_note_logs_random_note_hash_counter_fails() { builder.private_call.append_note_hashes_with_logs(2); // Tweak the note_hash_counter to not match any note hash's counter. - builder.private_call.private_logs.storage[1].inner.note_hash_counter += 100; + let mut note_hash = builder.private_call.private_logs.get(1); + note_hash.inner.note_hash_counter += 100; + builder.private_call.private_logs.set(1, note_hash); builder.validate(); } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_private_call_requests.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_private_call_requests.nr index 306a637c819..e6df04f716f 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_private_call_requests.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_private_call_requests.nr @@ -13,10 +13,10 @@ impl PrivateCallDataValidatorBuilder { pub fn add_private_call_request(&mut self, counter_start: u32, counter_end: u32) { let index = self.private_call.private_call_requests.len(); self.private_call.append_private_call_requests(1); - self.private_call.private_call_requests.storage[index].start_side_effect_counter = - counter_start; - self.private_call.private_call_requests.storage[index].end_side_effect_counter = - counter_end; + let mut call_request = self.private_call.private_call_requests.get(index); + call_request.start_side_effect_counter = counter_start; + call_request.end_side_effect_counter = counter_end; + self.private_call.private_call_requests.set(index, call_request); self.private_call.counter = counter_end + 1; } } @@ -45,8 +45,9 @@ fn validate_private_call_requests_incorrect_msg_sender_for_regular_call_fails() builder.private_call.append_private_call_requests(1); // Change the msg_sender to be the caller's msg_sender. - builder.private_call.private_call_requests.storage[0].call_context.msg_sender = - builder.private_call.msg_sender; + let mut call_request = builder.private_call.private_call_requests.get(0); + call_request.call_context.msg_sender = builder.private_call.msg_sender; + builder.private_call.private_call_requests.set(0, call_request); builder.validate(); } @@ -57,7 +58,9 @@ fn validate_private_call_requests_static_call_regular_call_fails() { builder.private_call.append_private_call_requests(1); // Tweak the request to be making a non-static call. - builder.private_call.private_call_requests.storage[0].call_context.is_static_call = false; + let mut call_request = builder.private_call.private_call_requests.get(0); + call_request.call_context.is_static_call = false; + builder.private_call.private_call_requests.set(0, call_request); builder.validate(); } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_output_validator_builder/validate_initial_values.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_output_validator_builder/validate_initial_values.nr index 3faeab0e8ab..5e9d29a5674 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_output_validator_builder/validate_initial_values.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_output_validator_builder/validate_initial_values.nr @@ -35,7 +35,9 @@ fn validate_initial_values_constants_mismatch_txs_effects_hash_fails() { fn validate_initial_values_constants_incorrect_first_nullifier_fails() { let mut builder = PrivateKernelCircuitOutputValidatorBuilder::new(); - builder.output.nullifiers.storage[0].nullifier.value += 1; + let mut nullifier = builder.output.nullifiers.get(0); + nullifier.nullifier.value += 1; + builder.output.nullifiers.set(0, nullifier); builder.validate_as_first_call(); } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_output_validator_builder/validate_propagated_from_private_call.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_output_validator_builder/validate_propagated_from_private_call.nr index 3798abb8ed9..04d35434dc9 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_output_validator_builder/validate_propagated_from_private_call.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_output_validator_builder/validate_propagated_from_private_call.nr @@ -1,4 +1,5 @@ use crate::tests::private_kernel_circuit_output_validator_builder::PrivateKernelCircuitOutputValidatorBuilder; +use dep::types::tests::utils::swap_items; #[test] fn validate_propagated_from_private_call_empty_data_succeeds() { @@ -25,9 +26,11 @@ fn validate_propagated_from_private_call_note_hash_read_requests_output_mismatch let mut builder = PrivateKernelCircuitOutputValidatorBuilder::new(); builder.private_call.append_note_hash_read_requests(2); - builder.output.append_note_hash_read_requests(1); + builder.output.append_note_hash_read_requests(2); // Tweak the value in the output. - builder.output.note_hash_read_requests.storage[1].read_request.value += 1; + let mut read_request = builder.output.note_hash_read_requests.get(1); + read_request.read_request.value += 1; + builder.output.note_hash_read_requests.set(1, read_request); builder.validate_as_inner_call(); } @@ -39,7 +42,9 @@ fn validate_propagated_from_private_call_note_hash_read_requests_mismatch_contra builder.private_call.append_note_hash_read_requests(2); builder.output.append_note_hash_read_requests(2); // Tweak the contract address in the output. - builder.output.note_hash_read_requests.storage[1].contract_address.inner += 1; + let mut read_request = builder.output.note_hash_read_requests.get(1); + read_request.contract_address.inner += 1; + builder.output.note_hash_read_requests.set(1, read_request); builder.validate_as_inner_call(); } @@ -73,9 +78,9 @@ fn validate_propagated_from_private_call_note_hash_read_requests_output_extra_no builder.private_call.append_note_hash_read_requests(2); builder.output.append_note_hash_read_requests(2); // Add a non-empty item to the end of the output. - let len = builder.output.note_hash_read_requests.storage.len(); - builder.output.note_hash_read_requests.storage[len - 1] = - builder.output.note_hash_read_requests.storage[0]; + let mut read_requests = builder.output.note_hash_read_requests.storage(); + read_requests[read_requests.len() - 1] = read_requests[0]; + builder.output.note_hash_read_requests = BoundedVec::from_array(read_requests); builder.validate_as_inner_call(); } @@ -112,7 +117,9 @@ fn validate_propagated_from_private_call_note_hash_read_requests_with_previous_m builder.private_call.append_note_hash_read_requests(2); builder.output.append_note_hash_read_requests(2); // Tweak the value in the output. - builder.output.note_hash_read_requests.storage[3].read_request.value += 1; + let mut read_request = builder.output.note_hash_read_requests.get(3); + read_request.read_request.value += 1; + builder.output.note_hash_read_requests.set(3, read_request); builder.validate_as_inner_call(); } @@ -125,7 +132,9 @@ fn validate_propagated_from_private_call_note_hash_read_requests_with_previous_m builder.private_call.append_note_hash_read_requests(2); builder.output.append_note_hash_read_requests(2); // Tweak the contract address in the output. - builder.output.note_hash_read_requests.storage[3].contract_address.inner += 1; + let mut read_request = builder.output.note_hash_read_requests.get(3); + read_request.contract_address.inner += 1; + builder.output.note_hash_read_requests.set(3, read_request); builder.validate_as_inner_call(); } @@ -162,9 +171,9 @@ fn validate_propagated_from_private_call_note_hash_read_requests_with_previous_o builder.private_call.append_note_hash_read_requests(2); builder.output.append_note_hash_read_requests(2); // Add a non-empty item to the end of the output. - let len = builder.output.note_hash_read_requests.storage.len(); - builder.output.note_hash_read_requests.storage[len - 1] = - builder.output.note_hash_read_requests.storage[0]; + let mut read_requests = builder.output.note_hash_read_requests.storage(); + read_requests[read_requests.len() - 1] = read_requests[0]; + builder.output.note_hash_read_requests = BoundedVec::from_array(read_requests); builder.validate_as_inner_call(); } @@ -387,10 +396,7 @@ fn validate_propagated_from_private_call_private_call_requests_not_reversed_fail builder.private_call.append_private_call_requests(2); builder.output.append_private_call_requests(2); // Swap the call requests. - let first_call_request = builder.output.private_call_requests.storage[0]; - builder.output.private_call_requests.storage[0] = - builder.output.private_call_requests.storage[1]; - builder.output.private_call_requests.storage[1] = first_call_request; + swap_items(&mut builder.output.private_call_requests, 0, 1); builder.validate_as_inner_call(); } @@ -400,7 +406,7 @@ fn validate_propagated_from_private_call_private_call_requests_with_previous_out let mut builder = PrivateKernelCircuitOutputValidatorBuilder::new(); builder.output.append_private_call_requests(5); - let requests = builder.output.private_call_requests.storage; + let requests = builder.output.private_call_requests.storage(); // The private_call_stack in the output will be: [requests[4], requests[3], requests[2], requests[1], requests[0]]. // First 2 are propagated from the previous kernel. builder.previous_kernel.private_call_requests.push(requests[3]); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/mod.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/mod.nr index 3ccc2438ab7..91559e7c9f1 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/mod.nr @@ -46,12 +46,16 @@ impl PrivateKernelCircuitPublicInputsComposerBuilder { pub fn new_from_previous_kernel(self) -> PrivateKernelCircuitPublicInputsComposer { let previous_kernel = self.previous_kernel.to_private_kernel_circuit_public_inputs(); - PrivateKernelCircuitPublicInputsComposer::new_from_previous_kernel(previous_kernel) + unsafe { + PrivateKernelCircuitPublicInputsComposer::new_from_previous_kernel(previous_kernel) + } } pub fn compose_from_tx_request(self) -> PrivateKernelCircuitPublicInputs { let private_call = self.private_call.to_private_call_data(); - self.new_from_tx_request().with_private_call(private_call.public_inputs).finish() + unsafe { + self.new_from_tx_request().with_private_call(private_call.public_inputs).finish() + } } pub fn compose_from_previous_kernel(self) -> PrivateKernelCircuitPublicInputs { @@ -64,9 +68,11 @@ impl PrivateKernelCircuitPublicInputsComposerBuilder { let private_call = self.private_call.to_private_call_data(); - PrivateKernelCircuitPublicInputsComposer::new_from_previous_kernel(previous_kernel) - .pop_top_call_request() - .with_private_call(private_call.public_inputs) - .finish() + unsafe { + PrivateKernelCircuitPublicInputsComposer::new_from_previous_kernel(previous_kernel) + .pop_top_call_request() + .with_private_call(private_call.public_inputs) + .finish() + } } } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/new_from_previous_kernel_with_private_call.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/new_from_previous_kernel_with_private_call.nr index 206da091af4..8e4d03af9f4 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/new_from_previous_kernel_with_private_call.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/new_from_previous_kernel_with_private_call.nr @@ -102,9 +102,9 @@ fn new_from_previous_kernel_with_private_call_note_hash_read_requests_succeeds() let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.previous_kernel.append_note_hash_read_requests(2); - let prev = builder.previous_kernel.note_hash_read_requests.storage; + let prev = builder.previous_kernel.note_hash_read_requests.storage(); builder.private_call.append_note_hash_read_requests(2); - let curr = builder.private_call.note_hash_read_requests.storage; + let curr = builder.private_call.note_hash_read_requests.storage(); let output = builder.compose_from_previous_kernel(); @@ -119,9 +119,9 @@ fn new_from_previous_kernel_with_private_call_nullifier_read_requests_succeeds() let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.previous_kernel.append_nullifier_read_requests(2); - let prev = builder.previous_kernel.nullifier_read_requests.storage; + let prev = builder.previous_kernel.nullifier_read_requests.storage(); builder.private_call.append_nullifier_read_requests(2); - let curr = builder.private_call.nullifier_read_requests.storage; + let curr = builder.private_call.nullifier_read_requests.storage(); let output = builder.compose_from_previous_kernel(); @@ -136,9 +136,9 @@ fn new_from_previous_kernel_with_private_call_key_validation_requests_succeeds() let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.previous_kernel.append_key_validation_requests(2); - let prev = builder.previous_kernel.scoped_key_validation_requests_and_generators.storage; + let prev = builder.previous_kernel.scoped_key_validation_requests_and_generators.storage(); builder.private_call.append_key_validation_requests(2); - let curr = builder.private_call.scoped_key_validation_requests_and_generators.storage; + let curr = builder.private_call.scoped_key_validation_requests_and_generators.storage(); let output = builder.compose_from_previous_kernel(); @@ -153,9 +153,9 @@ fn new_from_previous_kernel_with_private_call_note_hashes_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.previous_kernel.append_note_hashes(2); - let prev = builder.previous_kernel.note_hashes.storage; + let prev = builder.previous_kernel.note_hashes.storage(); builder.private_call.append_note_hashes(2); - let curr = builder.private_call.note_hashes.storage; + let curr = builder.private_call.note_hashes.storage(); let output = builder.compose_from_previous_kernel(); @@ -167,9 +167,9 @@ fn new_from_previous_kernel_with_private_call_nullifiers_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.previous_kernel.append_nullifiers(2); - let prev = builder.previous_kernel.nullifiers.storage; + let prev = builder.previous_kernel.nullifiers.storage(); builder.private_call.append_nullifiers(2); - let curr = builder.private_call.nullifiers.storage; + let curr = builder.private_call.nullifiers.storage(); let output = builder.compose_from_previous_kernel(); @@ -181,9 +181,9 @@ fn new_from_previous_kernel_with_private_call_l2_to_l1_msgs_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.previous_kernel.append_l2_to_l1_msgs(1); - let prev = builder.previous_kernel.l2_to_l1_msgs.storage; + let prev = builder.previous_kernel.l2_to_l1_msgs.storage(); builder.private_call.append_l2_to_l1_msgs(1); - let curr = builder.private_call.l2_to_l1_msgs.storage; + let curr = builder.private_call.l2_to_l1_msgs.storage(); let output = builder.compose_from_previous_kernel(); @@ -195,9 +195,9 @@ fn new_from_previous_kernel_with_private_call_private_logs_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.previous_kernel.append_private_logs(2); - let prev = builder.previous_kernel.private_logs.storage; + let prev = builder.previous_kernel.private_logs.storage(); builder.private_call.append_private_logs(2); - let curr = builder.private_call.private_logs.storage; + let curr = builder.private_call.private_logs.storage(); let output = builder.compose_from_previous_kernel(); @@ -212,7 +212,7 @@ fn new_from_previous_kernel_with_private_call_contract_class_log_hashes_succeeds let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.private_call.add_contract_class_log_hash(2, 200); - let curr = builder.private_call.contract_class_logs_hashes.storage; + let curr = builder.private_call.contract_class_logs_hashes.storage(); let output = builder.compose_from_previous_kernel(); @@ -224,9 +224,9 @@ fn new_from_previous_kernel_with_private_call_private_call_requests_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.previous_kernel.append_private_call_requests(2); - let prev = builder.previous_kernel.private_call_requests.storage; + let prev = builder.previous_kernel.private_call_requests.storage(); builder.private_call.append_private_call_requests(2); - let curr = builder.private_call.private_call_requests.storage; + let curr = builder.private_call.private_call_requests.storage(); let output = builder.compose_from_previous_kernel(); @@ -242,9 +242,9 @@ fn new_from_previous_kernel_with_private_call_public_call_requests_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.previous_kernel.append_public_call_requests(2); - let prev = builder.previous_kernel.public_call_requests.storage; + let prev = builder.previous_kernel.public_call_requests.storage(); builder.private_call.append_public_call_requests(2); - let curr = builder.private_call.public_call_requests.storage; + let curr = builder.private_call.public_call_requests.storage(); let output = builder.compose_from_previous_kernel(); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/propagate_from_private_call.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/propagate_from_private_call.nr index c40e653f6f4..4446d2f45ad 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/propagate_from_private_call.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/propagate_from_private_call.nr @@ -57,7 +57,7 @@ fn propagate_from_private_call_note_hash_read_requests_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.private_call.append_note_hash_read_requests(2); - let res = builder.private_call.note_hash_read_requests.storage; + let res = builder.private_call.note_hash_read_requests.storage(); let output = builder.compose_from_tx_request(); @@ -72,7 +72,7 @@ fn propagate_from_private_call_nullifier_read_requests_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.private_call.append_nullifier_read_requests(2); - let res = builder.private_call.nullifier_read_requests.storage; + let res = builder.private_call.nullifier_read_requests.storage(); let output = builder.compose_from_tx_request(); @@ -87,7 +87,7 @@ fn propagate_from_private_call_key_validation_requests_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.private_call.append_key_validation_requests(2); - let res = builder.private_call.scoped_key_validation_requests_and_generators.storage; + let res = builder.private_call.scoped_key_validation_requests_and_generators.storage(); let output = builder.compose_from_tx_request(); @@ -102,7 +102,7 @@ fn propagate_from_private_call_note_hashes_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.private_call.append_note_hashes(2); - let res = builder.private_call.note_hashes.storage; + let res = builder.private_call.note_hashes.storage(); let output = builder.compose_from_tx_request(); @@ -114,7 +114,7 @@ fn propagate_from_private_call_nullifiers_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.private_call.append_nullifiers(2); - let res = builder.private_call.nullifiers.storage; + let res = builder.private_call.nullifiers.storage(); let tx_request = builder.tx_request; let first_nullifier = create_first_nullifier(tx_request); @@ -129,7 +129,7 @@ fn propagate_from_private_call_l2_to_l1_msgs_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.private_call.append_l2_to_l1_msgs(2); - let res = builder.private_call.l2_to_l1_msgs.storage; + let res = builder.private_call.l2_to_l1_msgs.storage(); let output = builder.compose_from_tx_request(); @@ -141,7 +141,7 @@ fn propagate_from_private_call_private_logs_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.private_call.append_private_logs(2); - let res = builder.private_call.private_logs.storage; + let res = builder.private_call.private_logs.storage(); let output = builder.compose_from_tx_request(); @@ -153,7 +153,7 @@ fn propagate_from_private_call_contract_class_log_hashes_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.private_call.add_contract_class_log_hash(2, 200); - let res = builder.private_call.contract_class_logs_hashes.storage; + let res = builder.private_call.contract_class_logs_hashes.storage(); let output = builder.compose_from_tx_request(); @@ -165,7 +165,7 @@ fn propagate_from_private_call_private_call_requests_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.private_call.append_private_call_requests(2); - let res = builder.private_call.private_call_requests.storage; + let res = builder.private_call.private_call_requests.storage(); let output = builder.compose_from_tx_request(); @@ -178,7 +178,7 @@ fn propagate_from_private_call_public_call_requests_succeeds() { let mut builder = PrivateKernelCircuitPublicInputsComposerBuilder::new(); builder.private_call.append_public_call_requests(2); - let res = builder.private_call.public_call_requests.storage; + let res = builder.private_call.public_call_requests.storage(); let output = builder.compose_from_tx_request(); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/reset_output_validator_builder/validate_sorted_siloed_note_hashes.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/reset_output_validator_builder/validate_sorted_siloed_note_hashes.nr index efdc0380020..1e8ce42cdbc 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/reset_output_validator_builder/validate_sorted_siloed_note_hashes.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/reset_output_validator_builder/validate_sorted_siloed_note_hashes.nr @@ -39,10 +39,13 @@ fn validate_sorted_siloed_note_hashes_mismatch_sorted_hash_fails() { builder.output.append_siloed_note_hashes(2); // Swap the hashes in the output. - let tmp = builder.output.note_hashes.storage[0].note_hash.value; - builder.output.note_hashes.storage[0].note_hash.value = - builder.output.note_hashes.storage[1].note_hash.value; - builder.output.note_hashes.storage[1].note_hash.value = tmp; + let mut note_hash_0 = builder.output.note_hashes.get(0); + let mut note_hash_1 = builder.output.note_hashes.get(1); + let tmp = note_hash_0.note_hash.value; + note_hash_0.note_hash.value = note_hash_1.note_hash.value; + note_hash_1.note_hash.value = tmp; + builder.output.note_hashes.set(0, note_hash_0); + builder.output.note_hashes.set(1, note_hash_1); builder.validate(); } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/reset_output_validator_builder/validate_sorted_siloed_nullifiers.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/reset_output_validator_builder/validate_sorted_siloed_nullifiers.nr index 5535dc2bcc7..3faa8572a31 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/reset_output_validator_builder/validate_sorted_siloed_nullifiers.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/reset_output_validator_builder/validate_sorted_siloed_nullifiers.nr @@ -52,10 +52,13 @@ fn validate_sorted_siloed_nullifiers_mismatch_sorted_hash_fails() { builder.output.append_siloed_nullifiers(3); // Swap the hashes in the output. - let tmp = builder.output.nullifiers.storage[0].nullifier.value; - builder.output.nullifiers.storage[0].nullifier.value = - builder.output.nullifiers.storage[1].nullifier.value; - builder.output.nullifiers.storage[1].nullifier.value = tmp; + let mut nullifier_0 = builder.output.nullifiers.get(0); + let mut nullifier_1 = builder.output.nullifiers.get(1); + let tmp = nullifier_0.nullifier.value; + nullifier_0.nullifier.value = nullifier_1.nullifier.value; + nullifier_1.nullifier.value = tmp; + builder.output.nullifiers.set(0, nullifier_0); + builder.output.nullifiers.set(1, nullifier_1); builder.validate(); } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/mod.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/mod.nr index 30a032dad21..c84cbeaab2b 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/mod.nr @@ -67,6 +67,6 @@ impl TailOutputValidatorBuilder { pub fn validate_with_hints(self, hints: TailOutputHints) { let output = self.export_output(); let previous_kernel = self.previous_kernel.to_private_kernel_circuit_public_inputs(); - TailOutputValidator { output, previous_kernel, hints }.validate(); + TailOutputValidator::new_with_hints(output, previous_kernel, hints).validate(); } } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_propagated_sorted_values.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_propagated_sorted_values.nr index 68924be6824..0ebdc3b8725 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_propagated_sorted_values.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_propagated_sorted_values.nr @@ -32,7 +32,9 @@ fn validate_propagated_sorted_values_l2_to_l1_msgs_mismatch_hash_fails() { builder.previous_kernel.append_l2_to_l1_msgs(2); builder.output.append_exposed_l2_to_l1_msgs(2); // Tweak the content in the output. - builder.output.l2_to_l1_msgs.storage[0].message.content += 1; + let mut msg = builder.output.l2_to_l1_msgs.get(0); + msg.message.content += 1; + builder.output.l2_to_l1_msgs.set(0, msg); builder.validate(); } @@ -57,7 +59,9 @@ fn validate_propagated_sorted_values_contract_class_log_hashes_mismatch_fails() builder.previous_kernel.add_contract_class_log_hash(3, 2); builder.output.add_contract_class_log_hash(3, 2); // Tweak the content in the output. - builder.output.contract_class_logs_hashes.storage[0].log_hash.value += 1; + let mut log_hash = builder.output.contract_class_logs_hashes.get(0); + log_hash.log_hash.value += 1; + builder.output.contract_class_logs_hashes.set(0, log_hash); builder.validate(); } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_propagated_values.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_propagated_values.nr index c5552e9cfc3..27d59065348 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_propagated_values.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_output_validator_builder/validate_propagated_values.nr @@ -137,7 +137,9 @@ fn validate_propagated_values_note_hashes_mismatch_fails() { builder.output.append_note_hashes(3); // Tweak the value at index 1. - builder.output.note_hashes.storage[1].note_hash.value += 1; + let mut note_hash = builder.output.note_hashes.get(1); + note_hash.note_hash.value += 1; + builder.output.note_hashes.set(1, note_hash); builder.validate(); } @@ -174,7 +176,9 @@ fn validate_propagated_values_nullifiers_mismatch_fails() { builder.output.append_nullifiers(3); // Tweak the value at index 1. - builder.output.nullifiers.storage[1].nullifier.value += 1; + let mut nullifier = builder.output.nullifiers.get(1); + nullifier.nullifier.value += 1; + builder.output.nullifiers.set(1, nullifier); builder.validate(); } @@ -211,7 +215,9 @@ fn validate_propagated_values_private_logs_mismatch_fails() { builder.output.append_private_logs(3); // Tweak the value at index 1. - builder.output.private_logs.storage[1].inner.log.fields[0] += 1; + let mut private_log = builder.output.private_logs.get(1); + private_log.inner.log.fields[0] += 1; + builder.output.private_logs.set(1, private_log); builder.validate(); } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_to_public_output_composer_builder/split_to_public.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_to_public_output_composer_builder/split_to_public.nr index a657138cbee..fe799d793e8 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_to_public_output_composer_builder/split_to_public.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_to_public_output_composer_builder/split_to_public.nr @@ -1,4 +1,4 @@ -use crate::components::tail_to_public_output_composer::split_to_public::split_to_public; +use crate::components::tail_to_public_output_composer::split_to_public; use dep::types::tests::{fixture_builder::FixtureBuilder, utils::assert_array_eq}; #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/key_validation_hint.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/key_validation_hint.nr index dc15f06d7f0..5786424f639 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/key_validation_hint.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/key_validation_hint.nr @@ -1,8 +1,6 @@ -// TODO: For some reason this file requires `IndexedTreeLeafPreimage` but it's unclear why. use dep::types::{ abis::validation_requests::ScopedKeyValidationRequestAndGenerator, - hash::poseidon2_hash_with_separator, merkle_tree::IndexedTreeLeafPreimage, scalar::Scalar, - traits::Empty, + hash::poseidon2_hash_with_separator, scalar::Scalar, traits::Empty, }; use std::embedded_curve_ops::fixed_base_scalar_mul as derive_public_key; diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/note_hash_read_request_hints_builder.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/note_hash_read_request_hints_builder.nr index a396244a5a6..966a1a27fa0 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/note_hash_read_request_hints_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/note_hash_read_request_hints_builder.nr @@ -14,25 +14,21 @@ impl NoteHashReadRequest pub fn new() -> Self { NoteHashReadRequestHintsBuilder { read_request_statuses: [ReadRequestStatus::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_TX], - pending_read_hints: BoundedVec { - storage: [ - PendingReadHint::nada(MAX_NOTE_HASH_READ_REQUESTS_PER_TX); NUM_PENDING_HINTS - ], - len: 0, - }, - settled_read_hints: BoundedVec { - storage: [ + pending_read_hints: BoundedVec::from_parts_unchecked( + [PendingReadHint::nada(MAX_NOTE_HASH_READ_REQUESTS_PER_TX); NUM_PENDING_HINTS], + 0, + ), + settled_read_hints: BoundedVec::from_parts_unchecked( + [ NoteHashSettledReadHint::nada(MAX_NOTE_HASH_READ_REQUESTS_PER_TX); NUM_SETTLED_HINTS ], - len: 0, - }, + 0, + ), } } - pub unconstrained fn to_hints( - self, - ) -> NoteHashReadRequestHints { + pub fn to_hints(self) -> NoteHashReadRequestHints { NoteHashReadRequestHints { read_request_statuses: self.read_request_statuses, pending_read_hints: self.pending_read_hints.storage(), diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_read_request_hints_builder.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_read_request_hints_builder.nr index ddd28b07ebc..720e58b699b 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_read_request_hints_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_read_request_hints_builder.nr @@ -14,25 +14,21 @@ impl NullifierReadReques pub fn new() -> Self { NullifierReadRequestHintsBuilder { read_request_statuses: [ReadRequestStatus::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX], - pending_read_hints: BoundedVec { - storage: [ - PendingReadHint::nada(MAX_NULLIFIER_READ_REQUESTS_PER_TX); NUM_PENDING_HINTS - ], - len: 0, - }, - settled_read_hints: BoundedVec { - storage: [ + pending_read_hints: BoundedVec::from_parts_unchecked( + [PendingReadHint::nada(MAX_NULLIFIER_READ_REQUESTS_PER_TX); NUM_PENDING_HINTS], + 0, + ), + settled_read_hints: BoundedVec::from_parts_unchecked( + [ NullifierSettledReadHint::nada(MAX_NULLIFIER_READ_REQUESTS_PER_TX); NUM_SETTLED_HINTS ], - len: 0, - }, + 0, + ), } } - pub unconstrained fn to_hints( - self, - ) -> NullifierReadRequestHints { + pub fn to_hints(self) -> NullifierReadRequestHints { NullifierReadRequestHints { read_request_statuses: self.read_request_statuses, pending_read_hints: self.pending_read_hints.storage(), diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr index 40a7a09f8fb..24f3d79ddc4 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr @@ -12,23 +12,23 @@ pub(crate) global MERGE_ROLLUP_TYPE: u32 = 1; pub struct BaseOrMergeRollupPublicInputs { // rollup_type is either 0 (base) or 1 (merge) // TODO(Kev): Why is this a u32 instead of a u8/u16? - rollup_type: u32, - num_txs: u32, - constants: ConstantRollupData, + pub rollup_type: u32, + pub num_txs: u32, + pub constants: ConstantRollupData, - start: PartialStateReference, - end: PartialStateReference, + pub start: PartialStateReference, + pub end: PartialStateReference, // We hash public inputs to make them constant-sized (to then be unpacked on-chain) // U128 isn't safe if it's an input to the circuit (it won't automatically constrain the witness) // So we want to constrain it when casting these fields to U128 // We hash public inputs to make them constant-sized (to then be unpacked on-chain) - txs_effects_hash: Field, - out_hash: Field, + pub txs_effects_hash: Field, + pub out_hash: Field, - accumulated_fees: Field, - accumulated_mana_used: Field, + pub accumulated_fees: Field, + pub accumulated_mana_used: Field, } impl Empty for BaseOrMergeRollupPublicInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/block_root_or_block_merge_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/block_root_or_block_merge_public_inputs.nr index d325e1d2ed3..5834b57303e 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/block_root_or_block_merge_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/block_root_or_block_merge_public_inputs.nr @@ -10,8 +10,8 @@ use dep::types::{ }; pub struct FeeRecipient { - recipient: EthAddress, - value: Field, + pub recipient: EthAddress, + pub value: Field, } // TODO(#7346): Should the default empty value be MAX_FIELD? The zero addr may be a valid recipient @@ -42,21 +42,21 @@ impl Eq for FeeRecipient { // TODO: instead of archives + global vars, use ConstantRollupData x2? It also includes vk root // may be confusing as new_constant.last_archive would actually be the new_archive pub struct BlockRootOrBlockMergePublicInputs { - previous_archive: AppendOnlyTreeSnapshot, // Archive tree root immediately before this block range - new_archive: AppendOnlyTreeSnapshot, // Archive tree root after adding this block range - previous_block_hash: Field, // Identifier of the previous block before the range - end_block_hash: Field, // Identifier of the last block in the range - start_global_variables: GlobalVariables, // Global variables for the first block in the range - end_global_variables: GlobalVariables, // Global variables for the last block in the range - out_hash: Field, // Merkle node of the L2-to-L1 messages merkle roots in the block range - fees: [FeeRecipient; AZTEC_MAX_EPOCH_DURATION], // Concatenation of all coinbase and fees for the block range - vk_tree_root: Field, // Root of allowed vk tree - protocol_contract_tree_root: Field, // Root of protocol contract tree - prover_id: Field, // TODO(#7346): Temporarily added prover_id while we verify block-root proofs on L1 + pub previous_archive: AppendOnlyTreeSnapshot, // Archive tree root immediately before this block range + pub new_archive: AppendOnlyTreeSnapshot, // Archive tree root after adding this block range + pub previous_block_hash: Field, // Identifier of the previous block before the range + pub end_block_hash: Field, // Identifier of the last block in the range + pub start_global_variables: GlobalVariables, // Global variables for the first block in the range + pub end_global_variables: GlobalVariables, // Global variables for the last block in the range + pub out_hash: Field, // Merkle node of the L2-to-L1 messages merkle roots in the block range + pub fees: [FeeRecipient; AZTEC_MAX_EPOCH_DURATION], // Concatenation of all coinbase and fees for the block range + pub vk_tree_root: Field, // Root of allowed vk tree + pub protocol_contract_tree_root: Field, // Root of protocol contract tree + pub prover_id: Field, // TODO(#7346): Temporarily added prover_id while we verify block-root proofs on L1 } impl BlockRootOrBlockMergePublicInputs { - fn is_padding(self) -> bool { + pub fn is_padding(self) -> bool { self.previous_archive == self.new_archive } } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr index 6c2297ce367..224c0d9258a 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr @@ -12,10 +12,10 @@ use dep::types::{ }; pub struct PreviousRollupBlockData { - block_root_or_block_merge_public_inputs: BlockRootOrBlockMergePublicInputs, - proof: NestedRecursiveProof, - vk: HonkVerificationKey, - vk_witness: MembershipWitness, + pub block_root_or_block_merge_public_inputs: BlockRootOrBlockMergePublicInputs, + pub proof: NestedRecursiveProof, + pub vk: HonkVerificationKey, + pub vk_witness: MembershipWitness, } impl Verifiable for PreviousRollupBlockData { @@ -39,7 +39,7 @@ impl Empty for PreviousRollupBlockData { } impl PreviousRollupBlockData { - fn validate_in_vk_tree(self, allowed_indices: [u32; N]) { + pub fn validate_in_vk_tree(self, allowed_indices: [u32; N]) { self.vk.check_hash(); let leaf_index = self.vk_witness.leaf_index as u32; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr index a796a128fdb..b4248fc2946 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr @@ -12,10 +12,10 @@ use dep::types::{ }; pub struct PreviousRollupData { - base_or_merge_rollup_public_inputs: BaseOrMergeRollupPublicInputs, - proof: NestedRecursiveProof, - vk: HonkVerificationKey, - vk_witness: MembershipWitness, + pub base_or_merge_rollup_public_inputs: BaseOrMergeRollupPublicInputs, + pub proof: NestedRecursiveProof, + pub vk: HonkVerificationKey, + pub vk_witness: MembershipWitness, } impl Verifiable for PreviousRollupData { @@ -38,7 +38,7 @@ impl Empty for PreviousRollupData { } impl PreviousRollupData { - fn validate_in_vk_tree(self, allowed_indices: [u32; N]) { + pub fn validate_in_vk_tree(self, allowed_indices: [u32; N]) { self.vk.check_hash(); let leaf_index = self.vk_witness.leaf_index as u32; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/private_base_rollup.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/private_base_rollup.nr index e1c000a7b78..ff3347285ef 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/private_base_rollup.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/private_base_rollup.nr @@ -21,7 +21,6 @@ use dep::types::{ }, constants::{ ARCHIVE_HEIGHT, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NOTE_HASH_SUBTREE_HEIGHT, - PRIVATE_KERNEL_EMPTY_INDEX, TUBE_VK_INDEX, }, data::{hash::compute_public_data_tree_value, public_data_hint::PublicDataHint}, hash::silo_l2_to_l1_message, @@ -33,7 +32,7 @@ use dep::types::{ traits::is_empty, }; -global ALLOWED_PREVIOUS_CIRCUITS: [u32; 2] = [PRIVATE_KERNEL_EMPTY_INDEX, TUBE_VK_INDEX]; +// global ALLOWED_PREVIOUS_CIRCUITS: [u32; 2] = [PRIVATE_KERNEL_EMPTY_INDEX, TUBE_VK_INDEX]; pub struct PrivateBaseRollupInputs { tube_data: PrivateTubeData, @@ -250,7 +249,11 @@ mod tests { merkle_tree::MembershipWitness, messaging::l2_to_l1_message::ScopedL2ToL1Message, partial_state_reference::PartialStateReference, - tests::{fixture_builder::FixtureBuilder, fixtures, merkle_tree_utils::NonEmptyMerkleTree}, + tests::{ + fixture_builder::FixtureBuilder, + fixtures::{self, merkle_tree::generate_full_sha_tree}, + merkle_tree_utils::NonEmptyMerkleTree, + }, traits::{Empty, is_empty}, utils::{ arrays::get_sorted_tuple::get_sorted_tuple, @@ -400,7 +403,7 @@ mod tests { let sorted_new_nullifier_tuples = unsafe { get_sorted_tuple( - self.nullifiers.storage.map(|insertion: NullifierInsertion| insertion.value), + self.nullifiers.storage().map(|insertion: NullifierInsertion| insertion.value), |a, b| full_field_less_than(b, a), ) }; @@ -804,9 +807,7 @@ mod tests { ); // Since we fill the tree completely, we know to expect a full tree as below - let expected_tree = dep::types::merkle_tree::variable_merkle_tree::tests::generate_full_sha_tree( - siloed_l2_to_l1_msgs.storage(), - ); + let expected_tree = generate_full_sha_tree(siloed_l2_to_l1_msgs.storage()); assert_eq(out_hash, expected_tree.get_root()); } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/public_base_rollup.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/public_base_rollup.nr index ce7add25489..6c5d6d65b6c 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/public_base_rollup.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/public_base_rollup.nr @@ -380,7 +380,11 @@ mod tests { merkle_tree::MembershipWitness, messaging::l2_to_l1_message::ScopedL2ToL1Message, partial_state_reference::PartialStateReference, - tests::{fixture_builder::FixtureBuilder, fixtures, merkle_tree_utils::NonEmptyMerkleTree}, + tests::{ + fixture_builder::FixtureBuilder, + fixtures::{self, merkle_tree::generate_full_sha_tree}, + merkle_tree_utils::NonEmptyMerkleTree, + }, traits::{Empty, is_empty}, utils::{ arrays::get_sorted_tuple::get_sorted_tuple, @@ -547,7 +551,7 @@ mod tests { let sorted_new_nullifier_tuples = unsafe { get_sorted_tuple( - self.nullifiers.storage.map(|insertion: NullifierInsertion| insertion.value), + self.nullifiers.storage().map(|insertion: NullifierInsertion| insertion.value), |a, b| full_field_less_than(b, a), ) }; @@ -680,8 +684,8 @@ mod tests { let mut final_public_data_writes: BoundedVec<(u32, PublicDataTreeLeaf), MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX> = BoundedVec::new(); - final_public_data_writes.extend_from_array(self.public_data_writes.storage); - final_public_data_writes.extend_from_array(self.protocol_public_data_writes.storage); + final_public_data_writes.extend_from_array(self.public_data_writes.storage()); + final_public_data_writes.extend_from_array(self.protocol_public_data_writes.storage()); for i in 0..self.overwritten_public_data_writes.len() { if self.overwritten_public_data_writes[i].is_some() { final_public_data_writes.set( @@ -986,9 +990,7 @@ mod tests { ); // Since we fill the tree completely, we know to expect a full tree as below - let expected_tree = dep::types::merkle_tree::variable_merkle_tree::tests::generate_full_sha_tree( - siloed_l2_to_l1_msgs.storage(), - ); + let expected_tree = generate_full_sha_tree(siloed_l2_to_l1_msgs.storage()); assert_eq(out_hash, expected_tree.get_root()); } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/state_diff_hints.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/state_diff_hints.nr index 65d27104795..f34019c544d 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/state_diff_hints.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/state_diff_hints.nr @@ -5,7 +5,7 @@ use dep::types::{ NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH, NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH, NULLIFIER_TREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT, }, - data::{PublicDataTreeLeaf, PublicDataTreeLeafPreimage}, + data::PublicDataTreeLeafPreimage, merkle_tree::MembershipWitness, }; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr index bd4bdf585e3..0206da8b61a 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr @@ -6,7 +6,7 @@ use dep::types::{constants::{BLOCK_MERGE_ROLLUP_INDEX, BLOCK_ROOT_ROLLUP_INDEX}, global ALLOWED_PREVIOUS_CIRCUITS: [u32; 2] = [BLOCK_ROOT_ROLLUP_INDEX, BLOCK_MERGE_ROLLUP_INDEX]; pub struct BlockMergeRollupInputs { - previous_rollup_data: [PreviousRollupBlockData; 2], + pub previous_rollup_data: [PreviousRollupBlockData; 2], } impl Empty for BlockMergeRollupInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr index ea137243a54..e2e7b0bd5c4 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr @@ -26,26 +26,26 @@ global ALLOWED_PREVIOUS_CIRCUITS: [u32; 3] = pub struct BlockRootRollupInputs { // All below are shared between the base and merge rollups - previous_rollup_data: [PreviousRollupData; 2], + pub previous_rollup_data: [PreviousRollupData; 2], - l1_to_l2_roots: RootRollupParityInput, + pub l1_to_l2_roots: RootRollupParityInput, // inputs required to process l1 to l2 messages - l1_to_l2_messages: [Field; NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP], - l1_to_l2_message_subtree_sibling_path: [Field; L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH], + pub l1_to_l2_messages: [Field; NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP], + pub l1_to_l2_message_subtree_sibling_path: [Field; L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH], - start_l1_to_l2_message_tree_snapshot: AppendOnlyTreeSnapshot, + pub start_l1_to_l2_message_tree_snapshot: AppendOnlyTreeSnapshot, // inputs required to add the block hash // TODO: Remove in favor of left.constants.last_archive - start_archive_snapshot: AppendOnlyTreeSnapshot, - new_archive_sibling_path: [Field; ARCHIVE_HEIGHT], + pub start_archive_snapshot: AppendOnlyTreeSnapshot, + pub new_archive_sibling_path: [Field; ARCHIVE_HEIGHT], // Added previous_block_hash to be passed through to the final root, where it will be either: // - checked on L1 for first block in batch // - checked against previous block_root.end_block_hash in a block_merge - previous_block_hash: Field, + pub previous_block_hash: Field, // TODO(#7346): Temporarily added prover_id while we verify block-root proofs on L1 - prover_id: Field, + pub prover_id: Field, } impl BlockRootRollupInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/components.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/components.nr index 508aa5c2b39..6db3d9272eb 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/components.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/components.nr @@ -231,7 +231,7 @@ fn silo_and_hash_unencrypted_logs( // __ // 1 unencrypted logs hash --> 1 sha256 hash -> 31 bytes -> 1 fields | Beware when populating bytes that we fill (prepend) to 32! |-> 2 types of flexible-length logs - 2 fields for their hashes // 1 contract class logs hash --> 1 sha256 hash -> 31 bytes -> 1 fields | Beware when populating bytes that we fill (prepend) to 32! __| -global TX_EFFECTS_HASH_INPUT_FIELDS: u32 = 1 +pub global TX_EFFECTS_HASH_INPUT_FIELDS: u32 = 1 + 1 + MAX_NOTE_HASHES_PER_TX + MAX_NULLIFIERS_PER_TX diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr index 0b4867533f8..5253c3cc412 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr @@ -13,7 +13,7 @@ global ALLOWED_PREVIOUS_CIRCUITS: [u32; 3] = pub struct MergeRollupInputs { // TODO(Kev): Why is this 2? - previous_rollup_data: [PreviousRollupData; 2], + pub previous_rollup_data: [PreviousRollupData; 2], } impl Empty for MergeRollupInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/mod.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/mod.nr index acc9b715235..44c523a1e7b 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/mod.nr @@ -1,5 +1,5 @@ -mod root_rollup_inputs; -mod root_rollup_public_inputs; +pub mod root_rollup_inputs; +pub mod root_rollup_public_inputs; // Re-exports pub use root_rollup_inputs::RootRollupInputs; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr index 1b4e6343ff0..490d6dd2116 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr @@ -11,8 +11,8 @@ global ALLOWED_PREVIOUS_CIRCUITS: [u32; 3] = [BLOCK_ROOT_ROLLUP_INDEX, BLOCK_MERGE_ROLLUP_INDEX, BLOCK_ROOT_ROLLUP_EMPTY_INDEX]; pub struct RootRollupInputs { - previous_rollup_data: [PreviousRollupBlockData; 2], - prover_id: Field, + pub previous_rollup_data: [PreviousRollupBlockData; 2], + pub prover_id: Field, } impl Empty for RootRollupInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_public_inputs.nr index 2383e1481e1..d24568e1a2b 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_public_inputs.nr @@ -4,15 +4,15 @@ use dep::types::constants::AZTEC_MAX_EPOCH_DURATION; pub struct RootRollupPublicInputs { // Snapshot of archive tree before/after this rollup has been processed - previous_archive: AppendOnlyTreeSnapshot, - end_archive: AppendOnlyTreeSnapshot, - previous_block_hash: Field, - end_block_hash: Field, - end_timestamp: u64, - end_block_number: Field, - out_hash: Field, - fees: [FeeRecipient; AZTEC_MAX_EPOCH_DURATION], - vk_tree_root: Field, - protocol_contract_tree_root: Field, - prover_id: Field, + pub previous_archive: AppendOnlyTreeSnapshot, + pub end_archive: AppendOnlyTreeSnapshot, + pub previous_block_hash: Field, + pub end_block_hash: Field, + pub end_timestamp: u64, + pub end_block_number: Field, + pub out_hash: Field, + pub fees: [FeeRecipient; AZTEC_MAX_EPOCH_DURATION], + pub vk_tree_root: Field, + pub protocol_contract_tree_root: Field, + pub prover_id: Field, } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/block_merge_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/block_merge_rollup_inputs.nr index d76ccc5e873..7f19df3f12e 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/block_merge_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/block_merge_rollup_inputs.nr @@ -1,4 +1,4 @@ -use crate::block_merge::block_merge_rollup_inputs::BlockMergeRollupInputs; +use crate::block_merge::BlockMergeRollupInputs; use crate::tests::previous_rollup_block_data::default_previous_rollup_block_data; pub fn default_block_merge_rollup_inputs() -> BlockMergeRollupInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/block_root_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/block_root_rollup_inputs.nr index 7a213dc35da..3d33d83ad26 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/block_root_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/block_root_rollup_inputs.nr @@ -1,4 +1,4 @@ -use crate::block_root::block_root_rollup_inputs::BlockRootRollupInputs; +use crate::block_root::BlockRootRollupInputs; use crate::tests::l1_to_l2_roots::default_root_rollup_parity_input; use crate::tests::previous_rollup_data::default_previous_rollup_data; use dep::types::{ diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/merge_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/merge_rollup_inputs.nr index 088c3158aab..d2a2cbc56fa 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/merge_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/merge_rollup_inputs.nr @@ -1,4 +1,4 @@ -use crate::merge::merge_rollup_inputs::MergeRollupInputs; +use crate::merge::MergeRollupInputs; use crate::tests::previous_rollup_data::default_previous_rollup_data; pub fn default_merge_rollup_inputs() -> MergeRollupInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/mod.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/mod.nr index d1806e911c8..ff187b5dd43 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/mod.nr @@ -1,7 +1,7 @@ -mod merge_rollup_inputs; -mod block_root_rollup_inputs; -mod block_merge_rollup_inputs; -mod root_rollup_inputs; -mod previous_rollup_data; -mod previous_rollup_block_data; -mod l1_to_l2_roots; +pub(crate) mod merge_rollup_inputs; +pub(crate) mod block_root_rollup_inputs; +pub(crate) mod block_merge_rollup_inputs; +pub(crate) mod root_rollup_inputs; +pub(crate) mod previous_rollup_data; +pub(crate) mod previous_rollup_block_data; +pub(crate) mod l1_to_l2_roots; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/avm_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/avm_accumulated_data.nr index b87516dfbf7..2716b752fe7 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/avm_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/avm_accumulated_data.nr @@ -1,5 +1,5 @@ use crate::{ - abis::{gas::Gas, log_hash::ScopedLogHash, public_data_write::PublicDataWrite}, + abis::{log_hash::ScopedLogHash, public_data_write::PublicDataWrite}, constants::{ AVM_ACCUMULATED_DATA_LENGTH, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX, @@ -11,16 +11,16 @@ use crate::{ pub struct AvmAccumulatedData { // The note hashes from private combining with those made in the AVM execution. - note_hashes: [Field; MAX_NOTE_HASHES_PER_TX], + pub note_hashes: [Field; MAX_NOTE_HASHES_PER_TX], // The nullifiers from private combining with those made in the AVM execution. - nullifiers: [Field; MAX_NULLIFIERS_PER_TX], + pub nullifiers: [Field; MAX_NULLIFIERS_PER_TX], // The L2 to L1 messages from private combining with those made in the AVM execution. - l2_to_l1_msgs: [ScopedL2ToL1Message; MAX_L2_TO_L1_MSGS_PER_TX], + pub l2_to_l1_msgs: [ScopedL2ToL1Message; MAX_L2_TO_L1_MSGS_PER_TX], // TODO(#9589): This should only contain logs emitted from public. // The unencrypted logs emitted from private combining with those made in the AVM execution. - unencrypted_logs_hashes: [ScopedLogHash; MAX_UNENCRYPTED_LOGS_PER_TX], + pub unencrypted_logs_hashes: [ScopedLogHash; MAX_UNENCRYPTED_LOGS_PER_TX], // The public data writes made in the AVM execution. - public_data_writes: [PublicDataWrite; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], + pub public_data_writes: [PublicDataWrite; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], } impl Empty for AvmAccumulatedData { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_to_public_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_to_public_accumulated_data_builder.nr index 8d32e356de7..dd2625af85a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_to_public_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_to_public_accumulated_data_builder.nr @@ -13,16 +13,16 @@ use crate::{ }; pub struct PrivateToPublicAccumulatedDataBuilder { - note_hashes: BoundedVec, - nullifiers: BoundedVec, - l2_to_l1_msgs: BoundedVec, - private_logs: BoundedVec, - contract_class_logs_hashes: BoundedVec, - public_call_requests: BoundedVec, + pub note_hashes: BoundedVec, + pub nullifiers: BoundedVec, + pub l2_to_l1_msgs: BoundedVec, + pub private_logs: BoundedVec, + pub contract_class_logs_hashes: BoundedVec, + pub public_call_requests: BoundedVec, } impl PrivateToPublicAccumulatedDataBuilder { - pub fn new(data: PrivateToPublicAccumulatedData) -> Self { + pub unconstrained fn new(data: PrivateToPublicAccumulatedData) -> Self { PrivateToPublicAccumulatedDataBuilder { note_hashes: array_to_bounded_vec(data.note_hashes), nullifiers: array_to_bounded_vec(data.nullifiers), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/avm_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/avm_circuit_public_inputs.nr index b88a123a1fd..43dc792b522 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/avm_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/avm_circuit_public_inputs.nr @@ -26,25 +26,25 @@ use std::hash::{poseidon2, poseidon2_permutation}; pub struct AvmCircuitPublicInputs { /////////////////////////////////// // Inputs. - global_variables: GlobalVariables, - start_tree_snapshots: TreeSnapshots, - start_gas_used: Gas, - gas_settings: GasSettings, - public_setup_call_requests: [PublicCallRequest; MAX_ENQUEUED_CALLS_PER_TX], - public_app_logic_call_requests: [PublicCallRequest; MAX_ENQUEUED_CALLS_PER_TX], - public_teardown_call_request: PublicCallRequest, - previous_non_revertible_accumulated_data_array_lengths: PrivateToAvmAccumulatedDataArrayLengths, - previous_revertible_accumulated_data_array_lengths: PrivateToAvmAccumulatedDataArrayLengths, - previous_non_revertible_accumulated_data: PrivateToAvmAccumulatedData, - previous_revertible_accumulated_data: PrivateToAvmAccumulatedData, + pub global_variables: GlobalVariables, + pub start_tree_snapshots: TreeSnapshots, + pub start_gas_used: Gas, + pub gas_settings: GasSettings, + pub public_setup_call_requests: [PublicCallRequest; MAX_ENQUEUED_CALLS_PER_TX], + pub public_app_logic_call_requests: [PublicCallRequest; MAX_ENQUEUED_CALLS_PER_TX], + pub public_teardown_call_request: PublicCallRequest, + pub previous_non_revertible_accumulated_data_array_lengths: PrivateToAvmAccumulatedDataArrayLengths, + pub previous_revertible_accumulated_data_array_lengths: PrivateToAvmAccumulatedDataArrayLengths, + pub previous_non_revertible_accumulated_data: PrivateToAvmAccumulatedData, + pub previous_revertible_accumulated_data: PrivateToAvmAccumulatedData, /////////////////////////////////// // Outputs. - end_tree_snapshots: TreeSnapshots, - end_gas_used: Gas, - accumulated_data: AvmAccumulatedData, - transaction_fee: Field, - reverted: bool, + pub end_tree_snapshots: TreeSnapshots, + pub end_gas_used: Gas, + pub accumulated_data: AvmAccumulatedData, + pub transaction_fee: Field, + pub reverted: bool, } impl Empty for AvmCircuitPublicInputs { @@ -205,7 +205,7 @@ impl AvmProofData { ); let mut result: [Field; 4] = [input_hash, 0, 0, 0]; - for i in 0..DUMMY_AVM_VERIFIER_NUM_ITERATIONS { + for _i in 0..DUMMY_AVM_VERIFIER_NUM_ITERATIONS { result = poseidon2_permutation(result, 4); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas.nr index ccd0c236802..2a2ad1aa12a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas.nr @@ -6,8 +6,8 @@ use crate::{ use std::ops::{Add, Sub}; pub struct Gas { - da_gas: u32, - l2_gas: u32, + pub da_gas: u32, + pub l2_gas: u32, } impl Gas { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_settings.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_settings.nr index 457f1fb5a8a..42301eb096d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_settings.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_settings.nr @@ -1,14 +1,14 @@ use crate::{ abis::{gas::Gas, gas_fees::GasFees}, - constants::{DEFAULT_GAS_LIMIT, DEFAULT_TEARDOWN_GAS_LIMIT, GAS_SETTINGS_LENGTH}, + constants::GAS_SETTINGS_LENGTH, traits::{Deserialize, Empty, Serialize}, utils::reader::Reader, }; pub struct GasSettings { - gas_limits: Gas, - teardown_gas_limits: Gas, - max_fees_per_gas: GasFees, + pub gas_limits: Gas, + pub teardown_gas_limits: Gas, + pub max_fees_per_gas: GasFees, } impl GasSettings { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs_builder.nr index 1cee9d2d80b..3c0aab077c5 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs_builder.nr @@ -10,12 +10,12 @@ use crate::{ }; pub struct PrivateKernelCircuitPublicInputsBuilder { - constants: TxConstantData, - min_revertible_side_effect_counter: u32, - validation_requests: PrivateValidationRequestsBuilder, - end: PrivateAccumulatedDataBuilder, - public_teardown_call_request: PublicCallRequest, - fee_payer: AztecAddress, + pub constants: TxConstantData, + pub min_revertible_side_effect_counter: u32, + pub validation_requests: PrivateValidationRequestsBuilder, + pub end: PrivateAccumulatedDataBuilder, + pub public_teardown_call_request: PublicCallRequest, + pub fee_payer: AztecAddress, } impl PrivateKernelCircuitPublicInputsBuilder { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr index e272ede7eaa..63540dcbb37 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel_data.nr @@ -14,7 +14,7 @@ pub struct PrivateKernelData { } impl PrivateKernelData { - fn validate_in_vk_tree(self, allowed_indices: [u32; N]) { + pub fn validate_in_vk_tree(self, allowed_indices: [u32; N]) { self.vk.check_hash(); let index_in_allowed_list = if self.vk_index >= PRIVATE_KERNEL_RESET_INDEX { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/tree_snapshots.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/tree_snapshots.nr index 59863026a5b..7fb6948bfcb 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/tree_snapshots.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/tree_snapshots.nr @@ -5,10 +5,10 @@ use crate::{ }; pub struct TreeSnapshots { - l1_to_l2_message_tree: AppendOnlyTreeSnapshot, - note_hash_tree: AppendOnlyTreeSnapshot, - nullifier_tree: AppendOnlyTreeSnapshot, - public_data_tree: AppendOnlyTreeSnapshot, + pub l1_to_l2_message_tree: AppendOnlyTreeSnapshot, + pub note_hash_tree: AppendOnlyTreeSnapshot, + pub nullifier_tree: AppendOnlyTreeSnapshot, + pub public_data_tree: AppendOnlyTreeSnapshot, } impl Eq for TreeSnapshots { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/tube.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/tube.nr index e36c2ead478..3638c6bd368 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/tube.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/tube.nr @@ -25,7 +25,7 @@ impl Verifiable for PublicTubeData { } pub struct PrivateTubeData { - public_inputs: KernelCircuitPublicInputs, + pub public_inputs: KernelCircuitPublicInputs, proof: TubeProof, vk_data: VkData, } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/private_validation_requests_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/private_validation_requests_builder.nr index c5b0ddbb5e9..d8a64ceeddf 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/private_validation_requests_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/private_validation_requests_builder.nr @@ -16,11 +16,11 @@ use crate::{ }; pub struct PrivateValidationRequestsBuilder { - max_block_number: MaxBlockNumber, - note_hash_read_requests: BoundedVec, - nullifier_read_requests: BoundedVec, - scoped_key_validation_requests_and_generators: BoundedVec, - split_counter: Option, + pub max_block_number: MaxBlockNumber, + pub note_hash_read_requests: BoundedVec, + pub nullifier_read_requests: BoundedVec, + pub scoped_key_validation_requests_and_generators: BoundedVec, + pub split_counter: Option, } impl PrivateValidationRequestsBuilder { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index aee6a3d9127..f68acffd074 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -136,7 +136,7 @@ pub global GENESIS_ARCHIVE_ROOT: Field = 0x0237797d6a2c04d20d4fa06b74482bd970ccd51a43d9b05b57e9b91fa1ae1cae; // The following and the value in `deploy_l1_contracts` must match. We should not have the code both places, but // we are running into circular dependency issues. #3342 -global FEE_JUICE_INITIAL_MINT: Field = 200000000000000000000; +pub global FEE_JUICE_INITIAL_MINT: Field = 200000000000000000000; // Last 4 bytes of the Poseidon2 hash of 'public_dispatch(Field)'. pub global PUBLIC_DISPATCH_SELECTOR: Field = 0xd5441b0d; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/content_commitment.nr b/noir-projects/noir-protocol-circuits/crates/types/src/content_commitment.nr index a02e7f8e46c..3fb70c4fbb4 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/content_commitment.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/content_commitment.nr @@ -1,10 +1,10 @@ use crate::{constants::CONTENT_COMMITMENT_LENGTH, traits::{Deserialize, Empty, Serialize}}; pub struct ContentCommitment { - num_txs: Field, - txs_effects_hash: Field, - in_hash: Field, - out_hash: Field, + pub num_txs: Field, + pub txs_effects_hash: Field, + pub in_hash: Field, + pub out_hash: Field, } impl Serialize for ContentCommitment { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_hint.nr b/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_hint.nr index f2371ea7871..0e05f3ba021 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_hint.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_hint.nr @@ -6,10 +6,10 @@ use crate::{ }; pub struct PublicDataHint { - leaf_slot: Field, - value: Field, - membership_witness: MembershipWitness, - leaf_preimage: PublicDataTreeLeafPreimage, + pub leaf_slot: Field, + pub value: Field, + pub membership_witness: MembershipWitness, + pub leaf_preimage: PublicDataTreeLeafPreimage, } impl PublicDataHint { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr index f8d1bf3b464..6f7914d4825 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr @@ -18,7 +18,7 @@ use crate::{ traits::{is_empty, ToField}, utils::field::field_from_bytes_32_trunc, }; -use super::utils::field::field_from_bytes; +use super::utils::{arrays::array_concat, field::field_from_bytes}; pub fn sha256_to_field(bytes_to_hash: [u8; N]) -> Field { let sha256_hashed = std::hash::sha256(bytes_to_hash); @@ -230,18 +230,8 @@ pub fn poseidon2_hash_with_separator(inputs: [Field; N], separato where T: ToField, { - // We manually hash the inputs here, since we cannot express with the type system a constant size inputs array of N + 1 - let in_len = N + 1; - let two_pow_64 = 18446744073709551616; - let iv: Field = (in_len as Field) * two_pow_64; - let mut sponge = std::hash::poseidon2::Poseidon2::new(iv); - sponge.absorb(separator.to_field()); - - for i in 0..inputs.len() { - sponge.absorb(inputs[i]); - } - - sponge.squeeze() + let inputs_with_separator = array_concat([separator.to_field()], inputs); + poseidon2_hash(inputs_with_separator) } pub fn poseidon2_hash_with_separator_slice(inputs: [Field], separator: T) -> Field @@ -263,32 +253,22 @@ where #[no_predicates] pub fn poseidon2_hash_bytes(inputs: [u8; N]) -> Field { - // We manually hash the inputs here, since we cannot express with the type system a constant size inputs array of Math.ceil(N/31) - let mut in_len = N / 31; - let mut has_padding = false; - if N % 31 != 0 { - in_len += 1; - has_padding = true; - } - - let two_pow_64 = 18446744073709551616; - let iv: Field = (in_len as Field) * two_pow_64; - let mut sponge = std::hash::poseidon2::Poseidon2::new(iv); - + let mut fields = [0; (N + 30) / 31]; + let mut field_index = 0; let mut current_field = [0; 31]; for i in 0..inputs.len() { let index = i % 31; current_field[index] = inputs[i]; if index == 30 { - sponge.absorb(field_from_bytes(current_field, false)); + fields[field_index] = field_from_bytes(current_field, false); current_field = [0; 31]; + field_index += 1; } } - if has_padding { - sponge.absorb(field_from_bytes(current_field, false)); + if field_index != fields.len() { + fields[field_index] = field_from_bytes(current_field, false); } - - sponge.squeeze() + poseidon2_hash(fields) } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/variable_merkle_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/variable_merkle_tree.nr index 9c353ab02ab..f5921b96582 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/variable_merkle_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/variable_merkle_tree.nr @@ -84,15 +84,15 @@ impl VariableMerkleTree { VariableMerkleTree { root } } - fn get_root(self) -> Field { + pub fn get_root(self) -> Field { self.root } } mod tests { use crate::{ - hash::accumulate_sha256, - merkle_tree::{merkle_tree::MerkleTree, variable_merkle_tree::VariableMerkleTree}, + hash::accumulate_sha256, merkle_tree::variable_merkle_tree::VariableMerkleTree, + tests::fixtures::merkle_tree::generate_full_sha_tree, }; fn generate_test_array(non_empty_items: u32) -> [Field; 100] { @@ -109,21 +109,6 @@ mod tests { items } - pub fn generate_full_sha_tree(leaves: [Field; N]) -> MerkleTree { - let mut nodes = [0; N]; - let total_nodes = N - 1; - let half_size = N / 2; - // hash base layer - for i in 0..half_size { - nodes[i] = accumulate_sha256([leaves[2 * i], leaves[2 * i + 1]]); - } - // hash the other layers - for i in 0..(total_nodes - half_size) { - nodes[half_size + i] = accumulate_sha256([nodes[2 * i], nodes[2 * i + 1]]); - } - MerkleTree { leaves, nodes } - } - #[test] fn test_0_elems() { let items = [0; 100]; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/proof/avm_proof.nr b/noir-projects/noir-protocol-circuits/crates/types/src/proof/avm_proof.nr index a7085739062..58b4e063b10 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/proof/avm_proof.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/proof/avm_proof.nr @@ -1,7 +1,7 @@ use crate::{constants::AVM_PROOF_LENGTH_IN_FIELDS, traits::{Deserialize, Empty, Serialize}}; pub struct AvmProof { - fields: [Field; AVM_PROOF_LENGTH_IN_FIELDS], + pub fields: [Field; AVM_PROOF_LENGTH_IN_FIELDS], } impl Serialize for AvmProof { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/proof/tube_proof.nr b/noir-projects/noir-protocol-circuits/crates/types/src/proof/tube_proof.nr index 370f28d95de..49115f63d62 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/proof/tube_proof.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/proof/tube_proof.nr @@ -1,7 +1,7 @@ use crate::{constants::TUBE_PROOF_LENGTH, traits::{Deserialize, Empty, Serialize}}; pub struct TubeProof { - fields: [Field; TUBE_PROOF_LENGTH], + pub fields: [Field; TUBE_PROOF_LENGTH], } impl Serialize for TubeProof { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/proof/vk_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/proof/vk_data.nr index 7a62eddd4a3..f2e1b72332c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/proof/vk_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/proof/vk_data.nr @@ -5,7 +5,7 @@ use crate::{ use super::verification_key::VerificationKey; pub struct VkData { - vk: VerificationKey, + pub vk: VerificationKey, vk_index: u32, vk_path: [Field; VK_TREE_HEIGHT], } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr index 34274967dcd..460b1693128 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr @@ -269,6 +269,10 @@ impl FixtureBuilder { *self } + pub fn vk_tree_root() -> Field { + fixtures::vk_tree::get_vk_merkle_tree().get_root() + } + pub fn to_tx_constant_data(self) -> TxConstantData { TxConstantData { historical_header: self.historical_header, @@ -523,6 +527,38 @@ impl FixtureBuilder { } } + pub fn to_private_tube_data(self) -> PrivateTubeData { + let mut result: PrivateTubeData = std::mem::zeroed(); + result.public_inputs = self.to_kernel_circuit_public_inputs(); + result + } + + pub fn to_public_tube_data(self) -> PublicTubeData { + let mut result: PublicTubeData = std::mem::zeroed(); + result.public_inputs = self.to_private_to_public_kernel_circuit_public_inputs(true); + result + } + + pub fn to_avm_accumulated_data(self) -> AvmAccumulatedData { + AvmAccumulatedData { + note_hashes: self.note_hashes.storage().map(|n: ScopedNoteHash| n.note_hash.value), + nullifiers: self.nullifiers.storage().map(|n: ScopedNullifier| n.nullifier.value), + l2_to_l1_msgs: self.l2_to_l1_msgs.storage(), + unencrypted_logs_hashes: self.unencrypted_logs_hashes.storage(), + public_data_writes: self.public_data_writes.storage(), + } + } + + pub fn to_avm_proof_data(self, reverted: bool) -> AvmProofData { + let mut result: AvmProofData = std::mem::zeroed(); + + result.public_inputs.reverted = reverted; + result.public_inputs.global_variables = self.global_variables; + result.public_inputs.accumulated_data = self.to_avm_accumulated_data(); + + result + } + pub fn add_new_note_hash(&mut self, value: Field) { self.note_hashes.push(NoteHash { value, counter: self.next_counter() }.scope( self.contract_address, @@ -1012,42 +1048,6 @@ impl FixtureBuilder { self.counter += 1; counter } - - fn vk_tree_root() -> Field { - fixtures::vk_tree::get_vk_merkle_tree().get_root() - } - - fn to_private_tube_data(self) -> PrivateTubeData { - let mut result: PrivateTubeData = std::mem::zeroed(); - result.public_inputs = self.to_kernel_circuit_public_inputs(); - result - } - - fn to_public_tube_data(self) -> PublicTubeData { - let mut result: PublicTubeData = std::mem::zeroed(); - result.public_inputs = self.to_private_to_public_kernel_circuit_public_inputs(true); - result - } - - fn to_avm_accumulated_data(self) -> AvmAccumulatedData { - AvmAccumulatedData { - note_hashes: self.note_hashes.storage().map(|n: ScopedNoteHash| n.note_hash.value), - nullifiers: self.nullifiers.storage().map(|n: ScopedNullifier| n.nullifier.value), - l2_to_l1_msgs: self.l2_to_l1_msgs.storage(), - unencrypted_logs_hashes: self.unencrypted_logs_hashes.storage(), - public_data_writes: self.public_data_writes.storage(), - } - } - - fn to_avm_proof_data(self, reverted: bool) -> AvmProofData { - let mut result: AvmProofData = std::mem::zeroed(); - - result.public_inputs.reverted = reverted; - result.public_inputs.global_variables = self.global_variables; - result.public_inputs.accumulated_data = self.to_avm_accumulated_data(); - - result - } } impl Empty for FixtureBuilder { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures.nr index 2522ddc10a3..4c9e41cadb7 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures.nr @@ -1,13 +1,14 @@ -pub(crate) mod contract_functions; -pub(crate) mod contracts; -pub(crate) mod protocol_contract_tree; -pub(crate) mod vk_tree; +pub mod contract_functions; +pub mod contracts; +pub mod merkle_tree; +pub mod protocol_contract_tree; +pub mod vk_tree; use crate::address::AztecAddress; -pub(crate) global MSG_SENDER: AztecAddress = AztecAddress { inner: 27 }; +pub global MSG_SENDER: AztecAddress = AztecAddress { inner: 27 }; -pub(crate) global CHAIN_ID: Field = 1; +pub global CHAIN_ID: Field = 1; -pub(crate) global VERSION: Field = 3; +pub global VERSION: Field = 3; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/merkle_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/merkle_tree.nr new file mode 100644 index 00000000000..a9419be659c --- /dev/null +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/merkle_tree.nr @@ -0,0 +1,16 @@ +use crate::{hash::accumulate_sha256, merkle_tree::merkle_tree::MerkleTree}; + +pub fn generate_full_sha_tree(leaves: [Field; N]) -> MerkleTree { + let mut nodes = [0; N]; + let total_nodes = N - 1; + let half_size = N / 2; + // hash base layer + for i in 0..half_size { + nodes[i] = accumulate_sha256([leaves[2 * i], leaves[2 * i + 1]]); + } + // hash the other layers + for i in 0..(total_nodes - half_size) { + nodes[half_size + i] = accumulate_sha256([nodes[2 * i], nodes[2 * i + 1]]); + } + MerkleTree { leaves, nodes } +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays.nr index 97d90406a7d..5b89103fa2d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays.nr @@ -55,18 +55,14 @@ pub fn subarray( dst } -pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec +// Helper function to convert a validated array to BoundedVec. +// Important: Only use it for validated arrays: validate_array(array) should be true. +pub unconstrained fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Empty + Eq, { - let mut len = 0; - for elem in array { - if !is_empty(elem) { - len += 1; - } - } - - BoundedVec { storage: array, len } + let len = array_length(array); + BoundedVec::from_parts_unchecked(array, len) } pub unconstrained fn find_index_hint( diff --git a/noir-projects/noir-protocol-circuits/scripts/generate_variants.js b/noir-projects/noir-protocol-circuits/scripts/generate_variants.js old mode 100644 new mode 100755 index 239f33ea6ae..dbaa8f86650 --- a/noir-projects/noir-protocol-circuits/scripts/generate_variants.js +++ b/noir-projects/noir-protocol-circuits/scripts/generate_variants.js @@ -110,14 +110,31 @@ function generateCircuits(dimensionsList, nargoToml, isSimulated) { for (let i = 0; i < dimensions.length; i++) { const value = dimensions[i]; const name = dimensionNames[i]; - const regex = new RegExp(`^global\\s+${name}:\\su32\\s=\\s.*;.*$`, "m"); + const regex = new RegExp(`^global\\s+${name}:\\su32\\s=\\s(.*);.*$`, "m"); if (!mainDotNoirCode.match(regex)) { throw new Error(`Could not find dimension ${name} in main.nr`); } + // Update value. mainDotNoirCode = mainDotNoirCode.replace( regex, `global ${name}: u32 = ${value};` ); + // Remove constants. + mainDotNoirCode = mainDotNoirCode.replace( + /use dep::types::\{\s*constants::\{[^}]*?\},\s*([^}]*?)\};/, + (_, rest) => { + const restVars = rest + .split(",") + .map((item) => item.trim()) + .filter((item) => item.length > 0); + + return restVars.length > 1 + ? `use dep::types::{${restVars.join(", ")}};` + : restVars.length === 1 + ? `use dep::types::${restVars[0]};` + : ""; + } + ); } const variantFolder = path.join(