Skip to content

feat: KLEE symbolic driver and absolution_add_symbolic_target() - #30

Open
kajaaz wants to merge 1 commit into
feat/zero-lists-domain-overridesfrom
feat/klee-symbolic-driver
Open

kajaaz wants to merge 1 commit into
feat/zero-lists-domain-overridesfrom
feat/klee-symbolic-driver

Conversation

@kajaaz

@kajaaz kajaaz commented Nov 12, 2026

Copy link
Copy Markdown

The plan

This PR is 3 of 8. Together they let Ledger fuzz its device apps on an Absolution state model, with libFuzzer and with KLEE, through one harness.

Absolution (this repo)        Ledger SDK              Ledger apps
1 A1 build fixes
2 A2 model tuning
3 A3 KLEE driver  <- this PR
  tag v1.2.0 -------------->  4 S1 LedgerHarness ---> 6, 7, 8: one PR per app
                              5 S2 KLEE lane
# PR Adds
1 A1, #27 build fixes: a rebuild no longer recompiles unchanged sources, release builds keep the invariant check, a parser leak
2 A2, #28 model tuning in the same run: zero lists, domain overrides, --no-post-check, harness-only sources
3 A3, this PR --symbolic klee: a KLEE driver on the fuzzer's input layout, so a KLEE test replays on the fuzzer
4 S1 SDK: an app lists its APDU commands in a manifest, and the SDK builds its fuzzers, seeds and tests on Absolution v1.2.0
5 S2 SDK: an opt-in KLEE lane on the same harness, seeded from the fuzz corpus
6 to 8 apps three apps move their fuzzers to the SDK harness

A1 to A3 are stacked and released together as v1.2.0. The SDK and app PRs are in internal Ledger repositories.

This PR is the third and last Absolution step, stacked on A2 (#28): its base is the A2 branch, so the diff shows only this step. Once it is merged, the v1.2.0 tag is the release the SDK pins (step 4), and the SDK's KLEE lane (step 5) builds this driver for each app.

What

--symbolic klee emits a symbolic-execution driver instead of a libFuzzer harness, and absolution_add_symbolic_target() builds it into one LLVM bitcode module for KLEE.

absolution_sym_input[]   symbolic, GLOBALS_SIZE + APDU_SIZE bytes
     |  absolution_sym_prepare()    weak hook, no-op by default
     |  sample_invariant()          prefix -> globals, within the domains
     v
entry(apdu, APDU_SIZE)              your harness; KLEE forks on symbolic branches
     v
check_invariant()                   unless --no-post-check

The buffer has the fuzzer's input layout, so a KLEE test case replays on the libFuzzer build unchanged. Built without -DABSOLUTION_KLEE, the driver reads the buffer from stdin.

Changes

  • src/cgen/emit.zig, src/cgen/ir.zig: the symbolic driver; src/main.zig: -S/--symbolic klee, -a/--apdu-size, -P/--no-symbolic-pointers.
  • src/type_flatten.zig: pointer leaves are flagged (.is_pointer), so -P can leave them NULL; the test goldens gain that field.
  • CMake: AbsolutionSymbolic.cmake (ENGINE accepts klee), BuildSymbolicBitcode.cmake (bitcode, IR-level renames, llvm-link), RunAbsolutionSymbolic.cmake, SummarizeKleeFindings.cmake and cmake/symbolic/ (KLEE job runner, allocator and memcpy models, UBSan stubs).
  • example/protocol_parser: a KLEE target that finds the planted overflow.
  • USAGE.md: "Symbolic execution (KLEE)".

The Engine enum has one value, so other engines can be added later.

Tests

zig build test, zig build -Doptimize=ReleaseFast and zig run scripts/integration.zig pass. example/protocol_parser: sym_decode builds with clang 13 and sym_decode_klee reports the planted out-of-bounds memcpy.

@kajaaz
kajaaz requested a review from 0pendev as a code owner November 12, 2026 16:43
@kajaaz
kajaaz changed the base branch from main to feat/zero-lists-domain-overrides November 12, 2026 16:44
@kajaaz
kajaaz added this pull request to stack #29 November 12, 2026 16:44

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