Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 22, 2024
1 parent 384a241 commit b4f4d1c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,40 @@ pub fn encrypt_and_emit_partial_log<let P: u32>(
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<let P: u32, let N: u32>(
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<let P: u32, let N: u32>(
context: &mut PrivateContext,
log_plaintext: [u8; P],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions yarn-project/pxe/src/note_processor/note_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit b4f4d1c

Please sign in to comment.