Skip to content
Business logic Audit finding Intermediate

Dutch auction can be manipulated

The Dutch auction for arbitrage tokens can be manipulated by purchasing all but one wei of the maximum commitments, preventing the auction from ending early and forcing it to continue until the price drops to the midpoint between start and end. An attacker can thus guarantee a purchase at a lower price.

gzeon Follow

Originally disclosed on Code4rena

Submitted by gzeon

When malt is under-peg and the swing trader module do not have enough capital to buy back to peg, a Dutch auction is triggered to sell arb token. The price of the Dutch auction decrease linearly toward endprice until _endAuction() is called. https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/Auction.sol#L589

_endAuction() is called in

  1. When auction.commitments >= auction.maxCommitments

https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/Auction.sol#L212

  1. On stabilize() -> checkAuctionFinalization() -> _checkAuctionFinalization()

https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/StabilizerNode.sol#L146 https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/Auction.sol#L754

  1. On stabilize() ->_startAuction() -> triggerAuction() -> _checkAuctionFinalization()

https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/StabilizerNode.sol#L170 https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/Auction.sol#L754

It is possible manipulate the dutch auction by preventing _endAuction() being called.

Proof of Concept

Consider someone call purchaseArbitrageTokens with auction.maxCommitments minus 1 wei, _endAuction won’t be called because auction.commitments < auction.maxCommitments. Further purchase would revert because purchaseAndBurn (https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/Auction.sol#L184) would likely revert since swapping 1 wei in most AMM will fail due to rounding error. Even if it does not revert, there is no incentive to waste gas to purchase 1 wei of token.

As such, the only way for the auction to finalize is to call stabilize(). However, this is not immediately possible because it require block.timestamp >= stabilizeWindowEnd where stabilizeWindowEnd = block.timestamp + stabilizeBackoffPeriod stabilizeBackoffPeriod is initially set to 5 minutes in the contract

After 5 minute, stabilize() can be called by anyone. By using this exploit, an attacker can guarantee he can purchase at (startingPrice+endingPrice)/2 or lower, given the default 10 minute auctionLength and 5 minute stabilizeBackoffPeriod. (unless a privileged user call stabilize() which override the stability window)

Also note that stabilize() might not be called since there is no incentive.

Recommended Mitigation Steps

  1. Incentivize stabilize() or incentivize a permission-less call to _endAuction()
  2. Lock-in auction price when user commit purchase

0xScotch (sponsor) labeled sponsor confirmed

Alex the Entreprenerd (judge) commented:

By purchasing all but 1 wei of arbitrageTokens, any caller can guarantee that the auction will offer the steepest discount.

This is caused by the fact that AMMs (esp UniV2) will revert with small numbers, as rounding will cause the amountOut to == 0 which will cause a INSUFFICIENT_AMOUNT revert.

I agree with the pre-conditions and the possibility of this to happen. In a sense I believe this can become the meta strategy that every dutch auction participant will use (the fight between buyers will be done by paying gas to be the first few to buy arbitrageTokens).

So the question is how to avoid it. I guess purchasing at a time should lock the price for that particular buyer at that particular time (adding a mapping should increase cost of 20k on write and a few thousand gas on read).

Alex the Entreprenerd (judge) commented:

TODO: Decide on severity

Medium for sure, extract value reliably. Is it high though? Arguably the dutch auction is not properly coded as it allows to get a further discount instead of locking in a price for the user at time of deposit

Alex the Entreprenerd (judge) commented:

While an argument for the Dutch Auction being coded wrong (user locking in price) can be made, that’s not the definition of a Dutch Auciton

https://www.investopedia.com/terms/d/dutchauction.asp

So arguably the dutch auction is properly coded, it’s that there’s a specific way to sidestep it which is caused by:

  • 1 wei tx reverting on swap
  • sum of purchases not being enough

For this conditions to happen the “exploiter” needs to be fast enough to place an order, in such a way that their order will leave 1 commitment left. I can imagine them setting up a contract that reverts if this condition isn’t met and that checks for w/e amount is needed at that time.

I would assume that having an admin privileged function to close the auction prematurely would solve this specific attack.

I believe that the warden has identified a fairly reliable way to get a discount from the protocol because of the impact and some of the technicalities I believe Medium Severity to be more appropriate. This will be exploited, but in doing so will make the protocol successful (all auction full minus 1 wei), the premium / discount will be reliable predicted (50% between start and end) and as such I believe it will be priced in

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

An attacker can guarantee purchasing at (startingPrice+endingPrice)/2 or lower, but the attack requires being fast enough to place the order leaving 1 commitment, and stabilize() might not be called due to lack of incentive.

What the attacker needed

Auction is active; Attacker can purchase tokens; Attacker is fast enough to leave 1 wei

The fix

The fix should incentivize stabilize() or permissionless _endAuction(), and lock in the auction price when a user commits a purchase.

How it was found

  1. Call purchaseArbitrageTokens with auction.maxCommitments minus 1 wei.
  2. The auction does not end because commitments are below maxCommitments.
  3. Further purchases revert due to rounding in AMM swap.
  4. Wait for stabilizeWindowEnd (5 minutes) to pass.
  5. Call stabilize() to finalize the auction at a lower price.

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 Dutch auction is a sale where the price starts high and goes down over time. The report shows that someone can stop the auction from ending early by buying almost all the tokens, leaving just a tiny amount unsold. This forces the price to keep dropping, so the attacker can buy at a lower price.

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.

More by gzeon

View all

46 more disclosed reports, best first.

More from Malt Protocol - Versus contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.