Skip to content

Commit 912d939

Browse files
authored
primefield: update to safegcd-bounds (#1331)
Uses the new safegcd impl, which has a better strategy for computing the upper bounds on the number of divstep operations. It also has improved "bounds" in other ways, namely it's impl'd for all sizes and no longer needs to rely on the `PrecomputedInverter` trait or `SafeGcdInverter` type, even in `const fn` contexts.
1 parent 156914a commit 912d939

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

primefield/src/monty.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
44
use crate::ByteOrder;
55
use bigint::{
6-
ArrayEncoding, ByteArray, Integer, Invert, Odd, PrecomputeInverter, Uint,
6+
ArrayEncoding, ByteArray, Integer, Invert, Uint,
77
hybrid_array::{Array, ArraySize, typenum::Unsigned},
8-
modular::{
9-
ConstMontyForm as MontyForm, ConstMontyFormInverter, ConstMontyParams, SafeGcdInverter,
10-
},
8+
modular::{ConstMontyForm as MontyForm, ConstMontyFormInverter, ConstMontyParams},
119
};
1210
use core::fmt::Formatter;
1311
use core::{
@@ -325,20 +323,14 @@ impl<MOD: MontyFieldParams<LIMBS>, const LIMBS: usize> MontyFieldElement<MOD, LI
325323

326324
/// Compute field inversion: `1 / self`.
327325
#[inline]
328-
pub fn invert(&self) -> CtOption<Self>
329-
where
330-
MontyForm<MOD, LIMBS>: Invert<Output = CtOption<MontyForm<MOD, LIMBS>>>,
331-
{
332-
self.0.invert().map(Self)
326+
pub fn invert(&self) -> CtOption<Self> {
327+
CtOption::from(self.0.invert()).map(Self)
333328
}
334329

335330
/// Compute field inversion as a `const fn`. Panics if `self` is zero.
336331
///
337332
/// This is mainly intended for inverting constants at compile time.
338-
pub const fn const_invert<const UNSAT_LIMBS: usize>(&self) -> Self
339-
where
340-
Odd<Uint<LIMBS>>: PrecomputeInverter<Inverter = SafeGcdInverter<LIMBS, UNSAT_LIMBS>, Output = Uint<LIMBS>>,
341-
{
333+
pub const fn const_invert(&self) -> Self {
342334
Self(
343335
ConstMontyFormInverter::<MOD, LIMBS>::new()
344336
.invert(&self.0)
@@ -377,13 +369,10 @@ impl<MOD: MontyFieldParams<LIMBS>, const LIMBS: usize> MontyFieldElement<MOD, LI
377369
// `ff` crate trait impls
378370
//
379371

380-
impl<MOD: MontyFieldParams<LIMBS>, const LIMBS: usize, const UNSAT_LIMBS: usize> Field
381-
for MontyFieldElement<MOD, LIMBS>
372+
impl<MOD: MontyFieldParams<LIMBS>, const LIMBS: usize> Field for MontyFieldElement<MOD, LIMBS>
382373
where
383374
Array<u8, MOD::ByteSize>: Copy,
384375
Uint<LIMBS>: ArrayEncoding,
385-
Odd<Uint<LIMBS>>:
386-
PrecomputeInverter<Inverter = SafeGcdInverter<LIMBS, UNSAT_LIMBS>, Output = Uint<LIMBS>>,
387376
{
388377
const ZERO: Self = Self::ZERO;
389378
const ONE: Self = Self::ONE;
@@ -424,13 +413,10 @@ where
424413
}
425414
}
426415

427-
impl<MOD: MontyFieldParams<LIMBS>, const LIMBS: usize, const UNSAT_LIMBS: usize> PrimeField
428-
for MontyFieldElement<MOD, LIMBS>
416+
impl<MOD: MontyFieldParams<LIMBS>, const LIMBS: usize> PrimeField for MontyFieldElement<MOD, LIMBS>
429417
where
430418
Array<u8, MOD::ByteSize>: Copy,
431419
Uint<LIMBS>: ArrayEncoding,
432-
Odd<Uint<LIMBS>>:
433-
PrecomputeInverter<Inverter = SafeGcdInverter<LIMBS, UNSAT_LIMBS>, Output = Uint<LIMBS>>,
434420
{
435421
type Repr = Array<u8, MOD::ByteSize>;
436422

0 commit comments

Comments
 (0)