• Stars
    star
    646
  • Rank 69,672 (Top 2 %)
  • Language
    Rust
  • License
    Other
  • Created over 5 years ago
  • Updated 7 months ago

Reviews

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

Repository Details

OpenZKP - pure Rust implementations of Zero-Knowledge Proof systems.

OpenZKP

Crates.io CircleCI Codecov

OpenZKP - pure Rust implementations of Zero-Knowledge Proof systems.

Overview

Project current implements

  • 🐺 the Stark protocol (see its readme for details)

and has

  • 🌞 a simple interface (see the example below),
  • πŸ—œοΈ succinct proofs,
  • 🏎️ decent performance, and
  • 🌐 webassembly support.

That being said, it also has a number of limitations, it has

  • no high-level language,
  • no comprehensive security audit,
  • no perfect zero-knowledge,
  • hard-coded field and hash function,

and some others, see features and limitations below for details.

Packages

Package Version Description
utils/
criterion-utils Crates.io Criterion helpers to benchmark over size and number of processors.
error-utils Crates.io Assertion like macros for returning Result::Err.
logging-allocator Crates.io Wrapper around the system allocator that logs large allocations.
mmap-vec Crates.io Substitute for Vec that uses file-backed storage.
macros-lib Crates.io Library of procedural macros implemented using proc_macro2
macros-impl Crates.io Implementation crate for proc_macro_hack
macros-decl Crates.io Procedural macros.
algebra/
u256 Crates.io Implementation of 256-bit unsigned integers.
primefield Crates.io A 251-bit prime field suitable for FFTs.
elliptic-curve Crates.io An elliptic curve over the primefield.
crypto/
elliptic-curve-crypto Crates.io Pedersen commitments and digital signatures.
hash Crates.io Hash primitive used in zkp-stark.
merkle-tree Crates.io Merkle tree based vector commitment.
stark Crates.io STARK protocol implementation

Example

Example from the stark package:

use zkp_stark::{*, primefield::*};

struct FibonacciClaim {
    index: usize,
    value: FieldElement,
}

impl Verifiable for FibonacciClaim {
    fn constraints(&self) -> Constraints {
        use RationalExpression::*;

        // Seed
        let mut seed = self.index.to_be_bytes().to_vec();
        seed.extend_from_slice(&self.value.as_montgomery().to_bytes_be());

        // Constraint repetitions
        let trace_length = self.index.next_power_of_two();
        let g = Constant(FieldElement::root(trace_length).unwrap());
        let on_row = |index| (X - g.pow(index)).inv();
        let every_row = || (X - g.pow(trace_length - 1)) / (X.pow(trace_length) - 1.into());

        let mut c = Constraints::from_expressions((trace_length, 2), seed, vec![
            (Trace(0, 1) - Trace(1, 0)) * every_row(),
            (Trace(1, 1) - Trace(0, 0) - Trace(1, 0)) * every_row(),
            (Trace(0, 0) - 1.into()) * on_row(0),
            (Trace(0, 0) - (&self.value).into()) * on_row(self.index),
        ])
        .unwrap()
    }
}

impl Provable<&FieldElement> for FibonacciClaim {
    fn trace(&self, witness: &FieldElement) -> TraceTable {
        let trace_length = self.index.next_power_of_two();
        let mut trace = TraceTable::new(trace_length, 2);
        trace[(0, 0)] = 1.into();
        trace[(0, 1)] = witness.clone();
        for i in 0..(trace_length - 1) {
            trace[(i + 1, 0)] = trace[(i, 1)].clone();
            trace[(i + 1, 1)] = &trace[(i, 0)] + &trace[(i, 1)];
        }
        trace
    }
}

pub fn main() {
    let claim = FibonacciClaim {
        index: 5000,
        value: FieldElement::from_hex_str("069673d708ad3174714a2c27ffdb56f9b3bfb38c1ea062e070c3ace63e9e26eb"),
    };
    let secret = FieldElement::from(42);
    let proof = claim.prove(&secret).unwrap();
    claim.verify(&proof).unwrap();
}

Features and Limitations

Features

A simple interface. The public interface is simple and is considered semver-stable. Future versions are expected to add functionality without breaking this interface.

Succinct proofs. For a given security parameter, the proof size is close to minimal. Significant improvements here would require innovations in the way constraint systems are designed or in the underlying cryptography.

Decent performance. All steps of the proof are using asymptotically optimal algorithms and all of the major steps are multi-threaded. There are no hard memory requirements. We can expect a good amount of performance improvements by fine-tuning, but we don't expect orders of magnitude improvements.

Webassembly support. The verifier can be used in a WebAssembly environment without the Rust std lib. The prover will work too, but has not been a priority.

Limitations

No high-level language. Constraints are specified using their algebraic expressions. This requires complicated and careful design from the library user and is easy to do wrong, leading to insecure systems. A high level language would help make development simpler and safer and facilitate re-use of components.

No comprehensive security audit. While development is done with the best security practices in mind, it is still very early stage and has not had the amount of expert peer review required for a production grade system.

No perfect zero-knowledge. The current implementation provides succinct proofs but not perfect zero knowledge. While non-trivial, it is theoretically possible to learn something about the secret. Achieving perfect zero-knowledge is possible and can be implemented.

No side-channel resistance. The implementation favours performance over side-channel resistance. While this is common in zero-knowledge proof system, you should be aware that his might leak intermediate computations. Side-channel resistance can be implemented.

Hard-coded field and hash. The current implementation uses a particular prime field and a particular hash function. These are optimized for verification in the Ethereum Virtual Machine. This can be generalized to other primitives optimized for other use cases.

Contributing

See our Contributing guideline and Code of conduct.

See CircleCI documentation on how to run tests locally.

References

Resource overviews on Zero Knowledge Proof protoocols:

Resources on numeric and cryptographic algorithm implementation:

  • Alfred J. Menezes, Paul C. van Oorschot and Scott A. Vanstone (2001). "Handbook of Applied Cryptography". Available online
  • Donald Knuth (1968-). "The art of computer programming". In particular part II: Seminumerical algorithms.

More Repositories

1

0x-monorepo

0x protocol monorepo - includes our smart contracts and many developer tools
TypeScript
1,412
star
2

0x-launch-kit

Start an exchange in under a minute
JavaScript
380
star
3

protocol

TypeScript
362
star
4

0x-api

An HTTP Interface to 0x liquidity and tooling
TypeScript
362
star
5

0x-mesh

A peer-to-peer network for sharing 0x orders
Go
258
star
6

0x-starter-project

A project showcasing how to get started with 0x.js
TypeScript
200
star
7

0x-launch-kit-backend

Launch a 0x relayer in under a minute [DEPRECATED]
TypeScript
173
star
8

standard-relayer-api

Standard specifications for 0x relayer public APIs
164
star
9

0x-protocol-specification

Specification for 0x protocol
148
star
10

0x-launch-kit-frontend

TypeScript
112
star
11

tools

TypeScript
96
star
12

ZEIPs

0x Improvement Proposals
91
star
13

swap-demo-tutorial

JavaScript
67
star
14

website

0x.org website
TypeScript
54
star
15

0x-nextjs-demo-app

Example ERC20 swapping app made with 0x Swap API, Next.js, and ConnectKit
TypeScript
52
star
16

rpc-gateway

A failover proxy for node providers
Go
47
star
17

0x-relayer-registry

A collection of relayers using 0x
TypeScript
43
star
18

whitepaper

Technical document that specifies 0x protocol.
TeX
33
star
19

0x-parser

🧾 A library that parses 0x transactions from EVM blockchains into a format that is user-friendly and easy to understand.
TypeScript
30
star
20

web3-typescript-typings

[DEPRECATED] A preliminary Web3 v0.x typescript type definition
30
star
21

dev-tools-truffle-example

An example Truffle project showing how to use the 0x Dev Tools with the Truffle framework
JavaScript
28
star
22

fast-abi

ABI encoding, fast
Rust
27
star
23

0x-event-pipeline

A node.js app for pulling 0x event info to inform things like staking.
TypeScript
26
star
24

0x-examples

A collection of 0x API code examples
TypeScript
19
star
25

VDF

A Solidity implementation of a VDF verifier contract
Solidity
16
star
26

0x-sdk

TypeScript SDK for building exchange functionality on Ethereum and EVM-compatible chains πŸ› .
TypeScript
15
star
27

0x-codesandbox

0x Codesandbox
TypeScript
14
star
28

0x-debug

TypeScript
14
star
29

quote-server

An RFQ quote server that can be used to provide quotes via 0x API
TypeScript
14
star
30

0x-settler

0x settlement contracts using Permit2
Solidity
11
star
31

0x-instant

JavaScript
10
star
32

0x-staking-pool-registry

A collection of metadata about staking pools on 0x - https://0x.org/
TypeScript
10
star
33

connect-starter-project

A tutorial for interacting with a relayer that conforms to the standard relayer API
TypeScript
10
star
34

0x-coordinator-server

A reference implementation of a 0x coordinator server (soft-cancel variant)
TypeScript
9
star
35

sutro

Eye of Sutro: Ethereum State Watcher
Rust
7
star
36

pm

6
star
37

branding

Logos and other media
5
star
38

p2p_incentives

Python
5
star
39

node-anvil

Nodejs bindings to Foundry Anvil
Rust
5
star
40

zrx-buyer

A demonstration of using asset-buyer to buy ZRX
TypeScript
4
star
41

0x-subgraph

TypeScript
4
star
42

mesh-viz

https://mesh-viz.0x.org/
TypeScript
4
star
43

matcha-flagged-tokens

4
star
44

0x-exchange-proxy-subgraph

TypeScript
4
star
45

0x-api-forked-testnet-example

A basic example for how you can test 0x API using a private for of Ethereum mainnet
TypeScript
4
star
46

proxy

Simple Go Proxy
Go
3
star
47

mesh-mock-graphql-api

Demo of the new Mesh GraphQL API using mock data
TypeScript
3
star
48

setup-helm

Github Action for Helm installation
TypeScript
3
star
49

mesh-workshop-demo

TypeScript
3
star
50

exchange-v3

TypeScript
2
star
51

0x-mesh-demo-client-javascript

[DEPRECATED] A demo 0x Mesh WebSocket client written in Javascript
TypeScript
2
star
52

ts-doc-gen

A CLI for generating a single MD reference doc file for a TS project
TypeScript
2
star
53

setup-govulncheck

Setup govulncheck: https://go.dev/security/vuln/
TypeScript
2
star
54

setup-foundry

Install foundry-rs/foundry in your Github Action workflow
TypeScript
2
star
55

mesh-rs

Rust implementation of the 0x Mesh protocol
Rust
1
star
56

matcha-unsupported-tokens

1
star
57

permit2-matcha

A headless prototype of how the Matcha API works with permit2 smart contracts.
TypeScript
1
star