Wrong implementation of NoYield.sol#emergencyWithdraw()
The emergencyWithdraw function transfers zero tokens because the received variable is used before being assigned. As a result, the emergency withdrawal fails and assets remain stuck in the contract.
Submitted by WatchPug, also found by 0x1f8b
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;
}
received is not being assigned prior to L81, therefore, at L81, received is 0.
As a result, the emergencyWithdraw() does not work, in essence.
Recommendation
Change to:
function emergencyWithdraw(address _asset, address payable _wallet) external onlyOwner returns (uint256 received) {
require(_wallet != address(0), 'cant burn');
received = IERC20(_asset).balanceOf(address(this));
IERC20(_asset).safeTransfer(_wallet, received);
}
upgrading to High sev based on assets being “lost” directly. IE the emergency function will not work.
3 — High: Assets can be stolen/lost/compromised directly (or indirectly if there is a valid attack path that does not have hand-wavy hypotheticals).
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
Impact
The emergency withdrawal function does not work, so assets could be lost or stuck in the contract.
What the attacker needed
Owner calls emergencyWithdraw
The fix
The function should assign the token balance to received before calling safeTransfer.
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 function meant to let the owner withdraw all tokens in an emergency. However, it sends zero tokens because it uses a variable before giving it a value. So the emergency withdrawal does not work and the tokens stay stuck.
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.