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.
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.
Attack:
- Wait for TWAP to rise above the stabilization threshold
- Flashloan remove all but a tiny amount of Malt from the pool.
- Call
stabilize. This will pass the TWAP check and execute_distributeSupplywhich in turn ultimately calls_calculateTradeSizein theUniswapHandler. This calculation will determine that almost all of therewardTokenneeds to be removed from the pool to return the price to peg. - Malt will mint enough Malt to remove a lot of the
rewardTokenfrom the pool. - The protocol will now distribute that received
rewardTokenas 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.
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
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
- Wait for the TWAP to rise above the stabilization threshold.
- Flashloan to remove all but a tiny amount of Malt from the pool.
- Call stabilize, which passes the TWAP check and executes _distributeSupply, leading to _calculateTradeSize.
- The trade size calculation determines that almost all rewardToken needs to be removed from the pool.
- Malt mints enough Malt to remove a lot of rewardToken from the pool.
- 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.