From 1356813dddd0e03ea138743a799c2aece15f7d44 Mon Sep 17 00:00:00 2001 From: Arham-Tahir64 Date: Tue, 13 Oct 2026 16:45:37 -0600 Subject: [PATCH] Audit: bind retained PR589 supplier identity and COPY deficit --- .../retained-bit-supplier-binding/README.md | 150 ++++++++++++++ .../retained-bit-supplier-binding/RESULT.json | 47 +++++ .../SOURCES.json | 84 ++++++++ .../retained-bit-supplier-binding/TASK.json | 107 ++++++++++ .../retained-bit-supplier-binding/VERIFY.json | 43 ++++ .../retained-bit-supplier-binding/guard.py | 187 ++++++++++++++++++ .../test_guard.py | 144 ++++++++++++++ .../retained-bit-supplier-binding/verify.py | 59 ++++++ 8 files changed, 821 insertions(+) create mode 100644 research/retained-bit-supplier-binding/README.md create mode 100644 research/retained-bit-supplier-binding/RESULT.json create mode 100644 research/retained-bit-supplier-binding/SOURCES.json create mode 100644 research/retained-bit-supplier-binding/TASK.json create mode 100644 research/retained-bit-supplier-binding/VERIFY.json create mode 100644 research/retained-bit-supplier-binding/guard.py create mode 100644 research/retained-bit-supplier-binding/test_guard.py create mode 100644 research/retained-bit-supplier-binding/verify.py diff --git a/research/retained-bit-supplier-binding/README.md b/research/retained-bit-supplier-binding/README.md new file mode 100644 index 0000000000..57f9bda278 --- /dev/null +++ b/research/retained-bit-supplier-binding/README.md @@ -0,0 +1,150 @@ +# Bind the retained PR589 supplier identity + +**Supplemental source-binding guard and finite audit; no new kappa.** + +[PR1277](https://github.com/CrocSwap/integer-mult-bounds/pull/1277) identifies a +remaining question: the PR799 assembly can name a false `bit_supplier` commit +and Git blob while retaining its accepted numerical result. Its primary finding +and suggested ancestry-equality repair belong to Sagar Thakrar. This package +answers the separate supplier-identity question with an opt-in executable guard. +It changes no existing file or production acceptance predicate. + +All four committed PR741/PR799/PR1042/PR1094 assemblies and the archived PR589 +bit result pass. The guard independently connects the cited source to its +actual word and deficit, rather than treating a successful endpoint comparison +as proof of provenance. Normal verification is read-only. + +## Exact boundary and evidence + +The trusted historical selection is main +`bce54fb3f895cbe5cd4c0eb477c3afeed100190f`; its reviewed PR589 head is +`a5afc8c6169ea61ba7c51dfd3cade02cc7b13b46`. +[SOURCES.json](SOURCES.json) pins every external input and the governing source +code. The guard imports no supplier, frame checker or moment engine. + +1. **Git provenance.** The original source uses `research/e8-bit-p111/`. + Main retains it as `research/e8-bit-p111-tuned/`. The EXPECTED record and + compressed word are byte-identical at the exact PR589 head, the integration + commit `b3eb785ac5b4b1ca2beea0f80db078a505626a90`, and the pinned live inputs. + Git confirms that PR589 is a direct parent of that integration commit and + that the integration precedes this package's base. The original-to-retained + rename is checked explicitly; the assembly's retained path is not assumed to + have existed on the original contributor branch. +2. **Word-to-deficit binding.** Following the source format's D/A frame + assignments up to COPY and performing separately implemented rational row + elimination gives nine ranks `[7,7,7,7,7,7,7,7,7]`, hence decoder constant 63. + With the retained nine-stage, 32-replica layout, `K=4`, `M=64`, `v=111`, + `W=28416`, the full recorded profile has rank mass 1808352. Both sides give + `MW - mass = T(2Kv - L*cst) = 10272`. +3. **Consumer guard.** Every assembly must name that exact source commit, + integration commit, repository, PR, retained path and EXPECTED blob, and the + independently derived word/deficit. Its bit input digest, endpoint, decimal + and bad-residue surcharge must agree with that source. A supplied bit result + must preserve the entire priced profile, inventory and recorded bit budget. + +The EXPECTED Git blob is `e293ddc557742637f9f679f083a1a282d87b1b13`; the +compressed word blob is `85a4499bf9e4911a705d50567a2c2ef6cf23739a`. +The decompressed word SHA256 is +`5642fd0e35a1acc11acff8d0c08350c1617e95f310d4d35ad63a651f9eeeba0b`. +These are source pins, not hashes of newly regenerated gzip containers. + +[RESULT.json](RESULT.json) is deterministic. Ten test groups include 23 +rejection fixtures: six false provenance fields with unchanged endpoint and +kappa; a different real commit containing the identical EXPECTED blob; a +compensating `[6,8]` COPY-rank substitution preserving total rank 63; an actual +COPY-frame change; profile mass/type faults; endpoint/digest/surcharge/deficit +faults; bit-result faults including a rank-mass-preserving histogram change; +the CLI zeroed-source fixture; and corrupted relocated source bytes. + +The positive tests cover the four actual assemblies, the actual bit result, +and physically relocated inputs using the same Git object database. Checks run +under `-I -O -B`; this guard does not rely on Python assertions. + +## Reproduce and use + +Python 3.12 or later, Git, full repository history and no Python dependencies: + +```sh +python3 scripts/research_package.py --package research/retained-bit-supplier-binding --check-only +python3.12 scripts/research_package.py --package research/retained-bit-supplier-binding +``` + +Expected: `PASS_RETAINED_PR589_SUPPLIER_BINDING assemblies=4 deficit=10272`, +ten passing tests, and `PASS_REGISTERED_RESEARCH_PACKAGE`. + +After a replay that retains **this exact PR589 supplier**, additionally guard +its actual outputs: + +```sh +python3 -I -O -B research/retained-bit-supplier-binding/verify.py \ + --assembly /absolute/replay/global/ASSEMBLY.json \ + --bit-result /absolute/replay/ancestor/bit/RESULT9.json +``` + +Paths are explicit; the guard never follows a receipt's machine-local ancestor +path. A different word or source version requires a new contract and pins. +`--write /absolute/receipt.json` explicitly writes a freshly checked receipt; +otherwise the default fixture run also compares against committed RESULT.json. + +## What this establishes, and what remains + +This adds the executable supplier-identity check requested in PR1277; it does +not replace PR1277's broader equality-to-the-recorded-ancestry repair. The +earlier finding that a zeroed supplier passes `check_selected` is credited to +PR1277 and was not freshly replayed here. This package freshly tests rejection +by the new guard, including its real CLI. It does not claim that the unchanged +production pipeline now rejects the fixture. + +The frame trace is used only to measure COPY ranks, not to establish frame +legality, scalar restoration or H1-H5. The recorded global profile and bit +budget remain inputs. No native/scalar/phase/emitted-controller replay, +orthogonal-chart proof, cold supplier rebuild, certified moment endpoint, +complex-side verification, all-size/compiler, hosting, precision/tape, +exact-recovery or analytic-transfer proof is performed. No full multiplication +theorem, runtime improvement, selected-frontier change or execution +authentication is claimed. + +## Task and overlap + +Card `supplier-boundary-audit`, refined to the PR589 identity boundary; chooser +nonce `78116c731f9a59be32e8cd1544265921`, adversarial-audit track, priority +revision 2. [TASK.json](TASK.json) records the scope, method, domain and stop rule. +The card's historical owner audit and current `research_baseline.py` both pass +as orientation controls; they are not new results. + +An entry snapshot covered 806 open PRs including drafts, with complete PR +pagination. The repository overlap helper searched their titles/bodies and +local top-level package notes/ledger. Discussions' start-here, listing and live +handoff thread were read, but complete Discussion pagination was unavailable. +The browser was signed out and the GitHub connector exposes no Discussion-write +tool, so the claim is local. No absence-of-overlap or novelty proof is asserted. +Final refresh details are recorded in TASK.json and the PR. + +Nearest work: PR1277 at `02d279515ff1fc468ab99a19d89461f1b6391507` owns the +finding and supplies the explicit next question. PR1307 audits the selected +bit allocation's physical projectors; PR1312 audits complex-owner X2 coverage. +Neither is an input here. This package adds source-to-Git and word-to-deficit +enforcement, not another owner-window or projector census. + +## Open next questions + +Should a future unpinned replay wrapper require both this guard and PR1277's +ancestry equality? This would protect the cited supplier identity as well as +the particular retained ancestry receipt. The smallest useful step is to apply +both in a successor wrapper, check PR1277's false-supplier/timing variants and +then run a complete cold replay. Maintainer acceptance and versioned source and +coverage pins block adoption; changing frozen supplements is outside this +contribution. The structured question is in TASK.json. + +## Credit + +Sagar Thakrar / PR1277 for the finding and next question; DreamingOfClouds / +PR589 and eumemic / PR555 for the word and retained checker/hosting lineage; +PR545's rank-mass identity; Douglas Colkitt for the integration and composition +bindings; Rohan Arun, Jeremy Kothe, Hao Yan and the selected complex lineage; +nightangelflowerwin-ops / PR865 and Lucas Steinmetz / PR838 for the replay +coverage lineage. Existing source notices and licenses are retained. + +Prepared by Arham Tahir with substantial OpenAI Codex assistance in research, +implementation, verification and writing. No subagents or independent human +peer review. New material is Apache-2.0. diff --git a/research/retained-bit-supplier-binding/RESULT.json b/research/retained-bit-supplier-binding/RESULT.json new file mode 100644 index 0000000000..06510400c0 --- /dev/null +++ b/research/retained-bit-supplier-binding/RESULT.json @@ -0,0 +1,47 @@ +{ + "status": "PASS_RETAINED_PR589_SUPPLIER_BINDING", + "base_commit": "bce54fb3f895cbe5cd4c0eb477c3afeed100190f", + "supplier": { + "pr": 589, + "repository": "CrocSwap/integer-mult-bounds", + "commit": "a5afc8c6169ea61ba7c51dfd3cade02cc7b13b46", + "merged_as": "b3eb785ac5b4b1ca2beea0f80db078a505626a90", + "path": "research/e8-bit-p111-tuned/tune/EXPECTED.json", + "git_blob_sha1": "e293ddc557742637f9f679f083a1a282d87b1b13", + "word": { + "v": 111, + "decoder_constant": 63, + "copy_ranks": [ + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7 + ] + }, + "derived_deficit": 10272, + "deficit_formula": "T(2Kv-L*cst), L=9 T=32 K=4 M=64" + }, + "git_objects": { + "tune/EXPECTED.json": "e293ddc557742637f9f679f083a1a282d87b1b13", + "tune/bitE8mut-p111-tuned.json.gz": "85a4499bf9e4911a705d50567a2c2ef6cf23739a" + }, + "record_sha256": "b9f0e5ca038abe837b0007c8fe006f366a6f02009244ac57705a8a200e2301f4", + "word_content_sha256": "5642fd0e35a1acc11acff8d0c08350c1617e95f310d4d35ad63a651f9eeeba0b", + "assemblies_checked": 4, + "bit_results_checked": 1, + "assembly_sha256": [ + "21e2df9286542c9e2786f3720d0f13de0d0a7a982761ebe2184f8f7f811c774d", + "65c7648a8edaeaf4e0b8de3e21eeda94fba124d0935010d45ac9f76375b72cec", + "093f35445812ea96fe1bfe6a3af7d769cb7f274e08f4fb30f71a17ed1161e54e", + "1122cb3a575f8c788345fc1bf4c108ac7c3250fb81a5988671f5eb04b3ab3045" + ], + "bit_result_sha256": "28795393651ef4fbbc6232eb2b32f7b39b91fbd5ea6d2315583f350714698055", + "live": 28416, + "rank_mass": 1808352, + "scope": "Pinned PR589 source identity, COPY-frame ranks and profile deficit; no scalar/phase/native replay, certified moment or all-size theorem." +} diff --git a/research/retained-bit-supplier-binding/SOURCES.json b/research/retained-bit-supplier-binding/SOURCES.json new file mode 100644 index 0000000000..ca4e11da57 --- /dev/null +++ b/research/retained-bit-supplier-binding/SOURCES.json @@ -0,0 +1,84 @@ +{ + "schema_version": 1, + "base_commit": "bce54fb3f895cbe5cd4c0eb477c3afeed100190f", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "ae6a99f28aa468649eb66a361e764d769363bf11", + "sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "c05fafaa25ba95b2d5af86b1800427198e3d20eb", + "sha256": "89b5928bc92c81e2647b6d702a7ad85a6795b8f44e2eb267b2ff3145d8f2b2ce" + }, + { + "path": "research/community-frontier1042-audit/ASSEMBLY.json", + "usage": "input", + "git_blob": "4e308dc23da97373d66e5d8d4a68b0661caea8e9", + "sha256": "093f35445812ea96fe1bfe6a3af7d769cb7f274e08f4fb30f71a17ed1161e54e" + }, + { + "path": "research/community-frontier1094-audit/ASSEMBLY.json", + "usage": "input", + "git_blob": "5fd676df060f3b450782fdf5ff5f6beb63a5eeb0", + "sha256": "1122cb3a575f8c788345fc1bf4c108ac7c3250fb81a5988671f5eb04b3ab3045" + }, + { + "path": "research/community-frontier741-audit/ASSEMBLY.json", + "usage": "input", + "git_blob": "d2a594a6fdb33907f8e6760aa00fd4650535930f", + "sha256": "21e2df9286542c9e2786f3720d0f13de0d0a7a982761ebe2184f8f7f811c774d" + }, + { + "path": "research/community-frontier741-audit/bit/RESULT9.json", + "usage": "input", + "git_blob": "d9f15563217bce0d348a63d46e930d0ae997e211", + "sha256": "28795393651ef4fbbc6232eb2b32f7b39b91fbd5ea6d2315583f350714698055" + }, + { + "path": "research/community-frontier799-audit/ASSEMBLY.json", + "usage": "input", + "git_blob": "a04bfd932a15196fe8e2418eae912ea745152593", + "sha256": "65c7648a8edaeaf4e0b8de3e21eeda94fba124d0935010d45ac9f76375b72cec" + }, + { + "path": "research/e8-bit-p111-tuned/code/xcheck_p.py", + "usage": "input", + "git_blob": "184f5dcf94a486cc7db91ca4db5865916bf26009", + "sha256": "af3decc877e27c00001cf56f50c6c09566e8e101297ab34c7860aed96a06d80e" + }, + { + "path": "research/e8-bit-p111-tuned/tune/EXPECTED.json", + "usage": "input", + "git_blob": "e293ddc557742637f9f679f083a1a282d87b1b13", + "sha256": "b9f0e5ca038abe837b0007c8fe006f366a6f02009244ac57705a8a200e2301f4" + }, + { + "path": "research/e8-bit-p111-tuned/tune/bitE8mut-p111-tuned.json.gz", + "usage": "input", + "git_blob": "85a4499bf9e4911a705d50567a2c2ef6cf23739a", + "sha256": "e3e301e62bc2b41dbf1ceac0acf3d35824ebeab1848c5a2142d4577b109da52f" + }, + { + "path": "research/gauge44-frames-x/code/assemble.py", + "usage": "input", + "git_blob": "8cee90b50e238bd1519a7aeb7395f62d277b8ae4", + "sha256": "4c270a996b380ab712f72b81173ab24f1c73203a33578f261bfbaa7e67d75aec" + }, + { + "path": "scripts/verify_frontier741_bindings.py", + "usage": "input", + "git_blob": "dcb4029aeaafe60f4d852a1975b01e02438595fc", + "sha256": "eff455167e2fd0bc9a67d35241d0e69d8edc58f3a23e776dcfe8f500ca8e8d67" + }, + { + "path": "scripts/verify_frontier799_bindings.py", + "usage": "input", + "git_blob": "ff902406c7acc760cb3ab5c9cf732768bdde1620", + "sha256": "43897b3c99212d6134870898a1840f32898aa1b3679b299e654901568ad7e19b" + } + ] +} diff --git a/research/retained-bit-supplier-binding/TASK.json b/research/retained-bit-supplier-binding/TASK.json new file mode 100644 index 0000000000..348de764b0 --- /dev/null +++ b/research/retained-bit-supplier-binding/TASK.json @@ -0,0 +1,107 @@ +{ + "schema_version": 1, + "task_id": "supplier-boundary-audit", + "priority_revision": 2, + "base_commit": "bce54fb3f895cbe5cd4c0eb477c3afeed100190f", + "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": "Supplement the selected PR1094 ancestry with an opt-in PR589 supplier identity guard, checking four committed assemblies and an optional newly emitted assembly/result against the exact source Git objects and COPY/profile deficit.", + "scope_change_reason": "The card is narrowed to the unbound bit_supplier identity named as an open next question in PR1277. This is a complementary executable guard, not a new discovery of the ancestry finding, a change to a frozen verifier, or a mathematical supplier improvement.", + "bottleneck_link": "A correct priced number does not establish the identity of its cited supplier. Binding that identity and the COPY-derived deficit makes source-bound review reusable; it does not improve the complex bottleneck or kappa.", + "budget_minutes": 60, + "stop_rule": "Complete exact source/merge/retained byte bindings, nine COPY ranks and four assembly checks, then semantic and relocation/CLI controls. No optimizer, moment re-certification or supplier cold replay.", + "outcome": "completed", + "evidence": "RESULT.json; four assemblies and one bit result pass; test_guard.py has ten groups with 23 rejection fixtures, including false source identity at unchanged endpoint/kappa and compensating COPY ranks.", + "author": "Arham Tahir", + "ai_assistance": "Substantial OpenAI Codex assistance for research, implementation, tests and writing. No subagents or independent human review.", + "open_questions": [ + { + "question": "Should a future unpinned replay wrapper require this supplier identity guard together with PR1277's full ancestry-binding equality?", + "why_it_matters": "The two checks protect different boundaries: a specifically cited source versus equality to the particular ancestry receipt retained by PR1042.", + "first_step": "Apply both guards in a successor wrapper; run the existing full-reuse fixture and PR1277's zeroed supplier/timing variants, then a complete cold replay.", + "blocked_by": "Maintainer acceptance and versioned source/coverage pins; this package deliberately does not edit pinned verifiers or selected evidence." + } + ], + "scope_key": "66632af6c86d34fb0fdc/retained-pr589-source-identity-and-copy-deficit", + "selection_nonce": "78116c731f9a59be32e8cd1544265921", + "selection_track": "adversarial-audit", + "method": "Trace the original assemble.py emission and PR741/PR799 consumer predicates; independently bind Git objects across the original-to-retained directory rename, rank the nine COPY frames over Q, and guard actual assembly/result fields.", + "bounded_domain": "Pinned PR589 word; 111 ports, 439 helpers, nine COPY totals; nine-stage 32-replica profile; assembly checkpoints PR741, PR799, PR1042 and PR1094.", + "optimistic_full_cost_budget": "Verification-only guard; no changed circuit, recursive charge, primitive budget or kappa target.", + "predecessor_heads": { + "PR1277": "02d279515ff1fc468ab99a19d89461f1b6391507", + "PR589": "a5afc8c6169ea61ba7c51dfd3cade02cc7b13b46", + "selected_PR1094": "0fc329d0bec93ca7cd288eaea1295172e8789810" + }, + "overlap": { + "entry_pr_snapshot_utc": "2026-10-13T22:34:09.908Z", + "open_prs_including_drafts": 806, + "pr_pagination_complete": true, + "nearest": [ + "https://github.com/CrocSwap/integer-mult-bounds/pull/1277", + "https://github.com/CrocSwap/integer-mult-bounds/pull/1307", + "https://github.com/CrocSwap/integer-mult-bounds/pull/1312" + ], + "discussion_coverage": "Read start-here, active listing and the live handoff thread. No complete Discussion body/reply cache: public listing was incomplete. Browser was signed out and the GitHub connector has no Discussion-write tool; local claim only.", + "limits": "Literal open-PR titles/bodies plus local top-level notes/ledger; no arbitrary code diffs, all closed PRs or complete Discussion pagination. No novelty proof.", + "final_pr_snapshot_utc": "2026-10-13T22:42:31.217Z", + "final_open_prs_including_drafts": 815, + "final_pr_pagination_complete": true, + "PR1277_head_rechecked_unchanged": true + }, + "local_claim": { + "created_utc": "2026-10-13T22:37:14Z", + "expires_utc": "2026-10-14T00:37:14Z", + "status": "DONE", + "artifact": "research/retained-bit-supplier-binding" + }, + "validation": { + "python": "3.12.14", + "platform": "Windows-11-10.0.26200-SP0", + "registered_replay": "PASS; metadata/pins, four assemblies, one bit result, ten tests/23 rejection fixtures under -I -O -B", + "research_baseline": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "broader_research_suite": "20 tests; 3 reported Windows/platform errors in unchanged timeout/temporary-directory cleanup tests. Process-local core.autocrlf=false and workspace scratch directories used. Not a pass.", + "unrun": [ + "full cold supplier replay", + "original PR1277 false-source acceptance fixture", + "native/scalar/phase replay", + "moment recertification", + "all-size/hosting/precision/tape/analytic proof" + ] + } +} diff --git a/research/retained-bit-supplier-binding/VERIFY.json b/research/retained-bit-supplier-binding/VERIFY.json new file mode 100644 index 0000000000..7d2d9ed8a5 --- /dev/null +++ b/research/retained-bit-supplier-binding/VERIFY.json @@ -0,0 +1,43 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/community-frontier1042-audit/ASSEMBLY.json", + "research/community-frontier1094-audit/ASSEMBLY.json", + "research/community-frontier741-audit/ASSEMBLY.json", + "research/community-frontier741-audit/bit/RESULT9.json", + "research/community-frontier799-audit/ASSEMBLY.json", + "research/e8-bit-p111-tuned/code/xcheck_p.py", + "research/e8-bit-p111-tuned/tune/EXPECTED.json", + "research/e8-bit-p111-tuned/tune/bitE8mut-p111-tuned.json.gz", + "research/gauge44-frames-x/code/assemble.py", + "scripts/verify_frontier741_bindings.py", + "scripts/verify_frontier799_bindings.py" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-O", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Exact Git source/integration/retained identity, COPY ranks, full profile deficit, four assembly fixtures and one bit result; deterministic receipt." + }, + { + "argv": [ + "{python}", + "-I", + "-O", + "-B", + "{package}/test_guard.py" + ], + "timeout_seconds": 120, + "checks": "Ten semantic/source/CLI/relocation test groups with 23 rejection fixtures." + } + ] +} diff --git a/research/retained-bit-supplier-binding/guard.py b/research/retained-bit-supplier-binding/guard.py new file mode 100644 index 0000000000..38efd37b3c --- /dev/null +++ b/research/retained-bit-supplier-binding/guard.py @@ -0,0 +1,187 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Supplemental PR589 identity guard; no supplier replay or moment certification. + +Arham Tahir, with substantial OpenAI Codex assistance. Follows the provenance +question in Sagar Thakrar's PR1277 and credits the retained PR589 lineage. +""" +from fractions import Fraction +from hashlib import sha1, sha256 +from pathlib import Path +import gzip +import json +import subprocess + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +SOURCE_ROOT = 'research/e8-bit-p111' +RETAINED_ROOT = 'research/e8-bit-p111-tuned' +MERGE = 'b3eb785ac5b4b1ca2beea0f80db078a505626a90' +ASSEMBLIES = tuple('research/community-frontier%d-audit/ASSEMBLY.json' % n + for n in (741, 799, 1042, 1094)) +BIT_RESULT = 'research/community-frontier741-audit/bit/RESULT9.json' + + +def require(ok, message): + if not ok: + raise ValueError(message) + + +def same(actual, expected): + """JSON equality that does not silently identify true with 1.""" + if type(actual) is not type(expected): + return False + if isinstance(expected, dict): + return actual.keys() == expected.keys() and all(same(actual[k], v) for k, v in expected.items()) + if isinstance(expected, list): + return len(actual) == len(expected) and all(same(a, b) for a, b in zip(actual, expected)) + return actual == expected + + +def git(root, *args): + return subprocess.run(['git', '-C', str(root), *args], check=True, + capture_output=True).stdout + + +def blob_id(raw): + return sha1(b'blob ' + str(len(raw)).encode('ascii') + b'\0' + raw).hexdigest() + + +def rank(rows, width=8): + """Exact incremental elimination over Q, independent of the supplier code.""" + basis = {} + for row in rows: + require(len(row) == width and all(type(x) is int for x in row), 'integer root row') + v = list(map(Fraction, row)) + for pivot, b in sorted(basis.items()): + coefficient = v[pivot] + if coefficient: + v = [a - coefficient * c for a, c in zip(v, b)] + pivot = next((i for i, x in enumerate(v) if x), None) + if pivot is not None: + coefficient = v[pivot] + basis[pivot] = [x / coefficient for x in v] + return len(basis) + + +def copy_ranks(word): + """Follow only D/A frame assignments up to COPY, then rank the totals. + + Each gate lifts every operand to its named common frame. This is the + source format's frame trace, not a check of gate legality or scalar values. + """ + n = 2 * word['v'] + word['R'] + require(word['h'] == 8 and len(word['lines']) == word['v'], 'word dimensions') + cur = list(word['start']) + require(len(cur) == n, 'word register inventory') + for section in ('D', 'A'): + for frame, destination, sources in word[section]: + require(type(frame) is int and 0 <= frame < len(word['frames']), 'frame id') + operands = [destination, *sources] + require(sources and len(set(operands)) == len(operands) and + all(type(q) is int and 0 <= q < n for q in operands), 'gate operands') + for q in operands: + cur[q] = frame + totals = word['ret'] + require(len(set(totals)) == len(totals) and all(type(q) is int and 2 * word['v'] <= q < n + for q in totals), 'retained helper inventory') + out = [] + for q in totals: + frame = word['frames'][cur[q]] + require(all(type(i) is int and 0 <= i < word['v'] for i in frame), 'frame label index') + out.append(rank([word['lines'][i] for i in frame])) + require(all(0 < r <= 8 for r in out), 'COPY rank range') + return out + + +def derive(record, word): + """Connect the stated deficit to actual COPY frames and the priced profile.""" + ranks = copy_ranks(word) + summary = dict(v=word['v'], decoder_constant=sum(ranks), copy_ranks=ranks) + for name, value in summary.items(): + require(same(record['word'][name], value), 'word record: ' + name) + require(same(record['word']['R'], word['R']) and + same(record['word']['retained_totals'], len(ranks)), 'word helper/total count') + nine = record['nine'] + stages, replicas = 9, 32 + pairs, width = (stages - 1) // 2, 1 + 7 * stages + live = 2 * pairs * word['v'] * replicas + profile = nine['profile'] + require(all(type(k) is str and k.isdecimal() and str(int(k)) == k and 0 < int(k) < width + and type(v) is int and v > 0 for k, v in profile.items()), 'priced profile integers') + mass = sum(int(r) * count for r, count in profile.items()) + deficit = replicas * (2 * pairs * word['v'] - stages * sum(ranks)) + require(deficit > 0 and width * live - mass == deficit, 'COPY/profile deficit identity') + require(same(nine['bit']['live'], live) and same(nine['bit']['rank_mass'], mass), 'bit rank mass') + require(same(nine['bit']['hosted_residuals'], replicas * stages * word['R']), 'bit helper inventory') + return dict(word=summary, derived_deficit=deficit, live=live, rank_mass=mass, + stages=stages, replicas=replicas, profile=profile, + deficit_formula='T(2Kv-L*cst), L=9 T=32 K=4 M=64') + + +def context(root=ROOT, sources_path=HERE / 'SOURCES.json'): + """Authenticate pinned inputs and the source-to-main rename with Git objects.""" + sources = json.loads(sources_path.read_bytes()) + base = sources['base_commit'] + for item in sources['files']: + name = item['path'] + pinned = git(root, 'show', base + ':' + name) + require(sha256(pinned).hexdigest() == item['sha256'] and blob_id(pinned) == item['git_blob'], + 'historical source pin: ' + name) + if item['usage'] == 'input': + require((root / name).read_bytes() == pinned, 'live source pin: ' + name) + selected = json.loads(git(root, 'show', base + ':certificates/selected-result.json')) + head = selected['reviewed_dependency_heads']['589'] + require(git(root, 'cat-file', '-t', head).strip() == b'commit', 'reviewed PR589 commit') + parents = git(root, 'show', '-s', '--format=%P', MERGE).decode('ascii').split() + require(head in parents, 'PR589 is a preserved integration parent') + git(root, 'merge-base', '--is-ancestor', MERGE, base) + raw = (root / RETAINED_ROOT / 'tune/EXPECTED.json').read_bytes() + record = json.loads(raw) + word_name = record['word']['file'] + require(word_name == 'tune/bitE8mut-p111-tuned.json.gz', 'pinned word path') + word_raw = (root / RETAINED_ROOT / word_name).read_bytes() + objects = {} + for name, current in (('tune/EXPECTED.json', raw), (word_name, word_raw)): + source = git(root, 'show', head + ':' + SOURCE_ROOT + '/' + name) + merged = git(root, 'show', MERGE + ':' + RETAINED_ROOT + '/' + name) + require(source == merged == current, 'source/integration/retained bytes: ' + name) + objects[name] = blob_id(current) + payload = gzip.decompress(word_raw) + require(sha256(word_raw).hexdigest() == record['word']['file_sha256'] and + sha256(payload).hexdigest() == record['word']['content_sha256'], 'word payload binding') + word = json.loads(payload) + derived = derive(record, word) + supplier = dict(pr=589, repository='CrocSwap/integer-mult-bounds', commit=head, merged_as=MERGE, + path=RETAINED_ROOT + '/tune/EXPECTED.json', git_blob_sha1=blob_id(raw), + word=derived['word'], derived_deficit=derived['derived_deficit'], + deficit_formula=derived['deficit_formula']) + return dict(supplier=supplier, record=record, derived=derived, base_commit=base, + record_sha256=sha256(raw).hexdigest(), word_content_sha256=sha256(payload).hexdigest(), + git_objects=objects) + + +def check_assembly(assembly, ctx): + """Guard an untrusted assembly, including outputs supplied via --assembly.""" + supplier = assembly.get('bit_supplier') + require(type(supplier) is dict, 'missing bit_supplier') + for name, expected in ctx['supplier'].items(): + require(name in supplier and same(supplier[name], expected), 'bit_supplier.' + name) + require(assembly['input_sha256']['package:inputs/PR589-EXPECTED.json'] == ctx['record_sha256'], + 'assembly bit input digest') + nine = ctx['record']['nine'] + require(same(assembly['bit_lower'], nine['bit_lower']), 'assembly bit endpoint') + require(same(assembly['bit_decimal'], nine['bit_lower_decimal']), 'assembly bit decimal') + require(assembly['surcharge_model']['bit'] is True, 'bit bad-residue surcharge') + return ctx['derived']['derived_deficit'] + + +def check_bit_result(result, ctx): + """Bind the priced fields; intentionally make no execution-authentication claim.""" + expected = dict(R=ctx['record']['word']['R'], stages=9, replicas=32, + bit_lower=ctx['record']['nine']['bit_lower'], + bit_lower_decimal=ctx['record']['nine']['bit_lower_decimal'], + bit_profile=ctx['record']['nine']['profile'], bit=ctx['record']['nine']['bit']) + for name, value in expected.items(): + require(name in result and same(result[name], value), 'bit result: ' + name) + return True diff --git a/research/retained-bit-supplier-binding/test_guard.py b/research/retained-bit-supplier-binding/test_guard.py new file mode 100644 index 0000000000..e1a41b3b6b --- /dev/null +++ b/research/retained-bit-supplier-binding/test_guard.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Semantic faults and source/CLI controls; checks also run under -I -O.""" +import copy +import importlib.util +import json +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import unittest + +HERE = Path(__file__).resolve().parent +spec = importlib.util.spec_from_file_location('guard_under_test', HERE / 'guard.py') +g = importlib.util.module_from_spec(spec) +spec.loader.exec_module(g) + + +class GuardTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.ctx = g.context() + cls.assembly = json.loads((g.ROOT / g.ASSEMBLIES[-1]).read_bytes()) + cls.record = cls.ctx['record'] + import gzip + cls.word = json.loads(gzip.decompress((g.ROOT / g.RETAINED_ROOT / + cls.record['word']['file']).read_bytes())) + + def test_all_four_published_assemblies(self): + for name in g.ASSEMBLIES: + with self.subTest(name=name): + self.assertEqual(g.check_assembly(json.loads((g.ROOT / name).read_bytes()), self.ctx), 10272) + result = json.loads((g.ROOT / g.BIT_RESULT).read_bytes()) + self.assertTrue(g.check_bit_result(result, self.ctx)) + + def test_false_provenance_with_identical_priced_numbers(self): + # Mirrors PR1277's false-source fixture, then covers each identity field. + replacements = dict(pr=555, repository='another/repository', commit='0' * 40, + merged_as='0' * 40, path=g.SOURCE_ROOT + '/tune/EXPECTED.json', + git_blob_sha1='0' * 40) + for name, value in replacements.items(): + with self.subTest(name=name): + a = copy.deepcopy(self.assembly) + a['bit_supplier'][name] = value + self.assertEqual(a['bit_lower'], self.assembly['bit_lower']) + self.assertEqual(a['kappa'], self.assembly['kappa']) + with self.assertRaisesRegex(ValueError, 'bit_supplier.' + name): + g.check_assembly(a, self.ctx) + + def test_same_record_at_another_real_commit_is_not_the_cited_head(self): + a = copy.deepcopy(self.assembly) + a['bit_supplier']['commit'] = self.ctx['base_commit'] + raw = g.git(g.ROOT, 'show', self.ctx['base_commit'] + ':' + a['bit_supplier']['path']) + self.assertEqual(g.blob_id(raw), a['bit_supplier']['git_blob_sha1']) + with self.assertRaisesRegex(ValueError, 'bit_supplier.commit'): + g.check_assembly(a, self.ctx) + + def test_compensating_copy_rank_fault_preserves_scalar_deficit(self): + a = copy.deepcopy(self.assembly) + a['bit_supplier']['word']['copy_ranks'][:2] = [6, 8] + self.assertEqual(sum(a['bit_supplier']['word']['copy_ranks']), 63) + with self.assertRaisesRegex(ValueError, 'bit_supplier.word'): + g.check_assembly(a, self.ctx) + + def test_source_frame_change_is_measured_not_read_from_record(self): + w = copy.deepcopy(self.word) + total = w['ret'][0] + self.assertEqual(g.copy_ranks(w), [7] * 9) + # A final full-frame gate really changes the COPY rank to eight. + full = next(i for i, frame in enumerate(w['frames']) + if g.rank([w['lines'][j] for j in frame]) == 8) + w['A'].append([full, total, [0]]) + self.assertEqual(g.copy_ranks(w)[0], 8) + with self.assertRaisesRegex(ValueError, 'word record: decoder_constant'): + g.derive(self.record, w) + + def test_profile_mass_fault_and_boolean_count(self): + for value in (self.record['nine']['profile']['1'] + 1, True): + r = copy.deepcopy(self.record) + r['nine']['profile']['1'] = value + with self.assertRaises(ValueError): + g.derive(r, self.word) + + def test_endpoint_digest_surcharge_and_deficit_faults(self): + faults = [('endpoint', lambda a: a.update(bit_lower='1/2')), + ('digest', lambda a: a['input_sha256'].update({'package:inputs/PR589-EXPECTED.json': '0' * 64})), + ('surcharge', lambda a: a['surcharge_model'].update(bit=1)), + ('deficit', lambda a: a['bit_supplier'].update(derived_deficit=9984)), + ('formula', lambda a: a['bit_supplier'].update(deficit_formula='unpunctured'))] + for name, change in faults: + with self.subTest(name=name): + a = copy.deepcopy(self.assembly) + change(a) + with self.assertRaises(ValueError): + g.check_assembly(a, self.ctx) + + def test_priced_bit_result_faults(self): + positive = json.loads((g.ROOT / g.BIT_RESULT).read_bytes()) + for field, value in [('R', 438), ('replicas', 31), ('stages', 11), ('bit_lower', '1/2')]: + result = copy.deepcopy(positive) + result[field] = value + with self.subTest(field=field), self.assertRaises(ValueError): + g.check_bit_result(result, self.ctx) + result = copy.deepcopy(positive) + # Preserve rank mass by exchanging two H1 calls for one H2 call. + result['bit_profile']['1'] -= 2 + result['bit_profile']['2'] += 1 + self.assertEqual(sum(int(k) * v for k, v in result['bit_profile'].items()), 1808352) + with self.assertRaisesRegex(ValueError, 'bit result: bit_profile'): + g.check_bit_result(result, self.ctx) + + def test_cli_rejects_unchanged_numerics_with_zeroed_source(self): + with tempfile.TemporaryDirectory(prefix='.guard-test-', dir=HERE) as folder: + path = Path(folder) / 'assembly.json' + a = copy.deepcopy(self.assembly) + a['bit_supplier'].update(commit='0' * 40, git_blob_sha1='0' * 40) + path.write_text(json.dumps(a), encoding='utf-8') + p = subprocess.run([sys.executable, '-I', '-O', '-B', str(HERE / 'verify.py'), + '--assembly', str(path)], capture_output=True, text=True) + self.assertNotEqual(p.returncode, 0) + self.assertIn('bit_supplier.commit', p.stderr) + + def test_relocated_inputs_and_source_corruption(self): + with tempfile.TemporaryDirectory(prefix='.guard-test-', dir=HERE) as folder: + root = Path(folder) + # Reuse only the object database; every live input is physically relocated. + gitdir = g.git(g.ROOT, 'rev-parse', '--absolute-git-dir').decode().strip() + (root / '.git').write_text('gitdir: ' + gitdir + '\n', encoding='utf-8') + sources = json.loads((HERE / 'SOURCES.json').read_bytes()) + for item in sources['files']: + if item['usage'] == 'input': + target = root / item['path'] + target.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(g.ROOT / item['path'], target) + self.assertEqual(g.context(root)['supplier'], self.ctx['supplier']) + target = root / g.RETAINED_ROOT / 'tune/EXPECTED.json' + target.write_bytes(target.read_bytes() + b'\n') + with self.assertRaisesRegex(ValueError, 'live source pin'): + g.context(root) + + +if __name__ == '__main__': + unittest.main() diff --git a/research/retained-bit-supplier-binding/verify.py b/research/retained-bit-supplier-binding/verify.py new file mode 100644 index 0000000000..212b30cc9a --- /dev/null +++ b/research/retained-bit-supplier-binding/verify.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Verify the retained PR589 provenance/deficit contract without a cold replay.""" +import argparse +from hashlib import sha256 +import importlib.util +import json +from pathlib import Path +import sys + +HERE = Path(__file__).resolve().parent +spec = importlib.util.spec_from_file_location('retained_bit_guard', HERE / 'guard.py') +guard = importlib.util.module_from_spec(spec) +spec.loader.exec_module(guard) + + +def verify(root=guard.ROOT, assembly=None, bit_result=None): + ctx = guard.context(root) + assemblies = [assembly] if assembly is not None else [root / name for name in guard.ASSEMBLIES] + assembly_bytes = [path.read_bytes() for path in assemblies] + for raw in assembly_bytes: + guard.check_assembly(json.loads(raw), ctx) + result_path = bit_result if bit_result is not None else root / guard.BIT_RESULT + result_bytes = result_path.read_bytes() + guard.check_bit_result(json.loads(result_bytes), ctx) + return dict(status='PASS_RETAINED_PR589_SUPPLIER_BINDING', base_commit=ctx['base_commit'], + supplier=ctx['supplier'], git_objects=ctx['git_objects'], + record_sha256=ctx['record_sha256'], word_content_sha256=ctx['word_content_sha256'], + assemblies_checked=len(assemblies), bit_results_checked=1, + assembly_sha256=[sha256(raw).hexdigest() for raw in assembly_bytes], + bit_result_sha256=sha256(result_bytes).hexdigest(), + live=ctx['derived']['live'], rank_mass=ctx['derived']['rank_mass'], + scope='Pinned PR589 source identity, COPY-frame ranks and profile deficit; ' + 'no scalar/phase/native replay, certified moment or all-size theorem.') + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--root', type=Path, default=guard.ROOT) + parser.add_argument('--assembly', type=Path, help='Also guard a newly emitted assembly instead of the four fixtures') + parser.add_argument('--bit-result', type=Path, help='Guard a newly emitted RESULT9.json instead of the archived fixture') + parser.add_argument('--write', type=Path, help='Write an explicitly requested receipt') + args = parser.parse_args() + try: + receipt = verify(args.root, args.assembly, args.bit_result) + if args.write is None and args.assembly is None and args.bit_result is None: + guard.require(receipt == json.loads((HERE / 'RESULT.json').read_bytes()), 'committed receipt differs') + if args.write: + args.write.write_text(json.dumps(receipt, indent=2) + '\n', encoding='utf-8') + print(receipt['status'], 'assemblies=' + str(receipt['assemblies_checked']), + 'deficit=' + str(receipt['supplier']['derived_deficit'])) + except (OSError, ValueError, KeyError, TypeError, IndexError) as exc: + print('FAIL_RETAINED_PR589_SUPPLIER_BINDING:', exc, file=sys.stderr) + return 1 + return 0 + + +if __name__ == '__main__': + raise SystemExit(main())