from pathlib import Path import argparse,hashlib,json,runpy ROOT=Path(__file__).resolve().parent.parent def load(name):return json.loads((ROOT/'sources'/name).read_text()) def main(out): m=json.loads((ROOT/'SOURCE_MANIFEST.json').read_text());auth=[] for name,item in m.items(): p=ROOT/'sources'/name assert p.stat().st_size==item['bytes'] and hashlib.sha256(p.read_bytes()).hexdigest()==item['sha256'],name auth.append('frozen '+name) prev=load('PREVIOUS_CERTIFICATE.json') for k,n in [('results_sha256','PREVIOUS_RESULTS.json'),('data_sha256','PREVIOUS_DATA.json'),('checkpoint_sha256','PREVIOUS_CHECKPOINT.md'),('next_step_decision_sha256','PREVIOUS_NEXT_STEP.json')]: assert prev[k]==m[n]['sha256'],n;auth.append('predecessor '+n) checks=[] def check(name,value): assert value,name assert name not in checks,name checks.append(name) d=runpy.run_path(str(ROOT/'evidence/CALCULATION.py'))['run'](load,check) meta=json.loads((ROOT/'STEP.json').read_text()) r={'step':'C'+str(meta['number']),'status':'passed','assertions_passed':len(checks),'checks':checks,'source_checks_passed':len(auth),'source_checks':auth,'canonical_or_graph_edits':False,'check_scope':'Finite source-labelled calculation; counts are verification inventory, not witness counts.'} out.mkdir(parents=True,exist_ok=True) for n,o in [('DATA.json',d),('RESULTS.json',r)]: (out/n).write_text(json.dumps(o,ensure_ascii=False,indent=2)+'\n') print(json.dumps({'step':meta['number'],'status':'passed','checks':len(checks),'authentication_checks':len(auth)})) if __name__=='__main__': p=argparse.ArgumentParser();p.add_argument('--out',type=Path,required=True);main(p.parse_args().out)