0xPolygonMiden / crypto

Cryptographic primitives used in Polygon Miden rollup
MIT License
97 stars 32 forks source link

Miden Crypto

LICENSE test no-std [RUST_VERSION]() CRATE

This crate contains cryptographic primitives used in Polygon Miden.

Hash

Hash module provides a set of cryptographic hash functions which are used by the Miden VM and the Miden rollup. Currently, these functions are:

For performance benchmarks of these hash functions and their comparison to other popular hash functions please see here.

Merkle

Merkle module provides a set of data structures related to Merkle trees. All these data structures are implemented using the RPO hash function described above. The data structures are:

The module also contains additional supporting components such as NodeIndex, MerklePath, and MerkleError to assist with tree indexation, opening proofs, and reporting inconsistent arguments/state.

Signatures

DSA module provides a set of digital signature schemes supported by default in the Miden VM. Currently, these schemes are:

For the above signatures, key generation, signing, and signature verification are available for both std and no_std contexts (see crate features below). However, in no_std context, the user is responsible for supplying the key generation and signing procedures with a random number generator.

Pseudo-Random Element Generator

Pseudo random element generator module provides a set of traits and data structures that facilitate generating pseudo-random elements in the context of Miden VM and Miden rollup. The module currently includes:

Crate features

This crate can be compiled with the following features:

Both of these features imply the use of alloc to support heap-allocated collections.

To compile with no_std, disable default features via --no-default-features flag.

AVX2 acceleration

On platforms with AVX2 support, RPO and RPX hash function can be accelerated by using the vector processing unit. To enable AVX2 acceleration, the code needs to be compiled with the avx2 target feature enabled. For example:

cargo make build-avx2

SVE acceleration

On platforms with SVE support, RPO and RPX hash function can be accelerated by using the vector processing unit. To enable SVE acceleration, the code needs to be compiled with the sve target feature enabled. For example:

cargo make build-sve

Testing

The best way to test the library is using our Makefile.toml and cargo-make, this will enable you to use our pre-defined optimized testing commands:

cargo make test-all

For example, some of the functions are heavy and might take a while for the tests to complete if using simply cargo test. In order to test in release and optimized mode, we have to replicate the test conditions of the development mode so all debug assertions can be verified.

We do that by enabling some special flags for the compilation (which we have set as a default in our Makefile.toml):

RUSTFLAGS="-C debug-assertions -C overflow-checks -C debuginfo=2" cargo test --release

License

This project is MIT licensed.