MystenLabs / fastcrypto

Common cryptographic library used in software at Mysten Labs.
Apache License 2.0
238 stars 138 forks source link
benchmark blockchain bls crypto cryptography ed25519 zkp

fastcrypto

crate Docs Build status Update the fastcrypto pointer Sui Apache2/MIT licensed Rust Version codecov

fastcrypto is a common cryptography library used in software at Mysten Labs. It contains three individual crates: fastcrypto, fastcrypto-zkp and fastcrypto-cli. They are published as independent crates to encourage reusability across different applications and domains.

fastcrypto is a wrapper library around several carefully selected crates with the following considerations:

Furthermore, we extend the selected libraries with additional features:

This library will be continuously updated with more schemes and faster implementations based on benchmarking results, RFC updates, new research and auditor inputs.

The fastcrypto crate contains:

The fastcryto-zkp crate contains APIs to verify a Groth16 proof along with its prepared verifying key and public inputs. BN254 and BLS12381 curves are supported. The verifier is backed Arkworks and blst libraries.

The fastcrypto-cli crate includes CLI tools available for debugging. See usages with -h flag.

$ cargo build --bin encode-cli
$ target/debug/encode-cli -h
$ cargo build --bin sigs-cli
$ target/debug/sigs-cli -h
$ cargo build --bin ecvrf-cli
$ target/debug/ecvrf-cli -h

Tests

There exist unit tests for all primitives in all three crates, which can be run by:

$ cargo test

Benchmarks

In fastcrypto, one can compare all currently implemented signature schemes for sign, verify, verify_batch and key-generation by running:

$ cargo bench

A report of the benchmarks is generated for each release, allowing easy comparison of the performance of the different cryptographic primitives and schemes available in fastcrypto. As an example, we get these timings for signing messages and verifying the signature for the different schemes in fastcrypto as of revision dd5adb:

Signature schemes comparison.

Below is another plot made using data from the benchmark report, showing benchmarks for batched signature verification where all signatures are on the same message:

Batched signature verification with all signatures on same message.

In fastcrypto-zkp, benchmarks can be ran for Arkworks to blst representation of field elements, and verifying Groth16 in BN254 and BLS12381:

$ cd fastcrypto-zkp/
$ cargo bench

License

All crates licensed under either of