Skip to content

lambdaclass/lambdaworks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

705 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

lambdaworks

From the heights of these towers of fields, forty centuries of mathematics look down on us.

This library provides an efficient implementation of cryptographic primitives used to build proving systems. Along with it, many backends for proving systems are shipped, and compatibility with different frontends is supported.

Telegram Chat codecov

Examples - mini apps

Below is a list of examples to understand lambdaworks and learn what you can build with the tools provided. Most are educational examples and must not be used in production.

Cryptographic Signatures

Proof Systems & SNARKs

Cryptographic Primitives

Why we built lambdaworks

Zero-Knowledge and Validity Proofs have attracted significant attention over the last few years. We strongly believe in this potential, which is why we decided to start working in this challenging ecosystem where math, cryptography, and distributed systems meet. The main barrier at the beginning was not cryptography or math, but the lack of good, performant, developer-friendly libraries. There are some exceptions, though, like gnark or Halo 2. Some have nice APIs and are easy to work with, but they are not written in Rust; others are written in Rust but have poor programming and engineering practices. Most of them don't support CUDA, Metal, WebGPU, or distributed FFT calculations using schedulers like Dask.

So, we decided to build our library with performance in mind, providing clear documentation and a developer-focused approach. Our core team is a group of passionate people from diverse backgrounds and strengths; we believe the whole is greater than the sum of its parts. We don't want to be a compilation of every research result in the ZK space. We want this to be a library that can be used in production, not just in academic research. We want to offer developers the main building blocks and proof systems so that they can build their applications on top of this library.

Quick Start

Add lambdaworks to your project:

[dependencies]
lambdaworks-math = "0.13.0"
lambdaworks-crypto = "0.13.0"

Field arithmetic

use lambdaworks_math::field::{
    element::FieldElement,
    fields::fft_friendly::stark_252_prime_field::Stark252PrimeField,
};

// Create field elements
type FE = FieldElement<Stark252PrimeField>;

let a = FE::from(5u64);
let b = FE::from(3u64);

// Arithmetic operations
let sum = &a + &b;           // 8
let product = &a * &b;       // 15
let square = a.square();     // 25
let inverse = b.inv().unwrap();
assert_eq!(&b * &inverse, FE::one());

Elliptic curve operations

use lambdaworks_math::elliptic_curve::{
    short_weierstrass::curves::bls12_381::curve::BLS12381Curve,
    traits::IsEllipticCurve,
};

// Get the generator point
let g = BLS12381Curve::generator();

// Scalar multiplication
let g2 = g.operate_with_self(2u64);
let g3 = g.operate_with(&g2);

// Convert to affine coordinates
let g3_affine = g3.to_affine();

Polynomial operations

use lambdaworks_math::{
    field::element::FieldElement,
    field::fields::u64_prime_field::U64PrimeField,
    polynomial::Polynomial,
};

type F = U64PrimeField<65537>;
type FE = FieldElement<F>;

// Create polynomial: p(x) = 1 + 2x + 3xΒ²
let p = Polynomial::new(&[FE::from(1), FE::from(2), FE::from(3)]);

// Evaluate at a point
let result = p.evaluate(&FE::from(2)); // 1 + 4 + 12 = 17

// Interpolate from points
let poly = Polynomial::interpolate(
    &[FE::from(0), FE::from(1), FE::from(2)],
    &[FE::from(1), FE::from(2), FE::from(5)], // values of some quadratic
).unwrap();

For more examples, see the examples directory and the math crate documentation.

Main crates

Crypto

Performance Features

  • x86-64 Assembly Optimizations: Hand-tuned assembly for field arithmetic on supported platforms
  • GPU Acceleration: CUDA backend for Merkle tree construction and FFT operations
  • Metal Backend: Apple Silicon GPU acceleration for FFT and field operations
  • Sparse Polynomials: Memory-efficient representation for polynomials with few non-zero coefficients
  • Optimized FFT: Circle FFT and NTT implementations with field-specific optimizations

Most of the math and crypto crates support no-std without allocation with no-default-features. A few functions and modules require the alloc feature.

Both Math and Crypto support wasm with the target wasm32-unknown-unknown. To see an example of how to use this to deploy a verifier in a browser, check the Cairo Prover wasm-pack verifier.

Exercises and Challenges

Citing lambdaworks

If you use lambdaworks libraries in your research projects, please cite them using the following template:

@software{lambdaworks,
  author={lambdaworks contributors},
  title={lambdaworks},
  url={https://github.com/lambdaclass/lambdaworks},
  year={2023}
}

List of features

Disclaimer: This list contains cryptographic primitives and mathematical structures that we want to support in lambdaworks. It can be expanded later to include new primitives. If you find a mistake or notice an update in another library, please let us know.

List of symbols:

  • βœ”οΈ means the feature is currently supported.
  • πŸ—οΈ means that the feature is partially implemented or is under active construction.
  • ❌ means that the feature is not currently supported.
Finite Fields Lambdaworks Arkworks Plonky3 gnark Constantine Halo2
StarkField 252 βœ”οΈ βœ”οΈ ❌ βœ”οΈ ❌ ❌
Goldilocks βœ”οΈ βœ”οΈ βœ”οΈ βœ”οΈ ❌ ❌
Mersenne 31 βœ”οΈ ❌ βœ”οΈ ❌ ❌ ❌
Baby Bear βœ”οΈ ❌ βœ”οΈ ❌ ❌ ❌
KoalaBear βœ”οΈ ❌ βœ”οΈ ❌ ❌ ❌
MiniGoldilocks βœ”οΈ ❌ βœ”οΈ βœ”οΈ ❌ ❌
Binary fields βœ”οΈ ❌ ❌ ❌ ❌ ❌
ZK friendly Hash function Lambdaworks Arkworks Plonky3 gnark Constantine Halo2
Poseidon βœ”οΈ βœ”οΈ βœ”οΈ ❌ ❌ βœ”οΈ
Pedersen πŸ—οΈ βœ”οΈ ❌ ❌ ❌ βœ”οΈ
Rescue Prime XLIX βœ”οΈ ❌ βœ”οΈ ❌ ❌ ❌
Elliptic Curves Lambdaworks Arkworks Plonky3 gnark Constantine Halo2
BLS12-381 βœ”οΈ βœ”οΈ ❌ βœ”οΈ βœ”οΈ βœ”οΈ
BLS12-377 βœ”οΈ βœ”οΈ ❌ βœ”οΈ βœ”οΈ ❌
BN-254 βœ”οΈ βœ”οΈ ❌ βœ”οΈ βœ”οΈ βœ”οΈ
Pallas βœ”οΈ βœ”οΈ ❌ ❌ βœ”οΈ βœ”οΈ
Vesta βœ”οΈ βœ”οΈ ❌ ❌ βœ”οΈ βœ”οΈ
Bandersnatch βœ”οΈ βœ”οΈ ❌ βœ”οΈ βœ”οΈ ❌
secp256k1 βœ”οΈ βœ”οΈ ❌ βœ”οΈ βœ”οΈ βœ”οΈ
secq256k1 βœ”οΈ βœ”οΈ ❌ ❌ ❌ βœ”οΈ
secq256r1 βœ”οΈ βœ”οΈ ❌ ❌ ❌ βœ”οΈ
STARKs Lambdaworks Arkworks Plonky3 gnark Constantine Halo2
STARK Prover βœ”οΈ ❌ βœ”οΈ ❌ ❌ ❌
Circle STARKs πŸ—οΈ ❌ βœ”οΈ ❌ ❌ ❌
SNARKs Lambdaworks Arkworks Plonky3 gnark Constantine Halo2
Groth16 βœ”οΈ βœ”οΈ ❌ βœ”οΈ ❌ ❌
Plonk πŸ—οΈ βœ”οΈ ❌ βœ”οΈ ❌ βœ”οΈ
GKR βœ”οΈ βœ”οΈ ❌ βœ”οΈ ❌ ❌
Polynomial Commitment Schemes Lambdaworks Arkworks Plonky3 gnark Constantine Halo2
KZG10 βœ”οΈ βœ”οΈ ❌ βœ”οΈ βœ”οΈ βœ”οΈ
FRI βœ”οΈ ❌ βœ”οΈ βœ”οΈ ❌ ❌
Binius ❌ ❌ ❌ ❌ ❌ ❌
Circle FRI πŸ—οΈ ❌ βœ”οΈ ❌ ❌ ❌

Additionally, provers are compatible with the following frontends and VMs:

Backend Frontend Status
Groth16 Arkworks βœ”οΈ
Groth16 Gnark ❌
Groth16 Circom πŸ—οΈ
Plonk Gnark πŸ—οΈ
Plonk Noir ❌
Stark Winterfell βœ”οΈ
Stark Miden βœ”οΈ

This can be used in a multi-prover setting for extra security, or as a standalone with Rust.

Additional tooling usage

Fuzzers

Fuzzers are divided between those that use only the CPU and those that use CUDA.

To use them, make sure you have installed cargo fuzzer

You can install it with:

cargo install cargo-fuzz

CPU Fuzzers can be run with the command bash make run-fuzzer FUZZER=fuzzer_name

For example:

make run-fuzzer FUZZER=stark252

The list of fuzzers can be found in fuzz/no_gpu_fuzz

Fuzzers for FTT in Cuda can be run with make run-cuda-fuzzer

Run a specific fuzzer from the ones contained in fuzz/fuzz_targets/ folder withcargo, for example, to run the one for the target field_from_hex:

make run-fuzzer FUZZER=field_from_hex

Documentation building

To serve the documentation locally, first install both mdbook and the Katex preprocessor to render LaTeX, then run

make docs

Learning resources

If you want to learn about proof systems/cryptography, we have a list of resources available here

πŸ“š References and acknowledgements

The following links, repos, companies, and projects have been important in the development of this library, and we want to thank and acknowledge them.

Security

We take security seriously. If you discover a vulnerability in this project, please report it responsibly.

For more details, please refer to our Security Policy.

About

lambdaworks offers implementations for both SNARKs and STARKs provers, along with the flexibility to leverage their individual components for constructing customized SNARKs.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors