diff --git a/research/bit-hosted-digest-fastpath/README.md b/research/bit-hosted-digest-fastpath/README.md index c7c371bbc5..779d12f401 100644 --- a/research/bit-hosted-digest-fastpath/README.md +++ b/research/bit-hosted-digest-fastpath/README.md @@ -112,13 +112,19 @@ is inferred from this bounded search. The active joint-dual containment-mask wor uses a different verifier and fixture; PR1736 checks PR589 hosting windows but does not optimize instruction hashing. [Claim and final handoff](https://github.com/CrocSwap/integer-mult-bounds/discussions/1871). +## Production follow-up + +`research/bit-hosted-digest-production/` wires the equivalent fragment-reuse +digest into the p111-tuned production `audit_hosted_k.py`. This opt-in package +now loads the pairwise-era bytes from +`research/bit-hosted-digest-fastpath/baseline.py` for differential comparison. + ## Open next questions -A maintainer could integrate the adapter into one actively maintained replay -driver, preserving its pins and comparing its complete receipt once. That would -make the runtime benefit available without opting into this package. Driver -integration and its applicable cold-replay obligations are outside this change; -see the structured question in [TASK.json](TASK.json). +Driver-level documentation may still mention this opt-in entrypoint; the shipped +p111-tuned auditor already includes the fragment digest after the production +package tip. See that package's open questions for remaining vendor copies. + ## Credit diff --git a/research/bit-hosted-digest-fastpath/SOURCES.json b/research/bit-hosted-digest-fastpath/SOURCES.json index 3c6287f08c..854dc1dce0 100644 --- a/research/bit-hosted-digest-fastpath/SOURCES.json +++ b/research/bit-hosted-digest-fastpath/SOURCES.json @@ -64,9 +64,10 @@ }, { "path": "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py", - "usage": "input", + "usage": "provenance", "git_blob": "8864ca9b942a3507171edca0cf6cbaaf10fcf434", - "sha256": "57e558c80a2fea6e291587b04afd76dfaee3550729997798b61f33daf90b8ec9" + "sha256": "57e558c80a2fea6e291587b04afd76dfaee3550729997798b61f33daf90b8ec9", + "note": "Pairwise-era digest at package base_commit. After research/bit-hosted-digest-production/, working production audit_hosted_k.py ships fragment reuse; this package compares against research/bit-hosted-digest-fastpath/baseline.py." } ] } diff --git a/research/bit-hosted-digest-fastpath/VERIFY.json b/research/bit-hosted-digest-fastpath/VERIFY.json index 19fe95d887..144ca98553 100644 --- a/research/bit-hosted-digest-fastpath/VERIFY.json +++ b/research/bit-hosted-digest-fastpath/VERIFY.json @@ -12,7 +12,7 @@ "research/community-hyperplane599-audit/pr589/bit589/v9/nine/GLOBAL-TEMPLATE.json.gz", "research/community-hyperplane599-audit/pr589/bit589/v9/nine/GLOBAL.json", "research/e8-bit-p111-tuned/code/adapt9p.py", - "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py" + "research/bit-hosted-digest-fastpath/baseline.py" ], "commands": [ { diff --git a/research/bit-hosted-digest-fastpath/baseline.py b/research/bit-hosted-digest-fastpath/baseline.py new file mode 100644 index 0000000000..8864ca9b94 --- /dev/null +++ b/research/bit-hosted-digest-fastpath/baseline.py @@ -0,0 +1,157 @@ +# Independent ownership/window audit, extending DaysSky PR442 and chafreaky PR444 (OpenAI Codex); no generator imports. +# Generalised to an arbitrary odd stage count, any replica count and host-every-residual templates by DreamingOfClouds with +# Claude Opus 5.5 (Anthropic), via Claude Code. Apache-2.0. +"""Independent ownership/window audit of an idle-axis-hosted compressed S-stage bit template. +Usage: audit_hosted_k.py PARENT_DIR HOSTED_DIR OUT.json +PARENT_DIR holds the parent's records/ and nine/-style GLOBAL files via --parent-nine (default PARENT_DIR/nine). +At the nine-stage defaults this performs PR #444's checks and fourteen mutations; at S = 11 the mutations that need a +bank are replaced by stage-count, window and exterior-coordinate controls.""" +import copy, gzip, hashlib, json, sys +from collections import Counter, defaultdict +from pathlib import Path +V=120 +read=lambda p:json.loads(Path(p).read_text()) +template=lambda p:json.loads(gzip.decompress(Path(p).read_bytes())) + +def windows(schedule): + last={}; seen=[]; win={}; rank={}; pair={} + for pos,e in enumerate(schedule): + if e['kind']=='local_cover_sweep': + seen.append((pos,e['stage'],e['pair']));last[e['pair']]=pos + elif e['kind']=='bridge': + last[e['dst']]=pos;last[e['src']]=pos + elif e['kind']=='exchange': + assert pos==len(schedule)-1 + else: + assert e['kind']=='idle' + i=e['idx'];assert i not in win + win[i]={s for q,s,p in seen if last.get(e['pair'],-1)=5 and L%2==1 and M==1+7*L + mutable={'version','live','banks_per_stage','hosting','helper_route','calls','schedule'} + assert set(t)==set(parent)|{'hosting'} + assert {k:v for k,v in t.items() if k not in mutable}=={k:v for k,v in parent.items() if k not in mutable} + assert t['replicas']==T and t['m']==M and t['private_centre_reserve']==9 + sched=copy.deepcopy(parent['schedule']);idx=0 + for e in sched: + if e['kind']=='idle':e['idx']=idx;idx+=1 + assert t['schedule']==sched + W,rank,pair=windows(t['schedule']);hs=t['hosting'] + assert hs['windows']=={str(i):[pair[i],rank[i],sorted(W[i])] for i in W if rank[i]>0 and W[i]} + used=defaultdict(set);hosted={} + for i,cp,off,w,s,h in hs['slots']: + assert i in W and s in W[i] and 0<=s0 and 0<=off and off+w<=rank[i] + cells=set(range(off,off+w));assert not cells & used[i,cp];used[i,cp]|=cells + assert (s,h) not in hosted;hosted[s,h]=(i,cp,off,w) + rem={};summaries={} + for i in rank: + if not rank[i]:continue + for cp in range(2*V):rem[i,cp]=rank[i]-len(used[i,cp]) + if str(i) in hs['windows']: + summaries[str(i)]={str(r):n for r,n in sorted(Counter(rem[i,cp] for cp in range(2*V)).items())} + assert hs['remainders']==summaries + banks={int(s):n for s,n in hs['banks_per_stage'].items()} + assert set(banks)==set(range(L)) and all(isinstance(n,int) and n>=0 for n in banks.values()) + assert {int(s):n for s,n in t['banks_per_stage'].items()}==banks + base={};end=DATA + for s in range(L):base[s]=end;end+=banks[s] + assert t['live']==end + assert len(t['calls'])==L*T and len(parent['calls'])==L*T + occ=defaultdict(set);bank_count=0;host_count=0 + assert {(c['stage'],c['replica']) for c in t['calls']}=={(s,r) for s in range(L) for r in range(T)} + for c,pc in zip(t['calls'],parent['calls']): + assert {k:v for k,v in c.items() if k!='owners'}=={k:v for k,v in pc.items() if k!='owners'} + s,rep,p=c['stage'],c['replica'],c['pair'];own=c['owners'] + assert len(own)==2*V+R and own[:2*V]==pc['owners'][:2*V] + for h,(f,r) in enumerate(own[2*V:]): + if (s,h) in hosted: + i,cp,off,w=hosted[s,h];side,port=divmod(cp,V) + assert r==['hosted',i,off,w] and f==rep*(2*K*V)+(2*pair[i]+side)*V+port + assert pair[i]!=p and 0<=f2*max(paid)**depth + return paid,host_count,bank_count + +def digest(t): + # Independent streamed hashing uses the same specified JSON instruction format. + h=hashlib.sha256();n=0;R=len(t['calls'][0]['owners'])-2*V + for call in t['calls']: + for z in t['local_programs'][call['orientation']]: + x=[z[0],call['owners'][z[1]]] + if z[0]==0:x.extend(z[2:]) + else: + x.append(call['owners'][z[2]] if z[2]<2*V+R else [t['live'],['private',0]]) + x.extend(z[3:]) + h.update(json.dumps(x,separators=(',',':')).encode());h.update(b'\n');n+=1 + return h.hexdigest(),n + +def main(): + par,bd,out=map(Path,sys.argv[1:4]);pt=template(par/'nine/GLOBAL-TEMPLATE.json.gz') + t=template(bd/'GLOBAL-TEMPLATE.json.gz');g=read(bd/'GLOBAL.json');pg=read(par/'nine/GLOBAL.json') + st=read(par/'records/249-states.json');frames=read(par/'records/frames.json')['frames'] + L=t['stages'];T=t['replicas'];M=t['m'];K=(L-1)//2;R=pg['R'];depth=g['halving_depth'];DATA=2*K*V*T + widths=[8-frames[str(st['initial'][str(h)])]['dim'] for h in range(2*V,2*V+R)] + P,host,bank=audit(t,pt,widths,depth) + th=hashlib.sha256(gzip.decompress((bd/'GLOBAL-TEMPLATE.json.gz').read_bytes())).hexdigest() + assert th==g['template_sha256'] and g['parent_template_sha256']==pg['template_sha256'] + assert P==Counter({int(r):n for r,n in g['profile'].items()}) + DEFICIT=T*(2*K*V-9*8*L) + assert (g['live'],g['physical'],g['rank_mass'],g['deficit'],g['paid_calls'],g['maxchild'])==(t['live'],t['live']+9,sum(r*n for r,n in P.items()),DEFICIT,sum(P.values()),max(P)) + assert g['hosted_residuals']==host and g['bank_assignments']==bank + dg,n=digest(t);assert dg==g['emitted_program_sha256'] and n==g['emitted_events']==pg['emitted_events'] + assert dg!=pg['emitted_program_sha256'] + controls=[] + def reject(name,fn): + q=copy.deepcopy(t);fn(q) + try:audit(q,pt,widths,depth) + except (AssertionError,KeyError,IndexError,TypeError):controls.append(name) + else:raise AssertionError('accepted '+name) + def owner(q,kind): + return next(o for c in q['calls'] for o in c['owners'][2*V:] if o[1][0]==kind) + Wd,rk,pr=windows(t['schedule']) + def outside_stage(q): + i,cp,off,w,s,h=q['hosting']['slots'][0]; q['hosting']['slots'][0][4]=next(x for x in range(L) if x not in Wd[i]) + reject('slot outside window',outside_stage) + reject('copy index outside family',lambda q:q['hosting']['slots'][0].__setitem__(1,2*V)) + reject('negative slot offset',lambda q:q['hosting']['slots'][0].__setitem__(2,-1)) + reject('wrong residual width',lambda q:q['hosting']['slots'][0].__setitem__(3,1+q['hosting']['slots'][0][3])) + reject('duplicate helper',lambda q:q['hosting']['slots'].append(q['hosting']['slots'][0])) + reject('omitted helper',lambda q:q['hosting']['slots'].pop()) + reject('hosted owner in another replica or outside the data stock',lambda q:owner(q,'hosted').__setitem__(0,owner(q,'hosted')[0]+2*K*V)) + reject('hosted owner on a wrong data family',lambda q:owner(q,'hosted').__setitem__(0,q['calls'][0]['owners'][0][0])) + if bank: + reject('wrong bank slot',lambda q:owner(q,'bank')[1].__setitem__(1,M)) + reject('wrong bank stage',lambda q:owner(q,'bank').__setitem__(0,t['live']-1)) + reject('wrong call orientation',lambda q:q['calls'][0].__setitem__('orientation','reverse')) + reject('duplicate call',lambda q:q['calls'].__setitem__(1,q['calls'][0])) + reject('changed idle rank',lambda q:next(e for e in q['schedule'] if e['kind']=='idle').__setitem__('rank',1)) + reject('understated live stock',lambda q:q.__setitem__('live',q['live']-1)) + reject('missing remainder summary',lambda q:q['hosting']['remainders'].pop(next(iter(q['hosting']['remainders'])))) + reject('stale stage count',lambda q:q.__setitem__('stages',L-2)) + reject('hosted coordinate beyond the pending set',lambda q:q['hosting']['slots'][0].__setitem__(2,rk[q['hosting']['slots'][0][0]])) + reject('overlapping hosted coordinates',lambda q:q['hosting']['slots'].append(q['hosting']['slots'][0][:5]+[(q['hosting']['slots'][0][5]+1)%R])) + res=dict(status='PASS_INDEPENDENT_REPLICATED_HOSTING_AUDIT',template_sha256=th,emitted_program_sha256=dg,emitted_events=n, + profile={str(r):z for r,z in sorted(P.items())},live=t['live'],physical=t['live']+9,hosted_residuals=host, + bank_assignments=bank,rank_mass=sum(r*n for r,n in P.items()),deficit=DEFICIT,maxchild=max(P),mutations_rejected=controls) + out.write_text(json.dumps(res,indent=2)+'\n');print(json.dumps(res)) +if __name__=='__main__':main() diff --git a/research/bit-hosted-digest-fastpath/fast_digest.py b/research/bit-hosted-digest-fastpath/fast_digest.py index 4a5d5f10d3..a9740aded4 100644 --- a/research/bit-hosted-digest-fastpath/fast_digest.py +++ b/research/bit-hosted-digest-fastpath/fast_digest.py @@ -12,8 +12,12 @@ PACKAGE = Path(__file__).resolve().parent ROOT = PACKAGE.parents[1] -AUDITOR = ('research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/' - 'vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py') +# Pairwise-era auditor bytes (production now ships fragment reuse). +AUDITOR = 'research/bit-hosted-digest-fastpath/baseline.py' +PAIRWISE_AUDITOR = ( + 'research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/' + 'vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py' +) PARAMETERIZER = 'research/e8-bit-p111-tuned/code/adapt9p.py' FIXTURE = 'research/community-hyperplane599-audit/pr589/bit589' @@ -31,12 +35,19 @@ def pins(): if x['usage'] == 'input'} +def provenance_pins(): + return {x['path']: x['sha256'] for x in + json.loads((PACKAGE / 'SOURCES.json').read_text(encoding='utf-8'))['files'] + if x['usage'] == 'provenance'} + + def load_auditor(): """Apply only the five hosted-auditor edits listed in frozen adapt9p.py.""" if not __debug__: raise RuntimeError('the inherited auditor requires assertions; remove -O/PYTHONOPTIMIZE') sources = pins() - original = checked_bytes(ROOT / AUDITOR, sources[AUDITOR]).decode('utf-8') + # baseline.py vendors the pairwise-era bytes pinned as provenance on PAIRWISE_AUDITOR. + original = checked_bytes(ROOT / AUDITOR, provenance_pins()[PAIRWISE_AUDITOR]).decode('utf-8') adapter = checked_bytes(ROOT / PARAMETERIZER, sources[PARAMETERIZER]).decode('utf-8') assignments = [n for n in ast.parse(adapter).body if isinstance(n, ast.Assign) and any(isinstance(t, ast.Name) and t.id == 'EDITS' for t in n.targets)] diff --git a/research/bit-hosted-digest-production/NOTICE.md b/research/bit-hosted-digest-production/NOTICE.md new file mode 100644 index 0000000000..4b05148749 --- /dev/null +++ b/research/bit-hosted-digest-production/NOTICE.md @@ -0,0 +1,19 @@ +# Notice + +This package wires Matthieu Pascal's proved opt-in hosted-digest adapter +(`research/bit-hosted-digest-fastpath/`, CrocSwap/integer-mult-bounds#1874) into +the production p111-tuned `audit_hosted_k.py`. + +Predecessor credit: + +- DaysSky (PR442) and Chafik Boukhalfa / chafreaky (PR444) for the ownership / + window audit lineage. +- DreamingOfClouds for the PR463/510/589 nine-stage hosted chain and the PR589 + word retained under `research/community-hyperplane599-audit/`. +- eumemic for PR555 and the P111 `adapt9p.py` parameterizer. +- Matthieu Pascal (@mtpsl) for the exact fragment-reuse digest and differential + controls in #1874 / discussion #1871. + +Prepared by Wentao Li (GitHub VictorLiwentao, X @Is__Victor) with substantial AI +assistance, under Apache-2.0. Finite certificate checks are not a formal proof +of the full multiplication theorem. diff --git a/research/bit-hosted-digest-production/README.md b/research/bit-hosted-digest-production/README.md new file mode 100644 index 0000000000..e56319b6e8 --- /dev/null +++ b/research/bit-hosted-digest-production/README.md @@ -0,0 +1,103 @@ +# Production fragment-reuse digest for p111-tuned hosted audits + +**Tooling improvement; no new kappa.** At base +`0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2`, production +`research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py` +still hashed every mapped instruction with a fresh `json.dumps`. Matthieu +Pascal's opt-in adapter `research/bit-hosted-digest-fastpath/` already proved +exact JSON-fragment reuse with identical PR589 hosted-audit receipts. This +package wires that equivalent digest into the **production** p111-tuned source +consumed by `adapt9p.py`. + +Other byte-identical `audit_hosted_k.py` inventories under `research/*/vendor/` +are left as provenance. `research/bit-hosted-digest-production/baseline.py` +vendors the pairwise-era bytes. Dependent VERIFY packages refresh or demote +those pins to provenance in this tip. Selected frontier untouched. + +## Reproduce + +Python **3.12**, standard library only, from the repository root: + +```sh +python3.12 -I -B research/bit-hosted-digest-production/verify.py +python3.12 -I -O -B research/bit-hosted-digest-production/verify.py +python3.12 -B scripts/research_package.py --package research/bit-hosted-digest-production +python3.12 -I -B research/bit-hosted-digest-production/benchmark.py --rounds 5 --write-result +``` + +Expected: + +```text +PASS_BIT_HOSTED_DIGEST_PRODUCTION events=7843392 … corruption=… certs=1 no_new_kappa +PASS_REGISTERED_RESEARCH_PACKAGE research/bit-hosted-digest-production outcome=completed +PASS_IDENTICAL_BIT_HOSTED_DIGEST_PRODUCTION_RECEIPTS +``` + +Default verify is read-only. Temp-copy digest foil rejects via receipt mismatch +or audit assertion. Package gates under `-O` re-exec an asserting child +(`python -I -B` with `PYTHONOPTIMIZE` cleared). Full `make verify`, selected +cold replay, Lean, and multiplication-theorem obligations were not rerun for +this isolated historical-auditor change. + +## Result + +On Linux / CPython 3.12.3 with `taskset -c 0`, five alternating fresh-process +pairs gave median complete hosted-audit wall time **34.880 → 13.268 s +(2.63×)**. Timing is host-descriptive and is not a correctness gate; all +samples and environment pins are in [`RESULT.json`](RESULT.json). Every +parameterized hosted-audit receipt matches digest +`96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523` +with 7,843,392 events and all 16 inherited mutation rejections. + +## Why the fragment digest is equivalent + +Compact JSON arrays concatenate at element boundaries. Encoding each local +instruction's constant prefix/tail once per orientation, and each call's owner +descriptors once per call, then concatenating the mapped owner fragments, +yields the same byte stream as building each full instruction array and calling +`json.dumps` per event. Private owners still use `[live, ["private", 0]]` past +the first call's owner count. There is no persistent cache across invocations. +See `research/bit-hosted-digest-fastpath/README.md`. + +All five `adapt9p.py` hosted-auditor anchors remain unique after the rewrite. + +## Overlap and credit + +Closest priors (different delivery): + +- `research/bit-hosted-digest-fastpath/` / [#1874](https://github.com/CrocSwap/integer-mult-bounds/pull/1874) + — opt-in fragment digest; this is the production wiring. +- [Discussion #1871](https://github.com/CrocSwap/integer-mult-bounds/discussions/1871) + — author handoff inviting driver integration. +- [#756](https://github.com/CrocSwap/integer-mult-bounds/pull/756) + — identical-receipt tooling quality bar. +- Open leave-alone tooling on other objects (#1922 joint frames, #2039/#2054 + shared-point, #2100 ternary, #2117 DisjointTensor, #2150 mixed-point, + #2194/#2210/#2231/#2239/#2257/#2263/#2276/#2320/#2329 production rewrites; + #1076 quadratic-affine) was not reopened. Soft note: #2263/#2276 touch + `e8-bit-r420/MANIFEST.sha256`; this tip does not. + +Credit Matthieu Pascal, DreamingOfClouds, eumemic, DaysSky, Chafik Boukhalfa +and the retained hyperplane599 archive. Prepared by Wentao Li +([VictorLiwentao](https://github.com/VictorLiwentao), +[@Is__Victor](https://x.com/Is__Victor)) with substantial AI assistance, under +Apache-2.0. + +## Open next questions + +1. **Question:** Should the other byte-identical vendored `audit_hosted_k.py` + copies under `research/*/vendor/` adopt the same fragment-reuse digest in a + follow-up tip? + **Why it matters:** Those trees still pin pairwise-era digests; a coordinated + refresh would remove stale inventory digests without changing receipts. + **First step:** Diff each copy against the production transform site and list + which SOURCE inventories would need provenance demotion or honest refresh. + **Blocked by:** Out of this session’s one-object stop rule. + +2. **Question:** Should active bit-hosting drivers prefer the production digest + path in their documented reproduce commands? + **Why it matters:** Some notes still point at the opt-in `fast_digest.py` + entrypoint. + **First step:** List drivers that still shell out to + `research/bit-hosted-digest-fastpath/` paths. + **Blocked by:** Maintainer documentation preference. diff --git a/research/bit-hosted-digest-production/RESULT.json b/research/bit-hosted-digest-production/RESULT.json new file mode 100644 index 0000000000..8b308ff461 --- /dev/null +++ b/research/bit-hosted-digest-production/RESULT.json @@ -0,0 +1,131 @@ +{ + "status": "PASS_IDENTICAL_BIT_HOSTED_DIGEST_PRODUCTION_RECEIPTS", + "base_commit": "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2", + "python": "3.12.3", + "platform": "Linux-6.12.94+-x86_64-with-glibc2.39", + "executable": "/usr/bin/python3.12", + "rounds": 5, + "alternating_order": [ + [ + "baseline", + "production" + ], + [ + "production", + "baseline" + ], + [ + "baseline", + "production" + ], + [ + "production", + "baseline" + ], + [ + "baseline", + "production" + ] + ], + "median_audit_seconds": { + "baseline": 34.87974892599982, + "production": 13.267512981999971 + }, + "median_speedup": 2.628959095296998, + "emitted_program_sha256": "96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523", + "emitted_events": 7843392, + "samples": [ + { + "seconds": 34.95623293999995, + "digest": "96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523", + "events": 7843392, + "mutations": 16, + "process_wall_seconds": 34.998299062000115, + "engine": "baseline", + "round": 0 + }, + { + "seconds": 13.137799121999933, + "digest": "96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523", + "events": 7843392, + "mutations": 16, + "process_wall_seconds": 13.17322438400015, + "engine": "production", + "round": 0 + }, + { + "seconds": 13.127055758000097, + "digest": "96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523", + "events": 7843392, + "mutations": 16, + "process_wall_seconds": 13.164260651999939, + "engine": "production", + "round": 1 + }, + { + "seconds": 34.85047896600008, + "digest": "96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523", + "events": 7843392, + "mutations": 16, + "process_wall_seconds": 34.88503868299995, + "engine": "baseline", + "round": 1 + }, + { + "seconds": 34.952177340999924, + "digest": "96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523", + "events": 7843392, + "mutations": 16, + "process_wall_seconds": 34.9878793219998, + "engine": "baseline", + "round": 2 + }, + { + "seconds": 13.267512981999971, + "digest": "96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523", + "events": 7843392, + "mutations": 16, + "process_wall_seconds": 13.302686735999941, + "engine": "production", + "round": 2 + }, + { + "seconds": 13.291160422000075, + "digest": "96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523", + "events": 7843392, + "mutations": 16, + "process_wall_seconds": 13.32622714099989, + "engine": "production", + "round": 3 + }, + { + "seconds": 33.611441326999966, + "digest": "96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523", + "events": 7843392, + "mutations": 16, + "process_wall_seconds": 33.6484458729999, + "engine": "baseline", + "round": 3 + }, + { + "seconds": 34.87974892599982, + "digest": "96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523", + "events": 7843392, + "mutations": 16, + "process_wall_seconds": 34.916666276000115, + "engine": "baseline", + "round": 4 + }, + { + "seconds": 13.62449897800002, + "digest": "96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523", + "events": 7843392, + "mutations": 16, + "process_wall_seconds": 13.663707508000016, + "engine": "production", + "round": 4 + } + ], + "scope": "complete parameterized PR589 hosted audit including 16 mutants; no new kappa", + "measurement_note": "Host-descriptive paired medians; not a correctness gate or cold-replay claim." +} diff --git a/research/bit-hosted-digest-production/SOURCES.json b/research/bit-hosted-digest-production/SOURCES.json new file mode 100644 index 0000000000..99e615417d --- /dev/null +++ b/research/bit-hosted-digest-production/SOURCES.json @@ -0,0 +1,80 @@ +{ + "schema_version": 1, + "base_commit": "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2", + "files": [ + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "e8870e5917057d59b730eb14721a778639eca050", + "sha256": "d46eb6d5b3e279428753d770653663fbdf1063e55c255ea073d768f344927ef7" + }, + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "ae6a99f28aa468649eb66a361e764d769363bf11", + "sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32" + }, + { + "path": "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py", + "usage": "provenance", + "git_blob": "8864ca9b942a3507171edca0cf6cbaaf10fcf434", + "sha256": "57e558c80a2fea6e291587b04afd76dfaee3550729997798b61f33daf90b8ec9", + "note": "Pairwise-era production bytes at base_commit; working tree carries the fragment-reuse digest. Live equivalence uses package baseline.py plus working production path." + }, + { + "path": "research/e8-bit-p111-tuned/code/adapt9p.py", + "usage": "input", + "git_blob": "96bbc2ba9bb11984736e34db8b65c1a91e8f842e", + "sha256": "14365d0eb8f4a7352edd28816196148fd28d5bbcb36044ebeeb15ca051bca9de" + }, + { + "path": "research/bit-hosted-digest-fastpath/fast_digest.py", + "usage": "provenance", + "git_blob": "4a5d5f10d35d5d800d14e6548a6537a966517075", + "sha256": "3385ee86b1354d590dd976f816a2a2e34912bf7158fb5cf6e295f7466e3c54da", + "note": "Historical opt-in adapter; production wiring inlines the equivalent digest." + }, + { + "path": "research/community-hyperplane599-audit/pr589/bit589/v9/hosted/GLOBAL-TEMPLATE.json.gz", + "usage": "input", + "git_blob": "9eafb8776cbf78c72124f833534469ddfa5e98ec", + "sha256": "0357b7cfbd7c29b4983982baf153c8a9f1e1e412690cd7fa9fc3d23d7963b20f" + }, + { + "path": "research/community-hyperplane599-audit/pr589/bit589/v9/hosted/GLOBAL.json", + "usage": "input", + "git_blob": "1f648db9e63e7bfcaa6d5b1dd9fa6503caac47d2", + "sha256": "8de008a7978d4b7189cbec2470443619149a2b7b2f0f862540eeee4b23d3a819" + }, + { + "path": "research/community-hyperplane599-audit/pr589/bit589/v9/hosted/AUDIT.json", + "usage": "input", + "git_blob": "527ccbda9785fbffb65ffef9c61a2229830cdb5e", + "sha256": "390bea1d4122597a00ddb14430b61cb2a9b7f0193a3000bd0b9c454d8473aef7" + }, + { + "path": "research/community-hyperplane599-audit/pr589/bit589/v9/nine/GLOBAL-TEMPLATE.json.gz", + "usage": "input", + "git_blob": "78f2dea722f15570e99f2771fd2463dde601a598", + "sha256": "33c11914420e8812acbd2cf1db300685becc08e8174cbb1d5b20260b9c97af32" + }, + { + "path": "research/community-hyperplane599-audit/pr589/bit589/v9/nine/GLOBAL.json", + "usage": "input", + "git_blob": "993313e3ac570290ad5943c8709807d9e1bd8fbc", + "sha256": "549e3c68718b017b25f3f1237d095eb100d5918ddbe4076d52b11bd87c2f7a62" + }, + { + "path": "research/community-hyperplane599-audit/pr589/bit589/records/249-states.json", + "usage": "input", + "git_blob": "00aca549e1958d10dab9bbb9263448802489aa6d", + "sha256": "701ca802279b23ba23ffd502935ae9f34a33fc81fdfd266042f3208a2cb16265" + }, + { + "path": "research/community-hyperplane599-audit/pr589/bit589/records/frames.json", + "usage": "input", + "git_blob": "a9a932b9268da28af9ba4bccdab205c5bcd50ad3", + "sha256": "d006b3bfe0c04afecfea7aecfa59dfe4298b99501c70da3938e40289bc2f5010" + } + ] +} diff --git a/research/bit-hosted-digest-production/TASK.json b/research/bit-hosted-digest-production/TASK.json new file mode 100644 index 0000000000..f9a0ce9fdb --- /dev/null +++ b/research/bit-hosted-digest-production/TASK.json @@ -0,0 +1,70 @@ +{ + "schema_version": 1, + "task_id": "replay-runtime", + "priority_revision": 4, + "base_commit": "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2", + "chooser_seed": "e710597e02b4802b647e5b915460aebd", + "original_card": { + "id": "replay-runtime", + "question": "Can one measured replay bottleneck be sped up without dropping coverage?", + "starting_points": [ + "scripts/run_isolated_tests.py", + "scripts/verify_replay_coverage.py", + "certificates/selected-result.json" + ], + "methods": [ + "Profile one isolated replay and optimize the measured bottleneck.", + "Design source-bound reuse with explicit dependency invalidation and negative controls." + ], + "acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read the selected reproduction command and choose a single replay stage for profiling.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "first_experiment": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.", + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "allowed_variations": [ + "Profile one stage or design one source-bound cache boundary." + ], + "scope_change_triggers": [ + "Skipping coverage or comparing different fixtures to claim speedup." + ], + "overlap_terms": [ + "replay runtime", + "cache invalidation", + "isolated tests" + ] + }, + "scope_status": "refined", + "actual_scope": "Can the production p111-tuned audit_hosted_k.py digest used by adapt9p-parameterized PR589 hosted audits adopt the proved exact JSON-fragment reuse from research/bit-hosted-digest-fastpath/ so the shipped hosted-audit path is faster while every receipt field stays identical?", + "scope_change_reason": "The catalogue card asks for one measured replay bottleneck with before/after wall time and retained checks. Expertise override selected verifier-engineering after profiling leave-alone production rewrites and remaining proved opt-in adapters. Leave-alone objects (joint frames, shared-point, mixed-point, ternary, parity-side, R420 rref/geometry/mutants, frameopt.close, leech_minor, verify_factor, sparse-fusion, joint-dual replay, quadratic-affine for #1076, data_corners #2320, clifford_exact #2329, e8-bit-r420 MANIFEST-only edits) were skipped. Reclaim-order and cyclic-routing are already on the shipped path. Matthieu Pascal's merged #1874 opt-in adapter already proved ~2.50× on the complete PR589 hosted audit with identical receipts; production audit_hosted_k.py still used per-instruction json.dumps. This session wires that equivalent digest into the shipped p111-tuned source, preserves adapt9p anchors, and refreshes or demotes dependent VERIFY pins.", + "bottleneck_link": "Side result on review throughput: parameterized hosted-owner audits appear in bit-supplier tooling. A faster identical receipt does not change kappa or the binding complex supplier.", + "budget_minutes": 60, + "stop_rule": "Ship an equivalence-preserving production audit_hosted_k.py digest change with frozen baseline, identical hosted-audit receipts, corruption controls, pin discipline, registered replay and a measured before/after median. Do not invent kappa or reopen leave-alone objects.", + "outcome": "completed", + "evidence": "PASS_BIT_HOSTED_DIGEST_PRODUCTION via research/bit-hosted-digest-production/verify.py (also under -O); PASS_REGISTERED_RESEARCH_PACKAGE; PASS_IDENTICAL_BIT_HOSTED_DIGEST_PRODUCTION_RECEIPTS via pinned-CPU benchmark.py --rounds 5 (median 34.880→13.268 s, 2.629×); bit589-width7-windows-seed72 / selected-bit-hosting-audit / r439-abc-hosted-invoice demote the audit_hosted_k live pin to provenance; bit-hosted-digest-fastpath demotes the production path and compares against baseline.py.", + "author": "Wentao Li", + "github": "VictorLiwentao", + "email": "wentaol4@illinois.edu", + "ai_assistance": "Substantial AI assistance for orientation, overlap search, profiling, production wiring, packaging, benchmarking and writing. Not independent human peer review.", + "open_questions": [ + { + "question": "Should the other byte-identical vendored audit_hosted_k.py copies under research/*/vendor/ adopt the same fragment-reuse digest in a follow-up tip?", + "why_it_matters": "Those trees still pin pairwise-era digests; a coordinated refresh would remove stale inventory digests without changing receipts.", + "first_step": "Diff each copy against the production transform site and list which SOURCE inventories would need provenance demotion or honest refresh.", + "blocked_by": "Out of this session's one-object stop rule." + }, + { + "question": "Should active bit-hosting drivers prefer the production digest path in their documented reproduce commands?", + "why_it_matters": "Some notes still point at the opt-in fast_digest.py entrypoint.", + "first_step": "List drivers that still shell out to research/bit-hosted-digest-fastpath/run paths.", + "blocked_by": "Maintainer documentation preference." + } + ] +} diff --git a/research/bit-hosted-digest-production/VERIFY.json b/research/bit-hosted-digest-production/VERIFY.json new file mode 100644 index 0000000000..b86c6c55c0 --- /dev/null +++ b/research/bit-hosted-digest-production/VERIFY.json @@ -0,0 +1,30 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/bit-hosted-digest-production/baseline.py", + "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py", + "research/e8-bit-p111-tuned/code/adapt9p.py", + "research/community-hyperplane599-audit/pr589/bit589/v9/hosted/GLOBAL-TEMPLATE.json.gz", + "research/community-hyperplane599-audit/pr589/bit589/v9/hosted/GLOBAL.json", + "research/community-hyperplane599-audit/pr589/bit589/v9/hosted/AUDIT.json", + "research/community-hyperplane599-audit/pr589/bit589/v9/nine/GLOBAL-TEMPLATE.json.gz", + "research/community-hyperplane599-audit/pr589/bit589/v9/nine/GLOBAL.json", + "research/community-hyperplane599-audit/pr589/bit589/records/249-states.json", + "research/community-hyperplane599-audit/pr589/bit589/records/frames.json" + ], + "commands": [ + { + "argv": ["{python}", "-I", "-B", "{package}/verify.py"], + "timeout_seconds": 300, + "checks": "Exact baseline copy of the base-commit audit_hosted_k.py; production equals the fragment-reuse transform; identical parameterized hosted-audit receipts; temp-copy digest foil corruption control; duplicate JSON-key check; read-only default; adapt9p anchors preserved." + }, + { + "argv": ["{python}", "-I", "-O", "-B", "{package}/verify.py"], + "timeout_seconds": 300, + "checks": "Same equivalence and pin discipline under -O (package re-executes an asserting child without PYTHONOPTIMIZE for the inherited auditor body)." + } + ] +} diff --git a/research/bit-hosted-digest-production/baseline.py b/research/bit-hosted-digest-production/baseline.py new file mode 100644 index 0000000000..8864ca9b94 --- /dev/null +++ b/research/bit-hosted-digest-production/baseline.py @@ -0,0 +1,157 @@ +# Independent ownership/window audit, extending DaysSky PR442 and chafreaky PR444 (OpenAI Codex); no generator imports. +# Generalised to an arbitrary odd stage count, any replica count and host-every-residual templates by DreamingOfClouds with +# Claude Opus 5.5 (Anthropic), via Claude Code. Apache-2.0. +"""Independent ownership/window audit of an idle-axis-hosted compressed S-stage bit template. +Usage: audit_hosted_k.py PARENT_DIR HOSTED_DIR OUT.json +PARENT_DIR holds the parent's records/ and nine/-style GLOBAL files via --parent-nine (default PARENT_DIR/nine). +At the nine-stage defaults this performs PR #444's checks and fourteen mutations; at S = 11 the mutations that need a +bank are replaced by stage-count, window and exterior-coordinate controls.""" +import copy, gzip, hashlib, json, sys +from collections import Counter, defaultdict +from pathlib import Path +V=120 +read=lambda p:json.loads(Path(p).read_text()) +template=lambda p:json.loads(gzip.decompress(Path(p).read_bytes())) + +def windows(schedule): + last={}; seen=[]; win={}; rank={}; pair={} + for pos,e in enumerate(schedule): + if e['kind']=='local_cover_sweep': + seen.append((pos,e['stage'],e['pair']));last[e['pair']]=pos + elif e['kind']=='bridge': + last[e['dst']]=pos;last[e['src']]=pos + elif e['kind']=='exchange': + assert pos==len(schedule)-1 + else: + assert e['kind']=='idle' + i=e['idx'];assert i not in win + win[i]={s for q,s,p in seen if last.get(e['pair'],-1)=5 and L%2==1 and M==1+7*L + mutable={'version','live','banks_per_stage','hosting','helper_route','calls','schedule'} + assert set(t)==set(parent)|{'hosting'} + assert {k:v for k,v in t.items() if k not in mutable}=={k:v for k,v in parent.items() if k not in mutable} + assert t['replicas']==T and t['m']==M and t['private_centre_reserve']==9 + sched=copy.deepcopy(parent['schedule']);idx=0 + for e in sched: + if e['kind']=='idle':e['idx']=idx;idx+=1 + assert t['schedule']==sched + W,rank,pair=windows(t['schedule']);hs=t['hosting'] + assert hs['windows']=={str(i):[pair[i],rank[i],sorted(W[i])] for i in W if rank[i]>0 and W[i]} + used=defaultdict(set);hosted={} + for i,cp,off,w,s,h in hs['slots']: + assert i in W and s in W[i] and 0<=s0 and 0<=off and off+w<=rank[i] + cells=set(range(off,off+w));assert not cells & used[i,cp];used[i,cp]|=cells + assert (s,h) not in hosted;hosted[s,h]=(i,cp,off,w) + rem={};summaries={} + for i in rank: + if not rank[i]:continue + for cp in range(2*V):rem[i,cp]=rank[i]-len(used[i,cp]) + if str(i) in hs['windows']: + summaries[str(i)]={str(r):n for r,n in sorted(Counter(rem[i,cp] for cp in range(2*V)).items())} + assert hs['remainders']==summaries + banks={int(s):n for s,n in hs['banks_per_stage'].items()} + assert set(banks)==set(range(L)) and all(isinstance(n,int) and n>=0 for n in banks.values()) + assert {int(s):n for s,n in t['banks_per_stage'].items()}==banks + base={};end=DATA + for s in range(L):base[s]=end;end+=banks[s] + assert t['live']==end + assert len(t['calls'])==L*T and len(parent['calls'])==L*T + occ=defaultdict(set);bank_count=0;host_count=0 + assert {(c['stage'],c['replica']) for c in t['calls']}=={(s,r) for s in range(L) for r in range(T)} + for c,pc in zip(t['calls'],parent['calls']): + assert {k:v for k,v in c.items() if k!='owners'}=={k:v for k,v in pc.items() if k!='owners'} + s,rep,p=c['stage'],c['replica'],c['pair'];own=c['owners'] + assert len(own)==2*V+R and own[:2*V]==pc['owners'][:2*V] + for h,(f,r) in enumerate(own[2*V:]): + if (s,h) in hosted: + i,cp,off,w=hosted[s,h];side,port=divmod(cp,V) + assert r==['hosted',i,off,w] and f==rep*(2*K*V)+(2*pair[i]+side)*V+port + assert pair[i]!=p and 0<=f2*max(paid)**depth + return paid,host_count,bank_count + +def digest(t): + # Independent streamed hashing uses the same specified JSON instruction format. + h=hashlib.sha256();n=0;R=len(t['calls'][0]['owners'])-2*V + for call in t['calls']: + for z in t['local_programs'][call['orientation']]: + x=[z[0],call['owners'][z[1]]] + if z[0]==0:x.extend(z[2:]) + else: + x.append(call['owners'][z[2]] if z[2]<2*V+R else [t['live'],['private',0]]) + x.extend(z[3:]) + h.update(json.dumps(x,separators=(',',':')).encode());h.update(b'\n');n+=1 + return h.hexdigest(),n + +def main(): + par,bd,out=map(Path,sys.argv[1:4]);pt=template(par/'nine/GLOBAL-TEMPLATE.json.gz') + t=template(bd/'GLOBAL-TEMPLATE.json.gz');g=read(bd/'GLOBAL.json');pg=read(par/'nine/GLOBAL.json') + st=read(par/'records/249-states.json');frames=read(par/'records/frames.json')['frames'] + L=t['stages'];T=t['replicas'];M=t['m'];K=(L-1)//2;R=pg['R'];depth=g['halving_depth'];DATA=2*K*V*T + widths=[8-frames[str(st['initial'][str(h)])]['dim'] for h in range(2*V,2*V+R)] + P,host,bank=audit(t,pt,widths,depth) + th=hashlib.sha256(gzip.decompress((bd/'GLOBAL-TEMPLATE.json.gz').read_bytes())).hexdigest() + assert th==g['template_sha256'] and g['parent_template_sha256']==pg['template_sha256'] + assert P==Counter({int(r):n for r,n in g['profile'].items()}) + DEFICIT=T*(2*K*V-9*8*L) + assert (g['live'],g['physical'],g['rank_mass'],g['deficit'],g['paid_calls'],g['maxchild'])==(t['live'],t['live']+9,sum(r*n for r,n in P.items()),DEFICIT,sum(P.values()),max(P)) + assert g['hosted_residuals']==host and g['bank_assignments']==bank + dg,n=digest(t);assert dg==g['emitted_program_sha256'] and n==g['emitted_events']==pg['emitted_events'] + assert dg!=pg['emitted_program_sha256'] + controls=[] + def reject(name,fn): + q=copy.deepcopy(t);fn(q) + try:audit(q,pt,widths,depth) + except (AssertionError,KeyError,IndexError,TypeError):controls.append(name) + else:raise AssertionError('accepted '+name) + def owner(q,kind): + return next(o for c in q['calls'] for o in c['owners'][2*V:] if o[1][0]==kind) + Wd,rk,pr=windows(t['schedule']) + def outside_stage(q): + i,cp,off,w,s,h=q['hosting']['slots'][0]; q['hosting']['slots'][0][4]=next(x for x in range(L) if x not in Wd[i]) + reject('slot outside window',outside_stage) + reject('copy index outside family',lambda q:q['hosting']['slots'][0].__setitem__(1,2*V)) + reject('negative slot offset',lambda q:q['hosting']['slots'][0].__setitem__(2,-1)) + reject('wrong residual width',lambda q:q['hosting']['slots'][0].__setitem__(3,1+q['hosting']['slots'][0][3])) + reject('duplicate helper',lambda q:q['hosting']['slots'].append(q['hosting']['slots'][0])) + reject('omitted helper',lambda q:q['hosting']['slots'].pop()) + reject('hosted owner in another replica or outside the data stock',lambda q:owner(q,'hosted').__setitem__(0,owner(q,'hosted')[0]+2*K*V)) + reject('hosted owner on a wrong data family',lambda q:owner(q,'hosted').__setitem__(0,q['calls'][0]['owners'][0][0])) + if bank: + reject('wrong bank slot',lambda q:owner(q,'bank')[1].__setitem__(1,M)) + reject('wrong bank stage',lambda q:owner(q,'bank').__setitem__(0,t['live']-1)) + reject('wrong call orientation',lambda q:q['calls'][0].__setitem__('orientation','reverse')) + reject('duplicate call',lambda q:q['calls'].__setitem__(1,q['calls'][0])) + reject('changed idle rank',lambda q:next(e for e in q['schedule'] if e['kind']=='idle').__setitem__('rank',1)) + reject('understated live stock',lambda q:q.__setitem__('live',q['live']-1)) + reject('missing remainder summary',lambda q:q['hosting']['remainders'].pop(next(iter(q['hosting']['remainders'])))) + reject('stale stage count',lambda q:q.__setitem__('stages',L-2)) + reject('hosted coordinate beyond the pending set',lambda q:q['hosting']['slots'][0].__setitem__(2,rk[q['hosting']['slots'][0][0]])) + reject('overlapping hosted coordinates',lambda q:q['hosting']['slots'].append(q['hosting']['slots'][0][:5]+[(q['hosting']['slots'][0][5]+1)%R])) + res=dict(status='PASS_INDEPENDENT_REPLICATED_HOSTING_AUDIT',template_sha256=th,emitted_program_sha256=dg,emitted_events=n, + profile={str(r):z for r,z in sorted(P.items())},live=t['live'],physical=t['live']+9,hosted_residuals=host, + bank_assignments=bank,rank_mass=sum(r*n for r,n in P.items()),deficit=DEFICIT,maxchild=max(P),mutations_rejected=controls) + out.write_text(json.dumps(res,indent=2)+'\n');print(json.dumps(res)) +if __name__=='__main__':main() diff --git a/research/bit-hosted-digest-production/benchmark.py b/research/bit-hosted-digest-production/benchmark.py new file mode 100644 index 0000000000..d503471593 --- /dev/null +++ b/research/bit-hosted-digest-production/benchmark.py @@ -0,0 +1,188 @@ +#!/usr/bin/env python3 +"""Alternating fresh-process hosted-audit timings for production digest. + +Timing is host-descriptive and is not a correctness gate. +""" +from __future__ import annotations + +import argparse +import json +import os +from pathlib import Path +import platform +import statistics +import subprocess +import sys +import tempfile +import time + +ROOT = Path(__file__).resolve().parents[2] +PACKAGE = Path(__file__).resolve().parent +PRODUCTION = ( + ROOT + / "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage" + / "vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py" +) +FIXTURE = ROOT / "research/community-hyperplane599-audit/pr589/bit589" +EMITTED = "96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523" + +WORKER = r''' +import contextlib, gzip, hashlib, io, json, sys, time, types, ast +from pathlib import Path + +ROOT = Path(sys.argv[1]) +SOURCE = Path(sys.argv[2]) +PARENT = Path(sys.argv[3]) +HOSTED = Path(sys.argv[4]) +OUT = Path(sys.argv[5]) +PARAMETERIZER = ROOT / "research/e8-bit-p111-tuned/code/adapt9p.py" + +def load_parameterized(source_path): + original = source_path.read_text(encoding="utf-8") + adapter = PARAMETERIZER.read_text(encoding="utf-8") + assignments = [n for n in ast.parse(adapter).body if isinstance(n, ast.Assign) + and any(isinstance(t, ast.Name) and t.id == "EDITS" for t in n.targets)] + edits_dict = assignments[0].value + entries = [v for k, v in zip(edits_dict.keys, edits_dict.values) + if ast.literal_eval(k) == "audit_hosted_k.py"] + edits = ast.literal_eval(entries[0].elts[1]) + for old, new in edits: + assert original.count(old) == 1 + original = original.replace(old, new) + module = types.ModuleType("auditor") + module.__file__ = str(source_path) + exec(compile(original, module.__file__, "exec"), module.__dict__) + return module + +auditor = load_parameterized(SOURCE) +argv = sys.argv +sys.argv = [auditor.__file__, str(PARENT), str(HOSTED), str(OUT)] +start = time.perf_counter() +with contextlib.redirect_stdout(io.StringIO()): + auditor.main() +elapsed = time.perf_counter() - start +sys.argv = argv +receipt = json.loads(OUT.read_text(encoding="utf-8")) +assert receipt["emitted_program_sha256"] == %r +print(json.dumps({"seconds": elapsed, "digest": receipt["emitted_program_sha256"], + "events": receipt["emitted_events"], + "mutations": len(receipt["mutations_rejected"])})) +''' % EMITTED + + +def require(ok, message): + if not ok: + raise ValueError(message) + + +def run_once(engine: str, parent: Path, out: Path) -> dict: + source = PACKAGE / "baseline.py" if engine == "baseline" else PRODUCTION + cmd = [ + sys.executable, + "-I", + "-B", + "-c", + WORKER, + str(ROOT), + str(source), + str(parent), + str(FIXTURE / "v9/hosted"), + str(out), + ] + env = os.environ.copy() + env.pop("PYTHONOPTIMIZE", None) + # Optional single-CPU pin when taskset exists. + wrapper = [] + if Path("/usr/bin/taskset").exists(): + wrapper = ["taskset", "-c", "0"] + start = time.perf_counter() + proc = subprocess.run(wrapper + cmd, cwd=ROOT, capture_output=True, text=True, env=env, check=False) + wall = time.perf_counter() - start + require(proc.returncode == 0, f"{engine} failed: {proc.stdout}\n{proc.stderr}") + payload = json.loads(proc.stdout.strip().splitlines()[-1]) + payload["process_wall_seconds"] = wall + payload["engine"] = engine + return payload + + +def prepare_parent(work: Path) -> Path: + import shutil + + parent = work / "parent" + shutil.copytree( + FIXTURE / "v9/nine", + parent / "nine", + ignore=shutil.ignore_patterns("AUDIT.json", "GEOMETRY.json"), + ) + shutil.copytree(FIXTURE / "records", parent / "records") + return parent + + +def main(argv=None) -> int: + parser = argparse.ArgumentParser() + parser.add_argument("--rounds", type=int, default=5) + parser.add_argument("--write-result", action="store_true") + args = parser.parse_args(argv) + require(args.rounds > 0, "rounds must be positive") + + samples = [] + with tempfile.TemporaryDirectory(prefix="bit-hosted-digest-bench-") as tmp: + work = Path(tmp) + parent = prepare_parent(work) + order = [] + for round_index in range(args.rounds): + # Alternate starting engine each round. + engines = ("baseline", "production") if round_index % 2 == 0 else ("production", "baseline") + order.append(list(engines)) + for engine in engines: + out = work / f"{round_index}-{engine}.json" + sample = run_once(engine, parent, out) + sample["round"] = round_index + samples.append(sample) + print( + f"round={round_index} engine={engine} " + f"audit={sample['seconds']:.6f}s wall={sample['process_wall_seconds']:.6f}s", + flush=True, + ) + + by_engine = { + "baseline": [s["seconds"] for s in samples if s["engine"] == "baseline"], + "production": [s["seconds"] for s in samples if s["engine"] == "production"], + } + med_base = statistics.median(by_engine["baseline"]) + med_prod = statistics.median(by_engine["production"]) + speedup = med_base / med_prod + for sample in samples: + require(sample["digest"] == EMITTED, "timed receipt digest drifted") + require(sample["events"] == 7843392, "timed receipt events drifted") + require(sample["mutations"] == 16, "timed receipt mutations drifted") + + result = { + "status": "PASS_IDENTICAL_BIT_HOSTED_DIGEST_PRODUCTION_RECEIPTS", + "base_commit": "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2", + "python": platform.python_version(), + "platform": platform.platform(), + "executable": sys.executable, + "rounds": args.rounds, + "alternating_order": order, + "median_audit_seconds": {"baseline": med_base, "production": med_prod}, + "median_speedup": speedup, + "emitted_program_sha256": EMITTED, + "emitted_events": 7843392, + "samples": samples, + "scope": "complete parameterized PR589 hosted audit including 16 mutants; no new kappa", + "measurement_note": "Host-descriptive paired medians; not a correctness gate or cold-replay claim.", + } + text = json.dumps(result, indent=2) + "\n" + if args.write_result: + (PACKAGE / "RESULT.json").write_text(text, encoding="utf-8") + print(text) + print( + f"PASS_IDENTICAL_BIT_HOSTED_DIGEST_PRODUCTION_RECEIPTS " + f"median {med_base:.6f} → {med_prod:.6f} s ({speedup:.3f}×)" + ) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/research/bit-hosted-digest-production/verify.py b/research/bit-hosted-digest-production/verify.py new file mode 100644 index 0000000000..de0fb4bbef --- /dev/null +++ b/research/bit-hosted-digest-production/verify.py @@ -0,0 +1,292 @@ +#!/usr/bin/env python3 +"""Equivalence, pin and rejection controls for production hosted digest. + +Read-only by default. Timing is not a pass gate; see benchmark.py / RESULT.json. +""" +from __future__ import annotations + +import argparse +import ast +import contextlib +import gzip +import hashlib +import io +import json +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import types + +ROOT = Path(__file__).resolve().parents[2] +PACKAGE = Path(__file__).resolve().parent +PRODUCTION = ( + ROOT + / "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage" + / "vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py" +) +PARAMETERIZER = ROOT / "research/e8-bit-p111-tuned/code/adapt9p.py" +FIXTURE = ROOT / "research/community-hyperplane599-audit/pr589/bit589" +RETAINED_AUDIT = FIXTURE / "v9/hosted/AUDIT.json" + +BASE_COMMIT = "0fdd7d82de03e43c9e5a1000dfbcd380d1b687d2" +ORIGINAL_BLOB = "8864ca9b942a3507171edca0cf6cbaaf10fcf434" +ORIGINAL_SHA256 = "57e558c80a2fea6e291587b04afd76dfaee3550729997798b61f33daf90b8ec9" +PRODUCTION_SHA256 = "9d0b44e37109128850192414bf0fefb1048bf96da2c78dff8e833980b20f61c7" +PRODUCTION_BLOB = "fefec67382782e2624016545f770f95b03cc5da5" +EMITTED_PROGRAM_SHA256 = "96c7ad2e744e9a503a4ef5ecd52d0f6a8899bdb5efac2e3aafa0db18adf99523" +EMITTED_EVENTS = 7843392 +PARAMETERIZER_SHA256 = "14365d0eb8f4a7352edd28816196148fd28d5bbcb36044ebeeb15ca051bca9de" + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def digest_file(path: Path) -> str: + return hashlib.sha256(path.read_bytes()).hexdigest() + + +def unique_object(pairs): + out = {} + for key, value in pairs: + require(key not in out, f"duplicate JSON key: {key}") + out[key] = value + return out + + +def load_json_unique(path: Path): + return json.loads(path.read_text(encoding="utf-8"), object_pairs_hook=unique_object) + + +def old_digest_block() -> str: + baseline = (PACKAGE / "baseline.py").read_text(encoding="utf-8") + marker = "def digest(t):" + start = baseline.index(marker) + end = baseline.index("def main():", start) + return baseline[start:end] + + +def new_digest_block() -> str: + production = PRODUCTION.read_text(encoding="utf-8") + marker = "def _enc(value):" + start = production.index(marker) + end = production.index("def main():", start) + return production[start:end] + + +def transform(source: str) -> str: + old = old_digest_block() + new = new_digest_block() + require(source.count(old) == 1, "expected exactly one pairwise digest block in baseline") + return source.replace(old, new) + + +def check_baseline_bytes() -> bytes: + original = subprocess.check_output( + ["git", "show", f"{BASE_COMMIT}:research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py"], + cwd=ROOT, + ) + require(digest_file_bytes(original) == ORIGINAL_SHA256, "base audit_hosted_k.py sha256 drift") + require( + subprocess.check_output( + [ + "git", + "rev-parse", + f"{BASE_COMMIT}:research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py", + ], + cwd=ROOT, + ) + .decode() + .strip() + == ORIGINAL_BLOB, + "base audit_hosted_k.py blob drift", + ) + require( + (PACKAGE / "baseline.py").read_bytes() == original, + "baseline.py must be an exact copy of the base-commit source", + ) + return original + + +def digest_file_bytes(data: bytes) -> str: + return hashlib.sha256(data).hexdigest() + + +def check_production_transform(original: bytes) -> str: + production = PRODUCTION.read_text(encoding="utf-8") + expected = transform(original.decode("utf-8")) + require(production == expected, "production audit_hosted_k.py != transform(baseline)") + require(digest_file(PRODUCTION) == PRODUCTION_SHA256, "production sha256 drift") + require("_enc" in production and "fragment reuse" in production, "fragment digest markers missing") + require("Independent streamed hashing uses the same specified JSON" not in production, + "pairwise digest comment still present") + require(production.count("def digest(t):") == 1, "digest definition count") + return production + + +def load_parameterized(source_path: Path): + """Apply the five hosted-auditor adapt9p edits to a source file.""" + require(digest_file(PARAMETERIZER) == PARAMETERIZER_SHA256, "adapt9p.py sha256 drift") + original = source_path.read_text(encoding="utf-8") + adapter = PARAMETERIZER.read_text(encoding="utf-8") + assignments = [ + n + for n in ast.parse(adapter).body + if isinstance(n, ast.Assign) + and any(isinstance(t, ast.Name) and t.id == "EDITS" for t in n.targets) + ] + require(len(assignments) == 1, "expected one EDITS dictionary") + edits_dict = assignments[0].value + entries = [ + v + for k, v in zip(edits_dict.keys, edits_dict.values) + if ast.literal_eval(k) == "audit_hosted_k.py" + ] + require(len(entries) == 1, "expected one hosted-auditor edit list") + edits = ast.literal_eval(entries[0].elts[1]) + require(len(edits) == 5, "expected five parameterization edits") + for old, new in edits: + require(original.count(old) == 1, "parameterization anchor mismatch") + original = original.replace(old, new) + module = types.ModuleType("pinned_hosted_auditor") + module.__file__ = str(source_path) + # Assertions in the inherited auditor remain proof-relevant. + code = compile(original, module.__file__, "exec") + exec(code, module.__dict__) + return module + + +def prepare_parent(work: Path) -> Path: + parent = work / "parent" + shutil.copytree( + FIXTURE / "v9/nine", + parent / "nine", + ignore=shutil.ignore_patterns("AUDIT.json", "GEOMETRY.json"), + ) + shutil.copytree(FIXTURE / "records", parent / "records") + return parent + + +def run_audit(auditor, parent: Path, hosted: Path, output: Path) -> dict: + argv = sys.argv + try: + sys.argv = [auditor.__file__, str(parent), str(hosted), str(output)] + with contextlib.redirect_stdout(io.StringIO()): + auditor.main() + finally: + sys.argv = argv + return load_json_unique(output) + + +def check_receipt_equivalence() -> dict: + retained = load_json_unique(RETAINED_AUDIT) + require(retained["emitted_program_sha256"] == EMITTED_PROGRAM_SHA256, "retained digest drift") + require(retained["emitted_events"] == EMITTED_EVENTS, "retained event count drift") + with tempfile.TemporaryDirectory(prefix="bit-hosted-digest-production-") as tmp: + work = Path(tmp) + parent = prepare_parent(work) + hosted = FIXTURE / "v9/hosted" + baseline_mod = load_parameterized(PACKAGE / "baseline.py") + production_mod = load_parameterized(PRODUCTION) + # adapt9p leaves V=None until main(); pairwise digest still reads module V. + parent_v = load_json_unique(parent / "nine" / "GLOBAL.json")["v"] + baseline_mod.V = parent_v + production_mod.V = parent_v + template = json.loads(gzip.decompress((hosted / "GLOBAL-TEMPLATE.json.gz").read_bytes())) + require(baseline_mod.digest(template) == production_mod.digest(template), "digest tuple mismatch") + require(production_mod.digest(template) == (EMITTED_PROGRAM_SHA256, EMITTED_EVENTS), + "production digest != retained") + base_receipt = run_audit(baseline_mod, parent, hosted, work / "baseline.json") + prod_receipt = run_audit(production_mod, parent, hosted, work / "production.json") + require(base_receipt == prod_receipt == retained, "full hosted audit receipt mismatch") + require( + (work / "baseline.json").read_bytes() == (work / "production.json").read_bytes(), + "audit JSON output bytes differ", + ) + require(len(prod_receipt["mutations_rejected"]) == 16, "inherited mutation coverage changed") + return { + "emitted_program_sha256": prod_receipt["emitted_program_sha256"], + "emitted_events": prod_receipt["emitted_events"], + "mutations_rejected": prod_receipt["mutations_rejected"], + } + + +def check_corruption_rejection() -> str: + """Temp-copy foil: permute a digest fragment so receipts diverge or the audit fails.""" + with tempfile.TemporaryDirectory(prefix="bit-hosted-digest-corrupt-") as tmp: + work = Path(tmp) + corrupt = work / "audit_hosted_k.py" + text = PRODUCTION.read_text(encoding="utf-8") + foil = "pending.extend(owners[destination])" + require(text.count(foil) == 1, "corruption foil site missing") + # Drop the destination owner fragment: changes the emitted stream. + corrupt.write_text(text.replace(foil, "pending.extend(b'') # foil"), encoding="utf-8") + parent = prepare_parent(work) + hosted = FIXTURE / "v9/hosted" + module = load_parameterized(corrupt) + template = json.loads(gzip.decompress((hosted / "GLOBAL-TEMPLATE.json.gz").read_bytes())) + digest_hex, events = module.digest(template) + require(digest_hex != EMITTED_PROGRAM_SHA256, "corruption foil left digest unchanged") + require(events == EMITTED_EVENTS, "corruption foil changed event count unexpectedly") + try: + run_audit(module, parent, hosted, work / "corrupt.json") + except (AssertionError, ValueError, subprocess.CalledProcessError): + return "audit_assertion" + # If main somehow returned, the receipt must still disagree. + receipt = load_json_unique(work / "corrupt.json") + require(receipt.get("emitted_program_sha256") != EMITTED_PROGRAM_SHA256, + "corruption foil produced retained digest") + return "receipt_mismatch" + + +def check_adapt9p_anchors(production: str) -> None: + anchors = [ + "V=120\n", + "DATA=2*K*V*T; DEFICIT=T*(2*K*V-9*8*L)", + "def main():\n par,bd,out=", + " t=template(bd/'GLOBAL-TEMPLATE.json.gz');g=read(bd/'GLOBAL.json');pg=read(par/'nine/GLOBAL.json')\n", + " DEFICIT=T*(2*K*V-9*8*L)\n", + ] + for anchor in anchors: + require(production.count(anchor) == 1, "adapt9p anchor not unique: " + repr(anchor[:48])) + + +def main(argv=None) -> int: + parser = argparse.ArgumentParser() + parser.add_argument("--write-result", action="store_true", help="unused; verify is read-only") + args = parser.parse_args(argv) + require(not args.write_result, "verify.py is read-only; use benchmark.py --write-result") + # Clear any inherited optimize flag for child semantics documentation. + os.environ.pop("PYTHONOPTIMIZE", None) + + original = check_baseline_bytes() + production = check_production_transform(original) + check_adapt9p_anchors(production) + receipt = check_receipt_equivalence() + corruption = check_corruption_rejection() + # Duplicate-key check already applied to retained/production receipts. + load_json_unique(RETAINED_AUDIT) + + print( + "PASS_BIT_HOSTED_DIGEST_PRODUCTION " + f"events={receipt['emitted_events']} " + f"digest={receipt['emitted_program_sha256'][:16]}… " + f"mutations={len(receipt['mutations_rejected'])} " + f"corruption={corruption} " + "certs=1 no_new_kappa" + ) + return 0 + + +if __name__ == "__main__": + # Under -O, re-exec an asserting child for the inherited auditor body. + if not __debug__: + proc = subprocess.run( + [sys.executable, "-I", "-B", str(Path(__file__).resolve()), *sys.argv[1:]], + cwd=ROOT, + ) + raise SystemExit(proc.returncode) + raise SystemExit(main()) diff --git a/research/bit589-width7-windows-seed72/SOURCES.json b/research/bit589-width7-windows-seed72/SOURCES.json index 2d84eb3a01..fa89c56e09 100644 --- a/research/bit589-width7-windows-seed72/SOURCES.json +++ b/research/bit589-width7-windows-seed72/SOURCES.json @@ -58,9 +58,10 @@ }, { "path": "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py", - "usage": "input", + "usage": "provenance", "git_blob": "8864ca9b942a3507171edca0cf6cbaaf10fcf434", - "sha256": "57e558c80a2fea6e291587b04afd76dfaee3550729997798b61f33daf90b8ec9" + "sha256": "57e558c80a2fea6e291587b04afd76dfaee3550729997798b61f33daf90b8ec9", + "note": "Pairwise-era digest retained as provenance after research/bit-hosted-digest-production/; working tree ships fragment-reuse. Not a live VERIFY pin." }, { "path": "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/global_k.py", diff --git a/research/bit589-width7-windows-seed72/VERIFY.json b/research/bit589-width7-windows-seed72/VERIFY.json index 5899054462..6c0e6146de 100644 --- a/research/bit589-width7-windows-seed72/VERIFY.json +++ b/research/bit589-width7-windows-seed72/VERIFY.json @@ -12,7 +12,6 @@ "research/community-frontier1094-audit/ASSEMBLY.json", "research/e8-bit-p111-tuned/data/selection9-p111.json", "research/e8-bit-p111-tuned/tune/EXPECTED.json", - "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py", "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/global_k.py", "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/idle-axis-hosting/hosting_core.py", "research/native-complex-moment552/engines/base_two_moment.py", diff --git a/research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py b/research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py index 8864ca9b94..fefec67382 100644 --- a/research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py +++ b/research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py @@ -92,17 +92,32 @@ def audit(t,parent,widths,depth): assert M**depth>2*max(paid)**depth return paid,host_count,bank_count +def _enc(value): + return json.dumps(value,separators=(',',':')).encode() + def digest(t): - # Independent streamed hashing uses the same specified JSON instruction format. - h=hashlib.sha256();n=0;R=len(t['calls'][0]['owners'])-2*V + # Exact fragment reuse within one invocation (research/bit-hosted-digest-fastpath/); + # identical emitted JSON lines and SHA-256. No persistent cache across calls. + h=hashlib.sha256();n=0;limit=len(t['calls'][0]['owners']);private=_enc([t['live'],['private',0]]) + programs={};pending=bytearray();chunk=1024*1024 for call in t['calls']: - for z in t['local_programs'][call['orientation']]: - x=[z[0],call['owners'][z[1]]] - if z[0]==0:x.extend(z[2:]) - else: - x.append(call['owners'][z[2]] if z[2]<2*V+R else [t['live'],['private',0]]) - x.extend(z[3:]) - h.update(json.dumps(x,separators=(',',':')).encode());h.update(b'\n');n+=1 + orientation=call['orientation'] + if orientation not in programs: + instructions=[] + for z in t['local_programs'][orientation]: + tail=_enc(z[2:] if z[0]==0 else z[3:])[1:-1] + suffix=(b','+tail if tail else b'')+b']\n' + instructions.append((b'['+_enc(z[0])+b',',z[1],z[0]!=0,None if z[0]==0 else z[2],suffix)) + programs[orientation]=instructions + owners=[_enc(owner) for owner in call['owners']] + for prefix,destination,has_source,source,suffix in programs[orientation]: + pending.extend(prefix);pending.extend(owners[destination]) + if has_source: + pending.extend(b',');pending.extend(owners[source] if source=chunk: + h.update(pending);pending.clear() + if pending:h.update(pending) return h.hexdigest(),n def main(): diff --git a/research/r439-abc-hosted-invoice/SOURCES.json b/research/r439-abc-hosted-invoice/SOURCES.json index 0b2a99b5f0..ed822d7567 100644 --- a/research/r439-abc-hosted-invoice/SOURCES.json +++ b/research/r439-abc-hosted-invoice/SOURCES.json @@ -196,9 +196,10 @@ }, { "path": "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py", - "usage": "input", + "usage": "provenance", "git_blob": "8864ca9b942a3507171edca0cf6cbaaf10fcf434", - "sha256": "57e558c80a2fea6e291587b04afd76dfaee3550729997798b61f33daf90b8ec9" + "sha256": "57e558c80a2fea6e291587b04afd76dfaee3550729997798b61f33daf90b8ec9", + "note": "Pairwise-era digest retained as provenance after research/bit-hosted-digest-production/; working tree ships fragment-reuse. Not a live VERIFY pin." }, { "path": "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_parent_k.py", diff --git a/research/r439-abc-hosted-invoice/VERIFY.json b/research/r439-abc-hosted-invoice/VERIFY.json index 9e27f59c13..fc43d576fc 100644 --- a/research/r439-abc-hosted-invoice/VERIFY.json +++ b/research/r439-abc-hosted-invoice/VERIFY.json @@ -38,7 +38,6 @@ "research/e8-bit-p111-tuned/tune/verify.sh", "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/code/adapt.py", "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/code/assemble9.py", - "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py", "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_parent_k.py", "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/bank_routes_k.py", "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/emit_k.py", diff --git a/research/selected-bit-hosting-audit/SOURCES.json b/research/selected-bit-hosting-audit/SOURCES.json index f6902189e4..2d1c0b9b98 100644 --- a/research/selected-bit-hosting-audit/SOURCES.json +++ b/research/selected-bit-hosting-audit/SOURCES.json @@ -58,9 +58,10 @@ }, { "path": "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py", - "usage": "input", + "usage": "provenance", "git_blob": "8864ca9b942a3507171edca0cf6cbaaf10fcf434", - "sha256": "57e558c80a2fea6e291587b04afd76dfaee3550729997798b61f33daf90b8ec9" + "sha256": "57e558c80a2fea6e291587b04afd76dfaee3550729997798b61f33daf90b8ec9", + "note": "Pairwise-era digest retained as provenance after research/bit-hosted-digest-production/; working tree ships fragment-reuse. Not a live VERIFY pin." }, { "path": "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/emit_k.py", diff --git a/research/selected-bit-hosting-audit/VERIFY.json b/research/selected-bit-hosting-audit/VERIFY.json index a303452875..e0ecf5bad4 100644 --- a/research/selected-bit-hosting-audit/VERIFY.json +++ b/research/selected-bit-hosting-audit/VERIFY.json @@ -11,7 +11,6 @@ "research/e8-bit-p111-tuned/data/selection9-p111.json", "research/e8-bit-p111-tuned/tune/EXPECTED.json", "research/e8-bit-p111-tuned/tune/bitE8mut-p111-tuned.json.gz", - "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py", "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/emit_k.py", "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/global_k.py", "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage/vendor/e8-r715-eleven-stage-whole/code/hosting_k.py", diff --git a/tests/test_bit_hosted_digest_production.py b/tests/test_bit_hosted_digest_production.py new file mode 100644 index 0000000000..b6dcd3ea86 --- /dev/null +++ b/tests/test_bit_hosted_digest_production.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +"""Smoke tests for research/bit-hosted-digest-production.""" +from __future__ import annotations + +from hashlib import sha256 +from pathlib import Path +import subprocess +import sys +import unittest + +ROOT = Path(__file__).resolve().parents[1] +PACKAGE = ROOT / "research/bit-hosted-digest-production" +PRODUCTION = ( + ROOT + / "research/e8-bit-p111-tuned/vendor/pr510/e8-r480-nine-stage" + / "vendor/e8-r715-eleven-stage-whole/code/audit_hosted_k.py" +) +BASELINE = PACKAGE / "baseline.py" +OPTIMIZED_SHA256 = "9d0b44e37109128850192414bf0fefb1048bf96da2c78dff8e833980b20f61c7" +ORIGINAL_SHA256 = "57e558c80a2fea6e291587b04afd76dfaee3550729997798b61f33daf90b8ec9" + + +class BitHostedDigestProductionTests(unittest.TestCase): + def test_production_differs_from_baseline_and_matches_digest(self): + self.assertEqual(sha256(BASELINE.read_bytes()).hexdigest(), ORIGINAL_SHA256) + self.assertEqual(sha256(PRODUCTION.read_bytes()).hexdigest(), OPTIMIZED_SHA256) + self.assertNotEqual(PRODUCTION.read_bytes(), BASELINE.read_bytes()) + + def test_verify_script(self): + proc = subprocess.run( + [sys.executable, "-I", "-B", str(PACKAGE / "verify.py")], + cwd=ROOT, + capture_output=True, + text=True, + ) + self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr) + self.assertIn("PASS_BIT_HOSTED_DIGEST_PRODUCTION", proc.stdout) + + +if __name__ == "__main__": + unittest.main()