mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-01-30 23:42:13 +00:00
Address various clippy warnings/errors in bellman
This commit is contained in:
parent
d78c94b2a2
commit
d65fe2cda9
@ -26,15 +26,19 @@ pub struct EvaluationDomain<E: ScalarEngine, G: Group<E>> {
|
|||||||
minv: E::Fr,
|
minv: E::Fr,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: ScalarEngine, G: Group<E>> EvaluationDomain<E, G> {
|
impl<E: ScalarEngine, G: Group<E>> AsRef<[G]> for EvaluationDomain<E, G> {
|
||||||
pub fn as_ref(&self) -> &[G] {
|
fn as_ref(&self) -> &[G] {
|
||||||
&self.coeffs
|
&self.coeffs
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn as_mut(&mut self) -> &mut [G] {
|
impl<E: ScalarEngine, G: Group<E>> AsMut<[G]> for EvaluationDomain<E, G> {
|
||||||
|
fn as_mut(&mut self) -> &mut [G] {
|
||||||
&mut self.coeffs
|
&mut self.coeffs
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<E: ScalarEngine, G: Group<E>> EvaluationDomain<E, G> {
|
||||||
pub fn into_coeffs(self) -> Vec<G> {
|
pub fn into_coeffs(self) -> Vec<G> {
|
||||||
self.coeffs
|
self.coeffs
|
||||||
}
|
}
|
||||||
@ -64,9 +68,9 @@ impl<E: ScalarEngine, G: Group<E>> EvaluationDomain<E, G> {
|
|||||||
coeffs.resize(m, G::group_zero());
|
coeffs.resize(m, G::group_zero());
|
||||||
|
|
||||||
Ok(EvaluationDomain {
|
Ok(EvaluationDomain {
|
||||||
coeffs: coeffs,
|
coeffs,
|
||||||
exp: exp,
|
exp,
|
||||||
omega: omega,
|
omega,
|
||||||
omegainv: omega.inverse().unwrap(),
|
omegainv: omega.inverse().unwrap(),
|
||||||
geninv: E::Fr::multiplicative_generator().inverse().unwrap(),
|
geninv: E::Fr::multiplicative_generator().inverse().unwrap(),
|
||||||
minv: E::Fr::from_str(&format!("{}", m))
|
minv: E::Fr::from_str(&format!("{}", m))
|
||||||
@ -291,7 +295,7 @@ fn serial_fft<E: ScalarEngine, T: Group<E>>(a: &mut [T], omega: &E::Fr, log_n: u
|
|||||||
|
|
||||||
let mut m = 1;
|
let mut m = 1;
|
||||||
for _ in 0..log_n {
|
for _ in 0..log_n {
|
||||||
let w_m = omega.pow(&[(n / (2 * m)) as u64]);
|
let w_m = omega.pow(&[u64::from(n / (2 * m))]);
|
||||||
|
|
||||||
let mut k = 0;
|
let mut k = 0;
|
||||||
while k < n {
|
while k < n {
|
||||||
@ -337,12 +341,12 @@ fn parallel_fft<E: ScalarEngine, T: Group<E>>(
|
|||||||
let omega_step = omega.pow(&[(j as u64) << log_new_n]);
|
let omega_step = omega.pow(&[(j as u64) << log_new_n]);
|
||||||
|
|
||||||
let mut elt = E::Fr::one();
|
let mut elt = E::Fr::one();
|
||||||
for i in 0..(1 << log_new_n) {
|
for (i, tmp) in tmp.iter_mut().enumerate() {
|
||||||
for s in 0..num_cpus {
|
for s in 0..num_cpus {
|
||||||
let idx = (i + (s << log_new_n)) % (1 << log_n);
|
let idx = (i + (s << log_new_n)) % (1 << log_n);
|
||||||
let mut t = a[idx];
|
let mut t = a[idx];
|
||||||
t.group_mul_assign(&elt);
|
t.group_mul_assign(&elt);
|
||||||
tmp[i].group_add_assign(&t);
|
tmp.group_add_assign(&t);
|
||||||
elt.mul_assign(&omega_step);
|
elt.mul_assign(&omega_step);
|
||||||
}
|
}
|
||||||
elt.mul_assign(&omega_j);
|
elt.mul_assign(&omega_j);
|
||||||
|
@ -382,7 +382,7 @@ pub fn blake2s<E: Engine, CS: ConstraintSystem<E>>(
|
|||||||
blocks.push(this_block);
|
blocks.push(this_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
if blocks.len() == 0 {
|
if blocks.is_empty() {
|
||||||
blocks.push((0..16).map(|_| UInt32::constant(0)).collect());
|
blocks.push((0..16).map(|_| UInt32::constant(0)).collect());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,7 +433,7 @@ mod test {
|
|||||||
let expected = hex!("c59f682376d137f3f255e671e207d1f2374ebe504e9314208a52d9f88d69e8c8");
|
let expected = hex!("c59f682376d137f3f255e671e207d1f2374ebe504e9314208a52d9f88d69e8c8");
|
||||||
|
|
||||||
let mut out = out.into_iter();
|
let mut out = out.into_iter();
|
||||||
for b in expected.into_iter() {
|
for b in expected.iter() {
|
||||||
for i in 0..8 {
|
for i in 0..8 {
|
||||||
let c = out.next().unwrap().get_value().unwrap();
|
let c = out.next().unwrap().get_value().unwrap();
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ impl AllocatedBit {
|
|||||||
|
|
||||||
Ok(AllocatedBit {
|
Ok(AllocatedBit {
|
||||||
variable: var,
|
variable: var,
|
||||||
value: value,
|
value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ impl AllocatedBit {
|
|||||||
|
|
||||||
Ok(AllocatedBit {
|
Ok(AllocatedBit {
|
||||||
variable: var,
|
variable: var,
|
||||||
value: value,
|
value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ pub fn field_into_boolean_vec_le<E: Engine, CS: ConstraintSystem<E>, F: PrimeFie
|
|||||||
) -> Result<Vec<Boolean>, SynthesisError> {
|
) -> Result<Vec<Boolean>, SynthesisError> {
|
||||||
let v = field_into_allocated_bits_le::<E, CS, F>(cs, value)?;
|
let v = field_into_allocated_bits_le::<E, CS, F>(cs, value)?;
|
||||||
|
|
||||||
Ok(v.into_iter().map(|e| Boolean::from(e)).collect())
|
Ok(v.into_iter().map(Boolean::from).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn field_into_allocated_bits_le<E: Engine, CS: ConstraintSystem<E>, F: PrimeField>(
|
pub fn field_into_allocated_bits_le<E: Engine, CS: ConstraintSystem<E>, F: PrimeField>(
|
||||||
@ -412,24 +412,24 @@ impl Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_value(&self) -> Option<bool> {
|
pub fn get_value(&self) -> Option<bool> {
|
||||||
match self {
|
match *self {
|
||||||
&Boolean::Constant(c) => Some(c),
|
Boolean::Constant(c) => Some(c),
|
||||||
&Boolean::Is(ref v) => v.get_value(),
|
Boolean::Is(ref v) => v.get_value(),
|
||||||
&Boolean::Not(ref v) => v.get_value().map(|b| !b),
|
Boolean::Not(ref v) => v.get_value().map(|b| !b),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lc<E: Engine>(&self, one: Variable, coeff: E::Fr) -> LinearCombination<E> {
|
pub fn lc<E: Engine>(&self, one: Variable, coeff: E::Fr) -> LinearCombination<E> {
|
||||||
match self {
|
match *self {
|
||||||
&Boolean::Constant(c) => {
|
Boolean::Constant(c) => {
|
||||||
if c {
|
if c {
|
||||||
LinearCombination::<E>::zero() + (coeff, one)
|
LinearCombination::<E>::zero() + (coeff, one)
|
||||||
} else {
|
} else {
|
||||||
LinearCombination::<E>::zero()
|
LinearCombination::<E>::zero()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Boolean::Is(ref v) => LinearCombination::<E>::zero() + (coeff, v.get_variable()),
|
Boolean::Is(ref v) => LinearCombination::<E>::zero() + (coeff, v.get_variable()),
|
||||||
&Boolean::Not(ref v) => {
|
Boolean::Not(ref v) => {
|
||||||
LinearCombination::<E>::zero() + (coeff, one) - (coeff, v.get_variable())
|
LinearCombination::<E>::zero() + (coeff, one) - (coeff, v.get_variable())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -442,10 +442,10 @@ impl Boolean {
|
|||||||
|
|
||||||
/// Return a negated interpretation of this boolean.
|
/// Return a negated interpretation of this boolean.
|
||||||
pub fn not(&self) -> Self {
|
pub fn not(&self) -> Self {
|
||||||
match self {
|
match *self {
|
||||||
&Boolean::Constant(c) => Boolean::Constant(!c),
|
Boolean::Constant(c) => Boolean::Constant(!c),
|
||||||
&Boolean::Is(ref v) => Boolean::Not(v.clone()),
|
Boolean::Is(ref v) => Boolean::Not(v.clone()),
|
||||||
&Boolean::Not(ref v) => Boolean::Is(v.clone()),
|
Boolean::Not(ref v) => Boolean::Is(v.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ pub struct MultiEq<E: Engine, CS: ConstraintSystem<E>> {
|
|||||||
impl<E: Engine, CS: ConstraintSystem<E>> MultiEq<E, CS> {
|
impl<E: Engine, CS: ConstraintSystem<E>> MultiEq<E, CS> {
|
||||||
pub fn new(cs: CS) -> Self {
|
pub fn new(cs: CS) -> Self {
|
||||||
MultiEq {
|
MultiEq {
|
||||||
cs: cs,
|
cs,
|
||||||
ops: 0,
|
ops: 0,
|
||||||
bits_used: 0,
|
bits_used: 0,
|
||||||
lhs: LinearCombination::zero(),
|
lhs: LinearCombination::zero(),
|
||||||
|
@ -78,7 +78,7 @@ impl<E: Engine> AllocatedNum<E> {
|
|||||||
E: Engine,
|
E: Engine,
|
||||||
CS: ConstraintSystem<E>,
|
CS: ConstraintSystem<E>,
|
||||||
{
|
{
|
||||||
assert!(v.len() > 0);
|
assert!(!v.is_empty());
|
||||||
|
|
||||||
// Let's keep this simple for now and just AND them all
|
// Let's keep this simple for now and just AND them all
|
||||||
// manually
|
// manually
|
||||||
@ -132,7 +132,7 @@ impl<E: Engine> AllocatedNum<E> {
|
|||||||
current_run.push(a_bit.clone());
|
current_run.push(a_bit.clone());
|
||||||
result.push(a_bit);
|
result.push(a_bit);
|
||||||
} else {
|
} else {
|
||||||
if current_run.len() > 0 {
|
if !current_run.is_empty() {
|
||||||
// This is the start of a run of zeros, but we need
|
// This is the start of a run of zeros, but we need
|
||||||
// to k-ary AND against `last_run` first.
|
// to k-ary AND against `last_run` first.
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ impl<E: Engine> AllocatedNum<E> {
|
|||||||
cs.enforce(|| "unpacking constraint", |lc| lc, |lc| lc, |_| lc);
|
cs.enforce(|| "unpacking constraint", |lc| lc, |lc| lc, |_| lc);
|
||||||
|
|
||||||
// Convert into booleans, and reverse for little-endian bit order
|
// Convert into booleans, and reverse for little-endian bit order
|
||||||
Ok(result.into_iter().map(|b| Boolean::from(b)).rev().collect())
|
Ok(result.into_iter().map(Boolean::from).rev().collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert the allocated number into its little-endian representation.
|
/// Convert the allocated number into its little-endian representation.
|
||||||
@ -208,7 +208,7 @@ impl<E: Engine> AllocatedNum<E> {
|
|||||||
|
|
||||||
cs.enforce(|| "unpacking constraint", |lc| lc, |lc| lc, |_| lc);
|
cs.enforce(|| "unpacking constraint", |lc| lc, |lc| lc, |_| lc);
|
||||||
|
|
||||||
Ok(bits.into_iter().map(|b| Boolean::from(b)).collect())
|
Ok(bits.into_iter().map(Boolean::from).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mul<CS>(&self, mut cs: CS, other: &Self) -> Result<Self, SynthesisError>
|
pub fn mul<CS>(&self, mut cs: CS, other: &Self) -> Result<Self, SynthesisError>
|
||||||
@ -238,7 +238,7 @@ impl<E: Engine> AllocatedNum<E> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
Ok(AllocatedNum {
|
Ok(AllocatedNum {
|
||||||
value: value,
|
value,
|
||||||
variable: var,
|
variable: var,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -270,7 +270,7 @@ impl<E: Engine> AllocatedNum<E> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
Ok(AllocatedNum {
|
Ok(AllocatedNum {
|
||||||
value: value,
|
value,
|
||||||
variable: var,
|
variable: var,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ use super::uint32::UInt32;
|
|||||||
use crate::{ConstraintSystem, SynthesisError};
|
use crate::{ConstraintSystem, SynthesisError};
|
||||||
use pairing::Engine;
|
use pairing::Engine;
|
||||||
|
|
||||||
|
#[allow(clippy::unreadable_literal)]
|
||||||
const ROUND_CONSTANTS: [u32; 64] = [
|
const ROUND_CONSTANTS: [u32; 64] = [
|
||||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||||
@ -15,6 +16,7 @@ const ROUND_CONSTANTS: [u32; 64] = [
|
|||||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
#[allow(clippy::unreadable_literal)]
|
||||||
const IV: [u32; 8] = [
|
const IV: [u32; 8] = [
|
||||||
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
|
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
|
||||||
];
|
];
|
||||||
@ -130,7 +132,7 @@ where
|
|||||||
Ok(match self {
|
Ok(match self {
|
||||||
Maybe::Concrete(ref v) => return Ok(v.clone()),
|
Maybe::Concrete(ref v) => return Ok(v.clone()),
|
||||||
Maybe::Deferred(mut v) => {
|
Maybe::Deferred(mut v) => {
|
||||||
v.extend(others.into_iter().cloned());
|
v.extend(others.iter().cloned());
|
||||||
UInt32::addmany(cs, &v)?
|
UInt32::addmany(cs, &v)?
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -286,7 +288,7 @@ mod test {
|
|||||||
let expected = hex!("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
|
let expected = hex!("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
|
||||||
|
|
||||||
let mut out = out_bits.into_iter();
|
let mut out = out_bits.into_iter();
|
||||||
for b in expected.into_iter() {
|
for b in expected.iter() {
|
||||||
for i in (0..8).rev() {
|
for i in (0..8).rev() {
|
||||||
let c = out.next().unwrap().get_value().unwrap();
|
let c = out.next().unwrap().get_value().unwrap();
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ fn proc_lc<E: Engine>(terms: &[(Variable, E::Fr)]) -> BTreeMap<OrderedVariable,
|
|||||||
let mut map = BTreeMap::new();
|
let mut map = BTreeMap::new();
|
||||||
for &(var, coeff) in terms {
|
for &(var, coeff) in terms {
|
||||||
map.entry(OrderedVariable(var))
|
map.entry(OrderedVariable(var))
|
||||||
.or_insert(E::Fr::zero())
|
.or_insert_with(E::Fr::zero)
|
||||||
.add_assign(&coeff);
|
.add_assign(&coeff);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ impl<E: Engine> TestConstraintSystem<E> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let powers_of_two = (0..E::Fr::NUM_BITS)
|
let powers_of_two = (0..E::Fr::NUM_BITS)
|
||||||
.map(|i| E::Fr::from_str("2").unwrap().pow(&[i as u64]))
|
.map(|i| E::Fr::from_str("2").unwrap().pow(&[u64::from(i)]))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let pp = |s: &mut String, lc: &LinearCombination<E>| {
|
let pp = |s: &mut String, lc: &LinearCombination<E>| {
|
||||||
@ -286,7 +286,7 @@ impl<E: Engine> TestConstraintSystem<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn num_inputs(&self) -> usize {
|
pub fn num_inputs(&self) -> usize {
|
||||||
|
@ -33,7 +33,7 @@ impl UInt32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UInt32 {
|
UInt32 {
|
||||||
bits: bits,
|
bits,
|
||||||
value: Some(value),
|
value: Some(value),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,10 +69,7 @@ impl UInt32 {
|
|||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, SynthesisError>>()?;
|
.collect::<Result<Vec<_>, SynthesisError>>()?;
|
||||||
|
|
||||||
Ok(UInt32 {
|
Ok(UInt32 { bits, value })
|
||||||
bits: bits,
|
|
||||||
value: value,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_bits_be(&self) -> Vec<Boolean> {
|
pub fn into_bits_be(&self) -> Vec<Boolean> {
|
||||||
@ -98,7 +95,7 @@ impl UInt32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UInt32 {
|
UInt32 {
|
||||||
value: value,
|
value,
|
||||||
bits: bits.iter().rev().cloned().collect(),
|
bits: bits.iter().rev().cloned().collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,20 +116,20 @@ impl UInt32 {
|
|||||||
for b in new_bits.iter().rev() {
|
for b in new_bits.iter().rev() {
|
||||||
value.as_mut().map(|v| *v <<= 1);
|
value.as_mut().map(|v| *v <<= 1);
|
||||||
|
|
||||||
match b {
|
match *b {
|
||||||
&Boolean::Constant(b) => {
|
Boolean::Constant(b) => {
|
||||||
if b {
|
if b {
|
||||||
value.as_mut().map(|v| *v |= 1);
|
value.as_mut().map(|v| *v |= 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Boolean::Is(ref b) => match b.get_value() {
|
Boolean::Is(ref b) => match b.get_value() {
|
||||||
Some(true) => {
|
Some(true) => {
|
||||||
value.as_mut().map(|v| *v |= 1);
|
value.as_mut().map(|v| *v |= 1);
|
||||||
}
|
}
|
||||||
Some(false) => {}
|
Some(false) => {}
|
||||||
None => value = None,
|
None => value = None,
|
||||||
},
|
},
|
||||||
&Boolean::Not(ref b) => match b.get_value() {
|
Boolean::Not(ref b) => match b.get_value() {
|
||||||
Some(false) => {
|
Some(false) => {
|
||||||
value.as_mut().map(|v| *v |= 1);
|
value.as_mut().map(|v| *v |= 1);
|
||||||
}
|
}
|
||||||
@ -143,7 +140,7 @@ impl UInt32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UInt32 {
|
UInt32 {
|
||||||
value: value,
|
value,
|
||||||
bits: new_bits,
|
bits: new_bits,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,7 +212,7 @@ impl UInt32 {
|
|||||||
.collect::<Result<_, _>>()?;
|
.collect::<Result<_, _>>()?;
|
||||||
|
|
||||||
Ok(UInt32 {
|
Ok(UInt32 {
|
||||||
bits: bits,
|
bits,
|
||||||
value: new_value,
|
value: new_value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -274,7 +271,7 @@ impl UInt32 {
|
|||||||
.collect::<Result<_, _>>()?;
|
.collect::<Result<_, _>>()?;
|
||||||
|
|
||||||
Ok(UInt32 {
|
Ok(UInt32 {
|
||||||
bits: bits,
|
bits,
|
||||||
value: new_value,
|
value: new_value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -294,7 +291,7 @@ impl UInt32 {
|
|||||||
|
|
||||||
// Compute the maximum value of the sum so we allocate enough bits for
|
// Compute the maximum value of the sum so we allocate enough bits for
|
||||||
// the result
|
// the result
|
||||||
let mut max_value = (operands.len() as u64) * (u32::max_value() as u64);
|
let mut max_value = (operands.len() as u64) * (u64::from(u32::max_value()));
|
||||||
|
|
||||||
// Keep track of the resulting value
|
// Keep track of the resulting value
|
||||||
let mut result_value = Some(0u64);
|
let mut result_value = Some(0u64);
|
||||||
@ -310,7 +307,7 @@ impl UInt32 {
|
|||||||
// Accumulate the value
|
// Accumulate the value
|
||||||
match op.value {
|
match op.value {
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
result_value.as_mut().map(|v| *v += val as u64);
|
result_value.as_mut().map(|v| *v += u64::from(val));
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// If any of our operands have unknown value, we won't
|
// If any of our operands have unknown value, we won't
|
||||||
@ -408,8 +405,8 @@ mod test {
|
|||||||
let b = UInt32::from_bits_be(&v);
|
let b = UInt32::from_bits_be(&v);
|
||||||
|
|
||||||
for (i, bit) in b.bits.iter().enumerate() {
|
for (i, bit) in b.bits.iter().enumerate() {
|
||||||
match bit {
|
match *bit {
|
||||||
&Boolean::Constant(bit) => {
|
Boolean::Constant(bit) => {
|
||||||
assert!(bit == ((b.value.unwrap() >> i) & 1 == 1));
|
assert!(bit == ((b.value.unwrap() >> i) & 1 == 1));
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
@ -443,8 +440,8 @@ mod test {
|
|||||||
let b = UInt32::from_bits(&v);
|
let b = UInt32::from_bits(&v);
|
||||||
|
|
||||||
for (i, bit) in b.bits.iter().enumerate() {
|
for (i, bit) in b.bits.iter().enumerate() {
|
||||||
match bit {
|
match *bit {
|
||||||
&Boolean::Constant(bit) => {
|
Boolean::Constant(bit) => {
|
||||||
assert!(bit == ((b.value.unwrap() >> i) & 1 == 1));
|
assert!(bit == ((b.value.unwrap() >> i) & 1 == 1));
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
@ -491,14 +488,14 @@ mod test {
|
|||||||
assert!(r.value == Some(expected));
|
assert!(r.value == Some(expected));
|
||||||
|
|
||||||
for b in r.bits.iter() {
|
for b in r.bits.iter() {
|
||||||
match b {
|
match *b {
|
||||||
&Boolean::Is(ref b) => {
|
Boolean::Is(ref b) => {
|
||||||
assert!(b.get_value().unwrap() == (expected & 1 == 1));
|
assert!(b.get_value().unwrap() == (expected & 1 == 1));
|
||||||
}
|
}
|
||||||
&Boolean::Not(ref b) => {
|
Boolean::Not(ref b) => {
|
||||||
assert!(!b.get_value().unwrap() == (expected & 1 == 1));
|
assert!(!b.get_value().unwrap() == (expected & 1 == 1));
|
||||||
}
|
}
|
||||||
&Boolean::Constant(b) => {
|
Boolean::Constant(b) => {
|
||||||
assert!(b == (expected & 1 == 1));
|
assert!(b == (expected & 1 == 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -538,10 +535,10 @@ mod test {
|
|||||||
assert!(r.value == Some(expected));
|
assert!(r.value == Some(expected));
|
||||||
|
|
||||||
for b in r.bits.iter() {
|
for b in r.bits.iter() {
|
||||||
match b {
|
match *b {
|
||||||
&Boolean::Is(_) => panic!(),
|
Boolean::Is(_) => panic!(),
|
||||||
&Boolean::Not(_) => panic!(),
|
Boolean::Not(_) => panic!(),
|
||||||
&Boolean::Constant(b) => {
|
Boolean::Constant(b) => {
|
||||||
assert!(b == (expected & 1 == 1));
|
assert!(b == (expected & 1 == 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -576,8 +573,7 @@ mod test {
|
|||||||
let r = a_bit.xor(cs.namespace(|| "xor"), &b_bit).unwrap();
|
let r = a_bit.xor(cs.namespace(|| "xor"), &b_bit).unwrap();
|
||||||
let r = {
|
let r = {
|
||||||
let mut cs = MultiEq::new(&mut cs);
|
let mut cs = MultiEq::new(&mut cs);
|
||||||
let r = UInt32::addmany(cs.namespace(|| "addition"), &[r, c_bit, d_bit]).unwrap();
|
UInt32::addmany(cs.namespace(|| "addition"), &[r, c_bit, d_bit]).unwrap()
|
||||||
r
|
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(cs.is_satisfied());
|
assert!(cs.is_satisfied());
|
||||||
@ -585,14 +581,14 @@ mod test {
|
|||||||
assert!(r.value == Some(expected));
|
assert!(r.value == Some(expected));
|
||||||
|
|
||||||
for b in r.bits.iter() {
|
for b in r.bits.iter() {
|
||||||
match b {
|
match *b {
|
||||||
&Boolean::Is(ref b) => {
|
Boolean::Is(ref b) => {
|
||||||
assert!(b.get_value().unwrap() == (expected & 1 == 1));
|
assert!(b.get_value().unwrap() == (expected & 1 == 1));
|
||||||
}
|
}
|
||||||
&Boolean::Not(ref b) => {
|
Boolean::Not(ref b) => {
|
||||||
assert!(!b.get_value().unwrap() == (expected & 1 == 1));
|
assert!(!b.get_value().unwrap() == (expected & 1 == 1));
|
||||||
}
|
}
|
||||||
&Boolean::Constant(_) => unreachable!(),
|
Boolean::Constant(_) => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
expected >>= 1;
|
expected >>= 1;
|
||||||
@ -628,8 +624,8 @@ mod test {
|
|||||||
|
|
||||||
let mut tmp = num;
|
let mut tmp = num;
|
||||||
for b in &b.bits {
|
for b in &b.bits {
|
||||||
match b {
|
match *b {
|
||||||
&Boolean::Constant(b) => {
|
Boolean::Constant(b) => {
|
||||||
assert_eq!(b, tmp & 1 == 1);
|
assert_eq!(b, tmp & 1 == 1);
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
@ -451,7 +451,7 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(Parameters {
|
Ok(Parameters {
|
||||||
vk: vk,
|
vk,
|
||||||
h: Arc::new(h.into_iter().map(|e| e.into_affine()).collect()),
|
h: Arc::new(h.into_iter().map(|e| e.into_affine()).collect()),
|
||||||
l: Arc::new(l.into_iter().map(|e| e.into_affine()).collect()),
|
l: Arc::new(l.into_iter().map(|e| e.into_affine()).collect()),
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ impl<E: Engine> Proof<E> {
|
|||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(Proof { a: a, b: b, c: c })
|
Ok(Proof { a, b, c })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,13 +208,13 @@ impl<E: Engine> VerifyingKey<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(VerifyingKey {
|
Ok(VerifyingKey {
|
||||||
alpha_g1: alpha_g1,
|
alpha_g1,
|
||||||
beta_g1: beta_g1,
|
beta_g1,
|
||||||
beta_g2: beta_g2,
|
beta_g2,
|
||||||
gamma_g2: gamma_g2,
|
gamma_g2,
|
||||||
delta_g1: delta_g1,
|
delta_g1,
|
||||||
delta_g2: delta_g2,
|
delta_g2,
|
||||||
ic: ic,
|
ic,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -376,7 +376,7 @@ impl<E: Engine> Parameters<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(Parameters {
|
Ok(Parameters {
|
||||||
vk: vk,
|
vk,
|
||||||
h: Arc::new(h),
|
h: Arc::new(h),
|
||||||
l: Arc::new(l),
|
l: Arc::new(l),
|
||||||
a: Arc::new(a),
|
a: Arc::new(a),
|
||||||
|
@ -49,7 +49,7 @@ pub fn verify_proof<'a, E: Engine>(
|
|||||||
(&acc.into_affine().prepare(), &pvk.neg_gamma_g2),
|
(&acc.into_affine().prepare(), &pvk.neg_gamma_g2),
|
||||||
(&proof.c.prepare(), &pvk.neg_delta_g2),
|
(&proof.c.prepare(), &pvk.neg_delta_g2),
|
||||||
]
|
]
|
||||||
.into_iter(),
|
.iter(),
|
||||||
))
|
))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
== pvk.alpha_g1_beta_g2)
|
== pvk.alpha_g1_beta_g2)
|
||||||
|
@ -91,6 +91,7 @@ impl<E: ScalarEngine> Add<(E::Fr, Variable)> for LinearCombination<E> {
|
|||||||
impl<E: ScalarEngine> Sub<(E::Fr, Variable)> for LinearCombination<E> {
|
impl<E: ScalarEngine> Sub<(E::Fr, Variable)> for LinearCombination<E> {
|
||||||
type Output = LinearCombination<E>;
|
type Output = LinearCombination<E>;
|
||||||
|
|
||||||
|
#[allow(clippy::suspicious_arithmetic_impl)]
|
||||||
fn sub(self, (mut coeff, var): (E::Fr, Variable)) -> LinearCombination<E> {
|
fn sub(self, (mut coeff, var): (E::Fr, Variable)) -> LinearCombination<E> {
|
||||||
coeff.negate();
|
coeff.negate();
|
||||||
|
|
||||||
@ -213,7 +214,7 @@ impl Error for SynthesisError {
|
|||||||
|
|
||||||
impl fmt::Display for SynthesisError {
|
impl fmt::Display for SynthesisError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||||
if let &SynthesisError::IoError(ref e) = self {
|
if let SynthesisError::IoError(ref e) = *self {
|
||||||
write!(f, "I/O error: ")?;
|
write!(f, "I/O error: ")?;
|
||||||
e.fmt(f)
|
e.fmt(f)
|
||||||
} else {
|
} else {
|
||||||
@ -278,7 +279,7 @@ pub trait ConstraintSystem<E: ScalarEngine>: Sized {
|
|||||||
fn get_root(&mut self) -> &mut Self::Root;
|
fn get_root(&mut self) -> &mut Self::Root;
|
||||||
|
|
||||||
/// Begin a namespace for this constraint system.
|
/// Begin a namespace for this constraint system.
|
||||||
fn namespace<'a, NR, N>(&'a mut self, name_fn: N) -> Namespace<'a, E, Self::Root>
|
fn namespace<NR, N>(&mut self, name_fn: N) -> Namespace<'_, E, Self::Root>
|
||||||
where
|
where
|
||||||
NR: Into<String>,
|
NR: Into<String>,
|
||||||
N: FnOnce() -> NR,
|
N: FnOnce() -> NR,
|
||||||
|
@ -23,7 +23,7 @@ mod implementation {
|
|||||||
// CPUs configured.
|
// CPUs configured.
|
||||||
pub(crate) fn new_with_cpus(cpus: usize) -> Worker {
|
pub(crate) fn new_with_cpus(cpus: usize) -> Worker {
|
||||||
Worker {
|
Worker {
|
||||||
cpus: cpus,
|
cpus,
|
||||||
pool: CpuPool::new(cpus),
|
pool: CpuPool::new(cpus),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user