Auction bonder can steal user funds if bond block is high enough
The auction settlement logic calculates a new ratio that decreases over time without a lower bound, so after enough blocks it can become smaller than the basket's initial ratio or near zero. A malicious user could then bond and settle the auction to withdraw nearly all tokens from the basket, stealing user funds.
Submitted by kenzo.
After an auction has started, as time passes and according to the bondBlock, newRatio (which starts at 2*ibRatio) gets smaller and smaller and therefore less and less tokens need to remain in the basket. This is not capped, and after a while, newRatio can become smaller than current ibRatio.
Impact
If for some reason nobody has bonded and settled an auction and the publisher didn’t stop it, a malicious user can wait until newRatio < ibRatio, or even until newRatio ~= 0 (for an initial ibRatio of ~1e18 this happens after less than 3.5 days after auction started), and then bond and settle and steal user funds.
Proof of Concept
These are the vulnerable lines: https://github.com/code-423n4/2021-10-defiprotocol/blob/main/contracts/contracts/Auction.sol#L95:#L105
uint256 a = factory.auctionMultiplier() * basket.ibRatio();
uint256 b = (bondBlock - auctionStart) * BASE / factory.auctionDecrement();
uint256 newRatio = a - b;
(address[] memory pendingTokens, uint256[] memory pendingWeights) = basket.getPendingWeights();
IERC20 basketAsERC20 = IERC20(address(basket));
for (uint256 i = 0; i < pendingWeights.length; i++) {
uint256 tokensNeeded = basketAsERC20.totalSupply() * pendingWeights[i] * newRatio / BASE / BASE;
require(IERC20(pendingTokens[i]).balanceOf(address(basket)) >= tokensNeeded);
}
The function verifies that pendingTokens[i].balanceOf(basket) >= basketAsERC20.totalSupply() * pendingWeights[i] * newRatio / BASE / BASE. This is the formula that will be used later to mint/burn/withdraw user funds. As bondBlock increases, newRatio will get smaller, and there is no check on this. After a while we’ll arrive at a point where newRatio ~= 0, so tokensNeeded = newRatio*(...) ~= 0, so the attacker could withdraw nearly all the tokens using outputTokens and outputWeights, and leave just scraps in the basket.
Tools Used
Manual analysis, hardhat.
Recommended Mitigation Steps
Your needed condition/math might be different, and you might also choose to burn the bond while you’re at it, but I think at the minimum you should add a sanity check in settleAuction:
require (newRatio > basket.ibRatio());
Maybe you would require newRatio to be > BASE but not sure.
frank-beard (Kuiper) confirmed
Alex the Entreprenerd (judge) commented:
Would need to confirm with sponsor: Isn’t the point of
settleAuctionto be incentivized by offering a discount over time? If you’re offering a discount, then by definitionnewRatiowill be less thanbasket.ibRatio
Alex the Entreprenerd (judge) commented:
Have yet to hear back from the sponsor.
The more I think about it, the more this is a property of the discounted auction, the basket token can be bought for less, and that creates MEV opportunities. This is the economic incentive for bonding and settling the auction (else why do it?)
On the other hand there may be situation where the price decay is so aggressive, and the bonding gives a 24hrs privilege for settling which could create a situation where the bonder is incentivized to wait.
Locking the discount at the time of bonding, or forcing to bond and settle at the same time may mitigate this (creating effectively a dutch auction for the discounted basket tokens).
Given what I understand about the system, I would argue that:
- Given a specific
auctionDecrementand a basket big enough, the bonder has a 24 hour window to maximize the value they can extract, which can end up being too much from what the developer / users may expect.What do you think @frank-beard ?
frank-beard (Kuiper) commented:
Agree with @Alex the Entreprenerd. The purpose of the auction is to create an opportunity for participants to rebalance a basket if it is in their interest. However the warden is correct that there can be issues if the
ibRatiodrops too low, or even to 0, which would effectively allow someone to steal funds. We plan to mitigate this by having the auction have a minimumibRatioat which it can be settled.
Alex the Entreprenerd (judge) commented:
The vulnerability is reliant on
auctionDecrementbeing impactful enough on a 24 hr window (time in which bonder has privileged ability to settle or just stall)If
auctionDecrementgives a steep enough discount then it can creates scenarios where the bonder can get access to the underlying at no price. This can be taken to the extreme of rebalancing the entire basket (taking all funds)Because of the openness of the protocol am inclined to rate this a medium severity, however, the sponsor needs to be aware that every single time this scenario shows itself it will be abused against the protocol users.
Mitigation can happen by either setting a minimum
ibRatioor by allowing multiple entities to bond and settle at the same, creating a “prisoners dilemma” dutch auction that effectively motivates actors to rebalance as early as economically feasible
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 settlement function lacks a minimum bound on newRatio, allowing it to fall below the basket's ibRatio or to near zero.
Impact
A malicious user could steal user funds by withdrawing nearly all tokens from the basket, though the judge noted this depends on auctionDecrement being impactful enough and rated it medium severity.
What the attacker needed
Auction started and not settled; publisher did not stop auction; enough blocks passed for newRatio to drop
The fix
The sponsor plans to mitigate by having the auction enforce a minimum ibRatio at which it can be settled.
How it was found
- Wait until an auction has started and enough blocks have passed so that newRatio becomes less than ibRatio or near zero.
- Call bond and then settle the auction.
- Withdraw nearly all tokens from the basket using outputTokens and outputWeights, leaving only scraps.
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 auction system, a 'bond' is a deposit someone makes to settle an auction and get a reward. The reward grows over time as a ratio called newRatio goes down. The bug is that this ratio can go down too far, even to near zero, letting the bonder take almost everything from the shared basket of tokens.
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.