From 45d39ab8eb18f773776af37b465e32d0b00ba8f5 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 27 Mar 2024 17:10:39 +0000 Subject: [PATCH 01/77] initial prog more more --- .../aztec-nr/address-note/src/address_note.nr | 4 +- .../aztec-nr/authwit/src/entrypoint/app.nr | 4 +- .../aztec-nr/authwit/src/entrypoint/fee.nr | 4 +- .../aztec-nr/aztec/src/context/avm_context.nr | 6 +- .../aztec/src/context/private_context.nr | 22 +++---- .../aztec/src/context/public_context.nr | 2 +- noir-projects/aztec-nr/aztec/src/deploy.nr | 4 +- .../aztec-nr/aztec/src/initializer.nr | 3 +- .../aztec-nr/aztec/src/note/note_header.nr | 9 +-- .../aztec-nr/field-note/src/field_note.nr | 2 +- .../aztec-nr/value-note/src/value_note.nr | 2 +- .../app_subscription_contract/src/main.nr | 2 - .../src/subscription_note.nr | 2 +- .../contracts/card_game_contract/src/game.nr | 4 +- .../src/main.nr | 2 +- .../src/types/card_note.nr | 2 +- .../src/ecdsa_public_key_note.nr | 4 +- .../contracts/fpc_contract/src/main.nr | 2 +- .../src/public_key_note.nr | 2 +- .../token_blacklist_contract/src/main.nr | 4 +- .../src/types/token_note.nr | 2 +- .../src/types/transparent_note.nr | 6 +- .../contracts/token_contract/src/main.nr | 12 ++-- .../token_contract/src/types/token_note.nr | 2 +- .../src/types/transparent_note.nr | 6 +- .../contracts/uniswap_contract/src/main.nr | 15 +++-- .../crates/private-kernel-lib/src/common.nr | 18 ++--- .../src/private_kernel_init.nr | 3 +- .../src/private_kernel_inner.nr | 8 +-- .../src/private_kernel_tail.nr | 44 ++++++------- .../crates/public-kernel-lib/src/common.nr | 20 +++--- .../src/public_kernel_setup.nr | 22 ++++--- .../src/public_kernel_tail.nr | 6 +- .../src/public_kernel_teardown.nr | 4 +- .../crates/public-kernel-lib/src/utils.nr | 4 +- .../src/non_existent_read_request_reset.nr | 42 ++++++------ .../src/nullifier_read_request_reset.nr | 6 +- .../src/read_request_reset.nr | 12 ++-- ...non_existent_read_request_hints_builder.nr | 2 +- .../nullifier_read_request_hints_builder.nr | 2 +- .../rollup-lib/src/base/base_rollup_inputs.nr | 8 +-- .../combined_accumulated_data.nr | 6 +- .../combined_accumulated_data_builder.nr | 10 +-- .../src/abis/append_only_tree_snapshot.nr | 5 +- .../crates/types/src/abis/call_context.nr | 27 ++++---- .../crates/types/src/abis/call_request.nr | 16 ++--- .../crates/types/src/abis/caller_context.nr | 16 ++--- .../types/src/abis/function_selector.nr | 10 +-- .../crates/types/src/abis/global_variables.nr | 4 +- .../abis/nullifier_key_validation_request.nr | 20 +++--- .../types/src/abis/nullifier_leaf_preimage.nr | 16 +++-- .../src/abis/private_circuit_public_inputs.nr | 12 ++-- .../src/abis/public_circuit_public_inputs.nr | 14 ++-- .../crates/types/src/abis/public_data_read.nr | 10 +-- .../src/abis/public_data_update_request.nr | 10 +-- .../crates/types/src/abis/read_request.nr | 13 ++-- .../crates/types/src/abis/side_effect.nr | 10 +-- .../crates/types/src/address/aztec_address.nr | 18 +---- .../crates/types/src/address/eth_address.nr | 18 +---- .../types/src/address/partial_address.nr | 4 -- .../types/src/address/public_keys_hash.nr | 4 -- .../src/address/salted_initialization_hash.nr | 4 -- .../crates/types/src/content_commitment.nr | 9 +-- .../crates/types/src/contract_class_id.nr | 12 ++-- .../crates/types/src/contrakt/storage_read.nr | 6 +- .../src/contrakt/storage_update_request.nr | 7 +- .../crates/types/src/grumpkin_point.nr | 15 ++--- .../crates/types/src/grumpkin_private_key.nr | 14 ++-- .../crates/types/src/hash.nr | 4 +- .../crates/types/src/header.nr | 17 ++--- .../types/src/messaging/l2_to_l1_message.nr | 6 +- .../types/src/partial_state_reference.nr | 13 ++-- .../crates/types/src/public_data_tree_leaf.nr | 12 +--- .../src/public_data_tree_leaf_preimage.nr | 25 ++++--- .../crates/types/src/state_reference.nr | 10 +-- .../crates/types/src/tests/fixtures.nr | 8 +-- .../types/src/tests/kernel_data_builder.nr | 2 +- .../src/tests/private_call_data_builder.nr | 2 +- .../src/tests/public_call_data_builder.nr | 6 +- .../crates/types/src/traits.nr | 32 ++------- .../crates/types/src/utils/arrays.nr | 66 +++++++++---------- 81 files changed, 395 insertions(+), 448 deletions(-) diff --git a/noir-projects/aztec-nr/address-note/src/address_note.nr b/noir-projects/aztec-nr/address-note/src/address_note.nr index 048cd2f5033..3822b1c98f6 100644 --- a/noir-projects/aztec-nr/address-note/src/address_note.nr +++ b/noir-projects/aztec-nr/address-note/src/address_note.nr @@ -2,7 +2,7 @@ use dep::aztec::log::emit_encrypted_log; // docs:end:encrypted_import use dep::aztec::{ - protocol_types::{address::AztecAddress, traits::Empty}, + protocol_types::address::AztecAddress, note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption}, oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key}, hash::pedersen_hash, context::PrivateContext @@ -62,7 +62,7 @@ impl NoteInterface for AddressNote { impl AddressNote { pub fn new(address: AztecAddress, owner: AztecAddress) -> Self { let randomness = unsafe_rand(); - AddressNote { address, owner, randomness, header: NoteHeader::empty() } + AddressNote { address, owner, randomness, header: NoteHeader::default() } } // docs:end:address_note_def } diff --git a/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr b/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr index 33e1c7c2fa3..f9b85886118 100644 --- a/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr +++ b/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr @@ -1,5 +1,5 @@ use dep::aztec::prelude::PrivateContext; -use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize}}; +use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize, is_default}}; use crate::entrypoint::function_call::{FunctionCall, FUNCTION_CALL_SIZE_IN_BYTES}; @@ -56,7 +56,7 @@ impl AppPayload { // docs:start:entrypoint-execute-calls fn execute_calls(self, context: &mut PrivateContext) { for call in self.function_calls { - if !call.target_address.is_zero() { + if !is_default(call.target_address) { if call.is_public { context.call_public_function_with_packed_args( call.target_address, diff --git a/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr b/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr index 827dcc69c20..ac7cb5962ca 100644 --- a/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr +++ b/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr @@ -1,5 +1,5 @@ use dep::aztec::prelude::PrivateContext; -use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__FEE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize}}; +use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__FEE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize, is_default}}; use crate::entrypoint::function_call::FunctionCall; // 2 * 4 (function call) + 1 @@ -52,7 +52,7 @@ impl FeePayload { fn execute_calls(self, context: &mut PrivateContext) { for call in self.function_calls { - if !call.target_address.is_zero() { + if !is_default(call.target_address) { if call.is_public { context.call_public_function_with_packed_args( call.target_address, diff --git a/noir-projects/aztec-nr/aztec/src/context/avm_context.nr b/noir-projects/aztec-nr/aztec/src/context/avm_context.nr index 69d34d8d622..cd8af4626a3 100644 --- a/noir-projects/aztec-nr/aztec/src/context/avm_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/avm_context.nr @@ -84,12 +84,12 @@ impl PublicContextInterface for AvmContext { fn coinbase(self) -> EthAddress { assert(false, "'coinbase' not implemented!"); - EthAddress::zero() + EthAddress::default() } fn fee_recipient(self) -> AztecAddress { assert(false, "'fee_recipient' not implemented!"); - AztecAddress::zero() + AztecAddress::default() } fn push_nullifier_read_request(&mut self, nullifier: Field) { @@ -196,7 +196,7 @@ impl ContextInterface for AvmContext { } fn get_header(self) -> Header { assert(false, "'get_header' not implemented!"); - Header::empty() + Header::default() } fn get_args_hash(self) -> Field { self.inputs.args_hash diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 181e37e4aa7..5f25d6512be 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -28,7 +28,7 @@ use dep::protocol_types::{ }, contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, grumpkin_private_key::GrumpkinPrivateKey, hash::hash_args_array, header::Header, - messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, traits::is_empty + messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, traits::is_default }; // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) @@ -121,7 +121,7 @@ impl PrivateContext { pub fn new(inputs: PrivateContextInputs, args_hash: Field) -> PrivateContext { let side_effect_counter = inputs.start_side_effect_counter; let mut min_revertible_side_effect_counter = 0; - if is_empty(inputs.call_context.msg_sender) { + if is_default(inputs.call_context.msg_sender) { min_revertible_side_effect_counter = side_effect_counter; } PrivateContext { @@ -460,20 +460,20 @@ impl PrivateContext { call_context: reader.read_struct(CallContext::deserialize), args_hash: reader.read(), return_values: [0; RETURN_VALUES_LENGTH], - nullifier_read_requests: [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], - nullifier_non_existent_read_requests: [ReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], - contract_storage_update_requests: [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], - contract_storage_reads: [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL], + nullifier_read_requests: [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], + nullifier_non_existent_read_requests: [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], + contract_storage_update_requests: [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], + contract_storage_reads: [StorageRead::default(); MAX_PUBLIC_DATA_READS_PER_CALL], public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], - new_note_hashes: [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL], - new_nullifiers: [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL], - new_l2_to_l1_msgs: [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], + new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL], + new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL], + new_l2_to_l1_msgs: [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], start_side_effect_counter: 0, end_side_effect_counter: 0, unencrypted_logs_hash: 0, unencrypted_log_preimages_length: 0, - historical_header: Header::empty(), - prover_address: AztecAddress::zero(), + historical_header: Header::default(), + prover_address: AztecAddress::default(), revert_code: 0 }, is_execution_request: true diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index 1d2789d9a2c..4abc126bb40 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -67,7 +67,7 @@ impl PublicContext { unencrypted_logs_hash: 0, unencrypted_logs_preimages_length: 0, historical_header: inputs.historical_header, - prover_address: AztecAddress::zero() // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) + prover_address: AztecAddress::default() // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) // encrypted_logs_preimages: Vec::new(), // unencrypted_logs_preimages: Vec::new(), } diff --git a/noir-projects/aztec-nr/aztec/src/deploy.nr b/noir-projects/aztec-nr/aztec/src/deploy.nr index 6f75d3edef0..51d17cb76c9 100644 --- a/noir-projects/aztec-nr/aztec/src/deploy.nr +++ b/noir-projects/aztec-nr/aztec/src/deploy.nr @@ -1,12 +1,12 @@ use crate::{context::PrivateContext, oracle::get_contract_instance::get_contract_instance}; -use dep::protocol_types::{address::AztecAddress, abis::function_selector::FunctionSelector, constants::DEPLOYER_CONTRACT_ADDRESS}; +use dep::protocol_types::{address::AztecAddress, abis::function_selector::FunctionSelector, constants::DEPLOYER_CONTRACT_ADDRESS, traits::is_default}; // Calls `deploy` on the deployer contract to deploy a new instance. pub fn deploy_contract(context: &mut PrivateContext, target: AztecAddress) { let instance = get_contract_instance(target); - let universal_deploy = instance.deployer.is_zero(); + let universal_deploy = is_default(instance.deployer); if !universal_deploy { assert(instance.deployer == context.this_address(), "Deployer address does not match current address"); } diff --git a/noir-projects/aztec-nr/aztec/src/initializer.nr b/noir-projects/aztec-nr/aztec/src/initializer.nr index 5b8727a364d..242e0361c27 100644 --- a/noir-projects/aztec-nr/aztec/src/initializer.nr +++ b/noir-projects/aztec-nr/aztec/src/initializer.nr @@ -2,6 +2,7 @@ use dep::protocol_types::{ hash::{silo_nullifier, pedersen_hash}, constants::GENERATOR_INDEX__CONSTRUCTOR, abis::function_selector::FunctionSelector, + traits::is_default, }; use crate::{ @@ -37,7 +38,7 @@ pub fn assert_initialization_matches_address_preimage(context: TContex let instance = get_contract_instance(address); let expected_init = compute_initialization_hash(context.selector(), context.get_args_hash()); assert(instance.initialization_hash == expected_init, "Initialization hash does not match"); - assert((instance.deployer.is_zero()) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer"); + assert(is_default(instance.deployer) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer"); } pub fn compute_initialization_hash(init_selector: FunctionSelector, init_args_hash: Field) -> Field { diff --git a/noir-projects/aztec-nr/aztec/src/note/note_header.nr b/noir-projects/aztec-nr/aztec/src/note/note_header.nr index 27f81945c6a..a2ce86b5ff8 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_header.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_header.nr @@ -1,5 +1,6 @@ use dep::protocol_types::address::AztecAddress; -use dep::protocol_types::traits::{Empty, Serialize}; +use dep::protocol_types::traits::Serialize; +use dep::std::default::Default; struct NoteHeader { contract_address: AztecAddress, @@ -10,9 +11,9 @@ struct NoteHeader { is_transient: bool, } -impl Empty for NoteHeader { - fn empty() -> Self { - NoteHeader { contract_address: AztecAddress::zero(), nonce: 0, storage_slot: 0, is_transient: false } +impl Default for NoteHeader { + fn default() -> Self { + NoteHeader { contract_address: AztecAddress::default(), nonce: 0, storage_slot: 0, is_transient: false } } } diff --git a/noir-projects/aztec-nr/field-note/src/field_note.nr b/noir-projects/aztec-nr/field-note/src/field_note.nr index f6350ddd613..81e9f9600f3 100644 --- a/noir-projects/aztec-nr/field-note/src/field_note.nr +++ b/noir-projects/aztec-nr/field-note/src/field_note.nr @@ -34,7 +34,7 @@ impl NoteInterface for FieldNote { impl FieldNote { pub fn new(value: Field) -> Self { - FieldNote { value, header: NoteHeader::empty() } + FieldNote { value, header: Noteheader::default() } } } diff --git a/noir-projects/aztec-nr/value-note/src/value_note.nr b/noir-projects/aztec-nr/value-note/src/value_note.nr index 4598c1ab17b..8052f3e7cb0 100644 --- a/noir-projects/aztec-nr/value-note/src/value_note.nr +++ b/noir-projects/aztec-nr/value-note/src/value_note.nr @@ -60,7 +60,7 @@ impl NoteInterface for ValueNote { impl ValueNote { pub fn new(value: Field, owner: AztecAddress) -> Self { let randomness = unsafe_rand(); - let header = NoteHeader::empty(); + let header = Noteheader::default(); ValueNote { value, owner, randomness, header } } } diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr index 23837400645..fdb1daf9136 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr @@ -10,8 +10,6 @@ contract AppSubscription { SharedImmutable }; - use dep::aztec::protocol_types::traits::is_empty; - use dep::aztec::{context::Context, oracle::get_public_key::get_public_key}; use dep::authwit::{account::AccountActions, auth_witness::get_auth_witness, auth::assert_current_call_valid_authwit}; diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr index c541c92ae39..cb42e671554 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr @@ -54,6 +54,6 @@ impl NoteInterface for SubscriptionNote { impl SubscriptionNote { pub fn new(owner: AztecAddress, expiry_block_number: Field, remaining_txs: Field) -> Self { - SubscriptionNote { owner, expiry_block_number, remaining_txs, header: NoteHeader::empty() } + SubscriptionNote { owner, expiry_block_number, remaining_txs, header: Noteheader::default() } } } diff --git a/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr b/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr index 1a1415284db..f45e97132a3 100644 --- a/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr +++ b/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr @@ -1,4 +1,4 @@ -use dep::aztec::protocol_types::{address::AztecAddress, traits::{Serialize, Deserialize}}; +use dep::aztec::protocol_types::{address::AztecAddress, traits::{Serialize, Deserialize, is_default}}; use crate::cards::Card; global NUMBER_OF_PLAYERS = 2; @@ -12,7 +12,7 @@ struct PlayerEntry { impl PlayerEntry { pub fn is_initialized(self) -> bool { - !self.address.is_zero() + !is_default(self.address) } } diff --git a/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr b/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr index d991c74c0cf..5bc9911e752 100644 --- a/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr @@ -23,7 +23,7 @@ contract ContractInstanceDeployer { // TODO(@spalladino): assert nullifier_exists silo(contract_class_id, ContractClassRegisterer) let deployer = if universal_deploy { - AztecAddress::zero() + AztecAddress::default() } else { context.msg_sender() }; diff --git a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr index f66b855485a..772134279f7 100644 --- a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr +++ b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr @@ -20,7 +20,7 @@ struct CardNote { impl CardNote { pub fn new(points: u8, randomness: Field, owner: AztecAddress) -> Self { - CardNote { points, randomness, owner, header: NoteHeader::empty() } + CardNote { points, randomness, owner, header: Noteheader::default() } } } diff --git a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr index cd25fa907da..dee54cc542a 100644 --- a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr @@ -63,7 +63,7 @@ impl NoteInterface for EcdsaPublicKeyNote { } y[31] = serialized_note[3].to_be_bytes(32)[31]; - EcdsaPublicKeyNote { x, y, owner: AztecAddress::from_field(serialized_note[4]), header: NoteHeader::empty() } + EcdsaPublicKeyNote { x, y, owner: AztecAddress::from_field(serialized_note[4]), header: Noteheader::default() } } fn compute_nullifier(self, context: &mut PrivateContext) -> Field { @@ -104,6 +104,6 @@ impl NoteInterface for EcdsaPublicKeyNote { impl EcdsaPublicKeyNote { pub fn new(x: [u8; 32], y: [u8; 32], owner: AztecAddress) -> Self { - EcdsaPublicKeyNote { x, y, owner, header: NoteHeader::empty() } + EcdsaPublicKeyNote { x, y, owner, header: Noteheader::default() } } } diff --git a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr index da3f517b69a..7042bda11de 100644 --- a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr @@ -1,7 +1,7 @@ mod interfaces; contract FPC { - use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress, traits::is_empty}; + use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress}; use dep::aztec::state_vars::SharedImmutable; use crate::interfaces::Token; diff --git a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr index f78ad778189..18cf8e30ae9 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr @@ -54,6 +54,6 @@ impl NoteInterface for PublicKeyNote { impl PublicKeyNote { pub fn new(x: Field, y: Field, owner: AztecAddress) -> Self { - PublicKeyNote { x, y, owner, header: NoteHeader::empty() } + PublicKeyNote { x, y, owner, header: Noteheader::default() } } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr index cd046614445..5ce1218c2ec 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr @@ -15,7 +15,7 @@ mod interfaces; contract TokenBlacklist { // Libs - use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress}; + use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress, traits::is_default}; use dep::aztec::{ note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader}, hash::compute_secret_hash, state_vars::{Map, PublicMutable, PrivateSet, SharedImmutable} @@ -44,7 +44,7 @@ contract TokenBlacklist { #[aztec(initializer)] fn constructor(admin: AztecAddress, slow_updates_contract: AztecAddress) { // docs:end:constructor - assert(!admin.is_zero(), "invalid admin"); + assert(!is_default(admin), "invalid admin"); storage.admin.write(admin); // docs:start:write_slow_update_public storage.slow_update.initialize(slow_updates_contract); diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr index 765f9203368..3d01268f984 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr @@ -70,7 +70,7 @@ impl OwnedNote for TokenNote { amount, owner, randomness: unsafe_rand(), - header: NoteHeader::empty(), + header: Noteheader::default(), } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr index 80748a32375..3610ce0f02e 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr @@ -35,7 +35,7 @@ impl NoteInterface for TransparentNote { amount: serialized_note[0], secret_hash: serialized_note[1], secret: 0, - header: NoteHeader::empty(), + header: Noteheader::default(), } } @@ -59,13 +59,13 @@ impl TransparentNote { // CONSTRUCTORS pub fn new(amount: Field, secret_hash: Field) -> Self { - TransparentNote { amount, secret_hash, secret: 0, header: NoteHeader::empty() } + TransparentNote { amount, secret_hash, secret: 0, header: Noteheader::default() } } // new oracle call primitive // get me the secret corresponding to this hash pub fn new_from_secret(amount: Field, secret: Field) -> Self { - TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: NoteHeader::empty() } + TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: Noteheader::default() } } // CUSTOM FUNCTIONS FOR THIS NOTE TYPE diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr index 27a0b12ff80..d64fa58b852 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -14,11 +14,13 @@ contract Token { use dep::compressed_string::FieldCompressedString; - use dep::aztec::prelude::{ - NoteGetterOptions, NoteHeader, Map, PublicMutable, SharedImmutable, PrivateSet, - FunctionSelector, AztecAddress + use dep::aztec::{ + prelude::{ + NoteGetterOptions, NoteHeader, Map, PublicMutable, SharedImmutable, PrivateSet, + FunctionSelector, AztecAddress + }, + hash::compute_secret_hash, protocol_types::traits::is_default }; - use dep::aztec::hash::compute_secret_hash; // docs:start:import_authwit use dep::authwit::{auth::{assert_current_call_valid_authwit, assert_current_call_valid_authwit_public}}; @@ -55,7 +57,7 @@ contract Token { #[aztec(public)] #[aztec(initializer)] fn constructor(admin: AztecAddress, name: str<31>, symbol: str<31>, decimals: u8) { - assert(!admin.is_zero(), "invalid admin"); + assert(!is_default(admin), "invalid admin"); storage.admin.write(admin); storage.minters.at(admin).write(true); storage.name.initialize(FieldCompressedString::from_string(name)); diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr index 9a336e4baa9..f2922eb8ada 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr @@ -73,7 +73,7 @@ impl OwnedNote for TokenNote { amount, owner, randomness: unsafe_rand(), - header: NoteHeader::empty(), + header: Noteheader::default(), } } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr index dfc106d2c13..aa431368429 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr @@ -35,7 +35,7 @@ impl NoteInterface for TransparentNote { amount: serialized_note[0], secret_hash: serialized_note[1], secret: 0, - header: NoteHeader::empty(), + header: Noteheader::default(), } } @@ -59,13 +59,13 @@ impl TransparentNote { // CONSTRUCTORS pub fn new(amount: Field, secret_hash: Field) -> Self { - TransparentNote { amount, secret_hash, secret: 0, header: NoteHeader::empty() } + TransparentNote { amount, secret_hash, secret: 0, header: Noteheader::default() } } // new oracle call primitive // get me the secret corresponding to this hash pub fn new_from_secret(amount: Field, secret: Field) -> Self { - TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: NoteHeader::empty() } + TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: Noteheader::default() } } // CUSTOM FUNCTIONS FOR THIS NOTE TYPE diff --git a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr index c6a08d9c2bd..751e4c6497b 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr @@ -6,8 +6,11 @@ mod util; // Has two separate flows for private and public respectively // Uses the token bridge contract, which tells which input token we need to talk to and handles the exit funds to L1 contract Uniswap { - use dep::aztec::prelude::{FunctionSelector, AztecAddress, EthAddress, Map, PublicMutable}; - use dep::aztec::oracle::context::get_portal_address; + use dep::aztec::{ + prelude::{FunctionSelector, AztecAddress, EthAddress, Map, PublicMutable}, + oracle::context::get_portal_address, + protocol_types::traits::is_default, + }; use dep::authwit::auth::{ IS_VALID_SELECTOR, assert_current_call_valid_authwit_public, compute_call_authwit_hash, @@ -73,10 +76,10 @@ contract Uniswap { let output_asset_bridge_portal_address = get_portal_address(output_asset_bridge); // ensure portal exists - else funds might be lost assert( - !input_asset_bridge_portal_address.is_zero(), "L1 portal address of input_asset's bridge is 0" + !is_default(input_asset_bridge_portal_address), "L1 portal address of input_asset's bridge is 0" ); assert( - !output_asset_bridge_portal_address.is_zero(), "L1 portal address of output_asset's bridge is 0" + !is_default(output_asset_bridge_portal_address), "L1 portal address of output_asset's bridge is 0" ); let content_hash = compute_swap_public_content_hash( @@ -140,10 +143,10 @@ contract Uniswap { let output_asset_bridge_portal_address = get_portal_address(output_asset_bridge); // ensure portal exists - else funds might be lost assert( - !input_asset_bridge_portal_address.is_zero(), "L1 portal address of input_asset's bridge is 0" + !is_default(input_asset_bridge_portal_address), "L1 portal address of input_asset's bridge is 0" ); assert( - !output_asset_bridge_portal_address.is_zero(), "L1 portal address of output_asset's bridge is 0" + !is_default(output_asset_bridge_portal_address), "L1 portal address of output_asset's bridge is 0" ); let content_hash = compute_swap_private_content_hash( diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr index 416aefca438..ae09492da9c 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr @@ -22,7 +22,7 @@ use dep::types::{ }, merkle_tree::check_membership, utils::{arrays::{array_length, array_to_bounded_vec, validate_array}}, - traits::{is_empty, is_empty_array} + traits::{is_default, is_default_array} }; pub fn validate_arrays(app_public_inputs: PrivateCircuitPublicInputs) { @@ -121,10 +121,10 @@ fn perform_static_call_checks(private_call: PrivateCallData) { if is_static_call { // No state changes are allowed for static calls: assert( - is_empty_array(public_inputs.new_note_hashes), "new_note_hashes must be empty for static calls" + is_default_array(public_inputs.new_note_hashes), "new_note_hashes must be empty for static calls" ); assert( - is_empty_array(public_inputs.new_nullifiers), "new_nullifiers must be empty for static calls" + is_default_array(public_inputs.new_nullifiers), "new_nullifiers must be empty for static calls" ); let new_l2_to_l1_msgs_length = array_length(public_inputs.new_l2_to_l1_msgs); @@ -149,7 +149,7 @@ fn is_valid_caller(request_from_stack: CallRequest, fn_being_verified: PrivateCa & request_from_stack.caller_context.storage_contract_address.eq(call_context.storage_contract_address); request_from_stack.caller_contract_address.eq(fn_being_verified.call_stack_item.contract_address) - & (request_from_stack.caller_context.is_empty() | valid_caller_context) + & (is_default(request_from_stack.caller_context) | valid_caller_context) } fn validate_call_requests( @@ -204,7 +204,7 @@ pub fn update_end_values( let nullifier_read_requests = private_call_public_inputs.nullifier_read_requests; for i in 0..MAX_NULLIFIER_READ_REQUESTS_PER_CALL { let request = nullifier_read_requests[i]; - if !is_empty(request) { + if !is_default(request) { public_inputs.validation_requests.nullifier_read_requests.push(request.to_context(storage_contract_address)); } } @@ -213,7 +213,7 @@ pub fn update_end_values( let nullifier_key_validation_requests = private_call_public_inputs.nullifier_key_validation_requests; for i in 0..MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL { let request = nullifier_key_validation_requests[i]; - if !is_empty(request) { + if !is_default(request) { public_inputs.validation_requests.nullifier_key_validation_requests.push(request.to_context(storage_contract_address)); } } @@ -278,7 +278,7 @@ pub fn update_end_values( let mut new_l2_to_l1_msgs_to_insert : BoundedVec = BoundedVec::new(); for i in 0..MAX_NEW_L2_TO_L1_MSGS_PER_CALL { let msg = new_l2_to_l1_msgs[i]; - if !is_empty(msg) { + if !is_default(msg) { let new_l2_to_l1_msgs = compute_l2_to_l1_hash( storage_contract_address, private_call_public_inputs.version, @@ -312,7 +312,7 @@ pub fn contract_logic(private_call: PrivateCallData) { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3062): Why is this using a hash function from the stdlib::recursion namespace let private_call_vk_hash = stdlib_recursion_verification_key_compress_native_vk(private_call.vk); - assert(!contract_address.is_zero(), "contract address cannot be zero"); + assert(!is_default(contract_address), "contract address cannot be zero"); // std::println(f"contract_address={contract_address}"); // std::println(f"private_call_vk_hash={private_call_vk_hash}"); @@ -359,7 +359,7 @@ pub fn validate_call_against_request(private_call: PrivateCallData, request: Cal if call_context.is_delegate_call { let caller_context = request.caller_context; - assert(!caller_context.is_empty(), "caller context cannot be empty for delegate calls"); + assert(!is_default(caller_context), "caller context cannot be empty for delegate calls"); assert( call_context.msg_sender.eq(caller_context.msg_sender), "call stack msg_sender does not match expected msg_sender for delegate calls" ); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr index 73139ca59b2..f61baf456b5 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr @@ -8,7 +8,6 @@ use dep::types::{ }, address::{AztecAddress, PublicKeysHash, compute_initialization_hash}, mocked::{Proof, verify_previous_kernel_state}, transaction::tx_request::TxRequest, - traits::is_empty_array }; // Initialization struct for private inputs to the private kernel @@ -258,7 +257,7 @@ mod tests { builder.private_call.public_inputs.new_l2_to_l1_msgs.extend_from_array( [ - L2ToL1Message::empty(), + L2ToL1Message::default(), L2ToL1Message { recipient: EthAddress::from_field(6), content: 9123 } ] ); 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 3b03d951d47..4e88a5ef3a9 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 @@ -128,8 +128,8 @@ mod tests { let mut builder = PrivateKernelInnerInputsBuilder::new(); // Set (storage) contract_address to 0 - builder.private_call.contract_address = AztecAddress::zero(); - builder.private_call.public_inputs.call_context.storage_contract_address = AztecAddress::zero(); + builder.private_call.contract_address = AztecAddress::default(); + builder.private_call.public_inputs.call_context.storage_contract_address = AztecAddress::default(); builder.failed(); } @@ -450,7 +450,7 @@ mod tests { builder.private_call.public_inputs.new_l2_to_l1_msgs.extend_from_array( [ - L2ToL1Message::empty(), + L2ToL1Message::default(), L2ToL1Message { recipient: EthAddress::from_field(6), content: 888 } ] ); @@ -466,7 +466,7 @@ mod tests { builder.private_call.public_inputs.new_note_hashes.push(SideEffect { value: 4321, counter: 0 }); // Mock the previous new note hashes to be full, therefore no more commitments can be added. - let mut full_new_note_hashes = [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_TX]; + let mut full_new_note_hashes = [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_TX]; for i in 0..MAX_NEW_NOTE_HASHES_PER_TX { full_new_note_hashes[i] = SideEffect { value: i as Field + 1, 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 3e8493f596c..fbb6831cf9b 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 @@ -15,7 +15,7 @@ use dep::types::{ }, grumpkin_private_key::GrumpkinPrivateKey, hash::{compute_note_hash_nonce, compute_unique_siloed_note_hash}, - utils::{arrays::{array_length, array_eq}}, traits::{Empty, is_empty} + utils::{arrays::{array_length, array_eq}}, traits::is_default }; struct PrivateKernelTailCircuitPrivateInputs { @@ -66,7 +66,7 @@ impl PrivateKernelTailCircuitPrivateInputs { let requests = self.previous_kernel.public_inputs.validation_requests.nullifier_key_validation_requests; for i in 0..MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX { let request = requests[i]; - if !is_empty(request) { + if !is_default(request) { let master_secret_key = self.master_nullifier_secret_keys[i]; let computed_public_key = master_secret_key.derive_public_key(); assert( @@ -106,7 +106,7 @@ impl PrivateKernelTailCircuitPrivateInputs { public_inputs.validation_requests.note_hash_read_requests = BoundedVec::new(); } - fn assert_sorted_counters(original: [T; N], sorted: [T; N], indexes: [u64; N]) where T: Eq + Ordered + Empty { + fn assert_sorted_counters(original: [T; N], sorted: [T; N], indexes: [u64; N]) where T: Eq + Ordered + Default { let mut prev_was_empty = false; for i in 0..N { @@ -116,15 +116,15 @@ impl PrivateKernelTailCircuitPrivateInputs { sorted[indexes[i]] }; assert(item.eq(original[i]), "Sorted item is not equal"); - let is_empty = is_empty(item); + let is_default = is_default(item); if prev_was_empty { - assert(is_empty, "Empty items must be at the end"); - } else if (i != 0) & !is_empty { + assert(is_default, "Empty items must be at the end"); + } else if (i != 0) & !is_default { assert(sorted[i].counter() > sorted[i - 1].counter(), "Not sorted"); } - prev_was_empty = is_empty; + prev_was_empty = is_default; } } @@ -171,8 +171,8 @@ impl PrivateKernelTailCircuitPrivateInputs { // match found! // squash both the nullifier and the hash // (set to 0 here and then rearrange array after loop) - new_note_hashes[hint_pos] = SideEffect::empty(); - new_nullifiers[n_idx] = SideEffectLinkedToNoteHash::empty(); + new_note_hashes[hint_pos] = SideEffect::default(); + new_nullifiers[n_idx] = SideEffectLinkedToNoteHash::default(); } // non-transient (persistable) nullifiers are just kept in new_nullifiers array and forwarded // to public inputs (used later by base rollup circuit) @@ -269,7 +269,7 @@ mod tests { max_block_number::MaxBlockNumber, side_effect::{SideEffect, SideEffectLinkedToNoteHash, Ordered} }, hash::compute_unique_siloed_note_hashes, tests::kernel_data_builder::PreviousKernelDataBuilder, - utils::{arrays::{array_eq, array_length}}, traits::{Empty, is_empty, is_empty_array} + utils::{arrays::{array_eq, array_length}}, traits::{is_default, is_default_array} }; struct PrivateKernelTailInputsBuilder { @@ -336,7 +336,7 @@ mod tests { self.nullifier_commitment_hints[nullifier_index] = commitment_index; } - fn sort_sideffects(original: [T; N]) -> ([T; N], [u64; N]) where T: Ordered + Eq + Empty { + fn sort_sideffects(original: [T; N]) -> ([T; N], [u64; N]) where T: Ordered + Eq + Default { let mut indexes = [0; N]; for i in 0..N { indexes[i] = i; @@ -345,9 +345,9 @@ mod tests { |a_index: u64, b_index: u64| { let a = original[a_index]; let b = original[b_index]; - if is_empty(b) { + if is_default(b) { true - } else if is_empty(a) { + } else if is_default(a) { false } else { a.counter() < b.counter() @@ -519,7 +519,7 @@ mod tests { builder.nullify_transient_commitment(1, 0); let new_nullifiers = builder.get_new_nullifiers(); let public_inputs = builder.execute(); - assert(is_empty_array(public_inputs.end.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_note_hashes)); // The nullifier at index 1 is chopped. assert(array_eq(public_inputs.end.new_nullifiers, [new_nullifiers[2]])); @@ -574,8 +574,8 @@ mod tests { let public_inputs = builder.execute(); // app logic will be completely empty after squashing - assert(is_empty_array(public_inputs.end.new_note_hashes)); - assert(is_empty_array(public_inputs.end.new_nullifiers)); + assert(is_default_array(public_inputs.end.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_nullifiers)); // and the 0th nullifier will be moved to the non-revertible array assert( @@ -590,8 +590,8 @@ mod tests { unconstrained fn ordering_of_commitments_and_nullifiers() { let mut builder = PrivateKernelTailInputsBuilder::new(); - let mut sorted_new_note_hashes = [SideEffect::empty(); 10]; - let mut sorted_new_nullifiers = [SideEffectLinkedToNoteHash::empty(); 10]; + let mut sorted_new_note_hashes = [SideEffect::default(); 10]; + let mut sorted_new_nullifiers = [SideEffectLinkedToNoteHash::default(); 10]; for i in 0..10 { sorted_new_note_hashes[i] = SideEffect { value: (i + 1) as Field, counter: builder.previous_kernel.next_sideffect_counter() }; @@ -757,9 +757,9 @@ mod tests { let public_inputs = builder.execute(); - assert(!is_empty_array(public_inputs.end_non_revertible.new_nullifiers)); - assert(is_empty_array(public_inputs.end_non_revertible.new_note_hashes)); - assert(is_empty_array(public_inputs.end.new_note_hashes)); - assert(is_empty_array(public_inputs.end.new_nullifiers)); + assert(!is_default_array(public_inputs.end_non_revertible.new_nullifiers)); + assert(is_default_array(public_inputs.end_non_revertible.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_nullifiers)); } } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index 9f47aa645f1..7018a98f5c2 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -17,7 +17,7 @@ use dep::types::{ MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX }, hash::{silo_note_hash, silo_nullifier, compute_l2_to_l1_hash, accumulate_sha256}, - utils::{arrays::{array_length, array_to_bounded_vec}}, traits::{is_empty, is_empty_array} + utils::{arrays::{array_length, array_to_bounded_vec}}, traits::is_default }; use crate::hash::{compute_public_data_tree_index, compute_public_data_tree_value}; @@ -26,7 +26,7 @@ pub fn validate_inputs(public_call: PublicCallData) { // Validates commons inputs for all type of kernel inputs let this_call_stack_item: PublicCallStackItem = public_call.call_stack_item; assert( - !this_call_stack_item.contract_address.eq(AztecAddress::zero()), "Contract address cannot be zero" + !this_call_stack_item.contract_address.eq(AztecAddress::default()), "Contract address cannot be zero" ); assert(this_call_stack_item.function_data.selector.to_field() != 0, "Function signature cannot be zero"); assert( @@ -139,7 +139,7 @@ fn is_valid_caller(request: CallRequest, public_call: PublicCallData) -> bool { & request.caller_context.storage_contract_address.eq(call_context.storage_contract_address); request.caller_contract_address.eq(public_call.call_stack_item.contract_address) - & (request.caller_context.is_empty() | valid_caller_context) + & (is_default(request.caller_context) | valid_caller_context) } fn validate_call_requests( @@ -219,7 +219,7 @@ fn propagate_nullifier_read_requests( for i in 0..MAX_NULLIFIER_READ_REQUESTS_PER_CALL { let request = nullifier_read_requests[i]; - if !is_empty(request) { + if !is_default(request) { circuit_outputs.validation_requests.nullifier_read_requests.push(request.to_context(storage_contract_address)); } } @@ -235,7 +235,7 @@ fn propagate_nullifier_non_existent_read_requests( for i in 0..MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL { let request = nullifier_non_existent_read_requests[i]; - if !is_empty(request) { + if !is_default(request) { circuit_outputs.validation_requests.nullifier_non_existent_read_requests.push(request.to_context(storage_contract_address)); } } @@ -253,7 +253,7 @@ fn propagate_valid_public_data_update_requests( for i in 0..MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX { let update_request = update_requests[i]; - if (!update_request.is_empty()) { + if (!is_default(update_request) { let public_data_update_request = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value) @@ -277,7 +277,7 @@ fn propagate_valid_non_revertible_public_data_update_requests( for i in 0..MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX { let update_request = update_requests[i]; - if (!update_request.is_empty()) { + if (is_default(update_request)) { let public_data_update_request = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value) @@ -297,7 +297,7 @@ fn propagate_valid_public_data_reads(public_call: PublicCallData, circuit_output for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL { let read_request: StorageRead = read_requests[i]; - if !read_request.is_empty() { + if !is_default(read_request) { let public_data_read = PublicDataRead { leaf_slot: compute_public_data_tree_index(contract_address, read_request.storage_slot), value: compute_public_data_tree_value(read_request.current_value) @@ -409,7 +409,7 @@ fn propagate_new_l2_to_l1_messages(public_call: PublicCallData, public_inputs: & let mut new_l2_to_l1_msgs_to_insert : BoundedVec = BoundedVec::new(); for i in 0..MAX_NEW_L2_TO_L1_MSGS_PER_CALL { let msg = new_l2_to_l1_msgs[i]; - if !is_empty(msg) { + if !is_default(msg) { let new_l2_to_l1_msgs = compute_l2_to_l1_hash( storage_contract_address, public_inputs.constants.tx_context.version, @@ -469,7 +469,7 @@ pub fn validate_call_against_request(public_call: PublicCallData, request: CallR if call_context.is_delegate_call { let caller_context = request.caller_context; - assert(!caller_context.is_empty(), "caller context cannot be empty for delegate calls"); + assert(!is_default(caller_context), "caller context cannot be empty for delegate calls"); assert( call_context.msg_sender.eq(caller_context.msg_sender), "call stack msg_sender does not match expected msg_sender for delegate calls" ); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr index c3003672c8a..b7bba7d830a 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr @@ -1,11 +1,15 @@ use crate::common; -use dep::types::abis::{ - kernel_circuit_public_inputs::{ - PrivateKernelTailCircuitPublicInputs, PublicKernelCircuitPublicInputs, - PublicKernelCircuitPublicInputsBuilder -}, - kernel_data::PublicKernelData, public_call_data::PublicCallData +use dep::types::{ + abis::{ + kernel_circuit_public_inputs::{ + PrivateKernelTailCircuitPublicInputs, PublicKernelCircuitPublicInputs, + PublicKernelCircuitPublicInputsBuilder + }, + kernel_data::PublicKernelData, public_call_data::PublicCallData + }, + traits::is_default }; + use dep::std::unsafe; struct PublicKernelSetupCircuitPrivateInputs { @@ -27,7 +31,7 @@ impl PublicKernelSetupCircuitPrivateInputs { for i in 0..private_call_stack.len() { let private_call = private_call_stack[i]; assert( - private_call.is_empty(), "Private call stack must be empty when executing in the public kernel" + is_default(private_call), "Private call stack must be empty when executing in the public kernel" ); } @@ -208,7 +212,7 @@ mod tests { #[test(should_fail_with="Contract address cannot be zero")] fn contract_address_must_be_valid() { let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - builder.public_call.contract_address = AztecAddress::zero(); + builder.public_call.contract_address = AztecAddress::default(); builder.failed(); } @@ -216,7 +220,7 @@ mod tests { #[test(should_fail_with="Function signature cannot be zero")] fn function_selector_must_be_valid() { let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - builder.public_call.function_data.selector = FunctionSelector::zero(); + builder.public_call.function_data.selector = FunctionSelector::default(); builder.failed(); } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr index 68c48968012..9742650515e 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr @@ -10,7 +10,7 @@ use dep::types::{ }, constants::MAX_NEW_NULLIFIERS_PER_TX, utils::{arrays::{array_length, array_merge, array_concat, array_to_bounded_vec, assert_sorted_array}}, - hash::silo_nullifier, traits::is_empty + hash::silo_nullifier, traits::is_default }; use dep::std::unsafe; @@ -73,7 +73,7 @@ impl PublicKernelTailCircuitPrivateInputs { let mut read_requests = self.previous_kernel.public_inputs.validation_requests.nullifier_non_existent_read_requests; for i in 0..read_requests.len() { let read_request = read_requests[i]; - if !is_empty(read_request) { + if !is_default(read_request) { read_requests[i].value = silo_nullifier(read_request.contract_address, read_request.value); } } @@ -141,7 +141,7 @@ mod tests { }; fn build_nullifier_tree() -> NonEmptyMerkleTree { - let mut pre_existing_nullifiers = [NullifierLeafPreimage::empty(); MAX_NEW_NULLIFIERS_PER_TX]; + let mut pre_existing_nullifiers = [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX]; pre_existing_nullifiers[0] = NullifierLeafPreimage { nullifier: 0, next_nullifier: 100, next_index: 1 }; pre_existing_nullifiers[1] = NullifierLeafPreimage { nullifier: 100, next_nullifier: 0, next_index: 0 }; NonEmptyMerkleTree::new( diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr index 85409d64a6c..f1ce09d6827 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr @@ -153,7 +153,7 @@ mod tests { #[test(should_fail_with="Contract address cannot be zero")] fn contract_address_must_be_valid() { let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.public_call.contract_address = AztecAddress::zero(); + builder.public_call.contract_address = AztecAddress::default(); builder.failed(); } @@ -161,7 +161,7 @@ mod tests { #[test(should_fail_with="Function signature cannot be zero")] fn function_selector_must_be_valid() { let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.public_call.function_data.selector = FunctionSelector::zero(); + builder.public_call.function_data.selector = FunctionSelector::default(); builder.failed(); } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr index 2cbdf5c485d..186afeb65a3 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr @@ -13,7 +13,7 @@ pub fn compute_public_data_reads( contract_address: AztecAddress, read_requests: [StorageRead; N] ) -> [PublicDataRead; N] { - let mut public_data_reads = [PublicDataRead::empty(); N]; + let mut public_data_reads = [PublicDataRead::default(); N]; for i in 0..N { let read_request = read_requests[i]; if !read_request.is_empty() { @@ -34,7 +34,7 @@ pub fn compute_public_data_update_requests( contract_address: AztecAddress, update_requests: [StorageUpdateRequest; N] ) -> [PublicDataUpdateRequest; N] { - let mut public_data_update_requests = [PublicDataUpdateRequest::empty(); N]; + let mut public_data_update_requests = [PublicDataUpdateRequest::default(); N]; for i in 0..N { let update_request = update_requests[i]; if !update_request.is_empty() { diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr index 4beeee665ae..55c1886cbaa 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr @@ -1,7 +1,7 @@ use dep::types::{ abis::{side_effect::OrderedValue, read_request::ReadRequestContext}, merkle_tree::{assert_check_non_membership, IndexedTreeLeafPreimage, MembershipWitness}, - traits::{Empty, is_empty} + traits::is_default }; trait NonMembershipHint where LEAF_PREIMAGE: IndexedTreeLeafPreimage { @@ -63,7 +63,7 @@ pub fn reset_non_existent_read_requests for Nullifier NullifierSettledReadHint { read_request_index: read_request_len, membership_witness: unsafe::zeroed(), - leaf_preimage: NullifierLeafPreimage::empty() + leaf_preimage: NullifierLeafPreimage::default() } } } @@ -136,9 +136,9 @@ mod tests { let read_request_statuses = [ ReadRequestStatus { state: ReadRequestState.SETTLED, hint_index: 0 }, ReadRequestStatus { state: ReadRequestState.PENDING, hint_index: 0 }, - ReadRequestStatus::empty(), + ReadRequestStatus::default(), ReadRequestStatus { state: ReadRequestState.SETTLED, hint_index: 1 }, - ReadRequestStatus::empty() + ReadRequestStatus::default() ]; let (settled_read_hints, tree_root) = get_settled_read_hints(); let unverified_read_requests = reset_read_requests( diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr index 1432df9ef18..894619a15a0 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr @@ -1,7 +1,7 @@ // This will be moved to a separate Read Request Reset Circuit. use dep::types::{ abis::{read_request::ReadRequestContext, side_effect::OrderedValue}, hash::{silo_nullifier}, - merkle_tree::{assert_check_membership, LeafPreimage, MembershipWitness}, traits::{Empty, is_empty} + merkle_tree::{assert_check_membership, LeafPreimage, MembershipWitness}, traits::{is_default} }; struct ReadRequestStateEnum { @@ -21,8 +21,8 @@ struct ReadRequestStatus { hint_index: u64, } -impl Empty for ReadRequestStatus { - fn empty() -> Self { +impl Default for ReadRequestStatus { + fn default() -> Self { ReadRequestStatus { state: ReadRequestState.NADA, hint_index: 0 } } } @@ -112,7 +112,7 @@ fn propagate_unverified_read_requests Self { NullifierReadRequestHintsBuilder { - read_request_statuses: [ReadRequestStatus::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX], + read_request_statuses: [ReadRequestStatus::default(); MAX_NULLIFIER_READ_REQUESTS_PER_TX], pending_read_hints: BoundedVec { storage: [PendingReadHint::nada(read_request_len); MAX_NULLIFIER_READ_REQUESTS_PER_TX], len: 0 }, settled_read_hints: BoundedVec { storage: [NullifierSettledReadHint::nada(read_request_len); MAX_NULLIFIER_READ_REQUESTS_PER_TX], diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr index d5d537326f5..5100e1e15e4 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -306,7 +306,7 @@ fn insert_public_data_update_requests( |write: PublicDataTreeLeaf, low_preimage: PublicDataTreeLeafPreimage| { // Build insertion leaf let is_update = low_preimage.slot == write.slot; if is_update { - PublicDataTreeLeafPreimage::empty() + PublicDataTreeLeafPreimage::default() }else { PublicDataTreeLeafPreimage { slot: write.slot, @@ -497,7 +497,7 @@ mod tests { ); } } else { - sorted_public_data_writes[i] = PublicDataTreeLeaf::empty(); + sorted_public_data_writes[i] = PublicDataTreeLeaf::default(); sorted_public_data_writes_indexes[i] = i; } } @@ -817,7 +817,7 @@ mod tests { }; builder.new_nullifiers.push(NullifierInsertion { existing_index: 0, value: 1 }); - let mut tree_nullifiers = [NullifierLeafPreimage::empty(); MAX_NEW_NULLIFIERS_PER_TX * 2]; + let mut tree_nullifiers = [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX * 2]; tree_nullifiers[0] = NullifierLeafPreimage { nullifier : 0, next_nullifier : 1, @@ -867,7 +867,7 @@ mod tests { } let output = builder.execute(); - let mut tree_nullifiers = [NullifierLeafPreimage::empty(); MAX_NEW_NULLIFIERS_PER_TX * 2]; + let mut tree_nullifiers = [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX * 2]; tree_nullifiers[0] = builder.pre_existing_nullifiers[0]; tree_nullifiers[1] = NullifierLeafPreimage { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr index 76f7e00531f..85d199a07fb 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr @@ -102,14 +102,14 @@ mod tests { CallRequest { hash: 1, caller_contract_address: AztecAddress::from_field(1), - caller_context: CallerContext::empty(), + caller_context: CallerContext::default(), start_side_effect_counter: 5, end_side_effect_counter: 0 }, CallRequest { hash: 2, caller_contract_address: AztecAddress::from_field(1), - caller_context: CallerContext::empty(), + caller_context: CallerContext::default(), start_side_effect_counter: 6, end_side_effect_counter: 0 } @@ -129,7 +129,7 @@ mod tests { CallRequest { hash: 3, caller_contract_address: AztecAddress::from_field(3), - caller_context: CallerContext::empty(), + caller_context: CallerContext::default(), start_side_effect_counter: 9, end_side_effect_counter: 0 } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr index f72d34c9565..7db03c202d3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr @@ -20,7 +20,7 @@ use crate::constants::{ }; use dep::std::unsafe; -use crate::traits::is_empty; +use crate::traits::is_default; use crate::utils::arrays::{array_cp, array_concat, array_to_bounded_vec}; @@ -129,9 +129,9 @@ impl CombinedAccumulatedDataBuilder { for i in 0..MAX_NEW_NOTE_HASHES_PER_TX { let commitment = self.new_note_hashes.storage[i]; - // TODO(fees) we shouldn't need to check is_empty here, + // TODO(fees) we shouldn't need to check is_default here, // but we do because new_note_hashes is bounded to MAX_REVERTIBLE_NOTE_HASHES_PER_TX - if !is_empty(commitment) { + if !is_default(commitment) { if commitment.counter < min_revertible_side_effect_counter { non_revertible_builder.new_note_hashes.push(commitment); } else { @@ -141,7 +141,7 @@ impl CombinedAccumulatedDataBuilder { } for i in 0..MAX_NEW_NULLIFIERS_PER_TX { let nullifier = self.new_nullifiers.storage[i]; - if !is_empty(nullifier) { + if !is_default(nullifier) { if nullifier.counter < min_revertible_side_effect_counter { non_revertible_builder.new_nullifiers.push(nullifier); } else { @@ -152,7 +152,7 @@ impl CombinedAccumulatedDataBuilder { for i in 0..MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX { let call_stack_item = self.public_call_stack.storage[i]; - if !is_empty(call_stack_item) { + if !is_default(call_stack_item) { if call_stack_item.start_side_effect_counter < min_revertible_side_effect_counter { non_revertible_builder.public_call_stack.push(call_stack_item); } else { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr index 83925d95897..fa66db86454 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr @@ -1,4 +1,5 @@ use dep::std::cmp::Eq; +use dep::std::default::Default; struct AppendOnlyTreeSnapshot { root : Field, @@ -16,8 +17,10 @@ impl AppendOnlyTreeSnapshot { pub fn deserialize(serialized: [Field; APPEND_ONLY_TREE_SNAPSHOT_LENGTH]) -> AppendOnlyTreeSnapshot { AppendOnlyTreeSnapshot { root: serialized[0], next_available_leaf_index: serialized[1] as u32 } } +} - pub fn zero() -> Self { +impl Default for AppendOnlyTreeSnapshot { + fn default() -> Self { Self { root: 0, next_available_leaf_index: 0 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr index f8185f89aed..ac9fcdfd087 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr @@ -1,8 +1,9 @@ use crate::{ abis::function_selector::FunctionSelector, address::{EthAddress, AztecAddress}, constants::{CALL_CONTEXT_LENGTH, GENERATOR_INDEX__CALL_CONTEXT}, hash::pedersen_hash, - traits::{Deserialize, Hash, Serialize}, abis::side_effect::Ordered + traits::{Deserialize, Hash, Serialize, is_default}, abis::side_effect::Ordered }; +use dep::std::default::Default; // docs:start:call-context struct CallContext { @@ -19,12 +20,16 @@ struct CallContext { } // docs:end:call-context -impl CallContext { - fn assert_is_zero(self) { - let serialized: [Field; CALL_CONTEXT_LENGTH] = self.serialize(); - - for i in 0..CALL_CONTEXT_LENGTH { - assert(serialized[i] == 0); +impl Default for CallContext { + fn default() -> Self { + CallContext { + msg_sender: AztecAddress::default(), + storage_contract_address: AztecAddress::default(), + portal_contract_address: EthAddress::default(), + function_selector: FunctionSelector::default(), + is_delegate_call: false, + is_static_call: false, + side_effect_counter: 0, } } } @@ -78,16 +83,16 @@ fn serialize_deserialize_of_empty() { } #[test] -fn assert_is_zero() { +fn assert_is_default() { let context: CallContext = dep::std::unsafe::zeroed(); - context.assert_is_zero(); + is_default(context); } #[test(should_fail)] -fn not_zero_assert_is_zero() { +fn not_default_assert_is_default() { let mut context: CallContext = dep::std::unsafe::zeroed(); context.is_delegate_call = true; - context.assert_is_zero(); + is_default(context); } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr index 8eca6227d7c..eab77beeeb2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr @@ -1,6 +1,6 @@ use crate::address::AztecAddress; use dep::std::cmp::Eq; -use crate::traits::Empty; +use dep::std::default::Default; use crate::abis::caller_context::CallerContext; struct CallRequest { @@ -21,20 +21,14 @@ impl Eq for CallRequest { } } -impl Empty for CallRequest { - fn empty() -> Self { +impl Default for CallRequest { + fn default() -> Self { CallRequest { hash: 0, - caller_contract_address: AztecAddress::zero(), - caller_context: CallerContext::empty(), + caller_contract_address: AztecAddress::default(), + caller_context: CallerContext::default(), start_side_effect_counter: 0, end_side_effect_counter: 0, } } } - -impl CallRequest { - pub fn is_empty(self) -> bool { - self.hash == 0 - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr index 829429e4e9e..054644fa8bf 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr @@ -1,6 +1,6 @@ use crate::address::AztecAddress; use dep::std::cmp::Eq; -use crate::traits::Empty; +use dep::std::cmp::Default; struct CallerContext { msg_sender: AztecAddress, @@ -14,17 +14,11 @@ impl Eq for CallerContext { } } -impl Empty for CallerContext { - fn empty() -> Self { +impl Default for CallerContext { + fn default() -> Self { CallerContext { - msg_sender: AztecAddress::zero(), - storage_contract_address: AztecAddress::zero(), + msg_sender: AztecAddress::default(), + storage_contract_address: AztecAddress::default(), } } } - -impl CallerContext { - pub fn is_empty(self) -> bool { - self.msg_sender.is_zero() & self.storage_contract_address.is_zero() - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr index 32dbce09dfa..0257147723d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr @@ -15,6 +15,12 @@ impl Eq for FunctionSelector { } } +impl Default for FunctionSelector { + fn default() -> Self { + Self { inner: 0 } + } +} + impl Serialize<1> for FunctionSelector { fn serialize(self: Self) -> [Field; 1] { [self.inner as Field] @@ -57,8 +63,4 @@ impl FunctionSelector { FunctionSelector::from_field(field_from_bytes(selector_be_bytes, true)) } - - pub fn zero() -> Self { - Self { inner: 0 } - } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr index d636c867a3a..30b2dcef991 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr @@ -60,8 +60,8 @@ impl Empty for GlobalVariables { version: 0, block_number: 0, timestamp: 0, - coinbase: EthAddress::empty(), - fee_recipient: AztecAddress::empty(), + coinbase: EthAddress::default(), + fee_recipient: AztecAddress::default(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr index a522dace348..99699f0dd81 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr @@ -2,7 +2,7 @@ use dep::std::cmp::Eq; use crate::{ address::AztecAddress, constants::{NULLIFIER_KEY_VALIDATION_REQUEST_CONTEXT_LENGTH, NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH}, - traits::{Empty, Serialize, Deserialize}, grumpkin_point::GrumpkinPoint, + traits::{Serialize, Deserialize}, grumpkin_point::GrumpkinPoint, grumpkin_private_key::GrumpkinPrivateKey }; @@ -18,11 +18,11 @@ impl Eq for NullifierKeyValidationRequest { } } -impl Empty for NullifierKeyValidationRequest { - fn empty() -> Self { +impl Default for NullifierKeyValidationRequest { + fn default() -> Self { NullifierKeyValidationRequest { - public_key: GrumpkinPoint::zero(), - secret_key: GrumpkinPrivateKey::zero(), + public_key: GrumpkinPoint::default(), + secret_key: GrumpkinPrivateKey::default(), } } } @@ -67,12 +67,12 @@ impl Eq for NullifierKeyValidationRequestContext { } } -impl Empty for NullifierKeyValidationRequestContext { - fn empty() -> Self { +impl Default for NullifierKeyValidationRequestContext { + fn default() -> Self { NullifierKeyValidationRequestContext { - public_key: GrumpkinPoint::zero(), - secret_key: GrumpkinPrivateKey::zero(), - contract_address: AztecAddress::zero(), + public_key: GrumpkinPoint::default(), + secret_key: GrumpkinPrivateKey::default(), + contract_address: AztecAddress::default(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr index 895196567a0..42b5d4710df 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr @@ -8,8 +8,16 @@ struct NullifierLeafPreimage { next_index : u64, } -impl Empty for NullifierLeafPreimage { - fn empty() -> Self { +impl Eq for NullifierLeafPreimage { + fn eq(self, nullifier_leaf_preimage: NullifierLeafPreimage) -> bool { + (nullifier_leaf_preimage.nullifier == self.nullifier) + & (nullifier_leaf_preimage.next_nullifier == self.next_nullifier) + & (nullifier_leaf_preimage.next_index == self.next_index) + } +} + +impl Default for NullifierLeafPreimage { + fn default() -> Self { Self { nullifier : 0, next_nullifier : 0, @@ -53,10 +61,6 @@ impl IndexedTreeLeafPreimage for NullifierLeafPreimage { } impl NullifierLeafPreimage { - pub fn is_empty(self) -> bool { - (self.nullifier == 0) & (self.next_nullifier == 0) & (self.next_index == 0) - } - pub fn serialize(self) -> [Field; NULLIFIER_LEAF_PREIMAGE_LENGTH] { [self.nullifier, self.next_nullifier, self.next_index as Field] } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr index 331bb7ec6a6..4330c0f6601 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr @@ -139,14 +139,14 @@ impl Deserialize for PrivateCircuitPublicI return_values: reader.read_array([0; RETURN_VALUES_LENGTH]), min_revertible_side_effect_counter: reader.read() as u32, max_block_number: reader.read_struct(MaxBlockNumber::deserialize), - note_hash_read_requests: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]), - nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), - nullifier_key_validation_requests: reader.read_struct_array(NullifierKeyValidationRequest::deserialize, [NullifierKeyValidationRequest::empty(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL]), - new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL]), - new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL]), + note_hash_read_requests: reader.read_struct_array(SideEffect::deserialize, [SideEffect::default(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]), + nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), + nullifier_key_validation_requests: reader.read_struct_array(NullifierKeyValidationRequest::deserialize, [NullifierKeyValidationRequest::default(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL]), + new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL]), + new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL]), private_call_stack_hashes: reader.read_array([0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL]), public_call_stack_hashes: reader.read_array([0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), - new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), + new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), start_side_effect_counter: reader.read() as u32, end_side_effect_counter: reader.read() as u32, encrypted_logs_hash: reader.read() as Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index dab7f2b7fcf..6ed283c9d0f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -107,14 +107,14 @@ impl Deserialize for PublicCircuitPublicInp call_context: reader.read_struct(CallContext::deserialize), args_hash: reader.read(), return_values: reader.read_array([0; RETURN_VALUES_LENGTH]), - nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), - nullifier_non_existent_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL]), - contract_storage_update_requests: reader.read_struct_array(StorageUpdateRequest::deserialize, [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL]), - contract_storage_reads: reader.read_struct_array(StorageRead::deserialize, [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL]), + nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), + nullifier_non_existent_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL]), + contract_storage_update_requests: reader.read_struct_array(StorageUpdateRequest::deserialize, [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL]), + contract_storage_reads: reader.read_struct_array(StorageRead::deserialize, [StorageRead::default(); MAX_PUBLIC_DATA_READS_PER_CALL]), public_call_stack_hashes: reader.read_array([0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), - new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL]), - new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL]), - new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), + new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL]), + new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL]), + new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), start_side_effect_counter: reader.read() as u32, end_side_effect_counter: reader.read() as u32, unencrypted_logs_hash: reader.read() as Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr index f790fe142c8..de21c235a91 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr @@ -13,8 +13,8 @@ impl Eq for PublicDataRead { } } -impl Empty for PublicDataRead { - fn empty() -> Self { +impl Default for PublicDataRead { + fn default() -> Self { Self { leaf_slot : 0, value : 0, @@ -30,9 +30,3 @@ impl Hash for PublicDataRead { ], GENERATOR_INDEX__PUBLIC_DATA_READ) } } - -impl PublicDataRead { - pub fn is_empty(self) -> bool { - (self.leaf_slot == 0) & (self.value == 0) - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr index 8177f389f18..e7eeef24cd8 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr @@ -14,8 +14,8 @@ impl Eq for PublicDataUpdateRequest { } } -impl Empty for PublicDataUpdateRequest { - fn empty() -> Self { +impl Default for PublicDataUpdateRequest { + fn default() -> Self { Self { leaf_slot : 0, new_value : 0 @@ -31,9 +31,3 @@ impl Hash for PublicDataUpdateRequest { ], GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST) } } - -impl PublicDataUpdateRequest { - pub fn is_empty(self) -> bool { - (self.leaf_slot == 0) & (self.new_value == 0) - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr index 1d6acb753f1..ffe1f09dedf 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr @@ -1,8 +1,9 @@ use crate::{ abis::side_effect::{OrderedValue, ContractScopedOrderedValue}, - traits::{Empty, Serialize, Deserialize}, address::AztecAddress + traits::{Serialize, Deserialize}, address::AztecAddress }; use dep::std::cmp::Eq; +use dep::std::default::Default; global READ_REQUEST_SERIALIZED_LEN = 2; global READ_REQUEST_CONTEXT_SERIALIZED_LEN = 3; @@ -28,8 +29,8 @@ impl Eq for ReadRequest { } } -impl Empty for ReadRequest { - fn empty() -> Self { +impl Default for ReadRequest { + fn default() -> Self { ReadRequest { value: 0, counter: 0, @@ -93,12 +94,12 @@ impl Eq for ReadRequestContext { } } -impl Empty for ReadRequestContext { - fn empty() -> Self { +impl Default for ReadRequestContext { + fn default() -> Self { ReadRequestContext { value: 0, counter: 0, - contract_address: AztecAddress::empty(), + contract_address: AztecAddress::default(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr index a1f52acdc88..db96e4bb651 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr @@ -1,6 +1,6 @@ use crate::{ address::AztecAddress, constants::{GENERATOR_INDEX__SIDE_EFFECT}, - traits::{Empty, Hash, Serialize, Deserialize} + traits::{Hash, Serialize, Deserialize} }; use dep::std::cmp::Eq; @@ -48,8 +48,8 @@ impl Eq for SideEffect { } } -impl Empty for SideEffect { - fn empty() -> Self { +impl Default for SideEffect { + fn default() -> Self { SideEffect { value: 0, counter: 0, @@ -108,8 +108,8 @@ impl Eq for SideEffectLinkedToNoteHash { } } -impl Empty for SideEffectLinkedToNoteHash { - fn empty() -> Self { +impl Default for SideEffectLinkedToNoteHash { + fn default() -> Self { SideEffectLinkedToNoteHash { value: 0, note_hash: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr index aab51f65593..11d8732a88e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr @@ -2,7 +2,7 @@ use crate::{ crate::address::{eth_address::EthAddress, partial_address::PartialAddress, public_keys_hash::PublicKeysHash}, constants::{AZTEC_ADDRESS_LENGTH, GENERATOR_INDEX__CONTRACT_ADDRESS}, contract_class_id::ContractClassId, hash::pedersen_hash, grumpkin_point::GrumpkinPoint, - traits::{Empty, ToField, Serialize, Deserialize}, utils + traits::{ToField, Serialize, Deserialize}, utils }; // Aztec address @@ -16,8 +16,8 @@ impl Eq for AztecAddress { } } -impl Empty for AztecAddress { - fn empty() -> Self { +impl Default for AztecAddress { + fn default() -> Self { Self { inner : 0 } @@ -43,10 +43,6 @@ impl Deserialize for AztecAddress { } impl AztecAddress { - pub fn zero() -> Self { - Self { inner: 0 } - } - pub fn from_field(field: Field) -> Self { Self { inner: field } } @@ -80,14 +76,6 @@ impl AztecAddress { ) } - pub fn is_zero(self) -> bool { - self.inner == 0 - } - - pub fn assert_is_zero(self) { - assert(self.to_field() == 0); - } - pub fn conditional_assign(predicate: bool, lhs: Self, rhs: Self) -> Self { let result = utils::conditional_assign(predicate, rhs.to_field(), lhs.to_field()); Self { inner: result } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr index 77a93ce26de..57ffb4adda8 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr @@ -1,6 +1,6 @@ use crate::{ constants::ETH_ADDRESS_LENGTH, hash::pedersen_hash, - traits::{Empty, ToField, Serialize, Deserialize}, utils + traits::{ToField, Serialize, Deserialize}, utils }; struct EthAddress{ @@ -13,8 +13,8 @@ impl Eq for EthAddress { } } -impl Empty for EthAddress { - fn empty() -> Self { +impl Default for EthAddress { + fn default() -> Self { Self { inner : 0 } @@ -40,23 +40,11 @@ impl Deserialize for EthAddress { } impl EthAddress { - pub fn zero() -> Self { - Self { inner: 0 } - } - pub fn from_field(field: Field) -> Self { field.assert_max_bit_size(160); Self { inner: field } } - pub fn is_zero(self) -> bool { - self.inner == 0 - } - - pub fn assert_is_zero(self) { - assert(self.to_field() == 0); - } - pub fn conditional_assign(predicate: bool, lhs: Self, rhs: Self) -> Self { let result = utils::conditional_assign(predicate, rhs.to_field(), lhs.to_field()); Self { inner: result } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/partial_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/partial_address.nr index df67b7f6dc2..9877defb973 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/partial_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/partial_address.nr @@ -54,8 +54,4 @@ impl PartialAddress { pub fn to_field(self) -> Field { self.inner } - - pub fn assert_is_zero(self) { - assert(self.to_field() == 0); - } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/public_keys_hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/public_keys_hash.nr index ff75e878f4e..1af37165ffa 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/public_keys_hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/public_keys_hash.nr @@ -52,10 +52,6 @@ impl PublicKeysHash { pub fn to_field(self) -> Field { self.inner } - - pub fn assert_is_zero(self) { - assert(self.to_field() == 0); - } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/salted_initialization_hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/salted_initialization_hash.nr index 88af664b86b..79288771df6 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/salted_initialization_hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/salted_initialization_hash.nr @@ -37,8 +37,4 @@ impl SaltedInitializationHash { ) ) } - - pub fn assert_is_zero(self) { - assert(self.to_field() == 0); - } } 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 57ae95f1199..e450508bcb5 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,7 +1,8 @@ use crate::{ constants::CONTENT_COMMITMENT_LENGTH, - traits::{Deserialize, Empty, Hash, Serialize}, utils::{arr_copy_slice} + traits::{Deserialize, Hash, Serialize}, utils::{arr_copy_slice} }; +use dep::std::default::Default; struct ContentCommitment { tx_tree_height: Field, @@ -42,8 +43,8 @@ impl Deserialize for ContentCommitment { } } -impl Empty for ContentCommitment { - fn empty() -> Self { +impl Default for ContentCommitment { + fn default() -> Self { Self { tx_tree_height: 0, txs_effects_hash: 0, @@ -64,7 +65,7 @@ impl Eq for ContentCommitment { #[test] fn serialization_of_empty() { - let empty = ContentCommitment::empty(); + let empty = ContentCommitment::default(); let serialized = empty.serialize(); let deserialized = ContentCommitment::deserialize(serialized); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contract_class_id.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contract_class_id.nr index 1b0b4936b8d..44f0d62c765 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contract_class_id.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contract_class_id.nr @@ -11,6 +11,14 @@ impl Eq for ContractClassId { } } +impl Default for ContractClassId { + fn default() -> Self { + ContractClassId { + inner: 0 + } + } +} + impl ToField for ContractClassId { fn to_field(self) -> Field { self.inner @@ -52,8 +60,4 @@ impl ContractClassId { ContractClassId::from_field(hash) } - - pub fn assert_is_zero(self) { - assert(self.to_field() == 0); - } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr index 04ee782bd3d..b0ed828ce05 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr @@ -2,6 +2,8 @@ use crate::{ constants::{CONTRACT_STORAGE_READ_LENGTH, GENERATOR_INDEX__PUBLIC_DATA_READ}, hash::pedersen_hash, traits::{Deserialize, Hash, Empty, Serialize} }; +use dep::std::cmp::Eq; +use dep::std::default::Default; struct StorageRead { storage_slot: Field, @@ -14,8 +16,8 @@ impl Eq for StorageRead { } } -impl Empty for StorageRead { - fn empty() -> Self { +impl Default for StorageRead { + fn default() -> Self { Self { storage_slot: 0, current_value: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr index 01176175f60..47700f30e77 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr @@ -1,8 +1,9 @@ use crate::{ constants::{CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH, GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST}, - hash::pedersen_hash, traits::{Deserialize, Hash, Empty, Serialize} + hash::pedersen_hash, traits::{Deserialize, Hash, Serialize} }; use dep::std::cmp::Eq; +use dep::std::default::Default; struct StorageUpdateRequest{ storage_slot : Field, @@ -16,8 +17,8 @@ impl Eq for StorageUpdateRequest { } } -impl Empty for StorageUpdateRequest { - fn empty() -> Self { +impl Default for StorageUpdateRequest { + fn default() -> Self { StorageUpdateRequest { storage_slot: 0, new_value: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_point.nr b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_point.nr index 965654ac144..df841b9e250 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_point.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_point.nr @@ -29,23 +29,22 @@ impl Eq for GrumpkinPoint { } } -impl GrumpkinPoint { - pub fn new(x: Field, y: Field) -> Self { - Self { x, y } - } - - pub fn zero() -> Self { +impl Default for GrumpkinPoint { + fn default() -> Self { Self { x: 0, y: 0 } } +} - pub fn is_zero(self) -> bool { - (self.x == 0) & (self.y == 0) +impl GrumpkinPoint { + pub fn new(x: Field, y: Field) -> Self { + Self { x, y } } // TODO(David): Would be quite careful here as (0,0) is not a point // on the curve. A boolean flag may be the better approach here, // would also cost less constraints. It seems like we don't need to // group arithmetic either. + // Keeping this function here as a reminder even though its unused fn assert_is_zero(self) { assert(self.x == 0); assert(self.y == 0); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr index 4694322da8a..316337161f2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr @@ -14,17 +14,15 @@ impl Eq for GrumpkinPrivateKey { } } -impl GrumpkinPrivateKey { - pub fn new(high: Field, low: Field) -> Self { - GrumpkinPrivateKey { high, low } - } - - pub fn zero() -> Self { +impl Default for GrumpkinPrivateKey { + fn default() -> Self { Self { high: 0, low: 0 } } +} - pub fn is_zero(self) -> bool { - (self.high == 0) & (self.low == 0) +impl GrumpkinPrivateKey { + pub fn new(high: Field, low: Field) -> Self { + GrumpkinPrivateKey { high, low } } pub fn serialize(self) -> [Field; GRUMPKIN_PRIVATE_KEY_SERIALIZED_LEN] { 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 6badc53d659..31962863d34 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr @@ -182,7 +182,7 @@ pub fn compute_unique_siloed_note_hashes( first_nullifier: Field, siloed_note_hashes: [SideEffect; N] ) -> [SideEffect; N] { - let mut unique_siloed_note_hashes = [SideEffect::empty(); N]; + let mut unique_siloed_note_hashes = [SideEffect::default(); N]; for i in 0..N { let siloed_note_hash = siloed_note_hashes[i]; if siloed_note_hash.value != 0 { @@ -237,7 +237,7 @@ fn compute_var_args_hash() { #[test] fn compute_l2_l1_hash() { // All zeroes - let hash_result = compute_l2_to_l1_hash(AztecAddress::from_field(0), 0, 0, L2ToL1Message::empty()); + let hash_result = compute_l2_to_l1_hash(AztecAddress::from_field(0), 0, 0, L2ToL1Message::default()); assert(hash_result == 0xb393978842a0fa3d3e1470196f098f473f9678e72463cb65ec4ab5581856c2); // Non-zero case diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr index 7b388e65532..c6290201206 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr @@ -7,9 +7,10 @@ use crate::{ GENERATOR_INDEX__BLOCK_HASH, HEADER_LENGTH, STATE_REFERENCE_LENGTH, CONTENT_COMMITMENT_LENGTH }, - hash::pedersen_hash, state_reference::StateReference, traits::{Deserialize, Empty, Hash, Serialize}, + hash::pedersen_hash, state_reference::StateReference, traits::{Deserialize, Hash, Serialize}, utils::{arr_copy_slice}, content_commitment::ContentCommitment }; +use dep::std::default::Default; // docs:start:header struct Header { @@ -66,13 +67,13 @@ impl Deserialize for Header { } } -impl Empty for Header { - fn empty() -> Self { +impl Default for Header { + fn default() -> Self { Self { - last_archive: AppendOnlyTreeSnapshot::zero(), - content_commitment: ContentCommitment::empty(), - state: StateReference::empty(), - global_variables: GlobalVariables::empty(), + last_archive: AppendOnlyTreeSnapshot::default(), + content_commitment: ContentCommitment::default(), + state: StateReference::default(), + global_variables: GlobalVariables::default(), } } } @@ -98,7 +99,7 @@ fn hash_smoke() { } #[test] -fn empty_hash_is_zero() { +fn empty_hash_is_default() { let header: Header = dep::std::unsafe::zeroed(); let hash = header.hash(); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr index 928239bf935..10b67e9a5f9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr @@ -6,10 +6,10 @@ struct L2ToL1Message { content: Field, } -impl Empty for L2ToL1Message { - fn empty() -> Self { +impl Default for L2ToL1Message { + fn default() -> Self { Self { - recipient: EthAddress::empty(), + recipient: EthAddress::default(), content: 0, } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr b/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr index 10761f02f22..7094179b08f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr @@ -1,7 +1,8 @@ use crate::{ abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot, constants::PARTIAL_STATE_REFERENCE_LENGTH, - traits::{Deserialize, Empty, Hash, Serialize} + traits::{Deserialize, Hash, Serialize} }; +use dep::std::default::Default; struct PartialStateReference { note_hash_tree: AppendOnlyTreeSnapshot, @@ -50,12 +51,12 @@ impl Deserialize for PartialStateReference { } } -impl Empty for PartialStateReference { - fn empty() -> Self { +impl Default for PartialStateReference { + fn default() -> Self { Self { - note_hash_tree: AppendOnlyTreeSnapshot::zero(), - nullifier_tree: AppendOnlyTreeSnapshot::zero(), - public_data_tree: AppendOnlyTreeSnapshot::zero(), + note_hash_tree: AppendOnlyTreeSnapshot::default(), + nullifier_tree: AppendOnlyTreeSnapshot::default(), + public_data_tree: AppendOnlyTreeSnapshot::default(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr index 57eb1945a3a..5cdb09f962b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr @@ -1,5 +1,5 @@ -use crate::traits::Empty; use dep::std::cmp::Eq; +use dep::std::default::Default; struct PublicDataTreeLeaf { slot: Field, @@ -12,17 +12,11 @@ impl Eq for PublicDataTreeLeaf { } } -impl Empty for PublicDataTreeLeaf { - fn empty() -> Self { +impl Default for PublicDataTreeLeaf { + fn default() -> Self { Self { slot: 0, value: 0, } } } - -impl PublicDataTreeLeaf { - pub fn is_empty(self) -> bool { - (self.slot == 0) & (self.value == 0) - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf_preimage.nr b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf_preimage.nr index dcc84fe7026..c5baa57edcf 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf_preimage.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf_preimage.nr @@ -1,4 +1,6 @@ -use crate::traits::{Empty, Hash}; +use crate::traits::Hash; +use dep::std::default::Default; +use crate::traits::is_default; struct PublicDataTreeLeafPreimage { slot : Field, @@ -7,8 +9,17 @@ struct PublicDataTreeLeafPreimage { next_index : u64, } -impl Empty for PublicDataTreeLeafPreimage { - fn empty() -> Self { +impl Eq for PublicDataTreeLeafPreimage { + fn eq(self, public_data_tree_leaf_preimage: PublicDataTreeLeafPreimage) -> bool { + (public_data_tree_leaf_preimage.slot == self.slot) + & (public_data_tree_leaf_preimage.value == self.value) + & (public_data_tree_leaf_preimage.next_slot == self.next_slot) + & (public_data_tree_leaf_preimage.next_index == self.next_index) + } +} + +impl Default for PublicDataTreeLeafPreimage { + fn default() -> Self { Self { slot: 0, value: 0, @@ -20,16 +31,10 @@ impl Empty for PublicDataTreeLeafPreimage { impl Hash for PublicDataTreeLeafPreimage { fn hash(self) -> Field { - if self.is_empty() { + if is_default(self) { 0 } else { dep::std::hash::pedersen_hash([self.slot, self.value, (self.next_index as Field), self.next_slot]) } } } - -impl PublicDataTreeLeafPreimage { - pub fn is_empty(self) -> bool { - (self.slot == 0) & (self.value == 0) & (self.next_slot == 0) & (self.next_index == 0) - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr index e64c2654dd6..808e92c153a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr @@ -1,7 +1,7 @@ use crate::{ abis::append_only_tree_snapshot::{AppendOnlyTreeSnapshot, APPEND_ONLY_TREE_SNAPSHOT_LENGTH}, constants::{PARTIAL_STATE_REFERENCE_LENGTH, STATE_REFERENCE_LENGTH}, - partial_state_reference::PartialStateReference, traits::{Deserialize, Empty, Hash, Serialize}, + partial_state_reference::PartialStateReference, traits::{Deserialize, Hash, Serialize}, utils::{arr_copy_slice} }; @@ -44,11 +44,11 @@ impl Deserialize for StateReference { } } -impl Empty for StateReference { - fn empty() -> Self { +impl Default for StateReference { + fn default() -> Self { Self { - l1_to_l2_message_tree: AppendOnlyTreeSnapshot::zero(), - partial: PartialStateReference::empty(), + l1_to_l2_message_tree: AppendOnlyTreeSnapshot::default(), + partial: PartialStateReference::default(), } } } 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 e7d7c0271bc..dc1639a2a52 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 @@ -16,22 +16,22 @@ global PUBLIC_KEY = GrumpkinPoint { x: 123456789, y: 123456789 }; // Workaround for https://github.com/noir-lang/noir/issues/1440 fn empty_append_only_tree() -> AppendOnlyTreeSnapshot { - AppendOnlyTreeSnapshot::zero() + AppendOnlyTreeSnapshot::default() } // Workaround for https://github.com/noir-lang/noir/issues/1440 fn empty_eth_address() -> EthAddress { - EthAddress::empty() + EthAddress::default() } // Workaround for https://github.com/noir-lang/noir/issues/1440 fn empty_aztec_address() -> AztecAddress { - AztecAddress::empty() + AztecAddress::default() } // Workaround for https://github.com/noir-lang/noir/issues/1440 fn empty_content_commitment() -> ContentCommitment { - ContentCommitment::empty() + ContentCommitment::default() } global HEADER = Header { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr index e60f0ec64d7..bea2cd791db 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr @@ -261,7 +261,7 @@ impl PreviousKernelDataBuilder { } fn generate_call_request(&mut self, hash: Field, is_delegate_call: bool) -> CallRequest { - let mut caller_context = CallerContext::empty(); + let mut caller_context = CallerContext::default(); if is_delegate_call { caller_context.msg_sender = fixtures::MSG_SENDER; caller_context.storage_contract_address = self.contract_address; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr index e3874230c8c..a7f1433d61e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr @@ -110,7 +110,7 @@ impl PrivateCallDataBuilder { is_delegate_call: bool ) -> (BoundedVec, BoundedVec) { let value_offset = requests.len(); - let mut caller_context = CallerContext::empty(); + let mut caller_context = CallerContext::default(); if is_delegate_call { let call_context = self.public_inputs.call_context; caller_context.msg_sender = call_context.msg_sender; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr index e71ac955020..347fb89cde1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr @@ -75,7 +75,7 @@ impl PublicCallDataBuilder { pub fn append_public_call_requests(&mut self, num_requests: u64, is_delegate_call: bool) { let value_offset = self.public_inputs.public_call_stack_hashes.len(); - let mut caller_context = CallerContext::empty(); + let mut caller_context = CallerContext::default(); if is_delegate_call { let call_context = self.public_inputs.call_context; caller_context.msg_sender = call_context.msg_sender; @@ -119,7 +119,7 @@ impl PublicCallDataBuilder { pub fn append_empty_public_data_read_requests(&mut self, num_reads: u64) { for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL { if i < num_reads { - self.public_inputs.contract_storage_reads.push(StorageRead::empty()); + self.public_inputs.contract_storage_reads.push(StorageRead::default()); } } } @@ -142,7 +142,7 @@ impl PublicCallDataBuilder { pub fn append_empty_update_requests(&mut self, num_updates: u64) { for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { if i < num_updates { - self.public_inputs.contract_storage_update_requests.push(StorageUpdateRequest::empty()); + self.public_inputs.contract_storage_update_requests.push(StorageUpdateRequest::default()); } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr index 70870f64d84..30beefda263 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr @@ -1,34 +1,12 @@ use dep::std::cmp::Eq; +use dep::std::default::Default; -// Trait: is_empty -// -// The general is_empty trait checks if a data type is is empty, -// and it defines empty for the basic data types as 0. -// -// If a Field is equal to zero, then it is regarded as zero. -// We will go with this definition for now, however it can be problematic -// if a value can actually be zero. In a future refactor, we can -// use the optional type for safety. Doing it now would lead to a worse devex -// and would make it harder to sync up with the cpp code. -// Preferred over Default trait to convey intent, as default doesn't necessarily mean empty. -trait Empty { - fn empty() -> Self; +pub fn is_default(item: T) -> bool where T: Default + Eq { + item.eq(T::default()) } -impl Empty for Field { fn empty() -> Self {0} } - -impl Empty for u1 { fn empty() -> Self {0} } -impl Empty for u8 { fn empty() -> Self {0} } -impl Empty for u32 { fn empty() -> Self {0} } -impl Empty for u64 { fn empty() -> Self {0} } -impl Empty for U128 { fn empty() -> Self {U128::from_integer(0)} } - -pub fn is_empty(item: T) -> bool where T: Empty + Eq { - item.eq(T::empty()) -} - -pub fn is_empty_array(array: [T; N]) -> bool where T: Empty + Eq { - array.all(|elem| is_empty(elem)) +pub fn is_default_array(array: [T; N]) -> bool where T: Default + Eq { + array.all(|elem| is_default(elem)) } trait Hash { 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 73af12d2969..5eb9f0c10e7 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 @@ -1,11 +1,11 @@ use dep::std::array; use dep::std::cmp::Eq; -use crate::traits::{Empty, is_empty}; +use crate::traits::{is_default}; -pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Empty + Eq { +pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Default + Eq { let mut len = 0; for elem in array { - if !is_empty(elem) { + if !is_default(elem) { len += 1; } } @@ -16,30 +16,30 @@ pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Em // Routine which validates that all zero values of an array form a contiguous region at the end, i.e., // of the form: [*,*,*...,0,0,0,0] where any * is non-zero. Note that a full array of non-zero values is // valid. -pub fn validate_array(array: [T; N]) where T: Empty + Eq { +pub fn validate_array(array: [T; N]) where T: Default + Eq { let array_length = array.len(); let mut first_zero_pos = array_length; let mut last_non_zero_pos = 0; for i in 0..array_length { - let is_empty = is_empty(array[i]); - if !is_empty { + let is_default = is_default(array[i]); + if !is_default { last_non_zero_pos = i; - } else if is_empty & (first_zero_pos == array_length) { + } else if is_default & (first_zero_pos == array_length) { first_zero_pos = i; } } assert(last_non_zero_pos <= first_zero_pos, "invalid array"); } -// Helper method to determine the number of non-zero/empty elements in a validated array (ie, validate_array(array) +// Helper method to determine the number of non-zero/default elements in a validated array (ie, validate_array(array) // should be true). -pub fn array_length(array: [T; N]) -> u64 where T: Empty + Eq { +pub fn array_length(array: [T; N]) -> u64 where T: Default + Eq { let mut length = 0; let mut end = false; for elem in array { - end |= is_empty(elem); + end |= is_default(elem); if !end { length += 1; } @@ -47,7 +47,7 @@ pub fn array_length(array: [T; N]) -> u64 where T: Empty + Eq { length } -pub fn array_eq(array: [T; N], expected: [T; S]) -> bool where T: Empty + Eq { +pub fn array_eq(array: [T; N], expected: [T; S]) -> bool where T: Default + Eq { let mut eq = array_length(array) == S; for i in 0..S { @@ -67,26 +67,26 @@ pub fn find_index(array: [T; N], find: fn[Env](T) -> bool) -> u64 { index } -pub fn array_cp(array: [T; N]) -> [T; S] where T: Empty { - let mut result: [T; S] = [T::empty(); S]; +pub fn array_cp(array: [T; N]) -> [T; S] where T: Default { + let mut result: [T; S] = [T::default(); S]; for i in 0..S { result[i] = array[i]; } result } -pub fn array_concat(array1: [T; N], array2: [T; S]) -> [T; M] where T: Empty + Eq { +pub fn array_concat(array1: [T; N], array2: [T; S]) -> [T; M] where T: Default + Eq { assert(N + S <= M, "combined array length exceeds length of return array"); - let mut result: [T; M] = [T::empty(); M]; + let mut result: [T; M] = [T::default(); M]; let mut i = 0; for elem in array1 { - if !is_empty(elem) { + if !is_default(elem) { result[i] = elem; i += 1; } } for elem in array2 { - if !is_empty(elem) { + if !is_default(elem) { result[i] = elem; i += 1; } @@ -94,17 +94,17 @@ pub fn array_concat(array1: [T; N], array2: [T; S]) -> [T; M] where result } -pub fn array_merge(array1: [T; N], array2: [T; N]) -> [T; N] where T: Empty + Eq { - let mut result: [T; N] = [T::empty(); N]; +pub fn array_merge(array1: [T; N], array2: [T; N]) -> [T; N] where T: Default + Eq { + let mut result: [T; N] = [T::default(); N]; let mut i = 0; for elem in array1 { - if !is_empty(elem) { + if !is_default(elem) { result[i] = elem; i += 1; } } for elem in array2 { - if !is_empty(elem) { + if !is_default(elem) { result[i] = elem; i += 1; } @@ -116,7 +116,7 @@ pub fn check_permutation( original_array: [T; N], permuted_array: [T; N], original_indexes: [u64; N] -) where T: Eq + Empty { +) where T: Eq + Default { let mut seen_value = [false; N]; for i in 0..N { let index = original_indexes[i]; @@ -132,15 +132,15 @@ pub fn assert_sorted_array( sorted_array: [T; N], sorted_indexes: [u64; N], ordering: fn[Env](T, T) -> bool -) where T: Eq + Empty { - let mut seen_empty = false; +) where T: Eq + Default { + let mut seen_default = false; for i in 0..N { let original_value = original_array[i]; - if is_empty(original_value) { - seen_empty = true; - assert(is_empty(sorted_array[i]), "Empty values must not be mixed with sorted values"); + if is_default(original_value) { + seen_default = true; + assert(is_default(sorted_array[i]), "Default values must not be mixed with sorted values"); } else { - assert(!seen_empty, "Empty values must be padded to the right"); + assert(!seen_default, "Default values must be padded to the right"); let index = sorted_indexes[i]; assert(sorted_array[index].eq(original_value), "Invalid index"); @@ -182,7 +182,7 @@ fn smoke_validate_array_invalid_case2() { } #[test] -fn test_empty_array_length() { +fn test_default_array_length() { assert_eq(array_length([]), 0); assert_eq(array_length([0]), 0); assert_eq(array_length([0, 0, 0]), 0); @@ -254,7 +254,7 @@ fn assert_sorted_array_desc() { } #[test] -fn assert_sorted_array_all_empty() { +fn assert_sorted_array_all_default() { let original = [0, 0, 0, 0, 0, 0]; let sorted = [0, 0, 0, 0, 0, 0]; let indexes = [0, 0, 0, 0, 0, 0]; @@ -285,7 +285,7 @@ fn assert_sorted_array_failed_wrong_index() { assert_sorted_array(original, sorted, indexes, |a: Field, b: Field| a.lt(b)); } -#[test(should_fail_with="Empty values must be padded to the right")] +#[test(should_fail_with="Default values must be padded to the right")] fn assert_sorted_array_failed_not_padded() { let original = [30, 20, 90, 0, 50, 0]; let sorted = [20, 30, 90, 0, 0, 0]; @@ -293,8 +293,8 @@ fn assert_sorted_array_failed_not_padded() { assert_sorted_array(original, sorted, indexes, |a: Field, b: Field| a.lt(b)); } -#[test(should_fail_with="Empty values must not be mixed with sorted values")] -fn assert_sorted_array_failed_mixed_empty() { +#[test(should_fail_with="Default values must not be mixed with sorted values")] +fn assert_sorted_array_failed_mixed_default() { let original = [30, 20, 90, 0, 0, 0]; let sorted = [20, 30, 90, 0, 0, 10]; let indexes = [1, 0, 2, 0, 0, 0]; From ae232cf61569647b268dec1df61b324b067538b0 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Thu, 28 Mar 2024 01:32:01 +0000 Subject: [PATCH 02/77] fix fix --- .../crates/public-kernel-lib/src/utils.nr | 7 ++++--- .../rollup-lib/src/base/base_rollup_inputs.nr | 16 +++++++++------- .../combined_accumulated_data.nr | 4 ++-- ...private_accumulated_non_revertible_data.nr | 5 +++-- .../private_accumulated_revertible_data.nr | 3 ++- .../public_accumulated_non_revertible_data.nr | 19 ++++++++----------- .../public_accumulated_revertible_data.nr | 11 ++++++----- .../types/src/abis/membership_witness.nr | 2 +- .../types/src/abis/nullifier_leaf_preimage.nr | 4 ++-- .../crates/types/src/contrakt/storage_read.nr | 5 ----- .../src/contrakt/storage_update_request.nr | 6 ------ .../types/src/merkle_tree/indexed_tree.nr | 6 +++--- .../crates/types/src/tests/sort.nr | 8 ++++---- .../crates/types/src/utils/arrays.nr | 7 +++++-- 14 files changed, 49 insertions(+), 54 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr index 186afeb65a3..74ba8c86def 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr @@ -6,7 +6,8 @@ use dep::types::{ }, address::AztecAddress, contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, - utils::{arrays::array_eq} + utils::{arrays::array_eq}, + traits::{is_default}, }; pub fn compute_public_data_reads( @@ -16,7 +17,7 @@ pub fn compute_public_data_reads( let mut public_data_reads = [PublicDataRead::default(); N]; for i in 0..N { let read_request = read_requests[i]; - if !read_request.is_empty() { + if !is_default(read_request) { public_data_reads[i] = PublicDataRead { leaf_slot: compute_public_data_tree_index(contract_address, read_request.storage_slot), value: compute_public_data_tree_value(read_request.current_value), @@ -37,7 +38,7 @@ pub fn compute_public_data_update_requests( let mut public_data_update_requests = [PublicDataUpdateRequest::default(); N]; for i in 0..N { let update_request = update_requests[i]; - if !update_request.is_empty() { + if !is_default(update_request) { public_data_update_requests[i] = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value), diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr index 5100e1e15e4..f0cb914daad 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -34,7 +34,8 @@ use dep::types::{ mocked::{AggregationObject, Proof}, partial_state_reference::PartialStateReference, public_data_tree_leaf::PublicDataTreeLeaf, public_data_tree_leaf_preimage::PublicDataTreeLeafPreimage, - utils::{field::{full_field_less_than, full_field_greater_than}, uint256::U256} + utils::{field::{full_field_less_than, full_field_greater_than}, uint256::U256}, + traits::is_default, }; struct BaseRollupInputs { @@ -152,7 +153,7 @@ impl BaseRollupInputs { let is_less_than_nullifier = full_field_less_than(low_leaf.nullifier, nullifier); let is_next_greater_than = full_field_less_than(nullifier, low_leaf.next_nullifier); - (!low_leaf.is_empty()) & is_less_than_nullifier & ( + (!is_default(low_leaf)) & is_less_than_nullifier & ( is_next_greater_than | ((low_leaf.next_index == 0) & (low_leaf.next_nullifier == 0)) ) @@ -275,7 +276,7 @@ fn insert_public_data_update_requests( ), |low_preimage: PublicDataTreeLeafPreimage, write: PublicDataTreeLeaf| { // Is valid low preimage let is_update = low_preimage.slot == write.slot; - let is_low_empty = low_preimage.is_empty(); + let is_low_empty = is_default(low_preimage); let is_less_than_slot = full_field_less_than(low_preimage.slot, write.slot); let is_next_greater_than = full_field_less_than(write.slot, low_preimage.next_slot); @@ -332,7 +333,7 @@ fn validate_public_data_reads( let low_preimage = public_data_reads_preimages[i]; let witness = public_data_reads_witnesses[i]; - let is_low_empty = low_preimage.is_empty(); + let is_low_empty = is_default(low_preimage); let is_exact = low_preimage.slot == read.leaf_slot; let is_less_than_slot = full_field_less_than(low_preimage.slot, read.leaf_slot); @@ -340,7 +341,7 @@ fn validate_public_data_reads( let is_in_range = is_less_than_slot & (is_next_greater_than | ((low_preimage.next_index == 0) & (low_preimage.next_slot == 0))); - if (!read.is_empty()) { + if (!is_default(read)) { assert(!is_low_empty, "public data read is not empty but low preimage is empty"); if is_in_range { assert_eq(read.value, 0, "low leaf for public data read is in range but value is not zero"); @@ -417,7 +418,8 @@ mod tests { kernel_data_builder::PreviousKernelDataBuilder, merkle_tree_utils::{NonEmptyMerkleTree, compute_zero_hashes}, sort::sort_high_to_low }, - utils::{field::{full_field_less_than, field_from_bytes_32_trunc, field_from_bytes}, uint256::U256} + utils::{field::{full_field_less_than, field_from_bytes_32_trunc, field_from_bytes}, uint256::U256}, + traits::is_default, }; struct NullifierInsertion { @@ -467,7 +469,7 @@ mod tests { sorted_public_data_writes[i] = leaf; sorted_public_data_writes_indexes[i] = sorted_write_tuples[i].original_index; - if !leaf.is_empty() { + if !is_default(leaf) { let low_leaf = pre_existing_public_data[low_leaf_index]; if low_leaf.slot == leaf.slot { pre_existing_public_data[low_leaf_index].value = leaf.value; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr index 85d199a07fb..e61844e1c7b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr @@ -16,7 +16,7 @@ use crate::constants::{ }; use dep::std::unsafe; -use crate::traits::is_empty; +use crate::traits::is_default; use crate::utils::arrays::{array_cp, array_concat, array_to_bounded_vec}; @@ -44,7 +44,7 @@ struct CombinedAccumulatedData { impl CombinedAccumulatedData { pub fn needs_app_logic(self) -> bool { // if we have any enqueued revertible public calls, we need to run the public app logic circuit. - !self.public_call_stack[0].is_empty() + !is_default(self.public_call_stack[0]) } pub fn recombine( diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_non_revertible_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_non_revertible_data.nr index 57ea42b6faa..d6919a0f646 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_non_revertible_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_non_revertible_data.nr @@ -3,6 +3,7 @@ use crate::constants::{ MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX }; +use crate::traits::is_default; struct PrivateAccumulatedNonRevertibleData { revert_code: u8, @@ -16,12 +17,12 @@ impl PrivateAccumulatedNonRevertibleData { // By definition, the final non-revertible enqueued call is for teardown. // since this is a stack, the teardown call would be the 0th element. // So if we have more than one element, we need setup. - !self.public_call_stack[1].is_empty() + !is_default(self.public_call_stack[1]) } pub fn needs_teardown(self) -> bool { // By definition, the final non-revertible enqueued call is for teardown. // since this is a stack, the teardown call would be the 0th element. - !self.public_call_stack[0].is_empty() + !is_default(self.public_call_stack[0]) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_revertible_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_revertible_data.nr index 9144bd52a22..4215813aa39 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_revertible_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_revertible_data.nr @@ -4,6 +4,7 @@ use crate::constants::{ MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX }; +use crate::traits::is_default; struct PrivateAccumulatedRevertibleData { new_note_hashes: [SideEffect; MAX_REVERTIBLE_NOTE_HASHES_PER_TX], @@ -25,6 +26,6 @@ struct PrivateAccumulatedRevertibleData { impl PrivateAccumulatedRevertibleData { pub fn needs_app_logic(self) -> bool { // if we have any enqueued revertible public calls, we need to run the public app logic circuit. - !self.public_call_stack[0].is_empty() + !is_default(self.public_call_stack[0]) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_non_revertible_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_non_revertible_data.nr index 265466c9959..c972429461b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_non_revertible_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_non_revertible_data.nr @@ -1,20 +1,17 @@ use crate::{ abis::{ call_request::CallRequest, public_data_update_request::PublicDataUpdateRequest, - side_effect::{SideEffect, SideEffectLinkedToNoteHash} -} -}; -use crate::constants::{ + side_effect::{SideEffect, SideEffectLinkedToNoteHash}, + }, + traits::is_default, + utils::arrays::{array_cp, array_concat, array_to_bounded_vec}, + constants::{ MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX + }, }; -use dep::std::unsafe; -use crate::traits::is_empty; - -use crate::utils::arrays::{array_cp, array_concat, array_to_bounded_vec}; - struct PublicAccumulatedNonRevertibleData { revert_code: u8, new_note_hashes: [SideEffect; MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX], @@ -28,12 +25,12 @@ impl PublicAccumulatedNonRevertibleData { // By definition, the final non-revertible enqueued call is for teardown. // since this is a stack, the teardown call would be the 0th element. // So if we have more than one element, we need setup. - !self.public_call_stack[1].is_empty() + !is_default(self.public_call_stack[1]) } pub fn needs_teardown(self) -> bool { // By definition, the final non-revertible enqueued call is for teardown. // since this is a stack, the teardown call would be the 0th element. - !self.public_call_stack[0].is_empty() + !is_default(self.public_call_stack[0]) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_revertible_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_revertible_data.nr index 3b3c21a9067..8e33d220a2f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_revertible_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_revertible_data.nr @@ -1,14 +1,15 @@ use crate::{ abis::{ call_request::CallRequest, public_data_update_request::PublicDataUpdateRequest, - side_effect::{SideEffect, SideEffectLinkedToNoteHash} -} -}; -use crate::constants::{ + side_effect::{SideEffect, SideEffectLinkedToNoteHash}, + }, + constants::{ MAX_REVERTIBLE_NOTE_HASHES_PER_TX, MAX_REVERTIBLE_NULLIFIERS_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX + }, + traits::is_default, }; struct PublicAccumulatedRevertibleData { @@ -33,6 +34,6 @@ struct PublicAccumulatedRevertibleData { impl PublicAccumulatedRevertibleData { pub fn needs_app_logic(self) -> bool { // if we have any enqueued revertible public calls, we need to run the public app logic circuit. - !self.public_call_stack[0].is_empty() + !is_default(self.public_call_stack[0]) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr index d23cfb0f19a..2fbf666eb01 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr @@ -36,7 +36,7 @@ struct NoteHashReadRequestMembershipWitness { leaf_index: Field, sibling_path: [Field; NOTE_HASH_TREE_HEIGHT], // whether or not the read request corresponds to a pending note hash - // In case we change the default to true, we have to adapt is_empty() method + // In case we change the default to true, we have to adapt is_default() method // hint to point kernel to the commitment this rr corresponds to is_transient: bool, hint_to_note_hash: Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr index 42b5d4710df..baf4a2bf967 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr @@ -1,6 +1,6 @@ global NULLIFIER_LEAF_PREIMAGE_LENGTH: u64 = 3; -use crate::{merkle_tree::leaf_preimage::{LeafPreimage, IndexedTreeLeafPreimage}, traits::{Empty, Hash}}; +use crate::{merkle_tree::leaf_preimage::{LeafPreimage, IndexedTreeLeafPreimage}, traits::{is_default, Hash}}; struct NullifierLeafPreimage { nullifier : Field, @@ -28,7 +28,7 @@ impl Default for NullifierLeafPreimage { impl Hash for NullifierLeafPreimage { fn hash(self) -> Field { - if self.is_empty() { + if is_default(self) { 0 } else { dep::std::hash::pedersen_hash(self.serialize()) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr index b0ed828ce05..65e27eb6c6c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr @@ -46,8 +46,3 @@ impl Deserialize for StorageRead { } } -impl StorageRead { - pub fn is_empty(self) -> bool { - self.storage_slot == 0 - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr index 47700f30e77..a6e8c9bfe40 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr @@ -46,9 +46,3 @@ impl Deserialize for StorageUpdateReques } } } - -impl StorageUpdateRequest { - pub fn is_empty(self) -> bool { - self.storage_slot == 0 - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr index 6cfc75baaf6..8a702edf1e8 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr @@ -4,7 +4,7 @@ use crate::{ membership::{assert_check_membership, MembershipWitness}, root::{calculate_subtree_root, calculate_empty_tree_root, root_from_sibling_path} }, - traits::{Empty, Hash, is_empty}, utils::arrays::check_permutation + traits::{Default, Hash, is_default}, utils::arrays::check_permutation }; pub fn batch_insert( @@ -20,7 +20,7 @@ pub fn batch_insert Leaf, _subtree_height: [Field; SubtreeHeight], _tree_height: [Field; TreeHeight] -) -> AppendOnlyTreeSnapshot where Value: Eq + Empty, Leaf: Hash { +) -> AppendOnlyTreeSnapshot where Value: Eq + Default, Leaf: Hash { // A permutation to the values is provided to make the insertion use only one insertion strategy check_permutation(values_to_insert, sorted_values, sorted_values_indexes); @@ -31,7 +31,7 @@ pub fn batch_insert { value: T, @@ -29,7 +29,7 @@ struct SortedResult { pub fn sort_get_sorted_hints( values: [T; N], ordering: fn(T, T) -> bool -) -> SortedResult where T: Eq + Empty { +) -> SortedResult where T: Eq + Default { let mut tuples = [SortedTuple { value: values[0], original_index: 0 }; N]; for i in 0..N { tuples[i] = SortedTuple { @@ -39,13 +39,13 @@ pub fn sort_get_sorted_hints( } let sorted_tuples = tuples.sort_via( - |a: SortedTuple, b: SortedTuple| is_empty(b.value) | (!is_empty(a.value) & !is_empty(b.value) & ordering(a.value, b.value)) + |a: SortedTuple, b: SortedTuple| is_default(b.value) | (!is_default(a.value) & !is_default(b.value) & ordering(a.value, b.value)) ); let sorted_array = sorted_tuples.map(|t: SortedTuple| t.value); let mut sorted_index_hints = [0; N]; for i in 0..N { - if !is_empty(sorted_tuples[i].value) { + if !is_default(sorted_tuples[i].value) { let original_index = sorted_tuples[i].original_index; sorted_index_hints[original_index] = i; } 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 5eb9f0c10e7..620e88c44d2 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 @@ -153,7 +153,8 @@ pub fn assert_sorted_array( #[test] fn smoke_validate_array() { - let valid_array = []; + // unnecessary type dec needed to mitigate 'No matching impl found for `PoseidonHasher: Eq`' + let valid_array: [Field; 0] = []; validate_array(valid_array); let valid_array = [0]; @@ -183,7 +184,9 @@ fn smoke_validate_array_invalid_case2() { #[test] fn test_default_array_length() { - assert_eq(array_length([]), 0); + // unnecessary type dec needed to mitigate 'No matching impl found for `PoseidonHasher: Eq`' + let empty_array: [Field; 0] = []; + assert_eq(array_length(empty_array), 0); assert_eq(array_length([0]), 0); assert_eq(array_length([0, 0, 0]), 0); } From 95d2e3652ad1fc5bde6fdab258fd3d8fd8a91ed8 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Thu, 28 Mar 2024 01:57:09 +0000 Subject: [PATCH 03/77] fix --- .../crates/types/src/abis/global_variables.nr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr index 30b2dcef991..b3f22d0b378 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr @@ -2,7 +2,7 @@ use dep::std::cmp::Eq; use crate::{ address::{AztecAddress, EthAddress}, constants::{GENERATOR_INDEX__GLOBAL_VARIABLES, GLOBAL_VARIABLES_LENGTH}, - traits::{Deserialize, Empty, Hash, Serialize} + traits::{Deserialize, Hash, Serialize} }; // docs:start:global-variables @@ -53,8 +53,8 @@ impl Eq for GlobalVariables { } } -impl Empty for GlobalVariables { - fn empty() -> Self { +impl Default for GlobalVariables { + fn default() -> Self { Self { chain_id: 0, version: 0, @@ -67,7 +67,7 @@ impl Empty for GlobalVariables { } #[test] -fn serialization_of_empty() { +fn serialization_of_default() { let vars: GlobalVariables = dep::std::unsafe::zeroed(); let _serialized = vars.serialize(); let _deserialized = GlobalVariables::deserialize(_serialized); From 94b50b84a9387afefc1c94363a7dba6379bfe35d Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Thu, 28 Mar 2024 09:48:52 +0000 Subject: [PATCH 04/77] fix build/test --- noir-projects/aztec-nr/field-note/src/field_note.nr | 2 +- noir-projects/aztec-nr/value-note/src/value_note.nr | 2 +- .../app_subscription_contract/src/subscription_note.nr | 2 +- .../docs_example_contract/src/types/card_note.nr | 4 ++-- .../ecdsa_account_contract/src/ecdsa_public_key_note.nr | 4 ++-- .../schnorr_account_contract/src/public_key_note.nr | 2 +- .../token_blacklist_contract/src/types/token_note.nr | 2 +- .../src/types/transparent_note.nr | 6 +++--- .../contracts/token_contract/src/types/token_note.nr | 2 +- .../token_contract/src/types/transparent_note.nr | 6 +++--- .../crates/public-kernel-lib/src/common.nr | 2 +- .../crates/types/src/abis/call_context.nr | 8 ++++---- .../crates/types/src/abis/caller_context.nr | 2 +- .../crates/types/src/abis/public_data_read.nr | 3 ++- .../crates/types/src/abis/public_data_update_request.nr | 3 ++- .../crates/types/src/contrakt/storage_read.nr | 2 +- .../crates/types/src/messaging/l2_to_l1_message.nr | 2 +- .../aztec_macros/src/transforms/note_interface.rs | 2 +- 18 files changed, 29 insertions(+), 27 deletions(-) diff --git a/noir-projects/aztec-nr/field-note/src/field_note.nr b/noir-projects/aztec-nr/field-note/src/field_note.nr index 81e9f9600f3..654d5806c98 100644 --- a/noir-projects/aztec-nr/field-note/src/field_note.nr +++ b/noir-projects/aztec-nr/field-note/src/field_note.nr @@ -34,7 +34,7 @@ impl NoteInterface for FieldNote { impl FieldNote { pub fn new(value: Field) -> Self { - FieldNote { value, header: Noteheader::default() } + FieldNote { value, header: NoteHeader::default() } } } diff --git a/noir-projects/aztec-nr/value-note/src/value_note.nr b/noir-projects/aztec-nr/value-note/src/value_note.nr index 8052f3e7cb0..fa0d73275d7 100644 --- a/noir-projects/aztec-nr/value-note/src/value_note.nr +++ b/noir-projects/aztec-nr/value-note/src/value_note.nr @@ -60,7 +60,7 @@ impl NoteInterface for ValueNote { impl ValueNote { pub fn new(value: Field, owner: AztecAddress) -> Self { let randomness = unsafe_rand(); - let header = Noteheader::default(); + let header = NoteHeader::default(); ValueNote { value, owner, randomness, header } } } diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr index cb42e671554..2ce1b491159 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr @@ -54,6 +54,6 @@ impl NoteInterface for SubscriptionNote { impl SubscriptionNote { pub fn new(owner: AztecAddress, expiry_block_number: Field, remaining_txs: Field) -> Self { - SubscriptionNote { owner, expiry_block_number, remaining_txs, header: Noteheader::default() } + SubscriptionNote { owner, expiry_block_number, remaining_txs, header: NoteHeader::default() } } } diff --git a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr index 772134279f7..bd6a0a4a1f5 100644 --- a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr +++ b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr @@ -2,7 +2,7 @@ use dep::aztec::prelude::{AztecAddress, NoteInterface, NoteHeader, PrivateContex use dep::aztec::{ note::{utils::compute_note_hash_for_consumption}, oracle::{nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key}, - hash::pedersen_hash, protocol_types::traits::Empty + hash::pedersen_hash }; // Shows how to create a custom note @@ -20,7 +20,7 @@ struct CardNote { impl CardNote { pub fn new(points: u8, randomness: Field, owner: AztecAddress) -> Self { - CardNote { points, randomness, owner, header: Noteheader::default() } + CardNote { points, randomness, owner, header: NoteHeader::default() } } } diff --git a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr index dee54cc542a..a883eb96ce9 100644 --- a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr @@ -63,7 +63,7 @@ impl NoteInterface for EcdsaPublicKeyNote { } y[31] = serialized_note[3].to_be_bytes(32)[31]; - EcdsaPublicKeyNote { x, y, owner: AztecAddress::from_field(serialized_note[4]), header: Noteheader::default() } + EcdsaPublicKeyNote { x, y, owner: AztecAddress::from_field(serialized_note[4]), header: NoteHeader::default() } } fn compute_nullifier(self, context: &mut PrivateContext) -> Field { @@ -104,6 +104,6 @@ impl NoteInterface for EcdsaPublicKeyNote { impl EcdsaPublicKeyNote { pub fn new(x: [u8; 32], y: [u8; 32], owner: AztecAddress) -> Self { - EcdsaPublicKeyNote { x, y, owner, header: Noteheader::default() } + EcdsaPublicKeyNote { x, y, owner, header: NoteHeader::default() } } } diff --git a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr index 18cf8e30ae9..36f5dd3c1b2 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr @@ -54,6 +54,6 @@ impl NoteInterface for PublicKeyNote { impl PublicKeyNote { pub fn new(x: Field, y: Field, owner: AztecAddress) -> Self { - PublicKeyNote { x, y, owner, header: Noteheader::default() } + PublicKeyNote { x, y, owner, header: NoteHeader::default() } } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr index 3d01268f984..62fd7689608 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr @@ -70,7 +70,7 @@ impl OwnedNote for TokenNote { amount, owner, randomness: unsafe_rand(), - header: Noteheader::default(), + header: NoteHeader::default(), } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr index 3610ce0f02e..9e265ffe939 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr @@ -35,7 +35,7 @@ impl NoteInterface for TransparentNote { amount: serialized_note[0], secret_hash: serialized_note[1], secret: 0, - header: Noteheader::default(), + header: NoteHeader::default(), } } @@ -59,13 +59,13 @@ impl TransparentNote { // CONSTRUCTORS pub fn new(amount: Field, secret_hash: Field) -> Self { - TransparentNote { amount, secret_hash, secret: 0, header: Noteheader::default() } + TransparentNote { amount, secret_hash, secret: 0, header: NoteHeader::default() } } // new oracle call primitive // get me the secret corresponding to this hash pub fn new_from_secret(amount: Field, secret: Field) -> Self { - TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: Noteheader::default() } + TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: NoteHeader::default() } } // CUSTOM FUNCTIONS FOR THIS NOTE TYPE diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr index f2922eb8ada..8b29bf88b17 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr @@ -73,7 +73,7 @@ impl OwnedNote for TokenNote { amount, owner, randomness: unsafe_rand(), - header: Noteheader::default(), + header: NoteHeader::default(), } } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr index aa431368429..b2237c3d498 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr @@ -35,7 +35,7 @@ impl NoteInterface for TransparentNote { amount: serialized_note[0], secret_hash: serialized_note[1], secret: 0, - header: Noteheader::default(), + header: NoteHeader::default(), } } @@ -59,13 +59,13 @@ impl TransparentNote { // CONSTRUCTORS pub fn new(amount: Field, secret_hash: Field) -> Self { - TransparentNote { amount, secret_hash, secret: 0, header: Noteheader::default() } + TransparentNote { amount, secret_hash, secret: 0, header: NoteHeader::default() } } // new oracle call primitive // get me the secret corresponding to this hash pub fn new_from_secret(amount: Field, secret: Field) -> Self { - TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: Noteheader::default() } + TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: NoteHeader::default() } } // CUSTOM FUNCTIONS FOR THIS NOTE TYPE diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index 7018a98f5c2..92ca72ebebb 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -253,7 +253,7 @@ fn propagate_valid_public_data_update_requests( for i in 0..MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX { let update_request = update_requests[i]; - if (!is_default(update_request) { + if (!is_default(update_request)) { let public_data_update_request = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr index ac9fcdfd087..cd33171dd7a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr @@ -83,16 +83,16 @@ fn serialize_deserialize_of_empty() { } #[test] -fn assert_is_default() { +fn test_is_default() { let context: CallContext = dep::std::unsafe::zeroed(); - is_default(context); + assert(is_default(context), true); } #[test(should_fail)] -fn not_default_assert_is_default() { +fn test_not_default() { let mut context: CallContext = dep::std::unsafe::zeroed(); context.is_delegate_call = true; - is_default(context); + assert(is_default(context), true); } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr index 054644fa8bf..04eb47250a0 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr @@ -1,6 +1,6 @@ use crate::address::AztecAddress; use dep::std::cmp::Eq; -use dep::std::cmp::Default; +use dep::std::default::Default; struct CallerContext { msg_sender: AztecAddress, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr index de21c235a91..049eec8c75b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr @@ -1,6 +1,7 @@ use crate::constants::GENERATOR_INDEX__PUBLIC_DATA_READ; use dep::std::cmp::Eq; -use crate::traits::{Empty, Hash}; +use dep::std::default::Default; +use crate::traits::Hash; struct PublicDataRead { leaf_slot : Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr index e7eeef24cd8..e5be1f24e95 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr @@ -1,6 +1,7 @@ use crate::constants::GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST; use dep::std::cmp::Eq; -use crate::traits::{Empty, Hash}; +use dep::std::default::Default; +use crate::traits::Hash; struct PublicDataUpdateRequest { leaf_slot : Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr index 65e27eb6c6c..b0d72c35a8c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr @@ -1,6 +1,6 @@ use crate::{ constants::{CONTRACT_STORAGE_READ_LENGTH, GENERATOR_INDEX__PUBLIC_DATA_READ}, hash::pedersen_hash, - traits::{Deserialize, Hash, Empty, Serialize} + traits::{Deserialize, Hash, Serialize} }; use dep::std::cmp::Eq; use dep::std::default::Default; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr index 10b67e9a5f9..8f74fe07681 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr @@ -1,4 +1,4 @@ -use crate::{address::EthAddress, constants::L2_TO_L1_MESSAGE_LENGTH, traits::{Deserialize, Empty, Serialize}}; +use crate::{address::EthAddress, constants::L2_TO_L1_MESSAGE_LENGTH, traits::{Deserialize, Serialize}}; // Note: Not to be confused with L2ToL1Msg in Solidity struct L2ToL1Message { diff --git a/noir/noir-repo/aztec_macros/src/transforms/note_interface.rs b/noir/noir-repo/aztec_macros/src/transforms/note_interface.rs index 01d0272088b..54102883591 100644 --- a/noir/noir-repo/aztec_macros/src/transforms/note_interface.rs +++ b/noir/noir-repo/aztec_macros/src/transforms/note_interface.rs @@ -563,7 +563,7 @@ fn generate_note_deserialize_content_source( } } else { format!( - "{}: dep::aztec::note::note_header::NoteHeader::empty()", + "{}: dep::aztec::note::note_header::NoteHeader::default()", note_header_field_name ) } From 0fe0c4b664deab81ac77dbdb3b2f7a559c72c098 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Thu, 28 Mar 2024 16:34:29 +0000 Subject: [PATCH 05/77] fix --- .../src/private_kernel_tail.nr | 7 ++++--- .../reset-kernel-lib/src/read_request_reset.nr | 12 ++++++++++-- .../crates/types/src/abis/call_context.nr | 16 ++++++++-------- .../crates/types/src/abis/function_data.nr | 14 ++++++++++++-- .../crates/types/src/merkle_tree/membership.nr | 9 +++++++++ .../crates/types/src/mocked.nr | 6 ++++++ .../crates/types/src/transaction/tx_context.nr | 15 +++++++++++++-- .../crates/types/src/transaction/tx_request.nr | 13 ++++++++++++- 8 files changed, 74 insertions(+), 18 deletions(-) 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 fbb6831cf9b..1fe615d5c58 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 @@ -261,13 +261,14 @@ mod tests { use dep::types::constants::{ MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NULLIFIER_READ_REQUESTS_PER_TX, MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX, - MAX_REVERTIBLE_NOTE_HASHES_PER_TX + MAX_REVERTIBLE_NOTE_HASHES_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX }; use dep::types::{ abis::{ kernel_circuit_public_inputs::PrivateKernelTailCircuitPublicInputs, - max_block_number::MaxBlockNumber, side_effect::{SideEffect, SideEffectLinkedToNoteHash, Ordered} + max_block_number::MaxBlockNumber, side_effect::{SideEffect, SideEffectLinkedToNoteHash, Ordered}, }, + grumpkin_private_key::GrumpkinPrivateKey, hash::compute_unique_siloed_note_hashes, tests::kernel_data_builder::PreviousKernelDataBuilder, utils::{arrays::{array_eq, array_length}}, traits::{is_default, is_default_array} }; @@ -384,7 +385,7 @@ mod tests { sorted_new_nullifiers_indexes, nullifier_read_request_hints: self.nullifier_read_request_hints_builder.to_hints(), nullifier_commitment_hints: sorted_nullifier_commitment_hints, - master_nullifier_secret_keys: unsafe::zeroed() + master_nullifier_secret_keys: [GrumpkinPrivateKey::default(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX] }; kernel.native_private_kernel_circuit_tail() } diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr index 894619a15a0..89a3be4098b 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr @@ -180,6 +180,14 @@ mod tests { } } + impl Default for TestLeafPreimage { + fn default() -> Self { + TestLeafPreimage { + value: 0 + } + } + } + struct TestSettledReadHint { read_request_index: u64, membership_witness: MembershipWitness<3>, @@ -204,8 +212,8 @@ mod tests { fn nada(read_request_len: u64) -> Self { TestSettledReadHint { read_request_index: read_request_len, - membership_witness: unsafe::zeroed(), - leaf_preimage: unsafe::zeroed() + membership_witness: MembershipWitness::default(), + leaf_preimage: TestLeafPreimage::default() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr index cd33171dd7a..1901726e417 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr @@ -76,7 +76,7 @@ impl Deserialize for CallContext { #[test] fn serialize_deserialize_of_empty() { - let context: CallContext = dep::std::unsafe::zeroed(); + let context = CallContext::default(); let serialized = context.serialize(); let deserialized = CallContext::deserialize(serialized); assert(context.eq(deserialized)); @@ -84,21 +84,21 @@ fn serialize_deserialize_of_empty() { #[test] fn test_is_default() { - let context: CallContext = dep::std::unsafe::zeroed(); + let context = CallContext::default(); assert(is_default(context), true); } #[test(should_fail)] fn test_not_default() { - let mut context: CallContext = dep::std::unsafe::zeroed(); + let mut context = CallContext::default(); context.is_delegate_call = true; assert(is_default(context), true); } #[test] fn test_eq() { - let mut context1: CallContext = dep::std::unsafe::zeroed(); - let mut context2: CallContext = dep::std::unsafe::zeroed(); + let mut context1 = CallContext::default(); + let mut context2 = CallContext::default(); context1.is_delegate_call = true; context2.is_delegate_call = true; @@ -112,8 +112,8 @@ fn test_eq() { #[test(should_fail)] fn not_eq_test_eq() { - let mut context1: CallContext = dep::std::unsafe::zeroed(); - let mut context2: CallContext = dep::std::unsafe::zeroed(); + let mut context1 = CallContext::default(); + let mut context2 = CallContext::default(); context1.is_delegate_call = true; context2.is_delegate_call = false; @@ -129,6 +129,6 @@ fn not_eq_test_eq() { #[test] fn hash_smoke() { - let context: CallContext = dep::std::unsafe::zeroed(); + let context = CallContext::default(); let _hashed = context.hash(); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr index cf4f8985cac..ca8fc1a4d66 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr @@ -19,6 +19,16 @@ impl Eq for FunctionData { } } +impl Default for FunctionData { + fn default() -> Self { + FunctionData { + selector: FunctionSelector::default(), + is_private: false, + is_transpiled: false, + } + } +} + impl Serialize for FunctionData { // A field is ~256 bits // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3057): Since, function data can fit into a Field, @@ -50,7 +60,7 @@ impl Hash for FunctionData { #[test] fn serialization_of_empty() { - let data: FunctionData = dep::std::unsafe::zeroed(); + let data = FunctionData::default(); let serialized = data.serialize(); let deserialized = FunctionData::deserialize(serialized); assert(data.eq(deserialized)); @@ -58,7 +68,7 @@ fn serialization_of_empty() { #[test] fn empty_hash() { - let data: FunctionData = dep::std::unsafe::zeroed(); + let data = FunctionData::default(); let hash = data.hash(); // Value from function_data.test.ts "computes empty item hash" test diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr index 6fc8d91d13b..d810b55c9f9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr @@ -5,6 +5,15 @@ struct MembershipWitness { sibling_path: [Field; N] } +impl Default for MembershipWitness { + fn default() -> Self { + MembershipWitness { + leaf_index: 0, + sibling_path: [0; N] + } + } +} + pub fn check_membership(leaf: Field, index: Field, sibling_path: [Field; N], root: Field) -> bool { let calculated_root = root_from_sibling_path(leaf, index, sibling_path); calculated_root == root diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr b/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr index 343d15c1eed..36b1e955353 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr @@ -7,6 +7,12 @@ struct Proof{} struct VerificationKey{} +impl Default for AggregationObject { + fn default() -> Self { + AggregationObject {} + } +} + // Perform recursive verification of the previous kernel proof and private call // proof. pub fn verify_previous_kernel_state( diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr index a0655fa6250..7e260e381cd 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr @@ -20,6 +20,17 @@ impl Eq for TxContext { } } +impl Default for TxContext { + fn default() -> Self { + TxContext { + is_fee_payment_tx : false, + is_rebate_payment_tx : false, + chain_id : 0, + version : 0, + } + } +} + impl Serialize for TxContext { fn serialize(self) -> [Field; TX_CONTEXT_DATA_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(); @@ -60,7 +71,7 @@ impl Hash for TxContext { #[test] fn serialization_of_empty() { - let context: TxContext = dep::std::unsafe::zeroed(); + let context = TxContext::default(); let serialized = context.serialize(); let deserialized = TxContext::deserialize(serialized); assert(context.eq(deserialized)); @@ -68,7 +79,7 @@ fn serialization_of_empty() { #[test] fn empty_hash() { - let inputs: TxContext = dep::std::unsafe::zeroed(); + let inputs = TxContext::default(); let hash = inputs.hash(); // Value from tx_context.test.ts "computes empty item hash" test diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr index ac29ca6717a..3fd47e6b100 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr @@ -20,6 +20,17 @@ impl Eq for TxRequest { } } +impl Default for TxRequest { + fn default() -> Self { + TxRequest { + origin: AztecAddress::default(), + args_hash: 0, + tx_context: TxContext::default(), + function_data: FunctionData::default() + } + } +} + impl Hash for TxRequest { fn hash(self) -> Field { pedersen_hash(self.serialize(), GENERATOR_INDEX__TX_REQUEST) @@ -68,7 +79,7 @@ mod tests { #[test] fn serialization_of_empty() { // Assuming a zeroed initialization for simplicity - let request: TxRequest = dep::std::unsafe::zeroed(); + let request = TxRequest::default(); let serialized = request.serialize(); let deserialized = TxRequest::deserialize(serialized); assert(request.eq(deserialized)); From 7d1d27d59790311e20f8678e134c850aabe93f03 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Thu, 28 Mar 2024 17:20:51 +0000 Subject: [PATCH 06/77] fix --- .../src/private_kernel_init.nr | 2 +- .../src/private_kernel_inner.nr | 2 +- .../src/private_kernel_tail.nr | 2 +- .../src/nullifier_read_request_reset.nr | 2 +- ...non_existent_read_request_hints_builder.nr | 2 +- .../src/abis/previous_rollup_data.nr | 12 ++++++++ .../rollup-lib/src/base/base_rollup_inputs.nr | 22 +++++++------- .../src/tests/previous_rollup_data.nr | 2 +- ...accumulated_non_revertible_data_builder.nr | 12 ++++++++ .../accumulated_revertible_data_builder.nr | 17 +++++++++++ .../combined_accumulated_data.nr | 21 +++++++++++++- .../combined_accumulated_data_builder.nr | 22 ++++++++++++-- .../types/src/abis/combined_constant_data.nr | 9 ++++++ ...te_kernel_circuit_public_inputs_builder.nr | 13 +++++++++ .../types/src/abis/membership_witness.nr | 27 +++++++++++++++++ .../types/src/abis/public_call_stack_item.nr | 6 ++-- .../src/abis/public_circuit_public_inputs.nr | 29 +++++++++++++++++-- .../validation_requests_builder.nr | 13 +++++++++ .../crates/types/src/header.nr | 28 +++++++++--------- .../types/src/merkle_tree/merkle_tree.nr | 9 ++++++ .../crates/types/src/mocked.nr | 16 ++++++++-- .../types/src/partial_state_reference.nr | 24 ++++++++------- .../crates/types/src/state_reference.nr | 20 ++++++------- .../types/src/tests/kernel_data_builder.nr | 4 +-- .../types/src/tests/merkle_tree_utils.nr | 11 +++++++ 25 files changed, 263 insertions(+), 64 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr index f61baf456b5..2b7deae311e 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr @@ -76,7 +76,7 @@ impl PrivateKernelInitCircuitPrivateInputs { } pub fn native_private_kernel_circuit_initial(self) -> PrivateKernelInnerCircuitPublicInputs { - let mut public_inputs: PrivateKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let mut public_inputs = PrivateKernelCircuitPublicInputsBuilder::default(); public_inputs.is_private = true; self.initialize_end_values(&mut public_inputs); 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 4e88a5ef3a9..0d0908b25e4 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 @@ -30,7 +30,7 @@ impl PrivateKernelInnerCircuitPrivateInputs { } pub fn native_private_kernel_circuit_inner(self) -> PrivateKernelInnerCircuitPublicInputs { - let mut public_inputs : PrivateKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let mut public_inputs = PrivateKernelCircuitPublicInputsBuilder::default(); public_inputs.is_private = true; common::validate_previous_kernel_values(self.previous_kernel.public_inputs.end); 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 1fe615d5c58..4a05430ea31 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 @@ -225,7 +225,7 @@ impl PrivateKernelTailCircuitPrivateInputs { } pub fn native_private_kernel_circuit_tail(self) -> PrivateKernelTailCircuitPublicInputs { - let mut public_inputs : PrivateKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let mut public_inputs = PrivateKernelCircuitPublicInputsBuilder::default(); public_inputs.is_private = true; self.validate_inputs(); diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/nullifier_read_request_reset.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/nullifier_read_request_reset.nr index c33396e7052..98ca7d58c12 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/nullifier_read_request_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/nullifier_read_request_reset.nr @@ -31,7 +31,7 @@ impl SettledReadHint for Nullifier fn nada(read_request_len: u64) -> Self { NullifierSettledReadHint { read_request_index: read_request_len, - membership_witness: unsafe::zeroed(), + membership_witness: MembershipWitness::default(), leaf_preimage: NullifierLeafPreimage::default() } } diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_non_existent_read_request_hints_builder.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_non_existent_read_request_hints_builder.nr index e779cc12468..bde26ba7e86 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_non_existent_read_request_hints_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_non_existent_read_request_hints_builder.nr @@ -21,7 +21,7 @@ struct NullifierNonExistentReadRequestHintsBuilder { impl NullifierNonExistentReadRequestHintsBuilder { pub fn new() -> Self { NullifierNonExistentReadRequestHintsBuilder { - nullifier_tree: unsafe::zeroed(), + nullifier_tree: NonEmptyMerkleTree::default(), non_membership_hints: BoundedVec::new(), read_values: BoundedVec::new(), pending_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_TX] 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 db92815baa0..37200562c09 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 @@ -10,3 +10,15 @@ struct PreviousRollupData{ vk_index : u32, vk_sibling_path : VKMembershipWitness, } + +impl Default for PreviousRollupData { + fn default() -> Self { + PreviousRollupData { + base_or_merge_rollup_public_inputs: dep::std::unsafe::zeroed(), + proof : Proof::default(), + vk : VerificationKey::default(), + vk_index : 0 as u32, + vk_sibling_path : VKMembershipWitness::default(), + } + } +} diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr index 3ae08334f64..92a21b7fd2a 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -437,14 +437,14 @@ mod tests { public_data_writes: BoundedVec<(u64, PublicDataTreeLeaf), 2>, mut pre_existing_public_data: [PublicDataTreeLeafPreimage; EXISTING_LEAVES] ) -> ([Field; PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH], [PublicDataTreeLeaf; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], [u64; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], [PublicDataTreeLeafPreimage; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], [PublicDataMembershipWitness; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], [PublicDataTreeLeafPreimage; MAX_PUBLIC_DATA_READS_PER_TX], [PublicDataMembershipWitness; MAX_PUBLIC_DATA_READS_PER_TX], [PublicDataTreeLeafPreimage; EXISTING_LEAVES]) { - let mut subtree_path: [Field; PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH] = dep::std::unsafe::zeroed(); - let mut sorted_public_data_writes: [PublicDataTreeLeaf; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] = dep::std::unsafe::zeroed(); - let mut sorted_public_data_writes_indexes: [u64; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] = dep::std::unsafe::zeroed(); - let mut low_public_data_writes_preimages: [PublicDataTreeLeafPreimage; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] = dep::std::unsafe::zeroed(); - let mut low_public_data_writes_witnesses: [PublicDataMembershipWitness; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] = dep::std::unsafe::zeroed(); - let mut public_data_reads_preimages: [PublicDataTreeLeafPreimage; MAX_PUBLIC_DATA_READS_PER_TX] = dep::std::unsafe::zeroed(); - let mut public_data_reads_witnesses: [PublicDataMembershipWitness; MAX_PUBLIC_DATA_READS_PER_TX] = dep::std::unsafe::zeroed(); - let mut new_subtree: [PublicDataTreeLeafPreimage; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] = dep::std::unsafe::zeroed(); + let mut subtree_path = [0; PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH]; + let mut sorted_public_data_writes = [PublicDataTreeLeaf::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; + let mut sorted_public_data_writes_indexes = [0 as u64; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; + let mut low_public_data_writes_preimages = [PublicDataTreeLeafPreimage::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; + let mut low_public_data_writes_witnesses = [PublicDataMembershipWitness::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; + let mut public_data_reads_preimages = [PublicDataTreeLeafPreimage::default(); MAX_PUBLIC_DATA_READS_PER_TX]; + let mut public_data_reads_witnesses = [PublicDataMembershipWitness::default(); MAX_PUBLIC_DATA_READS_PER_TX]; + let mut new_subtree = [PublicDataTreeLeafPreimage::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; for i in 0..MAX_PUBLIC_DATA_WRITES_PER_TEST { if i < (public_data_writes.len()) { @@ -559,8 +559,8 @@ mod tests { kernel_data: &mut RollupKernelData, start_nullifier_tree_snapshot: AppendOnlyTreeSnapshot ) -> ([NullifierLeafPreimage; MAX_NEW_NULLIFIERS_PER_TX], [NullifierMembershipWitness; MAX_NEW_NULLIFIERS_PER_TX], [Field; MAX_NEW_NULLIFIERS_PER_TX], [u64; MAX_NEW_NULLIFIERS_PER_TX]) { - let mut nullifier_predecessor_preimages: [NullifierLeafPreimage; MAX_NEW_NULLIFIERS_PER_TX] = dep::std::unsafe::zeroed(); - let mut low_nullifier_membership_witness: [NullifierMembershipWitness; MAX_NEW_NULLIFIERS_PER_TX] = dep::std::unsafe::zeroed(); + let mut nullifier_predecessor_preimages = [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX]; + let mut low_nullifier_membership_witness = [NullifierMembershipWitness::default(); MAX_NEW_NULLIFIERS_PER_TX]; let sorted_new_nullifier_tuples = sort_high_to_low( self.new_nullifiers.storage.map(|insertion: NullifierInsertion| insertion.value), @@ -969,7 +969,7 @@ mod tests { #[test] unconstrained fn nonempty_block_out_hash() { - let mut end: CombinedAccumulatedData = dep::std::unsafe::zeroed(); + let mut end = CombinedAccumulatedData::default(); end.new_l2_to_l1_msgs[MAX_NEW_L2_TO_L1_MSGS_PER_TX - 1] = 123; let out_hash = compute_kernel_out_hash(end); diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/previous_rollup_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/previous_rollup_data.nr index 3185a6bfdb7..2f8334e502d 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/previous_rollup_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/previous_rollup_data.nr @@ -3,7 +3,7 @@ use crate::abis::previous_rollup_data::PreviousRollupData; use dep::types::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot; pub fn default_previous_rollup_data() -> [PreviousRollupData; 2] { - let mut previous_rollup_data: [PreviousRollupData; 2] = dep::std::unsafe::zeroed(); + let mut previous_rollup_data =[PreviousRollupData::default(); 2]; previous_rollup_data[0].base_or_merge_rollup_public_inputs.start.note_hash_tree = AppendOnlyTreeSnapshot { root: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_non_revertible_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_non_revertible_data_builder.nr index ad363eff5f1..04388d4fb7b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_non_revertible_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_non_revertible_data_builder.nr @@ -24,6 +24,18 @@ struct AccumulatedNonRevertibleDataBuilder { public_data_update_requests: BoundedVec, } +impl Default for AccumulatedNonRevertibleDataBuilder { + fn default() -> Self { + AccumulatedNonRevertibleDataBuilder { + revert_code: 0 as u8, + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + public_call_stack: BoundedVec::new(), + public_data_update_requests: BoundedVec::new(), + } + } +} + impl AccumulatedNonRevertibleDataBuilder { pub fn to_private(self) -> PrivateAccumulatedNonRevertibleData { PrivateAccumulatedNonRevertibleData { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_revertible_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_revertible_data_builder.nr index 232ebbc81bc..49827cff945 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_revertible_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_revertible_data_builder.nr @@ -33,6 +33,23 @@ struct AccumulatedRevertibleDataBuilder { public_data_update_requests: BoundedVec, } +impl Default for AccumulatedRevertibleDataBuilder { + fn default() -> Self { + AccumulatedRevertibleDataBuilder { + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + private_call_stack: BoundedVec::new(), + public_call_stack: BoundedVec::new(), + new_l2_to_l1_msgs: BoundedVec::new(), + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + public_data_update_requests: BoundedVec::new(), + } + } +} + impl AccumulatedRevertibleDataBuilder { pub fn to_private(self) -> PrivateAccumulatedRevertibleData { PrivateAccumulatedRevertibleData { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr index e61844e1c7b..8e4333b11e1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr @@ -41,6 +41,25 @@ struct CombinedAccumulatedData { public_data_update_requests: [PublicDataUpdateRequest; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], } +impl Default for CombinedAccumulatedData { + fn default() -> Self { + CombinedAccumulatedData { + revert_code: 0 as u8, + new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_TX], + new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_TX], + private_call_stack: [CallRequest::default(); MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], + public_call_stack: [CallRequest::default(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], + new_l2_to_l1_msgs: [0; MAX_NEW_L2_TO_L1_MSGS_PER_TX], + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + public_data_update_requests: [PublicDataUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], + } + } +} + + impl CombinedAccumulatedData { pub fn needs_app_logic(self) -> bool { // if we have any enqueued revertible public calls, we need to run the public app logic circuit. @@ -86,7 +105,7 @@ mod tests { #[test] unconstrained fn splits_revertible_and_non_revertible() { - let mut builder: CombinedAccumulatedDataBuilder = unsafe::zeroed(); + let mut builder = CombinedAccumulatedDataBuilder::default(); let non_revertible_commitments = [ SideEffect { value: 1, counter: 1 }, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr index 7db03c202d3..5cd5780acb5 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr @@ -45,6 +45,24 @@ struct CombinedAccumulatedDataBuilder { public_data_update_requests: BoundedVec, } +impl Default for CombinedAccumulatedDataBuilder { + fn default() -> Self { + CombinedAccumulatedDataBuilder { + revert_code: 0 as u8, + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + private_call_stack: BoundedVec::new(), + public_call_stack: BoundedVec::new(), + new_l2_to_l1_msgs: BoundedVec::new(), + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + public_data_update_requests: BoundedVec::new(), + } + } +} + impl CombinedAccumulatedDataBuilder { pub fn recombine( non_revertible: PublicAccumulatedNonRevertibleData, @@ -124,8 +142,8 @@ impl CombinedAccumulatedDataBuilder { self, min_revertible_side_effect_counter: u32 ) -> (PrivateAccumulatedNonRevertibleData, PrivateAccumulatedRevertibleData) { - let mut non_revertible_builder: AccumulatedNonRevertibleDataBuilder = unsafe::zeroed(); - let mut revertible_builder: AccumulatedRevertibleDataBuilder = unsafe::zeroed(); + let mut non_revertible_builder = AccumulatedNonRevertibleDataBuilder::default(); + let mut revertible_builder = AccumulatedRevertibleDataBuilder::default(); for i in 0..MAX_NEW_NOTE_HASHES_PER_TX { let commitment = self.new_note_hashes.storage[i]; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr index 9dc4974700f..bba3ebf718e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr @@ -9,3 +9,12 @@ struct CombinedConstantData { // protocol to execute and prove the transaction. tx_context: TxContext, } + +impl Default for CombinedConstantData { + fn default() -> Self { + CombinedConstantData { + historical_header: Header::default(), + tx_context: TxContext::default(), + } + } +} 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 927f5b5b37f..4e13b70d5cf 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 @@ -18,6 +18,19 @@ struct PrivateKernelCircuitPublicInputsBuilder { is_private: bool, } +impl Default for PrivateKernelCircuitPublicInputsBuilder { + fn default() -> Self { + PrivateKernelCircuitPublicInputsBuilder { + aggregation_object: AggregationObject::default(), + min_revertible_side_effect_counter: 0 as u32, + validation_requests: ValidationRequestsBuilder::default(), + end: CombinedAccumulatedDataBuilder::default(), + constants: CombinedConstantData::default(), + is_private: false, + } + } +} + impl PrivateKernelCircuitPublicInputsBuilder { pub fn to_inner(self) -> PrivateKernelInnerCircuitPublicInputs { PrivateKernelInnerCircuitPublicInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr index 2fbf666eb01..1b4af194791 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr @@ -17,16 +17,43 @@ struct VKMembershipWitness{ sibling_path: [Field; ROLLUP_VK_TREE_HEIGHT] } +impl Default for VKMembershipWitness { + fn default() -> Self { + VKMembershipWitness { + leaf_index: 0, + sibling_path: [0; ROLLUP_VK_TREE_HEIGHT] + } + } +} + struct NullifierMembershipWitness{ leaf_index: Field, sibling_path: [Field; NULLIFIER_TREE_HEIGHT] } +impl Default for NullifierMembershipWitness { + fn default() -> Self { + NullifierMembershipWitness { + leaf_index: 0, + sibling_path: [0; NULLIFIER_TREE_HEIGHT] + } + } +} + struct PublicDataMembershipWitness{ leaf_index: Field, sibling_path: [Field; PUBLIC_DATA_TREE_HEIGHT] } +impl Default for PublicDataMembershipWitness { + fn default() -> Self { + PublicDataMembershipWitness { + leaf_index: 0, + sibling_path: [0; PUBLIC_DATA_TREE_HEIGHT] + } + } +} + struct ArchiveRootMembershipWitness{ leaf_index: Field, sibling_path: [Field; ARCHIVE_HEIGHT] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr index ec3d1027d7e..409d84140c3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr @@ -31,7 +31,7 @@ impl Hash for PublicCallStackItem { impl PublicCallStackItem { fn as_execution_request(self) -> Self { let public_inputs = self.public_inputs; - let mut request_public_inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); + let mut request_public_inputs = PublicCircuitPublicInputs::default(); request_public_inputs.call_context = public_inputs.call_context; request_public_inputs.args_hash = public_inputs.args_hash; @@ -60,7 +60,7 @@ mod tests { let contract_address = AztecAddress::from_field(1); let function_data = FunctionData { selector: FunctionSelector::from_u32(2), is_private: false, is_transpiled: false }; - let mut public_inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); + let mut public_inputs = PublicCircuitPublicInputs::default(); public_inputs.new_note_hashes[0] = SideEffect{ value: 1, counter: 0, @@ -78,7 +78,7 @@ mod tests { let contract_address = AztecAddress::from_field(1); let function_data = FunctionData { selector: FunctionSelector::from_u32(2), is_private: false, is_transpiled: false }; - let mut public_inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); + let mut public_inputs = PublicCircuitPublicInputs::default(); public_inputs.new_note_hashes[0] = SideEffect{ value: 1, counter: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index 6ed283c9d0f..09d1b0c790a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -57,6 +57,31 @@ impl Eq for PublicCircuitPublicInputs { } } +impl Default for PublicCircuitPublicInputs { + fn default() -> Self { + PublicCircuitPublicInputs { + call_context: CallContext::default(), + args_hash: 0, + return_values: [0; RETURN_VALUES_LENGTH], + nullifier_read_requests: [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], + nullifier_non_existent_read_requests: [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], + contract_storage_update_requests: [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], + contract_storage_reads: [StorageRead::default(); MAX_PUBLIC_DATA_READS_PER_CALL], + public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], + new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL], + new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL], + new_l2_to_l1_msgs: [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], + start_side_effect_counter: 0 as u32, + end_side_effect_counter: 0 as u32, + unencrypted_logs_hash: 0, + unencrypted_log_preimages_length: 0, + historical_header: Header::default(), + prover_address: AztecAddress::default(), + revert_code: 0 as u8, + } + } +} + impl Serialize for PublicCircuitPublicInputs { fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(); @@ -137,7 +162,7 @@ impl Hash for PublicCircuitPublicInputs { #[test] fn serialization_of_empty() { - let pcpi: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); + let pcpi = PublicCircuitPublicInputs::default(); let serialized = pcpi.serialize(); let deserialized = PublicCircuitPublicInputs::deserialize(serialized); assert(pcpi.eq(deserialized)); @@ -145,7 +170,7 @@ fn serialization_of_empty() { #[test] fn empty_hash() { - let inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); + let inputs = PublicCircuitPublicInputs::default(); let hash = inputs.hash(); // Value from public_circuit_public_inputs.test.ts "computes empty item hash" test diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr index d8f02f49d29..1a18cc87c14 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr @@ -22,6 +22,19 @@ struct ValidationRequestsBuilder { public_data_reads: BoundedVec, } +impl Default for ValidationRequestsBuilder { + fn default() -> Self { + ValidationRequestsBuilder { + max_block_number: dep::std::unsafe::zeroed(), + note_hash_read_requests: BoundedVec::new(), + nullifier_read_requests: BoundedVec::new(), + nullifier_non_existent_read_requests: BoundedVec::new(), + nullifier_key_validation_requests: BoundedVec::new(), + public_data_reads: BoundedVec::new(), + } + } +} + impl ValidationRequestsBuilder { pub fn finish(self) -> ValidationRequests { ValidationRequests { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr index 5bb59eaf81a..e356edf8cd1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr @@ -27,6 +27,17 @@ impl Eq for Header { } } +impl Default for Header { + fn default() -> Self { + Self { + last_archive: AppendOnlyTreeSnapshot::default(), + content_commitment: ContentCommitment::default(), + state: StateReference::default(), + global_variables: GlobalVariables::default(), + } + } +} + impl Serialize for Header { fn serialize(self) -> [Field; HEADER_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(); @@ -64,17 +75,6 @@ impl Deserialize for Header { } } -impl Default for Header { - fn default() -> Self { - Self { - last_archive: AppendOnlyTreeSnapshot::default(), - content_commitment: ContentCommitment::default(), - state: StateReference::default(), - global_variables: GlobalVariables::default(), - } - } -} - impl Hash for Header { fn hash(self) -> Field { pedersen_hash(self.serialize(), GENERATOR_INDEX__BLOCK_HASH) @@ -83,7 +83,7 @@ impl Hash for Header { #[test] fn serialization_of_empty() { - let header: Header = dep::std::unsafe::zeroed(); + let header = Header::default(); let serialized = header.serialize(); let deserialized = Header::deserialize(serialized); assert(header.eq(deserialized)); @@ -91,13 +91,13 @@ fn serialization_of_empty() { #[test] fn hash_smoke() { - let header: Header = dep::std::unsafe::zeroed(); + let header = Header::default(); let _hashed = header.hash(); } #[test] fn empty_hash_is_default() { - let header: Header = dep::std::unsafe::zeroed(); + let header = Header::default(); let hash = header.hash(); // Value from new_contract_data.test.ts "computes empty hash" test diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr index f1cacb956ac..27108ed2c53 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr @@ -3,6 +3,15 @@ struct MerkleTree { nodes: [Field; N], } +impl Default for MerkleTree { + fn default() -> Self { + MerkleTree { + leaves: [0; N], + nodes: [0; N] + } + } +} + impl MerkleTree { pub fn new(leaves: [Field; N]) -> Self { let mut nodes = [0; N]; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr b/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr index 36b1e955353..23f75a58027 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr @@ -3,13 +3,25 @@ struct AggregationObject{} +impl Default for AggregationObject { + fn default() -> Self { + AggregationObject {} + } +} + struct Proof{} +impl Default for Proof { + fn default() -> Self { + Proof {} + } +} + struct VerificationKey{} -impl Default for AggregationObject { +impl Default for VerificationKey { fn default() -> Self { - AggregationObject {} + VerificationKey {} } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr b/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr index 7094179b08f..3f0451bce63 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr @@ -18,6 +18,16 @@ impl Eq for PartialStateReference { } } +impl Default for PartialStateReference { + fn default() -> Self { + Self { + note_hash_tree: AppendOnlyTreeSnapshot::default(), + nullifier_tree: AppendOnlyTreeSnapshot::default(), + public_data_tree: AppendOnlyTreeSnapshot::default(), + } + } +} + impl Serialize for PartialStateReference { fn serialize(self) -> [Field; PARTIAL_STATE_REFERENCE_LENGTH] { let serialized_note_hash_tree = self.note_hash_tree.serialize(); @@ -51,19 +61,11 @@ impl Deserialize for PartialStateReference { } } -impl Default for PartialStateReference { - fn default() -> Self { - Self { - note_hash_tree: AppendOnlyTreeSnapshot::default(), - nullifier_tree: AppendOnlyTreeSnapshot::default(), - public_data_tree: AppendOnlyTreeSnapshot::default(), - } - } -} + #[test] -fn serialization_of_empty() { - let partial: PartialStateReference = dep::std::unsafe::zeroed(); +fn serialization_of_default() { + let partial = PartialStateReference::default(); let _serialized = partial.serialize(); let _deserialized = PartialStateReference::deserialize(_serialized); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr index 24cb72b28ef..2f4004a1c2f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr @@ -17,6 +17,15 @@ impl Eq for StateReference { } } +impl Default for StateReference { + fn default() -> Self { + Self { + l1_to_l2_message_tree: AppendOnlyTreeSnapshot::default(), + partial: PartialStateReference::default(), + } + } +} + impl Serialize for StateReference { fn serialize(self) -> [Field; STATE_REFERENCE_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(); @@ -44,18 +53,9 @@ impl Deserialize for StateReference { } } -impl Default for StateReference { - fn default() -> Self { - Self { - l1_to_l2_message_tree: AppendOnlyTreeSnapshot::default(), - partial: PartialStateReference::default(), - } - } -} - #[test] fn serialization_of_empty() { - let state: StateReference = dep::std::unsafe::zeroed(); + let state = StateReference::default(); let _serialized = state.serialize(); let _deserialized = StateReference::deserialize(_serialized); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr index ee69f4c09a3..2f25514cf53 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr @@ -43,8 +43,8 @@ struct PreviousKernelDataBuilder { impl PreviousKernelDataBuilder { pub fn new(is_for_public: bool) -> Self { - let mut end: CombinedAccumulatedDataBuilder = dep::std::unsafe::zeroed(); - let mut end_non_revertible: AccumulatedNonRevertibleDataBuilder = dep::std::unsafe::zeroed(); + let mut end = CombinedAccumulatedDataBuilder::default(); + let mut end_non_revertible = AccumulatedNonRevertibleDataBuilder::default(); // 0th nullifier must be non-zero. let tx_nullifier = SideEffectLinkedToNoteHash { value: 321, note_hash: 0, counter: 0 }; // but the public kernels expect this first nullifier to have been partitioned into diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr index c5fdd279524..235bd8540d9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr @@ -76,6 +76,17 @@ struct NonEmptyMerkleTree Default for NonEmptyMerkleTree { + fn default() -> Self { + NonEmptyMerkleTree { + subtree: MerkleTree::default(), + zero_hashes: [0; TREE_HEIGHT], + left_supertree_branch: [0; SUPERTREE_HEIGHT], + _phantom_subtree_height: [0; SUBTREE_HEIGHT], + } + } +} + impl NonEmptyMerkleTree { pub fn new( non_zero_leaves: [Field; SUBTREE_ITEMS], From d6c67b69564fa13e49cf92c334d209a6b71095d8 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Thu, 28 Mar 2024 17:35:17 +0000 Subject: [PATCH 07/77] fix --- .../src/public_kernel_app_logic.nr | 2 +- .../src/public_kernel_setup.nr | 2 +- .../src/public_kernel_tail.nr | 2 +- .../src/public_kernel_teardown.nr | 2 +- .../src/abis/constant_rollup_data.nr | 13 +++++++++ .../rollup-lib/src/base/base_rollup_inputs.nr | 19 +++++++++++- .../src/merge/merge_rollup_inputs.nr | 8 +++++ .../src/tests/merge_rollup_inputs.nr | 2 +- .../crates/types/src/abis/global_variables.nr | 2 +- ...ic_kernel_circuit_public_inputs_builder.nr | 12 ++++++++ .../types/src/tests/kernel_data_builder.nr | 24 ++++++++++++++- .../private_circuit_public_inputs_builder.nr | 29 ++++++++++++++++++- 12 files changed, 108 insertions(+), 9 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr index db9b2311809..60c98f50fae 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr @@ -22,7 +22,7 @@ impl PublicKernelAppLogicCircuitPrivateInputs { fn public_kernel_app_logic(self) -> PublicKernelCircuitPublicInputs { // construct the circuit outputs - let mut public_inputs: PublicKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::default(); common::initialize_revert_code(self.previous_kernel, self.public_call, &mut public_inputs); // initialise the end state with our provided previous kernel state diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr index b7bba7d830a..1390e4a2143 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr @@ -41,7 +41,7 @@ impl PublicKernelSetupCircuitPrivateInputs { fn public_kernel_setup(self) -> PublicKernelCircuitPublicInputs { // construct the circuit outputs - let mut public_inputs: PublicKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::default(); // since this phase is non-revertible, we must assert the public call did not revert common::validate_public_call_non_revert(self.public_call); common::initialize_revert_code(self.previous_kernel, self.public_call, &mut public_inputs); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr index 9742650515e..1e762ba56b7 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr @@ -101,7 +101,7 @@ impl PublicKernelTailCircuitPrivateInputs { } pub fn public_kernel_tail(self) -> PublicKernelCircuitPublicInputs { - let mut public_inputs: PublicKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let mut public_input = PublicKernelCircuitPublicInputsBuilder::default(); self.validate_inputs(); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr index f1ce09d6827..289f39beefc 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr @@ -25,7 +25,7 @@ impl PublicKernelTeardownCircuitPrivateInputs { fn public_kernel_teardown(self) -> PublicKernelCircuitPublicInputs { // construct the circuit outputs - let mut public_inputs: PublicKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::default(); // since this phase is non-revertible, we must assert the public call did not revert common::validate_public_call_non_revert(self.public_call); common::initialize_revert_code(self.previous_kernel, self.public_call, &mut public_inputs); diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr index 66de37d34b4..3393ec50941 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr @@ -25,3 +25,16 @@ impl Eq for ConstantRollupData { (self.merge_rollup_vk_hash == other.merge_rollup_vk_hash) } } + +impl Default for ConstantRollupData { + fn default() -> Self { + ConstantRollupData { + last_archive: AppendOnlyTreeSnapshot::default(), + private_kernel_vk_tree_root: 0, + public_kernel_vk_tree_root: 0, + base_rollup_vk_hash: 0, + merge_rollup_vk_hash: 0, + global_variables: GlobalVariables::default(), + } + } +} diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr index 92a21b7fd2a..b8f643d9579 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -523,13 +523,30 @@ mod tests { constants: ConstantRollupData, } + impl Default for BaseRollupInputsBuilder { + fn default() -> Self { + BaseRollupInputsBuilder { + kernel_data: PreviousKernelDataBuilder::default(), + pre_existing_notes: [0; MAX_NEW_NOTE_HASHES_PER_TX], + pre_existing_nullifiers: [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX], + pre_existing_contracts: [0; 2], + pre_existing_public_data: [PublicDataTreeLeafPreimage::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], + pre_existing_blocks: [0; 2], + public_data_reads: BoundedVec::new(), + public_data_writes:BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + constants: ConstantRollupData::default(), + } + } + } + fn test_compute_empty_root(size: [Field; N]) -> Field { compute_zero_hashes(size)[N - 1] } impl BaseRollupInputsBuilder { fn new() -> Self { - let mut inputs: BaseRollupInputsBuilder = dep::std::unsafe::zeroed(); + let mut inputs = BaseRollupInputsBuilder::default(); inputs.constants.global_variables.chain_id = 1; inputs.constants.global_variables.version = 0; 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 a0fcfee73a8..32bc591c743 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 @@ -7,6 +7,14 @@ struct MergeRollupInputs{ previous_rollup_data : [PreviousRollupData; 2] } +impl Default for MergeRollupInputs { + fn default() -> Self { + MergeRollupInputs { + previous_rollup_data: [PreviousRollupData::default(); 2] + } + } +} + impl MergeRollupInputs { pub fn merge_rollup_circuit(self) -> BaseOrMergeRollupPublicInputs { // TODO(Lasse): Verify the previous rollup proofs 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 8c34ade8bbd..be11951252f 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 @@ -4,7 +4,7 @@ use dep::types::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot; use crate::tests::previous_rollup_data::default_previous_rollup_data; pub fn default_merge_rollup_inputs() -> MergeRollupInputs { - let mut inputs: MergeRollupInputs = dep::std::unsafe::zeroed(); + let mut inputs = MergeRollupInputs::default(); inputs.previous_rollup_data = default_previous_rollup_data(); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr index b3f22d0b378..2a415be8a61 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr @@ -68,7 +68,7 @@ impl Default for GlobalVariables { #[test] fn serialization_of_default() { - let vars: GlobalVariables = dep::std::unsafe::zeroed(); + let vars = GlobalVariables::default(); let _serialized = vars.serialize(); let _deserialized = GlobalVariables::deserialize(_serialized); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr index 96d8a0d7a75..306ff9c7d53 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr @@ -15,6 +15,18 @@ struct PublicKernelCircuitPublicInputsBuilder { constants: CombinedConstantData, } +impl Default for PublicKernelCircuitPublicInputsBuilder { + fn default() -> Self { + PublicKernelCircuitPublicInputsBuilder { + aggregation_object: AggregationObject::default(), + validation_requests: ValidationRequestsBuilder::default(), + end_non_revertible: AccumulatedNonRevertibleDataBuilder::default(), + end: AccumulatedRevertibleDataBuilder::default(), + constants: CombinedConstantData::default(), + } + } +} + impl PublicKernelCircuitPublicInputsBuilder { pub fn to_inner(self) -> PublicKernelCircuitPublicInputs { let end_non_revertible = self.end_non_revertible.to_public(); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr index 2f25514cf53..0a6d55dfba1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr @@ -41,6 +41,28 @@ struct PreviousKernelDataBuilder { min_revertible_side_effect_counter: u32, } +impl Default for PreviousKernelDataBuilder { + fn default() -> Self { + PreviousKernelDataBuilder { + contract_address: AztecAddress::default(), + storage_contract_address: AztecAddress::default(), + portal_contract_address: EthAddress::default(), + validation_requests: ValidationRequestsBuilder::default(), + end: CombinedAccumulatedDataBuilder::default(), + end_non_revertible: AccumulatedNonRevertibleDataBuilder::default(), + historical_header: Header::default(), + tx_context: TxContext::default(), + is_private: false, + proof: Proof::default(), + vk: VerificationKey::default(), + vk_index: 0 as u32, + vk_path: [0; VK_TREE_HEIGHT], + sideffect_counter: 0 as u32, + min_revertible_side_effect_counter: 0 as u32, + } + } +} + impl PreviousKernelDataBuilder { pub fn new(is_for_public: bool) -> Self { let mut end = CombinedAccumulatedDataBuilder::default(); @@ -62,7 +84,7 @@ impl PreviousKernelDataBuilder { contract_address: fixtures::contracts::parent_contract.address, storage_contract_address: fixtures::contracts::parent_contract.address, portal_contract_address: fixtures::contracts::parent_contract.portal_contract_address, - validation_requests: unsafe::zeroed(), + validation_requests: ValidationRequestsBuilder::default(), end, end_non_revertible, historical_header: fixtures::HEADER, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr index d0ecc0c82c1..3eb92302eba 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr @@ -48,9 +48,36 @@ struct PrivateCircuitPublicInputsBuilder { version: Field, } +impl Default for PrivateCircuitPublicInputsBuilder { + fn default() -> Self { + PrivateCircuitPublicInputsBuilder { + call_context: CallContext::default(), + args_hash: 0, + return_values: BoundedVec::new(), + min_revertible_side_effect_counter: 0 as u32, + max_block_number: dep::std::unsafe::zeroed(), + note_hash_read_requests: BoundedVec::new(), + nullifier_read_requests: BoundedVec::new(), + nullifier_key_validation_requests: BoundedVec::new(), + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + private_call_stack_hashes: BoundedVec::new(), + public_call_stack_hashes: BoundedVec::new(), + new_l2_to_l1_msgs: BoundedVec::new(), + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + historical_header: Header::default(), + chain_id: 0, + version: 0, + } + } +} + impl PrivateCircuitPublicInputsBuilder { pub fn new() -> Self { - let mut public_inputs: PrivateCircuitPublicInputsBuilder = dep::std::unsafe::zeroed(); + let mut public_inputs = PrivateCircuitPublicInputsBuilder::default(); let args_hash = hash_args_array([]); From a3cd011f4aada508e89bfa27ed4cab75b36c6ae2 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Thu, 28 Mar 2024 17:53:38 +0000 Subject: [PATCH 08/77] fix fix indexed tree --- .../parity-lib/src/parity_public_inputs.nr | 10 ++++ .../parity-lib/src/root/root_parity_input.nr | 9 +++ .../base_or_merge_rollup_public_inputs.nr | 15 +++++ .../src/abis/previous_rollup_data.nr | 2 +- .../rollup-lib/src/root/root_rollup_inputs.nr | 14 +++++ .../src/tests/root_rollup_inputs.nr | 2 +- .../types/src/abis/private_call_stack_item.nr | 14 ++++- .../src/abis/private_circuit_public_inputs.nr | 55 +++++++++++-------- .../validation_requests_builder.nr | 2 +- .../types/src/merkle_tree/indexed_tree.nr | 4 +- .../src/tests/private_call_data_builder.nr | 6 +- .../private_circuit_public_inputs_builder.nr | 2 +- .../src/tests/public_call_data_builder.nr | 2 +- .../public_circuit_public_inputs_builder.nr | 27 ++++++++- 14 files changed, 128 insertions(+), 36 deletions(-) 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 03240ebe3ab..e9e6ae5917d 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 @@ -5,3 +5,13 @@ struct ParityPublicInputs { sha_root: Field, converted_root: Field, } + +impl Default for ParityPublicInputs { + fn default() -> Self { + ParityPublicInputs { + aggregation_object: AggregationObject::default(), + sha_root: 0, + converted_root: 0, + } + } +} 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 bafb3dff201..563e7a109aa 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 @@ -5,3 +5,12 @@ struct RootParityInput { proof: Proof, public_inputs: ParityPublicInputs, } + +impl Default for RootParityInput { + fn default() -> Self { + RootParityInput { + proof: Proof::default(), + public_inputs: ParityPublicInputs::default(), + } + } +} 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 15f33302d75..b9c50ce08d0 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 @@ -29,3 +29,18 @@ struct BaseOrMergeRollupPublicInputs { txs_effects_hash : Field, out_hash : Field, } + +impl Default for BaseOrMergeRollupPublicInputs { + fn default() -> Self { + BaseOrMergeRollupPublicInputs { + rollup_type : 0 as u32, + height_in_block_tree : 0, + aggregation_object : AggregationObject::default(), + constants : ConstantRollupData::default(), + start: PartialStateReference::default(), + end: PartialStateReference::default(), + txs_effects_hash : 0, + out_hash : 0, + } + } +} 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 37200562c09..4afe9a85f0d 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 @@ -14,7 +14,7 @@ struct PreviousRollupData{ impl Default for PreviousRollupData { fn default() -> Self { PreviousRollupData { - base_or_merge_rollup_public_inputs: dep::std::unsafe::zeroed(), + base_or_merge_rollup_public_inputs: BaseOrMergeRollupPublicInputs::default(), proof : Proof::default(), vk : VerificationKey::default(), vk_index : 0 as u32, 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 52d61a21832..1e9b3dc1b5f 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 @@ -33,6 +33,20 @@ struct RootRollupInputs { new_archive_sibling_path : [Field; ARCHIVE_HEIGHT], } +impl Default for RootRollupInputs { + fn default() -> Self { + RootRollupInputs { + previous_rollup_data : [PreviousRollupData::default(); 2], + l1_to_l2_roots: RootParityInput::default(), + new_l1_to_l2_messages : [0; NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP], + new_l1_to_l2_message_tree_root_sibling_path : [0; L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH], + start_l1_to_l2_message_tree_snapshot : AppendOnlyTreeSnapshot::default(), + start_archive_snapshot : AppendOnlyTreeSnapshot::default(), + new_archive_sibling_path : [0; ARCHIVE_HEIGHT], + } + } +} + impl RootRollupInputs { pub fn root_rollup_circuit(self) -> RootRollupPublicInputs { let left = self.previous_rollup_data[0].base_or_merge_rollup_public_inputs; diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/root_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/root_rollup_inputs.nr index 5a7a64b0e80..ef833f83883 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/root_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/root_rollup_inputs.nr @@ -35,7 +35,7 @@ pub fn compute_archive_snapshot() -> (AppendOnlyTreeSnapshot, [Field; ARCHIVE_HE } pub fn default_root_rollup_inputs() -> RootRollupInputs { - let mut inputs: RootRollupInputs = dep::std::unsafe::zeroed(); + let mut inputs = RootRollupInputs::default(); let (l1_l2_empty_snapshot, l1_l2_empty_sibling_path) = compute_l1_l2_empty_snapshot(); inputs.new_l1_to_l2_message_tree_root_sibling_path = l1_l2_empty_sibling_path; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr index fb3d8c6362c..13936807157 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr @@ -24,6 +24,16 @@ impl Eq for PrivateCallStackItem { } } +impl Default for PrivateCallStackItem { + fn default() -> Self { + PrivateCallStackItem { + contract_address: AztecAddress::default(), + function_data: FunctionData::default(), + public_inputs: PrivateCircuitPublicInputs::default(), + } + } +} + impl Serialize for PrivateCallStackItem { fn serialize(self) -> [Field; PRIVATE_CALL_STACK_ITEM_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(); @@ -62,7 +72,7 @@ impl Hash for PrivateCallStackItem { #[test] fn serialization_of_empty() { - let item: PrivateCallStackItem = dep::std::unsafe::zeroed(); + let item = PrivateCallStackItem::default(); let serialized = item.serialize(); let deserialized = PrivateCallStackItem::deserialize(serialized); assert(item.eq(deserialized)); @@ -70,7 +80,7 @@ fn serialization_of_empty() { #[test] fn empty_hash() { - let mut item: PrivateCallStackItem = dep::std::unsafe::zeroed(); + let mut item = PrivateCallStackItem::default(); item.function_data.is_private = true; let hash = item.hash(); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr index 9b6ec359761..bc3f0313605 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr @@ -57,27 +57,36 @@ struct PrivateCircuitPublicInputs { impl Eq for PrivateCircuitPublicInputs { fn eq(self, other: Self) -> bool { - self.call_context.eq(other.call_context) & - self.args_hash.eq(other.args_hash) & - (self.return_values == other.return_values) & - (self.max_block_number == other.max_block_number) & - (self.note_hash_read_requests == other.note_hash_read_requests) & - (self.nullifier_read_requests == other.nullifier_read_requests) & - (self.nullifier_key_validation_requests == other.nullifier_key_validation_requests) & - (self.new_note_hashes == other.new_note_hashes) & - (self.new_nullifiers == other.new_nullifiers) & - (self.private_call_stack_hashes == other.private_call_stack_hashes) & - (self.public_call_stack_hashes == other.public_call_stack_hashes) & - (self.new_l2_to_l1_msgs == other.new_l2_to_l1_msgs) & - (self.start_side_effect_counter == other.start_side_effect_counter) & - (self.end_side_effect_counter == other.end_side_effect_counter) & - (self.encrypted_logs_hash == other.encrypted_logs_hash) & - (self.unencrypted_logs_hash == other.unencrypted_logs_hash) & - (self.encrypted_log_preimages_length == other.encrypted_log_preimages_length) & - (self.unencrypted_log_preimages_length == other.unencrypted_log_preimages_length) & - self.historical_header.eq(other.historical_header) & - self.chain_id.eq(other.chain_id) & - self.version.eq(other.version) + self.serialize() == other.serialize() + } +} + +impl Default for PrivateCircuitPublicInputs { + fn default() -> Self { + PrivateCircuitPublicInputs { + call_context: CallContext::default(), + args_hash: 0, + return_values: [0; RETURN_VALUES_LENGTH], + min_revertible_side_effect_counter: 0 as u32, + max_block_number: MaxBlockNumber::default(), + note_hash_read_requests: [SideEffect::default(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], + nullifier_read_requests: [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], + nullifier_key_validation_requests: [NullifierKeyValidationRequest::default(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL], + new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL], + new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL], + private_call_stack_hashes: [0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL], + public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], + new_l2_to_l1_msgs: [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], + start_side_effect_counter : 0 as u32, + end_side_effect_counter : 0 as u32, + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + historical_header: Header::default(), + chain_id: 0, + version: 0, + } } } @@ -170,7 +179,7 @@ impl Hash for PrivateCircuitPublicInputs { #[test] fn serialization_of_empty() { - let pcpi: PrivateCircuitPublicInputs = dep::std::unsafe::zeroed(); + let pcpi = PrivateCircuitPublicInputs::default(); let serialized = pcpi.serialize(); let deserialized = PrivateCircuitPublicInputs::deserialize(serialized); assert(pcpi.eq(deserialized)); @@ -178,7 +187,7 @@ fn serialization_of_empty() { #[test] fn empty_hash() { - let inputs: PrivateCircuitPublicInputs = dep::std::unsafe::zeroed(); + let inputs = PrivateCircuitPublicInputs::default(); let hash = inputs.hash(); // Value from private_circuit_public_inputs.test.ts "computes empty item hash" test diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr index 1a18cc87c14..ade84793296 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr @@ -25,7 +25,7 @@ struct ValidationRequestsBuilder { impl Default for ValidationRequestsBuilder { fn default() -> Self { ValidationRequestsBuilder { - max_block_number: dep::std::unsafe::zeroed(), + max_block_number: MaxBlockNumber::default(), note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), nullifier_non_existent_read_requests: BoundedVec::new(), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr index 8a702edf1e8..f5a5938ce81 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr @@ -20,13 +20,13 @@ pub fn batch_insert Leaf, _subtree_height: [Field; SubtreeHeight], _tree_height: [Field; TreeHeight] -) -> AppendOnlyTreeSnapshot where Value: Eq + Default, Leaf: Hash { +) -> AppendOnlyTreeSnapshot where Value: Eq + Default, Leaf: Hash + Default { // A permutation to the values is provided to make the insertion use only one insertion strategy check_permutation(values_to_insert, sorted_values, sorted_values_indexes); // Now, update the existing leaves with the new leaves let mut current_tree_root = start_snapshot.root; - let mut insertion_subtree: [Leaf; SubtreeWidth] = dep::std::unsafe::zeroed(); + let mut insertion_subtree = [Leaf::default(); SubtreeWidth]; let start_insertion_index = start_snapshot.next_available_leaf_index; for i in 0..sorted_values.len() { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr index 2eb4d1f2294..e9a03b8120e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr @@ -53,8 +53,8 @@ impl PrivateCallDataBuilder { public_inputs, is_execution_request: false, function_data, - private_call_stack: dep::std::unsafe::zeroed(), - public_call_stack: dep::std::unsafe::zeroed(), + private_call_stack: BoundedVec::new(), + public_call_stack: BoundedVec::new(), proof: Proof {}, vk: VerificationKey {}, function_leaf_membership_witness: contract_function.membership_witness, @@ -62,7 +62,7 @@ impl PrivateCallDataBuilder { public_keys_hash: contract_data.public_keys_hash, contract_class_artifact_hash: contract_data.artifact_hash, contract_class_public_bytecode_commitment: contract_data.public_bytecode_commitment, - note_hash_read_request_membership_witnesses: dep::std::unsafe::zeroed(), + note_hash_read_request_membership_witnesses: BoundedVec::new(), portal_contract_address: public_inputs.call_context.portal_contract_address, acir_hash: contract_function.acir_hash } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr index 3eb92302eba..c8e71d0bc28 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr @@ -55,7 +55,7 @@ impl Default for PrivateCircuitPublicInputsBuilder { args_hash: 0, return_values: BoundedVec::new(), min_revertible_side_effect_counter: 0 as u32, - max_block_number: dep::std::unsafe::zeroed(), + max_block_number: MaxBlockNumber::is_default(), note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), nullifier_key_validation_requests: BoundedVec::new(), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr index 347fb89cde1..399b51bbb76 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr @@ -50,7 +50,7 @@ impl PublicCallDataBuilder { public_inputs, is_execution_request: false, function_data, - public_call_stack: dep::std::unsafe::zeroed(), + public_call_stack: BoundedVec::new(), proof: Proof {}, portal_contract_address, bytecode_hash: contract_function.acir_hash diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr index c033915b4b9..729bcc2e1c4 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr @@ -35,9 +35,34 @@ struct PublicCircuitPublicInputsBuilder { revert_code: u8, } +impl Default for PublicCircuitPublicInputsBuilder { + fn default() -> Self { + PublicCircuitPublicInputsBuilder { + call_context: CallContext::default(), + args_hash: 0, + return_values: BoundedVec::new(), + nullifier_read_requests: BoundedVec::new(), + nullifier_non_existent_read_requests: BoundedVec::new(), + contract_storage_update_requests: BoundedVec::new(), + contract_storage_reads: BoundedVec::new(), + public_call_stack_hashes: BoundedVec::new(), + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + new_l2_to_l1_msgs: BoundedVec::new(), + start_side_effect_counter: 0 as u32, + end_side_effect_counter: 0 as u32, + unencrypted_logs_hash: 0, + unencrypted_log_preimages_length: 0, + historical_header: Header::default(), + prover_address: AztecAddress::default(), + revert_code: 0 as u8, + } + } +} + impl PublicCircuitPublicInputsBuilder { pub fn new() -> Self { - let mut public_inputs: PublicCircuitPublicInputsBuilder = dep::std::unsafe::zeroed(); + let mut public_inputs = PublicCircuitPublicInputsBuilder::default(); public_inputs.call_context.msg_sender = fixtures::MSG_SENDER; public_inputs.historical_header = fixtures::HEADER; public_inputs From d5426e41fe0b6b2821a4d5c83cab16be4a00d841 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 29 Mar 2024 16:20:13 +0000 Subject: [PATCH 09/77] fix --- .../globals/private_global_variables.nr | 9 ++++++++ .../context/inputs/private_context_inputs.nr | 11 +++++++++ .../aztec/src/context/private_context.nr | 23 +++++++++++++++++++ .../aztec-nr/tests/src/note_getter_test.nr | 14 +++++------ 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/globals/private_global_variables.nr b/noir-projects/aztec-nr/aztec/src/context/globals/private_global_variables.nr index 99126a10dbf..b918db9645a 100644 --- a/noir-projects/aztec-nr/aztec/src/context/globals/private_global_variables.nr +++ b/noir-projects/aztec-nr/aztec/src/context/globals/private_global_variables.nr @@ -9,6 +9,15 @@ struct PrivateGlobalVariables { } // docs:end:private-global-variables +impl Default for PrivateGlobalVariables { + fn default() -> Self { + PrivateGlobalVariables { + chain_id: 0, + version: 0, + } + } +} + // Note: public global vars are equal to the private ones impl Serialize for PrivateGlobalVariables { fn serialize(self) -> [Field; PRIVATE_GLOBAL_VARIABLES_LENGTH] { diff --git a/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr b/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr index 79523b9affc..5f2b89670d8 100644 --- a/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr +++ b/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr @@ -10,3 +10,14 @@ struct PrivateContextInputs { start_side_effect_counter: u32, } // docs:end:private-context-inputs + +impl Default for PrivateContextInputs { + fn default() -> Self { + PrivateContextInputs { + call_context : CallContext::default(), + historical_header: Header::default(), + private_global_variables: PrivateGlobalVariables::default(), + start_side_effect_counter: 0 as u32, + } + } +} diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 5f25d6512be..dac28681f17 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -69,6 +69,29 @@ struct PrivateContext { nullifier_key: Option, } +impl Default for PrivateContext { + fn default() -> Self { + PrivateContext { + inputs: PrivateContextInputs::default(), + side_effect_counter: 0 as u32, + min_revertible_side_effect_counter: 0 as u32, + args_hash : 0, + return_values : BoundedVec::new(), + max_block_number: MaxBlockNumber::default(), + note_hash_read_requests: BoundedVec::new(), + nullifier_read_requests: BoundedVec::new(), + nullifier_key_validation_requests: BoundedVec::new(), + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + private_call_stack_hashes : BoundedVec::new(), + public_call_stack_hashes : BoundedVec::new(), + new_l2_to_l1_msgs : BoundedVec::new(), + historical_header: Header::default(), + nullifier_key: Option::none(), + } + } +} + impl ContextInterface for PrivateContext { fn msg_sender(self) -> AztecAddress { self.inputs.call_context.msg_sender diff --git a/noir-projects/aztec-nr/tests/src/note_getter_test.nr b/noir-projects/aztec-nr/tests/src/note_getter_test.nr index 2eaf28d964e..cce64dda642 100644 --- a/noir-projects/aztec-nr/tests/src/note_getter_test.nr +++ b/noir-projects/aztec-nr/tests/src/note_getter_test.nr @@ -10,7 +10,7 @@ use crate::mock::test_note::TestNote; #[test] fn sets_note_manually_and_fetches_it() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); context.inputs.call_context.storage_contract_address = AztecAddress::from_field(69); let mut test_note = TestNote::new(1337); @@ -28,7 +28,7 @@ fn sets_note_manually_and_fetches_it() { #[test(should_fail)] fn cannot_return_zero_notes() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); let storage_slot: Field = 0; let mut opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; @@ -38,7 +38,7 @@ fn cannot_return_zero_notes() { #[test(should_fail)] fn mismatched_address() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); context.inputs.call_context.storage_contract_address = AztecAddress::from_field(1); let storage_slot: Field = 0; @@ -51,7 +51,7 @@ fn mismatched_address() { #[test(should_fail)] fn mismatched_storage_slot() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); context.inputs.call_context.storage_contract_address = AztecAddress::from_field(1); let mut test_note = TestNote::new(1); @@ -68,7 +68,7 @@ fn mismatched_storage_slot() { #[test(should_fail)] fn invalid_selector() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); context.inputs.call_context.storage_contract_address = AztecAddress::from_field(1); let mut test_note = TestNote::new(1); @@ -89,7 +89,7 @@ fn invalid_selector() { #[test(should_fail)] fn invalid_note_order() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); let mut opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; opt_notes[0] = Option::some(TestNote::new(1)); @@ -106,7 +106,7 @@ fn invalid_note_order() { #[test] fn sparse_notes_array() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); let mut opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; opt_notes[1] = Option::some(TestNote::new(0)); From 8472c0565dd3e1bc8ef5c51b2d40468646c0ca76 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 29 Mar 2024 16:31:46 +0000 Subject: [PATCH 10/77] fix --- .../crates/public-kernel-lib/src/public_kernel_tail.nr | 2 +- .../types/src/tests/private_circuit_public_inputs_builder.nr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr index 1e762ba56b7..9a5517f6954 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr @@ -101,7 +101,7 @@ impl PublicKernelTailCircuitPrivateInputs { } pub fn public_kernel_tail(self) -> PublicKernelCircuitPublicInputs { - let mut public_input = PublicKernelCircuitPublicInputsBuilder::default(); + let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::default(); self.validate_inputs(); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr index c8e71d0bc28..01fdf142b32 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr @@ -55,7 +55,7 @@ impl Default for PrivateCircuitPublicInputsBuilder { args_hash: 0, return_values: BoundedVec::new(), min_revertible_side_effect_counter: 0 as u32, - max_block_number: MaxBlockNumber::is_default(), + max_block_number: MaxBlockNumber::default(), note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), nullifier_key_validation_requests: BoundedVec::new(), From 4ef2fcf8ac9c0adc7f8977f15a2e820ec38fe150 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Sat, 30 Mar 2024 12:24:24 +0000 Subject: [PATCH 11/77] Fix --- noir-projects/aztec-nr/tests/src/mock/test_note.nr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noir-projects/aztec-nr/tests/src/mock/test_note.nr b/noir-projects/aztec-nr/tests/src/mock/test_note.nr index bc4f262550f..9bc70eead23 100644 --- a/noir-projects/aztec-nr/tests/src/mock/test_note.nr +++ b/noir-projects/aztec-nr/tests/src/mock/test_note.nr @@ -19,7 +19,7 @@ impl NoteInterface for TestNote { fn deserialize_content(fields: [Field; TEST_NOTE_LENGTH]) -> Self { Self { value: fields[0], - header: NoteHeader::empty(), + header: NoteHeader::default(), } } @@ -56,6 +56,6 @@ impl NoteInterface for TestNote { impl TestNote { pub fn new(value: Field) -> Self { - TestNote { value, header: NoteHeader::empty() } + TestNote { value, header: NoteHeader::default() } } } From 9f808e1a6161a429f25c4ca16be4d11017bf14d7 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Sat, 30 Mar 2024 14:55:32 +0000 Subject: [PATCH 12/77] isdef ts --- yarn-project/aztec.js/src/contract/sent_tx.ts | 2 +- .../circuit-types/src/public_data_write.ts | 8 +- yarn-project/circuit-types/src/tx/tx.ts | 4 +- yarn-project/circuit-types/src/tx_effect.ts | 2 +- .../src/structs/call_context.test.ts | 2 +- .../circuits.js/src/structs/call_context.ts | 6 +- .../circuits.js/src/structs/call_request.ts | 16 ++-- .../src/structs/content_commitment.ts | 4 +- .../src/structs/contract_storage_read.ts | 4 +- .../contract_storage_update_request.ts | 4 +- .../circuits.js/src/structs/function_data.ts | 10 +- .../src/structs/global_variables.ts | 4 +- .../circuits.js/src/structs/header.ts | 20 ++-- .../kernel/combined_accumulated_data.ts | 92 +++++++++---------- .../src/structs/l2_to_l1_message.ts | 4 +- .../src/structs/max_block_number.ts | 4 +- ...te_hash_read_request_membership_witness.ts | 2 +- .../nullifier_key_validation_request.ts | 8 +- .../src/structs/partial_state_reference.ts | 12 +-- .../src/structs/private_call_stack_item.ts | 12 +-- .../structs/private_circuit_public_inputs.ts | 40 ++++---- .../src/structs/public_call_stack_item.ts | 20 ++-- .../structs/public_circuit_public_inputs.ts | 56 +++++------ .../src/structs/public_data_read_request.ts | 4 +- .../src/structs/public_data_update_request.ts | 8 +- .../circuits.js/src/structs/read_request.ts | 16 ++-- .../rollup/append_only_tree_snapshot.ts | 4 +- .../structs/rollup/nullifier_leaf/index.ts | 4 +- .../structs/rollup/public_data_leaf/index.ts | 6 +- .../circuits.js/src/structs/side_effects.ts | 36 ++++---- .../src/structs/state_reference.ts | 8 +- .../circuits.js/src/structs/tx_context.ts | 4 +- .../circuits.js/src/structs/tx_request.ts | 8 +- .../src/abi/function_selector.test.ts | 2 +- .../foundation/src/abi/function_selector.ts | 2 +- yarn-project/foundation/src/abi/selector.ts | 2 +- yarn-project/foundation/src/trees/index.ts | 4 +- .../standard_indexed_tree.ts | 2 +- .../pxe/src/kernel_prover/hints_builder.ts | 6 +- .../pxe/src/pxe_service/pxe_service.ts | 8 +- .../src/sequencer/abstract_phase_manager.ts | 12 +-- .../src/sequencer/tx_validator.ts | 2 +- .../src/client/client_execution_context.ts | 8 +- .../src/client/private_execution.test.ts | 22 ++--- yarn-project/simulator/src/public/executor.ts | 10 +- 45 files changed, 257 insertions(+), 257 deletions(-) diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index 03e9da395de..7f8ed606755 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -77,7 +77,7 @@ export class SentTx { receipt.debugInfo = { noteHashes: tx.noteHashes.filter(n => !n.isZero()), nullifiers: tx.nullifiers.filter(n => !n.isZero()), - publicDataWrites: tx.publicDataWrites.filter(p => !p.isEmpty()), + publicDataWrites: tx.publicDataWrites.filter(p => !p.isDefault()), l2ToL1Msgs: tx.l2ToL1Msgs.filter(l => !l.isZero()), visibleNotes, }; diff --git a/yarn-project/circuit-types/src/public_data_write.ts b/yarn-project/circuit-types/src/public_data_write.ts index 51edff93868..615bf11064d 100644 --- a/yarn-project/circuit-types/src/public_data_write.ts +++ b/yarn-project/circuit-types/src/public_data_write.ts @@ -55,7 +55,7 @@ export class PublicDataWrite { * Checks if the public data write operation is empty. * @returns True if the public data write operation is empty, false otherwise. */ - isEmpty(): boolean { + isDefault(): boolean { return this.leafIndex.isZero() && this.newValue.isZero(); } @@ -82,7 +82,7 @@ export class PublicDataWrite { * Creates an empty public data write operation. * @returns A new public data write operation instance. */ - static empty(): PublicDataWrite { + static default(): PublicDataWrite { return new PublicDataWrite(Fr.ZERO, Fr.ZERO); } @@ -94,7 +94,7 @@ export class PublicDataWrite { return new PublicDataWrite(Fr.random(), Fr.random()); } - static isEmpty(data: PublicDataWrite): boolean { - return data.isEmpty(); + static isDefault(data: PublicDataWrite): boolean { + return data.isDefault(); } } diff --git a/yarn-project/circuit-types/src/tx/tx.ts b/yarn-project/circuit-types/src/tx/tx.ts index 4ce149a3720..e99b348ad13 100644 --- a/yarn-project/circuit-types/src/tx/tx.ts +++ b/yarn-project/circuit-types/src/tx/tx.ts @@ -53,7 +53,7 @@ export class Tx { } const kernelPublicCallStackSize = - data?.end.publicCallStack && arrayNonEmptyLength(data.end.publicCallStack, item => item.isEmpty()); + data?.end.publicCallStack && arrayNonEmptyLength(data.end.publicCallStack, item => item.isDefault()); if (kernelPublicCallStackSize && kernelPublicCallStackSize > (enqueuedPublicFunctionCalls?.length ?? 0)) { throw new Error( `Missing preimages for enqueued public function calls in kernel circuit public inputs (expected @@ -139,7 +139,7 @@ export class Tx { getTxHash(): TxHash { // Private kernel functions are executed client side and for this reason tx hash is already set as first nullifier const firstNullifier = this.data?.endNonRevertibleData.newNullifiers[0]; - if (!firstNullifier || firstNullifier.isEmpty()) { + if (!firstNullifier || firstNullifier.isDefault()) { throw new Error(`Cannot get tx hash since first nullifier is missing`); } return new TxHash(firstNullifier.value.toBuffer()); diff --git a/yarn-project/circuit-types/src/tx_effect.ts b/yarn-project/circuit-types/src/tx_effect.ts index 5814843f147..90ea92e81df 100644 --- a/yarn-project/circuit-types/src/tx_effect.ts +++ b/yarn-project/circuit-types/src/tx_effect.ts @@ -53,7 +53,7 @@ export class TxEffect { const nonZeroNoteHashes = this.noteHashes.filter(h => !h.isZero()); const nonZeroNullifiers = this.nullifiers.filter(h => !h.isZero()); const nonZeroL2ToL1Msgs = this.l2ToL1Msgs.filter(h => !h.isZero()); - const nonZeroPublicDataWrites = this.publicDataWrites.filter(h => !h.isEmpty()); + const nonZeroPublicDataWrites = this.publicDataWrites.filter(h => !h.isDefault()); return Buffer.concat([ this.revertCode.toBuffer(), diff --git a/yarn-project/circuits.js/src/structs/call_context.test.ts b/yarn-project/circuits.js/src/structs/call_context.test.ts index 5dc6af77e5c..74b12ef6afe 100644 --- a/yarn-project/circuits.js/src/structs/call_context.test.ts +++ b/yarn-project/circuits.js/src/structs/call_context.test.ts @@ -15,7 +15,7 @@ describe('CallContext', () => { const buffer = callContext.toBuffer(); const res = CallContext.fromBuffer(buffer); expect(res).toEqual(callContext); - expect(res.isEmpty()).toBe(false); + expect(res.isDefault()).toBe(false); }); it('number of fields matches constant', () => { diff --git a/yarn-project/circuits.js/src/structs/call_context.ts b/yarn-project/circuits.js/src/structs/call_context.ts index 17438a431a7..c805a5a586b 100644 --- a/yarn-project/circuits.js/src/structs/call_context.ts +++ b/yarn-project/circuits.js/src/structs/call_context.ts @@ -48,7 +48,7 @@ export class CallContext { * Returns a new instance of CallContext with zero msg sender, storage contract address and portal contract address. * @returns A new instance of CallContext with zero msg sender, storage contract address and portal contract address. */ - public static empty(): CallContext { + public static default(): CallContext { return new CallContext( AztecAddress.ZERO, AztecAddress.ZERO, @@ -60,12 +60,12 @@ export class CallContext { ); } - isEmpty() { + isDefault() { return ( this.msgSender.isZero() && this.storageContractAddress.isZero() && this.portalContractAddress.isZero() && - this.functionSelector.isEmpty() && + this.functionSelector.isDefault() && Fr.ZERO ); } diff --git a/yarn-project/circuits.js/src/structs/call_request.ts b/yarn-project/circuits.js/src/structs/call_request.ts index 353cce504f4..3396ee12e7f 100644 --- a/yarn-project/circuits.js/src/structs/call_request.ts +++ b/yarn-project/circuits.js/src/structs/call_request.ts @@ -19,14 +19,14 @@ export class CallerContext { ) {} /** - * Returns a new instance of CallerContext with zero values. - * @returns A new instance of CallerContext with zero values. + * Returns a new instance of CallerContext with default values. + * @returns A new instance of CallerContext with default values. */ - public static empty(): CallerContext { + public static default(): CallerContext { return new CallerContext(AztecAddress.ZERO, AztecAddress.ZERO); } - isEmpty() { + isDefault() { return this.msgSender.isZero() && this.storageContractAddress.isZero(); } @@ -117,11 +117,11 @@ export class CallRequest { ); } - isEmpty() { + isDefault() { return ( this.hash.isZero() && this.callerContractAddress.isZero() && - this.callerContext.isEmpty() && + this.callerContext.isDefault() && this.startSideEffectCounter.isZero() && this.endSideEffectCounter.isZero() ); @@ -131,8 +131,8 @@ export class CallRequest { * Returns a new instance of CallRequest with zero hash, caller contract address and caller context. * @returns A new instance of CallRequest with zero hash, caller contract address and caller context. */ - public static empty() { - return new CallRequest(Fr.ZERO, AztecAddress.ZERO, CallerContext.empty(), Fr.ZERO, Fr.ZERO); + public static default() { + return new CallRequest(Fr.ZERO, AztecAddress.ZERO, CallerContext.default(), Fr.ZERO, Fr.ZERO); } equals(callRequest: CallRequest) { diff --git a/yarn-project/circuits.js/src/structs/content_commitment.ts b/yarn-project/circuits.js/src/structs/content_commitment.ts index e95bd6f9189..f42bc5f03cf 100644 --- a/yarn-project/circuits.js/src/structs/content_commitment.ts +++ b/yarn-project/circuits.js/src/structs/content_commitment.ts @@ -65,7 +65,7 @@ export class ContentCommitment { ); } - static empty(): ContentCommitment { + static default(): ContentCommitment { return new ContentCommitment( Fr.zero(), Buffer.alloc(NUM_BYTES_PER_SHA256), @@ -74,7 +74,7 @@ export class ContentCommitment { ); } - isEmpty(): boolean { + isDefault(): boolean { return ( this.txTreeHeight.isZero() && this.txsEffectsHash.equals(Buffer.alloc(NUM_BYTES_PER_SHA256)) && diff --git a/yarn-project/circuits.js/src/structs/contract_storage_read.ts b/yarn-project/circuits.js/src/structs/contract_storage_read.ts index 2c376a1d3f5..3a76a06bf89 100644 --- a/yarn-project/circuits.js/src/structs/contract_storage_read.ts +++ b/yarn-project/circuits.js/src/structs/contract_storage_read.ts @@ -52,11 +52,11 @@ export class ContractStorageRead { return new ContractStorageRead(Fr.fromBuffer(reader), Fr.fromBuffer(reader)); } - static empty() { + static default() { return new ContractStorageRead(Fr.ZERO, Fr.ZERO); } - isEmpty() { + isDefault() { return this.storageSlot.isZero() && this.currentValue.isZero(); } diff --git a/yarn-project/circuits.js/src/structs/contract_storage_update_request.ts b/yarn-project/circuits.js/src/structs/contract_storage_update_request.ts index 37f9a678717..b02619696ea 100644 --- a/yarn-project/circuits.js/src/structs/contract_storage_update_request.ts +++ b/yarn-project/circuits.js/src/structs/contract_storage_update_request.ts @@ -53,11 +53,11 @@ export class ContractStorageUpdateRequest { return [fields.storageSlot, fields.newValue, fields.sideEffectCounter] as const; } - static empty() { + static default() { return new ContractStorageUpdateRequest(Fr.ZERO, Fr.ZERO); } - isEmpty() { + isDefault() { return this.storageSlot.isZero() && this.newValue.isZero(); } diff --git a/yarn-project/circuits.js/src/structs/function_data.ts b/yarn-project/circuits.js/src/structs/function_data.ts index 08c803270b5..3294871f366 100644 --- a/yarn-project/circuits.js/src/structs/function_data.ts +++ b/yarn-project/circuits.js/src/structs/function_data.ts @@ -47,11 +47,11 @@ export class FunctionData { } /** - * Returns whether this instance is empty. + * Returns whether this instance is default. * @returns True if the function selector is zero. */ - isEmpty() { - return this.selector.isEmpty(); + isDefault() { + return this.selector.isDefault(); } /** @@ -59,11 +59,11 @@ export class FunctionData { * @param args - Arguments to pass to the constructor. * @returns A new instance of FunctionData with zero function selector. */ - public static empty(args?: { + public static default(args?: { /** Indicates whether the function is private or public. */ isPrivate?: boolean; }): FunctionData { - return new FunctionData(FunctionSelector.empty(), args?.isPrivate ?? false); + return new FunctionData(FunctionSelector.default(), args?.isPrivate ?? false); } /** diff --git a/yarn-project/circuits.js/src/structs/global_variables.ts b/yarn-project/circuits.js/src/structs/global_variables.ts index 05c90e8b0e3..41133e063bc 100644 --- a/yarn-project/circuits.js/src/structs/global_variables.ts +++ b/yarn-project/circuits.js/src/structs/global_variables.ts @@ -29,7 +29,7 @@ export class GlobalVariables { return new GlobalVariables(...GlobalVariables.getFields(fields)); } - static empty(): GlobalVariables { + static default(): GlobalVariables { return new GlobalVariables(Fr.ZERO, Fr.ZERO, Fr.ZERO, Fr.ZERO, EthAddress.ZERO, AztecAddress.ZERO); } @@ -106,7 +106,7 @@ export class GlobalVariables { }; } - isEmpty(): boolean { + isDefault(): boolean { return ( this.chainId.isZero() && this.version.isZero() && diff --git a/yarn-project/circuits.js/src/structs/header.ts b/yarn-project/circuits.js/src/structs/header.ts index 782486a1fb6..d070e5fdb6d 100644 --- a/yarn-project/circuits.js/src/structs/header.ts +++ b/yarn-project/circuits.js/src/structs/header.ts @@ -62,21 +62,21 @@ export class Header { return new Header(lastArchive, contentCommitment, state, globalVariables); } - static empty(): Header { + static default(): Header { return new Header( - AppendOnlyTreeSnapshot.zero(), - ContentCommitment.empty(), - StateReference.empty(), - GlobalVariables.empty(), + AppendOnlyTreeSnapshot.default(), + ContentCommitment.default(), + StateReference.default(), + GlobalVariables.default(), ); } - isEmpty(): boolean { + isDefault(): boolean { return ( - this.lastArchive.isZero() && - this.contentCommitment.isEmpty() && - this.state.isEmpty() && - this.globalVariables.isEmpty() + this.lastArchive.isDefault() && + this.contentCommitment.isDefault() && + this.state.isDefault() && + this.globalVariables.isDefault() ); } diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts index 326e410a257..07095ad1408 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts @@ -134,19 +134,19 @@ export class CombinedAccumulatedData { return CombinedAccumulatedData.fromBuffer(Buffer.from(str, 'hex')); } - static empty() { + static default() { return new CombinedAccumulatedData( RevertCode.OK, - makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.empty), - makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.empty), - makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, CallRequest.empty), - makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.empty), + makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.default), + makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), + makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, CallRequest.default), + makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default), makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), Fr.zero(), Fr.zero(), Fr.zero(), Fr.zero(), - makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.empty), + makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.default), ); } @@ -160,33 +160,33 @@ export class CombinedAccumulatedData { nonRevertible: PublicAccumulatedNonRevertibleData, revertible: PublicAccumulatedRevertibleData, ): CombinedAccumulatedData { - if (!nonRevertible.revertCode.isOK() && !revertible.isEmpty()) { + if (!nonRevertible.revertCode.isOK() && !revertible.isDefault()) { log(inspect(revertible)); throw new Error('Revertible data should be empty if the transaction is revertCode'); } const newNoteHashes = padArrayEnd( - [...nonRevertible.newNoteHashes, ...revertible.newNoteHashes].filter(x => !x.isEmpty()).sort(sideEffectCmp), - SideEffect.empty(), + [...nonRevertible.newNoteHashes, ...revertible.newNoteHashes].filter(x => !x.isDefault()).sort(sideEffectCmp), + SideEffect.default(), MAX_NEW_NOTE_HASHES_PER_TX, ); const newNullifiers = padArrayEnd( - [...nonRevertible.newNullifiers, ...revertible.newNullifiers].filter(x => !x.isEmpty()).sort(sideEffectCmp), - SideEffectLinkedToNoteHash.empty(), + [...nonRevertible.newNullifiers, ...revertible.newNullifiers].filter(x => !x.isDefault()).sort(sideEffectCmp), + SideEffectLinkedToNoteHash.default(), MAX_NEW_NULLIFIERS_PER_TX, ); const publicCallStack = padArrayEnd( - [...nonRevertible.publicCallStack, ...revertible.publicCallStack].filter(x => !x.isEmpty()), - CallRequest.empty(), + [...nonRevertible.publicCallStack, ...revertible.publicCallStack].filter(x => !x.isDefault()), + CallRequest.default(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, ); const nonSquashedWrites = [ ...revertible.publicDataUpdateRequests, ...nonRevertible.publicDataUpdateRequests, - ].filter(x => !x.isEmpty()); + ].filter(x => !x.isDefault()); const squashedWrites = Array.from( nonSquashedWrites @@ -199,7 +199,7 @@ export class CombinedAccumulatedData { const publicDataUpdateRequests = padArrayEnd( squashedWrites, - PublicDataUpdateRequest.empty(), + PublicDataUpdateRequest.default(), MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, ); @@ -287,18 +287,18 @@ export class PublicAccumulatedRevertibleData { return this.toBuffer().toString('hex'); } - isEmpty(): boolean { + isDefault(): boolean { return ( - this.newNoteHashes.every(x => x.isEmpty()) && - this.newNullifiers.every(x => x.isEmpty()) && - this.privateCallStack.every(x => x.isEmpty()) && - this.publicCallStack.every(x => x.isEmpty()) && + this.newNoteHashes.every(x => x.isDefault()) && + this.newNullifiers.every(x => x.isDefault()) && + this.privateCallStack.every(x => x.isDefault()) && + this.publicCallStack.every(x => x.isDefault()) && this.newL2ToL1Msgs.every(x => x.isZero()) && this.encryptedLogsHash.isZero() && this.unencryptedLogsHash.isZero() && this.encryptedLogPreimagesLength.isZero() && this.unencryptedLogPreimagesLength.isZero() && - this.publicDataUpdateRequests.every(x => x.isEmpty()) + this.publicDataUpdateRequests.every(x => x.isDefault()) ); } @@ -341,16 +341,16 @@ export class PublicAccumulatedRevertibleData { static fromPrivateAccumulatedRevertibleData(finalData: PrivateAccumulatedRevertibleData) { return new this( - padArrayEnd(finalData.newNoteHashes, SideEffect.empty(), MAX_REVERTIBLE_NOTE_HASHES_PER_TX), - padArrayEnd(finalData.newNullifiers, SideEffectLinkedToNoteHash.empty(), MAX_REVERTIBLE_NULLIFIERS_PER_TX), + padArrayEnd(finalData.newNoteHashes, SideEffect.default(), MAX_REVERTIBLE_NOTE_HASHES_PER_TX), + padArrayEnd(finalData.newNullifiers, SideEffectLinkedToNoteHash.default(), MAX_REVERTIBLE_NULLIFIERS_PER_TX), finalData.privateCallStack, - padArrayEnd(finalData.publicCallStack, CallRequest.empty(), MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX), + padArrayEnd(finalData.publicCallStack, CallRequest.default(), MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX), finalData.newL2ToL1Msgs, finalData.encryptedLogsHash, finalData.unencryptedLogsHash, finalData.encryptedLogPreimagesLength, finalData.unencryptedLogPreimagesLength, - makeTuple(MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.empty), + makeTuple(MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.default), ); } @@ -363,18 +363,18 @@ export class PublicAccumulatedRevertibleData { return this.fromBuffer(Buffer.from(str, 'hex')); } - static empty() { + static default() { return new this( - makeTuple(MAX_REVERTIBLE_NOTE_HASHES_PER_TX, SideEffect.empty), - makeTuple(MAX_REVERTIBLE_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.empty), - makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, CallRequest.empty), - makeTuple(MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.empty), + makeTuple(MAX_REVERTIBLE_NOTE_HASHES_PER_TX, SideEffect.default), + makeTuple(MAX_REVERTIBLE_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), + makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, CallRequest.default), + makeTuple(MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default), makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), Fr.zero(), Fr.zero(), Fr.zero(), Fr.zero(), - makeTuple(MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.empty), + makeTuple(MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.default), ); } } @@ -473,12 +473,12 @@ export class PrivateAccumulatedRevertibleData { return PrivateAccumulatedRevertibleData.fromBuffer(Buffer.from(str, 'hex')); } - static empty() { + static default() { return new PrivateAccumulatedRevertibleData( - makeTuple(MAX_REVERTIBLE_NOTE_HASHES_PER_TX, SideEffect.empty), - makeTuple(MAX_REVERTIBLE_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.empty), - makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, CallRequest.empty), - makeTuple(MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.empty), + makeTuple(MAX_REVERTIBLE_NOTE_HASHES_PER_TX, SideEffect.default), + makeTuple(MAX_REVERTIBLE_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), + makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, CallRequest.default), + makeTuple(MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default), makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), Fr.zero(), Fr.zero(), @@ -530,12 +530,12 @@ export class PrivateAccumulatedNonRevertibleData { return PrivateAccumulatedNonRevertibleData.fromBuffer(Buffer.from(str, 'hex')); } - static empty() { + static default() { return new PrivateAccumulatedNonRevertibleData( RevertCode.OK, - makeTuple(MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX, SideEffect.empty), - makeTuple(MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.empty), - makeTuple(MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.empty), + makeTuple(MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX, SideEffect.default), + makeTuple(MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), + makeTuple(MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default), ); } } @@ -596,13 +596,13 @@ export class PublicAccumulatedNonRevertibleData { return this.fromBuffer(Buffer.from(str, 'hex')); } - static empty() { + static default() { return new this( RevertCode.OK, - makeTuple(MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX, SideEffect.empty), - makeTuple(MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.empty), - makeTuple(MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.empty), - makeTuple(MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.empty), + makeTuple(MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX, SideEffect.default), + makeTuple(MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), + makeTuple(MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default), + makeTuple(MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.default), ); } @@ -612,7 +612,7 @@ export class PublicAccumulatedNonRevertibleData { data.newNoteHashes, data.newNullifiers, data.publicCallStack, - makeTuple(MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.empty), + makeTuple(MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.default), ); } diff --git a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts index ef4bb082386..9d556494131 100644 --- a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts +++ b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts @@ -11,7 +11,7 @@ export class L2ToL1Message { * Creates an empty L2ToL1Message with default values. * @returns An instance of L2ToL1Message with empty fields. */ - static empty(): L2ToL1Message { + static default(): L2ToL1Message { return new L2ToL1Message(EthAddress.ZERO, Fr.zero()); } @@ -70,7 +70,7 @@ export class L2ToL1Message { * Convenience method to check if the message is empty. * @returns True if both recipient and content are zero. */ - isEmpty(): boolean { + isDefault(): boolean { return this.recipient.isZero() && this.content.isZero(); } } diff --git a/yarn-project/circuits.js/src/structs/max_block_number.ts b/yarn-project/circuits.js/src/structs/max_block_number.ts index cc124de2e26..a8e110a694f 100644 --- a/yarn-project/circuits.js/src/structs/max_block_number.ts +++ b/yarn-project/circuits.js/src/structs/max_block_number.ts @@ -52,11 +52,11 @@ export class MaxBlockNumber { return new MaxBlockNumber(reader.readBoolean(), reader.readField()); } - static empty() { + static default() { return new MaxBlockNumber(false, Fr.ZERO); } - isEmpty(): boolean { + isDefault(): boolean { return !this.isSome && this.value.isZero(); } diff --git a/yarn-project/circuits.js/src/structs/note_hash_read_request_membership_witness.ts b/yarn-project/circuits.js/src/structs/note_hash_read_request_membership_witness.ts index d9bb37c0c09..d4b80f2fd21 100644 --- a/yarn-project/circuits.js/src/structs/note_hash_read_request_membership_witness.ts +++ b/yarn-project/circuits.js/src/structs/note_hash_read_request_membership_witness.ts @@ -75,7 +75,7 @@ export class NoteHashReadRequestMembershipWitness { * @param leafIndex - Index of the leaf in the Merkle tree. * @returns Membership witness with zero sibling path. */ - public static empty(leafIndex: bigint): NoteHashReadRequestMembershipWitness { + public static default(leafIndex: bigint): NoteHashReadRequestMembershipWitness { const arr = makeTuple(NOTE_HASH_TREE_HEIGHT, () => Fr.ZERO); return new NoteHashReadRequestMembershipWitness(new Fr(leafIndex), arr, false, new Fr(0)); } diff --git a/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts b/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts index 37f2a6ad9ea..66816f4147a 100644 --- a/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts +++ b/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts @@ -47,11 +47,11 @@ export class NullifierKeyValidationRequest { return new NullifierKeyValidationRequest(Point.fromFields(reader), reader.readFq()); } - isEmpty() { + isDefault() { return this.publicKey.isZero() && this.secretKey.isZero(); } - static empty() { + static default() { return new NullifierKeyValidationRequest(Point.ZERO, GrumpkinScalar.ZERO); } } @@ -107,11 +107,11 @@ export class NullifierKeyValidationRequestContext { ); } - isEmpty() { + isDefault() { return this.publicKey.isZero() && this.secretKey.isZero() && this.contractAddress.isZero(); } - static empty() { + static default() { return new NullifierKeyValidationRequestContext(Point.ZERO, GrumpkinScalar.ZERO, AztecAddress.ZERO); } } diff --git a/yarn-project/circuits.js/src/structs/partial_state_reference.ts b/yarn-project/circuits.js/src/structs/partial_state_reference.ts index 0ca6b790f38..d0812a7347d 100644 --- a/yarn-project/circuits.js/src/structs/partial_state_reference.ts +++ b/yarn-project/circuits.js/src/structs/partial_state_reference.ts @@ -36,11 +36,11 @@ export class PartialStateReference { return new PartialStateReference(noteHashTree, nullifierTree, publicDataTree); } - static empty(): PartialStateReference { + static default(): PartialStateReference { return new PartialStateReference( - AppendOnlyTreeSnapshot.zero(), - AppendOnlyTreeSnapshot.zero(), - AppendOnlyTreeSnapshot.zero(), + AppendOnlyTreeSnapshot.default(), + AppendOnlyTreeSnapshot.default(), + AppendOnlyTreeSnapshot.default(), ); } @@ -62,7 +62,7 @@ export class PartialStateReference { return fields; } - isEmpty(): boolean { - return this.noteHashTree.isZero() && this.nullifierTree.isZero() && this.publicDataTree.isZero(); + isDefault(): boolean { + return this.noteHashTree.isDefault() && this.nullifierTree.isDefault() && this.publicDataTree.isDefault(); } } diff --git a/yarn-project/circuits.js/src/structs/private_call_stack_item.ts b/yarn-project/circuits.js/src/structs/private_call_stack_item.ts index 700cd968d17..7bf8e270731 100644 --- a/yarn-project/circuits.js/src/structs/private_call_stack_item.ts +++ b/yarn-project/circuits.js/src/structs/private_call_stack_item.ts @@ -77,13 +77,13 @@ export class PrivateCallStackItem { public static empty(): PrivateCallStackItem { return new PrivateCallStackItem( AztecAddress.ZERO, - FunctionData.empty({ isPrivate: true }), + FunctionData.default({ isPrivate: true }), PrivateCircuitPublicInputs.empty(), ); } - isEmpty() { - return this.contractAddress.isZero() && this.functionData.isEmpty() && this.publicInputs.isEmpty(); + isDefault() { + return this.contractAddress.isZero() && this.functionData.isDefault() && this.publicInputs.isDefault(); } /** @@ -99,14 +99,14 @@ export class PrivateCallStackItem { * @returns A CallRequest instance with the contract address, caller context, and the hash of the call stack item. */ public toCallRequest(parentCallContext: CallContext) { - if (this.isEmpty()) { - return CallRequest.empty(); + if (this.isDefault()) { + return CallRequest.default(); } const currentCallContext = this.publicInputs.callContext; const callerContext = currentCallContext.isDelegateCall ? new CallerContext(parentCallContext.msgSender, parentCallContext.storageContractAddress) - : CallerContext.empty(); + : CallerContext.default(); return new CallRequest( this.hash(), parentCallContext.storageContractAddress, diff --git a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts index 67e9347eba0..fc43bd610ec 100644 --- a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts @@ -209,55 +209,55 @@ export class PrivateCircuitPublicInputs { */ public static empty(): PrivateCircuitPublicInputs { return new PrivateCircuitPublicInputs( - CallContext.empty(), + CallContext.default(), Fr.ZERO, makeTuple(RETURN_VALUES_LENGTH, Fr.zero), Fr.ZERO, - MaxBlockNumber.empty(), - makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, SideEffect.empty), - makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, ReadRequest.empty), - makeTuple(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, NullifierKeyValidationRequest.empty), - makeTuple(MAX_NEW_NOTE_HASHES_PER_CALL, SideEffect.empty), - makeTuple(MAX_NEW_NULLIFIERS_PER_CALL, SideEffectLinkedToNoteHash.empty), + MaxBlockNumber.default(), + makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, SideEffect.default), + makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, ReadRequest.default), + makeTuple(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, NullifierKeyValidationRequest.default), + makeTuple(MAX_NEW_NOTE_HASHES_PER_CALL, SideEffect.default), + makeTuple(MAX_NEW_NULLIFIERS_PER_CALL, SideEffectLinkedToNoteHash.default), makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, Fr.zero), makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, Fr.zero), - makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, L2ToL1Message.empty), + makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, L2ToL1Message.default), Fr.ZERO, Fr.ZERO, Fr.ZERO, Fr.ZERO, Fr.ZERO, Fr.ZERO, - Header.empty(), + Header.default(), Fr.ZERO, Fr.ZERO, ); } - isEmpty() { + isDefault() { // eslint-disable-next-line jsdoc/require-jsdoc - const isEmptyArray = (arr: { isEmpty: (...args: any[]) => boolean }[]) => isArrayEmpty(arr, item => item.isEmpty()); + const isDefaultArray = (arr: { isDefault: (...args: any[]) => boolean }[]) => isArrayEmpty(arr, item => item.isDefault()); // eslint-disable-next-line jsdoc/require-jsdoc const isZeroArray = (arr: { isZero: (...args: any[]) => boolean }[]) => isArrayEmpty(arr, item => item.isZero()); return ( - this.callContext.isEmpty() && + this.callContext.isDefault() && this.argsHash.isZero() && isZeroArray(this.returnValues) && this.minRevertibleSideEffectCounter.isZero() && - this.maxBlockNumber.isEmpty() && - isEmptyArray(this.noteHashReadRequests) && - isEmptyArray(this.nullifierReadRequests) && - isEmptyArray(this.nullifierKeyValidationRequests) && - isEmptyArray(this.newNoteHashes) && - isEmptyArray(this.newNullifiers) && + this.maxBlockNumber.isDefault() && + isDefaultArray(this.noteHashReadRequests) && + isDefaultArray(this.nullifierReadRequests) && + isDefaultArray(this.nullifierKeyValidationRequests) && + isDefaultArray(this.newNoteHashes) && + isDefaultArray(this.newNullifiers) && isZeroArray(this.privateCallStackHashes) && isZeroArray(this.publicCallStackHashes) && - isEmptyArray(this.newL2ToL1Msgs) && + isDefaultArray(this.newL2ToL1Msgs) && this.encryptedLogsHash.isZero() && this.unencryptedLogsHash.isZero() && this.encryptedLogPreimagesLength.isZero() && this.unencryptedLogPreimagesLength.isZero() && - this.historicalHeader.isEmpty() && + this.historicalHeader.isDefault() && this.chainId.isZero() && this.version.isZero() ); diff --git a/yarn-project/circuits.js/src/structs/public_call_stack_item.ts b/yarn-project/circuits.js/src/structs/public_call_stack_item.ts index 454b695de62..234034c4796 100644 --- a/yarn-project/circuits.js/src/structs/public_call_stack_item.ts +++ b/yarn-project/circuits.js/src/structs/public_call_stack_item.ts @@ -68,20 +68,20 @@ export class PublicCallStackItem { } /** - * Returns a new instance of PublicCallStackItem with zero contract address, function data and public inputs. - * @returns A new instance of PublicCallStackItem with zero contract address, function data and public inputs. + * Returns a new instance of PublicCallStackItem with default contract address, function data and public inputs. + * @returns A new instance of PublicCallStackItem with default contract address, function data and public inputs. */ - public static empty(): PublicCallStackItem { + public static default(): PublicCallStackItem { return new PublicCallStackItem( AztecAddress.ZERO, - FunctionData.empty({ isPrivate: false }), - PublicCircuitPublicInputs.empty(), + FunctionData.default({ isPrivate: false }), + PublicCircuitPublicInputs.default(), false, ); } - isEmpty() { - return this.contractAddress.isZero() && this.functionData.isEmpty() && this.publicInputs.isEmpty(); + isDefault() { + return this.contractAddress.isZero() && this.functionData.isDefault() && this.publicInputs.isDefault(); } /** @@ -107,14 +107,14 @@ export class PublicCallStackItem { * @returns A CallRequest instance with the contract address, caller context, and the hash of the call stack item. */ public toCallRequest(parentCallContext: CallContext) { - if (this.isEmpty()) { - return CallRequest.empty(); + if (this.isDefault()) { + return CallRequest.default(); } const currentCallContext = this.publicInputs.callContext; const callerContext = currentCallContext.isDelegateCall ? new CallerContext(parentCallContext.msgSender, parentCallContext.storageContractAddress) - : CallerContext.empty(); + : CallerContext.default(); // todo: populate side effect counters correctly return new CallRequest(this.hash(), parentCallContext.storageContractAddress, callerContext, Fr.ZERO, Fr.ZERO); } diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts index 8ba49eb659a..d74a103cc30 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts @@ -126,54 +126,54 @@ export class PublicCircuitPublicInputs { } /** - * Returns an empty instance. - * @returns An empty instance. + * Returns an default instance. + * @returns An default instance. */ - public static empty() { + public static default() { return new PublicCircuitPublicInputs( - CallContext.empty(), + CallContext.default(), Fr.ZERO, makeTuple(RETURN_VALUES_LENGTH, Fr.zero), - makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, ReadRequest.empty), - makeTuple(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, ReadRequest.empty), - makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, ContractStorageUpdateRequest.empty), - makeTuple(MAX_PUBLIC_DATA_READS_PER_CALL, ContractStorageRead.empty), + makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, ReadRequest.default), + makeTuple(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, ReadRequest.default), + makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, ContractStorageUpdateRequest.default), + makeTuple(MAX_PUBLIC_DATA_READS_PER_CALL, ContractStorageRead.default), makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, Fr.zero), - makeTuple(MAX_NEW_NOTE_HASHES_PER_CALL, SideEffect.empty), - makeTuple(MAX_NEW_NULLIFIERS_PER_CALL, SideEffectLinkedToNoteHash.empty), - makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, L2ToL1Message.empty), + makeTuple(MAX_NEW_NOTE_HASHES_PER_CALL, SideEffect.default), + makeTuple(MAX_NEW_NULLIFIERS_PER_CALL, SideEffectLinkedToNoteHash.default), + makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, L2ToL1Message.default), Fr.ZERO, Fr.ZERO, Fr.ZERO, Fr.ZERO, - Header.empty(), + Header.default(), AztecAddress.ZERO, RevertCode.OK, ); } - isEmpty() { - const isSideEffectArrayEmpty = (arr: SideEffect[]) => isArrayEmpty(arr, item => item.isEmpty()); - const isSideEffectLinkedArrayEmpty = (arr: SideEffectLinkedToNoteHash[]) => - isArrayEmpty(arr, item => item.isEmpty()); - const isFrArrayEmpty = (arr: Fr[]) => isArrayEmpty(arr, item => item.isZero()); + isDefault() { + const isSideEffectArrayDefault = (arr: SideEffect[]) => isArrayEmpty(arr, item => item.isDefault()); + const isSideEffectLinkedArrayDefault = (arr: SideEffectLinkedToNoteHash[]) => + isArrayEmpty(arr, item => item.isDefault()); + const isFrArrayZero = (arr: Fr[]) => isArrayEmpty(arr, item => item.isZero()); return ( - this.callContext.isEmpty() && + this.callContext.isDefault() && this.argsHash.isZero() && - isFrArrayEmpty(this.returnValues) && - isArrayEmpty(this.nullifierReadRequests, item => item.isEmpty()) && - isArrayEmpty(this.nullifierNonExistentReadRequests, item => item.isEmpty()) && - isArrayEmpty(this.contractStorageUpdateRequests, item => item.isEmpty()) && - isArrayEmpty(this.contractStorageReads, item => item.isEmpty()) && - isFrArrayEmpty(this.publicCallStackHashes) && - isSideEffectArrayEmpty(this.newNoteHashes) && - isSideEffectLinkedArrayEmpty(this.newNullifiers) && - isArrayEmpty(this.newL2ToL1Msgs, item => item.isEmpty()) && + isFrArrayZero(this.returnValues) && + isArrayEmpty(this.nullifierReadRequests, item => item.isDefault()) && + isArrayEmpty(this.nullifierNonExistentReadRequests, item => item.isDefault()) && + isArrayEmpty(this.contractStorageUpdateRequests, item => item.isDefault()) && + isArrayEmpty(this.contractStorageReads, item => item.isDefault()) && + isFrArrayZero(this.publicCallStackHashes) && + isSideEffectArrayDefault(this.newNoteHashes) && + isSideEffectLinkedArrayDefault(this.newNullifiers) && + isArrayEmpty(this.newL2ToL1Msgs, item => item.isDefault()) && this.startSideEffectCounter.isZero() && this.endSideEffectCounter.isZero() && this.unencryptedLogsHash.isZero() && this.unencryptedLogPreimagesLength.isZero() && - this.historicalHeader.isEmpty() && + this.historicalHeader.isDefault() && this.proverAddress.isZero() && this.revertCode.isOK() ); diff --git a/yarn-project/circuits.js/src/structs/public_data_read_request.ts b/yarn-project/circuits.js/src/structs/public_data_read_request.ts index 70f7d2af2ff..64ecfb05072 100644 --- a/yarn-project/circuits.js/src/structs/public_data_read_request.ts +++ b/yarn-project/circuits.js/src/structs/public_data_read_request.ts @@ -38,7 +38,7 @@ export class PublicDataRead { return serializeToBuffer(this.leafSlot, this.value); } - isEmpty() { + isDefault() { return this.leafSlot.isZero() && this.value.isZero(); } @@ -47,7 +47,7 @@ export class PublicDataRead { return new PublicDataRead(Fr.fromBuffer(reader), Fr.fromBuffer(reader)); } - static empty() { + static default() { return new PublicDataRead(Fr.ZERO, Fr.ZERO); } diff --git a/yarn-project/circuits.js/src/structs/public_data_update_request.ts b/yarn-project/circuits.js/src/structs/public_data_update_request.ts index 981e4d13053..a4513e3f46f 100644 --- a/yarn-project/circuits.js/src/structs/public_data_update_request.ts +++ b/yarn-project/circuits.js/src/structs/public_data_update_request.ts @@ -37,12 +37,12 @@ export class PublicDataUpdateRequest { return serializeToBuffer(this.leafSlot, this.newValue); } - isEmpty() { + isDefault() { return this.leafSlot.isZero() && this.newValue.isZero(); } - static isEmpty(x: PublicDataUpdateRequest) { - return x.isEmpty(); + static isDefault(x: PublicDataUpdateRequest) { + return x.isDefault(); } equals(other: PublicDataUpdateRequest) { @@ -54,7 +54,7 @@ export class PublicDataUpdateRequest { return new PublicDataUpdateRequest(Fr.fromBuffer(reader), Fr.fromBuffer(reader)); } - static empty() { + static default() { return new PublicDataUpdateRequest(Fr.ZERO, Fr.ZERO); } diff --git a/yarn-project/circuits.js/src/structs/read_request.ts b/yarn-project/circuits.js/src/structs/read_request.ts index 1f47f967c6d..6caf707837e 100644 --- a/yarn-project/circuits.js/src/structs/read_request.ts +++ b/yarn-project/circuits.js/src/structs/read_request.ts @@ -46,18 +46,18 @@ export class ReadRequest { } /** - * Returns whether this instance of side-effect is empty. + * Returns whether this instance of side-effect is default. * @returns True if the value and counter both are zero. */ - isEmpty() { + isDefault() { return this.value.isZero() && !this.counter; } /** - * Returns an empty instance of side-effect. + * Returns a default instance of side-effect. * @returns Side-effect with both value and counter being zero. */ - static empty(): ReadRequest { + static default(): ReadRequest { return new ReadRequest(Fr.zero(), 0); } } @@ -113,18 +113,18 @@ export class ReadRequestContext { } /** - * Returns whether this instance of side-effect is empty. + * Returns whether this instance of side-effect is default. * @returns True if the value, note hash and counter are all zero. */ - isEmpty() { + isDefault() { return this.value.isZero() && !this.counter && this.contractAddress.isZero(); } /** - * Returns an empty instance of side-effect. + * Returns a default instance of side-effect. * @returns Side-effect with value, note hash and counter being zero. */ - static empty(): ReadRequestContext { + static default(): ReadRequestContext { return new ReadRequestContext(Fr.zero(), 0, AztecAddress.ZERO); } } diff --git a/yarn-project/circuits.js/src/structs/rollup/append_only_tree_snapshot.ts b/yarn-project/circuits.js/src/structs/rollup/append_only_tree_snapshot.ts index 6f39790a162..48589db9508 100644 --- a/yarn-project/circuits.js/src/structs/rollup/append_only_tree_snapshot.ts +++ b/yarn-project/circuits.js/src/structs/rollup/append_only_tree_snapshot.ts @@ -53,11 +53,11 @@ export class AppendOnlyTreeSnapshot { return new AppendOnlyTreeSnapshot(reader.readField(), Number(reader.readField().toBigInt())); } - static zero() { + static default() { return new AppendOnlyTreeSnapshot(Fr.ZERO, 0); } - isZero(): boolean { + isDefault(): boolean { return this.root.isZero() && this.nextAvailableLeafIndex === 0; } } diff --git a/yarn-project/circuits.js/src/structs/rollup/nullifier_leaf/index.ts b/yarn-project/circuits.js/src/structs/rollup/nullifier_leaf/index.ts index 149ab6c0014..bc29d3be085 100644 --- a/yarn-project/circuits.js/src/structs/rollup/nullifier_leaf/index.ts +++ b/yarn-project/circuits.js/src/structs/rollup/nullifier_leaf/index.ts @@ -67,7 +67,7 @@ export class NullifierLeafPreimage implements IndexedTreeLeafPreimage { }; } - static empty(): NullifierLeafPreimage { + static default(): NullifierLeafPreimage { return new NullifierLeafPreimage(Fr.ZERO, Fr.ZERO, 0n); } @@ -112,7 +112,7 @@ export class NullifierLeaf implements IndexedTreeLeaf { return this.nullifier.toBuffer(); } - isEmpty(): boolean { + isDefault(): boolean { return this.nullifier.isZero(); } diff --git a/yarn-project/circuits.js/src/structs/rollup/public_data_leaf/index.ts b/yarn-project/circuits.js/src/structs/rollup/public_data_leaf/index.ts index 5724f220e02..a551904230c 100644 --- a/yarn-project/circuits.js/src/structs/rollup/public_data_leaf/index.ts +++ b/yarn-project/circuits.js/src/structs/rollup/public_data_leaf/index.ts @@ -60,7 +60,7 @@ export class PublicDataTreeLeafPreimage implements IndexedTreeLeafPreimage { return new PublicDataTreeLeafPreimage(this.slot, this.value, this.nextSlot, this.nextIndex); } - static empty(): PublicDataTreeLeafPreimage { + static default(): PublicDataTreeLeafPreimage { return new PublicDataTreeLeafPreimage(Fr.ZERO, Fr.ZERO, Fr.ZERO, 0n); } @@ -118,7 +118,7 @@ export class PublicDataTreeLeaf implements IndexedTreeLeaf { return `PublicDataTreeLeaf(${this.slot.toString()}, ${this.value.toString()})`; } - isEmpty(): boolean { + isDefault(): boolean { return this.slot.isZero() && this.value.isZero(); } @@ -133,7 +133,7 @@ export class PublicDataTreeLeaf implements IndexedTreeLeaf { return new PublicDataTreeLeaf(new Fr(key), new Fr(0)); } - static empty(): PublicDataTreeLeaf { + static default(): PublicDataTreeLeaf { return new PublicDataTreeLeaf(Fr.ZERO, Fr.ZERO); } } diff --git a/yarn-project/circuits.js/src/structs/side_effects.ts b/yarn-project/circuits.js/src/structs/side_effects.ts index e91c0bb3356..33f7091d7d7 100644 --- a/yarn-project/circuits.js/src/structs/side_effects.ts +++ b/yarn-project/circuits.js/src/structs/side_effects.ts @@ -14,7 +14,7 @@ export interface SideEffectType { /** Convert to a field array */ toFields(): Fr[]; /** Are all of the fields of the SideEffect zero? */ - isEmpty(): boolean; + isDefault(): boolean; } /** @@ -59,18 +59,18 @@ export class SideEffect implements SideEffectType { } /** - * Returns whether this instance of side-effect is empty. + * Returns whether this instance of side-effect is default. * @returns True if the value and counter both are zero. */ - isEmpty() { - return SideEffect.isEmpty(this); + isDefault() { + return SideEffect.isDefault(this); } /** - * Checks whether this instance of side-effect is empty. + * Checks whether a supplied side-effect is default. * @returns True if the value and counter both are zero. */ - static isEmpty(sideEffect: SideEffect) { + static isDefault(sideEffect: SideEffect) { return sideEffect.value.isZero() && sideEffect.counter.isZero(); } @@ -78,7 +78,7 @@ export class SideEffect implements SideEffectType { * Returns an empty instance of side-effect. * @returns Side-effect with both value and counter being zero. */ - static empty(): SideEffect { + static default(): SideEffect { return new SideEffect(Fr.zero(), Fr.zero()); } @@ -139,26 +139,26 @@ export class SideEffectLinkedToNoteHash implements SideEffectType { } /** - * Returns whether this instance of side-effect is empty. + * Returns whether this instance of side-effect is default. * @returns True if the value, note hash and counter are all zero. */ - isEmpty() { - return SideEffectLinkedToNoteHash.isEmpty(this); + isDefault() { + return SideEffectLinkedToNoteHash.isDefault(this); } /** - * Returns whether this instance of side-effect is empty. + * Returns whether a supplied side-effect is default. * @returns True if the value, note hash and counter are all zero. */ - static isEmpty(sideEffect: SideEffectLinkedToNoteHash) { + static isDefault(sideEffect: SideEffectLinkedToNoteHash) { return sideEffect.value.isZero() && sideEffect.noteHash.isZero() && sideEffect.counter.isZero(); } /** - * Returns an empty instance of side-effect. + * Returns an default instance of side-effect. * @returns Side-effect with value, note hash and counter being zero. */ - static empty(): SideEffectLinkedToNoteHash { + static default(): SideEffectLinkedToNoteHash { return new SideEffectLinkedToNoteHash(Fr.zero(), Fr.zero(), Fr.zero()); } @@ -174,12 +174,12 @@ export class SideEffectLinkedToNoteHash implements SideEffectType { } /** - * Convert an array of side effects to an array only non-empty side effects. + * Convert an array of side effects to an array only non-default side effects. * @param sideEffects - array to be converted - * @returns the array of the non-empty side effects + * @returns the array of the non-default side effects */ -export function nonEmptySideEffects(sideEffects: SideEffectType[]): SideEffectType[] { - return sideEffects.filter!(sideEffect => !sideEffect.isEmpty()); +export function nonDefaultSideEffects(sideEffects: SideEffectType[]): SideEffectType[] { + return sideEffects.filter(sideEffect => !sideEffect.isDefault()); } /** diff --git a/yarn-project/circuits.js/src/structs/state_reference.ts b/yarn-project/circuits.js/src/structs/state_reference.ts index 8d05ec2b974..82825864925 100644 --- a/yarn-project/circuits.js/src/structs/state_reference.ts +++ b/yarn-project/circuits.js/src/structs/state_reference.ts @@ -45,11 +45,11 @@ export class StateReference { return new StateReference(l1ToL2MessageTree, partial); } - static empty(): StateReference { - return new StateReference(AppendOnlyTreeSnapshot.zero(), PartialStateReference.empty()); + static default(): StateReference { + return new StateReference(AppendOnlyTreeSnapshot.default(), PartialStateReference.default()); } - isEmpty(): boolean { - return this.l1ToL2MessageTree.isZero() && this.partial.isEmpty(); + isDefault(): boolean { + return this.l1ToL2MessageTree.isDefault() && this.partial.isDefault(); } } diff --git a/yarn-project/circuits.js/src/structs/tx_context.ts b/yarn-project/circuits.js/src/structs/tx_context.ts index 0eae14c831d..fc78a5351f7 100644 --- a/yarn-project/circuits.js/src/structs/tx_context.ts +++ b/yarn-project/circuits.js/src/structs/tx_context.ts @@ -63,11 +63,11 @@ export class TxContext { return new TxContext(reader.readBoolean(), reader.readBoolean(), Fr.fromBuffer(reader), Fr.fromBuffer(reader)); } - static empty(chainId: Fr | number = 0, version: Fr | number = 0) { + static default(chainId: Fr | number = 0, version: Fr | number = 0) { return new TxContext(false, false, new Fr(chainId), new Fr(version)); } - isEmpty(): boolean { + isDefault(): boolean { return !this.isFeePaymentTx && !this.isRebatePaymentTx && this.chainId.isZero() && this.version.isZero(); } diff --git a/yarn-project/circuits.js/src/structs/tx_request.ts b/yarn-project/circuits.js/src/structs/tx_request.ts index 6113bbb279a..819e60669ac 100644 --- a/yarn-project/circuits.js/src/structs/tx_request.ts +++ b/yarn-project/circuits.js/src/structs/tx_request.ts @@ -74,11 +74,11 @@ export class TxRequest { return pedersenHash(this.toFields(), GeneratorIndex.TX_REQUEST); } - static empty() { - return new TxRequest(AztecAddress.ZERO, FunctionData.empty(), Fr.zero(), TxContext.empty()); + static default() { + return new TxRequest(AztecAddress.ZERO, FunctionData.default(), Fr.zero(), TxContext.default()); } - isEmpty() { - return this.origin.isZero() && this.functionData.isEmpty() && this.argsHash.isZero() && this.txContext.isEmpty(); + isDefault() { + return this.origin.isZero() && this.functionData.isDefault() && this.argsHash.isZero() && this.txContext.isDefault(); } } diff --git a/yarn-project/foundation/src/abi/function_selector.test.ts b/yarn-project/foundation/src/abi/function_selector.test.ts index 6cb6155e922..961e93a6c7c 100644 --- a/yarn-project/foundation/src/abi/function_selector.test.ts +++ b/yarn-project/foundation/src/abi/function_selector.test.ts @@ -13,7 +13,7 @@ describe('FunctionSelector', () => { const buffer = selector.toBuffer(); const res = FunctionSelector.fromBuffer(buffer); expect(res).toEqual(selector); - expect(res.isEmpty()).toBe(false); + expect(res.isDefault()).toBe(false); }); it('serializes to field and deserializes it back', () => { diff --git a/yarn-project/foundation/src/abi/function_selector.ts b/yarn-project/foundation/src/abi/function_selector.ts index 9ffcc958883..8cfc151f983 100644 --- a/yarn-project/foundation/src/abi/function_selector.ts +++ b/yarn-project/foundation/src/abi/function_selector.ts @@ -95,7 +95,7 @@ export class FunctionSelector extends Selector { * Creates an empty selector. * @returns An empty selector. */ - static empty() { + static default() { return new FunctionSelector(0); } diff --git a/yarn-project/foundation/src/abi/selector.ts b/yarn-project/foundation/src/abi/selector.ts index e8f56e01093..ec0998919dd 100644 --- a/yarn-project/foundation/src/abi/selector.ts +++ b/yarn-project/foundation/src/abi/selector.ts @@ -18,7 +18,7 @@ export abstract class Selector { * Checks if the selector is empty (all bytes are 0). * @returns True if the selector is empty (all bytes are 0). */ - public isEmpty(): boolean { + public isDefault(): boolean { return this.value === 0; } diff --git a/yarn-project/foundation/src/trees/index.ts b/yarn-project/foundation/src/trees/index.ts index 60b025a9e13..47668dc2ede 100644 --- a/yarn-project/foundation/src/trees/index.ts +++ b/yarn-project/foundation/src/trees/index.ts @@ -11,9 +11,9 @@ export interface IndexedTreeLeaf { */ toBuffer(): Buffer; /** - * Returns true if the leaf is empty. + * Returns true if the leaf is default. */ - isEmpty(): boolean; + isDefault(): boolean; /** * Updates the leaf with the data of another leaf. * @param another - The leaf to update to. diff --git a/yarn-project/merkle-tree/src/standard_indexed_tree/standard_indexed_tree.ts b/yarn-project/merkle-tree/src/standard_indexed_tree/standard_indexed_tree.ts index 42e9a3cbfbe..001886fc4a3 100644 --- a/yarn-project/merkle-tree/src/standard_indexed_tree/standard_indexed_tree.ts +++ b/yarn-project/merkle-tree/src/standard_indexed_tree/standard_indexed_tree.ts @@ -490,7 +490,7 @@ export class StandardIndexedTree extends TreeBase implements IndexedTree const newLeaf = sortedDescendingLeaves[i]; const originalIndex = leavesToInsert.indexOf(newLeaf); - if (newLeaf.isEmpty()) { + if (newLeaf.isDefault()) { continue; } diff --git a/yarn-project/pxe/src/kernel_prover/hints_builder.ts b/yarn-project/pxe/src/kernel_prover/hints_builder.ts index eb7ee451963..e245cf9636f 100644 --- a/yarn-project/pxe/src/kernel_prover/hints_builder.ts +++ b/yarn-project/pxe/src/kernel_prover/hints_builder.ts @@ -30,7 +30,7 @@ export class HintsBuilder { .map((sideEffect, index) => ({ sideEffect, index })) .sort((a, b) => { // Empty ones go to the right - if (a.sideEffect.isEmpty()) { + if (a.sideEffect.isDefault()) { return 1; } return Number(a.sideEffect.counter.toBigInt() - b.sideEffect.counter.toBigInt()); @@ -60,7 +60,7 @@ export class HintsBuilder { noteHashes: Tuple, ): Tuple { const hints = makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_TX, Fr.zero); - for (let i = 0; i < MAX_NOTE_HASH_READ_REQUESTS_PER_TX && !noteHashReadRequests[i].isEmpty(); i++) { + for (let i = 0; i < MAX_NOTE_HASH_READ_REQUESTS_PER_TX && !noteHashReadRequests[i].isDefault(); i++) { const equalToRR = (cmt: SideEffect) => cmt.value.equals(noteHashReadRequests[i].value); const result = noteHashes.findIndex(equalToRR); if (result == -1) { @@ -145,7 +145,7 @@ export class HintsBuilder { const keys = makeTuple(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, GrumpkinScalar.zero); for (let i = 0; i < nullifierKeyValidationRequests.length; ++i) { const request = nullifierKeyValidationRequests[i]; - if (request.isEmpty()) { + if (request.isDefault()) { break; } keys[i] = await this.oracle.getMasterNullifierSecretKey(request.publicKey); diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 21e03cccf7d..41f83242869 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -688,7 +688,7 @@ export class PXEService implements PXE { publicInputs.end.publicCallStack.find(item => item.equals(enqueued)), ); - const revertibleStackSize = arrayNonEmptyLength(publicInputs.end.publicCallStack, item => item.isEmpty()); + const revertibleStackSize = arrayNonEmptyLength(publicInputs.end.publicCallStack, item => item.isDefault()); if (enqueuedRevertiblePublicCallStackItems.length !== revertibleStackSize) { throw new Error( @@ -701,7 +701,7 @@ export class PXEService implements PXE { // Override kernel output publicInputs.end.publicCallStack = padArrayEnd( enqueuedRevertiblePublicCallStackItems, - CallRequest.empty(), + CallRequest.default(), MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, ); @@ -712,7 +712,7 @@ export class PXEService implements PXE { ); const nonRevertibleStackSize = arrayNonEmptyLength(publicInputs.endNonRevertibleData.publicCallStack, item => - item.isEmpty(), + item.isDefault(), ); if (enqueuedNonRevertiblePublicCallStackItems.length !== nonRevertibleStackSize) { @@ -728,7 +728,7 @@ export class PXEService implements PXE { // Override kernel output publicInputs.endNonRevertibleData.publicCallStack = padArrayEnd( enqueuedNonRevertiblePublicCallStackItems, - CallRequest.empty(), + CallRequest.default(), MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, ); } diff --git a/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts b/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts index 6508ec26618..f6b860d7c05 100644 --- a/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts +++ b/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts @@ -117,8 +117,8 @@ export abstract class AbstractPhaseManager { enqueuedPublicFunctionCalls: PublicCallRequest[], ): Record { const publicCallsStack = enqueuedPublicFunctionCalls.slice().reverse(); - const nonRevertibleCallStack = publicInputs.endNonRevertibleData.publicCallStack.filter(i => !i.isEmpty()); - const revertibleCallStack = publicInputs.end.publicCallStack.filter(i => !i.isEmpty()); + const nonRevertibleCallStack = publicInputs.endNonRevertibleData.publicCallStack.filter(i => !i.isDefault()); + const revertibleCallStack = publicInputs.end.publicCallStack.filter(i => !i.isDefault()); const callRequestsStack = publicCallsStack .map(call => call.toCallRequest()) @@ -511,7 +511,7 @@ function patchPublicStorageActionOrdering( const effectSet = PhaseIsRevertible[phase] ? 'end' : 'endNonRevertibleData'; - const numReadsInKernel = arrayNonEmptyLength(publicDataReads, f => f.isEmpty()); + const numReadsInKernel = arrayNonEmptyLength(publicDataReads, f => f.isDefault()); const numReadsBeforeThisEnqueuedCall = numReadsInKernel - simPublicDataReads.length; publicInputs.validationRequests.publicDataReads = padArrayEnd( [ @@ -519,18 +519,18 @@ function patchPublicStorageActionOrdering( ...publicInputs.validationRequests.publicDataReads.slice(0, numReadsBeforeThisEnqueuedCall), ...simPublicDataReads, ], - PublicDataRead.empty(), + PublicDataRead.default(), MAX_PUBLIC_DATA_READS_PER_TX, ); - const numUpdatesInKernel = arrayNonEmptyLength(publicDataUpdateRequests, f => f.isEmpty()); + const numUpdatesInKernel = arrayNonEmptyLength(publicDataUpdateRequests, f => f.isDefault()); const numUpdatesBeforeThisEnqueuedCall = numUpdatesInKernel - simPublicDataUpdateRequests.length; publicInputs[effectSet].publicDataUpdateRequests = padArrayEnd( [ ...publicInputs[effectSet].publicDataUpdateRequests.slice(0, numUpdatesBeforeThisEnqueuedCall), ...simPublicDataUpdateRequests, ], - PublicDataUpdateRequest.empty(), + PublicDataUpdateRequest.default(), PhaseIsRevertible[phase] ? MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX : MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, diff --git a/yarn-project/sequencer-client/src/sequencer/tx_validator.ts b/yarn-project/sequencer-client/src/sequencer/tx_validator.ts index ac586965586..7f4ab3ebd5b 100644 --- a/yarn-project/sequencer-client/src/sequencer/tx_validator.ts +++ b/yarn-project/sequencer-client/src/sequencer/tx_validator.ts @@ -133,7 +133,7 @@ export class TxValidator { */ async #validateNullifiers(tx: Tx | ProcessedTx, thisBlockNullifiers: Set): Promise { const newNullifiers = [...tx.data.endNonRevertibleData.newNullifiers, ...tx.data.end.newNullifiers] - .filter(x => !x.isEmpty()) + .filter(x => !x.isDefault()) .map(x => x.value.toBigInt()); // Ditch this tx if it has repeated nullifiers diff --git a/yarn-project/simulator/src/client/client_execution_context.ts b/yarn-project/simulator/src/client/client_execution_context.ts index 8586f777ae1..cbcb4823a8b 100644 --- a/yarn-project/simulator/src/client/client_execution_context.ts +++ b/yarn-project/simulator/src/client/client_execution_context.ts @@ -125,7 +125,7 @@ export class ClientExecutionContext extends ViewDataOracle { */ public getNoteHashReadRequestPartialWitnesses(noteHashReadRequests: SideEffect[]) { return noteHashReadRequests - .filter(r => !r.isEmpty()) + .filter(r => !r.isDefault()) .map(r => { const index = this.gotNotes.get(r.value.toBigInt()); return index !== undefined @@ -321,9 +321,9 @@ export class ClientExecutionContext extends ViewDataOracle { #checkValidStaticCall(childExecutionResult: ExecutionResult) { if ( - childExecutionResult.callStackItem.publicInputs.newNoteHashes.some(item => !item.isEmpty()) || - childExecutionResult.callStackItem.publicInputs.newNullifiers.some(item => !item.isEmpty()) || - childExecutionResult.callStackItem.publicInputs.newL2ToL1Msgs.some(item => !item.isEmpty()) || + childExecutionResult.callStackItem.publicInputs.newNoteHashes.some(item => !item.isDefault()) || + childExecutionResult.callStackItem.publicInputs.newNullifiers.some(item => !item.isDefault()) || + childExecutionResult.callStackItem.publicInputs.newL2ToL1Msgs.some(item => !item.isDefault()) || !childExecutionResult.callStackItem.publicInputs.encryptedLogPreimagesLength.equals(new Fr(4)) || !childExecutionResult.callStackItem.publicInputs.unencryptedLogPreimagesLength.equals(new Fr(4)) ) { diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 1c959d2ae9b..019e5ac4ce2 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -15,7 +15,7 @@ import { computeSiloedNullifierSecretKey, derivePublicKey, getContractInstanceFromDeployParams, - nonEmptySideEffects, + nonDefaultSideEffects, sideEffectArrayToValueArray, } from '@aztec/circuits.js'; import { computeCommitmentNonce, computeMessageSecretHash, computeVarArgsHash } from '@aztec/circuits.js/hash'; @@ -295,7 +295,7 @@ describe('Private Execution test suite', () => { expect(newNote.noteTypeId).toEqual(new Fr(869710811710178111116101n)); // ValueNote const newNoteHashes = sideEffectArrayToValueArray( - nonEmptySideEffects(result.callStackItem.publicInputs.newNoteHashes), + nonDefaultSideEffects(result.callStackItem.publicInputs.newNoteHashes), ); expect(newNoteHashes).toHaveLength(1); @@ -321,7 +321,7 @@ describe('Private Execution test suite', () => { expect(newNote.noteTypeId).toEqual(new Fr(869710811710178111116101n)); // ValueNote const newNoteHashes = sideEffectArrayToValueArray( - nonEmptySideEffects(result.callStackItem.publicInputs.newNoteHashes), + nonDefaultSideEffects(result.callStackItem.publicInputs.newNoteHashes), ); expect(newNoteHashes).toHaveLength(1); @@ -358,7 +358,7 @@ describe('Private Execution test suite', () => { // The two notes were nullified const newNullifiers = sideEffectArrayToValueArray( - nonEmptySideEffects(result.callStackItem.publicInputs.newNullifiers), + nonDefaultSideEffects(result.callStackItem.publicInputs.newNullifiers), ); expect(newNullifiers).toHaveLength(consumedNotes.length); expect(newNullifiers).toEqual(expect.arrayContaining(consumedNotes.map(n => n.innerNullifier))); @@ -385,7 +385,7 @@ describe('Private Execution test suite', () => { expect(changeNote.note.items[0]).toEqual(new Fr(40n)); const readRequests = sideEffectArrayToValueArray( - nonEmptySideEffects(result.callStackItem.publicInputs.noteHashReadRequests), + nonDefaultSideEffects(result.callStackItem.publicInputs.noteHashReadRequests), ); expect(readRequests).toHaveLength(consumedNotes.length); @@ -412,7 +412,7 @@ describe('Private Execution test suite', () => { const result = await runSimulator({ args, artifact, msgSender: owner }); const newNullifiers = sideEffectArrayToValueArray( - nonEmptySideEffects(result.callStackItem.publicInputs.newNullifiers), + nonDefaultSideEffects(result.callStackItem.publicInputs.newNullifiers), ); expect(newNullifiers).toEqual(consumedNotes.map(n => n.innerNullifier)); @@ -579,7 +579,7 @@ describe('Private Execution test suite', () => { // Check a nullifier has been inserted const newNullifiers = sideEffectArrayToValueArray( - nonEmptySideEffects(result.callStackItem.publicInputs.newNullifiers), + nonDefaultSideEffects(result.callStackItem.publicInputs.newNullifiers), ); expect(newNullifiers).toHaveLength(1); @@ -752,14 +752,14 @@ describe('Private Execution test suite', () => { // Check a nullifier has been inserted. const newNullifiers = sideEffectArrayToValueArray( - nonEmptySideEffects(result.callStackItem.publicInputs.newNullifiers), + nonDefaultSideEffects(result.callStackItem.publicInputs.newNullifiers), ); expect(newNullifiers).toHaveLength(1); // Check the commitment read request was created successfully. const readRequests = sideEffectArrayToValueArray( - nonEmptySideEffects(result.callStackItem.publicInputs.noteHashReadRequests), + nonDefaultSideEffects(result.callStackItem.publicInputs.noteHashReadRequests), ); expect(readRequests).toHaveLength(1); @@ -866,7 +866,7 @@ describe('Private Execution test suite', () => { expect(noteAndSlot.note.items[0]).toEqual(new Fr(amountToTransfer)); const newNoteHashes = sideEffectArrayToValueArray( - nonEmptySideEffects(result.callStackItem.publicInputs.newNoteHashes), + nonDefaultSideEffects(result.callStackItem.publicInputs.newNoteHashes), ); expect(newNoteHashes).toHaveLength(1); @@ -945,7 +945,7 @@ describe('Private Execution test suite', () => { expect(noteAndSlot.note.items[0]).toEqual(new Fr(amountToTransfer)); const newNoteHashes = sideEffectArrayToValueArray( - nonEmptySideEffects(execInsert.callStackItem.publicInputs.newNoteHashes), + nonDefaultSideEffects(execInsert.callStackItem.publicInputs.newNoteHashes), ); expect(newNoteHashes).toHaveLength(1); diff --git a/yarn-project/simulator/src/public/executor.ts b/yarn-project/simulator/src/public/executor.ts index 13ffcecc79b..6c82a03134e 100644 --- a/yarn-project/simulator/src/public/executor.ts +++ b/yarn-project/simulator/src/public/executor.ts @@ -114,11 +114,11 @@ export async function executePublicFunction( endSideEffectCounter, } = PublicCircuitPublicInputs.fromFields(returnWitness); - const nullifierReadRequests = nullifierReadRequestsPadded.filter(v => !v.isEmpty()); - const nullifierNonExistentReadRequests = nullifierNonExistentReadRequestsPadded.filter(v => !v.isEmpty()); - const newL2ToL1Messages = newL2ToL1Msgs.filter(v => !v.isEmpty()); - const newNoteHashes = newNoteHashesPadded.filter(v => !v.isEmpty()); - const newNullifiers = newNullifiersPadded.filter(v => !v.isEmpty()); + const nullifierReadRequests = nullifierReadRequestsPadded.filter(v => !v.isDefault()); + const nullifierNonExistentReadRequests = nullifierNonExistentReadRequestsPadded.filter(v => !v.isDefault()); + const newL2ToL1Messages = newL2ToL1Msgs.filter(v => !v.isDefault()); + const newNoteHashes = newNoteHashesPadded.filter(v => !v.isDefault()); + const newNullifiers = newNullifiersPadded.filter(v => !v.isDefault()); const { contractStorageReads, contractStorageUpdateRequests } = context.getStorageActionData(); From 56009a04227e468aaccf61b5bd0e339f0b5bc476 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Sun, 31 Mar 2024 10:53:32 +0000 Subject: [PATCH 13/77] fix --- .../archiver/src/archiver/archiver.test.ts | 8 ++++---- yarn-project/archiver/src/archiver/config.ts | 14 ++++++------- .../aztec-node/src/aztec-node/server.ts | 4 ++-- .../aztec.js/src/contract/deploy_method.ts | 2 +- .../src/deployment/deploy_instance.ts | 2 +- yarn-project/aztec/src/cli/util.ts | 2 +- yarn-project/circuit-types/src/body.ts | 2 +- .../circuit-types/src/function_call.ts | 2 +- yarn-project/circuit-types/src/l2_block.ts | 20 +++++++++---------- .../circuit-types/src/messaging/l1_actor.ts | 2 +- .../circuit-types/src/messaging/l2_actor.ts | 2 +- yarn-project/circuit-types/src/tx/tx_hash.ts | 6 +++--- .../src/contract/contract_instance.ts | 4 ++-- .../circuits.js/src/structs/call_context.ts | 14 ++++++------- .../circuits.js/src/structs/call_request.ts | 8 ++++---- .../src/structs/content_commitment.ts | 7 +------ .../src/structs/global_variables.ts | 6 +++--- .../kernel/combined_accumulated_data.ts | 13 +----------- .../src/structs/l2_to_l1_message.ts | 4 ++-- .../src/structs/membership_witness.ts | 2 +- ...te_hash_read_request_membership_witness.ts | 4 ++-- .../nullifier_key_validation_request.ts | 6 +++--- .../src/structs/private_call_stack_item.ts | 4 ++-- .../src/structs/public_call_stack_item.ts | 4 ++-- .../structs/public_circuit_public_inputs.ts | 4 ++-- .../circuits.js/src/structs/read_request.ts | 2 +- .../circuits.js/src/structs/tx_request.ts | 4 ++-- yarn-project/cli/src/cmds/add_contract.ts | 4 ++-- .../end-to-end/src/e2e_card_game.test.ts | 2 +- .../src/e2e_deploy_contract.test.ts | 2 +- .../src/integration_l1_publisher.test.ts | 2 +- .../src/shared/cross_chain_test_harness.ts | 6 +++--- .../src/shared/gas_portal_test_harness.ts | 4 ++-- .../foundation/src/aztec-address/index.ts | 8 ++++++-- .../src/eth-address/eth_address.test.ts | 2 +- .../foundation/src/eth-address/index.ts | 10 +++++++--- yarn-project/foundation/src/fields/point.ts | 2 +- .../src/noir_test_gen.test.ts | 2 +- .../src/gas-token/index.test.ts | 2 +- .../src/multi-call-entrypoint/index.ts | 2 +- .../src/protocol_contract.ts | 2 +- .../orchestrator/block-building-helpers.ts | 14 ++++++------- .../src/orchestrator/orchestrator.test.ts | 4 ++-- .../src/kernel_prover/kernel_prover.test.ts | 2 +- yarn-project/sequencer-client/src/config.ts | 14 ++++++------- .../src/sequencer/abstract_phase_manager.ts | 2 +- .../src/sequencer/public_processor.test.ts | 2 +- .../src/sequencer/sequencer.ts | 4 ++-- .../src/sequencer/tx_validator.test.ts | 4 ++-- .../simulator/src/avm/fixtures/index.ts | 18 ++++++++--------- .../src/client/client_execution_context.ts | 4 ++-- .../src/client/execution_result.test.ts | 2 +- .../src/client/private_execution.test.ts | 14 ++++++------- .../simulator/src/client/simulator.ts | 2 +- .../simulator/src/public/index.test.ts | 8 ++++---- .../src/public/public_execution_context.ts | 4 ++-- .../src/world-state-db/merkle_trees.ts | 2 +- 57 files changed, 147 insertions(+), 155 deletions(-) diff --git a/yarn-project/archiver/src/archiver/archiver.test.ts b/yarn-project/archiver/src/archiver/archiver.test.ts index 3a4e4428a4c..646d29fb69a 100644 --- a/yarn-project/archiver/src/archiver/archiver.test.ts +++ b/yarn-project/archiver/src/archiver/archiver.test.ts @@ -12,10 +12,10 @@ import { ArchiverDataStore } from './archiver_store.js'; import { MemoryArchiverStore } from './memory_archiver_store/memory_archiver_store.js'; describe('Archiver', () => { - const rollupAddress = EthAddress.ZERO; - const inboxAddress = EthAddress.ZERO; - const registryAddress = EthAddress.ZERO; - const availabilityOracleAddress = EthAddress.ZERO; + const rollupAddress = EthAddress.default(); + const inboxAddress = EthAddress.default(); + const registryAddress = EthAddress.default(); + const availabilityOracleAddress = EthAddress.default(); const blockNumbers = [1, 2, 3]; let publicClient: MockProxy>; let archiverStore: ArchiverDataStore; diff --git a/yarn-project/archiver/src/archiver/config.ts b/yarn-project/archiver/src/archiver/config.ts index 8a741ff31ac..98381db0e7e 100644 --- a/yarn-project/archiver/src/archiver/config.ts +++ b/yarn-project/archiver/src/archiver/config.ts @@ -70,15 +70,15 @@ export function getConfigEnvVars(): ArchiverConfig { const addresses: L1ContractAddresses = { availabilityOracleAddress: AVAILABILITY_ORACLE_CONTRACT_ADDRESS ? EthAddress.fromString(AVAILABILITY_ORACLE_CONTRACT_ADDRESS) - : EthAddress.ZERO, - rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, - registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO, - inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, - outboxAddress: OUTBOX_CONTRACT_ADDRESS ? EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, - gasTokenAddress: GAS_TOKEN_CONTRACT_ADDRESS ? EthAddress.fromString(GAS_TOKEN_CONTRACT_ADDRESS) : EthAddress.ZERO, + : EthAddress.default(), + rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.default(), + registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.default(), + inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.default(), + outboxAddress: OUTBOX_CONTRACT_ADDRESS ? EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS) : EthAddress.default(), + gasTokenAddress: GAS_TOKEN_CONTRACT_ADDRESS ? EthAddress.fromString(GAS_TOKEN_CONTRACT_ADDRESS) : EthAddress.default(), gasPortalAddress: GAS_PORTAL_CONTRACT_ADDRESS ? EthAddress.fromString(GAS_PORTAL_CONTRACT_ADDRESS) - : EthAddress.ZERO, + : EthAddress.default(), }; return { rpcUrl: ETHEREUM_HOST || 'http://127.0.0.1:8545/', diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index f905fbe3186..ea2e230e6f1 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -638,8 +638,8 @@ export class AztecNodeService implements AztecNode { const blockNumber = (await this.blockSource.getBlockNumber()) + 1; // If sequencer is not initialized, we just set these values to zero for simulation. - const coinbase = this.sequencer?.coinbase || EthAddress.ZERO; - const feeRecipient = this.sequencer?.feeRecipient || AztecAddress.ZERO; + const coinbase = this.sequencer?.coinbase || EthAddress.default(); + const feeRecipient = this.sequencer?.feeRecipient || AztecAddress.default(); const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables( new Fr(blockNumber), diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index 0cf02ecab9c..2010f09aee4 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -186,7 +186,7 @@ export class DeployMethod extends Bas portalAddress: options.portalContract, publicKey: this.publicKey, constructorArtifact: this.constructorArtifact, - deployer: options.universalDeploy ? AztecAddress.ZERO : this.wallet.getAddress(), + deployer: options.universalDeploy ? AztecAddress.default() : this.wallet.getAddress(), }); } return this.instance; diff --git a/yarn-project/aztec.js/src/deployment/deploy_instance.ts b/yarn-project/aztec.js/src/deployment/deploy_instance.ts index aac32143c17..fa7f208d495 100644 --- a/yarn-project/aztec.js/src/deployment/deploy_instance.ts +++ b/yarn-project/aztec.js/src/deployment/deploy_instance.ts @@ -12,7 +12,7 @@ import { getDeployerContract } from './protocol_contracts.js'; export function deployInstance(wallet: Wallet, instance: ContractInstanceWithAddress): ContractFunctionInteraction { const deployerContract = getDeployerContract(wallet); const { salt, contractClassId, portalContractAddress, publicKeysHash, deployer } = instance; - const isUniversalDeploy = deployer.isZero(); + const isUniversalDeploy = deployer.isDefault(); if (!isUniversalDeploy && !wallet.getAddress().equals(deployer)) { throw new Error( `Expected deployer ${deployer.toString()} does not match sender wallet ${wallet.getAddress().toString()}`, diff --git a/yarn-project/aztec/src/cli/util.ts b/yarn-project/aztec/src/cli/util.ts index 3a7a3f499cd..0947dd41330 100644 --- a/yarn-project/aztec/src/cli/util.ts +++ b/yarn-project/aztec/src/cli/util.ts @@ -27,7 +27,7 @@ function hasL1Contracts(obj: any): obj is { const checkContractAddresses = (contracts: L1ContractAddresses) => { return l1ContractsNames.every(cn => { const key = cn as keyof L1ContractAddresses; - return contracts[key] && contracts[key] !== EthAddress.ZERO; + return contracts[key] && contracts[key] !== EthAddress.default(); }); }; diff --git a/yarn-project/circuit-types/src/body.ts b/yarn-project/circuit-types/src/body.ts index 3c9e0a87761..03fce05576d 100644 --- a/yarn-project/circuit-types/src/body.ts +++ b/yarn-project/circuit-types/src/body.ts @@ -96,7 +96,7 @@ export class Body { return new Body(txEffects); } - static empty() { + static default() { return new Body([]); } } diff --git a/yarn-project/circuit-types/src/function_call.ts b/yarn-project/circuit-types/src/function_call.ts index c3d8e831ad4..910dd804086 100644 --- a/yarn-project/circuit-types/src/function_call.ts +++ b/yarn-project/circuit-types/src/function_call.ts @@ -16,7 +16,7 @@ export type FunctionCall = { */ export function emptyFunctionCall() { return { - to: AztecAddress.ZERO, + to: AztecAddress.default(), functionData: FunctionData.empty(), args: [], }; diff --git a/yarn-project/circuit-types/src/l2_block.ts b/yarn-project/circuit-types/src/l2_block.ts index c62b4e8c9db..29fbd2168b1 100644 --- a/yarn-project/circuit-types/src/l2_block.ts +++ b/yarn-project/circuit-types/src/l2_block.ts @@ -120,8 +120,8 @@ export class L2Block { */ static empty(): L2Block { return L2Block.fromFields({ - archive: AppendOnlyTreeSnapshot.zero(), - header: Header.empty(), + archive: AppendOnlyTreeSnapshot.default(), + header: Header.default(), body: Body.empty(), }); } @@ -147,10 +147,10 @@ export class L2Block { getPublicInputsHash(): Fr { const preimage = [ this.header.globalVariables, - AppendOnlyTreeSnapshot.zero(), // this.startNoteHashTreeSnapshot / commitments, - AppendOnlyTreeSnapshot.zero(), // this.startNullifierTreeSnapshot, - AppendOnlyTreeSnapshot.zero(), // this.startPublicDataTreeSnapshot, - AppendOnlyTreeSnapshot.zero(), // this.startL1ToL2MessageTreeSnapshot, + AppendOnlyTreeSnapshot.default(), // this.startNoteHashTreeSnapshot / commitments, + AppendOnlyTreeSnapshot.default(), // this.startNullifierTreeSnapshot, + AppendOnlyTreeSnapshot.default(), // this.startPublicDataTreeSnapshot, + AppendOnlyTreeSnapshot.default(), // this.startL1ToL2MessageTreeSnapshot, this.header.lastArchive, this.header.state.partial.noteHashTree, this.header.state.partial.nullifierTree, @@ -171,10 +171,10 @@ export class L2Block { getStartStateHash() { const inputValue = serializeToBuffer( new Fr(Number(this.header.globalVariables.blockNumber.toBigInt()) - 1), - AppendOnlyTreeSnapshot.zero(), // this.startNoteHashTreeSnapshot, - AppendOnlyTreeSnapshot.zero(), // this.startNullifierTreeSnapshot, - AppendOnlyTreeSnapshot.zero(), // this.startPublicDataTreeSnapshot, - AppendOnlyTreeSnapshot.zero(), // this.startL1ToL2MessageTreeSnapshot, + AppendOnlyTreeSnapshot.default(), // this.startNoteHashTreeSnapshot, + AppendOnlyTreeSnapshot.default(), // this.startNullifierTreeSnapshot, + AppendOnlyTreeSnapshot.default(), // this.startPublicDataTreeSnapshot, + AppendOnlyTreeSnapshot.default(), // this.startL1ToL2MessageTreeSnapshot, this.header.lastArchive, ); return sha256(inputValue); diff --git a/yarn-project/circuit-types/src/messaging/l1_actor.ts b/yarn-project/circuit-types/src/messaging/l1_actor.ts index 12b149ea79f..03a3f7f7f39 100644 --- a/yarn-project/circuit-types/src/messaging/l1_actor.ts +++ b/yarn-project/circuit-types/src/messaging/l1_actor.ts @@ -19,7 +19,7 @@ export class L1Actor { ) {} static empty() { - return new L1Actor(EthAddress.ZERO, 0); + return new L1Actor(EthAddress.default(), 0); } toFields(): Fr[] { diff --git a/yarn-project/circuit-types/src/messaging/l2_actor.ts b/yarn-project/circuit-types/src/messaging/l2_actor.ts index 9581a454f1a..364972662cf 100644 --- a/yarn-project/circuit-types/src/messaging/l2_actor.ts +++ b/yarn-project/circuit-types/src/messaging/l2_actor.ts @@ -19,7 +19,7 @@ export class L2Actor { ) {} static empty() { - return new L2Actor(AztecAddress.ZERO, 0); + return new L2Actor(AztecAddress.default(), 0); } toFields(): Fr[] { diff --git a/yarn-project/circuit-types/src/tx/tx_hash.ts b/yarn-project/circuit-types/src/tx/tx_hash.ts index 514097b3d6b..d6114621d97 100644 --- a/yarn-project/circuit-types/src/tx/tx_hash.ts +++ b/yarn-project/circuit-types/src/tx/tx_hash.ts @@ -53,10 +53,10 @@ export class TxHash { } /** - * Returns true if this hash is zero. - * @returns True if this hash is zero. + * Returns true if this hash is default. + * @returns True if this hash is default. */ - public isZero(): boolean { + public isDefault(): boolean { return this.buffer.equals(Buffer.alloc(32, 0)); } diff --git a/yarn-project/circuits.js/src/contract/contract_instance.ts b/yarn-project/circuits.js/src/contract/contract_instance.ts index dd96ec19491..f5548559afc 100644 --- a/yarn-project/circuits.js/src/contract/contract_instance.ts +++ b/yarn-project/circuits.js/src/contract/contract_instance.ts @@ -33,9 +33,9 @@ export function getContractInstanceFromDeployParams( const args = opts.constructorArgs ?? []; const salt = opts.salt ?? Fr.random(); const publicKey = opts.publicKey ?? Point.ZERO; - const portalContractAddress = opts.portalAddress ?? EthAddress.ZERO; + const portalContractAddress = opts.portalAddress ?? EthAddress.default(); const constructorArtifact = getConstructorArtifact(artifact, opts.constructorArtifact); - const deployer = opts.deployer ?? AztecAddress.ZERO; + const deployer = opts.deployer ?? AztecAddress.default(); const contractClass = getContractClassFromArtifact(artifact); const contractClassId = computeContractClassId(contractClass); diff --git a/yarn-project/circuits.js/src/structs/call_context.ts b/yarn-project/circuits.js/src/structs/call_context.ts index c805a5a586b..366295ccf89 100644 --- a/yarn-project/circuits.js/src/structs/call_context.ts +++ b/yarn-project/circuits.js/src/structs/call_context.ts @@ -50,10 +50,10 @@ export class CallContext { */ public static default(): CallContext { return new CallContext( - AztecAddress.ZERO, - AztecAddress.ZERO, - EthAddress.ZERO, - FunctionSelector.empty(), + AztecAddress.default(), + AztecAddress.default(), + EthAddress.default(), + FunctionSelector.default(), false, false, 0, @@ -62,9 +62,9 @@ export class CallContext { isDefault() { return ( - this.msgSender.isZero() && - this.storageContractAddress.isZero() && - this.portalContractAddress.isZero() && + this.msgSender.isDefault() && + this.storageContractAddress.isDefault() && + this.portalContractAddress.isDefault() && this.functionSelector.isDefault() && Fr.ZERO ); diff --git a/yarn-project/circuits.js/src/structs/call_request.ts b/yarn-project/circuits.js/src/structs/call_request.ts index 3396ee12e7f..d83f8441c23 100644 --- a/yarn-project/circuits.js/src/structs/call_request.ts +++ b/yarn-project/circuits.js/src/structs/call_request.ts @@ -23,11 +23,11 @@ export class CallerContext { * @returns A new instance of CallerContext with default values. */ public static default(): CallerContext { - return new CallerContext(AztecAddress.ZERO, AztecAddress.ZERO); + return new CallerContext(AztecAddress.default(), AztecAddress.default()); } isDefault() { - return this.msgSender.isZero() && this.storageContractAddress.isZero(); + return this.msgSender.isDefault() && this.storageContractAddress.isDefault(); } static from(fields: FieldsOf): CallerContext { @@ -120,7 +120,7 @@ export class CallRequest { isDefault() { return ( this.hash.isZero() && - this.callerContractAddress.isZero() && + this.callerContractAddress.isDefault() && this.callerContext.isDefault() && this.startSideEffectCounter.isZero() && this.endSideEffectCounter.isZero() @@ -132,7 +132,7 @@ export class CallRequest { * @returns A new instance of CallRequest with zero hash, caller contract address and caller context. */ public static default() { - return new CallRequest(Fr.ZERO, AztecAddress.ZERO, CallerContext.default(), Fr.ZERO, Fr.ZERO); + return new CallRequest(Fr.ZERO, AztecAddress.default(), CallerContext.default(), Fr.ZERO, Fr.ZERO); } equals(callRequest: CallRequest) { diff --git a/yarn-project/circuits.js/src/structs/content_commitment.ts b/yarn-project/circuits.js/src/structs/content_commitment.ts index f42bc5f03cf..ca679f7fe1b 100644 --- a/yarn-project/circuits.js/src/structs/content_commitment.ts +++ b/yarn-project/circuits.js/src/structs/content_commitment.ts @@ -75,12 +75,7 @@ export class ContentCommitment { } isDefault(): boolean { - return ( - this.txTreeHeight.isZero() && - this.txsEffectsHash.equals(Buffer.alloc(NUM_BYTES_PER_SHA256)) && - this.inHash.equals(Buffer.alloc(NUM_BYTES_PER_SHA256)) && - this.outHash.equals(Buffer.alloc(NUM_BYTES_PER_SHA256)) - ); + return this.toBuffer().equals(ContentCommitment.default().toBuffer()); } public toString(): string { diff --git a/yarn-project/circuits.js/src/structs/global_variables.ts b/yarn-project/circuits.js/src/structs/global_variables.ts index 41133e063bc..ec58d6059e3 100644 --- a/yarn-project/circuits.js/src/structs/global_variables.ts +++ b/yarn-project/circuits.js/src/structs/global_variables.ts @@ -30,7 +30,7 @@ export class GlobalVariables { } static default(): GlobalVariables { - return new GlobalVariables(Fr.ZERO, Fr.ZERO, Fr.ZERO, Fr.ZERO, EthAddress.ZERO, AztecAddress.ZERO); + return new GlobalVariables(Fr.ZERO, Fr.ZERO, Fr.ZERO, Fr.ZERO, EthAddress.default(), AztecAddress.default()); } static fromBuffer(buffer: Buffer | BufferReader): GlobalVariables { @@ -112,8 +112,8 @@ export class GlobalVariables { this.version.isZero() && this.blockNumber.isZero() && this.timestamp.isZero() && - this.coinbase.isZero() && - this.feeRecipient.isZero() + this.coinbase.isDefault() && + this.feeRecipient.isDefault() ); } } diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts index 07095ad1408..e0dcc6b6ec0 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts @@ -288,18 +288,7 @@ export class PublicAccumulatedRevertibleData { } isDefault(): boolean { - return ( - this.newNoteHashes.every(x => x.isDefault()) && - this.newNullifiers.every(x => x.isDefault()) && - this.privateCallStack.every(x => x.isDefault()) && - this.publicCallStack.every(x => x.isDefault()) && - this.newL2ToL1Msgs.every(x => x.isZero()) && - this.encryptedLogsHash.isZero() && - this.unencryptedLogsHash.isZero() && - this.encryptedLogPreimagesLength.isZero() && - this.unencryptedLogPreimagesLength.isZero() && - this.publicDataUpdateRequests.every(x => x.isDefault()) - ); + return this.toBuffer().equals(PublicAccumulatedRevertibleData.default().toBuffer()); } [inspect.custom]() { diff --git a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts index 9d556494131..ec1d9ca7cd3 100644 --- a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts +++ b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts @@ -12,7 +12,7 @@ export class L2ToL1Message { * @returns An instance of L2ToL1Message with empty fields. */ static default(): L2ToL1Message { - return new L2ToL1Message(EthAddress.ZERO, Fr.zero()); + return new L2ToL1Message(EthAddress.default(), Fr.zero()); } /** @@ -71,6 +71,6 @@ export class L2ToL1Message { * @returns True if both recipient and content are zero. */ isDefault(): boolean { - return this.recipient.isZero() && this.content.isZero(); + return this.recipient.isDefault() && this.content.isZero(); } } diff --git a/yarn-project/circuits.js/src/structs/membership_witness.ts b/yarn-project/circuits.js/src/structs/membership_witness.ts index b2d9211c58b..fec977c5497 100644 --- a/yarn-project/circuits.js/src/structs/membership_witness.ts +++ b/yarn-project/circuits.js/src/structs/membership_witness.ts @@ -49,7 +49,7 @@ export class MembershipWitness { * @param leafIndex - Index of the leaf in the Merkle tree. * @returns Membership witness with zero sibling path. */ - public static empty(pathSize: N, leafIndex: bigint): MembershipWitness { + public static default(pathSize: N, leafIndex: bigint): MembershipWitness { const arr = Array(pathSize) .fill(0) .map(() => Fr.ZERO) as Tuple; diff --git a/yarn-project/circuits.js/src/structs/note_hash_read_request_membership_witness.ts b/yarn-project/circuits.js/src/structs/note_hash_read_request_membership_witness.ts index d4b80f2fd21..3fe5ab590b8 100644 --- a/yarn-project/circuits.js/src/structs/note_hash_read_request_membership_witness.ts +++ b/yarn-project/circuits.js/src/structs/note_hash_read_request_membership_witness.ts @@ -82,9 +82,9 @@ export class NoteHashReadRequestMembershipWitness { /** * Creates a transient read request membership witness. - * @returns an empty transient read request membership witness. + * @returns a default transient read request membership witness. */ - public static emptyTransient(): NoteHashReadRequestMembershipWitness { + public static defaultTransient(): NoteHashReadRequestMembershipWitness { const arr = makeTuple(NOTE_HASH_TREE_HEIGHT, () => Fr.ZERO); return new NoteHashReadRequestMembershipWitness(new Fr(0), arr, true, new Fr(0)); } diff --git a/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts b/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts index 66816f4147a..c9599a6a0eb 100644 --- a/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts +++ b/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts @@ -48,7 +48,7 @@ export class NullifierKeyValidationRequest { } isDefault() { - return this.publicKey.isZero() && this.secretKey.isZero(); + return this.publicKey.isDefault() && this.secretKey.isZero(); } static default() { @@ -108,10 +108,10 @@ export class NullifierKeyValidationRequestContext { } isDefault() { - return this.publicKey.isZero() && this.secretKey.isZero() && this.contractAddress.isZero(); + return this.publicKey.isDefault() && this.secretKey.isZero() && this.contractAddress.isDefault(); } static default() { - return new NullifierKeyValidationRequestContext(Point.ZERO, GrumpkinScalar.ZERO, AztecAddress.ZERO); + return new NullifierKeyValidationRequestContext(Point.ZERO, GrumpkinScalar.ZERO, AztecAddress.default()); } } diff --git a/yarn-project/circuits.js/src/structs/private_call_stack_item.ts b/yarn-project/circuits.js/src/structs/private_call_stack_item.ts index 7bf8e270731..8cf340466f1 100644 --- a/yarn-project/circuits.js/src/structs/private_call_stack_item.ts +++ b/yarn-project/circuits.js/src/structs/private_call_stack_item.ts @@ -76,14 +76,14 @@ export class PrivateCallStackItem { */ public static empty(): PrivateCallStackItem { return new PrivateCallStackItem( - AztecAddress.ZERO, + AztecAddress.default(), FunctionData.default({ isPrivate: true }), PrivateCircuitPublicInputs.empty(), ); } isDefault() { - return this.contractAddress.isZero() && this.functionData.isDefault() && this.publicInputs.isDefault(); + return this.contractAddress.isDefault() && this.functionData.isDefault() && this.publicInputs.isDefault(); } /** diff --git a/yarn-project/circuits.js/src/structs/public_call_stack_item.ts b/yarn-project/circuits.js/src/structs/public_call_stack_item.ts index 234034c4796..d8a06ec6e37 100644 --- a/yarn-project/circuits.js/src/structs/public_call_stack_item.ts +++ b/yarn-project/circuits.js/src/structs/public_call_stack_item.ts @@ -73,7 +73,7 @@ export class PublicCallStackItem { */ public static default(): PublicCallStackItem { return new PublicCallStackItem( - AztecAddress.ZERO, + AztecAddress.default(), FunctionData.default({ isPrivate: false }), PublicCircuitPublicInputs.default(), false, @@ -81,7 +81,7 @@ export class PublicCallStackItem { } isDefault() { - return this.contractAddress.isZero() && this.functionData.isDefault() && this.publicInputs.isDefault(); + return this.contractAddress.isDefault() && this.functionData.isDefault() && this.publicInputs.isDefault(); } /** diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts index d74a103cc30..1a50fd6096b 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts @@ -147,7 +147,7 @@ export class PublicCircuitPublicInputs { Fr.ZERO, Fr.ZERO, Header.default(), - AztecAddress.ZERO, + AztecAddress.default(), RevertCode.OK, ); } @@ -174,7 +174,7 @@ export class PublicCircuitPublicInputs { this.unencryptedLogsHash.isZero() && this.unencryptedLogPreimagesLength.isZero() && this.historicalHeader.isDefault() && - this.proverAddress.isZero() && + this.proverAddress.isDefault() && this.revertCode.isOK() ); } diff --git a/yarn-project/circuits.js/src/structs/read_request.ts b/yarn-project/circuits.js/src/structs/read_request.ts index 6caf707837e..0e1007f31ac 100644 --- a/yarn-project/circuits.js/src/structs/read_request.ts +++ b/yarn-project/circuits.js/src/structs/read_request.ts @@ -125,6 +125,6 @@ export class ReadRequestContext { * @returns Side-effect with value, note hash and counter being zero. */ static default(): ReadRequestContext { - return new ReadRequestContext(Fr.zero(), 0, AztecAddress.ZERO); + return new ReadRequestContext(Fr.zero(), 0, AztecAddress.default()); } } diff --git a/yarn-project/circuits.js/src/structs/tx_request.ts b/yarn-project/circuits.js/src/structs/tx_request.ts index 819e60669ac..56613edf8f1 100644 --- a/yarn-project/circuits.js/src/structs/tx_request.ts +++ b/yarn-project/circuits.js/src/structs/tx_request.ts @@ -75,10 +75,10 @@ export class TxRequest { } static default() { - return new TxRequest(AztecAddress.ZERO, FunctionData.default(), Fr.zero(), TxContext.default()); + return new TxRequest(AztecAddress.default(), FunctionData.default(), Fr.zero(), TxContext.default()); } isDefault() { - return this.origin.isZero() && this.functionData.isDefault() && this.argsHash.isZero() && this.txContext.isDefault(); + return this.origin.isDefault() && this.functionData.isDefault() && this.argsHash.isZero() && this.txContext.isDefault(); } } diff --git a/yarn-project/cli/src/cmds/add_contract.ts b/yarn-project/cli/src/cmds/add_contract.ts index b09e87d6eb7..de675466753 100644 --- a/yarn-project/cli/src/cmds/add_contract.ts +++ b/yarn-project/cli/src/cmds/add_contract.ts @@ -30,10 +30,10 @@ export async function addContract( salt, initializationHash, contractClassId: getContractClassFromArtifact(artifact).id, - portalContractAddress: portalContract ?? EthAddress.ZERO, + portalContractAddress: portalContract ?? EthAddress.default(), publicKeysHash: computePublicKeysHash(publicKey), address, - deployer: deployer ?? AztecAddress.ZERO, + deployer: deployer ?? AztecAddress.default(), }; const computed = computeContractAddressFromInstance(instance); if (!computed.equals(address)) { diff --git a/yarn-project/end-to-end/src/e2e_card_game.test.ts b/yarn-project/end-to-end/src/e2e_card_game.test.ts index 1520f91c92a..4a85a6073f8 100644 --- a/yarn-project/end-to-end/src/e2e_card_game.test.ts +++ b/yarn-project/end-to-end/src/e2e_card_game.test.ts @@ -186,7 +186,7 @@ describe('e2e_card_game', () => { points: 0n, }, { - address: AztecAddress.ZERO, + address: AztecAddress.default(), deck_strength: 0n, points: 0n, }, diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts index 7638c537499..11f6933cf04 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts @@ -127,7 +127,7 @@ describe('e2e_deploy_contract', () => { const artifact = TokenContractArtifact; const initArgs = ['TokenName', 'TKN', 18] as const; const goodDeploy = StatefulTestContract.deploy(wallet, accounts[0], 42); - const badDeploy = new ContractDeployer(artifact, wallet).deploy(AztecAddress.ZERO, ...initArgs); + const badDeploy = new ContractDeployer(artifact, wallet).deploy(AztecAddress.default(), ...initArgs); const firstOpts = { skipPublicSimulation: true, skipClassRegistration: true, skipInstanceDeploy: true }; const secondOpts = { skipPublicSimulation: true }; diff --git a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts index 050cf0da6bf..4c4de2b0b71 100644 --- a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts @@ -474,7 +474,7 @@ describe('L1Publisher integration', () => { const block = (result as ProvingSuccess).block; prevHeader = block.header; - writeJson(`empty_block_${i}`, block, [], AztecAddress.ZERO, deployerAccount.address); + writeJson(`empty_block_${i}`, block, [], AztecAddress.default(), deployerAccount.address); await publisher.processL2Block(block); diff --git a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts index 89f8778ae5f..da1118525d4 100644 --- a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts @@ -327,7 +327,7 @@ export class CrossChainTestHarness { async withdrawPrivateFromAztecToL1(withdrawAmount: bigint, nonce: Fr = Fr.ZERO): Promise> { const withdrawReceipt = await this.l2Bridge.methods - .exit_to_l1_private(this.l2Token.address, this.ethAccount, withdrawAmount, EthAddress.ZERO, nonce) + .exit_to_l1_private(this.l2Token.address, this.ethAccount, withdrawAmount, EthAddress.default(), nonce) .send() .wait(); @@ -336,7 +336,7 @@ export class CrossChainTestHarness { async withdrawPublicFromAztecToL1(withdrawAmount: bigint, nonce: Fr = Fr.ZERO): Promise> { const withdrawReceipt = await this.l2Bridge.methods - .exit_to_l1_public(this.ethAccount, withdrawAmount, EthAddress.ZERO, nonce) + .exit_to_l1_public(this.ethAccount, withdrawAmount, EthAddress.default(), nonce) .send() .wait(); @@ -362,7 +362,7 @@ export class CrossChainTestHarness { expect(balance).toBe(expectedBalance); } - getL2ToL1MessageLeaf(withdrawAmount: bigint, callerOnL1: EthAddress = EthAddress.ZERO): Fr { + getL2ToL1MessageLeaf(withdrawAmount: bigint, callerOnL1: EthAddress = EthAddress.default()): Fr { const content = sha256ToField([ Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'), this.ethAccount.toBuffer32(), diff --git a/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts b/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts index ef5140df02f..701d1511181 100644 --- a/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts @@ -26,7 +26,7 @@ export class GasPortalTestingHarnessFactory { const gasL2 = await GasTokenContract.deploy(wallet) .send({ - contractAddressSalt: getCanonicalGasToken(EthAddress.ZERO).instance.salt, + contractAddressSalt: getCanonicalGasToken(EthAddress.default()).instance.salt, }) .deployed(); return Promise.resolve(new MockGasBridgingTestHarness(gasL2)); @@ -41,7 +41,7 @@ export class GasPortalTestingHarnessFactory { const gasTokenAddress = l1ContractAddresses.gasTokenAddress; const gasPortalAddress = l1ContractAddresses.gasPortalAddress; - if (gasTokenAddress.isZero() || gasPortalAddress.isZero()) { + if (gasTokenAddress.isDefault() || gasPortalAddress.isDefault()) { throw new Error('Gas portal not deployed on L1'); } diff --git a/yarn-project/foundation/src/aztec-address/index.ts b/yarn-project/foundation/src/aztec-address/index.ts index ea1407b9eaa..1a9c8b20197 100644 --- a/yarn-project/foundation/src/aztec-address/index.ts +++ b/yarn-project/foundation/src/aztec-address/index.ts @@ -24,8 +24,12 @@ export class AztecAddress extends Fr { static ZERO = new AztecAddress(Buffer.alloc(32)); - static zero(): AztecAddress { - return AztecAddress.ZERO; + static default(): AztecAddress { + return AztecAddress.default(); + } + + isDefault(): boolean { + return this.equals(AztecAddress.default()); } static fromBuffer(buffer: Buffer | BufferReader) { diff --git a/yarn-project/foundation/src/eth-address/eth_address.test.ts b/yarn-project/foundation/src/eth-address/eth_address.test.ts index 2ae3e1bc736..fd593c4e74a 100644 --- a/yarn-project/foundation/src/eth-address/eth_address.test.ts +++ b/yarn-project/foundation/src/eth-address/eth_address.test.ts @@ -24,7 +24,7 @@ describe('address', () => { it('should check if is zero', () => { const zero = EthAddress.fromString('0x0000000000000000000000000000000000000000'); - expect(zero.isZero()).toBeTruthy(); + expect(zero.isDefault()).toBeTruthy(); }); it('should encode and decode as field', () => { diff --git a/yarn-project/foundation/src/eth-address/index.ts b/yarn-project/foundation/src/eth-address/index.ts index f61c1f75b4f..8119a13972d 100644 --- a/yarn-project/foundation/src/eth-address/index.ts +++ b/yarn-project/foundation/src/eth-address/index.ts @@ -74,14 +74,18 @@ export class EthAddress { } } + public static default() { + return EthAddress.default(); + } + /** - * Checks if the EthAddress instance represents a zero address. + * Checks if the EthAddress instance represents a default address (zero address). * A zero address consists of 20 bytes filled with zeros and is considered an invalid address. * * @returns A boolean indicating whether the EthAddress instance is a zero address or not. */ - public isZero() { - return this.equals(EthAddress.ZERO); + public isDefault() { + return this.equals(EthAddress.default()); } /** diff --git a/yarn-project/foundation/src/fields/point.ts b/yarn-project/foundation/src/fields/point.ts index dfb5065c03d..aef3fe8236b 100644 --- a/yarn-project/foundation/src/fields/point.ts +++ b/yarn-project/foundation/src/fields/point.ts @@ -126,7 +126,7 @@ export class Point { return this.x.equals(rhs.x) && this.y.equals(rhs.y); } - isZero() { + isDefault() { return this.x.isZero() && this.y.isZero(); } } diff --git a/yarn-project/noir-protocol-circuits-types/src/noir_test_gen.test.ts b/yarn-project/noir-protocol-circuits-types/src/noir_test_gen.test.ts index 8082a6c7801..eb93a0bb5d8 100644 --- a/yarn-project/noir-protocol-circuits-types/src/noir_test_gen.test.ts +++ b/yarn-project/noir-protocol-circuits-types/src/noir_test_gen.test.ts @@ -60,7 +60,7 @@ describe('Data generation for noir tests', () => { const initializationHash = computeInitializationHashFromEncodedArgs(constructorSelector, []); const { artifactHash, privateFunctionsRoot, publicBytecodeCommitment } = computeContractClassIdPreimage(contractClass); - const deployer = AztecAddress.ZERO; + const deployer = AztecAddress.default(); const instance: ContractInstance = { ...contract, version: 1, initializationHash, contractClassId, deployer }; const address = computeContractAddressFromInstance(instance); const saltedInitializationHash = computeSaltedInitializationHash(instance); diff --git a/yarn-project/protocol-contracts/src/gas-token/index.test.ts b/yarn-project/protocol-contracts/src/gas-token/index.test.ts index 4a15655d4a3..c6b9e4badc5 100644 --- a/yarn-project/protocol-contracts/src/gas-token/index.test.ts +++ b/yarn-project/protocol-contracts/src/gas-token/index.test.ts @@ -4,7 +4,7 @@ import { getCanonicalGasToken } from './index.js'; describe('GasToken', () => { it('returns canonical protocol contract', () => { - const contract = getCanonicalGasToken(EthAddress.ZERO); + const contract = getCanonicalGasToken(EthAddress.default()); expect(computeContractAddressFromInstance(contract.instance)).toEqual(contract.address); expect(getContractClassFromArtifact(contract.artifact).id).toEqual(contract.contractClass.id); }); diff --git a/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts b/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts index c9298b886f6..4a666a676c5 100644 --- a/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts +++ b/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts @@ -4,7 +4,7 @@ import { ProtocolContract, getCanonicalProtocolContract } from '../protocol_cont import { MultiCallEntrypointArtifact } from './artifact.js'; export function getCanonicalMultiCallEntrypointContract(): ProtocolContract { - return getCanonicalProtocolContract(MultiCallEntrypointArtifact, 1, [], Point.ZERO, EthAddress.ZERO); + return getCanonicalProtocolContract(MultiCallEntrypointArtifact, 1, [], Point.ZERO, EthAddress.default()); } export function getCanonicalMultiCallEntrypointAddress(): AztecAddress { diff --git a/yarn-project/protocol-contracts/src/protocol_contract.ts b/yarn-project/protocol-contracts/src/protocol_contract.ts index 8d7e4ccb371..2295eb9a129 100644 --- a/yarn-project/protocol-contracts/src/protocol_contract.ts +++ b/yarn-project/protocol-contracts/src/protocol_contract.ts @@ -26,7 +26,7 @@ export function getCanonicalProtocolContract( salt: Fr | number | bigint, constructorArgs: any[] = [], publicKey: Point = Point.ZERO, - portalAddress = EthAddress.ZERO, + portalAddress = EthAddress.default(), ): ProtocolContract { // TODO(@spalladino): This computes the contract class from the artifact twice. const contractClass = getContractClassFromArtifact(artifact); diff --git a/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts b/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts index 5156edd6301..41f75074d08 100644 --- a/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts +++ b/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts @@ -135,7 +135,7 @@ export async function buildBaseRollupInput( nullifierPredecessorPreimages: makeTuple(MAX_NEW_NULLIFIERS_PER_TX, i => i < nullifierWitnessLeaves.length ? (nullifierWitnessLeaves[i].leafPreimage as NullifierLeafPreimage) - : NullifierLeafPreimage.empty(), + : NullifierLeafPreimage.default(), ), nullifierPredecessorMembershipWitnesses: makeTuple(MAX_NEW_NULLIFIERS_PER_TX, i => i < nullifierPredecessorMembershipWitnessesWithoutPadding.length @@ -386,11 +386,11 @@ export async function getPublicDataReadsInfo(tx: ProcessedTx, db: MerkleTreeOper const newPublicDataReadsWitnesses: Tuple< MembershipWitness, typeof MAX_PUBLIC_DATA_READS_PER_TX - > = makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, () => MembershipWitness.empty(PUBLIC_DATA_TREE_HEIGHT, 0n)); + > = makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, () => MembershipWitness.default(PUBLIC_DATA_TREE_HEIGHT, 0n)); const newPublicDataReadsPreimages: Tuple = makeTuple( MAX_PUBLIC_DATA_READS_PER_TX, - () => PublicDataTreeLeafPreimage.empty(), + () => PublicDataTreeLeafPreimage.default(), ); for (const i in tx.data.validationRequests.publicDataReads) { @@ -578,16 +578,16 @@ export async function executeRootParityCircuit( export function validateTx(tx: ProcessedTx) { const txHeader = tx.data.constants.historicalHeader; - if (txHeader.state.l1ToL2MessageTree.isZero()) { + if (txHeader.state.l1ToL2MessageTree.isDefault()) { throw new Error(`Empty L1 to L2 messages tree in tx: ${toFriendlyJSON(tx)}`); } - if (txHeader.state.partial.noteHashTree.isZero()) { + if (txHeader.state.partial.noteHashTree.isDefault()) { throw new Error(`Empty note hash tree in tx: ${toFriendlyJSON(tx)}`); } - if (txHeader.state.partial.nullifierTree.isZero()) { + if (txHeader.state.partial.nullifierTree.isDefault()) { throw new Error(`Empty nullifier tree in tx: ${toFriendlyJSON(tx)}`); } - if (txHeader.state.partial.publicDataTree.isZero()) { + if (txHeader.state.partial.publicDataTree.isDefault()) { throw new Error(`Empty public data tree in tx: ${toFriendlyJSON(tx)}`); } } diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.test.ts index c4af9a479dc..8c7c6826bd7 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.test.ts @@ -80,8 +80,8 @@ describe('prover/tx-prover', () => { const chainId = Fr.ZERO; const version = Fr.ZERO; - const coinbase = EthAddress.ZERO; - const feeRecipient = AztecAddress.ZERO; + const coinbase = EthAddress.default(); + const feeRecipient = AztecAddress.default(); beforeEach(async () => { blockNumber = 3; diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts index 27ca152a181..4491c70d86c 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts @@ -63,7 +63,7 @@ describe('Kernel Prover', () => { const functionData = FunctionData.empty(); functionData.selector = new FunctionSelector(fnName.charCodeAt(0)); return { - callStackItem: new PrivateCallStackItem(AztecAddress.ZERO, functionData, publicInputs), + callStackItem: new PrivateCallStackItem(AztecAddress.default(), functionData, publicInputs), nestedExecutions: (dependencies[fnName] || []).map(name => createExecutionResult(name)), vk: VerificationKey.makeFake().toBuffer(), newNotes: newNoteIndices.map(idx => notesAndSlots[idx]), diff --git a/yarn-project/sequencer-client/src/config.ts b/yarn-project/sequencer-client/src/config.ts index f54dabbe3a9..c0808f12cb1 100644 --- a/yarn-project/sequencer-client/src/config.ts +++ b/yarn-project/sequencer-client/src/config.ts @@ -62,15 +62,15 @@ export function getConfigEnvVars(): SequencerClientConfig { const addresses: L1ContractAddresses = { availabilityOracleAddress: AVAILABILITY_ORACLE_CONTRACT_ADDRESS ? EthAddress.fromString(AVAILABILITY_ORACLE_CONTRACT_ADDRESS) - : EthAddress.ZERO, - rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, - registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO, - inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, - outboxAddress: OUTBOX_CONTRACT_ADDRESS ? EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, - gasTokenAddress: GAS_TOKEN_CONTRACT_ADDRESS ? EthAddress.fromString(GAS_TOKEN_CONTRACT_ADDRESS) : EthAddress.ZERO, + : EthAddress.default(), + rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.default(), + registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.default(), + inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.default(), + outboxAddress: OUTBOX_CONTRACT_ADDRESS ? EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS) : EthAddress.default(), + gasTokenAddress: GAS_TOKEN_CONTRACT_ADDRESS ? EthAddress.fromString(GAS_TOKEN_CONTRACT_ADDRESS) : EthAddress.default(), gasPortalAddress: GAS_PORTAL_CONTRACT_ADDRESS ? EthAddress.fromString(GAS_PORTAL_CONTRACT_ADDRESS) - : EthAddress.ZERO, + : EthAddress.default(), }; return { diff --git a/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts b/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts index f6b860d7c05..a4e6b05fcc7 100644 --- a/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts +++ b/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts @@ -351,7 +351,7 @@ export abstract class AbstractPhaseManager { return PublicCircuitPublicInputs.from({ callContext: result.execution.callContext, - proverAddress: AztecAddress.ZERO, + proverAddress: AztecAddress.default(), argsHash: computeVarArgsHash(result.execution.args), newNoteHashes: padArrayEnd(result.newNoteHashes, SideEffect.empty(), MAX_NEW_NOTE_HASHES_PER_CALL), newNullifiers: padArrayEnd(result.newNullifiers, SideEffectLinkedToNoteHash.empty(), MAX_NEW_NULLIFIERS_PER_CALL), diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts index 7044472cb53..0d9a66562bd 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts @@ -770,7 +770,7 @@ class PublicExecutionResultBuilder { revertReason?: SimulationError; }) { const builder = new PublicExecutionResultBuilder({ - callContext: new CallContext(from, tx.to, EthAddress.ZERO, tx.functionData.selector, false, false, 0), + callContext: new CallContext(from, tx.to, EthAddress.default(), tx.functionData.selector, false, false, 0), contractAddress: tx.to, functionData: tx.functionData, args: tx.args, diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index 4823f48d3fa..1500b0aa29e 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -31,8 +31,8 @@ export class Sequencer { private maxTxsPerBlock = 32; private minTxsPerBLock = 1; // TODO: zero values should not be allowed for the following 2 values in PROD - private _coinbase = EthAddress.ZERO; - private _feeRecipient = AztecAddress.ZERO; + private _coinbase = EthAddress.default(); + private _feeRecipient = AztecAddress.default(); private lastPublishedBlock = 0; private state = SequencerState.STOPPED; private allowedFeePaymentContractClasses: Fr[] = []; diff --git a/yarn-project/sequencer-client/src/sequencer/tx_validator.test.ts b/yarn-project/sequencer-client/src/sequencer/tx_validator.test.ts index a9f13a43079..e711146e6be 100644 --- a/yarn-project/sequencer-client/src/sequencer/tx_validator.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/tx_validator.test.ts @@ -306,7 +306,7 @@ describe('TxValidator', () => { const feeSetupFn = new PublicCallRequest( feePaymentContract, new FunctionData(feeSetupSelector, true), - new CallContext(feePaymentContract, feePaymentContract, EthAddress.ZERO, feeSetupSelector, false, false, 1), + new CallContext(feePaymentContract, feePaymentContract, EthAddress.default(), feeSetupSelector, false, false, 1), CallContext.empty(), [], ); @@ -318,7 +318,7 @@ describe('TxValidator', () => { const feeExecutionFn = new PublicCallRequest( feePaymentContract, new FunctionData(feeExecutionSelector, true), - new CallContext(feePaymentContract, feePaymentContract, EthAddress.ZERO, feeExecutionSelector, false, false, 2), + new CallContext(feePaymentContract, feePaymentContract, EthAddress.default(), feeExecutionSelector, false, false, 2), CallContext.empty(), [], ); diff --git a/yarn-project/simulator/src/avm/fixtures/index.ts b/yarn-project/simulator/src/avm/fixtures/index.ts index 88fc65a2de2..a8897c22392 100644 --- a/yarn-project/simulator/src/avm/fixtures/index.ts +++ b/yarn-project/simulator/src/avm/fixtures/index.ts @@ -53,20 +53,20 @@ export function initMockPersistableStateManager(): AvmPersistableStateManager { */ export function initExecutionEnvironment(overrides?: Partial): AvmExecutionEnvironment { return new AvmExecutionEnvironment( - overrides?.address ?? AztecAddress.zero(), - overrides?.storageAddress ?? AztecAddress.zero(), - overrides?.origin ?? AztecAddress.zero(), - overrides?.sender ?? AztecAddress.zero(), - overrides?.portal ?? EthAddress.ZERO, + overrides?.address ?? AztecAddress.default(), + overrides?.storageAddress ?? AztecAddress.default(), + overrides?.origin ?? AztecAddress.default(), + overrides?.sender ?? AztecAddress.default(), + overrides?.portal ?? EthAddress.default(), overrides?.feePerL1Gas ?? Fr.zero(), overrides?.feePerL2Gas ?? Fr.zero(), overrides?.feePerDaGas ?? Fr.zero(), overrides?.contractCallDepth ?? Fr.zero(), - overrides?.globals ?? GlobalVariables.empty(), + overrides?.globals ?? GlobalVariables.default(), overrides?.isStaticCall ?? false, overrides?.isDelegateCall ?? false, overrides?.calldata ?? [], - overrides?.temporaryFunctionSelector ?? FunctionSelector.empty(), + overrides?.temporaryFunctionSelector ?? FunctionSelector.default(), ); } @@ -79,8 +79,8 @@ export function initGlobalVariables(overrides?: Partial): Globa overrides?.version ?? Fr.zero(), overrides?.blockNumber ?? Fr.zero(), overrides?.timestamp ?? Fr.zero(), - overrides?.coinbase ?? EthAddress.ZERO, - overrides?.feeRecipient ?? AztecAddress.zero(), + overrides?.coinbase ?? EthAddress.default(), + overrides?.feeRecipient ?? AztecAddress.default(), ); } diff --git a/yarn-project/simulator/src/client/client_execution_context.ts b/yarn-project/simulator/src/client/client_execution_context.ts index cbcb4823a8b..7e5263bd243 100644 --- a/yarn-project/simulator/src/client/client_execution_context.ts +++ b/yarn-project/simulator/src/client/client_execution_context.ts @@ -129,8 +129,8 @@ export class ClientExecutionContext extends ViewDataOracle { .map(r => { const index = this.gotNotes.get(r.value.toBigInt()); return index !== undefined - ? NoteHashReadRequestMembershipWitness.empty(index) - : NoteHashReadRequestMembershipWitness.emptyTransient(); + ? NoteHashReadRequestMembershipWitness.default(index) + : NoteHashReadRequestMembershipWitness.defaultTransient(); }); } diff --git a/yarn-project/simulator/src/client/execution_result.test.ts b/yarn-project/simulator/src/client/execution_result.test.ts index f09c5bf0744..ba16d784bb4 100644 --- a/yarn-project/simulator/src/client/execution_result.test.ts +++ b/yarn-project/simulator/src/client/execution_result.test.ts @@ -163,7 +163,7 @@ describe('collect unencrypted logs', () => { function makeUnencryptedFunctionLogs(contents: string[]) { return new UnencryptedFunctionL2Logs( - contents.map(s => new UnencryptedL2Log(AztecAddress.ZERO, EventSelector.empty(), Buffer.from(s))), + contents.map(s => new UnencryptedL2Log(AztecAddress.default(), EventSelector.empty(), Buffer.from(s))), ); } diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 019e5ac4ce2..35097eff9cc 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -94,9 +94,9 @@ describe('Private Execution test suite', () => { const runSimulator = ({ artifact, args = [], - msgSender = AztecAddress.ZERO, + msgSender = AztecAddress.default(), contractAddress = defaultContractAddress, - portalContractAddress = EthAddress.ZERO, + portalContractAddress = EthAddress.default(), txContext = {}, }: { artifact: FunctionArtifact; @@ -278,7 +278,7 @@ describe('Private Execution test suite', () => { Promise.resolve(getFunctionArtifact(StatefulTestContractArtifact, selector)), ); - oracle.getPortalContractAddress.mockResolvedValue(EthAddress.ZERO); + oracle.getPortalContractAddress.mockResolvedValue(EthAddress.default()); }); it('should have a constructor with arguments that inserts notes', async () => { @@ -442,7 +442,7 @@ describe('Private Execution test suite', () => { const childSelector = FunctionSelector.fromNameAndParameters(childArtifact.name, childArtifact.parameters); oracle.getFunctionArtifact.mockImplementation(() => Promise.resolve(childArtifact)); - oracle.getPortalContractAddress.mockImplementation(() => Promise.resolve(EthAddress.ZERO)); + oracle.getPortalContractAddress.mockImplementation(() => Promise.resolve(EthAddress.default())); logger(`Parent deployed at ${parentAddress.toShortString()}`); logger(`Calling child function ${childSelector.toString()} at ${childAddress.toShortString()}`); @@ -495,7 +495,7 @@ describe('Private Execution test suite', () => { ); oracle.getFunctionArtifact.mockResolvedValue(testCodeGenArtifact); - oracle.getPortalContractAddress.mockResolvedValue(EthAddress.ZERO); + oracle.getPortalContractAddress.mockResolvedValue(EthAddress.default()); logger(`Calling importer main function`); const args = [testAddress]; @@ -809,7 +809,7 @@ describe('Private Execution test suite', () => { parentCallContext: CallContext.from({ msgSender: parentAddress, storageContractAddress: parentAddress, - portalContractAddress: EthAddress.ZERO, + portalContractAddress: EthAddress.default(), functionSelector: FunctionSelector.fromNameAndParameters(parentArtifact.name, parentArtifact.parameters), isDelegateCall: false, isStaticCall: false, @@ -922,7 +922,7 @@ describe('Private Execution test suite', () => { getThenNullifyArtifact.parameters, ); - oracle.getPortalContractAddress.mockImplementation(() => Promise.resolve(EthAddress.ZERO)); + oracle.getPortalContractAddress.mockImplementation(() => Promise.resolve(EthAddress.default())); const args = [amountToTransfer, owner, insertFnSelector.toField(), getThenNullifyFnSelector.toField()]; const result = await runSimulator({ diff --git a/yarn-project/simulator/src/client/simulator.ts b/yarn-project/simulator/src/client/simulator.ts index 4c1e829c8e6..9d03629a0f9 100644 --- a/yarn-project/simulator/src/client/simulator.ts +++ b/yarn-project/simulator/src/client/simulator.ts @@ -70,7 +70,7 @@ export class AcirSimulator { entryPointArtifact: FunctionArtifactWithDebugMetadata, contractAddress: AztecAddress, portalContractAddress: EthAddress, - msgSender = AztecAddress.ZERO, + msgSender = AztecAddress.default(), ): Promise { if (entryPointArtifact.functionType !== FunctionType.SECRET) { throw new Error(`Cannot run ${entryPointArtifact.functionType} function as secret`); diff --git a/yarn-project/simulator/src/public/index.test.ts b/yarn-project/simulator/src/public/index.test.ts index 03f6a631f9b..a9202e73950 100644 --- a/yarn-project/simulator/src/public/index.test.ts +++ b/yarn-project/simulator/src/public/index.test.ts @@ -464,8 +464,8 @@ describe('ACIR public execution simulator', () => { new Fr(preimage.recipient.version), Fr.ZERO, Fr.ZERO, - EthAddress.ZERO, - AztecAddress.ZERO, + EthAddress.default(), + AztecAddress.default(), ); const mockOracles = (updateState = true) => { @@ -650,7 +650,7 @@ describe('ACIR public execution simulator', () => { callContext = CallContext.from({ msgSender: AztecAddress.random(), storageContractAddress: AztecAddress.random(), - portalContractAddress: EthAddress.ZERO, + portalContractAddress: EthAddress.default(), functionSelector: FunctionSelector.empty(), isDelegateCall: false, isStaticCall: false, @@ -733,7 +733,7 @@ describe('ACIR public execution simulator', () => { callContext = CallContext.from({ msgSender: AztecAddress.random(), storageContractAddress: AztecAddress.random(), - portalContractAddress: EthAddress.ZERO, + portalContractAddress: EthAddress.default(), functionSelector: FunctionSelector.empty(), isDelegateCall: false, isStaticCall: false, diff --git a/yarn-project/simulator/src/public/public_execution_context.ts b/yarn-project/simulator/src/public/public_execution_context.ts index ab54bf1c792..7305ed2bbe5 100644 --- a/yarn-project/simulator/src/public/public_execution_context.ts +++ b/yarn-project/simulator/src/public/public_execution_context.ts @@ -120,7 +120,7 @@ export class PublicExecutionContext extends TypedOracle { * @returns The portal contract address. */ public async getPortalContractAddress(contractAddress: AztecAddress) { - return (await this.contractsDb.getPortalContractAddress(contractAddress)) ?? EthAddress.ZERO; + return (await this.contractsDb.getPortalContractAddress(contractAddress)) ?? EthAddress.default(); } /** @@ -179,7 +179,7 @@ export class PublicExecutionContext extends TypedOracle { const args = this.packedArgsCache.unpack(argsHash); this.log(`Public function call: addr=${targetContractAddress} selector=${functionSelector} args=${args.join(',')}`); - const portalAddress = (await this.contractsDb.getPortalContractAddress(targetContractAddress)) ?? EthAddress.ZERO; + const portalAddress = (await this.contractsDb.getPortalContractAddress(targetContractAddress)) ?? EthAddress.default(); const acir = await this.contractsDb.getBytecode(targetContractAddress, functionSelector); if (!acir) { diff --git a/yarn-project/world-state/src/world-state-db/merkle_trees.ts b/yarn-project/world-state/src/world-state-db/merkle_trees.ts index 352d94e8fb7..e8af09367be 100644 --- a/yarn-project/world-state/src/world-state-db/merkle_trees.ts +++ b/yarn-project/world-state/src/world-state-db/merkle_trees.ts @@ -178,7 +178,7 @@ export class MerkleTrees implements MerkleTreeDb { public async buildInitialHeader(includeUncommitted: boolean): Promise
{ const state = await this.getStateReference(includeUncommitted); - return new Header(AppendOnlyTreeSnapshot.zero(), ContentCommitment.empty(), state, GlobalVariables.empty()); + return new Header(AppendOnlyTreeSnapshot.default(), ContentCommitment.default(), state, GlobalVariables.default()); } /** From 26e225a57c54860ed3f47d4b11edbe58cb895b9f Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Sun, 31 Mar 2024 15:04:36 +0000 Subject: [PATCH 14/77] Fix --- .../src/entrypoint/default_entrypoint.ts | 2 +- .../circuit-types/src/function_call.ts | 2 +- yarn-project/circuit-types/src/l2_block.ts | 6 +- .../src/logs/encrypted_l2_log.ts | 2 +- .../src/logs/function_l2_logs.ts | 8 +-- .../circuit-types/src/logs/tx_l2_logs.ts | 8 +-- .../circuit-types/src/messaging/l1_actor.ts | 2 +- .../src/messaging/l1_to_l2_message.ts | 4 +- .../circuit-types/src/messaging/l2_actor.ts | 2 +- yarn-project/circuit-types/src/mocks.ts | 10 +-- .../circuit-types/src/tx/processed_tx.ts | 18 +++--- yarn-project/circuit-types/src/tx/tx.ts | 8 +-- yarn-project/circuit-types/src/tx_effect.ts | 12 ++-- .../circuits.js/src/hash/hash.test.ts | 4 +- .../circuits.js/src/hints/build_hints.test.ts | 20 +++--- .../circuits.js/src/hints/build_hints.ts | 2 +- .../circuits.js/src/hints/utils.test.ts | 50 +++++++-------- yarn-project/circuits.js/src/hints/utils.ts | 12 ++-- .../src/structs/function_data.test.ts | 6 +- .../circuits.js/src/structs/header.test.ts | 2 +- .../kernel/combined_accumulated_data.test.ts | 8 +-- .../structs/kernel/combined_constant_data.ts | 4 +- ...vate_kernel_inner_circuit_public_inputs.ts | 8 +-- .../kernel/private_kernel_inner_data.ts | 4 +- ...ivate_kernel_tail_circuit_public_inputs.ts | 10 +-- .../kernel/private_kernel_tail_data.ts | 4 +- .../public_kernel_circuit_public_inputs.ts | 12 ++-- .../src/structs/kernel/public_kernel_data.ts | 4 +- .../rollup_kernel_circuit_public_inputs.ts | 8 +-- .../src/structs/kernel/rollup_kernel_data.ts | 4 +- .../non_existent_read_request_hints.ts | 16 ++--- .../structs/private_call_stack_item.test.ts | 2 +- .../src/structs/private_call_stack_item.ts | 4 +- .../private_circuit_public_inputs.test.ts | 8 +-- .../structs/private_circuit_public_inputs.ts | 33 ++-------- .../src/structs/public_call_request.ts | 4 +- .../structs/public_call_stack_item.test.ts | 4 +- .../src/structs/public_call_stack_item.ts | 2 +- .../public_circuit_public_inputs.test.ts | 10 +-- .../src/structs/read_request_hints.ts | 6 +- .../src/structs/rollup_validation_requests.ts | 4 +- .../src/structs/tx_context.test.ts | 8 +-- .../src/structs/tx_request.test.ts | 2 +- .../src/structs/validation_requests.ts | 14 ++--- .../src/e2e_crowdfunding_and_claim.test.ts | 2 +- .../src/integration_l1_publisher.test.ts | 4 +- .../src/simulators/lending_simulator.ts | 2 +- .../entrypoints/src/account_entrypoint.ts | 2 +- .../entrypoints/src/dapp_entrypoint.ts | 2 +- .../entrypoints/src/multi_call_entrypoint.ts | 2 +- .../foundation/src/abi/event_selector.ts | 2 +- .../foundation/src/eth-address/index.ts | 2 +- .../src/interfaces/indexed_tree.ts | 2 +- .../standard_indexed_tree.ts | 6 +- .../prover-client/src/dummy-prover.ts | 2 +- .../src/orchestrator/orchestrator.test.ts | 14 ++--- .../src/kernel_prover/kernel_prover.test.ts | 20 +++--- .../pxe/src/kernel_prover/kernel_prover.ts | 8 +-- .../src/pxe_service/test/pxe_test_suite.ts | 4 +- .../src/sequencer/abstract_phase_manager.ts | 20 +++--- .../src/sequencer/public_processor.test.ts | 62 +++++++++---------- .../src/sequencer/sequencer.test.ts | 2 +- .../src/sequencer/setup_phase_manager.test.ts | 8 +-- .../src/sequencer/tx_validator.test.ts | 10 +-- .../simulator/src/acvm/oracle/oracle.ts | 2 +- yarn-project/simulator/src/avm/avm_context.ts | 4 +- .../src/avm/avm_execution_environment.test.ts | 7 ++- .../src/avm/avm_execution_environment.ts | 6 +- .../simulator/src/avm/journal/nullifiers.ts | 3 +- .../src/avm/journal/public_storage.ts | 3 +- .../src/avm/opcodes/external_calls.ts | 6 +- .../src/avm/temporary_executor_migration.ts | 4 +- .../src/client/execution_result.test.ts | 36 +++++------ .../src/client/private_execution.test.ts | 2 +- .../simulator/src/client/simulator.ts | 2 +- .../client/unconstrained_execution.test.ts | 4 +- .../simulator/src/public/avm_executor.test.ts | 4 +- yarn-project/simulator/src/public/executor.ts | 2 +- .../simulator/src/public/index.test.ts | 40 ++++++------ 79 files changed, 321 insertions(+), 343 deletions(-) diff --git a/yarn-project/aztec.js/src/entrypoint/default_entrypoint.ts b/yarn-project/aztec.js/src/entrypoint/default_entrypoint.ts index 7315d4f6aa0..3567820d7ac 100644 --- a/yarn-project/aztec.js/src/entrypoint/default_entrypoint.ts +++ b/yarn-project/aztec.js/src/entrypoint/default_entrypoint.ts @@ -12,7 +12,7 @@ export class DefaultEntrypoint implements EntrypointInterface { createTxExecutionRequest(executions: FunctionCall[]): Promise { const [execution] = executions; const packedArguments = PackedArguments.fromArgs(execution.args); - const txContext = TxContext.empty(this.chainId, this.protocolVersion); + const txContext = TxContext.default(this.chainId, this.protocolVersion); return Promise.resolve( new TxExecutionRequest( execution.to, diff --git a/yarn-project/circuit-types/src/function_call.ts b/yarn-project/circuit-types/src/function_call.ts index 910dd804086..82d5229e30a 100644 --- a/yarn-project/circuit-types/src/function_call.ts +++ b/yarn-project/circuit-types/src/function_call.ts @@ -17,7 +17,7 @@ export type FunctionCall = { export function emptyFunctionCall() { return { to: AztecAddress.default(), - functionData: FunctionData.empty(), + functionData: FunctionData.default(), args: [], }; } diff --git a/yarn-project/circuit-types/src/l2_block.ts b/yarn-project/circuit-types/src/l2_block.ts index 29fbd2168b1..17400a73221 100644 --- a/yarn-project/circuit-types/src/l2_block.ts +++ b/yarn-project/circuit-types/src/l2_block.ts @@ -115,14 +115,14 @@ export class L2Block { } /** - * Creates an L2 block containing empty data. + * Creates an L2 block containing default (empty) data. * @returns The L2 block. */ - static empty(): L2Block { + static default(): L2Block { return L2Block.fromFields({ archive: AppendOnlyTreeSnapshot.default(), header: Header.default(), - body: Body.empty(), + body: Body.default(), }); } diff --git a/yarn-project/circuit-types/src/logs/encrypted_l2_log.ts b/yarn-project/circuit-types/src/logs/encrypted_l2_log.ts index 4e11c696d2f..09f75cb3639 100644 --- a/yarn-project/circuit-types/src/logs/encrypted_l2_log.ts +++ b/yarn-project/circuit-types/src/logs/encrypted_l2_log.ts @@ -54,7 +54,7 @@ export class EncryptedL2Log { return new EncryptedL2Log(data); } - public static empty() { + public static default() { return new EncryptedL2Log(Buffer.alloc(0)); } } diff --git a/yarn-project/circuit-types/src/logs/function_l2_logs.ts b/yarn-project/circuit-types/src/logs/function_l2_logs.ts index 12c44942915..9092c4566e5 100644 --- a/yarn-project/circuit-types/src/logs/function_l2_logs.ts +++ b/yarn-project/circuit-types/src/logs/function_l2_logs.ts @@ -59,10 +59,10 @@ export abstract class FunctionL2Logs { /** - * Creates an empty L2Logs object with no logs. + * Creates a default L2Logs object with no logs. * @returns A new FunctionL2Logs object with no logs. */ - public static empty(): EncryptedFunctionL2Logs { + public static default(): EncryptedFunctionL2Logs { return new EncryptedFunctionL2Logs([]); } @@ -109,10 +109,10 @@ export class EncryptedFunctionL2Logs extends FunctionL2Logs { export class UnencryptedFunctionL2Logs extends FunctionL2Logs { /** - * Creates an empty L2Logs object with no logs. + * Creates a default L2Logs object with no logs. * @returns A new FunctionL2Logs object with no logs. */ - public static empty(): UnencryptedFunctionL2Logs { + public static default(): UnencryptedFunctionL2Logs { return new UnencryptedFunctionL2Logs([]); } diff --git a/yarn-project/circuit-types/src/logs/tx_l2_logs.ts b/yarn-project/circuit-types/src/logs/tx_l2_logs.ts index 774e479cf65..d09fa05d365 100644 --- a/yarn-project/circuit-types/src/logs/tx_l2_logs.ts +++ b/yarn-project/circuit-types/src/logs/tx_l2_logs.ts @@ -99,8 +99,8 @@ export abstract class TxL2Logs { } export class UnencryptedTxL2Logs extends TxL2Logs { - /** Creates an empty instance. */ - public static empty() { + /** Creates an default instance. */ + public static default() { return new UnencryptedTxL2Logs([]); } @@ -148,8 +148,8 @@ export class UnencryptedTxL2Logs extends TxL2Logs { } export class EncryptedTxL2Logs extends TxL2Logs { - /** Creates an empty instance. */ - public static empty() { + /** Creates a default instance. */ + public static default() { return new EncryptedTxL2Logs([]); } diff --git a/yarn-project/circuit-types/src/messaging/l1_actor.ts b/yarn-project/circuit-types/src/messaging/l1_actor.ts index 03a3f7f7f39..f9652150abb 100644 --- a/yarn-project/circuit-types/src/messaging/l1_actor.ts +++ b/yarn-project/circuit-types/src/messaging/l1_actor.ts @@ -18,7 +18,7 @@ export class L1Actor { public readonly chainId: number, ) {} - static empty() { + static default() { return new L1Actor(EthAddress.default(), 0); } diff --git a/yarn-project/circuit-types/src/messaging/l1_to_l2_message.ts b/yarn-project/circuit-types/src/messaging/l1_to_l2_message.ts index 79980b07da4..6da6173edcc 100644 --- a/yarn-project/circuit-types/src/messaging/l1_to_l2_message.ts +++ b/yarn-project/circuit-types/src/messaging/l1_to_l2_message.ts @@ -62,8 +62,8 @@ export class L1ToL2Message { return L1ToL2Message.fromBuffer(buffer); } - static empty(): L1ToL2Message { - return new L1ToL2Message(L1Actor.empty(), L2Actor.empty(), Fr.ZERO, Fr.ZERO); + static default(): L1ToL2Message { + return new L1ToL2Message(L1Actor.default(), L2Actor.default(), Fr.ZERO, Fr.ZERO); } static random(): L1ToL2Message { diff --git a/yarn-project/circuit-types/src/messaging/l2_actor.ts b/yarn-project/circuit-types/src/messaging/l2_actor.ts index 364972662cf..5dbf0753404 100644 --- a/yarn-project/circuit-types/src/messaging/l2_actor.ts +++ b/yarn-project/circuit-types/src/messaging/l2_actor.ts @@ -18,7 +18,7 @@ export class L2Actor { public readonly version: number, ) {} - static empty() { + static default() { return new L2Actor(AztecAddress.default(), 0); } diff --git a/yarn-project/circuit-types/src/mocks.ts b/yarn-project/circuit-types/src/mocks.ts index 18700c91c16..3c293ec852d 100644 --- a/yarn-project/circuit-types/src/mocks.ts +++ b/yarn-project/circuit-types/src/mocks.ts @@ -25,7 +25,7 @@ import { Tx, TxHash } from './tx/index.js'; * Testing utility to create empty logs composed from a single empty log. */ export function makeEmptyLogs(): EncryptedTxL2Logs { - const functionLogs = [new EncryptedFunctionL2Logs([EncryptedL2Log.empty()])]; + const functionLogs = [new EncryptedFunctionL2Logs([EncryptedL2Log.default()])]; return new EncryptedTxL2Logs(functionLogs); } @@ -35,20 +35,20 @@ export const mockTx = (seed = 1, logs = true) => { const tx = new Tx( makePrivateKernelTailCircuitPublicInputs(seed), new Proof(Buffer.alloc(0)), - logs ? EncryptedTxL2Logs.random(8, 3) : EncryptedTxL2Logs.empty(), // 8 priv function invocations creating 3 encrypted logs each - logs ? UnencryptedTxL2Logs.random(11, 2) : UnencryptedTxL2Logs.empty(), // 8 priv + 3 pub function invocations creating 2 unencrypted logs each + logs ? EncryptedTxL2Logs.random(8, 3) : EncryptedTxL2Logs.default(), // 8 priv function invocations creating 3 encrypted logs each + logs ? UnencryptedTxL2Logs.random(11, 2) : UnencryptedTxL2Logs.default(), // 8 priv + 3 pub function invocations creating 2 unencrypted logs each times(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, makePublicCallRequest), ); tx.data.endNonRevertibleData.publicCallStack = [ tx.enqueuedPublicFunctionCalls[1].toCallRequest(), tx.enqueuedPublicFunctionCalls[0].toCallRequest(), - CallRequest.empty(), + CallRequest.default(), ]; tx.data.end.publicCallStack = makeTuple( MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, - i => tx.enqueuedPublicFunctionCalls[i + 2]?.toCallRequest() ?? CallRequest.empty(), + i => tx.enqueuedPublicFunctionCalls[i + 2]?.toCallRequest() ?? CallRequest.default(), ).reverse() as Tuple; return tx; diff --git a/yarn-project/circuit-types/src/tx/processed_tx.ts b/yarn-project/circuit-types/src/tx/processed_tx.ts index 410052f705a..63b11e18af9 100644 --- a/yarn-project/circuit-types/src/tx/processed_tx.ts +++ b/yarn-project/circuit-types/src/tx/processed_tx.ts @@ -119,7 +119,7 @@ export function getPreviousOutputAndProof( const publicKernelPublicInput = new PublicKernelCircuitPublicInputs( tx.data.aggregationObject, tx.data.rollupValidationRequests, - ValidationRequests.empty(), + ValidationRequests.default(), PublicAccumulatedNonRevertibleData.fromPrivateAccumulatedNonRevertibleData(tx.data.endNonRevertibleData), PublicAccumulatedRevertibleData.fromPrivateAccumulatedRevertibleData(tx.data.end), tx.data.constants, @@ -151,8 +151,8 @@ export function makeProcessedTx( hash: tx.getTxHash(), data: publicKernelPublicInput, proof: previousProof, - encryptedLogs: revertReason ? EncryptedTxL2Logs.empty() : tx.encryptedLogs, - unencryptedLogs: revertReason ? UnencryptedTxL2Logs.empty() : tx.unencryptedLogs, + encryptedLogs: revertReason ? EncryptedTxL2Logs.default() : tx.encryptedLogs, + unencryptedLogs: revertReason ? UnencryptedTxL2Logs.default() : tx.unencryptedLogs, isEmpty: false, revertReason, }; @@ -163,7 +163,7 @@ export function makeProcessedTx( * @returns A processed empty tx. */ export function makeEmptyProcessedTx(header: Header, chainId: Fr, version: Fr): ProcessedTx { - const emptyKernelOutput = PublicKernelCircuitPublicInputs.empty(); + const emptyKernelOutput = PublicKernelCircuitPublicInputs.default(); emptyKernelOutput.constants.historicalHeader = header; emptyKernelOutput.constants.txContext.chainId = chainId; emptyKernelOutput.constants.txContext.version = version; @@ -172,8 +172,8 @@ export function makeEmptyProcessedTx(header: Header, chainId: Fr, version: Fr): const hash = new TxHash(Fr.ZERO.toBuffer()); return { hash, - encryptedLogs: EncryptedTxL2Logs.empty(), - unencryptedLogs: UnencryptedTxL2Logs.empty(), + encryptedLogs: EncryptedTxL2Logs.default(), + unencryptedLogs: UnencryptedTxL2Logs.default(), data: emptyKernelOutput, proof: emptyProof, isEmpty: true, @@ -194,13 +194,13 @@ export function toTxEffect(tx: ProcessedTx): TxEffect { PublicDataWrite, typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX >, - tx.encryptedLogs || EncryptedTxL2Logs.empty(), - tx.unencryptedLogs || UnencryptedTxL2Logs.empty(), + tx.encryptedLogs || EncryptedTxL2Logs.default(), + tx.unencryptedLogs || UnencryptedTxL2Logs.default(), ); } function validateProcessedTxLogs(tx: ProcessedTx): void { - const unencryptedLogs = tx.unencryptedLogs || UnencryptedTxL2Logs.empty(); + const unencryptedLogs = tx.unencryptedLogs || UnencryptedTxL2Logs.default(); const kernelUnencryptedLogsHash = tx.data.combinedData.unencryptedLogsHash; const referenceHash = Fr.fromBuffer(unencryptedLogs.hash()); if (!referenceHash.equals(kernelUnencryptedLogsHash)) { diff --git a/yarn-project/circuit-types/src/tx/tx.ts b/yarn-project/circuit-types/src/tx/tx.ts index e99b348ad13..d71fe3d2ad5 100644 --- a/yarn-project/circuit-types/src/tx/tx.ts +++ b/yarn-project/circuit-types/src/tx/tx.ts @@ -155,12 +155,12 @@ export class Tx { unencryptedLogSize: this.unencryptedLogs.getSerializedLength(), newCommitmentCount: - arrayNonEmptyLength(this.data!.endNonRevertibleData.newNoteHashes, SideEffect.isEmpty) + - arrayNonEmptyLength(this.data!.end.newNoteHashes, SideEffect.isEmpty), + arrayNonEmptyLength(this.data!.endNonRevertibleData.newNoteHashes, SideEffect.isDefault) + + arrayNonEmptyLength(this.data!.end.newNoteHashes, SideEffect.isDefault), newNullifierCount: - arrayNonEmptyLength(this.data!.endNonRevertibleData.newNullifiers, SideEffectLinkedToNoteHash.isEmpty) + - arrayNonEmptyLength(this.data!.end.newNullifiers, SideEffectLinkedToNoteHash.isEmpty), + arrayNonEmptyLength(this.data!.endNonRevertibleData.newNullifiers, SideEffectLinkedToNoteHash.isDefault) + + arrayNonEmptyLength(this.data!.end.newNullifiers, SideEffectLinkedToNoteHash.isDefault), proofSize: this.proof.buffer.length, size: this.toBuffer().length, diff --git a/yarn-project/circuit-types/src/tx_effect.ts b/yarn-project/circuit-types/src/tx_effect.ts index 90ea92e81df..bbecc8d2f94 100644 --- a/yarn-project/circuit-types/src/tx_effect.ts +++ b/yarn-project/circuit-types/src/tx_effect.ts @@ -85,7 +85,7 @@ export class TxEffect { padArrayEnd(nonZeroNoteHashes, Fr.ZERO, MAX_NEW_NOTE_HASHES_PER_TX), padArrayEnd(nonZeroNullifiers, Fr.ZERO, MAX_NEW_NULLIFIERS_PER_TX), padArrayEnd(nonZeroL2ToL1Msgs, Fr.ZERO, MAX_NEW_L2_TO_L1_MSGS_PER_TX), - padArrayEnd(nonZeroPublicDataWrites, PublicDataWrite.empty(), MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX), + padArrayEnd(nonZeroPublicDataWrites, PublicDataWrite.default(), MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX), EncryptedTxL2Logs.fromBuffer(reader), UnencryptedTxL2Logs.fromBuffer(reader), ); @@ -107,7 +107,7 @@ export class TxEffect { const newL2ToL1MsgsBuffer = Buffer.concat(this.l2ToL1Msgs.map(x => x.toBuffer())); assertLength(this.publicDataWrites, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX); - assertRightPadded(this.publicDataWrites, PublicDataWrite.isEmpty); + assertRightPadded(this.publicDataWrites, PublicDataWrite.isDefault); const publicDataUpdateRequestsBuffer = Buffer.concat(this.publicDataWrites.map(x => x.toBuffer())); const encryptedLogsHashKernel0 = this.encryptedLogs.hash(); const unencryptedLogsHashKernel0 = this.unencryptedLogs.hash(); @@ -142,15 +142,15 @@ export class TxEffect { ); } - static empty(): TxEffect { + static default(): TxEffect { return new TxEffect( RevertCode.OK, makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, Fr.zero), makeTuple(MAX_NEW_NULLIFIERS_PER_TX, Fr.zero), makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), - makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite.empty), - EncryptedTxL2Logs.empty(), - UnencryptedTxL2Logs.empty(), + makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite.default), + EncryptedTxL2Logs.default(), + UnencryptedTxL2Logs.default(), ); } diff --git a/yarn-project/circuits.js/src/hash/hash.test.ts b/yarn-project/circuits.js/src/hash/hash.test.ts index ce91f4c10d7..650fd8b0c59 100644 --- a/yarn-project/circuits.js/src/hash/hash.test.ts +++ b/yarn-project/circuits.js/src/hash/hash.test.ts @@ -90,14 +90,14 @@ describe('hash', () => { }); it('Computes an empty nullifier hash ', () => { - const emptyNull = SideEffectLinkedToNoteHash.empty(); + const emptyNull = SideEffectLinkedToNoteHash.default(); const emptyHash = computeNullifierHash(emptyNull).toString(); expect(emptyHash).toMatchSnapshot(); }); it('Computes an empty sideeffect hash ', () => { - const emptySideEffect = SideEffect.empty(); + const emptySideEffect = SideEffect.default(); const emptyHash = computeCommitmentsHash(emptySideEffect).toString(); expect(emptyHash).toMatchSnapshot(); }); diff --git a/yarn-project/circuits.js/src/hints/build_hints.test.ts b/yarn-project/circuits.js/src/hints/build_hints.test.ts index 9db861afe55..24391108925 100644 --- a/yarn-project/circuits.js/src/hints/build_hints.test.ts +++ b/yarn-project/circuits.js/src/hints/build_hints.test.ts @@ -77,9 +77,9 @@ describe('buildNullifierReadRequestHints', () => { const buildHints = () => buildNullifierReadRequestHints(oracle, nullifierReadRequests, nullifiers); beforeEach(() => { - nullifierReadRequests = makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_TX, ReadRequestContext.empty); + nullifierReadRequests = makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_TX, ReadRequestContext.default); nullifiers = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, i => makeNullifier(innerNullifier(i))); - expectedHints = NullifierReadRequestHintsBuilder.empty(); + expectedHints = NullifierReadRequestHintsBuilder.default(); numReadRequests = 0; numPendingReads = 0; numSettledReads = 0; @@ -125,8 +125,8 @@ describe('buildNullifierNonExistentReadRequestHints', () => { const oracle = { getLowNullifierMembershipWitness: () => ({ membershipWitness: {}, leafPreimage: {} } as any), }; - const nonExistentReadRequests = makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_TX, ReadRequestContext.empty); - let nullifiers = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.empty); + const nonExistentReadRequests = makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_TX, ReadRequestContext.default); + let nullifiers = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default); const innerNullifier = (index: number) => index + 1; @@ -145,7 +145,7 @@ describe('buildNullifierNonExistentReadRequestHints', () => { const populateNullifiers = (numNullifiers = MAX_NEW_NULLIFIERS_PER_TX) => { nullifiers = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, i => - i < numNullifiers ? makeNullifier(innerNullifier(i)) : SideEffectLinkedToNoteHash.empty(), + i < numNullifiers ? makeNullifier(innerNullifier(i)) : SideEffectLinkedToNoteHash.default(), ); }; @@ -163,9 +163,9 @@ describe('buildNullifierNonExistentReadRequestHints', () => { const buildHints = () => buildNullifierNonExistentReadRequestHints(oracle, nonExistentReadRequests, nullifiers); - it('builds empty hints', async () => { + it('builds default hints', async () => { const hints = await buildHints(); - const emptyHints = NullifierNonExistentReadRequestHintsBuilder.empty(); + const emptyHints = NullifierNonExistentReadRequestHintsBuilder.default(); expect(hints).toEqual(emptyHints); }); @@ -192,7 +192,7 @@ describe('buildNullifierNonExistentReadRequestHints', () => { // The first half contains sorted values. for (let i = 0; i < numNonEmptyNullifiers - 1; ++i) { - expect(sortedPendingValues[i]).not.toEqual(SideEffectLinkedToNoteHash.empty()); + expect(sortedPendingValues[i]).not.toEqual(SideEffectLinkedToNoteHash.default()); expect(sortedPendingValues[i].value.lt(sortedPendingValues[i + 1].value)).toBe(true); } for (let i = 0; i < numNonEmptyNullifiers; ++i) { @@ -202,7 +202,7 @@ describe('buildNullifierNonExistentReadRequestHints', () => { // The second half is empty. for (let i = numNonEmptyNullifiers; i < sortedPendingValues.length; ++i) { - expect(sortedPendingValues[i]).toEqual(SideEffectLinkedToNoteHash.empty()); + expect(sortedPendingValues[i]).toEqual(SideEffectLinkedToNoteHash.default()); } for (let i = numNonEmptyNullifiers; i < sortedPendingValueHints.length; ++i) { expect(sortedPendingValueHints[i]).toBe(0); @@ -224,7 +224,7 @@ describe('buildNullifierNonExistentReadRequestHints', () => { nonExistentReadRequests[2] = makeReadRequest(minNullifier.value); nullifiers = padArrayEnd( sortedNullifiers.map(n => makeNullifier(n.value)), - SideEffectLinkedToNoteHash.empty(), + SideEffectLinkedToNoteHash.default(), MAX_NEW_NULLIFIERS_PER_TX, ); diff --git a/yarn-project/circuits.js/src/hints/build_hints.ts b/yarn-project/circuits.js/src/hints/build_hints.ts index c22df8b15fe..befc034c5de 100644 --- a/yarn-project/circuits.js/src/hints/build_hints.ts +++ b/yarn-project/circuits.js/src/hints/build_hints.ts @@ -82,7 +82,7 @@ function sortNullifiersByValues( return { sortedValues: padArrayEnd( sorted.map(s => s.nullifier), - SideEffectLinkedToNoteHash.empty(), + SideEffectLinkedToNoteHash.default(), MAX_NEW_NULLIFIERS_PER_TX, ), sortedIndexHints: padArrayEnd(sortedIndexHints, 0, MAX_NEW_NULLIFIERS_PER_TX), diff --git a/yarn-project/circuits.js/src/hints/utils.test.ts b/yarn-project/circuits.js/src/hints/utils.test.ts index e5897e30a87..fc66385699b 100644 --- a/yarn-project/circuits.js/src/hints/utils.test.ts +++ b/yarn-project/circuits.js/src/hints/utils.test.ts @@ -1,4 +1,4 @@ -import { IsEmpty } from '@aztec/circuits.js'; +import { IsDefault } from '@aztec/circuits.js'; import { makeTuple } from '@aztec/foundation/array'; import { Tuple } from '@aztec/foundation/serialize'; @@ -7,23 +7,23 @@ import { concatAccumulatedData, countAccumulatedItems, mergeAccumulatedData } fr class TestItem { constructor(public value: number) {} - static empty() { + static default() { return new TestItem(0); } - isEmpty() { + isDefault() { return this.value === 0; } } describe('hints utils', () => { - const expectEmptyArrays = (arr: IsEmpty[]) => { - arr.forEach(item => expect(item.isEmpty()).toBe(true)); + const expectDefaultArrays = (arr: IsDefault[]) => { + arr.forEach(item => expect(item.isDefault()).toBe(true)); }; describe('countAccumulatedItems', () => { - it('counts the number of non-empty items', () => { - const arr = makeTuple(20, TestItem.empty); + it('counts the number of non-default items', () => { + const arr = makeTuple(20, TestItem.default); const num = 6; for (let i = 0; i < num; ++i) { arr[i] = new TestItem(i + 1); @@ -31,10 +31,10 @@ describe('hints utils', () => { expect(countAccumulatedItems(arr)).toBe(num); }); - it('throws if arr contains non-continuous non-empty items', () => { - const arr = makeTuple(20, TestItem.empty); + it('throws if arr contains non-continuous non-default items', () => { + const arr = makeTuple(20, TestItem.default); arr[1] = new TestItem(123); - expect(() => countAccumulatedItems(arr)).toThrow('Non-empty items must be placed continuously from index 0.'); + expect(() => countAccumulatedItems(arr)).toThrow('Non-default items must be placed continuously from index 0.'); }); }); @@ -44,8 +44,8 @@ describe('hints utils', () => { let arr1: Tuple; beforeEach(() => { - arr0 = makeTuple(length, TestItem.empty); - arr1 = makeTuple(length, TestItem.empty); + arr0 = makeTuple(length, TestItem.default); + arr1 = makeTuple(length, TestItem.default); }); it('propagates items from arr0', () => { @@ -53,7 +53,7 @@ describe('hints utils', () => { arr0[1] = new TestItem(34); const res = mergeAccumulatedData(length, arr0, arr1); expect(res.slice(0, 2)).toEqual([arr0[0], arr0[1]]); - expectEmptyArrays(res.slice(2)); + expectDefaultArrays(res.slice(2)); }); it('propagates items from arr1', () => { @@ -61,7 +61,7 @@ describe('hints utils', () => { arr1[1] = new TestItem(2); const res = mergeAccumulatedData(length, arr0, arr1); expect(res.slice(0, 2)).toEqual([arr1[0], arr1[1]]); - expectEmptyArrays(res.slice(2)); + expectDefaultArrays(res.slice(2)); }); it('merges items from both arrays', () => { @@ -71,14 +71,14 @@ describe('hints utils', () => { arr1[1] = new TestItem(2); const res = mergeAccumulatedData(length, arr0, arr1); expect(res.slice(0, 4)).toEqual([arr0[0], arr0[1], arr1[0], arr1[1]]); - expectEmptyArrays(res.slice(4)); + expectDefaultArrays(res.slice(4)); }); it('throws if arr0 contains non-continuous items', () => { arr0[0] = new TestItem(12); arr0[2] = new TestItem(34); expect(() => mergeAccumulatedData(length, arr0, arr1)).toThrow( - 'Non-empty items must be placed continuously from index 0.', + 'Non-default items must be placed continuously from index 0.', ); }); @@ -86,7 +86,7 @@ describe('hints utils', () => { arr1[0] = new TestItem(12); arr1[2] = new TestItem(34); expect(() => mergeAccumulatedData(length, arr0, arr1)).toThrow( - 'Non-empty items must be placed continuously from index 0.', + 'Non-default items must be placed continuously from index 0.', ); }); @@ -98,7 +98,7 @@ describe('hints utils', () => { arr1[0] = new TestItem(1234); expect(() => mergeAccumulatedData(length, arr0, arr1)).toThrow( - 'Combined non-empty items exceeded the maximum allowed.', + 'Combined non-default items exceeded the maximum allowed.', ); }); }); @@ -111,8 +111,8 @@ describe('hints utils', () => { let arr1: Tuple; beforeEach(() => { - arr0 = makeTuple(length0, TestItem.empty); - arr1 = makeTuple(length1, TestItem.empty); + arr0 = makeTuple(length0, TestItem.default); + arr1 = makeTuple(length1, TestItem.default); }); it('propagates items from arr0', () => { @@ -120,7 +120,7 @@ describe('hints utils', () => { arr0[1] = new TestItem(34); const nullifiers = concatAccumulatedData(length, arr0, arr1); expect(nullifiers.slice(0, 2)).toEqual([arr0[0], arr0[1]]); - expectEmptyArrays(nullifiers.slice(2)); + expectDefaultArrays(nullifiers.slice(2)); }); it('propagates items from arr1', () => { @@ -128,7 +128,7 @@ describe('hints utils', () => { arr1[1] = new TestItem(2); const nullifiers = concatAccumulatedData(length, arr0, arr1); expect(nullifiers.slice(0, 2)).toEqual([arr1[0], arr1[1]]); - expectEmptyArrays(nullifiers.slice(2)); + expectDefaultArrays(nullifiers.slice(2)); }); it('combines items from both arrays', () => { @@ -138,7 +138,7 @@ describe('hints utils', () => { arr1[1] = new TestItem(2); const nullifiers = concatAccumulatedData(length, arr0, arr1); expect(nullifiers.slice(0, 4)).toEqual([arr0[0], arr0[1], arr1[0], arr1[1]]); - expectEmptyArrays(nullifiers.slice(4)); + expectDefaultArrays(nullifiers.slice(4)); }); it('combines all items from both arrays', () => { @@ -158,7 +158,7 @@ describe('hints utils', () => { arr0[0] = new TestItem(12); arr0[2] = new TestItem(34); expect(() => concatAccumulatedData(length, arr0, arr1)).toThrow( - 'Non-empty items must be placed continuously from index 0.', + 'Non-default items must be placed continuously from index 0.', ); }); @@ -166,7 +166,7 @@ describe('hints utils', () => { arr1[0] = new TestItem(12); arr1[2] = new TestItem(34); expect(() => concatAccumulatedData(length, arr0, arr1)).toThrow( - 'Non-empty items must be placed continuously from index 0.', + 'Non-default items must be placed continuously from index 0.', ); }); }); diff --git a/yarn-project/circuits.js/src/hints/utils.ts b/yarn-project/circuits.js/src/hints/utils.ts index d98de228d7d..9799f217a31 100644 --- a/yarn-project/circuits.js/src/hints/utils.ts +++ b/yarn-project/circuits.js/src/hints/utils.ts @@ -1,15 +1,15 @@ import { Tuple } from '@aztec/foundation/serialize'; -export interface IsEmpty { - isEmpty: () => boolean; +export interface IsDefault { + isDefault: () => boolean; } // Define these utils here as their design is very specific to kernel's accumulated data and not general enough to be put in foundation. // Returns number of non-empty items in an array. -export function countAccumulatedItems(arr: T[]) { +export function countAccumulatedItems(arr: T[]) { return arr.reduce((num, item, i) => { - if (!item.isEmpty()) { + if (!item.isDefault()) { if (num !== i) { throw new Error('Non-empty items must be placed continuously from index 0.'); } @@ -20,7 +20,7 @@ export function countAccumulatedItems(arr: T[]) { } // Merges two arrays of length N into an array of length N. -export function mergeAccumulatedData( +export function mergeAccumulatedData( _length: N, arr0: Tuple, arr1: Tuple, @@ -38,7 +38,7 @@ export function mergeAccumulatedData( // Combines an array of length N and an array of length M into an array of length N + M. // All non-empty items are aggregated continuously from index 0. -export function concatAccumulatedData( +export function concatAccumulatedData( length: NM, arr0: Tuple, arr1: Tuple, diff --git a/yarn-project/circuits.js/src/structs/function_data.test.ts b/yarn-project/circuits.js/src/structs/function_data.test.ts index 12ab5a5cd1b..b7abcd3b1c1 100644 --- a/yarn-project/circuits.js/src/structs/function_data.test.ts +++ b/yarn-project/circuits.js/src/structs/function_data.test.ts @@ -16,7 +16,7 @@ describe('FunctionData', () => { const buffer = functionData.toBuffer(); const res = FunctionData.fromBuffer(buffer); expect(res).toEqual(functionData); - expect(res.isEmpty()).toBe(false); + expect(res.isDefault()).toBe(false); }); it('number of fields matches constant', () => { @@ -24,8 +24,8 @@ describe('FunctionData', () => { expect(fields.length).toBe(FUNCTION_DATA_LENGTH); }); - it('computes empty inputs hash', () => { - const data = FunctionData.empty(); + it('computes default inputs hash', () => { + const data = FunctionData.default(); const hash = data.hash(); expect(hash).toMatchSnapshot(); diff --git a/yarn-project/circuits.js/src/structs/header.test.ts b/yarn-project/circuits.js/src/structs/header.test.ts index 352acf4c681..a67b7ebe801 100644 --- a/yarn-project/circuits.js/src/structs/header.test.ts +++ b/yarn-project/circuits.js/src/structs/header.test.ts @@ -38,7 +38,7 @@ describe('Header', () => { }); it('computes empty hash', () => { - const header = Header.empty(); + const header = Header.default(); const hash = header.hash(); expect(hash).toMatchSnapshot(); diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.test.ts b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.test.ts index 474cd34b77d..95ccfc53492 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.test.ts +++ b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.test.ts @@ -15,12 +15,12 @@ describe('CombinedAccumulatedData', () => { }); it('recombines notes correctly', () => { - const nonRevertible = PublicAccumulatedNonRevertibleData.empty(); + const nonRevertible = PublicAccumulatedNonRevertibleData.default(); nonRevertible.newNoteHashes[0].counter = new Fr(1); // a note created in private fee setup nonRevertible.newNoteHashes[1].counter = new Fr(5); // a note created in public setup nonRevertible.newNoteHashes[2].counter = new Fr(10); // a note created in public teardown - const end = PublicAccumulatedRevertibleData.empty(); + const end = PublicAccumulatedRevertibleData.default(); end.newNoteHashes[0].counter = new Fr(2); // a note created in private app logic end.newNoteHashes[1].counter = new Fr(8); // a note created in public app logic @@ -30,12 +30,12 @@ describe('CombinedAccumulatedData', () => { }); it('recombines nullifiers correctly', () => { - const nonRevertible = PublicAccumulatedNonRevertibleData.empty(); + const nonRevertible = PublicAccumulatedNonRevertibleData.default(); nonRevertible.newNullifiers[0].counter = new Fr(1); // a nullifier created in private fee setup nonRevertible.newNullifiers[1].counter = new Fr(5); // a nullifier created in public setup nonRevertible.newNullifiers[2].counter = new Fr(10); // a nullifier created in public teardown - const end = PublicAccumulatedRevertibleData.empty(); + const end = PublicAccumulatedRevertibleData.default(); end.newNullifiers[0].counter = new Fr(2); // a nullifier created in private app logic end.newNullifiers[1].counter = new Fr(8); // a nullifier created in public app logic diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts b/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts index 189d6a27764..1130e003f64 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts @@ -37,7 +37,7 @@ export class CombinedConstantData { return new CombinedConstantData(reader.readObject(Header), reader.readObject(TxContext)); } - static empty() { - return new CombinedConstantData(Header.empty(), TxContext.empty()); + static default() { + return new CombinedConstantData(Header.default(), TxContext.default()); } } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_inner_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_inner_circuit_public_inputs.ts index 55152cb8fd1..76795990223 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_inner_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_inner_circuit_public_inputs.ts @@ -65,13 +65,13 @@ export class PrivateKernelInnerCircuitPublicInputs { ); } - static empty() { + static default() { return new PrivateKernelInnerCircuitPublicInputs( AggregationObject.makeFake(), Fr.zero(), - ValidationRequests.empty(), - CombinedAccumulatedData.empty(), - CombinedConstantData.empty(), + ValidationRequests.default(), + CombinedAccumulatedData.default(), + CombinedConstantData.default(), true, ); } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_inner_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_inner_data.ts index ab18c8460a0..38c22a8419f 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_inner_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_inner_data.ts @@ -54,9 +54,9 @@ export class PrivateKernelInnerData { ); } - static empty(): PrivateKernelInnerData { + static default(): PrivateKernelInnerData { return new PrivateKernelInnerData( - PrivateKernelInnerCircuitPublicInputs.empty(), + PrivateKernelInnerCircuitPublicInputs.default(), makeEmptyProof(), VerificationKey.makeFake(), 0, diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts index 2429a6f71cc..94c90036327 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts @@ -76,13 +76,13 @@ export class PrivateKernelTailCircuitPublicInputs { ); } - static empty() { + static default() { return new PrivateKernelTailCircuitPublicInputs( AggregationObject.makeFake(), - RollupValidationRequests.empty(), - PrivateAccumulatedNonRevertibleData.empty(), - PrivateAccumulatedRevertibleData.empty(), - CombinedConstantData.empty(), + RollupValidationRequests.default(), + PrivateAccumulatedNonRevertibleData.default(), + PrivateAccumulatedRevertibleData.default(), + CombinedConstantData.default(), true, true, true, diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_data.ts index 52afd0a3efd..f704101a0a9 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_data.ts @@ -46,9 +46,9 @@ export class PrivateKernelTailData { ); } - static empty(): PrivateKernelTailData { + static default(): PrivateKernelTailData { return new this( - PrivateKernelTailCircuitPublicInputs.empty(), + PrivateKernelTailCircuitPublicInputs.default(), makeEmptyProof(), VerificationKey.makeFake(), 0, diff --git a/yarn-project/circuits.js/src/structs/kernel/public_kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/public_kernel_circuit_public_inputs.ts index a6d6f1b5298..dbd0c218321 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_kernel_circuit_public_inputs.ts @@ -103,14 +103,14 @@ export class PublicKernelCircuitPublicInputs { ); } - static empty() { + static default() { return new PublicKernelCircuitPublicInputs( AggregationObject.makeFake(), - RollupValidationRequests.empty(), - ValidationRequests.empty(), - PublicAccumulatedNonRevertibleData.empty(), - PublicAccumulatedRevertibleData.empty(), - CombinedConstantData.empty(), + RollupValidationRequests.default(), + ValidationRequests.default(), + PublicAccumulatedNonRevertibleData.default(), + PublicAccumulatedRevertibleData.default(), + CombinedConstantData.default(), false, false, false, diff --git a/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts b/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts index 2dfcb7fe992..f515d69d85e 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts @@ -46,9 +46,9 @@ export class PublicKernelData { ); } - static empty(): PublicKernelData { + static default(): PublicKernelData { return new this( - PublicKernelCircuitPublicInputs.empty(), + PublicKernelCircuitPublicInputs.default(), makeEmptyProof(), VerificationKey.makeFake(), 0, diff --git a/yarn-project/circuits.js/src/structs/kernel/rollup_kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/rollup_kernel_circuit_public_inputs.ts index 9b973842448..f59e5e2326c 100644 --- a/yarn-project/circuits.js/src/structs/kernel/rollup_kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/rollup_kernel_circuit_public_inputs.ts @@ -48,12 +48,12 @@ export class RollupKernelCircuitPublicInputs { ); } - static empty() { + static default() { return new RollupKernelCircuitPublicInputs( AggregationObject.makeFake(), - CombinedAccumulatedData.empty(), - CombinedConstantData.empty(), - RollupValidationRequests.empty(), + CombinedAccumulatedData.default(), + CombinedConstantData.default(), + RollupValidationRequests.default(), ); } } diff --git a/yarn-project/circuits.js/src/structs/kernel/rollup_kernel_data.ts b/yarn-project/circuits.js/src/structs/kernel/rollup_kernel_data.ts index 9945403bdcc..1be02b9d1ce 100644 --- a/yarn-project/circuits.js/src/structs/kernel/rollup_kernel_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/rollup_kernel_data.ts @@ -46,9 +46,9 @@ export class RollupKernelData { ); } - static empty(): RollupKernelData { + static default(): RollupKernelData { return new this( - RollupKernelCircuitPublicInputs.empty(), + RollupKernelCircuitPublicInputs.default(), makeEmptyProof(), VerificationKey.makeFake(), 0, diff --git a/yarn-project/circuits.js/src/structs/non_existent_read_request_hints.ts b/yarn-project/circuits.js/src/structs/non_existent_read_request_hints.ts index 9cd254bc0b9..4c9ee2aadea 100644 --- a/yarn-project/circuits.js/src/structs/non_existent_read_request_hints.ts +++ b/yarn-project/circuits.js/src/structs/non_existent_read_request_hints.ts @@ -14,11 +14,11 @@ import { SideEffectLinkedToNoteHash, SideEffectType } from './side_effects.js'; export class NonMembershipHint { constructor(public membershipWitness: MembershipWitness, public leafPreimage: LEAF_PREIMAGE) {} - static empty( + static default( treeHeight: TREE_HEIGHT, makeEmptyLeafPreimage: () => LEAF_PREIMAGE, ) { - return new NonMembershipHint(MembershipWitness.empty(treeHeight, 0n), makeEmptyLeafPreimage()); + return new NonMembershipHint(MembershipWitness.default(treeHeight, 0n), makeEmptyLeafPreimage()); } static fromBuffer( @@ -119,7 +119,7 @@ export class NullifierNonExistentReadRequestHintsBuilder { ) { this.hints = new NonExistentReadRequestHints( makeTuple(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, () => - NonMembershipHint.empty(NULLIFIER_TREE_HEIGHT, NullifierLeafPreimage.empty), + NonMembershipHint.default(NULLIFIER_TREE_HEIGHT, NullifierLeafPreimage.default), ), makeTuple(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, () => 0), sortedPendingNullifiers, @@ -127,12 +127,12 @@ export class NullifierNonExistentReadRequestHintsBuilder { ); } - static empty() { - const emptySortedPendingNullifiers = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.empty); - const emptySortedPendingNullifierIndexHints = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, () => 0); + static default() { + const defaultSortedPendingNullifiers = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default); + const defaultSortedPendingNullifierIndexHints = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, () => 0); return new NullifierNonExistentReadRequestHintsBuilder( - emptySortedPendingNullifiers, - emptySortedPendingNullifierIndexHints, + defaultSortedPendingNullifiers, + defaultSortedPendingNullifierIndexHints, ).toHints(); } diff --git a/yarn-project/circuits.js/src/structs/private_call_stack_item.test.ts b/yarn-project/circuits.js/src/structs/private_call_stack_item.test.ts index 39d2b062661..d7c979433c7 100644 --- a/yarn-project/circuits.js/src/structs/private_call_stack_item.test.ts +++ b/yarn-project/circuits.js/src/structs/private_call_stack_item.test.ts @@ -38,7 +38,7 @@ describe('PrivateCallStackItem', () => { }); it('computes empty item hash', () => { - const item = PrivateCallStackItem.empty(); + const item = PrivateCallStackItem.default(); const hash = item.hash(); expect(hash).toMatchSnapshot(); diff --git a/yarn-project/circuits.js/src/structs/private_call_stack_item.ts b/yarn-project/circuits.js/src/structs/private_call_stack_item.ts index 8cf340466f1..0c99a51d8e4 100644 --- a/yarn-project/circuits.js/src/structs/private_call_stack_item.ts +++ b/yarn-project/circuits.js/src/structs/private_call_stack_item.ts @@ -74,11 +74,11 @@ export class PrivateCallStackItem { * Returns a new instance of PrivateCallStackItem with zero contract address, function data and public inputs. * @returns A new instance of PrivateCallStackItem with zero contract address, function data and public inputs. */ - public static empty(): PrivateCallStackItem { + public static default(): PrivateCallStackItem { return new PrivateCallStackItem( AztecAddress.default(), FunctionData.default({ isPrivate: true }), - PrivateCircuitPublicInputs.empty(), + PrivateCircuitPublicInputs.default(), ); } diff --git a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.test.ts b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.test.ts index 223daf96762..5d0e74eb57f 100644 --- a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.test.ts +++ b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.test.ts @@ -25,9 +25,9 @@ describe('PrivateCircuitPublicInputs', () => { expect(result).toEqual(inputs); }); - it(`initializes an empty PrivateCircuitPublicInputs`, () => { - const target = PrivateCircuitPublicInputs.empty(); - expect(target.isEmpty()).toBe(true); + it(`initializes a default PrivateCircuitPublicInputs`, () => { + const target = PrivateCircuitPublicInputs.default(); + expect(target.isDefault()).toBe(true); }); it('number of fields matches constant', () => { @@ -42,7 +42,7 @@ describe('PrivateCircuitPublicInputs', () => { }); it('computes empty inputs hash', () => { - const inputs = PrivateCircuitPublicInputs.empty(); + const inputs = PrivateCircuitPublicInputs.default(); const hash = inputs.hash(); expect(hash).toMatchSnapshot(); diff --git a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts index fc43bd610ec..cb62e25bf31 100644 --- a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts @@ -204,10 +204,10 @@ export class PrivateCircuitPublicInputs { } /** - * Create an empty PrivateCircuitPublicInputs. - * @returns An empty PrivateCircuitPublicInputs object. + * Create a default PrivateCircuitPublicInputs. + * @returns A default PrivateCircuitPublicInputs object. */ - public static empty(): PrivateCircuitPublicInputs { + public static default(): PrivateCircuitPublicInputs { return new PrivateCircuitPublicInputs( CallContext.default(), Fr.ZERO, @@ -235,32 +235,7 @@ export class PrivateCircuitPublicInputs { } isDefault() { - // eslint-disable-next-line jsdoc/require-jsdoc - const isDefaultArray = (arr: { isDefault: (...args: any[]) => boolean }[]) => isArrayEmpty(arr, item => item.isDefault()); - // eslint-disable-next-line jsdoc/require-jsdoc - const isZeroArray = (arr: { isZero: (...args: any[]) => boolean }[]) => isArrayEmpty(arr, item => item.isZero()); - return ( - this.callContext.isDefault() && - this.argsHash.isZero() && - isZeroArray(this.returnValues) && - this.minRevertibleSideEffectCounter.isZero() && - this.maxBlockNumber.isDefault() && - isDefaultArray(this.noteHashReadRequests) && - isDefaultArray(this.nullifierReadRequests) && - isDefaultArray(this.nullifierKeyValidationRequests) && - isDefaultArray(this.newNoteHashes) && - isDefaultArray(this.newNullifiers) && - isZeroArray(this.privateCallStackHashes) && - isZeroArray(this.publicCallStackHashes) && - isDefaultArray(this.newL2ToL1Msgs) && - this.encryptedLogsHash.isZero() && - this.unencryptedLogsHash.isZero() && - this.encryptedLogPreimagesLength.isZero() && - this.unencryptedLogPreimagesLength.isZero() && - this.historicalHeader.isDefault() && - this.chainId.isZero() && - this.version.isZero() - ); + return this.toBuffer().equals(PrivateCircuitPublicInputs.default().toBuffer()); } /** diff --git a/yarn-project/circuits.js/src/structs/public_call_request.ts b/yarn-project/circuits.js/src/structs/public_call_request.ts index 30f4faf8f8b..3e57add7401 100644 --- a/yarn-project/circuits.js/src/structs/public_call_request.ts +++ b/yarn-project/circuits.js/src/structs/public_call_request.ts @@ -101,7 +101,7 @@ export class PublicCallRequest { * @returns A PublicCallStackItem instance with the same contract address, function data, call context, and args. */ toPublicCallStackItem() { - const publicInputs = PublicCircuitPublicInputs.empty(); + const publicInputs = PublicCircuitPublicInputs.default(); publicInputs.callContext = this.callContext; publicInputs.argsHash = this.getArgsHash(); return new PublicCallStackItem(this.contractAddress, this.functionData, publicInputs, true); @@ -115,7 +115,7 @@ export class PublicCallRequest { const item = this.toPublicCallStackItem(); const callerContext = this.callContext.isDelegateCall ? new CallerContext(this.parentCallContext.msgSender, this.parentCallContext.storageContractAddress) - : CallerContext.empty(); + : CallerContext.default(); return new CallRequest( item.hash(), this.parentCallContext.storageContractAddress, diff --git a/yarn-project/circuits.js/src/structs/public_call_stack_item.test.ts b/yarn-project/circuits.js/src/structs/public_call_stack_item.test.ts index a7d87aabb79..8be87491cb9 100644 --- a/yarn-project/circuits.js/src/structs/public_call_stack_item.test.ts +++ b/yarn-project/circuits.js/src/structs/public_call_stack_item.test.ts @@ -22,7 +22,7 @@ describe('PublicCallStackItem', () => { }); it('Computes a callstack item request hash', () => { - const callStack = PublicCallStackItem.empty(); + const callStack = PublicCallStackItem.default(); callStack.contractAddress = AztecAddress.fromField(new Fr(1)); callStack.functionData = new FunctionData(new FunctionSelector(2), false); @@ -41,7 +41,7 @@ describe('PublicCallStackItem', () => { }); it('Computes a callstack item hash', () => { - const callStack = PublicCallStackItem.empty(); + const callStack = PublicCallStackItem.default(); callStack.contractAddress = AztecAddress.fromField(new Fr(1)); callStack.functionData = new FunctionData(new FunctionSelector(2), false); diff --git a/yarn-project/circuits.js/src/structs/public_call_stack_item.ts b/yarn-project/circuits.js/src/structs/public_call_stack_item.ts index d8a06ec6e37..2b83a946c88 100644 --- a/yarn-project/circuits.js/src/structs/public_call_stack_item.ts +++ b/yarn-project/circuits.js/src/structs/public_call_stack_item.ts @@ -91,7 +91,7 @@ export class PublicCallStackItem { public hash() { if (this.isExecutionRequest) { const { callContext, argsHash } = this.publicInputs; - this.publicInputs = PublicCircuitPublicInputs.empty(); + this.publicInputs = PublicCircuitPublicInputs.default(); this.publicInputs.callContext = callContext; this.publicInputs.argsHash = argsHash; } diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts index 71fbc0fc141..4edbe7a4ac2 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts @@ -15,9 +15,9 @@ describe('PublicCircuitPublicInputs', () => { expect(res).toEqual(expected); }); - it(`initializes an empty PrivateCircuitPublicInputs`, () => { - const target = PublicCircuitPublicInputs.empty(); - expect(target.isEmpty()).toBe(true); + it(`initializes an default PrivateCircuitPublicInputs`, () => { + const target = PublicCircuitPublicInputs.default(); + expect(target.isDefault()).toBe(true); }); it('number of fields matches constant', () => { @@ -32,8 +32,8 @@ describe('PublicCircuitPublicInputs', () => { expect(hash).toMatchSnapshot(); }); - it('computes empty item hash', () => { - const item = PublicCircuitPublicInputs.empty(); + it('computes default item hash', () => { + const item = PublicCircuitPublicInputs.default(); const hash = item.hash(); expect(hash).toMatchSnapshot(); diff --git a/yarn-project/circuits.js/src/structs/read_request_hints.ts b/yarn-project/circuits.js/src/structs/read_request_hints.ts index 880b71a4467..6699c15459a 100644 --- a/yarn-project/circuits.js/src/structs/read_request_hints.ts +++ b/yarn-project/circuits.js/src/structs/read_request_hints.ts @@ -58,7 +58,7 @@ export class SettledReadHint LEAF_PREIMAGE, ) { - return new SettledReadHint(readRequestLen, MembershipWitness.empty(treeHeight, 0n), emptyLeafPreimage()); + return new SettledReadHint(readRequestLen, MembershipWitness.default(treeHeight, 0n), emptyLeafPreimage()); } static fromBuffer( @@ -164,12 +164,12 @@ export class NullifierReadRequestHintsBuilder { makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_TX, ReadRequestStatus.nada), makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_TX, () => PendingReadHint.nada(MAX_NULLIFIER_READ_REQUESTS_PER_TX)), makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_TX, () => - SettledReadHint.nada(MAX_NULLIFIER_READ_REQUESTS_PER_TX, NULLIFIER_TREE_HEIGHT, NullifierLeafPreimage.empty), + SettledReadHint.nada(MAX_NULLIFIER_READ_REQUESTS_PER_TX, NULLIFIER_TREE_HEIGHT, NullifierLeafPreimage.default), ), ); } - static empty() { + static default() { return new NullifierReadRequestHintsBuilder().toHints(); } diff --git a/yarn-project/circuits.js/src/structs/rollup_validation_requests.ts b/yarn-project/circuits.js/src/structs/rollup_validation_requests.ts index 7da5e636478..814556671dc 100644 --- a/yarn-project/circuits.js/src/structs/rollup_validation_requests.ts +++ b/yarn-project/circuits.js/src/structs/rollup_validation_requests.ts @@ -40,7 +40,7 @@ export class RollupValidationRequests { return RollupValidationRequests.fromBuffer(Buffer.from(str, 'hex')); } - static empty() { - return new RollupValidationRequests(MaxBlockNumber.empty()); + static default() { + return new RollupValidationRequests(MaxBlockNumber.default()); } } diff --git a/yarn-project/circuits.js/src/structs/tx_context.test.ts b/yarn-project/circuits.js/src/structs/tx_context.test.ts index 940770dac82..78a476b1da2 100644 --- a/yarn-project/circuits.js/src/structs/tx_context.test.ts +++ b/yarn-project/circuits.js/src/structs/tx_context.test.ts @@ -17,7 +17,7 @@ describe('TxContext', () => { const buffer = context.toBuffer(); const res = TxContext.fromBuffer(buffer); expect(res).toEqual(context); - expect(res.isEmpty()).toBe(false); + expect(res.isDefault()).toBe(false); }); it('number of fields matches constant', () => { @@ -25,9 +25,9 @@ describe('TxContext', () => { expect(fields.length).toBe(TX_CONTEXT_DATA_LENGTH); }); - it('computes empty hash', () => { - const tc = TxContext.empty(); - expect(tc.isEmpty()).toBe(true); + it('computes default hash', () => { + const tc = TxContext.default(); + expect(tc.isDefault()).toBe(true); const hash = tc.hash(); expect(hash).toMatchSnapshot(); diff --git a/yarn-project/circuits.js/src/structs/tx_request.test.ts b/yarn-project/circuits.js/src/structs/tx_request.test.ts index d353bb36b24..c225492a43e 100644 --- a/yarn-project/circuits.js/src/structs/tx_request.test.ts +++ b/yarn-project/circuits.js/src/structs/tx_request.test.ts @@ -22,7 +22,7 @@ describe('TxRequest', () => { const buffer = request.toBuffer(); const res = TxRequest.fromBuffer(buffer); expect(res).toEqual(request); - expect(res.isEmpty()).toBe(false); + expect(res.isDefault()).toBe(false); }); it('number of fields matches constant', () => { diff --git a/yarn-project/circuits.js/src/structs/validation_requests.ts b/yarn-project/circuits.js/src/structs/validation_requests.ts index fbcbe3d2b35..a91b4d952bd 100644 --- a/yarn-project/circuits.js/src/structs/validation_requests.ts +++ b/yarn-project/circuits.js/src/structs/validation_requests.ts @@ -93,14 +93,14 @@ export class ValidationRequests { return ValidationRequests.fromBuffer(Buffer.from(str, 'hex')); } - static empty() { + static default() { return new ValidationRequests( - RollupValidationRequests.empty(), - makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_TX, SideEffect.empty), - makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_TX, ReadRequestContext.empty), - makeTuple(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, ReadRequestContext.empty), - makeTuple(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, NullifierKeyValidationRequestContext.empty), - makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, PublicDataRead.empty), + RollupValidationRequests.default(), + makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_TX, SideEffect.default), + makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_TX, ReadRequestContext.default), + makeTuple(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, ReadRequestContext.default), + makeTuple(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, NullifierKeyValidationRequestContext.default), + makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, PublicDataRead.default), ); } } diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index eaa666f525c..8f6dc26e39d 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -184,7 +184,7 @@ describe('e2e_crowdfunding_and_claim', () => { nonce: noteNonces[0], }, value: extendedNote.note.items[0], - owner: extendedNote.note.items[1], + owner: AztecAddress.fromField(extendedNote.note.items[1]), randomness: extendedNote.note.items[2], }; }; diff --git a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts index 4c4de2b0b71..7fcc81a69d9 100644 --- a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts @@ -159,7 +159,7 @@ describe('L1Publisher integration', () => { const makeBloatedProcessedTx = (seed = 0x1) => { const tx = mockTx(seed); - const kernelOutput = PublicKernelCircuitPublicInputs.empty(); + const kernelOutput = PublicKernelCircuitPublicInputs.default(); kernelOutput.constants.txContext.chainId = fr(chainId); kernelOutput.constants.txContext.version = fr(config.version); kernelOutput.constants.historicalHeader = prevHeader; @@ -178,7 +178,7 @@ describe('L1Publisher integration', () => { seed + 0x200, ); processedTx.data.end.newNullifiers[processedTx.data.end.newNullifiers.length - 1] = - SideEffectLinkedToNoteHash.empty(); + SideEffectLinkedToNoteHash.default(); processedTx.data.end.newL2ToL1Msgs = makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x300); processedTx.data.end.encryptedLogsHash = Fr.fromBuffer(processedTx.encryptedLogs.hash()); processedTx.data.end.unencryptedLogsHash = Fr.fromBuffer(processedTx.unencryptedLogs.hash()); diff --git a/yarn-project/end-to-end/src/simulators/lending_simulator.ts b/yarn-project/end-to-end/src/simulators/lending_simulator.ts index 48bd93fcd15..1ea67792bf3 100644 --- a/yarn-project/end-to-end/src/simulators/lending_simulator.ts +++ b/yarn-project/end-to-end/src/simulators/lending_simulator.ts @@ -173,7 +173,7 @@ export class LendingSimulator { expect(asset['last_updated_ts']).toEqual(BigInt(this.time)); for (const key of [this.account.address, this.account.key()]) { - const privatePos = await this.lendingContract.methods.get_position(key).view(); + const privatePos = await this.lendingContract.methods.get_position(AztecAddress.fromField(key)).view(); expect(new Fr(privatePos['collateral'])).toEqual(this.collateral[key.toString()] ?? Fr.ZERO); expect(new Fr(privatePos['static_debt'])).toEqual(this.staticDebt[key.toString()] ?? Fr.ZERO); expect(privatePos['debt']).toEqual( diff --git a/yarn-project/entrypoints/src/account_entrypoint.ts b/yarn-project/entrypoints/src/account_entrypoint.ts index e855e48324f..96a0cda6432 100644 --- a/yarn-project/entrypoints/src/account_entrypoint.ts +++ b/yarn-project/entrypoints/src/account_entrypoint.ts @@ -33,7 +33,7 @@ export class DefaultAccountEntrypoint implements EntrypointInterface { argsHash: entrypointPackedArgs.hash, origin: this.address, functionData: FunctionData.fromAbi(abi), - txContext: TxContext.empty(this.chainId, this.version), + txContext: TxContext.default(this.chainId, this.version), packedArguments: [...appPackedArguments, ...feePackedArguments, entrypointPackedArgs], authWitnesses: [appAuthWitness, feeAuthWitness], }); diff --git a/yarn-project/entrypoints/src/dapp_entrypoint.ts b/yarn-project/entrypoints/src/dapp_entrypoint.ts index 5e851d59f44..78dfde3dd6a 100644 --- a/yarn-project/entrypoints/src/dapp_entrypoint.ts +++ b/yarn-project/entrypoints/src/dapp_entrypoint.ts @@ -46,7 +46,7 @@ export class DefaultDappEntrypoint implements EntrypointInterface { argsHash: entrypointPackedArgs.hash, origin: this.dappEntrypointAddress, functionData, - txContext: TxContext.empty(this.chainId, this.version), + txContext: TxContext.default(this.chainId, this.version), packedArguments: [...packedArguments, entrypointPackedArgs], authWitnesses: [authWitness], }); diff --git a/yarn-project/entrypoints/src/multi_call_entrypoint.ts b/yarn-project/entrypoints/src/multi_call_entrypoint.ts index 59431343878..a7d2e28f308 100644 --- a/yarn-project/entrypoints/src/multi_call_entrypoint.ts +++ b/yarn-project/entrypoints/src/multi_call_entrypoint.ts @@ -27,7 +27,7 @@ export class DefaultMultiCallEntrypoint implements EntrypointInterface { argsHash: entrypointPackedArgs.hash, origin: this.address, functionData: FunctionData.fromAbi(abi), - txContext: TxContext.empty(this.chainId, this.version), + txContext: TxContext.default(this.chainId, this.version), packedArguments: [...appPackedArguments, entrypointPackedArgs], authWitnesses: [], }); diff --git a/yarn-project/foundation/src/abi/event_selector.ts b/yarn-project/foundation/src/abi/event_selector.ts index 48779aabad6..71799cbe272 100644 --- a/yarn-project/foundation/src/abi/event_selector.ts +++ b/yarn-project/foundation/src/abi/event_selector.ts @@ -67,7 +67,7 @@ export class EventSelector extends Selector { * Creates an empty selector. * @returns An empty selector. */ - static empty() { + static default() { return new EventSelector(0); } diff --git a/yarn-project/foundation/src/eth-address/index.ts b/yarn-project/foundation/src/eth-address/index.ts index 8119a13972d..c6d219ee078 100644 --- a/yarn-project/foundation/src/eth-address/index.ts +++ b/yarn-project/foundation/src/eth-address/index.ts @@ -75,7 +75,7 @@ export class EthAddress { } public static default() { - return EthAddress.default(); + return EthAddress.ZERO; } /** diff --git a/yarn-project/merkle-tree/src/interfaces/indexed_tree.ts b/yarn-project/merkle-tree/src/interfaces/indexed_tree.ts index 44bd849479b..6363ad62142 100644 --- a/yarn-project/merkle-tree/src/interfaces/indexed_tree.ts +++ b/yarn-project/merkle-tree/src/interfaces/indexed_tree.ts @@ -24,7 +24,7 @@ export interface PreimageFactory { /** * Creates an empty preimage. */ - empty(): IndexedTreeLeafPreimage; + default(): IndexedTreeLeafPreimage; /** * Creates a copy of a preimage. * @param preimage - Preimage to be cloned. diff --git a/yarn-project/merkle-tree/src/standard_indexed_tree/standard_indexed_tree.ts b/yarn-project/merkle-tree/src/standard_indexed_tree/standard_indexed_tree.ts index 001886fc4a3..4bb2ddc17e4 100644 --- a/yarn-project/merkle-tree/src/standard_indexed_tree/standard_indexed_tree.ts +++ b/yarn-project/merkle-tree/src/standard_indexed_tree/standard_indexed_tree.ts @@ -46,7 +46,7 @@ function getEmptyLowLeafWitness( leafPreimageFactory: PreimageFactory, ): LowLeafWitnessData { return { - leafPreimage: leafPreimageFactory.empty(), + leafPreimage: leafPreimageFactory.default(), index: 0n, siblingPath: new SiblingPath(treeHeight, Array(treeHeight).fill(toBufferBE(0n, 32))), }; @@ -474,7 +474,7 @@ export class StandardIndexedTree extends TreeBase implements IndexedTree const emptyLowLeafWitness = getEmptyLowLeafWitness(this.getDepth() as TreeHeight, this.leafPreimageFactory); // Accumulators const lowLeavesWitnesses: LowLeafWitnessData[] = leaves.map(() => emptyLowLeafWitness); - const pendingInsertionSubtree: IndexedTreeLeafPreimage[] = leaves.map(() => this.leafPreimageFactory.empty()); + const pendingInsertionSubtree: IndexedTreeLeafPreimage[] = leaves.map(() => this.leafPreimageFactory.default()); // Start info const startInsertionIndex = this.getNumLeaves(true); @@ -536,7 +536,7 @@ export class StandardIndexedTree extends TreeBase implements IndexedTree this.updateLeaf(newLowLeafPreimage, indexOfPrevious.index); - pendingInsertionSubtree[originalIndex] = this.leafPreimageFactory.empty(); + pendingInsertionSubtree[originalIndex] = this.leafPreimageFactory.default(); } else { const newLowLeafPreimage = this.leafPreimageFactory.fromLeaf( lowLeafPreimage.asLeaf(), diff --git a/yarn-project/prover-client/src/dummy-prover.ts b/yarn-project/prover-client/src/dummy-prover.ts index d2c1f4842e4..4d1af7c7c98 100644 --- a/yarn-project/prover-client/src/dummy-prover.ts +++ b/yarn-project/prover-client/src/dummy-prover.ts @@ -31,7 +31,7 @@ export class DummyProver implements ProverClient { const result: ProvingSuccess = { status: PROVING_STATUS.SUCCESS, proof: makeEmptyProof(), - block: L2Block.empty(), + block: L2Block.default(), }; const ticket: ProvingTicket = { provingPromise: Promise.resolve(result), diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.test.ts index 8c7c6826bd7..6225fc02fa3 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.test.ts @@ -132,9 +132,9 @@ describe('prover/tx-prover', () => { txs.flatMap(tx => padArrayEnd( [...tx.data.endNonRevertibleData.newNoteHashes, ...tx.data.end.newNoteHashes] - .filter(x => !x.isEmpty()) + .filter(x => !x.isDefault()) .sort(sideEffectCmp), - SideEffect.empty(), + SideEffect.default(), MAX_NEW_NOTE_HASHES_PER_TX, ).map(l => l.value), ), @@ -144,9 +144,9 @@ describe('prover/tx-prover', () => { txs.flatMap(tx => padArrayEnd( [...tx.data.endNonRevertibleData.newNullifiers, ...tx.data.end.newNullifiers] - .filter(x => !x.isEmpty()) + .filter(x => !x.isDefault()) .sort(sideEffectCmp), - SideEffectLinkedToNoteHash.empty(), + SideEffectLinkedToNoteHash.default(), MAX_NEW_NULLIFIERS_PER_TX, ).map(x => x.value.toBuffer()), ), @@ -234,7 +234,7 @@ describe('prover/tx-prover', () => { // // We are constructing the block here just to get body hash/calldata hash so we can pass in an empty archive and header // const l2Block = L2Block.fromFields({ // archive: AppendOnlyTreeSnapshot.zero(), - // header: Header.empty(), + // header: Header.default(), // // Only the values below go to body hash/calldata hash // body, // }); @@ -324,7 +324,7 @@ describe('prover/tx-prover', () => { const makeBloatedProcessedTx = async (seed = 0x1) => { seed *= MAX_NEW_NULLIFIERS_PER_TX; // Ensure no clashing given incremental seeds const tx = mockTx(seed); - const kernelOutput = PublicKernelCircuitPublicInputs.empty(); + const kernelOutput = PublicKernelCircuitPublicInputs.default(); kernelOutput.constants.historicalHeader = await builderDb.buildInitialHeader(); kernelOutput.end.publicDataUpdateRequests = makeTuple( MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, @@ -361,7 +361,7 @@ describe('prover/tx-prover', () => { seed + 0x100000 + MAX_REVERTIBLE_NULLIFIERS_PER_TX, ); - processedTx.data.end.newNullifiers[tx.data.end.newNullifiers.length - 1] = SideEffectLinkedToNoteHash.empty(); + processedTx.data.end.newNullifiers[tx.data.end.newNullifiers.length - 1] = SideEffectLinkedToNoteHash.default(); processedTx.data.end.newL2ToL1Msgs = makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x300); processedTx.data.end.encryptedLogsHash = Fr.fromBuffer(processedTx.encryptedLogs.hash()); diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts index 4491c70d86c..5428e1909ad 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts @@ -51,16 +51,16 @@ describe('Kernel Prover', () => { const generateFakeSiloedCommitment = (note: NoteAndSlot) => createFakeSiloedCommitment(generateFakeCommitment(note)); const createExecutionResult = (fnName: string, newNoteIndices: number[] = []): ExecutionResult => { - const publicInputs = PrivateCircuitPublicInputs.empty(); + const publicInputs = PrivateCircuitPublicInputs.default(); publicInputs.newNoteHashes = makeTuple( MAX_NEW_NOTE_HASHES_PER_CALL, i => i < newNoteIndices.length ? new SideEffect(generateFakeCommitment(notesAndSlots[newNoteIndices[i]]), Fr.ZERO) - : SideEffect.empty(), + : SideEffect.default(), 0, ); - const functionData = FunctionData.empty(); + const functionData = FunctionData.default(); functionData.selector = new FunctionSelector(fnName.charCodeAt(0)); return { callStackItem: new PrivateCallStackItem(AztecAddress.default(), functionData, publicInputs), @@ -70,20 +70,20 @@ describe('Kernel Prover', () => { // TODO(dbanks12): should test kernel prover with non-transient reads. // This will be necessary once kernel actually checks (attempts to match) transient reads. noteHashReadRequestPartialWitnesses: Array.from({ length: MAX_NOTE_HASH_READ_REQUESTS_PER_CALL }, () => - NoteHashReadRequestMembershipWitness.emptyTransient(), + NoteHashReadRequestMembershipWitness.defaultTransient(), ), returnValues: [], acir: Buffer.alloc(0), partialWitness: new Map(), enqueuedPublicFunctionCalls: [], - encryptedLogs: EncryptedFunctionL2Logs.empty(), - unencryptedLogs: UnencryptedFunctionL2Logs.empty(), + encryptedLogs: EncryptedFunctionL2Logs.default(), + unencryptedLogs: UnencryptedFunctionL2Logs.default(), }; }; const createProofOutput = (newNoteIndices: number[]) => { - const publicInputs = PrivateKernelInnerCircuitPublicInputs.empty(); - const commitments = makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, () => SideEffect.empty()); + const publicInputs = PrivateKernelInnerCircuitPublicInputs.default(); + const commitments = makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, () => SideEffect.default()); for (let i = 0; i < newNoteIndices.length; i++) { commitments[i] = new SideEffect(generateFakeSiloedCommitment(notesAndSlots[newNoteIndices[i]]), Fr.ZERO); } @@ -96,8 +96,8 @@ describe('Kernel Prover', () => { }; const createProofOutputFinal = (newNoteIndices: number[]) => { - const publicInputs = PrivateKernelTailCircuitPublicInputs.empty(); - const commitments = makeTuple(MAX_REVERTIBLE_NOTE_HASHES_PER_TX, () => SideEffect.empty()); + const publicInputs = PrivateKernelTailCircuitPublicInputs.default(); + const commitments = makeTuple(MAX_REVERTIBLE_NOTE_HASHES_PER_TX, () => SideEffect.default()); for (let i = 0; i < newNoteIndices.length; i++) { commitments[i] = new SideEffect(generateFakeSiloedCommitment(notesAndSlots[newNoteIndices[i]]), Fr.ZERO); } diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts index f2d8e65ad93..29453a530ff 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -94,7 +94,7 @@ export class KernelProver { let previousVerificationKey = VerificationKey.makeFake(); let output: ProofOutput = { - publicInputs: PrivateKernelInnerCircuitPublicInputs.empty(), + publicInputs: PrivateKernelInnerCircuitPublicInputs.default(), proof: makeEmptyProof(), }; @@ -131,7 +131,7 @@ export class KernelProver { noteHashReadRequestMembershipWitnesses.push( ...Array(MAX_NOTE_HASH_READ_REQUESTS_PER_CALL - noteHashReadRequestMembershipWitnesses.length) .fill(0) - .map(() => NoteHashReadRequestMembershipWitness.empty(BigInt(0))), + .map(() => NoteHashReadRequestMembershipWitness.default(BigInt(0))), ); const privateCallData = await this.createPrivateCallData( @@ -240,10 +240,10 @@ export class KernelProver { // Pad with empty items to reach max/const length expected by circuit. const privateCallStack = padArrayEnd( privateCallRequests, - CallRequest.empty(), + CallRequest.default(), MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, ); - const publicCallStack = padArrayEnd(publicCallRequests, CallRequest.empty(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL); + const publicCallStack = padArrayEnd(publicCallRequests, CallRequest.default(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL); const functionLeafMembershipWitness = await this.oracle.getFunctionMembershipWitness( contractAddress, diff --git a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts index 7c24b72307b..17518dbdaae 100644 --- a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts +++ b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts @@ -124,13 +124,13 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise) => }); it('throws when simulating a tx targeting public entrypoint', async () => { - const functionData = FunctionData.empty(); + const functionData = FunctionData.default(); functionData.isPrivate = false; const txExecutionRequest = TxExecutionRequest.from({ origin: AztecAddress.random(), argsHash: new Fr(0), functionData, - txContext: TxContext.empty(), + txContext: TxContext.default(), packedArguments: [], authWitnesses: [], }); diff --git a/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts b/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts index a4e6b05fcc7..265b914b45c 100644 --- a/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts +++ b/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts @@ -353,30 +353,30 @@ export abstract class AbstractPhaseManager { callContext: result.execution.callContext, proverAddress: AztecAddress.default(), argsHash: computeVarArgsHash(result.execution.args), - newNoteHashes: padArrayEnd(result.newNoteHashes, SideEffect.empty(), MAX_NEW_NOTE_HASHES_PER_CALL), - newNullifiers: padArrayEnd(result.newNullifiers, SideEffectLinkedToNoteHash.empty(), MAX_NEW_NULLIFIERS_PER_CALL), - newL2ToL1Msgs: padArrayEnd(result.newL2ToL1Messages, L2ToL1Message.empty(), MAX_NEW_L2_TO_L1_MSGS_PER_CALL), + newNoteHashes: padArrayEnd(result.newNoteHashes, SideEffect.default(), MAX_NEW_NOTE_HASHES_PER_CALL), + newNullifiers: padArrayEnd(result.newNullifiers, SideEffectLinkedToNoteHash.default(), MAX_NEW_NULLIFIERS_PER_CALL), + newL2ToL1Msgs: padArrayEnd(result.newL2ToL1Messages, L2ToL1Message.default(), MAX_NEW_L2_TO_L1_MSGS_PER_CALL), startSideEffectCounter: result.startSideEffectCounter, endSideEffectCounter: result.endSideEffectCounter, returnValues: padArrayEnd(result.returnValues, Fr.ZERO, RETURN_VALUES_LENGTH), nullifierReadRequests: padArrayEnd( result.nullifierReadRequests, - ReadRequest.empty(), + ReadRequest.default(), MAX_NULLIFIER_READ_REQUESTS_PER_CALL, ), nullifierNonExistentReadRequests: padArrayEnd( result.nullifierNonExistentReadRequests, - ReadRequest.empty(), + ReadRequest.default(), MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, ), contractStorageReads: padArrayEnd( result.contractStorageReads, - ContractStorageRead.empty(), + ContractStorageRead.default(), MAX_PUBLIC_DATA_READS_PER_CALL, ), contractStorageUpdateRequests: padArrayEnd( result.contractStorageUpdateRequests, - ContractStorageUpdateRequest.empty(), + ContractStorageUpdateRequest.default(), MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, ), publicCallStackHashes, @@ -429,7 +429,7 @@ export abstract class AbstractPhaseManager { const publicCallRequests = (await this.getPublicCallStackPreimages(result)).map(c => c.toCallRequest(callStackItem.publicInputs.callContext), ); - const publicCallStack = padArrayEnd(publicCallRequests, CallRequest.empty(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL); + const publicCallStack = padArrayEnd(publicCallRequests, CallRequest.default(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL); const portalContractAddress = result.execution.callContext.portalContractAddress.toField(); return new PublicCallData(callStackItem, publicCallStack, makeEmptyProof(), portalContractAddress, bytecodeHash); } @@ -447,13 +447,13 @@ function removeRedundantPublicDataWrites(publicInputs: PublicKernelCircuitPublic publicInputs.end.publicDataUpdateRequests = padArrayEnd( patch(publicInputs.end.publicDataUpdateRequests), - PublicDataUpdateRequest.empty(), + PublicDataUpdateRequest.default(), MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, ); publicInputs.endNonRevertibleData.publicDataUpdateRequests = padArrayEnd( patch(publicInputs.endNonRevertibleData.publicDataUpdateRequests), - PublicDataUpdateRequest.empty(), + PublicDataUpdateRequest.default(), MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, ); } diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts index 0d9a66562bd..9c67bcb7d7d 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts @@ -88,8 +88,8 @@ describe('public_processor', () => { db, publicExecutor, publicKernel, - GlobalVariables.empty(), - Header.empty(), + GlobalVariables.default(), + Header.default(), publicContractsDB, publicWorldStateDB, ); @@ -99,11 +99,11 @@ describe('public_processor', () => { const seed = 1; const includeLogs = false; const tx = mockTx(seed, includeLogs); - tx.data.end.publicCallStack = makeTuple(MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.empty); + tx.data.end.publicCallStack = makeTuple(MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default); tx.data.end.unencryptedLogsHash = Fr.ZERO; tx.data.endNonRevertibleData.publicCallStack = makeTuple( MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, - CallRequest.empty, + CallRequest.default, ); tx.data.needsSetup = false; tx.data.needsAppLogic = false; @@ -120,7 +120,7 @@ describe('public_processor', () => { data: new PublicKernelCircuitPublicInputs( tx.data.aggregationObject, tx.data.rollupValidationRequests, - ValidationRequests.empty(), + ValidationRequests.default(), PublicAccumulatedNonRevertibleData.fromPrivateAccumulatedNonRevertibleData(tx.data.endNonRevertibleData), PublicAccumulatedRevertibleData.fromPrivateAccumulatedRevertibleData(tx.data.end), tx.data.constants, @@ -176,8 +176,8 @@ describe('public_processor', () => { db, publicExecutor, publicKernel, - GlobalVariables.empty(), - Header.empty(), + GlobalVariables.default(), + Header.default(), publicContractsDB, publicWorldStateDB, ); @@ -196,22 +196,22 @@ describe('public_processor', () => { const kernelOutput = makePrivateKernelTailCircuitPublicInputs(0x10); kernelOutput.end.publicCallStack = padArrayEnd( callRequests, - CallRequest.empty(), + CallRequest.default(), MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, ); - kernelOutput.end.privateCallStack = padArrayEnd([], CallRequest.empty(), MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX); + kernelOutput.end.privateCallStack = padArrayEnd([], CallRequest.default(), MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX); kernelOutput.endNonRevertibleData.publicCallStack = makeTuple( MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, - CallRequest.empty, + CallRequest.default, ); kernelOutput.end.unencryptedLogsHash = Fr.ZERO; const tx = new Tx( kernelOutput, proof, - EncryptedTxL2Logs.empty(), - UnencryptedTxL2Logs.empty(), + EncryptedTxL2Logs.default(), + UnencryptedTxL2Logs.default(), publicCallRequests, ); @@ -246,20 +246,20 @@ describe('public_processor', () => { const kernelOutput = makePrivateKernelTailCircuitPublicInputs(0x10); kernelOutput.end.publicCallStack = padArrayEnd( [callStackItem], - CallRequest.empty(), + CallRequest.default(), MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, ); - kernelOutput.end.privateCallStack = padArrayEnd([], CallRequest.empty(), MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX); + kernelOutput.end.privateCallStack = padArrayEnd([], CallRequest.default(), MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX); kernelOutput.endNonRevertibleData.publicCallStack = makeTuple( MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, - CallRequest.empty, + CallRequest.default, ); kernelOutput.end.unencryptedLogsHash = Fr.ZERO; kernelOutput.needsSetup = false; kernelOutput.needsTeardown = false; - const tx = new Tx(kernelOutput, proof, EncryptedTxL2Logs.empty(), UnencryptedTxL2Logs.empty(), [callRequest]); + const tx = new Tx(kernelOutput, proof, EncryptedTxL2Logs.default(), UnencryptedTxL2Logs.default(), [callRequest]); const publicExecutionResult = PublicExecutionResultBuilder.fromPublicCallRequest({ request: callRequest, @@ -309,8 +309,8 @@ describe('public_processor', () => { const tx = new Tx( kernelOutput, proof, - EncryptedTxL2Logs.empty(), - UnencryptedTxL2Logs.empty(), + EncryptedTxL2Logs.default(), + UnencryptedTxL2Logs.default(), // reverse because `enqueuedPublicFunctions` expects the last element to be the front of the queue callRequests.slice().reverse(), ); @@ -387,10 +387,10 @@ describe('public_processor', () => { expect(publicWorldStateDB.commit).toHaveBeenCalledTimes(1); expect(publicWorldStateDB.rollbackToCommit).toHaveBeenCalledTimes(0); - expect(arrayNonEmptyLength(processed[0].data.combinedData.publicCallStack, i => i.isEmpty())).toEqual(0); + expect(arrayNonEmptyLength(processed[0].data.combinedData.publicCallStack, i => i.isDefault())).toEqual(0); const txEffect = toTxEffect(processed[0]); - expect(arrayNonEmptyLength(txEffect.publicDataWrites, PublicDataWrite.isEmpty)).toEqual(2); + expect(arrayNonEmptyLength(txEffect.publicDataWrites, PublicDataWrite.isDefault)).toEqual(2); expect(txEffect.publicDataWrites[0]).toEqual( new PublicDataWrite(computePublicDataTreeLeafSlot(baseContractAddress, contractSlotA), fr(0x101)), ); @@ -425,8 +425,8 @@ describe('public_processor', () => { const tx = new Tx( kernelOutput, proof, - EncryptedTxL2Logs.empty(), - UnencryptedTxL2Logs.empty(), + EncryptedTxL2Logs.default(), + UnencryptedTxL2Logs.default(), // reverse because `enqueuedPublicFunctions` expects the last element to be the front of the queue callRequests.slice().reverse(), ); @@ -529,8 +529,8 @@ describe('public_processor', () => { const tx = new Tx( kernelOutput, proof, - EncryptedTxL2Logs.empty(), - UnencryptedTxL2Logs.empty(), + EncryptedTxL2Logs.default(), + UnencryptedTxL2Logs.default(), // reverse because `enqueuedPublicFunctions` expects the last element to be the front of the queue callRequests.slice().reverse(), ); @@ -632,8 +632,8 @@ describe('public_processor', () => { const tx = new Tx( kernelOutput, proof, - EncryptedTxL2Logs.empty(), - UnencryptedTxL2Logs.empty(), + EncryptedTxL2Logs.default(), + UnencryptedTxL2Logs.default(), // reverse because `enqueuedPublicFunctions` expects the last element to be the front of the queue callRequests.slice().reverse(), ); @@ -706,7 +706,7 @@ describe('public_processor', () => { expect(publicWorldStateDB.rollbackToCommit).toHaveBeenCalledTimes(0); const txEffect = toTxEffect(processed[0]); - expect(arrayNonEmptyLength(txEffect.publicDataWrites, PublicDataWrite.isEmpty)).toEqual(3); + expect(arrayNonEmptyLength(txEffect.publicDataWrites, PublicDataWrite.isDefault)).toEqual(3); expect(txEffect.publicDataWrites[0]).toEqual( new PublicDataWrite(computePublicDataTreeLeafSlot(baseContractAddress, contractSlotA), fr(0x102)), ); @@ -819,7 +819,7 @@ class PublicExecutionResultBuilder { newNullifiers: [], newL2ToL1Messages: [], contractStorageReads: [], - unencryptedLogs: UnencryptedFunctionL2Logs.empty(), + unencryptedLogs: UnencryptedFunctionL2Logs.default(), startSideEffectCounter: Fr.ZERO, endSideEffectCounter: Fr.ZERO, reverted: this._reverted, @@ -848,14 +848,14 @@ function addKernelPublicCallStack( // this is a stack, so the first item is the last call // and callRequests is in the order of the calls [calls.teardownCall.toCallRequest(), ...calls.setupCalls.map(c => c.toCallRequest())], - CallRequest.empty(), + CallRequest.default(), MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, ); kernelOutput.end.publicCallStack = padArrayEnd( calls.appLogicCalls.map(c => c.toCallRequest()), - CallRequest.empty(), + CallRequest.default(), MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, ); - kernelOutput.end.privateCallStack = padArrayEnd([], CallRequest.empty(), MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX); + kernelOutput.end.privateCallStack = padArrayEnd([], CallRequest.default(), MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX); } diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts index ed46187cd94..e47fe67d3d8 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts @@ -72,7 +72,7 @@ describe('sequencer', () => { publicProcessor = mock({ process: async txs => [await Promise.all(txs.map(tx => makeProcessedTx(tx))), []], - makeEmptyProcessedTx: () => makeEmptyProcessedTx(Header.empty(), chainId, version), + makeEmptyProcessedTx: () => makeEmptyProcessedTx(Header.default(), chainId, version), }); publicProcessorFactory = mock({ diff --git a/yarn-project/sequencer-client/src/sequencer/setup_phase_manager.test.ts b/yarn-project/sequencer-client/src/sequencer/setup_phase_manager.test.ts index 9b198177c62..fd30e1dcc45 100644 --- a/yarn-project/sequencer-client/src/sequencer/setup_phase_manager.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/setup_phase_manager.test.ts @@ -47,8 +47,8 @@ describe('setup_phase_manager', () => { db, publicExecutor, publicKernel, - GlobalVariables.empty(), - Header.empty(), + GlobalVariables.default(), + Header.default(), publicContractsDB, publicWorldStateDB, ); @@ -56,10 +56,10 @@ describe('setup_phase_manager', () => { it('does not extract non-revertible calls when none exist', function () { const tx = mockTx(); - tx.data.end.publicCallStack = makeTuple(MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.empty); + tx.data.end.publicCallStack = makeTuple(MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default); tx.data.endNonRevertibleData.publicCallStack = makeTuple( MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, - CallRequest.empty, + CallRequest.default, ); const enqueuedNonRevertibleCalls = phaseManager.extractEnqueuedPublicCalls(tx); diff --git a/yarn-project/sequencer-client/src/sequencer/tx_validator.test.ts b/yarn-project/sequencer-client/src/sequencer/tx_validator.test.ts index e711146e6be..2f76efa3a5a 100644 --- a/yarn-project/sequencer-client/src/sequencer/tx_validator.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/tx_validator.test.ts @@ -262,9 +262,9 @@ describe('TxValidator', () => { // clear public call stacks as it's mocked data but the arrays are not correlated tx.data.endNonRevertibleData.publicCallStack = makeTuple( MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, - CallRequest.empty, + CallRequest.default, ); - tx.data.end.publicCallStack = makeTuple(MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.empty); + tx.data.end.publicCallStack = makeTuple(MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default); // use splice because it's a readonly property tx.enqueuedPublicFunctionCalls.splice(0, tx.enqueuedPublicFunctionCalls.length); @@ -286,7 +286,7 @@ describe('TxValidator', () => { gasTokenAddress, new FunctionData(signature, false), new CallContext(feePayer, gasTokenAddress, gasPortalAddress, signature, false, false, 1), - CallContext.empty(), + CallContext.default(), [], ); @@ -307,7 +307,7 @@ describe('TxValidator', () => { feePaymentContract, new FunctionData(feeSetupSelector, true), new CallContext(feePaymentContract, feePaymentContract, EthAddress.default(), feeSetupSelector, false, false, 1), - CallContext.empty(), + CallContext.default(), [], ); tx.data.endNonRevertibleData.publicCallStack[0] = feeSetupFn.toCallRequest(); @@ -319,7 +319,7 @@ describe('TxValidator', () => { feePaymentContract, new FunctionData(feeExecutionSelector, true), new CallContext(feePaymentContract, feePaymentContract, EthAddress.default(), feeExecutionSelector, false, false, 2), - CallContext.empty(), + CallContext.default(), [], ); tx.data.endNonRevertibleData.publicCallStack[1] = feeExecutionFn.toCallRequest(); diff --git a/yarn-project/simulator/src/acvm/oracle/oracle.ts b/yarn-project/simulator/src/acvm/oracle/oracle.ts index 812c41bc068..bfa94386a0f 100644 --- a/yarn-project/simulator/src/acvm/oracle/oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/oracle.ts @@ -29,7 +29,7 @@ export class Oracle { } async getNullifierKeyPair([accountAddress]: ACVMField[]): Promise { - const { publicKey, secretKey } = await this.typedOracle.getNullifierKeyPair(fromACVMField(accountAddress)); + const { publicKey, secretKey } = await this.typedOracle.getNullifierKeyPair(AztecAddress.fromField(fromACVMField(accountAddress))); return [ toACVMField(publicKey.x), toACVMField(publicKey.y), diff --git a/yarn-project/simulator/src/avm/avm_context.ts b/yarn-project/simulator/src/avm/avm_context.ts index 3ae5e6dfe3c..caaba85d879 100644 --- a/yarn-project/simulator/src/avm/avm_context.ts +++ b/yarn-project/simulator/src/avm/avm_context.ts @@ -38,7 +38,7 @@ export class AvmContext { public createNestedContractCallContext( address: AztecAddress, calldata: Fr[], - temporaryFunctionSelector: FunctionSelector = FunctionSelector.empty(), + temporaryFunctionSelector: FunctionSelector = FunctionSelector.default(), ): AvmContext { const newExecutionEnvironment = this.environment.deriveEnvironmentForNestedCall( address, @@ -65,7 +65,7 @@ export class AvmContext { public createNestedContractStaticCallContext( address: AztecAddress, calldata: Fr[], - temporaryFunctionSelector: FunctionSelector = FunctionSelector.empty(), + temporaryFunctionSelector: FunctionSelector = FunctionSelector.default(), ): AvmContext { const newExecutionEnvironment = this.environment.deriveEnvironmentForNestedStaticCall( address, diff --git a/yarn-project/simulator/src/avm/avm_execution_environment.test.ts b/yarn-project/simulator/src/avm/avm_execution_environment.test.ts index 6aad1e2ea25..495c2f0f3c5 100644 --- a/yarn-project/simulator/src/avm/avm_execution_environment.test.ts +++ b/yarn-project/simulator/src/avm/avm_execution_environment.test.ts @@ -1,6 +1,7 @@ import { Fr } from '@aztec/foundation/fields'; import { allSameExcept, anyAvmContextInputs, initExecutionEnvironment } from './fixtures/index.js'; +import { AztecAddress } from '@aztec/circuits.js'; describe('Execution Environment', () => { const newAddress = new Fr(123456n); @@ -8,7 +9,7 @@ describe('Execution Environment', () => { it('New call should fork execution environment correctly', () => { const executionEnvironment = initExecutionEnvironment(); - const newExecutionEnvironment = executionEnvironment.deriveEnvironmentForNestedCall(newAddress, calldata); + const newExecutionEnvironment = executionEnvironment.deriveEnvironmentForNestedCall(AztecAddress.fromField(newAddress), calldata); expect(newExecutionEnvironment).toEqual( allSameExcept(executionEnvironment, { @@ -22,7 +23,7 @@ describe('Execution Environment', () => { it('New delegate call should fork execution environment correctly', () => { const executionEnvironment = initExecutionEnvironment(); - const newExecutionEnvironment = executionEnvironment.newDelegateCall(newAddress, calldata); + const newExecutionEnvironment = executionEnvironment.newDelegateCall(AztecAddress.fromField(newAddress), calldata); expect(newExecutionEnvironment).toEqual( allSameExcept(executionEnvironment, { @@ -36,7 +37,7 @@ describe('Execution Environment', () => { it('New static call call should fork execution environment correctly', () => { const executionEnvironment = initExecutionEnvironment(); - const newExecutionEnvironment = executionEnvironment.deriveEnvironmentForNestedStaticCall(newAddress, calldata); + const newExecutionEnvironment = executionEnvironment.deriveEnvironmentForNestedStaticCall(AztecAddress.fromField(newAddress), calldata); expect(newExecutionEnvironment).toEqual( allSameExcept(executionEnvironment, { diff --git a/yarn-project/simulator/src/avm/avm_execution_environment.ts b/yarn-project/simulator/src/avm/avm_execution_environment.ts index 2381cf2f16b..5e80b169fd2 100644 --- a/yarn-project/simulator/src/avm/avm_execution_environment.ts +++ b/yarn-project/simulator/src/avm/avm_execution_environment.ts @@ -61,7 +61,7 @@ export class AvmExecutionEnvironment { public deriveEnvironmentForNestedCall( address: AztecAddress, calldata: Fr[], - temporaryFunctionSelector: FunctionSelector = FunctionSelector.empty(), + temporaryFunctionSelector: FunctionSelector = FunctionSelector.default(), ): AvmExecutionEnvironment { return new AvmExecutionEnvironment( address, @@ -84,7 +84,7 @@ export class AvmExecutionEnvironment { public deriveEnvironmentForNestedStaticCall( address: AztecAddress, calldata: Fr[], - temporaryFunctionSelector: FunctionSelector = FunctionSelector.empty(), + temporaryFunctionSelector: FunctionSelector = FunctionSelector.default(), ): AvmExecutionEnvironment { return new AvmExecutionEnvironment( address, @@ -107,7 +107,7 @@ export class AvmExecutionEnvironment { public newDelegateCall( address: AztecAddress, calldata: Fr[], - temporaryFunctionSelector: FunctionSelector = FunctionSelector.empty(), + temporaryFunctionSelector: FunctionSelector = FunctionSelector.default(), ): AvmExecutionEnvironment { return new AvmExecutionEnvironment( address, diff --git a/yarn-project/simulator/src/avm/journal/nullifiers.ts b/yarn-project/simulator/src/avm/journal/nullifiers.ts index f8374f6f8a7..f26cbdf4fa5 100644 --- a/yarn-project/simulator/src/avm/journal/nullifiers.ts +++ b/yarn-project/simulator/src/avm/journal/nullifiers.ts @@ -2,6 +2,7 @@ import { siloNullifier } from '@aztec/circuits.js/hash'; import { Fr } from '@aztec/foundation/fields'; import type { CommitmentsDB } from '../../index.js'; +import { AztecAddress } from '@aztec/circuits.js'; /** * A class to manage new nullifier staging and existence checks during a contract call's AVM simulation. @@ -50,7 +51,7 @@ export class Nullifiers { let leafIndex: bigint | undefined = undefined; if (!existsAsPending) { // silo the nullifier before checking for its existence in the host - leafIndex = await this.hostNullifiers.getNullifierIndex(siloNullifier(storageAddress, nullifier)); + leafIndex = await this.hostNullifiers.getNullifierIndex(siloNullifier(AztecAddress.fromField(storageAddress), nullifier)); } const exists = existsAsPending || leafIndex !== undefined; leafIndex = leafIndex === undefined ? BigInt(0) : leafIndex; diff --git a/yarn-project/simulator/src/avm/journal/public_storage.ts b/yarn-project/simulator/src/avm/journal/public_storage.ts index f6b3b7a35d8..566ff4abb93 100644 --- a/yarn-project/simulator/src/avm/journal/public_storage.ts +++ b/yarn-project/simulator/src/avm/journal/public_storage.ts @@ -1,6 +1,7 @@ import { Fr } from '@aztec/foundation/fields'; import type { PublicStateDB } from '../../index.js'; +import { AztecAddress } from '@aztec/circuits.js'; /** * A class to manage public storage reads and writes during a contract call's AVM simulation. @@ -48,7 +49,7 @@ export class PublicStorage { } // Finally try the host's Aztec state (a trip to the database) if (!value) { - value = await this.hostPublicStorage.storageRead(storageAddress, slot); + value = await this.hostPublicStorage.storageRead(AztecAddress.fromField(storageAddress), slot); } // if value is undefined, that means this slot has never been written to! const exists = value !== undefined; diff --git a/yarn-project/simulator/src/avm/opcodes/external_calls.ts b/yarn-project/simulator/src/avm/opcodes/external_calls.ts index 9a8e5b6d69c..d9e713b05c2 100644 --- a/yarn-project/simulator/src/avm/opcodes/external_calls.ts +++ b/yarn-project/simulator/src/avm/opcodes/external_calls.ts @@ -1,4 +1,4 @@ -import { FunctionSelector } from '@aztec/circuits.js'; +import { AztecAddress, FunctionSelector } from '@aztec/circuits.js'; import type { AvmContext } from '../avm_context.js'; import { Field, Uint8 } from '../avm_memory_types.js'; @@ -54,7 +54,7 @@ export class Call extends Instruction { const functionSelector = context.machineState.memory.getAs(this.temporaryFunctionSelectorOffset).toFr(); const nestedContext = context.createNestedContractCallContext( - callAddress.toFr(), + AztecAddress.fromField(callAddress.toFr()), calldata, FunctionSelector.fromField(functionSelector), ); @@ -123,7 +123,7 @@ export class StaticCall extends Instruction { const functionSelector = context.machineState.memory.getAs(this.temporaryFunctionSelectorOffset).toFr(); const nestedContext = context.createNestedContractStaticCallContext( - callAddress.toFr(), + AztecAddress.fromField(callAddress.toFr()), calldata, FunctionSelector.fromField(functionSelector), ); diff --git a/yarn-project/simulator/src/avm/temporary_executor_migration.ts b/yarn-project/simulator/src/avm/temporary_executor_migration.ts index 4c2e0bb203d..560dd323f3c 100644 --- a/yarn-project/simulator/src/avm/temporary_executor_migration.ts +++ b/yarn-project/simulator/src/avm/temporary_executor_migration.ts @@ -96,8 +96,8 @@ export function temporaryConvertAvmResults( const nullifierReadRequests: ReadRequest[] = []; const nullifierNonExistentReadRequests: ReadRequest[] = []; const newNullifiers: SideEffectLinkedToNoteHash[] = []; - const unencryptedLogs = UnencryptedFunctionL2Logs.empty(); - const newL2ToL1Messages = newWorldState.newL1Messages.map(() => L2ToL1Message.empty()); + const unencryptedLogs = UnencryptedFunctionL2Logs.default(); + const newL2ToL1Messages = newWorldState.newL1Messages.map(() => L2ToL1Message.default()); // TODO keep track of side effect counters const startSideEffectCounter = Fr.ZERO; const endSideEffectCounter = Fr.ZERO; diff --git a/yarn-project/simulator/src/client/execution_result.test.ts b/yarn-project/simulator/src/client/execution_result.test.ts index ba16d784bb4..842b712338c 100644 --- a/yarn-project/simulator/src/client/execution_result.test.ts +++ b/yarn-project/simulator/src/client/execution_result.test.ts @@ -14,19 +14,19 @@ function emptyExecutionResult(): ExecutionResult { acir: Buffer.from(''), vk: Buffer.from(''), partialWitness: new Map(), - callStackItem: PrivateCallStackItem.empty(), + callStackItem: PrivateCallStackItem.default(), noteHashReadRequestPartialWitnesses: [], newNotes: [], returnValues: [], nestedExecutions: [], enqueuedPublicFunctionCalls: [], - encryptedLogs: EncryptedFunctionL2Logs.empty(), - unencryptedLogs: UnencryptedFunctionL2Logs.empty(), + encryptedLogs: EncryptedFunctionL2Logs.default(), + unencryptedLogs: UnencryptedFunctionL2Logs.default(), }; } describe('Execution Result test suite - collect encrypted logs', () => { - function emptyExecutionResultWithEncryptedLogs(encryptedLogs = EncryptedFunctionL2Logs.empty()): ExecutionResult { + function emptyExecutionResultWithEncryptedLogs(encryptedLogs = EncryptedFunctionL2Logs.default()): ExecutionResult { const executionResult = emptyExecutionResult(); executionResult.encryptedLogs = encryptedLogs; return executionResult; @@ -114,9 +114,9 @@ describe('Execution Result test suite - collect encrypted logs', () => { executionResult.nestedExecutions.push(fnB); const encryptedLogs = collectEncryptedLogs(executionResult); expect(encryptedLogs).toEqual([ - EncryptedFunctionL2Logs.empty(), + EncryptedFunctionL2Logs.default(), makeEncryptedFunctionLogs(['Log 1']), - EncryptedFunctionL2Logs.empty(), + EncryptedFunctionL2Logs.default(), ]); }); @@ -141,11 +141,11 @@ describe('Execution Result test suite - collect encrypted logs', () => { const encryptedLogs = collectEncryptedLogs(executionResult); expect(encryptedLogs).toEqual([ - EncryptedFunctionL2Logs.empty(), - EncryptedFunctionL2Logs.empty(), - EncryptedFunctionL2Logs.empty(), - EncryptedFunctionL2Logs.empty(), - EncryptedFunctionL2Logs.empty(), + EncryptedFunctionL2Logs.default(), + EncryptedFunctionL2Logs.default(), + EncryptedFunctionL2Logs.default(), + EncryptedFunctionL2Logs.default(), + EncryptedFunctionL2Logs.default(), ]); }); }); @@ -154,7 +154,7 @@ describe('collect unencrypted logs', () => { // collection of unencrypted logs work similar to encrypted logs, so lets write other kinds of test cases: function emptyExecutionResultWithUnencryptedLogs( - unencryptedLogs = UnencryptedFunctionL2Logs.empty(), + unencryptedLogs = UnencryptedFunctionL2Logs.default(), ): ExecutionResult { const executionResult = emptyExecutionResult(); executionResult.unencryptedLogs = unencryptedLogs; @@ -163,7 +163,7 @@ describe('collect unencrypted logs', () => { function makeUnencryptedFunctionLogs(contents: string[]) { return new UnencryptedFunctionL2Logs( - contents.map(s => new UnencryptedL2Log(AztecAddress.default(), EventSelector.empty(), Buffer.from(s))), + contents.map(s => new UnencryptedL2Log(AztecAddress.default(), EventSelector.default(), Buffer.from(s))), ); } @@ -171,7 +171,7 @@ describe('collect unencrypted logs', () => { // fnA() const executionResult: ExecutionResult = emptyExecutionResult(); const unencryptedLogs = collectUnencryptedLogs(executionResult); - expect(unencryptedLogs).toEqual([UnencryptedFunctionL2Logs.empty()]); + expect(unencryptedLogs).toEqual([UnencryptedFunctionL2Logs.default()]); }); it('collect unencrypted logs with no logs in some nested calls', () => { @@ -189,9 +189,9 @@ describe('collect unencrypted logs', () => { const unencryptedLogs = collectUnencryptedLogs(executionResult); expect(unencryptedLogs).toEqual([ - UnencryptedFunctionL2Logs.empty(), + UnencryptedFunctionL2Logs.default(), makeUnencryptedFunctionLogs(['Log 1', 'Log 2', 'Log 3']), - UnencryptedFunctionL2Logs.empty(), + UnencryptedFunctionL2Logs.default(), ]); }); @@ -212,8 +212,8 @@ describe('collect unencrypted logs', () => { executionResult.nestedExecutions.push(fnB); const unencryptedLogs = collectUnencryptedLogs(executionResult); expect(unencryptedLogs).toEqual([ - UnencryptedFunctionL2Logs.empty(), - UnencryptedFunctionL2Logs.empty(), + UnencryptedFunctionL2Logs.default(), + UnencryptedFunctionL2Logs.default(), makeUnencryptedFunctionLogs(['Log 4', 'Log 5', 'Log 6']), makeUnencryptedFunctionLogs(['Log 1', 'Log 2', 'Log 3']), ]); diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 35097eff9cc..1539721bad3 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -65,7 +65,7 @@ describe('Private Execution test suite', () => { let acirSimulator: AcirSimulator; - let header = Header.empty(); + let header = Header.default(); let logger: DebugLogger; const defaultContractAddress = AztecAddress.random(); diff --git a/yarn-project/simulator/src/client/simulator.ts b/yarn-project/simulator/src/client/simulator.ts index 9d03629a0f9..1435a2f0881 100644 --- a/yarn-project/simulator/src/client/simulator.ts +++ b/yarn-project/simulator/src/client/simulator.ts @@ -202,7 +202,7 @@ export class AcirSimulator { const execRequest: FunctionCall = { to: contractAddress, - functionData: FunctionData.empty(), + functionData: FunctionData.default(), args: encodeArguments(artifact, [contractAddress, nonce, storageSlot, noteTypeId, extendedNoteItems]), }; diff --git a/yarn-project/simulator/src/client/unconstrained_execution.test.ts b/yarn-project/simulator/src/client/unconstrained_execution.test.ts index b4997ddba21..a7aff0bca8c 100644 --- a/yarn-project/simulator/src/client/unconstrained_execution.test.ts +++ b/yarn-project/simulator/src/client/unconstrained_execution.test.ts @@ -47,7 +47,7 @@ describe('Unconstrained Execution test suite', () => { const notes: Note[] = [...Array(5).fill(buildNote(1n, owner)), ...Array(2).fill(buildNote(2n, owner))]; - oracle.getHeader.mockResolvedValue(Header.empty()); + oracle.getHeader.mockResolvedValue(Header.default()); oracle.getNotes.mockResolvedValue( notes.map((note, index) => ({ contractAddress, @@ -63,7 +63,7 @@ describe('Unconstrained Execution test suite', () => { const execRequest: FunctionCall = { to: contractAddress, - functionData: new FunctionData(FunctionSelector.empty(), true), + functionData: new FunctionData(FunctionSelector.default(), true), args: encodeArguments(artifact, [owner]), }; diff --git a/yarn-project/simulator/src/public/avm_executor.test.ts b/yarn-project/simulator/src/public/avm_executor.test.ts index 23f31610c1a..d0cb215fc08 100644 --- a/yarn-project/simulator/src/public/avm_executor.test.ts +++ b/yarn-project/simulator/src/public/avm_executor.test.ts @@ -20,7 +20,7 @@ describe('AVM WitGen and Proof Generation', () => { msgSender: AztecAddress.random(), storageContractAddress: AztecAddress.random(), portalContractAddress: EthAddress.random(), - functionSelector: FunctionSelector.empty(), + functionSelector: FunctionSelector.default(), isDelegateCall: false, isStaticCall: false, sideEffectCounter: 0, @@ -46,7 +46,7 @@ describe('AVM WitGen and Proof Generation', () => { const bytecode: Buffer = Buffer.from('IAAAAAAAAAAAAgAAAAAAAAYAAAAAAAAAAQAAAAI4AAAAAAIAAAAB', 'base64'); publicContracts.getBytecode.mockResolvedValue(bytecode); const executor = new PublicExecutor(publicState, publicContracts, commitmentsDb, header); - const functionData = FunctionData.empty(); + const functionData = FunctionData.default(); const execution: PublicExecution = { contractAddress, functionData, args, callContext }; const [proof, vk] = await executor.getAvmProof(execution); const valid = await executor.verifyAvmProof(vk, proof); diff --git a/yarn-project/simulator/src/public/executor.ts b/yarn-project/simulator/src/public/executor.ts index 6c82a03134e..30898b88b1d 100644 --- a/yarn-project/simulator/src/public/executor.ts +++ b/yarn-project/simulator/src/public/executor.ts @@ -92,7 +92,7 @@ export async function executePublicFunction( contractStorageReads: [], contractStorageUpdateRequests: [], nestedExecutions: [], - unencryptedLogs: UnencryptedFunctionL2Logs.empty(), + unencryptedLogs: UnencryptedFunctionL2Logs.default(), reverted, revertReason, }; diff --git a/yarn-project/simulator/src/public/index.test.ts b/yarn-project/simulator/src/public/index.test.ts index a9202e73950..47826c28175 100644 --- a/yarn-project/simulator/src/public/index.test.ts +++ b/yarn-project/simulator/src/public/index.test.ts @@ -106,7 +106,7 @@ describe('ACIR public execution simulator', () => { msgSender, storageContractAddress: contractAddress, portalContractAddress: EthAddress.random(), - functionSelector: FunctionSelector.empty(), + functionSelector: FunctionSelector.default(), isDelegateCall: false, isStaticCall: false, sideEffectCounter: 0, @@ -124,7 +124,7 @@ describe('ACIR public execution simulator', () => { .mockResolvedValueOnce(previousTotalSupply); // reading total supply const execution: PublicExecution = { contractAddress, functionData, args, callContext }; - const result = await executor.simulate(execution, GlobalVariables.empty()); + const result = await executor.simulate(execution, GlobalVariables.default()); const recipientBalanceStorageSlot = computeSlotForMapping(new Fr(6n), recipient); const totalSupplyStorageSlot = new Fr(4n); @@ -171,7 +171,7 @@ describe('ACIR public execution simulator', () => { beforeEach(() => { transferArtifact = TokenContractArtifact.functions.find(f => f.name === 'transfer_public')!; - functionData = new FunctionData(FunctionSelector.empty(), false); + functionData = new FunctionData(FunctionSelector.default(), false); sender = AztecAddress.random(); args = encodeArguments(transferArtifact, [sender, recipient, 140n, 0n]); @@ -179,7 +179,7 @@ describe('ACIR public execution simulator', () => { msgSender: sender, storageContractAddress: contractAddress, portalContractAddress: EthAddress.random(), - functionSelector: FunctionSelector.empty(), + functionSelector: FunctionSelector.default(), isDelegateCall: false, isStaticCall: false, sideEffectCounter: 0, @@ -211,7 +211,7 @@ describe('ACIR public execution simulator', () => { const recipientBalance = new Fr(20n); mockStore(senderBalance, recipientBalance); - const result = await executor.simulate(execution, GlobalVariables.empty()); + const result = await executor.simulate(execution, GlobalVariables.default()); const expectedRecipientBalance = new Fr(160n); const expectedSenderBalance = new Fr(60n); @@ -237,7 +237,7 @@ describe('ACIR public execution simulator', () => { const recipientBalance = new Fr(20n); mockStore(senderBalance, recipientBalance); - const { reverted, revertReason } = await executor.simulate(execution, GlobalVariables.empty()); + const { reverted, revertReason } = await executor.simulate(execution, GlobalVariables.default()); expect(reverted).toBe(true); expect(revertReason?.message).toMatch('Assertion failed: attempt to subtract with underflow'); }); @@ -266,7 +266,7 @@ describe('ACIR public execution simulator', () => { msgSender: AztecAddress.random(), storageContractAddress: parentContractAddress, portalContractAddress: EthAddress.random(), - functionSelector: FunctionSelector.empty(), + functionSelector: FunctionSelector.default(), isDelegateCall: false, isStaticCall: false, sideEffectCounter: 0, @@ -315,7 +315,7 @@ describe('ACIR public execution simulator', () => { beforeEach(async () => { contractAddress = AztecAddress.random(); await mockInitializationNullifierCallback(contractAddress); - functionData = new FunctionData(FunctionSelector.empty(), false); + functionData = new FunctionData(FunctionSelector.default(), false); amount = new Fr(1); params = [amount, new Fr(1)]; }); @@ -331,7 +331,7 @@ describe('ACIR public execution simulator', () => { msgSender: msgSender, storageContractAddress: contractAddress, portalContractAddress: EthAddress.random(), - functionSelector: FunctionSelector.empty(), + functionSelector: FunctionSelector.default(), isDelegateCall: false, isStaticCall: false, sideEffectCounter: 0, @@ -342,7 +342,7 @@ describe('ACIR public execution simulator', () => { publicState.storageRead.mockResolvedValue(amount); const execution: PublicExecution = { contractAddress, functionData, args, callContext }; - const result = await executor.simulate(execution, GlobalVariables.empty()); + const result = await executor.simulate(execution, GlobalVariables.default()); // Assert the note hash was created expect(result.newNoteHashes.length).toEqual(1); @@ -365,7 +365,7 @@ describe('ACIR public execution simulator', () => { msgSender: AztecAddress.random(), storageContractAddress: contractAddress, portalContractAddress, - functionSelector: FunctionSelector.empty(), + functionSelector: FunctionSelector.default(), isDelegateCall: false, isStaticCall: false, sideEffectCounter: 0, @@ -374,7 +374,7 @@ describe('ACIR public execution simulator', () => { publicContracts.getBytecode.mockResolvedValue(createL2ToL1MessagePublicArtifact.bytecode); const execution: PublicExecution = { contractAddress, functionData, args, callContext }; - const result = await executor.simulate(execution, GlobalVariables.empty()); + const result = await executor.simulate(execution, GlobalVariables.default()); // Assert the l2 to l1 message was created expect(result.newL2ToL1Messages.length).toEqual(1); @@ -395,7 +395,7 @@ describe('ACIR public execution simulator', () => { msgSender: AztecAddress.random(), storageContractAddress: contractAddress, portalContractAddress: EthAddress.random(), - functionSelector: FunctionSelector.empty(), + functionSelector: FunctionSelector.default(), isDelegateCall: false, isStaticCall: false, sideEffectCounter: 0, @@ -404,7 +404,7 @@ describe('ACIR public execution simulator', () => { publicContracts.getBytecode.mockResolvedValue(createNullifierPublicArtifact.bytecode); const execution: PublicExecution = { contractAddress, functionData, args, callContext }; - const result = await executor.simulate(execution, GlobalVariables.empty()); + const result = await executor.simulate(execution, GlobalVariables.default()); // Assert the l2 to l1 message was created expect(result.newNullifiers.length).toEqual(1); @@ -452,7 +452,7 @@ describe('ACIR public execution simulator', () => { msgSender: AztecAddress.random(), storageContractAddress: contractAddress, portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, - functionSelector: FunctionSelector.empty(), + functionSelector: FunctionSelector.default(), isDelegateCall: false, isStaticCall: false, sideEffectCounter: 0, @@ -651,7 +651,7 @@ describe('ACIR public execution simulator', () => { msgSender: AztecAddress.random(), storageContractAddress: AztecAddress.random(), portalContractAddress: EthAddress.default(), - functionSelector: FunctionSelector.empty(), + functionSelector: FunctionSelector.default(), isDelegateCall: false, isStaticCall: false, sideEffectCounter: 0, @@ -684,7 +684,7 @@ describe('ACIR public execution simulator', () => { beforeAll(() => { // We create a new global variables object containing non-zero value in place of the tested property - globalVariables = modifyGlobalVariables(GlobalVariables.empty(), i, value); + globalVariables = modifyGlobalVariables(GlobalVariables.default(), i, value); }); it('Valid', () => { @@ -734,7 +734,7 @@ describe('ACIR public execution simulator', () => { msgSender: AztecAddress.random(), storageContractAddress: AztecAddress.random(), portalContractAddress: EthAddress.default(), - functionSelector: FunctionSelector.empty(), + functionSelector: FunctionSelector.default(), isDelegateCall: false, isStaticCall: false, sideEffectCounter: 0, @@ -753,7 +753,7 @@ describe('ACIR public execution simulator', () => { const execution: PublicExecution = { contractAddress, functionData, args, callContext }; executor = new PublicExecutor(publicState, publicContracts, commitmentsDb, header); - expect(() => executor.simulate(execution, GlobalVariables.empty())).not.toThrow(); + expect(() => executor.simulate(execution, GlobalVariables.default())).not.toThrow(); }); it('Throws when header is not as expected', async () => { @@ -763,7 +763,7 @@ describe('ACIR public execution simulator', () => { const execution: PublicExecution = { contractAddress, functionData, args, callContext }; executor = new PublicExecutor(publicState, publicContracts, commitmentsDb, header); - const { revertReason, reverted } = await executor.simulate(execution, GlobalVariables.empty()); + const { revertReason, reverted } = await executor.simulate(execution, GlobalVariables.default()); expect(reverted).toBe(true); expect(revertReason?.message).toMatch(`Invalid header hash`); }); From 97b918009fd324ee9807782b1559624a10b7b728 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Mon, 1 Apr 2024 07:30:02 +0000 Subject: [PATCH 15/77] comment --- .../crates/private-kernel-lib/src/private_kernel_tail.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4a05430ea31..3d2f693e8c7 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 @@ -119,7 +119,7 @@ impl PrivateKernelTailCircuitPrivateInputs { let is_default = is_default(item); if prev_was_empty { - assert(is_default, "Empty items must be at the end"); + assert(is_default, "Default items must be at the end"); } else if (i != 0) & !is_default { assert(sorted[i].counter() > sorted[i - 1].counter(), "Not sorted"); } From dc0d26c70236c65cb4903f4ddab6192b0a00be7f Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Mon, 1 Apr 2024 07:31:59 +0000 Subject: [PATCH 16/77] comment --- .../crates/public-kernel-lib/src/common.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index 92ca72ebebb..444649afa58 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -469,7 +469,7 @@ pub fn validate_call_against_request(public_call: PublicCallData, request: CallR if call_context.is_delegate_call { let caller_context = request.caller_context; - assert(!is_default(caller_context), "caller context cannot be empty for delegate calls"); + assert(!is_default(caller_context), "caller context cannot be default for delegate calls"); assert( call_context.msg_sender.eq(caller_context.msg_sender), "call stack msg_sender does not match expected msg_sender for delegate calls" ); From 512249c8e7b5251eeba55a24cf5ac539dda6dced Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Mon, 1 Apr 2024 07:32:46 +0000 Subject: [PATCH 17/77] comment --- .../crates/public-kernel-lib/src/public_kernel_setup.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr index 1390e4a2143..e4913f12923 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr @@ -31,7 +31,7 @@ impl PublicKernelSetupCircuitPrivateInputs { for i in 0..private_call_stack.len() { let private_call = private_call_stack[i]; assert( - is_default(private_call), "Private call stack must be empty when executing in the public kernel" + is_default(private_call), "Private call stack must be default when executing in the public kernel" ); } From f6cdaa2d14550dc67119501b649728f7d909bd41 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Mon, 1 Apr 2024 07:34:13 +0000 Subject: [PATCH 18/77] fix --- .../crates/reset-kernel-lib/src/read_request_reset.nr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr index 89a3be4098b..10045e84a04 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr @@ -1,7 +1,7 @@ // This will be moved to a separate Read Request Reset Circuit. use dep::types::{ - abis::{read_request::ReadRequestContext, side_effect::OrderedValue}, hash::{silo_nullifier}, - merkle_tree::{assert_check_membership, LeafPreimage, MembershipWitness}, traits::{is_default} + abis::{read_request::ReadRequestContext, side_effect::OrderedValue}, hash::silo_nullifier, + merkle_tree::{assert_check_membership, LeafPreimage, MembershipWitness}, traits::is_default }; struct ReadRequestStateEnum { From 6e536a7b3038bf8f8781ba157ca4328430d61401 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Mon, 1 Apr 2024 07:55:29 +0000 Subject: [PATCH 19/77] edit --- .../noir-protocol-circuits/crates/types/src/utils/arrays.nr | 2 +- yarn-project/circuit-types/src/public_data_write.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 620e88c44d2..b6c16f44b3c 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 @@ -1,6 +1,6 @@ use dep::std::array; use dep::std::cmp::Eq; -use crate::traits::{is_default}; +use crate::traits::is_default; pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Default + Eq { let mut len = 0; diff --git a/yarn-project/circuit-types/src/public_data_write.ts b/yarn-project/circuit-types/src/public_data_write.ts index 615bf11064d..00b2c33947f 100644 --- a/yarn-project/circuit-types/src/public_data_write.ts +++ b/yarn-project/circuit-types/src/public_data_write.ts @@ -79,7 +79,7 @@ export class PublicDataWrite { } /** - * Creates an empty public data write operation. + * Creates a default public data write operation. * @returns A new public data write operation instance. */ static default(): PublicDataWrite { From d73887613d308e045e846c0b1e5671be83c45c16 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Mon, 1 Apr 2024 08:10:09 +0000 Subject: [PATCH 20/77] fix --- yarn-project/circuits.js/src/hints/utils.ts | 30 +++++++++---------- .../circuits.js/src/structs/header.test.ts | 2 +- .../src/structs/l2_to_l1_message.ts | 8 ++--- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/yarn-project/circuits.js/src/hints/utils.ts b/yarn-project/circuits.js/src/hints/utils.ts index 9799f217a31..3e1e6fd5a7b 100644 --- a/yarn-project/circuits.js/src/hints/utils.ts +++ b/yarn-project/circuits.js/src/hints/utils.ts @@ -6,12 +6,12 @@ export interface IsDefault { // Define these utils here as their design is very specific to kernel's accumulated data and not general enough to be put in foundation. -// Returns number of non-empty items in an array. +// Returns number of non-default items in an array. export function countAccumulatedItems(arr: T[]) { return arr.reduce((num, item, i) => { if (!item.isDefault()) { if (num !== i) { - throw new Error('Non-empty items must be placed continuously from index 0.'); + throw new Error('Non-default items must be placed continuously from index 0.'); } return num + 1; } @@ -25,19 +25,19 @@ export function mergeAccumulatedData( arr0: Tuple, arr1: Tuple, ): Tuple { - const numNonEmptyItems0 = countAccumulatedItems(arr0); - const numNonEmptyItems1 = countAccumulatedItems(arr1); - if (numNonEmptyItems0 + numNonEmptyItems1 > arr0.length) { - throw new Error('Combined non-empty items exceeded the maximum allowed.'); + const numNonDefaultItems0 = countAccumulatedItems(arr0); + const numNonDefaultItems1 = countAccumulatedItems(arr1); + if (numNonDefaultItems0 + numNonDefaultItems1 > arr0.length) { + throw new Error('Combined non-default items exceeded the maximum allowed.'); } const arr = [...arr0] as Tuple; - arr1.slice(0, numNonEmptyItems1).forEach((item, i) => (arr[i + numNonEmptyItems0] = item)); + arr1.slice(0, numNonDefaultItems1).forEach((item, i) => (arr[i + numNonDefaultItems0] = item)); return arr; } // Combines an array of length N and an array of length M into an array of length N + M. -// All non-empty items are aggregated continuously from index 0. +// All non-default items are aggregated continuously from index 0. export function concatAccumulatedData( length: NM, arr0: Tuple, @@ -48,14 +48,14 @@ export function concatAccumulatedData; - if (numNonEmptyItems0 < arr0.length) { - const emptyItem = arr0[numNonEmptyItems0]; - arr1.slice(0, numNonEmptyItems1).forEach((item, i) => { - arr[i + numNonEmptyItems0] = item; - arr[arr0.length + i] = emptyItem; + if (numNonDefaultItems0 < arr0.length) { + const defaultItem = arr0[numNonDefaultItems0]; + arr1.slice(0, numNonDefaultItems1).forEach((item, i) => { + arr[i + numNonDefaultItems0] = item; + arr[arr0.length + i] = defaultItem; }); } return arr; diff --git a/yarn-project/circuits.js/src/structs/header.test.ts b/yarn-project/circuits.js/src/structs/header.test.ts index a67b7ebe801..8e824120894 100644 --- a/yarn-project/circuits.js/src/structs/header.test.ts +++ b/yarn-project/circuits.js/src/structs/header.test.ts @@ -37,7 +37,7 @@ describe('Header', () => { expect(fields.length).toBe(HEADER_LENGTH); }); - it('computes empty hash', () => { + it('computes default hash', () => { const header = Header.default(); const hash = header.hash(); expect(hash).toMatchSnapshot(); diff --git a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts index ec1d9ca7cd3..c15ebfbd2e5 100644 --- a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts +++ b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts @@ -8,8 +8,8 @@ export class L2ToL1Message { constructor(public recipient: EthAddress, public content: Fr) {} /** - * Creates an empty L2ToL1Message with default values. - * @returns An instance of L2ToL1Message with empty fields. + * Creates an default L2ToL1Message with default values. + * @returns An instance of L2ToL1Message with default fields. */ static default(): L2ToL1Message { return new L2ToL1Message(EthAddress.default(), Fr.zero()); @@ -67,8 +67,8 @@ export class L2ToL1Message { } /** - * Convenience method to check if the message is empty. - * @returns True if both recipient and content are zero. + * Convenience method to check if the message is default. + * @returns True if recipient is default and content is zero. */ isDefault(): boolean { return this.recipient.isDefault() && this.content.isZero(); From 933c73ed5db036566ffe647a727c5dfbe670f012 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Mon, 1 Apr 2024 08:29:03 +0000 Subject: [PATCH 21/77] fixes --- .../src/structs/private_circuit_public_inputs.test.ts | 2 +- yarn-project/foundation/src/abi/event_selector.ts | 4 ++-- yarn-project/foundation/src/abi/function_selector.ts | 4 ++-- yarn-project/foundation/src/abi/selector.ts | 4 ++-- yarn-project/merkle-tree/src/interfaces/indexed_tree.ts | 2 +- yarn-project/pxe/src/kernel_prover/hints_builder.ts | 2 +- yarn-project/pxe/src/kernel_prover/kernel_prover.ts | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.test.ts b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.test.ts index 5d0e74eb57f..a0c75ce3a77 100644 --- a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.test.ts +++ b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.test.ts @@ -41,7 +41,7 @@ describe('PrivateCircuitPublicInputs', () => { expect(hash).toMatchSnapshot(); }); - it('computes empty inputs hash', () => { + it('computes default inputs hash', () => { const inputs = PrivateCircuitPublicInputs.default(); const hash = inputs.hash(); expect(hash).toMatchSnapshot(); diff --git a/yarn-project/foundation/src/abi/event_selector.ts b/yarn-project/foundation/src/abi/event_selector.ts index 71799cbe272..1d0f23b83a5 100644 --- a/yarn-project/foundation/src/abi/event_selector.ts +++ b/yarn-project/foundation/src/abi/event_selector.ts @@ -64,8 +64,8 @@ export class EventSelector extends Selector { } /** - * Creates an empty selector. - * @returns An empty selector. + * Creates an default selector. + * @returns An default selector. */ static default() { return new EventSelector(0); diff --git a/yarn-project/foundation/src/abi/function_selector.ts b/yarn-project/foundation/src/abi/function_selector.ts index 8cfc151f983..2d1e754e152 100644 --- a/yarn-project/foundation/src/abi/function_selector.ts +++ b/yarn-project/foundation/src/abi/function_selector.ts @@ -92,8 +92,8 @@ export class FunctionSelector extends Selector { } /** - * Creates an empty selector. - * @returns An empty selector. + * Creates an default selector. + * @returns An default selector. */ static default() { return new FunctionSelector(0); diff --git a/yarn-project/foundation/src/abi/selector.ts b/yarn-project/foundation/src/abi/selector.ts index ec0998919dd..c31bcbba418 100644 --- a/yarn-project/foundation/src/abi/selector.ts +++ b/yarn-project/foundation/src/abi/selector.ts @@ -15,8 +15,8 @@ export abstract class Selector { } /** - * Checks if the selector is empty (all bytes are 0). - * @returns True if the selector is empty (all bytes are 0). + * Checks if the selector is default (all bytes are 0). + * @returns True if the selector is default (all bytes are 0). */ public isDefault(): boolean { return this.value === 0; diff --git a/yarn-project/merkle-tree/src/interfaces/indexed_tree.ts b/yarn-project/merkle-tree/src/interfaces/indexed_tree.ts index 6363ad62142..8f0deb779ea 100644 --- a/yarn-project/merkle-tree/src/interfaces/indexed_tree.ts +++ b/yarn-project/merkle-tree/src/interfaces/indexed_tree.ts @@ -22,7 +22,7 @@ export interface PreimageFactory { */ fromBuffer(buffer: Buffer): IndexedTreeLeafPreimage; /** - * Creates an empty preimage. + * Creates an default preimage. */ default(): IndexedTreeLeafPreimage; /** diff --git a/yarn-project/pxe/src/kernel_prover/hints_builder.ts b/yarn-project/pxe/src/kernel_prover/hints_builder.ts index e245cf9636f..89bcec0d223 100644 --- a/yarn-project/pxe/src/kernel_prover/hints_builder.ts +++ b/yarn-project/pxe/src/kernel_prover/hints_builder.ts @@ -29,7 +29,7 @@ export class HintsBuilder { const sorted = sideEffects .map((sideEffect, index) => ({ sideEffect, index })) .sort((a, b) => { - // Empty ones go to the right + // Default ones go to the right if (a.sideEffect.isDefault()) { return 1; } diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts index 29453a530ff..03a2670a6a8 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -127,7 +127,7 @@ export class KernelProver { } } - // fill in witnesses for remaining/empty read requests + // fill in witnesses for remaining/default read requests noteHashReadRequestMembershipWitnesses.push( ...Array(MAX_NOTE_HASH_READ_REQUESTS_PER_CALL - noteHashReadRequestMembershipWitnesses.length) .fill(0) @@ -237,7 +237,7 @@ export class KernelProver { const { contractAddress, functionData, publicInputs } = callStackItem; const { portalContractAddress } = publicInputs.callContext; - // Pad with empty items to reach max/const length expected by circuit. + // Pad with default items to reach max/const length expected by circuit. const privateCallStack = padArrayEnd( privateCallRequests, CallRequest.default(), From c9847c1a63887af888c0f02e4cc990bc743d92ab Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Mon, 1 Apr 2024 13:05:27 +0000 Subject: [PATCH 22/77] fixes --- .../crates/private-kernel-lib/src/common.nr | 8 ++++---- .../private-kernel-lib/src/private_kernel_inner.nr | 10 +++++----- .../private-kernel-lib/src/private_kernel_tail.nr | 4 ++-- .../crates/public-kernel-lib/src/common.nr | 6 +++--- .../public-kernel-lib/src/public_kernel_app_logic.nr | 4 ++-- .../public-kernel-lib/src/public_kernel_setup.nr | 8 ++++---- .../crates/public-kernel-lib/src/public_kernel_tail.nr | 4 ++-- .../public-kernel-lib/src/public_kernel_teardown.nr | 6 +++--- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr index ae09492da9c..1ba187136b0 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr @@ -121,14 +121,14 @@ fn perform_static_call_checks(private_call: PrivateCallData) { if is_static_call { // No state changes are allowed for static calls: assert( - is_default_array(public_inputs.new_note_hashes), "new_note_hashes must be empty for static calls" + is_default_array(public_inputs.new_note_hashes), "new_note_hashes must be default for static calls" ); assert( - is_default_array(public_inputs.new_nullifiers), "new_nullifiers must be empty for static calls" + is_default_array(public_inputs.new_nullifiers), "new_nullifiers must be default for static calls" ); let new_l2_to_l1_msgs_length = array_length(public_inputs.new_l2_to_l1_msgs); - assert(new_l2_to_l1_msgs_length == 0, "new_l2_to_l1_msgs must be empty for static calls"); + assert(new_l2_to_l1_msgs_length == 0, "new_l2_to_l1_msgs must be default for static calls"); // TODO: reevaluate when implementing https://github.com/AztecProtocol/aztec-packages/issues/1165 // This 4 magical number is the minimum size of the buffer, since it has to store the total length of all the serialized logs. @@ -359,7 +359,7 @@ pub fn validate_call_against_request(private_call: PrivateCallData, request: Cal if call_context.is_delegate_call { let caller_context = request.caller_context; - assert(!is_default(caller_context), "caller context cannot be empty for delegate calls"); + assert(!is_default(caller_context), "caller context cannot be default for delegate calls"); assert( call_context.msg_sender.eq(caller_context.msg_sender), "call stack msg_sender does not match expected msg_sender for delegate calls" ); 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 0d0908b25e4..5614110dbe1 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 @@ -218,13 +218,13 @@ mod tests { builder.succeeded(); } - #[test(should_fail_with="caller context cannot be empty for delegate calls")] - fn empty_caller_context_for_delegate_calls_fails() { + #[test(should_fail_with="caller context cannot be default for delegate calls")] + fn default_caller_context_for_delegate_calls_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_delegate_call(); let private_call = builder.private_call.finish(); let hash = private_call.call_stack_item.hash(); - // Caller context is empty for regular calls. + // Caller context is default for regular calls. let is_delegate_call = false; builder.previous_kernel.push_private_call_request(hash, is_delegate_call); let previous_kernel = builder.previous_kernel.to_private_kernel_inner_data(); @@ -707,7 +707,7 @@ mod tests { assert_eq(public_inputs.end.unencrypted_logs_hash, expected_unencrypted_logs_hash); } - #[test(should_fail_with="new_note_hashes must be empty for static calls")] + #[test(should_fail_with="new_note_hashes must be default for static calls")] fn creating_new_note_hashes_on_static_call_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_static_call(); @@ -716,7 +716,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_nullifiers must be empty for static calls")] + #[test(should_fail_with="new_nullifiers must be default for static calls")] fn creating_new_nullifiers_on_static_call_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_static_call(); 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 3d2f693e8c7..107788d1312 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 @@ -33,7 +33,7 @@ struct PrivateKernelTailCircuitPrivateInputs { impl PrivateKernelTailCircuitPrivateInputs { fn validate_inputs(self) { assert_eq( - array_length(self.previous_kernel.public_inputs.end.private_call_stack), 0, "Private call stack must be empty when executing the tail circuit" + array_length(self.previous_kernel.public_inputs.end.private_call_stack), 0, "Private call stack must be default when executing the tail circuit" ); } @@ -667,7 +667,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="Private call stack must be empty when executing the tail circuit")] + #[test(should_fail_with="Private call stack must be default when executing the tail circuit")] unconstrained fn non_empty_private_call_stack_should_fail() { let mut builder = PrivateKernelTailInputsBuilder::new(); builder.previous_kernel.push_private_call_request(1, false); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index 444649afa58..22e4a90f96d 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -111,10 +111,10 @@ fn perform_static_call_checks(public_call: PublicCallData) { if public_inputs.call_context.is_static_call { // No state changes are allowed for static calls: let new_note_hashes_length = array_length(public_inputs.new_note_hashes); - assert(new_note_hashes_length == 0, "new_note_hashes must be empty for static calls"); + assert(new_note_hashes_length == 0, "new_note_hashes must be default for static calls"); let new_nullifiers_length = array_length(public_inputs.new_nullifiers); - assert(new_nullifiers_length == 0, "new_nullifiers must be empty for static calls"); + assert(new_nullifiers_length == 0, "new_nullifiers must be default for static calls"); let update_requests_length = array_length(public_inputs.contract_storage_update_requests); assert( @@ -122,7 +122,7 @@ fn perform_static_call_checks(public_call: PublicCallData) { ); let new_l2_to_l1_msgs_length = array_length(public_inputs.new_l2_to_l1_msgs); - assert(new_l2_to_l1_msgs_length == 0, "new_l2_to_l1_msgs must be empty for static calls"); + assert(new_l2_to_l1_msgs_length == 0, "new_l2_to_l1_msgs must be default for static calls"); // TODO: reevaluate when implementing https://github.com/AztecProtocol/aztec-packages/issues/1165 // This 4 magical number is the minimum size of the buffer, since it has to store the total length of all the serialized logs. diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr index 60c98f50fae..115375f9b7f 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr @@ -341,7 +341,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_note_hashes must be empty for static calls")] + #[test(should_fail_with="new_note_hashes must be default for static calls")] fn public_kernel_fails_creating_new_note_hashes_on_static_call() { let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); builder.public_call.public_inputs.call_context.is_static_call = true; @@ -350,7 +350,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_nullifiers must be empty for static calls")] + #[test(should_fail_with="new_nullifiers must be default for static calls")] fn public_kernel_fails_creating_new_nullifiers_on_static_call() { let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); builder.public_call.public_inputs.call_context.is_static_call = true; diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr index e4913f12923..32e04d10115 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr @@ -275,15 +275,15 @@ mod tests { builder.succeeded(); } - #[test(should_fail_with="caller context cannot be empty for delegate calls")] - fn empty_caller_context_for_delegate_calls_fails() { + #[test(should_fail_with="caller context cannot be default for delegate calls")] + fn default_caller_context_for_delegate_calls_fails() { let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new().is_delegate_call(); builder.stub_teardown_call(); let public_call = builder.public_call.finish(); let hash = public_call.call_stack_item.hash(); - // Caller context is empty for regular calls. + // Caller context is default for regular calls. let is_delegate_call = false; builder.previous_kernel.push_public_call_request_non_revertible(hash, is_delegate_call); let previous_kernel = builder.previous_kernel.to_public_kernel_data(); @@ -404,7 +404,7 @@ mod tests { // assert_eq_public_data_reads(public_inputs.end.public_data_reads, read_requests); } - #[test(should_fail_with="Private call stack must be empty when executing in the public kernel")] + #[test(should_fail_with="Private call stack must be default when executing in the public kernel")] fn private_previous_kernel_non_empty_private_call_stack_should_fail() { let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); builder.previous_kernel.push_private_call_request(1, false); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr index 9a5517f6954..20ac2207a02 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr @@ -31,10 +31,10 @@ impl PublicKernelTailCircuitPrivateInputs { assert(previous_public_inputs.needs_app_logic == false, "Previous kernel needs app logic"); assert(previous_public_inputs.needs_teardown == false, "Previous kernel needs teardown"); assert_eq( - array_length(previous_public_inputs.end.public_call_stack), 0, "Public call stack must be empty when executing the tail circuit" + array_length(previous_public_inputs.end.public_call_stack), 0, "Public call stack must be default when executing the tail circuit" ); assert_eq( - array_length(previous_public_inputs.end_non_revertible.public_call_stack), 0, "Public call stack must be empty when executing the tail circuit" + array_length(previous_public_inputs.end_non_revertible.public_call_stack), 0, "Public call stack must be default when executing the tail circuit" ); } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr index 289f39beefc..dc139bf9a57 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr @@ -215,13 +215,13 @@ mod tests { builder.succeeded(); } - #[test(should_fail_with="caller context cannot be empty for delegate calls")] - fn empty_caller_context_for_delegate_calls_fails() { + #[test(should_fail_with="caller context cannot be default for delegate calls")] + fn default_caller_context_for_delegate_calls_fails() { let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new().is_delegate_call(); let public_call = builder.public_call.finish(); let hash = public_call.call_stack_item.hash(); - // Caller context is empty for regular calls. + // Caller context is default for regular calls. let is_delegate_call = false; builder.previous_kernel.push_public_call_request_non_revertible(hash, is_delegate_call); let previous_kernel = builder.previous_kernel.to_public_kernel_data(); From 6669380df244f2dcf22d7dcd3528047f665f097d Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Mon, 1 Apr 2024 14:36:04 +0000 Subject: [PATCH 23/77] fix --- yarn-project/foundation/src/aztec-address/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/foundation/src/aztec-address/index.ts b/yarn-project/foundation/src/aztec-address/index.ts index 1a9c8b20197..d572a7ae6c7 100644 --- a/yarn-project/foundation/src/aztec-address/index.ts +++ b/yarn-project/foundation/src/aztec-address/index.ts @@ -25,7 +25,7 @@ export class AztecAddress extends Fr { static ZERO = new AztecAddress(Buffer.alloc(32)); static default(): AztecAddress { - return AztecAddress.default(); + return AztecAddress.ZERO; } isDefault(): boolean { From b423c9a0d53335c0d11f4066ecf397a1a792f503 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 12:39:13 +0000 Subject: [PATCH 24/77] fix --- .../aztec/src/context/public_context.nr | 3 +- .../aztec-nr/aztec/src/initializer.nr | 2 +- .../kernel_circuit_public_inputs_composer.nr | 6 +- .../src/private_kernel_tail.nr | 9 +-- .../src/private_kernel_tail_to_public.nr | 18 +++--- .../private_validation_request_processor.nr | 4 +- .../rollup-lib/src/base/base_rollup_inputs.nr | 4 +- .../combined_accumulated_data.nr | 3 - .../combined_accumulated_data_builder.nr | 3 - .../private_accumulated_data_builder.nr | 22 +++++++- .../public_accumulated_data_builder.nr | 16 ++++++ .../crates/types/src/abis/function_data.nr | 1 - ...te_kernel_circuit_public_inputs_builder.nr | 3 +- .../public_kernel_circuit_public_inputs.nr | 7 ++- ...ic_kernel_circuit_public_inputs_builder.nr | 5 +- .../crates/types/src/tests/fixture_builder.nr | 36 +++++++++++- .../crates/types/src/utils/arrays.nr | 2 +- .../contract/contract_function_interaction.ts | 2 +- yarn-project/circuit-types/src/body.ts | 4 +- yarn-project/circuit-types/src/mocks.ts | 12 ++-- .../circuit-types/src/tx/processed_tx.ts | 6 +- yarn-project/circuit-types/src/tx/tx.ts | 6 +- .../circuit-types/src/tx_effect.test.ts | 2 +- yarn-project/circuit-types/src/tx_effect.ts | 2 +- .../kernel/combined_accumulated_data.ts | 4 +- .../kernel/kernel_circuit_public_inputs.ts | 4 +- .../kernel/private_accumulated_data.ts | 10 ++-- ...ivate_kernel_tail_circuit_public_inputs.ts | 14 ++--- .../structs/kernel/public_accumulated_data.ts | 20 +++---- .../public_kernel_circuit_public_inputs.ts | 6 +- .../circuits.js/src/tests/factories.ts | 56 +++++++++---------- yarn-project/circuits.js/src/utils/index.ts | 2 +- .../circuits.js/src/utils/utils.test.ts | 2 +- .../src/e2e_crowdfunding_and_claim.test.ts | 2 +- .../src/simulators/lending_simulator.ts | 4 +- yarn-project/foundation/src/array/array.ts | 10 ++-- .../foundation/src/collection/array.ts | 18 +++--- .../foundation/src/interfaces/index.ts | 4 +- .../src/orchestrator/orchestrator.ts | 2 +- .../pxe/src/pxe_service/pxe_service.ts | 10 ++-- .../src/sequencer/abstract_phase_manager.ts | 6 +- .../src/sequencer/hints_builder.ts | 4 +- .../src/sequencer/public_processor.test.ts | 16 +++--- .../src/sequencer/setup_phase_manager.test.ts | 2 +- .../src/sequencer/tail_phase_manager.ts | 2 +- .../src/sequencer/tx_validator.ts | 2 +- .../src/avm/opcodes/external_calls.ts | 2 +- .../src/avm/temporary_executor_migration.ts | 2 +- .../src/world-state-db/merkle_trees.ts | 4 +- 49 files changed, 224 insertions(+), 162 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index 779e169d998..8b3692c017d 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -68,7 +68,8 @@ impl PublicContext { unencrypted_logs_hash: 0, unencrypted_logs_preimages_length: 0, historical_header: inputs.historical_header, - prover_address: AztecAddress::default() // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) + prover_address: AztecAddress::default() + // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) // encrypted_logs_preimages: Vec::new(), // unencrypted_logs_preimages: Vec::new(), } diff --git a/noir-projects/aztec-nr/aztec/src/initializer.nr b/noir-projects/aztec-nr/aztec/src/initializer.nr index 127c1961672..a6021fa2faf 100644 --- a/noir-projects/aztec-nr/aztec/src/initializer.nr +++ b/noir-projects/aztec-nr/aztec/src/initializer.nr @@ -65,7 +65,7 @@ pub fn assert_initialization_matches_address_preimage_avm(context: AvmContext) { let expected_init = compute_initialization_hash(context.selector(), context.get_args_hash()); assert(instance.initialization_hash == expected_init, "Initialization hash does not match"); assert( - (instance.deployer.is_zero()) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer" + is_default(instance.deployer) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer" ); } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr index c2a16634303..ad495b68c8a 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr @@ -14,7 +14,7 @@ use dep::types::{ }, grumpkin_private_key::GrumpkinPrivateKey, hash::{compute_note_hash_nonce, compute_unique_siloed_note_hash}, - utils::arrays::{array_length, array_to_bounded_vec, assert_sorted_array}, traits::{Empty, is_empty} + utils::arrays::{array_length, array_to_bounded_vec, assert_sorted_array}, }; fn asc_sort_by_counters(a: T, b: T) -> bool where T: Ordered { @@ -178,8 +178,8 @@ impl KernelCircuitPublicInputsComposer { // match found! // squash both the nullifier and the hash // (set to 0 here and then rearrange array after loop) - new_note_hashes[hint_pos] = SideEffect::empty(); - new_nullifiers[n_idx] = SideEffectLinkedToNoteHash::empty(); + new_note_hashes[hint_pos] = SideEffect::default(); + new_nullifiers[n_idx] = SideEffectLinkedToNoteHash::default(); } // non-transient (persistable) nullifiers are just kept in new_nullifiers array and forwarded // to public inputs (used later by base rollup circuit) 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 0cb34e59f40..940e24f6703 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 @@ -63,17 +63,18 @@ mod tests { read_request_reset::{PendingReadHint, ReadRequestState, ReadRequestStatus} }; use dep::types::constants::{ - MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, - MAX_NULLIFIER_READ_REQUESTS_PER_TX + MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NULLIFIER_READ_REQUESTS_PER_TX, + MAX_NEW_NULLIFIERS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX }; use dep::types::{ abis::{ kernel_circuit_public_inputs::KernelCircuitPublicInputs, max_block_number::MaxBlockNumber, side_effect::{SideEffect, SideEffectLinkedToNoteHash, Ordered} }, + grumpkin_private_key::GrumpkinPrivateKey, hash::compute_unique_siloed_note_hashes, tests::{fixture_builder::FixtureBuilder, sort::sort_get_sorted_hints}, - utils::{arrays::{array_eq, array_length}}, traits::{Empty, is_default, is_default_array} + utils::{arrays::{array_eq, array_length}}, traits::{is_default, is_default_array} }; struct PrivateKernelTailInputsBuilder { @@ -316,7 +317,7 @@ mod tests { let public_inputs = builder.execute(); // Only the first nullifier is left after squashing. - assert(is_empty_default(public_inputs.end.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_note_hashes)); assert(array_eq(public_inputs.end.new_nullifiers, [new_nullifiers[0]])); } 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 7d0635d44c4..c344b5a958a 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 @@ -73,7 +73,7 @@ mod tests { }, hash::compute_unique_siloed_note_hashes, tests::{fixture_builder::FixtureBuilder, sort::sort_get_sorted_hints}, - utils::{arrays::{array_eq, array_length}}, traits::is_empty_array + utils::{arrays::{array_eq, array_length}}, traits::is_default_array }; struct PrivateKernelTailToPublicInputsBuilder { @@ -291,7 +291,7 @@ mod tests { builder.nullify_transient_note_hash(1, 0); let new_nullifiers = builder.previous_kernel.new_nullifiers.storage; let public_inputs = builder.execute(); - assert(is_empty_array(public_inputs.end.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_note_hashes)); // The nullifier at index 1 is chopped. assert( @@ -342,7 +342,7 @@ mod tests { let public_inputs = builder.execute(); // Only the first nullifier is left after squashing. - assert(is_empty_array(public_inputs.end.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_note_hashes)); assert(array_eq(public_inputs.end.new_nullifiers, [new_nullifiers[0]])); } @@ -356,8 +356,8 @@ mod tests { let sorted_note_hashes = builder.previous_kernel.new_note_hashes.storage; let sorted_nullifiers = builder.previous_kernel.new_nullifiers.storage; - let mut reversed_note_hashes = [SideEffect::empty(); 10]; - let mut reversed_nullifiers = [SideEffectLinkedToNoteHash::empty(); 10]; + let mut reversed_note_hashes = [SideEffect::default(); 10]; + let mut reversed_nullifiers = [SideEffectLinkedToNoteHash::default(); 10]; for i in 0..10 { reversed_note_hashes[9 - i] = builder.previous_kernel.new_note_hashes.pop(); @@ -505,9 +505,9 @@ mod tests { let public_inputs = builder.execute(); - assert(!is_empty_array(public_inputs.end_non_revertible.new_nullifiers)); - assert(is_empty_array(public_inputs.end_non_revertible.new_note_hashes)); - assert(is_empty_array(public_inputs.end.new_note_hashes)); - assert(is_empty_array(public_inputs.end.new_nullifiers)); + assert(!is_default_array(public_inputs.end_non_revertible.new_nullifiers)); + assert(is_default_array(public_inputs.end_non_revertible.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_nullifiers)); } } diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr index 9f60134dd45..b1745410087 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr @@ -6,7 +6,7 @@ use dep::types::{ MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX }, grumpkin_private_key::GrumpkinPrivateKey, keys::compute_siloed_nullifier_secret_key, - traits::is_empty + traits::is_default }; struct PrivateValidationRequestProcessor { @@ -60,7 +60,7 @@ impl PrivateValidationRequestProcessor { let requests = self.validation_requests.nullifier_key_validation_requests; for i in 0..MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX { let request = requests[i]; - if !is_empty(request) { + if !is_default(request) { let master_secret_key = self.master_nullifier_secret_keys[i]; let computed_public_key = master_secret_key.derive_public_key(); assert( diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr index e88667e6f15..93491bfd9bd 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -433,7 +433,7 @@ mod tests { snapshot: AppendOnlyTreeSnapshot, public_data_writes: BoundedVec<(u64, PublicDataTreeLeaf), 2>, mut pre_existing_public_data: [PublicDataTreeLeafPreimage; EXISTING_LEAVES] - ) -> ([Field; PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH], [PublicDataTreeLeaf; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], [u64; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], [PublicDataTreeLeafPreimage; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], [PublicDataMembershipWitness; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], [PublicDataTreeLeafPreimage; MAX_PUBLIC_DATA_READS_PER_TX], [PublicDataMembershipWitness; MAX_PUBLIC_DATA_READS_PER_TX], [PublicDataTreeLeafPreimage; EXISTING_LEAVES]) { + ) -> ([Field; 35], [PublicDataTreeLeaf; 32], [u64; 32], [PublicDataTreeLeafPreimage; 32], [PublicDataMembershipWitness; 32], [PublicDataTreeLeafPreimage; EXISTING_LEAVES]) { let mut subtree_path = [0; PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH]; let mut sorted_public_data_writes = [PublicDataTreeLeaf::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; let mut sorted_public_data_writes_indexes = [0 as u64; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; @@ -521,7 +521,7 @@ mod tests { impl Default for BaseRollupInputsBuilder { fn default() -> Self { BaseRollupInputsBuilder { - kernel_data: PreviousKernelDataBuilder::default(), + kernel_data: FixtureBuilder::new(), pre_existing_notes: [0; MAX_NEW_NOTE_HASHES_PER_TX], pre_existing_nullifiers: [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX], pre_existing_contracts: [0; 2], diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr index 8fb6d6f493f..ae7b85a30a2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr @@ -30,11 +30,8 @@ struct CombinedAccumulatedData { impl Default for CombinedAccumulatedData { fn default() -> Self { CombinedAccumulatedData { - revert_code: 0 as u8, new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_TX], new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_TX], - private_call_stack: [CallRequest::default(); MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], - public_call_stack: [CallRequest::default(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], new_l2_to_l1_msgs: [0; MAX_NEW_L2_TO_L1_MSGS_PER_TX], encrypted_logs_hash: 0, unencrypted_logs_hash: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr index 60a8244688b..b0b39b87137 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr @@ -29,11 +29,8 @@ struct CombinedAccumulatedDataBuilder { impl Default for CombinedAccumulatedDataBuilder { fn default() -> Self { CombinedAccumulatedDataBuilder { - revert_code: 0 as u8, new_note_hashes: BoundedVec::new(), new_nullifiers: BoundedVec::new(), - private_call_stack: BoundedVec::new(), - public_call_stack: BoundedVec::new(), new_l2_to_l1_msgs: BoundedVec::new(), encrypted_logs_hash: 0, unencrypted_logs_hash: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr index 0fed9cb468f..74e83c50a16 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr @@ -33,6 +33,22 @@ struct PrivateAccumulatedDataBuilder { public_call_stack: BoundedVec, } +impl Default for PrivateAccumulatedDataBuilder { + fn default() -> Self { + PrivateAccumulatedDataBuilder { + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + new_l2_to_l1_msgs: BoundedVec::new(), + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + private_call_stack: BoundedVec::new(), + public_call_stack: BoundedVec::new(), + } + } +} + impl PrivateAccumulatedDataBuilder { pub fn finish(self) -> PrivateAccumulatedData { PrivateAccumulatedData { @@ -134,14 +150,14 @@ mod tests { CallRequest { hash: 1, caller_contract_address: AztecAddress::from_field(1), - caller_context: CallerContext::empty(), + caller_context: CallerContext::default(), start_side_effect_counter: 5, end_side_effect_counter: 0 }, CallRequest { hash: 2, caller_contract_address: AztecAddress::from_field(1), - caller_context: CallerContext::empty(), + caller_context: CallerContext::default(), start_side_effect_counter: 6, end_side_effect_counter: 0 } @@ -161,7 +177,7 @@ mod tests { CallRequest { hash: 3, caller_contract_address: AztecAddress::from_field(3), - caller_context: CallerContext::empty(), + caller_context: CallerContext::default(), start_side_effect_counter: 9, end_side_effect_counter: 0 } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr index 0740f852f32..141e2a324b0 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr @@ -28,6 +28,22 @@ struct PublicAccumulatedDataBuilder { public_call_stack: BoundedVec, } +impl Default for PublicAccumulatedDataBuilder { + fn default() -> Self { + PublicAccumulatedDataBuilder { + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + new_l2_to_l1_msgs: BoundedVec::new(), + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + public_data_update_requests: BoundedVec::new(), + public_call_stack: BoundedVec::new(), + } + } +} + impl PublicAccumulatedDataBuilder { pub fn finish(self) -> PublicAccumulatedData { PublicAccumulatedData { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr index d874d50d46d..9331ec27e2c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr @@ -21,7 +21,6 @@ impl Default for FunctionData { FunctionData { selector: FunctionSelector::default(), is_private: false, - is_transpiled: false, } } } 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 9f2c7311c19..dc211a13ea4 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 @@ -24,9 +24,8 @@ impl Default for PrivateKernelCircuitPublicInputsBuilder { aggregation_object: AggregationObject::default(), min_revertible_side_effect_counter: 0 as u32, validation_requests: ValidationRequestsBuilder::default(), - end: CombinedAccumulatedDataBuilder::default(), + end: PrivateAccumulatedDataBuilder::default(), constants: CombinedConstantData::default(), - is_private: false, } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr index 2441851f617..9873d891a59 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr @@ -3,6 +3,7 @@ use crate::abis::{ validation_requests::{RollupValidationRequests, ValidationRequests} }; use crate::mocked::AggregationObject; +use crate::traits::is_default; struct PublicKernelCircuitPublicInputs { aggregation_object: AggregationObject, @@ -18,17 +19,17 @@ impl PublicKernelCircuitPublicInputs { // By definition, the final non-revertible enqueued call is for teardown. // since this is a stack, the teardown call would be the 0th element. // So if we have more than one element, we need setup. - !self.end_non_revertible.public_call_stack[1].is_empty() + !is_default(self.end_non_revertible.public_call_stack[1]) } pub fn needs_app_logic(self) -> bool { // if we have any enqueued revertible public calls, we need to run the public app logic circuit. - !self.end.public_call_stack[0].is_empty() + !is_default(self.end.public_call_stack[0]) } pub fn needs_teardown(self) -> bool { // By definition, the final non-revertible enqueued call is for teardown. // since this is a stack, the teardown call would be the 0th element. - !self.end_non_revertible.public_call_stack[0].is_empty() + !is_default(self.end_non_revertible.public_call_stack[0]) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr index beaaa67c2df..1fd3a5cef74 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr @@ -23,9 +23,10 @@ impl Default for PublicKernelCircuitPublicInputsBuilder { PublicKernelCircuitPublicInputsBuilder { aggregation_object: AggregationObject::default(), validation_requests: ValidationRequestsBuilder::default(), - end_non_revertible: AccumulatedNonRevertibleDataBuilder::default(), - end: AccumulatedRevertibleDataBuilder::default(), + end_non_revertible: PublicAccumulatedDataBuilder::default(), + end: PublicAccumulatedDataBuilder::default(), constants: CombinedConstantData::default(), + revert_code: 0, } } } 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 4fa846432b5..9a1c99209c5 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 @@ -67,6 +67,40 @@ struct FixtureBuilder { counter: u32, } +impl Default for FixtureBuilder { + fn default() -> Self { + FixtureBuilder { + contract_address: AztecAddress::default(), + storage_contract_address: AztecAddress::default(), + historical_header: Header::default(), + tx_context: TxContext::default(), + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + new_l2_to_l1_msgs: BoundedVec::new(), + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + public_data_update_requests: BoundedVec::new(), + private_call_stack: BoundedVec::new(), + public_call_stack: BoundedVec::new(), + max_block_number: MaxBlockNumber::default(), + note_hash_read_requests: BoundedVec::new(), + nullifier_read_requests: BoundedVec::new(), + nullifier_non_existent_read_requests: BoundedVec::new(), + nullifier_key_validation_requests: BoundedVec::new(), + public_data_reads: BoundedVec::new(), + proof: Proof::default(), + vk: VerificationKey::default(), + vk_index: 0, + vk_path: [0; VK_TREE_HEIGHT], + revert_code: 0, + min_revertible_side_effect_counter: 0, + counter: 0 + } + } +} + impl FixtureBuilder { pub fn new() -> Self { let tx_context = TxContext { is_fee_payment_tx: false, is_rebate_payment_tx: false, chain_id: 1, version: 0 }; @@ -345,7 +379,7 @@ impl FixtureBuilder { } fn generate_call_request(&mut self, hash: Field, is_delegate_call: bool) -> CallRequest { - let mut caller_context = CallerContext::empty(); + let mut caller_context = CallerContext::default(); if is_delegate_call { caller_context.msg_sender = fixtures::MSG_SENDER; caller_context.storage_contract_address = self.contract_address; 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 a35fd95a5a0..e891e93a879 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 @@ -75,7 +75,7 @@ pub fn array_cp(array: [T; N]) -> [T; S] where T: Default { result } -pub fn array_merge(array1: [T; N], array2: [T; N]) -> [T; N] where T: Empty + Eq { +pub fn array_merge(array1: [T; N], array2: [T; N]) -> [T; N] where T: Default + Eq { let mut result: [T; N] = [T::default(); N]; let mut i = 0; for elem in array1 { diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts index a79e8c652f4..e3b63298c8e 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -95,7 +95,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction { argsHash: packedArgs.hash, origin: this.contractAddress, functionData: FunctionData.fromAbi(this.functionDao), - txContext: TxContext.empty(nodeInfo.chainId, nodeInfo.protocolVersion), + txContext: TxContext.default(nodeInfo.chainId, nodeInfo.protocolVersion), packedArguments: [packedArgs], authWitnesses: [], }); diff --git a/yarn-project/circuit-types/src/body.ts b/yarn-project/circuit-types/src/body.ts index 5f262920aa1..ed488e996f6 100644 --- a/yarn-project/circuit-types/src/body.ts +++ b/yarn-project/circuit-types/src/body.ts @@ -8,7 +8,7 @@ import { inspect } from 'util'; export class Body { constructor(public txEffects: TxEffect[]) { txEffects.forEach(txEffect => { - if (txEffect.isEmpty()) { + if (txEffect.isDefault()) { throw new Error('Empty tx effect not allowed in Body'); } }); @@ -66,7 +66,7 @@ export class Body { return layers[layers.length - 1][0]; }; - const emptyTxEffectHash = TxEffect.empty().hash(); + const emptyTxEffectHash = TxEffect.default().hash(); const leaves: Buffer[] = padArrayEnd( this.txEffects.map(txEffect => txEffect.hash()), emptyTxEffectHash, diff --git a/yarn-project/circuit-types/src/mocks.ts b/yarn-project/circuit-types/src/mocks.ts index 2bf236c3d92..dbca9e5026a 100644 --- a/yarn-project/circuit-types/src/mocks.ts +++ b/yarn-project/circuit-types/src/mocks.ts @@ -48,23 +48,23 @@ export const mockTx = ( const publicCallRequests = times(totalPublicCallRequests, i => makePublicCallRequest(seed + 0x100 + i)); const isForPublic = totalPublicCallRequests > 0; - const data = PrivateKernelTailCircuitPublicInputs.empty(); + const data = PrivateKernelTailCircuitPublicInputs.default(); const firstNullifier = new SideEffectLinkedToNoteHash(new Fr(seed), new Fr(seed + 1), Fr.ZERO); if (isForPublic) { data.forRollup = undefined; - data.forPublic = PartialPrivateTailPublicInputsForPublic.empty(); + data.forPublic = PartialPrivateTailPublicInputsForPublic.default(); data.forPublic.endNonRevertibleData.newNullifiers[0] = firstNullifier; data.forPublic.endNonRevertibleData.publicCallStack = makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, i => - i < numberOfNonRevertiblePublicCallRequests ? publicCallRequests[i].toCallRequest() : CallRequest.empty(), + i < numberOfNonRevertiblePublicCallRequests ? publicCallRequests[i].toCallRequest() : CallRequest.default(), ); data.forPublic.end.publicCallStack = makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, i => i < numberOfRevertiblePublicCallRequests ? publicCallRequests[i + numberOfNonRevertiblePublicCallRequests].toCallRequest() - : CallRequest.empty(), + : CallRequest.default(), ); } else { data.forRollup!.end.newNullifiers[0] = firstNullifier; @@ -72,8 +72,8 @@ export const mockTx = ( const target = isForPublic ? data.forPublic! : data.forRollup!; - const encryptedLogs = hasLogs ? EncryptedTxL2Logs.random(8, 3) : EncryptedTxL2Logs.empty(); // 8 priv function invocations creating 3 encrypted logs each - const unencryptedLogs = hasLogs ? UnencryptedTxL2Logs.random(11, 2) : UnencryptedTxL2Logs.empty(); // 8 priv function invocations creating 3 encrypted logs each + const encryptedLogs = hasLogs ? EncryptedTxL2Logs.random(8, 3) : EncryptedTxL2Logs.default(); // 8 priv function invocations creating 3 encrypted logs each + const unencryptedLogs = hasLogs ? UnencryptedTxL2Logs.random(11, 2) : UnencryptedTxL2Logs.default(); // 8 priv function invocations creating 3 encrypted logs each if (!hasLogs) { target.end.encryptedLogsHash = Fr.ZERO; target.end.unencryptedLogsHash = Fr.ZERO; diff --git a/yarn-project/circuit-types/src/tx/processed_tx.ts b/yarn-project/circuit-types/src/tx/processed_tx.ts index b1b05681b64..63cad5cba7f 100644 --- a/yarn-project/circuit-types/src/tx/processed_tx.ts +++ b/yarn-project/circuit-types/src/tx/processed_tx.ts @@ -34,7 +34,7 @@ export type ProcessedTx = Pick { }); it('hash of empty tx effect matches snapshot', () => { - const txEffectHash = TxEffect.empty().hash().toString('hex'); + const txEffectHash = TxEffect.default().hash().toString('hex'); // If you change this you have to change the hardcoded value in TxsDecoder.sol! expect(txEffectHash).toMatchInlineSnapshot(`"0071f7630d28ce02cc1ca8b15c44953f84a39e1478445395247ae04dfa213c0e"`); }); diff --git a/yarn-project/circuit-types/src/tx_effect.ts b/yarn-project/circuit-types/src/tx_effect.ts index 9006c3e2096..6139cdaa0eb 100644 --- a/yarn-project/circuit-types/src/tx_effect.ts +++ b/yarn-project/circuit-types/src/tx_effect.ts @@ -81,7 +81,7 @@ export class TxEffect { ); } publicDataWrites.forEach(h => { - if (h.isEmpty()) { + if (h.isDefault()) { throw new Error('Public data write is empty'); } }); diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts index 2086add1e57..bc2acf770d8 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts @@ -100,8 +100,8 @@ export class CombinedAccumulatedData { static default() { return new CombinedAccumulatedData( - makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.defaul), - makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.defaul), + makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.default), + makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), Fr.zero(), Fr.zero(), diff --git a/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts index fcb07ec0e3d..9f61dc43321 100644 --- a/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts @@ -34,8 +34,8 @@ export class KernelCircuitPublicInputs { public revertCode: RevertCode, ) {} - getNonEmptyNullifiers() { - return this.end.newNullifiers.filter(n => !n.isEmpty()); + getNonDefaultNullifiers() { + return this.end.newNullifiers.filter(n => !n.isDefault()); } toBuffer() { diff --git a/yarn-project/circuits.js/src/structs/kernel/private_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_accumulated_data.ts index 8334b019fe4..deca14930f2 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_accumulated_data.ts @@ -107,17 +107,17 @@ export class PrivateAccumulatedData { return PrivateAccumulatedData.fromBuffer(Buffer.from(str, 'hex')); } - static empty() { + static default() { return new PrivateAccumulatedData( - makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.empty), - makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.empty), + makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.default), + makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), Fr.zero(), Fr.zero(), Fr.zero(), Fr.zero(), - makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, CallRequest.empty), - makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.empty), + makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, CallRequest.default), + makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default), ); } } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts index 8976a824826..f16186b5b22 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts @@ -29,15 +29,15 @@ export class PartialPrivateTailPublicInputsForPublic { ) {} get needsSetup() { - return !this.endNonRevertibleData.publicCallStack[1].isEmpty(); + return !this.endNonRevertibleData.publicCallStack[1].isDefault(); } get needsAppLogic() { - return !this.end.publicCallStack[0].isEmpty(); + return !this.end.publicCallStack[0].isDefault(); } get needsTeardown() { - return !this.endNonRevertibleData.publicCallStack[0].isEmpty(); + return !this.endNonRevertibleData.publicCallStack[0].isDefault(); } static fromBuffer(buffer: Buffer | BufferReader): PartialPrivateTailPublicInputsForPublic { @@ -146,7 +146,7 @@ export class PrivateKernelTailCircuitPublicInputs { : 0; } - getNonEmptyNoteHashes() { + getNonDefaultNoteHashes() { const noteHashes = this.forPublic ? mergeAccumulatedData( MAX_NEW_NULLIFIERS_PER_TX, @@ -154,10 +154,10 @@ export class PrivateKernelTailCircuitPublicInputs { this.forPublic.end.newNoteHashes, ) : this.forRollup!.end.newNoteHashes; - return noteHashes.filter(n => !n.isEmpty()); + return noteHashes.filter(n => !n.isDefault()); } - getNonEmptyNullifiers() { + getNonDefaultNullifiers() { const nullifiers = this.forPublic ? mergeAccumulatedData( MAX_NEW_NULLIFIERS_PER_TX, @@ -165,7 +165,7 @@ export class PrivateKernelTailCircuitPublicInputs { this.forPublic.end.newNullifiers, ) : this.forRollup!.end.newNullifiers; - return nullifiers.filter(n => !n.isEmpty()); + return nullifiers.filter(n => !n.isDefault()); } static fromBuffer(buffer: Buffer | BufferReader): PrivateKernelTailCircuitPublicInputs { diff --git a/yarn-project/circuits.js/src/structs/kernel/public_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/public_accumulated_data.ts index 737a4ce608f..ff560bbf2b1 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_accumulated_data.ts @@ -76,17 +76,17 @@ export class PublicAccumulatedData { return this.toBuffer().toString('hex'); } - isEmpty(): boolean { + isDefault(): boolean { return ( - this.newNoteHashes.every(x => x.isEmpty()) && - this.newNullifiers.every(x => x.isEmpty()) && + this.newNoteHashes.every(x => x.isDefault()) && + this.newNullifiers.every(x => x.isDefault()) && this.newL2ToL1Msgs.every(x => x.isZero()) && this.encryptedLogsHash.isZero() && this.unencryptedLogsHash.isZero() && this.encryptedLogPreimagesLength.isZero() && this.unencryptedLogPreimagesLength.isZero() && - this.publicDataUpdateRequests.every(x => x.isEmpty()) && - this.publicCallStack.every(x => x.isEmpty()) + this.publicDataUpdateRequests.every(x => x.isDefault()) && + this.publicCallStack.every(x => x.isDefault()) ); } @@ -134,17 +134,17 @@ export class PublicAccumulatedData { return this.fromBuffer(Buffer.from(str, 'hex')); } - static empty() { + static default() { return new this( - makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.empty), - makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.empty), + makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.default), + makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), Fr.zero(), Fr.zero(), Fr.zero(), Fr.zero(), - makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.empty), - makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.empty), + makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.default), + makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default), ); } } diff --git a/yarn-project/circuits.js/src/structs/kernel/public_kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/public_kernel_circuit_public_inputs.ts index a5cc4c3394e..58c7a6a510d 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_kernel_circuit_public_inputs.ts @@ -52,15 +52,15 @@ export class PublicKernelCircuitPublicInputs { } get needsSetup() { - return !this.endNonRevertibleData.publicCallStack[1].isEmpty(); + return !this.endNonRevertibleData.publicCallStack[1].isDefault(); } get needsAppLogic() { - return !this.end.publicCallStack[0].isEmpty(); + return !this.end.publicCallStack[0].isDefault(); } get needsTeardown() { - return !this.endNonRevertibleData.publicCallStack[0].isEmpty(); + return !this.endNonRevertibleData.publicCallStack[0].isDefault(); } /** diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index ea651678f24..17ad9833dc6 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -221,10 +221,10 @@ export function makePublicDataUpdateRequest(seed = 1): PublicDataUpdateRequest { } /** - * Creates empty public data update request. - * @returns An empty public data update request. + * Creates default public data update request. + * @returns An default public data update request. */ -export function makeEmptyPublicDataUpdateRequest(): PublicDataUpdateRequest { +export function makeDefaultPublicDataUpdateRequest(): PublicDataUpdateRequest { return new PublicDataUpdateRequest(fr(0), fr(0)); } @@ -238,10 +238,10 @@ export function makePublicDataRead(seed = 1): PublicDataRead { } /** - * Creates empty public data read. - * @returns An empty public data read. + * Creates default public data read. + * @returns An default public data read. */ -export function makeEmptyPublicDataRead(): PublicDataRead { +export function makeDefaultPublicDataRead(): PublicDataRead { return new PublicDataRead(fr(0), fr(0)); } @@ -287,12 +287,12 @@ export function makeCombinedAccumulatedData(seed = 1, full = false): CombinedAcc const tupleGenerator = full ? makeTuple : makeHalfFullTuple; return new CombinedAccumulatedData( - tupleGenerator(MAX_NEW_NOTE_HASHES_PER_TX, sideEffectFromNumber, seed + 0x120, SideEffect.empty), + tupleGenerator(MAX_NEW_NOTE_HASHES_PER_TX, sideEffectFromNumber, seed + 0x120, SideEffect.default), tupleGenerator( MAX_NEW_NULLIFIERS_PER_TX, sideEffectLinkedFromNumber, seed + 0x200, - SideEffectLinkedToNoteHash.empty, + SideEffectLinkedToNoteHash.default, ), tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.zero), fr(seed + 0x700), // encrypted logs hash @@ -303,7 +303,7 @@ export function makeCombinedAccumulatedData(seed = 1, full = false): CombinedAcc MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, makePublicDataUpdateRequest, seed + 0xd00, - PublicDataUpdateRequest.empty, + PublicDataUpdateRequest.default, ), ); } @@ -317,12 +317,12 @@ export function makePublicAccumulatedData(seed = 1, full = false): PublicAccumul const tupleGenerator = full ? makeTuple : makeHalfFullTuple; return new PublicAccumulatedData( - tupleGenerator(MAX_NEW_NOTE_HASHES_PER_TX, sideEffectFromNumber, seed + 0x120, SideEffect.empty), + tupleGenerator(MAX_NEW_NOTE_HASHES_PER_TX, sideEffectFromNumber, seed + 0x120, SideEffect.default), tupleGenerator( MAX_NEW_NULLIFIERS_PER_TX, sideEffectLinkedFromNumber, seed + 0x200, - SideEffectLinkedToNoteHash.empty, + SideEffectLinkedToNoteHash.default, ), tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.zero), fr(seed + 0x700), // encrypted logs hash @@ -333,9 +333,9 @@ export function makePublicAccumulatedData(seed = 1, full = false): PublicAccumul MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, makePublicDataUpdateRequest, seed + 0xd00, - PublicDataUpdateRequest.empty, + PublicDataUpdateRequest.default, ), - tupleGenerator(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, makeCallRequest, seed + 0x500, CallRequest.empty), + tupleGenerator(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, makeCallRequest, seed + 0x500, CallRequest.default), ); } @@ -348,20 +348,20 @@ export function makePrivateAccumulatedData(seed = 1, full = false) { const tupleGenerator = full ? makeTuple : makeHalfFullTuple; return new PrivateAccumulatedData( - tupleGenerator(MAX_NEW_NOTE_HASHES_PER_TX, sideEffectFromNumber, seed + 0x120, SideEffect.empty), + tupleGenerator(MAX_NEW_NOTE_HASHES_PER_TX, sideEffectFromNumber, seed + 0x120, SideEffect.default), tupleGenerator( MAX_NEW_NULLIFIERS_PER_TX, sideEffectLinkedFromNumber, seed + 0x200, - SideEffectLinkedToNoteHash.empty, + SideEffectLinkedToNoteHash.default, ), tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.zero), fr(seed + 0x700), // encrypted logs hash fr(seed + 0x800), // unencrypted logs hash fr(seed + 0x900), // encrypted_log_preimages_length fr(seed + 0xa00), // unencrypted_log_preimages_length - tupleGenerator(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, makeCallRequest, seed + 0x400, CallRequest.empty), - tupleGenerator(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, makeCallRequest, seed + 0x500, CallRequest.empty), + tupleGenerator(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, makeCallRequest, seed + 0x400, CallRequest.default), + tupleGenerator(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, makeCallRequest, seed + 0x500, CallRequest.default), ); } @@ -414,24 +414,24 @@ export function makePublicCircuitPublicInputs( makeCallContext(seed, storageContractAddress), fr(seed + 0x100), tupleGenerator(RETURN_VALUES_LENGTH, fr, seed + 0x200, Fr.zero), - tupleGenerator(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x400, ReadRequest.empty), - tupleGenerator(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x420, ReadRequest.empty), + tupleGenerator(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x400, ReadRequest.default), + tupleGenerator(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x420, ReadRequest.default), tupleGenerator( MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, makeContractStorageUpdateRequest, seed + 0x400, - ContractStorageUpdateRequest.empty, + ContractStorageUpdateRequest.default, ), - tupleGenerator(MAX_PUBLIC_DATA_READS_PER_CALL, makeContractStorageRead, seed + 0x500, ContractStorageRead.empty), + tupleGenerator(MAX_PUBLIC_DATA_READS_PER_CALL, makeContractStorageRead, seed + 0x500, ContractStorageRead.default), tupleGenerator(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, fr, seed + 0x600, Fr.zero), - tupleGenerator(MAX_NEW_NOTE_HASHES_PER_CALL, makeNewSideEffect, seed + 0x700, SideEffect.empty), + tupleGenerator(MAX_NEW_NOTE_HASHES_PER_CALL, makeNewSideEffect, seed + 0x700, SideEffect.default), tupleGenerator( MAX_NEW_NULLIFIERS_PER_CALL, makeNewSideEffectLinkedToNoteHash, seed + 0x800, - SideEffectLinkedToNoteHash.empty, + SideEffectLinkedToNoteHash.default, ), - tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, makeL2ToL1Message, seed + 0x900, L2ToL1Message.empty), + tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, makeL2ToL1Message, seed + 0x900, L2ToL1Message.default), fr(seed + 0xa00), fr(seed + 0xa01), fr(seed + 0x901), @@ -487,7 +487,7 @@ export function makePrivateKernelTailCircuitPublicInputs( ): PrivateKernelTailCircuitPublicInputs { const forPublic = isForPublic ? new PartialPrivateTailPublicInputsForPublic( - ValidationRequests.empty(), + ValidationRequests.default(), makePublicAccumulatedData(seed + 0x100, false), makePublicAccumulatedData(seed + 0x200, false), ) @@ -582,11 +582,11 @@ export function makeNoteHashReadRequestMembershipWitness(start: number): NoteHas } /** - * Creates empty membership witness where the sibling paths is an array of fields filled with zeros. + * Creates default membership witness where the sibling paths is an array of fields filled with zeros. * @param start - The start of the membership witness. - * @returns Non-transient empty read request membership witness. + * @returns Non-transient default read request membership witness. */ -export function makeEmptyNoteHashReadRequestMembershipWitness(): NoteHashReadRequestMembershipWitness { +export function makeDefaultNoteHashReadRequestMembershipWitness(): NoteHashReadRequestMembershipWitness { return new NoteHashReadRequestMembershipWitness( new Fr(0), makeTuple(NOTE_HASH_TREE_HEIGHT, Fr.zero), diff --git a/yarn-project/circuits.js/src/utils/index.ts b/yarn-project/circuits.js/src/utils/index.ts index ddb8dc812cb..a1170cda41d 100644 --- a/yarn-project/circuits.js/src/utils/index.ts +++ b/yarn-project/circuits.js/src/utils/index.ts @@ -1,4 +1,4 @@ -import { type IsEmpty } from '@aztec/foundation/interfaces'; +import { type IsDefault } from '@aztec/foundation/interfaces'; import { type Tuple } from '@aztec/foundation/serialize'; // Define these utils here as their design is very specific to kernel's accumulated data and not general enough to be put in foundation. diff --git a/yarn-project/circuits.js/src/utils/utils.test.ts b/yarn-project/circuits.js/src/utils/utils.test.ts index 28dd8012566..bd535a4b840 100644 --- a/yarn-project/circuits.js/src/utils/utils.test.ts +++ b/yarn-project/circuits.js/src/utils/utils.test.ts @@ -1,5 +1,5 @@ import { makeTuple } from '@aztec/foundation/array'; -import { type IsEmpty } from '@aztec/foundation/interfaces'; +import { type IsDefault } from '@aztec/foundation/interfaces'; import { type Tuple } from '@aztec/foundation/serialize'; import { concatAccumulatedData, countAccumulatedItems, mergeAccumulatedData } from './index.js'; diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index bb33616a2d1..19754d39961 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -1,6 +1,6 @@ import { type AccountWallet, - type AztecAddress, + AztecAddress, type CheatCodes, type DebugLogger, ExtendedNote, diff --git a/yarn-project/end-to-end/src/simulators/lending_simulator.ts b/yarn-project/end-to-end/src/simulators/lending_simulator.ts index 95805f00421..e5e387e73ab 100644 --- a/yarn-project/end-to-end/src/simulators/lending_simulator.ts +++ b/yarn-project/end-to-end/src/simulators/lending_simulator.ts @@ -1,5 +1,5 @@ // Convenience struct to hold an account's address and secret that can easily be passed around. -import { type AztecAddress, type CheatCodes, Fr } from '@aztec/aztec.js'; +import { AztecAddress, type CheatCodes, Fr } from '@aztec/aztec.js'; import { pedersenHash } from '@aztec/foundation/crypto'; import { type LendingContract } from '@aztec/noir-contracts.js/Lending'; @@ -173,7 +173,7 @@ export class LendingSimulator { expect(asset['last_updated_ts']).toEqual(BigInt(this.time)); for (const key of [this.account.address, this.account.key()]) { - const privatePos = await this.lendingContract.methods.get_position(key).simulate(); + const privatePos = await this.lendingContract.methods.get_position(AztecAddress.fromField(key)).simulate(); expect(new Fr(privatePos['collateral'])).toEqual(this.collateral[key.toString()] ?? Fr.ZERO); expect(new Fr(privatePos['static_debt'])).toEqual(this.staticDebt[key.toString()] ?? Fr.ZERO); expect(privatePos['debt']).toEqual( diff --git a/yarn-project/foundation/src/array/array.ts b/yarn-project/foundation/src/array/array.ts index a7f1d7a18fc..662cf294c98 100644 --- a/yarn-project/foundation/src/array/array.ts +++ b/yarn-project/foundation/src/array/array.ts @@ -28,7 +28,7 @@ export function makeTuple(length: N, fn: (i: number) => T, } /** - * Create an array over an integer range, filled with a function 'fn'. However, the latter half of the array are set to zeros. + * Create an array over an integer range, filled with a function 'fn'. However, the latter half of the array are set to default. * see `makeTuple` above. * @param n - The number of integers. * @param fn - The generator function. @@ -38,9 +38,9 @@ export function makeHalfFullTuple( length: N, fn: (i: number) => T, offset = 0, - makeEmpty: () => T, + makeDefault: () => T, ) { - return Array.from({ length }, (v: any, i: number) => (i < length / 2 ? fn(i + offset) : makeEmpty())) as Tuple; + return Array.from({ length }, (v: any, i: number) => (i < length / 2 ? fn(i + offset) : makeDefault())) as Tuple; } /** @@ -123,10 +123,10 @@ export function assertPermutation( } } -export function assertRightPadded(arr: T[], isEmpty: (item: T) => boolean) { +export function assertRightPadded(arr: T[], isDefault: (item: T) => boolean) { let seenEmpty = false; for (let i = 0; i < arr.length; i++) { - if (isEmpty(arr[i])) { + if (isDefault(arr[i])) { seenEmpty = true; } else if (seenEmpty) { throw new Error(`Non-empty element at index [${i}] after empty element`); diff --git a/yarn-project/foundation/src/collection/array.ts b/yarn-project/foundation/src/collection/array.ts index 3a397db8b50..5703b7e1395 100644 --- a/yarn-project/foundation/src/collection/array.ts +++ b/yarn-project/foundation/src/collection/array.ts @@ -16,8 +16,8 @@ export function padArrayEnd(arr: T[], elem: T, length: N): } /** Removes the right-padding for an array. Does not modify original array. */ -export function removeArrayPaddingEnd(arr: T[], isEmpty: (item: T) => boolean): T[] { - const lastNonEmptyIndex = arr.reduce((last, item, i) => (isEmpty(item) ? last : i), -1); +export function removeArrayPaddingEnd(arr: T[], isDefault: (item: T) => boolean): T[] { + const lastNonEmptyIndex = arr.reduce((last, item, i) => (isDefault(item) ? last : i), -1); return lastNonEmptyIndex === -1 ? [] : arr.slice(0, lastNonEmptyIndex + 1); } @@ -39,11 +39,11 @@ export function padArrayStart(arr: T[], elem: T, length: N) /** * Returns if an array is composed of empty items. * @param arr - Array to check. - * @returns True if every item in the array isEmpty. + * @returns True if every item in the array isDefault. */ -export function isArrayEmpty(arr: T[], isEmpty: (item: T) => boolean): boolean { +export function isArrayEmpty(arr: T[], isDefault: (item: T) => boolean): boolean { for (const item of arr) { - if (!isEmpty(item)) { + if (!isDefault(item)) { return false; } } @@ -51,12 +51,12 @@ export function isArrayEmpty(arr: T[], isEmpty: (item: T) => boolean): boolea } /** - * Returns the number of non-empty items in an array. + * Returns the number of non-default items in an array. * @param arr - Array to check. - * @returns Number of non-empty items in an array. + * @returns Number of non-default items in an array. */ -export function arrayNonEmptyLength(arr: T[], isEmpty: (item: T) => boolean): number { - return arr.reduce((sum, item) => (isEmpty(item) ? sum : sum + 1), 0); +export function arrayNonDefaultLength(arr: T[], isDefault: (item: T) => boolean): number { + return arr.reduce((sum, item) => (isDefault(item) ? sum : sum + 1), 0); } /** diff --git a/yarn-project/foundation/src/interfaces/index.ts b/yarn-project/foundation/src/interfaces/index.ts index 5672d325649..b25aa6894e7 100644 --- a/yarn-project/foundation/src/interfaces/index.ts +++ b/yarn-project/foundation/src/interfaces/index.ts @@ -1,3 +1,3 @@ -export interface IsEmpty { - isEmpty: () => boolean; +export interface IsDefault { + isDefault: () => boolean; } diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.ts index 7a0a15e8e97..3cf737fd563 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.ts @@ -339,7 +339,7 @@ export class ProvingOrchestrator { logger.info(`Completed root rollup`); // Collect all new nullifiers, commitments, and contracts from all txs in this block const nonEmptyTxEffects: TxEffect[] = this.provingState!.allTxs.map(tx => toTxEffect(tx)).filter( - txEffect => !txEffect.isEmpty(), + txEffect => !txEffect.isDefault(), ); const blockBody = new Body(nonEmptyTxEffects); diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 85086997ed9..1cca0d50b02 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -37,7 +37,7 @@ import { } from '@aztec/circuits.js'; import { computeCommitmentNonce, siloNullifier } from '@aztec/circuits.js/hash'; import { type ContractArtifact, type DecodedReturn, FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; -import { arrayNonEmptyLength, padArrayEnd } from '@aztec/foundation/collection'; +import { arrayNonDefaultLength, padArrayEnd } from '@aztec/foundation/collection'; import { Fr } from '@aztec/foundation/fields'; import { SerialQueue } from '@aztec/foundation/fifo'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; @@ -708,7 +708,7 @@ export class PXEService implements PXE { publicInputs.forPublic!.end.publicCallStack.find(item => item.equals(enqueued)), ); - const revertibleStackSize = arrayNonEmptyLength(publicInputs.forPublic.end.publicCallStack, item => item.isDefault()); + const revertibleStackSize = arrayNonDefaultLength(publicInputs.forPublic.end.publicCallStack, item => item.isDefault()); if (enqueuedRevertiblePublicCallStackItems.length !== revertibleStackSize) { throw new Error( @@ -723,7 +723,7 @@ export class PXEService implements PXE { // Override kernel output publicInputs.forPublic.end.publicCallStack = padArrayEnd( enqueuedRevertiblePublicCallStackItems, - CallRequest.empty(), + CallRequest.default(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, ); @@ -733,9 +733,9 @@ export class PXEService implements PXE { publicInputs.forPublic!.endNonRevertibleData.publicCallStack.find(item => item.equals(enqueued)), ); - const nonRevertibleStackSize = arrayNonEmptyLength( + const nonRevertibleStackSize = arrayNonDefaultLength( publicInputs.forPublic.endNonRevertibleData.publicCallStack, - item => item.isEmpty(), + item => item.isDefault(), ); if (enqueuedNonRevertiblePublicCallStackItems.length !== nonRevertibleStackSize) { diff --git a/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts b/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts index eb05e05cb97..687f6b97fa5 100644 --- a/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts +++ b/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts @@ -48,7 +48,7 @@ import { type ProcessReturnValues, decodeReturnValues, } from '@aztec/foundation/abi'; -import { arrayNonEmptyLength, padArrayEnd } from '@aztec/foundation/collection'; +import { arrayNonDefaultLength, padArrayEnd } from '@aztec/foundation/collection'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { type Tuple } from '@aztec/foundation/serialize'; import { @@ -524,7 +524,7 @@ function patchPublicStorageActionOrdering( const effectSet = PhaseIsRevertible[phase] ? 'end' : 'endNonRevertibleData'; - const numReadsInKernel = arrayNonEmptyLength(publicDataReads, f => f.isDefault()); + const numReadsInKernel = arrayNonDefaultLength(publicDataReads, f => f.isDefault()); const numReadsBeforeThisEnqueuedCall = numReadsInKernel - simPublicDataReads.length; publicInputs.validationRequests.publicDataReads = padArrayEnd( [ @@ -536,7 +536,7 @@ function patchPublicStorageActionOrdering( MAX_PUBLIC_DATA_READS_PER_TX, ); - const numUpdatesInKernel = arrayNonEmptyLength(publicDataUpdateRequests, f => f.isDefault()); + const numUpdatesInKernel = arrayNonDefaultLength(publicDataUpdateRequests, f => f.isDefault()); const numUpdatesBeforeThisEnqueuedCall = numUpdatesInKernel - simPublicDataUpdateRequests.length; publicInputs[effectSet].publicDataUpdateRequests = padArrayEnd( [ diff --git a/yarn-project/sequencer-client/src/sequencer/hints_builder.ts b/yarn-project/sequencer-client/src/sequencer/hints_builder.ts index b2a581d7696..5d97d3d15ba 100644 --- a/yarn-project/sequencer-client/src/sequencer/hints_builder.ts +++ b/yarn-project/sequencer-client/src/sequencer/hints_builder.ts @@ -91,10 +91,10 @@ export class HintsBuilder { const newPublicDataReadsWitnesses: Tuple< MembershipWitness, typeof MAX_PUBLIC_DATA_READS_PER_TX - > = makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, () => MembershipWitness.empty(PUBLIC_DATA_TREE_HEIGHT, 0n)); + > = makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, () => MembershipWitness.default(PUBLIC_DATA_TREE_HEIGHT, 0n)); const newPublicDataReadsPreimages: Tuple = - makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, () => PublicDataTreeLeafPreimage.empty()); + makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, () => PublicDataTreeLeafPreimage.default()); for (const i in publicDataReads) { const leafSlot = publicDataReads[i].leafSlot.value; diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts index e5a063879c3..b68abc8c387 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts @@ -40,7 +40,7 @@ import { makeSelector, } from '@aztec/circuits.js/testing'; import { makeTuple } from '@aztec/foundation/array'; -import { arrayNonEmptyLength, padArrayEnd, times } from '@aztec/foundation/collection'; +import { arrayNonDefaultLength, padArrayEnd, times } from '@aztec/foundation/collection'; import { type PublicExecution, type PublicExecutionResult, type PublicExecutor, WASMSimulator } from '@aztec/simulator'; import { type MerkleTreeOperations, type TreeInfo } from '@aztec/world-state'; @@ -109,7 +109,7 @@ describe('public_processor', () => { proof: tx.proof, encryptedLogs: tx.encryptedLogs, unencryptedLogs: tx.unencryptedLogs, - isEmpty: false, + isDefault: false, revertReason: undefined, }; @@ -233,11 +233,11 @@ describe('public_processor', () => { const kernelOutput = makePrivateKernelTailCircuitPublicInputs(0x10); kernelOutput.forPublic!.endNonRevertibleData.publicDataUpdateRequests = makeTuple( MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - PublicDataUpdateRequest.empty, + PublicDataUpdateRequest.default, ); kernelOutput.forPublic!.end.publicDataUpdateRequests = makeTuple( MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - PublicDataUpdateRequest.empty, + PublicDataUpdateRequest.default, ); addKernelPublicCallStack(kernelOutput, { @@ -328,7 +328,7 @@ describe('public_processor', () => { expect(publicWorldStateDB.rollbackToCommit).toHaveBeenCalledTimes(0); const txEffect = toTxEffect(processed[0]); - expect(arrayNonEmptyLength(txEffect.publicDataWrites, PublicDataWrite.isDefault)).toEqual(2); + expect(arrayNonDefaultLength(txEffect.publicDataWrites, PublicDataWrite.isDefault)).toEqual(2); expect(txEffect.publicDataWrites[0]).toEqual( new PublicDataWrite(computePublicDataTreeLeafSlot(baseContractAddress, contractSlotA), fr(0x101)), ); @@ -561,11 +561,11 @@ describe('public_processor', () => { kernelOutput.forPublic!.end.unencryptedLogsHash = Fr.ZERO; kernelOutput.forPublic!.endNonRevertibleData.publicDataUpdateRequests = makeTuple( MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - PublicDataUpdateRequest.empty, + PublicDataUpdateRequest.default, ); kernelOutput.forPublic!.end.publicDataUpdateRequests = makeTuple( MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - PublicDataUpdateRequest.empty, + PublicDataUpdateRequest.default, ); addKernelPublicCallStack(kernelOutput, { @@ -651,7 +651,7 @@ describe('public_processor', () => { expect(publicWorldStateDB.rollbackToCommit).toHaveBeenCalledTimes(0); const txEffect = toTxEffect(processed[0]); - expect(arrayNonEmptyLength(txEffect.publicDataWrites, PublicDataWrite.isDefault)).toEqual(3); + expect(arrayNonDefaultLength(txEffect.publicDataWrites, PublicDataWrite.isDefault)).toEqual(3); expect(txEffect.publicDataWrites[0]).toEqual( new PublicDataWrite(computePublicDataTreeLeafSlot(baseContractAddress, contractSlotC), fr(0x201)), ); diff --git a/yarn-project/sequencer-client/src/sequencer/setup_phase_manager.test.ts b/yarn-project/sequencer-client/src/sequencer/setup_phase_manager.test.ts index 25c2f5b92c1..00756bfd2cc 100644 --- a/yarn-project/sequencer-client/src/sequencer/setup_phase_manager.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/setup_phase_manager.test.ts @@ -50,7 +50,7 @@ describe('setup_phase_manager', () => { it('does not extract non-revertible calls when none exist', function () { const tx = mockTx(); - tx.data.forPublic!.end.publicCallStack = makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.empty); + tx.data.forPublic!.end.publicCallStack = makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default); tx.data.forPublic!.endNonRevertibleData.publicCallStack = makeTuple( MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default, diff --git a/yarn-project/sequencer-client/src/sequencer/tail_phase_manager.ts b/yarn-project/sequencer-client/src/sequencer/tail_phase_manager.ts index e41a05b818b..4f570067436 100644 --- a/yarn-project/sequencer-client/src/sequencer/tail_phase_manager.ts +++ b/yarn-project/sequencer-client/src/sequencer/tail_phase_manager.ts @@ -95,7 +95,7 @@ export class TailPhaseManager extends AbstractPhaseManager { private sortNoteHashes(noteHashes: Tuple): Tuple { return noteHashes.sort((n0, n1) => { - if (n0.isEmpty()) { + if (n0.isDefault()) { return 1; } return Number(n0.counter.toBigInt() - n1.counter.toBigInt()); diff --git a/yarn-project/sequencer-client/src/sequencer/tx_validator.ts b/yarn-project/sequencer-client/src/sequencer/tx_validator.ts index 457aedf2d34..cbec941056e 100644 --- a/yarn-project/sequencer-client/src/sequencer/tx_validator.ts +++ b/yarn-project/sequencer-client/src/sequencer/tx_validator.ts @@ -138,7 +138,7 @@ export class TxValidator { * @returns Whether this is a problematic double spend that the L1 contract would reject. */ async #validateNullifiers(tx: Tx | ProcessedTx, thisBlockNullifiers: Set): Promise { - const newNullifiers = tx.data.getNonEmptyNullifiers().map(x => x.value.toBigInt()); + const newNullifiers = tx.data.getNonDefaultNullifiers().map(x => x.value.toBigInt()); // Ditch this tx if it has repeated nullifiers const uniqueNullifiers = new Set(newNullifiers); diff --git a/yarn-project/simulator/src/avm/opcodes/external_calls.ts b/yarn-project/simulator/src/avm/opcodes/external_calls.ts index bef04c8fc9e..a9e6108915c 100644 --- a/yarn-project/simulator/src/avm/opcodes/external_calls.ts +++ b/yarn-project/simulator/src/avm/opcodes/external_calls.ts @@ -1,4 +1,4 @@ -import { FunctionSelector } from '@aztec/circuits.js'; +import { AztecAddress, FunctionSelector } from '@aztec/circuits.js'; import { padArrayEnd } from '@aztec/foundation/collection'; import type { AvmContext } from '../avm_context.js'; diff --git a/yarn-project/simulator/src/avm/temporary_executor_migration.ts b/yarn-project/simulator/src/avm/temporary_executor_migration.ts index be49160ba09..1659841dc32 100644 --- a/yarn-project/simulator/src/avm/temporary_executor_migration.ts +++ b/yarn-project/simulator/src/avm/temporary_executor_migration.ts @@ -100,7 +100,7 @@ export function temporaryConvertAvmResults( (nullifier, i) => new SideEffectLinkedToNoteHash(nullifier.toField(), Fr.zero(), new Fr(i + 1)), ); const unencryptedLogs = UnencryptedFunctionL2Logs.default(); - const newL2ToL1Messages = newWorldState.newL1Messages.map(() => L2ToL1Message.empty()); + const newL2ToL1Messages = newWorldState.newL1Messages.map(() => L2ToL1Message.default()); // TODO keep track of side effect counters const startSideEffectCounter = Fr.ZERO; const endSideEffectCounter = Fr.ZERO; diff --git a/yarn-project/world-state/src/world-state-db/merkle_trees.ts b/yarn-project/world-state/src/world-state-db/merkle_trees.ts index 3fefc281583..5014350e406 100644 --- a/yarn-project/world-state/src/world-state-db/merkle_trees.ts +++ b/yarn-project/world-state/src/world-state-db/merkle_trees.ts @@ -578,7 +578,7 @@ export class MerkleTrees implements MerkleTreeDb { // by circuits. const paddedTxEffects = padArrayEnd( l2Block.body.txEffects, - TxEffect.empty(), + TxEffect.default(), l2Block.body.numberOfTxsIncludingPadded, ); @@ -609,7 +609,7 @@ export class MerkleTrees implements MerkleTreeDb { for (const txEffect of paddedTxEffects) { const publicDataWrites = padArrayEnd( txEffect.publicDataWrites, - PublicDataWrite.empty(), + PublicDataWrite.default(), MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, ); From 6e81f94bc1b5b157132be10ac680a7555ffb768f Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 12:49:49 +0000 Subject: [PATCH 25/77] fix asdf fix --- .../src/private_kernel_tail.nr | 2 +- .../public-kernel-lib/src/public_kernel_tail.nr | 4 ++-- yarn-project/circuit-types/src/body.ts | 4 ++-- .../src/structs/content_commitment.ts | 2 +- .../src/structs/contract_storage_read.ts | 2 +- .../structs/contract_storage_update_request.ts | 2 +- .../src/structs/function_data.test.ts | 2 +- .../circuits.js/src/structs/function_data.ts | 4 ++-- .../structs/kernel/combined_accumulated_data.ts | 10 +++++----- .../src/structs/kernel/kernel_data.ts | 2 +- .../structs/kernel/private_accumulated_data.ts | 10 +++++----- .../private_kernel_circuit_public_inputs.ts | 2 +- .../src/structs/kernel/private_kernel_data.ts | 2 +- .../structs/kernel/private_kernel_tail_data.ts | 2 +- .../structs/kernel/public_accumulated_data.ts | 10 +++++----- .../src/structs/kernel/public_kernel_data.ts | 2 +- .../circuits.js/src/structs/l2_to_l1_message.ts | 2 +- .../src/structs/private_call_stack_item.ts | 2 +- .../src/structs/private_circuit_public_inputs.ts | 6 +++--- .../src/structs/public_call_stack_item.ts | 2 +- .../src/structs/public_circuit_public_inputs.ts | 4 ++-- .../circuits.js/src/structs/read_request.ts | 4 ++-- .../circuits.js/src/structs/side_effects.ts | 4 ++-- .../circuits.js/src/structs/tx_request.ts | 4 ++-- yarn-project/circuits.js/src/tests/factories.ts | 16 ++++++++-------- .../src/e2e_cross_chain_messaging.test.ts | 2 +- .../src/e2e_public_cross_chain_messaging.test.ts | 2 +- .../foundation/src/fields/fields.test.ts | 2 +- yarn-project/foundation/src/fields/fields.ts | 10 +++++++--- .../pxe/src/kernel_prover/hints_builder.ts | 4 ++-- yarn-project/simulator/src/avm/fixtures/index.ts | 16 ++++++++-------- .../src/avm/temporary_executor_migration.ts | 12 ++++++------ 32 files changed, 79 insertions(+), 75 deletions(-) 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 940e24f6703..2dc19de3488 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 @@ -403,7 +403,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="Private call stack must be default when executing the tail circuit")] + #[test(should_fail_with="Private call stack must be empty when executing the tail circuit")] unconstrained fn non_empty_private_call_stack_should_fail() { let mut builder = PrivateKernelTailInputsBuilder::new(); builder.previous_kernel.push_private_call_request(1, false); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr index 36701d7c01d..16cf635a265 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr @@ -31,10 +31,10 @@ impl PublicKernelTailCircuitPrivateInputs { assert(previous_public_inputs.needs_app_logic() == false, "Previous kernel needs app logic"); assert(previous_public_inputs.needs_teardown() == false, "Previous kernel needs teardown"); assert_eq( - array_length(previous_public_inputs.end.public_call_stack), 0, "Public call stack must be default when executing the tail circuit" + array_length(previous_public_inputs.end.public_call_stack), 0, "Public call stack must be empty when executing the tail circuit" ); assert_eq( - array_length(previous_public_inputs.end_non_revertible.public_call_stack), 0, "Public call stack must be default when executing the tail circuit" + array_length(previous_public_inputs.end_non_revertible.public_call_stack), 0, "Public call stack must be empty when executing the tail circuit" ); } diff --git a/yarn-project/circuit-types/src/body.ts b/yarn-project/circuit-types/src/body.ts index ed488e996f6..02512f5ca56 100644 --- a/yarn-project/circuit-types/src/body.ts +++ b/yarn-project/circuit-types/src/body.ts @@ -66,10 +66,10 @@ export class Body { return layers[layers.length - 1][0]; }; - const emptyTxEffectHash = TxEffect.default().hash(); + const defaultTxEffectHash = TxEffect.default().hash(); const leaves: Buffer[] = padArrayEnd( this.txEffects.map(txEffect => txEffect.hash()), - emptyTxEffectHash, + defaultTxEffectHash, this.numberOfTxsIncludingPadded, ); diff --git a/yarn-project/circuits.js/src/structs/content_commitment.ts b/yarn-project/circuits.js/src/structs/content_commitment.ts index ca679f7fe1b..68691339366 100644 --- a/yarn-project/circuits.js/src/structs/content_commitment.ts +++ b/yarn-project/circuits.js/src/structs/content_commitment.ts @@ -67,7 +67,7 @@ export class ContentCommitment { static default(): ContentCommitment { return new ContentCommitment( - Fr.zero(), + Fr.ZERO, Buffer.alloc(NUM_BYTES_PER_SHA256), Buffer.alloc(NUM_BYTES_PER_SHA256), Buffer.alloc(NUM_BYTES_PER_SHA256), diff --git a/yarn-project/circuits.js/src/structs/contract_storage_read.ts b/yarn-project/circuits.js/src/structs/contract_storage_read.ts index 3a76a06bf89..34d090b3239 100644 --- a/yarn-project/circuits.js/src/structs/contract_storage_read.ts +++ b/yarn-project/circuits.js/src/structs/contract_storage_read.ts @@ -57,7 +57,7 @@ export class ContractStorageRead { } isDefault() { - return this.storageSlot.isZero() && this.currentValue.isZero(); + return this.storageSlot.isZero() && this.currentValue.isZero() && (this.sideEffectCounter == 0 || this.sideEffectCounter == undefined); } toFriendlyJSON() { diff --git a/yarn-project/circuits.js/src/structs/contract_storage_update_request.ts b/yarn-project/circuits.js/src/structs/contract_storage_update_request.ts index c134db41b13..daa0c24576c 100644 --- a/yarn-project/circuits.js/src/structs/contract_storage_update_request.ts +++ b/yarn-project/circuits.js/src/structs/contract_storage_update_request.ts @@ -58,7 +58,7 @@ export class ContractStorageUpdateRequest { } isDefault() { - return this.storageSlot.isZero() && this.newValue.isZero(); + return this.storageSlot.isZero() && this.newValue.isZero() && (this.sideEffectCounter == 0 || this.sideEffectCounter == undefined); } toFriendlyJSON() { diff --git a/yarn-project/circuits.js/src/structs/function_data.test.ts b/yarn-project/circuits.js/src/structs/function_data.test.ts index b7abcd3b1c1..8066877bd8c 100644 --- a/yarn-project/circuits.js/src/structs/function_data.test.ts +++ b/yarn-project/circuits.js/src/structs/function_data.test.ts @@ -16,7 +16,7 @@ describe('FunctionData', () => { const buffer = functionData.toBuffer(); const res = FunctionData.fromBuffer(buffer); expect(res).toEqual(functionData); - expect(res.isDefault()).toBe(false); + expect(res.isDefault(true)).toBe(false); }); it('number of fields matches constant', () => { diff --git a/yarn-project/circuits.js/src/structs/function_data.ts b/yarn-project/circuits.js/src/structs/function_data.ts index 354dfb40509..99b81d5c65b 100644 --- a/yarn-project/circuits.js/src/structs/function_data.ts +++ b/yarn-project/circuits.js/src/structs/function_data.ts @@ -44,8 +44,8 @@ export class FunctionData { * Returns whether this instance is default. * @returns True if the function selector is zero. */ - isDefault() { - return this.selector.isDefault(); + isDefault(_private: boolean) { + return this.selector.isDefault() && _private == this.isPrivate; } /** diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts index bc2acf770d8..07a97f1497c 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts @@ -102,11 +102,11 @@ export class CombinedAccumulatedData { return new CombinedAccumulatedData( makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.default), makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), - makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), - Fr.zero(), - Fr.zero(), - Fr.zero(), - Fr.zero(), + makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.default), + Fr.ZERO, + Fr.ZERO, + Fr.ZERO, + Fr.ZERO, makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.default), ); } diff --git a/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts b/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts index 629d0d13f30..ea668e0e88c 100644 --- a/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts @@ -38,7 +38,7 @@ export class KernelData { makeEmptyProof(), VerificationKey.makeFake(), 0, - makeTuple(VK_TREE_HEIGHT, Fr.zero), + makeTuple(VK_TREE_HEIGHT, Fr.default), ); } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_accumulated_data.ts index deca14930f2..c07e4b87339 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_accumulated_data.ts @@ -111,11 +111,11 @@ export class PrivateAccumulatedData { return new PrivateAccumulatedData( makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.default), makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), - makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), - Fr.zero(), - Fr.zero(), - Fr.zero(), - Fr.zero(), + makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.default), + Fr.ZERO, + Fr.ZERO, + Fr.ZERO, + Fr.ZERO, makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, CallRequest.default), makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default), ); diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_circuit_public_inputs.ts index 66b903bc0e1..45aa6122f14 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_circuit_public_inputs.ts @@ -62,7 +62,7 @@ export class PrivateKernelCircuitPublicInputs { static default() { return new PrivateKernelCircuitPublicInputs( AggregationObject.makeFake(), - Fr.zero(), + Fr.ZERO, ValidationRequests.default(), PrivateAccumulatedData.default(), CombinedConstantData.default(), diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_data.ts index 795c4b82030..32020d3d1d7 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_data.ts @@ -60,7 +60,7 @@ export class PrivateKernelData { makeEmptyProof(), VerificationKey.makeFake(), 0, - makeTuple(VK_TREE_HEIGHT, Fr.zero), + makeTuple(VK_TREE_HEIGHT, Fr.default), ); } } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_data.ts index f704101a0a9..7754f694506 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_data.ts @@ -52,7 +52,7 @@ export class PrivateKernelTailData { makeEmptyProof(), VerificationKey.makeFake(), 0, - makeTuple(VK_TREE_HEIGHT, Fr.zero), + makeTuple(VK_TREE_HEIGHT, Fr.default), ); } diff --git a/yarn-project/circuits.js/src/structs/kernel/public_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/public_accumulated_data.ts index ff560bbf2b1..20e19016204 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_accumulated_data.ts @@ -138,11 +138,11 @@ export class PublicAccumulatedData { return new this( makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.default), makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), - makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), - Fr.zero(), - Fr.zero(), - Fr.zero(), - Fr.zero(), + makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.default), + Fr.ZERO, + Fr.ZERO, + Fr.ZERO, + Fr.ZERO, makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataUpdateRequest.default), makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, CallRequest.default), ); diff --git a/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts b/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts index fe6c3b3e694..37b5295fec4 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts @@ -52,7 +52,7 @@ export class PublicKernelData { makeEmptyProof(), VerificationKey.makeFake(), 0, - makeTuple(VK_TREE_HEIGHT, Fr.zero), + makeTuple(VK_TREE_HEIGHT, Fr.default), ); } diff --git a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts index c15ebfbd2e5..e86133a652c 100644 --- a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts +++ b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts @@ -12,7 +12,7 @@ export class L2ToL1Message { * @returns An instance of L2ToL1Message with default fields. */ static default(): L2ToL1Message { - return new L2ToL1Message(EthAddress.default(), Fr.zero()); + return new L2ToL1Message(EthAddress.default(), Fr.ZERO); } /** diff --git a/yarn-project/circuits.js/src/structs/private_call_stack_item.ts b/yarn-project/circuits.js/src/structs/private_call_stack_item.ts index 58e973c9b8a..aa0600a18ca 100644 --- a/yarn-project/circuits.js/src/structs/private_call_stack_item.ts +++ b/yarn-project/circuits.js/src/structs/private_call_stack_item.ts @@ -83,7 +83,7 @@ export class PrivateCallStackItem { } isDefault() { - return this.contractAddress.isDefault() && this.functionData.isDefault() && this.publicInputs.isDefault(); + return this.contractAddress.isDefault() && this.functionData.isDefault(true) && this.publicInputs.isDefault(); } /** diff --git a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts index 679a576967e..0e5a495c833 100644 --- a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts @@ -217,7 +217,7 @@ export class PrivateCircuitPublicInputs { return new PrivateCircuitPublicInputs( CallContext.default(), Fr.ZERO, - makeTuple(RETURN_VALUES_LENGTH, Fr.zero), + makeTuple(RETURN_VALUES_LENGTH, Fr.default), Fr.ZERO, MaxBlockNumber.default(), makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, SideEffect.default), @@ -225,8 +225,8 @@ export class PrivateCircuitPublicInputs { makeTuple(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, NullifierKeyValidationRequest.default), makeTuple(MAX_NEW_NOTE_HASHES_PER_CALL, SideEffect.default), makeTuple(MAX_NEW_NULLIFIERS_PER_CALL, SideEffectLinkedToNoteHash.default), - makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, Fr.zero), - makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, Fr.zero), + makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, Fr.default), + makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, Fr.default), makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, L2ToL1Message.default), Fr.ZERO, Fr.ZERO, diff --git a/yarn-project/circuits.js/src/structs/public_call_stack_item.ts b/yarn-project/circuits.js/src/structs/public_call_stack_item.ts index af563703c57..247afc7011c 100644 --- a/yarn-project/circuits.js/src/structs/public_call_stack_item.ts +++ b/yarn-project/circuits.js/src/structs/public_call_stack_item.ts @@ -81,7 +81,7 @@ export class PublicCallStackItem { } isDefault() { - return this.contractAddress.isDefault() && this.functionData.isDefault() && this.publicInputs.isDefault(); + return this.contractAddress.isDefault() && this.functionData.isDefault(false) && this.publicInputs.isDefault(); } /** diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts index 048f4db6b95..c2d7a47148c 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts @@ -139,12 +139,12 @@ export class PublicCircuitPublicInputs { return new PublicCircuitPublicInputs( CallContext.default(), Fr.ZERO, - makeTuple(RETURN_VALUES_LENGTH, Fr.zero), + makeTuple(RETURN_VALUES_LENGTH, Fr.default), makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, ReadRequest.default), makeTuple(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, ReadRequest.default), makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, ContractStorageUpdateRequest.default), makeTuple(MAX_PUBLIC_DATA_READS_PER_CALL, ContractStorageRead.default), - makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, Fr.zero), + makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, Fr.default), makeTuple(MAX_NEW_NOTE_HASHES_PER_CALL, SideEffect.default), makeTuple(MAX_NEW_NULLIFIERS_PER_CALL, SideEffectLinkedToNoteHash.default), makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, L2ToL1Message.default), diff --git a/yarn-project/circuits.js/src/structs/read_request.ts b/yarn-project/circuits.js/src/structs/read_request.ts index 0e1007f31ac..3c29ad87cbc 100644 --- a/yarn-project/circuits.js/src/structs/read_request.ts +++ b/yarn-project/circuits.js/src/structs/read_request.ts @@ -58,7 +58,7 @@ export class ReadRequest { * @returns Side-effect with both value and counter being zero. */ static default(): ReadRequest { - return new ReadRequest(Fr.zero(), 0); + return new ReadRequest(Fr.ZERO, 0); } } @@ -125,6 +125,6 @@ export class ReadRequestContext { * @returns Side-effect with value, note hash and counter being zero. */ static default(): ReadRequestContext { - return new ReadRequestContext(Fr.zero(), 0, AztecAddress.default()); + return new ReadRequestContext(Fr.ZERO, 0, AztecAddress.default()); } } diff --git a/yarn-project/circuits.js/src/structs/side_effects.ts b/yarn-project/circuits.js/src/structs/side_effects.ts index 33f7091d7d7..6f29a174c2f 100644 --- a/yarn-project/circuits.js/src/structs/side_effects.ts +++ b/yarn-project/circuits.js/src/structs/side_effects.ts @@ -79,7 +79,7 @@ export class SideEffect implements SideEffectType { * @returns Side-effect with both value and counter being zero. */ static default(): SideEffect { - return new SideEffect(Fr.zero(), Fr.zero()); + return new SideEffect(Fr.ZERO, Fr.ZERO); } /** @@ -159,7 +159,7 @@ export class SideEffectLinkedToNoteHash implements SideEffectType { * @returns Side-effect with value, note hash and counter being zero. */ static default(): SideEffectLinkedToNoteHash { - return new SideEffectLinkedToNoteHash(Fr.zero(), Fr.zero(), Fr.zero()); + return new SideEffectLinkedToNoteHash(Fr.ZERO, Fr.ZERO, Fr.ZERO); } /** diff --git a/yarn-project/circuits.js/src/structs/tx_request.ts b/yarn-project/circuits.js/src/structs/tx_request.ts index 1645d721303..46cdb202267 100644 --- a/yarn-project/circuits.js/src/structs/tx_request.ts +++ b/yarn-project/circuits.js/src/structs/tx_request.ts @@ -75,10 +75,10 @@ export class TxRequest { } static default() { - return new TxRequest(AztecAddress.default(), FunctionData.default(), Fr.zero(), TxContext.default()); + return new TxRequest(AztecAddress.default(), FunctionData.default(), Fr.ZERO, TxContext.default()); } isDefault() { - return this.origin.isDefault() && this.functionData.isDefault() && this.argsHash.isZero() && this.txContext.isDefault(); + return this.origin.isDefault() && (this.functionData.isDefault(true) || this.functionData.isDefault(false)) && this.argsHash.isZero() && this.txContext.isDefault(); } } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 17ad9833dc6..1756fccaa66 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -294,7 +294,7 @@ export function makeCombinedAccumulatedData(seed = 1, full = false): CombinedAcc seed + 0x200, SideEffectLinkedToNoteHash.default, ), - tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.zero), + tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.default), fr(seed + 0x700), // encrypted logs hash fr(seed + 0x800), // unencrypted logs hash fr(seed + 0x900), // encrypted_log_preimages_length @@ -324,7 +324,7 @@ export function makePublicAccumulatedData(seed = 1, full = false): PublicAccumul seed + 0x200, SideEffectLinkedToNoteHash.default, ), - tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.zero), + tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.defaultultult), fr(seed + 0x700), // encrypted logs hash fr(seed + 0x800), // unencrypted logs hash fr(seed + 0x900), // encrypted_log_preimages_length @@ -355,7 +355,7 @@ export function makePrivateAccumulatedData(seed = 1, full = false) { seed + 0x200, SideEffectLinkedToNoteHash.default, ), - tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.zero), + tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.default), fr(seed + 0x700), // encrypted logs hash fr(seed + 0x800), // unencrypted logs hash fr(seed + 0x900), // encrypted_log_preimages_length @@ -413,7 +413,7 @@ export function makePublicCircuitPublicInputs( return new PublicCircuitPublicInputs( makeCallContext(seed, storageContractAddress), fr(seed + 0x100), - tupleGenerator(RETURN_VALUES_LENGTH, fr, seed + 0x200, Fr.zero), + tupleGenerator(RETURN_VALUES_LENGTH, fr, seed + 0x200, Fr.defaultult), tupleGenerator(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x400, ReadRequest.default), tupleGenerator(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x420, ReadRequest.default), tupleGenerator( @@ -423,7 +423,7 @@ export function makePublicCircuitPublicInputs( ContractStorageUpdateRequest.default, ), tupleGenerator(MAX_PUBLIC_DATA_READS_PER_CALL, makeContractStorageRead, seed + 0x500, ContractStorageRead.default), - tupleGenerator(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, fr, seed + 0x600, Fr.zero), + tupleGenerator(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, fr, seed + 0x600, Fr.default), tupleGenerator(MAX_NEW_NOTE_HASHES_PER_CALL, makeNewSideEffect, seed + 0x700, SideEffect.default), tupleGenerator( MAX_NEW_NULLIFIERS_PER_CALL, @@ -589,7 +589,7 @@ export function makeNoteHashReadRequestMembershipWitness(start: number): NoteHas export function makeDefaultNoteHashReadRequestMembershipWitness(): NoteHashReadRequestMembershipWitness { return new NoteHashReadRequestMembershipWitness( new Fr(0), - makeTuple(NOTE_HASH_TREE_HEIGHT, Fr.zero), + makeTuple(NOTE_HASH_TREE_HEIGHT, Fr.default), false, new Fr(0), ); @@ -1342,7 +1342,7 @@ export function fr(n: number): Fr { * @returns The SideEffect instance. */ export function sideEffectFromNumber(n: number): SideEffect { - return new SideEffect(new Fr(BigInt(n)), Fr.zero()); + return new SideEffect(new Fr(BigInt(n)), Fr.ZERO); } /** @@ -1351,5 +1351,5 @@ export function sideEffectFromNumber(n: number): SideEffect { * @returns The SideEffect instance. */ export function sideEffectLinkedFromNumber(n: number): SideEffectLinkedToNoteHash { - return new SideEffectLinkedToNoteHash(new Fr(BigInt(n)), Fr.zero(), Fr.zero()); + return new SideEffectLinkedToNoteHash(new Fr(BigInt(n)), Fr.ZERO, Fr.ZERO); } diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts index e6f45ed8df5..fbef7687358 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts @@ -209,7 +209,7 @@ describe('e2e_cross_chain_messaging', () => { await expect( l2Bridge .withWallet(user1Wallet) - .methods.exit_to_l1_private(l2Token.address, ethAccount, withdrawAmount, EthAddress.ZERO, nonce) + .methods.exit_to_l1_private(l2Token.address, ethAccount, withdrawAmount, EthAddress.default(), nonce) .prove(), ).rejects.toThrow(`Unknown auth witness for message hash ${expectedBurnMessageHash.toString()}`); }, 120_000); diff --git a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts index 1031824eaff..02f25e3cb60 100644 --- a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts @@ -184,7 +184,7 @@ describe('e2e_public_cross_chain_messaging', () => { await expect( l2Bridge .withWallet(user1Wallet) - .methods.exit_to_l1_public(ethAccount, withdrawAmount, EthAddress.ZERO, nonce) + .methods.exit_to_l1_public(ethAccount, withdrawAmount, EthAddress.default(), nonce) .prove(), ).rejects.toThrow('Assertion failed: Message not authorized by account'); }, 60_000); diff --git a/yarn-project/foundation/src/fields/fields.test.ts b/yarn-project/foundation/src/fields/fields.test.ts index ff94978f0d1..8764df6e089 100644 --- a/yarn-project/foundation/src/fields/fields.test.ts +++ b/yarn-project/foundation/src/fields/fields.test.ts @@ -180,7 +180,7 @@ describe('Bn254 arithmetic', () => { [new Fr(0), new Fr(Fr.MODULUS - 1n), -1], [new Fr(Fr.MODULUS - 1n), new Fr(0), 1], [Fr.ZERO, Fr.ZERO, 0], - [Fr.zero(), Fr.ZERO, 0], + [Fr.ZERO, Fr.ZERO, 0], ])('Should compare field elements correctly', (a, b, expected) => { expect(a.cmp(b)).toEqual(expected); }); diff --git a/yarn-project/foundation/src/fields/fields.ts b/yarn-project/foundation/src/fields/fields.ts index a28018638f4..1c11a2c25b2 100644 --- a/yarn-project/foundation/src/fields/fields.ts +++ b/yarn-project/foundation/src/fields/fields.ts @@ -132,6 +132,10 @@ abstract class BaseField { return this.toBuffer().equals(ZERO_BUFFER); } + isDefault(): boolean { + return this.toBuffer().equals(ZERO_BUFFER); + } + toFriendlyJSON(): string { return this.toString(); } @@ -205,12 +209,12 @@ export class Fr extends BaseField { return random(Fr); } - static zero() { + static default() { return Fr.ZERO; } - static isZero(value: Fr) { - return value.isZero(); + static isDefault(value: Fr) { + return value.isDefault(); } static fromBuffer(buffer: Buffer | BufferReader) { diff --git a/yarn-project/pxe/src/kernel_prover/hints_builder.ts b/yarn-project/pxe/src/kernel_prover/hints_builder.ts index a65e2386cc6..8dce8d12fe9 100644 --- a/yarn-project/pxe/src/kernel_prover/hints_builder.ts +++ b/yarn-project/pxe/src/kernel_prover/hints_builder.ts @@ -59,7 +59,7 @@ export class HintsBuilder { noteHashReadRequests: Tuple, noteHashes: Tuple, ): Tuple { - const hints = makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_TX, Fr.zero); + const hints = makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_TX, Fr.default); for (let i = 0; i < MAX_NOTE_HASH_READ_REQUESTS_PER_TX && !noteHashReadRequests[i].isDefault(); i++) { const equalToRR = (cmt: SideEffect) => cmt.value.equals(noteHashReadRequests[i].value); const result = noteHashes.findIndex(equalToRR); @@ -114,7 +114,7 @@ export class HintsBuilder { nullifiedNoteHashes: Tuple, noteHashes: Tuple, ): Tuple { - const hints = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, Fr.zero); + const hints = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, Fr.default); const alreadyUsed = new Set(); for (let i = 0; i < MAX_NEW_NULLIFIERS_PER_TX; i++) { if (!nullifiedNoteHashes[i].isZero()) { diff --git a/yarn-project/simulator/src/avm/fixtures/index.ts b/yarn-project/simulator/src/avm/fixtures/index.ts index bad1654b0be..b373345610f 100644 --- a/yarn-project/simulator/src/avm/fixtures/index.ts +++ b/yarn-project/simulator/src/avm/fixtures/index.ts @@ -63,10 +63,10 @@ export function initExecutionEnvironment(overrides?: Partial): GlobalVariables { return new GlobalVariables( - overrides?.chainId ?? Fr.zero(), - overrides?.version ?? Fr.zero(), - overrides?.blockNumber ?? Fr.zero(), - overrides?.timestamp ?? Fr.zero(), + overrides?.chainId ?? Fr.ZERO, + overrides?.version ?? Fr.ZERO, + overrides?.blockNumber ?? Fr.ZERO, + overrides?.timestamp ?? Fr.ZERO, overrides?.coinbase ?? EthAddress.default(), overrides?.feeRecipient ?? AztecAddress.default(), ); diff --git a/yarn-project/simulator/src/avm/temporary_executor_migration.ts b/yarn-project/simulator/src/avm/temporary_executor_migration.ts index 1659841dc32..88c0cbd3965 100644 --- a/yarn-project/simulator/src/avm/temporary_executor_migration.ts +++ b/yarn-project/simulator/src/avm/temporary_executor_migration.ts @@ -37,10 +37,10 @@ export function temporaryCreateAvmExecutionEnvironment( current.callContext.msgSender, // TODO: origin is not available current.callContext.msgSender, current.callContext.portalContractAddress, - /*feePerL1Gas=*/ Fr.zero(), - /*feePerL2Gas=*/ Fr.zero(), - /*feePerDaGas=*/ Fr.zero(), - /*contractCallDepth=*/ Fr.zero(), + /*feePerL1Gas=*/ Fr.ZERO, + /*feePerL2Gas=*/ Fr.ZERO, + /*feePerDaGas=*/ Fr.ZERO, + /*contractCallDepth=*/ Fr.ZERO, globalVariables, current.callContext.isStaticCall, current.callContext.isDelegateCall, @@ -63,7 +63,7 @@ export function temporaryConvertAvmResults( newWorldState: JournalData, result: AvmContractCallResults, ): PublicExecutionResult { - const newNoteHashes = newWorldState.newNoteHashes.map(noteHash => new SideEffect(noteHash, Fr.zero())); + const newNoteHashes = newWorldState.newNoteHashes.map(noteHash => new SideEffect(noteHash, Fr.ZERO)); const contractStorageReads: ContractStorageRead[] = []; const reduceStorageReadRequests = (contractAddress: bigint, storageReads: Map) => { @@ -97,7 +97,7 @@ export function temporaryConvertAvmResults( const nullifierReadRequests: ReadRequest[] = []; const nullifierNonExistentReadRequests: ReadRequest[] = []; const newNullifiers: SideEffectLinkedToNoteHash[] = newWorldState.newNullifiers.map( - (nullifier, i) => new SideEffectLinkedToNoteHash(nullifier.toField(), Fr.zero(), new Fr(i + 1)), + (nullifier, i) => new SideEffectLinkedToNoteHash(nullifier.toField(), Fr.ZERO, new Fr(i + 1)), ); const unencryptedLogs = UnencryptedFunctionL2Logs.default(); const newL2ToL1Messages = newWorldState.newL1Messages.map(() => L2ToL1Message.default()); From 1c433ed340e0990b6ea13964e73f0606bec2b322 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 16:42:52 +0000 Subject: [PATCH 26/77] fix --- ...nconstrained_function_broadcasted_event.ts | 2 +- .../structs/public_circuit_public_inputs.ts | 25 +------------------ .../circuits.js/src/tests/factories.ts | 4 +-- 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/yarn-project/circuits.js/src/contract/events/unconstrained_function_broadcasted_event.ts b/yarn-project/circuits.js/src/contract/events/unconstrained_function_broadcasted_event.ts index 32556036e77..7fb8c98dc9b 100644 --- a/yarn-project/circuits.js/src/contract/events/unconstrained_function_broadcasted_event.ts +++ b/yarn-project/circuits.js/src/contract/events/unconstrained_function_broadcasted_event.ts @@ -90,7 +90,7 @@ export class UnconstrainedFunctionBroadcastedEvent { // since a sibling with value zero can only occur on the tree leaves, so the sibling path will never end // in a zero. The only exception is a tree with depth 2 with one non-zero leaf, where the sibling path would // be a single zero element, but in that case the artifact tree should be just the single leaf. - const artifactTreeSiblingPath = removeArrayPaddingEnd(this.artifactFunctionTreeSiblingPath, Fr.isZero); + const artifactTreeSiblingPath = removeArrayPaddingEnd(this.artifactFunctionTreeSiblingPath, Fr.isDefault); return { ...this.unconstrainedFunction, bytecode: this.unconstrainedFunction.bytecode, diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts index c2d7a47148c..9026e9c80ac 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts @@ -159,30 +159,7 @@ export class PublicCircuitPublicInputs { } isDefault() { - const isSideEffectArrayDefault = (arr: SideEffect[]) => isArrayEmpty(arr, item => item.isDefault()); - const isSideEffectLinkedArrayDefault = (arr: SideEffectLinkedToNoteHash[]) => - isArrayEmpty(arr, item => item.isDefault()); - const isFrArrayZero = (arr: Fr[]) => isArrayEmpty(arr, item => item.isZero()); - return ( - this.callContext.isDefault() && - this.argsHash.isZero() && - isFrArrayZero(this.returnValues) && - isArrayEmpty(this.nullifierReadRequests, item => item.isDefault()) && - isArrayEmpty(this.nullifierNonExistentReadRequests, item => item.isDefault()) && - isArrayEmpty(this.contractStorageUpdateRequests, item => item.isDefault()) && - isArrayEmpty(this.contractStorageReads, item => item.isDefault()) && - isFrArrayZero(this.publicCallStackHashes) && - isSideEffectArrayDefault(this.newNoteHashes) && - isSideEffectLinkedArrayDefault(this.newNullifiers) && - isArrayEmpty(this.newL2ToL1Msgs, item => item.isDefault()) && - this.startSideEffectCounter.isZero() && - this.endSideEffectCounter.isZero() && - this.unencryptedLogsHash.isZero() && - this.unencryptedLogPreimagesLength.isZero() && - this.historicalHeader.isDefault() && - this.proverAddress.isDefault() && - this.revertCode.isOK() - ); + return PublicCircuitPublicInputs.default().toBuffer().equals(this.toBuffer()); } /** diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 1756fccaa66..f9175349ef6 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -324,7 +324,7 @@ export function makePublicAccumulatedData(seed = 1, full = false): PublicAccumul seed + 0x200, SideEffectLinkedToNoteHash.default, ), - tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.defaultultult), + tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.default), fr(seed + 0x700), // encrypted logs hash fr(seed + 0x800), // unencrypted logs hash fr(seed + 0x900), // encrypted_log_preimages_length @@ -413,7 +413,7 @@ export function makePublicCircuitPublicInputs( return new PublicCircuitPublicInputs( makeCallContext(seed, storageContractAddress), fr(seed + 0x100), - tupleGenerator(RETURN_VALUES_LENGTH, fr, seed + 0x200, Fr.defaultult), + tupleGenerator(RETURN_VALUES_LENGTH, fr, seed + 0x200, Fr.default), tupleGenerator(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x400, ReadRequest.default), tupleGenerator(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x420, ReadRequest.default), tupleGenerator( From e2b1b5370cf229f21c7b9ae1fd49b78bdbef6d1a Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 17:06:19 +0000 Subject: [PATCH 27/77] address comments --- yarn-project/circuit-types/src/tx/tx_hash.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/circuit-types/src/tx/tx_hash.ts b/yarn-project/circuit-types/src/tx/tx_hash.ts index d6114621d97..160a60a12e9 100644 --- a/yarn-project/circuit-types/src/tx/tx_hash.ts +++ b/yarn-project/circuit-types/src/tx/tx_hash.ts @@ -53,8 +53,8 @@ export class TxHash { } /** - * Returns true if this hash is default. - * @returns True if this hash is default. + * Returns true if this hash is zero. + * @returns True if this hash is zero. */ public isDefault(): boolean { return this.buffer.equals(Buffer.alloc(32, 0)); From 1498c8b982aaf12f8939721c30eb9590c65f68b2 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 17:08:46 +0000 Subject: [PATCH 28/77] fix --- yarn-project/circuit-types/src/logs/tx_l2_logs.ts | 4 ++-- .../circuits.js/src/structs/public_circuit_public_inputs.ts | 4 ++-- yarn-project/circuits.js/src/structs/read_request.ts | 4 ++-- yarn-project/circuits.js/src/structs/side_effects.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/yarn-project/circuit-types/src/logs/tx_l2_logs.ts b/yarn-project/circuit-types/src/logs/tx_l2_logs.ts index be253657373..d2d1a80225f 100644 --- a/yarn-project/circuit-types/src/logs/tx_l2_logs.ts +++ b/yarn-project/circuit-types/src/logs/tx_l2_logs.ts @@ -99,7 +99,7 @@ export abstract class TxL2Logs { } export class UnencryptedTxL2Logs extends TxL2Logs { - /** Creates an default instance. */ + /** Creates an empty instance. */ public static default() { return new UnencryptedTxL2Logs([]); } @@ -148,7 +148,7 @@ export class UnencryptedTxL2Logs extends TxL2Logs { } export class EncryptedTxL2Logs extends TxL2Logs { - /** Creates a default instance. */ + /** Creates a empty instance. */ public static default() { return new EncryptedTxL2Logs([]); } diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts index 9026e9c80ac..ac3522a76a7 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts @@ -132,8 +132,8 @@ export class PublicCircuitPublicInputs { } /** - * Returns an default instance. - * @returns An default instance. + * Returns an default instance (zeroed). + * @returns An default instance (zeroed). */ public static default() { return new PublicCircuitPublicInputs( diff --git a/yarn-project/circuits.js/src/structs/read_request.ts b/yarn-project/circuits.js/src/structs/read_request.ts index 3c29ad87cbc..c46b7f32957 100644 --- a/yarn-project/circuits.js/src/structs/read_request.ts +++ b/yarn-project/circuits.js/src/structs/read_request.ts @@ -54,7 +54,7 @@ export class ReadRequest { } /** - * Returns a default instance of side-effect. + * Returns a default instance of side-effect (zeroed). * @returns Side-effect with both value and counter being zero. */ static default(): ReadRequest { @@ -121,7 +121,7 @@ export class ReadRequestContext { } /** - * Returns a default instance of side-effect. + * Returns a default instance of side-effect (zeroed). * @returns Side-effect with value, note hash and counter being zero. */ static default(): ReadRequestContext { diff --git a/yarn-project/circuits.js/src/structs/side_effects.ts b/yarn-project/circuits.js/src/structs/side_effects.ts index 6f29a174c2f..bd498c6c3da 100644 --- a/yarn-project/circuits.js/src/structs/side_effects.ts +++ b/yarn-project/circuits.js/src/structs/side_effects.ts @@ -155,7 +155,7 @@ export class SideEffectLinkedToNoteHash implements SideEffectType { } /** - * Returns an default instance of side-effect. + * Returns an default instance of side-effect (zeroed). * @returns Side-effect with value, note hash and counter being zero. */ static default(): SideEffectLinkedToNoteHash { From 308b537977254f83484bc5806c90ee24eb694fb3 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 17:13:53 +0000 Subject: [PATCH 29/77] fix --- docs/docs/misc/migration_notes.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/docs/misc/migration_notes.md b/docs/docs/misc/migration_notes.md index be8a430cc31..61f5facd669 100644 --- a/docs/docs/misc/migration_notes.md +++ b/docs/docs/misc/migration_notes.md @@ -24,6 +24,16 @@ It is not possible to call `simulate` on any call to get the return values! However, beware that it currently always returns a Field array of size 4 for private and public. This will change to become similar to the return values of the `unconstrained` functions with proper return types. +### [Aztec.nr] [Aztec.js] IsEmpty / IsZero have been unified and renamed to IsDefault + +```diff +- Fr.zero(); ++ Fr.default(); + +- Header::empty(); ++ Header::default(); +``` + ```diff - #[aztec(private)] - fn get_shared_immutable_constrained_private() -> pub Leader { From 1df200061f371cdf6e865987e2e83f48d66fe0f9 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 17:34:35 +0000 Subject: [PATCH 30/77] fix --- .../crates/private-kernel-lib/src/common.nr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr index 714dfe2e1e3..8dad9ac64eb 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr @@ -127,7 +127,7 @@ fn perform_static_call_checks(private_call: PrivateCallData) { ); let new_l2_to_l1_msgs_length = array_length(public_inputs.new_l2_to_l1_msgs); - assert(new_l2_to_l1_msgs_length == 0, "new_l2_to_l1_msgs must be default for static calls"); + assert(new_l2_to_l1_msgs_length == 0, "new_l2_to_l1_msgs must be empty (length 0) for static calls"); // TODO: reevaluate when implementing https://github.com/AztecProtocol/aztec-packages/issues/1165 // This 4 magical number is the minimum size of the buffer, since it has to store the total length of all the serialized logs. @@ -311,7 +311,7 @@ pub fn contract_logic(private_call: PrivateCallData) { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3062): Why is this using a hash function from the stdlib::recursion namespace let private_call_vk_hash = stdlib_recursion_verification_key_compress_native_vk(private_call.vk); - assert(!is_default(contract_address), "contract address cannot be zero"); + assert(!is_default(contract_address), "contract address cannot be default (zero)"); // std::println(f"contract_address={contract_address}"); // std::println(f"private_call_vk_hash={private_call_vk_hash}"); From af3a62efec847fb4b21b828d86a313805b1bace3 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 17:44:00 +0000 Subject: [PATCH 31/77] fix msg --- .../crates/private-kernel-lib/src/common.nr | 4 ++-- .../crates/private-kernel-lib/src/private_kernel_inner.nr | 4 ++-- .../crates/public-kernel-lib/src/common.nr | 4 ++-- .../crates/public-kernel-lib/src/public_kernel_app_logic.nr | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr index 8dad9ac64eb..3a9eb16ea02 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr @@ -120,10 +120,10 @@ fn perform_static_call_checks(private_call: PrivateCallData) { if is_static_call { // No state changes are allowed for static calls: assert( - is_default_array(public_inputs.new_note_hashes), "new_note_hashes must be default for static calls" + is_default_array(public_inputs.new_note_hashes), "new_note_hashes must be a default array (zeroed) for static calls" ); assert( - is_default_array(public_inputs.new_nullifiers), "new_nullifiers must be default for static calls" + is_default_array(public_inputs.new_nullifiers), "new_nullifiers must be a default array (zeroed) for static calls" ); let new_l2_to_l1_msgs_length = array_length(public_inputs.new_l2_to_l1_msgs); 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 24f22e26d8e..07bdbc70476 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 @@ -691,7 +691,7 @@ mod tests { assert_eq(public_inputs.end.unencrypted_logs_hash, expected_unencrypted_logs_hash); } - #[test(should_fail_with="new_note_hashes must be default for static calls")] + #[test(should_fail_with="new_note_hashes must be a default array (zeroed) for static calls")] fn creating_new_note_hashes_on_static_call_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_static_call(); @@ -700,7 +700,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_nullifiers must be default for static calls")] + #[test(should_fail_with="new_nullifiers must be a default array (zeroed) for static calls")] fn creating_new_nullifiers_on_static_call_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_static_call(); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index 914b9929c47..bbf8aa154e1 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -113,10 +113,10 @@ fn perform_static_call_checks(public_call: PublicCallData) { if public_inputs.call_context.is_static_call { // No state changes are allowed for static calls: let new_note_hashes_length = array_length(public_inputs.new_note_hashes); - assert(new_note_hashes_length == 0, "new_note_hashes must be default for static calls"); + assert(new_note_hashes_length == 0, "new_note_hashes must be a default array (zeroed) for static calls"); let new_nullifiers_length = array_length(public_inputs.new_nullifiers); - assert(new_nullifiers_length == 0, "new_nullifiers must be default for static calls"); + assert(new_nullifiers_length == 0, "new_nullifiers must be a default array (zeroed) for static calls"); let update_requests_length = array_length(public_inputs.contract_storage_update_requests); assert( diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr index 794c1ba7183..209969b254f 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr @@ -341,7 +341,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_note_hashes must be default for static calls")] + #[test(should_fail_with="new_note_hashes must be a default array (zeroed) for static calls")] fn public_kernel_fails_creating_new_note_hashes_on_static_call() { let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); builder.public_call.public_inputs.call_context.is_static_call = true; @@ -350,7 +350,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_nullifiers must be default for static calls")] + #[test(should_fail_with="new_nullifiers must be a default array (zeroed) for static calls")] fn public_kernel_fails_creating_new_nullifiers_on_static_call() { let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); builder.public_call.public_inputs.call_context.is_static_call = true; From 428621a2c97ffc2227841e847960e2d928d1d9ec Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 17:55:34 +0000 Subject: [PATCH 32/77] fix --- .../crates/public-kernel-lib/src/utils.nr | 4 +- ...accumulated_non_revertible_data_builder.nr | 57 ------------- .../accumulated_revertible_data_builder.nr | 82 ------------------- 3 files changed, 2 insertions(+), 141 deletions(-) delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_non_revertible_data_builder.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_revertible_data_builder.nr diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr index 74ba8c86def..905fe72c791 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr @@ -6,8 +6,8 @@ use dep::types::{ }, address::AztecAddress, contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, - utils::{arrays::array_eq}, - traits::{is_default}, + utils::arrays::array_eq, + traits::is_default, }; pub fn compute_public_data_reads( diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_non_revertible_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_non_revertible_data_builder.nr deleted file mode 100644 index 04388d4fb7b..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_non_revertible_data_builder.nr +++ /dev/null @@ -1,57 +0,0 @@ -use crate::{ - abis::{ - accumulated_data::{ - private_accumulated_non_revertible_data::PrivateAccumulatedNonRevertibleData, - public_accumulated_non_revertible_data::PublicAccumulatedNonRevertibleData -}, - call_request::CallRequest, public_data_update_request::PublicDataUpdateRequest, - side_effect::{SideEffect, SideEffectLinkedToNoteHash} -} -}; -use crate::constants::{ - MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, - MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, - MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX -}; - -struct AccumulatedNonRevertibleDataBuilder { - revert_code: u8, - - new_note_hashes: BoundedVec, - new_nullifiers: BoundedVec, - public_call_stack: BoundedVec, - - public_data_update_requests: BoundedVec, -} - -impl Default for AccumulatedNonRevertibleDataBuilder { - fn default() -> Self { - AccumulatedNonRevertibleDataBuilder { - revert_code: 0 as u8, - new_note_hashes: BoundedVec::new(), - new_nullifiers: BoundedVec::new(), - public_call_stack: BoundedVec::new(), - public_data_update_requests: BoundedVec::new(), - } - } -} - -impl AccumulatedNonRevertibleDataBuilder { - pub fn to_private(self) -> PrivateAccumulatedNonRevertibleData { - PrivateAccumulatedNonRevertibleData { - revert_code: self.revert_code, - new_note_hashes: self.new_note_hashes.storage, - new_nullifiers: self.new_nullifiers.storage, - public_call_stack: self.public_call_stack.storage - } - } - pub fn to_public(self) -> PublicAccumulatedNonRevertibleData { - PublicAccumulatedNonRevertibleData { - revert_code: self.revert_code, - new_note_hashes: self.new_note_hashes.storage, - new_nullifiers: self.new_nullifiers.storage, - public_call_stack: self.public_call_stack.storage, - public_data_update_requests: self.public_data_update_requests.storage - } - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_revertible_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_revertible_data_builder.nr deleted file mode 100644 index 49827cff945..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/accumulated_revertible_data_builder.nr +++ /dev/null @@ -1,82 +0,0 @@ -use crate::{ - abis::{ - accumulated_data::{ - private_accumulated_revertible_data::PrivateAccumulatedRevertibleData, - public_accumulated_revertible_data::PublicAccumulatedRevertibleData -}, - call_request::CallRequest, public_data_update_request::PublicDataUpdateRequest, - side_effect::{SideEffect, SideEffectLinkedToNoteHash} -} -}; -use crate::constants::{ - MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, - MAX_REVERTIBLE_NOTE_HASHES_PER_TX, MAX_REVERTIBLE_NULLIFIERS_PER_TX, - MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX -}; - -struct AccumulatedRevertibleDataBuilder { - new_note_hashes: BoundedVec, - new_nullifiers: BoundedVec, - - private_call_stack: BoundedVec, - public_call_stack: BoundedVec, - new_l2_to_l1_msgs: BoundedVec, - - encrypted_logs_hash: Field, - unencrypted_logs_hash: Field, - - // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the - // variable-length data. - encrypted_log_preimages_length: Field, - unencrypted_log_preimages_length: Field, - - public_data_update_requests: BoundedVec, -} - -impl Default for AccumulatedRevertibleDataBuilder { - fn default() -> Self { - AccumulatedRevertibleDataBuilder { - new_note_hashes: BoundedVec::new(), - new_nullifiers: BoundedVec::new(), - private_call_stack: BoundedVec::new(), - public_call_stack: BoundedVec::new(), - new_l2_to_l1_msgs: BoundedVec::new(), - encrypted_logs_hash: 0, - unencrypted_logs_hash: 0, - encrypted_log_preimages_length: 0, - unencrypted_log_preimages_length: 0, - public_data_update_requests: BoundedVec::new(), - } - } -} - -impl AccumulatedRevertibleDataBuilder { - pub fn to_private(self) -> PrivateAccumulatedRevertibleData { - PrivateAccumulatedRevertibleData { - new_note_hashes: self.new_note_hashes.storage, - new_nullifiers: self.new_nullifiers.storage, - private_call_stack: self.private_call_stack.storage, - public_call_stack: self.public_call_stack.storage, - new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, - encrypted_logs_hash: self.encrypted_logs_hash, - unencrypted_logs_hash: self.unencrypted_logs_hash, - encrypted_log_preimages_length: self.encrypted_log_preimages_length, - unencrypted_log_preimages_length: self.unencrypted_log_preimages_length - } - } - - pub fn to_public(self) -> PublicAccumulatedRevertibleData { - PublicAccumulatedRevertibleData { - new_note_hashes: self.new_note_hashes.storage, - new_nullifiers: self.new_nullifiers.storage, - private_call_stack: self.private_call_stack.storage, - public_call_stack: self.public_call_stack.storage, - new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, - encrypted_logs_hash: self.encrypted_logs_hash, - unencrypted_logs_hash: self.unencrypted_logs_hash, - encrypted_log_preimages_length: self.encrypted_log_preimages_length, - unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, - public_data_update_requests: self.public_data_update_requests.storage - } - } -} From 57fbcbfe1a94a76e19905cc013700a7c112da56f Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 17:58:32 +0000 Subject: [PATCH 33/77] sync --- ...private_accumulated_non_revertible_data.nr | 28 -------------- .../private_accumulated_revertible_data.nr | 31 --------------- .../public_accumulated_non_revertible_data.nr | 36 ------------------ .../public_accumulated_revertible_data.nr | 38 ------------------- 4 files changed, 133 deletions(-) delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_non_revertible_data.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_revertible_data.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_non_revertible_data.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_revertible_data.nr diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_non_revertible_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_non_revertible_data.nr deleted file mode 100644 index d6919a0f646..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_non_revertible_data.nr +++ /dev/null @@ -1,28 +0,0 @@ -use crate::{abis::{call_request::CallRequest, side_effect::{SideEffect, SideEffectLinkedToNoteHash}}}; -use crate::constants::{ - MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, - MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX -}; -use crate::traits::is_default; - -struct PrivateAccumulatedNonRevertibleData { - revert_code: u8, - new_note_hashes: [SideEffect; MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX], - new_nullifiers: [SideEffectLinkedToNoteHash; MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX], - public_call_stack: [CallRequest; MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX], -} - -impl PrivateAccumulatedNonRevertibleData { - pub fn needs_setup(self) -> bool { - // By definition, the final non-revertible enqueued call is for teardown. - // since this is a stack, the teardown call would be the 0th element. - // So if we have more than one element, we need setup. - !is_default(self.public_call_stack[1]) - } - - pub fn needs_teardown(self) -> bool { - // By definition, the final non-revertible enqueued call is for teardown. - // since this is a stack, the teardown call would be the 0th element. - !is_default(self.public_call_stack[0]) - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_revertible_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_revertible_data.nr deleted file mode 100644 index 4215813aa39..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_revertible_data.nr +++ /dev/null @@ -1,31 +0,0 @@ -use crate::{abis::{call_request::CallRequest, side_effect::{SideEffect, SideEffectLinkedToNoteHash}}}; -use crate::constants::{ - MAX_REVERTIBLE_NOTE_HASHES_PER_TX, MAX_REVERTIBLE_NULLIFIERS_PER_TX, - MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, - MAX_NEW_L2_TO_L1_MSGS_PER_TX -}; -use crate::traits::is_default; - -struct PrivateAccumulatedRevertibleData { - new_note_hashes: [SideEffect; MAX_REVERTIBLE_NOTE_HASHES_PER_TX], - new_nullifiers: [SideEffectLinkedToNoteHash; MAX_REVERTIBLE_NULLIFIERS_PER_TX], - - private_call_stack: [CallRequest; MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], - public_call_stack: [CallRequest; MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX], - new_l2_to_l1_msgs: [Field; MAX_NEW_L2_TO_L1_MSGS_PER_TX], - - encrypted_logs_hash: Field, - unencrypted_logs_hash: Field, - - // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the - // variable-length data. - encrypted_log_preimages_length: Field, - unencrypted_log_preimages_length: Field, -} - -impl PrivateAccumulatedRevertibleData { - pub fn needs_app_logic(self) -> bool { - // if we have any enqueued revertible public calls, we need to run the public app logic circuit. - !is_default(self.public_call_stack[0]) - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_non_revertible_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_non_revertible_data.nr deleted file mode 100644 index c972429461b..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_non_revertible_data.nr +++ /dev/null @@ -1,36 +0,0 @@ -use crate::{ - abis::{ - call_request::CallRequest, public_data_update_request::PublicDataUpdateRequest, - side_effect::{SideEffect, SideEffectLinkedToNoteHash}, - }, - traits::is_default, - utils::arrays::{array_cp, array_concat, array_to_bounded_vec}, - constants::{ - MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, - MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, - MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX - }, -}; - -struct PublicAccumulatedNonRevertibleData { - revert_code: u8, - new_note_hashes: [SideEffect; MAX_NON_REVERTIBLE_NOTE_HASHES_PER_TX], - new_nullifiers: [SideEffectLinkedToNoteHash; MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX], - public_call_stack: [CallRequest; MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX], - public_data_update_requests: [PublicDataUpdateRequest; MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], -} - -impl PublicAccumulatedNonRevertibleData { - pub fn needs_setup(self) -> bool { - // By definition, the final non-revertible enqueued call is for teardown. - // since this is a stack, the teardown call would be the 0th element. - // So if we have more than one element, we need setup. - !is_default(self.public_call_stack[1]) - } - - pub fn needs_teardown(self) -> bool { - // By definition, the final non-revertible enqueued call is for teardown. - // since this is a stack, the teardown call would be the 0th element. - !is_default(self.public_call_stack[0]) - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_revertible_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_revertible_data.nr deleted file mode 100644 index ee88dfb0cd1..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_revertible_data.nr +++ /dev/null @@ -1,38 +0,0 @@ -use crate::{ - abis::{ - call_request::CallRequest, public_data_update_request::PublicDataUpdateRequest, - side_effect::{SideEffect, SideEffectLinkedToNoteHash}, - }, - constants::{ - MAX_REVERTIBLE_NOTE_HASHES_PER_TX, MAX_REVERTIBLE_NULLIFIERS_PER_TX, - MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, - MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX - }, - traits::is_default, -}; - -struct PublicAccumulatedRevertibleData { - new_note_hashes: [SideEffect; MAX_REVERTIBLE_NOTE_HASHES_PER_TX], - new_nullifiers: [SideEffectLinkedToNoteHash; MAX_REVERTIBLE_NULLIFIERS_PER_TX], - - private_call_stack: [CallRequest; MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], - public_call_stack: [CallRequest; MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX], - new_l2_to_l1_msgs: [Field; MAX_NEW_L2_TO_L1_MSGS_PER_TX], - - encrypted_logs_hash: Field, - unencrypted_logs_hash: Field, - - // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the - // variable-length data. - encrypted_log_preimages_length: Field, - unencrypted_log_preimages_length: Field, - - public_data_update_requests: [PublicDataUpdateRequest; MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], -} - -impl PublicAccumulatedRevertibleData { - pub fn needs_app_logic(self) -> bool { - // if we have any enqueued revertible public calls, we need to run the public app logic circuit. - !is_default(self.public_call_stack[0]) - } -} From 626ba6ad371d0acae955b92863de0658901228f0 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 18:08:06 +0000 Subject: [PATCH 34/77] sync --- .../crates/types/src/abis/append_only_tree_snapshot.nr | 3 +-- .../crates/types/src/abis/call_request.nr | 3 +-- .../crates/types/src/abis/caller_context.nr | 3 +-- .../crates/types/src/abis/public_data_read.nr | 3 +-- .../crates/types/src/abis/public_data_update_request.nr | 3 +-- .../crates/types/src/abis/read_request.nr | 3 +-- .../crates/types/src/contrakt/storage_read.nr | 3 +-- .../crates/types/src/contrakt/storage_update_request.nr | 3 +-- .../crates/types/src/public_data_tree_leaf.nr | 3 +-- .../noir-protocol-circuits/crates/types/src/traits.nr | 3 +-- 10 files changed, 10 insertions(+), 20 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr index fa66db86454..e41a73b9c4a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr @@ -1,5 +1,4 @@ -use dep::std::cmp::Eq; -use dep::std::default::Default; +use dep::std::{cmp::Eq,default::Default}; struct AppendOnlyTreeSnapshot { root : Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr index eab77beeeb2..498fc1e16ca 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr @@ -1,6 +1,5 @@ use crate::address::AztecAddress; -use dep::std::cmp::Eq; -use dep::std::default::Default; +use dep::std::{cmp::Eq,default::Default}; use crate::abis::caller_context::CallerContext; struct CallRequest { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr index 04eb47250a0..e6f2a9801bd 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr @@ -1,6 +1,5 @@ use crate::address::AztecAddress; -use dep::std::cmp::Eq; -use dep::std::default::Default; +use dep::std::{cmp::Eq,default::Default}; struct CallerContext { msg_sender: AztecAddress, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr index 049eec8c75b..446d74cfe5f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr @@ -1,6 +1,5 @@ use crate::constants::GENERATOR_INDEX__PUBLIC_DATA_READ; -use dep::std::cmp::Eq; -use dep::std::default::Default; +use dep::std::{cmp::Eq,default::Default}; use crate::traits::Hash; struct PublicDataRead { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr index e5be1f24e95..2f477fc4b2f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr @@ -1,6 +1,5 @@ use crate::constants::GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST; -use dep::std::cmp::Eq; -use dep::std::default::Default; +use dep::std::{cmp::Eq,default::Default}; use crate::traits::Hash; struct PublicDataUpdateRequest { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr index ffe1f09dedf..5bcd8bb82eb 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr @@ -2,8 +2,7 @@ use crate::{ abis::side_effect::{OrderedValue, ContractScopedOrderedValue}, traits::{Serialize, Deserialize}, address::AztecAddress }; -use dep::std::cmp::Eq; -use dep::std::default::Default; +use dep::std::{cmp::Eq,default::Default}; global READ_REQUEST_SERIALIZED_LEN = 2; global READ_REQUEST_CONTEXT_SERIALIZED_LEN = 3; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr index b0d72c35a8c..2d2e550a637 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr @@ -2,8 +2,7 @@ use crate::{ constants::{CONTRACT_STORAGE_READ_LENGTH, GENERATOR_INDEX__PUBLIC_DATA_READ}, hash::pedersen_hash, traits::{Deserialize, Hash, Serialize} }; -use dep::std::cmp::Eq; -use dep::std::default::Default; +use dep::std::{cmp::Eq,default::Default}; struct StorageRead { storage_slot: Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr index a6e8c9bfe40..4e09efc3969 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr @@ -2,8 +2,7 @@ use crate::{ constants::{CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH, GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST}, hash::pedersen_hash, traits::{Deserialize, Hash, Serialize} }; -use dep::std::cmp::Eq; -use dep::std::default::Default; +use dep::std::{cmp::Eq,default::Default}; struct StorageUpdateRequest{ storage_slot : Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr index 5cdb09f962b..09bf94a1409 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr @@ -1,5 +1,4 @@ -use dep::std::cmp::Eq; -use dep::std::default::Default; +use dep::std::{cmp::Eq,default::Default}; struct PublicDataTreeLeaf { slot: Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr index 30beefda263..96a487ff729 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr @@ -1,5 +1,4 @@ -use dep::std::cmp::Eq; -use dep::std::default::Default; +use dep::std::{cmp::Eq,default::Default}; pub fn is_default(item: T) -> bool where T: Default + Eq { item.eq(T::default()) From bcd67b3175de511d311ad4fd5c48ae5ae741998e Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 18:27:37 +0000 Subject: [PATCH 35/77] align --- .../types/src/tests/kernel_data_builder.nr | 342 ------------------ .../kernel/private_kernel_tail_data.ts | 66 ---- 2 files changed, 408 deletions(-) delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr delete mode 100644 yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_data.ts diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr deleted file mode 100644 index 0a6d55dfba1..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/kernel_data_builder.nr +++ /dev/null @@ -1,342 +0,0 @@ -use crate::{ - abis::{ - call_context::CallContext, call_request::{CallerContext, CallRequest}, - combined_constant_data::CombinedConstantData, - accumulated_data::{CombinedAccumulatedDataBuilder, AccumulatedNonRevertibleDataBuilder, AccumulatedRevertibleDataBuilder}, - kernel_circuit_public_inputs::{ - PrivateKernelInnerCircuitPublicInputs, PrivateKernelTailCircuitPublicInputs, - PublicKernelCircuitPublicInputs, RollupKernelCircuitPublicInputs -}, - kernel_data::{PrivateKernelInnerData, PublicKernelData, RollupKernelData}, - max_block_number::MaxBlockNumber, public_data_read::PublicDataRead, - public_data_update_request::PublicDataUpdateRequest, read_request::ReadRequestContext, - side_effect::{SideEffect, SideEffectLinkedToNoteHash}, - validation_requests::ValidationRequestsBuilder -}, - address::{AztecAddress, EthAddress}, header::Header, hash::silo_nullifier, - mocked::{AggregationObject, Proof, VerificationKey}, - tests::{fixtures, testing_harness::build_tx_context}, transaction::tx_context::TxContext -}; -use crate::constants::{ - MAX_NEW_NOTE_HASHES_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, - MAX_PUBLIC_DATA_READS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, VK_TREE_HEIGHT -}; -use dep::std::unsafe; - -struct PreviousKernelDataBuilder { - contract_address: AztecAddress, - storage_contract_address: AztecAddress, - portal_contract_address: EthAddress, - validation_requests: ValidationRequestsBuilder, - end: CombinedAccumulatedDataBuilder, - end_non_revertible: AccumulatedNonRevertibleDataBuilder, - historical_header: Header, - tx_context: TxContext, - is_private: bool, - proof: Proof, - vk: VerificationKey, - vk_index: u32, - vk_path: [Field; VK_TREE_HEIGHT], - sideffect_counter: u32, - min_revertible_side_effect_counter: u32, -} - -impl Default for PreviousKernelDataBuilder { - fn default() -> Self { - PreviousKernelDataBuilder { - contract_address: AztecAddress::default(), - storage_contract_address: AztecAddress::default(), - portal_contract_address: EthAddress::default(), - validation_requests: ValidationRequestsBuilder::default(), - end: CombinedAccumulatedDataBuilder::default(), - end_non_revertible: AccumulatedNonRevertibleDataBuilder::default(), - historical_header: Header::default(), - tx_context: TxContext::default(), - is_private: false, - proof: Proof::default(), - vk: VerificationKey::default(), - vk_index: 0 as u32, - vk_path: [0; VK_TREE_HEIGHT], - sideffect_counter: 0 as u32, - min_revertible_side_effect_counter: 0 as u32, - } - } -} - -impl PreviousKernelDataBuilder { - pub fn new(is_for_public: bool) -> Self { - let mut end = CombinedAccumulatedDataBuilder::default(); - let mut end_non_revertible = AccumulatedNonRevertibleDataBuilder::default(); - // 0th nullifier must be non-zero. - let tx_nullifier = SideEffectLinkedToNoteHash { value: 321, note_hash: 0, counter: 0 }; - // but the public kernels expect this first nullifier to have been partitioned into - // the non-revertible set - - if is_for_public == true { - end_non_revertible.new_nullifiers.push(tx_nullifier); - } else { - end.new_nullifiers.push(tx_nullifier); - } - - let tx_context = build_tx_context(); - - PreviousKernelDataBuilder { - contract_address: fixtures::contracts::parent_contract.address, - storage_contract_address: fixtures::contracts::parent_contract.address, - portal_contract_address: fixtures::contracts::parent_contract.portal_contract_address, - validation_requests: ValidationRequestsBuilder::default(), - end, - end_non_revertible, - historical_header: fixtures::HEADER, - tx_context, - is_private: true, - proof: Proof {}, - vk: VerificationKey {}, - vk_index: 0, - vk_path: [0; VK_TREE_HEIGHT], - sideffect_counter: 2, - min_revertible_side_effect_counter: 2 - } - } - - pub fn is_public(&mut self) -> Self { - self.is_private = false; - *self - } - - pub fn set_max_block_number(&mut self, max_block_number: u32) { - self.validation_requests.max_block_number = MaxBlockNumber::new(max_block_number); - } - - pub fn append_public_data_update_requests(&mut self, num_updates: u64) { - let value_offset = self.end.public_data_update_requests.len(); - for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX { - if i < num_updates { - let update_request = PublicDataUpdateRequest { - // The default leaf index is its index + 23. - leaf_slot: (value_offset + i + 23) as Field, - // The default value is its index + 678. - new_value: (value_offset + i + 678) as Field - }; - self.end.public_data_update_requests.push(update_request); - } - } - } - - pub fn append_public_data_read_requests(&mut self, num_reads: u64) { - let value_offset = self.validation_requests.public_data_reads.len(); - for i in 0..MAX_PUBLIC_DATA_READS_PER_TX { - if i < num_reads { - let read_request = PublicDataRead { - // The default leaf index is its index + 34. - leaf_slot: (value_offset + i + 34) as Field, - // The default value is its index + 5566. - value: (value_offset + i + 5566) as Field - }; - self.validation_requests.public_data_reads.push(read_request); - } - } - } - - fn next_sideffect_counter(&mut self) -> u32 { - let counter = self.sideffect_counter; - self.sideffect_counter += 1; - counter - } - - pub fn add_read_request_for_transient_commitment(&mut self, commitment_index: u64) -> u64 { - let new_read_request_index = self.validation_requests.note_hash_read_requests.len(); - let commitment = self.end.new_note_hashes.get(commitment_index); - let read_request = SideEffect { value: commitment.value, counter: self.next_sideffect_counter() }; - self.validation_requests.note_hash_read_requests.push(read_request); - new_read_request_index - } - - pub fn append_new_note_hashes(&mut self, num_new_note_hashes: u64) { - let mocked_value_offset = self.end.new_note_hashes.len() + 1; - for i in 0..MAX_NEW_NOTE_HASHES_PER_TX { - if i < num_new_note_hashes { - // The default value is its index + 1. - self.end.new_note_hashes.push( - SideEffect { value: (i + mocked_value_offset) as Field, counter: self.next_sideffect_counter() } - ); - } - } - } - - fn get_mock_nullifier_value(_self: Self, nullifier_index: u64) -> Field { - let value_offset = 5678; - value_offset + nullifier_index as Field - } - - fn get_mock_nullifier_value_non_revertible(_self: Self, nullifier_index: u64) -> Field { - let value_offset = 987; - value_offset + nullifier_index as Field - } - - pub fn add_nullifier(&mut self, unsiloed_nullifier: Field) { - let value = silo_nullifier(self.storage_contract_address, unsiloed_nullifier); - self.end.new_nullifiers.push(SideEffectLinkedToNoteHash { value, note_hash: 0, counter: self.next_sideffect_counter() }); - } - - pub fn add_nullifier_non_revertible(&mut self, unsiloed_nullifier: Field) { - let value = silo_nullifier(self.storage_contract_address, unsiloed_nullifier); - self.end_non_revertible.new_nullifiers.push(SideEffectLinkedToNoteHash { value, note_hash: 0, counter: self.next_sideffect_counter() }); - } - - pub fn append_new_nullifiers_from_private(&mut self, num_extra_nullifier: u64) { - // in private kernel, the nullifiers have not yet been partitioned - // (that is part of the job of the private kernel tail) - // so the tx nullifier is in `end` - let index_offset = self.end.new_nullifiers.len(); - for i in 0..MAX_NEW_NULLIFIERS_PER_TX { - if i < num_extra_nullifier { - let mock_value = self.get_mock_nullifier_value(index_offset + i); - self.add_nullifier(mock_value); - } - } - } - - pub fn append_new_nullifiers_from_public(&mut self, num_extra_nullifier: u64) { - let index_offset = self.end.new_nullifiers.len(); - for i in 0..MAX_NEW_NULLIFIERS_PER_TX { - if i < num_extra_nullifier { - let mock_value = self.get_mock_nullifier_value(index_offset + i); - self.add_nullifier(mock_value); - } - } - } - - pub fn append_new_nullifiers_non_revertible_from_public(&mut self, num_extra_nullifier: u64) { - let index_offset = self.end_non_revertible.new_nullifiers.len(); - for i in 0..MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX { - if i < num_extra_nullifier { - let mock_value = self.get_mock_nullifier_value_non_revertible(index_offset + i); - self.add_nullifier_non_revertible(mock_value); - } - } - } - - pub fn add_read_request_for_pending_nullifier(&mut self, nullifier_index: u64) -> u64 { - let read_request_index = self.validation_requests.nullifier_read_requests.len(); - let unsiloed_nullifier = self.get_mock_nullifier_value(nullifier_index); - let read_request = ReadRequestContext { - value: unsiloed_nullifier, - counter: self.next_sideffect_counter(), - contract_address: self.storage_contract_address - }; - self.validation_requests.nullifier_read_requests.push(read_request); - read_request_index - } - - pub fn add_read_request_for_pending_non_revertible_nullifier(&mut self, nullifier_index: u64) -> u64 { - let read_request_index = self.validation_requests.nullifier_read_requests.len(); - let unsiloed_nullifier = self.get_mock_nullifier_value_non_revertible(nullifier_index); - let read_request = ReadRequestContext { - value: unsiloed_nullifier, - counter: self.next_sideffect_counter(), - contract_address: self.storage_contract_address - }; - self.validation_requests.nullifier_read_requests.push(read_request); - read_request_index - } - - pub fn add_non_existent_read_request_for_nullifier(&mut self, unsiloed_nullifier: Field) { - let read_request = ReadRequestContext { - value: unsiloed_nullifier, - counter: self.next_sideffect_counter(), - contract_address: self.storage_contract_address - }; - self.validation_requests.nullifier_non_existent_read_requests.push(read_request); - } - - // snapshot the side effects - // this is useful in the private tail circuit to test side effect splitting - pub fn capture_min_revertible_side_effect_counter(&mut self) { - self.min_revertible_side_effect_counter = self.sideffect_counter; - } - - pub fn set_encrypted_logs(&mut self, hash: Field, preimages_length: Field) { - self.end.encrypted_logs_hash = hash; - self.end.encrypted_log_preimages_length = preimages_length; - } - - pub fn set_unencrypted_logs(&mut self, hash: Field, preimages_length: Field) { - self.end.unencrypted_logs_hash = hash; - self.end.unencrypted_log_preimages_length = preimages_length; - } - - pub fn push_private_call_request(&mut self, hash: Field, is_delegate_call: bool) { - let call_stack_item = self.generate_call_request(hash, is_delegate_call); - self.end.private_call_stack.push(call_stack_item); - } - - pub fn push_public_call_request(&mut self, hash: Field, is_delegate_call: bool) { - let call_stack_item = self.generate_call_request(hash, is_delegate_call); - self.end.public_call_stack.push(call_stack_item); - } - - pub fn push_public_call_request_non_revertible(&mut self, hash: Field, is_delegate_call: bool) { - let call_stack_item = self.generate_call_request(hash, is_delegate_call); - self.end_non_revertible.public_call_stack.push(call_stack_item); - } - - fn generate_call_request(&mut self, hash: Field, is_delegate_call: bool) -> CallRequest { - let mut caller_context = CallerContext::default(); - if is_delegate_call { - caller_context.msg_sender = fixtures::MSG_SENDER; - caller_context.storage_contract_address = self.contract_address; - } - let counter = self.next_sideffect_counter(); - let end_counter = counter + 10; - self.sideffect_counter = end_counter; - CallRequest { - hash, - caller_contract_address: self.contract_address, - caller_context, - start_side_effect_counter: counter, - end_side_effect_counter: end_counter - } - } - - pub fn to_private_kernel_inner_data(self) -> PrivateKernelInnerData { - let public_inputs = PrivateKernelInnerCircuitPublicInputs { - aggregation_object: AggregationObject {}, - min_revertible_side_effect_counter: self.min_revertible_side_effect_counter, - end: self.end.finish(), - validation_requests: self.validation_requests.finish(), - constants: CombinedConstantData { historical_header: self.historical_header, tx_context: self.tx_context }, - is_private: self.is_private - }; - PrivateKernelInnerData { public_inputs, proof: self.proof, vk: self.vk, vk_index: self.vk_index, vk_path: self.vk_path } - } - - pub fn to_public_kernel_data(self) -> PublicKernelData { - let end_non_revertible = self.end_non_revertible.to_public(); - let end = self.end.to_public_accumulated_revertible_data(); - let public_inputs = PublicKernelCircuitPublicInputs { - aggregation_object: AggregationObject {}, - end_non_revertible, - end, - validation_requests: self.validation_requests.finish(), - rollup_validation_requests: self.validation_requests.to_rollup(), - constants: CombinedConstantData { historical_header: self.historical_header, tx_context: self.tx_context }, - needs_setup: end_non_revertible.needs_setup(), - needs_app_logic: end.needs_app_logic(), - needs_teardown: end_non_revertible.needs_teardown() - }; - - PublicKernelData { public_inputs, proof: self.proof, vk: self.vk, vk_index: self.vk_index, vk_path: self.vk_path } - } - - pub fn to_rollup_kernel_data(self) -> RollupKernelData { - let public_inputs = RollupKernelCircuitPublicInputs { - aggregation_object: AggregationObject {}, - end: self.end.finish(), - constants: CombinedConstantData { historical_header: self.historical_header, tx_context: self.tx_context }, - rollup_validation_requests: self.validation_requests.to_rollup() - }; - - RollupKernelData { public_inputs, proof: self.proof, vk: self.vk, vk_index: self.vk_index, vk_path: self.vk_path } - } -} diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_data.ts deleted file mode 100644 index 7754f694506..00000000000 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_data.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { makeTuple } from '@aztec/foundation/array'; -import { Fr } from '@aztec/foundation/fields'; -import { BufferReader, Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; - -import { VK_TREE_HEIGHT } from '../../constants.gen.js'; -import { Proof, makeEmptyProof } from '../proof.js'; -import { UInt32 } from '../shared.js'; -import { VerificationKey } from '../verification_key.js'; -import { PrivateKernelTailCircuitPublicInputs } from './private_kernel_tail_circuit_public_inputs.js'; - -/** - * Data of the private kernel tail. - */ -export class PrivateKernelTailData { - constructor( - /** - * Outputs of the private kernel tail. - */ - public publicInputs: PrivateKernelTailCircuitPublicInputs, - /** - * Proof of the previous kernel. - */ - public proof: Proof, - /** - * Verification key of the previous kernel. - */ - public vk: VerificationKey, - /** - * Index of the previous kernel's vk in a tree of vks. - */ - public vkIndex: UInt32, - /** - * Sibling path of the previous kernel's vk in a tree of vks. - */ - public vkPath: Tuple, - ) {} - - static fromBuffer(buffer: Buffer | BufferReader): PrivateKernelTailData { - const reader = BufferReader.asReader(buffer); - return new this( - reader.readObject(PrivateKernelTailCircuitPublicInputs), - reader.readObject(Proof), - reader.readObject(VerificationKey), - reader.readNumber(), - reader.readArray(VK_TREE_HEIGHT, Fr), - ); - } - - static default(): PrivateKernelTailData { - return new this( - PrivateKernelTailCircuitPublicInputs.default(), - makeEmptyProof(), - VerificationKey.makeFake(), - 0, - makeTuple(VK_TREE_HEIGHT, Fr.default), - ); - } - - /** - * Serialize this as a buffer. - * @returns The buffer. - */ - toBuffer() { - return serializeToBuffer(this.publicInputs, this.proof, this.vk, this.vkIndex, this.vkPath); - } -} From 6fd559fe2b647fe8c29cae58f5209b5a72ecc6a4 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 18:30:45 +0000 Subject: [PATCH 36/77] fix --- yarn-project/circuit-types/src/logs/tx_l2_logs.ts | 2 +- yarn-project/end-to-end/src/e2e_cheat_codes.test.ts | 2 +- yarn-project/end-to-end/src/e2e_deploy_contract.test.ts | 2 +- yarn-project/foundation/src/eth-address/eth_address.test.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/yarn-project/circuit-types/src/logs/tx_l2_logs.ts b/yarn-project/circuit-types/src/logs/tx_l2_logs.ts index d2d1a80225f..2d474f08c4c 100644 --- a/yarn-project/circuit-types/src/logs/tx_l2_logs.ts +++ b/yarn-project/circuit-types/src/logs/tx_l2_logs.ts @@ -148,7 +148,7 @@ export class UnencryptedTxL2Logs extends TxL2Logs { } export class EncryptedTxL2Logs extends TxL2Logs { - /** Creates a empty instance. */ + /** Creates an empty instance. */ public static default() { return new EncryptedTxL2Logs([]); } diff --git a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts index 20905605d68..4735de6e7d2 100644 --- a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts +++ b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts @@ -89,7 +89,7 @@ describe('e2e_cheat_codes', () => { it('load a value at a particular storage slot', async () => { // check that storage slot 0 is empty as expected - const res = await cc.eth.load(EthAddress.ZERO, 0n); + const res = await cc.eth.load(EthAddress.default(), 0n); expect(res).toBe(0n); }); diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts index 6e22ae60296..68b22473f6b 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts @@ -126,7 +126,7 @@ describe('e2e_deploy_contract', () => { const artifact = TokenContractArtifact; const initArgs = ['TokenName', 'TKN', 18] as const; const goodDeploy = StatefulTestContract.deploy(wallet, wallet.getAddress(), 42); - const badDeploy = new ContractDeployer(artifact, wallet).deploy(AztecAddress.ZERO, ...initArgs); + const badDeploy = new ContractDeployer(artifact, wallet).deploy(AztecAddress.default(), ...initArgs); const firstOpts = { skipPublicSimulation: true, skipClassRegistration: true, skipInstanceDeploy: true }; const secondOpts = { skipPublicSimulation: true }; diff --git a/yarn-project/foundation/src/eth-address/eth_address.test.ts b/yarn-project/foundation/src/eth-address/eth_address.test.ts index fd593c4e74a..5ec28973607 100644 --- a/yarn-project/foundation/src/eth-address/eth_address.test.ts +++ b/yarn-project/foundation/src/eth-address/eth_address.test.ts @@ -19,7 +19,7 @@ describe('address', () => { }); it('should have correct zero address', () => { - expect(EthAddress.ZERO.toString()).toBe('0x0000000000000000000000000000000000000000'); + expect(EthAddress.default().toString()).toBe('0x0000000000000000000000000000000000000000'); }); it('should check if is zero', () => { From ac8e9809934e1376a69c5856e2980223cdf39747 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 18:31:23 +0000 Subject: [PATCH 37/77] fix --- yarn-project/circuit-types/src/tx/processed_tx.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/circuit-types/src/tx/processed_tx.ts b/yarn-project/circuit-types/src/tx/processed_tx.ts index 63cad5cba7f..3c0cfbb215d 100644 --- a/yarn-project/circuit-types/src/tx/processed_tx.ts +++ b/yarn-project/circuit-types/src/tx/processed_tx.ts @@ -32,7 +32,7 @@ export type ProcessedTx = Pick Date: Fri, 5 Apr 2024 18:41:50 +0000 Subject: [PATCH 38/77] fix --- .../compiling_contracts/how_to_compile_contract.md | 2 +- yarn-project/aztec.js/src/contract/contract.ts | 2 +- yarn-project/aztec.js/src/deployment/contract_deployer.ts | 2 +- yarn-project/circuits.js/src/contract/contract_instance.ts | 2 +- yarn-project/circuits.js/src/hints/build_hints.test.ts | 6 +++--- yarn-project/circuits.js/src/structs/l2_to_l1_message.ts | 2 +- .../src/structs/nullifier_key_validation_request.ts | 4 ++-- yarn-project/foundation/src/fields/point.ts | 4 ++++ .../noir-compiler/src/contract-interface-gen/typescript.ts | 4 ++-- yarn-project/protocol-contracts/src/gas-token/index.ts | 2 +- .../protocol-contracts/src/multi-call-entrypoint/index.ts | 2 +- yarn-project/protocol-contracts/src/protocol_contract.ts | 2 +- 12 files changed, 19 insertions(+), 15 deletions(-) diff --git a/docs/docs/developers/contracts/compiling_contracts/how_to_compile_contract.md b/docs/docs/developers/contracts/compiling_contracts/how_to_compile_contract.md index 7d78818d4ff..4aca1f9c6f4 100644 --- a/docs/docs/developers/contracts/compiling_contracts/how_to_compile_contract.md +++ b/docs/docs/developers/contracts/compiling_contracts/how_to_compile_contract.md @@ -52,7 +52,7 @@ export class TokenContract extends ContractBase { * Creates a tx to deploy a new instance of this contract. */ public static deploy(pxe: PXE, admin: AztecAddressLike) { - return new DeployMethod(Point.ZERO, pxe, TokenContractArtifact, Array.from(arguments).slice(1)); + return new DeployMethod(Point.default(), pxe, TokenContractArtifact, Array.from(arguments).slice(1)); } /** diff --git a/yarn-project/aztec.js/src/contract/contract.ts b/yarn-project/aztec.js/src/contract/contract.ts index 36b4c831a4b..7d5ec2da8c2 100644 --- a/yarn-project/aztec.js/src/contract/contract.ts +++ b/yarn-project/aztec.js/src/contract/contract.ts @@ -40,7 +40,7 @@ export class Contract extends ContractBase { */ public static deploy(wallet: Wallet, artifact: ContractArtifact, args: any[], constructorName?: string) { const postDeployCtor = (address: AztecAddress, wallet: Wallet) => Contract.at(address, artifact, wallet); - return new DeployMethod(Point.ZERO, wallet, artifact, postDeployCtor, args, constructorName); + return new DeployMethod(Point.default(), wallet, artifact, postDeployCtor, args, constructorName); } /** diff --git a/yarn-project/aztec.js/src/deployment/contract_deployer.ts b/yarn-project/aztec.js/src/deployment/contract_deployer.ts index bd0f04ea74f..fe2a334a2ac 100644 --- a/yarn-project/aztec.js/src/deployment/contract_deployer.ts +++ b/yarn-project/aztec.js/src/deployment/contract_deployer.ts @@ -31,7 +31,7 @@ export class ContractDeployer { public deploy(...args: any[]) { const postDeployCtor = (address: AztecAddress, wallet: Wallet) => Contract.at(address, this.artifact, wallet); return new DeployMethod( - this.publicKey ?? Point.ZERO, + this.publicKey ?? Point.default(), this.wallet, this.artifact, postDeployCtor, diff --git a/yarn-project/circuits.js/src/contract/contract_instance.ts b/yarn-project/circuits.js/src/contract/contract_instance.ts index 28349fbd7bb..269e79810b2 100644 --- a/yarn-project/circuits.js/src/contract/contract_instance.ts +++ b/yarn-project/circuits.js/src/contract/contract_instance.ts @@ -32,7 +32,7 @@ export function getContractInstanceFromDeployParams( ): ContractInstanceWithAddress { const args = opts.constructorArgs ?? []; const salt = opts.salt ?? Fr.random(); - const publicKey = opts.publicKey ?? Point.ZERO; + const publicKey = opts.publicKey ?? Point.default(); const portalContractAddress = opts.portalAddress ?? EthAddress.default(); const constructorArtifact = getConstructorArtifact(artifact, opts.constructorArtifact); const deployer = opts.deployer ?? AztecAddress.default(); diff --git a/yarn-project/circuits.js/src/hints/build_hints.test.ts b/yarn-project/circuits.js/src/hints/build_hints.test.ts index 09292527a77..c174af9e8ae 100644 --- a/yarn-project/circuits.js/src/hints/build_hints.test.ts +++ b/yarn-project/circuits.js/src/hints/build_hints.test.ts @@ -165,8 +165,8 @@ describe('buildNullifierNonExistentReadRequestHints', () => { it('builds default hints', async () => { const hints = await buildHints(); - const emptyHints = NullifierNonExistentReadRequestHintsBuilder.default(); - expect(hints).toEqual(emptyHints); + const defaultHints = NullifierNonExistentReadRequestHintsBuilder.default(); + expect(hints).toEqual(defaultHints); }); it('builds hints for full sorted nullifiers', async () => { @@ -200,7 +200,7 @@ describe('buildNullifierNonExistentReadRequestHints', () => { expect(nullifiers[i].value.equals(sortedPendingValues[index].value)).toBe(true); } - // The second half is empty. + // The second half is default (empty). for (let i = numNonEmptyNullifiers; i < sortedPendingValues.length; ++i) { expect(sortedPendingValues[i]).toEqual(SideEffectLinkedToNoteHash.default()); } diff --git a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts index e86133a652c..5d580952222 100644 --- a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts +++ b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts @@ -71,6 +71,6 @@ export class L2ToL1Message { * @returns True if recipient is default and content is zero. */ isDefault(): boolean { - return this.recipient.isDefault() && this.content.isZero(); + return this.recipient.isDefault() && this.content.isDefault(); } } diff --git a/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts b/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts index 0c8227fdbcc..bb7cc61c645 100644 --- a/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts +++ b/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts @@ -52,7 +52,7 @@ export class NullifierKeyValidationRequest { } static default() { - return new NullifierKeyValidationRequest(Point.ZERO, GrumpkinScalar.ZERO); + return new NullifierKeyValidationRequest(Point.default(), GrumpkinScalar.ZERO); } } @@ -112,6 +112,6 @@ export class NullifierKeyValidationRequestContext { } static default() { - return new NullifierKeyValidationRequestContext(Point.ZERO, GrumpkinScalar.ZERO, AztecAddress.default()); + return new NullifierKeyValidationRequestContext(Point.default(), GrumpkinScalar.ZERO, AztecAddress.default()); } } diff --git a/yarn-project/foundation/src/fields/point.ts b/yarn-project/foundation/src/fields/point.ts index aef3fe8236b..24c61981022 100644 --- a/yarn-project/foundation/src/fields/point.ts +++ b/yarn-project/foundation/src/fields/point.ts @@ -34,6 +34,10 @@ export class Point { return new Point(Fr.random(), Fr.random()); } + static default() { + return Point.default(); + } + /** * Create a Point instance from a given buffer or BufferReader. * The input 'buffer' should have exactly 64 bytes representing the x and y coordinates. diff --git a/yarn-project/noir-compiler/src/contract-interface-gen/typescript.ts b/yarn-project/noir-compiler/src/contract-interface-gen/typescript.ts index 1a77f8916cb..bf996cc2499 100644 --- a/yarn-project/noir-compiler/src/contract-interface-gen/typescript.ts +++ b/yarn-project/noir-compiler/src/contract-interface-gen/typescript.ts @@ -82,7 +82,7 @@ function generateDeploy(input: ContractArtifact) { * Creates a tx to deploy a new instance of this contract. */ public static deploy(wallet: Wallet, ${args}) { - return new DeployMethod<${contractName}>(Point.ZERO, wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(1)); + return new DeployMethod<${contractName}>(Point.default(), wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(1)); } /** @@ -100,7 +100,7 @@ function generateDeploy(input: ContractArtifact) { ...args: Parameters<${contractName}['methods'][M]> ) { return new DeployMethod<${contractName}>( - opts.publicKey ?? Point.ZERO, + opts.publicKey ?? Point.default(), opts.wallet, ${artifactName}, ${contractName}.at, diff --git a/yarn-project/protocol-contracts/src/gas-token/index.ts b/yarn-project/protocol-contracts/src/gas-token/index.ts index d38126bf262..4b486331937 100644 --- a/yarn-project/protocol-contracts/src/gas-token/index.ts +++ b/yarn-project/protocol-contracts/src/gas-token/index.ts @@ -5,7 +5,7 @@ import { GasTokenArtifact } from './artifact.js'; /** Returns the canonical deployment of the gas token. */ export function getCanonicalGasToken(l1Bridge: EthAddress): ProtocolContract { - return getCanonicalProtocolContract(GasTokenArtifact, 1, [], Point.ZERO, l1Bridge); + return getCanonicalProtocolContract(GasTokenArtifact, 1, [], Point.default(), l1Bridge); } export function getCanonicalGasTokenAddress(l1Bridge: EthAddress): AztecAddress { diff --git a/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts b/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts index 0cd1b58abd9..3951e0ad12c 100644 --- a/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts +++ b/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts @@ -4,7 +4,7 @@ import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol import { MultiCallEntrypointArtifact } from './artifact.js'; export function getCanonicalMultiCallEntrypointContract(): ProtocolContract { - return getCanonicalProtocolContract(MultiCallEntrypointArtifact, 1, [], Point.ZERO, EthAddress.default()); + return getCanonicalProtocolContract(MultiCallEntrypointArtifact, 1, [], Point.default(), EthAddress.default()); } export function getCanonicalMultiCallEntrypointAddress(): AztecAddress { diff --git a/yarn-project/protocol-contracts/src/protocol_contract.ts b/yarn-project/protocol-contracts/src/protocol_contract.ts index e6d503429d4..8581e61007e 100644 --- a/yarn-project/protocol-contracts/src/protocol_contract.ts +++ b/yarn-project/protocol-contracts/src/protocol_contract.ts @@ -25,7 +25,7 @@ export function getCanonicalProtocolContract( artifact: ContractArtifact, salt: Fr | number | bigint, constructorArgs: any[] = [], - publicKey: Point = Point.ZERO, + publicKey: Point = Point.default(), portalAddress = EthAddress.default(), ): ProtocolContract { // TODO(@spalladino): This computes the contract class from the artifact twice. From 2657a82950d717643735a8d64772d65bd11ff29b Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 18:43:43 +0000 Subject: [PATCH 39/77] fix --- .../circuits.js/src/structs/public_circuit_public_inputs.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts index ac3522a76a7..09778c5c7c8 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts @@ -132,8 +132,8 @@ export class PublicCircuitPublicInputs { } /** - * Returns an default instance (zeroed). - * @returns An default instance (zeroed). + * Returns a default instance (zeroed). + * @returns A default instance (zeroed). */ public static default() { return new PublicCircuitPublicInputs( From b668055778531114423d2484ed168412f72d9fe7 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 18:44:20 +0000 Subject: [PATCH 40/77] fix --- yarn-project/circuits.js/src/structs/l2_to_l1_message.ts | 2 +- .../src/structs/public_circuit_public_inputs.test.ts | 2 +- yarn-project/circuits.js/src/structs/side_effects.ts | 2 +- yarn-project/circuits.js/src/tests/factories.ts | 4 ++-- yarn-project/foundation/src/abi/event_selector.ts | 4 ++-- yarn-project/foundation/src/abi/function_selector.ts | 4 ++-- yarn-project/merkle-tree/src/interfaces/indexed_tree.ts | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts index 5d580952222..19953cd26ee 100644 --- a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts +++ b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts @@ -8,7 +8,7 @@ export class L2ToL1Message { constructor(public recipient: EthAddress, public content: Fr) {} /** - * Creates an default L2ToL1Message with default values. + * Creates a default L2ToL1Message with default values. * @returns An instance of L2ToL1Message with default fields. */ static default(): L2ToL1Message { diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts index 4edbe7a4ac2..6c25d1c42bb 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.test.ts @@ -15,7 +15,7 @@ describe('PublicCircuitPublicInputs', () => { expect(res).toEqual(expected); }); - it(`initializes an default PrivateCircuitPublicInputs`, () => { + it(`initializes a default PrivateCircuitPublicInputs`, () => { const target = PublicCircuitPublicInputs.default(); expect(target.isDefault()).toBe(true); }); diff --git a/yarn-project/circuits.js/src/structs/side_effects.ts b/yarn-project/circuits.js/src/structs/side_effects.ts index bd498c6c3da..4fc4cba5a97 100644 --- a/yarn-project/circuits.js/src/structs/side_effects.ts +++ b/yarn-project/circuits.js/src/structs/side_effects.ts @@ -155,7 +155,7 @@ export class SideEffectLinkedToNoteHash implements SideEffectType { } /** - * Returns an default instance of side-effect (zeroed). + * Returns a default instance of side-effect (zeroed). * @returns Side-effect with value, note hash and counter being zero. */ static default(): SideEffectLinkedToNoteHash { diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index f9175349ef6..3727f167049 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -222,7 +222,7 @@ export function makePublicDataUpdateRequest(seed = 1): PublicDataUpdateRequest { /** * Creates default public data update request. - * @returns An default public data update request. + * @returns A default public data update request. */ export function makeDefaultPublicDataUpdateRequest(): PublicDataUpdateRequest { return new PublicDataUpdateRequest(fr(0), fr(0)); @@ -239,7 +239,7 @@ export function makePublicDataRead(seed = 1): PublicDataRead { /** * Creates default public data read. - * @returns An default public data read. + * @returns A default public data read. */ export function makeDefaultPublicDataRead(): PublicDataRead { return new PublicDataRead(fr(0), fr(0)); diff --git a/yarn-project/foundation/src/abi/event_selector.ts b/yarn-project/foundation/src/abi/event_selector.ts index 69e664445ef..95a66b5dfc3 100644 --- a/yarn-project/foundation/src/abi/event_selector.ts +++ b/yarn-project/foundation/src/abi/event_selector.ts @@ -64,8 +64,8 @@ export class EventSelector extends Selector { } /** - * Creates an default selector. - * @returns An default selector. + * Creates a default selector. + * @returns A default selector. */ static default() { return new EventSelector(0); diff --git a/yarn-project/foundation/src/abi/function_selector.ts b/yarn-project/foundation/src/abi/function_selector.ts index 83c722f3927..9b36bde2f50 100644 --- a/yarn-project/foundation/src/abi/function_selector.ts +++ b/yarn-project/foundation/src/abi/function_selector.ts @@ -92,8 +92,8 @@ export class FunctionSelector extends Selector { } /** - * Creates an default selector. - * @returns An default selector. + * Creates a default selector. + * @returns A default selector. */ static default() { return new FunctionSelector(0); diff --git a/yarn-project/merkle-tree/src/interfaces/indexed_tree.ts b/yarn-project/merkle-tree/src/interfaces/indexed_tree.ts index 9fbf13032ed..6b36f44a5ea 100644 --- a/yarn-project/merkle-tree/src/interfaces/indexed_tree.ts +++ b/yarn-project/merkle-tree/src/interfaces/indexed_tree.ts @@ -26,7 +26,7 @@ export interface PreimageFactory { */ fromBuffer(buffer: Buffer): IndexedTreeLeafPreimage; /** - * Creates an default preimage. + * Creates a default preimage. */ default(): IndexedTreeLeafPreimage; /** From dad29c9beade2629da5e847c0602bca368249ae7 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 19:07:27 +0000 Subject: [PATCH 41/77] fix --- yarn-project/circuits.js/src/structs/tx_context.ts | 4 ++-- yarn-project/foundation/src/fields/fields.test.ts | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/yarn-project/circuits.js/src/structs/tx_context.ts b/yarn-project/circuits.js/src/structs/tx_context.ts index 853e0eabd31..99dcda629ee 100644 --- a/yarn-project/circuits.js/src/structs/tx_context.ts +++ b/yarn-project/circuits.js/src/structs/tx_context.ts @@ -67,8 +67,8 @@ export class TxContext { return new TxContext(false, false, new Fr(chainId), new Fr(version)); } - isDefault(): boolean { - return !this.isFeePaymentTx && !this.isRebatePaymentTx && this.chainId.isZero() && this.version.isZero(); + isDefault(chainId: number = 0, version: number = 0): boolean { + return !this.isFeePaymentTx && !this.isRebatePaymentTx && this.chainId.equals(new Fr(chainId)) && this.version.equals(new Fr(version)); } /** diff --git a/yarn-project/foundation/src/fields/fields.test.ts b/yarn-project/foundation/src/fields/fields.test.ts index 8764df6e089..ceb602400ec 100644 --- a/yarn-project/foundation/src/fields/fields.test.ts +++ b/yarn-project/foundation/src/fields/fields.test.ts @@ -179,8 +179,7 @@ describe('Bn254 arithmetic', () => { [new Fr(5), new Fr(5), 0], [new Fr(0), new Fr(Fr.MODULUS - 1n), -1], [new Fr(Fr.MODULUS - 1n), new Fr(0), 1], - [Fr.ZERO, Fr.ZERO, 0], - [Fr.ZERO, Fr.ZERO, 0], + [Fr.ZERO, Fr.default(), 0], ])('Should compare field elements correctly', (a, b, expected) => { expect(a.cmp(b)).toEqual(expected); }); From 7ba3c1c88c79811270dc3441a50197599d81cdec Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 19:12:48 +0000 Subject: [PATCH 42/77] fix --- l1-contracts/test/portals/TokenPortal.sol | 2 +- l1-contracts/test/portals/TokenPortal.t.sol | 4 ++-- l1-contracts/test/portals/UniswapPortal.t.sol | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/l1-contracts/test/portals/TokenPortal.sol b/l1-contracts/test/portals/TokenPortal.sol index 1553673d1ef..dee5749b6b5 100644 --- a/l1-contracts/test/portals/TokenPortal.sol +++ b/l1-contracts/test/portals/TokenPortal.sol @@ -117,7 +117,7 @@ contract TokenPortal { _amount, _withCaller ? msg.sender : address(0) ) - ) + ) }); IOutbox outbox = registry.getOutbox(); diff --git a/l1-contracts/test/portals/TokenPortal.t.sol b/l1-contracts/test/portals/TokenPortal.t.sol index 550afbe5bc8..b1aa83db59f 100644 --- a/l1-contracts/test/portals/TokenPortal.t.sol +++ b/l1-contracts/test/portals/TokenPortal.t.sol @@ -83,7 +83,7 @@ contract TokenPortalTest is Test { abi.encodeWithSignature( "mint_private(bytes32,uint256)", secretHashForRedeemingMintedNotes, amount ) - ), + ), secretHash: secretHashForL2MessageConsumption }); } @@ -161,7 +161,7 @@ contract TokenPortalTest is Test { abi.encodeWithSignature( "withdraw(address,uint256,address)", recipient, withdrawAmount, _designatedCaller ) - ) + ) }) ); diff --git a/l1-contracts/test/portals/UniswapPortal.t.sol b/l1-contracts/test/portals/UniswapPortal.t.sol index b525e78a494..7a16abbf3d3 100644 --- a/l1-contracts/test/portals/UniswapPortal.t.sol +++ b/l1-contracts/test/portals/UniswapPortal.t.sol @@ -80,7 +80,7 @@ contract UniswapPortalTest is Test { recipient: DataStructures.L1Actor(address(daiTokenPortal), block.chainid), content: Hash.sha256ToField( abi.encodeWithSignature("withdraw(address,uint256,address)", _recipient, amount, _caller) - ) + ) }); return message.sha256ToField(); @@ -112,7 +112,7 @@ contract UniswapPortalTest is Test { secretHash, _caller ) - ) + ) }); return message.sha256ToField(); @@ -143,7 +143,7 @@ contract UniswapPortalTest is Test { secretHash, _caller ) - ) + ) }); return message.sha256ToField(); From f1a1ef372cdd2f6b14c6f1cb19b90a96d25dc744 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 19:58:57 +0000 Subject: [PATCH 43/77] fix --- .../crates/private-kernel-lib/src/private_kernel_inner.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 07bdbc70476..38177e0996f 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 @@ -123,7 +123,7 @@ mod tests { } } - #[test(should_fail_with = "contract address cannot be zero")] + #[test(should_fail_with = "contract address cannot be default (zero)")] fn private_function_zero_storage_contract_address_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new(); From 3aedba2ae40564fd103e13705343012f951f30aa Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 19:59:17 +0000 Subject: [PATCH 44/77] fix --- .../crates/public-kernel-lib/src/common.nr | 2 +- .../crates/public-kernel-lib/src/public_kernel_setup.nr | 2 +- .../crates/public-kernel-lib/src/public_kernel_teardown.nr | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index bbf8aa154e1..471a8e32997 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -24,7 +24,7 @@ pub fn validate_inputs(public_call: PublicCallData) { // Validates commons inputs for all type of kernel inputs let this_call_stack_item: PublicCallStackItem = public_call.call_stack_item; assert( - !this_call_stack_item.contract_address.eq(AztecAddress::default()), "Contract address cannot be zero" + !this_call_stack_item.contract_address.eq(AztecAddress::default()), "contract address cannot be default (zero)" ); assert(this_call_stack_item.function_data.selector.to_field() != 0, "Function signature cannot be zero"); assert( diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr index fbe1017fcd3..0aaeaf26ec6 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr @@ -198,7 +198,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="Contract address cannot be zero")] + #[test(should_fail_with="contract address cannot be default (zero)")] fn contract_address_must_be_valid() { let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); builder.public_call.contract_address = AztecAddress::default(); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr index cd0472a9749..ef88cbb0af5 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr @@ -147,7 +147,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="Contract address cannot be zero")] + #[test(should_fail_with="contract address cannot be default (zero)")] fn contract_address_must_be_valid() { let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); builder.public_call.contract_address = AztecAddress::default(); From b78f9fdae3a99de5d9b005494a2932cabbbdab2f Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 5 Apr 2024 20:53:14 +0000 Subject: [PATCH 45/77] address comments --- .../crates/private-kernel-lib/src/common.nr | 4 ++-- .../crates/private-kernel-lib/src/private_kernel_inner.nr | 4 ++-- .../crates/public-kernel-lib/src/common.nr | 6 +++--- .../crates/public-kernel-lib/src/public_kernel_app_logic.nr | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr index 3a9eb16ea02..60d3d178c7a 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr @@ -120,10 +120,10 @@ fn perform_static_call_checks(private_call: PrivateCallData) { if is_static_call { // No state changes are allowed for static calls: assert( - is_default_array(public_inputs.new_note_hashes), "new_note_hashes must be a default array (zeroed) for static calls" + is_default_array(public_inputs.new_note_hashes), "new_note_hashes must be a default array (empty) for static calls" ); assert( - is_default_array(public_inputs.new_nullifiers), "new_nullifiers must be a default array (zeroed) for static calls" + is_default_array(public_inputs.new_nullifiers), "new_nullifiers must be a default array (empty) for static calls" ); let new_l2_to_l1_msgs_length = array_length(public_inputs.new_l2_to_l1_msgs); 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 38177e0996f..b48e1a036bf 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 @@ -691,7 +691,7 @@ mod tests { assert_eq(public_inputs.end.unencrypted_logs_hash, expected_unencrypted_logs_hash); } - #[test(should_fail_with="new_note_hashes must be a default array (zeroed) for static calls")] + #[test(should_fail_with="new_note_hashes must be a default array (empty) for static calls")] fn creating_new_note_hashes_on_static_call_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_static_call(); @@ -700,7 +700,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_nullifiers must be a default array (zeroed) for static calls")] + #[test(should_fail_with="new_nullifiers must be a default array (empty) for static calls")] fn creating_new_nullifiers_on_static_call_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_static_call(); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index 471a8e32997..c171c25f126 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -113,10 +113,10 @@ fn perform_static_call_checks(public_call: PublicCallData) { if public_inputs.call_context.is_static_call { // No state changes are allowed for static calls: let new_note_hashes_length = array_length(public_inputs.new_note_hashes); - assert(new_note_hashes_length == 0, "new_note_hashes must be a default array (zeroed) for static calls"); + assert(new_note_hashes_length == 0, "new_note_hashes must be a default array (empty) for static calls"); let new_nullifiers_length = array_length(public_inputs.new_nullifiers); - assert(new_nullifiers_length == 0, "new_nullifiers must be a default array (zeroed) for static calls"); + assert(new_nullifiers_length == 0, "new_nullifiers must be a default array (empty) for static calls"); let update_requests_length = array_length(public_inputs.contract_storage_update_requests); assert( @@ -124,7 +124,7 @@ fn perform_static_call_checks(public_call: PublicCallData) { ); let new_l2_to_l1_msgs_length = array_length(public_inputs.new_l2_to_l1_msgs); - assert(new_l2_to_l1_msgs_length == 0, "new_l2_to_l1_msgs must be default for static calls"); + assert(new_l2_to_l1_msgs_length == 0, "new_l2_to_l1_msgs must be empty (length 0) for static calls"); // TODO: reevaluate when implementing https://github.com/AztecProtocol/aztec-packages/issues/1165 // This 4 magical number is the minimum size of the buffer, since it has to store the total length of all the serialized logs. diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr index 209969b254f..79e2dbbc17c 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr @@ -341,7 +341,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_note_hashes must be a default array (zeroed) for static calls")] + #[test(should_fail_with="new_note_hashes must be a default array (empty) for static calls")] fn public_kernel_fails_creating_new_note_hashes_on_static_call() { let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); builder.public_call.public_inputs.call_context.is_static_call = true; @@ -350,7 +350,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_nullifiers must be a default array (zeroed) for static calls")] + #[test(should_fail_with="new_nullifiers must be a default array (empty) for static calls")] fn public_kernel_fails_creating_new_nullifiers_on_static_call() { let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); builder.public_call.public_inputs.call_context.is_static_call = true; From 34bb1b5b160de86724d811adab888cbc3b45efa9 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Sat, 6 Apr 2024 05:32:06 +0000 Subject: [PATCH 46/77] fix --- yarn-project/foundation/src/fields/point.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/foundation/src/fields/point.ts b/yarn-project/foundation/src/fields/point.ts index 24c61981022..1cef5cf6e74 100644 --- a/yarn-project/foundation/src/fields/point.ts +++ b/yarn-project/foundation/src/fields/point.ts @@ -35,7 +35,7 @@ export class Point { } static default() { - return Point.default(); + return Point.ZERO; } /** From a7a9bf8604acffacb05a859c17020b1d92178b56 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Mon, 8 Apr 2024 19:15:32 +0000 Subject: [PATCH 47/77] noir adsf --- docs/docs/misc/migration_notes.md | 6 ++-- .../aztec-nr/authwit/src/entrypoint/app.nr | 4 +-- .../aztec-nr/authwit/src/entrypoint/fee.nr | 4 +-- .../aztec-nr/aztec/src/context/avm_context.nr | 4 +-- .../aztec/src/context/private_context.nr | 6 ++-- .../aztec/src/context/public_context.nr | 2 +- noir-projects/aztec-nr/aztec/src/deploy.nr | 4 +-- .../aztec-nr/aztec/src/initializer.nr | 6 ++-- .../aztec-nr/aztec/src/note/note_header.nr | 2 +- .../contracts/card_game_contract/src/game.nr | 4 +-- .../src/main.nr | 2 +- .../token_blacklist_contract/src/main.nr | 4 +-- .../contracts/token_contract/src/main.nr | 4 +-- .../contracts/uniswap_contract/src/main.nr | 10 +++--- .../crates/private-kernel-lib/src/common.nr | 9 ++--- .../src/private_kernel_inner.nr | 6 ++-- .../src/private_kernel_tail.nr | 2 +- .../crates/public-kernel-lib/src/common.nr | 8 ++--- .../src/public_kernel_setup.nr | 4 +-- .../src/public_kernel_teardown.nr | 4 +-- .../src/non_existent_read_request_reset.nr | 34 +++++++++---------- .../crates/types/src/abis/call_request.nr | 2 +- .../crates/types/src/abis/caller_context.nr | 4 +-- .../crates/types/src/abis/global_variables.nr | 4 +-- .../abis/nullifier_key_validation_request.nr | 2 +- .../src/abis/public_circuit_public_inputs.nr | 2 +- .../crates/types/src/address/aztec_address.nr | 14 ++++++-- .../crates/types/src/address/eth_address.nr | 14 ++++++-- .../types/src/messaging/l2_to_l1_message.nr | 2 +- .../crates/types/src/tests/fixture_builder.nr | 4 +-- .../crates/types/src/tests/fixtures.nr | 26 +++++++------- .../public_circuit_public_inputs_builder.nr | 2 +- .../crates/types/src/traits.nr | 8 +++++ .../archiver/src/archiver/archiver.test.ts | 8 ++--- yarn-project/archiver/src/archiver/config.ts | 14 ++++---- .../aztec-node/src/aztec-node/server.ts | 4 +-- .../aztec.js/src/contract/deploy_method.ts | 2 +- .../src/deployment/deploy_instance.ts | 2 +- yarn-project/aztec/src/cli/util.ts | 2 +- .../circuit-types/src/function_call.ts | 2 +- .../circuit-types/src/messaging/l1_actor.ts | 2 +- .../circuit-types/src/messaging/l2_actor.ts | 2 +- .../src/contract/contract_instance.ts | 4 +-- ...nconstrained_function_broadcasted_event.ts | 2 +- .../circuits.js/src/structs/call_context.ts | 22 ++++-------- .../circuits.js/src/structs/call_request.ts | 8 ++--- .../src/structs/global_variables.ts | 6 ++-- .../kernel/combined_accumulated_data.ts | 2 +- .../src/structs/kernel/kernel_data.ts | 2 +- .../kernel/private_accumulated_data.ts | 2 +- .../src/structs/kernel/private_kernel_data.ts | 2 +- .../structs/kernel/public_accumulated_data.ts | 2 +- .../src/structs/kernel/public_kernel_data.ts | 2 +- .../src/structs/l2_to_l1_message.ts | 8 ++--- .../nullifier_key_validation_request.ts | 4 +-- .../src/structs/private_call_stack_item.ts | 4 +-- .../structs/private_circuit_public_inputs.ts | 6 ++-- .../src/structs/public_call_stack_item.ts | 8 ++--- .../structs/public_circuit_public_inputs.ts | 6 ++-- .../circuits.js/src/structs/read_request.ts | 2 +- .../circuits.js/src/structs/tx_request.ts | 4 +-- .../circuits.js/src/tests/factories.ts | 12 +++---- yarn-project/cli/src/cmds/add_contract.ts | 4 +-- .../end-to-end/src/e2e_card_game.test.ts | 2 +- .../end-to-end/src/e2e_cheat_codes.test.ts | 2 +- .../src/e2e_cross_chain_messaging.test.ts | 2 +- .../src/e2e_deploy_contract.test.ts | 2 +- .../e2e_public_cross_chain_messaging.test.ts | 2 +- .../src/integration_l1_publisher.test.ts | 2 +- .../src/shared/cross_chain_test_harness.ts | 6 ++-- .../src/shared/gas_portal_test_harness.ts | 4 +-- .../foundation/src/aztec-address/index.ts | 10 +----- .../src/eth-address/eth_address.test.ts | 4 +-- .../foundation/src/eth-address/index.ts | 10 +++--- .../foundation/src/fields/fields.test.ts | 3 +- yarn-project/foundation/src/fields/fields.ts | 10 ++---- .../src/noir_test_gen.test.ts | 2 +- .../src/gas-token/index.test.ts | 2 +- .../src/multi-call-entrypoint/index.ts | 2 +- .../src/protocol_contract.ts | 2 +- .../src/orchestrator/orchestrator.test.ts | 4 +-- .../pxe/src/kernel_prover/hints_builder.ts | 4 +-- .../src/kernel_prover/kernel_prover.test.ts | 2 +- yarn-project/sequencer-client/src/config.ts | 14 ++++---- .../src/sequencer/abstract_phase_manager.ts | 2 +- .../src/sequencer/public_processor.test.ts | 2 +- .../src/sequencer/sequencer.ts | 4 +-- .../src/sequencer/tx_validator.test.ts | 4 +-- .../simulator/src/avm/fixtures/index.ts | 14 ++++---- .../src/client/execution_result.test.ts | 2 +- .../src/client/private_execution.test.ts | 14 ++++---- .../simulator/src/client/simulator.ts | 2 +- .../simulator/src/public/index.test.ts | 8 ++--- .../src/public/public_execution_context.ts | 4 +-- 94 files changed, 259 insertions(+), 251 deletions(-) diff --git a/docs/docs/misc/migration_notes.md b/docs/docs/misc/migration_notes.md index 61f5facd669..650d6821e3e 100644 --- a/docs/docs/misc/migration_notes.md +++ b/docs/docs/misc/migration_notes.md @@ -26,9 +26,11 @@ This will change to become similar to the return values of the `unconstrained` f ### [Aztec.nr] [Aztec.js] IsEmpty / IsZero have been unified and renamed to IsDefault +N.B: Fields and Addresses have not been changed + ```diff -- Fr.zero(); -+ Fr.default(); +- Point.ZERO; ++ Point.default(); - Header::empty(); + Header::default(); diff --git a/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr b/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr index f9b85886118..d65334c6b02 100644 --- a/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr +++ b/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr @@ -1,5 +1,5 @@ use dep::aztec::prelude::PrivateContext; -use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize, is_default}}; +use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize, is_zero}}; use crate::entrypoint::function_call::{FunctionCall, FUNCTION_CALL_SIZE_IN_BYTES}; @@ -56,7 +56,7 @@ impl AppPayload { // docs:start:entrypoint-execute-calls fn execute_calls(self, context: &mut PrivateContext) { for call in self.function_calls { - if !is_default(call.target_address) { + if !is_zero(call.target_address) { if call.is_public { context.call_public_function_with_packed_args( call.target_address, diff --git a/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr b/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr index ac7cb5962ca..f4a238045e5 100644 --- a/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr +++ b/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr @@ -1,5 +1,5 @@ use dep::aztec::prelude::PrivateContext; -use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__FEE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize, is_default}}; +use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__FEE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize, is_zero}}; use crate::entrypoint::function_call::FunctionCall; // 2 * 4 (function call) + 1 @@ -52,7 +52,7 @@ impl FeePayload { fn execute_calls(self, context: &mut PrivateContext) { for call in self.function_calls { - if !is_default(call.target_address) { + if !is_zero(call.target_address) { if call.is_public { context.call_public_function_with_packed_args( call.target_address, diff --git a/noir-projects/aztec-nr/aztec/src/context/avm_context.nr b/noir-projects/aztec-nr/aztec/src/context/avm_context.nr index f39b01ba7a1..c5145ed84e8 100644 --- a/noir-projects/aztec-nr/aztec/src/context/avm_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/avm_context.nr @@ -84,12 +84,12 @@ impl PublicContextInterface for AvmContext { fn coinbase(self) -> EthAddress { assert(false, "'coinbase' not implemented!"); - EthAddress::default() + EthAddress::zero() } fn fee_recipient(self) -> AztecAddress { assert(false, "'fee_recipient' not implemented!"); - AztecAddress::default() + AztecAddress::zero() } fn push_nullifier_read_request(&mut self, nullifier: Field) { diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 06c25b030b8..813e4f76863 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -29,7 +29,7 @@ use dep::protocol_types::{ }, contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, grumpkin_private_key::GrumpkinPrivateKey, header::Header, - messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, traits::is_default + messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, traits::is_zero }; // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) @@ -145,7 +145,7 @@ impl PrivateContext { pub fn new(inputs: PrivateContextInputs, args_hash: Field) -> PrivateContext { let side_effect_counter = inputs.start_side_effect_counter; let mut min_revertible_side_effect_counter = 0; - if is_default(inputs.call_context.msg_sender) { + if is_zero(inputs.call_context.msg_sender) { min_revertible_side_effect_counter = side_effect_counter; } PrivateContext { @@ -497,7 +497,7 @@ impl PrivateContext { unencrypted_logs_hash: 0, unencrypted_log_preimages_length: 0, historical_header: Header::default(), - prover_address: AztecAddress::default(), + prover_address: AztecAddress::zero(), revert_code: 0 }, is_execution_request: true diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index 8b3692c017d..7d341348707 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -68,7 +68,7 @@ impl PublicContext { unencrypted_logs_hash: 0, unencrypted_logs_preimages_length: 0, historical_header: inputs.historical_header, - prover_address: AztecAddress::default() + prover_address: AztecAddress::zero() // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) // encrypted_logs_preimages: Vec::new(), // unencrypted_logs_preimages: Vec::new(), diff --git a/noir-projects/aztec-nr/aztec/src/deploy.nr b/noir-projects/aztec-nr/aztec/src/deploy.nr index dc44d1e4cca..7a3988778ff 100644 --- a/noir-projects/aztec-nr/aztec/src/deploy.nr +++ b/noir-projects/aztec-nr/aztec/src/deploy.nr @@ -1,12 +1,12 @@ use crate::{context::PrivateContext, oracle::get_contract_instance::get_contract_instance}; -use dep::protocol_types::{address::AztecAddress, abis::function_selector::FunctionSelector, constants::DEPLOYER_CONTRACT_ADDRESS, traits::is_default}; +use dep::protocol_types::{address::AztecAddress, abis::function_selector::FunctionSelector, constants::DEPLOYER_CONTRACT_ADDRESS, traits::is_zero}; // Calls `deploy` on the deployer contract to deploy a new instance. pub fn deploy_contract(context: &mut PrivateContext, target: AztecAddress) { let instance = get_contract_instance(target); - let universal_deploy = is_default(instance.deployer); + let universal_deploy = is_zero(instance.deployer); if !universal_deploy { assert( instance.deployer == context.this_address(), "Deployer address does not match current address" diff --git a/noir-projects/aztec-nr/aztec/src/initializer.nr b/noir-projects/aztec-nr/aztec/src/initializer.nr index a6021fa2faf..ab5e7e1081f 100644 --- a/noir-projects/aztec-nr/aztec/src/initializer.nr +++ b/noir-projects/aztec-nr/aztec/src/initializer.nr @@ -1,6 +1,6 @@ use dep::protocol_types::{ address::AztecAddress, hash::{silo_nullifier, pedersen_hash}, - constants::GENERATOR_INDEX__CONSTRUCTOR, abis::function_selector::FunctionSelector, traits::is_default + constants::GENERATOR_INDEX__CONSTRUCTOR, abis::function_selector::FunctionSelector, traits::is_zero }; use crate::{ @@ -65,7 +65,7 @@ pub fn assert_initialization_matches_address_preimage_avm(context: AvmContext) { let expected_init = compute_initialization_hash(context.selector(), context.get_args_hash()); assert(instance.initialization_hash == expected_init, "Initialization hash does not match"); assert( - is_default(instance.deployer) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer" + is_zero(instance.deployer) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer" ); } @@ -78,7 +78,7 @@ fn assert_initialization_matches_address_preimage(context: TContext) w let instance = get_contract_instance(address); let expected_init = compute_initialization_hash(context.selector(), context.get_args_hash()); assert(instance.initialization_hash == expected_init, "Initialization hash does not match"); - assert(is_default(instance.deployer) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer"); + assert(is_zero(instance.deployer) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer"); } pub fn compute_initialization_hash(init_selector: FunctionSelector, init_args_hash: Field) -> Field { diff --git a/noir-projects/aztec-nr/aztec/src/note/note_header.nr b/noir-projects/aztec-nr/aztec/src/note/note_header.nr index a2ce86b5ff8..fb95c561a76 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_header.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_header.nr @@ -13,7 +13,7 @@ struct NoteHeader { impl Default for NoteHeader { fn default() -> Self { - NoteHeader { contract_address: AztecAddress::default(), nonce: 0, storage_slot: 0, is_transient: false } + NoteHeader { contract_address: AztecAddress::zero(), nonce: 0, storage_slot: 0, is_transient: false } } } diff --git a/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr b/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr index f45e97132a3..3d876762e02 100644 --- a/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr +++ b/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr @@ -1,4 +1,4 @@ -use dep::aztec::protocol_types::{address::AztecAddress, traits::{Serialize, Deserialize, is_default}}; +use dep::aztec::protocol_types::{address::AztecAddress, traits::{Serialize, Deserialize, is_zero}}; use crate::cards::Card; global NUMBER_OF_PLAYERS = 2; @@ -12,7 +12,7 @@ struct PlayerEntry { impl PlayerEntry { pub fn is_initialized(self) -> bool { - !is_default(self.address) + !is_zero(self.address) } } diff --git a/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr b/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr index c12043d94a9..3363324acff 100644 --- a/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr @@ -23,7 +23,7 @@ contract ContractInstanceDeployer { // TODO(@spalladino): assert nullifier_exists silo(contract_class_id, ContractClassRegisterer) let deployer = if universal_deploy { - AztecAddress::default() + AztecAddress::zero() } else { context.msg_sender() }; diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr index d914e5d06b8..0b27ede3458 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr @@ -15,7 +15,7 @@ mod interfaces; contract TokenBlacklist { // Libs - use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress, traits::is_default}; + use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress, traits::is_zero}; use dep::aztec::{ note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader}, hash::compute_secret_hash, state_vars::{Map, PublicMutable, PrivateSet, SharedImmutable} @@ -45,7 +45,7 @@ contract TokenBlacklist { #[aztec(initializer)] fn constructor(admin: AztecAddress, slow_updates_contract: AztecAddress) { // docs:end:constructor - assert(!is_default(admin), "invalid admin"); + assert(!is_zero(admin), "invalid admin"); storage.admin.write(admin); // docs:start:write_slow_update_public storage.slow_update.initialize(slow_updates_contract); diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr index 46c421d1674..ade53ef28dd 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -19,7 +19,7 @@ contract Token { NoteGetterOptions, NoteHeader, Map, PublicMutable, SharedImmutable, PrivateSet, FunctionSelector, AztecAddress }, - hash::compute_secret_hash, protocol_types::traits::is_default + hash::compute_secret_hash, protocol_types::traits::is_zero }; // docs:start:import_authwit @@ -58,7 +58,7 @@ contract Token { #[aztec(public)] #[aztec(initializer)] fn constructor(admin: AztecAddress, name: str<31>, symbol: str<31>, decimals: u8) { - assert(!is_default(admin), "invalid admin"); + assert(!is_zero(admin), "invalid admin"); storage.admin.write(admin); storage.minters.at(admin).write(true); storage.name.initialize(FieldCompressedString::from_string(name)); diff --git a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr index d4dd2d91ff4..374fb0c1c7e 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr @@ -9,7 +9,7 @@ contract Uniswap { use dep::aztec::{ prelude::{FunctionSelector, AztecAddress, EthAddress, Map, PublicMutable}, oracle::context::get_portal_address, - protocol_types::traits::is_default, + protocol_types::traits::is_zero, }; use dep::authwit::auth::{ @@ -77,10 +77,10 @@ contract Uniswap { let output_asset_bridge_portal_address = get_portal_address(output_asset_bridge); // ensure portal exists - else funds might be lost assert( - !is_default(input_asset_bridge_portal_address), "L1 portal address of input_asset's bridge is 0" + !is_zero(input_asset_bridge_portal_address), "L1 portal address of input_asset's bridge is 0" ); assert( - !is_default(output_asset_bridge_portal_address), "L1 portal address of output_asset's bridge is 0" + !is_zero(output_asset_bridge_portal_address), "L1 portal address of output_asset's bridge is 0" ); let content_hash = compute_swap_public_content_hash( @@ -144,10 +144,10 @@ contract Uniswap { let output_asset_bridge_portal_address = get_portal_address(output_asset_bridge); // ensure portal exists - else funds might be lost assert( - !is_default(input_asset_bridge_portal_address), "L1 portal address of input_asset's bridge is 0" + !is_zero(input_asset_bridge_portal_address), "L1 portal address of input_asset's bridge is 0" ); assert( - !is_default(output_asset_bridge_portal_address), "L1 portal address of output_asset's bridge is 0" + !is_zero(output_asset_bridge_portal_address), "L1 portal address of output_asset's bridge is 0" ); let content_hash = compute_swap_private_content_hash( diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr index 60d3d178c7a..a0ba9916c4d 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr @@ -21,7 +21,7 @@ use dep::types::{ }, merkle_tree::check_membership, utils::{arrays::{array_length, array_to_bounded_vec, validate_array}}, - traits::{is_default, is_default_array} + traits::{is_default, is_default_array, is_zero} }; pub fn validate_arrays(app_public_inputs: PrivateCircuitPublicInputs) { @@ -120,12 +120,13 @@ fn perform_static_call_checks(private_call: PrivateCallData) { if is_static_call { // No state changes are allowed for static calls: assert( - is_default_array(public_inputs.new_note_hashes), "new_note_hashes must be a default array (empty) for static calls" + is_default_array(public_inputs.new_note_hashes), "new_note_hashes must be empty (only default values) for static calls" ); assert( - is_default_array(public_inputs.new_nullifiers), "new_nullifiers must be a default array (empty) for static calls" + is_default_array(public_inputs.new_nullifiers), "new_nullifiers must be empty (only default values) for static calls" ); + // TODO: #5618 let new_l2_to_l1_msgs_length = array_length(public_inputs.new_l2_to_l1_msgs); assert(new_l2_to_l1_msgs_length == 0, "new_l2_to_l1_msgs must be empty (length 0) for static calls"); @@ -311,7 +312,7 @@ pub fn contract_logic(private_call: PrivateCallData) { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3062): Why is this using a hash function from the stdlib::recursion namespace let private_call_vk_hash = stdlib_recursion_verification_key_compress_native_vk(private_call.vk); - assert(!is_default(contract_address), "contract address cannot be default (zero)"); + assert(!is_zero(contract_address), "Contract address cannot be zero"); // std::println(f"contract_address={contract_address}"); // std::println(f"private_call_vk_hash={private_call_vk_hash}"); 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 b48e1a036bf..5ed50c3c760 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 @@ -123,13 +123,13 @@ mod tests { } } - #[test(should_fail_with = "contract address cannot be default (zero)")] + #[test(should_fail_with = "Contract address cannot be zero")] fn private_function_zero_storage_contract_address_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new(); // Set (storage) contract_address to 0 - builder.private_call.contract_address = AztecAddress::default(); - builder.private_call.public_inputs.call_context.storage_contract_address = AztecAddress::default(); + builder.private_call.contract_address = AztecAddress::zero(); + builder.private_call.public_inputs.call_context.storage_contract_address = AztecAddress::zero(); builder.failed(); } 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 2dc19de3488..4cc42181554 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 @@ -9,7 +9,7 @@ use dep::types::{ MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX }, - grumpkin_private_key::GrumpkinPrivateKey, utils::arrays::array_length, traits::is_default + grumpkin_private_key::GrumpkinPrivateKey, utils::arrays::array_length }; struct PrivateKernelTailCircuitPrivateInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index c171c25f126..38e1425de57 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -15,7 +15,7 @@ use dep::types::{ MAX_PUBLIC_DATA_READS_PER_CALL }, hash::{silo_note_hash, silo_nullifier, compute_l2_to_l1_hash, accumulate_sha256}, - utils::{arrays::{array_length, array_to_bounded_vec}}, traits::is_default + utils::{arrays::{array_length, array_to_bounded_vec}}, traits::{is_default,is_zero} }; use crate::hash::{compute_public_data_tree_index, compute_public_data_tree_value}; @@ -23,9 +23,7 @@ use crate::hash::{compute_public_data_tree_index, compute_public_data_tree_value pub fn validate_inputs(public_call: PublicCallData) { // Validates commons inputs for all type of kernel inputs let this_call_stack_item: PublicCallStackItem = public_call.call_stack_item; - assert( - !this_call_stack_item.contract_address.eq(AztecAddress::default()), "contract address cannot be default (zero)" - ); + assert(!is_zero(this_call_stack_item.contract_address), "Contract address cannot be zero"); assert(this_call_stack_item.function_data.selector.to_field() != 0, "Function signature cannot be zero"); assert( this_call_stack_item.function_data.is_private == false, "Cannot execute a private function with the public kernel circuit" @@ -111,6 +109,8 @@ pub fn initialize_end_values( fn perform_static_call_checks(public_call: PublicCallData) { let public_inputs = public_call.call_stack_item.public_inputs; if public_inputs.call_context.is_static_call { + + // TODO: #5618 // No state changes are allowed for static calls: let new_note_hashes_length = array_length(public_inputs.new_note_hashes); assert(new_note_hashes_length == 0, "new_note_hashes must be a default array (empty) for static calls"); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr index 0aaeaf26ec6..2262f1e2a3b 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr @@ -198,10 +198,10 @@ mod tests { builder.failed(); } - #[test(should_fail_with="contract address cannot be default (zero)")] + #[test(should_fail_with="Contract address cannot be zero")] fn contract_address_must_be_valid() { let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - builder.public_call.contract_address = AztecAddress::default(); + builder.public_call.contract_address = AztecAddress::zero(); builder.failed(); } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr index ef88cbb0af5..75e92d64607 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr @@ -147,10 +147,10 @@ mod tests { builder.failed(); } - #[test(should_fail_with="contract address cannot be default (zero)")] + #[test(should_fail_with="Contract address cannot be zero")] fn contract_address_must_be_valid() { let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.public_call.contract_address = AztecAddress::default(); + builder.public_call.contract_address = AztecAddress::zero(); builder.failed(); } diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr index 55c1886cbaa..05f18f364f6 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr @@ -170,9 +170,9 @@ mod tests { #[test] fn test_reset_non_existent_read_requests_in_range() { let read_requests = [ - ReadRequestContext { value: 11, counter: 50, contract_address: AztecAddress::default() }, - ReadRequestContext { value: 22, counter: 51, contract_address: AztecAddress::default() }, - ReadRequestContext { value: 6, counter: 52, contract_address: AztecAddress::default() } + ReadRequestContext { value: 11, counter: 50, contract_address: AztecAddress::zero() }, + ReadRequestContext { value: 22, counter: 51, contract_address: AztecAddress::zero() }, + ReadRequestContext { value: 6, counter: 52, contract_address: AztecAddress::zero() } ]; let (non_membership_hints, root) = get_non_membership_hints([3, 1, 0]); let next_pending_value_indices = [1, 2, 1]; @@ -188,8 +188,8 @@ mod tests { #[test] fn test_reset_non_existent_read_requests_less_than_min() { let read_requests = [ - ReadRequestContext { value: 3, counter: 50, contract_address: AztecAddress::default() }, - ReadRequestContext { value: 2, counter: 51, contract_address: AztecAddress::default() } + ReadRequestContext { value: 3, counter: 50, contract_address: AztecAddress::zero() }, + ReadRequestContext { value: 2, counter: 51, contract_address: AztecAddress::zero() } ]; let (non_membership_hints, root) = get_non_membership_hints([0, 0]); let next_pending_value_indices = [0, 0]; @@ -205,8 +205,8 @@ mod tests { #[test] fn test_reset_non_existent_read_requests_greater_than_max() { let read_requests = [ - ReadRequestContext { value: 35, counter: 50, contract_address: AztecAddress::default() }, - ReadRequestContext { value: 31, counter: 51, contract_address: AztecAddress::default() } + ReadRequestContext { value: 35, counter: 50, contract_address: AztecAddress::zero() }, + ReadRequestContext { value: 31, counter: 51, contract_address: AztecAddress::zero() } ]; let (non_membership_hints, root) = get_non_membership_hints([2, 2]); let next_pending_value_indices = [3, 3]; @@ -222,8 +222,8 @@ mod tests { #[test] fn test_reset_non_existent_read_requests_read_before_pending_emitted() { let read_requests = [ - ReadRequestContext { value: 25, counter: 10, contract_address: AztecAddress::default() }, - ReadRequestContext { value: 5, counter: 11, contract_address: AztecAddress::default() } + ReadRequestContext { value: 25, counter: 10, contract_address: AztecAddress::zero() }, + ReadRequestContext { value: 5, counter: 11, contract_address: AztecAddress::zero() } ]; let (non_membership_hints, root) = get_non_membership_hints([1, 0]); let next_pending_value_indices = [2, 0]; @@ -238,7 +238,7 @@ mod tests { #[test(should_fail_with="Cannot check non membership against empty leaf")] fn test_reset_non_existent_read_requests_empty_leaf_failed() { - let read_requests = [ReadRequestContext { value: 10, counter: 50, contract_address: AztecAddress::default() }]; + let read_requests = [ReadRequestContext { value: 10, counter: 50, contract_address: AztecAddress::zero() }]; let (non_membership_hints, root) = get_non_membership_hints([0]); let mut hint = non_membership_hints[0]; hint.low_leaf_preimage = TestLeafPreimage { value: 0, next_value: 0 }; @@ -254,7 +254,7 @@ mod tests { #[test(should_fail_with="Low leaf does not exist")] fn test_reset_non_existent_read_requests_invalid_preimage_failed() { - let read_requests = [ReadRequestContext { value: 10, counter: 50, contract_address: AztecAddress::default() }]; + let read_requests = [ReadRequestContext { value: 10, counter: 50, contract_address: AztecAddress::zero() }]; let (non_membership_hints, root) = get_non_membership_hints([3]); let mut hint = non_membership_hints[0]; hint.low_leaf_preimage = TestLeafPreimage { value: 9, next_value: 20 }; @@ -270,7 +270,7 @@ mod tests { #[test(should_fail_with="Key is not greater than the low leaf")] fn test_reset_non_existent_read_requests_read_settled_failed() { - let read_requests = [ReadRequestContext { value: 10, counter: 50, contract_address: AztecAddress::default() }]; + let read_requests = [ReadRequestContext { value: 10, counter: 50, contract_address: AztecAddress::zero() }]; let (non_membership_hints, root) = get_non_membership_hints([3]); let next_pending_value_indices = [1]; reset_non_existent_read_requests( @@ -284,7 +284,7 @@ mod tests { #[test(should_fail_with="Key is not less than the next leaf")] fn test_reset_non_existent_read_requests_invalid_non_membership_hint_failed() { - let read_requests = [ReadRequestContext { value: 10, counter: 50, contract_address: AztecAddress::default() }]; + let read_requests = [ReadRequestContext { value: 10, counter: 50, contract_address: AztecAddress::zero() }]; let (non_membership_hints, root) = get_non_membership_hints([0]); let next_pending_value_indices = [1]; reset_non_existent_read_requests( @@ -298,7 +298,7 @@ mod tests { #[test(should_fail_with="Value exists in pending set")] fn test_reset_non_existent_read_requests_read_pending_value_failed() { - let read_requests = [ReadRequestContext { value: 25, counter: 50, contract_address: AztecAddress::default() }]; + let read_requests = [ReadRequestContext { value: 25, counter: 50, contract_address: AztecAddress::zero() }]; let (non_membership_hints, root) = get_non_membership_hints([1]); let next_pending_value_indices = [2]; reset_non_existent_read_requests( @@ -312,7 +312,7 @@ mod tests { #[test(should_fail_with="Invalid next pending value index")] fn test_reset_non_existent_read_requests_wrong_next_pending_index_failed() { - let read_requests = [ReadRequestContext { value: 21, counter: 50, contract_address: AztecAddress::default() }]; + let read_requests = [ReadRequestContext { value: 21, counter: 50, contract_address: AztecAddress::zero() }]; let (non_membership_hints, root) = get_non_membership_hints([1]); let next_pending_value_indices = [1]; reset_non_existent_read_requests( @@ -326,7 +326,7 @@ mod tests { #[test(should_fail_with="Invalid next pending value index")] fn test_reset_non_existent_read_requests_wrong_max_next_pending_index_failed() { - let read_requests = [ReadRequestContext { value: 21, counter: 50, contract_address: AztecAddress::default() }]; + let read_requests = [ReadRequestContext { value: 21, counter: 50, contract_address: AztecAddress::zero() }]; let (non_membership_hints, root) = get_non_membership_hints([1]); let next_pending_value_indices = [3]; reset_non_existent_read_requests( @@ -340,7 +340,7 @@ mod tests { #[test(should_fail_with="Next pending value index out of bounds")] fn test_reset_non_existent_read_requests_overflown_index_failed() { - let read_requests = [ReadRequestContext { value: 21, counter: 50, contract_address: AztecAddress::default() }]; + let read_requests = [ReadRequestContext { value: 21, counter: 50, contract_address: AztecAddress::zero() }]; let (non_membership_hints, root) = get_non_membership_hints([1]); let next_pending_value_indices = [4]; reset_non_existent_read_requests( diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr index 498fc1e16ca..1f0e1494438 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr @@ -24,7 +24,7 @@ impl Default for CallRequest { fn default() -> Self { CallRequest { hash: 0, - caller_contract_address: AztecAddress::default(), + caller_contract_address: AztecAddress::zero(), caller_context: CallerContext::default(), start_side_effect_counter: 0, end_side_effect_counter: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr index e6f2a9801bd..f6d2a89449d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr @@ -16,8 +16,8 @@ impl Eq for CallerContext { impl Default for CallerContext { fn default() -> Self { CallerContext { - msg_sender: AztecAddress::default(), - storage_contract_address: AztecAddress::default(), + msg_sender: AztecAddress::zero(), + storage_contract_address: AztecAddress::zero(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr index 2a415be8a61..28ff9a93800 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr @@ -60,8 +60,8 @@ impl Default for GlobalVariables { version: 0, block_number: 0, timestamp: 0, - coinbase: EthAddress::default(), - fee_recipient: AztecAddress::default(), + coinbase: EthAddress::zero(), + fee_recipient: AztecAddress::zero(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr index 99699f0dd81..c65055e6574 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr @@ -72,7 +72,7 @@ impl Default for NullifierKeyValidationRequestContext { NullifierKeyValidationRequestContext { public_key: GrumpkinPoint::default(), secret_key: GrumpkinPrivateKey::default(), - contract_address: AztecAddress::default(), + contract_address: AztecAddress::zero(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index 09d1b0c790a..e6f4a8c5fa4 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -76,7 +76,7 @@ impl Default for PublicCircuitPublicInputs { unencrypted_logs_hash: 0, unencrypted_log_preimages_length: 0, historical_header: Header::default(), - prover_address: AztecAddress::default(), + prover_address: AztecAddress::zero(), revert_code: 0 as u8, } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr index 11d8732a88e..ea542725f44 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr @@ -2,7 +2,7 @@ use crate::{ crate::address::{eth_address::EthAddress, partial_address::PartialAddress, public_keys_hash::PublicKeysHash}, constants::{AZTEC_ADDRESS_LENGTH, GENERATOR_INDEX__CONTRACT_ADDRESS}, contract_class_id::ContractClassId, hash::pedersen_hash, grumpkin_point::GrumpkinPoint, - traits::{ToField, Serialize, Deserialize}, utils + traits::{Zero, ToField, Serialize, Deserialize}, utils }; // Aztec address @@ -16,14 +16,22 @@ impl Eq for AztecAddress { } } -impl Default for AztecAddress { - fn default() -> Self { +impl Zero for AztecAddress { + fn zero() -> Self { Self { inner : 0 } } } +// This is implemented so we have one trait for everything "default", or otherwise known as the "undefined" value, +// this helps with things such as the array helper +impl Default for AztecAddress { + fn default() -> Self { + AztecAddress::zero() + } +} + impl ToField for AztecAddress { fn to_field(self) -> Field { self.inner diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr index 57ffb4adda8..343a882af83 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr @@ -1,6 +1,6 @@ use crate::{ constants::ETH_ADDRESS_LENGTH, hash::pedersen_hash, - traits::{ToField, Serialize, Deserialize}, utils + traits::{ToField, Serialize, Deserialize, Zero}, utils }; struct EthAddress{ @@ -13,14 +13,22 @@ impl Eq for EthAddress { } } -impl Default for EthAddress { - fn default() -> Self { +impl Zero for EthAddress { + fn zero() -> Self { Self { inner : 0 } } } +// This is implemented so we have one trait for everything "default", or otherwise known as the "undefined" value, +// this helps with things such as the array helper +impl Default for EthAddress { + fn default() -> Self { + EthAddress::zero() + } +} + impl ToField for EthAddress { fn to_field(self) -> Field { self.inner diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr index 8f74fe07681..d43857aec9d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr @@ -9,7 +9,7 @@ struct L2ToL1Message { impl Default for L2ToL1Message { fn default() -> Self { Self { - recipient: EthAddress::default(), + recipient: EthAddress::zero(), content: 0, } } 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 9a1c99209c5..ff40b269a09 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 @@ -70,8 +70,8 @@ struct FixtureBuilder { impl Default for FixtureBuilder { fn default() -> Self { FixtureBuilder { - contract_address: AztecAddress::default(), - storage_contract_address: AztecAddress::default(), + contract_address: AztecAddress::zero(), + storage_contract_address: AztecAddress::zero(), historical_header: Header::default(), tx_context: TxContext::default(), new_note_hashes: BoundedVec::new(), 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 b55f3b8ba8a..12445f7e7ac 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 @@ -15,37 +15,37 @@ global MSG_SENDER = AztecAddress { inner: 27 }; global PUBLIC_KEY = GrumpkinPoint { x: 123456789, y: 123456789 }; // Workaround for https://github.com/noir-lang/noir/issues/1440 -fn empty_append_only_tree() -> AppendOnlyTreeSnapshot { +fn default_append_only_tree() -> AppendOnlyTreeSnapshot { AppendOnlyTreeSnapshot::default() } // Workaround for https://github.com/noir-lang/noir/issues/1440 -fn empty_eth_address() -> EthAddress { - EthAddress::default() +fn zero_eth_address() -> EthAddress { + EthAddress::zero() } // Workaround for https://github.com/noir-lang/noir/issues/1440 -fn empty_aztec_address() -> AztecAddress { - AztecAddress::default() +fn zero_aztec_address() -> AztecAddress { + AztecAddress::zero() } // Workaround for https://github.com/noir-lang/noir/issues/1440 -fn empty_content_commitment() -> ContentCommitment { +fn default_content_commitment() -> ContentCommitment { ContentCommitment::default() } global HEADER = Header { - last_archive: empty_append_only_tree(), - content_commitment: empty_content_commitment(), + last_archive: default_append_only_tree(), + content_commitment: default_content_commitment(), state: StateReference { - l1_to_l2_message_tree: empty_append_only_tree(), + l1_to_l2_message_tree: default_append_only_tree(), partial: PartialStateReference { note_hash_tree: AppendOnlyTreeSnapshot { root: fixtures::note_hash_tree::ROOT, next_available_leaf_index: 0, // TODO: should this be populated? }, - nullifier_tree: empty_append_only_tree(), - public_data_tree: empty_append_only_tree() + nullifier_tree: default_append_only_tree(), + public_data_tree: default_append_only_tree() } }, global_variables: GlobalVariables { @@ -53,7 +53,7 @@ global HEADER = Header { version: 0, block_number: 0, timestamp: 0, - coinbase: empty_eth_address(), - fee_recipient: empty_aztec_address(), + coinbase: zero_eth_address(), + fee_recipient: zero_aztec_address(), } }; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr index 729bcc2e1c4..022f3f8d5d8 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr @@ -54,7 +54,7 @@ impl Default for PublicCircuitPublicInputsBuilder { unencrypted_logs_hash: 0, unencrypted_log_preimages_length: 0, historical_header: Header::default(), - prover_address: AztecAddress::default(), + prover_address: AztecAddress::zero(), revert_code: 0 as u8, } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr index 96a487ff729..edefcd6624b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr @@ -8,6 +8,14 @@ pub fn is_default_array(array: [T; N]) -> bool where T: Default + Eq { array.all(|elem| is_default(elem)) } +trait Zero { + fn zero() -> Self; +} + +pub fn is_zero(item: T) -> bool where T: Zero + Eq { + item.eq(T::zero()) +} + trait Hash { fn hash(self) -> Field; } diff --git a/yarn-project/archiver/src/archiver/archiver.test.ts b/yarn-project/archiver/src/archiver/archiver.test.ts index f91be81a54a..6657106ef64 100644 --- a/yarn-project/archiver/src/archiver/archiver.test.ts +++ b/yarn-project/archiver/src/archiver/archiver.test.ts @@ -20,10 +20,10 @@ import { type ArchiverDataStore } from './archiver_store.js'; import { MemoryArchiverStore } from './memory_archiver_store/memory_archiver_store.js'; describe('Archiver', () => { - const rollupAddress = EthAddress.default(); - const inboxAddress = EthAddress.default(); - const registryAddress = EthAddress.default(); - const availabilityOracleAddress = EthAddress.default(); + const rollupAddress = EthAddress.ZERO; + const inboxAddress = EthAddress.ZERO; + const registryAddress = EthAddress.ZERO; + const availabilityOracleAddress = EthAddress.ZERO; const blockNumbers = [1, 2, 3]; let publicClient: MockProxy>; let archiverStore: ArchiverDataStore; diff --git a/yarn-project/archiver/src/archiver/config.ts b/yarn-project/archiver/src/archiver/config.ts index 0ac7c447b53..fe1fb79e848 100644 --- a/yarn-project/archiver/src/archiver/config.ts +++ b/yarn-project/archiver/src/archiver/config.ts @@ -70,15 +70,15 @@ export function getConfigEnvVars(): ArchiverConfig { const addresses: L1ContractAddresses = { availabilityOracleAddress: AVAILABILITY_ORACLE_CONTRACT_ADDRESS ? EthAddress.fromString(AVAILABILITY_ORACLE_CONTRACT_ADDRESS) - : EthAddress.default(), - rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.default(), - registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.default(), - inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.default(), - outboxAddress: OUTBOX_CONTRACT_ADDRESS ? EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS) : EthAddress.default(), - gasTokenAddress: GAS_TOKEN_CONTRACT_ADDRESS ? EthAddress.fromString(GAS_TOKEN_CONTRACT_ADDRESS) : EthAddress.default(), + : EthAddress.ZERO, + rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, + registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO, + inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, + outboxAddress: OUTBOX_CONTRACT_ADDRESS ? EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, + gasTokenAddress: GAS_TOKEN_CONTRACT_ADDRESS ? EthAddress.fromString(GAS_TOKEN_CONTRACT_ADDRESS) : EthAddress.ZERO, gasPortalAddress: GAS_PORTAL_CONTRACT_ADDRESS ? EthAddress.fromString(GAS_PORTAL_CONTRACT_ADDRESS) - : EthAddress.default(), + : EthAddress.ZERO, }; return { rpcUrl: ETHEREUM_HOST || 'http://127.0.0.1:8545/', diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index c0df7200154..e00c0b93f14 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -644,8 +644,8 @@ export class AztecNodeService implements AztecNode { const blockNumber = (await this.blockSource.getBlockNumber()) + 1; // If sequencer is not initialized, we just set these values to zero for simulation. - const coinbase = this.sequencer?.coinbase || EthAddress.default(); - const feeRecipient = this.sequencer?.feeRecipient || AztecAddress.default(); + const coinbase = this.sequencer?.coinbase || EthAddress.ZERO; + const feeRecipient = this.sequencer?.feeRecipient || AztecAddress.ZERO; const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables( new Fr(blockNumber), diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index f7f6673dc7f..795226cff01 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -190,7 +190,7 @@ export class DeployMethod extends Bas portalAddress: options.portalContract, publicKey: this.publicKey, constructorArtifact: this.constructorArtifact, - deployer: options.universalDeploy ? AztecAddress.default() : this.wallet.getAddress(), + deployer: options.universalDeploy ? AztecAddress.ZERO : this.wallet.getAddress(), }); } return this.instance; diff --git a/yarn-project/aztec.js/src/deployment/deploy_instance.ts b/yarn-project/aztec.js/src/deployment/deploy_instance.ts index c6408940b82..c6ff64a9992 100644 --- a/yarn-project/aztec.js/src/deployment/deploy_instance.ts +++ b/yarn-project/aztec.js/src/deployment/deploy_instance.ts @@ -12,7 +12,7 @@ import { getDeployerContract } from './protocol_contracts.js'; export function deployInstance(wallet: Wallet, instance: ContractInstanceWithAddress): ContractFunctionInteraction { const deployerContract = getDeployerContract(wallet); const { salt, contractClassId, portalContractAddress, publicKeysHash, deployer } = instance; - const isUniversalDeploy = deployer.isDefault(); + const isUniversalDeploy = deployer.isZero(); if (!isUniversalDeploy && !wallet.getAddress().equals(deployer)) { throw new Error( `Expected deployer ${deployer.toString()} does not match sender wallet ${wallet.getAddress().toString()}`, diff --git a/yarn-project/aztec/src/cli/util.ts b/yarn-project/aztec/src/cli/util.ts index 9b07da51e82..21e79359da2 100644 --- a/yarn-project/aztec/src/cli/util.ts +++ b/yarn-project/aztec/src/cli/util.ts @@ -27,7 +27,7 @@ function hasL1Contracts(obj: any): obj is { const checkContractAddresses = (contracts: L1ContractAddresses) => { return l1ContractsNames.every(cn => { const key = cn as keyof L1ContractAddresses; - return contracts[key] && contracts[key] !== EthAddress.default(); + return contracts[key] && contracts[key] !== EthAddress.ZERO; }); }; diff --git a/yarn-project/circuit-types/src/function_call.ts b/yarn-project/circuit-types/src/function_call.ts index f10d2625380..6c6e2b349fb 100644 --- a/yarn-project/circuit-types/src/function_call.ts +++ b/yarn-project/circuit-types/src/function_call.ts @@ -16,7 +16,7 @@ export type FunctionCall = { */ export function emptyFunctionCall() { return { - to: AztecAddress.default(), + to: AztecAddress.ZERO, functionData: FunctionData.default(), args: [], }; diff --git a/yarn-project/circuit-types/src/messaging/l1_actor.ts b/yarn-project/circuit-types/src/messaging/l1_actor.ts index f9652150abb..c07b957cff4 100644 --- a/yarn-project/circuit-types/src/messaging/l1_actor.ts +++ b/yarn-project/circuit-types/src/messaging/l1_actor.ts @@ -19,7 +19,7 @@ export class L1Actor { ) {} static default() { - return new L1Actor(EthAddress.default(), 0); + return new L1Actor(EthAddress.ZERO, 0); } toFields(): Fr[] { diff --git a/yarn-project/circuit-types/src/messaging/l2_actor.ts b/yarn-project/circuit-types/src/messaging/l2_actor.ts index 5dbf0753404..020f7a87fb8 100644 --- a/yarn-project/circuit-types/src/messaging/l2_actor.ts +++ b/yarn-project/circuit-types/src/messaging/l2_actor.ts @@ -19,7 +19,7 @@ export class L2Actor { ) {} static default() { - return new L2Actor(AztecAddress.default(), 0); + return new L2Actor(AztecAddress.ZERO, 0); } toFields(): Fr[] { diff --git a/yarn-project/circuits.js/src/contract/contract_instance.ts b/yarn-project/circuits.js/src/contract/contract_instance.ts index 269e79810b2..b3db3ee9dd2 100644 --- a/yarn-project/circuits.js/src/contract/contract_instance.ts +++ b/yarn-project/circuits.js/src/contract/contract_instance.ts @@ -33,9 +33,9 @@ export function getContractInstanceFromDeployParams( const args = opts.constructorArgs ?? []; const salt = opts.salt ?? Fr.random(); const publicKey = opts.publicKey ?? Point.default(); - const portalContractAddress = opts.portalAddress ?? EthAddress.default(); + const portalContractAddress = opts.portalAddress ?? EthAddress.ZERO; const constructorArtifact = getConstructorArtifact(artifact, opts.constructorArtifact); - const deployer = opts.deployer ?? AztecAddress.default(); + const deployer = opts.deployer ?? AztecAddress.ZERO; const contractClass = getContractClassFromArtifact(artifact); const contractClassId = computeContractClassId(contractClass); diff --git a/yarn-project/circuits.js/src/contract/events/unconstrained_function_broadcasted_event.ts b/yarn-project/circuits.js/src/contract/events/unconstrained_function_broadcasted_event.ts index 7fb8c98dc9b..32556036e77 100644 --- a/yarn-project/circuits.js/src/contract/events/unconstrained_function_broadcasted_event.ts +++ b/yarn-project/circuits.js/src/contract/events/unconstrained_function_broadcasted_event.ts @@ -90,7 +90,7 @@ export class UnconstrainedFunctionBroadcastedEvent { // since a sibling with value zero can only occur on the tree leaves, so the sibling path will never end // in a zero. The only exception is a tree with depth 2 with one non-zero leaf, where the sibling path would // be a single zero element, but in that case the artifact tree should be just the single leaf. - const artifactTreeSiblingPath = removeArrayPaddingEnd(this.artifactFunctionTreeSiblingPath, Fr.isDefault); + const artifactTreeSiblingPath = removeArrayPaddingEnd(this.artifactFunctionTreeSiblingPath, Fr.isZero); return { ...this.unconstrainedFunction, bytecode: this.unconstrainedFunction.bytecode, diff --git a/yarn-project/circuits.js/src/structs/call_context.ts b/yarn-project/circuits.js/src/structs/call_context.ts index ace2135809d..34e72a0542d 100644 --- a/yarn-project/circuits.js/src/structs/call_context.ts +++ b/yarn-project/circuits.js/src/structs/call_context.ts @@ -50,9 +50,9 @@ export class CallContext { */ public static default(): CallContext { return new CallContext( - AztecAddress.default(), - AztecAddress.default(), - EthAddress.default(), + AztecAddress.ZERO, + AztecAddress.ZERO, + EthAddress.ZERO, FunctionSelector.default(), false, false, @@ -62,9 +62,9 @@ export class CallContext { isDefault() { return ( - this.msgSender.isDefault() && - this.storageContractAddress.isDefault() && - this.portalContractAddress.isDefault() && + this.msgSender.isZero() && + this.storageContractAddress.isZero() && + this.portalContractAddress.isZero() && this.functionSelector.isDefault() && Fr.ZERO ); @@ -136,14 +136,6 @@ export class CallContext { } equals(callContext: CallContext) { - return ( - callContext.msgSender.equals(this.msgSender) && - callContext.storageContractAddress.equals(this.storageContractAddress) && - callContext.portalContractAddress.equals(this.portalContractAddress) && - callContext.functionSelector.equals(this.functionSelector) && - callContext.isDelegateCall === this.isDelegateCall && - callContext.isStaticCall === this.isStaticCall && - callContext.sideEffectCounter === this.sideEffectCounter - ); + return callContext.toBuffer().equals(this.toBuffer()); } } diff --git a/yarn-project/circuits.js/src/structs/call_request.ts b/yarn-project/circuits.js/src/structs/call_request.ts index f6b44ed0152..2a497584736 100644 --- a/yarn-project/circuits.js/src/structs/call_request.ts +++ b/yarn-project/circuits.js/src/structs/call_request.ts @@ -23,11 +23,11 @@ export class CallerContext { * @returns A new instance of CallerContext with default values. */ public static default(): CallerContext { - return new CallerContext(AztecAddress.default(), AztecAddress.default()); + return new CallerContext(AztecAddress.ZERO, AztecAddress.ZERO); } isDefault() { - return this.msgSender.isDefault() && this.storageContractAddress.isDefault(); + return this.msgSender.isZero() && this.storageContractAddress.isZero(); } static from(fields: FieldsOf): CallerContext { @@ -120,7 +120,7 @@ export class CallRequest { isDefault() { return ( this.hash.isZero() && - this.callerContractAddress.isDefault() && + this.callerContractAddress.isZero() && this.callerContext.isDefault() && this.startSideEffectCounter.isZero() && this.endSideEffectCounter.isZero() @@ -132,7 +132,7 @@ export class CallRequest { * @returns A new instance of CallRequest with zero hash, caller contract address and caller context. */ public static default() { - return new CallRequest(Fr.ZERO, AztecAddress.default(), CallerContext.default(), Fr.ZERO, Fr.ZERO); + return new CallRequest(Fr.ZERO, AztecAddress.ZERO, CallerContext.default(), Fr.ZERO, Fr.ZERO); } equals(callRequest: CallRequest) { diff --git a/yarn-project/circuits.js/src/structs/global_variables.ts b/yarn-project/circuits.js/src/structs/global_variables.ts index a0321124d6b..4f73cf19b72 100644 --- a/yarn-project/circuits.js/src/structs/global_variables.ts +++ b/yarn-project/circuits.js/src/structs/global_variables.ts @@ -30,7 +30,7 @@ export class GlobalVariables { } static default(): GlobalVariables { - return new GlobalVariables(Fr.ZERO, Fr.ZERO, Fr.ZERO, Fr.ZERO, EthAddress.default(), AztecAddress.default()); + return new GlobalVariables(Fr.ZERO, Fr.ZERO, Fr.ZERO, Fr.ZERO, EthAddress.ZERO, AztecAddress.ZERO); } static fromBuffer(buffer: Buffer | BufferReader): GlobalVariables { @@ -112,8 +112,8 @@ export class GlobalVariables { this.version.isZero() && this.blockNumber.isZero() && this.timestamp.isZero() && - this.coinbase.isDefault() && - this.feeRecipient.isDefault() + this.coinbase.isZero() && + this.feeRecipient.isZero() ); } } diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts index 07a97f1497c..ee3855ba59d 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts @@ -102,7 +102,7 @@ export class CombinedAccumulatedData { return new CombinedAccumulatedData( makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.default), makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), - makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.default), + makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), Fr.ZERO, Fr.ZERO, Fr.ZERO, diff --git a/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts b/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts index ea668e0e88c..629d0d13f30 100644 --- a/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/kernel_data.ts @@ -38,7 +38,7 @@ export class KernelData { makeEmptyProof(), VerificationKey.makeFake(), 0, - makeTuple(VK_TREE_HEIGHT, Fr.default), + makeTuple(VK_TREE_HEIGHT, Fr.zero), ); } diff --git a/yarn-project/circuits.js/src/structs/kernel/private_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_accumulated_data.ts index c07e4b87339..1f45b049315 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_accumulated_data.ts @@ -111,7 +111,7 @@ export class PrivateAccumulatedData { return new PrivateAccumulatedData( makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.default), makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), - makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.default), + makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), Fr.ZERO, Fr.ZERO, Fr.ZERO, diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_data.ts index 32020d3d1d7..795c4b82030 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_data.ts @@ -60,7 +60,7 @@ export class PrivateKernelData { makeEmptyProof(), VerificationKey.makeFake(), 0, - makeTuple(VK_TREE_HEIGHT, Fr.default), + makeTuple(VK_TREE_HEIGHT, Fr.zero), ); } } diff --git a/yarn-project/circuits.js/src/structs/kernel/public_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/public_accumulated_data.ts index 20e19016204..bcf8907867c 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_accumulated_data.ts @@ -138,7 +138,7 @@ export class PublicAccumulatedData { return new this( makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, SideEffect.default), makeTuple(MAX_NEW_NULLIFIERS_PER_TX, SideEffectLinkedToNoteHash.default), - makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.default), + makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_TX, Fr.zero), Fr.ZERO, Fr.ZERO, Fr.ZERO, diff --git a/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts b/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts index 37b5295fec4..fe6c3b3e694 100644 --- a/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/public_kernel_data.ts @@ -52,7 +52,7 @@ export class PublicKernelData { makeEmptyProof(), VerificationKey.makeFake(), 0, - makeTuple(VK_TREE_HEIGHT, Fr.default), + makeTuple(VK_TREE_HEIGHT, Fr.zero), ); } diff --git a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts index 19953cd26ee..23e00899451 100644 --- a/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts +++ b/yarn-project/circuits.js/src/structs/l2_to_l1_message.ts @@ -9,10 +9,10 @@ export class L2ToL1Message { /** * Creates a default L2ToL1Message with default values. - * @returns An instance of L2ToL1Message with default fields. + * @returns An instance of L2ToL1Message with default (zero) fields. */ static default(): L2ToL1Message { - return new L2ToL1Message(EthAddress.default(), Fr.ZERO); + return new L2ToL1Message(EthAddress.ZERO, Fr.ZERO); } /** @@ -68,9 +68,9 @@ export class L2ToL1Message { /** * Convenience method to check if the message is default. - * @returns True if recipient is default and content is zero. + * @returns True if both recipient and content are zero. */ isDefault(): boolean { - return this.recipient.isDefault() && this.content.isDefault(); + return this.recipient.isZero() && this.content.isZero(); } } diff --git a/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts b/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts index bb7cc61c645..203f3f8ae8b 100644 --- a/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts +++ b/yarn-project/circuits.js/src/structs/nullifier_key_validation_request.ts @@ -108,10 +108,10 @@ export class NullifierKeyValidationRequestContext { } isDefault() { - return this.publicKey.isDefault() && this.secretKey.isZero() && this.contractAddress.isDefault(); + return this.publicKey.isDefault() && this.secretKey.isZero() && this.contractAddress.isZero(); } static default() { - return new NullifierKeyValidationRequestContext(Point.default(), GrumpkinScalar.ZERO, AztecAddress.default()); + return new NullifierKeyValidationRequestContext(Point.default(), GrumpkinScalar.ZERO, AztecAddress.ZERO); } } diff --git a/yarn-project/circuits.js/src/structs/private_call_stack_item.ts b/yarn-project/circuits.js/src/structs/private_call_stack_item.ts index aa0600a18ca..18f14dcafe1 100644 --- a/yarn-project/circuits.js/src/structs/private_call_stack_item.ts +++ b/yarn-project/circuits.js/src/structs/private_call_stack_item.ts @@ -76,14 +76,14 @@ export class PrivateCallStackItem { */ public static default(): PrivateCallStackItem { return new PrivateCallStackItem( - AztecAddress.default(), + AztecAddress.ZERO, FunctionData.default({ isPrivate: true }), PrivateCircuitPublicInputs.default(), ); } isDefault() { - return this.contractAddress.isDefault() && this.functionData.isDefault(true) && this.publicInputs.isDefault(); + return this.contractAddress.isZero() && this.functionData.isDefault(true) && this.publicInputs.isDefault(); } /** diff --git a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts index 0e5a495c833..679a576967e 100644 --- a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts @@ -217,7 +217,7 @@ export class PrivateCircuitPublicInputs { return new PrivateCircuitPublicInputs( CallContext.default(), Fr.ZERO, - makeTuple(RETURN_VALUES_LENGTH, Fr.default), + makeTuple(RETURN_VALUES_LENGTH, Fr.zero), Fr.ZERO, MaxBlockNumber.default(), makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, SideEffect.default), @@ -225,8 +225,8 @@ export class PrivateCircuitPublicInputs { makeTuple(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, NullifierKeyValidationRequest.default), makeTuple(MAX_NEW_NOTE_HASHES_PER_CALL, SideEffect.default), makeTuple(MAX_NEW_NULLIFIERS_PER_CALL, SideEffectLinkedToNoteHash.default), - makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, Fr.default), - makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, Fr.default), + makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, Fr.zero), + makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, Fr.zero), makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, L2ToL1Message.default), Fr.ZERO, Fr.ZERO, diff --git a/yarn-project/circuits.js/src/structs/public_call_stack_item.ts b/yarn-project/circuits.js/src/structs/public_call_stack_item.ts index 247afc7011c..847370b2b18 100644 --- a/yarn-project/circuits.js/src/structs/public_call_stack_item.ts +++ b/yarn-project/circuits.js/src/structs/public_call_stack_item.ts @@ -68,12 +68,12 @@ export class PublicCallStackItem { } /** - * Returns a new instance of PublicCallStackItem with default contract address, function data and public inputs. - * @returns A new instance of PublicCallStackItem with default contract address, function data and public inputs. + * Returns a new instance of PublicCallStackItem with zero contract address, function data and public inputs. + * @returns A new instance of PublicCallStackItem with zero contract address, function data and public inputs. */ public static default(): PublicCallStackItem { return new PublicCallStackItem( - AztecAddress.default(), + AztecAddress.ZERO, FunctionData.default({ isPrivate: false }), PublicCircuitPublicInputs.default(), false, @@ -81,7 +81,7 @@ export class PublicCallStackItem { } isDefault() { - return this.contractAddress.isDefault() && this.functionData.isDefault(false) && this.publicInputs.isDefault(); + return this.contractAddress.isZero() && this.functionData.isDefault(false) && this.publicInputs.isDefault(); } /** diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts index 09778c5c7c8..11a3ab8eb47 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts @@ -139,12 +139,12 @@ export class PublicCircuitPublicInputs { return new PublicCircuitPublicInputs( CallContext.default(), Fr.ZERO, - makeTuple(RETURN_VALUES_LENGTH, Fr.default), + makeTuple(RETURN_VALUES_LENGTH, Fr.zero), makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, ReadRequest.default), makeTuple(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, ReadRequest.default), makeTuple(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, ContractStorageUpdateRequest.default), makeTuple(MAX_PUBLIC_DATA_READS_PER_CALL, ContractStorageRead.default), - makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, Fr.default), + makeTuple(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, Fr.zero), makeTuple(MAX_NEW_NOTE_HASHES_PER_CALL, SideEffect.default), makeTuple(MAX_NEW_NULLIFIERS_PER_CALL, SideEffectLinkedToNoteHash.default), makeTuple(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, L2ToL1Message.default), @@ -153,7 +153,7 @@ export class PublicCircuitPublicInputs { Fr.ZERO, Fr.ZERO, Header.default(), - AztecAddress.default(), + AztecAddress.ZERO, RevertCode.OK, ); } diff --git a/yarn-project/circuits.js/src/structs/read_request.ts b/yarn-project/circuits.js/src/structs/read_request.ts index c46b7f32957..9426b56d0a7 100644 --- a/yarn-project/circuits.js/src/structs/read_request.ts +++ b/yarn-project/circuits.js/src/structs/read_request.ts @@ -125,6 +125,6 @@ export class ReadRequestContext { * @returns Side-effect with value, note hash and counter being zero. */ static default(): ReadRequestContext { - return new ReadRequestContext(Fr.ZERO, 0, AztecAddress.default()); + return new ReadRequestContext(Fr.ZERO, 0, AztecAddress.ZERO); } } diff --git a/yarn-project/circuits.js/src/structs/tx_request.ts b/yarn-project/circuits.js/src/structs/tx_request.ts index 46cdb202267..27736d5db75 100644 --- a/yarn-project/circuits.js/src/structs/tx_request.ts +++ b/yarn-project/circuits.js/src/structs/tx_request.ts @@ -75,10 +75,10 @@ export class TxRequest { } static default() { - return new TxRequest(AztecAddress.default(), FunctionData.default(), Fr.ZERO, TxContext.default()); + return new TxRequest(AztecAddress.ZERO, FunctionData.default(), Fr.ZERO, TxContext.default()); } isDefault() { - return this.origin.isDefault() && (this.functionData.isDefault(true) || this.functionData.isDefault(false)) && this.argsHash.isZero() && this.txContext.isDefault(); + return this.origin.isZero() && (this.functionData.isDefault(true) || this.functionData.isDefault(false)) && this.argsHash.isZero() && this.txContext.isDefault(); } } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 3727f167049..2274f8b31e0 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -294,7 +294,7 @@ export function makeCombinedAccumulatedData(seed = 1, full = false): CombinedAcc seed + 0x200, SideEffectLinkedToNoteHash.default, ), - tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.default), + tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.zero), fr(seed + 0x700), // encrypted logs hash fr(seed + 0x800), // unencrypted logs hash fr(seed + 0x900), // encrypted_log_preimages_length @@ -324,7 +324,7 @@ export function makePublicAccumulatedData(seed = 1, full = false): PublicAccumul seed + 0x200, SideEffectLinkedToNoteHash.default, ), - tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.default), + tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.zero), fr(seed + 0x700), // encrypted logs hash fr(seed + 0x800), // unencrypted logs hash fr(seed + 0x900), // encrypted_log_preimages_length @@ -355,7 +355,7 @@ export function makePrivateAccumulatedData(seed = 1, full = false) { seed + 0x200, SideEffectLinkedToNoteHash.default, ), - tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.default), + tupleGenerator(MAX_NEW_L2_TO_L1_MSGS_PER_TX, fr, seed + 0x600, Fr.zero), fr(seed + 0x700), // encrypted logs hash fr(seed + 0x800), // unencrypted logs hash fr(seed + 0x900), // encrypted_log_preimages_length @@ -413,7 +413,7 @@ export function makePublicCircuitPublicInputs( return new PublicCircuitPublicInputs( makeCallContext(seed, storageContractAddress), fr(seed + 0x100), - tupleGenerator(RETURN_VALUES_LENGTH, fr, seed + 0x200, Fr.default), + tupleGenerator(RETURN_VALUES_LENGTH, fr, seed + 0x200, Fr.zero), tupleGenerator(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x400, ReadRequest.default), tupleGenerator(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x420, ReadRequest.default), tupleGenerator( @@ -423,7 +423,7 @@ export function makePublicCircuitPublicInputs( ContractStorageUpdateRequest.default, ), tupleGenerator(MAX_PUBLIC_DATA_READS_PER_CALL, makeContractStorageRead, seed + 0x500, ContractStorageRead.default), - tupleGenerator(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, fr, seed + 0x600, Fr.default), + tupleGenerator(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, fr, seed + 0x600, Fr.zero), tupleGenerator(MAX_NEW_NOTE_HASHES_PER_CALL, makeNewSideEffect, seed + 0x700, SideEffect.default), tupleGenerator( MAX_NEW_NULLIFIERS_PER_CALL, @@ -589,7 +589,7 @@ export function makeNoteHashReadRequestMembershipWitness(start: number): NoteHas export function makeDefaultNoteHashReadRequestMembershipWitness(): NoteHashReadRequestMembershipWitness { return new NoteHashReadRequestMembershipWitness( new Fr(0), - makeTuple(NOTE_HASH_TREE_HEIGHT, Fr.default), + makeTuple(NOTE_HASH_TREE_HEIGHT, Fr.zero), false, new Fr(0), ); diff --git a/yarn-project/cli/src/cmds/add_contract.ts b/yarn-project/cli/src/cmds/add_contract.ts index 2bc3099e5f0..c77283083c8 100644 --- a/yarn-project/cli/src/cmds/add_contract.ts +++ b/yarn-project/cli/src/cmds/add_contract.ts @@ -30,10 +30,10 @@ export async function addContract( salt, initializationHash, contractClassId: getContractClassFromArtifact(artifact).id, - portalContractAddress: portalContract ?? EthAddress.default(), + portalContractAddress: portalContract ?? EthAddress.ZERO, publicKeysHash: computePublicKeysHash(publicKey), address, - deployer: deployer ?? AztecAddress.default(), + deployer: deployer ?? AztecAddress.ZERO, }; const computed = computeContractAddressFromInstance(instance); if (!computed.equals(address)) { diff --git a/yarn-project/end-to-end/src/e2e_card_game.test.ts b/yarn-project/end-to-end/src/e2e_card_game.test.ts index 982384fccac..e92f0988880 100644 --- a/yarn-project/end-to-end/src/e2e_card_game.test.ts +++ b/yarn-project/end-to-end/src/e2e_card_game.test.ts @@ -186,7 +186,7 @@ describe('e2e_card_game', () => { points: 0n, }, { - address: AztecAddress.default(), + address: AztecAddress.ZERO, deck_strength: 0n, points: 0n, }, diff --git a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts index 4735de6e7d2..20905605d68 100644 --- a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts +++ b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts @@ -89,7 +89,7 @@ describe('e2e_cheat_codes', () => { it('load a value at a particular storage slot', async () => { // check that storage slot 0 is empty as expected - const res = await cc.eth.load(EthAddress.default(), 0n); + const res = await cc.eth.load(EthAddress.ZERO, 0n); expect(res).toBe(0n); }); diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts index fbef7687358..e6f45ed8df5 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts @@ -209,7 +209,7 @@ describe('e2e_cross_chain_messaging', () => { await expect( l2Bridge .withWallet(user1Wallet) - .methods.exit_to_l1_private(l2Token.address, ethAccount, withdrawAmount, EthAddress.default(), nonce) + .methods.exit_to_l1_private(l2Token.address, ethAccount, withdrawAmount, EthAddress.ZERO, nonce) .prove(), ).rejects.toThrow(`Unknown auth witness for message hash ${expectedBurnMessageHash.toString()}`); }, 120_000); diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts index 68b22473f6b..6e22ae60296 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts @@ -126,7 +126,7 @@ describe('e2e_deploy_contract', () => { const artifact = TokenContractArtifact; const initArgs = ['TokenName', 'TKN', 18] as const; const goodDeploy = StatefulTestContract.deploy(wallet, wallet.getAddress(), 42); - const badDeploy = new ContractDeployer(artifact, wallet).deploy(AztecAddress.default(), ...initArgs); + const badDeploy = new ContractDeployer(artifact, wallet).deploy(AztecAddress.ZERO, ...initArgs); const firstOpts = { skipPublicSimulation: true, skipClassRegistration: true, skipInstanceDeploy: true }; const secondOpts = { skipPublicSimulation: true }; diff --git a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts index 02f25e3cb60..1031824eaff 100644 --- a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts @@ -184,7 +184,7 @@ describe('e2e_public_cross_chain_messaging', () => { await expect( l2Bridge .withWallet(user1Wallet) - .methods.exit_to_l1_public(ethAccount, withdrawAmount, EthAddress.default(), nonce) + .methods.exit_to_l1_public(ethAccount, withdrawAmount, EthAddress.ZERO, nonce) .prove(), ).rejects.toThrow('Assertion failed: Message not authorized by account'); }, 60_000); diff --git a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts index 149c9fd0ac1..0f96b58c3fb 100644 --- a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts @@ -483,7 +483,7 @@ describe('L1Publisher integration', () => { const block = (result as ProvingSuccess).block; prevHeader = block.header; - writeJson(`empty_block_${i}`, block, [], AztecAddress.default(), deployerAccount.address); + writeJson(`empty_block_${i}`, block, [], AztecAddress.ZERO, deployerAccount.address); await publisher.processL2Block(block); diff --git a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts index d9c1474d277..78bfdb7ee73 100644 --- a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts @@ -327,7 +327,7 @@ export class CrossChainTestHarness { async withdrawPrivateFromAztecToL1(withdrawAmount: bigint, nonce: Fr = Fr.ZERO): Promise> { const withdrawReceipt = await this.l2Bridge.methods - .exit_to_l1_private(this.l2Token.address, this.ethAccount, withdrawAmount, EthAddress.default(), nonce) + .exit_to_l1_private(this.l2Token.address, this.ethAccount, withdrawAmount, EthAddress.ZERO, nonce) .send() .wait(); @@ -336,7 +336,7 @@ export class CrossChainTestHarness { async withdrawPublicFromAztecToL1(withdrawAmount: bigint, nonce: Fr = Fr.ZERO): Promise> { const withdrawReceipt = await this.l2Bridge.methods - .exit_to_l1_public(this.ethAccount, withdrawAmount, EthAddress.default(), nonce) + .exit_to_l1_public(this.ethAccount, withdrawAmount, EthAddress.ZERO, nonce) .send() .wait(); @@ -362,7 +362,7 @@ export class CrossChainTestHarness { expect(balance).toBe(expectedBalance); } - getL2ToL1MessageLeaf(withdrawAmount: bigint, callerOnL1: EthAddress = EthAddress.default()): Fr { + getL2ToL1MessageLeaf(withdrawAmount: bigint, callerOnL1: EthAddress = EthAddress.ZERO): Fr { const content = sha256ToField([ Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'), this.ethAccount.toBuffer32(), diff --git a/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts b/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts index 76dc810d93b..6118be50591 100644 --- a/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts @@ -42,7 +42,7 @@ export class GasPortalTestingHarnessFactory { const gasL2 = await GasTokenContract.deploy(wallet) .send({ - contractAddressSalt: getCanonicalGasToken(EthAddress.default()).instance.salt, + contractAddressSalt: getCanonicalGasToken(EthAddress.ZERO).instance.salt, }) .deployed(); return Promise.resolve(new MockGasBridgingTestHarness(gasL2)); @@ -57,7 +57,7 @@ export class GasPortalTestingHarnessFactory { const gasTokenAddress = l1ContractAddresses.gasTokenAddress; const gasPortalAddress = l1ContractAddresses.gasPortalAddress; - if (gasTokenAddress.isDefault() || gasPortalAddress.isDefault()) { + if (gasTokenAddress.isZero() || gasPortalAddress.isZero()) { throw new Error('Gas portal not deployed on L1'); } diff --git a/yarn-project/foundation/src/aztec-address/index.ts b/yarn-project/foundation/src/aztec-address/index.ts index 11158fc9f0a..5512b9c1466 100644 --- a/yarn-project/foundation/src/aztec-address/index.ts +++ b/yarn-project/foundation/src/aztec-address/index.ts @@ -22,15 +22,7 @@ export class AztecAddress extends Fr { return `AztecAddress<${this.toString()}>`; } - static ZERO = new AztecAddress(Buffer.alloc(32)); - - static default(): AztecAddress { - return AztecAddress.ZERO; - } - - isDefault(): boolean { - return this.equals(AztecAddress.default()); - } + static readonly ZERO = new AztecAddress(Buffer.alloc(32)); static fromBuffer(buffer: Buffer | BufferReader) { return fromBuffer(buffer, AztecAddress); diff --git a/yarn-project/foundation/src/eth-address/eth_address.test.ts b/yarn-project/foundation/src/eth-address/eth_address.test.ts index 5ec28973607..2ae3e1bc736 100644 --- a/yarn-project/foundation/src/eth-address/eth_address.test.ts +++ b/yarn-project/foundation/src/eth-address/eth_address.test.ts @@ -19,12 +19,12 @@ describe('address', () => { }); it('should have correct zero address', () => { - expect(EthAddress.default().toString()).toBe('0x0000000000000000000000000000000000000000'); + expect(EthAddress.ZERO.toString()).toBe('0x0000000000000000000000000000000000000000'); }); it('should check if is zero', () => { const zero = EthAddress.fromString('0x0000000000000000000000000000000000000000'); - expect(zero.isDefault()).toBeTruthy(); + expect(zero.isZero()).toBeTruthy(); }); it('should encode and decode as field', () => { diff --git a/yarn-project/foundation/src/eth-address/index.ts b/yarn-project/foundation/src/eth-address/index.ts index c6d219ee078..b60c382957b 100644 --- a/yarn-project/foundation/src/eth-address/index.ts +++ b/yarn-project/foundation/src/eth-address/index.ts @@ -19,7 +19,7 @@ export class EthAddress { /** * Represents a zero Ethereum address with 20 bytes filled with zeros. */ - public static ZERO = new EthAddress(Buffer.alloc(EthAddress.SIZE_IN_BYTES)); + public static readonly ZERO = new EthAddress(Buffer.alloc(EthAddress.SIZE_IN_BYTES)); constructor(private buffer: Buffer) { if (buffer.length !== EthAddress.SIZE_IN_BYTES) { @@ -74,18 +74,18 @@ export class EthAddress { } } - public static default() { + public static zero() { return EthAddress.ZERO; } /** - * Checks if the EthAddress instance represents a default address (zero address). + * Checks if the EthAddress instance represents a zero address. * A zero address consists of 20 bytes filled with zeros and is considered an invalid address. * * @returns A boolean indicating whether the EthAddress instance is a zero address or not. */ - public isDefault() { - return this.equals(EthAddress.default()); + public isZero() { + return this.equals(EthAddress.ZERO); } /** diff --git a/yarn-project/foundation/src/fields/fields.test.ts b/yarn-project/foundation/src/fields/fields.test.ts index ceb602400ec..ff94978f0d1 100644 --- a/yarn-project/foundation/src/fields/fields.test.ts +++ b/yarn-project/foundation/src/fields/fields.test.ts @@ -179,7 +179,8 @@ describe('Bn254 arithmetic', () => { [new Fr(5), new Fr(5), 0], [new Fr(0), new Fr(Fr.MODULUS - 1n), -1], [new Fr(Fr.MODULUS - 1n), new Fr(0), 1], - [Fr.ZERO, Fr.default(), 0], + [Fr.ZERO, Fr.ZERO, 0], + [Fr.zero(), Fr.ZERO, 0], ])('Should compare field elements correctly', (a, b, expected) => { expect(a.cmp(b)).toEqual(expected); }); diff --git a/yarn-project/foundation/src/fields/fields.ts b/yarn-project/foundation/src/fields/fields.ts index 1c11a2c25b2..a28018638f4 100644 --- a/yarn-project/foundation/src/fields/fields.ts +++ b/yarn-project/foundation/src/fields/fields.ts @@ -132,10 +132,6 @@ abstract class BaseField { return this.toBuffer().equals(ZERO_BUFFER); } - isDefault(): boolean { - return this.toBuffer().equals(ZERO_BUFFER); - } - toFriendlyJSON(): string { return this.toString(); } @@ -209,12 +205,12 @@ export class Fr extends BaseField { return random(Fr); } - static default() { + static zero() { return Fr.ZERO; } - static isDefault(value: Fr) { - return value.isDefault(); + static isZero(value: Fr) { + return value.isZero(); } static fromBuffer(buffer: Buffer | BufferReader) { diff --git a/yarn-project/noir-protocol-circuits-types/src/noir_test_gen.test.ts b/yarn-project/noir-protocol-circuits-types/src/noir_test_gen.test.ts index 90c762b30c7..6453b0313e0 100644 --- a/yarn-project/noir-protocol-circuits-types/src/noir_test_gen.test.ts +++ b/yarn-project/noir-protocol-circuits-types/src/noir_test_gen.test.ts @@ -60,7 +60,7 @@ describe('Data generation for noir tests', () => { const initializationHash = computeInitializationHashFromEncodedArgs(constructorSelector, []); const { artifactHash, privateFunctionsRoot, publicBytecodeCommitment } = computeContractClassIdPreimage(contractClass); - const deployer = AztecAddress.default(); + const deployer = AztecAddress.ZERO; const instance: ContractInstance = { ...contract, version: 1, initializationHash, contractClassId, deployer }; const address = computeContractAddressFromInstance(instance); const saltedInitializationHash = computeSaltedInitializationHash(instance); diff --git a/yarn-project/protocol-contracts/src/gas-token/index.test.ts b/yarn-project/protocol-contracts/src/gas-token/index.test.ts index c6b9e4badc5..4a15655d4a3 100644 --- a/yarn-project/protocol-contracts/src/gas-token/index.test.ts +++ b/yarn-project/protocol-contracts/src/gas-token/index.test.ts @@ -4,7 +4,7 @@ import { getCanonicalGasToken } from './index.js'; describe('GasToken', () => { it('returns canonical protocol contract', () => { - const contract = getCanonicalGasToken(EthAddress.default()); + const contract = getCanonicalGasToken(EthAddress.ZERO); expect(computeContractAddressFromInstance(contract.instance)).toEqual(contract.address); expect(getContractClassFromArtifact(contract.artifact).id).toEqual(contract.contractClass.id); }); diff --git a/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts b/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts index 3951e0ad12c..3a40b9860f9 100644 --- a/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts +++ b/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts @@ -4,7 +4,7 @@ import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol import { MultiCallEntrypointArtifact } from './artifact.js'; export function getCanonicalMultiCallEntrypointContract(): ProtocolContract { - return getCanonicalProtocolContract(MultiCallEntrypointArtifact, 1, [], Point.default(), EthAddress.default()); + return getCanonicalProtocolContract(MultiCallEntrypointArtifact, 1, [], Point.default(), EthAddress.ZERO); } export function getCanonicalMultiCallEntrypointAddress(): AztecAddress { diff --git a/yarn-project/protocol-contracts/src/protocol_contract.ts b/yarn-project/protocol-contracts/src/protocol_contract.ts index 8581e61007e..4272d71470b 100644 --- a/yarn-project/protocol-contracts/src/protocol_contract.ts +++ b/yarn-project/protocol-contracts/src/protocol_contract.ts @@ -26,7 +26,7 @@ export function getCanonicalProtocolContract( salt: Fr | number | bigint, constructorArgs: any[] = [], publicKey: Point = Point.default(), - portalAddress = EthAddress.default(), + portalAddress = EthAddress.ZERO, ): ProtocolContract { // TODO(@spalladino): This computes the contract class from the artifact twice. const contractClass = getContractClassFromArtifact(artifact); diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.test.ts index 7bfc6d42a18..df792d45ae9 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.test.ts @@ -75,8 +75,8 @@ describe('prover/tx-prover', () => { const chainId = Fr.ZERO; const version = Fr.ZERO; - const coinbase = EthAddress.default(); - const feeRecipient = AztecAddress.default(); + const coinbase = EthAddress.ZERO; + const feeRecipient = AztecAddress.ZERO; beforeEach(async () => { blockNumber = 3; diff --git a/yarn-project/pxe/src/kernel_prover/hints_builder.ts b/yarn-project/pxe/src/kernel_prover/hints_builder.ts index 8dce8d12fe9..a65e2386cc6 100644 --- a/yarn-project/pxe/src/kernel_prover/hints_builder.ts +++ b/yarn-project/pxe/src/kernel_prover/hints_builder.ts @@ -59,7 +59,7 @@ export class HintsBuilder { noteHashReadRequests: Tuple, noteHashes: Tuple, ): Tuple { - const hints = makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_TX, Fr.default); + const hints = makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_TX, Fr.zero); for (let i = 0; i < MAX_NOTE_HASH_READ_REQUESTS_PER_TX && !noteHashReadRequests[i].isDefault(); i++) { const equalToRR = (cmt: SideEffect) => cmt.value.equals(noteHashReadRequests[i].value); const result = noteHashes.findIndex(equalToRR); @@ -114,7 +114,7 @@ export class HintsBuilder { nullifiedNoteHashes: Tuple, noteHashes: Tuple, ): Tuple { - const hints = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, Fr.default); + const hints = makeTuple(MAX_NEW_NULLIFIERS_PER_TX, Fr.zero); const alreadyUsed = new Set(); for (let i = 0; i < MAX_NEW_NULLIFIERS_PER_TX; i++) { if (!nullifiedNoteHashes[i].isZero()) { diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts index 9c81119b810..7d58d8b7125 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts @@ -62,7 +62,7 @@ describe('Kernel Prover', () => { const functionData = FunctionData.default(); functionData.selector = new FunctionSelector(fnName.charCodeAt(0)); return { - callStackItem: new PrivateCallStackItem(AztecAddress.default(), functionData, publicInputs), + callStackItem: new PrivateCallStackItem(AztecAddress.ZERO, functionData, publicInputs), nestedExecutions: (dependencies[fnName] || []).map(name => createExecutionResult(name)), vk: VerificationKey.makeFake().toBuffer(), newNotes: newNoteIndices.map(idx => notesAndSlots[idx]), diff --git a/yarn-project/sequencer-client/src/config.ts b/yarn-project/sequencer-client/src/config.ts index d0cee5cc8f8..b86863b9393 100644 --- a/yarn-project/sequencer-client/src/config.ts +++ b/yarn-project/sequencer-client/src/config.ts @@ -62,15 +62,15 @@ export function getConfigEnvVars(): SequencerClientConfig { const addresses: L1ContractAddresses = { availabilityOracleAddress: AVAILABILITY_ORACLE_CONTRACT_ADDRESS ? EthAddress.fromString(AVAILABILITY_ORACLE_CONTRACT_ADDRESS) - : EthAddress.default(), - rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.default(), - registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.default(), - inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.default(), - outboxAddress: OUTBOX_CONTRACT_ADDRESS ? EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS) : EthAddress.default(), - gasTokenAddress: GAS_TOKEN_CONTRACT_ADDRESS ? EthAddress.fromString(GAS_TOKEN_CONTRACT_ADDRESS) : EthAddress.default(), + : EthAddress.ZERO, + rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, + registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO, + inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, + outboxAddress: OUTBOX_CONTRACT_ADDRESS ? EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, + gasTokenAddress: GAS_TOKEN_CONTRACT_ADDRESS ? EthAddress.fromString(GAS_TOKEN_CONTRACT_ADDRESS) : EthAddress.ZERO, gasPortalAddress: GAS_PORTAL_CONTRACT_ADDRESS ? EthAddress.fromString(GAS_PORTAL_CONTRACT_ADDRESS) - : EthAddress.default(), + : EthAddress.ZERO, }; return { diff --git a/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts b/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts index 687f6b97fa5..a91bd24c20c 100644 --- a/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts +++ b/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts @@ -360,7 +360,7 @@ export abstract class AbstractPhaseManager { return PublicCircuitPublicInputs.from({ callContext: result.execution.callContext, - proverAddress: AztecAddress.default(), + proverAddress: AztecAddress.ZERO, argsHash: computeVarArgsHash(result.execution.args), newNoteHashes: padArrayEnd(result.newNoteHashes, SideEffect.default(), MAX_NEW_NOTE_HASHES_PER_CALL), newNullifiers: padArrayEnd(result.newNullifiers, SideEffectLinkedToNoteHash.default(), MAX_NEW_NULLIFIERS_PER_CALL), diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts index b68abc8c387..22b3080d5ad 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts @@ -715,7 +715,7 @@ class PublicExecutionResultBuilder { revertReason?: SimulationError; }) { const builder = new PublicExecutionResultBuilder({ - callContext: new CallContext(from, tx.to, EthAddress.default(), tx.functionData.selector, false, false, 0), + callContext: new CallContext(from, tx.to, EthAddress.ZERO, tx.functionData.selector, false, false, 0), contractAddress: tx.to, functionData: tx.functionData, args: tx.args, diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index 09938298ecc..7976b9ae6fb 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -31,8 +31,8 @@ export class Sequencer { private maxTxsPerBlock = 32; private minTxsPerBLock = 1; // TODO: zero values should not be allowed for the following 2 values in PROD - private _coinbase = EthAddress.default(); - private _feeRecipient = AztecAddress.default(); + private _coinbase = EthAddress.ZERO; + private _feeRecipient = AztecAddress.ZERO; private lastPublishedBlock = 0; private state = SequencerState.STOPPED; private allowedFeePaymentContractClasses: Fr[] = []; diff --git a/yarn-project/sequencer-client/src/sequencer/tx_validator.test.ts b/yarn-project/sequencer-client/src/sequencer/tx_validator.test.ts index bfdbf79e1a6..bf83feb427b 100644 --- a/yarn-project/sequencer-client/src/sequencer/tx_validator.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/tx_validator.test.ts @@ -292,7 +292,7 @@ describe('TxValidator', () => { const feeSetupFn = new PublicCallRequest( feePaymentContract, new FunctionData(feeSetupSelector, true), - new CallContext(feePaymentContract, feePaymentContract, EthAddress.default(), feeSetupSelector, false, false, 1), + new CallContext(feePaymentContract, feePaymentContract, EthAddress.ZERO, feeSetupSelector, false, false, 1), CallContext.default(), [], ); @@ -303,7 +303,7 @@ describe('TxValidator', () => { const feeExecutionFn = new PublicCallRequest( feePaymentContract, new FunctionData(feeExecutionSelector, true), - new CallContext(feePaymentContract, feePaymentContract, EthAddress.default(), feeExecutionSelector, false, false, 2), + new CallContext(feePaymentContract, feePaymentContract, EthAddress.ZERO, feeExecutionSelector, false, false, 2), CallContext.default(), [], ); diff --git a/yarn-project/simulator/src/avm/fixtures/index.ts b/yarn-project/simulator/src/avm/fixtures/index.ts index b373345610f..412fe2911be 100644 --- a/yarn-project/simulator/src/avm/fixtures/index.ts +++ b/yarn-project/simulator/src/avm/fixtures/index.ts @@ -58,11 +58,11 @@ export function initMockPersistableStateManager(): AvmPersistableStateManager { */ export function initExecutionEnvironment(overrides?: Partial): AvmExecutionEnvironment { return new AvmExecutionEnvironment( - overrides?.address ?? AztecAddress.default(), - overrides?.storageAddress ?? AztecAddress.default(), - overrides?.origin ?? AztecAddress.default(), - overrides?.sender ?? AztecAddress.default(), - overrides?.portal ?? EthAddress.default(), + overrides?.address ?? AztecAddress.ZERO, + overrides?.storageAddress ?? AztecAddress.ZERO, + overrides?.origin ?? AztecAddress.ZERO, + overrides?.sender ?? AztecAddress.ZERO, + overrides?.portal ?? EthAddress.ZERO, overrides?.feePerL1Gas ?? Fr.ZERO, overrides?.feePerL2Gas ?? Fr.ZERO, overrides?.feePerDaGas ?? Fr.ZERO, @@ -84,8 +84,8 @@ export function initGlobalVariables(overrides?: Partial): Globa overrides?.version ?? Fr.ZERO, overrides?.blockNumber ?? Fr.ZERO, overrides?.timestamp ?? Fr.ZERO, - overrides?.coinbase ?? EthAddress.default(), - overrides?.feeRecipient ?? AztecAddress.default(), + overrides?.coinbase ?? EthAddress.ZERO, + overrides?.feeRecipient ?? AztecAddress.ZERO, ); } diff --git a/yarn-project/simulator/src/client/execution_result.test.ts b/yarn-project/simulator/src/client/execution_result.test.ts index 1339f3e5871..12331fed861 100644 --- a/yarn-project/simulator/src/client/execution_result.test.ts +++ b/yarn-project/simulator/src/client/execution_result.test.ts @@ -163,7 +163,7 @@ describe('collect unencrypted logs', () => { function makeUnencryptedFunctionLogs(contents: string[]) { return new UnencryptedFunctionL2Logs( - contents.map(s => new UnencryptedL2Log(AztecAddress.default(), EventSelector.default(), Buffer.from(s))), + contents.map(s => new UnencryptedL2Log(AztecAddress.ZERO, EventSelector.default(), Buffer.from(s))), ); } diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index ac149b7abcd..9f536029090 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -94,9 +94,9 @@ describe('Private Execution test suite', () => { const runSimulator = ({ artifact, args = [], - msgSender = AztecAddress.default(), + msgSender = AztecAddress.ZERO, contractAddress = defaultContractAddress, - portalContractAddress = EthAddress.default(), + portalContractAddress = EthAddress.ZERO, txContext = {}, }: { artifact: FunctionArtifact; @@ -278,7 +278,7 @@ describe('Private Execution test suite', () => { Promise.resolve(getFunctionArtifact(StatefulTestContractArtifact, selector)), ); - oracle.getPortalContractAddress.mockResolvedValue(EthAddress.default()); + oracle.getPortalContractAddress.mockResolvedValue(EthAddress.ZERO); }); it('should have a constructor with arguments that inserts notes', async () => { @@ -442,7 +442,7 @@ describe('Private Execution test suite', () => { const childSelector = FunctionSelector.fromNameAndParameters(childArtifact.name, childArtifact.parameters); oracle.getFunctionArtifact.mockImplementation(() => Promise.resolve(childArtifact)); - oracle.getPortalContractAddress.mockImplementation(() => Promise.resolve(EthAddress.default())); + oracle.getPortalContractAddress.mockImplementation(() => Promise.resolve(EthAddress.ZERO)); logger(`Parent deployed at ${parentAddress.toShortString()}`); logger(`Calling child function ${childSelector.toString()} at ${childAddress.toShortString()}`); @@ -495,7 +495,7 @@ describe('Private Execution test suite', () => { ); oracle.getFunctionArtifact.mockResolvedValue(testCodeGenArtifact); - oracle.getPortalContractAddress.mockResolvedValue(EthAddress.default()); + oracle.getPortalContractAddress.mockResolvedValue(EthAddress.ZERO); logger(`Calling importer main function`); const args = [testAddress]; @@ -809,7 +809,7 @@ describe('Private Execution test suite', () => { parentCallContext: CallContext.from({ msgSender: parentAddress, storageContractAddress: parentAddress, - portalContractAddress: EthAddress.default(), + portalContractAddress: EthAddress.ZERO, functionSelector: FunctionSelector.fromNameAndParameters(parentArtifact.name, parentArtifact.parameters), isDelegateCall: false, isStaticCall: false, @@ -922,7 +922,7 @@ describe('Private Execution test suite', () => { getThenNullifyArtifact.parameters, ); - oracle.getPortalContractAddress.mockImplementation(() => Promise.resolve(EthAddress.default())); + oracle.getPortalContractAddress.mockImplementation(() => Promise.resolve(EthAddress.ZERO)); const args = [amountToTransfer, owner, insertFnSelector.toField(), getThenNullifyFnSelector.toField()]; const result = await runSimulator({ diff --git a/yarn-project/simulator/src/client/simulator.ts b/yarn-project/simulator/src/client/simulator.ts index 05337451203..1aa66a195c6 100644 --- a/yarn-project/simulator/src/client/simulator.ts +++ b/yarn-project/simulator/src/client/simulator.ts @@ -70,7 +70,7 @@ export class AcirSimulator { entryPointArtifact: FunctionArtifactWithDebugMetadata, contractAddress: AztecAddress, portalContractAddress: EthAddress, - msgSender = AztecAddress.default(), + msgSender = AztecAddress.ZERO, ): Promise { if (entryPointArtifact.functionType !== FunctionType.SECRET) { throw new Error(`Cannot run ${entryPointArtifact.functionType} function as secret`); diff --git a/yarn-project/simulator/src/public/index.test.ts b/yarn-project/simulator/src/public/index.test.ts index cfa4bec321d..2e17f1d922e 100644 --- a/yarn-project/simulator/src/public/index.test.ts +++ b/yarn-project/simulator/src/public/index.test.ts @@ -464,8 +464,8 @@ describe('ACIR public execution simulator', () => { new Fr(preimage.recipient.version), Fr.ZERO, Fr.ZERO, - EthAddress.default(), - AztecAddress.default(), + EthAddress.ZERO, + AztecAddress.ZERO, ); const mockOracles = (updateState = true) => { @@ -650,7 +650,7 @@ describe('ACIR public execution simulator', () => { callContext = CallContext.from({ msgSender: AztecAddress.random(), storageContractAddress: AztecAddress.random(), - portalContractAddress: EthAddress.default(), + portalContractAddress: EthAddress.ZERO, functionSelector: FunctionSelector.default(), isDelegateCall: false, isStaticCall: false, @@ -733,7 +733,7 @@ describe('ACIR public execution simulator', () => { callContext = CallContext.from({ msgSender: AztecAddress.random(), storageContractAddress: AztecAddress.random(), - portalContractAddress: EthAddress.default(), + portalContractAddress: EthAddress.ZERO, functionSelector: FunctionSelector.default(), isDelegateCall: false, isStaticCall: false, diff --git a/yarn-project/simulator/src/public/public_execution_context.ts b/yarn-project/simulator/src/public/public_execution_context.ts index b23139da37f..b999d27ad13 100644 --- a/yarn-project/simulator/src/public/public_execution_context.ts +++ b/yarn-project/simulator/src/public/public_execution_context.ts @@ -130,7 +130,7 @@ export class PublicExecutionContext extends TypedOracle { * @returns The portal contract address. */ public async getPortalContractAddress(contractAddress: AztecAddress) { - return (await this.contractsDb.getPortalContractAddress(contractAddress)) ?? EthAddress.default(); + return (await this.contractsDb.getPortalContractAddress(contractAddress)) ?? EthAddress.ZERO; } /** @@ -189,7 +189,7 @@ export class PublicExecutionContext extends TypedOracle { const args = this.packedArgsCache.unpack(argsHash); this.log(`Public function call: addr=${targetContractAddress} selector=${functionSelector} args=${args.join(',')}`); - const portalAddress = (await this.contractsDb.getPortalContractAddress(targetContractAddress)) ?? EthAddress.default(); + const portalAddress = (await this.contractsDb.getPortalContractAddress(targetContractAddress)) ?? EthAddress.ZERO; const acir = await this.contractsDb.getBytecode(targetContractAddress, functionSelector); if (!acir) { From 92d2f1ffa272c0b592cc8bfa500d8a999486ee20 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Mon, 8 Apr 2024 21:34:53 +0000 Subject: [PATCH 48/77] fix --- .../src/private_kernel_tail_to_public.nr | 2 +- .../combined_accumulated_data.nr | 4 +- .../combined_accumulated_data_builder.nr | 57 ------------------- yarn-project/circuit-types/src/tx/tx.ts | 8 +-- .../kernel/kernel_circuit_public_inputs.ts | 4 +- ...ivate_kernel_tail_circuit_public_inputs.ts | 8 +-- .../prover-client/src/dummy-prover.ts | 2 +- .../src/orchestrator/orchestrator.ts | 2 +- .../src/kernel_prover/kernel_prover.test.ts | 2 +- .../src/sequencer/tx_validator.ts | 2 +- 10 files changed, 17 insertions(+), 74 deletions(-) delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr 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 d5b5dfd0ce2..d2b371cf57a 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 @@ -104,7 +104,7 @@ mod tests { note_hashes: [SideEffect; N] ) -> [SideEffect; N] { let first_nullifier = self.previous_kernel.new_nullifiers.get_unchecked(0); - let mut unique_siloed_note_hashes = [SideEffect::empty(); N]; + let mut unique_siloed_note_hashes = [SideEffect::default(); N]; for i in 0..N { if note_hashes[i].value != 0 { let nonce = compute_note_hash_nonce(first_nullifier.value, i); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr index 5d3991dcf2f..708390e78c8 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr @@ -30,8 +30,8 @@ struct CombinedAccumulatedData { impl Default for CombinedAccumulatedData { fn default() -> Self { CombinedAccumulatedData { - new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_TX], - new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_TX], + new_note_hashes: [0; MAX_NEW_NOTE_HASHES_PER_TX], + new_nullifiers: [0; MAX_NEW_NULLIFIERS_PER_TX], new_l2_to_l1_msgs: [0; MAX_NEW_L2_TO_L1_MSGS_PER_TX], encrypted_logs_hash: 0, unencrypted_logs_hash: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr deleted file mode 100644 index b0b39b87137..00000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data_builder.nr +++ /dev/null @@ -1,57 +0,0 @@ -use crate::{ - abis::{ - accumulated_data::combined_accumulated_data::CombinedAccumulatedData, - public_data_update_request::PublicDataUpdateRequest, - side_effect::{SideEffect, SideEffectLinkedToNoteHash} -} -}; -use crate::constants::{ - MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, - MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX -}; - -struct CombinedAccumulatedDataBuilder { - new_note_hashes: BoundedVec, - new_nullifiers: BoundedVec, - new_l2_to_l1_msgs: BoundedVec, - - encrypted_logs_hash: Field, - unencrypted_logs_hash: Field, - - // Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the - // variable-length data. - encrypted_log_preimages_length: Field, - unencrypted_log_preimages_length: Field, - - public_data_update_requests: BoundedVec, -} - -impl Default for CombinedAccumulatedDataBuilder { - fn default() -> Self { - CombinedAccumulatedDataBuilder { - new_note_hashes: BoundedVec::new(), - new_nullifiers: BoundedVec::new(), - new_l2_to_l1_msgs: BoundedVec::new(), - encrypted_logs_hash: 0, - unencrypted_logs_hash: 0, - encrypted_log_preimages_length: 0, - unencrypted_log_preimages_length: 0, - public_data_update_requests: BoundedVec::new(), - } - } -} - -impl CombinedAccumulatedDataBuilder { - pub fn finish(self) -> CombinedAccumulatedData { - CombinedAccumulatedData { - new_note_hashes: self.new_note_hashes.storage, - new_nullifiers: self.new_nullifiers.storage, - new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, - encrypted_logs_hash: self.encrypted_logs_hash, - unencrypted_logs_hash: self.unencrypted_logs_hash, - encrypted_log_preimages_length: self.encrypted_log_preimages_length, - unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, - public_data_update_requests: self.public_data_update_requests.storage - } - } -} diff --git a/yarn-project/circuit-types/src/tx/tx.ts b/yarn-project/circuit-types/src/tx/tx.ts index 2cb59d76244..0da7f782daf 100644 --- a/yarn-project/circuit-types/src/tx/tx.ts +++ b/yarn-project/circuit-types/src/tx/tx.ts @@ -138,8 +138,8 @@ export class Tx { */ getTxHash(): TxHash { // Private kernel functions are executed client side and for this reason tx hash is already set as first nullifier - const firstNullifier = this.data.getNonDefaultNullifiers()[0]; - if (!firstNullifier || firstNullifier.isDefault()) { + const firstNullifier = this.data.getNonZeroNullifiers()[0]; + if (!firstNullifier || firstNullifier.isZero()) { throw new Error(`Cannot get tx hash since first nullifier is missing`); } return new TxHash(firstNullifier.toBuffer()); @@ -154,8 +154,8 @@ export class Tx { encryptedLogSize: this.encryptedLogs.getSerializedLength(), unencryptedLogSize: this.unencryptedLogs.getSerializedLength(), - newCommitmentCount: this.data.getNonDefaultNoteHashes().length, - newNullifierCount: this.data.getNonDefaultNullifiers().length, + newCommitmentCount: this.data.getNonZeroNoteHashes().length, + newNullifierCount: this.data.getNonZeroNullifiers().length, proofSize: this.proof.buffer.length, size: this.toBuffer().length, diff --git a/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts index 9f61dc43321..5e0dc577b01 100644 --- a/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/kernel_circuit_public_inputs.ts @@ -34,8 +34,8 @@ export class KernelCircuitPublicInputs { public revertCode: RevertCode, ) {} - getNonDefaultNullifiers() { - return this.end.newNullifiers.filter(n => !n.isDefault()); + getNonZeroNullifiers() { + return this.end.newNullifiers.filter(n => !n.isZero()); } toBuffer() { diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts index 33af120de76..c219ba2d310 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_tail_circuit_public_inputs.ts @@ -146,7 +146,7 @@ export class PrivateKernelTailCircuitPublicInputs { : 0; } - getNonDefaultNoteHashes() { + getNonZeroNoteHashes() { const noteHashes = this.forPublic ? mergeAccumulatedData( MAX_NEW_NULLIFIERS_PER_TX, @@ -154,10 +154,10 @@ export class PrivateKernelTailCircuitPublicInputs { this.forPublic.end.newNoteHashes, ).map(n => n.value) : this.forRollup!.end.newNoteHashes; - return noteHashes.filter(n => !n.isDefault()); + return noteHashes.filter(n => !n.isZero()); } - getNonDefaultNullifiers() { + getNonZeroNullifiers() { const nullifiers = this.forPublic ? mergeAccumulatedData( MAX_NEW_NULLIFIERS_PER_TX, @@ -165,7 +165,7 @@ export class PrivateKernelTailCircuitPublicInputs { this.forPublic.end.newNullifiers, ).map(n => n.value) : this.forRollup!.end.newNullifiers; - return nullifiers.filter(n => !n.isDefault()); + return nullifiers.filter(n => !n.isZero()); } static fromBuffer(buffer: Buffer | BufferReader): PrivateKernelTailCircuitPublicInputs { diff --git a/yarn-project/prover-client/src/dummy-prover.ts b/yarn-project/prover-client/src/dummy-prover.ts index de61267c738..20a552e29b9 100644 --- a/yarn-project/prover-client/src/dummy-prover.ts +++ b/yarn-project/prover-client/src/dummy-prover.ts @@ -46,7 +46,7 @@ export class DummyProver implements ProverClient { finaliseBlock(): Promise { return Promise.resolve({ - block: L2Block.empty(), + block: L2Block.default(), proof: makeEmptyProof(), }); } diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.ts index 4d3baf6e150..67616887103 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.ts @@ -279,7 +279,7 @@ export class ProvingOrchestrator { // Collect all new nullifiers, commitments, and contracts from all txs in this block const nonEmptyTxEffects: TxEffect[] = this.provingState!.allTxs.map(tx => toTxEffect(tx)).filter( - txEffect => !txEffect.isEmpty(), + txEffect => !txEffect.isDefault(), ); const blockBody = new Body(nonEmptyTxEffects); diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts index 07a4a56b26f..f1056feb4a5 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts @@ -95,7 +95,7 @@ describe('Kernel Prover', () => { }; const createProofOutputFinal = (newNoteIndices: number[]) => { - const publicInputs = PrivateKernelTailCircuitPublicInputs.empty(); + const publicInputs = PrivateKernelTailCircuitPublicInputs.default(); const noteHashes = makeTuple(MAX_NEW_NOTE_HASHES_PER_TX, Fr.zero); for (let i = 0; i < newNoteIndices.length; i++) { noteHashes[i] = generateFakeSiloedCommitment(notesAndSlots[newNoteIndices[i]]); diff --git a/yarn-project/sequencer-client/src/sequencer/tx_validator.ts b/yarn-project/sequencer-client/src/sequencer/tx_validator.ts index 0e0f3ae2687..a2ceaac1236 100644 --- a/yarn-project/sequencer-client/src/sequencer/tx_validator.ts +++ b/yarn-project/sequencer-client/src/sequencer/tx_validator.ts @@ -138,7 +138,7 @@ export class TxValidator { * @returns Whether this is a problematic double spend that the L1 contract would reject. */ async #validateNullifiers(tx: Tx | ProcessedTx, thisBlockNullifiers: Set): Promise { - const newNullifiers = tx.data.getNonDefaultNullifiers().map(x => x.toBigInt()); + const newNullifiers = tx.data.getNonZeroNullifiers().map(x => x.toBigInt()); // Ditch this tx if it has repeated nullifiers const uniqueNullifiers = new Set(newNullifiers); From 4aa05a6f9d1b2d474de38f781885bc8b4a7ed37e Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 9 Apr 2024 08:43:14 +0000 Subject: [PATCH 49/77] yarn format yarn formatting fix --- .../circuits.js/src/structs/contract_storage_read.ts | 6 +++++- .../src/structs/contract_storage_update_request.ts | 6 +++++- .../src/structs/private_circuit_public_inputs.ts | 1 - .../src/structs/public_circuit_public_inputs.ts | 1 - yarn-project/circuits.js/src/structs/tx_context.ts | 7 ++++++- yarn-project/circuits.js/src/structs/tx_request.ts | 7 ++++++- yarn-project/circuits.js/src/tests/factories.ts | 7 ++++++- yarn-project/foundation/src/array/array.ts | 5 ++++- yarn-project/pxe/src/kernel_prover/kernel_prover.ts | 6 +++++- yarn-project/pxe/src/pxe_service/pxe_service.ts | 4 +++- .../src/sequencer/abstract_phase_manager.ts | 12 ++++++++++-- yarn-project/simulator/src/acvm/oracle/oracle.ts | 4 +++- .../src/avm/avm_execution_environment.test.ts | 12 +++++++++--- yarn-project/simulator/src/avm/journal/nullifiers.ts | 6 ++++-- .../simulator/src/avm/journal/public_storage.ts | 2 +- 15 files changed, 67 insertions(+), 19 deletions(-) diff --git a/yarn-project/circuits.js/src/structs/contract_storage_read.ts b/yarn-project/circuits.js/src/structs/contract_storage_read.ts index 34d090b3239..95459dc258f 100644 --- a/yarn-project/circuits.js/src/structs/contract_storage_read.ts +++ b/yarn-project/circuits.js/src/structs/contract_storage_read.ts @@ -57,7 +57,11 @@ export class ContractStorageRead { } isDefault() { - return this.storageSlot.isZero() && this.currentValue.isZero() && (this.sideEffectCounter == 0 || this.sideEffectCounter == undefined); + return ( + this.storageSlot.isZero() && + this.currentValue.isZero() && + (this.sideEffectCounter == 0 || this.sideEffectCounter == undefined) + ); } toFriendlyJSON() { diff --git a/yarn-project/circuits.js/src/structs/contract_storage_update_request.ts b/yarn-project/circuits.js/src/structs/contract_storage_update_request.ts index daa0c24576c..3f23f3573c5 100644 --- a/yarn-project/circuits.js/src/structs/contract_storage_update_request.ts +++ b/yarn-project/circuits.js/src/structs/contract_storage_update_request.ts @@ -58,7 +58,11 @@ export class ContractStorageUpdateRequest { } isDefault() { - return this.storageSlot.isZero() && this.newValue.isZero() && (this.sideEffectCounter == 0 || this.sideEffectCounter == undefined); + return ( + this.storageSlot.isZero() && + this.newValue.isZero() && + (this.sideEffectCounter == 0 || this.sideEffectCounter == undefined) + ); } toFriendlyJSON() { diff --git a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts index 679a576967e..ed93ec540dd 100644 --- a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts @@ -1,5 +1,4 @@ import { makeTuple } from '@aztec/foundation/array'; -import { isArrayEmpty } from '@aztec/foundation/collection'; import { pedersenHash } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import { diff --git a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts index 11a3ab8eb47..808c6e5eb83 100644 --- a/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/public_circuit_public_inputs.ts @@ -1,6 +1,5 @@ import { makeTuple } from '@aztec/foundation/array'; import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { isArrayEmpty } from '@aztec/foundation/collection'; import { pedersenHash } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import { diff --git a/yarn-project/circuits.js/src/structs/tx_context.ts b/yarn-project/circuits.js/src/structs/tx_context.ts index 99dcda629ee..24ba30e99aa 100644 --- a/yarn-project/circuits.js/src/structs/tx_context.ts +++ b/yarn-project/circuits.js/src/structs/tx_context.ts @@ -68,7 +68,12 @@ export class TxContext { } isDefault(chainId: number = 0, version: number = 0): boolean { - return !this.isFeePaymentTx && !this.isRebatePaymentTx && this.chainId.equals(new Fr(chainId)) && this.version.equals(new Fr(version)); + return ( + !this.isFeePaymentTx && + !this.isRebatePaymentTx && + this.chainId.equals(new Fr(chainId)) && + this.version.equals(new Fr(version)) + ); } /** diff --git a/yarn-project/circuits.js/src/structs/tx_request.ts b/yarn-project/circuits.js/src/structs/tx_request.ts index 27736d5db75..7ad6a3a5595 100644 --- a/yarn-project/circuits.js/src/structs/tx_request.ts +++ b/yarn-project/circuits.js/src/structs/tx_request.ts @@ -79,6 +79,11 @@ export class TxRequest { } isDefault() { - return this.origin.isZero() && (this.functionData.isDefault(true) || this.functionData.isDefault(false)) && this.argsHash.isZero() && this.txContext.isDefault(); + return ( + this.origin.isZero() && + (this.functionData.isDefault(true) || this.functionData.isDefault(false)) && + this.argsHash.isZero() && + this.txContext.isDefault() + ); } } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 2f29dc44967..5dca5e3add5 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -410,7 +410,12 @@ export function makePublicCircuitPublicInputs( fr(seed + 0x100), tupleGenerator(RETURN_VALUES_LENGTH, fr, seed + 0x200, Fr.zero), tupleGenerator(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x400, ReadRequest.default), - tupleGenerator(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x420, ReadRequest.default), + tupleGenerator( + MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, + makeReadRequest, + seed + 0x420, + ReadRequest.default, + ), tupleGenerator( MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, makeContractStorageUpdateRequest, diff --git a/yarn-project/foundation/src/array/array.ts b/yarn-project/foundation/src/array/array.ts index 662cf294c98..0b18a50c4c5 100644 --- a/yarn-project/foundation/src/array/array.ts +++ b/yarn-project/foundation/src/array/array.ts @@ -40,7 +40,10 @@ export function makeHalfFullTuple( offset = 0, makeDefault: () => T, ) { - return Array.from({ length }, (v: any, i: number) => (i < length / 2 ? fn(i + offset) : makeDefault())) as Tuple; + return Array.from({ length }, (v: any, i: number) => (i < length / 2 ? fn(i + offset) : makeDefault())) as Tuple< + T, + N + >; } /** diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts index 5dd6a58b8bf..bb9d4dc629e 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -201,7 +201,11 @@ export class KernelProver { CallRequest.default(), MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, ); - const publicCallStack = padArrayEnd(publicCallRequests, CallRequest.default(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL); + const publicCallStack = padArrayEnd( + publicCallRequests, + CallRequest.default(), + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, + ); const functionLeafMembershipWitness = await this.oracle.getFunctionMembershipWitness( contractAddress, diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 1cca0d50b02..42bae3efa88 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -708,7 +708,9 @@ export class PXEService implements PXE { publicInputs.forPublic!.end.publicCallStack.find(item => item.equals(enqueued)), ); - const revertibleStackSize = arrayNonDefaultLength(publicInputs.forPublic.end.publicCallStack, item => item.isDefault()); + const revertibleStackSize = arrayNonDefaultLength(publicInputs.forPublic.end.publicCallStack, item => + item.isDefault(), + ); if (enqueuedRevertiblePublicCallStackItems.length !== revertibleStackSize) { throw new Error( diff --git a/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts b/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts index a91bd24c20c..da7200c6994 100644 --- a/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts +++ b/yarn-project/sequencer-client/src/sequencer/abstract_phase_manager.ts @@ -363,7 +363,11 @@ export abstract class AbstractPhaseManager { proverAddress: AztecAddress.ZERO, argsHash: computeVarArgsHash(result.execution.args), newNoteHashes: padArrayEnd(result.newNoteHashes, SideEffect.default(), MAX_NEW_NOTE_HASHES_PER_CALL), - newNullifiers: padArrayEnd(result.newNullifiers, SideEffectLinkedToNoteHash.default(), MAX_NEW_NULLIFIERS_PER_CALL), + newNullifiers: padArrayEnd( + result.newNullifiers, + SideEffectLinkedToNoteHash.default(), + MAX_NEW_NULLIFIERS_PER_CALL, + ), newL2ToL1Msgs: padArrayEnd(result.newL2ToL1Messages, L2ToL1Message.default(), MAX_NEW_L2_TO_L1_MSGS_PER_CALL), startSideEffectCounter: result.startSideEffectCounter, endSideEffectCounter: result.endSideEffectCounter, @@ -438,7 +442,11 @@ export abstract class AbstractPhaseManager { const publicCallRequests = (await this.getPublicCallStackPreimages(result)).map(c => c.toCallRequest(callStackItem.publicInputs.callContext), ); - const publicCallStack = padArrayEnd(publicCallRequests, CallRequest.default(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL); + const publicCallStack = padArrayEnd( + publicCallRequests, + CallRequest.default(), + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, + ); const portalContractAddress = result.execution.callContext.portalContractAddress.toField(); return new PublicCallData(callStackItem, publicCallStack, makeEmptyProof(), portalContractAddress, bytecodeHash); } diff --git a/yarn-project/simulator/src/acvm/oracle/oracle.ts b/yarn-project/simulator/src/acvm/oracle/oracle.ts index ed20793e69e..83b5f75e827 100644 --- a/yarn-project/simulator/src/acvm/oracle/oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/oracle.ts @@ -28,7 +28,9 @@ export class Oracle { } async getNullifierKeyPair([accountAddress]: ACVMField[]): Promise { - const { publicKey, secretKey } = await this.typedOracle.getNullifierKeyPair(AztecAddress.fromField(fromACVMField(accountAddress))); + const { publicKey, secretKey } = await this.typedOracle.getNullifierKeyPair( + AztecAddress.fromField(fromACVMField(accountAddress)), + ); return [ toACVMField(publicKey.x), toACVMField(publicKey.y), diff --git a/yarn-project/simulator/src/avm/avm_execution_environment.test.ts b/yarn-project/simulator/src/avm/avm_execution_environment.test.ts index 495c2f0f3c5..7f83d49b709 100644 --- a/yarn-project/simulator/src/avm/avm_execution_environment.test.ts +++ b/yarn-project/simulator/src/avm/avm_execution_environment.test.ts @@ -1,7 +1,7 @@ +import { AztecAddress } from '@aztec/circuits.js'; import { Fr } from '@aztec/foundation/fields'; import { allSameExcept, anyAvmContextInputs, initExecutionEnvironment } from './fixtures/index.js'; -import { AztecAddress } from '@aztec/circuits.js'; describe('Execution Environment', () => { const newAddress = new Fr(123456n); @@ -9,7 +9,10 @@ describe('Execution Environment', () => { it('New call should fork execution environment correctly', () => { const executionEnvironment = initExecutionEnvironment(); - const newExecutionEnvironment = executionEnvironment.deriveEnvironmentForNestedCall(AztecAddress.fromField(newAddress), calldata); + const newExecutionEnvironment = executionEnvironment.deriveEnvironmentForNestedCall( + AztecAddress.fromField(newAddress), + calldata, + ); expect(newExecutionEnvironment).toEqual( allSameExcept(executionEnvironment, { @@ -37,7 +40,10 @@ describe('Execution Environment', () => { it('New static call call should fork execution environment correctly', () => { const executionEnvironment = initExecutionEnvironment(); - const newExecutionEnvironment = executionEnvironment.deriveEnvironmentForNestedStaticCall(AztecAddress.fromField(newAddress), calldata); + const newExecutionEnvironment = executionEnvironment.deriveEnvironmentForNestedStaticCall( + AztecAddress.fromField(newAddress), + calldata, + ); expect(newExecutionEnvironment).toEqual( allSameExcept(executionEnvironment, { diff --git a/yarn-project/simulator/src/avm/journal/nullifiers.ts b/yarn-project/simulator/src/avm/journal/nullifiers.ts index f26cbdf4fa5..1360f52b35a 100644 --- a/yarn-project/simulator/src/avm/journal/nullifiers.ts +++ b/yarn-project/simulator/src/avm/journal/nullifiers.ts @@ -1,8 +1,8 @@ +import { AztecAddress } from '@aztec/circuits.js'; import { siloNullifier } from '@aztec/circuits.js/hash'; import { Fr } from '@aztec/foundation/fields'; import type { CommitmentsDB } from '../../index.js'; -import { AztecAddress } from '@aztec/circuits.js'; /** * A class to manage new nullifier staging and existence checks during a contract call's AVM simulation. @@ -51,7 +51,9 @@ export class Nullifiers { let leafIndex: bigint | undefined = undefined; if (!existsAsPending) { // silo the nullifier before checking for its existence in the host - leafIndex = await this.hostNullifiers.getNullifierIndex(siloNullifier(AztecAddress.fromField(storageAddress), nullifier)); + leafIndex = await this.hostNullifiers.getNullifierIndex( + siloNullifier(AztecAddress.fromField(storageAddress), nullifier), + ); } const exists = existsAsPending || leafIndex !== undefined; leafIndex = leafIndex === undefined ? BigInt(0) : leafIndex; diff --git a/yarn-project/simulator/src/avm/journal/public_storage.ts b/yarn-project/simulator/src/avm/journal/public_storage.ts index 566ff4abb93..8713cd7cb8e 100644 --- a/yarn-project/simulator/src/avm/journal/public_storage.ts +++ b/yarn-project/simulator/src/avm/journal/public_storage.ts @@ -1,7 +1,7 @@ +import { AztecAddress } from '@aztec/circuits.js'; import { Fr } from '@aztec/foundation/fields'; import type { PublicStateDB } from '../../index.js'; -import { AztecAddress } from '@aztec/circuits.js'; /** * A class to manage public storage reads and writes during a contract call's AVM simulation. From d07cd6a05096c0f9ad1312064e3c55fcbd2386b7 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 9 Apr 2024 08:50:16 +0000 Subject: [PATCH 50/77] l1 contracts ci --- l1-contracts/test/portals/TokenPortal.sol | 2 +- l1-contracts/test/portals/TokenPortal.t.sol | 4 ++-- l1-contracts/test/portals/UniswapPortal.t.sol | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/l1-contracts/test/portals/TokenPortal.sol b/l1-contracts/test/portals/TokenPortal.sol index dee5749b6b5..1553673d1ef 100644 --- a/l1-contracts/test/portals/TokenPortal.sol +++ b/l1-contracts/test/portals/TokenPortal.sol @@ -117,7 +117,7 @@ contract TokenPortal { _amount, _withCaller ? msg.sender : address(0) ) - ) + ) }); IOutbox outbox = registry.getOutbox(); diff --git a/l1-contracts/test/portals/TokenPortal.t.sol b/l1-contracts/test/portals/TokenPortal.t.sol index b1aa83db59f..550afbe5bc8 100644 --- a/l1-contracts/test/portals/TokenPortal.t.sol +++ b/l1-contracts/test/portals/TokenPortal.t.sol @@ -83,7 +83,7 @@ contract TokenPortalTest is Test { abi.encodeWithSignature( "mint_private(bytes32,uint256)", secretHashForRedeemingMintedNotes, amount ) - ), + ), secretHash: secretHashForL2MessageConsumption }); } @@ -161,7 +161,7 @@ contract TokenPortalTest is Test { abi.encodeWithSignature( "withdraw(address,uint256,address)", recipient, withdrawAmount, _designatedCaller ) - ) + ) }) ); diff --git a/l1-contracts/test/portals/UniswapPortal.t.sol b/l1-contracts/test/portals/UniswapPortal.t.sol index 7a16abbf3d3..b525e78a494 100644 --- a/l1-contracts/test/portals/UniswapPortal.t.sol +++ b/l1-contracts/test/portals/UniswapPortal.t.sol @@ -80,7 +80,7 @@ contract UniswapPortalTest is Test { recipient: DataStructures.L1Actor(address(daiTokenPortal), block.chainid), content: Hash.sha256ToField( abi.encodeWithSignature("withdraw(address,uint256,address)", _recipient, amount, _caller) - ) + ) }); return message.sha256ToField(); @@ -112,7 +112,7 @@ contract UniswapPortalTest is Test { secretHash, _caller ) - ) + ) }); return message.sha256ToField(); @@ -143,7 +143,7 @@ contract UniswapPortalTest is Test { secretHash, _caller ) - ) + ) }); return message.sha256ToField(); From b2f852956ab6de05811370c1fee5e2255a374e23 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 9 Apr 2024 15:19:01 +0000 Subject: [PATCH 51/77] ci ?? --- docs/docs/misc/migration_notes.md | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/docs/docs/misc/migration_notes.md b/docs/docs/misc/migration_notes.md index be25bc49b4c..599439d9f71 100644 --- a/docs/docs/misc/migration_notes.md +++ b/docs/docs/misc/migration_notes.md @@ -6,6 +6,20 @@ keywords: [sandbox, cli, aztec, notes, migration, updating, upgrading] Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them. +## TBD + +### [Aztec.nr] [Aztec.js] IsEmpty / IsZero have been unified and renamed to IsDefault + +N.B: Fields and Addresses have not been changed + +```diff +- Point.ZERO; ++ Point.default(); + +- Header::empty(); ++ Header::default(); +``` + ## 0.33 ### [Aztec.nr] Storage struct annotation @@ -67,18 +81,6 @@ It is not possible to call `simulate` on any call to get the return values! However, beware that it currently always returns a Field array of size 4 for private and public. This will change to become similar to the return values of the `unconstrained` functions with proper return types. -### [Aztec.nr] [Aztec.js] IsEmpty / IsZero have been unified and renamed to IsDefault - -N.B: Fields and Addresses have not been changed - -```diff -- Point.ZERO; -+ Point.default(); - -- Header::empty(); -+ Header::default(); -``` - ```diff - #[aztec(private)] - fn get_shared_immutable_constrained_private() -> pub Leader { From 651f174ad15fe829bf8a6b6373eabdf322342e39 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 9 Apr 2024 15:47:30 +0000 Subject: [PATCH 52/77] finally --- .../src/structs/__snapshots__/function_data.test.ts.snap | 2 +- .../circuits.js/src/structs/__snapshots__/header.test.ts.snap | 2 +- .../structs/__snapshots__/private_call_stack_item.test.ts.snap | 2 +- .../__snapshots__/private_circuit_public_inputs.test.ts.snap | 2 +- .../__snapshots__/public_circuit_public_inputs.test.ts.snap | 2 +- .../src/structs/__snapshots__/tx_context.test.ts.snap | 2 +- .../circuits.js/src/structs/private_call_stack_item.test.ts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/function_data.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/function_data.test.ts.snap index f0abf4311e2..44b1eb5d4a9 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/function_data.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/function_data.test.ts.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`FunctionData computes empty inputs hash 1`] = `Fr<0x27b1d0839a5b23baf12a8d195b18ac288fcf401afb2f70b8a4b529ede5fa9fed>`; +exports[`FunctionData computes default inputs hash 1`] = `Fr<0x27b1d0839a5b23baf12a8d195b18ac288fcf401afb2f70b8a4b529ede5fa9fed>`; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap index 2575fdd8f35..75f91f6a945 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Header computes empty hash 1`] = `Fr<0x2a45c01b78a6b9a2392b7490966b41f47e5d9ac95610fa3eabe99d9aec7f6ad0>`; +exports[`Header computes default hash 1`] = `Fr<0x2a45c01b78a6b9a2392b7490966b41f47e5d9ac95610fa3eabe99d9aec7f6ad0>`; exports[`Header computes hash 1`] = `Fr<0x26c31c3eb93ca2ac5d43166895960b259839bf6947f23f77cea1e729892f5ad9>`; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap index dc69d2469ce..e1951e4645b 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PrivateCallStackItem computes empty item hash 1`] = `Fr<0x13f518365c690d1b96d31454afed495ad29fe530939caf7189dd44f9bd63ef89>`; +exports[`PrivateCallStackItem computes default item hash 1`] = `Fr<0x13f518365c690d1b96d31454afed495ad29fe530939caf7189dd44f9bd63ef89>`; exports[`PrivateCallStackItem computes hash 1`] = `Fr<0x1b1f2424b9b38679cd1520ad44392630ac60f1efd1e73e5a0682d999fdee5f91>`; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap index 58d9e7531c1..17631e43ca5 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PrivateCircuitPublicInputs computes empty inputs hash 1`] = `Fr<0x1304e6c42e3c53fc7c918cbf1ea70333b4f214726c0784cf9878cd641967dab1>`; +exports[`PrivateCircuitPublicInputs computes default inputs hash 1`] = `Fr<0x1304e6c42e3c53fc7c918cbf1ea70333b4f214726c0784cf9878cd641967dab1>`; exports[`PrivateCircuitPublicInputs hash matches snapshot 1`] = `Fr<0x050d0062a1ae46c0b45e57eb2bc730328474255040eaddfc93d564071e386c86>`; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap index 96c773f7947..8b4a49b676f 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PublicCircuitPublicInputs computes empty item hash 1`] = `Fr<0x0f1eb4e352e8dab6cbab3c63b6d8f3cd2cd90cc7ae5ff142e4dfa2b3e28e01c1>`; +exports[`PublicCircuitPublicInputs computes default item hash 1`] = `Fr<0x0f1eb4e352e8dab6cbab3c63b6d8f3cd2cd90cc7ae5ff142e4dfa2b3e28e01c1>`; exports[`PublicCircuitPublicInputs hash matches snapshot 1`] = `Fr<0x0acad66a97a2ab5e0e4e916f95ed5921766762cf85b5c2db29ec0edcba06d63c>`; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/tx_context.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/tx_context.test.ts.snap index 981e17e3f15..add07aabf14 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/tx_context.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/tx_context.test.ts.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`TxContext computes empty hash 1`] = `Fr<0x200569267c0f73ac89aaa414239398db9445dd4ad3a8cf37015cd55b8d4c5e8d>`; +exports[`TxContext computes default hash 1`] = `Fr<0x200569267c0f73ac89aaa414239398db9445dd4ad3a8cf37015cd55b8d4c5e8d>`; diff --git a/yarn-project/circuits.js/src/structs/private_call_stack_item.test.ts b/yarn-project/circuits.js/src/structs/private_call_stack_item.test.ts index d7c979433c7..e2515c5d00a 100644 --- a/yarn-project/circuits.js/src/structs/private_call_stack_item.test.ts +++ b/yarn-project/circuits.js/src/structs/private_call_stack_item.test.ts @@ -37,7 +37,7 @@ describe('PrivateCallStackItem', () => { expect(hash).toMatchSnapshot(); }); - it('computes empty item hash', () => { + it('computes default item hash', () => { const item = PrivateCallStackItem.default(); const hash = item.hash(); expect(hash).toMatchSnapshot(); From 38e7527a198da5700272dd825c3209cbbd02bb52 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 9 Apr 2024 19:38:16 +0000 Subject: [PATCH 53/77] test --- .../aztec-nr/authwit/src/entrypoint/app.nr | 4 +-- .../aztec-nr/authwit/src/entrypoint/fee.nr | 4 +-- .../aztec/src/context/private_context.nr | 4 +-- noir-projects/aztec-nr/aztec/src/deploy.nr | 4 +-- .../aztec-nr/aztec/src/initializer.nr | 6 ++--- .../contracts/card_game_contract/src/game.nr | 4 +-- .../token_blacklist_contract/src/main.nr | 5 ++-- .../contracts/token_contract/src/main.nr | 4 +-- .../crates/private-kernel-lib/src/common.nr | 4 +-- .../crates/types/src/abis/caller_context.nr | 4 +-- .../crates/types/src/abis/global_variables.nr | 2 +- .../crates/types/src/abis/read_request.nr | 2 +- .../crates/types/src/address/aztec_address.nr | 26 ++++++++----------- .../crates/types/src/tests/fixtures.nr | 2 +- .../crates/types/src/traits.nr | 18 ++++++++++++- 15 files changed, 53 insertions(+), 40 deletions(-) diff --git a/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr b/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr index 33e1c7c2fa3..d65334c6b02 100644 --- a/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr +++ b/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr @@ -1,5 +1,5 @@ use dep::aztec::prelude::PrivateContext; -use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize}}; +use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize, is_zero}}; use crate::entrypoint::function_call::{FunctionCall, FUNCTION_CALL_SIZE_IN_BYTES}; @@ -56,7 +56,7 @@ impl AppPayload { // docs:start:entrypoint-execute-calls fn execute_calls(self, context: &mut PrivateContext) { for call in self.function_calls { - if !call.target_address.is_zero() { + if !is_zero(call.target_address) { if call.is_public { context.call_public_function_with_packed_args( call.target_address, diff --git a/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr b/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr index 827dcc69c20..f4a238045e5 100644 --- a/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr +++ b/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr @@ -1,5 +1,5 @@ use dep::aztec::prelude::PrivateContext; -use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__FEE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize}}; +use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__FEE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize, is_zero}}; use crate::entrypoint::function_call::FunctionCall; // 2 * 4 (function call) + 1 @@ -52,7 +52,7 @@ impl FeePayload { fn execute_calls(self, context: &mut PrivateContext) { for call in self.function_calls { - if !call.target_address.is_zero() { + if !is_zero(call.target_address) { if call.is_public { context.call_public_function_with_packed_args( call.target_address, diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index f9de0291c38..7b19cf0ffe1 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -29,7 +29,7 @@ use dep::protocol_types::{ }, contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, grumpkin_private_key::GrumpkinPrivateKey, header::Header, - messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, traits::is_empty + messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, traits::{is_empty, is_zero} }; // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) @@ -122,7 +122,7 @@ impl PrivateContext { pub fn new(inputs: PrivateContextInputs, args_hash: Field) -> PrivateContext { let side_effect_counter = inputs.start_side_effect_counter; let mut min_revertible_side_effect_counter = 0; - if is_empty(inputs.call_context.msg_sender) { + if is_zero(inputs.call_context.msg_sender) { min_revertible_side_effect_counter = side_effect_counter; } PrivateContext { diff --git a/noir-projects/aztec-nr/aztec/src/deploy.nr b/noir-projects/aztec-nr/aztec/src/deploy.nr index 60f7fef0620..7a3988778ff 100644 --- a/noir-projects/aztec-nr/aztec/src/deploy.nr +++ b/noir-projects/aztec-nr/aztec/src/deploy.nr @@ -1,12 +1,12 @@ use crate::{context::PrivateContext, oracle::get_contract_instance::get_contract_instance}; -use dep::protocol_types::{address::AztecAddress, abis::function_selector::FunctionSelector, constants::DEPLOYER_CONTRACT_ADDRESS}; +use dep::protocol_types::{address::AztecAddress, abis::function_selector::FunctionSelector, constants::DEPLOYER_CONTRACT_ADDRESS, traits::is_zero}; // Calls `deploy` on the deployer contract to deploy a new instance. pub fn deploy_contract(context: &mut PrivateContext, target: AztecAddress) { let instance = get_contract_instance(target); - let universal_deploy = instance.deployer.is_zero(); + let universal_deploy = is_zero(instance.deployer); if !universal_deploy { assert( instance.deployer == context.this_address(), "Deployer address does not match current address" diff --git a/noir-projects/aztec-nr/aztec/src/initializer.nr b/noir-projects/aztec-nr/aztec/src/initializer.nr index 023b37106e1..8bd0b48febe 100644 --- a/noir-projects/aztec-nr/aztec/src/initializer.nr +++ b/noir-projects/aztec-nr/aztec/src/initializer.nr @@ -1,5 +1,5 @@ use dep::protocol_types::{ - address::AztecAddress, hash::{silo_nullifier, pedersen_hash}, + address::AztecAddress, hash::{silo_nullifier, pedersen_hash}, traits::is_zero, constants::GENERATOR_INDEX__CONSTRUCTOR, abis::function_selector::FunctionSelector }; @@ -65,7 +65,7 @@ pub fn assert_initialization_matches_address_preimage_avm(context: AvmContext) { let expected_init = compute_initialization_hash(context.selector(), context.get_args_hash()); assert(instance.initialization_hash == expected_init, "Initialization hash does not match"); assert( - (instance.deployer.is_zero()) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer" + (is_zero(instance.deployer)) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer" ); } @@ -79,7 +79,7 @@ fn assert_initialization_matches_address_preimage(context: TContext) w let expected_init = compute_initialization_hash(context.selector(), context.get_args_hash()); assert(instance.initialization_hash == expected_init, "Initialization hash does not match"); assert( - (instance.deployer.is_zero()) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer" + (is_zero(instance.deployer)) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer" ); } diff --git a/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr b/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr index 0003599559a..607ee77555a 100644 --- a/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr +++ b/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr @@ -1,4 +1,4 @@ -use dep::aztec::protocol_types::{address::AztecAddress, traits::{Serialize, Deserialize}}; +use dep::aztec::protocol_types::{address::AztecAddress, traits::{Serialize, Deserialize, is_zero}}; use crate::cards::Card; global NUMBER_OF_PLAYERS: u64 = 2; @@ -12,7 +12,7 @@ struct PlayerEntry { impl PlayerEntry { pub fn is_initialized(self) -> bool { - !self.address.is_zero() + !is_zero(self.address) } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr index cfad6717cc9..43461b39a46 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr @@ -18,7 +18,8 @@ contract TokenBlacklist { use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress}; use dep::aztec::{ note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader}, - hash::compute_secret_hash, state_vars::{Map, PublicMutable, PrivateSet, SharedImmutable} + hash::compute_secret_hash, state_vars::{Map, PublicMutable, PrivateSet, SharedImmutable}, + protocol_types::traits::is_zero }; use dep::field_note::field_note::FieldNote; @@ -45,7 +46,7 @@ contract TokenBlacklist { #[aztec(initializer)] fn constructor(admin: AztecAddress, slow_updates_contract: AztecAddress) { // docs:end:constructor - assert(!admin.is_zero(), "invalid admin"); + assert(!is_zero(admin), "invalid admin"); storage.admin.write(admin); // docs:start:write_slow_update_public storage.slow_update.initialize(slow_updates_contract); diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr index 7924299b27c..dedac40ec75 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -18,7 +18,7 @@ contract Token { NoteGetterOptions, NoteHeader, Map, PublicMutable, SharedImmutable, PrivateSet, FunctionSelector, AztecAddress }; - use dep::aztec::hash::compute_secret_hash; + use dep::aztec::{hash::compute_secret_hash, protocol_types::traits::is_zero}; // docs:start:import_authwit use dep::authwit::{auth::{assert_current_call_valid_authwit, assert_current_call_valid_authwit_public}}; @@ -56,7 +56,7 @@ contract Token { #[aztec(public)] #[aztec(initializer)] fn constructor(admin: AztecAddress, name: str<31>, symbol: str<31>, decimals: u8) { - assert(!admin.is_zero(), "invalid admin"); + assert(!is_zero(admin), "invalid admin"); storage.admin.write(admin); storage.minters.at(admin).write(true); storage.name.initialize(FieldCompressedString::from_string(name)); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr index 791edcfeb99..88daff7f617 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr @@ -21,7 +21,7 @@ use dep::types::{ }, merkle_tree::check_membership, utils::{arrays::{array_length, array_to_bounded_vec, validate_array}}, - traits::{is_empty, is_empty_array} + traits::{is_empty, is_empty_array, is_zero} }; pub fn validate_arrays(app_public_inputs: PrivateCircuitPublicInputs) { @@ -311,7 +311,7 @@ pub fn contract_logic(private_call: PrivateCallData) { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3062): Why is this using a hash function from the stdlib::recursion namespace let private_call_vk_hash = stdlib_recursion_verification_key_compress_native_vk(private_call.vk); - assert(!contract_address.is_zero(), "contract address cannot be zero"); + assert(!is_zero(contract_address), "contract address cannot be zero"); // std::println(f"contract_address={contract_address}"); // std::println(f"private_call_vk_hash={private_call_vk_hash}"); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr index 829429e4e9e..f6b6f13c75e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr @@ -1,6 +1,6 @@ use crate::address::AztecAddress; use dep::std::cmp::Eq; -use crate::traits::Empty; +use crate::traits::{Empty, is_zero}; struct CallerContext { msg_sender: AztecAddress, @@ -25,6 +25,6 @@ impl Empty for CallerContext { impl CallerContext { pub fn is_empty(self) -> bool { - self.msg_sender.is_zero() & self.storage_contract_address.is_zero() + is_zero(self.msg_sender) & is_zero(self.storage_contract_address) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr index d636c867a3a..bcb242ca586 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr @@ -61,7 +61,7 @@ impl Empty for GlobalVariables { block_number: 0, timestamp: 0, coinbase: EthAddress::empty(), - fee_recipient: AztecAddress::empty(), + fee_recipient: AztecAddress::zero(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr index 1d6acb753f1..4ce713c069a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr @@ -98,7 +98,7 @@ impl Empty for ReadRequestContext { ReadRequestContext { value: 0, counter: 0, - contract_address: AztecAddress::empty(), + contract_address: AztecAddress::zero(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr index aab51f65593..ea542725f44 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr @@ -2,7 +2,7 @@ use crate::{ crate::address::{eth_address::EthAddress, partial_address::PartialAddress, public_keys_hash::PublicKeysHash}, constants::{AZTEC_ADDRESS_LENGTH, GENERATOR_INDEX__CONTRACT_ADDRESS}, contract_class_id::ContractClassId, hash::pedersen_hash, grumpkin_point::GrumpkinPoint, - traits::{Empty, ToField, Serialize, Deserialize}, utils + traits::{Zero, ToField, Serialize, Deserialize}, utils }; // Aztec address @@ -16,14 +16,22 @@ impl Eq for AztecAddress { } } -impl Empty for AztecAddress { - fn empty() -> Self { +impl Zero for AztecAddress { + fn zero() -> Self { Self { inner : 0 } } } +// This is implemented so we have one trait for everything "default", or otherwise known as the "undefined" value, +// this helps with things such as the array helper +impl Default for AztecAddress { + fn default() -> Self { + AztecAddress::zero() + } +} + impl ToField for AztecAddress { fn to_field(self) -> Field { self.inner @@ -43,10 +51,6 @@ impl Deserialize for AztecAddress { } impl AztecAddress { - pub fn zero() -> Self { - Self { inner: 0 } - } - pub fn from_field(field: Field) -> Self { Self { inner: field } } @@ -80,14 +84,6 @@ impl AztecAddress { ) } - pub fn is_zero(self) -> bool { - self.inner == 0 - } - - pub fn assert_is_zero(self) { - assert(self.to_field() == 0); - } - pub fn conditional_assign(predicate: bool, lhs: Self, rhs: Self) -> Self { let result = utils::conditional_assign(predicate, rhs.to_field(), lhs.to_field()); Self { inner: result } 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 f920bd17c30..bdce5ccfca7 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 @@ -26,7 +26,7 @@ fn empty_eth_address() -> EthAddress { // Workaround for https://github.com/noir-lang/noir/issues/1440 fn empty_aztec_address() -> AztecAddress { - AztecAddress::empty() + AztecAddress::zero() } // Workaround for https://github.com/noir-lang/noir/issues/1440 diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr index 70870f64d84..96e8bd85965 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr @@ -1,4 +1,4 @@ -use dep::std::cmp::Eq; +use dep::std::{default::Default,cmp::Eq}; // Trait: is_empty // @@ -31,6 +31,22 @@ pub fn is_empty_array(array: [T; N]) -> bool where T: Empty + Eq { array.all(|elem| is_empty(elem)) } +pub fn is_default(item: T) -> bool where T: Default + Eq { + item.eq(T::default()) +} + +pub fn is_default_array(array: [T; N]) -> bool where T: Default + Eq { + array.all(|elem| is_default(elem)) +} + +trait Zero { + fn zero() -> Self; +} + +pub fn is_zero(item: T) -> bool where T: Zero + Eq { + item.eq(T::zero()) +} + trait Hash { fn hash(self) -> Field; } From 973e59c957022f76514de4bccfedfe2deecffebc Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 9 Apr 2024 19:51:45 +0000 Subject: [PATCH 54/77] next --- .../contracts/uniswap_contract/src/main.nr | 9 ++++--- .../crates/types/src/abis/global_variables.nr | 2 +- .../crates/types/src/address/eth_address.nr | 26 ++++++++----------- .../types/src/messaging/l2_to_l1_message.nr | 2 +- .../crates/types/src/tests/fixtures.nr | 2 +- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr index 7a7c68c5fe3..9ff46f4b3ca 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr @@ -9,6 +9,7 @@ contract Uniswap { use dep::aztec::prelude::{FunctionSelector, AztecAddress, EthAddress, Map, PublicMutable}; use dep::aztec::oracle::context::get_portal_address; use dep::aztec::context::gas::GasOpts; + use dep::aztec::protocol_types::traits::is_zero; use dep::authwit::auth::{ IS_VALID_SELECTOR, assert_current_call_valid_authwit_public, compute_call_authwit_hash, @@ -76,10 +77,10 @@ contract Uniswap { let output_asset_bridge_portal_address = get_portal_address(output_asset_bridge); // ensure portal exists - else funds might be lost assert( - !input_asset_bridge_portal_address.is_zero(), "L1 portal address of input_asset's bridge is 0" + !is_zero(input_asset_bridge_portal_address), "L1 portal address of input_asset's bridge is 0" ); assert( - !output_asset_bridge_portal_address.is_zero(), "L1 portal address of output_asset's bridge is 0" + !is_zero(output_asset_bridge_portal_address), "L1 portal address of output_asset's bridge is 0" ); let content_hash = compute_swap_public_content_hash( @@ -143,10 +144,10 @@ contract Uniswap { let output_asset_bridge_portal_address = get_portal_address(output_asset_bridge); // ensure portal exists - else funds might be lost assert( - !input_asset_bridge_portal_address.is_zero(), "L1 portal address of input_asset's bridge is 0" + !is_zero(input_asset_bridge_portal_address), "L1 portal address of input_asset's bridge is 0" ); assert( - !output_asset_bridge_portal_address.is_zero(), "L1 portal address of output_asset's bridge is 0" + !is_zero(output_asset_bridge_portal_address), "L1 portal address of output_asset's bridge is 0" ); let content_hash = compute_swap_private_content_hash( diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr index bcb242ca586..f3aac1777ef 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr @@ -60,7 +60,7 @@ impl Empty for GlobalVariables { version: 0, block_number: 0, timestamp: 0, - coinbase: EthAddress::empty(), + coinbase: EthAddress::zero(), fee_recipient: AztecAddress::zero(), } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr index 77a93ce26de..343a882af83 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr @@ -1,6 +1,6 @@ use crate::{ constants::ETH_ADDRESS_LENGTH, hash::pedersen_hash, - traits::{Empty, ToField, Serialize, Deserialize}, utils + traits::{ToField, Serialize, Deserialize, Zero}, utils }; struct EthAddress{ @@ -13,14 +13,22 @@ impl Eq for EthAddress { } } -impl Empty for EthAddress { - fn empty() -> Self { +impl Zero for EthAddress { + fn zero() -> Self { Self { inner : 0 } } } +// This is implemented so we have one trait for everything "default", or otherwise known as the "undefined" value, +// this helps with things such as the array helper +impl Default for EthAddress { + fn default() -> Self { + EthAddress::zero() + } +} + impl ToField for EthAddress { fn to_field(self) -> Field { self.inner @@ -40,23 +48,11 @@ impl Deserialize for EthAddress { } impl EthAddress { - pub fn zero() -> Self { - Self { inner: 0 } - } - pub fn from_field(field: Field) -> Self { field.assert_max_bit_size(160); Self { inner: field } } - pub fn is_zero(self) -> bool { - self.inner == 0 - } - - pub fn assert_is_zero(self) { - assert(self.to_field() == 0); - } - pub fn conditional_assign(predicate: bool, lhs: Self, rhs: Self) -> Self { let result = utils::conditional_assign(predicate, rhs.to_field(), lhs.to_field()); Self { inner: result } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr index 928239bf935..39ea711d09f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr @@ -9,7 +9,7 @@ struct L2ToL1Message { impl Empty for L2ToL1Message { fn empty() -> Self { Self { - recipient: EthAddress::empty(), + recipient: EthAddress::zero(), content: 0, } } 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 bdce5ccfca7..4a138e97e11 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 @@ -21,7 +21,7 @@ fn empty_append_only_tree() -> AppendOnlyTreeSnapshot { // Workaround for https://github.com/noir-lang/noir/issues/1440 fn empty_eth_address() -> EthAddress { - EthAddress::empty() + EthAddress::zero() } // Workaround for https://github.com/noir-lang/noir/issues/1440 From dd211ae669b069e7aaf4590ba17a7f137f925af1 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 9 Apr 2024 20:15:13 +0000 Subject: [PATCH 55/77] noteheader --- noir-projects/aztec-nr/address-note/src/address_note.nr | 2 +- noir-projects/aztec-nr/aztec/src/note/note_header.nr | 7 ++++--- noir-projects/aztec-nr/field-note/src/field_note.nr | 2 +- noir-projects/aztec-nr/tests/src/mock/test_note.nr | 4 ++-- noir-projects/aztec-nr/value-note/src/value_note.nr | 2 +- .../app_subscription_contract/src/subscription_note.nr | 2 +- .../contracts/docs_example_contract/src/types/card_note.nr | 2 +- .../ecdsa_account_contract/src/ecdsa_public_key_note.nr | 4 ++-- .../schnorr_account_contract/src/public_key_note.nr | 2 +- .../token_blacklist_contract/src/types/token_note.nr | 2 +- .../token_blacklist_contract/src/types/transparent_note.nr | 6 +++--- .../contracts/token_contract/src/types/token_note.nr | 2 +- .../contracts/token_contract/src/types/transparent_note.nr | 6 +++--- .../aztec_macros/src/transforms/note_interface.rs | 2 +- 14 files changed, 23 insertions(+), 22 deletions(-) diff --git a/noir-projects/aztec-nr/address-note/src/address_note.nr b/noir-projects/aztec-nr/address-note/src/address_note.nr index 048cd2f5033..babcbb18784 100644 --- a/noir-projects/aztec-nr/address-note/src/address_note.nr +++ b/noir-projects/aztec-nr/address-note/src/address_note.nr @@ -62,7 +62,7 @@ impl NoteInterface for AddressNote { impl AddressNote { pub fn new(address: AztecAddress, owner: AztecAddress) -> Self { let randomness = unsafe_rand(); - AddressNote { address, owner, randomness, header: NoteHeader::empty() } + AddressNote { address, owner, randomness, header: NoteHeader::default() } } // docs:end:address_note_def } diff --git a/noir-projects/aztec-nr/aztec/src/note/note_header.nr b/noir-projects/aztec-nr/aztec/src/note/note_header.nr index 27f81945c6a..fb95c561a76 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_header.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_header.nr @@ -1,5 +1,6 @@ use dep::protocol_types::address::AztecAddress; -use dep::protocol_types::traits::{Empty, Serialize}; +use dep::protocol_types::traits::Serialize; +use dep::std::default::Default; struct NoteHeader { contract_address: AztecAddress, @@ -10,8 +11,8 @@ struct NoteHeader { is_transient: bool, } -impl Empty for NoteHeader { - fn empty() -> Self { +impl Default for NoteHeader { + fn default() -> Self { NoteHeader { contract_address: AztecAddress::zero(), nonce: 0, storage_slot: 0, is_transient: false } } } diff --git a/noir-projects/aztec-nr/field-note/src/field_note.nr b/noir-projects/aztec-nr/field-note/src/field_note.nr index f6350ddd613..654d5806c98 100644 --- a/noir-projects/aztec-nr/field-note/src/field_note.nr +++ b/noir-projects/aztec-nr/field-note/src/field_note.nr @@ -34,7 +34,7 @@ impl NoteInterface for FieldNote { impl FieldNote { pub fn new(value: Field) -> Self { - FieldNote { value, header: NoteHeader::empty() } + FieldNote { value, header: NoteHeader::default() } } } diff --git a/noir-projects/aztec-nr/tests/src/mock/test_note.nr b/noir-projects/aztec-nr/tests/src/mock/test_note.nr index bc4f262550f..9bc70eead23 100644 --- a/noir-projects/aztec-nr/tests/src/mock/test_note.nr +++ b/noir-projects/aztec-nr/tests/src/mock/test_note.nr @@ -19,7 +19,7 @@ impl NoteInterface for TestNote { fn deserialize_content(fields: [Field; TEST_NOTE_LENGTH]) -> Self { Self { value: fields[0], - header: NoteHeader::empty(), + header: NoteHeader::default(), } } @@ -56,6 +56,6 @@ impl NoteInterface for TestNote { impl TestNote { pub fn new(value: Field) -> Self { - TestNote { value, header: NoteHeader::empty() } + TestNote { value, header: NoteHeader::default() } } } diff --git a/noir-projects/aztec-nr/value-note/src/value_note.nr b/noir-projects/aztec-nr/value-note/src/value_note.nr index 4598c1ab17b..fa0d73275d7 100644 --- a/noir-projects/aztec-nr/value-note/src/value_note.nr +++ b/noir-projects/aztec-nr/value-note/src/value_note.nr @@ -60,7 +60,7 @@ impl NoteInterface for ValueNote { impl ValueNote { pub fn new(value: Field, owner: AztecAddress) -> Self { let randomness = unsafe_rand(); - let header = NoteHeader::empty(); + let header = NoteHeader::default(); ValueNote { value, owner, randomness, header } } } diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr index c541c92ae39..2ce1b491159 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr @@ -54,6 +54,6 @@ impl NoteInterface for SubscriptionNote { impl SubscriptionNote { pub fn new(owner: AztecAddress, expiry_block_number: Field, remaining_txs: Field) -> Self { - SubscriptionNote { owner, expiry_block_number, remaining_txs, header: NoteHeader::empty() } + SubscriptionNote { owner, expiry_block_number, remaining_txs, header: NoteHeader::default() } } } diff --git a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr index f66b855485a..81f91f677be 100644 --- a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr +++ b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr @@ -20,7 +20,7 @@ struct CardNote { impl CardNote { pub fn new(points: u8, randomness: Field, owner: AztecAddress) -> Self { - CardNote { points, randomness, owner, header: NoteHeader::empty() } + CardNote { points, randomness, owner, header: NoteHeader::default() } } } diff --git a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr index cd25fa907da..a883eb96ce9 100644 --- a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr @@ -63,7 +63,7 @@ impl NoteInterface for EcdsaPublicKeyNote { } y[31] = serialized_note[3].to_be_bytes(32)[31]; - EcdsaPublicKeyNote { x, y, owner: AztecAddress::from_field(serialized_note[4]), header: NoteHeader::empty() } + EcdsaPublicKeyNote { x, y, owner: AztecAddress::from_field(serialized_note[4]), header: NoteHeader::default() } } fn compute_nullifier(self, context: &mut PrivateContext) -> Field { @@ -104,6 +104,6 @@ impl NoteInterface for EcdsaPublicKeyNote { impl EcdsaPublicKeyNote { pub fn new(x: [u8; 32], y: [u8; 32], owner: AztecAddress) -> Self { - EcdsaPublicKeyNote { x, y, owner, header: NoteHeader::empty() } + EcdsaPublicKeyNote { x, y, owner, header: NoteHeader::default() } } } diff --git a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr index f78ad778189..36f5dd3c1b2 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr @@ -54,6 +54,6 @@ impl NoteInterface for PublicKeyNote { impl PublicKeyNote { pub fn new(x: Field, y: Field, owner: AztecAddress) -> Self { - PublicKeyNote { x, y, owner, header: NoteHeader::empty() } + PublicKeyNote { x, y, owner, header: NoteHeader::default() } } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr index 765f9203368..62fd7689608 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr @@ -70,7 +70,7 @@ impl OwnedNote for TokenNote { amount, owner, randomness: unsafe_rand(), - header: NoteHeader::empty(), + header: NoteHeader::default(), } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr index 80748a32375..9e265ffe939 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr @@ -35,7 +35,7 @@ impl NoteInterface for TransparentNote { amount: serialized_note[0], secret_hash: serialized_note[1], secret: 0, - header: NoteHeader::empty(), + header: NoteHeader::default(), } } @@ -59,13 +59,13 @@ impl TransparentNote { // CONSTRUCTORS pub fn new(amount: Field, secret_hash: Field) -> Self { - TransparentNote { amount, secret_hash, secret: 0, header: NoteHeader::empty() } + TransparentNote { amount, secret_hash, secret: 0, header: NoteHeader::default() } } // new oracle call primitive // get me the secret corresponding to this hash pub fn new_from_secret(amount: Field, secret: Field) -> Self { - TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: NoteHeader::empty() } + TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: NoteHeader::default() } } // CUSTOM FUNCTIONS FOR THIS NOTE TYPE diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr index 9a336e4baa9..8b29bf88b17 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr @@ -73,7 +73,7 @@ impl OwnedNote for TokenNote { amount, owner, randomness: unsafe_rand(), - header: NoteHeader::empty(), + header: NoteHeader::default(), } } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr index dfc106d2c13..b2237c3d498 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr @@ -35,7 +35,7 @@ impl NoteInterface for TransparentNote { amount: serialized_note[0], secret_hash: serialized_note[1], secret: 0, - header: NoteHeader::empty(), + header: NoteHeader::default(), } } @@ -59,13 +59,13 @@ impl TransparentNote { // CONSTRUCTORS pub fn new(amount: Field, secret_hash: Field) -> Self { - TransparentNote { amount, secret_hash, secret: 0, header: NoteHeader::empty() } + TransparentNote { amount, secret_hash, secret: 0, header: NoteHeader::default() } } // new oracle call primitive // get me the secret corresponding to this hash pub fn new_from_secret(amount: Field, secret: Field) -> Self { - TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: NoteHeader::empty() } + TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: NoteHeader::default() } } // CUSTOM FUNCTIONS FOR THIS NOTE TYPE diff --git a/noir/noir-repo/aztec_macros/src/transforms/note_interface.rs b/noir/noir-repo/aztec_macros/src/transforms/note_interface.rs index 0514155824e..e58134f8846 100644 --- a/noir/noir-repo/aztec_macros/src/transforms/note_interface.rs +++ b/noir/noir-repo/aztec_macros/src/transforms/note_interface.rs @@ -594,7 +594,7 @@ fn generate_note_deserialize_content_source( } } else { format!( - "{}: dep::aztec::note::note_header::NoteHeader::empty()", + "{}: dep::aztec::note::note_header::NoteHeader::default()", note_header_field_name ) } From d89868c261ad5061de5417eb2ba5a7e6ee20107e Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 9 Apr 2024 20:29:56 +0000 Subject: [PATCH 56/77] good --- .../aztec-nr/aztec/src/context/avm_context.nr | 2 +- .../globals/private_global_variables.nr | 9 ++++ .../context/inputs/private_context_inputs.nr | 11 +++++ .../aztec/src/context/private_context.nr | 2 +- .../crates/types/src/abis/call_context.nr | 43 +++++++++++-------- .../crates/types/src/header.nr | 33 +++++++------- 6 files changed, 63 insertions(+), 37 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/avm_context.nr b/noir-projects/aztec-nr/aztec/src/context/avm_context.nr index 8f7a0193349..2058188ab44 100644 --- a/noir-projects/aztec-nr/aztec/src/context/avm_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/avm_context.nr @@ -208,7 +208,7 @@ impl ContextInterface for AvmContext { } fn get_header(self) -> Header { assert(false, "'get_header' not implemented!"); - Header::empty() + Header::default() } fn get_args_hash(self) -> Field { self.inputs.args_hash diff --git a/noir-projects/aztec-nr/aztec/src/context/globals/private_global_variables.nr b/noir-projects/aztec-nr/aztec/src/context/globals/private_global_variables.nr index 99126a10dbf..b918db9645a 100644 --- a/noir-projects/aztec-nr/aztec/src/context/globals/private_global_variables.nr +++ b/noir-projects/aztec-nr/aztec/src/context/globals/private_global_variables.nr @@ -9,6 +9,15 @@ struct PrivateGlobalVariables { } // docs:end:private-global-variables +impl Default for PrivateGlobalVariables { + fn default() -> Self { + PrivateGlobalVariables { + chain_id: 0, + version: 0, + } + } +} + // Note: public global vars are equal to the private ones impl Serialize for PrivateGlobalVariables { fn serialize(self) -> [Field; PRIVATE_GLOBAL_VARIABLES_LENGTH] { diff --git a/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr b/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr index 79523b9affc..5f2b89670d8 100644 --- a/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr +++ b/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr @@ -10,3 +10,14 @@ struct PrivateContextInputs { start_side_effect_counter: u32, } // docs:end:private-context-inputs + +impl Default for PrivateContextInputs { + fn default() -> Self { + PrivateContextInputs { + call_context : CallContext::default(), + historical_header: Header::default(), + private_global_variables: PrivateGlobalVariables::default(), + start_side_effect_counter: 0 as u32, + } + } +} diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 7b19cf0ffe1..0fdb1735006 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -473,7 +473,7 @@ impl PrivateContext { end_side_effect_counter: 0, unencrypted_logs_hash: 0, unencrypted_log_preimages_length: 0, - historical_header: Header::empty(), + historical_header: Header::default(), prover_address: AztecAddress::zero(), revert_code: 0 }, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr index f8185f89aed..35ab9751f04 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr @@ -1,8 +1,9 @@ use crate::{ abis::function_selector::FunctionSelector, address::{EthAddress, AztecAddress}, constants::{CALL_CONTEXT_LENGTH, GENERATOR_INDEX__CALL_CONTEXT}, hash::pedersen_hash, - traits::{Deserialize, Hash, Serialize}, abis::side_effect::Ordered + traits::{Deserialize, Hash, Serialize, is_default}, abis::side_effect::Ordered }; +use dep::std::default::Default; // docs:start:call-context struct CallContext { @@ -19,12 +20,16 @@ struct CallContext { } // docs:end:call-context -impl CallContext { - fn assert_is_zero(self) { - let serialized: [Field; CALL_CONTEXT_LENGTH] = self.serialize(); - - for i in 0..CALL_CONTEXT_LENGTH { - assert(serialized[i] == 0); +impl Default for CallContext { + fn default() -> Self { + CallContext { + msg_sender: AztecAddress::default(), + storage_contract_address: AztecAddress::default(), + portal_contract_address: EthAddress::default(), + function_selector: FunctionSelector::zero(), + is_delegate_call: false, + is_static_call: false, + side_effect_counter: 0, } } } @@ -71,29 +76,29 @@ impl Deserialize for CallContext { #[test] fn serialize_deserialize_of_empty() { - let context: CallContext = dep::std::unsafe::zeroed(); + let context = CallContext::default(); let serialized = context.serialize(); let deserialized = CallContext::deserialize(serialized); assert(context.eq(deserialized)); } #[test] -fn assert_is_zero() { - let context: CallContext = dep::std::unsafe::zeroed(); - context.assert_is_zero(); +fn test_is_default() { + let context = CallContext::default(); + assert(is_default(context), true); } #[test(should_fail)] -fn not_zero_assert_is_zero() { - let mut context: CallContext = dep::std::unsafe::zeroed(); +fn test_not_default() { + let mut context = CallContext::default(); context.is_delegate_call = true; - context.assert_is_zero(); + assert(is_default(context), true); } #[test] fn test_eq() { - let mut context1: CallContext = dep::std::unsafe::zeroed(); - let mut context2: CallContext = dep::std::unsafe::zeroed(); + let mut context1 = CallContext::default(); + let mut context2 = CallContext::default(); context1.is_delegate_call = true; context2.is_delegate_call = true; @@ -107,8 +112,8 @@ fn test_eq() { #[test(should_fail)] fn not_eq_test_eq() { - let mut context1: CallContext = dep::std::unsafe::zeroed(); - let mut context2: CallContext = dep::std::unsafe::zeroed(); + let mut context1 = CallContext::default(); + let mut context2 = CallContext::default(); context1.is_delegate_call = true; context2.is_delegate_call = false; @@ -124,6 +129,6 @@ fn not_eq_test_eq() { #[test] fn hash_smoke() { - let context: CallContext = dep::std::unsafe::zeroed(); + let context = CallContext::default(); let _hashed = context.hash(); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr index b6b7a9695bd..2dff0192f09 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr @@ -4,9 +4,10 @@ use crate::{ global_variables::{GlobalVariables, GLOBAL_VARIABLES_LENGTH} }, constants::{GENERATOR_INDEX__BLOCK_HASH, HEADER_LENGTH, STATE_REFERENCE_LENGTH, CONTENT_COMMITMENT_LENGTH}, - hash::pedersen_hash, state_reference::StateReference, traits::{Deserialize, Empty, Hash, Serialize}, + hash::pedersen_hash, state_reference::StateReference, traits::{Deserialize, Hash, Serialize}, utils::arr_copy_slice, content_commitment::ContentCommitment }; +use dep::std::default::Default; // docs:start:header struct Header { @@ -26,6 +27,17 @@ impl Eq for Header { } } +impl Default for Header { + fn default() -> Self { + Self { + last_archive: AppendOnlyTreeSnapshot::zero(), + content_commitment: ContentCommitment::empty(), + state: StateReference::empty(), + global_variables: GlobalVariables::empty(), + } + } +} + impl Serialize for Header { fn serialize(self) -> [Field; HEADER_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(); @@ -63,17 +75,6 @@ impl Deserialize for Header { } } -impl Empty for Header { - fn empty() -> Self { - Self { - last_archive: AppendOnlyTreeSnapshot::zero(), - content_commitment: ContentCommitment::empty(), - state: StateReference::empty(), - global_variables: GlobalVariables::empty(), - } - } -} - impl Hash for Header { fn hash(self) -> Field { pedersen_hash(self.serialize(), GENERATOR_INDEX__BLOCK_HASH) @@ -82,7 +83,7 @@ impl Hash for Header { #[test] fn serialization_of_empty() { - let header: Header = dep::std::unsafe::zeroed(); + let header = Header::default(); let serialized = header.serialize(); let deserialized = Header::deserialize(serialized); assert(header.eq(deserialized)); @@ -90,13 +91,13 @@ fn serialization_of_empty() { #[test] fn hash_smoke() { - let header: Header = dep::std::unsafe::zeroed(); + let header = Header::default(); let _hashed = header.hash(); } #[test] -fn empty_hash_is_zero() { - let header: Header = dep::std::unsafe::zeroed(); +fn empty_hash_is_default() { + let header = Header::default(); let hash = header.hash(); // Value from new_contract_data.test.ts "computes empty hash" test From 4d1d57618f1db88ee9b8d577960602209ec46a9b Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 9 Apr 2024 20:44:43 +0000 Subject: [PATCH 57/77] Success --- .../contracts/app_subscription_contract/src/main.nr | 2 -- .../contracts/fpc_contract/src/main.nr | 2 +- .../crates/private-kernel-lib/src/common.nr | 6 +++--- .../private-kernel-lib/src/private_kernel_inner.nr | 2 +- .../crates/public-kernel-lib/src/common.nr | 6 +++--- .../public-kernel-lib/src/public_kernel_setup.nr | 2 +- .../public-kernel-lib/src/public_kernel_teardown.nr | 2 +- .../private_accumulated_data_builder.nr | 6 +++--- .../crates/types/src/abis/call_request.nr | 2 +- .../crates/types/src/abis/caller_context.nr | 13 +++---------- .../crates/types/src/address/partial_address.nr | 4 ---- .../crates/types/src/address/public_keys_hash.nr | 4 ---- .../types/src/address/salted_initialization_hash.nr | 4 ---- .../crates/types/src/tests/fixture_builder.nr | 2 +- .../types/src/tests/private_call_data_builder.nr | 2 +- .../types/src/tests/public_call_data_builder.nr | 2 +- 16 files changed, 20 insertions(+), 41 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr index 37c2edf31b7..45a32dde06a 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr @@ -10,8 +10,6 @@ contract AppSubscription { SharedImmutable }; - use dep::aztec::protocol_types::traits::is_empty; - use dep::aztec::{context::Context, oracle::get_public_key::get_public_key}; use dep::authwit::{account::AccountActions, auth_witness::get_auth_witness, auth::assert_current_call_valid_authwit}; diff --git a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr index 6d70815c6e5..fe38de23538 100644 --- a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr @@ -1,7 +1,7 @@ mod interfaces; contract FPC { - use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress, traits::is_empty}; + use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress}; use dep::aztec::state_vars::SharedImmutable; use dep::aztec::context::gas::GasOpts; use crate::interfaces::Token; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr index 88daff7f617..a036c2ed507 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr @@ -21,7 +21,7 @@ use dep::types::{ }, merkle_tree::check_membership, utils::{arrays::{array_length, array_to_bounded_vec, validate_array}}, - traits::{is_empty, is_empty_array, is_zero} + traits::{is_empty, is_empty_array, is_zero, is_default} }; pub fn validate_arrays(app_public_inputs: PrivateCircuitPublicInputs) { @@ -148,7 +148,7 @@ fn is_valid_caller(request_from_stack: CallRequest, fn_being_verified: PrivateCa & request_from_stack.caller_context.storage_contract_address.eq(call_context.storage_contract_address); request_from_stack.caller_contract_address.eq(fn_being_verified.call_stack_item.contract_address) - & (request_from_stack.caller_context.is_empty() | valid_caller_context) + & (is_default(request_from_stack.caller_context) | valid_caller_context) } fn validate_call_requests( @@ -358,7 +358,7 @@ pub fn validate_call_against_request(private_call: PrivateCallData, request: Cal if call_context.is_delegate_call { let caller_context = request.caller_context; - assert(!caller_context.is_empty(), "caller context cannot be empty for delegate calls"); + assert(!is_default(caller_context), "caller context cannot be default for delegate calls"); assert( call_context.msg_sender.eq(caller_context.msg_sender), "call stack msg_sender does not match expected msg_sender for delegate calls" ); 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 4faf0831bf9..4b5d4ed901f 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 @@ -218,7 +218,7 @@ mod tests { builder.succeeded(); } - #[test(should_fail_with="caller context cannot be empty for delegate calls")] + #[test(should_fail_with="caller context cannot be default for delegate calls")] fn empty_caller_context_for_delegate_calls_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_delegate_call(); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index 1008e0c0f49..f990f637e14 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -15,7 +15,7 @@ use dep::types::{ MAX_PUBLIC_DATA_READS_PER_CALL }, hash::{silo_note_hash, silo_nullifier, compute_l2_to_l1_hash, accumulate_sha256}, - utils::{arrays::{array_length, array_to_bounded_vec}}, traits::{is_empty, is_empty_array} + utils::{arrays::{array_length, array_to_bounded_vec}}, traits::{is_empty, is_empty_array, is_default} }; use crate::hash::{compute_public_data_tree_index, compute_public_data_tree_value}; @@ -141,7 +141,7 @@ fn is_valid_caller(request: CallRequest, public_call: PublicCallData) -> bool { & request.caller_context.storage_contract_address.eq(call_context.storage_contract_address); request.caller_contract_address.eq(public_call.call_stack_item.contract_address) - & (request.caller_context.is_empty() | valid_caller_context) + & (is_default(request.caller_context) | valid_caller_context) } fn validate_call_requests( @@ -468,7 +468,7 @@ pub fn validate_call_against_request(public_call: PublicCallData, request: CallR if call_context.is_delegate_call { let caller_context = request.caller_context; - assert(!caller_context.is_empty(), "caller context cannot be empty for delegate calls"); + assert(!is_default(caller_context), "caller context cannot be default for delegate calls"); assert( call_context.msg_sender.eq(caller_context.msg_sender), "call stack msg_sender does not match expected msg_sender for delegate calls" ); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr index 2e46b97f832..320051c483f 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr @@ -263,7 +263,7 @@ mod tests { builder.succeeded(); } - #[test(should_fail_with="caller context cannot be empty for delegate calls")] + #[test(should_fail_with="caller context cannot be default for delegate calls")] fn empty_caller_context_for_delegate_calls_fails() { let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new().is_delegate_call(); builder.stub_teardown_call(); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr index 4624844617c..3ec6a448851 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr @@ -212,7 +212,7 @@ mod tests { builder.succeeded(); } - #[test(should_fail_with="caller context cannot be empty for delegate calls")] + #[test(should_fail_with="caller context cannot be default for delegate calls")] fn empty_caller_context_for_delegate_calls_fails() { let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new().is_delegate_call(); let public_call = builder.public_call.finish(); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr index eca17161fc4..e8d45bbaa96 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr @@ -134,14 +134,14 @@ mod tests { CallRequest { hash: 1, caller_contract_address: AztecAddress::from_field(1), - caller_context: CallerContext::empty(), + caller_context: CallerContext::default(), start_side_effect_counter: 5, end_side_effect_counter: 0 }, CallRequest { hash: 2, caller_contract_address: AztecAddress::from_field(1), - caller_context: CallerContext::empty(), + caller_context: CallerContext::default(), start_side_effect_counter: 6, end_side_effect_counter: 0 } @@ -161,7 +161,7 @@ mod tests { CallRequest { hash: 3, caller_contract_address: AztecAddress::from_field(3), - caller_context: CallerContext::empty(), + caller_context: CallerContext::default(), start_side_effect_counter: 9, end_side_effect_counter: 0 } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr index 8eca6227d7c..67c7f28021b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr @@ -26,7 +26,7 @@ impl Empty for CallRequest { CallRequest { hash: 0, caller_contract_address: AztecAddress::zero(), - caller_context: CallerContext::empty(), + caller_context: CallerContext::default(), start_side_effect_counter: 0, end_side_effect_counter: 0, } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr index f6b6f13c75e..f6d2a89449d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr @@ -1,6 +1,5 @@ use crate::address::AztecAddress; -use dep::std::cmp::Eq; -use crate::traits::{Empty, is_zero}; +use dep::std::{cmp::Eq,default::Default}; struct CallerContext { msg_sender: AztecAddress, @@ -14,17 +13,11 @@ impl Eq for CallerContext { } } -impl Empty for CallerContext { - fn empty() -> Self { +impl Default for CallerContext { + fn default() -> Self { CallerContext { msg_sender: AztecAddress::zero(), storage_contract_address: AztecAddress::zero(), } } } - -impl CallerContext { - pub fn is_empty(self) -> bool { - is_zero(self.msg_sender) & is_zero(self.storage_contract_address) - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/partial_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/partial_address.nr index df67b7f6dc2..9877defb973 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/partial_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/partial_address.nr @@ -54,8 +54,4 @@ impl PartialAddress { pub fn to_field(self) -> Field { self.inner } - - pub fn assert_is_zero(self) { - assert(self.to_field() == 0); - } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/public_keys_hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/public_keys_hash.nr index ff75e878f4e..1af37165ffa 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/public_keys_hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/public_keys_hash.nr @@ -52,10 +52,6 @@ impl PublicKeysHash { pub fn to_field(self) -> Field { self.inner } - - pub fn assert_is_zero(self) { - assert(self.to_field() == 0); - } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/salted_initialization_hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/salted_initialization_hash.nr index 88af664b86b..79288771df6 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/salted_initialization_hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/salted_initialization_hash.nr @@ -37,8 +37,4 @@ impl SaltedInitializationHash { ) ) } - - pub fn assert_is_zero(self) { - assert(self.to_field() == 0); - } } 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 703b4bd6bfe..411dba1a2ec 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 @@ -344,7 +344,7 @@ impl FixtureBuilder { } fn generate_call_request(&mut self, hash: Field, is_delegate_call: bool) -> CallRequest { - let mut caller_context = CallerContext::empty(); + let mut caller_context = CallerContext::default(); if is_delegate_call { caller_context.msg_sender = fixtures::MSG_SENDER; caller_context.storage_contract_address = self.contract_address; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr index a7e29d1554b..2eb4d1f2294 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr @@ -110,7 +110,7 @@ impl PrivateCallDataBuilder { is_delegate_call: bool ) -> (BoundedVec, BoundedVec) { let value_offset = requests.len(); - let mut caller_context = CallerContext::empty(); + let mut caller_context = CallerContext::default(); if is_delegate_call { let call_context = self.public_inputs.call_context; caller_context.msg_sender = call_context.msg_sender; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr index e71ac955020..b084ad07a63 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr @@ -75,7 +75,7 @@ impl PublicCallDataBuilder { pub fn append_public_call_requests(&mut self, num_requests: u64, is_delegate_call: bool) { let value_offset = self.public_inputs.public_call_stack_hashes.len(); - let mut caller_context = CallerContext::empty(); + let mut caller_context = CallerContext::default(); if is_delegate_call { let call_context = self.public_inputs.call_context; caller_context.msg_sender = call_context.msg_sender; From b8cf3c2d7dbd7990f56035425ff5dcb634d863a1 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 9 Apr 2024 21:01:55 +0000 Subject: [PATCH 58/77] fix --- .../parity-lib/src/parity_public_inputs.nr | 10 ++++++++++ .../parity-lib/src/root/root_parity_input.nr | 9 +++++++++ .../src/public_kernel_setup.nr | 2 +- .../src/public_kernel_teardown.nr | 2 +- .../crates/types/src/abis/call_context.nr | 2 +- .../crates/types/src/abis/function_data.nr | 13 +++++++++++-- .../crates/types/src/abis/function_selector.nr | 10 ++++++---- .../crates/types/src/mocked.nr | 18 ++++++++++++++++++ .../crates/types/src/transaction/tx_context.nr | 15 +++++++++++++-- .../crates/types/src/transaction/tx_request.nr | 13 ++++++++++++- 10 files changed, 82 insertions(+), 12 deletions(-) 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 03240ebe3ab..e9e6ae5917d 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 @@ -5,3 +5,13 @@ struct ParityPublicInputs { sha_root: Field, converted_root: Field, } + +impl Default for ParityPublicInputs { + fn default() -> Self { + ParityPublicInputs { + aggregation_object: AggregationObject::default(), + sha_root: 0, + converted_root: 0, + } + } +} 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 bafb3dff201..563e7a109aa 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 @@ -5,3 +5,12 @@ struct RootParityInput { proof: Proof, public_inputs: ParityPublicInputs, } + +impl Default for RootParityInput { + fn default() -> Self { + RootParityInput { + proof: Proof::default(), + public_inputs: ParityPublicInputs::default(), + } + } +} diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr index 320051c483f..709f660222f 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr @@ -208,7 +208,7 @@ mod tests { #[test(should_fail_with="Function signature cannot be zero")] fn function_selector_must_be_valid() { let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - builder.public_call.function_data.selector = FunctionSelector::zero(); + builder.public_call.function_data.selector = FunctionSelector::default(); builder.failed(); } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr index 3ec6a448851..29214a66919 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr @@ -158,7 +158,7 @@ mod tests { #[test(should_fail_with="Function signature cannot be zero")] fn function_selector_must_be_valid() { let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.public_call.function_data.selector = FunctionSelector::zero(); + builder.public_call.function_data.selector = FunctionSelector::default(); builder.failed(); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr index 35ab9751f04..1901726e417 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr @@ -26,7 +26,7 @@ impl Default for CallContext { msg_sender: AztecAddress::default(), storage_contract_address: AztecAddress::default(), portal_contract_address: EthAddress::default(), - function_selector: FunctionSelector::zero(), + function_selector: FunctionSelector::default(), is_delegate_call: false, is_static_call: false, side_effect_counter: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr index 7917108165c..9331ec27e2c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr @@ -16,6 +16,15 @@ impl Eq for FunctionData { } } +impl Default for FunctionData { + fn default() -> Self { + FunctionData { + selector: FunctionSelector::default(), + is_private: false, + } + } +} + impl Serialize for FunctionData { // A field is ~256 bits // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3057): Since, function data can fit into a Field, @@ -45,7 +54,7 @@ impl Hash for FunctionData { #[test] fn serialization_of_empty() { - let data: FunctionData = dep::std::unsafe::zeroed(); + let data = FunctionData::default(); let serialized = data.serialize(); let deserialized = FunctionData::deserialize(serialized); assert(data.eq(deserialized)); @@ -53,7 +62,7 @@ fn serialization_of_empty() { #[test] fn empty_hash() { - let data: FunctionData = dep::std::unsafe::zeroed(); + let data = FunctionData::default(); let hash = data.hash(); // Value from function_data.test.ts "computes empty item hash" test diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr index 32dbce09dfa..82aaee11018 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr @@ -15,6 +15,12 @@ impl Eq for FunctionSelector { } } +impl Default for FunctionSelector { + fn default() -> Self { + Self { inner: 0 as u32 } + } +} + impl Serialize<1> for FunctionSelector { fn serialize(self: Self) -> [Field; 1] { [self.inner as Field] @@ -57,8 +63,4 @@ impl FunctionSelector { FunctionSelector::from_field(field_from_bytes(selector_be_bytes, true)) } - - pub fn zero() -> Self { - Self { inner: 0 } - } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr b/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr index 343d15c1eed..23f75a58027 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr @@ -3,10 +3,28 @@ struct AggregationObject{} +impl Default for AggregationObject { + fn default() -> Self { + AggregationObject {} + } +} + struct Proof{} +impl Default for Proof { + fn default() -> Self { + Proof {} + } +} + struct VerificationKey{} +impl Default for VerificationKey { + fn default() -> Self { + VerificationKey {} + } +} + // Perform recursive verification of the previous kernel proof and private call // proof. pub fn verify_previous_kernel_state( diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr index a0655fa6250..7e260e381cd 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr @@ -20,6 +20,17 @@ impl Eq for TxContext { } } +impl Default for TxContext { + fn default() -> Self { + TxContext { + is_fee_payment_tx : false, + is_rebate_payment_tx : false, + chain_id : 0, + version : 0, + } + } +} + impl Serialize for TxContext { fn serialize(self) -> [Field; TX_CONTEXT_DATA_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(); @@ -60,7 +71,7 @@ impl Hash for TxContext { #[test] fn serialization_of_empty() { - let context: TxContext = dep::std::unsafe::zeroed(); + let context = TxContext::default(); let serialized = context.serialize(); let deserialized = TxContext::deserialize(serialized); assert(context.eq(deserialized)); @@ -68,7 +79,7 @@ fn serialization_of_empty() { #[test] fn empty_hash() { - let inputs: TxContext = dep::std::unsafe::zeroed(); + let inputs = TxContext::default(); let hash = inputs.hash(); // Value from tx_context.test.ts "computes empty item hash" test diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr index ba6179a05ee..7b4c526ea87 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr @@ -20,6 +20,17 @@ impl Eq for TxRequest { } } +impl Default for TxRequest { + fn default() -> Self { + TxRequest { + origin: AztecAddress::default(), + args_hash: 0, + tx_context: TxContext::default(), + function_data: FunctionData::default() + } + } +} + impl Hash for TxRequest { fn hash(self) -> Field { pedersen_hash(self.serialize(), GENERATOR_INDEX__TX_REQUEST) @@ -68,7 +79,7 @@ mod tests { #[test] fn serialization_of_empty() { // Assuming a zeroed initialization for simplicity - let request: TxRequest = dep::std::unsafe::zeroed(); + let request = TxRequest::default(); let serialized = request.serialize(); let deserialized = TxRequest::deserialize(serialized); assert(request.eq(deserialized)); From 225be506ef5e961f89dc6e1154484d532f485e68 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 9 Apr 2024 21:23:59 +0000 Subject: [PATCH 59/77] good --- .../aztec/src/context/private_context.nr | 2 +- .../src/private_kernel_init.nr | 2 +- .../src/private_kernel_inner.nr | 2 +- .../crates/public-kernel-lib/src/common.nr | 2 +- .../src/public_kernel_tail.nr | 2 +- .../src/nullifier_read_request_reset.nr | 2 +- .../rollup-lib/src/base/base_rollup_inputs.nr | 7 +++-- .../src/abis/append_only_tree_snapshot.nr | 6 ++-- .../crates/types/src/abis/call_request.nr | 20 ++++++++----- .../public_kernel_circuit_public_inputs.nr | 7 +++-- .../types/src/abis/membership_witness.nr | 29 ++++++++++++++++++- .../abis/nullifier_key_validation_request.nr | 8 ++--- .../types/src/abis/nullifier_leaf_preimage.nr | 20 ++++++++----- .../src/abis/private_circuit_public_inputs.nr | 2 +- .../src/abis/public_circuit_public_inputs.nr | 2 +- .../crates/types/src/grumpkin_point.nr | 15 +++++----- .../crates/types/src/grumpkin_private_key.nr | 14 ++++----- .../crates/types/src/hash.nr | 2 +- .../crates/types/src/header.nr | 2 +- .../types/src/merkle_tree/membership.nr | 9 ++++++ .../types/src/merkle_tree/merkle_tree.nr | 9 ++++++ .../types/src/messaging/l2_to_l1_message.nr | 11 ++++++- .../types/src/partial_state_reference.nr | 6 ++-- .../crates/types/src/state_reference.nr | 2 +- .../crates/types/src/tests/fixtures.nr | 2 +- .../types/src/tests/merkle_tree_utils.nr | 11 +++++++ 26 files changed, 136 insertions(+), 60 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 0fdb1735006..3b38d6df928 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -468,7 +468,7 @@ impl PrivateContext { public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], new_note_hashes: [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL], new_nullifiers: [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL], - new_l2_to_l1_msgs: [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], + new_l2_to_l1_msgs: [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], start_side_effect_counter: 0, end_side_effect_counter: 0, unencrypted_logs_hash: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr index afbdb75445e..10affa6a543 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr @@ -257,7 +257,7 @@ mod tests { builder.private_call.public_inputs.new_l2_to_l1_msgs.extend_from_array( [ - L2ToL1Message::empty(), + L2ToL1Message::default(), L2ToL1Message { recipient: EthAddress::from_field(6), content: 9123 } ] ); 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 4b5d4ed901f..69a6258ccb9 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 @@ -450,7 +450,7 @@ mod tests { builder.private_call.public_inputs.new_l2_to_l1_msgs.extend_from_array( [ - L2ToL1Message::empty(), + L2ToL1Message::default(), L2ToL1Message { recipient: EthAddress::from_field(6), content: 888 } ] ); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index f990f637e14..f153299d78b 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -408,7 +408,7 @@ fn propagate_new_l2_to_l1_messages(public_call: PublicCallData, public_inputs: & let mut new_l2_to_l1_msgs_to_insert : BoundedVec = BoundedVec::new(); for i in 0..MAX_NEW_L2_TO_L1_MSGS_PER_CALL { let msg = new_l2_to_l1_msgs[i]; - if !is_empty(msg) { + if !is_default(msg) { let new_l2_to_l1_msgs = compute_l2_to_l1_hash( storage_contract_address, public_inputs.constants.tx_context.version, diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr index 8240ae5d2d5..7debfd4f402 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr @@ -141,7 +141,7 @@ mod tests { }; fn build_nullifier_tree() -> NonEmptyMerkleTree { - let mut pre_existing_nullifiers = [NullifierLeafPreimage::empty(); MAX_NEW_NULLIFIERS_PER_TX]; + let mut pre_existing_nullifiers = [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX]; pre_existing_nullifiers[0] = NullifierLeafPreimage { nullifier: 0, next_nullifier: 100, next_index: 1 }; pre_existing_nullifiers[1] = NullifierLeafPreimage { nullifier: 100, next_nullifier: 0, next_index: 0 }; NonEmptyMerkleTree::new( diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/nullifier_read_request_reset.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/nullifier_read_request_reset.nr index 6a122e57a2d..97da56c6ac0 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/nullifier_read_request_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/nullifier_read_request_reset.nr @@ -32,7 +32,7 @@ impl SettledReadHint for Nullifier NullifierSettledReadHint { read_request_index: read_request_len, membership_witness: unsafe::zeroed(), - leaf_preimage: NullifierLeafPreimage::empty() + leaf_preimage: NullifierLeafPreimage::default() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr index 498632b4bd1..cc7f2b97399 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -8,6 +8,7 @@ use crate::{ }; use dep::types::{ hash::sha256_to_field, + traits::is_default, abis::{ append_only_tree_snapshot::AppendOnlyTreeSnapshot, membership_witness::{ArchiveRootMembershipWitness, NullifierMembershipWitness, PublicDataMembershipWitness}, @@ -149,7 +150,7 @@ impl BaseRollupInputs { let is_less_than_nullifier = full_field_less_than(low_leaf.nullifier, nullifier); let is_next_greater_than = full_field_less_than(nullifier, low_leaf.next_nullifier); - (!low_leaf.is_empty()) & is_less_than_nullifier & ( + (!is_default(low_leaf)) & is_less_than_nullifier & ( is_next_greater_than | ((low_leaf.next_index == 0) & (low_leaf.next_nullifier == 0)) ) @@ -804,7 +805,7 @@ mod tests { }; builder.new_nullifiers.push(NullifierInsertion { existing_index: 0, value: 1 }); - let mut tree_nullifiers = [NullifierLeafPreimage::empty(); MAX_NEW_NULLIFIERS_PER_TX * 2]; + let mut tree_nullifiers = [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX * 2]; tree_nullifiers[0] = NullifierLeafPreimage { nullifier : 0, next_nullifier : 1, @@ -854,7 +855,7 @@ mod tests { } let output = builder.execute(); - let mut tree_nullifiers = [NullifierLeafPreimage::empty(); MAX_NEW_NULLIFIERS_PER_TX * 2]; + let mut tree_nullifiers = [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX * 2]; tree_nullifiers[0] = builder.pre_existing_nullifiers[0]; tree_nullifiers[1] = NullifierLeafPreimage { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr index 83925d95897..e41a73b9c4a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr @@ -1,4 +1,4 @@ -use dep::std::cmp::Eq; +use dep::std::{cmp::Eq,default::Default}; struct AppendOnlyTreeSnapshot { root : Field, @@ -16,8 +16,10 @@ impl AppendOnlyTreeSnapshot { pub fn deserialize(serialized: [Field; APPEND_ONLY_TREE_SNAPSHOT_LENGTH]) -> AppendOnlyTreeSnapshot { AppendOnlyTreeSnapshot { root: serialized[0], next_available_leaf_index: serialized[1] as u32 } } +} - pub fn zero() -> Self { +impl Default for AppendOnlyTreeSnapshot { + fn default() -> Self { Self { root: 0, next_available_leaf_index: 0 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr index 67c7f28021b..ba9ee3cf24c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr @@ -1,7 +1,7 @@ use crate::address::AztecAddress; -use dep::std::cmp::Eq; -use crate::traits::Empty; +use dep::std::{cmp::Eq,default::Default}; use crate::abis::caller_context::CallerContext; +use crate::traits::Empty; struct CallRequest { hash: Field, @@ -21,8 +21,8 @@ impl Eq for CallRequest { } } -impl Empty for CallRequest { - fn empty() -> Self { +impl Default for CallRequest { + fn default() -> Self { CallRequest { hash: 0, caller_contract_address: AztecAddress::zero(), @@ -33,8 +33,14 @@ impl Empty for CallRequest { } } -impl CallRequest { - pub fn is_empty(self) -> bool { - self.hash == 0 +impl Empty for CallRequest { + fn empty() -> Self { + CallRequest { + hash: 0, + caller_contract_address: AztecAddress::zero(), + caller_context: CallerContext::default(), + start_side_effect_counter: 0, + end_side_effect_counter: 0, + } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr index 2441851f617..9873d891a59 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr @@ -3,6 +3,7 @@ use crate::abis::{ validation_requests::{RollupValidationRequests, ValidationRequests} }; use crate::mocked::AggregationObject; +use crate::traits::is_default; struct PublicKernelCircuitPublicInputs { aggregation_object: AggregationObject, @@ -18,17 +19,17 @@ impl PublicKernelCircuitPublicInputs { // By definition, the final non-revertible enqueued call is for teardown. // since this is a stack, the teardown call would be the 0th element. // So if we have more than one element, we need setup. - !self.end_non_revertible.public_call_stack[1].is_empty() + !is_default(self.end_non_revertible.public_call_stack[1]) } pub fn needs_app_logic(self) -> bool { // if we have any enqueued revertible public calls, we need to run the public app logic circuit. - !self.end.public_call_stack[0].is_empty() + !is_default(self.end.public_call_stack[0]) } pub fn needs_teardown(self) -> bool { // By definition, the final non-revertible enqueued call is for teardown. // since this is a stack, the teardown call would be the 0th element. - !self.end_non_revertible.public_call_stack[0].is_empty() + !is_default(self.end_non_revertible.public_call_stack[0]) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr index d23cfb0f19a..1b4af194791 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr @@ -17,16 +17,43 @@ struct VKMembershipWitness{ sibling_path: [Field; ROLLUP_VK_TREE_HEIGHT] } +impl Default for VKMembershipWitness { + fn default() -> Self { + VKMembershipWitness { + leaf_index: 0, + sibling_path: [0; ROLLUP_VK_TREE_HEIGHT] + } + } +} + struct NullifierMembershipWitness{ leaf_index: Field, sibling_path: [Field; NULLIFIER_TREE_HEIGHT] } +impl Default for NullifierMembershipWitness { + fn default() -> Self { + NullifierMembershipWitness { + leaf_index: 0, + sibling_path: [0; NULLIFIER_TREE_HEIGHT] + } + } +} + struct PublicDataMembershipWitness{ leaf_index: Field, sibling_path: [Field; PUBLIC_DATA_TREE_HEIGHT] } +impl Default for PublicDataMembershipWitness { + fn default() -> Self { + PublicDataMembershipWitness { + leaf_index: 0, + sibling_path: [0; PUBLIC_DATA_TREE_HEIGHT] + } + } +} + struct ArchiveRootMembershipWitness{ leaf_index: Field, sibling_path: [Field; ARCHIVE_HEIGHT] @@ -36,7 +63,7 @@ struct NoteHashReadRequestMembershipWitness { leaf_index: Field, sibling_path: [Field; NOTE_HASH_TREE_HEIGHT], // whether or not the read request corresponds to a pending note hash - // In case we change the default to true, we have to adapt is_empty() method + // In case we change the default to true, we have to adapt is_default() method // hint to point kernel to the commitment this rr corresponds to is_transient: bool, hint_to_note_hash: Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr index a522dace348..413f3f0173f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr @@ -21,8 +21,8 @@ impl Eq for NullifierKeyValidationRequest { impl Empty for NullifierKeyValidationRequest { fn empty() -> Self { NullifierKeyValidationRequest { - public_key: GrumpkinPoint::zero(), - secret_key: GrumpkinPrivateKey::zero(), + public_key: GrumpkinPoint::default(), + secret_key: GrumpkinPrivateKey::default(), } } } @@ -70,8 +70,8 @@ impl Eq for NullifierKeyValidationRequestContext { impl Empty for NullifierKeyValidationRequestContext { fn empty() -> Self { NullifierKeyValidationRequestContext { - public_key: GrumpkinPoint::zero(), - secret_key: GrumpkinPrivateKey::zero(), + public_key: GrumpkinPoint::default(), + secret_key: GrumpkinPrivateKey::default(), contract_address: AztecAddress::zero(), } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr index 895196567a0..baf4a2bf967 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr @@ -1,6 +1,6 @@ global NULLIFIER_LEAF_PREIMAGE_LENGTH: u64 = 3; -use crate::{merkle_tree::leaf_preimage::{LeafPreimage, IndexedTreeLeafPreimage}, traits::{Empty, Hash}}; +use crate::{merkle_tree::leaf_preimage::{LeafPreimage, IndexedTreeLeafPreimage}, traits::{is_default, Hash}}; struct NullifierLeafPreimage { nullifier : Field, @@ -8,8 +8,16 @@ struct NullifierLeafPreimage { next_index : u64, } -impl Empty for NullifierLeafPreimage { - fn empty() -> Self { +impl Eq for NullifierLeafPreimage { + fn eq(self, nullifier_leaf_preimage: NullifierLeafPreimage) -> bool { + (nullifier_leaf_preimage.nullifier == self.nullifier) + & (nullifier_leaf_preimage.next_nullifier == self.next_nullifier) + & (nullifier_leaf_preimage.next_index == self.next_index) + } +} + +impl Default for NullifierLeafPreimage { + fn default() -> Self { Self { nullifier : 0, next_nullifier : 0, @@ -20,7 +28,7 @@ impl Empty for NullifierLeafPreimage { impl Hash for NullifierLeafPreimage { fn hash(self) -> Field { - if self.is_empty() { + if is_default(self) { 0 } else { dep::std::hash::pedersen_hash(self.serialize()) @@ -53,10 +61,6 @@ impl IndexedTreeLeafPreimage for NullifierLeafPreimage { } impl NullifierLeafPreimage { - pub fn is_empty(self) -> bool { - (self.nullifier == 0) & (self.next_nullifier == 0) & (self.next_index == 0) - } - pub fn serialize(self) -> [Field; NULLIFIER_LEAF_PREIMAGE_LENGTH] { [self.nullifier, self.next_nullifier, self.next_index as Field] } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr index 9f5bcb28c18..26638a3df84 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr @@ -145,7 +145,7 @@ impl Deserialize for PrivateCircuitPublicI new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL]), private_call_stack_hashes: reader.read_array([0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL]), public_call_stack_hashes: reader.read_array([0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), - new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), + new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), start_side_effect_counter: reader.read() as u32, end_side_effect_counter: reader.read() as u32, encrypted_logs_hash: reader.read() as Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index dab7f2b7fcf..e4072aafc0c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -114,7 +114,7 @@ impl Deserialize for PublicCircuitPublicInp public_call_stack_hashes: reader.read_array([0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL]), new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL]), - new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), + new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), start_side_effect_counter: reader.read() as u32, end_side_effect_counter: reader.read() as u32, unencrypted_logs_hash: reader.read() as Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_point.nr b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_point.nr index 965654ac144..df841b9e250 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_point.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_point.nr @@ -29,23 +29,22 @@ impl Eq for GrumpkinPoint { } } -impl GrumpkinPoint { - pub fn new(x: Field, y: Field) -> Self { - Self { x, y } - } - - pub fn zero() -> Self { +impl Default for GrumpkinPoint { + fn default() -> Self { Self { x: 0, y: 0 } } +} - pub fn is_zero(self) -> bool { - (self.x == 0) & (self.y == 0) +impl GrumpkinPoint { + pub fn new(x: Field, y: Field) -> Self { + Self { x, y } } // TODO(David): Would be quite careful here as (0,0) is not a point // on the curve. A boolean flag may be the better approach here, // would also cost less constraints. It seems like we don't need to // group arithmetic either. + // Keeping this function here as a reminder even though its unused fn assert_is_zero(self) { assert(self.x == 0); assert(self.y == 0); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr index 4694322da8a..316337161f2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr @@ -14,17 +14,15 @@ impl Eq for GrumpkinPrivateKey { } } -impl GrumpkinPrivateKey { - pub fn new(high: Field, low: Field) -> Self { - GrumpkinPrivateKey { high, low } - } - - pub fn zero() -> Self { +impl Default for GrumpkinPrivateKey { + fn default() -> Self { Self { high: 0, low: 0 } } +} - pub fn is_zero(self) -> bool { - (self.high == 0) & (self.low == 0) +impl GrumpkinPrivateKey { + pub fn new(high: Field, low: Field) -> Self { + GrumpkinPrivateKey { high, low } } pub fn serialize(self) -> [Field; GRUMPKIN_PRIVATE_KEY_SERIALIZED_LEN] { 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 396ed601c2f..282edcb7a33 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr @@ -178,7 +178,7 @@ fn smoke_sha256_to_field() { #[test] fn compute_l2_l1_hash() { // All zeroes - let hash_result = compute_l2_to_l1_hash(AztecAddress::from_field(0), 0, 0, L2ToL1Message::empty()); + let hash_result = compute_l2_to_l1_hash(AztecAddress::from_field(0), 0, 0, L2ToL1Message::default()); assert(hash_result == 0xb393978842a0fa3d3e1470196f098f473f9678e72463cb65ec4ab5581856c2); // Non-zero case diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr index 2dff0192f09..1bf133e5297 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr @@ -30,7 +30,7 @@ impl Eq for Header { impl Default for Header { fn default() -> Self { Self { - last_archive: AppendOnlyTreeSnapshot::zero(), + last_archive: AppendOnlyTreeSnapshot::default(), content_commitment: ContentCommitment::empty(), state: StateReference::empty(), global_variables: GlobalVariables::empty(), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr index 6fc8d91d13b..d810b55c9f9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr @@ -5,6 +5,15 @@ struct MembershipWitness { sibling_path: [Field; N] } +impl Default for MembershipWitness { + fn default() -> Self { + MembershipWitness { + leaf_index: 0, + sibling_path: [0; N] + } + } +} + pub fn check_membership(leaf: Field, index: Field, sibling_path: [Field; N], root: Field) -> bool { let calculated_root = root_from_sibling_path(leaf, index, sibling_path); calculated_root == root diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr index f1cacb956ac..27108ed2c53 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr @@ -3,6 +3,15 @@ struct MerkleTree { nodes: [Field; N], } +impl Default for MerkleTree { + fn default() -> Self { + MerkleTree { + leaves: [0; N], + nodes: [0; N] + } + } +} + impl MerkleTree { pub fn new(leaves: [Field; N]) -> Self { let mut nodes = [0; N]; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr index 39ea711d09f..5bcfac770d3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr @@ -1,4 +1,4 @@ -use crate::{address::EthAddress, constants::L2_TO_L1_MESSAGE_LENGTH, traits::{Deserialize, Empty, Serialize}}; +use crate::{address::EthAddress, constants::L2_TO_L1_MESSAGE_LENGTH, traits::{Deserialize, Serialize, Empty}}; // Note: Not to be confused with L2ToL1Msg in Solidity struct L2ToL1Message { @@ -6,6 +6,15 @@ struct L2ToL1Message { content: Field, } +impl Default for L2ToL1Message { + fn default() -> Self { + Self { + recipient: EthAddress::zero(), + content: 0, + } + } +} + impl Empty for L2ToL1Message { fn empty() -> Self { Self { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr b/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr index 10761f02f22..d19f27bc62e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr @@ -53,9 +53,9 @@ impl Deserialize for PartialStateReference { impl Empty for PartialStateReference { fn empty() -> Self { Self { - note_hash_tree: AppendOnlyTreeSnapshot::zero(), - nullifier_tree: AppendOnlyTreeSnapshot::zero(), - public_data_tree: AppendOnlyTreeSnapshot::zero(), + note_hash_tree: AppendOnlyTreeSnapshot::default(), + nullifier_tree: AppendOnlyTreeSnapshot::default(), + public_data_tree: AppendOnlyTreeSnapshot::default(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr index dde8222e9cd..4b1878620d3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr @@ -47,7 +47,7 @@ impl Deserialize for StateReference { impl Empty for StateReference { fn empty() -> Self { Self { - l1_to_l2_message_tree: AppendOnlyTreeSnapshot::zero(), + l1_to_l2_message_tree: AppendOnlyTreeSnapshot::default(), partial: PartialStateReference::empty(), } } 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 4a138e97e11..28cb4fb8d08 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 @@ -16,7 +16,7 @@ global PUBLIC_KEY = GrumpkinPoint { x: 123456789, y: 123456789 }; // Workaround for https://github.com/noir-lang/noir/issues/1440 fn empty_append_only_tree() -> AppendOnlyTreeSnapshot { - AppendOnlyTreeSnapshot::zero() + AppendOnlyTreeSnapshot::default() } // Workaround for https://github.com/noir-lang/noir/issues/1440 diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr index c5fdd279524..235bd8540d9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr @@ -76,6 +76,17 @@ struct NonEmptyMerkleTree Default for NonEmptyMerkleTree { + fn default() -> Self { + NonEmptyMerkleTree { + subtree: MerkleTree::default(), + zero_hashes: [0; TREE_HEIGHT], + left_supertree_branch: [0; SUPERTREE_HEIGHT], + _phantom_subtree_height: [0; SUBTREE_HEIGHT], + } + } +} + impl NonEmptyMerkleTree { pub fn new( non_zero_leaves: [Field; SUBTREE_ITEMS], From 7fcc941e6f40d3f39ad46f3f534d371795654a39 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 9 Apr 2024 22:52:51 +0000 Subject: [PATCH 60/77] fixing --- .../src/public_kernel_teardown.nr | 6 +++--- .../public_accumulated_data_builder.nr | 16 ++++++++++++++++ .../types/src/abis/combined_constant_data.nr | 9 +++++++++ ...ublic_kernel_circuit_public_inputs_builder.nr | 13 +++++++++++++ .../validation_requests_builder.nr | 13 +++++++++++++ 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr index 29214a66919..75e92d64607 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr @@ -25,7 +25,7 @@ impl PublicKernelTeardownCircuitPrivateInputs { fn public_kernel_teardown(self) -> PublicKernelCircuitPublicInputs { // construct the circuit outputs - let mut public_inputs: PublicKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::default(); // since this phase is non-revertible, we must assert the public call did not revert common::validate_public_call_non_revert(self.public_call); common::initialize_revert_code(self.previous_kernel, self.public_call, &mut public_inputs); @@ -213,12 +213,12 @@ mod tests { } #[test(should_fail_with="caller context cannot be default for delegate calls")] - fn empty_caller_context_for_delegate_calls_fails() { + fn default_caller_context_for_delegate_calls_fails() { let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new().is_delegate_call(); let public_call = builder.public_call.finish(); let hash = public_call.call_stack_item.hash(); - // Caller context is empty for regular calls. + // Caller context is default for regular calls. let is_delegate_call = false; builder.previous_kernel.push_public_call_request(hash, is_delegate_call); let previous_kernel = builder.previous_kernel.to_public_kernel_data(false); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr index 0740f852f32..141e2a324b0 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr @@ -28,6 +28,22 @@ struct PublicAccumulatedDataBuilder { public_call_stack: BoundedVec, } +impl Default for PublicAccumulatedDataBuilder { + fn default() -> Self { + PublicAccumulatedDataBuilder { + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + new_l2_to_l1_msgs: BoundedVec::new(), + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + public_data_update_requests: BoundedVec::new(), + public_call_stack: BoundedVec::new(), + } + } +} + impl PublicAccumulatedDataBuilder { pub fn finish(self) -> PublicAccumulatedData { PublicAccumulatedData { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr index 9dc4974700f..bba3ebf718e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr @@ -9,3 +9,12 @@ struct CombinedConstantData { // protocol to execute and prove the transaction. tx_context: TxContext, } + +impl Default for CombinedConstantData { + fn default() -> Self { + CombinedConstantData { + historical_header: Header::default(), + tx_context: TxContext::default(), + } + } +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr index 70da6d47a1c..8bff3dab78f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr @@ -18,6 +18,19 @@ struct PublicKernelCircuitPublicInputsBuilder { revert_code: u8, } +impl Default for PublicKernelCircuitPublicInputsBuilder { + fn default() -> Self { + PublicKernelCircuitPublicInputsBuilder { + aggregation_object: AggregationObject::default(), + validation_requests: ValidationRequestsBuilder::default(), + end_non_revertible: PublicAccumulatedDataBuilder::default(), + end: PublicAccumulatedDataBuilder::default(), + constants: CombinedConstantData::default(), + revert_code: 0 as u8, + } + } +} + impl PublicKernelCircuitPublicInputsBuilder { pub fn finish(self) -> PublicKernelCircuitPublicInputs { PublicKernelCircuitPublicInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr index d8f02f49d29..ade84793296 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr @@ -22,6 +22,19 @@ struct ValidationRequestsBuilder { public_data_reads: BoundedVec, } +impl Default for ValidationRequestsBuilder { + fn default() -> Self { + ValidationRequestsBuilder { + max_block_number: MaxBlockNumber::default(), + note_hash_read_requests: BoundedVec::new(), + nullifier_read_requests: BoundedVec::new(), + nullifier_non_existent_read_requests: BoundedVec::new(), + nullifier_key_validation_requests: BoundedVec::new(), + public_data_reads: BoundedVec::new(), + } + } +} + impl ValidationRequestsBuilder { pub fn finish(self) -> ValidationRequests { ValidationRequests { From 62d517d80efe3201db5b0f6c6ca499d73a9f049f Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 9 Apr 2024 23:11:54 +0000 Subject: [PATCH 61/77] next --- .../aztec/src/context/private_context.nr | 25 +++++++++++++- .../aztec-nr/tests/src/note_getter_test.nr | 14 ++++---- .../crates/types/src/content_commitment.nr | 9 ++--- .../crates/types/src/header.nr | 2 +- .../crates/types/src/tests/fixture_builder.nr | 34 +++++++++++++++++++ .../crates/types/src/tests/fixtures.nr | 24 ++++++------- .../src/tests/private_call_data_builder.nr | 6 ++-- .../private_circuit_public_inputs_builder.nr | 29 +++++++++++++++- .../src/tests/public_call_data_builder.nr | 2 +- .../public_circuit_public_inputs_builder.nr | 27 ++++++++++++++- 10 files changed, 141 insertions(+), 31 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 3b38d6df928..6401689d23d 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -29,7 +29,7 @@ use dep::protocol_types::{ }, contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, grumpkin_private_key::GrumpkinPrivateKey, header::Header, - messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, traits::{is_empty, is_zero} + messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, traits::is_zero }; // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) @@ -70,6 +70,29 @@ struct PrivateContext { nullifier_key: Option, } +impl Default for PrivateContext { + fn default() -> Self { + PrivateContext { + inputs: PrivateContextInputs::default(), + side_effect_counter: 0 as u32, + min_revertible_side_effect_counter: 0 as u32, + args_hash : 0, + return_values : BoundedVec::new(), + max_block_number: MaxBlockNumber::default(), + note_hash_read_requests: BoundedVec::new(), + nullifier_read_requests: BoundedVec::new(), + nullifier_key_validation_requests: BoundedVec::new(), + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + private_call_stack_hashes : BoundedVec::new(), + public_call_stack_hashes : BoundedVec::new(), + new_l2_to_l1_msgs : BoundedVec::new(), + historical_header: Header::default(), + nullifier_key: Option::none(), + } + } +} + impl ContextInterface for PrivateContext { fn msg_sender(self) -> AztecAddress { self.inputs.call_context.msg_sender diff --git a/noir-projects/aztec-nr/tests/src/note_getter_test.nr b/noir-projects/aztec-nr/tests/src/note_getter_test.nr index c55db121145..42e37366193 100644 --- a/noir-projects/aztec-nr/tests/src/note_getter_test.nr +++ b/noir-projects/aztec-nr/tests/src/note_getter_test.nr @@ -10,7 +10,7 @@ use crate::mock::test_note::TestNote; #[test] fn sets_note_manually_and_fetches_it() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); context.inputs.call_context.storage_contract_address = AztecAddress::from_field(69); let mut test_note = TestNote::new(1337); @@ -28,7 +28,7 @@ fn sets_note_manually_and_fetches_it() { #[test(should_fail)] fn cannot_return_zero_notes() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); let storage_slot: Field = 0; let mut opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; @@ -38,7 +38,7 @@ fn cannot_return_zero_notes() { #[test(should_fail)] fn mismatched_address() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); context.inputs.call_context.storage_contract_address = AztecAddress::from_field(1); let storage_slot: Field = 0; @@ -51,7 +51,7 @@ fn mismatched_address() { #[test(should_fail)] fn mismatched_storage_slot() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); context.inputs.call_context.storage_contract_address = AztecAddress::from_field(1); let mut test_note = TestNote::new(1); @@ -68,7 +68,7 @@ fn mismatched_storage_slot() { #[test(should_fail)] fn invalid_selector() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); context.inputs.call_context.storage_contract_address = AztecAddress::from_field(1); let mut test_note = TestNote::new(1); @@ -90,7 +90,7 @@ fn invalid_selector() { #[test(should_fail)] fn invalid_note_order() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); let mut opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; opt_notes[0] = Option::some(TestNote::new(1)); @@ -108,7 +108,7 @@ fn invalid_note_order() { #[test] fn sparse_notes_array() { - let mut context: PrivateContext = dep::std::unsafe::zeroed(); + let mut context = PrivateContext::default(); let mut opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; opt_notes[1] = Option::some(TestNote::new(0)); 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 3279b6ab9f2..253af29f254 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,7 +1,8 @@ use crate::{ - constants::CONTENT_COMMITMENT_LENGTH, traits::{Deserialize, Empty, Hash, Serialize}, + constants::CONTENT_COMMITMENT_LENGTH, traits::{Deserialize, Hash, Serialize}, utils::arr_copy_slice }; +use dep::std::default::Default; struct ContentCommitment { tx_tree_height: Field, @@ -42,8 +43,8 @@ impl Deserialize for ContentCommitment { } } -impl Empty for ContentCommitment { - fn empty() -> Self { +impl Default for ContentCommitment { + fn default() -> Self { Self { tx_tree_height: 0, txs_effects_hash: 0, @@ -64,7 +65,7 @@ impl Eq for ContentCommitment { #[test] fn serialization_of_empty() { - let empty = ContentCommitment::empty(); + let empty = ContentCommitment::default(); let serialized = empty.serialize(); let deserialized = ContentCommitment::deserialize(serialized); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr index 1bf133e5297..7ffcd895653 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr @@ -31,7 +31,7 @@ impl Default for Header { fn default() -> Self { Self { last_archive: AppendOnlyTreeSnapshot::default(), - content_commitment: ContentCommitment::empty(), + content_commitment: ContentCommitment::default(), state: StateReference::empty(), global_variables: GlobalVariables::empty(), } 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 411dba1a2ec..859183efcde 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 @@ -67,6 +67,40 @@ struct FixtureBuilder { counter: u32, } +impl Default for FixtureBuilder { + fn default() -> Self { + FixtureBuilder { + contract_address: AztecAddress::zero(), + storage_contract_address: AztecAddress::zero(), + historical_header: Header::default(), + tx_context: TxContext::default(), + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + new_l2_to_l1_msgs: BoundedVec::new(), + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + public_data_update_requests: BoundedVec::new(), + private_call_stack: BoundedVec::new(), + public_call_stack: BoundedVec::new(), + max_block_number: MaxBlockNumber::default(), + note_hash_read_requests: BoundedVec::new(), + nullifier_read_requests: BoundedVec::new(), + nullifier_non_existent_read_requests: BoundedVec::new(), + nullifier_key_validation_requests: BoundedVec::new(), + public_data_reads: BoundedVec::new(), + proof: Proof::default(), + vk: VerificationKey::default(), + vk_index: 0, + vk_path: [0; VK_TREE_HEIGHT], + revert_code: 0, + min_revertible_side_effect_counter: 0, + counter: 0 + } + } +} + impl FixtureBuilder { pub fn new() -> Self { let tx_context = TxContext { is_fee_payment_tx: false, is_rebate_payment_tx: false, chain_id: 1, version: 0 }; 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 28cb4fb8d08..12445f7e7ac 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 @@ -15,37 +15,37 @@ global MSG_SENDER = AztecAddress { inner: 27 }; global PUBLIC_KEY = GrumpkinPoint { x: 123456789, y: 123456789 }; // Workaround for https://github.com/noir-lang/noir/issues/1440 -fn empty_append_only_tree() -> AppendOnlyTreeSnapshot { +fn default_append_only_tree() -> AppendOnlyTreeSnapshot { AppendOnlyTreeSnapshot::default() } // Workaround for https://github.com/noir-lang/noir/issues/1440 -fn empty_eth_address() -> EthAddress { +fn zero_eth_address() -> EthAddress { EthAddress::zero() } // Workaround for https://github.com/noir-lang/noir/issues/1440 -fn empty_aztec_address() -> AztecAddress { +fn zero_aztec_address() -> AztecAddress { AztecAddress::zero() } // Workaround for https://github.com/noir-lang/noir/issues/1440 -fn empty_content_commitment() -> ContentCommitment { - ContentCommitment::empty() +fn default_content_commitment() -> ContentCommitment { + ContentCommitment::default() } global HEADER = Header { - last_archive: empty_append_only_tree(), - content_commitment: empty_content_commitment(), + last_archive: default_append_only_tree(), + content_commitment: default_content_commitment(), state: StateReference { - l1_to_l2_message_tree: empty_append_only_tree(), + l1_to_l2_message_tree: default_append_only_tree(), partial: PartialStateReference { note_hash_tree: AppendOnlyTreeSnapshot { root: fixtures::note_hash_tree::ROOT, next_available_leaf_index: 0, // TODO: should this be populated? }, - nullifier_tree: empty_append_only_tree(), - public_data_tree: empty_append_only_tree() + nullifier_tree: default_append_only_tree(), + public_data_tree: default_append_only_tree() } }, global_variables: GlobalVariables { @@ -53,7 +53,7 @@ global HEADER = Header { version: 0, block_number: 0, timestamp: 0, - coinbase: empty_eth_address(), - fee_recipient: empty_aztec_address(), + coinbase: zero_eth_address(), + fee_recipient: zero_aztec_address(), } }; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr index 2eb4d1f2294..e9a03b8120e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr @@ -53,8 +53,8 @@ impl PrivateCallDataBuilder { public_inputs, is_execution_request: false, function_data, - private_call_stack: dep::std::unsafe::zeroed(), - public_call_stack: dep::std::unsafe::zeroed(), + private_call_stack: BoundedVec::new(), + public_call_stack: BoundedVec::new(), proof: Proof {}, vk: VerificationKey {}, function_leaf_membership_witness: contract_function.membership_witness, @@ -62,7 +62,7 @@ impl PrivateCallDataBuilder { public_keys_hash: contract_data.public_keys_hash, contract_class_artifact_hash: contract_data.artifact_hash, contract_class_public_bytecode_commitment: contract_data.public_bytecode_commitment, - note_hash_read_request_membership_witnesses: dep::std::unsafe::zeroed(), + note_hash_read_request_membership_witnesses: BoundedVec::new(), portal_contract_address: public_inputs.call_context.portal_contract_address, acir_hash: contract_function.acir_hash } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr index 0c62f4726e2..e17bb6ed908 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr @@ -48,9 +48,36 @@ struct PrivateCircuitPublicInputsBuilder { version: Field, } +impl Default for PrivateCircuitPublicInputsBuilder { + fn default() -> Self { + PrivateCircuitPublicInputsBuilder { + call_context: CallContext::default(), + args_hash: 0, + return_values: BoundedVec::new(), + min_revertible_side_effect_counter: 0 as u32, + max_block_number: MaxBlockNumber::default(), + note_hash_read_requests: BoundedVec::new(), + nullifier_read_requests: BoundedVec::new(), + nullifier_key_validation_requests: BoundedVec::new(), + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + private_call_stack_hashes: BoundedVec::new(), + public_call_stack_hashes: BoundedVec::new(), + new_l2_to_l1_msgs: BoundedVec::new(), + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + historical_header: Header::default(), + chain_id: 0, + version: 0, + } + } +} + impl PrivateCircuitPublicInputsBuilder { pub fn new() -> Self { - let mut public_inputs: PrivateCircuitPublicInputsBuilder = dep::std::unsafe::zeroed(); + let mut public_inputs = PrivateCircuitPublicInputsBuilder::default(); let args_hash = 0; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr index b084ad07a63..38c39e18ff7 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr @@ -50,7 +50,7 @@ impl PublicCallDataBuilder { public_inputs, is_execution_request: false, function_data, - public_call_stack: dep::std::unsafe::zeroed(), + public_call_stack: BoundedVec::new(), proof: Proof {}, portal_contract_address, bytecode_hash: contract_function.acir_hash diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr index c033915b4b9..022f3f8d5d8 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr @@ -35,9 +35,34 @@ struct PublicCircuitPublicInputsBuilder { revert_code: u8, } +impl Default for PublicCircuitPublicInputsBuilder { + fn default() -> Self { + PublicCircuitPublicInputsBuilder { + call_context: CallContext::default(), + args_hash: 0, + return_values: BoundedVec::new(), + nullifier_read_requests: BoundedVec::new(), + nullifier_non_existent_read_requests: BoundedVec::new(), + contract_storage_update_requests: BoundedVec::new(), + contract_storage_reads: BoundedVec::new(), + public_call_stack_hashes: BoundedVec::new(), + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + new_l2_to_l1_msgs: BoundedVec::new(), + start_side_effect_counter: 0 as u32, + end_side_effect_counter: 0 as u32, + unencrypted_logs_hash: 0, + unencrypted_log_preimages_length: 0, + historical_header: Header::default(), + prover_address: AztecAddress::zero(), + revert_code: 0 as u8, + } + } +} + impl PublicCircuitPublicInputsBuilder { pub fn new() -> Self { - let mut public_inputs: PublicCircuitPublicInputsBuilder = dep::std::unsafe::zeroed(); + let mut public_inputs = PublicCircuitPublicInputsBuilder::default(); public_inputs.call_context.msg_sender = fixtures::MSG_SENDER; public_inputs.historical_header = fixtures::HEADER; public_inputs From 61306de929c12efab35eff966fe9bc89aa3e9c86 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 10 Apr 2024 08:57:04 +0000 Subject: [PATCH 62/77] good --- .../crates/types/src/abis/global_variables.nr | 17 +++----- .../crates/types/src/abis/side_effect.nr | 39 ++++++++++++++----- .../crates/types/src/header.nr | 4 +- .../types/src/partial_state_reference.nr | 27 +++++++------ .../crates/types/src/state_reference.nr | 22 +++++------ 5 files changed, 63 insertions(+), 46 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr index f3aac1777ef..06ca2f86be3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr @@ -2,7 +2,7 @@ use dep::std::cmp::Eq; use crate::{ address::{AztecAddress, EthAddress}, constants::{GENERATOR_INDEX__GLOBAL_VARIABLES, GLOBAL_VARIABLES_LENGTH}, - traits::{Deserialize, Empty, Hash, Serialize} + traits::{Deserialize, Hash, Serialize} }; // docs:start:global-variables @@ -44,17 +44,12 @@ impl Deserialize for GlobalVariables { impl Eq for GlobalVariables { fn eq(self, other : GlobalVariables) -> bool { - (self.chain_id == other.chain_id) & - (self.version == other.version) & - (self.block_number == other.block_number) & - (self.timestamp == other.timestamp) & - (self.coinbase == other.coinbase) & - (self.fee_recipient == other.fee_recipient) + self.serialize() == other.serialize() } } -impl Empty for GlobalVariables { - fn empty() -> Self { +impl Default for GlobalVariables { + fn default() -> Self { Self { chain_id: 0, version: 0, @@ -67,8 +62,8 @@ impl Empty for GlobalVariables { } #[test] -fn serialization_of_empty() { - let vars: GlobalVariables = dep::std::unsafe::zeroed(); +fn serialization_of_default() { + let vars = GlobalVariables::default(); let _serialized = vars.serialize(); let _deserialized = GlobalVariables::deserialize(_serialized); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr index d7e4cca3fe8..af769450977 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr @@ -57,6 +57,15 @@ impl Empty for SideEffect { } } +impl Default for SideEffect { + fn default() -> Self { + SideEffect { + value: 0, + counter: 0, + } + } +} + impl Hash for SideEffect { fn hash(self) -> Field { dep::std::hash::pedersen_hash_with_separator( @@ -85,6 +94,26 @@ struct SideEffectLinkedToNoteHash{ counter: u32, } +impl Empty for SideEffectLinkedToNoteHash { + fn empty() -> Self { + SideEffectLinkedToNoteHash { + value: 0, + note_hash: 0, + counter: 0, + } + } +} + +impl Default for SideEffectLinkedToNoteHash { + fn default() -> Self { + SideEffectLinkedToNoteHash { + value: 0, + note_hash: 0, + counter: 0, + } + } +} + impl Ordered for SideEffectLinkedToNoteHash { fn counter(self) -> u32 { self.counter @@ -108,16 +137,6 @@ impl Eq for SideEffectLinkedToNoteHash { } } -impl Empty for SideEffectLinkedToNoteHash { - fn empty() -> Self { - SideEffectLinkedToNoteHash { - value: 0, - note_hash: 0, - counter: 0, - } - } -} - impl Hash for SideEffectLinkedToNoteHash { fn hash(self) -> Field { dep::std::hash::pedersen_hash_with_separator( diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr index 7ffcd895653..e356edf8cd1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr @@ -32,8 +32,8 @@ impl Default for Header { Self { last_archive: AppendOnlyTreeSnapshot::default(), content_commitment: ContentCommitment::default(), - state: StateReference::empty(), - global_variables: GlobalVariables::empty(), + state: StateReference::default(), + global_variables: GlobalVariables::default(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr b/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr index d19f27bc62e..3f0451bce63 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr @@ -1,7 +1,8 @@ use crate::{ abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot, constants::PARTIAL_STATE_REFERENCE_LENGTH, - traits::{Deserialize, Empty, Hash, Serialize} + traits::{Deserialize, Hash, Serialize} }; +use dep::std::default::Default; struct PartialStateReference { note_hash_tree: AppendOnlyTreeSnapshot, @@ -17,6 +18,16 @@ impl Eq for PartialStateReference { } } +impl Default for PartialStateReference { + fn default() -> Self { + Self { + note_hash_tree: AppendOnlyTreeSnapshot::default(), + nullifier_tree: AppendOnlyTreeSnapshot::default(), + public_data_tree: AppendOnlyTreeSnapshot::default(), + } + } +} + impl Serialize for PartialStateReference { fn serialize(self) -> [Field; PARTIAL_STATE_REFERENCE_LENGTH] { let serialized_note_hash_tree = self.note_hash_tree.serialize(); @@ -50,19 +61,11 @@ impl Deserialize for PartialStateReference { } } -impl Empty for PartialStateReference { - fn empty() -> Self { - Self { - note_hash_tree: AppendOnlyTreeSnapshot::default(), - nullifier_tree: AppendOnlyTreeSnapshot::default(), - public_data_tree: AppendOnlyTreeSnapshot::default(), - } - } -} + #[test] -fn serialization_of_empty() { - let partial: PartialStateReference = dep::std::unsafe::zeroed(); +fn serialization_of_default() { + let partial = PartialStateReference::default(); let _serialized = partial.serialize(); let _deserialized = PartialStateReference::deserialize(_serialized); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr index 4b1878620d3..2f4004a1c2f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr @@ -1,7 +1,7 @@ use crate::{ abis::append_only_tree_snapshot::{AppendOnlyTreeSnapshot, APPEND_ONLY_TREE_SNAPSHOT_LENGTH}, constants::{PARTIAL_STATE_REFERENCE_LENGTH, STATE_REFERENCE_LENGTH}, - partial_state_reference::PartialStateReference, traits::{Deserialize, Empty, Hash, Serialize}, + partial_state_reference::PartialStateReference, traits::{Deserialize, Hash, Serialize}, utils::arr_copy_slice }; @@ -17,6 +17,15 @@ impl Eq for StateReference { } } +impl Default for StateReference { + fn default() -> Self { + Self { + l1_to_l2_message_tree: AppendOnlyTreeSnapshot::default(), + partial: PartialStateReference::default(), + } + } +} + impl Serialize for StateReference { fn serialize(self) -> [Field; STATE_REFERENCE_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(); @@ -44,18 +53,9 @@ impl Deserialize for StateReference { } } -impl Empty for StateReference { - fn empty() -> Self { - Self { - l1_to_l2_message_tree: AppendOnlyTreeSnapshot::default(), - partial: PartialStateReference::empty(), - } - } -} - #[test] fn serialization_of_empty() { - let state: StateReference = dep::std::unsafe::zeroed(); + let state = StateReference::default(); let _serialized = state.serialize(); let _deserialized = StateReference::deserialize(_serialized); } From f04fb221c245d4856d2d3f1f1cfee74cc299195d Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 10 Apr 2024 09:20:01 +0000 Subject: [PATCH 63/77] test --- .../aztec/src/context/private_context.nr | 6 +- .../crates/private-kernel-lib/src/common.nr | 4 +- .../crates/public-kernel-lib/src/common.nr | 8 +-- .../src/public_kernel_tail.nr | 4 +- .../crates/public-kernel-lib/src/utils.nr | 5 +- .../src/non_existent_read_request_reset.nr | 4 +- .../src/nullifier_read_request_reset.nr | 4 +- .../private_validation_request_processor.nr | 4 +- .../src/read_request_reset.nr | 27 +++++---- .../nullifier_read_request_hints_builder.nr | 2 +- .../rollup-lib/src/base/base_rollup_inputs.nr | 15 ++--- .../abis/nullifier_key_validation_request.nr | 11 ++-- .../src/abis/private_circuit_public_inputs.nr | 4 +- .../src/abis/public_circuit_public_inputs.nr | 6 +- .../crates/types/src/abis/read_request.nr | 15 +++-- .../src/contrakt/storage_update_request.nr | 14 ++--- .../types/src/merkle_tree/indexed_tree.nr | 8 +-- .../crates/types/src/public_data_tree_leaf.nr | 13 +---- .../src/public_data_tree_leaf_preimage.nr | 25 +++++---- .../src/tests/public_call_data_builder.nr | 2 +- .../crates/types/src/utils/arrays.nr | 56 +++++++++---------- 21 files changed, 118 insertions(+), 119 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 6401689d23d..f40c04f09cd 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -484,9 +484,9 @@ impl PrivateContext { call_context: reader.read_struct(CallContext::deserialize), args_hash: reader.read(), return_values: [0; RETURN_VALUES_LENGTH], - nullifier_read_requests: [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], - nullifier_non_existent_read_requests: [ReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], - contract_storage_update_requests: [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], + nullifier_read_requests: [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], + nullifier_non_existent_read_requests: [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], + contract_storage_update_requests: [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], contract_storage_reads: [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL], public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], new_note_hashes: [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL], diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr index a036c2ed507..cd21c833c21 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr @@ -203,7 +203,7 @@ pub fn update_end_values( let nullifier_read_requests = private_call_public_inputs.nullifier_read_requests; for i in 0..MAX_NULLIFIER_READ_REQUESTS_PER_CALL { let request = nullifier_read_requests[i]; - if !is_empty(request) { + if !is_default(request) { public_inputs.validation_requests.nullifier_read_requests.push(request.to_context(storage_contract_address)); } } @@ -212,7 +212,7 @@ pub fn update_end_values( let nullifier_key_validation_requests = private_call_public_inputs.nullifier_key_validation_requests; for i in 0..MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL { let request = nullifier_key_validation_requests[i]; - if !is_empty(request) { + if !is_default(request) { public_inputs.validation_requests.nullifier_key_validation_requests.push(request.to_context(storage_contract_address)); } } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index f153299d78b..7716c4117d7 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -220,7 +220,7 @@ fn propagate_nullifier_read_requests( for i in 0..MAX_NULLIFIER_READ_REQUESTS_PER_CALL { let request = nullifier_read_requests[i]; - if !is_empty(request) { + if !is_default(request) { circuit_outputs.validation_requests.nullifier_read_requests.push(request.to_context(storage_contract_address)); } } @@ -236,7 +236,7 @@ fn propagate_nullifier_non_existent_read_requests( for i in 0..MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL { let request = nullifier_non_existent_read_requests[i]; - if !is_empty(request) { + if !is_default(request) { circuit_outputs.validation_requests.nullifier_non_existent_read_requests.push(request.to_context(storage_contract_address)); } } @@ -253,7 +253,7 @@ fn propagate_valid_public_data_update_requests( for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { let update_request = update_requests[i]; - if (!update_request.is_empty()) { + if (!is_default(update_request)) { let public_data_update_request = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value) @@ -276,7 +276,7 @@ fn propagate_valid_non_revertible_public_data_update_requests( for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { let update_request = update_requests[i]; - if (!update_request.is_empty()) { + if (!is_default(update_request)) { let public_data_update_request = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value) diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr index 7debfd4f402..dd824c7c028 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr @@ -10,7 +10,7 @@ use dep::types::{ }, constants::MAX_NEW_NULLIFIERS_PER_TX, utils::{arrays::{array_length, array_merge, array_to_bounded_vec, assert_sorted_array}}, - hash::silo_nullifier, traits::is_empty + hash::silo_nullifier, traits::is_default }; use dep::std::unsafe; @@ -73,7 +73,7 @@ impl PublicKernelTailCircuitPrivateInputs { let mut read_requests = self.previous_kernel.public_inputs.validation_requests.nullifier_non_existent_read_requests; for i in 0..read_requests.len() { let read_request = read_requests[i]; - if !is_empty(read_request) { + if !is_default(read_request) { read_requests[i].value = silo_nullifier(read_request.contract_address, read_request.value); } } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr index 2cbdf5c485d..54175f39d1e 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr @@ -6,7 +6,8 @@ use dep::types::{ }, address::AztecAddress, contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, - utils::{arrays::array_eq} + utils::{arrays::array_eq}, + traits::is_default }; pub fn compute_public_data_reads( @@ -37,7 +38,7 @@ pub fn compute_public_data_update_requests( let mut public_data_update_requests = [PublicDataUpdateRequest::empty(); N]; for i in 0..N { let update_request = update_requests[i]; - if !update_request.is_empty() { + if !is_default(update_request) { public_data_update_requests[i] = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value), diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr index 4beeee665ae..0b35573deaf 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr @@ -1,7 +1,7 @@ use dep::types::{ abis::{side_effect::OrderedValue, read_request::ReadRequestContext}, merkle_tree::{assert_check_non_membership, IndexedTreeLeafPreimage, MembershipWitness}, - traits::{Empty, is_empty} + traits::is_default }; trait NonMembershipHint where LEAF_PREIMAGE: IndexedTreeLeafPreimage { @@ -63,7 +63,7 @@ pub fn reset_non_existent_read_requests Self { +impl Default for ReadRequestStatus { + fn default() -> Self { ReadRequestStatus { state: ReadRequestState.NADA, hint_index: 0 } } } @@ -112,7 +112,7 @@ fn propagate_unverified_read_requests Self { + TestLeafPreimage { + value: 0 + } + } + } + struct TestSettledReadHint { read_request_index: u64, membership_witness: MembershipWitness<3>, @@ -204,8 +212,8 @@ mod tests { fn nada(read_request_len: u64) -> Self { TestSettledReadHint { read_request_index: read_request_len, - membership_witness: unsafe::zeroed(), - leaf_preimage: unsafe::zeroed() + membership_witness: MembershipWitness::default(), + leaf_preimage: TestLeafPreimage::default() } } } @@ -327,9 +335,9 @@ mod tests { #[test] fn test_propagate_unverified_read_requests() { let read_request_statuses = [ - ReadRequestStatus::empty(), + ReadRequestStatus::default(), ReadRequestStatus { state: ReadRequestState.PENDING, hint_index: 0 }, - ReadRequestStatus::empty(), + ReadRequestStatus::default(), ReadRequestStatus { state: ReadRequestState.SETTLED, hint_index: 0 } ]; let pending_read_hints = [pending_read_hints[0]]; @@ -418,4 +426,3 @@ mod tests { assert(unverified_read_requests.len() == 0); } } - 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 355106e7978..3a6170a97b4 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 @@ -13,7 +13,7 @@ struct NullifierReadRequestHintsBuilder { impl NullifierReadRequestHintsBuilder { pub fn new(read_request_len: u64) -> Self { NullifierReadRequestHintsBuilder { - read_request_statuses: [ReadRequestStatus::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX], + read_request_statuses: [ReadRequestStatus::default(); MAX_NULLIFIER_READ_REQUESTS_PER_TX], pending_read_hints: BoundedVec { storage: [PendingReadHint::nada(read_request_len); MAX_NULLIFIER_READ_REQUESTS_PER_TX], len: 0 }, settled_read_hints: BoundedVec { storage: [NullifierSettledReadHint::nada(read_request_len); MAX_NULLIFIER_READ_REQUESTS_PER_TX], diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr index cc7f2b97399..501f90cfca3 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -273,7 +273,7 @@ fn insert_public_data_update_requests( ), |low_preimage: PublicDataTreeLeafPreimage, write: PublicDataTreeLeaf| { // Is valid low preimage let is_update = low_preimage.slot == write.slot; - let is_low_empty = low_preimage.is_empty(); + let is_low_default = is_default(low_preimage); let is_less_than_slot = full_field_less_than(low_preimage.slot, write.slot); let is_next_greater_than = full_field_less_than(write.slot, low_preimage.next_slot); @@ -281,7 +281,7 @@ fn insert_public_data_update_requests( is_next_greater_than | ((low_preimage.next_index == 0) & (low_preimage.next_slot == 0))); - (!is_low_empty) & (is_update | is_in_range) + (!is_low_default) & (is_update | is_in_range) }, |low_preimage: PublicDataTreeLeafPreimage, write: PublicDataTreeLeaf, write_index: u64| { // Update low leaf let is_update = low_preimage.slot == write.slot; @@ -304,7 +304,7 @@ fn insert_public_data_update_requests( |write: PublicDataTreeLeaf, low_preimage: PublicDataTreeLeafPreimage| { // Build insertion leaf let is_update = low_preimage.slot == write.slot; if is_update { - PublicDataTreeLeafPreimage::empty() + PublicDataTreeLeafPreimage::default() }else { PublicDataTreeLeafPreimage { slot: write.slot, @@ -330,7 +330,7 @@ fn validate_public_data_reads( let low_preimage = public_data_reads_preimages[i]; let witness = public_data_reads_witnesses[i]; - let is_low_empty = low_preimage.is_empty(); + let is_low_default = is_default(low_preimage); let is_exact = low_preimage.slot == read.leaf_slot; let is_less_than_slot = full_field_less_than(low_preimage.slot, read.leaf_slot); @@ -339,7 +339,7 @@ fn validate_public_data_reads( & (is_next_greater_than | ((low_preimage.next_index == 0) & (low_preimage.next_slot == 0))); if (!read.is_empty()) { - assert(!is_low_empty, "public data read is not empty but low preimage is empty"); + assert(!is_low_default, "public data read is not empty but low preimage is empty"); if is_in_range { assert_eq(read.value, 0, "low leaf for public data read is in range but value is not zero"); } else { @@ -414,6 +414,7 @@ mod tests { fixture_builder::FixtureBuilder, merkle_tree_utils::{NonEmptyMerkleTree, compute_zero_hashes}, sort::sort_high_to_low }, + traits::is_default, utils::{field::{full_field_less_than, field_from_bytes_32_trunc, field_from_bytes}, uint256::U256} }; @@ -462,7 +463,7 @@ mod tests { sorted_public_data_writes[i] = leaf; sorted_public_data_writes_indexes[i] = sorted_write_tuples[i].original_index; - if !leaf.is_empty() { + if !is_default(leaf) { let low_leaf = pre_existing_public_data[low_leaf_index]; if low_leaf.slot == leaf.slot { pre_existing_public_data[low_leaf_index].value = leaf.value; @@ -492,7 +493,7 @@ mod tests { ); } } else { - sorted_public_data_writes[i] = PublicDataTreeLeaf::empty(); + sorted_public_data_writes[i] = PublicDataTreeLeaf::default(); sorted_public_data_writes_indexes[i] = i; } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr index 413f3f0173f..81f8bfb17c1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr @@ -2,7 +2,7 @@ use dep::std::cmp::Eq; use crate::{ address::AztecAddress, constants::{NULLIFIER_KEY_VALIDATION_REQUEST_CONTEXT_LENGTH, NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH}, - traits::{Empty, Serialize, Deserialize}, grumpkin_point::GrumpkinPoint, + traits::{Serialize, Deserialize}, grumpkin_point::GrumpkinPoint, grumpkin_private_key::GrumpkinPrivateKey }; @@ -18,8 +18,8 @@ impl Eq for NullifierKeyValidationRequest { } } -impl Empty for NullifierKeyValidationRequest { - fn empty() -> Self { +impl Default for NullifierKeyValidationRequest { + fn default() -> Self { NullifierKeyValidationRequest { public_key: GrumpkinPoint::default(), secret_key: GrumpkinPrivateKey::default(), @@ -67,8 +67,8 @@ impl Eq for NullifierKeyValidationRequestContext { } } -impl Empty for NullifierKeyValidationRequestContext { - fn empty() -> Self { +impl Default for NullifierKeyValidationRequestContext { + fn default() -> Self { NullifierKeyValidationRequestContext { public_key: GrumpkinPoint::default(), secret_key: GrumpkinPrivateKey::default(), @@ -98,4 +98,3 @@ impl Deserialize for NullifierK } } } - diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr index 26638a3df84..23dd6eea3d5 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr @@ -139,8 +139,8 @@ impl Deserialize for PrivateCircuitPublicI min_revertible_side_effect_counter: reader.read() as u32, max_block_number: reader.read_struct(MaxBlockNumber::deserialize), note_hash_read_requests: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]), - nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), - nullifier_key_validation_requests: reader.read_struct_array(NullifierKeyValidationRequest::deserialize, [NullifierKeyValidationRequest::empty(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL]), + nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), + nullifier_key_validation_requests: reader.read_struct_array(NullifierKeyValidationRequest::deserialize, [NullifierKeyValidationRequest::default(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL]), new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL]), new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL]), private_call_stack_hashes: reader.read_array([0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL]), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index e4072aafc0c..d2ff90cef50 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -107,9 +107,9 @@ impl Deserialize for PublicCircuitPublicInp call_context: reader.read_struct(CallContext::deserialize), args_hash: reader.read(), return_values: reader.read_array([0; RETURN_VALUES_LENGTH]), - nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), - nullifier_non_existent_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL]), - contract_storage_update_requests: reader.read_struct_array(StorageUpdateRequest::deserialize, [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL]), + nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), + nullifier_non_existent_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL]), + contract_storage_update_requests: reader.read_struct_array(StorageUpdateRequest::deserialize, [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL]), contract_storage_reads: reader.read_struct_array(StorageRead::deserialize, [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL]), public_call_stack_hashes: reader.read_array([0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL]), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr index 4ce713c069a..7fa992e0a20 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr @@ -1,8 +1,8 @@ use crate::{ abis::side_effect::{OrderedValue, ContractScopedOrderedValue}, - traits::{Empty, Serialize, Deserialize}, address::AztecAddress + traits::{Serialize, Deserialize}, address::AztecAddress }; -use dep::std::cmp::Eq; +use dep::std::{cmp::Eq,default::Default}; global READ_REQUEST_SERIALIZED_LEN = 2; global READ_REQUEST_CONTEXT_SERIALIZED_LEN = 3; @@ -28,8 +28,8 @@ impl Eq for ReadRequest { } } -impl Empty for ReadRequest { - fn empty() -> Self { +impl Default for ReadRequest { + fn default() -> Self { ReadRequest { value: 0, counter: 0, @@ -93,12 +93,12 @@ impl Eq for ReadRequestContext { } } -impl Empty for ReadRequestContext { - fn empty() -> Self { +impl Default for ReadRequestContext { + fn default() -> Self { ReadRequestContext { value: 0, counter: 0, - contract_address: AztecAddress::zero(), + contract_address: AztecAddress::default(), } } } @@ -118,4 +118,3 @@ impl Deserialize for ReadRequestContext { } } } - diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr index 01176175f60..4e09efc3969 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr @@ -1,8 +1,8 @@ use crate::{ constants::{CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH, GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST}, - hash::pedersen_hash, traits::{Deserialize, Hash, Empty, Serialize} + hash::pedersen_hash, traits::{Deserialize, Hash, Serialize} }; -use dep::std::cmp::Eq; +use dep::std::{cmp::Eq,default::Default}; struct StorageUpdateRequest{ storage_slot : Field, @@ -16,8 +16,8 @@ impl Eq for StorageUpdateRequest { } } -impl Empty for StorageUpdateRequest { - fn empty() -> Self { +impl Default for StorageUpdateRequest { + fn default() -> Self { StorageUpdateRequest { storage_slot: 0, new_value: 0, @@ -45,9 +45,3 @@ impl Deserialize for StorageUpdateReques } } } - -impl StorageUpdateRequest { - pub fn is_empty(self) -> bool { - self.storage_slot == 0 - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr index 6cfc75baaf6..f5a5938ce81 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr @@ -4,7 +4,7 @@ use crate::{ membership::{assert_check_membership, MembershipWitness}, root::{calculate_subtree_root, calculate_empty_tree_root, root_from_sibling_path} }, - traits::{Empty, Hash, is_empty}, utils::arrays::check_permutation + traits::{Default, Hash, is_default}, utils::arrays::check_permutation }; pub fn batch_insert( @@ -20,18 +20,18 @@ pub fn batch_insert Leaf, _subtree_height: [Field; SubtreeHeight], _tree_height: [Field; TreeHeight] -) -> AppendOnlyTreeSnapshot where Value: Eq + Empty, Leaf: Hash { +) -> AppendOnlyTreeSnapshot where Value: Eq + Default, Leaf: Hash + Default { // A permutation to the values is provided to make the insertion use only one insertion strategy check_permutation(values_to_insert, sorted_values, sorted_values_indexes); // Now, update the existing leaves with the new leaves let mut current_tree_root = start_snapshot.root; - let mut insertion_subtree: [Leaf; SubtreeWidth] = dep::std::unsafe::zeroed(); + let mut insertion_subtree = [Leaf::default(); SubtreeWidth]; let start_insertion_index = start_snapshot.next_available_leaf_index; for i in 0..sorted_values.len() { let value = sorted_values[i]; - if !is_empty(value) { + if !is_default(value) { let low_leaf_preimage = low_leaf_preimages[i]; let witness = low_leaf_membership_witnesses[i]; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr index 57eb1945a3a..09bf94a1409 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr @@ -1,5 +1,4 @@ -use crate::traits::Empty; -use dep::std::cmp::Eq; +use dep::std::{cmp::Eq,default::Default}; struct PublicDataTreeLeaf { slot: Field, @@ -12,17 +11,11 @@ impl Eq for PublicDataTreeLeaf { } } -impl Empty for PublicDataTreeLeaf { - fn empty() -> Self { +impl Default for PublicDataTreeLeaf { + fn default() -> Self { Self { slot: 0, value: 0, } } } - -impl PublicDataTreeLeaf { - pub fn is_empty(self) -> bool { - (self.slot == 0) & (self.value == 0) - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf_preimage.nr b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf_preimage.nr index dcc84fe7026..c5baa57edcf 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf_preimage.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf_preimage.nr @@ -1,4 +1,6 @@ -use crate::traits::{Empty, Hash}; +use crate::traits::Hash; +use dep::std::default::Default; +use crate::traits::is_default; struct PublicDataTreeLeafPreimage { slot : Field, @@ -7,8 +9,17 @@ struct PublicDataTreeLeafPreimage { next_index : u64, } -impl Empty for PublicDataTreeLeafPreimage { - fn empty() -> Self { +impl Eq for PublicDataTreeLeafPreimage { + fn eq(self, public_data_tree_leaf_preimage: PublicDataTreeLeafPreimage) -> bool { + (public_data_tree_leaf_preimage.slot == self.slot) + & (public_data_tree_leaf_preimage.value == self.value) + & (public_data_tree_leaf_preimage.next_slot == self.next_slot) + & (public_data_tree_leaf_preimage.next_index == self.next_index) + } +} + +impl Default for PublicDataTreeLeafPreimage { + fn default() -> Self { Self { slot: 0, value: 0, @@ -20,16 +31,10 @@ impl Empty for PublicDataTreeLeafPreimage { impl Hash for PublicDataTreeLeafPreimage { fn hash(self) -> Field { - if self.is_empty() { + if is_default(self) { 0 } else { dep::std::hash::pedersen_hash([self.slot, self.value, (self.next_index as Field), self.next_slot]) } } } - -impl PublicDataTreeLeafPreimage { - pub fn is_empty(self) -> bool { - (self.slot == 0) & (self.value == 0) & (self.next_slot == 0) & (self.next_index == 0) - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr index 38c39e18ff7..a2c82f9e760 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr @@ -142,7 +142,7 @@ impl PublicCallDataBuilder { pub fn append_empty_update_requests(&mut self, num_updates: u64) { for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { if i < num_updates { - self.public_inputs.contract_storage_update_requests.push(StorageUpdateRequest::empty()); + self.public_inputs.contract_storage_update_requests.push(StorageUpdateRequest::default()); } } } 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 4de0a338525..ee861a86406 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 @@ -1,11 +1,11 @@ use dep::std::array; use dep::std::cmp::Eq; -use crate::traits::{Empty, is_empty}; +use crate::traits::is_default; -pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Empty + Eq { +pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Default + Eq { let mut len = 0; for elem in array { - if !is_empty(elem) { + if !is_default(elem) { len += 1; } } @@ -16,30 +16,30 @@ pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Em // Routine which validates that all zero values of an array form a contiguous region at the end, i.e., // of the form: [*,*,*...,0,0,0,0] where any * is non-zero. Note that a full array of non-zero values is // valid. -pub fn validate_array(array: [T; N]) where T: Empty + Eq { +pub fn validate_array(array: [T; N]) where T: Default + Eq { let array_length = array.len(); let mut first_zero_pos = array_length; let mut last_non_zero_pos = 0; for i in 0..array_length { - let is_empty = is_empty(array[i]); - if !is_empty { + let is_default = is_default(array[i]); + if !is_default { last_non_zero_pos = i; - } else if is_empty & (first_zero_pos == array_length) { + } else if is_default & (first_zero_pos == array_length) { first_zero_pos = i; } } assert(last_non_zero_pos <= first_zero_pos, "invalid array"); } -// Helper method to determine the number of non-zero/empty elements in a validated array (ie, validate_array(array) +// Helper method to determine the number of non-zero/default elements in a validated array (ie, validate_array(array) // should be true). -pub fn array_length(array: [T; N]) -> u64 where T: Empty + Eq { +pub fn array_length(array: [T; N]) -> u64 where T: Default + Eq { let mut length = 0; let mut end = false; for elem in array { - end |= is_empty(elem); + end |= is_default(elem); if !end { length += 1; } @@ -47,7 +47,7 @@ pub fn array_length(array: [T; N]) -> u64 where T: Empty + Eq { length } -pub fn array_eq(array: [T; N], expected: [T; S]) -> bool where T: Empty + Eq { +pub fn array_eq(array: [T; N], expected: [T; S]) -> bool where T: Default + Eq { let mut eq = array_length(array) == S; for i in 0..S { @@ -67,25 +67,25 @@ pub fn find_index(array: [T; N], find: fn[Env](T) -> bool) -> u64 { index } -pub fn array_cp(array: [T; N]) -> [T; S] where T: Empty { - let mut result: [T; S] = [T::empty(); S]; +pub fn array_cp(array: [T; N]) -> [T; S] where T: Default { + let mut result: [T; S] = [T::default(); S]; for i in 0..S { result[i] = array[i]; } result } -pub fn array_merge(array1: [T; N], array2: [T; N]) -> [T; N] where T: Empty + Eq { - let mut result: [T; N] = [T::empty(); N]; +pub fn array_merge(array1: [T; N], array2: [T; N]) -> [T; N] where T: Default + Eq { + let mut result: [T; N] = [T::default(); N]; let mut i = 0; for elem in array1 { - if !is_empty(elem) { + if !is_default(elem) { result[i] = elem; i += 1; } } for elem in array2 { - if !is_empty(elem) { + if !is_default(elem) { result[i] = elem; i += 1; } @@ -97,7 +97,7 @@ pub fn check_permutation( original_array: [T; N], permuted_array: [T; N], original_indexes: [u64; N] -) where T: Eq + Empty { +) where T: Eq + Default { let mut seen_value = [false; N]; for i in 0..N { let index = original_indexes[i]; @@ -113,15 +113,15 @@ pub fn assert_sorted_array( sorted_array: [T; N], sorted_indexes: [u64; N], ordering: fn[Env](T, T) -> bool -) where T: Eq + Empty { - let mut seen_empty = false; +) where T: Eq + Default { + let mut seen_default = false; for i in 0..N { let original_value = original_array[i]; - if is_empty(original_value) { - seen_empty = true; - assert(is_empty(sorted_array[i]), "Empty values must not be mixed with sorted values"); + if is_default(original_value) { + seen_default = true; + assert(is_default(sorted_array[i]), "Default values must not be mixed with sorted values"); } else { - assert(!seen_empty, "Empty values must be padded to the right"); + assert(!seen_default, "Default values must be padded to the right"); let index = sorted_indexes[i]; assert(sorted_array[index].eq(original_value), "Invalid index"); @@ -236,7 +236,7 @@ fn assert_sorted_array_desc() { } #[test] -fn assert_sorted_array_all_empty() { +fn assert_sorted_array_all_default() { let original = [0, 0, 0, 0, 0, 0]; let sorted = [0, 0, 0, 0, 0, 0]; let indexes = [0, 0, 0, 0, 0, 0]; @@ -267,7 +267,7 @@ fn assert_sorted_array_failed_wrong_index() { assert_sorted_array(original, sorted, indexes, |a: Field, b: Field| a.lt(b)); } -#[test(should_fail_with="Empty values must be padded to the right")] +#[test(should_fail_with="Default values must be padded to the right")] fn assert_sorted_array_failed_not_padded() { let original = [30, 20, 90, 0, 50, 0]; let sorted = [20, 30, 90, 0, 0, 0]; @@ -275,8 +275,8 @@ fn assert_sorted_array_failed_not_padded() { assert_sorted_array(original, sorted, indexes, |a: Field, b: Field| a.lt(b)); } -#[test(should_fail_with="Empty values must not be mixed with sorted values")] -fn assert_sorted_array_failed_mixed_empty() { +#[test(should_fail_with="Default values must not be mixed with sorted values")] +fn assert_sorted_array_failed_mixed_default() { let original = [30, 20, 90, 0, 0, 0]; let sorted = [20, 30, 90, 0, 0, 10]; let indexes = [1, 0, 2, 0, 0, 0]; From 9eac6ccdfde37c623b9854e7cf56970eb01e59e1 Mon Sep 17 00:00:00 2001 From: Esau Date: Wed, 10 Apr 2024 11:23:16 +0200 Subject: [PATCH 64/77] test --- .../crates/types/src/contrakt.nr | 1 + .../crates/types/src/contrakt/traits.nr | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/contrakt/traits.nr diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt.nr index 1a84b4f0a76..179838fcf08 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt.nr @@ -1,2 +1,3 @@ mod storage_read; mod storage_update_request; +mod traits; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/traits.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/traits.nr new file mode 100644 index 00000000000..d11e0c46b33 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/traits.nr @@ -0,0 +1,42 @@ +// We use this because storage read is_default does not match behavior with the normal way we calculate is_default +trait StorageRequest { + fn is_default(self) -> bool; +} + +pub fn is_default(item: T) -> bool where T: StorageRequest { + item.is_default() +} + +// Routine which validates that all zero values of an array form a contiguous region at the end, i.e., +// of the form: [*,*,*...,0,0,0,0] where any * is non-zero. Note that a full array of non-zero values is +// valid. +pub fn validate_array(array: [T; N]) where T: StorageRequest + Eq { + let array_length = array.len(); + + let mut first_zero_pos = array_length; + let mut last_non_zero_pos = 0; + + for i in 0..array_length { + let is_default = array[i].is_default(); + if !is_default { + last_non_zero_pos = i; + } else if is_default & (first_zero_pos == array_length) { + first_zero_pos = i; + } + } + assert(last_non_zero_pos <= first_zero_pos, "invalid array"); +} + +// Helper method to determine the number of non-zero/default elements in a validated array (ie, validate_array(array) +// should be true). +pub fn array_length(array: [T; N]) -> u64 where T: StorageRequest + Eq { + let mut length = 0; + let mut end = false; + for elem in array { + end |= elem.is_default(); + if !end { + length += 1; + } + } + length +} From 87e9c88668037bf9b6111335771cc495ef1ad01e Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 10 Apr 2024 09:42:07 +0000 Subject: [PATCH 65/77] Test working --- .../aztec-nr/aztec/src/context/private_context.nr | 2 +- .../crates/public-kernel-lib/src/common.nr | 8 ++++---- .../crates/public-kernel-lib/src/utils.nr | 6 +++--- .../rollup-lib/src/base/base_rollup_inputs.nr | 2 +- .../types/src/abis/public_circuit_public_inputs.nr | 2 +- .../crates/types/src/abis/public_data_read.nr | 14 ++++---------- .../types/src/abis/public_data_update_request.nr | 14 ++++---------- .../types/src/contrakt/storage_update_request.nr | 14 ++++++++++---- .../types/src/tests/public_call_data_builder.nr | 2 +- 9 files changed, 29 insertions(+), 35 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index f40c04f09cd..12162d47207 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -486,7 +486,7 @@ impl PrivateContext { return_values: [0; RETURN_VALUES_LENGTH], nullifier_read_requests: [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], nullifier_non_existent_read_requests: [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], - contract_storage_update_requests: [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], + contract_storage_update_requests: [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], contract_storage_reads: [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL], public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], new_note_hashes: [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL], diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index 7716c4117d7..0ca31fc8920 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -118,9 +118,9 @@ fn perform_static_call_checks(public_call: PublicCallData) { let new_nullifiers_length = array_length(public_inputs.new_nullifiers); assert(new_nullifiers_length == 0, "new_nullifiers must be empty for static calls"); - let update_requests_length = array_length(public_inputs.contract_storage_update_requests); + let update_requests_length = is_empty_array(public_inputs.contract_storage_update_requests); assert( - update_requests_length == 0, "No contract storage update requests are allowed for static calls" + update_requests_length, "No contract storage update requests are allowed for static calls" ); let new_l2_to_l1_msgs_length = array_length(public_inputs.new_l2_to_l1_msgs); @@ -253,7 +253,7 @@ fn propagate_valid_public_data_update_requests( for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { let update_request = update_requests[i]; - if (!is_default(update_request)) { + if (!update_request.is_empty()) { let public_data_update_request = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value) @@ -276,7 +276,7 @@ fn propagate_valid_non_revertible_public_data_update_requests( for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { let update_request = update_requests[i]; - if (!is_default(update_request)) { + if (!update_request.is_empty()) { let public_data_update_request = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value) diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr index 54175f39d1e..34bcb4fa218 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr @@ -14,7 +14,7 @@ pub fn compute_public_data_reads( contract_address: AztecAddress, read_requests: [StorageRead; N] ) -> [PublicDataRead; N] { - let mut public_data_reads = [PublicDataRead::empty(); N]; + let mut public_data_reads = [PublicDataRead::default(); N]; for i in 0..N { let read_request = read_requests[i]; if !read_request.is_empty() { @@ -35,10 +35,10 @@ pub fn compute_public_data_update_requests( contract_address: AztecAddress, update_requests: [StorageUpdateRequest; N] ) -> [PublicDataUpdateRequest; N] { - let mut public_data_update_requests = [PublicDataUpdateRequest::empty(); N]; + let mut public_data_update_requests = [PublicDataUpdateRequest::default(); N]; for i in 0..N { let update_request = update_requests[i]; - if !is_default(update_request) { + if !update_request.is_empty() { public_data_update_requests[i] = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value), diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr index 501f90cfca3..827ae9f86c9 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -338,7 +338,7 @@ fn validate_public_data_reads( let is_in_range = is_less_than_slot & (is_next_greater_than | ((low_preimage.next_index == 0) & (low_preimage.next_slot == 0))); - if (!read.is_empty()) { + if (!is_default(read)) { assert(!is_low_default, "public data read is not empty but low preimage is empty"); if is_in_range { assert_eq(read.value, 0, "low leaf for public data read is in range but value is not zero"); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index d2ff90cef50..4448724bf11 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -109,7 +109,7 @@ impl Deserialize for PublicCircuitPublicInp return_values: reader.read_array([0; RETURN_VALUES_LENGTH]), nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), nullifier_non_existent_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL]), - contract_storage_update_requests: reader.read_struct_array(StorageUpdateRequest::deserialize, [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL]), + contract_storage_update_requests: reader.read_struct_array(StorageUpdateRequest::deserialize, [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL]), contract_storage_reads: reader.read_struct_array(StorageRead::deserialize, [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL]), public_call_stack_hashes: reader.read_array([0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL]), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr index f790fe142c8..446d74cfe5f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr @@ -1,6 +1,6 @@ use crate::constants::GENERATOR_INDEX__PUBLIC_DATA_READ; -use dep::std::cmp::Eq; -use crate::traits::{Empty, Hash}; +use dep::std::{cmp::Eq,default::Default}; +use crate::traits::Hash; struct PublicDataRead { leaf_slot : Field, @@ -13,8 +13,8 @@ impl Eq for PublicDataRead { } } -impl Empty for PublicDataRead { - fn empty() -> Self { +impl Default for PublicDataRead { + fn default() -> Self { Self { leaf_slot : 0, value : 0, @@ -30,9 +30,3 @@ impl Hash for PublicDataRead { ], GENERATOR_INDEX__PUBLIC_DATA_READ) } } - -impl PublicDataRead { - pub fn is_empty(self) -> bool { - (self.leaf_slot == 0) & (self.value == 0) - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr index 8177f389f18..2f477fc4b2f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr @@ -1,6 +1,6 @@ use crate::constants::GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST; -use dep::std::cmp::Eq; -use crate::traits::{Empty, Hash}; +use dep::std::{cmp::Eq,default::Default}; +use crate::traits::Hash; struct PublicDataUpdateRequest { leaf_slot : Field, @@ -14,8 +14,8 @@ impl Eq for PublicDataUpdateRequest { } } -impl Empty for PublicDataUpdateRequest { - fn empty() -> Self { +impl Default for PublicDataUpdateRequest { + fn default() -> Self { Self { leaf_slot : 0, new_value : 0 @@ -31,9 +31,3 @@ impl Hash for PublicDataUpdateRequest { ], GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST) } } - -impl PublicDataUpdateRequest { - pub fn is_empty(self) -> bool { - (self.leaf_slot == 0) & (self.new_value == 0) - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr index 4e09efc3969..01176175f60 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr @@ -1,8 +1,8 @@ use crate::{ constants::{CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH, GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST}, - hash::pedersen_hash, traits::{Deserialize, Hash, Serialize} + hash::pedersen_hash, traits::{Deserialize, Hash, Empty, Serialize} }; -use dep::std::{cmp::Eq,default::Default}; +use dep::std::cmp::Eq; struct StorageUpdateRequest{ storage_slot : Field, @@ -16,8 +16,8 @@ impl Eq for StorageUpdateRequest { } } -impl Default for StorageUpdateRequest { - fn default() -> Self { +impl Empty for StorageUpdateRequest { + fn empty() -> Self { StorageUpdateRequest { storage_slot: 0, new_value: 0, @@ -45,3 +45,9 @@ impl Deserialize for StorageUpdateReques } } } + +impl StorageUpdateRequest { + pub fn is_empty(self) -> bool { + self.storage_slot == 0 + } +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr index a2c82f9e760..38c39e18ff7 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr @@ -142,7 +142,7 @@ impl PublicCallDataBuilder { pub fn append_empty_update_requests(&mut self, num_updates: u64) { for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { if i < num_updates { - self.public_inputs.contract_storage_update_requests.push(StorageUpdateRequest::default()); + self.public_inputs.contract_storage_update_requests.push(StorageUpdateRequest::empty()); } } } From 3ef83ec93586403ec28a61bd8c0811724227b732 Mon Sep 17 00:00:00 2001 From: Esau Date: Wed, 10 Apr 2024 11:57:06 +0200 Subject: [PATCH 66/77] hi --- yarn-project/aztec.js/src/entrypoint/default_entrypoint.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/aztec.js/src/entrypoint/default_entrypoint.ts b/yarn-project/aztec.js/src/entrypoint/default_entrypoint.ts index e7a43da5903..e58afca10c2 100644 --- a/yarn-project/aztec.js/src/entrypoint/default_entrypoint.ts +++ b/yarn-project/aztec.js/src/entrypoint/default_entrypoint.ts @@ -18,7 +18,7 @@ export class DefaultEntrypoint implements EntrypointInterface { const call = calls[0]; const entrypointPackedArguments = PackedArguments.fromArgs(call.args); - const txContext = TxContext.empty(this.chainId, this.protocolVersion); + const txContext = TxContext.default(this.chainId, this.protocolVersion); return Promise.resolve( new TxExecutionRequest( call.to, From ff308f0c1d1322025cfd5d9bf33fe126b466c29b Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 10 Apr 2024 10:33:38 +0000 Subject: [PATCH 67/77] go --- .../crates/private-kernel-lib/src/common.nr | 13 ++++++------ .../kernel_circuit_public_inputs_composer.nr | 6 +++--- .../src/private_kernel_init.nr | 3 +-- .../src/private_kernel_inner.nr | 10 +++++----- .../src/private_kernel_tail.nr | 17 ++++++++-------- .../src/private_kernel_tail_to_public.nr | 20 +++++++++---------- .../private_accumulated_data_builder.nr | 16 +++++++++++++++ ...te_kernel_circuit_public_inputs_builder.nr | 12 +++++++++++ 8 files changed, 63 insertions(+), 34 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr index cd21c833c21..a0ba9916c4d 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr @@ -21,7 +21,7 @@ use dep::types::{ }, merkle_tree::check_membership, utils::{arrays::{array_length, array_to_bounded_vec, validate_array}}, - traits::{is_empty, is_empty_array, is_zero, is_default} + traits::{is_default, is_default_array, is_zero} }; pub fn validate_arrays(app_public_inputs: PrivateCircuitPublicInputs) { @@ -120,14 +120,15 @@ fn perform_static_call_checks(private_call: PrivateCallData) { if is_static_call { // No state changes are allowed for static calls: assert( - is_empty_array(public_inputs.new_note_hashes), "new_note_hashes must be empty for static calls" + is_default_array(public_inputs.new_note_hashes), "new_note_hashes must be empty (only default values) for static calls" ); assert( - is_empty_array(public_inputs.new_nullifiers), "new_nullifiers must be empty for static calls" + is_default_array(public_inputs.new_nullifiers), "new_nullifiers must be empty (only default values) for static calls" ); + // TODO: #5618 let new_l2_to_l1_msgs_length = array_length(public_inputs.new_l2_to_l1_msgs); - assert(new_l2_to_l1_msgs_length == 0, "new_l2_to_l1_msgs must be empty for static calls"); + assert(new_l2_to_l1_msgs_length == 0, "new_l2_to_l1_msgs must be empty (length 0) for static calls"); // TODO: reevaluate when implementing https://github.com/AztecProtocol/aztec-packages/issues/1165 // This 4 magical number is the minimum size of the buffer, since it has to store the total length of all the serialized logs. @@ -277,7 +278,7 @@ pub fn update_end_values( let mut new_l2_to_l1_msgs_to_insert : BoundedVec = BoundedVec::new(); for i in 0..MAX_NEW_L2_TO_L1_MSGS_PER_CALL { let msg = new_l2_to_l1_msgs[i]; - if !is_empty(msg) { + if !is_default(msg) { let new_l2_to_l1_msgs = compute_l2_to_l1_hash( storage_contract_address, private_call_public_inputs.version, @@ -311,7 +312,7 @@ pub fn contract_logic(private_call: PrivateCallData) { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3062): Why is this using a hash function from the stdlib::recursion namespace let private_call_vk_hash = stdlib_recursion_verification_key_compress_native_vk(private_call.vk); - assert(!is_zero(contract_address), "contract address cannot be zero"); + assert(!is_zero(contract_address), "Contract address cannot be zero"); // std::println(f"contract_address={contract_address}"); // std::println(f"private_call_vk_hash={private_call_vk_hash}"); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr index c2a16634303..ad495b68c8a 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr @@ -14,7 +14,7 @@ use dep::types::{ }, grumpkin_private_key::GrumpkinPrivateKey, hash::{compute_note_hash_nonce, compute_unique_siloed_note_hash}, - utils::arrays::{array_length, array_to_bounded_vec, assert_sorted_array}, traits::{Empty, is_empty} + utils::arrays::{array_length, array_to_bounded_vec, assert_sorted_array}, }; fn asc_sort_by_counters(a: T, b: T) -> bool where T: Ordered { @@ -178,8 +178,8 @@ impl KernelCircuitPublicInputsComposer { // match found! // squash both the nullifier and the hash // (set to 0 here and then rearrange array after loop) - new_note_hashes[hint_pos] = SideEffect::empty(); - new_nullifiers[n_idx] = SideEffectLinkedToNoteHash::empty(); + new_note_hashes[hint_pos] = SideEffect::default(); + new_nullifiers[n_idx] = SideEffectLinkedToNoteHash::default(); } // non-transient (persistable) nullifiers are just kept in new_nullifiers array and forwarded // to public inputs (used later by base rollup circuit) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr index 10affa6a543..6e69c8d4b33 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr @@ -8,7 +8,6 @@ use dep::types::{ }, address::{AztecAddress, PublicKeysHash, compute_initialization_hash}, mocked::{Proof, verify_previous_kernel_state}, transaction::tx_request::TxRequest, - traits::is_empty_array }; // Initialization struct for private inputs to the private kernel @@ -77,7 +76,7 @@ impl PrivateKernelInitCircuitPrivateInputs { } pub fn native_private_kernel_circuit_initial(self) -> PrivateKernelCircuitPublicInputs { - let mut public_inputs: PrivateKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let mut public_inputs = PrivateKernelCircuitPublicInputsBuilder::default(); self.initialize_end_values(&mut public_inputs); 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 69a6258ccb9..cf2cb07181b 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 @@ -27,7 +27,7 @@ impl PrivateKernelInnerCircuitPrivateInputs { } pub fn native_private_kernel_circuit_inner(self) -> PrivateKernelCircuitPublicInputs { - let mut public_inputs : PrivateKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let mut public_inputs = PrivateKernelCircuitPublicInputsBuilder::default(); common::validate_previous_kernel_values(self.previous_kernel.public_inputs.end); @@ -219,12 +219,12 @@ mod tests { } #[test(should_fail_with="caller context cannot be default for delegate calls")] - fn empty_caller_context_for_delegate_calls_fails() { + fn default_caller_context_for_delegate_calls_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_delegate_call(); let private_call = builder.private_call.finish(); let hash = private_call.call_stack_item.hash(); - // Caller context is empty for regular calls. + // Caller context is default for regular calls. let is_delegate_call = false; builder.previous_kernel.push_private_call_request(hash, is_delegate_call); let previous_kernel = builder.previous_kernel.to_private_kernel_data(); @@ -691,7 +691,7 @@ mod tests { assert_eq(public_inputs.end.unencrypted_logs_hash, expected_unencrypted_logs_hash); } - #[test(should_fail_with="new_note_hashes must be empty for static calls")] + #[test(should_fail_with="new_note_hashes must be a default array (empty) for static calls")] fn creating_new_note_hashes_on_static_call_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_static_call(); @@ -700,7 +700,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_nullifiers must be empty for static calls")] + #[test(should_fail_with="new_nullifiers must be a default array (empty) for static calls")] fn creating_new_nullifiers_on_static_call_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_static_call(); 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 9c1d74fe688..4b24a876cd2 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 @@ -63,17 +63,18 @@ mod tests { read_request_reset::{PendingReadHint, ReadRequestState, ReadRequestStatus} }; use dep::types::constants::{ - MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, - MAX_NULLIFIER_READ_REQUESTS_PER_TX + MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NULLIFIER_READ_REQUESTS_PER_TX, + MAX_NEW_NULLIFIERS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX }; use dep::types::{ abis::{ kernel_circuit_public_inputs::KernelCircuitPublicInputs, max_block_number::MaxBlockNumber, side_effect::{SideEffect, SideEffectLinkedToNoteHash, Ordered} }, + grumpkin_private_key::GrumpkinPrivateKey, hash::{compute_note_hash_nonce, compute_unique_siloed_note_hash}, tests::{fixture_builder::FixtureBuilder, sort::sort_get_sorted_hints}, - utils::{arrays::{array_eq, array_length}}, traits::{Empty, is_empty, is_empty_array} + utils::{arrays::{array_eq, array_length}}, traits::{is_default, is_default_array} }; struct PrivateKernelTailInputsBuilder { @@ -163,7 +164,7 @@ mod tests { sorted_new_nullifiers_indexes, nullifier_read_request_hints: self.nullifier_read_request_hints_builder.to_hints(), nullifier_commitment_hints: sorted_nullifier_commitment_hints, - master_nullifier_secret_keys: unsafe::zeroed() + master_nullifier_secret_keys: [GrumpkinPrivateKey::default(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX] }; kernel.native_private_kernel_circuit_tail() } @@ -269,7 +270,7 @@ mod tests { builder.nullify_pending_note_hash(1, 0); let new_nullifiers = builder.previous_kernel.new_nullifiers.storage; let public_inputs = builder.execute(); - assert(is_empty_array(public_inputs.end.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_note_hashes)); // The nullifier at index 1 is chopped. assert( @@ -320,7 +321,7 @@ mod tests { let public_inputs = builder.execute(); // Only the first nullifier is left after squashing. - assert(is_empty_array(public_inputs.end.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_note_hashes)); assert(array_eq(public_inputs.end.new_nullifiers, [new_nullifiers[0].value])); } @@ -334,8 +335,8 @@ mod tests { let sorted_note_hashes = builder.previous_kernel.new_note_hashes.storage; let sorted_nullifiers = builder.previous_kernel.new_nullifiers.storage; - let mut reversed_note_hashes = [SideEffect::empty(); 10]; - let mut reversed_nullifiers = [SideEffectLinkedToNoteHash::empty(); 10]; + let mut reversed_note_hashes = [SideEffect::default(); 10]; + let mut reversed_nullifiers = [SideEffectLinkedToNoteHash::default(); 10]; for i in 0..10 { reversed_note_hashes[9 - i] = builder.previous_kernel.new_note_hashes.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 e6a9c96be08..d2b371cf57a 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 @@ -73,7 +73,7 @@ mod tests { }, hash::{compute_note_hash_nonce, compute_unique_siloed_note_hash}, tests::{fixture_builder::FixtureBuilder, sort::sort_get_sorted_hints}, - utils::{arrays::{array_eq, array_length}}, traits::is_empty_array + utils::{arrays::{array_eq, array_length}}, traits::is_default_array }; struct PrivateKernelTailToPublicInputsBuilder { @@ -104,7 +104,7 @@ mod tests { note_hashes: [SideEffect; N] ) -> [SideEffect; N] { let first_nullifier = self.previous_kernel.new_nullifiers.get_unchecked(0); - let mut unique_siloed_note_hashes = [SideEffect::empty(); N]; + let mut unique_siloed_note_hashes = [SideEffect::default(); N]; for i in 0..N { if note_hashes[i].value != 0 { let nonce = compute_note_hash_nonce(first_nullifier.value, i); @@ -301,7 +301,7 @@ mod tests { builder.nullify_transient_note_hash(1, 0); let new_nullifiers = builder.previous_kernel.new_nullifiers.storage; let public_inputs = builder.execute(); - assert(is_empty_array(public_inputs.end.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_note_hashes)); // The nullifier at index 1 is chopped. assert( @@ -352,7 +352,7 @@ mod tests { let public_inputs = builder.execute(); // Only the first nullifier is left after squashing. - assert(is_empty_array(public_inputs.end.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_note_hashes)); assert(array_eq(public_inputs.end.new_nullifiers, [new_nullifiers[0]])); } @@ -366,8 +366,8 @@ mod tests { let sorted_note_hashes = builder.previous_kernel.new_note_hashes.storage; let sorted_nullifiers = builder.previous_kernel.new_nullifiers.storage; - let mut reversed_note_hashes = [SideEffect::empty(); 10]; - let mut reversed_nullifiers = [SideEffectLinkedToNoteHash::empty(); 10]; + let mut reversed_note_hashes = [SideEffect::default(); 10]; + let mut reversed_nullifiers = [SideEffectLinkedToNoteHash::default(); 10]; for i in 0..10 { reversed_note_hashes[9 - i] = builder.previous_kernel.new_note_hashes.pop(); @@ -507,9 +507,9 @@ mod tests { let public_inputs = builder.execute(); - assert(!is_empty_array(public_inputs.end_non_revertible.new_nullifiers)); - assert(is_empty_array(public_inputs.end_non_revertible.new_note_hashes)); - assert(is_empty_array(public_inputs.end.new_note_hashes)); - assert(is_empty_array(public_inputs.end.new_nullifiers)); + assert(!is_default_array(public_inputs.end_non_revertible.new_nullifiers)); + assert(is_default_array(public_inputs.end_non_revertible.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_note_hashes)); + assert(is_default_array(public_inputs.end.new_nullifiers)); } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr index e8d45bbaa96..04f1546addf 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr @@ -33,6 +33,22 @@ struct PrivateAccumulatedDataBuilder { public_call_stack: BoundedVec, } +impl Default for PrivateAccumulatedDataBuilder { + fn default() -> Self { + PrivateAccumulatedDataBuilder { + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + new_l2_to_l1_msgs: BoundedVec::new(), + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + private_call_stack: BoundedVec::new(), + public_call_stack: BoundedVec::new(), + } + } +} + impl PrivateAccumulatedDataBuilder { pub fn finish(self) -> PrivateAccumulatedData { PrivateAccumulatedData { 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 194cd7df510..dc211a13ea4 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 @@ -18,6 +18,18 @@ struct PrivateKernelCircuitPublicInputsBuilder { constants: CombinedConstantData, } +impl Default for PrivateKernelCircuitPublicInputsBuilder { + fn default() -> Self { + PrivateKernelCircuitPublicInputsBuilder { + aggregation_object: AggregationObject::default(), + min_revertible_side_effect_counter: 0 as u32, + validation_requests: ValidationRequestsBuilder::default(), + end: PrivateAccumulatedDataBuilder::default(), + constants: CombinedConstantData::default(), + } + } +} + impl PrivateKernelCircuitPublicInputsBuilder { pub fn finish(self) -> PrivateKernelCircuitPublicInputs { PrivateKernelCircuitPublicInputs { From 36896923e57f49d69675cbc76759872cd8fd1522 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 10 Apr 2024 10:43:53 +0000 Subject: [PATCH 68/77] good --- .../src/public_kernel_app_logic.nr | 6 +++--- .../public-kernel-lib/src/public_kernel_setup.nr | 7 ++++--- .../src/non_existent_read_request_reset.nr | 4 ++-- .../src/nullifier_read_request_reset.nr | 2 +- ...ier_non_existent_read_request_hints_builder.nr | 4 ++-- .../abis/base_or_merge_rollup_public_inputs.nr | 15 +++++++++++++++ .../rollup-lib/src/abis/constant_rollup_data.nr | 13 +++++++++++++ .../rollup-lib/src/abis/previous_rollup_data.nr | 12 ++++++++++++ .../rollup-lib/src/merge/merge_rollup_inputs.nr | 8 ++++++++ .../rollup-lib/src/root/root_rollup_inputs.nr | 14 ++++++++++++++ .../rollup-lib/src/tests/merge_rollup_inputs.nr | 2 +- 11 files changed, 75 insertions(+), 12 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr index 439cf74e6e4..79e2dbbc17c 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr @@ -22,7 +22,7 @@ impl PublicKernelAppLogicCircuitPrivateInputs { fn public_kernel_app_logic(self) -> PublicKernelCircuitPublicInputs { // construct the circuit outputs - let mut public_inputs: PublicKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::default(); common::initialize_revert_code(self.previous_kernel, self.public_call, &mut public_inputs); // initialise the end state with our provided previous kernel state @@ -341,7 +341,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_note_hashes must be empty for static calls")] + #[test(should_fail_with="new_note_hashes must be a default array (empty) for static calls")] fn public_kernel_fails_creating_new_note_hashes_on_static_call() { let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); builder.public_call.public_inputs.call_context.is_static_call = true; @@ -350,7 +350,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_nullifiers must be empty for static calls")] + #[test(should_fail_with="new_nullifiers must be a default array (empty) for static calls")] fn public_kernel_fails_creating_new_nullifiers_on_static_call() { let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); builder.public_call.public_inputs.call_context.is_static_call = true; diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr index 709f660222f..2262f1e2a3b 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr @@ -3,6 +3,7 @@ use dep::types::abis::{ kernel_circuit_public_inputs::{PublicKernelCircuitPublicInputs, PublicKernelCircuitPublicInputsBuilder}, kernel_data::PublicKernelData, public_call_data::PublicCallData }; + use dep::std::unsafe; struct PublicKernelSetupCircuitPrivateInputs { @@ -26,7 +27,7 @@ impl PublicKernelSetupCircuitPrivateInputs { fn public_kernel_setup(self) -> PublicKernelCircuitPublicInputs { // construct the circuit outputs - let mut public_inputs: PublicKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::default(); // since this phase is non-revertible, we must assert the public call did not revert common::validate_public_call_non_revert(self.public_call); common::initialize_revert_code(self.previous_kernel, self.public_call, &mut public_inputs); @@ -264,14 +265,14 @@ mod tests { } #[test(should_fail_with="caller context cannot be default for delegate calls")] - fn empty_caller_context_for_delegate_calls_fails() { + fn default_caller_context_for_delegate_calls_fails() { let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new().is_delegate_call(); builder.stub_teardown_call(); let public_call = builder.public_call.finish(); let hash = public_call.call_stack_item.hash(); - // Caller context is empty for regular calls. + // Caller context is default for regular calls. let is_delegate_call = false; builder.previous_kernel.push_public_call_request(hash, is_delegate_call); let previous_kernel = builder.previous_kernel.to_public_kernel_data(false); diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr index 0b35573deaf..05f18f364f6 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr @@ -133,8 +133,8 @@ mod tests { SideEffect { value: 5, counter: 17 }, SideEffect { value: 15, counter: 8 }, SideEffect { value: 25, counter: 11 }, - SideEffect::empty(), - SideEffect::empty(), + SideEffect::default(), + SideEffect::default(), ], len: 3, }; diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/nullifier_read_request_reset.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/nullifier_read_request_reset.nr index c33396e7052..98ca7d58c12 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/nullifier_read_request_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/nullifier_read_request_reset.nr @@ -31,7 +31,7 @@ impl SettledReadHint for Nullifier fn nada(read_request_len: u64) -> Self { NullifierSettledReadHint { read_request_index: read_request_len, - membership_witness: unsafe::zeroed(), + membership_witness: MembershipWitness::default(), leaf_preimage: NullifierLeafPreimage::default() } } diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_non_existent_read_request_hints_builder.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_non_existent_read_request_hints_builder.nr index d4de21463a7..bde26ba7e86 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_non_existent_read_request_hints_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_non_existent_read_request_hints_builder.nr @@ -21,10 +21,10 @@ struct NullifierNonExistentReadRequestHintsBuilder { impl NullifierNonExistentReadRequestHintsBuilder { pub fn new() -> Self { NullifierNonExistentReadRequestHintsBuilder { - nullifier_tree: unsafe::zeroed(), + nullifier_tree: NonEmptyMerkleTree::default(), non_membership_hints: BoundedVec::new(), read_values: BoundedVec::new(), - pending_nullifiers: [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_TX] + pending_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_TX] } } 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 15f33302d75..b9c50ce08d0 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 @@ -29,3 +29,18 @@ struct BaseOrMergeRollupPublicInputs { txs_effects_hash : Field, out_hash : Field, } + +impl Default for BaseOrMergeRollupPublicInputs { + fn default() -> Self { + BaseOrMergeRollupPublicInputs { + rollup_type : 0 as u32, + height_in_block_tree : 0, + aggregation_object : AggregationObject::default(), + constants : ConstantRollupData::default(), + start: PartialStateReference::default(), + end: PartialStateReference::default(), + txs_effects_hash : 0, + out_hash : 0, + } + } +} diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr index 66de37d34b4..3393ec50941 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr @@ -25,3 +25,16 @@ impl Eq for ConstantRollupData { (self.merge_rollup_vk_hash == other.merge_rollup_vk_hash) } } + +impl Default for ConstantRollupData { + fn default() -> Self { + ConstantRollupData { + last_archive: AppendOnlyTreeSnapshot::default(), + private_kernel_vk_tree_root: 0, + public_kernel_vk_tree_root: 0, + base_rollup_vk_hash: 0, + merge_rollup_vk_hash: 0, + global_variables: GlobalVariables::default(), + } + } +} 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 db92815baa0..4afe9a85f0d 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 @@ -10,3 +10,15 @@ struct PreviousRollupData{ vk_index : u32, vk_sibling_path : VKMembershipWitness, } + +impl Default for PreviousRollupData { + fn default() -> Self { + PreviousRollupData { + base_or_merge_rollup_public_inputs: BaseOrMergeRollupPublicInputs::default(), + proof : Proof::default(), + vk : VerificationKey::default(), + vk_index : 0 as u32, + vk_sibling_path : VKMembershipWitness::default(), + } + } +} 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 a0fcfee73a8..32bc591c743 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 @@ -7,6 +7,14 @@ struct MergeRollupInputs{ previous_rollup_data : [PreviousRollupData; 2] } +impl Default for MergeRollupInputs { + fn default() -> Self { + MergeRollupInputs { + previous_rollup_data: [PreviousRollupData::default(); 2] + } + } +} + impl MergeRollupInputs { pub fn merge_rollup_circuit(self) -> BaseOrMergeRollupPublicInputs { // TODO(Lasse): Verify the previous rollup proofs 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 52d61a21832..1e9b3dc1b5f 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 @@ -33,6 +33,20 @@ struct RootRollupInputs { new_archive_sibling_path : [Field; ARCHIVE_HEIGHT], } +impl Default for RootRollupInputs { + fn default() -> Self { + RootRollupInputs { + previous_rollup_data : [PreviousRollupData::default(); 2], + l1_to_l2_roots: RootParityInput::default(), + new_l1_to_l2_messages : [0; NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP], + new_l1_to_l2_message_tree_root_sibling_path : [0; L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH], + start_l1_to_l2_message_tree_snapshot : AppendOnlyTreeSnapshot::default(), + start_archive_snapshot : AppendOnlyTreeSnapshot::default(), + new_archive_sibling_path : [0; ARCHIVE_HEIGHT], + } + } +} + impl RootRollupInputs { pub fn root_rollup_circuit(self) -> RootRollupPublicInputs { let left = self.previous_rollup_data[0].base_or_merge_rollup_public_inputs; 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 8c34ade8bbd..be11951252f 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 @@ -4,7 +4,7 @@ use dep::types::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot; use crate::tests::previous_rollup_data::default_previous_rollup_data; pub fn default_merge_rollup_inputs() -> MergeRollupInputs { - let mut inputs: MergeRollupInputs = dep::std::unsafe::zeroed(); + let mut inputs = MergeRollupInputs::default(); inputs.previous_rollup_data = default_previous_rollup_data(); From c3025864341e4a58691866f3f85f3c91f83fba8e Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 10 Apr 2024 10:55:58 +0000 Subject: [PATCH 69/77] big --- .../src/tests/previous_rollup_data.nr | 2 +- .../src/tests/root_rollup_inputs.nr | 2 +- .../combined_accumulated_data.nr | 16 +++++ .../types/src/abis/private_call_stack_item.nr | 14 ++++- .../src/abis/private_circuit_public_inputs.nr | 61 +++++++++++-------- .../types/src/abis/public_call_stack_item.nr | 6 +- .../src/abis/public_circuit_public_inputs.nr | 33 ++++++++-- 7 files changed, 97 insertions(+), 37 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/previous_rollup_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/previous_rollup_data.nr index 3185a6bfdb7..2f8334e502d 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/previous_rollup_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/previous_rollup_data.nr @@ -3,7 +3,7 @@ use crate::abis::previous_rollup_data::PreviousRollupData; use dep::types::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot; pub fn default_previous_rollup_data() -> [PreviousRollupData; 2] { - let mut previous_rollup_data: [PreviousRollupData; 2] = dep::std::unsafe::zeroed(); + let mut previous_rollup_data =[PreviousRollupData::default(); 2]; previous_rollup_data[0].base_or_merge_rollup_public_inputs.start.note_hash_tree = AppendOnlyTreeSnapshot { root: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/root_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/root_rollup_inputs.nr index 5a7a64b0e80..ef833f83883 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/root_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/root_rollup_inputs.nr @@ -35,7 +35,7 @@ pub fn compute_archive_snapshot() -> (AppendOnlyTreeSnapshot, [Field; ARCHIVE_HE } pub fn default_root_rollup_inputs() -> RootRollupInputs { - let mut inputs: RootRollupInputs = dep::std::unsafe::zeroed(); + let mut inputs = RootRollupInputs::default(); let (l1_l2_empty_snapshot, l1_l2_empty_sibling_path) = compute_l1_l2_empty_snapshot(); inputs.new_l1_to_l2_message_tree_root_sibling_path = l1_l2_empty_sibling_path; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr index 9595eadf453..708390e78c8 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr @@ -27,6 +27,22 @@ struct CombinedAccumulatedData { public_data_update_requests: [PublicDataUpdateRequest; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], } +impl Default for CombinedAccumulatedData { + fn default() -> Self { + CombinedAccumulatedData { + new_note_hashes: [0; MAX_NEW_NOTE_HASHES_PER_TX], + new_nullifiers: [0; MAX_NEW_NULLIFIERS_PER_TX], + new_l2_to_l1_msgs: [0; MAX_NEW_L2_TO_L1_MSGS_PER_TX], + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + public_data_update_requests: [PublicDataUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], + } + } +} + + impl CombinedAccumulatedData { pub fn recombine(non_revertible: PublicAccumulatedData, revertible: PublicAccumulatedData) -> Self { CombinedAccumulatedData { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr index aa03f8589ef..cfb95d7fcda 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr @@ -24,6 +24,16 @@ impl Eq for PrivateCallStackItem { } } +impl Default for PrivateCallStackItem { + fn default() -> Self { + PrivateCallStackItem { + contract_address: AztecAddress::default(), + function_data: FunctionData::default(), + public_inputs: PrivateCircuitPublicInputs::default(), + } + } +} + impl Serialize for PrivateCallStackItem { fn serialize(self) -> [Field; PRIVATE_CALL_STACK_ITEM_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(); @@ -62,7 +72,7 @@ impl Hash for PrivateCallStackItem { #[test] fn serialization_of_empty() { - let item: PrivateCallStackItem = dep::std::unsafe::zeroed(); + let item = PrivateCallStackItem::default(); let serialized = item.serialize(); let deserialized = PrivateCallStackItem::deserialize(serialized); assert(item.eq(deserialized)); @@ -70,7 +80,7 @@ fn serialization_of_empty() { #[test] fn empty_hash() { - let mut item: PrivateCallStackItem = dep::std::unsafe::zeroed(); + let mut item = PrivateCallStackItem::default(); item.function_data.is_private = true; let hash = item.hash(); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr index 23dd6eea3d5..bc3f0313605 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr @@ -57,27 +57,36 @@ struct PrivateCircuitPublicInputs { impl Eq for PrivateCircuitPublicInputs { fn eq(self, other: Self) -> bool { - self.call_context.eq(other.call_context) & - self.args_hash.eq(other.args_hash) & - (self.return_values == other.return_values) & - (self.max_block_number == other.max_block_number) & - (self.note_hash_read_requests == other.note_hash_read_requests) & - (self.nullifier_read_requests == other.nullifier_read_requests) & - (self.nullifier_key_validation_requests == other.nullifier_key_validation_requests) & - (self.new_note_hashes == other.new_note_hashes) & - (self.new_nullifiers == other.new_nullifiers) & - (self.private_call_stack_hashes == other.private_call_stack_hashes) & - (self.public_call_stack_hashes == other.public_call_stack_hashes) & - (self.new_l2_to_l1_msgs == other.new_l2_to_l1_msgs) & - (self.start_side_effect_counter == other.start_side_effect_counter) & - (self.end_side_effect_counter == other.end_side_effect_counter) & - (self.encrypted_logs_hash == other.encrypted_logs_hash) & - (self.unencrypted_logs_hash == other.unencrypted_logs_hash) & - (self.encrypted_log_preimages_length == other.encrypted_log_preimages_length) & - (self.unencrypted_log_preimages_length == other.unencrypted_log_preimages_length) & - self.historical_header.eq(other.historical_header) & - self.chain_id.eq(other.chain_id) & - self.version.eq(other.version) + self.serialize() == other.serialize() + } +} + +impl Default for PrivateCircuitPublicInputs { + fn default() -> Self { + PrivateCircuitPublicInputs { + call_context: CallContext::default(), + args_hash: 0, + return_values: [0; RETURN_VALUES_LENGTH], + min_revertible_side_effect_counter: 0 as u32, + max_block_number: MaxBlockNumber::default(), + note_hash_read_requests: [SideEffect::default(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], + nullifier_read_requests: [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], + nullifier_key_validation_requests: [NullifierKeyValidationRequest::default(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL], + new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL], + new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL], + private_call_stack_hashes: [0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL], + public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], + new_l2_to_l1_msgs: [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], + start_side_effect_counter : 0 as u32, + end_side_effect_counter : 0 as u32, + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + historical_header: Header::default(), + chain_id: 0, + version: 0, + } } } @@ -138,11 +147,11 @@ impl Deserialize for PrivateCircuitPublicI return_values: reader.read_array([0; RETURN_VALUES_LENGTH]), min_revertible_side_effect_counter: reader.read() as u32, max_block_number: reader.read_struct(MaxBlockNumber::deserialize), - note_hash_read_requests: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]), + note_hash_read_requests: reader.read_struct_array(SideEffect::deserialize, [SideEffect::default(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]), nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), nullifier_key_validation_requests: reader.read_struct_array(NullifierKeyValidationRequest::deserialize, [NullifierKeyValidationRequest::default(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL]), - new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL]), - new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL]), + new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL]), + new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL]), private_call_stack_hashes: reader.read_array([0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL]), public_call_stack_hashes: reader.read_array([0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), @@ -170,7 +179,7 @@ impl Hash for PrivateCircuitPublicInputs { #[test] fn serialization_of_empty() { - let pcpi: PrivateCircuitPublicInputs = dep::std::unsafe::zeroed(); + let pcpi = PrivateCircuitPublicInputs::default(); let serialized = pcpi.serialize(); let deserialized = PrivateCircuitPublicInputs::deserialize(serialized); assert(pcpi.eq(deserialized)); @@ -178,7 +187,7 @@ fn serialization_of_empty() { #[test] fn empty_hash() { - let inputs: PrivateCircuitPublicInputs = dep::std::unsafe::zeroed(); + let inputs = PrivateCircuitPublicInputs::default(); let hash = inputs.hash(); // Value from private_circuit_public_inputs.test.ts "computes empty item hash" test diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr index 7ffb978ddf1..86504a0bf5b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr @@ -31,7 +31,7 @@ impl Hash for PublicCallStackItem { impl PublicCallStackItem { fn as_execution_request(self) -> Self { let public_inputs = self.public_inputs; - let mut request_public_inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); + let mut request_public_inputs = PublicCircuitPublicInputs::default(); request_public_inputs.call_context = public_inputs.call_context; request_public_inputs.args_hash = public_inputs.args_hash; @@ -60,7 +60,7 @@ mod tests { let contract_address = AztecAddress::from_field(1); let function_data = FunctionData { selector: FunctionSelector::from_u32(2), is_private: false }; - let mut public_inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); + let mut public_inputs = PublicCircuitPublicInputs::default(); public_inputs.new_note_hashes[0] = SideEffect{ value: 1, counter: 0, @@ -78,7 +78,7 @@ mod tests { let contract_address = AztecAddress::from_field(1); let function_data = FunctionData { selector: FunctionSelector::from_u32(2), is_private: false }; - let mut public_inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); + let mut public_inputs = PublicCircuitPublicInputs::default(); public_inputs.new_note_hashes[0] = SideEffect{ value: 1, counter: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index 4448724bf11..e6002989458 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -57,6 +57,31 @@ impl Eq for PublicCircuitPublicInputs { } } +impl Default for PublicCircuitPublicInputs { + fn default() -> Self { + PublicCircuitPublicInputs { + call_context: CallContext::default(), + args_hash: 0, + return_values: [0; RETURN_VALUES_LENGTH], + nullifier_read_requests: [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], + nullifier_non_existent_read_requests: [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], + contract_storage_update_requests: [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], + contract_storage_reads: [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL], + public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], + new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL], + new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL], + new_l2_to_l1_msgs: [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], + start_side_effect_counter: 0 as u32, + end_side_effect_counter: 0 as u32, + unencrypted_logs_hash: 0, + unencrypted_log_preimages_length: 0, + historical_header: Header::default(), + prover_address: AztecAddress::zero(), + revert_code: 0 as u8, + } + } +} + impl Serialize for PublicCircuitPublicInputs { fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(); @@ -112,8 +137,8 @@ impl Deserialize for PublicCircuitPublicInp contract_storage_update_requests: reader.read_struct_array(StorageUpdateRequest::deserialize, [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL]), contract_storage_reads: reader.read_struct_array(StorageRead::deserialize, [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL]), public_call_stack_hashes: reader.read_array([0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), - new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL]), - new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL]), + new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL]), + new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL]), new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), start_side_effect_counter: reader.read() as u32, end_side_effect_counter: reader.read() as u32, @@ -137,7 +162,7 @@ impl Hash for PublicCircuitPublicInputs { #[test] fn serialization_of_empty() { - let pcpi: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); + let pcpi = PublicCircuitPublicInputs::default(); let serialized = pcpi.serialize(); let deserialized = PublicCircuitPublicInputs::deserialize(serialized); assert(pcpi.eq(deserialized)); @@ -145,7 +170,7 @@ fn serialization_of_empty() { #[test] fn empty_hash() { - let inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); + let inputs = PublicCircuitPublicInputs::default(); let hash = inputs.hash(); // Value from public_circuit_public_inputs.test.ts "computes empty item hash" test From cc31767444aa5dc7c3242e799f8dbbeef285a68d Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 10 Apr 2024 11:09:44 +0000 Subject: [PATCH 70/77] before touching storage update reads/ requests --- .../aztec/src/context/private_context.nr | 4 +- .../src/public_kernel_tail.nr | 2 +- .../rollup-lib/src/base/base_rollup_inputs.nr | 53 ++++++++++++------- .../abis/nullifier_key_validation_request.nr | 1 + .../crates/types/src/abis/side_effect.nr | 41 ++++---------- .../crates/types/src/tests/sort.nr | 8 +-- 6 files changed, 54 insertions(+), 55 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index dd28dd19da2..272f81cb6b2 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -504,8 +504,8 @@ impl PrivateContext { contract_storage_update_requests: [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], contract_storage_reads: [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL], public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], - new_note_hashes: [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL], - new_nullifiers: [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL], + new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL], + new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL], new_l2_to_l1_msgs: [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], start_side_effect_counter: 0, end_side_effect_counter: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr index dd824c7c028..16cf635a265 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr @@ -101,7 +101,7 @@ impl PublicKernelTailCircuitPrivateInputs { } pub fn public_kernel_tail(self) -> KernelCircuitPublicInputs { - let mut public_inputs: PublicKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::default(); self.validate_inputs(); diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr index 827ae9f86c9..458a7810694 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -8,7 +8,6 @@ use crate::{ }; use dep::types::{ hash::sha256_to_field, - traits::is_default, abis::{ append_only_tree_snapshot::AppendOnlyTreeSnapshot, membership_witness::{ArchiveRootMembershipWitness, NullifierMembershipWitness, PublicDataMembershipWitness}, @@ -31,7 +30,8 @@ use dep::types::{ mocked::{AggregationObject, Proof}, partial_state_reference::PartialStateReference, public_data_tree_leaf::PublicDataTreeLeaf, public_data_tree_leaf_preimage::PublicDataTreeLeafPreimage, - utils::{field::{full_field_less_than, full_field_greater_than}, uint256::U256} + utils::{field::{full_field_less_than, full_field_greater_than}, uint256::U256}, + traits::is_default, }; struct BaseRollupInputs { @@ -273,7 +273,7 @@ fn insert_public_data_update_requests( ), |low_preimage: PublicDataTreeLeafPreimage, write: PublicDataTreeLeaf| { // Is valid low preimage let is_update = low_preimage.slot == write.slot; - let is_low_default = is_default(low_preimage); + let is_low_empty = is_default(low_preimage); let is_less_than_slot = full_field_less_than(low_preimage.slot, write.slot); let is_next_greater_than = full_field_less_than(write.slot, low_preimage.next_slot); @@ -281,7 +281,7 @@ fn insert_public_data_update_requests( is_next_greater_than | ((low_preimage.next_index == 0) & (low_preimage.next_slot == 0))); - (!is_low_default) & (is_update | is_in_range) + (!is_low_empty) & (is_update | is_in_range) }, |low_preimage: PublicDataTreeLeafPreimage, write: PublicDataTreeLeaf, write_index: u64| { // Update low leaf let is_update = low_preimage.slot == write.slot; @@ -330,7 +330,7 @@ fn validate_public_data_reads( let low_preimage = public_data_reads_preimages[i]; let witness = public_data_reads_witnesses[i]; - let is_low_default = is_default(low_preimage); + let is_low_empty = is_default(low_preimage); let is_exact = low_preimage.slot == read.leaf_slot; let is_less_than_slot = full_field_less_than(low_preimage.slot, read.leaf_slot); @@ -339,7 +339,7 @@ fn validate_public_data_reads( & (is_next_greater_than | ((low_preimage.next_index == 0) & (low_preimage.next_slot == 0))); if (!is_default(read)) { - assert(!is_low_default, "public data read is not empty but low preimage is empty"); + assert(!is_low_empty, "public data read is not empty but low preimage is empty"); if is_in_range { assert_eq(read.value, 0, "low leaf for public data read is in range but value is not zero"); } else { @@ -414,8 +414,8 @@ mod tests { fixture_builder::FixtureBuilder, merkle_tree_utils::{NonEmptyMerkleTree, compute_zero_hashes}, sort::sort_high_to_low }, + utils::{field::{full_field_less_than, field_from_bytes_32_trunc, field_from_bytes}, uint256::U256}, traits::is_default, - utils::{field::{full_field_less_than, field_from_bytes_32_trunc, field_from_bytes}, uint256::U256} }; struct NullifierInsertion { @@ -433,13 +433,13 @@ mod tests { snapshot: AppendOnlyTreeSnapshot, public_data_writes: BoundedVec<(u64, PublicDataTreeLeaf), 2>, mut pre_existing_public_data: [PublicDataTreeLeafPreimage; EXISTING_LEAVES] - ) -> ([Field; PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH], [PublicDataTreeLeaf; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], [u64; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], [PublicDataTreeLeafPreimage; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], [PublicDataMembershipWitness; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], [PublicDataTreeLeafPreimage; EXISTING_LEAVES]) { - let mut subtree_path: [Field; PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH] = dep::std::unsafe::zeroed(); - let mut sorted_public_data_writes: [PublicDataTreeLeaf; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] = dep::std::unsafe::zeroed(); - let mut sorted_public_data_writes_indexes: [u64; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] = dep::std::unsafe::zeroed(); - let mut low_public_data_writes_preimages: [PublicDataTreeLeafPreimage; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] = dep::std::unsafe::zeroed(); - let mut low_public_data_writes_witnesses: [PublicDataMembershipWitness; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] = dep::std::unsafe::zeroed(); - let mut new_subtree: [PublicDataTreeLeafPreimage; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] = dep::std::unsafe::zeroed(); + ) -> ([Field; 35], [PublicDataTreeLeaf; 32], [u64; 32], [PublicDataTreeLeafPreimage; 32], [PublicDataMembershipWitness; 32], [PublicDataTreeLeafPreimage; EXISTING_LEAVES]) { + let mut subtree_path = [0; PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH]; + let mut sorted_public_data_writes = [PublicDataTreeLeaf::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; + let mut sorted_public_data_writes_indexes = [0 as u64; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; + let mut low_public_data_writes_preimages = [PublicDataTreeLeafPreimage::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; + let mut low_public_data_writes_witnesses = [PublicDataMembershipWitness::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; + let mut new_subtree = [PublicDataTreeLeafPreimage::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; for i in 0..MAX_PUBLIC_DATA_WRITES_PER_TEST { if i < (public_data_writes.len()) { @@ -518,13 +518,30 @@ mod tests { constants: ConstantRollupData, } + impl Default for BaseRollupInputsBuilder { + fn default() -> Self { + BaseRollupInputsBuilder { + kernel_data: FixtureBuilder::new(), + pre_existing_notes: [0; MAX_NEW_NOTE_HASHES_PER_TX], + pre_existing_nullifiers: [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX], + pre_existing_contracts: [0; 2], + pre_existing_public_data: [PublicDataTreeLeafPreimage::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], + pre_existing_blocks: [0; 2], + public_data_reads: BoundedVec::new(), + public_data_writes:BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + constants: ConstantRollupData::default(), + } + } + } + fn test_compute_empty_root(size: [Field; N]) -> Field { compute_zero_hashes(size)[N - 1] } impl BaseRollupInputsBuilder { fn new() -> Self { - let mut inputs: BaseRollupInputsBuilder = dep::std::unsafe::zeroed(); + let mut inputs = BaseRollupInputsBuilder::default(); inputs.kernel_data = FixtureBuilder::new(); inputs.constants.global_variables.chain_id = 1; inputs.constants.global_variables.version = 0; @@ -551,8 +568,8 @@ mod tests { kernel_data: &mut KernelData, start_nullifier_tree_snapshot: AppendOnlyTreeSnapshot ) -> ([NullifierLeafPreimage; MAX_NEW_NULLIFIERS_PER_TX], [NullifierMembershipWitness; MAX_NEW_NULLIFIERS_PER_TX], [Field; MAX_NEW_NULLIFIERS_PER_TX], [u64; MAX_NEW_NULLIFIERS_PER_TX]) { - let mut nullifier_predecessor_preimages: [NullifierLeafPreimage; MAX_NEW_NULLIFIERS_PER_TX] = dep::std::unsafe::zeroed(); - let mut low_nullifier_membership_witness: [NullifierMembershipWitness; MAX_NEW_NULLIFIERS_PER_TX] = dep::std::unsafe::zeroed(); + let mut nullifier_predecessor_preimages = [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX]; + let mut low_nullifier_membership_witness = [NullifierMembershipWitness::default(); MAX_NEW_NULLIFIERS_PER_TX]; let sorted_new_nullifier_tuples = sort_high_to_low( self.new_nullifiers.storage.map(|insertion: NullifierInsertion| insertion.value), @@ -957,7 +974,7 @@ mod tests { #[test] unconstrained fn nonempty_block_out_hash() { - let mut end: CombinedAccumulatedData = dep::std::unsafe::zeroed(); + let mut end = CombinedAccumulatedData::default(); end.new_l2_to_l1_msgs[MAX_NEW_L2_TO_L1_MSGS_PER_TX - 1] = 123; let out_hash = compute_kernel_out_hash(end); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr index 81f8bfb17c1..c65055e6574 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr @@ -98,3 +98,4 @@ impl Deserialize for NullifierK } } } + diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr index af769450977..7cf3a78eaaf 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr @@ -1,6 +1,6 @@ use crate::{ address::AztecAddress, constants::GENERATOR_INDEX__SIDE_EFFECT, - traits::{Empty, Hash, Serialize, Deserialize} + traits::{Hash, Serialize, Deserialize} }; use dep::std::cmp::Eq; @@ -48,15 +48,6 @@ impl Eq for SideEffect { } } -impl Empty for SideEffect { - fn empty() -> Self { - SideEffect { - value: 0, - counter: 0, - } - } -} - impl Default for SideEffect { fn default() -> Self { SideEffect { @@ -94,26 +85,6 @@ struct SideEffectLinkedToNoteHash{ counter: u32, } -impl Empty for SideEffectLinkedToNoteHash { - fn empty() -> Self { - SideEffectLinkedToNoteHash { - value: 0, - note_hash: 0, - counter: 0, - } - } -} - -impl Default for SideEffectLinkedToNoteHash { - fn default() -> Self { - SideEffectLinkedToNoteHash { - value: 0, - note_hash: 0, - counter: 0, - } - } -} - impl Ordered for SideEffectLinkedToNoteHash { fn counter(self) -> u32 { self.counter @@ -137,6 +108,16 @@ impl Eq for SideEffectLinkedToNoteHash { } } +impl Default for SideEffectLinkedToNoteHash { + fn default() -> Self { + SideEffectLinkedToNoteHash { + value: 0, + note_hash: 0, + counter: 0, + } + } +} + impl Hash for SideEffectLinkedToNoteHash { fn hash(self) -> Field { dep::std::hash::pedersen_hash_with_separator( diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/sort.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/sort.nr index d067eb1a2d9..1dd5937e0fc 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/sort.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/sort.nr @@ -1,4 +1,4 @@ -use crate::traits::{Empty, is_empty}; +use crate::traits::{Default, is_default}; struct SortedTuple { value: T, @@ -29,7 +29,7 @@ struct SortedResult { pub fn sort_get_sorted_hints( values: [T; N], ordering: fn(T, T) -> bool -) -> SortedResult where T: Eq + Empty { +) -> SortedResult where T: Eq + Default { let mut tuples = [SortedTuple { value: values[0], original_index: 0 }; N]; for i in 0..N { tuples[i] = SortedTuple { @@ -39,13 +39,13 @@ pub fn sort_get_sorted_hints( } let sorted_tuples = tuples.sort_via( - |a: SortedTuple, b: SortedTuple| is_empty(b.value) | (!is_empty(a.value) & !is_empty(b.value) & ordering(a.value, b.value)) + |a: SortedTuple, b: SortedTuple| is_default(b.value) | (!is_default(a.value) & !is_default(b.value) & ordering(a.value, b.value)) ); let sorted_array = sorted_tuples.map(|t: SortedTuple| t.value); let mut sorted_index_hints = [0; N]; for i in 0..N { - if !is_empty(sorted_tuples[i].value) { + if !is_default(sorted_tuples[i].value) { let original_index = sorted_tuples[i].original_index; sorted_index_hints[original_index] = i; } From 93a1be83defc71d6412bae9fcc93420fd58cf6bb Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 10 Apr 2024 12:40:27 +0000 Subject: [PATCH 71/77] good --- .../aztec-nr/address-note/src/address_note.nr | 2 +- .../aztec/src/context/private_context.nr | 4 +-- .../src/types/card_note.nr | 2 +- .../crates/public-kernel-lib/src/common.nr | 26 +++++++------- .../crates/public-kernel-lib/src/utils.nr | 9 +++-- .../crates/types/src/abis/call_request.nr | 13 ------- .../src/abis/public_circuit_public_inputs.nr | 8 ++--- .../crates/types/src/contrakt/storage_read.nr | 13 +++++-- .../src/contrakt/storage_update_request.nr | 13 +++++-- .../crates/types/src/contrakt/traits.nr | 18 +++++++--- .../types/src/messaging/l2_to_l1_message.nr | 11 +----- .../src/tests/public_call_data_builder.nr | 4 +-- .../crates/types/src/traits.nr | 36 +++---------------- 13 files changed, 67 insertions(+), 92 deletions(-) diff --git a/noir-projects/aztec-nr/address-note/src/address_note.nr b/noir-projects/aztec-nr/address-note/src/address_note.nr index babcbb18784..3822b1c98f6 100644 --- a/noir-projects/aztec-nr/address-note/src/address_note.nr +++ b/noir-projects/aztec-nr/address-note/src/address_note.nr @@ -2,7 +2,7 @@ use dep::aztec::log::emit_encrypted_log; // docs:end:encrypted_import use dep::aztec::{ - protocol_types::{address::AztecAddress, traits::Empty}, + protocol_types::address::AztecAddress, note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption}, oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key}, hash::pedersen_hash, context::PrivateContext diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 272f81cb6b2..e47c8d4c831 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -501,8 +501,8 @@ impl PrivateContext { return_values: [0; RETURN_VALUES_LENGTH], nullifier_read_requests: [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], nullifier_non_existent_read_requests: [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], - contract_storage_update_requests: [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], - contract_storage_reads: [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL], + contract_storage_update_requests: [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], + contract_storage_reads: [StorageRead::default(); MAX_PUBLIC_DATA_READS_PER_CALL], public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL], new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL], diff --git a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr index 81f91f677be..bd6a0a4a1f5 100644 --- a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr +++ b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr @@ -2,7 +2,7 @@ use dep::aztec::prelude::{AztecAddress, NoteInterface, NoteHeader, PrivateContex use dep::aztec::{ note::{utils::compute_note_hash_for_consumption}, oracle::{nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key}, - hash::pedersen_hash, protocol_types::traits::Empty + hash::pedersen_hash }; // Shows how to create a custom note diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index 0ca31fc8920..6979a9f409b 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -7,7 +7,7 @@ use dep::types::{ side_effect::{SideEffect, SideEffectLinkedToNoteHash} }, address::AztecAddress, - contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, + contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest, traits::{is_default as storage_op_is_default, array_length as storage_op_array_length}}, constants::{ MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_NEW_NOTE_HASHES_PER_CALL, MAX_NEW_NULLIFIERS_PER_CALL, MAX_NULLIFIER_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, @@ -15,7 +15,7 @@ use dep::types::{ MAX_PUBLIC_DATA_READS_PER_CALL }, hash::{silo_note_hash, silo_nullifier, compute_l2_to_l1_hash, accumulate_sha256}, - utils::{arrays::{array_length, array_to_bounded_vec}}, traits::{is_empty, is_empty_array, is_default} + utils::{arrays::{array_length, array_to_bounded_vec}}, traits::{is_default,is_zero} }; use crate::hash::{compute_public_data_tree_index, compute_public_data_tree_value}; @@ -23,9 +23,7 @@ use crate::hash::{compute_public_data_tree_index, compute_public_data_tree_value pub fn validate_inputs(public_call: PublicCallData) { // Validates commons inputs for all type of kernel inputs let this_call_stack_item: PublicCallStackItem = public_call.call_stack_item; - assert( - !this_call_stack_item.contract_address.eq(AztecAddress::zero()), "Contract address cannot be zero" - ); + assert(!is_zero(this_call_stack_item.contract_address), "Contract address cannot be zero"); assert(this_call_stack_item.function_data.selector.to_field() != 0, "Function signature cannot be zero"); assert( this_call_stack_item.function_data.is_private == false, "Cannot execute a private function with the public kernel circuit" @@ -111,20 +109,22 @@ pub fn initialize_end_values( fn perform_static_call_checks(public_call: PublicCallData) { let public_inputs = public_call.call_stack_item.public_inputs; if public_inputs.call_context.is_static_call { + + // TODO: #5618 // No state changes are allowed for static calls: let new_note_hashes_length = array_length(public_inputs.new_note_hashes); - assert(new_note_hashes_length == 0, "new_note_hashes must be empty for static calls"); + assert(new_note_hashes_length == 0, "new_note_hashes must be a default array (empty) for static calls"); let new_nullifiers_length = array_length(public_inputs.new_nullifiers); - assert(new_nullifiers_length == 0, "new_nullifiers must be empty for static calls"); + assert(new_nullifiers_length == 0, "new_nullifiers must be a default array (empty) for static calls"); - let update_requests_length = is_empty_array(public_inputs.contract_storage_update_requests); + let update_requests_length = storage_op_array_length(public_inputs.contract_storage_update_requests); assert( - update_requests_length, "No contract storage update requests are allowed for static calls" + update_requests_length == 0, "No contract storage update requests are allowed for static calls" ); let new_l2_to_l1_msgs_length = array_length(public_inputs.new_l2_to_l1_msgs); - assert(new_l2_to_l1_msgs_length == 0, "new_l2_to_l1_msgs must be empty for static calls"); + assert(new_l2_to_l1_msgs_length == 0, "new_l2_to_l1_msgs must be empty (length 0) for static calls"); // TODO: reevaluate when implementing https://github.com/AztecProtocol/aztec-packages/issues/1165 // This 4 magical number is the minimum size of the buffer, since it has to store the total length of all the serialized logs. @@ -253,7 +253,7 @@ fn propagate_valid_public_data_update_requests( for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { let update_request = update_requests[i]; - if (!update_request.is_empty()) { + if (!storage_op_is_default(update_request)) { let public_data_update_request = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value) @@ -276,7 +276,7 @@ fn propagate_valid_non_revertible_public_data_update_requests( for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { let update_request = update_requests[i]; - if (!update_request.is_empty()) { + if (!storage_op_is_default(update_request)) { let public_data_update_request = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value) @@ -296,7 +296,7 @@ fn propagate_valid_public_data_reads(public_call: PublicCallData, circuit_output for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL { let read_request: StorageRead = read_requests[i]; - if !read_request.is_empty() { + if !storage_op_is_default(read_request) { let public_data_read = PublicDataRead { leaf_slot: compute_public_data_tree_index(contract_address, read_request.storage_slot), value: compute_public_data_tree_value(read_request.current_value) diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr index 34bcb4fa218..47899c94296 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr @@ -5,9 +5,8 @@ use dep::types::{ public_data_update_request::PublicDataUpdateRequest }, address::AztecAddress, - contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, - utils::{arrays::array_eq}, - traits::is_default + contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest, traits::is_default}, + utils::arrays::array_eq, }; pub fn compute_public_data_reads( @@ -17,7 +16,7 @@ pub fn compute_public_data_reads( let mut public_data_reads = [PublicDataRead::default(); N]; for i in 0..N { let read_request = read_requests[i]; - if !read_request.is_empty() { + if !is_default(read_request) { public_data_reads[i] = PublicDataRead { leaf_slot: compute_public_data_tree_index(contract_address, read_request.storage_slot), value: compute_public_data_tree_value(read_request.current_value), @@ -38,7 +37,7 @@ pub fn compute_public_data_update_requests( let mut public_data_update_requests = [PublicDataUpdateRequest::default(); N]; for i in 0..N { let update_request = update_requests[i]; - if !update_request.is_empty() { + if !is_default(update_request) { public_data_update_requests[i] = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr index ba9ee3cf24c..1f0e1494438 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr @@ -1,7 +1,6 @@ use crate::address::AztecAddress; use dep::std::{cmp::Eq,default::Default}; use crate::abis::caller_context::CallerContext; -use crate::traits::Empty; struct CallRequest { hash: Field, @@ -32,15 +31,3 @@ impl Default for CallRequest { } } } - -impl Empty for CallRequest { - fn empty() -> Self { - CallRequest { - hash: 0, - caller_contract_address: AztecAddress::zero(), - caller_context: CallerContext::default(), - start_side_effect_counter: 0, - end_side_effect_counter: 0, - } - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index e6002989458..e6f4a8c5fa4 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -65,8 +65,8 @@ impl Default for PublicCircuitPublicInputs { return_values: [0; RETURN_VALUES_LENGTH], nullifier_read_requests: [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], nullifier_non_existent_read_requests: [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], - contract_storage_update_requests: [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], - contract_storage_reads: [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL], + contract_storage_update_requests: [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], + contract_storage_reads: [StorageRead::default(); MAX_PUBLIC_DATA_READS_PER_CALL], public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL], new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL], @@ -134,8 +134,8 @@ impl Deserialize for PublicCircuitPublicInp return_values: reader.read_array([0; RETURN_VALUES_LENGTH]), nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), nullifier_non_existent_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL]), - contract_storage_update_requests: reader.read_struct_array(StorageUpdateRequest::deserialize, [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL]), - contract_storage_reads: reader.read_struct_array(StorageRead::deserialize, [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL]), + contract_storage_update_requests: reader.read_struct_array(StorageUpdateRequest::deserialize, [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL]), + contract_storage_reads: reader.read_struct_array(StorageRead::deserialize, [StorageRead::default(); MAX_PUBLIC_DATA_READS_PER_CALL]), public_call_stack_hashes: reader.read_array([0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL]), new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL]), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr index 04ee782bd3d..f0c7162c04b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr @@ -1,6 +1,7 @@ use crate::{ constants::{CONTRACT_STORAGE_READ_LENGTH, GENERATOR_INDEX__PUBLIC_DATA_READ}, hash::pedersen_hash, - traits::{Deserialize, Hash, Empty, Serialize} + traits::{Deserialize, Hash, Serialize}, + contrakt::traits::StorageOp }; struct StorageRead { @@ -14,8 +15,8 @@ impl Eq for StorageRead { } } -impl Empty for StorageRead { - fn empty() -> Self { +impl Default for StorageRead { + fn default() -> Self { Self { storage_slot: 0, current_value: 0, @@ -49,3 +50,9 @@ impl StorageRead { self.storage_slot == 0 } } + +impl StorageOp for StorageRead { + fn is_default(self) -> bool { + self.storage_slot == 0 + } +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr index 01176175f60..abbe456757a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr @@ -1,6 +1,7 @@ use crate::{ constants::{CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH, GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST}, - hash::pedersen_hash, traits::{Deserialize, Hash, Empty, Serialize} + hash::pedersen_hash, traits::{Deserialize, Hash, Default, Serialize}, + contrakt::traits::StorageOp }; use dep::std::cmp::Eq; @@ -16,8 +17,8 @@ impl Eq for StorageUpdateRequest { } } -impl Empty for StorageUpdateRequest { - fn empty() -> Self { +impl Default for StorageUpdateRequest { + fn default() -> Self { StorageUpdateRequest { storage_slot: 0, new_value: 0, @@ -51,3 +52,9 @@ impl StorageUpdateRequest { self.storage_slot == 0 } } + +impl StorageOp for StorageUpdateRequest { + fn is_default(self) -> bool { + self.storage_slot == 0 + } +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/traits.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/traits.nr index d11e0c46b33..ece96d6f881 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/traits.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/traits.nr @@ -1,16 +1,16 @@ // We use this because storage read is_default does not match behavior with the normal way we calculate is_default -trait StorageRequest { +trait StorageOp { fn is_default(self) -> bool; } -pub fn is_default(item: T) -> bool where T: StorageRequest { +pub fn is_default(item: T) -> bool where T: StorageOp { item.is_default() } // Routine which validates that all zero values of an array form a contiguous region at the end, i.e., // of the form: [*,*,*...,0,0,0,0] where any * is non-zero. Note that a full array of non-zero values is // valid. -pub fn validate_array(array: [T; N]) where T: StorageRequest + Eq { +pub fn validate_array(array: [T; N]) where T: StorageOp + Eq { let array_length = array.len(); let mut first_zero_pos = array_length; @@ -29,7 +29,7 @@ pub fn validate_array(array: [T; N]) where T: StorageRequest + Eq { // Helper method to determine the number of non-zero/default elements in a validated array (ie, validate_array(array) // should be true). -pub fn array_length(array: [T; N]) -> u64 where T: StorageRequest + Eq { +pub fn array_length(array: [T; N]) -> u64 where T: StorageOp + Eq { let mut length = 0; let mut end = false; for elem in array { @@ -40,3 +40,13 @@ pub fn array_length(array: [T; N]) -> u64 where T: StorageRequest + Eq { } length } + +pub fn array_eq(array: [T; N], expected: [T; S]) -> bool where T: StorageOp + Eq { + let mut eq = array_length(array) == S; + + for i in 0..S { + eq &= array[i].eq(expected[i]); + } + + eq +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr index 5bcfac770d3..d43857aec9d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr @@ -1,4 +1,4 @@ -use crate::{address::EthAddress, constants::L2_TO_L1_MESSAGE_LENGTH, traits::{Deserialize, Serialize, Empty}}; +use crate::{address::EthAddress, constants::L2_TO_L1_MESSAGE_LENGTH, traits::{Deserialize, Serialize}}; // Note: Not to be confused with L2ToL1Msg in Solidity struct L2ToL1Message { @@ -15,15 +15,6 @@ impl Default for L2ToL1Message { } } -impl Empty for L2ToL1Message { - fn empty() -> Self { - Self { - recipient: EthAddress::zero(), - content: 0, - } - } -} - impl Eq for L2ToL1Message { fn eq(self, other: Self) -> bool { (self.recipient == other.recipient) & (self.content == other.content) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr index 38c39e18ff7..399b51bbb76 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr @@ -119,7 +119,7 @@ impl PublicCallDataBuilder { pub fn append_empty_public_data_read_requests(&mut self, num_reads: u64) { for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL { if i < num_reads { - self.public_inputs.contract_storage_reads.push(StorageRead::empty()); + self.public_inputs.contract_storage_reads.push(StorageRead::default()); } } } @@ -142,7 +142,7 @@ impl PublicCallDataBuilder { pub fn append_empty_update_requests(&mut self, num_updates: u64) { for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { if i < num_updates { - self.public_inputs.contract_storage_update_requests.push(StorageUpdateRequest::empty()); + self.public_inputs.contract_storage_update_requests.push(StorageUpdateRequest::default()); } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr index 96e8bd85965..46c0c5e0a48 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr @@ -1,36 +1,5 @@ use dep::std::{default::Default,cmp::Eq}; -// Trait: is_empty -// -// The general is_empty trait checks if a data type is is empty, -// and it defines empty for the basic data types as 0. -// -// If a Field is equal to zero, then it is regarded as zero. -// We will go with this definition for now, however it can be problematic -// if a value can actually be zero. In a future refactor, we can -// use the optional type for safety. Doing it now would lead to a worse devex -// and would make it harder to sync up with the cpp code. -// Preferred over Default trait to convey intent, as default doesn't necessarily mean empty. -trait Empty { - fn empty() -> Self; -} - -impl Empty for Field { fn empty() -> Self {0} } - -impl Empty for u1 { fn empty() -> Self {0} } -impl Empty for u8 { fn empty() -> Self {0} } -impl Empty for u32 { fn empty() -> Self {0} } -impl Empty for u64 { fn empty() -> Self {0} } -impl Empty for U128 { fn empty() -> Self {U128::from_integer(0)} } - -pub fn is_empty(item: T) -> bool where T: Empty + Eq { - item.eq(T::empty()) -} - -pub fn is_empty_array(array: [T; N]) -> bool where T: Empty + Eq { - array.all(|elem| is_empty(elem)) -} - pub fn is_default(item: T) -> bool where T: Default + Eq { item.eq(T::default()) } @@ -39,6 +8,11 @@ pub fn is_default_array(array: [T; N]) -> bool where T: Default + Eq { array.all(|elem| is_default(elem)) } +// If a Field is equal to zero, then it is regarded as zero. +// We will go with this definition for now, however it can be problematic +// if a value can actually be zero. In a future refactor, we can +// use the optional type for safety. Doing it now would lead to a worse devex +// and would make it harder to sync up with the cpp code. trait Zero { fn zero() -> Self; } From 523fb316e471b8d0b6acfe5ad675141a255b7727 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 10 Apr 2024 12:51:21 +0000 Subject: [PATCH 72/77] test --- .../aztec-nr/aztec/src/context/private_context.nr | 2 +- .../aztec-nr/aztec/src/context/public_context.nr | 2 +- .../src/kernel_circuit_public_inputs_composer.nr | 4 ++-- .../crates/types/src/abis/function_data.nr | 8 ++++---- .../crates/types/src/abis/private_call_stack_item.nr | 8 ++++---- .../types/src/abis/private_circuit_public_inputs.nr | 8 ++++---- .../crates/types/src/abis/public_circuit_public_inputs.nr | 8 ++++---- .../crates/types/src/content_commitment.nr | 2 +- .../noir-protocol-circuits/crates/types/src/header.nr | 8 ++++---- .../crates/types/src/state_reference.nr | 2 +- .../crates/types/src/transaction/tx_context.nr | 8 ++++---- .../crates/types/src/transaction/tx_request.nr | 2 +- 12 files changed, 31 insertions(+), 31 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index e47c8d4c831..cc7b740ff61 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -274,7 +274,7 @@ impl PrivateContext { secret ); - // Push nullifier (and the "commitment" corresponding to this can be "empty") + // Push nullifier (and the "commitment" corresponding to this can be "default") self.push_new_nullifier(nullifier, 0) } // docs:end:consume_l1_to_l2_message diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index 46fbdc13ef9..0b2c83496f9 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -251,7 +251,7 @@ impl PublicContextInterface for PublicContext { secret ); - // Push nullifier (and the "commitment" corresponding to this can be "empty") + // Push nullifier (and the "commitment" corresponding to this can be "default") self.push_new_nullifier(nullifier, 0) } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr index ad495b68c8a..268b4a14913 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr @@ -164,8 +164,8 @@ impl KernelCircuitPublicInputsComposer { // Nullified_commitment of value `0` implies non-transient (persistable) // nullifier in which case no attempt will be made to match it to a hash. - // Non-empty nullified_note_hash implies transient nullifier which MUST be matched to a hash below! - // 0-valued nullified_note_hash is empty and will be ignored + // Non-default nullified_note_hash implies transient nullifier which MUST be matched to a hash below! + // 0-valued nullified_note_hash is default and will be ignored if nullified_note_hash != 0 { assert( hint_pos < MAX_NEW_NOTE_HASHES_PER_TX, "New nullifier is transient but hint is invalid" diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr index 9331ec27e2c..5a07ab22e28 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr @@ -53,7 +53,7 @@ impl Hash for FunctionData { } #[test] -fn serialization_of_empty() { +fn serialization_of_default() { let data = FunctionData::default(); let serialized = data.serialize(); let deserialized = FunctionData::deserialize(serialized); @@ -61,11 +61,11 @@ fn serialization_of_empty() { } #[test] -fn empty_hash() { +fn default_hash() { let data = FunctionData::default(); let hash = data.hash(); // Value from function_data.test.ts "computes empty item hash" test - let test_data_empty_hash = 0x27b1d0839a5b23baf12a8d195b18ac288fcf401afb2f70b8a4b529ede5fa9fed; - assert_eq(hash, test_data_empty_hash); + let test_data_default_hash = 0x27b1d0839a5b23baf12a8d195b18ac288fcf401afb2f70b8a4b529ede5fa9fed; + assert_eq(hash, test_data_default_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr index cfb95d7fcda..952857441bc 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr @@ -71,7 +71,7 @@ impl Hash for PrivateCallStackItem { } #[test] -fn serialization_of_empty() { +fn serialization_of_default() { let item = PrivateCallStackItem::default(); let serialized = item.serialize(); let deserialized = PrivateCallStackItem::deserialize(serialized); @@ -79,12 +79,12 @@ fn serialization_of_empty() { } #[test] -fn empty_hash() { +fn default_hash() { let mut item = PrivateCallStackItem::default(); item.function_data.is_private = true; let hash = item.hash(); // Value from private_call_stack_item.test.ts "computes empty item hash" test - let test_data_empty_hash = 0x13f518365c690d1b96d31454afed495ad29fe530939caf7189dd44f9bd63ef89; - assert_eq(hash, test_data_empty_hash); + let test_data_default_hash = 0x13f518365c690d1b96d31454afed495ad29fe530939caf7189dd44f9bd63ef89; + assert_eq(hash, test_data_default_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr index bc3f0313605..bbd0f458793 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr @@ -178,7 +178,7 @@ impl Hash for PrivateCircuitPublicInputs { } #[test] -fn serialization_of_empty() { +fn serialization_of_default() { let pcpi = PrivateCircuitPublicInputs::default(); let serialized = pcpi.serialize(); let deserialized = PrivateCircuitPublicInputs::deserialize(serialized); @@ -186,11 +186,11 @@ fn serialization_of_empty() { } #[test] -fn empty_hash() { +fn default_hash() { let inputs = PrivateCircuitPublicInputs::default(); let hash = inputs.hash(); // Value from private_circuit_public_inputs.test.ts "computes empty item hash" test - let test_data_empty_hash = 0x1304e6c42e3c53fc7c918cbf1ea70333b4f214726c0784cf9878cd641967dab1; - assert_eq(hash, test_data_empty_hash); + let test_data_default_hash = 0x1304e6c42e3c53fc7c918cbf1ea70333b4f214726c0784cf9878cd641967dab1; + assert_eq(hash, test_data_default_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index e6f4a8c5fa4..ae1b7e80c37 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -161,7 +161,7 @@ impl Hash for PublicCircuitPublicInputs { } #[test] -fn serialization_of_empty() { +fn serialization_of_default() { let pcpi = PublicCircuitPublicInputs::default(); let serialized = pcpi.serialize(); let deserialized = PublicCircuitPublicInputs::deserialize(serialized); @@ -169,11 +169,11 @@ fn serialization_of_empty() { } #[test] -fn empty_hash() { +fn default_hash() { let inputs = PublicCircuitPublicInputs::default(); let hash = inputs.hash(); // Value from public_circuit_public_inputs.test.ts "computes empty item hash" test - let test_data_empty_hash = 0x0f1eb4e352e8dab6cbab3c63b6d8f3cd2cd90cc7ae5ff142e4dfa2b3e28e01c1; - assert_eq(hash, test_data_empty_hash); + let test_data_default_hash = 0x0f1eb4e352e8dab6cbab3c63b6d8f3cd2cd90cc7ae5ff142e4dfa2b3e28e01c1; + assert_eq(hash, test_data_default_hash); } 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 253af29f254..c34e4e51358 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 @@ -64,7 +64,7 @@ impl Eq for ContentCommitment { } #[test] -fn serialization_of_empty() { +fn serialization_of_default() { let empty = ContentCommitment::default(); let serialized = empty.serialize(); let deserialized = ContentCommitment::deserialize(serialized); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr index e356edf8cd1..9c8eb5f536f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr @@ -82,7 +82,7 @@ impl Hash for Header { } #[test] -fn serialization_of_empty() { +fn serialization_of_default() { let header = Header::default(); let serialized = header.serialize(); let deserialized = Header::deserialize(serialized); @@ -96,11 +96,11 @@ fn hash_smoke() { } #[test] -fn empty_hash_is_default() { +fn default_hash() { let header = Header::default(); let hash = header.hash(); // Value from new_contract_data.test.ts "computes empty hash" test - let test_data_empty_hash = 0x2a45c01b78a6b9a2392b7490966b41f47e5d9ac95610fa3eabe99d9aec7f6ad0; - assert_eq(hash, test_data_empty_hash); + let test_data_default_hash = 0x2a45c01b78a6b9a2392b7490966b41f47e5d9ac95610fa3eabe99d9aec7f6ad0; + assert_eq(hash, test_data_default_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr index 2f4004a1c2f..ddab257ccb3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr @@ -54,7 +54,7 @@ impl Deserialize for StateReference { } #[test] -fn serialization_of_empty() { +fn serialization_of_default() { let state = StateReference::default(); let _serialized = state.serialize(); let _deserialized = StateReference::deserialize(_serialized); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr index 7e260e381cd..6f8e49665f2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr @@ -70,7 +70,7 @@ impl Hash for TxContext { } #[test] -fn serialization_of_empty() { +fn serialization_of_default() { let context = TxContext::default(); let serialized = context.serialize(); let deserialized = TxContext::deserialize(serialized); @@ -78,11 +78,11 @@ fn serialization_of_empty() { } #[test] -fn empty_hash() { +fn default_hash() { let inputs = TxContext::default(); let hash = inputs.hash(); // Value from tx_context.test.ts "computes empty item hash" test - let test_data_empty_hash = 0x200569267c0f73ac89aaa414239398db9445dd4ad3a8cf37015cd55b8d4c5e8d; - assert_eq(hash, test_data_empty_hash); + let test_data_default_hash = 0x200569267c0f73ac89aaa414239398db9445dd4ad3a8cf37015cd55b8d4c5e8d; + assert_eq(hash, test_data_default_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr index 7b4c526ea87..e354c0ebb9d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr @@ -77,7 +77,7 @@ mod tests { }; #[test] - fn serialization_of_empty() { + fn serialization_of_default() { // Assuming a zeroed initialization for simplicity let request = TxRequest::default(); let serialized = request.serialize(); From 4ee64831ee67baf254c0bf88a5dc67fafec4ddb9 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 10 Apr 2024 14:39:22 +0000 Subject: [PATCH 73/77] ci --- .../crates/private-kernel-lib/src/common.nr | 2 +- .../crates/public-kernel-lib/src/common.nr | 2 +- .../crates/public-kernel-lib/src/public_kernel_setup.nr | 2 +- .../crates/public-kernel-lib/src/public_kernel_teardown.nr | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr index a0ba9916c4d..84259c1083a 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr @@ -312,7 +312,7 @@ pub fn contract_logic(private_call: PrivateCallData) { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3062): Why is this using a hash function from the stdlib::recursion namespace let private_call_vk_hash = stdlib_recursion_verification_key_compress_native_vk(private_call.vk); - assert(!is_zero(contract_address), "Contract address cannot be zero"); + assert(!is_zero(contract_address), "contract address cannot be zero"); // std::println(f"contract_address={contract_address}"); // std::println(f"private_call_vk_hash={private_call_vk_hash}"); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index 6979a9f409b..61b522acb96 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -23,7 +23,7 @@ use crate::hash::{compute_public_data_tree_index, compute_public_data_tree_value pub fn validate_inputs(public_call: PublicCallData) { // Validates commons inputs for all type of kernel inputs let this_call_stack_item: PublicCallStackItem = public_call.call_stack_item; - assert(!is_zero(this_call_stack_item.contract_address), "Contract address cannot be zero"); + assert(!is_zero(this_call_stack_item.contract_address), "contract address cannot be zero"); assert(this_call_stack_item.function_data.selector.to_field() != 0, "Function signature cannot be zero"); assert( this_call_stack_item.function_data.is_private == false, "Cannot execute a private function with the public kernel circuit" diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr index 2262f1e2a3b..22424f9dd6b 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr @@ -198,7 +198,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="Contract address cannot be zero")] + #[test(should_fail_with="contract address cannot be zero")] fn contract_address_must_be_valid() { let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); builder.public_call.contract_address = AztecAddress::zero(); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr index 75e92d64607..869cb86de1e 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr @@ -147,7 +147,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="Contract address cannot be zero")] + #[test(should_fail_with="contract address cannot be zero")] fn contract_address_must_be_valid() { let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); builder.public_call.contract_address = AztecAddress::zero(); From 4af9361075afa7a7f026745cddd03cdbb8c5a730 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 10 Apr 2024 15:26:21 +0000 Subject: [PATCH 74/77] last touches --- .../src/kernel_circuit_public_inputs_composer.nr | 2 +- .../src/private_kernel_tail_to_public.nr | 7 ++++--- .../private_accumulated_data_builder.nr | 8 ++++---- .../accumulated_data/public_accumulated_data.nr | 16 ++++++++++++++++ .../crates/types/src/abis/call_context.nr | 2 +- .../crates/types/src/tests/fixture_builder.nr | 4 ++-- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr index 268b4a14913..7d01fe01cfc 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr @@ -40,7 +40,7 @@ impl KernelCircuitPublicInputsComposer { sorted_nullifiers_indexes: [u64; MAX_NEW_NULLIFIERS_PER_TX], transient_note_hash_index_hints: [u64; MAX_NEW_NULLIFIERS_PER_TX] ) -> Self { - let public_inputs: PrivateKernelCircuitPublicInputsBuilder = unsafe::zeroed(); + let public_inputs = PrivateKernelCircuitPublicInputsBuilder::default(); KernelCircuitPublicInputsComposer { public_inputs, 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 d2b371cf57a..674592e50c3 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 @@ -64,7 +64,7 @@ mod tests { }; use dep::types::constants::{ MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, - MAX_NULLIFIER_READ_REQUESTS_PER_TX + MAX_NULLIFIER_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX }; use dep::types::{ abis::{ @@ -73,7 +73,8 @@ mod tests { }, hash::{compute_note_hash_nonce, compute_unique_siloed_note_hash}, tests::{fixture_builder::FixtureBuilder, sort::sort_get_sorted_hints}, - utils::{arrays::{array_eq, array_length}}, traits::is_default_array + utils::{arrays::{array_eq, array_length}}, traits::is_default_array, + grumpkin_private_key::GrumpkinPrivateKey }; struct PrivateKernelTailToPublicInputsBuilder { @@ -170,7 +171,7 @@ mod tests { sorted_new_nullifiers_indexes, nullifier_read_request_hints: self.nullifier_read_request_hints_builder.to_hints(), nullifier_commitment_hints: sorted_nullifier_commitment_hints, - master_nullifier_secret_keys: unsafe::zeroed() + master_nullifier_secret_keys: [GrumpkinPrivateKey::default(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], }; kernel.execute() } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr index 04f1546addf..d810a3cb676 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr @@ -73,7 +73,7 @@ impl PrivateAccumulatedDataBuilder { unencrypted_logs_hash: self.unencrypted_logs_hash, encrypted_log_preimages_length: self.encrypted_log_preimages_length, unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, - public_data_update_requests: unsafe::zeroed() + public_data_update_requests: [PublicDataUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], } } @@ -81,8 +81,8 @@ impl PrivateAccumulatedDataBuilder { self, min_revertible_side_effect_counter: u32 ) -> (PublicAccumulatedData, PublicAccumulatedData) { - let mut non_revertible_builder: PublicAccumulatedDataBuilder = unsafe::zeroed(); - let mut revertible_builder: PublicAccumulatedDataBuilder = unsafe::zeroed(); + let mut non_revertible_builder = PublicAccumulatedDataBuilder::default(); + let mut revertible_builder = PublicAccumulatedDataBuilder::default(); for i in 0..MAX_NEW_NOTE_HASHES_PER_TX { let note_hash = self.new_note_hashes.storage[i]; @@ -134,7 +134,7 @@ mod tests { #[test] unconstrained fn splits_revertible_and_non_revertible() { - let mut builder: PrivateAccumulatedDataBuilder = unsafe::zeroed(); + let mut builder = PrivateAccumulatedDataBuilder::default(); let non_revertible_commitments = [ SideEffect { value: 1, counter: 1 }, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr index 89b520392fb..2e77526c725 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr @@ -26,3 +26,19 @@ struct PublicAccumulatedData { public_call_stack: [CallRequest; MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], } + +impl Default for PublicAccumulatedData { + fn default() -> Self { + PublicAccumulatedData { + new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_TX], + new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_TX], + new_l2_to_l1_msgs: [0; MAX_NEW_L2_TO_L1_MSGS_PER_TX], + encrypted_logs_hash: 0, + unencrypted_logs_hash: 0, + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + public_data_update_requests: [PublicDataUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], + public_call_stack: [CallRequest::default(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], + } + } +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr index 1901726e417..f809fc6c3e0 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr @@ -75,7 +75,7 @@ impl Deserialize for CallContext { } #[test] -fn serialize_deserialize_of_empty() { +fn serialize_deserialize_of_default() { let context = CallContext::default(); let serialized = context.serialize(); let deserialized = CallContext::deserialize(serialized); 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 859183efcde..8d46a467981 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 @@ -217,14 +217,14 @@ impl FixtureBuilder { pub fn to_public_kernel_circuit_public_inputs(self, revertible: bool) -> PublicKernelCircuitPublicInputs { let accumulated_data = self.to_public_accumulated_data(); let end_non_revertible = if revertible { - unsafe::zeroed() + PublicAccumulatedData::default() } else { accumulated_data }; let end = if revertible { accumulated_data } else { - unsafe::zeroed() + PublicAccumulatedData::default() }; let validation_requests = self.to_validation_requests(); let constants = self.to_constant_data(); From bad489d7b53300c1987bdd726983e346dee60b9b Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 10 Apr 2024 18:28:06 +0000 Subject: [PATCH 75/77] merge --- .../sequencer-client/src/tx_validator/double_spend_validator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/sequencer-client/src/tx_validator/double_spend_validator.ts b/yarn-project/sequencer-client/src/tx_validator/double_spend_validator.ts index 695e7b7b6f5..68da594f75f 100644 --- a/yarn-project/sequencer-client/src/tx_validator/double_spend_validator.ts +++ b/yarn-project/sequencer-client/src/tx_validator/double_spend_validator.ts @@ -34,7 +34,7 @@ export class DoubleSpendTxValidator implements TxValidator { } async #uniqueNullifiers(tx: AnyTx, thisBlockNullifiers: Set): Promise { - const newNullifiers = tx.data.getNonEmptyNullifiers().map(x => x.toBigInt()); + const newNullifiers = tx.data.getNonZeroNullifiers().map(x => x.toBigInt()); // Ditch this tx if it has repeated nullifiers const uniqueNullifiers = new Set(newNullifiers); From de4ac0e8cfa4f3133f6ed815dff37dbd760cf147 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 10 Apr 2024 18:57:59 +0000 Subject: [PATCH 76/77] add --- .../context/inputs/public_context_inputs.nr | 11 +++++++++ .../aztec/src/context/public_context.nr | 23 +++++++++++++++++++ .../shared_mutable/shared_mutable.nr | 4 ++-- .../contracts/auth_contract/src/main.nr | 6 ++--- .../crates/types/src/address/aztec_address.nr | 2 +- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr b/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr index 804485feea1..4569524283a 100644 --- a/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr +++ b/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr @@ -13,3 +13,14 @@ struct PublicContextInputs { start_side_effect_counter: u32, } // docs:end:public-context-inputs + +impl Default for PublicContextInputs { + fn default() -> Self { + PublicContextInputs { + call_context: CallContext::default(), + historical_header: Header::default(), + public_global_variables: PublicGlobalVariables::default(), + start_side_effect_counter: 0 as u32, + } + } +} diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index 3f2fba1cf79..52da895032e 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -53,6 +53,29 @@ struct PublicContext { prover_address: AztecAddress, } +impl Default for PublicContext { + fn default() -> Self { + PublicContext { + inputs: PublicContextInputs::default(), + side_effect_counter: 0 as u32, + args_hash : 0, + return_values : BoundedVec::new(), + nullifier_read_requests: BoundedVec::new(), + nullifier_non_existent_read_requests: BoundedVec::new(), + contract_storage_update_requests: BoundedVec::new(), + contract_storage_reads: BoundedVec::new(), + public_call_stack_hashes: BoundedVec::new(), + new_note_hashes: BoundedVec::new(), + new_nullifiers: BoundedVec::new(), + new_l2_to_l1_msgs: BoundedVec::new(), + unencrypted_logs_hash: 0, + unencrypted_logs_preimages_length: 0, + historical_header: Header::default(), + prover_address: AztecAddress::zero(), + } + } +} + impl PublicContext { pub fn new(inputs: PublicContextInputs, args_hash: Field) -> PublicContext { PublicContext { diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr index 8a795b43680..9093ead81d6 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr @@ -116,11 +116,11 @@ mod test { fn create_context(block_number: Field, private: bool) -> Context { if private { - let mut private_context: PrivateContext = unsafe::zeroed(); + let mut private_context = PrivateContext::default(); private_context.historical_header.global_variables.block_number = block_number; Context::private(&mut private_context) } else { - let mut public_context: PublicContext = unsafe::zeroed(); + let mut public_context = PublicContext::default(); public_context.inputs.public_global_variables.block_number = block_number; Context::public(&mut public_context) } diff --git a/noir-projects/noir-contracts/contracts/auth_contract/src/main.nr b/noir-projects/noir-contracts/contracts/auth_contract/src/main.nr index a8025208c60..784f4ad1702 100644 --- a/noir-projects/noir-contracts/contracts/auth_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/auth_contract/src/main.nr @@ -1,10 +1,10 @@ // Test contract showing basic public access control that can be used in private. It uses a SharedMutable state variable to // publicly store the address of an authorized account that can call private functions. contract Auth { - use dep::aztec::protocol_types::address::AztecAddress; + use dep::aztec::protocol_types::{address::AztecAddress, traits::is_zero}; use dep::aztec::{ log::{emit_unencrypted_log, emit_unencrypted_log_from_private}, - state_vars::{PublicImmutable, SharedMutable} + state_vars::{PublicImmutable, SharedMutable}, }; // Authorizing a new address has a certain block delay before it goes into effect. @@ -20,7 +20,7 @@ contract Auth { #[aztec(public)] #[aztec(initializer)] fn constructor(admin: AztecAddress) { - assert(!admin.is_zero(), "invalid admin"); + assert(!is_zero(admin), "invalid admin"); storage.admin.initialize(admin); // Note that we don't initialize authorized with any value: because storage defaults to 0 it'll have a 'post' // value of 0 and block of change 0, meaning it is effectively autoinitialized at the zero adddress. diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr index d5b88adfa0f..795a7db24c3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr @@ -2,7 +2,7 @@ use crate::{ crate::address::{eth_address::EthAddress, partial_address::PartialAddress, public_keys_hash::PublicKeysHash}, constants::{AZTEC_ADDRESS_LENGTH, GENERATOR_INDEX__CONTRACT_ADDRESS}, contract_class_id::ContractClassId, hash::pedersen_hash, grumpkin_point::GrumpkinPoint, - traits::{Zero, ToField, Serialize, Deserialize}, utils + traits::{Zero, FromField, ToField, Serialize, Deserialize}, utils }; // Aztec address From 8370fbc62c17393b008024932314c09dcde274f6 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 11 Apr 2024 07:11:46 +0000 Subject: [PATCH 77/77] refactor: not using unsafe::zeroed() --- .../aztec-nr/address-note/src/address_note.nr | 2 +- noir-projects/aztec-nr/authwit/src/auth.nr | 2 +- .../aztec-nr/authwit/src/entrypoint/app.nr | 2 +- .../aztec-nr/aztec/src/context/avm_context.nr | 2 +- .../aztec-nr/aztec/src/context/gas.nr | 2 +- .../globals/private_global_variables.nr | 4 +- .../context/inputs/private_context_inputs.nr | 10 ++-- .../context/inputs/public_context_inputs.nr | 10 ++-- .../aztec-nr/aztec/src/context/interface.nr | 2 +- .../aztec/src/context/private_context.nr | 30 +++++----- .../aztec/src/context/public_context.nr | 10 ++-- .../aztec-nr/aztec/src/note/note_header.nr | 6 +- .../shared_mutable/shared_mutable.nr | 4 +- .../aztec-nr/field-note/src/field_note.nr | 2 +- .../aztec-nr/tests/src/mock/test_note.nr | 4 +- .../aztec-nr/tests/src/note_getter_test.nr | 14 ++--- .../aztec-nr/value-note/src/value_note.nr | 2 +- .../src/dapp_payload.nr | 2 +- .../src/subscription_note.nr | 2 +- .../contracts/auth_contract/src/main.nr | 2 +- .../contracts/avm_test_contract/src/main.nr | 18 +++--- .../benchmarking_contract/src/main.nr | 2 +- .../contracts/child_contract/src/main.nr | 4 +- .../src/types/card_note.nr | 2 +- .../src/ecdsa_public_key_note.nr | 4 +- .../ecdsa_account_contract/src/main.nr | 2 +- .../contracts/fpc_contract/src/interfaces.nr | 4 +- .../contracts/fpc_contract/src/main.nr | 4 +- .../lending_contract/src/interfaces.nr | 8 +-- .../contracts/lending_contract/src/main.nr | 8 +-- .../contracts/parent_contract/src/main.nr | 10 ++-- .../schnorr_account_contract/src/main.nr | 2 +- .../src/public_key_note.nr | 2 +- .../src/main.nr | 2 +- .../src/main.nr | 2 +- .../stateful_test_contract/src/main.nr | 2 +- .../contracts/test_contract/src/interface.nr | 18 +++--- .../src/interfaces.nr | 2 +- .../src/types/token_note.nr | 2 +- .../src/types/transparent_note.nr | 6 +- .../src/token_interface.nr | 6 +- .../token_contract/src/types/token_note.nr | 2 +- .../src/types/transparent_note.nr | 6 +- .../uniswap_contract/src/interfaces.nr | 6 +- .../contracts/uniswap_contract/src/main.nr | 2 +- .../parity-lib/src/parity_public_inputs.nr | 6 +- .../parity-lib/src/root/root_parity_input.nr | 8 +-- .../crates/private-kernel-lib/src/common.nr | 16 +++--- .../kernel_circuit_public_inputs_composer.nr | 10 ++-- .../src/private_kernel_init.nr | 6 +- .../src/private_kernel_inner.nr | 14 ++--- .../src/private_kernel_tail.nr | 12 ++-- .../src/private_kernel_tail_to_public.nr | 22 ++++---- .../crates/public-kernel-lib/src/common.nr | 24 ++++---- .../src/public_kernel_app_logic.nr | 6 +- .../src/public_kernel_setup.nr | 10 ++-- .../src/public_kernel_tail.nr | 8 +-- .../src/public_kernel_teardown.nr | 10 ++-- .../crates/public-kernel-lib/src/utils.nr | 10 ++-- .../src/non_existent_read_request_reset.nr | 8 +-- .../src/nullifier_read_request_reset.nr | 8 +-- .../private_validation_request_processor.nr | 4 +- .../src/read_request_reset.nr | 20 +++---- ...non_existent_read_request_hints_builder.nr | 4 +- .../nullifier_read_request_hints_builder.nr | 2 +- .../base_or_merge_rollup_public_inputs.nr | 12 ++-- .../src/abis/constant_rollup_data.nr | 8 +-- .../src/abis/previous_rollup_data.nr | 12 ++-- .../rollup-lib/src/base/base_rollup_inputs.nr | 48 ++++++++-------- .../src/merge/merge_rollup_inputs.nr | 28 +++++----- .../crates/rollup-lib/src/root.nr | 6 +- .../rollup-lib/src/root/root_rollup_inputs.nr | 12 ++-- .../src/tests/merge_rollup_inputs.nr | 8 +-- .../src/tests/previous_rollup_data.nr | 4 +- .../src/tests/root_rollup_inputs.nr | 8 +-- .../combined_accumulated_data.nr | 6 +- .../private_accumulated_data_builder.nr | 18 +++--- .../public_accumulated_data.nr | 12 ++-- .../public_accumulated_data_builder.nr | 4 +- .../src/abis/append_only_tree_snapshot.nr | 6 +- .../crates/types/src/abis/call_context.nr | 42 +++++++------- .../crates/types/src/abis/call_request.nr | 8 +-- .../crates/types/src/abis/caller_context.nr | 6 +- .../types/src/abis/combined_constant_data.nr | 8 +-- .../crates/types/src/abis/function_data.nr | 18 +++--- .../types/src/abis/function_selector.nr | 4 +- .../crates/types/src/abis/global_variables.nr | 8 +-- ...te_kernel_circuit_public_inputs_builder.nr | 12 ++-- .../public_kernel_circuit_public_inputs.nr | 8 +-- ...ic_kernel_circuit_public_inputs_builder.nr | 14 ++--- .../crates/types/src/abis/max_block_number.nr | 30 +++++----- .../types/src/abis/membership_witness.nr | 14 ++--- .../abis/nullifier_key_validation_request.nr | 16 +++--- .../types/src/abis/nullifier_leaf_preimage.nr | 8 +-- .../types/src/abis/private_call_stack_item.nr | 22 ++++---- .../src/abis/private_circuit_public_inputs.nr | 46 +++++++-------- .../types/src/abis/public_call_stack_item.nr | 6 +- .../src/abis/public_circuit_public_inputs.nr | 48 ++++++++-------- .../crates/types/src/abis/public_data_read.nr | 6 +- .../src/abis/public_data_update_request.nr | 6 +- .../crates/types/src/abis/read_request.nr | 12 ++-- .../crates/types/src/abis/side_effect.nr | 8 +-- .../validation_requests_builder.nr | 6 +- .../crates/types/src/address/aztec_address.nr | 6 +- .../crates/types/src/address/eth_address.nr | 6 +- .../crates/types/src/constants.nr | 4 +- .../crates/types/src/content_commitment.nr | 10 ++-- .../crates/types/src/contrakt/storage_read.nr | 6 +- .../src/contrakt/storage_update_request.nr | 8 +-- .../crates/types/src/contrakt/traits.nr | 18 +++--- .../crates/types/src/grumpkin_point.nr | 4 +- .../crates/types/src/grumpkin_private_key.nr | 4 +- .../crates/types/src/hash.nr | 2 +- .../crates/types/src/header.nr | 28 +++++----- .../types/src/merkle_tree/indexed_tree.nr | 8 +-- .../types/src/merkle_tree/membership.nr | 4 +- .../types/src/merkle_tree/merkle_tree.nr | 4 +- .../types/src/messaging/l2_to_l1_message.nr | 4 +- .../crates/types/src/mocked.nr | 12 ++-- .../types/src/partial_state_reference.nr | 16 +++--- .../crates/types/src/public_data_tree_leaf.nr | 6 +- .../src/public_data_tree_leaf_preimage.nr | 10 ++-- .../crates/types/src/state_reference.nr | 12 ++-- .../crates/types/src/tests/fixture_builder.nr | 32 +++++------ .../crates/types/src/tests/fixtures.nr | 18 +++--- .../src/tests/fixtures/contract_functions.nr | 4 +- .../types/src/tests/fixtures/contracts.nr | 2 +- .../types/src/tests/merkle_tree_utils.nr | 6 +- .../src/tests/private_call_data_builder.nr | 8 +-- .../private_circuit_public_inputs_builder.nr | 16 +++--- .../src/tests/public_call_data_builder.nr | 20 +++---- .../public_circuit_public_inputs_builder.nr | 10 ++-- .../crates/types/src/tests/sort.nr | 8 +-- .../crates/types/src/traits.nr | 10 ++-- .../types/src/transaction/tx_context.nr | 16 +++--- .../types/src/transaction/tx_request.nr | 14 ++--- .../crates/types/src/utils/arrays.nr | 56 +++++++++---------- 137 files changed, 694 insertions(+), 694 deletions(-) diff --git a/noir-projects/aztec-nr/address-note/src/address_note.nr b/noir-projects/aztec-nr/address-note/src/address_note.nr index 3822b1c98f6..ee44fe1efb8 100644 --- a/noir-projects/aztec-nr/address-note/src/address_note.nr +++ b/noir-projects/aztec-nr/address-note/src/address_note.nr @@ -62,7 +62,7 @@ impl NoteInterface for AddressNote { impl AddressNote { pub fn new(address: AztecAddress, owner: AztecAddress) -> Self { let randomness = unsafe_rand(); - AddressNote { address, owner, randomness, header: NoteHeader::default() } + AddressNote { address, owner, randomness, header: NoteHeader::empty() } } // docs:end:address_note_def } diff --git a/noir-projects/aztec-nr/authwit/src/auth.nr b/noir-projects/aztec-nr/authwit/src/auth.nr index d38ff2bbf78..a25fd212f0b 100644 --- a/noir-projects/aztec-nr/authwit/src/auth.nr +++ b/noir-projects/aztec-nr/authwit/src/auth.nr @@ -37,7 +37,7 @@ pub fn assert_current_call_valid_authwit_public( on_behalf_of, function_selector, [inner_hash], - GasOpts::default() + GasOpts::empty() )[0]; assert(result == IS_VALID_SELECTOR, "Message not authorized by account"); } diff --git a/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr b/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr index d65334c6b02..470d8f15d59 100644 --- a/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr +++ b/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr @@ -10,7 +10,7 @@ global APP_PAYLOAD_SIZE_IN_BYTES: u64 = 420; global ACCOUNT_MAX_CALLS: u64 = 4; -// Note: If you change the following struct you have to update default_entrypoint.ts +// Note: If you change the following struct you have to update empty_entrypoint.ts // docs:start:app-payload-struct struct AppPayload { function_calls: [FunctionCall; ACCOUNT_MAX_CALLS], diff --git a/noir-projects/aztec-nr/aztec/src/context/avm_context.nr b/noir-projects/aztec-nr/aztec/src/context/avm_context.nr index 4f80785ca95..8231a82519c 100644 --- a/noir-projects/aztec-nr/aztec/src/context/avm_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/avm_context.nr @@ -209,7 +209,7 @@ impl ContextInterface for AvmContext { } fn get_header(self) -> Header { assert(false, "'get_header' not implemented!"); - Header::default() + Header::empty() } fn get_args_hash(self) -> Field { self.inputs.args_hash diff --git a/noir-projects/aztec-nr/aztec/src/context/gas.nr b/noir-projects/aztec-nr/aztec/src/context/gas.nr index 346eb089496..a6ae97acc6e 100644 --- a/noir-projects/aztec-nr/aztec/src/context/gas.nr +++ b/noir-projects/aztec-nr/aztec/src/context/gas.nr @@ -5,7 +5,7 @@ struct GasOpts { } impl GasOpts { - pub fn default() -> Self { + pub fn empty() -> Self { GasOpts { l1_gas: Option::none(), l2_gas: Option::none(), da_gas: Option::none() } } diff --git a/noir-projects/aztec-nr/aztec/src/context/globals/private_global_variables.nr b/noir-projects/aztec-nr/aztec/src/context/globals/private_global_variables.nr index b918db9645a..5d75180462b 100644 --- a/noir-projects/aztec-nr/aztec/src/context/globals/private_global_variables.nr +++ b/noir-projects/aztec-nr/aztec/src/context/globals/private_global_variables.nr @@ -9,8 +9,8 @@ struct PrivateGlobalVariables { } // docs:end:private-global-variables -impl Default for PrivateGlobalVariables { - fn default() -> Self { +impl Empty for PrivateGlobalVariables { + fn empty() -> Self { PrivateGlobalVariables { chain_id: 0, version: 0, diff --git a/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr b/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr index 5f2b89670d8..e4ed9f39988 100644 --- a/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr +++ b/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr @@ -11,12 +11,12 @@ struct PrivateContextInputs { } // docs:end:private-context-inputs -impl Default for PrivateContextInputs { - fn default() -> Self { +impl Empty for PrivateContextInputs { + fn empty() -> Self { PrivateContextInputs { - call_context : CallContext::default(), - historical_header: Header::default(), - private_global_variables: PrivateGlobalVariables::default(), + call_context : CallContext::empty(), + historical_header: Header::empty(), + private_global_variables: PrivateGlobalVariables::empty(), start_side_effect_counter: 0 as u32, } } diff --git a/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr b/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr index 4569524283a..d77bb3266fa 100644 --- a/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr +++ b/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr @@ -14,12 +14,12 @@ struct PublicContextInputs { } // docs:end:public-context-inputs -impl Default for PublicContextInputs { - fn default() -> Self { +impl Empty for PublicContextInputs { + fn empty() -> Self { PublicContextInputs { - call_context: CallContext::default(), - historical_header: Header::default(), - public_global_variables: PublicGlobalVariables::default(), + call_context: CallContext::empty(), + historical_header: Header::empty(), + public_global_variables: PublicGlobalVariables::empty(), start_side_effect_counter: 0 as u32, } } diff --git a/noir-projects/aztec-nr/aztec/src/context/interface.nr b/noir-projects/aztec-nr/aztec/src/context/interface.nr index a2a3d2e5f24..d92788f99be 100644 --- a/noir-projects/aztec-nr/aztec/src/context/interface.nr +++ b/noir-projects/aztec-nr/aztec/src/context/interface.nr @@ -19,7 +19,7 @@ trait ContextInterface { } // TEMPORARY: This trait is to promote sharing of the current public context -// and the upcoming AvmContext. This will be removed once the AvmContext is the default. +// and the upcoming AvmContext. This will be removed once the AvmContext is the empty. // If you are adding something here, then you should also implement it in the AvmContext. trait PublicContextInterface { fn block_number(self) -> Field; diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index cc7b740ff61..887263786b8 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -70,15 +70,15 @@ struct PrivateContext { nullifier_key: Option, } -impl Default for PrivateContext { - fn default() -> Self { +impl Empty for PrivateContext { + fn empty() -> Self { PrivateContext { - inputs: PrivateContextInputs::default(), + inputs: PrivateContextInputs::empty(), side_effect_counter: 0 as u32, min_revertible_side_effect_counter: 0 as u32, args_hash : 0, return_values : BoundedVec::new(), - max_block_number: MaxBlockNumber::default(), + max_block_number: MaxBlockNumber::empty(), note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), nullifier_key_validation_requests: BoundedVec::new(), @@ -87,7 +87,7 @@ impl Default for PrivateContext { private_call_stack_hashes : BoundedVec::new(), public_call_stack_hashes : BoundedVec::new(), new_l2_to_l1_msgs : BoundedVec::new(), - historical_header: Header::default(), + historical_header: Header::empty(), nullifier_key: Option::none(), } } @@ -154,7 +154,7 @@ impl PrivateContext { min_revertible_side_effect_counter, args_hash, return_values: BoundedVec::new(), - max_block_number: MaxBlockNumber::default(), + max_block_number: MaxBlockNumber::empty(), note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), nullifier_key_validation_requests: BoundedVec::new(), @@ -274,7 +274,7 @@ impl PrivateContext { secret ); - // Push nullifier (and the "commitment" corresponding to this can be "default") + // Push nullifier (and the "commitment" corresponding to this can be "empty") self.push_new_nullifier(nullifier, 0) } // docs:end:consume_l1_to_l2_message @@ -499,19 +499,19 @@ impl PrivateContext { call_context: reader.read_struct(CallContext::deserialize), args_hash: reader.read(), return_values: [0; RETURN_VALUES_LENGTH], - nullifier_read_requests: [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], - nullifier_non_existent_read_requests: [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], - contract_storage_update_requests: [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], - contract_storage_reads: [StorageRead::default(); MAX_PUBLIC_DATA_READS_PER_CALL], + nullifier_read_requests: [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], + nullifier_non_existent_read_requests: [ReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], + contract_storage_update_requests: [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], + contract_storage_reads: [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL], public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], - new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL], - new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL], - new_l2_to_l1_msgs: [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], + new_note_hashes: [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL], + new_nullifiers: [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL], + new_l2_to_l1_msgs: [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], start_side_effect_counter: 0, end_side_effect_counter: 0, unencrypted_logs_hash: 0, unencrypted_log_preimages_length: 0, - historical_header: Header::default(), + historical_header: Header::empty(), prover_address: AztecAddress::zero(), revert_code: 0 }, diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index 52da895032e..8f30dfcc841 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -53,10 +53,10 @@ struct PublicContext { prover_address: AztecAddress, } -impl Default for PublicContext { - fn default() -> Self { +impl Empty for PublicContext { + fn empty() -> Self { PublicContext { - inputs: PublicContextInputs::default(), + inputs: PublicContextInputs::empty(), side_effect_counter: 0 as u32, args_hash : 0, return_values : BoundedVec::new(), @@ -70,7 +70,7 @@ impl Default for PublicContext { new_l2_to_l1_msgs: BoundedVec::new(), unencrypted_logs_hash: 0, unencrypted_logs_preimages_length: 0, - historical_header: Header::default(), + historical_header: Header::empty(), prover_address: AztecAddress::zero(), } } @@ -280,7 +280,7 @@ impl PublicContextInterface for PublicContext { secret ); - // Push nullifier (and the "commitment" corresponding to this can be "default") + // Push nullifier (and the "commitment" corresponding to this can be "empty") self.push_new_nullifier(nullifier, 0) } diff --git a/noir-projects/aztec-nr/aztec/src/note/note_header.nr b/noir-projects/aztec-nr/aztec/src/note/note_header.nr index fb95c561a76..a91a2cb6b64 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_header.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_header.nr @@ -1,6 +1,6 @@ use dep::protocol_types::address::AztecAddress; use dep::protocol_types::traits::Serialize; -use dep::std::default::Default; +use dep::std::empty::Empty; struct NoteHeader { contract_address: AztecAddress, @@ -11,8 +11,8 @@ struct NoteHeader { is_transient: bool, } -impl Default for NoteHeader { - fn default() -> Self { +impl Empty for NoteHeader { + fn empty() -> Self { NoteHeader { contract_address: AztecAddress::zero(), nonce: 0, storage_slot: 0, is_transient: false } } } diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr index 9093ead81d6..be7b7026b8c 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr @@ -116,11 +116,11 @@ mod test { fn create_context(block_number: Field, private: bool) -> Context { if private { - let mut private_context = PrivateContext::default(); + let mut private_context = PrivateContext::empty(); private_context.historical_header.global_variables.block_number = block_number; Context::private(&mut private_context) } else { - let mut public_context = PublicContext::default(); + let mut public_context = PublicContext::empty(); public_context.inputs.public_global_variables.block_number = block_number; Context::public(&mut public_context) } diff --git a/noir-projects/aztec-nr/field-note/src/field_note.nr b/noir-projects/aztec-nr/field-note/src/field_note.nr index 654d5806c98..f6350ddd613 100644 --- a/noir-projects/aztec-nr/field-note/src/field_note.nr +++ b/noir-projects/aztec-nr/field-note/src/field_note.nr @@ -34,7 +34,7 @@ impl NoteInterface for FieldNote { impl FieldNote { pub fn new(value: Field) -> Self { - FieldNote { value, header: NoteHeader::default() } + FieldNote { value, header: NoteHeader::empty() } } } diff --git a/noir-projects/aztec-nr/tests/src/mock/test_note.nr b/noir-projects/aztec-nr/tests/src/mock/test_note.nr index 9bc70eead23..bc4f262550f 100644 --- a/noir-projects/aztec-nr/tests/src/mock/test_note.nr +++ b/noir-projects/aztec-nr/tests/src/mock/test_note.nr @@ -19,7 +19,7 @@ impl NoteInterface for TestNote { fn deserialize_content(fields: [Field; TEST_NOTE_LENGTH]) -> Self { Self { value: fields[0], - header: NoteHeader::default(), + header: NoteHeader::empty(), } } @@ -56,6 +56,6 @@ impl NoteInterface for TestNote { impl TestNote { pub fn new(value: Field) -> Self { - TestNote { value, header: NoteHeader::default() } + TestNote { value, header: NoteHeader::empty() } } } diff --git a/noir-projects/aztec-nr/tests/src/note_getter_test.nr b/noir-projects/aztec-nr/tests/src/note_getter_test.nr index 42e37366193..2ae8d21dae1 100644 --- a/noir-projects/aztec-nr/tests/src/note_getter_test.nr +++ b/noir-projects/aztec-nr/tests/src/note_getter_test.nr @@ -10,7 +10,7 @@ use crate::mock::test_note::TestNote; #[test] fn sets_note_manually_and_fetches_it() { - let mut context = PrivateContext::default(); + let mut context = PrivateContext::empty(); context.inputs.call_context.storage_contract_address = AztecAddress::from_field(69); let mut test_note = TestNote::new(1337); @@ -28,7 +28,7 @@ fn sets_note_manually_and_fetches_it() { #[test(should_fail)] fn cannot_return_zero_notes() { - let mut context = PrivateContext::default(); + let mut context = PrivateContext::empty(); let storage_slot: Field = 0; let mut opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; @@ -38,7 +38,7 @@ fn cannot_return_zero_notes() { #[test(should_fail)] fn mismatched_address() { - let mut context = PrivateContext::default(); + let mut context = PrivateContext::empty(); context.inputs.call_context.storage_contract_address = AztecAddress::from_field(1); let storage_slot: Field = 0; @@ -51,7 +51,7 @@ fn mismatched_address() { #[test(should_fail)] fn mismatched_storage_slot() { - let mut context = PrivateContext::default(); + let mut context = PrivateContext::empty(); context.inputs.call_context.storage_contract_address = AztecAddress::from_field(1); let mut test_note = TestNote::new(1); @@ -68,7 +68,7 @@ fn mismatched_storage_slot() { #[test(should_fail)] fn invalid_selector() { - let mut context = PrivateContext::default(); + let mut context = PrivateContext::empty(); context.inputs.call_context.storage_contract_address = AztecAddress::from_field(1); let mut test_note = TestNote::new(1); @@ -90,7 +90,7 @@ fn invalid_selector() { #[test(should_fail)] fn invalid_note_order() { - let mut context = PrivateContext::default(); + let mut context = PrivateContext::empty(); let mut opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; opt_notes[0] = Option::some(TestNote::new(1)); @@ -108,7 +108,7 @@ fn invalid_note_order() { #[test] fn sparse_notes_array() { - let mut context = PrivateContext::default(); + let mut context = PrivateContext::empty(); let mut opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; opt_notes[1] = Option::some(TestNote::new(0)); diff --git a/noir-projects/aztec-nr/value-note/src/value_note.nr b/noir-projects/aztec-nr/value-note/src/value_note.nr index fa0d73275d7..4598c1ab17b 100644 --- a/noir-projects/aztec-nr/value-note/src/value_note.nr +++ b/noir-projects/aztec-nr/value-note/src/value_note.nr @@ -60,7 +60,7 @@ impl NoteInterface for ValueNote { impl ValueNote { pub fn new(value: Field, owner: AztecAddress) -> Self { let randomness = unsafe_rand(); - let header = NoteHeader::default(); + let header = NoteHeader::empty(); ValueNote { value, owner, randomness, header } } } diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/dapp_payload.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/dapp_payload.nr index 8d6e9711a4d..6948eb59518 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/dapp_payload.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/dapp_payload.nr @@ -10,7 +10,7 @@ global DAPP_PAYLOAD_SIZE_IN_BYTES: u64 = 129; global DAPP_MAX_CALLS: u64 = 1; -// Note: If you change the following struct you have to update default_entrypoint.ts +// Note: If you change the following struct you have to update empty_entrypoint.ts // docs:start:app-payload-struct struct DAppPayload { function_calls: [FunctionCall; DAPP_MAX_CALLS], diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr index 2ce1b491159..c541c92ae39 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr @@ -54,6 +54,6 @@ impl NoteInterface for SubscriptionNote { impl SubscriptionNote { pub fn new(owner: AztecAddress, expiry_block_number: Field, remaining_txs: Field) -> Self { - SubscriptionNote { owner, expiry_block_number, remaining_txs, header: NoteHeader::default() } + SubscriptionNote { owner, expiry_block_number, remaining_txs, header: NoteHeader::empty() } } } diff --git a/noir-projects/noir-contracts/contracts/auth_contract/src/main.nr b/noir-projects/noir-contracts/contracts/auth_contract/src/main.nr index 784f4ad1702..bca1dd60088 100644 --- a/noir-projects/noir-contracts/contracts/auth_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/auth_contract/src/main.nr @@ -22,7 +22,7 @@ contract Auth { fn constructor(admin: AztecAddress) { assert(!is_zero(admin), "invalid admin"); storage.admin.initialize(admin); - // Note that we don't initialize authorized with any value: because storage defaults to 0 it'll have a 'post' + // Note that we don't initialize authorized with any value: because storage emptys to 0 it'll have a 'post' // value of 0 and block of change 0, meaning it is effectively autoinitialized at the zero adddress. } diff --git a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr index c929cff681d..c13cb5373df 100644 --- a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr @@ -206,7 +206,7 @@ contract AvmTest { context.this_address(), FunctionSelector::from_signature("constant_field_acvm()"), [], - GasOpts::default() + GasOpts::empty() ); data_to_return[0] } @@ -217,14 +217,14 @@ contract AvmTest { context.this_address(), FunctionSelector::from_signature("constant_field_avm()"), [], - GasOpts::default() + GasOpts::empty() ); data_to_return[0] } #[aztec(public-vm)] fn avm_to_acvm_call(selector: FunctionSelector, args: Field) { - context.call_public_function(context.this_address(), selector, [args], GasOpts::default()); + context.call_public_function(context.this_address(), selector, [args], GasOpts::empty()); } /************************************************************************ @@ -404,7 +404,7 @@ contract AvmTest { // Nested call let results = context.call_public_function_raw( - GasOpts::default(), + GasOpts::empty(), context.this_address(), selector, [arg_a, arg_b] @@ -457,7 +457,7 @@ contract AvmTest { context.this_address(), selector, [arg_a, arg_b], - GasOpts::default() + GasOpts::empty() ); // this explicit size in the return variable is necessary to ensure that ret_size is compile-time // (ensure the data_to_return is in a HeapArray not a HeapVector) @@ -472,7 +472,7 @@ contract AvmTest { let selector = FunctionSelector::from_signature("add_args_return(Field,Field)").to_field(); let (result_data, success): ([Field; 1], u8) = context.static_call_public_function_raw( - GasOpts::default(), + GasOpts::empty(), context.this_address(), selector, [arg_a, arg_b] @@ -487,7 +487,7 @@ contract AvmTest { let selector = FunctionSelector::from_signature("set_storage_single(Field)").to_field(); let calldata: [Field; 1] = [20]; - let (_data_to_return, success): ([Field; 0], u8) = context.static_call_public_function_raw(GasOpts::default(), context.this_address(), selector, calldata); + let (_data_to_return, success): ([Field; 0], u8) = context.static_call_public_function_raw(GasOpts::empty(), context.this_address(), selector, calldata); success } @@ -501,7 +501,7 @@ contract AvmTest { context.this_address(), selector, [arg_a, arg_b], - GasOpts::default() + GasOpts::empty() ); result_data[0] @@ -513,6 +513,6 @@ contract AvmTest { let selector = FunctionSelector::from_signature("set_storage_single(Field)"); let calldata: [Field; 1] = [20]; - let _resultData: [Field; RETURN_VALUES_LENGTH] = context.static_call_public_function(context.this_address(), selector, calldata, GasOpts::default()); + let _resultData: [Field; RETURN_VALUES_LENGTH] = context.static_call_public_function(context.this_address(), selector, calldata, GasOpts::empty()); } } diff --git a/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr b/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr index f909e0290ee..58c3ac9272a 100644 --- a/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr @@ -48,7 +48,7 @@ contract Benchmarking { context.this_address(), FunctionSelector::from_signature("broadcast((Field))"), [owner.to_field()], - GasOpts::default() + GasOpts::empty() ); } diff --git a/noir-projects/noir-contracts/contracts/child_contract/src/main.nr b/noir-projects/noir-contracts/contracts/child_contract/src/main.nr index 3d8cb921c37..dd6b0cb2372 100644 --- a/noir-projects/noir-contracts/contracts/child_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/child_contract/src/main.nr @@ -96,7 +96,7 @@ contract Child { context.this_address(), pub_set_value_selector, [10], - GasOpts::default() + GasOpts::empty() ); storage.current_value.write(20); @@ -113,7 +113,7 @@ contract Child { context.this_address(), pub_set_value_selector, [10], - GasOpts::default() + GasOpts::empty() ); } } diff --git a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr index bd6a0a4a1f5..f11e3f0b972 100644 --- a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr +++ b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr @@ -20,7 +20,7 @@ struct CardNote { impl CardNote { pub fn new(points: u8, randomness: Field, owner: AztecAddress) -> Self { - CardNote { points, randomness, owner, header: NoteHeader::default() } + CardNote { points, randomness, owner, header: NoteHeader::empty() } } } diff --git a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr index a883eb96ce9..cd25fa907da 100644 --- a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr @@ -63,7 +63,7 @@ impl NoteInterface for EcdsaPublicKeyNote { } y[31] = serialized_note[3].to_be_bytes(32)[31]; - EcdsaPublicKeyNote { x, y, owner: AztecAddress::from_field(serialized_note[4]), header: NoteHeader::default() } + EcdsaPublicKeyNote { x, y, owner: AztecAddress::from_field(serialized_note[4]), header: NoteHeader::empty() } } fn compute_nullifier(self, context: &mut PrivateContext) -> Field { @@ -104,6 +104,6 @@ impl NoteInterface for EcdsaPublicKeyNote { impl EcdsaPublicKeyNote { pub fn new(x: [u8; 32], y: [u8; 32], owner: AztecAddress) -> Self { - EcdsaPublicKeyNote { x, y, owner, header: NoteHeader::default() } + EcdsaPublicKeyNote { x, y, owner, header: NoteHeader::empty() } } } diff --git a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/main.nr index e0cd1cdaf90..a8935f4e1ea 100644 --- a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/main.nr @@ -32,7 +32,7 @@ contract EcdsaAccount { storage.public_key.initialize(&mut pub_key_note, true); } - // Note: If you globally change the entrypoint signature don't forget to update default_entrypoint.ts + // Note: If you globally change the entrypoint signature don't forget to update empty_entrypoint.ts #[aztec(private)] fn entrypoint(app_payload: pub AppPayload, fee_payload: pub FeePayload) { let actions = AccountActions::private(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); diff --git a/noir-projects/noir-contracts/contracts/fpc_contract/src/interfaces.nr b/noir-projects/noir-contracts/contracts/fpc_contract/src/interfaces.nr index fc98c231693..fd006721232 100644 --- a/noir-projects/noir-contracts/contracts/fpc_contract/src/interfaces.nr +++ b/noir-projects/noir-contracts/contracts/fpc_contract/src/interfaces.nr @@ -24,7 +24,7 @@ impl Token { self.address, FunctionSelector::from_signature("transfer_public((Field),(Field),Field,Field)"), [from.to_field(), to.to_field(), amount, nonce], - GasOpts::default() + GasOpts::empty() ); } @@ -40,7 +40,7 @@ impl Token { self.address, FunctionSelector::from_signature("shield((Field),Field,Field,Field)"), [from.to_field(), amount, secret_hash, nonce], - GasOpts::default() + GasOpts::empty() ); } diff --git a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr index fe38de23538..3cd2fa66405 100644 --- a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr @@ -66,7 +66,7 @@ contract FPC { storage.gas_token_address.read_public(), FunctionSelector::from_signature("pay_fee(Field)"), [amount], - GasOpts::default() + GasOpts::empty() )[0]; // Just do public refunds for the present @@ -80,7 +80,7 @@ contract FPC { storage.gas_token_address.read_public(), FunctionSelector::from_signature("pay_fee(Field)"), [amount], - GasOpts::default() + GasOpts::empty() )[0]; Token::at(asset).shield(&mut context, context.this_address(), refund, secret_hash, 0); diff --git a/noir-projects/noir-contracts/contracts/lending_contract/src/interfaces.nr b/noir-projects/noir-contracts/contracts/lending_contract/src/interfaces.nr index 3357c89a023..909d6425754 100644 --- a/noir-projects/noir-contracts/contracts/lending_contract/src/interfaces.nr +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/interfaces.nr @@ -19,7 +19,7 @@ impl PriceFeed { self.address, FunctionSelector::from_signature("get_price(Field)"), [0], - GasOpts::default() + GasOpts::empty() ); U128::from_integer(return_values[0]) @@ -47,7 +47,7 @@ impl Token { self.address, FunctionSelector::from_signature("transfer_public((Field),(Field),Field,Field)"), [from.to_field(), to.to_field(), amount, nonce], - GasOpts::default() + GasOpts::empty() ); } @@ -56,7 +56,7 @@ impl Token { self.address, FunctionSelector::from_signature("mint_public((Field),Field)"), [to.to_field(), amount], - GasOpts::default() + GasOpts::empty() ); } @@ -71,7 +71,7 @@ impl Token { self.address, FunctionSelector::from_signature("burn_public((Field),Field,Field)"), [from.to_field(), amount, nonce], - GasOpts::default() + GasOpts::empty() ); } diff --git a/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr b/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr index 80675129a15..c19337e3739 100644 --- a/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr @@ -127,7 +127,7 @@ contract Lending { context.this_address(), selector, [on_behalf_of, amount, collateral_asset.to_field()], - GasOpts::default() + GasOpts::empty() ); } @@ -162,7 +162,7 @@ contract Lending { context.this_address(), selector, [context.msg_sender().to_field(), to.to_field(), amount], - GasOpts::default() + GasOpts::empty() ); } @@ -221,7 +221,7 @@ contract Lending { context.this_address(), selector, [context.msg_sender().to_field(), to.to_field(), amount], - GasOpts::default() + GasOpts::empty() ); } @@ -285,7 +285,7 @@ contract Lending { context.this_address(), selector, [owner.to_field(), amount, stable_coin.to_field()], - GasOpts::default() + GasOpts::empty() ); } diff --git a/noir-projects/noir-contracts/contracts/parent_contract/src/main.nr b/noir-projects/noir-contracts/contracts/parent_contract/src/main.nr index ec699ebf649..3cdc5de6893 100644 --- a/noir-projects/noir-contracts/contracts/parent_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/parent_contract/src/main.nr @@ -24,7 +24,7 @@ contract Parent { target_contract, target_selector, [init_value], - GasOpts::default() + GasOpts::empty() ); return_values[0] @@ -41,13 +41,13 @@ contract Parent { target_contract, target_selector, [init_value], - GasOpts::default() + GasOpts::empty() )[0]; let return_values = context.call_public_function( target_contract, target_selector, [return_value], - GasOpts::default() + GasOpts::empty() ); return_values[0] @@ -202,7 +202,7 @@ contract Parent { target_selector: FunctionSelector, args: [Field; 1] ) -> Field { - let return_values = context.static_call_public_function(target_contract, target_selector, args, GasOpts::default()); + let return_values = context.static_call_public_function(target_contract, target_selector, args, GasOpts::empty()); return_values[0] } @@ -221,7 +221,7 @@ contract Parent { this_address, pub_entry_point_selector, [target_contract.to_field(), target_selector.to_field(), args[0]], - GasOpts::default() + GasOpts::empty() ); return_values[0] } diff --git a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr index f0b3f2c8ddd..9a33210c0be 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr @@ -36,7 +36,7 @@ contract SchnorrAccount { // docs:end:initialize } - // Note: If you globally change the entrypoint signature don't forget to update default_entrypoint.ts file + // Note: If you globally change the entrypoint signature don't forget to update empty_entrypoint.ts file #[aztec(private)] #[aztec(noinitcheck)] fn entrypoint(app_payload: pub AppPayload, fee_payload: pub FeePayload) { diff --git a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr index 36f5dd3c1b2..f78ad778189 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr @@ -54,6 +54,6 @@ impl NoteInterface for PublicKeyNote { impl PublicKeyNote { pub fn new(x: Field, y: Field, owner: AztecAddress) -> Self { - PublicKeyNote { x, y, owner, header: NoteHeader::default() } + PublicKeyNote { x, y, owner, header: NoteHeader::empty() } } } diff --git a/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr index 134a820b058..c10f5286161 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr @@ -14,7 +14,7 @@ contract SchnorrHardcodedAccount { global ACCOUNT_ACTIONS_STORAGE_SLOT = 1; - // Note: If you globally change the entrypoint signature don't forget to update default_entrypoint.ts + // Note: If you globally change the entrypoint signature don't forget to update empty_entrypoint.ts #[aztec(private)] fn entrypoint(app_payload: pub AppPayload, fee_payload: pub FeePayload) { let actions = AccountActions::private(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); diff --git a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr index 2a8678ce778..1e22c19b39c 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr @@ -10,7 +10,7 @@ contract SchnorrSingleKeyAccount { global ACCOUNT_ACTIONS_STORAGE_SLOT = 1; - // Note: If you globally change the entrypoint signature don't forget to update default_entrypoint.ts + // Note: If you globally change the entrypoint signature don't forget to update empty_entrypoint.ts #[aztec(private)] fn entrypoint(app_payload: pub AppPayload, fee_payload: pub FeePayload) { let actions = AccountActions::private(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); diff --git a/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr index 1a9b9950be4..13483f63fba 100644 --- a/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr @@ -36,7 +36,7 @@ contract StatefulTest { context.this_address(), selector, [owner.to_field(), value], - GasOpts::default() + GasOpts::empty() ); } diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/interface.nr b/noir-projects/noir-contracts/contracts/test_contract/src/interface.nr index 6eb4edbe314..d2202e07b79 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/interface.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/interface.nr @@ -602,7 +602,7 @@ impl TestPublicContextInterface { self.address, FunctionSelector::from_field(0x9e88565a), serialized_args, - GasOpts::default() + GasOpts::empty() ) } @@ -620,7 +620,7 @@ impl TestPublicContextInterface { self.address, FunctionSelector::from_field(0x9749ca06), serialized_args, - GasOpts::default() + GasOpts::empty() ) } @@ -638,7 +638,7 @@ impl TestPublicContextInterface { self.address, FunctionSelector::from_field(0x2fb25188), serialized_args, - GasOpts::default() + GasOpts::empty() ) } @@ -650,7 +650,7 @@ impl TestPublicContextInterface { self.address, FunctionSelector::from_field(0xb5bb17fa), serialized_args, - GasOpts::default() + GasOpts::empty() ) } @@ -670,7 +670,7 @@ impl TestPublicContextInterface { self.address, FunctionSelector::from_field(0xa0f84219), serialized_args, - GasOpts::default() + GasOpts::empty() ) } @@ -690,7 +690,7 @@ impl TestPublicContextInterface { self.address, FunctionSelector::from_field(0x42ca6d60), serialized_args, - GasOpts::default() + GasOpts::empty() ) } @@ -706,7 +706,7 @@ impl TestPublicContextInterface { self.address, FunctionSelector::from_field(0x817a64cb), serialized_args, - GasOpts::default() + GasOpts::empty() ) } @@ -724,7 +724,7 @@ impl TestPublicContextInterface { self.address, FunctionSelector::from_field(0xdf02db8d), serialized_args, - GasOpts::default() + GasOpts::empty() ) } @@ -740,7 +740,7 @@ impl TestPublicContextInterface { self.address, FunctionSelector::from_field(0x86e38c61), serialized_args, - GasOpts::default() + GasOpts::empty() ) } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/interfaces.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/interfaces.nr index 9ef4f1439b7..ae319fb7100 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/interfaces.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/interfaces.nr @@ -23,7 +23,7 @@ impl SlowMap { self.address, FunctionSelector::from_signature("read_at_pub(Field)"), [index], - GasOpts::default() + GasOpts::empty() ); _return_values[0] } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr index 62fd7689608..765f9203368 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr @@ -70,7 +70,7 @@ impl OwnedNote for TokenNote { amount, owner, randomness: unsafe_rand(), - header: NoteHeader::default(), + header: NoteHeader::empty(), } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr index 9e265ffe939..80748a32375 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr @@ -35,7 +35,7 @@ impl NoteInterface for TransparentNote { amount: serialized_note[0], secret_hash: serialized_note[1], secret: 0, - header: NoteHeader::default(), + header: NoteHeader::empty(), } } @@ -59,13 +59,13 @@ impl TransparentNote { // CONSTRUCTORS pub fn new(amount: Field, secret_hash: Field) -> Self { - TransparentNote { amount, secret_hash, secret: 0, header: NoteHeader::default() } + TransparentNote { amount, secret_hash, secret: 0, header: NoteHeader::empty() } } // new oracle call primitive // get me the secret corresponding to this hash pub fn new_from_secret(amount: Field, secret: Field) -> Self { - TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: NoteHeader::default() } + TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: NoteHeader::empty() } } // CUSTOM FUNCTIONS FOR THIS NOTE TYPE diff --git a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/token_interface.nr b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/token_interface.nr index be491ea1412..f547321942e 100644 --- a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/token_interface.nr +++ b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/token_interface.nr @@ -16,7 +16,7 @@ impl Token { self.address, FunctionSelector::from_signature("mint_public((Field),Field)"), [to.to_field(), amount], - GasOpts::default() + GasOpts::empty() ); } @@ -32,7 +32,7 @@ impl Token { self.address, FunctionSelector::from_signature("burn_public((Field),Field,Field)"), [from.to_field(), amount, nonce], - GasOpts::default() + GasOpts::empty() ); } // docs:end:public_burn_interface @@ -42,7 +42,7 @@ impl Token { self.address, FunctionSelector::from_signature("mint_private(Field,Field)"), [amount, secret_hash], - GasOpts::default() + GasOpts::empty() ); } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr index 8b29bf88b17..9a336e4baa9 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr @@ -73,7 +73,7 @@ impl OwnedNote for TokenNote { amount, owner, randomness: unsafe_rand(), - header: NoteHeader::default(), + header: NoteHeader::empty(), } } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr index b2237c3d498..dfc106d2c13 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr @@ -35,7 +35,7 @@ impl NoteInterface for TransparentNote { amount: serialized_note[0], secret_hash: serialized_note[1], secret: 0, - header: NoteHeader::default(), + header: NoteHeader::empty(), } } @@ -59,13 +59,13 @@ impl TransparentNote { // CONSTRUCTORS pub fn new(amount: Field, secret_hash: Field) -> Self { - TransparentNote { amount, secret_hash, secret: 0, header: NoteHeader::default() } + TransparentNote { amount, secret_hash, secret: 0, header: NoteHeader::empty() } } // new oracle call primitive // get me the secret corresponding to this hash pub fn new_from_secret(amount: Field, secret: Field) -> Self { - TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: NoteHeader::default() } + TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: NoteHeader::empty() } } // CUSTOM FUNCTIONS FOR THIS NOTE TYPE diff --git a/noir-projects/noir-contracts/contracts/uniswap_contract/src/interfaces.nr b/noir-projects/noir-contracts/contracts/uniswap_contract/src/interfaces.nr index 20b9b4af2af..888e0814811 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/interfaces.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/interfaces.nr @@ -23,7 +23,7 @@ impl Token { self.address, FunctionSelector::from_signature("transfer_public((Field),(Field),Field,Field)"), [from.to_field(), to.to_field(), amount, nonce], - GasOpts::default() + GasOpts::empty() ); } @@ -57,7 +57,7 @@ impl TokenBridge { self.address, FunctionSelector::from_signature("get_token()"), [], - GasOpts::default() + GasOpts::empty() ); AztecAddress::from_field(return_values[0]) } @@ -74,7 +74,7 @@ impl TokenBridge { self.address, FunctionSelector::from_signature("exit_to_l1_public((Field),Field,(Field),Field)"), [recipient.to_field(), amount, caller_on_l1.to_field(), nonce], - GasOpts::default() + GasOpts::empty() ); } } diff --git a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr index 9ff46f4b3ca..24969513a17 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr @@ -68,7 +68,7 @@ contract Uniswap { context.this_address(), FunctionSelector::from_signature("_approve_bridge_and_exit_input_asset_to_L1((Field),(Field),Field)"), [input_asset.to_field(), input_asset_bridge.to_field(), input_amount], - GasOpts::default() + GasOpts::empty() ); // Create swap message and send to Outbox for Uniswap Portal 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 e9e6ae5917d..d864614741d 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 @@ -6,10 +6,10 @@ struct ParityPublicInputs { converted_root: Field, } -impl Default for ParityPublicInputs { - fn default() -> Self { +impl Empty for ParityPublicInputs { + fn empty() -> Self { ParityPublicInputs { - aggregation_object: AggregationObject::default(), + aggregation_object: AggregationObject::empty(), sha_root: 0, converted_root: 0, } 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 563e7a109aa..ed7b8c61936 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 @@ -6,11 +6,11 @@ struct RootParityInput { public_inputs: ParityPublicInputs, } -impl Default for RootParityInput { - fn default() -> Self { +impl Empty for RootParityInput { + fn empty() -> Self { RootParityInput { - proof: Proof::default(), - public_inputs: ParityPublicInputs::default(), + proof: Proof::empty(), + public_inputs: ParityPublicInputs::empty(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr index 84259c1083a..b4fe21d91c3 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/common.nr @@ -21,7 +21,7 @@ use dep::types::{ }, merkle_tree::check_membership, utils::{arrays::{array_length, array_to_bounded_vec, validate_array}}, - traits::{is_default, is_default_array, is_zero} + traits::{is_empty, is_empty_array, is_zero} }; pub fn validate_arrays(app_public_inputs: PrivateCircuitPublicInputs) { @@ -120,10 +120,10 @@ fn perform_static_call_checks(private_call: PrivateCallData) { if is_static_call { // No state changes are allowed for static calls: assert( - is_default_array(public_inputs.new_note_hashes), "new_note_hashes must be empty (only default values) for static calls" + is_empty_array(public_inputs.new_note_hashes), "new_note_hashes must be empty (only empty values) for static calls" ); assert( - is_default_array(public_inputs.new_nullifiers), "new_nullifiers must be empty (only default values) for static calls" + is_empty_array(public_inputs.new_nullifiers), "new_nullifiers must be empty (only empty values) for static calls" ); // TODO: #5618 @@ -149,7 +149,7 @@ fn is_valid_caller(request_from_stack: CallRequest, fn_being_verified: PrivateCa & request_from_stack.caller_context.storage_contract_address.eq(call_context.storage_contract_address); request_from_stack.caller_contract_address.eq(fn_being_verified.call_stack_item.contract_address) - & (is_default(request_from_stack.caller_context) | valid_caller_context) + & (is_empty(request_from_stack.caller_context) | valid_caller_context) } fn validate_call_requests( @@ -204,7 +204,7 @@ pub fn update_end_values( let nullifier_read_requests = private_call_public_inputs.nullifier_read_requests; for i in 0..MAX_NULLIFIER_READ_REQUESTS_PER_CALL { let request = nullifier_read_requests[i]; - if !is_default(request) { + if !is_empty(request) { public_inputs.validation_requests.nullifier_read_requests.push(request.to_context(storage_contract_address)); } } @@ -213,7 +213,7 @@ pub fn update_end_values( let nullifier_key_validation_requests = private_call_public_inputs.nullifier_key_validation_requests; for i in 0..MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL { let request = nullifier_key_validation_requests[i]; - if !is_default(request) { + if !is_empty(request) { public_inputs.validation_requests.nullifier_key_validation_requests.push(request.to_context(storage_contract_address)); } } @@ -278,7 +278,7 @@ pub fn update_end_values( let mut new_l2_to_l1_msgs_to_insert : BoundedVec = BoundedVec::new(); for i in 0..MAX_NEW_L2_TO_L1_MSGS_PER_CALL { let msg = new_l2_to_l1_msgs[i]; - if !is_default(msg) { + if !is_empty(msg) { let new_l2_to_l1_msgs = compute_l2_to_l1_hash( storage_contract_address, private_call_public_inputs.version, @@ -359,7 +359,7 @@ pub fn validate_call_against_request(private_call: PrivateCallData, request: Cal if call_context.is_delegate_call { let caller_context = request.caller_context; - assert(!is_default(caller_context), "caller context cannot be default for delegate calls"); + assert(!is_empty(caller_context), "caller context cannot be empty for delegate calls"); assert( call_context.msg_sender.eq(caller_context.msg_sender), "call stack msg_sender does not match expected msg_sender for delegate calls" ); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr index 7d01fe01cfc..0110ae4d918 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr @@ -40,7 +40,7 @@ impl KernelCircuitPublicInputsComposer { sorted_nullifiers_indexes: [u64; MAX_NEW_NULLIFIERS_PER_TX], transient_note_hash_index_hints: [u64; MAX_NEW_NULLIFIERS_PER_TX] ) -> Self { - let public_inputs = PrivateKernelCircuitPublicInputsBuilder::default(); + let public_inputs = PrivateKernelCircuitPublicInputsBuilder::empty(); KernelCircuitPublicInputsComposer { public_inputs, @@ -164,8 +164,8 @@ impl KernelCircuitPublicInputsComposer { // Nullified_commitment of value `0` implies non-transient (persistable) // nullifier in which case no attempt will be made to match it to a hash. - // Non-default nullified_note_hash implies transient nullifier which MUST be matched to a hash below! - // 0-valued nullified_note_hash is default and will be ignored + // Non-empty nullified_note_hash implies transient nullifier which MUST be matched to a hash below! + // 0-valued nullified_note_hash is empty and will be ignored if nullified_note_hash != 0 { assert( hint_pos < MAX_NEW_NOTE_HASHES_PER_TX, "New nullifier is transient but hint is invalid" @@ -178,8 +178,8 @@ impl KernelCircuitPublicInputsComposer { // match found! // squash both the nullifier and the hash // (set to 0 here and then rearrange array after loop) - new_note_hashes[hint_pos] = SideEffect::default(); - new_nullifiers[n_idx] = SideEffectLinkedToNoteHash::default(); + new_note_hashes[hint_pos] = SideEffect::empty(); + new_nullifiers[n_idx] = SideEffectLinkedToNoteHash::empty(); } // non-transient (persistable) nullifiers are just kept in new_nullifiers array and forwarded // to public inputs (used later by base rollup circuit) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr index 6e69c8d4b33..09f7baa8569 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr @@ -76,7 +76,7 @@ impl PrivateKernelInitCircuitPrivateInputs { } pub fn native_private_kernel_circuit_initial(self) -> PrivateKernelCircuitPublicInputs { - let mut public_inputs = PrivateKernelCircuitPublicInputsBuilder::default(); + let mut public_inputs = PrivateKernelCircuitPublicInputsBuilder::empty(); self.initialize_end_values(&mut public_inputs); @@ -256,7 +256,7 @@ mod tests { builder.private_call.public_inputs.new_l2_to_l1_msgs.extend_from_array( [ - L2ToL1Message::default(), + L2ToL1Message::empty(), L2ToL1Message { recipient: EthAddress::from_field(6), content: 9123 } ] ); @@ -389,7 +389,7 @@ mod tests { } #[test] - fn default_max_block_number() { + fn empty_max_block_number() { let mut builder = PrivateKernelInitInputsBuilder::new(); let public_inputs = builder.execute(); 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 cf2cb07181b..0abd74d5ef1 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 @@ -27,7 +27,7 @@ impl PrivateKernelInnerCircuitPrivateInputs { } pub fn native_private_kernel_circuit_inner(self) -> PrivateKernelCircuitPublicInputs { - let mut public_inputs = PrivateKernelCircuitPublicInputsBuilder::default(); + let mut public_inputs = PrivateKernelCircuitPublicInputsBuilder::empty(); common::validate_previous_kernel_values(self.previous_kernel.public_inputs.end); @@ -218,13 +218,13 @@ mod tests { builder.succeeded(); } - #[test(should_fail_with="caller context cannot be default for delegate calls")] - fn default_caller_context_for_delegate_calls_fails() { + #[test(should_fail_with="caller context cannot be empty for delegate calls")] + fn empty_caller_context_for_delegate_calls_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_delegate_call(); let private_call = builder.private_call.finish(); let hash = private_call.call_stack_item.hash(); - // Caller context is default for regular calls. + // Caller context is empty for regular calls. let is_delegate_call = false; builder.previous_kernel.push_private_call_request(hash, is_delegate_call); let previous_kernel = builder.previous_kernel.to_private_kernel_data(); @@ -450,7 +450,7 @@ mod tests { builder.private_call.public_inputs.new_l2_to_l1_msgs.extend_from_array( [ - L2ToL1Message::default(), + L2ToL1Message::empty(), L2ToL1Message { recipient: EthAddress::from_field(6), content: 888 } ] ); @@ -691,7 +691,7 @@ mod tests { assert_eq(public_inputs.end.unencrypted_logs_hash, expected_unencrypted_logs_hash); } - #[test(should_fail_with="new_note_hashes must be a default array (empty) for static calls")] + #[test(should_fail_with="new_note_hashes must be a empty array (empty) for static calls")] fn creating_new_note_hashes_on_static_call_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_static_call(); @@ -700,7 +700,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_nullifiers must be a default array (empty) for static calls")] + #[test(should_fail_with="new_nullifiers must be a empty array (empty) for static calls")] fn creating_new_nullifiers_on_static_call_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new().is_static_call(); 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 4b24a876cd2..712e806a3d7 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 @@ -74,7 +74,7 @@ mod tests { grumpkin_private_key::GrumpkinPrivateKey, hash::{compute_note_hash_nonce, compute_unique_siloed_note_hash}, tests::{fixture_builder::FixtureBuilder, sort::sort_get_sorted_hints}, - utils::{arrays::{array_eq, array_length}}, traits::{is_default, is_default_array} + utils::{arrays::{array_eq, array_length}}, traits::{is_empty, is_empty_array} }; struct PrivateKernelTailInputsBuilder { @@ -164,7 +164,7 @@ mod tests { sorted_new_nullifiers_indexes, nullifier_read_request_hints: self.nullifier_read_request_hints_builder.to_hints(), nullifier_commitment_hints: sorted_nullifier_commitment_hints, - master_nullifier_secret_keys: [GrumpkinPrivateKey::default(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX] + master_nullifier_secret_keys: [GrumpkinPrivateKey::empty(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX] }; kernel.native_private_kernel_circuit_tail() } @@ -270,7 +270,7 @@ mod tests { builder.nullify_pending_note_hash(1, 0); let new_nullifiers = builder.previous_kernel.new_nullifiers.storage; let public_inputs = builder.execute(); - assert(is_default_array(public_inputs.end.new_note_hashes)); + assert(is_empty_array(public_inputs.end.new_note_hashes)); // The nullifier at index 1 is chopped. assert( @@ -321,7 +321,7 @@ mod tests { let public_inputs = builder.execute(); // Only the first nullifier is left after squashing. - assert(is_default_array(public_inputs.end.new_note_hashes)); + assert(is_empty_array(public_inputs.end.new_note_hashes)); assert(array_eq(public_inputs.end.new_nullifiers, [new_nullifiers[0].value])); } @@ -335,8 +335,8 @@ mod tests { let sorted_note_hashes = builder.previous_kernel.new_note_hashes.storage; let sorted_nullifiers = builder.previous_kernel.new_nullifiers.storage; - let mut reversed_note_hashes = [SideEffect::default(); 10]; - let mut reversed_nullifiers = [SideEffectLinkedToNoteHash::default(); 10]; + let mut reversed_note_hashes = [SideEffect::empty(); 10]; + let mut reversed_nullifiers = [SideEffectLinkedToNoteHash::empty(); 10]; for i in 0..10 { reversed_note_hashes[9 - i] = builder.previous_kernel.new_note_hashes.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 674592e50c3..48d4df980fd 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 @@ -73,7 +73,7 @@ mod tests { }, hash::{compute_note_hash_nonce, compute_unique_siloed_note_hash}, tests::{fixture_builder::FixtureBuilder, sort::sort_get_sorted_hints}, - utils::{arrays::{array_eq, array_length}}, traits::is_default_array, + utils::{arrays::{array_eq, array_length}}, traits::is_empty_array, grumpkin_private_key::GrumpkinPrivateKey }; @@ -105,7 +105,7 @@ mod tests { note_hashes: [SideEffect; N] ) -> [SideEffect; N] { let first_nullifier = self.previous_kernel.new_nullifiers.get_unchecked(0); - let mut unique_siloed_note_hashes = [SideEffect::default(); N]; + let mut unique_siloed_note_hashes = [SideEffect::empty(); N]; for i in 0..N { if note_hashes[i].value != 0 { let nonce = compute_note_hash_nonce(first_nullifier.value, i); @@ -171,7 +171,7 @@ mod tests { sorted_new_nullifiers_indexes, nullifier_read_request_hints: self.nullifier_read_request_hints_builder.to_hints(), nullifier_commitment_hints: sorted_nullifier_commitment_hints, - master_nullifier_secret_keys: [GrumpkinPrivateKey::default(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], + master_nullifier_secret_keys: [GrumpkinPrivateKey::empty(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], }; kernel.execute() } @@ -302,7 +302,7 @@ mod tests { builder.nullify_transient_note_hash(1, 0); let new_nullifiers = builder.previous_kernel.new_nullifiers.storage; let public_inputs = builder.execute(); - assert(is_default_array(public_inputs.end.new_note_hashes)); + assert(is_empty_array(public_inputs.end.new_note_hashes)); // The nullifier at index 1 is chopped. assert( @@ -353,7 +353,7 @@ mod tests { let public_inputs = builder.execute(); // Only the first nullifier is left after squashing. - assert(is_default_array(public_inputs.end.new_note_hashes)); + assert(is_empty_array(public_inputs.end.new_note_hashes)); assert(array_eq(public_inputs.end.new_nullifiers, [new_nullifiers[0]])); } @@ -367,8 +367,8 @@ mod tests { let sorted_note_hashes = builder.previous_kernel.new_note_hashes.storage; let sorted_nullifiers = builder.previous_kernel.new_nullifiers.storage; - let mut reversed_note_hashes = [SideEffect::default(); 10]; - let mut reversed_nullifiers = [SideEffectLinkedToNoteHash::default(); 10]; + let mut reversed_note_hashes = [SideEffect::empty(); 10]; + let mut reversed_nullifiers = [SideEffectLinkedToNoteHash::empty(); 10]; for i in 0..10 { reversed_note_hashes[9 - i] = builder.previous_kernel.new_note_hashes.pop(); @@ -508,9 +508,9 @@ mod tests { let public_inputs = builder.execute(); - assert(!is_default_array(public_inputs.end_non_revertible.new_nullifiers)); - assert(is_default_array(public_inputs.end_non_revertible.new_note_hashes)); - assert(is_default_array(public_inputs.end.new_note_hashes)); - assert(is_default_array(public_inputs.end.new_nullifiers)); + assert(!is_empty_array(public_inputs.end_non_revertible.new_nullifiers)); + assert(is_empty_array(public_inputs.end_non_revertible.new_note_hashes)); + assert(is_empty_array(public_inputs.end.new_note_hashes)); + assert(is_empty_array(public_inputs.end.new_nullifiers)); } } diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index 61b522acb96..68ab9d7646d 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -7,7 +7,7 @@ use dep::types::{ side_effect::{SideEffect, SideEffectLinkedToNoteHash} }, address::AztecAddress, - contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest, traits::{is_default as storage_op_is_default, array_length as storage_op_array_length}}, + contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest, traits::{is_empty as storage_op_is_empty, array_length as storage_op_array_length}}, constants::{ MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_NEW_NOTE_HASHES_PER_CALL, MAX_NEW_NULLIFIERS_PER_CALL, MAX_NULLIFIER_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, @@ -15,7 +15,7 @@ use dep::types::{ MAX_PUBLIC_DATA_READS_PER_CALL }, hash::{silo_note_hash, silo_nullifier, compute_l2_to_l1_hash, accumulate_sha256}, - utils::{arrays::{array_length, array_to_bounded_vec}}, traits::{is_default,is_zero} + utils::{arrays::{array_length, array_to_bounded_vec}}, traits::{is_empty,is_zero} }; use crate::hash::{compute_public_data_tree_index, compute_public_data_tree_value}; @@ -113,10 +113,10 @@ fn perform_static_call_checks(public_call: PublicCallData) { // TODO: #5618 // No state changes are allowed for static calls: let new_note_hashes_length = array_length(public_inputs.new_note_hashes); - assert(new_note_hashes_length == 0, "new_note_hashes must be a default array (empty) for static calls"); + assert(new_note_hashes_length == 0, "new_note_hashes must be a empty array (empty) for static calls"); let new_nullifiers_length = array_length(public_inputs.new_nullifiers); - assert(new_nullifiers_length == 0, "new_nullifiers must be a default array (empty) for static calls"); + assert(new_nullifiers_length == 0, "new_nullifiers must be a empty array (empty) for static calls"); let update_requests_length = storage_op_array_length(public_inputs.contract_storage_update_requests); assert( @@ -141,7 +141,7 @@ fn is_valid_caller(request: CallRequest, public_call: PublicCallData) -> bool { & request.caller_context.storage_contract_address.eq(call_context.storage_contract_address); request.caller_contract_address.eq(public_call.call_stack_item.contract_address) - & (is_default(request.caller_context) | valid_caller_context) + & (is_empty(request.caller_context) | valid_caller_context) } fn validate_call_requests( @@ -220,7 +220,7 @@ fn propagate_nullifier_read_requests( for i in 0..MAX_NULLIFIER_READ_REQUESTS_PER_CALL { let request = nullifier_read_requests[i]; - if !is_default(request) { + if !is_empty(request) { circuit_outputs.validation_requests.nullifier_read_requests.push(request.to_context(storage_contract_address)); } } @@ -236,7 +236,7 @@ fn propagate_nullifier_non_existent_read_requests( for i in 0..MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL { let request = nullifier_non_existent_read_requests[i]; - if !is_default(request) { + if !is_empty(request) { circuit_outputs.validation_requests.nullifier_non_existent_read_requests.push(request.to_context(storage_contract_address)); } } @@ -253,7 +253,7 @@ fn propagate_valid_public_data_update_requests( for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { let update_request = update_requests[i]; - if (!storage_op_is_default(update_request)) { + if (!storage_op_is_empty(update_request)) { let public_data_update_request = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value) @@ -276,7 +276,7 @@ fn propagate_valid_non_revertible_public_data_update_requests( for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { let update_request = update_requests[i]; - if (!storage_op_is_default(update_request)) { + if (!storage_op_is_empty(update_request)) { let public_data_update_request = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value) @@ -296,7 +296,7 @@ fn propagate_valid_public_data_reads(public_call: PublicCallData, circuit_output for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL { let read_request: StorageRead = read_requests[i]; - if !storage_op_is_default(read_request) { + if !storage_op_is_empty(read_request) { let public_data_read = PublicDataRead { leaf_slot: compute_public_data_tree_index(contract_address, read_request.storage_slot), value: compute_public_data_tree_value(read_request.current_value) @@ -408,7 +408,7 @@ fn propagate_new_l2_to_l1_messages(public_call: PublicCallData, public_inputs: & let mut new_l2_to_l1_msgs_to_insert : BoundedVec = BoundedVec::new(); for i in 0..MAX_NEW_L2_TO_L1_MSGS_PER_CALL { let msg = new_l2_to_l1_msgs[i]; - if !is_default(msg) { + if !is_empty(msg) { let new_l2_to_l1_msgs = compute_l2_to_l1_hash( storage_contract_address, public_inputs.constants.tx_context.version, @@ -468,7 +468,7 @@ pub fn validate_call_against_request(public_call: PublicCallData, request: CallR if call_context.is_delegate_call { let caller_context = request.caller_context; - assert(!is_default(caller_context), "caller context cannot be default for delegate calls"); + assert(!is_empty(caller_context), "caller context cannot be empty for delegate calls"); assert( call_context.msg_sender.eq(caller_context.msg_sender), "call stack msg_sender does not match expected msg_sender for delegate calls" ); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr index 79e2dbbc17c..8b786cbd6d6 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr @@ -22,7 +22,7 @@ impl PublicKernelAppLogicCircuitPrivateInputs { fn public_kernel_app_logic(self) -> PublicKernelCircuitPublicInputs { // construct the circuit outputs - let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::default(); + let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::empty(); common::initialize_revert_code(self.previous_kernel, self.public_call, &mut public_inputs); // initialise the end state with our provided previous kernel state @@ -341,7 +341,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_note_hashes must be a default array (empty) for static calls")] + #[test(should_fail_with="new_note_hashes must be a empty array (empty) for static calls")] fn public_kernel_fails_creating_new_note_hashes_on_static_call() { let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); builder.public_call.public_inputs.call_context.is_static_call = true; @@ -350,7 +350,7 @@ mod tests { builder.failed(); } - #[test(should_fail_with="new_nullifiers must be a default array (empty) for static calls")] + #[test(should_fail_with="new_nullifiers must be a empty array (empty) for static calls")] fn public_kernel_fails_creating_new_nullifiers_on_static_call() { let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new(); builder.public_call.public_inputs.call_context.is_static_call = true; diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr index 22424f9dd6b..3117e343379 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr @@ -27,7 +27,7 @@ impl PublicKernelSetupCircuitPrivateInputs { fn public_kernel_setup(self) -> PublicKernelCircuitPublicInputs { // construct the circuit outputs - let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::default(); + let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::empty(); // since this phase is non-revertible, we must assert the public call did not revert common::validate_public_call_non_revert(self.public_call); common::initialize_revert_code(self.previous_kernel, self.public_call, &mut public_inputs); @@ -209,7 +209,7 @@ mod tests { #[test(should_fail_with="Function signature cannot be zero")] fn function_selector_must_be_valid() { let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new(); - builder.public_call.function_data.selector = FunctionSelector::default(); + builder.public_call.function_data.selector = FunctionSelector::empty(); builder.failed(); } @@ -264,15 +264,15 @@ mod tests { builder.succeeded(); } - #[test(should_fail_with="caller context cannot be default for delegate calls")] - fn default_caller_context_for_delegate_calls_fails() { + #[test(should_fail_with="caller context cannot be empty for delegate calls")] + fn empty_caller_context_for_delegate_calls_fails() { let mut builder = PublicKernelSetupCircuitPrivateInputsBuilder::new().is_delegate_call(); builder.stub_teardown_call(); let public_call = builder.public_call.finish(); let hash = public_call.call_stack_item.hash(); - // Caller context is default for regular calls. + // Caller context is empty for regular calls. let is_delegate_call = false; builder.previous_kernel.push_public_call_request(hash, is_delegate_call); let previous_kernel = builder.previous_kernel.to_public_kernel_data(false); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr index 16cf635a265..bad81017f0d 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr @@ -10,7 +10,7 @@ use dep::types::{ }, constants::MAX_NEW_NULLIFIERS_PER_TX, utils::{arrays::{array_length, array_merge, array_to_bounded_vec, assert_sorted_array}}, - hash::silo_nullifier, traits::is_default + hash::silo_nullifier, traits::is_empty }; use dep::std::unsafe; @@ -73,7 +73,7 @@ impl PublicKernelTailCircuitPrivateInputs { let mut read_requests = self.previous_kernel.public_inputs.validation_requests.nullifier_non_existent_read_requests; for i in 0..read_requests.len() { let read_request = read_requests[i]; - if !is_default(read_request) { + if !is_empty(read_request) { read_requests[i].value = silo_nullifier(read_request.contract_address, read_request.value); } } @@ -101,7 +101,7 @@ impl PublicKernelTailCircuitPrivateInputs { } pub fn public_kernel_tail(self) -> KernelCircuitPublicInputs { - let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::default(); + let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::empty(); self.validate_inputs(); @@ -141,7 +141,7 @@ mod tests { }; fn build_nullifier_tree() -> NonEmptyMerkleTree { - let mut pre_existing_nullifiers = [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX]; + let mut pre_existing_nullifiers = [NullifierLeafPreimage::empty(); MAX_NEW_NULLIFIERS_PER_TX]; pre_existing_nullifiers[0] = NullifierLeafPreimage { nullifier: 0, next_nullifier: 100, next_index: 1 }; pre_existing_nullifiers[1] = NullifierLeafPreimage { nullifier: 100, next_nullifier: 0, next_index: 0 }; NonEmptyMerkleTree::new( diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr index 869cb86de1e..db6e7160d03 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr @@ -25,7 +25,7 @@ impl PublicKernelTeardownCircuitPrivateInputs { fn public_kernel_teardown(self) -> PublicKernelCircuitPublicInputs { // construct the circuit outputs - let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::default(); + let mut public_inputs = PublicKernelCircuitPublicInputsBuilder::empty(); // since this phase is non-revertible, we must assert the public call did not revert common::validate_public_call_non_revert(self.public_call); common::initialize_revert_code(self.previous_kernel, self.public_call, &mut public_inputs); @@ -158,7 +158,7 @@ mod tests { #[test(should_fail_with="Function signature cannot be zero")] fn function_selector_must_be_valid() { let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new(); - builder.public_call.function_data.selector = FunctionSelector::default(); + builder.public_call.function_data.selector = FunctionSelector::empty(); builder.failed(); } @@ -212,13 +212,13 @@ mod tests { builder.succeeded(); } - #[test(should_fail_with="caller context cannot be default for delegate calls")] - fn default_caller_context_for_delegate_calls_fails() { + #[test(should_fail_with="caller context cannot be empty for delegate calls")] + fn empty_caller_context_for_delegate_calls_fails() { let mut builder = PublicKernelTeardownCircuitPrivateInputsBuilder::new().is_delegate_call(); let public_call = builder.public_call.finish(); let hash = public_call.call_stack_item.hash(); - // Caller context is default for regular calls. + // Caller context is empty for regular calls. let is_delegate_call = false; builder.previous_kernel.push_public_call_request(hash, is_delegate_call); let previous_kernel = builder.previous_kernel.to_public_kernel_data(false); diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr index 47899c94296..e5828fc8e81 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/utils.nr @@ -5,7 +5,7 @@ use dep::types::{ public_data_update_request::PublicDataUpdateRequest }, address::AztecAddress, - contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest, traits::is_default}, + contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest, traits::is_empty}, utils::arrays::array_eq, }; @@ -13,10 +13,10 @@ pub fn compute_public_data_reads( contract_address: AztecAddress, read_requests: [StorageRead; N] ) -> [PublicDataRead; N] { - let mut public_data_reads = [PublicDataRead::default(); N]; + let mut public_data_reads = [PublicDataRead::empty(); N]; for i in 0..N { let read_request = read_requests[i]; - if !is_default(read_request) { + if !is_empty(read_request) { public_data_reads[i] = PublicDataRead { leaf_slot: compute_public_data_tree_index(contract_address, read_request.storage_slot), value: compute_public_data_tree_value(read_request.current_value), @@ -34,10 +34,10 @@ pub fn compute_public_data_update_requests( contract_address: AztecAddress, update_requests: [StorageUpdateRequest; N] ) -> [PublicDataUpdateRequest; N] { - let mut public_data_update_requests = [PublicDataUpdateRequest::default(); N]; + let mut public_data_update_requests = [PublicDataUpdateRequest::empty(); N]; for i in 0..N { let update_request = update_requests[i]; - if !is_default(update_request) { + if !is_empty(update_request) { public_data_update_requests[i] = PublicDataUpdateRequest { leaf_slot: compute_public_data_tree_index(contract_address, update_request.storage_slot), new_value: compute_public_data_tree_value(update_request.new_value), diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr index 05f18f364f6..aa3af1137c9 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/non_existent_read_request_reset.nr @@ -1,7 +1,7 @@ use dep::types::{ abis::{side_effect::OrderedValue, read_request::ReadRequestContext}, merkle_tree::{assert_check_non_membership, IndexedTreeLeafPreimage, MembershipWitness}, - traits::is_default + traits::is_empty }; trait NonMembershipHint where LEAF_PREIMAGE: IndexedTreeLeafPreimage { @@ -63,7 +63,7 @@ pub fn reset_non_existent_read_requests for Nullifier fn nada(read_request_len: u64) -> Self { NullifierSettledReadHint { read_request_index: read_request_len, - membership_witness: MembershipWitness::default(), - leaf_preimage: NullifierLeafPreimage::default() + membership_witness: MembershipWitness::empty(), + leaf_preimage: NullifierLeafPreimage::empty() } } } @@ -136,9 +136,9 @@ mod tests { let read_request_statuses = [ ReadRequestStatus { state: ReadRequestState.SETTLED, hint_index: 0 }, ReadRequestStatus { state: ReadRequestState.PENDING, hint_index: 0 }, - ReadRequestStatus::default(), + ReadRequestStatus::empty(), ReadRequestStatus { state: ReadRequestState.SETTLED, hint_index: 1 }, - ReadRequestStatus::default() + ReadRequestStatus::empty() ]; let (settled_read_hints, tree_root) = get_settled_read_hints(); let unverified_read_requests = reset_read_requests( diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr index b1745410087..9f60134dd45 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr @@ -6,7 +6,7 @@ use dep::types::{ MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX }, grumpkin_private_key::GrumpkinPrivateKey, keys::compute_siloed_nullifier_secret_key, - traits::is_default + traits::is_empty }; struct PrivateValidationRequestProcessor { @@ -60,7 +60,7 @@ impl PrivateValidationRequestProcessor { let requests = self.validation_requests.nullifier_key_validation_requests; for i in 0..MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX { let request = requests[i]; - if !is_default(request) { + if !is_empty(request) { let master_secret_key = self.master_nullifier_secret_keys[i]; let computed_public_key = master_secret_key.derive_public_key(); assert( diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr index ef2c8235b76..c0a2a30210e 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/read_request_reset.nr @@ -1,7 +1,7 @@ // This will be moved to a separate Read Request Reset Circuit. use dep::types::{ abis::{read_request::ReadRequestContext, side_effect::OrderedValue}, hash::silo_nullifier, - merkle_tree::{assert_check_membership, LeafPreimage, MembershipWitness}, traits::is_default + merkle_tree::{assert_check_membership, LeafPreimage, MembershipWitness}, traits::is_empty }; struct ReadRequestStateEnum { @@ -21,8 +21,8 @@ struct ReadRequestStatus { hint_index: u64, } -impl Default for ReadRequestStatus { - fn default() -> Self { +impl Empty for ReadRequestStatus { + fn empty() -> Self { ReadRequestStatus { state: ReadRequestState.NADA, hint_index: 0 } } } @@ -112,7 +112,7 @@ fn propagate_unverified_read_requests Self { + impl Empty for TestLeafPreimage { + fn empty() -> Self { TestLeafPreimage { value: 0 } @@ -212,8 +212,8 @@ mod tests { fn nada(read_request_len: u64) -> Self { TestSettledReadHint { read_request_index: read_request_len, - membership_witness: MembershipWitness::default(), - leaf_preimage: TestLeafPreimage::default() + membership_witness: MembershipWitness::empty(), + leaf_preimage: TestLeafPreimage::empty() } } } @@ -335,9 +335,9 @@ mod tests { #[test] fn test_propagate_unverified_read_requests() { let read_request_statuses = [ - ReadRequestStatus::default(), + ReadRequestStatus::empty(), ReadRequestStatus { state: ReadRequestState.PENDING, hint_index: 0 }, - ReadRequestStatus::default(), + ReadRequestStatus::empty(), ReadRequestStatus { state: ReadRequestState.SETTLED, hint_index: 0 } ]; let pending_read_hints = [pending_read_hints[0]]; diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_non_existent_read_request_hints_builder.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_non_existent_read_request_hints_builder.nr index bde26ba7e86..a28dca86d28 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_non_existent_read_request_hints_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/tests/nullifier_non_existent_read_request_hints_builder.nr @@ -21,10 +21,10 @@ struct NullifierNonExistentReadRequestHintsBuilder { impl NullifierNonExistentReadRequestHintsBuilder { pub fn new() -> Self { NullifierNonExistentReadRequestHintsBuilder { - nullifier_tree: NonEmptyMerkleTree::default(), + nullifier_tree: NonEmptyMerkleTree::empty(), non_membership_hints: BoundedVec::new(), read_values: BoundedVec::new(), - pending_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_TX] + pending_nullifiers: [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_TX] } } 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 3a6170a97b4..355106e7978 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 @@ -13,7 +13,7 @@ struct NullifierReadRequestHintsBuilder { impl NullifierReadRequestHintsBuilder { pub fn new(read_request_len: u64) -> Self { NullifierReadRequestHintsBuilder { - read_request_statuses: [ReadRequestStatus::default(); MAX_NULLIFIER_READ_REQUESTS_PER_TX], + read_request_statuses: [ReadRequestStatus::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX], pending_read_hints: BoundedVec { storage: [PendingReadHint::nada(read_request_len); MAX_NULLIFIER_READ_REQUESTS_PER_TX], len: 0 }, settled_read_hints: BoundedVec { storage: [NullifierSettledReadHint::nada(read_request_len); MAX_NULLIFIER_READ_REQUESTS_PER_TX], 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 b9c50ce08d0..3b34f2b2d38 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 @@ -30,15 +30,15 @@ struct BaseOrMergeRollupPublicInputs { out_hash : Field, } -impl Default for BaseOrMergeRollupPublicInputs { - fn default() -> Self { +impl Empty for BaseOrMergeRollupPublicInputs { + fn empty() -> Self { BaseOrMergeRollupPublicInputs { rollup_type : 0 as u32, height_in_block_tree : 0, - aggregation_object : AggregationObject::default(), - constants : ConstantRollupData::default(), - start: PartialStateReference::default(), - end: PartialStateReference::default(), + aggregation_object : AggregationObject::empty(), + constants : ConstantRollupData::empty(), + start: PartialStateReference::empty(), + end: PartialStateReference::empty(), txs_effects_hash : 0, out_hash : 0, } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr index 3393ec50941..ba9d9c464ab 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr @@ -26,15 +26,15 @@ impl Eq for ConstantRollupData { } } -impl Default for ConstantRollupData { - fn default() -> Self { +impl Empty for ConstantRollupData { + fn empty() -> Self { ConstantRollupData { - last_archive: AppendOnlyTreeSnapshot::default(), + last_archive: AppendOnlyTreeSnapshot::empty(), private_kernel_vk_tree_root: 0, public_kernel_vk_tree_root: 0, base_rollup_vk_hash: 0, merge_rollup_vk_hash: 0, - global_variables: GlobalVariables::default(), + global_variables: GlobalVariables::empty(), } } } 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 4afe9a85f0d..66ec9ac45c0 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 @@ -11,14 +11,14 @@ struct PreviousRollupData{ vk_sibling_path : VKMembershipWitness, } -impl Default for PreviousRollupData { - fn default() -> Self { +impl Empty for PreviousRollupData { + fn empty() -> Self { PreviousRollupData { - base_or_merge_rollup_public_inputs: BaseOrMergeRollupPublicInputs::default(), - proof : Proof::default(), - vk : VerificationKey::default(), + base_or_merge_rollup_public_inputs: BaseOrMergeRollupPublicInputs::empty(), + proof : Proof::empty(), + vk : VerificationKey::empty(), vk_index : 0 as u32, - vk_sibling_path : VKMembershipWitness::default(), + vk_sibling_path : VKMembershipWitness::empty(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr index 458a7810694..2f9b9cf73f8 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -31,7 +31,7 @@ use dep::types::{ public_data_tree_leaf::PublicDataTreeLeaf, public_data_tree_leaf_preimage::PublicDataTreeLeafPreimage, utils::{field::{full_field_less_than, full_field_greater_than}, uint256::U256}, - traits::is_default, + traits::is_empty, }; struct BaseRollupInputs { @@ -150,7 +150,7 @@ impl BaseRollupInputs { let is_less_than_nullifier = full_field_less_than(low_leaf.nullifier, nullifier); let is_next_greater_than = full_field_less_than(nullifier, low_leaf.next_nullifier); - (!is_default(low_leaf)) & is_less_than_nullifier & ( + (!is_empty(low_leaf)) & is_less_than_nullifier & ( is_next_greater_than | ((low_leaf.next_index == 0) & (low_leaf.next_nullifier == 0)) ) @@ -273,7 +273,7 @@ fn insert_public_data_update_requests( ), |low_preimage: PublicDataTreeLeafPreimage, write: PublicDataTreeLeaf| { // Is valid low preimage let is_update = low_preimage.slot == write.slot; - let is_low_empty = is_default(low_preimage); + let is_low_empty = is_empty(low_preimage); let is_less_than_slot = full_field_less_than(low_preimage.slot, write.slot); let is_next_greater_than = full_field_less_than(write.slot, low_preimage.next_slot); @@ -304,7 +304,7 @@ fn insert_public_data_update_requests( |write: PublicDataTreeLeaf, low_preimage: PublicDataTreeLeafPreimage| { // Build insertion leaf let is_update = low_preimage.slot == write.slot; if is_update { - PublicDataTreeLeafPreimage::default() + PublicDataTreeLeafPreimage::empty() }else { PublicDataTreeLeafPreimage { slot: write.slot, @@ -330,7 +330,7 @@ fn validate_public_data_reads( let low_preimage = public_data_reads_preimages[i]; let witness = public_data_reads_witnesses[i]; - let is_low_empty = is_default(low_preimage); + let is_low_empty = is_empty(low_preimage); let is_exact = low_preimage.slot == read.leaf_slot; let is_less_than_slot = full_field_less_than(low_preimage.slot, read.leaf_slot); @@ -338,7 +338,7 @@ fn validate_public_data_reads( let is_in_range = is_less_than_slot & (is_next_greater_than | ((low_preimage.next_index == 0) & (low_preimage.next_slot == 0))); - if (!is_default(read)) { + if (!is_empty(read)) { assert(!is_low_empty, "public data read is not empty but low preimage is empty"); if is_in_range { assert_eq(read.value, 0, "low leaf for public data read is in range but value is not zero"); @@ -415,7 +415,7 @@ mod tests { sort::sort_high_to_low }, utils::{field::{full_field_less_than, field_from_bytes_32_trunc, field_from_bytes}, uint256::U256}, - traits::is_default, + traits::is_empty, }; struct NullifierInsertion { @@ -435,11 +435,11 @@ mod tests { mut pre_existing_public_data: [PublicDataTreeLeafPreimage; EXISTING_LEAVES] ) -> ([Field; 35], [PublicDataTreeLeaf; 32], [u64; 32], [PublicDataTreeLeafPreimage; 32], [PublicDataMembershipWitness; 32], [PublicDataTreeLeafPreimage; EXISTING_LEAVES]) { let mut subtree_path = [0; PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH]; - let mut sorted_public_data_writes = [PublicDataTreeLeaf::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; + let mut sorted_public_data_writes = [PublicDataTreeLeaf::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; let mut sorted_public_data_writes_indexes = [0 as u64; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; - let mut low_public_data_writes_preimages = [PublicDataTreeLeafPreimage::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; - let mut low_public_data_writes_witnesses = [PublicDataMembershipWitness::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; - let mut new_subtree = [PublicDataTreeLeafPreimage::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; + let mut low_public_data_writes_preimages = [PublicDataTreeLeafPreimage::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; + let mut low_public_data_writes_witnesses = [PublicDataMembershipWitness::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; + let mut new_subtree = [PublicDataTreeLeafPreimage::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]; for i in 0..MAX_PUBLIC_DATA_WRITES_PER_TEST { if i < (public_data_writes.len()) { @@ -463,7 +463,7 @@ mod tests { sorted_public_data_writes[i] = leaf; sorted_public_data_writes_indexes[i] = sorted_write_tuples[i].original_index; - if !is_default(leaf) { + if !is_empty(leaf) { let low_leaf = pre_existing_public_data[low_leaf_index]; if low_leaf.slot == leaf.slot { pre_existing_public_data[low_leaf_index].value = leaf.value; @@ -493,7 +493,7 @@ mod tests { ); } } else { - sorted_public_data_writes[i] = PublicDataTreeLeaf::default(); + sorted_public_data_writes[i] = PublicDataTreeLeaf::empty(); sorted_public_data_writes_indexes[i] = i; } } @@ -518,19 +518,19 @@ mod tests { constants: ConstantRollupData, } - impl Default for BaseRollupInputsBuilder { - fn default() -> Self { + impl Empty for BaseRollupInputsBuilder { + fn empty() -> Self { BaseRollupInputsBuilder { kernel_data: FixtureBuilder::new(), pre_existing_notes: [0; MAX_NEW_NOTE_HASHES_PER_TX], - pre_existing_nullifiers: [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX], + pre_existing_nullifiers: [NullifierLeafPreimage::empty(); MAX_NEW_NULLIFIERS_PER_TX], pre_existing_contracts: [0; 2], - pre_existing_public_data: [PublicDataTreeLeafPreimage::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], + pre_existing_public_data: [PublicDataTreeLeafPreimage::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], pre_existing_blocks: [0; 2], public_data_reads: BoundedVec::new(), public_data_writes:BoundedVec::new(), new_nullifiers: BoundedVec::new(), - constants: ConstantRollupData::default(), + constants: ConstantRollupData::empty(), } } } @@ -541,7 +541,7 @@ mod tests { impl BaseRollupInputsBuilder { fn new() -> Self { - let mut inputs = BaseRollupInputsBuilder::default(); + let mut inputs = BaseRollupInputsBuilder::empty(); inputs.kernel_data = FixtureBuilder::new(); inputs.constants.global_variables.chain_id = 1; inputs.constants.global_variables.version = 0; @@ -568,8 +568,8 @@ mod tests { kernel_data: &mut KernelData, start_nullifier_tree_snapshot: AppendOnlyTreeSnapshot ) -> ([NullifierLeafPreimage; MAX_NEW_NULLIFIERS_PER_TX], [NullifierMembershipWitness; MAX_NEW_NULLIFIERS_PER_TX], [Field; MAX_NEW_NULLIFIERS_PER_TX], [u64; MAX_NEW_NULLIFIERS_PER_TX]) { - let mut nullifier_predecessor_preimages = [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX]; - let mut low_nullifier_membership_witness = [NullifierMembershipWitness::default(); MAX_NEW_NULLIFIERS_PER_TX]; + let mut nullifier_predecessor_preimages = [NullifierLeafPreimage::empty(); MAX_NEW_NULLIFIERS_PER_TX]; + let mut low_nullifier_membership_witness = [NullifierMembershipWitness::empty(); MAX_NEW_NULLIFIERS_PER_TX]; let sorted_new_nullifier_tuples = sort_high_to_low( self.new_nullifiers.storage.map(|insertion: NullifierInsertion| insertion.value), @@ -823,7 +823,7 @@ mod tests { }; builder.new_nullifiers.push(NullifierInsertion { existing_index: 0, value: 1 }); - let mut tree_nullifiers = [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX * 2]; + let mut tree_nullifiers = [NullifierLeafPreimage::empty(); MAX_NEW_NULLIFIERS_PER_TX * 2]; tree_nullifiers[0] = NullifierLeafPreimage { nullifier : 0, next_nullifier : 1, @@ -873,7 +873,7 @@ mod tests { } let output = builder.execute(); - let mut tree_nullifiers = [NullifierLeafPreimage::default(); MAX_NEW_NULLIFIERS_PER_TX * 2]; + let mut tree_nullifiers = [NullifierLeafPreimage::empty(); MAX_NEW_NULLIFIERS_PER_TX * 2]; tree_nullifiers[0] = builder.pre_existing_nullifiers[0]; tree_nullifiers[1] = NullifierLeafPreimage { @@ -974,7 +974,7 @@ mod tests { #[test] unconstrained fn nonempty_block_out_hash() { - let mut end = CombinedAccumulatedData::default(); + let mut end = CombinedAccumulatedData::empty(); end.new_l2_to_l1_msgs[MAX_NEW_L2_TO_L1_MSGS_PER_TX - 1] = 123; let out_hash = compute_kernel_out_hash(end); 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 32bc591c743..84dac4a6b2c 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 @@ -7,10 +7,10 @@ struct MergeRollupInputs{ previous_rollup_data : [PreviousRollupData; 2] } -impl Default for MergeRollupInputs { - fn default() -> Self { +impl Empty for MergeRollupInputs { + fn empty() -> Self { MergeRollupInputs { - previous_rollup_data: [PreviousRollupData::default(); 2] + previous_rollup_data: [PreviousRollupData::empty(); 2] } } } @@ -54,13 +54,13 @@ impl MergeRollupInputs { mod tests { use crate::{ merge::merge_rollup_inputs::MergeRollupInputs, - tests::merge_rollup_inputs::default_merge_rollup_inputs + tests::merge_rollup_inputs::empty_merge_rollup_inputs }; use dep::types::hash::accumulate_sha256; #[test(should_fail_with="input proofs are of different rollup types")] fn different_rollup_type_fails() { - let mut inputs = default_merge_rollup_inputs(); + let mut inputs = empty_merge_rollup_inputs(); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_type = 0; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_type = 1; let _output = inputs.merge_rollup_circuit(); @@ -68,7 +68,7 @@ mod tests { #[test(should_fail_with="input proofs are of different rollup heights")] fn different_height_fails() { - let mut inputs = default_merge_rollup_inputs(); + let mut inputs = empty_merge_rollup_inputs(); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.height_in_block_tree = 0; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.height_in_block_tree = 1; let _output = inputs.merge_rollup_circuit(); @@ -76,7 +76,7 @@ mod tests { #[test(should_fail_with="input proofs have different constants")] fn constants_different_fails() { - let mut inputs = default_merge_rollup_inputs(); + let mut inputs = empty_merge_rollup_inputs(); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = 1; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = 0; let _output = inputs.merge_rollup_circuit(); @@ -84,7 +84,7 @@ mod tests { #[test(should_fail_with="input proofs have different constants")] fn constants_different_chain_id_fails() { - let mut inputs = default_merge_rollup_inputs(); + let mut inputs = empty_merge_rollup_inputs(); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants.global_variables.chain_id = 1; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants.global_variables.chain_id = 0; let _output = inputs.merge_rollup_circuit(); @@ -92,7 +92,7 @@ mod tests { #[test(should_fail_with="input proofs have different note hash tree snapshots")] fn previous_rollups_dont_follow_note_hash() { - let mut inputs = default_merge_rollup_inputs(); + let mut inputs = empty_merge_rollup_inputs(); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end.note_hash_tree.root = 0; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start.note_hash_tree.root = 1; let _output = inputs.merge_rollup_circuit(); @@ -100,7 +100,7 @@ mod tests { #[test(should_fail_with="input proofs have different nullifier tree snapshots")] fn previous_rollups_dont_follow_nullifier() { - let mut inputs = default_merge_rollup_inputs(); + let mut inputs = empty_merge_rollup_inputs(); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end.nullifier_tree.root = 0; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start.nullifier_tree.root = 1; let _output = inputs.merge_rollup_circuit(); @@ -108,7 +108,7 @@ mod tests { #[test] fn rollup_fields_are_set_correctly() { - let mut inputs = default_merge_rollup_inputs(); + let mut inputs = empty_merge_rollup_inputs(); let mut outputs = inputs.merge_rollup_circuit(); assert_eq(outputs.rollup_type, 1); assert_eq( @@ -129,7 +129,7 @@ mod tests { #[test] fn start_and_end_partial_states() { - let mut inputs = default_merge_rollup_inputs(); + let mut inputs = empty_merge_rollup_inputs(); let outputs = inputs.merge_rollup_circuit(); assert(outputs.start.eq(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start)); @@ -138,7 +138,7 @@ mod tests { #[test] fn txs_effects_hash() { - let mut inputs = default_merge_rollup_inputs(); + let mut inputs = empty_merge_rollup_inputs(); let expected_hash = accumulate_sha256([1, 2]); let outputs = inputs.merge_rollup_circuit(); @@ -147,7 +147,7 @@ mod tests { #[test] fn constants_dont_change() { - let mut inputs = default_merge_rollup_inputs(); + let mut inputs = empty_merge_rollup_inputs(); let outputs = inputs.merge_rollup_circuit(); assert( diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root.nr index 402760ef95a..ece1ed4c063 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root.nr @@ -53,7 +53,7 @@ fn test_message_input_flattened_length() { mod tests { use crate::{ root::{root_rollup_inputs::RootRollupInputs, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP_NUM_BYTES}, - tests::root_rollup_inputs::default_root_rollup_inputs + tests::root_rollup_inputs::empty_root_rollup_inputs }; use dep::types::utils::{uint256::U256, field::field_from_bytes_32_trunc}; use dep::types::hash::accumulate_sha256; @@ -62,7 +62,7 @@ mod tests { fn check_block_hashes_empty_blocks() { let expected_txs_effects_hash = accumulate_sha256([1, 2]); - let inputs = default_root_rollup_inputs(); + let inputs = empty_root_rollup_inputs(); let outputs = inputs.root_rollup_circuit(); // check txs effects hash @@ -71,7 +71,7 @@ mod tests { #[test] fn end_state() { - let inputs = default_root_rollup_inputs(); + let inputs = empty_root_rollup_inputs(); let outputs = inputs.root_rollup_circuit(); assert( 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 1e9b3dc1b5f..5fff16f4d27 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 @@ -33,15 +33,15 @@ struct RootRollupInputs { new_archive_sibling_path : [Field; ARCHIVE_HEIGHT], } -impl Default for RootRollupInputs { - fn default() -> Self { +impl Empty for RootRollupInputs { + fn empty() -> Self { RootRollupInputs { - previous_rollup_data : [PreviousRollupData::default(); 2], - l1_to_l2_roots: RootParityInput::default(), + previous_rollup_data : [PreviousRollupData::empty(); 2], + l1_to_l2_roots: RootParityInput::empty(), new_l1_to_l2_messages : [0; NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP], new_l1_to_l2_message_tree_root_sibling_path : [0; L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH], - start_l1_to_l2_message_tree_snapshot : AppendOnlyTreeSnapshot::default(), - start_archive_snapshot : AppendOnlyTreeSnapshot::default(), + start_l1_to_l2_message_tree_snapshot : AppendOnlyTreeSnapshot::empty(), + start_archive_snapshot : AppendOnlyTreeSnapshot::empty(), new_archive_sibling_path : [0; ARCHIVE_HEIGHT], } } 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 be11951252f..7d0ffd769f8 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,12 +1,12 @@ use crate::merge::merge_rollup_inputs::MergeRollupInputs; use crate::abis::base_or_merge_rollup_public_inputs::BASE_ROLLUP_TYPE; use dep::types::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot; -use crate::tests::previous_rollup_data::default_previous_rollup_data; +use crate::tests::previous_rollup_data::empty_previous_rollup_data; -pub fn default_merge_rollup_inputs() -> MergeRollupInputs { - let mut inputs = MergeRollupInputs::default(); +pub fn empty_merge_rollup_inputs() -> MergeRollupInputs { + let mut inputs = MergeRollupInputs::empty(); - inputs.previous_rollup_data = default_previous_rollup_data(); + inputs.previous_rollup_data = empty_previous_rollup_data(); inputs } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/previous_rollup_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/previous_rollup_data.nr index 2f8334e502d..57ee2f5bc5b 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/previous_rollup_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/previous_rollup_data.nr @@ -2,8 +2,8 @@ use crate::abis::base_or_merge_rollup_public_inputs::BASE_ROLLUP_TYPE; use crate::abis::previous_rollup_data::PreviousRollupData; use dep::types::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot; -pub fn default_previous_rollup_data() -> [PreviousRollupData; 2] { - let mut previous_rollup_data =[PreviousRollupData::default(); 2]; +pub fn empty_previous_rollup_data() -> [PreviousRollupData; 2] { + let mut previous_rollup_data =[PreviousRollupData::empty(); 2]; previous_rollup_data[0].base_or_merge_rollup_public_inputs.start.note_hash_tree = AppendOnlyTreeSnapshot { root: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/root_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/root_rollup_inputs.nr index ef833f83883..34db6c0d17f 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/root_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/root_rollup_inputs.nr @@ -7,7 +7,7 @@ use dep::types::{ }, tests::merkle_tree_utils::compute_zero_hashes }; -use crate::tests::previous_rollup_data::default_previous_rollup_data; +use crate::tests::previous_rollup_data::empty_previous_rollup_data; pub fn compute_l1_l2_empty_snapshot() -> (AppendOnlyTreeSnapshot, [Field; L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH]) { let zero_hashes = compute_zero_hashes([0; L1_TO_L2_MSG_TREE_HEIGHT]); @@ -34,8 +34,8 @@ pub fn compute_archive_snapshot() -> (AppendOnlyTreeSnapshot, [Field; ARCHIVE_HE ) } -pub fn default_root_rollup_inputs() -> RootRollupInputs { - let mut inputs = RootRollupInputs::default(); +pub fn empty_root_rollup_inputs() -> RootRollupInputs { + let mut inputs = RootRollupInputs::empty(); let (l1_l2_empty_snapshot, l1_l2_empty_sibling_path) = compute_l1_l2_empty_snapshot(); inputs.new_l1_to_l2_message_tree_root_sibling_path = l1_l2_empty_sibling_path; @@ -46,7 +46,7 @@ pub fn default_root_rollup_inputs() -> RootRollupInputs { inputs.start_archive_snapshot = blocks_snapshot; inputs.new_archive_sibling_path = blocks_sibling_path; - inputs.previous_rollup_data = default_previous_rollup_data(); + inputs.previous_rollup_data = empty_previous_rollup_data(); inputs } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr index 708390e78c8..a78ee8b151b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr @@ -27,8 +27,8 @@ struct CombinedAccumulatedData { public_data_update_requests: [PublicDataUpdateRequest; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], } -impl Default for CombinedAccumulatedData { - fn default() -> Self { +impl Empty for CombinedAccumulatedData { + fn empty() -> Self { CombinedAccumulatedData { new_note_hashes: [0; MAX_NEW_NOTE_HASHES_PER_TX], new_nullifiers: [0; MAX_NEW_NULLIFIERS_PER_TX], @@ -37,7 +37,7 @@ impl Default for CombinedAccumulatedData { unencrypted_logs_hash: 0, encrypted_log_preimages_length: 0, unencrypted_log_preimages_length: 0, - public_data_update_requests: [PublicDataUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], + public_data_update_requests: [PublicDataUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr index d810a3cb676..ecb2bc105f6 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr @@ -33,8 +33,8 @@ struct PrivateAccumulatedDataBuilder { public_call_stack: BoundedVec, } -impl Default for PrivateAccumulatedDataBuilder { - fn default() -> Self { +impl Empty for PrivateAccumulatedDataBuilder { + fn empty() -> Self { PrivateAccumulatedDataBuilder { new_note_hashes: BoundedVec::new(), new_nullifiers: BoundedVec::new(), @@ -73,7 +73,7 @@ impl PrivateAccumulatedDataBuilder { unencrypted_logs_hash: self.unencrypted_logs_hash, encrypted_log_preimages_length: self.encrypted_log_preimages_length, unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, - public_data_update_requests: [PublicDataUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], + public_data_update_requests: [PublicDataUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], } } @@ -81,8 +81,8 @@ impl PrivateAccumulatedDataBuilder { self, min_revertible_side_effect_counter: u32 ) -> (PublicAccumulatedData, PublicAccumulatedData) { - let mut non_revertible_builder = PublicAccumulatedDataBuilder::default(); - let mut revertible_builder = PublicAccumulatedDataBuilder::default(); + let mut non_revertible_builder = PublicAccumulatedDataBuilder::empty(); + let mut revertible_builder = PublicAccumulatedDataBuilder::empty(); for i in 0..MAX_NEW_NOTE_HASHES_PER_TX { let note_hash = self.new_note_hashes.storage[i]; @@ -134,7 +134,7 @@ mod tests { #[test] unconstrained fn splits_revertible_and_non_revertible() { - let mut builder = PrivateAccumulatedDataBuilder::default(); + let mut builder = PrivateAccumulatedDataBuilder::empty(); let non_revertible_commitments = [ SideEffect { value: 1, counter: 1 }, @@ -150,14 +150,14 @@ mod tests { CallRequest { hash: 1, caller_contract_address: AztecAddress::from_field(1), - caller_context: CallerContext::default(), + caller_context: CallerContext::empty(), start_side_effect_counter: 5, end_side_effect_counter: 0 }, CallRequest { hash: 2, caller_contract_address: AztecAddress::from_field(1), - caller_context: CallerContext::default(), + caller_context: CallerContext::empty(), start_side_effect_counter: 6, end_side_effect_counter: 0 } @@ -177,7 +177,7 @@ mod tests { CallRequest { hash: 3, caller_contract_address: AztecAddress::from_field(3), - caller_context: CallerContext::default(), + caller_context: CallerContext::empty(), start_side_effect_counter: 9, end_side_effect_counter: 0 } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr index 2e77526c725..f4a376ee9e9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr @@ -27,18 +27,18 @@ struct PublicAccumulatedData { public_call_stack: [CallRequest; MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], } -impl Default for PublicAccumulatedData { - fn default() -> Self { +impl Empty for PublicAccumulatedData { + fn empty() -> Self { PublicAccumulatedData { - new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_TX], - new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_TX], + new_note_hashes: [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_TX], + new_nullifiers: [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_TX], new_l2_to_l1_msgs: [0; MAX_NEW_L2_TO_L1_MSGS_PER_TX], encrypted_logs_hash: 0, unencrypted_logs_hash: 0, encrypted_log_preimages_length: 0, unencrypted_log_preimages_length: 0, - public_data_update_requests: [PublicDataUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], - public_call_stack: [CallRequest::default(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], + public_data_update_requests: [PublicDataUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], + public_call_stack: [CallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr index 141e2a324b0..b004132d0ea 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr @@ -28,8 +28,8 @@ struct PublicAccumulatedDataBuilder { public_call_stack: BoundedVec, } -impl Default for PublicAccumulatedDataBuilder { - fn default() -> Self { +impl Empty for PublicAccumulatedDataBuilder { + fn empty() -> Self { PublicAccumulatedDataBuilder { new_note_hashes: BoundedVec::new(), new_nullifiers: BoundedVec::new(), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr index e41a73b9c4a..88f20676d7e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr @@ -1,4 +1,4 @@ -use dep::std::{cmp::Eq,default::Default}; +use dep::std::{cmp::Eq,empty::Empty}; struct AppendOnlyTreeSnapshot { root : Field, @@ -18,8 +18,8 @@ impl AppendOnlyTreeSnapshot { } } -impl Default for AppendOnlyTreeSnapshot { - fn default() -> Self { +impl Empty for AppendOnlyTreeSnapshot { + fn empty() -> Self { Self { root: 0, next_available_leaf_index: 0 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr index f809fc6c3e0..5f68dcb9976 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr @@ -1,9 +1,9 @@ use crate::{ abis::function_selector::FunctionSelector, address::{EthAddress, AztecAddress}, constants::{CALL_CONTEXT_LENGTH, GENERATOR_INDEX__CALL_CONTEXT}, hash::pedersen_hash, - traits::{Deserialize, Hash, Serialize, is_default}, abis::side_effect::Ordered + traits::{Deserialize, Hash, Serialize, is_empty}, abis::side_effect::Ordered }; -use dep::std::default::Default; +use dep::std::empty::Empty; // docs:start:call-context struct CallContext { @@ -20,13 +20,13 @@ struct CallContext { } // docs:end:call-context -impl Default for CallContext { - fn default() -> Self { +impl Empty for CallContext { + fn empty() -> Self { CallContext { - msg_sender: AztecAddress::default(), - storage_contract_address: AztecAddress::default(), - portal_contract_address: EthAddress::default(), - function_selector: FunctionSelector::default(), + msg_sender: AztecAddress::empty(), + storage_contract_address: AztecAddress::empty(), + portal_contract_address: EthAddress::empty(), + function_selector: FunctionSelector::empty(), is_delegate_call: false, is_static_call: false, side_effect_counter: 0, @@ -75,30 +75,30 @@ impl Deserialize for CallContext { } #[test] -fn serialize_deserialize_of_default() { - let context = CallContext::default(); +fn serialize_deserialize_of_empty() { + let context = CallContext::empty(); let serialized = context.serialize(); let deserialized = CallContext::deserialize(serialized); assert(context.eq(deserialized)); } #[test] -fn test_is_default() { - let context = CallContext::default(); - assert(is_default(context), true); +fn test_is_empty() { + let context = CallContext::empty(); + assert(is_empty(context), true); } #[test(should_fail)] -fn test_not_default() { - let mut context = CallContext::default(); +fn test_not_empty() { + let mut context = CallContext::empty(); context.is_delegate_call = true; - assert(is_default(context), true); + assert(is_empty(context), true); } #[test] fn test_eq() { - let mut context1 = CallContext::default(); - let mut context2 = CallContext::default(); + let mut context1 = CallContext::empty(); + let mut context2 = CallContext::empty(); context1.is_delegate_call = true; context2.is_delegate_call = true; @@ -112,8 +112,8 @@ fn test_eq() { #[test(should_fail)] fn not_eq_test_eq() { - let mut context1 = CallContext::default(); - let mut context2 = CallContext::default(); + let mut context1 = CallContext::empty(); + let mut context2 = CallContext::empty(); context1.is_delegate_call = true; context2.is_delegate_call = false; @@ -129,6 +129,6 @@ fn not_eq_test_eq() { #[test] fn hash_smoke() { - let context = CallContext::default(); + let context = CallContext::empty(); let _hashed = context.hash(); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr index 1f0e1494438..cfc59ebc7c3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr @@ -1,5 +1,5 @@ use crate::address::AztecAddress; -use dep::std::{cmp::Eq,default::Default}; +use dep::std::{cmp::Eq,empty::Empty}; use crate::abis::caller_context::CallerContext; struct CallRequest { @@ -20,12 +20,12 @@ impl Eq for CallRequest { } } -impl Default for CallRequest { - fn default() -> Self { +impl Empty for CallRequest { + fn empty() -> Self { CallRequest { hash: 0, caller_contract_address: AztecAddress::zero(), - caller_context: CallerContext::default(), + caller_context: CallerContext::empty(), start_side_effect_counter: 0, end_side_effect_counter: 0, } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr index f6d2a89449d..b5a320073d1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr @@ -1,5 +1,5 @@ use crate::address::AztecAddress; -use dep::std::{cmp::Eq,default::Default}; +use dep::std::{cmp::Eq,empty::Empty}; struct CallerContext { msg_sender: AztecAddress, @@ -13,8 +13,8 @@ impl Eq for CallerContext { } } -impl Default for CallerContext { - fn default() -> Self { +impl Empty for CallerContext { + fn empty() -> Self { CallerContext { msg_sender: AztecAddress::zero(), storage_contract_address: AztecAddress::zero(), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr index bba3ebf718e..77a3d08ab9d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr @@ -10,11 +10,11 @@ struct CombinedConstantData { tx_context: TxContext, } -impl Default for CombinedConstantData { - fn default() -> Self { +impl Empty for CombinedConstantData { + fn empty() -> Self { CombinedConstantData { - historical_header: Header::default(), - tx_context: TxContext::default(), + historical_header: Header::empty(), + tx_context: TxContext::empty(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr index 5a07ab22e28..d82aea7d6c5 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr @@ -16,10 +16,10 @@ impl Eq for FunctionData { } } -impl Default for FunctionData { - fn default() -> Self { +impl Empty for FunctionData { + fn empty() -> Self { FunctionData { - selector: FunctionSelector::default(), + selector: FunctionSelector::empty(), is_private: false, } } @@ -53,19 +53,19 @@ impl Hash for FunctionData { } #[test] -fn serialization_of_default() { - let data = FunctionData::default(); +fn serialization_of_empty() { + let data = FunctionData::empty(); let serialized = data.serialize(); let deserialized = FunctionData::deserialize(serialized); assert(data.eq(deserialized)); } #[test] -fn default_hash() { - let data = FunctionData::default(); +fn empty_hash() { + let data = FunctionData::empty(); let hash = data.hash(); // Value from function_data.test.ts "computes empty item hash" test - let test_data_default_hash = 0x27b1d0839a5b23baf12a8d195b18ac288fcf401afb2f70b8a4b529ede5fa9fed; - assert_eq(hash, test_data_default_hash); + let test_data_empty_hash = 0x27b1d0839a5b23baf12a8d195b18ac288fcf401afb2f70b8a4b529ede5fa9fed; + assert_eq(hash, test_data_empty_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr index 82aaee11018..416401f7c86 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr @@ -15,8 +15,8 @@ impl Eq for FunctionSelector { } } -impl Default for FunctionSelector { - fn default() -> Self { +impl Empty for FunctionSelector { + fn empty() -> Self { Self { inner: 0 as u32 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr index 06ca2f86be3..c67575f200d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr @@ -48,8 +48,8 @@ impl Eq for GlobalVariables { } } -impl Default for GlobalVariables { - fn default() -> Self { +impl Empty for GlobalVariables { + fn empty() -> Self { Self { chain_id: 0, version: 0, @@ -62,8 +62,8 @@ impl Default for GlobalVariables { } #[test] -fn serialization_of_default() { - let vars = GlobalVariables::default(); +fn serialization_of_empty() { + let vars = GlobalVariables::empty(); let _serialized = vars.serialize(); let _deserialized = GlobalVariables::deserialize(_serialized); } 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 dc211a13ea4..70b942571de 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 @@ -18,14 +18,14 @@ struct PrivateKernelCircuitPublicInputsBuilder { constants: CombinedConstantData, } -impl Default for PrivateKernelCircuitPublicInputsBuilder { - fn default() -> Self { +impl Empty for PrivateKernelCircuitPublicInputsBuilder { + fn empty() -> Self { PrivateKernelCircuitPublicInputsBuilder { - aggregation_object: AggregationObject::default(), + aggregation_object: AggregationObject::empty(), min_revertible_side_effect_counter: 0 as u32, - validation_requests: ValidationRequestsBuilder::default(), - end: PrivateAccumulatedDataBuilder::default(), - constants: CombinedConstantData::default(), + validation_requests: ValidationRequestsBuilder::empty(), + end: PrivateAccumulatedDataBuilder::empty(), + constants: CombinedConstantData::empty(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr index 9873d891a59..9528bc2c95c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr @@ -3,7 +3,7 @@ use crate::abis::{ validation_requests::{RollupValidationRequests, ValidationRequests} }; use crate::mocked::AggregationObject; -use crate::traits::is_default; +use crate::traits::is_empty; struct PublicKernelCircuitPublicInputs { aggregation_object: AggregationObject, @@ -19,17 +19,17 @@ impl PublicKernelCircuitPublicInputs { // By definition, the final non-revertible enqueued call is for teardown. // since this is a stack, the teardown call would be the 0th element. // So if we have more than one element, we need setup. - !is_default(self.end_non_revertible.public_call_stack[1]) + !is_empty(self.end_non_revertible.public_call_stack[1]) } pub fn needs_app_logic(self) -> bool { // if we have any enqueued revertible public calls, we need to run the public app logic circuit. - !is_default(self.end.public_call_stack[0]) + !is_empty(self.end.public_call_stack[0]) } pub fn needs_teardown(self) -> bool { // By definition, the final non-revertible enqueued call is for teardown. // since this is a stack, the teardown call would be the 0th element. - !is_default(self.end_non_revertible.public_call_stack[0]) + !is_empty(self.end_non_revertible.public_call_stack[0]) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr index 8bff3dab78f..e415da11a1c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr @@ -18,14 +18,14 @@ struct PublicKernelCircuitPublicInputsBuilder { revert_code: u8, } -impl Default for PublicKernelCircuitPublicInputsBuilder { - fn default() -> Self { +impl Empty for PublicKernelCircuitPublicInputsBuilder { + fn empty() -> Self { PublicKernelCircuitPublicInputsBuilder { - aggregation_object: AggregationObject::default(), - validation_requests: ValidationRequestsBuilder::default(), - end_non_revertible: PublicAccumulatedDataBuilder::default(), - end: PublicAccumulatedDataBuilder::default(), - constants: CombinedConstantData::default(), + aggregation_object: AggregationObject::empty(), + validation_requests: ValidationRequestsBuilder::empty(), + end_non_revertible: PublicAccumulatedDataBuilder::empty(), + end: PublicAccumulatedDataBuilder::empty(), + constants: CombinedConstantData::empty(), revert_code: 0 as u8, } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/max_block_number.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/max_block_number.nr index 9d693e8e1cb..a3dc717ac98 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/max_block_number.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/max_block_number.nr @@ -4,8 +4,8 @@ struct MaxBlockNumber { _opt: Option } -impl Default for MaxBlockNumber { - fn default() -> Self { +impl Empty for MaxBlockNumber { + fn empty() -> Self { Self { _opt: Option::none() } } } @@ -75,16 +75,16 @@ impl MaxBlockNumber { #[test] fn zeroed_is_none() { - // Large parts of the kernel rely on zeroed to initialize structs. This conveniently matches what `default` does, - // and though we should eventually move everything to use `default`, it's good to check for now that both are + // Large parts of the kernel rely on zeroed to initialize structs. This conveniently matches what `empty` does, + // and though we should eventually move everything to use `empty`, it's good to check for now that both are // equivalent. let a: MaxBlockNumber = dep::std::unsafe::zeroed(); assert(a.is_none()); } #[test] -fn serde_default() { - let a = MaxBlockNumber::default(); +fn serde_empty() { + let a = MaxBlockNumber::empty(); let b = MaxBlockNumber::deserialize(a.serialize()); assert(b.is_none()); } @@ -97,22 +97,22 @@ fn serde_some() { } #[test(should_fail)] -fn default_unwrap_panics() { - let a = MaxBlockNumber::default(); +fn empty_unwrap_panics() { + let a = MaxBlockNumber::empty(); let _ = a.unwrap(); } #[test] -fn min_default_default() { - let a = MaxBlockNumber::default(); - let b = MaxBlockNumber::default(); +fn min_empty_empty() { + let a = MaxBlockNumber::empty(); + let b = MaxBlockNumber::empty(); assert(MaxBlockNumber::min(a, b).is_none()); } #[test] -fn min_default_some() { - let a = MaxBlockNumber::default(); +fn min_empty_some() { + let a = MaxBlockNumber::empty(); let b = MaxBlockNumber::new(13); assert_eq(MaxBlockNumber::min(a, b).unwrap(), 13); @@ -129,8 +129,8 @@ fn min_some_some() { } #[test] -fn min_with_u32_default() { - let a = MaxBlockNumber::default(); +fn min_with_u32_empty() { + let a = MaxBlockNumber::empty(); let b = 42; assert_eq(MaxBlockNumber::min_with_u32(a, b).unwrap(), 42); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr index 1b4af194791..97cd652d8f3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/membership_witness.nr @@ -17,8 +17,8 @@ struct VKMembershipWitness{ sibling_path: [Field; ROLLUP_VK_TREE_HEIGHT] } -impl Default for VKMembershipWitness { - fn default() -> Self { +impl Empty for VKMembershipWitness { + fn empty() -> Self { VKMembershipWitness { leaf_index: 0, sibling_path: [0; ROLLUP_VK_TREE_HEIGHT] @@ -31,8 +31,8 @@ struct NullifierMembershipWitness{ sibling_path: [Field; NULLIFIER_TREE_HEIGHT] } -impl Default for NullifierMembershipWitness { - fn default() -> Self { +impl Empty for NullifierMembershipWitness { + fn empty() -> Self { NullifierMembershipWitness { leaf_index: 0, sibling_path: [0; NULLIFIER_TREE_HEIGHT] @@ -45,8 +45,8 @@ struct PublicDataMembershipWitness{ sibling_path: [Field; PUBLIC_DATA_TREE_HEIGHT] } -impl Default for PublicDataMembershipWitness { - fn default() -> Self { +impl Empty for PublicDataMembershipWitness { + fn empty() -> Self { PublicDataMembershipWitness { leaf_index: 0, sibling_path: [0; PUBLIC_DATA_TREE_HEIGHT] @@ -63,7 +63,7 @@ struct NoteHashReadRequestMembershipWitness { leaf_index: Field, sibling_path: [Field; NOTE_HASH_TREE_HEIGHT], // whether or not the read request corresponds to a pending note hash - // In case we change the default to true, we have to adapt is_default() method + // In case we change the empty to true, we have to adapt is_empty() method // hint to point kernel to the commitment this rr corresponds to is_transient: bool, hint_to_note_hash: Field, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr index c65055e6574..404d34844fa 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr @@ -18,11 +18,11 @@ impl Eq for NullifierKeyValidationRequest { } } -impl Default for NullifierKeyValidationRequest { - fn default() -> Self { +impl Empty for NullifierKeyValidationRequest { + fn empty() -> Self { NullifierKeyValidationRequest { - public_key: GrumpkinPoint::default(), - secret_key: GrumpkinPrivateKey::default(), + public_key: GrumpkinPoint::empty(), + secret_key: GrumpkinPrivateKey::empty(), } } } @@ -67,11 +67,11 @@ impl Eq for NullifierKeyValidationRequestContext { } } -impl Default for NullifierKeyValidationRequestContext { - fn default() -> Self { +impl Empty for NullifierKeyValidationRequestContext { + fn empty() -> Self { NullifierKeyValidationRequestContext { - public_key: GrumpkinPoint::default(), - secret_key: GrumpkinPrivateKey::default(), + public_key: GrumpkinPoint::empty(), + secret_key: GrumpkinPrivateKey::empty(), contract_address: AztecAddress::zero(), } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr index baf4a2bf967..8898711b27d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr @@ -1,6 +1,6 @@ global NULLIFIER_LEAF_PREIMAGE_LENGTH: u64 = 3; -use crate::{merkle_tree::leaf_preimage::{LeafPreimage, IndexedTreeLeafPreimage}, traits::{is_default, Hash}}; +use crate::{merkle_tree::leaf_preimage::{LeafPreimage, IndexedTreeLeafPreimage}, traits::{is_empty, Hash}}; struct NullifierLeafPreimage { nullifier : Field, @@ -16,8 +16,8 @@ impl Eq for NullifierLeafPreimage { } } -impl Default for NullifierLeafPreimage { - fn default() -> Self { +impl Empty for NullifierLeafPreimage { + fn empty() -> Self { Self { nullifier : 0, next_nullifier : 0, @@ -28,7 +28,7 @@ impl Default for NullifierLeafPreimage { impl Hash for NullifierLeafPreimage { fn hash(self) -> Field { - if is_default(self) { + if is_empty(self) { 0 } else { dep::std::hash::pedersen_hash(self.serialize()) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr index 952857441bc..0e93ec55c79 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr @@ -24,12 +24,12 @@ impl Eq for PrivateCallStackItem { } } -impl Default for PrivateCallStackItem { - fn default() -> Self { +impl Empty for PrivateCallStackItem { + fn empty() -> Self { PrivateCallStackItem { - contract_address: AztecAddress::default(), - function_data: FunctionData::default(), - public_inputs: PrivateCircuitPublicInputs::default(), + contract_address: AztecAddress::empty(), + function_data: FunctionData::empty(), + public_inputs: PrivateCircuitPublicInputs::empty(), } } } @@ -71,20 +71,20 @@ impl Hash for PrivateCallStackItem { } #[test] -fn serialization_of_default() { - let item = PrivateCallStackItem::default(); +fn serialization_of_empty() { + let item = PrivateCallStackItem::empty(); let serialized = item.serialize(); let deserialized = PrivateCallStackItem::deserialize(serialized); assert(item.eq(deserialized)); } #[test] -fn default_hash() { - let mut item = PrivateCallStackItem::default(); +fn empty_hash() { + let mut item = PrivateCallStackItem::empty(); item.function_data.is_private = true; let hash = item.hash(); // Value from private_call_stack_item.test.ts "computes empty item hash" test - let test_data_default_hash = 0x13f518365c690d1b96d31454afed495ad29fe530939caf7189dd44f9bd63ef89; - assert_eq(hash, test_data_default_hash); + let test_data_empty_hash = 0x13f518365c690d1b96d31454afed495ad29fe530939caf7189dd44f9bd63ef89; + assert_eq(hash, test_data_empty_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr index bbd0f458793..076bd3736d7 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr @@ -61,29 +61,29 @@ impl Eq for PrivateCircuitPublicInputs { } } -impl Default for PrivateCircuitPublicInputs { - fn default() -> Self { +impl Empty for PrivateCircuitPublicInputs { + fn empty() -> Self { PrivateCircuitPublicInputs { - call_context: CallContext::default(), + call_context: CallContext::empty(), args_hash: 0, return_values: [0; RETURN_VALUES_LENGTH], min_revertible_side_effect_counter: 0 as u32, - max_block_number: MaxBlockNumber::default(), - note_hash_read_requests: [SideEffect::default(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], - nullifier_read_requests: [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], - nullifier_key_validation_requests: [NullifierKeyValidationRequest::default(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL], - new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL], - new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL], + max_block_number: MaxBlockNumber::empty(), + note_hash_read_requests: [SideEffect::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], + nullifier_read_requests: [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], + nullifier_key_validation_requests: [NullifierKeyValidationRequest::empty(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL], + new_note_hashes: [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL], + new_nullifiers: [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL], private_call_stack_hashes: [0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL], public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], - new_l2_to_l1_msgs: [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], + new_l2_to_l1_msgs: [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], start_side_effect_counter : 0 as u32, end_side_effect_counter : 0 as u32, encrypted_logs_hash: 0, unencrypted_logs_hash: 0, encrypted_log_preimages_length: 0, unencrypted_log_preimages_length: 0, - historical_header: Header::default(), + historical_header: Header::empty(), chain_id: 0, version: 0, } @@ -147,14 +147,14 @@ impl Deserialize for PrivateCircuitPublicI return_values: reader.read_array([0; RETURN_VALUES_LENGTH]), min_revertible_side_effect_counter: reader.read() as u32, max_block_number: reader.read_struct(MaxBlockNumber::deserialize), - note_hash_read_requests: reader.read_struct_array(SideEffect::deserialize, [SideEffect::default(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]), - nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), - nullifier_key_validation_requests: reader.read_struct_array(NullifierKeyValidationRequest::deserialize, [NullifierKeyValidationRequest::default(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL]), - new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL]), - new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL]), + note_hash_read_requests: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]), + nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), + nullifier_key_validation_requests: reader.read_struct_array(NullifierKeyValidationRequest::deserialize, [NullifierKeyValidationRequest::empty(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL]), + new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL]), + new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL]), private_call_stack_hashes: reader.read_array([0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL]), public_call_stack_hashes: reader.read_array([0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), - new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), + new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), start_side_effect_counter: reader.read() as u32, end_side_effect_counter: reader.read() as u32, encrypted_logs_hash: reader.read() as Field, @@ -178,19 +178,19 @@ impl Hash for PrivateCircuitPublicInputs { } #[test] -fn serialization_of_default() { - let pcpi = PrivateCircuitPublicInputs::default(); +fn serialization_of_empty() { + let pcpi = PrivateCircuitPublicInputs::empty(); let serialized = pcpi.serialize(); let deserialized = PrivateCircuitPublicInputs::deserialize(serialized); assert(pcpi.eq(deserialized)); } #[test] -fn default_hash() { - let inputs = PrivateCircuitPublicInputs::default(); +fn empty_hash() { + let inputs = PrivateCircuitPublicInputs::empty(); let hash = inputs.hash(); // Value from private_circuit_public_inputs.test.ts "computes empty item hash" test - let test_data_default_hash = 0x1304e6c42e3c53fc7c918cbf1ea70333b4f214726c0784cf9878cd641967dab1; - assert_eq(hash, test_data_default_hash); + let test_data_empty_hash = 0x1304e6c42e3c53fc7c918cbf1ea70333b4f214726c0784cf9878cd641967dab1; + assert_eq(hash, test_data_empty_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr index 86504a0bf5b..01c9850d1bf 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr @@ -31,7 +31,7 @@ impl Hash for PublicCallStackItem { impl PublicCallStackItem { fn as_execution_request(self) -> Self { let public_inputs = self.public_inputs; - let mut request_public_inputs = PublicCircuitPublicInputs::default(); + let mut request_public_inputs = PublicCircuitPublicInputs::empty(); request_public_inputs.call_context = public_inputs.call_context; request_public_inputs.args_hash = public_inputs.args_hash; @@ -60,7 +60,7 @@ mod tests { let contract_address = AztecAddress::from_field(1); let function_data = FunctionData { selector: FunctionSelector::from_u32(2), is_private: false }; - let mut public_inputs = PublicCircuitPublicInputs::default(); + let mut public_inputs = PublicCircuitPublicInputs::empty(); public_inputs.new_note_hashes[0] = SideEffect{ value: 1, counter: 0, @@ -78,7 +78,7 @@ mod tests { let contract_address = AztecAddress::from_field(1); let function_data = FunctionData { selector: FunctionSelector::from_u32(2), is_private: false }; - let mut public_inputs = PublicCircuitPublicInputs::default(); + let mut public_inputs = PublicCircuitPublicInputs::empty(); public_inputs.new_note_hashes[0] = SideEffect{ value: 1, counter: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index ae1b7e80c37..94b8a714707 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -57,25 +57,25 @@ impl Eq for PublicCircuitPublicInputs { } } -impl Default for PublicCircuitPublicInputs { - fn default() -> Self { +impl Empty for PublicCircuitPublicInputs { + fn empty() -> Self { PublicCircuitPublicInputs { - call_context: CallContext::default(), + call_context: CallContext::empty(), args_hash: 0, return_values: [0; RETURN_VALUES_LENGTH], - nullifier_read_requests: [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], - nullifier_non_existent_read_requests: [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], - contract_storage_update_requests: [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], - contract_storage_reads: [StorageRead::default(); MAX_PUBLIC_DATA_READS_PER_CALL], + nullifier_read_requests: [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], + nullifier_non_existent_read_requests: [ReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL], + contract_storage_update_requests: [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], + contract_storage_reads: [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL], public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], - new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL], - new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL], - new_l2_to_l1_msgs: [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], + new_note_hashes: [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL], + new_nullifiers: [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL], + new_l2_to_l1_msgs: [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL], start_side_effect_counter: 0 as u32, end_side_effect_counter: 0 as u32, unencrypted_logs_hash: 0, unencrypted_log_preimages_length: 0, - historical_header: Header::default(), + historical_header: Header::empty(), prover_address: AztecAddress::zero(), revert_code: 0 as u8, } @@ -132,14 +132,14 @@ impl Deserialize for PublicCircuitPublicInp call_context: reader.read_struct(CallContext::deserialize), args_hash: reader.read(), return_values: reader.read_array([0; RETURN_VALUES_LENGTH]), - nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), - nullifier_non_existent_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL]), - contract_storage_update_requests: reader.read_struct_array(StorageUpdateRequest::deserialize, [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL]), - contract_storage_reads: reader.read_struct_array(StorageRead::deserialize, [StorageRead::default(); MAX_PUBLIC_DATA_READS_PER_CALL]), + nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), + nullifier_non_existent_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL]), + contract_storage_update_requests: reader.read_struct_array(StorageUpdateRequest::deserialize, [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL]), + contract_storage_reads: reader.read_struct_array(StorageRead::deserialize, [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL]), public_call_stack_hashes: reader.read_array([0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), - new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL]), - new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL]), - new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), + new_note_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL]), + new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL]), + new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), start_side_effect_counter: reader.read() as u32, end_side_effect_counter: reader.read() as u32, unencrypted_logs_hash: reader.read() as Field, @@ -161,19 +161,19 @@ impl Hash for PublicCircuitPublicInputs { } #[test] -fn serialization_of_default() { - let pcpi = PublicCircuitPublicInputs::default(); +fn serialization_of_empty() { + let pcpi = PublicCircuitPublicInputs::empty(); let serialized = pcpi.serialize(); let deserialized = PublicCircuitPublicInputs::deserialize(serialized); assert(pcpi.eq(deserialized)); } #[test] -fn default_hash() { - let inputs = PublicCircuitPublicInputs::default(); +fn empty_hash() { + let inputs = PublicCircuitPublicInputs::empty(); let hash = inputs.hash(); // Value from public_circuit_public_inputs.test.ts "computes empty item hash" test - let test_data_default_hash = 0x0f1eb4e352e8dab6cbab3c63b6d8f3cd2cd90cc7ae5ff142e4dfa2b3e28e01c1; - assert_eq(hash, test_data_default_hash); + let test_data_empty_hash = 0x0f1eb4e352e8dab6cbab3c63b6d8f3cd2cd90cc7ae5ff142e4dfa2b3e28e01c1; + assert_eq(hash, test_data_empty_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr index 446d74cfe5f..1e8a388327b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr @@ -1,5 +1,5 @@ use crate::constants::GENERATOR_INDEX__PUBLIC_DATA_READ; -use dep::std::{cmp::Eq,default::Default}; +use dep::std::{cmp::Eq,empty::Empty}; use crate::traits::Hash; struct PublicDataRead { @@ -13,8 +13,8 @@ impl Eq for PublicDataRead { } } -impl Default for PublicDataRead { - fn default() -> Self { +impl Empty for PublicDataRead { + fn empty() -> Self { Self { leaf_slot : 0, value : 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr index 2f477fc4b2f..62214a241dd 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr @@ -1,5 +1,5 @@ use crate::constants::GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST; -use dep::std::{cmp::Eq,default::Default}; +use dep::std::{cmp::Eq,empty::Empty}; use crate::traits::Hash; struct PublicDataUpdateRequest { @@ -14,8 +14,8 @@ impl Eq for PublicDataUpdateRequest { } } -impl Default for PublicDataUpdateRequest { - fn default() -> Self { +impl Empty for PublicDataUpdateRequest { + fn empty() -> Self { Self { leaf_slot : 0, new_value : 0 diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr index 7fa992e0a20..149e293752d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr @@ -2,7 +2,7 @@ use crate::{ abis::side_effect::{OrderedValue, ContractScopedOrderedValue}, traits::{Serialize, Deserialize}, address::AztecAddress }; -use dep::std::{cmp::Eq,default::Default}; +use dep::std::{cmp::Eq,empty::Empty}; global READ_REQUEST_SERIALIZED_LEN = 2; global READ_REQUEST_CONTEXT_SERIALIZED_LEN = 3; @@ -28,8 +28,8 @@ impl Eq for ReadRequest { } } -impl Default for ReadRequest { - fn default() -> Self { +impl Empty for ReadRequest { + fn empty() -> Self { ReadRequest { value: 0, counter: 0, @@ -93,12 +93,12 @@ impl Eq for ReadRequestContext { } } -impl Default for ReadRequestContext { - fn default() -> Self { +impl Empty for ReadRequestContext { + fn empty() -> Self { ReadRequestContext { value: 0, counter: 0, - contract_address: AztecAddress::default(), + contract_address: AztecAddress::empty(), } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr index 7cf3a78eaaf..b57a0d41e08 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr @@ -48,8 +48,8 @@ impl Eq for SideEffect { } } -impl Default for SideEffect { - fn default() -> Self { +impl Empty for SideEffect { + fn empty() -> Self { SideEffect { value: 0, counter: 0, @@ -108,8 +108,8 @@ impl Eq for SideEffectLinkedToNoteHash { } } -impl Default for SideEffectLinkedToNoteHash { - fn default() -> Self { +impl Empty for SideEffectLinkedToNoteHash { + fn empty() -> Self { SideEffectLinkedToNoteHash { value: 0, note_hash: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr index ade84793296..cdb544b2cdb 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr @@ -22,10 +22,10 @@ struct ValidationRequestsBuilder { public_data_reads: BoundedVec, } -impl Default for ValidationRequestsBuilder { - fn default() -> Self { +impl Empty for ValidationRequestsBuilder { + fn empty() -> Self { ValidationRequestsBuilder { - max_block_number: MaxBlockNumber::default(), + max_block_number: MaxBlockNumber::empty(), note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), nullifier_non_existent_read_requests: BoundedVec::new(), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr index 795a7db24c3..5c9417a176c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr @@ -24,10 +24,10 @@ impl Zero for AztecAddress { } } -// This is implemented so we have one trait for everything "default", or otherwise known as the "undefined" value, +// This is implemented so we have one trait for everything "empty", or otherwise known as the "undefined" value, // this helps with things such as the array helper -impl Default for AztecAddress { - fn default() -> Self { +impl Empty for AztecAddress { + fn empty() -> Self { AztecAddress::zero() } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr index 343a882af83..176ed6c7014 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr @@ -21,10 +21,10 @@ impl Zero for EthAddress { } } -// This is implemented so we have one trait for everything "default", or otherwise known as the "undefined" value, +// This is implemented so we have one trait for everything "empty", or otherwise known as the "undefined" value, // this helps with things such as the array helper -impl Default for EthAddress { - fn default() -> Self { +impl Empty for EthAddress { + fn empty() -> Self { EthAddress::zero() } } 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 f00c50ed762..97030527111 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -93,7 +93,7 @@ global INITIALIZATION_SLOT_SEPARATOR: Field = 1000_000_000; global INITIAL_L2_BLOCK_NUM: Field = 1; // 126976 = 31 * 4096; global BLOB_SIZE_IN_BYTES: Field = 126976; -// How much gas is subtracted from L2GASLEFT when making a nested public call by default in the AVM +// How much gas is subtracted from L2GASLEFT when making a nested public call by empty in the AVM global NESTED_CALL_L2_GAS_BUFFER = 20000; // CONTRACT CLASS CONSTANTS @@ -180,7 +180,7 @@ global NUM_BASE_PARITY_PER_ROOT_PARITY: u64 = 4; /** * Enumerate the hash_indices which are used for pedersen hashing. - * We start from 1 to avoid the default generators. The generator indices are listed + * We start from 1 to avoid the empty generators. The generator indices are listed * based on the number of elements each index hashes. The following conditions must be met: * * +-----------+-------------------------------+----------------------+ 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 c34e4e51358..5be03993b4a 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 @@ -2,7 +2,7 @@ use crate::{ constants::CONTENT_COMMITMENT_LENGTH, traits::{Deserialize, Hash, Serialize}, utils::arr_copy_slice }; -use dep::std::default::Default; +use dep::std::empty::Empty; struct ContentCommitment { tx_tree_height: Field, @@ -43,8 +43,8 @@ impl Deserialize for ContentCommitment { } } -impl Default for ContentCommitment { - fn default() -> Self { +impl Empty for ContentCommitment { + fn empty() -> Self { Self { tx_tree_height: 0, txs_effects_hash: 0, @@ -64,8 +64,8 @@ impl Eq for ContentCommitment { } #[test] -fn serialization_of_default() { - let empty = ContentCommitment::default(); +fn serialization_of_empty() { + let empty = ContentCommitment::empty(); let serialized = empty.serialize(); let deserialized = ContentCommitment::deserialize(serialized); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr index f0c7162c04b..1d6afcc9bfc 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr @@ -15,8 +15,8 @@ impl Eq for StorageRead { } } -impl Default for StorageRead { - fn default() -> Self { +impl Empty for StorageRead { + fn empty() -> Self { Self { storage_slot: 0, current_value: 0, @@ -52,7 +52,7 @@ impl StorageRead { } impl StorageOp for StorageRead { - fn is_default(self) -> bool { + fn is_empty(self) -> bool { self.storage_slot == 0 } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr index abbe456757a..4833fb7c5ca 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr @@ -1,6 +1,6 @@ use crate::{ constants::{CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH, GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST}, - hash::pedersen_hash, traits::{Deserialize, Hash, Default, Serialize}, + hash::pedersen_hash, traits::{Deserialize, Hash, Empty, Serialize}, contrakt::traits::StorageOp }; use dep::std::cmp::Eq; @@ -17,8 +17,8 @@ impl Eq for StorageUpdateRequest { } } -impl Default for StorageUpdateRequest { - fn default() -> Self { +impl Empty for StorageUpdateRequest { + fn empty() -> Self { StorageUpdateRequest { storage_slot: 0, new_value: 0, @@ -54,7 +54,7 @@ impl StorageUpdateRequest { } impl StorageOp for StorageUpdateRequest { - fn is_default(self) -> bool { + fn is_empty(self) -> bool { self.storage_slot == 0 } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/traits.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/traits.nr index ece96d6f881..6c0d62dda66 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/traits.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/traits.nr @@ -1,10 +1,10 @@ -// We use this because storage read is_default does not match behavior with the normal way we calculate is_default +// We use this because storage read is_empty does not match behavior with the normal way we calculate is_empty trait StorageOp { - fn is_default(self) -> bool; + fn is_empty(self) -> bool; } -pub fn is_default(item: T) -> bool where T: StorageOp { - item.is_default() +pub fn is_empty(item: T) -> bool where T: StorageOp { + item.is_empty() } // Routine which validates that all zero values of an array form a contiguous region at the end, i.e., @@ -17,23 +17,23 @@ pub fn validate_array(array: [T; N]) where T: StorageOp + Eq { let mut last_non_zero_pos = 0; for i in 0..array_length { - let is_default = array[i].is_default(); - if !is_default { + let is_empty = array[i].is_empty(); + if !is_empty { last_non_zero_pos = i; - } else if is_default & (first_zero_pos == array_length) { + } else if is_empty & (first_zero_pos == array_length) { first_zero_pos = i; } } assert(last_non_zero_pos <= first_zero_pos, "invalid array"); } -// Helper method to determine the number of non-zero/default elements in a validated array (ie, validate_array(array) +// Helper method to determine the number of non-zero/empty elements in a validated array (ie, validate_array(array) // should be true). pub fn array_length(array: [T; N]) -> u64 where T: StorageOp + Eq { let mut length = 0; let mut end = false; for elem in array { - end |= elem.is_default(); + end |= elem.is_empty(); if !end { length += 1; } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_point.nr b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_point.nr index df841b9e250..f93765ce94d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_point.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_point.nr @@ -29,8 +29,8 @@ impl Eq for GrumpkinPoint { } } -impl Default for GrumpkinPoint { - fn default() -> Self { +impl Empty for GrumpkinPoint { + fn empty() -> Self { Self { x: 0, y: 0 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr index 316337161f2..2a3a60513f4 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr @@ -14,8 +14,8 @@ impl Eq for GrumpkinPrivateKey { } } -impl Default for GrumpkinPrivateKey { - fn default() -> Self { +impl Empty for GrumpkinPrivateKey { + fn empty() -> Self { Self { high: 0, low: 0 } } } 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 282edcb7a33..396ed601c2f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr @@ -178,7 +178,7 @@ fn smoke_sha256_to_field() { #[test] fn compute_l2_l1_hash() { // All zeroes - let hash_result = compute_l2_to_l1_hash(AztecAddress::from_field(0), 0, 0, L2ToL1Message::default()); + let hash_result = compute_l2_to_l1_hash(AztecAddress::from_field(0), 0, 0, L2ToL1Message::empty()); assert(hash_result == 0xb393978842a0fa3d3e1470196f098f473f9678e72463cb65ec4ab5581856c2); // Non-zero case diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr index 9c8eb5f536f..10b3bd83fac 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr @@ -7,7 +7,7 @@ use crate::{ hash::pedersen_hash, state_reference::StateReference, traits::{Deserialize, Hash, Serialize}, utils::arr_copy_slice, content_commitment::ContentCommitment }; -use dep::std::default::Default; +use dep::std::empty::Empty; // docs:start:header struct Header { @@ -27,13 +27,13 @@ impl Eq for Header { } } -impl Default for Header { - fn default() -> Self { +impl Empty for Header { + fn empty() -> Self { Self { - last_archive: AppendOnlyTreeSnapshot::default(), - content_commitment: ContentCommitment::default(), - state: StateReference::default(), - global_variables: GlobalVariables::default(), + last_archive: AppendOnlyTreeSnapshot::empty(), + content_commitment: ContentCommitment::empty(), + state: StateReference::empty(), + global_variables: GlobalVariables::empty(), } } } @@ -82,8 +82,8 @@ impl Hash for Header { } #[test] -fn serialization_of_default() { - let header = Header::default(); +fn serialization_of_empty() { + let header = Header::empty(); let serialized = header.serialize(); let deserialized = Header::deserialize(serialized); assert(header.eq(deserialized)); @@ -91,16 +91,16 @@ fn serialization_of_default() { #[test] fn hash_smoke() { - let header = Header::default(); + let header = Header::empty(); let _hashed = header.hash(); } #[test] -fn default_hash() { - let header = Header::default(); +fn empty_hash() { + let header = Header::empty(); let hash = header.hash(); // Value from new_contract_data.test.ts "computes empty hash" test - let test_data_default_hash = 0x2a45c01b78a6b9a2392b7490966b41f47e5d9ac95610fa3eabe99d9aec7f6ad0; - assert_eq(hash, test_data_default_hash); + let test_data_empty_hash = 0x2a45c01b78a6b9a2392b7490966b41f47e5d9ac95610fa3eabe99d9aec7f6ad0; + assert_eq(hash, test_data_empty_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr index f5a5938ce81..bd8d3d1b482 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr @@ -4,7 +4,7 @@ use crate::{ membership::{assert_check_membership, MembershipWitness}, root::{calculate_subtree_root, calculate_empty_tree_root, root_from_sibling_path} }, - traits::{Default, Hash, is_default}, utils::arrays::check_permutation + traits::{Empty, Hash, is_empty}, utils::arrays::check_permutation }; pub fn batch_insert( @@ -20,18 +20,18 @@ pub fn batch_insert Leaf, _subtree_height: [Field; SubtreeHeight], _tree_height: [Field; TreeHeight] -) -> AppendOnlyTreeSnapshot where Value: Eq + Default, Leaf: Hash + Default { +) -> AppendOnlyTreeSnapshot where Value: Eq + Empty, Leaf: Hash + Empty { // A permutation to the values is provided to make the insertion use only one insertion strategy check_permutation(values_to_insert, sorted_values, sorted_values_indexes); // Now, update the existing leaves with the new leaves let mut current_tree_root = start_snapshot.root; - let mut insertion_subtree = [Leaf::default(); SubtreeWidth]; + let mut insertion_subtree = [Leaf::empty(); SubtreeWidth]; let start_insertion_index = start_snapshot.next_available_leaf_index; for i in 0..sorted_values.len() { let value = sorted_values[i]; - if !is_default(value) { + if !is_empty(value) { let low_leaf_preimage = low_leaf_preimages[i]; let witness = low_leaf_membership_witnesses[i]; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr index d810b55c9f9..0746102a0f2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr @@ -5,8 +5,8 @@ struct MembershipWitness { sibling_path: [Field; N] } -impl Default for MembershipWitness { - fn default() -> Self { +impl Empty for MembershipWitness { + fn empty() -> Self { MembershipWitness { leaf_index: 0, sibling_path: [0; N] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr index 27108ed2c53..fea686d70bb 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr @@ -3,8 +3,8 @@ struct MerkleTree { nodes: [Field; N], } -impl Default for MerkleTree { - fn default() -> Self { +impl Empty for MerkleTree { + fn empty() -> Self { MerkleTree { leaves: [0; N], nodes: [0; N] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr index d43857aec9d..2d6d84751dd 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr @@ -6,8 +6,8 @@ struct L2ToL1Message { content: Field, } -impl Default for L2ToL1Message { - fn default() -> Self { +impl Empty for L2ToL1Message { + fn empty() -> Self { Self { recipient: EthAddress::zero(), content: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr b/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr index 23f75a58027..d7417a685f5 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/mocked.nr @@ -3,24 +3,24 @@ struct AggregationObject{} -impl Default for AggregationObject { - fn default() -> Self { +impl Empty for AggregationObject { + fn empty() -> Self { AggregationObject {} } } struct Proof{} -impl Default for Proof { - fn default() -> Self { +impl Empty for Proof { + fn empty() -> Self { Proof {} } } struct VerificationKey{} -impl Default for VerificationKey { - fn default() -> Self { +impl Empty for VerificationKey { + fn empty() -> Self { VerificationKey {} } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr b/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr index 3f0451bce63..ac131bc9ce5 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr @@ -2,7 +2,7 @@ use crate::{ abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot, constants::PARTIAL_STATE_REFERENCE_LENGTH, traits::{Deserialize, Hash, Serialize} }; -use dep::std::default::Default; +use dep::std::empty::Empty; struct PartialStateReference { note_hash_tree: AppendOnlyTreeSnapshot, @@ -18,12 +18,12 @@ impl Eq for PartialStateReference { } } -impl Default for PartialStateReference { - fn default() -> Self { +impl Empty for PartialStateReference { + fn empty() -> Self { Self { - note_hash_tree: AppendOnlyTreeSnapshot::default(), - nullifier_tree: AppendOnlyTreeSnapshot::default(), - public_data_tree: AppendOnlyTreeSnapshot::default(), + note_hash_tree: AppendOnlyTreeSnapshot::empty(), + nullifier_tree: AppendOnlyTreeSnapshot::empty(), + public_data_tree: AppendOnlyTreeSnapshot::empty(), } } } @@ -64,8 +64,8 @@ impl Deserialize for PartialStateReference { #[test] -fn serialization_of_default() { - let partial = PartialStateReference::default(); +fn serialization_of_empty() { + let partial = PartialStateReference::empty(); let _serialized = partial.serialize(); let _deserialized = PartialStateReference::deserialize(_serialized); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr index 09bf94a1409..7bd0c20266b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf.nr @@ -1,4 +1,4 @@ -use dep::std::{cmp::Eq,default::Default}; +use dep::std::{cmp::Eq,empty::Empty}; struct PublicDataTreeLeaf { slot: Field, @@ -11,8 +11,8 @@ impl Eq for PublicDataTreeLeaf { } } -impl Default for PublicDataTreeLeaf { - fn default() -> Self { +impl Empty for PublicDataTreeLeaf { + fn empty() -> Self { Self { slot: 0, value: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf_preimage.nr b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf_preimage.nr index c5baa57edcf..375fc8ba9ef 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf_preimage.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/public_data_tree_leaf_preimage.nr @@ -1,6 +1,6 @@ use crate::traits::Hash; -use dep::std::default::Default; -use crate::traits::is_default; +use dep::std::empty::Empty; +use crate::traits::is_empty; struct PublicDataTreeLeafPreimage { slot : Field, @@ -18,8 +18,8 @@ impl Eq for PublicDataTreeLeafPreimage { } } -impl Default for PublicDataTreeLeafPreimage { - fn default() -> Self { +impl Empty for PublicDataTreeLeafPreimage { + fn empty() -> Self { Self { slot: 0, value: 0, @@ -31,7 +31,7 @@ impl Default for PublicDataTreeLeafPreimage { impl Hash for PublicDataTreeLeafPreimage { fn hash(self) -> Field { - if is_default(self) { + if is_empty(self) { 0 } else { dep::std::hash::pedersen_hash([self.slot, self.value, (self.next_index as Field), self.next_slot]) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr index ddab257ccb3..3d2291af9ac 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr @@ -17,11 +17,11 @@ impl Eq for StateReference { } } -impl Default for StateReference { - fn default() -> Self { +impl Empty for StateReference { + fn empty() -> Self { Self { - l1_to_l2_message_tree: AppendOnlyTreeSnapshot::default(), - partial: PartialStateReference::default(), + l1_to_l2_message_tree: AppendOnlyTreeSnapshot::empty(), + partial: PartialStateReference::empty(), } } } @@ -54,8 +54,8 @@ impl Deserialize for StateReference { } #[test] -fn serialization_of_default() { - let state = StateReference::default(); +fn serialization_of_empty() { + let state = StateReference::empty(); let _serialized = state.serialize(); let _deserialized = StateReference::deserialize(_serialized); } 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 8d46a467981..c79c981e318 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 @@ -67,13 +67,13 @@ struct FixtureBuilder { counter: u32, } -impl Default for FixtureBuilder { - fn default() -> Self { +impl Empty for FixtureBuilder { + fn empty() -> Self { FixtureBuilder { contract_address: AztecAddress::zero(), storage_contract_address: AztecAddress::zero(), - historical_header: Header::default(), - tx_context: TxContext::default(), + historical_header: Header::empty(), + tx_context: TxContext::empty(), new_note_hashes: BoundedVec::new(), new_nullifiers: BoundedVec::new(), new_l2_to_l1_msgs: BoundedVec::new(), @@ -84,14 +84,14 @@ impl Default for FixtureBuilder { public_data_update_requests: BoundedVec::new(), private_call_stack: BoundedVec::new(), public_call_stack: BoundedVec::new(), - max_block_number: MaxBlockNumber::default(), + max_block_number: MaxBlockNumber::empty(), note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), nullifier_non_existent_read_requests: BoundedVec::new(), nullifier_key_validation_requests: BoundedVec::new(), public_data_reads: BoundedVec::new(), - proof: Proof::default(), - vk: VerificationKey::default(), + proof: Proof::empty(), + vk: VerificationKey::empty(), vk_index: 0, vk_path: [0; VK_TREE_HEIGHT], revert_code: 0, @@ -120,7 +120,7 @@ impl FixtureBuilder { public_data_update_requests: BoundedVec::new(), private_call_stack: BoundedVec::new(), public_call_stack: BoundedVec::new(), - max_block_number: MaxBlockNumber::default(), + max_block_number: MaxBlockNumber::empty(), note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), nullifier_non_existent_read_requests: BoundedVec::new(), @@ -217,14 +217,14 @@ impl FixtureBuilder { pub fn to_public_kernel_circuit_public_inputs(self, revertible: bool) -> PublicKernelCircuitPublicInputs { let accumulated_data = self.to_public_accumulated_data(); let end_non_revertible = if revertible { - PublicAccumulatedData::default() + PublicAccumulatedData::empty() } else { accumulated_data }; let end = if revertible { accumulated_data } else { - PublicAccumulatedData::default() + PublicAccumulatedData::empty() }; let validation_requests = self.to_validation_requests(); let constants = self.to_constant_data(); @@ -267,7 +267,7 @@ impl FixtureBuilder { let mocked_value_offset = self.new_note_hashes.len() + 1; for i in 0..MAX_NEW_NOTE_HASHES_PER_TX { if i < num_new_note_hashes { - // The default value is its index + 1. + // The empty value is its index + 1. self.new_note_hashes.push( SideEffect { value: (i + mocked_value_offset) as Field, counter: self.next_counter() } ); @@ -295,9 +295,9 @@ impl FixtureBuilder { for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX { if i < num_updates { let update_request = PublicDataUpdateRequest { - // The default leaf index is its index + 23. + // The empty leaf index is its index + 23. leaf_slot: (value_offset + i + 23) as Field, - // The default value is its index + 678. + // The empty value is its index + 678. new_value: (value_offset + i + 678) as Field }; self.public_data_update_requests.push(update_request); @@ -310,9 +310,9 @@ impl FixtureBuilder { for i in 0..MAX_PUBLIC_DATA_READS_PER_TX { if i < num_reads { let read_request = PublicDataRead { - // The default leaf index is its index + 34. + // The empty leaf index is its index + 34. leaf_slot: (value_offset + i + 34) as Field, - // The default value is its index + 5566. + // The empty value is its index + 5566. value: (value_offset + i + 5566) as Field }; self.public_data_reads.push(read_request); @@ -378,7 +378,7 @@ impl FixtureBuilder { } fn generate_call_request(&mut self, hash: Field, is_delegate_call: bool) -> CallRequest { - let mut caller_context = CallerContext::default(); + let mut caller_context = CallerContext::empty(); if is_delegate_call { caller_context.msg_sender = fixtures::MSG_SENDER; caller_context.storage_contract_address = self.contract_address; 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 12445f7e7ac..430ec3b297a 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 @@ -15,8 +15,8 @@ global MSG_SENDER = AztecAddress { inner: 27 }; global PUBLIC_KEY = GrumpkinPoint { x: 123456789, y: 123456789 }; // Workaround for https://github.com/noir-lang/noir/issues/1440 -fn default_append_only_tree() -> AppendOnlyTreeSnapshot { - AppendOnlyTreeSnapshot::default() +fn empty_append_only_tree() -> AppendOnlyTreeSnapshot { + AppendOnlyTreeSnapshot::empty() } // Workaround for https://github.com/noir-lang/noir/issues/1440 @@ -30,22 +30,22 @@ fn zero_aztec_address() -> AztecAddress { } // Workaround for https://github.com/noir-lang/noir/issues/1440 -fn default_content_commitment() -> ContentCommitment { - ContentCommitment::default() +fn empty_content_commitment() -> ContentCommitment { + ContentCommitment::empty() } global HEADER = Header { - last_archive: default_append_only_tree(), - content_commitment: default_content_commitment(), + last_archive: empty_append_only_tree(), + content_commitment: empty_content_commitment(), state: StateReference { - l1_to_l2_message_tree: default_append_only_tree(), + l1_to_l2_message_tree: empty_append_only_tree(), partial: PartialStateReference { note_hash_tree: AppendOnlyTreeSnapshot { root: fixtures::note_hash_tree::ROOT, next_available_leaf_index: 0, // TODO: should this be populated? }, - nullifier_tree: default_append_only_tree(), - public_data_tree: default_append_only_tree() + nullifier_tree: empty_append_only_tree(), + public_data_tree: empty_append_only_tree() } }, global_variables: GlobalVariables { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/contract_functions.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/contract_functions.nr index a5f7642811a..2b03918579e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/contract_functions.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/contract_functions.nr @@ -11,7 +11,7 @@ struct ContractFunction { } // sibling_path taken from __snapshots__/noir_test_gen.test.ts.snap -global default_private_function = ContractFunction { +global empty_private_function = ContractFunction { data: FunctionData { selector: FunctionSelector { inner: 1010101 }, is_private: true, @@ -30,7 +30,7 @@ global default_private_function = ContractFunction { }, }; -global default_public_function = ContractFunction { +global empty_public_function = ContractFunction { data: FunctionData { selector: FunctionSelector { inner: 3030303 }, is_private: false, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/contracts.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/contracts.nr index 6aa8598dc16..fd7054282eb 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/contracts.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/contracts.nr @@ -17,7 +17,7 @@ struct ContractData { } // taken from __snapshots__/noir_test_gen.test.ts.snap -global default_contract = ContractData { +global empty_contract = ContractData { contract_address_salt: 0x000000000000000000000000000000000000000000000000000000000000ddd5, artifact_hash: 0x0000000000000000000000000000000000000000000000000000000000003039, public_bytecode_commitment: 0x129a3438653fe147133b2c274757920e37896305e7664c8c1eb380be3efd5fed, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr index 235bd8540d9..b502319c4cf 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr @@ -76,10 +76,10 @@ struct NonEmptyMerkleTree Default for NonEmptyMerkleTree { - fn default() -> Self { +impl Empty for NonEmptyMerkleTree { + fn empty() -> Self { NonEmptyMerkleTree { - subtree: MerkleTree::default(), + subtree: MerkleTree::empty(), zero_hashes: [0; TREE_HEIGHT], left_supertree_branch: [0; SUPERTREE_HEIGHT], _phantom_subtree_height: [0; SUBTREE_HEIGHT], diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr index e9a03b8120e..4e13d3beced 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr @@ -44,8 +44,8 @@ impl PrivateCallDataBuilder { pub fn new() -> Self { let public_inputs = PrivateCircuitPublicInputsBuilder::new(); - let contract_data = fixtures::contracts::default_contract; - let contract_function = fixtures::contract_functions::default_private_function; + let contract_data = fixtures::contracts::empty_contract; + let contract_function = fixtures::contract_functions::empty_private_function; let function_data = contract_function.data; PrivateCallDataBuilder { @@ -110,7 +110,7 @@ impl PrivateCallDataBuilder { is_delegate_call: bool ) -> (BoundedVec, BoundedVec) { let value_offset = requests.len(); - let mut caller_context = CallerContext::default(); + let mut caller_context = CallerContext::empty(); if is_delegate_call { let call_context = self.public_inputs.call_context; caller_context.msg_sender = call_context.msg_sender; @@ -122,7 +122,7 @@ impl PrivateCallDataBuilder { for i in 0..N { exceeded_len |= i == num_requests; if !exceeded_len { - // The default hash is its index + 7788. + // The empty hash is its index + 7788. let hash = (value_offset + 7788) as Field; let request = CallRequest { hash, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr index e17bb6ed908..405583f2414 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr @@ -48,14 +48,14 @@ struct PrivateCircuitPublicInputsBuilder { version: Field, } -impl Default for PrivateCircuitPublicInputsBuilder { - fn default() -> Self { +impl Empty for PrivateCircuitPublicInputsBuilder { + fn empty() -> Self { PrivateCircuitPublicInputsBuilder { - call_context: CallContext::default(), + call_context: CallContext::empty(), args_hash: 0, return_values: BoundedVec::new(), min_revertible_side_effect_counter: 0 as u32, - max_block_number: MaxBlockNumber::default(), + max_block_number: MaxBlockNumber::empty(), note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), nullifier_key_validation_requests: BoundedVec::new(), @@ -68,7 +68,7 @@ impl Default for PrivateCircuitPublicInputsBuilder { unencrypted_logs_hash: 0, encrypted_log_preimages_length: 0, unencrypted_log_preimages_length: 0, - historical_header: Header::default(), + historical_header: Header::empty(), chain_id: 0, version: 0, } @@ -77,14 +77,14 @@ impl Default for PrivateCircuitPublicInputsBuilder { impl PrivateCircuitPublicInputsBuilder { pub fn new() -> Self { - let mut public_inputs = PrivateCircuitPublicInputsBuilder::default(); + let mut public_inputs = PrivateCircuitPublicInputsBuilder::empty(); let args_hash = 0; - let contract_data = fixtures::contracts::default_contract; + let contract_data = fixtures::contracts::empty_contract; let portal_contract_address = contract_data.portal_contract_address; - let contract_function = fixtures::contract_functions::default_private_function; + let contract_function = fixtures::contract_functions::empty_private_function; let function_data = contract_function.data; let contract_address = contract_data.address; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr index 399b51bbb76..3296df47f2a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr @@ -26,11 +26,11 @@ struct PublicCallDataBuilder { impl PublicCallDataBuilder { pub fn new() -> Self { - let contract_data = fixtures::contracts::default_contract; + let contract_data = fixtures::contracts::empty_contract; let contract_address = contract_data.address; let portal_contract_address = contract_data.portal_contract_address; - let contract_function = fixtures::contract_functions::default_public_function; + let contract_function = fixtures::contract_functions::empty_public_function; let function_data = contract_function.data; let mut public_inputs = PublicCircuitPublicInputsBuilder::new(); @@ -75,7 +75,7 @@ impl PublicCallDataBuilder { pub fn append_public_call_requests(&mut self, num_requests: u64, is_delegate_call: bool) { let value_offset = self.public_inputs.public_call_stack_hashes.len(); - let mut caller_context = CallerContext::default(); + let mut caller_context = CallerContext::empty(); if is_delegate_call { let call_context = self.public_inputs.call_context; caller_context.msg_sender = call_context.msg_sender; @@ -85,7 +85,7 @@ impl PublicCallDataBuilder { for i in 0..MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL { exceeded_len |= i == num_requests; if !exceeded_len { - // The default hash is its index + 7788. + // The empty hash is its index + 7788. let hash = (value_offset + 7788) as Field; let call_request = CallRequest { hash, @@ -106,9 +106,9 @@ impl PublicCallDataBuilder { for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL { if i < num_reads { let read_request = StorageRead { - // The default storage slot is its index + 1. + // The empty storage slot is its index + 1. storage_slot: (value_offset + i + 1) as Field, - // The default value is its index + 999. + // The empty value is its index + 999. current_value: (value_offset + i + 999) as Field }; self.public_inputs.contract_storage_reads.push(read_request); @@ -119,7 +119,7 @@ impl PublicCallDataBuilder { pub fn append_empty_public_data_read_requests(&mut self, num_reads: u64) { for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL { if i < num_reads { - self.public_inputs.contract_storage_reads.push(StorageRead::default()); + self.public_inputs.contract_storage_reads.push(StorageRead::empty()); } } } @@ -129,9 +129,9 @@ impl PublicCallDataBuilder { for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { if i < num_updates { let update_request = StorageUpdateRequest { - // The default storage slot is its index + 1. + // The empty storage slot is its index + 1. storage_slot: (value_offset + i + 1) as Field, - // The default value is its index + 890. + // The empty value is its index + 890. new_value: (value_offset + i + 890) as Field }; self.public_inputs.contract_storage_update_requests.push(update_request); @@ -142,7 +142,7 @@ impl PublicCallDataBuilder { pub fn append_empty_update_requests(&mut self, num_updates: u64) { for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { if i < num_updates { - self.public_inputs.contract_storage_update_requests.push(StorageUpdateRequest::default()); + self.public_inputs.contract_storage_update_requests.push(StorageUpdateRequest::empty()); } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr index 022f3f8d5d8..5358a911271 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_circuit_public_inputs_builder.nr @@ -35,10 +35,10 @@ struct PublicCircuitPublicInputsBuilder { revert_code: u8, } -impl Default for PublicCircuitPublicInputsBuilder { - fn default() -> Self { +impl Empty for PublicCircuitPublicInputsBuilder { + fn empty() -> Self { PublicCircuitPublicInputsBuilder { - call_context: CallContext::default(), + call_context: CallContext::empty(), args_hash: 0, return_values: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), @@ -53,7 +53,7 @@ impl Default for PublicCircuitPublicInputsBuilder { end_side_effect_counter: 0 as u32, unencrypted_logs_hash: 0, unencrypted_log_preimages_length: 0, - historical_header: Header::default(), + historical_header: Header::empty(), prover_address: AztecAddress::zero(), revert_code: 0 as u8, } @@ -62,7 +62,7 @@ impl Default for PublicCircuitPublicInputsBuilder { impl PublicCircuitPublicInputsBuilder { pub fn new() -> Self { - let mut public_inputs = PublicCircuitPublicInputsBuilder::default(); + let mut public_inputs = PublicCircuitPublicInputsBuilder::empty(); public_inputs.call_context.msg_sender = fixtures::MSG_SENDER; public_inputs.historical_header = fixtures::HEADER; public_inputs diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/sort.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/sort.nr index 1dd5937e0fc..d067eb1a2d9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/sort.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/sort.nr @@ -1,4 +1,4 @@ -use crate::traits::{Default, is_default}; +use crate::traits::{Empty, is_empty}; struct SortedTuple { value: T, @@ -29,7 +29,7 @@ struct SortedResult { pub fn sort_get_sorted_hints( values: [T; N], ordering: fn(T, T) -> bool -) -> SortedResult where T: Eq + Default { +) -> SortedResult where T: Eq + Empty { let mut tuples = [SortedTuple { value: values[0], original_index: 0 }; N]; for i in 0..N { tuples[i] = SortedTuple { @@ -39,13 +39,13 @@ pub fn sort_get_sorted_hints( } let sorted_tuples = tuples.sort_via( - |a: SortedTuple, b: SortedTuple| is_default(b.value) | (!is_default(a.value) & !is_default(b.value) & ordering(a.value, b.value)) + |a: SortedTuple, b: SortedTuple| is_empty(b.value) | (!is_empty(a.value) & !is_empty(b.value) & ordering(a.value, b.value)) ); let sorted_array = sorted_tuples.map(|t: SortedTuple| t.value); let mut sorted_index_hints = [0; N]; for i in 0..N { - if !is_default(sorted_tuples[i].value) { + if !is_empty(sorted_tuples[i].value) { let original_index = sorted_tuples[i].original_index; sorted_index_hints[original_index] = i; } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr index 46c0c5e0a48..587423c4a22 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr @@ -1,11 +1,11 @@ -use dep::std::{default::Default,cmp::Eq}; +use dep::std::{empty::Empty,cmp::Eq}; -pub fn is_default(item: T) -> bool where T: Default + Eq { - item.eq(T::default()) +pub fn is_empty(item: T) -> bool where T: Empty + Eq { + item.eq(T::empty()) } -pub fn is_default_array(array: [T; N]) -> bool where T: Default + Eq { - array.all(|elem| is_default(elem)) +pub fn is_empty_array(array: [T; N]) -> bool where T: Empty + Eq { + array.all(|elem| is_empty(elem)) } // If a Field is equal to zero, then it is regarded as zero. diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr index 6f8e49665f2..7bd9c81dfcf 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr @@ -20,8 +20,8 @@ impl Eq for TxContext { } } -impl Default for TxContext { - fn default() -> Self { +impl Empty for TxContext { + fn empty() -> Self { TxContext { is_fee_payment_tx : false, is_rebate_payment_tx : false, @@ -70,19 +70,19 @@ impl Hash for TxContext { } #[test] -fn serialization_of_default() { - let context = TxContext::default(); +fn serialization_of_empty() { + let context = TxContext::empty(); let serialized = context.serialize(); let deserialized = TxContext::deserialize(serialized); assert(context.eq(deserialized)); } #[test] -fn default_hash() { - let inputs = TxContext::default(); +fn empty_hash() { + let inputs = TxContext::empty(); let hash = inputs.hash(); // Value from tx_context.test.ts "computes empty item hash" test - let test_data_default_hash = 0x200569267c0f73ac89aaa414239398db9445dd4ad3a8cf37015cd55b8d4c5e8d; - assert_eq(hash, test_data_default_hash); + let test_data_empty_hash = 0x200569267c0f73ac89aaa414239398db9445dd4ad3a8cf37015cd55b8d4c5e8d; + assert_eq(hash, test_data_empty_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr index e354c0ebb9d..38d4266dfac 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr @@ -20,13 +20,13 @@ impl Eq for TxRequest { } } -impl Default for TxRequest { - fn default() -> Self { +impl Empty for TxRequest { + fn empty() -> Self { TxRequest { - origin: AztecAddress::default(), + origin: AztecAddress::empty(), args_hash: 0, - tx_context: TxContext::default(), - function_data: FunctionData::default() + tx_context: TxContext::empty(), + function_data: FunctionData::empty() } } } @@ -77,9 +77,9 @@ mod tests { }; #[test] - fn serialization_of_default() { + fn serialization_of_empty() { // Assuming a zeroed initialization for simplicity - let request = TxRequest::default(); + let request = TxRequest::empty(); let serialized = request.serialize(); let deserialized = TxRequest::deserialize(serialized); assert(request.eq(deserialized)); 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 ee861a86406..d802416634d 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 @@ -1,11 +1,11 @@ use dep::std::array; use dep::std::cmp::Eq; -use crate::traits::is_default; +use crate::traits::is_empty; -pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Default + Eq { +pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Empty + Eq { let mut len = 0; for elem in array { - if !is_default(elem) { + if !is_empty(elem) { len += 1; } } @@ -16,30 +16,30 @@ pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: De // Routine which validates that all zero values of an array form a contiguous region at the end, i.e., // of the form: [*,*,*...,0,0,0,0] where any * is non-zero. Note that a full array of non-zero values is // valid. -pub fn validate_array(array: [T; N]) where T: Default + Eq { +pub fn validate_array(array: [T; N]) where T: Empty + Eq { let array_length = array.len(); let mut first_zero_pos = array_length; let mut last_non_zero_pos = 0; for i in 0..array_length { - let is_default = is_default(array[i]); - if !is_default { + let is_empty = is_empty(array[i]); + if !is_empty { last_non_zero_pos = i; - } else if is_default & (first_zero_pos == array_length) { + } else if is_empty & (first_zero_pos == array_length) { first_zero_pos = i; } } assert(last_non_zero_pos <= first_zero_pos, "invalid array"); } -// Helper method to determine the number of non-zero/default elements in a validated array (ie, validate_array(array) +// Helper method to determine the number of non-zero/empty elements in a validated array (ie, validate_array(array) // should be true). -pub fn array_length(array: [T; N]) -> u64 where T: Default + Eq { +pub fn array_length(array: [T; N]) -> u64 where T: Empty + Eq { let mut length = 0; let mut end = false; for elem in array { - end |= is_default(elem); + end |= is_empty(elem); if !end { length += 1; } @@ -47,7 +47,7 @@ pub fn array_length(array: [T; N]) -> u64 where T: Default + Eq { length } -pub fn array_eq(array: [T; N], expected: [T; S]) -> bool where T: Default + Eq { +pub fn array_eq(array: [T; N], expected: [T; S]) -> bool where T: Empty + Eq { let mut eq = array_length(array) == S; for i in 0..S { @@ -67,25 +67,25 @@ pub fn find_index(array: [T; N], find: fn[Env](T) -> bool) -> u64 { index } -pub fn array_cp(array: [T; N]) -> [T; S] where T: Default { - let mut result: [T; S] = [T::default(); S]; +pub fn array_cp(array: [T; N]) -> [T; S] where T: Empty { + let mut result: [T; S] = [T::empty(); S]; for i in 0..S { result[i] = array[i]; } result } -pub fn array_merge(array1: [T; N], array2: [T; N]) -> [T; N] where T: Default + Eq { - let mut result: [T; N] = [T::default(); N]; +pub fn array_merge(array1: [T; N], array2: [T; N]) -> [T; N] where T: Empty + Eq { + let mut result: [T; N] = [T::empty(); N]; let mut i = 0; for elem in array1 { - if !is_default(elem) { + if !is_empty(elem) { result[i] = elem; i += 1; } } for elem in array2 { - if !is_default(elem) { + if !is_empty(elem) { result[i] = elem; i += 1; } @@ -97,7 +97,7 @@ pub fn check_permutation( original_array: [T; N], permuted_array: [T; N], original_indexes: [u64; N] -) where T: Eq + Default { +) where T: Eq + Empty { let mut seen_value = [false; N]; for i in 0..N { let index = original_indexes[i]; @@ -113,15 +113,15 @@ pub fn assert_sorted_array( sorted_array: [T; N], sorted_indexes: [u64; N], ordering: fn[Env](T, T) -> bool -) where T: Eq + Default { - let mut seen_default = false; +) where T: Eq + Empty { + let mut seen_empty = false; for i in 0..N { let original_value = original_array[i]; - if is_default(original_value) { - seen_default = true; - assert(is_default(sorted_array[i]), "Default values must not be mixed with sorted values"); + if is_empty(original_value) { + seen_empty = true; + assert(is_empty(sorted_array[i]), "Empty values must not be mixed with sorted values"); } else { - assert(!seen_default, "Default values must be padded to the right"); + assert(!seen_empty, "Empty values must be padded to the right"); let index = sorted_indexes[i]; assert(sorted_array[index].eq(original_value), "Invalid index"); @@ -236,7 +236,7 @@ fn assert_sorted_array_desc() { } #[test] -fn assert_sorted_array_all_default() { +fn assert_sorted_array_all_empty() { let original = [0, 0, 0, 0, 0, 0]; let sorted = [0, 0, 0, 0, 0, 0]; let indexes = [0, 0, 0, 0, 0, 0]; @@ -267,7 +267,7 @@ fn assert_sorted_array_failed_wrong_index() { assert_sorted_array(original, sorted, indexes, |a: Field, b: Field| a.lt(b)); } -#[test(should_fail_with="Default values must be padded to the right")] +#[test(should_fail_with="Empty values must be padded to the right")] fn assert_sorted_array_failed_not_padded() { let original = [30, 20, 90, 0, 50, 0]; let sorted = [20, 30, 90, 0, 0, 0]; @@ -275,8 +275,8 @@ fn assert_sorted_array_failed_not_padded() { assert_sorted_array(original, sorted, indexes, |a: Field, b: Field| a.lt(b)); } -#[test(should_fail_with="Default values must not be mixed with sorted values")] -fn assert_sorted_array_failed_mixed_default() { +#[test(should_fail_with="Empty values must not be mixed with sorted values")] +fn assert_sorted_array_failed_mixed_empty() { let original = [30, 20, 90, 0, 0, 0]; let sorted = [20, 30, 90, 0, 0, 10]; let indexes = [1, 0, 2, 0, 0, 0];