OrderBook

First Flight #43
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: low
Valid

Fee Calculation and Rounding

Problem:
Fee calculation uses integer division, which can round down to zero for small order amounts, resulting in no fee collected.

Risk:
Attackers can create many small orders to avoid paying any protocol fee, reducing protocol revenue.

uint256 protocolFee = (order.priceInUSDC * FEE) / PRECISION;

Proof of Concept

// Solidity test
function testFeeRounding() public {
// Assume FEE = 3, PRECISION = 100
uint256 price = 1; // 1 USDC
uint256 protocolFee = (price * 3) / 100; // 0
assert(protocolFee == 0); // No fee collected
}

Recommended Mitigation

- uint256 public constant PRECISION = 100;
+ uint256 public constant PRECISION = 1e6;
- uint256 protocolFee = (order.priceInUSDC * FEE) / PRECISION;
+ uint256 protocolFee = (order.priceInUSDC * FEE) / PRECISION;
+ require(protocolFee > 0, "Fee too low");
Updates

Lead Judging Commences

yeahchibyke Lead Judge
5 months ago
yeahchibyke Lead Judge 5 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Fee can be bypassed

Protocol Suffers Potential Revenue Leakage due to Precision Loss in Fee Calculation

Support

FAQs

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

Give us feedback!