Some of the tokens that are identified as underlying tokens that can be loaned do not have 18 decimals of precision. For example, both USDT and USDC have 6 decimals of precision. But the contract sets s_feePrecision
to 1e18 for all tokens. In getCalculatedFee
when the amount is multiplied by the price of the underlying token in WETH and then divided by s_feePrecision
, you would truncate several decimals of precision if you were using a token like USDT or USDC.
You could end up with a much smaller fee calculation than you should or, worse, you could end up with something less than 1 (if the amount of the flash loan were small enough) which would round down to 0. Depositors would not get as much fees (or any fees) to compensate them for their deposits when flash loans were made.
Manual review
Instead of s_feePrecision
, add a mapping of token to decimals that will allow you to set the correct number of decimals when you call setAllowedToken
to add a token. Then call that mapping to get the correct number of decimals when needed. You can do this with the following changes:
Add a mapping of token to decimals:
In setAllowedToken, add another parameter for uint256 decimals:
Push the correct number of decimals to the mapping in setAllowedToken:
Refactor getCalculatedFee
as follows. Note that in a different finding I point out that you shouldn't be involving getPriceInWeth in this calculation but I am leaving it here for purposes of this refactoring:
Refactor the getFeePrecision
function:
Refactor updateFlashLoanFee
:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.