"""Verify ATLAS.md's pinned source, without extracting or redistributing it. Download/cache outside git: python verify_source.py --cache --download --report provenance.json Repeat offline by omitting --download. Only the small report belongs in git. """ import argparse from concurrent.futures import ThreadPoolExecutor from datetime import datetime, timezone import hashlib import json from pathlib import Path import subprocess SOURCE = 'https://alpo.ge/lean.tar.gz.part' EXPECTED_BYTES = 239_275_554 EXPECTED_SHA256 = '9631b4f020199e580ba86178cb56c6e9b09f690c2369a80dc4334aa93f49c7fc' PARTS = tuple(f'lean.tar.gz.part{i:02d}' for i in range(1, 15)) def fetch(cache, name): target = cache / name if target.exists(): return temporary = cache / (name + '.partial') subprocess.run(['curl.exe' if __import__('os').name == 'nt' else 'curl', '-fsSL', '--max-time', '120', '--retry', '2', SOURCE + name[-2:], '-o', str(temporary)], check=True) temporary.replace(target) def verify(cache, expected_bytes=EXPECTED_BYTES, expected_sha256=EXPECTED_SHA256): # Numeric order is part of the contract: never concatenate a glob/lexical # directory listing, and never load the entire archive into memory. combined = hashlib.sha256() total = 0 parts = [] for name in PARTS: individual = hashlib.sha256() size = 0 with (cache / name).open('rb') as stream: while block := stream.read(1024 * 1024): combined.update(block) individual.update(block) size += len(block) total += size parts.append({'file': name, 'url': SOURCE + name[-2:], 'bytes': size, 'sha256': individual.hexdigest()}) if total != expected_bytes: raise ValueError(f'archive size mismatch: {total} != {expected_bytes}') digest = combined.hexdigest() if digest != expected_sha256: raise ValueError(f'archive sha256 mismatch: {digest} != {expected_sha256}') return {'schema': 'source-provenance-v1', 'observed_at_utc': datetime.now(timezone.utc).isoformat(), 'archive_bytes': total, 'archive_sha256': digest, 'parts': parts, 'integrity': 'matches ATLAS.md pins', 'scope': 'Compressed source archive bytes only; not a Lean build, declaration atlas, proof verification, or publication permission.', 'lean_build_verified': False, 'atlas_extracted': False} def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--cache', type=Path, required=True) parser.add_argument('--download', action='store_true') parser.add_argument('--report', type=Path, required=True) args = parser.parse_args() if args.download: args.cache.mkdir(parents=True, exist_ok=True) with ThreadPoolExecutor(max_workers=4) as pool: list(pool.map(lambda name: fetch(args.cache, name), PARTS)) result = verify(args.cache) args.report.write_text(json.dumps(result, indent=2) + '\n', encoding='utf-8') print(f"source archive: {result['archive_bytes']} bytes, 14 parts, sha256 matches ATLAS.md") print('No source was extracted; no declaration atlas or Lean build was verified.') if __name__ == '__main__': main()