Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Oct 30, 2024
1 parent faf97e7 commit 33b657f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fn compute_payload_and_hash<Event, let N: u32>(
ovsk_app: Field,
ovpk: OvpkM,
recipient: AztecAddress,
sender: AztecAddress,
) -> ([u8; 384 + N * 32], Field)
where
Event: EventInterface<N>,
Expand All @@ -25,6 +26,7 @@ where
ovsk_app,
ovpk,
recipient,
sender,
plaintext,
false,
);
Expand All @@ -38,19 +40,21 @@ unconstrained fn compute_payload_and_hash_unconstrained<Event, let N: u32>(
randomness: Field,
ovpk: OvpkM,
recipient: AztecAddress,
sender: AztecAddress,
) -> ([u8; 384 + N * 32], Field)
where
Event: EventInterface<N>,
{
let ovsk_app = get_ovsk_app(ovpk.hash());
compute_payload_and_hash(context, event, randomness, ovsk_app, ovpk, recipient)
compute_payload_and_hash(context, event, randomness, ovsk_app, ovpk, recipient, sender)
}

pub fn encode_and_encrypt_event<Event, let N: u32>(
context: &mut PrivateContext,
ovpk: OvpkM,
recipient: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](Event) -> ()
sender: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](Event) -> ()
where
Event: EventInterface<N>,
{
Expand All @@ -62,7 +66,7 @@ where
let randomness = unsafe { random() };
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash());
let (encrypted_log, log_hash) =
compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient);
compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient, sender);
context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash);
}
}
Expand All @@ -71,7 +75,8 @@ pub fn encode_and_encrypt_event_unconstrained<Event, let N: u32>(
context: &mut PrivateContext,
ovpk: OvpkM,
recipient: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](Event) -> ()
sender: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress, AztecAddress)](Event) -> ()
where
Event: EventInterface<N>,
{
Expand All @@ -82,7 +87,7 @@ where
// value generation.
let randomness = unsafe { random() };
let (encrypted_log, log_hash) = unsafe {
compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient)
compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient, sender)
};
context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash);
}
Expand All @@ -96,14 +101,15 @@ pub fn encode_and_encrypt_event_with_randomness<Event, let N: u32>(
randomness: Field,
ovpk: OvpkM,
recipient: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, Field, AztecAddress)](Event) -> ()
sender: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, Field, AztecAddress, AztecAddress)](Event) -> ()
where
Event: EventInterface<N>,
{
|e: Event| {
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash());
let (encrypted_log, log_hash) =
compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient);
compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient, sender);
context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash);
}
}
Expand All @@ -113,7 +119,8 @@ pub fn encode_and_encrypt_event_with_randomness_unconstrained<Event, let N: u32>
randomness: Field,
ovpk: OvpkM,
recipient: AztecAddress,
) -> fn[(&mut PrivateContext, Field, OvpkM, AztecAddress)](Event) -> ()
sender: AztecAddress,
) -> fn[(&mut PrivateContext, Field, OvpkM, AztecAddress, AztecAddress)](Event) -> ()
where
Event: EventInterface<N>,
{
Expand All @@ -133,7 +140,7 @@ where
// return the log from this function to the app, otherwise it could try to do stuff with it and then that might
// be wrong.
let (encrypted_log, log_hash) = unsafe {
compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient)
compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient, sender)
};
context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fn compute_payload_and_hash<Note, let N: u32>(
ovsk_app: Field,
ovpk: OvpkM,
recipient: AztecAddress,
sender: AztecAddress,
) -> (u32, [u8; 385 + N * 32], Field)
where
Note: NoteInterface<N>,
Expand All @@ -33,7 +34,7 @@ where

// For note logs we always include public values prefix
let encrypted_log: [u8; 385 + N * 32] =
compute_private_log_payload(contract_address, ovsk_app, ovpk, recipient, plaintext, true);
compute_private_log_payload(contract_address, ovsk_app, ovpk, recipient, sender, plaintext, true);
let log_hash = sha256_to_field(encrypted_log);

(note_hash_counter, encrypted_log, log_hash)
Expand All @@ -44,12 +45,13 @@ unconstrained fn compute_payload_and_hash_unconstrained<Note, let N: u32>(
note: Note,
ovpk: OvpkM,
recipient: AztecAddress,
sender: AztecAddress,
) -> (u32, [u8; 385 + N * 32], Field)
where
Note: NoteInterface<N>,
{
let ovsk_app = get_ovsk_app(ovpk.hash());
compute_payload_and_hash(context, note, ovsk_app, ovpk, recipient)
compute_payload_and_hash(context, note, ovsk_app, ovpk, recipient, sender)
}

// This function seems to be affected by the following Noir bug:
Expand All @@ -59,6 +61,7 @@ pub fn encode_and_encrypt_note<Note, let N: u32>(
context: &mut PrivateContext,
ovpk: OvpkM,
recipient: AztecAddress,
sender: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](NoteEmission<Note>) -> ()
where
Note: NoteInterface<N>,
Expand All @@ -67,7 +70,7 @@ where
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash());

let (note_hash_counter, encrypted_log, log_hash) =
compute_payload_and_hash(*context, e.note, ovsk_app, ovpk, recipient);
compute_payload_and_hash(*context, e.note, ovsk_app, ovpk, recipient, sender);
context.emit_raw_note_log(note_hash_counter, encrypted_log, log_hash);
}
}
Expand All @@ -76,6 +79,7 @@ pub fn encode_and_encrypt_note_unconstrained<Note, let N: u32>(
context: &mut PrivateContext,
ovpk: OvpkM,
recipient: AztecAddress,
sender: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](NoteEmission<Note>) -> ()
where
Note: NoteInterface<N>,
Expand All @@ -101,7 +105,7 @@ where
// whatever), or cause for the log to not be deleted when it should have (which is also fine - it'll be a log
// for a note that doesn't exist).
let (note_hash_counter, encrypted_log, log_hash) =
unsafe { compute_payload_and_hash_unconstrained(*context, e.note, ovpk, recipient) };
unsafe { compute_payload_and_hash_unconstrained(*context, e.note, ovpk, recipient, sender) };
context.emit_raw_note_log(note_hash_counter, encrypted_log, log_hash);
}
}
1 change: 1 addition & 0 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn compute_private_log_payload<let P: u32, let M: u32>(
ovsk_app: Field,
ovpk: OvpkM,
recipient: AztecAddress,
sender: AztecAddress,
plaintext: [u8; P],
include_public_values_prefix: bool,
) -> [u8; M] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ contract Token {
let caller = context.msg_sender();
let caller_ovpk_m = get_public_keys(caller).ovpk_m;
storage.balances.at(caller).add(caller, U128::from_integer(amount)).emit(
encode_and_encrypt_note(&mut context, caller_ovpk_m, caller),
encode_and_encrypt_note(&mut context, caller_ovpk_m, caller, caller),
);
Token::at(context.this_address())
.assert_minter_and_mint(context.msg_sender(), amount)
Expand Down Expand Up @@ -309,6 +309,7 @@ contract Token {
storage.balances.at(to).add(to, U128::from_integer(amount)).emit(encode_and_encrypt_note(
&mut context,
from_ovpk_m,
context.msg_sender(),
to,
context.msg_sender(),
));
Expand Down Expand Up @@ -357,11 +358,13 @@ contract Token {
&mut context,
from_ovpk_m,
from,
from
));
storage.balances.at(to).add(to, amount).emit(encode_and_encrypt_note_unconstrained(
&mut context,
from_ovpk_m,
to,
from,
));
// We don't constrain encryption of the note log in `transfer` (unlike in `transfer_from`) because the transfer
// function is only designed to be used in situations where the event is not strictly necessary (e.g. payment to
Expand Down

0 comments on commit 33b657f

Please sign in to comment.