#!/usr/bin/env python3 # Copyright (C) 2026 Yusuke Oda # SPDX-License-Identifier: AGPL-3.0-only """Independently check DX09 provenance, all randomized trials, and statistics.""" from pathlib import Path import argparse, datetime, hashlib, json from audit_confirmations import audit_structure from verify_confirmation_statistics import verify ROOT = Path(__file__).resolve().parent.parent BASE = ROOT / 'dynamics/silence_performance' def sha(path): return hashlib.sha256(path.read_bytes()).hexdigest() parser = argparse.ArgumentParser() parser.add_argument('--metadata-only', action='store_true') args = parser.parse_args() registration = json.loads((ROOT/'common/dx09-registration.json').read_text()) manifest = json.loads((BASE/'frozen-manifest.json').read_text()) result = json.loads((BASE/'results/performance.json').read_text()) plan = json.loads((BASE/'plan.json').read_text()) assert result['status'] == 'complete' assert result['plan'] == plan assert result['plan_sha256'] == manifest['plan_sha256'] == sha(BASE/'plan.json') assert sha(BASE/'frozen-manifest.json') == registration['manifest_sha256'] assert sha(ROOT/registration['environment']) == registration['environment_sha256'] assert result['binary_sha256'] == manifest['binary_sha256'] for path, digest in manifest['sources'].items(): assert sha(ROOT/path) == digest, path if not args.metadata_only: for path, digest in manifest['binary_sha256'].items(): assert sha(ROOT/path) == digest, path for key, path in [('runner_sha256','common/run_blocks.py'),('statistics_sha256','common/standard_statistics.py')]: assert sha(ROOT/path) == registration[key] == result[key] state_checks = {} for block in result['blocks']: for run in block['runs']: row = run['measurement'] assert row['mxcsr_restored'] is True assert bool(row['mxcsr_control'] & (1 << 15)) == row['flush'] assert bool(row['mxcsr_control'] & (1 << 6)) == row['flush'] assert row['dc_prepare_frames'] == 48000 assert row['silent_prepare_frames'] == 120 * 48000 assert row['frames'] == 4 * 48000 assert row['peak'] == row['rms'] == 0 current = {name:row[name] for name in ('prepared_state','final_state','effective_parameters','mxcsr_control','checksum')} if run['job_id'] in state_checks: assert state_checks[run['job_id']] == current else: state_checks[run['job_id']] = current errors = [] structure = audit_structure(result, errors, 'DX09') structure.pop('fingerprints') statistics = verify(result) report = {'checked_utc':datetime.datetime.now(datetime.timezone.utc).isoformat(), 'family':'DX09', 'state_cases_verified':len(state_checks), 'result_sha256':sha(BASE/'results/performance.json'), 'registration_sha256':sha(ROOT/'common/dx09-registration.json'), 'structure':structure, 'structure_errors':errors, 'statistics':statistics, 'all_passed':not errors and statistics['passed']} (BASE/'results/parent-audit.json').write_text(json.dumps(report,indent=2)+'\n') print(json.dumps({'all_passed':report['all_passed'],'trials':sum(len(b['runs']) for b in result['blocks']),'pairs':len(result['analysis']['comparisons'])})) assert report['all_passed']