Skip to content

Commit

Permalink
Merge pull request #1223 from Zokrates/rc/0.8.2
Browse files Browse the repository at this point in the history
Release 0.8.2
  • Loading branch information
Schaeff authored Sep 5, 2022
2 parents 5744359 + 269db70 commit f592a4a
Show file tree
Hide file tree
Showing 307 changed files with 9,150 additions and 4,645 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ executors:
image: ubuntu-2004:202101-01
macos:
macos:
xcode: 12.4.0
xcode: 13.4.1

jobs:
build:
Expand Down Expand Up @@ -279,7 +279,7 @@ workflows:
<<: *tag-only
pre-steps:
- install_rust
build-with: SDKROOT=$(xcrun -sdk macosx11.1 --show-sdk-path) MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.1 --show-sdk-platform-version) cargo
build-with: SDKROOT=$(xcrun -sdk macosx12.3 --show-sdk-path) MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx12.3 --show-sdk-platform-version) cargo
add-target: true
matrix:
alias: cross-build-apple-silicon
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/js-format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Check JS/JSON/TS format
on: [pull_request]
jobs:
js-format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check format with prettier
uses: creyD/prettier_action@v4.2
with:
prettier_options: --check ./**/*.{js,ts,json}
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
https://github.com/Zokrates/ZoKrates/compare/latest...develop

## [0.8.2] - 2022-09-05

### Release
- https://github.com/Zokrates/ZoKrates/releases/tag/0.8.2 <!-- markdown-link-check-disable-line -->

### Changes
- Make return statement optional if no returns are expected (#1222, @dark64)
- Add a casting utility module to stdlib (#1215, @dark64)
- Introduce dead code elimination (#1206, @schaeff)
- Add magic square in javascript example to the book (#1198, @dark64)
- Fix circom r1cs export to avoid generating unverified proofs (#1220, @schaeff)
- Allow shadowing (#1193, @schaeff)

## [0.8.1] - 2022-08-22

### Release
Expand Down
15 changes: 8 additions & 7 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ You can enable zokrates git hooks locally by running:
```sh
git config core.hooksPath .githooks
```

### `{js,json,ts}` formatting

We enforce strict formatting of `.{js,json,ts}` files in CI. This check is not included in the git hooks. If you modify such a file, you can ensure its formatting is correct by running:

```
npm i -g prettier
prettier --write "./**/*.{js,ts,json}" --ignore-path .gitignore
```
2 changes: 1 addition & 1 deletion zokrates_ast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zokrates_ast"
version = "0.1.1"
version = "0.1.2"
edition = "2021"

[features]
Expand Down
20 changes: 13 additions & 7 deletions zokrates_ast/src/common/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ pub enum RuntimeError {
BranchIsolation,
ConstantLtBitness,
ConstantLtSum,
LtBitness,
LtSum,
LtFinalBitness,
LtFinalSum,
LtSymetric,
Or,
Xor,
IncompleteDynamicRange,
Inverse,
Euclidean,
ShaXor,
Expand All @@ -37,6 +35,10 @@ impl From<crate::zir::RuntimeError> for RuntimeError {
match error {
crate::zir::RuntimeError::SourceAssertion(s) => RuntimeError::SourceAssertion(s),
crate::zir::RuntimeError::SelectRangeCheck => RuntimeError::SelectRangeCheck,
crate::zir::RuntimeError::DivisionByZero => RuntimeError::Inverse,
crate::zir::RuntimeError::IncompleteDynamicRange => {
RuntimeError::IncompleteDynamicRange
}
}
}
}
Expand All @@ -47,7 +49,11 @@ impl RuntimeError {

!matches!(
self,
SourceAssertion(_) | Inverse | LtSum | SelectRangeCheck | ArgumentBitness
SourceAssertion(_)
| Inverse
| SelectRangeCheck
| ArgumentBitness
| IncompleteDynamicRange
)
}
}
Expand All @@ -70,13 +76,13 @@ impl fmt::Display for RuntimeError {
BranchIsolation => "Branch isolation failed",
ConstantLtBitness => "Bitness check failed in constant Lt check",
ConstantLtSum => "Sum check failed in constant Lt check",
LtBitness => "Bitness check failed in Lt check",
LtSum => "Sum check failed in Lt check",
LtFinalBitness => "Bitness check failed in final Lt check",
LtFinalSum => "Sum check failed in final Lt check",
LtSymetric => "Symetrical check failed in Lt check",
Or => "Or check failed",
Xor => "Xor check failed",
IncompleteDynamicRange => {
"Failed to compare field elements because dynamic comparison is incomplete"
}
Inverse => "Division by zero",
Euclidean => "Euclidean check failed",
ShaXor => "Internal Sha check failed",
Expand Down
9 changes: 0 additions & 9 deletions zokrates_ast/src/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,6 @@ impl<T: Field> fmt::Display for Prog<T> {
for s in &self.statements {
writeln!(f, "\t{}", s)?;
}
writeln!(
f,
"\treturn {}",
(0..self.return_count)
.map(Variable::public)
.map(|e| format!("{}", e))
.collect::<Vec<_>>()
.join(", ")
)?;

writeln!(f, "\treturn {}", returns)?;
writeln!(f, "}}")
Expand Down
22 changes: 15 additions & 7 deletions zokrates_ast/src/typed/folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ pub trait Folder<'ast, T: Field>: Sized {
fold_statement(self, s)
}

fn fold_definition_rhs(&mut self, rhs: DefinitionRhs<'ast, T>) -> DefinitionRhs<'ast, T> {
fold_definition_rhs(self, rhs)
}

fn fold_embed_call(&mut self, e: EmbedCall<'ast, T>) -> EmbedCall<'ast, T> {
fold_embed_call(self, e)
}
Expand Down Expand Up @@ -491,14 +495,24 @@ pub fn fold_constant_symbol_declaration<'ast, T: Field, F: Folder<'ast, T>>(
}
}

pub fn fold_definition_rhs<'ast, T: Field, F: Folder<'ast, T>>(
f: &mut F,
rhs: DefinitionRhs<'ast, T>,
) -> DefinitionRhs<'ast, T> {
match rhs {
DefinitionRhs::EmbedCall(c) => DefinitionRhs::EmbedCall(f.fold_embed_call(c)),
DefinitionRhs::Expression(e) => DefinitionRhs::Expression(f.fold_expression(e)),
}
}

pub fn fold_statement<'ast, T: Field, F: Folder<'ast, T>>(
f: &mut F,
s: TypedStatement<'ast, T>,
) -> Vec<TypedStatement<'ast, T>> {
let res = match s {
TypedStatement::Return(e) => TypedStatement::Return(f.fold_expression(e)),
TypedStatement::Definition(a, e) => {
TypedStatement::Definition(f.fold_assignee(a), f.fold_expression(e))
TypedStatement::Definition(f.fold_assignee(a), f.fold_definition_rhs(e))
}
TypedStatement::Assertion(e, error) => {
TypedStatement::Assertion(f.fold_boolean_expression(e), error)
Expand All @@ -515,12 +529,6 @@ pub fn fold_statement<'ast, T: Field, F: Folder<'ast, T>>(
TypedStatement::Log(s, e) => {
TypedStatement::Log(s, e.into_iter().map(|e| f.fold_expression(e)).collect())
}
TypedStatement::EmbedCallDefinition(assignee, embed_call) => {
TypedStatement::EmbedCallDefinition(
f.fold_assignee(assignee),
f.fold_embed_call(embed_call),
)
}
s => s,
};
vec![res]
Expand Down
59 changes: 39 additions & 20 deletions zokrates_ast/src/typed/identifier.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::typed::CanonicalConstantIdentifier;
use std::convert::TryInto;
use std::fmt;

pub type SourceIdentifier<'ast> = &'ast str;

#[derive(Debug, PartialEq, Clone, Hash, Eq, PartialOrd, Ord)]
pub enum CoreIdentifier<'ast> {
Source(&'ast str),
Source(ShadowedIdentifier<'ast>),
Call(usize),
Constant(CanonicalConstantIdentifier<'ast>),
Condition(usize),
Expand All @@ -21,12 +22,6 @@ impl<'ast> fmt::Display for CoreIdentifier<'ast> {
}
}

impl<'ast> From<&'ast str> for CoreIdentifier<'ast> {
fn from(s: &str) -> CoreIdentifier {
CoreIdentifier::Source(s)
}
}

impl<'ast> From<CanonicalConstantIdentifier<'ast>> for CoreIdentifier<'ast> {
fn from(s: CanonicalConstantIdentifier<'ast>) -> CoreIdentifier<'ast> {
CoreIdentifier::Constant(s)
Expand All @@ -42,13 +37,24 @@ pub struct Identifier<'ast> {
pub version: usize,
}

impl<'ast> TryInto<&'ast str> for Identifier<'ast> {
type Error = ();
#[derive(Debug, PartialEq, Clone, Hash, Eq, PartialOrd, Ord)]
pub struct ShadowedIdentifier<'ast> {
pub id: SourceIdentifier<'ast>,
pub shadow: usize,
}

impl<'ast> ShadowedIdentifier<'ast> {
pub fn shadow(id: SourceIdentifier<'ast>, shadow: usize) -> Self {
Self { id, shadow }
}
}

fn try_into(self) -> Result<&'ast str, Self::Error> {
match self.id {
CoreIdentifier::Source(i) => Ok(i),
_ => Err(()),
impl<'ast> fmt::Display for ShadowedIdentifier<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.shadow == 0 {
write!(f, "{}", self.id)
} else {
write!(f, "{}_{}", self.id, self.shadow)
}
}
}
Expand All @@ -69,21 +75,34 @@ impl<'ast> From<CanonicalConstantIdentifier<'ast>> for Identifier<'ast> {
}
}

impl<'ast> From<&'ast str> for Identifier<'ast> {
fn from(id: &'ast str) -> Identifier<'ast> {
Identifier::from(CoreIdentifier::Source(id))
}
}

impl<'ast> From<CoreIdentifier<'ast>> for Identifier<'ast> {
fn from(id: CoreIdentifier<'ast>) -> Identifier<'ast> {
Identifier { id, version: 0 }
}
}

impl<'ast> From<ShadowedIdentifier<'ast>> for CoreIdentifier<'ast> {
fn from(id: ShadowedIdentifier<'ast>) -> CoreIdentifier<'ast> {
CoreIdentifier::Source(id)
}
}

impl<'ast> Identifier<'ast> {
pub fn version(mut self, version: usize) -> Self {
self.version = version;
self
}
}

// these two From implementations are only used in tests but somehow cfg(test) doesn't work
impl<'ast> From<&'ast str> for CoreIdentifier<'ast> {
fn from(s: &str) -> CoreIdentifier {
CoreIdentifier::Source(ShadowedIdentifier::shadow(s, 0))
}
}

impl<'ast> From<&'ast str> for Identifier<'ast> {
fn from(id: &'ast str) -> Identifier<'ast> {
Identifier::from(CoreIdentifier::from(id))
}
}
Loading

0 comments on commit f592a4a

Please sign in to comment.