The "Predator" in Ethereum's dark forest
Editor's Note: This article comes fromCrypto Valley Live (ID: cryptovalley)Editor's Note: This article comes from
Crypto Valley Live (ID: cryptovalley)
, Author: Alex MenUskin, translation: Sherrie, reprinted with authorization by Odaily.
Ethereum's dark forest monsters are no joke. These frontrunning bots can analyze smart contract calls and functions that they have never used in a smart contract for potential profit.
Given the general lack of understanding of these robots, we embarked on a safari to learn more about the situation and see how common they are. We managed to "capture" some generic front-end bots and analyze their behavior. We looked at their efficiency and the likelihood of a transaction being "hunted". We also tested different ways to dodge them.
secondary title
What is Frontrunning?
A simple example of frontrunning is swap bidding. Suppose someone intends to buy a large amount of ETH on Uniswap, which is enough to drive up the price of ETH. One way to benefit from this situation is to trade before buying large amounts of ETH while the price remains low. Then, after the price surge, sell ETH for a profit.
Beyond this arbitrage example, Frontrunning for many other transactions could also be valuable, including liquidations, purchases of rare NFTs, or simple user errors. (A value extracted from a transaction or sequence of transactions is called MEV).
On Ethereum, frontrunning is achieved by bidding slightly higher transaction fees in transactions, incentivizing miners to sequence earlier when building blocks, with higher paying transactions executed first. Therefore, if two transactions that profit from the same contract call are placed in the same block, only the first transaction will make a profit.
secondary title
Behavior
Dan Robinson and Georgios Konstantopoulos described an attempted frontrunning in a blog post on "ETH is a Dark Forest," in which $12,000 fell into the clutches of a sophisticated "predator." A Predator is so ahead that it can track down any valuable transaction in the Ethereum transaction pool and reap the rewards through Frontrunning.
The story of "Dark Forest" is so "scary" that it is hard to believe at first. Indeed, we have reason to doubt the existence of such "predators". How to withdraw funds from Uniswap, an arbitrage platform closely monitored by a large number of robots? Could it be a "regular" arbitrageur?
Earlier this year, our in-depth analysis proved otherwise. This is no ordinary robot. It successfully called a contract function which, to our knowledge, has never been called before. The funds were siphoned despite obfuscating the transaction via proxy smart contracts.
That's pretty worrying, to say the least. The ability to monitor any transaction in a transaction pool is a super powerful weapon. Worryingly, some services are starting to publicly offer a "dark pool" trading layer.
The "dark pool" transaction layer does not use services like Infura, or even private nodes, but sends transactions directly to miners with the promise not to propagate them to the rest of the network, keeping them safe from predators snooping.
Samczun and co. used a similar method when trying to extract $9.6 million from a vulnerable contract. It’s not hard to imagine miners starting to use Frontrunning’s bots themselves, only offering safe access to those who pay a premium.
Unlike other elements of ethereum, such as smart contracts that can be tested in a development environment or on a testnet, these bots only exist on the ethereum mainnet. Other than some initial trials, it doesn't make financial sense for them to try and frontrunning testnet transactions. Also, they don't have to play by the same rules as everyone because their logic is hidden.
To ensure that the Frontrunners we catch are "real" generic Frontrunners, we need a unique trap. The trap is a newly created contract, initiated by a SHA256 hashed secret string, with some funds available for acquisition. Locked funds can only be withdrawn if this secret is provided, and the funds will be sent directly to the sender of the withdrawal transaction.
The idea is to send a "decoy" transaction providing the correct secret, see if anyone tries to replicate it, and then provide the secret themselves, thereby gaining usable funds. If someone gets the funds before the decoy transaction, it means that someone can analyze the transaction while it is still in the transaction pool l, copy its relevant content, and provide the secret itself.
Interestingly, they'll offer a secret they didn't know before, a contract they've never seen before, to get the money.
secondary title
How does the average frontrunner work?
An important part of this experiment is understanding how the Frontrunner works. However, if someone builds a money-making machine, it probably won't be shared on Github. Therefore, we can only observe and reverse engineer the behavior of criminals.
There are usually two parts to building a general purpose frontrunner. The first component is an Ethereum account to which modified transactions can be sent, with or without a smart wallet agent. The second is the "backend", the brains of the operation, which mostly happens off-chain. The operator uses some techniques to examine each transaction in the pool, parse it, replace its parameters (e.g. tx caller), and determine if it has any profit.
In addition, time is also critical due to the need to analyze each transaction (of which there are many) in the transaction pool. It takes an average of 12 seconds to mine an Ethereum block. If the transaction fee for this transaction is high enough, it must be analyzed and replaced quickly enough before the next block arrives.
This is a probabilistic process, and it is possible to mine a block as soon as a transaction is broadcast, giving bots no time to successfully analyze it and broadcast a running transaction.
With these considerations and some thought, we tested how long it took the robot to grab the bait."secondary title"Our contract (awarder) had an initial balance of 0.035 ETH, which was worth about $20 at the time. Those funds are available to anyone who provides the correct preimage to the hash stored in the contract. In order to obtain funds and act as a trigger for predators, a separate account (the obtainer) will attempt to obtain funds by providing the appropriate
Reverse image
Like to withdraw funds.
The first round: call the contract directly
To make sure our baseline trap works, we first use the getter account to call the contract. On the first try, with relatively high transaction fees (set by the ETH framework), we managed to get our funds back.
This could be due to margins being too low to attract predators, or because deals are being mined too quickly for them to react. Obviously, this is not what we want, because capturing the predator is our goal.
secondary title
In this round, we solved the problems we had before. We increased the potential profit and lowered the transaction fee so that transactions are not mined too quickly, giving bots time to discover it. The contract also appended 0.04 ETH (an increase of 0.005 from before).
This time, we succeeded. The transaction waited about 3 minutes before being mined, gaining no value from the contract. According to the internal transaction of the contract, we can find that the funds flow to others.
The current transaction uses 25.000001111 Gwei (.000001111 Gwei is higher than what we are using) and was mined in the same block as the attempted "extract".
secondary title
Cultivate followers
Now that we've managed to find a bot (for some cost), we can draw some interesting insights. First, transactions indicate that calls to contracts are not executed directly. Instead of just copying the transaction and sending it blindly from an owned account, the bot passes it through a proxy smart contract that acts as a smart wallet to execute those transactions.
We can now track previous and future transaction addresses to see how successful the bot is and how it operates.
Decompiled contracts have two main functions:
Through this function, the proxy contract acts as a smart wallet for the operator. In addition to the ability to perform calls to external functions, it also guarantees that the balance at the beginning of the transaction is at least as large as the balance at the end of the transaction, otherwise it can be restored, thereby avoiding possible loss of funds when calling unknown contracts (except for transaction fees, of course. ).
Using Dune Analytics, we can see how successful the bots have been since May 2018!
Assuming this particular bot always uses the same proxy and sending address to issue transactions, we can estimate its earnings to total about 17 ETH (~$10K at the time of writing).
secondary title
Round Three: How Smart Are They?
Now that we are convinced that the bot is attacking us, we want to test whether we can extract the bait. (There is also a "receive" function in the contract, which can return the money to us).
We deployed the ProxyTaker contract and called the appropriate function in an attempt to withdraw our funds. Due to the slightly higher cost of receiving funds through a proxy, the granter contract has a slightly higher amount of 0.055 ETH. Lo and behold, our deal was immediately snapped up by another bot.
This time it was even more impressive. Not only was the bot able to detect our withdrawal transaction, but it identified it from an internal call, from a completely different contract! This feat was accomplished in record time. Our withdrawal transactions were mined within seconds (as did the bot).
Given the same pattern of behavior of the bot (calling an agent from account A and transferring funds to account B) and the proximity of the incident, it is reasonable to assume that the bot was also performing a general frontrunning operation against white hackers in this incident.
This robot is much more complex than the previous one. It not only focuses on ETH, but also conducts various arbitrage transactions.
It's also far more successful in terms of the account balances from which it collects funds. Currently, the balance is around 300 ETH (~$180k at time of writing). We can also subtract all inflows and outflows from the contract address to estimate its yield, totaling ~900 ETH. This is only a rough estimate, as the account may have made transactions unrelated to its front-running activity. (Below is a list of all bot trades with positive values).
secondary title
Final round: successful extraction
To make this challenge a little more interesting, we did another obfuscation attempt, this time using a proxy contract that only we can use, an OwnedTaker.
The setup is similar to the third round. Grant contract appended 0.05 ETH. The funds are also transferred back to us in the same transaction instead of remaining in the contract.
On the first attempt, the transaction to the OwnedTaker contract took about 1 minute to mine, and we managed to withdraw the funds.
The experiment was repeated, this time refilling the giver contract with 0.06 ETH, the highest payout we've used so far, to make sure the lower payout wasn't the reason for the lack of Frontrunning attempts.
The requirement that only the contract owner may be allowed to execute the call, or the fact that the funds are sent to a different destination than the calling contract, helps avoid front-running attempts.
So, have we won?
Bots are likely to think about self-preservation first; after all, they are calling an unknown contract, which may execute arbitrary code. It stands to reason that they will avoid unnecessary risk or loss of transaction fees if profits are not guaranteed.
secondary title
Why were we able to resist (Frontrunning) last time?
in conclusion
Hard to say. It could be that the bot didn't take the risk of communicating with the authenticated contract, or the fact that the funds were transferred to another address was accidental. Of course, that doesn't mean it's a way to avoid Frontrunners entirely. Most likely, there are more sophisticated bots lurking in the trading pool l that are simply not willing to risk such a small profit.
secondary title
in conclusion
In this short experiment, we were able to show that general-purpose front-running bots exist, and that they are highly sophisticated.
Of course, we know our experiments are far from complete or definitive. There are many other bots with vastly different triggers and modes of operation. Factors such as potential upside, communication patterns, and minimal complexity (e.g., transaction fee limits) may affect how they work.
However, we believe our work provides a proof-of-concept and sheds further light on how these general-purpose front-end robots operate.
If you have come across any of these bots, or are looking into more sophisticated obfuscation techniques, please feel free to contact us. By sharing your experiences, we will better understand these bots and build a safer crypto community for all of us.
appendix
Thanks to Tal Be'ery, Omer Shlomovitz, Oded Leiba, Dan Robinson and others for their help with this article
secondary title
appendix


