Pieces Protocol

First Flight #32
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: low
Valid

Double to precision loss while calculating the protocol Fee.

Summary

Vulnerability Details

The issue of double precision loss occurs when calculating the protocol. This could result in letting some ether dust accumulate over time in the contract. Whereas there isn't a withdrawal mechanism to get the leftover calculation dust.

The vulnerability code:

uint256 fee = order.price / 100;
uint256 sellerFee = fee / 2;

Impact

For a price of 0.8 ETH (0.8 * 1e18 wei):

  • fee = (0.823 * 1e18) / 100 = 0.008 * 1e18 wei

  • sellerFee = (0.008* 1e18) / 2 = 0.004 * 1e18 wei

  • Each division lose precision in wei values

Tools Used

Recommendations

To fix this:

  • Calculate fees using multiplication first:

// Instead of price/100
+ fee = (order.price * FEE_PERCENTAGE) / FEE_DENOMINATOR; // e.g., (price * 100) / 10000 for 1%
  • Add a withdrawal mechanism to clear dust for the contract.

Updates

Lead Judging Commences

fishy Lead Judge 8 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Precision loss

Support

FAQs

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