"""Create/verify the single standard deterministic gzip transport of exact reviewed WASM."""
from pathlib import Path
import gzip,hashlib,io,json,sys,zlib
b=Path(__file__).parent;p=b/'runtime-build/artifacts/zeroperl.wasm';raw=p.read_bytes()
assert len(raw)==29202324 and hashlib.sha256(raw).hexdigest()=='8204ccf1c93dc66915a3d1acc9760d4b87320e0493aeded8a69168b213a68a7f'
buffer=io.BytesIO()
with gzip.GzipFile(filename='',mode='wb',compresslevel=9,mtime=0,fileobj=buffer)as f:f.write(raw)
compressed=buffer.getvalue();sha=hashlib.sha256(compressed).hexdigest();assert len(compressed)==8963962 and sha=='34c5fa8ae99652397600401eb0f3349163845693d37ef8c274ce0b0899fd514c';assert gzip.decompress(compressed)==raw
out=p.with_suffix('.wasm.gz')
if out.exists():assert out.read_bytes()==compressed
else:
 with out.open('xb')as f:f.write(compressed)
proof={'compression':'one standard gzip member, level9, emptyfilename, mtime0','compressedBytes':len(compressed),'compressedSha256':sha,'rawBytes':len(raw),'rawSha256':hashlib.sha256(raw).hexdigest(),'pythonVersion':sys.version,'zlibCompileVersion':zlib.ZLIB_VERSION,'zlibRuntimeVersion':zlib.ZLIB_RUNTIME_VERSION,'wasmLinearMemoryMaximumBytes':268435456,'wasmUnchanged':True}
(b/'runtime-build/artifacts/runtime-gzip-proof.json').write_text(json.dumps(proof,indent=2)+'\n');print(json.dumps(proof,indent=2))
