openPosition() Lack of minimum token0PremiumPortion/token1PremiumPortion limit
The openPosition function allowed both premium portions to be zero, so when a position was out of price, an attacker could borrow liquidity without paying any fees. This could lead to malicious occupation of liquidity and prevent liquidators from acting because there was no profit.
Submitted by bin2chen, also found by immeas
In openPosition(), it allows token0PremiumPortion and token1PremiumPortion to be 0 at the same time.
In this case, if tokenId enters out_of_price, for example, UpperOutOfRange, anyone might be able to input:
marginFrom = 0
marginTo = 0
amountSwap = 0
zeroForOne = false
liquidity > 0
Note: amountFromBorrowed + marginFrom == 0, so fees ==0
To open a new Position, borrow Liquidity, but without paying any fees. It’s basically a no-cost loan.
Impact
out_of_price tokenId, due to the no-cost loan, might lead to the following issues:
- Malicious occupation of Liquidity
- Since both
token0Premium/token1Premiumare 0, the liquidator will not executeliquidatePosition(), because there is no profit. - Since both
token0Premium/token1Premiumare 0,LPcannot get fees, but the borrower might still be able to profit.
Proof of Concept
The following test case demonstrates that if it is out_of_price, anyone can borrow at no cost.
Add to OpenPosition.t.sol:
function testZeroFees() public {
_setupUpperOutOfRange();
uint128 borrowerLiquidity = _liquidity / _borrowerLiquidityPorition;
console.log("borrowerLiquidity:",borrowerLiquidity);
address anyone = address(0x123999);
vm.startPrank(anyone);
particlePositionManager.openPosition(
DataStruct.OpenPositionParams({
tokenId: _tokenId,
marginFrom: 0,
marginTo: 0,
amountSwap: 0,
liquidity: borrowerLiquidity,
tokenFromPremiumPortionMin: 0,
tokenToPremiumPortionMin: 0,
marginPremiumRatio: type(uint8).max,
zeroForOne: false,
data: ""
})
);
vm.stopPrank();
(
,
uint128 liquidity,
,
uint128 token0Premium,
uint128 token1Premium,
,
,
) = particleInfoReader.getLien(anyone, 0);
console.log("liquidity:",liquidity);
console.log("token0Premium:",token0Premium);
console.log("token1Premium:",token1Premium);
}
Logs:
borrowerLiquidity: 1739134199054731
liquidity: 1739134199054731
token0Premium: 0
token1Premium: 0
Recommended Mitigation
It is suggested that openPosition() should add a minimum token0PremiumPortion/token1PremiumPortion limit.
function openPosition(
DataStruct.OpenPositionParams calldata params
) public override nonReentrant returns (uint96 lienId, uint256 collateralTo) {
...
+ require(params.tokenFromPremiumPortionMin>=MIN_FROM_PREMIUM_PORTION,"invalid tokenFromPremiumPortionMin");
+ require(params.tokenToPremiumPortionMin>=MIN_TO_PREMIUM_PORTION,"invalid tokenToPremiumPortionMin");
wukong-particle (Particle) confirmed and commented:
It’s a good suggestion. We will add minimum premium in contract (current frontend enforces a minimum 1-2%).
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 openPosition function did not enforce a minimum value for the premium portions, allowing them to be zero.
Impact
An attacker could borrow liquidity at no cost, potentially occupying liquidity maliciously and preventing liquidators from acting because there is no profit.
What the attacker needed
Position is out of price; attacker can call openPosition
The fix
The contract should enforce a minimum premium portion in openPosition; the team said they will add a minimum premium in the contract.
How it was found
- Set up a position that is out of price (upper out of range).
- Call openPosition with zero margins, zero swap amount, and zero premium portion minimums.
- Observe that the position is opened with zero premiums, meaning no fees were paid.
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 smart contract let someone borrow tokens without paying a fee if they set two fee settings to zero. This meant they could take up liquidity for free and others could not earn from it.
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.