Closes #354
Contracts that receive ETH or ERC-20 tokens—or that implement a pause/emergency mechanism—without any fund-recovery path risk permanently locking user funds if a critical bug is found, an admin key is lost, or the contract is paused indefinitely.
Implemented a new rule at rules/security/emergency/detect-missing-emergency-withdrawal.ts that statically analyzes Solidity source and flags contracts that:
- Receive ETH (
receive(),fallback(), payable functions,msg.value) but expose nowithdraw,rescue,recover,emergencyExit,drain, orsweepfunction and noselfdestructcall. - Interact with ERC-20 tokens (
IERC20,transferFrom,safeTransferFrom,.transfer(,.balanceOf() but expose no rescue/recovery function. - Use a pause/emergency pattern (
pause(),whenNotPaused,emergency,lockdown) but provide no corresponding fund-recovery path.
Each violation includes:
- The contract name and line number of the
contractdeclaration. - A human-readable reason explaining the risk.
- An actionable suggestion with a ready-to-use code template for the appropriate emergency flow.
| File | Description |
|---|---|
rules/security/emergency/detect-missing-emergency-withdrawal.ts |
New rule implementation |
tests/rules/detect-missing-emergency-withdrawal.spec.ts |
Comprehensive tests covering all violation kinds, clean contracts, multiple contracts, and line-number accuracy |
- Missing emergency withdrawals flagged (
eth-receiver-no-withdrawal,token-handler-no-withdrawal,pausable-no-withdrawal) - Missing recovery methods detected
- Emergency flow suggestions provided per violation kind
- Clean contracts (with recovery methods or
selfdestruct) are not flagged - Tests cover all scenarios