Skip to content

Commit 7c683a6

Browse files
committed
WIP
1 parent 21e94ff commit 7c683a6

File tree

21 files changed

+68
-64
lines changed

21 files changed

+68
-64
lines changed

docs/docs/tutorials/codealong/aztecjs-getting-started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Our output should now look like this:
283283
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.
284284

285285
Finally, the contract has 2 `mint` functions that can be used to generate new tokens for an account.
286-
We will focus only on `mint_private`.
286+
We will focus only on `mint_to_private`.
287287
This function is public but it mints tokens privately.
288288
This function takes:
289289

docs/docs/tutorials/codealong/contract_tutorials/advanced/token_bridge/1_depositing_to_aztec.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Let’s do the similar for the private flow:
7878

7979
Here we want to send a message to mint tokens privately on Aztec! Some key differences from the previous method are:
8080

81-
- 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!
81+
- 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!
8282
- 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
8383
- Like with the public flow, we move the user’s funds to the portal
8484
- 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).

docs/docs/tutorials/codealong/contract_tutorials/advanced/token_bridge/2_minting_on_aztec.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ Now we will create a function to mint the amount privately. Paste this into your
4646

4747
#include_code call_mint_on_token /noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr rust
4848

49-
The `get_mint_private_content_hash` function is imported from the `token_portal_content_hash_lib`.
49+
The `get_mint_to_private_content_hash` function is imported from the `token_portal_content_hash_lib`.
5050

51-
If the content hashes were constructed similarly for `mint_private` and `mint_to_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.
51+
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.
5252

5353
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.
5454

55-
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).
55+
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).
5656

5757
In the next step we will see how we can cancel a message.

docs/docs/tutorials/codealong/contract_tutorials/token_contract.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ These are functions that have transparent logic, will execute in a publicly veri
6868
- `set_admin` enables the admin to be updated
6969
- `set_minter` enables accounts to be added / removed from the approved minter list
7070
- `mint_to_public` enables tokens to be minted to the public balance of an account
71-
- `mint_private` enables tokens to be minted to the private balance of an account (with some caveats we will dig into)
71+
- `mint_to_private` enables tokens to be minted to the private balance of an account (with some caveats we will dig into)
7272
- `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)
7373
- `transfer_in_public` enables users to transfer tokens from one account's public balance to another account's public balance
7474
- `burn_public` enables users to burn tokens
@@ -199,7 +199,7 @@ First, storage is initialized. Then the function checks that the `msg_sender` is
199199

200200
#include_code mint_to_public /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust
201201

202-
#### `mint_private`
202+
#### `mint_to_private`
203203

204204
This public function allows an account approved in the public `minters` mapping to create new private tokens.
205205

l1-contracts/test/portals/TokenPortal.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ contract TokenPortal {
8787
// Hash the message content to be reconstructed in the receiving contract - the signature below does not correspond
8888
// to a real function. It's just an identifier of an action.
8989
bytes32 contentHash =
90-
Hash.sha256ToField(abi.encodeWithSignature("mint_private(uint256)", _amount));
90+
Hash.sha256ToField(abi.encodeWithSignature("mint_to_private(uint256)", _amount));
9191

9292
// Hold the tokens in the portal
9393
underlying.safeTransferFrom(msg.sender, address(this), _amount);

l1-contracts/test/portals/TokenPortal.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ contract TokenPortalTest is Test {
9191
return DataStructures.L1ToL2Msg({
9292
sender: DataStructures.L1Actor(address(tokenPortal), block.chainid),
9393
recipient: DataStructures.L2Actor(l2TokenAddress, 1),
94-
content: Hash.sha256ToField(abi.encodeWithSignature("mint_private(uint256)", amount)),
94+
content: Hash.sha256ToField(abi.encodeWithSignature("mint_to_private(uint256)", amount)),
9595
secretHash: secretHashForL2MessageConsumption,
9696
index: _index
9797
});

noir-projects/noir-contracts/contracts/test_contract/src/main.nr

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ contract Test {
3434
utils::comparison::Comparator,
3535
};
3636
use dep::token_portal_content_hash_lib::{
37-
get_mint_private_content_hash, get_mint_to_public_content_hash,
37+
get_mint_to_private_content_hash, get_mint_to_public_content_hash,
3838
};
3939
use dep::value_note::value_note::ValueNote;
4040
// TODO investigate why the macros require EmbeddedCurvePoint and EmbeddedCurveScalar
@@ -385,14 +385,14 @@ contract Test {
385385
}
386386

387387
#[private]
388-
fn consume_mint_private_message(
388+
fn consume_mint_to_private_message(
389389
amount: Field,
390390
secret_for_L1_to_L2_message_consumption: Field,
391391
portal_address: EthAddress,
392392
message_leaf_index: Field,
393393
) {
394394
// Consume L1 to L2 message and emit nullifier
395-
let content_hash = get_mint_private_content_hash(amount);
395+
let content_hash = get_mint_to_private_content_hash(amount);
396396
context.consume_l1_to_l2_message(
397397
content_hash,
398398
secret_for_L1_to_L2_message_consumption,

noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ contract TokenBridge {
1212
use dep::aztec::prelude::{AztecAddress, EthAddress, SharedImmutable};
1313

1414
use dep::token_portal_content_hash_lib::{
15-
get_mint_private_content_hash, get_mint_to_public_content_hash, get_withdraw_content_hash,
15+
get_mint_to_private_content_hash, get_mint_to_public_content_hash,
16+
get_withdraw_content_hash,
1617
};
1718

1819
use dep::token::Token;
@@ -103,7 +104,7 @@ contract TokenBridge {
103104
message_leaf_index: Field,
104105
) {
105106
// Consume L1 to L2 message and emit nullifier
106-
let content_hash = get_mint_private_content_hash(amount);
107+
let content_hash = get_mint_to_private_content_hash(amount);
107108
context.consume_l1_to_l2_message(
108109
content_hash,
109110
secret_for_L1_to_L2_message_consumption,

noir-projects/noir-contracts/contracts/token_contract/src/test/burn_private.nr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use dep::aztec::oracle::random::random;
66
#[test]
77
unconstrained fn burn_private_on_behalf_of_self() {
88
let (env, token_contract_address, owner, _, mint_amount) =
9-
utils::setup_and_mint_private(/* with_account_contracts */ false);
9+
utils::setup_and_mint_to_private(/* with_account_contracts */ false);
1010
let burn_amount = mint_amount / 10;
1111

1212
// Burn less than balance
@@ -17,7 +17,7 @@ unconstrained fn burn_private_on_behalf_of_self() {
1717
#[test]
1818
unconstrained fn burn_private_on_behalf_of_other() {
1919
let (env, token_contract_address, owner, recipient, mint_amount) =
20-
utils::setup_and_mint_private(/* with_account_contracts */ true);
20+
utils::setup_and_mint_to_private(/* with_account_contracts */ true);
2121
let burn_amount = mint_amount / 10;
2222

2323
// Burn on behalf of other

noir-projects/noir-contracts/contracts/token_contract/src/test/refunds.nr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::test::OracleMock;
77
#[test]
88
unconstrained fn setup_refund_success() {
99
let (env, token_contract_address, owner, recipient, mint_amount) =
10-
utils::setup_and_mint_private(true);
10+
utils::setup_and_mint_to_private(true);
1111

1212
// Renaming owner and recipient to match naming in Token
1313
let user = owner;
@@ -65,7 +65,7 @@ unconstrained fn setup_refund_success() {
6565
#[test(should_fail_with = "Balance too low")]
6666
unconstrained fn setup_refund_insufficient_funded_amount() {
6767
let (env, token_contract_address, owner, recipient, _mint_amount) =
68-
utils::setup_and_mint_private(true);
68+
utils::setup_and_mint_to_private(true);
6969

7070
// Renaming owner and recipient to match naming in Token
7171
let user = owner;

noir-projects/noir-contracts/contracts/token_contract/src/test/transfer.nr

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use dep::aztec::test::helpers::cheatcodes;
77
unconstrained fn transfer_private() {
88
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
99
let (env, token_contract_address, owner, recipient, mint_amount) =
10-
utils::setup_and_mint_private(/* with_account_contracts */ false);
10+
utils::setup_and_mint_to_private(/* with_account_contracts */ false);
1111

1212
// docs:start:txe_test_transfer_private
1313
// Transfer tokens
@@ -23,7 +23,7 @@ unconstrained fn transfer_private() {
2323
unconstrained fn transfer_private_to_self() {
2424
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
2525
let (env, token_contract_address, owner, _, mint_amount) =
26-
utils::setup_and_mint_private(/* with_account_contracts */ false);
26+
utils::setup_and_mint_to_private(/* with_account_contracts */ false);
2727
// Transfer tokens
2828
let transfer_amount = 1000;
2929
Token::at(token_contract_address).transfer(owner, transfer_amount).call(&mut env.private());
@@ -36,7 +36,7 @@ unconstrained fn transfer_private_to_self() {
3636
unconstrained fn transfer_private_to_non_deployed_account() {
3737
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
3838
let (env, token_contract_address, owner, _, mint_amount) =
39-
utils::setup_and_mint_private(/* with_account_contracts */ false);
39+
utils::setup_and_mint_to_private(/* with_account_contracts */ false);
4040
let not_deployed = cheatcodes::create_account();
4141
// Transfer tokens
4242
let transfer_amount = 1000;
@@ -57,7 +57,7 @@ unconstrained fn transfer_private_to_non_deployed_account() {
5757
unconstrained fn transfer_private_failure_more_than_balance() {
5858
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
5959
let (env, token_contract_address, _, recipient, mint_amount) =
60-
utils::setup_and_mint_private(/* with_account_contracts */ false);
60+
utils::setup_and_mint_to_private(/* with_account_contracts */ false);
6161
// Transfer tokens
6262
let transfer_amount = mint_amount + 1;
6363
Token::at(token_contract_address).transfer(recipient, transfer_amount).call(&mut env.private());

noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_in_private.nr

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use dep::authwit::cheatcodes as authwit_cheatcodes;
66
unconstrained fn transfer_private_on_behalf_of_other() {
77
// Setup with account contracts. Slower since we actually deploy them, but needed for authwits.
88
let (env, token_contract_address, owner, recipient, mint_amount) =
9-
utils::setup_and_mint_private(/* with_account_contracts */ true);
9+
utils::setup_and_mint_to_private(/* with_account_contracts */ true);
1010
// Add authwit
1111
// docs:start:private_authwit
1212
let transfer_amount = 1000;
@@ -32,7 +32,7 @@ unconstrained fn transfer_private_on_behalf_of_other() {
3232
unconstrained fn transfer_private_failure_on_behalf_of_self_non_zero_nonce() {
3333
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
3434
let (env, token_contract_address, owner, recipient, _) =
35-
utils::setup_and_mint_private(/* with_account_contracts */ false);
35+
utils::setup_and_mint_to_private(/* with_account_contracts */ false);
3636
// Add authwit
3737
let transfer_amount = 1000;
3838
let transfer_private_from_call_interface =
@@ -51,7 +51,7 @@ unconstrained fn transfer_private_failure_on_behalf_of_self_non_zero_nonce() {
5151
unconstrained fn transfer_private_failure_on_behalf_of_more_than_balance() {
5252
// Setup with account contracts. Slower since we actually deploy them, but needed for authwits.
5353
let (env, token_contract_address, owner, recipient, mint_amount) =
54-
utils::setup_and_mint_private(/* with_account_contracts */ true);
54+
utils::setup_and_mint_to_private(/* with_account_contracts */ true);
5555
// Add authwit
5656
let transfer_amount = mint_amount + 1;
5757
let transfer_private_from_call_interface =
@@ -71,7 +71,7 @@ unconstrained fn transfer_private_failure_on_behalf_of_more_than_balance() {
7171
unconstrained fn transfer_private_failure_on_behalf_of_other_without_approval() {
7272
// Setup with account contracts. Slower since we actually deploy them, but needed for authwits.
7373
let (env, token_contract_address, owner, recipient, _) =
74-
utils::setup_and_mint_private(/* with_account_contracts */ true);
74+
utils::setup_and_mint_to_private(/* with_account_contracts */ true);
7575
// Add authwit
7676
let transfer_amount = 1000;
7777
let transfer_private_from_call_interface =
@@ -86,7 +86,7 @@ unconstrained fn transfer_private_failure_on_behalf_of_other_without_approval()
8686
unconstrained fn transfer_private_failure_on_behalf_of_other_wrong_caller() {
8787
// Setup with account contracts. Slower since we actually deploy them, but needed for authwits.
8888
let (env, token_contract_address, owner, recipient, _) =
89-
utils::setup_and_mint_private(/* with_account_contracts */ true);
89+
utils::setup_and_mint_to_private(/* with_account_contracts */ true);
9090
// Add authwit
9191
let transfer_amount = 1000;
9292
let transfer_private_from_call_interface =

noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_to_private.nr

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use std::test::OracleMock;
1111
/// in `utils::setup_mint_and_transfer_to_private`.
1212
#[test]
1313
unconstrained fn transfer_to_private_internal_orchestration() {
14-
// The transfer to private is done in `utils::setup_and_mint_private` and for this reason
14+
// The transfer to private is done in `utils::setup_and_mint_to_private` and for this reason
1515
// in this test we just call it and check the outcome.
1616
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
1717
let (_, token_contract_address, user, _, amount) =
18-
utils::setup_and_mint_private(/* with_account_contracts */ false);
18+
utils::setup_and_mint_to_private(/* with_account_contracts */ false);
1919

2020
// User's private balance should be equal to the amount
2121
utils::check_private_balance(token_contract_address, user, amount);

noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_to_public.nr

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use dep::aztec::oracle::random::random;
77
unconstrained fn transfer_to_public_on_behalf_of_self() {
88
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
99
let (env, token_contract_address, owner, _, mint_amount) =
10-
utils::setup_and_mint_private(/* with_account_contracts */ false);
10+
utils::setup_and_mint_to_private(/* with_account_contracts */ false);
1111

1212
let transfer_to_public_amount = mint_amount / 10;
1313
Token::at(token_contract_address)
@@ -24,7 +24,7 @@ unconstrained fn transfer_to_public_on_behalf_of_self() {
2424
#[test]
2525
unconstrained fn transfer_to_public_on_behalf_of_other() {
2626
let (env, token_contract_address, owner, recipient, mint_amount) =
27-
utils::setup_and_mint_private(/* with_account_contracts */ true);
27+
utils::setup_and_mint_to_private(/* with_account_contracts */ true);
2828

2929
let transfer_to_public_amount = mint_amount / 10;
3030
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() {
5454
unconstrained fn transfer_to_public_failure_more_than_balance() {
5555
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
5656
let (env, token_contract_address, owner, _, mint_amount) =
57-
utils::setup_and_mint_private(/* with_account_contracts */ false);
57+
utils::setup_and_mint_to_private(/* with_account_contracts */ false);
5858

5959
let transfer_to_public_amount = mint_amount + 1;
6060
Token::at(token_contract_address)
@@ -66,7 +66,7 @@ unconstrained fn transfer_to_public_failure_more_than_balance() {
6666
unconstrained fn transfer_to_public_failure_on_behalf_of_self_non_zero_nonce() {
6767
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
6868
let (env, token_contract_address, owner, _, mint_amount) =
69-
utils::setup_and_mint_private(/* with_account_contracts */ false);
69+
utils::setup_and_mint_to_private(/* with_account_contracts */ false);
7070

7171
let transfer_to_public_amount = mint_amount + 1;
7272
Token::at(token_contract_address)
@@ -77,7 +77,7 @@ unconstrained fn transfer_to_public_failure_on_behalf_of_self_non_zero_nonce() {
7777
#[test(should_fail_with = "Balance too low")]
7878
unconstrained fn transfer_to_public_failure_on_behalf_of_other_more_than_balance() {
7979
let (env, token_contract_address, owner, recipient, mint_amount) =
80-
utils::setup_and_mint_private(/* with_account_contracts */ true);
80+
utils::setup_and_mint_to_private(/* with_account_contracts */ true);
8181

8282
let transfer_to_public_amount = mint_amount + 1;
8383
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
100100
#[test(should_fail_with = "Authorization not found for message hash")]
101101
unconstrained fn transfer_to_public_failure_on_behalf_of_other_invalid_designated_caller() {
102102
let (env, token_contract_address, owner, recipient, mint_amount) =
103-
utils::setup_and_mint_private(/* with_account_contracts */ true);
103+
utils::setup_and_mint_to_private(/* with_account_contracts */ true);
104104

105105
let transfer_to_public_amount = mint_amount + 1;
106106
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
123123
#[test(should_fail_with = "Authorization not found for message hash")]
124124
unconstrained fn transfer_to_public_failure_on_behalf_of_other_no_approval() {
125125
let (env, token_contract_address, owner, recipient, mint_amount) =
126-
utils::setup_and_mint_private(/* with_account_contracts */ true);
126+
utils::setup_and_mint_to_private(/* with_account_contracts */ true);
127127

128128
let transfer_to_public_amount = mint_amount + 1;
129129
let transfer_to_public_call_interface = Token::at(token_contract_address).transfer_to_public(

0 commit comments

Comments
 (0)