PureOne's picture
Release VSCE v6.0: manuscript, proofs, reproducible evidence and 10 research tables
347a3de verified
Raw History Blame Contribute Delete
2.75 kB
"""Verify delivery checksums and research-table integrity without dependencies."""
from pathlib import Path
import hashlib
import json
import math
ROOT=Path(__file__).resolve().parent
def finite_tree(value):
if isinstance(value,float) and not math.isfinite(value):
raise ValueError('nonfinite JSON numerical value')
if isinstance(value,dict):
for x in value.values():finite_tree(x)
if isinstance(value,list):
for x in value:finite_tree(x)
def pointer(document,path):
if path=='':return document
if not path.startswith('/'):
raise ValueError('JSON pointer must start with slash or be empty')
obj=document
for piece in path.split('/')[1:]:
piece=piece.replace('~1','/').replace('~0','~')
obj=obj[int(piece)] if isinstance(obj,list) else obj[piece]
return obj
def verify(checksums=True):
if checksums:
manifest=ROOT/'SHA256SUMS.txt'
if not manifest.exists():raise FileNotFoundError('Delivery checksum manifest missing')
for line in manifest.read_text().splitlines():
expected,relative=line.split(' ',1)
path=ROOT/relative
if not path.is_file():raise FileNotFoundError(relative)
if hashlib.sha256(path.read_bytes()).hexdigest()!=expected:
raise ValueError(f'Checksum mismatch: {relative}')
table_manifest=json.loads((ROOT/'docs/HF_TABLES_MANIFEST.json').read_text())
total=0;sources={}
for spec in table_manifest['tables']:
path=ROOT/spec['path']
rows=[json.loads(line) for line in path.read_text(encoding='utf8').splitlines() if line.strip()]
if len(rows)!=spec['rows']:raise ValueError(f'Row count mismatch: {path.name}')
ids=set()
for row in rows:
if set(row)!=set(spec['columns']):raise ValueError(f'Column mismatch: {path.name}')
finite_tree(row)
if row['row_id'] in ids:raise ValueError(f'Duplicate row id: {path.name}')
ids.add(row['row_id'])
source_path=row['source_file']
if source_path not in sources:
sources[source_path]=json.loads((ROOT/source_path).read_text(encoding='utf8'))
pointer(sources[source_path],row['source_pointer'])
total+=len(rows)
if total!=table_manifest['total_rows']:raise ValueError('Total count mismatch')
raw=json.loads((ROOT/'results/nested_monitoring.json').read_text())
if raw['trials']!=30000:raise ValueError('Unexpected monitoring sample count')
return {'configurations':len(table_manifest['tables']),'rows':total,
'checksums_checked':checksums,'source_pointers_resolve':True}
if __name__=='__main__':print(json.dumps(verify(),indent=2))