Pieces Protocol

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

Zero Fees For Low-Value Sales Due To Integer Division

Vulnerability Details

In TokenDivider.sol, the fee calculation uses integer division which rounds down to 0 for small prices:

uint256 fee = order.price / 100; // fee = 0 if price < 100 wei
uint256 sellerFee = fee / 2; // sellerFee = 0 if price <= 200 wei

For example:

  • If price = 99 wei: fee = 99/100 = 0 wei

  • If price = 199 wei: fee = 1 wei, but sellerFee = 1/2 = 0 wei

Impact

Protocol loses revenue on small trades

Recommendations

Use basis points (BPS) and multiply before division to avoid rounding to zero:

// Fee is 1% (100 BPS)
uint256 constant FEE_BPS = 100;
uint256 constant BPS_DENOMINATOR = 10000;
function buyOrder(uint256 orderIndex, address seller) external payable {
// ...existing code...
uint256 fee = (order.price * FEE_BPS) / BPS_DENOMINATOR;
uint256 sellerFee = fee / 2;
// ...existing code...
}

This ensures precise fee calculation even for small amounts.

Updates

Lead Judging Commences

fishy Lead Judge 5 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.