Git Product home page Git Product logo

bellman-examples's Introduction

Bellman examples

Examples of circuits for bellman, a Rust zk-SNARKs library.

Bellman provides a Circuit trait which you can use to synthesize the constraints in your program.

multiply.rs contains a circuit for the statement "I know x and y such that x * y = public_input".

cube.rs contains a circuit for the statement "I know x such that x^3 + x + 5 == 35"

Constructing a circuit

To construct a circuit, first flatten your program into its constituent steps.

Allocate the variables, then enforce the constraints.

Enforcing the constraint takes the form of A * B = C. (is a linear combination, vectors of all your variables)

The lc in the cs.enforce function stands for "linear combination", and is an inner product of all the variables with some vector of coefficients.

Generating Parameters

These examples use the function generate_random_parameters to generate a random set of parameters for testing. For real use cases, these parameters would have to be generated securely, through a multi-party computation.

Creating a proof

To create a proof, instantiate a version of the struct that is passed into the circuit, with the inputs to the circuit.

In these examples, the function create_random_proof is used to create a random groth16 proof.

Verifying a proof

To verify a proof, prepare the verifying key by passing in params.vk to prepare_verifying_key. This gives you the prepared viewing key, pvk.

The function verify_proof takes the prepared viewing key pvk, the proof, and the output as an array.

Running

cargo build

cargo test runs test proofs using both example circuits. Tests are located at the bottom of their source files.

cargo run runs the cube.rs example proof in the main file.

bellman-examples's People

Contributors

arcalinea avatar h0ngcha0 avatar porcuquine avatar

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.