The vfhe library
An open-source Python library, built on native C kernels, for zero-knowledge proofs, fully homomorphic encryption, and verifiable FHE.
Python 3.11–3.15 · Linux and macOS · x86_64 (arm64 in progress) · Apache-2.0
Efficient Arithmetic Backends
Fast native arithmetic over power-of-two cyclotomic rings in RNS form, finite and extension fields, multiprecision integers, and complex numbers. The kernels are optimized for x86_64 with AVX-512 IFMA, with a portable fallback for other CPUs, and run multithreaded. Optimized arm64 support is in progress.
Zero-Knowledge Proofs
The building blocks of succinct arguments, over finite fields and over Rq: a framework for polynomial IOPs with sumcheck, GKR, and lookup and range arguments, the Basefold and BatchFold polynomial commitments, and Fiat-Shamir. Complete SNARKs built from these blocks are in progress.
Fully Homomorphic Encryption
The CKKS and BFV schemes over RNS, on a Module-LWE and GSW core with key switching, automorphisms, and ring switching, together with bootstrapping implementations (CGGI16, GP25, CHKS25). It is all built on the same proof-friendly arithmetic as the proof systems, so that encrypted computations can be proven.
Verifiable FHE
Proofs that an encrypted computation was carried out correctly. vfhe records every operation of an FHE computation and turns the record into the witness of an arithmetization: Batch, Pack, and Prove for now, with more to come. Proving these witnesses end to end is the next step.
A first look
Compute on encrypted data, record the computation for a proof, and prove a claim about committed polynomials. Every snippet runs as shown on vfhe 0.0.4.
Multiply two encrypted vectors with CKKS, at a toy ring size.
from vfhe.arith import Ring
from vfhe.fhe import CKKS_Scheme
scheme = CKKS_Scheme(Ring(256, 300), scaling_factor=2**49) # toy size: 128 slots
key = scheme.key_gen(3.2)
scheme.rlk = scheme.gen_rlk(key, key) # relinearization key
ct_a = scheme.encrypt(scheme.encode([1.5 + 0.5j, 2.0]), key)
ct_b = scheme.encrypt(scheme.encode([0.5 - 0.5j, 3.0]), key)
ct = ct_a * ct_b # multiply under encryption
print(scheme.decode(scheme.decrypt(ct, key))[:2]) # ≈ [1-0.5j, 6]
Record the same multiplication and read it as the witness of the Batch, Pack, and Prove arithmetization.
# Continuing the first tab
from vfhe.util import trace
from vfhe.vfhe import cccfgs26, witness
with trace.recording() as t: # record every ring operation of the product
ct = ct_a * ct_b
w = witness.of(t.operations(), cccfgs26) # the Batch, Pack, and Prove witness
w.check() # every relation of the arithmetization holds
Commit to 256 polynomials of Rq and prove that every coefficient is below 216, a bound on their L∞ norm. The verifier sees only the commitment and the proof: Basefold commitments, Fiat-Shamir, 128-bit parameters.
import random
from vfhe.arith import MLE, MLE_Variable, Polynomial, PseudoMersenneField, Ring
from vfhe.piop import IOP, OracleKind, Relation_Eval, Statement
from vfhe.piop.protocols import LogUpGKR, RangeDecomposition, Sumcheck, VirtualEval
from vfhe.piop.relations import Relation_Lookup, Relation_Range, Relation_Sum
from vfhe.polycom import (Basefold, BasefoldEval, FoldableRS, basefold_messages,
basefold_parameters)
ring = Ring(256, prime_size=[45, 45, 45])
field = PseudoMersenneField.generate(208, two_adicity=32)
# Basefold over R_q commits the 2^8 polynomials (128-bit parameters)
p = basefold_parameters(ring, 8)
ring_basefold = BasefoldEval(Basefold(FoldableRS(ring, p.k0, p.c, p.d)), rep=p.rep)
# The tables the proof itself sends (2^16 entries) are committed with Basefold too
messages, (field_basefold,) = basefold_messages(field, [16])
def iop(): # look up every coefficient in the table {0, ..., 2^16 - 1}
iop = IOP(domain=field, fiat_shamir=True)
iop.register(Relation_Range, RangeDecomposition(
field, m=15, alphabet=2**11, kappa=20, ring=ring, chunks=1, messages=messages))
iop.register(Relation_Lookup, LogUpGKR(field, messages=messages))
iop.register(Relation_Sum, Sumcheck())
iop.register(Relation_Eval, VirtualEval(), kind=OracleKind.virtual)
iop.register(Relation_Eval, field_basefold)
iop.register(Relation_Eval, ring_basefold)
return iop
# 2^8 polynomials with coefficients in [0, 2^16): their L-inf norm is below 2^16
evaluations = [Polynomial(ring).from_array([random.getrandbits(16) for _ in range(256)])
for _ in range(256)]
polys = MLE(ring=ring, variables=[MLE_Variable(f"x{i}") for i in range(8)],
evaluations=evaluations)
proving, verifying = iop(), iop() # the prover's and the verifier's side
v, _ = ring_basefold.scheme.commit(polys, prover=proving.prover)
claim = Statement(Relation_Range(2**16), oracles=[v])
proof = proving.prove(claim)
print(verifying.verify(claim, proof)) # True: the verifier sees only v and the proof