Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Introduce native tracer support #81

Merged
merged 10 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ verifier_state_*

# Ignore IntelliJ IDEA/RustRover/Clion metadata
.idea/

# System files
.DS_Store
9 changes: 7 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ thiserror = "1.0.50"
futures = "0.3.29"
keccak-hash = "0.10.0"
alloy = { git = "https://github.com/alloy-rs/alloy", features = [
"consensus",
"json-rpc",
"rlp",
"rpc",
"rpc-client",
"rpc-types-eth",
"rpc-types-trace",
"providers",
"transports",
"transport-http",
Expand All @@ -26,9 +32,10 @@ alloy = { git = "https://github.com/alloy-rs/alloy", features = [

# zk-evm dependencies
plonky2 = "0.2.2"
evm_arithmetization = { git = "https://github.com/0xPolygonZero/zk_evm.git", tag = "v0.4.0" }
trace_decoder = { git = "https://github.com/0xPolygonZero/zk_evm.git", tag = "v0.4.0" }
proof_gen = { git = "https://github.com/0xPolygonZero/zk_evm.git", tag = "v0.4.0" }
evm_arithmetization = { git = "https://github.com/0xPolygonZero/zk_evm.git", tag = "v0.4.0" }
mpt_trie = { git = "https://github.com/0xPolygonZero/zk_evm.git", tag = "v0.4.0" }
trace_decoder = { git = "https://github.com/0xPolygonZero/zk_evm.git", tag = "v0.4.0" }
proof_gen = { git = "https://github.com/0xPolygonZero/zk_evm.git", tag = "v0.4.0" }

[workspace.package]
edition = "2021"
Expand Down
79 changes: 65 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Usage: leader [OPTIONS] <COMMAND>
Commands:
stdio Reads input from stdin and writes output to stdout
jerigon Reads input from a Jerigon node and writes output to stdout
native Reads input from a native node and writes output to stdout
0xaatif marked this conversation as resolved.
Show resolved Hide resolved
http Reads input from HTTP and writes output to a directory
help Print this message or the help of the given subcommand(s)

Expand Down Expand Up @@ -205,23 +206,31 @@ cargo r --release --bin leader jerigon --help

Reads input from a Jerigon node and writes output to stdout

Usage: leader jerigon [OPTIONS] --rpc-url <RPC_URL> --block-number <BLOCK_NUMBER>
Usage: leader jerigon [OPTIONS] --rpc-url <RPC_URL> --block-interval <BLOCK_INTERVAL>

Options:
-u, --rpc-url <RPC_URL>

-b, --block-number <BLOCK_NUMBER>
The block number for which to generate a proof
-i, --block-interval <BLOCK_INTERVAL>
The block interval for which to generate a proof
-c, --checkpoint-block-number <CHECKPOINT_BLOCK_NUMBER>
The checkpoint block number [default: 0]
-f, --previous-proof <PREVIOUS_PROOF>
The previous proof output
-o, --proof-output-path <PROOF_OUTPUT_PATH>
If provided, write the generated proof to this file instead of stdout
-o, --proof-output-dir <PROOF_OUTPUT_DIR>
If provided, write the generated proofs to this directory instead of stdout
-s, --save-inputs-on-error
If true, save the public inputs to disk on error
-b, --block-time <BLOCK_TIME>
Network block time in milliseconds. This value is used to determine the blockchain node polling interval [env: ZERO_BIN_BLOCK_TIME=] [default: 2000]
-k, --keep-intermediate-proofs
Keep intermediate proofs. Default action is to delete them after the final proof is generated [env: ZERO_BIN_KEEP_INTERMEDIATE_PROOFS=]
--backoff <BACKOFF>
Backoff in milliseconds for request retries [default: 0]
--max-retries <MAX_RETRIES>
The maximum number of retries [default: 0]
-h, --help
Print help
-s, --save-inputs-on-error
If provided, save the public inputs to disk on error
```

Prove a block.
Expand All @@ -230,6 +239,48 @@ Prove a block.
cargo r --release --bin leader -- -r in-memory jerigon -u <RPC_URL> -b 16 > ./output/proof_16.json
```

### Native

The native command reads proof input from a native node and writes output to stdout.

```
cargo r --release --bin leader native --help

Reads input from a native node and writes output to stdout

Usage: leader native [OPTIONS] --rpc-url <RPC_URL> --block-interval <BLOCK_INTERVAL>

Options:
-u, --rpc-url <RPC_URL>

-i, --block-interval <BLOCK_INTERVAL>
The block interval for which to generate a proof
-c, --checkpoint-block-number <CHECKPOINT_BLOCK_NUMBER>
The checkpoint block number [default: 0]
-f, --previous-proof <PREVIOUS_PROOF>
The previous proof output
-o, --proof-output-dir <PROOF_OUTPUT_DIR>
If provided, write the generated proofs to this directory instead of stdout
-s, --save-inputs-on-error
If true, save the public inputs to disk on error
-b, --block-time <BLOCK_TIME>
Network block time in milliseconds. This value is used to determine the blockchain node polling interval [env: ZERO_BIN_BLOCK_TIME=] [default: 2000]
-k, --keep-intermediate-proofs
Keep intermediate proofs. Default action is to delete them after the final proof is generated [env: ZERO_BIN_KEEP_INTERMEDIATE_PROOFS=]
--backoff <BACKOFF>
Backoff in milliseconds for request retries [default: 0]
--max-retries <MAX_RETRIES>
The maximum number of retries [default: 0]
-h, --help
Print help
```

Prove a block.

```bash
cargo r --release --bin leader -- -r in-memory native -u <RPC_URL> -b 16 > ./output/proof_16.json
```

### HTTP

The HTTP command reads proof input from HTTP and writes output to a directory.
Expand Down Expand Up @@ -343,7 +394,7 @@ Options:
Example:

```bash
cargo r --release --bin rpc fetch --rpc-url <RPC_URL> --block-number 16 > ./output/block-16.json
cargo r --release --bin rpc fetch --start-block <START_BLOCK> --end-block <END_BLOCK> --rpc-url <RPC_URL> --block-number 16 > ./output/block-16.json
```

## Docker
Expand All @@ -364,16 +415,16 @@ For testing proof generation for blocks, the `testing` branch should be used.

### Proving Blocks

If you want to generate a full block proof, you can use `tools/prove_jerigon.sh`:
If you want to generate a full block proof, you can use `tools/prove_rpc.sh`:

```sh
./prove_jerigon.sh <BLOCK_START> <BLOCK_END> <FULL_NODE_ENDPOINT> <IGNORE_PREVIOUS_PROOFS>
./prove_rpc.sh <BLOCK_START> <BLOCK_END> <FULL_NODE_ENDPOINT> <RPC_TYPE> <IGNORE_PREVIOUS_PROOFS>
```

Which may look like this:

```sh
./prove_jerigon.sh 17 18 http://127.0.0.1:8545 false
./prove_rpc.sh 17 18 http://127.0.0.1:8545 jerigon false
```

Which will attempt to generate proofs for blocks `17` & `18` consecutively and incorporate the previous block proof during generation.
Expand All @@ -385,16 +436,16 @@ A few other notes:

### Generating Witnesses Only

If you want to test a block without the high CPU & memory requirements that come with creating a full proof, you can instead generate only the witness using `tools/prove_jerigon.sh` in the `test_only` mode:
If you want to test a block without the high CPU & memory requirements that come with creating a full proof, you can instead generate only the witness using `tools/prove_rpc.sh` in the `test_only` mode:

```sh
./prove_jerigon.sh <START_BLOCK> <END_BLOCK> <FULL_NODE_ENDPOINT> <IGNORE_PREVIOUS_PROOFS> test_only
./prove_rpc.sh <START_BLOCK> <END_BLOCK> <FULL_NODE_ENDPOINT> <RPC_TYPE> <IGNORE_PREVIOUS_PROOFS> <BACKOFF> <RETRIES> test_only
```

Filled in:

```sh
./prove_jerigon.sh 18299898 18299899 http://34.89.57.138:8545 true test_only
./prove_rpc.sh 18299898 18299899 http://34.89.57.138:8545 jerigon true 0 0 test_only
```

Finally, note that both of these testing scripts force proof generation to be sequential by allowing only one worker. Because of this, this is not a realistic representation of performance but makes the debugging logs much easier to follow.
Expand Down
52 changes: 50 additions & 2 deletions leader/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::path::PathBuf;

use alloy::transports::http::reqwest::Url;
use clap::{Parser, Subcommand, ValueHint};
use common::prover_state::cli::CliProverStateConfig;

Expand All @@ -18,7 +19,7 @@ pub(crate) struct Cli {
pub(crate) prover_state_config: CliProverStateConfig,
}

#[derive(Subcommand)]
#[derive(Subcommand, Clone)]
pub(crate) enum Command {
/// Reads input from stdin and writes output to stdout.
Stdio {
Expand All @@ -33,7 +34,7 @@ pub(crate) enum Command {
Jerigon {
// The Jerigon RPC URL.
#[arg(long, short = 'u', value_hint = ValueHint::Url)]
rpc_url: String,
rpc_url: Url,
/// The block interval for which to generate a proof.
#[arg(long, short = 'i')]
block_interval: String,
Expand Down Expand Up @@ -63,6 +64,53 @@ pub(crate) enum Command {
default_value_t = false
)]
keep_intermediate_proofs: bool,
/// Backoff in milliseconds for request retries
#[arg(long, default_value_t = 0)]
backoff: u64,
/// The maximum number of retries
#[arg(long, default_value_t = 0)]
max_retries: u32,
},
/// Reads input from a native node and writes output to stdout.
Native {
// The native RPC URL.
#[arg(long, short = 'u', value_hint = ValueHint::Url)]
rpc_url: Url,
/// The block interval for which to generate a proof.
#[arg(long, short = 'i')]
block_interval: String,
/// The checkpoint block number.
#[arg(short, long, default_value_t = 0)]
checkpoint_block_number: u64,
/// The previous proof output.
#[arg(long, short = 'f', value_hint = ValueHint::FilePath)]
previous_proof: Option<PathBuf>,
/// If provided, write the generated proofs to this directory instead of
/// stdout.
#[arg(long, short = 'o', value_hint = ValueHint::FilePath)]
proof_output_dir: Option<PathBuf>,
/// If true, save the public inputs to disk on error.
#[arg(short, long, default_value_t = false)]
save_inputs_on_error: bool,
/// Network block time in milliseconds. This value is used
/// to determine the blockchain node polling interval.
#[arg(short, long, env = "ZERO_BIN_BLOCK_TIME", default_value_t = 2000)]
block_time: u64,
/// Keep intermediate proofs. Default action is to
/// delete them after the final proof is generated.
#[arg(
short,
long,
env = "ZERO_BIN_KEEP_INTERMEDIATE_PROOFS",
default_value_t = false
)]
keep_intermediate_proofs: bool,
/// Backoff in milliseconds for request retries
#[arg(long, default_value_t = 0)]
backoff: u64,
/// The maximum number of retries
#[arg(long, default_value_t = 0)]
max_retries: u32,
},
/// Reads input from HTTP and writes output to a directory.
Http {
Expand Down
34 changes: 29 additions & 5 deletions leader/src/jerigon.rs → leader/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
use std::io::Write;
use std::path::PathBuf;

use alloy::providers::RootProvider;
use alloy::transports::http::reqwest::Url;
use anyhow::Result;
use common::block_interval::BlockInterval;
use common::fs::generate_block_proof_file_name;
use paladin::runtime::Runtime;
use proof_gen::proof_types::GeneratedBlockProof;
use rpc::{retry::build_http_retry_provider, RpcType};
use tracing::{error, info, warn};

#[derive(Debug)]
pub struct RpcParams {
pub rpc_url: Url,
pub rpc_type: RpcType,
pub backoff: u64,
pub max_retries: u32,
}

#[derive(Debug, Default)]
pub struct ProofParams {
pub checkpoint_block_number: u64,
Expand All @@ -18,17 +27,22 @@ pub struct ProofParams {
pub keep_intermediate_proofs: bool,
}

/// The main function for the jerigon mode.
pub(crate) async fn jerigon_main(
/// The main function for the client.
pub(crate) async fn client_main(
runtime: Runtime,
rpc_url: &str,
rpc_params: RpcParams,
block_interval: BlockInterval,
mut params: ProofParams,
) -> Result<()> {
let prover_input = rpc::prover_input(
RootProvider::new_http(rpc_url.parse()?),
&build_http_retry_provider(
rpc_params.rpc_url,
rpc_params.backoff,
rpc_params.max_retries,
),
block_interval,
params.checkpoint_block_number.into(),
rpc_params.rpc_type,
)
.await?;

Expand Down Expand Up @@ -92,3 +106,13 @@ pub(crate) async fn jerigon_main(

Ok(())
}

impl From<super::cli::Command> for RpcType {
fn from(command: super::cli::Command) -> Self {
match command {
super::cli::Command::Native { .. } => RpcType::Native,
super::cli::Command::Jerigon { .. } => RpcType::Jerigon,
_ => panic!("Unsupported command type"),
}
}
}
Loading
Loading