Ethereum Asked by ceds on December 22, 2020
With frontrunning in the headlines these days due to raids on platforms like Uniswap I was wondering from a technical point of view how these guys are able to do it ? I’m still learning Ethereum with all the pros and cons, especially with subjects such as the txpool.
I’ve watched the successful bots closely and they all seem to be using smart contracts. My initial guess was that everything was done on-chain, however, after learning that smart contracts cannot listen to events of other smart contracts, I’m not so sure that is the case anymore. How can a smart contract trigger a trade if it is not notified by some event of doing so ?
So all that I can think of is that an off-chain bot is going through every single pending transaction in the txpool and when it detects what it’s looking for, it calls the on-chain smart contract to execute the trade.
Is my thinking correct on this ?
My second question would be is there a way to stop them?
I did not mark a correct answer below as both answers add a lot of value and completed the picture in my opinion
You're thinking is heading in the right direction. A contract cannot monitor event logs so that activity needs to be off-chain. Using off-chain processes to identify opportunities has advantages - computing capacity, off-chain inputs, maintenance/optimization of the algorithms, cost, etc.
Many (most) attack strategies require transaction atomicity. That is, all the parts of the transaction must succeed entirely or the entire transaction must fail.
Consider a simplistic front-running arbitrage that wants to buy something from somewhere at a price that is lower than the price where it wants to sell it elsewhere. If this is done by signing two transactions and the buy succeeds but the sell fails then the arbitrageur will end up with an asset they don't want and a likely loss on the trade.
A contract on the chain can perform both trades from a single input. That is, the arbitrageur can sign a single transaction with instructions to the contract that will handle both trades. That transaction is atomic - it succeeds completely or fails entirely.
Hope it helps.
Answered by Rob Hitchens on December 22, 2020
The bots are continuously listening to both onchain changes (events, transactions, etc) and offchain changes (for example, price changes).
Whenever they find that the time is right, they send a transaction to one of their already-deployed smart contracts, or possibly even deploy a new smart contract.
In both cases, the desired set of operations is performed atomically within the transaction.
Answered by goodvibration on December 22, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP