Skip to content
Smart contracts Audit finding Advanced

Basket.sol#auctionBurn calculates ibRatio wrong

The auctionBurn function calculates the new ibRatio using a startSupply value that does not include tokens minted during handleFees, leading to an inflated ibRatio. This causes basket token holders to lose value when burning or minting, as the ratio is used throughout the protocol.

0x0x0x Follow

Originally disclosed on Code4rena

Submitted by 0x0x0x

The function is implemented as follows:

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

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

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

When handleFees is called, totalSupply and ibRatio changes accordingly, but for newIbRatio calculation tokens minted in handleFees is not included. Therefore, ibRatio is calculated higher than it should be. This is dangerous, since last withdrawing user(s) lose their funds with this operation. In case this miscalculation happens more than once, newIbRatio will increase the miscalculation even faster and can result in serious amount of funds missing. At each time auctionBurn is called, at least 1 day (auction duration) of fees result in this miscalculation. Furthermore, all critical logic of this contract is based on ibRatio, this behaviour can create serious miscalculations.

Mitigation step

Rather than

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

A practical solution to this problem is calculating newIbRatio as follows:

uint256 supply = totalSupply();
uint256 newIbRatio = ibRatio * (supply + amount) / supply;

frank-beard (Kuiper) confirmed

0xleastwood (judge) decreased severity to Medium and commented:

The warden has identified an issue whereby newIbRatio uses an incorrect startSupply variable which is under-represented. As new tokens may be minted in handleFees(), this will lead to an incorrect ibRatio which is used in all other areas of the protocol. A lower ibRatio causes pushUnderlying() and pullUnderlying() to be improperly accounted for. As a result, burning basket tokens will redeem a smaller amount of underlying tokens and minting basket tokens will require a smaller amount of underlying tokens.

This causes the protocol to leak value from all basket token holders but it does not allow assets to be stolen. As such, I think this is better put as a medium severity issue.


The original report as published on Code4rena, by 0x0x0x. 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 new ibRatio is calculated using the total supply before fees are handled, ignoring tokens minted during handleFees, so the denominator is too small and the ratio too high.

Impact

The miscalculation causes the protocol to leak value from all basket token holders, though it does not allow assets to be stolen; repeated occurrences can worsen the error and lead to serious fund shortages.

What the attacker needed

Calling auctionBurn; fees minted in handleFees

The fix

The new ibRatio should be calculated using the current total supply after fees, for example by using supply = totalSupply() and newIbRatio = ibRatio * (supply + amount) / supply.

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 bug where a number called ibRatio is updated incorrectly after burning tokens. The code forgets that new tokens were created just before, so the ratio becomes too high. As a result, people who later withdraw their funds get less than they should, and the mistake grows each time.

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 0x0x0x

View all

6 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.

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.