Skip to content

Commit

Permalink
fix: SubscriptionNote preimage attack (#8390)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Sep 5, 2024
1 parent d582c93 commit 94006a9
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
use dep::aztec::prelude::{AztecAddress, PrivateContext, NoteHeader, NoteInterface};
use dep::aztec::{
protocol_types::{constants::GENERATOR_INDEX__NOTE_NULLIFIER, hash::poseidon2_hash_with_separator},
note::utils::compute_note_hash_for_nullify, keys::getters::get_nsk_app
hash::poseidon2_hash_with_separator, note::utils::compute_note_hash_for_nullify,
keys::getters::get_nsk_app, oracle::unsafe_rand::unsafe_rand,
prelude::{PrivateContext, NoteHeader, NoteInterface},
protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER
};

global SUBSCRIPTION_NOTE_LEN: Field = 3;
// ADDRESS_NOTE_LEN * 32 + 32(storage_slot as bytes) + 32(note_type_id as bytes)
global SUBSCRIPTION_NOTE_BYTES_LEN: Field = 3 * 32 + 64;
global SUBSCRIPTION_NOTE_LEN: Field = 4;
// SUBSCRIPTION_NOTE_BYTES_LEN * 32 + 32(storage_slot as bytes) + 32(note_type_id as bytes)
global SUBSCRIPTION_NOTE_BYTES_LEN: Field = SUBSCRIPTION_NOTE_LEN * 32 + 64;

// Stores a public key composed of two fields
// TODO: Do we need to include a nonce, in case we want to read/nullify/recreate with the same pubkey value?
#[aztec(note)]
struct SubscriptionNote {
// The nullifying public key hash is used with the nsk_app to ensure that the note can be privately spent.
npk_m_hash: Field,
expiry_block_number: Field,
remaining_txs: Field,
// Randomness of the note to hide its contents
randomness: Field,
}

impl NoteInterface<SUBSCRIPTION_NOTE_LEN, SUBSCRIPTION_NOTE_BYTES_LEN> for SubscriptionNote {
Expand Down Expand Up @@ -43,6 +44,9 @@ impl NoteInterface<SUBSCRIPTION_NOTE_LEN, SUBSCRIPTION_NOTE_BYTES_LEN> for Subsc

impl SubscriptionNote {
pub fn new(npk_m_hash: Field, expiry_block_number: Field, remaining_txs: Field) -> Self {
SubscriptionNote { npk_m_hash, expiry_block_number, remaining_txs, header: NoteHeader::empty() }
let randomness = unsafe {
unsafe_rand()
};
Self { npk_m_hash, expiry_block_number, remaining_txs, randomness, header: NoteHeader::empty() }
}
}

0 comments on commit 94006a9

Please sign in to comment.