Skip to content
Business logic Audit finding Intermediate

loan.hash() does not contain protocolFee

The loan hash used to verify loan integrity omitted the protocolFee field, so a caller could supply an arbitrary protocolFee in later calls without failing the hash check. This allowed borrowers to avoid paying protocol fees and could cause accounting errors in the LoanManager.

bin2chen Follow with oakcobalt and minhquanym

Originally disclosed on Code4rena

Submitted by bin2chen, also found by oakcobalt and minhquanym

The current IMultiSourceLoan.loop.hash() does not contain protocolFee:

    function emitLoan(LoanExecutionData calldata _loanExecutionData)
        external
        nonReentrant
        returns (uint256, Loan memory)
    {
...
@>      _loans[loanId] = loan.hash();
        emit LoanEmitted(loanId, offerIds, loan, totalFee);

        return (loanId, loan);
    }

    function hash(IMultiSourceLoan.Loan memory _loan) internal pure returns (bytes32) {
        bytes memory trancheHashes;
        for (uint256 i; i < _loan.tranche.length;) {
            trancheHashes = abi.encodePacked(trancheHashes, _hashTranche(_loan.tranche[i]));
            unchecked {
                ++i;
            }
        }
        return keccak256(
            abi.encode(
                _MULTI_SOURCE_LOAN_HASH,
                _loan.borrower,
                _loan.nftCollateralTokenId,
                _loan.nftCollateralAddress,
                _loan.principalAddress,
                _loan.principalAmount,
                _loan.startTime,
                _loan.duration,
@>              //@audit miss protocolFee
                keccak256(trancheHashes)
            )
        );
    }

   struct Loan {
        address borrower;
        uint256 nftCollateralTokenId;
        address nftCollateralAddress;
        address principalAddress;
        uint256 principalAmount;
        uint256 startTime;
        uint256 duration;
        Tranche[] tranche;
@>      uint256 protocolFee;
    }

Then, you can specify protocolFee arbitrarily in many methods, but the _baseLoanChecks() security check doesn’t revert.

    function _baseLoanChecks(uint256 _loanId, Loan memory _loan) private view {
@>      if (_loan.hash() != _loans[_loanId]) {
            revert InvalidLoanError(_loanId);
        }
        if (_loan.startTime + _loan.duration < block.timestamp) {
            revert LoanExpiredError();
        }
    }

Example: repayLoan(loadn.protocolFee=0) to escape fees and cause a LoanManager accounting error. refinancePartial()/refinanceFull() can also specify the wrong fees to skip the fees.

Impact

The loan hash does not contain a protocolFee, leading to an arbitrary protocolFee that can be specified to escape fees or cause an accounting error.

Recommended Mitigation

    function hash(IMultiSourceLoan.Loan memory _loan) internal pure returns (bytes32) {
        bytes memory trancheHashes;
        for (uint256 i; i < _loan.tranche.length;) {
            trancheHashes = abi.encodePacked(trancheHashes, _hashTranche(_loan.tranche[i]));
            unchecked {
                ++i;
            }
        }
        return keccak256(
            abi.encode(
                _MULTI_SOURCE_LOAN_HASH,
                _loan.borrower,
                _loan.nftCollateralTokenId,
                _loan.nftCollateralAddress,
                _loan.principalAddress,
                _loan.principalAmount,
                _loan.startTime,
                _loan.duration,
                keccak256(trancheHashes),
+               _loan.protocolFee
            )
        );
    }

Assessed type

Context

0xend (Gondi) confirmed

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

Avoiding fees is just a Medium. For the accounting error, I’ll need more proof that this can lead to something significant to mark this as High.

Gondi mitigated:

Added field in hash.

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


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

The hash function used to verify loan integrity did not include the protocolFee field, so changes to that field were not detected.

Impact

An attacker could avoid protocol fees and potentially cause accounting errors in the LoanManager; the judge rated fee avoidance as Medium and required more proof for a High-severity accounting impact.

What the attacker needed

A loan exists; ability to call repay or refinance

The fix

The hash function was updated to include the protocolFee field, and the mitigation was confirmed.

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 smart contract stores a fingerprint (hash) of each loan to check later that the loan details have not been changed. The fingerprint was built from most loan fields but forgot to include the protocol fee, so someone could change the fee in later calls and the check would still pass. This let them avoid paying fees and confused the contract's accounting.

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

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.