Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ConstZero trait from num_traits #573

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ subtle = { version = "2.5", default-features = false }
# optional dependencies
der = { version = "0.7", optional = true, default-features = false }
hybrid-array = { version = "0.2.0-rc.4", optional = true }
num-traits = { version = "0.2", default-features = false }
num-traits = { version = "0.2.18", default-features = false }
rand_core = { version = "0.6.4", optional = true }
rlp = { version = "0.5", optional = true, default-features = false }
serdect = { version = "0.2", optional = true, default-features = false }
Expand Down
12 changes: 12 additions & 0 deletions src/modular/const_monty_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> ConstZero for ConstMontyF
const ZERO: Self = Self::ZERO;
}

impl<MOD: ConstMontyParams<LIMBS>, const LIMBS: usize> num_traits::Zero
for ConstMontyForm<MOD, LIMBS>
{
fn zero() -> Self {
Self::ZERO
}

fn is_zero(&self) -> bool {
self.ct_eq(&Self::ZERO).into()
}
}

#[cfg(feature = "rand_core")]
impl<MOD, const LIMBS: usize> Random for ConstMontyForm<MOD, LIMBS>
where
Expand Down
12 changes: 2 additions & 10 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mod sealed;

pub use num_traits::{
WrappingAdd, WrappingMul, WrappingNeg, WrappingShl, WrappingShr, WrappingSub,
ConstZero, WrappingAdd, WrappingMul, WrappingNeg, WrappingShl, WrappingShr, WrappingSub,
};

pub(crate) use sealed::PrecomputeInverterWithAdjuster;
Expand Down Expand Up @@ -264,15 +264,7 @@ pub trait Zero: ConstantTimeEq + Sized {
}
}

/// Trait for associating a constant representing zero.
///
/// Types which impl this trait automatically receive a blanket impl of [`Zero`].
pub trait ConstZero: Zero {
/// The value `0`.
const ZERO: Self;
}

impl<T: ConstZero> Zero for T {
impl<T: ConstZero + ConstantTimeEq> Zero for T {
#[inline(always)]
fn zero() -> T {
Self::ZERO
Expand Down