Skip to content

Commit

Permalink
Merge pull request #464 from Zokrates/rc/0.4.11
Browse files Browse the repository at this point in the history
Release 0.4.11
  • Loading branch information
JacobEberhardt authored Aug 21, 2019
2 parents bb98ab1 + db4beb6 commit 6522cf0
Show file tree
Hide file tree
Showing 11 changed files with 426 additions and 476 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
734 changes: 342 additions & 392 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion zokrates_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zokrates_cli"
version = "0.4.10"
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"
Expand Down
2 changes: 1 addition & 1 deletion zokrates_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zokrates_core"
version = "0.3.13"
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"
Expand Down
36 changes: 18 additions & 18 deletions zokrates_core/src/absy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,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)
Expand All @@ -201,9 +201,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")
}
Expand Down Expand Up @@ -362,11 +362,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, ")")
Expand All @@ -379,11 +379,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, "]")
Expand Down Expand Up @@ -411,8 +411,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),
Expand All @@ -423,8 +423,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),
Expand All @@ -451,9 +451,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, "")
Expand Down
4 changes: 2 additions & 2 deletions zokrates_core/src/flat_absy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,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, "")
Expand Down
41 changes: 21 additions & 20 deletions zokrates_core/src/flatten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,28 @@ impl<'ast> Flattener<'ast> {
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],
)));

// 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]),
),
));
}
Expand All @@ -175,7 +175,7 @@ impl<'ast> Flattener<'ast> {
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)),
),
);
Expand All @@ -194,23 +194,23 @@ impl<'ast> Flattener<'ast> {
// 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],
)));

// 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]),
),
));
}
Expand All @@ -222,7 +222,7 @@ impl<'ast> Flattener<'ast> {
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)),
),
);
Expand All @@ -247,22 +247,23 @@ impl<'ast> Flattener<'ast> {
);

// 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()],
)));

// 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]),
),
));
}
Expand All @@ -274,15 +275,15 @@ impl<'ast> Flattener<'ast> {
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)),
),
);
}

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
Expand Down
14 changes: 7 additions & 7 deletions zokrates_core/src/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ pub 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, ")")
Expand Down
Loading

0 comments on commit 6522cf0

Please sign in to comment.