slot0 Reliance in swap Allows Price Manipulation #39
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
duplicate-27
🤖_03_group
AI based duplicate group recommendation
sufficient quality report
This report is of sufficient quality
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/ronin-chain/katana-v3-contracts/blob/03c80179e04f40d96f06c451ea494bb18f2a58fc/src/core/KatanaV3Pool.sol#L552
Vulnerability details
Summary
The KatanaV3Pool contract has a vulnerability that allows attackers to manipulate the price of tokens during swaps. This is because the contract uses the instantaneous price from slot0, which can be manipulated through MEV bots or flash loan attacks.
The bug lies in how it fetches and uses price data during a swap.
The contract stores critical pool state in a
Slot0
struct:The
swap()
function uses thesqrtPriceX96
fromslot0
to calculate swap amounts and execute trades:The problem is that
slot0.sqrtPriceX96
reflects the current instantaneous price. This value can be manipulated by attackers using techniques like:KatanaV3Pool
at the manipulated price, profiting from the artificial price difference.Scenario
Imagine the fair price of token A is 10 tokens of B. An attacker might use a flash loan to briefly drive the price of token A up to 15 tokens of B on the underlying DEX. Because
KatanaV3Pool
uses the instantaneousslot0
price, the attacker could then swap a large amount of token B for token A at this inflated price. Once the attacker repays the flash loan, the price of token A returns to normal, leaving the attacker with a significant profit and the pool with a loss.Impact
swap()
function. They may receive less of the desired token than expected due to the manipulated price.Recommended Solution
To fix this vulnerability, the
KatanaV3Pool
contract should be modified to use a TWAP for price retrieval instead of relying on the instantaneousslot0
price. This would involve:swap()
: Modify theswap()
function to use the calculated TWAP instead ofslot0.sqrtPriceX96
for price determination.Assessed type
Oracle
The text was updated successfully, but these errors were encountered: