ERC4626RouterBase.withdraw should use a max shares out check
The withdraw function in ERC4626RouterBase checks that the shares burned are not less than a minimum, but the user actually needs protection against burning too many shares for a given asset amount. An attacker who can manipulate the vault's share price could cause the user to burn all their shares while the check still passes.
Submitted by cmichel, also found by CertoraInc and Picodes
The docs/video say
ERC4626RouterBase.solis in scope as its part ofTurboRouter
The ERC4626RouterBase.withdraw function withdraws the asset amount parameter by burning shares.
function withdraw(
IERC4626 vault,
address to,
uint256 amount,
uint256 minSharesOut
) public payable virtual override returns (uint256 sharesOut) {
// @audit-info from = msg.sender
if ((sharesOut = vault.withdraw(amount, to, msg.sender)) < minSharesOut) {
revert MinAmountError();
}
}
It then checks that the burned shares sharesOut are not less than a minSharesOut amount. However, the user wants to be protected against burning too many shares for their specified amount, and therefore a maxSharesBurned amount parameter should be used.
The user can lose their entire shares due to the wrong check.
this extends to
TurboRouter.withdraw
Proof of Concept
User calls Router.withdraw(amount=1100, minSharesOut=1000) to protect against not burning more than 1000 shares for their 1100 asset amount. However, there’s an exploit in the vault which makes the sharesOut = 100_000, the entire user’s shares. The check then passes as it only reverts if 100_000 < 1000.
Recommended Mitigation Steps
function withdraw(
IERC4626 vault,
address to,
uint256 amount,
- uint256 minSharesOut
+ uint256 maxSharesIn
) public payable virtual override returns (uint256 sharesOut) {
- if ((sharesOut = vault.withdraw(amount, to, msg.sender)) < minSharesOut) {
+ if ((sharesOut = vault.withdraw(amount, to, msg.sender)) > maxSharesIn) {
revert MinAmountError();
}
}
Also, rename the variable in TurboRouter.withdraw.
Joeysantoro (Tribe Turbo) disagreed with High severity and commented:
This should be a medium severity issue. The function logic is correct, it’s just not a useful check in its current state.
Joeysantoro (Tribe Turbo) resolved and commented:
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
I agree with both sides, ultimately the check doesn’t provide protection against loss of value, as such medium severity is appropriate.
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 withdraw function uses a minimum shares out check instead of a maximum shares in check, so it does not protect against burning too many shares.
Impact
A user could lose their entire share balance if the vault's share price is manipulated, because the check does not limit the number of shares burned.
What the attacker needed
User interacts with the withdraw function; Vault share price can be manipulated
The fix
The check should be changed to a maximum shares in check, reverting if the shares burned exceed the user's specified maximum.
How it was found
- User calls Router.withdraw with an amount and a minSharesOut value.
- The vault's share price is manipulated so that withdrawing the amount burns far more shares than expected.
- The check only reverts if sharesOut is less than minSharesOut, so the transaction succeeds and the user loses all their shares.
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 take money out of a savings vault, you specify how much you want and the vault tells you how many shares it will burn. The code checks that the number of shares burned is not too small, but it should check that it is not too large. If the vault's share price is manipulated, you could lose all your shares and the check would still pass.
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.