CodeMirror is a web-based application that helps analyze the correctness and semantic equivalence of programs written in a custom mini-language. Built using React, the tool leverages formal methods by converting code into Static Single Assignment (SSA) form and generating SMT-LIB constraints to verify them using the Z3 SMT solver.
-
โ Mini-language Parser (PEG.js-based):
- Variable assignments using
:=or= - Control structures:
if,while,for - Arrays and array indexing
- Quantified assertions (e.g.,
forall,exists)
- Variable assignments using
-
๐ง SSA Transformation:
- Variable versioning
- Phi node generation for branching
- Expression rewriting and concrete value tracking
-
๐ Loop Unrolling:
- Configurable depth
- Static termination detection
- Transforms loops into nested
ifblocks
-
๐งฉ SMT-LIB2 Constraint Generator:
- QF_ALIA logic (Quantifier-Free Arrays and Linear Integer Arithmetic)
- Full SSA-to-SMT conversion
- Assertion and equivalence verification
-
๐ Graph Visualization (React Flow):
- Control flow graph (CFG)
- SSA control flow graph
- Data flow graph for variable dependencies
-
๐ Verification Modes:
- Program correctness (via
assert) - Semantic equivalence of two programs
- Program correctness (via
-
๐ Z3 Solver Integration:
- Runs Z3 locally in WebAssembly (in-browser)
- Option to export SMT to FM Playground Z3
- React (UI framework)
- PEG.js (parser generator for mini-language)
- Tailwind CSS (UI styling)
- Z3 SMT Solver (WebAssembly & external link)
- React Flow (graph rendering)
- JavaScript (SSA & SMT logic)
Below are some example programs you can run in the tool. You can paste them directly into the editor.
for (i := 0; i < n; i := i + 1) { for (j := 0; j < n - i - 1; j := j + 1) { if (arr[j] > arr[j+1]) { temp := arr[j]; arr[j] := arr[j+1]; arr[j+1] := temp; } } } assert(for (i in range (n)):arr[i] < arr[i+1]);
for (i := 1; i < n; i := i + 1) { key := arr[i]; j := i - 1; while (j >= 0 && arr[j] > key) { arr[j + 1] := arr[j]; j := j - 1; } arr[j + 1] := key; } assert(for (i in range (n-1)): arr[i] <= arr[i+1]);
for (i := 0; i < n; i := i + 1) { for (j := 0; j < n - i - 1; j := j + 1) { if (arr[j] > arr[j+1]) { temp := arr[j]; arr[j] := arr[j+1]; arr[j+1] := temp; } } } assert(for (i in range (n-1)):arr[i] < arr[i+1]);
x := 0; while (x < 4) { x := x + 1; } assert(x == 4);
x := 3; if (x < 5) { y := x + 1; } else { y := x - 1; } assert(y > 0);
x := 0; while (x < 4) { x := x + 1; } assert(x == 4);
x := 0; for (i := 0; i < 4; i := i + 1) { x := x + 1; } assert(x == 4);
n := 10;
sum := 0;
i := 1;
while (i <= n) {
sum := sum + i;
i := i + 1;
}
assert(sum >= 0);
n := 10;
sum := 0;
if (n >= 0) {
sum := n * (n + 1) / 2;
}
assert(sum >= 0);
- โ Does not model integer overflows โ assumes unbounded integers.
- ๐งฎ Limited support for integers and integer arrays only.
- โ โ Quantifier-heavy assertions may be difficult for Z3 to handle efficiently.
- ๐ข Performance may degrade for large or deeply nested programs due to SSA and SMT complexity.
- ๐ง Add symbolic execution and counterexample generation for better analysis.
- ๐งฌ Support functions, recursion, and a richer type system (e.g., booleans, strings).
- ๐งฉ Implement modular and parallel verification techniques for better scalability.
- ๐ฃ Improve error reporting and counterexample display for easier debugging.
- ๐งโ๐ซ Integrate interactive proof assistance when automatic verification fails.
Made by Ayesha ๐งช

















