Dria

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

Swan Dria Audit Report(by coinleft)

Findings

1. Asset Transfer Before Payment Confirmation

Severity: High

Context: Swan.sol#L276-302

Code:

/// @notice Executes the purchase of a listing for a buyer for the given asset.
/// @dev Must be called by the buyer of the given asset.
function purchase(address _asset) external {
AssetListing storage listing = listings[_asset];
// asset must be listed to be purchased
if (listing.status != AssetStatus.Listed) {
revert InvalidStatus(listing.status, AssetStatus.Listed);
}
// can only the buyer can purchase the asset
if (listing.buyer != msg.sender) {
revert Unauthorized(msg.sender);
}
// update asset status to be sold
listing.status = AssetStatus.Sold;
// transfer asset from seller to Swan, and then from Swan to buyer
// this ensure that only approval to Swan is enough for the sellers
SwanAsset(_asset).transferFrom(listing.seller, address(this), 1);
`SwanAsset(_asset).transferFrom(address(this), listing.buyer, 1);`
// transfer money
`token.transferFrom(listing.buyer, address(this), listing.price);`
token.transfer(listing.seller, listing.price);
emit AssetSold(listing.seller, msg.sender, _asset, listing.price);
}

Description: In the code, SwanAsset(_asset).transferFrom(address(this), listing.buyer, 1); is called to move the asset to listing.buyer before the payment(token.transferFrom(listing.buyer, address(this), listing.price);)is confirmed. if the payment fails, will lost seller's asset.

Recommendation:
Move the transfer of assets (transferFrom to the buyer) to after confirming the buyer has sent funds successfully.

2. Misuse transfer and transferFrom

Severity: High

Context: Swan.sol#L276-302

Code:

token.transfer(listing.seller, listing.price);

Description: transfer token from Swan contract(address(this)) to seller, or the buyer will pay twice.

Recommendation:

token.transferFrom(address(this), listing.seller, listing.price);
Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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