Skip to content
Smart contracts Audit finding Advanced

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.

kenzo Follow

Originally disclosed on Code4rena

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

  1. 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:

  2. Add a bounty of an ERC20 contract with a malicious transfer() function.

  3. Settle the valid new weights correctly (using settleAuction() with the correct parameters, and passing the malicious bounty id).

  4. settleAuction() will call withdrawBounty() which upon transfer will call the publisher’s malicious ERC20 contract.

  5. 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 call setNewWeights() which will set the new valid weights and set pendingWeights.pending = false.

  6. 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 set pendingWeights.pending = false.

  7. Now the malicious withdrawBounty() has ended, and the original settleAuction() is resuming, but now with malicious weights in pendingWeights (set in step 6). settleAuction() will now call setNewWeights() which will set the basket’s weights to be the malicious pending weights.

  8. Now settleAuction has finished, and the publisher (within the same transaction) will burn() 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 publishNewIndex which is a onlyPublisher function. 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

The original report as published on Code4rena, by kenzo. 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

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

  1. The publisher proposes a new valid index and bonds the auction.
  2. The publisher adds a bounty of an ERC20 contract with a malicious transfer() function.
  3. The publisher calls settleAuction() with correct parameters and the malicious bounty id.
  4. settleAuction() calls withdrawBounty(), which triggers the malicious ERC20 contract.
  5. The malicious contract calls settleAuction() again with empty parameters, which succeeds and sets new weights.
  6. 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.

More by kenzo

View all

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