M-05 Yearn `withdraw(uint)` selector may backfire
The YearnController contract uses a hardcoded function selector for Yearn's withdraw function that includes a maxLoss parameter of 1 basis point. This means that if a withdrawal would incur a loss greater than 1 basis point, the transaction will revert, preventing users from withdrawing their funds.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-08-sentiment-judging/tree/main/208-M
Found by
GalloDaSballo
Summary
The YearnController is using:
/// @notice withdraw(uint256) function signature
bytes4 constant WITHDRAW = 0x2e1a7d4d;
Which is the selector for withdraw(amount, msg.sender, 1) where the max_loss is 1bps
See Yearn Code: https://github.com/yearn/yearn-vaults/blob/efb47d8a84fcb13ceebd3ceb11b126b323bcc05d/contracts/Vault.vy#L1010
Vulnerability Detail
On one hand the selector will allow for loss, if you'd want to have no loss you should change it to a function call with a hardcoded 0 value for maxLoss
On the other hand, if the account has too big of a position in a Yearn Vault (e.g. more than 10% of the vault), then a withdrawal may simply not be possible as the function will always revert.
You can monitor the limits on https://yearn.watch/, per the Yearn withdraw code, the function will go through the withdrawal queue, adding up losses (if any) to the caller.
Because the hardcoded selector will not offer any flexibility to the maxLoss parameter, in any scenario in which the losses are above 1 bps, the function will simply revert, preventing any withdrawal.
Tool used
Manual Review
Recommendation
Consider adding support for a more complete withdraw that allows to change the maxLoss parameter
Sentiment Team
Not fixing since we don't plan to launch with Yearn. We are okay with not including this contract in the coverage scope since it won't be deployed.
Lead Senior Watson
Acknowledged.
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 hardcodes a function selector that corresponds to a withdraw call with a fixed maxLoss of 1 basis point, offering no way to adjust the acceptable loss.
Impact
Users with large positions in a Yearn vault may be unable to withdraw if the vault's losses exceed 1 basis point, as the transaction will revert.
What the attacker needed
Account has a position in a Yearn vault; vault losses exceed 1 basis point
The fix
The recommendation is to add support for a more complete withdraw function that allows changing the maxLoss parameter.
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.
When you withdraw money from a Yearn vault, the vault may take a small fee (loss) to cover costs. The code here always tells the vault that it will accept a loss of at most 0.01% (1 basis point). If the actual loss would be higher, the vault refuses to process the withdrawal, so the user cannot get their money out.
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.