diff --git a/research/pr7612-independent-invoice-recount/.gitattributes b/research/pr7612-independent-invoice-recount/.gitattributes new file mode 100644 index 0000000000..8abeb4295b --- /dev/null +++ b/research/pr7612-independent-invoice-recount/.gitattributes @@ -0,0 +1 @@ +inputs/** -text diff --git a/research/pr7612-independent-invoice-recount/README.md b/research/pr7612-independent-invoice-recount/README.md new file mode 100644 index 0000000000..a1bb437e4a --- /dev/null +++ b/research/pr7612-independent-invoice-recount/README.md @@ -0,0 +1,132 @@ +# Independent recount of the PR #7612 word, paid invoice and moment signs + +**No new κ. No frontier change. No supplier admission.** This package is an +independent finite audit of one open candidate, +[PR #7612](https://github.com/CrocSwap/integer-mult-bounds/pull/7612) at exact +head `e814828ee5b869c9468282d57ba28c364b07d130` (conditional κ = 0.003652740309, +Clear1nsight). The author requested independent review in the +[handoff thread](https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19626233). + +## Why this check adds coverage + +The four-command generic replay of #7612 does not count the candidate invoice +from the candidate word. `build.py` builds `data/invoice-new.json` as the #7611 +invoice plus the declared delta `{1:-34, 2:+34, 3:-17, 4:-17, 5:+17}`. Only the +two dedicated application stages (about 20 minutes, 2 GiB) reconstruct the +complete invoice. This package binds the declared paid histogram to the word +bytes with a separate count that runs in about one second. `verify.py` imports +no constructor, application or pricing engine from the PR. + +## Result + +All statements are about the four pinned files in `inputs/pr7612/`. Their bytes +equal the blobs at the PR head (see [SOURCES.json](SOURCES.json)). + +1. **Edit recount.** A diff that does not use the PR's index literals finds + exactly one dropped event (index 41074, `MOVE 329 373->618`) and four + substitutions (indices 41073, 41075, 41166, 42110). All of them act on fields + 134 and 329. The word headers are equal. Scalar content of the edited ADD is + equal. The incident ranks change from `{1,1,3,4}` to `{2,2,5}`. +2. **Chart chronology.** Each field is followed through the complete program of + both words (76,668 and 76,667 events). Each MOVE starts at the current chart + of its field. Each ADD, COPY and SCALE acts at the chart where its operands + are. Each INIT creates a dead owned field and each CLEAR removes a live owned + field at its current chart. The public fields end at the `final` charts. +3. **Paid recount.** Rank law: `rank(a->b) = dim(A+B) - dim(A∩B)` over GF(2) + for the frame spans A and B. In both words each MOVE joins two nested frames + and has a positive rank. Let `H(word)` be the MOVE rank histogram (public and + owned MOVEs together). Then, exactly: + + `paid(invoice) = 17 · H(word) + K` + + with the same word-independent caller histogram + + `K = {1:384, 8:656, 9:32, 16:416, 24:416, 32:416, 40:416, 48:416, 56:416, 64:208}` + + for #7611 and for #7612. The recounted native delta is + `H(7612) - H(7611) = {1:-2, 2:+2, 3:-1, 4:-1, 5:+1}`. Paid positions are + 110,281 and 110,264. The two invoices state equal targets (22,461 positions, + rank surplus 1,424). +4. **Moment signs.** A separate 256-bit integer interval engine (logarithms from + an `atanh` recurrence, exponentials from a Taylor series, both with explicit + remainder bounds) evaluates `M(κ) = Σ (T_r - P_r) r^(1-κ)`. The signs agree + with the PR at seven points: the candidate is positive at the claim, at the + tested point `0.003652740309007`, at the stated lower bracket and at the + #7611 raw upper. The candidate is negative at the stated upper bracket. The + #7611 invoice is negative at the claim and at its raw upper. An upper bound + of `dM/dκ` on `[0, 0.00376669]` is negative for both invoices (about + -3.8086e5 for #7612), so each crossing is unique on that interval. +5. **Controls.** Nine semantic mutations reject: a growth-only rank law, one + more paid unit, the old word with the new invoice, the ADD at the old contact + chart, the dropped MOVE restored, a wrong restoration chart, a changed frame + 373, the #7611 invoice at the claim, and a point above the bracket. + +**Local-only supplement.** `verify.py --lineage` reads the #7604, #7605 and +#7608 words and invoices from the PR head tree in local Git objects. The same +`K` holds for all three. This mode skips when the PR head object is absent. It +is not part of the registered command. + +## What this does not establish + +- The histogram `K` is measured from the invoices. This package does not derive + it from the #7113 caller. +- The target histogram is not recounted. The package only checks that the edit + leaves headers, owned MOVEs, INIT and CLEAR events unchanged and that both + invoices state equal targets. +- No physical map, Clifford identity, native or signed application, compiler, + precision, tape, ordinary bound or outer predicate is replayed. +- The five framework assumptions and the CLEAR44 service premise of #7608/#7611 + remain as stated in the PR. +- A correct count and a correct root are not a supplier admission. + +## Reproduce + +From the repository root, Python 3.10 or later, standard library only: + +```sh +python3 scripts/research_package.py --package research/pr7612-independent-invoice-recount --check-only +python3 scripts/research_package.py --package research/pr7612-independent-invoice-recount +``` + +Direct run, with the optional lineage supplement: + +```sh +git fetch --no-tags https://github.com/CrocSwap/integer-mult-bounds.git pull/7612/head +python3 -I -B research/pr7612-independent-invoice-recount/verify.py --lineage +``` + +Environment of the recorded run: CPython 3.13.9, Windows 11, about 1 s, with +the registered argv run directly, in normal and `-O` mode. The metadata and pin +check passed. The package runner requires Python 3.12 for the replay step, and +this machine has no Python 3.12. **The Python 3.12 runner replay is not run.** +Canonical main at the start and before submission: +`e54523517d0f03e58352e647c403a5af3e525a57`, priority revision 8, +checked 2026-11-16 UTC. + +## Open next questions + +The structured list is in [TASK.json](TASK.json). + +1. Derive the caller histogram `K` from the #7113 signed caller definition. + With that derivation, the complete paid invoice of each P104 successor word + follows from the word bytes in about one second. First step: count the QUERY + and IDLE charges by rank in the retained #7605 signed application. Blocker: + that reconstruction lives in the dedicated application stages, which this + session did not read. +2. Recount the productive target histogram from the word header and owner + chronology. First step: apply the target rule of the reviewed #5599/#7000 + proof review to the `hosted` and `ports` fields. Blocker: the word file does + not state the helper target semantics. + +## Credit + +The audited construction, word, invoices and claim are by Clear1nsight +(#7612, #7611), on the retained P104 lineage of Ali Romman (#7605), +DreamingOfClouds, SYLforge, Hao Yan, ToikY, Rohan Arun and their predecessors. +The recursive invoice schema and the pricing tools belong to their authors. +The vendored files keep their Apache-2.0 license. The task card +`independent-moment` and the package tooling are by Douglas Colkitt. + +This audit was prepared by fluorine with substantial Anthropic Claude +(Claude Code) assistance. New work is Apache-2.0. No independent human review +of this audit exists yet. diff --git a/research/pr7612-independent-invoice-recount/SOURCES.json b/research/pr7612-independent-invoice-recount/SOURCES.json new file mode 100644 index 0000000000..0913b08867 --- /dev/null +++ b/research/pr7612-independent-invoice-recount/SOURCES.json @@ -0,0 +1,66 @@ +{ + "schema_version": 1, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "75d77b328ea02ded535e7f23aee5b1e55d0bb1a8", + "sha256": "154c3d30455d778fd3343b6b4851f0fa4665f0f7625b0adb3675e2bafbbf6bf1" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81" + }, + { + "path": "research/pr7612-independent-invoice-recount/inputs/pr7612/word-7612.json.gz", + "usage": "input", + "git_blob": "8f530e70f8ce01c13f1c6f0eeba0caa5b6c8ad23", + "sha256": "92a3b664c99e5a8d52771f3d682af6b34dead3df3498eeb58d4f437873db33d6", + "origin": { + "pull_request": 7612, + "commit": "e814828ee5b869c9468282d57ba28c364b07d130", + "path": "research/p104-contact134-329-on7611/data/word.json.gz" + }, + "pin": "head:1f04a53c38623905e6eea0b185a5f344fe1bba66:research/pr7612-independent-invoice-recount/inputs/pr7612/word-7612.json.gz" + }, + { + "path": "research/pr7612-independent-invoice-recount/inputs/pr7612/word-7611.json.gz", + "usage": "input", + "git_blob": "0821cb79b8f386e27258984d2bc18866a1cff827", + "sha256": "cb8c33817afbf7863074af90e3d287d1ef48c45a761f653143947ce2f58db1b6", + "origin": { + "pull_request": 7612, + "commit": "e814828ee5b869c9468282d57ba28c364b07d130", + "path": "research/p104-contact134-329-on7611/retained/pr7611/data/word.json.gz" + }, + "pin": "head:1f04a53c38623905e6eea0b185a5f344fe1bba66:research/pr7612-independent-invoice-recount/inputs/pr7612/word-7611.json.gz" + }, + { + "path": "research/pr7612-independent-invoice-recount/inputs/pr7612/invoice-7612.json", + "usage": "input", + "git_blob": "9a2c003c454a8ef8e6129464ee7c9825c91cc42a", + "sha256": "c34cea264b96ad495401064bee801de6bea6509372770daec6e8bb3053b3d883", + "origin": { + "pull_request": 7612, + "commit": "e814828ee5b869c9468282d57ba28c364b07d130", + "path": "research/p104-contact134-329-on7611/data/invoice-new.json" + }, + "pin": "head:1f04a53c38623905e6eea0b185a5f344fe1bba66:research/pr7612-independent-invoice-recount/inputs/pr7612/invoice-7612.json" + }, + { + "path": "research/pr7612-independent-invoice-recount/inputs/pr7612/invoice-7611.json", + "usage": "input", + "git_blob": "859aa639fdca06dba05e2beb167302343e1ad081", + "sha256": "3e02c92a82e403154a33dc4ad7cc7b49e3add55ec9a1f8db330b3ac32007ccbb", + "origin": { + "pull_request": 7612, + "commit": "e814828ee5b869c9468282d57ba28c364b07d130", + "path": "research/p104-contact134-329-on7611/retained/pr7611/data/invoice-new.json" + }, + "pin": "head:1f04a53c38623905e6eea0b185a5f344fe1bba66:research/pr7612-independent-invoice-recount/inputs/pr7612/invoice-7611.json" + } + ] +} diff --git a/research/pr7612-independent-invoice-recount/TASK.json b/research/pr7612-independent-invoice-recount/TASK.json new file mode 100644 index 0000000000..ae6b16fe07 --- /dev/null +++ b/research/pr7612-independent-invoice-recount/TASK.json @@ -0,0 +1,105 @@ +{ + "schema_version": 1, + "task_id": "independent-moment", + "priority_revision": 8, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "original_card": { + "id": "independent-moment", + "question": "Does a changed construction's serialized target/paid invoice independently support its claimed improvement?", + "starting_points": [ + "docs/research/current-priorities.md", + "docs/research/research-family-status.md", + "certificates/selected-result.json", + "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md", + "docs/research/recursive-invoice-preflight.md" + ], + "methods": [ + "Construct and independently check one source-bound instance of the stated first experiment.", + "Seek an exact counterexample or target-specific complete-budget obstruction to that same proposed change." + ], + "acceptance_gate": "Demonstrate independence, source binding, positive cases and semantic failure controls. Name the existing checks and the missing coverage. More digits or another equivalent evaluation of an unchanged root is not by itself new verification coverage.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read revision 8, the selected review and live exact-source handoffs. Then follow this card's bounded first_experiment.", + "scope": "Source-bound orientation only, not a supplier replay or theorem proof." + }, + "first_experiment": "Independently recount one changed emitted word and its complete caller, importing no constructor or pricing engine. Include target losses, owned lifetimes, native orientation and extra charges. Check existing #5633/#5708/#5717/#5719 coverage to avoid duplicate audits and preserve its exact head. Stop after the chosen missing implication; a correct root alone is not supplier admission.", + "bottleneck_link": "Judge the actual current supplier contract and complete signed target/paid bill; frozen-profile ceilings require an applicability proof.", + "allowed_variations": [ + "One exact source head, helper/cut region or quantified proposition and changed hypothesis; check live handoffs first. Different seeds are not different scopes." + ], + "scope_change_triggers": [ + "Changing source head, helper/cut domain, operation alphabet or caller boundary without recording the new scope.", + "Treating an archived proposal or local numerical pass as complete supplier admission." + ], + "overlap_terms": [ + "invoice", + "signed moment", + "productive target", + "independent recount" + ], + "existing_checks": [ + { + "scope": "PR #4088: mixed local/owner/phase ledger and moment reported.", + "evidence": "research/staged544-mixed-fourth-entry/README.md", + "remaining": "Independent binding of changed construction to paid histogram, distinct from full admission.", + "status": "author-checked", + "source_commit": "72d7efc181edb21806a878f174847c96dd410ab0", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #4091: sharp pooled ceiling proposed for fixed THREE/FOUR words and inventory.", + "evidence": "research/staged-fourth-mixture-ceiling/README.md", + "remaining": "Validate dual, exhaustive pattern scope and exact source equivalence before applying to newer fills.", + "status": "author-checked", + "source_commit": "a29bdd8f56cd18b805917775cdec09ff935eddc4", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #4067: paid (2,2) to (1,3) exchange and fixed OQ4 host reported.", + "evidence": "research/r437-two-window-carrier/README.md", + "remaining": "Independent full cost delta; remaining caller/precision/stock obligations are separate.", + "status": "author-checked", + "source_commit": "a95f11c52e3ca1e4c5171b3c20d8f4b0815aee2e", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "Selected PR5599: complete helper-subspace construction and independent caller replay; five framework assumptions remain.", + "evidence": "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md", + "remaining": "The next experiment must identify uncovered source-specific work. Successor archive intake does not transfer this admission.", + "status": "reviewed", + "source_commit": "09dd0965711ca7eeb169057a420abab1c9052137", + "selected_record_sha256": "2a0220e866417774606e0f991e41b9c1d26b1f43b97857238cf478dbc7d330b5" + } + ] + }, + "scope_status": "refined", + "actual_scope": "Independent recount, at the exact open PR #7612 head e814828ee5b869c9468282d57ba28c364b07d130, of (1) the five-event edit from the #7611 word, (2) the chart chronology of both complete words, (3) the MOVE rank histogram of both words and its relation to the declared 17-call paid invoice, and (4) the signs of the declared complete moment at the claim, the tested point, the stated bracket and the #7611 raw upper. No constructor, application or pricing engine of the PR is imported.", + "scope_change_reason": "The card names #5633/#5708/#5717/#5719 as existing coverage. The live handoff thread now requests independent review of #7612, so the same first experiment is applied to that newer exact head. The word-independent caller part of the paid histogram is measured from the invoices, not rederived from the caller.", + "bottleneck_link": "The complex supplier binds. #7612 changes only paid MOVE ranks of the P104 word. Its generic replay builds the candidate invoice as the #7611 invoice plus a declared delta. This audit binds the declared paid histogram to the emitted word bytes with a separate rank count.", + "budget_minutes": 60, + "stop_rule": "Stop after the word-to-paid-invoice binding and the moment signs are resolved or one exact mismatch is found. Do not replay the native, signed, physical or outer stages.", + "outcome": "completed", + "evidence": "verify.py passes on CPython 3.13.9 (Windows) in about 1 s: paid = 17 x (MOVE rank histogram of the word) + one fixed caller histogram for #7611 and #7612, the native delta {1:-2,2:+2,3:-1,4:-1,5:+1} is recounted from the words, both words have a legal chart chronology, seven moment signs agree with the PR, and nine controls reject. The optional --lineage mode finds the same caller histogram for the #7604, #7605 and #7608 words (local Git objects only).", + "author": "fluorine", + "ai_assistance": "Prepared with substantial Anthropic Claude (Claude Code) assistance: task selection, verifier code, runs and text. No independent human review of the mathematics.", + "open_questions": [ + { + "question": "Derive the word-independent caller histogram {1:384, 8:656, 9:32, 16:416, 24:416, 32:416, 40:416, 48:416, 56:416, 64:208} from the #7113 signed caller definition, without the invoice files.", + "why_it_matters": "With that derivation the complete paid invoice of each P104 successor word follows from the word bytes in about one second. Reviewers can then reject a wrong declared delta before the 20-minute application replay.", + "first_step": "Read the 17-call caller in the retained #7605 signed application and count its QUERY and IDLE charges by rank. Compare with the histogram above.", + "blocked_by": "The caller reconstruction lives in the dedicated application stages. This session did not read or replay them." + }, + { + "question": "Recount the productive target histogram (22,461 positions) of the #7612 word from the word header and owner chronology.", + "why_it_matters": "This audit only confirms that the two invoices state equal targets and that the edit leaves headers, owned MOVEs, INIT and CLEAR events unchanged. The target law itself is not recounted.", + "first_step": "Locate the target rule in the reviewed #5599/#7000 proof review and apply it to the hosted and ports header fields of the word.", + "blocked_by": "The target credit rule depends on helper target semantics that the word file does not state." + } + ] +} diff --git a/research/pr7612-independent-invoice-recount/VERIFY.json b/research/pr7612-independent-invoice-recount/VERIFY.json new file mode 100644 index 0000000000..0e15212c6b --- /dev/null +++ b/research/pr7612-independent-invoice-recount/VERIFY.json @@ -0,0 +1,26 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/pr7612-independent-invoice-recount/inputs/pr7612/word-7612.json.gz", + "research/pr7612-independent-invoice-recount/inputs/pr7612/word-7611.json.gz", + "research/pr7612-independent-invoice-recount/inputs/pr7612/invoice-7612.json", + "research/pr7612-independent-invoice-recount/inputs/pr7612/invoice-7611.json" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "-W", + "error", + "{package}/verify.py" + ], + "timeout_seconds": 60, + "checks": "Input pins and canonical word digests; independent edit recount; complete chart chronology of both words; GF(2) MOVE rank recount and 17-call paid split; seven moment signs and strict monotonicity with an independent 256-bit interval engine; nine rejecting controls." + } + ] +} diff --git a/research/pr7612-independent-invoice-recount/inputs/pr7612/invoice-7611.json b/research/pr7612-independent-invoice-recount/inputs/pr7612/invoice-7611.json new file mode 100644 index 0000000000..859aa639fd --- /dev/null +++ b/research/pr7612-independent-invoice-recount/inputs/pr7612/invoice-7611.json @@ -0,0 +1 @@ +{"schema":"integer-mult-recursive-invoice/v1","contract":{"model":"mixed-target-unnormalized-power-v1","rank_semantics":"H_r costs r^(1-C); debit surrendered productive fields","ambient_rank":145,"boundary":"complete signed #7113 caller application with 17 native calls"},"paid":{"1":68197,"2":14382,"3":14093,"4":3791,"5":5865,"6":289,"7":187,"8":741,"9":32,"16":416,"24":416,"32":416,"40":416,"48":416,"56":416,"64":208},"targets":{"1":306,"2":357,"3":799,"4":3825,"5":1360,"6":731,"7":323,"8":544,"9":10888,"17":416,"25":416,"33":416,"41":416,"49":416,"57":416,"65":416,"73":208,"137":208}} \ No newline at end of file diff --git a/research/pr7612-independent-invoice-recount/inputs/pr7612/invoice-7612.json b/research/pr7612-independent-invoice-recount/inputs/pr7612/invoice-7612.json new file mode 100644 index 0000000000..9a2c003c45 --- /dev/null +++ b/research/pr7612-independent-invoice-recount/inputs/pr7612/invoice-7612.json @@ -0,0 +1,47 @@ +{ + "schema": "integer-mult-recursive-invoice/v1", + "contract": { + "model": "mixed-target-unnormalized-power-v1", + "rank_semantics": "H_r costs r^(1-C); debit surrendered productive fields", + "ambient_rank": 145, + "boundary": "complete signed #7113 caller application with 17 native calls" + }, + "paid": { + "1": 68163, + "2": 14416, + "3": 14076, + "4": 3774, + "5": 5882, + "6": 289, + "7": 187, + "8": 741, + "9": 32, + "16": 416, + "24": 416, + "32": 416, + "40": 416, + "48": 416, + "56": 416, + "64": 208 + }, + "targets": { + "1": 306, + "2": 357, + "3": 799, + "4": 3825, + "5": 1360, + "6": 731, + "7": 323, + "8": 544, + "9": 10888, + "17": 416, + "25": 416, + "33": 416, + "41": 416, + "49": 416, + "57": 416, + "65": 416, + "73": 208, + "137": 208 + } +} diff --git a/research/pr7612-independent-invoice-recount/inputs/pr7612/word-7611.json.gz b/research/pr7612-independent-invoice-recount/inputs/pr7612/word-7611.json.gz new file mode 100644 index 0000000000..0821cb79b8 Binary files /dev/null and b/research/pr7612-independent-invoice-recount/inputs/pr7612/word-7611.json.gz differ diff --git a/research/pr7612-independent-invoice-recount/inputs/pr7612/word-7612.json.gz b/research/pr7612-independent-invoice-recount/inputs/pr7612/word-7612.json.gz new file mode 100644 index 0000000000..8f530e70f8 Binary files /dev/null and b/research/pr7612-independent-invoice-recount/inputs/pr7612/word-7612.json.gz differ diff --git a/research/pr7612-independent-invoice-recount/verify.py b/research/pr7612-independent-invoice-recount/verify.py new file mode 100644 index 0000000000..9a79807426 --- /dev/null +++ b/research/pr7612-independent-invoice-recount/verify.py @@ -0,0 +1,474 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Independent recount of the PR #7612 word, paid invoice and moment signs. + +Imports no constructor, application or pricing engine from the audited PR. +Scope: finite checks on pinned bytes. Not a supplier admission. +""" +import argparse +import collections +import copy +import gzip +import hashlib +import json +import subprocess +import sys +from fractions import Fraction as Q +from pathlib import Path + +HERE = Path(__file__).absolute().parent +INPUTS = HERE / 'inputs' / 'pr7612' +PR_HEAD = 'e814828ee5b869c9468282d57ba28c364b07d130' +PR_ROOT = 'research/p104-contact134-329-on7611' +# SHA256 of the vendored bytes. They must equal the PR head blobs. +PINS = { + 'word-7612.json.gz': '92a3b664c99e5a8d52771f3d682af6b34dead3df3498eeb58d4f437873db33d6', + 'word-7611.json.gz': 'cb8c33817afbf7863074af90e3d287d1ef48c45a761f653143947ce2f58db1b6', + 'invoice-7612.json': 'c34cea264b96ad495401064bee801de6bea6509372770daec6e8bb3053b3d883', + 'invoice-7611.json': '3e02c92a82e403154a33dc4ad7cc7b49e3add55ec9a1f8db330b3ac32007ccbb', +} +# Canonical JSON digests that PROOF.md of the PR states for the two words. +CANONICAL = { + 'word-7612.json.gz': 'ff380ae02b238bdf41db5247a2278f7e7be391fe49879f91950fdb775a0f983a', + 'word-7611.json.gz': '177b74c42ac633aaee21b0bbd5373441ccba8e5bad029d827877cf2d585fd0e3', +} +CALLS = 17 +# Word-independent caller part of the paid histogram. This audit measures it. +CALLER = {1: 384, 8: 656, 9: 32, 16: 416, 24: 416, 32: 416, 40: 416, + 48: 416, 56: 416, 64: 208} +NATIVE_DELTA = {1: -2, 2: 2, 3: -1, 4: -1, 5: 1} +CLAIM = Q('0.003652740309') +TESTED = Q('0.003652740309007') +NEW_LO = Q(6128281319, 1677721600000) +NEW_HI = Q(153207033, 41943040000) +OLD_HI = CLAIM - Q(20741937499, 65536000000000000) +BIT_CAP = Q('0.00376669') +LINEAGE = { + 7604: ('retained/pr7605/retained/pr7604/word.json.gz', + 'retained/pr7605/retained/pr7604/invoice-new.json'), + 7605: ('retained/pr7605/data/word.json.gz', + 'retained/pr7605/data/invoice-new.json'), + 7608: ('retained/pr7608/data/word.json.gz', + 'retained/pr7608/data/invoice-new.json'), +} + + +class Reject(Exception): + pass + + +def require(ok, message): + if not ok: + raise Reject(message) + + +def sha(raw): + return hashlib.sha256(raw).hexdigest() + + +def load_word(raw): + return json.loads(gzip.decompress(raw)) + + +# ---------------------------------------------------------------- GF(2) ranks + +def gf2_rank(vectors): + basis = {} + for v in vectors: + while v: + top = v.bit_length() - 1 + if top not in basis: + basis[top] = v + break + v ^= basis[top] + return len(basis) + + +def move_rank(frames, a, b): + """Rank dim(A+B) - dim(A meet B), and whether the two frames are nested.""" + ra, rb = gf2_rank(frames[a]), gf2_rank(frames[b]) + ru = gf2_rank(frames[a] + frames[b]) + return 2 * ru - ra - rb, ru == max(ra, rb) + + +def move_histogram(word): + frames = word['frames'] + hist = collections.Counter() + for e in word['program']: + if e[0] == 'MOVE': + r, nested = move_rank(frames, e[2], e[3]) + require(nested, 'a MOVE joins two frames that are not nested') + require(r > 0, 'a MOVE has rank zero') + hist[r] += 1 + return hist + + +def growth_only_histogram(word): + # Wrong law for the negative control: charge only dim(A+B) - dim(A). + frames = word['frames'] + hist = collections.Counter() + for e in word['program']: + if e[0] == 'MOVE': + r = gf2_rank(frames[e[2]] + frames[e[3]]) - gf2_rank(frames[e[2]]) + if r: + hist[r] += 1 + return hist + + +def caller_part(word_hist, invoice): + paid = {int(r): n for r, n in invoice['paid'].items()} + rest = collections.Counter(paid) + for r, n in word_hist.items(): + rest[r] -= CALLS * n + require(all(n >= 0 for n in rest.values()), 'paid is below the word count') + return {r: n for r, n in sorted(rest.items()) if n} + + +# ------------------------------------------------------- chart chronology + +def chronology(word): + """Follow the chart of each field through the complete program.""" + require(len(word['initial']) == word['public'] == len(word['final']), + 'public field header') + chart = dict(enumerate(word['initial'])) + owned = set() + nframes = len(word['frames']) + for i, e in enumerate(word['program']): + op = e[0] + where = '%s at event %d' % (op, i) + if op == 'MOVE': + require(len(e) == 5 and e[2] != e[3] and 0 <= e[3] < nframes, where) + require(chart.get(e[1]) == e[2], where + ': source chart') + require(e[4] is (e[1] in owned), where + ': owner flag') + chart[e[1]] = e[3] + elif op in ('ADD', 'COPY'): + require(len(e) == 5 and e[1] != e[2], where) + require(chart.get(e[1]) == e[4] == chart.get(e[2]), + where + ': operands are not at the stated chart') + elif op == 'SCALE': + require(len(e) == 4 and chart.get(e[1]) == e[3], where + ': chart') + elif op == 'INIT': + require(len(e) == 3 and e[1] not in chart, where + ': live field') + require(e[1] >= word['public'], where + ': public field') + chart[e[1]] = e[2] + owned.add(e[1]) + elif op == 'CLEAR': + require(len(e) == 3 and e[1] in owned, where + ': not owned') + require(chart[e[1]] == e[2], where + ': chart') + del chart[e[1]] + owned.remove(e[1]) + else: + raise Reject(where + ': unknown opcode') + require(not owned, 'an owned field stays live at the end') + require([chart[f] for f in range(word['public'])] == word['final'], + 'final charts') + return {'events': len(word['program']), 'fields': len(chart)} + + +# ------------------------------------------------------------ edit recount + +def edit_script(old, new): + """Positions where the programs differ, found without the PR literals.""" + p, q = old['program'], new['program'] + require(all(old[k] == new[k] for k in old if k != 'program') + and old.keys() == new.keys(), 'word headers differ') + require(len(q) == len(p) - 1, 'event count') + first = next(i for i in range(len(q)) if p[i] != q[i]) + # A dropped event leaves p[d+1:] aligned with q[d:] up to substitutions. + # Accept only substitutions that keep the opcode and the acted field. + found = [] + for d in range(first, min(first + 8, len(p))): + aligned = p[:d] + p[d + 1:] + changes = [(i if i < d else i + 1, x, y) + for i, (x, y) in enumerate(zip(aligned, q)) if x != y] + if len(changes) <= 8 and all(x[:2] == y[:2] for _, x, y in changes): + found.append((d, changes)) + require(len(found) == 1, 'no unique dropped event explains the edit') + return found[0] + + +def check_edit(old, new): + drop, changes = edit_script(old, new) + p = old['program'] + require(p[drop][0] == 'MOVE' and not p[drop][4], 'dropped event') + fields = {p[drop][1]} | {x[1] for _, x, _ in changes} + require(fields == {134, 329}, 'edited fields') + for i, x, y in changes: + require(x[0] == y[0] and x[1] == y[1], 'opcode or field changed') + if x[0] == 'MOVE': + require(x[4] is False and y[4] is False, 'owned MOVE changed') + require(x[2] == y[2] or x[3] == y[3], 'both MOVE charts changed') + else: + require(x[0] == 'ADD' and x[:4] == y[:4], 'scalar content changed') + frames = old['frames'] + before = sorted(move_rank(frames, e[2], e[3])[0] + for e in [p[drop]] + [x for _, x, _ in changes] + if e[0] == 'MOVE') + after = sorted(move_rank(frames, y[2], y[3])[0] + for _, _, y in changes if y[0] == 'MOVE') + require(before == [1, 1, 3, 4] and after == [2, 2, 5], 'incident ranks') + return {'dropped_index': drop, 'dropped': p[drop], + 'substituted_indices': [i for i, _, _ in changes], + 'ranks_before': before, 'ranks_after': after} + + +# ------------------------------------------- exact interval moment engine + +BITS = 256 +ONE = 1 << BITS + + +def _atanh_inv(q): + """Integer bounds of atanh(1/q) * 2^BITS for an integer q >= 3.""" + lo = hi = 0 + j = 0 + while True: + den = (2 * j + 1) * q ** (2 * j + 1) + lo += ONE // den + hi += -(-ONE // den) + j += 1 + if den > ONE: + break + # Tail < next_term / (1 - q^-2) <= 2 * next_term, and next_term < 1 ulp. + return lo, hi + 2 + + +def log_table(top): + """ln(n) bounds from ln(n) = ln(n-1) + 2 atanh(1/(2n-1)).""" + table = {1: (0, 0)} + for n in range(2, top + 1): + a, b = _atanh_inv(2 * n - 1) + table[n] = (table[n - 1][0] + 2 * a, table[n - 1][1] + 2 * b) + return table + + +def _exp_bounds(y_lo, y_hi): + """Bounds of exp(y) * 2^BITS for 0 <= y < 8, y scaled by 2^BITS.""" + require(0 <= y_lo <= y_hi < 8 * ONE, 'exp domain') + lo, term = ONE, ONE + n = 0 + while term: + n += 1 + term = term * y_lo // (n * ONE) + lo += term + hi, term = ONE, ONE + n = 0 + while n < 32 or term > 1: + n += 1 + term = -(-term * y_hi // (n * ONE)) + hi += term + # n >= 32 > 2 * y_hi, so the tail is below the last term, which is <= 1. + return lo, hi + 2 + + +def moment_bounds(signed, kappa, logs): + """Bounds of sum_r signed[r] * r^(1-kappa), as exact rationals.""" + p = 1 - kappa + require(0 < p <= 1, 'exponent domain') + lo = hi = 0 + for r, s in signed.items(): + l_lo, l_hi = logs[r] + y_lo = l_lo * p.numerator // p.denominator + y_hi = -(-l_hi * p.numerator // p.denominator) + e_lo, e_hi = _exp_bounds(y_lo, y_hi) + lo += s * (e_lo if s > 0 else e_hi) + hi += s * (e_hi if s > 0 else e_lo) + return Q(lo, ONE), Q(hi, ONE) + + +def derivative_upper(signed, cap, logs): + """Upper bound of d/dkappa of the moment on the interval [0, cap].""" + total = 0 + for r, s in signed.items(): + if r == 1 or s == 0: + continue + l_lo, l_hi = logs[r] + if s > 0: + # -s ln(r) r^(1-kappa) is largest at kappa = cap. + e_lo = moment_bounds({r: 1}, cap, logs)[0] + total -= s * Q(l_lo, ONE) * e_lo + else: + # |s| ln(r) r^(1-kappa) is largest at kappa = 0. + total += -s * Q(l_hi, ONE) * r + return total + + +def signed_profile(invoice): + out = collections.Counter() + for r, n in invoice['targets'].items(): + out[int(r)] += n + for r, n in invoice['paid'].items(): + out[int(r)] -= n + return {r: s for r, s in out.items() if s} + + +def sign_at(signed, kappa, logs): + lo, hi = moment_bounds(signed, kappa, logs) + require(lo > 0 or hi < 0, 'moment sign is not resolved') + return 1 if lo > 0 else -1 + + +def check_moments(old_inv, new_inv): + for inv in (old_inv, new_inv): + require(inv['contract']['model'] == 'mixed-target-unnormalized-power-v1', + 'invoice model') + old, new = signed_profile(old_inv), signed_profile(new_inv) + logs = log_table(max(max(old), max(new))) + # Self-test of the engine against exact integer powers at kappa = 0. + lo, hi = moment_bounds(new, Q(0), logs) + exact = sum(r * s for r, s in new.items()) + require(lo <= exact <= hi and hi - lo < Q(1, 1 << 200), 'engine self-test') + require(exact == 1424, 'rank surplus') + wanted = [('candidate at claim', new, CLAIM, 1), + ('candidate at tested point', new, TESTED, 1), + ('candidate at stated lower bracket', new, NEW_LO, 1), + ('candidate at stated upper bracket', new, NEW_HI, -1), + ('candidate at #7611 raw upper', new, OLD_HI, 1), + ('#7611 at claim', old, CLAIM, -1), + ('#7611 at its raw upper', old, OLD_HI, -1)] + for label, profile, kappa, sign in wanted: + require(sign_at(profile, kappa, logs) == sign, label + ': sign') + require(OLD_HI < CLAIM < TESTED < NEW_LO < NEW_HI < BIT_CAP, 'point order') + slopes = [derivative_upper(x, BIT_CAP, logs) for x in (old, new)] + require(all(s < 0 for s in slopes), 'moment is not strictly decreasing') + return {'points': [label for label, _, _, _ in wanted], + 'derivative_upper_7611': float(slopes[0]), + 'derivative_upper_7612': float(slopes[1]), + 'interval': ['0', str(BIT_CAP)], 'engine_bits': BITS}, logs + + +# ------------------------------------------------------------------ controls + +def rejects(fn, *args): + try: + fn(*args) + except Reject: + return True + return False + + +def controls(old, new, old_inv, new_inv, logs): + seen = [] + + def control(name, ok): + require(ok, 'control did not reject: ' + name) + seen.append(name) + + hist = move_histogram(new) + drop, changes = edit_script(old, new) + # 1. A rank law that charges only frame growth does not fit the invoice. + wrong = growth_only_histogram(new) + control('growth-only rank law', + rejects(caller_part, wrong, new_inv) + or caller_part(wrong, new_inv) != CALLER) + # 2. One more paid unit in the invoice. + bad = copy.deepcopy(new_inv) + bad['paid']['1'] += 1 + control('invoice paid unit', caller_part(hist, bad) != CALLER) + # 3. The candidate invoice with the old word. + control('old word with new invoice', + rejects(caller_part, move_histogram(old), new_inv) + or caller_part(move_histogram(old), new_inv) != CALLER) + # 4. The edited ADD stays at the old contact chart. + index, x, _ = next(c for c in changes if c[1][0] == 'ADD') + bad = copy.deepcopy(new) + bad['program'][index - 1] = x + control('ADD at the old contact chart', rejects(chronology, bad)) + # 5. The dropped MOVE returns without the other substitutions. + bad = copy.deepcopy(new) + bad['program'].insert(drop, old['program'][drop]) + control('dropped MOVE restored', rejects(chronology, bad)) + # 6. A changed MOVE loses its restoration chart. + index, _, y = [c for c in changes if c[1][0] == 'MOVE'][-1] + bad = copy.deepcopy(new) + bad['program'][index - 1] = y[:3] + [y[3] + 1, y[4]] + control('wrong restoration chart', rejects(chronology, bad)) + # 7. A frame vector change breaks nestedness or the paid count. + bad = copy.deepcopy(new) + bad['frames'][373] = [30, 320] + control('changed frame 373', + rejects(move_histogram, bad) + or caller_part(move_histogram(bad), new_inv) != CALLER) + # 8. The #7611 invoice does not support the claim. + control('#7611 invoice at claim', + sign_at(signed_profile(old_inv), CLAIM, logs) == -1) + # 9. A point above the stated upper bracket is not positive. + control('candidate above bracket', + sign_at(signed_profile(new_inv), NEW_HI + Q(1, 10 ** 12), logs) == -1) + return seen + + +# ---------------------------------------------------------------------- main + +def audit(raw): + for name, pin in PINS.items(): + require(sha(raw[name]) == pin, 'input pin ' + name) + new, old = load_word(raw['word-7612.json.gz']), load_word(raw['word-7611.json.gz']) + for name, word in (('word-7612.json.gz', new), ('word-7611.json.gz', old)): + canon = json.dumps(word, sort_keys=True, separators=(',', ':')).encode() + require(sha(canon) == CANONICAL[name], 'canonical digest ' + name) + new_inv = json.loads(raw['invoice-7612.json']) + old_inv = json.loads(raw['invoice-7611.json']) + + report = {'edit': check_edit(old, new)} + report['chronology'] = {'7611': chronology(old), '7612': chronology(new)} + h_old, h_new = move_histogram(old), move_histogram(new) + delta = {r: h_new[r] - h_old[r] for r in sorted(set(h_old) | set(h_new)) + if h_new[r] != h_old[r]} + require(delta == NATIVE_DELTA, 'native MOVE rank delta') + require(caller_part(h_old, old_inv) == CALLER, '#7611 caller part') + require(caller_part(h_new, new_inv) == CALLER, '#7612 caller part') + require(old_inv['targets'] == new_inv['targets'], 'targets changed') + paid_old, paid_new = (sum(x['paid'].values()) for x in (old_inv, new_inv)) + require((paid_old, paid_new) == (110281, 110264), 'paid positions') + require(sum(new_inv['targets'].values()) == 22461, 'target positions') + report['recount'] = { + 'law': 'rank(a->b) = dim(A+B) - dim(A meet B) over GF(2); all nested', + 'moves_7611': dict(sorted(h_old.items())), + 'moves_7612': dict(sorted(h_new.items())), + 'native_delta': delta, 'calls': CALLS, 'caller_part': CALLER, + 'paid_positions': [paid_old, paid_new]} + report['moments'], logs = check_moments(old_inv, new_inv) + report['controls'] = controls(old, new, old_inv, new_inv, logs) + return report + + +def lineage(head): + """Optional: the same paid split on three earlier words in the PR tree.""" + out = {} + for number, (word_path, invoice_path) in LINEAGE.items(): + blobs = [] + for path in (word_path, invoice_path): + done = subprocess.run( + ['git', 'cat-file', 'blob', '%s:%s/%s' % (head, PR_ROOT, path)], + capture_output=True, cwd=str(HERE)) + if done.returncode: + return {'status': 'SKIPPED_PR_HEAD_OBJECT_ABSENT', 'head': head} + blobs.append(done.stdout) + hist = move_histogram(load_word(blobs[0])) + require(caller_part(hist, json.loads(blobs[1])) == CALLER, + 'lineage caller part #%d' % number) + out[str(number)] = dict(sorted(hist.items())) + return {'status': 'PASS_LINEAGE_SAME_CALLER_PART', 'head': head, 'moves': out} + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--lineage', action='store_true', + help='also check #7604/#7605/#7608 from local Git objects') + args = parser.parse_args() + raw = {name: (INPUTS / name).read_bytes() for name in PINS} + report = audit(raw) + if args.lineage: + report['lineage'] = lineage(PR_HEAD) + report['status'] = 'PASS_INDEPENDENT_RECOUNT_PR7612_DECLARED_SCOPE' + report['scope'] = ('Finite recount of pinned bytes at PR head ' + PR_HEAD + + '. Not a native, physical, compiler or outer admission.') + print(json.dumps(report, indent=1, sort_keys=True)) + + +if __name__ == '__main__': + try: + main() + except Reject as error: + sys.exit('REJECT: %s' % error)