Skip to content
Business logic Audit finding Intermediate

Refinancing and auction take less fee than expected

The protocol fee in refinance and auction is calculated on the debt amount instead of the full loan amount, causing the protocol to collect less fee than intended. An attacker could exploit this to reduce fees paid, leading to a loss of up to 2% of protocol fees.

000000 Follow with 0xNirix, bughuntoor and 6 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-09-predict-fun-judging/issues/118

Found by

000000, 0xNirix, bughuntoor, dany.armstrong90, iamnmt, kennedy1030, silver_eth, t.aksoy, tobi0x18

Summary

When creating a new loan within _acceptOffer, the protocolFee is applied to the whole amount taken from the lender - the fulfilled amount.

Solidity
    function _transferLoanAmountAndProtocolFee(
        address from,
        address to,
        uint256 loanAmount
    ) private returns (uint256 protocolFee) {
        protocolFee = (loanAmount * protocolFeeBasisPoints) / 10_000;
        LOAN_TOKEN.safeTransferFrom(from, to, loanAmount - protocolFee);
        if (protocolFee > 0) {
            LOAN_TOKEN.safeTransferFrom(from, protocolFeeRecipient, protocolFee);
        }
    }

So if the user fulfills 1000 USDC and the protocol fee is 2%, the fee that will be taken will be 20 USDC and the user will receive 980 USDC.

However, this is not the case within refinance and auction.

Solidity
        uint256 _nextLoanId = nextLoanId;
        uint256 debt = _calculateDebt(loan.loanAmount, loan.interestRatePerSecond, callTime - loan.startTime);
        uint256 protocolFee = (debt * protocolFeeBasisPoints) / 10_000;

There. the protocol fee is applied on the debt. So if a position with a debt of 980 USDC gets auctioned, the fee that will be paid will be 19,6 USDC. In this case, the protocol will earn 2% less fees than expected.

Whenever there's a protocol fee, refinance and auction will earn less fees proportional to the set protocolFee. Meaning that if the fee is 1%, these functions would earn 1% less. And if the fee is set to 2%, the loss will be 2%.

As the protocol can easily lose up to 2% of its fees, this according to Sherlock rules should be classified as High severity

Definite loss of funds without (extensive) limitations of external conditions. The loss of the affected party must exceed 1%.

Root Cause

Wrong math formula used

Affected Code

https://github.com/sherlock-audit/2024-09-predict-fun/blob/main/predict-dot-loan/contracts/PredictDotLoan.sol#L585

Impact

Protocol will make significantly less fees than expected.

PoC

No response

Mitigation

Use the following formula instead

Solidity
        uint256 protocolFee = (debt * protocolFeeBasisPoints) / (10_000 - protocolFeeBasisPoints);

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/PredictDotFun/predict-dot-loan/pull/50

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

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 protocol fee is calculated on the debt amount instead of the loan amount in refinance and auction functions.

Impact

The protocol loses up to 2% of its fees, which is a definite loss of funds exceeding 1%.

What the attacker needed

Protocol fee > 0; user uses refinance or auction

The fix

The protocol fee should be calculated using the formula: (debt * protocolFeeBasisPoints) / (10_000 - protocolFeeBasisPoints).

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 borrow money, the protocol takes a small fee. In some actions, the fee is calculated on the amount you owe (debt) rather than the full amount borrowed, so the fee is smaller than it should be. This means the protocol earns less money than expected.

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 000000

View all

32 more disclosed reports, best first.

More from predict.fun lending market

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.