Closed sherlock-admin closed 8 months ago
Invalid, accumulated fees are scaled down by 18 decimals as seen here, so the minimum fee imposed is only 1000 wei (1e18 is a scaling factor), so this would cause an extremely small loss involved
Sponsor comments:
The minimal fees were conceived as a roundup to a minimum value and do not carry any significance for the protocol. There is no point in wasting gas to take them for yourself, so I consider all issues related to them invalid.
0xDetermination
medium
Minimum loan fee isn't enforced properly for multiple-loan positions
Summary
A check in
borrow()
is used in conjunction with the_calcFeeCompensationUpToMin()
inrepay()
to enforce a minimum fee amount per loan. This min fee enforcement is important for HFT activity, but the minimum loan fee is not fully applied for positions with multiple loans.Vulnerability Detail
The protocol sponsors have stated that
Constants.MINIMUM_AMOUNT
is to be used as a minimum fee per loan (on top of the entrance fee). This fee is not enforced correctly for borrower positions with multiple loans. This is due to 2 factors, the first is in_precalculateBorrowing()
which is called inborrow()
:We can see above that if a borrower takes out a loan for the position such that the calculated 1-day collateral is less than
Constants.MINIMUM_AMOUNT
,cache.dailyRateCollateral
will be set to the min amount (this will later be added to the buyer's collateral to transfer to the protocol).This works fine for 1 loan, but for 2 loans or more the minimum fee per loan won't be enforced for all the loans, only one of them.
Notice how the minimum fee is enforced in
repay()
(in conjunction withborrow()
):As we can see the min collateral enforcement in
borrow()
works in tandem with the min fee enforcement inrepay()
to take the min fee from the collateral balance if necessary and enforce the min fee per loan. But similarly here inrepay()
as inborrow()
, this fee is only enforced for one loan; if a position has multiple loans then the minimum fee per loan won't be enforced.Impact
Borrowers can avoid paying some minimum loan fees.
Code Snippet
https://github.com/sherlock-audit/2024-02-leverage-contracts/blob/main/wagmi-leverage/contracts/LiquidityBorrowingManager.sol#L925-L945 https://github.com/sherlock-audit/2024-02-leverage-contracts/blob/main/wagmi-leverage/contracts/LiquidityBorrowingManager.sol#L617-L623 https://github.com/sherlock-audit/2024-02-leverage-contracts/blob/main/wagmi-leverage/contracts/LiquidityBorrowingManager.sol#L758-L771
Tool used
Manual Review
Recommendation
First, the below check should multiply the min amount by
params.loans.length
:Second, the minimum calcuation below from
_calcFeeCompensationUpToMin()
should also be multiplied by the number of loans.