From fb09d4ebcb7fe2066e40776dec3444f5d5f69f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bene=C5=A1?= Date: Wed, 13 Nov 2024 13:04:39 -0300 Subject: [PATCH] refactor: token naming cleanup (#9904) --- .../developer_guides/getting_started.md | 6 +- .../developer_guides/js_apps/authwit.md | 6 +- .../how_to_compile_contract.md | 4 +- .../testing_contracts/testing.md | 12 +- .../writing_contracts/authwit.md | 8 +- .../common_patterns/index.md | 4 +- .../portals/communicate_with_portal.md | 2 +- docs/docs/migration_notes.md | 15 ++ .../sandbox_reference/cli_wallet_reference.md | 6 +- .../codealong/aztecjs-getting-started.md | 2 +- .../codealong/cli_wallet/faceid_wallet.md | 4 +- .../token_bridge/1_depositing_to_aztec.md | 4 +- .../token_bridge/2_minting_on_aztec.md | 12 +- .../contract_tutorials/token_contract.md | 26 +-- .../tutorials/examples/uniswap/l2_contract.md | 2 +- .../fee_portal/depositToAztecPublic.t.sol | 2 + l1-contracts/test/portals/TokenPortal.sol | 8 +- l1-contracts/test/portals/TokenPortal.t.sol | 12 +- l1-contracts/test/portals/UniswapPortal.sol | 4 + l1-contracts/test/portals/UniswapPortal.t.sol | 6 + .../app_subscription_contract/src/main.nr | 2 +- .../contracts/claim_contract/src/main.nr | 2 +- .../crowdfunding_contract/src/main.nr | 2 +- .../contracts/fee_juice_contract/src/lib.nr | 14 +- .../contracts/fpc_contract/src/main.nr | 4 +- .../contracts/lending_contract/src/main.nr | 8 +- .../contracts/test_contract/src/main.nr | 10 +- .../token_bridge_contract/src/main.nr | 11 +- .../contracts/token_contract/src/main.nr | 28 +-- .../contracts/token_contract/src/test.nr | 16 +- .../contracts/token_contract/src/test/burn.nr | 188 ------------------ .../token_contract/src/test/burn_private.nr | 107 ++++++++++ .../token_contract/src/test/burn_public.nr | 89 +++++++++ .../test/{minting.nr => mint_to_public.nr} | 26 +-- .../token_contract/src/test/refunds.nr | 4 +- .../token_contract/src/test/transfer.nr | 64 ++++++ ...sfer_private.nr => transfer_in_private.nr} | 81 +------- ...ansfer_public.nr => transfer_in_public.nr} | 54 ++--- .../src/test/transfer_to_private.nr | 10 +- .../src/test/transfer_to_public.nr | 14 +- .../token_contract/src/test/utils.nr | 10 +- .../token_portal_content_hash_lib/src/lib.nr | 56 +++--- .../contracts/uniswap_contract/src/main.nr | 2 +- .../contracts/uniswap_contract/src/util.nr | 36 +++- .../src/fee/public_fee_payment_method.ts | 4 +- yarn-project/bot/src/bot.ts | 2 +- yarn-project/bot/src/factory.ts | 2 +- yarn-project/bot/src/utils.ts | 2 +- yarn-project/cli-wallet/test/flows/basic.sh | 2 +- .../cli-wallet/test/flows/no_alias.sh | 2 +- .../test/flows/private_authwit_transfer.sh | 6 +- .../test/flows/public_authwit_transfer.sh | 6 +- .../test/flows/shield_and_transfer.sh | 2 +- .../create_main_and_mint_public.sh | 2 +- .../src/benchmarks/bench_prover.test.ts | 4 +- .../src/benchmarks/bench_tx_size_fees.test.ts | 2 +- .../src/composed/docs_examples.test.ts | 2 +- .../end-to-end/src/e2e_block_building.test.ts | 2 +- .../token_bridge_failure_cases.test.ts | 2 +- .../token_bridge_private.test.ts | 2 +- .../src/e2e_crowdfunding_and_claim.test.ts | 8 +- .../src/e2e_fees/account_init.test.ts | 8 +- .../src/e2e_fees/dapp_subscription.test.ts | 2 +- .../end-to-end/src/e2e_fees/failures.test.ts | 24 +-- .../src/e2e_fees/fee_juice_payments.test.ts | 6 +- .../end-to-end/src/e2e_fees/fees_test.ts | 2 +- .../src/e2e_fees/gas_estimation.test.ts | 2 +- .../src/e2e_lending_contract.test.ts | 8 +- .../src/e2e_prover/e2e_prover_test.ts | 2 +- .../end-to-end/src/e2e_prover/full.test.ts | 4 +- .../end-to-end/src/e2e_synching.test.ts | 4 +- .../src/e2e_token_contract/burn.test.ts | 18 +- .../src/e2e_token_contract/minting.test.ts | 10 +- .../e2e_token_contract/token_contract_test.ts | 2 +- .../src/e2e_token_contract/transfer.test.ts | 85 ++++++++ ...te.test.ts => transfer_in_private.test.ts} | 79 +------- ...lic.test.ts => transfer_in_public.test.ts} | 30 +-- .../src/guides/dapp_testing.test.ts | 6 +- .../writing_an_account_contract.test.ts | 2 +- .../end-to-end/src/sample-dapp/index.mjs | 2 +- .../src/shared/cross_chain_test_harness.ts | 4 +- .../end-to-end/src/shared/uniswap_l1_l2.ts | 8 +- .../end-to-end/src/spartan/4epochs.test.ts | 2 +- .../src/spartan/setup_test_wallets.ts | 4 +- .../end-to-end/src/spartan/transfer.test.ts | 2 +- .../src/client/private_execution.test.ts | 4 +- 86 files changed, 730 insertions(+), 625 deletions(-) delete mode 100644 noir-projects/noir-contracts/contracts/token_contract/src/test/burn.nr create mode 100644 noir-projects/noir-contracts/contracts/token_contract/src/test/burn_private.nr create mode 100644 noir-projects/noir-contracts/contracts/token_contract/src/test/burn_public.nr rename noir-projects/noir-contracts/contracts/token_contract/src/test/{minting.nr => mint_to_public.nr} (62%) create mode 100644 noir-projects/noir-contracts/contracts/token_contract/src/test/transfer.nr rename noir-projects/noir-contracts/contracts/token_contract/src/test/{transfer_private.nr => transfer_in_private.nr} (51%) rename noir-projects/noir-contracts/contracts/token_contract/src/test/{transfer_public.nr => transfer_in_public.nr} (70%) create mode 100644 yarn-project/end-to-end/src/e2e_token_contract/transfer.test.ts rename yarn-project/end-to-end/src/e2e_token_contract/{transfer_private.test.ts => transfer_in_private.test.ts} (71%) rename yarn-project/end-to-end/src/e2e_token_contract/{transfer_public.test.ts => transfer_in_public.test.ts} (85%) diff --git a/docs/docs/guides/developer_guides/getting_started.md b/docs/docs/guides/developer_guides/getting_started.md index f665739c8d9..ce015ba29db 100644 --- a/docs/docs/guides/developer_guides/getting_started.md +++ b/docs/docs/guides/developer_guides/getting_started.md @@ -139,12 +139,12 @@ In the next step, let's mint some tokens! Call the public mint function like this: ```bash -aztec-wallet send mint_public --from accounts:my-wallet --contract-address contracts:testtoken --args accounts:my-wallet 100 +aztec-wallet send mint_to_public --from accounts:my-wallet --contract-address contracts:testtoken --args accounts:my-wallet 100 ``` This takes -- the function name as the argument, which is `mint_public` +- the function name as the argument, which is `mint_to_public` - the `from` account (caller) which is `accounts:my-wallet` - the contract address, which is aliased as `contracts:testtoken` (or simply `testtoken`) - the args that the function takes, which is the account to mint the tokens into (`my-wallet`), and `amount` (`100`). @@ -165,7 +165,7 @@ Transaction has been mined Status: success Block number: 17 Block hash: 1e27d200600bc45ab94d467c230490808d1e7d64f5ee6cee5e94a08ee9580809 -Transaction hash stored in database with aliases last & mint_public-9044 +Transaction hash stored in database with aliases last & mint_to_public-9044 ``` You can double-check by calling the function that checks your public account balance: diff --git a/docs/docs/guides/developer_guides/js_apps/authwit.md b/docs/docs/guides/developer_guides/js_apps/authwit.md index d4db5d8c5cd..92dd49dc677 100644 --- a/docs/docs/guides/developer_guides/js_apps/authwit.md +++ b/docs/docs/guides/developer_guides/js_apps/authwit.md @@ -68,9 +68,9 @@ Then create the message hash by hashing the inner hash with the authwit receiver ## Create the authwit -There are slightly different interfaces depending on whether your contract is checking the authwit in private or public. +There are slightly different interfaces depending on whether your contract is checking the authwit in private or public. -Public authwits are stored in the account contract and batched with the authwit action call, so a user must send a transaction to update their account contract, authorizing an action before the authorized contract's public call will succeed. +Public authwits are stored in the account contract and batched with the authwit action call, so a user must send a transaction to update their account contract, authorizing an action before the authorized contract's public call will succeed. Private execution uses oracles and are executed locally by the PXE, so the authwit needs to be created by the authwit giver and then added to the authwit receiver's PXE. @@ -107,7 +107,7 @@ Set a public authwit like this: Remember it is a transaction and calls a method in the account contract. In this example, - `wallets[0]` is the authwit giver -- `wallets[1]` is the authwit reciever and caller of the function +- `wallets[1]` is the authwit receiver and caller of the function - `action` was [defined previously](#define-the-action) - `true` sets the `authorized` boolean (`false` would revoke this authwit) diff --git a/docs/docs/guides/developer_guides/smart_contracts/how_to_compile_contract.md b/docs/docs/guides/developer_guides/smart_contracts/how_to_compile_contract.md index c356ddb1544..902230fa304 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/how_to_compile_contract.md +++ b/docs/docs/guides/developer_guides/smart_contracts/how_to_compile_contract.md @@ -199,8 +199,8 @@ export class TokenContract extends ContractBase { /** Type-safe wrappers for the public methods exposed by the contract. */ public override methods!: { - /** transfer_public(from: struct, to: struct, amount: field, nonce: field) */ - transfer_public: (( + /** transfer_in_public(from: struct, to: struct, amount: field, nonce: field) */ + transfer_in_public: (( from: AztecAddressLike, to: AztecAddressLike, amount: FieldLike, diff --git a/docs/docs/guides/developer_guides/smart_contracts/testing_contracts/testing.md b/docs/docs/guides/developer_guides/smart_contracts/testing_contracts/testing.md index 2449195013b..86d470de664 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/testing_contracts/testing.md +++ b/docs/docs/guides/developer_guides/smart_contracts/testing_contracts/testing.md @@ -118,13 +118,13 @@ Our test environment is capable of utilizing the autogenerated contract interfac For example, to call the private `transfer` function on the token contract: -#include_code txe_test_transfer_private /noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_private.nr rust +#include_code txe_test_transfer_private /noir-projects/noir-contracts/contracts/token_contract/src/test/transfer.nr rust #### Public -To call the public `transfer_public` function: +To call the public `transfer_in_public` function: -#include_code call_public /noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_public.nr rust +#include_code call_public /noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_in_public.nr rust #### Unconstrained @@ -178,11 +178,11 @@ Reading notes: You can add [authwits](../writing_contracts/authwit.md) to the TXE. Here is an example of testing a private token transfer using authwits: -#include_code private_authwit /noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_private.nr rust +#include_code private_authwit /noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_in_private.nr rust #### Public -#include_code public_authwit /noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_public.nr rust +#include_code public_authwit /noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_in_public.nr rust ### Storing notes in cache @@ -206,7 +206,7 @@ You can test functions that you expect to fail generically, with the `#[test(sho For example: -#include_code fail_with_message /noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_private.nr rust +#include_code fail_with_message /noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_in_private.nr rust You can also use the `assert_public_call_fails` or `assert_private_call_fails` methods on the `TestEnvironment` to check that a call fails. diff --git a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/authwit.md b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/authwit.md index fb288b5ef3d..ac40dbc36c0 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/authwit.md +++ b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/authwit.md @@ -141,7 +141,7 @@ Then you will be able to import it into your contracts as follows. Based on the diagram earlier on this page let's take a look at how we can implement the `transfer` function such that it checks if the tokens are to be transferred `from` the caller or needs to be authenticated with an authentication witness. -#include_code transfer_from /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust +#include_code transfer_in_private /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust The first thing we see in the snippet above, is that if `from` is not the call we are calling the `assert_current_call_valid_authwit` function from [earlier](#private-functions). If the call is not throwing, we are all good and can continue with the transfer. @@ -151,7 +151,7 @@ In the snippet we are constraining the `else` case such that only `nonce = 0` is Cool, so we have a function that checks if the current call is authenticated, but how do we actually authenticate it? Well, assuming that we use a wallet that is following the spec, we import `computeAuthWitMessageHash` from `aztec.js` to help us compute the hash, and then we simply `addAuthWitness` to the wallet. Behind the scenes this will make the witness available to the oracle. -#include_code authwit_transfer_example /yarn-project/end-to-end/src/e2e_token_contract/transfer_private.test.ts typescript +#include_code authwit_transfer_example /yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts typescript Learn more about authwits in Aztec.js by [following this guide](../../js_apps/authwit.md). @@ -161,7 +161,7 @@ With private functions covered, how can we use this in a public function? Well, #### Checking if the current call is authenticated -#include_code transfer_public /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust +#include_code transfer_in_public /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust #### Authenticating an action in TypeScript @@ -169,7 +169,7 @@ Authenticating an action in the public domain is slightly different from the pri In the snippet below, this is done as a separate contract call, but can also be done as part of a batch as mentioned in the [Accounts concepts](../../../../aztec/concepts/accounts/authwit.md#what-about-public). -#include_code authwit_public_transfer_example /yarn-project/end-to-end/src/e2e_token_contract/transfer_public.test.ts typescript +#include_code authwit_public_transfer_example /yarn-project/end-to-end/src/e2e_token_contract/transfer_in_public.test.ts typescript #### Updating approval state in Noir diff --git a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/common_patterns/index.md b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/common_patterns/index.md index 848fffa0e1f..0e601ef307b 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/common_patterns/index.md +++ b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/common_patterns/index.md @@ -21,7 +21,7 @@ We call this the "authentication witness" pattern or authwit for short. Here you approve a contract to burn funds on your behalf. - Approve in public domain: - #include_code authwit_public_transfer_example /yarn-project/end-to-end/src/e2e_token_contract/transfer_public.test.ts typescript + #include_code authwit_public_transfer_example /yarn-project/end-to-end/src/e2e_token_contract/transfer_in_public.test.ts typescript Here you approve someone to transfer funds publicly on your behalf @@ -84,8 +84,6 @@ Let's say you have some storage in public and want to move them into the private So you have to create a custom note in the public domain that is not encrypted by some owner - we call such notes a "TransparentNote" since it is created in public, anyone can see the amount and the note is not encrypted by some owner. -This pattern is discussed in detail in [the codealong token tutorial in the shield() method](../../../../../tutorials/codealong/contract_tutorials/token_contract.md#redeem_shield). - ### Discovering my notes When you send someone a note, the note hash gets added to the note hash tree. To spend the note, the receiver needs to get the note itself (the note hash preimage). There are two ways you can get a hold of your notes: diff --git a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/portals/communicate_with_portal.md b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/portals/communicate_with_portal.md index 8c497e3f41c..d08078b0aec 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/portals/communicate_with_portal.md +++ b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/portals/communicate_with_portal.md @@ -53,7 +53,7 @@ The `content_hash` is a sha256 truncated to a field element (~ 254 bits). In Azt ### Token portal hash library -#include_code mint_public_content_hash_nr /noir-projects/noir-contracts/contracts/token_portal_content_hash_lib/src/lib.nr rust +#include_code mint_to_public_content_hash_nr /noir-projects/noir-contracts/contracts/token_portal_content_hash_lib/src/lib.nr rust ### Token Portal contract diff --git a/docs/docs/migration_notes.md b/docs/docs/migration_notes.md index 4e44286b40c..9a7adc06ad1 100644 --- a/docs/docs/migration_notes.md +++ b/docs/docs/migration_notes.md @@ -6,6 +6,21 @@ keywords: [sandbox, aztec, notes, migration, updating, upgrading] Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them. +## 0.63.0 +### [Token contract] Partial notes related refactor +We've decided to replace the old "shield" flow with one leveraging partial notes. +This led to a removal of `shield` and `redeem_shield` functions and an introduction of `transfer_to_private`. +An advantage of the new approach is that only 1 tx is required and the API of partial notes is generally nicer. +For more information on partial notes refer to docs. + +### [Token contract] Function naming changes +There have been a few naming changes done for improved consistency. +These are the renamings: +`transfer_public` --> `transfer_in_public` +`transfer_from` --> `transfer_in_private` +`mint_public` --> `mint_to_public` +`burn` --> `burn_private` + ## 0.62.0 ### [TXE] Single execution environment Thanks to recent advancements in Brillig TXE performs every single call as if it was a nested call, spawning a new ACVM or AVM simulator without performance loss. diff --git a/docs/docs/reference/developer_references/sandbox_reference/cli_wallet_reference.md b/docs/docs/reference/developer_references/sandbox_reference/cli_wallet_reference.md index 593415d21d9..12a837c227a 100644 --- a/docs/docs/reference/developer_references/sandbox_reference/cli_wallet_reference.md +++ b/docs/docs/reference/developer_references/sandbox_reference/cli_wallet_reference.md @@ -104,10 +104,10 @@ The authwit management in private is a two-step process: create and add. It's no #### Example -An example for authorizing an operator (ex. a DeFi protocol) to call the transfer_from action (transfer on the user's behalf): +An example for authorizing an operator (ex. a DeFi protocol) to call the transfer_in_private action (transfer on the user's behalf): ```bash -aztec-wallet create-authwit transfer_from accounts:coruscant_trader -ca contracts:token --args accounts:jedi_master accounts:coruscant_trader 20 secrets:auth_nonce -f accounts:jedi_master -a secret_trade +aztec-wallet create-authwit transfer_in_private accounts:coruscant_trader -ca contracts:token --args accounts:jedi_master accounts:coruscant_trader 20 secrets:auth_nonce -f accounts:jedi_master -a secret_trade aztec-wallet add-authwit authwits:secret_trade accounts:jedi_master -f accounts:coruscant_trader ``` @@ -117,7 +117,7 @@ aztec-wallet add-authwit authwits:secret_trade accounts:jedi_master -f accounts: A similar call to the above, but in public: ```bash -aztec-wallet authorize-action transfer_public accounts:coruscant_trader -ca contracts:token --args accounts:jedi_master accounts:coruscant_trader 20 secrets:auth_nonce -f accounts:jedi_master +aztec-wallet authorize-action transfer_in_public accounts:coruscant_trader -ca contracts:token --args accounts:jedi_master accounts:coruscant_trader 20 secrets:auth_nonce -f accounts:jedi_master ``` ### Simulate diff --git a/docs/docs/tutorials/codealong/aztecjs-getting-started.md b/docs/docs/tutorials/codealong/aztecjs-getting-started.md index e0f03f62b9b..72168fc5da5 100644 --- a/docs/docs/tutorials/codealong/aztecjs-getting-started.md +++ b/docs/docs/tutorials/codealong/aztecjs-getting-started.md @@ -283,7 +283,7 @@ Our output should now look like this: Here, we used the same contract abstraction as was previously used for reading Alice's balance. But this time we called `send()` generating and sending a transaction to the network. After waiting for the transaction to settle we were able to check the new balance values. Finally, the contract has 2 `mint` functions that can be used to generate new tokens for an account. -We will focus only on `mint_private`. +We will focus only on `mint_to_private`. This function is public but it mints tokens privately. This function takes: diff --git a/docs/docs/tutorials/codealong/cli_wallet/faceid_wallet.md b/docs/docs/tutorials/codealong/cli_wallet/faceid_wallet.md index 73d04e960b9..fc9b89d6b24 100644 --- a/docs/docs/tutorials/codealong/cli_wallet/faceid_wallet.md +++ b/docs/docs/tutorials/codealong/cli_wallet/faceid_wallet.md @@ -103,9 +103,9 @@ You should get a prompt to sign this transaction. You can now mint, transfer, an ```bash aztec-wallet create-account -a new_recipient # creating a schnorr account -aztec-wallet send mint_public -ca last --args accounts:my-wallet 10 -f accounts:my-wallet # minting some tokens in public +aztec-wallet send mint_to_public -ca last --args accounts:my-wallet 10 -f accounts:my-wallet # minting some tokens in public aztec-wallet simulate balance_of_public -ca contracts:devtoken --args accounts:my-wallet -f my-wallet # checking that my-wallet has 10 tokens -aztec-wallet send transfer_public -ca contracts:devtoken --args accounts:my-wallet accounts:new_recipient 10 0 -f accounts:my-wallet # transferring some tokens in public +aztec-wallet send transfer_in_public -ca contracts:devtoken --args accounts:my-wallet accounts:new_recipient 10 0 -f accounts:my-wallet # transferring some tokens in public aztec-wallet simulate balance_of_public -ca contracts:devtoken --args accounts:new_recipient -f my-wallet # checking that new_recipient has 10 tokens ``` diff --git a/docs/docs/tutorials/codealong/contract_tutorials/advanced/token_bridge/1_depositing_to_aztec.md b/docs/docs/tutorials/codealong/contract_tutorials/advanced/token_bridge/1_depositing_to_aztec.md index 0d7632cc1bc..955e16f2799 100644 --- a/docs/docs/tutorials/codealong/contract_tutorials/advanced/token_bridge/1_depositing_to_aztec.md +++ b/docs/docs/tutorials/codealong/contract_tutorials/advanced/token_bridge/1_depositing_to_aztec.md @@ -57,7 +57,7 @@ Here is an explanation of what it is doing: - The content is limited to a single field (~254 bits). So if the content is larger, we have to hash it and the hash can be passed along. - We use our utility method that creates a sha256 hash but truncates it to fit into a field - Since we want to mint tokens on Aztec publicly, the content here is the amount to mint and the address on Aztec who will receive the tokens. - - We encode this message as a mint_public function call, to specify the exact intentions and parameters we want to execute on L2. + - We encode this message as a mint_to_public function call, to specify the exact intentions and parameters we want to execute on L2. - In reality the content can be constructed in any manner as long as the sister contract on L2 can also create it. But for clarity, we are constructing the content like an ABI encoded function call. - It is good practice to include all parameters used by L2 into this content (like the amount and to) so that a malicious actor can’t change the to to themselves when consuming the message. 3. The tokens are transferred from the user to the portal using `underlying.safeTransferFrom()`. This puts the funds under the portal's control. @@ -78,7 +78,7 @@ Let’s do the similar for the private flow: Here we want to send a message to mint tokens privately on Aztec! Some key differences from the previous method are: -- The content hash uses a different function name - `mint_private`. This is done to make it easy to separate concerns. If the contentHash between the public and private message was the same, then an attacker could consume a private message publicly! +- The content hash uses a different function name - `mint_to_private`. This is done to make it easy to separate concerns. If the contentHash between the public and private message was the same, then an attacker could consume a private message publicly! - Since we want to mint tokens privately, we shouldn’t specify a `to` Aztec address (remember that Ethereum is completely public). Instead, we will use a secret hash - `secretHashForRedeemingMintedNotes`. Only he who knows the preimage to the secret hash can actually mint the notes. This is similar to the mechanism we use for message consumption on L2 - Like with the public flow, we move the user’s funds to the portal - We now send the message to the inbox with the `recipient` (the sister contract on L2 along with the version of aztec the message is intended for) and the `secretHashForL2MessageConsumption` (such that on L2, the consumption of the message can be private). diff --git a/docs/docs/tutorials/codealong/contract_tutorials/advanced/token_bridge/2_minting_on_aztec.md b/docs/docs/tutorials/codealong/contract_tutorials/advanced/token_bridge/2_minting_on_aztec.md index 7316793ec39..8effc323e74 100644 --- a/docs/docs/tutorials/codealong/contract_tutorials/advanced/token_bridge/2_minting_on_aztec.md +++ b/docs/docs/tutorials/codealong/contract_tutorials/advanced/token_bridge/2_minting_on_aztec.md @@ -28,15 +28,15 @@ The `claim_public` function enables anyone to consume the message on the user's **What’s happening here?** -1. We first recompute the L1->L2 message content by calling `get_mint_public_content_hash()`. Note that the method does exactly the same as what the TokenPortal contract does in `depositToAztecPublic()` to create the content hash. +1. We first recompute the L1->L2 message content by calling `get_mint_to_public_content_hash()`. Note that the method does exactly the same as what the TokenPortal contract does in `depositToAztecPublic()` to create the content hash. 2. We then attempt to consume the L1->L2 message. Since we are depositing to Aztec publicly, all of the inputs are public. - `context.consume_l1_to_l2_message()` takes in the few parameters: - - `content_hash`: The content - which is reconstructed in the `get_mint_public_content_hash()` + - `content_hash`: The content - which is reconstructed in the `get_mint_to_public_content_hash()` - `secret`: The secret used for consumption, often 0 for public messages - `sender`: Who on L1 sent the message. Which should match the stored `portal_address` in our case as we only want to allow messages from a specific sender. - `message_leaf_index`: The index in the message tree of the message. - Note that the `content_hash` requires `to` and `amount`. If a malicious user tries to mint tokens to their address by changing the to address, the content hash will be different to what the token portal had calculated on L1 and thus not be in the tree, failing the consumption. This is why we add these parameters into the content. -3. Then we call `Token::at(storage.token.read()).mint_public()` to mint the tokens to the to address. +3. Then we call `Token::at(storage.token.read()).mint_to_public()` to mint the tokens to the to address. ## Private flow @@ -46,12 +46,12 @@ Now we will create a function to mint the amount privately. Paste this into your #include_code call_mint_on_token /noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr rust -The `get_mint_private_content_hash` function is imported from the `token_portal_content_hash_lib`. +The `get_mint_to_private_content_hash` function is imported from the `token_portal_content_hash_lib`. -If the content hashes were constructed similarly for `mint_private` and `mint_publicly`, then content intended for private execution could have been consumed by calling the `claim_public` method. By making these two content hashes distinct, we prevent this scenario. +If the content hashes were constructed similarly for `mint_to_private` and `mint_to_public`, then content intended for private execution could have been consumed by calling the `claim_public` method. By making these two content hashes distinct, we prevent this scenario. While we mint the tokens on L2, we _still don’t actually mint them to a certain address_. Instead we continue to pass the `secret_hash_for_redeeming_minted_notes` like we did on L1. This means that a user could reveal their secret for L2 message consumption for anyone to mint tokens on L2 but they can redeem these notes at a later time. **This enables a paradigm where an app can manage user’s secrets for L2 message consumption on their behalf**. **The app or any external party can also mint tokens on the user’s behalf should they be comfortable with leaking the secret for L2 Message consumption.** This doesn’t leak any new information to the app because their smart contract on L1 knew that a user wanted to move some amount of tokens to L2. The app still doesn’t know which address on L2 the user wants these notes to be in, but they can mint tokens nevertheless on their behalf. -To mint tokens privately, `claim_private` calls an internal function `_call_mint_on_token()` which then calls [token.mint_private()](../../token_contract.md#mint_private). +To mint tokens privately, `claim_private` calls an internal function `_call_mint_on_token()` which then calls [token.mint_to_private()](../../token_contract.md#mint_to_private). In the next step we will see how we can cancel a message. diff --git a/docs/docs/tutorials/codealong/contract_tutorials/token_contract.md b/docs/docs/tutorials/codealong/contract_tutorials/token_contract.md index 5461f33d380..98a660a7c02 100644 --- a/docs/docs/tutorials/codealong/contract_tutorials/token_contract.md +++ b/docs/docs/tutorials/codealong/contract_tutorials/token_contract.md @@ -67,10 +67,10 @@ These are functions that have transparent logic, will execute in a publicly veri - `set_admin` enables the admin to be updated - `set_minter` enables accounts to be added / removed from the approved minter list -- `mint_public` enables tokens to be minted to the public balance of an account -- `mint_private` enables tokens to be minted to the private balance of an account (with some caveats we will dig into) +- `mint_to_public` enables tokens to be minted to the public balance of an account +- `mint_to_private` enables tokens to be minted to the private balance of an account (with some caveats we will dig into) - `transfer_to_public` enables tokens to be moved from a public balance to a private balance, not necessarily the same account (step 1 of a 2 step process) -- `transfer_public` enables users to transfer tokens from one account's public balance to another account's public balance +- `transfer_in_public` enables users to transfer tokens from one account's public balance to another account's public balance - `burn_public` enables users to burn tokens ### Private functions @@ -78,7 +78,7 @@ These are functions that have transparent logic, will execute in a publicly veri These are functions that have private logic and will be executed on user devices to maintain privacy. The only data that is submitted to the network is a proof of correct execution, new data commitments and nullifiers, so users will not reveal which contract they are interacting with or which function they are executing. The only information that will be revealed publicly is that someone executed a private transaction on Aztec. - `transfer` enables an account to send tokens from their private balance to another account's private balance -- `transfer_from` enables an account to send tokens from another account's private balance to another account's private balance +- `transfer_in_private` enables an account to send tokens from another account's private balance to another account's private balance - `cancel_authwit` enables an account to cancel an authorization to spend tokens - `burn` enables tokens to be burned privately @@ -191,15 +191,15 @@ This function allows the `admin` to add or a remove a `minter` from the public ` #include_code set_minter /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust -#### `mint_public` +#### `mint_to_public` This function allows an account approved in the public `minters` mapping to create new public tokens owned by the provided `to` address. First, storage is initialized. Then the function checks that the `msg_sender` is approved to mint in the `minters` mapping. If it is, a new `U128` value is created of the `amount` provided. The function reads the recipients public balance and then adds the amount to mint, saving the output as `new_balance`, then reads to total supply and adds the amount to mint, saving the output as `supply`. `new_balance` and `supply` are then written to storage. -#include_code mint_public /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust +#include_code mint_to_public /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust -#### `mint_private` +#### `mint_to_private` This public function allows an account approved in the public `minters` mapping to create new private tokens. @@ -215,7 +215,7 @@ First a partial note is prepared then a call to `_finalize_transfer_to_private_u #include_code transfer_to_private /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust -#### `transfer_public` +#### `transfer_in_public` This public function enables public transfers between Aztec accounts. The sender's public balance will be debited the specified `amount` and the recipient's public balances will be credited with that amount. @@ -227,7 +227,7 @@ If the `msg_sender` is the same as the account to debit tokens from, the authori It returns `1` to indicate successful execution. -#include_code transfer_public /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust +#include_code transfer_in_public /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust #### `burn_public` @@ -268,19 +268,19 @@ After initializing storage, the function checks that the `msg_sender` is authori #include_code transfer /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust -#### `transfer_from` +#### `transfer_in_private` This private function enables an account to transfer tokens on behalf of another account. The account that tokens are being debited from must have authorized the `msg_sender` to spend tokens on its behalf. -#include_code transfer_from /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust +#include_code transfer_in_private /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust -#### `burn` +#### `burn_private` This private function enables accounts to privately burn (destroy) tokens. After initializing storage, the function checks that the `msg_sender` is authorized to spend tokens. Then it gets the sender's current balance and decrements it. Finally it stages a public function call to [`_reduce_total_supply`](#_reduce_total_supply). -#include_code burn /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust +#include_code burn_private /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust ### Internal function implementations diff --git a/docs/docs/tutorials/examples/uniswap/l2_contract.md b/docs/docs/tutorials/examples/uniswap/l2_contract.md index b8f9101e7a1..f1f31104325 100644 --- a/docs/docs/tutorials/examples/uniswap/l2_contract.md +++ b/docs/docs/tutorials/examples/uniswap/l2_contract.md @@ -47,7 +47,7 @@ This uses a util function `compute_swap_private_content_hash()` - find that [her This flow works similarly to the public flow with a few notable changes: - Notice how in the `swap_private()`, user has to pass in `token` address which they didn't in the public flow? Since `swap_private()` is a private method, it can't read what token is publicly stored on the token bridge, so instead the user passes a token address, and `_assert_token_is_same()` checks that this user provided address is same as the one in storage. Note that because public functions are executed by the sequencer while private methods are executed locally, all public calls are always done after all private calls are done. So first the burn would happen and only later the sequencer asserts that the token is same. Note that the sequencer just sees a request to `execute_assert_token_is_same` and therefore has no context on what the appropriate private method was. If the assertion fails, then the kernel circuit will fail to create a proof and hence the transaction will be dropped. -- In the public flow, the user calls `transfer_public()`. Here instead, the user calls `transfer_to_public()`. Why? The user can't directly transfer their private tokens (their notes) to the uniswap contract, because later the Uniswap contract has to approve the bridge to burn these notes and withdraw to L1. The authwit flow for the private domain requires a signature from the `sender`, which in this case would be the Uniswap contract. For the contract to sign, it would need a private key associated to it. But who would operate this key? +- In the public flow, the user calls `transfer_in_public()`. Here instead, the user calls `transfer_to_public()`. Why? The user can't directly transfer their private tokens (their notes) to the uniswap contract, because later the Uniswap contract has to approve the bridge to burn these notes and withdraw to L1. The authwit flow for the private domain requires a signature from the `sender`, which in this case would be the Uniswap contract. For the contract to sign, it would need a private key associated to it. But who would operate this key? - To work around this, the user can transfer to public their private tokens into Uniswap L2 contract. Transferring to public would convert user's private notes to public balance. It is a private method on the token contract that reduces a user’s private balance and then calls a public method to increase the recipient’s (ie Uniswap) public balance. **Remember that first all private methods are executed and then later all public methods will be - so the Uniswap contract won’t have the funds until public execution begins.** - Now uniswap has public balance (like with the public flow). Hence, `swap_private()` calls the internal public method which approves the input token bridge to burn Uniswap’s tokens and calls `exit_to_l1_public` to create an L2 → L1 message to exit to L1. - Constructing the message content for swapping works exactly as the public flow except instead of specifying who would be the Aztec address that receives the swapped funds, we specify a secret hash (`secret_hash_for_redeeming_minted_notes`). Only those who know the preimage to the secret can later redeem the minted notes to themselves. diff --git a/l1-contracts/test/fee_portal/depositToAztecPublic.t.sol b/l1-contracts/test/fee_portal/depositToAztecPublic.t.sol index db038cfe772..fc68df1a444 100644 --- a/l1-contracts/test/fee_portal/depositToAztecPublic.t.sol +++ b/l1-contracts/test/fee_portal/depositToAztecPublic.t.sol @@ -81,6 +81,8 @@ contract DepositToAztecPublic is Test { uint256 amount = 100 ether; uint256 expectedIndex = 2 ** Constants.L1_TO_L2_MSG_SUBTREE_HEIGHT; + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. DataStructures.L1ToL2Msg memory message = DataStructures.L1ToL2Msg({ sender: DataStructures.L1Actor(address(feeJuicePortal), block.chainid), recipient: DataStructures.L2Actor(feeJuicePortal.L2_TOKEN_ADDRESS(), 1 + numberOfRollups), diff --git a/l1-contracts/test/portals/TokenPortal.sol b/l1-contracts/test/portals/TokenPortal.sol index d9bd3280946..115132e5234 100644 --- a/l1-contracts/test/portals/TokenPortal.sol +++ b/l1-contracts/test/portals/TokenPortal.sol @@ -53,8 +53,10 @@ contract TokenPortal { DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2Bridge, 1); // Hash the message content to be reconstructed in the receiving contract + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. bytes32 contentHash = - Hash.sha256ToField(abi.encodeWithSignature("mint_public(bytes32,uint256)", _to, _amount)); + Hash.sha256ToField(abi.encodeWithSignature("mint_to_public(bytes32,uint256)", _to, _amount)); // Hold the tokens in the portal underlying.safeTransferFrom(msg.sender, address(this), _amount); @@ -87,7 +89,7 @@ contract TokenPortal { // Hash the message content to be reconstructed in the receiving contract - the signature below does not correspond // to a real function. It's just an identifier of an action. bytes32 contentHash = - Hash.sha256ToField(abi.encodeWithSignature("mint_private(uint256)", _amount)); + Hash.sha256ToField(abi.encodeWithSignature("mint_to_private(uint256)", _amount)); // Hold the tokens in the portal underlying.safeTransferFrom(msg.sender, address(this), _amount); @@ -123,6 +125,8 @@ contract TokenPortal { uint256 _leafIndex, bytes32[] calldata _path ) external { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({ sender: DataStructures.L2Actor(l2Bridge, 1), recipient: DataStructures.L1Actor(address(this), block.chainid), diff --git a/l1-contracts/test/portals/TokenPortal.t.sol b/l1-contracts/test/portals/TokenPortal.t.sol index ba5fa33c0c0..da7af0eb534 100644 --- a/l1-contracts/test/portals/TokenPortal.t.sol +++ b/l1-contracts/test/portals/TokenPortal.t.sol @@ -88,10 +88,12 @@ contract TokenPortalTest is Test { view returns (DataStructures.L1ToL2Msg memory) { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. return DataStructures.L1ToL2Msg({ sender: DataStructures.L1Actor(address(tokenPortal), block.chainid), recipient: DataStructures.L2Actor(l2TokenAddress, 1), - content: Hash.sha256ToField(abi.encodeWithSignature("mint_private(uint256)", amount)), + content: Hash.sha256ToField(abi.encodeWithSignature("mint_to_private(uint256)", amount)), secretHash: secretHashForL2MessageConsumption, index: _index }); @@ -102,10 +104,14 @@ contract TokenPortalTest is Test { view returns (DataStructures.L1ToL2Msg memory) { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. return DataStructures.L1ToL2Msg({ sender: DataStructures.L1Actor(address(tokenPortal), block.chainid), recipient: DataStructures.L2Actor(l2TokenAddress, 1), - content: Hash.sha256ToField(abi.encodeWithSignature("mint_public(bytes32,uint256)", to, amount)), + content: Hash.sha256ToField( + abi.encodeWithSignature("mint_to_public(bytes32,uint256)", to, amount) + ), secretHash: secretHashForL2MessageConsumption, index: _index }); @@ -169,6 +175,8 @@ contract TokenPortalTest is Test { internal returns (bytes32, bytes32) { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. bytes32 l2ToL1Message = Hash.sha256ToField( DataStructures.L2ToL1Msg({ sender: DataStructures.L2Actor({actor: l2TokenAddress, version: 1}), diff --git a/l1-contracts/test/portals/UniswapPortal.sol b/l1-contracts/test/portals/UniswapPortal.sol index a4eb66d8b80..37e02ee69bb 100644 --- a/l1-contracts/test/portals/UniswapPortal.sol +++ b/l1-contracts/test/portals/UniswapPortal.sol @@ -87,6 +87,8 @@ contract UniswapPortal { { // prevent stack too deep errors + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. vars.contentHash = Hash.sha256ToField( abi.encodeWithSignature( "swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)", @@ -191,6 +193,8 @@ contract UniswapPortal { { // prevent stack too deep errors + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. vars.contentHash = Hash.sha256ToField( abi.encodeWithSignature( "swap_private(address,uint256,uint24,address,uint256,bytes32,address)", diff --git a/l1-contracts/test/portals/UniswapPortal.t.sol b/l1-contracts/test/portals/UniswapPortal.t.sol index bf37ae19e64..ac646e17bac 100644 --- a/l1-contracts/test/portals/UniswapPortal.t.sol +++ b/l1-contracts/test/portals/UniswapPortal.t.sol @@ -94,6 +94,8 @@ contract UniswapPortalTest is Test { view returns (bytes32 l2ToL1MessageHash) { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({ sender: DataStructures.L2Actor(l2TokenAddress, 1), recipient: DataStructures.L1Actor(address(daiTokenPortal), block.chainid), @@ -116,6 +118,8 @@ contract UniswapPortalTest is Test { view returns (bytes32 l2ToL1MessageHash) { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({ sender: DataStructures.L2Actor(l2UniswapAddress, 1), recipient: DataStructures.L1Actor(address(uniswapPortal), block.chainid), @@ -143,6 +147,8 @@ contract UniswapPortalTest is Test { * Set to address(0) if anyone can call. */ function _createUniswapSwapMessagePrivate(address _caller) internal view returns (bytes32) { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({ sender: DataStructures.L2Actor(l2UniswapAddress, 1), recipient: DataStructures.L1Actor(address(uniswapPortal), block.chainid), diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr index fd11c9a9c5d..d188ebe78db 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr @@ -96,7 +96,7 @@ contract AppSubscription { assert(tx_count as u64 <= SUBSCRIPTION_TXS as u64); Token::at(storage.subscription_token_address.read_private()) - .transfer_from( + .transfer_in_private( context.msg_sender(), storage.subscription_recipient_address.read_private(), storage.subscription_price.read_private(), diff --git a/noir-projects/noir-contracts/contracts/claim_contract/src/main.nr b/noir-projects/noir-contracts/contracts/claim_contract/src/main.nr index 668c2c86e31..edaf81c7cc4 100644 --- a/noir-projects/noir-contracts/contracts/claim_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/claim_contract/src/main.nr @@ -52,7 +52,7 @@ contract Claim { // 4) Finally we mint the reward token to the sender of the transaction Token::at(storage.reward_token.read_private()) - .mint_public(recipient, proof_note.value) + .mint_to_public(recipient, proof_note.value) .enqueue(&mut context); } } diff --git a/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr b/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr index 92e89729e74..991b10c40a4 100644 --- a/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr @@ -77,7 +77,7 @@ contract Crowdfunding { // 2) Transfer the donation tokens from donor to this contract let donor = context.msg_sender(); Token::at(storage.donation_token.read_private()) - .transfer_from(donor, context.this_address(), amount as Field, 0) + .transfer_in_private(donor, context.this_address(), amount as Field, 0) .call(&mut context); // docs:end:do-transfer // 3) Create a value note for the donor so that he can later on claim a rewards token in the Claim diff --git a/noir-projects/noir-contracts/contracts/fee_juice_contract/src/lib.nr b/noir-projects/noir-contracts/contracts/fee_juice_contract/src/lib.nr index 6f77d74b16e..35179d962e1 100644 --- a/noir-projects/noir-contracts/contracts/fee_juice_contract/src/lib.nr +++ b/noir-projects/noir-contracts/contracts/fee_juice_contract/src/lib.nr @@ -11,17 +11,19 @@ pub fn get_bridge_gas_msg_hash(owner: AztecAddress, amount: Field) -> Field { let recipient_bytes: [u8; 32] = owner.to_field().to_be_bytes(); let amount_bytes: [u8; 32] = amount.to_be_bytes(); + // The purpose of including the following selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. + let selector = comptime { std::hash::keccak256("claim(bytes32,uint256)".as_bytes(), 22) }; + + for i in 0..4 { + hash_bytes[i] = selector[i]; + } + for i in 0..32 { hash_bytes[i + 4] = recipient_bytes[i]; hash_bytes[i + 36] = amount_bytes[i]; } - // Function selector: 0x63f44968 keccak256('claim(bytes32,uint256)') - hash_bytes[0] = 0x63; - hash_bytes[1] = 0xf4; - hash_bytes[2] = 0x49; - hash_bytes[3] = 0x68; - let content_hash = sha256_to_field(hash_bytes); content_hash } diff --git a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr index 9a9376abfc9..ab1ffdc4753 100644 --- a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr @@ -58,7 +58,7 @@ contract FPC { #[internal] fn prepare_fee(from: AztecAddress, amount: Field, asset: AztecAddress, nonce: Field) { // docs:start:public_call - Token::at(asset).transfer_public(from, context.this_address(), amount, nonce).call( + Token::at(asset).transfer_in_public(from, context.this_address(), amount, nonce).call( &mut context, ); // docs:end:public_call @@ -69,7 +69,7 @@ contract FPC { fn pay_refund(refund_address: AztecAddress, amount: Field, asset: AztecAddress) { // Just do public refunds for the present let refund = compute_rebate(context, amount); - Token::at(asset).transfer_public(context.this_address(), refund_address, refund, 0).call( + Token::at(asset).transfer_in_public(context.this_address(), refund_address, refund, 0).call( &mut context, ); } diff --git a/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr b/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr index 938d403c803..b5781af3b20 100644 --- a/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr @@ -129,7 +129,7 @@ contract Lending { collateral_asset: AztecAddress, ) { let _ = Token::at(collateral_asset) - .transfer_public(context.msg_sender(), context.this_address(), amount, nonce) + .transfer_in_public(context.msg_sender(), context.this_address(), amount, nonce) .call(&mut context); let _ = Lending::at(context.this_address()) ._deposit(AztecAddress::from_field(on_behalf_of), amount, collateral_asset) @@ -199,7 +199,7 @@ contract Lending { // @todo @LHerskind Support both shielding and transfers (for now just transfer) let collateral_asset = storage.collateral_asset.read(); let _ = Token::at(collateral_asset) - .transfer_public(context.this_address(), recipient, amount, 0) + .transfer_in_public(context.this_address(), recipient, amount, 0) .call(&mut context); } @@ -248,7 +248,7 @@ contract Lending { // @todo @LHerskind Need to support both private and public minting. let stable_coin = storage.stable_coin.read(); - let _ = Token::at(stable_coin).mint_public(to, amount).call(&mut context); + let _ = Token::at(stable_coin).mint_to_public(to, amount).call(&mut context); } #[private] @@ -263,7 +263,7 @@ contract Lending { let on_behalf_of = compute_identifier(secret, on_behalf_of, context.msg_sender().to_field()); // docs:start:private_call - let _ = Token::at(stable_coin).burn(from, amount, nonce).call(&mut context); + let _ = Token::at(stable_coin).burn_private(from, amount, nonce).call(&mut context); // docs:end:private_call let _ = Lending::at(context.this_address()) ._repay(AztecAddress::from_field(on_behalf_of), amount, stable_coin) diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index 723239b18d0..8a8091e6422 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -34,7 +34,7 @@ contract Test { utils::comparison::Comparator, }; use dep::token_portal_content_hash_lib::{ - get_mint_private_content_hash, get_mint_public_content_hash, + get_mint_to_private_content_hash, get_mint_to_public_content_hash, }; use dep::value_note::value_note::ValueNote; // TODO investigate why the macros require EmbeddedCurvePoint and EmbeddedCurveScalar @@ -372,27 +372,27 @@ contract Test { } #[public] - fn consume_mint_public_message( + fn consume_mint_to_public_message( to: AztecAddress, amount: Field, secret: Field, message_leaf_index: Field, portal_address: EthAddress, ) { - let content_hash = get_mint_public_content_hash(to, amount); + let content_hash = get_mint_to_public_content_hash(to, amount); // Consume message and emit nullifier context.consume_l1_to_l2_message(content_hash, secret, portal_address, message_leaf_index); } #[private] - fn consume_mint_private_message( + fn consume_mint_to_private_message( amount: Field, secret_for_L1_to_L2_message_consumption: Field, portal_address: EthAddress, message_leaf_index: Field, ) { // Consume L1 to L2 message and emit nullifier - let content_hash = get_mint_private_content_hash(amount); + let content_hash = get_mint_to_private_content_hash(amount); context.consume_l1_to_l2_message( content_hash, secret_for_L1_to_L2_message_consumption, diff --git a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr index b5a75ad1623..0c20ba05832 100644 --- a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr @@ -12,7 +12,8 @@ contract TokenBridge { use dep::aztec::prelude::{AztecAddress, EthAddress, SharedImmutable}; use dep::token_portal_content_hash_lib::{ - get_mint_private_content_hash, get_mint_public_content_hash, get_withdraw_content_hash, + get_mint_to_private_content_hash, get_mint_to_public_content_hash, + get_withdraw_content_hash, }; use dep::token::Token; @@ -54,7 +55,7 @@ contract TokenBridge { // Consumes a L1->L2 message and calls the token contract to mint the appropriate amount publicly #[public] fn claim_public(to: AztecAddress, amount: Field, secret: Field, message_leaf_index: Field) { - let content_hash = get_mint_public_content_hash(to, amount); + let content_hash = get_mint_to_public_content_hash(to, amount); // Consume message and emit nullifier context.consume_l1_to_l2_message( @@ -65,7 +66,7 @@ contract TokenBridge { ); // Mint tokens - Token::at(storage.token.read_public()).mint_public(to, amount).call(&mut context); + Token::at(storage.token.read_public()).mint_to_public(to, amount).call(&mut context); } // docs:end:claim_public @@ -103,7 +104,7 @@ contract TokenBridge { message_leaf_index: Field, ) { // Consume L1 to L2 message and emit nullifier - let content_hash = get_mint_private_content_hash(amount); + let content_hash = get_mint_to_private_content_hash(amount); context.consume_l1_to_l2_message( content_hash, secret_for_L1_to_L2_message_consumption, @@ -143,7 +144,7 @@ contract TokenBridge { TokenBridge::at(context.this_address())._assert_token_is_same(token).enqueue(&mut context); // docs:end:call_assert_token_is_same // Burn tokens - Token::at(token).burn(context.msg_sender(), amount, nonce).call(&mut context); + Token::at(token).burn_private(context.msg_sender(), amount, nonce).call(&mut context); } /// docs:end:exit_to_l1_private // docs:start:get_token diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr index d22ae39e5cf..fd1b5180159 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -197,9 +197,9 @@ contract Token { } // docs:end:set_minter - // docs:start:mint_public + // docs:start:mint_to_public #[public] - fn mint_public(to: AztecAddress, amount: Field) { + fn mint_to_public(to: AztecAddress, amount: Field) { // docs:start:read_minter assert(storage.minters.at(context.msg_sender()).read(), "caller is not minter"); // docs:end:read_minter @@ -209,11 +209,11 @@ contract Token { storage.public_balances.at(to).write(new_balance); storage.total_supply.write(supply); } - // docs:end:mint_public + // docs:end:mint_to_public - // docs:start:transfer_public + // docs:start:transfer_in_public #[public] - fn transfer_public(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) { + fn transfer_in_public(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) { if (!from.eq(context.msg_sender())) { assert_current_call_valid_authwit_public(&mut context, from); } else { @@ -225,7 +225,7 @@ contract Token { let to_balance = storage.public_balances.at(to).read().add(amount); storage.public_balances.at(to).write(to_balance); } - // docs:end:transfer_public + // docs:end:transfer_in_public // docs:start:burn_public #[public] @@ -297,7 +297,7 @@ contract Token { to, from, )); - // We don't constrain encryption of the note log in `transfer` (unlike in `transfer_from`) because the transfer + // We don't constrain encryption of the note log in `transfer` (unlike in `transfer_in_private`) because the transfer // function is only designed to be used in situations where the event is not strictly necessary (e.g. payment to // another person where the payment is considered to be successful when the other party successfully decrypts a // note). @@ -371,9 +371,9 @@ contract Token { } // docs:end:cancel_authwit - // docs:start:transfer_from + // docs:start:transfer_in_private #[private] - fn transfer_from(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) { + fn transfer_in_private(from: AztecAddress, to: AztecAddress, amount: Field, nonce: Field) { // docs:start:assert_current_call_valid_authwit if (!from.eq(context.msg_sender())) { assert_current_call_valid_authwit(&mut context, from); @@ -405,11 +405,11 @@ contract Token { from, )); } - // docs:end:transfer_from + // docs:end:transfer_in_private - // docs:start:burn + // docs:start:burn_private #[private] - fn burn(from: AztecAddress, amount: Field, nonce: Field) { + fn burn_private(from: AztecAddress, amount: Field, nonce: Field) { if (!from.eq(context.msg_sender())) { assert_current_call_valid_authwit(&mut context, from); } else { @@ -423,7 +423,7 @@ contract Token { ); Token::at(context.this_address())._reduce_total_supply(amount).enqueue(&mut context); } - // docs:end:burn + // docs:end:burn_private // docs:start:transfer_to_private // Transfers token `amount` from public balance of message sender to a private balance of `to`. @@ -572,7 +572,7 @@ contract Token { /// `prepare_transfer_to_private` first and the resulting /// `hiding_point_slot` must be passed as an argument to this function. /// - /// Note: This function is only an optimization as it could be replaced by a combination of `mint_public` + /// Note: This function is only an optimization as it could be replaced by a combination of `mint_to_public` /// and `finalize_transfer_to_private`. It is however used very commonly so it makes sense to optimize it /// (e.g. used during token bridging, in AMM liquidity token etc.). #[public] diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/test.nr b/noir-projects/noir-contracts/contracts/token_contract/src/test.nr index b746bbe1f6c..1ed2b177ced 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/test.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/test.nr @@ -1,10 +1,12 @@ mod access_control; -mod burn; -mod utils; -mod transfer_public; -mod transfer_private; +mod burn_private; +mod burn_public; +mod mint_to_public; +mod reading_constants; +mod refunds; +mod transfer; +mod transfer_in_private; +mod transfer_in_public; mod transfer_to_private; mod transfer_to_public; -mod refunds; -mod minting; -mod reading_constants; +mod utils; diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/test/burn.nr b/noir-projects/noir-contracts/contracts/token_contract/src/test/burn.nr deleted file mode 100644 index 151ef95a506..00000000000 --- a/noir-projects/noir-contracts/contracts/token_contract/src/test/burn.nr +++ /dev/null @@ -1,188 +0,0 @@ -use crate::test::utils; -use crate::Token; -use dep::authwit::cheatcodes as authwit_cheatcodes; -use dep::aztec::oracle::random::random; - -#[test] -unconstrained fn burn_public_success() { - let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ false); - let burn_amount = mint_amount / 10; - - // Burn less than balance - Token::at(token_contract_address).burn_public(owner, burn_amount, 0).call(&mut env.public()); - utils::check_public_balance(token_contract_address, owner, mint_amount - burn_amount); -} - -#[test] -unconstrained fn burn_public_on_behalf_of_other() { - let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ true); - let burn_amount = mint_amount / 10; - - // Burn on behalf of other - let burn_call_interface = - Token::at(token_contract_address).burn_public(owner, burn_amount, random()); - authwit_cheatcodes::add_public_authwit_from_call_interface( - owner, - recipient, - burn_call_interface, - ); - // Impersonate recipient to perform the call - env.impersonate(recipient); - // Burn tokens - burn_call_interface.call(&mut env.public()); - utils::check_public_balance(token_contract_address, owner, mint_amount - burn_amount); -} - -#[test(should_fail_with = "attempt to subtract with underflow")] -unconstrained fn burn_public_failure_more_than_balance() { - let (env, token_contract_address, owner, _, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ false); - - // Burn more than balance - let burn_amount = mint_amount * 10; - // Try to burn - Token::at(token_contract_address).burn_public(owner, burn_amount, 0).call(&mut env.public()); -} - -#[test(should_fail_with = "invalid nonce")] -unconstrained fn burn_public_failure_on_behalf_of_self_non_zero_nonce() { - let (env, token_contract_address, owner, _, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ false); - - // Burn on behalf of self with non-zero nonce - let burn_amount = mint_amount / 10; - // Try to burn - Token::at(token_contract_address).burn_public(owner, burn_amount, random()).call( - &mut env.public(), - ); -} - -#[test(should_fail_with = "unauthorized")] -unconstrained fn burn_public_failure_on_behalf_of_other_without_approval() { - let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ true); - - // Burn on behalf of other without approval - let burn_amount = mint_amount / 10; - let burn_call_interface = - Token::at(token_contract_address).burn_public(owner, burn_amount, random()); - // Impersonate recipient to perform the call - env.impersonate(recipient); - burn_call_interface.call(&mut env.public()); -} - -#[test(should_fail_with = "unauthorized")] -unconstrained fn burn_public_failure_on_behalf_of_other_wrong_caller() { - let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ true); - - // Burn on behalf of other, wrong designated caller - let burn_amount = mint_amount / 10; - let burn_call_interface = - Token::at(token_contract_address).burn_public(owner, burn_amount, random()); - authwit_cheatcodes::add_public_authwit_from_call_interface(owner, owner, burn_call_interface); - // Impersonate recipient to perform the call - env.impersonate(recipient); - burn_call_interface.call(&mut env.public()); -} - -#[test] -unconstrained fn burn_private_on_behalf_of_self() { - let (env, token_contract_address, owner, _, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ false); - let burn_amount = mint_amount / 10; - - // Burn less than balance - Token::at(token_contract_address).burn(owner, burn_amount, 0).call(&mut env.private()); - utils::check_private_balance(token_contract_address, owner, mint_amount - burn_amount); -} - -#[test] -unconstrained fn burn_private_on_behalf_of_other() { - let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ true); - let burn_amount = mint_amount / 10; - - // Burn on behalf of other - let burn_call_interface = Token::at(token_contract_address).burn(owner, burn_amount, random()); - authwit_cheatcodes::add_private_authwit_from_call_interface( - owner, - recipient, - burn_call_interface, - ); - // Impersonate recipient to perform the call - env.impersonate(recipient); - // Burn tokens - burn_call_interface.call(&mut env.private()); - utils::check_private_balance(token_contract_address, owner, mint_amount - burn_amount); -} - -#[test(should_fail_with = "Balance too low")] -unconstrained fn burn_private_failure_more_than_balance() { - let (env, token_contract_address, owner, _, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ false); - - // Burn more than balance - let burn_amount = mint_amount * 10; - Token::at(token_contract_address).burn(owner, burn_amount, 0).call(&mut env.private()); -} - -#[test(should_fail_with = "invalid nonce")] -unconstrained fn burn_private_failure_on_behalf_of_self_non_zero_nonce() { - let (env, token_contract_address, owner, _, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ false); - - // Burn more than balance - let burn_amount = mint_amount / 10; - Token::at(token_contract_address).burn(owner, burn_amount, random()).call(&mut env.private()); -} - -#[test(should_fail_with = "Balance too low")] -unconstrained fn burn_private_failure_on_behalf_of_other_more_than_balance() { - let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ true); - - // Burn more than balance - let burn_amount = mint_amount * 10; - // Burn on behalf of other - let burn_call_interface = Token::at(token_contract_address).burn(owner, burn_amount, random()); - authwit_cheatcodes::add_private_authwit_from_call_interface( - owner, - recipient, - burn_call_interface, - ); - // Impersonate recipient to perform the call - env.impersonate(recipient); - burn_call_interface.call(&mut env.private()); -} - -#[test(should_fail_with = "Authorization not found for message hash")] -unconstrained fn burn_private_failure_on_behalf_of_other_without_approval() { - let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ true); - - // Burn more than balance - let burn_amount = mint_amount / 10; - // Burn on behalf of other - let burn_call_interface = Token::at(token_contract_address).burn(owner, burn_amount, 3); - // Impersonate recipient to perform the call - env.impersonate(recipient); - burn_call_interface.call(&mut env.private()); -} - -#[test(should_fail_with = "Authorization not found for message hash")] -unconstrained fn burn_private_failure_on_behalf_of_other_wrong_designated_caller() { - let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ true); - - // Burn more than balance - let burn_amount = mint_amount / 10; - // Burn on behalf of other - let burn_call_interface = Token::at(token_contract_address).burn(owner, burn_amount, 3); - authwit_cheatcodes::add_private_authwit_from_call_interface(owner, owner, burn_call_interface); - // Impersonate recipient to perform the call - env.impersonate(recipient); - burn_call_interface.call(&mut env.private()); -} diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/test/burn_private.nr b/noir-projects/noir-contracts/contracts/token_contract/src/test/burn_private.nr new file mode 100644 index 00000000000..a3ac58f79a1 --- /dev/null +++ b/noir-projects/noir-contracts/contracts/token_contract/src/test/burn_private.nr @@ -0,0 +1,107 @@ +use crate::test::utils; +use crate::Token; +use dep::authwit::cheatcodes as authwit_cheatcodes; +use dep::aztec::oracle::random::random; + +#[test] +unconstrained fn burn_private_on_behalf_of_self() { + let (env, token_contract_address, owner, _, mint_amount) = + utils::setup_and_mint_to_private(/* with_account_contracts */ false); + let burn_amount = mint_amount / 10; + + // Burn less than balance + Token::at(token_contract_address).burn_private(owner, burn_amount, 0).call(&mut env.private()); + utils::check_private_balance(token_contract_address, owner, mint_amount - burn_amount); +} + +#[test] +unconstrained fn burn_private_on_behalf_of_other() { + let (env, token_contract_address, owner, recipient, mint_amount) = + utils::setup_and_mint_to_private(/* with_account_contracts */ true); + let burn_amount = mint_amount / 10; + + // Burn on behalf of other + let burn_call_interface = + Token::at(token_contract_address).burn_private(owner, burn_amount, random()); + authwit_cheatcodes::add_private_authwit_from_call_interface( + owner, + recipient, + burn_call_interface, + ); + // Impersonate recipient to perform the call + env.impersonate(recipient); + // Burn tokens + burn_call_interface.call(&mut env.private()); + utils::check_private_balance(token_contract_address, owner, mint_amount - burn_amount); +} + +#[test(should_fail_with = "Balance too low")] +unconstrained fn burn_private_failure_more_than_balance() { + let (env, token_contract_address, owner, _, mint_amount) = + utils::setup_and_mint_to_public(/* with_account_contracts */ false); + + // Burn more than balance + let burn_amount = mint_amount * 10; + Token::at(token_contract_address).burn_private(owner, burn_amount, 0).call(&mut env.private()); +} + +#[test(should_fail_with = "invalid nonce")] +unconstrained fn burn_private_failure_on_behalf_of_self_non_zero_nonce() { + let (env, token_contract_address, owner, _, mint_amount) = + utils::setup_and_mint_to_public(/* with_account_contracts */ false); + + // Burn more than balance + let burn_amount = mint_amount / 10; + Token::at(token_contract_address).burn_private(owner, burn_amount, random()).call( + &mut env.private(), + ); +} + +#[test(should_fail_with = "Balance too low")] +unconstrained fn burn_private_failure_on_behalf_of_other_more_than_balance() { + let (env, token_contract_address, owner, recipient, mint_amount) = + utils::setup_and_mint_to_public(/* with_account_contracts */ true); + + // Burn more than balance + let burn_amount = mint_amount * 10; + // Burn on behalf of other + let burn_call_interface = + Token::at(token_contract_address).burn_private(owner, burn_amount, random()); + authwit_cheatcodes::add_private_authwit_from_call_interface( + owner, + recipient, + burn_call_interface, + ); + // Impersonate recipient to perform the call + env.impersonate(recipient); + burn_call_interface.call(&mut env.private()); +} + +#[test(should_fail_with = "Authorization not found for message hash")] +unconstrained fn burn_private_failure_on_behalf_of_other_without_approval() { + let (env, token_contract_address, owner, recipient, mint_amount) = + utils::setup_and_mint_to_public(/* with_account_contracts */ true); + + // Burn more than balance + let burn_amount = mint_amount / 10; + // Burn on behalf of other + let burn_call_interface = Token::at(token_contract_address).burn_private(owner, burn_amount, 3); + // Impersonate recipient to perform the call + env.impersonate(recipient); + burn_call_interface.call(&mut env.private()); +} + +#[test(should_fail_with = "Authorization not found for message hash")] +unconstrained fn burn_private_failure_on_behalf_of_other_wrong_designated_caller() { + let (env, token_contract_address, owner, recipient, mint_amount) = + utils::setup_and_mint_to_public(/* with_account_contracts */ true); + + // Burn more than balance + let burn_amount = mint_amount / 10; + // Burn on behalf of other + let burn_call_interface = Token::at(token_contract_address).burn_private(owner, burn_amount, 3); + authwit_cheatcodes::add_private_authwit_from_call_interface(owner, owner, burn_call_interface); + // Impersonate recipient to perform the call + env.impersonate(recipient); + burn_call_interface.call(&mut env.private()); +} diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/test/burn_public.nr b/noir-projects/noir-contracts/contracts/token_contract/src/test/burn_public.nr new file mode 100644 index 00000000000..1d427ff30ff --- /dev/null +++ b/noir-projects/noir-contracts/contracts/token_contract/src/test/burn_public.nr @@ -0,0 +1,89 @@ +use crate::test::utils; +use crate::Token; +use dep::authwit::cheatcodes as authwit_cheatcodes; +use dep::aztec::oracle::random::random; + +#[test] +unconstrained fn burn_public_success() { + let (env, token_contract_address, owner, recipient, mint_amount) = + utils::setup_and_mint_to_public(/* with_account_contracts */ false); + let burn_amount = mint_amount / 10; + + // Burn less than balance + Token::at(token_contract_address).burn_public(owner, burn_amount, 0).call(&mut env.public()); + utils::check_public_balance(token_contract_address, owner, mint_amount - burn_amount); +} + +#[test] +unconstrained fn burn_public_on_behalf_of_other() { + let (env, token_contract_address, owner, recipient, mint_amount) = + utils::setup_and_mint_to_public(/* with_account_contracts */ true); + let burn_amount = mint_amount / 10; + + // Burn on behalf of other + let burn_call_interface = + Token::at(token_contract_address).burn_public(owner, burn_amount, random()); + authwit_cheatcodes::add_public_authwit_from_call_interface( + owner, + recipient, + burn_call_interface, + ); + // Impersonate recipient to perform the call + env.impersonate(recipient); + // Burn tokens + burn_call_interface.call(&mut env.public()); + utils::check_public_balance(token_contract_address, owner, mint_amount - burn_amount); +} + +#[test(should_fail_with = "attempt to subtract with underflow")] +unconstrained fn burn_public_failure_more_than_balance() { + let (env, token_contract_address, owner, _, mint_amount) = + utils::setup_and_mint_to_public(/* with_account_contracts */ false); + + // Burn more than balance + let burn_amount = mint_amount * 10; + // Try to burn + Token::at(token_contract_address).burn_public(owner, burn_amount, 0).call(&mut env.public()); +} + +#[test(should_fail_with = "invalid nonce")] +unconstrained fn burn_public_failure_on_behalf_of_self_non_zero_nonce() { + let (env, token_contract_address, owner, _, mint_amount) = + utils::setup_and_mint_to_public(/* with_account_contracts */ false); + + // Burn on behalf of self with non-zero nonce + let burn_amount = mint_amount / 10; + // Try to burn + Token::at(token_contract_address).burn_public(owner, burn_amount, random()).call( + &mut env.public(), + ); +} + +#[test(should_fail_with = "unauthorized")] +unconstrained fn burn_public_failure_on_behalf_of_other_without_approval() { + let (env, token_contract_address, owner, recipient, mint_amount) = + utils::setup_and_mint_to_public(/* with_account_contracts */ true); + + // Burn on behalf of other without approval + let burn_amount = mint_amount / 10; + let burn_call_interface = + Token::at(token_contract_address).burn_public(owner, burn_amount, random()); + // Impersonate recipient to perform the call + env.impersonate(recipient); + burn_call_interface.call(&mut env.public()); +} + +#[test(should_fail_with = "unauthorized")] +unconstrained fn burn_public_failure_on_behalf_of_other_wrong_caller() { + let (env, token_contract_address, owner, recipient, mint_amount) = + utils::setup_and_mint_to_public(/* with_account_contracts */ true); + + // Burn on behalf of other, wrong designated caller + let burn_amount = mint_amount / 10; + let burn_call_interface = + Token::at(token_contract_address).burn_public(owner, burn_amount, random()); + authwit_cheatcodes::add_public_authwit_from_call_interface(owner, owner, burn_call_interface); + // Impersonate recipient to perform the call + env.impersonate(recipient); + burn_call_interface.call(&mut env.public()); +} diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/test/minting.nr b/noir-projects/noir-contracts/contracts/token_contract/src/test/mint_to_public.nr similarity index 62% rename from noir-projects/noir-contracts/contracts/token_contract/src/test/minting.nr rename to noir-projects/noir-contracts/contracts/token_contract/src/test/mint_to_public.nr index 1b572b872ff..c4cb9055ac0 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/test/minting.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/test/mint_to_public.nr @@ -1,12 +1,12 @@ use crate::{test::utils, Token}; #[test] -unconstrained fn mint_public_success() { +unconstrained fn mint_to_public_success() { // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (env, token_contract_address, owner, _) = utils::setup(/* with_account_contracts */ false); let mint_amount = 10000; - Token::at(token_contract_address).mint_public(owner, mint_amount).call(&mut env.public()); + Token::at(token_contract_address).mint_to_public(owner, mint_amount).call(&mut env.public()); utils::check_public_balance(token_contract_address, owner, mint_amount); @@ -15,7 +15,7 @@ unconstrained fn mint_public_success() { } #[test] -unconstrained fn mint_public_failures() { +unconstrained fn mint_to_public_failures() { // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (env, token_contract_address, owner, recipient) = utils::setup(/* with_account_contracts */ false); @@ -23,9 +23,9 @@ unconstrained fn mint_public_failures() { // As non-minter let mint_amount = 10000; env.impersonate(recipient); - let mint_public_call_interface = - Token::at(token_contract_address).mint_public(owner, mint_amount); - env.assert_public_call_fails(mint_public_call_interface); + let mint_to_public_call_interface = + Token::at(token_contract_address).mint_to_public(owner, mint_amount); + env.assert_public_call_fails(mint_to_public_call_interface); utils::check_public_balance(token_contract_address, owner, 0); @@ -33,23 +33,23 @@ unconstrained fn mint_public_failures() { // Overflow recipient let mint_amount = 2.pow_32(128); - let mint_public_call_interface = - Token::at(token_contract_address).mint_public(owner, mint_amount); - env.assert_public_call_fails(mint_public_call_interface); + let mint_to_public_call_interface = + Token::at(token_contract_address).mint_to_public(owner, mint_amount); + env.assert_public_call_fails(mint_to_public_call_interface); utils::check_public_balance(token_contract_address, owner, 0); // Overflow total supply let mint_for_recipient_amount = 1000; - Token::at(token_contract_address).mint_public(recipient, mint_for_recipient_amount).call( + Token::at(token_contract_address).mint_to_public(recipient, mint_for_recipient_amount).call( &mut env.public(), ); let mint_amount = 2.pow_32(128) - mint_for_recipient_amount; - let mint_public_call_interface = - Token::at(token_contract_address).mint_public(owner, mint_amount); - env.assert_public_call_fails(mint_public_call_interface); + let mint_to_public_call_interface = + Token::at(token_contract_address).mint_to_public(owner, mint_amount); + env.assert_public_call_fails(mint_to_public_call_interface); utils::check_public_balance(token_contract_address, recipient, mint_for_recipient_amount); utils::check_public_balance(token_contract_address, owner, 0); diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/test/refunds.nr b/noir-projects/noir-contracts/contracts/token_contract/src/test/refunds.nr index 2990163baae..d326fe250be 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/test/refunds.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/test/refunds.nr @@ -7,7 +7,7 @@ use std::test::OracleMock; #[test] unconstrained fn setup_refund_success() { let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_private(true); + utils::setup_and_mint_to_private(true); // Renaming owner and recipient to match naming in Token let user = owner; @@ -65,7 +65,7 @@ unconstrained fn setup_refund_success() { #[test(should_fail_with = "Balance too low")] unconstrained fn setup_refund_insufficient_funded_amount() { let (env, token_contract_address, owner, recipient, _mint_amount) = - utils::setup_and_mint_private(true); + utils::setup_and_mint_to_private(true); // Renaming owner and recipient to match naming in Token let user = owner; diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer.nr b/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer.nr new file mode 100644 index 00000000000..24015869d66 --- /dev/null +++ b/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer.nr @@ -0,0 +1,64 @@ +use crate::test::utils; +use crate::Token; +use dep::authwit::cheatcodes as authwit_cheatcodes; +use dep::aztec::test::helpers::cheatcodes; + +#[test] +unconstrained fn transfer_private() { + // Setup without account contracts. We are not using authwits here, so dummy accounts are enough + let (env, token_contract_address, owner, recipient, mint_amount) = + utils::setup_and_mint_to_private(/* with_account_contracts */ false); + + // docs:start:txe_test_transfer_private + // Transfer tokens + let transfer_amount = 1000; + Token::at(token_contract_address).transfer(recipient, transfer_amount).call(&mut env.private()); + // docs:end:txe_test_transfer_private + // Check balances + utils::check_private_balance(token_contract_address, owner, mint_amount - transfer_amount); + utils::check_private_balance(token_contract_address, recipient, transfer_amount); +} + +#[test] +unconstrained fn transfer_private_to_self() { + // Setup without account contracts. We are not using authwits here, so dummy accounts are enough + let (env, token_contract_address, owner, _, mint_amount) = + utils::setup_and_mint_to_private(/* with_account_contracts */ false); + // Transfer tokens + let transfer_amount = 1000; + Token::at(token_contract_address).transfer(owner, transfer_amount).call(&mut env.private()); + + // Check balances + utils::check_private_balance(token_contract_address, owner, mint_amount); +} + +#[test] +unconstrained fn transfer_private_to_non_deployed_account() { + // Setup without account contracts. We are not using authwits here, so dummy accounts are enough + let (env, token_contract_address, owner, _, mint_amount) = + utils::setup_and_mint_to_private(/* with_account_contracts */ false); + let not_deployed = cheatcodes::create_account(); + // Transfer tokens + let transfer_amount = 1000; + Token::at(token_contract_address).transfer(not_deployed.address, transfer_amount).call( + &mut env.private(), + ); + + // Check balances + utils::check_private_balance(token_contract_address, owner, mint_amount - transfer_amount); + utils::check_private_balance( + token_contract_address, + not_deployed.address, + transfer_amount, + ); +} + +#[test(should_fail_with = "Balance too low")] +unconstrained fn transfer_private_failure_more_than_balance() { + // Setup without account contracts. We are not using authwits here, so dummy accounts are enough + let (env, token_contract_address, _, recipient, mint_amount) = + utils::setup_and_mint_to_private(/* with_account_contracts */ false); + // Transfer tokens + let transfer_amount = mint_amount + 1; + Token::at(token_contract_address).transfer(recipient, transfer_amount).call(&mut env.private()); +} diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_private.nr b/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_in_private.nr similarity index 51% rename from noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_private.nr rename to noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_in_private.nr index 11f32bba6ec..e7113a7aa44 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_private.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_in_private.nr @@ -1,68 +1,17 @@ use crate::test::utils; use crate::Token; use dep::authwit::cheatcodes as authwit_cheatcodes; -use dep::aztec::test::helpers::cheatcodes; - -#[test] -unconstrained fn transfer_private() { - // Setup without account contracts. We are not using authwits here, so dummy accounts are enough - let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ false); - - // docs:start:txe_test_transfer_private - // Transfer tokens - let transfer_amount = 1000; - Token::at(token_contract_address).transfer(recipient, transfer_amount).call(&mut env.private()); - // docs:end:txe_test_transfer_private - // Check balances - utils::check_private_balance(token_contract_address, owner, mint_amount - transfer_amount); - utils::check_private_balance(token_contract_address, recipient, transfer_amount); -} - -#[test] -unconstrained fn transfer_private_to_self() { - // Setup without account contracts. We are not using authwits here, so dummy accounts are enough - let (env, token_contract_address, owner, _, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ false); - // Transfer tokens - let transfer_amount = 1000; - Token::at(token_contract_address).transfer(owner, transfer_amount).call(&mut env.private()); - - // Check balances - utils::check_private_balance(token_contract_address, owner, mint_amount); -} - -#[test] -unconstrained fn transfer_private_to_non_deployed_account() { - // Setup without account contracts. We are not using authwits here, so dummy accounts are enough - let (env, token_contract_address, owner, _, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ false); - let not_deployed = cheatcodes::create_account(); - // Transfer tokens - let transfer_amount = 1000; - Token::at(token_contract_address).transfer(not_deployed.address, transfer_amount).call( - &mut env.private(), - ); - - // Check balances - utils::check_private_balance(token_contract_address, owner, mint_amount - transfer_amount); - utils::check_private_balance( - token_contract_address, - not_deployed.address, - transfer_amount, - ); -} #[test] unconstrained fn transfer_private_on_behalf_of_other() { // Setup with account contracts. Slower since we actually deploy them, but needed for authwits. let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ true); + utils::setup_and_mint_to_private(/* with_account_contracts */ true); // Add authwit // docs:start:private_authwit let transfer_amount = 1000; let transfer_private_from_call_interface = - Token::at(token_contract_address).transfer_from(owner, recipient, transfer_amount, 1); + Token::at(token_contract_address).transfer_in_private(owner, recipient, transfer_amount, 1); authwit_cheatcodes::add_private_authwit_from_call_interface( owner, recipient, @@ -78,26 +27,16 @@ unconstrained fn transfer_private_on_behalf_of_other() { utils::check_private_balance(token_contract_address, recipient, transfer_amount); } -#[test(should_fail_with = "Balance too low")] -unconstrained fn transfer_private_failure_more_than_balance() { - // Setup without account contracts. We are not using authwits here, so dummy accounts are enough - let (env, token_contract_address, _, recipient, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ false); - // Transfer tokens - let transfer_amount = mint_amount + 1; - Token::at(token_contract_address).transfer(recipient, transfer_amount).call(&mut env.private()); -} - // docs:start:fail_with_message #[test(should_fail_with = "invalid nonce")] unconstrained fn transfer_private_failure_on_behalf_of_self_non_zero_nonce() { // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (env, token_contract_address, owner, recipient, _) = - utils::setup_and_mint_private(/* with_account_contracts */ false); + utils::setup_and_mint_to_private(/* with_account_contracts */ false); // Add authwit let transfer_amount = 1000; let transfer_private_from_call_interface = - Token::at(token_contract_address).transfer_from(owner, recipient, transfer_amount, 1); + Token::at(token_contract_address).transfer_in_private(owner, recipient, transfer_amount, 1); authwit_cheatcodes::add_private_authwit_from_call_interface( owner, recipient, @@ -112,11 +51,11 @@ unconstrained fn transfer_private_failure_on_behalf_of_self_non_zero_nonce() { unconstrained fn transfer_private_failure_on_behalf_of_more_than_balance() { // Setup with account contracts. Slower since we actually deploy them, but needed for authwits. let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ true); + utils::setup_and_mint_to_private(/* with_account_contracts */ true); // Add authwit let transfer_amount = mint_amount + 1; let transfer_private_from_call_interface = - Token::at(token_contract_address).transfer_from(owner, recipient, transfer_amount, 1); + Token::at(token_contract_address).transfer_in_private(owner, recipient, transfer_amount, 1); authwit_cheatcodes::add_private_authwit_from_call_interface( owner, recipient, @@ -132,11 +71,11 @@ unconstrained fn transfer_private_failure_on_behalf_of_more_than_balance() { unconstrained fn transfer_private_failure_on_behalf_of_other_without_approval() { // Setup with account contracts. Slower since we actually deploy them, but needed for authwits. let (env, token_contract_address, owner, recipient, _) = - utils::setup_and_mint_private(/* with_account_contracts */ true); + utils::setup_and_mint_to_private(/* with_account_contracts */ true); // Add authwit let transfer_amount = 1000; let transfer_private_from_call_interface = - Token::at(token_contract_address).transfer_from(owner, recipient, transfer_amount, 1); + Token::at(token_contract_address).transfer_in_private(owner, recipient, transfer_amount, 1); // Impersonate recipient to perform the call env.impersonate(recipient); // Transfer tokens @@ -147,11 +86,11 @@ unconstrained fn transfer_private_failure_on_behalf_of_other_without_approval() unconstrained fn transfer_private_failure_on_behalf_of_other_wrong_caller() { // Setup with account contracts. Slower since we actually deploy them, but needed for authwits. let (env, token_contract_address, owner, recipient, _) = - utils::setup_and_mint_private(/* with_account_contracts */ true); + utils::setup_and_mint_to_private(/* with_account_contracts */ true); // Add authwit let transfer_amount = 1000; let transfer_private_from_call_interface = - Token::at(token_contract_address).transfer_from(owner, recipient, transfer_amount, 1); + Token::at(token_contract_address).transfer_in_private(owner, recipient, transfer_amount, 1); authwit_cheatcodes::add_private_authwit_from_call_interface( owner, owner, diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_public.nr b/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_in_public.nr similarity index 70% rename from noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_public.nr rename to noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_in_public.nr index 5dddac32573..aa8ba0376fb 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_public.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_in_public.nr @@ -7,10 +7,10 @@ use dep::aztec::oracle::random::random; unconstrained fn public_transfer() { // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ false); + utils::setup_and_mint_to_public(/* with_account_contracts */ false); // Transfer tokens let transfer_amount = mint_amount / 10; - Token::at(token_contract_address).transfer_public(owner, recipient, transfer_amount, 0).call( + Token::at(token_contract_address).transfer_in_public(owner, recipient, transfer_amount, 0).call( &mut env.public(), ); @@ -23,11 +23,11 @@ unconstrained fn public_transfer() { unconstrained fn public_transfer_to_self() { // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (env, token_contract_address, owner, _, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ false); + utils::setup_and_mint_to_public(/* with_account_contracts */ false); // Transfer tokens let transfer_amount = mint_amount / 10; // docs:start:call_public - Token::at(token_contract_address).transfer_public(owner, owner, transfer_amount, 0).call( + Token::at(token_contract_address).transfer_in_public(owner, owner, transfer_amount, 0).call( &mut env.public(), ); // docs:end:call_public @@ -39,19 +39,19 @@ unconstrained fn public_transfer_to_self() { unconstrained fn public_transfer_on_behalf_of_other() { // Setup with account contracts. Slower since we actually deploy them, but needed for authwits. let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ true); + utils::setup_and_mint_to_public(/* with_account_contracts */ true); let transfer_amount = mint_amount / 10; - let public_transfer_from_call_interface = - Token::at(token_contract_address).transfer_public(owner, recipient, transfer_amount, 1); + let public_transfer_in_private_call_interface = + Token::at(token_contract_address).transfer_in_public(owner, recipient, transfer_amount, 1); authwit_cheatcodes::add_public_authwit_from_call_interface( owner, recipient, - public_transfer_from_call_interface, + public_transfer_in_private_call_interface, ); // Impersonate recipient to perform the call env.impersonate(recipient); // Transfer tokens - public_transfer_from_call_interface.call(&mut env.public()); + public_transfer_in_private_call_interface.call(&mut env.public()); // Check balances utils::check_public_balance(token_contract_address, owner, mint_amount - transfer_amount); utils::check_public_balance(token_contract_address, recipient, transfer_amount); @@ -61,11 +61,11 @@ unconstrained fn public_transfer_on_behalf_of_other() { unconstrained fn public_transfer_failure_more_than_balance() { // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ false); + utils::setup_and_mint_to_public(/* with_account_contracts */ false); // Transfer tokens let transfer_amount = mint_amount + 1; let public_transfer_call_interface = - Token::at(token_contract_address).transfer_public(owner, recipient, transfer_amount, 0); + Token::at(token_contract_address).transfer_in_public(owner, recipient, transfer_amount, 0); // Try to transfer tokens public_transfer_call_interface.call(&mut env.public()); } @@ -74,10 +74,10 @@ unconstrained fn public_transfer_failure_more_than_balance() { unconstrained fn public_transfer_failure_on_behalf_of_self_non_zero_nonce() { // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ false); + utils::setup_and_mint_to_public(/* with_account_contracts */ false); // Transfer tokens let transfer_amount = mint_amount / 10; - let public_transfer_call_interface = Token::at(token_contract_address).transfer_public( + let public_transfer_call_interface = Token::at(token_contract_address).transfer_in_public( owner, recipient, transfer_amount, @@ -96,52 +96,52 @@ unconstrained fn public_transfer_failure_on_behalf_of_self_non_zero_nonce() { unconstrained fn public_transfer_failure_on_behalf_of_other_without_approval() { // Setup with account contracts. Slower since we actually deploy them, but needed for authwits. let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ true); + utils::setup_and_mint_to_public(/* with_account_contracts */ true); let transfer_amount = mint_amount / 10; - let public_transfer_from_call_interface = - Token::at(token_contract_address).transfer_public(owner, recipient, transfer_amount, 1); + let public_transfer_in_private_call_interface = + Token::at(token_contract_address).transfer_in_public(owner, recipient, transfer_amount, 1); // Impersonate recipient to perform the call env.impersonate(recipient); // Try to transfer tokens - public_transfer_from_call_interface.call(&mut env.public()); + public_transfer_in_private_call_interface.call(&mut env.public()); } #[test(should_fail_with = "attempt to subtract with underflow")] unconstrained fn public_transfer_failure_on_behalf_of_other_more_than_balance() { // Setup with account contracts. Slower since we actually deploy them, but needed for authwits. let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ true); + utils::setup_and_mint_to_public(/* with_account_contracts */ true); let transfer_amount = mint_amount + 1; // docs:start:public_authwit - let public_transfer_from_call_interface = - Token::at(token_contract_address).transfer_public(owner, recipient, transfer_amount, 1); + let public_transfer_in_private_call_interface = + Token::at(token_contract_address).transfer_in_public(owner, recipient, transfer_amount, 1); authwit_cheatcodes::add_public_authwit_from_call_interface( owner, recipient, - public_transfer_from_call_interface, + public_transfer_in_private_call_interface, ); // docs:end:public_authwit // Impersonate recipient to perform the call env.impersonate(recipient); // Try to transfer tokens - public_transfer_from_call_interface.call(&mut env.public()); + public_transfer_in_private_call_interface.call(&mut env.public()); } #[test(should_fail_with = "unauthorized")] unconstrained fn public_transfer_failure_on_behalf_of_other_wrong_caller() { // Setup with account contracts. Slower since we actually deploy them, but needed for authwits. let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_public(/* with_account_contracts */ true); + utils::setup_and_mint_to_public(/* with_account_contracts */ true); let transfer_amount = mint_amount / 10; - let public_transfer_from_call_interface = - Token::at(token_contract_address).transfer_public(owner, recipient, transfer_amount, 1); + let public_transfer_in_private_call_interface = + Token::at(token_contract_address).transfer_in_public(owner, recipient, transfer_amount, 1); authwit_cheatcodes::add_public_authwit_from_call_interface( owner, owner, - public_transfer_from_call_interface, + public_transfer_in_private_call_interface, ); // Impersonate recipient to perform the call env.impersonate(recipient); // Try to transfer tokens - public_transfer_from_call_interface.call(&mut env.public()); + public_transfer_in_private_call_interface.call(&mut env.public()); } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_to_private.nr b/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_to_private.nr index a02f4f3d4a2..52ff6d43915 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_to_private.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_to_private.nr @@ -11,11 +11,11 @@ use std::test::OracleMock; /// in `utils::setup_mint_and_transfer_to_private`. #[test] unconstrained fn transfer_to_private_internal_orchestration() { - // The transfer to private is done in `utils::setup_and_mint_private` and for this reason + // The transfer to private is done in `utils::setup_and_mint_to_private` and for this reason // in this test we just call it and check the outcome. // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (_, token_contract_address, user, _, amount) = - utils::setup_and_mint_private(/* with_account_contracts */ false); + utils::setup_and_mint_to_private(/* with_account_contracts */ false); // User's private balance should be equal to the amount utils::check_private_balance(token_contract_address, user, amount); @@ -27,7 +27,7 @@ unconstrained fn transfer_to_private_internal_orchestration() { unconstrained fn transfer_to_private_external_orchestration() { // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (env, token_contract_address, _, recipient, amount) = - utils::setup_and_mint_public(/* with_account_contracts */ false); + utils::setup_and_mint_to_public(/* with_account_contracts */ false); let note_randomness = random(); @@ -61,7 +61,7 @@ unconstrained fn transfer_to_private_external_orchestration() { unconstrained fn transfer_to_private_transfer_not_prepared() { // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (env, token_contract_address, _, _, amount) = - utils::setup_and_mint_public(/* with_account_contracts */ false); + utils::setup_and_mint_to_public(/* with_account_contracts */ false); // Transfer was not prepared so we can use random value for the hiding point slot let hiding_point_slot = random(); @@ -76,7 +76,7 @@ unconstrained fn transfer_to_private_transfer_not_prepared() { unconstrained fn transfer_to_private_failure_not_an_owner() { // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (env, token_contract_address, _, not_owner, amount) = - utils::setup_and_mint_public(/* with_account_contracts */ false); + utils::setup_and_mint_to_public(/* with_account_contracts */ false); // (For this specific test we could set a random value for the commitment and not do the call to `prepare...` // as the token balance check is before we use the value but that would made the test less robust against changes diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_to_public.nr b/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_to_public.nr index 63f84481c74..7789bf8aeb4 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_to_public.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_to_public.nr @@ -7,7 +7,7 @@ use dep::aztec::oracle::random::random; unconstrained fn transfer_to_public_on_behalf_of_self() { // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (env, token_contract_address, owner, _, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ false); + utils::setup_and_mint_to_private(/* with_account_contracts */ false); let transfer_to_public_amount = mint_amount / 10; Token::at(token_contract_address) @@ -24,7 +24,7 @@ unconstrained fn transfer_to_public_on_behalf_of_self() { #[test] unconstrained fn transfer_to_public_on_behalf_of_other() { let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ true); + utils::setup_and_mint_to_private(/* with_account_contracts */ true); let transfer_to_public_amount = mint_amount / 10; let transfer_to_public_call_interface = Token::at(token_contract_address).transfer_to_public( @@ -54,7 +54,7 @@ unconstrained fn transfer_to_public_on_behalf_of_other() { unconstrained fn transfer_to_public_failure_more_than_balance() { // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (env, token_contract_address, owner, _, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ false); + utils::setup_and_mint_to_private(/* with_account_contracts */ false); let transfer_to_public_amount = mint_amount + 1; Token::at(token_contract_address) @@ -66,7 +66,7 @@ unconstrained fn transfer_to_public_failure_more_than_balance() { unconstrained fn transfer_to_public_failure_on_behalf_of_self_non_zero_nonce() { // Setup without account contracts. We are not using authwits here, so dummy accounts are enough let (env, token_contract_address, owner, _, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ false); + utils::setup_and_mint_to_private(/* with_account_contracts */ false); let transfer_to_public_amount = mint_amount + 1; Token::at(token_contract_address) @@ -77,7 +77,7 @@ unconstrained fn transfer_to_public_failure_on_behalf_of_self_non_zero_nonce() { #[test(should_fail_with = "Balance too low")] unconstrained fn transfer_to_public_failure_on_behalf_of_other_more_than_balance() { let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ true); + utils::setup_and_mint_to_private(/* with_account_contracts */ true); let transfer_to_public_amount = mint_amount + 1; let transfer_to_public_call_interface = Token::at(token_contract_address).transfer_to_public( @@ -100,7 +100,7 @@ unconstrained fn transfer_to_public_failure_on_behalf_of_other_more_than_balance #[test(should_fail_with = "Authorization not found for message hash")] unconstrained fn transfer_to_public_failure_on_behalf_of_other_invalid_designated_caller() { let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ true); + utils::setup_and_mint_to_private(/* with_account_contracts */ true); let transfer_to_public_amount = mint_amount + 1; let transfer_to_public_call_interface = Token::at(token_contract_address).transfer_to_public( @@ -123,7 +123,7 @@ unconstrained fn transfer_to_public_failure_on_behalf_of_other_invalid_designate #[test(should_fail_with = "Authorization not found for message hash")] unconstrained fn transfer_to_public_failure_on_behalf_of_other_no_approval() { let (env, token_contract_address, owner, recipient, mint_amount) = - utils::setup_and_mint_private(/* with_account_contracts */ true); + utils::setup_and_mint_to_private(/* with_account_contracts */ true); let transfer_to_public_amount = mint_amount + 1; let transfer_to_public_call_interface = Token::at(token_contract_address).transfer_to_public( diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/test/utils.nr b/noir-projects/noir-contracts/contracts/token_contract/src/test/utils.nr index 893e659706f..9ccc8ed6b7b 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/test/utils.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/test/utils.nr @@ -44,19 +44,19 @@ pub unconstrained fn setup( (&mut env, token_contract_address, owner, recipient) } -pub unconstrained fn setup_and_mint_public( +pub unconstrained fn setup_and_mint_to_public( with_account_contracts: bool, ) -> (&mut TestEnvironment, AztecAddress, AztecAddress, AztecAddress, Field) { // Setup let (env, token_contract_address, owner, recipient) = setup(with_account_contracts); let mint_amount = 10000; // Mint some tokens - Token::at(token_contract_address).mint_public(owner, mint_amount).call(&mut env.public()); + Token::at(token_contract_address).mint_to_public(owner, mint_amount).call(&mut env.public()); (env, token_contract_address, owner, recipient, mint_amount) } -pub unconstrained fn setup_and_mint_private( +pub unconstrained fn setup_and_mint_to_private( with_account_contracts: bool, ) -> (&mut TestEnvironment, AztecAddress, AztecAddress, AztecAddress, Field) { // Setup the tokens and mint public balance @@ -64,12 +64,12 @@ pub unconstrained fn setup_and_mint_private( // Mint some tokens let mint_amount = 10000; - mint_private(env, token_contract_address, owner, mint_amount); + mint_to_private(env, token_contract_address, owner, mint_amount); (env, token_contract_address, owner, recipient, mint_amount) } -pub unconstrained fn mint_private( +pub unconstrained fn mint_to_private( env: &mut TestEnvironment, token_contract_address: AztecAddress, recipient: AztecAddress, diff --git a/noir-projects/noir-contracts/contracts/token_portal_content_hash_lib/src/lib.nr b/noir-projects/noir-contracts/contracts/token_portal_content_hash_lib/src/lib.nr index c31f6c4e0a9..682e80ce5f1 100644 --- a/noir-projects/noir-contracts/contracts/token_portal_content_hash_lib/src/lib.nr +++ b/noir-projects/noir-contracts/contracts/token_portal_content_hash_lib/src/lib.nr @@ -1,53 +1,57 @@ -// docs:start:mint_public_content_hash_nr +// docs:start:mint_to_public_content_hash_nr use dep::aztec::prelude::{AztecAddress, EthAddress}; use dep::aztec::protocol_types::hash::sha256_to_field; -// Computes a content hash of a deposit/mint_public message. +// Computes a content hash of a deposit/mint_to_public message. // Refer TokenPortal.sol for reference on L1. -pub fn get_mint_public_content_hash(owner: AztecAddress, amount: Field) -> Field { +pub fn get_mint_to_public_content_hash(owner: AztecAddress, amount: Field) -> Field { let mut hash_bytes = [0; 68]; let recipient_bytes:[u8; 32] = owner.to_field().to_be_bytes(); let amount_bytes:[u8; 32] = amount.to_be_bytes(); + // The purpose of including the following selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. + let selector = comptime { std::hash::keccak256("mint_to_public(bytes32,uint256)".as_bytes(), 31) }; + + for i in 0..4 { + hash_bytes[i] = selector[i]; + } + for i in 0..32 { hash_bytes[i + 4] = recipient_bytes[i]; hash_bytes[i + 36] = amount_bytes[i]; } - // Function selector: 0x3e87b9be keccak256('mint_public(bytes32,uint256)') - hash_bytes[0] = 0x3e; - hash_bytes[1] = 0x87; - hash_bytes[2] = 0xb9; - hash_bytes[3] = 0xbe; - let content_hash = sha256_to_field(hash_bytes); content_hash } -// docs:end:mint_public_content_hash_nr +// docs:end:mint_to_public_content_hash_nr -// docs:start:get_mint_private_content_hash -// Computes a content hash of a deposit/mint_private message. +// docs:start:get_mint_to_private_content_hash +// Computes a content hash of a deposit/mint_to_private message. // Refer TokenPortal.sol for reference on L1. -pub fn get_mint_private_content_hash( +pub fn get_mint_to_private_content_hash( amount: Field ) -> Field { let mut hash_bytes = [0; 36]; let amount_bytes:[u8; 32] = amount.to_be_bytes(); + // The purpose of including the following selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. + let selector = comptime { std::hash::keccak256("mint_to_private(uint256)".as_bytes(), 24) }; + + for i in 0..4 { + hash_bytes[i] = selector[i]; + } + for i in 0..32 { hash_bytes[i + 4] = amount_bytes[i]; } - // Function selector: 0xb81559e2 keccak256('mint_private(uint256)') - hash_bytes[0] = 0xb8; - hash_bytes[1] = 0x15; - hash_bytes[2] = 0x59; - hash_bytes[3] = 0xe2; - let content_hash = sha256_to_field(hash_bytes); content_hash } -// docs:end:get_mint_private_content_hash +// docs:end:get_mint_to_private_content_hash // docs:start:get_withdraw_content_hash // Computes a content hash of a withdraw message. @@ -61,11 +65,13 @@ pub fn get_withdraw_content_hash(recipient: EthAddress, amount: Field, caller_on let amount_bytes: [u8; 32] = amount.to_be_bytes(); let caller_on_l1_bytes: [u8; 32] = caller_on_l1.to_field().to_be_bytes(); - // 0x69328dec, selector for "withdraw(address,uint256,address)" - hash_bytes[0] = 0x69; - hash_bytes[1] = 0x32; - hash_bytes[2] = 0x8d; - hash_bytes[3] = 0xec; + // The purpose of including the following selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. + let selector = comptime { std::hash::keccak256("withdraw(address,uint256,address)".as_bytes(), 33) }; + + for i in 0..4 { + hash_bytes[i] = selector[i]; + } for i in 0..32 { hash_bytes[i + 4] = recipient_bytes[i]; diff --git a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr index f95c986983d..e1fd634121f 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr @@ -62,7 +62,7 @@ contract Uniswap { // Transfer funds to this contract Token::at(input_asset) - .transfer_public( + .transfer_in_public( sender, context.this_address(), input_amount, diff --git a/noir-projects/noir-contracts/contracts/uniswap_contract/src/util.nr b/noir-projects/noir-contracts/contracts/uniswap_contract/src/util.nr index a0e2ca12774..dc5605d7fd0 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/util.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/util.nr @@ -27,11 +27,19 @@ pub fn compute_swap_public_content_hash( secret_hash_for_L1_to_l2_message.to_be_bytes(); let caller_on_L1_bytes: [u8; 32] = caller_on_L1.to_field().to_be_bytes(); - // function selector: 0xf18186d8 keccak256("swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)") - hash_bytes[0] = 0xf1; - hash_bytes[1] = 0x81; - hash_bytes[2] = 0x86; - hash_bytes[3] = 0xd8; + // The purpose of including the following selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. + let selector = comptime { + std::hash::keccak256( + "swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)".as_bytes(), + 75, + ) + }; + + hash_bytes[0] = selector[0]; + hash_bytes[1] = selector[1]; + hash_bytes[2] = selector[2]; + hash_bytes[3] = selector[3]; for i in 0..32 { hash_bytes[i + 4] = input_token_portal_bytes[i]; @@ -73,11 +81,19 @@ pub fn compute_swap_private_content_hash( secret_hash_for_L1_to_l2_message.to_be_bytes(); let caller_on_L1_bytes: [u8; 32] = caller_on_L1.to_field().to_be_bytes(); - // function selector: 0x84e55078 keccak256("swap_private(address,uint256,uint24,address,uint256,bytes32,address)") - hash_bytes[0] = 0x84; - hash_bytes[1] = 0xe5; - hash_bytes[2] = 0x50; - hash_bytes[3] = 0x78; + // The purpose of including the following selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. + let selector = comptime { + std::hash::keccak256( + "swap_private(address,uint256,uint24,address,uint256,bytes32,address)".as_bytes(), + 68, + ) + }; + + hash_bytes[0] = selector[0]; + hash_bytes[1] = selector[1]; + hash_bytes[2] = selector[2]; + hash_bytes[3] = selector[3]; for i in 0..32 { hash_bytes[i + 4] = input_token_portal_bytes[i]; diff --git a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts index 13842e36131..144e307d7ea 100644 --- a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts @@ -53,9 +53,9 @@ export class PublicFeePaymentMethod implements FeePaymentMethod { { caller: this.paymentContract, action: { - name: 'transfer_public', + name: 'transfer_in_public', args: [this.wallet.getAddress().toField(), this.paymentContract.toField(), maxFee, nonce], - selector: FunctionSelector.fromSignature('transfer_public((Field),(Field),Field,Field)'), + selector: FunctionSelector.fromSignature('transfer_in_public((Field),(Field),Field,Field)'), type: FunctionType.PUBLIC, isStatic: false, to: this.asset, diff --git a/yarn-project/bot/src/bot.ts b/yarn-project/bot/src/bot.ts index f0eefb75daa..08cf67bbb38 100644 --- a/yarn-project/bot/src/bot.ts +++ b/yarn-project/bot/src/bot.ts @@ -59,7 +59,7 @@ export class Bot { calls.push(...times(privateTransfersPerTx, () => token.methods.transfer(recipient, TRANSFER_AMOUNT).request())); calls.push( ...times(publicTransfersPerTx, () => - token.methods.transfer_public(sender, recipient, TRANSFER_AMOUNT, 0).request(), + token.methods.transfer_in_public(sender, recipient, TRANSFER_AMOUNT, 0).request(), ), ); } else { diff --git a/yarn-project/bot/src/factory.ts b/yarn-project/bot/src/factory.ts index e59910700e5..b05e840fdb2 100644 --- a/yarn-project/bot/src/factory.ts +++ b/yarn-project/bot/src/factory.ts @@ -156,7 +156,7 @@ export class BotFactory { } if (isStandardToken && publicBalance < MIN_BALANCE) { this.log.info(`Minting public tokens for ${sender.toString()}`); - calls.push(token.methods.mint_public(sender, MINT_BALANCE).request()); + calls.push(token.methods.mint_to_public(sender, MINT_BALANCE).request()); } if (calls.length === 0) { this.log.info(`Skipping minting as ${sender.toString()} has enough tokens`); diff --git a/yarn-project/bot/src/utils.ts b/yarn-project/bot/src/utils.ts index 4c90afa8fba..0bc402c6a34 100644 --- a/yarn-project/bot/src/utils.ts +++ b/yarn-project/bot/src/utils.ts @@ -23,5 +23,5 @@ export async function getPrivateBalance(token: EasyPrivateTokenContract, who: Az } export function isStandardTokenContract(token: TokenContract | EasyPrivateTokenContract): token is TokenContract { - return 'mint_public' in token.methods; + return 'mint_to_public' in token.methods; } diff --git a/yarn-project/cli-wallet/test/flows/basic.sh b/yarn-project/cli-wallet/test/flows/basic.sh index 45f1053607b..31a59ad5bcc 100755 --- a/yarn-project/cli-wallet/test/flows/basic.sh +++ b/yarn-project/cli-wallet/test/flows/basic.sh @@ -8,7 +8,7 @@ AMOUNT=42 aztec-wallet create-account -a main aztec-wallet deploy token_contract@Token --args accounts:main Test TST 18 -f main -aztec-wallet send mint_public -ca last --args accounts:main $AMOUNT -f main +aztec-wallet send mint_to_public -ca last --args accounts:main $AMOUNT -f main RESULT=$(aztec-wallet simulate balance_of_public -ca last --args accounts:main -f main | grep "Simulation result:" | awk '{print $3}') section "Main account public balance is ${RESULT}" diff --git a/yarn-project/cli-wallet/test/flows/no_alias.sh b/yarn-project/cli-wallet/test/flows/no_alias.sh index 5925b115baf..0466501315e 100755 --- a/yarn-project/cli-wallet/test/flows/no_alias.sh +++ b/yarn-project/cli-wallet/test/flows/no_alias.sh @@ -8,7 +8,7 @@ AMOUNT=42 ACCOUNT_ADDRESS=$(aztec-wallet create-account -a main | grep "Address:" | awk '{print $2}') TOKEN_ADDRESS=$(aztec-wallet deploy ./target/token_contract-Token.json --args $ACCOUNT_ADDRESS Test TST 18 -f $ACCOUNT_ADDRESS | grep "Contract deployed at" | awk '{print $4}') -aztec-wallet send mint_public -c ./target/token_contract-Token.json -ca $TOKEN_ADDRESS --args $ACCOUNT_ADDRESS $AMOUNT -f $ACCOUNT_ADDRESS +aztec-wallet send mint_to_public -c ./target/token_contract-Token.json -ca $TOKEN_ADDRESS --args $ACCOUNT_ADDRESS $AMOUNT -f $ACCOUNT_ADDRESS RESULT=$(aztec-wallet simulate balance_of_public -c ./target/token_contract-Token.json -ca $TOKEN_ADDRESS --args $ACCOUNT_ADDRESS -f $ACCOUNT_ADDRESS | grep "Simulation result:" | awk '{print $3}') section "Main account public balance is ${RESULT}" diff --git a/yarn-project/cli-wallet/test/flows/private_authwit_transfer.sh b/yarn-project/cli-wallet/test/flows/private_authwit_transfer.sh index 693998b0925..abcf7c09016 100755 --- a/yarn-project/cli-wallet/test/flows/private_authwit_transfer.sh +++ b/yarn-project/cli-wallet/test/flows/private_authwit_transfer.sh @@ -7,15 +7,15 @@ test_title "Private transfer on behalf of other" MINT_AMOUNT=42 TRANSFER_AMOUNT=21 -source $TEST_FOLDER/token_utils/create_main_and_mint_private.sh $MINT_AMOUNT +source $TEST_FOLDER/token_utils/create_main_and_mint_to_private.sh $MINT_AMOUNT aztec-wallet create-account -a operator aztec-wallet create-secret -a auth_nonce -aztec-wallet create-authwit transfer_from operator -ca token --args accounts:main accounts:operator $TRANSFER_AMOUNT secrets:auth_nonce -f main +aztec-wallet create-authwit transfer_in_private operator -ca token --args accounts:main accounts:operator $TRANSFER_AMOUNT secrets:auth_nonce -f main aztec-wallet add-authwit authwits:last main -f operator -aztec-wallet send transfer_from -ca token --args accounts:main accounts:operator $TRANSFER_AMOUNT secrets:auth_nonce -f operator +aztec-wallet send transfer_in_private -ca token --args accounts:main accounts:operator $TRANSFER_AMOUNT secrets:auth_nonce -f operator RESULT_MAIN=$(aztec-wallet simulate balance_of_private -ca token --args accounts:main -f main | grep "Simulation result:" | awk '{print $3}') RESULT_RECIPIENT=$(aztec-wallet simulate balance_of_private -ca token --args accounts:operator -f operator | grep "Simulation result:" | awk '{print $3}') diff --git a/yarn-project/cli-wallet/test/flows/public_authwit_transfer.sh b/yarn-project/cli-wallet/test/flows/public_authwit_transfer.sh index 4d355bbca85..89634c47437 100755 --- a/yarn-project/cli-wallet/test/flows/public_authwit_transfer.sh +++ b/yarn-project/cli-wallet/test/flows/public_authwit_transfer.sh @@ -7,14 +7,14 @@ test_title "Public transfer on behalf of other" MINT_AMOUNT=42 TRANSFER_AMOUNT=21 -source $TEST_FOLDER/token_utils/create_main_and_mint_public.sh $MINT_AMOUNT +source $TEST_FOLDER/token_utils/create_main_and_mint_to_public.sh $MINT_AMOUNT aztec-wallet create-account -a operator aztec-wallet create-secret -a auth_nonce -aztec-wallet authorize-action transfer_public operator -ca token --args accounts:main accounts:operator $TRANSFER_AMOUNT secrets:auth_nonce -f main +aztec-wallet authorize-action transfer_in_public operator -ca token --args accounts:main accounts:operator $TRANSFER_AMOUNT secrets:auth_nonce -f main -aztec-wallet send transfer_public -ca token --args accounts:main accounts:operator $TRANSFER_AMOUNT secrets:auth_nonce -f operator +aztec-wallet send transfer_in_public -ca token --args accounts:main accounts:operator $TRANSFER_AMOUNT secrets:auth_nonce -f operator RESULT_MAIN=$(aztec-wallet simulate balance_of_public -ca token --args accounts:main -f main | grep "Simulation result:" | awk '{print $3}') RESULT_RECIPIENT=$(aztec-wallet simulate balance_of_public -ca token --args accounts:operator -f operator | grep "Simulation result:" | awk '{print $3}') diff --git a/yarn-project/cli-wallet/test/flows/shield_and_transfer.sh b/yarn-project/cli-wallet/test/flows/shield_and_transfer.sh index 7e27e6eb790..e54da2fa649 100755 --- a/yarn-project/cli-wallet/test/flows/shield_and_transfer.sh +++ b/yarn-project/cli-wallet/test/flows/shield_and_transfer.sh @@ -7,7 +7,7 @@ test_title "Shield and private transfer" MINT_AMOUNT=42 TRANSFER_AMOUNT=21 -source $TEST_FOLDER/token_utils/create_main_and_mint_private.sh $MINT_AMOUNT +source $TEST_FOLDER/token_utils/create_main_and_mint_to_private.sh $MINT_AMOUNT aztec-wallet create-account -a recipient diff --git a/yarn-project/cli-wallet/test/flows/token_utils/create_main_and_mint_public.sh b/yarn-project/cli-wallet/test/flows/token_utils/create_main_and_mint_public.sh index 20d49f06817..862b2d04fe9 100644 --- a/yarn-project/cli-wallet/test/flows/token_utils/create_main_and_mint_public.sh +++ b/yarn-project/cli-wallet/test/flows/token_utils/create_main_and_mint_public.sh @@ -2,7 +2,7 @@ section "Deploying contracts and minting tokens publicly" aztec-wallet create-account -a main aztec-wallet deploy token_contract@Token --args accounts:main Test TST 18 -f main -a token -aztec-wallet send mint_public -ca token --args accounts:main $1 -f main +aztec-wallet send mint_to_public -ca token --args accounts:main $1 -f main RESULT_MAIN=$(aztec-wallet simulate balance_of_public -ca token --args accounts:main -f main | grep "Simulation result:" | awk '{print $3}') diff --git a/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts index 7148d1be742..5aa2b0c33fc 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts @@ -115,7 +115,7 @@ describe('benchmarks/proving', () => { const from = initialSchnorrWallet.getAddress(); // we are setting from to initial schnorr wallet here because of TODO(#9887) await Promise.all([ initialGasContract.methods.claim(initialFpContract.address, 1e12, claimSecret, messageLeafIndex).send().wait(), - initialTokenContract.methods.mint_public(initialSchnorrWallet.getAddress(), 1e12).send().wait(), + initialTokenContract.methods.mint_to_public(initialSchnorrWallet.getAddress(), 1e12).send().wait(), initialTokenContract.methods.mint_to_private(from, initialSchnorrWallet.getAddress(), 1e12).send().wait(), ]); }); @@ -183,7 +183,7 @@ describe('benchmarks/proving', () => { ctx.logger.info('+----------------------+'); const fnCalls = [ - (await getTokenContract(0)).methods.transfer_public(schnorrWalletAddress.address, recipient.address, 1000, 0), + (await getTokenContract(0)).methods.transfer_in_public(schnorrWalletAddress.address, recipient.address, 1000, 0), (await getTokenContract(1)).methods.transfer(recipient.address, 1000), // (await getTestContractOnPXE(2)).methods.emit_unencrypted(43), // (await getTestContractOnPXE(3)).methods.create_l2_to_l1_message_public(45, 46, EthAddress.random()), diff --git a/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts index ab248cca561..f831e265c37 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts @@ -73,7 +73,7 @@ describe('benchmarks/tx_size_fees', () => { ]); const from = aliceWallet.getAddress(); // we are setting from to Alice here because of TODO(#9887) await token.methods.mint_to_private(from, aliceWallet.getAddress(), 100e9).send().wait(); - await token.methods.mint_public(aliceWallet.getAddress(), 100e9).send().wait(); + await token.methods.mint_to_public(aliceWallet.getAddress(), 100e9).send().wait(); }); it.each<[string, () => FeePaymentMethod | undefined /*bigint*/]>([ diff --git a/yarn-project/end-to-end/src/composed/docs_examples.test.ts b/yarn-project/end-to-end/src/composed/docs_examples.test.ts index 129717f8504..e90135cb67c 100644 --- a/yarn-project/end-to-end/src/composed/docs_examples.test.ts +++ b/yarn-project/end-to-end/src/composed/docs_examples.test.ts @@ -42,7 +42,7 @@ describe('docs_examples', () => { // docs:end:full_deploy // docs:start:send_transaction - const _tx = await contract.methods.mint_public(wallet.getAddress(), 1).send().wait(); + const _tx = await contract.methods.mint_to_public(wallet.getAddress(), 1).send().wait(); // docs:end:send_transaction // docs:start:simulate_function diff --git a/yarn-project/end-to-end/src/e2e_block_building.test.ts b/yarn-project/end-to-end/src/e2e_block_building.test.ts index 605644f13fb..88bfd6a1b23 100644 --- a/yarn-project/end-to-end/src/e2e_block_building.test.ts +++ b/yarn-project/end-to-end/src/e2e_block_building.test.ts @@ -400,7 +400,7 @@ describe('e2e_block_building', () => { logger.info('Spamming the network with public txs'); const txs = []; for (let i = 0; i < 30; i++) { - const tx = token.methods.mint_public(owner.getAddress(), 10n); + const tx = token.methods.mint_to_public(owner.getAddress(), 10n); txs.push(tx.send({ skipPublicSimulation: false })); } diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_failure_cases.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_failure_cases.test.ts index cac9f75b106..f91f0ab555e 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_failure_cases.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_failure_cases.test.ts @@ -52,7 +52,7 @@ describe('e2e_cross_chain_messaging token_bridge_failure_cases', () => { // Wrong message hash const wrongBridgeAmount = bridgeAmount + 1n; const wrongMessageContent = sha256ToField([ - Buffer.from(toFunctionSelector('mint_private(uint256)').substring(2), 'hex'), + Buffer.from(toFunctionSelector('mint_to_private(uint256)').substring(2), 'hex'), new Fr(wrongBridgeAmount), ]); diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts index 87af389c0e3..b55cedc1e02 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_private.test.ts @@ -72,7 +72,7 @@ describe('e2e_cross_chain_messaging token_bridge_private', () => { const nonce = Fr.random(); await user1Wallet.createAuthWit({ caller: l2Bridge.address, - action: l2Token.methods.burn(ownerAddress, withdrawAmount, nonce), + action: l2Token.methods.burn_private(ownerAddress, withdrawAmount, nonce), }); // docs:end:authwit_to_another_sc diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index 08a49bced6d..eeb91f00f72 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -148,7 +148,7 @@ describe('e2e_crowdfunding_and_claim', () => { { const action = donationToken .withWallet(donorWallets[0]) - .methods.transfer_from(donorWallets[0].getAddress(), crowdfundingContract.address, donationAmount, 0); + .methods.transfer_in_private(donorWallets[0].getAddress(), crowdfundingContract.address, donationAmount, 0); const witness = await donorWallets[0].createAuthWit({ caller: crowdfundingContract.address, action }); await donorWallets[0].addAuthWitness(witness); } @@ -219,7 +219,7 @@ describe('e2e_crowdfunding_and_claim', () => { { const action = donationToken .withWallet(donorWallets[1]) - .methods.transfer_from(donorWallets[1].getAddress(), crowdfundingContract.address, donationAmount, 0); + .methods.transfer_in_private(donorWallets[1].getAddress(), crowdfundingContract.address, donationAmount, 0); const witness = await donorWallets[1].createAuthWit({ caller: crowdfundingContract.address, action }); await donorWallets[1].addAuthWitness(witness); } @@ -311,7 +311,7 @@ describe('e2e_crowdfunding_and_claim', () => { // 1) We add authwit so that the Crowdfunding contract can transfer donor's DNT const action = donationToken .withWallet(donorWallets[1]) - .methods.transfer_from(donorWallets[1].getAddress(), crowdfundingContract.address, donationAmount, 0); + .methods.transfer_in_private(donorWallets[1].getAddress(), crowdfundingContract.address, donationAmount, 0); const witness = await donorWallets[1].createAuthWit({ caller: crowdfundingContract.address, action }); await donorWallets[1].addAuthWitness(witness); @@ -357,7 +357,7 @@ describe('e2e_crowdfunding_and_claim', () => { { const action = donationToken .withWallet(donorWallets[1]) - .methods.transfer_from(donorWallets[1].getAddress(), crowdfundingContract.address, donationAmount, 0); + .methods.transfer_in_private(donorWallets[1].getAddress(), crowdfundingContract.address, donationAmount, 0); const witness = await donorWallets[1].createAuthWit({ caller: crowdfundingContract.address, action }); await donorWallets[1].addAuthWitness(witness); } diff --git a/yarn-project/end-to-end/src/e2e_fees/account_init.test.ts b/yarn-project/end-to-end/src/e2e_fees/account_init.test.ts index b114bd07fd6..6685ff2f5c2 100644 --- a/yarn-project/end-to-end/src/e2e_fees/account_init.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/account_init.test.ts @@ -134,7 +134,7 @@ describe('e2e_fees account_init', () => { it('pays publicly through an FPC', async () => { const mintedBananas = BigInt(1e12); - await bananaCoin.methods.mint_public(bobsAddress, mintedBananas).send().wait(); + await bananaCoin.methods.mint_to_public(bobsAddress, mintedBananas).send().wait(); const paymentMethod = new PublicFeePaymentMethod(bananaCoin.address, bananaFPC.address, bobsWallet); const tx = await bobsAccountManager @@ -192,7 +192,11 @@ describe('e2e_fees account_init', () => { await expect(t.getGasBalanceFn(aliceAddress)).resolves.toEqual([alicesInitialGas - tx.transactionFee!]); // bob can now use his wallet for sending txs - await bananaCoin.withWallet(bobsWallet).methods.transfer_public(bobsAddress, aliceAddress, 0n, 0n).send().wait(); + await bananaCoin + .withWallet(bobsWallet) + .methods.transfer_in_public(bobsAddress, aliceAddress, 0n, 0n) + .send() + .wait(); }); }); }); diff --git a/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts b/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts index 6511ad56466..b567a385c43 100644 --- a/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts @@ -207,7 +207,7 @@ describe('e2e_fees dapp_subscription', () => { async function subscribe(paymentMethod: FeePaymentMethod, blockDelta: number = 5, txCount: number = 4) { const nonce = Fr.random(); - const action = bananaCoin.methods.transfer_from(aliceAddress, bobAddress, t.SUBSCRIPTION_AMOUNT, nonce); + const action = bananaCoin.methods.transfer_in_private(aliceAddress, bobAddress, t.SUBSCRIPTION_AMOUNT, nonce); await aliceWallet.createAuthWit({ caller: subscriptionContract.address, action }); return subscriptionContract diff --git a/yarn-project/end-to-end/src/e2e_fees/failures.test.ts b/yarn-project/end-to-end/src/e2e_fees/failures.test.ts index d96da87f4b1..18058dba944 100644 --- a/yarn-project/end-to-end/src/e2e_fees/failures.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/failures.test.ts @@ -51,7 +51,7 @@ describe('e2e_fees failures', () => { await expect( bananaCoin.methods // still use a public transfer so as to fail in the public app logic phase - .transfer_public(aliceAddress, sequencerAddress, outrageousPublicAmountAliceDoesNotHave, 0) + .transfer_in_public(aliceAddress, sequencerAddress, outrageousPublicAmountAliceDoesNotHave, 0) .send({ fee: { gasSettings, @@ -79,7 +79,7 @@ describe('e2e_fees failures', () => { const currentSequencerL1Gas = await t.getCoinbaseBalance(); const txReceipt = await bananaCoin.methods - .transfer_public(aliceAddress, sequencerAddress, outrageousPublicAmountAliceDoesNotHave, 0) + .transfer_in_public(aliceAddress, sequencerAddress, outrageousPublicAmountAliceDoesNotHave, 0) .send({ skipPublicSimulation: true, fee: { @@ -143,11 +143,11 @@ describe('e2e_fees failures', () => { sequencerAddress, ); - await bananaCoin.methods.mint_public(aliceAddress, publicMintedAlicePublicBananas).send().wait(); + await bananaCoin.methods.mint_to_public(aliceAddress, publicMintedAlicePublicBananas).send().wait(); // if we simulate locally, it throws an error await expect( bananaCoin.methods - .transfer_public(aliceAddress, sequencerAddress, outrageousPublicAmountAliceDoesNotHave, 0) + .transfer_in_public(aliceAddress, sequencerAddress, outrageousPublicAmountAliceDoesNotHave, 0) .send({ fee: { gasSettings, @@ -176,7 +176,7 @@ describe('e2e_fees failures', () => { // if we skip simulation, it includes the failed TX const txReceipt = await bananaCoin.methods - .transfer_public(aliceAddress, sequencerAddress, outrageousPublicAmountAliceDoesNotHave, 0) + .transfer_in_public(aliceAddress, sequencerAddress, outrageousPublicAmountAliceDoesNotHave, 0) .send({ skipPublicSimulation: true, fee: { @@ -213,7 +213,7 @@ describe('e2e_fees failures', () => { // simulation throws an error when setup fails await expect( bananaCoin.methods - .transfer_public(aliceAddress, sequencerAddress, OutrageousPublicAmountAliceDoesNotHave, 0) + .transfer_in_public(aliceAddress, sequencerAddress, OutrageousPublicAmountAliceDoesNotHave, 0) .send({ fee: { gasSettings, @@ -226,7 +226,7 @@ describe('e2e_fees failures', () => { // so does the sequencer await expect( bananaCoin.methods - .transfer_public(aliceAddress, sequencerAddress, OutrageousPublicAmountAliceDoesNotHave, 0) + .transfer_in_public(aliceAddress, sequencerAddress, OutrageousPublicAmountAliceDoesNotHave, 0) .send({ skipPublicSimulation: true, fee: { @@ -258,7 +258,7 @@ describe('e2e_fees failures', () => { sequencerAddress, ); - await bananaCoin.methods.mint_public(aliceAddress, publicMintedAlicePublicBananas).send().wait(); + await bananaCoin.methods.mint_to_public(aliceAddress, publicMintedAlicePublicBananas).send().wait(); const badGas = GasSettings.from({ gasLimits: gasSettings.gasLimits, @@ -268,7 +268,7 @@ describe('e2e_fees failures', () => { await expect( bananaCoin.methods - .mint_public(aliceAddress, 1n) // random operation + .mint_to_public(aliceAddress, 1n) // random operation .send({ fee: { gasSettings: badGas, @@ -279,7 +279,7 @@ describe('e2e_fees failures', () => { ).rejects.toThrow(); const receipt = await bananaCoin.methods - .mint_public(aliceAddress, 1n) // random operation + .mint_to_public(aliceAddress, 1n) // random operation .send({ skipPublicSimulation: true, fee: { @@ -329,9 +329,9 @@ class BuggedSetupFeePaymentMethod extends PublicFeePaymentMethod { { caller: this.paymentContract, action: { - name: 'transfer_public', + name: 'transfer_in_public', args: [this.wallet.getAddress().toField(), this.paymentContract.toField(), maxFee, nonce], - selector: FunctionSelector.fromSignature('transfer_public((Field),(Field),Field,Field)'), + selector: FunctionSelector.fromSignature('transfer_in_public((Field),(Field),Field,Field)'), type: FunctionType.PUBLIC, isStatic: false, to: this.asset, diff --git a/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts b/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts index 6956bcf24a9..dcaabbf882b 100644 --- a/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts @@ -43,7 +43,7 @@ describe('e2e_fees Fee Juice payments', () => { it('fails to send a tx', async () => { await expect( bananaCoin.methods - .transfer_public(aliceAddress, bobAddress, 1n, 0n) + .transfer_in_public(aliceAddress, bobAddress, 1n, 0n) .send({ fee: { gasSettings, paymentMethod } }) .wait(), ).rejects.toThrow(/Not enough balance for fee payer to pay for transaction/i); @@ -53,7 +53,7 @@ describe('e2e_fees Fee Juice payments', () => { const claim = await t.feeJuiceBridgeTestHarness.prepareTokensOnL1(t.INITIAL_GAS_BALANCE, aliceAddress); const paymentMethod = new FeeJuicePaymentMethodWithClaim(aliceAddress, claim); const receipt = await bananaCoin.methods - .transfer_public(aliceAddress, bobAddress, 1n, 0n) + .transfer_in_public(aliceAddress, bobAddress, 1n, 0n) .send({ fee: { gasSettings, paymentMethod } }) .wait(); const endBalance = await feeJuiceContract.methods.balance_of_public(aliceAddress).simulate(); @@ -72,7 +72,7 @@ describe('e2e_fees Fee Juice payments', () => { it('sends tx with payment in Fee Juice with public calls', async () => { const initialBalance = await feeJuiceContract.methods.balance_of_public(aliceAddress).simulate(); const { transactionFee } = await bananaCoin.methods - .transfer_public(aliceAddress, bobAddress, 1n, 0n) + .transfer_in_public(aliceAddress, bobAddress, 1n, 0n) .send({ fee: { gasSettings, paymentMethod } }) .wait(); expect(transactionFee).toBeGreaterThan(0n); diff --git a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts index fad11c79369..d69ff14f11b 100644 --- a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts @@ -270,7 +270,7 @@ export class FeesTest { 'fund_alice', async () => { await this.mintPrivateBananas(this.ALICE_INITIAL_BANANAS, this.aliceAddress); - await this.bananaCoin.methods.mint_public(this.aliceAddress, this.ALICE_INITIAL_BANANAS).send().wait(); + await this.bananaCoin.methods.mint_to_public(this.aliceAddress, this.ALICE_INITIAL_BANANAS).send().wait(); }, () => Promise.resolve(), ); diff --git a/yarn-project/end-to-end/src/e2e_fees/gas_estimation.test.ts b/yarn-project/end-to-end/src/e2e_fees/gas_estimation.test.ts index 862bdc387cb..28e20fc79e5 100644 --- a/yarn-project/end-to-end/src/e2e_fees/gas_estimation.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/gas_estimation.test.ts @@ -42,7 +42,7 @@ describe('e2e_fees gas_estimation', () => { await t.teardown(); }); - const makeTransferRequest = () => bananaCoin.methods.transfer_public(aliceAddress, bobAddress, 1n, 0n); + const makeTransferRequest = () => bananaCoin.methods.transfer_in_public(aliceAddress, bobAddress, 1n, 0n); // Sends two tx with transfers of public tokens: one with estimateGas on, one with estimateGas off const sendTransfers = (paymentMethod: FeePaymentMethod) => diff --git a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts index a80b6264203..4b0c502e1e2 100644 --- a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts @@ -100,7 +100,7 @@ describe('e2e_lending_contract', () => { const mintAmount = 10000n; for (const asset of assets) { await Promise.all([ - asset.methods.mint_public(lendingAccount.address, mintAmount).send().wait(), + asset.methods.mint_to_public(lendingAccount.address, mintAmount).send().wait(), mintTokensToPrivate(asset, wallet, lendingAccount.address, mintAmount), ]); } @@ -201,7 +201,7 @@ describe('e2e_lending_contract', () => { .setPublicAuthWit( { caller: lendingContract.address, - action: collateralAsset.methods.transfer_public( + action: collateralAsset.methods.transfer_in_public( lendingAccount.address, lendingContract.address, depositAmount, @@ -271,7 +271,7 @@ describe('e2e_lending_contract', () => { const nonce = Fr.random(); await wallet.createAuthWit({ caller: lendingContract.address, - action: stableCoin.methods.burn(lendingAccount.address, repayAmount, nonce), + action: stableCoin.methods.burn_private(lendingAccount.address, repayAmount, nonce), }); await lendingSim.progressSlots(SLOT_JUMP); @@ -295,7 +295,7 @@ describe('e2e_lending_contract', () => { const nonce = Fr.random(); await wallet.createAuthWit({ caller: lendingContract.address, - action: stableCoin.methods.burn(lendingAccount.address, repayAmount, nonce), + action: stableCoin.methods.burn_private(lendingAccount.address, repayAmount, nonce), }); await lendingSim.progressSlots(SLOT_JUMP); diff --git a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts b/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts index 2df25d15ab6..9007b2e0f7a 100644 --- a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts +++ b/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts @@ -336,7 +336,7 @@ export class FullProverTest { this.logger.verbose(`Minting ${privateAmount + publicAmount} publicly...`); await asset.methods - .mint_public(accounts[0].address, privateAmount + publicAmount) + .mint_to_public(accounts[0].address, privateAmount + publicAmount) .send() .wait(waitOpts); diff --git a/yarn-project/end-to-end/src/e2e_prover/full.test.ts b/yarn-project/end-to-end/src/e2e_prover/full.test.ts index 15662b97106..6bc9e3f3005 100644 --- a/yarn-project/end-to-end/src/e2e_prover/full.test.ts +++ b/yarn-project/end-to-end/src/e2e_prover/full.test.ts @@ -74,7 +74,7 @@ describe('full_prover', () => { const publicBalance = await provenAssets[1].methods.balance_of_public(sender).simulate(); const publicSendAmount = publicBalance / 10n; expect(publicSendAmount).toBeGreaterThan(0n); - const publicInteraction = provenAssets[1].methods.transfer_public(sender, recipient, publicSendAmount, 0); + const publicInteraction = provenAssets[1].methods.transfer_in_public(sender, recipient, publicSendAmount, 0); // Prove them logger.info(`Proving txs`); @@ -166,7 +166,7 @@ describe('full_prover', () => { } const privateInteraction = t.fakeProofsAsset.methods.transfer(recipient, 1n); - const publicInteraction = t.fakeProofsAsset.methods.transfer_public(sender, recipient, 1n, 0); + const publicInteraction = t.fakeProofsAsset.methods.transfer_in_public(sender, recipient, 1n, 0); const sentPrivateTx = privateInteraction.send({ skipPublicSimulation: true }); const sentPublicTx = publicInteraction.send({ skipPublicSimulation: true }); diff --git a/yarn-project/end-to-end/src/e2e_synching.test.ts b/yarn-project/end-to-end/src/e2e_synching.test.ts index af1963d24b9..743c780bda8 100644 --- a/yarn-project/end-to-end/src/e2e_synching.test.ts +++ b/yarn-project/end-to-end/src/e2e_synching.test.ts @@ -172,7 +172,7 @@ class TestVariant { if (this.txComplexity == TxComplexity.PublicTransfer) { await Promise.all( this.wallets.map(w => - this.token.methods.mint_public(w.getAddress(), MINT_AMOUNT).send().wait({ timeout: 600 }), + this.token.methods.mint_to_public(w.getAddress(), MINT_AMOUNT).send().wait({ timeout: 600 }), ), ); } @@ -219,7 +219,7 @@ class TestVariant { const sender = this.wallets[i].getAddress(); const recipient = this.wallets[(i + 1) % this.txCount].getAddress(); const tk = await TokenContract.at(this.token.address, this.wallets[i]); - txs.push(tk.methods.transfer_public(sender, recipient, 1n, 0).send()); + txs.push(tk.methods.transfer_in_public(sender, recipient, 1n, 0).send()); } return txs; } else if (this.txComplexity == TxComplexity.Spam) { diff --git a/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts index ed23358282e..0b7b10306bf 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts @@ -116,7 +116,7 @@ describe('e2e_token_contract burn', () => { const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); - await asset.methods.burn(accounts[0].address, amount, 0).send().wait(); + await asset.methods.burn_private(accounts[0].address, amount, 0).send().wait(); tokenSim.burnPrivate(accounts[0].address, amount); }); @@ -127,7 +127,7 @@ describe('e2e_token_contract burn', () => { expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); + const action = asset.withWallet(wallets[1]).methods.burn_private(accounts[0].address, amount, nonce); // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. @@ -137,11 +137,11 @@ describe('e2e_token_contract burn', () => { // We give wallets[1] access to wallets[0]'s notes to burn the note. wallets[1].setScopes([wallets[1].getAddress(), wallets[0].getAddress()]); - await asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce).send().wait(); + await asset.withWallet(wallets[1]).methods.burn_private(accounts[0].address, amount, nonce).send().wait(); tokenSim.burnPrivate(accounts[0].address, amount); // Perform the transfer again, should fail - const txReplay = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce).send(); + const txReplay = asset.withWallet(wallets[1]).methods.burn_private(accounts[0].address, amount, nonce).send(); await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); }); @@ -150,7 +150,7 @@ describe('e2e_token_contract burn', () => { const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); const amount = balance0 + 1n; expect(amount).toBeGreaterThan(0n); - await expect(asset.methods.burn(accounts[0].address, amount, 0).simulate()).rejects.toThrow( + await expect(asset.methods.burn_private(accounts[0].address, amount, 0).simulate()).rejects.toThrow( 'Assertion failed: Balance too low', ); }); @@ -159,7 +159,7 @@ describe('e2e_token_contract burn', () => { const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); const amount = balance0 - 1n; expect(amount).toBeGreaterThan(0n); - await expect(asset.methods.burn(accounts[0].address, amount, 1).simulate()).rejects.toThrow( + await expect(asset.methods.burn_private(accounts[0].address, amount, 1).simulate()).rejects.toThrow( 'Assertion failed: invalid nonce', ); }); @@ -171,7 +171,7 @@ describe('e2e_token_contract burn', () => { expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); + const action = asset.withWallet(wallets[1]).methods.burn_private(accounts[0].address, amount, nonce); // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. @@ -188,7 +188,7 @@ describe('e2e_token_contract burn', () => { expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); + const action = asset.withWallet(wallets[1]).methods.burn_private(accounts[0].address, amount, nonce); const messageHash = computeAuthWitMessageHash( { caller: accounts[1].address, action: action.request() }, { chainId: wallets[0].getChainId(), version: wallets[0].getVersion() }, @@ -209,7 +209,7 @@ describe('e2e_token_contract burn', () => { expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[2]).methods.burn(accounts[0].address, amount, nonce); + const action = asset.withWallet(wallets[2]).methods.burn_private(accounts[0].address, amount, nonce); const expectedMessageHash = computeAuthWitMessageHash( { caller: accounts[2].address, action: action.request() }, { chainId: wallets[0].getChainId(), version: wallets[0].getVersion() }, diff --git a/yarn-project/end-to-end/src/e2e_token_contract/minting.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/minting.test.ts index 484f6288533..b2fcc69add9 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/minting.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/minting.test.ts @@ -22,7 +22,7 @@ describe('e2e_token_contract minting', () => { describe('Public', () => { it('as minter', async () => { const amount = 10000n; - await asset.methods.mint_public(accounts[0].address, amount).send().wait(); + await asset.methods.mint_to_public(accounts[0].address, amount).send().wait(); tokenSim.mintPublic(accounts[0].address, amount); expect(await asset.methods.balance_of_public(accounts[0].address).simulate()).toEqual( @@ -35,27 +35,27 @@ describe('e2e_token_contract minting', () => { it('as non-minter', async () => { const amount = 10000n; await expect( - asset.withWallet(wallets[1]).methods.mint_public(accounts[0].address, amount).simulate(), + asset.withWallet(wallets[1]).methods.mint_to_public(accounts[0].address, amount).simulate(), ).rejects.toThrow('Assertion failed: caller is not minter'); }); it('mint >u128 tokens to overflow', async () => { const amount = 2n ** 128n; // U128::max() + 1; - await expect(asset.methods.mint_public(accounts[0].address, amount).simulate()).rejects.toThrow( + await expect(asset.methods.mint_to_public(accounts[0].address, amount).simulate()).rejects.toThrow( BITSIZE_TOO_BIG_ERROR, ); }); it('mint u128', async () => { const amount = 2n ** 128n - tokenSim.balanceOfPublic(accounts[0].address); - await expect(asset.methods.mint_public(accounts[0].address, amount).simulate()).rejects.toThrow( + await expect(asset.methods.mint_to_public(accounts[0].address, amount).simulate()).rejects.toThrow( U128_OVERFLOW_ERROR, ); }); it('mint u128', async () => { const amount = 2n ** 128n - tokenSim.balanceOfPublic(accounts[0].address); - await expect(asset.methods.mint_public(accounts[1].address, amount).simulate()).rejects.toThrow( + await expect(asset.methods.mint_to_public(accounts[1].address, amount).simulate()).rejects.toThrow( U128_OVERFLOW_ERROR, ); }); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/token_contract_test.ts b/yarn-project/end-to-end/src/e2e_token_contract/token_contract_test.ts index 9d1d76123bc..3748f1b8986 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/token_contract_test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/token_contract_test.ts @@ -122,7 +122,7 @@ export class TokenContractTest { const amount = 10000n; this.logger.verbose(`Minting ${amount} publicly...`); - await asset.methods.mint_public(wallets[0].getAddress(), amount).send().wait(); + await asset.methods.mint_to_public(wallets[0].getAddress(), amount).send().wait(); this.logger.verbose(`Minting ${amount} privately...`); await mintTokensToPrivate(asset, wallets[0], wallets[0].getAddress(), amount); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/transfer.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/transfer.test.ts new file mode 100644 index 00000000000..619f24c3a7d --- /dev/null +++ b/yarn-project/end-to-end/src/e2e_token_contract/transfer.test.ts @@ -0,0 +1,85 @@ +import { AztecAddress, CompleteAddress } from '@aztec/aztec.js'; +import { TokenContract, type Transfer } from '@aztec/noir-contracts.js'; + +import { TokenContractTest } from './token_contract_test.js'; + +describe('e2e_token_contract transfer private', () => { + const t = new TokenContractTest('transfer_private'); + let { asset, accounts, tokenSim, wallets } = t; + + beforeAll(async () => { + await t.applyBaseSnapshots(); + await t.applyMintSnapshot(); + await t.setup(); + ({ asset, accounts, tokenSim, wallets } = t); + }); + + afterAll(async () => { + await t.teardown(); + }); + + afterEach(async () => { + await t.tokenSim.check(); + }); + + it('transfer less than balance', async () => { + const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const amount = balance0 / 2n; + expect(amount).toBeGreaterThan(0n); + + // We give wallets[0] access to wallets[1]'s notes to be able to transfer the notes. + wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]); + + const tx = await asset.methods.transfer(accounts[1].address, amount).send().wait(); + tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount); + + const events = await wallets[1].getEncryptedEvents(TokenContract.events.Transfer, tx.blockNumber!, 1); + + expect(events[0]).toEqual({ + from: accounts[0].address, + to: accounts[1].address, + amount: amount, + }); + }); + + it('transfer less than balance to non-deployed account', async () => { + const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const amount = balance0 / 2n; + expect(amount).toBeGreaterThan(0n); + + const nonDeployed = CompleteAddress.random(); + + await asset.methods.transfer(nonDeployed.address, amount).send().wait(); + + // Add the account as balance we should change, but since we don't have the key, + // we cannot decrypt, and instead we simulate a transfer to address(0) + tokenSim.addAccount(nonDeployed.address); + tokenSim.transferPrivate(accounts[0].address, AztecAddress.ZERO, amount); + }); + + it('transfer to self', async () => { + const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const amount = balance0 / 2n; + expect(amount).toBeGreaterThan(0n); + await asset.methods.transfer(accounts[0].address, amount).send().wait(); + tokenSim.transferPrivate(accounts[0].address, accounts[0].address, amount); + }); + + describe('failure cases', () => { + it('transfer more than balance', async () => { + const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const amount = balance0 + 1n; + expect(amount).toBeGreaterThan(0n); + await expect(asset.methods.transfer(accounts[1].address, amount).simulate()).rejects.toThrow( + 'Assertion failed: Balance too low', + ); + }); + + it.skip('transfer into account to overflow', () => { + // This should already be covered by the mint case earlier. e.g., since we cannot mint to overflow, there is not + // a way to get funds enough to overflow. + // Require direct storage manipulation for us to perform a nice explicit case though. + // See https://github.com/AztecProtocol/aztec-packages/issues/1259 + }); + }); +}); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/transfer_private.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts similarity index 71% rename from yarn-project/end-to-end/src/e2e_token_contract/transfer_private.test.ts rename to yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts index b1a81efd77b..9834024f24c 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/transfer_private.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts @@ -1,11 +1,4 @@ -import { - AztecAddress, - CompleteAddress, - Fr, - computeAuthWitMessageHash, - computeInnerAuthWitHashFromAction, -} from '@aztec/aztec.js'; -import { TokenContract, type Transfer } from '@aztec/noir-contracts.js'; +import { Fr, computeAuthWitMessageHash, computeInnerAuthWitHashFromAction } from '@aztec/aztec.js'; import { DUPLICATE_NULLIFIER_ERROR } from '../fixtures/fixtures.js'; import { TokenContractTest } from './token_contract_test.js'; @@ -29,49 +22,6 @@ describe('e2e_token_contract transfer private', () => { await t.tokenSim.check(); }); - it('transfer less than balance', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); - const amount = balance0 / 2n; - expect(amount).toBeGreaterThan(0n); - - // We give wallets[0] access to wallets[1]'s notes to be able to transfer the notes. - wallets[0].setScopes([wallets[0].getAddress(), wallets[1].getAddress()]); - - const tx = await asset.methods.transfer(accounts[1].address, amount).send().wait(); - tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount); - - const events = await wallets[1].getEncryptedEvents(TokenContract.events.Transfer, tx.blockNumber!, 1); - - expect(events[0]).toEqual({ - from: accounts[0].address, - to: accounts[1].address, - amount: amount, - }); - }); - - it('transfer less than balance to non-deployed account', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); - const amount = balance0 / 2n; - expect(amount).toBeGreaterThan(0n); - - const nonDeployed = CompleteAddress.random(); - - await asset.methods.transfer(nonDeployed.address, amount).send().wait(); - - // Add the account as balance we should change, but since we don't have the key, - // we cannot decrypt, and instead we simulate a transfer to address(0) - tokenSim.addAccount(nonDeployed.address); - tokenSim.transferPrivate(accounts[0].address, AztecAddress.ZERO, amount); - }); - - it('transfer to self', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); - const amount = balance0 / 2n; - expect(amount).toBeGreaterThan(0n); - await asset.methods.transfer(accounts[0].address, amount).send().wait(); - tokenSim.transferPrivate(accounts[0].address, accounts[0].address, amount); - }); - it('transfer on behalf of other', async () => { const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); const amount = balance0 / 2n; @@ -82,7 +32,7 @@ describe('e2e_token_contract transfer private', () => { // docs:start:authwit_transfer_example const action = asset .withWallet(wallets[1]) - .methods.transfer_from(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_in_private(accounts[0].address, accounts[1].address, amount, nonce); const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); await wallets[1].addAuthWitness(witness); @@ -102,7 +52,7 @@ describe('e2e_token_contract transfer private', () => { // Perform the transfer again, should fail const txReplay = asset .withWallet(wallets[1]) - .methods.transfer_from(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer_in_private(accounts[0].address, accounts[1].address, amount, nonce) .send(); await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); @@ -111,21 +61,12 @@ describe('e2e_token_contract transfer private', () => { }); describe('failure cases', () => { - it('transfer more than balance', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); - const amount = balance0 + 1n; - expect(amount).toBeGreaterThan(0n); - await expect(asset.methods.transfer(accounts[1].address, amount).simulate()).rejects.toThrow( - 'Assertion failed: Balance too low', - ); - }); - it('transfer on behalf of self with non-zero nonce', async () => { const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); const amount = balance0 - 1n; expect(amount).toBeGreaterThan(0n); await expect( - asset.methods.transfer_from(accounts[0].address, accounts[1].address, amount, 1).simulate(), + asset.methods.transfer_in_private(accounts[0].address, accounts[1].address, amount, 1).simulate(), ).rejects.toThrow('Assertion failed: invalid nonce'); }); @@ -139,7 +80,7 @@ describe('e2e_token_contract transfer private', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer_from(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_in_private(accounts[0].address, accounts[1].address, amount, nonce); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -169,7 +110,7 @@ describe('e2e_token_contract transfer private', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer_from(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_in_private(accounts[0].address, accounts[1].address, amount, nonce); const messageHash = computeAuthWitMessageHash( { caller: accounts[1].address, action: action.request() }, { @@ -192,7 +133,7 @@ describe('e2e_token_contract transfer private', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[2]) - .methods.transfer_from(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_in_private(accounts[0].address, accounts[1].address, amount, nonce); const expectedMessageHash = computeAuthWitMessageHash( { caller: accounts[2].address, action: action.request() }, { @@ -222,7 +163,7 @@ describe('e2e_token_contract transfer private', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer_from(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_in_private(accounts[0].address, accounts[1].address, amount, nonce); const intent = { caller: accounts[1].address, action }; @@ -245,7 +186,7 @@ describe('e2e_token_contract transfer private', () => { // Perform the transfer, should fail because nullifier already emitted const txCancelledAuthwit = asset .withWallet(wallets[1]) - .methods.transfer_from(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer_in_private(accounts[0].address, accounts[1].address, amount, nonce) .send(); await expect(txCancelledAuthwit.wait()).rejects.toThrowError(DUPLICATE_NULLIFIER_ERROR); }); @@ -256,7 +197,7 @@ describe('e2e_token_contract transfer private', () => { // Should fail as the returned value from the badAccount is malformed const txCancelledAuthwit = asset .withWallet(wallets[1]) - .methods.transfer_from(badAccount.address, accounts[1].address, 0, nonce) + .methods.transfer_in_private(badAccount.address, accounts[1].address, 0, nonce) .send(); await expect(txCancelledAuthwit.wait()).rejects.toThrow( "Assertion failed: Message not authorized by account 'result == IS_VALID_SELECTOR'", diff --git a/yarn-project/end-to-end/src/e2e_token_contract/transfer_public.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_public.test.ts similarity index 85% rename from yarn-project/end-to-end/src/e2e_token_contract/transfer_public.test.ts rename to yarn-project/end-to-end/src/e2e_token_contract/transfer_in_public.test.ts index 5ba38158564..0c92a459ad0 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/transfer_public.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_public.test.ts @@ -4,7 +4,7 @@ import { U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js'; import { TokenContractTest } from './token_contract_test.js'; describe('e2e_token_contract transfer public', () => { - const t = new TokenContractTest('transfer_public'); + const t = new TokenContractTest('transfer_in_public'); let { asset, accounts, tokenSim, wallets, badAccount } = t; beforeAll(async () => { @@ -27,7 +27,7 @@ describe('e2e_token_contract transfer public', () => { const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); - await asset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, 0).send().wait(); + await asset.methods.transfer_in_public(accounts[0].address, accounts[1].address, amount, 0).send().wait(); tokenSim.transferPublic(accounts[0].address, accounts[1].address, amount); }); @@ -36,7 +36,7 @@ describe('e2e_token_contract transfer public', () => { const balance = await asset.methods.balance_of_public(accounts[0].address).simulate(); const amount = balance / 2n; expect(amount).toBeGreaterThan(0n); - await asset.methods.transfer_public(accounts[0].address, accounts[0].address, amount, 0).send().wait(); + await asset.methods.transfer_in_public(accounts[0].address, accounts[0].address, amount, 0).send().wait(); tokenSim.transferPublic(accounts[0].address, accounts[0].address, amount); }); @@ -50,7 +50,7 @@ describe('e2e_token_contract transfer public', () => { // docs:start:authwit_public_transfer_example const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_in_public(accounts[0].address, accounts[1].address, amount, nonce); await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); // docs:end:authwit_public_transfer_example @@ -64,7 +64,7 @@ describe('e2e_token_contract transfer public', () => { await expect( asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer_in_public(accounts[0].address, accounts[1].address, amount, nonce) .simulate(), ).rejects.toThrow(/unauthorized/); }); @@ -75,7 +75,7 @@ describe('e2e_token_contract transfer public', () => { const amount = balance0 + 1n; const nonce = 0; await expect( - asset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce).simulate(), + asset.methods.transfer_in_public(accounts[0].address, accounts[1].address, amount, nonce).simulate(), ).rejects.toThrow(U128_UNDERFLOW_ERROR); }); @@ -84,7 +84,7 @@ describe('e2e_token_contract transfer public', () => { const amount = balance0 - 1n; const nonce = 1; await expect( - asset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce).simulate(), + asset.methods.transfer_in_public(accounts[0].address, accounts[1].address, amount, nonce).simulate(), ).rejects.toThrow('Assertion failed: invalid nonce'); }); @@ -95,7 +95,7 @@ describe('e2e_token_contract transfer public', () => { await expect( asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer_in_public(accounts[0].address, accounts[1].address, amount, nonce) .simulate(), ).rejects.toThrow(/unauthorized/); }); @@ -109,7 +109,7 @@ describe('e2e_token_contract transfer public', () => { const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_in_public(accounts[0].address, accounts[1].address, amount, nonce); expect(await wallets[0].lookupValidity(wallets[0].getAddress(), { caller: accounts[1].address, action })).toEqual( { @@ -145,7 +145,7 @@ describe('e2e_token_contract transfer public', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_in_public(accounts[0].address, accounts[1].address, amount, nonce); await wallets[0].setPublicAuthWit({ caller: accounts[0].address, action }, true).send().wait(); @@ -166,7 +166,7 @@ describe('e2e_token_contract transfer public', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_in_public(accounts[0].address, accounts[1].address, amount, nonce); await wallets[0].setPublicAuthWit({ caller: accounts[0].address, action }, true).send().wait(); // Perform the transfer @@ -184,7 +184,7 @@ describe('e2e_token_contract transfer public', () => { const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_in_public(accounts[0].address, accounts[1].address, amount, nonce); await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); @@ -193,7 +193,7 @@ describe('e2e_token_contract transfer public', () => { await expect( asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer_in_public(accounts[0].address, accounts[1].address, amount, nonce) .simulate(), ).rejects.toThrowError(/unauthorized/); }); @@ -206,7 +206,7 @@ describe('e2e_token_contract transfer public', () => { const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_in_public(accounts[0].address, accounts[1].address, amount, nonce); await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); @@ -221,7 +221,7 @@ describe('e2e_token_contract transfer public', () => { await expect( asset .withWallet(wallets[1]) - .methods.transfer_public(badAccount.address, accounts[1].address, 0, nonce) + .methods.transfer_in_public(badAccount.address, accounts[1].address, 0, nonce) .simulate(), ).rejects.toThrow(/unauthorized/); }); diff --git a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts index ffe17819f62..b5f187d9e26 100644 --- a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts +++ b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts @@ -120,7 +120,7 @@ describe('guides/dapp/testing', () => { it('checks public storage', async () => { // docs:start:public-storage - await token.methods.mint_public(owner.getAddress(), 100n).send().wait(); + await token.methods.mint_to_public(owner.getAddress(), 100n).send().wait(); const ownerPublicBalanceSlot = cheats.aztec.computeSlotInMap( TokenContract.storage.public_balances.slot, owner.getAddress(), @@ -172,14 +172,14 @@ describe('guides/dapp/testing', () => { it('asserts a simulation for a public function call fails', async () => { // docs:start:local-pub-fails - const call = token.methods.transfer_public(owner.getAddress(), recipient.getAddress(), 1000n, 0); + const call = token.methods.transfer_in_public(owner.getAddress(), recipient.getAddress(), 1000n, 0); await expect(call.prove()).rejects.toThrow(U128_UNDERFLOW_ERROR); // docs:end:local-pub-fails }); it('asserts a transaction with a failing public call is included (with no state changes)', async () => { // docs:start:pub-reverted - const call = token.methods.transfer_public(owner.getAddress(), recipient.getAddress(), 1000n, 0); + const call = token.methods.transfer_in_public(owner.getAddress(), recipient.getAddress(), 1000n, 0); const receipt = await call.send({ skipPublicSimulation: true }).wait({ dontThrowOnRevert: true }); expect(receipt.status).toEqual(TxStatus.APP_LOGIC_REVERTED); const ownerPublicBalanceSlot = cheats.aztec.computeSlotInMap( diff --git a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts index 3840c08a3bf..678aeaa5682 100644 --- a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts +++ b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts @@ -80,7 +80,7 @@ describe('guides/writing_an_account_contract', () => { const tokenWithWrongWallet = token.withWallet(wrongWallet); try { - await tokenWithWrongWallet.methods.mint_public(address, 200).prove(); + await tokenWithWrongWallet.methods.mint_to_public(address, 200).prove(); } catch (err) { logger.info(`Failed to send tx: ${err}`); } diff --git a/yarn-project/end-to-end/src/sample-dapp/index.mjs b/yarn-project/end-to-end/src/sample-dapp/index.mjs index 2c68a011117..fff9f14e117 100644 --- a/yarn-project/end-to-end/src/sample-dapp/index.mjs +++ b/yarn-project/end-to-end/src/sample-dapp/index.mjs @@ -84,7 +84,7 @@ async function mintPublicFunds(pxe) { await showPublicBalances(pxe); console.log(`Sending transaction, awaiting transaction to be mined`); - const receipt = await token.methods.mint_public(owner.getAddress(), 100).send().wait(); + const receipt = await token.methods.mint_to_public(owner.getAddress(), 100).send().wait(); console.log(`Transaction ${receipt.txHash} has been mined on block ${receipt.blockNumber}`); await showPublicBalances(pxe); diff --git a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts index 687fe8148c7..5767a678460 100644 --- a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts @@ -240,7 +240,7 @@ export class CrossChainTestHarness { async mintTokensPublicOnL2(amount: bigint) { this.logger.info('Minting tokens on L2 publicly'); - await this.l2Token.methods.mint_public(this.ownerAddress, amount).send().wait(); + await this.l2Token.methods.mint_to_public(this.ownerAddress, amount).send().wait(); } async mintTokensPrivateOnL2(amount: bigint) { @@ -249,7 +249,7 @@ export class CrossChainTestHarness { async sendL2PublicTransfer(transferAmount: bigint, receiverAddress: AztecAddress) { // send a transfer tx to force through rollup with the message included - await this.l2Token.methods.transfer_public(this.ownerAddress, receiverAddress, transferAmount, 0).send().wait(); + await this.l2Token.methods.transfer_in_public(this.ownerAddress, receiverAddress, transferAmount, 0).send().wait(); } async consumeMessageOnAztecAndMintPrivately( diff --git a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts index 6e594253985..ef6b20c0018 100644 --- a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts +++ b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts @@ -418,7 +418,7 @@ export const uniswapL1L2TestSuite = ( // { // caller: uniswapL2Contract.address, // action: wethCrossChainHarness.l2Token.methods - // .transfer_public( + // .transfer_in_public( // ownerAddress, // uniswapL2Contract.address, // wethAmountToBridge, @@ -690,7 +690,7 @@ export const uniswapL1L2TestSuite = ( { caller: uniswapL2Contract.address, action: wethCrossChainHarness.l2Token.methods - .transfer_public( + .transfer_in_public( ownerAddress, uniswapL2Contract.address, wethAmountToBridge, @@ -762,7 +762,7 @@ export const uniswapL1L2TestSuite = ( { caller: uniswapL2Contract.address, action: wethCrossChainHarness.l2Token.methods - .transfer_public( + .transfer_in_public( ownerAddress, uniswapL2Contract.address, wethAmountToBridge, @@ -932,7 +932,7 @@ export const uniswapL1L2TestSuite = ( { caller: uniswapL2Contract.address, action: wethCrossChainHarness.l2Token.methods - .transfer_public( + .transfer_in_public( ownerAddress, uniswapL2Contract.address, wethAmountToBridge, diff --git a/yarn-project/end-to-end/src/spartan/4epochs.test.ts b/yarn-project/end-to-end/src/spartan/4epochs.test.ts index 9c601e1fa26..354da3335f0 100644 --- a/yarn-project/end-to-end/src/spartan/4epochs.test.ts +++ b/yarn-project/end-to-end/src/spartan/4epochs.test.ts @@ -80,7 +80,7 @@ describe('token transfer test', () => { ...testWallets.wallets.map(async w => ( await TokenContract.at(testWallets.tokenAddress, w) - ).methods.transfer_public(w.getAddress(), recipient, transferAmount, 0), + ).methods.transfer_in_public(w.getAddress(), recipient, transferAmount, 0), ), ]); diff --git a/yarn-project/end-to-end/src/spartan/setup_test_wallets.ts b/yarn-project/end-to-end/src/spartan/setup_test_wallets.ts index 5feb52d1de8..bb4528707a9 100644 --- a/yarn-project/end-to-end/src/spartan/setup_test_wallets.ts +++ b/yarn-project/end-to-end/src/spartan/setup_test_wallets.ts @@ -69,7 +69,7 @@ export async function setupTestWalletsWithTokens( logger.verbose(`Minting ${mintAmount} public assets to the ${wallets.length} wallets...`); await Promise.all( - wallets.map(w => tokenAdminWallet.methods.mint_public(w.getAddress(), mintAmount).send().wait({ timeout: 600 })), + wallets.map(w => tokenAdminWallet.methods.mint_to_public(w.getAddress(), mintAmount).send().wait({ timeout: 600 })), ); logger.verbose(`Minting complete.`); @@ -95,7 +95,7 @@ export async function performTransfers({ testWallets.wallets.map(async w => ( await TokenContract.at(testWallets.tokenAddress, w) - ).methods.transfer_public(w.getAddress(), recipient, transferAmount, 0), + ).methods.transfer_in_public(w.getAddress(), recipient, transferAmount, 0), ), ); diff --git a/yarn-project/end-to-end/src/spartan/transfer.test.ts b/yarn-project/end-to-end/src/spartan/transfer.test.ts index 2988c23b9cb..a073247cae3 100644 --- a/yarn-project/end-to-end/src/spartan/transfer.test.ts +++ b/yarn-project/end-to-end/src/spartan/transfer.test.ts @@ -57,7 +57,7 @@ describe('token transfer test', () => { ...testWallets.wallets.map(async w => ( await TokenContract.at(testWallets.tokenAddress, w) - ).methods.transfer_public(w.getAddress(), recipient, transferAmount, 0), + ).methods.transfer_in_public(w.getAddress(), recipient, transferAmount, 0), ), ]); diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 989c5ed7067..72c684ff435 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -603,7 +603,7 @@ describe('Private Execution test suite', () => { const contractAddress = defaultContractAddress; describe('L1 to L2', () => { - const artifact = getFunctionArtifact(TestContractArtifact, 'consume_mint_private_message'); + const artifact = getFunctionArtifact(TestContractArtifact, 'consume_mint_to_private_message'); let bridgedAmount = 100n; const l1ToL2MessageIndex = 0; @@ -626,7 +626,7 @@ describe('Private Execution test suite', () => { const computePreimage = () => buildL1ToL2Message( - toFunctionSelector('mint_private(uint256)').substring(2), + toFunctionSelector('mint_to_private(uint256)').substring(2), [new Fr(bridgedAmount)], crossChainMsgRecipient ?? contractAddress, secretForL1ToL2MessageConsumption,