Skip to content

Commit

Permalink
Build with stable rust (#1288)
Browse files Browse the repository at this point in the history
make zokrates build on stable rust
  • Loading branch information
Schaeff authored Apr 13, 2023
1 parent 52e45a3 commit 8c08164
Show file tree
Hide file tree
Showing 66 changed files with 984 additions and 924 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions changelogs/unreleased/1288-schaeff
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make ZoKrates build on stable rust
1 change: 0 additions & 1 deletion clippy.toml

This file was deleted.

6 changes: 3 additions & 3 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM rustlang/rust:nightly
FROM rust:latest

RUN useradd -u 1000 -m zokrates

COPY ./scripts/install_foundry_deb.sh /tmp/
RUN /tmp/install_foundry_deb.sh
COPY ./scripts/install_foundry.sh /tmp/
RUN /tmp/install_foundry.sh

USER zokrates

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly-2022-07-01"
channel = "stable"
2 changes: 0 additions & 2 deletions zokrates_abi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(box_patterns, box_syntax)]

pub enum Inputs<T> {
Raw(Vec<T>),
Abi(Values<T>),
Expand Down
18 changes: 9 additions & 9 deletions zokrates_analysis/src/boolean_array_comparator.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use zokrates_ast::{
common::WithSpan,
typed::{
folder::*, ArrayExpression, BooleanExpression, Conditional, ConditionalKind, Expr,
FieldElementExpression, Select, Type, TypedExpression, TypedProgram, UExpression,
folder::*, ArrayExpression, ArrayType, BooleanExpression, Conditional, ConditionalKind,
Expr, FieldElementExpression, Select, Type, TypedExpression, TypedProgram, UExpression,
UExpressionInner,
},
};
Expand Down Expand Up @@ -42,7 +42,7 @@ impl<'ast, T: Field> Folder<'ast, T> for BooleanArrayComparator {
_ => unreachable!("array size should be known"),
};

let chunk_size = T::get_required_bits() as usize - 1;
let chunk_size = T::get_required_bits() - 1;

let left_elements: Vec<_> = (0..len)
.map(|i| BooleanExpression::select(*e.left.clone(), i as u32).span(span))
Expand Down Expand Up @@ -91,10 +91,10 @@ impl<'ast, T: Field> Folder<'ast, T> for BooleanArrayComparator {

BooleanExpression::array_eq(
ArrayExpression::value(left)
.annotate(Type::FieldElement, chunk_count as u32)
.annotate(ArrayType::new(Type::FieldElement, chunk_count as u32))
.span(span),
ArrayExpression::value(right)
.annotate(Type::FieldElement, chunk_count as u32)
.annotate(ArrayType::new(Type::FieldElement, chunk_count as u32))
.span(span),
)
}
Expand Down Expand Up @@ -124,8 +124,8 @@ mod tests {
// [x[0] ? 2**1 : 0 + x[1] ? 2**0 : 0] == [y[0] ? 2**1 : 0 + y[1] ? 2**0 : 0]
// a single field is sufficient, as the prime we're working with is 3 bits long, so we can pack up to 2 bits

let x = a_id("x").annotate(Type::Boolean, 2u32);
let y = a_id("y").annotate(Type::Boolean, 2u32);
let x = a_id("x").annotate(ArrayType::new(Type::Boolean, 2u32));
let y = a_id("y").annotate(ArrayType::new(Type::Boolean, 2u32));

let e: BooleanExpression<DummyCurveField> =
BooleanExpression::ArrayEq(BinaryExpression::new(x.clone(), y.clone()));
Expand All @@ -152,8 +152,8 @@ mod tests {
// should become
// [x[0] ? 2**2 : 0 + x[1] ? 2**1 : 0, x[2] ? 2**0 : 0] == [y[0] ? 2**2 : 0 + y[1] ? 2**1 : 0 y[2] ? 2**0 : 0]

let x = a_id("x").annotate(Type::Boolean, 3u32);
let y = a_id("y").annotate(Type::Boolean, 3u32);
let x = a_id("x").annotate(ArrayType::new(Type::Boolean, 3u32));
let y = a_id("y").annotate(ArrayType::new(Type::Boolean, 3u32));

let e: BooleanExpression<DummyCurveField> =
BooleanExpression::ArrayEq(BinaryExpression::new(x.clone(), y.clone()));
Expand Down
18 changes: 10 additions & 8 deletions zokrates_analysis/src/constant_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mod tests {
use zokrates_ast::typed::types::{DeclarationSignature, GTupleType};
use zokrates_ast::typed::{
DeclarationArrayType, DeclarationFunctionKey, DeclarationType, FieldElementExpression,
GType, Identifier, TypedConstant, TypedExpression, TypedFunction, TypedFunctionSymbol,
Identifier, TypedConstant, TypedExpression, TypedFunction, TypedFunctionSymbol,
TypedStatement,
};
use zokrates_field::Bn128Field;
Expand Down Expand Up @@ -316,12 +316,12 @@ mod tests {
FieldElementExpression::add(
FieldElementExpression::select(
ArrayExpression::identifier(Identifier::from(const_id.clone()))
.annotate(GType::FieldElement, 2u32),
.annotate(GArrayType::new(Type::FieldElement, 2u32)),
UExpression::value(0u128).annotate(UBitwidth::B32),
),
FieldElementExpression::select(
ArrayExpression::identifier(Identifier::from(const_id.clone()))
.annotate(GType::FieldElement, 2u32),
.annotate(GArrayType::new(Type::FieldElement, 2u32)),
UExpression::value(1u128).annotate(UBitwidth::B32),
),
)
Expand All @@ -347,7 +347,7 @@ mod tests {
FieldElementExpression::value(Bn128Field::from(2)).into(),
FieldElementExpression::value(Bn128Field::from(2)).into(),
])
.annotate(GType::FieldElement, 2u32),
.annotate(GArrayType::new(Type::FieldElement, 2u32)),
),
DeclarationType::Array(DeclarationArrayType::new(
DeclarationType::FieldElement,
Expand Down Expand Up @@ -741,8 +741,9 @@ mod tests {
main_baz_const_id.clone(),
TypedConstantSymbol::Here(TypedConstant::new(
TypedExpression::Array(
ArrayExpression::identifier(main_bar_const_id.clone().into())
.annotate(Type::FieldElement, main_foo_const_id.clone()),
ArrayExpression::identifier(main_bar_const_id.clone().into()).annotate(
ArrayType::new(Type::FieldElement, main_foo_const_id.clone()),
),
),
DeclarationType::Array(DeclarationArrayType::new(
DeclarationType::FieldElement,
Expand Down Expand Up @@ -814,8 +815,9 @@ mod tests {
main_baz_const_id.clone(),
TypedConstantSymbol::Here(TypedConstant::new(
TypedExpression::Array(
ArrayExpression::identifier(main_bar_const_id.into())
.annotate(Type::FieldElement, main_foo_const_id.clone()),
ArrayExpression::identifier(main_bar_const_id.into()).annotate(
ArrayType::new(Type::FieldElement, main_foo_const_id.clone()),
),
),
DeclarationType::Array(DeclarationArrayType::new(
DeclarationType::FieldElement,
Expand Down
30 changes: 12 additions & 18 deletions zokrates_analysis/src/flatten_complex_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,14 @@ fn flatten_identifier_rec<'ast>(
}
typed::types::ConcreteType::Array(array_type) => (0..*array_type.size)
.flat_map(|i| {
flatten_identifier_rec(
SourceIdentifier::Select(Box::new(id.clone()), i),
&array_type.ty,
)
flatten_identifier_rec(SourceIdentifier::select(id.clone(), i), &array_type.ty)
})
.collect(),
typed::types::ConcreteType::Struct(members) => members
.iter()
.flat_map(|struct_member| {
flatten_identifier_rec(
SourceIdentifier::Member(Box::new(id.clone()), struct_member.id.clone()),
SourceIdentifier::member(id.clone(), struct_member.id.clone()),
&struct_member.ty,
)
})
Expand All @@ -59,10 +56,7 @@ fn flatten_identifier_rec<'ast>(
.iter()
.enumerate()
.flat_map(|(i, ty)| {
flatten_identifier_rec(
SourceIdentifier::Element(Box::new(id.clone()), i as u32),
ty,
)
flatten_identifier_rec(SourceIdentifier::element(id.clone(), i as u32), ty)
})
.collect(),
}
Expand All @@ -88,7 +82,7 @@ fn flatten_identifier_to_expression_rec<'ast, T: Field>(
typed::ConcreteType::Array(array_type) => (0..*array_type.size)
.flat_map(|i| {
flatten_identifier_to_expression_rec(
SourceIdentifier::Select(box id.clone(), i),
SourceIdentifier::select(id.clone(), i),
&array_type.ty,
)
})
Expand All @@ -97,7 +91,7 @@ fn flatten_identifier_to_expression_rec<'ast, T: Field>(
.iter()
.flat_map(|struct_member| {
flatten_identifier_to_expression_rec(
SourceIdentifier::Member(box id.clone(), struct_member.id.clone()),
SourceIdentifier::member(id.clone(), struct_member.id.clone()),
&struct_member.ty,
)
})
Expand All @@ -108,7 +102,7 @@ fn flatten_identifier_to_expression_rec<'ast, T: Field>(
.enumerate()
.flat_map(|(i, ty)| {
flatten_identifier_to_expression_rec(
SourceIdentifier::Element(box id.clone(), i as u32),
SourceIdentifier::element(id.clone(), i as u32),
ty,
)
})
Expand Down Expand Up @@ -231,12 +225,12 @@ impl<'ast, T: Field> Flattener<T> {
fn fold_assignee(&mut self, a: typed::TypedAssignee<'ast, T>) -> Vec<zir::ZirAssignee<'ast>> {
match a {
typed::TypedAssignee::Identifier(v) => self.fold_variable(v),
typed::TypedAssignee::Select(box a, box i) => {
typed::TypedAssignee::Select(a, i) => {
let count = match typed::ConcreteType::try_from(a.get_type()).unwrap() {
typed::ConcreteType::Array(array_ty) => array_ty.ty.get_primitive_count(),
_ => unreachable!(),
};
let a = self.fold_assignee(a);
let a = self.fold_assignee(*a);

match i.as_inner() {
typed::UExpressionInner::Value(index) => {
Expand All @@ -245,7 +239,7 @@ impl<'ast, T: Field> Flattener<T> {
i => unreachable!("index {:?} not allowed, should be a constant", i),
}
}
typed::TypedAssignee::Member(box a, m) => {
typed::TypedAssignee::Member(a, m) => {
let (offset, size) =
match typed::ConcreteType::try_from(a.get_type()).unwrap() {
typed::ConcreteType::Struct(struct_type) => struct_type
Expand All @@ -263,11 +257,11 @@ impl<'ast, T: Field> Flattener<T> {

let size = size.unwrap();

let a = self.fold_assignee(a);
let a = self.fold_assignee(*a);

a[offset..offset + size].to_vec()
}
typed::TypedAssignee::Element(box a, index) => {
typed::TypedAssignee::Element(a, index) => {
let tuple_ty = typed::ConcreteTupleType::try_from(
typed::ConcreteType::try_from(a.get_type()).unwrap(),
)
Expand All @@ -282,7 +276,7 @@ impl<'ast, T: Field> Flattener<T> {

let size = &tuple_ty.elements[index as usize].get_primitive_count();

let a = self.fold_assignee(a);
let a = self.fold_assignee(*a);

a[offset..offset + size].to_vec()
}
Expand Down
2 changes: 0 additions & 2 deletions zokrates_analysis/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(box_patterns, box_syntax)]

//! Module containing static analysis
//!
//! @file mod.rs
Expand Down
12 changes: 6 additions & 6 deletions zokrates_analysis/src/out_of_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ impl<'ast, T: Field> ResultFolder<'ast, T> for OutOfBoundsChecker {
a: TypedAssignee<'ast, T>,
) -> Result<TypedAssignee<'ast, T>, Error> {
match a {
TypedAssignee::Select(box array, box index) => {
TypedAssignee::Select(array, index) => {
use zokrates_ast::typed::Typed;

let array = self.fold_assignee(array)?;
let array = self.fold_assignee(*array)?;

let size = match array.get_type() {
Type::Array(array_ty) => match array_ty.size.as_inner() {
Expand All @@ -62,13 +62,13 @@ impl<'ast, T: Field> ResultFolder<'ast, T> for OutOfBoundsChecker {
match index.as_inner() {
UExpressionInner::Value(i) if i.value >= size => Err(Error(format!(
"Out of bounds write to `{}` because `{}` has size {}",
TypedAssignee::Select(box array.clone(), box index),
TypedAssignee::select(array.clone(), *index),
array,
size
))),
_ => Ok(TypedAssignee::Select(
box self.fold_assignee(array)?,
box self.fold_uint_expression(index)?,
_ => Ok(TypedAssignee::select(
array,
self.fold_uint_expression(*index)?,
)),
}
}
Expand Down
16 changes: 7 additions & 9 deletions zokrates_analysis/src/panic_extractor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::*;
use zokrates_ast::{
common::{expressions::BinaryExpression, Fold, WithSpan},
common::{Fold, WithSpan},
zir::{
folder::*, BooleanExpression, Conditional, ConditionalExpression, ConditionalOrExpression,
Expr, FieldElementExpression, IfElseStatement, RuntimeError, UBitwidth, UExpression,
Expand Down Expand Up @@ -160,14 +160,12 @@ impl<'ast, T: Field> Folder<'ast, T> for PanicExtractor<'ast, T> {
) -> BooleanExpression<'ast, T> {
match e {
// constant range checks are complete, so no panic needs to be extracted
e @ BooleanExpression::FieldLt(BinaryExpression {
left: box FieldElementExpression::Value(_),
..
})
| e @ BooleanExpression::FieldLt(BinaryExpression {
right: box FieldElementExpression::Value(_),
..
}) => fold_boolean_expression_cases(self, e),
BooleanExpression::FieldLt(b)
if matches!(b.left.as_ref(), FieldElementExpression::Value(_))
|| matches!(b.right.as_ref(), FieldElementExpression::Value(_)) =>
{
fold_boolean_expression_cases(self, BooleanExpression::FieldLt(b))
}
BooleanExpression::FieldLt(e) => {
let span = e.get_span();

Expand Down
Loading

0 comments on commit 8c08164

Please sign in to comment.