Skip to content

[AUTOMATED] Check Tier L on targets Unicorn does not run, with objdump, rasm2 and radare2's ESIL - #2116

Draft
sjkim1127 wants to merge 10 commits into
Noelo-Lab:mainfrom
sjkim1127:diffverify-tierl-other
Draft

sjkim1127 wants to merge 10 commits into
Noelo-Lab:mainfrom
sjkim1127:diffverify-tierl-other

Conversation

@sjkim1127

@sjkim1127 sjkim1127 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

A follow-up to the #1830 split, on top of #2115 (whose commits it carries; review from 50668c9ae). Tier L checks the SLEIGH specs against Unicorn, which runs only QEMU's targets. This adds the same check for targets Unicorn does not run (AVR, MSP430, Z80, the 6502 and more), against tools that do not use SLEIGH: GNU objdump and radare2's rasm2 for decoding, and radare2's ESIL for running one instruction.

make
python3 scripts/diffverify/tier_l_decode.py tests/stages/kuna-bejoin-avr.xml
python3 scripts/diffverify/tier_l_esil.py avr8 tests/stages/gh1951-avr-rcallwrap.xml
objdump: avr8 instructions 7  same 7  mnemonic 0  length 0  kuna-only 0  tool-only 0
rasm2: avr8 instructions 7  same 7  mnemonic 0  length 0  kuna-only 0  tool-only 0
forms 2  same 1  differs 1  skipped 0
DIFFERS 0x0 rcall 0x100e                     writes: kuna-only [] radare2-only [] differing ['0x5b9f']

The rcall difference is a spec error. The AVR spec's pushPC stores a call's return address little-endian, but the part pushes it big-endian (QEMU's gen_push_ret uses MO_BEUW). A call and its return still agree with each other, so decompiled control flow is unaffected. Code that reads a return address off the stack sees its bytes swapped.

  • kuna-verify step now takes a datatest XML, so any language with a stage test can be swept. --decode lists each instruction of the sweep without running it. On AVR, whose general registers live at data addresses 0-31, step sets and reads them there and does not count them as memory read or written.
  • Both drivers compare only the bytes a datatest's <bytechunk>s hold. The XML loader pads each chunk with up to 512 zero bytes, as Ghidra's does, and those would otherwise decode as nops.
  • radare2 6 runs a script only from a .r2 file, and takes rasm2's start address as -s (-o now names an output file). A radare2 that runs no case is an error, not zero results. radare2's AVR CPU is pinned to ATmega8, a part with a 16-bit program counter like kuna's avr8; its default pushes three-byte return addresses.

Tests: step --decode and the memory-mapped AVR registers in Rust, and the comparisons on canned tool output in Python. End-to-end runs on kuna-bejoin-avr with objdump, rasm2 and ESIL need those tools and skip without them. On the AVR, MSP430 and Z80 stage images every instruction (11, 2 and 30) decodes as both tools decode it.

🤖 Generated with Claude Code

Model: anthropic/claude-opus-5-5

@sjkim1127
sjkim1127 marked this pull request as draft December 3, 2026 03:55
sjkim1127 and others added 10 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>
`kuna-verify abi-model` prints where kuna's model puts a declared
prototype's parameters and return value, and what it says a call preserves,
kills and pops. `scripts/diffverify/cspec_check.py` compiles probes with
clang for six targets, runs them under Unicorn, finds where the code reads
each value by changing one register or stack slot at a time, and compares.
Gaps found are listed with their causes in cspec_known.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…p, rasm2 and radare2's ESIL

`kuna-verify step` takes a datatest XML, so any SLEIGH language with a stage
test can be swept, and `--decode` lists each instruction of the sweep without
running it. On AVR, whose general registers live at data addresses 0-31, it
sets and reads them there and does not count them as memory traffic.

tier_l_decode.py compares the decode with GNU objdump and rasm2;
tier_l_esil.py runs the cases through radare2's ESIL. Both compare only the
bytes a datatest's chunks hold, not the loader's zero padding. radare2 6 runs
a script only from a `.r2` file and takes rasm2's start address as `-s`, and
its AVR CPU is pinned to a 16-bit-PC part.

On the AVR, MSP430 and Z80 stage images every instruction decodes as both
tools decode it. ESIL finds one AVR difference: the spec pushes a call's
return address little-endian, where the part (QEMU's gen_push_ret) pushes it
big-endian.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sjkim1127
sjkim1127 force-pushed the diffverify-tierl-other branch from b41631b to 50668c9 Compare December 5, 2026 01:36

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