From c250549f83af8b7b668e3375bc8c91b368f8fe75 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 3 Oct 2024 08:59:48 +0000 Subject: [PATCH] API improvements --- .../src/encrypted_logs/encrypted_note_emission.nr | 15 +++++++++------ .../contracts/nft_contract/src/main.nr | 11 ++--------- 2 files changed, 11 insertions(+), 15 deletions(-) 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 81cbaf1991ac..551bd6f7cf76 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 @@ -1,6 +1,6 @@ use crate::{ context::PrivateContext, note::{note_emission::NoteEmission, note_interface::NoteInterface}, - keys::{getters::get_ovsk_app, public_keys::{OvpkM, IvpkM}}, + keys::{getters::get_ovsk_app, public_keys::{PublicKeys, OvpkM, IvpkM}}, encrypted_logs::payload::compute_encrypted_log }; use dep::protocol_types::{hash::sha256_to_field, address::AztecAddress, abis::note_hash::NoteHash}; @@ -91,20 +91,23 @@ pub fn encode_and_encrypt_note_unconstrained( } } +/// Encrypts a partial log and emits it. Takes recipient keys on the input and encrypts both the outgoing and incoming +/// logs for the recipient. This is necessary because in the partial notes flow the outgoing always has to be the same +/// as the incoming to not leak any information (typically the `from` party finalizing the partial note in public does +/// not know who the recipient is). pub fn encrypt_and_emit_partial_log( context: &mut PrivateContext, log_plaintext: [u8; M], - ovpk: OvpkM, - ivpk: IvpkM, + recipient_keys: PublicKeys, recipient: AztecAddress ) { - let ovsk_app: Field = context.request_ovsk_app(ovpk.hash()); + let ovsk_app: Field = context.request_ovsk_app(recipient_keys.ovpk_m.hash()); let encrypted_log: [u8; 352 + M] = compute_encrypted_log( context.this_address(), ovsk_app, - ovpk, - ivpk, + recipient_keys.ovpk_m, + recipient_keys.ivpk_m, recipient, log_plaintext ); 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 bc4214ccafc3..47c2f6d8fb8d 100644 --- a/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr @@ -153,15 +153,8 @@ contract NFT { // We create a partial NFT note hiding point with unpopulated/zero token id for 'to' let note_partial_payload = NFTNote::partial_payload().new(to_npk_m_hash, note_randomness, to_note_slot); - // `from` cannot receive any logs here as that would leak information of who is the note recipient. For this - // reason we encrypt outgoing to `to`. - encrypt_and_emit_partial_log( - &mut context, - note_partial_payload.log_plaintext, - to_keys.ovpk_m, - to_keys.ivpk_m, - to - ); + // We encrypt and emit the partial note log + encrypt_and_emit_partial_log(&mut context, note_partial_payload.log_plaintext, to_keys, to); // We make the msg_sender/transfer_preparer part of the slot preimage to ensure he cannot interfere with // non-sender's slots