Skip to content
Business logic Audit finding Advanced

AMM pool can be drained using a flashloan and calling stabilize

The stabilize function uses a short TWAP to decide if intervention is needed, but then calculates the trade size by reading the AMM pool directly, which can be manipulated with a flashloan. An attacker could flashloan to remove most Malt from the pool, call stabilize, and cause the protocol to mint Malt and drain reward tokens from the pool, distributing them as rewards.

stonesandtrees Follow

Originally disclosed on Code4rena

Submitted by stonesandtrees

All of the rewardToken in a given AMM pool can be removed from the AMM pool and distributed as LP rewards.

Proof of Concept

In the stabilize method in the StabilizerNode the initial check to see if the Malt price needs to be stabilized it uses a short period TWAP: https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/StabilizerNode.sol#L156

However, if the price is above the threshold for stabilization then the trade size required to stabilize looks at the AMM pool directly which is vulnerable to flashloan manipulation.

https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/DexHandlers/UniswapHandler.sol#L250-L275

Attack:

  1. Wait for TWAP to rise above the stabilization threshold
  2. Flashloan remove all but a tiny amount of Malt from the pool.
  3. Call stabilize. This will pass the TWAP check and execute _distributeSupply which in turn ultimately calls _calculateTradeSize in the UniswapHandler. This calculation will determine that almost all of the rewardToken needs to be removed from the pool to return the price to peg.
  4. Malt will mint enough Malt to remove a lot of the rewardToken from the pool.
  5. The protocol will now distribute that received rewardToken as rewards. 0.3% of which goes directly to the attacker and the rest goes to LP rewards, swing trader and the treasury.

The amount of money that can be directly stolen by a malicious actor is small but it can cause a lot of pain for the protocol as the pool will be destroyed and confusion around rewards will be created.

Recommended Mitigation Steps

Use a short TWAP to calculate the trade size instead of reading directly from the pool.

0xScotch (sponsor) confirmed

Alex the Entreprenerd (judge) commented:

I believe the warden has identified a valid grief and potential exploit

I’m not convinced on the simplicity of: 2. Flashloan remove all but a tiny amount of Malt from the pool.

You’d have to buy that liquidity in order to be able to remove the malt, which effectively makes the operation not as straightforward (if not unprofitable for the attacker).

I do believe the grief can be performed but in lack of a clear incentive for the attacker, am going to downgrade to Medium Severity. Can be done, but not clear on the incentives

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

Root cause

Likely the trade size calculation reads the instantaneous AMM pool reserves instead of using a manipulation-resistant oracle such as a TWAP.

Impact

The pool can be drained of rewardToken and destroyed, though the direct profit to the attacker is small and the judge noted the incentive is unclear, downgrading to Medium.

What the attacker needed

TWAP above stabilization threshold; Ability to flashloan large amount; Sufficient liquidity to manipulate pool

The fix

The trade size should be calculated using a short TWAP instead of reading directly from the pool.

How it was found

  1. Wait for the TWAP to rise above the stabilization threshold.
  2. Flashloan to remove all but a tiny amount of Malt from the pool.
  3. Call stabilize, which passes the TWAP check and executes _distributeSupply, leading to _calculateTradeSize.
  4. The trade size calculation determines that almost all rewardToken needs to be removed from the pool.
  5. Malt mints enough Malt to remove a lot of rewardToken from the pool.
  6. The protocol distributes the received rewardToken as rewards, with 0.3% going directly to the attacker.

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.

An AMM pool is a smart contract that holds two tokens and lets people trade between them; the price is set by the ratio of tokens in the pool. A flashloan lets someone borrow a huge amount of money for a single transaction without collateral, as long as they return it in the same transaction. Here, the attacker uses a flashloan to temporarily skew the pool's balance, tricking the protocol into thinking it needs to swap a large amount, which drains reward tokens from the pool.

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