Flash loan fee is incorrect in Private Pool contract
The flash loan fee in the Private Pool contract was incorrectly set to the raw changeFee value without scaling, so a changeFee of 25 resulted in a flash loan fee of only 25 wei instead of the intended 0.0025 ETH. An attacker could borrow NFTs via flash loans for almost no fee.
Private Pools support NFT borrowing using flash loans. Users that decide to use this feature have to pay a flash loan fee to the owner of the pool.
The contract has a changeFee variable that is used to configure the fee for changing NFTs, and this variable is also used to determine the fee for flash loans. In the case of a change operation, the value is interpreted as an amount with 4 decimals, and the token is the base token of the pool. This means that, for example, if the base token is ETH, a changeFee value of 25 should be interpreted as a fee of 0.0025 ETH for change operation.
However, as we can see in this following snippet, the flashFee function just returns the value of changeFee without any scaling or modification.
750: function flashFee(address, uint256) public view returns (uint256) {
751: return changeFee;
752: }
This means that, following the previous example, a changeFee value of 25 will result in 0.0025 ETH for change operation, but just 25 wei for flash loans.
The documentation hints that this value should also be scaled to 4 decimals in the case of the flash loan fee, but in any case this is clearly an incorrect setting of the flash loan fee.
Proof of Concept
In the following test, the pool is configured with a changeFee value of 25, and Alice is able to execute a flash loan by just paying 25 wei.
Note: the snippet shows only the relevant code for the test. Full test file can be found here.
That said, the code and the codebase point to wanting to offer a fee that scales based on the amounts loaned. For this nuanced reason, given that the Sponsor has confirmed and mitigated with a scaling fee, I believe that the most appropriate severity is Medium.
The original report as published on Code4rena, by adriro. 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
The flashFee function returned the changeFee variable directly without scaling it to account for the token's decimals, unlike the changeFeeQuote function which properly scales the fee.
Impact
The pool owner received far less fee than intended for flash loans, potentially allowing cheap borrowing of NFTs.
What the attacker needed
A PrivatePool with flash loans enabled; An NFT deposited in the pool; Ability to deploy a contract to receive the flash loan
The fix
The flashFee function should scale the changeFee value similarly to changeFeeQuote, by exponentiating it based on the base token's decimals.
How it was found
Deploy a PrivatePool with a changeFee of 25.
Mint an NFT to the pool.
As Alice, deploy a FlashLoanBorrower contract.
Call flashLoan on the pool with 25 wei as the 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 flash loan is a loan that must be borrowed and repaid within the same transaction. The pool charged a fee for this service, but due to a mistake, the fee was calculated as a tiny number of wei (the smallest unit of ETH) instead of the intended amount. This meant users could borrow NFTs very cheaply, depriving the pool owner of fees.
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.