minOfferCost can be bypassed in certain scenarios
The minimum interest guarantee for lenders could be bypassed because interest is paid proportionally once total interest exceeds the minimum, allowing a lender with a small provision to receive less than the guaranteed minimum. An attacker could exploit this by creating a loan with multiple provisions of unequal sizes, causing some lenders to receive less interest than intended.
Source: https://github.com/sherlock-audit/2023-02-kairos-judging/issues/23
Found by
0x52
Summary
minOfferCost is designed to prevent spam loan requests that can cause the lender to have positions that cost more gas to claim than interest. Due to how interest is calculated right after this minimum is passed it is still possible for the lender to receive less than the minimum.
Vulnerability Detail
function sendInterests(Loan storage loan, Provision storage provision) internal returns (uint256 sent) {
uint256 interests = loan.payment.paid - loan.lent;
if (interests == loan.payment.minInterestsToRepay) {
// this is the case if the loan is repaid shortly after issuance
// each lender gets its minimal interest, as an anti ddos measure to spam offer
sent = provision.amount + (interests / loan.nbOfPositions);
} else {
/* provision.amount / lent = share of the interests belonging to the lender. The parenthesis make the
calculus in the order that maximizes precison */
sent = provision.amount + (interests * (provision.amount)) / loan.lent; <- audit-issue minimal interest isn't guaranteed
}
loan.assetLent.checkedTransfer(msg.sender, sent);
}
When a loan has generated more than the minimum interest amount the method for calculating the interest paid is different and depending on the size of the provisions it may lead to provisions that are under the guaranteed minimum.
Example: Assume the minimum interest is 1e18. A loan is filled with 2 provisions. The first provision is 25% and the second is 75%. Since there are two loans the total minimum interest for the loan is 2e18. After some time the paid interest reaches 2.001e18 and the loan is paid back. Since it is above the minimum interest rate, it is paid out proportionally. This gives 0.5e18 to the first provision and 1.5e18 to the second provision. This violates the minimum guaranteed interest amount.
Impact
Minimum interest guarantee can be violated
Code Snippet
Tool used
Manual Review
Recommendation
Minimum interest should be set based on the percentage of the lowest provision and provision shouldn't be allowed to be lower than some amount. Since this problem occurs when the percentage is less than 1/n (where n is the number of provisions), any single provision should be allowed to be lower than 1/(2n).
Discussion
npasquie
fixed by https://github.com/kairos-loan/kairos-contracts/pull/51 the fix restricts the nb of offer/provision per loan to 1 eliminating the vulnerability
IAm0x52
Fix looks good. All code relevant to multiple offers has been removed. Borrowing, lending, liquidating and distributing to provisions work correctly with only one offer
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
Impact
The minimum interest guarantee can be violated, meaning lenders may receive less interest than the protocol promises, potentially making certain loans unprofitable after gas costs.
What the attacker needed
A loan with multiple provisions; provisions of unequal sizes; interest paid above the minimum
The fix
The vulnerability was fixed by restricting the number of offers/provisions per loan to one, eliminating the proportional split issue.
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.
In a lending system, a minimum interest amount is set to protect lenders from spam loans that cost more gas to claim than the interest earned. However, when a loan is repaid with interest above that minimum, the interest is split proportionally among lenders based on their contribution. If one lender contributed a very small amount, their share of the interest can be less than the minimum, defeating the protection.
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.