20261117 固化13步自然回放、数据哈希与第二版性能基线
This commit is contained in:
88
scripts/experiments/reuse_eval/verify_bundle_chain.py
Normal file
88
scripts/experiments/reuse_eval/verify_bundle_chain.py
Normal file
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify consumed snapshot/delta transitions against original recorded view digests.
|
||||
|
||||
No RP or live Internet access. This verifies the frozen 13-step workload, not
|
||||
unused minute observations or all advertised RRDP history in the full capture.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from common import Archive, file_sha256, read_json
|
||||
from replay_bundle import load_manifest, verify
|
||||
from rrdp import notification, payload_view, view_digest
|
||||
from scope import require_closure
|
||||
from serve import ReplayState
|
||||
|
||||
|
||||
def verify_chain(root: Path, manifest_path: Path, expected_sha256: str) -> dict:
|
||||
manifest = load_manifest(manifest_path, expected_sha256)
|
||||
proof = verify(root, manifest)
|
||||
archive = Archive(root / "archive", read_only=True)
|
||||
scope_path = root / "config/scope.json"
|
||||
scope = require_closure(archive.root, scope_path)
|
||||
views, versions = {}, {}
|
||||
steps = []
|
||||
for selection in manifest["epochs"]:
|
||||
epoch_path = archive.root / selection["path"]
|
||||
state = ReplayState(archive.root, epoch_path, scope_path, manifest_path, expected_sha256)
|
||||
allowed = {(r["uri"], r["sha256"]) for r in selection["http_entities"]}
|
||||
snapshots, deltas, unchanged, failures = 0, 0, 0, 0
|
||||
for uri, binding in state.epoch["repositories"].items():
|
||||
if uri in scope["routes"].get(epoch_path.name, {}):
|
||||
failures += 1
|
||||
continue # This step consumes the bound rsync view, not RRDP.
|
||||
observation = read_json(archive.root / "observations" / f"{binding['id']}.json")
|
||||
parsed = notification(archive.blob_path(binding["notification"]["sha256"]), uri)
|
||||
if (parsed["session"], parsed["serial"]) != (binding["session"], binding["serial"]):
|
||||
raise ValueError("notification binding changed")
|
||||
if uri not in views:
|
||||
ref = next(r for r in parsed["references"] if r["kind"] == "snapshot")
|
||||
if (ref["uri"], ref["sha256"]) not in allowed:
|
||||
raise ValueError("required initial snapshot missing")
|
||||
views[uri] = payload_view(archive.blob_path(ref["sha256"]), "snapshot", parsed["session"], parsed["serial"])
|
||||
snapshots += 1
|
||||
else:
|
||||
session, serial, digest = versions[uri]
|
||||
if session != parsed["session"] or serial > parsed["serial"]:
|
||||
raise ValueError("unserved session reset or serial rollback")
|
||||
refs = {r["serial"]: r for r in parsed["references"] if r["kind"] == "delta"}
|
||||
if parsed["serial"] - serial > 10000:
|
||||
raise ValueError("delta chain bound")
|
||||
for number in range(serial + 1, parsed["serial"] + 1):
|
||||
ref = refs[number]
|
||||
if (ref["uri"], ref["sha256"]) not in allowed:
|
||||
raise ValueError("consumed delta chain is incomplete")
|
||||
views[uri] = payload_view(archive.blob_path(ref["sha256"]), "delta", session, number, views[uri])
|
||||
deltas += 1
|
||||
if serial == parsed["serial"]:
|
||||
unchanged += 1
|
||||
digest = view_digest(views[uri])
|
||||
if digest != binding["view"]:
|
||||
raise ValueError("consumed chain differs from original snapshot view: " + uri)
|
||||
versions[uri] = (parsed["session"], parsed["serial"], digest)
|
||||
rsync = {uri: ref for event in state.rsync_events for uri, ref in event["objects"].items()}
|
||||
expected_rsync = {r["uri"]: {"sha256": r["sha256"], "size": r["bytes"]}
|
||||
for r in manifest["payload_inventory"] if r["kind"] == "rsync" and selection["step"] in r["steps"]}
|
||||
if rsync != expected_rsync:
|
||||
raise ValueError("rsync workload differs from selected content")
|
||||
steps.append({"step": selection["step"], "snapshots": snapshots, "deltas": deltas,
|
||||
"unchanged": unchanged, "rrdp_controlled_failures": failures,
|
||||
"http_entities": len(state.entries), "rsync_files": len(rsync), "view_digests_match": True})
|
||||
return {**proof, "manifest_sha256": file_sha256(manifest_path), "steps": steps,
|
||||
"new_rp_executions": 0, "verification": "consumed natural chain vs original view digests; no full minute-history closure claim"}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--root", type=Path, required=True)
|
||||
parser.add_argument("--manifest", type=Path, required=True)
|
||||
parser.add_argument("--expected-sha256", required=True)
|
||||
args = parser.parse_args()
|
||||
print(json.dumps(verify_chain(args.root, args.manifest, args.expected_sha256)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user