Pieces Protocol

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

Lack of Relation Between Price and Amount in sellErc20 Function

Summary

The sellErc20 function in Solidity enables a user to create a sell order for a specified amount of ERC20 tokens pegged to a specific NFT address

Vulnerability Details

In the current implementation of the sellErc20 function, there's an important oversight: the function does not establish a direct relationship between the price and the amount of ERC20 tokens being sold. This missing link can lead to ambiguity and potential misinterpretation when users create sell orders.

s_userToSellOrders[msg.sender].push(
SellOrder({
seller: msg.sender,
erc20Address: tokenInfo.erc20Address,
price: price,
amount: amount
})
);

The priceis The price of all the tokens to sell, but in code there is not logic for that:

And the priceis not dependend from amount.

Impact

Is possible to buy eg. 100 tokens with 1 wei.

Tools Used

manual review

Recommendations

Please add logic:

function sellErc20(address nftPegged, uint256 pricePerToken, uint256 amount) external {
if (nftPegged == address(0)) {
revert TokenDivider\_\_NftAddressIsZero();
}
if (amount == 0) {
revert TokenDivider__AmountCantBeZero();
}
ERC20Info memory tokenInfo = nftToErc20Info[nftPegged];
if (balances[msg.sender][tokenInfo.erc20Address] < amount) {
revert TokenDivider__InsuficientBalance();
}
balances[msg.sender][tokenInfo.erc20Address] -= amount;
//@audit modification
uint256 totalPrice = pricePerToken * amount;
s_userToSellOrders[msg.sender].push(
SellOrder({
seller: msg.sender,
erc20Address: tokenInfo.erc20Address,
price: totalPrice,
amount: amount
})
);
emit OrderPublished(amount, msg.sender, nftPegged);
IERC20(tokenInfo.erc20Address).transferFrom(msg.sender, address(this), amount);

}

Updates

Lead Judging Commences

fishy Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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