Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMM pool can be drained using a flashloan and calling stabilize #372

Open
code423n4 opened this issue Dec 1, 2021 · 1 comment
Open
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Handle

stonesandtrees

Vulnerability details

Impact

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.

Tools Used

Manual review

Recommended Mitigation Steps

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

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Dec 1, 2021
code423n4 added a commit that referenced this issue Dec 1, 2021
@0xScotch 0xScotch added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Dec 8, 2021
@GalloDaSballo
Copy link
Collaborator

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

@GalloDaSballo GalloDaSballo added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

3 participants