From bc697c14bb10dfcae7a04667bb93fa66ff17783d Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 12 Sep 2019 19:25:41 +0100 Subject: [PATCH] bellman: Fix compile errors without multicore feature --- src/gadgets/blake2s.rs | 16 +++++----------- src/gadgets/boolean.rs | 33 ++++++++++++++++----------------- src/gadgets/lookup.rs | 9 ++++----- src/gadgets/multieq.rs | 11 +++++------ src/gadgets/multipack.rs | 7 +++---- src/gadgets/num.rs | 17 ++++++++--------- src/gadgets/sha256.rs | 10 +++++----- src/gadgets/test/mod.rs | 15 +++++++-------- src/gadgets/uint32.rs | 15 +++++++-------- 9 files changed, 60 insertions(+), 73 deletions(-) diff --git a/src/gadgets/blake2s.rs b/src/gadgets/blake2s.rs index 672f13937..96e554bf7 100644 --- a/src/gadgets/blake2s.rs +++ b/src/gadgets/blake2s.rs @@ -1,12 +1,6 @@ -use pairing::Engine; - +use super::{boolean::Boolean, multieq::MultiEq, uint32::UInt32}; use crate::{ConstraintSystem, SynthesisError}; - -use super::boolean::Boolean; - -use super::uint32::UInt32; - -use super::multieq::MultiEq; +use ff::ScalarEngine; /* 2.1. Parameters @@ -81,7 +75,7 @@ const SIGMA: [[usize; 16]; 10] = [ END FUNCTION. */ -fn mixing_g, M>( +fn mixing_g, M>( mut cs: M, v: &mut [UInt32], a: usize, @@ -166,7 +160,7 @@ where END FUNCTION. */ -fn blake2s_compression>( +fn blake2s_compression>( mut cs: CS, h: &mut [UInt32], m: &[UInt32], @@ -339,7 +333,7 @@ fn blake2s_compression>( END FUNCTION. */ -pub fn blake2s>( +pub fn blake2s>( mut cs: CS, input: &[Boolean], personalization: &[u8], diff --git a/src/gadgets/boolean.rs b/src/gadgets/boolean.rs index b26bb1925..bbc0d302a 100644 --- a/src/gadgets/boolean.rs +++ b/src/gadgets/boolean.rs @@ -1,5 +1,4 @@ -use ff::{BitIterator, Field, PrimeField}; -use pairing::Engine; +use ff::{BitIterator, Field, PrimeField, ScalarEngine}; use crate::{ConstraintSystem, LinearCombination, SynthesisError, Variable}; @@ -31,7 +30,7 @@ impl AllocatedBit { must_be_false: &AllocatedBit, ) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { let var = cs.alloc( @@ -68,7 +67,7 @@ impl AllocatedBit { /// boolean value. pub fn alloc(mut cs: CS, value: Option) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { let var = cs.alloc( @@ -101,7 +100,7 @@ impl AllocatedBit { /// an `AllocatedBit`. pub fn xor(mut cs: CS, a: &Self, b: &Self) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { let mut result_value = None; @@ -153,7 +152,7 @@ impl AllocatedBit { /// an `AllocatedBit`. pub fn and(mut cs: CS, a: &Self, b: &Self) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { let mut result_value = None; @@ -191,7 +190,7 @@ impl AllocatedBit { /// Calculates `a AND (NOT b)`. pub fn and_not(mut cs: CS, a: &Self, b: &Self) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { let mut result_value = None; @@ -229,7 +228,7 @@ impl AllocatedBit { /// Calculates `(NOT a) AND (NOT b)`. pub fn nor(mut cs: CS, a: &Self, b: &Self) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { let mut result_value = None; @@ -265,7 +264,7 @@ impl AllocatedBit { } } -pub fn u64_into_boolean_vec_le>( +pub fn u64_into_boolean_vec_le>( mut cs: CS, value: Option, ) -> Result, SynthesisError> { @@ -296,7 +295,7 @@ pub fn u64_into_boolean_vec_le>( Ok(bits) } -pub fn field_into_boolean_vec_le, F: PrimeField>( +pub fn field_into_boolean_vec_le, F: PrimeField>( cs: CS, value: Option, ) -> Result, SynthesisError> { @@ -305,7 +304,7 @@ pub fn field_into_boolean_vec_le, F: PrimeFie Ok(v.into_iter().map(Boolean::from).collect()) } -pub fn field_into_allocated_bits_le, F: PrimeField>( +pub fn field_into_allocated_bits_le, F: PrimeField>( mut cs: CS, value: Option, ) -> Result, SynthesisError> { @@ -367,7 +366,7 @@ impl Boolean { pub fn enforce_equal(mut cs: CS, a: &Self, b: &Self) -> Result<(), SynthesisError> where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { match (a, b) { @@ -419,7 +418,7 @@ impl Boolean { } } - pub fn lc(&self, one: Variable, coeff: E::Fr) -> LinearCombination { + pub fn lc(&self, one: Variable, coeff: E::Fr) -> LinearCombination { match *self { Boolean::Constant(c) => { if c { @@ -452,7 +451,7 @@ impl Boolean { /// Perform XOR over two boolean operands pub fn xor<'a, E, CS>(cs: CS, a: &'a Self, b: &'a Self) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { match (a, b) { @@ -474,7 +473,7 @@ impl Boolean { /// Perform AND over two boolean operands pub fn and<'a, E, CS>(cs: CS, a: &'a Self, b: &'a Self) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { match (a, b) { @@ -508,7 +507,7 @@ impl Boolean { c: &'a Self, ) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { let ch_value = match (a.get_value(), b.get_value(), c.get_value()) { @@ -615,7 +614,7 @@ impl Boolean { c: &'a Self, ) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { let maj_value = match (a.get_value(), b.get_value(), c.get_value()) { diff --git a/src/gadgets/lookup.rs b/src/gadgets/lookup.rs index bbb1da616..8124b22a3 100644 --- a/src/gadgets/lookup.rs +++ b/src/gadgets/lookup.rs @@ -1,5 +1,4 @@ -use ff::Field; -use pairing::Engine; +use ff::{Field, ScalarEngine}; use super::boolean::Boolean; use super::num::{AllocatedNum, Num}; @@ -7,7 +6,7 @@ use super::*; use crate::ConstraintSystem; // Synthesize the constants for each base pattern. -fn synth<'a, E: Engine, I>(window_size: usize, constants: I, assignment: &mut [E::Fr]) +fn synth<'a, E: ScalarEngine, I>(window_size: usize, constants: I, assignment: &mut [E::Fr]) where I: IntoIterator, { @@ -28,7 +27,7 @@ where /// Performs a 3-bit window table lookup. `bits` is in /// little-endian order. -pub fn lookup3_xy( +pub fn lookup3_xy( mut cs: CS, bits: &[Boolean], coords: &[(E::Fr, E::Fr)], @@ -118,7 +117,7 @@ where /// Performs a 3-bit window table lookup, where /// one of the bits is a sign bit. -pub fn lookup3_xy_with_conditional_negation( +pub fn lookup3_xy_with_conditional_negation( mut cs: CS, bits: &[Boolean], coords: &[(E::Fr, E::Fr)], diff --git a/src/gadgets/multieq.rs b/src/gadgets/multieq.rs index 095017a9e..d05282270 100644 --- a/src/gadgets/multieq.rs +++ b/src/gadgets/multieq.rs @@ -1,9 +1,8 @@ -use ff::{Field, PrimeField}; -use pairing::Engine; +use ff::{Field, PrimeField, ScalarEngine}; use crate::{ConstraintSystem, LinearCombination, SynthesisError, Variable}; -pub struct MultiEq> { +pub struct MultiEq> { cs: CS, ops: usize, bits_used: usize, @@ -11,7 +10,7 @@ pub struct MultiEq> { rhs: LinearCombination, } -impl> MultiEq { +impl> MultiEq { pub fn new(cs: CS) -> Self { MultiEq { cs, @@ -58,7 +57,7 @@ impl> MultiEq { } } -impl> Drop for MultiEq { +impl> Drop for MultiEq { fn drop(&mut self) { if self.bits_used > 0 { self.accumulate(); @@ -66,7 +65,7 @@ impl> Drop for MultiEq { } } -impl> ConstraintSystem for MultiEq { +impl> ConstraintSystem for MultiEq { type Root = Self; fn one() -> Variable { diff --git a/src/gadgets/multipack.rs b/src/gadgets/multipack.rs index 34df7cd6d..1fa1967a1 100644 --- a/src/gadgets/multipack.rs +++ b/src/gadgets/multipack.rs @@ -2,14 +2,13 @@ use super::boolean::Boolean; use super::num::Num; use super::Assignment; use crate::{ConstraintSystem, SynthesisError}; -use ff::{Field, PrimeField}; -use pairing::Engine; +use ff::{Field, PrimeField, ScalarEngine}; /// Takes a sequence of booleans and exposes them as compact /// public inputs pub fn pack_into_inputs(mut cs: CS, bits: &[Boolean]) -> Result<(), SynthesisError> where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { for (i, bits) in bits.chunks(E::Fr::CAPACITY as usize).enumerate() { @@ -49,7 +48,7 @@ pub fn bytes_to_bits_le(bytes: &[u8]) -> Vec { .collect() } -pub fn compute_multipacking(bits: &[bool]) -> Vec { +pub fn compute_multipacking(bits: &[bool]) -> Vec { let mut result = vec![]; for bits in bits.chunks(E::Fr::CAPACITY as usize) { diff --git a/src/gadgets/num.rs b/src/gadgets/num.rs index eeccceff5..b7caf6df8 100644 --- a/src/gadgets/num.rs +++ b/src/gadgets/num.rs @@ -1,5 +1,4 @@ -use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr}; -use pairing::Engine; +use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr, ScalarEngine}; use crate::{ConstraintSystem, LinearCombination, SynthesisError, Variable}; @@ -7,12 +6,12 @@ use super::Assignment; use super::boolean::{self, AllocatedBit, Boolean}; -pub struct AllocatedNum { +pub struct AllocatedNum { value: Option, variable: Variable, } -impl Clone for AllocatedNum { +impl Clone for AllocatedNum { fn clone(&self) -> Self { AllocatedNum { value: self.value, @@ -21,7 +20,7 @@ impl Clone for AllocatedNum { } } -impl AllocatedNum { +impl AllocatedNum { pub fn alloc(mut cs: CS, value: F) -> Result where CS: ConstraintSystem, @@ -75,7 +74,7 @@ impl AllocatedNum { v: &[AllocatedBit], ) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { assert!(!v.is_empty()); @@ -359,12 +358,12 @@ impl AllocatedNum { } } -pub struct Num { +pub struct Num { value: Option, lc: LinearCombination, } -impl From> for Num { +impl From> for Num { fn from(num: AllocatedNum) -> Num { Num { value: num.value, @@ -373,7 +372,7 @@ impl From> for Num { } } -impl Num { +impl Num { pub fn zero() -> Self { Num { value: Some(E::Fr::zero()), diff --git a/src/gadgets/sha256.rs b/src/gadgets/sha256.rs index e346a71ed..a875513fb 100644 --- a/src/gadgets/sha256.rs +++ b/src/gadgets/sha256.rs @@ -2,7 +2,7 @@ use super::boolean::Boolean; use super::multieq::MultiEq; use super::uint32::UInt32; use crate::{ConstraintSystem, SynthesisError}; -use pairing::Engine; +use ff::ScalarEngine; #[allow(clippy::unreadable_literal)] const ROUND_CONSTANTS: [u32; 64] = [ @@ -26,7 +26,7 @@ pub fn sha256_block_no_padding( input: &[Boolean], ) -> Result, SynthesisError> where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { assert_eq!(input.len(), 512); @@ -41,7 +41,7 @@ where pub fn sha256(mut cs: CS, input: &[Boolean]) -> Result, SynthesisError> where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { assert!(input.len() % 8 == 0); @@ -78,7 +78,7 @@ fn sha256_compression_function( current_hash_value: &[UInt32], ) -> Result, SynthesisError> where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { assert_eq!(input.len(), 512); @@ -125,7 +125,7 @@ where impl Maybe { fn compute(self, cs: M, others: &[UInt32]) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, M: ConstraintSystem>, { diff --git a/src/gadgets/test/mod.rs b/src/gadgets/test/mod.rs index eed676e62..fedfe9492 100644 --- a/src/gadgets/test/mod.rs +++ b/src/gadgets/test/mod.rs @@ -1,5 +1,4 @@ -use ff::{Field, PrimeField, PrimeFieldRepr}; -use pairing::Engine; +use ff::{Field, PrimeField, PrimeFieldRepr, ScalarEngine}; use crate::{ConstraintSystem, Index, LinearCombination, SynthesisError, Variable}; @@ -20,7 +19,7 @@ enum NamedObject { } /// Constraint system for testing purposes. -pub struct TestConstraintSystem { +pub struct TestConstraintSystem { named_objects: HashMap, current_namespace: Vec, constraints: Vec<( @@ -62,7 +61,7 @@ impl Ord for OrderedVariable { } } -fn proc_lc(terms: &[(Variable, E::Fr)]) -> BTreeMap { +fn proc_lc(terms: &[(Variable, E::Fr)]) -> BTreeMap { let mut map = BTreeMap::new(); for &(var, coeff) in terms { map.entry(OrderedVariable(var)) @@ -85,7 +84,7 @@ fn proc_lc(terms: &[(Variable, E::Fr)]) -> BTreeMap(terms: &[(Variable, E::Fr)], h: &mut Blake2sState) { +fn hash_lc(terms: &[(Variable, E::Fr)], h: &mut Blake2sState) { let map = proc_lc::(terms); let mut buf = [0u8; 9 + 32]; @@ -110,7 +109,7 @@ fn hash_lc(terms: &[(Variable, E::Fr)], h: &mut Blake2sState) { } } -fn eval_lc( +fn eval_lc( terms: &[(Variable, E::Fr)], inputs: &[(E::Fr, String)], aux: &[(E::Fr, String)], @@ -130,7 +129,7 @@ fn eval_lc( acc } -impl TestConstraintSystem { +impl TestConstraintSystem { pub fn new() -> TestConstraintSystem { let mut map = HashMap::new(); map.insert( @@ -344,7 +343,7 @@ fn compute_path(ns: &[String], this: String) -> String { name } -impl ConstraintSystem for TestConstraintSystem { +impl ConstraintSystem for TestConstraintSystem { type Root = Self; fn alloc(&mut self, annotation: A, f: F) -> Result diff --git a/src/gadgets/uint32.rs b/src/gadgets/uint32.rs index 5a93e75a6..cf8e3906a 100644 --- a/src/gadgets/uint32.rs +++ b/src/gadgets/uint32.rs @@ -1,5 +1,4 @@ -use ff::{Field, PrimeField}; -use pairing::Engine; +use ff::{Field, PrimeField, ScalarEngine}; use crate::{ConstraintSystem, LinearCombination, SynthesisError}; @@ -41,7 +40,7 @@ impl UInt32 { /// Allocate a `UInt32` in the constraint system pub fn alloc(mut cs: CS, value: Option) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { let values = match value { @@ -194,7 +193,7 @@ impl UInt32 { circuit_fn: U, ) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, F: Fn(u32, u32, u32) -> u32, U: Fn(&mut CS, usize, &Boolean, &Boolean, &Boolean) -> Result, @@ -223,7 +222,7 @@ impl UInt32 { /// during SHA256. pub fn sha256_maj(cs: CS, a: &Self, b: &Self, c: &Self) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { Self::triop( @@ -240,7 +239,7 @@ impl UInt32 { /// during SHA256. pub fn sha256_ch(cs: CS, a: &Self, b: &Self, c: &Self) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { Self::triop( @@ -256,7 +255,7 @@ impl UInt32 { /// XOR this `UInt32` with another `UInt32` pub fn xor(&self, mut cs: CS, other: &Self) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, { let new_value = match (self.value, other.value) { @@ -281,7 +280,7 @@ impl UInt32 { /// Perform modular addition of several `UInt32` objects. pub fn addmany(mut cs: M, operands: &[Self]) -> Result where - E: Engine, + E: ScalarEngine, CS: ConstraintSystem, M: ConstraintSystem>, {