Reentrancy in settleAuction(): malicious publisher can bypass index timelock mechanism, inject malicious index, and rug the basket
The settleAuction() function calls withdrawBounty() before setting auctionOngoing to false, allowing a malicious publisher to reenter and bypass the index timelock. This lets the publisher set malicious weights and withdraw all basket funds.
Submitted by kenzo, also found by itsmeSTYJ and jonah1005
The settleAuction() function calls withdrawBounty() before setting auctionOngoing = false, thereby allowing reentrancy.
Impact
A malicious publisher can bypass the index timelock mechanism and publish new index which the basket’s users won’t have time to respond to. At worst case, this means setting weights that allow the publisher to withdraw all the basket’s underlying funds for himself, under the guise of a valid new index.
Proof of Concept
-
The publisher (a contract) will propose new valid index and bond the auction.
To settle the auction, the publisher will execute the following steps in the same transaction:
-
Add a bounty of an ERC20 contract with a malicious
transfer()function. -
Settle the valid new weights correctly (using
settleAuction()with the correct parameters, and passing the malicious bounty id). -
settleAuction()will callwithdrawBounty()which upon transfer will call the publisher’s malicious ERC20 contract. -
The contract will call
settleAuction()again, with empty parameters. Since the previous call’s effects have already set all the requirements to be met,settleAuction()will finish correctly and callsetNewWeights()which will set the new valid weights and setpendingWeights.pending = false. -
Still inside the malicious ERC20 contract transfer function, the attacker will now call the basket’s
publishNewIndex(), with weights that will transfer all the funds to him upon his burning of shares. This call will succeed to set new pending weights as the previous step setpendingWeights.pending = false. -
Now the malicious
withdrawBounty()has ended, and the originalsettleAuction()is resuming, but now with malicious weights inpendingWeights(set in step 6).settleAuction()will now callsetNewWeights()which will set the basket’s weights to be the malicious pending weights. -
Now
settleAuctionhas finished, and the publisher (within the same transaction) willburn()all his shares of the basket, thereby transferring all the tokens to himself.
POC exploit: Password to both files: “exploit”. AttackPublisher.sol , to be put under contracts/contracts/Exploit: https://pastebin.com/efHZjstS ExploitPublisher.test.js , to be put under contracts/test: https://pastebin.com/knBtcWkk
Tools Used
Manual analysis, hardhat.
Recommended Mitigation Steps
In settleAuction(), move basketAsERC20.transfer() and withdrawBounty() to the end of the function, conforming with Checks Effects Interactions pattern.
frank-beard (defiProtocol) confirmed
Alex the Entreprenerd (judge) commented:
This is a re-entrancy finding.
There is no denying that the code is vulnerable to re-entrancy
The warden identified the way to exploit re-entrancy by using a malicious bounty token.
I think the finding is valid and the warden has shown how to run re-entrnacy.
That said the POC the warden shows requires calling
publishNewIndexwhich is aonlyPublisherfunction. This exploit would be contingent on the publisher rugging the basket.The code is:
- Vulnerable to re-entancy
- The warden showed how to trigger it
Despite the fact that the POC is flawed, I believe this finding highlights a different vector for re-entrancy (bounty token transfers) as such I agree with a high severity
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
Impact
A malicious publisher could bypass the index timelock and set weights that allow them to withdraw all basket funds, though the exploit requires the publisher to be the attacker.
What the attacker needed
Attacker is the publisher; malicious ERC20 token with reentrant transfer
The fix
Move the external calls (transfer and withdrawBounty) to the end of settleAuction() to follow the checks-effects-interactions pattern.
How it was found
- The publisher proposes a new valid index and bonds the auction.
- The publisher adds a bounty of an ERC20 contract with a malicious transfer() function.
- The publisher calls settleAuction() with correct parameters and the malicious bounty id.
- settleAuction() calls withdrawBounty(), which triggers the malicious ERC20 contract.
- The malicious contract calls settleAuction() again with empty parameters, which succeeds and sets new weights.
- Still inside the malicious transfer, the attacker calls publishNewIndex() with weights that transfer all funds to them.
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.
A reentrancy attack happens when a contract calls another contract before finishing its own updates, letting the called contract call back into the original and exploit the incomplete state. Here, the basket contract lets a malicious publisher sneak in a new index before the auction is properly closed, so they can steal all the funds.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.