Dria

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

Rounding Issue in `transferRoyalties` Function

Summary

A Rounding issue is identified in the transferRoyalties function of the Swan.sol smart contract. The vulnerability arises from the integer division of fee calculations, which can lead to unintended values. This may affect the revenue model of the protocol, as protocol fees could be calculated to be zero in specific scenarios.

Vulnerability Details

In the transferRoyalties function, fees are calculated using integer arithmetic, which can result in zero fees due to truncation when performing division operations. The relevant lines of code are as follows: https://github.com/Cyfrin/2024-10-swan-dria/blob/main/contracts/swan/Swan.sol#L258-L272

/// @notice Function to transfer the royalties to the seller & Dria.
function transferRoyalties(AssetListing storage asset) internal {
// calculate fees
uint256 buyerFee = (asset.price * asset.royaltyFee) / 100;
uint256 driaFee = (buyerFee * getCurrentMarketParameters().platformFee) / 100;
// first, Swan receives the entire fee from seller
// this allows only one approval from the seller's side
token.transferFrom(asset.seller, address(this), buyerFee);
// send the buyer's portion to them
token.transfer(asset.buyer, buyerFee - driaFee);
// then it sends the remaining to Swan owner
token.transfer(owner(), driaFee);
}

Example Scenario:

  • Alice lists the NFT for 1000 tokens.

  • The buyerAgent address is 0x123 with a 1% royalty.

  • The protocol fee is 5%.

buyerFee = ( 1000 * 1 ) / 100 = 10 tokens

driaFee = ( 10 * 5 ) / 100 = 0.5 = 0 tokens (due to rounding)

So, Amount to Buyer Agent= buyerFeedriaFee = 10−0 = 10 tokens.

Amount to Swan Owner = driaFee = 0 tokens.

So, if a buyerAgent has a low royaltyFee then that agent gets the whole buyerFee without giving any fee to the protocol.

Impact

  • Loss of Protocol Revenue: If the protocol fee is calculated to be zero, the contract will not transfer any fees to the protocol owner, resulting in a loss of revenue.

  • Reduced Trust and Incentive: Continuous occurrences of zero fees could diminish trust among users and stakeholders, potentially impacting the overall adoption and usage of the protocol.

Tools Used

Manual Review

Recommendations

Introduce a Multiplier: Use a constant multiplier to scale the values before performing the division. This approach helps preserve precision during calculations.

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.