$ show mratsim/constantine
Constantine is a high-performance modular cryptography library implemented in Nim, with bindings for C, Rust, and Go. It provides production-grade implementations of elliptic curve arithmetic, pairings, BLS signatures, KZG polynomial commitments, and Ethereum-specific protocols (EIP-2537, EIP-4844, EIP-7594). The library is designed with constant-time operations to resist side-channel attacks, includes a custom lock-free work-stealing threadpool for parallel execution, and features hand-optimized assembly for x86 (ADX, BMI2) and ARM64. It also contains experimental GPU code generation (CUDA, AMD ROCm) via LLVM IR. The codebase is extensively tested against GMP, OpenSSL, and official Ethereum test vectors, and includes formal verification of field arithmetic via fiat-crypto. Despite its research components (Sage scripts, optimization papers), the dominant character is a reusable, production-oriented library for blockchain and zero-knowledge proof systems.
The LLM identified 3 files worth highlighting for reuse:
Provides fundamental constant-time primitives: SecretBool, SecretWord, secretLookup, ccopy, cswap, and conditional moves. These are self-contained, platform-agnostic routines essential for any cryptographic implementation needing side-channel resistance. Can be extracted into a standalone module.
Implements a high-performance lock-free work-stealing threadpool with Await, spawn, and parallelFor abstractions. Includes barrier synchronization, scoped parallel regions, and configurable scheduling. The implementation is self-contained (imports only threadpool internals and platform primitives) and could be reused in other Nim projects needing parallelism.
Provides cross-platform endian conversion routines (big-endian and little-endian) for Nim's fixed-size integers. Uses compile-time endian detection and optimized intrinsics. While small, it is a clean, self-contained utility that could be extracted to any project needing reliable endian handling.