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 1c35b088185..ac31ebc34a7 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr @@ -590,7 +590,7 @@ comptime fn generate_finalization_payload( impl $finalization_payload_name { fn new(mut self, hiding_point: aztec::protocol_types::point::Point, $args) -> $finalization_payload_name { $aux_vars_for_serialization - self.log = [$fields]; + self.public_values = [$fields]; $msm_aux_vars let finalization_hiding_point = std::embedded_curve_ops::multi_scalar_mul( @@ -601,35 +601,39 @@ comptime fn generate_finalization_payload( self.note_hash = finalization_hiding_point.x; self } - } - fn get_log(self, context: &mut PublicContext, slot: Field) -> [u8; $finalization_log_byte_length] { - let setup_log_fields: [Field; $setup_log_field_length] = context.storage_read(slot); - let setup_log: [u8; $setup_log_byte_length] = aztec::utils::bytes::fields_to_bytes(setup_log_fields); + fn get_log(self, context: &mut aztec::prelude::PublicContext, slot: Field) -> [u8; $finalization_log_byte_length] { + let setup_log_fields: [Field; $setup_log_field_length] = context.storage_read(slot); + let setup_log: [u8; $setup_log_byte_length] = aztec::utils::bytes::fields_to_bytes(setup_log_fields); - // First byte should be zero as the number of public values is populated in public - assert(setup_log[0] == 0, "Non-zero first byte"); + // First byte should be zero as the number of public values is populated in public + assert(setup_log[0] == 0, "Non-zero first byte"); - // We append the public value to the log and emit it as unencrypted log - let mut finalization_log = [0; $finalization_log_byte_length]; + // We append the public value to the log and emit it as unencrypted log + let mut finalization_log = [0; $finalization_log_byte_length]; - // Iterate over the partial log and copy it to the final log - for i in 1..setup_log.len() { - finalization_log[i] = setup_log[i]; - } + // Iterate over the partial log and copy it to the final log + for i in 1..setup_log.len() { + finalization_log[i] = setup_log[i]; + } - // Now we populate the first byte with number of public values - finalization_log[0] = 1; + // Now we populate the first byte with number of public values + finalization_log[0] = 1; - // Iterate over the public values and append them to the log - for i in 0..$public_values_length { - let public_value_bytes: [u8; 32] = self.public_values[i].to_be_bytes(); - for j in 0..public_value_bytes.len() { - finalization_log[$setup_log_byte_length + i * 32 + j] = public_value_bytes[j]; + // Iterate over the public values and append them to the log + for i in 0..$public_values_length { + let public_value_bytes: [u8; 32] = self.public_values[i].to_be_bytes(); + for j in 0..public_value_bytes.len() { + finalization_log[$setup_log_byte_length + i * 32 + j] = public_value_bytes[j]; + } } - } - finalization_log + // We reset public storage to zero to achieve the effect of transient storage - kernels will squash + // the writes + context.storage_write(slot, [0; $setup_log_field_length]); + + finalization_log + } } impl aztec::protocol_types::traits::Empty for $finalization_payload_name { 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 ac8e19aa429..5b9f6674c49 100644 --- a/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/nft_contract/src/main.nr @@ -249,38 +249,11 @@ contract NFT { // We insert the finalization note hash context.push_note_hash(finalization_payload.note_hash); - // ############### HACKY NEW CODE TO BE POLISHED LATER ############### - let setup_log_fields: [Field; 16] = context.storage_read(hiding_point_slot + 3); - let setup_log: [u8; 481] = fields_to_bytes(setup_log_fields); - - // First byte should be zero as the number of public values is populated in public - assert(setup_log[0] == 0, "Non-zero first byte"); - - // We append the public value to the log and emit it as unencrypted log - let mut log = [0; 513]; - - // Iterate over the partial log and copy it to the final log - for i in 1..setup_log.len() { - log[i] = setup_log[i]; - } - - // Now we populate the first byte with number of public values - log[0] = 1; - // Iterate over the finalization log and copy it to the final log - let finalization_log: [u8; 32] = finalization_payload.log[0].to_be_bytes(); - - for i in 0..finalization_log.len() { - log[481 + i] = finalization_log[i]; - } - - // We emit the `token_id` as unencrypted event such that the `NoteProcessor` can use it to reconstruct the note - context.emit_unencrypted_log(log); + let finalization_log = finalization_payload.get_log(context, hiding_point_slot + 3); - // At last we reset public storage to zero to achieve the effect of transient storage - kernels will squash - // the writes - context.storage_write(hiding_point_slot, Point::empty()); - context.storage_write(hiding_point_slot + 3, [0; 16]); + // We emit the finalization log via the unencrypted logs stream + context.emit_unencrypted_log(finalization_log); } /** 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 ae6c9c5b828..8eb74a8808e 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -560,8 +560,8 @@ contract Token { // 4. We emit the `tx_fee` and `refund_amount` as unencrypted event such that the `NoteProcessor` can use it // to reconstruct the note. - context.emit_unencrypted_log(fee_payer_finalization_payload.log); - context.emit_unencrypted_log(user_finalization_payload.log); + context.emit_unencrypted_log(fee_payer_finalization_payload.public_values); + context.emit_unencrypted_log(user_finalization_payload.public_values); // 5. At last we emit the note hashes. context.push_note_hash(fee_payer_finalization_payload.note_hash);