Building cryptographic primitives from scratch in Rust β ECC, BLS signatures, pairings, Pedersen commitments, and zero-knowledge proof building blocks. Strictly for learning.
β οΈ DO NOT USE IN PRODUCTION. This code is educational only. It has not been audited, is not constant-time, and is not secure for any real-world application.
π ecc/ β Elliptic Curve Cryptography from Scratch
A ground-up implementation of ECC without any external crypto libraries. Everything is built by hand to understand the math.
| Module | What it implements |
|---|---|
field.rs |
Finite field arithmetic (Fβ) β add, subtract, multiply, modular exponentiation, modular inverse |
point.rs |
Elliptic curve points β point addition, point doubling, point at infinity |
scalar.rs |
Scalar multiplication β double-and-add algorithm, O(log k) |
ecdsa.rs |
Toy ECDSA β key generation, message signing, signature verification |
Key concepts: Finite fields, elliptic curve group law, discrete logarithm problem, digital signatures.
π bls/ β BLS Signatures & Pairings β
Pairing-based cryptography using arkworks on BLS12-381.
| Part | File | What it covers |
|---|---|---|
| 1 | groups.rs |
Gβ/Gβ generators, scalar multiplication, identity |
| 2 | pairings.rs |
Bilinear pairing e(P,Q), bilinearity, non-degeneracy |
| 3 | bls.rs |
keygen, sign, verify via e(Ο, Gβ) == e(H(m), pk) |
| 4β5 | aggregate.rs |
Aggregate N signatures β 1, size comparison |
Ethereum context: Ethereum PoS uses BLS12-381 for validator attestations β 1M signatures collapsed into one 96-byte signature.
π pedersen-commitment/ β Pedersen Commitments β
Commit to a secret value without revealing it: C = vΒ·G + rΒ·H.
| Part | File | What it covers |
|---|---|---|
| 1 | generator.rs |
G (standard) and H (hash-derived), why independence matters |
| 2 | commit.rs |
commit(v, r), verify(v, r, C), hiding & binding demos |
| 3 | homomorphic.rs |
C1 + C2 = Commit(v1+v2, r1+r2), balance proofs |
Real-world use: Monero (hidden amounts), Mimblewimble, Bulletproofs, ZK-SNARKs.
# Run ECC project
cd ecc && cargo test
# Run BLS project
cd bls && cargo run # see all demonstrations
cd bls && cargo test # run unit tests
# Run Pedersen Commitment project
cd pedersen-commitment && cargo run # see demonstration
cd pedersen-commitment && cargo test # run unit testsECC (from scratch) β
ββββΆ BLS Signatures & Aggregation β
ββββΆ Pedersen Commitments β
ββββΆ Polynomial Commitments (KZG / IPA) π²
ββββΆ ZK-SNARKs (PLONK / Groth16) π²