Skip to content
Business logic Audit finding Beginner

Bad Debt in PoolLens.sol#getPoolBadDebt() is not calculated correctly in USD

The getPoolBadDebt view function in PoolLens multiplies a market's bad debt by the oracle price without dividing by 1e18, unlike the equivalent calculation in Shortfall. This makes the reported bad debt in USD massively inflated compared with the correct value.

peanuts Follow with jasonxiale, 0xStalin and 1 other

Originally disclosed on Code4rena

Submitted by peanuts, also found by jasonxiale, 0xStalin and volodya.

Proof of Concept

In PoolLens.sol#getPoolBadDebt(), bad debt is calculated as such:

            badDebt.badDebtUsd =
                VToken(address(markets[i])).badDebt() *
                priceOracle.getUnderlyingPrice(address(markets[i]));
            badDebtSummary.badDebts[i] = badDebt;
            totalBadDebtUsd = totalBadDebtUsd + badDebt.badDebtUsd;

In Shortfall.sol#\_startAuction(), bad debt is calculated as such:

        uint256[] memory marketsDebt = new uint256[](marketsCount);
        auction.markets = new VToken[](marketsCount);

        for (uint256 i; i < marketsCount; ++i) {
            uint256 marketBadDebt = vTokens[i].badDebt();

            priceOracle.updatePrice(address(vTokens[i]));
            uint256 usdValue = (priceOracle.getUnderlyingPrice(address(vTokens[i])) * marketBadDebt) / 1e18;

            poolBadDebt = poolBadDebt + usdValue;

Focus on the line with the priceOracle.getUnderlyingPrice. In PoolLens.sol#getPoolBadDebt, badDebt in USD is calculated by multiplying the bad debt of the VToken market by the underlying price. However, in Shortfall, badDebt in USD is calculated by the bad debt of the VToken market by the underlying price and divided by 1e18.

The PoolLens#getPoolBadDebt() function doesn’t divide the debt in USD by 1e18.

This is what the function is actually counting:

Let’s say that the VToken market has a badDebt of 1.3 ETH (1e18 ETH). The pool intends to calculate 1.3 ETH in terms of USD, so it calls the oracle to determine the price of ETH. Let’s say the price of ETH is 1500 USD. The total pool debt should be 1.3 * 1500 = 1950 USD. In decimal calculation, the pool debt should be 1.3e18 * 1500e18 (if oracle returns in 18 decimal places) / 1e18 = 1950e18.

The badDebt in USD in PoolLens.sol#getPoolBadDebt() will be massively inflated.

Tools Used

VSCode

Recommended Mitigation Steps

Normalize the decimals of the bad debt calculation in getPoolBadDebt().

            badDebt.badDebtUsd =
                VToken(address(markets[i])).badDebt() *
+               priceOracle.getUnderlyingPrice(address(markets[i])) / 1e18;
            badDebtSummary.badDebts[i] = badDebt;
            totalBadDebtUsd = totalBadDebtUsd + badDebt.badDebtUsd;

Assessed type

Decimal

chechu (Venus) confirmed


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

Any consumer of getPoolBadDebt receives a massively inflated bad debt figure in USD, which could mislead reporting or downstream logic that relies on it.

What the attacker needed

None

The fix

The decimals of the bad debt calculation in getPoolBadDebt should be normalised by dividing the product by 1e18.

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.

Smart contracts store token amounts as whole numbers scaled up by a large factor (1e18) to represent fractions. When converting an amount into dollars, you must divide by that same factor to bring the number back to a normal scale. Here one function forgot that division, so the dollar figure it reports is far too large.

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 peanuts

View all

3 more disclosed reports, best first.

More from Venus Prime

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.