id
string
title
string
date
timestamp[ns]
author
string
severity
string
rarity
null
quality
null
categories
sequence
tags
sequence
description
string
code
string
recommendations
string
C-01
Malicious token creator can block the token `buy/sells`
2024-10-09T00:00:00
Pashov Audit Group
HIGH
null
null
[]
[]
The `_sendFees` function includes a `revert` statement, located at lines `TokenFactory#L806-809`, that could be triggered by a token creator to intentionally fail the transaction. This issue allows the token creator to control who can buy or sell tokens by strategically causing the transaction to fail, the token creator can leverage this to prevent token sales, ensuring that the token he created can be pumped to create the `Uniswap pool`. The following test demonstrates that the malicious creator can cause the `buyWithReferral` call to be reverted:
File: TokenFactory.sol ```solidity 490: function sellWithReferral( 491: address erc20Address, 492: uint256 tokenAmountToSell, 493: uint256 minEthReceivedAfterFees, 494: address referral 495: ) external nonReentrant validToken(erc20Address) { ... 536: // send fees 537: _sendFees(erc20Address, protocolFee, creatorFee, referralFee, referral); ... ``` File: TokenFactory.sol ```solidity 806: (bool creatorFeeSuccess,) = creatorFeeRecipients[erc20Address].call{value: creatorFee, gas: 100_000}(""); 807: if (!creatorFeeSuccess) { 808: revert TokenFactory_CreatorFeeTransferFailed(); 809: } ``` // File: TokenFactoryForkTest_BuyAndSell.t.sol ```solidity function test_buyMaliciousCreatorDOS() public { string memory name = "TestToken"; string memory symbol = "TT"; uint256 initialBuyerBalance = 10 ether; // Malicious creator contract MaliciousCreator customCreatorFeeRecipient = new MaliciousCreator(); // 1. Token creation using the `malicious creator` contract vm.startPrank(buyer); address newTokenAddress = factory.initializeToken(name, symbol, address(customCreatorFeeRecipient)); vm.deal(buyer, initialBuyerBalance); // 2. Malicious creator can block purchases vm.expectRevert(bytes4(keccak256("TokenFactory_CreatorFeeTransferFailed()"))); factory.buyWithReferral{value: 10 ether}(newTokenAddress, 1e7 ether, address(0)); vm.stopPrank(); } contract MaliciousCreator { receive() external payable { // custom revert revert(); } } ```
**OPTION 1:** The `TokenFactory::_sendFees` function should be modified so that it does not revert when the `creatorFee` transfer fails: ```solidity (bool creatorFeeSuccess,) = creatorFeeRecipients[erc20Address].call{value: creatorFee, gas: 100_000}(""); if (!creatorFeeSuccess) { emit CreatorFeeTransferFailed(erc20Address, creatorFee); } ``` **OPTION 2:** Consider having a mapping for each creator and the tokenAddress, so that if such an attack happens, the protocol can single out the malicious creator and set his creatorFee to zero, without impacting the other creators. Since there is already a mapping of creatorFeeRecipients[ERC20Token] to the creator, recommend changing the mapping to point to a struct, with the creator and the creator fees.

No dataset card yet

New: Create and edit this dataset card directly on the website!

Contribute a Dataset Card
Downloads last month
8
Add dataset card