A "Type 0" zkEVM. Prove validity of Ethereum blocks using RISC Zero's zkVM

Related tags

Cryptography zeth
Overview

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 (i.e., is the result of applying the given list of transactions to the parent block) without relying on the validator or sync committees. This is because Zeth does all the work needed to construct a new block from within the zkVM, including:

  • Verifying transaction signatures.
  • Verifying account & storage state against the parent block’s state root.
  • Applying transactions.
  • Paying the block reward.
  • Updating the state root.
  • Etc.

After constructing the new block, Zeth calculates and outputs the block hash. By running this process within the zkVM, we obtain a ZK proof that the new block is valid.

Status

Zeth is experimental and may still contain bugs.

Usage

Building

  • Install the cargo risczero tool and the risc0 toolchain:
$ cargo install cargo-risczero
$ cargo risczero install
  • Clone the repository and build with cargo:
$ cargo build --release

Running

Zeth currently has several modes of execution:

Usage: zeth [OPTIONS] --block-no=<BLOCK_NO>

Options:
  -r, --rpc-url=<RPC_URL>
          URL of the chain RPC node.
  -c, --cache[=<CACHE>]
          Use a local directory as a cache for RPC calls.
          Accepts a custom directory.
          [default: host/testdata]
  -n, --network=<NETWORK>
          Network name (ethereum/optimism).
          [default: ethereum]
  -b, --block-no=<BLOCK_NO>
          Block number to validate.
  -l, --local-exec[=<LOCAL_EXEC>]
          Runs the verification inside the zkvm executor locally.
          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.
  -v, --verify-bonsai-receipt-uuid=<VERIFY_BONSAI_RECEIPT_UUID>
          Bonsai Session UUID to use for receipt verification.
  -p, --profile
          Whether to profile the zkVM execution.
  -h, --help
          Print help.
  -V, --version
          Print version.

Zeth primarily requires an Ethereum RPC provider. Two complementary types of providers are supported:

  • RPC provider. This fetches data from a Web2 RPC provider, such as Alchemy. Specified using the --rpc-url=<RPC_URL> parameter.
  • Cached RPC provider. This fetches RPC data from a local file when possible, and falls back to a Web2 RPC provider when necessary. It amends the local file with results from the Web2 provider so that subsequent runs don't require additional Web2 RPC calls. Specified using the --cache[=CACHE_DIRECTORY] parameter.

Quick test mode. 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:

$ RUST_LOG=info ./target/release/zeth \
    --rpc-url="https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY" \
    --cache \
    --block-no=16424130

Optimism:

$ 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]. When run in this mode, Zeth does all the work needed to construct an Ethereum block from within the zkVM's non-proving emulator. Correctness of the result is checked using the RPC provider. This is useful for measuring the size of the computation (number of execution segments and cycles). No proofs are generated.

$ RUST_LOG=info ./target/release/zeth \
    --rpc-url="https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY" \
    --cache \
    --block-no=16424130 \
    --local-exec

Bonsai proving mode. This mode generates a ZK proof. To run in this mode, add the parameter --submit-to-bonsai. When run in this mode, Zeth submits a proving task to the Bonsai proving service, which then constructs an Ethereum block entirely from within the zkVM. This mode checks the correctness of the result using the RPC provider. It also outputs the Bonsai session UUID, and polls Bonsai until the proof is complete.

To use this feature, first set the BONSAI_API_URL and BONSAI_API_KEY environment variables, then follow the instructions below for submitting jobs to Bonsai and verifying the proofs.

Need a Bonsai API key? Sign up today.

$ RUST_LOG=info ./target/release/zeth \
    --rpc-url="https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY" \
    --cache \
    --block-no=16424130 \
    --submit-to-bonsai

Bonsai verify mode. This mode verifies the ZK proof. To run in this mode, add the parameter --verify-bonsai-receipt-uuid=BONSAI_SESSION_UUID, where BONSAI_SESSION_UUID is the session UUID returned by the --submit-to-bonsai mode. This mode checks the correctness of the result using the RPC provider.

$ RUST_LOG=info ./target/release/zeth \
    --rpc-url="https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY" \
    --cache \
    --block-no=16424130 \
    --verify-bonsai-receipt-uuid=BONSAI_SESSION_UUID

Additional resources

Check out these resources and say hi on our Discord:

Comments
  • Add cache file for block 16424130

    Add cache file for block 16424130

    Tested with:

    $ RUST_LOG=info ./target/release/zeth \
        --cache-path host/testdata \
        --block-no 16424130
    [2023-08-04T22:12:20Z INFO  zeth_lib::host] Initial block: 16424129 (0x9ff998f61f15b627854802e68743f9ed7a822a7ac509fc7d66f06bbceb96a510)
    [2023-08-04T22:12:20Z INFO  zeth_lib::host] Final block number: 16424130 (0x3f841e7f8e56223202e174a94524e33cb7aa3a0cc5141b6efd24be3520655ec7)
    [2023-08-04T22:12:20Z INFO  zeth_lib::host] Transaction count: 172
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder] Block no. 16424130
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   EVM spec ID: MERGE
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Timestamp: 2023-01-17 04:29:23 UTC
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Transactions: 172
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Withdrawals: 0
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Fee Recipient: 0xdafea492d9c6733ae3d56b7ed1adb60692c98bc5
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Gas limit: 30000000
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Base fee per gas: 16132243465
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Extra data: Bytes(0x496c6c756d696e61746520446d6f63726174697a6520447374726962757465)
    [2023-08-04T22:12:20Z INFO  zeth_lib::host] Gathering inclusion proofs ...
    [2023-08-04T22:12:20Z INFO  zeth_lib::host] Saving provider cache ...
    [2023-08-04T22:12:20Z INFO  zeth_lib::host] Provider-backed execution is Done!
    [2023-08-04T22:12:20Z INFO  zeth_lib::host] Constructed proof tries with 7400 nodes
    [2023-08-04T22:12:20Z INFO  zeth] Running from memory ...
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder] Block no. 16424130
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   EVM spec ID: MERGE
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Timestamp: 2023-01-17 04:29:23 UTC
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Transactions: 172
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Withdrawals: 0
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Fee Recipient: 0xdafea492d9c6733ae3d56b7ed1adb60692c98bc5
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Gas limit: 30000000
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Base fee per gas: 16132243465
    [2023-08-04T22:12:20Z INFO  zeth_lib::block_builder]   Extra data: Bytes(0x496c6c756d696e61746520446d6f63726174697a6520447374726962757465)
    [2023-08-04T22:12:20Z INFO  zeth] Memory-backed execution is Done! Database contains 422 accounts
    [2023-08-04T22:12:20Z INFO  zeth] Verifying final state using provider data ...
    [2023-08-04T22:12:21Z INFO  zeth] Final block hash derived successfully. 0x3f841e7f8e56223202e174a94524e33cb7aa3a0cc5141b6efd24be3520655ec7
    
    opened by intoverflow 4
  • Failed to run `eth-block`

    Failed to run `eth-block`

    I would like to use zeth to bake demo code that reads a series of transactions as input and outputs the resulting block hash. It looks like you've already prepared this kind of demo here: https://github.com/risc0/zeth/blob/main/guests/eth-block/src/main.rs

    Unfortunately I fail to make use of it. My attempt to run it:

    ubuntu@VM-0-6-ubuntu:~/zeth/guests/eth-block$ RUST_BACKTRACE=full cargo run
        Finished dev [unoptimized + debuginfo] target(s) in 0.17s
         Running `target/debug/eth-block`
    thread '<unnamed>' panicked at 'not implemented', /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-platform-0.18.0/src/syscall.rs:224:1
    stack backtrace:
       0:     0x55c85bc9e86a - std::backtrace_rs::backtrace::libunwind::trace::h95061b614921b6ff
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
       1:     0x55c85bc9e86a - std::backtrace_rs::backtrace::trace_unsynchronized::hf451b1d73b4bdad4
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
       2:     0x55c85bc9e86a - std::sys_common::backtrace::_print_fmt::h9fca4c77375a2dbe
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:65:5
       3:     0x55c85bc9e86a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb32a52511e633a9b
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:44:22
       4:     0x55c85bcbbaae - core::fmt::write::hb58172bccf5a732a
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/core/src/fmt/mod.rs:1232:17
       5:     0x55c85bc9c9f5 - std::io::Write::write_fmt::hc477a162dd78515a
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/io/mod.rs:1684:15
       6:     0x55c85bc9e635 - std::sys_common::backtrace::_print::hc9c29ec89e5d88cd
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:47:5
       7:     0x55c85bc9e635 - std::sys_common::backtrace::print::h641a35e35def21bb
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:34:9
       8:     0x55c85bc9f93f - std::panicking::default_hook::{{closure}}::h6f17652ca069c908
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:271:22
       9:     0x55c85bc9f67b - std::panicking::default_hook::h33fe72da8bfd0e11
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:290:9
      10:     0x55c85bc9fee8 - std::panicking::rust_panic_with_hook::haf1dd3d09ecba84d
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:692:13
      11:     0x55c85bc9fda2 - std::panicking::begin_panic_handler::{{closure}}::h2657be74b6192e09
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:581:13
      12:     0x55c85bc9ecd6 - std::sys_common::backtrace::__rust_end_short_backtrace::h6bee8db45459b0a6
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:150:18
      13:     0x55c85bc9faf2 - rust_begin_unwind
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:579:5
      14:     0x55c85b8f9b73 - core::panicking::panic_fmt::hd40b690c85fbbb1d
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/core/src/panicking.rs:64:14
      15:     0x55c85b8f9c0d - core::panicking::panic::h2c093a338a41f38f
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/core/src/panicking.rs:114:5
      16:     0x55c85bc87708 - syscall_2
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-platform-0.18.0/src/syscall.rs:217:13
      17:     0x55c85bc873b4 - risc0_zkvm_platform::syscall::sys_read_internal::h8ad8760c2dbfe7d6
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-platform-0.18.0/src/syscall.rs:518:13
      18:     0x55c85bc872af - risc0_zkvm_platform::syscall::sys_read_words::hb794065292e73493
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-platform-0.18.0/src/syscall.rs:503:5
      19:     0x55c85bc6428a - <risc0_zkvm::guest::env::FdReader as risc0_zkvm::serde::deserializer::WordRead>::read_words::ha0c1443bcaba8244
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-0.18.0/src/guest/env.rs:249:36
      20:     0x55c85ba4685b - <&mut R as risc0_zkvm::serde::deserializer::WordRead>::read_words::hbc9cafdbb7607a3a
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-0.18.0/src/serde/deserializer.rs:39:9
      21:     0x55c85b90c06d - risc0_zkvm::serde::deserializer::Deserializer<R>::try_take_word::h6b9b98bef062984f
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-0.18.0/src/serde/deserializer.rs:202:9
      22:     0x55c85b90d6c3 - <&mut risc0_zkvm::serde::deserializer::Deserializer<R> as serde::de::Deserializer>::deserialize_bytes::h0389a0b44e2086dd
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-0.18.0/src/serde/deserializer.rs:341:25
      23:     0x55c85b9630b2 - alloy_primitives::bits::serde::<impl serde::de::Deserialize for alloy_primitives::bits::fixed::FixedBytes<_>>::deserialize::h3010ed5d98f3cc61
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/alloy-primitives-0.3.3/src/bits/serde.rs:65:13
      24:     0x55c85b93fc95 - <core::marker::PhantomData<T> as serde::de::DeserializeSeed>::deserialize::h4c41d3886b403fac
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.171/src/de/mod.rs:792:9
      25:     0x55c85b912c18 - <risc0_zkvm::serde::deserializer::SeqAccess<R> as serde::de::SeqAccess>::next_element_seed::hf78689e056d050e5
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-0.18.0/src/serde/deserializer.rs:111:21
      26:     0x55c85b90f916 - serde::de::SeqAccess::next_element::h80fa4759aa2ef15e
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.171/src/de/mod.rs:1731:9
      27:     0x55c85b925c6a - <zeth_primitives::block::_::<impl serde::de::Deserialize for zeth_primitives::block::Header>::deserialize::__Visitor as serde::de::Visitor>::visit_seq::h88b6049b04422057
                                   at /home/ubuntu/zeth/primitives/src/block.rs:25:50
      28:     0x55c85b90e35f - <&mut risc0_zkvm::serde::deserializer::Deserializer<R> as serde::de::Deserializer>::deserialize_tuple::h28b1493643573e77
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-0.18.0/src/serde/deserializer.rs:404:9
      29:     0x55c85b90ee2c - <&mut risc0_zkvm::serde::deserializer::Deserializer<R> as serde::de::Deserializer>::deserialize_struct::h7b8283f1d0ad2707
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-0.18.0/src/serde/deserializer.rs:442:9
      30:     0x55c85b925c30 - zeth_primitives::block::_::<impl serde::de::Deserialize for zeth_primitives::block::Header>::deserialize::h450700b44013782e
                                     at /home/ubuntu/zeth/primitives/src/block.rs:25:50
      31:     0x55c85b93fed5 - <core::marker::PhantomData<T> as serde::de::DeserializeSeed>::deserialize::hd360538895e99cb6
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.171/src/de/mod.rs:792:9
      32:     0x55c85b911cab - <risc0_zkvm::serde::deserializer::SeqAccess<R> as serde::de::SeqAccess>::next_element_seed::h84fe1f19dbdd07ed
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-0.18.0/src/serde/deserializer.rs:111:21
      33:     0x55c85b90f696 - serde::de::SeqAccess::next_element::h19c97ecf78808123
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.171/src/de/mod.rs:1731:9
      34:     0x55c85b97a073 - <zeth_lib::input::_::<impl serde::de::Deserialize for zeth_lib::input::Input<E>>::deserialize::__Visitor<E> as serde::de::Visitor>::visit_seq::h204d1b4526b4dbb8
                                   at /home/ubuntu/zeth/lib/src/input.rs:31:33
      35:     0x55c85b90e39f - <&mut risc0_zkvm::serde::deserializer::Deserializer<R> as serde::de::Deserializer>::deserialize_tuple::h61732905f4f86d38
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-0.18.0/src/serde/deserializer.rs:404:9
      36:     0x55c85b90eabc - <&mut risc0_zkvm::serde::deserializer::Deserializer<R> as serde::de::Deserializer>::deserialize_struct::h34fcd07908594780
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-0.18.0/src/serde/deserializer.rs:442:9
      37:     0x55c85b97b1f0 - zeth_lib::input::_::<impl serde::de::Deserialize for zeth_lib::input::Input<E>>::deserialize::h9f4757b4361869de
                                   at /home/ubuntu/zeth/lib/src/input.rs:31:33
      38:     0x55c85ba468c5 - <risc0_zkvm::guest::env::FdReader as risc0_zkvm::guest::env::Read>::read::hd19d9f809420e3fa
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-0.18.0/src/guest/env.rs:231:9
      39:     0x55c85ba46775 - risc0_zkvm::guest::env::read::h192e8209a443c704
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-0.18.0/src/guest/env.rs:91:5
      40:     0x55c85b93c9bf - eth_block::main::h95b60fc4cd30742e
                                   at /home/ubuntu/zeth/guests/eth-block/src/main.rs:24:17
      41:     0x55c85b979ad6 - main
                                   at /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-0.18.0/src/guest/mod.rs:156:17
      42:     0x7fd5e2c29d90 - <unknown>
      43:     0x7fd5e2c29e40 - __libc_start_main
      44:     0x55c85b8fa1a5 - _start
      45:                0x0 - <unknown>
    fatal runtime error: failed to initiate panic, error 5
    Aborted (core dumped)
    

    Other attempt:

    ubuntu@VM-0-6-ubuntu:~/zeth/guests/eth-block$ RUST_BACKTRACE=full target/release/eth-block
    thread '<unnamed>' panicked at 'not implemented', /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/risc0-zkvm-platform-0.18.0/src/syscall.rs:224:1
    stack backtrace:
       0:     0x55cf991113ea - std::backtrace_rs::backtrace::libunwind::trace::h95061b614921b6ff
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
       1:     0x55cf991113ea - std::backtrace_rs::backtrace::trace_unsynchronized::hf451b1d73b4bdad4
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
       2:     0x55cf991113ea - std::sys_common::backtrace::_print_fmt::h9fca4c77375a2dbe
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:65:5
       3:     0x55cf991113ea - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb32a52511e633a9b
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:44:22
       4:     0x55cf9912a86e - core::fmt::write::hb58172bccf5a732a
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/core/src/fmt/mod.rs:1232:17
       5:     0x55cf9910f575 - std::io::Write::write_fmt::hc477a162dd78515a
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/io/mod.rs:1684:15
       6:     0x55cf991111b5 - std::sys_common::backtrace::_print::hc9c29ec89e5d88cd
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:47:5
       7:     0x55cf991111b5 - std::sys_common::backtrace::print::h641a35e35def21bb
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:34:9
       8:     0x55cf9911239f - std::panicking::default_hook::{{closure}}::h6f17652ca069c908
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:271:22
       9:     0x55cf991120db - std::panicking::default_hook::h33fe72da8bfd0e11
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:290:9
      10:     0x55cf99112948 - std::panicking::rust_panic_with_hook::haf1dd3d09ecba84d
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:692:13
      11:     0x55cf99112802 - std::panicking::begin_panic_handler::{{closure}}::h2657be74b6192e09
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:581:13
      12:     0x55cf99111856 - std::sys_common::backtrace::__rust_end_short_backtrace::h6bee8db45459b0a6
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:150:18
      13:     0x55cf99112552 - rust_begin_unwind
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:579:5
      14:     0x55cf9901a283 - core::panicking::panic_fmt::hd40b690c85fbbb1d
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/core/src/panicking.rs:64:14
      15:     0x55cf9901a31d - core::panicking::panic::h2c093a338a41f38f
                                   at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/core/src/panicking.rs:114:5
      16:     0x55cf990fa7c6 - risc0_zkvm_platform::syscall::sys_read_words::h1c41f918ad0c2555
      17:     0x55cf990f58ec - <risc0_zkvm::guest::env::FdReader as risc0_zkvm::serde::deserializer::WordRead>::read_words::hd8694ed457b78ad3
    Aborted (core dumped)
    

    Can you please guide me on how is it supposed to be run? I guess I'm missing something very fundamental here as there is #![no_main] in the above code: https://github.com/risc0/zeth/blob/202222a08387b8143b2b1c378a27c7d0a16e0c33/guests/eth-block/src/main.rs#L15 I guess I should run the above code with your zkVM but I have no idea how to do it. Do you have any docs so I can learn more about zeth?

    Tagging @hashcashier as the co-author of the above file (to get your attention). Thanks!

    opened by pbeza 3
  • feat: Optimism L2 Block Validation

    feat: Optimism L2 Block Validation

    This PR adds support for validating OP L2 Blocks by passing in the --network=optimism parameter.

    The main changes for this feature are:

    • A dedicated op-block guest binary for optimism L2 block validation.
    • A generic ConfiguredBlockBuilder parameterized by a NetworkStrategyBundle that wraps around the BlockBuilder.
      • EthereumBlockBuilder is an alias for ConfiguredBlockBuilder<EthereumStrategyBundle>.
      • OptimismBlockBuilder is an alias for ConfiguredBlockBuilder<OptimismStrategyBundle>.
    • Abstraction of TxEssence and implementation of EthereumTxEssence and OptimismTxEssence.
    • Profiling of guest runs through the --profile argument at runtime rather than a feature flag on compilation.
    • Introduction of the optimal --network parameter with ethereum and optimism as valid arguments.
    • Delegation of the state update logic to the implementation of the DatabaseCommit trait from revm.
    • Introduction of the OptimismTxExecStrategy.

    The readme is updated to include a quick optimism test example:

    $ RUST_LOG=info ./target/release/zeth \
        --network=optimism \
        --rpc-url="https://opt-mainnet.g.alchemy.com/v2/YOUR_API_KEY" \
        --cache \
        --block-no=107728767
    
    opened by hashcashier 1
  • fix: update fs write and thread sleep to async versions

    fix: update fs write and thread sleep to async versions

    I was skimming code and noticed this. Doesn't matter now since nothing is being executed async (didn't look in depth), but it is a good future proof if there is in order not to block the executor.

    Alternatively, since it seems like nothing needs to be async, this could be done to remove the runtime until it's needed:

    diff --git a/host/src/main.rs b/host/src/main.rs
    index d0809fc..8b97021 100644
    --- a/host/src/main.rs
    +++ b/host/src/main.rs
    @@ -82,8 +82,7 @@ fn cache_file_path(cache_path: &String, network: &String, block_no: u64, ext: &s
         format!("{}/{}/{}.{}", cache_path, network, block_no, ext)
     }
    
    -#[tokio::main]
    -async fn main() -> Result<()> {
    +fn main() -> Result<()> {
         env_logger::init();
         let args = Args::parse();
    
    @@ -93,11 +92,8 @@ async fn main() -> Result<()> {
             .as_ref()
             .map(|dir| cache_file_path(dir, &args.network.to_string(), args.block_no, "json.gz"));
    
    -    let init = tokio::task::spawn_blocking(move || {
    -        zeth_lib::host::get_initial_data(rpc_cache, args.rpc_url, args.block_no)
    -            .expect("Could not init")
    -    })
    -    .await?;
    +    let init = zeth_lib::host::get_initial_data(rpc_cache, args.rpc_url, args.block_no)
    +        .expect("Could not init");
    
         let input: Input = init.clone().into();
    

    I'm assuming this was made to be async because maybe there is a plan to change the bonsai HTTP calls to async or have more logic be handled in parallel in the future, which is why I suggested the change I PRed.

    Feel free to close; this change doesn't matter right now. I just figured I'd point it out!

    opened by austinabell 1
  • docs: Detailed documentation

    docs: Detailed documentation

    This (WIP) PR adds detailed documentation to Zeth. The updates aim to provide clearer context and more detailed explanations for developers.

    TODO:

    • [ ] guests

      • [ ] eth-block
        • [ ] main.rs
    • [ ] host

      • [ ] main.rs
    • [ ] lib

      • [ ] block_builder.rs
      • [ ] consts.rs
      • [ ] execution.rs
      • [ ] host
        • [ ] mpt.rs
        • [ ] provider
          • [ ] cached_rpc_provider.rs
          • [ ] file_provider.rs
          • [ ] rpc_provider.rs
        • [ ] provider_db.rs
      • [ ] mem_db.rs
      • [x] ~~validation.rs~~
    • [x] primitives

      • [x] access_list.rs
      • [x] block.rs
      • [x] ethers.rs
      • [x] keccak.rs
      • [x] lib.rs
      • [x] receipt.rs
      • [x] revm.rs
      • [x] signature.rs
      • [x] transaction.rs
      • [x] withdrawl.rs
      • [x] trie
        • [x] account.rs
        • [x] mpt.rs

    Draft: looking for early feedback - lmk if it missing anything, typos, or is too pedantic.

    documentation 
    opened by hmrtn 1
  • Introduce op-info tool

    Introduce op-info tool

    The op-info tool fetches and displays epoch information for a given Op block.

    Example:

    $ ./target/release/op-info --op-rpc-url=[hidden] --block-no=111330600
    setL1BlockValues(setL1BlockValuesCall { _number: 18429149, _timestamp: 1698259907, _basefee: 0x000000000000000000000000000000000000000000000000000000098aa55d24_U256, _hash: 0xba523e94231f321d5873d4e0a14b27455354d96af26089522a449fa686c3effc, _sequenceNumber: 0, _batcherHash: 0x0000000000000000000000006887246668a3b87f54deb3b94ba47a6f63f32985, _l1FeeOverhead: 0x00000000000000000000000000000000000000000000000000000000000000bc_U256, _l1FeeScalar: 0x00000000000000000000000000000000000000000000000000000000000a6fe0_U256 })
    

    (The example data given above can be corroborated using etherscan).

    Under the hood, this tool uses the alloy_sol_macro crate, resulting in a clean implementation. First we describe the function we care about:

    use alloy_sol_types::{sol, SolInterface};
    
    sol! {
        #[derive(Debug)]
        interface OpSystemInfo {
            function setL1BlockValues(
                uint64 _number,
                uint64 _timestamp,
                uint256 _basefee,
                bytes32 _hash,
                uint64 _sequenceNumber,
                bytes32 _batcherHash,
                uint256 _l1FeeOverhead,
                uint256 _l1FeeScalar
            );
        }
    }
    

    Then we parse the calldata from the transaction:

       let system_tx_data = op_block
            .transactions
            .first()
            .expect("No transactions")
            .input
            .to_vec();
        let set_l1_block_values = OpSystemInfo::OpSystemInfoCalls::abi_decode(&system_tx_data, true)
            .expect("Could not decode call data");
    
    opened by intoverflow 0
  • Performance improvement

    Performance improvement

    No lto

    [2023-09-28T14:38:47Z INFO  zeth] Generated 2745 segments; elapsed time: 287.196395458s
    [2023-09-28T14:38:47Z INFO  zeth] Executor ran in (roughly) 2878341120 cycles
    

    VS

    lto = "thin"

    [2023-09-28T14:47:10Z INFO  zeth] Generated 2699 segments; elapsed time: 282.953058208s
    [2023-09-28T14:47:10Z INFO  zeth] Executor ran in (roughly) 2830106624 cycles
    
    opened by capossele 0
  • feat: op-zeth

    feat: op-zeth

    Description

    Adds support for OP Stack chains via an optimism feature flag.

    Note, this will need to change if alloy hoists primitive types (including transactions and the optimism deposit transaction type).

    opened by refcell 0
  • build: Bump alloy to

    build: Bump alloy to "0.3.3"

    Upgrades alloy-primitives to v0.3.3. This new version deprecates B160 in favor of Address. While we technically don't need the advanced features Address brings, it doesn't hurt either.

    opened by Wollac 0
  • docs: detailed documentation of `primitives`

    docs: detailed documentation of `primitives`

    Primitives documentation updates:

    • [x] access_list.rs
    • [x] blocks.rs
    • [x] ethers.rs
    • [x] keccak.rs
    • [x] receipt.rs
    • [x] revm.rs
    • [x] signature.rs
    • [x] transaction.rs
    • [x] trie/account.rs
    • [x] trie/mpt.rs
    • [x] withdrawl.rs
    documentation 
    opened by hmrtn 0
  • MptNode doesn't seem to match with cita-trie, @ethereumjs/trie, lambdaclass/merkle-patrica-trie

    MptNode doesn't seem to match with cita-trie, @ethereumjs/trie, lambdaclass/merkle-patrica-trie

    others

    //! # Basic example.
    //!
    //! Target hash extracted from here:
    //!   https://github.com/ethereum/tests/blob/develop/TrieTests/trietest.json#L97-L104
    //!
    //! ## Dependencies
    //!
    //! ```toml
    //! [dependencies]
    //! cita_trie = "4.0.0"
    //! hasher = "0.1.4"
    //! hex-literal = "0.3.4"
    //! memory-db = "0.31.0"
    //! reference-trie = "0.26.0"
    //! sha3 = "0.10.6"
    //! trie-db = "0.24.0"
    //!
    //! [dependencies.patricia-merkle-tree]
    //! git = "https://github.com/lambdaclass/merkle_patricia_tree"
    //! ```
    
    use cita_trie::{MemoryDB, PatriciaTrie, Trie};
    use hasher::HasherKeccak;
    use hex_literal::hex;
    use patricia_merkle_tree::PatriciaMerkleTree;
    use sha3::Keccak256;
    use std::sync::Arc;
    
    #[inline]
    pub fn keccak(data: impl AsRef<[u8]>) -> [u8; 32] {
        Keccak256::digest(data).into()
    }
    
    fn main() {
        const DATA: &[(&[u8], &[u8])] = &[(b"abc", b"123"), (b"abcd", b"abcd"), (b"abc", b"abc")];
        const HASH: [u8; 32] = hex!("7a320748f780ad9ad5b0837302075ce0eeba6c26e3d8562c67ccc0f1b273298a");
    
        println!("Expected   : {HASH:02x?}");
        println!("Our    hash: {:02x?}", run_ours(DATA.iter().copied()));
        println!("Cita   hash: {:02x?}", run_cita(DATA.iter().copied()));
        println!("Parity hash: {:02x?}", run_parity(DATA.iter().copied()));
    }
    
    fn run_ours<'a>(data: impl Iterator<Item = (&'a [u8], &'a [u8])>) -> [u8; 32] {
        let mut trie = PatriciaMerkleTree::<_, _, Keccak256>::new();
    
        data.for_each(|(p, v)| {
            trie.insert(p, v);
        });
    
        trie.compute_hash().as_slice().try_into().unwrap()
    }
    
    fn run_cita<'a>(data: impl Iterator<Item = (&'a [u8], &'a [u8])>) -> [u8; 32] {
        let mem_db = Arc::new(MemoryDB::new(true));
        let hasher = Arc::new(HasherKeccak::new());
    
        let mut trie = PatriciaTrie::new(mem_db, hasher);
    
        data.for_each(|(p, v)| {
            trie.insert(p.to_vec(), v.to_vec()).unwrap();
        });
    
        trie.root().unwrap().try_into().unwrap()
    }
    
    fn run_parity<'a>(data: impl Iterator<Item = (&'a [u8], &'a [u8])>) -> [u8; 32] {
        use memory_db::{HashKey, MemoryDB};
        use reference_trie::ExtensionLayout;
        use trie_db::{NodeCodec, TrieDBMutBuilder, TrieHash, TrieLayout, TrieMut};
    
        let mut mem_db =
            MemoryDB::<_, HashKey<_>, _>::new(<ExtensionLayout as TrieLayout>::Codec::empty_node());
        let mut root = <TrieHash<ExtensionLayout>>::default();
    
        let mut trie = TrieDBMutBuilder::<ExtensionLayout>::new(&mut mem_db, &mut root).build();
    
        data.for_each(|(p, v)| {
            trie.insert(p, v).unwrap();
        });
    
        trie.commit();
        *trie.root()
    }
    

    MPTNode

    let mut trie = MptNode::default();
    trie.insert_rlp(&keccak(b"abc"), b"123");
    trie.insert_rlp(&keccak(b"abcd"), b"abcd");
    trie.insert_rlp(&keccak(b"abc"), b"abc");
    println!("{}", trie.hash()); // 0x3ee240ca74b2cea91b94e23efcfa630a46fb553f9bde61e53a01c0db311c0c4e
    
    opened by GopherJ 0
  • feat: Use revm Optimism execution

    feat: Use revm Optimism execution

    • Uses the optimism feature of revm to execute Optimism blocks
    • Add support for Bedrock and Regolith
    • Add e2e tests for Optimism blocks
    • Upgrade dependencies to latest version to resolve conflicts

    Note: This currently depends on the latest revm commit from https://github.com/bluealloy/revm.git, so we might want to wait until the next release.

    opened by Wollac 0
  • Better error reporting if cache directory does not exist

    Better error reporting if cache directory does not exist

    When given the --cache=dir flag, zeth assumes the directory dir/network exists. If this directory does not exist, it exits with an error, but the error is not very helpful. Zeth should either create the missing directory tree, or provide an error message that includes the path that is expected to exist.

    opened by intoverflow 0
Owner
RISC Zero
Fixing the Internet, one ZKP at a time
RISC Zero
Ethereum (and Ethereum like) indexer using P2P message to fetch blocks and transactions

Ethereum P2P indexer This project is an indexer for Ethereum and Ethereum forks. It takes advantage of the ETH (Ethereum Wire Protocol) to fetch block

null 5 Nov 10, 2023
CosmWasm + zkVM RISC-V EFI template

cosmwasm-risc0-example CosmWasm + RISC-V zkVM gm example Overview CosmWasm RISC Zero This example exists to explore the patterns of use of CosmWasm an

barton 11 Jan 11, 2023
L2 validity rollup combined with blind signatures over elliptic curves inside zkSNARK, to provide offchain anonymous voting with onchain binding execution on Ethereum

blind-ovote Blind-OVOTE is a L2 voting solution which combines the validity rollup ideas with blind signatures over elliptic curves inside zkSNARK, to

Aragon ZK Research 3 Nov 18, 2022
RISC Zero is a zero-knowledge verifiable general computing platform based on zk-STARKs and the RISC-V microarchitecture.

RISC Zero WARNING: This software is still experimental, we do not recommend it for production use (see Security section). RISC Zero is a zero-knowledg

RISC Zero 653 Jan 3, 2023
Validity is a next-generation, deduction-based language for formally verified, context-aware, autonomous & reactive smart contracts.

Validity Language Validity is a next-generation, deduction-based language for formally verified, context-aware, autonomous & reactive smart contracts.

Tempest Labs 4 Nov 11, 2022
deductive verification of Rust code. (semi) automatically prove your code satisfies your specifications!

Le marteau-pilon, forges et aciéries de Saint-Chamond, Joseph-Fortuné LAYRAUD, 1889 About Creusot is a tool for deductive verification of Rust code. I

Xavier Denis 609 Dec 28, 2022
Fastmurmur3 - Fast non-cryptographic hash, with the benchmarks to prove it.

Fastmurmur3 Murmur3 is a fast, non-cryptographic hash function. fastmurmur3 is, in my testing, the fastest implementation of Murmur3. Usage let bytes:

Kurt Wolf 13 Dec 2, 2022
Substreams development kit for Ethereum chains, contains Firehose Block model and helpers as well as utilities for Ethereum ABI encoding/decoding.

Substreams Ethereum Substreams development kit for Ethereum chains, contains Rust Firehose Block model and helpers as well as utilities for Ethereum A

StreamingFast 15 Oct 25, 2022
Iterate over bitcoin blocks

Blocks iterator Iterates over Bitcoin blocks, decoding data inside Bitcoin Core's blocks directory. Features: Blocks are returned in height order, it

Riccardo Casatta 38 Nov 8, 2022
Rust-native building blocks for the Cardano blockchain ecosystem

Pallas Rust-native building blocks for the Cardano blockchain ecosystem. Introduction Pallas is an expanding collection of modules that re-implements

null 78 Dec 6, 2022
Common protocol for generating ZK proofs for blocks on different blockchains.

Proof Protocol Decoder A flexible protocol that clients (eg. full nodes) can use to easily generate block proofs for different chains. Specification I

Polygon Zero 3 Oct 5, 2023
CKB's vm, based on open source RISC-V ISA

Nervos CKB VM About CKB VM CKB VM is a pure software implementation of the RISC-V instruction set used as scripting VM in CKB. Right now it implements

Nervos Network 297 Jan 3, 2023
Custom Ethereum vanity address generator made in Rust

ethaddrgen Custom Ethereum address generator Get a shiny ethereum address and stand out from the crowd! Disclaimer: Do not use the private key shown i

Jakub Hlusička 153 Dec 27, 2022
Rust Ethereum 2.0 Client

Lighthouse: Ethereum 2.0 An open-source Ethereum 2.0 client, written in Rust and maintained by Sigma Prime. Documentation Overview Lighthouse is: Read

Sigma Prime 2.1k Jan 6, 2023
Parity-Bridge — Bridge between any two ethereum-based networks

Deprecated Bridges This repo is deprecated. Originally it contained the ETH <> ETH-PoA bridge (see tumski tag). Later it was repurposed for ETH-PoA <>

Parity Technologies 314 Nov 25, 2022
The fast, light, and robust client for the Ethereum mainnet.

OpenEthereum Fast and feature-rich multi-network Ethereum client. » Download the latest release « Table of Contents Description Technical Overview Bui

OpenEthereum 1.6k Dec 28, 2022
An Ethereum 2.0 Emulator for Local Testing of Eth2 Applications

Mousse is an Ethereum 2.0 emulator for local testing of Eth2 applications (mainly Rollups). HTTP Server The REST API definition can be found in the ht

Mousse 46 Sep 10, 2022
C++ `std::unique_ptr` that represents each object as an NFT on the Ethereum blockchain

C++ `std::unique_ptr` that represents each object as an NFT on the Ethereum blockchain

null 1.9k Dec 28, 2022
Rust client to Opensea's APIs and Ethereum smart contracts

opensea.rs Rust bindings & CLI to the Opensea API and Contracts CLI Usage Run cargo r -- --help to get the top level help menu: opensea-cli 0.1.0 Choo

Georgios Konstantopoulos 226 Dec 27, 2022