Dria

Swan
NFTHardhat
21,000 USDC
View results
Submission Details
Severity: low
Invalid

Use Bips(basis points) instead of Decimals for following reasons

Summary

Vulnerability Details

Using basis points (bips) instead of integers for fee calculations provides greater precision, standardization, and clarity. Here are some key reasons and use cases for using bips instead of integers for fees:

  • Precision and Avoidance of Floating Point Errors:

    Basis points are a standardized unit, where 1 bip = 0.01%. This avoids the need for fractional or floating-point calculations, which can introduce rounding errors. Representing fees in bips (e.g., 150 bips for 1.5%) ensures accuracy in fee calculations, especially for very small percentages.

  • Compatibility with Financial Systems:

    Bips are widely used in traditional finance, so using them for fee calculations makes it easier to align with external systems or integrate with APIs that expect fee inputs in bips.

  • Clearer Code Readability:

    Code that uses bips makes it easier to understand the fee being applied without needing additional comments or calculations.

function setMarketParameters(SwanMarketParameters memory _marketParameters) external onlyOwner {
require(_marketParameters.platformFee <= 100, "Platform fee cannot exceed 100%");

https://github.com/Cyfrin/2024-10-swan-dria/blob/main/contracts/swan/SwanManager.sol#L80-L81

function transferRoyalties(AssetListing storage asset) internal {
// calculate fees
uint256 buyerFee = (asset.price * asset.royaltyFee) / 100; // @audit for high precision
uint256 driaFee = (buyerFee * getCurrentMarketParameters().platformFee) / 100;

https://github.com/Cyfrin/2024-10-swan-dria/blob/main/contracts/swan/Swan.sol#L258-L261

Impact

Tools Used

Recommendations

Updates

Lead Judging Commences

inallhonesty Lead Judge 8 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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