Skip to content

Commit

Permalink
Merge pull request #1027 from Zokrates/rc/0.7.7
Browse files Browse the repository at this point in the history
Release 0.7.7
  • Loading branch information
Schaeff authored Oct 4, 2021
2 parents b5d2afd + 0444564 commit fc55d88
Show file tree
Hide file tree
Showing 93 changed files with 5,801 additions and 2,516 deletions.
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ jobs:
- checkout
- run:
name: Build
no_output_timeout: "30m"
command: cd zokrates_js && npm run build:dev
zokrates_js_test:
docker:
Expand All @@ -142,6 +143,7 @@ jobs:
command: cargo clippy -- -D warnings
- run:
name: Run tests
no_output_timeout: "30m"
command: npm run test
cross_build:
parameters:
Expand All @@ -168,7 +170,7 @@ jobs:
- run:
name: Build
no_output_timeout: "30m"
command: << parameters.build-with >> build --target << parameters.target >> --release
command: RUSTFLAGS="--remap-path-prefix=$PWD=" << parameters.build-with >> build --target << parameters.target >> --release
- tar_artifacts:
target: << parameters.target >>
publish_artifacts:
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
https://github.com/Zokrates/ZoKrates/compare/latest...develop

## [0.7.7] - 2021-10-04

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

### Changes
- Reduce the deployment cost of the g16 and pghr13 verifiers (#1008, @m1cm1c)
- Make operators table more clear in the book (#1017, @dark64)
- Allow calls in constant definitions (#975, @schaeff)
- Handle out of bound accesses gracefully (#1013, @schaeff)
- Improve error message on unconstrained variable detection (#1015, @dark64)
- Apply propagation in ZIR (#957, @dark64)
- Fail on mistyped constants (#974, @schaeff)
- Graceful error handling on unconstrained variable detection (#977, @dark64)
- Fix incorrect propagation of spreads (#987, @schaeff)
- Add range semantics to docs (#992, @dark64)
- Fix invalid cast to `usize` which caused wrong values in 32-bit environments (#998, @dark64)

## [0.7.6] - 2021-08-16

### Release
Expand Down
4 changes: 2 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 build_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Exit if any subcommand fails
set -e
export RUSTFLAGS="--remap-path-prefix=$PWD="

if [ -n "$WITH_LIBSNARK" ]; then
cargo build --release --package zokrates_cli --features="libsnark"
Expand Down
1 change: 1 addition & 0 deletions zokrates_book/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
book
mdbook
2 changes: 1 addition & 1 deletion zokrates_book/src/examples/sha256example.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Based on that Victor can run the setup phase and export a verifier smart contrac
{{#include ../../../zokrates_cli/examples/book/sha256_tutorial/test.sh:18:19}}
```

`setup` creates a `verifiation.key` file and a `proving.key` file. Victor gives the proving key to Peggy.
`setup` creates a `verification.key` file and a `proving.key` file. Victor gives the proving key to Peggy.

`export-verifier` creates a `verifier.sol` contract that contains our verification key and a function `verifyTx`. Victor deploys this smart contract to the Ethereum network.

Expand Down
4 changes: 2 additions & 2 deletions zokrates_book/src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ZoKrates is a toolbox for zkSNARKs on Ethereum. It helps you use verifiable comp

One particular family of ZKPs is described as zero-knowledge **S**uccinct **N**on-interactive **AR**guments of **K**nowledge, a.k.a. zkSNARKs. zkSNARKs are the most widely used zero-knowledge protocols, with the anonymous cryptocurrency Zcash and the smart-contract platform Ethereum among the notable early adopters.

For further details we refer the reader to some introductory material provided by the community: [[1]](https://z.cash/technology/zksnarks/),[[2]](https://medium.com/@VitalikButerin/zkSNARKs-under-the-hood-b33151a013f6), [[3]](https://blog.decentriq.ch/zk-SNARKs-primer-part-one/).
For further details we refer the reader to some introductory material provided by the community: [[1]](https://z.cash/technology/zksnarks/), [[2]](https://medium.com/@VitalikButerin/zkSNARKs-under-the-hood-b33151a013f6), [[3]](https://blog.decentriq.ch/zk-SNARKs-primer-part-one/).

## Motivation

Expand All @@ -19,4 +19,4 @@ ZoKrates bridges this gap. It helps you create off-chain programs and link them

## License

ZoKrates is released under the GNU Lesser General Public License v3.
ZoKrates is released under the GNU Lesser General Public License v3.
1 change: 1 addition & 0 deletions zokrates_book/src/language/control_flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ For loops are available with the following syntax:
```

The bounds have to be constant at compile-time, therefore they cannot depend on execution inputs. They can depend on generic parameters.
The range is half-open, meaning it is bounded inclusively below and exclusively above. The range `start..end` contains all values within `start <= x < end`. The range is empty if `start >= end`.

> For loops are only syntactic sugar for repeating a block of statements many times. No condition of the type `index < max` is being checked at run-time after each iteration. Instead, at compile-time, the index is incremented and the block is executed again. Therefore, assigning to the loop index does not have any influence on the number of iterations performed and is considered bad practice.
Expand Down
32 changes: 16 additions & 16 deletions zokrates_book/src/language/operators.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
## Operators

The following table lists the precedence and associativity of all operators. Operators are listed top to bottom, in ascending precedence. Operators in the same box group left to right. Operators are binary, unless the syntax is provided.
The following table lists the precedence and associativity of all operators. Operators are listed top to bottom, in ascending precedence. Operators in the same cell have the same precedence. Operators are binary, unless the syntax is provided.

| Operator | Description | Remarks |
|---------------------------------|-------------------------------------------------------------------|---------|
| `**` <br> | Power | [^1] |
| `+x` <br> `-x` <br> `!x` <br> | Positive <br> Negative <br> Negation <br> | |
| `*` <br> `/` <br> `%` <br> | Multiplication <br> Division <br> Remainder <br> | |
| `+` <br> `-` <br> | Addition <br> Subtraction <br> | |
| `<<` <br> `>>` <br> | Left shift <br> Right shift <br> | [^2] |
| `&` | Bitwise AND | |
| <code>&#124;</code> | Bitwise OR | |
| `^` | Bitwise XOR | |
| `>=` <br> `>` <br> `<=` <br> `<`| Greater or equal <br> Greater <br> Lower or equal <br> Lower <br> | [^3] |
| `!=` <br> `==` <br> | Not Equal <br> Equal <br> | |
| `&&` | Boolean AND | |
| <code>&#124;&#124;</code> | Boolean OR | |
| `if c then x else y fi` | Conditional expression | |
| Operator | Description | `field` | `u8/u16` `u32/u64` | `bool` | Associativity | Remarks |
|----------------------------|------------------------------------------------------------|------------------------------|-------------------------------|-----------------------------|---------------|---------|
| `**`<br> | Power | &check; | &nbsp; | &nbsp; | Left | [^1] |
| `+x`<br>`-x`<br>`!x`<br> | Positive<br>Negative<br>Negation<br> | &check;<br>&check;<br>&nbsp; | &check;<br>&check;<br>&nbsp; | &nbsp;<br>&nbsp;<br>&check; | Right | |
| `*`<br>`/`<br>`%`<br> | Multiplication<br> Division<br> Remainder<br> | &check;<br>&check;<br>&nbsp; | &check;<br>&check;<br>&check; | &nbsp;<br>&nbsp;<br>&nbsp; | Left | |
| `+`<br>`-`<br> | Addition<br> Subtraction<br> | &check; | &check; | &nbsp; | Left | |
| `<<`<br>`>>`<br> | Left shift<br> Right shift<br> | &nbsp; | &check; | &nbsp; | Left | [^2] |
| `&` | Bitwise AND | &nbsp; | &check; | &nbsp; | Left | |
| <code>&#124;</code> | Bitwise OR | &nbsp; | &check; | &nbsp; | Left | |
| `^` | Bitwise XOR | &nbsp; | &check; | &nbsp; | Left | |
| `>=`<br>`>`<br>`<=`<br>`<` | Greater or equal<br>Greater<br>Lower or equal<br>Lower<br> | &check; | &check; | &nbsp; | Left | [^3] |
| `!=`<br>`==`<br> | Not Equal<br>Equal<br> | &check; | &check; | &check; | Left | |
| `&&` | Boolean AND | &nbsp; | &nbsp; | &check; | Left | |
| <code>&#124;&#124;</code> | Boolean OR | &nbsp; | &nbsp; | &check; | Left | |
| `if c then x else y fi` | Conditional expression | &check; | &check; | &check; | Right | |

[^1]: The exponent must be a compile-time constant of type `u32`

Expand Down
5 changes: 3 additions & 2 deletions zokrates_book/src/language/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ZoKrates currently exposes two primitive types and two complex types:

### `field`

This is the most basic type in ZoKrates, and it represents a field element with positive integer values in `[0, p - 1]` where `p` is a (large) prime number. Standard arithmetic operations are supported; note that [division in the finite field](https://en.wikipedia.org/wiki/Finite_field_arithmetic) behaves differently than in the case of integers.
This is the most basic type in ZoKrates, and it represents a field element with positive integer values in `[0, p - 1]` where `p` is a (large) prime number.

As an example, `p` is set to `21888242871839275222246405745257275088548364400416034343698204186575808495617` when working with the [ALT_BN128](../toolbox/proving_schemes.md#curves) curve supported by Ethereum.

Expand All @@ -16,7 +16,8 @@ While `field` values mostly behave like unsigned integers, one should keep in mi
{{#include ../../../zokrates_cli/examples/book/field_overflow.zok}}
```

Note that for field elements, the division operation multiplies the numerator with the denominator's inverse field element. The results coincide with integer divisions for cases with remainder 0, but differ otherwise.
Note that [division in the finite field](https://en.wikipedia.org/wiki/Finite_field_arithmetic) behaves differently than in the case of integers.
For field elements, the division operation multiplies the numerator with the denominator's inverse field element. The results coincide with integer divisions for cases with remainder 0, but differ otherwise.

### `bool`

Expand Down
2 changes: 1 addition & 1 deletion zokrates_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zokrates_cli"
version = "0.7.6"
version = "0.7.7"
authors = ["Jacob Eberhardt <jacob.eberhardt@tu-berlin.de>", "Dennis Kuhnert <mail@kyroy.com>", "Thibaut Schaeffer <thibaut@schaeff.fr>"]
repository = "https://github.com/Zokrates/ZoKrates.git"
edition = "2018"
Expand Down
11 changes: 11 additions & 0 deletions zokrates_cli/examples/array_generic_inference.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def myFct<N, N2>(u64[N] ignored) -> u64[N2]:
assert(2*N == N2)
return [0; N2]

const u32 N = 3

const u32 N2 = 2*N

def main(u64[N] arg) -> bool:
u64[N2] someVariable = myFct(arg)
return true
10 changes: 10 additions & 0 deletions zokrates_cli/examples/call_in_const.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from "./call_in_const_aux.zok" import A, foo, F

def bar(field[A] x) -> field[A]:
return x

const field[A] Y = [...bar(foo::<A>(F))[..A - 1], 1]

def main(field[A] X):
assert(X == Y)
return
9 changes: 9 additions & 0 deletions zokrates_cli/examples/call_in_const_aux.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const field F = 10
const u32 A = 10
const u32 B = A

def foo<N>(field X) -> field[N]:
return [X; N]

def main():
return
7 changes: 7 additions & 0 deletions zokrates_cli/examples/call_in_constant.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def yes() -> bool:
return true

const bool TRUE = yes()

def main():
return
14 changes: 14 additions & 0 deletions zokrates_cli/examples/compile_errors/ambiguous_generic_call.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// this should not compile, as A == B

const u32 A = 1
const u32 B = 1

def foo(field[A] a) -> bool:
return true

def foo(field[B] a) -> bool:
return true

def main():
assert(foo([1]))
return
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// this should actually compile, as A != B

const u32 A = 2
const u32 B = 1

def foo(field[A] a) -> bool:
return true

def foo(field[B] a) -> bool:
return true

def main():
assert(foo([1]))
return
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const u32 ONE = 1
const u32 TWO = 2
const field[ONE] ONE_FIELD = [1; TWO] // actually set the value to an array of 2 elements

def main(field[TWO] TWO_FIELDS):
assert(TWO_FIELDS == ONE_FIELD) // use the value as is
return
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from "EMBED" import bit_array_le

const bool CONST = bit_array_le([true], [true])

def main() -> bool:
return CONST
3 changes: 3 additions & 0 deletions zokrates_cli/examples/compile_errors/div_by_zero.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def main(field input) -> field:
field divisor = if [input, 0] != [input, 1] then 0 else 1 fi
return input / divisor
4 changes: 4 additions & 0 deletions zokrates_cli/examples/compile_errors/out_of_bounds.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def main(field a, field b) -> field:
field[10] arr = [0; 10]
u32 index = if [a, 1] != [b, 0] then 1000 else 0 fi
return arr[index]
7 changes: 7 additions & 0 deletions zokrates_cli/examples/compile_errors/out_of_bounds_read.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def foo(field[1] a) -> field[1]:
return a

def main(field a):
field[1] h = foo([a])
field f = h[1]
return
7 changes: 7 additions & 0 deletions zokrates_cli/examples/compile_errors/out_of_bounds_write.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def foo(field[1] a) -> field[1]:
return a

def main(field a):
field[1] h = foo([a])
h[1] = 1
return
2 changes: 2 additions & 0 deletions zokrates_cli/examples/compile_errors/unconstrained_input.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main(private field a) -> field:
return 1
14 changes: 14 additions & 0 deletions zokrates_cli/examples/complex_call_in_constant.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def constant() -> u32:
u32 res = 0
u32 x = 3
for u32 y in 0..x do
res = res + 1
endfor
return res

const u32 CONSTANT = 1 + constant()

const u32 OTHER_CONSTANT = 42

def main(field[CONSTANT] a) -> u32:
return CONSTANT + OTHER_CONSTANT
16 changes: 16 additions & 0 deletions zokrates_cli/examples/empty_spread_propagation.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def func<N>() -> bool:
for u32 i in 0..N do
endfor

u64[N] y = [...[0; N-1], 1] // the rhs should *not* be reduced to [1] because the spread is not empty
u64 q = 0

for u32 i in 0..N do
q = y[i]
endfor

return true

def main():
assert(func::<2>())
return
15 changes: 15 additions & 0 deletions zokrates_cli/examples/struct_generic_inference.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
struct SomeStruct<N> {
u64[N] f
}

def myFct<N, N2, N3>(SomeStruct<N> ignored) -> u32[N2]:
assert(2*N == N2)
return [N3; N2]

const u32 N = 3

const u32 N2 = 2*N

def main(SomeStruct<N> arg) -> u32:
u32[N2] someVariable = myFct::<_, _, 42>(arg)
return someVariable[0]
7 changes: 2 additions & 5 deletions zokrates_cli/src/ops/compute_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,8 @@ fn cli_compute<T: Field>(ir_prog: ir::Prog<T>, sub_matches: &ArgMatches) -> Resu
abi.signature()
}
false => ConcreteSignature::new()
.inputs(vec![
ConcreteType::FieldElement;
ir_prog.main.arguments.len()
])
.outputs(vec![ConcreteType::FieldElement; ir_prog.main.returns.len()]),
.inputs(vec![ConcreteType::FieldElement; ir_prog.arguments.len()])
.outputs(vec![ConcreteType::FieldElement; ir_prog.returns.len()]),
};

use zokrates_abi::Inputs;
Expand Down
Loading

0 comments on commit fc55d88

Please sign in to comment.