File size: 2,373 Bytes
808efc6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #!/usr/bin/env python3
"""Integrity check for the DeFiReplay package (no model involved).
For every TRAIN task (whose reference solution ships): the golden must score 1,
and an empty answer must score 0. For every TEST task (no solution shipped): an
empty answer must score 0 and the grading oracle must be present in meta.json.
Prints one line per task and a final JSON summary; exit code 0 iff bad == 0.
Usage: python3 scripts/validate_split.py [threads]
Requires Foundry and a mainnet RPC (ETH_RPC_URL). This recompiles+forks every
task, so a full run is slow on a cold RPC cache; pass a small thread count.
"""
import json, sys, os
from pathlib import Path
from concurrent.futures import ThreadPoolExecutor
REPO = Path(__file__).resolve().parent.parent
os.environ.setdefault("DEFIREPLAY_ROOT", str(REPO))
sys.path.insert(0, str(REPO / "verifier"))
import foundry_verifier as fv # noqa: E402
def rows(split):
return [json.loads(l) for l in open(REPO / "data" / f"{split}.jsonl")]
def ref(inc):
return json.dumps({"incident": inc, "registry": f"tasks/{inc}", "tier": "scaffolded"})
def check_train(r):
inc = r["incident"]
gold = r["reference_solution"]
if "```" not in gold:
gold = "```solidity\n" + gold + "\n```"
g, _ = fv.evaluate_foundry(gold, ref(inc))
e, _ = fv.evaluate_foundry("```solidity\n\n```", ref(inc))
ok = g == 1 and e == 0
return ("train", inc, ok, f"golden={g} empty={e}")
def check_test(r):
inc = r["incident"]
meta = json.loads((REPO / "tasks" / inc / "meta.json").read_text())
orc = (meta.get("oracle") or {})
has_oracle = orc.get("needs_calibration") is False and orc.get("min_profit") is not None
e, _ = fv.evaluate_foundry("```solidity\n\n```", ref(inc))
ok = has_oracle and e == 0
return ("test", inc, ok, f"oracle={has_oracle} empty={e}")
def main():
threads = int(sys.argv[1]) if len(sys.argv) > 1 else 2
jobs = [(check_train, r) for r in rows("train")] + [(check_test, r) for r in rows("test")]
bad = 0
with ThreadPoolExecutor(threads) as ex:
for split, inc, ok, why in ex.map(lambda j: j[0](j[1]), jobs):
bad += not ok
print(("OK " if ok else "BAD "), split, inc, why, flush=True)
print(json.dumps({"tasks": len(jobs), "bad": bad}))
sys.exit(1 if bad else 0)
if __name__ == "__main__":
main()
|