Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SubscriptionNote preimage attack #8390

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() }
}
}
Loading