Download scripts/validate_split.py from zZmey/DeFiReplay: direct link, hf CLI and curl.
- Browser
- Download file 2.37 kB
-
https://huggingface.co/datasets/zZmey/DeFiReplay/resolve/main/scripts/validate_split.py
- Command line
-
hf download hf://datasets/zZmey/DeFiReplay/scripts/validate_split.py
-
curl -L -o validate_split.py https://huggingface.co/datasets/zZmey/DeFiReplay/resolve/main/scripts/validate_split.py
2.37 kB
| #!/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() | |