CopeyBara

A fire exit for DeFi: withdraw straight from the contracts when the website is down or hijacked.

CopeyBara

Created At

ETHGlobal Mumbai

Project Description

When Curve's DNS was hijacked in 2022, nothing was wrong with Curve's smart contracts. People typed the right address, got a perfect copy of the site, and signed an approval to a drainer. It keeps happening. In October 2026 alone, a hijacked script on Polymarket hit 726 wallets, and a DNS hijack at Name.com sent a dozen DeFi sites to drainer copies. And when a frontend simply goes offline, loses its domain or loses the company behind it, the money is still on chain but out of reach for almost everyone. Today's fallback is Etherscan's "Write contract" tab, which is another website and will happily send an approval to a drainer.

Copeybara is a fire exit for DeFi: a way out that never goes through the front door. It has four parts that share one root of trust, the protocol's ENS v2 name.

The exit kit is one self-contained HTML file (258 KB) a user saves ahead of time. Its sha256 is published on the protocol's ENS name, so any copy can be checked from outside the browser. Type the ENS name and connect a wallet, and the kit finds your positions (Uniswap v3 and v4, Aave v3, Curve 3pool, plus any vault the protocol describes on ENS) and withdraws them straight from the contracts. Every read goes to three independent RPCs, and they must agree at a pinned block or the kit stops. Every transaction passes a fail-closed Exit Guard: it must target a contract in the protocol's on-chain Exit Plan, pay only your own address, move no ETH and contain no approvals, permits or transfers. There is no override. "Recovered" appears only after the receipt and a positive balance change for every token.

The Exit Plan on ENS makes the name the protocol's security root. A 2-of-3 Safe publishes the kit's hash, the Exit Plan, the website's script fingerprint and the extension's hash. ENS v2's Permissioned Resolver gives each key exactly one job: the website key can write url and nothing else.

The browser extension checks every script a protocol's site runs against that fingerprint. It blocks a compromised site before it loads, and stops drainer approvals and permits before the wallet shows them.

The watcher is an agent with its own ENS name (watcher.demoswap-blackout.eth). It can raise an alarm and blocklist look-alike domains, never touch a release, and the Safe can revoke it in one transaction.

Protocols set it all up with the Copeybara SDK: one config, one Safe batch, and a fire drill that switches off their own site and RPC.

It's live on Sepolia. A real attack replication drains a wallet through a hijacked clone, then the saved kit rescues the position with the site and RPC switched off. Measured:

  • The Curve 2022 victim's replay goes from 400,227.23 USDC lost to 0 (mainnet fork, counterfactual).
  • The real Ledger Connect Kit and Balancer hijack payloads are all flagged.
  • 696 of 697 PTXPhish drainer requests are stopped or asked.
  • Every attempt by a stolen website key to change the release reverts on chain.

No server, nothing for us to switch off. Verified, not trusted.

How it's Made

TypeScript monorepo (pnpm, 14 packages and 5 apps), Solidity and Foundry for the on-chain parts, viem everywhere, Preact for the UIs. There are 900+ unit tests, plus fork, Playwright and Foundry suites. Each piece:

ENS v2 (Sepolia). The kit's only baked-in address is the ENS v2 UniversalResolver proxy. Everything about a protocol comes from text records read at one pinned block through our RPC quorum: org.copeybara.release, .manifest, .exits, .site, .extension, .status and .blocklist.

  • A 2-of-3 Safe owns the name.
  • Each app gets its own PermissionedResolver, deployed through the VerifiableFactory. ENS v2 roles are per resolver, so one resolver per name keeps a role scoped to exactly one name.
  • Enhanced Access Control gives the website key the url setter only, and the watcher key status + blocklist only. We sent the attacks on chain: the website key trying to write the release, swap the resolver, upgrade the resolver proxy and grant itself roles. All of them revert. Nine must-revert cases also run as Foundry fork tests.
  • The watcher's identity is an ENS v2 subname: a token in a Safe-owned UserRegistry attached with setSubregistry, with its own resolver, addr = its key, and an org.copeybara.agent record listing what it may write.

Uniswap.

  • v3: discovery via NonfungiblePositionManager (balanceOf → tokenOfOwnerByIndex → positions). The exit is one multicall[decreaseLiquidity, collect(to = user)], with minimums from an eth_call simulation. A collect-only path covers owed-only positions, because decreaseLiquidity(0) reverts.
  • v4: positions aren't enumerable, so we combine balanceOf, a Transfer log scan in 10k-block chunks through the quorum, an ownerOf check, and add-by-ID. The exit is one PositionManager.modifyLiquidities([DECREASE_LIQUIDITY, TAKE_PAIR]). modifyLiquidities returns no amounts, so we ported TickMath and SqrtPriceMath to bigint and read StateView for minimums. They match on-chain results to the wei.
  • The Guard decodes v4 action lists and bans SETTLE*, INCREASE, MINT, SWEEP and TAKE*, which could pull tokens through a live Permit2 allowance. Hook permission bits come from the hook address, so pools with remove-liquidity hooks get a warning badge.
  • A table of Permit2, the Universal Routers and the position managers keeps the normal Uniswap flow from raising false alarms in the extension.

The exit kit. Vite + Preact built into a single HTML file with exactly one inline script, pinned by hash in a CSP meta tag. No external assets, zero third-party requests (Playwright-verified), and reproducible bytes (SOURCE_DATE_EPOCH=0). Its only wallet methods are connect/chain methods, eth_estimateGas and eth_sendTransaction. It never asks for typed-data signatures.

The quorum. Three providers, 4 s timeout, 2 retries. At least two must answer, and all must agree. Heads more than 16 blocks from the median are dropped, so one stale provider can't serve an old release.

The extension (MV3).

  • The service worker is the only place that decides: it reads ENS through the quorum, computes every verdict and checks the sender of each message.
  • An isolated content script hashes every script from document_start.
  • A MAIN-world shim wraps EIP-1193/6963 providers and decides nothing.
  • declarativeNetRequest rules block compromised or blocklisted sites before a byte loads.
  • Zips are reproducible. A tree hash lets you verify an already-unpacked install against ENS.

The watcher. Two mismatches in a row write status=compromised, and it only clears alarms it raised. With an Anthropic key, Claude writes the one-line warning from structured facts only.

SDK. The copeybara CLI (manifest, release, fingerprint, propose, verify, roles-check, drill, certify, incident) never holds a key. Every write is one Safe Transaction Builder batch checked against its allowed scope. There are also Vite, Next and webpack plugins that fail the build on an unpinned third-party script.

The hacky bits:

  • The Curve 2022 hijack replayed with Foundry vm.transact at block 15309928. The Guard rejects the victim's real approve calldata.
  • 62,300 generated property cases against the Guard, 0 counterexamples.
  • Benchmarks on real data: PTXPhish (NDSS'25), 14,130 ScamSniffer domains, and the actual Ledger Connect Kit 1.1.5–1.1.7 bytes from the CDN.
  • An Attack Theater that runs a real drain and a real rescue on Sepolia, with a primary RPC proxy we can kill live.

Honest scope: Sepolia only, the demo Safe's three keys are on one machine, and it doesn't protect against bugs in a protocol's own contracts. The full threat model is in the README.

background image mobile

Join the mailing list

Get the latest news and updates