Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Oct 31, 2024
1 parent 651dd5c commit c3f9087
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 17 deletions.
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 @@ -26,7 +26,7 @@ contract BoxReact {
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner));
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner, context.msg_sender()));
}

#[private]
Expand All @@ -38,7 +38,7 @@ contract BoxReact {
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner));
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner, context.msg_sender()));
}

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 @@ -26,7 +26,7 @@ contract Vanilla {
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner));
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner, context.msg_sender()));
}

#[private]
Expand All @@ -38,7 +38,7 @@ contract Vanilla {
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner));
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner, context.msg_sender()));
}

unconstrained fn getNumber(owner: AztecAddress) -> pub ValueNote {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<Context> EasyPrivateUint<Context> {

impl EasyPrivateUint<&mut PrivateContext> {
// Very similar to `value_note::utils::increment`.
pub fn add(self, addend: u64, owner: AztecAddress, outgoing_viewer: AztecAddress) {
pub fn add(self, addend: u64, owner: AztecAddress, outgoing_viewer: AztecAddress, sender: AztecAddress) {
let outgoing_viewer_keys = get_public_keys(outgoing_viewer);
// Creates new note for the owner.
let mut addend_note = ValueNote::new(addend as Field, owner);
Expand All @@ -33,12 +33,13 @@ impl EasyPrivateUint<&mut PrivateContext> {
self.context,
outgoing_viewer_keys.ovpk_m,
owner,
sender,
));
// docs:end:insert
}

// Very similar to `value_note::utils::decrement`.
pub fn sub(self, subtrahend: u64, owner: AztecAddress, outgoing_viewer: AztecAddress) {
pub fn sub(self, subtrahend: u64, owner: AztecAddress, outgoing_viewer: AztecAddress, sender: AztecAddress) {
let outgoing_viewer_keys = get_public_keys(outgoing_viewer);

// docs:start:pop_notes
Expand All @@ -63,6 +64,7 @@ impl EasyPrivateUint<&mut PrivateContext> {
self.context,
outgoing_viewer_keys.ovpk_m,
owner,
sender,
));
}
}
8 changes: 6 additions & 2 deletions noir-projects/aztec-nr/value-note/src/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub fn increment(
amount: Field,
recipient: AztecAddress,
outgoing_viewer: AztecAddress, // docs:end:increment_args
sender: AztecAddress,
) {
let outgoing_viewer_ovpk_m = get_public_keys(outgoing_viewer).ovpk_m;

Expand All @@ -32,6 +33,7 @@ pub fn increment(
balance.context,
outgoing_viewer_ovpk_m,
recipient,
sender,
));
}

Expand All @@ -44,8 +46,9 @@ pub fn decrement(
amount: Field,
owner: AztecAddress,
outgoing_viewer: AztecAddress,
sender: AztecAddress,
) {
let sum = decrement_by_at_most(balance, amount, owner, outgoing_viewer);
let sum = decrement_by_at_most(balance, amount, owner, outgoing_viewer, sender);
assert(sum == amount, "Balance too low");
}

Expand All @@ -62,6 +65,7 @@ pub fn decrement_by_at_most(
max_amount: Field,
owner: AztecAddress,
outgoing_viewer: AztecAddress,
sender: AztecAddress,
) -> Field {
let options = create_note_getter_options_for_decreasing_balance(max_amount);
let notes = balance.pop_notes(options);
Expand All @@ -80,7 +84,7 @@ pub fn decrement_by_at_most(
change_value = decremented - max_amount;
decremented -= change_value;
}
increment(balance, change_value, owner, outgoing_viewer);
increment(balance, change_value, owner, outgoing_viewer, sender);

decremented
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ contract AppSubscription {
&mut context,
keys.ovpk_m,
user_address,
user_address,
));

context.set_as_fee_payer();
Expand Down Expand Up @@ -116,7 +117,7 @@ contract AppSubscription {
let mut subscription_note =
SubscriptionNote::new(subscriber, expiry_block_number, tx_count);
storage.subscriptions.at(subscriber).initialize_or_replace(&mut subscription_note).emit(
encode_and_encrypt_note(&mut context, msg_sender_ovpk_m, subscriber),
encode_and_encrypt_note(&mut context, msg_sender_ovpk_m, subscriber, context.msg_sender()),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ impl Deck<&mut PrivateContext> {
self.set.context,
msg_sender_ovpk_m,
owner,
self.set.context.msg_sender(),
));
inserted_cards = inserted_cards.push_back(card_note);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ contract Child {
&mut context,
owner_ovpk_m,
owner,
context.msg_sender(),
));
new_value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ contract Crowdfunding {
&mut context,
donor_ovpk_m,
donor,
donor,
));
}
// docs:end:donate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ contract DocsExample {
&mut context,
msg_sender_ovpk_m,
context.msg_sender(),
context.msg_sender(),
));
}
// docs:end:initialize-private-mutable
Expand All @@ -196,6 +197,7 @@ contract DocsExample {
&mut context,
msg_sender_ovpk_m,
context.msg_sender(),
context.msg_sender(),
));
}

Expand All @@ -209,6 +211,7 @@ contract DocsExample {
&mut context,
msg_sender_ovpk_m,
context.msg_sender(),
context.msg_sender(),
));
}
}
Expand All @@ -221,6 +224,7 @@ contract DocsExample {
&mut context,
msg_sender_ovpk_m,
context.msg_sender(),
context.msg_sender(),
));
}
// docs:start:state_vars-NoteGetterOptionsComparatorExampleNoir
Expand All @@ -238,6 +242,7 @@ contract DocsExample {
&mut context,
msg_sender_ovpk_m,
context.msg_sender(),
context.msg_sender(),
));
DocsExample::at(context.this_address()).update_leader(context.msg_sender(), points).enqueue(
&mut context,
Expand All @@ -259,6 +264,7 @@ contract DocsExample {
&mut context,
msg_sender_ovpk_m,
context.msg_sender(),
context.msg_sender(),
));
// docs:end:state_vars-PrivateMutableReplace
DocsExample::at(context.this_address()).update_leader(context.msg_sender(), points).enqueue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ contract EcdsaKAccount {
&mut context,
this_ovpk_m,
this,
this,
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ contract EcdsaRAccount {
&mut context,
this_ovpk_m,
this,
this,
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ contract Escrow {
&mut context,
msg_sender_ovpk_m,
owner,
context.msg_sender(),
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ contract InclusionProofs {
&mut context,
msg_sender_ovpk_m,
owner,
context.msg_sender(),
));
}
// docs:end:create_note
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ contract NFT {
&mut context,
from_ovpk_m,
to,
from,
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ contract PendingNoteHashes {
&mut context,
outgoing_viewer_ovpk_m,
owner,
context.msg_sender(),
));

let options = NoteGetterOptions::with_filter(filter_notes_min_sum, amount);
Expand Down Expand Up @@ -96,6 +97,7 @@ contract PendingNoteHashes {
&mut context,
outgoing_viewer_ovpk_m,
owner,
context.msg_sender(),
));
}

Expand All @@ -120,6 +122,7 @@ contract PendingNoteHashes {
&mut context,
outgoing_viewer_ovpk_m,
owner,
context.msg_sender(),
));
}

Expand All @@ -136,10 +139,10 @@ contract PendingNoteHashes {
// Insert note
let emission = owner_balance.insert(&mut note);

emission.emit(encode_and_encrypt_note(&mut context, outgoing_viewer_ovpk_m, owner));
emission.emit(encode_and_encrypt_note(&mut context, outgoing_viewer_ovpk_m, owner, context.msg_sender()));

// Emit note again
emission.emit(encode_and_encrypt_note(&mut context, outgoing_viewer_ovpk_m, owner));
emission.emit(encode_and_encrypt_note(&mut context, outgoing_viewer_ovpk_m, owner, context.msg_sender()));
}

// Nested/inner function to get a note and confirm it matches the expected value
Expand Down Expand Up @@ -359,6 +362,7 @@ contract PendingNoteHashes {
&mut context,
outgoing_viewer_ovpk_m,
owner,
context.msg_sender(),
));

// We will emit a note log with an incorrect preimage to ensure the pxe throws
Expand All @@ -372,6 +376,7 @@ contract PendingNoteHashes {
&mut context,
outgoing_viewer_ovpk_m,
owner,
context.msg_sender(),
));
}

Expand All @@ -392,6 +397,7 @@ contract PendingNoteHashes {
context,
outgoing_viewer_ovpk_m,
owner,
context.msg_sender(),
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ contract SchnorrAccount {
&mut context,
this_ovpk_m,
this,
this,
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract Spam {

for _ in 0..MAX_NOTE_HASHES_PER_CALL {
storage.balances.at(caller).add(caller, U128::from_integer(amount)).emit(
encode_and_encrypt_note_unconstrained(&mut context, caller_ovpk_m, caller),
encode_and_encrypt_note_unconstrained(&mut context, caller_ovpk_m, caller, caller),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ contract StaticChild {
&mut context,
msg_sender_ovpk_m,
owner,
context.msg_sender(),
));
new_value
}
Expand All @@ -70,6 +71,7 @@ contract StaticChild {
&mut context,
outgoing_viewer_ovpk_m,
owner,
context.msg_sender(),
));
new_value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ contract Test {
&mut context,
outgoing_viewer_ovpk_m,
owner,
context.msg_sender(),
));
}

Expand Down Expand Up @@ -343,6 +344,7 @@ contract Test {
&mut context,
msg_sender_ovpk_m,
owner,
context.msg_sender(),
));
storage_slot += 1;
Test::at(context.this_address())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ contract TokenBlacklist {
// TODO: constrain encryption below - we are using unconstrained here only becuase of the following Noir issue
// https://github.com/noir-lang/noir/issues/5771
storage.balances.add(to, U128::from_integer(amount)).emit(
encode_and_encrypt_note_unconstrained(&mut context, msg_sender_ovpk_m, to),
encode_and_encrypt_note_unconstrained(&mut context, msg_sender_ovpk_m, to, context.msg_sender()),
);
}

Expand All @@ -212,7 +212,7 @@ contract TokenBlacklist {
// TODO: constrain encryption below - we are using unconstrained here only becuase of the following Noir issue
// https://github.com/noir-lang/noir/issues/5771
storage.balances.sub(from, U128::from_integer(amount)).emit(
encode_and_encrypt_note_unconstrained(&mut context, from_ovpk_m, from),
encode_and_encrypt_note_unconstrained(&mut context, from_ovpk_m, from, from),
);

TokenBlacklist::at(context.this_address())._increase_public_balance(to, amount).enqueue(
Expand Down Expand Up @@ -241,11 +241,13 @@ contract TokenBlacklist {
&mut context,
from_ovpk_m,
from,
from,
));
storage.balances.add(to, amount).emit(encode_and_encrypt_note_unconstrained(
&mut context,
from_ovpk_m,
to,
from,
));
}

Expand All @@ -264,7 +266,7 @@ contract TokenBlacklist {
// TODO: constrain encryption below - we are using unconstrained here only becuase of the following Noir issue
// https://github.com/noir-lang/noir/issues/5771
storage.balances.sub(from, U128::from_integer(amount)).emit(
encode_and_encrypt_note_unconstrained(&mut context, from_ovpk_m, from),
encode_and_encrypt_note_unconstrained(&mut context, from_ovpk_m, from, from),
);

TokenBlacklist::at(context.this_address())._reduce_total_supply(amount).enqueue(&mut context);
Expand Down
Loading

0 comments on commit c3f9087

Please sign in to comment.