From a73c4aacc9c8ecd5a2d83f5d07bdf76bcbb13eed Mon Sep 17 00:00:00 2001 From: Lasse Herskind <16536249+LHerskind@users.noreply.github.com> Date: Wed, 22 Nov 2023 09:00:13 +0000 Subject: [PATCH] chore: formatted `noir-contracts` and `aztec-nr` --- .../aztec-nr/address-note/src/address_note.nr | 2 +- yarn-project/aztec-nr/address-note/src/lib.nr | 2 +- yarn-project/aztec-nr/authwit/src/account.nr | 2 +- yarn-project/aztec-nr/authwit/src/auth.nr | 44 ++--- .../aztec-nr/authwit/src/auth_witness.nr | 2 +- .../aztec-nr/authwit/src/entrypoint.nr | 4 +- yarn-project/aztec-nr/authwit/src/lib.nr | 2 +- yarn-project/aztec-nr/aztec/src/abi.nr | 1 - yarn-project/aztec-nr/aztec/src/address.nr | 5 +- yarn-project/aztec-nr/aztec/src/context.nr | 2 +- yarn-project/aztec-nr/aztec/src/hash.nr | 34 ++-- yarn-project/aztec-nr/aztec/src/lib.nr | 2 +- yarn-project/aztec-nr/aztec/src/log.nr | 12 +- yarn-project/aztec-nr/aztec/src/messaging.nr | 6 +- .../messaging/l1_to_l2_message_getter_data.nr | 12 +- yarn-project/aztec-nr/aztec/src/note.nr | 2 +- .../aztec-nr/aztec/src/note/lifecycle.nr | 12 +- .../aztec-nr/aztec/src/note/note_getter.nr | 64 ++----- .../aztec-nr/aztec/src/note/note_header.nr | 2 +- yarn-project/aztec-nr/aztec/src/note/utils.nr | 27 +-- .../aztec/src/oracle/call_private_function.nr | 20 +- .../aztec-nr/aztec/src/oracle/context.nr | 2 +- .../aztec/src/oracle/create_commitment.nr | 1 - .../oracle/enqueue_public_function_call.nr | 20 +- .../aztec/src/oracle/get_l1_to_l2_message.nr | 3 +- .../aztec/src/oracle/get_public_key.nr | 20 +- .../aztec/src/oracle/get_secret_key.nr | 5 +- .../aztec-nr/aztec/src/oracle/logs.nr | 25 +-- .../aztec-nr/aztec/src/oracle/notes.nr | 59 +++--- .../aztec-nr/aztec/src/oracle/public_call.nr | 18 +- .../aztec-nr/aztec/src/oracle/rand.nr | 2 - .../aztec-nr/aztec/src/oracle/storage.nr | 25 +-- .../aztec/src/private_call_stack_item.nr | 2 +- yarn-project/aztec-nr/aztec/src/selector.nr | 4 +- yarn-project/aztec-nr/aztec/src/state_vars.nr | 2 +- .../aztec/src/state_vars/singleton.nr | 11 +- yarn-project/aztec-nr/aztec/src/types.nr | 2 +- .../aztec-nr/aztec/src/types/address.nr | 2 +- .../aztec-nr/aztec/src/types/point.nr | 7 +- .../aztec_address_serialization.nr | 2 +- .../type_serialization/bool_serialization.nr | 2 +- .../type_serialization/u32_serialization.nr | 2 +- yarn-project/aztec-nr/aztec/src/types/vec.nr | 3 +- yarn-project/aztec-nr/aztec/src/utils.nr | 8 +- .../aztec-nr/easy-private-state/src/lib.nr | 2 +- .../aztec-nr/field-note/src/field_note.nr | 2 +- yarn-project/aztec-nr/field-note/src/lib.nr | 2 +- yarn-project/aztec-nr/safe-math/src/lib.nr | 2 +- .../aztec-nr/safe-math/src/safe_u120.nr | 3 - .../aztec-nr/slow-updates-tree/src/lib.nr | 2 +- .../slow-updates-tree/src/slow_map.nr | 14 +- .../aztec-nr/value-note/src/balance_utils.nr | 2 +- .../aztec-nr/value-note/src/filter.nr | 2 +- yarn-project/aztec-nr/value-note/src/lib.nr | 2 +- yarn-project/aztec-nr/value-note/src/utils.nr | 26 +-- .../benchmarking_contract/src/main.nr | 6 +- .../contracts/card_game_contract/src/cards.nr | 21 +-- .../contracts/card_game_contract/src/game.nr | 22 +-- .../contracts/card_game_contract/src/main.nr | 77 +++----- .../src/contracts/child_contract/src/main.nr | 25 +-- .../contracts/counter_contract/src/main.nr | 47 +++-- .../docs_example_contract/src/actions.nr | 38 +--- .../docs_example_contract/src/main.nr | 67 ++----- .../docs_example_contract/src/options.nr | 44 +---- .../docs_example_contract/src/types.nr | 2 +- .../docs_example_contract/src/types/queen.nr | 5 +- .../easy_private_token_contract/src/main.nr | 26 +-- .../src/ecdsa_public_key_note.nr | 21 +-- .../ecdsa_account_contract/src/main.nr | 18 +- .../src/contracts/escrow_contract/src/main.nr | 18 +- .../import_test_contract/src/main.nr | 35 ++-- .../contracts/lending_contract/src/asset.nr | 4 +- .../contracts/lending_contract/src/helpers.nr | 63 +++---- .../lending_contract/src/interest_math.nr | 19 +- .../lending_contract/src/interfaces.nr | 2 +- .../contracts/lending_contract/src/main.nr | 171 ++++++------------ .../src/contracts/parent_contract/src/main.nr | 73 +++----- .../pending_commitments_contract/src/main.nr | 119 ++++++------ .../price_feed_contract/src/asset.nr | 4 +- .../contracts/price_feed_contract/src/main.nr | 21 +-- .../schnorr_account_contract/src/main.nr | 21 ++- .../src/public_key_note.nr | 9 +- .../src/main.nr | 10 +- .../src/auth_oracle.nr | 2 +- .../src/main.nr | 2 +- .../src/util.nr | 12 +- .../slow_tree_contract/src/capsule.nr | 2 +- .../contracts/slow_tree_contract/src/main.nr | 43 ++--- .../contracts/slow_tree_contract/src/types.nr | 16 +- .../stateful_test_contract/src/main.nr | 19 +- .../contracts/test_contract/src/interface.nr | 9 +- .../src/contracts/test_contract/src/main.nr | 59 ++---- .../src/interfaces.nr | 2 +- .../token_blacklist_contract/src/main.nr | 110 +++-------- .../token_blacklist_contract/src/types.nr | 2 +- .../src/types/balance_set.nr | 2 +- .../src/types/roles.nr | 2 +- .../src/types/safe_u120_serialization.nr | 4 +- .../src/types/token_note.nr | 2 +- .../token_bridge_contract/src/main.nr | 31 ++-- .../src/contracts/token_contract/src/main.nr | 90 ++------- .../src/contracts/token_contract/src/types.nr | 2 +- .../token_contract/src/types/balance_set.nr | 2 +- .../src/types/safe_u120_serialization.nr | 4 +- .../token_contract/src/types/token_note.nr | 2 +- .../contracts/uniswap_contract/src/main.nr | 95 ++++------ .../contracts/uniswap_contract/src/util.nr | 4 +- 107 files changed, 699 insertions(+), 1352 deletions(-) diff --git a/yarn-project/aztec-nr/address-note/src/address_note.nr b/yarn-project/aztec-nr/address-note/src/address_note.nr index 6259cd92f74..90d62ea8760 100644 --- a/yarn-project/aztec-nr/address-note/src/address_note.nr +++ b/yarn-project/aztec-nr/address-note/src/address_note.nr @@ -89,7 +89,7 @@ fn deserialize(serialized_note: [Field; ADDRESS_NOTE_LEN]) -> AddressNote { AddressNote::deserialize(serialized_note) } -fn serialize(note: AddressNote) -> [Field; ADDRESS_NOTE_LEN]{ +fn serialize(note: AddressNote) -> [Field; ADDRESS_NOTE_LEN] { note.serialize() } diff --git a/yarn-project/aztec-nr/address-note/src/lib.nr b/yarn-project/aztec-nr/address-note/src/lib.nr index f016584e48c..5a96025fa25 100644 --- a/yarn-project/aztec-nr/address-note/src/lib.nr +++ b/yarn-project/aztec-nr/address-note/src/lib.nr @@ -1 +1 @@ -mod address_note; \ No newline at end of file +mod address_note; diff --git a/yarn-project/aztec-nr/authwit/src/account.nr b/yarn-project/aztec-nr/authwit/src/account.nr index d2f541c5dff..7a79d089f68 100644 --- a/yarn-project/aztec-nr/authwit/src/account.nr +++ b/yarn-project/aztec-nr/authwit/src/account.nr @@ -66,4 +66,4 @@ impl AccountActions { 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 7094fae9c53..61952330832 100644 --- a/yarn-project/aztec-nr/authwit/src/auth.nr +++ b/yarn-project/aztec-nr/authwit/src/auth.nr @@ -14,54 +14,46 @@ global IS_VALID_PUBLIC_SELECTOR = 0xf3661153; // docs:start:assert_valid_authwit // Assert that `on_behalf_of` have authorized `message_hash` with a valid authentication witness pub fn assert_valid_authwit(context: &mut PrivateContext, on_behalf_of: AztecAddress, message_hash: Field) { - let result = context.call_private_function(on_behalf_of.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"); + let result = context.call_private_function(on_behalf_of.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"); } // docs:end:assert_valid_authwit // docs:start:assert_current_call_valid_authwit // Assert that `on_behalf_of` have authorized the current call with a valid authentication witness pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, on_behalf_of: AztecAddress) { - // message_hash = H(caller, contract_this, selector, args_hash) - let message_hash = pedersen_hash( - [context.msg_sender(), context.this_address(), context.selector(), context.args_hash], - GENERATOR_INDEX__SIGNATURE_PAYLOAD - ); - assert_valid_authwit(context, on_behalf_of, message_hash); + // message_hash = H(caller, contract_this, selector, args_hash) + let message_hash = pedersen_hash([context.msg_sender(), context.this_address(), context.selector(), context.args_hash], + GENERATOR_INDEX__SIGNATURE_PAYLOAD); + assert_valid_authwit(context, on_behalf_of, message_hash); } // docs:end:assert_current_call_valid_authwit // docs:start:assert_valid_authwit_public // Assert that `on_behalf_of` have authorized `message_hash` in a public context pub fn assert_valid_authwit_public(context: &mut PublicContext, on_behalf_of: AztecAddress, message_hash: Field) { - let result = context.call_public_function(on_behalf_of.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"); + let result = context.call_public_function(on_behalf_of.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"); } // docs:end:assert_valid_authwit_public // docs:start:assert_current_call_valid_authwit_public // Assert that `on_behalf_of` have authorized the current call in a public context pub fn assert_current_call_valid_authwit_public(context: &mut PublicContext, on_behalf_of: AztecAddress) { - // message_hash = H(caller, contract_this, selector, args_hash) - let message_hash = pedersen_hash( - [context.msg_sender(), context.this_address(), context.selector(), context.args_hash], - GENERATOR_INDEX__SIGNATURE_PAYLOAD - ); - assert_valid_authwit_public(context, on_behalf_of, message_hash); + // message_hash = H(caller, contract_this, selector, args_hash) + let message_hash = pedersen_hash([context.msg_sender(), context.this_address(), context.selector(), context.args_hash], + GENERATOR_INDEX__SIGNATURE_PAYLOAD); + assert_valid_authwit_public(context, on_behalf_of, message_hash); } // docs:end:assert_current_call_valid_authwit_public // docs:start:compute_authwit_message_hash // Compute the message hash to be used by an authentication witness -pub fn compute_authwit_message_hash( - caller: AztecAddress, - target: AztecAddress, - selector: Field, - args: [Field; N] -) -> Field { - let args_hash = hash_args(args); - pedersen_hash([caller.address, target.address, selector, args_hash], GENERATOR_INDEX__SIGNATURE_PAYLOAD) +pub fn compute_authwit_message_hash(caller: AztecAddress, target: AztecAddress, selector: Field, args: [Field; N]) -> Field { + let args_hash = hash_args(args); + pedersen_hash([caller.address, target.address, selector, args_hash], + GENERATOR_INDEX__SIGNATURE_PAYLOAD) } // docs:end:compute_authwit_message_hash \ 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 7ef0577f28e..e51567a618d 100644 --- a/yarn-project/aztec-nr/authwit/src/auth_witness.nr +++ b/yarn-project/aztec-nr/authwit/src/auth_witness.nr @@ -3,4 +3,4 @@ fn get_auth_witness_oracle(_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/authwit/src/entrypoint.nr b/yarn-project/aztec-nr/authwit/src/entrypoint.nr index 4d97421f2b8..227be7d17fc 100644 --- a/yarn-project/aztec-nr/authwit/src/entrypoint.nr +++ b/yarn-project/aztec-nr/authwit/src/entrypoint.nr @@ -3,7 +3,7 @@ use dep::aztec::types::vec::BoundedVec; use dep::aztec::hash::pedersen_hash; use dep::aztec::context::PrivateContext; use dep::aztec::private_call_stack_item::PrivateCallStackItem; -use dep::aztec::public_call_stack_item::PublicCallStackItem; +use dep::aztec::public_call_stack_item::PublicCallStackItem; use dep::aztec::constants_gen::GENERATOR_INDEX__SIGNATURE_PAYLOAD; global ACCOUNT_MAX_CALLS: Field = 4; @@ -105,4 +105,4 @@ impl EntrypointPayload { } } // docs:end:entrypoint-execute-calls -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/authwit/src/lib.nr b/yarn-project/aztec-nr/authwit/src/lib.nr index ec0b9239404..e56460fd701 100644 --- a/yarn-project/aztec-nr/authwit/src/lib.nr +++ b/yarn-project/aztec-nr/authwit/src/lib.nr @@ -1,4 +1,4 @@ mod account; mod auth_witness; mod auth; -mod entrypoint; \ No newline at end of file +mod entrypoint; diff --git a/yarn-project/aztec-nr/aztec/src/abi.nr b/yarn-project/aztec-nr/aztec/src/abi.nr index 314e5b3fe7e..541dc73cf3a 100644 --- a/yarn-project/aztec-nr/aztec/src/abi.nr +++ b/yarn-project/aztec-nr/aztec/src/abi.nr @@ -302,7 +302,6 @@ impl ContractStorageUpdateRequest { } } - struct PublicCircuitPublicInputs { call_context: CallContext, args_hash: Field, diff --git a/yarn-project/aztec-nr/aztec/src/address.nr b/yarn-project/aztec-nr/aztec/src/address.nr index 162949df483..f1f4224513c 100644 --- a/yarn-project/aztec-nr/aztec/src/address.nr +++ b/yarn-project/aztec-nr/aztec/src/address.nr @@ -2,5 +2,6 @@ use crate::constants_gen::GENERATOR_INDEX__CONTRACT_ADDRESS; use crate::hash::pedersen_hash; pub fn compute_address(pub_key_x: Field, pub_key_y: Field, partial_address: Field) -> Field { - pedersen_hash([pub_key_x, pub_key_y, partial_address], GENERATOR_INDEX__CONTRACT_ADDRESS) -} \ No newline at end of file + pedersen_hash([pub_key_x, pub_key_y, partial_address], + GENERATOR_INDEX__CONTRACT_ADDRESS) +} diff --git a/yarn-project/aztec-nr/aztec/src/context.nr b/yarn-project/aztec-nr/aztec/src/context.nr index 7926e159a3d..a2f34867c6c 100644 --- a/yarn-project/aztec-nr/aztec/src/context.nr +++ b/yarn-project/aztec-nr/aztec/src/context.nr @@ -616,4 +616,4 @@ impl Context { private: Option::none() } } -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/aztec/src/hash.nr b/yarn-project/aztec-nr/aztec/src/hash.nr index 7e3d0071605..f8d3abb51aa 100644 --- a/yarn-project/aztec-nr/aztec/src/hash.nr +++ b/yarn-project/aztec-nr/aztec/src/hash.nr @@ -5,30 +5,30 @@ use crate::constants_gen::{ }; pub fn sha256_to_field(bytes_to_hash: [u8; N]) -> Field { - let sha256_hashed = sha256(bytes_to_hash); + let sha256_hashed = sha256(bytes_to_hash); - // Convert it to a field element - let mut v = 1; - let mut high = 0 as Field; - let mut low = 0 as Field; + // Convert it to a field element + let mut v = 1; + let mut high = 0 as Field; + let mut low = 0 as Field; - for i in 0..16 { - high = high + (sha256_hashed[15 - i] as Field) * v; - low = low + (sha256_hashed[16 + 15 - i] as Field) * v; - v = v * 256; - } + for i in 0..16 { + high = high + (sha256_hashed[15 - i] as Field) * v; + low = low + (sha256_hashed[16 + 15 - i] as Field) * v; + v = v * 256; + } - // Abuse that a % p + b % p = (a + b) % p and that low < p - let hash_in_a_field = low + high * v; + // Abuse that a % p + b % p = (a + b) % p and that low < p + let hash_in_a_field = low + high * v; - hash_in_a_field + hash_in_a_field } pub fn compute_secret_hash(secret: Field) -> Field { - // TODO(#1205) This is probably not the right index to use - pedersen_hash([secret], GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET) + // TODO(#1205) This is probably not the right index to use + pedersen_hash([secret], GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET) } pub fn pedersen_hash(inputs: [Field; N], hash_index: u32) -> Field { - pedersen_hash_with_separator(inputs, hash_index) -} \ No newline at end of file + pedersen_hash_with_separator(inputs, hash_index) +} diff --git a/yarn-project/aztec-nr/aztec/src/lib.nr b/yarn-project/aztec-nr/aztec/src/lib.nr index 10330e9c1d0..d1080f9056f 100644 --- a/yarn-project/aztec-nr/aztec/src/lib.nr +++ b/yarn-project/aztec-nr/aztec/src/lib.nr @@ -12,4 +12,4 @@ mod public_call_stack_item; mod selector; mod state_vars; mod types; -mod utils; \ No newline at end of file +mod utils; diff --git a/yarn-project/aztec-nr/aztec/src/log.nr b/yarn-project/aztec-nr/aztec/src/log.nr index d38775dcb72..35bc5ee690c 100644 --- a/yarn-project/aztec-nr/aztec/src/log.nr +++ b/yarn-project/aztec-nr/aztec/src/log.nr @@ -7,16 +7,13 @@ pub fn emit_encrypted_log( contract_address: Field, storage_slot: Field, encryption_pub_key: Point, - log: [Field; N], + log: [Field; N] ) { let _ = oracle::logs::emit_encrypted_log(contract_address, storage_slot, encryption_pub_key, log); context.accumulate_encrypted_logs(log); } -pub fn emit_unencrypted_log( - context: &mut PublicContext, - log: T, -) { +pub fn emit_unencrypted_log(context: &mut PublicContext, log: T) { let contract_address = context.this_address(); let event_selector = 5; // TODO: compute actual event selector. let _ = oracle::logs::emit_unencrypted_log(contract_address, event_selector, log); @@ -27,10 +24,7 @@ pub 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. -pub fn emit_unencrypted_log_from_private( - context: &mut PrivateContext, - log: T, -) { +pub fn emit_unencrypted_log_from_private(context: &mut PrivateContext, log: T) { let contract_address = context.this_address(); let event_selector = 5; // TODO: compute actual event selector. let _ = oracle::logs::emit_unencrypted_log(contract_address, event_selector, log); diff --git a/yarn-project/aztec-nr/aztec/src/messaging.nr b/yarn-project/aztec-nr/aztec/src/messaging.nr index 7e7aeae4500..185733de9a8 100644 --- a/yarn-project/aztec-nr/aztec/src/messaging.nr +++ b/yarn-project/aztec-nr/aztec/src/messaging.nr @@ -6,10 +6,8 @@ use l1_to_l2_message_getter_data::make_l1_to_l2_message_getter_data; use crate::abi::PublicContextInputs; use crate::oracle::get_l1_to_l2_message::get_l1_to_l2_message_call; - // Returns the nullifier for the message -pub 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); @@ -27,4 +25,4 @@ pub fn process_l1_to_l2_message(l1_to_l2_root: Field, storage_contract_address: // Compute Nullifier l1_to_l2_message_data.message.compute_nullifier() -} \ No newline at end of file +} 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 c8bd586e053..396d758006a 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 @@ -18,9 +18,13 @@ pub fn l1_to_l2_message_getter_len() -> Field { 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]), + 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], - sibling_path: arr_copy_slice(fields, [0; L1_TO_L2_MSG_TREE_HEIGHT], L1_TO_L2_MESSAGE_LENGTH + 1), - root: fields[start + L1_TO_L2_MESSAGE_LENGTH + L1_TO_L2_MSG_TREE_HEIGHT + 1], + sibling_path: arr_copy_slice(fields, + [0; L1_TO_L2_MSG_TREE_HEIGHT], + L1_TO_L2_MESSAGE_LENGTH + 1), + root: fields[start + L1_TO_L2_MESSAGE_LENGTH + L1_TO_L2_MSG_TREE_HEIGHT + 1] } -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/aztec/src/note.nr b/yarn-project/aztec-nr/aztec/src/note.nr index d76f7090689..5df51e71dd4 100644 --- a/yarn-project/aztec-nr/aztec/src/note.nr +++ b/yarn-project/aztec-nr/aztec/src/note.nr @@ -5,4 +5,4 @@ mod note_hash; mod note_header; mod note_interface; mod note_viewer_options; -mod utils; \ No newline at end of file +mod utils; diff --git a/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr b/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr index 2930c4430f7..f44d8ab31ec 100644 --- a/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr +++ b/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr @@ -16,7 +16,7 @@ pub fn create_note( storage_slot: Field, note: &mut Note, note_interface: NoteInterface, - broadcast: bool, + broadcast: bool ) { let contract_address = (*context).this_address(); @@ -41,7 +41,7 @@ pub fn create_note_hash_from_public( context: &mut PublicContext, storage_slot: Field, note: &mut Note, - note_interface: NoteInterface, + note_interface: NoteInterface ) { let contract_address = (*context).this_address(); @@ -53,11 +53,7 @@ pub fn create_note_hash_from_public( context.push_new_note_hash(inner_note_hash); } -pub fn destroy_note( - context: &mut PrivateContext, - note: Note, - note_interface: NoteInterface, -) { +pub fn destroy_note(context: &mut PrivateContext, note: Note, note_interface: NoteInterface) { let mut nullifier = 0; let mut nullified_commitment: Field = EMPTY_NULLIFIED_COMMITMENT; let compute_nullifier = note_interface.compute_nullifier; @@ -78,4 +74,4 @@ pub fn destroy_note( assert(notify_nullified_note(nullifier, nullified_commitment) == 0); context.push_new_nullifier(nullifier, nullified_commitment) -} \ No newline at end of file +} 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 1ed8b14830d..1e5131a22ae 100644 --- a/yarn-project/aztec-nr/aztec/src/note/note_getter.nr +++ b/yarn-project/aztec-nr/aztec/src/note/note_getter.nr @@ -16,12 +16,7 @@ use crate::note::{ use crate::oracle; use crate::types::vec::BoundedVec; -fn check_note_header( - context: PrivateContext, - storage_slot: Field, - note_interface: NoteInterface, - note: Note, -) { +fn check_note_header(context: PrivateContext, storage_slot: Field, note_interface: NoteInterface, note: Note) { let get_header = note_interface.get_header; let header = get_header(note); let contract_address = context.this_address(); @@ -29,10 +24,7 @@ fn check_note_header( assert(header.storage_slot == storage_slot); } -fn check_note_fields( - fields: [Field; N], - selects: BoundedVec, N>, -) { +fn check_note_fields(fields: [Field; N], selects: BoundedVec, N>) { for i in 0..selects.len { let select = selects.get_unchecked(i).unwrap_unchecked(); assert(fields[select.field_index] == select.value, "Mismatch return note field."); @@ -52,11 +44,7 @@ fn check_notes_order(fields_0: [Field; N], fields_1: [Field; N], sorts: Bound } } -pub fn get_note( - context: &mut PrivateContext, - storage_slot: Field, - note_interface: NoteInterface, -) -> Note { +pub fn get_note(context: &mut PrivateContext, storage_slot: Field, note_interface: NoteInterface) -> Note { let note = get_note_internal(storage_slot, note_interface); check_note_header(*context, storage_slot, note_interface, note); @@ -71,7 +59,7 @@ pub fn get_notes( context: &mut PrivateContext, storage_slot: Field, note_interface: NoteInterface, - options: NoteGetterOptions, + options: NoteGetterOptions ) -> [Option; MAX_READ_REQUESTS_PER_CALL] { let opt_notes = get_notes_internal(storage_slot, note_interface, options); let mut num_notes = 0; @@ -96,21 +84,17 @@ pub fn get_notes( num_notes += 1; }; - }; + } if options.limit != 0 { assert(num_notes <= options.limit, "Invalid number of return notes."); } opt_notes } -unconstrained fn get_note_internal( - storage_slot: Field, - note_interface: NoteInterface, -) -> Note { +unconstrained fn get_note_internal(storage_slot: Field, note_interface: NoteInterface) -> Note { let placeholder_note = [Option::none()]; let placeholder_fields = [0; GET_NOTE_ORACLE_RETURN_LENGTH]; - oracle::notes::get_notes( - storage_slot, + oracle::notes::get_notes(storage_slot, note_interface, 0, [], @@ -120,20 +104,18 @@ unconstrained fn get_note_internal( 1, // limit 0, // offset placeholder_note, - placeholder_fields, - )[0].unwrap() // Notice: we don't allow dummies to be returned from get_note (singular). + placeholder_fields)[0].unwrap() // Notice: we don't allow dummies to be returned from get_note (singular). } unconstrained fn get_notes_internal( storage_slot: Field, note_interface: NoteInterface, - options: NoteGetterOptions, + options: NoteGetterOptions ) -> [Option; MAX_READ_REQUESTS_PER_CALL] { let (num_selects, select_by, select_values, sort_by, sort_order) = flatten_options(options.selects, options.sorts); let placeholder_opt_notes = [Option::none(); MAX_READ_REQUESTS_PER_CALL]; let placeholder_fields = [0; GET_NOTES_ORACLE_RETURN_LENGTH]; - let opt_notes = oracle::notes::get_notes( - storage_slot, + let opt_notes = oracle::notes::get_notes(storage_slot, note_interface, num_selects, select_by, @@ -143,24 +125,18 @@ unconstrained fn get_notes_internal( options.limit, options.offset, placeholder_opt_notes, - placeholder_fields, - ); + placeholder_fields); let filter = options.filter; let filter_args = options.filter_args; filter(opt_notes, filter_args) } -unconstrained pub fn view_notes( - storage_slot: Field, - note_interface: NoteInterface, - options: NoteViewerOptions, -) -> [Option; MAX_NOTES_PER_PAGE] { +unconstrained pub fn view_notes(storage_slot: Field, note_interface: NoteInterface, options: NoteViewerOptions) -> [Option; MAX_NOTES_PER_PAGE] { let (num_selects, select_by, select_values, sort_by, sort_order) = flatten_options(options.selects, options.sorts); let placeholder_opt_notes = [Option::none(); MAX_NOTES_PER_PAGE]; let placeholder_fields = [0; VIEW_NOTE_ORACLE_RETURN_LENGTH]; - oracle::notes::get_notes( - storage_slot, + oracle::notes::get_notes(storage_slot, note_interface, num_selects, select_by, @@ -170,14 +146,10 @@ unconstrained pub fn view_notes( options.limit, options.offset, placeholder_opt_notes, - placeholder_fields, - ) + placeholder_fields) } -unconstrained fn flatten_options( - selects: BoundedVec, N>, - sorts: BoundedVec, N>, -) -> (u8, [u8; N], [Field; N], [u8; N], [u2; N]) { +unconstrained fn flatten_options(selects: BoundedVec, N>, sorts: BoundedVec, N>) -> (u8, [u8; N], [Field; N], [u8; N], [u2; N]) { let mut num_selects = 0; let mut select_by = [0; N]; let mut select_values = [0; N]; @@ -188,7 +160,7 @@ unconstrained fn flatten_options( select_values[num_selects] = select.unwrap_unchecked().value; num_selects += 1; }; - }; + } let mut sort_by = [0; N]; let mut sort_order = [0; N]; @@ -198,7 +170,7 @@ unconstrained fn flatten_options( sort_by[i] = sort.unwrap_unchecked().field_index; sort_order[i] = sort.unwrap_unchecked().order; }; - }; + } (num_selects, select_by, select_values, sort_by, sort_order) -} \ No newline at end of file +} 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 6f82cebf149..45450638401 100644 --- a/yarn-project/aztec-nr/aztec/src/note/note_header.nr +++ b/yarn-project/aztec-nr/aztec/src/note/note_header.nr @@ -15,4 +15,4 @@ impl NoteHeader { 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/utils.nr b/yarn-project/aztec-nr/aztec/src/note/utils.nr index 74d006c0a18..bce81ff225e 100644 --- a/yarn-project/aztec-nr/aztec/src/note/utils.nr +++ b/yarn-project/aztec-nr/aztec/src/note/utils.nr @@ -5,10 +5,7 @@ use crate::note::{ }; use crate::utils::arr_copy_slice; -pub fn compute_inner_note_hash( - note_interface: NoteInterface, - note: Note, -) -> Field { +pub fn compute_inner_note_hash(note_interface: NoteInterface, note: Note) -> Field { let get_header = note_interface.get_header; let header = get_header(note); @@ -18,10 +15,7 @@ pub fn compute_inner_note_hash( compute_inner_hash(header.storage_slot, note_hash) } -pub fn compute_siloed_note_hash( - note_interface: NoteInterface, - note_with_header: Note, -) -> Field { +pub fn compute_siloed_note_hash(note_interface: NoteInterface, note_with_header: Note) -> Field { let get_header = note_interface.get_header; let header = get_header(note_with_header); @@ -30,10 +24,7 @@ pub fn compute_siloed_note_hash( compute_siloed_hash(header.contract_address, inner_note_hash) } -pub fn compute_unique_siloed_note_hash( - note_interface: NoteInterface, - note_with_header: Note, -) -> Field { +pub fn compute_unique_siloed_note_hash(note_interface: NoteInterface, note_with_header: Note) -> Field { let get_header = note_interface.get_header; let header = get_header(note_with_header); @@ -42,10 +33,7 @@ pub fn compute_unique_siloed_note_hash( compute_unique_hash(header.nonce, siloed_note_hash) } -pub fn compute_note_hash_for_read_or_nullify( - note_interface: NoteInterface, - note_with_header: Note, -) -> Field { +pub fn compute_note_hash_for_read_or_nullify(note_interface: NoteInterface, note_with_header: Note) -> Field { let get_header = note_interface.get_header; let header = get_header(note_with_header); @@ -63,14 +51,9 @@ pub fn compute_note_hash_for_read_or_nullify( // data tree, so the kernel can just perform a membership check directly on this hash/leaf. compute_unique_siloed_note_hash(note_interface, note_with_header) } - } -pub fn compute_note_hash_and_nullifier( - note_interface: NoteInterface, - note_header: NoteHeader, - serialized_note: [Field; S], -) -> [Field; 4] { +pub fn compute_note_hash_and_nullifier(note_interface: NoteInterface, note_header: NoteHeader, serialized_note: [Field; S]) -> [Field; 4] { let deserialize = note_interface.deserialize; let set_header = note_interface.set_header; let mut note = deserialize(arr_copy_slice(serialized_note, [0; N], 0)); 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 13a9e5f24c5..a5ab1eb95f3 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 @@ -1,20 +1,8 @@ use crate::constants_gen::CALL_PRIVATE_FUNCTION_RETURN_SIZE; #[oracle(callPrivateFunction)] -fn call_private_function_oracle( - _contract_address: Field, - _function_selector: Field, - _args_hash: Field -) -> [Field; CALL_PRIVATE_FUNCTION_RETURN_SIZE] {} +fn call_private_function_oracle(_contract_address: Field, _function_selector: Field, _args_hash: Field) -> [Field; CALL_PRIVATE_FUNCTION_RETURN_SIZE] {} -unconstrained pub fn call_private_function_internal( - contract_address: Field, - function_selector: Field, - args_hash: Field -) -> [Field; CALL_PRIVATE_FUNCTION_RETURN_SIZE] { - call_private_function_oracle( - contract_address, - function_selector, - args_hash, - ) -} \ No newline at end of file +unconstrained pub fn call_private_function_internal(contract_address: Field, function_selector: Field, args_hash: Field) -> [Field; CALL_PRIVATE_FUNCTION_RETURN_SIZE] { + call_private_function_oracle(contract_address, function_selector, args_hash) +} diff --git a/yarn-project/aztec-nr/aztec/src/oracle/context.nr b/yarn-project/aztec-nr/aztec/src/oracle/context.nr index 8200f9fe18a..5895ec26187 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/context.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/context.nr @@ -4,4 +4,4 @@ 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 4f9b99cf716..62c848c1d71 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/create_commitment.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/create_commitment.nr @@ -1,4 +1,3 @@ - #[oracle(createCommitment)] fn create_commitment_oracle(_commitment: Field) -> Field {} 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 17ea7f2f67b..9d6e1cf80e7 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 @@ -7,20 +7,8 @@ global ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE: Field = 13; #[oracle(enqueuePublicFunctionCall)] -fn enqueue_public_function_call_oracle( - _contract_address: Field, - _function_selector: Field, - _args_hash: Field, -) -> [Field; ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE] {} +fn enqueue_public_function_call_oracle(_contract_address: Field, _function_selector: Field, _args_hash: Field) -> [Field; ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE] {} -unconstrained pub fn enqueue_public_function_call_internal( - contract_address: Field, - function_selector: Field, - args_hash: Field -) -> [Field; ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE] { - enqueue_public_function_call_oracle( - contract_address, - function_selector, - args_hash, - ) -} \ No newline at end of file +unconstrained pub fn enqueue_public_function_call_internal(contract_address: Field, function_selector: Field, args_hash: Field) -> [Field; ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_SIZE] { + enqueue_public_function_call_oracle(contract_address, function_selector, args_hash) +} 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 32a1f0e719d..358511db402 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 @@ -1,4 +1,3 @@ - use crate::constants_gen::L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH; // Checks if a msg is within the l1ToL2Msg tree @@ -7,4 +6,4 @@ fn get_l1_to_l2_msg_oracle(_msg_key: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_C 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 5afaa258a21..e2e1684e36f 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 @@ -5,17 +5,17 @@ use crate::address::compute_address; fn get_public_key_and_partial_address_oracle(_address: Field) -> [Field; 3] {} unconstrained fn get_public_key_and_partial_address_internal(address: Field) -> [Field; 3] { - get_public_key_and_partial_address_oracle(address) + get_public_key_and_partial_address_oracle(address) } pub fn get_public_key(address: Field) -> Point { - let result = get_public_key_and_partial_address_internal(address); - let pub_key_x = result[0]; - let pub_key_y = result[1]; - let partial_address = result[2]; - - let calculated_address = compute_address(pub_key_x, pub_key_y, partial_address); - assert(calculated_address == address); - - Point::new(pub_key_x, pub_key_y) + let result = get_public_key_and_partial_address_internal(address); + let pub_key_x = result[0]; + let pub_key_y = result[1]; + let partial_address = result[2]; + + let calculated_address = compute_address(pub_key_x, pub_key_y, partial_address); + assert(calculated_address == address); + + Point::new(pub_key_x, pub_key_y) } 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 4ec21bcf5e8..fb7de3e56ed 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 @@ -2,10 +2,7 @@ use crate::oracle::get_public_key::get_public_key; use crate::types::point::Point; #[oracle(getSecretKey)] -fn get_secret_key_oracle( - _owner: Point, -) -> [Field; dep::std::grumpkin_scalar::GRUMPKIN_SCALAR_SERIALIZED_LEN] { -} +fn get_secret_key_oracle(_owner: Point) -> [Field; dep::std::grumpkin_scalar::GRUMPKIN_SCALAR_SERIALIZED_LEN] {} unconstrained fn get_secret_key_internal(owner_public_key: Point) -> dep::std::grumpkin_scalar::GrumpkinScalar { dep::std::grumpkin_scalar::deserialize_grumpkin_scalar(get_secret_key_oracle(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 bc658e67bdd..caab7b2a13c 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/logs.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/logs.nr @@ -3,31 +3,16 @@ use crate::constants_gen::NUM_FIELDS_PER_SHA256; // TODO: Should take encrypted data. #[oracle(emitEncryptedLog)] -fn emit_encrypted_log_oracle( - _contract_address: Field, - _storage_slot: Field, - _encryption_pub_key: Point, - _preimage: [Field; N], -) -> Field {} +fn emit_encrypted_log_oracle(_contract_address: Field, _storage_slot: Field, _encryption_pub_key: Point, _preimage: [Field; N]) -> Field {} -unconstrained pub fn emit_encrypted_log( - contract_address: Field, - storage_slot: Field, - encryption_pub_key: Point, - preimage: [Field; N], -) -> [Field; NUM_FIELDS_PER_SHA256] { - [emit_encrypted_log_oracle( - contract_address, - storage_slot, - encryption_pub_key, - preimage, - ), 0] +unconstrained pub fn emit_encrypted_log(contract_address: Field, storage_slot: Field, encryption_pub_key: Point, preimage: [Field; N]) -> [Field; NUM_FIELDS_PER_SHA256] { + [emit_encrypted_log_oracle(contract_address, storage_slot, encryption_pub_key, preimage), 0] } #[oracle(emitUnencryptedLog)] -fn emit_unencrypted_log_oracle(_contract_address: Field, _event_selector: Field, _message: T) -> Field {} +fn emit_unencrypted_log_oracle(_contract_address: Field, _event_selector: Field, _message: T) -> Field {} 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 c9e61ee28a2..e3790168cd9 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/notes.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/notes.nr @@ -6,30 +6,16 @@ use crate::note::{ use crate::utils::arr_copy_slice; #[oracle(notifyCreatedNote)] -fn notify_created_note_oracle( - _storage_slot: Field, - _serialized_note: [Field; N], - _inner_note_hash: Field, -) -> Field {} +fn notify_created_note_oracle(_storage_slot: Field, _serialized_note: [Field; N], _inner_note_hash: Field) -> Field {} -unconstrained pub fn notify_created_note( - storage_slot: Field, - serialized_note: [Field; N], - inner_note_hash: Field, -) -> Field { +unconstrained pub fn notify_created_note(storage_slot: Field, serialized_note: [Field; N], inner_note_hash: Field) -> Field { notify_created_note_oracle(storage_slot, serialized_note, inner_note_hash) } #[oracle(notifyNullifiedNote)] -fn notify_nullified_note_oracle( - _nullifier: Field, - _inner_note_hash: Field, -) -> Field {} +fn notify_nullified_note_oracle(_nullifier: Field, _inner_note_hash: Field) -> Field {} -unconstrained pub fn notify_nullified_note( - nullifier: Field, - inner_note_hash: Field, -) -> Field { +unconstrained pub fn notify_nullified_note(nullifier: Field, inner_note_hash: Field) -> Field { notify_nullified_note_oracle(nullifier, inner_note_hash) } @@ -44,7 +30,7 @@ fn get_notes_oracle( _limit: u32, _offset: u32, _return_size: u32, - _placeholder_fields: [Field; S], + _placeholder_fields: [Field; S] ) -> [Field; S] {} unconstrained fn get_notes_oracle_wrapper( @@ -56,10 +42,19 @@ unconstrained fn get_notes_oracle_wrapper( sort_order: [u2; N], limit: u32, offset: u32, - mut placeholder_fields: [Field; S], -)-> [Field; S] { + mut placeholder_fields: [Field; S] +) -> [Field; S] { let return_size = placeholder_fields.len() as u32; - get_notes_oracle(storage_slot, num_selects, select_by, select_values, sort_by, sort_order, limit, offset, return_size, placeholder_fields) + get_notes_oracle(storage_slot, + num_selects, + select_by, + select_values, + sort_by, + sort_order, + limit, + offset, + return_size, + placeholder_fields) } unconstrained pub fn get_notes( @@ -73,9 +68,17 @@ unconstrained pub fn get_notes( limit: u32, offset: u32, mut placeholder_opt_notes: [Option; S], // TODO: Remove it and use `limit` to initialize the note array. - placeholder_fields: [Field; NS], // TODO: Remove it and use `limit` to initialize the note array. + placeholder_fields: [Field; NS] // TODO: Remove it and use `limit` to initialize the note array. ) -> [Option; S] { - let fields = get_notes_oracle_wrapper(storage_slot, num_selects, select_by, select_values, sort_by, sort_order, limit, offset, placeholder_fields); + let fields = get_notes_oracle_wrapper(storage_slot, + num_selects, + select_by, + select_values, + sort_by, + sort_order, + limit, + offset, + placeholder_fields); let num_notes = fields[0] as u32; let contract_address = fields[1]; let deserialize = note_interface.deserialize; @@ -94,15 +97,13 @@ unconstrained pub fn get_notes( set_header(&mut note, header); placeholder_opt_notes[i] = Option::some(note); }; - }; + } placeholder_opt_notes } #[oracle(checkNullifierExists)] -fn check_nullifier_exists_oracle( - _inner_nullifier: Field, -) -> Field {} +fn check_nullifier_exists_oracle(_inner_nullifier: Field) -> Field {} 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 a2caf7ef23f..cda65354018 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/public_call.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/public_call.nr @@ -1,20 +1,8 @@ use crate::constants_gen::RETURN_VALUES_LENGTH; #[oracle(callPublicFunction)] -fn call_public_function_oracle( - _contract_address: Field, - _function_selector: Field, - _args_hash: Field -) -> [Field; RETURN_VALUES_LENGTH] {} +fn call_public_function_oracle(_contract_address: Field, _function_selector: Field, _args_hash: Field) -> [Field; RETURN_VALUES_LENGTH] {} -unconstrained pub fn call_public_function_internal( - contract_address: Field, - function_selector: Field, - args_hash: Field -) -> [Field; RETURN_VALUES_LENGTH] { - call_public_function_oracle( - contract_address, - function_selector, - args_hash, - ) +unconstrained pub fn call_public_function_internal(contract_address: Field, function_selector: Field, args_hash: Field) -> [Field; RETURN_VALUES_LENGTH] { + call_public_function_oracle(contract_address, function_selector, args_hash) } diff --git a/yarn-project/aztec-nr/aztec/src/oracle/rand.nr b/yarn-project/aztec-nr/aztec/src/oracle/rand.nr index b21f6ad93af..0d417e69422 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/rand.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/rand.nr @@ -1,5 +1,3 @@ - - #[oracle(getRandomField)] fn rand_oracle() -> Field {} diff --git a/yarn-project/aztec-nr/aztec/src/oracle/storage.nr b/yarn-project/aztec-nr/aztec/src/oracle/storage.nr index 0b5d96997d2..b2c2c434c1f 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/storage.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/storage.nr @@ -1,32 +1,19 @@ - #[oracle(storageRead)] -fn storage_read_oracle( - _storage_slot: Field, - _number_of_elements: Field, -) -> [Field; N] {} +fn storage_read_oracle(_storage_slot: Field, _number_of_elements: Field) -> [Field; N] {} -unconstrained fn storage_read_oracle_wrapper(_storage_slot: Field)-> [Field; N] { +unconstrained fn storage_read_oracle_wrapper(_storage_slot: Field) -> [Field; N] { storage_read_oracle(_storage_slot, N) } -pub fn storage_read( - storage_slot: Field, - deserialize: fn ([Field; N]) -> T, -) -> T { +pub fn storage_read(storage_slot: Field, deserialize: fn ([Field; N]) -> T) -> T { let fields = storage_read_oracle_wrapper(storage_slot); deserialize(fields) } #[oracle(storageWrite)] -fn storage_write_oracle( - _storage_slot: Field, - _values: [Field; N], -) -> [Field; N] {} +fn storage_write_oracle(_storage_slot: Field, _values: [Field; N]) -> [Field; N] {} // TODO: Remove return value. -unconstrained pub fn storage_write( - storage_slot: Field, - fields: [Field; N] -) { +unconstrained pub fn storage_write(storage_slot: Field, fields: [Field; N]) { let _hash = storage_write_oracle(storage_slot, fields); -} \ No newline at end of file +} 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 0900e601d27..9742106c152 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 @@ -18,4 +18,4 @@ impl PrivateCallStackItem { self.public_inputs.hash(), ], GENERATOR_INDEX__CALL_STACK_ITEM) } -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/aztec/src/selector.nr b/yarn-project/aztec-nr/aztec/src/selector.nr index 9f5d368e5d7..6b81188571d 100644 --- a/yarn-project/aztec-nr/aztec/src/selector.nr +++ b/yarn-project/aztec-nr/aztec/src/selector.nr @@ -5,11 +5,11 @@ global SELECTOR_SIZE = 4; pub fn compute_selector(signature: str) -> Field { let bytes = signature.as_bytes(); let hash = dep::std::hash::keccak256(bytes, bytes.len() as u32); - + let mut selector_be_bytes = [0; SELECTOR_SIZE]; for i in 0..SELECTOR_SIZE { selector_be_bytes[i] = hash[i]; } field_from_bytes(selector_be_bytes, true) -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/aztec/src/state_vars.nr b/yarn-project/aztec-nr/aztec/src/state_vars.nr index b35df0399d1..e1e813891ff 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars.nr @@ -2,4 +2,4 @@ mod immutable_singleton; mod map; mod public_state; mod set; -mod singleton; \ No newline at end of file +mod singleton; 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 2ec2979bc59..9f64faf3c82 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars/singleton.nr @@ -16,15 +16,10 @@ use crate::hash::pedersen_hash; 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_hash( - [storage_slot, secret.low, secret.high], - GENERATOR_INDEX__INITIALIZATION_NULLIFIER, - ) + pedersen_hash([storage_slot, secret.low, secret.high], + GENERATOR_INDEX__INITIALIZATION_NULLIFIER) } else { - pedersen_hash( - [storage_slot], - GENERATOR_INDEX__INITIALIZATION_NULLIFIER, - ) + pedersen_hash([storage_slot], GENERATOR_INDEX__INITIALIZATION_NULLIFIER) } } diff --git a/yarn-project/aztec-nr/aztec/src/types.nr b/yarn-project/aztec-nr/aztec/src/types.nr index a93267973be..07b38d9b988 100644 --- a/yarn-project/aztec-nr/aztec/src/types.nr +++ b/yarn-project/aztec-nr/aztec/src/types.nr @@ -1,4 +1,4 @@ mod address; mod point; mod vec; // This can/should be moved out into an official noir library -mod type_serialization; \ No newline at end of file +mod type_serialization; diff --git a/yarn-project/aztec-nr/aztec/src/types/address.nr b/yarn-project/aztec-nr/aztec/src/types/address.nr index c238b491950..c0654e55de0 100644 --- a/yarn-project/aztec-nr/aztec/src/types/address.nr +++ b/yarn-project/aztec-nr/aztec/src/types/address.nr @@ -50,4 +50,4 @@ impl EthereumAddress { address: fields[0] } } -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/aztec/src/types/point.nr b/yarn-project/aztec-nr/aztec/src/types/point.nr index 5a51780a81b..f50be1fe2bb 100644 --- a/yarn-project/aztec-nr/aztec/src/types/point.nr +++ b/yarn-project/aztec-nr/aztec/src/types/point.nr @@ -14,10 +14,7 @@ impl Point { global POINT_SERIALIZED_LEN: Field = 2; fn deserializePoint(fields: [Field; POINT_SERIALIZED_LEN]) -> Point { - Point { - x: fields[0], - y: fields[1], - } + Point { x: fields[0], y: fields[1] } } fn serializePoint(point: Point) -> [Field; POINT_SERIALIZED_LEN] { @@ -27,4 +24,4 @@ fn serializePoint(point: Point) -> [Field; POINT_SERIALIZED_LEN] { global PointSerializationMethods = TypeSerializationInterface { deserialize: deserializePoint, serialize: serializePoint, -}; \ No newline at end of file +}; diff --git a/yarn-project/aztec-nr/aztec/src/types/type_serialization/aztec_address_serialization.nr b/yarn-project/aztec-nr/aztec/src/types/type_serialization/aztec_address_serialization.nr index 8ce68ec513f..2e53171542d 100644 --- a/yarn-project/aztec-nr/aztec/src/types/type_serialization/aztec_address_serialization.nr +++ b/yarn-project/aztec-nr/aztec/src/types/type_serialization/aztec_address_serialization.nr @@ -14,4 +14,4 @@ fn serialize(value: AztecAddress) -> [Field; AZTEC_ADDRESS_SERIALIZED_LEN] { global AztecAddressSerializationMethods = TypeSerializationInterface { deserialize, serialize, -}; \ No newline at end of file +}; diff --git a/yarn-project/aztec-nr/aztec/src/types/type_serialization/bool_serialization.nr b/yarn-project/aztec-nr/aztec/src/types/type_serialization/bool_serialization.nr index ac9829ecfb0..255f519234c 100644 --- a/yarn-project/aztec-nr/aztec/src/types/type_serialization/bool_serialization.nr +++ b/yarn-project/aztec-nr/aztec/src/types/type_serialization/bool_serialization.nr @@ -13,4 +13,4 @@ fn serializeBool(value: bool) -> [Field; BOOL_SERIALIZED_LEN] { global BoolSerializationMethods = TypeSerializationInterface { deserialize: deserializeBool, serialize: serializeBool, -}; \ No newline at end of file +}; diff --git a/yarn-project/aztec-nr/aztec/src/types/type_serialization/u32_serialization.nr b/yarn-project/aztec-nr/aztec/src/types/type_serialization/u32_serialization.nr index e04cf948a53..2517532b420 100644 --- a/yarn-project/aztec-nr/aztec/src/types/type_serialization/u32_serialization.nr +++ b/yarn-project/aztec-nr/aztec/src/types/type_serialization/u32_serialization.nr @@ -13,4 +13,4 @@ fn serializeU32(value: u32) -> [Field; U32_SERIALIZED_LEN] { global U32SerializationMethods = TypeSerializationInterface { deserialize: deserializeU32, serialize: serializeU32, -}; \ No newline at end of file +}; diff --git a/yarn-project/aztec-nr/aztec/src/types/vec.nr b/yarn-project/aztec-nr/aztec/src/types/vec.nr index 4851a1200c3..135bbbd53c3 100644 --- a/yarn-project/aztec-nr/aztec/src/types/vec.nr +++ b/yarn-project/aztec-nr/aztec/src/types/vec.nr @@ -1,4 +1,3 @@ - struct BoundedVec { storage: [T; MaxLen], len: Field, @@ -124,4 +123,4 @@ fn test_vec_any_not_default() { let mut vec: BoundedVec = BoundedVec::new(default_value); vec.push_array([2, 4]); assert(vec.any(|v| v == default_value) == false); -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/aztec/src/utils.nr b/yarn-project/aztec-nr/aztec/src/utils.nr index c80e360de56..205b19fd49a 100644 --- a/yarn-project/aztec-nr/aztec/src/utils.nr +++ b/yarn-project/aztec-nr/aztec/src/utils.nr @@ -1,8 +1,4 @@ -pub fn arr_copy_slice( - src: [T; N], - mut dst: [T; M], - offset: Field, -) -> [T; M] { +pub fn arr_copy_slice(src: [T; N], mut dst: [T; M], offset: Field) -> [T; M] { for i in 0..dst.len() { dst[i] = src[i + offset]; } @@ -23,4 +19,4 @@ pub fn field_from_bytes(bytes: [u8; N], big_endian: bool) -> Field { } as_field -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/easy-private-state/src/lib.nr b/yarn-project/aztec-nr/easy-private-state/src/lib.nr index 5a483393d84..2a29ab85139 100644 --- a/yarn-project/aztec-nr/easy-private-state/src/lib.nr +++ b/yarn-project/aztec-nr/easy-private-state/src/lib.nr @@ -1 +1 @@ -mod easy_private_state; \ No newline at end of file +mod easy_private_state; diff --git a/yarn-project/aztec-nr/field-note/src/field_note.nr b/yarn-project/aztec-nr/field-note/src/field_note.nr index da8f7d286eb..6e0e133476c 100644 --- a/yarn-project/aztec-nr/field-note/src/field_note.nr +++ b/yarn-project/aztec-nr/field-note/src/field_note.nr @@ -55,7 +55,7 @@ fn deserialize(serialized_note: [Field; FIELD_NOTE_LEN]) -> FieldNote { FieldNote::deserialize(serialized_note) } -fn serialize(note: FieldNote) -> [Field; FIELD_NOTE_LEN]{ +fn serialize(note: FieldNote) -> [Field; FIELD_NOTE_LEN] { note.serialize() } diff --git a/yarn-project/aztec-nr/field-note/src/lib.nr b/yarn-project/aztec-nr/field-note/src/lib.nr index 2625d3a2277..71523fc462b 100644 --- a/yarn-project/aztec-nr/field-note/src/lib.nr +++ b/yarn-project/aztec-nr/field-note/src/lib.nr @@ -1 +1 @@ -mod field_note; \ No newline at end of file +mod field_note; diff --git a/yarn-project/aztec-nr/safe-math/src/lib.nr b/yarn-project/aztec-nr/safe-math/src/lib.nr index f8f829b67e3..7e29a39a85e 100644 --- a/yarn-project/aztec-nr/safe-math/src/lib.nr +++ b/yarn-project/aztec-nr/safe-math/src/lib.nr @@ -1,3 +1,3 @@ mod safe_u120; -use crate::safe_u120::SafeU120; \ No newline at end of file +use crate::safe_u120::SafeU120; 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 b7ebfa2de82..8412f45a43a 100644 --- a/yarn-project/aztec-nr/safe-math/src/safe_u120.nr +++ b/yarn-project/aztec-nr/safe-math/src/safe_u120.nr @@ -163,7 +163,6 @@ fn test_lt() { assert(b.lt(a) == false); } - #[test] fn test_le() { let a = SafeU120::new(2); @@ -182,7 +181,6 @@ fn test_gt() { assert(a.gt(b) == false); } - #[test] fn test_ge() { let a = SafeU120::new(2); @@ -302,7 +300,6 @@ fn test_mul_div_up_non_rounding() { assert(d.value == 9); } - #[test(should_fail)] fn test_mul_div_up_ghost_overflow() { let a = SafeU120::max(); diff --git a/yarn-project/aztec-nr/slow-updates-tree/src/lib.nr b/yarn-project/aztec-nr/slow-updates-tree/src/lib.nr index 9e861a90607..72a8c1ad19f 100644 --- a/yarn-project/aztec-nr/slow-updates-tree/src/lib.nr +++ b/yarn-project/aztec-nr/slow-updates-tree/src/lib.nr @@ -1 +1 @@ -mod slow_map; \ No newline at end of file +mod slow_map; diff --git a/yarn-project/aztec-nr/slow-updates-tree/src/slow_map.nr b/yarn-project/aztec-nr/slow-updates-tree/src/slow_map.nr index f0a626ef436..f36d9f79593 100644 --- a/yarn-project/aztec-nr/slow-updates-tree/src/slow_map.nr +++ b/yarn-project/aztec-nr/slow-updates-tree/src/slow_map.nr @@ -10,7 +10,7 @@ use dep::std::option::Option; global EPOCH_LENGTH: u120 = 100; fn compute_next_change(time: Field) -> Field { - (((time as u120 / EPOCH_LENGTH + 1) * EPOCH_LENGTH)) as Field + ((time as u120 / EPOCH_LENGTH + 1) * EPOCH_LENGTH) as Field } // A leaf in the tree. @@ -21,15 +21,11 @@ struct Leaf { } fn serialize_leaf(leaf: Leaf) -> [Field; 3] { - [leaf.next_change, leaf.before, leaf.after] + [leaf.next_change, leaf.before, leaf.after] } fn deserialize_leaf(serialized: [Field; 3]) -> Leaf { - Leaf { - next_change: serialized[0], - before: serialized[1], - after: serialized[2], - } + Leaf { next_change: serialized[0], before: serialized[1], after: serialized[2] } } impl Leaf { @@ -58,7 +54,7 @@ struct SlowUpdateProof { } pub fn deserialize_slow_update_proof(serialized: [Field; M]) -> SlowUpdateProof { - SlowUpdateProof::deserialize(serialized) + SlowUpdateProof::deserialize(serialized) } impl SlowUpdateProof { @@ -273,4 +269,4 @@ impl SlowMap { }; current } -*/ \ No newline at end of file +*/ 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 eedefb3c27e..cd577b97af7 100644 --- a/yarn-project/aztec-nr/value-note/src/balance_utils.nr +++ b/yarn-project/aztec-nr/value-note/src/balance_utils.nr @@ -26,4 +26,4 @@ unconstrained pub fn get_balance_with_offset(set: Set } balance -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/value-note/src/filter.nr b/yarn-project/aztec-nr/value-note/src/filter.nr index 05424756218..8657358cf10 100644 --- a/yarn-project/aztec-nr/value-note/src/filter.nr +++ b/yarn-project/aztec-nr/value-note/src/filter.nr @@ -13,4 +13,4 @@ pub fn filter_notes_min_sum(notes: [Option; MAX_READ_REQUESTS_PER_CAL } } selected -} \ No newline at end of file +} diff --git a/yarn-project/aztec-nr/value-note/src/lib.nr b/yarn-project/aztec-nr/value-note/src/lib.nr index 83b1454e9b7..c48740b98d2 100644 --- a/yarn-project/aztec-nr/value-note/src/lib.nr +++ b/yarn-project/aztec-nr/value-note/src/lib.nr @@ -1,4 +1,4 @@ mod balance_utils; mod filter; mod utils; -mod value_note; \ No newline at end of file +mod value_note; diff --git a/yarn-project/aztec-nr/value-note/src/utils.nr b/yarn-project/aztec-nr/value-note/src/utils.nr index f5abca9ffcc..5751bba16f1 100644 --- a/yarn-project/aztec-nr/value-note/src/utils.nr +++ b/yarn-project/aztec-nr/value-note/src/utils.nr @@ -16,11 +16,7 @@ pub fn create_note_getter_options_for_decreasing_balance(amount: Field) -> NoteG // Creates a new note for the recipient. // Inserts it to the recipient's set of notes. -pub fn increment( - balance: Set, - amount: Field, - recipient: Field, -) { +pub fn increment(balance: Set, amount: Field, recipient: Field) { let mut note = ValueNote::new(amount, recipient); // Insert the new note to the owner's set of notes and emit the log if value is non-zero. balance.insert(&mut note, amount != 0); @@ -30,11 +26,7 @@ pub 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. -pub fn decrement( - balance: Set, - amount: Field, - owner: Field, -) { +pub fn decrement(balance: Set, amount: Field, owner: Field) { let sum = decrement_by_at_most(balance, amount, owner); assert(sum == amount, "Balance too low"); } @@ -47,11 +39,7 @@ pub fn decrement( // equal `amount`. // // It returns the decremented amount, which should be less than or equal to max_amount. -pub fn decrement_by_at_most( - balance: Set, - max_amount: Field, - owner: Field, -) -> Field { +pub fn decrement_by_at_most(balance: Set, max_amount: Field, owner: Field) -> Field { let options = create_note_getter_options_for_decreasing_balance(max_amount); let opt_notes = balance.get_notes(options); @@ -75,16 +63,12 @@ pub fn decrement_by_at_most( // Removes the note from the owner's set of notes. // Returns the value of the destroyed note. -pub fn destroy_note( - balance: Set, - owner: Field, - note: ValueNote, -) -> Field { +pub fn destroy_note(balance: Set, owner: Field, note: ValueNote) -> Field { // Ensure the note is actually owned by the owner (to prevent user from generating a valid proof while // spending someone else's notes). assert(note.owner == owner); balance.remove(note); - + note.value } diff --git a/yarn-project/noir-contracts/src/contracts/benchmarking_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/benchmarking_contract/src/main.nr index 12ee0cccdcc..27683d5a52d 100644 --- a/yarn-project/noir-contracts/src/contracts/benchmarking_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/benchmarking_contract/src/main.nr @@ -50,7 +50,7 @@ contract Benchmarking { // by @rahul-kothari for a full explanation on why this is needed. #[aztec(private)] fn recreate_note(owner: Field, index: u32) { - let owner_notes = storage.notes.at(owner); + let owner_notes = storage.notes.at(owner); let getter_options = NoteGetterOptions::new().set_limit(1).set_offset(index); let notes = owner_notes.get_notes(getter_options); let note = notes[0].unwrap_unchecked(); @@ -63,7 +63,9 @@ contract Benchmarking { fn increment_balance(owner: Field, value: Field) { let current = storage.balances.at(owner).read(); storage.balances.at(owner).write(current + value); - let _callStackItem1 = context.call_public_function(context.this_address(), compute_selector("broadcast(Field)"), [owner]); + let _callStackItem1 = context.call_public_function(context.this_address(), + compute_selector("broadcast(Field)"), + [owner]); } // Emits a public log. 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 68c560c9de5..f5f5636132b 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 @@ -50,7 +50,6 @@ fn test_to_from_field() { assert(card.to_field() == field); } - struct CardNote { card: Card, note: ValueNote, @@ -96,23 +95,21 @@ pub fn filter_cards(notes: [Option; MAX_READ_REQUESTS_PER_CALL], d for i in 0..notes.len() { let note = notes[i]; if note.is_some() { - let card_note = CardNote::from_note( - note.unwrap_unchecked() - ); + let card_note = CardNote::from_note(note.unwrap_unchecked()); for j in 0..N { - if !found[j] & (card_note.card.strength == desired_cards[j].strength) & (card_note.card.points == desired_cards[j].points) { + if !found[j] + & (card_note.card.strength == desired_cards[j].strength) + & (card_note.card.points == desired_cards[j].points) { selected[i] = note; found[j] = true; } } } - } selected } - impl Deck { pub fn new( context: Context, @@ -191,10 +188,7 @@ impl Deck { global PACK_CARDS = 3; // Limited by number of write requests (max 4) -pub fn get_pack_cards( - seed: Field, - owner_address: Field -) -> [Card; PACK_CARDS] { +pub fn get_pack_cards(seed: Field, owner_address: Field) -> [Card; PACK_CARDS] { // generate pseudo randomness deterministically from 'seed' and user secret let secret = get_secret_key(owner_address); let mix = secret.high + secret.low + seed; @@ -215,7 +209,8 @@ pub fn get_pack_cards( } pub fn compute_deck_strength(cards: [Card; N]) -> Field { - cards.fold(0, |acc, card: Card| { + cards.fold(0, + |acc, card: Card| { acc + card.strength as Field }) -} \ No newline at end of file +} 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 75be5f84979..7b6255e907c 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 @@ -32,29 +32,21 @@ global GAME_SERIALIZED_LEN: Field = 15; fn deserializeGame(fields: [Field; GAME_SERIALIZED_LEN]) -> Game { let players = [ - PlayerEntry { - address: fields[0], - deck_strength: fields[1] as u32, - points: fields[2] as u120, - }, - PlayerEntry { - address: fields[3], - deck_strength: fields[4] as u32, - points: fields[5] as u120, - }, + PlayerEntry { address: fields[0], deck_strength: fields[1] as u32, points: fields[2] as u120 }, + PlayerEntry { address: fields[3], deck_strength: fields[4] as u32, points: fields[5] as u120 } ]; let rounds_cards = [ Card::from_field(fields[6]), Card::from_field(fields[7]), - Card::from_field(fields[8]), Card::from_field(fields[9]), + Card::from_field(fields[8]), Card::from_field(fields[9]) ]; - Game { + Game { players, rounds_cards, started: fields[10] as bool, finished: fields[11] as bool, claimed: fields[12] as bool, current_player: fields[13] as u32, - current_round: fields[14] as u32, + current_round: fields[14] as u32 } } @@ -74,7 +66,7 @@ fn serializeGame(game: Game) -> [Field; GAME_SERIALIZED_LEN] { game.finished as Field, game.claimed as Field, game.current_player as Field, - game.current_round as Field, + game.current_round as Field ] } @@ -169,4 +161,4 @@ impl Game { global GameSerializationMethods = TypeSerializationInterface { deserialize: deserializeGame, serialize: serializeGame, -}; \ No newline at end of file +}; diff --git a/yarn-project/noir-contracts/src/contracts/card_game_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/card_game_contract/src/main.nr index 732bf0f0c28..aa01e597e91 100644 --- a/yarn-project/noir-contracts/src/contracts/card_game_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/card_game_contract/src/main.nr @@ -11,7 +11,6 @@ contract CardGame { }, }; - use dep::std::option::Option; use dep::value_note::{ balance_utils, @@ -50,7 +49,7 @@ contract CardGame { GameSerializationMethods, GAME_SERIALIZED_LEN }; - + struct Storage { collections: Map, game_decks: Map>, @@ -107,10 +106,8 @@ contract CardGame { fn constructor() {} #[aztec(private)] - fn buy_pack( - seed: Field, // The randomness used to generate the cards. Passed in for now. - ) { - + fn buy_pack(seed: Field // The randomness used to generate the cards. Passed in for now. + ) { let buyer = context.msg_sender(); let mut cards = get_pack_cards(seed, buyer); @@ -119,12 +116,9 @@ contract CardGame { } #[aztec(private)] - fn join_game( - game: u32, - cards_fields: [Field; 2], - ) { + fn join_game(game: u32, cards_fields: [Field; 2]) { let cards = cards_fields.map(|card_field| Card::from_field(card_field)); - + let player = context.msg_sender(); let mut collection = storage.collections.at(player); @@ -133,54 +127,47 @@ contract CardGame { let _added_to_game_deck = game_deck.add_cards(cards, player); let selector = compute_selector("on_game_joined(u32,Field,u32)"); let strength = compute_deck_strength(cards); - context.call_public_function(context.this_address(), selector, [game as Field, player, strength]); + context.call_public_function(context.this_address(), + selector, + [game as Field, player, strength]); } #[aztec(public)] - internal fn on_game_joined( - game: u32, - player: Field, - deck_strength: u32, - ) { - + internal fn on_game_joined(game: u32, player: Field, deck_strength: u32) { let game_storage = storage.games.at(game as Field); let mut game_data = game_storage.read(); - assert(game_data.add_player(PlayerEntry {address: player, deck_strength, points: 0}), "Game full"); + assert(game_data.add_player(PlayerEntry { address: player, deck_strength, points: 0 }), "Game full"); game_storage.write(game_data); } #[aztec(public)] - fn start_game(game: u32) { - + fn start_game(game: u32) { let game_storage = storage.games.at(game as Field); - + let mut game_data = game_storage.read(); game_data.start_game(); game_storage.write(game_data); } #[aztec(private)] - fn play_card( - game: u32, - card: Card, - ) { - + fn play_card(game: u32, card: Card) { let player = context.msg_sender(); let mut game_deck = storage.game_decks.at(game as Field).at(player); game_deck.remove_cards([card], player); let selector = compute_selector("on_card_played(u32,Field,Field)"); - context.call_public_function(context.this_address(), selector, [game as Field, player, card.to_field()]); + context.call_public_function(context.this_address(), + selector, + [game as Field, player, card.to_field()]); } #[aztec(public)] internal fn on_card_played(game: u32, player: Field, card_as_field: Field) { - let game_storage = storage.games.at(game as Field); - + let mut game_data = game_storage.read(); let card = Card::from_field(card_as_field); @@ -192,11 +179,7 @@ contract CardGame { } #[aztec(private)] - fn claim_cards( - game: u32, - cards_fields: [Field; PLAYABLE_CARDS], - ) { - + fn claim_cards(game: u32, cards_fields: [Field; PLAYABLE_CARDS]) { let player = context.msg_sender(); let cards = cards_fields.map(|card_field| Card::from_field(card_field)); @@ -204,26 +187,20 @@ contract CardGame { let _inserted_cards = collection.add_cards(cards, player); let selector = compute_selector("on_cards_claimed(u32,Field,Field)"); - context.call_public_function( - context.this_address(), - selector, - [game as Field, player, pedersen_hash(cards_fields,0)] - ); + context.call_public_function(context.this_address(), + selector, + [game as Field, player, pedersen_hash(cards_fields, 0)]); } #[aztec(public)] internal fn on_cards_claimed(game: u32, player: Field, cards_hash: Field) { - let game_storage = storage.games.at(game as Field); let mut game_data = game_storage.read(); - + assert(!game_data.claimed, "Already claimed"); game_data.claimed = true; - assert_eq( - cards_hash, - pedersen_hash(game_data.rounds_cards.map(|card: Card| card.to_field()),0) - ); + assert_eq(cards_hash, pedersen_hash(game_data.rounds_cards.map(|card: Card| card.to_field()), 0)); let winner = game_data.winner(); assert_eq(player, winner.address, "Not the winner"); @@ -232,22 +209,20 @@ contract CardGame { } unconstrained fn view_collection_cards(owner: Field, offset: u32) -> [Option; MAX_NOTES_PER_PAGE] { - let collection = storage.collections.at(owner); collection.view_cards(offset) - } + } unconstrained fn view_game_cards(game: u32, player: Field, offset: u32) -> [Option; MAX_NOTES_PER_PAGE] { - let game_deck = storage.game_decks.at(game as Field).at(player); game_deck.view_cards(offset) - } + } unconstrained fn view_game(game: u32) -> Game { storage.games.at(game as Field).read() - } + } // Computes note hash and nullifier. // Note 1: Needs to be defined by every contract producing logs. diff --git a/yarn-project/noir-contracts/src/contracts/child_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/child_contract/src/main.nr index f1ecd53091e..c884aece908 100644 --- a/yarn-project/noir-contracts/src/contracts/child_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/child_contract/src/main.nr @@ -28,13 +28,11 @@ contract Child { } #[aztec(private)] - fn constructor() {} + fn constructor() {} // Returns a sum of the input and the chain id and version of the contract in private circuit public input's return_values. #[aztec(private)] - fn value( - input: Field, - ) -> Field { + fn value(input: Field) -> Field { input + context.chain_id() + context.version() } @@ -45,9 +43,7 @@ contract Child { // Returns a sum of the input and the chain id and version of the contract in private circuit public input's return_values. // Can only be called from this contract. #[aztec(private)] - fn valueInternal( - input: Field, - ) -> Field { + fn valueInternal(input: Field) -> Field { check_sender(inputs.call_context); input + context.chain_id() + context.version() } @@ -55,7 +51,11 @@ contract Child { // Returns base_value + chain_id + version + block_number + timestamp #[aztec(public)] fn pubGetValue(base_value: Field) -> Field { - let returnValue = base_value + context.chain_id() + context.version() + context.block_number() + context.timestamp(); + let returnValue = base_value + + context.chain_id() + + context.version() + + context.block_number() + + context.timestamp(); returnValue } @@ -63,17 +63,15 @@ contract Child { // Sets `current_value` to `new_value` #[aztec(public)] fn pubSetValue(new_value: Field) -> Field { - storage.current_value.write(new_value); emit_unencrypted_log(&mut context, new_value); - + new_value } // Increments `current_value` by `new_value` #[aztec(public)] fn pubIncValue(new_value: Field) -> Field { - let old_value = storage.current_value.read(); storage.current_value.write(old_value + new_value); emit_unencrypted_log(&mut context, new_value); @@ -84,12 +82,11 @@ contract Child { // Increments `current_value` by `new_value`. Can only be called from this contract. #[aztec(public)] fn pubIncValueInternal(new_value: Field) -> Field { - check_sender(inputs.call_context); let old_value = storage.current_value.read(); storage.current_value.write(old_value + new_value); emit_unencrypted_log(&mut context, new_value); - + new_value } @@ -98,14 +95,12 @@ contract Child { let pubSetValueSelector = compute_selector("pubSetValue(Field)"); let _ret = context.call_public_function(context.this_address(), pubSetValueSelector, [10]); - storage.current_value.write(20); emit_unencrypted_log(&mut context, 20); } #[aztec(public)] fn setValueTwiceWithNestedLast() { - storage.current_value.write(20); emit_unencrypted_log(&mut context, 20); diff --git a/yarn-project/noir-contracts/src/contracts/counter_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/counter_contract/src/main.nr index 18836e71827..e332d692bd8 100644 --- a/yarn-project/noir-contracts/src/contracts/counter_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/counter_contract/src/main.nr @@ -1,5 +1,5 @@ contract Counter { -// docs:start:imports + // docs:start:imports use dep::aztec::{ context::{PrivateContext, Context}, note::{ @@ -16,17 +16,17 @@ contract Counter { }, }; use dep::easy_private_state::easy_private_state::EasyPrivateUint; -// docs:end:imports + // docs:end:imports -// docs:start:storage_struct + // docs:start:storage_struct struct Storage { counters: Map, } -// docs:end:storage_struct + // docs:end:storage_struct -// docs:start:storage_init + // docs:start:storage_init impl Storage { fn init(context: Context) -> pub Self { Storage { @@ -40,40 +40,35 @@ contract Counter { } } } -// docs:end:storage_init + // docs:end:storage_init -// docs:start:constructor + // docs:start:constructor #[aztec(private)] fn constructor(headstart: u120, owner: Field) { let counters = storage.counters; counters.at(owner).add(headstart, owner); } -// docs:end:constructor + // docs:end:constructor -// docs:start:increment + // docs:start:increment #[aztec(private)] - fn increment(owner: Field) { + fn increment(owner: Field) { let counters = storage.counters; counters.at(owner).add(1, owner); } -// docs:end:increment + // docs:end:increment -// docs:start:get_counter + // docs:start:get_counter unconstrained fn get_counter(owner: Field) -> Field { - let counters = storage.counters; - balance_utils::get_balance(counters.at(owner).set) + let counters = storage.counters; + balance_utils::get_balance(counters.at(owner).set) } -// docs:end:get_counter + // docs:end:get_counter -// docs:start:nullifier - unconstrained fn compute_note_hash_and_nullifier( - contract_address: Field, - nonce: Field, - storage_slot: Field, - preimage: [Field; VALUE_NOTE_LEN], - ) -> [Field; 4] { - let note_header = NoteHeader::new(contract_address, nonce, storage_slot); - note_utils::compute_note_hash_and_nullifier(ValueNoteMethods, note_header, preimage) + // docs:start:nullifier + unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; VALUE_NOTE_LEN]) -> [Field; 4] { + let note_header = NoteHeader::new(contract_address, nonce, storage_slot); + note_utils::compute_note_hash_and_nullifier(ValueNoteMethods, note_header, preimage) } -// docs:end:nullifier -} \ No newline at end of file + // docs:end:nullifier +} 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 03bd8c2c0de..474fb20c6fc 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 @@ -38,10 +38,7 @@ pub fn get_current_queen(state_var: PublicState) -> } // docs:end:state_vars-PublicStateReadCustom -pub fn can_replace_queen( - state_var: PublicState, - new_queen: Queen, -) -> bool { +pub fn can_replace_queen(state_var: PublicState, new_queen: Queen) -> bool { let current_queen = get_current_queen(state_var); new_queen.points > current_queen.points } @@ -79,10 +76,7 @@ pub fn get_legendary_card(state_var: Singleton) -> Card // docs:end:state_vars-SingletonGet // docs:start:state_vars-ImmutableSingletonInit -pub fn init_game_rules( - state_var: ImmutableSingleton, - rules: &mut RulesNote, -) { +pub fn init_game_rules(state_var: ImmutableSingleton, rules: &mut RulesNote) { state_var.initialize(rules, Option::none(), true); } // docs:end:state_vars-ImmutableSingletonInit @@ -109,29 +103,20 @@ pub fn remove_card(state_var: Set, card: CardNote) { // docs:start:state_vars-SetGet pub fn get_cards( state_var: Set, - options: NoteGetterOptions, + options: NoteGetterOptions ) -> [Option; MAX_READ_REQUESTS_PER_CALL] { state_var.get_notes(options) } // docs:end:state_vars-SetGet // docs:start:state_vars-SetView -unconstrained pub fn view_cards( - state_var: Set, - options: NoteViewerOptions, -) -> [Option; MAX_NOTES_PER_PAGE] { +unconstrained pub fn view_cards(state_var: Set, options: NoteViewerOptions) -> [Option; MAX_NOTES_PER_PAGE] { state_var.view_notes(options) } // docs:end:state_vars-SetView -unconstrained pub fn get_total_points( - state_var: Set, - account: Field, - offset: u32, -) -> u8 { - let options = NoteViewerOptions::new() - .select(2, account) - .set_offset(offset); +unconstrained pub fn get_total_points(state_var: Set, account: Field, offset: u32) -> u8 { + let options = NoteViewerOptions::new().select(2, account).set_offset(offset); let mut total_points = 0; let notes = view_cards(state_var, options); for i in 0..notes.len() { @@ -146,20 +131,13 @@ unconstrained pub fn get_total_points( } // docs:start:state_vars-MapAtSingletonInit -pub fn add_new_profile( - state_var: Map>, - account: Field, - profile: &mut ProfileNote, -) { +pub fn add_new_profile(state_var: Map>, account: Field, profile: &mut ProfileNote) { state_var.at(account).initialize(profile, Option::some(account), true); } // docs:end:state_vars-MapAtSingletonInit // docs:start:state_vars-MapAtSingletonGet -pub fn get_profile( - state_var: Map>, - account: Field, -) -> ProfileNote { +pub fn get_profile(state_var: Map>, account: Field) -> ProfileNote { state_var.at(account).get_note(true) } // docs:end:state_vars-MapAtSingletonGet diff --git a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/main.nr index 3930ac84f2b..95eb42363cb 100644 --- a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/main.nr @@ -91,11 +91,7 @@ contract DocsExample { global GET_POINTS_OF_COMMON_CARD_FUNCTION_SELECTOR = 11111111; #[aztec(private)] - fn constructor( - min_points: u8, - max_points: u8, - legendary_card_secret: Field, - ) { + fn constructor(min_points: u8, max_points: u8, legendary_card_secret: Field) { let mut game_rules = RulesNote::new(min_points, max_points, Option::some(0)); actions::init_game_rules(storage.game_rules, &mut game_rules); @@ -107,7 +103,7 @@ contract DocsExample { #[aztec(public)] fn lock() { // highlight-next-line:storage-init - + storage.locked.write(true); } // docs:end:storage-init @@ -115,30 +111,22 @@ contract DocsExample { // docs:start:functions-OpenFunction #[aztec(public)] fn unlock() { - actions::unlock(storage.locked); } // docs:end:functions-OpenFunction #[aztec(public)] - fn replace_queen( - account: Field, - points: u8, - ) { - - + fn replace_queen(account: Field, points: u8) { let new_queen = Queen { account, points }; - + assert(actions::can_replace_queen(storage.queen, new_queen)); - + actions::replace_queen(storage.queen, new_queen); } // docs:start:state_vars-PublicStateWriteBeforeCall #[aztec(public)] fn replace_queen_unsafe() { - - let account = context.msg_sender(); let points = actions::get_total_points(storage.cards, account, 0); @@ -147,7 +135,7 @@ contract DocsExample { assert(points > current_queen.points); AccountContractInterface::at(account).send_rewards(current_queen.points); - + let new_queen = Queen { account, points }; storage.queen.write(new_queen); } @@ -156,8 +144,6 @@ contract DocsExample { // docs:start:functions-SecretFunction #[aztec(private)] fn add_common_cards(secrets: [Field; 4]) { - - for i in 0..secrets.len() as u8 { let mut card = CardNote::new(0, secrets[i], 0); actions::add_new_card(storage.cards, &mut card); @@ -166,12 +152,7 @@ contract DocsExample { // docs:end:functions-SecretFunction #[aztec(private)] - fn update_legendary_card( - new_points: u8, - new_secret: Field, - ) { - - + fn update_legendary_card(new_points: u8, new_secret: Field) { let owner = inputs.call_context.msg_sender; let mut updated_card = CardNote::new(new_points, new_secret, owner); @@ -182,32 +163,21 @@ contract DocsExample { #[aztec(private)] fn become_queen() { - - let legendary_card = actions::get_legendary_card(storage.legendary_card); let owner = legendary_card.owner; - let result = context.call_private_function( - inputs.call_context.storage_contract_address, + let result = context.call_private_function(inputs.call_context.storage_contract_address, GET_POINTS_OF_COMMON_CARD_FUNCTION_SELECTOR, - [owner, 0] - ); + [owner, 0]); let total_points = legendary_card.points + result[0] as u8; - context.call_public_function( - inputs.call_context.storage_contract_address, + context.call_public_function(inputs.call_context.storage_contract_address, REPLACE_QUEEN_FUNCTION_SELECTOR, - [owner, total_points as Field] - ); + [owner, total_points as Field]); } #[aztec(private)] - fn get_points_of_common_cards( - account: Field, - offset: u32, - ) { - - + fn get_points_of_common_cards(account: Field, offset: u32) { let mut total_points = 0; let options = create_account_card_getter_options(account, offset); let cards = actions::get_cards(storage.cards, options); @@ -224,12 +194,10 @@ contract DocsExample { // docs:start:functions-UnconstrainedFunction unconstrained fn get_total_points(account: Field) -> u8 { - actions::get_total_points(storage.cards, account, 0) } // docs:end:functions-UnconstrainedFunction - /// Macro equivalence section use dep::aztec::abi; use dep::aztec::abi::Hasher; @@ -243,7 +211,6 @@ contract DocsExample { } // docs:end:simple_macro_example - // docs:start:simple_macro_example_expanded fn simple_macro_example_expanded( // ************************************************************ @@ -255,9 +222,7 @@ contract DocsExample { // Our original inputs! a: Field, - b: Field - - // The actual return type of our circuit is the PrivateCircuitPublicInputs struct, this will be the + b: Field // The actual return type of our circuit is the PrivateCircuitPublicInputs struct, this will be the // input to our kernel! // docs:start:context-example-return ) -> distinct pub abi::PrivateCircuitPublicInputs { @@ -297,15 +262,11 @@ contract DocsExample { } // docs:end:simple_macro_example_expanded - // Cross chain messaging section // Demonstrates a cross chain message // docs:start:l1_to_l2_cross_chain_message #[aztec(private)] - fn send_to_l1() { - - - } + fn send_to_l1() {} // docs:end:l1_to_l2_cross_chain_message // TODO: remove this placeholder once https://github.com/AztecProtocol/aztec-packages/issues/2918 is implemented 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 636a6de3609..c225942b9fb 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,35 +4,19 @@ use dep::aztec::note::note_getter_options::{NoteGetterOptions, Sort, SortOrder}; use dep::std::option::Option; // docs:start:state_vars-NoteGetterOptionsSelectSortOffset -pub fn create_account_card_getter_options( - account_address: Field, - offset: u32, -) -> NoteGetterOptions { - NoteGetterOptions::new() - .select(2, account_address) - .sort(0, SortOrder.DESC) - .set_offset(offset) +pub fn create_account_card_getter_options(account_address: Field, offset: u32) -> NoteGetterOptions { + NoteGetterOptions::new().select(2, account_address).sort(0, SortOrder.DESC).set_offset(offset) } // docs:end:state_vars-NoteGetterOptionsSelectSortOffset // docs:start:state_vars-NoteGetterOptionsMultiSelects -pub fn create_exact_card_getter_options( - points: u8, - secret: Field, - account_address: Field, -) -> NoteGetterOptions { - NoteGetterOptions::new() - .select(0, points as Field) - .select(1, secret) - .select(2, account_address) +pub fn create_exact_card_getter_options(points: u8, secret: Field, account_address: Field) -> NoteGetterOptions { + NoteGetterOptions::new().select(0, points as Field).select(1, secret).select(2, account_address) } // docs:end:state_vars-NoteGetterOptionsMultiSelects // docs:start:state_vars-OptionFilter -pub fn filter_min_points( - cards: [Option; MAX_READ_REQUESTS_PER_CALL], - min_points: u8, -) -> [Option; MAX_READ_REQUESTS_PER_CALL] { +pub fn filter_min_points(cards: [Option; MAX_READ_REQUESTS_PER_CALL], min_points: u8) -> [Option; MAX_READ_REQUESTS_PER_CALL] { let mut selected_cards = [Option::none(); MAX_READ_REQUESTS_PER_CALL]; let mut num_selected = 0; for i in 0..cards.len() { @@ -46,23 +30,13 @@ pub fn filter_min_points( // docs:end:state_vars-OptionFilter // docs:start:state_vars-NoteGetterOptionsFilter -pub fn create_account_cards_with_min_points_getter_options( - account_address: Field, - min_points: u8, -) -> NoteGetterOptions { - NoteGetterOptions::with_filter(filter_min_points, min_points) - .select(2, account_address) - .sort(0, SortOrder.ASC) +pub fn create_account_cards_with_min_points_getter_options(account_address: Field, min_points: u8) -> NoteGetterOptions { + NoteGetterOptions::with_filter(filter_min_points, min_points).select(2, account_address).sort(0, SortOrder.ASC) } // docs:end:state_vars-NoteGetterOptionsFilter // docs:start:state_vars-NoteGetterOptionsPickOne -pub fn create_largest_account_card_getter_options( - account_address: Field, -) -> NoteGetterOptions { - NoteGetterOptions::new() - .select(2, account_address) - .sort(0, SortOrder.DESC) - .set_limit(1) +pub fn create_largest_account_card_getter_options(account_address: Field) -> NoteGetterOptions { + NoteGetterOptions::new().select(2, account_address).sort(0, SortOrder.DESC).set_limit(1) } // docs:end:state_vars-NoteGetterOptionsPickOne diff --git a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types.nr b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types.nr index 9e0784c92ca..b8bf6dc7bfd 100644 --- a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types.nr +++ b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types.nr @@ -1,4 +1,4 @@ mod card_note; mod profile_note; mod queen; -mod rules_note; \ No newline at end of file +mod rules_note; diff --git a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/queen.nr b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/queen.nr index 635205ecd6f..488ee5f52bc 100644 --- a/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/queen.nr +++ b/yarn-project/noir-contracts/src/contracts/docs_example_contract/src/types/queen.nr @@ -11,10 +11,7 @@ struct Queen { global QUEEN_SERIALIZED_LEN: Field = 2; fn deserialize(fields: [Field; QUEEN_SERIALIZED_LEN]) -> Queen { - Queen { - account: fields[0], - points: fields[1] as u8, - } + Queen { account: fields[0], points: fields[1] as u8 } } fn serialize(queen: Queen) -> [Field; QUEEN_SERIALIZED_LEN] { diff --git a/yarn-project/noir-contracts/src/contracts/easy_private_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/easy_private_token_contract/src/main.nr index fc3ebaf65ac..859d6859bf7 100644 --- a/yarn-project/noir-contracts/src/contracts/easy_private_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/easy_private_token_contract/src/main.nr @@ -38,13 +38,9 @@ contract EasyPrivateToken { /** * initialize the contract's initial state variables. - */ + */ #[aztec(private)] - fn constructor( - initial_supply: u120, - owner: Field, - ) { - + fn constructor(initial_supply: u120, owner: Field) { let balances = storage.balances; balances.at(owner).add(initial_supply, owner); @@ -52,11 +48,7 @@ contract EasyPrivateToken { // Mints `amount` of tokens to `owner`. #[aztec(private)] - fn mint( - amount: u120, - owner: Field, - ) { - + fn mint(amount: u120, owner: Field) { let balances = storage.balances; balances.at(owner).add(amount, owner); @@ -64,12 +56,7 @@ contract EasyPrivateToken { // Transfers `amount` of tokens from `sender` to a `recipient`. #[aztec(private)] - fn transfer( - amount: u120, - sender: Field, - recipient: Field, - ) { - + fn transfer(amount: u120, sender: Field, recipient: Field) { let balances = storage.balances; balances.at(sender).sub(amount, sender); @@ -77,10 +64,7 @@ contract EasyPrivateToken { } // Helper function to get the balance of a user ("unconstrained" is a Noir alternative of Solidity's "view" function). - unconstrained fn getBalance( - owner: Field, - ) -> Field { - + unconstrained fn getBalance(owner: Field) -> Field { let balances = storage.balances; // Return the sum of all notes in the set. 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 18d45ad39dd..436199240ad 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 @@ -89,23 +89,22 @@ impl EcdsaPublicKeyNote { } fn deserialize(serialized_note: [Field; ECDSA_PUBLIC_KEY_NOTE_LEN]) -> EcdsaPublicKeyNote { - let mut x: [u8; 32] = [0;32]; - let mut y: [u8; 32] = [0;32]; + let mut x: [u8; 32] = [0; 32]; + let mut y: [u8; 32] = [0; 32]; let part_x = serialized_note[0].to_be_bytes(32); - for i in 0..31 { x[i] = part_x[i + 1]; } + for i in 0..31 { + x[i] = part_x[i + 1]; + } x[31] = serialized_note[1].to_be_bytes(32)[31]; let part_y = serialized_note[2].to_be_bytes(32); - for i in 0..31 { y[i] = part_y[i + 1]; } + for i in 0..31 { + y[i] = part_y[i + 1]; + } y[31] = serialized_note[3].to_be_bytes(32)[31]; - EcdsaPublicKeyNote { - x, - y, - owner: serialized_note[4], - header: NoteHeader::empty(), - } + EcdsaPublicKeyNote { x, y, owner: serialized_note[4], header: NoteHeader::empty() } } fn serialize(note: EcdsaPublicKeyNote) -> [Field; ECDSA_PUBLIC_KEY_NOTE_LEN] { @@ -114,7 +113,7 @@ fn serialize(note: EcdsaPublicKeyNote) -> [Field; ECDSA_PUBLIC_KEY_NOTE_LEN] { fn compute_note_hash(note: EcdsaPublicKeyNote) -> Field { // TODO(#1205) Should use a non-zero generator index. - pedersen_hash(note.serialize(),0) + pedersen_hash(note.serialize(), 0) } fn compute_nullifier(note: EcdsaPublicKeyNote) -> Field { diff --git a/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main.nr index 4dabf31b3b6..7706217e639 100644 --- a/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main.nr @@ -41,10 +41,7 @@ contract EcdsaAccount { // Creates a new account out of an ECDSA public key to use for signature verification #[aztec(private)] - fn constructor( - signing_pub_key_x: pub [u8;32], - signing_pub_key_y: pub [u8;32], - ) { + fn constructor(signing_pub_key_x: pub [u8;32], signing_pub_key_y: pub [u8;32]) { let this = context.this_address(); let mut pub_key_note = EcdsaPublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, this); storage.public_key.initialize(&mut pub_key_note, Option::none(), true); @@ -79,11 +76,13 @@ contract EcdsaAccount { // Load public key from storage let storage = Storage::init(Context::private(context)); let public_key = storage.public_key.get_note(); - + // Load auth witness let witness: [Field; 64] = get_auth_witness(message_field); let mut signature: [u8; 64] = [0; 64]; - for i in 0..64 { signature[i] = witness[i] as u8; } + for i in 0..64 { + signature[i] = witness[i] as u8; + } // Verify payload signature using Ethereum's signing scheme // Note that noir expects the hash of the message/challenge as input to the ECDSA verification. @@ -97,7 +96,12 @@ contract EcdsaAccount { // Computes note hash and nullifier. // Note 1: Needs to be defined by every contract producing logs. // Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes. - unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, serialized_note: [Field; ECDSA_PUBLIC_KEY_NOTE_LEN]) -> [Field; 4] { + unconstrained fn compute_note_hash_and_nullifier( + contract_address: Field, + nonce: Field, + storage_slot: Field, + serialized_note: [Field; ECDSA_PUBLIC_KEY_NOTE_LEN] + ) -> [Field; 4] { assert(storage_slot == 1); let note_header = NoteHeader::new(contract_address, nonce, storage_slot); note_utils::compute_note_hash_and_nullifier(EcdsaPublicKeyNoteInterface, note_header, serialized_note) diff --git a/yarn-project/noir-contracts/src/contracts/escrow_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/escrow_contract/src/main.nr index 49bedc9234e..befda626373 100644 --- a/yarn-project/noir-contracts/src/contracts/escrow_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/escrow_contract/src/main.nr @@ -35,11 +35,9 @@ contract Escrow { // Creates a new instance // docs:start:constructor #[aztec(private)] - fn constructor( - owner: pub Field - ) { + fn constructor(owner: pub Field) { let this = context.this_address(); - + // Create a new note and add it to the owners set. let mut note = AddressNote::new(owner, this); @@ -50,11 +48,7 @@ contract Escrow { // Withdraws balance. Requires that msg.sender is registered as an owner. #[aztec(private)] - fn withdraw( - token: Field, - amount: Field, - recipient: Field, - ) { + fn withdraw(token: Field, amount: Field, recipient: Field) { let this = context.this_address(); let sender = context.msg_sender(); @@ -64,11 +58,7 @@ contract Escrow { assert(notes[0].is_some(), "Sender is not an owner."); let selector = compute_selector("transfer((Field),(Field),Field,Field)"); - let _callStackItem = context.call_private_function( - token, - selector, - [this, recipient, amount, 0] - ); + let _callStackItem = context.call_private_function(token, selector, [this, recipient, amount, 0]); } unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, serialized_note: [Field; ADDRESS_NOTE_LEN]) -> [Field; 4] { diff --git a/yarn-project/noir-contracts/src/contracts/import_test_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/import_test_contract/src/main.nr index 599a28218fb..abf55cd9ba6 100644 --- a/yarn-project/noir-contracts/src/contracts/import_test_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/import_test_contract/src/main.nr @@ -12,38 +12,33 @@ contract ImportTest { ManyNotesADeepStructTestCodeGenStruct, }; - #[aztec(private)] fn constructor( ) {} - + // Calls the testCodeGen on the Test contract at the target address // Used for testing calling a function with arguments of multiple types // See yarn-project/acir-simulator/src/client/private_execution.ts // See yarn-project/end-to-end/src/e2e_nested_contract.test.ts #[aztec(private)] - fn main( - target: Field - ) -> Field { + fn main(target: Field) -> Field { let test_contract_instance = TestPrivateContextInterface::at(target); - let return_values = test_contract_instance.test_code_gen( - &mut context, + let return_values = test_contract_instance.test_code_gen(&mut context, 1, true, 1 as u32, [1, 2], AStructTestCodeGenStruct { amount: 1, secret_hash: 2 }, ADeepStructTestCodeGenStruct { - a_field: 1, - a_bool: true, + a_field: 1, + a_bool: true, a_note: ANoteADeepStructTestCodeGenStruct { amount: 1, secret_hash: 2 }, many_notes: [ ManyNotesADeepStructTestCodeGenStruct { amount: 1, secret_hash: 2 }, ManyNotesADeepStructTestCodeGenStruct { amount: 1, secret_hash: 2 }, - ManyNotesADeepStructTestCodeGenStruct { amount: 1, secret_hash: 2 }, + ManyNotesADeepStructTestCodeGenStruct { amount: 1, secret_hash: 2 } ] - } - ); + }); return_values[0] } @@ -52,12 +47,10 @@ contract ImportTest { // Used for testing calling a function with no arguments // See yarn-project/end-to-end/src/e2e_nested_contract.test.ts #[aztec(private)] - fn callNoArgs( - target: Field - ) -> Field { + fn callNoArgs(target: Field) -> Field { let test_contract_instance = TestPrivateContextInterface::at(target); let return_values = test_contract_instance.get_this_address(&mut context); - + return_values[0] } @@ -65,9 +58,7 @@ contract ImportTest { // Used for testing calling an open function // See yarn-project/end-to-end/src/e2e_nested_contract.test.ts #[aztec(private)] - fn callOpenFn( - target: Field, - ) { + fn callOpenFn(target: Field) { let test_contract_instance = TestPrivateContextInterface::at(target); test_contract_instance.create_nullifier_public(&mut context, 1, 2); } @@ -76,12 +67,10 @@ contract ImportTest { // Used for testing calling an open function from another open function // See yarn-project/end-to-end/src/e2e_nested_contract.test.ts #[aztec(public)] - fn pubCallOpenFn( - target: Field, - ) -> Field { + fn pubCallOpenFn(target: Field) -> Field { let test_contract_instance = TestPublicContextInterface::at(target); let ret = test_contract_instance.create_nullifier_public(context, 1, 2); - + ret[0] } } 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 cb8dcd90ad4..e4158fda7f2 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 @@ -21,7 +21,7 @@ fn deserializeAsset(fields: [Field; ASSET_SERIALIZED_LEN]) -> Asset { interest_accumulator: fields[0] as u120, last_updated_ts: fields[1] as u120, loan_to_value: fields[2] as u120, - oracle_address: fields[3], + oracle_address: fields[3] } } @@ -30,7 +30,7 @@ fn serializeAsset(asset: Asset) -> [Field; ASSET_SERIALIZED_LEN] { asset.interest_accumulator as Field, asset.last_updated_ts as Field, asset.loan_to_value as Field, - asset.oracle_address, + asset.oracle_address ] } 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 eb20e2d5bdb..26592ff6d66 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 @@ -5,33 +5,23 @@ use dep::aztec::hash::pedersen_hash; // 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. -pub fn compute_identifier( - secret: Field, - on_behalf_of: Field, - self: Field, -) -> Field { +pub fn compute_identifier(secret: Field, on_behalf_of: Field, self: Field) -> Field { // EITHER secret OR on_behalf_of MUST be set. But not both - assert (!((secret == 0) as bool & (on_behalf_of == 0) as bool)); + assert(!((secret == 0) as bool & (on_behalf_of == 0) as bool)); if (secret != 0) { - pedersen_hash([self, secret],0) + pedersen_hash([self, secret], 0) } else { on_behalf_of } } -pub fn covered_by_collateral( - price: u120, - loan_to_value: u120, - collateral: u120, - increase: u120, - decrease: u120, -) -> u120 { - let price_precision = SafeU120{value: 1000000000}; - let ltv_precision = SafeU120{value: 10000}; +pub fn covered_by_collateral(price: u120, loan_to_value: u120, collateral: u120, increase: u120, decrease: u120) -> u120 { + let price_precision = SafeU120 { value: 1000000000 }; + let ltv_precision = SafeU120 { value: 10000 }; - let price = SafeU120{value: price}; - let collateral = SafeU120{value: collateral}.add(SafeU120{value:increase}).sub(SafeU120{value:decrease}); - let loan_to_value = SafeU120{value: loan_to_value}; + let price = SafeU120 { value: price }; + let collateral = SafeU120 { value: collateral }.add(SafeU120 { value: increase }).sub(SafeU120 { value: decrease }); + let loan_to_value = SafeU120 { value: loan_to_value }; let collateral_value = collateral.mul_div(price, price_precision); let debt_covered = collateral_value.mul_div(loan_to_value, ltv_precision); @@ -44,19 +34,14 @@ struct DebtReturn { static_debt: u120, } -pub fn debt_updates( - interest_accumulator: u120, - static_debt: u120, - increase: u120, - decrease: u120, -) -> DebtReturn { +pub fn debt_updates(interest_accumulator: u120, static_debt: u120, increase: u120, decrease: u120) -> DebtReturn { assert(interest_accumulator > 0); - let accumulator_precision = SafeU120{value: 1000000000}; + let accumulator_precision = SafeU120 { value: 1000000000 }; - let static_debt = SafeU120{value: static_debt}; - let interest_accumulator = SafeU120{value: interest_accumulator}; - let increase = SafeU120{value: increase}; - let decrease = SafeU120{value: decrease}; + let static_debt = SafeU120 { value: static_debt }; + let interest_accumulator = SafeU120 { value: interest_accumulator }; + let increase = SafeU120 { value: increase }; + let decrease = SafeU120 { value: decrease }; let current_debt_value = static_debt.mul_div(interest_accumulator, accumulator_precision); let new_debt_value = current_debt_value.add(increase).sub(decrease); @@ -71,18 +56,12 @@ pub fn debt_updates( // if you try to repay exact due to time diff between sim and execution. let new_static_debt = static_debt.add(static_debt_increase).sub(static_debt_decrease); - DebtReturn { - debt_value: new_debt_value.value, - static_debt: new_static_debt.value, - } + DebtReturn { debt_value: new_debt_value.value, static_debt: new_static_debt.value } } -pub fn debt_value( - static_debt: u120, - interest_accumulator: u120, -) -> u120 { - let static_debt = SafeU120{value: static_debt}; - let accumulator_precision = SafeU120{value: 1000000000}; - let interest_accumulator = SafeU120{value: interest_accumulator}; +pub fn debt_value(static_debt: u120, interest_accumulator: u120) -> u120 { + let static_debt = SafeU120 { value: static_debt }; + let accumulator_precision = SafeU120 { value: 1000000000 }; + let interest_accumulator = SafeU120 { value: interest_accumulator }; static_debt.mul_div_up(interest_accumulator, accumulator_precision).value -} \ No newline at end of file +} 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 5b089405a3f..9f9d3c518fb 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,17 +7,14 @@ 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 -pub fn compute_multiplier( - rate_per_second: u120, - dt: SafeU120, -) -> SafeU120 { - let base = SafeU120{value: 1000000000}; // 1e9 - let WAD = SafeU120{value: 1000000000000000000}; // 1e18 +pub fn compute_multiplier(rate_per_second: u120, dt: SafeU120) -> SafeU120 { + let base = SafeU120 { value: 1000000000 }; // 1e9 + let WAD = SafeU120 { value: 1000000000000000000 }; // 1e18 let diff = WAD.div(base); let mut res = base; if (!dt.is_zero()) { - let exp_minus_one = SafeU120{value: dt.value - 1}; - let exp_minus_two = SafeU120 {value: if (dt.value > 2) {dt.value - 2} else { 0 }}; + let exp_minus_one = SafeU120 { value: dt.value - 1 }; + let exp_minus_two = SafeU120 { value: if (dt.value > 2) { dt.value - 2 } else { 0 } }; // if rate_per_second < sqrt(WAD), then base_power_two and base_power_three = 0 let rate = SafeU120 { value: rate_per_second }; @@ -25,8 +22,8 @@ pub fn compute_multiplier( let base_power_three = base_power_two.mul_div(rate, WAD); let temp = dt.mul(exp_minus_one); - let second_term = temp.mul(base_power_two).div(SafeU120 {value: 2}); - let third_term = temp.mul(exp_minus_two).mul(base_power_three).div(SafeU120{value: 6}); + let second_term = temp.mul(base_power_two).div(SafeU120 { value: 2 }); + let third_term = temp.mul(exp_minus_two).mul(base_power_three).div(SafeU120 { value: 6 }); // throwing away precision to keep us under u120 :sob: let offset = dt.mul(rate).add(second_term).add(third_term).div(diff); @@ -34,4 +31,4 @@ pub fn compute_multiplier( res = base.add(offset); } res -} \ No newline at end of file +} 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 b4f0634f723..e2377ef2f6e 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 @@ -100,4 +100,4 @@ impl Lending { oracle_address: return_values[3], } } -} \ No newline at end of file +} diff --git a/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr index f9f32af3b84..adca6f6adc5 100644 --- a/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr @@ -101,26 +101,20 @@ contract Lending { ) {} #[aztec(public)] - fn init( - oracle_address: Field, - loan_to_value: Field, - collateral_asset: Field, - stable_coin: Field, - ) -> Field { - + fn init(oracle_address: Field, loan_to_value: Field, collateral_asset: Field, stable_coin: Field) -> Field { let asset_loc = storage.assets.at(0); let asset = asset_loc.read(); - assert (loan_to_value as u120 <= 10000); - assert (asset.last_updated_ts == 0); - assert (asset.interest_accumulator == 0); + assert(loan_to_value as u120 <= 10000); + assert(asset.last_updated_ts == 0); + assert(asset.interest_accumulator == 0); asset_loc.write(Asset { - interest_accumulator: 1000000000, - last_updated_ts: context.timestamp() as u120, - loan_to_value: loan_to_value as u120, - oracle_address, - }); + interest_accumulator: 1000000000, + last_updated_ts: context.timestamp() as u120, + loan_to_value: loan_to_value as u120, + oracle_address + }); storage.collateral_asset.write(collateral_asset); storage.stable_coin.write(stable_coin); @@ -131,16 +125,14 @@ contract Lending { // Create a position. #[aztec(public)] fn update_accumulator() -> Asset { - - let asset_loc = storage.assets.at(0); let mut asset = asset_loc.read(); - let dt: SafeU120 = SafeU120{value: context.timestamp() as u120}.sub(SafeU120{value: asset.last_updated_ts}); + let dt: SafeU120 = SafeU120 { value: context.timestamp() as u120 }.sub(SafeU120 { value: asset.last_updated_ts }); // Only update if time has passed. if (!dt.is_zero()) { - let precision: SafeU120 = SafeU120{value: 1000000000}; + let precision: SafeU120 = SafeU120 { value: 1000000000 }; let rate_per_second: u120 = 1268391679; // 4% yearly rate / (60 * 60 * 24 * 365) // if rate_per_second < sqrt(WAD) our approx is eq precision + rate * dt let multiplier = compute_multiplier(rate_per_second, dt); @@ -156,43 +148,34 @@ contract Lending { } #[aztec(private)] - fn deposit_private( - from: Field, - amount: Field, - nonce: Field, - secret: Field, - on_behalf_of: Field, - collateral_asset: Field, - ) { + fn deposit_private(from: Field, amount: Field, nonce: Field, secret: Field, on_behalf_of: Field, collateral_asset: Field) { let on_behalf_of = compute_identifier(secret, on_behalf_of, context.msg_sender()); let _res = Token::at(collateral_asset).unshield(&mut context, from, context.this_address(), amount, nonce); // _deposit(on_behalf_of, amount, collateral_asset) let selector = compute_selector("_deposit(Field,Field,Field)"); - let _callStackItem2 = context.call_public_function(context.this_address(), selector, [on_behalf_of, amount, collateral_asset]); + let _callStackItem2 = context.call_public_function(context.this_address(), + selector, + [on_behalf_of, amount, collateral_asset]); } #[aztec(public)] - fn deposit_public( - amount: Field, - nonce: Field, - on_behalf_of: Field, - collateral_asset: Field, - ) -> Field { - Token::at(collateral_asset).transfer_public(context, context.msg_sender(), context.this_address(), amount, nonce); + fn deposit_public(amount: Field, nonce: Field, on_behalf_of: Field, collateral_asset: Field) -> Field { + Token::at(collateral_asset).transfer_public(context, + context.msg_sender(), + context.this_address(), + amount, + nonce); let selector = compute_selector("_deposit(Field,Field,Field)"); - let return_values = context.call_public_function(context.this_address(), selector, [on_behalf_of, amount, collateral_asset]); - + let return_values = context.call_public_function(context.this_address(), + selector, + [on_behalf_of, amount, collateral_asset]); + return_values[0] } #[aztec(public)] - internal fn _deposit( - owner: Field, - amount: Field, - collateral_asset: Field, - ) -> Field { + internal fn _deposit(owner: Field, amount: Field, collateral_asset: Field) -> Field { let _asset = Lending::at(context.this_address()).update_accumulator(context); - let coll_asset = storage.collateral_asset.read(); assert(coll_asset == collateral_asset); @@ -205,37 +188,26 @@ contract Lending { } #[aztec(private)] - fn withdraw_private( - secret: Field, - to: Field, - amount: Field - ) { + fn withdraw_private(secret: Field, to: Field, amount: Field) { let on_behalf_of = compute_identifier(secret, 0, context.msg_sender()); let selector = compute_selector("_withdraw(Field,Field,Field)"); let _callStackItem = context.call_public_function(context.this_address(), selector, [on_behalf_of, to, amount]); } #[aztec(public)] - fn withdraw_public( - to: Field, - amount: Field, - ) -> Field { + fn withdraw_public(to: Field, amount: Field) -> Field { let selector = compute_selector("_withdraw(Field,Field,Field)"); - let return_values = context.call_public_function(context.this_address(), selector, [context.msg_sender(), to, amount]); + let return_values = context.call_public_function(context.this_address(), + selector, + [context.msg_sender(), to, amount]); return_values[0] } #[aztec(public)] - internal fn _withdraw( - owner: Field, - recipient: Field, - amount: Field - ) -> Field { + internal fn _withdraw(owner: Field, recipient: Field, amount: Field) -> Field { let asset = Lending::at(context.this_address()).update_accumulator(context); let price = PriceFeed::at(asset.oracle_address).get_price(context); - - let coll_loc = storage.collateral.at(owner); let collateral: Field = coll_loc.read(); @@ -245,10 +217,14 @@ contract Lending { // debt_covered will revert if decrease would leave insufficient collateral to cover debt. // or trying to remove more collateral than available - let debt_covered = covered_by_collateral(price, asset.loan_to_value, collateral as u120, 0, amount as u120); + let debt_covered = covered_by_collateral(price, + asset.loan_to_value, + collateral as u120, + 0, + amount as u120); let debt_returns = debt_updates(asset.interest_accumulator, static_debt as u120, 0, 0); - assert (debt_returns.debt_value < debt_covered); + assert(debt_returns.debt_value < debt_covered); coll_loc.write(collateral - amount); @@ -260,37 +236,26 @@ contract Lending { } #[aztec(private)] - fn borrow_private( - secret: Field, - to: Field, - amount: Field - ) { + fn borrow_private(secret: Field, to: Field, amount: Field) { let on_behalf_of = compute_identifier(secret, 0, context.msg_sender()); let selector = compute_selector("_borrow(Field,Field,Field)"); let _callStackItem = context.call_public_function(context.this_address(), selector, [on_behalf_of, to, amount]); } #[aztec(public)] - fn borrow_public( - to: Field, - amount: Field - ) -> Field { + fn borrow_public(to: Field, amount: Field) -> Field { let selector = compute_selector("_borrow(Field,Field,Field)"); - let return_values = context.call_public_function(context.this_address(), selector, [context.msg_sender(), to, amount]); - + let return_values = context.call_public_function(context.this_address(), + selector, + [context.msg_sender(), to, amount]); + return_values[0] } #[aztec(public)] - internal fn _borrow( - owner: Field, - to: Field, - amount: Field - ) -> Field { + internal fn _borrow(owner: Field, to: Field, amount: Field) -> Field { let asset = Lending::at(context.this_address()).update_accumulator(context); let price = PriceFeed::at(asset.oracle_address).get_price(context); - - // Fetch collateral and static_debt, compute health of current position let collateral = storage.collateral.at(owner).read() as u120; @@ -299,7 +264,7 @@ contract Lending { let debt_covered = covered_by_collateral(price, asset.loan_to_value, collateral, 0, 0); let debt_returns = debt_updates(asset.interest_accumulator, static_debt, amount as u120, 0); - assert (debt_returns.debt_value < debt_covered); + assert(debt_returns.debt_value < debt_covered); storage.static_debt.at(owner).write(debt_returns.static_debt as Field); @@ -311,42 +276,27 @@ contract Lending { } #[aztec(private)] - fn repay_private( - from: Field, - amount: Field, - nonce: Field, - secret: Field, - on_behalf_of: Field, - stable_coin: Field, - ) { + fn repay_private(from: Field, amount: Field, nonce: Field, secret: Field, on_behalf_of: Field, stable_coin: Field) { let on_behalf_of = compute_identifier(secret, on_behalf_of, context.msg_sender()); let _res = Token::at(stable_coin).burn(&mut context, from, amount, nonce); let selector = compute_selector("_repay(Field,Field,Field)"); - let _callStackItem = context.call_public_function(context.this_address(), selector, [on_behalf_of, amount, stable_coin]); + let _callStackItem = context.call_public_function(context.this_address(), + selector, + [on_behalf_of, amount, stable_coin]); } #[aztec(public)] - fn repay_public( - amount: Field, - nonce: Field, - owner: Field, - stable_coin: Field, - ) -> Field { + fn repay_public(amount: Field, nonce: Field, owner: Field, stable_coin: Field) -> Field { Token::at(stable_coin).burn_public(context, context.msg_sender(), amount, nonce); let selector = compute_selector("_repay(Field,Field,Field)"); let return_values = context.call_public_function(context.this_address(), selector, [owner, amount, stable_coin]); - + return_values[0] } #[aztec(public)] - internal fn _repay( - owner: Field, - amount: Field, - stable_coin: Field, - ) { + internal fn _repay(owner: Field, amount: Field, stable_coin: Field) { let asset = Lending::at(context.this_address()).update_accumulator(context); - // To ensure that private is using the correct token. assert(stable_coin == storage.stable_coin.read()); @@ -355,30 +305,23 @@ contract Lending { let debt_returns = debt_updates(asset.interest_accumulator, static_debt, 0, amount as u120); storage.static_debt.at(owner).write(debt_returns.static_debt as Field); - + 1 } - unconstrained fn get_asset( - assetId: Field, - ) -> Asset { - + unconstrained fn get_asset(assetId: Field) -> Asset { storage.assets.at(assetId).read() } - unconstrained fn get_position( - owner: Field, - ) -> Position { - + unconstrained fn get_position(owner: Field) -> Position { let collateral = storage.collateral.at(owner).read(); let static_debt = storage.static_debt.at(owner).read(); let asset = storage.assets.at(0).read(); let debt = debt_value(static_debt as u120, asset.interest_accumulator as u120) as Field; - Position {collateral, static_debt, debt} + Position { collateral, static_debt, debt } } unconstrained fn get_assets() -> [Field; 2] { - [storage.collateral_asset.read(), storage.stable_coin.read()] } diff --git a/yarn-project/noir-contracts/src/contracts/parent_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/parent_contract/src/main.nr index 02e893ecb4a..9560223aff5 100644 --- a/yarn-project/noir-contracts/src/contracts/parent_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/parent_contract/src/main.nr @@ -7,10 +7,7 @@ contract Parent { // Private function to call another private function in the targetContract using the provided selector #[aztec(private)] - fn entryPoint( - targetContract: Field, - targetSelector: Field, - ) -> Field { + fn entryPoint(targetContract: Field, targetSelector: Field) -> Field { // Call the target private function let return_values = context.call_private_function(targetContract, targetSelector, [0]); @@ -20,11 +17,7 @@ contract Parent { // Public function to directly call another public function to the targetContract using the selector and value provided #[aztec(public)] - fn pubEntryPoint( - targetContract: Field, - targetSelector: Field, - initValue: Field - ) -> Field { + fn pubEntryPoint(targetContract: Field, targetSelector: Field, initValue: Field) -> Field { let return_values = context.call_public_function(targetContract, targetSelector, [initValue]); return_values[0] @@ -32,11 +25,7 @@ contract Parent { // Same as pubEntryPoint, but calls the target contract twice, using the return value from the first invocation as the argument for the second. #[aztec(public)] - fn pubEntryPointTwice( - targetContract: Field, - targetSelector: Field, - initValue: Field - ) -> Field { + fn pubEntryPointTwice(targetContract: Field, targetSelector: Field, initValue: Field) -> Field { let returnValue = context.call_public_function(targetContract, targetSelector, [initValue])[0]; let return_values = context.call_public_function(targetContract, targetSelector, [returnValue]); @@ -45,11 +34,7 @@ contract Parent { // Private function to enqueue a call to the targetContract address using the selector and argument provided #[aztec(private)] - fn enqueueCallToChild( - targetContract: Field, - targetSelector: Field, - targetValue: Field, - ) { + fn enqueueCallToChild(targetContract: Field, targetSelector: Field, targetValue: Field) { context.call_public_function(targetContract, targetSelector, [targetValue]); } @@ -57,12 +42,11 @@ contract Parent { // - one through a nested call to enqueueCallToChild with value 10, // - followed by one issued directly from this function with value 20. #[aztec(private)] - fn enqueueCallsToChildWithNestedFirst( - targetContract: Field, - targetSelector: Field, - ) { + fn enqueueCallsToChildWithNestedFirst(targetContract: Field, targetSelector: Field) { let enqueueCallToChildSelector = compute_selector("enqueueCallToChild(Field,Field,Field)"); - let _ret = context.call_private_function(context.this_address(), enqueueCallToChildSelector, [targetContract, targetSelector, 10]); + let _ret = context.call_private_function(context.this_address(), + enqueueCallToChildSelector, + [targetContract, targetSelector, 10]); context.call_public_function(targetContract, targetSelector, [20]); } @@ -70,22 +54,17 @@ contract Parent { // - one issued directly from this function with value 20, // - followed by one through a nested call to enqueueCallToChild with value 10. #[aztec(private)] - fn enqueueCallsToChildWithNestedLast( - targetContract: Field, - targetSelector: Field, - ) { + fn enqueueCallsToChildWithNestedLast(targetContract: Field, targetSelector: Field) { context.call_public_function(targetContract, targetSelector, [20]); let enqueueCallToChildSelector = compute_selector("enqueueCallToChild(Field,Field,Field)"); - let _ret = context.call_private_function(context.this_address(), enqueueCallToChildSelector, [targetContract, targetSelector, 10]); + let _ret = context.call_private_function(context.this_address(), + enqueueCallToChildSelector, + [targetContract, targetSelector, 10]); } // Private function to enqueue a call to the targetContract address using the selector and argument provided #[aztec(private)] - fn enqueueCallToChildTwice( - targetContract: Field, - targetSelector: Field, - targetValue: Field, - ) { + fn enqueueCallToChildTwice(targetContract: Field, targetSelector: Field, targetValue: Field) { // Enqueue the first public call context.call_public_function(targetContract, targetSelector, [targetValue]); // Enqueue the second public call @@ -94,28 +73,26 @@ contract Parent { // Private function to enqueue a call to the pubEntryPoint function of this same contract, passing the target arguments provided #[aztec(private)] - fn enqueueCallToPubEntryPoint( - targetContract: Field, - targetSelector: Field, - targetValue: Field, - ) { + fn enqueueCallToPubEntryPoint(targetContract: Field, targetSelector: Field, targetValue: Field) { let pubEntryPointSelector = compute_selector("pubEntryPoint(Field,Field,Field)"); let thisAddress = context.this_address(); - let _void = context.call_public_function(thisAddress, pubEntryPointSelector, [targetContract, targetSelector, targetValue]); + let _void = context.call_public_function(thisAddress, + pubEntryPointSelector, + [targetContract, targetSelector, targetValue]); } // Private function to enqueue two calls to the pubEntryPoint function of this same contract, passing the target arguments provided #[aztec(private)] - fn enqueueCallsToPubEntryPoint( - targetContract: Field, - targetSelector: Field, - targetValue: Field, - ) { + fn enqueueCallsToPubEntryPoint(targetContract: Field, targetSelector: Field, targetValue: Field) { let pubEntryPointSelector = compute_selector("pubEntryPoint(Field,Field,Field)"); let thisAddress = context.this_address(); - - context.call_public_function(thisAddress, pubEntryPointSelector, [targetContract, targetSelector, targetValue]); - context.call_public_function(thisAddress, pubEntryPointSelector, [targetContract, targetSelector, targetValue + 1]); + context.call_public_function(thisAddress, + pubEntryPointSelector, + [targetContract, targetSelector, targetValue]); + + context.call_public_function(thisAddress, + pubEntryPointSelector, + [targetContract, targetSelector, targetValue + 1]); } } diff --git a/yarn-project/noir-contracts/src/contracts/pending_commitments_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/pending_commitments_contract/src/main.nr index 7ccbc640daf..c07f02136d1 100644 --- a/yarn-project/noir-contracts/src/contracts/pending_commitments_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/pending_commitments_contract/src/main.nr @@ -49,12 +49,7 @@ contract PendingCommitments { // getting / reading that note all in the same contract function // Realistic way to describe this test is "Mint note A, then burn note A in the same transaction" #[aztec(private)] - fn test_insert_then_get_then_nullify_flat( - amount: Field, - owner: Field, - ) -> Field { - - + fn test_insert_then_get_then_nullify_flat(amount: Field, owner: Field) -> Field { let owner_balance = storage.balances.at(owner); let mut note = ValueNote::new(amount, owner); @@ -76,12 +71,7 @@ contract PendingCommitments { // Confirm cannot access commitments inserted later in same function #[aztec(private)] - fn test_bad_get_then_insert_flat( - amount: Field, - owner: Field, - ) -> Field { - - + fn test_bad_get_then_insert_flat(amount: Field, owner: Field) -> Field { let owner_balance = storage.balances.at(owner); let options = NoteGetterOptions::with_filter(filter_notes_min_sum, amount); @@ -100,19 +90,11 @@ contract PendingCommitments { // Dummy nested/inner function (to pass a function which does nothing) #[aztec(private)] - fn dummy( - amount: Field, - owner: Field, - ) {} + fn dummy(amount: Field, owner: Field) {} // Nested/inner function to create and insert a note #[aztec(private)] - fn insert_note( - amount: Field, - owner: Field, - ) { - - + fn insert_note(amount: Field, owner: Field) { let owner_balance = storage.balances.at(owner); let mut note = ValueNote::new(amount, owner); @@ -122,12 +104,7 @@ contract PendingCommitments { // Nested/inner function to get a note and confirm it matches the expected value #[aztec(private)] - fn get_then_nullify_note( - expected_value: Field, - owner: Field, - ) -> Field { - - + fn get_then_nullify_note(expected_value: Field, owner: Field) -> Field { let owner_balance = storage.balances.at(owner); let options = NoteGetterOptions::new().set_limit(1); @@ -142,11 +119,7 @@ contract PendingCommitments { // Nested/inner function to get a note and confirms that none is returned #[aztec(private)] - fn get_note_zero_balance( - owner: Field, - ) { - - + fn get_note_zero_balance(owner: Field) { let owner_balance = storage.balances.at(owner); let options = NoteGetterOptions::new(); @@ -165,33 +138,42 @@ contract PendingCommitments { owner: Field, insert_fn_selector: Field, get_then_nullify_fn_selector: Field, - get_note_zero_fn_selector: Field, + get_note_zero_fn_selector: Field ) { // nested call to create/insert note - let _callStackItem1 = context.call_private_function(inputs.call_context.storage_contract_address, insert_fn_selector, [amount, owner]); + let _callStackItem1 = context.call_private_function(inputs.call_context.storage_contract_address, + insert_fn_selector, + [amount, owner]); // nested call to read and nullify that note - let _callStackItem2 = context.call_private_function(inputs.call_context.storage_contract_address, get_then_nullify_fn_selector, [amount, owner]); - // nested call to confirm that balance is zero - let _callStackItem3 = context.call_private_function(inputs.call_context.storage_contract_address, get_note_zero_fn_selector, [owner]); + let _callStackItem2 = context.call_private_function(inputs.call_context.storage_contract_address, + get_then_nullify_fn_selector, + [amount, owner]); + // nested call to confirm that balance is zero + let _callStackItem3 = context.call_private_function(inputs.call_context.storage_contract_address, + get_note_zero_fn_selector, + [owner]); } // same test as above, but insert 2, get 2, nullify 2 #[aztec(private)] - fn test_insert2_then_get2_then_nullify2_all_in_nested_calls( - amount: Field, - owner: Field, - insert_fn_selector: Field, - get_then_nullify_fn_selector: Field, - ) { + fn test_insert2_then_get2_then_nullify2_all_in_nested_calls(amount: Field, owner: Field, insert_fn_selector: Field, get_then_nullify_fn_selector: Field) { // args for nested calls let args = [amount, owner]; // nested call to create/insert note - let _callStackItem1 = context.call_private_function(inputs.call_context.storage_contract_address, insert_fn_selector, args); - let _callStackItem2 = context.call_private_function(inputs.call_context.storage_contract_address, insert_fn_selector, args); + let _callStackItem1 = context.call_private_function(inputs.call_context.storage_contract_address, + insert_fn_selector, + args); + let _callStackItem2 = context.call_private_function(inputs.call_context.storage_contract_address, + insert_fn_selector, + args); // nested call to read and nullify that note - let _callStackItem3 = context.call_private_function(inputs.call_context.storage_contract_address, get_then_nullify_fn_selector, args); - let _callStackItem4 = context.call_private_function(inputs.call_context.storage_contract_address, get_then_nullify_fn_selector, args); + let _callStackItem3 = context.call_private_function(inputs.call_context.storage_contract_address, + get_then_nullify_fn_selector, + args); + let _callStackItem4 = context.call_private_function(inputs.call_context.storage_contract_address, + get_then_nullify_fn_selector, + args); // nested call to confirm that balance is zero // TODO(dbanks12): once > 4 nested calls is supported, can confirm 0 balance: //let _callStackItem5 = context.call_private_function(inputs.call_context.storage_contract_address, get_note_zero_fn_selector, [owner]); @@ -199,20 +181,21 @@ contract PendingCommitments { // same test as above, but insert 2, get 1, nullify 1 #[aztec(private)] - fn test_insert2_then_get2_then_nullify1_all_in_nested_calls( - amount: Field, - owner: Field, - insert_fn_selector: Field, - get_then_nullify_fn_selector: Field, - ) { + fn test_insert2_then_get2_then_nullify1_all_in_nested_calls(amount: Field, owner: Field, insert_fn_selector: Field, get_then_nullify_fn_selector: Field) { // args for nested calls let args = [amount, owner]; // nested call to create/insert note - let _callStackItem1 = context.call_private_function(inputs.call_context.storage_contract_address, insert_fn_selector, args); - let _callStackItem2 = context.call_private_function(inputs.call_context.storage_contract_address, insert_fn_selector, args); + let _callStackItem1 = context.call_private_function(inputs.call_context.storage_contract_address, + insert_fn_selector, + args); + let _callStackItem2 = context.call_private_function(inputs.call_context.storage_contract_address, + insert_fn_selector, + args); // nested call to read and nullify that note - let _callStackItem3 = context.call_private_function(inputs.call_context.storage_contract_address, get_then_nullify_fn_selector, args); + let _callStackItem3 = context.call_private_function(inputs.call_context.storage_contract_address, + get_then_nullify_fn_selector, + args); } // insert 1 note, then get 2 notes (one pending, one persistent) and nullify both. @@ -224,18 +207,26 @@ contract PendingCommitments { owner: Field, insert_fn_selector: Field, get_then_nullify_fn_selector: Field, - get_note_zero_fn_selector: Field, + get_note_zero_fn_selector: Field ) { // args for nested calls let args = [amount, owner]; // nested call to create/insert note - let _callStackItem1 = context.call_private_function(inputs.call_context.storage_contract_address, insert_fn_selector, args); + let _callStackItem1 = context.call_private_function(inputs.call_context.storage_contract_address, + insert_fn_selector, + args); // nested call to read and nullify that note - let _callStackItem2 = context.call_private_function(inputs.call_context.storage_contract_address, get_then_nullify_fn_selector, args); - let _callStackItem3 = context.call_private_function(inputs.call_context.storage_contract_address, get_then_nullify_fn_selector, args); - - let _callStackItem4 = context.call_private_function(inputs.call_context.storage_contract_address, get_note_zero_fn_selector, [owner]); + let _callStackItem2 = context.call_private_function(inputs.call_context.storage_contract_address, + get_then_nullify_fn_selector, + args); + let _callStackItem3 = context.call_private_function(inputs.call_context.storage_contract_address, + get_then_nullify_fn_selector, + args); + + let _callStackItem4 = context.call_private_function(inputs.call_context.storage_contract_address, + get_note_zero_fn_selector, + [owner]); } // Confirm cannot get/read a pending commitment in a nested call @@ -260,4 +251,4 @@ contract PendingCommitments { let note_header = NoteHeader::new(contract_address, nonce, storage_slot); note_utils::compute_note_hash_and_nullifier(ValueNoteMethods, note_header, serialized_note) } -} \ No newline at end of file +} diff --git a/yarn-project/noir-contracts/src/contracts/price_feed_contract/src/asset.nr b/yarn-project/noir-contracts/src/contracts/price_feed_contract/src/asset.nr index 9686d74a28d..9d464eefddc 100644 --- a/yarn-project/noir-contracts/src/contracts/price_feed_contract/src/asset.nr +++ b/yarn-project/noir-contracts/src/contracts/price_feed_contract/src/asset.nr @@ -7,9 +7,7 @@ struct Asset { global ASSET_SERIALIZED_LEN: Field = 1; fn deserializeAsset(fields: [Field; ASSET_SERIALIZED_LEN]) -> Asset { - Asset { - price: fields[0] as u120, - } + Asset { price: fields[0] as u120 } } fn serializeAsset(asset: Asset) -> [Field; ASSET_SERIALIZED_LEN] { diff --git a/yarn-project/noir-contracts/src/contracts/price_feed_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/price_feed_contract/src/main.nr index 1b59c3cd5ac..b4a2e6461bc 100644 --- a/yarn-project/noir-contracts/src/contracts/price_feed_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/price_feed_contract/src/main.nr @@ -35,33 +35,22 @@ contract PriceFeed { } #[aztec(private)] - fn constructor(){} + fn constructor() {} #[aztec(public)] - fn set_price( - asset_id: Field, - price: u120, - ) -> Field { - + fn set_price(asset_id: Field, price: u120) -> Field { let asset = storage.assets.at(asset_id); - asset.write(Asset {price: price}); + asset.write(Asset { price }); 1 } #[aztec(public)] - fn get_price( - asset_id: Field, - ) -> Asset { - - + fn get_price(asset_id: Field) -> Asset { storage.assets.at(asset_id).read() } - unconstrained fn fetch_price( - assetId: Field, - ) -> Asset { - + unconstrained fn fetch_price(assetId: Field) -> Asset { storage.assets.at(assetId).read() } diff --git a/yarn-project/noir-contracts/src/contracts/schnorr_account_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/schnorr_account_contract/src/main.nr index 40985f45f38..34513072247 100644 --- a/yarn-project/noir-contracts/src/contracts/schnorr_account_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/schnorr_account_contract/src/main.nr @@ -40,10 +40,7 @@ contract SchnorrAccount { // Constructs the contract #[aztec(private)] - fn constructor( - signing_pub_key_x: pub Field, - signing_pub_key_y: pub Field, - ) { + fn constructor(signing_pub_key_x: pub Field, signing_pub_key_y: pub Field) { let this = context.this_address(); // docs:start:initialize let mut pub_key_note = PublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, this); @@ -86,10 +83,15 @@ contract SchnorrAccount { // Load auth witness let witness: [Field; 64] = get_auth_witness(message_hash); let mut signature: [u8; 64] = [0; 64]; - for i in 0..64 { signature[i] = witness[i] as u8; } + for i in 0..64 { + signature[i] = witness[i] as u8; + } // Verify signature of the payload bytes - let verification = std::schnorr::verify_signature(public_key.x, public_key.y, signature, message_hash.to_be_bytes(32)); + let verification = std::schnorr::verify_signature(public_key.x, + public_key.y, + signature, + message_hash.to_be_bytes(32)); assert(verification == true); // docs:end:entrypoint true @@ -98,7 +100,12 @@ contract SchnorrAccount { // Computes notes hash and nullifier. // Note 1: Needs to be defined by every contract producing logs. // Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes. - unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, serialized_note: [Field; PUBLIC_KEY_NOTE_LEN]) -> [Field; 4] { + unconstrained fn compute_note_hash_and_nullifier( + contract_address: Field, + nonce: Field, + storage_slot: Field, + serialized_note: [Field; PUBLIC_KEY_NOTE_LEN] + ) -> [Field; 4] { assert(storage_slot == 1); let note_header = NoteHeader::new(contract_address, nonce, storage_slot); note_utils::compute_note_hash_and_nullifier(PublicKeyNoteMethods, note_header, serialized_note) 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 538eb288ae6..5547b887f5b 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 @@ -68,12 +68,7 @@ impl PublicKeyNote { } fn deserialize(serialized_note: [Field; PUBLIC_KEY_NOTE_LEN]) -> PublicKeyNote { - PublicKeyNote { - x: serialized_note[0], - y: serialized_note[1], - owner: serialized_note[2], - header: NoteHeader::empty(), - } + PublicKeyNote { x: serialized_note[0], y: serialized_note[1], owner: serialized_note[2], header: NoteHeader::empty() } } fn serialize(note: PublicKeyNote) -> [Field; PUBLIC_KEY_NOTE_LEN] { @@ -82,7 +77,7 @@ fn serialize(note: PublicKeyNote) -> [Field; PUBLIC_KEY_NOTE_LEN] { fn compute_note_hash(note: PublicKeyNote) -> Field { // TODO(#1205) Should use a non-zero generator index. - pedersen_hash(note.serialize(),0) + pedersen_hash(note.serialize(), 0) } fn compute_nullifier(note: PublicKeyNote) -> Field { diff --git a/yarn-project/noir-contracts/src/contracts/schnorr_hardcoded_account_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/schnorr_hardcoded_account_contract/src/main.nr index bfaa0b285e4..69b6ef6b5b6 100644 --- a/yarn-project/noir-contracts/src/contracts/schnorr_hardcoded_account_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/schnorr_hardcoded_account_contract/src/main.nr @@ -52,14 +52,18 @@ contract SchnorrHardcodedAccount { // Load auth witness and format as an u8 array let witness: [Field; 64] = get_auth_witness(message_hash); let mut signature: [u8; 64] = [0; 64]; - for i in 0..64 { signature[i] = witness[i] as u8; } + for i in 0..64 { + signature[i] = witness[i] as u8; + } // Verify signature using hardcoded public key - let verification = std::schnorr::verify_signature(public_key_x, public_key_y, signature, message_hash.to_be_bytes(32)); + let verification = std::schnorr::verify_signature(public_key_x, + public_key_y, + signature, + message_hash.to_be_bytes(32)); assert(verification == true); true } // docs:end:is-valid - } // docs:end:contract \ No newline at end of file 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 2cb544a4502..5b6b3dd7219 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 @@ -24,4 +24,4 @@ impl 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/main.nr b/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/main.nr index 6030f2f1251..6ddcff3a22e 100644 --- a/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/main.nr @@ -49,4 +49,4 @@ contract SchnorrSingleKeyAccount { assert(recover_address(message_hash, witness) == context.this_address()); true } -} \ 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 3b814373567..db5384cb7c5 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,14 +2,14 @@ use dep::std::{schnorr::verify_signature}; use dep::aztec::address::compute_address; use crate::auth_oracle::{AuthWitness}; -pub fn recover_address( - message_hash: Field, - witness: AuthWitness, -) -> Field { +pub fn recover_address(message_hash: Field, witness: AuthWitness) -> Field { let message_bytes = message_hash.to_be_bytes(32); - let verification = verify_signature(witness.owner.x, witness.owner.y, witness.signature, message_bytes); + let verification = verify_signature(witness.owner.x, + witness.owner.y, + witness.signature, + message_bytes); assert(verification == true); let reproduced_address = compute_address(witness.owner.x, witness.owner.y, witness.partial_address); reproduced_address -} \ No newline at end of file +} diff --git a/yarn-project/noir-contracts/src/contracts/slow_tree_contract/src/capsule.nr b/yarn-project/noir-contracts/src/contracts/slow_tree_contract/src/capsule.nr index d47e56d47a4..8731eca35d2 100644 --- a/yarn-project/noir-contracts/src/contracts/slow_tree_contract/src/capsule.nr +++ b/yarn-project/noir-contracts/src/contracts/slow_tree_contract/src/capsule.nr @@ -4,4 +4,4 @@ fn pop_capsule_oracle() -> [Field; N] {} // A capsule is a "blob" of data that is passed to the contract through an oracle. unconstrained pub fn pop_capsule() -> [Field; N] { pop_capsule_oracle() -} \ No newline at end of file +} diff --git a/yarn-project/noir-contracts/src/contracts/slow_tree_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/slow_tree_contract/src/main.nr index f2345e111ac..0af6f5565a2 100644 --- a/yarn-project/noir-contracts/src/contracts/slow_tree_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/slow_tree_contract/src/main.nr @@ -84,11 +84,9 @@ contract SlowTree { let expected_root = compute_merkle_root(p.value, p.index, p.sibling_path); let selector = compute_selector("_assert_current_root(Field,Field)"); - context.call_public_function( - context.this_address(), - selector, - [context.msg_sender(), expected_root] - ); + context.call_public_function(context.this_address(), + selector, + [context.msg_sender(), expected_root]); p.value } @@ -117,40 +115,27 @@ contract SlowTree { let new_after_root = compute_merkle_root(p.new_value, p.index, p.after.sibling_path); let selector = compute_selector("_update(Field,Field,Field,Field,Field,Field)"); - context.call_public_function( - context.this_address(), - selector, + context.call_public_function(context.this_address(), + selector, [ - context.msg_sender(), - p.index, - p.new_value, - before_root, - after_root, + context.msg_sender(), + p.index, + p.new_value, + before_root, + after_root, new_after_root - ] - ); + ]); } #[aztec(public)] - internal fn _update( - caller: Field, - index: Field, - new_value: Field, - before: Field, - after: Field, - new_root: Field - ) { + internal fn _update(caller: Field, index: Field, new_value: Field, before: Field, after: Field, new_root: Field) { let current_root = storage.trees.at(caller).current_root(); let after_root = storage.trees.at(caller).read_root().after; assert(current_root == before, "Before root does not match expected"); assert(after_root == after, "After root does not match expected"); - storage.trees.at(caller).update_unsafe_at( - index, - new_value, - new_root, - ); + storage.trees.at(caller).update_unsafe_at(index, new_value, new_root); } unconstrained fn un_read_leaf_at(address: Field, key: Field) -> Leaf { @@ -164,4 +149,4 @@ contract SlowTree { unconstrained fn compute_note_hash_and_nullifier(_contract_address: Field, _nonce: Field, _storage_slot: Field, _preimage: [Field; 4]) -> [Field; 4] { [0x0d, 0x0e, 0x0a, 0x0d] } -} \ No newline at end of file +} diff --git a/yarn-project/noir-contracts/src/contracts/slow_tree_contract/src/types.nr b/yarn-project/noir-contracts/src/contracts/slow_tree_contract/src/types.nr index cdef27fbbf1..0f4f5eb4119 100644 --- a/yarn-project/noir-contracts/src/contracts/slow_tree_contract/src/types.nr +++ b/yarn-project/noir-contracts/src/contracts/slow_tree_contract/src/types.nr @@ -7,15 +7,11 @@ struct MembershipProof { } fn deserialize_membership_proof(serialized: [Field; M]) -> MembershipProof { - let mut sibling_path = [0; N]; - for i in 0..N { - sibling_path[i] = serialized[2 + i]; - } - MembershipProof { - index: serialized[0], - value: serialized[1], - sibling_path, - } + let mut sibling_path = [0; N]; + for i in 0..N { + sibling_path[i] = serialized[2 + i]; + } + MembershipProof { index: serialized[0], value: serialized[1], sibling_path } } impl MembershipProof { @@ -32,4 +28,4 @@ impl MembershipProof { fn deserialize(serialized: [Field; M]) -> Self { deserialize_membership_proof(serialized) } -} \ No newline at end of file +} diff --git a/yarn-project/noir-contracts/src/contracts/stateful_test_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/stateful_test_contract/src/main.nr index 921d11f013e..491f8ff494a 100644 --- a/yarn-project/noir-contracts/src/contracts/stateful_test_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/stateful_test_contract/src/main.nr @@ -55,23 +55,15 @@ contract StatefulTest { } #[aztec(private)] - fn create_note( - owner: Field, - value: Field, - ) { - - if (value != 0){ + fn create_note(owner: Field, value: Field) { + if (value != 0) { let loc = storage.notes.at(owner); increment(loc, value, owner); } } #[aztec(private)] - fn destroy_and_create( - recipient: Field, - amount: Field, - ) { - + fn destroy_and_create(recipient: Field, amount: Field) { let sender = context.msg_sender(); let sender_notes = storage.notes.at(sender); @@ -81,10 +73,7 @@ contract StatefulTest { increment(recipient_notes, amount, recipient); } - unconstrained fn summed_values( - owner: Field, - ) -> Field { - + unconstrained fn summed_values(owner: Field) -> Field { let owner_balance = storage.notes.at(owner); // Return the sum of all notes in the set. 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 1bb62e9f3f6..65cf52e96b5 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 @@ -1,5 +1,5 @@ /* Autogenerated file, do not edit! */ - + use dep::std; use dep::aztec::context::{ PrivateContext, PublicContext }; use dep::aztec::constants_gen::RETURN_VALUES_LENGTH; @@ -26,7 +26,6 @@ struct ManyNotesADeepStructTestCodeGenStruct { secret_hash: Field, } - // Interface for calling Test functions from a private context struct TestPrivateContextInterface { address: Field, @@ -242,9 +241,6 @@ impl TestPrivateContextInterface { } } - - - // Interface for calling Test functions from a public context struct TestPublicContextInterface { @@ -330,5 +326,4 @@ impl TestPublicContextInterface { } } - - + diff --git a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr index 43180fa693d..186b9220cfb 100644 --- a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr @@ -52,19 +52,15 @@ contract Test { // docs:end:empty-constructor #[aztec(private)] - fn get_public_key( - address: Field, - ) -> [Field; 2]{ + fn get_public_key(address: Field) -> [Field; 2] { let pub_key = get_public_key_oracle(address); - + [pub_key.x, pub_key.y] } // Get the portal contract address through an oracle call #[aztec(private)] - fn get_portal_contract_address( - aztec_address: Field - ) -> Field { + fn get_portal_contract_address(aztec_address: Field) -> Field { get_portal_address(aztec_address) } @@ -90,7 +86,7 @@ contract Test { a_number: u32, an_array: [Field; 2], a_struct: DummyNote, - a_deep_struct: DeepStruct, + a_deep_struct: DeepStruct ) -> distinct pub abi::PrivateCircuitPublicInputs { let mut args: BoundedVec = BoundedVec::new(0); args.push(a_field); @@ -105,7 +101,7 @@ contract Test { args.push(a_deep_struct.a_note.secret_hash); for note in a_deep_struct.many_notes { args.push(note.amount); - args.push(note.secret_hash); + args.push(note.secret_hash); } let args_hash = abi::hash_args(args.storage); let mut context = PrivateContext::new(inputs, args_hash); @@ -115,27 +111,20 @@ contract Test { // Purely exists for testing #[aztec(public)] - fn create_l2_to_l1_message_public( - amount: Field, - secret_hash: Field, - ) { + fn create_l2_to_l1_message_public(amount: Field, secret_hash: Field) { // Create a commitment to the amount let note = DummyNote::new(amount, secret_hash); - + // Public oracle call to emit new commitment. context.message_portal(note.get_commitment()); - } // Purely exists for testing #[aztec(public)] - fn create_nullifier_public( - amount: Field, - secret_hash: Field, - ) { + fn create_nullifier_public(amount: Field, secret_hash: Field) { // Create a commitment to the amount let note = DummyNote::new(amount, secret_hash); - + // Public oracle call to emit new commitment. context.push_new_nullifier(note.get_commitment(), EMPTY_NULLIFIED_COMMITMENT); } @@ -154,18 +143,14 @@ contract Test { // docs:start:is-time-equal #[aztec(public)] - fn is_time_equal( - time: Field, - ) -> Field { + fn is_time_equal(time: Field) -> Field { assert(context.timestamp() == time); time } // docs:end:is-time-equal #[aztec(public)] - fn emit_unencrypted( - value: Field - ) -> Field { + fn emit_unencrypted(value: Field) -> Field { // docs:start:emit_unencrypted emit_unencrypted_log(&mut context, value); // docs:end:emit_unencrypted @@ -173,25 +158,19 @@ contract Test { } #[aztec(public)] - fn consume_mint_public_message( - to: Field, - amount: Field, - canceller: Field, - msg_key: Field, - secret: Field, - ) { + fn consume_mint_public_message(to: Field, amount: Field, canceller: Field, msg_key: Field, secret: Field) { let content_hash = get_mint_public_content_hash(to, amount, canceller); // Consume message and emit nullifier context.consume_l1_to_l2_message(msg_key, content_hash, secret); } - #[aztec(private)] + #[aztec(private)] fn consume_mint_private_message( - secret_hash_for_redeeming_minted_notes: Field, + secret_hash_for_redeeming_minted_notes: Field, amount: Field, canceller: Field, msg_key: Field, - secret_for_L1_to_L2_message_consumption: Field, + secret_for_L1_to_L2_message_consumption: Field ) { // Consume L1 to L2 message and emit nullifier let content_hash = get_mint_private_content_hash(secret_hash_for_redeeming_minted_notes, amount, canceller); @@ -199,9 +178,7 @@ contract Test { } #[aztec(private)] - fn set_constant( - value: Field, - ) { + fn set_constant(value: Field) { let mut note = FieldNote::new(value); storage.example_constant.initialize(&mut note, Option::none(), false); } @@ -212,9 +189,7 @@ contract Test { } // Purely exists for testing - unconstrained fn get_random( - kindaSeed: Field - ) -> Field { + unconstrained fn get_random(kindaSeed: Field) -> Field { kindaSeed * rand() } diff --git a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/interfaces.nr b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/interfaces.nr index d21f75b2517..a05dc34874b 100644 --- a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/interfaces.nr +++ b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/interfaces.nr @@ -45,4 +45,4 @@ impl SlowMap { [index, new_value] ); } -} \ No newline at end of file +} diff --git a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/main.nr index d30ccb60501..8e51623b854 100644 --- a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/main.nr @@ -107,8 +107,9 @@ contract TokenBlacklist { storage.slow_update.initialize(&mut slow_note, Option::none(), false); let selector = compute_selector("_initialize((Field),(Field))"); - context.call_public_function(context.this_address(), selector, [admin.address, slow_updates_contract.address]); - + context.call_public_function(context.this_address(), + selector, + [admin.address, slow_updates_contract.address]); // We cannot do the following atm // let roles = UserFlags{is_admin: true, is_minter: false, is_blacklisted: false}.get_value() as Field; // SlowMap::at(slow_updates_contract).update_at_private(&mut context, admin.address, roles); @@ -118,17 +119,13 @@ contract TokenBlacklist { // Looking ugly because we cannot do constructor -> private calls #[aztec(private)] - fn init_slow_tree( - user: AztecAddress - ) { - let roles = UserFlags{is_admin: true, is_minter: false, is_blacklisted: false}.get_value() as Field; + fn init_slow_tree(user: AztecAddress) { + let roles = UserFlags { is_admin: true, is_minter: false, is_blacklisted: false }.get_value() as Field; let slow = SlowMap::at(AztecAddress::new(storage.slow_update.get_note().value)); slow.update_at_private(&mut context, user.address, roles); - context.call_public_function( - context.this_address(), + context.call_public_function(context.this_address(), compute_selector("_init_slow_tree((Field))"), - [context.msg_sender()], - ); + [context.msg_sender()]); } #[aztec(public)] @@ -139,10 +136,7 @@ contract TokenBlacklist { /////// #[aztec(private)] - fn update_roles( - user: AztecAddress, - roles: Field, - ) { + fn update_roles(user: AztecAddress, roles: Field) { let slow = SlowMap::at(AztecAddress::new(storage.slow_update.get_note().value)); let caller_roles = UserFlags::new(slow.read_at(&mut context, context.msg_sender()) as u120); assert(caller_roles.is_admin, "caller is not admin"); @@ -151,10 +145,7 @@ contract TokenBlacklist { } #[aztec(public)] - fn mint_public( - to: AztecAddress, - amount: Field, - ) -> Field { + fn mint_public(to: AztecAddress, amount: Field) -> Field { let slow = SlowMap::at(storage.public_slow_update.read()); let to_roles = UserFlags::new(slow.read_at_pub(context, to.address) as u120); assert(!to_roles.is_blacklisted, "Blacklisted: Recipient"); @@ -172,10 +163,7 @@ contract TokenBlacklist { } #[aztec(public)] - fn mint_private( - amount: Field, - secret_hash: Field, - ) -> Field { + fn mint_private(amount: Field, secret_hash: Field) -> Field { let slow = SlowMap::at(storage.public_slow_update.read()); let caller_roles = UserFlags::new(slow.read_at_pub(context, context.msg_sender()) as u120); assert(caller_roles.is_minter, "caller is not minter"); @@ -190,12 +178,7 @@ contract TokenBlacklist { } #[aztec(public)] - fn shield( - from: AztecAddress, - amount: Field, - secret_hash: Field, - nonce: Field, - ) -> Field { + fn shield(from: AztecAddress, amount: Field, secret_hash: Field, nonce: Field) -> Field { let slow = SlowMap::at(storage.public_slow_update.read()); let from_roles = UserFlags::new(slow.read_at_pub(context, from.address) as u120); assert(!from_roles.is_blacklisted, "Blacklisted: Sender"); @@ -219,13 +202,8 @@ contract TokenBlacklist { } #[aztec(public)] - fn transfer_public( - from: AztecAddress, - to: AztecAddress, - amount: Field, - nonce: Field, - ) -> Field { - let slow = SlowMap::at(storage.public_slow_update.read()); + fn transfer_public(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field { + let slow = SlowMap::at(storage.public_slow_update.read()); let from_roles = UserFlags::new(slow.read_at_pub(context, from.address) as u120); assert(!from_roles.is_blacklisted, "Blacklisted: Sender"); let to_roles = UserFlags::new(slow.read_at_pub(context, to.address) as u120); @@ -248,12 +226,8 @@ contract TokenBlacklist { } #[aztec(public)] - fn burn_public( - from: AztecAddress, - amount: Field, - nonce: Field, - ) -> Field { - let slow = SlowMap::at(storage.public_slow_update.read()); + fn burn_public(from: AztecAddress, amount: Field, nonce: Field) -> Field { + let slow = SlowMap::at(storage.public_slow_update.read()); let from_roles = UserFlags::new(slow.read_at_pub(context, from.address) as u120); assert(!from_roles.is_blacklisted, "Blacklisted: Sender"); @@ -274,12 +248,8 @@ contract TokenBlacklist { } #[aztec(private)] - fn redeem_shield( - to: AztecAddress, - amount: Field, - secret: Field, - ) -> Field { - let slow = SlowMap::at(AztecAddress::new(storage.slow_update.get_note().value)); + fn redeem_shield(to: AztecAddress, amount: Field, secret: Field) -> Field { + let slow = SlowMap::at(AztecAddress::new(storage.slow_update.get_note().value)); let to_roles = UserFlags::new(slow.read_at(&mut context, to.address) as u120); assert(!to_roles.is_blacklisted, "Blacklisted: Recipient"); @@ -300,12 +270,7 @@ contract TokenBlacklist { } #[aztec(private)] - fn unshield( - from: AztecAddress, - to: AztecAddress, - amount: Field, - nonce: Field, - ) -> Field { + fn unshield(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field { let slow = SlowMap::at(AztecAddress::new(storage.slow_update.get_note().value)); let from_roles = UserFlags::new(slow.read_at(&mut context, from.address) as u120); assert(!from_roles.is_blacklisted, "Blacklisted: Sender"); @@ -327,12 +292,7 @@ contract TokenBlacklist { } #[aztec(private)] - fn transfer( - from: AztecAddress, - to: AztecAddress, - amount: Field, - nonce: Field, - ) -> Field { + fn transfer(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field { let slow = SlowMap::at(AztecAddress::new(storage.slow_update.get_note().value)); let from_roles = UserFlags::new(slow.read_at(&mut context, from.address) as u120); assert(!from_roles.is_blacklisted, "Blacklisted: Sender"); @@ -353,11 +313,7 @@ contract TokenBlacklist { } #[aztec(private)] - fn burn( - from: AztecAddress, - amount: Field, - nonce: Field, - ) -> Field { + fn burn(from: AztecAddress, amount: Field, nonce: Field) -> Field { let slow = SlowMap::at(AztecAddress::new(storage.slow_update.get_note().value)); let from_roles = UserFlags::new(slow.read_at(&mut context, from.address) as u120); assert(!from_roles.is_blacklisted, "Blacklisted: Sender"); @@ -377,10 +333,7 @@ contract TokenBlacklist { } #[aztec(public)] - internal fn _initialize( - new_admin: AztecAddress, - slow_updates_contract: AztecAddress - ) { + internal fn _initialize(new_admin: AztecAddress, slow_updates_contract: AztecAddress) { assert(new_admin.address != 0, "invalid admin"); storage.admin.write(new_admin); storage.public_slow_update.write(slow_updates_contract); @@ -390,18 +343,13 @@ contract TokenBlacklist { /// Internal /// #[aztec(public)] - internal fn _increase_public_balance( - to: AztecAddress, - amount: Field, - ) { + internal fn _increase_public_balance(to: AztecAddress, amount: Field) { let new_balance = storage.public_balances.at(to.address).read().add(SafeU120::new(amount)); storage.public_balances.at(to.address).write(new_balance); } #[aztec(public)] - internal fn _reduce_total_supply( - amount: Field, - ) { + internal fn _reduce_total_supply(amount: Field) { // Only to be called from burn. let new_supply = storage.total_supply.read().sub(SafeU120::new(amount)); storage.total_supply.write(new_supply); @@ -413,15 +361,11 @@ contract TokenBlacklist { storage.total_supply.read().value } - unconstrained fn balance_of_private( - owner: AztecAddress, - ) -> u120 { + unconstrained fn balance_of_private(owner: AztecAddress) -> u120 { storage.balances.at(owner).balance_of().value } - unconstrained fn balance_of_public( - owner: AztecAddress, - ) -> u120 { + unconstrained fn balance_of_public(owner: AztecAddress) -> u120 { storage.public_balances.at(owner.address).read().value } @@ -439,6 +383,6 @@ contract TokenBlacklist { note_utils::compute_note_hash_and_nullifier(FieldNoteMethods, note_header, preimage) } else { note_utils::compute_note_hash_and_nullifier(TokenNoteMethods, note_header, preimage) - } + } } -} \ No newline at end of file +} diff --git a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types.nr b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types.nr index d5747a136a1..f5a3aeaa6fd 100644 --- a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types.nr +++ b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types.nr @@ -3,4 +3,4 @@ mod balance_set; mod balances_map; mod token_note; mod safe_u120_serialization; -mod roles; \ No newline at end of file +mod roles; diff --git a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/balance_set.nr b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/balance_set.nr index 37dbcd4ddbe..5c3da5897b6 100644 --- a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/balance_set.nr +++ b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/balance_set.nr @@ -123,4 +123,4 @@ pub fn filter_notes_min_sum(notes: [Option; MAX_READ_REQUESTS_PER_CAL } } selected -} \ No newline at end of file +} diff --git a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/roles.nr b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/roles.nr index 4412dff5592..793674e996d 100644 --- a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/roles.nr +++ b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/roles.nr @@ -39,4 +39,4 @@ impl UserFlags { value } -} \ No newline at end of file +} diff --git a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/safe_u120_serialization.nr b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/safe_u120_serialization.nr index f4f3ef84d23..876007184fe 100644 --- a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/safe_u120_serialization.nr +++ b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/safe_u120_serialization.nr @@ -5,7 +5,7 @@ global SAFE_U120_SERIALIZED_LEN: Field = 1; // This is safe when reading from storage IF only correct safeu120 was written to storage fn deserializeU120(fields: [Field; SAFE_U120_SERIALIZED_LEN]) -> SafeU120 { - SafeU120{value: fields[0] as u120} + SafeU120 { value: fields[0] as u120 } } fn serializeU120(value: SafeU120) -> [Field; SAFE_U120_SERIALIZED_LEN] { @@ -15,4 +15,4 @@ fn serializeU120(value: SafeU120) -> [Field; SAFE_U120_SERIALIZED_LEN] { global SafeU120SerializationMethods = TypeSerializationInterface { deserialize: deserializeU120, serialize: serializeU120, -}; \ No newline at end of file +}; diff --git a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/token_note.nr b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/token_note.nr index 41fd41c6082..978676cc22e 100644 --- a/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/token_note.nr +++ b/yarn-project/noir-contracts/src/contracts/token_blacklist_contract/src/types/token_note.nr @@ -137,4 +137,4 @@ global TokenNoteMethods = NoteInterface { get_header, set_header, broadcast, -}; \ No newline at end of file +}; diff --git a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr index decb8cd295c..4fb1553eefe 100644 --- a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr @@ -49,17 +49,10 @@ contract TokenBridge { } // docs:end:token_bridge_storage_and_constructor - // docs:start:claim_public // Consumes a L1->L2 message and calls the token contract to mint the appropriate amount publicly #[aztec(public)] - fn claim_public( - to: AztecAddress, - amount: Field, - canceller: EthereumAddress, - msg_key: Field, - secret: Field, - ) -> Field { + fn claim_public(to: AztecAddress, amount: Field, canceller: EthereumAddress, msg_key: Field, secret: Field) -> Field { let content_hash = get_mint_public_content_hash(to.address, amount, canceller.address); // Consume message and emit nullifier context.consume_l1_to_l2_message(msg_key, content_hash, secret); @@ -79,7 +72,7 @@ contract TokenBridge { recipient: EthereumAddress, // ethereum address to withdraw to amount: Field, callerOnL1: EthereumAddress, // ethereum address that can call this function on the L1 portal (0x0 if anyone can call) - nonce: Field, // nonce used in the approval message by `msg.sender` to let bridge burn their tokens on L2 + nonce: Field // nonce used in the approval message by `msg.sender` to let bridge burn their tokens on L2 ) -> Field { // Send an L2 to L1 message let content = get_withdraw_content_hash(recipient.address, amount, callerOnL1.address); @@ -100,21 +93,21 @@ contract TokenBridge { amount: Field, canceller: EthereumAddress, msg_key: Field, // L1 to L2 message key as derived from the inbox contract - secret_for_L1_to_L2_message_consumption: Field, // secret used to consume the L1 to L2 message + secret_for_L1_to_L2_message_consumption: Field // secret used to consume the L1 to L2 message ) -> Field { // Consume L1 to L2 message and emit nullifier - let content_hash = get_mint_private_content_hash(secret_hash_for_redeeming_minted_notes, amount, canceller.address); + let content_hash = get_mint_private_content_hash(secret_hash_for_redeeming_minted_notes, + amount, + canceller.address); context.consume_l1_to_l2_message(msg_key, content_hash, secret_for_L1_to_L2_message_consumption); // Mint tokens on L2 // `mint_private` on token is public. So we call an internal public function // which then calls the public method on the token contract. // Since the secret_hash is passed, no secret is leaked. - context.call_public_function( - context.this_address(), + context.call_public_function(context.this_address(), compute_selector("_call_mint_on_token(Field,Field)"), - [amount, secret_hash_for_redeeming_minted_notes], - ); + [amount, secret_hash_for_redeeming_minted_notes]); 1 } @@ -129,14 +122,16 @@ contract TokenBridge { recipient: EthereumAddress, // ethereum address to withdraw to amount: Field, callerOnL1: EthereumAddress, // ethereum address that can call this function on the L1 portal (0x0 if anyone can call) - nonce: Field, // nonce used in the approval message by `msg.sender` to let bridge burn their tokens on L2 + nonce: Field // nonce used in the approval message by `msg.sender` to let bridge burn their tokens on L2 ) -> Field { // Send an L2 to L1 message let content = get_withdraw_content_hash(recipient.address, amount, callerOnL1.address); context.message_portal(content); // Assert that user provided token address is same as seen in storage. - context.call_public_function(context.this_address(), compute_selector("_assert_token_is_same(Field)"), [token.address]); + context.call_public_function(context.this_address(), + compute_selector("_assert_token_is_same(Field)"), + [token.address]); // Burn tokens Token::at(token.address).burn(&mut context, context.msg_sender(), amount, nonce); @@ -168,7 +163,7 @@ contract TokenBridge { // Also, note that user hashes their secret in private and only sends the hash in public // meaning only user can `redeem_shield` at a later time with their secret. #[aztec(public)] - internal fn _call_mint_on_token(amount: Field, secret_hash: Field){ + internal fn _call_mint_on_token(amount: Field, secret_hash: Field) { Token::at(storage.token.read()).mint_private(context, amount, secret_hash); } // docs:end:call_mint_on_token diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr index b6db0a2de8c..6eb7c6cd906 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr @@ -130,9 +130,7 @@ contract Token { // docs:start:set_admin #[aztec(public)] - fn set_admin( - new_admin: AztecAddress, - ) { + fn set_admin(new_admin: AztecAddress) { assert(storage.admin.read().eq(AztecAddress::new(context.msg_sender())), "caller is not admin"); // docs:start:write_admin storage.admin.write(new_admin); @@ -142,10 +140,7 @@ contract Token { // docs:start:set_minter #[aztec(public)] - fn set_minter( - minter: AztecAddress, - approve: bool, - ) { + fn set_minter(minter: AztecAddress, approve: bool) { // docs:start:read_admin assert(storage.admin.read().eq(AztecAddress::new(context.msg_sender())), "caller is not admin"); // docs:end:read_admin @@ -157,10 +152,7 @@ contract Token { // docs:start:mint_public #[aztec(public)] - fn mint_public( - to: AztecAddress, - amount: Field, - ) -> Field { + fn mint_public(to: AztecAddress, amount: Field) -> Field { // docs:start:read_minter assert(storage.minters.at(context.msg_sender()).read(), "caller is not minter"); // docs:end:read_minter @@ -176,10 +168,7 @@ contract Token { // docs:start:mint_private #[aztec(public)] - fn mint_private( - amount: Field, - secret_hash: Field, - ) -> Field { + fn mint_private(amount: Field, secret_hash: Field) -> Field { assert(storage.minters.at(context.msg_sender()).read(), "caller is not minter"); let pending_shields = storage.pending_shields; let mut note = TransparentNote::new(amount, secret_hash); @@ -195,12 +184,7 @@ contract Token { // docs:start:shield #[aztec(public)] - fn shield( - from: AztecAddress, - amount: Field, - secret_hash: Field, - nonce: Field, - ) -> Field { + fn shield(from: AztecAddress, amount: Field, secret_hash: Field, nonce: Field) -> Field { if (from.address != context.msg_sender()) { // The redeem is only spendable once, so we need to ensure that you cannot insert multiple shields from the same message. assert_current_call_valid_authwit_public(&mut context, from); @@ -222,12 +206,7 @@ contract Token { // docs:start:transfer_public #[aztec(public)] - fn transfer_public( - from: AztecAddress, - to: AztecAddress, - amount: Field, - nonce: Field, - ) -> Field { + fn transfer_public(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field { if (from.address != context.msg_sender()) { assert_current_call_valid_authwit_public(&mut context, from); } else { @@ -247,11 +226,7 @@ contract Token { // docs:start:burn_public #[aztec(public)] - fn burn_public( - from: AztecAddress, - amount: Field, - nonce: Field, - ) -> Field { + fn burn_public(from: AztecAddress, amount: Field, nonce: Field) -> Field { // docs:start:assert_current_call_valid_authwit_public if (from.address != context.msg_sender()) { assert_current_call_valid_authwit_public(&mut context, from); @@ -273,11 +248,7 @@ contract Token { // docs:start:redeem_shield #[aztec(private)] - fn redeem_shield( - to: AztecAddress, - amount: Field, - secret: Field, - ) -> Field { + fn redeem_shield(to: AztecAddress, amount: Field, secret: Field) -> Field { let pending_shields = storage.pending_shields; let secret_hash = compute_secret_hash(secret); // Get 1 note (set_limit(1)) which has amount stored in field with index 0 (select(0, amount)) and secret_hash @@ -297,12 +268,7 @@ contract Token { // docs:start:unshield #[aztec(private)] - fn unshield( - from: AztecAddress, - to: AztecAddress, - amount: Field, - nonce: Field, - ) -> Field { + fn unshield(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field { if (from.address != context.msg_sender()) { assert_current_call_valid_authwit(&mut context, from); } else { @@ -320,12 +286,7 @@ contract Token { // docs:start:transfer #[aztec(private)] - fn transfer( - from: AztecAddress, - to: AztecAddress, - amount: Field, - nonce: Field, - ) -> Field { + fn transfer(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) -> Field { // docs:start:assert_current_call_valid_authwit if (from.address != context.msg_sender()) { assert_current_call_valid_authwit(&mut context, from); @@ -346,11 +307,7 @@ contract Token { // docs:start:burn #[aztec(private)] - fn burn( - from: AztecAddress, - amount: Field, - nonce: Field, - ) -> Field { + fn burn(from: AztecAddress, amount: Field, nonce: Field) -> Field { if (from.address != context.msg_sender()) { assert_current_call_valid_authwit(&mut context, from); } else { @@ -368,9 +325,7 @@ contract Token { // docs:start:initialize #[aztec(public)] - internal fn _initialize( - new_admin: AztecAddress, - ) { + internal fn _initialize(new_admin: AztecAddress) { assert(new_admin.address != 0, "invalid admin"); storage.admin.write(new_admin); storage.minters.at(new_admin.address).write(true); @@ -381,10 +336,7 @@ contract Token { // docs:start:increase_public_balance #[aztec(public)] - internal fn _increase_public_balance( - to: AztecAddress, - amount: Field, - ) { + internal fn _increase_public_balance(to: AztecAddress, amount: Field) { let new_balance = storage.public_balances.at(to.address).read().add(SafeU120::new(amount)); storage.public_balances.at(to.address).write(new_balance); } @@ -392,9 +344,7 @@ contract Token { // docs:start:reduce_total_supply #[aztec(public)] - internal fn _reduce_total_supply( - amount: Field, - ) { + internal fn _reduce_total_supply(amount: Field) { // Only to be called from burn. let new_supply = storage.total_supply.read().sub(SafeU120::new(amount)); storage.total_supply.write(new_supply); @@ -410,9 +360,7 @@ contract Token { // docs:end:admin // docs:start:is_minter - unconstrained fn is_minter( - minter: AztecAddress, - ) -> bool { + unconstrained fn is_minter(minter: AztecAddress) -> bool { storage.minters.at(minter.address).read() } // docs:end:is_minter @@ -424,17 +372,13 @@ contract Token { // docs:end:total_supply // docs:start:balance_of_private - unconstrained fn balance_of_private( - owner: AztecAddress, - ) -> u120 { + unconstrained fn balance_of_private(owner: AztecAddress) -> u120 { storage.balances.at(owner).balance_of().value } // docs:end:balance_of_private // docs:start:balance_of_public - unconstrained fn balance_of_public( - owner: AztecAddress, - ) -> u120 { + unconstrained fn balance_of_public(owner: AztecAddress) -> u120 { storage.public_balances.at(owner.address).read().value } // docs:end:balance_of_public diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/types.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/types.nr index 1f4883a54c6..e29a8151e9f 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/types.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/types.nr @@ -2,4 +2,4 @@ mod transparent_note; mod balance_set; mod balances_map; mod token_note; -mod safe_u120_serialization; \ No newline at end of file +mod safe_u120_serialization; 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 37dbcd4ddbe..5c3da5897b6 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 @@ -123,4 +123,4 @@ pub fn filter_notes_min_sum(notes: [Option; MAX_READ_REQUESTS_PER_CAL } } selected -} \ No newline at end of file +} diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/safe_u120_serialization.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/safe_u120_serialization.nr index f4f3ef84d23..876007184fe 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/safe_u120_serialization.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/safe_u120_serialization.nr @@ -5,7 +5,7 @@ global SAFE_U120_SERIALIZED_LEN: Field = 1; // This is safe when reading from storage IF only correct safeu120 was written to storage fn deserializeU120(fields: [Field; SAFE_U120_SERIALIZED_LEN]) -> SafeU120 { - SafeU120{value: fields[0] as u120} + SafeU120 { value: fields[0] as u120 } } fn serializeU120(value: SafeU120) -> [Field; SAFE_U120_SERIALIZED_LEN] { @@ -15,4 +15,4 @@ fn serializeU120(value: SafeU120) -> [Field; SAFE_U120_SERIALIZED_LEN] { global SafeU120SerializationMethods = TypeSerializationInterface { deserialize: deserializeU120, serialize: serializeU120, -}; \ No newline at end of file +}; 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 442b600f1ce..cc366cc2277 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 @@ -137,4 +137,4 @@ global TokenNoteMethods = NoteInterface { get_header, set_header, broadcast, -}; \ No newline at end of file +}; diff --git a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr index 75ce7e78ea6..1e332adcd70 100644 --- a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr @@ -21,7 +21,7 @@ contract Uniswap { }; use dep::authwit::auth::{IS_VALID_SELECTOR, assert_current_call_valid_authwit_public, compute_authwit_message_hash}; - + use crate::interfaces::{Token, TokenBridge}; use crate::util::{compute_swap_private_content_hash, compute_swap_public_content_hash}; @@ -47,16 +47,16 @@ contract Uniswap { } } } - + #[aztec(private)] fn constructor() {} -// docs:end:uniswap_setup + // docs:end:uniswap_setup -// docs:start:swap_public + // docs:start:swap_public #[aztec(public)] fn swap_public( sender: AztecAddress, - input_asset_bridge: AztecAddress, + input_asset_bridge: AztecAddress, input_amount: Field, output_asset_bridge: AztecAddress, // params for using the transfer approval @@ -71,9 +71,8 @@ contract Uniswap { canceller_for_L1_to_L2_message: EthereumAddress, caller_on_L1: EthereumAddress, // nonce for someone to call swap on sender's behalf - nonce_for_swap_approval: Field, + nonce_for_swap_approval: Field ) -> Field { - if (sender.address != context.msg_sender()) { assert_current_call_valid_authwit_public(&mut context, sender); } @@ -81,20 +80,16 @@ contract Uniswap { let input_asset = TokenBridge::at(input_asset_bridge.address).token(context); // Transfer funds to this contract - Token::at(input_asset.address).transfer_public( - context, + Token::at(input_asset.address).transfer_public(context, sender.address, context.this_address(), input_amount, - nonce_for_transfer_approval, - ); + nonce_for_transfer_approval); // Approve bridge to burn this contract's funds and exit to L1 Uniswap Portal - let _void = context.call_public_function( - context.this_address(), - compute_selector("_approve_bridge_and_exit_input_asset_to_L1((Field),(Field),Field)"), - [input_asset.address, input_asset_bridge.address, input_amount], - ); + let _void = context.call_public_function(context.this_address(), + compute_selector("_approve_bridge_and_exit_input_asset_to_L1((Field),(Field),Field)"), + [input_asset.address, input_asset_bridge.address, input_amount]); // Create swap message and send to Outbox for Uniswap Portal // this ensures the integrity of what the user originally intends to do on L1. @@ -104,8 +99,7 @@ contract Uniswap { assert(input_asset_bridge_portal_address != 0, "L1 portal address of input_asset's bridge is 0"); assert(output_asset_bridge_portal_address != 0, "L1 portal address of output_asset's bridge is 0"); - let content_hash = compute_swap_public_content_hash( - input_asset_bridge_portal_address, + let content_hash = compute_swap_public_content_hash(input_asset_bridge_portal_address, input_amount, uniswap_fee_tier, output_asset_bridge_portal_address, @@ -114,53 +108,49 @@ contract Uniswap { secret_hash_for_L1_to_l2_message, deadline_for_L1_to_l2_message, canceller_for_L1_to_L2_message.address, - caller_on_L1.address, - ); + caller_on_L1.address); context.message_portal(content_hash); 1 } -// docs:end:swap_public + // docs:end:swap_public -// docs:start:swap_private + // docs:start:swap_private #[aztec(private)] fn swap_private( input_asset: AztecAddress, // since private, we pass here and later assert that this is as expected by input_bridge - input_asset_bridge: AztecAddress, + input_asset_bridge: AztecAddress, input_amount: Field, output_asset_bridge: AztecAddress, // params for using the unshield approval nonce_for_unshield_approval: Field, // params for the swap - uniswap_fee_tier: Field, // which uniswap tier to use (eg 3000 for 0.3% fee) + uniswap_fee_tier: Field,// which uniswap tier to use (eg 3000 for 0.3% fee) minimum_output_amount: Field, // minimum output amount to receive (slippage protection for the swap) // params for the depositing output_asset back to Aztec - secret_hash_for_redeeming_minted_notes: Field, // secret hash used to redeem minted notes at a later time. This enables anyone to call this function and mint tokens to a user on their behalf + secret_hash_for_redeeming_minted_notes: Field,// secret hash used to redeem minted notes at a later time. This enables anyone to call this function and mint tokens to a user on their behalf secret_hash_for_L1_to_l2_message: Field, // for when l1 uniswap portal inserts the message to consume output assets on L2 deadline_for_L1_to_l2_message: Field, // for when l1 uniswap portal inserts the message to consume output assets on L2 canceller_for_L1_to_L2_message: EthereumAddress, // L1 address of who can cancel the message to consume assets on L2. - caller_on_L1: EthereumAddress, // ethereum address that can call this function on the L1 portal (0x0 if anyone can call) + caller_on_L1: EthereumAddress // ethereum address that can call this function on the L1 portal (0x0 if anyone can call) ) -> Field { - // Assert that user provided token address is same as expected by token bridge. // we can't directly use `input_asset_bridge.token` because that is a public method and public can't return data to private - context.call_public_function(context.this_address(), compute_selector("_assert_token_is_same((Field),(Field))"), [input_asset.address, input_asset_bridge.address]); + context.call_public_function(context.this_address(), + compute_selector("_assert_token_is_same((Field),(Field))"), + [input_asset.address, input_asset_bridge.address]); // Transfer funds to this contract - Token::at(input_asset.address).unshield( - &mut context, + Token::at(input_asset.address).unshield(&mut context, context.msg_sender(), context.this_address(), input_amount, - nonce_for_unshield_approval, - ); + nonce_for_unshield_approval); // Approve bridge to burn this contract's funds and exit to L1 Uniswap Portal - context.call_public_function( - context.this_address(), - compute_selector("_approve_bridge_and_exit_input_asset_to_L1((Field),(Field),Field)"), - [input_asset.address, input_asset_bridge.address, input_amount], - ); + context.call_public_function(context.this_address(), + compute_selector("_approve_bridge_and_exit_input_asset_to_L1((Field),(Field),Field)"), + [input_asset.address, input_asset_bridge.address, input_amount]); // Create swap message and send to Outbox for Uniswap Portal // this ensures the integrity of what the user originally intends to do on L1. @@ -170,8 +160,7 @@ contract Uniswap { assert(input_asset_bridge_portal_address != 0, "L1 portal address of input_asset's bridge is 0"); assert(output_asset_bridge_portal_address != 0, "L1 portal address of output_asset's bridge is 0"); - let content_hash = compute_swap_private_content_hash( - input_asset_bridge_portal_address, + let content_hash = compute_swap_private_content_hash(input_asset_bridge_portal_address, input_amount, uniswap_fee_tier, output_asset_bridge_portal_address, @@ -180,8 +169,7 @@ contract Uniswap { secret_hash_for_L1_to_l2_message, deadline_for_L1_to_l2_message, canceller_for_L1_to_L2_message.address, - caller_on_L1.address, - ); + caller_on_L1.address); context.message_portal(content_hash); 1 @@ -195,11 +183,7 @@ contract Uniswap { #[aztec(public)] fn is_valid_public(message_hash: Field) -> Field { let value = storage.approved_action.at(message_hash).read(); - if (value){ - IS_VALID_SELECTOR - } else { - 0 - } + if (value) { IS_VALID_SELECTOR } else { 0 } } // docs:end:authwit_uniswap_get @@ -210,28 +194,25 @@ contract Uniswap { // Note that private can't read public return values so created an internal public that handles everything // this method is used for both private and public swaps. #[aztec(public)] - internal fn _approve_bridge_and_exit_input_asset_to_L1( - token: AztecAddress, - token_bridge: AztecAddress, - amount: Field, - ) { + internal fn _approve_bridge_and_exit_input_asset_to_L1(token: AztecAddress, token_bridge: AztecAddress, amount: Field) { // approve bridge to burn this contract's funds (required when exiting on L1, as it burns funds on L2): let nonce_for_burn_approval = storage.nonce_for_burn_approval.read(); let selector = compute_selector("burn_public((Field),Field,Field)"); - let message_hash = compute_authwit_message_hash(token_bridge, token, selector, [context.this_address(), amount, nonce_for_burn_approval]); + let message_hash = compute_authwit_message_hash(token_bridge, + token, + selector, + [context.this_address(), amount, nonce_for_burn_approval]); storage.approved_action.at(message_hash).write(true); // increment nonce_for_burn_approval so it won't be used again storage.nonce_for_burn_approval.write(nonce_for_burn_approval + 1); // Exit to L1 Uniswap Portal ! - TokenBridge::at(token_bridge.address).exit_to_l1_public( - context, + TokenBridge::at(token_bridge.address).exit_to_l1_public(context, context.this_portal_address(), amount, context.this_portal_address(), - nonce_for_burn_approval, - ); + nonce_for_burn_approval); } // docs:end:authwit_uniswap_set @@ -253,4 +234,4 @@ contract Uniswap { unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, serialized_note: [Field; 0]) -> [Field; 4] { [0, 0, 0, 0] } -} \ No newline at end of file +} 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 cc39741944b..163f8056a10 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 @@ -13,7 +13,7 @@ pub fn compute_swap_public_content_hash( secret_hash_for_L1_to_l2_message: Field, deadline_for_L1_to_l2_message: Field, canceller_for_L1_to_L2_message: Field, - caller_on_L1: Field, + caller_on_L1: Field ) -> Field { let mut hash_bytes: [u8; 324] = [0; 324]; // 10 fields of 32 bytes each + 4 bytes fn selector @@ -65,7 +65,7 @@ pub fn compute_swap_private_content_hash( secret_hash_for_L1_to_l2_message: Field, deadline_for_L1_to_l2_message: Field, canceller_for_L1_to_L2_message: Field, - caller_on_L1: Field, + caller_on_L1: Field ) -> Field { let mut hash_bytes: [u8; 324] = [0; 324]; // 10 fields of 32 bytes each + 4 bytes fn selector