Insufficient Price Protection in Liquidity Actions May Enable Manipulation #102
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-93
🤖_102_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/omnipool/src/lib.rs#L577-L607
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/stableswap/src/lib.rs#L1165-L1187
Vulnerability details
Description
There are a few ways an attacker could potentially manipulate prices in the Omnipool to profit from other liquidity providers (LPs), Sandwich attack on liquidity actions. An attacker could execute a sandwich attack around a large liquidity action by another LP.
For example:
The Omnipool pallet allows for the pooled trading of assets, with the on-chain prices used to value liquidity additions and withdrawals. However, the current design does not sufficiently protect these pricing queries from manipulation. An attacker could exploit this by pushing prices before a victim's transaction, draining value in the process.
Impact
In the
add_liquidity
andremove_liquidity
functions in the Omnipool pallet. When liquidity is added or removed, the code calculates the amount of pool shares to mint or burn based on the current on-chain price. However, there are no checks that this price matches external prices. This leaves the door open to manipulation.scenario
Alice decides to add a large amount of liquidity to the Omnipool, e.g. 1,000 DOT.
Eve notices this intent and quickly executes a swap of 1 DOT for 1 KSM right before Alice's transaction is included.
This swap changes the on-chain DOT/KSM price used to calculate Alice's minted shares. Eve got 1 KSM for cheap due to low liquidity.
Alice's transaction goes through. The manipulated price causes her to get less pool shares than she should have.
Eve immediately swaps the 1 KSM back for DOT, reversing the price change. She pockets the difference as profit.
Impact
This attack would cause Alice to lose out on pool share value. It also damages integrity of the system. Over time, this may cause users to lose trust in the Omnipool.
Proof of Concept
HydraDX-node/pallets/omnipool/src/lib.rs#fn add_liquidity
HydraDX-node/pallets/stableswap/src/lib.rs#fn calculate_shares
There is no check that
price
matches an external reference like an oracle. This allows manipulation.However, this
PriceBarrier
only does a basic check that the on-chain price is within expected bounds. It does not prevent manipulation itself.Similarly in https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/stableswap/src/lib.rs#L1165-L1187, there is no external price check when calculating shares to mint based on the reserves and amounts added. This could potentially be manipulated.
Step to Reproduce
Preconditions
Attack Steps
Attacker monitors chain activity and spots victim's intent to add/remove liquidity
Right before victim sends liquidity transaction, attacker quickly swaps a small amount of DOT for KSM
Victim's transaction executes, minting/burning shares based on manipulated price
Attacker immediately swaps KSM back for DOT, reversing the price change
Victim's wallet shows less DOT/KSM than intended due to sandwich attack
Tools Used
Manual Review
Recommended Mitigation Steps
Solution
The key improvement would be to incorporate a stronger price protection mechanism before large liquidity actions like:
Without stronger measures, the liquidity action pricing remains vulnerable to manipulation attacks via swaps right before, as described in the scenario.
Assessed type
Oracle
The text was updated successfully, but these errors were encountered: