Ethereum Rescue
eth-rescue moves assets and contract control out of an Ethereum account whose private key or seed phrase has been compromised, using private Flashbots bundles so a sweeper bot never sees ETH arrive in the wallet.
You build a rescue plan (plan.json) in the web plan builder, or by hand, and the CLI runs it. The plan holds addresses only. The CLI asks for private keys in a hidden prompt on your own machine.
User guide
Requirements
- uv. It fetches a compatible Python automatically.
- Network access to the public RPC and the Flashbots relay.
Commands
Run a pinned release so a cached older eth-rescue, with a different plan format, is never used:
uvx eth-rescue@1.0.0 --help
uvx eth-rescue@1.0.0 gas-wallet new # optional: a fresh wallet to pay fees (--out FILE saves the key to a private file)
uvx eth-rescue@1.0.0 validate plan.json # schema + calldata check, offline, no keys
uvx eth-rescue@1.0.0 simulate plan.json # build and simulate phase 1, never sends
uvx eth-rescue@1.0.0 run plan.json # the rescue
uvx eth-rescue@1.0.0 schema # print the plan JSON Schema
Each command's --help lists its flags and exit codes. --json prints NDJSON events on stdout; warnings and errors go to stderr. To use your own RPC, set ETH_RESCUE_RPC_URL rather than passing --rpc, so an API key in the URL stays out of your shell history (printed errors never show URL paths).
Accounts
- Compromised wallet (
compromised): holds what is being rescued. You type its private key. - Gas wallet: pays every fee. It must be a plain account with no code.
gas-wallet newprints a fresh one; save its key until you have recovered any leftover balance. - Destination wallet (
destination): receives every typed asset and all ETH left in the compromised wallet. It must differ from both other wallets, and only its address is needed. It can be an ordinary account or a smart wallet such as a Safe multisig. A smart wallet must already be deployed on the plan's network, accept ETH and ERC-1155s (onERC1155Received), and be able to make arbitrary calls, because ERC-721s arrive bytransferFrom, which never checks whether the receiver can move them on.
What run does
- Reads the plan and asks for the compromised-wallet and gas-wallet keys. If the plan names a
gas_wallet, the key must match it. - Checks that the network's EthRescue deployment is the pinned build (runtime codehash), and shows what the plan will do: network, the three wallets, every custom call, and whether the fallback is on.
- Waits until the gas wallet holds enough ETH, printing the amount. The amount covers base fees rising every block of a five-block window.
- Phase 1, EIP-7702. One or more transactions from the gas wallet delegate the compromised wallet to the EthRescue singleton and run every action as that wallet. An EIP-712 request signed by the compromised wallet binds the gas wallet, the destination wallet, a deadline and the exact action list. Each action reports its own result, so one failing action never blocks the others. The remaining ETH is swept to the destination wallet in the same transaction.
- Simulates the exact signed bundle on the relay, then asks once before sending.
- Submits for five blocks at a time, rebuilding with fresh nonces and fees between windows, until included or
options.max_blocksblocks have been submitted. Before each rebuild it checks whether an earlier bundle landed. If the gas wallet's nonce moved and no bundle is visible, it stops instead of resubmitting. - Checks each action at the inclusion block: the destination wallet's ERC-20/ERC-1155 balance went up by the amount, or the destination wallet now owns the NFT or the contract.
- Phase 2, legacy fallback (
options.legacy_fallback, default on). Actions that failed or never ran are retried as direct transactions from the compromised wallet: clear the delegation, fund the wallet, send each action, sweep the ETH. It runs without asking again. An action that reverts in simulation, in any window, is left out so it cannot block the rest. Unverified and partial actions are never retried. The sweep is signed before the gas used is known, so unused gas money stays in the compromised wallet; the CLI prints the most that can be left behind. - Prints the outcome table, the ETH left in the compromised wallet, and its delegation.
If the compromised wallet's nonce changes before the phase-1 transaction in the same block, its EIP-7702 authorization is skipped: the transaction succeeds but rescues nothing. Step 7 reports those actions failed, and phase 2 (or a rerun) retries them.
Outcomes and exit codes
Each action ends rescued, partial (some of the amount arrived, or an Ownable2Step contract now lists the destination wallet as its pending owner: call acceptOwnership() from the destination wallet), unverified (it ran, but nothing can check it: custom calls and delists), failed, or not executed. Confirm unverified actions yourself. A delist that has no effect while its NFT still reaches the destination wallet (it was not listed) does not count against the rescue.
| Code | Meaning |
|---|---|
| 0 | Included; every checkable action verified |
| 1 | Invalid plan, arguments, keys, network or deployment, or an RPC error before anything was sent |
| 2 | Simulation failed; nothing was sent |
| 3 | The gas wallet was not funded in time |
| 4 | Not included within max_blocks, or it cannot tell whether a bundle landed. Check the gas wallet's latest transactions on a block explorer before running again |
| 5 | Included, but an action was not rescued (after the fallback, when enabled) |
| 6 | Declined at the confirmation |
| 130 | Interrupted. The message says whether a bundle was already submitted (it may still be included) |
When phase 1 lands and phase 2 cannot finish, the exit code is 4 if phase 2's inclusion is unknown, 3 if its funding ran out, and 5 otherwise.
Plan format
{
"version": 1,
"network": "mainnet",
"compromised": "0xd068c6A6db349A8Ce9C7aD3706391e53417abF61",
"destination": "0x74A7b842FDeb244C152aa5BC8B7fbae362091EE1",
"gas_wallet": "0x2546BcD3c84621e976D8185a91A922aE77ECEc30",
"options": { "priority_fee_gwei": "2.5", "max_blocks": 25, "legacy_fallback": true },
"actions": [
{ "type": "erc20", "contract": "0x…", "amount": "1000000000000000000" },
{ "type": "erc721", "contract": "0x…", "token_id": "78" },
{ "type": "erc1155", "contract": "0x…", "token_id": "3", "amount": "5" },
{ "type": "ownership", "contract": "0x…" },
{ "type": "transient_delist_erc721", "auction_house": "0x…", "contract": "0x…", "token_id": "12" },
{ "type": "cryptopunk", "token_id": "78" },
{ "type": "superrare_v1", "token_id": "43" },
{ "type": "custom", "target": "0x…", "signature": "setApprovalForAll(address,bool)", "args": ["0x…", true], "gas": 75000 }
]
}
- Amounts, token IDs and the priority fee are decimal strings, so browsers never round them. Amounts must be above zero.
priority_fee_gweiis added to every gas unit; the CLI warns above 50 gwei. - Addresses must be valid checksums (or all lowercase or all uppercase), non-zero, and no action may target the compromised wallet.
- Every action takes an optional
labelandgas(a minimum; the CLI raises it from a live estimate). cryptopunkandsuperrare_v1rescue collections that predate ERC-721 and have notransferFrom. The contract comes from the network (eth_rescue/collections.py), so only the token ID is given; Punks are numbered 0 to 9999. A generic action pointed at either contract is rejected, because it would fail.customcalls the target as the compromised wallet; its arguments, notdestination, decide where anything goes. The signature must be canonical (uint256, notuint; no parameter names, spaces orreturns), because the selector is the hash of that exact text. Arguments are strict JSON: integers as numbers or decimal/0xstrings,boolastrue/false,bytesas0xhex of whole bytes, addresses as checksummed or lowercase hex, arrays and tuples as JSON arrays.
schema/plan.v1.schema.json is the JSON Schema. The CLI also checks what a schema cannot express: address checksums, distinct wallets, the uint256 range and canonical signatures, so run validate on a plan. examples/ has sample plans with placeholder addresses.
Networks
The CLI runs on Ethereum mainnet only. Testnet Flashbots relays rarely land bundles, so a testnet run can't show whether a rescue would work. The integration suite instead runs every rescue flow against the real EthRescue deployment on a fork of a live network (see Integration tests).
Web plan builder
web/ is a static Vite + React app that builds plan.json from addresses. It never asks for keys, and it refuses input that looks like a private key or seed phrase. It can look up what the compromised wallet holds (Alchemy for tokens and NFTs, the Transient API for listings and creator contracts); names come from those providers, so check every address before adding it. The draft is saved in the browser, except custom-call arguments.
Developer guide
git clone https://github.com/mpeyfuss/eth-rescue.git
cd eth-rescue
uv sync
uv run eth-rescue --help
| Command | What it does |
|---|---|
make fmt / make lint |
Ruff format and lint |
make test |
Python unit tests |
make test-integration |
Compile fixtures, run the Anvil suite on Osaka and Amsterdam |
make test-fork |
Run the Anvil suite on a fork of Sepolia, against its EthRescue deployment (needs network access) |
make schema |
Regenerate the plan schema and the web's TypeScript types |
make web-install / web-dev / web-test / web-build |
The web app (Bun) |
make test-all |
Unit, integration and web tests |
Contract tests: cd contracts && forge test.
eth_rescue/: plan.py (models, expansion), calldata.py (ABI rules), bundle.py (building and signing), engine.py (fund → simulate → send → verify → fallback), checks.py (postconditions), relay.py (Flashbots), cli.py, report.py/ui.py (output).
The ABI rules are shared with the web builder through tests/fixtures/abi_vectors.json: tests/test_calldata.py and web/test/custom.test.ts must agree on every vector, so a plan the builder accepts encodes to the same bytes in the CLI.
Gas and forks
EthRescue never checks gas itself, so the CLI's budget is all that stands between a rescue and starved actions. The constants and their reasoning live in eth_rescue/bundle.py. The rules:
- Measure, don't hardcode. Each action's gas limit is a live
eth_estimateGas×--gas-multiplier, with the template's gas as a floor that an estimate can only raise. The cost of sweeping to an empty destination comes from a live transfer estimate. - Size once, before any delegation changes. Phase-1 estimates also describe the undelegated wallet that the legacy fallback runs as.
- Budget per rescue transaction:
RESCUE_TX_FIXED_GAS+SWEEP_CALL_GAS+ the destination wallet's receive cost + Σ(stipend + stipend/63 +RESCUE_ACTION_OVERHEAD_GAS+ calldata at 40 gas/byte). The stipend/63 term is what makes EIP-150 forward the full stipend. - Estimates only raise the budget. Each transaction's limit is max(budget, whole-transaction estimate × 1.5). The node's estimator can't see an action starving inside
rescue(), because the transaction still succeeds, so an estimate is never used alone. If the RPC can't estimate (no type-4 or state-override support), the budget stands and the CLI warns. - Never exceed 2^24 gas per transaction. Under EIP-8037, gas above the EIP-7825 cap becomes a state-gas reservoir that
gasleft()can't see and that bypasses call stipends. - Test every fork.
make test-integrationruns Osaka and Amsterdam with EIP-7825 enforced, and the gas-burner test asserts worst-case overhead uses at most 75% of its budget.
Measured on Anvil:
| Operation | Osaka | Amsterdam |
|---|---|---|
| Rescue tx: 1 ERC-721 action, fresh destination | 95.4k | 300.8k |
| ETH transfer to a fresh account | 21k | 204.6k |
| ERC-20 / ERC-1155 transfer to a fresh holder | 50k / 52k | 139.5k / 141k |
| Set 7702 delegation / clear it | 36.8k / 36.8k | 64k / 28.8k |
| Rescue overhead per action (calldata included) | ~5.3k | ~5.3k |
Integration tests
The integration suite needs forge and anvil from Foundry. Its relay double (tests/integration/conftest.py) gives bundles Flashbots semantics on Anvil: a bundle lands atomically, in order, in its target block, or not at all, and blocks advance only when the engine waits. It does not model builder competition, privacy or real base-fee movement, and it never contacts a relay.
make test-fork runs the same suite on an Anvil fork of a live network (FORK_NETWORK, default sepolia) at one block pinned for the run. It uses that network's EthRescue deployment instead of a fresh one: every run checks the pinned codehash, and a dedicated test checks that the deployed code is this checkout's build apart from its EIP-712 immutables. Sepolia's deployment is pinned in tests/integration/conftest.py, since Sepolia is not a CLI network; any network pinned in networks.py (mainnet) can be forked too, e.g. make test-fork FORK_NETWORK=mainnet. FORK_RPC_URL overrides the public RPC, and FORK_HARDFORK (default osaka) must match the live chain's fork, because Anvil otherwise assumes its newest one.
License
This project is available under the MIT License.
Metadata
Release files for eth-rescue 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| eth_rescue-1.0.0.tar.gz | 53.3 kB | With provenance | Details for eth_rescue-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| eth_rescue-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for eth_rescue-1.0.0-py3-none-any.whl |
Total release size: 113.0 kB
Release files / eth_rescue-1.0.0.tar.gz
| Download URL | eth_rescue-1.0.0.tar.gz |
|---|---|
| Size | 53.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e4f56a179a52cdea8f658c2fa0889fa01bc63cc408f40a8706cb7d9ac7770f3
|
|
BLAKE2b-256 checksum How to use checksums |
2c65d77632cab1c9e0c030342dc517f63a2ae149d4838fbe5318122fd20acbfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logRelease files / eth_rescue-1.0.0-py3-none-any.whl
| Download URL | eth_rescue-1.0.0-py3-none-any.whl |
|---|---|
| Size | 59.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f8a8869b66b55a856957f2269451e3cdb2cade1bfdd3716da022e1e41b0630d9
|
|
BLAKE2b-256 checksum How to use checksums |
2190d56805402d2e116032ad3968548aea3ab72c00aed23d90a01bb01928a922
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logSecurity for eth-rescue 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for eth_rescue-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.