1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00

Merge branch 'develop' of github.com:Zokrates/ZoKrates into simplify-resolver

This commit is contained in:
schaeff 2019-09-13 14:05:01 +02:00
commit 691b3c1d90
30 changed files with 598 additions and 595 deletions

1
.gitignore vendored
View file

@ -8,7 +8,6 @@ out.code
out.wit
proof.json
proving.key
variables.inf
verification.key
verifier.sol
proof.json

View file

@ -17,7 +17,7 @@ matrix:
# Linux
- env: TARGET=aarch64-unknown-linux-gnu
- env: TARGET=arm-unknown-linux-gnueabi
- env: TARGET=i686-unknown-linux-gnu
#- env: TARGET=i686-unknown-linux-gnu
- env: TARGET=x86_64-unknown-linux-gnu
# OSX

874
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -71,11 +71,19 @@ import "utils/pack/unpack128"
Unpacks a field element to 128 field elements.
#### unpack256
#### pack256
```zokrates
import "utils/pack/unpack256"
import "utils/pack/pack256"
```
Unpacks a field element to 256 field elements.
Packs 256 field elements as one. Overflows can occur.
#### nonStrictUnpack256
```zokrates
import "utils/pack/nonStrictUnpack256"
```
Unpacks a field element to 256 field elements. Uniqueness of the output is not guaranteed.

View file

@ -58,4 +58,4 @@ Then run the different phases of the protocol:
./zokrates export-verifier
```
The CLI commands are explained in more detail in the [CLI reference](reference/cli.html).
The CLI commands are explained in more detail in the [CLI reference](reference/cli.md).

View file

@ -1,6 +1,6 @@
[package]
name = "zokrates_cli"
version = "0.4.9"
version = "0.4.11"
authors = ["Jacob Eberhardt <jacob.eberhardt@tu-berlin.de>", "Dennis Kuhnert <mail@kyroy.com>", "Thibaut Schaeffer <thibaut@schaeff.fr>"]
repository = "https://github.com/JacobEberhardt/ZoKrates.git"
edition = "2018"

View file

@ -86,8 +86,7 @@ fn cli() -> Result<(), String> {
.takes_value(true)
.required(false)
.default_value(FLATTENED_CODE_DEFAULT_PATH)
)
.arg(Arg::with_name("proving-key-path")
).arg(Arg::with_name("proving-key-path")
.short("p")
.long("proving-key-path")
.help("Path of the generated proving key file")
@ -95,8 +94,7 @@ fn cli() -> Result<(), String> {
.takes_value(true)
.required(false)
.default_value(PROVING_KEY_DEFAULT_PATH)
)
.arg(Arg::with_name("verification-key-path")
).arg(Arg::with_name("verification-key-path")
.short("v")
.long("verification-key-path")
.help("Path of the generated verification key file")
@ -104,8 +102,7 @@ fn cli() -> Result<(), String> {
.takes_value(true)
.required(false)
.default_value(VERIFICATION_KEY_DEFAULT_PATH)
)
.arg(Arg::with_name("proving-scheme")
).arg(Arg::with_name("proving-scheme")
.short("s")
.long("proving-scheme")
.help("Proving scheme to use in the setup. Available options are G16 (default), PGHR13 and GM17")
@ -129,8 +126,7 @@ fn cli() -> Result<(), String> {
.takes_value(true)
.required(false)
.default_value(VERIFICATION_KEY_DEFAULT_PATH)
)
.arg(Arg::with_name("output")
).arg(Arg::with_name("output")
.short("o")
.long("output")
.help("Path of the output file")

View file

@ -63,7 +63,7 @@ let jsonInterface = JSON.parse(solc.compile(jsonContractSource));
})
function makeTransaction(account, correct) {
let proof = getProof();
let proof = getProof(correct);
function handleReceipt(tx) {
if (tx.status == true && !correct) {

View file

@ -1,6 +1,6 @@
[package]
name = "zokrates_core"
version = "0.3.12"
version = "0.3.14"
authors = ["Jacob Eberhardt <jacob.eberhardt@tu-berlin.de>", "Dennis Kuhnert <mail@kyroy.com>"]
repository = "https://github.com/JacobEberhardt/ZoKrates"
readme = "README.md"
@ -15,7 +15,7 @@ wasm = ["wasmi", "parity-wasm", "rustc-hex"]
libc = "0.2.0"
num = {version = "0.1.36", default-features = false}
num-bigint = {version = "0.1.36", default-features = false}
lazy_static = "0.1.*"
lazy_static = "1.4"
typed-arena = "1.4.1"
reduce = "0.1.1"
# serialization and deserialization
@ -25,9 +25,9 @@ serde_json = "1.0"
serde_bytes = "0.10"
bincode = "0.8.0"
regex = "0.2"
bellman = { git = "https://github.com/matterinc/bellman", tag = "0.2.0" }
pairing = { git = "https://github.com/matterinc/pairing", tag = "0.16.2" }
ff = { git = 'https://github.com/matterinc/ff', features = ["derive"], tag = "0.5" }
bellman_ce = "0.3"
pairing_ce = "0.18"
ff_ce = "0.7"
zokrates_field = { version = "0.3.0", path = "../zokrates_field" }
zokrates_pest_ast = { version = "0.1.0", path = "../zokrates_pest_ast" }
zokrates_embed = { path = "../zokrates_embed" }

View file

@ -69,7 +69,7 @@ impl<'ast, T: Field> From<pest::Function<'ast>> for absy::FunctionDeclarationNod
.collect(),
signature,
}
.span(span.clone()); // TODO check
.span(span.clone());
absy::FunctionDeclaration {
id,
@ -554,8 +554,7 @@ mod tests {
#[test]
fn return_forty_two() {
let source = "def main() -> (field): return 42
";
let source = "def main() -> (field): return 42";
let ast = pest::generate_ast(&source).unwrap();
let expected: absy::Module<FieldPrime> = absy::Module {
functions: vec![absy::FunctionDeclaration {
@ -588,8 +587,7 @@ mod tests {
#[test]
fn return_true() {
let source = "def main() -> (bool): return true
";
let source = "def main() -> (bool): return true";
let ast = pest::generate_ast(&source).unwrap();
let expected: absy::Module<FieldPrime> = absy::Module {
functions: vec![absy::FunctionDeclaration {
@ -619,8 +617,7 @@ mod tests {
#[test]
fn arguments() {
let source = "def main(private field a, bool b) -> (field): return 42
";
let source = "def main(private field a, bool b) -> (field): return 42";
let ast = pest::generate_ast(&source).unwrap();
let expected: absy::Module<FieldPrime> = absy::Module {

View file

@ -22,7 +22,7 @@ use zokrates_field::field::Field;
use std::collections::HashMap;
/// An identifier in a function or a variable
/// An identifier of a function or a variable
pub type Identifier<'ast> = &'ast str;
/// The identifier of a `Module`, typically a path or uri
@ -239,17 +239,17 @@ impl<'ast, T: Field> fmt::Display for Statement<'ast, T> {
Statement::Definition(ref lhs, ref rhs) => write!(f, "{} = {}", lhs, rhs),
Statement::Condition(ref lhs, ref rhs) => write!(f, "{} == {}", lhs, rhs),
Statement::For(ref var, ref start, ref stop, ref list) => {
r#try!(write!(f, "for {} in {}..{} do\n", var, start, stop));
write!(f, "for {} in {}..{} do\n", var, start, stop)?;
for l in list {
r#try!(write!(f, "\t\t{}\n", l));
write!(f, "\t\t{}\n", l)?;
}
write!(f, "\tendfor")
}
Statement::MultipleDefinition(ref ids, ref rhs) => {
for (i, id) in ids.iter().enumerate() {
r#try!(write!(f, "{}", id));
write!(f, "{}", id)?;
if i < ids.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
write!(f, " = {}", rhs)
@ -268,9 +268,9 @@ impl<'ast, T: Field> fmt::Debug for Statement<'ast, T> {
}
Statement::Condition(ref lhs, ref rhs) => write!(f, "Condition({:?}, {:?})", lhs, rhs),
Statement::For(ref var, ref start, ref stop, ref list) => {
r#try!(write!(f, "for {:?} in {:?}..{:?} do\n", var, start, stop));
write!(f, "for {:?} in {:?}..{:?} do\n", var, start, stop)?;
for l in list {
r#try!(write!(f, "\t\t{:?}\n", l));
write!(f, "\t\t{:?}\n", l)?;
}
write!(f, "\tendfor")
}
@ -434,11 +434,11 @@ impl<'ast, T: Field> fmt::Display for Expression<'ast, T> {
condition, consequent, alternative
),
Expression::FunctionCall(ref i, ref p) => {
r#try!(write!(f, "{}(", i,));
write!(f, "{}(", i,)?;
for (i, param) in p.iter().enumerate() {
r#try!(write!(f, "{}", param));
write!(f, "{}", param)?;
if i < p.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
write!(f, ")")
@ -451,11 +451,11 @@ impl<'ast, T: Field> fmt::Display for Expression<'ast, T> {
Expression::And(ref lhs, ref rhs) => write!(f, "{} && {}", lhs, rhs),
Expression::Not(ref exp) => write!(f, "!{}", exp),
Expression::InlineArray(ref exprs) => {
r#try!(write!(f, "["));
write!(f, "[")?;
for (i, e) in exprs.iter().enumerate() {
r#try!(write!(f, "{}", e));
write!(f, "{}", e)?;
if i < exprs.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
write!(f, "]")
@ -483,8 +483,8 @@ impl<'ast, T: Field> fmt::Debug for Expression<'ast, T> {
condition, consequent, alternative
),
Expression::FunctionCall(ref i, ref p) => {
r#try!(write!(f, "FunctionCall({:?}, (", i));
r#try!(f.debug_list().entries(p.iter()).finish());
write!(f, "FunctionCall({:?}, (", i)?;
f.debug_list().entries(p.iter()).finish()?;
write!(f, ")")
}
Expression::Lt(ref lhs, ref rhs) => write!(f, "{} < {}", lhs, rhs),
@ -495,8 +495,8 @@ impl<'ast, T: Field> fmt::Debug for Expression<'ast, T> {
Expression::And(ref lhs, ref rhs) => write!(f, "{} && {}", lhs, rhs),
Expression::Not(ref exp) => write!(f, "!{}", exp),
Expression::InlineArray(ref exprs) => {
r#try!(write!(f, "InlineArray(["));
r#try!(f.debug_list().entries(exprs.iter()).finish());
write!(f, "InlineArray([")?;
f.debug_list().entries(exprs.iter()).finish()?;
write!(f, "]")
}
Expression::Select(ref array, ref index) => write!(f, "{}[{}]", array, index),
@ -524,9 +524,9 @@ impl<'ast, T: Field> ExpressionList<'ast, T> {
impl<'ast, T: Field> fmt::Display for ExpressionList<'ast, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for (i, param) in self.expressions.iter().enumerate() {
r#try!(write!(f, "{}", param));
write!(f, "{}", param)?;
if i < self.expressions.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
write!(f, "")

View file

@ -247,9 +247,9 @@ pub struct FlatExpressionList<T: Field> {
impl<T: Field> fmt::Display for FlatExpressionList<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for (i, param) in self.expressions.iter().enumerate() {
r#try!(write!(f, "{}", param));
write!(f, "{}", param)?;
if i < self.expressions.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
write!(f, "")

View file

@ -29,7 +29,7 @@ impl<'ast, T: Field> Flattener<'ast, T> {
Flattener::new().flatten_program(p)
}
/// Returns a `Flattener` with fresh a fresh [substitution] and [variables].
/// Returns a `Flattener` with fresh [substitution] and [variables].
///
/// # Arguments
///
@ -82,17 +82,17 @@ impl<'ast, T: Field> Flattener<'ast, T> {
let lhs_id = self.use_sym();
statements_flattened.push(FlatStatement::Definition(lhs_id, lhs_flattened));
// check that lhs and rhs are within the right range, ie, their last two bits are zero
// check that lhs and rhs are within the right range, ie, their higher two bits are zero. We use big-endian so they are at positions 0 and 1
// lhs
{
// define variables for the bits
let lhs_bits: Vec<FlatVariable> =
let lhs_bits_be: Vec<FlatVariable> =
(0..bitwidth).map(|_| self.use_sym()).collect();
// add a directive to get the bits
statements_flattened.push(FlatStatement::Directive(DirectiveStatement::new(
lhs_bits.clone(),
lhs_bits_be.clone(),
Helper::bits(),
vec![lhs_id],
)));
@ -100,10 +100,10 @@ impl<'ast, T: Field> Flattener<'ast, T> {
// bitness checks
for i in 0..bitwidth - 2 {
statements_flattened.push(FlatStatement::Condition(
FlatExpression::Identifier(lhs_bits[i + 2]),
FlatExpression::Identifier(lhs_bits_be[i + 2]),
FlatExpression::Mult(
box FlatExpression::Identifier(lhs_bits[i + 2]),
box FlatExpression::Identifier(lhs_bits[i + 2]),
box FlatExpression::Identifier(lhs_bits_be[i + 2]),
box FlatExpression::Identifier(lhs_bits_be[i + 2]),
),
));
}
@ -115,7 +115,7 @@ impl<'ast, T: Field> Flattener<'ast, T> {
lhs_sum = FlatExpression::Add(
box lhs_sum,
box FlatExpression::Mult(
box FlatExpression::Identifier(lhs_bits[i + 2]),
box FlatExpression::Identifier(lhs_bits_be[i + 2]),
box FlatExpression::Number(T::from(2).pow(bitwidth - 2 - i - 1)),
),
);
@ -134,12 +134,12 @@ impl<'ast, T: Field> Flattener<'ast, T> {
// rhs
{
// define variables for the bits
let rhs_bits: Vec<FlatVariable> =
let rhs_bits_be: Vec<FlatVariable> =
(0..bitwidth).map(|_| self.use_sym()).collect();
// add a directive to get the bits
statements_flattened.push(FlatStatement::Directive(DirectiveStatement::new(
rhs_bits.clone(),
rhs_bits_be.clone(),
Helper::bits(),
vec![rhs_id],
)));
@ -147,10 +147,10 @@ impl<'ast, T: Field> Flattener<'ast, T> {
// bitness checks
for i in 0..bitwidth - 2 {
statements_flattened.push(FlatStatement::Condition(
FlatExpression::Identifier(rhs_bits[i + 2]),
FlatExpression::Identifier(rhs_bits_be[i + 2]),
FlatExpression::Mult(
box FlatExpression::Identifier(rhs_bits[i + 2]),
box FlatExpression::Identifier(rhs_bits[i + 2]),
box FlatExpression::Identifier(rhs_bits_be[i + 2]),
box FlatExpression::Identifier(rhs_bits_be[i + 2]),
),
));
}
@ -162,7 +162,7 @@ impl<'ast, T: Field> Flattener<'ast, T> {
rhs_sum = FlatExpression::Add(
box rhs_sum,
box FlatExpression::Mult(
box FlatExpression::Identifier(rhs_bits[i + 2]),
box FlatExpression::Identifier(rhs_bits_be[i + 2]),
box FlatExpression::Number(T::from(2).pow(bitwidth - 2 - i - 1)),
),
);
@ -187,11 +187,12 @@ impl<'ast, T: Field> Flattener<'ast, T> {
);
// define variables for the bits
let sub_bits: Vec<FlatVariable> = (0..bitwidth).map(|_| self.use_sym()).collect();
let sub_bits_be: Vec<FlatVariable> =
(0..bitwidth).map(|_| self.use_sym()).collect();
// add a directive to get the bits
statements_flattened.push(FlatStatement::Directive(DirectiveStatement::new(
sub_bits.clone(),
sub_bits_be.clone(),
Helper::bits(),
vec![subtraction_result.clone()],
)));
@ -199,10 +200,10 @@ impl<'ast, T: Field> Flattener<'ast, T> {
// bitness checks
for i in 0..bitwidth {
statements_flattened.push(FlatStatement::Condition(
FlatExpression::Identifier(sub_bits[i]),
FlatExpression::Identifier(sub_bits_be[i]),
FlatExpression::Mult(
box FlatExpression::Identifier(sub_bits[i]),
box FlatExpression::Identifier(sub_bits[i]),
box FlatExpression::Identifier(sub_bits_be[i]),
box FlatExpression::Identifier(sub_bits_be[i]),
),
));
}
@ -214,7 +215,7 @@ impl<'ast, T: Field> Flattener<'ast, T> {
expr = FlatExpression::Add(
box expr,
box FlatExpression::Mult(
box FlatExpression::Identifier(sub_bits[i]),
box FlatExpression::Identifier(sub_bits_be[i]),
box FlatExpression::Number(T::from(2).pow(bitwidth - i - 1)),
),
);
@ -222,7 +223,7 @@ impl<'ast, T: Field> Flattener<'ast, T> {
statements_flattened.push(FlatStatement::Condition(subtraction_result, expr));
FlatExpression::Identifier(sub_bits[0])
FlatExpression::Identifier(sub_bits_be[bitwidth - 1])
}
BooleanExpression::Eq(box lhs, box rhs) => {
// We know from semantic checking that lhs and rhs have the same type

View file

@ -8,11 +8,11 @@ extern crate serde_json;
extern crate typed_arena;
#[macro_use]
extern crate serde_derive;
extern crate bellman;
extern crate bellman_ce as bellman;
extern crate bincode;
extern crate ff;
extern crate ff_ce as ff;
extern crate lazy_static;
extern crate pairing;
extern crate pairing_ce as pairing;
#[cfg(feature = "wasm")]
extern crate parity_wasm;
extern crate regex;

View file

@ -225,12 +225,15 @@ contract Verifier {
<%vk_gamma_abc_pts%>
}
function verify(uint[] memory input, Proof memory proof) internal returns (uint) {
uint256 snark_scalar_field = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
VerifyingKey memory vk = verifyingKey();
require(input.length + 1 == vk.gamma_abc.length);
// Compute the linear combination vk_x
Pairing.G1Point memory vk_x = Pairing.G1Point(0, 0);
for (uint i = 0; i < input.length; i++)
for (uint i = 0; i < input.length; i++) {
require(input[i] < snark_scalar_field);
vk_x = Pairing.addition(vk_x, Pairing.scalar_mul(vk.gamma_abc[i + 1], input[i]));
}
vk_x = Pairing.addition(vk_x, vk.gamma_abc[0]);
if(!Pairing.pairingProd4(
proof.a, proof.b,
@ -282,12 +285,15 @@ contract Verifier {
<%vk_gamma_abc_pts%>
}
function verify(uint[] memory input, Proof memory proof) internal returns (uint) {
uint256 snark_scalar_field = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
VerifyingKey memory vk = verifyingKey();
require(input.length + 1 == vk.gamma_abc.length);
// Compute the linear combination vk_x
Pairing.G1Point memory vk_x = Pairing.G1Point(0, 0);
for (uint i = 0; i < input.length; i++)
for (uint i = 0; i < input.length; i++) {
require(input[i] < snark_scalar_field);
vk_x = Pairing.addition(vk_x, Pairing.scalar_mul(vk.gamma_abc[i + 1], input[i]));
}
vk_x = Pairing.addition(vk_x, vk.gamma_abc[0]);
if(!Pairing.pairingProd4(
proof.a, proof.b,

View file

@ -222,12 +222,15 @@ contract Verifier {
<%vk_query_pts%>
}
function verify(uint[] memory input, Proof memory proof) internal returns (uint) {
uint256 snark_scalar_field = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
VerifyingKey memory vk = verifyingKey();
require(input.length + 1 == vk.query.length);
// Compute the linear combination vk_x
Pairing.G1Point memory vk_x = Pairing.G1Point(0, 0);
for (uint i = 0; i < input.length; i++)
for (uint i = 0; i < input.length; i++) {
require(input[i] < snark_scalar_field);
vk_x = Pairing.addition(vk_x, Pairing.scalar_mul(vk.query[i + 1], input[i]));
}
vk_x = Pairing.addition(vk_x, vk.query[0]);
/**
* e(A*G^{alpha}, B*H^{beta}) = e(G^{alpha}, H^{beta}) * e(G^{psi}, H^{gamma})
@ -286,12 +289,15 @@ contract Verifier {
<%vk_query_pts%>
}
function verify(uint[] memory input, Proof memory proof) internal returns (uint) {
uint256 snark_scalar_field = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
VerifyingKey memory vk = verifyingKey();
require(input.length + 1 == vk.query.length);
// Compute the linear combination vk_x
Pairing.G1Point memory vk_x = Pairing.G1Point(0, 0);
for (uint i = 0; i < input.length; i++)
for (uint i = 0; i < input.length; i++) {
require(input[i] < snark_scalar_field);
vk_x = Pairing.addition(vk_x, Pairing.scalar_mul(vk.query[i + 1], input[i]));
}
vk_x = Pairing.addition(vk_x, vk.query[0]);
/**
* e(A*G^{alpha}, B*H^{beta}) = e(G^{alpha}, H^{beta}) * e(G^{psi}, H^{gamma})

View file

@ -233,12 +233,15 @@ const CONTRACT_TEMPLATE_V2: &str = r#"contract Verifier {
<%vk_ic_pts%>
}
function verify(uint[] memory input, Proof memory proof) internal returns (uint) {
uint256 snark_scalar_field = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
VerifyingKey memory vk = verifyingKey();
require(input.length + 1 == vk.ic.length);
// Compute the linear combination vk_x
Pairing.G1Point memory vk_x = Pairing.G1Point(0, 0);
for (uint i = 0; i < input.length; i++)
for (uint i = 0; i < input.length; i++) {
require(input[i] < snark_scalar_field);
vk_x = Pairing.addition(vk_x, Pairing.scalar_mul(vk.ic[i + 1], input[i]));
}
vk_x = Pairing.addition(vk_x, vk.ic[0]);
if (!Pairing.pairingProd2(proof.a, vk.a, Pairing.negate(proof.a_p), Pairing.P2())) return 1;
if (!Pairing.pairingProd2(vk.b, proof.b, Pairing.negate(proof.b_p), Pairing.P2())) return 2;
@ -308,12 +311,15 @@ const CONTRACT_TEMPLATE: &str = r#"contract Verifier {
<%vk_ic_pts%>
}
function verify(uint[] memory input, Proof memory proof) internal returns (uint) {
uint256 snark_scalar_field = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
VerifyingKey memory vk = verifyingKey();
require(input.length + 1 == vk.ic.length);
// Compute the linear combination vk_x
Pairing.G1Point memory vk_x = Pairing.G1Point(0, 0);
for (uint i = 0; i < input.length; i++)
for (uint i = 0; i < input.length; i++) {
require(input[i] < snark_scalar_field);
vk_x = Pairing.addition(vk_x, Pairing.scalar_mul(vk.ic[i + 1], input[i]));
}
vk_x = Pairing.addition(vk_x, vk.ic[0]);
if (!Pairing.pairingProd2(proof.a, vk.a, Pairing.negate(proof.a_p), Pairing.P2())) return 1;
if (!Pairing.pairingProd2(vk.b, proof.b, Pairing.negate(proof.b_p), Pairing.P2())) return 2;

View file

@ -1,5 +1,3 @@
#![allow(deprecated)] // TODO remove when lazy_static is warning-free
extern crate rand;
use crate::ir::{CanonicalLinComb, Prog, Statement, Witness};

View file

@ -44,21 +44,21 @@ struct FunctionQuery<'ast> {
impl<'ast> fmt::Display for FunctionQuery<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
r#try!(write!(f, "("));
write!(f, "(")?;
for (i, t) in self.inputs.iter().enumerate() {
r#try!(write!(f, "{}", t));
write!(f, "{}", t)?;
if i < self.inputs.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
r#try!(write!(f, ") -> ("));
write!(f, ") -> (")?;
for (i, t) in self.outputs.iter().enumerate() {
match t {
Some(t) => r#try!(write!(f, "{}", t)),
None => r#try!(write!(f, "_")),
Some(t) => write!(f, "{}", t)?,
None => write!(f, "_")?,
}
if i < self.outputs.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
write!(f, ")")
@ -657,18 +657,24 @@ impl<'ast> Checker<'ast> {
let checked_expression = self.check_expression(s.value.expression)?;
match checked_expression {
TypedExpression::FieldElementArray(e) => {
let size = e.size();
Ok((0..size)
.map(|i| {
FieldElementExpression::Select(
box e.clone(),
box FieldElementExpression::Number(T::from(i)),
)
.into()
})
.collect())
}
TypedExpression::FieldElementArray(e) => match e {
// if we're doing a spread over an inline array, we return the inside of the array: ...[x, y, z] == x, y, z
FieldElementArrayExpression::Value(_, v) => {
Ok(v.into_iter().map(|e| e.into()).collect())
}
e => {
let size = e.size();
Ok((0..size)
.map(|i| {
FieldElementExpression::Select(
box e.clone(),
box FieldElementExpression::Number(T::from(i)),
)
.into()
})
.collect())
}
},
e => Err(Error {
pos: Some(pos),

View file

@ -281,11 +281,11 @@ impl<'ast, T: Field> fmt::Debug for TypedStatement<'ast, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
TypedStatement::Return(ref exprs) => {
r#try!(write!(f, "Return("));
write!(f, "Return(")?;
for (i, expr) in exprs.iter().enumerate() {
r#try!(write!(f, "{}", expr));
write!(f, "{}", expr)?;
if i < exprs.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
write!(f, ")")
@ -298,9 +298,9 @@ impl<'ast, T: Field> fmt::Debug for TypedStatement<'ast, T> {
write!(f, "Condition({:?}, {:?})", lhs, rhs)
}
TypedStatement::For(ref var, ref start, ref stop, ref list) => {
r#try!(write!(f, "for {:?} in {:?}..{:?} do\n", var, start, stop));
write!(f, "for {:?} in {:?}..{:?} do\n", var, start, stop)?;
for l in list {
r#try!(write!(f, "\t\t{:?}\n", l));
write!(f, "\t\t{:?}\n", l)?;
}
write!(f, "\tendfor")
}
@ -315,11 +315,11 @@ impl<'ast, T: Field> fmt::Display for TypedStatement<'ast, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
TypedStatement::Return(ref exprs) => {
r#try!(write!(f, "return "));
write!(f, "return ")?;
for (i, expr) in exprs.iter().enumerate() {
r#try!(write!(f, "{}", expr));
write!(f, "{}", expr)?;
if i < exprs.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
write!(f, "")
@ -328,17 +328,17 @@ impl<'ast, T: Field> fmt::Display for TypedStatement<'ast, T> {
TypedStatement::Definition(ref lhs, ref rhs) => write!(f, "{} = {}", lhs, rhs),
TypedStatement::Condition(ref lhs, ref rhs) => write!(f, "{} == {}", lhs, rhs),
TypedStatement::For(ref var, ref start, ref stop, ref list) => {
r#try!(write!(f, "for {} in {}..{} do\n", var, start, stop));
write!(f, "for {} in {}..{} do\n", var, start, stop)?;
for l in list {
r#try!(write!(f, "\t\t{}\n", l));
write!(f, "\t\t{}\n", l)?;
}
write!(f, "\tendfor")
}
TypedStatement::MultipleDefinition(ref ids, ref rhs) => {
for (i, id) in ids.iter().enumerate() {
r#try!(write!(f, "{}", id));
write!(f, "{}", id)?;
if i < ids.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
write!(f, " = {}", rhs)
@ -552,11 +552,11 @@ impl<'ast, T: Field> fmt::Display for FieldElementExpression<'ast, T> {
)
}
FieldElementExpression::FunctionCall(ref k, ref p) => {
r#try!(write!(f, "{}(", k.id,));
write!(f, "{}(", k.id,)?;
for (i, param) in p.iter().enumerate() {
r#try!(write!(f, "{}", param));
write!(f, "{}", param)?;
if i < p.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
write!(f, ")")
@ -597,11 +597,11 @@ impl<'ast, T: Field> fmt::Display for FieldElementArrayExpression<'ast, T> {
.join(", ")
),
FieldElementArrayExpression::FunctionCall(_, ref key, ref p) => {
r#try!(write!(f, "{}(", key.id,));
write!(f, "{}(", key.id,)?;
for (i, param) in p.iter().enumerate() {
r#try!(write!(f, "{}", param));
write!(f, "{}", param)?;
if i < p.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
write!(f, ")")
@ -643,8 +643,8 @@ impl<'ast, T: Field> fmt::Debug for FieldElementExpression<'ast, T> {
)
}
FieldElementExpression::FunctionCall(ref i, ref p) => {
r#try!(write!(f, "FunctionCall({:?}, (", i));
r#try!(f.debug_list().entries(p.iter()).finish());
write!(f, "FunctionCall({:?}, (", i)?;
f.debug_list().entries(p.iter()).finish()?;
write!(f, ")")
}
FieldElementExpression::Select(ref id, ref index) => {
@ -660,8 +660,8 @@ impl<'ast, T: Field> fmt::Debug for FieldElementArrayExpression<'ast, T> {
FieldElementArrayExpression::Identifier(_, ref var) => write!(f, "{:?}", var),
FieldElementArrayExpression::Value(_, ref values) => write!(f, "{:?}", values),
FieldElementArrayExpression::FunctionCall(_, ref i, ref p) => {
r#try!(write!(f, "FunctionCall({:?}, (", i));
r#try!(f.debug_list().entries(p.iter()).finish());
write!(f, "FunctionCall({:?}, (", i)?;
f.debug_list().entries(p.iter()).finish()?;
write!(f, ")")
}
FieldElementArrayExpression::IfElse(ref condition, ref consequent, ref alternative) => {
@ -679,11 +679,11 @@ impl<'ast, T: Field> fmt::Display for TypedExpressionList<'ast, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
TypedExpressionList::FunctionCall(ref key, ref p, _) => {
r#try!(write!(f, "{}(", key.id,));
write!(f, "{}(", key.id,)?;
for (i, param) in p.iter().enumerate() {
r#try!(write!(f, "{}", param));
write!(f, "{}", param)?;
if i < p.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
write!(f, ")")
@ -696,8 +696,8 @@ impl<'ast, T: Field> fmt::Debug for TypedExpressionList<'ast, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
TypedExpressionList::FunctionCall(ref i, ref p, _) => {
r#try!(write!(f, "FunctionCall({:?}, (", i));
r#try!(f.debug_list().entries(p.iter()).finish());
write!(f, "FunctionCall({:?}, (", i)?;
f.debug_list().entries(p.iter()).finish()?;
write!(f, ")")
}
}

View file

@ -37,7 +37,7 @@ impl Type {
match *self {
Type::FieldElement => String::from("f"),
Type::Boolean => String::from("b"),
Type::FieldElementArray(size) => format!("{}[{}]", Type::FieldElement.to_slug(), size), // TODO differentiate types?
Type::FieldElementArray(size) => format!("{}[{}]", Type::FieldElement.to_slug(), size),
}
}

View file

@ -19,18 +19,18 @@ impl fmt::Debug for Signature {
impl fmt::Display for Signature {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
r#try!(write!(f, "("));
write!(f, "(")?;
for (i, t) in self.inputs.iter().enumerate() {
r#try!(write!(f, "{}", t));
write!(f, "{}", t)?;
if i < self.inputs.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
r#try!(write!(f, ") -> ("));
write!(f, ") -> (")?;
for (i, t) in self.outputs.iter().enumerate() {
r#try!(write!(f, "{}", t));
write!(f, "{}", t)?;
if i < self.outputs.len() - 1 {
r#try!(write!(f, ", "));
write!(f, ", ")?;
}
}
write!(f, ")")

View file

@ -5,5 +5,5 @@ authors = ["schaeff <thibaut@schaeff.fr>"]
edition = "2018"
[dependencies]
sapling-crypto = { git = 'https://github.com/matterinc/sapling-crypto', tag = "0.0.4" }
bellman = { git = 'https://github.com/matterinc/bellman', tag = "0.2.0" }
sapling-crypto_ce = "0.1"
bellman_ce = "0.3"

View file

@ -1,3 +1,6 @@
extern crate bellman_ce as bellman;
extern crate sapling_crypto_ce as sapling_crypto;
use bellman::{
pairing::{ff::Field, Engine},
ConstraintSystem, Index, LinearCombination, SynthesisError, Variable,

View file

@ -7,13 +7,13 @@ edition = "2018"
[dependencies]
serde = "1.0"
serde_derive = "1.0"
lazy_static = "0.1.*"
lazy_static = "1.4"
bincode = "0.8.0"
serde_json = "1.0"
num-traits = "0.2"
num-integer = "0.1"
pairing = { git = "https://github.com/matterinc/pairing", tag = "0.16.2" }
ff = { git = 'https://github.com/matterinc/ff', features = ["derive"], tag = "0.5" }
pairing_ce = "0.18"
ff_ce = { features = ["derive"], version = "0.7" }
[dev-dependencies]
rand = "0.4"

View file

@ -1,5 +1,3 @@
#![allow(deprecated)] // TODO remove when lazy_static is warning-free
//
// @file field.rs
// @author Dennis Kuhnert <dennis.kuhnert@campus.tu-berlin.de>
@ -800,5 +798,4 @@ mod tests {
assert_eq!(FieldPrime::from_bellman(a), cc);
}
}
}

View file

@ -1 +1,4 @@
extern crate ff_ce as ff;
extern crate pairing_ce as pairing;
pub mod field;

View file

@ -1,6 +1,6 @@
[package]
name = "zokrates_parser"
version = "0.1.1"
version = "0.1.2"
authors = ["JacobEberhardt <jacob.eberhardt@tu-berlin.de>"]
edition = "2018"

View file

@ -1,6 +1,6 @@
[package]
name = "zokrates_pest_ast"
version = "0.1.1"
version = "0.1.2"
authors = ["schaeff <thibaut@schaeff.fr>"]
edition = "2018"

View file

@ -1,4 +1,5 @@
// SHA2 initial values are taken from here: https://en.wikipedia.org/wiki/SHA-2
// SHA-256 is specified in FIPS 180-3 and initial values are listed in section 5.3.3
// https://csrc.nist.gov/csrc/media/publications/fips/180/3/archive/2008-10-31/documents/fips180-3_final.pdf
def main() -> (field[256]):
field[32] h0 = [0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1]
field[32] h1 = [1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1]
@ -11,4 +12,4 @@ def main() -> (field[256]):
field[256] IV = [...h0, ...h1, ...h2, ...h3, ...h4, ...h5, ...h6, ...h7]
return IV
return IV