Skip to content

[PROPOSAL] angr-tr-build-spec-list-ea32be: SAILR condition folding / goto reduction (S7, large) - #39

Closed
mahaloz wants to merge 1 commit into
mainfrom
feat/angr-tr-build-spec-list-ea32be
Closed

mahaloz wants to merge 1 commit into
mainfrom
feat/angr-tr-build-spec-list-ea32be

Conversation

@mahaloz

@mahaloz mahaloz commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

[PROPOSAL] SAILR-style condition folding / crossing-edge goto reduction (S7)

Opportunity: test_decompiling_tr_build_spec_list::build_spec_list
Binary: binaries/tests/x86_64/decompiler/tr.o (coreutils tr, x86-64; ET_REL)
Proposed option: condfold (S7 region structuring, default-OFF)
Scope: LARGE — needs human go/no-go before any implementation worker is spent.

The problem

For build_spec_list, kuna's full-pipeline output (kuna-fullpipeline.c) is structurally
close to angr's (angr-vs-kuna.txt) — DWARF types and loops match, __stack_chk_fail is
already no-return — except that kuna emits 11 gotos with crossing edges where angr
emits 4, because angr collapses short-circuit control flow into compound conditions.

Concretely, the bracket-class dispatch:

// angr — one compound condition, no crossing goto
if (!(char)es_match(ptr, cur, '[') ... )
if (!(char)es_match() && !(char)es_match() || !(char)find_closing_delim(ptr, v11, ..., &v7)) {
LABEL_400d08: ...
}
// kuna — nested if/else with a crossing-edge goto back into the sibling branch
v2 = es_match(v15, v10, ':');
if (v2) { ... find_closing_delim ... if (!v2) goto label_4024b8; ... }
else {
  v2 = es_match(v15, v14, '=');
  if (v2) goto label_40242e;     // <-- jumps from the else branch back into the then branch
label_4024b8: ...
}

The goto label_40242e is a crossing edge that angr removes by recovering
es_match(':') || es_match('=') as a single compound condition.

The angr reference

angr's decompiler (Basque et al., SAILR, USENIX Security 2024) produces this via:

  • RegionIdentifier + Phoenix structuring — synthesizes compound &&/|| condition
    nodes when two condition blocks share a successor (the short-circuit schema).
    (angr/analyses/decompiler/structuring/phoenix.py, _make_condition_node /
    _match_acyclic_schemas.)
  • SAILR optimization passes — CrossJumpReverter, DuplicationReverter,
    ConditionConstantPropagation (angr/analyses/decompiler/optimization_passes/) that undo
    compiler control-flow duplication so the crossing edges disappear.

Ghidra (and thus kuna today) structures with the BlockGraph collapse rules
(blockaction.cc), which do not synthesize short-circuit compound conditions across
distinct basic blocks — they emit a goto for the crossing edge instead.

Why this is LARGE (Hard Rule 7)

  • It is S7 structuring logic, not a single gated early-return: it must add condition
    synthesis to the region collapse and/or a pre-structuring deoptimization pass.
  • It is a new pass type / infrastructure, not one Action/Rule modeled on
    kuna_loweredswitch.rs (which manufactures an S2 artifact and reuses the existing
    structurer). Compound-condition recovery has no existing seam to reuse.
  • It will likely touch >3 ported-core anchor files (blockaction.cc/the S7 region
    collapse, block.cc for a new compound-condition block kind, the C-printer for &&/||
    emission, plus the option/registration anchors) and >1 module.

Any one of these alone triggers the LARGE classification.

Proposed multi-step implementation plan (for the approved worker)

  1. Detect the short-circuit schema in the S7 region graph: two BlockConditions whose
    true/false edges share a target (the A && B / A || B shapes), pre-collapse — port of
    Phoenix._make_condition_node. Gate behind option condfold.
  2. Synthesize a compound-condition region node (a new BlockCondition whose predicate is
    BoolAnd/BoolOr of the two operands) and rewire edges so the crossing goto becomes a
    structured edge.
  3. C-printer support for emitting the folded &&/|| (likely already present for
    in-block boolean ops; verify it renders for the synthesized node).
  4. Crossing-edge deoptimization (SAILR CrossJumpReverter) as a follow-up sub-step if
    step 1–2 do not remove all crossing edges on the corpus.
  5. Stage test tests/stages/ghangr-tr-build-spec-list-ea32be.xml: pass 1 (option condfold off) asserts the crossing goto; pass 2 (default-on for the test) asserts the
    compound condition and goto reduction.

Speed / risk assessment

  • Risk: HIGH. S7 structuring changes are the riskiest in the engine — the 675-datatest
    parity gate is very sensitive to block-collapse order. Expect a large ablation; the option
    must ship default-OFF opt-in regardless of speed.
  • Speed: an extra schema-match scan over region nodes is O(blocks); modest, but must be
    measured on build_spec_list off-vs-on per Hard Rule 6 before shipping.
  • Generalizes: yes — short-circuit &&/|| lowering is ubiquitous in -O2 GCC/Clang
    output, so a correct port helps far beyond this one function.

Recommendation

Approve as a dedicated S7-structuring implementation worker (not this single-feature
slot). The smallest viable first cut is steps 1–3 (compound-condition synthesis for the
acyclic short-circuit schema), gated option condfold, default-off, with the stage test
above; defer the SAILR deoptimizers (step 4) to a follow-up if needed.

Note: the target binary itself (tr.o) cannot be loaded by kuna (ET_REL loader gap,
proposal PR #37). The approved worker should use the linked standalone ELF approach
documented in analysis.md (stubs.c + tr_synth.elf) or a relocated bytechunk
(probe.xml) for its stage test, exactly as done here.

…reduction (S7, large)

angr's test_decompiling_tr_build_spec_list decompiles build_spec_list with 4
gotos by collapsing short-circuit && / || compound conditions; kuna emits 11
gotos with crossing edges. The genuine angr win here is SAILR-style condition
folding, which is LARGE S7 structuring infrastructure (new pass type, >1 module)
-> draft proposal per Hard Rule 7, not a single option-gated Action.

Other observed diffs are out of scope: the -fstack-protector canary epilogue is
already covered by `option stackguard`, and the duplicate/undeclared variables
are a generic S9 emit bug, not an angr algorithm.

Target tr.o is ET_REL (kuna's PT_LOAD-only loader can't load it; loader proposal
PR #37); fair comparison done via a linked standalone non-PIE ELF (stubs.c).

Bundle: docs/features/tr-build-spec-list-ea32be/ (analysis.md, proposal.md,
record.json, angr-vs-kuna.txt, kuna-fullpipeline.c, probe.xml, stubs.c).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@mahaloz

mahaloz commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Re-triage against today's main — still a real gap; implementation dispatched

Keeping this open. Re-measured, and the headline number moved, but not for the reason it looks like, and the named defect is still fully present.

The target loads now

tr.o loads directly today (relocobjects, #37, default-on) — it did not at proposal time. build_spec_list @ 0x400bc0, matching angr's address.

On tr.o directly

proposal baseline today, defaults angr 9.2.213
gotos 11 5 4
loc 122 116 128
folded || 0 1 (compound)

But the 11 → 5 comparison is cross-binary and cross-fidelity

The baseline 11 was measured on the synthetic linked ELF (stubs.c + tr_synth.elf); today's 5 is on ET_REL tr.o, whose output is materially lossier — signature degrades from build_spec_list(E_string *a0, Spec_list *a1) to (int8 *a0, unsigned long a1), string literals degrade to raw addresses (v5 = 0x404858; instead of "missing character class name '[::]'"), and calls lose arguments (es_match() with none, find_closing_delim(a0,v17) with 2 of 4). Fewer gotos partly reflects less recovered structure.

Apples-to-apples, the proposal's defect is 100% present

Rebuilding this branch's own measurement vehicle bit-for-bit (gcc -no-pie -nostdlib -nostartfiles -static -Wl,-Ttext-segment=0x400000 tr.o stubs.c; build_spec_list lands at 0x402370, exactly as analysis.md documents), today's defaults emit:

if (es_match(es,v12,'=')) goto label_40242e;   // THE crossing edge, else arm -> then arm

with zero folds (0 ||, 0 &&).

Correction to an earlier read: the existing fold is not landed P8 work

With all 11 P8 goto-quality options forced off, kuna still folds the short-circuit condition — it just renders it in negated polarity as &&:

else if ((es_match() == '\0') && (es_match() == '\0'))

So the fold on tr.o comes from the pre-existing ported-Ghidra CollapseStructure::ruleBlockOr, which kuna has had since the C++ port — not from #69/#79/#85/#103/#110. branchflip only flips polarity (&& → ||); it does not create the fold. Measured worth of the entire landed P8 family on this function: exactly 1 goto (tr.o 6→5, synth 7→6).

Root cause, now localized

The else block carries result_idx = &v10; before the condition, so the isComplex gate declines the fold. angr's Phoenix folds it anyway. That is precisely this proposal's thesis — Ghidra-style collapse rules can't fold across a non-trivial sibling block — and it is generalizable, not noise.

What changed since 2026-06-25: this is no longer LARGE

This PR was ruled LARGE on the premise that compound-condition recovery "has no existing seam to reuse". That premise is now obsolete. p8_structure/region_structurer.rs (default path, regionstructure on since #85/DIV-12) already contains match_acyclic_short_circuit_conditions() (:865) — the port of angr phoenix._match_acyclic_short_circuit_conditions — and try_block_or() (:886). The remaining work is relaxing the complexity gate to tolerate a bounded side-effect-free prefix, i.e. an increment on an existing schema, not a new pass type.

Cross-reference

Now-closed #53 (true_ubuntu1804::usage) has a measured residual of exactly +2 ifs vs angr from this same root — angr short-circuits if (!v30 || !strncmp(v30, "en_", 3)) where kuna emits two nested ifs, twice. That is a second witness for condfold.

An implementation worker is running on branch feat/condfold (default-off option, two-pass stage test, four gates, speed + decbench measurement).

@mahaloz

mahaloz commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Implementation is up: #196

This proposal and its sibling turned out to share one root cause — Ghidra's BlockBasic::isComplex >2-statement readability budget gating the short-circuit fold in CollapseStructure::rule_block_or (and its verbatim twin try_block_or in the region structurer). Proposal #39 (tr::build_spec_list crossing edge) and proposal #56 (newbury::main SUID-guard goto) are two symptoms of that single gate.

They were implemented separately as #193 and #194, which collided (same struct field, same builder method, same gate line, same ElementId). Both are now closed and consolidated into #196 — one option condfold off|on|wide, default-off, ElementId 4113, whose admission predicate is the union of the two rules.

Both criteria are met and measured against main @ d09f21ce:

Notably, both proposals' LARGE / "new pass type" verdicts were wrong, and for the same reason: they were filed on 2026-06-25, before regionstructure (#85, DIV-12) made the Phoenix/SAILR region structurer the default emit-driving path. Proposal #56's step 1 — "promote kuna_regionid.rs from a read-only console surface into an emit-driving structurer" — was already done. Neither needed a new pass type; each needed one gate relaxation. Nor was a de Morgan rewrite or a purity analysis required: negate_condition_rec already distributes the NOT and never swaps operands, so #56's worry about reordering the getuid/geteuid/getegid/getgid predicates does not arise.

Leaving this open until #196 merges.

@mahaloz mahaloz closed this in #196 Jul 30, 2026
rdmmf pushed a commit to rdmmf/kuna that referenced this pull request Aug 3, 2026
… sibling (supersedes Noelo-Lab#193 + Noelo-Lab#194, closes Noelo-Lab#39 + Noelo-Lab#56) (Noelo-Lab#196)

* feat(p8): condfold -- short-circuit fold across a non-trivial sibling block

Ghidra's ruleBlockOr declines the `A || B` short-circuit fold whenever the
sibling condition block is *complex* (BlockBasic::isComplex: more than two
statements). One spill or address computation parked in front of the second
test is enough, and kuna then emits the second condition as its own block
branching back into the first arm's clause -- a crossing goto where angr
renders one compound condition. On coreutils tr::build_spec_list that is
literally `result_idx = &v10; if (es_match(es,v12,'=')) goto label_40242e;`.

This ports angr Phoenix's MultiStatementExpression relaxation
(_match_acyclic_short_circuit_conditions types a-d, phoenix.py:2688) and
nothing else: a second, narrower disjunct at the single is_complex(orblock)
decline in BOTH structurers (CollapseStructure::rule_block_or and
RegionStructurer::try_block_or -- verbatim copies of each other; implementing
only one would no-op on functions where the other converges). A complex
sibling is accepted when it is a BlockCopy of ONE BlockBasic whose printed
prefix is bounded, branch-free, and comment-free; the prefix then renders
inside the &&/|| operand as a C comma expression, which the printer already
supports (comma_separate).

No p-code moves: new_block_condition re-parents two existing structuring
nodes. The sibling is single-in (an inherited ruleBlockOr precondition), C's
short-circuit rule evaluates the right operand exactly when control used to
fall into the sibling, and the comma operator is a sequence point -- so the
prefix runs on the same paths in the same order. Every added guard is a
rendering-validity or readability guard, not a semantic one:

  - BlockCopy-of-one-BlockBasic only (a list/if/condition operand could render
    braces or a label inside the parens = invalid C);
  - the pre-existing !is_interior_goto_target decline is never relaxed
    (emit_block_copy emits the label statement first);
  - bounded statement/call count, counted with the printer's own skip rules;
  - no non-terminal branch op (angr's own refusal);
  - no instruction comment in the block (emit_comment_group is suppressed
    under comma_separate, so folding would silently delete it);
  - a relaxed fold's node is force-marked complex so rule_block_while_do can
    never hoist the comma chain into a while(...) header.

Option `condfold`, default OFF, three-valued: `on` is exact angr parity
(<=5 statements, <=1 call) and `wide` raises only the statement cap to 9 to
absorb kuna's finer printed-statement granularity (argument recovery and
address-tied copy shadows split one AIL statement into several printed ones).
OFF skips the precompute and leaves both disjuncts dead, so output is
byte-identical.

Gates: make test 675/675 PARITY OK; make test-stages 268/268 PARITY OK;
make rust-test green; make check-spec green (strict).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* test(p8): condfold gate unit tests + docs/features/condfold measurement record

Five hand-built-graph unit tests in blockaction/tests.rs covering the gate
itself: the upstream decline when the option is off, the fold when the sibling
is complex-but-eligible, the refusal of a non-BlockCopy operand, the dead-gate
state, and -- the one that matters most -- that a condfold-relaxed
BlockCondition reports ITSELF complex despite a trivial left operand, so
rule_block_while_do can never hoist the comma chain into a while(...) header.

docs/features/condfold/record.json carries the full measurement: the
angr-vs-off-vs-on-vs-wide metric table on both vehicles, the PR Noelo-Lab#53 bonus
result on true_ubuntu1804::usage (ifs 9 -> 7 at wide, closing the +2 residual),
the 1580-function / 5-binary aggregate sanity sweep (gotos 931 -> 902, ifs
5077 -> 4961, ZERO invalid C, with the gcc -fsyntax-only checker validated
against both failure modes this option could produce), the interleaved
CPU-time speed delta (-0.21% on, -0.27% wide), and an honest note that the
region_structurer mirror is currently unexercised end-to-end because that
engine does not converge on any function where the fold applies (verified
pre-existing on main's binary).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* docs(p8): condfold's call cap counts statement-root calls only, not angr parity

Review finding on PR Noelo-Lab#193: in `condfold_eligible` the implied-output skip
`continue`s BEFORE the `if o.is_call()` test, so a call inlined into the
sibling's condition expression is never charged against `MAX_PREFIX_CALLS = 1`.
The enforced bound is "at most one call printed as its own comma-chain element",
not "at most one call in the rendered operand" -- so the tree's four "<=1 call /
exact angr parity" claims were untrue. Measured: 1 of the 46 new call-bearing
folded operands renders two calls (`mv -O2 copy_internal` at `wide` renders
`cached_umask(...)`, a statement root that is counted, alongside `fchmod(...)`,
implied into the test and not counted).

Fixed by correcting the documentation, NOT the code. The cap is a readability
bound, not a soundness bound -- the fold moves no p-code and the short-circuit +
comma sequencing argument is independent of the call count, so the looser count
cannot produce wrong C. Reordering the two checks would TIGHTEN the gate and
therefore invalidate the PR's measured metric table, aggregate sweep and
stage-test witness; that choice is recorded in the PR body as an explicit
open decision for the reviewer rather than taken silently here.

Corrected in all four places:
  * kuna_condfold.rs -- module doc guard 1 + the MAX_PREFIX_CALLS doc comment
    (plus the condfold_eligible decline list and the policy-constant unit test's
    comment, which carried the same claim)
  * phases.toml -- the condfold row's summary + use_when
  * infra/architecture.rs -- the cond_fold field doc
  * docs/spec/08-structuring.md -- a new paragraph stating the semantics precisely

`on` remains exact angr parity on the *statement* threshold (5); only the
call-cap parity claim is withdrawn.

Also fixes a factual error in the ElementId provenance comment: it named 4112
as `loopbreak`; on `main` 4112 is `switchreturn` and `loopbreakrecovery` is
4092. The comment now also records that `condjoin` (PR Noelo-Lab#194, developed in
parallel) takes 4114 -- both branches had allocated 4113; condfold keeps it.

Regenerated the two derived artifacts the phases.toml prose feeds:
docs/options.md and tests/fixtures/phase_catalog.json.

No code change, so no re-measurement is needed and no behaviour moves.
docs/baseline.json untouched.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* feat(p8): consolidate condfold + condjoin into one option (union predicate)

PR Noelo-Lab#193 (`condfold`, proposal Noelo-Lab#39) and PR Noelo-Lab#194 (`condjoin`, proposal Noelo-Lab#56)
relax THE IDENTICAL GATE -- the `is_complex(orblock)` decline inside
`rule_block_or` and its verbatim twin `try_block_or`.  Ship them as ONE
option whose admission predicate is the UNION of the two rules.

* `condjoin` disappears: no option name, no `cond_join` field, no
  `kuna_condjoin.rs`, no second spec section.  ElementId 4114 is released.
  Exactly one net new option (76 -> 77).
* Rule A (from Noelo-Lab#193): bounded, branch-free, comment-free printed prefix on a
  `BlockCopy` of one `BlockBasic`.  Closes Noelo-Lab#39.
* Rule B (from Noelo-Lab#194): statement-shape allowlist, and the only rule that
  admits a nested `BlockCondition` operand -- which is what a guard CASCADE
  needs.  Closes Noelo-Lab#56.
* Both witnesses kept: `tests/stages/ghangr-condfold.xml` (Rule A) and
  `tests/stages/ghangr-condfold-newbury.xml` (Rule B, renamed from
  ghangr-condjoin.xml and rewritten to drive `option condfold`).

Four reviewer-found accuracy defects addressed:
1. Rule A's call cap counts statement-root calls only.  Decision recorded:
   KEEP those semantics; constant renamed `MAX_PREFIX_ROOT_CALLS` so the name
   is the contract, and every doc says so.
2. Rule B's expression-size cap bypass is closed by inheriting Noelo-Lab#193's
   `condfolded` force-complex marking (a relaxed result always re-enters the
   admission check).  The residual left-extension case is documented instead
   of claimed away.
3. The option is NOT a monotone goto reducer; `use_when` and the spec now say
   so with the measured per-function regressions.
4. A later-produced advisory comment can still be lost; documented.

Re-measured on main @ d09f21c (nothing carried over from Noelo-Lab#193/Noelo-Lab#194):
`on` closes BOTH criteria -- newbury::main 0 gotos / 0 labels, the tr crossing
`goto label_40242e` gone with the compound condition present and tr gotos at
angr parity (4).  Aggregate over 2827 functions / 7 binaries: gotos 2294 ->
2198 (on) -> 2189 (wide), ifs 10492 -> 10135 -> 10108, loc 87959 -> 86713 ->
86567, 0 invalid-C hard stops with a checker validated against
label-inside-expression and unbalanced-condition.

Gates: make test 675/675 PARITY OK (baseline.json untouched), make test-stages
272/272 PARITY OK, make rust-test green, make check-spec green lenient and
--strict, kuna catalog --check OK.

Refs Noelo-Lab#39 Noelo-Lab#56 Noelo-Lab#193 Noelo-Lab#194

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015PVb6KdMKGV5rGEooSGHr4

* docs(p8): describe the union predicate at the Architecture/ArchContext seam

- Architecture::cond_fold and ArchContext::cond_fold now document BOTH
  admission rules, the fixed MAX_PREFIX_ROOT_CALLS intra-doc link, and the
  two accepted effects (not a monotone goto reducer; a later-produced
  advisory comment can be lost).
- The quoted tr build_spec_list OFF snippet now matches what this main
  actually emits (&v9 / es_00,v11, not the proposal's &v10 / v12).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015PVb6KdMKGV5rGEooSGHr4

* docs(condfold): record the measured proof that neither admission rule subsumes the other

newbury::main folds entirely under Rule B (five shape folds, zero prefix folds,
two of them on a nested BlockCondition Rule A can never accept), and the whole
aggregate delta of `wide` over `on` is Rule A folding blocks Rule B declines
with 'over MAX_SHAPE_STMTS'. The predicate has to be the union.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015PVb6KdMKGV5rGEooSGHr4

* fix(p8): give condfold ONE printed-width budget shared by both rules

Review round on the consolidation (NEEDS_WORK).  Four defects, all in the
option's contract rather than its correctness.

1. Rule B's cap did not bound printed width.  MAX_SHAPE_STMTS counts
   calc_explicit-*scored* statements, and on this PR's own headline witness
   `tr::build_spec_list` a block scored 2 and rendered SEVEN comma elements.
   The consequences were exactly what that predicts: the widest emitted comma
   operand was 7 at BOTH `on` and `wide`, `on` and `wide` were byte-identical
   on all four named targets, and an operator following "try `on` first" got
   the option's widest folds at the conservative setting.

   Fixed by factoring Rule A's walk into one shared measure,
   `kuna_condfold.rs (printed_shape)`, and enforcing it in BOTH rules against
   the policy level's cap (5 at `on`, 9 at `wide`).  Rule B's shape allowlist
   and call cap are untouched -- they are the soundness-relevant half.  The
   calc_explicit score survives only because the cross-leaf caps are expressed
   in it.

   Measured effect (7 binaries / 2827 functions, one counter for every column
   including the angr panes):
     - widest comma operand condfold CREATES: 5 at `on` (its own budget),
       7 at `wide`.  Was 7 at both.
     - newbury::main still closes at `on` (0 gotos / 0 labels), byte-identical
       to the pre-fix output.
     - tr::build_spec_list now needs `wide` for angr goto parity (4), restoring
       Noelo-Lab#193's original finding; tr.o is byte-identical to `off` at `on`.
     - true_ubuntu1804::usage (the Noelo-Lab#53 bonus, ifs 9 -> 7) now needs `wide`.
     - `wide` differentiates itself on 3 of the 4 named targets again.
     - aggregate gotos 2294 -> 2219 (`on`) -> 2191 (`wide`); 0 invalid-C hard
       stops, 0 functions lost.

2. Stale measurement text.  The module docs still listed Noelo-Lab#193's
   `newbury::network_init 3 -> 4` / `lshpack_enc_encode 16 -> 17`, contradicted
   by record.json in the same commit; phases.toml and options.md carried the
   round-1 numbers, now also stale.  Re-measured after (1) and rewritten on
   every surface: the regressions are `clientloop.o::process_escapes` 26 -> 28
   (both levels) and `true_ubuntu1804::usage` 1 -> 2 (`wide` only).

3. Comment guard restored to Noelo-Lab#194's breadth.  The consolidation had narrowed it
   to comment_type::warning; it now declines on ANY buffered comment at a
   covered address.  Behaviourally equivalent today, but the narrow form rested
   on an unstated invariant and the failure mode is a silently deleted comment.

4. Width slack documented honestly.  "can render one statement wider than the
   nominal budget" is gone from all four surfaces (module docs, architecture.rs,
   phases.toml, docs/spec/08-structuring.md).  Each now states what the budget
   bounds (per-leaf comma-chain width) and what it does not (a Rule-B cascade's
   summed width, post-structuring drift, over-counting on unprototyped calls,
   the final condition's global width).

Also: KUNA_CONDFOLD_DEBUG=1 now reports both measures on every admit
(`scored N, prints M (budget B)`) and the numbers on every decline;
KUNA_CONDFOLD_DEBUG=ops lists every op printed_shape charges, so a measured
width can be reconciled op by op against the emitted chain -- the reviewer had
to do that by hand.

The Rule-B stage witness `ghangr-condfold-newbury.xml` moves from `on` to
`wide`, and its comment says why: its stub callees are unprototyped, so each
guard block still carries the call's stack-effect ops at structuring time and
measures 6 for an operand that finally emits none.  The over-count only ever
declines.  That move is itself the two-pass proof of the fix -- under the
pre-review predicate this shape folded at `on`.  Assertions unchanged, so the
stages baseline is NOT re-recorded.

Gates: make test 675/675 PARITY OK; make test-stages 272/272 PARITY OK;
make rust-test green (4319 tests, cargo exit 0); make check-spec OK lenient AND
--strict; kuna catalog --check OK; docs/baseline.json diff vs origin/main empty.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015PVb6KdMKGV5rGEooSGHr4

* test(p8): isolate condfold's Rule B with a witness Rule A cannot take

`condfold`'s admission predicate is the UNION of two rules and `condfold_ok`
consults Rule A first, so a sibling both rules accept folds through Rule A.
Measured with `KUNA_CONDFOLD_DEBUG=1`, both shipped witnesses did exactly
that: `ghangr-condfold-newbury.xml` at `wide` takes 2 `prefix` folds per
engine and 0 `shape`, `ghangr-condfold.xml` at `on` takes 1 `prefix`, and the
whole stages corpus took ZERO `shape` folds. Deleting Rule B entirely left
`make test-stages` green -- a coverage regression against PR Noelo-Lab#194, which
shipped the newbury witness at `on` where Rule A declined all three guards.

The shared printed-width budget cannot separate the rules (both enforce it,
on the same `printed_shape` measure) and the comment guard declines both.
Exactly two properties are Rule B's alone: the nested `BlockCondition`
operand, and the call cap -- which, unlike the width budget, does NOT move
with the policy level (`MAX_PREFIX_ROOT_CALLS` = 1 at `on` AND at `wide`,
against `MAX_SHAPE_CALLS` = 2).

New witness `tests/stages/ghangr-condfold-ruleb.xml` (6 assertions, off ->
on): a three-guard permission cascade whose middle guard is
`su_log(); x = su_euid(); if (x != wu)` -- a void call plus a call whose
output the failure arm consumes, so neither is implied and both print as
their own comma element. At `on` it traces
`admit(shape) ... scored 2, prints 4 (budget 5)` with no `admit(prefix)`
line, and folds twice as `shape` in BOTH engines.

Acceptance check: with `shape_score` stubbed to always decline,
`make test-stages` reports 274/278 and PARITY FAIL on exactly this file's
#1..Noelo-Lab#4; restored, 278/278 PARITY OK. The other two condfold witnesses stay
green under the stub.

Also in this commit:

* `KUNA_CONDFOLD_DEBUG=ops` was off by one. `printed_shape` charged the
  terminal CBRANCH at its own early `continue`, which skipped the trace, so a
  block measuring 6 listed 5 ops -- exactly the op-by-op reconciliation the
  docs advertised. Every `out.stmts` increment now goes through one `charge!`.
  Verified: the newbury guard block at 0x100060 lists 7 ops and reports
  `prints 7`; the one at 0x10006b lists 6 and reports `prints 6`.
* `data:condfold-newbury #1..Noelo-Lab#4` said "ON" while the pass runs `wide`.
  Renamed to say WIDE; the regexes, min/max and verdicts are unchanged.
* Seven unit tests that run `printed_shape` / `prefix_eligible` /
  `shape_score` / `compute_condfold_sets` over REAL hand-built op lists. The
  existing unit tests only covered the gate against synthetic `CondFoldSets`
  and never ran the scorers.
* `docs/spec/08-structuring.md`, the module docs and all three witness
  headers now state which rule each witness fires, rather than implying the
  newbury one isolates Rule B.

Gates: `make test` 675/675 PARITY OK; `make test-stages` 278/278 PARITY OK
(baseline re-recorded: additive, 272 -> 278, no key dropped, and
`docs/baseline.json` untouched); `make rust-test` green; `make check-spec`
green lenient and --strict; `kuna catalog --check` OK. No new option (77).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015PVb6KdMKGV5rGEooSGHr4

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@mahaloz
mahaloz deleted the feat/angr-tr-build-spec-list-ea32be branch August 9, 2026 02:45
mahaloz added a commit that referenced this pull request Oct 2, 2026
…anch stores again

Adds e_reg (store, then on a branch load through the pointer and store again,
a register carrying both values to a call) to storealias_x86_64.c, rebuilds
the three fixtures (SHAs in the README), round-trips it in store_alias.rs and
adds stage assertion #39. Records the footprint of the call-path change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
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