File size: 3,955 Bytes
b3c3fe4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | """Offline byte equivalence to an already qualified C5 run; no fresh audit or native test."""
import argparse, collections, json
from pathlib import Path
import phase_c_qualify as c
from phase_d1_compare import code_ok, lines
def compare(run,base):
s,p=c.read(run/'summary.json'),c.read(base/'summary.json');sr,pr=c.index(s['records']),c.index(p['records']);fn=lines(run/'functions.jsonl');errors=[];failed=[]
def need(ok,msg):
if not ok:errors.append(msg)
need(s.get('function_only') is True,'function-only run required')
need(all(x.get('hashes')==c.PINS and x.get('syntax_sha256')==c.SYNTAX_PIN and x.get('checkpoint_unchanged') is True and x.get('fixture') is False and x.get('device','').startswith('cuda') and x.get('selected')==x.get('corpus')==598 for x in (s,p)),'pinned full CUDA runs required')
need(set(sr)==set(pr)==set(fn) and len(sr)==598,'ID sets or denominator mismatch')
need(dict(collections.Counter(r.get('role') for r in sr.values()))==c.ROLES,'role counts')
# Bind the existing C5 qualification to its original artifacts, as in D1.
g=c.read(base/'phase_c_gate.json');a=c.read(base/'assembly_comparison.json');ar=c.index(a['records'])
trusted=(g.get('qualified') is True and g.get('programs')==g.get('passed')==598 and g.get('native_checks')==49326 and not g.get('errors') and not p.get('compact') and a.get('selected')==a.get('assembled')==a.get('learned_compared')==a.get('learned_byte_exact')==598 and set(ar)==set(pr) and a.get('summary_sha256')==c.sha(base/'summary.json') and a.get('physical_assembly_sha256')==c.sha(base/'physical.s') and a.get('plans_sha256')==c.sha(base/'plans.jsonl') and a.get('plan_binding_errors')==[] and not c.binding(base,p))
need(trusted,'C5 qualification/provenance failed')
for sid,r in sr.items():
old=pr.get(sid,{});f=fn.get(sid,{});assembled=ar.get(sid,{});bad=[]
for k in ('source_sha256','ast_packet_sha256','ssa_sha256','signature','constructor','role','family','symbol','learned_bytes','learned_sha256','learned_code_hex'):
if k not in r or r.get(k)!=old.get(k):bad.append(k)
if not all(r.get(k) is True for k in ('semantic_valid','ast_valid','ssa_valid','resident_valid','encoder_valid','exported')) or r.get('resident_stage_valid')!=[True]*11 or r.get('allocation_audit') is not False or 'error' in r:bad.append('resident stage validation')
if not code_ok(r) or not code_ok(old) or r.get('relocations')!=0 or old.get('relocations')!=0 or assembled.get('learned_byte_exact') is not True or assembled.get('sha256')!=r.get('learned_sha256') or assembled.get('bytes')!=r.get('learned_bytes'):bad.append('byte verification')
expected=dict(schema='neurocc.function.v1',id=sid,symbol=r.get('symbol'),architecture='x86_64',abi='sysv',signature=r.get('signature'),size=r.get('learned_bytes'),code_hex=r.get('learned_code_hex'),sha256=r.get('learned_sha256'),relocations=[])
if any(f.get(k)!=v for k,v in expected.items()):bad.append('handoff metadata')
if bad:failed.append(dict(id=sid,fields=bad))
need(not failed,'per-function mismatch')
out=dict(scope='function-byte equivalence to qualified C5; no new physical allocation audit or native execution',selected=len(sr),matched=len(sr)-len(failed),byte_equivalent_to_qualified_baseline=not errors,baseline_verified=trusted,seconds=s['seconds'],functions_per_second=len(sr)/s['seconds'],peak_allocated_mib=s.get('peak_allocated_mib'),peak_reserved_mib=s.get('peak_reserved_mib'),stage_seconds=s['stage_seconds'],errors=errors,failed=failed)
(run/'phase_d3b_function_parity.json').write_text(json.dumps(out,indent=2)+'\n');print(json.dumps(out,indent=2));return int(bool(errors))
if __name__=='__main__':
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--run',type=Path,required=True);p.add_argument('--baseline',type=Path,required=True);a=p.parse_args();raise SystemExit(compare(a.run,a.baseline))
|