"""Download and hash-check pinned native cache archives; execute no Lean code.""" import argparse import gzip import hashlib import json import os from pathlib import Path import subprocess import time MANIFEST_URL='https://rh-cache.taucetiproject.org/bootstrap/e50d09817ad81469f737e8f637561e6ccf86c670/modules.jsonl.gz' MANIFEST_SHA='292caa386a620d935cfc736b56fcceaab9fe7073086693b62e899c1ee4725f04' ARTIFACT_URL='https://rh-cache.taucetiproject.org/artifacts/leanprover-community/riemann-hypothesis/' def sha(path): with path.open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest() def main(): p=argparse.ArgumentParser(description=__doc__) p.add_argument('--private-root',type=Path,required=True) p.add_argument('--report',type=Path,required=True) a=p.parse_args();root=a.private_root.resolve();root.mkdir(parents=True,exist_ok=True) curl='curl.exe' if os.name=='nt' else 'curl' manifest=root/'modules.jsonl.gz' if not manifest.exists() or sha(manifest)!=MANIFEST_SHA: subprocess.run([curl,'-fsSL','--retry','4','--retry-all-errors',MANIFEST_URL,'-o',str(manifest)],check=True) if sha(manifest)!=MANIFEST_SHA:raise ValueError('cache manifest digest mismatch') lines=gzip.decompress(manifest.read_bytes()).splitlines();header=json.loads(lines[0]);rows=[json.loads(l) for l in lines[1:]] if len(rows)!=175187 or header['source_tree']!='24df20b62d9976ccd20da819bc20b16f808f0fdd':raise ValueError('unexpected cache inputs') directory=root/'artifacts';directory.mkdir(exist_ok=True) pending={};verified=0 config=root/'download.conf' with config.open('w',encoding='utf-8',newline='\n') as cfg: for _,_,artifact,digest in rows: if len(artifact)!=21 or not artifact.endswith('.ltar') or any(c not in '0123456789abcdef' for c in artifact[:-5]):raise ValueError('unsafe artifact name') target=directory/artifact if target.exists() and sha(target)==digest:verified+=1;continue partial=target.with_suffix('.partial');pending[str(partial)]=(target,digest) cfg.write('url = '+json.dumps(ARTIFACT_URL+artifact[:-5]+'.art')+'\n') cfg.write('output = '+json.dumps(str(partial))+'\n') cfg.write('fail\nlocation\nsilent\nshow-error\nretry = 4\nretry-all-errors\nmax-time = 120\nnext\n') print(f'progress: {verified}/{len(rows)} pinned native cache archives verified',flush=True) failures=0;start=time.monotonic() if pending: with (root/'download-errors.log').open('w') as errors: proc=subprocess.Popen([curl,'--parallel','--parallel-max','64','--config',str(config),'--write-out','%{filename_effective}\\n'],stdout=subprocess.PIPE,stderr=errors,text=True) for line in proc.stdout: key=line.strip();item=pending.pop(key,None) if item is None:raise ValueError('unexpected curl output path') target,digest=item;partial=Path(key) if partial.exists() and sha(partial)==digest:partial.replace(target);verified+=1 else:failures+=1 if verified%1000==0:print(f'progress: {verified}/{len(rows)} native cache archives hash-checked',flush=True) if time.monotonic()-start>3300: proc.terminate();break rc=proc.wait() if rc or pending or failures:raise RuntimeError(f'incomplete download: verified={verified}, unfinished={len(pending)}, failed={failures}; completed archives retained for resume') report={'manifest_url':MANIFEST_URL,'manifest_sha256':MANIFEST_SHA,'modules':len(rows),'verified_artifacts':verified, 'source_tree':header['source_tree'],'scope':'Third-party compiled-cache bytes; not an independent rebuild or a declaration atlas.'} a.report.write_text(json.dumps(report,indent=2)+'\n',encoding='utf-8') print('Native cache archive digests verified; no proof verification or declaration extraction performed.',flush=True) if __name__=='__main__':main()