Usage of `slot0` is extremely easy to manipulate
BugBusters Follow with Jaraxxus, ash and 9 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-06-real-wagmi-judging/issues/97
Found by
BugBusters, Jaraxxus, ash, bitsurfer, kutugu, ni8mare, rogue-lion-0619, sashik_eth, shealtielanz, stopthecap, toshii, tsvetanovv
Summary
Usage of slot0 is extremely easy to manipulate
Vulnerability Detail
Real Wagmi is using slot0 to calculate several variables in their codebase:
slot0 is the most recent data point and is therefore extremely easy to manipulate.
Multipool directly uses the token values returned by getAmountsForLiquidity
(uint256 amount0, uint256 amount1) = LiquidityAmounts.getAmountsForLiquidity(
slots[i].currentSqrtRatioX96,
TickMath.getSqrtRatioAtTick(position.lowerTick),
TickMath.getSqrtRatioAtTick(position.upperTick),
liquidity
);
to calculate the reserves.
reserve0 += amount0;
reserve1 += amount1;
Which they are used to calculate the lpAmount to mint from the pool. This allows a malicious user to manipulate the amount of the minted by a user.
https://github.com/sherlock-audit/2023-06-real-wagmi/blob/main/concentrator/contracts/Multipool.sol#L483
Impact
Pool lp value can be manipulated and cause other users to receive less lp tokens.
Code Snippet
https://github.com/sherlock-audit/2023-06-real-wagmi/blob/main/concentrator/contracts/Multipool.sol#L589-L596 https://github.com/sherlock-audit/2023-06-real-wagmi/blob/main/concentrator/contracts/Multipool.sol#L754-L755 https://github.com/sherlock-audit/2023-06-real-wagmi/blob/main/concentrator/contracts/Multipool.sol#L749 https://github.com/sherlock-audit/2023-06-real-wagmi/blob/main/concentrator/contracts/Multipool.sol#L289
Tool used
Manual Review
Recommendation
To make any calculation use a TWAP instead of slot0.
Discussion
SergeKireev
Escalate
Usage of slot0 is correct in this context. Using anything else as a price source would misrepresent current token liquidity in UniV3 pools and break the calculations used during minting (and could actually result in the user receiving more or less shares than due).
The possibility of price manipulation is correctly mitigated by slippage parameters in the deposit function
sherlock-admin
Escalate
Usage of slot0 is correct in this context. Using anything else as a price source would misrepresent current token liquidity in UniV3 pools and break the calculations used during minting (and could actually result in the user receiving more or less shares than due).
The possibility of price manipulation is correctly mitigated by slippage parameters in the deposit function
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
fann95
FIXED. The _checkPriceDeviation function checks deviations from the weighted average price for each pool https://github.com/RealWagmi/concentrator/blob/fbccf1caf28edbb23db8c7e0409d0c40c3a56461/contracts/Multipool.sol#L984C14-L984C34
hrishibhat
@ctf-sec
hrishibhat
Result:
High
Has duplicates
Although in general, the slot0 manipulation issue may need further discussion on its validity,severity and practicality of the issue, currently keeping this issue as a valid high based on historical decisions.
This will be further discussed and with additional information, the rulebook will be updated accordingly
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- crimson-rat-reach: rejected
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A high-severity security bug in Real Wagmi #2. Sherlock made it public on 13 July 2023. Found in the 88 audit contest (finding H-3), also found by 11 other wardens.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.