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.
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
newIbRatiouses an incorrectstartSupplyvariable which is under-represented. As new tokens may be minted inhandleFees(), this will lead to an incorrectibRatiowhich is used in all other areas of the protocol. A loweribRatiocausespushUnderlying()andpullUnderlying()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
mediumseverity issue.
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.