NFT Dealers

First Flight #58
Beginner FriendlyFoundry
100 EXP
Submission Details
Impact: low
Likelihood: medium

[G-3] Useless parameters inside of the `Listing` struct can be removed

Author Revealed upon completion

Useless parameters inside of the Listing struct can be removed

Description

The Listing struct contains 2 parameters that are useless in the contract context:

struct Listing {
address seller;
uint32 price;
@> address nft;
@> uint256 tokenId;
bool isActive;
}
  1. The nft parameter is only used inside the list function, when the listing is created. Its value is always set to address(this) so it can be removed without any impact. If we need to access the NFT address, we can directly call address(this) instead of using the object parameter nft:

s_listings[_tokenId] = Listing({
seller: msg.sender,
price: _price,
@> nft: address(this),
tokenId: _tokenId,
isActive: true
});
  1. The tokenId parameter of listings is always matching the listing id. We don't need to track both the token id and the listing id, so we can get rid of this parameter as well.

Recommended Mitigation

Delete the useless parameters:

s_listings[_tokenId] = Listing({
seller: msg.sender,
price: _price,
- nft: address(this),
- tokenId: _tokenId,
isActive: true
});
...
function list(uint256 _tokenId, uint32 _price) external onlyWhitelisted {
...
s_listings[_tokenId] =
- Listing({seller: msg.sender, price: _price, nft: address(this), tokenId: _tokenId, isActive: true});
+ Listing({seller: msg.sender, price: _price, isActive: true});
...
}
function buy(uint256 _listingId) external payable {
...
- _safeTransfer(listing.seller, msg.sender, listing.tokenId, "");
+ _safeTransfer(listing.seller, msg.sender, _listingId, "");
...
}
function cancelListing(uint256 _listingId) external {
...
- usdc.safeTransfer(listing.seller, collateralForMinting[listing.tokenId]);
- collateralForMinting[listing.tokenId] = 0;
+ usdc.safeTransfer(listing.seller, collateralForMinting[_listingId]);
+ collateralForMinting[_listingId] = 0;
...
}

Support

FAQs

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

Give us feedback!