From af3320c7f7dc5a048d42135886393679ba61f6d0 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Thu, 5 Oct 2023 11:27:27 -0300 Subject: [PATCH] Impl Zero --- crates/stark-felt/src/arbitrary_proptest.rs | 1 + crates/stark-felt/src/lib.rs | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/stark-felt/src/arbitrary_proptest.rs b/crates/stark-felt/src/arbitrary_proptest.rs index 28ae9e5..49ea020 100644 --- a/crates/stark-felt/src/arbitrary_proptest.rs +++ b/crates/stark-felt/src/arbitrary_proptest.rs @@ -1,4 +1,5 @@ use lambdaworks_math::{field::element::FieldElement, unsigned_integer::element::UnsignedInteger}; +use num_traits::Zero; use proptest::prelude::*; use crate::Felt; diff --git a/crates/stark-felt/src/lib.rs b/crates/stark-felt/src/lib.rs index 2bff8bc..e321ec1 100644 --- a/crates/stark-felt/src/lib.rs +++ b/crates/stark-felt/src/lib.rs @@ -3,7 +3,7 @@ use core::ops::{Add, Neg}; use bitvec::array::BitArray; -use num_traits::{FromPrimitive, ToPrimitive}; +use num_traits::{FromPrimitive, ToPrimitive, Zero}; #[cfg(test)] mod arbitrary_proptest; @@ -130,10 +130,6 @@ impl Felt { BitArray::new(limbs) } - /// Checks if `self` is equal to [Felt::ZERO]. - pub fn is_zero(&self) -> bool { - *self == Felt::ZERO - } /// Finite field division. pub fn field_div(&self, rhs: &NonZeroFelt) -> Self { Self(self.0 / rhs.0) @@ -381,6 +377,16 @@ impl ToPrimitive for Felt { } } +impl Zero for Felt { + fn is_zero(&self) -> bool { + *self == Felt::ZERO + } + + fn zero() -> Felt { + Felt::ZERO + } +} + impl Add<&Felt> for u64 { type Output = Option; @@ -822,10 +828,7 @@ mod errors { #[cfg(test)] mod test { - use super::{ - alloc::{format, string::String, vec::Vec}, - Felt, FieldElement, NonZeroFelt, - }; + use super::*; use crate::arbitrary_proptest::nonzero_felt; use core::ops::Shl; use proptest::prelude::*;