Crate ark_ff_optimized

source ·
Expand description

Optimized arkworks field implementations

Specialized field implementations that outperform the generic, Montgomery arithmetic, field implementations provided in arkworks. Currently only one field has been added. Please contribute an implementation! PRs are welcomed!

Prime field p=18446744069414584321

use ark_ff_optimized::fp64::Fp;

An amazing prime with modulus p=2^64−2^32+1. This field has some nice properties (1) Multiplying two 32-bit values does not overflow the field modulus and (2) Checking whether four 16-bit values form a valid field element can be done efficiently. This field is used in Polygon Miden and Polygon Zero. Implementation was sourced from EcGFp5: a Specialized Elliptic Curve and Facebook’s Winterfell repo.

BenchmarkGenericSpecialized (this repo)
Sum of products of size 218.04 ns7.34 ns (🚀 2.46x faster)
Inverse556.74 ns283.87 ns (🚀 1.96x faster)
Legendre for QR1.12 us596.15 ns (🚀 1.88x faster)
Naive sum of products of size 215.41 ns8.68 ns (🚀 1.78x faster)
Deserialize Compressed8.82 ns4.99 ns (🚀 1.77x faster)
Deserialize Compressed Unchecked8.80 ns4.97 ns (🚀 1.77x faster)
Deserialize Uncompressed8.86 ns5.16 ns (🚀 1.72x faster)
Deserialize Uncompressed Unchecked8.81 ns5.15 ns (🚀 1.71x faster)
Square Root for QR4.43 us2.77 us (🚀 1.60x faster)
Multiplication6.15 ns4.03 ns (🚀 1.53x faster)
From BigInt5.32 ns4.30 ns (✅ 1.24x faster)
Serialize Uncompressed4.72 ns3.95 ns (✅ 1.20x faster)
Into BigInt4.72 ns3.92 ns (✅ 1.20x faster)
Serialize Compressed4.72 ns3.96 ns (✅ 1.19x faster)
Square5.60 ns4.88 ns (✅ 1.15x faster)
Subtraction4.09 ns3.77 ns (✅ 1.09x faster)
Addition4.11 ns3.79 ns (✅ 1.08x faster)
Negation4.21 ns3.90 ns (✅ 1.08x faster)
Double4.13 ns4.32 ns (❌ 1.04x slower)

Benchmarked on an M1 Max. Markdown generated with criterion-table. More detailed benchmark info is here

Modules

  • An implementation of a 31-bit Mersenne prime (no 2^k roots of unity for k>1) field with modulus 2^31 - 1. Mersenne primes have a fast reductions to to their binary representation.
  • An implementation of a 64-bit STARK-friendly prime field with modulus 2^64 - 2^32 + 1. The implementation follows https://eprint.iacr.org/2022/274.pdf and the code for the majority of functions was taken and adapted from https://github.com/novifinancial/winterfell

Macros