Lack of slippage control on `_redeemPT` function
The `_redeemPT` function sets the minimum output amount to zero, disabling slippage protection. An attacker could sandwich the redemption transaction or natural market movements could cause the vault to receive fewer tokens than expected, leading to asset loss.
BiasedMerc Follow with Ironsidesec, ZeroTrust and 6 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-06-leveraged-vaults-judging/issues/70
Found by
BiasedMerc, Ironsidesec, ZeroTrust, blackhole, brgltd, denzi_, lemonmon, pseudoArtist, xiaoming90
Summary
The slippage control on the _redeemPT function has been disabled. As a result, it can lead to a loss of assets. Slippage can occur naturally due to on-chain trading activities or the victim being sandwiched by malicious users/MEV.
Vulnerability Detail
In Line 137 of the _redeemPT function, the minTokenOut is set to 0, which disables the slippage control. Note that redeeming one TOKEN_OUT_SY does not always give you one netTokenOut. Not all SY contracts will burn one share and return 1 yield token back. Inspecting the Pendle's source code will reveal that for some SY contracts, some redemption will involve withdrawing/redemption from external staking protocol or performing some swaps, which might suffer from some slippage.
File: PendlePrincipalToken.sol
123: /// @notice Handles PT redemption whether it is expired or not
124: function _redeemPT(uint256 vaultShares) internal returns (uint256 netTokenOut) {
125: uint256 netPtIn = getStakingTokensForVaultShare(vaultShares);
126: uint256 netSyOut;
127:
128: // PT tokens are known to be ERC20 compatible
129: if (PT.isExpired()) {
130: PT.transfer(address(YT), netPtIn);
131: netSyOut = YT.redeemPY(address(SY));
132: } else {
133: PT.transfer(address(MARKET), netPtIn);
134: (netSyOut, ) = MARKET.swapExactPtForSy(address(SY), netPtIn, "");
135: }
136:
137: netTokenOut = SY.redeem(address(this), netSyOut, TOKEN_OUT_SY, 0, true);
138: }
The _redeemPT function is being used in two places:
Instance 1 - Within _executeInstantRedemption function
If TOKEN_OUT_SY == BORROW_TOKEN, the code will accept any netTokenOut redeemed, even if it is fewer than expected due to slippage.
File: PendlePrincipalToken.sol
140: function _executeInstantRedemption(
141: address /* account */,
142: uint256 vaultShares,
143: uint256 /* maturity */,
144: RedeemParams memory params
145: ) internal override returns (uint256 borrowedCurrencyAmount) {
146: uint256 netTokenOut = _redeemPT(vaultShares);
147:
148: if (TOKEN_OUT_SY != BORROW_TOKEN) {
149: Trade memory trade = Trade({
150: tradeType: TradeType.EXACT_IN_SINGLE,
151: sellToken: TOKEN_OUT_SY,
152: buyToken: BORROW_TOKEN,
153: amount: netTokenOut,
154: limit: params.minPurchaseAmount,
155: deadline: block.timestamp,
156: exchangeData: params.exchangeData
157: });
158:
159: // Executes a trade on the given Dex, the vault must have permissions set for
160: // each dex and token it wants to sell.
161: (/* */, borrowedCurrencyAmount) = _executeTrade(params.dexId, trade);
162: } else {
163: borrowedCurrencyAmount = netTokenOut;
164: }
Instance 2 - Within _initiateWithdrawImpl function
The code will accept any tokenOutSy redeemed, even if it is fewer than expected due to slippage, and proceed to withdraw them from external protocols.
File: PendlePrincipalToken.sol
171: function _initiateWithdrawImpl(
172: address account, uint256 vaultSharesToRedeem, bool isForced
173: ) internal override returns (uint256 requestId) {
174: // When doing a direct withdraw for PTs, we first redeem or trade out of the PT
175: // and then initiate a withdraw on the TOKEN_OUT_SY. Since the vault shares are
176: // stored in PT terms, we pass tokenOutSy terms (i.e. weETH or sUSDe) to the withdraw
177: // implementation.
178: uint256 tokenOutSy = _redeemPT(vaultSharesToRedeem);
179: requestId = _initiateSYWithdraw(account, tokenOutSy, isForced);
180: // Store the tokenOutSy here for later when we do a valuation check against the position
181: VaultStorage.getWithdrawRequestData()[requestId] = abi.encode(tokenOutSy);
182: }
Impact
Loss of assets due to lack of slippage control. Slippage can occur naturally due to on-chain trading activities or the victim being sandwiched by malicious users/MEV.
Code Snippet
Tool used
Manual Review
Recommendation
Consider implementing the required slippage control.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/notional-finance/leveraged-vaults/pull/99
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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 passes a minimum output of zero to the SY redemption call, removing any check on the amount received.
Impact
The vault could lose assets because redemptions accept any output amount, whether due to normal market slippage or a sandwich attack by MEV bots.
What the attacker needed
None
The fix
The issue was fixed by adding slippage control, as confirmed by the protocol team's pull request and the lead senior Watson's sign-off.
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 swap one token for another, the amount you get back can change between the moment you send the transaction and when it is processed. A minimum output amount protects you by cancelling the trade if the return is too low. Here that protection was turned off, so the vault could accept a much smaller amount than intended.
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.