bellman: Fix compile errors without multicore feature

This commit is contained in:
Jack Grigg 2019-09-12 19:25:41 +01:00
parent a4e5df9190
commit bc697c14bb
9 changed files with 60 additions and 73 deletions

View File

@ -1,12 +1,6 @@
use pairing::Engine; use super::{boolean::Boolean, multieq::MultiEq, uint32::UInt32};
use crate::{ConstraintSystem, SynthesisError}; use crate::{ConstraintSystem, SynthesisError};
use ff::ScalarEngine;
use super::boolean::Boolean;
use super::uint32::UInt32;
use super::multieq::MultiEq;
/* /*
2.1. Parameters 2.1. Parameters
@ -81,7 +75,7 @@ const SIGMA: [[usize; 16]; 10] = [
END FUNCTION. END FUNCTION.
*/ */
fn mixing_g<E: Engine, CS: ConstraintSystem<E>, M>( fn mixing_g<E: ScalarEngine, CS: ConstraintSystem<E>, M>(
mut cs: M, mut cs: M,
v: &mut [UInt32], v: &mut [UInt32],
a: usize, a: usize,
@ -166,7 +160,7 @@ where
END FUNCTION. END FUNCTION.
*/ */
fn blake2s_compression<E: Engine, CS: ConstraintSystem<E>>( fn blake2s_compression<E: ScalarEngine, CS: ConstraintSystem<E>>(
mut cs: CS, mut cs: CS,
h: &mut [UInt32], h: &mut [UInt32],
m: &[UInt32], m: &[UInt32],
@ -339,7 +333,7 @@ fn blake2s_compression<E: Engine, CS: ConstraintSystem<E>>(
END FUNCTION. END FUNCTION.
*/ */
pub fn blake2s<E: Engine, CS: ConstraintSystem<E>>( pub fn blake2s<E: ScalarEngine, CS: ConstraintSystem<E>>(
mut cs: CS, mut cs: CS,
input: &[Boolean], input: &[Boolean],
personalization: &[u8], personalization: &[u8],

View File

@ -1,5 +1,4 @@
use ff::{BitIterator, Field, PrimeField}; use ff::{BitIterator, Field, PrimeField, ScalarEngine};
use pairing::Engine;
use crate::{ConstraintSystem, LinearCombination, SynthesisError, Variable}; use crate::{ConstraintSystem, LinearCombination, SynthesisError, Variable};
@ -31,7 +30,7 @@ impl AllocatedBit {
must_be_false: &AllocatedBit, must_be_false: &AllocatedBit,
) -> Result<Self, SynthesisError> ) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
let var = cs.alloc( let var = cs.alloc(
@ -68,7 +67,7 @@ impl AllocatedBit {
/// boolean value. /// boolean value.
pub fn alloc<E, CS>(mut cs: CS, value: Option<bool>) -> Result<Self, SynthesisError> pub fn alloc<E, CS>(mut cs: CS, value: Option<bool>) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
let var = cs.alloc( let var = cs.alloc(
@ -101,7 +100,7 @@ impl AllocatedBit {
/// an `AllocatedBit`. /// an `AllocatedBit`.
pub fn xor<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<Self, SynthesisError> pub fn xor<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
let mut result_value = None; let mut result_value = None;
@ -153,7 +152,7 @@ impl AllocatedBit {
/// an `AllocatedBit`. /// an `AllocatedBit`.
pub fn and<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<Self, SynthesisError> pub fn and<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
let mut result_value = None; let mut result_value = None;
@ -191,7 +190,7 @@ impl AllocatedBit {
/// Calculates `a AND (NOT b)`. /// Calculates `a AND (NOT b)`.
pub fn and_not<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<Self, SynthesisError> pub fn and_not<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
let mut result_value = None; let mut result_value = None;
@ -229,7 +228,7 @@ impl AllocatedBit {
/// Calculates `(NOT a) AND (NOT b)`. /// Calculates `(NOT a) AND (NOT b)`.
pub fn nor<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<Self, SynthesisError> pub fn nor<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
let mut result_value = None; let mut result_value = None;
@ -265,7 +264,7 @@ impl AllocatedBit {
} }
} }
pub fn u64_into_boolean_vec_le<E: Engine, CS: ConstraintSystem<E>>( pub fn u64_into_boolean_vec_le<E: ScalarEngine, CS: ConstraintSystem<E>>(
mut cs: CS, mut cs: CS,
value: Option<u64>, value: Option<u64>,
) -> Result<Vec<Boolean>, SynthesisError> { ) -> Result<Vec<Boolean>, SynthesisError> {
@ -296,7 +295,7 @@ pub fn u64_into_boolean_vec_le<E: Engine, CS: ConstraintSystem<E>>(
Ok(bits) Ok(bits)
} }
pub fn field_into_boolean_vec_le<E: Engine, CS: ConstraintSystem<E>, F: PrimeField>( pub fn field_into_boolean_vec_le<E: ScalarEngine, CS: ConstraintSystem<E>, F: PrimeField>(
cs: CS, cs: CS,
value: Option<F>, value: Option<F>,
) -> Result<Vec<Boolean>, SynthesisError> { ) -> Result<Vec<Boolean>, SynthesisError> {
@ -305,7 +304,7 @@ pub fn field_into_boolean_vec_le<E: Engine, CS: ConstraintSystem<E>, F: PrimeFie
Ok(v.into_iter().map(Boolean::from).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: ScalarEngine, CS: ConstraintSystem<E>, F: PrimeField>(
mut cs: CS, mut cs: CS,
value: Option<F>, value: Option<F>,
) -> Result<Vec<AllocatedBit>, SynthesisError> { ) -> Result<Vec<AllocatedBit>, SynthesisError> {
@ -367,7 +366,7 @@ impl Boolean {
pub fn enforce_equal<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<(), SynthesisError> pub fn enforce_equal<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<(), SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
match (a, b) { match (a, b) {
@ -419,7 +418,7 @@ impl Boolean {
} }
} }
pub fn lc<E: Engine>(&self, one: Variable, coeff: E::Fr) -> LinearCombination<E> { pub fn lc<E: ScalarEngine>(&self, one: Variable, coeff: E::Fr) -> LinearCombination<E> {
match *self { match *self {
Boolean::Constant(c) => { Boolean::Constant(c) => {
if c { if c {
@ -452,7 +451,7 @@ impl Boolean {
/// Perform XOR over two boolean operands /// Perform XOR over two boolean operands
pub fn xor<'a, E, CS>(cs: CS, a: &'a Self, b: &'a Self) -> Result<Self, SynthesisError> pub fn xor<'a, E, CS>(cs: CS, a: &'a Self, b: &'a Self) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
match (a, b) { match (a, b) {
@ -474,7 +473,7 @@ impl Boolean {
/// Perform AND over two boolean operands /// Perform AND over two boolean operands
pub fn and<'a, E, CS>(cs: CS, a: &'a Self, b: &'a Self) -> Result<Self, SynthesisError> pub fn and<'a, E, CS>(cs: CS, a: &'a Self, b: &'a Self) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
match (a, b) { match (a, b) {
@ -508,7 +507,7 @@ impl Boolean {
c: &'a Self, c: &'a Self,
) -> Result<Self, SynthesisError> ) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
let ch_value = match (a.get_value(), b.get_value(), c.get_value()) { let ch_value = match (a.get_value(), b.get_value(), c.get_value()) {
@ -615,7 +614,7 @@ impl Boolean {
c: &'a Self, c: &'a Self,
) -> Result<Self, SynthesisError> ) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
let maj_value = match (a.get_value(), b.get_value(), c.get_value()) { let maj_value = match (a.get_value(), b.get_value(), c.get_value()) {

View File

@ -1,5 +1,4 @@
use ff::Field; use ff::{Field, ScalarEngine};
use pairing::Engine;
use super::boolean::Boolean; use super::boolean::Boolean;
use super::num::{AllocatedNum, Num}; use super::num::{AllocatedNum, Num};
@ -7,7 +6,7 @@ use super::*;
use crate::ConstraintSystem; use crate::ConstraintSystem;
// Synthesize the constants for each base pattern. // 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 where
I: IntoIterator<Item = &'a E::Fr>, I: IntoIterator<Item = &'a E::Fr>,
{ {
@ -28,7 +27,7 @@ where
/// Performs a 3-bit window table lookup. `bits` is in /// Performs a 3-bit window table lookup. `bits` is in
/// little-endian order. /// little-endian order.
pub fn lookup3_xy<E: Engine, CS>( pub fn lookup3_xy<E: ScalarEngine, CS>(
mut cs: CS, mut cs: CS,
bits: &[Boolean], bits: &[Boolean],
coords: &[(E::Fr, E::Fr)], coords: &[(E::Fr, E::Fr)],
@ -118,7 +117,7 @@ where
/// Performs a 3-bit window table lookup, where /// Performs a 3-bit window table lookup, where
/// one of the bits is a sign bit. /// one of the bits is a sign bit.
pub fn lookup3_xy_with_conditional_negation<E: Engine, CS>( pub fn lookup3_xy_with_conditional_negation<E: ScalarEngine, CS>(
mut cs: CS, mut cs: CS,
bits: &[Boolean], bits: &[Boolean],
coords: &[(E::Fr, E::Fr)], coords: &[(E::Fr, E::Fr)],

View File

@ -1,9 +1,8 @@
use ff::{Field, PrimeField}; use ff::{Field, PrimeField, ScalarEngine};
use pairing::Engine;
use crate::{ConstraintSystem, LinearCombination, SynthesisError, Variable}; use crate::{ConstraintSystem, LinearCombination, SynthesisError, Variable};
pub struct MultiEq<E: Engine, CS: ConstraintSystem<E>> { pub struct MultiEq<E: ScalarEngine, CS: ConstraintSystem<E>> {
cs: CS, cs: CS,
ops: usize, ops: usize,
bits_used: usize, bits_used: usize,
@ -11,7 +10,7 @@ pub struct MultiEq<E: Engine, CS: ConstraintSystem<E>> {
rhs: LinearCombination<E>, rhs: LinearCombination<E>,
} }
impl<E: Engine, CS: ConstraintSystem<E>> MultiEq<E, CS> { impl<E: ScalarEngine, CS: ConstraintSystem<E>> MultiEq<E, CS> {
pub fn new(cs: CS) -> Self { pub fn new(cs: CS) -> Self {
MultiEq { MultiEq {
cs, cs,
@ -58,7 +57,7 @@ impl<E: Engine, CS: ConstraintSystem<E>> MultiEq<E, CS> {
} }
} }
impl<E: Engine, CS: ConstraintSystem<E>> Drop for MultiEq<E, CS> { impl<E: ScalarEngine, CS: ConstraintSystem<E>> Drop for MultiEq<E, CS> {
fn drop(&mut self) { fn drop(&mut self) {
if self.bits_used > 0 { if self.bits_used > 0 {
self.accumulate(); self.accumulate();
@ -66,7 +65,7 @@ impl<E: Engine, CS: ConstraintSystem<E>> Drop for MultiEq<E, CS> {
} }
} }
impl<E: Engine, CS: ConstraintSystem<E>> ConstraintSystem<E> for MultiEq<E, CS> { impl<E: ScalarEngine, CS: ConstraintSystem<E>> ConstraintSystem<E> for MultiEq<E, CS> {
type Root = Self; type Root = Self;
fn one() -> Variable { fn one() -> Variable {

View File

@ -2,14 +2,13 @@ use super::boolean::Boolean;
use super::num::Num; use super::num::Num;
use super::Assignment; use super::Assignment;
use crate::{ConstraintSystem, SynthesisError}; use crate::{ConstraintSystem, SynthesisError};
use ff::{Field, PrimeField}; use ff::{Field, PrimeField, ScalarEngine};
use pairing::Engine;
/// Takes a sequence of booleans and exposes them as compact /// Takes a sequence of booleans and exposes them as compact
/// public inputs /// public inputs
pub fn pack_into_inputs<E, CS>(mut cs: CS, bits: &[Boolean]) -> Result<(), SynthesisError> pub fn pack_into_inputs<E, CS>(mut cs: CS, bits: &[Boolean]) -> Result<(), SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
for (i, bits) in bits.chunks(E::Fr::CAPACITY as usize).enumerate() { 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<bool> {
.collect() .collect()
} }
pub fn compute_multipacking<E: Engine>(bits: &[bool]) -> Vec<E::Fr> { pub fn compute_multipacking<E: ScalarEngine>(bits: &[bool]) -> Vec<E::Fr> {
let mut result = vec![]; let mut result = vec![];
for bits in bits.chunks(E::Fr::CAPACITY as usize) { for bits in bits.chunks(E::Fr::CAPACITY as usize) {

View File

@ -1,5 +1,4 @@
use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr}; use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr, ScalarEngine};
use pairing::Engine;
use crate::{ConstraintSystem, LinearCombination, SynthesisError, Variable}; use crate::{ConstraintSystem, LinearCombination, SynthesisError, Variable};
@ -7,12 +6,12 @@ use super::Assignment;
use super::boolean::{self, AllocatedBit, Boolean}; use super::boolean::{self, AllocatedBit, Boolean};
pub struct AllocatedNum<E: Engine> { pub struct AllocatedNum<E: ScalarEngine> {
value: Option<E::Fr>, value: Option<E::Fr>,
variable: Variable, variable: Variable,
} }
impl<E: Engine> Clone for AllocatedNum<E> { impl<E: ScalarEngine> Clone for AllocatedNum<E> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
AllocatedNum { AllocatedNum {
value: self.value, value: self.value,
@ -21,7 +20,7 @@ impl<E: Engine> Clone for AllocatedNum<E> {
} }
} }
impl<E: Engine> AllocatedNum<E> { impl<E: ScalarEngine> AllocatedNum<E> {
pub fn alloc<CS, F>(mut cs: CS, value: F) -> Result<Self, SynthesisError> pub fn alloc<CS, F>(mut cs: CS, value: F) -> Result<Self, SynthesisError>
where where
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
@ -75,7 +74,7 @@ impl<E: Engine> AllocatedNum<E> {
v: &[AllocatedBit], v: &[AllocatedBit],
) -> Result<AllocatedBit, SynthesisError> ) -> Result<AllocatedBit, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
assert!(!v.is_empty()); assert!(!v.is_empty());
@ -359,12 +358,12 @@ impl<E: Engine> AllocatedNum<E> {
} }
} }
pub struct Num<E: Engine> { pub struct Num<E: ScalarEngine> {
value: Option<E::Fr>, value: Option<E::Fr>,
lc: LinearCombination<E>, lc: LinearCombination<E>,
} }
impl<E: Engine> From<AllocatedNum<E>> for Num<E> { impl<E: ScalarEngine> From<AllocatedNum<E>> for Num<E> {
fn from(num: AllocatedNum<E>) -> Num<E> { fn from(num: AllocatedNum<E>) -> Num<E> {
Num { Num {
value: num.value, value: num.value,
@ -373,7 +372,7 @@ impl<E: Engine> From<AllocatedNum<E>> for Num<E> {
} }
} }
impl<E: Engine> Num<E> { impl<E: ScalarEngine> Num<E> {
pub fn zero() -> Self { pub fn zero() -> Self {
Num { Num {
value: Some(E::Fr::zero()), value: Some(E::Fr::zero()),

View File

@ -2,7 +2,7 @@ use super::boolean::Boolean;
use super::multieq::MultiEq; use super::multieq::MultiEq;
use super::uint32::UInt32; use super::uint32::UInt32;
use crate::{ConstraintSystem, SynthesisError}; use crate::{ConstraintSystem, SynthesisError};
use pairing::Engine; use ff::ScalarEngine;
#[allow(clippy::unreadable_literal)] #[allow(clippy::unreadable_literal)]
const ROUND_CONSTANTS: [u32; 64] = [ const ROUND_CONSTANTS: [u32; 64] = [
@ -26,7 +26,7 @@ pub fn sha256_block_no_padding<E, CS>(
input: &[Boolean], input: &[Boolean],
) -> Result<Vec<Boolean>, SynthesisError> ) -> Result<Vec<Boolean>, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
assert_eq!(input.len(), 512); assert_eq!(input.len(), 512);
@ -41,7 +41,7 @@ where
pub fn sha256<E, CS>(mut cs: CS, input: &[Boolean]) -> Result<Vec<Boolean>, SynthesisError> pub fn sha256<E, CS>(mut cs: CS, input: &[Boolean]) -> Result<Vec<Boolean>, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
assert!(input.len() % 8 == 0); assert!(input.len() % 8 == 0);
@ -78,7 +78,7 @@ fn sha256_compression_function<E, CS>(
current_hash_value: &[UInt32], current_hash_value: &[UInt32],
) -> Result<Vec<UInt32>, SynthesisError> ) -> Result<Vec<UInt32>, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
assert_eq!(input.len(), 512); assert_eq!(input.len(), 512);
@ -125,7 +125,7 @@ where
impl Maybe { impl Maybe {
fn compute<E, CS, M>(self, cs: M, others: &[UInt32]) -> Result<UInt32, SynthesisError> fn compute<E, CS, M>(self, cs: M, others: &[UInt32]) -> Result<UInt32, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
M: ConstraintSystem<E, Root = MultiEq<E, CS>>, M: ConstraintSystem<E, Root = MultiEq<E, CS>>,
{ {

View File

@ -1,5 +1,4 @@
use ff::{Field, PrimeField, PrimeFieldRepr}; use ff::{Field, PrimeField, PrimeFieldRepr, ScalarEngine};
use pairing::Engine;
use crate::{ConstraintSystem, Index, LinearCombination, SynthesisError, Variable}; use crate::{ConstraintSystem, Index, LinearCombination, SynthesisError, Variable};
@ -20,7 +19,7 @@ enum NamedObject {
} }
/// Constraint system for testing purposes. /// Constraint system for testing purposes.
pub struct TestConstraintSystem<E: Engine> { pub struct TestConstraintSystem<E: ScalarEngine> {
named_objects: HashMap<String, NamedObject>, named_objects: HashMap<String, NamedObject>,
current_namespace: Vec<String>, current_namespace: Vec<String>,
constraints: Vec<( constraints: Vec<(
@ -62,7 +61,7 @@ impl Ord for OrderedVariable {
} }
} }
fn proc_lc<E: Engine>(terms: &[(Variable, E::Fr)]) -> BTreeMap<OrderedVariable, E::Fr> { fn proc_lc<E: ScalarEngine>(terms: &[(Variable, E::Fr)]) -> BTreeMap<OrderedVariable, E::Fr> {
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))
@ -85,7 +84,7 @@ fn proc_lc<E: Engine>(terms: &[(Variable, E::Fr)]) -> BTreeMap<OrderedVariable,
map map
} }
fn hash_lc<E: Engine>(terms: &[(Variable, E::Fr)], h: &mut Blake2sState) { fn hash_lc<E: ScalarEngine>(terms: &[(Variable, E::Fr)], h: &mut Blake2sState) {
let map = proc_lc::<E>(terms); let map = proc_lc::<E>(terms);
let mut buf = [0u8; 9 + 32]; let mut buf = [0u8; 9 + 32];
@ -110,7 +109,7 @@ fn hash_lc<E: Engine>(terms: &[(Variable, E::Fr)], h: &mut Blake2sState) {
} }
} }
fn eval_lc<E: Engine>( fn eval_lc<E: ScalarEngine>(
terms: &[(Variable, E::Fr)], terms: &[(Variable, E::Fr)],
inputs: &[(E::Fr, String)], inputs: &[(E::Fr, String)],
aux: &[(E::Fr, String)], aux: &[(E::Fr, String)],
@ -130,7 +129,7 @@ fn eval_lc<E: Engine>(
acc acc
} }
impl<E: Engine> TestConstraintSystem<E> { impl<E: ScalarEngine> TestConstraintSystem<E> {
pub fn new() -> TestConstraintSystem<E> { pub fn new() -> TestConstraintSystem<E> {
let mut map = HashMap::new(); let mut map = HashMap::new();
map.insert( map.insert(
@ -344,7 +343,7 @@ fn compute_path(ns: &[String], this: String) -> String {
name name
} }
impl<E: Engine> ConstraintSystem<E> for TestConstraintSystem<E> { impl<E: ScalarEngine> ConstraintSystem<E> for TestConstraintSystem<E> {
type Root = Self; type Root = Self;
fn alloc<F, A, AR>(&mut self, annotation: A, f: F) -> Result<Variable, SynthesisError> fn alloc<F, A, AR>(&mut self, annotation: A, f: F) -> Result<Variable, SynthesisError>

View File

@ -1,5 +1,4 @@
use ff::{Field, PrimeField}; use ff::{Field, PrimeField, ScalarEngine};
use pairing::Engine;
use crate::{ConstraintSystem, LinearCombination, SynthesisError}; use crate::{ConstraintSystem, LinearCombination, SynthesisError};
@ -41,7 +40,7 @@ impl UInt32 {
/// Allocate a `UInt32` in the constraint system /// Allocate a `UInt32` in the constraint system
pub fn alloc<E, CS>(mut cs: CS, value: Option<u32>) -> Result<Self, SynthesisError> pub fn alloc<E, CS>(mut cs: CS, value: Option<u32>) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
let values = match value { let values = match value {
@ -194,7 +193,7 @@ impl UInt32 {
circuit_fn: U, circuit_fn: U,
) -> Result<Self, SynthesisError> ) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
F: Fn(u32, u32, u32) -> u32, F: Fn(u32, u32, u32) -> u32,
U: Fn(&mut CS, usize, &Boolean, &Boolean, &Boolean) -> Result<Boolean, SynthesisError>, U: Fn(&mut CS, usize, &Boolean, &Boolean, &Boolean) -> Result<Boolean, SynthesisError>,
@ -223,7 +222,7 @@ impl UInt32 {
/// during SHA256. /// during SHA256.
pub fn sha256_maj<E, CS>(cs: CS, a: &Self, b: &Self, c: &Self) -> Result<Self, SynthesisError> pub fn sha256_maj<E, CS>(cs: CS, a: &Self, b: &Self, c: &Self) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
Self::triop( Self::triop(
@ -240,7 +239,7 @@ impl UInt32 {
/// during SHA256. /// during SHA256.
pub fn sha256_ch<E, CS>(cs: CS, a: &Self, b: &Self, c: &Self) -> Result<Self, SynthesisError> pub fn sha256_ch<E, CS>(cs: CS, a: &Self, b: &Self, c: &Self) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
Self::triop( Self::triop(
@ -256,7 +255,7 @@ impl UInt32 {
/// XOR this `UInt32` with another `UInt32` /// XOR this `UInt32` with another `UInt32`
pub fn xor<E, CS>(&self, mut cs: CS, other: &Self) -> Result<Self, SynthesisError> pub fn xor<E, CS>(&self, mut cs: CS, other: &Self) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
{ {
let new_value = match (self.value, other.value) { let new_value = match (self.value, other.value) {
@ -281,7 +280,7 @@ impl UInt32 {
/// Perform modular addition of several `UInt32` objects. /// Perform modular addition of several `UInt32` objects.
pub fn addmany<E, CS, M>(mut cs: M, operands: &[Self]) -> Result<Self, SynthesisError> pub fn addmany<E, CS, M>(mut cs: M, operands: &[Self]) -> Result<Self, SynthesisError>
where where
E: Engine, E: ScalarEngine,
CS: ConstraintSystem<E>, CS: ConstraintSystem<E>,
M: ConstraintSystem<E, Root = MultiEq<E, CS>>, M: ConstraintSystem<E, Root = MultiEq<E, CS>>,
{ {