Skip to content
Business logic Audit finding Intermediate

Missing Tranche Tracking After `extendDeposit()` Causes Temporary Asset Underreporting

The extendDeposit() function moves a staking position into a new tranche but does not record the new tranche in the tokenIdToTranches mapping. As a result, stakedNxm() and totalAssets() underreport the vault's holdings until resetTranches() is called, which could let a depositor obtain an inflated number of shares.

0x73696d616f Follow with 0x97, 0xDLG and 22 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-11-stnxm-by-easedefi-judging/issues/212 

## Found by 
0x73696d616f, 0x97, 0xDLG, 0xgh0stcybers3c, 0xsai, AestheticBhai, Drynooo, HeckerTrieuTien, IzuMan, Orhukl, OxSath404, Solea, Vesko210, Ziusz, asui, axelot, blockace, edger, ivxylo, oxwhite, slcoder, theboiledcorn, thimthor, werulez99, zaida

## Summary

The `extendDeposit()` function moves a staking position from one tranche to another in the Nexus Mutual pool but fails to update the `tokenIdToTranches` mapping. When `stakedNxm()` is subsequently called, it only queries the old tranche (which now has 0 deposits) and misses the extended position in the new tranche. This causes `totalAssets()` to underreport vault assets until `resetTranches()` is called, creating a temporary but real accounting discrepancy.

**Location:** [stNXM.sol](https://github.com/sherlock-audit/2025-11-stnxm-by-easedefi/blob/main/stNXM-Contracts/contracts/core/stNXM.sol#L366-L380)

**Vulnerable Code:**

```solidity
function extendDeposit(uint256 _tokenId, uint256 _initialTrancheId, uint256 _newTrancheId, uint256 _topUpAmount)
    external
    onlyOwner
    update
{
    address stakingPool = tokenIdToPool[_tokenId];

    if (_topUpAmount > 0) {
        wNxm.unwrap(_topUpAmount);
        nxm.approve(nxmMaster.getLatestAddress("TC"), _topUpAmount);
    }

    IStakingPool(stakingPool).extendDeposit(_tokenId, _initialTrancheId, _newTrancheId, _topUpAmount);
    // ❌ Missing: tokenIdToTranches[_tokenId].push(_newTrancheId);
}
```

**Correct Pattern (from `_stakeNxm()`):**

```solidity
function _stakeNxm(uint256 _amount, address _poolAddress, uint256 _trancheId, uint256 _requestTokenId) internal {
    // ... approval logic ...
    uint256 tokenId = pool.depositTo(_amount, _trancheId, _requestTokenId, address(this));
    tokenIdToTranches[tokenId].push(_trancheId); // �
 Correctly tracks new tranche
    // ...
}
```

## Impact

**Accounting Error:**
- After `extendDeposit()`, the new tranche is NOT tracked in `tokenIdToTranches`
- `stakedNxm()` loops through tracked tranches and queries Nexus: `getDeposit(tokenId, tranche)`
- For the new tranche: `getDeposit(tokenId, newTranche)` returns the extended funds but is never queried
- Result: `totalAssets()` underreports by the amount of the extended stake

**Exploitation Scenario:**

```bash
1. Initial state: 10,000 wNXM staked in tranche T1
   - totalAssets = 10,000
   - totalSupply = 10,000 shares
   - Share price = 1.0

2. Owner calls: extendDeposit(tokenId, T1, T2, 5000)
   - T2 now has 10,000 + 5000 = 15,000 wNXM
   - But tokenIdToTranches still = [T1]

3. stakedNxm() calculation:
   - Queries getDeposit(tokenId, T1) → 0 (was moved)
   - Never queries T2 (not tracked)
   - Returns 0

4. totalAssets now reports: 0 (artificially low!)
   - Share price drops to 0

5. Attacker deposits 5,000 wNXM:
   - Gets 5,000 / 0 = very high number of shares
   - Extreme share inflation

6. Someone calls resetTranches():
   - Discovers T2 has deposits
   - Updates tokenIdToTranches = [T2]
   - totalAssets corrects back to 15,000

7. Attacker redeems shares at corrected price
   - Extracts significantly more value than deposited
```

**Severity Justification:**
- Temporary accounting error that self-corrects within 91 days
- Requires specific conditions (owner using `extendDeposit`)
- Exploitable but correction is permissionless and quick
- Financial impact: Medium (temporary share inflation/deflation)

## POC

```solidity
function testExtendDepositAccountingError() public {
    // Setup: Initial staking position
    uint256 initialStake = 10000 ether;
    depositWNXM(initialStake, wnxmWhale);
    
    uint256 currentTranche = block.timestamp / 91 days;
    stakeNxm(initialStake, riskPools[0], currentTranche, tokenIds[0]);

    // Record initial state
    uint256 initialAssets = stNxm.totalAssets();
    uint256 initialSupply = stNxm.totalSupply();
    
    console.log("Before extend:");
    console.log("  totalAssets:", initialAssets);
    console.log("  totalSupply:", initialSupply);
    console.log("  tracked tranches:", stNxm.tokenIdToTranches(tokenIds[0]).length);

    // Owner extends deposit to new tranche
    uint256 extensionAmount = 5000 ether;
    uint256 newTranche = currentTranche + 4;

    vm.startPrank(multisig);
    stNxm.extendDeposit(tokenIds[0], currentTranche, newTranche, extensionAmount);
    vm.stopPrank();

    // Check accounting after extension (BEFORE resetTranches)
    uint256 assetsAfterExtend = stNxm.totalAssets();
    uint256[] memory tranchesAfter = stNxm.tokenIdToTranches(tokenIds[0]);

    console.log("\nAfter extend (before resetTranches):");
    console.log("  totalAssets:", assetsAfterExtend);
    console.log("  tracked tranches length:", tranchesAfter.length);
    
    // BUG: totalAssets doesn't increase
    // Extended funds exist in Nexus but aren't counted
    uint256 expectedIncrease = extensionAmount; // Should increase by at least this
    require(assetsAfterExtend < initialAssets + expectedIncrease, "Assets should have increased more");

    // Verify funds actually exist in Nexus pool
    IStakingPool pool = IStakingPool(riskPools[0]);
    (,, uint256 sharesInNewTranche,) = pool.getDeposit(tokenIds[0], newTranche);
    require(sharesInNewTranche > 0, "Deposit exists in new tranche");

    // Now call resetTranches - this fixes the accounting
    stNxm.resetTranches();

    uint256 assetsAfterReset = stNxm.totalAssets();
    uint256[] memory tranchesAfterReset = stNxm.tokenIdToTranches(tokenIds[0]);

    console.log("\nAfter resetTranches:");
    console.log("  totalAssets:", assetsAfterReset);
    console.log("  tracked tranches length:", tranchesAfterReset.length);

    // NOW assets are correct
    require(assetsAfterReset >= initialAssets + (extensionAmount / 2), "Assets corrected after reset");
    require(tranchesAfterReset.length >= 2, "New tranche now tracked");
}
```

## Recommendation

Add tranche tracking immediately after extending the deposit:

```solidity
function extendDeposit(uint256 _tokenId, uint256 _initialTrancheId, uint256 _newTrancheId, uint256 _topUpAmount)
    external
    onlyOwner
    update
{
    address stakingPool = tokenIdToPool[_tokenId];

    if (_topUpAmount > 0) {
        wNxm.unwrap(_topUpAmount);
        nxm.approve(nxmMaster.getLatestAddress("TC"), _topUpAmount);
    }

    IStakingPool(stakingPool).extendDeposit(_tokenId, _initialTrancheId, _newTrancheId, _topUpAmount);

    // Fix: Track the new tranche immediately
    tokenIdToTranches[_tokenId].push(_newTrancheId);

    // Optional: Consider removing _initialTrancheId if fully moved
    // This prevents querying a tranche with 0 deposits
}
```

## Discussion

**sherlock-admin2**

The protocol team fixed this issue in the following PRs/commits:
https://github.com/EaseDeFi/stNXM-Contracts/commit/40630a0d88fdd663803afb73dfb9437ae01707ed

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

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 extendDeposit() function calls the staking pool's extendDeposit() but never pushes the new tranche id into the tokenIdToTranches array, unlike _stakeNxm() which does.

Impact

totalAssets() could temporarily underreport the vault's holdings, potentially allowing a depositor to receive an inflated number of shares until resetTranches() corrects the accounting; the text notes the error is temporary and self-corrects within 91 days.

What the attacker needed

Owner calls extendDeposit(); attacker deposits before resetTranches()

The fix

The protocol team fixed this issue by adding the new tranche to tokenIdToTranches immediately after extending the deposit.

How it was found

  1. Stake an initial amount of wNXM into the current tranche and record totalAssets and totalSupply.
  2. The owner calls extendDeposit() to move the position to a new tranche with a top-up amount.
  3. Observe that totalAssets has not increased and the tracked tranche list still only contains the old tranche.
  4. Confirm via the pool's getDeposit() that shares do exist in the new tranche.
  5. Call resetTranches() and observe that totalAssets is corrected and the new tranche is now tracked.

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 vault tracks how much money it holds so it can work out the value of each share. When a position was moved to a new place, the vault forgot to note the new location, so it counted the money as zero for a while. Anyone who deposited during that window could receive far more shares than they paid for.

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 0x73696d616f

View all

172 more disclosed reports, best first.

More from stNXM by EaseDeFi

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.