Summary
Vulnerability Details
In the documentation of the MartenitsaMarketplace.sol
contract, there is mention of the cancelListing
function but the function is not present in the contract.
The cancelListing
function is required to be present in the contract so that the producer can cancel the listing of the Martenitsa from the marketplace.
## MartenitsaMarketplace.sol
This contract provides a marketplace where users can buy and sell martenitsa tokens, with additional functionality for making presents, collecting rewards and managing listings. All users can participate in buying and collecting rewards, but only producers can list their tokens for sale and then sell them.
- `listMartenitsaForSale`: Allows registered producers to list a martenitsa token for sale with a specified price.
- `buyMartenitsa`: Allows users to buy a listed martenitsa token and transfer funds to the seller.
- `makePresent`: Allows users to make a present of a martenitsa token they own to someone else.
- `collectReward`: Allows users to collect `HealthTokens` as a reward based on the number of `MartenitsaTokens` they own. For every 3 different `MartenitsaTokens` you receive 1 `HealthToken`.
@> - `cancelListing`: Allows sellers to cancel the listing for sale of a martenitsa token.
- `getListing`: Retrieves the characteristics of a martenitsa token listed for sale.
POC (Testing the cancelListing
function)
After Adding the cancelListing
function in the MartenitsaMarketplace.sol
contract, the producer will be able to cancel the listing of the Martenitsa from the marketplace.
we can test the cancelListing
function by adding the following code in the MartenitsaMarketplace.t.sol
contract.
function testCancelListing() public listMartenitsa {
vm.prank(chasy);
marketplace.cancelListing(0);
vm.expectRevert("Token is not listed for sale");
list = marketplace.getListing(0);
(,,,,bool forSale) = marketplace.tokenIdToListing(0);
assert(forSale == false);
}
forge test --mt testCancelListing -vvvv
Impact
Tools Used
Recommendations
+ event MartenitsaCanceled(uint256 indexed tokenId);
+ function cancelListing(uint256 tokenId) external {
+ require(msg.sender == martenitsaToken.ownerOf(tokenId), "You do not own this token");
+ require(martenitsaToken.isProducer(msg.sender), "You are not a producer!");
+ delete tokenIdToListing[tokenId];
+ emit MartenitsaCanceled(tokenId);
+ }