Code Monkey home page Code Monkey logo

zero-knowledge-proofs's Introduction

zero-knowledge-proofs

Zero Knowledge Proofs and how they can be implemented in Quorum

This is a SNARK implementation using libsnark for the following:

ZkPoK{ (R1, R2, R3): Hi = sha256(Ri) and R3 = R1 + R2 }

Read: given H1, H2, H3, prove you know R1, R2, R3 such that R1 is the preimage of H1, R2 is the preimage of H2, R3 is the preimage of H3, and R3 is R1 + R2.

This is an implementation and benchmark of the "Receive" zk-SNARK in the Confidential Transaction scheme from this article: https://media.consensys.net/introduction-to-zksnarks-with-examples-3283b554fc3b.

Code based on https://github.com/ebfull/lightning_circuit.

Some more background here: https://www.youtube.com/watch?v=0KhFhvdEpoA

howto

Required packages

  • On Ubuntu 16.04 LTS:

      `$ sudo apt-get install build-essential cmake git libgmp3-dev libprocps4-dev python-markdown libboost-all-dev libssl-dev`
    
  • On Ubuntu 14.04 LTS:

      `$ sudo apt-get install build-essential cmake git libgmp3-dev libprocps3-dev python-markdown libboost-all-dev libssl-dev`
    

Installation

./get-libsnark && make

npm install

Running

node index.js startBalance=10000

First select

  1. Single payment in and single payment out
  2. Multiple payments in and multiple payments out

Follow the prompts.

  1. Generate a key pair
  2. Generate a proof (single or multiple)
  3. Verify proof
  4. Quit

Generate a new key pair

This creates a new proving key and verification key from the circuit. They are saved to the files:

  • provingKey-single or provingKey-multi
  • verificationKey-single or verificationKey-multi

Generate a payment proof

This generates a proof using the proving key as well as the following values:

  • start balance
  • incoming payment/s
  • outgoing payment/s
  • end balance (start balance + incoming - outgoing)

The proof is:

  • start balance + incoming payments = end balance + outgoing payments

Verify payment proof

Verifies the above proofs

License

Copyright (C) 2017 The Quorum Zero Knowledge Proof Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

zero-knowledge-proofs's People

Contributors

coder5876 avatar coeniebeyers avatar petermunnings 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zero-knowledge-proofs's Issues

Get the library working from node.js

In order to use this from a dApp, we'll need access from node.js This can either be as a c++ addon in node.js or running it from a c++ web service.

Either way, the serialisation will be an issue.

Run-time errors on OSX

I'm trying to compile and run this on OSX.

I can compile fine. However, I'm getting the following errors when I go to run ("Single payment in and single payment out"):

terminating with uncaught exception of type std::invalid_argument: libff::get_root_of_unity: expected n == (1u << logn)

node index.js startBalance=10000

Please select an option:
1) Single payment in and single payment out
2) Multiple payments in and multiple payments out
3) Simulation of an RTGS payment node
0) Quit
prompt: option:  1

The provingKey and verificationKey need to be generated

libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: libff::get_root_of_unity: expected n == (1u << logn)

Loading proving key from file.  This will take a few seconds
..payment_in_out_generate_proof(91763,0x7fff9d3e33c0) malloc: *** mach_vm_map(size=1125876303986688) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

libc++abi.dylib: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc

.........................................................................................

Questions about compiling test.cpp and output of index.js

I'm running these code on Linux ubuntu 16.04.

First, my index.js works well but I didn't find the output of using libsnark(like the detailed time and the mark of entering a new process.)I'd like to know how to get the corresponding output.

Second, I find test.cpp in the project,it wasn't compiled,so I add it in makefile and get errors. I find that some functions in test.cpp didn't even exist. So I want to know, how can I get the test.cpp works well ? (Maybe the test.hpp is left for me to write the nonexistent corresponding funtion?)

Makefile:15: recipe for target 'all' failed

I just run ./get-libsnark && make, but make prints error...
I installed raspberry-pi(ubuntu mate).

...(logs of ./get-libsnark)...
g++ -o payment_in_out_generate_keypair.o src/payment_in_out_generate_keypair.cpp -c -g -Wall -Wextra -Wno-unused-parameter -std=c++11 -fPIC -Wno-unused-variable -Ilibsnark/build/install/usr/local/include -Ilibsnark/libfqfft/build/install/include -DUSE_ASM -DCURVE_ALT_BN128 -DWITH_PROCPS=OFF -DWITH_SUPERCOP=OFF  -march=native -mtune=native -O2
In file included from libsnark/build/install/usr/local/include/libsnark/reductions/r1cs_to_qap/r1cs_to_qap.hpp:35:0,
                 from libsnark/build/install/usr/local/include/libsnark/zk_proof_systems/ppzksnark/r1cs_ppzksnark/r1cs_ppzksnark.tcc:32,
                 from libsnark/build/install/usr/local/include/libsnark/zk_proof_systems/ppzksnark/r1cs_ppzksnark/r1cs_ppzksnark.hpp:469,
                 from src/snark.hpp:2,
                 from src/payment_in_out_generate_keypair.cpp:6:
libsnark/build/install/usr/local/include/libsnark/relations/arithmetic_programs/qap/qap.hpp:28:60: fatal error: libfqfft/evaluation_domain/evaluation_domain.hpp: No such file or directory
compilation terminated.
Makefile:15: recipe for target 'all' failed
make: *** [all] Error 1

How could I solve this?

Update the libsnarks build process

Libsnarks library has recently gone through some big changes around how it is cloned and built. We need to update the scripts in this project to match the new libsnarks process

Origination of Salt values needs to be resolved

Currently, the salt values are just hard coded values in the javascript code.

This needs to be fixed. It is however a bigger discussion.

  • where do the salt values come from
  • where are they stored (if they need to be stored)
  • how is the salt value for the payment communicated to the counterparty to the payment

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.