Skip to content
DoS Audit finding Intermediate

StakeOnBehalf() function enables out-of-gas DoS

Anyone can call stakeOnBehalf to add validator entries to another user's userValidators array, and once that array is large enough, functions that loop over it consume more gas than the block gas limit and revert. This causes a denial of service for restakeRewards and withdraw.

KlosMitSoss Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

51452 sc high stakeonbehalf function enables out of gas dos

Submitted on Aug 2nd 2025 at 23:43:13 UTC by @KlosMitSoss for Attackathon | Plume Network

Description

Brief/Intro

Staking on behalf of another user can be exploited by an attacker who adds enough items to the userValidators mapping of any user to cause the gas consumption of function calls to exceed the block gas limit. This results in a denial of service for several functions, preventing them from being called.

Vulnerability Details

When StakingFacet::stakeOnBehalf() is called, which can be done by anyone to stake PLUME to a specific validator on behalf of another user, _performStakeSetup() is called within this function:

Solidity
function stakeOnBehalf(uint16 validatorId, address staker) external payable returns (uint256) {
    ... ...
    // Perform all common staking setup for the beneficiary
>>  bool isNewStake = _performStakeSetup(staker, validatorId, stakeAmount);
    ... ...
}

This function calls PlumeValidatorLogic::addStakerToValidator(), which then pushes the validatorId onto the userValidator mapping:

Solidity
function addStakerToValidator(PlumeStakingStorage.Layout storage $, address staker, uint16 validatorId) internal {
    ... ...
    if (!$.userHasStakedWithValidator[staker][validatorId]) {
>>  $.userValidators[staker].push(validatorId);
        $.userHasStakedWithValidator[staker][validatorId] = true;
    }
    ... ...
}

This can be done for any existing validatorId, which means the mapping can be flooded with entries. As a result, when looping over the mapping, it could cause a revert due to the transaction consuming more gas than the block gas limit. This could happen, for example, in StakingFacet::_calculateAndClaimAllRewardsWithCleanup(), which is called within StakingFacet::restakeRewards():

Solidity
function _calculateAndClaimAllRewardsWithCleanup(
    address user,
    address targetToken
) internal returns (uint256 totalRewards) {
    ... ...
    // Make a copy to avoid iteration issues
>>  uint16[] memory currentUserValidators = $.userValidators[user];

    // Track validators that might need cleanup after claiming
    uint16[] memory validatorsToCheck = new uint16[](currentUserValidators.length);
    uint256 checkCount = 0;

>>  for (uint256 i = 0; i < currentUserValidators.length; i++) {
        uint16 userValidatorId = currentUserValidators[i];

        uint256 existingRewards = $.userRewards[user][userValidatorId][targetToken];
        uint256 rewardDelta =
            IRewardsGetter(address(this)).getPendingRewardForValidator(user, userValidatorId, targetToken);
        uint256 totalValidatorReward = existingRewards + rewardDelta;

        if (totalValidatorReward > 0) {
            totalRewards += totalValidatorReward;
            PlumeRewardLogic.updateRewardsForValidator($, user, userValidatorId);
            $.userRewards[user][userValidatorId][targetToken] = 0;

            if ($.totalClaimableByToken[targetToken] >= totalValidatorReward) {
                $.totalClaimableByToken[targetToken] -= totalValidatorReward;
            } else {
                $.totalClaimableByToken[targetToken] = 0;
            }

            emit RewardClaimedFromValidator(user, targetToken, userValidatorId, totalValidatorReward);

            // Clear pending rewards flag for this validator and track for cleanup
            PlumeRewardLogic.clearPendingRewardsFlagIfEmpty($, user, userValidatorId);

            // Track this validator for potential relationship cleanup
            validatorsToCheck[checkCount] = userValidatorId;
            checkCount++;
        }
    }
    ... ...
}

Impact Details

This issue causes a denial of service for several functions, including StakingFacet::restakeRewards() and StakingFacet::withdraw().

References

Code references are provided throughout the report (links above).

Proof of Concept

{% stepper %} {% step %}

Stake on behalf to populate user's validators

An attacker calls StakingFacet::stakeOnBehalf() to stake PLUME to a specific validator on behalf of Alice. Within this function, _performStakeSetup() is called.

Reference: https://github.com/immunefi-team/attackathon-plume-network/blob/580cc6d61b08a728bd98f11b9a2140b84f41c802/plume/src/facets/StakingFacet.sol#L436 {% endstep %}

{% step %}

addStakerToValidator pushes validatorId for the beneficiary

_performStakeSetup() calls PlumeValidatorLogic::addStakerToValidator() which pushes the validatorId onto the userValidators mapping for Alice.

Reference: https://github.com/immunefi-team/attackathon-plume-network/blob/580cc6d61b08a728bd98f11b9a2140b84f41c802/plume/src/facets/StakingFacet.sol#L224 https://github.com/immunefi-team/attackathon-plume-network/blob/580cc6d61b08a728bd98f11b9a2140b84f41c802/plume/src/lib/PlumeValidatorLogic.sol#L60 {% endstep %}

{% step %}

Looping over flooded mapping causes out-of-gas

When StakingFacet::restakeRewards() is called, it invokes _calculateAndClaimAllRewardsWithCleanup(), which loops over $.userValidators[user]. If that array is large enough (flooded by the attacker), the loop can consume more gas than the block gas limit and revert, causing a denial of service.

Reference: https://github.com/immunefi-team/attackathon-plume-network/blob/580cc6d61b08a728bd98f11b9a2140b84f41c802/plume/src/facets/StakingFacet.sol#L961-L995 {% endstep %} {% endstepper %}

The original report as published on Immunefi, by KlosMitSoss. 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 userValidators array can be appended to by any caller through stakeOnBehalf, and later functions iterate over the whole array without a bound, so its length can be inflated until iteration exceeds the block gas limit.

Impact

The victim's restakeRewards and withdraw calls could revert, preventing them from claiming rewards or withdrawing funds.

What the attacker needed

Attacker can call stakeOnBehalf; victim has a staking position

How it was found

  1. An attacker calls stakeOnBehalf to stake PLUME to a validator on behalf of a victim.
  2. The internal setup calls addStakerToValidator, which pushes the validatorId onto the victim's userValidators array.
  3. The attacker repeats this for many validators until the array is large.
  4. When the victim calls restakeRewards, the loop over userValidators consumes more gas than the block gas limit and reverts.

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 stores a list of validators for each user. Anyone can add entries to someone else's list by staking on their behalf. If the list gets very long, functions that read the whole list run out of gas and fail, so the victim cannot withdraw or restake.

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 KlosMitSoss

View all

25 more disclosed reports, best first.

More from Plume Network

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.