Skip to content

Commit

Permalink
refactor!: using native u128 type (#12213)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored and AztecBot committed Feb 27, 2025
1 parent 5f0ff52 commit 3f0fc30
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
5 changes: 2 additions & 3 deletions aztec/src/macros/notes/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ comptime fn generate_fixed_generators() -> (Quoted, Quoted) {
/// std::hash::from_field_unsafe(npk_m_hash as Field),
/// std::hash::from_field_unsafe(randomness as Field)
/// ]
/// args_list: [amount: U128, npk_m_hash: Field, randomness: Field]
/// args_list: [amount: u128, npk_m_hash: Field, randomness: Field]
/// aux_vars: []
comptime fn generate_multi_scalar_mul(
indexed_fields: [(Quoted, Type, u32)],
Expand Down Expand Up @@ -695,7 +695,7 @@ comptime fn get_setup_log_plaintext_body(
/// }
///
/// impl TokenNoteFinalizationPayload {
/// fn new(mut self, context: &mut aztec::prelude::PublicContext, slot: Field, amount: U128) -> TokenNoteFinalizationPayload {
/// fn new(mut self, context: &mut aztec::prelude::PublicContext, slot: Field, amount: u128) -> TokenNoteFinalizationPayload {
/// self.context = context;
/// self.hiding_point_slot = slot;
/// self.setup_log_slot = slot + aztec::protocol_types::point::POINT_LENGTH as Field;
Expand Down Expand Up @@ -978,7 +978,6 @@ comptime fn register_note(

/// Separates note struct members into fixed and nullable ones. It also stores the index of where each struct member
/// starts in the serialized note. Note that each struct member can occupy multiple fields (as in Field type).
/// An example of a struct member occupying multiple fields is `amount` in `TokenNote` that uses `U128` type.
comptime fn index_note_fields(
s: StructDefinition,
nullable_fields: [Quoted],
Expand Down
2 changes: 1 addition & 1 deletion aztec/src/state_vars/public_immutable.nr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use dep::protocol_types::{constants::INITIALIZATION_SLOT_SEPARATOR, traits::Pack
/// #[derive(Eq, Packable)]
/// pub struct Config \{
/// pub address_1: AztecAddress,
/// pub value_1: U128,
/// pub value_1: u128,
/// pub value_2: u64,
/// ...
/// }
Expand Down
6 changes: 3 additions & 3 deletions uint-note/src/uint_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use dep::aztec::{
#[derive(Eq, Serialize)]
pub struct UintNote {
// The amount of tokens in the note
value: U128,
value: u128,
owner: AztecAddress,
// Randomness of the note to protect against note hash preimage attacks
randomness: Field,
}
// docs:end:UintNote
impl UintNote {
pub fn new(value: U128, owner: AztecAddress) -> Self {
pub fn new(value: u128, owner: AztecAddress) -> Self {
// Safety: We use the randomness to preserve the privacy of the note recipient by preventing brute-forcing,
// so a malicious sender could use non-random values to make the note less private. But they already know
// the full note pre-image anyway, and so the recipient already trusts them to not disclose this
Expand All @@ -26,7 +26,7 @@ impl UintNote {
Self { value, owner, randomness }
}

pub fn get_value(self) -> U128 {
pub fn get_value(self) -> u128 {
self.value
}
}
14 changes: 9 additions & 5 deletions value-note/src/filter.nr
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
use crate::value_note::ValueNote;
use dep::aztec::note::retrieved_note::RetrievedNote;
use dep::aztec::protocol_types::constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL;
use aztec::{
note::retrieved_note::RetrievedNote,
protocol_types::{
constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, utils::field::full_field_less_than,
},
};

pub fn filter_notes_min_sum(
notes: [Option<RetrievedNote<ValueNote>>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL],
min_sum: Field,
) -> [Option<RetrievedNote<ValueNote>>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] {
let mut selected = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL];

let mut sum = U128::from_integer(0);
let mut sum = 0;
for i in 0..notes.len() {
if notes[i].is_some() & (sum < U128::from_integer(min_sum)) {
if notes[i].is_some() & full_field_less_than(sum, min_sum) {
let retrieved_note = notes[i].unwrap_unchecked();
selected[i] = Option::some(retrieved_note);
sum += U128::from_integer(retrieved_note.note.value);
sum += retrieved_note.note.value;
}
}

Expand Down

0 comments on commit 3f0fc30

Please sign in to comment.