#!/usr/bin/env python3 """Verify delivered bytes with the Python standard library only.""" from __future__ import annotations import hashlib, json, sys from pathlib import Path ROOT=Path(__file__).resolve().parents[1] def digest(path): h=hashlib.sha256() with path.open('rb') as handle: for block in iter(lambda:handle.read(1048576),b''):h.update(block) return h.hexdigest() def main(): count=0;failures=[] for line in (ROOT/'CHECKSUMS.sha256').read_text().splitlines(): expected,relative=line.split(' ',1) path=ROOT/relative if not path.is_file() or digest(path)!=expected:failures.append(relative) count+=1 env=json.loads((ROOT/'environment.json').read_text()) if digest(ROOT/'code/benchmark.py')!=env['benchmark_code_sha256']: failures.append('pre-run implementation hash') if digest(ROOT/'protocol.json')!=env['protocol_sha256']: failures.append('pre-run protocol hash') if failures: print('FAILED:',*failures,sep='\n');sys.exit(1) records=list((ROOT/'results').glob('n*.json')) arrays=list((ROOT/'data').glob('n*.npz')) assert len(records)==60 and len(arrays)==60 print(f'PASS: {count} payload hashes; 60 result records and 60 instance archives.') print('Pre-execution code/protocol hashes match. This is byte verification, not independent scientific replication.') if __name__=='__main__':main()