Dandy Caramel Tortoise
Medium
Not updating state before making custom external call can cause borrower's to loose assets due to re-entrancy
Not updating state before making custom external call can cause borrower's to loose assets due to re-entrancy
The details of the repayment is updated only after the external call to the loanRepaymentListener
is made
function _repayLoan(
uint256 _bidId,
Payment memory _payment,
uint256 _owedAmount,
bool _shouldWithdrawCollateral
) internal virtual {
....
// @audit attacker can re-enter here. the repayment details are not yet updated
_sendOrEscrowFunds(_bidId, _payment); //send or escrow the funds
// update our mappings
bid.loanDetails.totalRepaid.principal += _payment.principal;
bid.loanDetails.totalRepaid.interest += _payment.interest;
bid.loanDetails.lastRepaidTimestamp = uint32(block.timestamp);
function _sendOrEscrowFunds(uint256 _bidId, Payment memory _payment)
internal virtual
{
....
address loanRepaymentListener = repaymentListenerForBid[_bidId];
// @audit re-enter in this call
if (loanRepaymentListener != address(0)) {
require(gasleft() >= 80000, "NR gas"); //fixes the 63/64 remaining issue
try
ILoanRepaymentListener(loanRepaymentListener).repayLoanCallback{
gas: 80000
}( //limit gas costs to prevent lender preventing repayments
_bidId,
_msgSenderForMarket(bid.marketplaceId),
_payment.principal,
_payment.interest
)
{} catch {}
This allows a malicious lender to reenter the TellerV2
contract and invoke lenderCloseLoan
seizing the collateral of the borrower as well if the loan is currently defaulted
- The repayment should be made after defaultTimestamp has passed
No response
- Defaulting timestmap of loan has passed
- Borrower does a repayment of 100 which is transferred to the lender. Following this
.repayLoanCallback
is called - Lender reenters via the
loanRepaymentListener
and invokes thelenderCloseLoan
function further seizing the collateral of the borrower - Borrower looses both the repayment amount and the collateral
Borrower will loose repayment amount and also the collateral
No response
Update the state before the loanRepaymentListener
call is made