Skip to content
Business logic Audit finding Intermediate

The debt in EligibilityDataProvider::requiredUsdValue() needs to be converted into USD; otherwise, it is not a correct value comparison

The reward eligibility check compares a USD value of locked LP tokens against a required value that is calculated by applying a ratio to a raw debt amount without first converting that debt to USD. As a result, the effective threshold is about 4.5% of total debt instead of the documented 5%, so users can qualify for rewards with less locked value than intended.

lian886 Follow with pkqs90 and nnez

Originally disclosed on Code4rena

Submitted by lian886, also found by pkqs90 and nnez

https://github.com/code-423n4/2024-07-loopfi/blob/57871f64bdea450c1f04c9a53dc1a78223719164/src/reward/EligibilityDataProvider.sol#L187

https://github.com/code-423n4/2024-07-loopfi/blob/57871f64bdea450c1f04c9a53dc1a78223719164/src/reward/EligibilityDataProvider.sol#L197

https://github.com/code-423n4/2024-07-loopfi/blob/57871f64bdea450c1f04c9a53dc1a78223719164/src/reward/EligibilityDataProvider.sol#L274

https://github.com/code-423n4/2024-07-loopfi/blob/57871f64bdea450c1f04c9a53dc1a78223719164/src/reward/EligibilityDataProvider.sol#L177

Impact

It does not align with the documentation and the eligibility criteria for rewards are lower than what is specified by the protocol.

Proof of Concept

   function requiredUsdValue(address user) public view returns (uint256 required) {
@>>        uint256 totalNormalDebt = vaultRegistry.getUserTotalDebt(user);
@>>        required = (totalNormalDebt * requiredDepositRatio) / RATIO_DIVISOR;
        return _lockedUsdValue(required);
    }

Here, the value of totalNormalDebt should be calculated first, and then the requiredDepositRatio should be applied to that value.

However, in the current implementation:

function isEligibleForRewards(address _user) public view returns (bool) {
        uint256 lockedValue = lockedUsdValue(_user);

        uint256 requiredValue = (requiredUsdValue(_user) * priceToleranceRatio) / RATIO_DIVISOR;
        return requiredValue != 0 && lockedValue >= requiredValue;
    }
function lockedUsdValue(address user) public view returns (uint256) {
        Balances memory _balances = IMultiFeeDistribution(multiFeeDistribution).getBalances(user);
        return _lockedUsdValue(_balances.locked);
    }
function _lockedUsdValue(uint256 lockedLP) internal view returns (uint256) {
        uint256 lpPrice = priceProvider.getLpTokenPriceUsd();
        return (lockedLP * lpPrice) / 10 ** 18;
    }

Based on the lockedUsdValue function and the _lockedUsdValue() function, we know that:

lockedValue = _lockedUsdValue(_balances.locked) = (_balances.locked * lpPrice) / 10**18;

uint256 requiredValue = (requiredUsdValue(_user) * priceToleranceRatio) / RATIO_DIVISOR;

This expands to:

requiredValue = _lockedUsdValue((totalNormalDebt * requiredDepositRatio) / RATIO_DIVISOR) * priceToleranceRatio / RATIO_DIVISOR;

Which further breaks down to:

requiredValue = (((totalNormalDebt * requiredDepositRatio) / RATIO_DIVISOR) * lpPrice / 10**18) * (priceToleranceRatio / RATIO_DIVISOR);

This shows the step-by-step calculation of the lockedValue and requiredValue based on the total debt, deposit ratio, and price tolerances.

Thus, the comparison lockedValue >= requiredValue becomes:

lockedLP > totalNormalDebt * (requiredDepositRatio / RATIO_DIVISOR) * (priceToleranceRatio / RATIO_DIVISOR)

Where:

  • requiredDepositRatio / RATIO_DIVISOR = 5%
  • priceToleranceRatio / RATIO_DIVISOR = 90%

This simplifies to:

lockedLP > totalNormalDebt * 5% * 90% = 4.5% * totalNormalDebt

So, the condition checks if the lockedLP is greater than 4.5% of the totalNormalDebt.

This contradicts the description in the documentation:

“Loopers maintaining a dLP value exceeding 5% of their Total Position Size qualify for LOOP token emissions to offset borrowing costs incurred from leveraging.”

In reality, because the value of one lockedLP token is lower than the value of the debt (in ETH), the number of lockedLP tokens falls far short of the actual requirement.

Recommended Mitigation Steps

In the requiredUsdValue function, the debt value is first calculated and then multiplied by the relevant ratio. In fact, Radiant Capital implements this exact approach in their code, as shown here.

Assessed type

Error

amarcu (LoopFi) confirmed


The original report as published on Code4rena, by lian886. 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 required USD value is computed by multiplying a raw debt amount by a ratio before converting the debt to USD, so the comparison mixes units and understates the requirement.

Impact

The eligibility threshold is effectively about 4.5% instead of the documented 5%, so more users may qualify for rewards than intended.

What the attacker needed

None

The fix

The required USD value should be calculated by first converting the total debt to USD and then applying the required deposit ratio.

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 that decides who earns rewards. It compares two numbers: the value of tokens a user has locked and a required value based on their debt. The bug is that one of those numbers is not converted into the same units (US dollars) before the comparison, so the test is too lenient and lets people qualify with less locked value than the rules say.

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 lian886

View all

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