Premium owed can be calculated as a very big number due to reentrancy on uninitialized pools
An attacker can reenter the pool initialisation function during a mint callback to burn a position before the mint completes, causing an underflow in removedLiquidity and making the premium owed appear extremely large. This only affects the optional premium accumulator and does not break core SFPM functionality.
tapir Follow with hash and SpicyMeatball
Originally disclosed on Code4rena
Submitted by tapir, also found by hash and SpicyMeatball
When minting or burning a position, an attacker can take advantage of reentrancy to make the pool has more removedLiquidity than it has. This would make the owed premium to be mistakenly very high value. The issue root cause is reentrancy on an uninitialized pool in SFPM. SFPM initialize pool function explicitly makes the locked flag to false which can be leveraged for the attacker to reenter and burn the position before the mint goes through fully. This will lead to an underflow in the removedLiquidity part of the chunk. Thus, the premium owed will be calculated as a very big number since the removed liquidity is used to track the premiums owed.
Proof of Concept
It’s best to explain this issue using an example due to its complexity:
First, the attacker is a contract that has a custom onERC1155Received implemented. In this case, the attacker checks for uninitialized pools in SFPM. Let’s say the USDC-ETH 0.05% pool is not yet initialized. The attacker initiates a call to mintTokenizedPosition with a “short” type. Normally, this action would remove specific liquidity from Uniswapv3 deposited through SFPM. Attempting this without a deposit in that range would normally throw an error in this part of the code. Also, note that although the underlying uniswap pool is not registered, mintTokenizedPosition does not revert since the attacker will initialize the pool in the ERC1155 callback!
The attacker proceeds with the mint function despite expecting it to revert. The tokenId’s Uniswap pool part (first 64 bits) remains uninitialized. The attacker takes advantage of this and, once the _mint is called internally in ERC1155, the attacker can execute their custom onERC1155Received in their contract.
As we can see here, before any execution on state and storage the _mint is called so attacker will has its onERC1155Received callback function called by SFPM:
Now, attacker will have the following onERC1155Received function:
function onERC1155Received(*/ address caller, address to */ , uint tokenId, uint amount, bytes calldata data) return bytes4 {
SFPM.initializeAMMPool(USDC, WETH, FEE_TIER);
SFPM.burnTokenizedPosition(tokenId, tokenId.positionSize(), slippageTickLimitLow, slippageTickLimitHigh);
return ERC1155Holder.onERC1155Received.selector;
}
The first step here is initializing the pool. This action unlocks the pool’s reentrancy lock, allowing re-entry into the functions for that pool link.
The second call burns the token. As this was a long position and has the burn flag, it flips the long to short link.
When reaching this part of the code, isLong equals 0, initiating an unchecked scope, resulting in an underflow of removedLiquidity, leading to an immensely large number!
Continuing with the function, these lines execute, minting liquidity using 1 ETH from the attacker, inadvertently increasing the actual liquidity without a prior deposit.
The removedLiquidity and netLiquidity are then written to storage.
Despite the attacker’s tokenId being burnt and nonexistent due to the onERC1155Received function execution, the process continues. Which means we can now continue with the initial mintTokenizedPosition function
Since the previous call updated removedLiquidity to an enormous number via underflow, and increasing netLiquidity with chunk liquidity, leads to no reversion in these lines.
Afterward, the position is successfully burned from Uniswap. Continuing with the function, at this point, the rightSlot holds the net liquidity from previous storage balance. Hence, we will execute the _collectAndWritePositionData function.
However, we have a problem arising in the _updateStoredPremia function which is called inside the _collectAndWritePositionData here. The removed liquidity is used to calculate the premium owed. Due to the underflow from previous storage balance in removedLiquidity (leftSlot), the resulting premiumOwed becomes immensely high. This impacts the premium owed to be an immensely big number, returning a false statement. Furthermore, users intending to use the USDC-ETH 0.05% pool may encounter difficulties due to messed-up premiums in one range position, potentially affecting other positions relying on these premiums within the external contract.
Recommended Mitigation Steps
Validate the uniswap pool ID before the _mint OR do not explicitly set the locked value to false when initializing the pool
Assessed type
Under/Overflow
dyedm1 (Panoptic) confirmed, but disagreed with severity and commented:
This is a good one, but might be Med since
removedLiquidityis only used for the optional premium accumulators that get exposed and has no effect on the internal SFPM functionality. Panoptic obviously wouldn’t execute this reentrancy on its own mints (and besides the factory initializes the pool before deploying aPanopticPool). Essentially, it only allows you to screw up your ownremovedLiquidity, which outside of a protocol is not very relevant.
Picodes (judge) decreased severity to Medium and commented:
Medium severity seems more appropriate here under “hypothetical attack path with stated assumptions, but external requirement”. Storage can be manipulated and this state manipulation could lead to loss of funds in a protocol using the SPFM.
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 pool initialisation function explicitly sets the reentrancy lock to false, allowing a callback during minting to reenter and burn the position before the mint completes, causing an underflow in removedLiquidity.
Impact
The premium owed can be calculated as an extremely large number, but this only affects the optional premium accumulator and does not impact core SFPM functionality; the protocol itself would not execute this reentrancy, and the factory initialises the pool before deploying a PanopticPool.
What the attacker needed
Attacker contract with onERC1155Received; uninitialized pool; attacker provides 1 ETH liquidity
The fix
Validate the Uniswap pool ID before the _mint call, or do not explicitly set the locked flag to false when initializing the pool.
How it was found
- Deploy an attacker contract that implements onERC1155Received and checks for uninitialized pools.
- Call mintTokenizedPosition with a short type on an uninitialized pool.
- In the onERC1155Received callback, initialize the pool and then call burnTokenizedPosition on the same tokenId.
- The burn flips the position and triggers an underflow in removedLiquidity, setting it to a huge number.
- The original mint continues and writes the inflated removedLiquidity to storage.
- The premium calculation uses the inflated removedLiquidity, producing an extremely large premium owed.
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 reentrancy attack happens when a contract calls back into another contract before it has finished its own work, letting the attacker run code in the middle of an operation. Here, the attacker uses that gap to burn a position early, which makes an internal counter go below zero and wrap around to a huge number. That huge number is then used to calculate a premium, so the premium looks enormous.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.