# MEV on Berachain notes How to do MEV on Berachain? MEV quick run down: https://docs.merkle.io/private-pool/what-is-mev Berachain tech stacks include: * CometBFT (consensus layer) * beacon-kit (Cosmos adapter) * Etherum execution client (execution layer) MEV is done through searching transaction opportunities and executing that opportunities. All of this is done through transaction ordering logic at mempool, and be the first block submitter. ## Where is Berachain mempool? ![beacon-kit.drawio](https://hackmd.io/_uploads/HJrDNNqtyx.png) All three components above contain mempool. My initial assumption is that there could be multiple mempools working together. Further dig into Berachain's CometBFT coniguration reveals that mempool option is `nop`, meaning that it will disable mempool at CometBFT and delegate that mempool task to Cosmos app - level. Cosmos adapter service beacon-kit uses ABCI++ `PrepareProposal` and `ProcessProposal` to emulate mempool handling at app-level. Further inspection into Tx proposal reveals that it returns a Tx byte array of two [`{block, sidecars}`](https://github.com/berachain/beacon-kit/blob/main/consensus/cometbft/service/prepare_proposal.go#L84). This is weird, unlike other Cosmos tx data format. Within `{block, sidecars}`, transactions are contained in `ExecutionPayload`. `ExecutionPayload` is fetched from calling geth `engine_getPayloadV3`. This indicate that payload is actually built in etherum execution client side. There is no mempool in Cosmos app level. Further inspection into geth brings me to this exact location where payload is built and filled with transactions. Full flow is available in the diagram above. * https://github.com/ethereum/go-ethereum/blob/master/eth/catalyst/api.go#L450 * transactions are filled into newly built payload (this is the location of mempool, within geth): https://github.com/ethereum/go-ethereum/blob/master/miner/worker.go#L427 Conclusion: berachain mempool is in geth, others are disabled ## Private mempool * MEV opportunity execution relies a lot on being the first to find opportunities and timely inclusion of transactions. Trying to compete by raising priority fee is not a sustainable practice as costs will become too large when competition is firece. Setting up a private mempool with strong validator backing ensures majority of block production rights for member MEV opportunities. * Overview of private mempool: https://docs.merkle.io/private-pool/what-is-private-mempool * Operating a private mempool example: https://github.com/berachain/mev-geth?tab=readme-ov-file#operating-a-private-network * Big players that can potentially onboard Berachain: * https://docs.flashbots.net/ * https://docs.merkle.io/ 1. Next actions to assess private mempool situations * if not existed -> work and engage with validators to set up private mempool * if foundation intend to onboard big private mempools or work on this directly -> approach and keep contacts with all major private mempools * if there is private mempool with majority -> partnership with that private mempool 2. Next actions to write MEV logic (assumed interacting with the private mempool) * write logic for searchers * write logic for Backrun strategy