makePayment() Lack of access control allows malicious lender to retrieve a large portion of the funds earlier, making the borrower suffer fund loss
The makePayment function lacked access control, allowing any caller to repay the loan using the contract's drawable funds. A malicious lender could call it repeatedly after funding to reclaim most of their principal early, leaving the borrower owing interest on unused funds or facing collateral loss.
Submitted by WatchPug
function makePayment(uint256 amount_) external override returns (uint256 principal_, uint256 interest_) {
// The amount specified is an optional amount to be transfer from the caller, as a convenience for EOAs.
require(amount_ == uint256(0) || ERC20Helper.transferFrom(_fundsAsset, msg.sender, address(this), amount_), "ML:MP:TRANSFER_FROM_FAILED");
( principal_, interest_ ) = _makePayment();
emit PaymentMade(principal_, interest_);
}
The current implementation allows anyone to call makePayment() and repay the loan with _drawableFunds.
This makes it possible for a malicious lender to call makePayment() multiple times right after fundLoan() and retrieve most of the funds back immediately, while then borrower must continue to make payments or lose the collateral.
PoC
Given:
_collateralRequired= 1 BTC_principalRequested= 12,000 USDC_paymentInterval= 30 day_paymentsRemaining= 12_gracePeriod= 1 dayinterestRate_= 2e17- The borrower calls
postCollateral()and added1 BTCas_collateralAsset; - The lender calls
fundLoan()and added12,000 USDCas_fundsAsset; - The lender calls
makePayment()11 times, then: _drawableFunds= 96_claimableFunds= 11903_principal= 1553- The lender calls
_claimFunds()get 11,903 USDC of_fundsAssetback;
Now, for the borrower 1,579 USDC is due, but only 96 USDC can be used. The borrower is now forced to pay the interests for the funds that never be used or lose the collateral.
Recommendation
Change to:
function makePayment(uint256 amount_) external override returns (uint256 principal_, uint256 interest_) {
// The amount specified is an optional amount to be transfer from the caller, as a convenience for EOAs.
require(amount_ == uint256(0) || ERC20Helper.transferFrom(_fundsAsset, msg.sender, address(this), amount_), "ML:MP:TRANSFER_FROM_FAILED");
require(msg.sender == _borrower, "ML:DF:NOT_BORROWER");
( principal_, interest_ ) = _makePayment();
emit PaymentMade(principal_, interest_);
}
deluca-mike (Maple) confirmed:
Good catch. However, we do want accounts other than the borrower to make payments (this is actually functionality that our current borrowers use), so instead of this fix, we may enforce that a payment can only be made some window of time before it is due, to prevent anyone from prematurely paying it down.
Great find, with a POC, deserves a severity of high as it may incur in funds lost for the borrower. The sponsor has acknowledged and mitigated the issue.
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 borrower could be forced to pay interest on funds they never used or lose their collateral, as the lender retrieves most of the funds early.
What the attacker needed
A loan contract with drawable funds; lender has funded the loan; borrower has posted collateral
The fix
The project acknowledged the issue and planned to mitigate it by restricting when payments can be made, rather than simply limiting the caller to the borrower.
How it was found
- The borrower posts 1 BTC as collateral.
- The lender funds the loan with 12,000 USDC.
- The lender calls makePayment 11 times.
- The lender calls _claimFunds and receives 11,903 USDC back.
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 loan contract, the borrower is supposed to make payments. Here, anyone could trigger a payment using money already sitting in the contract. A lender could abuse this to take back most of their money right after lending it, while the borrower still owes interest on the full amount.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.