Skip to content
Business logic Audit finding Intermediate

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.

leastwood Follow

Originally disclosed on Code4rena

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.

The original report as published on Code4rena, by leastwood. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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.

More by leastwood

View all

70 more disclosed reports, best first.

More from Sublime contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.