Incorrect protocol fee is taken when changing NFTs
The protocol fee for changing NFTs was calculated as a percentage of the pool fee rather than the input amount, making it extremely low. This resulted in a loss of yield for the Caviar protocol.
Proposed fix is to add a separate fee called protocolChangeFeeRate which can be much higher than protocolFeeRate. For example, protocolChangeFeeRate could be on the order of ~20-30%. For example, if the fixed changeFee is 0.1 ETH, the NFT is worth 1.5 ETH, and the protocolChangeFeeRate is 30%, then the protocol fee would be 0.03 ETH on a change() or flashLoan().
function changeFeeQuote(uint256 inputAmount) 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;
uint256 feePerNft = changeFee * 10 ** exponent;
feeAmount = inputAmount * feePerNft / 1e18;
protocolFeeAmount = feeAmount * Factory(factory).protocolChangeFeeRate() / 10_000;
}
The original report as published on Code4rena, by Voyvoda. 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 40 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 changeFeeQuote function calculated the protocol fee based on the pool fee amount instead of the input amount, unlike buyQuote and sellQuote.
Impact
The protocol fee was extremely low, causing a profit loss for the protocol; the judge rated this as Medium severity because it is limited to a loss of yield.
What the attacker needed
None
The fix
The fix was to add a separate protocolChangeFeeRate and calculate the protocol fee as a percentage of the fee amount using that rate.
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 40 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
In a smart contract, a fee is taken when users change NFTs. The fee was calculated incorrectly, so the protocol received much less money than it should have. This meant the protocol lost out on potential earnings.
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.