diff --git a/research/qq16-noise-lattice-audit/README.md b/research/qq16-noise-lattice-audit/README.md new file mode 100644 index 0000000000..e8e6dae3fe --- /dev/null +++ b/research/qq16-noise-lattice-audit/README.md @@ -0,0 +1,172 @@ +# QQ16: input grids do not certify child-error grids + +**Scoped audit and a corrected lattice criterion.** PR3181's ideal scalar +projection has denominator guards 4 for F0 and 17 for B1,2. Those facts do not +imply that scalar operations stay exact after approximate native children. +This package adds the missing independent child-error columns. In the same +projection, their sharp uniform guards are **4 and 18**, respectively. +Twelve B1,2 child sites require the eighteenth position. + +There is also a smaller obstruction that does not discard any intervening +native operation: two adjacent instructions in each actual serialized program +are a child followed by a half-ADD. An on-grid child error can make the ADD's +exact result leave that grid. This refutes the grid-closure implication under +an error-only child contract. It does **not** exhibit a failure of a particular +rounding algorithm, disprove the final `50+beta` accuracy bound by every possible +method, or refute the selected construction. + +## Exact sources and predecessor credit + +Base main: `997e6a9ca7b4f95d50e366f61412fd640d72a88a` (priority revision 6). +The sole live scientific input is the unchanged +[`joint-query/certificate.json.gz`](../joint-query/certificate.json.gz), +SHA256 `a5ed85fac5ebf3c091482a113ab0d351eb5a7892fe2841a35e16017ec1ff49f7`; +the decompressed payload is also authenticated. SOURCES.json records its Git +blob and the task/selected-record provenance. + +The audited claim is dcharb78's [PR3181](https://github.com/CrocSwap/integer-mult-bounds/pull/3181) +at `80fc72d14546088e9fce3c06dc12bc67270da0af`, specifically +[README, Common-Grid Exactness and the 50+beta inference](https://github.com/CrocSwap/integer-mult-bounds/blob/80fc72d14546088e9fce3c06dc12bc67270da0af/research/qq16-interior-dynamic-range-and-adjoint-ledger/README.md) +and [verify.py](https://github.com/CrocSwap/integer-mult-bounds/blob/80fc72d14546088e9fce3c06dc12bc67270da0af/research/qq16-interior-dynamic-range-and-adjoint-ledger/verify.py) +(lines 159–162, 204–225 and 747–775). The checker initializes each input column +at the coarse scale but does not inject child defects into that divisibility +replay. Its later precision calculation combines `eps_gate=0` with nonzero child +errors. PR3181 does name child-interior execution as an open question; our +finding specifies an additional **caller-side** closure requirement even when +every child returns on the working grid. + +Credit dcharb78 for the ideal-column and adjoint analyses; the joint-query/native +word authors for the preserved certificate; Nick Petalas / PR2965 for completed +producer-defect transfer; Arham Tahir / PR2995 and Tekalign / PR3017 for the earlier +scalar/native dirty-helper fault distinction; and Arham Tahir / PR3036 for +concrete scalar-rounding analysis. Their original proofs and notices remain +unchanged. This is a new audit of child-error lattice closure, not another claim +to the ideal magnitude or terminal sensitivity results. + +## A two-instruction countermodel + +All event indices are zero-based in the fully expanded, unfiltered programs. +OS seed **61** selects site 61 from each ordered list of adjacent half-scalar +consumers (185 in F0; 122 in B1,2): + +| Program | Child event | Immediately following scalar | +|---|---:|---| +| F0 | 14914, child on L67 | 14915: `L117 -= L67/2`, frame 627 | +| B1,2 | 15338, child on L216 | 15339: `L688 -= L216/2`, frame 423 | + +Let the storage grid be `q Z`, `q=2^(-p)`. A source equal to `2M q`, with target +zero, produces the on-grid exact ADD output `-M q`. A child defect `q` changes +the source to `(2M+1)q`, still on the grid, but the exact ADD output becomes +`-(M+1/2)q`. Every rounding to `q Z` introduces error at least `q/2`. +Taking `M=2^p` keeps the ideal source magnitude at two while the defect tends +to zero as p grows. Thus this is not limited to large relative errors on tiny +inputs. Magnitude-only child error contracts do not exclude the odd residue. + +This is a local contract countermodel at the actual adjacent instruction bytes, +not a completed native input-to-output counterexample. We do not assert that a +specific implemented child returns that residue, or that these local values +have been lifted through an imposed coarse-entry-grid contract. Such an +implementation or reachability restriction would be an additional hypothesis. +One extra fractional position repairs these **local** examples; it is not a +sufficient guard for the entire program. + +## The corrected criterion + +For a rational linear trace, write the state after completed operation t as + +``` +x_t = P_t x_0 + sum_j R_(t,j) zeta_j. +``` + +Here `zeta_j` is an additive defect after child j. For independent inputs on +`h_in Z` and independent defects on `h_j Z`, every state lies on `q Z` if and +only if **every entry** of `h_in P_t/q` and `h_j R_(t,j)/q` is integral, at +**every** cut t. Sufficiency follows by integer linear combination. Necessity +follows by setting one input or one defect to its lattice unit and all others +to zero. This is an exact algebraic statement, not a finite-search inference. +Independence is needed for the necessity direction; correlated errors may +satisfy weaker requirements. + +When all h's equal one dyadic quantum h and coefficients are dyadic, the sharp +uniform guard g for working quantum `q=h/2^g` is the largest reduced denominator +exponent of these matrices. Checking only P misses R. The maximum must be taken +at intermediate cuts, even if later arithmetic cancels a denominator. + +The primary verifier propagates all 712 input columns and one new symbol per +child. It records each column's maximum denominator and an attaining cut; +RESULT.json contains the complete guard histograms, witness bytes and a digest +of the full column-attainment table. Replay reconstructs that table. + +| Projection | Events | Scalar cuts | Child-error columns | Input guard | Child-error guard | +|---|---:|---:|---:|---:|---:| +| F0 | 26,099 | 21,025 | 3,494 | 4 | 4 | +| B1,2 | 27,019 | 21,401 | 3,510 | 17 | **18** | + +A unit defect after F0 child 12607 on L416 has coefficient `7/16` in L431 after +scalar 21975. A unit defect after B1,2 child 13489 on L344 has coefficient +**`-81921/262144`** in L93 after scalar 26472. The latter numerator is odd: +17 guard positions leave a half-integer, while 18 suffice for every error +column in this projection. Merely choosing a finer common storage grid and +allowing child errors at its own least significant bit repeats the problem. + +A conditional repair is to distinguish the entry/error quantum from the finer +working quantum, or to prove the necessary correlated/divisibility conditions +on child defects. The theorem is about **defects relative to the ideal trace**; +rounding returned values to a coarse grid does not automatically put their +defects on that grid. This package does not supply such a recursive child. + +## Scope that remains material + +For the global guard census we use exactly PR3181's scalar projection: +`climb`, `native_line`, adapters, residual adapters, phases and cover maps act +as identities; CLEAR resets its destination. The receipt counts those ignored +operations explicitly. The 4/18 result is sharp **in that projection**. It is +not a physical all-depth guard, an implementation of the child interiors, or a +certificate for all 37 QQ16 cases. Only F0 and B1,2 are covered. + +The adjacent half-ADD countermodels need no such identity replacement between +the child and its consumer. Their scope is still a local input/error contract. +No terminal accuracy failure, rounded execution, all-size theorem, full native +adjoint bound, dirty-stock magnitude bound, overflow guarantee or physical +consumer invoice is claimed. In particular, simply adding 18 to `50+beta` would +not produce an admitted width theorem. The selected Îș and all supplier costs +are unchanged. The family decision is to narrow precision work to its actual +child-return/receiver contract before reusing an exact-gate budget. + +## Reproduce + +From a checkout with the declared input materialized, using Python 3.12: + +```sh +uv run --python 3.12 --no-project python -B scripts/research_package.py \ + --package research/qq16-noise-lattice-audit +``` + +Expected: `PASS_QQ16_NOISE_LATTICE_AUDIT` with input guards 4,17 and child guards +4,18; `PASS_QQ16_NOISE_INDEPENDENT witnesses=6`; eleven passing behavioral tests; +and the registered replay's PASS. Default replay is read-only. For a Git-free +export, run the three Python files directly with the input at its declared path. + +`independent.py` imports no primary or predecessor implementation. It uses dense +single-channel forward replay and a separate reverse dual to check the four +attaining coefficients, their whole-channel denominators, and both local +witnesses. The primary upper bound covers all columns; the independent check +is not a second complete 7,004-column census. Negative controls include a +changed numerator, insufficient guard, swapped child wire, corrupted source, +unknown events, non-dyadic coefficients, endpoint cancellation and a later CLEAR +that must not erase an earlier precision obligation. All checks survive `-O`. + +## Open next questions + +- Can actual child outputs satisfy a sufficient defect lattice or correlated + error invariant? Begin with the two literal child/half-ADD interfaces above; + an on-grid output and a norm bound alone do not suffice. +- Can the 18-bit projected witness be lifted through the actual changing charts + and residual adapters? First propagate its single error direction using the + native recipes, without treating non-scalar operators as identities. +- Can a completed rounded-gate analysis establish `50+beta` or another useful + width without assuming zero scalar error? It needs actual dirty-input bounds, + noise-aware intermediate magnitudes, child error contracts and a paid caller. + +Prepared by Tekalign (`tekuuu`) with substantial OpenAI Codex assistance in +analysis, implementation, checking and writing. Apache-2.0. diff --git a/research/qq16-noise-lattice-audit/RESULT.json b/research/qq16-noise-lattice-audit/RESULT.json new file mode 100644 index 0000000000..9ee8bbd1eb --- /dev/null +++ b/research/qq16-noise-lattice-audit/RESULT.json @@ -0,0 +1,200 @@ +{ + "assignment_seed": 61, + "cases": { + "B_1_2": { + "all_column_attainments_sha256": "d53cc0114361cd550cc38393a0a1cab8d67deeef3d3eb210b4208a6f2f99b292", + "child_attainment": { + "attainment": { + "bits": 18, + "coefficient": "-81921/262144", + "event": 26472, + "wire": 93 + }, + "origin": { + "event": 13489, + "kind": "climb", + "wire": 344 + } + }, + "child_defect_columns": 3510, + "child_guard_bits": 18, + "child_guard_histogram": { + "0": 118, + "1": 403, + "10": 41, + "11": 33, + "12": 10, + "13": 14, + "14": 18, + "15": 97, + "16": 91, + "17": 28, + "18": 12, + "2": 704, + "3": 645, + "4": 359, + "5": 413, + "6": 401, + "7": 58, + "8": 22, + "9": 43 + }, + "direct_adjacent_sites": 122, + "event_count": 27019, + "event_counts": { + "adapter": 1090, + "climb": 3486, + "cover_map": 528, + "native_line": 24, + "phase": 10, + "residual_adapter": 480, + "scalar": 21401 + }, + "input_attainment": { + "attainment": { + "bits": 17, + "coefficient": "-49151/131072", + "event": 26472, + "wire": 93 + }, + "origin": { + "event": -1, + "kind": "input", + "wire": 28 + } + }, + "input_columns": 712, + "input_guard_bits": 17, + "scalar_cuts": 21401, + "seed_selected_local_witness": { + "actual_output_units": "-3/2", + "actual_source_units": 3, + "child": [ + "climb", + "B", + 216, + 0, + 423, + 1 + ], + "child_defect_units": 1, + "child_event": 15338, + "coefficient": "-1/2", + "ideal_output_units": "-1", + "ideal_source_units": 2, + "scalar": [ + "scalar", + [ + "add", + [ + "L", + 688 + ], + [ + "L", + 216 + ], + -1, + 2 + ], + 423 + ], + "scalar_event": 15339, + "selection": "61 modulo 122", + "working_grid": "q = 2^(-p), any integer p >= 0" + } + }, + "F_0": { + "all_column_attainments_sha256": "21e6c0c3edaf2c4621766c110cee1c222999bb8d0ca1e88a290eb1d0682a084a", + "child_attainment": { + "attainment": { + "bits": 4, + "coefficient": "7/16", + "event": 21975, + "wire": 431 + }, + "origin": { + "event": 12607, + "kind": "climb", + "wire": 416 + } + }, + "child_defect_columns": 3494, + "child_guard_bits": 4, + "child_guard_histogram": { + "0": 427, + "1": 1541, + "2": 1323, + "3": 187, + "4": 16 + }, + "direct_adjacent_sites": 185, + "event_count": 26099, + "event_counts": { + "adapter": 1090, + "climb": 3486, + "native_line": 8, + "phase": 10, + "residual_adapter": 480, + "scalar": 21025 + }, + "input_attainment": { + "attainment": { + "bits": 4, + "coefficient": "7/16", + "event": 21975, + "wire": 431 + }, + "origin": { + "event": -1, + "kind": "input", + "wire": 13 + } + }, + "input_columns": 712, + "input_guard_bits": 4, + "scalar_cuts": 21025, + "seed_selected_local_witness": { + "actual_output_units": "-3/2", + "actual_source_units": 3, + "child": [ + "climb", + "B", + 67, + 571, + 627, + 1 + ], + "child_defect_units": 1, + "child_event": 14914, + "coefficient": "-1/2", + "ideal_output_units": "-1", + "ideal_source_units": 2, + "scalar": [ + "scalar", + [ + "add", + [ + "L", + 117 + ], + [ + "L", + 67 + ], + -1, + 2 + ], + 627 + ], + "scalar_event": 14915, + "selection": "61 modulo 185", + "working_grid": "q = 2^(-p), any integer p >= 0" + } + } + }, + "no_new_kappa": true, + "schema_version": 1, + "scope": "All completed scalar cuts of two identity-nonscalar projections; independent additive child defects. Direct adjacent witnesses retain actual instruction bytes.", + "source_payload_sha256": "2efe83c59978aa9c0db2c3e4eccc14cbfdcd3c9ce499432601b5dd34083472ef" +} diff --git a/research/qq16-noise-lattice-audit/SOURCES.json b/research/qq16-noise-lattice-audit/SOURCES.json new file mode 100644 index 0000000000..8b881739ce --- /dev/null +++ b/research/qq16-noise-lattice-audit/SOURCES.json @@ -0,0 +1,24 @@ +{ + "schema_version": 1, + "base_commit": "997e6a9ca7b4f95d50e366f61412fd640d72a88a", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "b1fea0c94436b236cc2b7d41a7be032811b94c81", + "sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "67f085acd86acd7d4e03922d9cf4b26bca66fed5", + "sha256": "47b42433f5a85809a3aadd29c2c339da2c6ed728e4f7762df6b88bccb7874cf0" + }, + { + "path": "research/joint-query/certificate.json.gz", + "usage": "input", + "git_blob": "c6e876d8b48d768214deee265ade428f8983b566", + "sha256": "a5ed85fac5ebf3c091482a113ab0d351eb5a7892fe2841a35e16017ec1ff49f7" + } + ] +} diff --git a/research/qq16-noise-lattice-audit/TASK.json b/research/qq16-noise-lattice-audit/TASK.json new file mode 100644 index 0000000000..7362555fb9 --- /dev/null +++ b/research/qq16-noise-lattice-audit/TASK.json @@ -0,0 +1,111 @@ +{ + "schema_version": 1, + "task_id": "joint-query-controller", + "priority_revision": 6, + "base_commit": "997e6a9ca7b4f95d50e366f61412fd640d72a88a", + "original_card": { + "id": "joint-query-controller", + "question": "Can a literal QQ16 producer meet the proposed completed-output error budgets with dirty helpers and an affordable physical consumer?", + "starting_points": [ + "docs/research/research-family-status.md", + "research/joint-query/README.md", + "research/joint-query/evidence/QQ16-SELECTED-WITNESS.md", + "research/joint-query/evidence/JOINT-QUERY-TRANSFER.md", + "docs/research/community-efficient1000-review.md", + "research/qq16-producer-defect-transfer/README.md" + ], + "methods": [ + "Derive one literal producer's completed-output defects and intermediate dirty-helper bounds, with its physical bill.", + "Design or audit one consumer, retention or hosting boundary and its complete cost for the pinned producer/decoder." + ], + "acceptance_gate": "Name the changed premise of the fixed F0/B1 observation obstruction. Show exactly which query is recovered, legal native reads and restoration, and a full favorable budget including cover maps, helpers and endpoints. Local inverse identities alone do not close the global controller. 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 #2965 producer-defect transfer after the local QQ16 decoder contract. Its author-checked output-error estimate does not implement producer interiors, bound dirty helpers, or pay for the consumer; independently check the implication used.", + "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": "Pin one literal F0/B1 producer and its native-child contracts; derive the actual intermediate magnitude ledger and completed-output defects, including dirty helpers and correlations. Compare with #2965 budgets and price storage, movement, cleanup and F17 consumption. Stop with a precise missing bound if no producer contract supplies it; do not optimize another decoder precision constant in isolation.", + "bottleneck_link": "The native local words exist; retained query information and its physical access are the missing link to a composed recursive interface.", + "allowed_variations": [ + "One paid query, one changed first pair, or one precisely specified affine helper state.", + "A counterexample or lower bound for that exact proposed repair.", + "One unresolved obligation of a newer local decoder, with exact source heads and a distinct claim/domain." + ], + "scope_change_triggers": [ + "Retaining the fixed first pair and ordinary schedule while allowing only homogeneous selected-only control, already excluded by the witness.", + "Treating cover-map counts as zero-cost physical address operations.", + "Recreating the pending complete local decoder or early-record/output-bank coalescing already under investigation without a distinct audit or changed premise.", + "Treating a completed-output defect inequality as a producer-interior, dirty-range or physical-cost certificate." + ], + "overlap_terms": [ + "QQ16", + "joint-query", + "changing-chart controller", + "selected observation", + "1969", + "2540", + "early record", + "output-bank retention", + "complete native decoder", + "2965", + "producer defect", + "dirty-helper range", + "F17 consumer" + ] + }, + "scope_status": "refined", + "actual_scope": "Audit the approximate-child to exact-scalar grid implication in PR3181; give adjacent contract countermodels and a sharp independent-defect guard census for F0 and B1,2 scalar projections.", + "scope_change_reason": "The producer-defect card now has a pending precision proposal. Test its child-return lattice implication rather than repeat completed decoder bounds or ideal norms.", + "bottleneck_link": "An exact-gate producer budget is not usable without proving closure after approximate recursive children.", + "budget_minutes": 60, + "stop_rule": "Stop after two named projections and adjacent local witnesses; reserve final quarter for independent replay, mutation controls, source/head refresh and handoff. Do not infer a full physical guard or final accuracy failure.", + "outcome": "negative-result", + "evidence": "RESULT.json; verify.py complete 7004-child-column census; independent.py dense-channel/reverse-dual checks; test_verify.py", + "author": "Tekalign (tekuuu), with substantial OpenAI Codex assistance", + "ai_assistance": "Substantial OpenAI Codex assistance in mathematical analysis, implementation, verification and writing.", + "open_questions": [ + { + "question": "Can actual child errors satisfy a receiver-compatible lattice or correlated residue invariant?", + "why_it_matters": "Needed before setting scalar error to zero in a recursive precision budget.", + "first_step": "Analyze the child/half-ADD interfaces at F0 events 14914/14915 and B1,2 events 15338/15339.", + "blocked_by": "A specified physical child-return/rounding implementation." + }, + { + "question": "Does the projected 18-bit child witness lift through actual native maps?", + "why_it_matters": "Projection guard minima are not full native precision bounds.", + "first_step": "Propagate the L344 defect after B1,2 event 13489 through actual recipes to event 26472.", + "blocked_by": "Changing-chart and residual-adapter execution for that error direction." + } + ], + "assignment_seed": 61, + "assignment_track": "adversarial mathematical audit", + "candidates_considered": [ + "PR3181 child-error/common-grid closure (chosen; new uncertainty between ideal and noisy execution).", + "PR3182 pooled P104 cycle and one-hop claims (recent broad treatment already exists).", + "PR3159 in-place Gaussian SCALE bank/word-width contract (extensive new truth-column replay; less direct connection to producer error transfer)." + ], + "audited_claim": { + "pr": 3181, + "head": "80fc72d14546088e9fce3c06dc12bc67270da0af", + "status": "open proposal; not selected supplier", + "files": { + "research/qq16-interior-dynamic-range-and-adjoint-ledger/README.md": { + "sha256": "2d2284bcb33cc437a9d3e03eaf93ca1ebfef4ced52fdb5d727a79970eab3b61b", + "usage": "external audited claim, not runtime input" + }, + "research/qq16-interior-dynamic-range-and-adjoint-ledger/verify.py": { + "sha256": "40238fe46cb6d416f0a277a3d0e531b79222f207f6904d6e3586f590ec1d1b27", + "usage": "external audited claim, not runtime input" + }, + "research/qq16-interior-dynamic-range-and-adjoint-ledger/RESULT.json": { + "sha256": "f24537e48fead1189555d1e9cdbf881aa1c0022c4ed0c033baaf1cf9c131dc29", + "usage": "external audited claim, not runtime input" + } + } + } +} diff --git a/research/qq16-noise-lattice-audit/VERIFY.json b/research/qq16-noise-lattice-audit/VERIFY.json new file mode 100644 index 0000000000..a4098e49e9 --- /dev/null +++ b/research/qq16-noise-lattice-audit/VERIFY.json @@ -0,0 +1,46 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/joint-query/certificate.json.gz" + ], + "commands": [ + { + "argv": [ + "{python}", + "-Werror", + "-I", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Authenticate source; regenerate all input/child-error column guards and compare the receipt." + }, + { + "argv": [ + "{python}", + "-Werror", + "-I", + "-O", + "-B", + "{package}/independent.py" + ], + "timeout_seconds": 120, + "checks": "Separate dense single-channel and reverse-dual attainments, lower guards and literal adjacent local countermodels." + }, + { + "argv": [ + "{python}", + "-Werror", + "-I", + "-O", + "-B", + "{package}/test_verify.py" + ], + "timeout_seconds": 120, + "checks": "Eleven numerical, source, witness and unsupported-operation failure controls." + } + ] +} diff --git a/research/qq16-noise-lattice-audit/independent.py b/research/qq16-noise-lattice-audit/independent.py new file mode 100644 index 0000000000..7b828d2dbd --- /dev/null +++ b/research/qq16-noise-lattice-audit/independent.py @@ -0,0 +1,132 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Separate dense single-channel and reverse-dual checks; no primary imports.""" +import gzip +import hashlib +import json +from fractions import Fraction +from pathlib import Path + +BASE = Path(__file__).resolve().parent +CERT = BASE.parents[1] / 'research/joint-query/certificate.json.gz' +CERT_HASH = 'a5ed85fac5ebf3c091482a113ab0d351eb5a7892fe2841a35e16017ec1ff49f7' + + +def check(ok, message): + if not ok: + raise ValueError(message) + + +def wire(token): + return token[1] if token[0] == 'L' else 704 + token[1] + + +def sequence(packet, name): + for item in packet['programs'][name]: + if item[0] == 'retained_core': + yield from packet['core_words'][item[1]] + elif item[0] in ['cover_sweep', 'private_sweep']: + yield from item[2] + else: + yield item + + +def forward_channel(events, origin): + values = [Fraction(0) for _ in range(712)] + if origin['event'] == -1: + values[origin['wire']] = Fraction(1) + peak = 0 + snapshots = {} + for t, event in enumerate(events): + if event[0] == 'scalar': + g = event[1] + d = wire(g[1]) + if g[0] == 'clear': + values[d] = Fraction(0) + elif g[0] == 'scale': + values[d] *= Fraction(g[2], g[3]) + elif g[0] == 'add': + values[d] += values[wire(g[2])] * Fraction(g[3], g[4]) + else: + raise ValueError('unknown operation') + peak = max(peak, values[d].denominator.bit_length() - 1) + snapshots[(t, d)] = values[d] + if t == origin['event']: + values[origin['wire']] += 1 + return peak, snapshots + + +def reverse_coefficient(events, origin, attainment): + dual = [Fraction(0) for _ in range(712)] + dual[attainment['wire']] = Fraction(1) + for t in range(attainment['event'], origin['event'], -1): + e = events[t] + if e[0] != 'scalar': + continue + g = e[1] + d = wire(g[1]) + if g[0] == 'clear': + dual[d] = Fraction(0) + elif g[0] == 'scale': + dual[d] *= Fraction(g[2], g[3]) + elif g[0] == 'add': + dual[wire(g[2])] += dual[d] * Fraction(g[3], g[4]) + return dual[origin['wire']] + + +def verify(report, packet): + checked = 0 + for name, record in report['cases'].items(): + events = list(sequence(packet, name)) + check(len(events) == record['event_count'], 'event count') + for key in ('input_attainment', 'child_attainment'): + witness = record[key] + origin, endpoint = witness['origin'], witness['attainment'] + if origin['event'] >= 0: + child = events[origin['event']] + check(child[0] in ('climb', 'native_line'), 'fault is not at a child') + target = child[2] if child[0] == 'climb' else wire(child[1]) + check(target == origin['wire'], 'fault is not on child wire') + at = events[endpoint['event']] + check(at[0] == 'scalar' and wire(at[1][1]) == endpoint['wire'], 'attainment is not a scalar destination') + peak, snapshots = forward_channel(events, origin) + expected = Fraction(endpoint['coefficient']) + check(snapshots[(endpoint['event'], endpoint['wire'])] == expected, 'forward coefficient') + check(reverse_coefficient(events, origin, endpoint) == expected, 'reverse coefficient') + check(peak == endpoint['bits'], 'whole-channel guard maximum') + check((expected * (1 << peak)).denominator == 1, 'sufficient guard') + check(peak > 0 and (expected * (1 << (peak - 1))).denominator == 2, 'one fewer guard must fail') + # Check the entire projected trajectory on this channel, not just the endpoint. + check(all((v * (1 << peak)).denominator == 1 for v in snapshots.values()), 'channel guard closure') + checked += 1 + local = record['seed_selected_local_witness'] + check(events[local['child_event']] == local['child'], 'child bytes') + check(events[local['scalar_event']] == local['scalar'], 'scalar bytes') + check(local['scalar_event'] == local['child_event'] + 1, 'not adjacent') + child = local['child'] + src = child[2] if child[0] == 'climb' else wire(child[1]) + gate = local['scalar'][1] + check(gate[0] == 'add' and wire(gate[2]) == src, 'wrong child consumer') + factor = Fraction(gate[3], gate[4]) + check(factor == Fraction(-1, 2), 'wrong half ADD') + for p in [0, 4, 17, 29, 61, 93, 256]: + q = Fraction(1, 1 << p) + clean, noisy = factor * 2 * q, factor * 3 * q + check((clean / q).denominator == 1, 'ideal grid') + check((noisy / q).denominator == 2, 'noise did not leave grid') + check((noisy / (q / 2)).denominator == 1, 'one-bit local repair') + checked += 1 + return checked + + +def main(): + raw = CERT.read_bytes() + check(hashlib.sha256(raw).hexdigest() == CERT_HASH, 'source bytes') + packet = json.loads(gzip.decompress(raw)) + report = json.loads((BASE / 'RESULT.json').read_text()) + count = verify(report, packet) + print(f'PASS_QQ16_NOISE_INDEPENDENT witnesses={count} forward_dense_and_reverse_dual') + + +if __name__ == '__main__': + main() diff --git a/research/qq16-noise-lattice-audit/test_verify.py b/research/qq16-noise-lattice-audit/test_verify.py new file mode 100644 index 0000000000..3076e87d4b --- /dev/null +++ b/research/qq16-noise-lattice-audit/test_verify.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +import copy +import importlib.util +import json +from fractions import Fraction as Q +from pathlib import Path +import tempfile +import unittest +from unittest.mock import patch + +HERE = Path(__file__).resolve().parent + + +def module(name): + spec = importlib.util.spec_from_file_location(name, HERE / f'{name}.py') + value = importlib.util.module_from_spec(spec) + spec.loader.exec_module(value) + return value + + +V = module('verify') +I = module('independent') + + +class NoiseLatticeControls(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.packet = V.load_packet() + cls.receipt = json.loads((HERE / 'RESULT.json').read_text()) + + def test_intermediate_guard_survives_endpoint_cancellation(self): + events = [ + ['climb', 'B', 0, 0, 1, 1], + ['scalar', ['add', ['L', 1], ['L', 0], 1, 2], 1], + ['scalar', ['add', ['L', 1], ['L', 0], -1, 2], 1], + ['scalar', ['scale', ['L', 0], 1, 8], 1], + ['scalar', ['scale', ['L', 0], 8, 1], 1], + ] + report = V.analyze(events) + self.assertEqual(report['child_guard_bits'], 3) + self.assertEqual(report['child_attainment']['attainment']['event'], 3) + self.assertEqual(I.reverse_coefficient(events, {'event': 0, 'wire': 0}, + {'event': 4, 'wire': 0}), 1) + + def test_clear_erases_a_fault_but_does_not_erase_earlier_obligation(self): + events = [ + ['climb', 'B', 0, 0, 1, 1], + ['scalar', ['add', ['L', 1], ['L', 0], 1, 2], 1], + ['scalar', ['clear', ['L', 1]], 1], + ] + report = V.analyze(events) + self.assertEqual(report['child_guard_bits'], 1) + self.assertEqual(I.reverse_coefficient(events, {'event': 0, 'wire': 0}, + {'event': 2, 'wire': 1}), 0) + + def test_adjacent_witness_cannot_skip_an_adapter(self): + events = [ + ['climb', 'B', 0, 0, 1, 1], + ['adapter', 'not a scalar'], + ['scalar', ['add', ['L', 1], ['L', 0], 1, 2], 1], + ] + self.assertEqual(V.direct_sites(events), []) + + def test_same_grid_and_nearest_rounding_are_not_exact(self): + for p in [0, 4, 17, 29, 61, 256]: + q = Q(1, 1 << p) + for sign in [-1, 1]: + exact = sign * 3 * q / 2 + lower = (exact // q) * q + self.assertEqual(abs(exact - lower), q / 2) + self.assertEqual(abs(exact - (lower + q)), q / 2) + + def test_mutated_attainment_rejected_by_independent_dual(self): + report = copy.deepcopy(self.receipt) + report['cases']['B_1_2']['child_attainment']['attainment']['coefficient'] = '-81920/262144' + with self.assertRaisesRegex(ValueError, 'forward coefficient'): + I.verify(report, self.packet) + + def test_weaker_guard_rejected(self): + report = copy.deepcopy(self.receipt) + report['cases']['B_1_2']['child_attainment']['attainment']['bits'] = 17 + with self.assertRaisesRegex(ValueError, 'guard maximum'): + I.verify(report, self.packet) + + def test_swapped_child_register_rejected(self): + report = copy.deepcopy(self.receipt) + report['cases']['B_1_2']['seed_selected_local_witness']['child'][2] += 1 + with self.assertRaisesRegex(ValueError, 'child bytes'): + I.verify(report, self.packet) + + def test_changed_live_source_rejected(self): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + source = root / V.SOURCE + source.parent.mkdir(parents=True) + source.write_bytes(b'not the pinned certificate') + with patch.object(V, 'ROOT', root): + with self.assertRaisesRegex(ValueError, 'SHA256 mismatch'): + V.load_packet() + + def test_unknown_event_rejected(self): + packet = {'programs': {'bad': [['unknown_map']]}} + with self.assertRaisesRegex(ValueError, 'unknown event'): + V.expand(packet, 'bad') + + def test_non_dyadic_and_invalid_register_rejected(self): + with self.assertRaisesRegex(ValueError, 'non-dyadic'): + V.denominator_bits(Q(1, 3)) + for invalid in [['L', 704], ['C', 8], ['Q', 0], ['L', -1]]: + with self.assertRaises(ValueError): + V.register(invalid) + + def test_complete_child_histograms(self): + self.assertEqual(sum(c['child_defect_columns'] for c in self.receipt['cases'].values()), 7004) + for record in self.receipt['cases'].values(): + self.assertEqual(sum(record['child_guard_histogram'].values()), record['child_defect_columns']) + self.assertEqual(max(map(int, record['child_guard_histogram'])), record['child_guard_bits']) + self.assertEqual(self.receipt['cases']['B_1_2']['child_guard_histogram']['18'], 12) + + +if __name__ == '__main__': + unittest.main() diff --git a/research/qq16-noise-lattice-audit/verify.py b/research/qq16-noise-lattice-audit/verify.py new file mode 100644 index 0000000000..a383ff5b6d --- /dev/null +++ b/research/qq16-noise-lattice-audit/verify.py @@ -0,0 +1,199 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Noise-lattice audit of two pinned QQ16 scalar projections, not native execution.""" +from __future__ import annotations + +import argparse +from collections import Counter +from fractions import Fraction as Q +import gzip +import hashlib +import json +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +SOURCE = 'research/joint-query/certificate.json.gz' +PAYLOAD_SHA256 = '2efe83c59978aa9c0db2c3e4eccc14cbfdcd3c9ce499432601b5dd34083472ef' +SEED = 61 +NONSCALAR = {'climb', 'native_line', 'adapter', 'residual_adapter', 'phase', 'cover_map'} + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def canonical(value): + return json.dumps(value, sort_keys=True, separators=(',', ':')).encode() + + +def load_packet(): + pins = json.loads((HERE / 'SOURCES.json').read_text()) + pin = next(p for p in pins['files'] if p['path'] == SOURCE) + raw = (ROOT / SOURCE).read_bytes() + require(hashlib.sha256(raw).hexdigest() == pin['sha256'], 'source SHA256 mismatch') + require(hashlib.sha1(f'blob {len(raw)}\0'.encode() + raw).hexdigest() == pin['git_blob'], 'source Git blob mismatch') + plain = gzip.decompress(raw) + require(hashlib.sha256(plain).hexdigest() == PAYLOAD_SHA256, 'payload SHA256 mismatch') + return json.loads(plain) + + +def register(token): + kind, i = token + require(kind in ('L', 'C') and type(i) is int, 'invalid register') + require(0 <= i < (704 if kind == 'L' else 8), 'register out of range') + return i + (704 if kind == 'C' else 0) + + +def expand(packet, case): + result = [] + for event in packet['programs'][case]: + if event[0] == 'retained_core': + result.extend(packet['core_words'][event[1]]) + elif event[0] in ('cover_sweep', 'private_sweep'): + result.extend(event[2]) + else: + result.append(event) + for event in result: + require(event[0] == 'scalar' or event[0] in NONSCALAR, f'unknown event {event[0]}') + return result + + +def child_wire(event): + if event[0] == 'climb': + return register(['L', event[2]]) + if event[0] == 'native_line': + return register(event[1]) + return None + + +def denominator_bits(value): + d = value.denominator + require(d & (d - 1) == 0, 'non-dyadic coefficient') + return d.bit_length() - 1 + + +def direct_sites(events): + """No ignored adapter/map lies between the actual child and half-scalar.""" + sites = [] + for i, (a, b) in enumerate(zip(events, events[1:])): + w = child_wire(a) + if w is None or b[0] != 'scalar': + continue + gate = b[1] + if gate[0] == 'add' and register(gate[2]) == w: + coeff = Q(gate[3], gate[4]) + require(register(gate[1]) != w, 'self ADD unsupported') + elif gate[0] == 'scale' and register(gate[1]) == w: + coeff = Q(gate[2], gate[3]) + else: + continue + if coeff.denominator == 2: + sites.append({'child_event': i, 'scalar_event': i + 1, + 'child': a, 'scalar': b, 'coefficient': str(coeff)}) + return sites + + +def analyze(events): + """All independent input and child-fault columns at every completed scalar cut. + + Exactly the scalar projection of PR3181: non-scalar operators are identities. + The extra independent symbols are additive defects AFTER each child. + """ + rows = [{j: Q(1)} for j in range(712)] + origins = [{'kind': 'input', 'event': -1, 'wire': j} for j in range(712)] + maxima = [{'bits': 0, 'event': -1, 'wire': j, 'coefficient': '1'} for j in range(712)] + for i, event in enumerate(events): + w = child_wire(event) + if w is not None: + k = len(origins) + origins.append({'kind': event[0], 'event': i, 'wire': w}) + maxima.append({'bits': 0, 'event': i, 'wire': w, 'coefficient': '1'}) + rows[w][k] = Q(1) + continue + if event[0] != 'scalar': + continue + gate = event[1] + op, w = gate[0], register(gate[1]) + if op == 'clear': + rows[w] = {} + elif op == 'scale': + c = Q(gate[2], gate[3]) + rows[w] = {k: v * c for k, v in rows[w].items() if v * c} + elif op == 'add': + s, c = register(gate[2]), Q(gate[3], gate[4]) + require(s != w, 'self ADD unsupported') + for k, v in rows[s].items(): + value = rows[w].get(k, Q(0)) + c * v + if value: + rows[w][k] = value + else: + rows[w].pop(k, None) + else: + raise ValueError(f'unknown scalar {op}') + for k, value in rows[w].items(): + bits = denominator_bits(value) + if bits > maxima[k]['bits']: + maxima[k] = {'bits': bits, 'event': i, 'wire': w, 'coefficient': str(value)} + child_maxima = maxima[712:] + histogram = Counter(m['bits'] for m in child_maxima) + max_child = max(range(712, len(origins)), key=lambda k: maxima[k]['bits']) + max_input = max(range(712), key=lambda k: maxima[k]['bits']) + sites = direct_sites(events) + require(bool(sites), 'no direct child-to-fractional-scalar witness') + selected = sites[SEED % len(sites)] + coefficient = Q(selected['coefficient']) + # In working-grid units, ideal source=2 and actual source=3 for a half ADD. + require(coefficient.denominator == 2, 'selected site is not a half scalar') + selected.update({'selection': f'{SEED} modulo {len(sites)}', + 'working_grid': 'q = 2^(-p), any integer p >= 0', + 'ideal_source_units': 2, 'child_defect_units': 1, + 'actual_source_units': 3, + 'ideal_output_units': str(2 * coefficient), + 'actual_output_units': str(3 * coefficient)}) + require((2 * coefficient).denominator == 1 and (3 * coefficient).denominator == 2, + 'local grid escape not established') + full = [{'origin': o, 'attainment': m} for o, m in zip(origins, maxima)] + return { + 'event_count': len(events), 'event_counts': dict(sorted(Counter(e[0] for e in events).items())), + 'input_columns': 712, 'child_defect_columns': len(child_maxima), + 'scalar_cuts': sum(e[0] == 'scalar' for e in events), + 'input_guard_bits': maxima[max_input]['bits'], + 'child_guard_bits': maxima[max_child]['bits'], + 'child_guard_histogram': {str(k): v for k, v in sorted(histogram.items())}, + 'input_attainment': full[max_input], 'child_attainment': full[max_child], + 'all_column_attainments_sha256': hashlib.sha256(canonical(full)).hexdigest(), + 'direct_adjacent_sites': len(sites), 'seed_selected_local_witness': selected, + } + + +def generate(): + packet = load_packet() + cases = {case: analyze(expand(packet, case)) for case in ('F_0', 'B_1_2')} + return { + 'schema_version': 1, 'no_new_kappa': True, 'assignment_seed': SEED, + 'scope': 'All completed scalar cuts of two identity-nonscalar projections; independent additive child defects. Direct adjacent witnesses retain actual instruction bytes.', + 'source_payload_sha256': PAYLOAD_SHA256, 'cases': cases, + } + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--write', action='store_true', help='create an absent RESULT.json') + args = parser.parse_args() + report = generate() + result_path = HERE / 'RESULT.json' + if args.write: + with result_path.open('x') as out: + out.write(json.dumps(report, indent=2, sort_keys=True) + '\n') + else: + require(report == json.loads(result_path.read_text()), 'receipt mismatch') + cases = [report['cases'][name] for name in ('F_0', 'B_1_2')] + inputs = ','.join(str(c['input_guard_bits']) for c in cases) + children = ','.join(str(c['child_guard_bits']) for c in cases) + print(f'PASS_QQ16_NOISE_LATTICE_AUDIT input_guards={inputs} child_guards={children} cases=F_0,B_1_2 no_new_kappa') + + +if __name__ == '__main__': + main()