DatingDapp

First Flight #33
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: low
Invalid

Calculation Precision Loss in Fee Calculations Can Lead to Rounding Errors and Lost Protocol Revenue

Summary

Vulnerability Details

The matchRewards function in the LikeRegistry contract suffers from potential precision loss during fee calculations due to integer division rounding down. This occurs when calculating the protocol fees using percentage-based arithmetic.

function matchRewards(address from, address to) internal {
uint256 matchUserOne = userBalances[from];
uint256 matchUserTwo = userBalances[to];
uint256 totalRewards = matchUserOne + matchUserTwo;
uint256 matchingFees = (totalRewards * FIXEDFEE) / 100; // Precision loss here
uint256 rewards = totalRewards - matchingFees;
totalFees += matchingFees;
// ... rest of the function
}

The issue arises because:

  • The fee calculation uses integer division (totalRewards * FIXEDFEE) / 100

  • Any remainder from the division is truncated

  • For small transactions or when the total amount isn't perfectly divisible by 100, the protocol loses fee revenue

Impact

Protocol loses fee revenue due to rounding down

Tools Used

Manual Review

Recommendations

Implement a precision-based calculation using basis points (bps) instead of percentages:

contract LikeRegistry is Ownable {
// Use basis points (1 basis point = 0.01%)
uint256 constant FIXED_FEE_BPS = 1000; // 10% in basis points
uint256 constant BPS_DENOMINATOR = 10000;
function matchRewards(address from, address to) internal {
uint256 matchUserOne = userBalances[from];
uint256 matchUserTwo = userBalances[to];
uint256 totalRewards = matchUserOne + matchUserTwo;
// More precise fee calculation using basis points
uint256 matchingFees = (totalRewards * FIXED_FEE_BPS) / BPS_DENOMINATOR;
uint256 rewards = totalRewards - matchingFees;
totalFees += matchingFees;
// ... rest of the function
}
}
Updates

Appeal created

n0kto Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Support

FAQs

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