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.
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:
- Block i, twap is below the value returned from
maltDataLab.getSwingTraderEntryPrice(), attacker callstabilize()and receivedefaultIncentive.primedBlock = block.number. - Block i+1, call to
_validateSwingTraderTrigger()returntrueand trigger swing trader to bring the price back to peg. It’s also resetprimedBlock = 0(stop blocking transfer to AMM pool) - 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) - Now attacker can use flash loan to manipulate the
livePriceto be larger thanentryPrice(tranfer to AMM is not blocked) and callstabilize()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).
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.
I’m kinda skeptical of this but I think its possible in theory.
However:
stabilizecan only be called via EOA due tomsg.sender == tx.origincheck (inonlyEOAmodifier)- 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.
Regarding the previous comment:
- The
onlyEOAcheck 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.
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.
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
- 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.
- 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.
- Assume twap is still below the entry price because it moves slowly.
- 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.