Volatile pools with higher fee structure cannot be created because of tick_spacing
The tick_spacing parameter in the pool initialisation function is a u8, so pools requiring a tick spacing greater than 256 (such as those with fees above 1.3%) cannot be created. This prevents the protocol from supporting volatile asset pairs that need higher fee tiers.
Submitted by wasm_it
https://github.com/code-423n4/2024-08-superposition/blob/main/pkg/seawater/src/pool.rs#L53
https://github.com/code-423n4/2024-08-superposition/blob/main/pkg/seawater/src/pool.rs#L67
Impact
Provision of liquidity for pools with high volatility will not be possible as such pools cannot be initiated with a tick spacing basis point greater than 256 because of the tick_spacing datatype constrained to a u8.
Proof of Concept
Less volatile pools usually have fee tiers in the range of 0.05% to 1%. But higher volatile pools go over 1% as a baseline and some pools can have a 3-5% fee tier depending on the volatility of the pool pairs. Since the protocol intends to be able to create pools for any tokens with sufficient liquidity, pools with exotic pairs in the fee range of > 1.3% cannot be instantiated.
pub fn init(
&mut self,
price: U256,
fee: u32,
@> tick_spacing: u8, // e.g 300 for a pool with 1.5% fee tier
max_liquidity_per_tick: u128,
) -> Result<(), Revert> {
assert_eq_or!(
self.sqrt_price.get(),
U256::ZERO,
Error::PoolAlreadyInitialised
);
self.sqrt_price.set(price);
self.cur_tick
.set(I32::lib(&tick_math::get_tick_at_sqrt_ratio(price)?));
self.fee.set(U32::lib(&fee));
@> self.tick_spacing.set(U8::lib(&tick_spacing)); // @audit would revert at this point because the value exceeds the size of the datatype
self.max_liquidity_per_tick
.set(U128::lib(&max_liquidity_per_tick));
Ok(())
}
Recommended Mitigation Steps
Uniswap uses a bigger datatype for this such as a 24-bit integer type. A bigger datatype would be sufficient for this such as u16.
Assessed type
Context
af-afk (Superposition) confirmed and commented:
See commit.
We wound up enforcing a limit on the fee after some discussion that we don’t intend to set fees that high.
The submission has correctly identified that the data type used for the tick spacing of AMM pools is insufficient for volatile pools, causing them to become unusable due to their prices moving across ticks too swiftly.
I believe a medium-risk severity rating is appropriate given that the current AMM model is curated for volatile rather than stable pairs, rendering this scenario to have a non-negligible likelihood of manifesting in practice.
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
The tick_spacing parameter is declared as u8, which cannot hold values above 255, but some valid fee tiers require larger tick spacings.
What the attacker needed
Attempt to create a pool with fee >1.3%
The fix
The team addressed this by enforcing a limit on the fee rather than increasing the data type, as they do not intend to set fees that high.
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.
In automated market makers (AMMs), the 'tick spacing' controls how finely prices can be divided. The code stores this number in a tiny container that can only hold values up to 255. So if someone tries to set a larger spacing for a high-fee pool, the transaction fails and the pool can't be created.
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.