Skip to content
SimonLangowskiPublic

About

No description, website, or topics provided.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Latest commit

 

History

42 Commits

Folders and files

Repository files navigation

RNS Montgomery multiplication with AVX512

Standalone C++ template/header code. Benchmarks use Google Benchmark. Inversion with BLST requires BLST with extern "C" modification.

Artifact reviewers: start with ARTIFACT.md (environment, smoke test, parameter generation).

Repository layout

Path Role
src/ RNS rings, pairing/EC code, tests, benchmarks
cpu/ AVX vector CRNS, Montgomery reduction, precompute
examples/ Minimal working examples
scripts/ Parameter generation (rns_secp256k1.py), optional GPU benchmarks
test_data/ Reference test vectors
blst/ BLST fork (based on supranational/blst @ 8065152) — primary CPU baseline
baselines/ Optional external CPU baselines (arkworks, gnark, zksync, zkcrypto)
gpu/ CUDA kernels (optional, separate GPU host — see ARTIFACT_GPU.md)

Supported environment

OS Linux x86_64 — Amazon Linux 2023 on AWS for paper numbers; Ubuntu also works
Cloud AWS c7i (Intel Xeon Platinum 8488C, Sapphire Rapids)
CPU AVX-512 IFMA required for production build (grep avx512ifma /proc/cpuinfo)
Compiler clang 21.1.0 (LLVM 21 prebuilt) on reference host — IFMA codegen improves with newer clang; see ARTIFACT.md §1
Packages C++ toolchain, GMP, Google Benchmark — build from source with clang 21 on AL2023 (ARTIFACT.md §2)

Verify IFMA on a fresh instance:

cat /etc/os-release && uname -r
lscpu | grep -E 'Model name|Flags' | head -5
grep -q avx512ifma /proc/cpuinfo && echo "IFMA ok" || echo "Use fallback build"

Compiler note: AVX-512 IFMA performance depends strongly on the compiler. Newer clang (we used 21.1.0 on the paper host) emits much better IFMA code than distro GCC or older clang on the same CPU. Use scripts/setup_toolchain.sh for paper-comparable timings; older compilers are fine for correctness builds only.

GPU benchmarks are optional; see scripts/README.md.

Building & testing

Install dependencies — Amazon Linux 2023 (paper host):

chmod +x scripts/setup_toolchain.sh
./scripts/setup_toolchain.sh
eval "$(./scripts/setup_toolchain.sh --print)"

Pins clang 21.1.0 and google/benchmark at paper commits; see ARTIFACT.md §2.

Ubuntu:

sudo apt install build-essential libgmp-dev libbenchmark-dev

Build:

cd blst
make
cd ../src
make

Requires AVX-512 IFMA (-mavx512ifma). For integer-simulated vector ops (debugging / machines without IFMA), use make -f Makefile.fallback in src/ — compiles slowly and is not used for performance work.

Quick verification:

chmod +x scripts/smoke_test.sh
./scripts/smoke_test.sh

Use FALLBACK=1 ./scripts/smoke_test.sh without IFMA.

Minimal working examples

make -C examples
./examples/01_parameter_setup
./examples/02_singular_modmul
./examples/03_sum_of_products
./examples/04_difference_of_products
./examples/05_product_of_sums

See examples/README.md for details. Use make -C examples FALLBACK=1 without IFMA.

Tests & benchmarks

Target Purpose
make test Elementwise reduce + inversion
make test-bls12-381-field-mul BLS12-381 field multiply
make test-bls12-381-pairing BLS12-381 pairing
make test-pairing Pairing (AVX512 IFMA)
make test-ec EC point arithmetic
make test-ec-bn254 BN254 EC
make test-scalar-mult Scalar multiplication
make bench-bls12-381 Paper CPU benchmarks (BLS12-381, Matrix + MatrixNoK)
make bench-bls12-381 BLS12-381 component benchmarks
make bench-ec-bn254 BN254 EC benchmarks
make -f Makefile.fallback test-pairing Pairing test with integer fallback (correctness only)

Module map and parameter files: src/README.md. Parameter regeneration: ARTIFACT.md § Parameter generation.

External CPU baselines (optional)

VROOM vs BLST is automated in scripts/reproduce_cpu_bench.sh. For arkworks, gnark, zksync, and zkcrypto comparisons, see baselines/README.md and ./baselines/reproduce_baselines.sh.

Running

Paper numbers: AWS c7i.metal-24xl, Amazon Linux 2023, Intel Xeon Platinum 8488C, clang 21.1.0 (~/LLVM-21.1.0-Linux-X64/bin/clang++).

Development: AWS c7i-flex.large on the same AMI family is enough for iteration.

Compiler: GCC and older clang versions are significantly slower than clang 21.x on this codebase — especially on the AVX-512 IFMA path (-mavx512ifma), where LLVM’s backend has improved IFMA instruction selection and scheduling across recent releases. Paper timings use clang 21.1.0 (scripts/setup_toolchain.sh); do not expect to match published ns/op with the Amazon Linux default compiler.

  • ./bench_bls12_381 — paper CPU suite. MatrixNoK is the production BLS12-381 configuration (QR “no k” change-base); Matrix (IntRNS2 baseline) rows are also emitted. Parsed tables include both by default; pass --exclude-nok to parse_bench_json.py for Matrix only.

Sample output on c7i.metal-24xl with clang 21.1.0 (MatrixNoK rows; abbreviated):

Running ./bench_bls12_381
...
BM_ModMul_MatrixNoK                        21.8 ns         21.8 ns     ... ModMul_MatrixNoK
BM_BatchModMul_MatrixNoK_1                 21.7 ns         21.7 ns     ... BatchModMul_MatrixNoK_1
...
BM_MillerLoop_MatrixNoK                49888 ns        49888 ns        ... MillerLoop_MatrixNoK
BM_Pairing_RNS_BLST_Inverter_MatrixNoK 128146 ns       128146 ns       ... Pairing_RNS_BLST_Inverter_MatrixNoK
  • BM_BatchModMul_N — batch Montgomery multiplication, a*b mod p.
  • RNS_BLST_Inverter — uses RNS for FP12 inversion and BLST for FP inversion.
  • BM_Inverse — uses an addition chain of length 425 to invert in RNS without BLST dependency (compare to BM_FP12_Inverse_BLST and BM_FP12_Inverse_RNS_BLST)

GPU (optional, separate host)

CPU artifact evaluation does not require a GPU. For paper GPU latency figures:

  1. ARTIFACT_GPU.md — environment (Ubuntu + RTX 3090), setup, reproduction commands, claim mapping
  2. ./scripts/setup_gpu_deps.sh then ./scripts/reproduce_gpu_latency.sh (runs python3 latency.py)
  3. gpu/README.md — CUDA module map

scripts/requirements-gpu.txt pins cuda-python>=12.0,<13 (13.x breaks the imports used by basic_benchmarker.py). If nvcc picks an old default GCC and C++20 JIT fails, set NVCC_CCBIN / CUDAHOSTCXX as documented in ARTIFACT_GPU.md.

License

MIT. The blst/ subtree keeps its original Apache license and copyright (see blst/LICENSE).

Security

This is research-grade code, demonstrating the speedups of combining AVX512-IFMA, RNS Montgomery, and the BLS12-381 curve. It has not been vetted or audited for security.

Special thanks to Peter Rindal for identifying a bug in the conversion from radix to RNS algorithm, which requires floor rather than ceiling rounding. An updated proof for this case can be found in fix.pdf

About

No description, website, or topics provided.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages