"""run_benchmark.py — score the local engine against an independent labelled set and emit a reproducible accuracy report. Usage: python bench/run_benchmark.py python bench/run_benchmark.py --replay python bench/run_benchmark.py --fill missing-urls.txt Replay never fetches and refuses to publish when an answer is unrecorded. Fill asks only the distinct listed URLs without entries; run a separate replay afterwards. Four things happen here: 1. **Run the engine.** Calls assess() from src/risk.py directly, with its _fetch_json swapped for a caching fetcher (role="engine"). What gets measured is the code in the repo, not the deployed service, so this can run in CI. 2. **Assert independence.** The set of endpoints the engine touched and the set the labeller touched must not intersect. Any overlap fails the benchmark and exits non-zero — this is the foundation of the whole report's credibility, and it can't just live in the docs. 3. **Ablation.** Some pools have already drained by the market snapshot. The engine can call those high from the liquidity signal alone. So alongside the full score we report a second one that **keeps only contract-safety signals** (dropping liquidity/activity/freshness/cross-chain). The gap between the two numbers is what this tool actually tells you beyond the obvious. 4. **Signal attribution.** Count which category of signal drove each correct verdict. If 100% come from upstream_risk, the engine is only paraphrasing honeypot.is and adds nothing of its own. """ import json import os import sys from collections import Counter from datetime import datetime, timezone from urllib.parse import urlsplit HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) sys.path.insert(0, os.path.join(HERE, "..", "src")) import labels as LABELS # noqa: E402 import risk # noqa: E402 import fetcher as fetcher_module # noqa: E402 from fetcher import access_report, fetch_json, load_persisted_access_log # noqa: E402 DATASET = os.path.join(HERE, "dataset.json") RESULTS_JSON = os.path.join(HERE, "results.json") RESULTS_MD = os.path.join(HERE, "results.md") # Chosen by reproducing both committed result files; whole hours from September 20 # at 16:00 UTC through September 21 at 09:00 UTC reproduced, adjacent hours did not. BENCH_CLOCK = datetime(2026, 9, 21, 2, tzinfo=timezone.utc) LAST_RUN = {} # Contract-safety signals: the ones independent of how much liquidity is left right now # What survives when the market-data signals are stripped. The point of the column is to # show what the engine concludes from CONTRACT evidence alone -- the part a competitor # reading the same free liquidity feed could not trivially reproduce. # # `drained` is deliberately absent, and it used to be inside `sellability`. The # drained-pool finding is computed entirely from DexScreener liquidity figures: it fires # when every pool on the token's own chain reports a depth of zero. That is a market-data # conclusion wearing a sellability label, and it carried `fatal` (100) into the ablated # score after R10 promoted it from `critical`. 14 of 42 ablated-high verdicts -- a third -- # rode on it, which is a third of the column's headline claiming to be contract evidence # while being liquidity evidence. # # All 14 are currently `centralized`, so the published unsafe/dead ablated figures were # not yet contaminated. W3 grows the adversarial cohort with exactly these tokens, so the # contamination was scheduled rather than avoided. CONTRACT_CATEGORIES = { "honeypot", "sellability", "sell_tax", "upstream_risk", "rugcheck", "contract", "concentration", } def install_engine_fetcher(replay=False): """Swap the engine's fetcher for one that caches and books which endpoints it hit.""" async def _fetch(url, retries=2, timeout=8, mark_missing=False, headers=None): # `headers` is accepted and not used: the benchmark runs keyless (no CG_DEMO_KEY is # configured here), so the keyed CoinGecko source is never selected. # retries=2, matching src/risk.py. It was 1, so the harness gave upstream one # fewer chance than production does and then scored the engine on the result. # Production is gentler still: it caches at the edge and serves data up to 15 # minutes stale rather than answering unknown, and it never asks about 558 tokens # in a burst. got = fetch_json(url, role="engine", retries=2, mark_missing=mark_missing, dated=True, replay=replay) return risk.NO_DATA if got is fetcher_module.NOT_FOUND else got risk._fetch_json = _fetch def ablate(address, signals, data_gaps=None): """Re-grade with contract-safety signals only, to see how much judgement is left. The gaps are passed through, filtered to the dimensions this column still covers. Passing an empty list -- as this did -- switched off the fail-closed override for every ablated verdict, so the published column reported low and medium for tokens whose sell simulation never ran. The ablation is meant to remove *signals derived from liquidity*, not to remove the rule that an unverified token cannot be called safe, and a benchmark column that quietly grades itself under laxer rules than the engine flatters the engine. """ kept = [s for s in signals if s["category"] in CONTRACT_CATEGORIES] if not kept: return "unknown", 0 gaps = [g for g in (data_gaps or []) if g.get("dimension") == "sellability"] r = risk._finalize(address, kept, {}, gaps) return r["risk_level"], r["risk_score"] def driving_category(signals): """Category of the one signal that decided this verdict. The rule lives in the engine (`risk._driver`) since the API started exposing it, so the report and the product cannot disagree about what drove the same verdict. """ d = risk._driver(signals) return d["category"] if d else None def evaluate(rows, label_key, bad_value, good_value): """Compute metrics for one set of labels. strict = only high counts as "caught it" lenient = high or medium both count as "flagged risk" (in product terms, medium means a human has to look) """ bad = [r for r in rows if r.get(label_key) == bad_value] good = [r for r in rows if r.get(label_key) == good_value] def rate(sub, pred): return (sum(1 for r in sub if pred(r)) / len(sub)) if sub else None def block(sub, verdict_field, score_field): return { "n": len(sub), "high": rate(sub, lambda r: r[verdict_field] == "high"), "high_or_medium": rate(sub, lambda r: r[verdict_field] in ("high", "medium")), "low": rate(sub, lambda r: r[verdict_field] == "low"), "unknown": rate(sub, lambda r: r[verdict_field] == "unknown"), "mean_score": (sum(r[score_field] for r in sub) / len(sub)) if sub else None, } out = { "bad_label": bad_value, "good_label": good_value, "full": {"bad": block(bad, "verdict", "score"), "good": block(good, "verdict", "score")}, "contract_only": {"bad": block(bad, "verdict_ablated", "score_ablated"), "good": block(good, "verdict_ablated", "score_ablated")}, "driving_categories_on_bad": dict( Counter(r["driver"] for r in bad if r.get("driver")).most_common()), } return out def false_blocks(rows): """Liquid healthy tokens rated medium or high, by driving signal. The false-positive rate counts only `high` on `alive`. An agent treats `medium` as do-not-trade too, so that rate understates what a caller is refused. This counts it the way a caller experiences it, on tokens whose health is not in doubt -- outcome `alive` or oracle `centralized` -- and whose depth ($100k+) cannot be the reason. Printed beside the FP rate, never folded into it (B3/B4). Source: ChatGPT evaluation §8.1. """ pop = [r for r in rows if (r.get("outcome_label") == "alive" or r.get("goplus_label") == "centralized") and (r.get("liquidity_usd") or 0) >= 100_000] blocked = [r for r in pop if r["verdict"] in ("medium", "high")] return {"n": len(pop), "blocked": len(blocked), "rate": (len(blocked) / len(pop)) if pop else None, "by_driver": dict(Counter(r.get("driver") or "none" for r in blocked).most_common())} def centralized_view(rows): """The "privileged functions, no adversarial traits" bucket — USDT / WBTC / LDO. This bucket is **not scored right or wrong**; it only shows whether the engine paints every centralized asset as high risk. A lot of high verdicts means the thresholds are too blunt and will produce grating false positives in real use. """ sub = [r for r in rows if r.get("goplus_label") == "centralized"] if not sub: return {"n": 0} dist = Counter(r["verdict"] for r in sub) return { "n": len(sub), "verdict_distribution": dict(dist), "high_rate": dist.get("high", 0) / len(sub), "examples": [{"symbol": r.get("symbol"), "chain": r["chain"], "verdict": r["verdict"], "driver": r.get("driver")} for r in sub[:10]], } def composition(rows): """What the sample is made of, split out for the bad cohort specifically. A recall figure is a statement about a population, and this one's population is not the market -- it is whatever the three sampling sources could reach. The bad cohort especially: it is small, and if it turns out to be one chain and one source then the number describes that corner rather than the tool. Printing it is the difference between a reader being able to discount the result correctly and having to trust it. """ from collections import Counter def split(subset): return { "n": len(subset), "chain": dict(Counter(r.get("chain") or "?" for r in subset).most_common()), "source": dict(Counter((r.get("sampled_from") or "?").split("_")[0] for r in subset).most_common()), } bad = [r for r in rows if r.get("outcome_label") == "dead" or r.get("goplus_label") == "unsafe"] return {"all": split(rows), "bad": split(bad)} def collect_disagreements(rows): """Keep the original scoring categories and put low-verdict disagreements first.""" out = [] for r in rows: for key, bad, good in (("outcome_label", "dead", "alive"), ("goplus_label", "unsafe", "safe")): lab = r.get(key) if lab == bad and r["verdict"] == "low": kind = "false negative" elif lab == good and r["verdict"] == "high": kind = "false positive" else: continue out.append({"kind": kind, "label": "%s=%s" % (key.split("_")[0], lab), "address": r["address"], "symbol": r.get("symbol"), "chain": r["chain"], "verdict": r["verdict"], "verdict_ablated": r["verdict_ablated"], "driver": r.get("driver")}) out.sort(key=lambda d: 0 if d["kind"] == "false negative" else 1) return out def _pool_identity(chain, pool_id): chain = risk._canonical_chain(chain) if isinstance(chain, str) else None if chain not in risk._KNOWN_CHAINS: return None identity = risk._validated_chain_pool_id(pool_id, chain) if identity is None: return None return chain, identity if chain == "solana" else identity.lower() def outcome_pool_scope(row): labelled = _pool_identity(row.get("chain"), row.get("labelled_pool")) assessed = _pool_identity(row.get("engine_chain"), row.get("engine_pool_id")) if labelled is None or assessed is None: return "unknown" if labelled[0] != assessed[0]: return "different_chain" return "same" if labelled == assessed else "different" def outcome_pool_counts(rows): scope = Counter(outcome_pool_scope(row) for row in rows) return scope["same"], scope["different"] + scope["different_chain"], scope["unknown"] def _pct(v): return "—" if v is None else "%.1f%%" % (v * 100) def _num(v): return "—" if v is None else "%.1f" % v def _fill(file): try: with open(file, encoding="utf-8") as f: lines = f.read().splitlines() except (OSError, UnicodeError): print("Fill file cannot be read") return 5 urls = [] for line in lines: if not line.strip(): continue try: parsed = urlsplit(line) port = parsed.port valid = (line.startswith("https://") and not any(c.isspace() for c in line) and parsed.scheme == "https" and bool(parsed.hostname) and (port is None or 0 <= port <= 65535)) except ValueError: valid = False if not valid: print("Fill file must contain one https URL per line") return 5 if line not in urls: urls.append(line) if not urls: print("Fill file contains no URLs") return 5 outcomes, hosts = [], {} for url in urls: if fetcher_module.read_cache_entry(url) is not None: outcome = "already recorded" else: fetch_json(url, role="engine", retries=2, dated=True) entry = fetcher_module.read_cache_entry(url) outcome = ("stored answer" if isinstance(entry, dict) and "data" in entry else "stored 4xx" if isinstance(entry, dict) and "status" in entry else "not stored") outcomes.append({"url": url, "outcome": outcome}) hosts.setdefault(urlsplit(url).netloc, Counter())[outcome] += 1 print("%s: %s" % (outcome, url)) per_host = {host: dict(counts) for host, counts in sorted(hosts.items())} LAST_RUN["fill"] = {"outcomes": outcomes, "per_host": per_host} for host, counts in per_host.items(): print("Fill %s: %s" % (host, dict(counts))) return 6 if any(o["outcome"] == "not stored" for o in outcomes) else 0 def main(argv=None): global LAST_RUN args = list(sys.argv[1:] if argv is None else argv) LAST_RUN = {} if args not in ([], ["--replay"]) and not (len(args) == 2 and args[0] == "--fill"): print("Usage: run_benchmark.py [--replay | --fill FILE]") return 5 fetcher_module.reset_benchmark_stats() if args and args[0] == "--fill": return _fill(args[1]) replay = args == ["--replay"] LAST_RUN = {"clock": BENCH_CLOCK.isoformat().replace("+00:00", "Z"), "pairs_after_clock": 0, "evaluated": 0} previous_fetcher = risk._fetch_json pin = risk._BENCH_NOW.set(BENCH_CLOCK) try: return _evaluate(replay) finally: risk._BENCH_NOW.reset(pin) risk._fetch_json = previous_fetcher LAST_RUN.update(fetcher_module.benchmark_stats()) if LAST_RUN["evaluated"]: print("Benchmark clock: %s; best pairs created after it: %d" % ( LAST_RUN["clock"], LAST_RUN["pairs_after_clock"])) if not replay: print("Dated cache writes: %d entries; %d negative" % ( LAST_RUN["writes"]["entries"], LAST_RUN["writes"]["negative"])) def _evaluate(replay=False): if not os.path.exists(DATASET): print("%s not found — run python bench/build_dataset.py first" % DATASET) return 1 with open(DATASET, encoding="utf-8") as f: data = json.load(f) tokens = data.get("tokens") or [] if not tokens: print("Dataset is empty") return 1 install_engine_fetcher(replay=replay) import asyncio rows = [] print("Evaluating %d tokens ..." % len(tokens)) for i, t in enumerate(tokens, 1): try: # verbose=True only to see `best_pair.pair_address`. It adds evidence # fields and changes no verdict, no score and no signal -- the numbers below # are identical either way. res = asyncio.run(risk.assess(t["address"], t["chain"], verbose=True)) except Exception as e: # noqa: BLE001 print(" %s failed to evaluate: %s" % (t.get("symbol"), e)) continue LAST_RUN["evaluated"] += 1 best_pair = (res.get("evidence") or {}).get("best_pair") or {} created = best_pair.get("pair_created_at") created_ms = risk._pair_created_ms(created) if created_ms is not None and created_ms > BENCH_CLOCK.timestamp() * 1000: LAST_RUN["pairs_after_clock"] += 1 sigs = res.get("signals") or [] ab_level, ab_score = ablate(t["address"], sigs, (res.get("evidence") or {}).get("data_gaps")) rows.append({ # Sanitised at the boundary, not at each of the six places the report prints # it. A ticker is upstream text: `results.md` renders it inside a markdown # table, where an unescaped pipe silently reshapes the row, and this file is # the project's public evidence. It is also how a CJK ticker turned the # English-only guard red on a tip commit -- the guard was right, and the # answer is to quote the ticker accurately in ASCII rather than to exempt the # file from the rule. "address": t["address"], "symbol": risk._ascii_safe(t.get("symbol")), "chain": t["chain"], # The pool the LABEL describes, and the pool the ENGINE judged. They are # picked independently -- build_dataset samples one pool and assess() runs # its own selection -- so they are not always the same venue, and every # disagreement between them was being booked as an engine error. "labelled_pool": t.get("pool") or None, "engine_pool": (best_pair.get("pair_address") or "").lower() or None, "engine_chain": best_pair.get("chain"), "engine_pool_id": best_pair.get("pool_id"), "outcome_label": t.get("outcome_label"), "goplus_label": t.get("goplus_label"), "sampled_from": t.get("sampled_from"), "liquidity_usd": best_pair.get("liquidity_usd"), "gap_reasons": [g.get("reason") for g in ((res.get("evidence") or {}).get("data_gaps") or [])], "verdict": res.get("risk_level"), "score": res.get("risk_score"), "confidence": res.get("confidence"), "verdict_ablated": ab_level, "score_ablated": ab_score, "driver": driving_category(sigs), "categories": sorted({s["category"] for s in sigs}), "has_data_gap": bool((res.get("evidence") or {}).get("data_gaps")), }) if i % 20 == 0 or i == len(tokens): print(" [%d/%d]" % (i, len(tokens))) # ---- Independence assertion: the foundation of the whole report ---- # Pull in what the labeling process recorded. Without this the label set is empty # in this process, engine n {} is always {}, and the disjointness assertion below # can never fail -- which is exactly what it did until it was caught. had_labels = load_persisted_access_log() engine_eps, label_eps, overlap = access_report() if not had_labels or not label_eps: print("\nBenchmark void: no labeling endpoints on record, so the independence") print("assertion would pass vacuously. Run python bench/build_dataset.py first") print("(it writes bench/access_log.json) and re-run this.") return 3 if overlap: print("\nBenchmark invalid: engine and labeller hit the same endpoint —" " that makes the result circular") for e in overlap: print(" overlapping endpoint:", e) return 2 if replay: misses = fetcher_module.benchmark_stats()["replay"] print("Replay missed %d requests over %d distinct URLs" % ( misses["requests"], len(misses["urls"]))) for host, count in misses["per_host"].items(): print(" %s: %d missed requests" % (host, count)) for url in misses["urls"]: print(url) if misses["requests"]: return 4 report = { "n_evaluated": len(rows), "independence": {"engine_endpoints": engine_eps, "label_endpoints": label_eps, "overlap": overlap}, "overall": { "verdict_distribution": dict(Counter(r["verdict"] for r in rows)), "unknown_rate": sum(1 for r in rows if r["verdict"] == "unknown") / len(rows), "data_gap_rate": sum(1 for r in rows if r["has_data_gap"]) / len(rows), }, "outcome": evaluate(rows, "outcome_label", "dead", "alive"), "goplus": evaluate(rows, "goplus_label", "unsafe", "safe"), "centralized": centralized_view(rows), "false_block": false_blocks(rows), "disagreements": collect_disagreements(rows), "composition": composition(rows), "rows": rows, } with open(RESULTS_JSON, "w", encoding="utf-8") as f: json.dump(report, f, ensure_ascii=False, indent=1) write_markdown(report) print("\nWrote %s and %s" % (RESULTS_JSON, RESULTS_MD)) o = report["outcome"]["full"]["bad"] print("\nAt a glance:") print(" dead rated high (see report) : %s (n=%d)" % (_pct(o["high"]), o["n"])) print(" still high on contract signals : %s" % _pct(report["outcome"]["contract_only"]["bad"]["high"])) print(" false positives, established : %s (n=%d)" % (_pct(report["outcome"]["full"]["good"]["high"]), report["outcome"]["full"]["good"]["n"])) print(" unknown rate : %s" % _pct(report["overall"]["unknown_rate"])) return 0 def write_markdown(rep): L = [] A = L.append rows = rep.get("rows") or [] A("# VetAgent Accuracy Benchmark\n") A("> Generated by `python bench/run_benchmark.py`. Do not edit by hand.\n") A("Sample size **%d**. This is v1 and the sample is small — read it as a check for " "obvious breakage, not as a precise statistical result.\n" % rep["n_evaluated"]) A("\n## Method\n") A("Labels use **none of the endpoints the engine reads** — otherwise this would " "measure whether the engine can paraphrase its upstream.\n") A("\n| | Label source | Read by the engine? |") A("|---|---|---|") A("| `outcome` | GeckoTerminal daily OHLCV history (price + volume) " "| No, the engine uses market snapshots |") A("| `goplus` | GoPlus token_security | No, deliberately held back as a labeller |") A("\n**Runtime assertion**: engine endpoints ∩ labeller endpoints = ∅. If that " "fails, the benchmark declares itself invalid and exits non-zero. " "This run: **passed**.\n") A('\n
Endpoints hit: engine on this run, ' 'labeller on the run that built the dataset\n') A("\nEngine:\n") for e in rep["independence"]["engine_endpoints"]: A("- `%s`" % e) A("\nLabeller:\n") for e in rep["independence"]["label_endpoints"]: A("- `%s`" % e) A("\n
\n") A("\n### Label definitions\n") A("Generated from the constants in `bench/labels.py`, not written by hand — the two " "had drifted apart and the published rule no longer matched the one applied.\n\n") A("- **dead**: traded for real at some point (peak 7d volume >= $%s), then price fell " ">= %.0f%% off its peak **and** 7d volume collapsed below %.0f%% of peak. A price " "drop alone isn't death, and neither is volume drying up alone.\n" % (format(LABELS.DEAD_PEAK_VOL_7D, ","), LABELS.DEAD_DRAWDOWN * 100, (1 - LABELS.DEAD_VOL_COLLAPSE) * 100)) A("- **alive**: >= %d days of history, drawdown <= %.0f%%, 7d volume >= %.0f%% of " "peak and >= $%s.\n" % (LABELS.ALIVE_MIN_DAYS, LABELS.ALIVE_MAX_DRAWDOWN * 100, LABELS.ALIVE_MIN_VOL_RATIO * 100, format(LABELS.ALIVE_MIN_VOL_7D, ","))) A("- **unsafe**: an unambiguously adversarial trait — cannot sell all / cannot buy / " "self-destructible / per-address tax / buy or sell tax > %.0f%% / closed source " "with privileged functions — outside the reputation guardrail.\n" % (LABELS.UNSAFE_TAX * 100)) A(" A honeypot flag counts **only** if the pool traded >= $%s in the last 7 days, or " "another adversarial trait corroborates it. The oracle raises that flag when its own " "sell simulation fails, and a sell simulation fails against an empty pool whatever " "the contract does — so on a dead pool the flag is unfalsifiable and the token is " "left unlabelled instead.\n" % format(LABELS.HONEYPOT_TESTABLE_VOL_7D, ",")) A("- **safe**: none of the above, plus open source, >= %s holders and taxes <= %.0f%%.\n" % (format(LABELS.SAFE_MIN_HOLDERS, ","), LABELS.SAFE_MAX_TAX * 100)) A("\nAnything in between goes unlabelled — a smaller sample beats dirty labels.\n") ov = rep["overall"] A("\n## Overall\n") A("| Metric | Value |") A("|---|---|") A("| Verdict distribution | %s |" % ", ".join("%s=%d" % kv for kv in sorted(ov["verdict_distribution"].items()))) A("| unknown rate | %s |" % _pct(ov["unknown_rate"])) A("| Share with a data gap | %s |" % _pct(ov["data_gap_rate"])) A("\n> Read the unknown rate next to recall. A tool that answers unknown for " "everything has perfect recall and is useless.\n") for key, title, bad_name, good_name in ( ("outcome", "Outcome labels (dead vs alive)", "dead", "alive"), ("goplus", "GoPlus held-out oracle (unsafe vs safe)", "unsafe", "safe")): r = rep[key] A("\n## %s\n" % title) for view, vtitle, note in ( ("full", "Full signals", ""), ("contract_only", "Contract-safety signals only (ablated)", "Recomputed after dropping liquidity/activity/freshness/cross-chain. " "This column is the engine's real judgement beyond the obvious.")): b, g = r[view]["bad"], r[view]["good"] A("\n### %s\n" % vtitle) if note: A("%s\n" % note) A("\n| | n | high | high or medium | low | unknown | mean score |") A("|---|---|---|---|---|---|---|") A("| **%s** | %d | %s | %s | %s | %s | %s |" % ( bad_name, b["n"], _pct(b["high"]), _pct(b["high_or_medium"]), _pct(b["low"]), _pct(b["unknown"]), _num(b["mean_score"]))) A("| **%s** | %d | %s | %s | %s | %s | %s |" % ( good_name, g["n"], _pct(g["high"]), _pct(g["high_or_medium"]), _pct(g["low"]), _pct(g["unknown"]), _num(g["mean_score"]))) drv = r.get("driving_categories_on_bad") or {} if drv: A("\n**Which signal category made the call on %s samples:** %s\n" % (bad_name, ", ".join("`%s` %d" % kv for kv in drv.items()))) A("\n> If this concentrates in `upstream_risk`, the engine is mostly " "paraphrasing honeypot.is and adds little of its own.\n") fb = rep.get("false_block") or {} if fb.get("n"): A("\n## False blocks: liquid healthy tokens rated medium or high\n") A("An agent refuses `medium` as well as `high`, so the false-positive rate above " "understates what a caller is turned away from. Population: outcome `alive` or " "oracle `centralized`, with $100,000 or more of depth.\n") A("\n**%s** (%d of %d). By driving signal: %s\n" % (_pct(fb["rate"]), fb["blocked"], fb["n"], ", ".join("`%s` %d" % kv for kv in fb["by_driver"].items()))) cen = rep.get("centralized") or {} if cen.get("n"): A("\n## Centralized-asset control group (not scored)\n") A("Tokens with privileged functions (pausable/blacklist/mintable) but " "**no adversarial traits** — USDT, WBTC and LDO all land here. Those " "privileges are how a centralized asset is designed, not a rug.\n") A("\nThis bucket answers one question: **does the engine paint them all as " "high risk.** A lot of high verdicts means the thresholds are too blunt and " "will produce grating false positives in real use.\n") A("\n| n | high rate | Verdict distribution |") A("|---|---|---|") A("| %d | %s | %s |" % ( cen["n"], _pct(cen["high_rate"]), ", ".join("%s=%d" % kv for kv in sorted(cen["verdict_distribution"].items())))) if cen.get("examples"): A("\nExamples: %s\n" % ", ".join( "%s(%s)" % (e["symbol"] or "?", e["verdict"]) for e in cen["examples"])) # Two oracles, two false-positive rates, and they answer different questions. # # An external audit found the headline rate was circular: measured against GoPlus-safe, # it is really "how often we disagree with GoPlus", and GoPlus is the benchmark's own # labeller. The proposed fix was to buy a second commercial oracle. The actual fix was # already on disk and had never been printed -- the realized market outcome is a # CAUSALLY INDEPENDENT oracle. GoPlus, honeypot.is and every commercial scanner answer # "what does this contract do under simulation". dead/alive answers "what happened to # the money". Those are different instruments, not two readings of one. # # So the report now states both, names the oracle behind each, and says which # population each describes. Neither is strictly the honest number: # - the outcome-based rate uses an INDEPENDENT oracle on a MATURITY-SELECTED cohort # - the GoPlus-based rate uses a BROADER cohort but a CIRCULAR oracle # Publishing one and calling it the headline is what let the circularity hide. # How often the label and the verdict are even about the same pool. # # build_dataset labels ONE sampled pool; assess() independently picks its own. When # they differ, a "false positive" may be the engine saying "this contract is a # honeypot right now" against a label saying "this pool traded healthily last week" -- # two answers to two different questions, booked as one error. The audit measured 84% # agreement and explicitly declined to publish a corrected false-positive rate, # because checking each disagreement showed its first correction was unsupported. # That restraint is right and the mismatch rate is still owed to a reader: it does # not tell you the number is wrong, it tells you how much of it is not a clean # comparison. same, different, unknown = outcome_pool_counts(rows) matched = same + different if rows: A("\n### Are the sampled pool and the assessed pool the same?\n") A("The dataset samples one pool, while the engine selects its own market.\n") if matched: A("The pools match on **%d of %d** rows with two verified identities on known " "chains (%.0f%%).\n" % (same, matched, 100.0 * same / matched)) A("Scope across all rows: %d same, %d different, %d unknown. " "Unknown includes missing or unverifiable pool IDs or chains.\n" % (same, different, unknown)) A("\nThat is a stricter question than the one an external audit measured. It " "found the labelled pool was among the pairs the engine *loaded* 84% of the " "time. Loading it and choosing it are different: the engine ranks by chain " "canonicality and depth and then judges a single pool, so it can hold the " "labelled pool in hand and still return a verdict about another venue. Both " "measurements describe venue coverage. A like-for-like outcome comparison also " "requires compatible observation times.\n") A("\nOn the rest, a disagreement is not necessarily an engine error -- it can be " "the engine judging a different venue than the one the label was computed from. " "No corrected false-positive rate is offered here: an attempt to produce one " "did not survive checking the individual rows. What is supported is that the " "headline rate mixes at least three kinds of disagreement, and this is how much " "of it is not a like-for-like comparison.\n") # What the `unsafe` cohort is made of, printed next to the recall it produces. # # HONEYPOT_TESTABLE_VOL_7D exists to stop a honeypot flag being asserted about a token # nothing has traded, and it works: it collapsed the cohort from 28 to 9. But what it # selects for is not what the report implied. Measured here rather than asserted: the # survivors are almost entirely tokens holding no liquidity at all, so the gate moved # the cutoff from "dead" to "died recently" -- it did not produce a cohort of # adversarial contracts, which is what a recall figure computed on it would suggest. # # A reader deciding how much the recall number is worth needs this in the same place # as the number, not in a commit message. unsafe_rows = [r for r in rows if r.get("goplus_label") == "unsafe"] if unsafe_rows: thin = [r for r in unsafe_rows if isinstance(r.get("liquidity_usd"), (int, float)) and r["liquidity_usd"] < 1] nolq = [r for r in unsafe_rows if r.get("liquidity_usd") is None] ours_disagree = [r for r in unsafe_rows if r["verdict"] in ("low", "medium")] by_chain = {} for r in unsafe_rows: by_chain[r["chain"]] = by_chain.get(r["chain"], 0) + 1 A("\n### What the `unsafe` cohort is, before you read a recall number off it\n") A("The adversarial cohort is **n=%d**, and it is not a sample of adversarial " "contracts in the wild. It is what survived a testability gate, and the gate " "selects for recency more than for hostility.\n" % len(unsafe_rows)) A("\n| Property | Count |") A("|---|---|") A("| holds under $1 of liquidity | %d of %d |" % (len(thin), len(unsafe_rows))) A("| no liquidity figure at all | %d of %d |" % (len(nolq), len(unsafe_rows))) A("| our engine rates them low or medium | %d of %d |" % (len(ours_disagree), len(unsafe_rows))) A("| chain concentration | %s |" % ", ".join("%s %d" % kv for kv in sorted(by_chain.items(), key=lambda kv: -kv[1]))) A("\n**Read the recall figure against that.** A cohort of %d tokens of which %d " "hold under a dollar is measuring whether we flag empty pools, which we do for " "reasons that have nothing to do with the contract being adversarial. And on " "%d of them our own engine disagrees with the labeller outright -- `results.md` " "presents the oracle's verdict as ground truth, and on those rows two " "instruments contradict each other and we cannot say which is right.\n" % (len(unsafe_rows), len(thin) + len(nolq), len(ours_disagree))) A("\nCleaning this cohort needs a **third, engine-independent oracle** -- " "requiring honeypot.is corroboration would make the label circular under B1/B2, " "since the engine reads honeypot.is. That is BACKLOG W5, and it is a " "prerequisite for W3 rather than the coverage fix it was originally filed as.\n") safe_rows = [r for r in rows if r.get("goplus_label") == "safe"] alive_rows = [r for r in rows if r.get("outcome_label") == "alive"] both_rows = [r for r in rows if r.get("goplus_label") == "safe" and r.get("outcome_label") == "alive"] if safe_rows and alive_rows: sh = len([r for r in safe_rows if r["verdict"] == "high"]) ah = len([r for r in alive_rows if r["verdict"] == "high"]) bh = len([r for r in both_rows if r["verdict"] == "high"]) A("\n### Two oracles, two false-positive rates\n") A("The false-positive rate depends on who is asked what a 'healthy token' is, and " "this benchmark has two answers available. They are reported together because " "reporting either alone hides something.\n") A("\n| Oracle | What it actually measures | Independent of us? | Cohort | FP rate |") A("|---|---|---|---|---|") A("| realized market outcome | what happened to the money | **yes** -- built from " "price/volume history, not from any contract scanner | `alive`, n=%d | **%.1f%%** " "(%d) |" % (len(alive_rows), 100.0 * ah / len(alive_rows), ah)) A("| GoPlus | what the contract does under simulation | **no** -- GoPlus is this " "benchmark's own labeller, so this is a disagreement rate | `safe`, n=%d | %.1f%% " "(%d) |" % (len(safe_rows), 100.0 * sh / len(safe_rows), sh)) A("| both, intersected | passes on both instruments | strictest available | n=%d | " "%.1f%% (%d) |" % (len(both_rows), 100.0 * bh / max(len(both_rows), 1), bh)) A("\n**Read it this way.** The outcome-based rate is the one to trust on method: " "market outcome is causally independent of every contract scanner, so it cannot " "be circular. Its weakness is population -- `alive` requires %d days of history " "and real weekly volume, so freshness signals cannot fire on those tokens and " "liquidity rarely does, while agents mostly ask about tokens younger than that.\n" % LABELS.ALIVE_MIN_DAYS) A("\nThe GoPlus-based rate has the better population -- it includes new tokens -- " "and the worse oracle, because a rate measured against our own labeller is a " "disagreement rate wearing a false-positive label. An audit was right to flag it. " "What the audit assumed, and what turned out to be false, is that breaking the " "circularity required buying an independent oracle. It did not. The independent " "oracle was already in this file and had simply never been crossed against the " "other one.\n") A("\nThe three figures are statistically consistent, which is the substantive " "finding: the circularity is real as a method problem and does not appear to be " "moving the number much. That is a claim with a confidence interval on it, not a " "reassurance -- n is %d on the independent side and the honest reading is that " "these rates are indistinguishable at this sample size, not that they are " "equal.\n" % len(alive_rows)) unk = [r for r in rows if r["verdict"] == "unknown"] if unk: ours = [r for r in unk if any(str(g).startswith("upstream request failed") for g in (r.get("gap_reasons") or []))] A("\n### What the unknown rate is made of\n") A("An `unknown` because we could not reach an upstream is a different thing from " "an `unknown` about the token, and only the second is a property of the engine. " "Reported separately because the first kind drifts between runs -- failed " "requests are not cached, so each run re-rolls them -- and because a harness " "that provokes refusals and then scores them has happened here twice.\n") A("\n| | n | share of all %d |" % len(rows)) A("|---|---|---|") A("| unknown, our side (upstream unreachable or uncovered) | %d | %.1f%% |" % (len(ours), 100.0 * len(ours) / len(rows))) A("| unknown, token side (nothing verifiable about it) | %d | %.1f%% |" % (len(unk) - len(ours), 100.0 * (len(unk) - len(ours)) / len(rows))) A("") comp = rep.get("composition") or {} if comp: A("\n## What the sample is made of\n") A("A recall figure describes a population, and this one's population is what " "three sampling sources could reach -- not the market. The bad cohort is the " "row that matters: it is the smallest, and if it sits on one chain from one " "source then the number describes that corner rather than the tool.\n") A("\n| | n | by chain | by source |") A("|---|---|---|---|") for key, label in (("all", "whole set"), ("bad", "**dead or unsafe**")): c = comp.get(key) or {} if not c: continue A("| %s | %d | %s | %s |" % ( label, c.get("n", 0), ", ".join("%s %d" % kv for kv in (c.get("chain") or {}).items()) or "-", ", ".join("%s %d" % kv for kv in (c.get("source") or {}).items()) or "-")) A("") dis = rep.get("disagreements") or [] if dis: A("\n## Disagreements (need manual review)\n") A("Rows retain their original benchmark counts and order. An outcome disagreement " "compares historical price and volume in the sampled pool with a snapshot-based " "assessment. Even a same-pool row does not measure whether the engine warned before " "the decline. A GoPlus disagreement compares a recorded contract label independently " "of the sampled pool's market outcome.\n") A("\n| Type | Token | Label chain | Label | Comparison scope | Label evidence | " "Engine verdict | Ablated | Driving signal |") A("|---|---|---|---|---|---|---|---|---|") rows_by_token = {(r["chain"], r["address"]): r for r in rows} pool_scope_names = {"same": "Same pool", "different": "Different pools", "different_chain": "Different chains", "unknown": "Unknown pool relationship"} for d in dis[:20]: if d["label"].startswith("outcome="): row = rows_by_token.get((d["chain"], d["address"]), {}) kind = "Outcome disagreement" scope = pool_scope_names[outcome_pool_scope(row)] basis = "Retrospective pool price and volume" else: kind, scope, basis = "Contract disagreement", "Contract-level label", "Recorded GoPlus response" A("| %s | `%s` | %s | %s | %s | %s | %s | %s | %s |" % ( kind, (d["symbol"] or d["address"][:10]), d["chain"], d["label"], scope, basis, d["verdict"], d["verdict_ablated"], d["driver"] or "—")) if len(dis) > 20: A("\n(%d more in `results.json`)\n" % (len(dis) - 20)) # Impersonation is the one dimension the GoPlus labeller cannot see, so a # disagreement there means something different from the others -- and saying so # is only honest if the number stays in the headline rate regardless. It does. blind = [d for d in dis if d["kind"] == "false positive" and d["label"].startswith("goplus") and d["driver"] == "impersonation"] if blind: A("\n### Counted as false positives, but outside the labeller's reach\n") A("%d of the false positives above were driven by `impersonation`. GoPlus " "reads bytecode and ownership; impersonation is a fact about identity, and " "an impostor's bytecode is usually perfectly ordinary. So GoPlus returns " "`safe` for a token it has no instrument to judge, and the disagreement is " "structural rather than evidence either way.\n" % len(blind)) A("\nThey stay in the headline rate anyway. A tool that subtracts its " "disagreements whenever it can explain them is grading its own homework, " "and an explanation is only worth something if it costs something. What " "this section buys is auditability: they are named, so a reader can check " "them one at a time instead of taking the framing on trust.\n") A("\n| Token | Chain | Verdict | Address |") A("|---|---|---|---|") for d in blind: A("| `%s` | %s | %s | `%s` |" % (d["symbol"] or "?", d["chain"], d["verdict"], d["address"])) A("\n## Reading the `dead` recall figure\n") A("The `dead` label describes price and volume decline in the sampled pool. The table " "summarizes liquidity estimates for the markets the engine assessed. A particular " "sale requires separate execution evidence.\n") def _q(rows_, sel): vals = sorted(r["liquidity_usd"] for r in rows_ if sel(r) and r.get("liquidity_usd") is not None) if not vals: return None n = len(vals) pick = [vals[0], vals[n // 4], vals[n // 2], vals[(3 * n) // 4], vals[-1]] return n, ["$%s" % format(int(v), ",") for v in pick] A("\n| | n | min | p25 | median | p75 | max |") A("|---|---|---|---|---|---|---|") for label, sel in (("`dead`", lambda r: r.get("outcome_label") == "dead"), ("`alive`", lambda r: r.get("outcome_label") == "alive")): q = _q(rows, sel) if q: A("| liquidity, %s | %d | %s |" % (label, q[0], " | ".join(q[1]))) dead_rows = [r for r in rows if r.get("outcome_label") == "dead"] still_liquid = len([r for r in dead_rows if (r.get("liquidity_usd") or 0) >= 5000]) A("\n%d of the %d assessments with a dead outcome label recorded at least $5,000 in " "estimated liquidity in the assessed pool. The outcome label describes the sampled " "pool, which may be a different market. Verifying a sale in a specific pool, from a " "particular wallet, or for a particular amount requires separate evidence.\n" % (still_liquid, len(dead_rows))) not_low = len([r for r in dead_rows if r["verdict"] != "low"]) A("\nOf %d cases with a dead outcome label, %d received a verdict other than `low`. " "The disagreements table gives the comparison scope for the remaining cases.\n" % (len(dead_rows), not_low)) A("\n**The limit this exposes.** The engine scores a market snapshot without the label's " "daily price history, so a token whose price is down 99% from a peak it cannot see looks " "like a quiet pool with working sells. Turnover cannot substitute: at the current " "2% threshold it catches roughly half the dead cohort at a cost of several percent " "of the live one, and loosening it doubles that cost for a few more points.\n") A("\nThe history that would catch it is GeckoTerminal daily OHLCV -- the exact series " "the `outcome` label is computed from. Wiring it into the engine would buy " "drawdown detection and simultaneously void this column as an independent " "measurement. That is a live trade-off, not an oversight, and it is recorded as an " "open decision rather than settled quietly.\n") A("\n## What this benchmark does not measure\n") A("1. **Whether it warns you in time.** The engine scores a market snapshot, and " "the `dead` label is retrospective. Some assessed pools were already drained by the " "market snapshot. The contract-only column removes that liquidity evidence. " "Answering 'would it have warned me before I bought' needs " "historical state replayed point-in-time, and the upstream security APIs don't " "serve history.\n") A("2. **Whether a specific sale will work.** The `dead` label measures historical price " "drawdown and volume collapse in the sampled pool. A particular sale requires its " "own execution evidence.\n") A("3. **GoPlus and honeypot.is may be correlated.** Both simulate buys and sells, " "so the `goplus` column flatters the engine. The `outcome` column doesn't have " "that problem.\n") A("**Sample bias.** Candidates come from three places: pool launches " "recovered from chain history, the daily snapshot archive of " "newly-listed pools, and per-chain pool rankings (which skew " "healthy and act as the control group). Each has a fixed share of " "the set. None is a random sample of what an agent would actually " "be asked about.\n") with open(RESULTS_MD, "w", encoding="utf-8") as f: f.write("\n".join(L) + "\n") if __name__ == "__main__": sys.exit(main())