-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from Yoii-Inc/feat/less-than-constraints
✅ Add circuits test for enforce_smaller_eq_than
- Loading branch information
Showing
6 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use ark_ff::One; | ||
use ark_ff::PrimeField; | ||
use ark_r1cs_std::{alloc::AllocVar, boolean::Boolean}; | ||
use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystemRef, SynthesisError}; | ||
use mpc_algebra::{malicious_majority::MpcField, MpcBoolean}; | ||
|
||
type Fr = ark_bls12_377::Fr; | ||
type MFr = MpcField<Fr>; | ||
|
||
pub struct SmallerEqThanCircuit<F: PrimeField> { | ||
pub a: Vec<F>, | ||
// instance | ||
pub b: Fr, | ||
} | ||
|
||
impl ConstraintSynthesizer<MFr> for SmallerEqThanCircuit<MFr> { | ||
fn generate_constraints(self, cs: ConstraintSystemRef<MFr>) -> Result<(), SynthesisError> { | ||
// let a_var = MpcFpVar::new_witness(cs.clone(), || Ok(self.a))?; | ||
let a_var = self | ||
.a | ||
.iter() | ||
.map(|x| MpcBoolean::new_witness(cs.clone(), || Ok(x)).unwrap()) | ||
.collect::<Vec<_>>(); | ||
|
||
let _ = MpcBoolean::enforce_smaller_or_equal_than_le(&a_var, self.b.into_repr()).unwrap(); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl ConstraintSynthesizer<Fr> for SmallerEqThanCircuit<Fr> { | ||
fn generate_constraints(self, cs: ConstraintSystemRef<Fr>) -> Result<(), SynthesisError> { | ||
let a_var = self | ||
.a | ||
.iter() | ||
.map(|x| Boolean::new_witness(cs.clone(), || Ok(x.is_one())).unwrap()) | ||
.collect::<Vec<_>>(); | ||
|
||
let _ = Boolean::enforce_smaller_or_equal_than_le(&a_var, self.b.into_repr()).unwrap(); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters