Decreasing a position in PendleConnector will remove it even if there’s still a stake at Penpie
The decreasePosition function removes a market from the connector's holdings when closePosition is true and isMarketEmpty returns true, but isMarketEmpty does not check the connector's staked balance in the Penpie pool. This allows the connector to exclude its Penpie stake from the connector and AccountingManager TVL.
Submitted by Sentryx
https://github.com/code-423n4/2024-04-noya/blob/main/contracts/connectors/PendleConnector.sol#L303-L309 https://github.com/code-423n4/2024-04-noya/blob/main/contracts/connectors/PendleConnector.sol#L223-L231
decreasePosition() will falsely remove the market as a holding position, ignoring the staked Pendle market LP tokens at Penpie and thus that stake won’t be counted towards the TVL of the connector and the TVL of the AccountingManager the connector belongs to.
Proof of Concept
The PendleConnector has a function decreasePosition() to redeem Pendle SY tokens in exchange for underlying tokens with which it effectively would remove its stake in a given Pendle market.
function decreasePosition(IPMarket market, uint256 _amount, bool closePosition) external onlyManager nonReentrant {
(IPStandardizedYield SY,,) = market.readTokens();
(, address _underlyingToken,) = SY.assetInfo();
// redeems an amount of base tokens by burning SY
IERC20(address(SY)).safeTransfer(address(SY), _amount);
IPStandardizedYield(address(SY)).redeem(address(this), _amount, _underlyingToken, 1, true);
→ if (closePosition && isMarketEmpty(market)) {
registry.updateHoldingPosition(
vaultId,
registry.calculatePositionId(address(this), PENDLE_POSITION_ID, abi.encode(market)),
"",
"",
true
);
}
emit DecreasePosition(address(market), _amount, closePosition);
}
When the closePosition parameter is true, isMarketEmpty() would be called for the given market to check if the connector holds any of the 3 tokens composing it - Yield token (YT), Principal token (PT) and Standardized Yield token (SY).
function isMarketEmpty(IPMarket market) public view returns (bool) {
(IPStandardizedYield _SY, IPPrincipalToken _PT, IPYieldToken _YT) = IPMarket(market).readTokens();
return (
_SY.balanceOf(address(this)) == 0 && _PT.balanceOf(address(this)) == 0 && _YT.balanceOf(address(this)) == 0
&& market.balanceOf(address(this)) == 0
);
}
The function however does not check if the connector still has a balance in the Penpie pool for this market (a stake), and that will allow the connector to remove its holding position for a market, effectively excluding its stake in the Penpie pool from the connector and the AccountingManager TVL.
Recommended Mitigation Steps
In the isMarketOpen() function check for the connector’s balance in the Penpie staking pool for this market.
diff --git a/contracts/connectors/PendleConnector.sol b/contracts/connectors/PendleConnector.sol
index 17607ee..e1b1208 100644
--- a/contracts/connectors/PendleConnector.sol
+++ b/contracts/connectors/PendleConnector.sol
@@ -304,7 +304,7 @@ contract PendleConnector is BaseConnector {
(IPStandardizedYield _SY, IPPrincipalToken _PT, IPYieldToken _YT) = IPMarket(market).readTokens();
return (
_SY.balanceOf(address(this)) == 0 && _PT.balanceOf(address(this)) == 0 && _YT.balanceOf(address(this)) == 0
- && market.balanceOf(address(this)) == 0
+ && market.balanceOf(address(this)) == 0 && pendleMarketDepositHelper.balance(market, address(this)) == 0
);
}
gzeon (judge) increased severity to High
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 the isMarketEmpty function does not include the connector's balance in the Penpie staking pool when determining if a market position is empty.
Impact
The connector and AccountingManager TVL could be understated because the staked Pendle market LP tokens at Penpie are not counted after the position is removed.
What the attacker needed
Connector has a stake in Penpie for the market; manager calls decreasePosition with closePosition true
The fix
The isMarketEmpty function should also check the connector's balance in the Penpie staking pool for the market.
How it was found
- Call decreasePosition with closePosition set to true for a market where the connector still has a stake in Penpie.
- The function redeems SY tokens and then calls isMarketEmpty.
- isMarketEmpty returns true because it only checks SY, PT, YT, and market token balances, not the Penpie stake.
- The holding position for that market is removed, excluding the Penpie stake from TVL.
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.
A smart contract tracks how much money it holds. When someone reduces a position, the contract checks if it still has any tokens for that market; if not, it stops counting that market. But it forgets to check tokens that were put into a separate staking pool (Penpie). So the contract thinks the market is empty and stops counting the staked tokens, making the total value look smaller than it really is.
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.