fix PR comments
This commit is contained in:
parent
a7e5477d2b
commit
94f855ede8
31 changed files with 53 additions and 46 deletions
|
@ -1,5 +1,5 @@
|
||||||
import "./IVconstants.code" as IVconstants
|
import "./IVconstants.code" as IVconstants
|
||||||
import "./shaRound.code" as sha256
|
import "./shaRoundNoBoolCheck.code" as sha256
|
||||||
|
|
||||||
// A function that takes 4 field[256] arrays as inputs
|
// A function that takes 4 field[256] arrays as inputs
|
||||||
// and applies 2 rounds of sha256 compression.
|
// and applies 2 rounds of sha256 compression.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import "./IVconstants.code" as IVconstants
|
import "./IVconstants.code" as IVconstants
|
||||||
import "./shaRound.code" as sha256
|
import "./shaRoundNoBoolCheck.code" as sha256
|
||||||
|
|
||||||
// A function that takes 6 field[256] arrays as inputs
|
// A function that takes 6 field[256] arrays as inputs
|
||||||
// and applies 3 rounds of sha256 compression.
|
// and applies 3 rounds of sha256 compression.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import "./IVconstants.code" as IVconstants
|
import "./IVconstants.code" as IVconstants
|
||||||
import "./shaRound.code" as sha256
|
import "./shaRoundNoBoolCheck.code" as sha256
|
||||||
|
|
||||||
// A function that takes 2 field[256] arrays as inputs
|
// A function that takes 2 field[256] arrays as inputs
|
||||||
// and returns their sha256 compression function as an array of 256 field elements.
|
// and returns their sha256 compression function as an array of 256 field elements.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import "./1024bit.code" as sha256
|
import "./1024bit.code" as sha256
|
||||||
|
|
||||||
// A function that takes 2 field[256] arrays as inputs
|
// A function that takes 2 field[256] arrays as inputs
|
||||||
// and returns their sha256 compression function as an array of 256 field elements.
|
// and returns their sha256 full round output as an array of 256 field elements.
|
||||||
def main(field[256] a, field[256] b) -> (field[256]):
|
def main(field[256] a, field[256] b) -> (field[256]):
|
||||||
|
|
||||||
// Hash is computed on the full 512bit block size
|
// Hash is computed on the full 512bit block size
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,8 +0,0 @@
|
||||||
// ANDXORNOTAND
|
|
||||||
|
|
||||||
import "./and.code" as AND
|
|
||||||
import "./xor.code" as XOR
|
|
||||||
import "./not.code" as NOT
|
|
||||||
|
|
||||||
def main(field a, field b, field c) -> (field):
|
|
||||||
return XOR(AND(a, b), AND(NOT(a), c))
|
|
|
@ -1,4 +0,0 @@
|
||||||
// COPY
|
|
||||||
|
|
||||||
def main(field[32] b) -> (field[32]):
|
|
||||||
return b
|
|
|
@ -3,9 +3,7 @@ def main(field selector, field[256] lhs, field[256] rhs) -> (field[256]):
|
||||||
field[256] out = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
field[256] out = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
|
||||||
for field i in 0..256 do
|
for field i in 0..256 do
|
||||||
|
|
||||||
out[i] = if selector == 0 then lhs[i] else rhs[i] fi
|
out[i] = if selector == 0 then lhs[i] else rhs[i] fi
|
||||||
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return out
|
return out
|
|
@ -3,9 +3,7 @@ def main(field selector, field[2] lhs, field[2] rhs) -> (field[2]):
|
||||||
field[2] out = [0, 0]
|
field[2] out = [0, 0]
|
||||||
|
|
||||||
for field i in 0..2 do
|
for field i in 0..2 do
|
||||||
|
|
||||||
out[i] = if selector == 0 then lhs[i] else rhs[i] fi
|
out[i] = if selector == 0 then lhs[i] else rhs[i] fi
|
||||||
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return out
|
return out
|
|
@ -16,7 +16,7 @@ import "../mycode.code"
|
||||||
|
|
||||||
Also imports further up the file-system are supported:
|
Also imports further up the file-system are supported:
|
||||||
```zokrates
|
```zokrates
|
||||||
import "./../../../mycode.code"
|
import "../../../mycode.code"
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also choose to rename the imported resource, like so:
|
You can also choose to rename the imported resource, like so:
|
||||||
|
@ -26,4 +26,5 @@ import "./mycode.code" as abc
|
||||||
|
|
||||||
### Absolute Imports
|
### Absolute Imports
|
||||||
|
|
||||||
Absolute imports don't start with `./` in the path and are used to import components from the ZoKrates standard library. Please check the according [section](./stdlib.html) for more details.
|
Absolute imports don't start with `./` or `../` in the path and are used to import components from the ZoKrates standard library. Please check the according [section](./stdlib.html) for more details.
|
||||||
|
`
|
|
@ -1,6 +1,6 @@
|
||||||
## Standard library
|
## Standard library
|
||||||
|
|
||||||
ZoKrates comes with a number of reusable components which are defined at `./stdlib/` in the ZoKrates root folder. The standard library is solely based on the ZoKrates DSL and can be easily extended.
|
ZoKrates comes with a number of reusable components which are defined at `./stdlib/` in the ZoKrates root repository. In order to import the standard library as described in the [imports](./imports.html) section the `$ZOKRATES_HOME` environment variable needs to be set to the `stdlib` folder. The standard library is solely based on the ZoKrates DSL and can be easily extended.
|
||||||
|
|
||||||
The following section highlights a subset of available imports:
|
The following section highlights a subset of available imports:
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ A function that takes an array of 4 field elements as inputs, unpacks each of th
|
||||||
|
|
||||||
### Direct imports
|
### Direct imports
|
||||||
|
|
||||||
Some components of the standard library can not be efficiently represented in the ZoKrates DSL language. Those functions are injected at compile-time and are available by default.
|
Some components of the standard library cannot yet be efficiently represented in the ZoKrates DSL language. Those functions are injected at compile-time and are available by default.
|
||||||
|
|
||||||
#### pack128
|
#### pack128
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ Make sure you have followed the instructions in the [Getting Started](gettingsta
|
||||||
|
|
||||||
We will start this tutorial by using ZoKrates to compute the hash for an arbitrarily chosen preimage, being the number `5` in this example.
|
We will start this tutorial by using ZoKrates to compute the hash for an arbitrarily chosen preimage, being the number `5` in this example.
|
||||||
|
|
||||||
First, make sure that the `zokrates` binary is located in the `ZoKrates` directory. Then, we create a new file named `hashexample.code` with the following content:
|
First, we create a new file named `hashexample.code` with the following content:
|
||||||
|
|
||||||
```zokrates
|
```zokrates
|
||||||
{{#include ../../zokrates_cli/examples/book/hashexample.code}}
|
{{#include ../../zokrates_cli/examples/book/hashexample.code}}
|
||||||
|
|
|
@ -6,7 +6,6 @@ repository = "https://github.com/JacobEberhardt/ZoKrates.git"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# default = []
|
|
||||||
default = ["libsnark"]
|
default = ["libsnark"]
|
||||||
libsnark = ["zokrates_core/libsnark"]
|
libsnark = ["zokrates_core/libsnark"]
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,20 @@
|
||||||
|
// Python code used to create test vector:
|
||||||
|
// import hashlib
|
||||||
|
|
||||||
|
// preimage = bytes.fromhex('00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
|
||||||
|
// 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05')
|
||||||
|
|
||||||
|
// bin(int(preimage.hex(), 16))
|
||||||
|
// # '0b101'
|
||||||
|
|
||||||
|
// digest = hashlib.sha256(preimage).hexdigest()
|
||||||
|
// # digest = 'c6481e22c5ff4164af680b8cfaa5e8ed3120eeff89c4f307c4a6faaae059ce10'
|
||||||
|
|
||||||
|
// int(digest[:32], 16)
|
||||||
|
// # 263561599766550617289250058199814760685
|
||||||
|
// int(digest[32:], 16)
|
||||||
|
// # 65303172752238645975888084098459749904
|
||||||
|
|
||||||
import "hashes/sha256/512bitPacked.code" as sha256packed
|
import "hashes/sha256/512bitPacked.code" as sha256packed
|
||||||
def main() -> (field):
|
def main() -> (field):
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import "merkleTree/sha256PathProof.code" as merkleTreeProof
|
import "merkleTree/sha256PathProof3.code" as merkleTreeProof
|
||||||
def main() -> (field):
|
def main() -> (field):
|
||||||
|
|
||||||
field treeDepth = 3
|
field treeDepth = 3
|
|
@ -1,7 +1,7 @@
|
||||||
// ANDXORANDXORAND
|
// ANDXORANDXORAND
|
||||||
|
|
||||||
import "./xor.code" as XOR
|
import "utils/binary/xor.code" as XOR
|
||||||
import "./and.code" as AND
|
import "utils/binary/and.code" as AND
|
||||||
|
|
||||||
def main(field a, field b, field c) -> (field):
|
def main(field a, field b, field c) -> (field):
|
||||||
return XOR(XOR(AND(a, b), AND(a, c)), AND(b, c))
|
return XOR(XOR(AND(a, b), AND(a, c)), AND(b, c))
|
8
zokrates_cli/examples/sha256/binary/andxornotand.code
Normal file
8
zokrates_cli/examples/sha256/binary/andxornotand.code
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// ANDXORNOTAND
|
||||||
|
|
||||||
|
import "utils/binary/and.code" as AND
|
||||||
|
import "utils/binary/xor.code" as XOR
|
||||||
|
import "utils/binary/not.code" as NOT
|
||||||
|
|
||||||
|
def main(field a, field b, field c) -> (field):
|
||||||
|
return XOR(AND(a, b), AND(NOT(a), c))
|
|
@ -1,7 +1,7 @@
|
||||||
// FULLADD
|
// FULLADD
|
||||||
|
|
||||||
import "./halfadd.code" as HALFADD
|
import "./halfadd.code" as HALFADD
|
||||||
import "./or.code" as OR
|
import "utils/binary/or.code" as OR
|
||||||
|
|
||||||
def main(field a, field b, field car) -> (field, field):
|
def main(field a, field b, field car) -> (field, field):
|
||||||
out1, car1 = HALFADD(a, b)
|
out1, car1 = HALFADD(a, b)
|
|
@ -1,7 +1,7 @@
|
||||||
// HALFADD
|
// HALFADD
|
||||||
|
|
||||||
import "./xor.code" as XOR
|
import "utils/binary/xor.code" as XOR
|
||||||
import "./and.code" as AND
|
import "utils/binary/and.code" as AND
|
||||||
|
|
||||||
def main(field a, field b) -> (field, field):
|
def main(field a, field b) -> (field, field):
|
||||||
return XOR(a, b), AND(a, b)
|
return XOR(a, b), AND(a, b)
|
|
@ -1,6 +1,6 @@
|
||||||
// AND
|
// AND
|
||||||
|
|
||||||
import "./../../binary/and.code" as AND
|
import "utils/binary/and.code" as AND
|
||||||
|
|
||||||
def main(field[32] b, field[32] c) -> (field[32]):
|
def main(field[32] b, field[32] c) -> (field[32]):
|
||||||
field[32] result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
field[32] result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
@ -1,6 +1,6 @@
|
||||||
// NOT
|
// NOT
|
||||||
|
|
||||||
import "./../../binary/not.code" as NOT
|
import "utils/binary/not.code" as NOT
|
||||||
|
|
||||||
def main(field[32] b) -> (field[32]):
|
def main(field[32] b) -> (field[32]):
|
||||||
field[32] result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
field[32] result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
@ -1,6 +1,6 @@
|
||||||
// XOR
|
// XOR
|
||||||
|
|
||||||
import "./../../binary/xor.code" as XOR
|
import "utils/binary/xor.code" as XOR
|
||||||
|
|
||||||
def main(field[32] b, field[32] c) -> (field[32]):
|
def main(field[32] b, field[32] c) -> (field[32]):
|
||||||
field[32] result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
field[32] result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
@ -1,6 +1,6 @@
|
||||||
// ADD
|
// ADD
|
||||||
|
|
||||||
import "utils/binary/fulladd.code" as FULLADD
|
import "../../binary/fulladd.code" as FULLADD
|
||||||
|
|
||||||
def main(field[32] b, field[32] c) -> (field[32]):
|
def main(field[32] b, field[32] c) -> (field[32]):
|
||||||
field[33] car = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
field[33] car = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// AR17XAR19XAR10
|
// AR17XAR19XAR10
|
||||||
|
|
||||||
import "utils/bitwise/32/xor.code" as XOR
|
import "../../bitwise/32/xor.code" as XOR
|
||||||
|
|
||||||
def RR17(field[32] b) -> (field[32]):
|
def RR17(field[32] b) -> (field[32]):
|
||||||
return [b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24], b[25], b[26], b[27], b[28], b[29], b[30], b[31], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14]]
|
return [b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24], b[25], b[26], b[27], b[28], b[29], b[30], b[31], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14]]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// AR2XAR13XAR22
|
// AR2XAR13XAR22
|
||||||
|
|
||||||
import "utils/bitwise/32/xor.code" as XOR
|
import "../../bitwise/32/xor.code" as XOR
|
||||||
|
|
||||||
def RR2(field[32] b) -> (field[32]):
|
def RR2(field[32] b) -> (field[32]):
|
||||||
return [b[30], b[31], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24], b[25], b[26], b[27], b[28], b[29]]
|
return [b[30], b[31], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24], b[25], b[26], b[27], b[28], b[29]]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// AR6XAR11XAR25
|
// AR6XAR11XAR25
|
||||||
|
|
||||||
import "utils/bitwise/32/xor.code" as XOR
|
import "../../bitwise/32/xor.code" as XOR
|
||||||
|
|
||||||
def RR6(field[32] b) -> (field[32]):
|
def RR6(field[32] b) -> (field[32]):
|
||||||
return [b[26], b[27], b[28], b[29], b[30], b[31], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24], b[25]]
|
return [b[26], b[27], b[28], b[29], b[30], b[31], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24], b[25]]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// AR7XAR18XAR3
|
// AR7XAR18XAR3
|
||||||
|
|
||||||
import "utils/bitwise/32/xor.code" as XOR
|
import "../../bitwise/32/xor.code" as XOR
|
||||||
|
|
||||||
def RR7(field[32] b) -> (field[32]):
|
def RR7(field[32] b) -> (field[32]):
|
||||||
return [b[25], b[26], b[27], b[28], b[29], b[30], b[31], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24]]
|
return [b[25], b[26], b[27], b[28], b[29], b[30], b[31], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24]]
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
import "./ar6xar11xar25.code" as AR6XAR11XAR25
|
import "./ar6xar11xar25.code" as AR6XAR11XAR25
|
||||||
import "./ar2xar13xar22.code" as AR2XAR13XAR22
|
import "./ar2xar13xar22.code" as AR2XAR13XAR22
|
||||||
import "utils/bitwise/32/andxornotand.code" as ANDXORNOTAND
|
import "../../bitwise/32/andxornotand.code" as ANDXORNOTAND
|
||||||
import "utils/bitwise/32/andxorandxorand.code" as ANDXORANDXORAND
|
import "../../bitwise/32/andxorandxorand.code" as ANDXORANDXORAND
|
||||||
import "./add.code" as ADD2
|
import "./add.code" as ADD2
|
||||||
|
|
||||||
def ADD5(field[32] a, field[32] b, field[32] c, field[32] d, field[32] e) -> (field[32]):
|
def ADD5(field[32] a, field[32] b, field[32] c, field[32] d, field[32] e) -> (field[32]):
|
||||||
|
|
Loading…
Reference in a new issue