#!/usr/bin/env python3 """Verify initialization inputs against complete, source-bound REA byte records.""" import argparse import hashlib import json from pathlib import Path from lift_rng import arm64_image,file_range from build_target_deserialiser import RANGES as TARGET_RANGES from build_deserialiser import RANGES as DESER_RANGES ROOT=Path(__file__).resolve().parents[1] parser=argparse.ArgumentParser(description=__doc__) parser.add_argument('binary',type=Path);parser.add_argument('bundle',type=Path) args=parser.parse_args();image,_=arm64_image(args.binary.read_bytes()) source_hash=hashlib.sha256(image).hexdigest() bundle=json.loads(args.bundle.read_text()) for name,ranges in [('target-deserialiser',TARGET_RANGES),('deserialiser',DESER_RANGES)]: checks=[] for address,size,expected in ranges: offset=file_range(image,address,size);data=image[offset:offset+size] assert hashlib.sha256(data).hexdigest()==expected matches=[] for record in bundle['records']: if record.get('operation')!='read_bytes' or record.get('confidence')!='observed' or record.get('authority')!='shipped-artifact':continue if record.get('subject',{}).get('digest',{}).get('sha256')!=source_hash:continue value=record['normalized_result'] if value['address']==hex(address) and value['complete'] and value['returned_bytes']==size and value['requested_bytes']==size: if bytes.fromhex(value['bytes_hex'])!=data:raise ValueError('REA bytes contradict the pinned local input') matches.append(record['evidence_id']) if not matches:raise ValueError(f'Missing complete REA byte record at {address:#x} ({size} bytes)') checks.append({'address':hex(address),'bytes':size,'sha256':expected,'evidence_ids':matches}) report={'status':'pass','arm64_sha256':source_hash,'checks':checks, 'scope':'exact translation input bytes; not whole-engine behavioral equivalence'} (ROOT/'build'/name/'rea-provenance.json').write_text(json.dumps(report,indent=2)+'\n') print(f'PASS: {name}, {len(checks)} pinned input ranges match complete REA observations')