Thunder Loan

AI First Flight #7
Beginner FriendlyFoundryDeFiOracle
EXP
View results
Submission Details
Severity: low
Valid

getCalculatedFee rounds to zero for small borrows, giving free flash loans

Description

ThunderLoan::getCalculatedFee divides twice by s_feePrecision (1e18). For small borrow amounts the integer division truncates the fee to zero, so small flash loans are free.

uint256 valueOfBorrowedToken = (amount * getPriceInWeth(address(token))) / s_feePrecision;
@> fee = (valueOfBorrowedToken * s_flashLoanFee) / s_feePrecision; // truncates to 0 for small amounts

Risk

Likelihood: Medium

  • Any borrow below roughly s_feePrecision / s_flashLoanFee tokens pays no fee; trivially reproducible.

Impact: Low

  • Fee revenue leaks on small loans; negligible per call, but a free-loan primitive and a precision-correctness defect.

Proof of Concept

Borrowing 300 wei of an 18-decimal token whose price is 1e18 yields (300 * 1e18 / 1e18) * 3e15 / 1e18 = 0, so the fee truncates to zero and the loan is free:

function test_G4_smallLoanHasZeroFee() public allowTokenA {
assertEq(thunderLoan.getCalculatedFee(tokenA, 300), 0); // fee rounds to zero
}

Recommended Mitigation

Restructure the fee math to avoid the double division by s_feePrecision (or enforce a minimum fee) so small borrows cannot round down to a zero fee.

Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 4 hours ago
Submission Judgement Published
Validated
Assigned finding tags:

[L-01] getCalculatedFee can be 0

## Description getCalculatedFee can be as low as 0 ## Vulnerability Details Any value up to 333 for "amount" can result in 0 fee based on calculation ``` function testFuzzGetCalculatedFee() public { AssetToken asset = thunderLoan.getAssetFromToken(tokenA); uint256 calculatedFee = thunderLoan.getCalculatedFee( tokenA, 333 ); assertEq(calculatedFee ,0); console.log(calculatedFee); } ``` ## Impact Low as this amount is really small ## Recommendations A minimum fee can be used to offset the calculation, though it is not that important.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!