Research artifact for The Ghosts of Polymarket: When Off-Chain Matches Meet On-Chain Reverts.
Warning
Ethics Statement. This repository selectively open-sources the methodology part: detection rules, analysis scripts, and reproducible SQL queries, but does not include raw detection outputs, attacker address lists, or any other data that could be used to identify or target specific entities. We also omit Polymarket market slug/name mappings, as some market titles reference politically or religiously sensitive topics.
GhostHunter is a lightweight on-chain transaction analysis engine that detects and classifies reverted Polymarket CLOB matchOrders on Polygon (i.e., Ghost Fills). It decodes calldata, replays execution traces, and runs a prioritized rule chain to attribute each revert to an attack vector: Proxy Trap, Nonce Bump, Allowance Revoke, or Balance Drain.
src/ghost_hunter/ Detection engine (decoder, trace context, rule loader, rules)
main.py CLI entry point
config.yml Contract addresses, selectors, revert decoders, rule config
tests/ Unit tests
rq1/ RQ1 analysis scripts + BigQuery SQL (v1.sql, v2.sql)
rq2/ RQ2 analysis script + proxy-trap bytecode collectors
rq3/ RQ3 cross-chain reuse: SQL sweeps + reuse analysis scripts
discussion/ Profit measurement and liquidity-reward analysis scripts
Requires Python 3.12+ and uv.
uv syncCreate a .env file with your API keys (needed for the scanner and some analysis scripts):
ETHERSCAN_API_KEY=...
ALCHEMY_API_KEY=...
Multiple keys can be added by suffixing with _2, _3, etc.
GhostHunter operates on parquet files of reverted matchOrders() transactions. Use the provided SQL to query Google BigQuery's bigquery-public-data.crypto_polygon.transactions table:
# V1 matchOrders (selector 0x2287e350, 2025-08-15 to 2026-04-28)
# → see rq1/v1.sql
# V2 matchOrders (selector 0x3c2b4399, from 2026-04-28)
# → see rq1/v2.sqlExport the results as parquet files into a local directory (e.g. parquets/v1/, parquets/v2/).
# Scan V1 reverts
uv run main.py scan --parquet-dir parquets/v1 --output output/v1_findings.jsonl
# Scan V2 reverts
uv run main.py scan --parquet-dir parquets/v2 --output output/v2_findings.jsonlEach finding includes the transaction hash, block number, decoded order data, matched rule, and classification details.
uv run python rq1/rq1_analysis.py # RQ1: prevalence tables + daily revert figure
uv run python rq2/rq2_analysis.py # RQ2: per-vector breakdown + stacked figure
uv run python discussion/profit_measurement.pyTo export the attacker address list from the findings:
uv run python discussion/export_attackers.pyRQ3 uses Dune Analytics SQL to sweep for contract reuse across chains. The queries are in rq3/sql/ (numbered 01–09). Run them on Dune and export the results as CSV into rq3/csv/. Then:
uv run python rq3/reuse/analyze_reuse.py--parquet-dir <dir>— Directory to scan recursively for parquet files. Repeatable.--parquet-file <file>— Single parquet file to scan. Repeatable.--output <path>— Output JSONL file path. Defaults tooutput/findings.jsonl.-v, --verbose— Enable debug logging.
config.yml defines the rule priority chain, contract addresses, method selectors, revert error decoders, and performance settings. The default rule order is:
- Proxy Trap — onERC1155Received callback revert
- Nonce Bump — V1 incrementNonce() invalidation
- Allowance Revoke — collateral approval change
- Balance Drain — collateral transfer-out with gas_ratio > 1
MIT
Note
This artifact is released for academic research only.