Git Product home page Git Product logo

lambdaclass / lambdaworks Goto Github PK

View Code? Open in Web Editor NEW
575.0 10.0 121.0 25.19 MB

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

Home Page: https://lambdaclass.github.io/lambdaworks/

License: Apache License 2.0

Dockerfile 0.01% Makefile 0.23% Nix 0.01% Rust 97.34% Metal 1.17% Cuda 0.85% C 0.01% Cairo 0.37%
cryptography mathematics zero-knowledge-proofs

lambdaworks's Introduction

lambdaworks

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

This library provides 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

Why we built lambdaworks

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

So, we decided to build our library, focusing on performance, with clear documentation and developer-focused. Our core team is a group of passionate people from different backgrounds and different strengths; we think that the whole is greater than just the addition of the 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.

Main crates

Crypto

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

Both Math and Crypto support wasm with 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.

Examples - mini apps

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 there is a mistake or there has been 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 Halo2 gnark Constantine
StarkField 252 โœ”๏ธ โœ”๏ธ โŒ โœ”๏ธ โŒ
Mersenne 31 โœ”๏ธ โŒ โŒ โŒ โŒ
Baby Bear โœ”๏ธ โŒ โŒ โŒ โŒ
MiniGoldilocks โœ”๏ธ โŒ โŒ โœ”๏ธ โŒ
ZK friendly Hash function Lambdaworks Arkworks Halo2 gnark Constantine
Poseidon ๐Ÿ—๏ธ โœ”๏ธ โœ”๏ธ โŒ โŒ
Pedersen ๐Ÿ—๏ธ โœ”๏ธ โœ”๏ธ โŒ โŒ
Rescue Prime XLIX โŒ โŒ โŒ โŒ โŒ
Elliptic Curves Lambdaworks Arkworks Halo2 gnark Constantine
BLS12-381 โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
BLS12-377 ๐Ÿ—๏ธ โœ”๏ธ โŒ โœ”๏ธ โœ”๏ธ
BN-254 ๐Ÿ—๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
Pallas โœ”๏ธ โœ”๏ธ โŒ โŒ โœ”๏ธ
Vesta โœ”๏ธ โœ”๏ธ โŒ โŒ โœ”๏ธ
Bandersnatch ๐Ÿ—๏ธ โœ”๏ธ โŒ โœ”๏ธ โœ”๏ธ
STARKs Lambdaworks Arkworks Halo2 gnark Constantine
STARK Prover โœ”๏ธ โŒ โŒ โŒ โŒ
CAIRO Prover ๐Ÿ—๏ธ โŒ โŒ โŒ โŒ
SNARKs Lambdaworks Arkworks Halo2 gnark Constantine
Groth16 โœ”๏ธ โœ”๏ธ โŒ โœ”๏ธ โŒ
Plonk ๐Ÿ—๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โŒ
Spartan โŒ โœ”๏ธ โŒ โŒ โŒ
Marlin โŒ โœ”๏ธ โŒ โŒ โŒ
GKR โŒ โœ”๏ธ โŒ โœ”๏ธ โŒ
Polynomial Commitment Schemes Lambdaworks Arkworks Halo2 gnark Constantine
KZG10 โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
FRI ๐Ÿ—๏ธ โŒ โŒ โœ”๏ธ โŒ
IPA ๐Ÿ—๏ธ โœ”๏ธ โœ”๏ธ โŒ โŒ
Brakedown โŒ โŒ โŒ โŒ โŒ
Basefold โŒ โŒ โŒ โŒ โŒ
Folding Schemes Lambdaworks Arkworks Halo2 gnark Constantine
Nova โŒ โœ”๏ธ โŒ โŒ โŒ
Supernova โŒ โŒ โŒ โŒ โŒ
Protostar โŒ โŒ โŒ โŒ โŒ
Protogalaxy โŒ โœ”๏ธ โŒ โŒ โŒ

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 โœ”๏ธ
Stark Cairo โœ”๏ธ

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

Additional tooling usage

Fuzzers

Fuzzers are divided between the ones that use only the CPU, the ones that use Metal, and the ones that use CUDA.

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

For example:

make run-fuzzer FUZZER=field_from_hex

The list of fuzzers can be found in fuzz/no_gpu_fuzz

Fuzzers for FTT in Metal and Cuda can be run with make run-metal-fuzzer and 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

๐Ÿ“š References

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

lambdaworks's People

Contributors

ajgara avatar aminarria avatar daphneherlambda avatar diegokingston avatar elfantasma avatar entropidelic avatar feltroidprime avatar fmoletta avatar franfiuba avatar gabrielbosio avatar gianfrancobazzani avatar iavecilla avatar ilitteri avatar irfanbozkurt avatar jrchatruc avatar juan-m-v avatar juan518munoz avatar maurotoscano avatar mb-dci avatar mdvillagra avatar megaredhand avatar mpaulucci avatar oppen avatar pablodeymo avatar patstiles avatar schouhy avatar startup-dreamer avatar tcoratger avatar unbalancedparentheses avatar xqft 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

lambdaworks's Issues

Rename traits

There is currently a naming convention on traits that they are supposed to start with something like Is or Has. We should get rid of it

Refactor benchmarks structure

The idea is to have a structure like this (for both math and crypto crates):

benches
|_benchmarks
|  |_mod.rs
|  |_field.rs
|  |_...
|_benchmarks.rs
|_benchmarks_field.rs
|_...
  • The benchmarks.rs file will run all the benchmarks and the benchmarks_<module> will run the module's benchmarks.
  • The benchmarks will be written in the benchmarks module in the corresponding files.

The goal with this is for us to be able to run all the benchmarks at once or just some of them individually.

We'll also need to have two targets in the Makefile:

// Run all the benchmarks at once
benches:
    cargo criterion --bench benchmarks

// Run a specific benchmark
benchmark:
    cargo criterion --bench ${BENCHMARK}

Implement Arbritrary for all types

Building from the ground up with fuzzing in mind is always beneficial to libraries, especially ones that define their own types.

Meaning the Arbitrary trait should be implemented for all types, maybe even on the features themselves. This way, setting up libFuzzer, cargo fuzz, or AFL is easy.

The standard approach is to add a feature gate arbitrary that reveals the Arbitrary trait implementations when enabled.

Add `to_hex(&self) -> String` to `FieldElement` of a `IsPrimeField`

Add to_hex(&self) -> String function to FieldElement and implement it where needed

This function should create an hexstring representing the number in FieldElement. It should abstract the user from the internal representation, so if the number is in Montgomery form, it should convert it back to the original form before returning the element.

Add `from_hex(hex_string: &str)` to `FieldElement`

Add from_hex(hex_string: &str) -> Self function to FieldElement and implement it where needed

This function should create FieldElement from an hex string. It should support arbitrary sizes of strings, and be easily shared between FieldElement implementations.

It needs to take in account the internal representation may not be the same number. For example, if "1" is the input, and the MontgomeryBackend is used, the number stored will be 1 * R mod MODULUS, but the user should never know about the internal representation.

Additionally, it may be useful to make it a const fn

More in the Readme file

Hey, you folks planning on writing any tutorials or more comprehensive for Readme.md for newbies? Would love to help with that so more learners could start with this

Field Trait API UX

I think that for the Field trait, rather than defining methods like add, sub, mult, inv, etc., they should leverage the core::ops::Add and others.

If a trait for a method does not exist, it should be defined in a similar style to one from core::ops.

NOTE:
The use of core instead of std here, and I would recommend using core for all things where possible as it would make supporting no_std easier.
They point to the same implementations, but core is specifically for no_std environments.

Add boundary polynomial functionality

  • Interpolate trace values where there are boundary constraintsto obtain polynomial
  • Subtract this new polynomial to the trace polynomial
  • Divide by zerofier

Implement two-adic fields in MSL (Metal)

We need operations over finite fields defined in the Metal Shading Language for implementing FFT (#116) and possibly other future algorithms in the GPU. So it's required to make implementations that mimic the ones we already have in Rust.

Some requirements:

  • Basic operations like sum, sub, mul, div.
  • Watch out for integer overflow, special care is needed to implement the mul operation for example.
  • Ideally we could build a field with a custom module (represented as an uint64_t or whichever type is needed)
  • MSL only supports up to 64-bit integers, so it would be needed to also implement classes for bigger ints (specifically see which fields with big integers there are implemented on Rust right now)
  • The work directory will be math/src/fft/metal/

Relevant resources:

  • MSL Specification (MSL is based on C++)
  • The Metal documentation and also see our metal_playground repo for examples on how to use the metal crate in Rust, useful for testing.
  • risc0 and ministark have some examples of prime fields implemented in C or MSL.
  • Us
  • General information about finite fields and modular arithmetic can be easily found on the web.

Define `ByteConversion` trait

The ByteConversion trait should define:

  • to_bytes_be: Big-Endian representation.
  • to_bytes_le: Little-Endian representation.
  • from_bytes_be: Big-Endian representation.
  • from_bytes_le: Little-Endian representation.

Change `assert!`s for `debug_assert!`s

Some functions should return a Resultinstead of using an assert because doing the latter would panic in runtime.

In general, if you don't have any choice but to panic it is better to describe the cases in which that function would panic and why in the documentation.

For this issue, we just want to replace these assertions with debug assertions. We'll address the Result in another issue.

An example would be this.

Implement parallelizable 2-radix FFT algorithms

Acceptance criteria:

  • It should be customisable to to use sequential or the parallelizable implementation.
  • Parallelizable version should pass all the tests that the sequencial version passes.

Sparse polynomial representation

Implement sparse polynomial representation. We should support operations between sparse and dense polynomials, and conversions between them.

The first task is to be investigate how it's done in other libraries, and update the issue with an explanation of how it's done in them.

Investigate Canonical Signed Digit representation for faster exponentiations and EC scalar mul

The canonical signed digit, or Non-Adjacent Form (NAF) is a unique way to represent a binary number with a lower absolute hamming weight, using digit โ‚ฌ {0,1,-1} as coefficients instead of just digit โ‚ฌ {0,1}.

See https://en.wikipedia.org/wiki/Non-adjacent_form

It should improve performance in exponentiation by squaring algorithms and similar as you just need a sub or negate function for -1 cases.
The overall hamming weight W = sum([abs(digit) for digit in bin(int)]) is in average 1/3 instead of 1/2.
Using this representation should lead to improvements in the range of 10-25% for the average case.

An example of this technique can be found in the gnark repo :

definition : https://github.com/ConsenSys/gnark-crypto/blob/8f7ca09273c24ed9465043566906cbecf5dcee91/ecc/bn254/bn254.go#L141-L143
usage (miller loop) : https://github.com/ConsenSys/gnark-crypto/blob/8f7ca09273c24ed9465043566906cbecf5dcee91/ecc/bn254/pairing.go#L161

Remove panics on the `inv` methods

Currently the inv implementations for U64PrimeField and U384PrimeField both panic when dividing by zero. We should return an error instead. For this, we should use thiserror.

Add Zerofiers to the STARK prover polynomials

The current composition polynomials we commit to do not divide by the appropriate zerofiers. When this is done, change the proving to evaluate on a root of unity coset instead of an actual set of roots of unity.

Generalize `IsMontgomeryConfiguration` and `MontgomeryBackendPrimeField`

In order to solve #95 without repeat code i tried to generalize IsMontgomeryConfiguration trait and MontgomeryBackendPrimeField struct to allow usage with any UnsignedInteger.

Tried something like this:
image

If i use a generic U: IsUnsignedInteger :

image

Any idea to define a generic to generalize any type UnsignedInteger<_> struct like?

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.