Beginner FriendlyFoundryGameFi
100 EXP
View results
Submission Details
Severity: medium
Invalid

function listMartenitsaForSale must be "external producers"

Summary

As we want that only the producers can call this function, there is no restriction to anyone preventing from calling function listMartenitsaForSale

Vulnerability Details

Anyone can call this function. But, The function includes a require statement that checks if the caller is a producer. Since the caller in the test is not a producer, the require statement will cause the transaction to revert.

      @>   function listMartenitsaForSale(uint256 tokenId, uint256 price) external {
             require(
                msg.sender == martenitsaToken.ownerOf(tokenId),
             "You do not own this token"
              );
              require(
              martenitsaToken.isProducer(msg.sender),
             "You are not a producer!"
            );
            require(price > 0, "Price must be greater than zero");

           Listing memory newListing = Listing({
           tokenId: tokenId,
          seller: msg.sender,
           price: price,
                    design: martenitsaToken.getDesign(tokenId),
                    forSale: true
                });

                tokenIdToListing[tokenId] = newListing;
                emit MartenitsaListed(tokenId, msg.sender, price);
                }

Impact

Medium

PoC

function testListMartenitsaForSaleEveryone() public {
// Attempt to list a martenitsa for sale by a non-producer
martenitsaToken.createMartenitsa("bracelet");
martenitsaToken.approve(address(marketplace), 0);
marketplace.listMartenitsaForSale(0, 1 ether);
// Verify that the martenitsa is listed for sale
assertTrue(marketplace.tokenIdToListing(0).tokenId == 0, "Token Id should match");
assertTrue(marketplace.tokenIdToListing(0).seller == address(this), "Seller address should match");
assertTrue(marketplace.tokenIdToListing(0).price == 1 ether, "Price should match");
assertTrue(keccak256(bytes(marketplace.tokenIdToListing(0).design)) == keccak256(bytes("bracelet")), "Design should match");
assertTrue(marketplace.tokenIdToListing(0).forSale == true, "Martenitsa should be listed for sale");
In the test, we're attempting to call the listMartenitsaForSale function from an address that is not a producer. The function includes a require statement that checks if the caller is a producer. Since the caller in the test is not a producer, the require statement will cause the transaction to revert, resulting in a failed test.
This demonstrates that the function is not properly restricted to only allow producers to call it.
## Tools Used
Manual Review
## Recommendations
+ function listMartenitsaForSale(uint256 tokenId, uint256 price) external producers {
require(
msg.sender == martenitsaToken.ownerOf(tokenId),
"You do not own this token"
);
require(
martenitsaToken.isProducer(msg.sender),
"You are not a producer!"
);
require(price > 0, "Price must be greater than zero");
Listing memory newListing = Listing({
tokenId: tokenId,
seller: msg.sender,
price: price,
design: martenitsaToken.getDesign(tokenId),
forSale: true
});
tokenIdToListing[tokenId] = newListing;
emit MartenitsaListed(tokenId, msg.sender, price);
}
Updates

Lead Judging Commences

bube Lead Judge over 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.