Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suave #4

Merged
merged 60 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
61c540e
remove CHANGELOG.md symlink
zeroXbrock Oct 23, 2023
9b816dc
add transactionRequest test, update SuaveTransactionRequest definition
zeroXbrock Oct 23, 2023
671a79a
add tx formatter
zeroXbrock Oct 24, 2023
17b0fde
disable anvil calls in vitest setup (run with SKIP_GLOBAL_SETUP=true)
zeroXbrock Oct 25, 2023
1e7a94b
add test:e2e in playgrounds/bun/
zeroXbrock Oct 25, 2023
6f693e3
update chain id, add local devnet config
zeroXbrock Oct 25, 2023
97c36e1
working SuaveTransactionRequest impl
zeroXbrock Oct 25, 2023
71a6576
infer isConfidential from confidentialInputs
zeroXbrock Oct 25, 2023
7b61d6d
infer tx type in SuaveTransactionRequest
zeroXbrock Oct 25, 2023
92fa84b
add getTransaction[Receipt] to playground test
zeroXbrock Oct 26, 2023
af71ab8
revise SuaveTransaction formatter/type
zeroXbrock Oct 26, 2023
9c0d032
harden SuaveTransaction[Request] formatter/type
zeroXbrock Oct 27, 2023
b5cfd0e
add SuaveTransaction serialization constructs
zeroXbrock Oct 28, 2023
0de1318
refactor type defs; make rpc types generic, deserialized types restri…
zeroXbrock Oct 30, 2023
84c8072
experimental serializer
zeroXbrock Oct 31, 2023
51f382e
fix rlp signature bugs; working CCR transactionRequests
zeroXbrock Oct 31, 2023
7e51c28
push lint fixes
zeroXbrock Oct 31, 2023
b2238c3
cleanup, remove debug console logs
zeroXbrock Oct 31, 2023
bff6fbd
compartmentalize wallet action overrides with new fn: getSuaveWallet
zeroXbrock Oct 31, 2023
4f1c223
support all tx types
zeroXbrock Oct 31, 2023
951d93c
remove bad 'from' addrs
zeroXbrock Oct 31, 2023
b6f70bc
lint
zeroXbrock Oct 31, 2023
e762187
fix bad imports
zeroXbrock Oct 31, 2023
ac62568
make privatekey optional in getSuaveWallet
zeroXbrock Oct 31, 2023
39bfd43
lint
zeroXbrock Oct 31, 2023
91655de
fix some type-related bugs + formatter tests
zeroXbrock Nov 1, 2023
e259e77
remove junk comments
zeroXbrock Nov 3, 2023
0198218
add block formatter tests
zeroXbrock Nov 3, 2023
eb893b2
remove unused fields in block formatter
zeroXbrock Nov 3, 2023
d54b843
add tx receipt formatter test
zeroXbrock Nov 3, 2023
5de428b
clean up duplicate logic in sendTransaction override, add examples in…
zeroXbrock Nov 4, 2023
85b287d
wait for fund tx to land in playground example
zeroXbrock Nov 4, 2023
b0fb4a4
lint
zeroXbrock Nov 4, 2023
d94a0f4
re-enable anvil backend for tests
zeroXbrock Nov 7, 2023
1aafb9c
cleanup junk comments, remove unused arg
zeroXbrock Nov 8, 2023
5bed2ca
stricter input requirement for serializeConfidentialComputeRequest
zeroXbrock Nov 8, 2023
a9ef4c8
add links to spec in doc-comments
zeroXbrock Nov 8, 2023
62a37ec
use idiomatic errors in tx serializers
zeroXbrock Nov 8, 2023
e8324ca
add parsers in parsers.ts, tests
zeroXbrock Nov 8, 2023
ee6fa6f
add parseTransactionSuave; covers all supported tx types; +test
zeroXbrock Nov 9, 2023
1a901a5
chore: forge init
zeroXbrock Nov 9, 2023
4ca1588
forge install: forge-std
zeroXbrock Nov 9, 2023
5eb8ff4
fix pre-signature ccRecord serialization scheme
zeroXbrock Nov 10, 2023
a581074
replace 'executionNode' with 'kettleAddress', remove invalid instance…
zeroXbrock Nov 10, 2023
552c92d
add deployment example in playground
zeroXbrock Nov 10, 2023
eeebe95
clean up & fix bugs in serializer/signer
zeroXbrock Nov 21, 2023
c79a4f0
cleanup
zeroXbrock Nov 21, 2023
830fbe4
add deploy script for mev-share contract, clean up
zeroXbrock Nov 21, 2023
18a21a0
tighten up types
zeroXbrock Nov 21, 2023
7fa521e
clean up deploy script
zeroXbrock Nov 21, 2023
1b2c842
add working mev-share bid example in playgrounds/bun
zeroXbrock Nov 22, 2023
f16e50b
comment out old examples; saving for later isolated examples
zeroXbrock Nov 22, 2023
c83812f
make chainId optional in TransactionRequestSuave
zeroXbrock Nov 22, 2023
c29aec0
move getSuaveWallet to suaveRigil.newWallet
zeroXbrock Nov 22, 2023
ce252fb
move playground code to examples/suave/
zeroXbrock Nov 22, 2023
e2eab53
lint
zeroXbrock Nov 22, 2023
899a5dc
delete old code comments
zeroXbrock Nov 22, 2023
d4236bc
insert suave chainId if missing
zeroXbrock Nov 22, 2023
06362b5
add 'suaveRigil.newPublicClient'
zeroXbrock Nov 22, 2023
83e9b9f
chore: format
zeroXbrock Nov 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "contracts/lib/forge-std"]
path = contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "examples/suave/contracts/lib/suave-geth"]
path = examples/suave/contracts/lib/suave-geth
url = https://github.com/flashbots/suave-geth
1 change: 0 additions & 1 deletion CHANGELOG.md

This file was deleted.

3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"tsconfig.json",
"tsconfig.*.json",
"generated.ts",
"vectors/*.json"
"vectors/*.json",
"examples"
]
},
"formatter": {
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 4 additions & 0 deletions examples/suave/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PRIVATE_KEY=0x91ab9a7e53c220e6210460b65a7a3bb2ca181412a8a7b43ff336b3df1737ce12
KETTLE_ADDRESS=0xb5feafbdd752ad52afb7e1bd2e40432a485bbb7f
SUAVE_RPC_URL_HTTP=http://localhost:8545
GOERLI_RPC_URL_HTTP=
42 changes: 42 additions & 0 deletions examples/suave/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# suave example

## build contracts

Forge will install the required solidity dependencies into `examples/suave/contracts/lib/`.

```sh
# from examples/suave/contracts/

forge install
forge build
```

## deploy contracts

We use a forge script to deploy our contracts. Normally we'd use `forge create` for this but because we rely on (deeply-nested) suave-geth contracts, this is a bit cleaner.

```sh
# from examples/suave/contracts/

# do a dry run to see that your dependencies are set up correctly:
forge script DeployContracts

# populate environment vars using this project's .env file
source ../.env

# send real deployment transactions with the --broadcast flag
forge script --broadcast --rpc-url $RPC_URL_HTTP --private-key $PRIVATE_KEY DeployContracts
```

Then populate your .env file with the new bid contract address.

```sh
# from examples/suave/contracts/
echo "BID_CONTRACT_ADDRESS=$(cat broadcast/Deploy.s.sol/16813125/run-latest.json | jq -r '.receipts[0].contractAddress')" >> ../.env
```

## run example

```bash
bun run index.ts
```
76 changes: 76 additions & 0 deletions examples/suave/bids/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {
Address,
Hex,
encodeAbiParameters,
encodeFunctionData,
toHex,
} from 'viem'
import precompiles from 'viem/chains/suave/precompiles'
import { SuaveTxTypes, TransactionRequestSuave } from 'viem/chains/suave/types'
import MevShareBidContract from '../contracts/out/bids.sol/MevShareBidContract.json'

export interface MevShareBid {
allowedPeekers: Address[]
allowedStores: Address[]
blockNumber: bigint
signedTx: Hex
mevShareContract: Address
kettle: Address
chainId: number
}

/** Helper class to create MEV-Share bids on SUAVE. */
export class MevShareBid {
constructor(
blockNumber: bigint,
signedTx: Hex,
kettle: Address,
mevShareContract: Address,
chainId: number,
) {
this.blockNumber = blockNumber
this.signedTx = signedTx
this.kettle = kettle
this.mevShareContract = mevShareContract
this.chainId = chainId
this.allowedPeekers = [
// no idea what I'm doing here
precompiles.ANYALLOWED,
]
this.allowedStores = []
}

/** Encodes calldata to call the `newBid` function. */
private newBidCalldata() {
return encodeFunctionData({
abi: MevShareBidContract.abi,
functionName: 'newBid',
args: [this.blockNumber, this.allowedPeekers, this.allowedStores],
})
}

/** Wraps `signedTx` in a bundle, then ABI-encodes it as bytes for `confidentialInputs`. */
private confidentialInputsBytes(): Hex {
const bundleBytes = toHex(
JSON.stringify({
txs: [this.signedTx],
revertingHashes: [],
}),
)
return encodeAbiParameters([{ type: 'bytes' }], [bundleBytes])
}

/** Encodes this bid as a ConfidentialComputeRequest, which can be sent to SUAVE. */
toConfidentialRequest(): TransactionRequestSuave {
return {
to: this.mevShareContract,
data: this.newBidCalldata(),
type: SuaveTxTypes.ConfidentialRequest,
gas: 500000n,
gasPrice: 1000000000n,
chainId: this.chainId,
kettleAddress: this.kettle,
confidentialInputs: this.confidentialInputsBytes(),
}
}
}
34 changes: 34 additions & 0 deletions examples/suave/contracts/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: test

on: workflow_dispatch

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
15 changes: 15 additions & 0 deletions examples/suave/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
**/broadcast

# Docs
docs/

# Dotenv file
.env
66 changes: 66 additions & 0 deletions examples/suave/contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Foundry

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

Foundry consists of:

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.

## Documentation

https://book.getfoundry.sh/

## Usage

### Build

```shell
$ forge build
```

### Test

```shell
$ forge test
```

### Format

```shell
$ forge fmt
```

### Gas Snapshots

```shell
$ forge snapshot
```

### Anvil

```shell
$ anvil
```

### Deploy

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
```

### Cast

```shell
$ cast <subcommand>
```

### Help

```shell
$ forge --help
$ anvil --help
$ cast --help
```
9 changes: 9 additions & 0 deletions examples/suave/contracts/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
remappings = [
"suave/=lib/suave-geth/suave/sol/"
]
1 change: 1 addition & 0 deletions examples/suave/contracts/lib/suave-geth
Submodule suave-geth added at 57cbeb
12 changes: 12 additions & 0 deletions examples/suave/contracts/script/Counter.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console2} from "forge-std/Script.sol";

contract CounterScript is Script {
function setUp() public {}

function run() public {
vm.broadcast();
}
}
15 changes: 15 additions & 0 deletions examples/suave/contracts/script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console2} from "forge-std/Script.sol";
import {MevShareBidContract} from "suave/standard_peekers/bids.sol";

contract DeployContracts is Script {
function setUp() public {}

function run() public {
vm.broadcast();
MevShareBidContract bidContract = new MevShareBidContract();
console2.log("bid contract deployed", address(bidContract));
}
}
53 changes: 53 additions & 0 deletions examples/suave/contracts/src/ConfidentialWithLogs.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "suave/libraries/Suave.sol";

contract ConfidentialWithLogs {
event SimResultEvent(
uint64 egp
);

event Test(
uint64 num
);

constructor() {
emit Test(1);
}

fallback() external {
emit Test(2);
}

function fetchBidConfidentialBundleData() public returns (bytes memory x) {
emit Test(101);
// require(Suave.isConfidential(), "not confidential");

// bytes memory confidentialInputs = Suave.confidentialInputs();
// return abi.decode(confidentialInputs, (bytes));
x = hex"deadbeef";
}

// note: this enables the result of the confidential compute request (CCR)
// to be emitted on chain
function emitSimResultEvent(uint64 egp) public {
emit SimResultEvent(egp);
}

// note: because of confidential execution,
// you will not see your input as input to the function
function helloWorld() external returns (bytes memory) {
// 0. ensure confidential execution
// require(Suave.isConfidential(), "not confidential");

// 1. fetch bundle data
bytes memory bundleData = this.fetchBidConfidentialBundleData();

// 2. sim bundle and get effective gas price
uint64 effectiveGasPrice = Suave.simulateBundle(bundleData);

// note: this enables the computation result to be emitted on chain
return bytes.concat(this.emitSimResultEvent.selector, abi.encode(effectiveGasPrice));
}
}
Loading
Loading