Skip to content
Smart contracts Audit finding Advanced

refinanceFull / addNewTranche reusing a lender’s signature leads to unintended behavior

The refinanceFull and addNewTranche functions accept the same lender signature, so a malicious user can front-run a refinanceFull call with addNewTranche using the same signature. This causes the loan amount to approximately double and increases the lender's risk dramatically.

bin2chen Follow

Originally disclosed on Code4rena

Submitted by bin2chen

https://github.com/code-423n4/2024-04-gondi/blob/b9863d73c08fcdd2337dc80a8b5e0917e18b036c/src/lib/loans/MultiSourceLoan.sol#L358

https://github.com/code-423n4/2024-04-gondi/blob/b9863d73c08fcdd2337dc80a8b5e0917e18b036c/src/lib/loans/MultiSourceLoan.sol#L194

Vulnerability details

In MultiSourceLoan, refinanceFull() and addNewTranche() use the same signature.

    function refinanceFull(
        RenegotiationOffer calldata _renegotiationOffer,
        Loan memory _loan,
        bytes calldata _renegotiationOfferSignature
    ) external nonReentrant returns (uint256, Loan memory) {
...
        if (lenderInitiated) {
            if (_isLoanLocked(_loan.startTime, _loan.startTime + _loan.duration)) {
                revert LoanLockedError();
            }
            _checkStrictlyBetter(
                _renegotiationOffer.principalAmount,
                _loan.principalAmount,
                _renegotiationOffer.duration + block.timestamp,
                _loan.duration + _loan.startTime,
                _renegotiationOffer.aprBps,
                totalAnnualInterest / _loan.principalAmount,
                _renegotiationOffer.fee
            );
        } else if (msg.sender != _loan.borrower) {
            revert InvalidCallerError();
        } else {
            /// @notice Borrowers clears interest
@>          _checkSignature(_renegotiationOffer.lender, _renegotiationOffer.hash(), _renegotiationOfferSignature);
            netNewLender -= totalAccruedInterest;
            totalAccruedInterest = 0;
        }
    function addNewTranche(
        RenegotiationOffer calldata _renegotiationOffer,
        Loan memory _loan,
        bytes calldata _renegotiationOfferSignature
    ) external nonReentrant returns (uint256, Loan memory) {
...
        uint256 loanId = _renegotiationOffer.loanId;

        _baseLoanChecks(loanId, _loan);
        _baseRenegotiationChecks(_renegotiationOffer, _loan);
@>      _checkSignature(_renegotiationOffer.lender, _renegotiationOffer.hash(), _renegotiationOfferSignature);
        if (_loan.tranche.length == getMaxTranches) {
            revert TooManyTranchesError();
        }

So when lender signs RenegotiationOffer, it is meant to replace tranche, i.e. execute refinanceFull(). But a malicious user can use this sign and front-run execute addNewTranche().

addNewTranche() doesn’t limit the RenegotiationOffer too much. The newly generated Loan will be approximately twice the total amount borrowed, and the risk of borrowing against the lender will increase dramatically.

Impact

Maliciously using the signature of refinanceFull() to execute addNewTranche() will result in approximately double the borrowed amount, and the risk of borrowing will increase dramatically.

Recommended Mitigation

In RenegotiationOffer, add a type field to differentiate between signatures.

Assessed type

Context

0xend (Gondi) confirmed

Gondi mitigated:

Check trancheIndex to differentiate between refiFull/addNewTranche.

Status: Unmitigated. Full details in reports from minhquanym, bin2chen and oakcobalt, and also included in the Mitigation Review section below.


The original report as published on Code4rena, by bin2chen. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Likely the signed offer does not include a field that distinguishes between the refinanceFull and addNewTranche operations, so the same signature is valid for both.

Impact

The borrowed amount could approximately double and the risk of borrowing against the lender could increase dramatically.

What the attacker needed

Lender signs a RenegotiationOffer; attacker can front-run the transaction

The fix

A type field should be added to RenegotiationOffer to differentiate between signatures, or the trancheIndex should be checked to distinguish refiFull from addNewTranche.

How it was found

  1. A lender signs a RenegotiationOffer intended for refinanceFull.
  2. A malicious user obtains that signature.
  3. The malicious user front-runs and calls addNewTranche with the same offer and signature.
  4. The loan is modified by adding a new tranche instead of replacing the existing one.

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.

A lender signs a message to approve replacing an existing loan with a new one. Because another function that adds an extra loan part accepts the same signed message, an attacker can use that signature to add a new loan part instead. This makes the total borrowed amount roughly twice as large, which the lender did not intend.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by bin2chen

View all

139 more disclosed reports, best first.

More from Gondi Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.