Skip to content
Business logic Audit finding Advanced

Manipulation of livePrice to receive defaultIncentive in 2 consecutive blocks

The swing trader trigger validation relies on a manipulable live price, allowing an attacker to claim the default incentive in two consecutive blocks. The attacker could use a flash loan or sandwich attack to manipulate the price and receive the incentive again.

minhquanym Follow

Originally disclosed on Code4rena

Submitted by minhquanym

In StabilizerNode, the default behaviour when twap is below the lower peg threshold, all transfers to the amm pool are blocked. However when usePrimedWindow = true, it will only block transfers for primedWindow = 10 blocks. After 10 blocks, the block automatically stops and allows free market trading.

The first call to start this priming will receive defaultIncentive Malt and set primedBlock to start the priming. However, function _validateSwingTraderTrigger() which is used to validate and start the priming using livePrice is easy to be manipulated. Attacker can manipulate it to receive defaultIncentive in 2 consecutive blocks.

Proof of Concept

Consider the scenario:

  1. Block i, twap is below the value returned from maltDataLab.getSwingTraderEntryPrice(), attacker call stabilize() and receive defaultIncentive. primedBlock = block.number.
  2. Block i+1, call to _validateSwingTraderTrigger() return true and trigger swing trader to bring the price back to peg. It’s also reset primedBlock = 0 (stop blocking transfer to AMM pool)
  3. Since only 1 block pass, let’s assume twap is still below the value returned from maltDataLab.getSwingTraderEntryPrice() (because twap moves slowly and will not change immediately to current price)
  4. Now attacker can use flash loan to manipulate the livePrice to be larger than entryPrice (tranfer to AMM is not blocked) and call stabilize() to receive incentive again then repay the flash loan.

Attacker cost is only flash loan fee, since his call will start an auction but not trigger swing trader so the state of AMM pool when he repays the flash loan is still the same (only added flash loan fee).

https://github.com/code-423n4/2023-02-malt/blob/700f9b468f9cf8c9c5cffaa1eba1b8dea40503f9/contracts/StabilityPod/StabilizerNode.sol#L312-L334

function _validateSwingTraderTrigger(uint256 livePrice, uint256 entryPrice)
    internal
    returns (bool)
  {
    if (usePrimedWindow) {
      if (livePrice > entryPrice) {
        return false;
      }

      if (block.number > primedBlock + primedWindow) {
        primedBlock = block.number;
        malt.mint(msg.sender, defaultIncentive * (10**malt.decimals()));
        emit MintMalt(defaultIncentive * (10**malt.decimals()));
        return false;
      }

      if (primedBlock == block.number) {
        return false;
      }
    }

    return true;
  }

Recommended Mitigation Steps

Consider not giving incentives for caller or reset the primedBlock at least after primedWindow blocks.

0xScotch (Malt) commented:

I’m kinda skeptical of this but I think its possible in theory.

However:

  • stabilize can only be called via EOA due to msg.sender == tx.origin check (in onlyEOA modifier)
  • Size of flashloan required is proportional to the size of the pool (as you have to manipulate price of that pool) while the incentive is fixed. So it seems like this would quickly become unprofitable

I would be very curious to see a real PoC of this rather than just a theoretical threat.

Picodes (judge) commented:

Regarding the previous comment:

  • The onlyEOA check can be bypassed using a sandwich attack instead of a flashloan so the possibility of a MEV attack still exists
  • We should consider that the cost of capital within a block is 0. For example, Euler already proposes feeless flashloans of up to their TVL. See https://twitter.com/euler_mab/status/1595725665868910595. However there would still be the cost of using the AMM to manipulate the price.

Picodes (judge) commented:

Although the possibility of this being implemented depends on the size of the incentives and the cost of manipulating the AMM, it does not seem so unlikely. It could lead to a significant loss for the protocol, so I agree that high severity is appropriate.

0xScotch (Malt) acknowledged


The original report as published on Code4rena, by minhquanym. 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 validation of the swing trader trigger uses a spot price (livePrice) that can be manipulated within a single block, rather than a time-weighted average price.

Impact

The attacker could receive the default incentive twice in consecutive blocks, leading to a significant loss for the protocol, though the profitability depends on the incentive size and the cost of manipulating the AMM; the onlyEOA check can be bypassed with a sandwich attack, and flash loans may have zero capital cost.

What the attacker needed

Twap below swing trader entry price; ability to manipulate livePrice (flash loan or sandwich); onlyEOA bypass via sandwich attack

The fix

The protocol should not give incentives to the caller or should reset primedBlock only after primedWindow blocks.

How it was found

  1. In block i, when twap is below the swing trader entry price, call stabilize() to receive the default incentive and set primedBlock to the current block.
  2. In block i+1, the validation returns true and triggers the swing trader, resetting primedBlock to 0 and stopping the block on transfers to the AMM pool.
  3. Assume twap is still below the entry price because it moves slowly.
  4. Use a flash loan to manipulate livePrice above entryPrice, then call stabilize() to receive the incentive again and repay the flash loan.

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 smart contract gives a reward to anyone who helps stabilise a token's price when it is too low. The check for whether the price is still too low uses a price that can be temporarily pushed around by a large trade. An attacker can therefore trick the contract into paying the reward twice in a row.

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 minhquanym

View all

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