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.
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.
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);
}
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.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.