Pieces Protocol

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

Fee Calculation Issues

Relevant GitHub Links

https://github.com/Cyfrin/2025-01-pieces-protocol/blob/4ef5e96fced27334f2a62e388a8a377f97a7f8cb/src/TokenDivider.sol#L274-L275

Summary

The fee calculation system in buyOrder function contains serious flaws due to Solidity's integer division limitations and lack of proper fee minimums/precision handling.

Vulnerability Details

In the buyOrder() function, the fee calculation cann't get the amount as the potential of the function because no floating point numbersand only integer operations.And leading integer division truncation.

fee = 150 / 100 = 1 wei
sellerFee = 1 / 2 = 0 wei // Lost precision!

Impact

Small orders are not charged at all. Inaccurate calculation of fees leads to loss of agreement revenue

Tools Used

Manual Review

Recommendations

uint256 constant BPS = 10000; // basic point:1 BPS = 0.01%
uint256 constant FEE_BPS = 100; // 1%
function calculateFees(uint256 price) internal pure returns (uint256 fee, uint256 sellerFee) {
fee = (price * FEE_BPS) / BPS;
sellerFee = fee / 2;
}
Updates

Lead Judging Commences

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