From a912211d77a58a6d9514abed80884c93236d99d5 Mon Sep 17 00:00:00 2001 From: Gregorio Juliana Date: Thu, 4 Jan 2024 22:00:25 +0100 Subject: [PATCH] chore: use traits in noir-protocol-circuits (#3832) Simple use of traits in `noir-protocol-circuits` and `aztec-nr` when possible. Missing: Serialize/Deserialize due to: https://github.com/noir-lang/noir/issues/3471 Renamed ::default() to ::empty(), since it better conveys meaning for our use cases (open to discussion). --- aztec/src/note/note_header.nr | 11 +++++++---- safe-math/src/safe_u120.nr | 18 +++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/aztec/src/note/note_header.nr b/aztec/src/note/note_header.nr index 306e92a4..b807deea 100644 --- a/aztec/src/note/note_header.nr +++ b/aztec/src/note/note_header.nr @@ -1,4 +1,5 @@ use dep::protocol_types::address::AztecAddress; +use dep::protocol_types::traits::Empty; struct NoteHeader { contract_address: AztecAddress, @@ -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 } - } } diff --git a/safe-math/src/safe_u120.nr b/safe-math/src/safe_u120.nr index 8412f45a..a7051457 100644 --- a/safe-math/src/safe_u120.nr +++ b/safe-math/src/safe_u120.nr @@ -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 { @@ -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 }