• Stars
    star
    543
  • Rank 81,848 (Top 2 %)
  • Language
    Rust
  • License
    Mozilla Public Li...
  • Created about 5 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pure Rust implementation of the PLONK ZKProof System done by the Dusk team

PLONK

Build Status Repository Documentation

This is a pure Rust implementation of the PLONK proving system over BLS12-381

This library contains a modularised implementation of KZG10 as the default polynomial commitment scheme.

DISCLAIMER: This library is currently unstable and still needs to go through an exhaustive security analysis. Use at your own risk.

Usage

use dusk_plonk::prelude::*;
use rand_core::OsRng;

// Implement a circuit that checks:
// 1) a + b = c where C is a PI
// 2) a < 2^6
// 3) b < 2^5
// 4) a * b = d where D is a PI
// 5) JubJub::GENERATOR * e(JubJubScalar) = f where F is a Public Input
#[derive(Debug, Default)]
pub struct TestCircuit {
    a: BlsScalar,
    b: BlsScalar,
    c: BlsScalar,
    d: BlsScalar,
    e: JubJubScalar,
    f: JubJubAffine,
}

impl Circuit for TestCircuit {
    fn circuit<C>(&self, composer: &mut C) -> Result<(), Error>
    where
        C: Composer,
    {
        let a = composer.append_witness(self.a);
        let b = composer.append_witness(self.b);

        // Make first constraint a + b = c
        let constraint =
            Constraint::new().left(1).right(1).public(-self.c).a(a).b(b);

        composer.append_gate(constraint);

        // Check that a and b are in range
        composer.component_range(a, 6);
        composer.component_range(b, 5);

        // Make second constraint a * b = d
        let constraint =
            Constraint::new().mult(1).public(-self.d).a(a).b(b);

        composer.append_gate(constraint);

        let e = composer.append_witness(self.e);
        let scalar_mul_result = composer
            .component_mul_generator(e, dusk_jubjub::GENERATOR_EXTENDED)?;

        // Apply the constraint
        composer.assert_equal_public_point(scalar_mul_result, self.f);

        Ok(())
    }
}

let label = b"transcript-arguments";
let pp = PublicParameters::setup(1 << 12, &mut OsRng)
    .expect("failed to setup");

let (prover, verifier) = Compiler::compile::<TestCircuit>(&pp, label)
    .expect("failed to compile circuit");

// Generate the proof and its public inputs
let (proof, public_inputs) = prover
    .prove(&mut OsRng, &TestCircuit::default())
    .expect("failed to prove");

// Verify the generated proof
verifier
    .verify(&proof, &public_inputs)
    .expect("failed to verify proof");

Features

This crate includes a variety of features which will briefly be explained below:

  • alloc: Enables the usage of an allocator and with it the capability of performing Proof constructions and verifications. Without this feature it IS NOT possible to prove or verify anything. Its absence only makes dusk-plonk export certain fixed-size data structures such as Proof which can be useful in no_std environments where we don't have allocators either.
  • std: Enables std usage as well as rayon parallelization in some proving and verifying ops. It also uses the std versions of the elliptic curve deps, which utilizes the parallel feature from dusk-bls12-381. By default, this is the feature that comes enabled with the crate.
  • debug: Enables the runtime debugger backend. Will output CDF files to the path defined in the CDF_OUTPUT environment variable. If used, the binary must be compiled with debug = true. For more info, check the cargo book. The recommended method is to derive the std output, and the std error, and then place them in text file which can be used to efficiently analyse the gates.
  • canon: Enables canonical serialization for particular data structures, which is very useful in integrating this library within the rest of the Dusk stack - especially for storage purposes.

Documentation

There are two main types of documentation in this repository:

  • Crate documentation. This provides info about all of the functions that the library provides, as well as the documentation regarding the data structures that it exports. To check this, please feel free to go to the documentation page or run make doc or make doc-internal.

  • Notes. This is a specific subset of documentation which explains the key mathematical concepts of PLONK and how they work with mathematical demonstrations. To check it, run make doc and open the resulting docs, which will be located under /target with your browser.

Performance

Benchmarks taken on Apple M1, for a circuit-size of 2^16 constraints:

  • Proving time: 7.871s
  • Verification time: 7.643ms (This time will not vary depending on the circuit-size.)

For more results, please run cargo bench to get a full report of benchmarks in respect of constraint numbers.

Acknowledgements

  • Reference implementation AztecProtocol/Barretenberg
  • FFT Module and KZG10 Module were taken and modified from zexe/zcash and scipr-lab, respectively.

Licensing

This code is licensed under Mozilla Public License Version 2.0 (MPL-2.0). Please see LICENSE for further info.

About

Implementation designed by the dusk team.

Contributing

  • If you want to contribute to this repository/project please, check CONTRIBUTING.md
  • If you want to report a bug or request a new feature addition, please open an issue on this repository.

More Repositories

1

Poseidon252

Reference implementation for the Poseidon Snark-friendly Hash algorithm.
Rust
209
star
2

rusk

The reference Dusk platform implementation and tools
Rust
157
star
3

dusk-blockchain

Reference implementation of the DUSK Network node, written in Golang
Go
102
star
4

rusk-vm

The Dusk Rust WASM VM implementation
Rust
54
star
5

dusk-zerocaf

Zerocaf: A library built for EC operations in Zero Knowledge.
Rust
53
star
6

kelvin

Merkle tree toolkit
Rust
46
star
7

wallet-cli

Dusk wallet CLI and library
Rust
24
star
8

piecrust

General purpose virtual machine for running WASM smart contracts
Rust
22
star
9

Hades252

Implementation of the Hades permutation algorithm used in Poseidon Hashes with ZKProof capabilities.
Rust
22
star
10

kadcast

Official rust implementation of the Kadcast P2P protocol for ultra-efficient message dissemination within Dusk Network
Rust
22
star
11

dusk-blindbid

Implementation of the blindbid logic within Zero Knowledge Proofs
Rust
21
star
12

node-installer

Easy to use tool to install a Dusk node with extra utilities
Shell
21
star
13

dusk-poseidon-merkle

Rust
20
star
14

phoenix

Privacy-preserving transaction model by Dusk
Rust
18
star
15

microkelvin

Rust
16
star
16

plonkup

Proof system with plonkup back-end proving arguments
Rust
14
star
17

plonk_gadgets

Container of general purpose gadgets used across Dusk Network's circuit implementations.
Rust
13
star
18

schnorr

Schnorr Signature algorithm usiing BLS12-381 Curve
Rust
13
star
19

dusk-crypto

Cryptographic primitives created for the Dusk Network ecosystem but widely applicable everywhere else
Go
12
star
20

canonical

A no_std, host-allocating serialization library
Rust
10
star
21

phoenix-archived

Rust
9
star
22

whitepaper

The Dusk Network enables fast, anonymous and secure bi-directional transmission of data and streaming among peers, paid for by a decentralized digital currency named DUSK
TeX
8
star
23

citadel

Implementation of Citadel, a self-sovereign identity system integrated in Dusk.
Rust
8
star
24

dusk-kelvin-map

Rust
8
star
25

dusk-hamt

HAMT datastructure
Rust
7
star
26

exu

A library to run WebAssembly code as parallel, isolated and abortable functions in JS engine
JavaScript
7
star
27

dusk-pki

Dusk Public Key Infrastructure
Rust
7
star
28

nstack

Stack data structure
Rust
6
star
29

dusk-protobuf

Makefile
6
star
30

wallet-core

The library responsible for the core functionality of a wallet
Rust
6
star
31

jubjub-schnorr

Rust implementation of the Schnorr signature scheme for the JubJub elliptic curve group, using the Poseidon hash function.
Rust
6
star
32

dusk-bytes

Rust
5
star
33

bulletproofs_gadgets

A container to test bulletproofs gadgets implementations
Rust
5
star
34

dusk-go-poseidon

Go
5
star
35

bls12_381-sign

Implementation of BLS signatures on the BLS12-381 curve in Rust.
Rust
5
star
36

consensus

Pure Rust implementation of the Proof-of-Stake-based consensus mechanism done by the Dusk-Network team.
5
star
37

dusk-wallet-cli

Command line application for managing a DUSK wallet and a full/light node, by communicating over JSON-RPC.
Go
4
star
38

merkle-benchmarks

Benchmarking Merkle tree structures
Rust
4
star
39

ElGamal

Implementation of the ElGamal encryption scheme
Rust
4
star
40

trusted-setup

Powers of tau MPC ceremony coordinated by Dusk.
Rust
4
star
41

dusk-blindbidproof

Implementation of Dusk Network privacy-oriented PoS protocol, aka Proof of Blind Bid
Rust
4
star
42

bls12_381-bls

Implementation of BLS signatures using the BLS12-381 curve
Rust
4
star
43

merkle

A sparsely populated Merkle tree, parametrized over its height and arity.
Rust
3
star
44

cake-rusk

Writing a Smart Contract is a piece of `cake!`
Rust
3
star
45

eslint-config

⚙️ Dusk ESLint configuration
JavaScript
3
star
46

dusk-example-contract

Rust
3
star
47

EdDSA

Implementation of the EdDSA for JubJub curve group using Poseidon as the hash function
Rust
3
star
48

prestaking-contract

This repository contains the Solidity code, test cases and documentation, regarding the DUSK pre-staking Ethereum smart contract.
JavaScript
3
star
49

dusk-abi

Dusk ABI for Rusk VM
Rust
3
star
50

avltree

An AVL tree data structure, implemented on the Kelvin library in Rust.
Rust
3
star
51

cargo-bake

A cargo extension which bake your Rusk Smart Contracts made with love & cake!
Rust
3
star
52

rusk-mirror

[MIRROR] Dusk's Smart Contract Platform
Rust
3
star
53

rusk-contract

Set of macros to help building contracts for Rusk VM
Rust
3
star
54

cargo-dusk-analyzer

Cargo subcommand to analyzing and doing some reaility check on our rust repos
Rust
3
star
55

rusk-schema

Schema definition for all of the Rusk GRPC services
2
star
56

go-analyzer

A modular, extensible linting tool, which is used to enforce custom checks on Go repos in the Dusk organization.
Go
2
star
57

poseidon252-hash

Rust
2
star
58

phoenix-abi

FFI for Phoenix host functions, used by rusk-vm.
Rust
2
star
59

transparent-token

A transparent token on Dusk
Rust
2
star
60

audits

This GitHub repository hosts comprehensive audit reports for Dusk, ensuring transparency and security for its users and stakeholders
2
star
61

docs-public

Astro
1
star
62

vm-proto

Rust
1
star
63

dusk-ipc

Inter-Process Communication framework for composing applications as discrete modules connected by an event bus
Makefile
1
star
64

plang

A compiler for a language representing plonk circuits
Rust
1
star
65

dusk-deploy-cli

Tool for smart contracts' deployment to Dusk blockchain.
Rust
1
star
66

dusk-varint

no_std varint encoding
Rust
1
star
67

docker-elk

Shell
1
star
68

.github

Community Health File repo
1
star
69

dusk-tlv

Rust
1
star
70

bls12_381-sign-go

Wrapper library for CGo calls to the dusk-bls12_381-sign crate.
1
star
71

prestaking-provisioner

Ethereum smart contract, test cases and documentation for the Provisioner Prestaking campaign.
Solidity
1
star
72

dusk-wallet-dat

The wallet.dat file format parser and generator
Rust
1
star
73

safe

Sponge API for Field Elements
Rust
1
star