# Rewards are not accounted for properly in NTokenApeStaking contracts, limiting user's collateral

getTokenIdStakingAmount omits pending BAKC rewards, so PTokenSApe.balanceOf underreports collateral, limiting users' borrowing power.

- Payout: Contest reward
- Severity: medium
- Program: ParaSpace
- Credited: Trust
- Disclosed: 2023-04-27
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2022-11-paraspace-findings/issues/481
- Library page: https://bugbountylibrary.com/r/c4%3A2022-11-paraspace%3AM-19
- Tags: domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:solidity technique:source-review vuln:accounting-error

**Target:** NTokenApeStaking / ApeStakingLogic.sol getTokenIdStakingAmount
**Root cause:** getTokenIdStakingAmount adds the paired BAKC staked amount but not the BAKC pendingRewards, so the returned total is lower than the true staked balance.
**Steps:**
1. Read ApeStakingLogic.getTokenIdStakingAmount: it sums apeStakedAmount + apeReward, and if paired adds bakcStakedAmount from nftPosition(BAKC_POOL_ID, bakcTokenId).
2. Note pendingRewards is only queried for the main pool/tokenId, never for the BAKC pool/bakcTokenId.
3. Observe PTokenSApe.balanceOf uses this value as the user's collateral.
4. Unstaking via executeUnstakePositionAndRepay calls _withdrawPairNft which does claim BAKC rewards, confirming rewards exist but were uncounted.
**How found:** Code reading of the staking amount aggregation: noticed the paired BAKC branch adds only staked principal while the main branch adds both principal and pending rewards, an asymmetry implying missing reward accrual.
**Insight:** When a helper aggregates multiple positions, check each branch for symmetric treatment of principal vs. accrued rewards; a paired/secondary position often skips the pendingRewards call that the primary position includes.
