Skip to content

Commit

Permalink
fix: key-rotation related issues in TokenWithRefunds
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jul 31, 2024
1 parent 619fcec commit 6ecee68
Show file tree
Hide file tree
Showing 11 changed files with 556 additions and 224 deletions.
12 changes: 6 additions & 6 deletions noir-projects/aztec-nr/aztec/src/note/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ use dep::protocol_types::{
};
use dep::std::{embedded_curve_ops::multi_scalar_mul, hash::from_field_unsafe};

pub fn compute_slotted_note_hash_raw(storage_slot: Field, note_hiding_point: Point) -> Field {
pub fn compute_slotted_note_hiding_point_raw(storage_slot: Field, note_hiding_point: Point) -> Point {
// 1. We derive the storage slot point by multiplying the storage slot with the generator G_slot.
// We use the unsafe version because the multi_scalar_mul will constrain the scalars.
let storage_slot_scalar = from_field_unsafe(storage_slot);
let storage_slot_point = multi_scalar_mul([G_slot], [storage_slot_scalar]);
let slotted_note_hiding_point = storage_slot_point + note_hiding_point;
let slotted_note_hash = slotted_note_hiding_point.x;

slotted_note_hash
// 2. Then we compute the slotted note hiding point by adding the storage slot point to the note hiding point.
storage_slot_point + note_hiding_point
}

pub fn compute_slotted_note_hash<Note, let N: u32, let M: u32>(note: Note) -> Field where Note: NoteInterface<N, M> {
let header = note.get_header();
let note_hash = note.compute_note_hiding_point();
let note_hiding_point = note.compute_note_hiding_point();

compute_slotted_note_hash_raw(header.storage_slot, note_hash)
compute_slotted_note_hiding_point_raw(header.storage_slot, note_hiding_point).x
}

pub fn compute_siloed_nullifier<Note, let N: u32, let M: u32>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ contract PrivateFPC {
#[aztec(storage)]
struct Storage {
other_asset: SharedImmutable<AztecAddress>,
admin_npk_m_hash: SharedImmutable<Field>
admin: SharedImmutable<AztecAddress>,
}

#[aztec(public)]
#[aztec(initializer)]
fn constructor(other_asset: AztecAddress, admin_npk_m_hash: Field) {
fn constructor(other_asset: AztecAddress, admin: AztecAddress) {
storage.other_asset.initialize(other_asset);
storage.admin_npk_m_hash.initialize(admin_npk_m_hash);
storage.admin.initialize(admin);
}

#[aztec(private)]
Expand All @@ -32,7 +32,7 @@ contract PrivateFPC {
emit_randomness_as_unencrypted_log(&mut context, fee_payer_randomness);

TokenWithRefunds::at(asset).setup_refund(
storage.admin_npk_m_hash.read_private(),
storage.admin.read_private(),
context.msg_sender(),
amount,
user_randomness,
Expand Down
Loading

0 comments on commit 6ecee68

Please sign in to comment.