PureOne's picture
Add Orythmea manuscript, research artifacts, and verification records
e3791a2 verified
Raw History Blame Contribute Delete
4.31 kB
"""Verify the archived release and the exact derived data. Standard library only."""
from pathlib import Path
import hashlib
import json
import re
ROOT = Path(__file__).resolve().parents[1]
def sha(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def rows(name):
return [json.loads(line) for line in (ROOT / 'data' / (name + '.jsonl')).read_text(encoding='utf-8').splitlines() if line.strip()]
def main():
manifest = ROOT / 'SHA256SUMS.txt'
expected = set()
for line in manifest.read_text(encoding='utf-8').splitlines():
digest, relative = line.split(' ', 1)
if not re.fullmatch('[0-9a-f]{64}', digest):
raise ValueError('Invalid manifest digest')
path = ROOT / relative
if path.is_symlink() or not path.is_file() or not path.resolve().is_relative_to(ROOT):
raise ValueError(f'Invalid path: {relative}')
if relative in expected or sha(path) != digest:
raise ValueError(f'Checksum or duplicate failure: {relative}')
expected.add(relative)
actual = {p.relative_to(ROOT).as_posix() for p in ROOT.rglob('*') if p.is_file() and p != manifest and '__pycache__' not in p.parts and p.suffix != '.pyc'}
if actual != expected:
raise ValueError(f'Unlisted or missing files: {sorted(actual.symmetric_difference(expected))}')
for line in (ROOT / 'research' / 'SHA256SUMS.txt').read_text().splitlines():
digest, filename = line.split(' ', 1)
if sha(ROOT / 'research' / filename) != digest:
raise ValueError(f'Original file changed: {filename}')
tex_path = ROOT / 'research' / 'Orythmea_Private_Covers.tex'
tex_bytes = tex_path.read_bytes()
tex = tex_bytes.decode('utf-8')
sections = rows('manuscript_sections')
if ''.join(row['text'] for row in sections).encode('utf-8') != tex_bytes:
raise ValueError('Sections do not reconstruct the original source')
offset = 0
for i, row in enumerate(sections):
if row['section_index'] != i or row['source_sha256'] != sha(tex_path):
raise ValueError('Invalid section ordering or source hash')
if row['line_start'] != tex.count('\n', 0, offset) + 1:
raise ValueError('Incorrect section source line')
offset += len(row['text'])
if row['line_end'] != tex.count('\n', 0, offset-1) + 1:
raise ValueError('Incorrect section ending line')
claims = rows('claims')
for row in claims:
statement = row['statement_latex']
pos = tex.find(statement)
if pos < 0 or row['source_line'] != tex.count('\n', 0, pos) + 1:
raise ValueError(f'Invalid copied statement: {row["record_id"]}')
if row['source_sha256'] != sha(tex_path) or row['universal_conjecture_resolved']:
raise ValueError('Invalid statement provenance/status')
if '\\label{' + row['source_label'] + '}' not in statement:
raise ValueError('Missing statement label')
checks = rows('verification_checks')
for row in checks:
original = json.loads((ROOT / row['source_path']).read_text())
expected_group = original['checks'][row['check_name']] if row['suite'] == 'orythmea' else original[row['check_name']]
if json.loads(row['results_json']) != expected_group:
raise ValueError('Changed verification group')
metadata = json.loads((ROOT / 'release_metadata.json').read_text())
counts = {'manuscript_sections': len(sections), 'claims': len(claims), 'verification_checks': len(checks)}
if metadata['data_configs'] != counts or metadata['universal_conjecture_resolved']:
raise ValueError('Invalid release metadata')
for name in counts:
data = rows(name)
keys = set(data[0])
types = {k: type(data[0][k]) for k in keys}
if len({row['record_id'] for row in data}) != len(data):
raise ValueError('Duplicate record IDs')
for row in data:
if set(row) != keys or any(type(row[k]) != types[k] for k in keys):
raise ValueError('Inconsistent dataset schema')
print(json.dumps({'status': 'passed', 'manifest_files': len(expected), 'original_files_preserved': 8, 'dataset_records': counts}, indent=2))
if __name__ == '__main__':
main()