Skip to content
Business logic Audit finding Intermediate

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.

Sentryx Follow

Originally disclosed on Code4rena

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
         );
     }

HadiEsna (NOYA) confirmed

gzeon (judge) increased severity to High


The original report as published on Code4rena, by Sentryx. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Call decreasePosition with closePosition set to true for a market where the connector still has a stake in Penpie.
  2. The function redeems SY tokens and then calls isMarketEmpty.
  3. isMarketEmpty returns true because it only checks SY, PT, YT, and market token balances, not the Penpie stake.
  4. 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.

More by Sentryx

View all

2 more disclosed reports, best first.

More from NOYA

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.