12 个不稳定版本 (4 个破坏性更新)

0.5.0 2021 年 11 月 16 日
0.4.1 2021 年 4 月 11 日
0.3.2 2020 年 9 月 1 日
0.3.1 2020 年 5 月 21 日
0.1.4 2020 年 4 月 7 日

#13 in #circom

MIT 许可证

55KB
1K SLoC

Rust 1K SLoC // 0.0% comments Solidity 115 SLoC // 0.2% comments Shell 9 SLoC // 0.4% comments

zkUtil GitHub Workflow Status Crates.io

用于与 circom 编译器生成的 zkSNARK 电路工作的工具。基于 @kobigurk 的 circom 导入代码。

生成的密钥目前与上游 Websnark 不兼容,需要使用自定义分支。

使用示例

# Getting help
> zkutil --help
zkutil
A tool to work with SNARK circuits generated by circom

USAGE:
    zkutil <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    export-keys          Export proving and verifying keys compatible with snarkjs/websnark
    generate-verifier    Generate verifier smart contract
    help                 Prints this message or the help of the given subcommand(s)
    prove                Generate a SNARK proof
    setup                Generate trusted setup parameters
    verify               Verify a SNARK proof

# Getting help for a subcommand
> zkutil prove --help
zkutil-prove
Generate a SNARK proof

USAGE:
    zkutil prove [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -c, --circuit <circuit>    Circuit R1CS or JSON file [default: circuit.r1cs]
    -p, --params <params>      Snark trusted setup parameters file [default: params.bin]
    -r, --proof <proof>        Output file for proof JSON [default: proof.json]
    -i, --public <public>      Output file for public inputs JSON [default: public.json]
    -w, --witness <witness>    Witness JSON file [default: witness.json]

# Suppose we have circuit file and a sample inputs
> ls
circuit.circom  input.json

# Compile the circuit
> circom -rw circuit.circom
Constraints: 10000
Constraints: 20000
Constraints: 30000
Constraints: 40000
Constraints: 50000

# Generate a local trusted setup
> zkutil setup
Loading circuit...
Generating trusted setup parameters...
Has generated 28296 points
Writing to file...
Done!

# Calculate witness from the input.json
# At the moment we still need to calculate witness using snarkjs
> snarkjs calculatewitness

# Generate a snark proof
> zkutil prove
Loading circuit...
Proving...
Saved proof.json and public.json

# Verify the proof
> zkutil verify
Proof is correct

# Generate a solidity verifier contract
> zkutil generate-verifier
Created verifier.sol

# Export keys to snarkjs/websnark compatible format
> zkutil export-keys
Exporting params.bin...
Created proving_key.json and verification_key.json

# Verify the same proof with snarkjs
> snarkjs verify
OK

# Here's a list of files that we have after this
> ls
circuit.circom  circuit.r1cs  circuit.wasm  input.json  params.bin  proof.json  public.json  Verifier.sol  proving_key.json  verifying_key.json  witness.json

还可以查看 test.sh 中的示例

安装

安装 Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

全局安装 zkutil

cargo install zkutil
# Make sure `~/.cargo/bin` is in $PATH (should be added automatically during Rust installation)

或者您也可以编译并运行它

git clone https://github.com/poma/zkutil
cd zkutil
cargo run --release -- prove --help

依赖项

~11MB
~205K SLoC