Skip to content

[AUTOMATED] Add Tier S to kuna-verify: prove a scoped equivalence with z3 - #2114

Open
sjkim1127 wants to merge 8 commits into
Noelo-Lab:mainfrom
sjkim1127:diffverify-proof
Open

sjkim1127 wants to merge 8 commits into
Noelo-Lab:mainfrom
sjkim1127:diffverify-proof

Conversation

@sjkim1127

@sjkim1127 sjkim1127 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

A follow-up to the #1830 split, on top of #2113 (whose commits it carries; review from 59a35774c). Random runs and concolic inputs show agreement on the inputs they try; prove asks z3 whether kuna's final IR and the machine's raw p-code can differ on any input, within a declared scope.

# fixture.elf as in #2113
set -- $(llvm-nm --format=posix --print-size fixture.elf | awk '$1 == "add" { print $3, $4 }')
ret=$(printf '0x%x' "$((0x$1 + 0x$2 - 1))")
K=decompiler/target/release/kuna-verify
$K prove fixture.elf add --stop-at "$ret" --input RDI --input RSI --return RAX:8 --sleighpath specs | jq .classification
$K prove fixture.elf add --stop-at "$ret" --input RDI --input RSI --return RAX:8 --sleighpath specs --opcode-mutant 0 | jq .classification
"MODEL_EQUIVALENCE"
"COUNTEREXAMPLE"

The second turns the IR's INT_ADD at 0x201050 into INT_SUB; z3 finds inputs where they differ, and proof_replay.py runs them on both interpreters and Unicorn.

  • prove encodes a straight-line interval, or a whole function with memory and declared indirect branches, as SMT-LIB bit-vectors on both sides and asks z3 whether the selected return can differ. Loops are compared up to --loop-bound, or by --induct. What is outside the model (calls, floating point) is INCONCLUSIVE, never equivalence.
  • Every report archives the ELF and spec digests, the solver version and both queries, so a result can be checked again (proof_certificate.py, with Ethos for archived refutations).
  • rv64-terms and sail_rv64.py check RV64 integer ops against the Sail model, independently of SLEIGH.

Tests: the symbolic encoder (45 unit tests), and end to end through prove, oracle-case and the replay scripts on the fixture, with z3 and clang (test_function_oracle_integration.py). Guides: translation-validation.md, symbolic-memory.md, formal-rv64.md, proof-certificates.md.

🤖 Generated with Claude Code

Model: anthropic/claude-opus-5-5

sjkim1127 and others added 8 commits December 5, 2026 09:48
A rule cap that counts rule applications per thread and can stop one rule
after its first n, checked once per rule attempt in ActionPool::process_op
and inert unless armed; Funcdata::vararg_folded, the register-save stores the
varargsave fold removes; kuna_narrowext::rules_for for a given mode;
IfaceStatus::last_command; and interface::quote_filename, moved from kuna-cli
so other callers can reach it. With every hook unset kuna's output is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…inst the machine code

kuna-verify runs a function's SLEIGH p-code and kuna's final Funcdata from
the same random machine state, and compares the calls each makes and their
arguments, the memory written outside the frame and the value returned.
`check` runs it on functions of a binary, `corpus` on every decompile the
datatest corpus makes, and `mutate` plants faults on kuna's side to measure
how many the check catches. Slices C1, C2 and C4 of the diffverify proposal.

Rule localization, concolic inputs, single-instruction (Tier L) and
symbolic (Tier S) checks, the function oracle, the calling-convention model
check and the CI baseline come in their own changes. Every corpus verdict
matches the unsplit tool's on the same base.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… which a function differs

For a function kuna-verify finds DIFFERS, `localize` holds one rule back at a
time through the rule cap and bisects how many of its applications are
allowed, so that with k - 1 the function agrees over every run and with k it
differs. It reports those applications by rule and address, under the same
contract and options as `check`. Slice C3 of the diffverify proposal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d baseline

`make verify-corpus` checks every function tests/datatests and tests/stages
decompile and compares each verdict with docs/baseline-verify.json; a
non-gating step of the parity-gates job runs it and uploads the verdicts.

A function that agreed (or a new one) and now differs, or a file that can
no longer be checked, is a regression. A function that agreed and is now
UNKNOWN, or agrees on at most half the runs it agreed on, is lost coverage.
A DIFFERS is recorded with the place it first differs, without values, so a
difference that moves is listed as a notice instead of passing unseen or
failing the run.

Baseline recorded on this base: 5,837 functions, 5,073 agree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After the random runs, the machine side records each run's path as
expressions over the input bytes. `--concolic N` negates one recorded branch
condition at a time and asks z3 (a subprocess speaking SMT-LIB 2) for an
input that takes the other way, up to N queries per function. z3 only picks
inputs; the verdict still comes from running both sides. With no z3, the
report says no concolic run was made. Slice C5 of the diffverify proposal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st Unicorn

`kuna-verify step` runs one instruction's SLEIGH p-code from random register
values and prints each case as JSON; `scripts/diffverify/tier_l.py` runs the
same cases under Unicorn and compares registers, flags, memory writes and the
next address. Both sides of the Tier C check share the SLEIGH specs and the
p-code op semantics, so this is the check that can see an error in either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ase)

`kuna-verify oracle-case` runs one explicit x86-64 case (named input
registers and memory bytes, external entries that stop the run) on the
function's raw p-code and on kuna's final IR, and prints both observations as
JSON with the ELF and spec digests. `scripts/diffverify/function_oracle.py`
runs the same case in Unicorn and compares the three. `make
test-diffverify-tools` runs the scripts' tests, as a CI step that installs
Unicorn, z3 and clang.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h z3

`kuna-verify prove` encodes a raw p-code interval or a whole function and
kuna's final IR for it as SMT-LIB bit-vectors, with symbolic memory, declared
indirect branches and bounded or inductive loops, and asks z3 whether the
selected return can differ. A model is a counterexample that
`proof_replay.py` runs on both interpreters and Unicorn; anything outside the
model is INCONCLUSIVE. Reports archive the ELF and spec digests and both
queries for `proof_certificate.py`. `rv64-terms` and `sail_rv64.py` check RV64
integer ops against the Sail model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant