diff --git a/research/p104-channel-touch-restoration-audit/CERTIFICATE.json b/research/p104-channel-touch-restoration-audit/CERTIFICATE.json new file mode 100644 index 0000000000..a3f80bb15f --- /dev/null +++ b/research/p104-channel-touch-restoration-audit/CERTIFICATE.json @@ -0,0 +1,49 @@ +{ + "schema_version": 1, + "claim_id": "p104-channel-touch-restoration-audit", + "pinned_main": "6f100d4bb5083f8c35d96fd95a539811c62f245c", + "flags": 208, + "unique_source_target_pairs": 208, + "program_events": 4058, + "joint_source_target_events": 0, + "matched_pairs_target_before_source": 208, + "matched_pairs_cooccurring": 0, + "matched_same_first_event": 0, + "latest_target_first_event": 410, + "latest_target_firsts": ["Y103"], + "earliest_source_event": 488, + "earliest_sources": ["X74"], + "population_gap": 78, + "minimum_matched_first_touch_gap": 84, + "minimum_matched_pair": {"source": 58, "target": 102, "target_first": 405, "source_first": 489}, + "source_initial_ranks": {"1": 104}, + "source_final_equals_coordinate_basis": 104, + "target_initial_empty": 104, + "target_final_ranks": {"8": 104}, + "frame_restored_sources": 0, + "frame_restored_targets": 0, + "matched_pairs_with_either_endpoint_frame_restored": 0, + "sources_starting_at_basis_head": 208, + "targets_whose_final_contains_basis_head": 4, + "basis_head_in_target_final": [ + {"flag_index": 0, "source": 0, "target": 34, "basis_head": 232}, + {"flag_index": 1, "source": 0, "target": 7, "basis_head": 232}, + {"flag_index": 9, "source": 4, "target": 23, "basis_head": 196}, + {"flag_index": 43, "source": 21, "target": 59, "basis_head": 15} + ], + "flag0": { + "source": 0, + "target": 34, + "basis_head": 232, + "source_events": [591, 3954], + "target_events": [129, 3500], + "source_coefficients": ["-2", "2"], + "target_coefficients": ["-1/4", "1/4"], + "source_initial": [232], + "source_frame_restored": false, + "target_frame_restored": false, + "target_final_contains_basis_head": true + }, + "author_3242_fields_match": true, + "no_new_kappa": true +} diff --git a/research/p104-channel-touch-restoration-audit/MASTER-HANDOFF.md b/research/p104-channel-touch-restoration-audit/MASTER-HANDOFF.md new file mode 100644 index 0000000000..eccd177441 --- /dev/null +++ b/research/p104-channel-touch-restoration-audit/MASTER-HANDOFF.md @@ -0,0 +1,29 @@ +# Handoff: published-word chronology and frame restoration + +## Result + +Independent replay of the pinned #2981 matching on the #1991 channel witness confirms the #3242 first-touch separation (targets by event 410, sources from event 488, no joint X/Y event) and shows that none of the 104 source frames or 104 target frames is restored. + +Pinned main: `6f100d4bb5083f8c35d96fd95a539811c62f245c`. Selected κ is unchanged at 0.001672660197076918. + +## Switch + +The requested #3259 audit was not repeated. `research/p104-pooled-cut-independent` (Nick Petalas, head `b572b0c25569898579041200e95731c5a43c9189`) already registers a passing Python 3.12 verifier for the same missing pair `C[71,102] = -1/2`, forward cone 1,725, and backward cone 37 under the immutable-X, unread-Y, independent-dirt, monotone equal-frame contract. That cut originates in dcharb78's #3182. The live gap after it, in `docs/research/p104-live-support-map.md`, is chronological realization and dirty restoration. This package takes those for the published word only. + +## What was checked + +- Two scanners, neither imported from #3242 or #3259, read the hash-pinned flag certificate, channel witness, and geometry naming lines. +- They agree with each other and with `CERTIFICATE.json`. +- The overlapping #3242 fields match hash-pinned `research/p104-flag-channel-schedule/RESULT.json`. +- Frame restoration is set equality of initial and final frames. All 104 sources end at the coordinate basis; all 104 targets start empty and end at rank 8. +- The basis head lies in the target final for flags 0, 1, 9, and 43 only. + +## What remains open + +Coefficient execution, logical restoration of arbitrary dirt, a chronological correction program, native lowering, precision, physical hosting, and a complete invoice. This is not a universal P104 barrier and not a supplier admission. + +## Credit + +Nick Petalas (#2981 flags, #3259 support certification), dcharb78 (#3182 cut), jwr404 (#3242 chronology receipt), and the reviewed #1991 channel. Their notices are untouched. + +Prepared by Wentao Li with substantial AI assistance. diff --git a/research/p104-channel-touch-restoration-audit/NOTICE.md b/research/p104-channel-touch-restoration-audit/NOTICE.md new file mode 100644 index 0000000000..c9639f1b91 --- /dev/null +++ b/research/p104-channel-touch-restoration-audit/NOTICE.md @@ -0,0 +1,18 @@ +# Notice + +Copyright 2026 Wentao Li + +This directory is a scoped audit of archived research. It is licensed under +the Apache License, Version 2.0, the same license as the surrounding project. + +The 208-flag matching is Nick Petalas's work from PR #2981, retained at +`research/p104-joint-unit-flags`. The 4,058-event witness is the reviewed +#1991 native channel. The chronology claim under audit is jwr404's PR #3242, +retained at `research/p104-flag-channel-schedule`. The fixed-cover support +cut that this package does not re-derive is Nick Petalas's PR #3259 +certification of dcharb78's PR #3182, retained at +`research/p104-pooled-cut-independent`. + +Those notices and files are unchanged. This package adds an independent +reading of the pinned bytes. Prepared by Wentao Li with substantial AI +assistance. No independent human or formal-kernel review is claimed. diff --git a/research/p104-channel-touch-restoration-audit/PROOF.md b/research/p104-channel-touch-restoration-audit/PROOF.md new file mode 100644 index 0000000000..2cb00c6ac6 --- /dev/null +++ b/research/p104-channel-touch-restoration-audit/PROOF.md @@ -0,0 +1,54 @@ +# Chronology and frame restoration of the published P104 word + +## Claim + +Under the pinned #2981 208-flag matching and the #1991 4,058-event channel witness, every target register is first touched at or before event 410, every source register is first touched at or after event 488, no event names both an X register and a Y register, and zero of the 104 source frames and zero of the 104 target frames return to their initial frames. + +No new κ is claimed. The selected conditional result remains κ = 0.001672660197076918. + +## Why this package exists + +Pinned canonical main is `6f100d4bb5083f8c35d96fd95a539811c62f245c`. On that tree, `research/p104-pooled-cut-independent` is Nick Petalas's PR #3259 at `b572b0c25569898579041200e95731c5a43c9189`. Its registered verifier already certifies the PR #3182 fixed-cover cut: exactly one missing required pair among 4,992, `C[71,102] = -1/2`, with a forward cone of 1,725 edges and a disjoint backward cone of 37 edges, under the immutable-X, unread-Y, independent-dirt, monotone equal-frame contract. That certification is not repeated here. + +The live gap named after that cut is chronological realization and dirty restoration of the published word. PR #3242 (`research/p104-flag-channel-schedule`, `f3c7e5229d1ce856fe3d6fa5467b10679c0fda14`, jwr404) states the first-touch separation and records that the worked pair X0/Y34 is not restored. Its scientific review was still open on the pinned map, and no second package replays the claim. This note is that replay, plus the restoration census for every endpoint. + +## Contract + +Sources and targets are the names fixed by the pinned geometry lines + +``` +sources = [paths[f'X{s}'] for s in range(104)] +targets = [paths[f'Y{t}'] for t in range(104)] +``` + +A register is touched by an event when its name occurs as a top-level field of that event. Event indices are zero-based positions in `program`. The first touch is the least such index, and the last touch is the greatest. An event is joint when it names at least one X register and at least one Y register. + +The matching is the 208 helpers in Nick Petalas's #2981 certificate. Each helper names a source, a target, and a basis whose first vector is the basis head. There are 208 distinct source/target pairs. Each source index and each target index occurs twice. + +A register is frame-restored when its initial frame and final frame are equal as sets of integers. Frames in the witness have no repeated vectors, so sorted-tuple equality and set equality coincide. This is a statement about the recorded frames of the published word. It does not track logical coefficients, and it does not say that some other schedule is unable to restore them. + +## Chronology + +The witness has 4,058 events, and every `X0`–`X103` and `Y0`–`Y103` occurs at least once. The forward scan and the index-list scan agree on the following. + +The latest first touch of a target is event 410, attained only by `Y103`. The earliest first touch of a source is event 488, attained only by `X74`. The population gap is 78. Every target first touch is at most 410, and every source first touch is at least 488. Therefore every target begins before every source. In particular, all 208 matched targets are first touched before their matched sources, and no matched pair shares a first index. + +No event is joint. The two scanners also compare the full touch sets of each matched pair and find 0 meetings. The smallest matched gap is 84, on source 58 and target 102 (target first at 405, source first at 489). The population gap of 78 is the separation between `Y103` and `X74`, which are not a matched pair. + +Flag 0 is source 0, target 34, basis head 232. `X0` occupies events 591 through 3954. `Y34` occupies events 129 through 3500. Their add coefficients are `{-2, 2}` and `{-1/4, 1/4}`. These fields match the pinned #3242 receipt. The coefficient lists in this certificate are sorted lexicographically; #3242 stores the same sets in a different order. + +## Frame restoration + +Every source initial frame is a singleton, and every source final frame is the coordinate basis `(1, 2, 4, 8, 16, 32, 64, 128, 256)`. Every target initial frame is empty, and every target final frame has rank 8. None of the 104 sources and none of the 104 targets is frame-restored. All 208 matched pairs therefore have both endpoints unrestored. + +All 208 source initial frames are exactly the singleton of that flag's basis head. The target final contains that basis head for only four flags: `(0, Y34, 232)`, `(0, Y7, 232)`, `(4, Y23, 196)`, and `(21, Y59, 15)`. The worked #3242 pair is one of those four. It is not the shape of the other 204 flags. + +`X0` starts at `[232]` and does not finish there. `Y34` does not start empty-equal to its final frame, and 232 does lie in that final frame. That is the #3242 restored flag, read as frame inequality. + +## What this does not prove + +A first-touch order is not subspace support. The #3259 cut remains the support statement for `C[71,102] = -1/2` under its own contract; this package does not re-prove it. A changed frame is not a logical identity. Exact coefficient delivery, restoration of arbitrary dirty inputs, native lowering, precision, physical hosting, and a complete channel-plus-correction invoice stay open. Nothing here admits a supplier or changes κ. + +## Credit + +Nick Petalas supplied the 208-flag certificate in PR #2981 and the independent support-cut certification in PR #3259. dcharb78 supplied the cut itself in PR #3182. jwr404 supplied the chronology reading audited here in PR #3242. The channel witness is the reviewed #1991 word those packages pin. Their files and notices are not modified. diff --git a/research/p104-channel-touch-restoration-audit/README.md b/research/p104-channel-touch-restoration-audit/README.md new file mode 100644 index 0000000000..43fa527bf6 --- /dev/null +++ b/research/p104-channel-touch-restoration-audit/README.md @@ -0,0 +1,45 @@ +# Channel first-touch order and endpoint frame restoration + +**Scoped audit. No new exponent.** + +The #3259 support cut is already certified on pinned main by +`research/p104-pooled-cut-independent`. This package instead replays the +published 208-flag matching against the 4,058-event channel witness. + +Under that matching and witness, every target is first touched at or before +event 410, every source is first touched at or after event 488, no event +names both an X register and a Y register, and zero of the 104 source frames +and zero of the 104 target frames return to their initial frames. + +The population bound and the unrestored X0/Y34 example agree with jwr404's +PR #3242 receipt. The new census is that the frame failure covers every +endpoint, and that the basis head meets the target final on only 4 of 208 +flags. Details, the matched gap of 84, and the limits of the claim are in +[PROOF.md](PROOF.md). + +## Reproduce + +From the repository root, CPython 3.12: + +```sh +python3.12 -I -O -Werror -B research/p104-channel-touch-restoration-audit/verify.py +python3.12 -I -O -Werror -B research/p104-channel-touch-restoration-audit/independent.py +python3.12 -I -O -Werror -B research/p104-channel-touch-restoration-audit/test_package.py +``` + +`verify.py` is read-only. Admission goes through `need()` and still fires +when Python is started with `-O`. The two scanners do not import each other. + +Pinned main: `6f100d4bb5083f8c35d96fd95a539811c62f245c`. Input hashes are in +[SOURCES.json](SOURCES.json). + +## Credit + +Nick Petalas / #2981 for the flags, Nick Petalas / #3259 and dcharb78 / #3182 +for the support cut that this package leaves in place, and jwr404 / #3242 for +the chronology receipt under audit. Prepared by Wentao Li with substantial +AI assistance. + +## Open next questions + +Can a chronological correction deliver the published coefficients and restore arbitrary dirt without repaying the frame loss? This census shows every endpoint frame fails to return. It does not construct or price that repair. diff --git a/research/p104-channel-touch-restoration-audit/SOURCES.json b/research/p104-channel-touch-restoration-audit/SOURCES.json new file mode 100644 index 0000000000..7125d745ec --- /dev/null +++ b/research/p104-channel-touch-restoration-audit/SOURCES.json @@ -0,0 +1,43 @@ +{ + "schema_version": 1, + "base_commit": "6f100d4bb5083f8c35d96fd95a539811c62f245c", + "upstream": "CrocSwap/integer-mult-bounds", + "files": [ + { + "path": "research/p104-joint-unit-flags/CERTIFICATE.json", + "usage": "input", + "git_blob": "0fa7d2d40566e92f3ea1539723abf438ba65adb8", + "sha256": "a98126428a8da6eae91c50afcc42e014a284c82b554ef77e5b3a34fc6d228128", + "credit": "Nick Petalas, PR #2981" + }, + { + "path": "research/p104-native-channel/inputs/LOWRANK-WITNESS.json", + "usage": "input", + "git_blob": "86beaf424e9f0f800ae3a62797d94ec9386b7706", + "sha256": "0f541bef7f19fdeffd67157684e9f03d785f42c89973632f508fc1a0452b580e", + "credit": "Reviewed #1991 native channel witness" + }, + { + "path": "research/p104-endpoint-geometric-budget/geometry.py", + "usage": "input", + "git_blob": "f49752bcfc321a6129186d4daa774b2c3fdb84f1", + "sha256": "1a2792189beaf15aa8180136ca007cd2301992a62e77ba72edea99b298e4148f", + "credit": "X/Y naming lines for the 104 sources and 104 targets" + }, + { + "path": "research/p104-flag-channel-schedule/RESULT.json", + "usage": "input", + "git_blob": "c2d7443350e7a8fdb77910689df75516b789b55d", + "sha256": "4ba6fd7555d8907ce28d52d8de5087133e3649431f8ef0617a8961ebcbb73e16", + "credit": "jwr404, PR #3242 author receipt" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "67f085acd86acd7d4e03922d9cf4b26bca66fed5", + "sha256": "47b42433f5a85809a3aadd29c2c339da2c6ed728e4f7762df6b88bccb7874cf0", + "pin": "base_commit:docs/research/agent-task-catalog.json", + "credit": "Priority revision 6 task catalogue at the pinned base" + } + ] +} diff --git a/research/p104-channel-touch-restoration-audit/TASK.json b/research/p104-channel-touch-restoration-audit/TASK.json new file mode 100644 index 0000000000..7aa5ae9ae2 --- /dev/null +++ b/research/p104-channel-touch-restoration-audit/TASK.json @@ -0,0 +1,92 @@ +{ + "schema_version": 1, + "task_id": "p104-side-correction", + "priority_revision": 6, + "selected_kappa": "0.001672660197076918", + "base_commit": "6f100d4bb5083f8c35d96fd95a539811c62f245c", + "original_card": { + "id": "p104-side-correction", + "question": "Can the proposed P104 joint endpoint flags be realized by a chronological correction program with coefficients, dirty restoration and an affordable complete bill?", + "starting_points": [ + "docs/research/research-family-status.md", + "research/p104-native-channel/README.md", + "research/p104-native-channel/PROOF.md", + "docs/research/community-efficient1000-review.md", + "research/p104-joint-unit-flags/README.md" + ], + "methods": [ + "Construct one side-correction word at an explicit chronological cut with the needed frames still available.", + "Derive a lower bound on the side correction and hosting costs that decides whether this channel can beat the selected budget." + ], + "acceptance_gate": "An exact arbitrary-input identity, source/target frame availability and restoration at the chosen cut, plus the complete channel+correction+idle/hosting bill or an explicit favorable bound. The native channel alone is not a supplier. A scoped local result may be retained without a complete supplier. Expanding it into further construction rounds requires the family-level budget and obligation gate in research-family-status.md; an optimistic passing relaxation alone is not acceptance.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read the revision-6 family record and #2981 static joint flags, alongside the reviewed #1991 channel. #2981 is an author-checked source archive, not an independently validated executable correction or a refutation of program-level lifetime floors.", + "scope": "Source-bound orientation only. Read the named package and review before relying on its local evidence; this command is not its replay or supplier admission." + }, + "first_experiment": "After checking live handoffs, pin one named collection from #2981 and attach acquisition/delivery times, source dependencies and coefficient requirements. Test legal access and arbitrary dirty restoration; price any completion against the full channel/endpoint/hosting allowance. Stop with the exact missing implication or a scoped counterexample rather than expanding the static cover census.", + "bottleneck_link": "Completing an already realized changed channel tests a concrete construction opportunity, instead of refining the incumbent packing. A positive local result still needs global and all-size admission.", + "allowed_variations": [ + "One correction factorization, one chronological cut, or one explicit hosting obstruction.", + "A changed correction schedule with an updated full bill and native frame contract." + ], + "scope_change_triggers": [ + "Recompiling the already certified low-rank channel without closing a new obligation.", + "Treating a pending ancestor, local histogram or unpriced side correction as an admitted global supplier.", + "Repeating a correction or physical conversion already supplied by a pending follow-up without adding independent coverage or a different unresolved obligation.", + "Repeating the 208-flag static matching or calling a static nested cover a chronological correction program. Independent audit of that certificate is distinct and remains useful." + ], + "overlap_terms": [ + "P104", + "I-G/2", + "side correction", + "native channel", + "1972", + "1991", + "2586", + "endpoint transport", + "physical dual", + "relay composition", + "2981", + "joint unit flags", + "acquisition delivery", + "static nesting" + ], + "existing_checks": [ + { + "scope": "PR #2981 reports static joint endpoint flags and a matching of 208 departure and arrival flags; archival intake is not independent verification.", + "evidence": "research/p104-joint-unit-flags/README.md", + "remaining": "Independent flag check and a chronological coefficient program with dirty restoration and a complete cost.", + "status": "author-checked", + "source_commit": "3d24b92d8ba057b57cb2d480170ec407520e6882", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + } + ] + }, + "scope_status": "refined", + "actual_scope": "Independent replay of the published 208-flag matching against the 4058-event channel witness: first-touch chronology and a complete endpoint frame-restoration census.", + "scope_change_reason": "The #3259 fixed-cover support cut already has a registered verifier on this base. This package takes the live chronology and dirty-restoration obligation for the published word only, and does not rebuild the support cut.", + "switched_from": "PR #3259 fixed-cover support cut", + "switch_reason": "research/p104-pooled-cut-independent on pinned main, head b572b0c25569898579041200e95731c5a43c9189, already registers a Python 3.12 verifier for the same missing pair C[71,102]=-1/2, forward cone 1725, and backward cone 37. A second census of that cut is not the live gap.", + "bottleneck_link": "A static matching is not a correction until the published word's frames are restored and coefficients are delivered in time. This census records that restoration fails on every endpoint.", + "budget_minutes": 60, + "stop_rule": "Stop after the first-touch order and the 104-source/104-target restoration census agree across two scanners. Do not build a correction word or search another matching.", + "outcome": "completed", + "evidence": "Targets are first touched by event 410, sources at or after event 488, no event names both an X and a Y register, and zero of 208 endpoint frames return to their initial frames. The basis head meets the target final on 4 of 208 flags.", + "author": "Wentao Li", + "ai_assistance": "Substantial AI assistance for derivation, implementation, checking and writing.", + "no_new_kappa": true, + "open_questions": [ + { + "question": "Can a chronological correction deliver the published coefficients and restore arbitrary dirt without repaying the frame loss?", + "why_it_matters": "Frame inequality on the published word does not by itself price a repair or admit a supplier.", + "first_step": "Pin one flag whose basis head is absent from the target final and write the coefficient and restoration steps that flag still lacks.", + "blocked_by": "This package records the schedule and the restoration census. It does not construct the repair." + } + ] +} diff --git a/research/p104-channel-touch-restoration-audit/VERIFY.json b/research/p104-channel-touch-restoration-audit/VERIFY.json new file mode 100644 index 0000000000..7f6c1eda62 --- /dev/null +++ b/research/p104-channel-touch-restoration-audit/VERIFY.json @@ -0,0 +1,29 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/p104-joint-unit-flags/CERTIFICATE.json", + "research/p104-native-channel/inputs/LOWRANK-WITNESS.json", + "research/p104-endpoint-geometric-budget/geometry.py", + "research/p104-flag-channel-schedule/RESULT.json" + ], + "commands": [ + { + "argv": ["{python}", "-I", "-O", "-Werror", "-B", "{package}/verify.py"], + "timeout_seconds": 60, + "checks": "Forward touch scan, frame-restoration census, and #3242 field comparison" + }, + { + "argv": ["{python}", "-I", "-O", "-Werror", "-B", "{package}/independent.py"], + "timeout_seconds": 60, + "checks": "Index-list touch scan and setwise frame comparison" + }, + { + "argv": ["{python}", "-I", "-O", "-Werror", "-B", "{package}/test_package.py"], + "timeout_seconds": 90, + "checks": "Duplicate JSON keys, temp-copy certificate corruption, optimized admission, scanner agreement" + } + ] +} diff --git a/research/p104-channel-touch-restoration-audit/independent.py b/research/p104-channel-touch-restoration-audit/independent.py new file mode 100644 index 0000000000..b643e6e615 --- /dev/null +++ b/research/p104-channel-touch-restoration-audit/independent.py @@ -0,0 +1,267 @@ +#!/usr/bin/env python3 +"""Second chronology scanner. It does not import verify.py. + +Touches are stored as index lists. First and last events are min and max. +Frames are compared as sets. A matched pair co-occurs only when those index +sets meet. Admission uses need() and remains active under python -O. +""" + +import hashlib +import json +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +MARKER = ( + "PASS_P104_CHANNEL_TOUCH_RESTORATION_INDEPENDENT events=4058 " + "flags=208 restored=0 no_new_kappa" +) +COORDINATE_BASIS = frozenset((1, 2, 4, 8, 16, 32, 64, 128, 256)) + + +def need(ok, message): + if not ok: + raise ValueError(message) + + +def pairs_unique(pairs): + value = {} + for key, item in pairs: + need(key not in value, "duplicate JSON key") + value[key] = item + return value + + +def read_json(path): + raw = Path(path).read_bytes() + need(len(raw) <= 2_000_000, "input exceeds 2 MB") + return json.loads(raw, object_pairs_hook=pairs_unique) + + +def register_name(item): + if type(item) is not str or len(item) < 2 or item[0] not in "XY": + return None + if not item[1:].isdigit() or int(item[1:]) > 103: + return None + return item + + +def frame_set(frame): + need(type(frame) is list, "frame") + values = [] + for entry in frame: + need(type(entry) is int, "frame entry") + values.append(entry) + folded = frozenset(values) + need(len(folded) == len(values), "duplicate frame vector") + return folded + + +def index_touches(program): + seen = {f"{kind}{index}": [] for kind in "XY" for index in range(104)} + joint = 0 + for index, event in enumerate(program): + need(type(event) is list, "event shape") + found = [] + for slot in range(len(event)): + name = register_name(event[slot]) + if name is None: + continue + found.append(name) + seen[name].append(index) + has_source = False + has_target = False + for name in found: + has_source = has_source or name[0] == "X" + has_target = has_target or name[0] == "Y" + if has_source and has_target: + joint += 1 + return seen, joint + + +def coefficients(program, name): + found = set() + for event in program: + if event[0] != "add": + continue + named = register_name(event[1]) == name or register_name(event[2]) == name + if not named: + continue + need(type(event[3]) in {str, int}, "add coefficient") + found.add(str(event[3])) + return sorted(found) + + +def build_receipt(witness, helpers): + program = witness["program"] + need(len(program) == 4058 and len(helpers) == 208, "published sizes") + seen, joint = index_touches(program) + for name, hits in seen.items(): + need(len(hits) > 0, "missing register " + name) + source_first = min(seen[f"X{i}"][0] for i in range(104)) + target_last_first = max(seen[f"Y{i}"][0] for i in range(104)) + earliest = [f"X{i}" for i in range(104) if seen[f"X{i}"][0] == source_first] + latest = [f"Y{i}" for i in range(104) if seen[f"Y{i}"][0] == target_last_first] + before = 0 + same = 0 + meet = 0 + restored_pairs = 0 + starts_at_head = 0 + head_hits = [] + gaps = [] + for index, row in enumerate(helpers): + source_hits = seen[f"X{row['source']}"] + target_hits = seen[f"Y{row['target']}"] + if target_hits[0] < source_hits[0]: + before += 1 + if target_hits[0] == source_hits[0]: + same += 1 + if set(source_hits) & set(target_hits): + meet += 1 + initial = witness["initial_frames"][f"X{row['source']}"] + final = witness["final_frames"][f"Y{row['target']}"] + head = row["basis"][0] + if initial == [head]: + starts_at_head += 1 + if head in final: + head_hits.append( + { + "flag_index": index, + "source": row["source"], + "target": row["target"], + "basis_head": head, + } + ) + source_same = frame_set(initial) == frame_set( + witness["final_frames"][f"X{row['source']}"] + ) + target_same = frame_set(witness["initial_frames"][f"Y{row['target']}"]) == frame_set( + final + ) + if source_same or target_same: + restored_pairs += 1 + gaps.append( + ( + source_hits[0] - target_hits[0], + row["source"], + row["target"], + target_hits[0], + source_hits[0], + ) + ) + source_ranks = {} + basis_finals = 0 + restored_sources = 0 + for index in range(104): + initial = frame_set(witness["initial_frames"][f"X{index}"]) + final = frame_set(witness["final_frames"][f"X{index}"]) + source_ranks[str(len(initial))] = source_ranks.get(str(len(initial)), 0) + 1 + if final == COORDINATE_BASIS: + basis_finals += 1 + if initial == final: + restored_sources += 1 + empty_targets = 0 + target_ranks = {} + restored_targets = 0 + for index in range(104): + initial = frame_set(witness["initial_frames"][f"Y{index}"]) + final = frame_set(witness["final_frames"][f"Y{index}"]) + if not initial: + empty_targets += 1 + target_ranks[str(len(final))] = target_ranks.get(str(len(final)), 0) + 1 + if initial == final: + restored_targets += 1 + gap, source, target, target_first, source_at = min(gaps) + flag = helpers[0] + return { + "schema_version": 1, + "claim_id": "p104-channel-touch-restoration-audit", + "pinned_main": "6f100d4bb5083f8c35d96fd95a539811c62f245c", + "flags": 208, + "unique_source_target_pairs": len({(row["source"], row["target"]) for row in helpers}), + "program_events": 4058, + "joint_source_target_events": joint, + "matched_pairs_target_before_source": before, + "matched_pairs_cooccurring": meet, + "matched_same_first_event": same, + "latest_target_first_event": target_last_first, + "latest_target_firsts": latest, + "earliest_source_event": source_first, + "earliest_sources": earliest, + "population_gap": source_first - target_last_first, + "minimum_matched_first_touch_gap": gap, + "minimum_matched_pair": { + "source": source, + "target": target, + "target_first": target_first, + "source_first": source_at, + }, + "source_initial_ranks": source_ranks, + "source_final_equals_coordinate_basis": basis_finals, + "target_initial_empty": empty_targets, + "target_final_ranks": target_ranks, + "frame_restored_sources": restored_sources, + "frame_restored_targets": restored_targets, + "matched_pairs_with_either_endpoint_frame_restored": restored_pairs, + "sources_starting_at_basis_head": starts_at_head, + "targets_whose_final_contains_basis_head": len(head_hits), + "basis_head_in_target_final": head_hits, + "flag0": { + "source": flag["source"], + "target": flag["target"], + "basis_head": flag["basis"][0], + "source_events": [min(seen["X0"]), max(seen["X0"])], + "target_events": [min(seen["Y34"]), max(seen["Y34"])], + "source_coefficients": coefficients(program, "X0"), + "target_coefficients": coefficients(program, "Y34"), + "source_initial": witness["initial_frames"]["X0"], + "source_frame_restored": frame_set(witness["initial_frames"]["X0"]) + == frame_set(witness["final_frames"]["X0"]), + "target_frame_restored": frame_set(witness["initial_frames"]["Y34"]) + == frame_set(witness["final_frames"]["Y34"]), + "target_final_contains_basis_head": flag["basis"][0] + in witness["final_frames"]["Y34"], + }, + "author_3242_fields_match": True, + "no_new_kappa": True, + } + + +def evaluate(): + manifest = read_json(HERE / "SOURCES.json") + for row in manifest["files"]: + if row["usage"] != "input": + continue + raw = (ROOT / row["path"]).read_bytes() + need(hashlib.sha256(raw).hexdigest() == row["sha256"], "source hash: " + row["path"]) + certificate = read_json(ROOT / "research/p104-joint-unit-flags/CERTIFICATE.json") + witness = read_json(ROOT / "research/p104-native-channel/inputs/LOWRANK-WITNESS.json") + author = read_json(ROOT / "research/p104-flag-channel-schedule/RESULT.json") + geometry = (ROOT / "research/p104-endpoint-geometric-budget/geometry.py").read_text( + encoding="utf-8" + ) + need("sources = [paths[f'X{s}'] for s in range(104)]" in geometry, "source naming") + need("targets = [paths[f'Y{t}'] for t in range(104)]" in geometry, "target naming") + receipt = build_receipt(witness, certificate["helpers"]) + need(receipt["joint_source_target_events"] == 0, "joint event") + need(receipt["frame_restored_sources"] == 0, "source frame returned") + need(receipt["frame_restored_targets"] == 0, "target frame returned") + need(author["earliest_source_event"] == receipt["earliest_source_event"], "discrepancy with #3242 earliest source") + need(author["latest_target_first_event"] == receipt["latest_target_first_event"], "discrepancy with #3242 latest target") + need(author["joint_source_target_events"] == 0, "discrepancy with #3242 joint events") + need(author["matched_pairs_with_target_first"] == 208, "discrepancy with #3242 matched order") + need(author["flag0"]["restored"] is False, "discrepancy with #3242 restored flag") + need(set(author["flag0"]["source_coefficients"]) == set(receipt["flag0"]["source_coefficients"]), "discrepancy with #3242 X0 coefficients") + need(set(author["flag0"]["target_coefficients"]) == set(receipt["flag0"]["target_coefficients"]), "discrepancy with #3242 Y34 coefficients") + return receipt + + +def main(): + observed = evaluate() + expected = read_json(HERE / "CERTIFICATE.json") + need(observed == expected, "certificate mismatch") + print(MARKER) + + +if __name__ == "__main__": + main() diff --git a/research/p104-channel-touch-restoration-audit/test_package.py b/research/p104-channel-touch-restoration-audit/test_package.py new file mode 100644 index 0000000000..353c7e10ba --- /dev/null +++ b/research/p104-channel-touch-restoration-audit/test_package.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python3 +"""Admission, corruption, and scanner-agreement checks. No assert statements.""" + +import hashlib +import json +import subprocess +import sys +import tempfile +from pathlib import Path + +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import independent +import verify + + +def need(ok, message): + if not ok: + raise ValueError(message) + + +def test_duplicate_key(): + with tempfile.TemporaryDirectory() as tmp: + path = Path(tmp) / "dup.json" + path.write_text('{"a": 1, "a": 2}\n', encoding="utf-8") + try: + verify.read_json(path) + except ValueError as exc: + need(str(exc) == "duplicate JSON key", "duplicate message") + else: + need(False, "duplicate key accepted") + + +def test_corrupt_certificate(): + observed = verify.evaluate() + with tempfile.TemporaryDirectory() as tmp: + path = Path(tmp) / "CERTIFICATE.json" + blob = json.loads((HERE / "CERTIFICATE.json").read_text(encoding="utf-8")) + blob["program_events"] = 4057 + path.write_text(json.dumps(blob), encoding="utf-8") + bad = verify.read_json(path) + try: + verify.admit(observed, bad) + except ValueError as exc: + need(str(exc) == "certificate mismatch", "corruption message") + else: + need(False, "corrupt certificate accepted") + live = verify.read_json(HERE / "CERTIFICATE.json") + need(live["program_events"] == 4058, "on-disk certificate mutated") + + +def test_optimized_admission(): + script = ( + "import sys\n" + "from pathlib import Path\n" + f"sys.path.insert(0, {str(HERE)!r})\n" + "import verify\n" + "verify.need(__debug__ is False, 'optimization off')\n" + "try:\n" + " verify.need(False, 'admission')\n" + "except ValueError as exc:\n" + " if str(exc) != 'admission':\n" + " raise SystemExit('wrong admission')\n" + "else:\n" + " raise SystemExit('admission skipped')\n" + "print('PASS_OPTIMIZED_ADMISSION')\n" + ) + done = subprocess.run( + [sys.executable, "-O", "-I", "-B", "-c", script], + check=False, + capture_output=True, + text=True, + ) + need(done.returncode == 0, "optimized admission failed: " + done.stderr) + need("PASS_OPTIMIZED_ADMISSION" in done.stdout, "optimized marker") + + +def test_sample_order(): + program = [ + ["add", "Y34", "Q1", "1/4", []], + ["transport", "X0", [232], [8], 4], + ] + first, _last, _present, joint = verify.forward_touches(program) + seen, joints = independent.index_touches(program) + need(first["Y34"] == 0 and first["X0"] == 1, "sample order") + need(seen["Y34"] == [0] and seen["X0"] == [1], "sample lists") + need(joint == 0 and joints == 0, "sample joint") + need(verify.add_coefficients(program, "Y34") == ["1/4"], "sample coefficient") + need(independent.coefficients(program, "X0") == [], "sample source coefficient") + need(not (set(seen["Y34"]) & set(seen["X0"])), "sample meeting") + + +def test_hash_rejection(): + with tempfile.TemporaryDirectory() as tmp: + path = Path(tmp) / "blob.txt" + path.write_bytes(b"nope") + try: + verify.need( + hashlib.sha256(path.read_bytes()).hexdigest() == "0" * 64, + "source hash: temp", + ) + except ValueError as exc: + need("source hash" in str(exc), "hash message") + else: + need(False, "bad hash accepted") + + +def test_scanners_agree(): + before = { + path.name: hashlib.sha256(path.read_bytes()).hexdigest() + for path in HERE.iterdir() + if path.is_file() + } + left = verify.evaluate() + right = independent.evaluate() + need(left == right, "scanner disagreement") + verify.admit(left, verify.read_json(HERE / "CERTIFICATE.json")) + after = { + path.name: hashlib.sha256(path.read_bytes()).hexdigest() + for path in HERE.iterdir() + if path.is_file() + } + need(before == after, "audit wrote package files") + + +def main(): + test_duplicate_key() + test_corrupt_certificate() + test_optimized_admission() + test_sample_order() + test_hash_rejection() + test_scanners_agree() + print("PASS_P104_CHANNEL_TOUCH_RESTORATION_TESTS groups=6") + + +if __name__ == "__main__": + main() diff --git a/research/p104-channel-touch-restoration-audit/verify.py b/research/p104-channel-touch-restoration-audit/verify.py new file mode 100644 index 0000000000..212f5874bb --- /dev/null +++ b/research/p104-channel-touch-restoration-audit/verify.py @@ -0,0 +1,319 @@ +#!/usr/bin/env python3 +"""Read-only chronology and frame-restoration audit of the published P104 word. + +This module does not import the #3242 or #3259 verifiers. Admission uses +need(); those checks stay active when Python is started with -O. +""" + +import hashlib +import json +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +MARKER = ( + "PASS_P104_CHANNEL_TOUCH_RESTORATION events=4058 flags=208 " + "restored=0 no_new_kappa" +) +INPUTS = ( + "research/p104-joint-unit-flags/CERTIFICATE.json", + "research/p104-native-channel/inputs/LOWRANK-WITNESS.json", + "research/p104-endpoint-geometric-budget/geometry.py", + "research/p104-flag-channel-schedule/RESULT.json", +) +AUDITED = "research/p104-flag-channel-schedule/RESULT.json" +COORDINATE_BASIS = (1, 2, 4, 8, 16, 32, 64, 128, 256) +SOURCE_LINE = "sources = [paths[f'X{s}'] for s in range(104)]" +TARGET_LINE = "targets = [paths[f'Y{t}'] for t in range(104)]" + + +def need(ok, message): + if not ok: + raise ValueError(message) + + +def pairs_unique(pairs): + value = {} + for key, item in pairs: + need(key not in value, "duplicate JSON key") + value[key] = item + return value + + +def read_json(path): + raw = Path(path).read_bytes() + need(len(raw) <= 2_000_000, "input exceeds 2 MB") + return json.loads(raw, object_pairs_hook=pairs_unique) + + +def register_name(item): + if type(item) is not str or len(item) < 2 or item[0] not in "XY": + return None + tail = item[1:] + if not tail.isdigit(): + return None + index = int(tail) + if index > 103: + return None + return item + + +def canonical_frame(frame): + need(type(frame) is list, "frame") + seen = [] + for entry in frame: + need(type(entry) is int, "frame entry") + need(entry not in seen, "duplicate frame vector") + seen.append(entry) + return tuple(sorted(seen)) + + +def forward_touches(program): + first = {} + last = {} + present = {} + joint = 0 + for index, event in enumerate(program): + need(type(event) is list and 1 <= len(event) <= 8, "event shape") + names = [] + for item in event: + name = register_name(item) + if name is not None: + names.append(name) + kinds = {name[0] for name in names} + if "X" in kinds and "Y" in kinds: + joint += 1 + for name in names: + if name not in first: + first[name] = index + present[name] = set() + last[name] = index + present[name].add(index) + return first, last, present, joint + + +def add_coefficients(program, name): + found = [] + for event in program: + if event[0] != "add": + continue + slots = (register_name(event[1]), register_name(event[2])) + if name not in slots: + continue + need(type(event[3]) in {str, int}, "add coefficient") + text = str(event[3]) + if text not in found: + found.append(text) + found.sort() + return found + + +def pin_sources(): + manifest = read_json(HERE / "SOURCES.json") + rows = manifest["files"] + inputs = [row for row in rows if row["usage"] == "input"] + need(tuple(row["path"] for row in inputs) == INPUTS, "input inventory") + need(any(row["path"] == AUDITED for row in inputs), "audited claim") + pinned = {} + for row in inputs: + path = ROOT / row["path"] + raw = path.read_bytes() + need(len(raw) <= 2_000_000, "source size") + digest = hashlib.sha256(raw).hexdigest() + need(digest == row["sha256"], "source hash: " + row["path"]) + pinned[row["path"]] = raw + return pinned + + +def build_receipt(witness, helpers): + program = witness["program"] + need(len(program) == 4058, "word length") + need(len(helpers) == 208, "flag count") + first, last, present, joint = forward_touches(program) + sources = [f"X{i}" for i in range(104)] + targets = [f"Y{i}" for i in range(104)] + need(all(name in first for name in sources + targets), "missing register") + source_first = min(first[name] for name in sources) + target_last_first = max(first[name] for name in targets) + earliest = sorted(name for name in sources if first[name] == source_first) + latest = sorted(name for name in targets if first[name] == target_last_first) + pairs = [] + head_hits = [] + restored_pairs = 0 + starts_at_head = 0 + meetings = 0 + for index, row in enumerate(helpers): + need(type(row["source"]) is int and type(row["target"]) is int, "endpoint") + source = f"X{row['source']}" + target = f"Y{row['target']}" + need(source in first and target in first, "matched register") + gap = first[source] - first[target] + pairs.append((gap, row["source"], row["target"], first[target], first[source])) + if present[source] & present[target]: + meetings += 1 + head = row["basis"][0] + initial = witness["initial_frames"][source] + if initial == [head]: + starts_at_head += 1 + if head in witness["final_frames"][target]: + head_hits.append( + { + "flag_index": index, + "source": row["source"], + "target": row["target"], + "basis_head": head, + } + ) + source_back = canonical_frame(initial) == canonical_frame( + witness["final_frames"][source] + ) + target_back = canonical_frame(witness["initial_frames"][target]) == canonical_frame( + witness["final_frames"][target] + ) + if source_back or target_back: + restored_pairs += 1 + source_ranks = {} + final_basis = 0 + restored_sources = 0 + for index in range(104): + initial = canonical_frame(witness["initial_frames"][f"X{index}"]) + final = canonical_frame(witness["final_frames"][f"X{index}"]) + source_ranks[str(len(initial))] = source_ranks.get(str(len(initial)), 0) + 1 + if final == COORDINATE_BASIS: + final_basis += 1 + if initial == final: + restored_sources += 1 + empty_targets = 0 + target_ranks = {} + restored_targets = 0 + for index in range(104): + initial = canonical_frame(witness["initial_frames"][f"Y{index}"]) + final = canonical_frame(witness["final_frames"][f"Y{index}"]) + if initial == (): + empty_targets += 1 + target_ranks[str(len(final))] = target_ranks.get(str(len(final)), 0) + 1 + if initial == final: + restored_targets += 1 + gap, source, target, target_first, source_at = min(pairs) + flag = helpers[0] + return { + "schema_version": 1, + "claim_id": "p104-channel-touch-restoration-audit", + "pinned_main": "6f100d4bb5083f8c35d96fd95a539811c62f245c", + "flags": 208, + "unique_source_target_pairs": len({(row["source"], row["target"]) for row in helpers}), + "program_events": 4058, + "joint_source_target_events": joint, + "matched_pairs_target_before_source": sum(1 for item in pairs if item[0] > 0), + "matched_pairs_cooccurring": meetings, + "matched_same_first_event": sum(1 for item in pairs if item[0] == 0), + "latest_target_first_event": target_last_first, + "latest_target_firsts": latest, + "earliest_source_event": source_first, + "earliest_sources": earliest, + "population_gap": source_first - target_last_first, + "minimum_matched_first_touch_gap": gap, + "minimum_matched_pair": { + "source": source, + "target": target, + "target_first": target_first, + "source_first": source_at, + }, + "source_initial_ranks": source_ranks, + "source_final_equals_coordinate_basis": final_basis, + "target_initial_empty": empty_targets, + "target_final_ranks": target_ranks, + "frame_restored_sources": restored_sources, + "frame_restored_targets": restored_targets, + "matched_pairs_with_either_endpoint_frame_restored": restored_pairs, + "sources_starting_at_basis_head": starts_at_head, + "targets_whose_final_contains_basis_head": len(head_hits), + "basis_head_in_target_final": head_hits, + "flag0": { + "source": flag["source"], + "target": flag["target"], + "basis_head": flag["basis"][0], + "source_events": [first["X0"], last["X0"]], + "target_events": [first["Y34"], last["Y34"]], + "source_coefficients": add_coefficients(program, "X0"), + "target_coefficients": add_coefficients(program, "Y34"), + "source_initial": witness["initial_frames"]["X0"], + "source_frame_restored": canonical_frame(witness["initial_frames"]["X0"]) + == canonical_frame(witness["final_frames"]["X0"]), + "target_frame_restored": canonical_frame(witness["initial_frames"]["Y34"]) + == canonical_frame(witness["final_frames"]["Y34"]), + "target_final_contains_basis_head": flag["basis"][0] + in witness["final_frames"]["Y34"], + }, + "author_3242_fields_match": True, + "no_new_kappa": True, + } + + +def agree_with_author(receipt, author, witness): + flag = receipt["flag0"] + need(author["flags"] == 208, "discrepancy with #3242 flags") + need(author["program_events"] == 4058, "discrepancy with #3242 events") + need(author["joint_source_target_events"] == 0, "discrepancy with #3242 joint events") + need( + author["matched_pairs_with_target_first"] == 208, + "discrepancy with #3242 matched order", + ) + need(author["earliest_source_event"] == receipt["earliest_source_event"], "discrepancy with #3242 earliest source") + need( + author["latest_target_first_event"] == receipt["latest_target_first_event"], + "discrepancy with #3242 latest target", + ) + need(author["matched_same_first_event"] == 0, "discrepancy with #3242 same first") + recorded = author["flag0"] + need(recorded["source"] == 0 and recorded["target"] == 34, "discrepancy with #3242 flag 0") + need(recorded["basis_head"] == flag["basis_head"], "discrepancy with #3242 basis head") + need(recorded["source_events"] == flag["source_events"], "discrepancy with #3242 X0 span") + need(recorded["target_events"] == flag["target_events"], "discrepancy with #3242 Y34 span") + need(set(recorded["source_coefficients"]) == set(flag["source_coefficients"]), "discrepancy with #3242 X0 coefficients") + need(set(recorded["target_coefficients"]) == set(flag["target_coefficients"]), "discrepancy with #3242 Y34 coefficients") + need(recorded["source_initial"] == witness["initial_frames"]["X0"], "discrepancy with #3242 X0 initial") + need(recorded["restored"] is False, "discrepancy with #3242 restored flag") + need(recorded["target_final_contains_basis_head"] is True, "discrepancy with #3242 Y34 head") + need(author["no_new_kappa"] is True, "discrepancy with #3242 kappa flag") + + +def evaluate(): + pinned = pin_sources() + geometry = pinned[ + "research/p104-endpoint-geometric-budget/geometry.py" + ].decode("utf-8") + need(SOURCE_LINE in geometry, "source naming left the geometry") + need(TARGET_LINE in geometry, "target naming left the geometry") + certificate = json.loads( + pinned["research/p104-joint-unit-flags/CERTIFICATE.json"], + object_pairs_hook=pairs_unique, + ) + witness = json.loads( + pinned["research/p104-native-channel/inputs/LOWRANK-WITNESS.json"], + object_pairs_hook=pairs_unique, + ) + author = json.loads( + pinned[AUDITED], + object_pairs_hook=pairs_unique, + ) + receipt = build_receipt(witness, certificate["helpers"]) + agree_with_author(receipt, author, witness) + need(receipt["joint_source_target_events"] == 0, "joint event survived") + need(receipt["matched_pairs_cooccurring"] == 0, "cooccurrence encoding") + return receipt + + +def admit(observed, expected): + need(observed == expected, "certificate mismatch") + + +def main(): + observed = evaluate() + expected = read_json(HERE / "CERTIFICATE.json") + admit(observed, expected) + print(MARKER) + + +if __name__ == "__main__": + main()