Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions boxes/boxes/react/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract BoxReact {
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
numbers.at(owner).initialize(&mut new_number, true, owner_ovpk_m, owner_ivpk_m);
numbers.at(owner).initialize(&mut new_number, owner_ovpk_m, owner_ivpk_m);
}

#[aztec(private)]
Expand All @@ -33,7 +33,7 @@ contract BoxReact {
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
numbers.at(owner).replace(&mut new_number, true, owner_ovpk_m, owner_ivpk_m);
numbers.at(owner).replace(&mut new_number, owner_ovpk_m, owner_ivpk_m);
}

unconstrained fn getNumber(owner: AztecAddress) -> pub ValueNote {
Expand Down
4 changes: 2 additions & 2 deletions boxes/boxes/vanilla/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ contract Vanilla {
fn constructor(number: Field, owner: AztecAddress, owner_npk_m_hash: Field, owner_ovpk_m: GrumpkinPoint, owner_ivpk_m: GrumpkinPoint) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
numbers.at(owner).initialize(&mut new_number, true, owner_ovpk_m, owner_ivpk_m);
numbers.at(owner).initialize(&mut new_number, owner_ovpk_m, owner_ivpk_m);
}

#[aztec(private)]
fn setNumber(number: Field, owner: AztecAddress, owner_npk_m_hash: Field, owner_ovpk_m: GrumpkinPoint, owner_ivpk_m: GrumpkinPoint) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
numbers.at(owner).replace(&mut new_number, true, owner_ovpk_m, owner_ivpk_m);
numbers.at(owner).replace(&mut new_number, owner_ovpk_m, owner_ivpk_m);
}

unconstrained fn getNumber(owner: AztecAddress) -> pub ValueNote {
Expand Down
5 changes: 1 addition & 4 deletions noir-projects/aztec-nr/aztec/src/note/lifecycle.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub fn create_note<Note, N, M>(
context: &mut PrivateContext,
storage_slot: Field,
note: &mut Note,
broadcast: bool,
ovpk_m: GrumpkinPoint,
ivpk_m: GrumpkinPoint
) where Note: NoteInterface<N, M> {
Expand Down Expand Up @@ -38,9 +37,7 @@ pub fn create_note<Note, N, M>(

context.push_new_note_hash(inner_note_hash);

if broadcast {
Note::broadcast(*note, context, storage_slot, ovpk_m, ivpk_m);
}
Note::broadcast(*note, context, storage_slot, ovpk_m, ivpk_m);
}

pub fn create_note_hash_from_public<Note, N, M>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ impl<Note> PrivateImmutable<Note, &mut PrivateContext> {
pub fn initialize<N, M>(
self,
note: &mut Note,
broadcast: bool,
ovpk_m: GrumpkinPoint,
ivpk_m: GrumpkinPoint
) where Note: NoteInterface<N, M> {
// Nullify the storage slot.
let nullifier = self.compute_initialization_nullifier();
self.context.push_new_nullifier(nullifier, 0);

create_note(self.context, self.storage_slot, note, broadcast, ovpk_m, ivpk_m);
create_note(self.context, self.storage_slot, note, ovpk_m, ivpk_m);
}
// docs:end:initialize

Expand Down
28 changes: 5 additions & 23 deletions noir-projects/aztec-nr/aztec/src/state_vars/private_mutable.nr
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,21 @@ impl<Note> PrivateMutable<Note, &mut PrivateContext> {
pub fn initialize<N, M>(
self,
note: &mut Note,
broadcast: bool,
ovpk_m: GrumpkinPoint,
ivpk_m: GrumpkinPoint
) where Note: NoteInterface<N, M> {
// Nullify the storage slot.
let nullifier = self.compute_initialization_nullifier();
self.context.push_new_nullifier(nullifier, 0);

create_note(self.context, self.storage_slot, note, broadcast, ovpk_m, ivpk_m);
create_note(self.context, self.storage_slot, note, ovpk_m, ivpk_m);
}
// docs:end:initialize

// docs:start:replace
pub fn replace<N, M>(
self,
new_note: &mut Note,
broadcast: bool,
ovpk_m: GrumpkinPoint,
ivpk_m: GrumpkinPoint
) where Note: NoteInterface<N, M> {
Expand All @@ -77,21 +75,13 @@ impl<Note> PrivateMutable<Note, &mut PrivateContext> {
destroy_note(self.context, prev_note);

// Add replacement note.
create_note(
self.context,
self.storage_slot,
new_note,
broadcast,
ovpk_m,
ivpk_m
);
create_note(self.context, self.storage_slot, new_note, ovpk_m, ivpk_m);
}
// docs:end:replace

pub fn initialize_or_replace<N, M>(
self,
note: &mut Note,
broadcast: bool,
ovpk_m: GrumpkinPoint,
ivpk_m: GrumpkinPoint
) where Note: NoteInterface<N, M> {
Expand All @@ -108,16 +98,15 @@ impl<Note> PrivateMutable<Note, &mut PrivateContext> {
// This means that an honest oracle will assist the prover to produce a valid proof, while a malicious oracle
// (i.e. one that returns an incorrect value for is_initialized) will simply fail to produce a proof.
if (!is_initialized) {
self.initialize(note, broadcast, ovpk_m, ivpk_m);
self.initialize(note, ovpk_m, ivpk_m);
} else {
self.replace(note, broadcast, ovpk_m, ivpk_m)
self.replace(note, ovpk_m, ivpk_m)
}
}

// docs:start:get_note
pub fn get_note<N, M>(
self,
broadcast: bool,
ovpk_m: GrumpkinPoint,
ivpk_m: GrumpkinPoint
) -> Note where Note: NoteInterface<N, M> {
Expand All @@ -128,14 +117,7 @@ impl<Note> PrivateMutable<Note, &mut PrivateContext> {

// Add the same note again.
// Because a nonce is added to every note in the kernel, its nullifier will be different.
create_note(
self.context,
self.storage_slot,
&mut note,
broadcast,
ovpk_m,
ivpk_m
);
create_note(self.context, self.storage_slot, &mut note, ovpk_m, ivpk_m);

note
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ fn test_initialize_or_replace_without_nullifier() {

let ovpk_m: GrumpkinPoint = zeroed();
let ivpk_m: GrumpkinPoint = zeroed();
let broadcast = false;

let value = 42;
let mut note = MockNote::new(value).contract_address(contract_address).storage_slot(storage_slot).build();

OracleMock::mock("checkNullifierExists").returns(0);
state_var.initialize_or_replace(&mut note, broadcast, ovpk_m, ivpk_m);
state_var.initialize_or_replace(&mut note, ovpk_m, ivpk_m);

// Since we reported there was no nullifier, we should initialize and see the following side-effects:
// - a new note being created
Expand Down
3 changes: 1 addition & 2 deletions noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ impl<Note> PrivateSet<Note, &mut PrivateContext> {
pub fn insert<N, M>(
self,
note: &mut Note,
broadcast: bool,
ovpk_m: GrumpkinPoint,
ivpk_m: GrumpkinPoint
) where Note: NoteInterface<N, M> {
create_note(self.context, self.storage_slot, note, broadcast, ovpk_m, ivpk_m);
create_note(self.context, self.storage_slot, note, ovpk_m, ivpk_m);
}
// docs:end:insert

Expand Down
6 changes: 3 additions & 3 deletions noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ impl NoteInterface<MOCK_NOTE_LENGTH, MOCK_NOTE_BYTES_LENGTH> for MockNote {
}

fn broadcast(self, context: &mut PrivateContext, slot: Field, ovpk_m: GrumpkinPoint, ivpk_m: GrumpkinPoint) {
assert(
false, "MockNote does not support broadcast."
);
// MockNote does not support broadcasting. Since this function gets called in various places anyway we will verify
// that the dev really did not intend to broadcast by checking that zero keys were passed in.
assert(ovpk_m.is_zero() & ivpk_m.is_zero(), "MockNote does not support broadcast.");
}

fn to_be_bytes(self, storage_slot: Field) -> [u8; MOCK_NOTE_BYTES_LENGTH] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<Context> EasyPrivateUint<&mut PrivateContext> {

// Insert the new note to the owner's set of notes.
// docs:start:insert
self.set.insert(&mut addend_note, true, outgoing_viewer, owner_ivpk_m);
self.set.insert(&mut addend_note, outgoing_viewer, owner_ivpk_m);
// docs:end:insert
}

Expand Down Expand Up @@ -66,11 +66,6 @@ impl<Context> EasyPrivateUint<&mut PrivateContext> {
// Creates change note for the owner.
let result_value = minuend - subtrahend;
let mut result_note = ValueNote::new(result_value as Field, owner_npk_m_hash);
self.set.insert(
&mut result_note,
result_value != 0,
outgoing_viewer_ovpk_m,
owner_ivpk_m
);
self.set.insert(&mut result_note, outgoing_viewer_ovpk_m, owner_ivpk_m);
}
}
7 changes: 1 addition & 6 deletions noir-projects/aztec-nr/value-note/src/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ pub fn increment(

let mut note = ValueNote::new(amount, recipient_npk_m_hash);
// Insert the new note to the owner's set of notes and emit the log if value is non-zero.
balance.insert(
&mut note,
amount != 0,
outgoing_viewer_ovpk_m,
recipient_ivpk_m
);
balance.insert(&mut note, outgoing_viewer_ovpk_m, recipient_ivpk_m);
}

// Find some of the `owner`'s notes whose values add up to the `amount`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ contract AppSubscription {
assert(context.msg_sender().to_field() == 0);
assert_current_call_valid_authwit(&mut context, user_address);

let mut note = storage.subscriptions.at(user_address).get_note(false, GrumpkinPoint::zero(), GrumpkinPoint::zero());
assert(note.remaining_txs as u64 > 0, "you're out of txs");

note.remaining_txs -= 1;

let header = context.get_header();
// We are emitting both the outgoing and the incoming logs to the subscriber here because passing a separate
// outgoing_viewer arg to entrypoint function is impractical and the outgoing are not so valuable here.
let subscriber_ovpk_m = header.get_ovpk_m(&mut context, user_address);
let subscriber_ivpk_m = header.get_ivpk_m(&mut context, user_address);
storage.subscriptions.at(user_address).replace(&mut note, true, subscriber_ovpk_m, subscriber_ivpk_m);

let mut note = storage.subscriptions.at(user_address).get_note(subscriber_ovpk_m, subscriber_ivpk_m);
assert(note.remaining_txs as u64 > 0, "you're out of txs");

note.remaining_txs -= 1;

storage.subscriptions.at(user_address).replace(&mut note, subscriber_ovpk_m, subscriber_ivpk_m);

context.set_as_fee_payer();

Expand Down Expand Up @@ -120,12 +121,7 @@ contract AppSubscription {
let subscriber_ivpk_m = header.get_ivpk_m(&mut context, subscriber_address);

let mut subscription_note = SubscriptionNote::new(subscriber_npk_m_hash, expiry_block_number, tx_count);
storage.subscriptions.at(subscriber_address).initialize_or_replace(
&mut subscription_note,
true,
msg_sender_ovpk_m,
subscriber_ivpk_m
);
storage.subscriptions.at(subscriber_address).initialize_or_replace(&mut subscription_note, msg_sender_ovpk_m, subscriber_ivpk_m);
}

unconstrained fn is_initialized(subscriber_address: AztecAddress) -> pub bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Deck<&mut PrivateContext> {
let mut inserted_cards = &[];
for card in cards {
let mut card_note = CardNote::from_card(card, owner_npk_m_hash);
self.set.insert(&mut card_note.note, true, msg_sender_ovpk_m, owner_ivpk_m);
self.set.insert(&mut card_note.note, msg_sender_ovpk_m, owner_ivpk_m);
inserted_cards = inserted_cards.push_back(card_note);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract Child {
let owner_ivpk_m = header.get_ivpk_m(&mut context, owner);

let mut note = ValueNote::new(new_value, owner_npk_m_hash);
storage.a_map_with_private_values.at(owner).insert(&mut note, true, msg_sender_ovpk_m, owner_ivpk_m);
storage.a_map_with_private_values.at(owner).insert(&mut note, msg_sender_ovpk_m, owner_ivpk_m);
new_value
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ contract Crowdfunding {
let donor_ovpk_m = header.get_ovpk_m(&mut context, donor);
let donor_ivpk_m = header.get_ivpk_m(&mut context, donor);
let mut note = ValueNote::new(amount as Field, donor_npk_m_hash);
storage.donation_receipts.insert(&mut note, true, donor_ovpk_m, donor_ivpk_m);
storage.donation_receipts.insert(&mut note, donor_ovpk_m, donor_ivpk_m);
}
// docs:end:donate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract DelegatedOn {
let owner_ivpk_m = header.get_ivpk_m(&mut context, owner);

let mut note = ValueNote::new(new_value, owner_npk_m_hash);
storage.a_map_with_private_values.at(owner).insert(&mut note, true, msg_sender_ovpk_m, owner_ivpk_m);
storage.a_map_with_private_values.at(owner).insert(&mut note, msg_sender_ovpk_m, owner_ivpk_m);
new_value
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ contract DocsExample {
let msg_sender_ivpk_m = header.get_ivpk_m(&mut context, context.msg_sender());

let mut new_card = CardNote::new(points, randomness, msg_sender_npk_m_hash);
storage.private_immutable.initialize(&mut new_card, true, msg_sender_ovpk_m, msg_sender_ivpk_m);
storage.private_immutable.initialize(&mut new_card, msg_sender_ovpk_m, msg_sender_ivpk_m);
}
// docs:end:initialize-private-mutable

Expand All @@ -188,7 +188,7 @@ contract DocsExample {

let mut legendary_card = CardNote::new(points, randomness, msg_sender_npk_m_hash);
// create and broadcast note
storage.legendary_card.initialize(&mut legendary_card, true, msg_sender_ovpk_m, msg_sender_ivpk_m);
storage.legendary_card.initialize(&mut legendary_card, msg_sender_ovpk_m, msg_sender_ivpk_m);
}

#[aztec(private)]
Expand All @@ -200,7 +200,7 @@ contract DocsExample {

for i in 0..amounts.len() {
let mut note = CardNote::new(amounts[i], 1, msg_sender_npk_m_hash);
storage.set.insert(&mut note, true, msg_sender_ovpk_m, msg_sender_ivpk_m);
storage.set.insert(&mut note, msg_sender_ovpk_m, msg_sender_ivpk_m);
}
}

Expand All @@ -212,7 +212,7 @@ contract DocsExample {
let msg_sender_ivpk_m = header.get_ivpk_m(&mut context, context.msg_sender());

let mut note = CardNote::new(amount, randomness, msg_sender_npk_m_hash);
storage.set.insert(&mut note, true, msg_sender_ovpk_m, msg_sender_ivpk_m);
storage.set.insert(&mut note, msg_sender_ovpk_m, msg_sender_ivpk_m);
}

// docs:start:state_vars-NoteGetterOptionsComparatorExampleNoir
Expand All @@ -238,7 +238,7 @@ contract DocsExample {
let msg_sender_ivpk_m = header.get_ivpk_m(&mut context, context.msg_sender());

let mut new_card = CardNote::new(points, randomness, msg_sender_npk_m_hash);
storage.legendary_card.replace(&mut new_card, true, msg_sender_ovpk_m, msg_sender_ivpk_m);
storage.legendary_card.replace(&mut new_card, msg_sender_ovpk_m, msg_sender_ivpk_m);
DocsExample::at(context.this_address()).update_leader(context.msg_sender(), points).enqueue(&mut context);
}

Expand All @@ -247,20 +247,20 @@ contract DocsExample {
// Ensure `points` > current value
// Also serves as a e2e test that you can `get_note()` and then `replace()`

// docs:start:state_vars-PrivateMutableGet
let card = storage.legendary_card.get_note(false, GrumpkinPoint::zero(), GrumpkinPoint::zero());
// docs:end:state_vars-PrivateMutableGet

let points = card.points + 1;

let header = context.get_header();
let msg_sender_npk_m_hash = header.get_npk_m_hash(&mut context, context.msg_sender());
let msg_sender_ovpk_m = header.get_ovpk_m(&mut context, context.msg_sender());
let msg_sender_ivpk_m = header.get_ivpk_m(&mut context, context.msg_sender());

// docs:start:state_vars-PrivateMutableGet
let card = storage.legendary_card.get_note(msg_sender_ovpk_m, msg_sender_ivpk_m);
// docs:end:state_vars-PrivateMutableGet

let points = card.points + 1;

let mut new_card = CardNote::new(points, card.randomness, msg_sender_npk_m_hash);
// docs:start:state_vars-PrivateMutableReplace
storage.legendary_card.replace(&mut new_card, true, msg_sender_ovpk_m, msg_sender_ivpk_m);
storage.legendary_card.replace(&mut new_card, msg_sender_ovpk_m, msg_sender_ivpk_m);
// docs:end:state_vars-PrivateMutableReplace

DocsExample::at(context.this_address()).update_leader(context.msg_sender(), points).enqueue(&mut context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract EcdsaAccount {
let this_ivpk_m = header.get_ivpk_m(&mut context, this);

let mut pub_key_note = EcdsaPublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, this_npk_m_hash);
storage.public_key.initialize(&mut pub_key_note, true, this_ovpk_m, this_ivpk_m);
storage.public_key.initialize(&mut pub_key_note, this_ovpk_m, this_ivpk_m);
}

// Note: If you globally change the entrypoint signature don't forget to update default_entrypoint.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract Escrow {
let owner_ivpk_m = header.get_ivpk_m(&mut context, owner);

let mut note = AddressNote::new(owner, owner_npk_m_hash);
storage.owner.initialize(&mut note, true, msg_sender_ovpk_m, owner_ivpk_m);
storage.owner.initialize(&mut note, msg_sender_ovpk_m, owner_ivpk_m);
}

// Withdraws balance. Requires that msg.sender is the owner.
Expand Down
Loading