"""SIEVE capacity counterexample: pinned library and Algorithm 1 state audit. SPDX-License-Identifier: MIT Copyright (c) 2026 Hesela """ import argparse from datetime import datetime, timezone import hashlib import importlib.metadata import json from pathlib import Path import platform import runpy HELPER = Path(__file__).with_name("sieve-traces.py") engine = runpy.run_path(str(HELPER)) require, validate, replay = engine["require"], engine["validate"], engine["replay"] TRACE = "AABBCCDED" def states(refs, capacity): """Readable Algorithm 1 model; state rows are not library instrumentation.""" validate(refs, capacity) queue, bits, hand, rows = [], {}, None, [] for index, key in enumerate(refs, 1): hit, victim = key in bits, None if hit: bits[key] = 1 else: if len(queue) == capacity: candidate = queue[0] if hand is None else hand while bits[candidate]: bits[candidate] = 0 pos = queue.index(candidate) + 1 candidate = queue[pos] if pos < len(queue) else queue[0] pos = queue.index(candidate) + 1 hand = queue[pos] if pos < len(queue) else None victim = candidate queue.remove(candidate) del bits[candidate] queue.append(key) bits[key] = 0 rows.append({"request": index, "key": key, "hit": hit, "victim": victim, "residentOldestFirst": "".join(queue), "visitedOldestFirst": "".join(str(bits[k]) for k in queue), "hand": hand}) return rows def canonical_sequences(length, prefix="A", largest=0): """First-occurrence-normalized names, at most five distinct objects.""" if len(prefix) == length: yield prefix return for value in range(min(4, largest + 1) + 1): yield from canonical_sequences(length, prefix + chr(65 + value), max(largest, value)) def check_case(refs, capacity): observed = replay(refs, capacity, "SIEVE") history = states(refs, capacity) outcomes = "".join("H" if row["hit"] else "M" for row in history) require(observed["outcomes"] == outcomes, ("state model mismatch", refs, capacity)) require(outcomes == engine["sieve_oracle"](refs, capacity)["outcomes"], ("prior oracle mismatch", refs, capacity)) for row in history: resident = row["residentOldestFirst"] require(len(set(resident)) == len(resident) <= capacity, "invalid resident set") require(len(resident) == len(row["visitedOldestFirst"]), "invalid visited bits") require(row["hand"] is None or row["hand"] in resident, "dangling hand") return observed, history def discover(): require(importlib.metadata.version("libcachesim") == engine["VERSION"], "library version mismatch") checked = 0 for length in range(1, 10): for refs in canonical_sequences(length): small, _ = check_case(refs, 3) large, _ = check_case(refs, 4) checked += 1 if large["misses"] > small["misses"]: return {"references": refs, "canonicalSequencesChecked": checked, "libraryModelComparisons": checked * 2, "method": "Length then lexicographic order; first-occurrence-normalized names A-E; capacities 3 and 4; stop at first increase.", "scope": "All normalized sequences of lengths 1-8, then a prefix of length 9. No claim about other capacities, sizes or admission rules."} raise AssertionError("expected counterexample not found") def result(): search = discover() require(search["references"] == TRACE, "discovery changed") rows = [] for capacity in range(1, 6): observed, history = check_case(TRACE, capacity) rows.append({"capacityObjects": capacity, "policies": {p: replay(TRACE, capacity, p) for p in engine["POLICIES"]}, "sieveStates": history}) require(observed == rows[-1]["policies"]["SIEVE"], "non-repeatable replay") require([r["policies"]["SIEVE"]["misses"] for r in rows] == [6, 6, 5, 6, 5], "capacity sweep changed") require(rows[2]["sieveStates"][7]["residentOldestFirst"] == "CDE", "small prefix state") require(rows[3]["sieveStates"][7]["residentOldestFirst"] == "ABCE", "large prefix state") return { "schemaVersion": 1, "evidenceType": "constructed counterexample replay", "generatedAt": datetime.now(timezone.utc).isoformat(), "license": "MIT (Hesela code and generated results); upstream retains its rights", "references": TRACE, "requests": len(TRACE), "library": {"name": "libcachesim", "version": engine["VERSION"]}, "pythonVersion": platform.python_version(), "scriptSha256": hashlib.sha256(Path(__file__).read_bytes()).hexdigest(), "helperSha256": hashlib.sha256(HELPER.read_bytes()).hexdigest(), "source": {"url": "https://www.usenix.org/system/files/nsdi24-zhang-yazhuo.pdf", "locator": "Section 3.1, Algorithm 1", "accessed": "2026-10-19", "authorArtifactCommit": "0861f8261c37b8286a70449a1defb5a4749c72d2"}, "discovery": search, "seed": None, "assumptions": [ "Empty caches; equal-size objects; count cold misses; immediate demand admission and fill.", "One sequential requester; full associativity; no TTL, writes, prefetch or metadata charge.", "CLOCK uses one bit and initial frequency zero, matching the existing replay helper.", "State rows come from a separate Algorithm 1 model; hit/miss outcomes match the pinned library.", "Counterexample existence, not workload prevalence, device performance, a new theorem or a novelty claim." ], "rows": rows } if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--output", type=Path) args = parser.parse_args() encoded = json.dumps(result(), indent=2) + "\n" if args.output: args.output.write_text(encoded, encoding="utf-8") else: print(encoded, end="")