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.
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.
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.
Manual Code Review
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.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.