Skip to content

Commit

Permalink
Apply noir formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
nventuro committed Aug 14, 2024
1 parent 398edac commit 11a0211
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::{
context::PrivateContext, event::event_interface::EventInterface,
encrypted_logs::payload::compute_encrypted_event_log, keys::getters::get_current_public_keys,
oracle::logs_traits::LensForEncryptedEvent,
oracle::unsafe_rand::unsafe_rand
oracle::logs_traits::LensForEncryptedEvent, oracle::unsafe_rand::unsafe_rand
};
use dep::protocol_types::{address::AztecAddress, point::Point, hash::sha256_to_field};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
context::PrivateContext, note::{note_emission::NoteEmission, note_interface::NoteInterface},
keys::getters::get_current_public_keys,
encrypted_logs::payload::compute_encrypted_note_log, oracle::logs_traits::LensForEncryptedLog
keys::getters::get_current_public_keys, encrypted_logs::payload::compute_encrypted_note_log,
oracle::logs_traits::LensForEncryptedLog
};
use dep::protocol_types::{
hash::sha256_to_field, address::AztecAddress, point::Point, abis::note_hash::NoteHash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dep::aztec::{
context::PrivateContext, protocol_types::{address::AztecAddress},
note::note_getter_options::NoteGetterOptions, state_vars::PrivateSet,
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note,
keys::getters::get_current_public_keys,
keys::getters::get_current_public_keys
};
use dep::value_note::{filter::filter_notes_min_sum, value_note::ValueNote};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ contract AppSubscription {
SharedImmutable
},
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note,
keys::getters::get_current_public_keys,
protocol_types::constants::MAX_FIELD_VALUE
keys::getters::get_current_public_keys, protocol_types::constants::MAX_FIELD_VALUE
};
use authwit::{auth_witness::get_auth_witness, auth::assert_current_call_valid_authwit};
use token::Token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use dep::aztec::prelude::{AztecAddress, FunctionSelector, PrivateContext, NoteHe
use dep::aztec::{
context::UnconstrainedContext,
protocol_types::{traits::{ToField, Serialize, FromField}, constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL},
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_with_keys, keys::getters::get_current_public_keys,
note::note_getter::view_notes, state_vars::PrivateSet, note::constants::MAX_NOTES_PER_PAGE
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_with_keys,
keys::getters::get_current_public_keys, note::note_getter::view_notes, state_vars::PrivateSet,
note::constants::MAX_NOTES_PER_PAGE
};
use dep::value_note::{value_note::{ValueNote, VALUE_NOTE_LEN}};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ contract DocsExample {
#[aztec(private)]
fn insert_note(amount: u8, randomness: Field) {
let sender_npk_m_hash = get_current_public_keys(&mut context, context.msg_sender()).npk_m.hash();

let mut note = CardNote::new(amount, randomness, sender_npk_m_hash);
storage.set.insert(&mut note).emit(encode_and_encrypt_note(&mut context, context.msg_sender(), context.msg_sender()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ contract PendingNoteHashes {
let owner_npk_m_hash = owner_keys.npk_m.hash();
let owner_ivpk_m = owner_keys.ivpk_m;
let outgoing_viewer_ovpk_m = get_current_public_keys(&mut context, outgoing_viewer).ovpk_m;

let mut good_note = ValueNote::new(10, owner_npk_m_hash);
// Insert good note with real log
owner_balance.insert(&mut good_note).emit(encode_and_encrypt_note(&mut context, outgoing_viewer, owner));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ contract SchnorrAccount {
entrypoint::{app::AppPayload, fee::FeePayload}, account::AccountActions,
auth_witness::get_auth_witness, auth::{compute_authwit_nullifier, compute_authwit_message_hash}
};
use dep::aztec::{
hash::compute_siloed_nullifier,
keys::getters::get_current_public_keys
};
use dep::aztec::{hash::compute_siloed_nullifier, keys::getters::get_current_public_keys};
use dep::aztec::oracle::get_nullifier_membership_witness::get_low_nullifier_membership_witness;

use crate::public_key_note::{PublicKeyNote, PUBLIC_KEY_NOTE_LEN};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ contract Test {
#[aztec(private)]
fn get_master_incoming_viewing_public_key(address: AztecAddress) -> [Field; 2] {
let ivpk_m = get_current_public_keys(&mut context, address).ivpk_m;

[ivpk_m.x, ivpk_m.y]
}

Expand Down
18 changes: 12 additions & 6 deletions noir-projects/noir-contracts/contracts/token_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract Token {
},
encrypted_event_emission::{encode_and_encrypt_event, encode_and_encrypt_event_with_keys_unconstrained}
},
keys::getters::get_current_public_keys,
keys::getters::get_current_public_keys
};

// docs:start:import_authwit
Expand Down Expand Up @@ -335,7 +335,7 @@ contract Token {
#[aztec(private)]
fn transfer(to: AztecAddress, amount: Field) {
let from = context.msg_sender();

let from_keys = get_current_public_keys(&mut context, from);
let to_keys = get_current_public_keys(&mut context, to);

Expand All @@ -355,15 +355,21 @@ contract Token {
INITIAL_TRANSFER_CALL_MAX_NOTES
);

storage.balances.add(from, change).emit(encode_and_encrypt_note_with_keys_unconstrained(&mut context, from_keys.ivpk_m, from_keys.ovpk_m, from));
storage.balances.add(from, change).emit(
encode_and_encrypt_note_with_keys_unconstrained(&mut context, from_keys.ivpk_m, from_keys.ovpk_m, from)
);

storage.balances.add(to, amount).emit(encode_and_encrypt_note_with_keys_unconstrained(&mut context, from_keys.ivpk_m, to_keys.ivpk_m, to));
storage.balances.add(to, amount).emit(
encode_and_encrypt_note_with_keys_unconstrained(&mut context, from_keys.ivpk_m, to_keys.ivpk_m, to)
);

// We don't constrain encryption of the note log in `transfer` (unlike in `transfer_from`) 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).
Transfer { from, to, amount: amount.to_field() }.emit(encode_and_encrypt_event_with_keys_unconstrained(&mut context, from_keys.ivpk_m, to_keys.ivpk_m, to));
Transfer { from, to, amount: amount.to_field() }.emit(
encode_and_encrypt_event_with_keys_unconstrained(&mut context, from_keys.ivpk_m, to_keys.ivpk_m, to)
);
}
// docs:end:transfer

Expand Down Expand Up @@ -443,7 +449,7 @@ contract Token {
assert(nonce == 0, "invalid nonce");
}
// docs:end:assert_current_call_valid_authwit

let from_keys = get_current_public_keys(&mut context, from);
let to_keys = get_current_public_keys(&mut context, to);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use dep::aztec::{
protocol_types::constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
note::{
note_getter::view_notes, note_getter_options::SortOrder,
note_emission::{NoteEmission, OuterNoteEmission},
note_emission::{NoteEmission, OuterNoteEmission}
},
keys::getters::get_current_public_keys
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ contract TokenWithRefunds {
#[aztec(private)]
fn transfer(to: AztecAddress, amount: Field) {
let from = context.msg_sender();

let from_keys = get_current_public_keys(&mut context, from);
let to_keys = get_current_public_keys(&mut context, to);

Expand All @@ -351,15 +351,21 @@ contract TokenWithRefunds {
INITIAL_TRANSFER_CALL_MAX_NOTES
);

storage.balances.add(from, change).emit(encode_and_encrypt_note_with_keys_unconstrained(&mut context, from_keys.ovpk_m, from_keys.ivpk_m, from));
storage.balances.add(from, change).emit(
encode_and_encrypt_note_with_keys_unconstrained(&mut context, from_keys.ovpk_m, from_keys.ivpk_m, from)
);

storage.balances.add(to, amount).emit(encode_and_encrypt_note_with_keys_unconstrained(&mut context, from_keys.ovpk_m, to_keys.ivpk_m, to));
storage.balances.add(to, amount).emit(
encode_and_encrypt_note_with_keys_unconstrained(&mut context, from_keys.ovpk_m, to_keys.ivpk_m, to)
);

// We don't constrain encryption of the note log in `transfer` (unlike in `transfer_from`) 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).
Transfer2 { from, to, amount: amount.to_field() }.emit(encode_and_encrypt_event_with_keys_unconstrained(&mut context, from_keys.ovpk_m, to_keys.ivpk_m, to));
Transfer2 { from, to, amount: amount.to_field() }.emit(
encode_and_encrypt_event_with_keys_unconstrained(&mut context, from_keys.ovpk_m, to_keys.ivpk_m, to)
);
}
// docs:end:transfer

Expand Down Expand Up @@ -439,7 +445,7 @@ contract TokenWithRefunds {
assert(nonce == 0, "invalid nonce");
}
// docs:end:assert_current_call_valid_authwit

let from_keys = get_current_public_keys(&mut context, from);
let to_keys = get_current_public_keys(&mut context, to);

Expand Down Expand Up @@ -545,7 +551,9 @@ contract TokenWithRefunds {
U128::from_integer(funded_amount),
INITIAL_TRANSFER_CALL_MAX_NOTES
);
storage.balances.add(user, change).emit(encode_and_encrypt_note_with_keys_unconstrained(&mut context, user_keys.ovpk_m, user_keys.ivpk_m, user));
storage.balances.add(user, change).emit(
encode_and_encrypt_note_with_keys_unconstrained(&mut context, user_keys.ovpk_m, user_keys.ivpk_m, user)
);

// 4. We create the partial notes for the fee payer and the user.
// --> Called "partial" because they don't have the amount set yet (that will be done in `complete_refund(...)`).
Expand Down

0 comments on commit 11a0211

Please sign in to comment.