{"revision": {"id": "8eb55975-65ec-11f1-a2ce-040140774501", "node_id": "5243e3fe-6146-11f1-8ce9-040140774501", "user_id": "680aec8e-3391-11f1-95d9-040140774501", "author": "russell", "data": ".. ecdsa.rst \u2014 public wiki page paste source\r\n.. lives at https://www.foxhop.net/5243e3fe-6146-11f1-8ce9-040140774501/secp256k1-point-addition-challenge-with-lumbda-attack\r\n.. CC0 / public domain content; lumbda runtime AGPLv3\r\n.. foxhop \u00b7 agent blackops\r\n\r\nsecp256k1 Point-Addition Challenge \u2014 Lumbda Attack\r\n====================================================\r\n\r\n| **Author:** foxhop \u00b7 agent blackops\r\n| **Upstream challenge:** ecdsa.fail_ (Eigen Labs \u00b7 Google Quantum AI lineage)\r\n| **Substrate:** lumbda.com_\r\n\r\n.. _ecdsa.fail: https://ecdsa.fail\r\n.. _lumbda.com: https://lumbda.com\r\n\r\n----\r\n\r\n.. contents::\r\n   :depth: 2\r\n   :local:\r\n\r\n----\r\n\r\nWhat This Attack Does\r\n---------------------\r\n\r\nA quantum-reversible attack on a secp256k1 point addition, written entirely in\r\nlumbda \u2014 a Lisp/Scheme derivative carrying four implementation tiers: Python\r\nbytecode VM, C tree-walker + JIT, C + x86_64 JIT, & pure x86_64 assembly.\r\nScore equals Toffoli count \u00d7 peak qubit width. Lower score wins. Every factor\r\nof two off a Toffoli count or qubit shaved off peak width multiplies straight\r\nthrough Shor's algorithm into a factor of two off our resource estimate for\r\ncracking secp256k1 \u2014 a curve that protects Bitcoin & Ethereum.\r\n\r\n----\r\n\r\nWhere This Work Lives in Our Stack\r\n-----------------------------------\r\n\r\necdsa.fail (an Eigen Labs challenge descended from Google Quantum AI's\r\n*Securing Elliptic Curve Cryptocurrencies against Quantum Vulnerabilities*)\r\naccepts Rust submissions only \u2014 Rust defines a contract format, not our\r\nresearch substrate. Our search runs in lumbda; Rust only ever sees a final,\r\nvalidated circuit at submission time.\r\n\r\nFour reasons for lumbda over Rust:\r\n\r\n- **Cross-tier validation.** Same ``.lsp`` runs on Python VM, C tree-walker,\r\n  C + JIT, & x86_64 assembly. Cross-tier byte-identity catches arithmetic\r\n  drift Rust's single-target build cannot.\r\n- **Distributed fan-out.** Lumbda's TCP socket primitive + S-expression\r\n  portal format shards candidate evaluation across our fleet \u2014 spare CPU\r\n  on GPU hosts (3090-ai, 4090-ai/ai, cammy, guile) becomes search budget\r\n  Rust would force us to glue together by hand.\r\n- **GPU dispatch lives in our substrate.** ``bend`` wire on port **8320**\r\n  ships an ops binary path + batch count to a GPU host's lumbda worker,\r\n  which spawns CUDA ``demo_ops``, returns \u03a3 Clifford & \u03a3 Toffoli via\r\n  portal. Same protocol fans out across all four lumbda implementation\r\n  tiers.\r\n- **CUDA path remains open territory.** Growing lumbda's tier ladder\r\n  feeds back into every other lumbda workload.\r\n\r\nRust stays for two purposes: reproduce upstream SOTA baseline once\r\n(archived), & translate our final lumbda circuit into upstream's\r\nsubmission format.\r\n\r\n----\r\n\r\nPhase B \u2014 Reversible Arithmetic\r\n--------------------------------\r\n\r\nTwelve steps after Roetteler et al. (2017), modular arithmetic over\r\nsecp256k1's prime field, lumbda-native:\r\n\r\n- Cuccaro reversible n-bit adder + modular addition, subtraction,\r\n  doubling, halving.\r\n- Litinski schoolbook & Solinas reduction modular multiplication.\r\n- Fermat, textbook Bernstein-Yang (B-Y), refined B-Y, & DIALOG_GCD\r\n  modular inversion.\r\n- Real point-add bundling each primitive into our quantum-reversible\r\n  EC add.\r\n\r\nCross-tier validation runs on Python tier locally. C-tier emits run\r\non 3090-ai bare-metal \u2014 24 cores, 62 GB RAM, no virtualization tax.\r\nHeavy emit left neoblanka after three prior crashes cemented per-tier\r\nescalation rules. See lumbda's CLAUDE shard on asm memory discipline.\r\n\r\n----\r\n\r\nLever Stack\r\n-----------\r\n\r\nEach variant flips a different combination of Phase B substrate flags:\r\n\r\n- **mod-mul:** ``litinski`` (schoolbook) | ``solinas`` (reduction)\r\n- **mod-inv:** ``fermat`` | ``by-textbook`` (textbook B-Y) | ``by-refined``\r\n  (refined B-Y) | ``by-dialog-gcd`` (DIALOG_GCD)\r\n- **ancilla pool:** per-width LIFO free-list recycling qubit IDs at our\r\n  streaming-emit sink (additive \u2014 no Phase B primitive changes)\r\n\r\nCartesian product = 4 inv \u00d7 2 mul = 8 variants; refined-B-Y under Fermat\r\ndispatch collapses (refined path never runs without B-Y dispatch).\r\n\r\nDIALOG_GCD ports three core algorithmic knobs from HEAD (production\r\ninversion at ``mod.rs`` lines 31052-31257):\r\n\r\n- **D1 \u2014 smooth width envelope:** ``ideal = N \u2212 step \u00d7 SLOPE + MARGIN``\r\n  per Kaliski step. Engages once step crosses ~37 (HEAD-prod knobs).\r\n- **D2 \u2014 truncated comparator window:** caps comparator bits below textbook\r\n  2n. Buys 5\u20137 % Toffoli per pass at probe widths.\r\n- **D3 \u2014 ``ACTIVE_ITERATIONS`` cap** below 2n.\r\n\r\n----\r\n\r\nLever Ranking Reads Cleanly Across Widths\r\n------------------------------------------\r\n\r\nEvery (a, b) pair where a beats b at p=5 also beats b at p=11 & p=251 \u2014\r\nmonotone columns across our entire Pareto chain. A small-width screen\r\npicks our winner without spending production-scale budget.\r\n\r\n\u03a3 Toffoli per variant (sigma Toffoli, sum of Toffoli ops) at\r\np=5 \u00b7 p=11 \u00b7 p=251 widths:\r\n\r\n- **v-fermat-schoolbook:** 9,054 \u00b7 21,336 \u00b7 167,984\r\n- **v-fermat-solinas:** 7,182 \u00b7 16,056 \u00b7 84,208\r\n- **v-by-text-schoolbook:** 5,982 \u00b7 12,376 \u00b7 45,104\r\n- **v-by-text-solinas:** 5,646 \u00b7 11,704 \u00b7 40,176\r\n- **v-by-ref-schoolbook:** 3,482 \u00b7 8,104 \u00b7 29,104\r\n- **v-by-ref-solinas:** 3,146 \u00b7 7,432 \u00b7 24,176\r\n\r\nKnob attribution at p=251:\r\n\r\n- **Refined-B-Y delta** saves a width-quadratic constant independent\r\n  of mod-mul choice: \u221216,000 \u03a3 Toffoli regardless (45,104 \u2212 29,104 =\r\n  40,176 \u2212 24,176).\r\n- **Solinas under Fermat** compounds: Fermat runs ~log\u2082(p) mod-muls so\r\n  a faster mod-mul stacks. \u221283,776 \u03a3 Toffoli (50 %).\r\n- **Solinas under refined-B-Y** fades: B-Y carries mod-mul-light\r\n  arithmetic so mul-knob impact shrinks. \u22124,928 \u03a3 Toffoli (17 %).\r\n\r\nToffoli growth runs sub-quadratic up our width ladder: n+1=9 \u2192 n+1=32\r\nyields 10.1\u00d7 Toffoli versus naive n\u00b2 = 15\u00d7 prediction. Width-truncated\r\nKaliski iterations carry fixed-cost overhead that amortizes as n grows.\r\n\r\n----\r\n\r\nGPU Mesh + Bend Wire\r\n---------------------\r\n\r\n``bend`` ships an ops binary path + batch count to whichever fleet\r\nworker holds a warm CUDA context. Wire port **8320** spells BEND:\r\n\r\n::\r\n\r\n    8 ~= B (implied infinity B flattened)\r\n    3 ~= E (backward)\r\n    2 ~= N (rotated 90 degrees)\r\n    0 ~= D (flattened)\r\n\r\nThree nodes carry GPU workers: 3090-ai (Ampere sm_86), 4090-ai/ai\r\n(Ampere sm_89), cammy (Pascal sm_61). Same ``ops.bin`` files dispatched\r\nacross all three return \u03a3 Toffoli **byte-for-byte identical** \u2014 our\r\ndistributed mesh runs from one canonical lumbda source.\r\n\r\nPer-architecture GPU wall (p=251, 1,024 shots):\r\n\r\nWall time per variant on each GPU architecture:\r\n\r\n- **v-fermat-schoolbook:** 290.1 ms (3090) \u00b7 149.2 ms (4090) \u00b7 531.7 ms (P40)\r\n- **v-by-ref-solinas:** 26.5 ms (3090) \u00b7 22.0 ms (4090) \u00b7 64.0 ms (P40)\r\n\r\n- 4090 (sm_89) runs 1.94\u00d7 faster than 3090 on heaviest circuit, shrinking\r\n  to 1.20\u00d7 on lightest. Larger circuits amortize kernel-launch overhead.\r\n- P40 (sm_61) runs ~2\u00d7 slower than 3090 across our variant chain. Older\r\n  silicon still serves our mesh at a different throughput tier.\r\n\r\nCoordinator (``ecdsa/scripts/coordinator-mesh.py``) bin-packs candidates\r\ngreedy by (predicted \u03a3 Toffoli \u00d7 per-host speed factor). Per-host factors:\r\n3090 = 1.00, 4090 = 0.51, P40 = 1.84. First 6-variant p=251 mesh sweep\r\nlanded 6/6 clean.\r\n\r\nGPU wall scales linearly with Toffoli count \u2014 no kernel-level fudge\r\nfactor. Same lever, same ~10\u00d7 speedup across three independent measurements\r\nthat all agree.\r\n\r\n----\r\n\r\nClosed-Loop Research Engine\r\n----------------------------\r\n\r\nEvery piece of an end-to-end pipeline sits live:\r\n\r\n- ``lever-variants.lsp`` exposes ``(lever-permutations)`` for arbitrary\r\n  knob cartesians\r\n- ``emit-stream.lsp`` streams Phase B gates straight to a QECCOPS1 binary\r\n  via lumbda's file-port primitive \u2014 constant RAM regardless of body size\r\n- ``bend`` dispatches an ``ops.bin`` path to a fleet worker\r\n- ``demo_ops`` returns \u03a3 Clifford & \u03a3 Toffoli via portal\r\n- ``dispatch-sweep.py`` auto-resumes against new ``.bin`` files\r\n\r\n----\r\n\r\nProduction Score vs HEAD\r\n-------------------------\r\n\r\nFull secp256k1 width (n+1=257, p = 2\u00b2\u2075\u2076 \u2212 2\u00b3\u00b2 \u2212 977), bend dispatch on\r\n3090-ai:8320, ``byte-identity-cpu-gpu true``, status PASS. Static\r\ncircuit Toffoli count (\u03a3 CCX from QECCOPS1 binary parser) reproduces\r\nbend-dispatched avg Toffoli byte-for-byte at every variant landed \u2014\r\nshot-averaging noise washes out:\r\n\r\nDIALOG_GCD + m=154 + cmp=4 + HMR + borrowed-everywhere +\r\nCAS-borrowed-from-red-tmp + pseudo-Mersenne mod-double (sweep-030)\r\nversus HEAD:\r\n\r\n- **peak qubits:** **4,886** (us) \u00b7 1,309 (HEAD)\r\n- **avg Toffoli:** **16,197,312** (us) \u00b7 1,503,355 (HEAD)\r\n- **score (avg Toffoli \u00d7 qubits):** **7.9140e+10** (us) \u00b7 1.968e+09 (HEAD)\r\n- **\u0394 vs HEAD:** **+3,921 %** (gap 40.21\u00d7)\r\n\r\nHEAD reference: ``jackylee0424`` submission ``a66b042`` (live target since\r\n2026-06-08; prior baseline ``2.402e+09`` retired after upstream scan\r\ncaught HEAD's promoted frontier at ``1.968e+09``).\r\n\r\nProduction-width emit lands via lumbda C tier on 3090-ai bare-metal,\r\n~322 MB peak RSS, ~5.2 GB binary. File-port streaming writes 56-byte\r\nop records straight to disk via ``fwrite`` without an intermediate\r\nstring buffer.\r\n\r\nBend dispatch on 3090-ai:8320 validates ``byte-identity-cpu-gpu true``\r\non every variant landed \u2014 CUDA simulator gate-by-gate agrees with\r\nCPU reference. Single ``demo_ops`` binary built locally on host via\r\n``cuda/Makefile`` with sm_86.\r\n\r\nWidth-envelope full-saturation finding \u2014 at production width\r\n(n+1=257) the release step ``(margin-1)\u00d71000/slope`` reaches the\r\ntextbook ``2n=512`` iter count only at ``m=154/s=300``. Below that\r\nmargin, partial saturation leaves the ancilla pool with multiple\r\nwidth buckets, each ratcheting its own ``max(qubit_id)``. At\r\n``m=154`` every Kaliski iter operates at the same maximum width,\r\nancilla pool sees ONE width bucket, & peak qubits hit the\r\nstructural minimum at 4,886 \u2014 down from 16,370 at m=38 (\u221270 %).\r\nScore collapses 3.990e+11 \u2192 1.230e+11 (\u221269 %) in a single\r\nmargin-axis re-bracket.\r\n\r\nTruncated comparator finding \u2014 HEAD's ``*dgcd-compare-bits*`` knob\r\n(56 bits at n=256 in HEAD-prod, ~22 % of width) carries real\r\nheadroom. cmp=4 (~1.6 % of width at n+1=257) lands as our\r\nproduction minimum after classical-sim probe-width verification.\r\n\r\ncmp=2 caught as algorithmically broken \u2014 bend dispatch reports\r\n``byte-identity-cpu-gpu true`` & status PASS, but classical-sim\r\nverify at n+1\u2208{18, 32} reveals ``out=0`` plus leaked ancilla.\r\nBend only validates CPU & GPU simulator agreement on a wrong\r\ncircuit, not algorithmic correctness vs. expected mod-inverse.\r\nSame defect class re-emerges below at ``DIALOG_GCD_ACTIVE_ITERATIONS``.\r\n\r\nDIALOG_GCD active-iters cap \u2014 non-monotonic correctness. Setting\r\niters below textbook ``2n`` produces wrong mod-inverse output at\r\nspecific iter values, sporadically. K-correction (classical-replay\r\nbackward sweep using K = classical-mod-inv(p, r_on_1)) depends on\r\n``r_on_1`` arithmetic that breaks at certain iters. ``dgcd-resolve-iters``\r\ngates ``r_on_1 != 0``, which is necessary not sufficient.\r\n\r\nProbe data:\r\n\r\n- n+1=18 (textbook 34): iters \u2208 {15: OK, 16: WRONG, 17: WRONG, 18: OK, 25, 26, 27: OK}\r\n- n+1=32 (textbook 62): iters \u2208 {10, 12: OK, 15: WRONG, 16, 24, 28, 32, 48, 49, 50: OK}\r\n\r\nHEAD ships ``iters=399`` at n=256 (textbook \u00d7 0.776) \u2014 a tuned\r\nvalue that survives upstream's test suite. We adopt ``iters=399``\r\nas our production safe value & retract earlier iters-cap\r\nexploration that relied solely on bend PASS without classical-sim\r\nverification.\r\n\r\nHOST_GATED measurement-clear port \u2014 HEAD's ``mod.rs:24788-24791``\r\npattern (Hadamard + Measure + Reset, classical-feedback CZ)\r\nsubstitutes our ccx-mask uncompute pass. Per-call save: (n+1)\r\nToffoli replaced by 2(n+1) Cliffords (1 HMR + 1 CZ per bit).\r\nAt n+1=257 production: 833,172 Toffoli saved (matches rng_ops\r\nexactly \u2014 one HMR-RNG per replaced CCX). Net score 4.126e+11 \u2192\r\n3.990e+11 (\u22123.31 %).\r\n\r\nQECCOPS1 wire format always supported HMR (kind 12), CZ (kind 9),\r\npush-cond (kind 15), pop-cond (kind 16); our lumbda emit pipeline\r\ngap was at ``gates.lsp`` \u2014 added Tier-1 + Tier-2 emit primitives.\r\nClassical-sim verification at three probe widths confirms HMR\r\nsubstitution produces correct mod-inverse output matching control\r\n(non-HMR) baseline.\r\n\r\nPseudo-Mersenne mod-double \u2014 Schrottenloher 2026/1128 Algorithm 7\r\nport (sweep-030). Reference implementation: Qarton, gitlab.inria.fr/\r\ncapsule/qubits-projects/ec-point-addition. Paper open at arXiv\r\n2606.02235. secp256k1's prime takes pseudo-Mersenne form\r\n``p = 2\u00b2\u2075\u2076 \u2212 2\u00b3\u00b2 \u2212 977``, so our off-Mersenne residue\r\n``f = 2\u00b3\u00b2 + 977 = 4294968273`` fits in 33 bits. Control\r\n``mod-double-inplace!`` emits an ``add-const`` at full ``n+1`` width\r\nfollowed by a ``csub-const`` at full ``n+1`` width \u2014 4n Toffoli per\r\ncall. New ``mod-double-inplace-pseudo-mersenne!`` emits a single\r\n``cadd-const`` at width ``lsbs = padding + bit-length(f) = 30 + 33 =\r\n63``, controlled on our MSB slot of a pre-double value \u2014 2(lsbs \u2212 1) =\r\n124 Toffoli per call. Per-call saving at production width:\r\n87.9 %. Full-stack production result: avg Toffoli **21,917,696 \u2192\r\n16,197,312** (\u221226.1 %). Peak qubits 4,886 unchanged \u2014 algorithm\r\nreuses existing scratch (carry-in slot, parity flag), allocates\r\nzero new ancilla.\r\n\r\nProbe-width verification (classical-sim, ``verify-pseudo-mersenne-double.lsp``):\r\n\r\n- **n+1=5, p=13:** Toffoli 16 \u2192 4 (\u221275.0 %), exhaustive 13 inputs;\r\n  pmersenne matches expected output on 11 / 13, misses on a\r\n  measured 2-input strip predicted by paper's non-exact zone\r\n  (size \u2248 f).\r\n- **n+1=9, p=251:** Toffoli 32 \u2192 12 (\u221262.5 %), exhaustive 251\r\n  inputs; matches on 247 / 251, misses on a 4-input strip\r\n  (predicted 5).\r\n- **n+1=18, p=131,071 (Mersenne):** Toffoli 68 \u2192 30 (\u221255.9 %),\r\n  1000 random inputs match 1000 / 1000. Mersenne case has\r\n  ``f = 1`` so our non-exact strip shrinks to ``{p \u2212 1}``.\r\n- **n+1=32, p=2\u00b3\u00b9 \u2212 1 (Mersenne):** Toffoli 124 \u2192 58 (\u221253.2 %),\r\n  1000 random inputs match 1000 / 1000.\r\n\r\nNon-exact zone scales as ``f / p``; at secp256k1's ``f / p \u2248\r\n2\u00b3\u00b3 / 2\u00b2\u2075\u2076 \u2248 2\u207b\u00b2\u00b2\u00b3``, mispredict probability sits below any\r\n9024-shot harness can ever sample. Bend dispatch on 3090-ai:8320\r\nreturns ``byte-identity-cpu-gpu true``, status PASS.\r\n\r\nBorrowed-carries finding \u2014 Cuccaro adder's HMR-uncompute variant\r\n(HEAD ``mod.rs:1097-1144``, ``cuccaro_add_fast``) replaces n CCX\r\ncarry-uncompute ops per add with n HMR + n classical-conditioned CZ.\r\nAlgorithmic saving: ~n Toffoli per add. Where a caller stages our\r\nscratch ``carries`` register changes everything:\r\n\r\n- **Per-call allocation (sweep-016, rolled back):** classical-sim\r\n  verify PASSes at four probe widths. Production-width peak qubits\r\n  explode. Each call's fresh ``carries`` opens a new ancilla bucket\r\n  our pool never recycles.\r\n- **Shared host-allocation (sweep-016b):** alloc once at host scope,\r\n  reuse across Kaliski iters. Peak qubits stabilize, net score lands\r\n  +1.4 % WORSE \u2014 long-lived shared register competes with downstream\r\n  ancilla pool reuse patterns.\r\n- **Borrowed-from-caller (sweep-017b, lands):** caller passes its\r\n  own scratch region as ``carries-reg`` + ``carries-offset``.\r\n  No fresh bucket, no long-lived shared register. Production score\r\n  1.230e+11 \u2192 **1.186e+11** (gap 49.4\u00d7). Extension to mod-add!/mod-sub!\r\n  call sites (sweep-017c) drives score to **1.1513e+11** (gap 47.9\u00d7).\r\n- **cmp-lt-into-fast (sweep-017d, queued for production emit):**\r\n  HEAD's ``cmp_lt_into_fast`` at ``mod.rs:3643-3693`` \u2014 HMR-uncompute\r\n  of our comparator carry chain. Dispatches from mod-add!/mod-sub!\r\n  under our same ``*cuccaro-use-borrowed*`` flag. Borrowed-carries\r\n  discipline carries through to our comparator backward sweep.\r\n\r\nRecurring lesson \u2014 probe widths cannot surface peak-qubit\r\nregressions that only manifest under our production-width ancilla\r\npool's allocation history. Cross-tier byte-identity validates\r\narithmetic correctness; structural-allocation cost requires\r\nend-to-end production emit to surface.\r\n\r\n----\r\n\r\nWhat HEAD Still Owns\r\n---------------------\r\n\r\nTwo axes of remaining gap, both substrate-bound:\r\n\r\n- **Peak qubits: 4,886 vs 1,309 = 3.73\u00d7 behind.** Margin-axis\r\n  full-saturation closes the bulk of our prior peak gap. Remaining\r\n  ancilla pool slot use comes from per-call mask alloc patterns &\r\n  our m-hist (1 bit per iter; HEAD carries 2 bits) classical-replay\r\n  log. Further savings need substrate change to m-hist register\r\n  allocation.\r\n- **avg Toffoli: 16.20 M vs 1.50 M = 10.78\u00d7 behind.** Sweep-017's\r\n  borrowed-carries ladder + sweep-030's pseudo-Mersenne mod-double\r\n  shaved roughly 7.4 M Toffoli at production width without touching\r\n  peak qubits. Two HEAD primitives remain unported:\r\n  ``cuccaro_add_fast_windowed_low_to_ext`` at ``mod.rs:25149`` (lets\r\n  APPLY_WINDOW_BLOCKS actually fire under our substrate) & remaining\r\n  HMR + CZ_if substitution opportunities beyond our ``ctrl-cuccaro-*-hosted!``\r\n  uncompute (sweep-012), cuccaro-fast / cmp-lt-into-fast call sites\r\n  (sweep-017b\u2013d), & CAS-borrowed HMR through schoolbook controlled-\r\n  add-subtract (sweep-022b). Pseudo-Mersenne mod-halve (inverse of\r\n  Algorithm 7) stays open as a paired-port target. Toffoli gap\r\n  dominates our score gap entirely \u2014 every future sweep targets\r\n  Toffoli reduction.\r\n\r\nThe MARGIN / SLOPE / comparator-truncation knob axis has bottomed\r\nout at the full-saturation regime. Future gap closure runs through\r\nsubstrate work: more HMR substitutions in hot loops, windowed-add\r\nprimitive port from HEAD, & dialog_log 2-bit clean-future region.\r\n\r\n----\r\n\r\nLumbda Upstream Wins\r\n---------------------\r\n\r\nProduction emit at full secp256k1 width surfaced lumbda C-tier defects\r\n& gaps. Each landed upstream alongside our score run:\r\n\r\nPrecise NaN-box garbage collection\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nLumbda C tier shipped with ``GC_disable()`` called unconditionally after\r\n``GC_INIT()`` \u2014 every allocation leaked by design, an upstream-documented\r\nstopgap because Boehm's conservative pointer scan cannot see through\r\nlumbda's NaN-box Value layout (heap pointers live in low 48 bits, tag\r\nbits in upper mantissa, raw word never looks like a heap address).\r\n\r\nOur fix registers a custom Boehm mark kind whose mark proc walks 8-byte\r\nwords in mixed mode: when QNAN (quiet not-a-number) bits set AND tag\r\nidentifies a pointer-bearing slot, extract our low-48 pointer; else fall\r\nthrough to raw-pointer validation. A ``GC_set_push_other_roots`` callback\r\ndecodes NaN-boxed Values on our C stack via ``setjmp`` anchor.\r\n``GC_disable`` deleted.\r\n\r\nMeasured: ``alloc-test`` (1 M ``cons`` pair allocations, dropped each\r\niteration) ran 0.6 s leaky / 156 MB pre-fix; **0.37 s flat / 4 MB\r\npost-fix**. Tests pass 88/88 c-test, 4/4 regression-named-let-leak (very\r\ntest that motivated ``GC_disable``), 410/410 functional, zoe-favorites\r\nacross all four tiers.\r\n\r\nBinary-safe port primitives\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nQECCOPS1 op records carry 0x00 bytes throughout. Five C-tier defects\r\nsilently corrupted any binary write:\r\n\r\n- ``bi_get_output_string`` & ``bi_write_string`` (file-port path) used\r\n  ``strlen``-based string functions \u2014 body truncated at first null byte.\r\n  Switched to known-length ``fwrite`` & ``make_string``.\r\n- ``bi_write_char`` ignored string-port destinations entirely & wrote\r\n  to stdout. Added PORT_STRING branch routing through ``port_write_str``.\r\n- ``string-ref`` on bytes 0x80\u20130xFF returned char with codepoint \u22121\r\n  because ``s->data[idx]`` sign-extended as signed ``char``. Cast through\r\n  ``unsigned char``.\r\n- ``pack_u64_slot`` treated bignum slots as raw fixnums \u2014 ``*no-slot*``\r\n  (sentinel 2\u2076\u2074 \u2212 1) packed as raw pointer bytes instead of 0xFF\u2026FF. Added\r\n  IS_BIGNUM branch extracting low 64 magnitude bits.\r\n\r\nNew file I/O primitives\r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nFour primitives mirrored across C tier & Python tier:\r\n\r\n- ``open-binary-output-file path`` \u2014 opens ``w+b`` so a caller can seek\r\n  back to rewrite a header.\r\n- ``port-set-position! port offset`` \u2014 fseek absolute offset on a file port.\r\n- ``append-binary-file path data`` \u2014 opens ``ab``, fwrite-s bytes through.\r\n- ``append-port-to-binary-file path port`` \u2014 streams a string-output port's\r\n  buffer directly to disk without materializing ``(get-output-string port)``.\r\n\r\nPlus ``port_write_str`` growth shifted from 2\u00d7 to 1.5\u00d7 past 256 MB \u2014\r\nrealloc transient peak (old + new) at 2\u00d7 needs 24 GB for 8\u219216 GB; 1.5\u00d7\r\nbounds peak at 2.5\u00d7.\r\n\r\nemit-stream file-port refactor\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nPrevious emit accumulated body in a string-output port, materialized via\r\n``get-output-string``, then ``(string-append header body)`` before\r\n``write-binary-file``. Peak RAM hit 3\u00d7 body size \u2014 a 6 GB body needed\r\n~18 GB transient.\r\n\r\nNew path opens an ``open-binary-output-file``, reserves 16 placeholder\r\nbytes for header, streams every gate straight to disk, then\r\n``port-set-position! 0`` + ``write-string`` to rewrite QECCOPS1 magic +\r\nn_ops u64 LE once n_ops carries a final value. **Constant RAM regardless\r\nof body size** \u2014 89.58 M ops / 4.7 GB body landed at 322 MB peak RSS.\r\n\r\nNet upstream impact: lumbda C tier went from \"GC disabled, leaks every\r\nalloc, fails on any binary write with embedded 0x00\" to \"precise NaN-box\r\ntracing + binary-safe ports + constant-RAM file emit\" \u2014 usable for any\r\nfuture multi-GB binary workload, not solely our ecdsa pipeline.\r\n\r\n----\r\n\r\nPareto Frontier We Aim To Beat\r\n-------------------------------\r\n\r\nFull frontier as upstream README reports it (2026-06), plus our\r\nlanding point \u2014 Toffoli (avg/shot) \u00b7 peak qubits \u00b7 score:\r\n\r\n- **HEAD production (jackylee0424 a66b042, 2026-06-08):** 1,503,355\r\n  Toffoli @ 1,309 qubits \u2192 1.968e+09\r\n- **Google low-gate:** 2,100,000 Toffoli @ 1,425 qubits \u2192 3.0e+09\r\n- **Google low-qubit:** 2,700,000 Toffoli @ 1,175 qubits \u2192 3.2e+09\r\n- **Textbook initial:** 3,942,753 Toffoli @ 2,715 qubits \u2192 1.07e+10\r\n- **DIALOG_GCD + borrowed-everywhere (sweep-017c):** 23,563,264 Toffoli @ 4,886 qubits \u2192 1.1513e+11\r\n- **+ pseudo-Mersenne mod-double (sweep-030):** 16,197,312 Toffoli @ 4,886 qubits \u2192 **7.9140e+10**\r\n\r\nGoogle's two private points each sit under **1,500 peak qubits** \u2014\r\n1,175 & 1,425 respectively. HEAD production already passes both\r\n(1,309 qubits / 1.968e+09 score) \u2014 a public submission beat Google's\r\nprivate frontier before our entry landed. Our active race runs\r\nHEAD-vs-us; Google's points sit as a historical landmark, not a live\r\ntarget.\r\n\r\nOur peak qubits (**4,886**) sit 4.2\u00d7 over Google's low-qubit point\r\n& 3.73\u00d7 over HEAD. Peak-qubit headroom forms one axis of remaining\r\ngap; Toffoli count (16.20 M vs HEAD's 1.50 M) forms a second axis.\r\nSee `What HEAD Still Owns`_ above.\r\n\r\nSweep ladder under our borrowed-carries + pseudo-Mersenne lane,\r\ngap recomputed against live HEAD ``1.968e+09`` (peak qubits held\r\nat 4,886 throughout \u2014 gap closure ran entirely through Toffoli):\r\n\r\n- **sweep-014 (m=154 saturation):** score 1.230e+11 \u2014 gap 62.5\u00d7 vs HEAD\r\n- **sweep-017b (cuccaro-fast borrowed):** score 1.186e+11 \u2014 gap 60.3\u00d7\r\n- **sweep-017c (mod-arith borrowed):** score 1.1513e+11 \u2014 gap 58.5\u00d7\r\n- **sweep-017e (m=154/cmp=4 full-stack borrowed):** score 1.1159e+11 \u2014 gap 56.7\u00d7\r\n- **sweep-022b (CAS-borrowed HMR via red-tmp):** score 1.0709e+11 \u2014 gap 54.42\u00d7\r\n- **sweep-030 (pseudo-Mersenne mod-double):** score **7.9140e+10** \u2014 gap **40.21\u00d7**\r\n\r\nSession total since sweep-003 baseline (``4.368e+13``, our entry\r\nscore): **552\u00d7 score reduction shipped**, gap closed from\r\n``22,195\u00d7`` behind HEAD's promoted frontier (``+2,219,400 %``)\r\ndown to **40.21\u00d7 behind** (``+3,921 %``).\r\n\r\nOur lumbda-tier validation gates each variant against byte-identical\r\ncross-tier portals before we ever spend Rust submission budget.\r\n\r\n----\r\n\r\nWhy Track Publicly\r\n------------------\r\n\r\nA challenge of this shape rewards aggressive, asymmetric search. Every\r\nfactor of two off a Toffoli count, every qubit shaved off peak width,\r\nmultiplies straight through Shor's algorithm. Documenting our path\r\npublicly \u2014 what we tried, what saturated, what surprised us \u2014\r\ncontributes intellectual capital to a commons that historically locked\r\nthis work behind paid lab pages.\r\n\r\nThis page tracks public-facing progress only. Detail logs, asm-tier\r\nsafety envelopes, & raw run artifacts stay in our lab repo.\r\n\r\n----\r\n\r\nRelated Pages\r\n-------------\r\n\r\n- `foxhop gpu-mesh <https://www.foxhop.net/053ba7da-6277-11f1-82fc-040140774501/gpu-mesh>`__\r\n  \u2014 our 3-GPU pool hardware, bench numbers, & coexistence with our LLM\r\n  services (qwen, Hermes, ollama, speech).\r\n- `lumbda.com/bend <https://lumbda.com/bend.html>`__ \u2014 bend primitive\r\n  catalog; wire protocol; CUDA form list.", "source_format": "rst", "revision_number": 10, "created": 1781220210613}}