pub struct PseudoMersenneModReduce { /* private fields */ }Expand description
Modular reduction verification for BigUint for pseudo Mersenne moduli.
This circuit verifies that:
a = quotient * (2^modulus_po2 - modulus_subtrahend) + remainder
where modulus_po2 is additionally restricted to be a multiple of limb size to only split BigUint at limb boundaries.
This algorithm is more efficient than ModReduce when modulus_subtrahend is a short
compared to modulus_po2. This is the case for many practically interesting prime field.
Implementations§
Source§impl PseudoMersenneModReduce
impl PseudoMersenneModReduce
Sourcepub fn new(
builder: &CircuitBuilder,
a: &BigUint,
modulus_po2: usize,
modulus_subtrahend: &BigUint,
quotient: &BigUint,
remainder: &BigUint,
) -> Self
pub fn new( builder: &CircuitBuilder, a: &BigUint, modulus_po2: usize, modulus_subtrahend: &BigUint, quotient: &BigUint, remainder: &BigUint, ) -> Self
Creates a new pseudo Mersenne modular reduction verifier circuit.
§Arguments
builder- Circuit builder for constraint generationa- The dividendmodulus_po2- the power of two modulus minuend (has to be a multiple ofWord::BITS)modulus_subtrahend- the value subtracted form2^modulus_po2to obtain modulusquotient- The quotientremainder- The remainder
§Constraints
The circuit enforces that a = quotient * (2^modulus_po2 - modulus_subtrahend) + remainder.
Remainder range check (0 <= remainder < 2^modulus_po2 - modulus_subtrahend) is not
enforced.
Note: This adds arithmetic constraints for computing intermediate values
(multiplication, addition, subtraction), but does NOT add the final equality
constraint. You must call .constrain() or .constrain_cond() to enforce
that the equation actually holds.
Sourcepub fn constrain(self, builder: &CircuitBuilder)
pub fn constrain(self, builder: &CircuitBuilder)
Apply the reduction constraint unconditionally.
Sourcepub fn constrain_cond(self, builder: &CircuitBuilder, cond: Wire)
pub fn constrain_cond(self, builder: &CircuitBuilder, cond: Wire)
Apply the reduction constraint conditionally based on the value of boolean mask wire.
Auto Trait Implementations§
impl Freeze for PseudoMersenneModReduce
impl RefUnwindSafe for PseudoMersenneModReduce
impl Send for PseudoMersenneModReduce
impl Sync for PseudoMersenneModReduce
impl Unpin for PseudoMersenneModReduce
impl UnsafeUnpin for PseudoMersenneModReduce
impl UnwindSafe for PseudoMersenneModReduce
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more