The Language of Approximation
Fundamentals Deep Dive • PA Bootcamp
An abstract domain maps infinite concrete values to finite abstract representations — trading precision for computability.
Every abstract domain in the bootcamp implements this OCaml module type — 7 operations that define the domain's behavior.
The simplest useful domain — tracks whether a value is negative, zero, or positive.
x = 1 and x = 1000000 — both are just Pos.
x * x is always ≥ 0, but sign analysis computes Pos * Pos = Pos, Neg * Neg = Pos, Pos * Neg = Neg — so ⊤ * ⊤ = ⊤. It can't prove non-negativity!
How arithmetic works in the sign world. Step through to see each operation.
| × | Neg | Zero | Pos | ⊤ |
|---|---|---|---|---|
| Neg | ? | ? | ? | ? |
| Zero | ? | ? | ? | ? |
| Pos | ? | ? | ? | ? |
| ⊤ | ? | ? | ? | ? |
Tracks whether a variable always holds the same constant value — if so, the compiler can fold it.
x = 3; y = x + 2; → analysis determines y = Const(5) → compiler replaces with y = 5Tracks a range [lo, hi] of possible values — more precise than sign, but infinite height.
How to add, subtract, multiply, and divide intervals — the transfer functions for the interval domain.
Given the concrete set {-4, 0, 3, 7}, predict the abstraction in each domain.
A simple but useful domain — tracks whether a value is even or odd. Great for array indexing and alignment checks.
2 * x is always Even regardless of x — parity can prove this but sign domain cannot. Each domain has unique strengths!
Tracks whether data originates from untrusted sources — essential for finding injection vulnerabilities.
The same program analyzed with three different domains — watch how precision differs.
Run two domains simultaneously and let them share information. The combination catches things neither alone can.
x after x = 2*y + 1 where y ∈ PosWidening forces convergence by overshooting. Narrowing recovers precision by tightening back.
x = 0; while(*) x = x + 1;
Follow the 5-step recipe to build a custom abstract domain for any property you want to track.
Each domain implementation has a bug. Identify what's wrong.
All domains so far track one variable at a time. What happens when the property you need involves two variables?
i < n at line 3 to guarantee no out-of-bounds access. Click a view to see what intervals can (and can't) tell us.
Octagons track constraints of the form ±x ± y ≤ c for every pair of variables. Step through a loop analysis.
Polyhedra track arbitrary linear constraints: a₁x₁ + a₂x₂ + ... + aₙxₙ ≤ c. Toggle to compare all three.
y = 2*x + 1 where x ∈ [0,5].Choosing the right domain is a precision/cost trade-off. Follow this decision tree.
Every module uses abstract domains. Here's the map of where each domain appears.
For each scenario, pick the most appropriate abstract domain. Consider precision needs and cost.
x * 2 with x << 1 when it can prove x is always the same constant.request.params can reach db.query() without passing through sanitize().i is always between 0 and arr.length - 1 inside a loop.i < n holds at a specific point, where both i and n are variables modified in a loop.Given this program, predict the abstract state at each point in the sign domain.
For each situation, choose the correct design decision for your abstract domain.