Dria

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

Loss of Precision in Royalty Calculations

Summary

The transferRoyalties function in the Swan contract calculates and distributes royalties from the seller to the buyer and owner. However, the current implementation may lead to a significant loss of precision, particularly when the asset price is low, due to the nature of integer division in Solidity.

Vulnerability Detail

In Solidity, division between two integers truncates any decimal portion, leading to a loss of precision. The function calculates the buyer's fee based on the asset price and the royalty fee expressed as a percentage. When either the asset price or the royalty fee is small, the resulting fee calculation can yield zero due to truncation.

This loss of precision means that, for low-priced assets, the calculated fees may effectively be zero, resulting in the following issues:

  • The buyer may receive significantly less than expected, or in some scenarios, nothing at all.

  • Swan owner, which is entitled to a portion of the fees, may also receive an incorrect or zero amount, potentially affecting the platform’s revenue model.

As a result, both buyers and the platform may face financial discrepancies that could undermine trust and participation in the marketplace.

Impact

The potential consequences of this precision loss are critical:

  • Buyers may become disenchanted if they do not receive the expected royalties or if the amounts are negligible.

  • The overall financial health of the platform could be jeopardized if owner receives insufficient funds, affecting its operational sustainability and ability to provide services.

Tool used

Manual Code Review

Recommendation

To mitigate the loss of precision, it is recommended to increase the denominator in the fee calculation. For instance, instead of dividing by 100, using a larger base (e.g., 10,000) can retain more significant figures and prevent truncation, ensuring that all parties receive their fair share of royalties accurately. By implementing this change, the contract can enhance trust and reliability, fostering a more sustainable economic environment for all participants.

Updates

Lead Judging Commences

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

Rounding Issue in `Swan.sol::transferRoyalties` function

Support

FAQs

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