Skip to content

ENABLE_P384_VERIFY was a no-op on the REU profiles, so the P-384 mutation control passed vacuously #207

Closed

Description

@JC-000

Summary

CA65FLAGS += -D ENABLE_P384_VERIFY=1 sat inside ifeq ($(USE_NISTCURVES_ONCHIP),1),
so the two REU-profile builds — plain make and make BACKEND=uci — dropped the -D
silently. The flag did nothing at all on those two configurations.

Proof that the -D never reached ca65 (PRG sha256; the PRG is the check, per CLAUDE.md):

make BACKEND=ip65                       d780f719fac82e07bba9d30db804e853…
make BACKEND=ip65 ENABLE_P384_VERIFY=1  d780f719fac82e07bba9d30db804e853…   identical
make BACKEND=uci                        7c79a4e00a19685de7540970247c759a…
make BACKEND=uci  ENABLE_P384_VERIFY=1  7c79a4e00a19685de7540970247c759a…   identical

Why it matters

ENABLE_P384_VERIFY exists for exactly one reason: so the P-384 safety gate can be
mutation-tested. CLAUDE.md's "Smoke tests" section documents
tools/test_p384_overlay_hazard.py as failing under ENABLE_P384_VERIFY=1 by design —
"a safety gate nobody can switch off is a gate nobody can prove is load-bearing."

On the REU profiles that control passed. Measured, master, BACKEND=uci ENABLE_P384_VERIFY=1, PRG 7c79a4e00a19685d…, VICE, C64_SKIP_BUILD=1:

returned : C=1
bytes changed in the live overlay slot: 0 / 7680
[PASS] resident code left intact
[PASS] clean reject (C=1) on an unsupported curve
PASS: a P-384 certificate is handled safely            exit 0

It reported green while exercising the unmutated build. Anyone who ran the control on
BACKEND=uci and saw green concluded the gate was proven, having proven nothing.

After hoisting the block to top level, the same command on the same profile
(PRG 8b67ee949f8507b8…):

returned : DID NOT RETURN (hung)
bytes changed in the live overlay slot: 5548 / 7680
[FAIL] resident code left intact
[FAIL] clean reject (C=1) on an unsupported curve      exit 1

Scope

  • The gate itself was never weakened. ecdsa_verify's P-384 arm was a sec reject in
    every shipped image throughout, and remains one.
  • No shipped image was affected. All three products set USE_NISTCURVES_ONCHIP, where
    the nesting happened to be harmless; the three onchip profiles' armed PRGs are unchanged
    by the fix (b9f03169…, 3c271262…, cc555c19…).
  • What was broken was the control, on two of five configurations.

The class of defect — this is the part worth keeping

This was a flag that silently did nothing, and build/flags.stamp structurally cannot
catch that.
The stamp faithfully records the flags that were computed; the computed set
was the wrong one. It guards against stale objects surviving a flag change — not against a
knob that never reaches the compiler. Every existing guard in
tools/test_build_flags_stamp.py was green throughout.

Suggested guard (not built, maintainer's call): assert that every documented knob
changes either the PRG sha256 or build/flags.stamp on each profile it claims to support.
That is a natural companion to test_build_flags_stamp.py, needs no VICE, and would have
caught this the day the nesting was introduced. It would also cover the next knob that
grows a conditional around it.

Fix

Two commits, cherry-picked with -x onto chore/crypto-lib-bump. The first hoists the
block to top level; all five unarmed PRGs are unchanged by it (verified by comparing
fully-expanded CA65FLAGS / LD65FLAGS / ALL_OBJS / archive sets across all five
variants).

Two notes for whoever triages

  • Evidence strength. The finding rests on the two REU rows above (7c79a4e0… 0/7680
    exit 0, and 8b67ee94… 5548/7680 exit 1), both measured here. A supporting row on
    USE_NISTCURVES_ONCHIP=1 ENABLE_P384_VERIFY=1 was measured once here at PRG
    3c2712629063de69… → 5575/7680; a second lane reports 5653/7680 at PRG c16423ba…,
    reportedly on the integrated branch rather than chore/gate-p384-objects pre-cherry-pick.
    Those are different artifact hashes, therefore different builds — so this is not a
    discrepancy at all
    , and neither figure reproduces or contradicts the other. (Two figures
    differing on the same PRG hash would be a discrepancy and would need chasing; two
    figures on different PRG hashes are simply two different measurements.) Both are single
    measurements. The finding does not depend on that row.

  • Adjacent, not part of this issue. The two profiles this bug silently disarmed are the
    same two the libs/nistcurves v0.14.0 exposure analysis concerns: another lane reports
    they read LIB_NISTCURVES_REU_BANKS_USED = $0003, i.e. they do library REU DMA and are
    exposed to the SPEC §8.2 settle fix. They ship in nothing today, but CLAUDE.md records
    restoring them as "one line in PACKAGE_VARIANTS". I have not verified that figure —
    it belongs in the bump PR, and is recorded here only because the profile overlap makes it
    easy to lose.

Activity

  1. JC-000 commented on Sep 8, 2026

    @JC-000
    OwnerAuthor

    Fixed by 4265ae1 (#216) — the Makefile block is now at top level, outside any USE_NISTCURVES_ONCHIP conditional.

    This issue's own discriminator inverts on the REU profile, which is the proof: make BACKEND=uci → PRG sha256 9eaee61d…, make BACKEND=uci ENABLE_P384_VERIFY=1 → 7e55fbc7…. Previously identical, which is what made the mutation control pass vacuously. On BACKEND=ip65 the flag now reaches ca65 hard enough to change the link outcome outright (HTTP_AUX_CODE2 overflows CRYPTO_OVERLAY by 174 B) — the strongest available evidence it is no longer being dropped.

    Not built: the knob-effectiveness guard suggested here. tools/test_build_flags_stamp.py has nine tests and none of them asserts that a flag reaches the compiler. Filing that separately if it is still wanted — the defect is fixed, but nothing stops it recurring.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions