The emergencyWithdrawERC20
function only hardcodes protection for a few tokens (i.e., iWETH
, iWBTC
, iWSOL
, and iUSDC
). However, it does not check if a token is allowed for active sell orders, which are tracked via the allowedSellToken
mapping.
The emergencyWithdrawERC20
function is designed to prevent withdrawal of core assets (iWETH
, iWBTC
, iWSOL
, and iUSDC
) to safeguard order book liquidity. However, it fails to account for other tokens that may be dynamically marked as allowed for trading using setAllowedSellToken
. As a result, the owner can add new tradeable tokens and later withdraw them via the emergency function, bypassing core asset protection.
setAllowedSellToken
emergencyWithdrawERC20
Likelihood: High — easy to exploit if malicious owner
Severity: High — leads to unauthorized withdrawal
Critical protocol assets, once marked allowed via setAllowedSellToken
, can be silently drained by the owner.
Test Setup:
A mock address ayo
is created to simulate a user.
A new MockDAI
token is deployed.
ayo
is minted 30 DAI tokens.
Token Approval for Trading:
The contract owner calls setAllowedSellToken(dai, true)
, allowing DAI
to be used in sell orders.
Creating a Legitimate Sell Order:
ayo
approves the contract to spend 20 DAI.
ayo
creates a sell order for 20 DAI at a price of 180,000 USDC.
The order is successfully stored, and 20 DAI are held by the contract (book
).
The Exploit:
The owner calls emergencyWithdrawERC20()
to steal the 20 DAI in the contract before the order is bought.
Since DAI
is not among the hardcoded "core" tokens (iWETH
, iWBTC
, iWSOL
, iUSDC
), and there’s no check for allowedSellToken
, the withdrawal succeeds.
Post-Conditions Verified:
Owner now holds the 20 DAI.
The contract holds zero DAI, even though an active sell order exists.
Modify emergencyWithdrawERC20
to also check allowedSellToken[_tokenAddress]
:
Or combine the check:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.