Skip to content
Business logic Audit finding Intermediate

Basket.sol#auctionBurn() A failed auction will freeze part of the funds

The auctionBurn function burns auction bonds without updating the internal exchange rate (ibRatio), so the proportional share of underlying tokens for those bonds remains stuck in the contract. An attacker could cause a failed auction and then call auctionBurn to permanently freeze a portion of the basket's funds.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

https://github.com/code-423n4/2021-09-defiProtocol/blob/main/contracts/contracts/Basket.sol#L102-L108

Given the auctionBurn() function will _burn() the auction bond without updating the ibRatio. Once the bond of a failed auction is burned, the proportional underlying tokens won’t be able to be withdrawn, in other words, being frozen in the contract.

Proof of Concept

With the configuration of:

basket.ibRatio = 1e18 factory.bondPercentDiv = 400 basket.totalSupply = 400 basket.tokens = [BTC, ETH] basket.weights = [1, 1]

  1. Create an auction;
  2. Bond with 1 BASKET TOKEN;
  3. Wait for 24 hrs and call auctionBurn();

basket.ibRatio remains to be 1e18; basket.totalSupply = 399.

Burn 1 BASKET TOKEN will only get back 1 BTC and 1 ETH, which means, there are 1 BTC and 1 ETH frozen in the contract.

Recommended Mitigation Steps

Change to:

function auctionBurn(uint256 amount) onlyAuction external override {
    handleFees();
    uint256 startSupply = totalSupply();
    _burn(msg.sender, amount);

    uint256 newIbRatio = ibRatio * startSupply / (startSupply - amount);
    ibRatio = newIbRatio;

    emit NewIBRatio(newIbRatio);
    emit Burned(msg.sender, amount);
}

frank-beard (Kuiper) confirmed

Alex the Entreprenerd (judge) commented:

The warden has identified a way for funds to be stuck without a way to recoup them, this is because ibRatio is not updated, while totalSupply is.

Because this is a specific accounting error, which is effectively a bug in the logic of the protocol, and funds can be irrevocably lost, this is a high severity finding

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

The auctionBurn function reduces totalSupply without adjusting ibRatio, breaking the invariant that ibRatio times totalSupply equals the total underlying value.

Impact

A failed auction followed by auctionBurn causes a proportional amount of underlying tokens to be permanently frozen in the contract, as confirmed by the judge.

What the attacker needed

A failed auction; ability to call auctionBurn

The fix

The auctionBurn function should update ibRatio after burning, using the formula newIbRatio = ibRatio * startSupply / (startSupply - amount).

How it was found

  1. Create an auction.
  2. Bond with 1 BASKET TOKEN.
  3. Wait for 24 hrs and call auctionBurn().

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 contract holds a basket of tokens and uses a number called ibRatio to track how many underlying tokens each basket token is worth. When someone burns a basket token, the total supply goes down but ibRatio stays the same, so the remaining tokens are now worth less than they should be. The difference stays locked in the contract forever.

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 WatchPug

View all

197 more disclosed reports, best first.

More from Kuiper contest

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.