Skip to content
Business logic Audit finding Intermediate

Flashloan fee is not distributed to the factory

The flashloan function in PrivatePool sends the entire fee to the pool, while the factory receives no protocol fee, unlike other functions such as change. An attacker could take flashloans repeatedly and the protocol would lose the fee revenue it should have earned.

rvierdiiev Follow

Originally disclosed on Code4rena

Submitted by rvierdiiev

When user takes a flashloan, then he pays a fee to the PrivatePool. The problem is that the whole fee amount is sent to PrivatePool and factory receives nothing.

However, all other function of contract send some part of fees to the factory.

For example, change function, which is similar to the flashloan as it doesn’t change virtual nft and balance reserves. This function calculates pool and protocol fees.

But in case of flashloan, only pool receives fees.

Tools Used

VS Code

Recommended Mitigation Steps

Send some part of flashloan fee to the factory.

outdoteth (Caviar) confirmed and commented:

Fixed in: https://github.com/outdoteth/caviar-private-pools/pull/8.

Proposed fix is to add a method that returns the protocol fee and flash fee. And then have the flash fee function sum the two outputs:

function flashFeeAndProtocolFee() public view returns (uint256 feeAmount, uint256 protocolFeeAmount) {
    // multiply the changeFee to get the fee per NFT (4 decimals of accuracy)
    uint256 exponent = baseToken == address(0) ? 18 - 4 : ERC20(baseToken).decimals() - 4;
    feeAmount = changeFee * 10 ** exponent;
    protocolFeeAmount = feeAmount * Factory(factory).protocolFeeRate() / 10_000;
}


function flashFee(address, uint256) public view returns (uint256) {
    (uint256 feeAmount, uint256 protocolFeeAmount) = flashFeeAndProtocolFee();
    return feeAmount + protocolFeeAmount;
}

and then add the protocol payment in the flashLoan method:

// -- snip -- //

if (baseToken != address(0)) {
    // transfer the fee from the borrower
    ERC20(baseToken).safeTransferFrom(msg.sender, address(this), flashFee);

    // transfer the protocol fee to the factory
    ERC20(baseToken).safeTransferFrom(msg.sender, factory, protocolFee);
} else {
    // transfer the protocol fee to the factory
    factory.safeTransferETH(protocolFee);
}

Alex the Entreprenerd (judge) commented:

@outdoteth - Can you please confirm if you originally intended to have the protocol charge a fee for Flashloans?

outdoteth (Caviar) commented:

It was an oversight that we did not charge fees on flash loans. It’s implied that it should be paid though since protocol fees are charged everywhere else a user makes a transaction.

Alex the Entreprenerd (judge) commented:

The Warden has found an inconsistency as to how fees are paid. After confirming with the Sponsor, I agree with Medium Severity.

Status: Mitigation confirmed. Full details in reports from rbserver, KrisApostolov, and rvierdiiev.


The original report as published on Code4rena, by rvierdiiev. 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 flashloan function calculates and transfers only the pool fee, omitting the protocol fee that other functions include.

Impact

The protocol loses the fee revenue it should have collected from flashloans, as confirmed by the sponsor who called it an oversight.

What the attacker needed

None

The fix

The flashloan function was fixed to calculate and transfer the protocol fee to the factory in addition to the pool fee.

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 flashloan is a loan that is borrowed and repaid within a single transaction. The pool charges a fee for this service, but the code sends all of that fee to the pool itself and none to the factory that manages the protocol. This means the protocol misses out on income it collects from other actions.

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 rvierdiiev

View all

72 more disclosed reports, best first.

More from Caviar Private Pools

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.