Pieces Protocol

First Flight #32
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: high
Invalid

A Sell Order with 0 price can be submitted.

Summary

Function sellErc20 of contract TokenDivider.sol accepts 0 as price.

Vulnerability Details

Function sellErc20 of contract TokenDivider.sol has not validation on price. A sell order can be published using price 0. Such sell order should be invalidated by doing a check. There is no way to cancel sell order in the contract. Hence invalid order will stay in the order queue unless buy order is placed with 0 price.

Following is the POC showing the vulnerability. Paste this code in unit test - TokenDividerTest.t.sol and run the test.

function testSellUsingZeroPrice() public {
uint256 PRICE = 0; // Price of ERC20 Tokens
vm.startPrank(USER);
// Step 1 - User Locks NFT and get ERC tokens
erc721Mock.approve(address(tokenDivider), TOKEN_ID);
tokenDivider.divideNft(address(erc721Mock), TOKEN_ID, AMOUNT);
ERC20Mock erc20Mock = ERC20Mock(
tokenDivider.getErc20InfoFromNft(address(erc721Mock)).erc20Address
);
erc20Mock.approve(address(tokenDivider), AMOUNT);
// Step 2 - User tries to sell ERC tokens but enters price as 0. No error is thrown
tokenDivider.sellErc20(address(erc721Mock), PRICE, AMOUNT);
vm.stopPrank();
}

Impact

Validation must be done to prevent user from adding an invalid order. There is no way to cancel sell order in the contract. Hence invalid order will stay in the order queue unless buy order is placed with 0 price. This will be equivalent of transferring erc20 for free ( there is already a function for that - transferErcToken) but with wastage of gas.

Tools Used

Foundry

Recommendations

A validation on price must be done in the function sellErc20. Price must be non-zero for sell order to publish.

Updates

Lead Judging Commences

fishy Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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