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 296e23d85f5..e257557c0c3 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 @@ -175,6 +175,40 @@ pub fn encrypt_and_emit_partial_log( context.emit_raw_note_log(note_hash_counter, encrypted_log, log_hash); } +// Temporary hack function TODO: remove +pub fn encrypt_and_emit_partial_log_and_return( + context: &mut PrivateContext, + log_plaintext: [u8; P], + recipient_keys: PublicKeys, + recipient: AztecAddress +) -> [Field; N] { + let ovsk_app: Field = context.request_ovsk_app(recipient_keys.ovpk_m.hash()); + + let encrypted_log: [u8; 353 + P] = compute_encrypted_log( + context.this_address(), + ovsk_app, + recipient_keys.ovpk_m, + recipient_keys.ivpk_m, + recipient, + log_plaintext, + true + ); + let log_hash = sha256_to_field(encrypted_log); + + // for i in 0..encrypted_log.len() { + // crate::protocol_types::debug_log::debug_log_format("e {0}", [encrypted_log[i].to_field()]); + // } + + // Unfortunately we need to push a dummy note hash to the context here because a note log requires having + // a counter that corresponds to a note hash in the same call. + let note_hash_counter = context.side_effect_counter; + context.push_note_hash(5); + + context.emit_raw_note_log(note_hash_counter, encrypted_log, log_hash); + + bytes_to_fields(encrypted_log) +} + pub fn encrypt_partial_log( context: &mut PrivateContext, log_plaintext: [u8; P], 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 d4b1ce1032c..30aa508d527 100644 --- a/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr @@ -14,7 +14,7 @@ contract NFT { NoteGetterOptions, NoteViewerOptions, Map, PublicMutable, SharedImmutable, PrivateSet, AztecAddress, PublicContext }, - encrypted_logs::{encrypted_note_emission::{encode_and_encrypt_note, encrypt_and_emit_partial_log, encrypt_partial_log}}, + encrypted_logs::{encrypted_note_emission::{encode_and_encrypt_note, encrypt_and_emit_partial_log, encrypt_and_emit_partial_log_and_return, encrypt_partial_log}}, keys::getters::get_public_keys, note::constants::MAX_NOTES_PER_PAGE, protocol_types::traits::is_empty, utils::comparison::Comparator, protocol_types::{point::Point, traits::Serialize}, utils::bytes::fields_to_bytes, @@ -178,11 +178,14 @@ contract NFT { let note_setup_payload = NFTNote::setup_payload().new(to_npk_m_hash, note_randomness, to_note_slot); // We encrypt and emit the partial note log - encrypt_and_emit_partial_log(&mut context, note_setup_payload.log_plaintext, to_keys, to); + // encrypt_and_emit_partial_log(&mut context, note_setup_payload.log_plaintext, to_keys, to); // setup payload plaintext is 2*32+64 = 128 // the full log is 128 + 353 = 481 // each field can contain 31 bytes so we need 16 fields - let partial_log: [Field; 16] = encrypt_partial_log(&mut context, note_setup_payload.log_plaintext, to_keys, to); + // let partial_log: [Field; 16] = encrypt_partial_log(&mut context, note_setup_payload.log_plaintext, to_keys, to); + let partial_log: [Field; 16] = encrypt_and_emit_partial_log_and_return(&mut context, note_setup_payload.log_plaintext, to_keys, to); + + // dep::aztec::protocol_types::debug_log::debug_log_format("before transient {}", partial_log); // 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/yarn-project/pxe/src/note_processor/note_processor.ts b/yarn-project/pxe/src/note_processor/note_processor.ts index af8ff8dff9c..b2b532a6c16 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.ts @@ -153,6 +153,10 @@ export class NoteProcessor { const incomingNotePayload = L1NotePayload.decryptAsIncoming(log, ivskM); const outgoingNotePayload = L1NotePayload.decryptAsOutgoing(log, ovskM); + if (incomingNotePayload) { + console.log("decrypted incoming", incomingNotePayload); + } + if (incomingNotePayload || outgoingNotePayload) { if (incomingNotePayload && outgoingNotePayload && !incomingNotePayload.equals(outgoingNotePayload)) { throw new Error( @@ -366,12 +370,13 @@ export class NoteProcessor { /** * When a log is emitted via the unencrypted log channel each field contains only 1 byte. OTOH when a log is emitted * via the encrypted log channel there are no empty bytes. This function removes the padding bytes. - * @param unprocessedLog + * @param unprocessedLog - Log to be processed. * @returns Log with padding bytes removed. + * TODO(benesjan): Nuke this once the logs are all refactored. */ function removePaddingBytes(unprocessedLog: Buffer) { if (unprocessedLog.length === 640160) { - // I have no idea what this log is. + // TODO(benejsan): I have no why this monster log appears here and would bother with that only after we have the log refactor. return unprocessedLog; }