Skip to content

[AUTOMATED] Add kuna-verify, a differential check of the final IR against the machine code - #2108

Open
sjkim1127 wants to merge 2 commits into
Noelo-Lab:mainfrom
sjkim1127:diffverify-core
Open

sjkim1127 wants to merge 2 commits into
Noelo-Lab:mainfrom
sjkim1127:diffverify-core

Conversation

@sjkim1127

@sjkim1127 sjkim1127 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

The second of the pieces #1830 is split into, on top of #2107 (whose commit it carries; review from 78ae1ba67). It adds kuna-verify, a dev-only tool that answers one question about a decompiled function: does kuna's final IR compute what the machine code computes? Nothing it does changes kuna's output, and the release kuna binary does not link it.

make binaries specs
(cd decompiler && cargo build --release -p kuna-verify)
decompiler/target/release/kuna-verify corpus tests/stages/kuna-narrowext.xml
| kuna-narrowext | csc | DIFFERS | 2.12 |
| | | `input    k=0x00000040 (a0)` | |
| | | `machine  a0 = 0xffffffffffffff94` | |
| | | `kuna     int8 csc(int4 k) = 0x0000000000000294` | |
...
| kuna-narrowext | csc | AGREES(256) | 2.77 |

The first pass of that stage test turns narrowext off and brings the bug back; the check names the input and both results without anyone reading the C. The default pass agrees.

  • It runs the function's SLEIGH p-code and kuna's final Funcdata from the same random state, and compares each call (target, arguments, the memory a callee can read), the memory written outside the frame and the return value, under the calling convention and, with --contract FILE.c, the real C return type.
  • A difference kuna makes on purpose behind an option is DIVERGES(id), and one the check cannot decide is UNKNOWN(reason), never AGREES.
  • check takes functions of a binary, corpus every decompile a datatest script makes (one worker process per file), mutate plants faults on kuna's side and reports how many are caught (74–76% on the corpus, ls and find).
  • Rule localization, concolic inputs, Tier L/S, the function oracle, the cspec check and a CI baseline are later pieces. docs/features/diffverify/README.md is the guide.

Tests: 92 in the crate (cargo test -p kuna-verify), each pinning a verdict the check once got wrong. Every verdict over tests/datatests and tests/stages (5,707 functions) is the same as the unsplit tool's on the same base.

🤖 Generated with Claude Code

Model: anthropic/claude-opus-5-5

sjkim1127 and others added 2 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>

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