Proving & Trust Reports
Clever's verification philosophy is: a human reads the specification; the machine checks the rest — and every build reports exactly what was proven versus assumed.
Laws Next to Code (law)
A law is a universally quantified boolean claim written in the same file as the functions it specifies. Preconditions use short-circuiting || (!pre || claim), so neither side is required to avoid traps outside the precondition.
Clever has two proof engines:
- Clever's own kernel (
Clever/Kernel/):proof by bv: bit-blasts word/boolean claims, invokes a SAT solver, and verifies the LRAT certificate inside Clever's kernel. Fast for bitwise identities, carry/borrow arithmetic, masking, and 64-bit reductions.- Clever proof scripts (
simp,decide,cases,induction,rewrite,use,exact): checked by Clever's data kernel over enums, recursive functions,&mutstate passing, loops, arrays, andBytes.
- Lean 4 escape hatch (
proof by lean:):- Embeds verbatim Lean 4 tactic text checked against the generated Lean model (
clever lean). Ideal for wide nonlinear arithmetic (e.g., 128-bit reductions modp),omega, or multi-pass loop simulations.
- Embeds verbatim Lean 4 tactic text checked against the generated Lean model (
Example: Bit-Vector Kernel (proof by bv)
fun ch(x: U32, y: U32, z: U32): U32 = z ^ (x & (y ^ z))
fun specCh(x: U32, y: U32, z: U32): U32 = (x & y) ^ (~x & z)
fun maj(x: U32, y: U32, z: U32): U32 = (x & y) | (z & (x | y))
fun specMaj(x: U32, y: U32, z: U32): U32 = (x & y) ^ (x & z) ^ (y & z)
law ch_equiv(x: U32, y: U32, z: U32): ch(x, y, z) == specCh(x, y, z)
proof by bv
law maj_equiv(x: U32, y: U32, z: U32): maj(x, y, z) == specMaj(x, y, z)
proof by bvExample: Data Kernel (Structural Induction & decide)
enum List8 {
Nil,
Cons(val head: U8, val tail: List8)
}
fun len(xs: &List8): U64 = when (xs) {
List8.Nil -> 0u64
is List8.Cons -> 1u64 +% len(xs.tail)
}
fun appendList(a: &List8, b: &List8): List8 = when (a) {
List8.Nil -> b.share()
is List8.Cons -> List8.Cons(a.head, appendList(a.tail, b))
}
law len_example(): len(List8.Cons(1u8, List8.Cons(2u8, List8.Nil))) == 2u64
proof by decide
law append_len(a: List8, b: List8): len(appendList(a, b)) == len(a) +% len(b)
proof by
induction a
simpExample: Lean 4 Proof (proof by lean:)
When a claim goes beyond bit-blasting or built-in kernel tactics, drop into Lean 4 tactics right inside the .clv file. clever prove checks the proof with Lean's kernel and audits its axioms (only propext, Classical.choice, Quot.sound are permitted — no sorryAx or native bv_decide axioms):
fun double(x: U64): U64 = x +% x
law double_is_mul2(x: U64): double(x) == x *% 2u64
proof by lean:
intro x
unfold double
have hx := x.toNat_lt
simp only [beq_iff_eq, UInt64.eq_iff_toBitVec_eq, ← BitVec.toNat_inj,
UInt64.toNat_toBitVec, UInt64.toNat_add, UInt64.toNat_mul, UInt64.reduceToNat]
omega(Inspect the generated Lean goal for any file with clever lean F.clv -o Model.lean.)
Contracts (requires / ensures), Loop invariants & @noabort
Proofs in Clever are not just documentation — proofs pay rent in speed.
requires Pstates a caller precondition. Inside the body, the optimizer assumesPto eliminate redundant overflow and bounds checks.ensures Qstates a postcondition onresult. Once proven (and passed via--use-proofs manifest.json), callers assumeQautomatically, discharging downstreamrequiresand bounds checks across function boundaries.invariant Ion awhileloop states an inductive invariant proven by the kernel; with--use-proofs, it eliminates bounds checks inside the loop body (used bylib/std/collections.clv'slowerBoundandupperBound).@noabortasserts that zero runtime trap sites survive optimization (modulo out-of-memory resource traps). Enforce it in CI withclever c F.clv --require-noabort. Note that anexport funwithrequireskeeps a boundary precondition check for untrusted callers, so@noabortexports validate their inputs explicitly.
const LIMIT: U64 = 1_000_000u64
fun boundedScale(x: U64): U64
requires x < LIMIT
ensures result < LIMIT * 10u64
proof by bv
{
x * 10u64
}
@noabort
export fun safeScale(x: U64): U64 {
if (x < LIMIT) { boundedScale(x) } else { LIMIT * 10u64 }
}
export fun searchBound(b: &Buf<U64>, x: U64): U64 {
var base = 0u64
var size = b.len
while (size > 1u64)
invariant (base <= b.len && size <= b.len - base)
decreases (size)
{
val half = size / 2u64
val mid = base +% half
if (b[mid] < x) { base = mid }
size = size - half
}
if (size == 1u64 && b[base] < x) { base + 1u64 } else { base }
}Use clever checks F.clv to see every trap site that survived optimization and why it was kept:
clever checks F.clv --target c
clever checks F.clv --input # only trap sites reachable from untrusted export inputsTesting & Auditing Law Quality
A proof of a vacuous law (false || ...) proves nothing. Clever ships built-in law-quality tools:
# Property-test every law (especially laws without a `proof by` yet)
clever test F.clv --n 1000
# Plain-English explanation of what each law states
clever laws F.clv --explain
# Flag laws whose precondition is rarely or never satisfied
clever laws F.clv --vacuity
# Search for counterexamples to broken laws
clever laws F.clv --cex
# Mutation-test specifications: plant bugs in code and verify laws catch them
clever spec-mutate F.clv
# Differential equivalence check between two functions (e.g. fast vs spec)
clever equiv F.clv fastFn specFnCross-check Clever kernel laws against Lean's own kernel as a second opinion:
clever prove F.clv --via leanTrust Reports (clever trust) & Semantic Lockfiles (clever.lock)
Per-Build Trust Reports
clever prove F.clv -o F.proofs.json
clever trust F.clv --target c --use-proofs F.proofs.json
clever c F.clv -o out.c --use-proofs F.proofs.json --trust-report out.trust.jsonEvery report itemizes:
build/target— Core content hash (clever hash), compiler binary SHA-256, route,@limitsproven— Proven laws (by kernel vs. Lean), checks removed by proof, discharged preconditions,@noabortfunctions, proven legalization lemmaschecked— Remaining runtime trap sites by reason, validated instruction-scheduling regions, translation-validated optimizer functions (--tv=on)tested— Unproven compiler passes (differentially tested across interp, C, Wasm, JS, Lean)assumed— Unproven laws,externcontracts, capability refinements,@hwintrinsics,@nativealternatives,unsafe, host FFI obligationstrusted— Lean kernel, Clever kernel, C compiler + version/SHA-256, linker, runtime, CPU
Dependency Trust-Surface Pinning (clever.lock)
In a multi-package build (clever.toml), clever lock records the reachable trust surface of every dependency: definition code/spec Merkle hashes, signatures, contracts, laws and their proven/tested status, externs, capabilities, intrinsics, unsafe uses, and toolchain hashes.
clever fetch # fetches dependencies into content-addressed store (only network step)
clever lock # prints diff against clever.lock
clever lock --accept # writes/updates clever.lock after review
clever build # FAILS if any dependency's trust surface differs from clever.lock
clever update dep --to ../dep-v2 --review --accept # diffs surface & re-proves dep's laws locally