Missing overflow check in flashLoan
The flashLoan function in ERC20FlashMintUpgradeable lacks an overflow check when adding the fee to the loan amount, allowing an attacker to burn zero tokens and avoid repayment. This could lead to a huge profit if the fee is non-zero.
NFTX contest
Originally disclosed on Code4rena
ERC20FlashMintUpgradeable.flashLoan does not check for an overflow when adding the fees to the flashloan amount. The functionality might have been copied from https://eips.ethereum.org/EIPS/eip-3156 but this one already has overflow checks as it uses solidity 0.8.0. This leads to an issue where the attacker does not need to pay back the flashloan as they will burn 0 tokens:
_burn(address(receiver), amount + fee);
They end up with a huge profit. (Luckily, this is currently not exploitable as the fee is set to 0 so there’s no possibility to overflow. However, if governance decides to change the flashloan fee, flashloans can be taken without having to repay them). Recommend using SafeMath.
Upgraded to 0.8.x.
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
Impact
If the flashloan fee is set to a non-zero value, an attacker could take flashloans without repaying them, resulting in a huge profit; currently not exploitable because the fee is zero.
What the attacker needed
Flashloan fee set to non-zero
The fix
The contract was upgraded to Solidity 0.8.x, which includes built-in overflow checks.
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 flash loan lets you borrow tokens and repay them in the same transaction. Here, the code adds the loan amount and fee without checking if that sum overflows (wraps around to a small number). An attacker could exploit this to make the system think they repaid when they didn't, keeping the borrowed tokens.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.