Skip to content

Commit

Permalink
cuter names
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 3, 2024
1 parent d6e07cd commit 232337c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn encode_and_encrypt_note_unconstrained<Note, let N: u32>(
}
}

pub fn encrypt_and_emit_log_of_partial<let M: u32>(
pub fn encrypt_and_emit_partial_log<let M: u32>(
context: &mut PrivateContext,
log_plaintext: [u8; M],
ovpk: OvpkM,
Expand Down
20 changes: 10 additions & 10 deletions noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ comptime fn generate_partial_payload(
let new_generators = new_generators_list.push_back(quote { aztec::generators::G_slot }).join(quote {,});
let new_scalars = new_scalars_list.push_back(quote { std::hash::from_field_unsafe(storage_slot) }).join(quote {,});

let buffer_length = indexed_fixed_fields.len() * 32 + 64;
let log_plaintext_length = indexed_fixed_fields.len() * 32 + 64;

// Now we compute serialization of the fixed fields. We do that by passing the whole note struct
// to the flatten_to_fields function but we omit the NoteHeader and the nullable fields.
Expand All @@ -334,15 +334,15 @@ comptime fn generate_partial_payload(
let serialized_fields = fields.join(quote {,});

// indexed_fixed_fields has preserved order so we can used to serialize the note to log
let partial_note_buffer = quote {
let mut buffer: [u8; $buffer_length] = [0; $buffer_length];
let partial_note_log_plaintext = quote {
let mut log_plaintext: [u8; $log_plaintext_length] = [0; $log_plaintext_length];

let storage_slot_bytes: [u8; 32] = storage_slot.to_be_bytes();
let note_type_id_bytes: [u8; 32] = $name::get_note_type_id().to_be_bytes();

for i in 0..32 {
buffer[i] = storage_slot_bytes[i];
buffer[32 + i] = note_type_id_bytes[i];
log_plaintext[i] = storage_slot_bytes[i];
log_plaintext[32 + i] = note_type_id_bytes[i];
}

$aux_vars_for_serialization
Expand All @@ -351,14 +351,14 @@ comptime fn generate_partial_payload(
for i in 0..serialized_note.len() {
let bytes: [u8; 32] = serialized_note[i].to_be_bytes();
for j in 0..32 {
buffer[64 + i * 32 + j] = bytes[j];
log_plaintext[64 + i * 32 + j] = bytes[j];
}
}
};

(quote {
struct $partial_payload_name {
buffer: [u8; $buffer_length],
log_plaintext: [u8; $log_plaintext_length],
hiding_point: $hiding_point_name
}

Expand All @@ -370,18 +370,18 @@ comptime fn generate_partial_payload(
[$new_scalars]
);
let hiding_point = $hiding_point_name::empty().from_point(point);
$partial_note_buffer
$partial_note_log_plaintext

$partial_payload_name {
buffer,
log_plaintext,
hiding_point
}
}
}

impl aztec::protocol_types::traits::Empty for $partial_payload_name {
fn empty() -> Self {
Self { buffer: [0; $buffer_length], hiding_point: $hiding_point_name::empty() }
Self { log_plaintext: [0; $log_plaintext_length], hiding_point: $hiding_point_name::empty() }
}
}
}, partial_payload_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract NFT {
use dep::compressed_string::FieldCompressedString;
use dep::aztec::{
prelude::{NoteGetterOptions, NoteViewerOptions, Map, PublicMutable, SharedImmutable, PrivateSet, AztecAddress},
encrypted_logs::{encrypted_note_emission::{encode_and_encrypt_note, encrypt_and_emit_log_of_partial}},
encrypted_logs::{encrypted_note_emission::{encode_and_encrypt_note, encrypt_and_emit_partial_log}},
hash::pedersen_hash, 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},
Expand Down Expand Up @@ -147,16 +147,17 @@ contract NFT {
transient_storage_slot_randomness: Field
) {
let to_keys = get_public_keys(to);
// We create a partial NFT note hiding point with unpopulated/zero token id for 'to'
let to_npk_m_hash = to_keys.npk_m.hash();
let to_note_slot = storage.private_nfts.at(to).storage_slot;

// 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_log_of_partial(
encrypt_and_emit_partial_log(
&mut context,
note_partial_payload.buffer,
note_partial_payload.log_plaintext,
to_keys.ovpk_m,
to_keys.ivpk_m,
to
Expand Down

0 comments on commit 232337c

Please sign in to comment.