From cef80bcbb0ff84553cf57a8ff6755ffc0ad94ff6 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Mon, 1 Jul 2024 10:45:56 +0000 Subject: [PATCH] refactor: add log_hash as input in log emission in private context --- .../aztec-nr/aztec/src/context/private_context.nr | 15 ++++++--------- .../encrypted_logs/encrypted_event_emission.nr | 6 ++++-- .../src/encrypted_logs/encrypted_note_emission.nr | 8 +++++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 6a5a7048371..48899a15876 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -13,7 +13,6 @@ use crate::{ } }; use dep::protocol_types::{ - hash::sha256_to_field, abis::{ caller_context::CallerContext, function_selector::FunctionSelector, max_block_number::MaxBlockNumber, @@ -263,25 +262,23 @@ impl PrivateContext { // NB: A randomness value of 0 signals that the kernels should not mask the contract address // used in siloing later on e.g. 'handshaking' contract w/ known address. - pub fn emit_raw_event_log_with_masked_address(&mut self, randomness: Field, encrypted_log: [u8; M]) { + pub fn emit_raw_event_log_with_masked_address(&mut self, randomness: Field, log: [u8; M], log_hash: Field) { let counter = self.next_counter(); let contract_address = self.this_address(); - let len = encrypted_log.len() as Field + 4; - let log_hash = sha256_to_field(encrypted_log); + let len = log.len() as Field + 4; let side_effect = EncryptedLogHash { value: log_hash, counter, length: len, randomness }; self.encrypted_logs_hashes.push(side_effect); - emit_encrypted_event_log(contract_address, randomness, encrypted_log, counter); + emit_encrypted_event_log(contract_address, randomness, log, counter); } - pub fn emit_raw_note_log(&mut self, note_hash_counter: u32, encrypted_log: [u8; M]) { + pub fn emit_raw_note_log(&mut self, note_hash_counter: u32, log: [u8; M], log_hash: Field) { let counter = self.next_counter(); - let len = encrypted_log.len() as Field + 4; - let log_hash = sha256_to_field(encrypted_log); + let len = log.len() as Field + 4; let side_effect = NoteLogHash { value: log_hash, counter, length: len, note_hash_counter }; self.note_encrypted_logs_hashes.push(side_effect); - emit_encrypted_note_log(note_hash_counter, encrypted_log, counter); + emit_encrypted_note_log(note_hash_counter, log, counter); } pub fn call_private_function( 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 935cd0fa48f..28e1c15d1b5 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 @@ -3,7 +3,7 @@ use crate::{ encrypted_logs::payload::compute_encrypted_event_log, oracle::logs_traits::LensForEncryptedEvent, oracle::unsafe_rand::unsafe_rand }; -use dep::protocol_types::{address::AztecAddress, grumpkin_point::GrumpkinPoint}; +use dep::protocol_types::{address::AztecAddress, grumpkin_point::GrumpkinPoint, hash::sha256_to_field}; fn emit_with_keys( context: &mut PrivateContext, @@ -17,7 +17,9 @@ fn emit_with_keys( let encrypted_log: [u8; OB] = compute_encrypted_event_log(contract_address, randomness, ovsk_app, ovpk, ivpk, event); - context.emit_raw_event_log_with_masked_address(randomness, encrypted_log); + let log_hash = sha256_to_field(encrypted_log); + + context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash); } pub fn encode_and_encrypt_event( 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 5b66e2e8027..a427f09cd16 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 @@ -3,8 +3,8 @@ use crate::{ encrypted_logs::payload::compute_encrypted_note_log, oracle::logs_traits::LensForEncryptedLog }; use dep::protocol_types::{ - address::AztecAddress, grumpkin_point::GrumpkinPoint, abis::note_hash::NoteHash, - constants::MAX_NEW_NOTE_HASHES_PER_CALL, utils::arrays::find_index + hash::sha256_to_field, address::AztecAddress, grumpkin_point::GrumpkinPoint, + abis::note_hash::NoteHash, constants::MAX_NEW_NOTE_HASHES_PER_CALL, utils::arrays::find_index }; fn emit_with_keys( @@ -30,7 +30,9 @@ fn emit_with_keys( let encrypted_log: [u8; M] = compute_encrypted_note_log(contract_address, storage_slot, ovsk_app, ovpk, ivpk, note); - context.emit_raw_note_log(note_hash_counter, encrypted_log); + let log_hash = sha256_to_field(encrypted_log); + + context.emit_raw_note_log(note_hash_counter, encrypted_log, log_hash); } pub fn encode_and_encrypt_note(