MCPcopy Index your code
hub / github.com/arkworks-rs/snark

github.com/arkworks-rs/snark @gm17-v0.1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release gm17-v0.1.1 ↗ · + Follow
2,157 symbols 5,504 edges 408 files 220 documented · 10%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ZEXE (Zero knowledge EXEcution)

<img src="https://github.com/scipr-lab/zexe/workflows/CI/badge.svg?branch=master">
<a href="https://github.com/scipr-lab/zexe/blob/master/AUTHORS"><img src="https://img.shields.io/badge/authors-SCIPR%20Lab-orange.svg"></a>
<a href="https://github.com/scipr-lab/zexe/blob/master/LICENSE-APACHE"><img src="https://img.shields.io/badge/license-APACHE-blue.svg"></a>
<a href="https://github.com/scipr-lab/zexe/blob/master/LICENSE-MIT"><img src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
<a href="https://deps.rs/repo/github/scipr-lab/zexe"><img src="https://deps.rs/repo/github/scipr-lab/zexe/status.svg"></a>

ZEXE (pronounced /zeksē/) is a Rust library for decentralized private computation.

This library was initially developed as part of the paper "ZEXE: Enabling Decentralized Private Computation", and it is released under the MIT License and the Apache v2 License (see License).

WARNING: This is an academic proof-of-concept prototype, and in particular has not received careful code review. This implementation is NOT ready for production use.

Overview

This library implements a ledger-based system that enables users to execute offline computations and subsequently produce publicly-verifiable transactions that attest to the correctness of these offline executions. The transactions contain zero-knowledge succinct arguments (zkSNARKs) attesting to the correctness of the offline computations, and provide strong notions of privacy and succinctness.

  • Privacy - transactions reveal no information about the offline computation.
  • Succinctness - transactions can be validated in time that is independent of the offline computation.
  • Application isolation - malicious applications cannot affect the execution of honest applications.
  • Application interaction - applications can safely communicate with each other.

Informally, the library provides the ability to create transactions that run arbitrary (Turing-complete) scripts on hidden data stored on the ledger. In more detail, the library implements a cryptographic primitive known as decentralized private computation (DPC) schemes, which are described in detail in the ZEXE paper.

Directory structure

This repository contains several Rust crates that implement the different building blocks of ZEXE. The high-level structure of the repository is as follows.

  • algebra-core: Rust crate that provides generic arithmetic for finite fields and elliptic curves
  • algebra: Rust crate that provides concrete instantiations of some finite fields and elliptic curves
  • crypto-primitives: Rust crate that implements some useful cryptographic primitives (and constraints for them)
  • dpc: Rust crate that implements DPC schemes (the main cryptographic primitive in this repository)
  • ff-fft: Rust crate that provides efficient finite field polynomial arithmetic based on finite field FFTs
  • r1cs-core: Rust crate that defines core interfaces for a Rank-1 Constraint System (R1CS)
  • r1cs-std: Rust crate that provides various gadgets used to construct R1CS
  • gm17: Rust crate that implements the zkSNARK of Groth and Maller
  • groth16: Rust crate that implements the zkSNARK of Groth

In addition, there is a bench-utils crate which contains infrastructure for benchmarking. This crate includes macros for timing code segments and is used for profiling the building blocks of ZEXE.

Build guide

The library compiles on the stable toolchain of the Rust compiler. To install the latest version of Rust, first install rustup by following the instructions here, or via your platform's package manager. Once rustup is installed, install the Rust toolchain by invoking:

rustup install stable

After that, use cargo, the standard Rust build tool, to build the library:

git clone https://github.com/scipr-lab/zexe.git
cd zexe/dpc
cargo build --release

This library comes with unit tests for each of the provided crates. Run the tests with:

cargo test

This library comes with benchmarks for the following crates:

These benchmarks require the nightly Rust toolchain; to install this, run rustup install nightly. Then, to run benchmarks, run the following command:

cargo +nightly bench

Compiling with adcxq, adoxq and mulxq instructions can lead to a 30-70% speedup. These are available on most x86_64 platforms (Broadwell onwards for Intel and Ryzen onwards for AMD). Run the following command:

RUSTFLAGS="-C target-feature=+bmi2,+adx" cargo +nightly test/build/bench --features asm

Tip: If optimising for performance, your mileage may vary with passing --emit=asm to RUSTFLAGS.

To bench algebra-benches with greater accuracy, especially for functions with execution times on the order of nanoseconds, use the n_fold feature to run selected functions 1000x per iteration. To run with multiple features, make sure to double quote the features.

cargo +nightly bench --features "n_fold bls12_381"

License

ZEXE is licensed under either of the following licenses, at your discretion.

  • Apache License Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

Unless you explicitly state otherwise, any contribution submitted for inclusion in ZEXE by you shall be dual licensed as above (as defined in the Apache v2 License), without any additional terms or conditions.

Reference paper

ZEXE: Enabling Decentralized Private Computation
Sean Bowe, Alessandro Chiesa, Matthew Green, Ian Miers, Pratyush Mishra, Howard Wu
IEEE S&P 2020 (IACR ePrint Report 2018/962)

Acknowledgements

This work was supported by: a Google Faculty Award; the National Science Foundation; the UC Berkeley Center for Long-Term Cybersecurity; and donations from the Ethereum Foundation, the Interchain Foundation, and Qtum.

Some parts of the finite field arithmetic, elliptic curve arithmetic, FFTs, and multi-threading infrastructure in the algebra crate have been adapted from code in the ff, pairing, and bellman crates, developed by Sean Bowe and others from Zcash.

Extension points exported contracts — how you extend this code

ToConstraintField (Interface)
Types that can be converted to a vector of `F` elements. Useful for specifying how public inputs to a constraint system [21 …
algebra-core/src/to_field_vec.rs
CondSelectGadget (Interface)
Generates constraints for selecting between one of two values. [8 implementers]
r1cs-std/src/select.rs
ConstraintSynthesizer (Interface)
Computations are expressed in terms of rank-1 constraint systems (R1CS). The `generate_constraints` method is called to [26 …
r1cs-core/src/constraint_system.rs
Window (Interface)
(no doc) [10 implementers]
crypto-primitives/src/crh/pedersen/mod.rs
EvaluationDomain (Interface)
Defines a domain over which finite field (I)FFTs can be performed. The size of the supported FFT depends on the size of [3 …
ff-fft/src/domain/mod.rs
DelegableDPCComponents (Interface)
Trait that stores all information about the components of a Delegable DPC scheme. Simplifies the interface of `Delegable [1 …
dpc/src/dpc/delegable_dpc/mod.rs
CurvePair (Interface)
(no doc) [2 implementers]
gm17/examples/recursive-snark/constraints.rs
CurvePair (Interface)
(no doc) [2 implementers]
groth16/examples/recursive-snark/constraints.rs

Core symbols most depended-on inside this repo

clone
called by 538
dpc/src/dpc/plain_dpc/predicate.rs
push
called by 258
dpc/src/ledger/ideal_ledger.rs
into
called by 153
ff-fft/src/polynomial/mod.rs
square
called by 136
algebra-core/src/fields/models/cubic_extension.rs
into_affine
called by 98
algebra-core/src/curves/mod.rs
mul_assign
called by 96
algebra-core/src/fields/models/cubic_extension.rs
add_assign
called by 86
algebra-core/src/fields/models/cubic_extension.rs
enforce_equal
called by 72
r1cs-std/src/eq.rs

Shape

Method 1,142
Function 597
Class 309
Interface 87
Enum 22

Languages

Rust100%

Modules by API surface

r1cs-std/src/bits/boolean.rs50 symbols
algebra-core/src/fields/models/quadratic_extension.rs48 symbols
algebra/src/bls12_381/fields/tests.rs46 symbols
algebra-core/src/fields/models/cubic_extension.rs41 symbols
r1cs-core/src/constraint_system.rs40 symbols
r1cs-std/src/fields/fp/mod.rs38 symbols
algebra-core/src/curves/models/twisted_edwards_extended.rs35 symbols
ff-fft/src/polynomial/dense.rs34 symbols
r1cs-std/src/fields/quadratic_extension.rs32 symbols
algebra-core/src/curves/models/short_weierstrass_projective.rs32 symbols
algebra-core/src/curves/models/short_weierstrass_jacobian.rs32 symbols
r1cs-std/src/groups/curves/twisted_edwards/mod.rs31 symbols

For agents

$ claude mcp add snark \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page