Introduction to SUAVE & MEVM

category
Cryptography
date
Dec 13, 2023
slug
introduction-to-suave-and-mevm
type
Post
lang
en
status
Published
Auther: tomo
We’ll skip the basic description of MEV here; if you want to know more about MEV here. This article is mainly about writing code using MEVM, so as far as SUAVE is concerned, we will only explain the background behind SUAVE and an overview of SUAVE.
notion image

Background of SUAVE

About 90% of the current Ethreum block construction is done using an open source middleware called MEV-Boost, which is divided into Block Builder that constructs blocks and Block Proposer that proposes blocks. This provided an environment in which validators could outsource the building of blocks to third-party builders and anyone could become a builder. Auctions among the builders made it possible to build higher-value blocks.
For more information about MEV-Boost, please refer to the official documentation.
However, on the other hand, the centralization of the Builder becomes a problem due to the exclusive order flow and the fact that the company operating the Builder also operates Searcher at the same time to build its own supply chain. The centralization of the Builder could have a significant impact on Ethereum’s censorship resistance, for example.
For more information on Builder centralization, please refer to this article. Flashbots has announced SUAVE (the Single Unified Auction for Value Expression), a protocol for decentralized block building.

What is SUAVE?

notion image
SUAVE is a blockchain, but unlike other general-purpose chains, it has decoupled the mempool and builder portions from the existing chain and replaced them with a highly specialized plug-and-play mempool and distributed Block Builder network with highly specialized plug-and-play mempool and distributed Block Builder to replace them.
SUAVE’s architecture has three major components
  1. The Universal Preference Environment: The Universal Preference Environment is dedicated to the representation and settlement of Preferences, and aggregates the Preferences of users and Searchers of all participating chains in one place (in simple terms, it can be described as a Shared mempool). A Preference is a message signed to express a user’s specific goal, such as “I have an asset called X, I want Y, and I want to pay with Z”.
  1. Optimal Execution Market: Refers to the network of special parties, called Executors, who compete to provide SUAVE’s mempool with the best execution for the user’s Preference. This market recognizes the economic value of order flow and aims to be a decentralized place where users, wallets, and other actors that generate order flow can maximize profits from their transactions.
  1. Decentralized Block Building: A decentralized network for builders that accesses encrypted preferences from users and builds them as partial or full blocks.
notion image
SUAVE is still in its early stages, with the first stage, Rigil, being launched. In the future, secure computation using TEE (SGX) is also planned to be introduced.

Introducing MEVM

notion image
This is an enhanced version of EVM with new precompiles for MEV use cases. It offers MEV supply chain primitives as precompiles to help build various block constructs on SUAVE (such as PROF) and the creation of Order Flow Auctions.
It is believed that this improvement contributes to the decentralization of the MEV supply chain by allowing the programming of centralized infrastructures such as Relay, using smart contracts on the blockchain. Applications created using SUAVE (MEVM) are referred to as SUAPP.
notion image

Confidential Data Store

The Confidential Data Store stores SUAPP’s confidential data (L1 transactions, EIP-712 signatures, userOps, private keys, etc).
The Confidential Data Store has four main functions.
  1. Confidential Data Input: Users send Confidential Data to SUAPP via Confidential Compute Requests (CCR). * CCRs are user requests to SUAVE that include Confidential Data.
  1. Confidential Data Transfer: When a Kettle successfully completes a CCR, the results are broadcast to other Kettles using a dedicated transport protocol. * Kettle is the main actor in the SUAVE network that accepts and processes CCRs and maintains the SUAVE chain.
  1. Data Modeling: The Confidential Data Store employs key-value storage and supports a variety of types.Transaction, EIP-712 signature, userOpsBundlePartial block or Full block
  1. Access Control: To achieve privacy, only contracts with appropriate permissions, called peekers, are allowed to retrieve and store data.

Precompile

Precompile is implemented to handle Confidential Data Store and other calculations that would be expensive in solidity.
Here are some typical examples.
ConfidentialInputs: Function to receive Inputs provided during CCR.
ConfidentialStore: Store Confidential data.
ConfidentialRetrieve: Retrieve data from the Confidential store.
NewBid: Initialize the Bid in the Confidential Store. * Bid” here does not mean a bid, but just an identifier of data. It is a remnant from the early days of development.
FetchBids: Find all bids related to the specified decryption conditions.

Examples

Order flow auction

The first example is an Order flow auction SUAPP based on MEV-Share.
The repository is here.
  1. send the first transaction (newOrder())
  1. Submit the backrun transaction (newMatch())
  1. Merge the first transaction with the backrun transaction (Bid) (newMatch())
  1. Send the merged transaction to the Builder (emitMatchBidAndHint())
As you can see from this flow, this sample is programmed from the user / Searcher to passing the Bundle to the Builder, so this code does not build the block. And I will explain the part of this code where Precompile is used in particular.
newOrder()
This gets the bundleData, which is the Confidential data sent by the user, as introduced in the Precompile earlier. This bundleData contains the user’s transaction. The part of the script that actually sends the data is here.
This precompile builds the block containing the bundle and runs its simulation. The output returns the gas price of the block.
This precompile interprets the bundle and extracts hints such as “To” address and calldata. * Hint are information that the Searcher provides to the Matchmaker to match the user’s transaction with the bundle.
This precompile initializes the Bid as described above.
This Precompile stores the Confidential data as described above. In this case, bundleData is stored. The bid.id is the identifier of the Bid initialized with newBid() one above.
emitMatchBidAndHint()
This precompile combines the user’s transactions and backruns and returns an encoded MEV-Share Bundle. The bidId here refers to the Id of the Bid merged by newMatch().
Finally, this Precompile sends the Bundle created by Suave.fillMevShareBundle()to Relayer.

PEPC-REP

This is a project utilizing MEVM submitted at ETH Global Istanbul in — November.
  • The repository is here
The general flow of this project is as follows. Limited to where MEVM is concerned.
  1. multiple searchers send a Bundle containing transactions of swap (this time using Uniswap V4)
  1. sort the Bundle by volume order of transactions
  1. build a block based on the sorted Bundle
  1. send the block to Relay
I will then explain the part of this code in which Precompile is used in particular.
doBuild()
This Precompile builds a block of Ethereum based on the specified BidIds. The construction is done according to the order of the BidIds. In this case, they are ordered by volume of transactions, and the blocks are built in that order.
buildAndEmit()
Submit the given builderBid to MEV-boost Relay. In this case, the block built with doBuild()will be submitted to Relay.
In addition to the example shown here, there are other sample codes available.

How to run

There are two ways to run SUAVE: locally or by using a test net.
Local
Here we will show you how to run SUAVE on Docker.
  1. clone the repository
2. start SUAVE
3. run test transaction
If the result looks like this, it is successful.
notion image
Testnet
For testnet, you can run it by adding the following network in hardhat or foundry.
  • ChainId: 16813125

How to deploy and execute contract

We recommend using the Go SDK to deploy and execute contracts. The documentation also introduces Typescript, but it doesn’t work. The actual code to deploy and send transactions looks like this.
We also recommend using this file for easier handling.
The above file can be utilized to deploy contracts and send transactions more easily.
In the following, we will only share the differences between Local and Testnet.
Local
When Local is used, the RPC of the node must be set to http://localhost:8585
It is actually written here.
Testnet
The RPC of the node must be set to https//rpc.rigil.suave.flashbots.net when Testnet. Also, you need to set the Private key and the address of the node separately.

SUAVE and Interop

We have described the basic handling of MEVMs, but here I would like to discuss them in the context of Interoperability, which is of personal interest to me.
For example, if we treat SUAVE as a shared mempool (so-called Intents and Preferences), the user sends his/her signature to SUAVE, and thus, as a user, he/she is sending to a single network and does not need to be aware of the chain. This is recently called Chain Abstraction.
Some may wonder if SUAVE can play the role of not only a shared mempool but also a shared sequencer, especially between Layer 2 networks, by also constructing the blocks (this is the first time this has been done). (This is linked to the first two roles of plug-and-play mempool and distributed Block Builder as a description of SUAVE). 
Will SUAVE replace Shared sequencers such as Espresso? The answer is no. SUAVE and existing Shared sequencers each have their own ProCon. And the two can be combined for more powerful Interoperability.

Suave

Pro
  • When using SUAVE, block atomic (inclusion) cannot be guaranteed
  • SUAVE is only up to building the block, so there is no guarantee that it will be accepted (indicating that it is not a Proposer).
Con
However, it knows what state the block will be in if it is accepted.

Shared sequencer

Pro
  • Guarantees atomic inclusion (not execution) of the block itself.
Con
  • Shared sequencer cannot know the contents of transactions
  • If all transactions are successful, execution is atomic, but it is almost impossible to achieve atomic excution in the presence of smart contract-based transactions that are not simple deposit/withdrawal transactions (= atomic inclusion has little or no benefit)

SUAVE and Shared sequencer combination

If SUAVE can build a block for cross-rollup, and if Shared sequencer can guarantee atomic inclusion of that block, the completeness of atomic execution will be enhanced.
SUAVE guarantees the atomic inclusion of the two rollup blocks and what state they would be in if executed simultaneously, and the shared sequencer guarantees that the two rollup blocks are both included. This would allow PBS in L2.
notion image
This idea has yet to take shape, so if you are interested, let’s discuss it!

Reference


© Titania Research 2024