Skip to content
Smart contracts Audit finding Intermediate

Function return variable shadowing prevents storage updates in solidity

The notifyRewardAmount function declares a return variable named rewardRate that shadows the contract's storage variable, so assignments only update the local copy. As a result, the stored rewardRate remains zero and rewardForDuration always returns zero, misleading dashboards and tools that rely on it.

a39955720 Follow with Ekene

Originally disclosed on Code4rena

Submitted by a39955720, also found by Ekene

https://github.com/code-423n4/2025-05-blackhole/blob/92fff849d3b266e609e6d63478c4164d9f608e91/contracts/AlgebraCLVe33/GaugeCL.sol#L38

https://github.com/code-423n4/2025-05-blackhole/blob/92fff849d3b266e609e6d63478c4164d9f608e91/contracts/AlgebraCLVe33/GaugeCL.sol#L157-L183

https://github.com/code-423n4/2025-05-blackhole/blob/92fff849d3b266e609e6d63478c4164d9f608e91/contracts/AlgebraCLVe33/GaugeCL.sol#L257-L259

Finding description

The GaugeCL::notifyRewardAmount function attempts to update the rewardRate state variable, which is meant to track the reward emission rate for the current distribution period. However, the function declares a return variable named rewardRate (as part of the function’s return signature), which shadows the contract-level storage variable. As a result, assignments within the function update only the local return variable, and the contract’s storage rewardRate is never updated.

This leads to the reward rate always remaining at its initial value (0), and any queries to rewardForDuration() or other on-chain users referencing rewardRate will receive inaccurate results.

// @audit-issue Storage rewardRate is shadowed and never updated
function notifyRewardAmount(address token, uint256 reward)
    external nonReentrant isNotEmergency onlyDistribution
    returns (IncentiveKey memory incentivekey, uint256 rewardRate, uint128 bonusRewardRate)
{
    ...
    if (block.timestamp >= _periodFinish) {
        rewardRate = reward / DURATION;
    } else {
        uint256 remaining = _periodFinish - block.timestamp;
        uint256 leftover = remaining * rewardRate;
        rewardRate = (reward + leftover) / DURATION;
    }
    ...
}

Issue identified

  • The function’s return signature declares a local variable rewardRate, which shadows the contract’s storage variable of the same name.
  • All assignments to rewardRate within the function only affect this local variable, not the contract storage.
  • The contract storage variable rewardRate remains permanently zero, and is never updated by any function in the contract.
  • Consequently, the function rewardForDuration() always returns 0, misleading dApps, explorers, and UIs that rely on this state variable for reward calculations.

Risk and impact

Likelihood:

  • This is a deterministic bug and will always occur if the function signature is not fixed.
  • Any user or protocol that queries rewardForDuration() or the public rewardRate will receive incorrect values.

Impact:

  • Protocol dashboards, explorers, or analytic scripts may display incorrect or misleading reward information.
  • Third-party tools or automated scripts that rely on on-chain rewardRate data could behave incorrectly.
  • Does not directly cause loss of funds or user assets, but can lead to confusion or improper reward tracking.

Recommended mitigation steps

Rename the function return variable to avoid shadowing, or directly assign to the storage variable inside the function:

function notifyRewardAmount(address token, uint256 reward)
    external
    nonReentrant
    isNotEmergency
    onlyDistribution
-   returns (IncentiveKey memory incentivekey, uint256 rewardRate, uint128 bonusRewardRate)
+   returns (IncentiveKey memory, uint256, uint128)
{
    require(token == address(rewardToken), "not rew token");
    if (block.timestamp >= _periodFinish) {
        rewardRate = reward / DURATION;
    } else {
        uint256 remaining = _periodFinish - block.timestamp;
        uint256 leftover = remaining * rewardRate;
        rewardRate = (reward + leftover) / DURATION;
    }
    _periodFinish = block.timestamp + DURATION;
    (IERC20Minimal rewardTokenAdd, IERC20Minimal bonusRewardTokenAdd, IAlgebraPool pool, uint256 nonce) =
        algebraEternalFarming.incentiveKeys(poolAddress);
-   incentivekey = IncentiveKey(rewardTokenAdd, bonusRewardTokenAdd, pool, nonce);
+   IncentiveKey memory incentivekey = IncentiveKey(rewardTokenAdd, bonusRewardTokenAdd, pool, nonce);
    bytes32 incentiveId = IncentiveId.compute(incentivekey);

    (,, address virtualPoolAddress,,,) = algebraEternalFarming.incentives(incentiveId);
-   (,bonusRewardRate) = IAlgebraEternalVirtualPool(virtualPoolAddress).rewardRates();
+   (,uint128 bonusRewardRate) = IAlgebraEternalVirtualPool(virtualPoolAddress).rewardRates();

    rewardToken.safeTransferFrom(DISTRIBUTION, address(this), reward);
    IERC20(token).safeApprove(farmingParam.algebraEternalFarming, reward);
    algebraEternalFarming.addRewards(incentivekey, uint128(reward), 0);
    emit RewardAdded(reward);
+   return(incentivekey, rewardRate, bonusRewardRate);
}

Proof of Concept

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

contract ShadowedStorageExample {
    uint256 public rewardRate;

    function incrementRewardRate(uint256 amount) public returns (uint256 rewardRate) {
        rewardRate += amount;
    }
}

No matter how you call incrementRewardRate with different values, the storage variable rewardRate will never change. This is because the function’s return variable rewardRate shadows the contract’s storage variable of the same name.

All updates inside the function only affect the local return variable, not the storage. As a result, rewardRate() (the public getter) will always return 0, regardless of how many times you call the function or what arguments you provide.

Blackhole mitigated

Status: Mitigation confirmed. Full details in reports from lonelybones, rayss and maxvzuvex.



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

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 a return variable in the function signature shadows the contract storage variable of the same name, so assignments update only the local return value.

Impact

The stored reward rate stays at zero, so rewardForDuration and public rewardRate queries return incorrect values, which could mislead dashboards and automated tools; the report states this does not directly cause loss of funds.

What the attacker needed

None

The fix

The issue was mitigated by renaming the return variable or assigning directly to the storage variable, as confirmed in the mitigation review.

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.

In Solidity, a function can have a variable with the same name as a contract-wide variable. When that happens, the function's variable hides the contract's one, so changes only affect the temporary copy. Here, the reward rate that should be saved permanently is never updated, so anyone reading it sees zero.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More from Blackhole

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.