Skip to content

Commit

Permalink
Adds Mateusz name changes, Ferran's new docker devenv testing stuff, …
Browse files Browse the repository at this point in the history
…works on MEVM page
  • Loading branch information
andytudhope committed Sep 14, 2023
1 parent 66992d6 commit e55b0bb
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 157 deletions.
5 changes: 2 additions & 3 deletions docs/how-to/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Initially, we will support applications that require:

In this section, you'll find all of our recipes.

The [tutorials](/tutorials/index) are intended to get you from 0 to 1. These "how to guides" will help you get from 1 to wherever else you want to go. They do not provide history and background explanation: they show you how to do interesting and delicious things.
The tutorials are intended to get you from 0 to 1. These "how to guides" will help you get from 1 to wherever else you want to go. They do not provide history and background explanation: they show you how to do interesting and delicious things.

1. [How to setup SUAVE](/how-to/setup-suave) and participate in the network.
2. [How to use SUAVE CLI](/how-to/use-suave-cli), deploy contracts, and interact with them.
1. [How to setup SUAVE](/how-to/setup-suave), test your node, and participate in the network.
66 changes: 31 additions & 35 deletions docs/how-to/setup-suave.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A SUAVE node is really two nodes in a trenchcoat, both participating in the same

### What you need

1. Install Docker. You can find general directions [here](https://docs.docker.com/get-docker/).
1. Install and start Docker. You can find general directions [here](https://docs.docker.com/get-docker/).
1. If you're running Ubuntu or Debian, we recommend [this specific guide](https://docs.docker.com/engine/install/ubuntu/#installation-methods).
2. Make sure you have `docker-compose` installed too. The should just happen when you install Docker.
1. Check with `docker-compose version` (Docker Engine) or `docker compose version` (Docker Desktop).
Expand All @@ -36,20 +36,43 @@ git clone https://github.com/flashbots/suave-geth.git
```
2. Get to the right place in the repo:
```bash
cd suave-geth/suave/devenv/
cd suave-geth/
```
3. Run SUAVE:
3. Run SUAVE (depending on your docker setup, you may need to run this as `sudo`):
```bash
docker-compose up -d
make devnet-up
```

### Optional testing

4. If you'd like to test your node by deploying a contract and sending it some transactions, you can do so easily by running:
```bash
go run suave/devenv/cmd/main.go
```
You should see something like the below printed to your terminal (addresses, txns, and ids will differ):
```bash
suave-geth$ go run suave/devenv/cmd/main.go
Step 0: Create and fund test accounts
- Funded test account: 0x66d5a8D6B34329c0639071275b3d78D29e11EbC6 (100000000)
Step 1: Deploy mev-share contract
- Mev share contract deployed: 0x8f21Fdd6B4f4CacD33151777A46c122797c8BF17
Step 2: Send bid
- Bid sent at txn: 0xb49debcdead2b306d6ab6282b88fdad7c8d6a33d87df34b79f56d141eae7c08a
- Bid id: 30bbc65298f24e67aaf5c95bf5f0686c
Step 3: Send backrun
- Backrun sent at txn: 0xcf7880e61e94aaab48c60655c321716ecab6edab752586448b0412e93a969889
- Backrun bid id: db98b83d02694fc2b13c042ad22c233
```

### What just happened

Both SUAVE nodes are now running as a daemon process (because of the `-d` flag in the `docker-compose` command). Well done!
Both the MEVM instance and the Chain instance are now running in separate containers, which means your local SUAVE dev environment is ready to go. If you followed through with Step 4 above, you've also deployed a contract in your local environment and sent some transactions to it.

1. Read more about [confidential computation](/reference/confidential-computation/index) and the [APIs we've built to enable it](/reference/confidential-computation/apis).
2. Dig deeper in the [architecture of the MEVM](/reference/MEVM#architecture).
3. Browse a full list of the [precompiles this gives you access to in any smart contract](/reference/precompiles).
1. Learn more about the contract you deployed and what those transactions are in our [worked examples](/reference/builder-solidity/worked-examples/mev-share).
2. Read more about [confidential computation](/reference/confidential-computation/index) and the [APIs we've built to enable it](/reference/confidential-computation/apis).
3. Dig deeper in the [architecture of the MEVM](/reference/MEVM#architecture).
4. Browse a full list of the [precompiles](/reference/precompiles) this gives you access to in [builder solidity](/reference/builder-solidity/index).
5. If you'd like to examine the Go code responsible for deploying contracts and sending transactions, you can do so [here].

### Common problems

Expand All @@ -71,33 +94,6 @@ Both SUAVE nodes are now running as a daemon process (because of the `-d` flag i
</div>
</details>

<details>
<summary>2. Using Docker Desktop</summary>
<div>
<div>
If you're using Docker Desktop, it's likely that you need to use <code>docker compose up -d</code> (without the <code>-</code>).
</div>
</div>
</details>

<details>
<summary>3. Older OS won't shut down</summary>
<div>
<div>
<div>
Depending on your OS version and the way you installed Docker, you might have issues switching your new SUAVE node off again. If so:<br/>
<code>
sudo killall containerd-shim
</code><br/><br/>
Now you should be able to run:<br/>
<code>
sudo docker-compose down
</code>
</div>
</div>
</div>
</details>

## Build it yourself

The `docker-compose` version above sets up SUAVE using simple defaults. If you'd like to run the binaries yourself and customise what is happening, read on.
Expand Down
90 changes: 0 additions & 90 deletions docs/how-to/use-suave-cli.mdx

This file was deleted.

61 changes: 40 additions & 21 deletions docs/reference/MEVM.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ keywords:
- go-ethereum
---

# MEVM
import AlignItems from "@site/src/components/AlignItems/AlignItems.tsx"

The MEVM gives anyone the power to program MEV applications in builder solidity: an expressive, familiar, and flexible programming environment for smart contract mechanisms.
# MEVM

The MEVM seeks to offer every primitive of the MEV supply chain as a precompile, allowing any centralized MEV infrastructure to be transformed into a smart contract running on SUAVE.

Expand All @@ -20,13 +20,29 @@ If you'd prefer to learn by running it yourself, please follow [this guide](/how

## Architecture

Our goal is to give you what you need to write more expressive smart contracts and conduct confidential computation, such that you can build any kind of MEV application.
Our goal is to give you what you need to write more expressive [builder solidity](/reference/builder-solidity/index) and conduct [confidential computation](/reference/confidential-computation/index), such that you can build any kind of MEV application.

If you've read the two links above, you'll know that the basic flow of a transaction on SUAVE looks like this:

<AlignItems horizontal="center" vertical="center" sideMargin={0}>
<div>
<img alt="Fairier Transformers" src={require('/static/img/basic_flow_mevshare.png').default} />
</div>
</AlignItems>

We'll be explaing how we achieve the above "Confidential MEVM execution" for the rest of this page.

For this part, if you remember the below formula, you're good to go:
At a high level, we have adapted the `eth_sendRawTransaction` RPC method to accept an additional field, called `confidential_data`. Users place signed transactions from other blockchains in this field. They encrypt the field for specific SUAVE node(s), and specify some builder solidity contract on SUAVE, which holds the logic for what to do with their encrypted inputs.

**SuaveExecutionBackend 🤝 EVM = MEVM**
When a SUAVE node receives a `RawTransaction`, it checks whether there are confidential inputs. If there are, we call this a `confidentialComputeRequest` and the MEVM kicks into action. It enters the function being called in the builder solidity contract and, using a `view` function and the `confidentalInputs` [precompile](/reference/precompiles), gets the data it needs about the user's transaction on another blockchain. The MEVM computes some result and stores the relevant data locally, in its `confidentialDataStore`. This does not permute state, as we're only using a `view` function fetch data and then doing the computation locally, in the MEVM.

Here is a visual overview of what the above actually looks like:
Computation complete, the MEVM places what we call the `confidentialComputeResult` in the original `RawTransaction` it received, which it then propagates to the public mempool. The `confidentialComputeResult` is really a callback to another function, which does permute state and often emits some kind of event, the logs of which hold data required by others parties without revealing the original inputs. We encourage you to read about [mev-share on SUAVE](/reference/builder-solidity/worked-examples/mev-share) for a practical example.

For now, it is good enough that you understand that all our adaptations to the EVM serve the goal of confidential computation, as outlined above. These changes can be summed up in a very simple formula:

> **SuaveExecutionBackend 🤝 EVM = MEVM**
Here is a visual overview of what that actually means in practice:

```mermaid
graph TB
Expand Down Expand Up @@ -59,35 +75,38 @@ graph TB
classDef lightgreen fill:#b3c69f,stroke:#444,stroke-width:2px, color:#333;
```

What do you get from the **SuaveExecutionBackend** that we've married to the EVM through the new runtime? In a nutshell: [3 new API endpoints](/reference/confidential-computation/apis):
In words: the EVM is made up of a whole bunch of different parts. THose numbered `1` through `7` exist in the vanilla EVM we all know and love. Parts `8` through `13` are what we have added (or adapted in the case of the `interpreter`) in order to enable confidential computation.

What do you get from the [SuaveExecutionBackend](https://github.com/flashbots/suave-geth/blob/main/core/vm/suave.go) that we've married to the EVM through the new runtime? In a nutshell: [3 new API endpoints](/reference/confidential-computation/apis):

```go
func NewRuntimeSuaveExecutionBackend(evm *EVM, caller common.Address) *SuaveExecutionBackend {
if !evm.Config.IsOffchain {
if !evm.Config.IsConfidential {
return nil
}

return &SuaveExecutionBackend{
ConfidentialStoreBackend: evm.suaveExecutionBackend.ConfidentialStoreBackend,
MempoolBackend: evm.suaveExecutionBackend.MempoolBackend,
OffchainEthBackend: evm.suaveExecutionBackend.OffchainEthBackend,
ConfidentialEthBackend: evm.suaveExecutionBackend.ConfidentialEthBackend,
confidentialInputs: evm.suaveExecutionBackend.confidentialInputs,
callerStack: append(evm.suaveExecutionBackend.callerStack, &caller),
}
}
```

Each of these new APIs - `ConfidentialStoreBackend`, `MempoolBackend`, `OffchainEthBackend` - are available in [builder solidity](/reference/builder-solidity) through the use of [precompiles](/reference/precompiles). The precompiles also make use of `callerStack` to specify whether there is confidential computation required, and `confidentialInputs` to specify the inputs to that computation if it is required.
Each of these new APIs - `ConfidentialStoreBackend`, `MempoolBackend`, `ConfidentialEthBackend` - are available in [builder solidity](/reference/builder-solidity/index) through the use of [precompiles](/reference/precompiles). The precompiles also make use of `confidentialInputs` to specify the data relevant to confidential computation, and `callerStack` enables transaction tracing.

## Notable differences from go-ethereum

### Changes to RPC methods

1. New `IsOffchain` and `ExecutionNode` fields have been added to TransactionArgs, used in `eth_sendTransaction` and `eth_call` methods.
- If `IsOffchain` is set to true, the call will be performed confidentially, using the `ExecutionNode` passed in for constructing `OffchainTx`.
1. New `IsConfidential` and `ExecutionNode` fields are added to the TransactionArgs used in `eth_sendTransaction` and `eth_call` methods.
- If `IsConfidential` is set to true, the call will be performed as a confidential call, using the SUAVE node passed in for constructing `ConfidentialComputeRequest`.
- `SuaveTransaction` is the result of `eth_sendTransaction`.

2. New, optional `confidential_data` argument has been added to `eth_sendRawTransaction`, `eth_sendTransaction` and `eth_call` methods.
- The confidential data is made available to the EVM in the confidential mode via a precompile, but does not become a part of the eventual on-chain transaction. This enables confidential computation (like simulating a bundle, putting the data into confidential store).
2. New optional argument - `confidential_data` is added to `eth_sendRawTransaction`, `eth_sendTransaction` and `eth_call` methods.
- The confidential data is made available to the EVM in the confidential mode via a precompile, but does not become a part of the transaction that makes it to chain. This allows performing computation based on confidential data (like simulating a bundle, or putting the data into confidential store).

### SuavePrecompiledContract

Expand All @@ -96,15 +115,15 @@ We introduce a new interface [SuavePrecompiledContract](https://github.com/flash
```go
type SuavePrecompiledContract interface {
PrecompiledContract
RunOffchain(backend *SuaveExecutionBackend, input []byte) ([]byte, error)
RunConfidential(backend *SuaveExecutionBackend, input []byte) ([]byte, error)
}
```

The method `RunOffchain` is invoked during confidential execution, and the `SuaveExecutionBackend` which provides access to confidential compute APIs is passed in as input.
The method `RunConfidential` is invoked during confidential execution, and the suave execution backend which provides access to confidential APIs is passed in as input.

### SuavePrecompiledContractWrapper
### SUAVE Precompile Wrapper

We introduce [SuavePrecompiledContractWrapper](https://github.com/flashbots/suave-geth/blob/main/core/vm/suave.go) implementing the `PrecompiledContract` interface. The new structure captures the confidential compute APIs in its constructor, and passes the confidential compute APIs during the usual contract's `Run` method to a separate method: `RunOffchain`.
We introduce [SuavePrecompiledContractWrapper](https://github.com/flashbots/suave-geth/blob/main/core/vm/suave.go) implementing the `PrecompiledContract` interface. The new structure captures the confidential APIs in its constructor, and passes the confidential APIs during the usual contract's `Run` method to a separate method - `RunConfidential`.

### SuaveExecutionBackend

Expand All @@ -118,9 +137,9 @@ We introduce [SuaveExecutionBackend](https://github.com/flashbots/suave-geth/blo

The [EVM interpreter](https://github.com/flashbots/suave-geth/blob/main/core/vm/interpreter.go) is modified to enable confidential computation:

1. We introduce `IsOffchain` to the interpreter's config
2. We modify the `Run` function to accept off-chain APIs `func (in *EVMInterpreter) Run(*SuaveExecutionBackend, *Contract, []byte, bool) ([]byte, err)`
3. We modify the `Run` function to trace the caller stack
* We introduce `IsConfidential` to the interpreter's config
* We modify the `Run` function to accept confidential APIs `func (in *EVMInterpreter) Run(*SuaveExecutionBackend, *Contract, []byte, bool) ([]byte, err)`
* We modify the `Run` function to trace the caller stack

Like `eth_sendTransaction`, this method accepts an additional, optional confidential inputs argument.

Expand Down
Loading

0 comments on commit e55b0bb

Please sign in to comment.