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

feat: Optimism L2 Block Validation #31

Merged
merged 16 commits into from
Sep 18, 2023
36 changes: 25 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# zeth

**NEW: Zeth now supports Optimism blocks! Just pass in `--network=optimism`!**

Zeth is an open-source ZK block prover for Ethereum built on the RISC Zero zkVM.

Zeth makes it possible to *prove* that a given Ethereum block is valid
Expand Down Expand Up @@ -47,28 +49,30 @@ Usage: zeth [OPTIONS] --block-no=<BLOCK_NO>

Options:
-r, --rpc-url=<RPC_URL>
URL of the chain RPC node
URL of the chain RPC node.
-c, --cache[=<CACHE>]
Use a local directory as a cache for RPC calls.
Accepts an optional custom directory.
Accepts a custom directory.
[default: host/testdata]
-n, --network=<NETWORK>
Network name [default: ethereum]
Network name (ethereum/optimism).
[default: ethereum]
-b, --block-no=<BLOCK_NO>
Block number to validate
Block number to validate.
-l, --local-exec[=<LOCAL_EXEC>]
Runs the verification inside the zkvm executor locally.
Accepts an optional custom maximum segment cycle count
specified as a power of 2.
[default: 20 (i.e. ~1M cycles)]
Accepts a custom maximum segment cycle count as a power of 2. [default: 20]
-s, --submit-to-bonsai
Whether to submit the proving workload to Bonsai
Whether to submit the proving workload to Bonsai.
-v, --verify-bonsai-receipt-uuid=<VERIFY_BONSAI_RECEIPT_UUID>
Bonsai Session UUID to use for receipt verification
Bonsai Session UUID to use for receipt verification.
-p, --profile
Whether to profile the zkVM execution.
-h, --help
Print help
Print help.
-V, --version
Print version
Print version.

```

Zeth primarily requires an Ethereum RPC provider.
Expand All @@ -87,13 +91,23 @@ This is the default.
When run in this mode, Zeth does all the work needed to construct an Ethereum block and verifies the correctness
of the result using the RPC provider.
No proofs are generated.
You can omit the `rpc-url` parameter if you do not change the `block-no` parameters from the below examples as the data is already cached.

Ethereum:
```console
$ RUST_LOG=info ./target/release/zeth \
--rpc-url="https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY" \
--cache \
--block-no=16424130
```
Optimism:
```console
$ RUST_LOG=info ./target/release/zeth \
--network=optimism \
--rpc-url="https://opt-mainnet.g.alchemy.com/v2/YOUR_API_KEY" \
--cache \
--block-no=107728767
```

**Local executor mode**.
To run in this mode, add the parameter `--local-exec[=SEGMENT_LIMIT]`.
Expand Down
2 changes: 1 addition & 1 deletion guests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"
risc0-build = { workspace = true }

[package.metadata.risc0]
methods = ["eth-block"]
methods = ["eth-block", "op-block"]
17 changes: 3 additions & 14 deletions guests/eth-block/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,15 @@
#![no_main]

use risc0_zkvm::guest::env;
use zeth_lib::{
block_builder::BlockBuilder, consts::ETH_MAINNET_CHAIN_SPEC, execution::EthTxExecStrategy,
finalization::BuildFromMemDbStrategy, initialization::MemDbInitStrategy, input::Input,
mem_db::MemDb, preparation::EthHeaderPrepStrategy,
};
use zeth_lib::{block_builder::EthereumBlockBuilder, consts::ETH_MAINNET_CHAIN_SPEC};

risc0_zkvm::guest::entry!(main);

pub fn main() {
// Read the input previous block and transaction data
let input: Input = env::read();
let input = env::read();
// Build the resulting block
let output = BlockBuilder::<MemDb>::new(&ETH_MAINNET_CHAIN_SPEC, input)
.initialize_database::<MemDbInitStrategy>()
.expect("Failed to create in-memory evm storage")
.prepare_header::<EthHeaderPrepStrategy>()
.expect("Failed to create the initial block header fields")
.execute_transactions::<EthTxExecStrategy>()
.expect("Failed to execute transactions")
.build::<BuildFromMemDbStrategy>()
let output = EthereumBlockBuilder::build_from(&ETH_MAINNET_CHAIN_SPEC, input)
.expect("Failed to build the resulting block");
// Output the resulting block's hash to the journal
env::commit(&output.hash());
Expand Down
Loading