Skip to content
Access control Audit finding Intermediate

Reward token in GaugeFactoryCL can be drained by anyone

The public createGauge function in GaugeFactoryCL lacks access control, allowing anyone to trigger the creation of a new eternal farming incentive that pulls a fixed amount of reward tokens from the factory. If the factory holds reward tokens, an attacker can repeatedly call createGauge to drain them into farms they control.

danzero Follow with a39955720, bareli and 7 others

Originally disclosed on Code4rena

Submitted by danzero, also found by a39955720, bareli, DarkeEEandMe, Kariukigithinji, mahadev, maxzuvex, wafflewizard, wankleven, and Ziusz

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

Findings Description and Impact

The GaugeFactoryCL.sol contract, responsible for creating GaugeCL instances for Algebra Concentrated Liquidity pools, has a public createGauge function. Below is the implementation of the function:

    function createGauge(address _rewardToken,address _ve,address _pool,address _distribution, address _internal_bribe, address _external_bribe, bool _isPair,
                        IGaugeManager.FarmingParam memory farmingParam, address _bonusRewardToken) external returns (address) {

createEternalFarming(_pool, farmingParam.algebraEternalFarming, _rewardToken, _bonusRewardToken);
        last_gauge = address(new GaugeCL(_rewardToken,_ve,_pool,_distribution,_internal_bribe,_external_bribe,_isPair, farmingParam, _bonusRewardToken, address(this)));
        __gauges.push(last_gauge);
        return last_gauge;
    }

The GaugeFactoryCL.createGauge function lacks access control, allowing any external actor to call it. This function, in turn, calls an internal createEternalFarming function. Below is the implementation of the createEternalFarming function:

    function createEternalFarming(address _pool, address _algebraEternalFarming, address _rewardToken, address _bonusRewardToken) internal {
        IAlgebraPool algebraPool = IAlgebraPool(_pool);
        uint24 tickSpacing = uint24(algebraPool.tickSpacing());
        address pluginAddress = algebraPool.plugin();
        IncentiveKey memory incentivekey = getIncentiveKey(_rewardToken, _bonusRewardToken, _pool, _algebraEternalFarming);
        uint256 remainingTimeInCurrentEpoch = BlackTimeLibrary.epochNext(block.timestamp) - block.timestamp;
        uint128 reward = 1e10;
        uint128 rewardRate = uint128(reward/remainingTimeInCurrentEpoch);

        IERC20(_rewardToken).safeApprove(_algebraEternalFarming, reward);
        address customDeployer = IAlgebraPoolAPIStorage(algebraPoolAPIStorage).pairToDeployer(_pool);
        IAlgebraEternalFarming.IncentiveParams memory incentiveParams =
            IAlgebraEternalFarming.IncentiveParams(reward, 0, rewardRate, 0, tickSpacing);
        IAlgebraEternalFarmingCustom(_algebraEternalFarming).createEternalFarming(incentivekey, incentiveParams, pluginAddress, customDeployer);
    }

It is designed to seed a new Algebra eternal farming incentive with an initial, hardcoded amount of 1e10 of the _rewardToken. It achieves this by having GaugeFactoryCL approve the algebraEternalFarming contract, which is then expected to pull these tokens from GaugeFactoryCL.

If the GaugeFactoryCL contract is pre-funded with reward tokens to facilitate this initial seeding for legitimate gauges, an attacker can repeatedly call the createGauge function which will trigger the createEternalFarming process, causing the reward token to be transferred from GaugeFactoryCL to a new Algebra farm associated with a pool specified by the attacker ultimately draining the reward token from the GaugeFactoryCL contract.

The attacker can then potentially stake a Liquidity Provider (LP) NFT into this newly created (spam) GaugeCL and its associated Algebra farm, and subsequently claim that reward.

Recommended mitigation steps

Implement robust access control on the GaugeFactoryCL.createGauge() function, restricting its execution to authorized administrators or designated smart contracts, thereby preventing unauthorized calls.

Proof of Concept

  1. Protocol admin pre-funds GaugeFactoryCL with 5e10 of USDC (50,000).
  2. Attacker calls GaugeFactoryCL.createGauge():
 IGaugeFactoryCL(GFCL_ADDRESS).createGauge(
     USDC_ADDRESS,       // _rewardToken
     VE_ADDRESS,
     TARGET_POOL_ADDRESS,
     ATTACKER_ADDRESS,   // _distribution
     ATTACKER_ADDRESS,   // _internal_bribe
     ATTACKER_ADDRESS,   // _external_bribe
     true,               // _isPair
     farmingParams,      // including ALGEBRA_ETERNAL_FARMING_ADDRESS
     ZERO_ADDRESS        // _bonusRewardToken
 );
  1. The public createGauge function is entered which calls its internal createEternalFarming(_pool, farmingParam.algebraEternalFarming, USDC_ADDRESS, _bonusRewardToken).
  2. Execution within GaugeFactoryCL.createEternalFarming():
function createEternalFarming(address _pool, address _algebraEternalFarming, address _rewardToken, address _bonusRewardToken) internal {
    // ...
    uint128 reward = 1e10; // 10,000 USDC
    // ...
    // GaugeFactoryCL approves AlgebraEternalFarming to spend its USDC
    IERC20(_rewardToken /* USDC_ADDRESS */).safeApprove(_algebraEternalFarming, reward);
    // ...
    // Call to AlgebraEternalFarming which will pull the approved USDC
    IAlgebraEternalFarmingCustom(_algebraEternalFarming).createEternalFarming(incentivekey, incentiveParamsWithReward, pluginAddress, customDeployer);
}
  1. Execution within AlgebraEternalFarming.createEternalFarming() here:
/// @inheritdoc IAlgebraEternalFarming
  function createEternalFarming(
    IncentiveKey memory key,
    IncentiveParams memory params,
    address plugin
  ) external override onlyIncentiveMaker returns (address virtualPool) {
    address connectedPlugin = key.pool.plugin();
    if (connectedPlugin != plugin || connectedPlugin == address(0)) revert pluginNotConnected();
    if (IFarmingPlugin(connectedPlugin).incentive() != address(0)) revert anotherFarmingIsActive();

    virtualPool = address(new EternalVirtualPool(address(this), connectedPlugin));
    IFarmingCenter(farmingCenter).connectVirtualPoolToPlugin(virtualPool, IFarmingPlugin(connectedPlugin));

    key.nonce = numOfIncentives++;
    incentiveKeys[address(key.pool)] = key;
    bytes32 incentiveId = IncentiveId.compute(key);
    Incentive storage newIncentive = incentives[incentiveId];

    (params.reward, params.bonusReward) = _receiveRewards(key, params.reward, params.bonusReward, newIncentive);
    if (params.reward == 0) revert zeroRewardAmount();

    unchecked {
      if (int256(uint256(params.minimalPositionWidth)) > (int256(TickMath.MAX_TICK) - int256(TickMath.MIN_TICK)))
        revert minimalPositionWidthTooWide();
    }
    newIncentive.virtualPoolAddress = virtualPool;
    newIncentive.minimalPositionWidth = params.minimalPositionWidth;
    newIncentive.pluginAddress = connectedPlugin;

    emit EternalFarmingCreated(
      key.rewardToken,
      key.bonusRewardToken,
      key.pool,
      virtualPool,
      key.nonce,
      params.reward,
      params.bonusReward,
      params.minimalPositionWidth
    );

    _addRewards(IAlgebraEternalVirtualPool(virtualPool), params.reward, params.bonusReward, incentiveId);
    _setRewardRates(IAlgebraEternalVirtualPool(virtualPool), params.rewardRate, params.bonusRewardRate, incentiveId);
  }
  1. It calls the _receiveRewards function here:
  function _receiveRewards(
    IncentiveKey memory key,
    uint128 reward,
    uint128 bonusReward,
    Incentive storage incentive
  ) internal returns (uint128 receivedReward, uint128 receivedBonusReward) {
    if (!unlocked) revert reentrancyLock();
    unlocked = false; // reentrancy lock
    if (reward > 0) receivedReward = _receiveToken(key.rewardToken, reward);
    if (bonusReward > 0) receivedBonusReward = _receiveToken(key.bonusRewardToken, bonusReward);
    unlocked = true;

    (uint128 _totalRewardBefore, uint128 _bonusRewardBefore) = (incentive.totalReward, incentive.bonusReward);
    incentive.totalReward = _totalRewardBefore + receivedReward;
    incentive.bonusReward = _bonusRewardBefore + receivedBonusReward;
  }
  1. It calls the _receiveToken function here:
  function _receiveToken(IERC20Minimal token, uint128 amount) private returns (uint128) {
    uint256 balanceBefore = _getBalanceOf(token);
    TransferHelper.safeTransferFrom(address(token), msg.sender, address(this), amount);
    uint256 balanceAfter = _getBalanceOf(token);
    require(balanceAfter > balanceBefore);
    unchecked {
      uint256 received = balanceAfter - balanceBefore;
      if (received > type(uint128).max) revert invalidTokenAmount();
      return (uint128(received));
    }
  }
  1. 1e10 (10,000) USDC has been transferred to the new algebra farm.
  2. Attacker repeats step 2 to 6 for 5 times to fully transfer 50,000 USDC out of the GaugeCLFactory contract.
  3. Attacker stakes relevant LP NFT into the spam gauges through the GaugeCL.deposit function:
    function deposit(uint256 tokenId) external nonReentrant isNotEmergency {
        require(msg.sender == nonfungiblePositionManager.ownerOf(tokenId));

        nonfungiblePositionManager.approveForFarming(tokenId, true, farmingParam.farmingCenter);

        (IERC20Minimal rewardTokenAdd, IERC20Minimal bonusRewardTokenAdd, IAlgebraPool pool, uint256 nonce) =
                algebraEternalFarming.incentiveKeys(poolAddress);
        IncentiveKey memory incentivekey = IncentiveKey(rewardTokenAdd, bonusRewardTokenAdd, pool, nonce);
        farmingCenter.enterFarming(incentivekey, tokenId);
        emit Deposit(msg.sender, tokenId);
    }
  1. Attacker directly calls the AlgebraEternalFarming.claimReward function to claim the rewards here:
  /// @inheritdoc IAlgebraEternalFarming
  function claimReward(IERC20Minimal rewardToken, address to, uint256 amountRequested) external override returns (uint256 reward) {
    return _claimReward(rewardToken, msg.sender, to, amountRequested);
  }

  function _claimReward(IERC20Minimal rewardToken, address from, address to, uint256 amountRequested) internal returns (uint256 reward) {
    if (to == address(0)) revert claimToZeroAddress();
    mapping(IERC20Minimal => uint256) storage userRewards = rewards[from];
    reward = userRewards[rewardToken];

    if (amountRequested == 0 || amountRequested > reward) amountRequested = reward;

    if (amountRequested > 0) {
      unchecked {
        userRewards[rewardToken] = reward - amountRequested;
      }
      TransferHelper.safeTransfer(address(rewardToken), to, amountRequested);
      emit RewardClaimed(to, amountRequested, address(rewardToken), from);
    }
  }

Blackhole commented:

Blackhole Protocol disputes the classification of this issue as high severity, noting that the protocol is designed to deposit no more than $0.10 worth of BLACK tokens, an amount sufficient to spawn over a million liquidity pools on Blackhole.

Blackhole mitigated

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


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

Impact

If the factory is pre-funded with reward tokens, an attacker could drain them; the protocol disputes the severity, stating it deposits only about $0.10 worth of BLACK tokens.

What the attacker needed

GaugeFactoryCL holds reward tokens; Attacker can call createGauge

The fix

Access control should be added to the createGauge function so only authorised administrators or designated contracts can call it.

How it was found

  1. The protocol admin pre-funds GaugeFactoryCL with reward tokens.
  2. The attacker calls createGauge with a pool and addresses they control.
  3. The factory approves the AlgebraEternalFarming contract to spend the reward token.
  4. The AlgebraEternalFarming contract pulls the approved reward tokens from the factory.
  5. The attacker repeats the call until the factory's reward token balance is drained.
  6. The attacker stakes an LP NFT into the spam gauge and claims the rewards.

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 that creates farming rewards for liquidity pools had a function that anyone could call. That function automatically sent a small amount of a reward token from the contract to a new farm. If the contract held tokens, an attacker could call the function over and over to send those tokens to farms they set up, then claim the rewards.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by danzero

View all

1 more disclosed report, best first.

More from Blackhole

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.