lambdaworks

repository·main·Indexed 20 days ago

https://github.com/lambdaclass/lambdaworks

A high-performance Rust library providing cryptographic primitives and proving systems (SNARKs/STARKs) for Zero-Knowledge proofs and distributed systems. It features hardware acceleration via CUDA, Metal, and x86-64 assembly. Key components include lambdaworks-crypto for hash functions (Poseidon, Pedersen, Keccak256, SHA2-256, SHA3-256), Merkle trees, and polynomial commitment schemes such as KZG (requiring a trusted setup) and the transparent Inner Product Argument (IPA).

Tokens
109.1K
Snippets
258
Records
401
Agent score
70%

What's inside lambdaworks

  1. Overview of Lambdaworks Groth16 Prover

    main

    The Lambdaworks Groth16 Prover is an implementation of the Groth16 proof system. Groth16 is a SNARK (succinct, non-interactive argument of knowledge) protocol known for having very small proof sizes (consisting of only three elliptic curve elements) and extremely fast verification times.

    Key Characteristics:

    • Protocol: Groth16.
    • Curves: Relies on pairing-friendly elliptic curves such as BN254, BLS12-381, and BLS12-377.
    • Trade-off: Requires a trusted setup per program. Any change to the original program necessitates regenerating all parameters.
    • Status: Currently an under-optimized implementation.

    To use this prover with Circom circuits, refer to the circom-adapter examples.

  2. Overview of lambdaworks core crates

    main

    The library is organized into several specialized crates:

    • Math: Core mathematical primitives including field arithmetic, elliptic curves, and polynomial operations.
    • Crypto primitives: Cryptographic building blocks such as hashes, multiscalar multiplication (MSM), and elliptic curves.
    • STARK Prover: Implementation for proving Algebraic Intermediate Representations (AIR).
    • Plonk Prover: Implementation of the Plonk proving system.
    • Groth 16: Implementation of the Groth16 proving system, which can be used with Circom-generated circuits.
  3. Overview of Lambdaworks Stark Platinum Prover

    main

    The Lambdaworks Stark Platinum Prover is an open-source STARK (Scalable Transparent Argument of Knowledge) prover and verifier. It is designed as a drop-in replacement for Winterfell. STARKs are transparent (requiring no trusted setup) and post-quantum secure.

    Key components of the prover include:

    • Hash functions
    • Fiat-Shamir transformation
    • Finite fields
    • Univariate polynomials
    • Reed-Solomon codes

    Security Requirements:

    • The security level depends on the number of queries and the size of the underlying field.
    • The prover requires either a finite field of prime order or a field extension, both of which must be at least 128 bits in size.

    ⚠️ Disclaimer: This prover is currently in development and may contain bugs. It is not intended for production use at this time.

  4. Understand the lambdaworks crate structure and dependency graph

    main

    Lambdaworks is organized as a Cargo workspace where crates follow a hierarchical dependency model:

    • lambdaworks-math: The foundation. It has no internal dependencies and provides core mathematical primitives.
    • lambdaworks-crypto: Depends on math for field and curve operations. Provides cryptographic primitives like Merkle trees and hash functions.
    • lambdaworks-gpu: Provides optional acceleration (CUDA/Metal) for math operations.
    • provers (e.g., stark, plonk, groth16): The highest level. They depend on both math and crypto to implement various proof systems.

    Crate Hierarchy

                        ┌─────────────┐
                        │   provers   │
                        │(stark/plonk/│
                        │  groth16)   │
                        └──────┬──────┘
                               │
                  ┌────────────┼────────────┐
                  ▼            ▼            ▼
            ┌─────────┐  ┌─────────┐  ┌─────────┐
            │  math   │◄─│ crypto  │  │   gpu   │
            └─────────┘  └─────────┘  └─────────┘
    lambdaworks/
    ├── crates/
    │   ├── math/           # Core mathematical primitives
    │   ├── crypto/         # Cryptographic primitives
    │   ├── gpu/            # GPU acceleration (CUDA/Metal)
    │   └── provers/        # Proof systems
    │       ├── stark/      # STARK prover
    │       ├── plonk/      # PLONK prover
    │       ├── groth16/    # Groth16 prover
    │       ├── sumcheck/   # Sumcheck protocol
    │       └── gkr/        # GKR protocol
  5. Supported Elliptic Curve Models in lambdaworks

    main

    lambdaworks supports three primary elliptic curve models, each with various coordinate systems (e.g., homogeneous projective, Jacobian, XZ) optimized for performance:

    • Short Weierstrass: Includes pairing-friendly curves like BLS12-377, BLS12-381, and BN-254 (used on Ethereum), as well as Grumpkin, Pallas, Vesta, Starknet's curve, secp256k1 (Bitcoin's curve, non-constant time), secq256k1, and secp256r1 (P-256).
    • Twisted Edwards: Includes Ed448Goldilocks, Bandersnatch, and TinyJubJub (for learning).
    • Montgomery: Includes TinyJubJub (for learning).
  6. Explore Lambdaworks Examples

    main

    The examples/ directory contains several implementations to demonstrate different cryptographic tools:

    • Shamir Secret Sharing: Demonstrates polynomial and finite field usage.
    • Merkle tree CLI: A CLI tool for generating and verifying Merkle tree inclusion proofs.
    • Proving Miden: Shows how to execute a Miden VM program, extract a trace, and generate/verify a proof using the STARK Platinum prover.
    • BabySNARK: A simple SNARK implementation for learning elliptic curve-based proof systems.
    • Pinocchio: A practical SNARK implementation for zero-knowledge proof learning.
    • Circom to Lambdaworks: A tutorial for creating circuits in Circom and verifying them using Groth16 via Lambdaworks.
  7. Available hash functions in lambdaworks-crypto

    main

    The lambdaworks-crypto crate provides several hash functions designed for use in non-interactive proof systems. These are categorized into algebraic hash functions and elliptic curve-based hash functions:

    Algebraic Hash Functions

    • Monolith: An algebraic hash function.
    • Poseidon: An algebraic hash function.
    • Rescue: Contains two variants:
      • RPO (Rescue Prime Optimized)
      • RPX (Rescue Prime eXtension / XHash-12). Note that RPX is approximately 2x faster than RPO because it utilizes cubic extension field arithmetic in the extension rounds.

    Elliptic Curve-based Hash Functions

    • Pedersen: A hash function based on elliptic curves.
  8. Use the RSA implementation for educational purposes

    main

    The RSA implementation in lambdaworks provides an asymmetric cryptographic algorithm using a public key (for encryption) and a private key (for decryption).

    ⚠️ WARNING: NOT FOR PRODUCTION USE This implementation is not cryptographically secure because it uses non-constant time operations. It is intended strictly for educational purposes and should not be used in production environments. For production, use established, audited cryptographic libraries.

  9. What is MultiScalar Multiplication (MSM) in lambdaworks

    main

    MultiScalar Multiplication (MSM) is a cryptographic primitive used in polynomial commitment schemes (like KZG), proof systems, and protocols such as EIP-4844. Given a set of scalars $a_0, a_1, ..., a_n$ from a finite field and a set of elliptic curve points $P_0, P_1, ... , P_n$, MSM computes the sum:

    $$P = \sum_k a_k P_k$$

    where $a_k P_k$ represents the group operation applied to $P_k$ a total of $a_k$ times.

    lambdaworks provides two primary implementation strategies:

    1. Naïve: A direct implementation of the summation.
    2. Pippenger: An optimized algorithm designed for high performance in large-scale multiplications.
  10. Overview of LogUp-GKR

    main

    LogUp-GKR is an implementation of the LogUp-GKR protocol designed for efficient lookup arguments. It improves upon standard LogUp by replacing intermediate accumulator columns with a single multiplicities column, using the GKR interactive proof protocol to verify accumulation. This significantly reduces commitment costs.

    The lookup is expressed as a fractional sum identity: $$\sum_i \frac{1}{z - a_i} = \sum_j \frac{m_j}{z - t_j}$$ where $a_i$ are accessed values, $t_j$ are table entries, and $m_j$ are multiplicities. The prover evaluates this through a binary tree of fraction additions, which forms the GKR circuit.

  11. What is Circle Fast-Fourier Transform (CircleFFT)?

    main
    CircleFFT is an algorithm for performing a variant of the radix-2 FFT over finite fields that are not 'smooth'. A field is considered smooth if the size of its multiplicative group is divisible by a high power of 2. CircleFFT allows for efficient polynomial evaluation and interpolation in the Circle group, which is a key component in Circle STARKs. It is particularly useful when the field size $p$ does not satisfy $p-1 = 2^m c$ for a large $m$.
  12. Overview of the Sumcheck Protocol

    main
    The Sumcheck Protocol allows a prover to convince a verifier that the sum of a multivariate polynomial over the Boolean hypercube equals a claimed value without the verifier computing the entire sum. It reduces the complexity of computing the sum to $O(\nu)$ additions plus an evaluation at a random point. The protocol proceeds in rounds (one per variable), where the prover sends a univariate polynomial and the verifier responds with a random challenge.