Skip to content

Commit

Permalink
chore: use traits in noir-protocol-circuits (#3832)
Browse files Browse the repository at this point in the history
Simple use of traits in `noir-protocol-circuits` and `aztec-nr` when
possible.

Missing: Serialize/Deserialize due to:
noir-lang/noir#3471

Renamed ::default() to ::empty(), since it better conveys meaning for
our use cases (open to discussion).
  • Loading branch information
superstar0402 committed Jan 7, 2024
1 parent 97afc53 commit 303fd0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
11 changes: 7 additions & 4 deletions aztec/src/note/note_header.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use dep::protocol_types::address::AztecAddress;
use dep::protocol_types::traits::Empty;

struct NoteHeader {
contract_address: AztecAddress,
Expand All @@ -9,12 +10,14 @@ struct NoteHeader {
is_transient: bool,
}

impl Empty for NoteHeader {
fn empty() -> Self {
NoteHeader { contract_address: AztecAddress::zero(), nonce: 0, storage_slot: 0, is_transient: false }
}
}

impl NoteHeader {
pub fn new(contract_address: AztecAddress, nonce: Field, storage_slot: Field) -> Self {
NoteHeader { contract_address, nonce, storage_slot, is_transient: false }
}

pub fn empty() -> Self {
NoteHeader { contract_address: AztecAddress::zero(), nonce: 0, storage_slot: 0, is_transient: false }
}
}
18 changes: 11 additions & 7 deletions safe-math/src/safe_u120.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
use dep::std::ops::Eq;

struct SafeU120 {
value: u120,
}

impl Eq for SafeU120 {
fn eq(
self: Self,
other: Self
) -> bool {
self.value == other.value
}
}

impl SafeU120 {
pub fn min() -> Self {
Self {
Expand Down Expand Up @@ -34,13 +45,6 @@ impl SafeU120 {
self.value == 0
}

pub fn eq(
self: Self,
other: Self
) -> bool {
self.value == other.value
}

pub fn lt(self: Self, other: Self) -> bool {
self.value < other.value
}
Expand Down

0 comments on commit 303fd0c

Please sign in to comment.