Mental model
Zero-knowledge machine learning compiles a precisely specified model into arithmetic constraints, then proves that a witness satisfies those constraints for declared public inputs and outputs. The proof can hide selected data or weights, but it certifies only the compiled circuit's computation; it does not establish that the model is accurate, fair, current, or useful.
Learning outcomes
- Explain how fixed-point quantization turns neural operations into finite-field constraints.
- Separate proof validity from model quality, data provenance, and float-model equivalence.
- Design public inputs that bind a proof to a model revision, input commitment, output, and request.
- Estimate the cost added by range checks, nonlinear operations, proving, and verification.
Theory
Neural networks normally execute floating-point operations. A proof system works over a finite field, so a compiler chooses an integer encoding and a circuit that constrains every operation. For scale S, a real value x can be represented as the signed integer x_q = round(Sx). Multiplying two encoded values produces scale S²; the circuit must specify how it rescales, rounds, clips, and handles overflow before the next layer. The exact rules are part of the model, not an implementation detail that can be changed after setup.
The EuroSys ZKML system paper shows why compiler choices matter: equivalent neural operations can map to different constraint layouts and proving costs. EZKL exports a graph such as ONNX, derives settings, compiles a circuit, creates keys, generates a witness and proof, and verifies the result. Halo2 supplies a proving system in that toolchain; its proof-system book describes the circuit and polynomial machinery underneath.
A useful mental model is that the prover knows a witness w and public statement x, while the circuit checks a relation R(x,w) = 1. For inference, x might contain a model commitment, an input commitment, and a public score or class. The witness can contain private inputs, intermediate activations, and possibly private weights. A verifier accepts only if the proof matches the circuit and public instances. If the public inputs omit the model version or output interpretation, a valid proof can be attached to the wrong artifact or schema.
Quantization requires special care. A field element is computed modulo a prime p, so signed integers need an agreed encoding and range constraints that prevent wraparound from masquerading as a small negative number. Lookup tables or bit decompositions can constrain ranges and nonlinear activations. ReLU, comparisons, division, and softmax are often more expensive than linear layers because they need extra constraints or lookups. A proof of a quantized result means “this circuit produced this encoded result,” not “the original floating-point model produced the identical value.”
Mechanism and implementation boundary
Treat model export, quantization settings, circuit compilation, and verification-key generation as one versioned release. A model digest alone may not identify the proof relation: the ONNX graph, scale, rounding behavior, visibility of tensors, field, lookup tables, and compiler version can all change the circuit. Store a circuit or verification-key digest with the model commitment and make the verifier select the matching key rather than a caller-supplied key.
The proving pipeline has distinct artifacts. The model and settings define the circuit. A witness generator evaluates the encoded model and records intermediate values. The prover combines that witness with a proving key to construct a proof. The verifier consumes the proof and a fixed ordered list of public instances. Production code should canonicalize input serialization, bind an input commitment and nonce into those instances, and reject stale model IDs. A successful proof must not become an unrestricted oracle response: keep authorization, rate limits, output policy, and provenance checks outside the arithmetic relation where they belong.
Worked example
Consider a two-feature linear score with weights 0.30 and -0.80, bias 0.10, and inputs 1.20 and 0.50. At scale S = 100, the encoded inputs are 120 and 50, the encoded weights are 30 and -80, and the encoded bias is 10. The integer accumulator is 120 × 30 + 50 × (-80) + 100 × 10 = 600. Since this accumulator has scale S² = 10,000, it represents a score of 0.06 before any model-specific clipping or activation.
The circuit should constrain that exact accumulator and the declared output. If the classification decision is whether the score is nonnegative, the circuit must constrain the sign comparison too; merely revealing 600 and letting an untrusted service label it would leave the label outside the proof. A neighboring class score of 0.04 leaves a margin of only 0.02, so a quantization change that moves either logit by more than that margin can flip the class even while both proofs remain valid. Evaluate class agreement and confidence margins against the source floating-point model on representative inputs before shipping.
Quantitative model
For one quantized linear layer with d inputs, the integer accumulator can be written as:
Here x_{i,q}, w_{i,q}, and b_q are values rounded at scale S; a_q is the circuit's integer accumulator and is the corresponding real-valued approximation. Range constraints must keep intermediate integers within the chosen signed bound and within an unambiguous field encoding. For a network, the compiler adds constraints for each layer plus the operations that rescale or compare outputs.
As a cost estimate, a 64-feature sum has 63 additions. If each private input is constrained to 16 bits by bit decomposition, it needs about 64 × 16 = 1,024 Booleanity checks in addition to the additions, before commitment, packing, and protocol-specific overhead. This example is intentionally small; matrix products, range checks, activation lookups, and transcript hashing dominate real inference circuits. Measure the compiled constraint count, witness-generation time, peak prover memory, proof size, and verifier gas for each model release.
Trade-offs
Proving is usually much more expensive than ordinary inference because the prover must build and process a witness for every constrained operation. Verification can be substantially cheaper, but its cost depends on the proof system, public-input count, curve, and deployment target. A proof generated off-chain and checked in a browser has different latency and resource limits from one verified inside an EVM transaction. Benchmark the complete path, including model compilation, witness generation, proving, serialization, submission, and finality.
Making weights or inputs private can protect trade secrets or user data, but privacy follows the circuit's public-input design and the proof system's assumptions. A public score can still leak information through repeated queries or a narrow decision threshold. Conversely, a private output cannot be acted on by a contract without exposing some result or commitment. A verifier also proves neither the source of a private input nor that a data provider supplied a truthful value unless the statement binds it to a trusted signature, commitment, or authenticated data source.
Failure modes and misconceptions
- Float and circuit disagreement: different rounding or overflow rules shift logits. Pin the scale and rounding policy, then compare encoded outputs with the reference model on edge cases near decision boundaries.
- Unbound model revision: a valid proof for one verification key is accepted as if it used a newer model. Bind a model or circuit digest into the public instances and registry.
- Field wraparound: an accumulator exceeds its intended signed range and becomes a different field element. Add range checks and test maximum and minimum inputs, not just typical examples.
- Incomplete statement: the circuit proves a score but the service assumes it proves a class, threshold, or approved dataset. Specify every public input and output schema explicitly.
- Privacy leakage: a proof hides the witness but the public output, query pattern, or repeated threshold results reveal sensitive information. Threat-model the full interface and limit repeated queries where needed.
- Constraint regression: a compiler change makes proving time or memory exceed the service budget. Track circuit size and end-to-end p95 proving latency as release metrics.
Decision scenario
A new model matches the reference model on average, but its quantized top-two margin falls below 0.01 for 3% of evaluation inputs. The proof verifier accepts every generated proof and the median proving time stays within budget. Keep the new circuit in a parallel release, measure class disagreement and false decisions on those low-margin inputs, and decide whether to increase precision, alter the decision threshold, or abstain on ambiguous cases. A valid proof cannot compensate for an unstable decision rule; promote only after the model, quantization policy, public-output contract, and privacy review all match the intended use.
Implementation pattern
This small integer evaluator is a deterministic witness oracle for one quantized linear layer. A production prover must compile the same arithmetic, range, and rounding rules into its circuit; this Python function alone does not create a cryptographic proof.
pythonfrom hashlib import sha256SCALE = 100MAX_ABS_ACCUMULATOR = 2**31 - 1def encode(values: list[float]) -> list[int]:return [round(value * SCALE) for value in values]def input_commitment(values: list[float]) -> str:packed = ",".join(str(value) for value in encode(values)).encode()return sha256(b"zkml-input-v1:" + packed).hexdigest()def quantized_logit(inputs: list[float], weights: list[float], bias: float) -> int:if len(inputs) != len(weights):raise ValueError("input and weight dimensions differ")x_q, w_q, b_q = encode(inputs), encode(weights), encode([bias])[0]accumulator = sum(x * w for x, w in zip(x_q, w_q, strict=True)) + SCALE * b_qif abs(accumulator) > MAX_ABS_ACCUMULATOR:raise OverflowError("accumulator exceeds the circuit's signed range")return accumulatorfeatures, weights, bias = [1.20, 0.50], [0.30, -0.80], 0.10commitment = input_commitment(features)logit_q = quantized_logit(features, weights, bias)print({"input_commitment": commitment, "logit_q_scale_squared": logit_q})