Skip to content

Commit

Permalink
fix: token naming issue
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Nov 13, 2024
1 parent 3d4724b commit e6f37b9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ First, storage is initialized. Then the function checks that the `msg_sender` is

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

First, partial note is prepared by the call to `_prepare_transfer_to_private` for the minted tokens recipient. Then a public call to `_finalize_mint_to_private_unsafe` is enqueued while `msg_sender`, `amount` and the `hiding_point_slot` are passed in via arguments. Since we set `from` to `msg_sender` here the usage of the unsafe function is safe. The enqueued call then checks the minter permissions of `from` and it finalizes the partial note for `to`.
First, partial note is prepared by the call to `_prepare_private_balance_increase` for the minted tokens recipient. Then a public call to `_finalize_mint_to_private_unsafe` is enqueued while `msg_sender`, `amount` and the `hiding_point_slot` are passed in via arguments. Since we set `from` to `msg_sender` here the usage of the unsafe function is safe. The enqueued call then checks the minter permissions of `from` and it finalizes the partial note for `to`.

#include_code mint_to_private /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ contract NFT {

let nft = NFT::at(context.this_address());

// We prepare the transfer.
let hiding_point_slot = _prepare_transfer_to_private(to, &mut context, storage);
// We prepare the private balance increase.
let hiding_point_slot = _prepare_private_balance_increase(to, &mut context, storage);

// At last we finalize the transfer. Usafe of the `unsafe` method here is safe because we set the `from`
// function argument to a message sender, guaranteeing that he can transfer only his own NFTs.
Expand All @@ -164,7 +164,7 @@ contract NFT {
/// finalized by calling `finalize_transfer_to_private`. Returns a hiding point slot.
#[private]
fn prepare_transfer_to_private(to: AztecAddress) -> Field {
_prepare_transfer_to_private(to, &mut context, storage)
_prepare_private_balance_increase(to, &mut context, storage)
}

/// This function exists separately from `prepare_transfer_to_private` solely as an optimization as it allows
Expand All @@ -173,7 +173,7 @@ contract NFT {
/// TODO(#9180): Consider adding macro support for functions callable both as an entrypoint and as an internal
/// function.
#[contract_library_method]
fn _prepare_transfer_to_private(
fn _prepare_private_balance_increase(
to: AztecAddress,
context: &mut PrivateContext,
storage: Storage<&mut PrivateContext>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ contract Token {
let from = context.msg_sender();
let token = Token::at(context.this_address());

// We prepare the transfer.
let hiding_point_slot = _prepare_transfer_to_private(from, to, &mut context, storage);
// We prepare the private balance increase (the partial note).
let hiding_point_slot = _prepare_private_balance_increase(from, to, &mut context, storage);

// At last we finalize the transfer. Usage of the `unsafe` method here is safe because we set the `from`
// function argument to a message sender, guaranteeing that he can transfer only his own tokens.
Expand All @@ -449,7 +449,7 @@ contract Token {
#[private]
fn prepare_transfer_to_private(to: AztecAddress) -> Field {
let from = context.msg_sender();
_prepare_transfer_to_private(from, to, &mut context, storage)
_prepare_private_balance_increase(from, to, &mut context, storage)
}

/// This function exists separately from `prepare_transfer_to_private` solely as an optimization as it allows
Expand All @@ -458,7 +458,7 @@ contract Token {
/// TODO(#9180): Consider adding macro support for functions callable both as an entrypoint and as an internal
/// function.
#[contract_library_method]
fn _prepare_transfer_to_private(
fn _prepare_private_balance_increase(
from: AztecAddress, // recipient of the outgoing: TODO(#9887): this is not great?
to: AztecAddress,
context: &mut PrivateContext,
Expand Down Expand Up @@ -557,7 +557,7 @@ contract Token {
let token = Token::at(context.this_address());

// We prepare the partial note to which we'll "send" the minted amount.
let hiding_point_slot = _prepare_transfer_to_private(from, to, &mut context, storage);
let hiding_point_slot = _prepare_private_balance_increase(from, to, &mut context, storage);

// At last we finalize the mint. Usage of the `unsafe` method here is safe because we set the `from`
// function argument to a message sender, guaranteeing that only a message sender with minter permissions
Expand Down Expand Up @@ -667,11 +667,11 @@ contract Token {
));

// 4. We prepare the partial notes
// TODO(#9887): In each `_prepare_transfer_to_private` call we fetch the user's ovpk_m 2 more times. This is
// TODO(#9887): In each `_prepare_private_balance_increase` call we fetch the user's ovpk_m 2 more times. This is
// very inefficient.
let fee_payer_point_slot =
_prepare_transfer_to_private(user, fee_payer, &mut context, storage);
let user_point_slot = _prepare_transfer_to_private(user, user, &mut context, storage);
_prepare_private_balance_increase(user, fee_payer, &mut context, storage);
let user_point_slot = _prepare_private_balance_increase(user, user, &mut context, storage);

// 5. Set the public teardown function to `complete_refund(...)`. Public teardown is the only time when a public
// function has access to the final transaction fee, which is needed to compute the actual refund amount.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::{test::utils, Token};
use dep::aztec::{
keys::getters::get_public_keys, oracle::random::random,
protocol_types::storage::map::derive_storage_slot_in_map,
};
use dep::aztec::oracle::random::random;
use std::test::OracleMock;

/// Internal orchestration means that the calls to `prepare_transfer_to_private`
Expand Down

0 comments on commit e6f37b9

Please sign in to comment.