Giter Site home page Giter Site logo

plonkit's People

Contributors

29988122 avatar dependabot[bot] avatar haoyuathz avatar lightsing avatar lispc avatar noel2004 avatar poma avatar weijiekoh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plonkit's Issues

Feature: add prove server mode

Feature

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.

How

  1. add a new feature flag, 'server'. All the following stuff lives under this flag. (Default: false)
  2. add a grpc definition with the following two APIs.
  3. Add a new command, 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 ) :
    1. Preload a local r1cs circuit ( filename from cmd flag) , with witness set to None.
    2. Then prepare_setup_for_prover.
    3. Then start the grpc server.
    4. For every API call, set the 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.

API

Prove

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

ValidateWitness

similar to Prove. But only check is_valid

Output may either be {is_valid: true, error_msg: ''} or {is_valid: false, error_msg: 'XXXX'}

Status

client can use this API to check whether the server is idle or not.

Response {
available: bool,
current_task_name: String
}

Proof Aggregation does not work for circom2

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

...

  1. Plonk
    Should return true when proof is correct:
    Error: missing revert data in call exception; Transaction reverted without a reason string [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (error={"stackTrace":[{"type":0,"sourceReference":{"function":"verifyAggregatedProof","contract":"KeysWithPlonkVerifier","sourceName":"contracts/verifier.sol","sourceContent":"// SPDX-License-Identifier: MIT OR Apache-2.0\n// Based on: https://github.com/matter-labs/zksync/blob/master/core/bin/key_generator/src/verifier_contract_generator/VerifierTemplate.sol, rev#4012188\n\npragma solidity >=0.5.0 <0.9.0;\n\npragma experimental ABIEncoderV2;\n\nlibrary PairingsBn254 {\n ... ...

RUSTSEC-2021-0073: Conversion from `prost_types::Timestamp` to `SystemTime` can cause an overflow and panic

Conversion from prost_types::Timestamp to SystemTime 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&lt;Timestamp&gt; for SystemTime to TryFrom&lt;Timestamp&gt; for SystemTime.

See #438 for more information.

See advisory page for additional details.

Solidity template not found

#7

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?

How to use plonkit to verify proof for given public inputs?

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.

thread 'main' panicked at 'capacity overflow' (plonkit prove)

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?

use of undeclared crate or module `tonic`

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?

RUSTSEC-2021-0139: ansi_term is Unmaintained

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.

Possible Alternative(s)

The below list has not been vetted in any way and may or may not contain alternatives;

See advisory page for additional details.

Error calling generate-verifier

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.

bump rust version

dingir-exchange has bumped rust-toolchain from 1.50.0 to 1.49.0.

(don't forget to update github CI config)

reorganize project structure

"test" dir under "testdata" looks really messy

and we'd better reorg Cargo.server.toml, contrib/, server.proto, test_poseidon_plonk.sh as well

server mode: proof serialization

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.

Error: entered unreachable code: R1CS has a gate 1 * 1 = 1

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

improve the api design in `reader.rs`

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>.

add ut

  1. a UT for checking generating verification key. Generate vk in testcase, and then check the new vk is identical to the vk in repo.
    $PLONKIT_BIN export-verification-key -m $SETUP_MK -c $CIRCUIT_DIR/circuit.r1cs.json -v $CIRCUIT_DIR/vk.bin
  2. a UT for checking proving. Generate proof in testcase, and then check the new proof is identical to the proof.bin in repo.
    $PLONKIT_BIN prove -m $SETUP_MK -c $CIRCUIT_DIR/circuit.r1cs.json -w $CIRCUIT_DIR/witness.json -p $CIRCUIT_DIR/proof.bin -j $CIRCUIT_DIR/proof.json -i $CIRCUIT_DIR/public.json
  3. a UT for verification. Loading proof.bin and vk.bin from repo, and assert result is true.
    $PLONKIT_BIN verify -p $CIRCUIT_DIR/proof.bin -v $CIRCUIT_DIR/vk.bin

provide a CLI flag for overwriting files

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.