From 1dbd753ac77f904e79a5955f8ebc4f18a23c5b10 Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 20 Sep 2021 18:23:24 +0200 Subject: [PATCH 01/23] Add optional message to assert statement --- zokrates_core/src/absy/from_ast.rs | 7 +- zokrates_core/src/absy/mod.rs | 11 +- zokrates_core/src/flat_absy/mod.rs | 20 +-- zokrates_core/src/flatten/mod.rs | 139 +++++++++++------- zokrates_core/src/ir/interpreter.rs | 34 ++++- zokrates_core/src/parser/tokenize/position.rs | 2 +- zokrates_core/src/semantics.rs | 13 +- .../static_analysis/flatten_complex_types.rs | 4 +- .../src/static_analysis/propagation.rs | 10 +- .../src/static_analysis/uint_optimizer.rs | 9 +- .../static_analysis/variable_write_remover.rs | 1 + .../src/static_analysis/zir_propagation.rs | 36 +++-- zokrates_core/src/typed_absy/folder.rs | 4 +- zokrates_core/src/typed_absy/mod.rs | 31 +++- zokrates_core/src/typed_absy/result_folder.rs | 4 +- zokrates_core/src/zir/folder.rs | 2 +- zokrates_core/src/zir/mod.rs | 42 ++---- zokrates_core/src/zir/result_folder.rs | 2 +- .../tests/tests/arrays/identity.json | 2 +- .../tests/tests/arrays/select.json | 2 +- .../tests/tests/assert_one.json | 4 +- .../conditional_bound_throw_no_isolation.json | 12 +- .../panics/deep_branch_no_isolation.json | 4 +- .../panics/internal_panic_no_isolation.json | 2 +- .../tests/tests/panics/loop_bound.json | 4 +- .../tests/tests/panics/panic_isolation.json | 4 +- .../tests/panics/panic_no_isolation.json | 4 +- .../tests/tests/structs/identity.json | 2 +- zokrates_parser/src/zokrates.pest | 9 +- zokrates_pest_ast/src/lib.rs | 31 ++-- 30 files changed, 276 insertions(+), 175 deletions(-) diff --git a/zokrates_core/src/absy/from_ast.rs b/zokrates_core/src/absy/from_ast.rs index a968b9c2..bd95f61c 100644 --- a/zokrates_core/src/absy/from_ast.rs +++ b/zokrates_core/src/absy/from_ast.rs @@ -346,8 +346,11 @@ impl<'ast> From> for absy::StatementNode<'ast> { fn from(statement: pest::AssertionStatement<'ast>) -> absy::StatementNode<'ast> { use crate::absy::NodeValue; - absy::Statement::Assertion(absy::ExpressionNode::from(statement.expression)) - .span(statement.span) + absy::Statement::Assertion( + absy::ExpressionNode::from(statement.expression), + statement.message.map(|m| m.value), + ) + .span(statement.span) } } diff --git a/zokrates_core/src/absy/mod.rs b/zokrates_core/src/absy/mod.rs index 70fc76d0..31150df4 100644 --- a/zokrates_core/src/absy/mod.rs +++ b/zokrates_core/src/absy/mod.rs @@ -337,7 +337,7 @@ pub enum Statement<'ast> { Return(ExpressionListNode<'ast>), Declaration(VariableNode<'ast>), Definition(AssigneeNode<'ast>, ExpressionNode<'ast>), - Assertion(ExpressionNode<'ast>), + Assertion(ExpressionNode<'ast>, Option), For( VariableNode<'ast>, ExpressionNode<'ast>, @@ -355,7 +355,14 @@ impl<'ast> fmt::Display for Statement<'ast> { Statement::Return(ref expr) => write!(f, "return {}", expr), Statement::Declaration(ref var) => write!(f, "{}", var), Statement::Definition(ref lhs, ref rhs) => write!(f, "{} = {}", lhs, rhs), - Statement::Assertion(ref e) => write!(f, "assert({})", e), + Statement::Assertion(ref e, ref message) => { + write!(f, "assert({}", e)?; + if message.is_some() { + write!(f, ", \"{}\")", message.as_ref().unwrap()) + } else { + write!(f, ")") + } + } Statement::For(ref var, ref start, ref stop, ref list) => { writeln!(f, "for {} in {}..{} do", var, start, stop)?; for l in list { diff --git a/zokrates_core/src/flat_absy/mod.rs b/zokrates_core/src/flat_absy/mod.rs index 9da11f49..96cdab83 100644 --- a/zokrates_core/src/flat_absy/mod.rs +++ b/zokrates_core/src/flat_absy/mod.rs @@ -43,18 +43,18 @@ pub enum RuntimeError { Euclidean, ShaXor, Division, - Source, + Source(Option), ArgumentBitness, SelectRangeCheck, } impl RuntimeError { - fn is_malicious(&self) -> bool { + pub(crate) fn is_malicious(&self) -> bool { use RuntimeError::*; !matches!( self, - Source | Inverse | LtSum | SelectRangeCheck | ArgumentBitness + Source(_) | Inverse | LtSum | SelectRangeCheck | ArgumentBitness ) } } @@ -87,19 +87,15 @@ impl fmt::Display for RuntimeError { Euclidean => "Euclidean check failed", ShaXor => "Internal Sha check failed", Division => "Division check failed", - Source => "User assertion failed", + Source(m) => m + .as_ref() + .map(|s| s.as_str()) + .unwrap_or("User assertion failed"), ArgumentBitness => "Argument bitness check failed", SelectRangeCheck => "Out of bounds array access", }; - write!(f, "{}", msg)?; - - if self.is_malicious() { - writeln!(f)?; - write!(f, "The default ZoKrates interpreter should not yield this error. Please open an issue")?; - } - - write!(f, "") + write!(f, "{}", msg) } } diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index 79d3948f..7564ba9d 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -14,6 +14,7 @@ use crate::compile::CompileConfig; use crate::embed::FlatEmbed; use crate::flat_absy::*; use crate::solvers::Solver; +use crate::typed_absy::AssertionMetadata; use crate::zir::types::{Type, UBitwidth}; use crate::zir::*; use std::collections::hash_map::Entry; @@ -2367,13 +2368,13 @@ impl<'ast, T: Field> Flattener<'ast, T> { .insert(FlatExpression::Identifier(var), bits); } } - ZirStatement::Assertion(e) => { + ZirStatement::Assertion(e, metadata) => { match e { BooleanExpression::And(..) => { for boolean in e.into_conjunction_iterator() { self.flatten_statement( statements_flattened, - ZirStatement::Assertion(boolean), + ZirStatement::Assertion(boolean, metadata.clone()), ) } } @@ -2381,7 +2382,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { let lhs = self.flatten_field_expression(statements_flattened, lhs); let rhs = self.flatten_field_expression(statements_flattened, rhs); - self.flatten_equality_assertion(statements_flattened, lhs, rhs) + self.flatten_equality_assertion(statements_flattened, lhs, rhs, metadata) } BooleanExpression::UintEq(box lhs, box rhs) => { let lhs = self @@ -2391,13 +2392,13 @@ impl<'ast, T: Field> Flattener<'ast, T> { .flatten_uint_expression(statements_flattened, rhs) .get_field_unchecked(); - self.flatten_equality_assertion(statements_flattened, lhs, rhs) + self.flatten_equality_assertion(statements_flattened, lhs, rhs, metadata) } BooleanExpression::BoolEq(box lhs, box rhs) => { let lhs = self.flatten_boolean_expression(statements_flattened, lhs); let rhs = self.flatten_boolean_expression(statements_flattened, rhs); - self.flatten_equality_assertion(statements_flattened, lhs, rhs) + self.flatten_equality_assertion(statements_flattened, lhs, rhs, metadata) } _ => { // naive approach: flatten the boolean to a single field element and constrain it to 1 @@ -2407,14 +2408,14 @@ impl<'ast, T: Field> Flattener<'ast, T> { statements_flattened.push(FlatStatement::Condition( e, FlatExpression::Number(T::from(1)), - RuntimeError::Source, + RuntimeError::Source(metadata.map(|m| m.to_string())), )); } else { // swap so that left side is linear statements_flattened.push(FlatStatement::Condition( FlatExpression::Number(T::from(1)), e, - RuntimeError::Source, + RuntimeError::Source(metadata.map(|m| m.to_string())), )); } } @@ -2526,6 +2527,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { statements_flattened: &mut FlatStatements, lhs: FlatExpression, rhs: FlatExpression, + metadata: Option, ) { let (lhs, rhs) = match (lhs, rhs) { (FlatExpression::Mult(box x, box y), z) | (z, FlatExpression::Mult(box x, box y)) => ( @@ -2543,7 +2545,11 @@ impl<'ast, T: Field> Flattener<'ast, T> { ), ), }; - statements_flattened.push(FlatStatement::Condition(lhs, rhs, RuntimeError::Source)); + statements_flattened.push(FlatStatement::Condition( + lhs, + rhs, + RuntimeError::Source(metadata.map(|m| m.to_string())), + )); } /// Identifies a non-linear expression by assigning it to a new identifier. @@ -2676,10 +2682,13 @@ mod tests { Variable::boolean("y".into()), BooleanExpression::Value(true).into(), ), - ZirStatement::Assertion(BooleanExpression::BoolEq( - box BooleanExpression::Identifier("x".into()), - box BooleanExpression::Identifier("y".into()), - )), + ZirStatement::Assertion( + BooleanExpression::BoolEq( + box BooleanExpression::Identifier("x".into()), + box BooleanExpression::Identifier("y".into()), + ), + None, + ), ], signature: Signature { inputs: vec![], @@ -2708,7 +2717,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Number(Bn128Field::from(1)), ), - RuntimeError::Source, + RuntimeError::Source(None), ), ], }; @@ -2738,13 +2747,16 @@ mod tests { Variable::field_element("y"), FieldElementExpression::Number(Bn128Field::from(2)).into(), ), - ZirStatement::Assertion(BooleanExpression::FieldEq( - box FieldElementExpression::Add( - box FieldElementExpression::Identifier("x".into()), - box FieldElementExpression::Number(Bn128Field::from(1)), + ZirStatement::Assertion( + BooleanExpression::FieldEq( + box FieldElementExpression::Add( + box FieldElementExpression::Identifier("x".into()), + box FieldElementExpression::Number(Bn128Field::from(1)), + ), + box FieldElementExpression::Identifier("y".into()), ), - box FieldElementExpression::Identifier("y".into()), - )), + None, + ), ], signature: Signature { inputs: vec![], @@ -2776,7 +2788,7 @@ mod tests { ), box FlatExpression::Number(Bn128Field::from(1)), ), - RuntimeError::Source, + RuntimeError::Source(None), ), ], }; @@ -2808,12 +2820,15 @@ mod tests { .metadata(metadata.clone()), ), ), - ZirStatement::Assertion(BooleanExpression::UintEq( - box UExpressionInner::Identifier("x".into()) - .annotate(32) - .metadata(metadata.clone()), - box UExpressionInner::Value(42).annotate(32).metadata(metadata), - )), + ZirStatement::Assertion( + BooleanExpression::UintEq( + box UExpressionInner::Identifier("x".into()) + .annotate(32) + .metadata(metadata.clone()), + box UExpressionInner::Value(42).annotate(32).metadata(metadata), + ), + None, + ), ], signature: Signature { inputs: vec![], @@ -2838,7 +2853,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Number(Bn128Field::from(1)), ), - RuntimeError::Source, + RuntimeError::Source(None), ), ], }; @@ -2868,10 +2883,13 @@ mod tests { Variable::field_element("y"), FieldElementExpression::Number(Bn128Field::from(2)).into(), ), - ZirStatement::Assertion(BooleanExpression::FieldEq( - box FieldElementExpression::Identifier("x".into()), - box FieldElementExpression::Identifier("y".into()), - )), + ZirStatement::Assertion( + BooleanExpression::FieldEq( + box FieldElementExpression::Identifier("x".into()), + box FieldElementExpression::Identifier("y".into()), + ), + None, + ), ], signature: Signature { inputs: vec![], @@ -2900,7 +2918,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Number(Bn128Field::from(1)), ), - RuntimeError::Source, + RuntimeError::Source(None), ), ], }; @@ -2936,13 +2954,16 @@ mod tests { Variable::field_element("z"), FieldElementExpression::Number(Bn128Field::from(4)).into(), ), - ZirStatement::Assertion(BooleanExpression::FieldEq( - box FieldElementExpression::Mult( - box FieldElementExpression::Identifier("x".into()), - box FieldElementExpression::Identifier("y".into()), + ZirStatement::Assertion( + BooleanExpression::FieldEq( + box FieldElementExpression::Mult( + box FieldElementExpression::Identifier("x".into()), + box FieldElementExpression::Identifier("y".into()), + ), + box FieldElementExpression::Identifier("z".into()), ), - box FieldElementExpression::Identifier("z".into()), - )), + None, + ), ], signature: Signature { inputs: vec![], @@ -2975,7 +2996,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Identifier(FlatVariable::new(1)), ), - RuntimeError::Source, + RuntimeError::Source(None), ), ], }; @@ -3011,13 +3032,16 @@ mod tests { Variable::field_element("z"), FieldElementExpression::Number(Bn128Field::from(4)).into(), ), - ZirStatement::Assertion(BooleanExpression::FieldEq( - box FieldElementExpression::Identifier("z".into()), - box FieldElementExpression::Mult( - box FieldElementExpression::Identifier("x".into()), - box FieldElementExpression::Identifier("y".into()), + ZirStatement::Assertion( + BooleanExpression::FieldEq( + box FieldElementExpression::Identifier("z".into()), + box FieldElementExpression::Mult( + box FieldElementExpression::Identifier("x".into()), + box FieldElementExpression::Identifier("y".into()), + ), ), - )), + None, + ), ], signature: Signature { inputs: vec![], @@ -3050,7 +3074,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Identifier(FlatVariable::new(1)), ), - RuntimeError::Source, + RuntimeError::Source(None), ), ], }; @@ -3093,16 +3117,19 @@ mod tests { Variable::field_element("t"), FieldElementExpression::Number(Bn128Field::from(2)).into(), ), - ZirStatement::Assertion(BooleanExpression::FieldEq( - box FieldElementExpression::Mult( - box FieldElementExpression::Identifier("x".into()), - box FieldElementExpression::Identifier("y".into()), + ZirStatement::Assertion( + BooleanExpression::FieldEq( + box FieldElementExpression::Mult( + box FieldElementExpression::Identifier("x".into()), + box FieldElementExpression::Identifier("y".into()), + ), + box FieldElementExpression::Mult( + box FieldElementExpression::Identifier("z".into()), + box FieldElementExpression::Identifier("t".into()), + ), ), - box FieldElementExpression::Mult( - box FieldElementExpression::Identifier("z".into()), - box FieldElementExpression::Identifier("t".into()), - ), - )), + None, + ), ], signature: Signature { inputs: vec![], @@ -3146,7 +3173,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Identifier(FlatVariable::new(1)), ), - RuntimeError::Source, + RuntimeError::Source(None), ), ], }; diff --git a/zokrates_core/src/ir/interpreter.rs b/zokrates_core/src/ir/interpreter.rs index 8b071998..be02e8b1 100644 --- a/zokrates_core/src/ir/interpreter.rs +++ b/zokrates_core/src/ir/interpreter.rs @@ -1,4 +1,5 @@ use crate::flat_absy::flat_variable::FlatVariable; +use crate::flat_absy::RuntimeError; use crate::ir::{LinComb, Prog, QuadComb, Statement, Witness}; use crate::solvers::Solver; use serde::{Deserialize, Serialize}; @@ -44,7 +45,7 @@ impl Interpreter { for statement in program.statements.iter() { match statement { - Statement::Constraint(quad, lin, message) => match lin.is_assignee(&witness) { + Statement::Constraint(quad, lin, error) => match lin.is_assignee(&witness) { true => { let val = quad.evaluate(&witness).unwrap(); witness.insert(lin.0.get(0).unwrap().0, val); @@ -56,10 +57,7 @@ impl Interpreter { return Err(Error::UnsatisfiedConstraint { left: lhs_value.to_dec_string(), right: rhs_value.to_dec_string(), - message: message - .as_ref() - .map(|m| m.to_string()) - .unwrap_or_else(|| "Unknown".to_string()), + error: error.to_owned(), }); } } @@ -285,7 +283,7 @@ pub enum Error { UnsatisfiedConstraint { left: String, right: String, - message: String, + error: Option, }, Solver, WrongInputCount { @@ -300,8 +298,28 @@ impl fmt::Display for Error { Error::UnsatisfiedConstraint { ref left, ref right, - ref message, - } => write!(f, "{}: expected {} to equal {}", message, left, right), + ref error, + } => { + write!( + f, + "{}", + error + .as_ref() + .map(|m| m.to_string()) + .unwrap_or_else(|| format!( + "Unsatisfied constraint: expected {} to equal {}", + left, right + )) + )?; + + match error { + Some(e) if e.is_malicious() => { + writeln!(f)?; + write!(f, "The default ZoKrates interpreter should not yield this error. Please open an issue.") + } + _ => write!(f, ""), + } + } Error::Solver => write!(f, ""), Error::WrongInputCount { expected, received } => write!( f, diff --git a/zokrates_core/src/parser/tokenize/position.rs b/zokrates_core/src/parser/tokenize/position.rs index a85ed3ce..ee90bccb 100644 --- a/zokrates_core/src/parser/tokenize/position.rs +++ b/zokrates_core/src/parser/tokenize/position.rs @@ -1,6 +1,6 @@ use std::fmt; -#[derive(Clone, PartialEq, Copy)] +#[derive(Clone, PartialEq, Eq, Copy, Hash, Default)] pub struct Position { pub line: usize, pub col: usize, diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 937fbf17..2ce7f517 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -1700,13 +1700,20 @@ impl<'ast, T: Field> Checker<'ast, T> { .map(|rhs| TypedStatement::Definition(var, rhs)) .map_err(|e| vec![e]) } - Statement::Assertion(e) => { + Statement::Assertion(e, message) => { let e = self .check_expression(e, module_id, types) .map_err(|e| vec![e])?; match e { - TypedExpression::Boolean(e) => Ok(TypedStatement::Assertion(e)), + TypedExpression::Boolean(e) => Ok(TypedStatement::Assertion( + e, + Some(AssertionMetadata { + file: module_id.display().to_string(), + position: pos.0, + message, + }), + )), e => Err(ErrorInner { pos: Some(pos), message: format!( @@ -4523,6 +4530,7 @@ mod tests { box Expression::FunctionCall("foo", None, vec![]).mock(), ) .mock(), + None, ) .mock(), Statement::Return( @@ -4923,6 +4931,7 @@ mod tests { box Expression::FunctionCall("foo", None, vec![]).mock(), ) .mock(), + None, ) .mock(), Statement::Return( diff --git a/zokrates_core/src/static_analysis/flatten_complex_types.rs b/zokrates_core/src/static_analysis/flatten_complex_types.rs index f3973297..83af0e99 100644 --- a/zokrates_core/src/static_analysis/flatten_complex_types.rs +++ b/zokrates_core/src/static_analysis/flatten_complex_types.rs @@ -379,9 +379,9 @@ fn fold_statement<'ast, T: Field>( typed_absy::TypedStatement::Declaration(..) => { unreachable!() } - typed_absy::TypedStatement::Assertion(e) => { + typed_absy::TypedStatement::Assertion(e, m) => { let e = f.fold_boolean_expression(statements_buffer, e); - vec![zir::ZirStatement::Assertion(e)] + vec![zir::ZirStatement::Assertion(e, m)] } typed_absy::TypedStatement::For(..) => unreachable!(), typed_absy::TypedStatement::MultipleDefinition(variables, elist) => { diff --git a/zokrates_core/src/static_analysis/propagation.rs b/zokrates_core/src/static_analysis/propagation.rs index 38c29a0c..0fb654cf 100644 --- a/zokrates_core/src/static_analysis/propagation.rs +++ b/zokrates_core/src/static_analysis/propagation.rs @@ -610,15 +610,17 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { Ok(statements) } - TypedStatement::Assertion(e) => { + TypedStatement::Assertion(e, s) => { let e_str = e.to_string(); let expr = self.fold_boolean_expression(e)?; match expr { BooleanExpression::Value(v) if !v => Err(Error::AssertionFailed(format!( - "Assertion failed on expression `{}`", - e_str + "{}: ({})", + s.map(|m| m.to_string()) + .unwrap_or_else(|| "Assertion failed".to_string()), + e_str, ))), - _ => Ok(vec![TypedStatement::Assertion(expr)]), + _ => Ok(vec![TypedStatement::Assertion(expr, s)]), } } s @ TypedStatement::PushCallLog(..) => Ok(vec![s]), diff --git a/zokrates_core/src/static_analysis/uint_optimizer.rs b/zokrates_core/src/static_analysis/uint_optimizer.rs index ab8911a7..4c0a26c6 100644 --- a/zokrates_core/src/static_analysis/uint_optimizer.rs +++ b/zokrates_core/src/static_analysis/uint_optimizer.rs @@ -531,7 +531,7 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { } } } - ZirStatement::Assertion(BooleanExpression::UintEq(box left, box right)) => { + ZirStatement::Assertion(BooleanExpression::UintEq(box left, box right), m) => { let left = self.fold_uint_expression(left); let right = self.fold_uint_expression(right); @@ -539,9 +539,10 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { let left = force_reduce(left); let right = force_reduce(right); - vec![ZirStatement::Assertion(BooleanExpression::UintEq( - box left, box right, - ))] + vec![ZirStatement::Assertion( + BooleanExpression::UintEq(box left, box right), + m, + )] } s => fold_statement(self, s), } diff --git a/zokrates_core/src/static_analysis/variable_write_remover.rs b/zokrates_core/src/static_analysis/variable_write_remover.rs index 82cc206e..c99459fd 100644 --- a/zokrates_core/src/static_analysis/variable_write_remover.rs +++ b/zokrates_core/src/static_analysis/variable_write_remover.rs @@ -49,6 +49,7 @@ impl<'ast> VariableWriteRemover { Access::Select(head) => { statements.insert(TypedStatement::Assertion( BooleanExpression::UintLt(box head.clone(), box size.into()), + None, )); ArrayExpressionInner::Value( diff --git a/zokrates_core/src/static_analysis/zir_propagation.rs b/zokrates_core/src/static_analysis/zir_propagation.rs index c3028a03..8e0b7714 100644 --- a/zokrates_core/src/static_analysis/zir_propagation.rs +++ b/zokrates_core/src/static_analysis/zir_propagation.rs @@ -51,9 +51,9 @@ impl<'ast, T: Field> ResultFolder<'ast, T> for ZirPropagator<'ast, T> { s: ZirStatement<'ast, T>, ) -> Result>, Self::Error> { match s { - ZirStatement::Assertion(e) => match self.fold_boolean_expression(e)? { + ZirStatement::Assertion(e, m) => match self.fold_boolean_expression(e)? { BooleanExpression::Value(true) => Ok(vec![]), - e => Ok(vec![ZirStatement::Assertion(e)]), + e => Ok(vec![ZirStatement::Assertion(e, m)]), }, ZirStatement::Definition(a, e) => { let e = self.fold_expression(e)?; @@ -659,16 +659,19 @@ mod tests { #[test] fn propagation() { // assert([x, 1] == [y, 1]) - let statements = vec![ZirStatement::Assertion(BooleanExpression::And( - box BooleanExpression::FieldEq( - box FieldElementExpression::Identifier("x".into()), - box FieldElementExpression::Identifier("y".into()), + let statements = vec![ZirStatement::Assertion( + BooleanExpression::And( + box BooleanExpression::FieldEq( + box FieldElementExpression::Identifier("x".into()), + box FieldElementExpression::Identifier("y".into()), + ), + box BooleanExpression::FieldEq( + box FieldElementExpression::Number(Bn128Field::from(1)), + box FieldElementExpression::Number(Bn128Field::from(1)), + ), ), - box BooleanExpression::FieldEq( - box FieldElementExpression::Number(Bn128Field::from(1)), - box FieldElementExpression::Number(Bn128Field::from(1)), - ), - ))]; + None, + )]; let mut propagator = ZirPropagator::default(); let statements: Vec> = statements @@ -682,10 +685,13 @@ mod tests { assert_eq!( statements, - vec![ZirStatement::Assertion(BooleanExpression::FieldEq( - box FieldElementExpression::Identifier("x".into()), - box FieldElementExpression::Identifier("y".into()), - ))] + vec![ZirStatement::Assertion( + BooleanExpression::FieldEq( + box FieldElementExpression::Identifier("x".into()), + box FieldElementExpression::Identifier("y".into()), + ), + None + )] ); } diff --git a/zokrates_core/src/typed_absy/folder.rs b/zokrates_core/src/typed_absy/folder.rs index 6bb1cc19..ac3dcd49 100644 --- a/zokrates_core/src/typed_absy/folder.rs +++ b/zokrates_core/src/typed_absy/folder.rs @@ -416,7 +416,9 @@ pub fn fold_statement<'ast, T: Field, F: Folder<'ast, T>>( TypedStatement::Definition(f.fold_assignee(a), f.fold_expression(e)) } TypedStatement::Declaration(v) => TypedStatement::Declaration(f.fold_variable(v)), - TypedStatement::Assertion(e) => TypedStatement::Assertion(f.fold_boolean_expression(e)), + TypedStatement::Assertion(e, m) => { + TypedStatement::Assertion(f.fold_boolean_expression(e), m) + } TypedStatement::For(v, from, to, statements) => TypedStatement::For( f.fold_variable(v), f.fold_uint_expression(from), diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index b31dfeee..3b4a9039 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -24,6 +24,7 @@ pub use self::types::{ DeclarationStructType, DeclarationType, GArrayType, GStructType, GType, GenericIdentifier, IntoTypes, Signature, StructType, Type, Types, UBitwidth, }; +use crate::parser::Position; use crate::typed_absy::types::ConcreteGenericsAssignment; pub use self::variable::{ConcreteVariable, DeclarationVariable, GVariable, Variable}; @@ -485,6 +486,24 @@ impl<'ast, T: fmt::Display> fmt::Display for TypedAssignee<'ast, T> { } } +#[derive(Clone, Debug, PartialEq, Hash, Eq, Default)] +pub struct AssertionMetadata { + pub file: String, + pub position: Position, + pub message: Option, +} + +impl fmt::Display for AssertionMetadata { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Assertion failed at {}:{}", self.file, self.position)?; + if self.message.is_some() { + write!(f, ": \"{}\"", self.message.as_ref().unwrap()) + } else { + write!(f, "") + } + } +} + /// A statement in a `TypedFunction` #[allow(clippy::large_enum_variant)] #[derive(Clone, PartialEq, Debug, Hash, Eq)] @@ -492,7 +511,7 @@ pub enum TypedStatement<'ast, T> { Return(Vec>), Definition(TypedAssignee<'ast, T>, TypedExpression<'ast, T>), Declaration(Variable<'ast, T>), - Assertion(BooleanExpression<'ast, T>), + Assertion(BooleanExpression<'ast, T>, Option), For( Variable<'ast, T>, UExpression<'ast, T>, @@ -540,7 +559,15 @@ impl<'ast, T: fmt::Display> fmt::Display for TypedStatement<'ast, T> { } TypedStatement::Declaration(ref var) => write!(f, "{}", var), TypedStatement::Definition(ref lhs, ref rhs) => write!(f, "{} = {}", lhs, rhs), - TypedStatement::Assertion(ref e) => write!(f, "assert({})", e), + TypedStatement::Assertion(ref e, ref metadata) => { + write!(f, "assert({}", e)?; + let metadata = metadata.as_ref().unwrap(); + if metadata.message.is_some() { + write!(f, ", \"{}\")", metadata.message.as_ref().unwrap()) + } else { + write!(f, ")") + } + } TypedStatement::For(ref var, ref start, ref stop, ref list) => { writeln!(f, "for {} in {}..{} do", var, start, stop)?; for l in list { diff --git a/zokrates_core/src/typed_absy/result_folder.rs b/zokrates_core/src/typed_absy/result_folder.rs index c85e97a7..831e7af6 100644 --- a/zokrates_core/src/typed_absy/result_folder.rs +++ b/zokrates_core/src/typed_absy/result_folder.rs @@ -444,7 +444,9 @@ pub fn fold_statement<'ast, T: Field, F: ResultFolder<'ast, T>>( TypedStatement::Definition(f.fold_assignee(a)?, f.fold_expression(e)?) } TypedStatement::Declaration(v) => TypedStatement::Declaration(f.fold_variable(v)?), - TypedStatement::Assertion(e) => TypedStatement::Assertion(f.fold_boolean_expression(e)?), + TypedStatement::Assertion(e, m) => { + TypedStatement::Assertion(f.fold_boolean_expression(e)?, m) + } TypedStatement::For(v, from, to, statements) => TypedStatement::For( f.fold_variable(v)?, f.fold_uint_expression(from)?, diff --git a/zokrates_core/src/zir/folder.rs b/zokrates_core/src/zir/folder.rs index b8f55e8d..dbf6011f 100644 --- a/zokrates_core/src/zir/folder.rs +++ b/zokrates_core/src/zir/folder.rs @@ -115,7 +115,7 @@ pub fn fold_statement<'ast, T: Field, F: Folder<'ast, T>>( .flat_map(|e| f.fold_statement(e)) .collect(), ), - ZirStatement::Assertion(e) => ZirStatement::Assertion(f.fold_boolean_expression(e)), + ZirStatement::Assertion(e, m) => ZirStatement::Assertion(f.fold_boolean_expression(e), m), ZirStatement::MultipleDefinition(variables, elist) => ZirStatement::MultipleDefinition( variables.into_iter().map(|v| f.fold_variable(v)).collect(), f.fold_expression_list(elist), diff --git a/zokrates_core/src/zir/mod.rs b/zokrates_core/src/zir/mod.rs index db5ab4a6..bc54c58a 100644 --- a/zokrates_core/src/zir/mod.rs +++ b/zokrates_core/src/zir/mod.rs @@ -21,6 +21,7 @@ use zokrates_field::Field; pub use self::folder::Folder; pub use self::identifier::{Identifier, SourceIdentifier}; +use crate::typed_absy::AssertionMetadata; /// A typed program as a collection of modules, one of them being the main #[derive(PartialEq, Debug)] @@ -87,7 +88,7 @@ impl<'ast, T: fmt::Debug> fmt::Debug for ZirFunction<'ast, T> { pub type ZirAssignee<'ast> = Variable<'ast>; /// A statement in a `ZirFunction` -#[derive(Clone, PartialEq, Hash, Eq)] +#[derive(Clone, PartialEq, Hash, Eq, Debug)] pub enum ZirStatement<'ast, T> { Return(Vec>), Definition(ZirAssignee<'ast>, ZirExpression<'ast, T>), @@ -96,37 +97,10 @@ pub enum ZirStatement<'ast, T> { Vec>, Vec>, ), - Assertion(BooleanExpression<'ast, T>), + Assertion(BooleanExpression<'ast, T>, Option), MultipleDefinition(Vec>, ZirExpressionList<'ast, T>), } -impl<'ast, T: fmt::Debug> fmt::Debug for ZirStatement<'ast, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - ZirStatement::Return(ref exprs) => { - write!(f, "Return(")?; - for (i, expr) in exprs.iter().enumerate() { - write!(f, "{:?}", expr)?; - if i < exprs.len() - 1 { - write!(f, ", ")?; - } - } - write!(f, ")") - } - ZirStatement::Definition(ref consequence, ref alternative) => { - write!(f, "Definition({:?}, {:?})", consequence, alternative) - } - ZirStatement::IfElse(ref condition, ref lhs, ref rhs) => { - write!(f, "IfElse({:?}, {:?}, {:?})", condition, lhs, rhs) - } - ZirStatement::Assertion(ref e) => write!(f, "Assertion({:?})", e), - ZirStatement::MultipleDefinition(ref lhs, ref rhs) => { - write!(f, "MultipleDefinition({:?}, {:?})", lhs, rhs) - } - } - } -} - impl<'ast, T: fmt::Display> fmt::Display for ZirStatement<'ast, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { @@ -158,7 +132,15 @@ impl<'ast, T: fmt::Display> fmt::Display for ZirStatement<'ast, T> { .join("\n") ) } - ZirStatement::Assertion(ref e) => write!(f, "assert({})", e), + ZirStatement::Assertion(ref e, ref metadata) => { + write!(f, "assert({}", e)?; + let metadata = metadata.as_ref().unwrap(); + if metadata.message.is_some() { + write!(f, ", \"{}\")", metadata.message.as_ref().unwrap()) + } else { + write!(f, ")") + } + } ZirStatement::MultipleDefinition(ref ids, ref rhs) => { for (i, id) in ids.iter().enumerate() { write!(f, "{}", id)?; diff --git a/zokrates_core/src/zir/result_folder.rs b/zokrates_core/src/zir/result_folder.rs index 791e16ba..0b566c9c 100644 --- a/zokrates_core/src/zir/result_folder.rs +++ b/zokrates_core/src/zir/result_folder.rs @@ -137,7 +137,7 @@ pub fn fold_statement<'ast, T: Field, F: ResultFolder<'ast, T>>( .flatten() .collect(), ), - ZirStatement::Assertion(e) => ZirStatement::Assertion(f.fold_boolean_expression(e)?), + ZirStatement::Assertion(e, m) => ZirStatement::Assertion(f.fold_boolean_expression(e)?, m), ZirStatement::MultipleDefinition(variables, elist) => ZirStatement::MultipleDefinition( variables .into_iter() diff --git a/zokrates_core_test/tests/tests/arrays/identity.json b/zokrates_core_test/tests/tests/arrays/identity.json index 62fa6ec4..2b3bfa95 100644 --- a/zokrates_core_test/tests/tests/arrays/identity.json +++ b/zokrates_core_test/tests/tests/arrays/identity.json @@ -31,7 +31,7 @@ "UnsatisfiedConstraint": { "left": "4", "right": "2", - "message": "Argument bitness check failed" + "error": "ArgumentBitness" } } } diff --git a/zokrates_core_test/tests/tests/arrays/select.json b/zokrates_core_test/tests/tests/arrays/select.json index fff4f17e..d48fbf75 100644 --- a/zokrates_core_test/tests/tests/arrays/select.json +++ b/zokrates_core_test/tests/tests/arrays/select.json @@ -42,7 +42,7 @@ "UnsatisfiedConstraint": { "left": "1", "right": "0", - "message": "Out of bounds array access" + "error": "SelectRangeCheck" } } } diff --git a/zokrates_core_test/tests/tests/assert_one.json b/zokrates_core_test/tests/tests/assert_one.json index 290e69e8..3e4f785c 100644 --- a/zokrates_core_test/tests/tests/assert_one.json +++ b/zokrates_core_test/tests/tests/assert_one.json @@ -11,7 +11,9 @@ "UnsatisfiedConstraint": { "left": "0", "right": "1", - "message": "User assertion failed" + "error": { + "Source": "Assertion failed at ./tests/tests/assert_one.zok:2:2" + } } } } diff --git a/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json b/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json index 89c37f17..1e7ef278 100644 --- a/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json +++ b/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json @@ -13,7 +13,9 @@ "UnsatisfiedConstraint": { "left": "0", "right": "1", - "message": "User assertion failed" + "error": { + "Source": "Assertion failed at ./tests/tests/panics/conditional_bound_throw.zok:2:5" + } } } } @@ -29,7 +31,9 @@ "UnsatisfiedConstraint": { "left": "1", "right": "0", - "message": "User assertion failed" + "error": { + "Source": "Assertion failed at ./tests/tests/panics/conditional_bound_throw.zok:2:5" + } } } } @@ -45,7 +49,9 @@ "UnsatisfiedConstraint": { "left": "2", "right": "0", - "message": "User assertion failed" + "error": { + "Source": "Assertion failed at ./tests/tests/panics/conditional_bound_throw.zok:2:5" + } } } } diff --git a/zokrates_core_test/tests/tests/panics/deep_branch_no_isolation.json b/zokrates_core_test/tests/tests/panics/deep_branch_no_isolation.json index 64497465..952bfff2 100644 --- a/zokrates_core_test/tests/tests/panics/deep_branch_no_isolation.json +++ b/zokrates_core_test/tests/tests/panics/deep_branch_no_isolation.json @@ -13,7 +13,9 @@ "UnsatisfiedConstraint": { "left": "0", "right": "1", - "message": "User assertion failed" + "error": { + "Source": "Assertion failed at ./tests/tests/panics/deep_branch.zok:2:5" + } } } } diff --git a/zokrates_core_test/tests/tests/panics/internal_panic_no_isolation.json b/zokrates_core_test/tests/tests/panics/internal_panic_no_isolation.json index df455520..fb1f8c58 100644 --- a/zokrates_core_test/tests/tests/panics/internal_panic_no_isolation.json +++ b/zokrates_core_test/tests/tests/panics/internal_panic_no_isolation.json @@ -25,7 +25,7 @@ "UnsatisfiedConstraint": { "left": "0", "right": "1", - "message": "Division by zero" + "error": "Inverse" } } } diff --git a/zokrates_core_test/tests/tests/panics/loop_bound.json b/zokrates_core_test/tests/tests/panics/loop_bound.json index cddac312..fe123a72 100644 --- a/zokrates_core_test/tests/tests/panics/loop_bound.json +++ b/zokrates_core_test/tests/tests/panics/loop_bound.json @@ -13,7 +13,9 @@ "UnsatisfiedConstraint": { "left": "0", "right": "1", - "message": "User assertion failed" + "error": { + "Source": "Assertion failed at ./tests/tests/panics/loop_bound.zok:2:3" + } } } } diff --git a/zokrates_core_test/tests/tests/panics/panic_isolation.json b/zokrates_core_test/tests/tests/panics/panic_isolation.json index 1dc70fd5..6d7da952 100644 --- a/zokrates_core_test/tests/tests/panics/panic_isolation.json +++ b/zokrates_core_test/tests/tests/panics/panic_isolation.json @@ -20,7 +20,9 @@ "UnsatisfiedConstraint": { "left": "1", "right": "21888242871839275222246405745257275088548364400416034343698204186575808495577", - "message": "User assertion failed" + "error": { + "Source": "Assertion failed at ./tests/tests/panics/panic_isolation.zok:18:5" + } } } } diff --git a/zokrates_core_test/tests/tests/panics/panic_no_isolation.json b/zokrates_core_test/tests/tests/panics/panic_no_isolation.json index 063cb533..9feb6d3f 100644 --- a/zokrates_core_test/tests/tests/panics/panic_no_isolation.json +++ b/zokrates_core_test/tests/tests/panics/panic_no_isolation.json @@ -20,7 +20,9 @@ "UnsatisfiedConstraint": { "left": "1", "right": "0", - "message": "User assertion failed" + "error": { + "Source": "Assertion failed at ./tests/tests/panics/panic_isolation.zok:14:5" + } } } } diff --git a/zokrates_core_test/tests/tests/structs/identity.json b/zokrates_core_test/tests/tests/structs/identity.json index cce1788d..26cc4b51 100644 --- a/zokrates_core_test/tests/tests/structs/identity.json +++ b/zokrates_core_test/tests/tests/structs/identity.json @@ -31,7 +31,7 @@ "UnsatisfiedConstraint": { "left": "9", "right": "3", - "message": "Argument bitness check failed" + "error": "ArgumentBitness" } } } diff --git a/zokrates_parser/src/zokrates.pest b/zokrates_parser/src/zokrates.pest index ce7499e7..e83b091e 100644 --- a/zokrates_parser/src/zokrates.pest +++ b/zokrates_parser/src/zokrates.pest @@ -3,13 +3,14 @@ file = { SOI ~ NEWLINE* ~ pragma? ~ NEWLINE* ~ symbol_declaration* ~ EOI } pragma = { "#pragma" ~ "curve" ~ curve } curve = @{ (ASCII_ALPHANUMERIC | "_") * } +string = @{(!"\"" ~ ANY)*} +quoted_string = _{ "\"" ~ string ~ "\"" } symbol_declaration = { (import_directive | ty_struct_definition | const_definition | function_definition) ~ NEWLINE* } import_directive = { main_import_directive | from_import_directive } -from_import_directive = { "from" ~ "\"" ~ import_source ~ "\"" ~ "import" ~ import_symbol_list ~ NEWLINE* } -main_import_directive = { "import" ~ "\"" ~ import_source ~ "\"" ~ ("as" ~ identifier)? ~ NEWLINE+ } -import_source = @{(!"\"" ~ ANY)*} +from_import_directive = { "from" ~ quoted_string ~ "import" ~ import_symbol_list ~ NEWLINE* } +main_import_directive = { "import" ~ quoted_string ~ ("as" ~ identifier)? ~ NEWLINE+ } import_symbol = { identifier ~ ("as" ~ identifier)? } import_symbol_list = _{ import_symbol ~ ("," ~ import_symbol)* } function_definition = {"def" ~ identifier ~ constant_generics_declaration? ~ "(" ~ parameter_list ~ ")" ~ return_types ~ ":" ~ NEWLINE* ~ statement* } @@ -55,7 +56,7 @@ statement = { (return_statement // does not require subsequent newline iteration_statement = { "for" ~ ty ~ identifier ~ "in" ~ expression ~ ".." ~ expression ~ "do" ~ NEWLINE* ~ statement* ~ "endfor"} return_statement = { "return" ~ expression_list} definition_statement = { typed_identifier_or_assignee_list ~ "=" ~ expression } // declare and assign, so only identifiers are allowed, unlike `assignment_statement` -expression_statement = {"assert" ~ "(" ~ expression ~ ")"} +expression_statement = {"assert" ~ "(" ~ expression ~ ("," ~ quoted_string)? ~ ")"} typed_identifier_or_assignee_list = _{ typed_identifier_or_assignee ~ ("," ~ typed_identifier_or_assignee)* } typed_identifier_or_assignee = { typed_identifier | assignee } // we don't use { ty? ~ identifier } as with a single token, it gets parsed as `ty` but we want `identifier` diff --git a/zokrates_pest_ast/src/lib.rs b/zokrates_pest_ast/src/lib.rs index 22b4d0d7..fb6e8096 100644 --- a/zokrates_pest_ast/src/lib.rs +++ b/zokrates_pest_ast/src/lib.rs @@ -13,7 +13,7 @@ pub use ast::{ CallAccess, ConstantDefinition, ConstantGenericValue, DecimalLiteralExpression, DecimalNumber, DecimalSuffix, DefinitionStatement, ExplicitGenerics, Expression, FieldType, File, FromExpression, FunctionDefinition, HexLiteralExpression, HexNumberExpression, - IdentifierExpression, ImportDirective, ImportSource, ImportSymbol, InlineArrayExpression, + IdentifierExpression, ImportDirective, ImportSymbol, InlineArrayExpression, InlineStructExpression, InlineStructMember, IterationStatement, LiteralExpression, Parameter, PostfixExpression, Range, RangeOrExpression, ReturnStatement, Span, Spread, SpreadOrExpression, Statement, StructDefinition, StructField, SymbolDeclaration, TernaryExpression, ToExpression, @@ -194,7 +194,7 @@ mod ast { #[derive(Debug, FromPest, PartialEq, Clone)] #[pest_ast(rule(Rule::main_import_directive))] pub struct MainImportDirective<'ast> { - pub source: ImportSource<'ast>, + pub source: AnyString<'ast>, pub alias: Option>, #[pest_ast(outer())] pub span: Span<'ast>, @@ -212,21 +212,12 @@ mod ast { #[derive(Debug, FromPest, PartialEq, Clone)] #[pest_ast(rule(Rule::from_import_directive))] pub struct FromImportDirective<'ast> { - pub source: ImportSource<'ast>, + pub source: AnyString<'ast>, pub symbols: Vec>, #[pest_ast(outer())] pub span: Span<'ast>, } - #[derive(Debug, FromPest, PartialEq, Clone)] - #[pest_ast(rule(Rule::import_source))] - pub struct ImportSource<'ast> { - #[pest_ast(outer(with(span_into_str)))] - pub value: String, - #[pest_ast(outer())] - pub span: Span<'ast>, - } - #[derive(Debug, FromPest, PartialEq, Clone)] #[pest_ast(rule(Rule::ty))] pub enum Type<'ast> { @@ -357,10 +348,20 @@ mod ast { pub span: Span<'ast>, } + #[derive(Debug, FromPest, PartialEq, Clone)] + #[pest_ast(rule(Rule::string))] + pub struct AnyString<'ast> { + #[pest_ast(outer(with(span_into_str)))] + pub value: String, + #[pest_ast(outer())] + pub span: Span<'ast>, + } + #[derive(Debug, FromPest, PartialEq, Clone)] #[pest_ast(rule(Rule::expression_statement))] pub struct AssertionStatement<'ast> { pub expression: Expression<'ast>, + pub message: Option>, #[pest_ast(outer())] pub span: Span<'ast>, } @@ -1076,7 +1077,7 @@ mod tests { pragma: None, declarations: vec![ SymbolDeclaration::Import(ImportDirective::Main(MainImportDirective { - source: ImportSource { + source: AnyString { value: String::from("foo"), span: Span::new(&source, 8, 11).unwrap() }, @@ -1137,7 +1138,7 @@ mod tests { pragma: None, declarations: vec![ SymbolDeclaration::Import(ImportDirective::Main(MainImportDirective { - source: ImportSource { + source: AnyString { value: String::from("foo"), span: Span::new(&source, 8, 11).unwrap() }, @@ -1222,7 +1223,7 @@ mod tests { pragma: None, declarations: vec![ SymbolDeclaration::Import(ImportDirective::Main(MainImportDirective { - source: ImportSource { + source: AnyString { value: String::from("foo"), span: Span::new(&source, 8, 11).unwrap() }, From 7cc8279460021ddab517aed3afc4b407e08efef5 Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 20 Sep 2021 18:24:38 +0200 Subject: [PATCH 02/23] add changelog --- changelogs/unreleased/1012-dark64 | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/1012-dark64 diff --git a/changelogs/unreleased/1012-dark64 b/changelogs/unreleased/1012-dark64 new file mode 100644 index 00000000..7c55ef91 --- /dev/null +++ b/changelogs/unreleased/1012-dark64 @@ -0,0 +1 @@ +Add optional message to assert statement \ No newline at end of file From 302f561993a3f76124aef59c39a81646248aac98 Mon Sep 17 00:00:00 2001 From: dark64 Date: Mon, 20 Sep 2021 18:30:03 +0200 Subject: [PATCH 03/23] fix indentation --- .../tests/tests/assert_one.json | 40 +++++++++---------- .../conditional_bound_throw_no_isolation.json | 38 +++++++++--------- .../panics/deep_branch_no_isolation.json | 14 +++---- .../panics/internal_panic_no_isolation.json | 20 +++++----- .../tests/tests/panics/loop_bound.json | 20 +++++----- .../tests/tests/panics/panic_isolation.json | 30 +++++++------- .../tests/panics/panic_no_isolation.json | 14 +++---- 7 files changed, 88 insertions(+), 88 deletions(-) diff --git a/zokrates_core_test/tests/tests/assert_one.json b/zokrates_core_test/tests/tests/assert_one.json index 3e4f785c..7791e6bb 100644 --- a/zokrates_core_test/tests/tests/assert_one.json +++ b/zokrates_core_test/tests/tests/assert_one.json @@ -1,22 +1,22 @@ { - "entry_point": "./tests/tests/assert_one.zok", - "curves": ["Bn128", "Bls12_381", "Bls12_377", "Bw6_761"], - "tests": [ - { - "input": { - "values": ["0"] - }, - "output": { - "Err": { - "UnsatisfiedConstraint": { - "left": "0", - "right": "1", - "error": { - "Source": "Assertion failed at ./tests/tests/assert_one.zok:2:2" - } - } - } - } - } - ] + "entry_point": "./tests/tests/assert_one.zok", + "curves": ["Bn128", "Bls12_381", "Bls12_377", "Bw6_761"], + "tests": [ + { + "input": { + "values": ["0"] + }, + "output": { + "Err": { + "UnsatisfiedConstraint": { + "left": "0", + "right": "1", + "error": { + "Source": "Assertion failed at ./tests/tests/assert_one.zok:2:2" + } + } + } + } + } + ] } diff --git a/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json b/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json index 1e7ef278..4402beb1 100644 --- a/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json +++ b/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json @@ -1,7 +1,7 @@ { "entry_point": "./tests/tests/panics/conditional_bound_throw.zok", "curves": ["Bn128"], - "tests": [ + "tests": [ { "input": { "values": [ @@ -9,15 +9,15 @@ ] }, "output": { - "Err": { - "UnsatisfiedConstraint": { - "left": "0", - "right": "1", + "Err": { + "UnsatisfiedConstraint": { + "left": "0", + "right": "1", "error": { "Source": "Assertion failed at ./tests/tests/panics/conditional_bound_throw.zok:2:5" } - } - } + } + } } }, { @@ -27,15 +27,15 @@ ] }, "output": { - "Err": { - "UnsatisfiedConstraint": { - "left": "1", - "right": "0", + "Err": { + "UnsatisfiedConstraint": { + "left": "1", + "right": "0", "error": { "Source": "Assertion failed at ./tests/tests/panics/conditional_bound_throw.zok:2:5" } - } - } + } + } } }, { @@ -45,15 +45,15 @@ ] }, "output": { - "Err": { - "UnsatisfiedConstraint": { - "left": "2", - "right": "0", + "Err": { + "UnsatisfiedConstraint": { + "left": "2", + "right": "0", "error": { "Source": "Assertion failed at ./tests/tests/panics/conditional_bound_throw.zok:2:5" } - } - } + } + } } } ] diff --git a/zokrates_core_test/tests/tests/panics/deep_branch_no_isolation.json b/zokrates_core_test/tests/tests/panics/deep_branch_no_isolation.json index 952bfff2..d89b6a1d 100644 --- a/zokrates_core_test/tests/tests/panics/deep_branch_no_isolation.json +++ b/zokrates_core_test/tests/tests/panics/deep_branch_no_isolation.json @@ -1,7 +1,7 @@ { "entry_point": "./tests/tests/panics/deep_branch.zok", "curves": ["Bn128"], - "tests": [ + "tests": [ { "input": { "values": [ @@ -9,15 +9,15 @@ ] }, "output": { - "Err": { - "UnsatisfiedConstraint": { - "left": "0", - "right": "1", + "Err": { + "UnsatisfiedConstraint": { + "left": "0", + "right": "1", "error": { "Source": "Assertion failed at ./tests/tests/panics/deep_branch.zok:2:5" } - } - } + } + } } } ] diff --git a/zokrates_core_test/tests/tests/panics/internal_panic_no_isolation.json b/zokrates_core_test/tests/tests/panics/internal_panic_no_isolation.json index fb1f8c58..46e3e275 100644 --- a/zokrates_core_test/tests/tests/panics/internal_panic_no_isolation.json +++ b/zokrates_core_test/tests/tests/panics/internal_panic_no_isolation.json @@ -1,7 +1,7 @@ { "entry_point": "./tests/tests/panics/internal_panic.zok", "curves": ["Bn128"], - "tests": [ + "tests": [ { "input": { "values": [ @@ -9,9 +9,9 @@ ] }, "output": { - "Ok": { - "values": ["1"] - } + "Ok": { + "values": ["1"] + } } }, { @@ -21,13 +21,13 @@ ] }, "output": { - "Err": { - "UnsatisfiedConstraint": { - "left": "0", - "right": "1", + "Err": { + "UnsatisfiedConstraint": { + "left": "0", + "right": "1", "error": "Inverse" - } - } + } + } } } ] diff --git a/zokrates_core_test/tests/tests/panics/loop_bound.json b/zokrates_core_test/tests/tests/panics/loop_bound.json index fe123a72..a3599f3b 100644 --- a/zokrates_core_test/tests/tests/panics/loop_bound.json +++ b/zokrates_core_test/tests/tests/panics/loop_bound.json @@ -1,7 +1,7 @@ { "entry_point": "./tests/tests/panics/loop_bound.zok", "curves": ["Bn128", "Bls12_381", "Bls12_377", "Bw6_761"], - "tests": [ + "tests": [ { "input": { "values": [ @@ -9,15 +9,15 @@ ] }, "output": { - "Err": { - "UnsatisfiedConstraint": { - "left": "0", - "right": "1", + "Err": { + "UnsatisfiedConstraint": { + "left": "0", + "right": "1", "error": { "Source": "Assertion failed at ./tests/tests/panics/loop_bound.zok:2:3" } - } - } + } + } } }, { @@ -27,9 +27,9 @@ ] }, "output": { - "Ok": { - "values": [] - } + "Ok": { + "values": [] + } } } ] diff --git a/zokrates_core_test/tests/tests/panics/panic_isolation.json b/zokrates_core_test/tests/tests/panics/panic_isolation.json index 6d7da952..703b0dea 100644 --- a/zokrates_core_test/tests/tests/panics/panic_isolation.json +++ b/zokrates_core_test/tests/tests/panics/panic_isolation.json @@ -5,7 +5,7 @@ "isolate_branches": true }, "curves": ["Bn128"], - "tests": [ + "tests": [ { "input": { "values": [ @@ -16,15 +16,15 @@ ] }, "output": { - "Err": { - "UnsatisfiedConstraint": { - "left": "1", - "right": "21888242871839275222246405745257275088548364400416034343698204186575808495577", + "Err": { + "UnsatisfiedConstraint": { + "left": "1", + "right": "21888242871839275222246405745257275088548364400416034343698204186575808495577", "error": { "Source": "Assertion failed at ./tests/tests/panics/panic_isolation.zok:18:5" } - } - } + } + } } }, { @@ -37,14 +37,14 @@ ] }, "output": { - "Ok": { - "values": [ + "Ok": { + "values": [ "1", "1", "1", "1" - ] - } + ] + } } }, { @@ -57,14 +57,14 @@ ] }, "output": { - "Ok": { - "values": [ + "Ok": { + "values": [ "0", "2", "2", "0" - ] - } + ] + } } } ] diff --git a/zokrates_core_test/tests/tests/panics/panic_no_isolation.json b/zokrates_core_test/tests/tests/panics/panic_no_isolation.json index 9feb6d3f..f2b562e8 100644 --- a/zokrates_core_test/tests/tests/panics/panic_no_isolation.json +++ b/zokrates_core_test/tests/tests/panics/panic_no_isolation.json @@ -5,7 +5,7 @@ "isolate_branches": false }, "curves": ["Bn128"], - "tests": [ + "tests": [ { "input": { "values": [ @@ -16,15 +16,15 @@ ] }, "output": { - "Err": { - "UnsatisfiedConstraint": { - "left": "1", - "right": "0", + "Err": { + "UnsatisfiedConstraint": { + "left": "1", + "right": "0", "error": { "Source": "Assertion failed at ./tests/tests/panics/panic_isolation.zok:14:5" } - } - } + } + } } } ] From 018e5bf29ea5704a83f244e4992556e91df1f9a3 Mon Sep 17 00:00:00 2001 From: dark64 Date: Thu, 23 Sep 2021 13:26:15 +0200 Subject: [PATCH 04/23] cleanup --- zokrates_core/src/static_analysis/propagation.rs | 7 ++++--- zokrates_core/src/static_analysis/uint_optimizer.rs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/zokrates_core/src/static_analysis/propagation.rs b/zokrates_core/src/static_analysis/propagation.rs index 0fb654cf..a097a289 100644 --- a/zokrates_core/src/static_analysis/propagation.rs +++ b/zokrates_core/src/static_analysis/propagation.rs @@ -610,17 +610,18 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { Ok(statements) } - TypedStatement::Assertion(e, s) => { + TypedStatement::Assertion(e, metadata) => { let e_str = e.to_string(); let expr = self.fold_boolean_expression(e)?; match expr { BooleanExpression::Value(v) if !v => Err(Error::AssertionFailed(format!( "{}: ({})", - s.map(|m| m.to_string()) + metadata + .map(|m| m.to_string()) .unwrap_or_else(|| "Assertion failed".to_string()), e_str, ))), - _ => Ok(vec![TypedStatement::Assertion(expr, s)]), + _ => Ok(vec![TypedStatement::Assertion(expr, metadata)]), } } s @ TypedStatement::PushCallLog(..) => Ok(vec![s]), diff --git a/zokrates_core/src/static_analysis/uint_optimizer.rs b/zokrates_core/src/static_analysis/uint_optimizer.rs index 4c0a26c6..7219b652 100644 --- a/zokrates_core/src/static_analysis/uint_optimizer.rs +++ b/zokrates_core/src/static_analysis/uint_optimizer.rs @@ -531,7 +531,7 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { } } } - ZirStatement::Assertion(BooleanExpression::UintEq(box left, box right), m) => { + ZirStatement::Assertion(BooleanExpression::UintEq(box left, box right), metadata) => { let left = self.fold_uint_expression(left); let right = self.fold_uint_expression(right); @@ -541,7 +541,7 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { vec![ZirStatement::Assertion( BooleanExpression::UintEq(box left, box right), - m, + metadata, )] } s => fold_statement(self, s), From f41639864a53860e4f3ced12ac5d61698d739cfc Mon Sep 17 00:00:00 2001 From: dark64 Date: Tue, 28 Sep 2021 14:23:29 +0200 Subject: [PATCH 05/23] minor refactor --- zokrates_core/src/absy/mod.rs | 7 +++---- zokrates_core/src/typed_absy/mod.rs | 14 ++++++-------- zokrates_core/src/zir/mod.rs | 7 +++---- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/zokrates_core/src/absy/mod.rs b/zokrates_core/src/absy/mod.rs index 31150df4..14b67f4a 100644 --- a/zokrates_core/src/absy/mod.rs +++ b/zokrates_core/src/absy/mod.rs @@ -357,10 +357,9 @@ impl<'ast> fmt::Display for Statement<'ast> { Statement::Definition(ref lhs, ref rhs) => write!(f, "{} = {}", lhs, rhs), Statement::Assertion(ref e, ref message) => { write!(f, "assert({}", e)?; - if message.is_some() { - write!(f, ", \"{}\")", message.as_ref().unwrap()) - } else { - write!(f, ")") + match message { + Some(m) => write!(f, ", \"{}\")", m), + None => write!(f, ")"), } } Statement::For(ref var, ref start, ref stop, ref list) => { diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index 3b4a9039..c1286150 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -496,10 +496,9 @@ pub struct AssertionMetadata { impl fmt::Display for AssertionMetadata { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Assertion failed at {}:{}", self.file, self.position)?; - if self.message.is_some() { - write!(f, ": \"{}\"", self.message.as_ref().unwrap()) - } else { - write!(f, "") + match &self.message { + Some(m) => write!(f, ": \"{}\"", m), + None => write!(f, ""), } } } @@ -562,10 +561,9 @@ impl<'ast, T: fmt::Display> fmt::Display for TypedStatement<'ast, T> { TypedStatement::Assertion(ref e, ref metadata) => { write!(f, "assert({}", e)?; let metadata = metadata.as_ref().unwrap(); - if metadata.message.is_some() { - write!(f, ", \"{}\")", metadata.message.as_ref().unwrap()) - } else { - write!(f, ")") + match &metadata.message { + Some(m) => write!(f, ", \"{}\")", m), + None => write!(f, ")"), } } TypedStatement::For(ref var, ref start, ref stop, ref list) => { diff --git a/zokrates_core/src/zir/mod.rs b/zokrates_core/src/zir/mod.rs index bc54c58a..01abcaa6 100644 --- a/zokrates_core/src/zir/mod.rs +++ b/zokrates_core/src/zir/mod.rs @@ -135,10 +135,9 @@ impl<'ast, T: fmt::Display> fmt::Display for ZirStatement<'ast, T> { ZirStatement::Assertion(ref e, ref metadata) => { write!(f, "assert({}", e)?; let metadata = metadata.as_ref().unwrap(); - if metadata.message.is_some() { - write!(f, ", \"{}\")", metadata.message.as_ref().unwrap()) - } else { - write!(f, ")") + match &metadata.message { + Some(m) => write!(f, ", \"{}\")", m), + None => write!(f, ")"), } } ZirStatement::MultipleDefinition(ref ids, ref rhs) => { From fe6a334997795932fa0caf59b9b9295317aa23f8 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 29 Sep 2021 15:10:31 +0200 Subject: [PATCH 06/23] fix interpreter error display --- zokrates_core/src/ir/interpreter.rs | 31 ++++------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/zokrates_core/src/ir/interpreter.rs b/zokrates_core/src/ir/interpreter.rs index be02e8b1..d4c06c8c 100644 --- a/zokrates_core/src/ir/interpreter.rs +++ b/zokrates_core/src/ir/interpreter.rs @@ -55,8 +55,6 @@ impl Interpreter { let rhs_value = lin.evaluate(&witness).unwrap(); if lhs_value != rhs_value { return Err(Error::UnsatisfiedConstraint { - left: lhs_value.to_dec_string(), - right: rhs_value.to_dec_string(), error: error.to_owned(), }); } @@ -280,37 +278,16 @@ impl QuadComb { #[derive(PartialEq, Serialize, Deserialize, Clone)] pub enum Error { - UnsatisfiedConstraint { - left: String, - right: String, - error: Option, - }, + UnsatisfiedConstraint { error: Option }, Solver, - WrongInputCount { - expected: usize, - received: usize, - }, + WrongInputCount { expected: usize, received: usize }, } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - Error::UnsatisfiedConstraint { - ref left, - ref right, - ref error, - } => { - write!( - f, - "{}", - error - .as_ref() - .map(|m| m.to_string()) - .unwrap_or_else(|| format!( - "Unsatisfied constraint: expected {} to equal {}", - left, right - )) - )?; + Error::UnsatisfiedConstraint { ref error } => { + write!(f, "{}", error.as_ref().map(|m| m.to_string()).unwrap())?; match error { Some(e) if e.is_malicious() => { From 6d7482f347050d2e7bf8178101a52c036b73634e Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 29 Sep 2021 15:14:17 +0200 Subject: [PATCH 07/23] use expect instead of unwrap --- zokrates_core/src/ir/interpreter.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zokrates_core/src/ir/interpreter.rs b/zokrates_core/src/ir/interpreter.rs index d4c06c8c..ba256c88 100644 --- a/zokrates_core/src/ir/interpreter.rs +++ b/zokrates_core/src/ir/interpreter.rs @@ -287,7 +287,14 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Error::UnsatisfiedConstraint { ref error } => { - write!(f, "{}", error.as_ref().map(|m| m.to_string()).unwrap())?; + write!( + f, + "{}", + error + .as_ref() + .map(|m| m.to_string()) + .expect("Found an unsatisfied constraint without an attached error.") + )?; match error { Some(e) if e.is_malicious() => { From c8ddc8913e8e56b5f632a6c22f55a5d389c5dc69 Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 5 Oct 2021 19:56:43 +0300 Subject: [PATCH 08/23] enable general postfix expressions in the parser, move function name check to semantics --- zokrates_core/src/absy/from_ast.rs | 50 +++++++++++----------- zokrates_core/src/absy/mod.rs | 4 +- zokrates_core/src/absy/types.rs | 2 - zokrates_core/src/semantics.rs | 66 +++++++++++++++++++++++------ zokrates_core/src/typed_absy/mod.rs | 4 +- zokrates_parser/src/zokrates.pest | 6 +-- zokrates_pest_ast/src/lib.rs | 47 +++++++++++++------- 7 files changed, 118 insertions(+), 61 deletions(-) diff --git a/zokrates_core/src/absy/from_ast.rs b/zokrates_core/src/absy/from_ast.rs index a968b9c2..48db883f 100644 --- a/zokrates_core/src/absy/from_ast.rs +++ b/zokrates_core/src/absy/from_ast.rs @@ -599,17 +599,18 @@ impl<'ast> From> for absy::ExpressionNode<'ast> { fn from(expression: pest::PostfixExpression<'ast>) -> absy::ExpressionNode<'ast> { use crate::absy::NodeValue; - let id_str = expression.id.span.as_str(); - let id = absy::ExpressionNode::from(expression.id); + let base = absy::ExpressionNode::from(*expression.base); // pest::PostFixExpression contains an array of "accesses": `a(34)[42]` is represented as `[a, [Call(34), Select(42)]]`, but absy::ExpressionNode // is recursive, so it is `Select(Call(a, 34), 42)`. We apply this transformation here - // we start with the id, and we fold the array of accesses by wrapping the current value - expression.accesses.into_iter().fold(id, |acc, a| match a { - pest::Access::Call(a) => match acc.value { - absy::Expression::Identifier(_) => absy::Expression::FunctionCall( - &id_str, + // we start with the base, and we fold the array of accesses by wrapping the current value + expression + .accesses + .into_iter() + .fold(base, |acc, a| match a { + pest::Access::Call(a) => absy::Expression::FunctionCall( + Box::new(acc), a.explicit_generics.map(|explicit_generics| { explicit_generics .values @@ -630,18 +631,17 @@ impl<'ast> From> for absy::ExpressionNode<'ast> { .into_iter() .map(absy::ExpressionNode::from) .collect(), - ), - e => unimplemented!("only identifiers are callable, found \"{}\"", e), - } - .span(a.span), - pest::Access::Select(a) => { - absy::Expression::Select(box acc, box absy::RangeOrExpression::from(a.expression)) - .span(a.span) - } - pest::Access::Member(m) => { - absy::Expression::Member(box acc, box m.id.span.as_str()).span(m.span) - } - }) + ) + .span(a.span), + pest::Access::Select(a) => absy::Expression::Select( + box acc, + box absy::RangeOrExpression::from(a.expression), + ) + .span(a.span), + pest::Access::Member(m) => { + absy::Expression::Member(box acc, box m.id.span.as_str()).span(m.span) + } + }) } } @@ -1082,7 +1082,7 @@ mod tests { "a(3)[4]", absy::Expression::Select( box absy::Expression::FunctionCall( - "a", + box absy::Expression::Identifier("a").mock(), None, vec![absy::Expression::IntConstant(3usize.into()).into()], ) @@ -1097,7 +1097,7 @@ mod tests { absy::Expression::Select( box absy::Expression::Select( box absy::Expression::FunctionCall( - "a", + box absy::Expression::Identifier("a").mock(), None, vec![absy::Expression::IntConstant(3usize.into()).into()], ) @@ -1195,10 +1195,10 @@ mod tests { span: span.clone(), })], expression: pest::Expression::Postfix(pest::PostfixExpression { - id: pest::IdentifierExpression { + base: box pest::Expression::Identifier(pest::IdentifierExpression { value: String::from("foo"), span: span.clone(), - }, + }), accesses: vec![pest::Access::Call(pest::CallAccess { explicit_generics: None, arguments: pest::Arguments { @@ -1248,10 +1248,10 @@ mod tests { }), ], expression: pest::Expression::Postfix(pest::PostfixExpression { - id: pest::IdentifierExpression { + base: box pest::Expression::Identifier(pest::IdentifierExpression { value: String::from("foo"), span: span.clone(), - }, + }), accesses: vec![pest::Access::Call(pest::CallAccess { explicit_generics: None, arguments: pest::Arguments { diff --git a/zokrates_core/src/absy/mod.rs b/zokrates_core/src/absy/mod.rs index 70fc76d0..efab2fa8 100644 --- a/zokrates_core/src/absy/mod.rs +++ b/zokrates_core/src/absy/mod.rs @@ -13,7 +13,7 @@ pub mod variable; pub use crate::absy::node::{Node, NodeValue}; pub use crate::absy::parameter::{Parameter, ParameterNode}; -use crate::absy::types::{FunctionIdentifier, UnresolvedSignature, UnresolvedType, UserTypeId}; +use crate::absy::types::{UnresolvedSignature, UnresolvedType, UserTypeId}; pub use crate::absy::variable::{Variable, VariableNode}; use crate::embed::FlatEmbed; use std::path::{Path, PathBuf}; @@ -479,7 +479,7 @@ pub enum Expression<'ast> { Box>, ), FunctionCall( - FunctionIdentifier<'ast>, + Box>, Option>>>, Vec>, ), diff --git a/zokrates_core/src/absy/types.rs b/zokrates_core/src/absy/types.rs index a3582076..86409591 100644 --- a/zokrates_core/src/absy/types.rs +++ b/zokrates_core/src/absy/types.rs @@ -56,8 +56,6 @@ impl<'ast> UnresolvedType<'ast> { } } -pub type FunctionIdentifier<'ast> = &'ast str; - pub use self::signature::UnresolvedSignature; mod signature { diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index d4b224c3..008df9c4 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -1764,7 +1764,19 @@ impl<'ast, T: Field> Checker<'ast, T> { Statement::MultipleDefinition(assignees, rhs) => { match rhs.value { // Right side has to be a function call - Expression::FunctionCall(fun_id, generics, arguments) => { + Expression::FunctionCall(fun_id_expression, generics, arguments) => { + + let fun_id = match fun_id_expression.value { + Expression::Identifier(id) => Ok(id), + e => Err(vec![ErrorInner { + pos: Some(pos), + message: format!( + "Expected function in function call to be an identifier, found {}", + e + ), + }]) + }?; + // check the generic arguments, if any let generics_checked: Option>>> = generics .map(|generics| @@ -2318,7 +2330,18 @@ impl<'ast, T: Field> Checker<'ast, T> { Expression::U16Constant(n) => Ok(UExpressionInner::Value(n.into()).annotate(16).into()), Expression::U32Constant(n) => Ok(UExpressionInner::Value(n.into()).annotate(32).into()), Expression::U64Constant(n) => Ok(UExpressionInner::Value(n.into()).annotate(64).into()), - Expression::FunctionCall(fun_id, generics, arguments) => { + Expression::FunctionCall(fun_id_expression, generics, arguments) => { + let fun_id = match fun_id_expression.value { + Expression::Identifier(id) => Ok(id), + e => Err(ErrorInner { + pos: Some(pos), + message: format!( + "Expected function in function call to be an identifier, found `{}`", + e + ), + }), + }?; + // check the generic arguments, if any let generics_checked: Option>>> = generics .map(|generics| { @@ -4516,7 +4539,8 @@ mod tests { .mock(), Statement::MultipleDefinition( vec![Assignee::Identifier("a").mock()], - Expression::FunctionCall("foo", None, vec![]).mock(), + Expression::FunctionCall(box Expression::Identifier("foo").mock(), None, vec![]) + .mock(), ) .mock(), Statement::Return( @@ -4573,7 +4597,12 @@ mod tests { Statement::Assertion( Expression::Eq( box Expression::IntConstant(2usize.into()).mock(), - box Expression::FunctionCall("foo", None, vec![]).mock(), + box Expression::FunctionCall( + box Expression::Identifier("foo").mock(), + None, + vec![], + ) + .mock(), ) .mock(), ) @@ -4632,7 +4661,8 @@ mod tests { .mock(), Statement::MultipleDefinition( vec![Assignee::Identifier("a").mock()], - Expression::FunctionCall("foo", None, vec![]).mock(), + Expression::FunctionCall(box Expression::Identifier("foo").mock(), None, vec![]) + .mock(), ) .mock(), Statement::Return( @@ -4717,8 +4747,12 @@ mod tests { Assignee::Identifier("a").mock(), Assignee::Identifier("b").mock(), ], - Expression::FunctionCall("foo", None, vec![Expression::Identifier("x").mock()]) - .mock(), + Expression::FunctionCall( + box Expression::Identifier("foo").mock(), + None, + vec![Expression::Identifier("x").mock()], + ) + .mock(), ) .mock(), Statement::Return( @@ -4806,7 +4840,8 @@ mod tests { Assignee::Identifier("a").mock(), Assignee::Identifier("b").mock(), ], - Expression::FunctionCall("foo", None, vec![]).mock(), + Expression::FunctionCall(box Expression::Identifier("foo").mock(), None, vec![]) + .mock(), ) .mock(), Statement::Return( @@ -4921,7 +4956,8 @@ mod tests { ), ) .mock()], - Expression::FunctionCall("foo", None, vec![]).mock(), + Expression::FunctionCall(box Expression::Identifier("foo").mock(), None, vec![]) + .mock(), ) .mock(), Statement::Return( @@ -4973,7 +5009,12 @@ mod tests { Statement::Assertion( Expression::Eq( box Expression::IntConstant(1usize.into()).mock(), - box Expression::FunctionCall("foo", None, vec![]).mock(), + box Expression::FunctionCall( + box Expression::Identifier("foo").mock(), + None, + vec![], + ) + .mock(), ) .mock(), ) @@ -5071,7 +5112,8 @@ mod tests { Assignee::Identifier("a").mock(), Assignee::Identifier("b").mock(), ], - Expression::FunctionCall("foo", None, vec![]).mock(), + Expression::FunctionCall(box Expression::Identifier("foo").mock(), None, vec![]) + .mock(), ) .mock(), Statement::Return( @@ -6128,7 +6170,7 @@ mod tests { main.value.statements = vec![Statement::Return( ExpressionList { expressions: vec![Expression::FunctionCall( - "foo", + box Expression::Identifier("foo").mock(), None, vec![Expression::IntConstant(0usize.into()).mock()], ) diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index f9d40185..70faa133 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -1141,7 +1141,7 @@ impl<'ast, T> IntoIterator for ArrayValue<'ast, T> { } } -impl<'ast, T: Clone> ArrayValue<'ast, T> { +impl<'ast, T: Clone + fmt::Debug> ArrayValue<'ast, T> { fn expression_at_aux + Into>>( v: TypedExpressionOrSpread<'ast, T>, ) -> Vec>> { @@ -1181,7 +1181,7 @@ impl<'ast, T: Clone> ArrayValue<'ast, T> { ) -> Option> { self.0 .iter() - .map(|v| Self::expression_at_aux::(v.clone())) + .map(|v| dbg!(Self::expression_at_aux::(v.clone()))) .flatten() .take_while(|e| e.is_some()) .map(|e| e.unwrap()) diff --git a/zokrates_parser/src/zokrates.pest b/zokrates_parser/src/zokrates.pest index ce7499e7..a9d4da85 100644 --- a/zokrates_parser/src/zokrates.pest +++ b/zokrates_parser/src/zokrates.pest @@ -65,8 +65,9 @@ expression_list = _{(expression ~ ("," ~ expression)*)?} expression = { unaried_term ~ (op_binary ~ unaried_term)* } unaried_term = { op_unary? ~ powered_term } -powered_term = { term ~ (op_pow ~ exponent_expression)? } -term = { ("(" ~ expression ~ ")") | inline_struct_expression | conditional_expression | postfix_expression | primary_expression | inline_array_expression | array_initializer_expression } +powered_term = { postfixed_term ~ (op_pow ~ exponent_expression)? } +postfixed_term = { term ~ access* } +term = { ("(" ~ expression ~ ")") | inline_struct_expression | conditional_expression | primary_expression | inline_array_expression | array_initializer_expression } spread = { "..." ~ expression } range = { from_expression? ~ ".." ~ to_expression? } from_expression = { expression } @@ -74,7 +75,6 @@ to_expression = { expression } conditional_expression = { "if" ~ expression ~ "then" ~ expression ~ "else" ~ expression ~ "fi"} -postfix_expression = { identifier ~ access+ } // we force there to be at least one access, otherwise this matches single identifiers access = { array_access | call_access | member_access } array_access = { "[" ~ range_or_expression ~ "]" } call_access = { ("::" ~ explicit_generics)? ~ "(" ~ arguments ~ ")" } diff --git a/zokrates_pest_ast/src/lib.rs b/zokrates_pest_ast/src/lib.rs index 22b4d0d7..ae27e471 100644 --- a/zokrates_pest_ast/src/lib.rs +++ b/zokrates_pest_ast/src/lib.rs @@ -413,8 +413,8 @@ mod ast { Ternary(TernaryExpression<'ast>), Binary(BinaryExpression<'ast>), Unary(UnaryExpression<'ast>), - Postfix(PostfixExpression<'ast>), Identifier(IdentifierExpression<'ast>), + Postfix(PostfixExpression<'ast>), Literal(LiteralExpression<'ast>), InlineArray(InlineArrayExpression<'ast>), InlineStruct(InlineStructExpression<'ast>), @@ -427,16 +427,43 @@ mod ast { Expression(Expression<'ast>), InlineStruct(InlineStructExpression<'ast>), Ternary(TernaryExpression<'ast>), - Postfix(PostfixExpression<'ast>), Primary(PrimaryExpression<'ast>), InlineArray(InlineArrayExpression<'ast>), ArrayInitializer(ArrayInitializerExpression<'ast>), } + #[derive(Debug, FromPest, PartialEq, Clone)] + #[pest_ast(rule(Rule::postfixed_term))] + pub struct PostfixedTerm<'ast> { + pub base: Term<'ast>, + pub accesses: Vec>, + #[pest_ast(outer())] + pub span: Span<'ast>, + } + + #[derive(Debug, Clone, PartialEq)] + pub struct PostfixExpression<'ast> { + pub base: Box>, + pub accesses: Vec>, + pub span: Span<'ast>, + } + + impl<'ast> From> for Expression<'ast> { + fn from(t: PostfixedTerm<'ast>) -> Self { + let base = Expression::from(t.base); + let accesses = t.accesses.into_iter().map(Access::from).collect(); + Expression::Postfix(PostfixExpression { + base: Box::new(base), + accesses, + span: t.span, + }) + } + } + #[derive(Debug, FromPest, PartialEq, Clone)] #[pest_ast(rule(Rule::powered_term))] struct PoweredTerm<'ast> { - base: Term<'ast>, + base: PostfixedTerm<'ast>, op: Option, exponent: Option>, #[pest_ast(outer())] @@ -512,7 +539,6 @@ mod ast { match t { Term::Expression(e) => e, Term::Ternary(e) => Expression::Ternary(e), - Term::Postfix(e) => Expression::Postfix(e), Term::Primary(e) => e.into(), Term::InlineArray(e) => Expression::InlineArray(e), Term::InlineStruct(e) => Expression::InlineStruct(e), @@ -592,15 +618,6 @@ mod ast { #[pest_ast(rule(Rule::to_expression))] pub struct ToExpression<'ast>(pub Expression<'ast>); - #[derive(Debug, FromPest, PartialEq, Clone)] - #[pest_ast(rule(Rule::postfix_expression))] - pub struct PostfixExpression<'ast> { - pub id: IdentifierExpression<'ast>, - pub accesses: Vec>, - #[pest_ast(outer())] - pub span: Span<'ast>, - } - #[derive(Debug, FromPest, PartialEq, Clone)] #[pest_ast(rule(Rule::inline_array_expression))] pub struct InlineArrayExpression<'ast> { @@ -1359,10 +1376,10 @@ mod tests { }), ], expression: Expression::Postfix(PostfixExpression { - id: IdentifierExpression { + base: Box::new(Expression::Identifier(IdentifierExpression { value: String::from("foo"), span: Span::new(&source, 36, 39).unwrap() - }, + })), accesses: vec![Access::Call(CallAccess { explicit_generics: None, arguments: Arguments { From f3f400a6bd838c4a4869170f2ebf44eb0dbc2b42 Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 5 Oct 2021 21:20:55 +0300 Subject: [PATCH 09/23] fix tests, add breaking example --- .../constant_index_on_spread_inline.zok | 2 ++ zokrates_core/src/absy/from_ast.rs | 35 +++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 zokrates_cli/examples/constant_index_on_spread_inline.zok diff --git a/zokrates_cli/examples/constant_index_on_spread_inline.zok b/zokrates_cli/examples/constant_index_on_spread_inline.zok new file mode 100644 index 00000000..ccd266e2 --- /dev/null +++ b/zokrates_cli/examples/constant_index_on_spread_inline.zok @@ -0,0 +1,2 @@ +def main(field[3] a) -> field: + return [...a][0] \ No newline at end of file diff --git a/zokrates_core/src/absy/from_ast.rs b/zokrates_core/src/absy/from_ast.rs index 48db883f..296a9865 100644 --- a/zokrates_core/src/absy/from_ast.rs +++ b/zokrates_core/src/absy/from_ast.rs @@ -1123,21 +1123,44 @@ mod tests { } #[test] - #[should_panic] fn call_array_element() { - // a call after an array access should be rejected + // a call after an array access should be accepted let source = "def main(): return a[2](3)"; let ast = pest::generate_ast(&source).unwrap(); - absy::Module::from(ast); + assert_eq!( + absy::Module::from(ast), + wrap(absy::Expression::FunctionCall( + box absy::Expression::Select( + box absy::Expression::Identifier("a").mock(), + box absy::RangeOrExpression::Expression( + absy::Expression::IntConstant(2u32.into()).mock() + ) + ) + .mock(), + None, + vec![absy::Expression::IntConstant(3u32.into()).mock()], + )) + ); } #[test] - #[should_panic] fn call_call_result() { - // a call after a call should be rejected + // a call after a call should be accepted let source = "def main(): return a(2)(3)"; let ast = pest::generate_ast(&source).unwrap(); - absy::Module::from(ast); + assert_eq!( + absy::Module::from(ast), + wrap(absy::Expression::FunctionCall( + box absy::Expression::FunctionCall( + box absy::Expression::Identifier("a").mock(), + None, + vec![absy::Expression::IntConstant(2u32.into()).mock()] + ) + .mock(), + None, + vec![absy::Expression::IntConstant(3u32.into()).mock()], + )) + ); } } #[test] From 69cb867a8e3745769c0e70b8946dd1e1e7e456ca Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 5 Oct 2021 21:39:18 +0300 Subject: [PATCH 10/23] fix incorrect propagation --- .../src/static_analysis/propagation.rs | 21 ++++------- zokrates_core/src/typed_absy/mod.rs | 36 +++++++++---------- zokrates_core/src/typed_absy/result_folder.rs | 10 ++++-- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/zokrates_core/src/static_analysis/propagation.rs b/zokrates_core/src/static_analysis/propagation.rs index cb09a669..337b2c34 100644 --- a/zokrates_core/src/static_analysis/propagation.rs +++ b/zokrates_core/src/static_analysis/propagation.rs @@ -971,7 +971,10 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { } fn fold_select_expression< - E: Expr<'ast, T> + Select<'ast, T> + From>, + E: Expr<'ast, T> + + Select<'ast, T> + + From> + + Into>, >( &mut self, _: &E::Ty, @@ -988,12 +991,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { (ArrayExpressionInner::Value(v), UExpressionInner::Value(n)) => { if n < size { Ok(SelectOrExpression::Expression( - E::from( - v.expression_at::>(n as usize) - .unwrap() - .clone(), - ) - .into_inner(), + v.expression_at::(n as usize).unwrap().into_inner(), )) } else { Err(Error::OutOfBounds(n, size)) @@ -1005,14 +1003,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { TypedExpression::Array(a) => match a.as_inner() { ArrayExpressionInner::Value(v) => { Ok(SelectOrExpression::Expression( - E::from( - v.expression_at::>( - n as usize, - ) - .unwrap() - .clone(), - ) - .into_inner(), + v.expression_at::(n as usize).unwrap().into_inner(), )) } _ => unreachable!("should be an array value"), diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index 70faa133..8b362c9e 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -1142,30 +1142,28 @@ impl<'ast, T> IntoIterator for ArrayValue<'ast, T> { } impl<'ast, T: Clone + fmt::Debug> ArrayValue<'ast, T> { - fn expression_at_aux + Into>>( + fn expression_at_aux< + U: Select<'ast, T> + Into> + From>, + >( v: TypedExpressionOrSpread<'ast, T>, - ) -> Vec>> { + ) -> Vec> { match v { - TypedExpressionOrSpread::Expression(e) => vec![Some(e.clone())], + TypedExpressionOrSpread::Expression(e) => vec![Some(e.clone().into())], TypedExpressionOrSpread::Spread(s) => match s.array.size().into_inner() { UExpressionInner::Value(size) => { let array_ty = s.array.ty().clone(); match s.array.into_inner() { - ArrayExpressionInner::Value(v) => v - .into_iter() - .flat_map(Self::expression_at_aux::) - .collect(), + ArrayExpressionInner::Value(v) => { + v.into_iter().flat_map(Self::expression_at_aux).collect() + } a => (0..size) .map(|i| { - Some( - U::select( - a.clone() - .annotate(*array_ty.ty.clone(), array_ty.size.clone()), - i as u32, - ) - .into(), - ) + Some(U::select( + a.clone() + .annotate(*array_ty.ty.clone(), array_ty.size.clone()), + i as u32, + )) }) .collect(), } @@ -1175,13 +1173,15 @@ impl<'ast, T: Clone + fmt::Debug> ArrayValue<'ast, T> { } } - pub fn expression_at + Into>>( + pub fn expression_at< + U: Select<'ast, T> + Into> + From>, + >( &self, index: usize, - ) -> Option> { + ) -> Option { self.0 .iter() - .map(|v| dbg!(Self::expression_at_aux::(v.clone()))) + .map(|v| Self::expression_at_aux(v.clone())) .flatten() .take_while(|e| e.is_some()) .map(|e| e.unwrap()) diff --git a/zokrates_core/src/typed_absy/result_folder.rs b/zokrates_core/src/typed_absy/result_folder.rs index 738f026c..eb0e38fe 100644 --- a/zokrates_core/src/typed_absy/result_folder.rs +++ b/zokrates_core/src/typed_absy/result_folder.rs @@ -212,7 +212,10 @@ pub trait ResultFolder<'ast, T: Field>: Sized { } fn fold_select_expression< - E: Expr<'ast, T> + Select<'ast, T> + From>, + E: Expr<'ast, T> + + Select<'ast, T> + + From> + + Into>, >( &mut self, ty: &E::Ty, @@ -724,7 +727,10 @@ pub fn fold_member_expression< pub fn fold_select_expression< 'ast, T: Field, - E: Expr<'ast, T> + Select<'ast, T> + From>, + E: Expr<'ast, T> + + Select<'ast, T> + + From> + + Into>, F: ResultFolder<'ast, T>, >( f: &mut F, From fa30d66427a168dc80d6b6303e7443f8f1ef8f37 Mon Sep 17 00:00:00 2001 From: schaeff Date: Fri, 8 Oct 2021 10:28:32 +0300 Subject: [PATCH 11/23] avoid creating postfix expressions with no accesses --- zokrates_pest_ast/src/lib.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/zokrates_pest_ast/src/lib.rs b/zokrates_pest_ast/src/lib.rs index ae27e471..cf41cd9c 100644 --- a/zokrates_pest_ast/src/lib.rs +++ b/zokrates_pest_ast/src/lib.rs @@ -413,8 +413,8 @@ mod ast { Ternary(TernaryExpression<'ast>), Binary(BinaryExpression<'ast>), Unary(UnaryExpression<'ast>), - Identifier(IdentifierExpression<'ast>), Postfix(PostfixExpression<'ast>), + Identifier(IdentifierExpression<'ast>), Literal(LiteralExpression<'ast>), InlineArray(InlineArrayExpression<'ast>), InlineStruct(InlineStructExpression<'ast>), @@ -451,12 +451,16 @@ mod ast { impl<'ast> From> for Expression<'ast> { fn from(t: PostfixedTerm<'ast>) -> Self { let base = Expression::from(t.base); - let accesses = t.accesses.into_iter().map(Access::from).collect(); - Expression::Postfix(PostfixExpression { - base: Box::new(base), - accesses, - span: t.span, - }) + let accesses = t.accesses; + if accesses.is_empty() { + base + } else { + Expression::Postfix(PostfixExpression { + base: Box::new(base), + accesses, + span: t.span, + }) + } } } From 392bd9e67cdff9a81e86e25d0b58a4fc841a7bad Mon Sep 17 00:00:00 2001 From: Thibaut Schaeffer Date: Fri, 8 Oct 2021 13:14:03 +0300 Subject: [PATCH 12/23] Create 1030-schaeff --- changelogs/unreleased/1030-schaeff | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/1030-schaeff diff --git a/changelogs/unreleased/1030-schaeff b/changelogs/unreleased/1030-schaeff new file mode 100644 index 00000000..bfeaa2d0 --- /dev/null +++ b/changelogs/unreleased/1030-schaeff @@ -0,0 +1 @@ +Allow more postfix expressions, exit gracefully when trying to call anything else than an identifier From 6de5a21d7e7228cbd83abe97aac6430f353209a4 Mon Sep 17 00:00:00 2001 From: schaeff Date: Fri, 8 Oct 2021 20:26:28 +0300 Subject: [PATCH 13/23] improve example --- zokrates_cli/examples/constant_index_on_spread_inline.zok | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zokrates_cli/examples/constant_index_on_spread_inline.zok b/zokrates_cli/examples/constant_index_on_spread_inline.zok index ccd266e2..c876e1aa 100644 --- a/zokrates_cli/examples/constant_index_on_spread_inline.zok +++ b/zokrates_cli/examples/constant_index_on_spread_inline.zok @@ -1,2 +1,2 @@ def main(field[3] a) -> field: - return [...a][0] \ No newline at end of file + return [...a][0] + [a[0]][0] + [a[0]; 1][0] \ No newline at end of file From be629093ec20b0f8d33387b5b921e7ff514b6fe8 Mon Sep 17 00:00:00 2001 From: schaeff Date: Mon, 11 Oct 2021 09:33:23 +0300 Subject: [PATCH 14/23] remove clone --- zokrates_core/src/typed_absy/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index 8b362c9e..0dc8db34 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -1148,7 +1148,7 @@ impl<'ast, T: Clone + fmt::Debug> ArrayValue<'ast, T> { v: TypedExpressionOrSpread<'ast, T>, ) -> Vec> { match v { - TypedExpressionOrSpread::Expression(e) => vec![Some(e.clone().into())], + TypedExpressionOrSpread::Expression(e) => vec![Some(e.into())], TypedExpressionOrSpread::Spread(s) => match s.array.size().into_inner() { UExpressionInner::Value(size) => { let array_ty = s.array.ty().clone(); From d7389378238acc6196cc3a05e92dd06ae4933ef8 Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 12 Oct 2021 19:35:25 +0300 Subject: [PATCH 15/23] try with older nightly --- rust-toolchain | 2 +- rust-toolchain.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust-toolchain b/rust-toolchain index 07734de2..5ca2f2e2 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2021-09-01 \ No newline at end of file +nightly-2021-08-01 \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 146e37bd..47d8ceee 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2021-09-01" \ No newline at end of file +channel = "nightly-2021-08-01" \ No newline at end of file From bdd68fb922a5470081a1643271fee097527af3d8 Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 12 Oct 2021 19:45:17 +0300 Subject: [PATCH 16/23] try with previous nightly --- rust-toolchain | 2 +- rust-toolchain.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust-toolchain b/rust-toolchain index 5ca2f2e2..1cfd57a1 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2021-08-01 \ No newline at end of file +nightly-2021-04-25 \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 47d8ceee..41d688e5 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2021-08-01" \ No newline at end of file +channel = "nightly-2021-04-25" \ No newline at end of file From bb3632f57d254721274d7d579cce318214092bd4 Mon Sep 17 00:00:00 2001 From: schaeff Date: Tue, 12 Oct 2021 19:56:34 +0300 Subject: [PATCH 17/23] upgrade cargo lock --- Cargo.lock | 367 ++++++++++++++++++++++++++--------------------------- 1 file changed, 182 insertions(+), 185 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84b07de1..5896115c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.15.2" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7a2e47a1fbe209ee101dd6d61285226744c6c8d3c21c8dc878ba6cb9f467f3a" +checksum = "3e61f2b7f93d2c7d2b08263acaa4a363b3e276806c68af6134c44f523bf1aacd" dependencies = [ "gimli", ] @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98" +checksum = "991984e3fd003e7ba02eb724f87a0f997b78677c46c0e91f8424ad7394c9886a" dependencies = [ "getrandom 0.2.3", "once_cell", @@ -145,8 +145,8 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e8cb28c2137af1ef058aa59616db3f7df67dbb70bf2be4ee6920008cc30d98c" dependencies = [ - "quote 1.0.9", - "syn 1.0.73", + "quote 1.0.10", + "syn 1.0.80", ] [[package]] @@ -155,10 +155,10 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b9c256a93a10ed9708c16a517d6dcfaba3d215c0d7fab44d29a9affefb5eeb8" dependencies = [ - "num-bigint 0.4.0", + "num-bigint 0.4.2", "num-traits 0.2.14", - "quote 1.0.9", - "syn 1.0.73", + "quote 1.0.10", + "syn 1.0.80", ] [[package]] @@ -208,7 +208,7 @@ dependencies = [ "ark-relations", "ark-std", "derivative", - "num-bigint 0.4.0", + "num-bigint 0.4.2", "num-integer", "num-traits 0.2.14", "tracing", @@ -254,7 +254,7 @@ dependencies = [ "ark-relations", "ark-std", "derivative", - "num-bigint 0.4.0", + "num-bigint 0.4.2", "num-traits 0.2.14", "tracing", ] @@ -286,9 +286,9 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ac3d78c750b01f5df5b2e76d106ed31487a93b3868f14a7f0eb3a74f45e1d8a" dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", + "proc-macro2 1.0.29", + "quote 1.0.10", + "syn 1.0.80", ] [[package]] @@ -354,9 +354,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7815ea54e4d821e791162e078acbebfd6d8c8939cd559c9335dceb1c8ca7282" +checksum = "e7a905d892734eea339e896738c14b9afce22b5318f64b951e70bf3844419b01" dependencies = [ "addr2line", "cc", @@ -403,15 +403,15 @@ checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "blake2" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a5720225ef5daecf08657f23791354e1685a8c91a4c60c7f3d3b2892f978f4" +checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" dependencies = [ "crypto-mac", "digest 0.9.0", @@ -461,9 +461,9 @@ dependencies = [ [[package]] name = "bstr" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90682c8d613ad3373e66de8c6411e0ae2ab2571e879d2efbf73558cc66f21279" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" dependencies = [ "lazy_static", "memchr", @@ -473,9 +473,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.7.0" +version = "3.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" +checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538" [[package]] name = "byte-tools" @@ -497,9 +497,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cargo-platform" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0226944a63d1bf35a3b5f948dd7c59e263db83695c9e8bffc4037de02e30f1d7" +checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" dependencies = [ "serde", ] @@ -519,9 +519,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.68" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" +checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" dependencies = [ "jobserver", ] @@ -555,9 +555,9 @@ dependencies = [ [[package]] name = "cmake" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb6210b637171dfba4cda12e579ac6dc73f5165ad56133e5d72ef3131f320855" +checksum = "b7b858541263efe664aead4a5209a4ae5c5d2811167d4ed4ee0944503f8d2089" dependencies = [ "cc", ] @@ -575,11 +575,11 @@ dependencies = [ [[package]] name = "console_error_panic_hook" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "wasm-bindgen", ] @@ -591,9 +591,9 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] name = "cpufeatures" -version = "0.1.5" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" +checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" dependencies = [ "libc", ] @@ -624,9 +624,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" +checksum = "c20ff29ded3204c5106278a81a38f4b482636ed4fa1e6cfbeef193291beb29ed" dependencies = [ "crossbeam-epoch", "crossbeam-utils", @@ -710,12 +710,12 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e98e2ad1a782e33928b96fc3948e7c355e5af34ba4de7670fe8bac2a3b2006d" +checksum = "ccc0a48a9b826acdf4028595adc9db92caea352f7af011a3034acd172a52a0aa" dependencies = [ - "quote 1.0.9", - "syn 1.0.73", + "quote 1.0.10", + "syn 1.0.80", ] [[package]] @@ -724,9 +724,9 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", + "proc-macro2 1.0.29", + "quote 1.0.10", + "syn 1.0.80", ] [[package]] @@ -838,9 +838,9 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", + "proc-macro2 1.0.29", + "quote 1.0.10", + "syn 1.0.80", "synstructure", ] @@ -882,9 +882,9 @@ dependencies = [ "num-bigint 0.2.6", "num-integer", "num-traits 0.2.14", - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", + "proc-macro2 1.0.29", + "quote 1.0.10", + "syn 1.0.80", ] [[package]] @@ -921,9 +921,9 @@ checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" [[package]] name = "futures" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27" +checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca" dependencies = [ "futures-channel", "futures-core", @@ -936,9 +936,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2" +checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" dependencies = [ "futures-core", "futures-sink", @@ -946,15 +946,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1" +checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" [[package]] name = "futures-executor" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "badaa6a909fac9e7236d0620a2f57f7664640c56575b71a7552fbd68deafab79" +checksum = "45025be030969d763025784f7f355043dc6bc74093e4ecc5000ca4dc50d8745c" dependencies = [ "futures-core", "futures-task", @@ -964,27 +964,27 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1" +checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" [[package]] name = "futures-sink" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282" +checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" [[package]] name = "futures-task" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae" +checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" [[package]] name = "futures-util" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967" +checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" dependencies = [ "autocfg", "futures-channel", @@ -1043,15 +1043,15 @@ dependencies = [ [[package]] name = "gimli" -version = "0.24.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4075386626662786ddb0ec9081e7c7eeb1ba31951f447ca780ef9f5d568189" +checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" [[package]] name = "git2" -version = "0.13.20" +version = "0.13.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9831e983241f8c5591ed53f17d874833e2fa82cac2625f3888c50cbfe136cba" +checksum = "2a8057932925d3a9d9e4434ea016570d37420ddb1ceed45a174d577f24ed6700" dependencies = [ "bitflags", "libc", @@ -1126,24 +1126,24 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "jobserver" -version = "0.1.22" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "972f5ae5d1cb9c6ae417789196c803205313edde988685da5e3aae0827b9e7fd" +checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.51" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062" +checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" dependencies = [ "wasm-bindgen", ] @@ -1156,15 +1156,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.98" +version = "0.2.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" +checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" [[package]] name = "libgit2-sys" -version = "0.12.21+1.1.0" +version = "0.12.24+1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86271bacd72b2b9e854c3dcfb82efd538f15f870e4c11af66900effb462f6825" +checksum = "ddbd6021eef06fb289a8f54b3c2acfdd85ff2a585dfbb24b8576325373d2152c" dependencies = [ "cc", "libc", @@ -1176,9 +1176,9 @@ dependencies = [ [[package]] name = "libssh2-sys" -version = "0.2.21" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0186af0d8f171ae6b9c4c90ec51898bad5d08a2d5e470903a50d9ad8959cbee" +checksum = "b094a36eb4b8b8c8a7b4b8ae43b2944502be3e59cd87687595cf6b0a71b3f4ca" dependencies = [ "cc", "libc", @@ -1217,9 +1217,9 @@ checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" [[package]] name = "matches" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "maybe-uninit" @@ -1229,9 +1229,9 @@ checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] name = "memchr" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "memoffset" @@ -1283,9 +1283,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e0d047c1062aa51e256408c560894e5251f08925980e53cf1aa5bd00eec6512" +checksum = "74e768dff5fb39a41b3bcd30bb25cf989706c90d028d1ad71971987aa309d535" dependencies = [ "autocfg", "num-integer", @@ -1343,9 +1343,9 @@ dependencies = [ [[package]] name = "object" -version = "0.25.3" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a38f2be3697a57b4060074ff41b44c16870d916ad7877c17696e063257482bc7" +checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2" dependencies = [ "memchr", ] @@ -1376,9 +1376,9 @@ checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" [[package]] name = "openssl-sys" -version = "0.9.65" +version = "0.9.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a7907e3bfa08bb85105209cdfcb6c63d109f8f6c1ed6ca318fff5c1853fbc1d" +checksum = "69df2d8dfc6ce3aaf44b40dec6f487d5a886516cf6879c49e98e0710f310a058" dependencies = [ "autocfg", "cc", @@ -1453,9 +1453,9 @@ checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" dependencies = [ "pest", "pest_meta", - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", + "proc-macro2 1.0.29", + "quote 1.0.10", + "syn 1.0.80", ] [[package]] @@ -1483,9 +1483,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.19" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +checksum = "7c9b1041b4387893b91ee6746cddfc28516aff326a3519fb2adf820932c5e6cb" [[package]] name = "ppv-lite86" @@ -1516,9 +1516,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.27" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" dependencies = [ "unicode-xid 0.2.2", ] @@ -1545,11 +1545,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" dependencies = [ - "proc-macro2 1.0.27", + "proc-macro2 1.0.29", ] [[package]] @@ -1681,9 +1681,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" dependencies = [ "bitflags", ] @@ -1760,9 +1760,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dead70b0b5e03e9c814bcb6b01e03e68f7c57a80aa48c72ec92152ab3e818d49" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" [[package]] name = "rustc_version" @@ -1838,29 +1838,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.126" +version = "1.0.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" +checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.126" +version = "1.0.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" +checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", + "proc-macro2 1.0.29", + "quote 1.0.10", + "syn 1.0.80", ] [[package]] name = "serde_json" -version = "1.0.64" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" +checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" dependencies = [ "itoa", "ryu", @@ -1893,9 +1893,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.5" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" +checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", @@ -1930,9 +1930,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" +checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" [[package]] name = "strsim" @@ -1942,9 +1942,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "subtle" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" @@ -1959,24 +1959,24 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.73" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" +checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194" dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", + "proc-macro2 1.0.29", + "quote 1.0.10", "unicode-xid 0.2.2", ] [[package]] name = "synstructure" -version = "0.12.4" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", + "proc-macro2 1.0.29", + "quote 1.0.10", + "syn 1.0.80", "unicode-xid 0.2.2", ] @@ -2042,9 +2042,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.2.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" +checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7" dependencies = [ "tinyvec_macros", ] @@ -2057,9 +2057,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tracing" -version = "0.1.26" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" dependencies = [ "cfg-if 1.0.0", "pin-project-lite", @@ -2069,20 +2069,20 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.15" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", + "proc-macro2 1.0.29", + "quote 1.0.10", + "syn 1.0.80", ] [[package]] name = "tracing-core" -version = "0.1.18" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" [[package]] name = "typed-arena" @@ -2092,9 +2092,9 @@ checksum = "a9b2228007eba4120145f785df0f6c92ea538f5a3635a612ecf4e334c8c1446d" [[package]] name = "typenum" -version = "1.13.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" +checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" [[package]] name = "ucd-trie" @@ -2119,12 +2119,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" -dependencies = [ - "matches", -] +checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" [[package]] name = "unicode-normalization" @@ -2137,9 +2134,9 @@ dependencies = [ [[package]] name = "unicode-width" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "unicode-xid" @@ -2220,9 +2217,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" +checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -2230,24 +2227,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" +checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" dependencies = [ "bumpalo", "lazy_static", "log", - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", + "proc-macro2 1.0.29", + "quote 1.0.10", + "syn 1.0.80", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.24" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fba7978c679d53ce2d0ac80c8c175840feb849a161664365d1287b41f2e67f1" +checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -2257,38 +2254,38 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" +checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" dependencies = [ - "quote 1.0.9", + "quote 1.0.10", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" +checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", + "proc-macro2 1.0.29", + "quote 1.0.10", + "syn 1.0.80", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" +checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" [[package]] name = "wasm-bindgen-test" -version = "0.3.24" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cab416a9b970464c2882ed92d55b0c33046b08e0bdc9d59b3b718acd4e1bae8" +checksum = "96f1aa7971fdf61ef0f353602102dbea75a56e225ed036c1e3740564b91e6b7e" dependencies = [ "console_error_panic_hook", "js-sys", @@ -2300,19 +2297,19 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.24" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd4543fc6cf3541ef0d98bf720104cc6bd856d7eba449fd2aa365ef4fed0e782" +checksum = "6006f79628dfeb96a86d4db51fbf1344cd7fd8408f06fc9aa3c84913a4789688" dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", + "proc-macro2 1.0.29", + "quote 1.0.10", ] [[package]] name = "web-sys" -version = "0.3.51" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582" +checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" dependencies = [ "js-sys", "wasm-bindgen", @@ -2351,22 +2348,22 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "zeroize" -version = "1.3.0" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" +checksum = "bf68b08513768deaa790264a7fac27a58cbf2705cfcdc9448362229217d7e970" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2c1e130bebaeab2f23886bf9acbaca14b092408c452543c857f66399cd6dab1" +checksum = "bdff2024a851a322b08f179173ae2ba620445aef1e838f0c196820eade4ae0c7" dependencies = [ - "proc-macro2 1.0.27", - "quote 1.0.9", - "syn 1.0.73", + "proc-macro2 1.0.29", + "quote 1.0.10", + "syn 1.0.80", "synstructure", ] @@ -2445,7 +2442,7 @@ dependencies = [ "regex 0.2.11", "serde", "serde_json", - "sha2 0.9.5", + "sha2 0.9.8", "typed-arena", "wasm-bindgen-test", "zokrates_common", From e42033241e57e8a1f05f95af3b69ac1d77b08bdc Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 13 Oct 2021 11:45:55 +0300 Subject: [PATCH 18/23] add marlin to backend table --- zokrates_book/src/toolbox/proving_schemes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zokrates_book/src/toolbox/proving_schemes.md b/zokrates_book/src/toolbox/proving_schemes.md index 3629c5ee..f1b58063 100644 --- a/zokrates_book/src/toolbox/proving_schemes.md +++ b/zokrates_book/src/toolbox/proving_schemes.md @@ -49,7 +49,7 @@ ZoKrates supports multiple backends. The options are the following: | ---- | -------- | --------------- | ------ | | Bellman | `--backend bellman` | G16 | ALTBN_128, BLS12_381 | | Libsnark | `--backend libsnark` | GM17, PGHR13 | ALTBN_128 | -| Ark | `--backend ark` | GM17 | ALTBN_128, BLS12_377, BW6_761 | +| Ark | `--backend ark` | GM17, MARLIN | ALTBN_128, BLS12_377, BW6_761 | Default: `bellman` From e97826719f4e4d7bed92687c547a7ad6f47aa3ee Mon Sep 17 00:00:00 2001 From: schaeff Date: Wed, 13 Oct 2021 11:47:59 +0300 Subject: [PATCH 19/23] changelog --- changelogs/unreleased/1034-schaeff | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/1034-schaeff diff --git a/changelogs/unreleased/1034-schaeff b/changelogs/unreleased/1034-schaeff new file mode 100644 index 00000000..cc4498d1 --- /dev/null +++ b/changelogs/unreleased/1034-schaeff @@ -0,0 +1 @@ +Add Marlin proving scheme to the backend table in the book \ No newline at end of file From 37940bb067887ac704af03d6c732583a0c795ccb Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 13 Oct 2021 12:07:28 +0200 Subject: [PATCH 20/23] introduce assertion type --- zokrates_core/src/flat_absy/mod.rs | 7 ++-- zokrates_core/src/flatten/mod.rs | 32 +++++++++++-------- zokrates_core/src/parser/tokenize/position.rs | 2 +- zokrates_core/src/semantics.rs | 2 +- .../static_analysis/flatten_complex_types.rs | 10 ++++-- .../src/static_analysis/propagation.rs | 14 +++----- .../static_analysis/variable_write_remover.rs | 2 +- zokrates_core/src/typed_absy/folder.rs | 4 +-- zokrates_core/src/typed_absy/mod.rs | 31 ++++++++++++++---- zokrates_core/src/typed_absy/result_folder.rs | 4 +-- zokrates_core/src/zir/folder.rs | 2 +- zokrates_core/src/zir/mod.rs | 28 +++++++++++----- zokrates_core/src/zir/result_folder.rs | 4 ++- 13 files changed, 88 insertions(+), 54 deletions(-) diff --git a/zokrates_core/src/flat_absy/mod.rs b/zokrates_core/src/flat_absy/mod.rs index 96cdab83..cd5ed915 100644 --- a/zokrates_core/src/flat_absy/mod.rs +++ b/zokrates_core/src/flat_absy/mod.rs @@ -43,7 +43,7 @@ pub enum RuntimeError { Euclidean, ShaXor, Division, - Source(Option), + Source(String), ArgumentBitness, SelectRangeCheck, } @@ -87,10 +87,7 @@ impl fmt::Display for RuntimeError { Euclidean => "Euclidean check failed", ShaXor => "Internal Sha check failed", Division => "Division check failed", - Source(m) => m - .as_ref() - .map(|s| s.as_str()) - .unwrap_or("User assertion failed"), + Source(m) => m.as_str(), ArgumentBitness => "Argument bitness check failed", SelectRangeCheck => "Out of bounds array access", }; diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index 58846f80..d1dd4bae 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -14,7 +14,6 @@ use crate::compile::CompileConfig; use crate::embed::FlatEmbed; use crate::flat_absy::*; use crate::solvers::Solver; -use crate::typed_absy::AssertionMetadata; use crate::zir::types::{Type, UBitwidth}; use crate::zir::*; use std::collections::hash_map::Entry; @@ -147,6 +146,15 @@ impl FlatUExpression { } } +impl From for RuntimeError { + fn from(ty: AssertionType) -> Self { + match ty { + AssertionType::Source(s) => RuntimeError::Source(s), + AssertionType::SelectRangeCheck => RuntimeError::SelectRangeCheck, + } + } +} + impl<'ast, T: Field> Flattener<'ast, T> { pub fn flatten(p: ZirProgram<'ast, T>, config: &CompileConfig) -> FlatProg { Flattener::new(config).flatten_program(p) @@ -2371,13 +2379,13 @@ impl<'ast, T: Field> Flattener<'ast, T> { .insert(FlatExpression::Identifier(var), bits); } } - ZirStatement::Assertion(e, metadata) => { + ZirStatement::Assertion(e, ty) => { match e { BooleanExpression::And(..) => { for boolean in e.into_conjunction_iterator() { self.flatten_statement( statements_flattened, - ZirStatement::Assertion(boolean, metadata.clone()), + ZirStatement::Assertion(boolean, ty.clone()), ) } } @@ -2385,7 +2393,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { let lhs = self.flatten_field_expression(statements_flattened, lhs); let rhs = self.flatten_field_expression(statements_flattened, rhs); - self.flatten_equality_assertion(statements_flattened, lhs, rhs, metadata) + self.flatten_equality_assertion(statements_flattened, lhs, rhs, ty) } BooleanExpression::UintEq(box lhs, box rhs) => { let lhs = self @@ -2395,13 +2403,13 @@ impl<'ast, T: Field> Flattener<'ast, T> { .flatten_uint_expression(statements_flattened, rhs) .get_field_unchecked(); - self.flatten_equality_assertion(statements_flattened, lhs, rhs, metadata) + self.flatten_equality_assertion(statements_flattened, lhs, rhs, ty) } BooleanExpression::BoolEq(box lhs, box rhs) => { let lhs = self.flatten_boolean_expression(statements_flattened, lhs); let rhs = self.flatten_boolean_expression(statements_flattened, rhs); - self.flatten_equality_assertion(statements_flattened, lhs, rhs, metadata) + self.flatten_equality_assertion(statements_flattened, lhs, rhs, ty) } _ => { // naive approach: flatten the boolean to a single field element and constrain it to 1 @@ -2411,14 +2419,14 @@ impl<'ast, T: Field> Flattener<'ast, T> { statements_flattened.push(FlatStatement::Condition( e, FlatExpression::Number(T::from(1)), - RuntimeError::Source(metadata.map(|m| m.to_string())), + ty.into(), )); } else { // swap so that left side is linear statements_flattened.push(FlatStatement::Condition( FlatExpression::Number(T::from(1)), e, - RuntimeError::Source(metadata.map(|m| m.to_string())), + ty.into(), )); } } @@ -2530,7 +2538,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { statements_flattened: &mut FlatStatements, lhs: FlatExpression, rhs: FlatExpression, - metadata: Option, + assertion_type: AssertionType, ) { let (lhs, rhs) = match (lhs, rhs) { (FlatExpression::Mult(box x, box y), z) | (z, FlatExpression::Mult(box x, box y)) => ( @@ -2548,11 +2556,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { ), ), }; - statements_flattened.push(FlatStatement::Condition( - lhs, - rhs, - RuntimeError::Source(metadata.map(|m| m.to_string())), - )); + statements_flattened.push(FlatStatement::Condition(lhs, rhs, assertion_type.into())); } /// Identifies a non-linear expression by assigning it to a new identifier. diff --git a/zokrates_core/src/parser/tokenize/position.rs b/zokrates_core/src/parser/tokenize/position.rs index a37b2a4b..12394209 100644 --- a/zokrates_core/src/parser/tokenize/position.rs +++ b/zokrates_core/src/parser/tokenize/position.rs @@ -1,6 +1,6 @@ use std::fmt; -#[derive(Clone, PartialEq, Eq, Copy, Hash, Default)] +#[derive(Clone, PartialEq, Eq, Copy, Hash, Default, PartialOrd, Ord)] pub struct Position { pub line: usize, pub col: usize, diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 6f787be8..0a5b3c92 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -1741,7 +1741,7 @@ impl<'ast, T: Field> Checker<'ast, T> { match e { TypedExpression::Boolean(e) => Ok(TypedStatement::Assertion( e, - Some(AssertionMetadata { + AssertionType::Source(AssertionMetadata { file: module_id.display().to_string(), position: pos.0, message, diff --git a/zokrates_core/src/static_analysis/flatten_complex_types.rs b/zokrates_core/src/static_analysis/flatten_complex_types.rs index e6522fc1..2f1435e7 100644 --- a/zokrates_core/src/static_analysis/flatten_complex_types.rs +++ b/zokrates_core/src/static_analysis/flatten_complex_types.rs @@ -379,9 +379,15 @@ fn fold_statement<'ast, T: Field>( typed_absy::TypedStatement::Declaration(..) => { unreachable!() } - typed_absy::TypedStatement::Assertion(e, m) => { + typed_absy::TypedStatement::Assertion(e, ty) => { let e = f.fold_boolean_expression(statements_buffer, e); - vec![zir::ZirStatement::Assertion(e, m)] + let ty = match ty { + typed_absy::AssertionType::Source(metadata) => { + zir::AssertionType::Source(metadata.to_string()) + } + typed_absy::AssertionType::SelectRangeCheck => zir::AssertionType::SelectRangeCheck, + }; + vec![zir::ZirStatement::Assertion(e, ty)] } typed_absy::TypedStatement::For(..) => unreachable!(), typed_absy::TypedStatement::MultipleDefinition(variables, elist) => { diff --git a/zokrates_core/src/static_analysis/propagation.rs b/zokrates_core/src/static_analysis/propagation.rs index c4339c5e..8c9c6e8a 100644 --- a/zokrates_core/src/static_analysis/propagation.rs +++ b/zokrates_core/src/static_analysis/propagation.rs @@ -620,18 +620,14 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { Ok(statements) } - TypedStatement::Assertion(e, metadata) => { + TypedStatement::Assertion(e, ty) => { let e_str = e.to_string(); let expr = self.fold_boolean_expression(e)?; match expr { - BooleanExpression::Value(v) if !v => Err(Error::AssertionFailed(format!( - "{}: ({})", - metadata - .map(|m| m.to_string()) - .unwrap_or_else(|| "Assertion failed".to_string()), - e_str, - ))), - _ => Ok(vec![TypedStatement::Assertion(expr, metadata)]), + BooleanExpression::Value(v) if !v => { + Err(Error::AssertionFailed(format!("{}: ({})", ty, e_str))) + } + _ => Ok(vec![TypedStatement::Assertion(expr, ty)]), } } s @ TypedStatement::PushCallLog(..) => Ok(vec![s]), diff --git a/zokrates_core/src/static_analysis/variable_write_remover.rs b/zokrates_core/src/static_analysis/variable_write_remover.rs index c99459fd..614e5b28 100644 --- a/zokrates_core/src/static_analysis/variable_write_remover.rs +++ b/zokrates_core/src/static_analysis/variable_write_remover.rs @@ -49,7 +49,7 @@ impl<'ast> VariableWriteRemover { Access::Select(head) => { statements.insert(TypedStatement::Assertion( BooleanExpression::UintLt(box head.clone(), box size.into()), - None, + AssertionType::SelectRangeCheck, )); ArrayExpressionInner::Value( diff --git a/zokrates_core/src/typed_absy/folder.rs b/zokrates_core/src/typed_absy/folder.rs index 4fa9e820..ef91db57 100644 --- a/zokrates_core/src/typed_absy/folder.rs +++ b/zokrates_core/src/typed_absy/folder.rs @@ -461,8 +461,8 @@ pub fn fold_statement<'ast, T: Field, F: Folder<'ast, T>>( TypedStatement::Definition(f.fold_assignee(a), f.fold_expression(e)) } TypedStatement::Declaration(v) => TypedStatement::Declaration(f.fold_variable(v)), - TypedStatement::Assertion(e, m) => { - TypedStatement::Assertion(f.fold_boolean_expression(e), m) + TypedStatement::Assertion(e, ty) => { + TypedStatement::Assertion(f.fold_boolean_expression(e), ty) } TypedStatement::For(v, from, to, statements) => TypedStatement::For( f.fold_variable(v), diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index 8b8b75bb..de7dc6e9 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -576,7 +576,7 @@ impl<'ast, T: fmt::Display> fmt::Display for TypedAssignee<'ast, T> { } } -#[derive(Clone, Debug, PartialEq, Hash, Eq, Default)] +#[derive(Clone, Debug, PartialEq, Hash, Eq, Default, PartialOrd, Ord)] pub struct AssertionMetadata { pub file: String, pub position: Position, @@ -593,6 +593,21 @@ impl fmt::Display for AssertionMetadata { } } +#[derive(Debug, Clone, PartialEq, Hash, Eq, PartialOrd, Ord)] +pub enum AssertionType { + Source(AssertionMetadata), + SelectRangeCheck, +} + +impl fmt::Display for AssertionType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + AssertionType::Source(metadata) => write!(f, "{}", metadata), + AssertionType::SelectRangeCheck => write!(f, "Range check on array access"), + } + } +} + /// A statement in a `TypedFunction` #[allow(clippy::large_enum_variant)] #[derive(Clone, PartialEq, Debug, Hash, Eq, PartialOrd, Ord)] @@ -600,7 +615,7 @@ pub enum TypedStatement<'ast, T> { Return(Vec>), Definition(TypedAssignee<'ast, T>, TypedExpression<'ast, T>), Declaration(Variable<'ast, T>), - Assertion(BooleanExpression<'ast, T>, Option), + Assertion(BooleanExpression<'ast, T>, AssertionType), For( Variable<'ast, T>, UExpression<'ast, T>, @@ -648,12 +663,14 @@ impl<'ast, T: fmt::Display> fmt::Display for TypedStatement<'ast, T> { } TypedStatement::Declaration(ref var) => write!(f, "{}", var), TypedStatement::Definition(ref lhs, ref rhs) => write!(f, "{} = {}", lhs, rhs), - TypedStatement::Assertion(ref e, ref metadata) => { + TypedStatement::Assertion(ref e, ref ty) => { write!(f, "assert({}", e)?; - let metadata = metadata.as_ref().unwrap(); - match &metadata.message { - Some(m) => write!(f, ", \"{}\")", m), - None => write!(f, ")"), + match ty { + AssertionType::Source(metadata) => match &metadata.message { + Some(m) => write!(f, ", \"{}\")", m), + None => write!(f, ")"), + }, + internal => write!(f, ") // {}", internal), } } TypedStatement::For(ref var, ref start, ref stop, ref list) => { diff --git a/zokrates_core/src/typed_absy/result_folder.rs b/zokrates_core/src/typed_absy/result_folder.rs index 0dfdf909..b173a668 100644 --- a/zokrates_core/src/typed_absy/result_folder.rs +++ b/zokrates_core/src/typed_absy/result_folder.rs @@ -458,8 +458,8 @@ pub fn fold_statement<'ast, T: Field, F: ResultFolder<'ast, T>>( TypedStatement::Definition(f.fold_assignee(a)?, f.fold_expression(e)?) } TypedStatement::Declaration(v) => TypedStatement::Declaration(f.fold_variable(v)?), - TypedStatement::Assertion(e, m) => { - TypedStatement::Assertion(f.fold_boolean_expression(e)?, m) + TypedStatement::Assertion(e, ty) => { + TypedStatement::Assertion(f.fold_boolean_expression(e)?, ty) } TypedStatement::For(v, from, to, statements) => TypedStatement::For( f.fold_variable(v)?, diff --git a/zokrates_core/src/zir/folder.rs b/zokrates_core/src/zir/folder.rs index dbf6011f..88d0eb4e 100644 --- a/zokrates_core/src/zir/folder.rs +++ b/zokrates_core/src/zir/folder.rs @@ -115,7 +115,7 @@ pub fn fold_statement<'ast, T: Field, F: Folder<'ast, T>>( .flat_map(|e| f.fold_statement(e)) .collect(), ), - ZirStatement::Assertion(e, m) => ZirStatement::Assertion(f.fold_boolean_expression(e), m), + ZirStatement::Assertion(e, ty) => ZirStatement::Assertion(f.fold_boolean_expression(e), ty), ZirStatement::MultipleDefinition(variables, elist) => ZirStatement::MultipleDefinition( variables.into_iter().map(|v| f.fold_variable(v)).collect(), f.fold_expression_list(elist), diff --git a/zokrates_core/src/zir/mod.rs b/zokrates_core/src/zir/mod.rs index 01abcaa6..2d0fded6 100644 --- a/zokrates_core/src/zir/mod.rs +++ b/zokrates_core/src/zir/mod.rs @@ -19,9 +19,7 @@ use std::fmt; use zokrates_field::Field; pub use self::folder::Folder; - pub use self::identifier::{Identifier, SourceIdentifier}; -use crate::typed_absy::AssertionMetadata; /// A typed program as a collection of modules, one of them being the main #[derive(PartialEq, Debug)] @@ -87,6 +85,21 @@ impl<'ast, T: fmt::Debug> fmt::Debug for ZirFunction<'ast, T> { pub type ZirAssignee<'ast> = Variable<'ast>; +#[derive(Debug, Clone, PartialEq, Hash, Eq)] +pub enum AssertionType { + Source(String), + SelectRangeCheck, +} + +impl fmt::Display for AssertionType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + AssertionType::Source(message) => write!(f, "{}", message), + AssertionType::SelectRangeCheck => write!(f, "Range check on array access"), + } + } +} + /// A statement in a `ZirFunction` #[derive(Clone, PartialEq, Hash, Eq, Debug)] pub enum ZirStatement<'ast, T> { @@ -97,7 +110,7 @@ pub enum ZirStatement<'ast, T> { Vec>, Vec>, ), - Assertion(BooleanExpression<'ast, T>, Option), + Assertion(BooleanExpression<'ast, T>, AssertionType), MultipleDefinition(Vec>, ZirExpressionList<'ast, T>), } @@ -132,12 +145,11 @@ impl<'ast, T: fmt::Display> fmt::Display for ZirStatement<'ast, T> { .join("\n") ) } - ZirStatement::Assertion(ref e, ref metadata) => { + ZirStatement::Assertion(ref e, ref ty) => { write!(f, "assert({}", e)?; - let metadata = metadata.as_ref().unwrap(); - match &metadata.message { - Some(m) => write!(f, ", \"{}\")", m), - None => write!(f, ")"), + match ty { + AssertionType::Source(message) => write!(f, ", \"{}\")", message), + internal => write!(f, ") // {}", internal), } } ZirStatement::MultipleDefinition(ref ids, ref rhs) => { diff --git a/zokrates_core/src/zir/result_folder.rs b/zokrates_core/src/zir/result_folder.rs index 0b566c9c..47462c2f 100644 --- a/zokrates_core/src/zir/result_folder.rs +++ b/zokrates_core/src/zir/result_folder.rs @@ -137,7 +137,9 @@ pub fn fold_statement<'ast, T: Field, F: ResultFolder<'ast, T>>( .flatten() .collect(), ), - ZirStatement::Assertion(e, m) => ZirStatement::Assertion(f.fold_boolean_expression(e)?, m), + ZirStatement::Assertion(e, ty) => { + ZirStatement::Assertion(f.fold_boolean_expression(e)?, ty) + } ZirStatement::MultipleDefinition(variables, elist) => ZirStatement::MultipleDefinition( variables .into_iter() From 9474406aaf7362d8405215382948b59decfac682 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 13 Oct 2021 12:43:49 +0200 Subject: [PATCH 21/23] make tests pass --- zokrates_core/src/flatten/mod.rs | 28 +++++++++---------- .../src/static_analysis/zir_propagation.rs | 5 ++-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index d1dd4bae..011fcfa3 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -2694,7 +2694,7 @@ mod tests { box BooleanExpression::Identifier("x".into()), box BooleanExpression::Identifier("y".into()), ), - None, + AssertionType::Source("".to_string()), ), ], signature: Signature { @@ -2724,7 +2724,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Number(Bn128Field::from(1)), ), - RuntimeError::Source(None), + RuntimeError::Source("".to_string()), ), ], }; @@ -2762,7 +2762,7 @@ mod tests { ), box FieldElementExpression::Identifier("y".into()), ), - None, + AssertionType::Source("".to_string()), ), ], signature: Signature { @@ -2795,7 +2795,7 @@ mod tests { ), box FlatExpression::Number(Bn128Field::from(1)), ), - RuntimeError::Source(None), + RuntimeError::Source("".to_string()), ), ], }; @@ -2834,7 +2834,7 @@ mod tests { .metadata(metadata.clone()), box UExpressionInner::Value(42).annotate(32).metadata(metadata), ), - None, + AssertionType::Source("".to_string()), ), ], signature: Signature { @@ -2860,7 +2860,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Number(Bn128Field::from(1)), ), - RuntimeError::Source(None), + RuntimeError::Source("".to_string()), ), ], }; @@ -2895,7 +2895,7 @@ mod tests { box FieldElementExpression::Identifier("x".into()), box FieldElementExpression::Identifier("y".into()), ), - None, + AssertionType::Source("".to_string()), ), ], signature: Signature { @@ -2925,7 +2925,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Number(Bn128Field::from(1)), ), - RuntimeError::Source(None), + RuntimeError::Source("".to_string()), ), ], }; @@ -2969,7 +2969,7 @@ mod tests { ), box FieldElementExpression::Identifier("z".into()), ), - None, + AssertionType::Source("".to_string()), ), ], signature: Signature { @@ -3003,7 +3003,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Identifier(FlatVariable::new(1)), ), - RuntimeError::Source(None), + RuntimeError::Source("".to_string()), ), ], }; @@ -3047,7 +3047,7 @@ mod tests { box FieldElementExpression::Identifier("y".into()), ), ), - None, + AssertionType::Source("".to_string()), ), ], signature: Signature { @@ -3081,7 +3081,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Identifier(FlatVariable::new(1)), ), - RuntimeError::Source(None), + RuntimeError::Source("".to_string()), ), ], }; @@ -3135,7 +3135,7 @@ mod tests { box FieldElementExpression::Identifier("t".into()), ), ), - None, + AssertionType::Source("".to_string()), ), ], signature: Signature { @@ -3180,7 +3180,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Identifier(FlatVariable::new(1)), ), - RuntimeError::Source(None), + RuntimeError::Source("".to_string()), ), ], }; diff --git a/zokrates_core/src/static_analysis/zir_propagation.rs b/zokrates_core/src/static_analysis/zir_propagation.rs index 8e0b7714..7699ce23 100644 --- a/zokrates_core/src/static_analysis/zir_propagation.rs +++ b/zokrates_core/src/static_analysis/zir_propagation.rs @@ -654,6 +654,7 @@ impl<'ast, T: Field> ResultFolder<'ast, T> for ZirPropagator<'ast, T> { #[cfg(test)] mod tests { use super::*; + use crate::zir::AssertionType; use zokrates_field::Bn128Field; #[test] @@ -670,7 +671,7 @@ mod tests { box FieldElementExpression::Number(Bn128Field::from(1)), ), ), - None, + AssertionType::Source("".to_string()), )]; let mut propagator = ZirPropagator::default(); @@ -690,7 +691,7 @@ mod tests { box FieldElementExpression::Identifier("x".into()), box FieldElementExpression::Identifier("y".into()), ), - None + AssertionType::Source("".to_string()) )] ); } From 035a193f58d7d330352c3ac050878f7daae780fb Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 13 Oct 2021 18:48:18 +0200 Subject: [PATCH 22/23] apply suggestions --- zokrates_core/src/flat_absy/mod.rs | 6 +- zokrates_core/src/flatten/mod.rs | 74 +++++++++++-------- zokrates_core/src/semantics.rs | 2 +- .../static_analysis/flatten_complex_types.rs | 12 +-- .../static_analysis/variable_write_remover.rs | 2 +- .../src/static_analysis/zir_propagation.rs | 16 ++-- zokrates_core/src/typed_absy/folder.rs | 4 +- zokrates_core/src/typed_absy/mod.rs | 20 ++--- zokrates_core/src/typed_absy/result_folder.rs | 4 +- zokrates_core/src/zir/folder.rs | 4 +- zokrates_core/src/zir/mod.rs | 20 ++--- zokrates_core/src/zir/result_folder.rs | 4 +- 12 files changed, 96 insertions(+), 72 deletions(-) diff --git a/zokrates_core/src/flat_absy/mod.rs b/zokrates_core/src/flat_absy/mod.rs index cd5ed915..4f73c126 100644 --- a/zokrates_core/src/flat_absy/mod.rs +++ b/zokrates_core/src/flat_absy/mod.rs @@ -43,7 +43,7 @@ pub enum RuntimeError { Euclidean, ShaXor, Division, - Source(String), + SourceAssertion(String), ArgumentBitness, SelectRangeCheck, } @@ -54,7 +54,7 @@ impl RuntimeError { !matches!( self, - Source(_) | Inverse | LtSum | SelectRangeCheck | ArgumentBitness + SourceAssertion(_) | Inverse | LtSum | SelectRangeCheck | ArgumentBitness ) } } @@ -87,7 +87,7 @@ impl fmt::Display for RuntimeError { Euclidean => "Euclidean check failed", ShaXor => "Internal Sha check failed", Division => "Division check failed", - Source(m) => m.as_str(), + SourceAssertion(m) => m.as_str(), ArgumentBitness => "Argument bitness check failed", SelectRangeCheck => "Out of bounds array access", }; diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index 011fcfa3..ba73cc41 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -12,7 +12,7 @@ use crate::ir::Interpreter; use crate::compile::CompileConfig; use crate::embed::FlatEmbed; -use crate::flat_absy::*; +use crate::flat_absy::{RuntimeError, *}; use crate::solvers::Solver; use crate::zir::types::{Type, UBitwidth}; use crate::zir::*; @@ -146,11 +146,11 @@ impl FlatUExpression { } } -impl From for RuntimeError { - fn from(ty: AssertionType) -> Self { - match ty { - AssertionType::Source(s) => RuntimeError::Source(s), - AssertionType::SelectRangeCheck => RuntimeError::SelectRangeCheck, +impl From for RuntimeError { + fn from(error: crate::zir::RuntimeError) -> Self { + match error { + crate::zir::RuntimeError::SourceAssertion(s) => RuntimeError::SourceAssertion(s), + crate::zir::RuntimeError::SelectRangeCheck => RuntimeError::SelectRangeCheck, } } } @@ -2379,13 +2379,13 @@ impl<'ast, T: Field> Flattener<'ast, T> { .insert(FlatExpression::Identifier(var), bits); } } - ZirStatement::Assertion(e, ty) => { + ZirStatement::Assertion(e, error) => { match e { BooleanExpression::And(..) => { for boolean in e.into_conjunction_iterator() { self.flatten_statement( statements_flattened, - ZirStatement::Assertion(boolean, ty.clone()), + ZirStatement::Assertion(boolean, error.clone()), ) } } @@ -2393,7 +2393,12 @@ impl<'ast, T: Field> Flattener<'ast, T> { let lhs = self.flatten_field_expression(statements_flattened, lhs); let rhs = self.flatten_field_expression(statements_flattened, rhs); - self.flatten_equality_assertion(statements_flattened, lhs, rhs, ty) + self.flatten_equality_assertion( + statements_flattened, + lhs, + rhs, + error.into(), + ) } BooleanExpression::UintEq(box lhs, box rhs) => { let lhs = self @@ -2403,13 +2408,23 @@ impl<'ast, T: Field> Flattener<'ast, T> { .flatten_uint_expression(statements_flattened, rhs) .get_field_unchecked(); - self.flatten_equality_assertion(statements_flattened, lhs, rhs, ty) + self.flatten_equality_assertion( + statements_flattened, + lhs, + rhs, + error.into(), + ) } BooleanExpression::BoolEq(box lhs, box rhs) => { let lhs = self.flatten_boolean_expression(statements_flattened, lhs); let rhs = self.flatten_boolean_expression(statements_flattened, rhs); - self.flatten_equality_assertion(statements_flattened, lhs, rhs, ty) + self.flatten_equality_assertion( + statements_flattened, + lhs, + rhs, + error.into(), + ) } _ => { // naive approach: flatten the boolean to a single field element and constrain it to 1 @@ -2419,14 +2434,14 @@ impl<'ast, T: Field> Flattener<'ast, T> { statements_flattened.push(FlatStatement::Condition( e, FlatExpression::Number(T::from(1)), - ty.into(), + error.into(), )); } else { // swap so that left side is linear statements_flattened.push(FlatStatement::Condition( FlatExpression::Number(T::from(1)), e, - ty.into(), + error.into(), )); } } @@ -2538,7 +2553,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { statements_flattened: &mut FlatStatements, lhs: FlatExpression, rhs: FlatExpression, - assertion_type: AssertionType, + error: RuntimeError, ) { let (lhs, rhs) = match (lhs, rhs) { (FlatExpression::Mult(box x, box y), z) | (z, FlatExpression::Mult(box x, box y)) => ( @@ -2556,7 +2571,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { ), ), }; - statements_flattened.push(FlatStatement::Condition(lhs, rhs, assertion_type.into())); + statements_flattened.push(FlatStatement::Condition(lhs, rhs, error)); } /// Identifies a non-linear expression by assigning it to a new identifier. @@ -2663,6 +2678,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { #[cfg(test)] mod tests { use super::*; + use crate::zir; use crate::zir::types::Signature; use crate::zir::types::Type; use zokrates_field::Bn128Field; @@ -2694,7 +2710,7 @@ mod tests { box BooleanExpression::Identifier("x".into()), box BooleanExpression::Identifier("y".into()), ), - AssertionType::Source("".to_string()), + zir::RuntimeError::mock(), ), ], signature: Signature { @@ -2724,7 +2740,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Number(Bn128Field::from(1)), ), - RuntimeError::Source("".to_string()), + zir::RuntimeError::mock().into(), ), ], }; @@ -2762,7 +2778,7 @@ mod tests { ), box FieldElementExpression::Identifier("y".into()), ), - AssertionType::Source("".to_string()), + zir::RuntimeError::mock(), ), ], signature: Signature { @@ -2795,7 +2811,7 @@ mod tests { ), box FlatExpression::Number(Bn128Field::from(1)), ), - RuntimeError::Source("".to_string()), + zir::RuntimeError::mock().into(), ), ], }; @@ -2834,7 +2850,7 @@ mod tests { .metadata(metadata.clone()), box UExpressionInner::Value(42).annotate(32).metadata(metadata), ), - AssertionType::Source("".to_string()), + zir::RuntimeError::mock(), ), ], signature: Signature { @@ -2860,7 +2876,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Number(Bn128Field::from(1)), ), - RuntimeError::Source("".to_string()), + zir::RuntimeError::mock().into(), ), ], }; @@ -2895,7 +2911,7 @@ mod tests { box FieldElementExpression::Identifier("x".into()), box FieldElementExpression::Identifier("y".into()), ), - AssertionType::Source("".to_string()), + zir::RuntimeError::mock(), ), ], signature: Signature { @@ -2925,7 +2941,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Number(Bn128Field::from(1)), ), - RuntimeError::Source("".to_string()), + zir::RuntimeError::mock().into(), ), ], }; @@ -2969,7 +2985,7 @@ mod tests { ), box FieldElementExpression::Identifier("z".into()), ), - AssertionType::Source("".to_string()), + zir::RuntimeError::mock(), ), ], signature: Signature { @@ -3003,7 +3019,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Identifier(FlatVariable::new(1)), ), - RuntimeError::Source("".to_string()), + zir::RuntimeError::mock().into(), ), ], }; @@ -3047,7 +3063,7 @@ mod tests { box FieldElementExpression::Identifier("y".into()), ), ), - AssertionType::Source("".to_string()), + zir::RuntimeError::mock(), ), ], signature: Signature { @@ -3081,7 +3097,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Identifier(FlatVariable::new(1)), ), - RuntimeError::Source("".to_string()), + zir::RuntimeError::mock().into(), ), ], }; @@ -3135,7 +3151,7 @@ mod tests { box FieldElementExpression::Identifier("t".into()), ), ), - AssertionType::Source("".to_string()), + zir::RuntimeError::mock(), ), ], signature: Signature { @@ -3180,7 +3196,7 @@ mod tests { box FlatExpression::Identifier(FlatVariable::new(0)), box FlatExpression::Identifier(FlatVariable::new(1)), ), - RuntimeError::Source("".to_string()), + zir::RuntimeError::mock().into(), ), ], }; diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 0a5b3c92..0cbd7eaf 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -1741,7 +1741,7 @@ impl<'ast, T: Field> Checker<'ast, T> { match e { TypedExpression::Boolean(e) => Ok(TypedStatement::Assertion( e, - AssertionType::Source(AssertionMetadata { + RuntimeError::SourceAssertion(AssertionMetadata { file: module_id.display().to_string(), position: pos.0, message, diff --git a/zokrates_core/src/static_analysis/flatten_complex_types.rs b/zokrates_core/src/static_analysis/flatten_complex_types.rs index 2f1435e7..1986efde 100644 --- a/zokrates_core/src/static_analysis/flatten_complex_types.rs +++ b/zokrates_core/src/static_analysis/flatten_complex_types.rs @@ -379,15 +379,15 @@ fn fold_statement<'ast, T: Field>( typed_absy::TypedStatement::Declaration(..) => { unreachable!() } - typed_absy::TypedStatement::Assertion(e, ty) => { + typed_absy::TypedStatement::Assertion(e, error) => { let e = f.fold_boolean_expression(statements_buffer, e); - let ty = match ty { - typed_absy::AssertionType::Source(metadata) => { - zir::AssertionType::Source(metadata.to_string()) + let error = match error { + typed_absy::RuntimeError::SourceAssertion(metadata) => { + zir::RuntimeError::SourceAssertion(metadata.to_string()) } - typed_absy::AssertionType::SelectRangeCheck => zir::AssertionType::SelectRangeCheck, + typed_absy::RuntimeError::SelectRangeCheck => zir::RuntimeError::SelectRangeCheck, }; - vec![zir::ZirStatement::Assertion(e, ty)] + vec![zir::ZirStatement::Assertion(e, error)] } typed_absy::TypedStatement::For(..) => unreachable!(), typed_absy::TypedStatement::MultipleDefinition(variables, elist) => { diff --git a/zokrates_core/src/static_analysis/variable_write_remover.rs b/zokrates_core/src/static_analysis/variable_write_remover.rs index 614e5b28..bce07349 100644 --- a/zokrates_core/src/static_analysis/variable_write_remover.rs +++ b/zokrates_core/src/static_analysis/variable_write_remover.rs @@ -49,7 +49,7 @@ impl<'ast> VariableWriteRemover { Access::Select(head) => { statements.insert(TypedStatement::Assertion( BooleanExpression::UintLt(box head.clone(), box size.into()), - AssertionType::SelectRangeCheck, + RuntimeError::SelectRangeCheck, )); ArrayExpressionInner::Value( diff --git a/zokrates_core/src/static_analysis/zir_propagation.rs b/zokrates_core/src/static_analysis/zir_propagation.rs index 7699ce23..138a9c21 100644 --- a/zokrates_core/src/static_analysis/zir_propagation.rs +++ b/zokrates_core/src/static_analysis/zir_propagation.rs @@ -51,9 +51,9 @@ impl<'ast, T: Field> ResultFolder<'ast, T> for ZirPropagator<'ast, T> { s: ZirStatement<'ast, T>, ) -> Result>, Self::Error> { match s { - ZirStatement::Assertion(e, m) => match self.fold_boolean_expression(e)? { + ZirStatement::Assertion(e, error) => match self.fold_boolean_expression(e)? { BooleanExpression::Value(true) => Ok(vec![]), - e => Ok(vec![ZirStatement::Assertion(e, m)]), + e => Ok(vec![ZirStatement::Assertion(e, error)]), }, ZirStatement::Definition(a, e) => { let e = self.fold_expression(e)?; @@ -654,9 +654,15 @@ impl<'ast, T: Field> ResultFolder<'ast, T> for ZirPropagator<'ast, T> { #[cfg(test)] mod tests { use super::*; - use crate::zir::AssertionType; + use crate::zir::RuntimeError; use zokrates_field::Bn128Field; + impl RuntimeError { + pub fn mock() -> Self { + RuntimeError::SourceAssertion(String::default()) + } + } + #[test] fn propagation() { // assert([x, 1] == [y, 1]) @@ -671,7 +677,7 @@ mod tests { box FieldElementExpression::Number(Bn128Field::from(1)), ), ), - AssertionType::Source("".to_string()), + RuntimeError::mock(), )]; let mut propagator = ZirPropagator::default(); @@ -691,7 +697,7 @@ mod tests { box FieldElementExpression::Identifier("x".into()), box FieldElementExpression::Identifier("y".into()), ), - AssertionType::Source("".to_string()) + RuntimeError::mock() )] ); } diff --git a/zokrates_core/src/typed_absy/folder.rs b/zokrates_core/src/typed_absy/folder.rs index ef91db57..6a60e65a 100644 --- a/zokrates_core/src/typed_absy/folder.rs +++ b/zokrates_core/src/typed_absy/folder.rs @@ -461,8 +461,8 @@ pub fn fold_statement<'ast, T: Field, F: Folder<'ast, T>>( TypedStatement::Definition(f.fold_assignee(a), f.fold_expression(e)) } TypedStatement::Declaration(v) => TypedStatement::Declaration(f.fold_variable(v)), - TypedStatement::Assertion(e, ty) => { - TypedStatement::Assertion(f.fold_boolean_expression(e), ty) + TypedStatement::Assertion(e, error) => { + TypedStatement::Assertion(f.fold_boolean_expression(e), error) } TypedStatement::For(v, from, to, statements) => TypedStatement::For( f.fold_variable(v), diff --git a/zokrates_core/src/typed_absy/mod.rs b/zokrates_core/src/typed_absy/mod.rs index de7dc6e9..6c970ff3 100644 --- a/zokrates_core/src/typed_absy/mod.rs +++ b/zokrates_core/src/typed_absy/mod.rs @@ -594,16 +594,16 @@ impl fmt::Display for AssertionMetadata { } #[derive(Debug, Clone, PartialEq, Hash, Eq, PartialOrd, Ord)] -pub enum AssertionType { - Source(AssertionMetadata), +pub enum RuntimeError { + SourceAssertion(AssertionMetadata), SelectRangeCheck, } -impl fmt::Display for AssertionType { +impl fmt::Display for RuntimeError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - AssertionType::Source(metadata) => write!(f, "{}", metadata), - AssertionType::SelectRangeCheck => write!(f, "Range check on array access"), + RuntimeError::SourceAssertion(metadata) => write!(f, "{}", metadata), + RuntimeError::SelectRangeCheck => write!(f, "Range check on array access"), } } } @@ -615,7 +615,7 @@ pub enum TypedStatement<'ast, T> { Return(Vec>), Definition(TypedAssignee<'ast, T>, TypedExpression<'ast, T>), Declaration(Variable<'ast, T>), - Assertion(BooleanExpression<'ast, T>, AssertionType), + Assertion(BooleanExpression<'ast, T>, RuntimeError), For( Variable<'ast, T>, UExpression<'ast, T>, @@ -663,14 +663,14 @@ impl<'ast, T: fmt::Display> fmt::Display for TypedStatement<'ast, T> { } TypedStatement::Declaration(ref var) => write!(f, "{}", var), TypedStatement::Definition(ref lhs, ref rhs) => write!(f, "{} = {}", lhs, rhs), - TypedStatement::Assertion(ref e, ref ty) => { + TypedStatement::Assertion(ref e, ref error) => { write!(f, "assert({}", e)?; - match ty { - AssertionType::Source(metadata) => match &metadata.message { + match error { + RuntimeError::SourceAssertion(metadata) => match &metadata.message { Some(m) => write!(f, ", \"{}\")", m), None => write!(f, ")"), }, - internal => write!(f, ") // {}", internal), + error => write!(f, ") // {}", error), } } TypedStatement::For(ref var, ref start, ref stop, ref list) => { diff --git a/zokrates_core/src/typed_absy/result_folder.rs b/zokrates_core/src/typed_absy/result_folder.rs index b173a668..62a745af 100644 --- a/zokrates_core/src/typed_absy/result_folder.rs +++ b/zokrates_core/src/typed_absy/result_folder.rs @@ -458,8 +458,8 @@ pub fn fold_statement<'ast, T: Field, F: ResultFolder<'ast, T>>( TypedStatement::Definition(f.fold_assignee(a)?, f.fold_expression(e)?) } TypedStatement::Declaration(v) => TypedStatement::Declaration(f.fold_variable(v)?), - TypedStatement::Assertion(e, ty) => { - TypedStatement::Assertion(f.fold_boolean_expression(e)?, ty) + TypedStatement::Assertion(e, error) => { + TypedStatement::Assertion(f.fold_boolean_expression(e)?, error) } TypedStatement::For(v, from, to, statements) => TypedStatement::For( f.fold_variable(v)?, diff --git a/zokrates_core/src/zir/folder.rs b/zokrates_core/src/zir/folder.rs index 88d0eb4e..cdd4534a 100644 --- a/zokrates_core/src/zir/folder.rs +++ b/zokrates_core/src/zir/folder.rs @@ -115,7 +115,9 @@ pub fn fold_statement<'ast, T: Field, F: Folder<'ast, T>>( .flat_map(|e| f.fold_statement(e)) .collect(), ), - ZirStatement::Assertion(e, ty) => ZirStatement::Assertion(f.fold_boolean_expression(e), ty), + ZirStatement::Assertion(e, error) => { + ZirStatement::Assertion(f.fold_boolean_expression(e), error) + } ZirStatement::MultipleDefinition(variables, elist) => ZirStatement::MultipleDefinition( variables.into_iter().map(|v| f.fold_variable(v)).collect(), f.fold_expression_list(elist), diff --git a/zokrates_core/src/zir/mod.rs b/zokrates_core/src/zir/mod.rs index 2d0fded6..9978ed14 100644 --- a/zokrates_core/src/zir/mod.rs +++ b/zokrates_core/src/zir/mod.rs @@ -86,16 +86,16 @@ impl<'ast, T: fmt::Debug> fmt::Debug for ZirFunction<'ast, T> { pub type ZirAssignee<'ast> = Variable<'ast>; #[derive(Debug, Clone, PartialEq, Hash, Eq)] -pub enum AssertionType { - Source(String), +pub enum RuntimeError { + SourceAssertion(String), SelectRangeCheck, } -impl fmt::Display for AssertionType { +impl fmt::Display for RuntimeError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - AssertionType::Source(message) => write!(f, "{}", message), - AssertionType::SelectRangeCheck => write!(f, "Range check on array access"), + RuntimeError::SourceAssertion(message) => write!(f, "{}", message), + RuntimeError::SelectRangeCheck => write!(f, "Range check on array access"), } } } @@ -110,7 +110,7 @@ pub enum ZirStatement<'ast, T> { Vec>, Vec>, ), - Assertion(BooleanExpression<'ast, T>, AssertionType), + Assertion(BooleanExpression<'ast, T>, RuntimeError), MultipleDefinition(Vec>, ZirExpressionList<'ast, T>), } @@ -145,11 +145,11 @@ impl<'ast, T: fmt::Display> fmt::Display for ZirStatement<'ast, T> { .join("\n") ) } - ZirStatement::Assertion(ref e, ref ty) => { + ZirStatement::Assertion(ref e, ref error) => { write!(f, "assert({}", e)?; - match ty { - AssertionType::Source(message) => write!(f, ", \"{}\")", message), - internal => write!(f, ") // {}", internal), + match error { + RuntimeError::SourceAssertion(message) => write!(f, ", \"{}\")", message), + error => write!(f, ") // {}", error), } } ZirStatement::MultipleDefinition(ref ids, ref rhs) => { diff --git a/zokrates_core/src/zir/result_folder.rs b/zokrates_core/src/zir/result_folder.rs index 47462c2f..d36c7c96 100644 --- a/zokrates_core/src/zir/result_folder.rs +++ b/zokrates_core/src/zir/result_folder.rs @@ -137,8 +137,8 @@ pub fn fold_statement<'ast, T: Field, F: ResultFolder<'ast, T>>( .flatten() .collect(), ), - ZirStatement::Assertion(e, ty) => { - ZirStatement::Assertion(f.fold_boolean_expression(e)?, ty) + ZirStatement::Assertion(e, error) => { + ZirStatement::Assertion(f.fold_boolean_expression(e)?, error) } ZirStatement::MultipleDefinition(variables, elist) => ZirStatement::MultipleDefinition( variables From c3288b93c59a9e19e0fb99e50ca37d01b49eaa11 Mon Sep 17 00:00:00 2001 From: dark64 Date: Wed, 13 Oct 2021 19:03:06 +0200 Subject: [PATCH 23/23] fix tests --- zokrates_core_test/tests/tests/assert_one.json | 2 +- .../tests/panics/conditional_bound_throw_no_isolation.json | 6 +++--- .../tests/tests/panics/deep_branch_no_isolation.json | 2 +- zokrates_core_test/tests/tests/panics/loop_bound.json | 2 +- zokrates_core_test/tests/tests/panics/panic_isolation.json | 2 +- .../tests/tests/panics/panic_no_isolation.json | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/zokrates_core_test/tests/tests/assert_one.json b/zokrates_core_test/tests/tests/assert_one.json index 7791e6bb..ef7fd1da 100644 --- a/zokrates_core_test/tests/tests/assert_one.json +++ b/zokrates_core_test/tests/tests/assert_one.json @@ -12,7 +12,7 @@ "left": "0", "right": "1", "error": { - "Source": "Assertion failed at ./tests/tests/assert_one.zok:2:2" + "SourceAssertion": "Assertion failed at ./tests/tests/assert_one.zok:2:2" } } } diff --git a/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json b/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json index 4402beb1..a709d916 100644 --- a/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json +++ b/zokrates_core_test/tests/tests/panics/conditional_bound_throw_no_isolation.json @@ -14,7 +14,7 @@ "left": "0", "right": "1", "error": { - "Source": "Assertion failed at ./tests/tests/panics/conditional_bound_throw.zok:2:5" + "SourceAssertion": "Assertion failed at ./tests/tests/panics/conditional_bound_throw.zok:2:5" } } } @@ -32,7 +32,7 @@ "left": "1", "right": "0", "error": { - "Source": "Assertion failed at ./tests/tests/panics/conditional_bound_throw.zok:2:5" + "SourceAssertion": "Assertion failed at ./tests/tests/panics/conditional_bound_throw.zok:2:5" } } } @@ -50,7 +50,7 @@ "left": "2", "right": "0", "error": { - "Source": "Assertion failed at ./tests/tests/panics/conditional_bound_throw.zok:2:5" + "SourceAssertion": "Assertion failed at ./tests/tests/panics/conditional_bound_throw.zok:2:5" } } } diff --git a/zokrates_core_test/tests/tests/panics/deep_branch_no_isolation.json b/zokrates_core_test/tests/tests/panics/deep_branch_no_isolation.json index d89b6a1d..51a74761 100644 --- a/zokrates_core_test/tests/tests/panics/deep_branch_no_isolation.json +++ b/zokrates_core_test/tests/tests/panics/deep_branch_no_isolation.json @@ -14,7 +14,7 @@ "left": "0", "right": "1", "error": { - "Source": "Assertion failed at ./tests/tests/panics/deep_branch.zok:2:5" + "SourceAssertion": "Assertion failed at ./tests/tests/panics/deep_branch.zok:2:5" } } } diff --git a/zokrates_core_test/tests/tests/panics/loop_bound.json b/zokrates_core_test/tests/tests/panics/loop_bound.json index a3599f3b..2891415e 100644 --- a/zokrates_core_test/tests/tests/panics/loop_bound.json +++ b/zokrates_core_test/tests/tests/panics/loop_bound.json @@ -14,7 +14,7 @@ "left": "0", "right": "1", "error": { - "Source": "Assertion failed at ./tests/tests/panics/loop_bound.zok:2:3" + "SourceAssertion": "Assertion failed at ./tests/tests/panics/loop_bound.zok:2:3" } } } diff --git a/zokrates_core_test/tests/tests/panics/panic_isolation.json b/zokrates_core_test/tests/tests/panics/panic_isolation.json index 703b0dea..573da700 100644 --- a/zokrates_core_test/tests/tests/panics/panic_isolation.json +++ b/zokrates_core_test/tests/tests/panics/panic_isolation.json @@ -21,7 +21,7 @@ "left": "1", "right": "21888242871839275222246405745257275088548364400416034343698204186575808495577", "error": { - "Source": "Assertion failed at ./tests/tests/panics/panic_isolation.zok:18:5" + "SourceAssertion": "Assertion failed at ./tests/tests/panics/panic_isolation.zok:18:5" } } } diff --git a/zokrates_core_test/tests/tests/panics/panic_no_isolation.json b/zokrates_core_test/tests/tests/panics/panic_no_isolation.json index f2b562e8..c0a9bab0 100644 --- a/zokrates_core_test/tests/tests/panics/panic_no_isolation.json +++ b/zokrates_core_test/tests/tests/panics/panic_no_isolation.json @@ -21,7 +21,7 @@ "left": "1", "right": "0", "error": { - "Source": "Assertion failed at ./tests/tests/panics/panic_isolation.zok:14:5" + "SourceAssertion": "Assertion failed at ./tests/tests/panics/panic_isolation.zok:14:5" } } }