Skip to content
Business logic Audit finding Intermediate

Borrower signature could be reused in emitLoan()

The borrower's signature for a loan execution could be reused to call emitLoan() multiple times, allowing an attacker to force the borrower into repeated loans after repayment. This could happen if the borrower set a long expiration time and the lender's offer still had capacity.

minhquanym Follow

Originally disclosed on Code4rena

Submitted by minhquanym

The function emitLoan() is used to issue a new loan. This function could be called directly by the borrower or by a random address if the borrower has signed the LoanExecutionData.

function emitLoan(LoanExecutionData calldata _loanExecutionData)
    external
    nonReentrant
    returns (uint256, Loan memory)
{
    address borrower = _loanExecutionData.borrower;
    ExecutionData calldata executionData = _loanExecutionData.executionData;
    (address principalAddress, address nftCollateralAddress) = _getAddressesFromExecutionData(executionData);

    OfferExecution[] calldata offerExecution = executionData.offerExecution;

    // @audit Check borrower signature or borrower is caller
    _validateExecutionData(_loanExecutionData, borrower);
    ...
}

function _validateExecutionData(LoanExecutionData calldata _executionData, address _borrower) private view {
    if (msg.sender != _borrower) {
        _checkSignature(
            _executionData.borrower, _executionData.executionData.hash(), _executionData.borrowerOfferSignature
        );
    }
    if (block.timestamp > _executionData.executionData.expirationTime) {
        revert ExpiredOfferError(_executionData.executionData.expirationTime);
    }
}

However, there isn’t a check to ensure the signature for the same LoanExecutionData can’t be used to execute emitLoan() more than once. As a result, if the borrower repays the loan, an attacker could call emitLoan() again to initiate a new loan.

Proof of Concept

Consider this scenario:

  1. Lender Alice has an offer with a capacity of 50 ETH.
  2. Borrower Bob signs a signature to take a 10 ETH loan with his NFT.
  3. After Bob repays the loan, anyone can call emitLoan() using the previous signature to force Bob to take the 10 ETH loan again. Since the capacity of Alice’s offer is 50 ETH, the signature can be reused up to 5 times.

Recommended Mitigation Steps

Add a nonce to ensure a signature cannot be reused.

0xend (Gondi) acknowledged and commented:

This could be the case but don’t think is high given the struct has an expiration time to contemplate this. Borrower can avoid any issue by setting this to be close to the execution. Loans lasts for months, this will be at most a few hours.

To avoid an extra write+read, I’d probably make it very clear to the consumer of the smart contract.

0xA5DF (judge) decreased severity to Medium and commented:

Marking as Medium due to sponsor comment. This requires some external conditions which don’t seem to be easily satisfied.

0xend (Gondi) commented:

For the replay to happens:

  • Borrower needs to set an expiration longer than the intended time in which they’ll repay the loan.
  • All lender offers must not expire before the loan is repaid AND have capacity.

Borrower has no reason to set this variable longer than block.timestamp + small delta (the time it remains in the mempool).

Gondi mitigated:

Borrower should always set block.timestamp + small time delta as expiration to control when the loan can be started.

Status: Mitigation confirmed. Full details in reports from oakcobalt and bin2chen.


The original report as published on Code4rena, by minhquanym. 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

The contract did not include a nonce or replay protection for the borrower's signature, so the same signed loan execution data could be used more than once.

Impact

An attacker could force the borrower to take repeated loans, but only if the borrower set a long expiration time and the lender's offer still had capacity; the sponsor noted this requires external conditions that are not easily satisfied.

What the attacker needed

Borrower sets long expiration; lender offer has remaining capacity; loan is repaid before offer expires

The fix

The mitigation was to instruct borrowers to always set the expiration time to a small delta from the current block timestamp, limiting the window for replay.

How it was found

  1. Lender Alice creates an offer with a capacity of 50 ETH.
  2. Borrower Bob signs a signature to take a 10 ETH loan using his NFT.
  3. Bob repays the loan.
  4. Anyone calls emitLoan() with the previous signature to force Bob to take the 10 ETH loan again.
  5. The signature can be reused up to 5 times because Alice's offer capacity is 50 ETH.

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.

When you take a loan, you sign a message to prove you agree. The contract did not check if that signature was already used, so someone could reuse it to make you take the same loan again. This is like someone copying your signature on a cheque and cashing it multiple times.

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.

More by minhquanym

View all

28 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.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.