mirror of
https://github.com/autistic-symposium/mev-toolkit.git
synced 2025-12-15 16:28:51 -05:00
move solidity to its own repo
This commit is contained in:
parent
8c7233b677
commit
4a2138e181
23 changed files with 0 additions and 319 deletions
43
random-notes/GETH/running_a_node_geth.md
Normal file
43
random-notes/GETH/running_a_node_geth.md
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
|
||||
## Running a node in Ethereum with `geth`
|
||||
|
||||
```
|
||||
geth -help
|
||||
```
|
||||
|
||||
```
|
||||
COMMANDS:
|
||||
account Manage accounts
|
||||
attach Start an interactive JavaScript environment (connect to node)
|
||||
console Start an interactive JavaScript environment
|
||||
db Low level database operations
|
||||
dump Dump a specific block from storage
|
||||
dumpconfig Show configuration values
|
||||
dumpgenesis Dumps genesis block JSON configuration to stdout
|
||||
export Export blockchain into file
|
||||
export-preimages Export the preimage database into an RLP stream
|
||||
import Import a blockchain file
|
||||
import-preimages Import the preimage database from an RLP stream
|
||||
init Bootstrap and initialize a new genesis block
|
||||
js Execute the specified JavaScript files
|
||||
license Display license information
|
||||
makecache Generate ethash verification cache (for testing)
|
||||
makedag Generate ethash mining DAG (for testing)
|
||||
removedb Remove blockchain and state databases
|
||||
show-deprecated-flags Show flags that have been deprecated
|
||||
snapshot A set of commands based on the snapshot
|
||||
version Print version numbers
|
||||
version-check Checks (online) whether the current version suffers from any known security vulnerabilities
|
||||
wallet Manage Ethereum presale wallets
|
||||
```
|
||||
|
||||
Advanced options are:
|
||||
|
||||
```
|
||||
ETHEREUM OPTIONS
|
||||
LIGHT CLIENT OPTIONS
|
||||
DEVELOPER CHAIN OPTIONS
|
||||
ETHASH OPTIONS
|
||||
```
|
||||
|
||||
4
random-notes/MEV/arbitrage-notes.md
Normal file
4
random-notes/MEV/arbitrage-notes.md
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
## DEX arbitrage
|
||||
|
||||
* the simplest MEV opportunity: two DEXes offering a token at two different prices, someone can buy the token on the lower-priced DEX and sell it on the higher priced DEX in a single atomic transaction.
|
||||
* [TX example](https://etherscan.io/tx/0x5e1657ef0e9be9bc72efefe59a2528d0d730d478cfc9e6cdd09af9f997bb3ef4)
|
||||
32
random-notes/MEV/flashbots.md
Normal file
32
random-notes/MEV/flashbots.md
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
## Flashbots
|
||||
|
||||
* Flashbots is a research and development organization focused on mitigating the negative externalities of current MEV extraction techniques and avoiding the existential risks MEV could cause to state-rich blockchains like Ethereum.
|
||||
|
||||
* Flashbots try to move the problem to another area to prevent clogging up the Ethereum network and giving it more clarity. I works by reducing MEV's complexity by three fronts:
|
||||
- tools to inspect and quantize the impact of MEV. This helps reduce the information asymmetry and people can understand the problem and its impact better. (MEV-Inspect).
|
||||
- Democratize the extraction of MEV. The power to extract MEV exists in the hands of few people so they provide tools for everyone to start extracting MEV. (MEV-Geth)
|
||||
- Distribute the benefit of MEV. Currently, the miners and validators extract a disproportionate amount of benefits. So it’s important to redistribute these to all the participants.
|
||||
|
||||
|
||||
### The auction architecture relies on 3 parties:
|
||||
|
||||
- searcher: bots looking for access to blockspace, users frontrunning protection on their transactions, and dappas with advanced use cases
|
||||
- relay
|
||||
- miner
|
||||
|
||||
|
||||
## `mev-inspect-py`
|
||||
|
||||
Tool to inspect maximal extractable value for Ethereum: [mev-inspect-py](https://github.com/flashbots/mev-inspect-py).
|
||||
If shows: miner payments, tokens transfers and profit, swaps and arbritages.
|
||||
|
||||
#### Pre-requisites:
|
||||
|
||||
- [k8s's kind](https://kind.sigs.k8s.io/docs/user/quick-start/)
|
||||
- docker
|
||||
- [helm](https://helm.sh/docs/intro/install/)
|
||||
- an `RPC_URL`
|
||||
|
||||
## MEV-geth
|
||||
|
||||
* Software which can be run by miners to mitgate negative externalities of MEV.
|
||||
19
random-notes/MEV/flashbots_bundle.md
Normal file
19
random-notes/MEV/flashbots_bundle.md
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
## Flashbots bundle
|
||||
|
||||
Steps to access the flashbots network.
|
||||
|
||||
### Setting a Private key for identity
|
||||
|
||||
```
|
||||
python3 gen_private_key.py
|
||||
```
|
||||
|
||||
### Interacting with Flashbots
|
||||
|
||||
Flashbots runs a relay you send bundles at `relay.flashbots.net`.
|
||||
|
||||
```
|
||||
python3 create_bundle.py
|
||||
```
|
||||
|
||||
|
||||
4
random-notes/MEV/frontrunners-notes.md
Normal file
4
random-notes/MEV/frontrunners-notes.md
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
## Notes on frontrunners
|
||||
|
||||
* rather than programming complx algorithms to detect profitable MEV opportunities, some searchers run generalized frontrunners. These are bots that watch the mempool to detect profitable transactions.
|
||||
* frontrunners will copy the potentially profitable transaction's code and replace addresses with theirs. Then, they submit the modified transaction with the replaced address and a higher gas price, frontrunning the original transaction and getting the searcher's MEV.
|
||||
7
random-notes/MEV/liquidations-notes.md
Normal file
7
random-notes/MEV/liquidations-notes.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
## Liquidations
|
||||
|
||||
* Lending protocol (e.g. Aave or Maker) liquidations present a well-known MEV opportunity.
|
||||
* They work by requiring users to deposit some collateral. Users can then borrow different assets and toekns from others depending on what they need, up to a certain amount of their deposited collateral.
|
||||
* As the value of a borrower's collateral fluctuates, if the value of the borrowed assets exceeds the value of the collateral, the protcol allows anyone to liquidate the collateral (similar to margin calls in traditional finance).
|
||||
* If liquidated, the borrower usually has to pay a hefty liquidation fee, some of which goes to the liquidator (where the MEV opportunity comes in).
|
||||
* Searchers compete to parse blockchain data as fast as possible to determine which borrowers can be liquidated and be the first to submit a liquidation transaction and collect the liquidation fee.
|
||||
5
random-notes/MEV/sandwich-tranding-notes.md
Normal file
5
random-notes/MEV/sandwich-tranding-notes.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
## Notes on Sandwich trading
|
||||
|
||||
* To sandwich, a searcher will watch the mempool for large DEX trades.
|
||||
* A searcher can calculate the approximate price effect of this large trade and execute an optimal buy order immediately before the large trade, then executing a sell order immediately after the large trade (selling it for the igher price caused by the large order).
|
||||
* Sandwiching is riskier as it isn't atomic an it's prone to [salmonella attack](https://github.co/Defi-Cartel/salmonella)
|
||||
51
random-notes/MEV/terminology.md
Normal file
51
random-notes/MEV/terminology.md
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
## ☠️ Some terminology
|
||||
|
||||
<br>
|
||||
|
||||
#### Merkle tree: a type of binary tree, composed of a set of notes with a large number of leaf nodes at the bottom of the tre containing the underlying data, a set of intermediate nodes where each node is the hash of its two children, and finally a single root node, also formed from the hash of its two children, representing the top of the tree.
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
#### 𝕄𝕒𝕩𝕚𝕞𝕒𝕝 𝕖𝕩𝕥𝕣𝕒𝕔𝕥𝕒𝕓𝕝𝕖 𝕧𝕒𝕝𝕦𝕖 (MEV, formerly "miner" in the context of Proof of Work) refers to the maximum value that can be extracted from block production in excess of the standard block reward and gas fees by censoring and/or changing the order of transactions in a block.
|
||||
|
||||
<br>
|
||||
|
||||
#### The 𝕞𝕖𝕞𝕡𝕠𝕠𝕝 is the set of pending, unconfirmed transactions in the EVM... when someone sends a transaction in the blockchain, there is a delay between the time when the transaction is broadcasted to the network and when it is actually mined into a block. During this period, transactions sit in a pending transaction pool, the mempool, where contents are visible to everyone.
|
||||
|
||||
<br>
|
||||
|
||||
#### 𝔽𝕣𝕠𝕟𝕥𝕣𝕦𝕟𝕟𝕚𝕟𝕘, also known as Priority Gas Auctions (PGAs), happens when a miner steals a profitable opportunity (such as arbitrage) for themselves by sending the same transaction with a higher gas price. For example, a transaction A is broadcasted with a higher gas price than an already pending transaction B so that A gets mined before B (e.g., to snatch a Uniswap price arbitrage trade to rebalance a pool).
|
||||
|
||||
<br>
|
||||
|
||||
#### 𝔹𝕒𝕔𝕜𝕣𝕦𝕟𝕟𝕚𝕟𝕘 happens when a transaction A is broadcasted with a slightly lower gas price than already pending transaction B so that A gets mined right after B in the same block. (eg. to execute a DyDx liquidation after a price oracle update that triggers a DyDx loan to go under the required collateralization ratio).
|
||||
|
||||
<br>
|
||||
|
||||
#### 𝕊𝕒𝕟𝕕𝕨𝕚𝕔𝕙𝕚𝕟𝕘 is the profiting off slippage in liquidity pools by buying and selling before and after large transactions posted in the mempool.
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
#### 𝔻𝔼𝕏 𝕒𝕣𝕓𝕚𝕥𝕣𝕒𝕘𝕖 happens when two DEXes are offering a token at two different prices and one can buy the token on the lower-priced DEX and sell it on the higher-priced DEX.
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
#### 𝕃𝕚𝕢𝕦𝕚𝕕𝕒𝕥𝕚𝕠𝕟𝕤 happens when the value of a borrowed asset exceeds the collateral and anyone can liquidate the collateral and collect the liquidation fee for themselves.
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
#### Long Tail MEV encompasses all other forms of MEV not described here. Long Tail MEV describes niche, arcane, undiscovered MEV often realized through interacting with lesser known protocols, event based strategies, or unorthodox economic mechanisms.
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
44
random-notes/MEV/the_mempool_and_mev.md
Normal file
44
random-notes/MEV/the_mempool_and_mev.md
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
## The Mempool and MEV
|
||||
|
||||
|
||||
## Ethereum's Mempool (The Dark Forest)
|
||||
|
||||
**"Whenever you make a transaction in the Ethereum network (you sign the transaction), you have to wait until it to be confirmed in the blockchain. During that period, it sits in the memory pool. Anyone can listen to these transactions, and their details, while they are there, and even modify them. If someone pays a higher gas price, their modification will be included a block first."**
|
||||
|
||||
---
|
||||
|
||||
## MEVs
|
||||
|
||||
*"Miner extractable value (MEV) is a measure devised to study consensus security by modeling the profit a miner (or validator, sequencer, or other privileged protocol actor) can make through their ability to arbitrarily include, exclude, or re-order transactions from the blocks they produce. MEV includes both ‘conventional’ profits from transaction fees and block rewards, and ‘unconventional’ profits from transaction reordering, transaction insertion, and transaction censorship within the block a miner is producing."* - Alex Obadia
|
||||
|
||||
* MEV exists in places where there is high complexity which requires significant knowledge of smart contracts to understand.
|
||||
* ~90% arbitrage
|
||||
|
||||
## Arbritage bots
|
||||
|
||||
* Monitor pending transactions and attempt to exploit profitabe opportunities.
|
||||
* Usually loo for specific types of transactions in the mempool, such as DEX trade or an oracle update
|
||||
|
||||
|
||||
|
||||
## To find Extracted MEV:
|
||||
|
||||
1. look at each Ethereum's transaction trace
|
||||
2. parse it and go through the token transfers
|
||||
3. calculate the starting balance of the sender address and its ending balance (taking into account proxy addresses)
|
||||
|
||||
```
|
||||
Extracted MEV = Successful MEV transactions + Successful MEV transactions gas fees + Failed MEV transactions gas fees
|
||||
|
||||
|
||||
Failed MEV transactions gas fees = Reverted MEV transactions gas fees + Checked MEV transactions gas fees
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
---
|
||||
|
||||
## References
|
||||
|
||||
* [Frontrunning MEV crisis](https://writings.flashbots.net/writings/frontrunning-mev-crisis/)
|
||||
11
random-notes/README.md
Normal file
11
random-notes/README.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
## Notes on MEV
|
||||
|
||||
<br>
|
||||
|
||||
### How the blockchain works 101
|
||||
|
||||
* Each block in the blockchain contains a list of transactions in a particular order, enconding a sequence of updates to the blockchain sate (world state).
|
||||
* Anyone can broadcast a transaction to the network, which means that the transaction is public. A broadcast is a request. In order for that request to be carried out, someone must place the transaction in a block and add the block to the blockchain.
|
||||
* Anyone can listen for transactions being broadcast and gather them into a list. In order to a turn a list into a block, it needs to be validated. Validation creats a mathematical (cryptographic) proof that the state changes are consistent.
|
||||
* In a proof-of-work blockchain, block producers are miners. In a proof-of-stake blockchain, they are validators.
|
||||
* The act of converting a transaction into a block is called *settlement*. The process of block production is called *settlement layer* or *consensus layer*.
|
||||
43
random-notes/ethereum/README.md
Normal file
43
random-notes/ethereum/README.md
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
## Ethereum notes
|
||||
|
||||
|
||||
### Basics
|
||||
|
||||
* the existence of a Turing-complete programming language means that arbitrary contracts can be created for any transaction type or application.
|
||||
|
||||
* a state is made up of objects called "accounts", with each account hacing a 20-byte address and state transitions being direct transfers of value and information between accounts.
|
||||
|
||||
* an Ethereum account contains four fields:
|
||||
* the nounce: a coutner used to make sure each transaction can only be processed once
|
||||
* the account's current ether balance
|
||||
* the account's contract code
|
||||
* the account's storage
|
||||
|
||||
* there are two type of accounts: externally owned accounts (controlled by private keys) and contract accounts (controlled by their contract code)
|
||||
|
||||
* a transaction refers to the signed data package that stores a message to be sent from an externally owned account. It contains:
|
||||
* the recipient of the message
|
||||
* a signature identifying the sender
|
||||
* the amount of ether to transfer from the sender to the recipient
|
||||
* an optional data field
|
||||
* STARTGAS, representing the maxium numner of computation steps the transaction is allowed to take
|
||||
* GASPRICE, representing the fee the sender pays per computation step
|
||||
|
||||
* contracts can send "messages" to other contracts, which are virtual objects that are never serialized and exist only in the Ethereum execution environment. It contains:
|
||||
* the sender of the message (implicit)
|
||||
* the recipient of the message
|
||||
* the amount of ether tot transfer alongside the message
|
||||
* an optional data field
|
||||
* STARTGAS
|
||||
|
||||
* a message is like a transaction, except it is produced by a contract and not an external actor. A message is produced when a cotnract currently executing code executes the CALL opcode.
|
||||
|
||||
### Code execution
|
||||
|
||||
* the code in Ethereum contracts is written in a low-level, stack-based bytecode language, referred as the EVM.
|
||||
|
||||
* The operations have access to three types of space in which to store data:
|
||||
* the stack, a last-in-first-out container to which values can be pushed and popped
|
||||
* memory, an infinite expandable byte array
|
||||
* contract's long-term storage, a key/value store (persist long term)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue