fluidex / plonkit Goto Github PK
View Code? Open in Web Editor NEWA zkSNARK toolkit to work with circom zkp DSL in plonk proof system.
Home Page: https://t.me/fluid_dex
License: MIT License
A zkSNARK toolkit to work with circom zkp DSL in plonk proof system.
Home Page: https://t.me/fluid_dex
License: MIT License
Run plonkit as a server process, so client can send witness to this server, then this server calculates a proof and returns it to the client.
server
. This cmd has similar cmd arguments like prove
, except witness / proof / proofjson / publicjson ( They are all API inputs and outputs). This command behave like following ( you can have a look at prove
command first ) :
witness
set to None.prepare_setup_for_prover
.witness
field of the circuit, then call prove.Remember the setup
object is reused between every API call.
prove function uses every cpu core, so I think requests should be handled one by one. So (n+1)-th request can be processed only after n-th request is finished.
Input {
task_name: String, // log::debug this task_name
witness: bytes
}
Output {
is_valid: boolean,
error_msg: string, // empty when everything is ok
time_cost: f64, # time cost in seconds
proof: Array<bigint as string>,
inputs: Array<bigint as string>
}
is_valid is calculated from is_satisfied_using_one_shot_check. error_msg is any error encountered.
proof and input are from bellman_vk_codegen::serialize_proof
similar to Prove
. But only check is_valid
Output may either be {is_valid: true, error_msg: ''} or {is_valid: false, error_msg: 'XXXX'}
client can use this API to check whether the server is idle or not.
Response {
available: bool,
current_task_name: String
}
Updated poseidon_recursive test to circom2 and got errors:
Step: verify recursive proof
[2022-05-07T03:26:29Z INFO plonkit::recursive] individual_inputs: [
[
Fr(0x115cc0f5e7d690413df64c6b9662e9cf2a3617f2743245519e19607a4417189a),
],
[
Fr(0x20a3af0435914ccd84b806164531b0cd36e37d4efb93efab76913a93e1f30996),
],
[
Fr(0x0427b43899bdfc36d3d4f26c018dd73f5437ea8e5f533fc122441881d5d0b737),
],
]
[2022-05-07T03:26:29Z INFO plonkit] Proof is invalid!
...
Step: verify via smart contract
...
Conversion from
prost_types::Timestamp
toSystemTime
can cause an overflow and panic
Details | |
---|---|
Package | prost-types |
Version | 0.7.0 |
URL | tokio-rs/prost#438 |
Date | 2021-07-08 |
Patched versions | >=0.8.0 |
Affected versions of this crate contained a bug in which untrusted input could cause an overflow and panic when converting a Timestamp
to SystemTime
.
It is recommended to upgrade to prost-types
v0.8 and switch the usage of From<Timestamp> for SystemTime
to TryFrom<Timestamp> for SystemTime
.
See #438 for more information.
See advisory page for additional details.
After cargo install --git https://github.com/Fluidex/plonkit
, plonkit cannot find contrib/template.sol.
Maybe we can embed this sol file into rust source codes using macro?
Is it possible to have the feature?
After calling plonkit prove
I have proof.bin, proof.json, public.json.
Public.json contains the public inputs and the public output of the circuit, correct? So how I can verify the proof is valid for that public data? That is, if i change the public inputs the proof should fail verification.
I'm envisaging something similar to this:
snarkjs groth16 verify verification_key.json public.json proof.json
e.g.
plonkit verify vk.bin public.json proof.json
But current verification only requires proof.bin, e.g. `plonkit verify proof.bin vk.bin'. What is stored in proof.bin? Does it already contain the public inputs and outputs too? Thanks.
I use the following command to generate witness.wtns
(7.67KB)
snarkjs wtns calculate circuit.wasm input.json witness.wtns
circuit_final.zkey
(3.54KB) come from snarkjs
i got an error
$ plonkit prove --srs_monomial_form circuit_final.zkey --circuit circuit.r1cs --witness witness.wtns --proof proof.bin
[2021-05-17T11:55:13Z INFO plonkit] Loading circuit from circuit.r1cs...
[2021-05-17T11:55:13Z INFO plonkit::reader] wtns version 2
[2021-05-17T11:55:13Z INFO plonkit::reader] witness len 243
thread 'main' panicked at 'capacity overflow', library/alloc/src/raw_vec.rs:537:5
stack backtrace:
0: rust_begin_unwind
at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:493:5
1: core::panicking::panic_fmt
at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/panicking.rs:50:5
3: alloc::raw_vec::capacity_overflow
at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/alloc/src/raw_vec.rs:537:5
4: bellman_ce::kate_commitment::Crs<E,T>::read
5: plonkit::reader::load_key_monomial_form
6: plonkit::main
The experiment runs on linux
Why does this problem occur?
how to solve this problem?
I get an error When I install plonkit with the following command
$ cargo install --git https://github.com/Fluidex/plonkit
error[E0433]: failed to resolve: use of undeclared crate or module `tonic`
--> src/lib.rs:20:5
|
20 | tonic::include_proto!("plonkitserver");
| ^^^^^ use of undeclared crate or module `tonic`
How can i solve it?
As mentioned in #21 (comment)
ansi_term is Unmaintained
Details | |
---|---|
Status | unmaintained |
Package | ansi_term |
Version | 0.12.1 |
URL | ogham/rust-ansi-term#72 |
Date | 2021-08-18 |
The maintainer has adviced this crate is deprecated and will not
receive any maintenance.
The crate does not seem to have much dependencies and may or may not be ok to use as-is.
Last release seems to have been three years ago.
The below list has not been vetted in any way and may or may not contain alternatives;
See advisory page for additional details.
plonkit generate-verifier
plonkit generate-verifier --verification_key vk.bin --sol verifier.sol
Both calls return same error:
thread 'main' panicked at 'must read the template: IOError(Os { code: 2, kind: NotFound, message: "No such file or directory" }, "contract")', /home/test/.cargo/git/checkouts/solidity_plonk_verifier-6ecbad31843ffc31/c19a11c/bellman_vk_codegen/src/lib.rs:66:66
note: run with RUST_BACKTRACE=1
environment variable to display a backtrace
vk.bin file exists.
dingir-exchange has bumped rust-toolchain from 1.50.0 to 1.49.0.
(don't forget to update github CI config)
"test" dir under "testdata" looks really messy
and we'd better reorg Cargo.server.toml
, contrib/
, server.proto
, test_poseidon_plonk.sh
as well
Currently we return structured proof.
When transporting, the bigint strings will be marshalled. I think it adds up communication overhead because in this way we are serializing strings, in stead of serializing according to "proof"'s structure.
We can just respond with proof.bin bytes, and let the client unserialize it.
When testing with the following circom code
include "../../src/rollup-main.circom"
component main = RollupMain(8, 24, 8, 8);
"rollup-main.circom" is https://github.com/hermeznetwork/circuits/blob/master/src/rollup-main.circom
An err will occurr
Running `/Users/zhangzhuo/repos/fluidex/plonkit/target/release/plonkit prove --srs_monomial_form '../keys/setup/setup_2^20.key' --circuit ./circuit-8-24-8-8.r1cs --witness witness-8-24-8-8.json --proof proof.bin -j proof.json -i public.json`
Loading circuit from ./circuit-8-24-8-8.r1cs...
thread 'main' panicked at 'internal error: entered unreachable code: R1CS has a gate 1 * 1 = 1', /Users/zhangzhuo/.cargo/git/checkouts/bellman-3ff25c59c43002dc/eb9c1db/src/plonk/better_cs/adaptor.rs:852:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I will fix this problem
Usually, the "load" API should give a signature like fn <R: Read>(reader: R) -> Result<T, E>
.
Current API with signature like fn (filename: &str) -> Result<T, E>
can be preserved.
Also, load by filename should have a more generic signature like fn <P: AsRef<Path>>(path: P) -> Result<T, E>
.
will still re-install if cd
into testdata/poseidon/
consider switching bellman_vk_codegen to
https://github.com/matter-labs/zksync/tree/master/core/bin/key_generator/src/verifier_contract_generator
The code is more elegant.
For now we panic when a vk.bin exists when writing to it, but overwrite when creating proof.json and etc..
We should provide a flag for users, to specify whether overwriting files when creating them.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.