Add premium doesn’t collect fees
The protocol charges a fee on the margin provided when opening a position, but not when adding margin later via addPremium. A borrower can avoid part of the fee by opening a position with minimal margin and then adding the rest via addPremium.
Submitted by adriro, also found by bin2chen
Fees are applied to premiums when a new position is opened, but the same mechanism is not enforced when margin is added to an existing position.
Impact
When a new position is created in the LAMM protocol, fees are collected in favor of the LP owner that provides the liquidity for the position. The fee is calculated by applying a configurable rate over the tokens “from” amounts:
191: // pay for fee
192: if (FEE_FACTOR > 0) {
193: cache.feeAmount = ((params.marginFrom + cache.amountFromBorrowed) * FEE_FACTOR) / Base.BASIS_POINT;
194: cache.treasuryAmount = (cache.feeAmount * _treasuryRate) / Base.BASIS_POINT;
195: _treasury[cache.tokenFrom] += cache.treasuryAmount;
196: if (params.zeroForOne) {
197: lps.addTokensOwed(params.tokenId, uint128(cache.feeAmount - cache.treasuryAmount), 0);
198: } else {
199: lps.addTokensOwed(params.tokenId, 0, uint128(cache.feeAmount - cache.treasuryAmount));
200: }
201: }
The fee is applied to amountFromBorrowed, the “from” amount from the LP liquidity, and marginFrom, the user provided margin to cover the required amount for the swap and provide a premium in the position.
However, the same logic is not followed when the borrower adds more margin using addPremium(). In this case, the amounts are added in full to the position’s premiums without incurring any fees.
This not only represents an inconsistent behavior (which may be a design decision), but allows the borrower to avoid paying part of the fees. The borrower can provide enough marginTo so that the swap can reach the required collateralTo amount, leaving the token “from” premium at zero. Then, in a second call, provide the needed premium to cover for eventual LP fees using addPremium(). This can be done with null liquidation risk and is greatly simplified by leveraging the multicall functionality. The borrower can bundle both operations in a single transaction, without even deploying a contract.
Proof of Concept
A user can skip paying part of the fees by bundling two operations in a single transaction:
- A call to
openPosition()with the minimal required amount ofmarginFromso thatamountReceived + amountToBorrowed + marginTo >= collateralTo. - A call to
addPremium()to provide the required premiums to cover for eventual fees.
Recommendation
Apply the same fee schedule to addPremium(). Depending on the value of zeroForOne, determine the “from” token, apply the FEE_FACTOR to it, and accrue the fee to the corresponding liquidity position.
wukong-particle (Particle) acknowledged and commented:
I think this fee free premium is by design. We were only targeting the minimum required margin + the borrowed amount to calculate for fees. More friendly for traders.
We were only targeting the minimum required margin + the borrowed amount to calculate for fees.
Correct, this is exactly what the issue is about (the title might be a bit misleading). The borrower can skip paying the “minimum required margin” part of the fees.
wukong-particle (Particle) commented:
Hmm sorry “minimum required margin” is the amount to meet
collateralFrom/To. This margin cannot be skipped because otherwise opening a position won’t have enough to covercollateralFrom/To.
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 fee calculation is only applied in openPosition and not in addPremium, so later margin additions bypass the fee.
Impact
The borrower can avoid paying part of the fees, with no liquidation risk, and can bundle both calls in one transaction using multicall.
What the attacker needed
A position with margin; ability to call openPosition and addPremium; multicall functionality (optional)
The fix
Apply the same fee schedule to addPremium, determining the 'from' token based on zeroForOne and accruing the fee to the liquidity position.
How it was found
- Call openPosition with the minimal required marginFrom so that the swap reaches the required collateralTo.
- Call addPremium to provide the remaining premium needed to cover eventual LP fees.
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.
When you open a leveraged position, the protocol takes a small fee based on the amount you put in. But if you add more money to an existing position later, no fee is taken. This means you can pay less in fees by opening with a small amount and adding the rest afterwards.
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.