The emergencyWithdrawERC20 function does not check if the token transfer was successful, which could lead to inconsistent state if the transfer fails silently.
The emergencyWithdrawERC20 function is designed to allow the contract owner to withdraw any non-core tokens that might have been sent to the contract by mistake. While the function correctly uses safeTransfer from OpenZeppelin's SafeERC20 library, which will revert if the transfer fails, there is still a potential issue with tokens that have unusual behaviour or non-standard implementations. Some ERC20 tokens, despite being compliant with the standard interface, might have custom behaviour that could cause transfers to fail silently or return false without reverting. In such cases, the contract would proceed as if the transfer was successful, emitting the EmergencyWithdrawal event. The tokens remain in the contract, but the contract and off-chain systems believe they have been withdrawn.
A non-standard ERC20 token is accidentally sent to the contract.
The owner calls emergencyWithdrawERC20 to recover these tokens.
The token's transfer function silently fails without reverting.
The contract proceeds as if the transfer was successful, emitting the EmergencyWithdrawal event.
The tokens remain in the contract, but the contract and off-chain systems believe they have been withdrawn.
Impact: Low - The potential impact is limited to non-standard tokens and would only affect emergency withdrawals.
Likelihood: Low - Most ERC20 tokens follow the standard behaviour, and SafeERC20 mitigates many issues.
OrderBook.sol
Although SafeERC20's safeTransfer already provides significant protection, for maximum safety, consider checking the token balance before and after the transfer to ensure it was successful, especially for critical functions like emergency withdrawals.
The proposed fix adds balance checks before and after the token transfer to ensure that the expected amount was actually transferred. This provides an additional layer of safety beyond what SafeERC20 offers, ensuring that the contract's state accurately reflects the token balances.
The `emergencyWithdrawERC20()` function does not check if the token transfer was successful, which could lead to inconsistent state if the transfer fails silently.
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.