diff --git a/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr b/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr index f2ff913076a..010bd593b5e 100644 --- a/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr @@ -27,8 +27,7 @@ contract Crowdfunding { // Crowdfunding campaign operator operator: SharedImmutable, // End of the crowdfunding campaign after which no more donations are accepted - // TODO(#4990): Make deadline a u64 once the neccessary traits are implemented - deadline: PublicImmutable, + deadline: PublicImmutable, // Notes emitted to donors when they donate (later on used to claim rewards in the Claim contract) claim_notes: PrivateSet, } @@ -36,17 +35,15 @@ contract Crowdfunding { #[aztec(public)] #[aztec(initializer)] fn constructor(donation_token: AztecAddress, operator: AztecAddress, deadline: u64) { - // TODO(#4990): Make deadline a u64 once the neccessary traits are implemented storage.donation_token.initialize(donation_token); storage.operator.initialize(operator); - storage.deadline.initialize(deadline as Field); + storage.deadline.initialize(deadline); } #[aztec(public)] #[aztec(internal)] fn _check_deadline() { - // TODO(#4990): Remove the cast here once u64 is used directly - let deadline = storage.deadline.read() as u64; + let deadline = storage.deadline.read(); assert(context.timestamp() as u64 < deadline, "Deadline has passed"); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/type_serialization.nr b/noir-projects/noir-protocol-circuits/crates/types/src/type_serialization.nr index 9b4929fc63d..e7aac333e59 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/type_serialization.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/type_serialization.nr @@ -1,19 +1,21 @@ use crate::traits::{Serialize, Deserialize}; global BOOL_SERIALIZED_LEN: Field = 1; -global U32_SERIALIZED_LEN: Field = 1; global U8_SERIALIZED_LEN: Field = 1; +global U32_SERIALIZED_LEN: Field = 1; +global U64_SERIALIZED_LEN: Field = 1; +global U128_SERIALIZED_LEN: Field = 1; global FIELD_SERIALIZED_LEN: Field = 1; -impl Serialize for u32 { - fn serialize(self) -> [Field; U32_SERIALIZED_LEN] { +impl Serialize for bool { + fn serialize(self) -> [Field; BOOL_SERIALIZED_LEN] { [self as Field] } } -impl Deserialize for u32 { - fn deserialize(fields: [Field; U32_SERIALIZED_LEN]) -> Self { - fields[0] as u32 +impl Deserialize for bool { + fn deserialize(fields: [Field; BOOL_SERIALIZED_LEN]) -> bool { + fields[0] as bool } } @@ -29,39 +31,51 @@ impl Deserialize for u8 { } } -impl Serialize for Field { +impl Serialize for u32 { fn serialize(self) -> [Field; U32_SERIALIZED_LEN] { - [self] + [self as Field] } } -impl Deserialize for Field { - fn deserialize(fields: [Field; FIELD_SERIALIZED_LEN]) -> Self { - fields[0] +impl Deserialize for u32 { + fn deserialize(fields: [Field; U32_SERIALIZED_LEN]) -> Self { + fields[0] as u32 } } -impl Serialize for bool { - fn serialize(self) -> [Field; BOOL_SERIALIZED_LEN] { +impl Serialize for u64 { + fn serialize(self) -> [Field; U64_SERIALIZED_LEN] { [self as Field] } } -impl Deserialize for bool { - fn deserialize(fields: [Field; BOOL_SERIALIZED_LEN]) -> bool { - fields[0] as bool +impl Deserialize for u64 { + fn deserialize(fields: [Field; U64_SERIALIZED_LEN]) -> Self { + fields[0] as u64 } } -impl Serialize<1> for U128 { +impl Serialize for U128 { fn serialize(self) -> [Field; 1] { [self.to_integer()] } } -impl Deserialize<1> for U128 { - fn deserialize(fields: [Field; 1]) -> Self { +impl Deserialize for U128 { + fn deserialize(fields: [Field; U128_SERIALIZED_LEN]) -> Self { U128::from_integer(fields[0]) } } + +impl Serialize for Field { + fn serialize(self) -> [Field; U32_SERIALIZED_LEN] { + [self] + } +} + +impl Deserialize for Field { + fn deserialize(fields: [Field; FIELD_SERIALIZED_LEN]) -> Self { + fields[0] + } +}