Skip to content
Smart contracts Audit finding Intermediate

ShortFall contract might transfer an incorrect amount of tokens to the highest bidder.

The ShortFall auction contract computes the amount owed to the highest bidder in USD terms but then transfers that same number of convertibleBaseAsset tokens directly, without converting through the price oracle. If the base asset is not pegged to USD, the winner could receive far more value than intended.

fs0c Follow with yongskiws, BPZ and 10 others

Originally disclosed on Code4rena

Submitted by fs0c, also found by yongskiws, BPZ, rvierdiiev, BPZ, rvierdiiev, J4de, Team_Rocket, rvierdiiev, rvierdiiev, peanuts, Brenzee and 0xnev.

There might be an incorrect amount of transfer possible if convertibleBaseAsset is not a token which is pegged to USD.

There is not much information on what convertibleBaseAsset is supposed to be. If it is a token which is not pegged to USD, then the auction process might transfer wrong amount of tokens or entirely wrong tokens.

Let’s take an example of LARGE_RISK_FUND type of auction for simplicity. Assuming the convertibleBaseAsset is not a token pegged to USD (let’s take it as BNB, for this case).

Now the calculation of poolBadDebt is calculated by converting the badDebt to usd terms in the code below:

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;
            auction.markets[i] = vTokens[i];
            auction.marketDebt[vTokens[i]] = marketBadDebt;
            marketsDebt[i] = marketBadDebt;
        }

In this case, the auction properties would be as follows:

auction.seizedRiskFund = incentivizedRiskFundBalance;
auction.startBlock = block.number;
auction.status = AuctionStatus.STARTED;
auction.highestBidder = address(0);

Where incentivizedRiskFundBalance = poolBadDebt + ((poolBadDebt * incentiveBps) / MAX_BPS);

function closeAuction(address comptroller) external nonReentrant {
        Auction storage auction = auctions[comptroller];
				// ...
        if (auction.auctionType == AuctionType.LARGE_POOL_DEBT) {
            riskFundBidAmount = auction.seizedRiskFund;
        } else {
            riskFundBidAmount = (auction.seizedRiskFund * auction.highestBidBps) / MAX_BPS;
        }

        uint256 transferredAmount = riskFund.transferReserveForAuction(comptroller, riskFundBidAmount);
        IERC20Upgradeable(convertibleBaseAsset).safeTransfer(auction.highestBidder, riskFundBidAmount);
    }

When the closeAuction is called, the contract will transfer the riskFundBidAmount of convertibleBaseAsset to the highest bidder. Here, if the convertibleBaseAsset token is not a token pegged to USD, it will transfer those tokens to the highest bidder, where it should have transferred the tokens that amount to that value.

Example:

  • convertibleBaseAsset = TokenA (the price of this token is $100 per 1e18 tokens).
  • PoolBadDebt = 200 * ie18, which should be equal to $200 as poolbaddebt is calculated in USD.
  • seizedRiskFund = 220 * 1e18.

Assume the auction type is LARGE_RISK_FUND and highestBidBps = 10000.

At the auction complete the tokens transferred to the highestbidder would be:

  • riskFundBidAmount = 220 * 1e18 * 10000/10000 = 220 * 1e18
  • Actual price of tokens transferred to the highestbidder = 220 * 100 = $22000
  • Token amount that should be transferred = $220.

Here, the tokens are directly transferred before converting them into the terms of convertibleBaseAsset which causes the main issue.

Recommendation

Before transferring the amount to the highest bidder, ping the Oracle for the correct price of convertibleBaseAsset and then convert the riskFundBidAmount in the terms of convertibleBaseAsset Tokens. Even if a token pegged to USD is used, the Oracle should be used to get the correct value AND the tokens should always be converted in terms of convertibleBaseAsset, as sometimes the pegged tokens might also divert from their price or decimals might be different for different tokens.

Assessed type

Token-Transfer

chechu (Venus) confirmed


The original report as published on Code4rena, by fs0c. 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 payout amount is calculated in USD but transferred as a raw token quantity without converting it through the price oracle into units of convertibleBaseAsset.

Impact

The highest bidder could receive tokens worth far more than the debt being recovered, draining value from the risk fund; the report notes this only applies when the base asset is not USD-pegged.

What the attacker needed

ConvertibleBaseAsset not pegged to USD; an auction reaches closeAuction

The fix

The contract should query the oracle for the convertibleBaseAsset price and convert the bid amount into that token's units before transferring, and the report says this should be done even for USD-pegged tokens.

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 runs an auction to recover bad debt and pays the winner in a chosen token. The code works out the payout as if that token were worth one dollar each, then hands over that many tokens. If the token is actually worth much more, the winner gets a windfall and the protocol loses funds.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by fs0c

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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.