### 1 unstable release

0.4.0 | May 26, 2024 |
---|

#**2226** in Cryptography

**50** downloads per month

Used in **5** crates
(4 directly)

**MIT/Apache**

645KB

14K
SLoC

# arkworks::algebra

The arkworks ecosystem consist of Rust libraries for designing and working with *zero knowledge succinct non-interactive arguments (zkSNARKs)*. This repository contains efficient implementations of the key algebraic components underlying zkSNARKs: finite fields, elliptic curves, and polynomials.

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

## Directory structure

This repository contains several Rust crates:

: Generic abstractions for, and implementations of various kinds of finite fields`ark-ff`

: Generic abstractions for prime-order groups, and implementations of various kinds of (pairing-friendly and standard) elliptic curves`ark-ec`

: Interfaces for univariate, multivariate, and multilinear polynomials, and FFTs over finite fields`ark-poly`

: Efficient interfaces for serialization and point compression for finite fields and elliptic curves`ark-serialize`

In addition, the

repository contains concrete implementations of popular elliptic curves; see here for details.`curves`

## Build guide

The library compiles on the

toolchain of the Rust compiler (v 1.51+). To install the latest version of Rust, first install `stable`

by following the instructions here, or via your platform's package manager. Once `rustup`

is installed, install the Rust toolchain by invoking:`rustup`

`rustup`` install stable`

After that, use

, the standard Rust build tool, to build the libraries:`cargo`

`git`` clone https://github.com/arkworks-rs/algebra.git`
`cd`` algebra`
`cargo`` build`` --`release

## Tests

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

`cargo`` test`` --`all

## Benchmarks

To run the benchmarks, install the nightly Rust toolchain, via

, and then run the following command:`rustup`` install nightly`

`cargo`` +nightly bench`

## Assembly backend for field arithmetic

The

crate contains (off-by-default) optimized assembly implementations of field arithmetic that rely on the `ark-ff`

, `adcxq`

and `adoxq`

instructions. These are available on most `mulxq`

platforms (Broadwell onwards for Intel and Ryzen onwards for AMD). Using this backend can lead to a 30-70% speedup in finite field and elliptic curve arithmetic. To build with this backend enabled, run the following command:`x86_64`

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

To enable this in the

of your own projects, enable the `Cargo.toml`

feature flag:`asm`

`ark-ff = { version = "0.4", features = [ "asm" ] }
`

Note that because inline assembly support in Rust is currently unstable, using this backend requires using the Nightly compiler at the moment.

## License

The crates in this repository are licensed under either of the following licenses, at your discretion.

- Apache License Version 2.0 (LICENSE-APACHE or apache.org license link)
- MIT license (LICENSE-MIT or opensource.org license link)

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

## 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.

An earlier version of this library was developed as part of the paper *"ZEXE: Enabling Decentralized Private Computation"*.

###
`lib.rs`

:

This library implements a twisted Edwards curve whose base field is the scalar field of the curve BN254. This allows defining cryptographic primitives that use elliptic curves over the scalar field of the latter curve. This curve is also known as Baby-Jubjub.

Curve information:

- Base field: q = 21888242871839275222246405745257275088548364400416034343698204186575808495617
- Scalar field: r = 2736030358979909402780800718157159386076813972158567259200215660948447373041
- Valuation(q - 1, 2) = 28
- Valuation(r - 1, 2) = 4
- Curve equation: ax^2 + y^2 =1 + dx^2y^2, where
- a = 1
- d = 168696/168700 mod q = 9706598848417545097372247223557719406784115219466060233080913168975159366771

#### Dependencies

~4–5MB

~93K SLoC