Skip to content

Commit

Permalink
DIP003 and DIP004 (#109)
Browse files Browse the repository at this point in the history
* Begin DIP003 and DIP004

* e2e examples worth highlighting

* Completes dip003 and dip004

* change mev-blocker emoji
  • Loading branch information
andytudhope authored Apr 6, 2024
1 parent 97f8b9a commit b9216f9
Show file tree
Hide file tree
Showing 19 changed files with 1,628 additions and 875 deletions.
2 changes: 1 addition & 1 deletion docs/concepts/block-building.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ All of these functions utilize the SUAVE Execution Namespace. To understand more

Bundles are one or more transactions that are grouped together and executed in the order they are provided and are the core unit of block building. If you're unfamiliar with bundles, and want to learn more, you can read [this document](https://docs.flashbots.net/flashbots-auction/advanced/understanding-bundles).

To see how to handle bundles in your SUAPP, check out the [`suave-std` repo](https://github.com/flashbots/suave-std/pull/28).
To see how to handle bundles in your SUAPP, check out the [`SUAVE-STD` bundle protocol contract](https://github.com/flashbots/suave-std/blob/main/src/protocols/Bundle.sol).

16 changes: 4 additions & 12 deletions docs/concepts/confidential-computation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ Confidential computation enables you to handle orderflow privately and securely.

In SUAVE, we achieve this with [Kettles](/technical/specs/rigil/kettle#confidential-computation) performing compute offchain, but according to smart contracts written onchain. In this way, offchain compute is not constrained by chain consensus. The Kettles will eventually run in [TEEs](https://www.youtube.com/watch?v=ek-bu4aoh0A), which provide both **enhanced privacy** (no-one, not even the host OS, can see unencrypted data) and **integrity** (you can be sure the correct code, and only that code, is running at all times).

:::info

For practical examples of how Confidential Compute Requests (CCRs) work, please follow [**this tutorial**](/tutorials/confidential-compute-requests). The below will explain CCRs conceptually, without code.

:::

## Interface

SUAVE exposes several precompiles to help you with confidential computation. The first is a simple check, often used in `require` statements in smart contracts:
SUAVE exposes several precompiles to help you with confidential computation. The first is a simple check, often used in `require` statements:

```solidity
function isConfidential() internal view returns (bool b)
Expand All @@ -39,9 +33,9 @@ You can also consult [our technical specs](/technical/specs/rigil/kettle#confide

How to index, store, and use confidential data is left up to each SUAPP.

For example, in the [Private OFA Suapp](https://github.com/flashbots/suapp-examples/tree/main/examples/app-ofa-private), to submit a valid backrun, a searcher must include the `recordId` of the user transaction in order for the Suapp to match them. Therefore, the Suapp emits the user transaction `recordId` as a log on chain, which searchers can listen for and use to construct valid backruns.
For example, our [confidential store tutorial](/tutorials/confidential-store) demonstrates how to store a private key in the confidential store. In order to sign a transaction intended for Ethereum L1, we only store the `recordId` associated with that private key in the contract's memory, which is what ends up ends up onchain.

However, the NFTEE example demonstrates how to store a private key in the confidential store. In order to get it to sign a transaction intended for Ethereum L1, we store the `recordId` associated with that private key in the contract's memory, which ends up onchain. In this context, this is not a concern, since it's gated, so only that Suapp can access the key for signing purposes.
In the [Private OFA Suapp](https://github.com/flashbots/suapp-examples/tree/main/examples/app-ofa-private), to submit a valid backrun, a searcher must include the `recordId` of the user transaction in order for the Suapp to match them. Therefore, the Suapp emits the user transaction `recordId` as a log on chain, which searchers can listen for and use to construct valid backruns.

### Restricting Access

Expand All @@ -53,6 +47,4 @@ You need not use confidential requests in the ways which our examples illustrate
4. Whenever a restricted method is accessed, the present secret needs to be provided.
1. This is only accessible through confidential execution.

You can find Miha's implementation of [ConfidentialControl here](https://github.com/halo3mic/suave-playground/blob/9afe269ab2da983ca7314b68fcad00134712f4c0/contracts/blockad/lib/ConfidentialControl.sol), along with a [good example which illustrates its use](https://github.com/halo3mic/suave-playground/blob/9afe269ab2da983ca7314b68fcad00134712f4c0/contracts/blockad/BlockAdV2.sol).

This particular approach, and the reason it currently works in this manner, is being discussed in this [`suave-geth` issue](https://github.com/flashbots/suave-geth/issues/121).
You can find an implementation of [ConfidentialControl here](https://github.com/halo3mic/suave-playground/blob/9afe269ab2da983ca7314b68fcad00134712f4c0/contracts/blockad/lib/ConfidentialControl.sol), along with a [good example which illustrates its use](https://github.com/halo3mic/suave-playground/blob/9afe269ab2da983ca7314b68fcad00134712f4c0/contracts/blockad/BlockAdV2.sol).
4 changes: 2 additions & 2 deletions docs/concepts/confidential-data-storage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This is what these DataRecords look like in the [`suave-std` library](https://gi

## Practical Example

Consider the same [Private OFA Suapp](https://github.com/flashbots/suapp-examples/blob/main/examples/app-ofa-private/ofa-private.sol) from the previous page. The OFA contract needs to accept user transactions, store them, and emit a hint that searchers can use. It then needs to accept backruns from searchers and match those with the user transactions in storage: a task it achieves by means of the `recordId`.
Consider the [Private OFA example contract](https://github.com/flashbots/suapp-examples/blob/main/examples/app-ofa-private/ofa-private.sol). This contract needs to accept user transactions, store them, and emit a hint that searchers can use. It then needs to accept backruns from searchers and match those with the user transactions in storage: a task it achieves by means of the `recordId`.

The end-to-end flow looks like this:

Expand All @@ -47,7 +47,7 @@ bytes memory hint = Suave.extractHint(bundleData);

<div>

The contract then sets who can store and "peek" (i.e. retrieve) the data. In this case, both this Private OFA contract and the precompile contract deployed at the address `0x...43200001` are set as **allowedPeekers** and **allowedStores** (though you could have totally different addresses in these arrays in your own use case). If you consult the [`suave-std` library](https://github.com/flashbots/suave-std/blob/main/src/suavelib/Suave.sol), you'll see that the precompile deployed at that address is the `FILL_MEV_SHARE_BUNDLE`, which is what we require for this particular contract.
The contract then sets who can store and "peek" (i.e. retrieve) the data. In this case, both this Private OFA contract and the precompile contract deployed at the address `0x...43200001` are set as **allowedPeekers** and **allowedStores** (though you could have totally different addresses in these arrays in your own use case). If you consult the [`SUAVE-STD` library](https://github.com/flashbots/suave-std/blob/main/src/suavelib/Suave.sol), you'll see that the precompile deployed at that address is the `FILL_MEV_SHARE_BUNDLE`, which is what we require for this particular contract.

```solidity
address[] memory allowedList = new address[](2);
Expand Down
11 changes: 6 additions & 5 deletions docs/concepts/mev-supplychain-interface.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ The previous pages have illustrated how to:
- Build blocks for other chains
- Use confidential computation in various different ways depending on your use case
- Leverage confidential data storage to create a service that is currently run in a centralized way on a decentralized and permissionless network.
- Request data from anywhere on the IntersectionObserverEntry.

Taken together, these three broad categories of the unique SUAVE features allow you to interact with any component in the MEV supply chain. The MEV supply chain looks something like this:
Taken together, these four unique SUAVE features allow you to interact with any component in the MEV supply chain. The MEV supply chain looks something like this:

![MEV Supply Chain - Linear Version](/img/mev-supplychain.png)

Expand All @@ -22,11 +23,11 @@ Taken together, these three broad categories of the unique SUAVE features allow
function doHTTPRequest(HttpRequest memory request) internal view returns (bytes memory)
```

We've already seen in the previous tutorial, which looked at the [Private OFA Suapp](https://github.com/flashbots/suapp-examples/blob/main/examples/app-ofa-private/ofa-private.sol) example contract, how to create bundles and send them to a predefined block builder using the `submitBundleJsonRPC()` precompile.
The [Private OFA](https://github.com/flashbots/suapp-examples/blob/main/examples/app-ofa-private/ofa-private.sol) example contract demonstrates how to create bundles and send them to a predefined block builder using the `submitBundleJsonRPC()` precompile.

Similarly speaking, you can construct the whole block yourself and send it to a builder using `submitEthBlockToRelay()`. Taken together, these two precompiles allow you to interface with the **transaction**, **bundle**, and **block** aspects of the supply chain above.
You can construct the whole block yourself and send it to a builder using `submitEthBlockToRelay()`. Taken together, these two precompiles allow you to interface with the **transaction**, **bundle**, and **block** aspects of the supply chain above.

Furthermore, there is a `doHTTPRequest()` precompile, which enables Kettles to make any arbitrary http request in order to fetch information from other services they're running on different chains, or just about any other API they need to handle their off chain computation. An example of this in use can also be found in the Private OFA Suapp Example, and it looks like this:
Furthermore, the `doHTTPRequest()` precompile enables Kettles to make any arbitrary http request in order to fetch information from other services they're running on different chains, or just about any other API they need to handle their off chain computation. An example of this in use can also be found in the Private OFA Suapp Example, and it looks like this:

```solidity
function submitBundle(string memory builderUrl, bytes memory bundleData) internal view returns (bytes memory) {
Expand Down Expand Up @@ -57,6 +58,6 @@ function submitBundle(string memory builderUrl, bytes memory bundleData) interna

The Private OFA examples also illustrates how the confidential store, and the various on chain interactions in enables, may be used to interface with **every aspect** of the supply chain, right from user intents to bundles and blocks.

The below visualization demonstrate the generalized form such Suapps can take as SUAVE matures, illustrating how the OFA contract could key values into the confidential store such that a block building contract could fetch them and use them to create and emit valid blocks (this would require, among other things, extending the **allowedPeekers** we set in [the previous page](/concepts/confidential-data-storage#practical-example)):
The below visualization demonstrates the generalized form such Suapps can take as SUAVE matures, illustrating how the OFA contract could key values into the confidential store such that a block building contract could fetch them and use them to create and emit valid blocks (this would require, among other things, extending the **allowedPeekers** we [discussed here](/concepts/confidential-data-storage#practical-example)):

![OFA to Block Flow](/assets/OFA_And_Block_Flow.svg)
46 changes: 45 additions & 1 deletion docs/concepts/offchain-http.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,48 @@
---
title: Offchain HTTP Calls
description: Fetching data from the rest of the world to do more interesting things on SUAVE
---
---

# External HTTP Calls

Given that code specified in contracts on SUAVE is execued in TEEs, which can provide attestations about the code they are running, we can more securely make requests to arbitrary http endpoints to fetch data relevant to any offchain computation we are running.

The kinds of data we can fetch are **arbitrary**: it ranges from price data to ChatGPT responses, or as far afield as your imagination is willing to go.

## Practical Example

In order to understand the implications of fetching data from external sources when running secure, offchain computation in a Kettle, we encourage you to go through our [external calls tutorial](/tutorials/external-call). Essentially, we're able to query the ChatGPT completion API with a few lines of code (but this could just as easily be the Binance or Bloomberg APIs too):

```solidity
function offchain() external returns (bytes memory) {
bytes memory keyData = Suave.confidentialRetrieve(apiKeyRecord, API_KEY);
string memory apiKey = bytesToString(keyData);
ChatGPT chatgpt = new ChatGPT(apiKey);
ChatGPT.Message[] memory messages = new ChatGPT.Message[](1);
messages[0] = ChatGPT.Message(ChatGPT.Role.User, "Say hello world");
string memory data = chatgpt.complete(messages);
emit Response(data);
return abi.encodeWithSelector(this.onchain.selector);
}
```

One additional note: if you wish to create your own Foundry project with contracts that make external calls, please make sure to adjust the `foundry.toml` file to include the following (the equivalent of running `suave-geth` with the `--suave.eth.external-whitelist='*'` flag):

```bash
[profile.suave]
whitelist = ["*"]
```

## Interface

SUAVE exposes one precompile which can handle all your external call needs:

```solidity
function doHTTPRequest(HttpRequest memory request) internal returns (bytes memory)
```

You can see how this is used in everything from [EthJsonRPC](https://github.com/flashbots/suave-std/blob/main/src/protocols/EthJsonRPC.sol) (which powers patterns like [Gateway.sol](https://github.com/flashbots/suave-std/blob/main/src/Gateway.sol)), to [sending bundles to the Flashbots relay](https://github.com/flashbots/suave-std/blob/main/src/protocols/Bundle.sol), to querying [`ChatGPT.sol`](https://github.com/flashbots/suave-std/blob/main/src/protocols/ChatGPT.sol).
24 changes: 2 additions & 22 deletions docs/tools/rigil.mdx → docs/concepts/rpc-differences.mdx
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
---
title: Rigil Testnet
title: RPC Key Differences
description: All the relevant information you need to interact with Rigil
---

import RPCButton from '@site/src/components/RPCButton/index';
import List from '@site/src/components/List/List.tsx';

The [SUAVE Rigil Testnet](/technical/specs/rigil/) is live and public:

- [Block Explorer](https://explorer.rigil.suave.flashbots.net)
- [Faucet](https://faucet.rigil.suave.flashbots.net/)
- [EthStats](https://ethstats.rigil.suave.flashbots.net/)
- [Technical Docs](/technical/specs/rigil/)
- `chainId: 16813125`
- Rigil Kettle Address: `0x03493869959c866713c33669ca118e774a30a0e5`
- Localhost Kettle Address: `0xb5feafbdd752ad52afb7e1bd2e40432a485bbb7f`

We have RPC nodes you can connect to:

<RPCButton />


---

### RPC Key Differences
# RPC Key Differences

In order to keep some data in transactions confidential, SUAVE JSON-RPC extends the usual Ethereum JSOPN-RPC methods. Some methods in the `eth_` namespace are overloaded to support confidential compute requests.

Expand Down
36 changes: 18 additions & 18 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,6 @@ module.exports = {
},
],
},
{
type: 'category',
label: '🗺️ Concepts',
collapsed: false,
link: { type: 'doc', id: 'concepts/index' },
items: [
'technical/specs/rigil/mevm',
'technical/specs/rigil/precompiles',
'technical/specs/rigil/confidential-data-store',
'concepts/confidential-computation',
'concepts/block-building',
'concepts/mev-supplychain-interface'
]
},
{
type: 'category',
label: '📚 Tutorials',
Expand All @@ -40,18 +26,33 @@ module.exports = {
'tutorials/onchain-offchain',
'tutorials/confidential-store',
'tutorials/external-call',
'tutorials/build-suapp-webapp',
'tutorials/confidential-compute-requests',
'tutorials/rigil',
'tutorials/create-precompiles'
]
},
{
type: 'category',
label: '🗺️ Concepts',
collapsed: false,
link: { type: 'doc', id: 'concepts/index' },
items: [
'technical/specs/rigil/mevm',
'technical/specs/rigil/precompiles',
'concepts/confidential-computation',
'technical/specs/rigil/confidential-data-store',
'concepts/block-building',
'concepts/offchain-http',
'concepts/mev-supplychain-interface',
'concepts/rpc-differences',
]
},
{
type: 'category',
label: '🛠️ Tools',
collapsed: false,
link: { type: 'doc', id: 'tools/index' },
items: [
'tools/rigil',
'tools/community-directory',
{
type: 'category',
label: 'SUAVE-STD',
Expand All @@ -64,7 +65,6 @@ module.exports = {
}
]
},
'tools/forge',
'tools/golang-sdk',
'tools/typescript-sdk'
],
Expand Down
Loading

0 comments on commit b9216f9

Please sign in to comment.