Unable To Call emergencyWithdraw ETH in NoYield Contract
The emergencyWithdraw function in the NoYield contract cannot withdraw ETH because it treats ETH as a zero address and calls balanceOf on that address, which reverts. As a result, the owner cannot recover ETH in an emergency, leaving funds stuck.
Submitted by leastwood
Impact
The emergencyWithdraw function is implemented in all yield sources to allow the onlyOwner role to drain the contract’s balance in case of emergency. The contract considers ETH as a zero address asset. However, there is a call made on _asset which will revert if it is the zero address. As a result, ETH tokens can never be withdrawn from the NoYield contract in the event of an emergency.
Proof of Concept
Consider the case where _asset == address(0). An external call is made to check the contract’s token balance for the target _asset. However, this call will revert as _asset is the zero address. As a result, the onlyOwner role will never be able to withdraw ETH tokens during an emergency.
function emergencyWithdraw(address _asset, address payable _wallet) external onlyOwner returns (uint256 received) {
require(_wallet != address(0), 'cant burn');
uint256 amount = IERC20(_asset).balanceOf(address(this));
IERC20(_asset).safeTransfer(_wallet, received);
received = amount;
}
Affected function as per below: https://github.com/code-423n4/2021-12-sublime/blob/main/contracts/yield/NoYield.sol#L78-L83
Recommended Mitigation Steps
Consider handling the case where _asset is the zero address, i.e. the asset to be withdrawn under emergency is the ETH token.
ritik99 (Sublime) confirmed 0xean (judge) commented:
Upgrading to Sev 3 in line with #4 / #115 as this results in funds being stuck in the contract.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The contract treats ETH as a zero address but then calls an ERC20 balanceOf function on that zero address, which reverts.
Impact
ETH held by the NoYield contract could become permanently stuck because the owner cannot withdraw it in an emergency.
What the attacker needed
Contract holds ETH; emergency situation
The fix
The contract should handle the case where the asset is the zero address (representing ETH) by using a different withdrawal method for ETH.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This smart contract has a special function for the owner to withdraw funds in an emergency. But when the asset is ETH (the native cryptocurrency of Ethereum), the function tries to check the balance using a method that only works for tokens, not ETH. That check fails, so the owner can never withdraw ETH in an emergency.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.