From 4881414ceb30590674c244ef9bc4c8416eacd6bc Mon Sep 17 00:00:00 2001 From: Cody Gunton Date: Fri, 6 Oct 2023 23:05:35 -0400 Subject: [PATCH 1/4] feat: GCC 13 preset (#2623) Add a CMake preset for building with GCC 13. --- barretenberg/cpp/CMakePresets.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/barretenberg/cpp/CMakePresets.json b/barretenberg/cpp/CMakePresets.json index ec0889e64eb..0b43346e94a 100644 --- a/barretenberg/cpp/CMakePresets.json +++ b/barretenberg/cpp/CMakePresets.json @@ -89,6 +89,15 @@ } }, { + "name": "gcc13", + "displayName": "Build with GCC-13", + "description": "Build with globally installed GCC-13", + "inherits": "default", + "environment": { + "CC": "gcc-13", + "CXX": "g++-13" + } + }, { "name": "bench", "displayName": "Build benchmarks", "description": "Build default preset but with a special benchmark directory", @@ -212,6 +221,11 @@ "inherits": "default", "configurePreset": "gcc10" }, + { + "name": "gcc13", + "inherits": "default", + "configurePreset": "gcc13" + }, { "name": "bench", "inherits": "clang16", @@ -297,6 +311,11 @@ "inherits": "default", "configurePreset": "gcc10" }, + { + "name": "gcc13", + "inherits": "default", + "configurePreset": "gcc13" + }, { "name": "bench", "inherits": "clang16", From d9ae189bcee43a193d262d2e819c55966494cce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Rodr=C3=ADguez?= Date: Mon, 9 Oct 2023 10:45:13 +0200 Subject: [PATCH 2/4] chore: Add visibility modifiers (#2728) --- yarn-project/aztec-nr/authwit/src/account.nr | 14 ++-- yarn-project/aztec-nr/authwit/src/auth.nr | 10 +-- .../aztec-nr/authwit/src/auth_witness.nr | 2 +- yarn-project/aztec-nr/aztec/src/abi.nr | 30 +++---- yarn-project/aztec-nr/aztec/src/address.nr | 2 +- yarn-project/aztec-nr/aztec/src/context.nr | 84 +++++++++---------- yarn-project/aztec-nr/aztec/src/hash.nr | 4 +- yarn-project/aztec-nr/aztec/src/log.nr | 6 +- yarn-project/aztec-nr/aztec/src/messaging.nr | 2 +- .../aztec/src/messaging/l1_to_l2_message.nr | 6 +- .../messaging/l1_to_l2_message_getter_data.nr | 4 +- .../aztec-nr/aztec/src/note/lifecycle.nr | 6 +- .../aztec-nr/aztec/src/note/note_getter.nr | 6 +- .../aztec/src/note/note_getter_options.nr | 16 ++-- .../aztec-nr/aztec/src/note/note_hash.nr | 6 +- .../aztec-nr/aztec/src/note/note_header.nr | 4 +- .../aztec/src/note/note_viewer_options.nr | 10 +-- yarn-project/aztec-nr/aztec/src/note/utils.nr | 10 +-- .../aztec-nr/aztec/src/oracle/arguments.nr | 2 +- .../aztec/src/oracle/call_private_function.nr | 2 +- .../aztec-nr/aztec/src/oracle/context.nr | 2 +- .../aztec/src/oracle/create_commitment.nr | 2 +- .../aztec-nr/aztec/src/oracle/debug_log.nr | 8 +- .../oracle/enqueue_public_function_call.nr | 2 +- .../aztec/src/oracle/get_l1_to_l2_message.nr | 2 +- .../aztec/src/oracle/get_public_key.nr | 2 +- .../aztec/src/oracle/get_secret_key.nr | 2 +- .../aztec-nr/aztec/src/oracle/logs.nr | 4 +- .../aztec-nr/aztec/src/oracle/notes.nr | 8 +- .../aztec-nr/aztec/src/oracle/public_call.nr | 2 +- .../aztec-nr/aztec/src/oracle/rand.nr | 2 +- .../aztec-nr/aztec/src/oracle/storage.nr | 4 +- .../aztec/src/private_call_stack_item.nr | 2 +- .../aztec/src/public_call_stack_item.nr | 2 +- yarn-project/aztec-nr/aztec/src/selector.nr | 2 +- .../src/state_vars/immutable_singleton.nr | 10 +-- .../aztec-nr/aztec/src/state_vars/map.nr | 4 +- .../aztec/src/state_vars/public_state.nr | 6 +- .../aztec-nr/aztec/src/state_vars/set.nr | 12 +-- .../aztec/src/state_vars/singleton.nr | 14 ++-- .../aztec-nr/aztec/src/types/address.nr | 14 ++-- .../aztec-nr/aztec/src/types/point.nr | 2 +- yarn-project/aztec-nr/aztec/src/types/vec.nr | 14 ++-- yarn-project/aztec-nr/aztec/src/utils.nr | 4 +- .../src/easy_private_state.nr | 6 +- .../aztec-nr/safe-math/src/safe_u120.nr | 30 +++---- .../aztec-nr/value-note/src/balance_utils.nr | 4 +- .../aztec-nr/value-note/src/filter.nr | 2 +- yarn-project/aztec-nr/value-note/src/utils.nr | 12 +-- .../aztec-nr/value-note/src/value_note.nr | 12 +-- .../src/contract-interface-gen/noir.ts | 4 +- .../contracts/card_game_contract/src/cards.nr | 26 +++--- .../contracts/card_game_contract/src/game.nr | 14 ++-- .../src/account_contract_interface.nr | 4 +- .../docs_example_contract/src/actions.nr | 38 ++++----- .../docs_example_contract/src/options.nr | 10 +-- .../src/types/card_note.nr | 12 +-- .../src/types/profile_note.nr | 12 +-- .../src/types/rules_note.nr | 12 +-- .../src/ecdsa_public_key_note.nr | 8 +- .../escrow_contract/src/address_note.nr | 8 +- .../contracts/lending_contract/src/asset.nr | 2 +- .../contracts/lending_contract/src/helpers.nr | 8 +- .../lending_contract/src/interest_math.nr | 2 +- .../lending_contract/src/interfaces.nr | 20 ++--- .../non_native_token_contract/src/hash.nr | 4 +- .../src/interface.nr | 30 +++---- .../src/transparent_note.nr | 18 ++-- .../src/address_note.nr | 8 +- .../src/claim_note.nr | 12 +-- .../src/interface.nr | 16 ++-- .../private_token_contract/src/interface.nr | 8 +- .../src/public_key_note.nr | 8 +- .../src/auth_oracle.nr | 2 +- .../src/util.nr | 2 +- .../contracts/test_contract/src/interface.nr | 32 +++---- .../src/token_interface.nr | 10 +-- .../token_bridge_contract/src/util.nr | 6 +- .../token_contract/src/types/balance_set.nr | 12 +-- .../token_contract/src/types/balances_map.nr | 4 +- .../token_contract/src/types/token_note.nr | 14 ++-- .../src/types/transparent_note.nr | 16 ++-- .../uniswap_contract/src/interfaces.nr | 14 ++-- .../contracts/uniswap_contract/src/util.nr | 4 +- 84 files changed, 409 insertions(+), 409 deletions(-) diff --git a/yarn-project/aztec-nr/authwit/src/account.nr b/yarn-project/aztec-nr/authwit/src/account.nr index 28a982fd4d0..d2f541c5dff 100644 --- a/yarn-project/aztec-nr/authwit/src/account.nr +++ b/yarn-project/aztec-nr/authwit/src/account.nr @@ -13,7 +13,7 @@ struct AccountActions { } impl AccountActions { - fn init(context: Context, approved_action_storage_slot: Field, is_valid_impl: fn(&mut PrivateContext, Field) -> bool) -> Self { + pub fn init(context: Context, approved_action_storage_slot: Field, is_valid_impl: fn(&mut PrivateContext, Field) -> bool) -> Self { AccountActions { context: context, is_valid_impl: is_valid_impl, @@ -27,16 +27,16 @@ impl AccountActions { } } - fn private(context: &mut PrivateContext, approved_action_storage_slot: Field, is_valid_impl: fn(&mut PrivateContext, Field) -> bool) -> Self { + pub fn private(context: &mut PrivateContext, approved_action_storage_slot: Field, is_valid_impl: fn(&mut PrivateContext, Field) -> bool) -> Self { AccountActions::init(Context::private(context), approved_action_storage_slot, is_valid_impl) } - fn public(context: &mut PublicContext, approved_action_storage_slot: Field, is_valid_impl: fn(&mut PrivateContext, Field) -> bool) -> Self { + pub fn public(context: &mut PublicContext, approved_action_storage_slot: Field, is_valid_impl: fn(&mut PrivateContext, Field) -> bool) -> Self { AccountActions::init(Context::public(context), approved_action_storage_slot, is_valid_impl) } // docs:start:entrypoint - fn entrypoint(self, payload: EntrypointPayload) { + pub fn entrypoint(self, payload: EntrypointPayload) { let message_hash = payload.hash(); let valid_fn = self.is_valid_impl; let private_context = self.context.private.unwrap(); @@ -45,7 +45,7 @@ impl AccountActions { } // docs:end:entrypoint - fn is_valid(self, message_hash: Field) -> Field { + pub fn is_valid(self, message_hash: Field) -> Field { let valid_fn = self.is_valid_impl; if (valid_fn(self.context.private.unwrap(), message_hash)) { IS_VALID_SELECTOR @@ -54,7 +54,7 @@ impl AccountActions { } } - fn is_valid_public(self, message_hash: Field) -> Field { + pub fn is_valid_public(self, message_hash: Field) -> Field { let value = self.approved_action.at(message_hash).read(); if (value){ IS_VALID_SELECTOR @@ -63,7 +63,7 @@ impl AccountActions { } } - fn internal_set_is_valid_storage(self, message_hash: Field, value: bool) { + pub fn internal_set_is_valid_storage(self, message_hash: Field, value: bool) { self.approved_action.at(message_hash).write(value); } } \ No newline at end of file diff --git a/yarn-project/aztec-nr/authwit/src/auth.nr b/yarn-project/aztec-nr/authwit/src/auth.nr index 45adb83a6a0..751818587a3 100644 --- a/yarn-project/aztec-nr/authwit/src/auth.nr +++ b/yarn-project/aztec-nr/authwit/src/auth.nr @@ -13,35 +13,35 @@ global IS_VALID_PUBLIC_SELECTOR = 0xf3661153; // @todo #2676 Should use different generator than the payload to limit probability of collisions. // Assert that `whom` have authorized `message_hash` with a valid authentication witness -fn assert_valid_authwit(context: &mut PrivateContext, whom: AztecAddress, message_hash: Field) { +pub fn assert_valid_authwit(context: &mut PrivateContext, whom: AztecAddress, message_hash: Field) { let result = context.call_private_function(whom.address, IS_VALID_SELECTOR, [message_hash])[0]; context.push_new_nullifier(message_hash, EMPTY_NULLIFIED_COMMITMENT); assert(result == IS_VALID_SELECTOR, "Message not authorized by account"); } // Assert that `whom` have authorized the current call with a valid authentication witness -fn assert_current_call_valid_authwit(context: &mut PrivateContext, whom: AztecAddress) { +pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, whom: AztecAddress) { let args = [context.msg_sender(), context.this_address(), context.selector(), context.args_hash]; let message_hash = pedersen_with_separator(args, GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0]; assert_valid_authwit(context, whom, message_hash); } // Assert that `whom` have authorized `message_hash` in a public context -fn assert_valid_authwit_public(context: &mut PublicContext, whom: AztecAddress, message_hash: Field) { +pub fn assert_valid_authwit_public(context: &mut PublicContext, whom: AztecAddress, message_hash: Field) { let result = context.call_public_function(whom.address, IS_VALID_PUBLIC_SELECTOR, [message_hash])[0]; context.push_new_nullifier(message_hash, EMPTY_NULLIFIED_COMMITMENT); assert(result == IS_VALID_SELECTOR, "Message not authorized by account"); } // Assert that `whom` have authorized the current call in a public context -fn assert_current_call_valid_authwit_public(context: &mut PublicContext, whom: AztecAddress) { +pub fn assert_current_call_valid_authwit_public(context: &mut PublicContext, whom: AztecAddress) { let args = [context.msg_sender(), context.this_address(), context.selector(), context.args_hash]; let message_hash = pedersen_with_separator(args, GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0]; assert_valid_authwit_public(context, whom, message_hash); } // Compute the message hash to be used by an authentication witness -fn compute_authwit_message_hash(caller: AztecAddress, target: AztecAddress, selector: Field, args: [Field; N]) -> Field { +pub fn compute_authwit_message_hash(caller: AztecAddress, target: AztecAddress, selector: Field, args: [Field; N]) -> Field { let args_hash = hash_args(args); pedersen_with_separator([caller.address, target.address, selector, args_hash], GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0] } \ No newline at end of file diff --git a/yarn-project/aztec-nr/authwit/src/auth_witness.nr b/yarn-project/aztec-nr/authwit/src/auth_witness.nr index d3ee1bd132c..7ef0577f28e 100644 --- a/yarn-project/aztec-nr/authwit/src/auth_witness.nr +++ b/yarn-project/aztec-nr/authwit/src/auth_witness.nr @@ -1,6 +1,6 @@ #[oracle(getAuthWitness)] fn get_auth_witness_oracle(_message_hash: Field) -> [Field; N] {} -unconstrained fn get_auth_witness(message_hash: Field) -> [Field; N] { +unconstrained pub fn get_auth_witness(message_hash: Field) -> [Field; N] { get_auth_witness_oracle(message_hash) } \ No newline at end of file diff --git a/yarn-project/aztec-nr/aztec/src/abi.nr b/yarn-project/aztec-nr/aztec/src/abi.nr index f7936fc0985..916c6eafac4 100644 --- a/yarn-project/aztec-nr/aztec/src/abi.nr +++ b/yarn-project/aztec-nr/aztec/src/abi.nr @@ -153,7 +153,7 @@ struct HistoricBlockData { impl HistoricBlockData { // NOTE: this order must match the order in `private_circuit_public_inputs.hpp` - fn serialize(self) -> [Field; HISTORIC_BLOCK_DATA_LENGTH] { + pub fn serialize(self) -> [Field; HISTORIC_BLOCK_DATA_LENGTH] { [ self.private_data_tree_root, self.nullifier_tree_root, @@ -165,7 +165,7 @@ impl HistoricBlockData { ] } - fn empty() -> Self { + pub fn empty() -> Self { Self { private_data_tree_root: 0, nullifier_tree_root: 0, contract_tree_root: 0, l1_to_l2_messages_tree_root: 0, blocks_tree_root: 0, public_data_tree_root: 0, global_variables_hash: 0 } } } @@ -265,15 +265,15 @@ struct ContractStorageRead { } impl ContractStorageRead { - fn serialize(self) -> [Field; CONTRACT_STORAGE_READ_LENGTH] { + pub fn serialize(self) -> [Field; CONTRACT_STORAGE_READ_LENGTH] { [self.storage_slot, self.value] } - fn hash(self) -> Field { + pub fn hash(self) -> Field { dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__PUBLIC_DATA_READ)[0] } - fn empty() -> Self { + pub fn empty() -> Self { Self { storage_slot: 0, value: 0 } } } @@ -285,15 +285,15 @@ struct ContractStorageUpdateRequest { } impl ContractStorageUpdateRequest { - fn serialize(self) -> [Field; CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH] { + pub fn serialize(self) -> [Field; CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH] { [self.storage_slot, self.old_value, self.new_value] } - fn hash(self) -> Field { + pub fn hash(self) -> Field { dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST)[0] } - fn empty() -> Self { + pub fn empty() -> Self { Self { storage_slot: 0, old_value: 0, new_value: 0 } } } @@ -320,7 +320,7 @@ struct PublicCircuitPublicInputs { impl PublicCircuitPublicInputs { - fn hash(self) -> Field { + pub fn hash(self) -> Field { let mut inputs: BoundedVec = BoundedVec::new(0); inputs.push(self.call_context.hash()); inputs.push(self.args_hash); @@ -346,7 +346,7 @@ impl PublicCircuitPublicInputs { dep::std::hash::pedersen_with_separator(inputs.storage, GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS)[0] } - fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] { + pub fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(0); fields.push_array(self.call_context.serialize()); fields.push(self.args_hash); @@ -374,21 +374,21 @@ struct Hasher { } impl Hasher { - fn new()-> Self { + pub fn new()-> Self { Self { fields: [] } } - fn add(&mut self, field: Field) { + pub fn add(&mut self, field: Field) { self.fields = self.fields.push_back(field); } - fn add_multiple(&mut self, fields: [Field; N]) { + pub fn add_multiple(&mut self, fields: [Field; N]) { for i in 0..N { self.fields = self.fields.push_back(fields[i]); } } - fn hash(self) -> Field { + pub fn hash(self) -> Field { hash_args(self.fields) } } @@ -396,7 +396,7 @@ impl Hasher { global ARGS_HASH_CHUNK_LENGTH: u32 = 32; global ARGS_HASH_CHUNK_COUNT: u32 = 16; -fn hash_args(args: [Field; N]) -> Field { +pub fn hash_args(args: [Field; N]) -> Field { if args.len() == 0 { 0 } else { diff --git a/yarn-project/aztec-nr/aztec/src/address.nr b/yarn-project/aztec-nr/aztec/src/address.nr index 6d0767741ce..1cb0ed933bc 100644 --- a/yarn-project/aztec-nr/aztec/src/address.nr +++ b/yarn-project/aztec-nr/aztec/src/address.nr @@ -1,6 +1,6 @@ use dep::std::hash; use crate::constants_gen::GENERATOR_INDEX__CONTRACT_ADDRESS; -fn compute_address(pub_key_x: Field, pub_key_y: Field, partial_address: Field) -> Field { +pub fn compute_address(pub_key_x: Field, pub_key_y: Field, partial_address: Field) -> Field { hash::pedersen_with_separator([pub_key_x, pub_key_y, partial_address], GENERATOR_INDEX__CONTRACT_ADDRESS)[0] } \ No newline at end of file diff --git a/yarn-project/aztec-nr/aztec/src/context.nr b/yarn-project/aztec-nr/aztec/src/context.nr index 3acda3e2a8e..68d378123a8 100644 --- a/yarn-project/aztec-nr/aztec/src/context.nr +++ b/yarn-project/aztec-nr/aztec/src/context.nr @@ -76,7 +76,7 @@ struct PrivateContext { } impl PrivateContext { - fn new(inputs: abi::PrivateContextInputs, args_hash: Field) -> PrivateContext { + pub fn new(inputs: abi::PrivateContextInputs, args_hash: Field) -> PrivateContext { PrivateContext { inputs: inputs, @@ -101,31 +101,31 @@ impl PrivateContext { } } - fn msg_sender(self) -> Field { + pub fn msg_sender(self) -> Field { self.inputs.call_context.msg_sender } - fn this_address(self) -> Field { + pub fn this_address(self) -> Field { self.inputs.call_context.storage_contract_address } - fn this_portal_address(self) -> Field { + pub fn this_portal_address(self) -> Field { self.inputs.call_context.portal_contract_address } - fn chain_id(self) -> Field { + pub fn chain_id(self) -> Field { self.inputs.private_global_variables.chain_id } - fn version(self) -> Field { + pub fn version(self) -> Field { self.inputs.private_global_variables.version } - fn selector(self) -> Field { + pub fn selector(self) -> Field { self.inputs.call_context.function_selector } - fn finish(self) -> abi::PrivateCircuitPublicInputs { + pub fn finish(self) -> abi::PrivateCircuitPublicInputs { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) let encrypted_logs_hash = [0; NUM_FIELDS_PER_SHA256]; let unencrypted_logs_hash = [0; NUM_FIELDS_PER_SHA256]; @@ -155,18 +155,18 @@ impl PrivateContext { priv_circuit_pub_inputs } - fn push_read_request(&mut self, read_request: Field) { + pub fn push_read_request(&mut self, read_request: Field) { self.read_requests.push(read_request); } - fn push_new_note_hash(&mut self, note_hash: Field) { + pub fn push_new_note_hash(&mut self, note_hash: Field) { self.new_commitments.push(note_hash); } // We never push a zero nullified_commitment as zero is used to indicate the end // of a field array in private kernel. This routine transparently replaces a // zero value into the special placeholder: EMPTY_NULLIFIED_COMMITMENT. - fn push_new_nullifier(&mut self, nullifier: Field, nullified_commitment: Field) { + pub fn push_new_nullifier(&mut self, nullifier: Field, nullified_commitment: Field) { self.new_nullifiers.push(nullifier); let mut non_zero_nullified = nullified_commitment; if (non_zero_nullified == 0) { @@ -176,7 +176,7 @@ impl PrivateContext { } // docs:start:context_message_portal - fn message_portal(&mut self, content: Field) + pub fn message_portal(&mut self, content: Field) // docs:end:context_message_portal { self.new_l2_to_l1_msgs.push(content); @@ -186,7 +186,7 @@ impl PrivateContext { // Note this returns self to get around an issue where mutable structs do not maintain mutations unless reassigned // docs:start:context_consume_l1_to_l2_message // docs:start:consume_l1_to_l2_message - fn consume_l1_to_l2_message( + pub fn consume_l1_to_l2_message( &mut self, msg_key: Field, content: Field, @@ -201,19 +201,19 @@ impl PrivateContext { } // docs:end:consume_l1_to_l2_message - fn accumulate_encrypted_logs(&mut self, log: [Field; N]) { + pub fn accumulate_encrypted_logs(&mut self, log: [Field; N]) { let _void1 = self.inputs; let _void2 = log; // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) } - fn accumulate_unencrypted_logs(&mut self, log: T) { + pub fn accumulate_unencrypted_logs(&mut self, log: T) { let _void1 = self.inputs; let _void2 = log; // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) } - fn call_private_function( + pub fn call_private_function( &mut self, contract_address: Field, function_selector: Field, @@ -224,7 +224,7 @@ impl PrivateContext { self.call_private_function_with_packed_args(contract_address, function_selector, args_hash) } - fn call_private_function_no_args( + pub fn call_private_function_no_args( &mut self, contract_address: Field, function_selector: Field, @@ -232,7 +232,7 @@ impl PrivateContext { self.call_private_function_with_packed_args(contract_address, function_selector, 0) } - fn call_private_function_with_packed_args( + pub fn call_private_function_with_packed_args( &mut self, contract_address: Field, function_selector: Field, @@ -319,7 +319,7 @@ impl PrivateContext { item.public_inputs.return_values } - fn call_public_function( + pub fn call_public_function( &mut self, contract_address: Field, function_selector: Field, @@ -330,7 +330,7 @@ impl PrivateContext { self.call_public_function_with_packed_args(contract_address, function_selector, args_hash) } - fn call_public_function_no_args( + pub fn call_public_function_no_args( &mut self, contract_address: Field, function_selector: Field, @@ -338,7 +338,7 @@ impl PrivateContext { self.call_public_function_with_packed_args(contract_address, function_selector, 0) } - fn call_public_function_with_packed_args( + pub fn call_public_function_with_packed_args( &mut self, contract_address: Field, function_selector: Field, @@ -430,7 +430,7 @@ struct PublicContext { } impl PublicContext { - fn new(inputs: abi::PublicContextInputs, args_hash: Field) -> PublicContext { + pub fn new(inputs: abi::PublicContextInputs, args_hash: Field) -> PublicContext { let empty_storage_read = ContractStorageRead::empty(); let empty_storage_update = ContractStorageUpdateRequest::empty(); PublicContext { @@ -461,39 +461,39 @@ impl PublicContext { } } - fn msg_sender(self) -> Field { + pub fn msg_sender(self) -> Field { self.inputs.call_context.msg_sender } - fn this_address(self) -> Field { + pub fn this_address(self) -> Field { self.inputs.call_context.storage_contract_address } - fn this_portal_address(self) -> Field { + pub fn this_portal_address(self) -> Field { self.inputs.call_context.portal_contract_address } - fn chain_id(self) -> Field { + pub fn chain_id(self) -> Field { self.inputs.public_global_variables.chain_id } - fn version(self) -> Field { + pub fn version(self) -> Field { self.inputs.public_global_variables.version } - fn selector(self) -> Field { + pub fn selector(self) -> Field { self.inputs.call_context.function_selector } - fn block_number(self) -> Field { + pub fn block_number(self) -> Field { self.inputs.public_global_variables.block_number } - fn timestamp(self) -> Field { + pub fn timestamp(self) -> Field { self.inputs.public_global_variables.timestamp } - fn finish(self) -> abi::PublicCircuitPublicInputs { + pub fn finish(self) -> abi::PublicCircuitPublicInputs { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) let unencrypted_logs_hash = [0; NUM_FIELDS_PER_SHA256]; let unencrypted_log_preimages_length = 0; @@ -518,21 +518,21 @@ impl PublicContext { pub_circuit_pub_inputs } - fn push_new_note_hash(&mut self, note_hash: Field) { + pub fn push_new_note_hash(&mut self, note_hash: Field) { self.new_commitments.push(note_hash); } - fn push_new_nullifier(&mut self, nullifier: Field, _nullified_commitment: Field) { + pub fn push_new_nullifier(&mut self, nullifier: Field, _nullified_commitment: Field) { self.new_nullifiers.push(nullifier); } - fn message_portal(&mut self, content: Field) { + pub fn message_portal(&mut self, content: Field) { self.new_l2_to_l1_msgs.push(content); } // PrivateContextInputs must be temporarily passed in to prevent too many unknowns // Note this returns self to get around an issue where mutable structs do not maintain mutations unless reassigned - fn consume_l1_to_l2_message(&mut self, msg_key: Field, content: Field, secret: Field) { + pub fn consume_l1_to_l2_message(&mut self, msg_key: Field, content: Field, secret: Field) { let this = (*self).this_address(); let nullifier = process_l1_to_l2_message(self.block_data.l1_to_l2_messages_tree_root, this, msg_key, content, secret); @@ -540,19 +540,19 @@ impl PublicContext { self.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT) } - fn accumulate_encrypted_logs(&mut self, log: [Field; N]) { + pub fn accumulate_encrypted_logs(&mut self, log: [Field; N]) { let _void1 = self; let _void2 = log; // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) } - fn accumulate_unencrypted_logs(&mut self, log: T) { + pub fn accumulate_unencrypted_logs(&mut self, log: T) { let _void1 = self; let _void2 = log; // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) } - fn call_public_function( + pub fn call_public_function( _self: Self, contract_address: Field, function_selector: Field, @@ -567,7 +567,7 @@ impl PublicContext { ) } - fn call_public_function_no_args( + pub fn call_public_function_no_args( _self: Self, contract_address: Field, function_selector: Field, @@ -587,21 +587,21 @@ struct Context { } impl Context { - fn private(context: &mut PrivateContext) -> Context { + pub fn private(context: &mut PrivateContext) -> Context { Context { private: Option::some(context), public: Option::none() } } - fn public(context: &mut PublicContext) -> Context { + pub fn public(context: &mut PublicContext) -> Context { Context { public: Option::some(context), private: Option::none() } } - fn none() -> Context { + pub fn none() -> Context { Context { public: Option::none(), private: Option::none() diff --git a/yarn-project/aztec-nr/aztec/src/hash.nr b/yarn-project/aztec-nr/aztec/src/hash.nr index 9ddcb02c533..5e528af3438 100644 --- a/yarn-project/aztec-nr/aztec/src/hash.nr +++ b/yarn-project/aztec-nr/aztec/src/hash.nr @@ -4,7 +4,7 @@ use crate::constants_gen::{ GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET, }; -fn sha256_to_field(bytes_to_hash: [u8; N]) -> Field { +pub fn sha256_to_field(bytes_to_hash: [u8; N]) -> Field { let sha256_hashed = sha256(bytes_to_hash); // Convert it to a field element @@ -24,7 +24,7 @@ fn sha256_to_field(bytes_to_hash: [u8; N]) -> Field { hash_in_a_field } -fn compute_secret_hash(secret: Field) -> Field { +pub fn compute_secret_hash(secret: Field) -> Field { // TODO(#1205) This is probably not the right index to use pedersen_with_separator([secret], GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET)[0] } \ No newline at end of file diff --git a/yarn-project/aztec-nr/aztec/src/log.nr b/yarn-project/aztec-nr/aztec/src/log.nr index 1c483b76702..d38775dcb72 100644 --- a/yarn-project/aztec-nr/aztec/src/log.nr +++ b/yarn-project/aztec-nr/aztec/src/log.nr @@ -2,7 +2,7 @@ use crate::context::{PrivateContext, PublicContext}; use crate::oracle; use crate::types::point::Point; -fn emit_encrypted_log( +pub fn emit_encrypted_log( context: &mut PrivateContext, contract_address: Field, storage_slot: Field, @@ -13,7 +13,7 @@ fn emit_encrypted_log( context.accumulate_encrypted_logs(log); } -fn emit_unencrypted_log( +pub fn emit_unencrypted_log( context: &mut PublicContext, log: T, ) { @@ -27,7 +27,7 @@ fn emit_unencrypted_log( // --> might be a better approach to force devs to make a public function call that emits the log if needed then // it would be less easy to accidentally leak information. // If we decide to keep this function around would make sense to wait for traits and then merge it with emit_unencrypted_log. -fn emit_unencrypted_log_from_private( +pub fn emit_unencrypted_log_from_private( context: &mut PrivateContext, log: T, ) { diff --git a/yarn-project/aztec-nr/aztec/src/messaging.nr b/yarn-project/aztec-nr/aztec/src/messaging.nr index 8f41c29c943..7e7aeae4500 100644 --- a/yarn-project/aztec-nr/aztec/src/messaging.nr +++ b/yarn-project/aztec-nr/aztec/src/messaging.nr @@ -8,7 +8,7 @@ use crate::oracle::get_l1_to_l2_message::get_l1_to_l2_message_call; // Returns the nullifier for the message -fn process_l1_to_l2_message(l1_to_l2_root: Field, storage_contract_address: Field, msg_key: Field, content: Field, secret: Field) -> Field{ +pub fn process_l1_to_l2_message(l1_to_l2_root: Field, storage_contract_address: Field, msg_key: Field, content: Field, secret: Field) -> Field{ let returned_message = get_l1_to_l2_message_call(msg_key); let l1_to_l2_message_data = make_l1_to_l2_message_getter_data(returned_message, 0, secret); diff --git a/yarn-project/aztec-nr/aztec/src/messaging/l1_to_l2_message.nr b/yarn-project/aztec-nr/aztec/src/messaging/l1_to_l2_message.nr index 8ac1a932490..9762bfc341e 100644 --- a/yarn-project/aztec-nr/aztec/src/messaging/l1_to_l2_message.nr +++ b/yarn-project/aztec-nr/aztec/src/messaging/l1_to_l2_message.nr @@ -19,7 +19,7 @@ struct L1ToL2Message { } impl L1ToL2Message { - fn deserialize( + pub fn deserialize( fields: [Field; L1_TO_L2_MESSAGE_LENGTH], secret: Field, tree_index: Field @@ -38,7 +38,7 @@ impl L1ToL2Message { } } - fn validate_message_secret(self: Self) { + pub fn validate_message_secret(self: Self) { let recomputed_hash = dep::std::hash::pedersen_with_separator([self.secret], GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET)[0]; assert(self.secret_hash == recomputed_hash); } @@ -71,7 +71,7 @@ impl L1ToL2Message { // The nullifier of a l1 to l2 message is the hash of the message salted with the secret and tree index // docs:start:l1_to_l2_message_compute_nullifier - fn compute_nullifier(self: Self) -> Field { + pub fn compute_nullifier(self: Self) -> Field { let message_hash = self.message_hash(); dep::std::hash::pedersen_with_separator([message_hash, self.secret, self.tree_index], GENERATOR_INDEX__NULLIFIER)[0] } diff --git a/yarn-project/aztec-nr/aztec/src/messaging/l1_to_l2_message_getter_data.nr b/yarn-project/aztec-nr/aztec/src/messaging/l1_to_l2_message_getter_data.nr index 70ae8137ae8..c8bd586e053 100644 --- a/yarn-project/aztec-nr/aztec/src/messaging/l1_to_l2_message_getter_data.nr +++ b/yarn-project/aztec-nr/aztec/src/messaging/l1_to_l2_message_getter_data.nr @@ -12,11 +12,11 @@ struct L1ToL2MessageGetterData { root: Field, } -fn l1_to_l2_message_getter_len() -> Field { +pub fn l1_to_l2_message_getter_len() -> Field { L1_TO_L2_MESSAGE_LENGTH + 1 + L1_TO_L2_MSG_TREE_HEIGHT + 1 } -fn make_l1_to_l2_message_getter_data(fields: [Field; N], start: Field, secret: Field) -> L1ToL2MessageGetterData { +pub fn make_l1_to_l2_message_getter_data(fields: [Field; N], start: Field, secret: Field) -> L1ToL2MessageGetterData { L1ToL2MessageGetterData { message: L1ToL2Message::deserialize(arr_copy_slice(fields, [0; L1_TO_L2_MESSAGE_LENGTH], start), secret, fields[start + L1_TO_L2_MESSAGE_LENGTH]), leaf_index: fields[start + L1_TO_L2_MESSAGE_LENGTH], diff --git a/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr b/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr index 6df1ef8ad58..bc15b4dec4a 100644 --- a/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr +++ b/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr @@ -12,7 +12,7 @@ use crate::note::{ use crate::oracle::notes::{notify_created_note, notify_nullified_note}; use crate::constants_gen::EMPTY_NULLIFIED_COMMITMENT; -fn create_note( +pub fn create_note( context: &mut PrivateContext, storage_slot: Field, note: &mut Note, @@ -32,7 +32,7 @@ fn create_note( context.push_new_note_hash(inner_note_hash); } -fn create_note_hash_from_public( +pub fn create_note_hash_from_public( context: &mut PublicContext, storage_slot: Field, note: &mut Note, @@ -48,7 +48,7 @@ fn create_note_hash_from_public( context.push_new_note_hash(inner_note_hash); } -fn destroy_note( +pub fn destroy_note( context: &mut PrivateContext, note: Note, note_interface: NoteInterface, diff --git a/yarn-project/aztec-nr/aztec/src/note/note_getter.nr b/yarn-project/aztec-nr/aztec/src/note/note_getter.nr index cfac7ed9986..1ed8b14830d 100644 --- a/yarn-project/aztec-nr/aztec/src/note/note_getter.nr +++ b/yarn-project/aztec-nr/aztec/src/note/note_getter.nr @@ -52,7 +52,7 @@ fn check_notes_order(fields_0: [Field; N], fields_1: [Field; N], sorts: Bound } } -fn get_note( +pub fn get_note( context: &mut PrivateContext, storage_slot: Field, note_interface: NoteInterface, @@ -67,7 +67,7 @@ fn get_note( note } -fn get_notes( +pub fn get_notes( context: &mut PrivateContext, storage_slot: Field, note_interface: NoteInterface, @@ -151,7 +151,7 @@ unconstrained fn get_notes_internal( filter(opt_notes, filter_args) } -unconstrained fn view_notes( +unconstrained pub fn view_notes( storage_slot: Field, note_interface: NoteInterface, options: NoteViewerOptions, diff --git a/yarn-project/aztec-nr/aztec/src/note/note_getter_options.nr b/yarn-project/aztec-nr/aztec/src/note/note_getter_options.nr index d8905b2452e..c43fd996850 100644 --- a/yarn-project/aztec-nr/aztec/src/note/note_getter_options.nr +++ b/yarn-project/aztec-nr/aztec/src/note/note_getter_options.nr @@ -8,7 +8,7 @@ struct Select { } impl Select { - fn new(field_index: u8, value: Field) -> Self { + pub fn new(field_index: u8, value: Field) -> Self { Select { field_index, value } } } @@ -29,7 +29,7 @@ struct Sort { } impl Sort { - fn new(field_index: u8, order: u2) -> Self { + pub fn new(field_index: u8, order: u2) -> Self { Sort { field_index, order } } } @@ -55,7 +55,7 @@ struct NoteGetterOptions { // And finally, a custom filter to refine the outcome further. impl NoteGetterOptions { // This function initializes a NoteGetterOptions that simply returns the maximum number of notes allowed in a call. - fn new() -> NoteGetterOptions { + pub fn new() -> NoteGetterOptions { NoteGetterOptions { selects: BoundedVec::new(Option::none()), sorts: BoundedVec::new(Option::none()), @@ -68,7 +68,7 @@ impl NoteGetterOptions { // This function initializes a NoteGetterOptions with a filter, which takes the notes returned from the database and filter_args as its parameters. // `filter_args` allows you to provide additional data or context to the custom filter. - fn with_filter( + pub fn with_filter( filter: fn ([Option; MAX_READ_REQUESTS_PER_CALL], FILTER_ARGS) -> [Option; MAX_READ_REQUESTS_PER_CALL], filter_args: FILTER_ARGS, ) -> Self { @@ -84,27 +84,27 @@ impl NoteGetterOptions { // This method adds a `Select` criterion to the options. // It takes a field_index indicating which field to select and a value representing the specific value to match in that field. - fn select(&mut self, field_index: u8, value: Field) -> Self { + pub fn select(&mut self, field_index: u8, value: Field) -> Self { self.selects.push(Option::some(Select::new(field_index, value))); *self } // This method adds a `Sort` criterion to the options. // It takes a field_index indicating which field to sort by and an order (SortOrder) to determine the sorting direction. - fn sort(&mut self, field_index: u8, order: u2) -> Self { + pub fn sort(&mut self, field_index: u8, order: u2) -> Self { self.sorts.push(Option::some(Sort::new(field_index, order))); *self } // This method lets you set a limit for the maximum number of notes to be retrieved in a single query result. - fn set_limit(&mut self, limit: u32) -> Self { + pub fn set_limit(&mut self, limit: u32) -> Self { assert(limit <= MAX_READ_REQUESTS_PER_CALL as u32); self.limit = limit; *self } // This method sets the offset value, which determines where to start retrieving notes in the query results. - fn set_offset(&mut self, offset: u32) -> Self { + pub fn set_offset(&mut self, offset: u32) -> Self { self.offset = offset; *self } diff --git a/yarn-project/aztec-nr/aztec/src/note/note_hash.nr b/yarn-project/aztec-nr/aztec/src/note/note_hash.nr index 8b507a404f9..5c28cca9273 100644 --- a/yarn-project/aztec-nr/aztec/src/note/note_hash.nr +++ b/yarn-project/aztec-nr/aztec/src/note/note_hash.nr @@ -1,17 +1,17 @@ use dep::std::hash::{pedersen, pedersen_with_separator}; use crate::constants_gen::{GENERATOR_INDEX__UNIQUE_COMMITMENT, GENERATOR_INDEX__SILOED_COMMITMENT}; -fn compute_inner_hash(storage_slot: Field, note_hash: Field) -> Field { +pub fn compute_inner_hash(storage_slot: Field, note_hash: Field) -> Field { // TODO(#1205) Do we need a generator index here? pedersen([storage_slot, note_hash])[0] } -fn compute_siloed_hash(contract_address: Field, inner_note_hash: Field) -> Field { +pub fn compute_siloed_hash(contract_address: Field, inner_note_hash: Field) -> Field { let inputs = [contract_address, inner_note_hash]; pedersen_with_separator(inputs, GENERATOR_INDEX__SILOED_COMMITMENT)[0] } -fn compute_unique_hash(nonce: Field, siloed_note_hash: Field) -> Field { +pub fn compute_unique_hash(nonce: Field, siloed_note_hash: Field) -> Field { let inputs = [nonce, siloed_note_hash]; pedersen_with_separator(inputs, GENERATOR_INDEX__UNIQUE_COMMITMENT)[0] } diff --git a/yarn-project/aztec-nr/aztec/src/note/note_header.nr b/yarn-project/aztec-nr/aztec/src/note/note_header.nr index 66ba4e9261d..6f82cebf149 100644 --- a/yarn-project/aztec-nr/aztec/src/note/note_header.nr +++ b/yarn-project/aztec-nr/aztec/src/note/note_header.nr @@ -8,11 +8,11 @@ struct NoteHeader { } impl NoteHeader { - fn new(contract_address: Field, nonce: Field, storage_slot: Field) -> Self { + pub fn new(contract_address: Field, nonce: Field, storage_slot: Field) -> Self { NoteHeader { contract_address, nonce, storage_slot, is_transient: false } } - fn empty() -> Self { + pub fn empty() -> Self { NoteHeader { contract_address: 0, nonce: 0, storage_slot: 0, is_transient: false } } } \ No newline at end of file diff --git a/yarn-project/aztec-nr/aztec/src/note/note_viewer_options.nr b/yarn-project/aztec-nr/aztec/src/note/note_viewer_options.nr index b4ce1a9a6a6..709237c4437 100644 --- a/yarn-project/aztec-nr/aztec/src/note/note_viewer_options.nr +++ b/yarn-project/aztec-nr/aztec/src/note/note_viewer_options.nr @@ -13,7 +13,7 @@ struct NoteViewerOptions { // docs:end:NoteViewerOptions impl NoteViewerOptions { - fn new() -> NoteViewerOptions { + pub fn new() -> NoteViewerOptions { NoteViewerOptions { selects: BoundedVec::new(Option::none()), sorts: BoundedVec::new(Option::none()), @@ -22,23 +22,23 @@ impl NoteViewerOptions { } } - fn select(&mut self, field_index: u8, value: Field) -> Self { + pub fn select(&mut self, field_index: u8, value: Field) -> Self { self.selects.push(Option::some(Select::new(field_index, value))); *self } - fn sort(&mut self, field_index: u8, order: u2) -> Self { + pub fn sort(&mut self, field_index: u8, order: u2) -> Self { self.sorts.push(Option::some(Sort::new(field_index, order))); *self } - fn set_limit(&mut self, limit: u32) -> Self { + pub fn set_limit(&mut self, limit: u32) -> Self { assert(limit <= MAX_NOTES_PER_PAGE as u32); self.limit = limit; *self } - fn set_offset(&mut self, offset: u32) -> Self { + pub fn set_offset(&mut self, offset: u32) -> Self { self.offset = offset; *self } diff --git a/yarn-project/aztec-nr/aztec/src/note/utils.nr b/yarn-project/aztec-nr/aztec/src/note/utils.nr index 8750cab7d05..115ba675237 100644 --- a/yarn-project/aztec-nr/aztec/src/note/utils.nr +++ b/yarn-project/aztec-nr/aztec/src/note/utils.nr @@ -5,7 +5,7 @@ use crate::note::{ }; use crate::utils::arr_copy_slice; -fn compute_inner_note_hash( +pub fn compute_inner_note_hash( note_interface: NoteInterface, note: Note, ) -> Field { @@ -18,7 +18,7 @@ fn compute_inner_note_hash( compute_inner_hash(header.storage_slot, note_hash) } -fn compute_siloed_note_hash( +pub fn compute_siloed_note_hash( note_interface: NoteInterface, note_with_header: Note, ) -> Field { @@ -30,7 +30,7 @@ fn compute_siloed_note_hash( compute_siloed_hash(header.contract_address, inner_note_hash) } -fn compute_unique_siloed_note_hash( +pub fn compute_unique_siloed_note_hash( note_interface: NoteInterface, note_with_header: Note, ) -> Field { @@ -42,7 +42,7 @@ fn compute_unique_siloed_note_hash( compute_unique_hash(header.nonce, siloed_note_hash) } -fn compute_note_hash_for_read_or_nullify( +pub fn compute_note_hash_for_read_or_nullify( note_interface: NoteInterface, note_with_header: Note, ) -> Field { @@ -66,7 +66,7 @@ fn compute_note_hash_for_read_or_nullify( } -fn compute_note_hash_and_nullifier( +pub fn compute_note_hash_and_nullifier( note_interface: NoteInterface, note_header: NoteHeader, preimage: [Field; S], diff --git a/yarn-project/aztec-nr/aztec/src/oracle/arguments.nr b/yarn-project/aztec-nr/aztec/src/oracle/arguments.nr index b8ab424835c..f5bd2831291 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/arguments.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/arguments.nr @@ -2,6 +2,6 @@ fn pack_arguments_oracle(_args: [Field; N]) -> Field {} // TODO: explain what this does. -unconstrained fn pack_arguments(args: [Field; N]) -> Field { +unconstrained pub fn pack_arguments(args: [Field; N]) -> Field { pack_arguments_oracle(args) } diff --git a/yarn-project/aztec-nr/aztec/src/oracle/call_private_function.nr b/yarn-project/aztec-nr/aztec/src/oracle/call_private_function.nr index 86aa18079e6..13a9e5f24c5 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/call_private_function.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/call_private_function.nr @@ -7,7 +7,7 @@ fn call_private_function_oracle( _args_hash: Field ) -> [Field; CALL_PRIVATE_FUNCTION_RETURN_SIZE] {} -unconstrained fn call_private_function_internal( +unconstrained pub fn call_private_function_internal( contract_address: Field, function_selector: Field, args_hash: Field diff --git a/yarn-project/aztec-nr/aztec/src/oracle/context.nr b/yarn-project/aztec-nr/aztec/src/oracle/context.nr index 1b70c476d9a..8200f9fe18a 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/context.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/context.nr @@ -1,7 +1,7 @@ #[oracle(getPortalContractAddress)] fn _get_portal_address(_contract_address: Field) -> Field {} -unconstrained fn get_portal_address(contract_address: Field) -> Field { +unconstrained pub fn get_portal_address(contract_address: Field) -> Field { let portal_address = _get_portal_address(contract_address); portal_address } \ No newline at end of file diff --git a/yarn-project/aztec-nr/aztec/src/oracle/create_commitment.nr b/yarn-project/aztec-nr/aztec/src/oracle/create_commitment.nr index 2e72a633e31..4f9b99cf716 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/create_commitment.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/create_commitment.nr @@ -2,6 +2,6 @@ #[oracle(createCommitment)] fn create_commitment_oracle(_commitment: Field) -> Field {} -unconstrained fn create_commitment(commitment: Field) { +unconstrained pub fn create_commitment(commitment: Field) { assert(create_commitment_oracle(commitment) == 0); } diff --git a/yarn-project/aztec-nr/aztec/src/oracle/debug_log.nr b/yarn-project/aztec-nr/aztec/src/oracle/debug_log.nr index 5be0cc39ffc..f18c6a341ea 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/debug_log.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/debug_log.nr @@ -15,7 +15,7 @@ fn debug_log_array_with_prefix_oracle(_prefix: S, _arbitrary_array: [T; /// NOTE: call this with a str msg of length > 1 /// Example: /// `debug_log("blah blah this is a debug string");` -unconstrained fn debug_log(msg: T) { +unconstrained pub fn debug_log(msg: T) { assert(debug_log_oracle(msg, 0) == 0); } @@ -25,13 +25,13 @@ unconstrained fn debug_log(msg: T) { /// into the string in the simulator. /// Example: /// debug_log_format("get_2(slot:{0}) =>\n\t0:{1}\n\t1:{2}", [storage_slot, note0_hash, note1_hash]); -unconstrained fn debug_log_format(msg: T, args: [Field; N]) { +unconstrained pub fn debug_log_format(msg: T, args: [Field; N]) { assert(debug_log_format_oracle(msg, args, args.len()) == 0); } /// Example: /// `debug_log_field(my_field);` -unconstrained fn debug_log_field(field: Field) { +unconstrained pub fn debug_log_field(field: Field) { assert(debug_log_field_oracle(field) == 0); } @@ -43,6 +43,6 @@ unconstrained fn debug_log_array(arbitrary_array: [T; N]) { /// Example: /// `debug_log_array_with_prefix("Prefix", my_array);` -unconstrained fn debug_log_array_with_prefix(prefix: S, arbitrary_array: [T; N]) { +unconstrained pub fn debug_log_array_with_prefix(prefix: S, arbitrary_array: [T; N]) { assert(debug_log_array_with_prefix_oracle(prefix, arbitrary_array) == 0); } diff --git a/yarn-project/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr b/yarn-project/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr index 994909633fb..17ea7f2f67b 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr @@ -13,7 +13,7 @@ fn enqueue_public_function_call_oracle( _args_hash: Field, ) -> [Field; ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE] {} -unconstrained fn enqueue_public_function_call_internal( +unconstrained pub fn enqueue_public_function_call_internal( contract_address: Field, function_selector: Field, args_hash: Field diff --git a/yarn-project/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr b/yarn-project/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr index 6ed3ad7fd8a..32a1f0e719d 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr @@ -5,6 +5,6 @@ use crate::constants_gen::L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH; #[oracle(getL1ToL2Message)] fn get_l1_to_l2_msg_oracle(_msg_key: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] {} -unconstrained fn get_l1_to_l2_message_call(msg_key: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] { +unconstrained pub fn get_l1_to_l2_message_call(msg_key: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] { get_l1_to_l2_msg_oracle(msg_key) } \ No newline at end of file diff --git a/yarn-project/aztec-nr/aztec/src/oracle/get_public_key.nr b/yarn-project/aztec-nr/aztec/src/oracle/get_public_key.nr index 42d1080da6d..f98d0dfb53e 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/get_public_key.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/get_public_key.nr @@ -8,7 +8,7 @@ unconstrained fn get_public_key_internal(address: Field) -> [Field; 3] { get_public_key_oracle(address) } -fn get_public_key(address: Field) -> Point { +pub fn get_public_key(address: Field) -> Point { let result = get_public_key_internal(address); let pub_key_x = result[0]; let pub_key_y = result[1]; diff --git a/yarn-project/aztec-nr/aztec/src/oracle/get_secret_key.nr b/yarn-project/aztec-nr/aztec/src/oracle/get_secret_key.nr index 2ffa3ece98a..4ec21bcf5e8 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/get_secret_key.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/get_secret_key.nr @@ -11,7 +11,7 @@ unconstrained fn get_secret_key_internal(owner_public_key: Point) -> dep::std::g dep::std::grumpkin_scalar::deserialize_grumpkin_scalar(get_secret_key_oracle(owner_public_key)) } -fn get_secret_key(owner: Field) -> dep::std::grumpkin_scalar::GrumpkinScalar { +pub fn get_secret_key(owner: Field) -> dep::std::grumpkin_scalar::GrumpkinScalar { let owner_public_key = get_public_key(owner); let secret = get_secret_key_internal(owner_public_key); diff --git a/yarn-project/aztec-nr/aztec/src/oracle/logs.nr b/yarn-project/aztec-nr/aztec/src/oracle/logs.nr index c5cf55724ad..bc658e67bdd 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/logs.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/logs.nr @@ -10,7 +10,7 @@ fn emit_encrypted_log_oracle( _preimage: [Field; N], ) -> Field {} -unconstrained fn emit_encrypted_log( +unconstrained pub fn emit_encrypted_log( contract_address: Field, storage_slot: Field, encryption_pub_key: Point, @@ -27,7 +27,7 @@ unconstrained fn emit_encrypted_log( #[oracle(emitUnencryptedLog)] fn emit_unencrypted_log_oracle(_contract_address: Field, _event_selector: Field, _message: T) -> Field {} -unconstrained fn emit_unencrypted_log(contract_address: Field, event_selector: Field, message: T) -> [Field; NUM_FIELDS_PER_SHA256] { +unconstrained pub fn emit_unencrypted_log(contract_address: Field, event_selector: Field, message: T) -> [Field; NUM_FIELDS_PER_SHA256] { // https://github.com/AztecProtocol/aztec-packages/issues/885 [emit_unencrypted_log_oracle(contract_address, event_selector, message), 0] } \ No newline at end of file diff --git a/yarn-project/aztec-nr/aztec/src/oracle/notes.nr b/yarn-project/aztec-nr/aztec/src/oracle/notes.nr index 68670b95f8a..ed62bdcd1d1 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/notes.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/notes.nr @@ -12,7 +12,7 @@ fn notify_created_note_oracle( _inner_note_hash: Field, ) -> Field {} -unconstrained fn notify_created_note( +unconstrained pub fn notify_created_note( storage_slot: Field, preimage: [Field; N], inner_note_hash: Field, @@ -26,7 +26,7 @@ fn notify_nullified_note_oracle( _inner_note_hash: Field, ) -> Field {} -unconstrained fn notify_nullified_note( +unconstrained pub fn notify_nullified_note( nullifier: Field, inner_note_hash: Field, ) -> Field { @@ -62,7 +62,7 @@ unconstrained fn get_notes_oracle_wrapper( get_notes_oracle(storage_slot, num_selects, select_by, select_values, sort_by, sort_order, limit, offset, return_size, placeholder_fields) } -unconstrained fn get_notes( +unconstrained pub fn get_notes( storage_slot: Field, note_interface: NoteInterface, num_selects: u8, @@ -103,6 +103,6 @@ fn check_nullifier_exists_oracle( _inner_nullifier: Field, ) -> Field {} -unconstrained fn check_nullifier_exists(inner_nullifier: Field) -> bool { +unconstrained pub fn check_nullifier_exists(inner_nullifier: Field) -> bool { check_nullifier_exists_oracle(inner_nullifier) == 1 } \ No newline at end of file diff --git a/yarn-project/aztec-nr/aztec/src/oracle/public_call.nr b/yarn-project/aztec-nr/aztec/src/oracle/public_call.nr index 2a25b85930f..a2caf7ef23f 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/public_call.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/public_call.nr @@ -7,7 +7,7 @@ fn call_public_function_oracle( _args_hash: Field ) -> [Field; RETURN_VALUES_LENGTH] {} -unconstrained fn call_public_function_internal( +unconstrained pub fn call_public_function_internal( contract_address: Field, function_selector: Field, args_hash: Field diff --git a/yarn-project/aztec-nr/aztec/src/oracle/rand.nr b/yarn-project/aztec-nr/aztec/src/oracle/rand.nr index 2f0f35583ea..b21f6ad93af 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/rand.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/rand.nr @@ -3,6 +3,6 @@ #[oracle(getRandomField)] fn rand_oracle() -> Field {} -unconstrained fn rand() -> Field { +unconstrained pub fn rand() -> Field { rand_oracle() } diff --git a/yarn-project/aztec-nr/aztec/src/oracle/storage.nr b/yarn-project/aztec-nr/aztec/src/oracle/storage.nr index 7b367360cd4..0b5d96997d2 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/storage.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/storage.nr @@ -9,7 +9,7 @@ unconstrained fn storage_read_oracle_wrapper(_storage_slot: Field)-> [Field; storage_read_oracle(_storage_slot, N) } -fn storage_read( +pub fn storage_read( storage_slot: Field, deserialize: fn ([Field; N]) -> T, ) -> T { @@ -24,7 +24,7 @@ fn storage_write_oracle( ) -> [Field; N] {} // TODO: Remove return value. -unconstrained fn storage_write( +unconstrained pub fn storage_write( storage_slot: Field, fields: [Field; N] ) { diff --git a/yarn-project/aztec-nr/aztec/src/private_call_stack_item.nr b/yarn-project/aztec-nr/aztec/src/private_call_stack_item.nr index 77d702667b6..a28bcd89477 100644 --- a/yarn-project/aztec-nr/aztec/src/private_call_stack_item.nr +++ b/yarn-project/aztec-nr/aztec/src/private_call_stack_item.nr @@ -10,7 +10,7 @@ struct PrivateCallStackItem { } impl PrivateCallStackItem { - fn hash(self) -> Field { + pub fn hash(self) -> Field { dep::std::hash::pedersen_with_separator([ self.contract_address, self.function_data.hash(), diff --git a/yarn-project/aztec-nr/aztec/src/public_call_stack_item.nr b/yarn-project/aztec-nr/aztec/src/public_call_stack_item.nr index 25318b221c3..c1c0d2a2251 100644 --- a/yarn-project/aztec-nr/aztec/src/public_call_stack_item.nr +++ b/yarn-project/aztec-nr/aztec/src/public_call_stack_item.nr @@ -23,7 +23,7 @@ struct PublicCallStackItem { } impl PublicCallStackItem { - fn hash(self) -> Field { + pub fn hash(self) -> Field { dep::std::hash::pedersen_with_separator([ self.contract_address, self.function_data.hash(), diff --git a/yarn-project/aztec-nr/aztec/src/selector.nr b/yarn-project/aztec-nr/aztec/src/selector.nr index 39951a264ec..9f5d368e5d7 100644 --- a/yarn-project/aztec-nr/aztec/src/selector.nr +++ b/yarn-project/aztec-nr/aztec/src/selector.nr @@ -2,7 +2,7 @@ use crate::utils::field_from_bytes; global SELECTOR_SIZE = 4; -fn compute_selector(signature: str) -> Field { +pub fn compute_selector(signature: str) -> Field { let bytes = signature.as_bytes(); let hash = dep::std::hash::keccak256(bytes, bytes.len() as u32); diff --git a/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr b/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr index edc8b7883c0..0dad78df1c6 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars/immutable_singleton.nr @@ -21,7 +21,7 @@ struct ImmutableSingleton { impl ImmutableSingleton { // docs:start:new - fn new( + pub fn new( context: Context, storage_slot: Field, note_interface: NoteInterface, @@ -37,7 +37,7 @@ impl ImmutableSingleton { // docs:end:new // docs:start:is_initialized - unconstrained fn is_initialized(self, owner: Option) -> bool { + unconstrained pub fn is_initialized(self, owner: Option) -> bool { let compute_initialization_nullifier = self.compute_initialization_nullifier; let nullifier = compute_initialization_nullifier(self.storage_slot, owner); check_nullifier_exists(nullifier) @@ -45,7 +45,7 @@ impl ImmutableSingleton { // docs:end:is_initialized // docs:start:initialize - fn initialize(self, note: &mut Note, owner: Option) { + pub fn initialize(self, note: &mut Note, owner: Option) { let context = self.context.unwrap(); // Nullify the storage slot. @@ -63,14 +63,14 @@ impl ImmutableSingleton { // docs:end:initialize // docs:start:get_note - fn get_note(self) -> Note { + pub fn get_note(self) -> Note { let context = self.context.unwrap(); let storage_slot = self.storage_slot; get_note(context, storage_slot, self.note_interface) } // docs:end:get_note - unconstrained fn view_note(self) -> Note { + unconstrained pub fn view_note(self) -> Note { let options = NoteViewerOptions::new().set_limit(1); view_notes(self.storage_slot, self.note_interface, options)[0].unwrap() } diff --git a/yarn-project/aztec-nr/aztec/src/state_vars/map.nr b/yarn-project/aztec-nr/aztec/src/state_vars/map.nr index 5ee97e8b681..9aa49a47354 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars/map.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars/map.nr @@ -11,7 +11,7 @@ struct Map { impl Map { // docs:start:new - fn new( + pub fn new( context: Context, storage_slot: Field, state_var_constructor: fn(Context, Field) -> V, @@ -26,7 +26,7 @@ impl Map { // docs:end:new // docs:start:at - fn at(self, key: Field) -> V { + pub fn at(self, key: Field) -> V { // TODO(#1204): use a generator index for the storage slot let derived_storage_slot = dep::std::hash::pedersen([self.storage_slot, key])[0]; diff --git a/yarn-project/aztec-nr/aztec/src/state_vars/public_state.nr b/yarn-project/aztec-nr/aztec/src/state_vars/public_state.nr index fb1962227a7..37a5e877e52 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars/public_state.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars/public_state.nr @@ -13,7 +13,7 @@ struct PublicState { impl PublicState { // docs:start:public_state_struct_new - fn new( + pub fn new( // Note: Passing the contexts to new(...) just to have an interface compatible with a Map. _: Context, storage_slot: Field, @@ -28,13 +28,13 @@ impl PublicState { // docs:end:public_state_struct_new // docs:start:public_state_struct_read - fn read(self) -> T { + pub fn read(self) -> T { storage_read(self.storage_slot, self.serialization_methods.deserialize) } // docs:end:public_state_struct_read // docs:start:public_state_struct_write - fn write(self, value: T) { + pub fn write(self, value: T) { let serialize = self.serialization_methods.serialize; let fields = serialize(value); storage_write(self.storage_slot, fields); diff --git a/yarn-project/aztec-nr/aztec/src/state_vars/set.nr b/yarn-project/aztec-nr/aztec/src/state_vars/set.nr index 162c670058f..68fe16dd3b6 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars/set.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars/set.nr @@ -22,7 +22,7 @@ struct Set { impl Set { // docs:start:new - fn new( + pub fn new( context: Context, storage_slot: Field, note_interface: NoteInterface, @@ -37,7 +37,7 @@ impl Set { // docs:end:new // docs:start:insert - fn insert(self, note: &mut Note) { + pub fn insert(self, note: &mut Note) { create_note( self.context.private.unwrap(), self.storage_slot, @@ -48,7 +48,7 @@ impl Set { // docs:end:insert // docs:start:insert_from_public - fn insert_from_public(self, note: &mut Note) { + pub fn insert_from_public(self, note: &mut Note) { create_note_hash_from_public( self.context.public.unwrap(), self.storage_slot, @@ -69,7 +69,7 @@ impl Set { } // docs:start:remove - fn remove(self, note: Note) { + pub fn remove(self, note: Note) { let context = self.context.private.unwrap(); let note_hash = compute_note_hash_for_read_or_nullify(self.note_interface, note); let has_been_read = context.read_requests.any(|r| r == note_hash); @@ -84,7 +84,7 @@ impl Set { // docs:end:remove // docs:start:get_notes - fn get_notes( + pub fn get_notes( self, options: NoteGetterOptions, ) -> [Option; MAX_READ_REQUESTS_PER_CALL] { @@ -100,7 +100,7 @@ impl Set { // docs:end:get_notes // docs:start:view_notes - unconstrained fn view_notes( + unconstrained pub fn view_notes( self, options: NoteViewerOptions, ) -> [Option; MAX_NOTES_PER_PAGE] { diff --git a/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr b/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr index 19eb92664a6..965e4e5f47f 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr @@ -13,7 +13,7 @@ use crate::oracle::{ }; use dep::std::hash::pedersen_with_separator; -fn compute_singleton_initialization_nullifier(storage_slot: Field, owner: Option) -> Field { +pub fn compute_singleton_initialization_nullifier(storage_slot: Field, owner: Option) -> Field { if owner.is_some() { let secret = get_secret_key(owner.unwrap_unchecked()); pedersen_with_separator( @@ -39,7 +39,7 @@ struct Singleton { impl Singleton { // docs:start:new - fn new( + pub fn new( context: Context, storage_slot: Field, note_interface: NoteInterface, @@ -55,7 +55,7 @@ impl Singleton { // docs:end:new // docs:start:is_initialized - unconstrained fn is_initialized(self, owner: Option) -> bool { + unconstrained pub fn is_initialized(self, owner: Option) -> bool { let compute_initialization_nullifier = self.compute_initialization_nullifier; let nullifier = compute_initialization_nullifier(self.storage_slot, owner); check_nullifier_exists(nullifier) @@ -63,7 +63,7 @@ impl Singleton { // docs:end:is_initialized // docs:start:initialize - fn initialize(self, note: &mut Note, owner: Option) { + pub fn initialize(self, note: &mut Note, owner: Option) { let context = self.context.unwrap(); // Nullify the storage slot. @@ -76,7 +76,7 @@ impl Singleton { // docs:end:initialize // docs:start:replace - fn replace(self, new_note: &mut Note) { + pub fn replace(self, new_note: &mut Note) { let context = self.context.unwrap(); let prev_note = get_note(context, self.storage_slot, self.note_interface); @@ -89,7 +89,7 @@ impl Singleton { // docs:end:replace // docs:start:get_note - fn get_note(self) -> Note { + pub fn get_note(self) -> Note { let context = self.context.unwrap(); let mut note = get_note(context, self.storage_slot, self.note_interface); @@ -104,7 +104,7 @@ impl Singleton { } // docs:end:get_note - unconstrained fn view_note(self) -> Note { + unconstrained pub fn view_note(self) -> Note { let options = NoteViewerOptions::new().set_limit(1); view_notes(self.storage_slot, self.note_interface, options)[0].unwrap() } diff --git a/yarn-project/aztec-nr/aztec/src/types/address.nr b/yarn-project/aztec-nr/aztec/src/types/address.nr index 79a8f1bd343..c238b491950 100644 --- a/yarn-project/aztec-nr/aztec/src/types/address.nr +++ b/yarn-project/aztec-nr/aztec/src/types/address.nr @@ -3,21 +3,21 @@ struct AztecAddress { } impl AztecAddress { - fn new(address: Field) -> Self { + pub fn new(address: Field) -> Self { Self { address } } - fn eq(self: Self, other: Self) -> bool { + pub fn eq(self: Self, other: Self) -> bool { self.address == other.address } - fn serialize(self: Self) -> [Field; 1] { + pub fn serialize(self: Self) -> [Field; 1] { [self.address] } - fn deserialize(fields: [Field; 1]) -> Self { + pub fn deserialize(fields: [Field; 1]) -> Self { Self { address: fields[0] } @@ -29,7 +29,7 @@ struct EthereumAddress { } impl EthereumAddress { - fn new(address: Field) -> Self { + pub fn new(address: Field) -> Self { // Check that it actually will fit. Spending a lot of constraints here :grimacing: let bytes = address.to_be_bytes(32); for i in 0..12 { @@ -41,11 +41,11 @@ impl EthereumAddress { } - fn serialize(self: Self) -> [Field; 1] { + pub fn serialize(self: Self) -> [Field; 1] { [self.address] } - fn deserialize(fields: [Field; 1]) -> Self { + pub fn deserialize(fields: [Field; 1]) -> Self { Self { address: fields[0] } diff --git a/yarn-project/aztec-nr/aztec/src/types/point.nr b/yarn-project/aztec-nr/aztec/src/types/point.nr index 6b391354874..5a51780a81b 100644 --- a/yarn-project/aztec-nr/aztec/src/types/point.nr +++ b/yarn-project/aztec-nr/aztec/src/types/point.nr @@ -6,7 +6,7 @@ struct Point { } impl Point { - fn new(x: Field, y: Field) -> Self { + pub fn new(x: Field, y: Field) -> Self { Point { x, y } } } diff --git a/yarn-project/aztec-nr/aztec/src/types/vec.nr b/yarn-project/aztec-nr/aztec/src/types/vec.nr index 589159eb805..4851a1200c3 100644 --- a/yarn-project/aztec-nr/aztec/src/types/vec.nr +++ b/yarn-project/aztec-nr/aztec/src/types/vec.nr @@ -5,27 +5,27 @@ struct BoundedVec { } impl BoundedVec { - fn new(initial_value: T) -> Self { + pub fn new(initial_value: T) -> Self { BoundedVec { storage: [initial_value; MaxLen], len: 0 } } - fn get(mut self: Self, index: Field) -> T { + pub fn get(mut self: Self, index: Field) -> T { assert(index as u64 < self.len as u64); self.storage[index] } - fn get_unchecked(mut self: Self, index: Field) -> T { + pub fn get_unchecked(mut self: Self, index: Field) -> T { self.storage[index] } - fn push(&mut self, elem: T) { + pub fn push(&mut self, elem: T) { assert(self.len as u64 < MaxLen as u64); self.storage[self.len] = elem; self.len += 1; } - fn push_array(&mut self, array: [T; Len]) { + pub fn push_array(&mut self, array: [T; Len]) { let newLen = self.len + array.len(); assert(newLen as u64 <= MaxLen as u64); for i in 0..array.len() { @@ -34,7 +34,7 @@ impl BoundedVec { self.len = newLen; } - fn pop(&mut self) -> T { + pub fn pop(&mut self) -> T { assert(self.len as u64 > 0); let elem = self.storage[self.len - 1]; @@ -42,7 +42,7 @@ impl BoundedVec { elem } - fn any(self, predicate: fn[Env](T) -> bool) -> bool { + pub fn any(self, predicate: fn[Env](T) -> bool) -> bool { let mut ret = false; let mut exceeded_len = false; for i in 0..MaxLen { diff --git a/yarn-project/aztec-nr/aztec/src/utils.nr b/yarn-project/aztec-nr/aztec/src/utils.nr index 9d32901bc2c..c80e360de56 100644 --- a/yarn-project/aztec-nr/aztec/src/utils.nr +++ b/yarn-project/aztec-nr/aztec/src/utils.nr @@ -1,4 +1,4 @@ -fn arr_copy_slice( +pub fn arr_copy_slice( src: [T; N], mut dst: [T; M], offset: Field, @@ -9,7 +9,7 @@ fn arr_copy_slice( dst } -fn field_from_bytes(bytes: [u8; N], big_endian: bool) -> Field { +pub fn field_from_bytes(bytes: [u8; N], big_endian: bool) -> Field { assert(bytes.len() as u32 < 32, "field_from_bytes: N must be less than 32"); let mut as_field = 0; let mut offset = 1; diff --git a/yarn-project/aztec-nr/easy-private-state/src/easy_private_state.nr b/yarn-project/aztec-nr/easy-private-state/src/easy_private_state.nr index 69ec2eea87f..be293eb960b 100644 --- a/yarn-project/aztec-nr/easy-private-state/src/easy_private_state.nr +++ b/yarn-project/aztec-nr/easy-private-state/src/easy_private_state.nr @@ -19,7 +19,7 @@ struct EasyPrivateUint { } impl EasyPrivateUint { - fn new( + pub fn new( context: Context, storage_slot: Field, ) -> Self { @@ -37,7 +37,7 @@ impl EasyPrivateUint { } // Very similar to `value_note::utils::increment`. - fn add(self, addend: u120, owner: Field) { + pub fn add(self, addend: u120, owner: Field) { // Creates new note for the owner. let mut addend_note = ValueNote::new(addend as Field, owner); @@ -59,7 +59,7 @@ impl EasyPrivateUint { } // Very similar to `value_note::utils::decrement`. - fn sub(self, subtrahend: u120, owner: Field) { + pub fn sub(self, subtrahend: u120, owner: Field) { // docs:start:get_notes let options = NoteGetterOptions::with_filter(filter_notes_min_sum, subtrahend as Field); let maybe_notes = self.set.get_notes(options); diff --git a/yarn-project/aztec-nr/safe-math/src/safe_u120.nr b/yarn-project/aztec-nr/safe-math/src/safe_u120.nr index a36c05ac3cd..b7ebfa2de82 100644 --- a/yarn-project/aztec-nr/safe-math/src/safe_u120.nr +++ b/yarn-project/aztec-nr/safe-math/src/safe_u120.nr @@ -3,19 +3,19 @@ struct SafeU120 { } impl SafeU120 { - fn min() -> Self { + pub fn min() -> Self { Self { value: 0 } } - fn max() -> Self { + pub fn max() -> Self { Self { value: 0xffffffffffffffffffffffffffffff } } - fn new( + pub fn new( value: Field, ) -> Self { // Check that it actually will fit. Spending a lot of constraints here :grimacing: @@ -28,36 +28,36 @@ impl SafeU120 { } } - fn is_zero( + pub fn is_zero( self: Self, ) -> bool { self.value == 0 } - fn eq( + pub fn eq( self: Self, other: Self ) -> bool { self.value == other.value } - fn lt(self: Self, other: Self) -> bool { + pub fn lt(self: Self, other: Self) -> bool { self.value < other.value } - fn le(self: Self, other: Self) -> bool { + pub fn le(self: Self, other: Self) -> bool { self.value <= other.value } - fn gt(self: Self, other: Self) -> bool { + pub fn gt(self: Self, other: Self) -> bool { self.value > other.value } - fn ge(self: Self, other: Self) -> bool { + pub fn ge(self: Self, other: Self) -> bool { self.value >= other.value } - fn sub( + pub fn sub( self: Self, b: Self, ) -> Self { @@ -67,7 +67,7 @@ impl SafeU120 { } } - fn add( + pub fn add( self: Self, b: Self, ) -> Self { @@ -78,7 +78,7 @@ impl SafeU120 { } } - fn mul( + pub fn mul( self: Self, b: Self, ) -> Self { @@ -91,7 +91,7 @@ impl SafeU120 { } } - fn div( + pub fn div( self: Self, b: Self, ) -> Self { @@ -101,7 +101,7 @@ impl SafeU120 { } } - fn mul_div( + pub fn mul_div( self: Self, b: Self, divisor: Self @@ -109,7 +109,7 @@ impl SafeU120 { self.mul(b).div(divisor) } - fn mul_div_up( + pub fn mul_div_up( self: Self, b: Self, divisor: Self diff --git a/yarn-project/aztec-nr/value-note/src/balance_utils.nr b/yarn-project/aztec-nr/value-note/src/balance_utils.nr index 0b8f04b61e4..eedefb3c27e 100644 --- a/yarn-project/aztec-nr/value-note/src/balance_utils.nr +++ b/yarn-project/aztec-nr/value-note/src/balance_utils.nr @@ -5,11 +5,11 @@ use dep::aztec::note::{ use dep::aztec::state_vars::set::Set; use crate::value_note::{VALUE_NOTE_LEN, ValueNote}; -unconstrained fn get_balance(set: Set) -> Field { +unconstrained pub fn get_balance(set: Set) -> Field { get_balance_with_offset(set, 0) } -unconstrained fn get_balance_with_offset(set: Set, offset: u32) -> Field { +unconstrained pub fn get_balance_with_offset(set: Set, offset: u32) -> Field { let mut balance = 0; // docs:start:view_notes let options = NoteViewerOptions::new().set_offset(offset); diff --git a/yarn-project/aztec-nr/value-note/src/filter.nr b/yarn-project/aztec-nr/value-note/src/filter.nr index 7849747f3f1..05424756218 100644 --- a/yarn-project/aztec-nr/value-note/src/filter.nr +++ b/yarn-project/aztec-nr/value-note/src/filter.nr @@ -2,7 +2,7 @@ use dep::std::option::Option; use dep::aztec::constants_gen::MAX_READ_REQUESTS_PER_CALL; use crate::value_note::ValueNote; -fn filter_notes_min_sum(notes: [Option; MAX_READ_REQUESTS_PER_CALL], min_sum: Field) -> [Option; MAX_READ_REQUESTS_PER_CALL] { +pub fn filter_notes_min_sum(notes: [Option; MAX_READ_REQUESTS_PER_CALL], min_sum: Field) -> [Option; MAX_READ_REQUESTS_PER_CALL] { let mut selected = [Option::none(); MAX_READ_REQUESTS_PER_CALL]; let mut sum = 0; for i in 0..notes.len() { diff --git a/yarn-project/aztec-nr/value-note/src/utils.nr b/yarn-project/aztec-nr/value-note/src/utils.nr index 56204cdd97a..0d54f9961a0 100644 --- a/yarn-project/aztec-nr/value-note/src/utils.nr +++ b/yarn-project/aztec-nr/value-note/src/utils.nr @@ -15,13 +15,13 @@ use crate::{ // Sort the note values (0th field) in descending order. // Pick the fewest notes whose sum is equal to or greater than `amount`. -fn create_note_getter_options_for_decreasing_balance(amount: Field) -> NoteGetterOptions { +pub fn create_note_getter_options_for_decreasing_balance(amount: Field) -> NoteGetterOptions { NoteGetterOptions::with_filter(filter_notes_min_sum, amount).sort(0, SortOrder.DESC) } // Creates a new note for the recipient. // Inserts it to the recipient's set of notes. -fn increment( +pub fn increment( balance: Set, amount: Field, recipient: Field, @@ -39,7 +39,7 @@ fn increment( // Remove those notes. // If the value of the removed notes exceeds the requested `amount`, create a new note containing the excess value, so that exactly `amount` is removed. // Fail if the sum of the selected notes is less than the amount. -fn decrement( +pub fn decrement( balance: Set, amount: Field, owner: Field, @@ -56,7 +56,7 @@ fn decrement( // equal `amount`. // // It returns the decremented amount, which should be less than or equal to max_amount. -fn decrement_by_at_most( +pub fn decrement_by_at_most( balance: Set, max_amount: Field, owner: Field, @@ -82,7 +82,7 @@ fn decrement_by_at_most( decremented } -fn create_note( +pub fn create_note( balance: Set, owner: Field, note: &mut ValueNote, @@ -113,7 +113,7 @@ fn create_note( // Removes the note from the owner's set of notes. // Returns the value of the destroyed note. -fn destroy_note( +pub fn destroy_note( balance: Set, owner: Field, note: ValueNote, diff --git a/yarn-project/aztec-nr/value-note/src/value_note.nr b/yarn-project/aztec-nr/value-note/src/value_note.nr index 7b7855e37f3..df35dd97fc0 100644 --- a/yarn-project/aztec-nr/value-note/src/value_note.nr +++ b/yarn-project/aztec-nr/value-note/src/value_note.nr @@ -20,7 +20,7 @@ struct ValueNote { // docs:end:value-note-def impl ValueNote { - fn new(value: Field, owner: Field) -> Self { + pub fn new(value: Field, owner: Field) -> Self { let randomness = rand(); let header = NoteHeader::empty(); ValueNote { @@ -31,11 +31,11 @@ impl ValueNote { } } - fn serialize(self) -> [Field; VALUE_NOTE_LEN] { + pub fn serialize(self) -> [Field; VALUE_NOTE_LEN] { [self.value, self.owner, self.randomness] } - fn deserialize(preimage: [Field; VALUE_NOTE_LEN]) -> Self { + pub fn deserialize(preimage: [Field; VALUE_NOTE_LEN]) -> Self { ValueNote { value: preimage[0], owner: preimage[1], @@ -44,7 +44,7 @@ impl ValueNote { } } - fn compute_note_hash(self) -> Field { + pub fn compute_note_hash(self) -> Field { // TODO(#1205) Should use a non-zero generator index. dep::std::hash::pedersen([ self.value, @@ -55,7 +55,7 @@ impl ValueNote { // docs:start:nullifier - fn compute_nullifier(self) -> Field { + pub fn compute_nullifier(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_read_or_nullify(ValueNoteMethods, self); let secret = get_secret_key(self.owner); // TODO(#1205) Should use a non-zero generator index. @@ -68,7 +68,7 @@ impl ValueNote { // docs:end:nullifier - fn set_header(&mut self, header: NoteHeader) { + pub fn set_header(&mut self, header: NoteHeader) { self.header = header; } } diff --git a/yarn-project/noir-compiler/src/contract-interface-gen/noir.ts b/yarn-project/noir-compiler/src/contract-interface-gen/noir.ts index d1fd96bea21..0e47951fe38 100644 --- a/yarn-project/noir-compiler/src/contract-interface-gen/noir.ts +++ b/yarn-project/noir-compiler/src/contract-interface-gen/noir.ts @@ -151,7 +151,7 @@ function generateFunctionInterface(functionData: FunctionAbi, kind: 'private' | const retType = isSync ? `-> [Field; RETURN_VALUES_LENGTH] ` : ``; return ` - fn ${name}( + pub fn ${name}( ${allParams.join(',\n ')} ) ${retType}{ ${serialization} @@ -203,7 +203,7 @@ struct ${generateContractStructName(contractName, kind)} { */ function generateContractInterfaceImpl(contractName: string, kind: 'private' | 'public', functions: string[]) { return `impl ${generateContractStructName(contractName, kind)} { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address, } diff --git a/yarn-project/noir-contracts/src/contracts/card_game_contract/src/cards.nr b/yarn-project/noir-contracts/src/contracts/card_game_contract/src/cards.nr index 219728e3f90..58005615eca 100644 --- a/yarn-project/noir-contracts/src/contracts/card_game_contract/src/cards.nr +++ b/yarn-project/noir-contracts/src/contracts/card_game_contract/src/cards.nr @@ -28,7 +28,7 @@ struct Card { } impl Card { - fn from_field(field: Field) -> Card { + pub fn from_field(field: Field) -> Card { let value_bytes = field.to_le_bytes(32); let strength = (value_bytes[0] as u16) + (value_bytes[1] as u16) * 256; let points = (value_bytes[2] as u16) + (value_bytes[3] as u16) * 256; @@ -38,11 +38,11 @@ impl Card { } } - fn to_field(self) -> Field { + pub fn to_field(self) -> Field { self.strength as Field + (self.points as Field)*65536 } - fn serialize(self) -> [Field; 2] { + pub fn serialize(self) -> [Field; 2] { [self.strength as Field, self.points as Field] } } @@ -73,14 +73,14 @@ impl CardNote { CardNote::from_card(card, owner) } - fn from_card(card: Card, owner: Field) -> CardNote { + pub fn from_card(card: Card, owner: Field) -> CardNote { CardNote { card, note: ValueNote::new(card.to_field(), owner), } } - fn from_note(note: ValueNote) -> CardNote { + pub fn from_note(note: ValueNote) -> CardNote { CardNote { card: Card::from_field(note.value), note, @@ -92,7 +92,7 @@ struct Deck { set: Set, } -fn filter_cards(notes: [Option; MAX_READ_REQUESTS_PER_CALL], desired_cards: [Card; N]) -> [Option; MAX_READ_REQUESTS_PER_CALL] { +pub fn filter_cards(notes: [Option; MAX_READ_REQUESTS_PER_CALL], desired_cards: [Card; N]) -> [Option; MAX_READ_REQUESTS_PER_CALL] { let mut selected = [Option::none(); MAX_READ_REQUESTS_PER_CALL]; let mut found = [false; N]; @@ -118,7 +118,7 @@ fn filter_cards(notes: [Option; MAX_READ_REQUESTS_PER_CALL], desir impl Deck { - fn new( + pub fn new( context: Context, storage_slot: Field, ) -> Self { @@ -132,7 +132,7 @@ impl Deck { } } - fn add_cards(&mut self, cards: [Card; N], owner: Field) -> [CardNote]{ + pub fn add_cards(&mut self, cards: [Card; N], owner: Field) -> [CardNote]{ let owner_key = get_public_key(owner); let context = self.set.context.private.unwrap(); @@ -153,7 +153,7 @@ impl Deck { inserted_cards } - fn get_cards(&mut self, cards: [Card; N], owner: Field) -> [CardNote; N] { + pub fn get_cards(&mut self, cards: [Card; N], owner: Field) -> [CardNote; N] { let options = NoteGetterOptions::with_filter(filter_cards, cards); let maybe_notes = self.set.get_notes(options); let mut found_cards = [Option::none(); N]; @@ -180,14 +180,14 @@ impl Deck { }) } - fn remove_cards(&mut self, cards: [Card; N], owner: Field) { + pub fn remove_cards(&mut self, cards: [Card; N], owner: Field) { let card_notes = self.get_cards(cards, owner); for card_note in card_notes { self.set.remove(card_note.note); } } - unconstrained fn view_cards(self, offset: u32) -> [Option; MAX_NOTES_PER_PAGE] { + unconstrained pub fn view_cards(self, offset: u32) -> [Option; MAX_NOTES_PER_PAGE] { let options = NoteViewerOptions::new().set_offset(offset); let opt_notes = self.set.view_notes(options); let mut opt_cards = [Option::none(); MAX_NOTES_PER_PAGE]; @@ -203,7 +203,7 @@ impl Deck { global PACK_CARDS = 3; // Limited by number of write requests (max 4) -fn get_pack_cards( +pub fn get_pack_cards( seed: Field, owner_address: Field ) -> [Card; PACK_CARDS] { @@ -226,7 +226,7 @@ fn get_pack_cards( cards } -fn compute_deck_strength(cards: [Card; N]) -> Field { +pub fn compute_deck_strength(cards: [Card; N]) -> Field { cards.fold(0, |acc, card: Card| { acc + card.strength as Field }) diff --git a/yarn-project/noir-contracts/src/contracts/card_game_contract/src/game.nr b/yarn-project/noir-contracts/src/contracts/card_game_contract/src/game.nr index 30a8c722bd1..75be5f84979 100644 --- a/yarn-project/noir-contracts/src/contracts/card_game_contract/src/game.nr +++ b/yarn-project/noir-contracts/src/contracts/card_game_contract/src/game.nr @@ -11,7 +11,7 @@ struct PlayerEntry { } impl PlayerEntry { - fn is_initialized(self) -> bool { + pub fn is_initialized(self) -> bool { self.address != 0 } } @@ -79,11 +79,11 @@ fn serializeGame(game: Game) -> [Field; GAME_SERIALIZED_LEN] { } impl Game { - fn serialize(self: Self) -> [Field; GAME_SERIALIZED_LEN] { + pub fn serialize(self: Self) -> [Field; GAME_SERIALIZED_LEN] { serializeGame(self) } - fn add_player(&mut self, player_entry: PlayerEntry) -> bool { + pub fn add_player(&mut self, player_entry: PlayerEntry) -> bool { let mut added = false; for i in 0..NUMBER_OF_PLAYERS { @@ -99,7 +99,7 @@ impl Game { added } - fn start_game(&mut self) { + pub fn start_game(&mut self) { assert(!self.started, "Game already started"); for i in 0..NUMBER_OF_PLAYERS { let entry = self.players[i]; @@ -110,13 +110,13 @@ impl Game { self.started = true; } - fn current_player(self) -> PlayerEntry { + pub fn current_player(self) -> PlayerEntry { assert(self.started, "Game not started"); assert(!self.finished, "Game finished"); self.players[self.current_player] } - fn winner(self) -> PlayerEntry { + pub fn winner(self) -> PlayerEntry { assert(self.finished, "Game not finished"); let mut winner = self.players[0]; for i in 1..NUMBER_OF_PLAYERS { @@ -128,7 +128,7 @@ impl Game { winner } - fn play_card(&mut self, card: Card) { + pub fn play_card(&mut self, card: Card) { assert(self.started, "Game not started"); assert(!self.finished, "Game finished"); diff --git a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/account_contract_interface.nr b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/account_contract_interface.nr index ab79a11c716..0701b4819be 100644 --- a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/account_contract_interface.nr +++ b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/account_contract_interface.nr @@ -3,9 +3,9 @@ struct AccountContractInterface { } impl AccountContractInterface { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { AccountContractInterface { address } } - fn send_rewards(_self: Self, _rewards: u8) {} + pub fn send_rewards(_self: Self, _rewards: u8) {} } diff --git a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/actions.nr b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/actions.nr index 4a3b77d8914..f84bd291478 100644 --- a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/actions.nr +++ b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/actions.nr @@ -17,28 +17,28 @@ use crate::types::{ }; // docs:start:state_vars-PublicStateRead -fn is_locked(state_var: PublicState) -> bool { +pub fn is_locked(state_var: PublicState) -> bool { state_var.read() } // docs:end:state_vars-PublicStateRead // docs:start:state_vars-PublicStateWrite -fn lock(state_var: PublicState) { +pub fn lock(state_var: PublicState) { state_var.write(true); } // docs:end:state_vars-PublicStateWrite -fn unlock(state_var: PublicState) { +pub fn unlock(state_var: PublicState) { state_var.write(false); } // docs:start:state_vars-PublicStateReadCustom -fn get_current_queen(state_var: PublicState) -> Queen { +pub fn get_current_queen(state_var: PublicState) -> Queen { state_var.read() } // docs:end:state_vars-PublicStateReadCustom -fn can_replace_queen( +pub fn can_replace_queen( state_var: PublicState, new_queen: Queen, ) -> bool { @@ -47,13 +47,13 @@ fn can_replace_queen( } // docs:start:state_vars-PublicStateWriteCustom -fn replace_queen(state_var: PublicState, new_queen: Queen) { +pub fn replace_queen(state_var: PublicState, new_queen: Queen) { state_var.write(new_queen); } // docs:end:state_vars-PublicStateWriteCustom // docs:start:state_vars-PublicStateReadWriteCustom -fn add_points_to_queen(state_var: PublicState, new_points: u8) { +pub fn add_points_to_queen(state_var: PublicState, new_points: u8) { let mut queen = state_var.read(); queen.points += new_points; state_var.write(queen); @@ -61,25 +61,25 @@ fn add_points_to_queen(state_var: PublicState, new_ // docs:end:state_vars-PublicStateReadWriteCustom // docs:start:state_vars-SingletonInit -fn init_legendary_card(state_var: Singleton, card: &mut CardNote) { +pub fn init_legendary_card(state_var: Singleton, card: &mut CardNote) { state_var.initialize(card, Option::some(card.owner)); } // docs:end:state_vars-SingletonInit // docs:start:state_vars-SingletonReplace -fn update_legendary_card(state_var: Singleton, card: &mut CardNote) { +pub fn update_legendary_card(state_var: Singleton, card: &mut CardNote) { state_var.replace(card); } // docs:end:state_vars-SingletonReplace // docs:start:state_vars-SingletonGet -fn get_legendary_card(state_var: Singleton) -> CardNote { +pub fn get_legendary_card(state_var: Singleton) -> CardNote { state_var.get_note() } // docs:end:state_vars-SingletonGet // docs:start:state_vars-ImmutableSingletonInit -fn init_game_rules( +pub fn init_game_rules( state_var: ImmutableSingleton, rules: &mut RulesNote, ) { @@ -88,26 +88,26 @@ fn init_game_rules( // docs:end:state_vars-ImmutableSingletonInit // docs:start:state_vars-ImmutableSingletonGet -fn is_valid_card(state_var: ImmutableSingleton, card: CardNote) -> bool { +pub fn is_valid_card(state_var: ImmutableSingleton, card: CardNote) -> bool { let rules = state_var.get_note(); card.points >= rules.min_points & card.points <= rules.max_points } // docs:end:state_vars-ImmutableSingletonGet // docs:start:state_vars-SetInsert -fn add_new_card(state_var: Set, card: &mut CardNote) { +pub fn add_new_card(state_var: Set, card: &mut CardNote) { state_var.insert(card); } // docs:end:state_vars-SetInsert // docs:start:state_vars-SetRemove -fn remove_card(state_var: Set, card: CardNote) { +pub fn remove_card(state_var: Set, card: CardNote) { state_var.remove(card); } // docs:end:state_vars-SetRemove // docs:start:state_vars-SetGet -fn get_cards( +pub fn get_cards( state_var: Set, options: NoteGetterOptions, ) -> [Option; MAX_READ_REQUESTS_PER_CALL] { @@ -116,7 +116,7 @@ fn get_cards( // docs:end:state_vars-SetGet // docs:start:state_vars-SetView -unconstrained fn view_cards( +unconstrained pub fn view_cards( state_var: Set, options: NoteViewerOptions, ) -> [Option; MAX_NOTES_PER_PAGE] { @@ -124,7 +124,7 @@ unconstrained fn view_cards( } // docs:end:state_vars-SetView -unconstrained fn get_total_points( +unconstrained pub fn get_total_points( state_var: Set, account: Field, offset: u32, @@ -146,7 +146,7 @@ unconstrained fn get_total_points( } // docs:start:state_vars-MapAtSingletonInit -fn add_new_profile( +pub fn add_new_profile( state_var: Map>, account: Field, profile: &mut ProfileNote, @@ -156,7 +156,7 @@ fn add_new_profile( // docs:end:state_vars-MapAtSingletonInit // docs:start:state_vars-MapAtSingletonGet -fn get_profile( +pub fn get_profile( state_var: Map>, account: Field, ) -> ProfileNote { diff --git a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/options.nr b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/options.nr index 56751913f0c..636a6de3609 100644 --- a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/options.nr +++ b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/options.nr @@ -4,7 +4,7 @@ use dep::aztec::note::note_getter_options::{NoteGetterOptions, Sort, SortOrder}; use dep::std::option::Option; // docs:start:state_vars-NoteGetterOptionsSelectSortOffset -fn create_account_card_getter_options( +pub fn create_account_card_getter_options( account_address: Field, offset: u32, ) -> NoteGetterOptions { @@ -16,7 +16,7 @@ fn create_account_card_getter_options( // docs:end:state_vars-NoteGetterOptionsSelectSortOffset // docs:start:state_vars-NoteGetterOptionsMultiSelects -fn create_exact_card_getter_options( +pub fn create_exact_card_getter_options( points: u8, secret: Field, account_address: Field, @@ -29,7 +29,7 @@ fn create_exact_card_getter_options( // docs:end:state_vars-NoteGetterOptionsMultiSelects // docs:start:state_vars-OptionFilter -fn filter_min_points( +pub fn filter_min_points( cards: [Option; MAX_READ_REQUESTS_PER_CALL], min_points: u8, ) -> [Option; MAX_READ_REQUESTS_PER_CALL] { @@ -46,7 +46,7 @@ fn filter_min_points( // docs:end:state_vars-OptionFilter // docs:start:state_vars-NoteGetterOptionsFilter -fn create_account_cards_with_min_points_getter_options( +pub fn create_account_cards_with_min_points_getter_options( account_address: Field, min_points: u8, ) -> NoteGetterOptions { @@ -57,7 +57,7 @@ fn create_account_cards_with_min_points_getter_options( // docs:end:state_vars-NoteGetterOptionsFilter // docs:start:state_vars-NoteGetterOptionsPickOne -fn create_largest_account_card_getter_options( +pub fn create_largest_account_card_getter_options( account_address: Field, ) -> NoteGetterOptions { NoteGetterOptions::new() diff --git a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/card_note.nr b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/card_note.nr index c193534e594..509e7337269 100644 --- a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/card_note.nr +++ b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/card_note.nr @@ -19,7 +19,7 @@ struct CardNote { // docs:end:state_vars-CardNote impl CardNote { - fn new(points: u8, secret: Field, owner: Field) -> Self { + pub fn new(points: u8, secret: Field, owner: Field) -> Self { CardNote { points, secret, @@ -28,11 +28,11 @@ impl CardNote { } } - fn serialize(self) -> [Field; CARD_NOTE_LEN] { + pub fn serialize(self) -> [Field; CARD_NOTE_LEN] { [self.points as Field, self.secret, self.owner] } - fn deserialize(preimage: [Field; CARD_NOTE_LEN]) -> Self { + pub fn deserialize(preimage: [Field; CARD_NOTE_LEN]) -> Self { CardNote { points: preimage[0] as u8, secret: preimage[1], @@ -41,7 +41,7 @@ impl CardNote { } } - fn compute_note_hash(self) -> Field { + pub fn compute_note_hash(self) -> Field { dep::std::hash::pedersen([ self.points as Field, self.secret, @@ -49,7 +49,7 @@ impl CardNote { ])[0] } - fn compute_nullifier(self) -> Field { + pub fn compute_nullifier(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_read_or_nullify(CardNoteMethods, self); let secret = get_secret_key(self.owner); dep::std::hash::pedersen([ @@ -59,7 +59,7 @@ impl CardNote { ])[0] } - fn set_header(&mut self, header: NoteHeader) { + pub fn set_header(&mut self, header: NoteHeader) { self.header = header; } } diff --git a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/profile_note.nr b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/profile_note.nr index e287d8ab544..6205a5acf00 100644 --- a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/profile_note.nr +++ b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/profile_note.nr @@ -12,7 +12,7 @@ struct ProfileNote { } impl ProfileNote { - fn new(avatar: Field, xp: Field) -> Self { + pub fn new(avatar: Field, xp: Field) -> Self { ProfileNote { avatar, xp, @@ -20,11 +20,11 @@ impl ProfileNote { } } - fn serialize(self) -> [Field; PROFILE_NOTE_LEN] { + pub fn serialize(self) -> [Field; PROFILE_NOTE_LEN] { [self.avatar, self.xp] } - fn deserialize(preimage: [Field; PROFILE_NOTE_LEN]) -> Self { + pub fn deserialize(preimage: [Field; PROFILE_NOTE_LEN]) -> Self { ProfileNote { avatar: preimage[1], xp: preimage[0], @@ -32,19 +32,19 @@ impl ProfileNote { } } - fn compute_note_hash(self) -> Field { + pub fn compute_note_hash(self) -> Field { dep::std::hash::pedersen([ self.avatar, self.xp, ])[0] } - fn compute_nullifier(_self: Self) -> Field { + pub fn compute_nullifier(_self: Self) -> Field { assert(false); // Not allowed. 0 } - fn set_header(&mut self, header: NoteHeader) { + pub fn set_header(&mut self, header: NoteHeader) { self.header = header; } } diff --git a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/rules_note.nr b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/rules_note.nr index e67c116e961..27b0faf1cc1 100644 --- a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/rules_note.nr +++ b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/rules_note.nr @@ -12,7 +12,7 @@ struct RulesNote { } impl RulesNote { - fn new(min_points: u8, max_points: u8) -> Self { + pub fn new(min_points: u8, max_points: u8) -> Self { RulesNote { min_points, max_points, @@ -20,11 +20,11 @@ impl RulesNote { } } - fn serialize(self) -> [Field; RULES_NOTE_LEN] { + pub fn serialize(self) -> [Field; RULES_NOTE_LEN] { [self.min_points as Field, self.max_points as Field] } - fn deserialize(preimage: [Field; RULES_NOTE_LEN]) -> Self { + pub fn deserialize(preimage: [Field; RULES_NOTE_LEN]) -> Self { RulesNote { min_points: preimage[0] as u8, max_points: preimage[1] as u8, @@ -32,19 +32,19 @@ impl RulesNote { } } - fn compute_note_hash(self) -> Field { + pub fn compute_note_hash(self) -> Field { dep::std::hash::pedersen([ self.min_points as Field, self.max_points as Field, ])[0] } - fn compute_nullifier(_self: Self) -> Field { + pub fn compute_nullifier(_self: Self) -> Field { // Not used 0 } - fn set_header(&mut self, header: NoteHeader) { + pub fn set_header(&mut self, header: NoteHeader) { self.header = header; } } diff --git a/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr b/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr index c80188fff21..e7df3dcb1bc 100644 --- a/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr +++ b/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr @@ -15,7 +15,7 @@ struct EcdsaPublicKeyNote { } impl EcdsaPublicKeyNote { - fn new(x: [u8; 32], y: [u8; 32], owner: Field) -> Self { + pub fn new(x: [u8; 32], y: [u8; 32], owner: Field) -> Self { EcdsaPublicKeyNote { x, y, @@ -30,7 +30,7 @@ impl EcdsaPublicKeyNote { // [2] = y[0..31] // [3] = y[31] // [4] = owner - fn serialize(self) -> [Field; ECDSA_PUBLIC_KEY_NOTE_LEN] { + pub fn serialize(self) -> [Field; ECDSA_PUBLIC_KEY_NOTE_LEN] { let mut x: Field = 0; let mut y: Field = 0; let mut mul: Field = 1; @@ -50,7 +50,7 @@ impl EcdsaPublicKeyNote { res } - fn compute_nullifier(self) -> Field { + pub fn compute_nullifier(self) -> Field { let unique_siloed_note_hash = compute_unique_siloed_note_hash(EcdsaPublicKeyNoteInterface, self); let secret = get_secret_key(self.owner); // TODO(#1205) Should use a non-zero generator index. @@ -61,7 +61,7 @@ impl EcdsaPublicKeyNote { ])[0] } - fn set_header(&mut self, header: NoteHeader) { + pub fn set_header(&mut self, header: NoteHeader) { self.header = header; } } diff --git a/yarn-project/noir-contracts/src/contracts/escrow_contract/src/address_note.nr b/yarn-project/noir-contracts/src/contracts/escrow_contract/src/address_note.nr index 6d83dcff9f9..f7c8f9807c8 100644 --- a/yarn-project/noir-contracts/src/contracts/escrow_contract/src/address_note.nr +++ b/yarn-project/noir-contracts/src/contracts/escrow_contract/src/address_note.nr @@ -13,7 +13,7 @@ struct AddressNote { } impl AddressNote { - fn new(address: Field, owner: Field) -> Self { + pub fn new(address: Field, owner: Field) -> Self { AddressNote { address, owner, @@ -21,11 +21,11 @@ impl AddressNote { } } - fn serialize(self) -> [Field; ADDRESS_NOTE_LEN]{ + pub fn serialize(self) -> [Field; ADDRESS_NOTE_LEN]{ [self.address, self.owner] } - fn compute_nullifier(self) -> Field { + pub fn compute_nullifier(self) -> Field { let siloed_note_hash = compute_siloed_note_hash(AddressNoteMethods, self); let secret = get_secret_key(self.owner); // TODO(#1205) Should use a non-zero generator index. @@ -36,7 +36,7 @@ impl AddressNote { ])[0] } - fn set_header(&mut self, header: NoteHeader) { + pub fn set_header(&mut self, header: NoteHeader) { self.header = header; } } diff --git a/yarn-project/noir-contracts/src/contracts/lending_contract/src/asset.nr b/yarn-project/noir-contracts/src/contracts/lending_contract/src/asset.nr index 76a6744c9e3..cb8dcd90ad4 100644 --- a/yarn-project/noir-contracts/src/contracts/lending_contract/src/asset.nr +++ b/yarn-project/noir-contracts/src/contracts/lending_contract/src/asset.nr @@ -35,7 +35,7 @@ fn serializeAsset(asset: Asset) -> [Field; ASSET_SERIALIZED_LEN] { } impl Asset { - fn serialize(self: Self) -> [Field; ASSET_SERIALIZED_LEN] { + pub fn serialize(self: Self) -> [Field; ASSET_SERIALIZED_LEN] { serializeAsset(self) } } diff --git a/yarn-project/noir-contracts/src/contracts/lending_contract/src/helpers.nr b/yarn-project/noir-contracts/src/contracts/lending_contract/src/helpers.nr index 30df21ea5b0..d94ebe60872 100644 --- a/yarn-project/noir-contracts/src/contracts/lending_contract/src/helpers.nr +++ b/yarn-project/noir-contracts/src/contracts/lending_contract/src/helpers.nr @@ -6,7 +6,7 @@ use dep::safe_math::SafeU120; // Utility used to easily get a "id" for a private user that sits in the same // "space" as the public users. // It help us to have a single mapping for collateral that have both public and private users. -fn compute_identifier( +pub fn compute_identifier( secret: Field, on_behalf_of: Field, self: Field, @@ -20,7 +20,7 @@ fn compute_identifier( } } -fn covered_by_collateral( +pub fn covered_by_collateral( price: u120, loan_to_value: u120, collateral: u120, @@ -45,7 +45,7 @@ struct DebtReturn { static_debt: u120, } -fn debt_updates( +pub fn debt_updates( interest_accumulator: u120, static_debt: u120, increase: u120, @@ -78,7 +78,7 @@ fn debt_updates( } } -fn debt_value( +pub fn debt_value( static_debt: u120, interest_accumulator: u120, ) -> u120 { diff --git a/yarn-project/noir-contracts/src/contracts/lending_contract/src/interest_math.nr b/yarn-project/noir-contracts/src/contracts/lending_contract/src/interest_math.nr index e6bcadd9b56..735e6ce9e7a 100644 --- a/yarn-project/noir-contracts/src/contracts/lending_contract/src/interest_math.nr +++ b/yarn-project/noir-contracts/src/contracts/lending_contract/src/interest_math.nr @@ -7,7 +7,7 @@ use dep::safe_math::SafeU120; // dividing with 31536000 (seconds per year). // rate must be measured with higher precision than 10^9. // we use e18, and rates >= 4% yearly. Otherwise need more precision -fn compute_multiplier( +pub fn compute_multiplier( rate_per_second: u120, dt: SafeU120, ) -> SafeU120 { diff --git a/yarn-project/noir-contracts/src/contracts/lending_contract/src/interfaces.nr b/yarn-project/noir-contracts/src/contracts/lending_contract/src/interfaces.nr index b11e56a59f6..b4f0634f723 100644 --- a/yarn-project/noir-contracts/src/contracts/lending_contract/src/interfaces.nr +++ b/yarn-project/noir-contracts/src/contracts/lending_contract/src/interfaces.nr @@ -12,11 +12,11 @@ struct PriceFeed { } impl PriceFeed { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address } } - fn get_price(self: Self, context: PublicContext) -> u120 { + pub fn get_price(self: Self, context: PublicContext) -> u120 { let return_values = context.call_public_function( self.address, compute_selector("get_price(Field)"), @@ -32,11 +32,11 @@ struct Token { } impl Token { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address } } - fn transfer_public(self: Self, context: PublicContext, from: Field, to: Field, amount: Field, nonce: Field) { + pub fn transfer_public(self: Self, context: PublicContext, from: Field, to: Field, amount: Field, nonce: Field) { let _transfer_return_values = context.call_public_function( self.address, compute_selector("transfer_public((Field),(Field),Field,Field)"), @@ -44,7 +44,7 @@ impl Token { ); } - fn mint_public(self: Self, context: PublicContext, to: Field, amount: Field) { + pub fn mint_public(self: Self, context: PublicContext, to: Field, amount: Field) { let _return_values = context.call_public_function( self.address, compute_selector("mint_public((Field),Field)"), @@ -52,7 +52,7 @@ impl Token { ); } - fn burn_public(self: Self, context: PublicContext, from: Field, amount: Field, nonce: Field){ + pub fn burn_public(self: Self, context: PublicContext, from: Field, amount: Field, nonce: Field){ let _return_values = context.call_public_function( self.address, compute_selector("burn_public((Field),Field,Field)"), @@ -61,7 +61,7 @@ impl Token { } // Private - fn unshield(self: Self, context: &mut PrivateContext, from: Field, to: Field, amount: Field, nonce: Field) -> [Field; RETURN_VALUES_LENGTH] { + pub fn unshield(self: Self, context: &mut PrivateContext, from: Field, to: Field, amount: Field, nonce: Field) -> [Field; RETURN_VALUES_LENGTH] { context.call_private_function( self.address, compute_selector("unshield((Field),(Field),Field,Field)"), @@ -69,7 +69,7 @@ impl Token { ) } - fn burn(self: Self, context: &mut PrivateContext, from: Field, amount: Field, nonce: Field) -> [Field; RETURN_VALUES_LENGTH] { + pub fn burn(self: Self, context: &mut PrivateContext, from: Field, amount: Field, nonce: Field) -> [Field; RETURN_VALUES_LENGTH] { context.call_private_function( self.address, compute_selector("burn((Field),Field,Field)"), @@ -83,11 +83,11 @@ struct Lending { } impl Lending { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address } } - fn update_accumulator(self: Self, context: PublicContext) -> Asset { + pub fn update_accumulator(self: Self, context: PublicContext) -> Asset { let return_values = context.call_public_function_no_args( self.address, compute_selector("update_accumulator()"), diff --git a/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/hash.nr b/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/hash.nr index 42b092c59ec..b0f1e56cbc3 100644 --- a/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/hash.nr +++ b/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/hash.nr @@ -1,7 +1,7 @@ use dep::std::hash::sha256; // Computes a content hash of a deposit/mint message. -fn get_mint_content_hash(amount: Field, owner_address: Field, canceller: Field) -> Field { +pub fn get_mint_content_hash(amount: Field, owner_address: Field, canceller: Field) -> Field { let mut hash_bytes: [u8; 100] = [0; 100]; let amount_bytes = amount.to_be_bytes(32); let recipient_bytes = owner_address.to_be_bytes(32); @@ -38,7 +38,7 @@ fn get_mint_content_hash(amount: Field, owner_address: Field, canceller: Field) } // Computes a content hash of a withdraw message. -fn get_withdraw_content_hash(amount: Field, recipient: Field, callerOnL1: Field) -> Field { +pub fn get_withdraw_content_hash(amount: Field, recipient: Field, callerOnL1: Field) -> Field { // Compute the content hash // Compute sha256(selector || amount || recipient) // then convert to a single field element diff --git a/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/interface.nr b/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/interface.nr index f81e987051a..880bfe0729c 100644 --- a/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/interface.nr +++ b/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/interface.nr @@ -12,13 +12,13 @@ struct NonNativeTokenPrivateContextInterface { } impl NonNativeTokenPrivateContextInterface { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address, } } - fn addUnshieldedBalance( + pub fn addUnshieldedBalance( self, context: &mut PrivateContext, amount: Field, @@ -32,7 +32,7 @@ impl NonNativeTokenPrivateContextInterface { } - fn mint( + pub fn mint( self, context: &mut PrivateContext, amount: Field, @@ -52,7 +52,7 @@ impl NonNativeTokenPrivateContextInterface { } - fn mintPublic( + pub fn mintPublic( self, context: &mut PrivateContext, amount: Field, @@ -72,7 +72,7 @@ impl NonNativeTokenPrivateContextInterface { } - fn redeemShield( + pub fn redeemShield( self, context: &mut PrivateContext, amount: Field, @@ -88,7 +88,7 @@ impl NonNativeTokenPrivateContextInterface { } - fn shield( + pub fn shield( self, context: &mut PrivateContext, amount: Field, @@ -102,7 +102,7 @@ impl NonNativeTokenPrivateContextInterface { } - fn transfer( + pub fn transfer( self, context: &mut PrivateContext, amount: Field, @@ -116,7 +116,7 @@ impl NonNativeTokenPrivateContextInterface { } - fn unshieldTokens( + pub fn unshieldTokens( self, context: &mut PrivateContext, amount: Field, @@ -130,7 +130,7 @@ impl NonNativeTokenPrivateContextInterface { } - fn withdraw( + pub fn withdraw( self, context: &mut PrivateContext, amount: Field, @@ -148,7 +148,7 @@ impl NonNativeTokenPrivateContextInterface { } - fn withdrawPublic( + pub fn withdrawPublic( self, context: &mut PrivateContext, amount: Field, @@ -174,13 +174,13 @@ struct NonNativeTokenPublicContextInterface { } impl NonNativeTokenPublicContextInterface { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address, } } - fn addUnshieldedBalance( + pub fn addUnshieldedBalance( self, context: PublicContext, amount: Field, @@ -194,7 +194,7 @@ impl NonNativeTokenPublicContextInterface { } - fn mintPublic( + pub fn mintPublic( self, context: PublicContext, amount: Field, @@ -214,7 +214,7 @@ impl NonNativeTokenPublicContextInterface { } - fn shield( + pub fn shield( self, context: PublicContext, amount: Field, @@ -228,7 +228,7 @@ impl NonNativeTokenPublicContextInterface { } - fn withdrawPublic( + pub fn withdrawPublic( self, context: PublicContext, amount: Field, diff --git a/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/transparent_note.nr b/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/transparent_note.nr index 2c9bcbe2461..a5ac0bf85a5 100644 --- a/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/transparent_note.nr +++ b/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/transparent_note.nr @@ -23,7 +23,7 @@ impl TransparentNote { // CONSTRUCTORS - fn new(amount: Field, secret_hash: Field) -> Self { + pub fn new(amount: Field, secret_hash: Field) -> Self { TransparentNote { amount: amount, secret_hash: secret_hash, @@ -34,7 +34,7 @@ impl TransparentNote { // new oracle call primitive // get me the secret corresponding to this hash - fn new_from_secret(amount: Field, secret: Field) -> Self { + pub fn new_from_secret(amount: Field, secret: Field) -> Self { TransparentNote { amount: amount, secret_hash: TransparentNote::compute_secret_hash(secret), @@ -46,11 +46,11 @@ impl TransparentNote { // STANDARD NOTE_INTERFACE FUNCTIONS - fn serialize(self) -> [Field; TRANSPARENT_NOTE_LEN] { + pub fn serialize(self) -> [Field; TRANSPARENT_NOTE_LEN] { [self.amount, self.secret_hash] } - fn deserialize(preimage: [Field; TRANSPARENT_NOTE_LEN]) -> Self { + pub fn deserialize(preimage: [Field; TRANSPARENT_NOTE_LEN]) -> Self { TransparentNote { amount: preimage[0], secret_hash: preimage[1], @@ -59,7 +59,7 @@ impl TransparentNote { } } - fn compute_note_hash(self) -> Field { + pub fn compute_note_hash(self) -> Field { // TODO(#1205) Should use a non-zero generator index. dep::std::hash::pedersen([ self.amount, @@ -67,7 +67,7 @@ impl TransparentNote { ])[0] } - fn compute_nullifier(self) -> Field { + pub fn compute_nullifier(self) -> Field { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): should use // `compute_note_hash_for_read_or_nullify` once public functions inject nonce! let siloed_note_hash = compute_siloed_note_hash(TransparentNoteMethods, self); @@ -75,19 +75,19 @@ impl TransparentNote { pedersen([self.secret, siloed_note_hash])[0] } - fn set_header(&mut self, header: NoteHeader) { + pub fn set_header(&mut self, header: NoteHeader) { self.header = header; } // CUSTOM FUNCTIONS FOR THIS NOTE TYPE - fn compute_secret_hash(secret: Field) -> Field { + pub fn compute_secret_hash(secret: Field) -> Field { // TODO(#1205) This is probably not the right index to use pedersen_with_separator([secret], GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET)[0] } - fn knows_secret(self, secret: Field) { + pub fn knows_secret(self, secret: Field) { let hash = TransparentNote::compute_secret_hash(secret); assert(self.secret_hash == hash); } diff --git a/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/address_note.nr b/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/address_note.nr index e931dcb04d1..602f5e343d9 100644 --- a/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/address_note.nr +++ b/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/address_note.nr @@ -11,20 +11,20 @@ struct AddressNote { } impl AddressNote { - fn new(address: Field) -> Self { + pub fn new(address: Field) -> Self { AddressNote { address, header: NoteHeader::empty(), } } - fn serialize(self) -> [Field; ADDRESS_NOTE_LEN] { + pub fn serialize(self) -> [Field; ADDRESS_NOTE_LEN] { let mut res: [Field; ADDRESS_NOTE_LEN] = [0; ADDRESS_NOTE_LEN]; res[0] = self.address; res } - fn compute_nullifier(self) -> Field { + pub fn compute_nullifier(self) -> Field { let unique_siloed_note_hash = compute_unique_siloed_note_hash(AddressNoteMethods, self); let secret = get_secret_key(self.address); // TODO(#1205) Should use a non-zero generator index. @@ -35,7 +35,7 @@ impl AddressNote { ])[0] } - fn set_header(&mut self, header: NoteHeader) { + pub fn set_header(&mut self, header: NoteHeader) { self.header = header; } } diff --git a/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/claim_note.nr b/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/claim_note.nr index 1126e440580..2fe27299969 100644 --- a/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/claim_note.nr +++ b/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/claim_note.nr @@ -14,7 +14,7 @@ struct ClaimNote { } impl ClaimNote { - fn new(value: Field, secret_hash: Field) -> Self { + pub fn new(value: Field, secret_hash: Field) -> Self { ClaimNote { value, secret_hash, @@ -22,11 +22,11 @@ impl ClaimNote { } } - fn serialize(self) -> [Field; CLAIM_NOTE_LEN] { + pub fn serialize(self) -> [Field; CLAIM_NOTE_LEN] { [self.value, self.secret_hash] } - fn deserialize(preimage: [Field; CLAIM_NOTE_LEN]) -> Self { + pub fn deserialize(preimage: [Field; CLAIM_NOTE_LEN]) -> Self { ClaimNote { value: preimage[0], secret_hash: preimage[1], @@ -34,7 +34,7 @@ impl ClaimNote { } } - fn compute_note_hash(self) -> Field { + pub fn compute_note_hash(self) -> Field { // TODO(#1205) Should use a non-zero generator index. dep::std::hash::pedersen([ self.value, @@ -42,7 +42,7 @@ impl ClaimNote { ])[0] } - fn compute_nullifier(self) -> Field { + pub fn compute_nullifier(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_read_or_nullify(ClaimNoteMethods, self); // TODO(#1205) Should use a non-zero generator index. dep::std::hash::pedersen([ @@ -51,7 +51,7 @@ impl ClaimNote { ])[0] } - fn set_header(&mut self, header: NoteHeader) { + pub fn set_header(&mut self, header: NoteHeader) { self.header = header; } } diff --git a/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/interface.nr b/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/interface.nr index babfad8d325..1c6bc62fb5a 100644 --- a/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/interface.nr +++ b/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/interface.nr @@ -12,13 +12,13 @@ struct PrivateTokenAirdropPrivateContextInterface { } impl PrivateTokenAirdropPrivateContextInterface { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address, } } - fn batchTransfer( + pub fn batchTransfer( self, context: &mut PrivateContext, sender: Field, @@ -40,7 +40,7 @@ impl PrivateTokenAirdropPrivateContextInterface { } - fn burn( + pub fn burn( self, context: &mut PrivateContext, amount: Field, @@ -54,7 +54,7 @@ impl PrivateTokenAirdropPrivateContextInterface { } - fn claim( + pub fn claim( self, context: &mut PrivateContext, amount: Field, @@ -68,7 +68,7 @@ impl PrivateTokenAirdropPrivateContextInterface { } - fn createClaims( + pub fn createClaims( self, context: &mut PrivateContext, amounts: [Field;16], @@ -112,7 +112,7 @@ impl PrivateTokenAirdropPrivateContextInterface { } - fn mint( + pub fn mint( self, context: &mut PrivateContext, amount: Field, @@ -126,7 +126,7 @@ impl PrivateTokenAirdropPrivateContextInterface { } - fn transfer( + pub fn transfer( self, context: &mut PrivateContext, amount: Field, @@ -150,7 +150,7 @@ struct PrivateTokenAirdropPublicContextInterface { } impl PrivateTokenAirdropPublicContextInterface { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address, } diff --git a/yarn-project/noir-contracts/src/contracts/private_token_contract/src/interface.nr b/yarn-project/noir-contracts/src/contracts/private_token_contract/src/interface.nr index 0f59f541a24..19b526671a3 100644 --- a/yarn-project/noir-contracts/src/contracts/private_token_contract/src/interface.nr +++ b/yarn-project/noir-contracts/src/contracts/private_token_contract/src/interface.nr @@ -12,13 +12,13 @@ struct PrivateTokenPrivateContextInterface { } impl PrivateTokenPrivateContextInterface { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address, } } - fn mint( + pub fn mint( self, context: &mut PrivateContext, amount: Field, @@ -32,7 +32,7 @@ impl PrivateTokenPrivateContextInterface { } - fn transfer( + pub fn transfer( self, context: &mut PrivateContext, amount: Field, @@ -56,7 +56,7 @@ struct PrivateTokenPublicContextInterface { } impl PrivateTokenPublicContextInterface { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address, } diff --git a/yarn-project/noir-contracts/src/contracts/schnorr_account_contract/src/public_key_note.nr b/yarn-project/noir-contracts/src/contracts/schnorr_account_contract/src/public_key_note.nr index ceb64ac8cb4..54e3f3fc9a0 100644 --- a/yarn-project/noir-contracts/src/contracts/schnorr_account_contract/src/public_key_note.nr +++ b/yarn-project/noir-contracts/src/contracts/schnorr_account_contract/src/public_key_note.nr @@ -15,7 +15,7 @@ struct PublicKeyNote { } impl PublicKeyNote { - fn new(x: Field, y: Field, owner: Field) -> Self { + pub fn new(x: Field, y: Field, owner: Field) -> Self { PublicKeyNote { x, y, @@ -25,11 +25,11 @@ impl PublicKeyNote { } // serialize the note as 3 fields - fn serialize(self) -> [Field; PUBLIC_KEY_NOTE_LEN] { + pub fn serialize(self) -> [Field; PUBLIC_KEY_NOTE_LEN] { [self.x, self.y, self.owner] } - fn compute_nullifier(self) -> Field { + pub fn compute_nullifier(self) -> Field { let unique_siloed_note_hash = compute_unique_siloed_note_hash(PublicKeyNoteMethods, self); let secret = get_secret_key(self.owner); // TODO(#1205) Should use a non-zero generator index. @@ -40,7 +40,7 @@ impl PublicKeyNote { ])[0] } - fn set_header(&mut self, header: NoteHeader) { + pub fn set_header(&mut self, header: NoteHeader) { self.header = header; } } diff --git a/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/auth_oracle.nr b/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/auth_oracle.nr index 878da45b183..2cb544a4502 100644 --- a/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/auth_oracle.nr +++ b/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/auth_oracle.nr @@ -21,7 +21,7 @@ impl AuthWitness { } } -unconstrained fn get_auth_witness(message_hash: Field) -> AuthWitness { +unconstrained pub fn get_auth_witness(message_hash: Field) -> AuthWitness { let witness: [Field; 67] = auth_witness::get_auth_witness(message_hash); AuthWitness::deserialize(witness) } \ No newline at end of file diff --git a/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/util.nr b/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/util.nr index 2c0a21c342d..3b814373567 100644 --- a/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/util.nr +++ b/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/util.nr @@ -2,7 +2,7 @@ use dep::std::{schnorr::verify_signature}; use dep::aztec::address::compute_address; use crate::auth_oracle::{AuthWitness}; -fn recover_address( +pub fn recover_address( message_hash: Field, witness: AuthWitness, ) -> Field { diff --git a/yarn-project/noir-contracts/src/contracts/test_contract/src/interface.nr b/yarn-project/noir-contracts/src/contracts/test_contract/src/interface.nr index 453b7f399cc..51b6abea779 100644 --- a/yarn-project/noir-contracts/src/contracts/test_contract/src/interface.nr +++ b/yarn-project/noir-contracts/src/contracts/test_contract/src/interface.nr @@ -33,13 +33,13 @@ struct TestPrivateContextInterface { } impl TestPrivateContextInterface { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address, } } - fn createL2ToL1MessagePublic( + pub fn createL2ToL1MessagePublic( self, context: &mut PrivateContext, amount: Field, @@ -53,7 +53,7 @@ impl TestPrivateContextInterface { } - fn createNullifierPublic( + pub fn createNullifierPublic( self, context: &mut PrivateContext, amount: Field, @@ -67,7 +67,7 @@ impl TestPrivateContextInterface { } - fn emit_nullifier( + pub fn emit_nullifier( self, context: &mut PrivateContext, nullifier: Field @@ -79,7 +79,7 @@ impl TestPrivateContextInterface { } - fn emit_unencrypted( + pub fn emit_unencrypted( self, context: &mut PrivateContext, value: Field @@ -91,7 +91,7 @@ impl TestPrivateContextInterface { } - fn getPortalContractAddress( + pub fn getPortalContractAddress( self, context: &mut PrivateContext, aztec_address: Field @@ -103,7 +103,7 @@ impl TestPrivateContextInterface { } - fn getPublicKey( + pub fn getPublicKey( self, context: &mut PrivateContext, address: Field @@ -115,7 +115,7 @@ impl TestPrivateContextInterface { } - fn getThisAddress( + pub fn getThisAddress( self, context: &mut PrivateContext ) -> [Field; RETURN_VALUES_LENGTH] { @@ -125,7 +125,7 @@ impl TestPrivateContextInterface { } - fn getThisPortalAddress( + pub fn getThisPortalAddress( self, context: &mut PrivateContext ) -> [Field; RETURN_VALUES_LENGTH] { @@ -135,7 +135,7 @@ impl TestPrivateContextInterface { } - fn isTimeEqual( + pub fn isTimeEqual( self, context: &mut PrivateContext, time: Field @@ -147,7 +147,7 @@ impl TestPrivateContextInterface { } - fn testCodeGen( + pub fn testCodeGen( self, context: &mut PrivateContext, aField: Field, @@ -190,13 +190,13 @@ struct TestPublicContextInterface { } impl TestPublicContextInterface { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address, } } - fn createL2ToL1MessagePublic( + pub fn createL2ToL1MessagePublic( self, context: PublicContext, amount: Field, @@ -210,7 +210,7 @@ impl TestPublicContextInterface { } - fn createNullifierPublic( + pub fn createNullifierPublic( self, context: PublicContext, amount: Field, @@ -224,7 +224,7 @@ impl TestPublicContextInterface { } - fn emit_unencrypted( + pub fn emit_unencrypted( self, context: PublicContext, value: Field @@ -236,7 +236,7 @@ impl TestPublicContextInterface { } - fn isTimeEqual( + pub fn isTimeEqual( self, context: PublicContext, time: Field diff --git a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/token_interface.nr b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/token_interface.nr index e0a17779f77..f4d89558415 100644 --- a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/token_interface.nr +++ b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/token_interface.nr @@ -8,11 +8,11 @@ struct Token { } impl Token { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address } } - fn mint_public(self: Self, context: PublicContext, to: Field, amount: Field) { + pub fn mint_public(self: Self, context: PublicContext, to: Field, amount: Field) { let _return_values = context.call_public_function( self.address, compute_selector("mint_public((Field),Field)"), @@ -21,7 +21,7 @@ impl Token { } // docs:start:public_burn_interface - fn burn_public(self: Self, context: PublicContext, from: Field, amount: Field, nonce: Field) { + pub fn burn_public(self: Self, context: PublicContext, from: Field, amount: Field, nonce: Field) { let _return_values = context.call_public_function( self.address, compute_selector("burn_public((Field),Field,Field)"), @@ -30,7 +30,7 @@ impl Token { } // docs:end:public_burn_interface - fn mint_private(self: Self, context: PublicContext, amount: Field, secret_hash: Field) { + pub fn mint_private(self: Self, context: PublicContext, amount: Field, secret_hash: Field) { let _return_values = context.call_public_function( self.address, compute_selector("mint_private(Field,Field)"), @@ -40,7 +40,7 @@ impl Token { // docs:start:private_burn_interface - fn burn(self: Self, context: &mut PrivateContext, from: Field, amount: Field, nonce: Field) { + pub fn burn(self: Self, context: &mut PrivateContext, from: Field, amount: Field, nonce: Field) { let _return_values = context.call_private_function( self.address, compute_selector("burn((Field),Field,Field)"), diff --git a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/util.nr b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/util.nr index f03bed15094..e58879f7034 100644 --- a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/util.nr +++ b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/util.nr @@ -4,7 +4,7 @@ use dep::aztec::hash::{sha256_to_field}; // Computes a content hash of a deposit/mint_public message. // Refer TokenPortal.sol for reference on L1. -fn get_mint_public_content_hash(owner_address: Field, amount: Field, canceller: Field) -> Field { +pub fn get_mint_public_content_hash(owner_address: Field, amount: Field, canceller: Field) -> Field { let mut hash_bytes: [u8; 100] = [0; 100]; let amount_bytes = amount.to_be_bytes(32); @@ -30,7 +30,7 @@ fn get_mint_public_content_hash(owner_address: Field, amount: Field, canceller: // Computes a content hash of a deposit/mint_private message. // Refer TokenPortal.sol for reference on L1. -fn get_mint_private_content_hash(amount: Field, secret_hash_for_redeeming_minted_notes: Field, canceller: Field) -> Field { +pub fn get_mint_private_content_hash(amount: Field, secret_hash_for_redeeming_minted_notes: Field, canceller: Field) -> Field { let mut hash_bytes: [u8; 100] = [0; 100]; let amount_bytes = amount.to_be_bytes(32); let secret_hash_bytes = secret_hash_for_redeeming_minted_notes.to_be_bytes(32); @@ -53,7 +53,7 @@ fn get_mint_private_content_hash(amount: Field, secret_hash_for_redeeming_minted } // Computes a content hash of a withdraw message. -fn get_withdraw_content_hash(recipient: Field, amount: Field, callerOnL1: Field) -> Field { +pub fn get_withdraw_content_hash(recipient: Field, amount: Field, callerOnL1: Field) -> Field { // Compute the content hash // Compute sha256(selector || amount || recipient) // then convert to a single field element diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/balance_set.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/balance_set.nr index 3789e62c96a..240b8a3a8c4 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/balance_set.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/balance_set.nr @@ -35,7 +35,7 @@ struct BalanceSet { } impl BalanceSet { - fn new(context: Context, owner: AztecAddress, storage_slot: Field) -> Self { + pub fn new(context: Context, owner: AztecAddress, storage_slot: Field) -> Self { assert(storage_slot != 0, "Storage slot 0 not allowed. Storage slots must start from 1."); let set = Set { context, @@ -49,11 +49,11 @@ impl BalanceSet { } } - unconstrained fn balance_of(self: Self) -> SafeU120 { + unconstrained pub fn balance_of(self: Self) -> SafeU120 { self.balance_of_with_offset(0) } - unconstrained fn balance_of_with_offset(self: Self, offset: u32) -> SafeU120 { + unconstrained pub fn balance_of_with_offset(self: Self, offset: u32) -> SafeU120 { // Same as SafeU120::new(0), but fewer constraints because no check. let mut balance = SafeU120::min(); // docs:start:view_notes @@ -73,7 +73,7 @@ impl BalanceSet { balance } - fn add(self: Self, addend: SafeU120) { + pub fn add(self: Self, addend: SafeU120) { let mut addend_note = TokenNote::new(addend, self.owner); // docs:start:insert @@ -86,7 +86,7 @@ impl BalanceSet { ); } - fn sub(self: Self, subtrahend: SafeU120) { + pub fn sub(self: Self, subtrahend: SafeU120) { // docs:start:get_notes let options = NoteGetterOptions::with_filter(filter_notes_min_sum, subtrahend); let maybe_notes = self.set.get_notes(options); @@ -118,7 +118,7 @@ impl BalanceSet { } } -fn filter_notes_min_sum(notes: [Option; MAX_READ_REQUESTS_PER_CALL], min_sum: SafeU120) -> [Option; MAX_READ_REQUESTS_PER_CALL] { +pub fn filter_notes_min_sum(notes: [Option; MAX_READ_REQUESTS_PER_CALL], min_sum: SafeU120) -> [Option; MAX_READ_REQUESTS_PER_CALL] { let mut selected = [Option::none(); MAX_READ_REQUESTS_PER_CALL]; let mut sum = SafeU120::min(); for i in 0..notes.len() { diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/balances_map.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/balances_map.nr index fef342cbea7..dfcdfb3fbd3 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/balances_map.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/balances_map.nr @@ -9,7 +9,7 @@ struct BalancesMap { } impl BalancesMap { - fn new( + pub fn new( context: Context, storage_slot: Field, ) -> Self { @@ -20,7 +20,7 @@ impl BalancesMap { } } - fn at(self, owner: AztecAddress) -> BalanceSet { + pub fn at(self, owner: AztecAddress) -> BalanceSet { let derived_storage_slot = dep::std::hash::pedersen([self.storage_slot, owner.address])[0]; BalanceSet::new(self.context, owner, derived_storage_slot) } diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/token_note.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/token_note.nr index 1322f248332..fdc147adf1a 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/token_note.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/token_note.nr @@ -36,7 +36,7 @@ struct TokenNote { } impl TokenNote { - fn new(amount: SafeU120, owner: AztecAddress) -> Self { + pub fn new(amount: SafeU120, owner: AztecAddress) -> Self { Self { amount, owner, @@ -45,11 +45,11 @@ impl TokenNote { } } - fn serialize(self) -> [Field; TOKEN_NOTE_LEN] { + pub fn serialize(self) -> [Field; TOKEN_NOTE_LEN] { [self.amount.value as Field, self.owner.address, self.randomness] } - fn deserialize(preimage: [Field; TOKEN_NOTE_LEN]) -> Self { + pub fn deserialize(preimage: [Field; TOKEN_NOTE_LEN]) -> Self { Self { amount: SafeU120::new(preimage[0]), owner: AztecAddress::new(preimage[1]), @@ -58,7 +58,7 @@ impl TokenNote { } } - fn compute_note_hash(self) -> Field { + pub fn compute_note_hash(self) -> Field { // TODO(#1205) Should use a non-zero generator index. dep::std::hash::pedersen([ self.amount.value as Field, @@ -68,7 +68,7 @@ impl TokenNote { } // docs:start:nullifier - fn compute_nullifier(self) -> Field { + pub fn compute_nullifier(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_read_or_nullify(TokenNoteMethods, self); let secret = get_secret_key(self.owner.address); // TODO(#1205) Should use a non-zero generator index. @@ -80,12 +80,12 @@ impl TokenNote { } // docs:end:nullifier - fn set_header(&mut self, header: NoteHeader) { + pub fn set_header(&mut self, header: NoteHeader) { self.header = header; } - fn emit_encrypted( + pub fn emit_encrypted( self: &mut Self, context: &mut PrivateContext, storage_slot: Field, diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/transparent_note.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/transparent_note.nr index bce35b24660..9cee3bf6d23 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/transparent_note.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/transparent_note.nr @@ -24,7 +24,7 @@ impl TransparentNote { // CONSTRUCTORS - fn new(amount: Field, secret_hash: Field) -> Self { + pub fn new(amount: Field, secret_hash: Field) -> Self { TransparentNote { amount: amount, secret_hash: secret_hash, @@ -35,7 +35,7 @@ impl TransparentNote { // new oracle call primitive // get me the secret corresponding to this hash - fn new_from_secret(amount: Field, secret: Field) -> Self { + pub fn new_from_secret(amount: Field, secret: Field) -> Self { TransparentNote { amount: amount, secret_hash: compute_secret_hash(secret), @@ -47,11 +47,11 @@ impl TransparentNote { // STANDARD NOTE_INTERFACE FUNCTIONS - fn serialize(self) -> [Field; TRANSPARENT_NOTE_LEN] { + pub fn serialize(self) -> [Field; TRANSPARENT_NOTE_LEN] { [self.amount, self.secret_hash] } - fn deserialize(preimage: [Field; TRANSPARENT_NOTE_LEN]) -> Self { + pub fn deserialize(preimage: [Field; TRANSPARENT_NOTE_LEN]) -> Self { TransparentNote { amount: preimage[0], secret_hash: preimage[1], @@ -60,7 +60,7 @@ impl TransparentNote { } } - fn compute_note_hash(self) -> Field { + pub fn compute_note_hash(self) -> Field { // TODO(#1205) Should use a non-zero generator index. dep::std::hash::pedersen([ self.amount, @@ -68,21 +68,21 @@ impl TransparentNote { ])[0] } - fn compute_nullifier(self) -> Field { + pub fn compute_nullifier(self) -> Field { // TODO(#1386): should use `compute_note_hash_for_read_or_nullify` once public functions inject nonce! let siloed_note_hash = compute_siloed_note_hash(TransparentNoteMethods, self); // TODO(#1205) Should use a non-zero generator index. pedersen([self.secret, siloed_note_hash])[0] } - fn set_header(&mut self, header: NoteHeader) { + pub fn set_header(&mut self, header: NoteHeader) { self.header = header; } // CUSTOM FUNCTIONS FOR THIS NOTE TYPE - fn knows_secret(self, secret: Field) { + pub fn knows_secret(self, secret: Field) { let hash = compute_secret_hash(secret); assert(self.secret_hash == hash); } diff --git a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/interfaces.nr b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/interfaces.nr index 24feb699e48..7742785694e 100644 --- a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/interfaces.nr +++ b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/interfaces.nr @@ -9,11 +9,11 @@ struct Token { } impl Token { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address } } - fn transfer_public(self: Self, context: PublicContext, from: Field, to: Field, amount: Field, nonce: Field) { + pub fn transfer_public(self: Self, context: PublicContext, from: Field, to: Field, amount: Field, nonce: Field) { let _transfer_return_values = context.call_public_function( self.address, compute_selector("transfer_public((Field),(Field),Field,Field)"), @@ -21,7 +21,7 @@ impl Token { ); } - fn unshield(self: Self, context: &mut PrivateContext, from: Field, to: Field, amount: Field, nonce: Field) { + pub fn unshield(self: Self, context: &mut PrivateContext, from: Field, to: Field, amount: Field, nonce: Field) { let _return_values = context.call_private_function( self.address, compute_selector("unshield((Field),(Field),Field,Field)"), @@ -35,16 +35,16 @@ struct TokenBridge { } impl TokenBridge { - fn at(address: Field) -> Self { + pub fn at(address: Field) -> Self { Self { address } } - fn token(self: Self, context: PublicContext) -> AztecAddress { + pub fn token(self: Self, context: PublicContext) -> AztecAddress { let return_values = context.call_public_function(self.address, compute_selector("get_token()"), []); AztecAddress::new(return_values[0]) } - fn claim_public(self: Self, context: PublicContext, to: Field, amount: Field, canceller: Field, msg_key: Field, secret: Field) { + pub fn claim_public(self: Self, context: PublicContext, to: Field, amount: Field, canceller: Field, msg_key: Field, secret: Field) { let _return_values = context.call_public_function( self.address, compute_selector("claim_public((Field),Field,Field,Field,Field)"), @@ -52,7 +52,7 @@ impl TokenBridge { ); } - fn exit_to_l1_public(self: Self, context: PublicContext, recipient: Field, amount: Field, callerOnL1: Field, nonce: Field) { + pub fn exit_to_l1_public(self: Self, context: PublicContext, recipient: Field, amount: Field, callerOnL1: Field, nonce: Field) { let _return_values = context.call_public_function( self.address, compute_selector("exit_to_l1_public((Field),Field,(Field),Field)"), diff --git a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/util.nr b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/util.nr index 8d51e11679b..4d9a1cd845f 100644 --- a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/util.nr +++ b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/util.nr @@ -2,7 +2,7 @@ use dep::aztec::hash::sha256_to_field; // This method computes the L2 to L1 message content hash for the private // refer `l1-contracts/test/portals/UniswapPortal.sol` on how L2 to L1 message is expected -fn compute_swap_private_content_hash( +pub fn compute_swap_private_content_hash( input_asset_bridge_portal_address: Field, input_amount: Field, uniswap_fee_tier: Field, @@ -51,7 +51,7 @@ fn compute_swap_private_content_hash( // This method computes the L2 to L1 message content hash for the public // refer `l1-contracts/test/portals/UniswapPortal.sol` on how L2 to L1 message is expected -fn compute_swap_public_content_hash( +pub fn compute_swap_public_content_hash( input_asset_bridge_portal_address: Field, input_amount: Field, uniswap_fee_tier: Field, From 502ee872d6360bf4bc5b83c672eeb64c58944073 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 9 Oct 2023 13:07:48 +0100 Subject: [PATCH 3/4] chore: bump ACIR deserializer (#2675) This PR updates the deserializer to match that currently on Noir master. We're just renaming the C++ structs created so this should be a non-breaking change. --- .../dsl/acir_format/serde/acir.hpp | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index 92839b90ec2..6867fefbcae 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -712,7 +712,7 @@ struct BrilligOutputs { static BrilligOutputs bincodeDeserialize(std::vector); }; -struct ForeignCallOutput { +struct ForeignCallParam { struct Single { Circuit::Value value; @@ -732,13 +732,13 @@ struct ForeignCallOutput { std::variant value; - friend bool operator==(const ForeignCallOutput&, const ForeignCallOutput&); + friend bool operator==(const ForeignCallParam&, const ForeignCallParam&); std::vector bincodeSerialize() const; - static ForeignCallOutput bincodeDeserialize(std::vector); + static ForeignCallParam bincodeDeserialize(std::vector); }; struct ForeignCallResult { - std::vector values; + std::vector values; friend bool operator==(const ForeignCallResult&, const ForeignCallResult&); std::vector bincodeSerialize() const; @@ -4758,7 +4758,7 @@ Circuit::Expression serde::Deserializable::deserialize(Dese namespace Circuit { -inline bool operator==(const ForeignCallOutput& lhs, const ForeignCallOutput& rhs) +inline bool operator==(const ForeignCallParam& lhs, const ForeignCallParam& rhs) { if (!(lhs.value == rhs.value)) { return false; @@ -4766,17 +4766,17 @@ inline bool operator==(const ForeignCallOutput& lhs, const ForeignCallOutput& rh return true; } -inline std::vector ForeignCallOutput::bincodeSerialize() const +inline std::vector ForeignCallParam::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } -inline ForeignCallOutput ForeignCallOutput::bincodeDeserialize(std::vector input) +inline ForeignCallParam ForeignCallParam::bincodeDeserialize(std::vector input) { auto deserializer = serde::BincodeDeserializer(input); - auto value = serde::Deserializable::deserialize(deserializer); + auto value = serde::Deserializable::deserialize(deserializer); if (deserializer.get_buffer_offset() < input.size()) { throw_or_abort("Some input bytes were not read"); } @@ -4787,8 +4787,8 @@ inline ForeignCallOutput ForeignCallOutput::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Circuit::ForeignCallOutput& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Circuit::ForeignCallParam& obj, + Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -4797,10 +4797,10 @@ void serde::Serializable::serialize(const Circuit::F template <> template -Circuit::ForeignCallOutput serde::Deserializable::deserialize(Deserializer& deserializer) +Circuit::ForeignCallParam serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Circuit::ForeignCallOutput obj; + Circuit::ForeignCallParam obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; @@ -4808,7 +4808,7 @@ Circuit::ForeignCallOutput serde::Deserializable::de namespace Circuit { -inline bool operator==(const ForeignCallOutput::Single& lhs, const ForeignCallOutput::Single& rhs) +inline bool operator==(const ForeignCallParam::Single& lhs, const ForeignCallParam::Single& rhs) { if (!(lhs.value == rhs.value)) { return false; @@ -4816,17 +4816,17 @@ inline bool operator==(const ForeignCallOutput::Single& lhs, const ForeignCallOu return true; } -inline std::vector ForeignCallOutput::Single::bincodeSerialize() const +inline std::vector ForeignCallParam::Single::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } -inline ForeignCallOutput::Single ForeignCallOutput::Single::bincodeDeserialize(std::vector input) +inline ForeignCallParam::Single ForeignCallParam::Single::bincodeDeserialize(std::vector input) { auto deserializer = serde::BincodeDeserializer(input); - auto value = serde::Deserializable::deserialize(deserializer); + auto value = serde::Deserializable::deserialize(deserializer); if (deserializer.get_buffer_offset() < input.size()) { throw_or_abort("Some input bytes were not read"); } @@ -4837,25 +4837,25 @@ inline ForeignCallOutput::Single ForeignCallOutput::Single::bincodeDeserialize(s template <> template -void serde::Serializable::serialize(const Circuit::ForeignCallOutput::Single& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Circuit::ForeignCallParam::Single& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::ForeignCallOutput::Single serde::Deserializable::deserialize( +Circuit::ForeignCallParam::Single serde::Deserializable::deserialize( Deserializer& deserializer) { - Circuit::ForeignCallOutput::Single obj; + Circuit::ForeignCallParam::Single obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } namespace Circuit { -inline bool operator==(const ForeignCallOutput::Array& lhs, const ForeignCallOutput::Array& rhs) +inline bool operator==(const ForeignCallParam::Array& lhs, const ForeignCallParam::Array& rhs) { if (!(lhs.value == rhs.value)) { return false; @@ -4863,17 +4863,17 @@ inline bool operator==(const ForeignCallOutput::Array& lhs, const ForeignCallOut return true; } -inline std::vector ForeignCallOutput::Array::bincodeSerialize() const +inline std::vector ForeignCallParam::Array::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } -inline ForeignCallOutput::Array ForeignCallOutput::Array::bincodeDeserialize(std::vector input) +inline ForeignCallParam::Array ForeignCallParam::Array::bincodeDeserialize(std::vector input) { auto deserializer = serde::BincodeDeserializer(input); - auto value = serde::Deserializable::deserialize(deserializer); + auto value = serde::Deserializable::deserialize(deserializer); if (deserializer.get_buffer_offset() < input.size()) { throw_or_abort("Some input bytes were not read"); } @@ -4884,18 +4884,18 @@ inline ForeignCallOutput::Array ForeignCallOutput::Array::bincodeDeserialize(std template <> template -void serde::Serializable::serialize(const Circuit::ForeignCallOutput::Array& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Circuit::ForeignCallParam::Array& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::ForeignCallOutput::Array serde::Deserializable::deserialize( +Circuit::ForeignCallParam::Array serde::Deserializable::deserialize( Deserializer& deserializer) { - Circuit::ForeignCallOutput::Array obj; + Circuit::ForeignCallParam::Array obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } @@ -6115,4 +6115,4 @@ Circuit::Witness serde::Deserializable::deserialize(Deserializ obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; -} +} \ No newline at end of file From a7710f0849801a85e6907ac0072dd65140ae086a Mon Sep 17 00:00:00 2001 From: Dan Lee <142251406+dan-aztec@users.noreply.github.com> Date: Mon, 9 Oct 2023 05:13:34 -0700 Subject: [PATCH 4/4] chore: add storage slot to docs (#2601) https://github.com/AztecProtocol/aztec-packages/pull/1725#discussion_r1301836610 acir-simulator has oracle calls for read/write public state <- read these to see how storage actually works. see the oracle callback, note write is only available in public context. in aztec-nr, see the oracle-storage.nr (storage read and storage write). --------- Co-authored-by: Maddiaa <47148561+Maddiaa0@users.noreply.github.com> --- .../docs/dev_docs/contracts/syntax/storage.md | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/docs/docs/dev_docs/contracts/syntax/storage.md b/docs/docs/dev_docs/contracts/syntax/storage.md index 88447a7a3c5..77ae0b61338 100644 --- a/docs/docs/dev_docs/contracts/syntax/storage.md +++ b/docs/docs/dev_docs/contracts/syntax/storage.md @@ -2,14 +2,14 @@ title: Storage --- -In an Aztec.nr contract, storage is to be defined as a single struct, that contains both public and private state variables. +In an Aztec.nr contract, storage is contained in a single struct that contains both public and private state variables. -As their name indicates, public state variables can be read by anyone, while private state variables can only be read by their owner, or people whom the owner has shared the data with. +Public state variables can be read by anyone, while private state variables can only be read by their owner (or people whom the owner has shared the decrypted data/note viewing key with). -As mentioned earlier in the foundational concepts ([state model](./../../../concepts/foundation/state_model.md) and [private/public execution](./../../../concepts/foundation/communication/public_private_calls.md)) private state follows a UTXO model. Where note pre-images are only known to those able to decrypt them. +Public state follows the ethereum style account model, where each contract has its own key-value datastore. Private state follows a UTXO model, where note contents (pre-images) are only known by the sender and those able to decrypt them - see ([state model](./../../../concepts/foundation/state_model.md) and [private/public execution](./../../../concepts/foundation/communication/public_private_calls.md)) for more background. :::info -The struct **must** be called `Storage` for the Aztec.nr library to properly handle it (will be fixed in the future to support more flexibility). +The struct **must** be called `Storage` for the Aztec.nr library to properly handle it (this will be relaxed in the future). ::: ```rust @@ -20,10 +20,10 @@ struct Storage { ``` :::info -If your storage includes private state variables it must include a `compute_note_hash_and_nullifier` function to allow the RPC to process encrypted events, see [encrypted events](./events.md#processing-encrypted-events) for more. +If your contract storage includes private state variables, it must include a `compute_note_hash_and_nullifier` function to allow the RPC to process encrypted events. See [encrypted events](./events.md#processing-encrypted-events) for more. ::: -Since Aztec.nr is written in Noir, which on its own is state-less, we need to specify how the storage struct should be initialized to read and write data correctly. This is done by specifying an `init` function that is run in functions that rely on reading or altering the state variables. This `init` function should declare the storage struct with an actual instantiation defining how variables are accessed and manipulated. The function MUST be called `init` for the Aztec.nr library to properly handle it (will be fixed in the future to support more flexibility). +Since Aztec.nr is written in Noir, which on its own is state-less, we need to specify how the storage struct should be initialized to read and write data correctly. This is done by specifying an `init` function that is run in functions that rely on reading or altering the state variables. This `init` function must declare the storage struct with an instantiation defining how variables are accessed and manipulated. The function MUST be called `init` for the Aztec.nr library to properly handle it (this will be relaxed in the future). ```rust impl Storage { @@ -39,12 +39,36 @@ impl Storage { If you have defined a `Storage` struct following this naming scheme, then it will be made available to you through the reserved `storage` keyword within your contract functions. :::warning Using slot `0` is not supported! -No storage values should be initialized at slot `0`. This is a known issue that will be fixed in the future. +No storage values should be initialized at slot `0` - storage slots begin at `1`. This is a known issue that will be fixed in the future. ::: +## Storage Slots + +Public state in Aztec is implemented as a single global merkle tree of depth 254, with each contract's internal storage slot combined with its contract address to generate its position in the global tree as `global_storage_slot = pedersen_hash(contract_storage_slot, contract_address)`. + +A contract's state is represented by mapping its own storage slots to each variable. For now, storage slot positions for each variable must be explicitly assigned inside the `Storage impl`. Although variables can be arrays or structs that are stored internally as contiguous blocks, each variable in the storage definition takes just 1 block, so you can increment the storage slot by 1 each time you add another variable, whether it is public or private. + +When assigning contract storage slots, `Map`s are also treated as occupying only 1 storage slot (its "base_slot"), because the actual values in the global state tree are stored in derived slots calculated as `map_value_storage_slot = pedersen_hash(base_slot, key)`. + +Private state is stored in a separate UTXO tree, but each private variable is still assigned a storage slot to track the meaning of the note. Each private variable's storage slot is contained in a contract's bytecode, but they do not appear at all in the global storage tree. Each contract private variable can be associated with 0, 1, or multiple notes in the UTXO tree (and some of those may have already been spent, if their nullifier is already present in the nullifier tree). +The position of each note in the UTXO tree does not matter - the relationship to contract state is contained entirely in its note header. + +:::info +Private variables only require one single slot, because all notes are linked their contract variable through the `storage slot` attribute in their note header (which also contains the contract address and nonce). ::: + +We currently do not support any "bit packing" type optimizations as in most EVM languages. + +Note: The choice of hash function for global slot position is subject to change in later versions. + ## Map -A `map` is a state variable that "maps" a key to a value. In Aztec.nr, keys are `Field`s (or values that are convertible to Fields) and values can be any type - even other maps. The map is a struct defined as follows: +A `map` is a state variable that "maps" a key to a value. + +:::info +In Aztec.nr, keys are always `Field`s (or types that can be serialized as Fields) and values can be any type - even other maps. +::: + +The map is a struct defined as follows: #include_code map /yarn-project/aztec-nr/aztec/src/state_vars/map.nr rust @@ -113,15 +137,15 @@ When declaring the storage for `T` as a persistent public storage variable, we u #### Single value example -Say that we wish to add `admin` public state variable into our storage struct. In the struct we can add it as follows: +Say that we wish to add `admin` public state variable into our storage struct. In the struct we can define it as: #include_code storage_admin /yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr rust -And then when initializing it in the `Storage::init` function we can do it as follows: +And then when initializing it in the `Storage::init` function we can do: #include_code storage_admin_init /yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr rust -In this case, specifying that we are dealing with a Field, and that it should be put at slot 1. This is just a single value, and would be similar to the following in solidity: +We have specified that we are storing a `Field` that should be placed in storage slot `1`. This is just a single value, and is similar to the following in solidity: ```solidity address internal admin;