diff --git a/research/frontier1094-certificate-binding-audit/README.md b/research/frontier1094-certificate-binding-audit/README.md new file mode 100644 index 0000000000..12a3e9b682 --- /dev/null +++ b/research/frontier1094-certificate-binding-audit/README.md @@ -0,0 +1,200 @@ +# Selected #1094 certificate: invoice/outer recheck and replay-binding gap + +**Adversarial audit; no new κ; no defect in the current certificate.** + +The committed #1094 certificate passes an independent recheck of its finite +invoice, bootstrap chain and all 47 + 47 outer slacks, and its profile agrees +across five artifacts. + +The audit also finds a **check-level binding gap** in the selected record's +reproduce command, `make frontier1094-verify`. That command binds the committed +certificate to its cold replay **only through κ**. A well-formed certificate +that claims an uncertified complex endpoint, with every arithmetic identity +recomputed so κ is unchanged, is: + +* accepted by the selected-record check once its hash pin is updated, and +* never compared with the replay output. + +Only an exact moment evaluation, outside the reproduce path, rejects it. + +The current certificate is not affected. The published replay output and the +recorded `assembly_sha256` are byte-identical to it. A one-line binding is +proposed below as a handoff; it is not applied to the selected script. + +## Results + +1. **Invoice and outer recheck of the committed #1094 certificate: PASS.** This + applies Wronskode's + [frontier1042-invoice-audit-seed81](../frontier1042-invoice-audit-seed81/README.md) + recheck, unchanged and loaded as its exact Git blob. The recheck covers: + * profile composition, per-vertex envelope and the nine finite guards; + * 7 + 7 bootstrap levels and 47 + 47 outer slacks; + * κ as the last 10⁻¹⁸ grid point below the absorption margin; + * the four outer controls and all 15 mutation controls. + + The package binds the certificate directly, by path and SHA256 + `1122cb3a…3045` (the `certificate_sha256` of the selected record at the + base), not through the moving `selected-result.json` pointer. As a positive + control, it reproduces seed81's published #1042 result exactly from the + frozen #1042 checkpoint. +2. **Seed81's own entry point is stale.** It requires the *selected* certificate + to be #1042's, so `make frontier1042-invoice-audit-verify` now stops with + `FAIL selected certificate path moved`. The #1042 recheck still holds through + this package's checkpoint-bound loader. The suggested repair is to read + `certificates/checkpoints/frontier1042.json` instead. +3. **The #1094 invoice arithmetic is unchanged from #1042.** The receipts differ + in exactly 14 fields: + * `PREFIX-AND-INVOICE.json`: only three provenance hashes; + * `OWNERS-AND-PROFILE.json`: those hashes, the idle-remainder profile + (ranks 1, 2, 3, 7, 16 and 48), the idle child count (7,550 → 7,526), + `actual_73column_sigmas` and `cross_replica_helper_roles`. + + The envelope and guards are therefore identical to #1042's, which is + consistent with #1094's idle re-placements. +4. **Profile binding.** The certificate's `complex_profile` equals all four + other copies: + * the archived owner receipt's `paid_profile`; + * the package's `PROFILE.json`; + * the package's `data/PLAN.json`; + * the owner-audited profile in `INDEPENDENT1094.json`. + + The maintainer composition (`check_frontier1094.py`) prices the owner-audited + profile but does not itself compare it with the certificate. The values agree. +5. **Mutant certificate.** The complex endpoint `b` is replaced by `b + 10⁻²⁴`, + the next grid point. The bootstrap, the 47 outer slacks and both complex + moment records are recomputed with seed81's formulas, and κ stays + `836330098538459/5·10¹⁷`. Results by layer: + + | Layer | Mutant | + |---|---| + | Seed81 invoice/outer arithmetic (endpoint taken as data) | accepted | + | `verify_selected_result.check` with `certificate_sha256` re-pinned | accepted | + | `verify_frontier1094.py` cold replay and its candidate stage | never read the committed certificate | + | Exact moment, via `selected-suppliers-de-diagnostic`'s enclosure | **rejected**: residual > 1.62·10⁻²⁴ | + + The cold replay contains no reference to the #1094 certificate path, the + selected record or `certificate_sha256`. Its only certificate-related string + is the historical `certificates/checkpoints/frontier1042.json` stage. + + Its candidate stage (`complex-t16-rare-pattern-exchanges/verify.py`) + regenerates the assembly with the unchanged PR1087 strict verifier. It then + binds only the replay's status, its κ and its `complex_profile`, the last + to the package's `PROFILE.json`. It never names `complex_lower`, + `bootstrap`, `outer`, `moments` or `conservative_outer`. + + At the certified endpoint, the residual is below −1.30·10⁻²⁴ (accepted). As + a control, the selected check does reject a κ edit (`Selected kappa differs + from finite certificate`). So the record's hash pin says *which bytes* are + selected, and the replay says *which κ* is reproduced. Nothing on the + reproduce path says those bytes are the replay's output. + +## Proposed handoff (not applied) + +Add one requirement in `scripts/verify_frontier1094.py` after the replay: + +```python +require(sha(work/'candidate/strict/ASSEMBLY.json') == + read(ROOT/'certificates/selected-result.json')['certificate_sha256'], + 'Replay output is the selected certificate') +``` + +If cross-platform byte determinism is in doubt, compare parsed JSON instead. + +This package shows the requirement holds on the published replay output: the +archived `candidate/strict/ASSEMBLY.json` and the recorded `assembly_sha256` +both equal the certificate. It also shows the requirement rejects the mutant. + +A fresh cold replay with the added line was **not** run here. It needs the full +#1042 baseline replay, which is long, and editing the selected reproduce script +is a maintainer decision. + +Statically, `scripts/verify_frontier1042.py`, `verify_frontier942.py`, +`verify_frontier890.py` and `verify_frontier799.py` also contain no reference +to their committed certificates. They were not audited further. + +## Reproduce + +Standard library only, plus `git` with history for the base commit. From the +repository root: + +```sh +python3 scripts/research_package.py --package research/frontier1094-certificate-binding-audit --check-only +python3 -I -B research/frontier1094-certificate-binding-audit/verify.py +``` + +Expected (about 5 seconds): + +```text +PASS_FRONTIER1094_CERTIFICATE_BINDING_AUDIT invoice_outer=PASS controls=15 receipt_delta=14 profile_copies=5 mutant_accepted_by=arithmetic,selected_check mutant_rejected_by=exact_moment no_new_kappa +``` + +[RESULT.json](RESULT.json) is the regenerated receipt; `--write` rewrites it. + +Five pieces of audited code are loaded as exact Git blobs at base `0b1cccf8`, +so a later repair does not change what this package checked: + +* seed81's `verify.py`; +* the endpoint package's `verify.py`; +* `scripts/verify_selected_result.py`; +* `scripts/verify_frontier1094.py`; +* the candidate stage `research/complex-t16-rare-pattern-exchanges/verify.py`. + +The data inputs are pinned in [SOURCES.json](SOURCES.json). The mutant exists +only in a temporary directory during the run. The script refuses to run under +`-O`. + +## Scope and limits + +This audits the binding and arithmetic from the frozen receipts to κ. It takes +the receipts' semantic content as data: words, owners, hosting and local +replays. It re-establishes no moment endpoint beyond the two exact residual +evaluations above. + +* **Not run:** the cold replay, the native or hosted pipeline, and the + all-size/compiler, precision/tape, analytic and H1–H5 obligations. These are + unchanged and inherited. +* **Environment:** run on Windows with CPython 3.14. The registered Python 3.12 + replay was not run locally; `--check-only` passes. + +## Open next questions + +1. **Should the selected reproduce path bind the certificate to the replay + output?** + * *Why it matters:* today a promotion that commits a non-replay certificate + with the same κ would pass `make frontier1094-verify`. The certificate's + endpoints and outer slacks are what downstream audits read. + * *First step:* add the requirement above and run one cold + `make frontier1094-verify` on Linux, comparing raw and parsed equality. + * *Blocked by:* maintainer authorization to edit the selected reproduce + script, and the long cold baseline replay. + +## Related work + +* **#474** (artuskg, open) identified the same class of gap for the historical + gen4 record. Its `gen4-bank-verify` "does not compare that replay's + certificate with the frozen publication", and it adds a recursive comparison + helper, `scripts/check_selected_replay.py`. That helper is a natural way to + implement the handoff above for #1094. This package claims no priority for + the pattern; it establishes the gap on the current selected path, with a + concrete mutant. +* **#1277** (merged) covers the reuse-mode ancestry binding of the same + replay, and **#1654** (open) is the overlap receipt for the #1094 + replay-tooling family. Neither adds a certificate-to-replay comparison. + #1654 also notes the same moving-pointer staleness in another capsule audit. + +## Credit + +Prepared for rtyu193-rgb with Claude Code (Anthropic Claude Opus 5.5) in one +session, with no subagents and no independent human review. Apache-2.0. + +* **Wronskode:** the seed81 invoice/outer recheck, reused unchanged. +* **Navinor:** the `selected-suppliers-de-diagnostic` exact moment enclosure, + reused unchanged. +* **Douglas Colkitt:** the selected reproduce scripts and the + `check_frontier1094.py` composition. +* **Construction lineage:** Rohan Arun (#1094), with Jeremy Kothe's k8/T16 + construction and the supplier lineage credited in the selected review. Josie + Elliston (#1091) and Sagar Thakrar (#1069) supplied the auditors applied by + that composition. + +No predecessor file is modified. diff --git a/research/frontier1094-certificate-binding-audit/RESULT.json b/research/frontier1094-certificate-binding-audit/RESULT.json new file mode 100644 index 0000000000..246f0c6fad --- /dev/null +++ b/research/frontier1094-certificate-binding-audit/RESULT.json @@ -0,0 +1,189 @@ +{ + "mutant": { + "candidate_stage_binds": [ + "status", + "kappa_decimal", + "complex_profile == package PROFILE.json" + ], + "candidate_stage_never_names": [ + "bootstrap", + "complex_lower", + "conservative_outer", + "frontier1094-audit", + "moments", + "outer" + ], + "change": "complex_lower + 1e-24 with bootstrap, 47 outer slacks, complex moment endpoints recomputed", + "complex_lower": "837731338404051761463/500000000000000000000000", + "frontier1094_verify_recipe": [ + "@work=$$(mktemp -d \"$${TMPDIR:-/tmp}/integer-mult-frontier1094.XXXXXX\"); \\", + "python3 -B scripts/verify_frontier1094.py --work \"$$work/replay\"" + ], + "kappa_edit_control": "ValueError: Selected kappa differs from finite certificate", + "kappa_unchanged": "836330098538459/500000000000000000", + "layers": { + "exact_moment": "rejects", + "seed81_invoice_outer_arithmetic": "accepts", + "verify_frontier1094": "never reads the committed certificate; replay binds only kappa and profile", + "verify_selected_result_check": "accepts after repinning certificate_sha256" + }, + "moment_residual_lower_at_mutant": "1.624724e-24", + "moment_residual_upper_at_certified": "-1.304215e-24", + "verify_frontier1094_certificate_strings": [ + "Exact selected kappa", + "certificates/checkpoints/frontier1042.json", + "scripts/verify_selected_result.py" + ] + }, + "profile_binding": { + "artifacts": [ + "INDEPENDENT1094 owner-audited profile", + "archived OWNERS-AND-PROFILE paid_profile", + "certificate complex_profile", + "package PROFILE.json", + "package data/PLAN.json profile" + ], + "equal": true, + "profile": { + "1": 349604, + "2": 60192, + "3": 62585, + "4": 20448, + "5": 11808, + "7": 7, + "8": 1152, + "48": 4866 + } + }, + "proposed_binding": { + "check": "require(sha(work/'candidate/strict/ASSEMBLY.json') == selected['certificate_sha256'])", + "published_replay_output_matches": true, + "published_result_assembly_sha256_matches": true, + "rejects_mutant": true + }, + "receipt_delta_vs_1042": { + "invoice": [ + "/controller_audit_sha256", + "/owner_audit_sha256", + "/template_sha256" + ], + "owners": [ + "/actual_73column_sigmas", + "/controller_audit_sha256", + "/cross_replica_helper_roles", + "/explicit_idle_remainder_children", + "/paid_profile/1", + "/paid_profile/16", + "/paid_profile/2", + "/paid_profile/3", + "/paid_profile/48", + "/paid_profile/7", + "/template_sha256" + ] + }, + "recheck_1094": { + "conservative": { + "kappa": "104541262139063/62500000000000000" + }, + "controls_rejected": [ + "bit_endpoint", + "bootstrap_cut", + "call_primitives", + "complex_endpoint", + "drop_call", + "extra_idle", + "group_Sp70", + "kappa_up", + "max_rank", + "physical_plus", + "prior_dropped", + "router_bits", + "row_bound", + "slack_edit", + "swap_orientation" + ], + "envelope": { + "compiler": 25934336, + "hosted_rebased_pervertex": 3588959010114264, + "local_adapters": 387056, + "local_primitive_bound": 10038040553630, + "local_primitive_bound_bits": 44, + "nonlocal_items": 10330706, + "selected_primitives": 28625376, + "unhosted_pervertex": 3588959010714576, + "used": 6466906000439144, + "wrapper_factors": 9953280 + }, + "guards": { + "group": "|Sp(72,2)| = |O(73,2)|", + "group_bits": 2628, + "halving": [ + 5329, + 4608 + ], + "headroom_bits": { + "literal": 64716, + "local_primitive_bound": 4, + "logical": 3370, + "precision": 9988, + "router": 22012, + "streamed_mass_below_2E": 97352, + "tape": 109998 + }, + "prefix": { + "charged": 512, + "global_bits": 397, + "local_max": 68 + }, + "row": [ + 16469, + 20161 + ], + "stock_bits": 2642 + }, + "native": { + "kappa": "836330098538459/500000000000000000", + "min_slack_names": [ + "lambda_above_tau", + "lambda_above_internal", + "lambda_prime_above_lambda" + ] + }, + "profile": { + "calls": 144, + "deficit": 5120, + "halving": [ + 5329, + 4608 + ], + "idle": { + "1": 2276, + "3": 377, + "7": 7, + "48": 4866 + }, + "idle_children": 7526, + "live": 14336, + "local": { + "1": 347328, + "2": 60192, + "3": 62208, + "4": 20448, + "5": 11808, + "8": 1152 + }, + "rank_mass": 1041408 + }, + "same_as_1042": { + "envelope": true, + "guards": true + }, + "status": "PASS" + }, + "seed81_binding": { + "audit_constant": "research/community-frontier1042-audit", + "selected_at_base": "research/community-frontier1094-audit/ASSEMBLY.json", + "stale": true + }, + "status": "PASS_FRONTIER1094_CERTIFICATE_BINDING_AUDIT" +} diff --git a/research/frontier1094-certificate-binding-audit/SOURCES.json b/research/frontier1094-certificate-binding-audit/SOURCES.json new file mode 100644 index 0000000000..eff52768f1 --- /dev/null +++ b/research/frontier1094-certificate-binding-audit/SOURCES.json @@ -0,0 +1,78 @@ +{ + "schema_version": 1, + "base_commit": "0b1cccf86e2f5132ed286a26ef0a681a495740ea", + "files": [ + { + "path": "certificates/checkpoints/frontier1042.json", + "usage": "input", + "git_blob": "f451ced6626a1f03aba6915ce23a136b01ebe51d", + "sha256": "207d1f49f113c585024b9d3c17eadbb8b1be17c1321e3d190aabe2f18ce1c5b7" + }, + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "ae6a99f28aa468649eb66a361e764d769363bf11", + "sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "06c96f5579bb67ed1b86d334e78fbed7da6945f1", + "sha256": "6686ad58f1fbdbc87134a78901b60fd53a20d3984355e91defbbebc9e9fa8075" + }, + { + "path": "research/community-frontier1042-audit/ASSEMBLY.json", + "usage": "input", + "git_blob": "4e308dc23da97373d66e5d8d4a68b0661caea8e9", + "sha256": "093f35445812ea96fe1bfe6a3af7d769cb7f274e08f4fb30f71a17ed1161e54e" + }, + { + "path": "research/community-frontier1042-audit/selected-replay.tar.gz", + "usage": "input", + "git_blob": "6f4dc6fe7631d8aacf8081fcaecf32197181685b", + "sha256": "22c3f4dce4b897a1d423d1388801933e288b6a6b1906cb15e1b16a5eb68db754" + }, + { + "path": "research/community-frontier1094-audit/ASSEMBLY.json", + "usage": "input", + "git_blob": "5fd676df060f3b450782fdf5ff5f6beb63a5eeb0", + "sha256": "1122cb3a575f8c788345fc1bf4c108ac7c3250fb81a5988671f5eb04b3ab3045" + }, + { + "path": "research/community-frontier1094-audit/INDEPENDENT1094.json", + "usage": "input", + "git_blob": "009a385e26858058a18188364078d162aa6f9519", + "sha256": "301fb8a0e4ab7e3c383ff974c54c08178283b2a3453c5282757f692a3c7a4bfd" + }, + { + "path": "research/community-frontier1094-audit/RESULT.json", + "usage": "input", + "git_blob": "131d9c96a54632ae385ced4138fd7f30ad448a3e", + "sha256": "1e3e47e9ec24bcb6fb5f703b7fce0aab658d84ff72bfae5da3ae429d17b6e752" + }, + { + "path": "research/community-frontier1094-audit/selected-replay.tar.gz", + "usage": "input", + "git_blob": "c24daf067f9c543421d89ca2eeaa4eb78a57fb6f", + "sha256": "f1da80610bf33c58527f18ad63b4350d0b864e1d4486141ee17ac9bed4d529d6" + }, + { + "path": "research/complex-t16-rare-pattern-exchanges/PROFILE.json", + "usage": "input", + "git_blob": "7acbdeb81015d4681b5773489369a2a8b0d46d79", + "sha256": "cf539f314584ee0b6d7102d2344be96a63defa88b9d9ab6ffe05cddd6c13a874" + }, + { + "path": "research/complex-t16-rare-pattern-exchanges/data/PLAN.json", + "usage": "input", + "git_blob": "f1bec76e8e9b7a1f09c1e05cb6cce973b6e59f1b", + "sha256": "7bd786ba8e66408f02aa9ef446eaf20c1bfe981ea2e4dd1e5a929f0aa7767bc0" + }, + { + "path": "research/e8-bit-p111-tuned/tune/EXPECTED.json", + "usage": "input", + "git_blob": "e293ddc557742637f9f679f083a1a282d87b1b13", + "sha256": "b9f0e5ca038abe837b0007c8fe006f366a6f02009244ac57705a8a200e2301f4" + } + ] +} diff --git a/research/frontier1094-certificate-binding-audit/TASK.json b/research/frontier1094-certificate-binding-audit/TASK.json new file mode 100644 index 0000000000..b557d59343 --- /dev/null +++ b/research/frontier1094-certificate-binding-audit/TASK.json @@ -0,0 +1,60 @@ +{ + "schema_version": 1, + "task_id": "supplier-boundary-audit", + "priority_revision": 3, + "base_commit": "0b1cccf86e2f5132ed286a26ef0a681a495740ea", + "original_card": { + "id": "supplier-boundary-audit", + "question": "Does one selected supplier obligation follow from its actual source-bound checks?", + "starting_points": [ + "certificates/selected-result.json", + "research/owner-boundary-audit/README.md" + ], + "methods": [ + "Trace one hypothesis through the source, checker and complete caller.", + "Construct one semantically invalid but superficially well-formed fixture and test rejection." + ], + "acceptance_gate": "Pin the current sources and one obligation; the historical owner audit is an example, not evidence of a current bug.", + "first_step": { + "command": [ + "python3", + "-B", + "research/owner-boundary-audit/verify.py" + ], + "expected": "PASS_PR626_NEXT_TOUCH_BOUNDARY_AUDIT", + "inspect": "Identify why the timing-only omission passes but the full production controller still rejects it.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "first_experiment": "Choose one current supplier obligation and trace whether its acceptance depends on an independent check.", + "bottleneck_link": "Closing a current acceptance gap or proof obligation strengthens reliability even without changing kappa.", + "allowed_variations": [ + "Audit one named current condition using a new semantic counterexample." + ], + "scope_change_triggers": [ + "Reporting the historical timing-only diagnostic as a new current acceptance bug." + ], + "overlap_terms": [ + "owner boundary", + "bridge omission", + "hosting" + ] + }, + "scope_status": "refined", + "actual_scope": "For the selected #1094 certificate: does `make frontier1094-verify` bind the committed ASSEMBLY.json (endpoints, bootstrap, 47+47 outer slacks, profile) to its cold replay, and do those committed fields follow from their pinned receipts? Tested with the unchanged seed81 invoice/outer recheck, an exact receipt delta against #1042, five-way profile binding and one well-formed, arithmetic-consistent mutant certificate with an uncertified complex endpoint and unchanged kappa.", + "scope_change_reason": "The card's generic supplier obligation is narrowed to one concrete obligation: that the published certificate fields beyond kappa are the replay's output. The owner-boundary example's timing question is not revisited.", + "bottleneck_link": "Side result for review trust: downstream audits and future candidates read the selected certificate's endpoints and outer slacks, so a reproduce path that binds only kappa could let a non-replay certificate stand. No kappa or construction change.", + "budget_minutes": 60, + "stop_rule": "Stop after the invoice/outer recheck, receipt delta, profile binding, one endpoint mutant tested on every reproduce-path layer and the proposed binding evaluated on published output; do not run the long cold replay or edit the selected scripts.", + "outcome": "completed", + "evidence": "RESULT.json: seed81 recheck PASS on #1094 with 15 controls and exact #1042 reproduction; 14-field receipt delta; five equal profile copies; mutant (complex_lower + 1e-24, kappa unchanged) accepted by the arithmetic layer and by verify_selected_result.check after repinning, never read by verify_frontier1094.py, rejected by the exact moment (residual lower bound 1.62e-24 > 0); proposed binding passes on the published replay output and rejects the mutant. Seed81's own entry point is stale on main.", + "author": "rtyu193-rgb", + "ai_assistance": "Claude Code (Anthropic Claude Opus 5.5) chose the scope, wrote verify.py and the prose; reused seed81 and DE diagnostic code unchanged; one session, no subagents, no independent human review.", + "open_questions": [ + { + "question": "Should the selected reproduce path require the replay's ASSEMBLY.json to equal the selected certificate (bytes or parsed JSON)?", + "why_it_matters": "Today a promotion committing a non-replay certificate with the same kappa passes make frontier1094-verify; downstream audits read that certificate's endpoints and outer slacks.", + "first_step": "Add the one-line requirement to scripts/verify_frontier1094.py and run one cold make frontier1094-verify on Linux, comparing raw and parsed equality; consider the same for the frontier1042/942/890/799 replays, which also contain no certificate reference.", + "blocked_by": "Maintainer authorization to edit the selected reproduce script and a long cold baseline replay." + } + ] +} diff --git a/research/frontier1094-certificate-binding-audit/VERIFY.json b/research/frontier1094-certificate-binding-audit/VERIFY.json new file mode 100644 index 0000000000..282b43775f --- /dev/null +++ b/research/frontier1094-certificate-binding-audit/VERIFY.json @@ -0,0 +1,30 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "certificates/checkpoints/frontier1042.json", + "research/community-frontier1042-audit/ASSEMBLY.json", + "research/community-frontier1042-audit/selected-replay.tar.gz", + "research/community-frontier1094-audit/ASSEMBLY.json", + "research/community-frontier1094-audit/INDEPENDENT1094.json", + "research/community-frontier1094-audit/RESULT.json", + "research/community-frontier1094-audit/selected-replay.tar.gz", + "research/complex-t16-rare-pattern-exchanges/PROFILE.json", + "research/complex-t16-rare-pattern-exchanges/data/PLAN.json", + "research/e8-bit-p111-tuned/tune/EXPECTED.json" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 180, + "checks": "Unchanged seed81 invoice/outer recheck of the committed #1094 certificate with 15 controls and #1042 reproduction; exact 14-field receipt delta; five-way profile binding; endpoint mutant tested on the arithmetic layer, verify_selected_result.check, verify_frontier1094.py source and the exact moment; proposed binding on published replay output; kappa-edit control; RESULT.json comparison." + } + ] +} diff --git a/research/frontier1094-certificate-binding-audit/verify.py b/research/frontier1094-certificate-binding-audit/verify.py new file mode 100644 index 0000000000..d82204f610 --- /dev/null +++ b/research/frontier1094-certificate-binding-audit/verify.py @@ -0,0 +1,286 @@ +#!/usr/bin/env python3 +"""Selected #1094 certificate: invoice/outer recheck and certificate-to-replay binding audit. + +Adversarial audit (supplier-boundary-audit). Standard library and git only. +Audited code is loaded as exact Git objects at BASE, so later repairs of the +audited scripts do not silently change what this package checked. + + 1. Apply the unchanged frontier1042-invoice-audit-seed81 recheck (profile, + per-vertex envelope, nine finite guards, 7+7 bootstrap levels, 47+47 outer + slacks, 15 mutation controls) to the committed #1094 certificate and its + pinned receipts, bound directly to the certificate bytes rather than the + moving selected pointer. Reproduce seed81's own #1042 result as a control. + 2. Exact field-level delta of the #1094 receipts against #1042. + 3. Equality of the #1094 complex profile across five artifacts. + 4. A well-formed mutant certificate: complex endpoint + 1e-24 (the next grid + point, rejected by the exact moment), with bootstrap, outer slacks and moment + records recomputed so every arithmetic identity holds and kappa is unchanged. + It is tested against each check on the reproduce path. + 5. The proposed one-line binding (replay ASSEMBLY sha == certificate_sha256), + evaluated on the published replay output. + +Prepared for rtyu193-rgb with Claude Code (Claude Opus 5.5). Apache-2.0. +""" +import argparse +import ast +import copy +import hashlib +import json +from pathlib import Path +import subprocess +import sys +import tarfile +import tempfile +import types +from fractions import Fraction as Q + +if not __debug__: + raise SystemExit("checks use assert; run without -O") + +PKG = Path(__file__).resolve().parent +ROOT = PKG.parents[1] +BASE = "0b1cccf86e2f5132ed286a26ef0a681a495740ea" +CODE = { # audited code as exact Git blobs at BASE + "seed81": ("research/frontier1042-invoice-audit-seed81/verify.py", "8ee1d7a01473e1b5674710165566e4e9761f7c65"), + "de": ("research/selected-suppliers-de-diagnostic/verify.py", "f9a9d5e5103b6ccbadb3f50fea34e25ccfce7ff1"), + "selected": ("scripts/verify_selected_result.py", "c755b76e0d44ba4917aa94440ebe54daefce5b2a"), + "replay": ("scripts/verify_frontier1094.py", "96e6c1386bd052b9bcaf136d934406f3f0c3f777"), + "candidate": ("research/complex-t16-rare-pattern-exchanges/verify.py", "9d471cf90835bc91d32bb0216c2bb867011a7420"), +} +A1094, P1094 = "research/community-frontier1094-audit", "candidate/strict" +A1042, P1042 = "research/community-frontier1042-audit", "t16" +CERT1094_SHA = "1122cb3a575f8c788345fc1bf4c108ac7c3250fb81a5988671f5eb04b3ab3045" +GRID = Q(1, 10 ** 24) +ETA = BETA = Q(1, 10 ** 24) +EXPECTED_DELTA = { + "invoice": ["/controller_audit_sha256", "/owner_audit_sha256", "/template_sha256"], + "owners": ["/actual_73column_sigmas", "/controller_audit_sha256", "/cross_replica_helper_roles", + "/explicit_idle_remainder_children", "/paid_profile/1", "/paid_profile/16", "/paid_profile/2", + "/paid_profile/3", "/paid_profile/48", "/paid_profile/7", "/template_sha256"], +} + + +def sha256(b): + return hashlib.sha256(b).hexdigest() + + +def git_blob(b): + return hashlib.sha1(b"blob %d\0" % len(b) + b).hexdigest() + + +def git_show(path): + return subprocess.run(["git", "-C", str(ROOT), "show", BASE + ":" + path], + capture_output=True, check=True).stdout + + +def load_module(key): + path, blob = CODE[key] + src = git_show(path) + assert git_blob(src) == blob, f"audited code blob differs: {path}" + mod = types.ModuleType("audited_" + key) + mod.__file__ = str(ROOT / path) + exec(compile(src, str(ROOT / path), "exec"), mod.__dict__) + return mod + + +def load_record(audit, prefix, cert_sha): + """Certificate and receipts, each bound by hash; no moving pointer is read.""" + cert = (ROOT / audit / "ASSEMBLY.json").read_bytes() + assert sha256(cert) == cert_sha, audit + " certificate bytes" + asm = json.loads(cert) + with tarfile.open(ROOT / audit / "selected-replay.tar.gz") as tar: + get = lambda n: tar.extractfile(prefix + "/" + n).read() + owner, invoice, archived = (get("global/audit/OWNERS-AND-PROFILE.json"), + get("global/audit/PREFIX-AND-INVOICE.json"), get("ASSEMBLY.json")) + assert archived == cert, audit + " archived replay assembly differs from committed certificate" + assert sha256(owner) == asm["input_sha256"]["owner_audit"], audit + " owner receipt pin" + assert sha256(invoice) == asm["input_sha256"]["fresh_invoice"], audit + " invoice receipt pin" + bit = (ROOT / asm["bit_supplier"]["path"]).read_bytes() + assert git_blob(bit) == asm["bit_supplier"]["git_blob_sha1"], "PR589 blob pin" + return dict(asm=asm, owner=json.loads(owner), invoice=json.loads(invoice), bit=json.loads(bit)), cert + + +def delta(x, y, path=""): + if isinstance(x, dict) and isinstance(y, dict): + out = [] + for k in sorted(set(x) | set(y), key=str): + out += [f"{path}/{k}"] if (k in x) != (k in y) else delta(x[k], y[k], f"{path}/{k}") + return out + if isinstance(x, list) and isinstance(y, list) and len(x) == len(y): + return [p for i, (u, v) in enumerate(zip(x, y)) for p in delta(u, v, f"{path}[{i}]")] + return [] if x == y else [path] + + +def profile(d): + return {int(k): int(v) for k, v in d.items() if int(v)} + + +def exact_decimal(x, digits=24): + n = x * 10 ** digits + assert n.denominator == 1 + s = str(n.numerator).rjust(digits + 1, "0") + return s[:-digits] + "." + s[-digits:] + + +def make_mutant(asm, s81, shift=GRID): + """Arithmetic-consistent certificate claiming acceptance at complex endpoint + shift.""" + b, c = Q(asm["complex_lower"]) + shift, Q(asm["bit_lower"]) + a, cuts = s81.bootstrap(b, c, ETA, BETA) + k = s81.kappa_from(a, ETA) + slacks, _ = s81.assembly_slacks(a, b, k, ETA, BETA) + m = copy.deepcopy(asm) + m["complex_lower"], m["complex_decimal"] = str(b), exact_decimal(b) + m["bootstrap"] = [dict(exponent=str(x["exponent"]), gap=str(x["gap"]), cutoff_log2=str(x["cutoff_log2"])) + for x in cuts] + m["outer"] = {n: str(slacks[n]) for n in asm["outer"]} + for e in m["moments"]: + if e["side"] == "complex": + e["endpoint"] = str(Q(e["endpoint"]) + shift) + return m, k + + +def strings_in(src): + return [n.value for n in ast.walk(ast.parse(src)) if isinstance(n, ast.Constant) and isinstance(n.value, str)] + + +def rejects(fn): + try: + fn() + except Exception as exc: # the audited checkers raise ValueError / Fail / AssertionError + return type(exc).__name__ + ": " + str(exc)[:120] + return None + + +def main(): + ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + ap.add_argument("--write", action="store_true", help="regenerate RESULT.json") + args = ap.parse_args() + s81, de, sel = load_module("seed81"), load_module("de"), load_module("selected") + out = {} + + # 1. Invoice/outer recheck of the committed #1094 certificate; #1042 reproduction as control. + record_base = json.loads(git_show("certificates/selected-result.json")) + assert record_base["certificate"] == A1094 + "/ASSEMBLY.json" + assert record_base["certificate_sha256"] == CERT1094_SHA + d1094, cert1094 = load_record(A1094, P1094, CERT1094_SHA) + chk1042 = json.loads((ROOT / "certificates/checkpoints/frontier1042.json").read_bytes()) + assert chk1042["certificate"] == A1042 + "/ASSEMBLY.json" + d1042, _ = load_record(A1042, P1042, chk1042["certificate_sha256"]) + r1042 = s81.run_all(d1042) + published = json.loads(git_show("research/frontier1042-invoice-audit-seed81/RESULT.json")) + for key in ("profile", "envelope", "guards", "native", "conservative"): + assert json.loads(json.dumps(r1042[key], sort_keys=True)) == published[key], "seed81 #1042 result not reproduced: " + key + r1094 = s81.run_all(d1094) + ctl = s81.controls(d1094) + assert len(ctl) == 15 + out["recheck_1094"] = dict(status="PASS", controls_rejected=sorted(ctl), **{ + k: r1094[k] for k in ("profile", "envelope", "guards")}, + native=dict(kappa=r1094["native"]["kappa"], min_slack_names=r1094["native"]["min_slack_names"]), + conservative=dict(kappa=r1094["conservative"]["kappa"])) + out["recheck_1094"]["same_as_1042"] = {k: r1094[k] == r1042[k] for k in ("envelope", "guards")} + # seed81's own entry point binds the moving pointer; at BASE it targets a non-selected record. + out["seed81_binding"] = dict(audit_constant=s81.AUDIT, selected_at_base=record_base["certificate"], + stale=s81.AUDIT + "/ASSEMBLY.json" != record_base["certificate"]) + + # 2. Exact receipt delta against #1042. + got = dict(invoice=delta(d1042["invoice"], d1094["invoice"]), owners=delta(d1042["owner"], d1094["owner"])) + assert got == EXPECTED_DELTA, got + out["receipt_delta_vs_1042"] = got + + # 3. Profile binding across five artifacts. + P = "research/complex-t16-rare-pattern-exchanges/" + ind = json.loads((ROOT / A1094 / "INDEPENDENT1094.json").read_bytes()) + copies = { + "certificate complex_profile": profile(d1094["asm"]["complex_profile"]), + "archived OWNERS-AND-PROFILE paid_profile": profile(d1094["owner"]["paid_profile"]), + "package PROFILE.json": profile(json.loads((ROOT / P / "PROFILE.json").read_bytes())), + "package data/PLAN.json profile": profile(json.loads((ROOT / P / "data/PLAN.json").read_bytes())["profile"]), + "INDEPENDENT1094 owner-audited profile": profile(ind["owner"]["profile"]), + } + ref = copies["certificate complex_profile"] + assert all(v == ref for v in copies.values()), "profile copies disagree" + out["profile_binding"] = dict(artifacts=sorted(copies), equal=True, profile=dict(sorted(ref.items()))) + + # 4. The mutant certificate against each layer of the reproduce path. + asm = d1094["asm"] + mutant, k_mut = make_mutant(asm, s81) + assert k_mut == Q(asm["kappa"]) and mutant["kappa"] == asm["kappa"], "mutant must keep kappa" + layers = {} + layers["seed81_invoice_outer_arithmetic"] = rejects(lambda: s81.run_all(dict(d1094, asm=mutant))) + mbytes = (json.dumps(mutant, indent=2) + "\n").encode() + with tempfile.TemporaryDirectory(dir=PKG) as tmp: + rel = Path(tmp).relative_to(ROOT).as_posix() + "/ASSEMBLY.json" + (ROOT / rel).write_bytes(mbytes) + rec = dict(record_base, certificate=rel, certificate_sha256=sha256(mbytes)) + layers["verify_selected_result_check"] = rejects(lambda: sel.check(rec, ROOT)) + assert sel.check(record_base, ROOT) == Q(asm["kappa"]) + # Control: the same layer does bind kappa itself. + bad = dict(mutant, kappa=str(Q(asm["kappa"]) + Q(1, 10 ** 18))) + bbytes = json.dumps(bad).encode() + (ROOT / rel).write_bytes(bbytes) + kappa_control = rejects(lambda: sel.check(dict(rec, certificate_sha256=sha256(bbytes)), ROOT)) + assert kappa_control is not None, "kappa edit must be rejected" + replay_src = git_show(CODE["replay"][0]).decode() + cert_strings = sorted(s for s in strings_in(replay_src) if "certificate" in s or "selected" in s) + refs = [s for s in cert_strings if any(t in s for t in ("frontier1094-audit", "selected-result", + "certificate_sha256"))] + makefile = git_show("Makefile").decode().splitlines() + i = makefile.index("frontier1094-verify: selected-record-check") + recipe = [line.strip() for line in makefile[i + 1:i + 3]] + assert recipe[-1] == 'python3 -B scripts/verify_frontier1094.py --work "$$work/replay"', recipe + layers["verify_frontier1094_reads_committed_certificate"] = bool(refs) + assert not refs, refs + # The candidate stage it runs binds only status, kappa and the profile (to package PROFILE.json). + cand_src = git_show(CODE["candidate"][0]) + assert git_blob(cand_src) == CODE["candidate"][1] + cand_strings = set(strings_in(cand_src.decode())) + assert {"kappa_decimal", "complex_profile", "PROFILE.json"} <= cand_strings + cand_unbound = sorted(f for f in ("complex_lower", "bootstrap", "outer", "moments", "conservative_outer", + "frontier1094-audit") if f not in cand_strings) + assert len(cand_unbound) == 6, cand_unbound + # Exact moment (code-disjoint enclosure of the endpoint package) at both endpoints. + bill, _ = de.complex_ledger(asm, ind) + lo, hi = bill.residual(Q(asm["complex_lower"])) + mlo, mhi = bill.residual(Q(mutant["complex_lower"])) + assert hi < 0 < mlo, "moment must accept the certified endpoint and reject the mutant" + layers["exact_moment_at_mutant_endpoint"] = "rejects: residual lower bound > 0" + assert layers["seed81_invoice_outer_arithmetic"] is None and layers["verify_selected_result_check"] is None + out["mutant"] = dict( + change="complex_lower + 1e-24 with bootstrap, 47 outer slacks, complex moment endpoints recomputed", + complex_lower=mutant["complex_lower"], kappa_unchanged=mutant["kappa"], + layers=dict(seed81_invoice_outer_arithmetic="accepts", + verify_selected_result_check="accepts after repinning certificate_sha256", + verify_frontier1094="never reads the committed certificate; replay binds only kappa and profile", + exact_moment="rejects"), + moment_residual_upper_at_certified=f"{float(hi):.6e}", moment_residual_lower_at_mutant=f"{float(mlo):.6e}", + kappa_edit_control=kappa_control, frontier1094_verify_recipe=recipe, + verify_frontier1094_certificate_strings=cert_strings, + candidate_stage_binds=["status", "kappa_decimal", "complex_profile == package PROFILE.json"], + candidate_stage_never_names=cand_unbound) + + # 5. Proposed binding: replay output bytes must equal the selected certificate. + with tarfile.open(ROOT / A1094 / "selected-replay.tar.gz") as tar: + replay_out = tar.extractfile(P1094 + "/ASSEMBLY.json").read() + published_result = json.loads((ROOT / A1094 / "RESULT.json").read_bytes()) + proposed = lambda replay_bytes, record: sha256(replay_bytes) == record["certificate_sha256"] + assert proposed(replay_out, record_base) and published_result["assembly_sha256"] == CERT1094_SHA + assert not proposed(replay_out, dict(record_base, certificate_sha256=sha256(mbytes))) + out["proposed_binding"] = dict( + check="require(sha(work/'candidate/strict/ASSEMBLY.json') == selected['certificate_sha256'])", + published_replay_output_matches=True, published_result_assembly_sha256_matches=True, + rejects_mutant=True) + + out["status"] = "PASS_FRONTIER1094_CERTIFICATE_BINDING_AUDIT" + text = json.dumps(out, indent=1, sort_keys=True) + "\n" + target = PKG / "RESULT.json" + if args.write: + target.write_text(text, encoding="utf-8", newline="\n") + print("WROTE", target.relative_to(ROOT).as_posix()) + else: + assert target.read_text(encoding="utf-8") == text, "RESULT.json differs from regenerated result" + print(f"{out['status']} invoice_outer=PASS controls=15 receipt_delta=14 profile_copies=5 " + f"mutant_accepted_by=arithmetic,selected_check mutant_rejected_by=exact_moment no_new_kappa") + + +if __name__ == "__main__": + main()