diff --git a/research/pr7630-independent-recount/.gitattributes b/research/pr7630-independent-recount/.gitattributes new file mode 100644 index 0000000000..b13bbf03d0 --- /dev/null +++ b/research/pr7630-independent-recount/.gitattributes @@ -0,0 +1 @@ +inputs/** -text \ No newline at end of file diff --git a/research/pr7630-independent-recount/README.md b/research/pr7630-independent-recount/README.md new file mode 100644 index 0000000000..18d74a2664 --- /dev/null +++ b/research/pr7630-independent-recount/README.md @@ -0,0 +1,140 @@ +# Independent recount of the PR #7630 word, paid and target invoices + +**No new κ. No frontier change. No supplier admission.** This package is an +independent finite audit of one open candidate, +[PR #7630](https://github.com/CrocSwap/integer-mult-bounds/pull/7630) at exact +head `6026e87d1cac03eb5bd2aa8524a8f5891dd9934e` (conditional +κ = 0.0036667343458, DreamingOfClouds). It applies the method of +[PR #7628](https://github.com/CrocSwap/integer-mult-bounds/pull/7628) to a +word that also changes the productive target histogram. + +## Why this check adds coverage + +The generic replay of #7630 builds `data/invoice-new.json` as the #7623 invoice +plus a declared per-call delta, for the paid side and for the helper targets. +This package binds both sides of that delta to the emitted word bytes with +separate counts that run in about two seconds. `verify.py` imports no +constructor, application or pricing engine from the PR. No audit of #7630 or of +its parent #7623 was found among the open PRs on 2026-11-17. + +## Result + +All statements are about the four pinned files in `inputs/pr7630/`. Their bytes +equal the blobs at the PR head (see [SOURCES.json](SOURCES.json)). The #7623 +word bytes also equal the word published in #7623. + +1. **Header.** The two words have equal headers except `initial`. Exactly two + fields change: `initial[457]` 3 → 281 and `initial[461]` 3 → 285. +2. **Chart chronology.** Each field is followed through the complete program of + both words (77,277 and 208,738 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. 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 #7623 and for #7630. This `K` also equals the one of the #7612 recount. + The recounted native delta per call is + `H(7630) - H(7623) = {1:-2, 2:-3, 3:-5, 5:+1, 6:+2}` (6,257 to 6,250 MOVEs). + Paid positions are 110,145 and 110,026. +4. **Target recount.** For each helper field (every public field that is not a + main, with the main set as the PR defines it) the target rank is + `rank(final frame) - rank(initial frame)`. Then, exactly: + + `targets(invoice) = 17 · T(word) + K_T` + + with the same `K_T = {9:416, 17:416, 25:416, 33:416, 41:416, 49:416, 57:416, 65:416, 73:208, 137:208}` + for both words. The recounted helper delta per call is + `T(7630) - T(7623) = {6:+2, 9:-2}`. Target positions stay 22,461. The rank + surplus stays 1,424. +5. **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 #7630 + invoice is positive at the claim `0.0036667343458`, at the #7627 value + `0.003665731276` and at the #7623 value `0.0036624027915`. It is negative at + `0.0036667343459`. The #7623 invoice is positive at its own value, negative + at `0.0036624027916` and negative at the #7630 claim. An upper bound of + `dM/dκ` on `[0, 0.00376669]` is negative for both invoices (about + -3.794e5 for #7630), so each crossing is unique on that interval. +6. **Tent test.** The change in `Σ (T_r - P_r) f(r)` is zero or positive for + every `f(r) = min(r, a)`, a = 1 to 137, and positive for some a. Every + increasing concave `f` with `f(0) = 0` is a non-negative combination of + these tents on the integer ranks, so the #7630 profile is no worse for any + such tariff. The PR states this as "uniformly better". +7. **Controls.** Ten semantic mutations reject: a growth-only rank law, one more + paid unit, the old word with the new invoice, the old helper targets with + the new invoice, an undone rebirth of field 457, an ADD at the wrong chart, + a MOVE to another chart, a changed frame, the #7623 invoice at the claim, + and a point above the bracket. + +## What this does not establish + +- The histograms `K` and `K_T` are measured from the invoices. This package does + not derive them from the #7113 caller. +- The main set is the PR's own definition (`live`, `live + 112`, and the hosted + `X2` and `Y2` fields). It is not derived from the physical caller. +- The exact rational replay of the hub re-settle, the changed CLEAR contents and + the 5-smooth coefficient grid are not recounted. +- The ordinary bill is not recounted. The PR states 786,433,632 for #7623 and + 867,014,040 for #7630, below 10^9. The word grows from 77,277 to 208,738 + events, so about 133 million of the allowance remain. +- No physical map, Clifford identity, native or signed application, compiler, + precision, tape or outer predicate is replayed. +- The five framework assumptions and the premises that #7630 inherits from + #7620 remain as the PR states them. 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/pr7630-independent-recount --check-only +python3 scripts/research_package.py --package research/pr7630-independent-recount +``` + +Direct run: + +```sh +python3 -I -B research/pr7630-independent-recount/verify.py +``` + +Environment of the recorded run: CPython 3.13.9, Windows 11, about 2 s, with +the registered argv run directly. 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-17 UTC. + +## Open next questions + +The structured list is in [TASK.json](TASK.json). + +1. Recount the ordinary bill of the #7630 word with the formula the PR names. + Blocker: that formula lives in a repository script that this audit did not + read. +2. Derive the paid and target caller histograms from the #7113 signed caller + definition. Blocker: the reconstruction lives in the dedicated application + stages, which this session did not read. + +## Credit + +The audited construction, word, invoices and claim are by DreamingOfClouds +(#7630, #7623), on the P104 lineage of SYLforge (#7620), Clear1nsight, +Ali Romman, 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/pr7630-independent-recount/SOURCES.json b/research/pr7630-independent-recount/SOURCES.json new file mode 100644 index 0000000000..618f9dcfab --- /dev/null +++ b/research/pr7630-independent-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/pr7630-independent-recount/inputs/pr7630/base-7623-word.json.gz", + "usage": "input", + "git_blob": "d4528141a4f61532b5679075ce1dc7c1e4347025", + "sha256": "97391721ab7d30f8dd84c8d3c29a3c3ed2df2d65ca55e7ff8329bd09877681d2", + "origin": { + "pull_request": 7630, + "commit": "6026e87d1cac03eb5bd2aa8524a8f5891dd9934e", + "path": "research/p104-reroutes-on7623/data/base-7623-word.json.gz" + }, + "pin": "head:a122b07da3f2f77d9cc8c0f1f03311a7274084c6:research/pr7630-independent-recount/inputs/pr7630/base-7623-word.json.gz" + }, + { + "path": "research/pr7630-independent-recount/inputs/pr7630/word-7630.json.gz", + "usage": "input", + "git_blob": "d652af4f8a2ef41d996b59251c036c77fef74aaa", + "sha256": "fa1a8dad12d28e6e5ced5a6989d49074efe15d6647ffc122cb28fcd666f366c2", + "origin": { + "pull_request": 7630, + "commit": "6026e87d1cac03eb5bd2aa8524a8f5891dd9934e", + "path": "research/p104-reroutes-on7623/data/word.json.gz" + }, + "pin": "head:a122b07da3f2f77d9cc8c0f1f03311a7274084c6:research/pr7630-independent-recount/inputs/pr7630/word-7630.json.gz" + }, + { + "path": "research/pr7630-independent-recount/inputs/pr7630/invoice-7623.json", + "usage": "input", + "git_blob": "638ad110b8eac426c9f0e3fa2c46b6ecdc38bc2c", + "sha256": "5be4724fde8264b8b1b4a565ea2eb1a56339f29528db40728b3fab210c44208d", + "origin": { + "pull_request": 7630, + "commit": "6026e87d1cac03eb5bd2aa8524a8f5891dd9934e", + "path": "research/p104-reroutes-on7623/data/invoice-7623.json" + }, + "pin": "head:a122b07da3f2f77d9cc8c0f1f03311a7274084c6:research/pr7630-independent-recount/inputs/pr7630/invoice-7623.json" + }, + { + "path": "research/pr7630-independent-recount/inputs/pr7630/invoice-7630.json", + "usage": "input", + "git_blob": "8b5bd00eaf6e147af61b3088c5a2d6733249b40e", + "sha256": "887128e79be28ded1a8a62fc6311ccaa975e5bcf9b7868dbcc5c8bdceaa6e9d4", + "origin": { + "pull_request": 7630, + "commit": "6026e87d1cac03eb5bd2aa8524a8f5891dd9934e", + "path": "research/p104-reroutes-on7623/data/invoice-new.json" + }, + "pin": "head:a122b07da3f2f77d9cc8c0f1f03311a7274084c6:research/pr7630-independent-recount/inputs/pr7630/invoice-7630.json" + } + ] +} diff --git a/research/pr7630-independent-recount/TASK.json b/research/pr7630-independent-recount/TASK.json new file mode 100644 index 0000000000..304f945167 --- /dev/null +++ b/research/pr7630-independent-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 #7630 head 6026e87d1cac03eb5bd2aa8524a8f5891dd9934e, of (1) the header and initial-chart change from the #7623 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, (4) the helper target ranks of both words and their relation to the declared target invoice, and (5) the signs of the declared complete moment at the claim, at the point above it, and at the #7623 and #7627 values. No constructor, application or pricing engine of the PR is imported.", + "scope_change_reason": "The first experiment of the card is applied to a newer exact head. No audit of #7630 or of its parent #7623 was found among the open PRs on 2026-11-17. #7630 differs from the #7612 recount in two ways. It changes seven stops and re-settles the hub ADD and SCALE events jointly, so the word grows from 77,277 to 208,738 events. It also changes the productive target histogram, so this audit recounts the helper targets as well.", + "bottleneck_link": "The complex supplier binds. #7630 changes paid MOVE ranks and helper target ranks of the P104 word. Its generic replay builds the candidate invoice as the #7623 invoice plus a declared per-call delta. This audit binds both sides of that delta to the emitted word bytes.", + "budget_minutes": 60, + "stop_rule": "Stop after the word-to-invoice binding and the moment signs are resolved or one exact mismatch is found. Do not replay the native, signed, physical, ordinary or outer stages.", + "outcome": "completed", + "evidence": "verify.py passes on CPython 3.13.9 (Windows) in about 2 s: paid = 17 x (MOVE rank histogram of the word) + one fixed caller histogram, equal for #7623 and #7630 and equal to the one of the #7612 recount; targets = 17 x (helper target rank histogram) + one fixed caller target histogram; the native delta {1:-2,2:-3,3:-5,5:+1,6:+2} and the helper delta {6:+2,9:-2} are recounted from the words; both words have a legal chart chronology; seven moment signs agree with the PR; the change is no worse for every tent tariff min(r,a); and ten controls reject.", + "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": "Recount the ordinary bill of the #7630 word. The PR states 786,433,632 for #7623 and 867,014,040 for #7630, below 10^9, with ADD events 66,930 to 197,626 and non-dyadic literal events 5,903 to 12,312.", + "why_it_matters": "The hub re-settle triples the word length. The moment is unchanged by ADD events, but the ordinary allowance and the 5-smooth coefficient grid are not. About 133 million of the allowance remain.", + "first_step": "Count the route, ADD, SCALE and odd-division items of the word with the formula the PR names, and compare with the stated total.", + "blocked_by": "The formula lives in a repository script that this audit did not read." + }, + { + "question": "Derive the word-independent caller histograms (paid and target) from the #7113 signed caller definition, without the invoice files.", + "why_it_matters": "Both histograms are measured here, and the paid one equals the #7612 recount. A derivation would give the complete invoice of each P104 successor from the word bytes alone.", + "first_step": "Count the QUERY and IDLE charges by rank in the retained #7605 signed application and compare.", + "blocked_by": "The caller reconstruction lives in the dedicated application stages, which this session did not read." + } + ] +} diff --git a/research/pr7630-independent-recount/VERIFY.json b/research/pr7630-independent-recount/VERIFY.json new file mode 100644 index 0000000000..44192930f7 --- /dev/null +++ b/research/pr7630-independent-recount/VERIFY.json @@ -0,0 +1,26 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/pr7630-independent-recount/inputs/pr7630/base-7623-word.json.gz", + "research/pr7630-independent-recount/inputs/pr7630/word-7630.json.gz", + "research/pr7630-independent-recount/inputs/pr7630/invoice-7623.json", + "research/pr7630-independent-recount/inputs/pr7630/invoice-7630.json" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "-W", + "error", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Input pins; complete chart chronology of both words; GF(2) MOVE rank recount and 17-call paid split; helper target recount and 17-call target split; seven moment signs, strict monotonicity and a tent-tariff test with an independent 256-bit interval engine; ten rejecting controls." + } + ] +} diff --git a/research/pr7630-independent-recount/inputs/pr7630/base-7623-word.json.gz b/research/pr7630-independent-recount/inputs/pr7630/base-7623-word.json.gz new file mode 100644 index 0000000000..d4528141a4 Binary files /dev/null and b/research/pr7630-independent-recount/inputs/pr7630/base-7623-word.json.gz differ diff --git a/research/pr7630-independent-recount/inputs/pr7630/invoice-7623.json b/research/pr7630-independent-recount/inputs/pr7630/invoice-7623.json new file mode 100644 index 0000000000..638ad110b8 --- /dev/null +++ b/research/pr7630-independent-recount/inputs/pr7630/invoice-7623.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": 68129, "2": 15946, "3": 11033, "4": 4964, "5": 6001, "6": 391, "7": 187, "8": 758, "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/pr7630-independent-recount/inputs/pr7630/invoice-7630.json b/research/pr7630-independent-recount/inputs/pr7630/invoice-7630.json new file mode 100644 index 0000000000..8b5bd00eaf --- /dev/null +++ b/research/pr7630-independent-recount/inputs/pr7630/invoice-7630.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": 68095, "2": 15895, "3": 10948, "4": 4964, "5": 6018, "6": 425, "7": 187, "8": 758, "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": 765, "7": 323, "8": 544, "9": 10854, "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/pr7630-independent-recount/inputs/pr7630/word-7630.json.gz b/research/pr7630-independent-recount/inputs/pr7630/word-7630.json.gz new file mode 100644 index 0000000000..d652af4f8a Binary files /dev/null and b/research/pr7630-independent-recount/inputs/pr7630/word-7630.json.gz differ diff --git a/research/pr7630-independent-recount/verify.py b/research/pr7630-independent-recount/verify.py new file mode 100644 index 0000000000..341ccd43e5 --- /dev/null +++ b/research/pr7630-independent-recount/verify.py @@ -0,0 +1,471 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Independent recount of the PR #7630 word, paid and target invoices. + +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 sys +from fractions import Fraction as Q +from pathlib import Path + +HERE = Path(__file__).absolute().parent +INPUTS = HERE / 'inputs' / 'pr7630' +PR_HEAD = '6026e87d1cac03eb5bd2aa8524a8f5891dd9934e' +# SHA256 of the vendored bytes. They must equal the PR head blobs. +PINS = { + 'base-7623-word.json.gz': + '97391721ab7d30f8dd84c8d3c29a3c3ed2df2d65ca55e7ff8329bd09877681d2', + 'word-7630.json.gz': + 'fa1a8dad12d28e6e5ced5a6989d49074efe15d6647ffc122cb28fcd666f366c2', + 'invoice-7623.json': + '5be4724fde8264b8b1b4a565ea2eb1a56339f29528db40728b3fab210c44208d', + 'invoice-7630.json': + '887128e79be28ded1a8a62fc6311ccaa975e5bcf9b7868dbcc5c8bdceaa6e9d4', +} +CALLS = 17 +CLAIM = Q('0.0036667343458') +ABOVE = Q('0.0036667343459') +KAPPA_7623 = Q('0.0036624027915') +KAPPA_7623_UP = Q('0.0036624027916') +KAPPA_7627 = Q('0.003665731276') +BIT_CAP = Q('0.00376669') +# Native MOVE rank change per call that the PR reports. This audit measures it. +NATIVE_DELTA = {1: -2, 2: -3, 3: -5, 5: 1, 6: 2} +HELPER_DELTA = {6: 2, 9: -2} +REBIRTH = {457: (3, 281), 461: (3, 285)} +RANK_SURPLUS = 1424 + + +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)} + + +# ------------------------------------------- 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 + + + + +# ------------------------------------------------------------- recounts + +def diff(a, b): + d = collections.Counter(b) + d.subtract(a) + return {k: v for k, v in sorted(d.items()) if v} + + +def mains(word): + """Main fields as the PR defines them. Other public fields are helpers.""" + live = set(word['live']) + hosted = word['hosted'] + shifted = {r + 112 for r in live} + return live | shifted | set(hosted['X2']) | set(hosted['Y2']) + + +def helper_targets(word): + """Per call: rank(final frame) - rank(initial frame), for each helper.""" + ranks = [gf2_rank(f) for f in word['frames']] + main = mains(word) + out = collections.Counter() + for r in range(word['public']): + if r not in main: + d = ranks[word['final'][r]] - ranks[word['initial'][r]] + require(d > 0, 'helper %d has no productive rank' % r) + out[d] += 1 + return out + + +def target_rest(helpers, invoice): + """Targets left after the helpers of all calls. Word-independent.""" + rest = collections.Counter( + {int(r): n for r, n in invoice['targets'].items()}) + for r, n in helpers.items(): + rest[r] -= CALLS * n + require(all(n >= 0 for n in rest.values()), 'targets are below the count') + return {r: n for r, n in sorted(rest.items()) if n} + + +def uniform_gain(old_s, new_s): + """Smallest and largest gain over the tents min(r, a), a = 1 .. max rank.""" + d = collections.Counter(new_s) + d.subtract(old_s) + top = max(max(old_s), max(new_s)) + gains = [sum(s * min(r, a) for r, s in d.items()) + for a in range(1, top + 1)] + return min(gains), max(gains) + + +def check_moments(old_inv, new_inv): + for inv in (old_inv, new_inv): + model = inv['contract']['model'] + require(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))) + for profile in (old, new): + lo, hi = moment_bounds(profile, Q(0), logs) + exact = sum(r * s for r, s in profile.items()) + tight = hi - lo < Q(1, 1 << 200) + require(lo <= exact <= hi and tight, 'engine self-test') + require(exact == RANK_SURPLUS, 'rank surplus') + wanted = [('#7630 at claim', new, CLAIM, 1), + ('#7630 above claim', new, ABOVE, -1), + ('#7630 at #7627 value', new, KAPPA_7627, 1), + ('#7630 at #7623 value', new, KAPPA_7623, 1), + ('#7623 at its own value', old, KAPPA_7623, 1), + ('#7623 above its value', old, KAPPA_7623_UP, -1), + ('#7623 at #7630 claim', old, CLAIM, -1)] + for label, profile, kappa, sign in wanted: + require(sign_at(profile, kappa, logs) == sign, label + ': sign') + require(KAPPA_7623 < KAPPA_7623_UP < KAPPA_7627 < CLAIM < ABOVE < 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') + low, high = uniform_gain(old, new) + require(low >= 0 and high > 0, 'not better for every tent tariff') + return {'points': [label for label, _, _, _ in wanted], + 'derivative_upper_7623': float(slopes[0]), + 'derivative_upper_7630': float(slopes[1]), + 'tent_gain_min_max': [low, high], + '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) + + h_old, h_new = move_histogram(old), move_histogram(new) + k_old, k_new = caller_part(h_old, old_inv), caller_part(h_new, new_inv) + t_new = target_rest(helper_targets(new), new_inv) + # 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) != k_new) + # 2. One more paid unit in the invoice. + bad = copy.deepcopy(new_inv) + bad['paid']['1'] += 1 + control('invoice paid unit', caller_part(h_new, bad) != k_new) + # 3. The new invoice with the old word. + control('old word with new invoice', + rejects(caller_part, h_old, new_inv) + or caller_part(h_old, new_inv) != k_old) + # 4. The helper targets of the old word with the new invoice. + control('old helper targets with new invoice', + rejects(target_rest, helper_targets(old), new_inv) + or target_rest(helper_targets(old), new_inv) != t_new) + # 5. One rebirth is not applied. + bad = copy.deepcopy(new) + bad['initial'][457] = 3 + control('rebirth of 457 undone', rejects(chronology, bad)) + # 6. An ADD at the wrong chart. + index = next(i for i, e in enumerate(new['program']) if e[0] == 'ADD') + bad = copy.deepcopy(new) + bad['program'][index][4] += 1 + control('ADD at the wrong chart', rejects(chronology, bad)) + # 7. A MOVE that lands on another chart. + index = next(i for i, e in enumerate(new['program']) if e[0] == 'MOVE') + bad = copy.deepcopy(new) + event = bad['program'][index] + event[3] = (event[3] + 1) % len(bad['frames']) + control('MOVE to another chart', rejects(chronology, bad)) + # 8. A frame vector change breaks nestedness or the paid count. + move = next(e for e in new['program'] if e[0] == 'MOVE') + bad = copy.deepcopy(new) + bad['frames'][move[3]] = bad['frames'][move[3]] + [1 << 20] + control('changed frame', + rejects(move_histogram, bad) + or caller_part(move_histogram(bad), new_inv) != k_new) + # 9. The #7623 invoice does not support the #7630 claim. + control('#7623 invoice at claim', + sign_at(signed_profile(old_inv), CLAIM, logs) == -1) + # 10. A point above the stated bracket is not positive. + higher = ABOVE + Q(1, 10 ** 12) + control('#7630 above bracket', + sign_at(signed_profile(new_inv), higher, logs) == -1) + return seen + + +# ---------------------------------------------------------------------- main + +def audit(raw): + for name, pin in PINS.items(): + require(sha(raw[name]) == pin, 'input pin ' + name) + old = load_word(raw['base-7623-word.json.gz']) + new = load_word(raw['word-7630.json.gz']) + old_inv = json.loads(raw['invoice-7623.json']) + new_inv = json.loads(raw['invoice-7630.json']) + + same = [k for k in old if k not in ('program', 'initial')] + require(old.keys() == new.keys() and all(old[k] == new[k] for k in same), + 'word headers differ beyond initial charts') + changed = {r: (a, b) for r, (a, b) in + enumerate(zip(old['initial'], new['initial'])) if a != b} + require(changed == {r: v for r, v in REBIRTH.items()}, 'initial charts') + report = {'rebirths': {str(r): list(v) for r, v in changed.items()}} + report['chronology'] = {'7623': chronology(old), '7630': chronology(new)} + + h_old, h_new = move_histogram(old), move_histogram(new) + delta = diff(h_old, h_new) + require(delta == NATIVE_DELTA, 'native MOVE rank delta') + require((sum(h_old.values()), sum(h_new.values())) == (6257, 6250), + 'native MOVE count') + k_old, k_new = caller_part(h_old, old_inv), caller_part(h_new, new_inv) + require(k_old == k_new, 'caller part of the paid profile changed') + ht_old, ht_new = helper_targets(old), helper_targets(new) + hdelta = diff(ht_old, ht_new) + require(hdelta == HELPER_DELTA, 'helper target delta') + tk_old, tk_new = target_rest(ht_old, old_inv), target_rest(ht_new, new_inv) + require(tk_old == tk_new, 'caller part of the target profile changed') + paid = [sum(x['paid'].values()) for x in (old_inv, new_inv)] + targets = [sum(x['targets'].values()) for x in (old_inv, new_inv)] + require(paid == [110145, 110026] and targets[0] == targets[1], + 'invoice position counts') + report['recount'] = { + 'law': 'rank(a->b) = dim(A+B) - dim(A meet B) over GF(2); all nested', + 'moves_7623': dict(sorted(h_old.items())), + 'moves_7630': dict(sorted(h_new.items())), + 'native_delta_per_call': delta, 'helper_delta_per_call': hdelta, + 'calls': CALLS, 'caller_paid_part': k_new, + 'caller_target_part': tk_new, 'paid_positions': paid, + 'target_positions': targets} + report['moments'], logs = check_moments(old_inv, new_inv) + report['controls'] = controls(old, new, old_inv, new_inv, logs) + return report + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.parse_args() + raw = {name: (INPUTS / name).read_bytes() for name in PINS} + report = audit(raw) + report['status'] = 'PASS_INDEPENDENT_RECOUNT_PR7630_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)