From 27b1edc6f0bcb485a66dacfb3298a555f276a813 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Tue, 29 Oct 2024 13:38:52 +0000 Subject: [PATCH] init --- .../encrypted_event_emission.nr | 33 ++++++++++++++----- .../encrypted_logs/encrypted_note_emission.nr | 30 ++++++++++++----- .../aztec/src/encrypted_logs/payload.nr | 6 ++++ .../aztec-nr/aztec/src/macros/notes/mod.nr | 3 +- .../src/easy_private_uint.nr | 16 +++++++-- .../app_subscription_contract/src/main.nr | 7 +++- .../benchmarking_contract/src/main.nr | 16 +++++++-- .../contracts/counter_contract/src/main.nr | 4 +-- .../easy_private_token_contract/src/main.nr | 8 ++--- .../contracts/nft_contract/src/main.nr | 3 +- .../pending_note_hashes_contract/src/main.nr | 14 ++++++-- .../stateful_test_contract/src/main.nr | 12 +++---- .../contracts/test_contract/src/main.nr | 2 ++ .../contracts/test_log_contract/src/main.nr | 3 ++ .../token_blacklist_contract/src/main.nr | 7 +++- .../contracts/token_contract/src/main.nr | 14 +++++--- 16 files changed, 134 insertions(+), 44 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr index 967bae1b570..920ef2ee5cc 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr @@ -12,6 +12,7 @@ fn compute_payload_and_hash( ovsk_app: Field, ovpk: OvpkM, recipient: AztecAddress, + sender: AztecAddress, ) -> ([u8; 384 + N * 32], Field) where Event: EventInterface, @@ -25,6 +26,7 @@ where ovsk_app, ovpk, recipient, + sender, plaintext, false, ); @@ -38,19 +40,29 @@ unconstrained fn compute_payload_and_hash_unconstrained( randomness: Field, ovpk: OvpkM, recipient: AztecAddress, + sender: AztecAddress, ) -> ([u8; 384 + N * 32], Field) where Event: EventInterface, { let ovsk_app = get_ovsk_app(ovpk.hash()); - compute_payload_and_hash(context, event, randomness, ovsk_app, ovpk, recipient) + compute_payload_and_hash( + context, + event, + randomness, + ovsk_app, + ovpk, + recipient, + sender, + ) } pub fn encode_and_encrypt_event( context: &mut PrivateContext, ovpk: OvpkM, recipient: AztecAddress, -) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](Event) -> () + sender: AztecAddress, +) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](Event) -> () where Event: EventInterface, { @@ -62,7 +74,7 @@ where let randomness = unsafe { random() }; let ovsk_app: Field = context.request_ovsk_app(ovpk.hash()); let (encrypted_log, log_hash) = - compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient); + compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient, sender); context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash); } } @@ -71,7 +83,8 @@ pub fn encode_and_encrypt_event_unconstrained( context: &mut PrivateContext, ovpk: OvpkM, recipient: AztecAddress, -) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](Event) -> () + sender: AztecAddress, +) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](Event) -> () where Event: EventInterface, { @@ -82,7 +95,7 @@ where // value generation. let randomness = unsafe { random() }; let (encrypted_log, log_hash) = unsafe { - compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient) + compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient, sender) }; context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash); } @@ -96,14 +109,15 @@ pub fn encode_and_encrypt_event_with_randomness( randomness: Field, ovpk: OvpkM, recipient: AztecAddress, -) -> fn[(&mut PrivateContext, OvpkM, Field, AztecAddress)](Event) -> () + sender: AztecAddress, +) -> fn[(&mut PrivateContext, OvpkM, Field, AztecAddress, AztecAddress)](Event) -> () where Event: EventInterface, { |e: Event| { let ovsk_app: Field = context.request_ovsk_app(ovpk.hash()); let (encrypted_log, log_hash) = - compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient); + compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient, sender); context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash); } } @@ -113,7 +127,8 @@ pub fn encode_and_encrypt_event_with_randomness_unconstrained randomness: Field, ovpk: OvpkM, recipient: AztecAddress, -) -> fn[(&mut PrivateContext, Field, OvpkM, AztecAddress)](Event) -> () + sender: AztecAddress, +) -> fn[(&mut PrivateContext, Field, OvpkM, AztecAddress, AztecAddress)](Event) -> () where Event: EventInterface, { @@ -133,7 +148,7 @@ where // return the log from this function to the app, otherwise it could try to do stuff with it and then that might // be wrong. let (encrypted_log, log_hash) = unsafe { - compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient) + compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient, sender) }; context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash); } diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr index 0c280a9a257..0faf7cf2ef0 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr @@ -15,6 +15,7 @@ fn compute_payload_and_hash( ovsk_app: Field, ovpk: OvpkM, recipient: AztecAddress, + sender: AztecAddress, ) -> (u32, [u8; 385 + N * 32], Field) where Note: NoteInterface, @@ -32,8 +33,15 @@ where let plaintext = note.to_be_bytes(storage_slot); // For note logs we always include public values prefix - let encrypted_log: [u8; 385 + N * 32] = - compute_private_log_payload(contract_address, ovsk_app, ovpk, recipient, plaintext, true); + let encrypted_log: [u8; 385 + N * 32] = compute_private_log_payload( + contract_address, + ovsk_app, + ovpk, + recipient, + sender, + plaintext, + true, + ); let log_hash = sha256_to_field(encrypted_log); (note_hash_counter, encrypted_log, log_hash) @@ -44,12 +52,13 @@ unconstrained fn compute_payload_and_hash_unconstrained( note: Note, ovpk: OvpkM, recipient: AztecAddress, + sender: AztecAddress, ) -> (u32, [u8; 385 + N * 32], Field) where Note: NoteInterface, { let ovsk_app = get_ovsk_app(ovpk.hash()); - compute_payload_and_hash(context, note, ovsk_app, ovpk, recipient) + compute_payload_and_hash(context, note, ovsk_app, ovpk, recipient, sender) } // This function seems to be affected by the following Noir bug: @@ -59,7 +68,9 @@ pub fn encode_and_encrypt_note( context: &mut PrivateContext, ovpk: OvpkM, recipient: AztecAddress, -) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](NoteEmission) -> () + // TODO: We need this because to compute a tagging secret, we require a sender. Should we have the tagging secret oracle take a ovpk_m as input instead of the address? + sender: AztecAddress, +) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](NoteEmission) -> () where Note: NoteInterface, { @@ -67,7 +78,7 @@ where let ovsk_app: Field = context.request_ovsk_app(ovpk.hash()); let (note_hash_counter, encrypted_log, log_hash) = - compute_payload_and_hash(*context, e.note, ovsk_app, ovpk, recipient); + compute_payload_and_hash(*context, e.note, ovsk_app, ovpk, recipient, sender); context.emit_raw_note_log(note_hash_counter, encrypted_log, log_hash); } } @@ -76,7 +87,9 @@ pub fn encode_and_encrypt_note_unconstrained( context: &mut PrivateContext, ovpk: OvpkM, recipient: AztecAddress, -) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](NoteEmission) -> () + // TODO: We need this because to compute a tagging secret, we require a sender. Should we have the tagging secret oracle take a ovpk_m as input instead of the address? + sender: AztecAddress, +) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](NoteEmission) -> () where Note: NoteInterface, { @@ -100,8 +113,9 @@ where // for the log to be deleted when it shouldn't have (which is fine - they can already make the content be // whatever), or cause for the log to not be deleted when it should have (which is also fine - it'll be a log // for a note that doesn't exist). - let (note_hash_counter, encrypted_log, log_hash) = - unsafe { compute_payload_and_hash_unconstrained(*context, e.note, ovpk, recipient) }; + let (note_hash_counter, encrypted_log, log_hash) = unsafe { + compute_payload_and_hash_unconstrained(*context, e.note, ovpk, recipient, sender) + }; context.emit_raw_note_log(note_hash_counter, encrypted_log, log_hash); } } diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr index 27bdc617044..8e9d0001910 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr @@ -19,6 +19,7 @@ fn compute_private_log_payload( ovsk_app: Field, ovpk: OvpkM, recipient: AztecAddress, + sender: AztecAddress, plaintext: [u8; P], include_public_values_prefix: bool, ) -> [u8; M] { @@ -206,11 +207,16 @@ mod test { 0x25afb798ea6d0b8c1618e50fdeafa463059415013d3b7c75d46abf5e242be70c, ); + let sender = AztecAddress::from_field( + 0x25afb798ea6d0b8c1618e50fdeafa463059415013d3b7c75d46abf5e242be70c, + ); + let log = compute_private_log_payload( contract_address, ovsk_app, ovpk_m, recipient, + sender, plaintext, false, ); diff --git a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr index 05fde8cfe25..3e9c6ce2347 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr @@ -463,7 +463,7 @@ comptime fn generate_setup_payload( } } - fn encrypt_log(self, context: &mut PrivateContext, ovpk: aztec::protocol_types::public_keys::OvpkM, recipient: aztec::protocol_types::address::AztecAddress) -> [Field; $encrypted_log_field_length] { + fn encrypt_log(self, context: &mut PrivateContext, ovpk: aztec::protocol_types::public_keys::OvpkM, recipient: aztec::protocol_types::address::AztecAddress, sender: aztec::protocol_types::address::AztecAddress) -> [Field; $encrypted_log_field_length] { let ovsk_app: Field = context.request_ovsk_app(ovpk.hash()); let encrypted_log_bytes: [u8; $encrypted_log_byte_length] = aztec::encrypted_logs::payload::compute_private_log_payload( @@ -471,6 +471,7 @@ comptime fn generate_setup_payload( ovsk_app, ovpk, recipient, + sender, self.log_plaintext, true ); diff --git a/noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr b/noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr index f4fc93e0228..d42e7c6d7ef 100644 --- a/noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr +++ b/noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr @@ -22,7 +22,13 @@ impl EasyPrivateUint { impl EasyPrivateUint<&mut PrivateContext> { // Very similar to `value_note::utils::increment`. - pub fn add(self, addend: u64, owner: AztecAddress, outgoing_viewer: AztecAddress, sender: 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); @@ -39,7 +45,13 @@ impl EasyPrivateUint<&mut PrivateContext> { } // Very similar to `value_note::utils::decrement`. - pub fn sub(self, subtrahend: u64, owner: AztecAddress, outgoing_viewer: AztecAddress, sender: 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 diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr index 4d1b2f542e1..fd11c9a9c5d 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr @@ -117,7 +117,12 @@ 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, context.msg_sender()), + encode_and_encrypt_note( + &mut context, + msg_sender_ovpk_m, + subscriber, + context.msg_sender(), + ), ); } diff --git a/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr b/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr index 436617354af..e04c1c2ffb9 100644 --- a/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr @@ -22,7 +22,13 @@ contract Benchmarking { #[private] fn create_note(owner: AztecAddress, outgoing_viewer: AztecAddress, value: Field) { // docs:start:increment_valuenote - increment(storage.notes.at(owner), value, owner, outgoing_viewer); + increment( + storage.notes.at(owner), + value, + owner, + outgoing_viewer, + outgoing_viewer, + ); // docs:end:increment_valuenote } // Deletes a note at a specific index in the set and creates a new one with the same value. @@ -36,7 +42,13 @@ contract Benchmarking { let mut getter_options = NoteGetterOptions::new(); let notes = owner_notes.pop_notes(getter_options.set_limit(1).set_offset(index)); let note = notes.get(0); - increment(owner_notes, note.value, owner, outgoing_viewer); + increment( + owner_notes, + note.value, + owner, + outgoing_viewer, + outgoing_viewer, + ); } // Reads and writes to public storage and enqueues a call to another public function. diff --git a/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr b/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr index 965de3140a5..c7dbedbfca0 100644 --- a/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr @@ -24,7 +24,7 @@ contract Counter { // We can name our initializer anything we want as long as it's marked as aztec(initializer) fn initialize(headstart: u64, owner: AztecAddress, outgoing_viewer: AztecAddress) { let counters = storage.counters; - counters.at(owner).add(headstart, owner, outgoing_viewer); + counters.at(owner).add(headstart, owner, outgoing_viewer, context.msg_sender()); } // docs:end:constructor @@ -38,7 +38,7 @@ contract Counter { ); } let counters = storage.counters; - counters.at(owner).add(1, owner, outgoing_viewer); + counters.at(owner).add(1, owner, outgoing_viewer, context.msg_sender()); } // docs:end:increment // docs:start:get_counter diff --git a/noir-projects/noir-contracts/contracts/easy_private_token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/easy_private_token_contract/src/main.nr index 0544a592f73..8abf2a3be45 100644 --- a/noir-projects/noir-contracts/contracts/easy_private_token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/easy_private_token_contract/src/main.nr @@ -21,7 +21,7 @@ contract EasyPrivateToken { fn constructor(initial_supply: u64, owner: AztecAddress, outgoing_viewer: AztecAddress) { let balances = storage.balances; - balances.at(owner).add(initial_supply, owner, outgoing_viewer); + balances.at(owner).add(initial_supply, owner, outgoing_viewer, context.msg_sender()); } // Mints `amount` of tokens to `owner`. @@ -29,7 +29,7 @@ contract EasyPrivateToken { fn mint(amount: u64, owner: AztecAddress, outgoing_viewer: AztecAddress) { let balances = storage.balances; - balances.at(owner).add(amount, owner, outgoing_viewer); + balances.at(owner).add(amount, owner, outgoing_viewer, context.msg_sender()); } // Transfers `amount` of tokens from `sender` to a `recipient`. @@ -42,8 +42,8 @@ contract EasyPrivateToken { ) { let balances = storage.balances; - balances.at(sender).sub(amount, sender, outgoing_viewer); - balances.at(recipient).add(amount, recipient, outgoing_viewer); + balances.at(sender).sub(amount, sender, outgoing_viewer, sender); + balances.at(recipient).add(amount, recipient, outgoing_viewer, sender); } // Helper function to get the balance of a user ("unconstrained" is a Noir alternative of Solidity's "view" function). diff --git a/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr b/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr index e88b0af0c9f..401e5b015ed 100644 --- a/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr @@ -188,7 +188,8 @@ contract NFT { // We set the ovpk to the message sender's ovpk and we encrypt the log. let from_ovpk = get_public_keys(context.msg_sender()).ovpk_m; - let setup_log = note_setup_payload.encrypt_log(context, from_ovpk, to); + let setup_log = + note_setup_payload.encrypt_log(context, from_ovpk, to, context.msg_sender()); // Using the x-coordinate as a hiding point slot is safe against someone else interfering with it because // we have a guarantee that the public functions of the transaction are executed right after the private ones diff --git a/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr b/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr index 52494022a51..f1211f87b3b 100644 --- a/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr @@ -139,10 +139,20 @@ contract PendingNoteHashes { // Insert note let emission = owner_balance.insert(&mut note); - emission.emit(encode_and_encrypt_note(&mut context, outgoing_viewer_ovpk_m, owner, context.msg_sender())); + 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, context.msg_sender())); + 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 diff --git a/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr index 958386d0803..776e6bb0641 100644 --- a/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr @@ -45,7 +45,7 @@ contract StatefulTest { fn create_note(owner: AztecAddress, outgoing_viewer: AztecAddress, value: Field) { if (value != 0) { let loc = storage.notes.at(owner); - increment(loc, value, owner, outgoing_viewer); + increment(loc, value, owner, outgoing_viewer, context.msg_sender()); } } @@ -54,7 +54,7 @@ contract StatefulTest { fn create_note_no_init_check(owner: AztecAddress, outgoing_viewer: AztecAddress, value: Field) { if (value != 0) { let loc = storage.notes.at(owner); - increment(loc, value, owner, outgoing_viewer); + increment(loc, value, owner, outgoing_viewer, context.msg_sender()); } } @@ -64,10 +64,10 @@ contract StatefulTest { let sender = context.msg_sender(); let sender_notes = storage.notes.at(sender); - decrement(sender_notes, amount, sender, context.msg_sender()); + decrement(sender_notes, amount, sender, sender, sender); let recipient_notes = storage.notes.at(recipient); - increment(recipient_notes, amount, recipient, context.msg_sender()); + increment(recipient_notes, amount, recipient, sender, sender); } #[private] @@ -76,10 +76,10 @@ contract StatefulTest { let sender = context.msg_sender(); let sender_notes = storage.notes.at(sender); - decrement(sender_notes, amount, sender, context.msg_sender()); + decrement(sender_notes, amount, sender, sender, sender); let recipient_notes = storage.notes.at(recipient); - increment(recipient_notes, amount, recipient, context.msg_sender()); + increment(recipient_notes, amount, recipient, sender, sender); } #[public] diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index 612a1c0bfae..64b0c6a8fe3 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -304,6 +304,7 @@ contract Test { 5, outgoing_viewer_ovpk_m, owner, + outgoing_viewer, )); // this contract has reached max number of functions, so using this one fn @@ -321,6 +322,7 @@ contract Test { 0, outgoing_viewer_ovpk_m, owner, + outgoing_viewer, )); } } diff --git a/noir-projects/noir-contracts/contracts/test_log_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_log_contract/src/main.nr index 8c3f65d38fd..19e5c109243 100644 --- a/noir-projects/noir-contracts/contracts/test_log_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_log_contract/src/main.nr @@ -48,6 +48,7 @@ contract TestLog { // outgoing is set to other, incoming is set to msg sender other_ovpk_m, context.msg_sender(), + other, )); // We duplicate the emission, but specifying different incoming and outgoing parties @@ -57,6 +58,7 @@ contract TestLog { // outgoing is set to msg sender, incoming is set to other msg_sender_ovpk_m, other, + context.msg_sender(), )); let event1 = ExampleEvent1 { @@ -70,6 +72,7 @@ contract TestLog { // outgoing is set to other, incoming is set to msg sender other_ovpk_m, context.msg_sender(), + other, )); } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr index 45f9c657544..bdb3b8bd0a9 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr @@ -191,7 +191,12 @@ 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, context.msg_sender()), + encode_and_encrypt_note_unconstrained( + &mut context, + msg_sender_ovpk_m, + to, + context.msg_sender(), + ), ); } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr index ef1157217c6..f08ef9fb987 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -227,7 +227,7 @@ contract Token { let caller = context.msg_sender(); let caller_ovpk_m = get_public_keys(caller).ovpk_m; storage.balances.at(caller).add(caller, U128::from_integer(amount)).emit( - encode_and_encrypt_note(&mut context, caller_ovpk_m, caller), + encode_and_encrypt_note(&mut context, caller_ovpk_m, caller, caller), ); Token::at(context.this_address()) .assert_minter_and_mint(context.msg_sender(), amount) @@ -358,18 +358,20 @@ contract Token { &mut context, from_ovpk_m, from, + from, )); storage.balances.at(to).add(to, amount).emit(encode_and_encrypt_note_unconstrained( &mut context, from_ovpk_m, to, + from, )); // 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_unconstrained(&mut context, from_ovpk_m, to), + encode_and_encrypt_event_unconstrained(&mut context, from_ovpk_m, to, from), ); } // docs:end:transfer @@ -532,7 +534,8 @@ contract Token { // We set the ovpk to the message sender's ovpk and we encrypt the log. let from_ovpk = get_public_keys(context.msg_sender()).ovpk_m; - let setup_log = note_setup_payload.encrypt_log(context, from_ovpk, to); + let setup_log = + note_setup_payload.encrypt_log(context, from_ovpk, to, context.msg_sender()); // Using the x-coordinate as a hiding point slot is safe against someone else interfering with it because // we have a guarantee that the public functions of the transaction are executed right after the private ones @@ -751,8 +754,9 @@ contract Token { // 6. We compute setup logs let fee_payer_setup_log = - fee_payer_setup_payload.encrypt_log(&mut context, user_ovpk, fee_payer); - let user_setup_log = user_setup_payload.encrypt_log(&mut context, user_ovpk, user); + fee_payer_setup_payload.encrypt_log(&mut context, user_ovpk, fee_payer, fee_payer); + let user_setup_log = + user_setup_payload.encrypt_log(&mut context, user_ovpk, user, fee_payer); // 7. We store the hiding points an logs in transients storage Token::at(context.this_address())