Auction.sol#settleAuction() late auction bond could potentially not being able to be settled, cause funds loss to bonder
The settleAuction function can revert due to an arithmetic underflow when an auction is bonded late, because the calculated newRatio becomes negative. This prevents the bonder from settling the auction and causes them to lose their bond.
Submitted by WatchPug
The newRatio that determines tokensNeeded to settle the auction is calculated based on auctionMultiplier, bondTimestamp - auctionStart and auctionDecrement.
uint256 a = factory.auctionMultiplier() * basket.ibRatio();
uint256 b = (bondTimestamp - auctionStart) * BASE / factory.auctionDecrement();
uint256 newRatio = a - b;
However, if an auction is bonded late (bondTimestamp - auctionStart is a large number), and/or the auctionMultiplier is small enough, and/or the auctionDecrement is small enough, that makes b to be greater than a, so that uint256 newRatio = a - b; will revert on underflow.
This might seem to be an edge case issue, but considering that a rebalance auction of a bag of shitcoin to high-value tokens might just end up being bonded at the last minute, with a newRatio near zero. When we take the time between the bonder submits the transaction and it got packed into a block, it’s quite possible that the final bondTimestamp gets large enough to revet a - b.
Impact
An auction successfully bonded by a regular user won’t be able to be settled, and the user will lose the bond.
Proof of Concept
With the configuration of:
basket.ibRatio = 1e18 factory.auctionDecrement = 5760 (Blocks per day) factory.auctionMultiplier = 2
- Create an auction;
- The auction remain inactive (not get bonded) for more than 2 days (>11,520 blocks);
- Call
bondForRebalance()and it will succeed; - Calling
settleAuction()will always revert.
Recommended Mitigation Steps
Calculate and require newRatio > 0 in bondForRebalance(), or limit the max value of decrement and make sure newRatio always > 0 in settleAuction().
frank-beard (Kuiper) confirmed
Alex the Entreprenerd (judge) commented:
Finding is valid, there are cases that can cause a - b to revert
The finding is reliant on external condition (multiplier being low and / or bonding late) as such I believe this to be a medium severity finding.
Note for the sponsor: The cause for reverts should get clearer with time (as people use the protocol), you definitely want to model these revert behaviour to avoid edge cases that will make funds stuck
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 subtraction a - b in settleAuction can underflow when b exceeds a, which happens if the auction is bonded late or if auctionMultiplier or auctionDecrement are small.
What the attacker needed
AuctionMultiplier and/or auctionDecrement small; auction bonded late (large time delta)
The fix
Calculate and require newRatio > 0 in bondForRebalance(), or limit the maximum value of decrement to ensure newRatio always > 0 in settleAuction().
How it was found
- Create an auction.
- Leave the auction inactive (not bonded) for more than 2 days (>11,520 blocks).
- Call bondForRebalance() and it will succeed.
- Call settleAuction() and it will always revert.
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.
In this smart contract, when someone bonds an auction, they pay a bond and later get it back if they settle the auction. The code calculates a number called newRatio by subtracting a time-based value from a base value. If the auction is bonded very late, the time-based value can become larger than the base value, causing the subtraction to fail (underflow) and the settlement to always revert. As a result, the bonder cannot settle and loses their bond.
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.