mirror of
https://github.com/arnaucube/ark-r1cs-std.git
synced 2026-01-10 16:01:28 +01:00
Runs rustfmt on the repo
This commit is contained in:
committed by
Pratyush Mishra
parent
a3e1cd6cf2
commit
b26867f267
@@ -13,9 +13,9 @@ use std::{borrow::Borrow, marker::PhantomData};
|
||||
#[derive(Derivative)]
|
||||
#[derivative(Clone(bound = "G: Group, W: PedersenWindow, ConstraintF: Field"))]
|
||||
pub struct PedersenCommitmentGadgetParameters<G: Group, W: PedersenWindow, ConstraintF: Field> {
|
||||
params: PedersenParameters<G>,
|
||||
params: PedersenParameters<G>,
|
||||
#[doc(hidden)]
|
||||
_group: PhantomData<G>,
|
||||
_group: PhantomData<G>,
|
||||
#[doc(hidden)]
|
||||
_engine: PhantomData<ConstraintF>,
|
||||
#[doc(hidden)]
|
||||
|
||||
@@ -122,8 +122,10 @@ impl<G: Group, W: PedersenWindow> FixedLengthCRH for BoweHopwoodPedersenCRH<G, W
|
||||
}
|
||||
assert_eq!(CHUNK_SIZE, 3);
|
||||
|
||||
// Compute sum of h_i^{sum of (1-2*c_{i,j,2})*(1+c_{i,j,0}+2*c_{i,j,1})*2^{4*(j-1)} for all j in segment} for all i.
|
||||
// Described in section 5.4.1.7 in the Zcash protocol specification.
|
||||
// Compute sum of h_i^{sum of
|
||||
// (1-2*c_{i,j,2})*(1+c_{i,j,0}+2*c_{i,j,1})*2^{4*(j-1)} for all j in segment}
|
||||
// for all i. Described in section 5.4.1.7 in the Zcash protocol
|
||||
// specification.
|
||||
let result = padded_input
|
||||
.par_chunks(W::WINDOW_SIZE * CHUNK_SIZE)
|
||||
.zip(¶meters.generators)
|
||||
|
||||
@@ -26,11 +26,11 @@ pub struct PedersenCRHGadgetParameters<
|
||||
|
||||
pub struct PedersenCRHGadget<G: Group, ConstraintF: Field, GG: GroupGadget<G, ConstraintF>> {
|
||||
#[doc(hideen)]
|
||||
_group: PhantomData<*const G>,
|
||||
_group: PhantomData<*const G>,
|
||||
#[doc(hideen)]
|
||||
_group_gadget: PhantomData<*const GG>,
|
||||
#[doc(hideen)]
|
||||
_engine: PhantomData<ConstraintF>,
|
||||
_engine: PhantomData<ConstraintF>,
|
||||
}
|
||||
|
||||
impl<ConstraintF, G, GG, W> FixedLengthCRHGadget<PedersenCRH<G, W>, ConstraintF>
|
||||
|
||||
@@ -200,7 +200,7 @@ impl<P: MerkleTreeConfig> MerkleHashTree<P> {
|
||||
|
||||
// Check that the given index corresponds to the correct leaf.
|
||||
if leaf_hash != self.tree[tree_index] {
|
||||
return Err(MerkleTreeError::IncorrectLeafIndex(tree_index).into())
|
||||
return Err(MerkleTreeError::IncorrectLeafIndex(tree_index).into());
|
||||
}
|
||||
|
||||
// Iterate from the leaf up to the root, storing all intermediate hash values.
|
||||
@@ -230,7 +230,7 @@ impl<P: MerkleTreeConfig> MerkleHashTree<P> {
|
||||
}
|
||||
end_timer!(prove_time);
|
||||
if path.len() != (Self::HEIGHT - 1) as usize {
|
||||
return Err(MerkleTreeError::IncorrectPathLength(path.len()).into())
|
||||
return Err(MerkleTreeError::IncorrectPathLength(path.len()).into());
|
||||
} else {
|
||||
Ok(MerkleTreePath { path })
|
||||
}
|
||||
@@ -371,8 +371,7 @@ mod test {
|
||||
crh::{pedersen::*, *},
|
||||
merkle_tree::*,
|
||||
};
|
||||
use algebra::curves::jubjub::JubJubAffine as JubJub;
|
||||
use algebra::Zero;
|
||||
use algebra::{curves::jubjub::JubJubAffine as JubJub, Zero};
|
||||
use rand::SeedableRng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ pub struct Gm17<
|
||||
V: ToConstraintField<E::Fr> + ?Sized,
|
||||
> {
|
||||
#[doc(hidden)]
|
||||
_engine: PhantomData<E>,
|
||||
_engine: PhantomData<E>,
|
||||
#[doc(hidden)]
|
||||
_circuit: PhantomData<C>,
|
||||
_circuit: PhantomData<C>,
|
||||
#[doc(hidden)]
|
||||
_verifier_input: PhantomData<V>,
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ pub struct Groth16<
|
||||
V: ToConstraintField<E::Fr> + ?Sized,
|
||||
> {
|
||||
#[doc(hidden)]
|
||||
_engine: PhantomData<E>,
|
||||
_engine: PhantomData<E>,
|
||||
#[doc(hidden)]
|
||||
_circuit: PhantomData<C>,
|
||||
_circuit: PhantomData<C>,
|
||||
#[doc(hidden)]
|
||||
_verifier_input: PhantomData<V>,
|
||||
}
|
||||
|
||||
@@ -59,8 +59,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_gm17() {
|
||||
use crate::nizk::{gm17::Gm17, NIZK};
|
||||
use algebra::{curves::bls12_381::Bls12_381, fields::bls12_381::Fr};
|
||||
use algebra::One;
|
||||
use algebra::{curves::bls12_381::Bls12_381, fields::bls12_381::Fr, One};
|
||||
use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, SynthesisError};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
|
||||
@@ -38,18 +38,18 @@ impl<G: Group, ConstraintF: Field, GG: GroupGadget<G, ConstraintF>> Clone
|
||||
pub struct SchnorrSigGadgetPk<G: Group, ConstraintF: Field, GG: GroupGadget<G, ConstraintF>> {
|
||||
pub_key: GG,
|
||||
#[doc(hidden)]
|
||||
_group: PhantomData<*const G>,
|
||||
_group: PhantomData<*const G>,
|
||||
#[doc(hidden)]
|
||||
_engine: PhantomData<*const ConstraintF>,
|
||||
}
|
||||
|
||||
pub struct SchnorrRandomizePkGadget<G: Group, ConstraintF: Field, GG: GroupGadget<G, ConstraintF>> {
|
||||
#[doc(hidden)]
|
||||
_group: PhantomData<*const G>,
|
||||
_group: PhantomData<*const G>,
|
||||
#[doc(hidden)]
|
||||
_group_gadget: PhantomData<*const GG>,
|
||||
#[doc(hidden)]
|
||||
_engine: PhantomData<*const ConstraintF>,
|
||||
_engine: PhantomData<*const ConstraintF>,
|
||||
}
|
||||
|
||||
impl<G, GG, D, ConstraintF> SigRandomizePkGadget<SchnorrSignature<G, D>, ConstraintF>
|
||||
|
||||
@@ -3,10 +3,9 @@ use algebra::{
|
||||
bytes::ToBytes,
|
||||
fields::{Field, PrimeField},
|
||||
groups::Group,
|
||||
to_bytes, ToConstraintField, UniformRand,
|
||||
to_bytes, One, ToConstraintField, UniformRand, Zero,
|
||||
};
|
||||
use digest::Digest;
|
||||
use algebra::{One, Zero};
|
||||
use rand::Rng;
|
||||
use std::{
|
||||
hash::Hash,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use algebra::{BitIterator, Field, FpParameters, PrimeField};
|
||||
|
||||
use crate::{prelude::*, Assignment};
|
||||
use r1cs_core::{ConstraintSystem, LinearCombination, SynthesisError, Variable, ConstraintVar};
|
||||
use r1cs_core::{ConstraintSystem, ConstraintVar, LinearCombination, SynthesisError, Variable};
|
||||
use std::borrow::Borrow;
|
||||
|
||||
/// Represents a variable in the constraint system which is guaranteed
|
||||
@@ -336,11 +336,14 @@ fn cond_select_helper<F: PrimeField, CS: ConstraintSystem<F>>(
|
||||
) -> Result<AllocatedBit, SynthesisError> {
|
||||
let mut result_val = None;
|
||||
let result_var = cs.alloc(
|
||||
|| "cond_select_result",
|
||||
|| "cond_select_result",
|
||||
|| {
|
||||
result_val = cond.get_value().and_then(|c| if c { first.0 } else { second.0 });
|
||||
result_val = cond
|
||||
.get_value()
|
||||
.and_then(|c| if c { first.0 } else { second.0 });
|
||||
result_val.get().map(|v| F::from(v as u8))
|
||||
})?;
|
||||
},
|
||||
)?;
|
||||
|
||||
let first_var = first.1.into();
|
||||
let second_var = second.1.into();
|
||||
@@ -358,8 +361,10 @@ fn cond_select_helper<F: PrimeField, CS: ConstraintSystem<F>>(
|
||||
|lc| ConstraintVar::from(result_var) - &second_var + lc,
|
||||
);
|
||||
|
||||
Ok(AllocatedBit { value: result_val, variable: result_var })
|
||||
|
||||
Ok(AllocatedBit {
|
||||
value: result_val,
|
||||
variable: result_var,
|
||||
})
|
||||
}
|
||||
|
||||
/// This is a boolean value which may be either a constant or
|
||||
@@ -800,31 +805,23 @@ impl<ConstraintF: PrimeField> CondSelectGadget<ConstraintF> for Boolean {
|
||||
Boolean::Constant(true) => Ok(first.clone()),
|
||||
Boolean::Constant(false) => Ok(second.clone()),
|
||||
cond @ Boolean::Not(_) => Self::conditionally_select(cs, &cond.not(), second, first),
|
||||
cond @ Boolean::Is(_) => {
|
||||
match (first, second) {
|
||||
(x, &Boolean::Constant(false)) => {
|
||||
Boolean::and(cs.ns(|| "and"), cond, x).into()
|
||||
},
|
||||
(&Boolean::Constant(false), x) => {
|
||||
Boolean::and(cs.ns(|| "and"), &cond.not(), x)
|
||||
},
|
||||
(&Boolean::Constant(true), x) => {
|
||||
Boolean::or(cs.ns(|| "or"), cond, x).into()
|
||||
},
|
||||
(x, &Boolean::Constant(true)) => {
|
||||
Boolean::or(cs.ns(|| "or"), &cond.not(), x)
|
||||
},
|
||||
(a @ Boolean::Is(_), b @ Boolean::Is(_))
|
||||
| (a @ Boolean::Not(_), b @ Boolean::Not(_))
|
||||
| (a @ Boolean::Is(_), b @ Boolean::Not(_))
|
||||
| (a @ Boolean::Not(_), b @ Boolean::Is(_)) => {
|
||||
let a_lc = a.lc(CS::one(), ConstraintF::one());
|
||||
let b_lc = b.lc(CS::one(), ConstraintF::one());
|
||||
Ok(cond_select_helper(cs, cond, (a.get_value(), a_lc), (b.get_value(), b_lc))?.into())
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
cond @ Boolean::Is(_) => match (first, second) {
|
||||
(x, &Boolean::Constant(false)) => Boolean::and(cs.ns(|| "and"), cond, x).into(),
|
||||
(&Boolean::Constant(false), x) => Boolean::and(cs.ns(|| "and"), &cond.not(), x),
|
||||
(&Boolean::Constant(true), x) => Boolean::or(cs.ns(|| "or"), cond, x).into(),
|
||||
(x, &Boolean::Constant(true)) => Boolean::or(cs.ns(|| "or"), &cond.not(), x),
|
||||
(a @ Boolean::Is(_), b @ Boolean::Is(_))
|
||||
| (a @ Boolean::Not(_), b @ Boolean::Not(_))
|
||||
| (a @ Boolean::Is(_), b @ Boolean::Not(_))
|
||||
| (a @ Boolean::Not(_), b @ Boolean::Is(_)) => {
|
||||
let a_lc = a.lc(CS::one(), ConstraintF::one());
|
||||
let b_lc = b.lc(CS::one(), ConstraintF::one());
|
||||
Ok(
|
||||
cond_select_helper(cs, cond, (a.get_value(), a_lc), (b.get_value(), b_lc))?
|
||||
.into(),
|
||||
)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -837,8 +834,7 @@ impl<ConstraintF: PrimeField> CondSelectGadget<ConstraintF> for Boolean {
|
||||
mod test {
|
||||
use super::{AllocatedBit, Boolean};
|
||||
use crate::{prelude::*, test_constraint_system::TestConstraintSystem};
|
||||
use algebra::{fields::bls12_381::Fr, BitIterator, Field, PrimeField, UniformRand};
|
||||
use algebra::{One, Zero};
|
||||
use algebra::{fields::bls12_381::Fr, BitIterator, Field, One, PrimeField, UniformRand, Zero};
|
||||
use r1cs_core::ConstraintSystem;
|
||||
use rand::SeedableRng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
@@ -1408,10 +1404,12 @@ mod test {
|
||||
Boolean::from(AllocatedBit::alloc(cs, || Ok(false)).unwrap())
|
||||
},
|
||||
OperandType::NegatedAllocatedTrue => {
|
||||
Boolean::from(AllocatedBit::alloc(cs, || Ok(true)).unwrap()).not()
|
||||
Boolean::from(AllocatedBit::alloc(cs, || Ok(true)).unwrap())
|
||||
.not()
|
||||
},
|
||||
OperandType::NegatedAllocatedFalse => {
|
||||
Boolean::from(AllocatedBit::alloc(cs, || Ok(false)).unwrap()).not()
|
||||
Boolean::from(AllocatedBit::alloc(cs, || Ok(false)).unwrap())
|
||||
.not()
|
||||
},
|
||||
}
|
||||
};
|
||||
@@ -1432,7 +1430,14 @@ mod test {
|
||||
first_operand,
|
||||
second_operand,
|
||||
);
|
||||
assert_eq!(c.get_value(), if cond.get_value().unwrap() { a.get_value() } else { b.get_value() });
|
||||
assert_eq!(
|
||||
c.get_value(),
|
||||
if cond.get_value().unwrap() {
|
||||
a.get_value()
|
||||
} else {
|
||||
b.get_value()
|
||||
}
|
||||
);
|
||||
assert!(<Boolean as CondSelectGadget<Fr>>::cost() >= after - before);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,8 +344,7 @@ impl<ConstraintF: Field> ConditionalEqGadget<ConstraintF> for UInt32 {
|
||||
mod test {
|
||||
use super::UInt32;
|
||||
use crate::{bits::boolean::Boolean, test_constraint_system::TestConstraintSystem};
|
||||
use algebra::fields::bls12_381::Fr;
|
||||
use algebra::{One, Zero};
|
||||
use algebra::{fields::bls12_381::Fr, One, Zero};
|
||||
use r1cs_core::ConstraintSystem;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use rand_xorshift::XorShiftRng;
|
||||
|
||||
@@ -6,9 +6,8 @@ use algebra::{
|
||||
fp6_3over2::{Fp6, Fp6Parameters},
|
||||
Fp2Parameters,
|
||||
},
|
||||
BitIterator, Field, PrimeField,
|
||||
BitIterator, Field, One, PrimeField,
|
||||
};
|
||||
use algebra::One;
|
||||
use std::{borrow::Borrow, marker::PhantomData};
|
||||
|
||||
use crate::{prelude::*, Assignment};
|
||||
@@ -32,8 +31,8 @@ where
|
||||
P: Fp12Parameters,
|
||||
<P::Fp6Params as Fp6Parameters>::Fp2Params: Fp2Parameters<Fp = ConstraintF>,
|
||||
{
|
||||
pub c0: Fp6Gadget<P, ConstraintF>,
|
||||
pub c1: Fp6Gadget<P, ConstraintF>,
|
||||
pub c0: Fp6Gadget<P, ConstraintF>,
|
||||
pub c1: Fp6Gadget<P, ConstraintF>,
|
||||
#[derivative(Debug = "ignore")]
|
||||
_params: PhantomData<P>,
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ use crate::{fields::fp::FpGadget, prelude::*, Assignment};
|
||||
#[derivative(Debug(bound = "P: Fp2Parameters, ConstraintF: PrimeField"))]
|
||||
#[must_use]
|
||||
pub struct Fp2Gadget<P: Fp2Parameters<Fp = ConstraintF>, ConstraintF: PrimeField> {
|
||||
pub c0: FpGadget<ConstraintF>,
|
||||
pub c1: FpGadget<ConstraintF>,
|
||||
pub c0: FpGadget<ConstraintF>,
|
||||
pub c1: FpGadget<ConstraintF>,
|
||||
#[derivative(Debug = "ignore")]
|
||||
_params: PhantomData<P>,
|
||||
}
|
||||
@@ -75,10 +75,7 @@ impl<P: Fp2Parameters<Fp = ConstraintF>, ConstraintF: PrimeField> FieldGadget<Fp
|
||||
|
||||
#[inline]
|
||||
fn get_variable(&self) -> Self::Variable {
|
||||
(
|
||||
self.c0.get_variable(),
|
||||
self.c1.get_variable(),
|
||||
)
|
||||
(self.c0.get_variable(), self.c1.get_variable())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -21,9 +21,9 @@ where
|
||||
P: Fp6Parameters,
|
||||
P::Fp2Params: Fp2Parameters<Fp = ConstraintF>,
|
||||
{
|
||||
pub c0: Fp2Gadget<P, ConstraintF>,
|
||||
pub c1: Fp2Gadget<P, ConstraintF>,
|
||||
pub c2: Fp2Gadget<P, ConstraintF>,
|
||||
pub c0: Fp2Gadget<P, ConstraintF>,
|
||||
pub c1: Fp2Gadget<P, ConstraintF>,
|
||||
pub c2: Fp2Gadget<P, ConstraintF>,
|
||||
#[derivative(Debug = "ignore")]
|
||||
_params: PhantomData<P>,
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use algebra::{
|
||||
curves::bls12::{Bls12Parameters, G1Prepared, TwistType},
|
||||
fields::Field,
|
||||
BitIterator, ProjectiveCurve,
|
||||
BitIterator, One, ProjectiveCurve,
|
||||
};
|
||||
use algebra::One;
|
||||
use r1cs_core::{ConstraintSystem, SynthesisError};
|
||||
|
||||
use crate::{
|
||||
|
||||
@@ -3,9 +3,8 @@ use algebra::{
|
||||
short_weierstrass_jacobian::{GroupAffine as SWAffine, GroupProjective as SWProjective},
|
||||
SWModelParameters,
|
||||
},
|
||||
AffineCurve, BitIterator, Field, PrimeField, ProjectiveCurve,
|
||||
AffineCurve, BitIterator, Field, One, PrimeField, ProjectiveCurve, Zero,
|
||||
};
|
||||
use algebra::{One, Zero};
|
||||
use r1cs_core::{ConstraintSystem, SynthesisError};
|
||||
use std::{borrow::Borrow, marker::PhantomData, ops::Neg};
|
||||
|
||||
@@ -21,11 +20,11 @@ pub struct AffineGadget<
|
||||
ConstraintF: Field,
|
||||
F: FieldGadget<P::BaseField, ConstraintF>,
|
||||
> {
|
||||
pub x: F,
|
||||
pub y: F,
|
||||
pub x: F,
|
||||
pub y: F,
|
||||
pub infinity: Boolean,
|
||||
_params: PhantomData<P>,
|
||||
_engine: PhantomData<ConstraintF>,
|
||||
_params: PhantomData<P>,
|
||||
_engine: PhantomData<ConstraintF>,
|
||||
}
|
||||
|
||||
impl<P: SWModelParameters, ConstraintF: Field, F: FieldGadget<P::BaseField, ConstraintF>>
|
||||
@@ -99,7 +98,11 @@ where
|
||||
|
||||
#[inline]
|
||||
fn get_value(&self) -> Option<Self::Value> {
|
||||
match (self.x.get_value(), self.y.get_value(), self.infinity.get_value()) {
|
||||
match (
|
||||
self.x.get_value(),
|
||||
self.y.get_value(),
|
||||
self.infinity.get_value(),
|
||||
) {
|
||||
(Some(x), Some(y), Some(infinity)) => {
|
||||
Some(SWAffine::new(x, y, infinity).into_projective())
|
||||
},
|
||||
@@ -341,14 +344,19 @@ where
|
||||
) -> Result<Self, SynthesisError> {
|
||||
let x = F::conditionally_select(&mut cs.ns(|| "x"), cond, &first.x, &second.x)?;
|
||||
let y = F::conditionally_select(&mut cs.ns(|| "y"), cond, &first.y, &second.y)?;
|
||||
let infinity = Boolean::conditionally_select(&mut cs.ns(|| "infinity"), cond, &first.infinity, &second.infinity)?;
|
||||
let infinity = Boolean::conditionally_select(
|
||||
&mut cs.ns(|| "infinity"),
|
||||
cond,
|
||||
&first.infinity,
|
||||
&second.infinity,
|
||||
)?;
|
||||
|
||||
Ok(Self::new(x, y, infinity))
|
||||
}
|
||||
|
||||
fn cost() -> usize {
|
||||
2 * <F as CondSelectGadget<ConstraintF>>::cost() +
|
||||
<Boolean as CondSelectGadget<ConstraintF>>::cost()
|
||||
2 * <F as CondSelectGadget<ConstraintF>>::cost()
|
||||
+ <Boolean as CondSelectGadget<ConstraintF>>::cost()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -558,7 +566,7 @@ where
|
||||
FN: FnOnce() -> Result<T, SynthesisError>,
|
||||
T: Borrow<SWProjective<P>>,
|
||||
{
|
||||
// When allocating the input we assume that the verifier has performed
|
||||
// When allocating the input we assume that the verifier has performed
|
||||
// any on curve checks already.
|
||||
let (x, y, infinity) = match value_gen() {
|
||||
Ok(ge) => {
|
||||
|
||||
@@ -3,9 +3,8 @@ use algebra::{
|
||||
twisted_edwards_extended::GroupAffine as TEAffine, MontgomeryModelParameters,
|
||||
TEModelParameters,
|
||||
},
|
||||
BitIterator, Field,
|
||||
BitIterator, Field, One, Zero,
|
||||
};
|
||||
use algebra::{One, Zero};
|
||||
|
||||
use r1cs_core::{ConstraintSystem, SynthesisError};
|
||||
|
||||
@@ -28,8 +27,8 @@ pub struct MontgomeryAffineGadget<
|
||||
ConstraintF: Field,
|
||||
F: FieldGadget<P::BaseField, ConstraintF>,
|
||||
> {
|
||||
pub x: F,
|
||||
pub y: F,
|
||||
pub x: F,
|
||||
pub y: F,
|
||||
#[derivative(Debug = "ignore")]
|
||||
_params: PhantomData<P>,
|
||||
#[derivative(Debug = "ignore")]
|
||||
@@ -62,8 +61,8 @@ mod montgomery_affine_impl {
|
||||
} else if p.x == P::BaseField::zero() {
|
||||
GroupAffine::new(P::BaseField::zero(), P::BaseField::zero())
|
||||
} else {
|
||||
let u = (P::BaseField::one() + &p.y)
|
||||
* &(P::BaseField::one() - &p.y).inverse().unwrap();
|
||||
let u =
|
||||
(P::BaseField::one() + &p.y) * &(P::BaseField::one() - &p.y).inverse().unwrap();
|
||||
let v = u * &p.x.inverse().unwrap();
|
||||
GroupAffine::new(u, v)
|
||||
};
|
||||
@@ -200,8 +199,8 @@ pub struct AffineGadget<
|
||||
ConstraintF: Field,
|
||||
F: FieldGadget<P::BaseField, ConstraintF>,
|
||||
> {
|
||||
pub x: F,
|
||||
pub y: F,
|
||||
pub x: F,
|
||||
pub y: F,
|
||||
#[derivative(Debug = "ignore")]
|
||||
_params: PhantomData<P>,
|
||||
#[derivative(Debug = "ignore")]
|
||||
|
||||
@@ -71,6 +71,6 @@ pub trait Assignment<T> {
|
||||
|
||||
impl<T> Assignment<T> for Option<T> {
|
||||
fn get(self) -> Result<T, r1cs_core::SynthesisError> {
|
||||
self.ok_or_else(|| { r1cs_core::SynthesisError::AssignmentMissing })
|
||||
self.ok_or_else(|| r1cs_core::SynthesisError::AssignmentMissing)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +59,7 @@ pub trait PairingGadget<PairingE: PairingEngine, ConstraintF: Field> {
|
||||
mod test {
|
||||
// use rand;
|
||||
use crate::test_constraint_system::TestConstraintSystem;
|
||||
use algebra::{BitIterator, Field};
|
||||
use algebra::One;
|
||||
use algebra::{BitIterator, Field, One};
|
||||
use r1cs_core::ConstraintSystem;
|
||||
|
||||
#[test]
|
||||
@@ -107,23 +106,17 @@ mod test {
|
||||
let sb_prep_g = G2PreparedGadget::from_affine(&mut cs.ns(|| "sb_prep"), &sb_g).unwrap();
|
||||
|
||||
let (ans1_g, ans1_n) = {
|
||||
let ans_g = PairingGadget::pairing(
|
||||
cs.ns(|| "pair(sa, b)"),
|
||||
sa_prep_g,
|
||||
b_prep_g.clone(),
|
||||
)
|
||||
.unwrap();
|
||||
let ans_g =
|
||||
PairingGadget::pairing(cs.ns(|| "pair(sa, b)"), sa_prep_g, b_prep_g.clone())
|
||||
.unwrap();
|
||||
let ans_n = Bls12_377::pairing(sa, b);
|
||||
(ans_g, ans_n)
|
||||
};
|
||||
|
||||
let (ans2_g, ans2_n) = {
|
||||
let ans_g = PairingGadget::pairing(
|
||||
cs.ns(|| "pair(a, sb)"),
|
||||
a_prep_g.clone(),
|
||||
sb_prep_g,
|
||||
)
|
||||
.unwrap();
|
||||
let ans_g =
|
||||
PairingGadget::pairing(cs.ns(|| "pair(a, sb)"), a_prep_g.clone(), sb_prep_g)
|
||||
.unwrap();
|
||||
let ans_n = Bls12_377::pairing(a, sb);
|
||||
(ans_g, ans_n)
|
||||
};
|
||||
@@ -134,8 +127,7 @@ mod test {
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut ans_g =
|
||||
PairingGadget::pairing(cs.ns(|| "pair(a, b)"), a_prep_g, b_prep_g)
|
||||
.unwrap();
|
||||
PairingGadget::pairing(cs.ns(|| "pair(a, b)"), a_prep_g, b_prep_g).unwrap();
|
||||
let mut ans_n = Bls12_377::pairing(a, b);
|
||||
ans_n = ans_n.pow(s.into_repr());
|
||||
ans_g = ans_g.pow(cs.ns(|| "pow"), &s_iter).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user