“We took the first deep look at MEV and released our findings through MEV-Explore, a public dashboard and live MEV transactions explorer. After scraping the Ethereum blockchain starting from the first block of 2020, weβve classified more than 1.3M MEV transactions and found a total of at least $708M worth of Extracted MEV since Jan 1st 2020, as well as $12.6M wasted gas fees on failed MEV transactions, equivalent to 6,234 Ethereum blocks of wasted blockspace.”
To understand MEV, we need to understand how does miner pick up txns.
Miner Extractable Value (MEV), where blockchain miners are able to extract profits at the expense of users by arbitrarily reordering, including, or excluding transactions within a block. Miners can determine the order of when transactions are processed on the blockchain and exploit that power to their advantage.
The Flash Boys 2.0 paper coined the term "miner extractable value" (MEV)
Front Running is a way to manipulate txns sequences by peeping the mempool. And the front runners can initiate a same transaction with higher gas fee to benefit themselves.
An epic story to read and understand more about Front Running in general.
Sandwich Bot Attack is a technique, which usually follows a similar course:
Bad Sandwich: DeFi Trader 'Poisons' Front-Running Miners for $250K Profit. Wrecking sandwich traders for fun and profit.
Back Running is similar to Front Running, but vice versa. A good article to read is The fastest draw on the Blockchain: Ethereum Backrunning
Now start to build MEV and Get π€π€π€
1st, set up your own Node by using Geth
2nd, peek the mempool ...
βββ, I am kidding. It's kinda bad.
Why? π€
Official: Flashbots is a research and development organization working on mitigating the negative externalities of current MEV extraction techniques and avoiding the existential risks MEV could cause to state-rich blockchains like Ethereum.
Plain: We can't fix MEV, then we work with it. To enable a permisionless, transparent and fair ecosystem for MEV extraction.
A miner may profit from it by accepting MEV bundles either via direct block.coinbase payments, or with extra transactions that pay the block's coinbase
Guarantee | PGA | Dark-txPool | MEV-Geth |
---|---|---|---|
Permissionless | β | β | β |
Efficient | β | β | β |
Pre-trade privacy | β | β | β |
Failed trade privacy | β | β | β |
Complete privacy | β | β | β |
Finality | β | β | β |
Searcher is a term describing Etherem bot operators / users looking for fast, risk controlled or frontrunning protected bundled-txn execution via Flashbots MEV-Relay with out disclosing txns info on mempool by sending enough GAS or brbing miners to send $ETH to coinbase via smart contract::
block.coinbase.transfer(_ethAmountToCoinbase);
A research hub for MEV, tackling and uncovering questions relevant to the short, medium and long-term future of the ecosystem.
Blockchain is a very adversarial env. There are lots of phishing sites and impersonators try to steal your private keys. One of my community member got phished and exposed his private key. All Ethers / ERC20 Tokens have been transfered out immediately. However, he still has 2000 sushi vested in the farming pool. How can we save him from desperate?
A simple Flashbots "searcher" for submitting a transaction from an executor account, but paying for the transaction from a sponsor account. This is accomplished by submitting a Flashbots transaction bundle, with the first "sponsor" transaction paying the "executor" wallet in ETH, followed by a series of executor transactions that spend this newly received ETH on gas fees.
We have 3 seperate accounts. One account is hacked account, another is sponsor account (who is gonna provide gas), last is the account the erc20 token will be transfered in.
Left (Hacked Account) with no $ETH, Middle (Sponsor Account) and Right is to recieve the 5000 TTT from Hacked Account
Connect to Testnet, prepare for wallets and setup TransferERC20 action
const walletRelay = new Wallet(FLASHBOTS_RELAY_SIGNING_KEY)
// ======= UNCOMMENT FOR GOERLI ==========
const provider = new providers.InfuraProvider(5, process.env.INFURA_API_KEY || '');
const flashbotsProvider = await FlashbotsBundleProvider.create(provider, walletRelay,
'https://relay-goerli.epheph.com/');
// ======= UNCOMMENT FOR GOERLI ==========
const walletExecutor = new Wallet(PRIVATE_KEY_EXECUTOR);
const walletSponsor = new Wallet(PRIVATE_KEY_SPONSOR);
const block = await provider.getBlock("latest")
// ======= UNCOMMENT FOR ERC20 TRANSFER ==========
const tokenAddress = "0xA766A59AA95Be7B06726650233cAEa39122204bd";
const engine: Base = new TransferERC20(provider, walletExecutor.address, RECIPIENT, tokenAddress);
Build the txn bundle, the first txn is to sponsor the second txn. Second tx is to transfer Erc20
const bundleTransactions: Array = [{
transaction: {
to: walletExecutor.address,
gasPrice: gasPrice,
value: gasEstimateTotal.mul(gasPrice),
gasLimit: 121000,
},
signer: walletSponsor
},
...sponsoredTransactions.map((transaction, txNumber) => {
return {
transaction: {
...transaction,
gasPrice: gasPrice,
gasLimit: gasEstimates[txNumber],
},
signer: walletExecutor,
}
})]
const signedBundle = await flashbotsProvider.signBundle(bundleTransactions)
Simulation and send bundle!
provider.on('block', async (blockNumber) => {
const simulatedGasPrice = await checkSimulation(flashbotsProvider, signedBundle);
const targetBlockNumber = blockNumber + BLOCKS_IN_FUTURE;
const bundleResponse = await flashbotsProvider.sendBundle(bundleTransactions, targetBlockNumber);
if ('error' in bundleResponse) {
throw new Error(bundleResponse.error.message)
}
const bundleResolution = await bundleResponse.wait()
if (bundleResolution === FlashbotsBundleResolution.BundleIncluded) {
console.log(`Congrats, included in ${targetBlockNumber}`)
process.exit(0)
} else if (bundleResolution === FlashbotsBundleResolution.BlockPassedWithoutInclusion) {
console.log(`Not included in ${targetBlockNumber}`)
} else if (bundleResolution === FlashbotsBundleResolution.AccountNonceTooHigh) {
console.log("Nonce too high, bailing")
process.exit(1)
}
})
Hopefully this can help my friend to save his lost assets ... πππ
Chainlink is developing Fair Sequencing Services (FSS)βan MEV solution that uses a decentralized oracle network to fairly order transactions sent to an on-chain smart contract. By separating the ability to order transactions from the ability to produce blocks, malicious value extraction such as frontrunning can be prevented through predefined ordering policies.
FSS is still under development, shall give a in-depth look once it's into mature state.
Chainlink