A mathematically rigorous implementation of fundamental cryptographic protocols including Number Theoretic Transforms, polynomial commitments, and zero-knowledge Polynomial Interactive Oracle Proofs (PIOPs).
The Number Theoretic Transform is the finite field analogue of the Fast Fourier Transform, enabling efficient polynomial operations over finite fields.
For prime p and primitive n-th root of unity ω where n | (p-1):
- Forward NTT: For polynomial f(x) = ∑ᵢ₌₀ⁿ⁻¹ aᵢ xⁱ:
- Inverse NTT: Reconstruction using ω⁻¹:
Non-recursive implementation using bit-reversal permutation for optimal cache performance. Polynomial interpolation achieved through inverse NTT of evaluation points.
Efficient multiplication using convolution theorem in finite fields.
For polynomials f(x), g(x) of degree less than n:
- Pad to size 2n and compute NTT(f), NTT(g)
- Pointwise multiplication: NTT(h)[i] = NTT(f)[i] · NTT(g)[i]
- Inverse transform: h(x) = INTT(NTT(h))
- Time complexity: O(n log n) versus naive O(n²)
- Space complexity: O(n) field elements
Implementation of the Kate-Zaverucha-Goldberg commitment scheme for univariate polynomials.
- Setup(1^λ, d) → SRS: Generate (g, g^τ, g^τ², ..., g^τᵈ)
- Commit(f(x)) → c: Compute c = g^f(τ)
- CreateWitness(f(x), z) → π: Generate π = g^w(τ) where w(x) = (f(x) - f(z))/(x - z)
- VerifyEval(c, z, v, π) → {0,1}: Check e(c · g^(-v), g) = e(π, g^τ · g^(-z))
- Binding: Under d-Strong Diffie-Hellman assumption
- Succinctness: Constant proof size independent of polynomial degree
A PIOP proving that polynomial f(x) evaluates to zero everywhere on subgroup 𝐇_ℓ.
Key insight: f(x) = 0 on 𝐇_ℓ ⟺ Z₍𝐇_ℓ₎(x) | f(x) where Z₍𝐇_ℓ₎(x) = ∏ᵢ₌₀^(ℓ-1)(x - ωₗⁱ).
- Prover: Compute quotient q(x) = f(x)/Z₍𝐇_ℓ₎(x) and send Cᵩ = PCS(q)
- Verifier: Send random challenge r ∈ 𝔽_p
- Prover: Open f(r) and q(r) with respective proofs
- Verifier: Check f(r) = q(r) · Z₍𝐇_ℓ₎(r) and verify opening proofs
- Prover time: O(D)𝔾 + O(D)𝔽
- Verifier time: O(1)𝔾 + O(1)𝔽
- Proof size: O(1)
A PIOP proving that polynomial evaluations sum to zero over subgroup 𝐇_ℓ.
Key insight: For polynomial g(x) of degree < ℓ: ∑_(a ∈ 𝐇_ℓ) g(a) = g(0) · ℓ.
Therefore, ∑_(a ∈ 𝐇_ℓ) f(a) = 0 ⟺ ∃ h*(x), t(x) such that:
where deg(t) < ℓ - 1.
- Prover: Compute h*(x) and t(x), send C_{h*} = PCS(h*) and Cₜ = PCS(t)
- Verifier: Send random challenge r ∈ 𝔽_p
- Prover: Open f(r), h*(r), and t(r) with respective proofs
- Verifier: Check f(r) = h*(r) · Z₍𝐇_ℓ₎(r) + r · t(r) and verify opening proofs
- Prover time: O(D)𝔾 + O(D)𝔽
- Verifier time: O(1)𝔾 + O(1)𝔽
- Proof size: O(1)
# Install MCL cryptographic library
git clone https://github.com/herumi/mcl.git
cd mcl && make -j$(nproc) && sudo make install
# System requirements
sudo apt update && sudo apt install -y cmake g++ libomp-dev
# Clone and build
git clone <your-repo-url>
cd cryptography-implementation
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
# Run comprehensive test suite
./test_suite
include/
├── kzg.h # KZG polynomial commitment interface
├── ntt.h # Number theoretic transform operations
├── polynomial.h # Polynomial arithmetic and utilities
├── zerotest.h # ZeroTest PIOP protocol
└── sumcheck.h # SumCheck PIOP protocol
src/
├── kzg.cpp # KZG implementation with security proofs
├── ntt.cpp # Optimized NTT with primitive root finding
├── polynomial.cpp # Polynomial operations (eval, multiply, divide)
├── zerotest.cpp # ZeroTest prover/verifier with full verification
└── sumcheck.cpp # SumCheck prover/verifier with mathematical rigor
tests/
└── test_suite.cpp # Comprehensive test suite with attack vectors
- Library: Used mcl library with BN_SNARK1 curve for cryptographic operations
- Testing: Generated random polynomials and verified against mathematical properties
- Security: All protocols include formal verification and security proofs
- Performance: Optimized implementations with complexity analysis
#include <mcl/bn.hpp>
#include "kzg.h"
#include "zerotest.h"
#include "sumcheck.h"
// Initialize curve parameters
mcl::initPairing(mcl::BN_SNARK1);
// Setup phase (trusted setup)
KZG::SetupParams params = KZG::Setup(1024);
// Create and commit to polynomial
std::vector<Fr> poly = {Fr(1), Fr(2), Fr(3)}; // 1 + 2x + 3x²
KZG::Commitment commit = KZG::Commit(poly, params);
// Generate and verify evaluation proof
Fr point = Fr(42);
KZG::Proof proof = KZG::CreateWitness(poly, point, params);
bool valid = KZG::VerifyEval(commit, point, proof, params);
-
[KZG10] Kate, A., Zaverucha, G. M., & Goldberg, I. (2010). Constant-size commitments to polynomials and their applications. ASIACRYPT 2010.
-
[Thaler22] Thaler, J. (2022). Proofs, Arguments, and Zero-Knowledge.
-
MCL Library: https://github.com/herumi/mcl - High-performance cryptographic library
MIT License - see LICENSE file for details.
This implementation is for educational and research purposes. Mathematical rigor and security are prioritized throughout.