Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 24, 2024
1 parent 8e90fb2 commit e0a1ee9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
23 changes: 17 additions & 6 deletions noir-projects/noir-contracts/contracts/nft_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract NFT {
oracle::random::random,
prelude::{
NoteGetterOptions, NoteViewerOptions, Map, PublicMutable, SharedImmutable, PrivateSet,
AztecAddress, PrivateContext, PublicContext
AztecAddress, PrivateContext, PublicContext,
},
encrypted_logs::encrypted_note_emission::{
encode_and_encrypt_note, encrypt_and_emit_partial_log,
Expand Down Expand Up @@ -154,7 +154,9 @@ contract NFT {

// 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.
nft._finalize_transfer_to_private_unsafe(from, token_id, hiding_point_slot).enqueue(&mut context);
nft._finalize_transfer_to_private_unsafe(from, token_id, hiding_point_slot).enqueue(
&mut context,
);
}

/// Prepares a transfer to a private balance of `to`. The transfer then needs to be
Expand All @@ -173,7 +175,7 @@ contract NFT {
fn _prepare_transfer_to_private(
to: AztecAddress,
context: &mut PrivateContext,
storage: Storage<&mut PrivateContext>
storage: Storage<&mut PrivateContext>,
) -> Field {
let to_keys = get_public_keys(to);
let to_npk_m_hash = to_keys.npk_m.hash();
Expand Down Expand Up @@ -205,7 +207,12 @@ contract NFT {
// We don't need to perform a check that the value overwritten by `_store_point_in_transient_storage_unsafe`
// is zero because the slot is the x-coordinate of the hiding point and hence we could only overwrite
// the value in the slot with the same value. This makes usage of the `unsafe` method safe.
NFT::at(context.this_address())._store_point_in_transient_storage_unsafe(hiding_point_slot, note_setup_payload.hiding_point).enqueue(context);
NFT::at(context.this_address())
._store_point_in_transient_storage_unsafe(
hiding_point_slot,
note_setup_payload.hiding_point,
)
.enqueue(context);

hiding_point_slot
}
Expand All @@ -227,7 +234,11 @@ contract NFT {

#[public]
#[internal]
fn _finalize_transfer_to_private_unsafe(from: AztecAddress, token_id: Field, hiding_point_slot: Field) {
fn _finalize_transfer_to_private_unsafe(
from: AztecAddress,
token_id: Field,
hiding_point_slot: Field,
) {
_finalize_transfer_to_private(from, token_id, hiding_point_slot, &mut context, storage);
}

Expand All @@ -237,7 +248,7 @@ contract NFT {
token_id: Field,
hiding_point_slot: Field,
context: &mut PublicContext,
storage: Storage<&mut PublicContext>
storage: Storage<&mut PublicContext>,
) {
let public_owners_storage = storage.public_owners.at(token_id);
assert(public_owners_storage.read().eq(from), "invalid NFT owner");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{test::utils, types::nft_note::NFTNote, NFT};
use dep::aztec::{
keys::getters::get_public_keys, prelude::{AztecAddress, NoteHeader}, oracle::random::random,
protocol_types::storage::map::derive_storage_slot_in_map
protocol_types::storage::map::derive_storage_slot_in_map,
};
use std::test::OracleMock;

Expand Down Expand Up @@ -29,16 +29,18 @@ unconstrained fn transfer_to_private_internal_orchestration() {
#[test]
unconstrained fn transfer_to_private_external_orchestration() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, nft_contract_address, _, recipient, token_id) = utils::setup_and_mint(/* with_account_contracts */ false);
let (env, nft_contract_address, _, recipient, token_id) =
utils::setup_and_mint( /* with_account_contracts */ false);

let note_randomness = random();

// We mock the Oracle to return the note randomness such that later on we can manually add the note
let _ = OracleMock::mock("getRandomField").returns(note_randomness);

// We prepare the transfer
let hiding_point_slot: Field = NFT::at(nft_contract_address).prepare_transfer_to_private(recipient).call(&mut env.private());

let hiding_point_slot: Field = NFT::at(nft_contract_address)
.prepare_transfer_to_private(recipient)
.call(&mut env.private());

// Finalize the transfer of the NFT (message sender owns the NFT in public)
NFT::at(nft_contract_address).finalize_transfer_to_private(token_id, hiding_point_slot).call(
Expand Down Expand Up @@ -93,7 +95,9 @@ unconstrained fn transfer_to_private_failure_not_an_owner() {
// (For this specific test we could set a random value for the commitment and not do the call to `prepare...`
// as the NFT owner check is before we use the value but that would made the test less robust against changes
// in the contract.)
let hiding_point_slot: Field = NFT::at(nft_contract_address).prepare_transfer_to_private(not_owner).call(&mut env.private());
let hiding_point_slot: Field = NFT::at(nft_contract_address)
.prepare_transfer_to_private(not_owner)
.call(&mut env.private());

// Try transferring someone else's public NFT
env.impersonate(not_owner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ pub unconstrained fn setup_mint_and_transfer_to_private(
let _ = OracleMock::mock("getRandomField").returns(note_randomness);

// We transfer the public NFT to private.
NFT::at(nft_contract_address).transfer_to_private(owner, minted_token_id).call(&mut env.private());
NFT::at(nft_contract_address).transfer_to_private(owner, minted_token_id).call(
&mut env.private(),
);

// TODO(#8771): We need to manually add the note because in the partial notes flow `notify_created_note_oracle`
// is not called and we don't have a `NoteProcessor` in TXE.
Expand Down

0 comments on commit e0a1ee9

Please sign in to comment.