# Decreasing a position in PendleConnector will remove it even if there's still a stake at Penpie

PendleConnector.decreasePosition removes a market holding position while LP tokens remain staked at Penpie, understating connector and AccountingManager TVL.

- Payout: Audit contest
- Severity: high
- Program: NOYA
- Found by: Sentryx
- Disclosed: 2025-02-17
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-04-noya-findings/issues/677
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-noya%3AH-21
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** PendleConnector.sol decreasePosition/isMarketEmpty
**Root cause:** isMarketEmpty only checks SY/PT/YT and market LP balances on the connector, ignoring the balance staked in the Penpie deposit helper, so closePosition deletes the holding position while stake remains.
**Steps:**
1. Stake Pendle market LP tokens via PendleConnector into Penpie (pendleMarketDepositHelper).
2. Call `decreasePosition(market, _amount, true)` with closePosition=true.
3. isMarketEmpty returns true because SY/PT/YT and market.balanceOf are zero, ignoring Penpie stake.
4. registry.updateHoldingPosition(..., true) removes the market position; staked LP no longer counted in connector/AccountingManager TVL.
**How found:** Code review of decreasePosition and isMarketEmpty; noticed isMarketEmpty omits the Penpie deposit helper balance check.
**Exploitation:** Manager-triggered decreasePosition with closePosition=true removes the holding position while Penpie stake persists, causing TVL accounting to omit the staked value; no direct theft described.
**Insight:** When a connector tracks value across multiple venues (native balance plus staked balance), any 'is empty' predicate must include every venue's balance or position removal desyncs TVL accounting.

## Proof of concept (copied exactly from the original report)

**isMarketEmpty missing Penpie stake balance check**

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

**decreasePosition removes holding when closePosition**

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

