Submitted by said
Excess tokens from margins provided by traders when opening position could become stuck inside the ParticlePositionManager due to precision loss when calculating the token premium portion.
When traders call openPosition, eventually it will calculate cache.token0PremiumPortion and cache.token1PremiumPortion before putting it into lien data.
https://github.com/code-423n4/2023-12-particle/blob/main/contracts/protocol/ParticlePositionManager.sol#L218-L244
It can be observed that when calculating cache.token0PremiumPortion and cache.token1PremiumPortion, precision loss could occur, especially when the token used has a high decimals (e.g. 18) while BASIS_POINT used only 1_000_000. When this happens, the token could become stuck inside the ParticlePositionManager.
Coded PoC :
The PoC goal is to check the amount of tokens inside the ParticlePositionManager after the position is opened, premium is added, liquidated, the LP withdraws the tokens and collects fees, and the admin collects the treasury.
Add the following test inside test/OpenPosition.t.sol and also add import "forge-std/console.sol"; to the test contract.
Run the test :
Output log :
It can be observed that some tokens stuck inside the ParticlePositionManager contract.
Foundry
Use a higher scaling for BASIS_POINT, considering the fact that tokens commonly have a high number of decimals.
wukong-particle (Particle) acknowledged and commented:
adriro (Warden) commented:
0xleastwood (Judge) commented:
