Original title: "Popular Science | Catch the Universal Runaway Robot in the Dark Forest of Ethereum"
Original Source: Ethereum Enthusiast
The beasts in the dark forest of Ethereum are rampant, this is not sensational. These preemptive robots can find potential profit margins by analyzing the calls of contracts, even if these calls and contracts are things they have never seen before and know nothing about.
In view of the fact that most people don’t know enough about rush robots, we will analyze The ubiquity of running robots. We managed to “capture” some generic front-running trading bots and analyze their behavior. We studied the efficiency of these bots and the probability of getting frontrunned deals. We also tested different ways to defend against front-running trading bots.
Generally speaking, a frontrunning transaction is to insert another transaction into execution before a known future transaction occurs First in the queue.
A simple example is the trading process of the exchange. Assuming someone wants to buy a large amount of ETH on Uniswap (enough to cause the price of ETH to rise), one way to make a profit is to buy ETH before the price rises, and sell ETH after the large-scale buying transaction drives the price of ETH up .
In addition to this example, frontrunning other transactions may also bring huge profits, such as liquidation, purchase of rare NFT (non-fungible tokens), or simple user error. [The extractable value of a transaction or a group of transactions is the miner’s extractable value (MEV)]
In Ethereum In fact, to preempt a transaction can be achieved by providing a slightly higher gas price than the target transaction, incentivizing miners to rank their own transactions (rather than the target transaction) at the front when building blocks. Transactions with high Gas prices will be executed first. Therefore, if two transactions that want to profit from the same transaction contract call are packaged into the same block, only the transaction that is ranked first can successfully arbitrage.
Dan Robinson and Georgios Konstantopoulos mentioned a value extraction in "Ethereum is a Dark Forest", where $12,000 fell into the clutches of a "predator". This predator is so powerful that it can track arbitrage transactions in the Ethereum transaction pool and profit by preempting this transaction.
Dark Forest Tale sounds so "scary" that it is unbelievable at first reading. We do have reason to suspect the existence of this predator. How can you withdraw funds from a platform like Uniswap that is heavily monitored by bots? Has Uniswap become a "regular" arbitrageur?
Our in-depth analysis earlier this year proved otherwise. This is no ordinary robot. As far as we can tell, it successfully invoked contract functions that had never been invoked before, and also managed to withdraw funds even though the original transaction was obfuscated by the proxy smart contract.
This should at least alarm us. Being able to monitor the transactions in the transaction pool is equivalent to having a big killer. It is therefore disconcerting that some service providers are starting to openly offer a "dark pool" trading layer.
This kind of exclusive transaction service will not use services like Infura, or even run a private node, it The transaction will be sent directly to the miner, and the transaction will not be propagated to other nodes in the network, so as to protect the transaction from being discovered by predators.
Samczun et al took the same approach and successfully extracted $9.6 million from a buggy contract . It's not hard to imagine miners also starting to run front-running trading bots, while only providing secure access to those users who pay a premium.
Different from other parts of Ethereum (e.g. smart contracts that can be tested in a development environment or a testnet) , these bots only run on the Ethereum mainnet. For these bots, other than initial experiments, frontrunning testnet transactions is not profitable and is not very interesting. Also, they don't need to follow the rules like everyone else because their logic is hidden.
We don't know under what circumstances these frontrunners will stop. So, in a way, tracking these predators is like hunting for rare animals. We don't want to find all front-running trading bots, here are just a few general types of bots.
To make sure that the snappers we capture are "true" generic snapchats, we need to set A special trap. The trick is to create a new contract using the SHA256 hash of a secret string and deposit some funds inside the contract. Only those who provide the secret string can withdraw the funds locked in the contract. Once someone sends a withdrawal transaction, the funds are sent directly to the sender of the transaction.
The idea is to send a "decoy" transaction providing the correct secret string and see if anyone will Copy this string, and send yourself a transaction containing this string to withdraw funds from the contract. If someone can withdraw the funds before the decoy transaction, it means that someone can analyze the decoy transaction in the exchange pool, copy its relevant content, and send the transaction providing this content.
Interestingly, they will give a contract they have never seen before a contract they have never seen before , to withdraw funds - this is the real universal front-runner.
The most important part of this experiment is understanding how the universal frontrunner works. However, if someone builds a money-making machine, it is impossible to share it on Github. Therefore, we can only observe the behavior of the predator and reverse engineer it.
There are usually two components required to build a general purpose front runner. The first component is an Ethereum account with or without a smart wallet agent that can send modified transactions. The second component is the "backend", the brains of the entire operation, which usually happens off-chain. The operator can use some technology to check each transaction in the transaction pool, parse the transaction, replace the parameters of the transaction (for example, the transaction caller), and judge whether the transaction is profitable.

-The processing flow of the front-running trading robot-
A rational bot will not try to preempt a trade where the transaction fee exceeds the potential profit. Transaction fees can be high, especially if gas prices are high. Therefore, we expect that at least some profit will be required to lure bots into the bait.
Furthermore, there are many transactions in the transaction pool and time is of the essence in order to analyze each transaction. It takes an average of 12 seconds to mine an Ethereum block. If a transaction pays a high enough gas price, frontrunners must quickly analyze and replace that transaction before the next block is mined.
This process has a certain probability. It is possible that after a transaction is broadcast, the block containing the transaction is mined immediately, and the robot has no time to analyze the transaction and broadcast the front-running transaction.
Considering various factors, we tested ways to get bots hooked.
Our contract (bait) had an initial balance of 0.035 ETH, which was worth about $20 at the time. The money is awarded to anyone who can provide the correct preimage of the hash stored in that contract. In order to take the funds and lure the predator, another account (the withdrawer) will try to get the money by providing the correct preimage.
To make sure our trap works, we first call the decoy contract using the withdrawer's account. On the first try, with a relatively high gas price (set by the ethers framework), we managed to get the funds back in the decoy contract.
This may be because margins are too low to lure predators, or because deals are poached quickly out, the predator has no time to react. Obviously, this is not an ideal outcome, because the goal is to hook the predator.
This time, we succeeded. This transaction waited about 3 minutes before being mined, ultimately failing to get back the funds in the decoy contract. After reviewing the contract's internal transactions, we found that the funds had been taken by someone else.
This front-running transaction used 25.000001111 Gwei (0.000001111Gwei more than us), and our transaction are packed into the same block.
Since we have successfully captured A robot (and paid a little for it), we can find something interesting. First, this frontrunning transaction shows that the robot does not directly call the contract. Instead of copying the withdrawer's transaction and sending it through an account it owns, it sends the transaction to the proxy smart contract, which acts as a smart wallet to execute the transaction.
Now, we can trace the transaction address of this robot before and after, and see how many transactions it has successfully robbed Trading and how it works.
![]()
- The robot is using its own proxy contract-- blockquote>
After decompiling this proxy contract, we found that it mainly has two functions:
One is the "withdrawal" function: it sends all the funds in the contract to the operator of the contract. Another function is responsible for receiving parameters: the contract to call, a parameter list, and a pass-value parameter.
With the withdrawal function, the proxy contract can act as the operator’s smart wallet. In addition to being able to execute calls to external functions, the proxy contract can also ensure that the balance at the beginning of the transaction is not lower than the balance at the end of the transaction, otherwise it will be restored, thereby avoiding potential losses caused by calling unknown contracts (excluding gas fees of course ).
Using Dune Analytics, we found that this bot has been " Great feats."
If this robot always uses the same proxy contract and sends addresses to make transactions, we estimate that this robot will earn a total of Around 17 ETH.
- All revenues drawn by the robot since its operation (in ETH )-
Round 3: How smart is the front-running trading robot?
Now that we are sure that the bot exists, we want to test whether we can obfuscate our call via a second contract, so that it succeeds Get back the funds in the decoy contract. The second contract is a proxy contract that will call a function to take funds from the decoy contract. (The contract also has a "retrieve" function that allows us to retrieve funds.)
We deploy a ProxyTaker contract, and call the function to try to take our funds. Due to the high cost of withdrawing funds using the proxy contract, we increased the funds in the decoy contract to 0.055 ETH. Sure enough, our deal was snapped up by another bot right away.
We were even more impressed with this early start. Not only was the bot able to detect our withdrawal transaction, it actually recognized that this transaction came from an internal call from a completely different contract! And it did it in a very short time. Our transaction was successfully mined in just a few seconds (as was this bot's transaction).
The identity of this robot is also quite interesting. The contract of this robot is mainly controlled by the account shown in the picture below. The account posted a comment on Etherscan reminiscent of a campaign by white hat hackers attempting to take user funds from a vulnerable Bancor smart contract.
- Comments from bot operator account (source: etherscan)- blockquote>
Given that this bot is behaving in the same pattern as the previous one (calling a proxy contract from account A, sending funds to account B) and twice The situation of the preemption incident is similar. We have reason to suspect that this robot also launched a preemption against the white hat hackers during the rescue activities of the white hat hackers.
This robot is much more complicated than the last one. It does not only focus on ETH, but also executes other different arbitrage transactions.
Judging by the balance of the account from which the funds were taken, the bot was far more successful. Currently, its account balance holds about 300 ETH. We can also estimate the bot’s earnings by all the funds flowing into and out of the proxy contract address, totaling about 900 ETH. This is only a rough estimate, as the account may have traded unrelated to the front-running trade. (Click here to view all profitable trades of this robot.)
Final round: Successfully withdraw funds
< br>
To make this challenge even more interesting, we once again tried obfuscating calls, this time using OwnedTaker, a proxy contract that only we can use.
The setup this time is similar to the third round. We deposit 0.05 ETH into the decoy contract. The funds are also returned to us through the transaction instead of staying in the contract.
On the first attempt, the transaction sent to the OwnedTaker contract was mined after about 1 minute, We successfully retrieved the funds in the decoy contract.
We repeated the experiment again. This time, we recharged 0.06 ETH into the bait contract, which is the largest bait in previous experiments, to rule out the possibility that the snatching robot would not take the bait because the bait is too small.
We also keep the gas price low on purpose. This transaction waited for about 7 minutes, but still successfully retrieved the decoy.
Using an Owned proxy contract that can only be used by the owner to forward transactions effectively prevents robots from parsing data and running away trade.
-Successfully retrieved funds-
It may be due to the fact that only the contract owner can execute the call, or the fact that the funds are sent to a different address than the calling contract, we have successfully avoided the robbery. Run trading bots.
These robots are likely programmed to prioritize self-preservation. After all, when they call an unknown contract, that contract has the potential to execute arbitrary code. Therefore, we can reasonably assume that they will choose to avoid unnecessary risk or transaction fee losses when profits cannot be guaranteed.
So, did we win?
It depends on how you look at it. We use a new contract, and only we know the secret string that controls the contract. Apparently, the two front-running bots we captured detect all trades in the trade pool. Judging by the profits they make, they are really good at it.
Why did we successfully resist the attack of the jump-starting robot in the last experiment?
It's hard to say. Maybe it's because bots don't want to risk communicating with an authenticated contract, or because they don't expect funds to be transferred to another address. That doesn't mean that this method is immune to all frontrunners. More likely, there are more sophisticated bots lurking in the trading pool that don't bother to take risks for such small profits.
Conclusion
Through this In this experiment, we have proved that the general-purpose preemptive robot not only exists, but also has a high degree of intelligence.
Of course, we know that this experiment is not complete, and we cannot draw authoritative conclusions. Many other types of robots have vastly different trigger mechanisms and modes of operation. Factors such as potential profit, communication patterns, and minimum complexity (such as gas caps) can also affect how these bots operate.
However, we believe our work provides a proof of concept and further reveals the Operation mode.
The scary thing is that if someone calls a contract that can generate income and anyone can call it, even if this contract Very complex, and very likely to be preempted by robots.
So understanding these robots and how they work is critical so we can build safer systems. Projects such as Flashbots attempt to achieve this by democratizing MEV (miner extractable yield) extraction and making it a public resource. We hope this study will be helpful.
If you have come across such bots, or are working on more complex obfuscation techniques, please feel free to contact us . Your experience can help us better understand these types of bots and build a safer cryptocurrency community.
Thanks to Tal Be'ery, Omer Shlomovitz, Oded Leiba, Dan Robinson, et al for reviewing this article.
Original text link
Welcome to join the official BlockBeats community:
Telegram Subscription Group: https://t.me/theblockbeats
Telegram Discussion Group: https://t.me/BlockBeats_App
Official Twitter Account: https://twitter.com/BlockBeatsAsia