1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

merge dev

This commit is contained in:
schaeff 2021-10-13 01:05:41 +03:00
commit 6798b02a13
28 changed files with 192 additions and 199 deletions

View file

@ -305,4 +305,4 @@ workflows:
- wasm_test
- integration_test
- zokrates_js_build
- zokrates_js_test
- zokrates_js_test

View file

@ -1,6 +1,8 @@
FROM ubuntu:18.04
SHELL ["/bin/bash", "-c"]
ARG RUST_VERSION=nightly
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH
@ -29,7 +31,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain none -y \
&& rustup toolchain install nightly --allow-downgrade --profile minimal --component rustfmt clippy \
&& rustup toolchain install $RUST_VERSION --allow-downgrade --profile minimal --component rustfmt clippy \
&& cargo install --git https://github.com/rustwasm/wasm-pack \
&& rm -rf /usr/local/cargo/registry \
&& curl -sL https://deb.nodesource.com/setup_lts.x | bash - && apt-get install -y nodejs && npm i -g solc \

View file

@ -1 +0,0 @@
nightly-2021-04-25

View file

@ -1,2 +1,2 @@
[toolchain]
channel = "nightly-2021-04-25"
channel = "nightly-2021-08-01"

View file

@ -195,7 +195,7 @@ mod tests {
let interpreter = ir::Interpreter::default();
let _ = interpreter
.execute(&artifacts.prog(), &[Bn128Field::from(0)])
.execute(artifacts.prog(), &[Bn128Field::from(0)])
.unwrap();
}
}
@ -226,7 +226,7 @@ mod tests {
let interpreter = ir::Interpreter::default();
let res = interpreter.execute(&artifacts.prog(), &[Bn128Field::from(0)]);
let res = interpreter.execute(artifacts.prog(), &[Bn128Field::from(0)]);
assert!(res.is_err());
}

View file

@ -99,7 +99,7 @@ fn cli_export_verifier<T: SolidityCompatibleField, S: SolidityCompatibleScheme<T
let mut writer = BufWriter::new(output_file);
writer
.write_all(&verifier.as_bytes())
.write_all(verifier.as_bytes())
.map_err(|_| "Failed writing output to file".to_string())?;
println!("Verifier exported to '{}'", output_path.display());

View file

@ -64,5 +64,5 @@ zokrates_fs_resolver = { version = "0.5", path = "../zokrates_fs_resolver"}
[build-dependencies]
cc = { version = "1.0", features = ["parallel"], optional = true }
cmake = { version = "0.1.31", optional = true }
cmake = { version = "=0.1.45", optional = true }
git2 = { version = "0.13.1", optional = true }

View file

@ -636,7 +636,7 @@ impl<'ast> From<pest::PostfixExpression<'ast>> for absy::ExpressionNode<'ast> {
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,
id_str,
a.explicit_generics.map(|explicit_generics| {
explicit_generics
.values
@ -679,7 +679,7 @@ impl<'ast> From<pest::DecimalLiteralExpression<'ast>> for absy::ExpressionNode<'
match expression.suffix {
Some(suffix) => match suffix {
pest::DecimalSuffix::Field(_) => absy::Expression::FieldConstant(
BigUint::parse_bytes(&expression.value.span.as_str().as_bytes(), 10).unwrap(),
BigUint::parse_bytes(expression.value.span.as_str().as_bytes(), 10).unwrap(),
),
pest::DecimalSuffix::U64(_) => {
absy::Expression::U64Constant(expression.value.span.as_str().parse().unwrap())
@ -696,7 +696,7 @@ impl<'ast> From<pest::DecimalLiteralExpression<'ast>> for absy::ExpressionNode<'
}
.span(expression.span),
None => absy::Expression::IntConstant(
BigUint::parse_bytes(&expression.value.span.as_str().as_bytes(), 10).unwrap(),
BigUint::parse_bytes(expression.value.span.as_str().as_bytes(), 10).unwrap(),
)
.span(expression.span),
}
@ -709,16 +709,16 @@ impl<'ast> From<pest::HexLiteralExpression<'ast>> for absy::ExpressionNode<'ast>
match expression.value {
pest::HexNumberExpression::U64(e) => {
absy::Expression::U64Constant(u64::from_str_radix(&e.span.as_str(), 16).unwrap())
absy::Expression::U64Constant(u64::from_str_radix(e.span.as_str(), 16).unwrap())
}
pest::HexNumberExpression::U32(e) => {
absy::Expression::U32Constant(u32::from_str_radix(&e.span.as_str(), 16).unwrap())
absy::Expression::U32Constant(u32::from_str_radix(e.span.as_str(), 16).unwrap())
}
pest::HexNumberExpression::U16(e) => {
absy::Expression::U16Constant(u16::from_str_radix(&e.span.as_str(), 16).unwrap())
absy::Expression::U16Constant(u16::from_str_radix(e.span.as_str(), 16).unwrap())
}
pest::HexNumberExpression::U8(e) => {
absy::Expression::U8Constant(u8::from_str_radix(&e.span.as_str(), 16).unwrap())
absy::Expression::U8Constant(u8::from_str_radix(e.span.as_str(), 16).unwrap())
}
}
.span(expression.span)
@ -865,7 +865,7 @@ mod tests {
#[test]
fn return_forty_two() {
let source = "def main() -> field: return 42";
let ast = pest::generate_ast(&source).unwrap();
let ast = pest::generate_ast(source).unwrap();
let expected: absy::Module = absy::Module {
symbols: vec![absy::SymbolDeclaration {
id: &source[4..8],
@ -896,7 +896,7 @@ mod tests {
#[test]
fn return_true() {
let source = "def main() -> bool: return true";
let ast = pest::generate_ast(&source).unwrap();
let ast = pest::generate_ast(source).unwrap();
let expected: absy::Module = absy::Module {
symbols: vec![absy::SymbolDeclaration {
id: &source[4..8],
@ -925,7 +925,7 @@ mod tests {
#[test]
fn arguments() {
let source = "def main(private field a, bool b) -> field: return 42";
let ast = pest::generate_ast(&source).unwrap();
let ast = pest::generate_ast(source).unwrap();
let expected: absy::Module = absy::Module {
symbols: vec![absy::SymbolDeclaration {
@ -1154,7 +1154,7 @@ mod tests {
fn call_array_element() {
// a call after an array access should be rejected
let source = "def main(): return a[2](3)";
let ast = pest::generate_ast(&source).unwrap();
let ast = pest::generate_ast(source).unwrap();
absy::Module::from(ast);
}
@ -1163,7 +1163,7 @@ mod tests {
fn call_call_result() {
// a call after a call should be rejected
let source = "def main(): return a(2)(3)";
let ast = pest::generate_ast(&source).unwrap();
let ast = pest::generate_ast(source).unwrap();
absy::Module::from(ast);
}
}
@ -1171,7 +1171,7 @@ mod tests {
fn declarations() {
use self::pest::Span;
let span = Span::new(&"", 0, 0).unwrap();
let span = Span::new("", 0, 0).unwrap();
// For different definitions, we generate declarations
// Case 1: `id = expr` where `expr` is not a function call
@ -1190,7 +1190,7 @@ mod tests {
expression: pest::Expression::Literal(pest::LiteralExpression::DecimalLiteral(
pest::DecimalLiteralExpression {
value: pest::DecimalNumber {
span: Span::new(&"1", 0, 1).unwrap(),
span: Span::new("1", 0, 1).unwrap(),
},
suffix: None,
span: span.clone(),

View file

@ -243,7 +243,7 @@ fn check_with_arena<'ast, T: Field, E: Into<imports::Error>>(
log::debug!("Parse program with entry file {}", location.display());
let compiled = parse_program::<T, E>(source, location, resolver, &arena)?;
let compiled = parse_program::<T, E>(source, location, resolver, arena)?;
log::debug!("Check semantics");
@ -271,7 +271,7 @@ pub fn parse_program<'ast, T: Field, E: Into<imports::Error>>(
) -> Result<Program<'ast>, CompileErrors> {
let mut modules = HashMap::new();
let main = parse_module::<T, E>(&source, location.clone(), resolver, &mut modules, &arena)?;
let main = parse_module::<T, E>(source, location.clone(), resolver, &mut modules, arena)?;
modules.insert(location.clone(), main);
@ -290,7 +290,7 @@ pub fn parse_module<'ast, T: Field, E: Into<imports::Error>>(
) -> Result<Module<'ast>, CompileErrors> {
log::debug!("Generate pest AST for {}", location.display());
let ast = pest::generate_ast(&source)
let ast = pest::generate_ast(source)
.map_err(|e| CompileErrors::from(CompileErrorInner::from(e).in_file(&location)))?;
log::debug!("Process macros for {}", location.display());
@ -309,7 +309,7 @@ pub fn parse_module<'ast, T: Field, E: Into<imports::Error>>(
location.clone(),
resolver,
modules,
&arena,
arena,
)
}

View file

@ -2202,7 +2202,10 @@ impl<'ast, T: Field> Flattener<'ast, T> {
// convert the exponent to bytes, big endian
let ebytes_be = e.to_be_bytes();
// convert the bytes to bits, remove leading zeroes (we only need powers up to the highest non-zero bit)
#[allow(clippy::needless_collect)]
// collecting is required as we then reverse
let ebits_be: Vec<_> = ebytes_be
.iter()
.flat_map(|byte| (0..8).rev().map(move |i| byte & (1 << i) != 0)) // byte to bit, big endian

View file

@ -231,7 +231,7 @@ impl Importer {
new_location.clone(),
resolver,
modules,
&arena,
arena,
)?;
assert!(modules.insert(new_location.clone(), compiled).is_none());
@ -239,7 +239,7 @@ impl Importer {
};
SymbolDeclaration {
id: &alias,
id: alias,
symbol: Symbol::There(
SymbolImport::with_id_in_module(symbol.id, new_location)
.start_end(pos.0, pos.1),

View file

@ -10,20 +10,13 @@ pub type ExecutionResult<T> = Result<Witness<T>, Error>;
impl<T: Field> Prog<T> {}
#[derive(Default)]
pub struct Interpreter {
/// Whether we should try to give out-of-range bit decompositions when the input is not a single summand.
/// Used to do targetted testing of `<` flattening, making sure the bit decomposition we base the result on is unique.
should_try_out_of_range: bool,
}
impl Default for Interpreter {
fn default() -> Interpreter {
Interpreter {
should_try_out_of_range: false,
}
}
}
impl Interpreter {
pub fn try_out_of_range() -> Interpreter {
Interpreter {
@ -34,7 +27,7 @@ impl Interpreter {
impl Interpreter {
pub fn execute<T: Field>(&self, program: &Prog<T>, inputs: &[T]) -> ExecutionResult<T> {
self.check_inputs(&program, &inputs)?;
self.check_inputs(program, inputs)?;
let mut witness = BTreeMap::new();
witness.insert(FlatVariable::one(), T::one());
@ -274,8 +267,8 @@ impl<T: Field> LinComb<T> {
impl<T: Field> QuadComb<T> {
pub fn evaluate(&self, witness: &BTreeMap<FlatVariable, T>) -> Result<T, EvaluationError> {
let left = self.left.evaluate(&witness)?;
let right = self.right.evaluate(&witness)?;
let left = self.left.evaluate(witness)?;
let right = self.right.evaluate(witness)?;
Ok(left * right)
}
}

View file

@ -191,7 +191,7 @@ impl<T: Field> Folder<T> for RedefinitionOptimizer<T> {
match lc
.0
.iter()
.any(|(variable, _)| self.substitution.get(&variable).is_some())
.any(|(variable, _)| self.substitution.get(variable).is_some())
{
true =>
// for each summand, check if it is equal to a linear term in our substitution, otherwise keep it as is

View file

@ -126,7 +126,7 @@ impl NonUniversalBackend<Bw6_761Field, GM17> for Ark {
.vk
.query
.iter()
.map(|g1| parse_g1::<Bw6_761Field>(g1))
.map(parse_g1::<Bw6_761Field>)
.collect(),
};

View file

@ -228,8 +228,8 @@ mod parse {
let raw_e = e.to_string();
let captures = G1_REGEX.captures(&raw_e).unwrap();
G1Affine(
captures.name(&"x").unwrap().as_str().to_string(),
captures.name(&"y").unwrap().as_str().to_string(),
captures.name("x").unwrap().as_str().to_string(),
captures.name("y").unwrap().as_str().to_string(),
)
}
@ -240,12 +240,12 @@ mod parse {
let captures = G2_REGEX.captures(&raw_e).unwrap();
G2Affine(
(
captures.name(&"x0").unwrap().as_str().to_string(),
captures.name(&"x1").unwrap().as_str().to_string(),
captures.name("x0").unwrap().as_str().to_string(),
captures.name("x1").unwrap().as_str().to_string(),
),
(
captures.name(&"y0").unwrap().as_str().to_string(),
captures.name(&"y1").unwrap().as_str().to_string(),
captures.name("y0").unwrap().as_str().to_string(),
captures.name("y1").unwrap().as_str().to_string(),
),
)
}
@ -253,7 +253,7 @@ mod parse {
pub fn parse_fr<T: BellmanFieldExtensions>(e: &<T::BellmanEngine as ScalarEngine>::Fr) -> Fr {
let raw_e = e.to_string();
let captures = FR_REGEX.captures(&raw_e).unwrap();
captures.name(&"x").unwrap().as_str().to_string()
captures.name("x").unwrap().as_str().to_string()
}
}

View file

@ -259,7 +259,7 @@ impl<'ast, T: Field> FunctionQuery<'ast, T> {
.inputs
.iter()
.zip(func.signature.inputs.iter())
.all(|(input_ty, sig_ty)| input_ty.can_be_specialized_to(&sig_ty))
.all(|(input_ty, sig_ty)| input_ty.can_be_specialized_to(sig_ty))
&& self.outputs.len() == func.signature.outputs.len()
&& self
.outputs
@ -268,7 +268,7 @@ impl<'ast, T: Field> FunctionQuery<'ast, T> {
.all(|(output_ty, sig_ty)| {
output_ty
.as_ref()
.map(|output_ty| output_ty.can_be_specialized_to(&sig_ty))
.map(|output_ty| output_ty.can_be_specialized_to(sig_ty))
.unwrap_or(true)
})
}
@ -482,7 +482,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
let ty = self.check_declaration_type(
c.value.ty.clone(),
module_id,
&state,
state,
&BTreeMap::default(),
&mut HashSet::default(),
)?;
@ -500,11 +500,10 @@ impl<'ast, T: Field> Checker<'ast, T> {
UExpression::try_from_typed(checked_expr, &bitwidth).map(TypedExpression::from)
}
DeclarationType::Array(ref array_ty) => {
ArrayExpression::try_from_typed(checked_expr, &array_ty).map(TypedExpression::from)
ArrayExpression::try_from_typed(checked_expr, array_ty).map(TypedExpression::from)
}
DeclarationType::Struct(ref struct_ty) => {
StructExpression::try_from_typed(checked_expr, &struct_ty)
.map(TypedExpression::from)
StructExpression::try_from_typed(checked_expr, struct_ty).map(TypedExpression::from)
}
DeclarationType::Int => Err(checked_expr), // Integers cannot be assigned
}
@ -1938,7 +1937,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
let arguments_types: Vec<_> =
arguments_checked.iter().map(|a| a.get_type()).collect();
let query = FunctionQuery::new(&fun_id, &generics_checked, &arguments_types, &assignee_types);
let query = FunctionQuery::new(fun_id, &generics_checked, &arguments_types, &assignee_types);
let functions = self.find_functions(&query);
@ -1984,7 +1983,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
let pos = assignee.pos();
// check that the assignee is declared
match assignee.value {
Assignee::Identifier(variable_name) => match self.get_key_value_scope(&variable_name) {
Assignee::Identifier(variable_name) => match self.get_key_value_scope(variable_name) {
Some((id, ty)) => match id.is_constant() {
true => Err(ErrorInner {
pos: Some(assignee.pos()),
@ -2120,7 +2119,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
Expression::Identifier(name) => {
// check that `id` is defined in the scope
match self
.get_key_value_scope(&name)
.get_key_value_scope(name)
.map(|(x, y)| (x.clone(), y.clone()))
{
Some((id, ty)) => match ty {
@ -2489,7 +2488,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
// outside of multidef, function calls must have a single return value
// we use type inference to determine the type of the return, so we don't specify it
let query =
FunctionQuery::new(&fun_id, &generics_checked, &arguments_types, &[None]);
FunctionQuery::new(fun_id, &generics_checked, &arguments_types, &[None]);
let functions = self.find_functions(&query);
@ -2502,7 +2501,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
let signature = f.signature;
let arguments_checked = arguments_checked.into_iter().zip(signature.inputs.iter()).map(|(a, t)| TypedExpression::align_to_type(a, &t)).collect::<Result<Vec<_>, _>>().map_err(|e| ErrorInner {
let arguments_checked = arguments_checked.into_iter().zip(signature.inputs.iter()).map(|(a, t)| TypedExpression::align_to_type(a, t)).collect::<Result<Vec<_>, _>>().map_err(|e| ErrorInner {
pos: Some(pos),
message: format!("Expected function call argument to be of type {}, found {}", e.1, e.0)
})?;
@ -3459,7 +3458,7 @@ impl<'ast, T: Field> Checker<'ast, T> {
fn exit_scope(&mut self) {
let current_level = self.level;
self.scope
.retain(|ref scoped_variable, _| scoped_variable.level < current_level);
.retain(|scoped_variable, _| scoped_variable.level < current_level);
self.level -= 1;
}
}
@ -3986,22 +3985,20 @@ mod tests {
.get(&*MODULE_ID)
.unwrap()
.functions_iter()
.find(|d| d.key
.any(|d| d.key
== DeclarationFunctionKey::with_location((*MODULE_ID).clone(), "foo")
.signature(DeclarationSignature::new()))
.is_some());
.signature(DeclarationSignature::new())));
assert!(state
.typed_modules
.get(&*MODULE_ID)
.unwrap()
.functions_iter()
.find(|d| d.key
.any(|d| d.key
== DeclarationFunctionKey::with_location((*MODULE_ID).clone(), "foo")
.signature(
DeclarationSignature::new().inputs(vec![DeclarationType::FieldElement])
))
.is_some());
)));
}
#[test]

View file

@ -81,7 +81,7 @@ impl<'ast, 'a, T: Field> Propagator<'ast, 'a, T> {
.map(|c| Ok((var, c)))
.unwrap_or(Err(var)),
TypedAssignee::Select(box assignee, box index) => {
match self.try_get_constant_mut(&assignee) {
match self.try_get_constant_mut(assignee) {
Ok((variable, constant)) => match index.as_inner() {
UExpressionInner::Value(n) => match constant {
TypedExpression::Array(a) => match a.as_inner_mut() {
@ -103,7 +103,7 @@ impl<'ast, 'a, T: Field> Propagator<'ast, 'a, T> {
e => e,
}
}
TypedAssignee::Member(box assignee, m) => match self.try_get_constant_mut(&assignee) {
TypedAssignee::Member(box assignee, m) => match self.try_get_constant_mut(assignee) {
Ok((v, c)) => {
let ty = assignee.get_type();
@ -561,7 +561,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> {
let invalidations = assignees.iter().flat_map(|assignee| {
let v = self
.try_get_constant_mut(&assignee)
.try_get_constant_mut(assignee)
.map(|(v, _)| v)
.unwrap_or_else(|v| v);
match self.constants.remove(&v.id) {
@ -603,7 +603,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> {
let invalidations = assignees.iter().flat_map(|assignee| {
let v = self
.try_get_constant_mut(&assignee)
.try_get_constant_mut(assignee)
.map(|(v, _)| v)
.unwrap_or_else(|v| v);
match self.constants.remove(&v.id) {

View file

@ -69,7 +69,7 @@ fn get_canonical_function<'ast, T: Field>(
.unwrap();
match &s.symbol {
TypedFunctionSymbol::There(key) => get_canonical_function(key.clone(), &program),
TypedFunctionSymbol::There(key) => get_canonical_function(key.clone(), program),
_ => s.clone(),
}
}

View file

@ -161,7 +161,7 @@ fn register<'ast>(
) {
for (id, key, value) in substitute
.iter()
.filter_map(|(id, version)| with.get(&id).map(|to| (id, version, to)))
.filter_map(|(id, version)| with.get(id).map(|to| (id, version, to)))
.filter(|(_, key, value)| key != value)
{
let sub = substitutions.0.entry(id.clone()).or_default();
@ -235,8 +235,8 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Reducer<'ast, 'a, T> {
generics,
arguments,
ty,
&self.program,
&mut self.versions,
self.program,
self.versions,
);
match res {
@ -354,8 +354,8 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Reducer<'ast, 'a, T> {
generics,
arguments,
&types,
&self.program,
&mut self.versions,
self.program,
self.versions,
) {
Ok(Output::Complete((statements, expressions))) => {
assert_eq!(v.len(), expressions.len());
@ -420,7 +420,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Reducer<'ast, 'a, T> {
self.versions.values_mut().for_each(|v| *v += 1);
// add this set of versions to the substitution, pointing to the versions before the loop
register(&mut self.substitutions, &self.versions, &versions_before);
register(self.substitutions, self.versions, &versions_before);
// the versions after the loop are found by applying an offset of 2 to the versions before the loop
let versions_after = versions_before
@ -429,7 +429,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Reducer<'ast, 'a, T> {
.map(|(k, v)| (k, v + 2))
.collect();
let mut transformer = ShallowTransformer::with_versions(&mut self.versions);
let mut transformer = ShallowTransformer::with_versions(self.versions);
if to - from > MAX_FOR_LOOP_SIZE {
return Err(Error::LoopTooLarge(to.saturating_sub(*from)));
@ -454,7 +454,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Reducer<'ast, 'a, T> {
// we know the final versions of the variables after full unrolling of the loop
// the versions after the loop need to point to these, so we add to the substitutions
register(&mut self.substitutions, &versions_after, &self.versions);
register(self.substitutions, &versions_after, self.versions);
// we may have found new for loops when unrolling this one, which means new backed up versions
// we insert these in our backup list and update our cursor
@ -573,7 +573,7 @@ fn reduce_function<'ast, T: Field>(
loop {
let mut reducer = Reducer::new(
&program,
program,
&mut versions,
&mut substitutions,
for_loop_versions,

View file

@ -28,7 +28,7 @@ impl fmt::Display for Error {
impl UnconstrainedVariableDetector {
pub fn detect<T: Field>(p: &Prog<T>) -> Result<(), Error> {
let mut instance = Self::default();
instance.visit_module(&p);
instance.visit_module(p);
if instance.variables.is_empty() {
Ok(())
@ -118,39 +118,39 @@ mod tests {
// (1 * ~one) * (1 * ~one + (-1) * _1) == 1 * ~out_0
// return ~out_0
let _0 = FlatParameter::private(FlatVariable::new(0));
let _1 = FlatVariable::new(1);
let _2 = FlatVariable::new(2);
let v_0 = FlatParameter::private(FlatVariable::new(0));
let v_1 = FlatVariable::new(1);
let v_2 = FlatVariable::new(2);
let out_0 = FlatVariable::public(0);
let one = FlatVariable::one();
let p: Prog<Bn128Field> = Prog {
arguments: vec![_0],
arguments: vec![v_0],
statements: vec![
Statement::Directive(Directive {
inputs: vec![(LinComb::summand(-42, one) + LinComb::summand(1, _0.id)).into()],
outputs: vec![_1, _2],
inputs: vec![(LinComb::summand(-42, one) + LinComb::summand(1, v_0.id)).into()],
outputs: vec![v_1, v_2],
solver: Solver::ConditionEq,
}),
Statement::constraint(
QuadComb::from_linear_combinations(
LinComb::summand(-42, one) + LinComb::summand(1, _0.id),
LinComb::summand(1, _2),
LinComb::summand(-42, one) + LinComb::summand(1, v_0.id),
LinComb::summand(1, v_2),
),
LinComb::summand(1, _1),
LinComb::summand(1, v_1),
),
Statement::constraint(
QuadComb::from_linear_combinations(
LinComb::summand(1, one) + LinComb::summand(-1, _1),
LinComb::summand(-42, one) + LinComb::summand(1, _0.id),
LinComb::summand(1, one) + LinComb::summand(-1, v_1),
LinComb::summand(-42, one) + LinComb::summand(1, v_0.id),
),
LinComb::zero(),
),
Statement::constraint(
QuadComb::from_linear_combinations(
LinComb::summand(1, one),
LinComb::summand(1, one) + LinComb::summand(-1, _1),
LinComb::summand(1, one) + LinComb::summand(-1, v_1),
),
LinComb::summand(1, out_0),
),

View file

@ -597,7 +597,7 @@ impl<'ast, T: Field> ArrayExpression<'ast, T> {
inline_array
.into_iter()
.map(|v| {
TypedExpressionOrSpread::align_to_type(v, &target_array_ty).map_err(
TypedExpressionOrSpread::align_to_type(v, target_array_ty).map_err(
|(e, _)| match e {
TypedExpressionOrSpread::Expression(e) => e,
TypedExpressionOrSpread::Spread(a) => {
@ -620,7 +620,7 @@ impl<'ast, T: Field> ArrayExpression<'ast, T> {
GType::Int => Ok(ArrayExpressionInner::Repeat(box e, box count)
.annotate(Type::Int, array_ty.size)),
// try to align the repeated element to the target type
t => TypedExpression::align_to_type(e, &t)
t => TypedExpression::align_to_type(e, t)
.map(|e| {
let ty = e.get_type().clone();

View file

@ -263,7 +263,7 @@ impl<'ast, T: Field> TypedFunctionSymbol<'ast, T> {
.find(|d| d.key == *key)
.unwrap()
.symbol
.signature(&modules),
.signature(modules),
TypedFunctionSymbol::Flat(flat_fun) => flat_fun.typed_signature(),
}
}
@ -1589,7 +1589,7 @@ impl<'ast, T: Clone> Expr<'ast, T> for FieldElementExpression<'ast, T> {
}
fn as_inner(&self) -> &Self::Inner {
&self
self
}
fn as_inner_mut(&mut self) -> &mut Self::Inner {
@ -1610,7 +1610,7 @@ impl<'ast, T: Clone> Expr<'ast, T> for BooleanExpression<'ast, T> {
}
fn as_inner(&self) -> &Self::Inner {
&self
self
}
fn as_inner_mut(&mut self) -> &mut Self::Inner {
@ -1694,7 +1694,7 @@ impl<'ast, T: Clone> Expr<'ast, T> for IntExpression<'ast, T> {
}
fn as_inner(&self) -> &Self::Inner {
&self
self
}
fn as_inner_mut(&mut self) -> &mut Self::Inner {

View file

@ -353,7 +353,7 @@ impl<S: fmt::Display> fmt::Display for GArrayType<S> {
) -> fmt::Result {
acc.push(&t.size);
match &*t.ty {
GType::Array(array_type) => fmt_aux(f, &array_type, acc),
GType::Array(array_type) => fmt_aux(f, array_type, acc),
t => {
write!(f, "{}", t)?;
for i in acc {
@ -366,7 +366,7 @@ impl<S: fmt::Display> fmt::Display for GArrayType<S> {
let acc = vec![];
fmt_aux(f, &self, acc)
fmt_aux(f, self, acc)
}
}
@ -509,7 +509,7 @@ impl<S> GStructType<S> {
}
fn location(&self) -> &StructLocation {
&self.location.as_ref().unwrap_or(&self.canonical_location)
self.location.as_ref().unwrap_or(&self.canonical_location)
}
pub fn name(&self) -> &str {
@ -1080,7 +1080,7 @@ pub fn specialize_declaration_type<
Ok(match decl_ty {
DeclarationType::Int => unreachable!(),
DeclarationType::Array(t0) => {
let ty = box specialize_declaration_type(*t0.ty, &generics)?;
let ty = box specialize_declaration_type(*t0.ty, generics)?;
let size = t0.size.map(generics)?;
GType::Array(GArrayType { size, ty })
@ -1163,7 +1163,7 @@ pub mod signature {
impl<S: Ord> Ord for GSignature<S> {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.partial_cmp(&other).unwrap()
self.partial_cmp(other).unwrap()
}
}

View file

@ -38,7 +38,7 @@ fn lt_field() {
assert!(interpreter
.execute(
&res.prog(),
res.prog(),
&[Bn128Field::from(10000), Bn128Field::from(5555)]
)
.is_err());
@ -70,7 +70,7 @@ fn lt_uint() {
assert!(interpreter
.execute(
&res.prog(),
res.prog(),
&[Bn128Field::from(10000), Bn128Field::from(5555)]
)
.is_err());
@ -112,7 +112,7 @@ fn unpack256() {
let interpreter = Interpreter::try_out_of_range();
assert!(interpreter
.execute(&res.prog(), &[Bn128Field::from(0)])
.execute(res.prog(), &[Bn128Field::from(0)])
.is_err());
}
@ -152,6 +152,6 @@ fn unpack256_unchecked() {
let interpreter = Interpreter::try_out_of_range();
assert!(interpreter
.execute(&res.prog(), &[Bn128Field::from(0)])
.execute(res.prog(), &[Bn128Field::from(0)])
.is_ok());
}

View file

@ -111,7 +111,7 @@ pub fn generate_verify_constraints(
let num_instance_variables = cs.num_instance_variables();
let input_indices = fp_vars
.iter()
.map(|f| var_to_index(&f, 0))
.map(|f| var_to_index(f, 0))
.collect::<Vec<usize>>();
let proof_indices: Vec<usize> = vec![

View file

@ -793,7 +793,7 @@ mod ast {
match self {
Expression::Binary(b) => &b.span,
Expression::Identifier(i) => &i.span,
Expression::Literal(c) => &c.span(),
Expression::Literal(c) => c.span(),
Expression::Ternary(t) => &t.span,
Expression::Postfix(p) => &p.span,
Expression::InlineArray(a) => &a.span,
@ -1082,57 +1082,57 @@ mod tests {
def main() -> (field): return 1 + 1
"#;
assert_eq!(
generate_ast(&source),
generate_ast(source),
Ok(File {
pragma: None,
declarations: vec![
SymbolDeclaration::Import(ImportDirective::Main(MainImportDirective {
source: ImportSource {
value: String::from("foo"),
span: Span::new(&source, 8, 11).unwrap()
span: Span::new(source, 8, 11).unwrap()
},
alias: None,
span: Span::new(&source, 0, 29).unwrap()
span: Span::new(source, 0, 29).unwrap()
})),
SymbolDeclaration::Function(FunctionDefinition {
generics: vec![],
id: IdentifierExpression {
value: String::from("main"),
span: Span::new(&source, 33, 37).unwrap()
span: Span::new(source, 33, 37).unwrap()
},
parameters: vec![],
returns: vec![Type::Basic(BasicType::Field(FieldType {
span: Span::new(&source, 44, 49).unwrap()
span: Span::new(source, 44, 49).unwrap()
}))],
statements: vec![Statement::Return(ReturnStatement {
expressions: vec![Expression::add(
Expression::Literal(LiteralExpression::DecimalLiteral(
DecimalLiteralExpression {
value: DecimalNumber {
span: Span::new(&source, 59, 60).unwrap()
span: Span::new(source, 59, 60).unwrap()
},
suffix: None,
span: Span::new(&source, 59, 60).unwrap()
span: Span::new(source, 59, 60).unwrap()
}
)),
Expression::Literal(LiteralExpression::DecimalLiteral(
DecimalLiteralExpression {
value: DecimalNumber {
span: Span::new(&source, 63, 64).unwrap()
span: Span::new(source, 63, 64).unwrap()
},
suffix: None,
span: Span::new(&source, 63, 64).unwrap()
span: Span::new(source, 63, 64).unwrap()
}
)),
Span::new(&source, 59, 64).unwrap()
Span::new(source, 59, 64).unwrap()
)],
span: Span::new(&source, 52, 64).unwrap(),
span: Span::new(source, 52, 64).unwrap(),
})],
span: Span::new(&source, 29, source.len()).unwrap(),
span: Span::new(source, 29, source.len()).unwrap(),
})
],
eoi: EOI {},
span: Span::new(&source, 0, 65).unwrap()
span: Span::new(source, 0, 65).unwrap()
})
);
}
@ -1143,27 +1143,27 @@ mod tests {
def main() -> (field): return 1 + 2 * 3 ** 4
"#;
assert_eq!(
generate_ast(&source),
generate_ast(source),
Ok(File {
pragma: None,
declarations: vec![
SymbolDeclaration::Import(ImportDirective::Main(MainImportDirective {
source: ImportSource {
value: String::from("foo"),
span: Span::new(&source, 8, 11).unwrap()
span: Span::new(source, 8, 11).unwrap()
},
alias: None,
span: Span::new(&source, 0, 29).unwrap()
span: Span::new(source, 0, 29).unwrap()
})),
SymbolDeclaration::Function(FunctionDefinition {
generics: vec![],
id: IdentifierExpression {
value: String::from("main"),
span: Span::new(&source, 33, 37).unwrap()
span: Span::new(source, 33, 37).unwrap()
},
parameters: vec![],
returns: vec![Type::Basic(BasicType::Field(FieldType {
span: Span::new(&source, 44, 49).unwrap()
span: Span::new(source, 44, 49).unwrap()
}))],
statements: vec![Statement::Return(ReturnStatement {
expressions: vec![Expression::add(
@ -1171,9 +1171,9 @@ mod tests {
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(&source, 59, 60).unwrap()
span: Span::new(source, 59, 60).unwrap()
},
span: Span::new(&source, 59, 60).unwrap()
span: Span::new(source, 59, 60).unwrap()
}
)),
Expression::mul(
@ -1181,9 +1181,9 @@ mod tests {
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(&source, 63, 64).unwrap()
span: Span::new(source, 63, 64).unwrap()
},
span: Span::new(&source, 63, 64).unwrap()
span: Span::new(source, 63, 64).unwrap()
}
)),
Expression::pow(
@ -1191,33 +1191,33 @@ mod tests {
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(&source, 67, 68).unwrap()
span: Span::new(source, 67, 68).unwrap()
},
span: Span::new(&source, 67, 68).unwrap()
span: Span::new(source, 67, 68).unwrap()
}
)),
Expression::Literal(LiteralExpression::DecimalLiteral(
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(&source, 72, 73).unwrap()
span: Span::new(source, 72, 73).unwrap()
},
span: Span::new(&source, 72, 73).unwrap()
span: Span::new(source, 72, 73).unwrap()
}
)),
Span::new(&source, 67, 73).unwrap()
Span::new(source, 67, 73).unwrap()
),
Span::new(&source, 63, 73).unwrap()
Span::new(source, 63, 73).unwrap()
),
Span::new(&source, 59, 73).unwrap()
Span::new(source, 59, 73).unwrap()
)],
span: Span::new(&source, 52, 73).unwrap(),
span: Span::new(source, 52, 73).unwrap(),
})],
span: Span::new(&source, 29, 74).unwrap(),
span: Span::new(source, 29, 74).unwrap(),
})
],
eoi: EOI {},
span: Span::new(&source, 0, 74).unwrap()
span: Span::new(source, 0, 74).unwrap()
})
);
}
@ -1228,27 +1228,27 @@ mod tests {
def main() -> (field): return if 1 then 2 else 3 fi
"#;
assert_eq!(
generate_ast(&source),
generate_ast(source),
Ok(File {
pragma: None,
declarations: vec![
SymbolDeclaration::Import(ImportDirective::Main(MainImportDirective {
source: ImportSource {
value: String::from("foo"),
span: Span::new(&source, 8, 11).unwrap()
span: Span::new(source, 8, 11).unwrap()
},
alias: None,
span: Span::new(&source, 0, 29).unwrap()
span: Span::new(source, 0, 29).unwrap()
})),
SymbolDeclaration::Function(FunctionDefinition {
generics: vec![],
id: IdentifierExpression {
value: String::from("main"),
span: Span::new(&source, 33, 37).unwrap()
span: Span::new(source, 33, 37).unwrap()
},
parameters: vec![],
returns: vec![Type::Basic(BasicType::Field(FieldType {
span: Span::new(&source, 44, 49).unwrap()
span: Span::new(source, 44, 49).unwrap()
}))],
statements: vec![Statement::Return(ReturnStatement {
expressions: vec![Expression::if_else(
@ -1256,38 +1256,38 @@ mod tests {
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(&source, 62, 63).unwrap()
span: Span::new(source, 62, 63).unwrap()
},
span: Span::new(&source, 62, 63).unwrap()
span: Span::new(source, 62, 63).unwrap()
}
)),
Expression::Literal(LiteralExpression::DecimalLiteral(
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(&source, 69, 70).unwrap()
span: Span::new(source, 69, 70).unwrap()
},
span: Span::new(&source, 69, 70).unwrap()
span: Span::new(source, 69, 70).unwrap()
}
)),
Expression::Literal(LiteralExpression::DecimalLiteral(
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(&source, 76, 77).unwrap()
span: Span::new(source, 76, 77).unwrap()
},
span: Span::new(&source, 76, 77).unwrap()
span: Span::new(source, 76, 77).unwrap()
}
)),
Span::new(&source, 59, 80).unwrap()
Span::new(source, 59, 80).unwrap()
)],
span: Span::new(&source, 52, 80).unwrap(),
span: Span::new(source, 52, 80).unwrap(),
})],
span: Span::new(&source, 29, 81).unwrap(),
span: Span::new(source, 29, 81).unwrap(),
})
],
eoi: EOI {},
span: Span::new(&source, 0, 81).unwrap()
span: Span::new(source, 0, 81).unwrap()
})
);
}
@ -1297,35 +1297,35 @@ mod tests {
let source = r#"def main() -> (field): return (1)
"#;
assert_eq!(
generate_ast(&source),
generate_ast(source),
Ok(File {
pragma: None,
declarations: vec![SymbolDeclaration::Function(FunctionDefinition {
generics: vec![],
id: IdentifierExpression {
value: String::from("main"),
span: Span::new(&source, 4, 8).unwrap()
span: Span::new(source, 4, 8).unwrap()
},
parameters: vec![],
returns: vec![Type::Basic(BasicType::Field(FieldType {
span: Span::new(&source, 15, 20).unwrap()
span: Span::new(source, 15, 20).unwrap()
}))],
statements: vec![Statement::Return(ReturnStatement {
expressions: vec![Expression::Literal(LiteralExpression::DecimalLiteral(
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(&source, 31, 32).unwrap()
span: Span::new(source, 31, 32).unwrap()
},
span: Span::new(&source, 31, 32).unwrap()
span: Span::new(source, 31, 32).unwrap()
}
))],
span: Span::new(&source, 23, 33).unwrap(),
span: Span::new(source, 23, 33).unwrap(),
})],
span: Span::new(&source, 0, 34).unwrap(),
span: Span::new(source, 0, 34).unwrap(),
})],
eoi: EOI {},
span: Span::new(&source, 0, 34).unwrap()
span: Span::new(source, 0, 34).unwrap()
})
);
}
@ -1335,44 +1335,44 @@ mod tests {
let source = r#"def main() -> (field): field a, b = foo(1, 2 + 3)
"#;
assert_eq!(
generate_ast(&source),
generate_ast(source),
Ok(File {
pragma: None,
declarations: vec![SymbolDeclaration::Function(FunctionDefinition {
generics: vec![],
id: IdentifierExpression {
value: String::from("main"),
span: Span::new(&source, 4, 8).unwrap()
span: Span::new(source, 4, 8).unwrap()
},
parameters: vec![],
returns: vec![Type::Basic(BasicType::Field(FieldType {
span: Span::new(&source, 15, 20).unwrap()
span: Span::new(source, 15, 20).unwrap()
}))],
statements: vec![Statement::Definition(DefinitionStatement {
lhs: vec![
TypedIdentifierOrAssignee::TypedIdentifier(TypedIdentifier {
ty: Type::Basic(BasicType::Field(FieldType {
span: Span::new(&source, 23, 28).unwrap()
span: Span::new(source, 23, 28).unwrap()
})),
identifier: IdentifierExpression {
value: String::from("a"),
span: Span::new(&source, 29, 30).unwrap(),
span: Span::new(source, 29, 30).unwrap(),
},
span: Span::new(&source, 23, 30).unwrap()
span: Span::new(source, 23, 30).unwrap()
}),
TypedIdentifierOrAssignee::Assignee(Assignee {
id: IdentifierExpression {
value: String::from("b"),
span: Span::new(&source, 32, 33).unwrap(),
span: Span::new(source, 32, 33).unwrap(),
},
accesses: vec![],
span: Span::new(&source, 32, 34).unwrap()
span: Span::new(source, 32, 34).unwrap()
}),
],
expression: Expression::Postfix(PostfixExpression {
id: IdentifierExpression {
value: String::from("foo"),
span: Span::new(&source, 36, 39).unwrap()
span: Span::new(source, 36, 39).unwrap()
},
accesses: vec![Access::Call(CallAccess {
explicit_generics: None,
@ -1382,9 +1382,9 @@ mod tests {
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(&source, 40, 41).unwrap()
span: Span::new(source, 40, 41).unwrap()
},
span: Span::new(&source, 40, 41).unwrap()
span: Span::new(source, 40, 41).unwrap()
}
)),
Expression::add(
@ -1392,35 +1392,35 @@ mod tests {
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(&source, 43, 44).unwrap()
span: Span::new(source, 43, 44).unwrap()
},
span: Span::new(&source, 43, 44).unwrap()
span: Span::new(source, 43, 44).unwrap()
}
)),
Expression::Literal(LiteralExpression::DecimalLiteral(
DecimalLiteralExpression {
suffix: None,
value: DecimalNumber {
span: Span::new(&source, 47, 48).unwrap()
span: Span::new(source, 47, 48).unwrap()
},
span: Span::new(&source, 47, 48).unwrap()
span: Span::new(source, 47, 48).unwrap()
}
)),
Span::new(&source, 43, 48).unwrap()
Span::new(source, 43, 48).unwrap()
),
],
span: Span::new(&source, 40, 48).unwrap()
span: Span::new(source, 40, 48).unwrap()
},
span: Span::new(&source, 39, 49).unwrap()
span: Span::new(source, 39, 49).unwrap()
})],
span: Span::new(&source, 36, 49).unwrap(),
span: Span::new(source, 36, 49).unwrap(),
}),
span: Span::new(&source, 23, 49).unwrap()
span: Span::new(source, 23, 49).unwrap()
})],
span: Span::new(&source, 0, 50).unwrap(),
span: Span::new(source, 0, 50).unwrap(),
})],
eoi: EOI {},
span: Span::new(&source, 0, 50).unwrap()
span: Span::new(source, 0, 50).unwrap()
})
);
}
@ -1443,8 +1443,8 @@ mod tests {
assert(a.member == 1)
return a
"#;
let res = generate_ast(&source);
println!("{:#?}", generate_ast(&source));
let res = generate_ast(source);
println!("{:#?}", generate_ast(source));
assert!(res.is_ok());
}
}

View file

@ -157,15 +157,14 @@ fn compile_and_run<T: Field>(t: Tests) {
if let Some(target_count) = t.max_constraint_count {
let count = bin.constraint_count();
if count > target_count {
panic!(
"{} exceeded max constraint count (actual={}, max={}, p={:.2}% of max)",
entry_point.display(),
count,
target_count,
(count as f32) / (target_count as f32) * 100_f32
);
}
assert!(
count <= target_count,
"{} exceeded max constraint count (actual={}, max={}, p={:.2}% of max)",
entry_point.display(),
count,
target_count,
(count as f32) / (target_count as f32) * 100_f32
);
};
let interpreter = zokrates_core::ir::Interpreter::default();

View file

@ -13,7 +13,7 @@ pub fn write_tests(base: &str) {
let mut writer = BufWriter::new(test_file);
for p in glob(base.join("**/*.json").to_str().unwrap()).unwrap() {
write_test(&mut writer, &p.unwrap(), &base);
write_test(&mut writer, &p.unwrap(), base);
}
}