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 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<E: Engine, CS: ConstraintSystem<E>, M>(
fn mixing_g<E: ScalarEngine, CS: ConstraintSystem<E>, M>(
mut cs: M,
v: &mut [UInt32],
a: usize,
@ -166,7 +160,7 @@ where
END FUNCTION.
*/
fn blake2s_compression<E: Engine, CS: ConstraintSystem<E>>(
fn blake2s_compression<E: ScalarEngine, CS: ConstraintSystem<E>>(
mut cs: CS,
h: &mut [UInt32],
m: &[UInt32],
@ -339,7 +333,7 @@ fn blake2s_compression<E: Engine, CS: ConstraintSystem<E>>(
END FUNCTION.
*/
pub fn blake2s<E: Engine, CS: ConstraintSystem<E>>(
pub fn blake2s<E: ScalarEngine, CS: ConstraintSystem<E>>(
mut cs: CS,
input: &[Boolean],
personalization: &[u8],

View File

@ -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<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
let var = cs.alloc(
@ -68,7 +67,7 @@ impl AllocatedBit {
/// boolean value.
pub fn alloc<E, CS>(mut cs: CS, value: Option<bool>) -> Result<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
let var = cs.alloc(
@ -101,7 +100,7 @@ impl AllocatedBit {
/// an `AllocatedBit`.
pub fn xor<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
let mut result_value = None;
@ -153,7 +152,7 @@ impl AllocatedBit {
/// an `AllocatedBit`.
pub fn and<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
let mut result_value = None;
@ -191,7 +190,7 @@ impl AllocatedBit {
/// Calculates `a AND (NOT b)`.
pub fn and_not<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
let mut result_value = None;
@ -229,7 +228,7 @@ impl AllocatedBit {
/// Calculates `(NOT a) AND (NOT b)`.
pub fn nor<E, CS>(mut cs: CS, a: &Self, b: &Self) -> Result<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
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,
value: Option<u64>,
) -> Result<Vec<Boolean>, SynthesisError> {
@ -296,7 +295,7 @@ pub fn u64_into_boolean_vec_le<E: Engine, CS: ConstraintSystem<E>>(
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,
value: Option<F>,
) -> 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())
}
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,
value: Option<F>,
) -> 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>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
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 {
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<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
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<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
match (a, b) {
@ -508,7 +507,7 @@ impl Boolean {
c: &'a Self,
) -> Result<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
let ch_value = match (a.get_value(), b.get_value(), c.get_value()) {
@ -615,7 +614,7 @@ impl Boolean {
c: &'a Self,
) -> Result<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
let maj_value = match (a.get_value(), b.get_value(), c.get_value()) {

View File

@ -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<Item = &'a E::Fr>,
{
@ -28,7 +27,7 @@ where
/// Performs a 3-bit window table lookup. `bits` is in
/// little-endian order.
pub fn lookup3_xy<E: Engine, CS>(
pub fn lookup3_xy<E: ScalarEngine, CS>(
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<E: Engine, CS>(
pub fn lookup3_xy_with_conditional_negation<E: ScalarEngine, CS>(
mut cs: CS,
bits: &[Boolean],
coords: &[(E::Fr, E::Fr)],

View File

@ -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<E: Engine, CS: ConstraintSystem<E>> {
pub struct MultiEq<E: ScalarEngine, CS: ConstraintSystem<E>> {
cs: CS,
ops: usize,
bits_used: usize,
@ -11,7 +10,7 @@ pub struct MultiEq<E: Engine, CS: ConstraintSystem<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 {
MultiEq {
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) {
if self.bits_used > 0 {
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;
fn one() -> Variable {

View File

@ -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<E, CS>(mut cs: CS, bits: &[Boolean]) -> Result<(), SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
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()
}
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![];
for bits in bits.chunks(E::Fr::CAPACITY as usize) {

View File

@ -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<E: Engine> {
pub struct AllocatedNum<E: ScalarEngine> {
value: Option<E::Fr>,
variable: Variable,
}
impl<E: Engine> Clone for AllocatedNum<E> {
impl<E: ScalarEngine> Clone for AllocatedNum<E> {
fn clone(&self) -> Self {
AllocatedNum {
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>
where
CS: ConstraintSystem<E>,
@ -75,7 +74,7 @@ impl<E: Engine> AllocatedNum<E> {
v: &[AllocatedBit],
) -> Result<AllocatedBit, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
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>,
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> {
Num {
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 {
Num {
value: Some(E::Fr::zero()),

View File

@ -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<E, CS>(
input: &[Boolean],
) -> Result<Vec<Boolean>, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
assert_eq!(input.len(), 512);
@ -41,7 +41,7 @@ where
pub fn sha256<E, CS>(mut cs: CS, input: &[Boolean]) -> Result<Vec<Boolean>, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
assert!(input.len() % 8 == 0);
@ -78,7 +78,7 @@ fn sha256_compression_function<E, CS>(
current_hash_value: &[UInt32],
) -> Result<Vec<UInt32>, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
assert_eq!(input.len(), 512);
@ -125,7 +125,7 @@ where
impl Maybe {
fn compute<E, CS, M>(self, cs: M, others: &[UInt32]) -> Result<UInt32, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
M: ConstraintSystem<E, Root = MultiEq<E, CS>>,
{

View File

@ -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<E: Engine> {
pub struct TestConstraintSystem<E: ScalarEngine> {
named_objects: HashMap<String, NamedObject>,
current_namespace: Vec<String>,
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();
for &(var, coeff) in terms {
map.entry(OrderedVariable(var))
@ -85,7 +84,7 @@ fn proc_lc<E: Engine>(terms: &[(Variable, E::Fr)]) -> BTreeMap<OrderedVariable,
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 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)],
inputs: &[(E::Fr, String)],
aux: &[(E::Fr, String)],
@ -130,7 +129,7 @@ fn eval_lc<E: Engine>(
acc
}
impl<E: Engine> TestConstraintSystem<E> {
impl<E: ScalarEngine> TestConstraintSystem<E> {
pub fn new() -> TestConstraintSystem<E> {
let mut map = HashMap::new();
map.insert(
@ -344,7 +343,7 @@ fn compute_path(ns: &[String], this: String) -> String {
name
}
impl<E: Engine> ConstraintSystem<E> for TestConstraintSystem<E> {
impl<E: ScalarEngine> ConstraintSystem<E> for TestConstraintSystem<E> {
type Root = Self;
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 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<E, CS>(mut cs: CS, value: Option<u32>) -> Result<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
let values = match value {
@ -194,7 +193,7 @@ impl UInt32 {
circuit_fn: U,
) -> Result<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
F: Fn(u32, u32, u32) -> u32,
U: Fn(&mut CS, usize, &Boolean, &Boolean, &Boolean) -> Result<Boolean, SynthesisError>,
@ -223,7 +222,7 @@ impl UInt32 {
/// during SHA256.
pub fn sha256_maj<E, CS>(cs: CS, a: &Self, b: &Self, c: &Self) -> Result<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
Self::triop(
@ -240,7 +239,7 @@ impl UInt32 {
/// during SHA256.
pub fn sha256_ch<E, CS>(cs: CS, a: &Self, b: &Self, c: &Self) -> Result<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
Self::triop(
@ -256,7 +255,7 @@ impl UInt32 {
/// XOR this `UInt32` with another `UInt32`
pub fn xor<E, CS>(&self, mut cs: CS, other: &Self) -> Result<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
{
let new_value = match (self.value, other.value) {
@ -281,7 +280,7 @@ impl UInt32 {
/// Perform modular addition of several `UInt32` objects.
pub fn addmany<E, CS, M>(mut cs: M, operands: &[Self]) -> Result<Self, SynthesisError>
where
E: Engine,
E: ScalarEngine,
CS: ConstraintSystem<E>,
M: ConstraintSystem<E, Root = MultiEq<E, CS>>,
{