Protocol Suffers Potential Revenue Leakage due to Precision Loss in Fee Calculation
The protocol's fee calculation, which uses integer division with low precision (/ 100
), creates a rounding error that can be exploited. For any trade priced at 33 wei of USDC or less, the calculated 3% fee rounds down to zero, allowing the trade to be processed fee-free. While the high gas cost of performing many small transactions makes a large-scale economic attack impractical today, this represents a fundamental design flaw that causes a verifiable and permanent leakage of protocol revenue. This flaw undermines the economic model and should be remediated as a matter of protocol robustness and best practice.
The buyOrder
function calculates the protocol fee using the formula (order.priceInUSDC * 3) / 100
. Due to Solidity's integer division, any result with a remainder is truncated. Consequently, if the numerator (order.priceInUSDC * 3)
is less than 100
, the resulting protocolFee
is 0
. This is true for any priceInUSDC
value between 1 and 33.
This creates a scenario where users can intentionally price their orders just below the 34 wei threshold to avoid fees. Although a single such transaction has a negligible impact, it establishes a pattern of value leakage that is built into the protocol's core logic.
The primary impact is a direct, albeit small, loss of protocol revenue on certain trades. While the economic viability of a large-scale attack is questionable due to gas costs, the existence of this flaw has several negative consequences:
Protocol Value Leak: The protocol fails to capture fees it is entitled to, creating a small but persistent drain on its treasury.
Design Flaw: It demonstrates a weakness in the handling of financial calculations. In DeFi, even minor rounding errors can be aggregated or combined with other exploits to cause significant issues.
Future Risk: A reduction in L2 gas fees or the introduction of new protocol features could potentially make this exploit more economically viable in the future.
Medium. From a technical standpoint, the flaw is easy to trigger. Any user can create a low-priced order. However, the economic incentive to do so at scale is currently low, which reduces the practical likelihood of a major exploit.
The following test demonstrates that an order priced at 33 wei of USDC results in zero fees being collected by the protocol, confirming the rounding vulnerability.
Test File: test/FeeRoundingVulnerabilityV2.t.sol
Successful Test Output:
The successful test confirms that it is possible to execute a trade without paying any fees, validating the existence of the revenue leakage flaw.
The standard industry practice to prevent such rounding issues is to increase the precision of the calculation by using basis points (1 bp = 0.01%).
Impact of the Fix:
With this change, the fee calculation becomes significantly more precise. While a price of 33 wei would still result in a zero fee ((33 * 300) / 10000 = 0
), the threshold for earning a fee is much lower. For a more realistic low-value transaction of 1 USDC (1,000,000 wei), the fee would be:
(1,000,000 * 300) / 10000 = 30,000 wei
(or 0.03 USDC).
This ensures that fees are collected fairly and consistently across almost all non-trivial trades, patching the revenue leak.
Protocol Suffers Potential Revenue Leakage due to Precision Loss in Fee Calculation
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.