Skip to content

Commit

Permalink
added must use
Browse files Browse the repository at this point in the history
  • Loading branch information
puma314 committed Mar 8, 2024
1 parent 9837327 commit d6b6996
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions plonky2x/core/src/frontend/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
}

/// Returns 1 if i1 is zero, 0 otherwise as a boolean.
#[must_use]
pub fn is_zero(&mut self, i1: Variable) -> BoolVariable {
let zero = self.api.zero();

Expand All @@ -372,6 +373,7 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
}

/// Returns 1 if i1 == i2 and 0 otherwise as a BoolVariable.
#[must_use]
pub fn is_equal<V: CircuitVariable>(&mut self, i1: V, i2: V) -> BoolVariable {
let mut result = self._true();
for (t1, t2) in i1.targets().iter().zip(i2.targets().iter()) {
Expand Down
2 changes: 1 addition & 1 deletion plonky2x/core/src/frontend/hash/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
// = a*( 1 - 2*b - 2*c + 4*b*c ) + b + c - 2*b*c
// = a*( 1 - 2*b -2*c + 4*m ) + b + c - 2*m
// where m = b*c
//
#[must_use]
pub fn xor3(&mut self, a: Variable, b: Variable, c: Variable) -> BoolVariable {
let m = self.mul(b, c);
let two_b = self.add(b, b);
Expand Down
6 changes: 6 additions & 0 deletions plonky2x/core/src/frontend/ops/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
///
/// Types implementing this trait can be used within the `builder.lte(lhs, rhs)` method.
pub trait LessThanOrEqual<L: PlonkParameters<D>, const D: usize, Rhs = Self> {
#[must_use]
fn lte(self, rhs: Rhs, builder: &mut CircuitBuilder<L, D>) -> BoolVariable;
}

impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
/// The less than or equal to operation (<=).
#[must_use]
pub fn lte<Lhs, Rhs>(&mut self, lhs: Lhs, rhs: Rhs) -> BoolVariable
where
Lhs: LessThanOrEqual<L, D, Rhs>,
Expand All @@ -166,6 +168,7 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
}

/// The less than operation (<).
#[must_use]
pub fn lt<Lhs, Rhs>(&mut self, lhs: Lhs, rhs: Rhs) -> BoolVariable
where
Rhs: LessThanOrEqual<L, D, Lhs>,
Expand All @@ -175,6 +178,7 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
}

/// The greater than operation (>).
#[must_use]
pub fn gt<Lhs, Rhs>(&mut self, lhs: Lhs, rhs: Rhs) -> BoolVariable
where
Lhs: LessThanOrEqual<L, D, Rhs>,
Expand All @@ -183,6 +187,7 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
}

/// The greater than or equal to operation (>=).
#[must_use]
pub fn gte<Lhs, Rhs>(&mut self, lhs: Lhs, rhs: Rhs) -> BoolVariable
where
Rhs: LessThanOrEqual<L, D, Lhs>,
Expand All @@ -191,6 +196,7 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
}

/// The within range operation (lhs <= variable < rhs).
#[must_use]
pub fn within_range<V>(&mut self, variable: V, lhs: V, rhs: V) -> BoolVariable
where
V: LessThanOrEqual<L, D, V> + Sub<L, D, V, Output = V> + One<L, D> + Clone,
Expand Down
1 change: 1 addition & 0 deletions plonky2x/core/src/frontend/uint/uint32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ impl From<U32Target> for U32Variable {
}

impl<L: PlonkParameters<D>, const D: usize> LessThanOrEqual<L, D> for U32Variable {
#[must_use]
fn lte(self, rhs: Self, builder: &mut CircuitBuilder<L, D>) -> BoolVariable {
list_lte_circuit(&mut builder.api, self.targets(), rhs.targets(), 32).into()
}
Expand Down
1 change: 1 addition & 0 deletions plonky2x/core/src/frontend/uint/uint32_n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ macro_rules! make_uint32_n {
}

impl<L: PlonkParameters<D>, const D: usize> LessThanOrEqual<L, D> for $a {
#[must_use]
fn lte(self, rhs: Self, builder: &mut CircuitBuilder<L, D>) -> BoolVariable {
let mut lte_acc = builder.constant::<BoolVariable>(false);
let mut equal_so_far = builder.constant::<BoolVariable>(true);
Expand Down

0 comments on commit d6b6996

Please sign in to comment.