Get virtual price is not monotonically increasing
The virtualPrice function is not monotonically increasing because the precision multiplier can be changed after pool setup, allowing the virtual price to be manipulated. This could mislead protocols that rely on virtualPrice and potentially harm liquidity providers.
Submitted by jonah1005
Impact
There’s a feature of virtualPrice that is monotonically increasing regardless of the market. This function is heavily used in multiple protocols. e.g.(curve metapool, mim, …) This is not held in the current implementation of customSwap since customPrecisionMultipliers can be changed by changing the target price.
There are two issues here: The meaning of virtualPrice would be vague. This may damage the lp providers as the protocol that adopts it may be hacked.
I consider this is a medium-risk issue.
Proof of Concept
We can set up a mockSwap with extra setPrecisionMultiplier to check the issue.
function setPrecisionMultiplier(uint256 multipliers) external {
swapStorage.tokenPrecisionMultipliers[0] = multipliers;
}
print(swap.functions.getVirtualPrice().call())
swap.functions.setPrecisionMultiplier(2).transact()
print(swap.functions.getVirtualPrice().call())
# output log:
# 1000000000000000000
# 1499889859738721606
Tools Used
None
Recommended Mitigation Steps
Dealing with the target price with multiplier precision seems clever as we can reuse most of the existing code. However, the precision multiplier should be an immutable parameter. Changing it after the pool is set up would create multiple issues. This function could be implemented in a safer way IMHO.
The quick fix would be to remove the getVirtualPrice function. I can’t come up with a safe way if other protocol wants to use this function.
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 precision multiplier used in virtual price calculation is not immutable and can be altered after pool deployment.
Impact
The virtual price can be manipulated, which may mislead protocols that rely on it and could harm liquidity providers if those protocols are exploited.
What the attacker needed
Ability to change precision multiplier
The fix
The precision multiplier should be immutable, or the getVirtualPrice function should be removed.
How it was found
- Deploy a mock swap contract with a function to set the precision multiplier.
- Call getVirtualPrice and record the value.
- Call setPrecisionMultiplier with a new value.
- Call getVirtualPrice again and observe the changed value.
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 virtual price is supposed to only go up, like a savings account balance that never decreases. Here, a setting that controls how token amounts are scaled can be changed after the pool is created, which makes the virtual price jump around. Other programs that trust this number could make bad decisions.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.