Dev.to Security 🔐 Cybersecurity 👁 0 📖 3 min read

How UNSWEEP Tests and Verifies Its EIP-7702 Token Recovery Contracts

When a wallet's private key is compromised by a sweeper bot, sending ETH for gas to rescue remaining ERC-20 tokens usually fails—the bot drains the gas before the recovery transaction lands. UNSWEEP (unsweep/unsweep, MI

When a wallet's private key is compromised by a sweeper bot, sending ETH for gas to rescue remaining ERC-20 tokens usually fails—the bot drains the gas before the recovery transaction lands.

UNSWEEP (unsweep/unsweep, MIT) uses EIP-7702 delegation plus a relayer so a compromised EOA can sign a rescue intent locally in the browser without funding gas on the compromised address.

Because asking users to sign with a compromised private key is inherently sensitive, claiming "it's safe" is useless. Instead, we published a reproducible technical evidence package so any developer or security researcher can verify the contracts, tests, static analysis, and production frontend independently.

Disclaimer: This is not a third-party professional audit. It is a reproducible engineering baseline (Foundry + Slither + bytecode/hash checks + manual review) with open findings documented transparently.

1. Contract Testing with Foundry

The core delegate contract (src/UnsweepDelegate.sol) is compiled with solc 0.8.39 (EVM prague, optimizer 200, via_ir) and tested with Foundry (forge 1.10.0).

git clone [https://github.com/unsweep/unsweep.git](https://github.com/unsweep/unsweep.git)
cd unsweep
forge build
forge test -vv

Current baseline (docs/security/forge-test.txt):

  • 36 tests passed, 0 failed, 0 skipped across 4 suites: Unsweep.t.sol, Hardening.t.sol, M4.t.sol, and M4c.t.sol.
  • Key invariants covered:
    • EIP-712 domain & replay protection: verifyingContract is the EOA itself, high-s signatures are rejected, bitmap nonces prevent replay, and deadline bounds execution.
    • Transient reentrancy lock: tload/tstore guard around rescue execution.
    • Cross-stack digest parity: Python tests (relayer/test_typehash_parity.py and relayer/test_digest_parity_appjs.py) verify that Solidity, Python (relayer/eip712.py), and the browser's web/assets/app.js produce identical EIP-712 RESCUE_TYPEHASH and digests.

2. Static Analysis (Slither)

Running Slither (0.11.6) against the project contracts:

slither . --filter-paths "lib/|node_modules/|test/|script/"

Out of 25 filtered findings in UnsweepDelegate.sol (raw outputs in docs/security/):

  • 1 High (reentrancy-balance, line 134): Justified false positive. The function is guarded by a transient storage lock (tload/tstore), and pre/post balanceOf reads intentionally measure actual received amounts to bound fees.
  • 1 Real Low (locked-ether, line 21 / receive line 91): ETH sent directly to the implementation contract address is locked (EOAs delegating via EIP-7702 still control their own ETH).
  • Remaining items are calls-loop (by design), timestamp (deadline), reentrancy-events, and informational notes.

3. Verifying On-Chain Bytecode & Production Frontend

Tests in a repo only matter if production matches the repo.

On-Chain Bytecode (Base & Arbitrum One)

Both contracts are deployed at:

  • UnsweepDelegate: 0x38bcF425bC4d13624734e09376F2fafc799fA8c8
  • UnsweepConfig: 0x56a345661e3999F2b20f1E069aAC14097Fa0D118

On Base, both contracts have verified source code on Basescan. On Arbitrum One (checked at block 527221874), the runtime bytecode (6059 B Delegate, 881 B Config) matches forge build at HEAD byte-for-byte once immutable references are masked.

Production Frontend Hash Check

The signing logic lives in web/assets/app.js (the private key is used locally with ethers.js and never sent to /api/rescue). Anyone can verify that the script served by https://unsweep.com matches the repository:

curl -s [https://unsweep.com/assets/app.js](https://unsweep.com/assets/app.js) | sha256sum
sha256sum web/assets/app.js

4. Known Limitations (Documented Openly)

We track unresolved issues publicly in SECURITY_EVIDENCE.md and our HackMD security summary:

  1. C-1 / R-5 (Medium): In UnsweepDelegate.sol, minFees[j] is bounded by token balance (bal) rather than MAX_FEE_BPS (15%). While the relayer enforces the 15% cap during quoting, submission only checks the minFees array length. Exploiting this still requires the victim's EIP-712 signature, but it is a real gap to close.
  2. W-7 (Low): readKey() clears the private key input (#pk) from the DOM when signing starts, but early validation returns or navigating back between steps do not clear it yet.
  3. No third-party audit yet: Independent review of the contracts, relayer, and frontend is still needed.

Feedback Welcome

If you work on Solidity, EIP-7702, or Web3 security, we'd appreciate critical review:

Open an issue or PR if you find anything we missed.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.