Code Monkey home page Code Monkey logo

bls12_381's Introduction

bls12_381 Crates.io

This crate provides an implementation of the BLS12-381 pairing-friendly elliptic curve construction.

  • This implementation has not been reviewed or audited. Use at your own risk.
  • This implementation targets Rust 1.56 or later.
  • This implementation does not require the Rust standard library.
  • All operations are constant time unless explicitly noted.

RFC process

This crate follows the zkcrypto RFC process. If you want to propose "substantial" changes to this crate, please create an RFC for wider discussion.

Features

  • bits (on by default): Enables APIs for obtaining bit iterators for scalars.
  • groups (on by default): Enables APIs for performing group arithmetic with G1, G2, and GT.
  • pairings (on by default): Enables some APIs for performing pairings.
  • alloc (on by default): Enables APIs that require an allocator; these include pairing optimizations.
  • nightly: Enables subtle/nightly which tries to prevent compiler optimizations that could jeopardize constant time operations. Requires the nightly Rust compiler.
  • experimental: Enables experimental features. These features have no backwards-compatibility guarantees and may change at any time; users that depend on specific behaviour should pin an exact version of this crate. The current list of experimental features:

Curve Description

BLS12-381 is a pairing-friendly elliptic curve construction from the BLS family, with embedding degree 12. It is built over a 381-bit prime field GF(p) with...

  • z = -0xd201000000010000
  • p = (z - 1)2(z4 - z2 + 1) / 3 + z
    • = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab
  • q = z4 - z2 + 1
    • = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001

... yielding two source groups G1 and G2, each of 255-bit prime order q, such that an efficiently computable non-degenerate bilinear pairing function e exists into a third target group GT. Specifically, G1 is the q-order subgroup of E(Fp) : y2 = x3 + 4 and G2 is the q-order subgroup of E'(Fp2) : y2 = x3 + 4(u + 1) where the extension field Fp2 is defined as Fp(u) / (u2 + 1).

BLS12-381 is chosen so that z has small Hamming weight (to improve pairing performance) and also so that GF(q) has a large 232 primitive root of unity for performing radix-2 fast Fourier transforms for efficient multi-point evaluation and interpolation. It is also chosen so that it exists in a particularly efficient and rigid subfamily of BLS12 curves.

Curve Security

Pairing-friendly elliptic curve constructions are (necessarily) less secure than conventional elliptic curves due to their small "embedding degree". Given a small enough embedding degree, the pairing function itself would allow for a break in DLP hardness if it projected into a weak target group, as weaknesses in this target group are immediately translated into weaknesses in the source group.

In order to achieve reasonable security without an unreasonably expensive pairing function, a careful choice of embedding degree, base field characteristic and prime subgroup order must be made. BLS12-381 uses an embedding degree of 12 to ensure fast pairing performance but a choice of a 381-bit base field characteristic to yield a 255-bit subgroup order (for protection against Pollard's rho algorithm) while reaching close to a 128-bit security level.

There are known optimizations of the Number Field Sieve algorithm which could be used to weaken DLP security in the target group by taking advantage of its structure, as it is a multiplicative subgroup of a low-degree extension field. However, these attacks require an (as of yet unknown) efficient algorithm for scanning a large space of polynomials. Even if the attack were practical it would only reduce security to roughly 117 to 120 bits. (This contrasts with 254-bit BN curves which usually have less than 100 bits of security in the same situation.)

Alternative Curves

Applications may wish to exchange pairing performance and/or G2 performance by using BLS24 or KSS16 curves which conservatively target 128-bit security. In applications that need cycles of elliptic curves for e.g. arbitrary proof composition, MNT6/MNT4 curve cycles are known that target the 128-bit security level. In applications that only need fixed-depth proof composition, curves of this form have been constructed as part of Zexe.

Acknowledgements

Please see Cargo.toml for a list of primary authors of this codebase.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

bls12_381's People

Contributors

a-manning avatar andrewwhitehead avatar daniel-aaron-bloom avatar dignifiedquire avatar ebfull avatar erikzhang avatar iamalwaysuncomfortable avatar joebebel avatar justindrake avatar mmaker avatar nuttycom avatar rex4539 avatar saitima avatar samuelburnham avatar str4d avatar wwared avatar

Watchers

 avatar  avatar

bls12_381's Issues

CI: install basic CI + remove clippy linting or make sure the repo passes it

At the moment, no PR is likely to pass the CI of this repo, because of :

  • a stale rust-toolchain,
  • clippy warnings in many places.

We should modify the repo so that it has basic CI. Important note: the clippy lint needless_borrow is often a false positive in this repo, since the verbose references are there to allow the compiler to infer that many functions are in a const context. I'd advise initially #[allow(...)]-ing it.

Add tests ensuring equivalence between zkvm and native Rust

As we've optimized more of the codebase for the zkvm context, we've ended up with slight duplication of functionality. Ideally we should have some simple tests that can be run inside the zkvm ensuring the native rust and the in-rust functionality are still an exact match.

Tracking Issue: Precompiles for Light Client

Currently, we leverage the zkvm or the decompress branch to leverage the pre-compiles in our light client implementation. I'm opening this issue to keep track of what is needed, what is available and what is to come.

Usage in Light Client

For the Light Client usage we are leveraging the bls crate on two main structures: PublicKey and Signature. PublicKey are structure defined over G1 while Signature are defined over G2. Those components have the following usage associated to them:

  • PubllicKey
    • decompression: Conversion from a compressed form (slice of 48 bytes) to its decompressed one.
    • aggregate: Addition of G1 decompressed points. In the future, we might also need substraction for optimization purposes.
  • Signature
    • decompression: Conversion from a compressed form (slice of 96 bytes) to its decompressed one.
  • signature_verification : Verify an aggregated signature based on the aggregated public key, by leveraging the pairing mechanism.

What's to be integrated

After some exchange with @wwared here is what we believe should be integrated in this crate for our purposes:

Current status

Already on the branch

  • add, sub, mul of Fp
  • add, sub, mul of Fp2
  • Decompression of G1 in the unchecked endpoint
  • add and double for G1Affine (used in G1Affine::add_affine only for now)

To add

  • add for G2Affine

To add in future work

  • Fp2 sqrt (done, but not merged as a PR - might not get merged in favor of a G2 decompress precompile)
  • Fp sqrt (same as above)
  • Fp invert
  • Fp2 invert
  • double for G2Affine
  • G2 decompress in the unchecked endpoint

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.