Adjusting ” I ” will create a sandwich opportunity because of price changes
The contract allows the owner to change a parameter that directly affects the price, and a MEV bot can sandwich the transaction to profit at the expense of liquidity providers. The report notes that even without front-running, the sudden price change creates arbitrage opportunities.
grearlake Follow with roguereggiant, Breeje and 2 others
Originally disclosed on Code4rena
Submitted by grearlake, also found by roguereggiant, Breeje, hals, and blutorque
https://github.com/code-423n4/2024-03-abracadabra-money/blob/main/src/mimswap/MagicLP.sol#L470-#L510
https://github.com/code-423n4/2024-03-abracadabra-money/blob/main/src/mimswap/MagicLP.sol#L244-#L265
Because MagicLP is forked from DODO, we will check DODO documentation to understand this contract. From DODO documentation, the ”I” is the “i” value in here and it is directly related with the output amount a trader will receive when selling a quote/base token:
Adjusting the value of ”I” directly by calling setParameters() function will influence the price. This can be exploited by a MEV bot, simply by trading just before the setParameters() function and exiting right after the price change. The profit gained from this operation essentially represents potential losses for the liquidity providers who supplied liquidity to the pool.
Impact
Since the price will change, the MEV bot can simply sandwich the tx and get profit.
Another note on this is that even though the adjustPrice called by onlyImplementationOwner without getting frontrunned, it still creates a big price difference which requires immediate arbitrages. Usually these type of parameter changes that impacts the trades are setted by time via ramping to mitigate the unfair advantages that it can occur during the price update.
Recommended Mitigation Steps
Acknowledge the issue and use private RPC’s to eliminate front-running or slowly ramp up the ”I” so that the arbitrage opportunity is fair
0xCalibur (Abracadabra) acknowledged and commented:
Fixed in main: https://github.com/Abracadabra-money/abracadabra-money-contracts/
We now have protocol own pool and can disable trading for our own pools, changing the parameters and make sure the pool is in good state before enabling it back.
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 parameter that sets the price can be changed instantly without a time delay or ramp, allowing traders to anticipate and profit from the price shift.
Impact
A MEV bot could sandwich the parameter-change transaction and profit, causing losses for liquidity providers; even without front-running, the sudden price change creates arbitrage opportunities.
What the attacker needed
Owner calls setParameters; MEV bot can front-run
The fix
The issue was fixed by using a protocol-owned pool where trading can be disabled, parameters changed, and the pool checked before re-enabling trading.
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 liquidity pool uses a number to set prices. The owner can change that number instantly. A fast trader can buy just before the change and sell just after, making a profit that comes from the pool's liquidity providers.
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.