Skip to content
Audit finding Intermediate

Precision loss leads to locked incentives in `DebitaIncentives::claimIncentives()`

The incentive claim function rounds each user's share to two decimal places, leaving a small fraction of the total incentives unclaimable. Over many epochs and users, these fractions accumulate and become permanently locked in the contract.

BengalCatBalu Follow with KlosMitSoss, Maroutis and 4 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-10-debita-judging/issues/385

Found by

BengalCatBalu, KlosMitSoss, Maroutis, VAD37, dany.armstrong90, jsmi, pashap9990

Summary

When a lender or borrwer calls DebitaIncentives::claimIncentives() to claim a share of the incentives for a specific token pair they interacted with during an epoch, their share is calculated as a percentage. This percentage is determined based on the amount they lent or borrowed through the protocol during that epoch, relative to the total amount lent and borrowed by all users in the same period.

The percentage is rounded to two decimal places, which means up to 0.0099% of the incentives may remain unclaimed for each lender or borrower. Consider the following simple scenario:

  1. Six lenders each lent 5e18 over a 14-day period for a specific token pair
  2. That token pair is incentivized with 1000e18
  3. The total amount lent equals 6 * 5e18 = 30e18

After each lender calls DebitaIncentives::claimIncentives(), there will still be 4e17 locked in the contract permanently. This means the incentivizer loses 0.04% of their incentives and every lender lost 4e17 / 6.

Root Cause

In DebitaIncentives.sol, there is no mechanism for incentivizers to withdraw unclaimed incentives that cannot be claimed due to precision loss.

Internal pre-conditions

  1. Incentivizers need to call DebitaIncentives::incentivizePair() to incentivize specific token pairs.
  2. Users need to interact with one of these incentivized pairs by borrowing or lending them.

External pre-conditions

None.

Attack Path

  1. A user that interacted with an incentivized token pair calls DebitaIncentives::claimIncentives(). He will receive less funds due to rounding. The funds will be stuck in the contract.

Impact

In this example, the incentivizer suffers an approximate loss of 0.04%. This loss could increase as the number of distinct lenders and borrowers interacting with the protocol grows, aligning with the protocol's objective of fostering increased activity. Users experience a partial loss of their incentive share each time they interact with an incentivized pair within a 14-day period.

It is important to note that incentivizers can incentivize an unlimited number of token pairs for an unlimited number of epochs. Additionally, lenders can participate across multiple epochs.

While the amount of locked funds in this simple scenario is relatively small, similar scenarios could occur repeatedly over an unlimited number of epochs. Over time, this accumulation could result in hundreds of tokens being permanently locked in the contract.

PoC

The following should be added in MultipleLoansDuringIncentives.t.sol:

Solidity
address fourthLender = address(0x04);
address fifthLender = address(0x05);
address sixthLender = address(0x06);

Add the following test to MultipleLoansDuringIncentives.t.sol:

Solidity
function testUnclaimableIncentives() public {
    incentivize(AERO, AERO, USDC, true, 1000e18, 2);
    vm.warp(block.timestamp + 15 days);
    createLoan(borrower, firstLender, AERO, AERO);
    createLoan(borrower, secondLender, AERO, AERO);
    createLoan(borrower, thirdLender, AERO, AERO);
    createLoan(borrower, fourthLender, AERO, AERO);
    createLoan(borrower, fifthLender, AERO, AERO);
    createLoan(borrower, sixthLender, AERO, AERO);
    vm.warp(block.timestamp + 30 days);
        
    // principles, tokenIncentives, epoch with dynamic Data
    address[] memory principles = allDynamicData.getDynamicAddressArray(1);
    address[] memory tokenUsedIncentive = allDynamicData
        .getDynamicAddressArray(1);
    address[][] memory tokenIncentives = new address[][](
        tokenUsedIncentive.length
    );
    principles[0] = AERO;
    tokenUsedIncentive[0] = USDC;
    tokenIncentives[0] = tokenUsedIncentive;

    vm.startPrank(firstLender);
    uint balanceBefore_First = IERC20(USDC).balanceOf(firstLender);
    incentivesContract.claimIncentives(principles, tokenIncentives, 2);
    uint balanceAfter_First = IERC20(USDC).balanceOf(firstLender);
    vm.stopPrank();

    vm.startPrank(secondLender);
    uint balanceBefore_Second = IERC20(USDC).balanceOf(secondLender);
    incentivesContract.claimIncentives(principles, tokenIncentives, 2);
    uint balanceAfter_Second = IERC20(USDC).balanceOf(secondLender);
    vm.stopPrank();

    vm.startPrank(thirdLender);
    uint balanceBefore_Third = IERC20(USDC).balanceOf(thirdLender);
    incentivesContract.claimIncentives(principles, tokenIncentives, 2);
    uint balanceAfter_Third = IERC20(USDC).balanceOf(thirdLender);
    vm.stopPrank();

    vm.startPrank(fourthLender);
    uint balanceBefore_Fourth = IERC20(USDC).balanceOf(fourthLender);
    incentivesContract.claimIncentives(principles, tokenIncentives, 2);
    uint balanceAfter_Fourth = IERC20(USDC).balanceOf(fourthLender);
    vm.stopPrank();

    vm.startPrank(fifthLender);
    uint balanceBefore_Fifth = IERC20(USDC).balanceOf(fifthLender);
    incentivesContract.claimIncentives(principles, tokenIncentives, 2);
    uint balanceAfter_Fifth = IERC20(USDC).balanceOf(fifthLender);
    vm.stopPrank();

    vm.startPrank(sixthLender);
    uint balanceBefore_Sixth = IERC20(USDC).balanceOf(sixthLender);
    incentivesContract.claimIncentives(principles, tokenIncentives, 2);
    uint balanceAfter_Sixth = IERC20(USDC).balanceOf(sixthLender);
    vm.stopPrank();

    uint claimedFirst = balanceAfter_First - balanceBefore_First;
    uint claimedSecond = balanceAfter_Second - balanceBefore_Second;
    uint claimedThird = balanceAfter_Third - balanceBefore_Third;
    uint claimedFourth = balanceAfter_Fourth - balanceBefore_Fourth;
    uint claimedFifth = balanceAfter_Fifth - balanceBefore_Fifth;
    uint claimedSixth = balanceAfter_Sixth - balanceBefore_Sixth;

    assertEq(claimedFirst, claimedSecond);
    assertEq(claimedSecond, claimedThird);
    assertEq(claimedThird, claimedFourth);
    assertEq(claimedFourth, claimedFifth);
    assertEq(claimedFifth, claimedSixth);

    // formula percentage: porcentageLent = (lentAmount * 10000) / totalLentAmount;
    // (5e18 * 10000) / 30e18 = 1666.66667 (16.6666667%)
    // rounded to 1666 (16%), 0.66667 (0.0066667%) will be lost
    uint amount = (1000e18 * 1666) / 10000;

    assertEq(amount, 1666e17);
    assertEq(claimedFirst, amount);
        
    uint claimedAmount = claimedFirst + claimedSecond + claimedThird + claimedFourth + claimedFifth + claimedSixth;

    // 6 different lenders with lend orders of 5e18 will not get the whole 1000e18 of incentives
    assertNotEq(1000e18, claimedAmount);

    // percentage should be approximately 1666.66667 (16.6666667%)
    // rounded to 1666 (16%), 0.66667 (0.0066667%) will be lost per lend order

    uint lockedAmount = 1000e18 - claimedAmount;

    // 0.04% of 1000e18 (4e17) will be locked forever
    assertEq(lockedAmount, 4e17);
}

Mitigation

Consider adding a mechanism that allows incentivizers to withdraw their unclaimed incentives from all their past incentivized epochs after a specified period following the end of the last incentivized epoch (e.g., two epochs later).

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/DebitaFinance/Debita-V3-Contracts/commit/f9fc693f1fb78447b44a11be8808b1d482b6e0ae

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

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 lack of a mechanism for incentivizers to withdraw unclaimed incentives that remain due to rounding.

Impact

The incentivizer loses approximately 0.04% of incentives in the example, and this loss could increase with more users and epochs, leading to hundreds of tokens permanently locked.

What the attacker needed

Incentivizers call incentivizePair(); users interact with incentivized pairs

The fix

The protocol team fixed this issue by adding a mechanism for incentivizers to withdraw unclaimed incentives after a specified period.

How it was found

  1. Six lenders each lend 5e18 tokens for a specific pair over 14 days.
  2. The pair is incentivized with 1000e18 tokens.
  3. Each lender calls claimIncentives() and receives a rounded-down share.
  4. The total claimed is less than 1000e18, leaving 4e17 locked.

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.

When you claim a reward, the system calculates your share as a percentage and rounds it down to two decimal places. This means you get slightly less than your exact share, and the tiny leftover amount stays stuck in the contract forever. Over time, many small leftovers add up to a significant amount that nobody can retrieve.

More by BengalCatBalu

View all

3 more disclosed reports, best first.

More from Debita Finance V3

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.