57703 sc medium dos with revert via unbounded loop

Submitted on Oct 28th 2025 at 10:07:09 UTC by @lllll for Audit Comp | Belongarrow-up-right

  • Report ID: #57703

  • Report Type: Smart Contract

  • Report severity: Medium

  • Target: https://github.com/immunefi-team/audit-comp-belong/blob/main/contracts/v2/periphery/Staking.sol

  • Impacts:

    • Permanent freezing of funds

triangle-exclamation

Description

Brief / Intro

The function _removeAnySharesFor contains an unbounded loop that iterates over the stakes[staker] array and removes shares until the requested shares amount is satisfied. If a user accumulates a very large number of stake entries (i.e., stakes[staker].length becomes very large), calling _removeAnySharesFor can consume an arbitrarily large amount of gas and eventually run out of gas and revert.

Vulnerability Details

The implementation iterates over userStakes and removes elements via swap-and-pop or decrements an element. The loop condition is unbounded:

for (uint256 i; i < userStakes.length && remaining > 0;) {
    ...
}

Each iteration can modify the array length, and in the worst case (many small stakes), the number of iterations grows with the number of entries. A malicious or inadvertent accumulation of many small stakes can therefore make the function revert due to gas exhaustion.

Impact Details

If this function is used during withdraw/exit flows, affected users may be unable to withdraw staked assets, potentially resulting in permanent freezing of funds for those users.

References

Vulnerable snippet:

Proof of Concept

Was this helpful?