YaxisVaultAdapter.sol#withdraw() will most certainly fail
The withdraw function in YaxisVaultAdapter.sol converts the requested token amount to vault shares, but due to precision loss the actual tokens received are less than the requested amount, causing the subsequent safeTransfer to revert from insufficient balance. The report states this will fail 99.99% of the time unless the price per share equals 1e18.
Submitted by WatchPug
The actual token withdrawn from vault.withdraw() will most certainly less than the _amount, due to precision loss in _tokensToShares() and vault.withdraw().
As a result, IDetailedERC20(_token).safeTransfer(_recipient, _amount) will revert due to insufficant balance.
Based on the simulation we ran, it will fail 99.99% of the time unless the pps == 1e18.
function withdraw(address _recipient, uint256 _amount) external override onlyAdmin {
vault.withdraw(_tokensToShares(_amount));
address _token = vault.getToken();
IDetailedERC20(_token).safeTransfer(_recipient, _amount);
}
function withdraw(
uint256 _shares
)
public
override
{
uint256 _amount = (balance().mul(_shares)).div(IERC20(address(vaultToken)).totalSupply());
Recommendation
Change to:
function withdraw(address _recipient, uint256 _amount) external override onlyAdmin {
address _token = vault.getToken();
uint256 beforeBalance = IDetailedERC20(_token).balanceOf(address(this));
vault.withdraw(_tokensToShares(_amount));
IDetailedERC20(_token).safeTransfer(
_recipient,
IDetailedERC20(_token).balanceOf(address(this)) - beforeBalance
);
}
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
Likely precision loss in the share-to-token conversion causes the withdrawn token amount to be less than the requested amount, leading to a failed transfer.
Impact
The withdraw function will fail 99.99% of the time unless the price per share is exactly 1e18, preventing users from withdrawing their funds.
What the attacker needed
Admin calls withdraw; vault has sufficient liquidity
The fix
The recommendation is to calculate the actual amount received by checking the balance difference before and after the vault withdrawal, and transfer that amount instead of the requested amount.
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 is a smart contract bug where a function tries to send a specific amount of tokens but ends up with slightly less due to rounding errors when converting between shares and tokens. When it tries to send the full amount, the contract doesn't have enough tokens, so the transaction fails.
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.