Skip to content

Commit

Permalink
implement version command for all zero bin binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
temaniarpit27 committed Jul 28, 2024
1 parent cd1b804 commit 4198fd9
Show file tree
Hide file tree
Showing 16 changed files with 479 additions and 14 deletions.
128 changes: 128 additions & 0 deletions Cargo.lock

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

14 changes: 11 additions & 3 deletions zero_bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ 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
native Reads input from a native node and writes output to stdout
version Fetch the version, build commit hash, build timestamp
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 @@ -366,6 +367,7 @@ cargo r --bin verifier -- --help
Usage: verifier --file-path <FILE_PATH>
Options:
version Fetch the version, build commit hash, build timestamp
-f, --file-path <FILE_PATH> The file containing the proof to verify
-h, --help Print help
```
Expand All @@ -386,8 +388,9 @@ cargo r --bin rpc -- --help
Usage: rpc <COMMAND>
Commands:
fetch Fetch and generate prover input from the RPC endpoint
help Print this message or the help of the given subcommand(s)
fetch Fetch and generate prover input from the RPC endpoint
version Fetch the version, build commit hash, build timestamp
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
Expand Down Expand Up @@ -457,15 +460,20 @@ Finally, note that both of these testing scripts force proof generation to be se

The trace decoder module has some basic regression tests, using the json witness data from the `trace_decoder/tests/data/witnesses` subdirectories.
When needed (e.g. some block with corner-case discovered), additional input witness data should be generated using the following procedure:

1. Run the `rpc` tool to fetch the block (or multiple blocks) witness:

```sh
cargo run --bin rpc fetch --rpc-url <node_rpc_endpoint> --start-block <start> --end-block <end> > ./b<number>_<network>.json
```

2. Download the header file for the block (or range of blocks), making the json array of headers:

```sh
file_name = "b<number>_<network>_header.json"
echo "[" > $file_name && cast rpc eth_getBlockByNumber "0x<block_number>" 'false' --rpc-url <node_rpc_endpoint> >> $file_name && echo "]" >> $file_name
```

Move the generated files to the appropriate subdirectory, and they will be automatically included in the test run.

## License
Expand Down
2 changes: 2 additions & 0 deletions zero_bin/leader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license.workspace = true
repository.workspace = true
keywords.workspace = true
categories.workspace = true
build = "build.rs"

[dependencies]
paladin-core = { workspace = true }
Expand Down Expand Up @@ -38,3 +39,4 @@ test_only = ["ops/test_only", "prover/test_only"]
[build-dependencies]
cargo_metadata = "0.18.1"
anyhow = { workspace = true }
vergen = { version = "9.0.0", features = ["build", "rustc"] }
11 changes: 11 additions & 0 deletions zero_bin/leader/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
use anyhow::Context as _;
use vergen::{BuildBuilder, Emitter, RustcBuilder};

fn main() -> anyhow::Result<()> {
let build_timestamp = BuildBuilder::default().build_timestamp(true).build()?;
let rust_commit_hash = RustcBuilder::default().commit_hash(true).build()?;

Emitter::default()
.add_instructions(&build_timestamp)?
.add_instructions(&rust_commit_hash)?
.emit()?;

let meta = cargo_metadata::MetadataCommand::new()
.exec()
.context("failed to probe cargo-metadata")?;
Expand All @@ -15,5 +25,6 @@ fn main() -> anyhow::Result<()> {
version.major,
version.minor
);

Ok(())
}
1 change: 1 addition & 0 deletions zero_bin/leader/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@ pub(crate) enum Command {
#[arg(short, long, default_value_t = false)]
save_inputs_on_error: bool,
},
Version {},
}
39 changes: 36 additions & 3 deletions zero_bin/leader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ mod init;
mod stdio;

const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER";
const VERGEN_BUILD_TIMESTAMP: &str = "VERGEN_BUILD_TIMESTAMP";
const VERGEN_RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH";

fn get_previous_proof(path: Option<PathBuf>) -> Result<Option<GeneratedBlockProof>> {
if path.is_none() {
Expand Down Expand Up @@ -49,7 +51,29 @@ async fn main() -> Result<()> {
env!("EVM_ARITHMETIZATION_PACKAGE_VERSION"),
);
}
};
}
if env::var_os(VERGEN_BUILD_TIMESTAMP).is_none() {
// Safety:
// - we're early enough in main that nothing else should race
unsafe {
env::set_var(
VERGEN_BUILD_TIMESTAMP,
// see build.rs
env!("VERGEN_BUILD_TIMESTAMP"),
);
}
}
if env::var_os(VERGEN_RUSTC_COMMIT_HASH).is_none() {
// Safety:
// - we're early enough in main that nothing else should race
unsafe {
env::set_var(
VERGEN_RUSTC_COMMIT_HASH,
// see build.rs
env!("VERGEN_RUSTC_COMMIT_HASH"),
);
}
}

let args = cli::Cli::parse();
if let paladin::config::Runtime::InMemory = args.paladin.runtime {
Expand All @@ -60,13 +84,20 @@ async fn main() -> Result<()> {
.initialize()?;
}

let runtime = Runtime::from_config(&args.paladin, register()).await?;

match args.command {
Command::Version {} => {
println!(
"Evm Arithmetization package version: {}",
env::var(EVM_ARITH_VER_KEY)?
);
println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?);
println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?);
}
Command::Stdio {
previous_proof,
save_inputs_on_error,
} => {
let runtime = Runtime::from_config(&args.paladin, register()).await?;
let previous_proof = get_previous_proof(previous_proof)?;
stdio::stdio_main(runtime, previous_proof, save_inputs_on_error).await?;
}
Expand All @@ -75,6 +106,7 @@ async fn main() -> Result<()> {
output_dir,
save_inputs_on_error,
} => {
let runtime = Runtime::from_config(&args.paladin, register()).await?;
// check if output_dir exists, is a directory, and is writable
let output_dir_metadata = std::fs::metadata(&output_dir);
if output_dir_metadata.is_err() {
Expand All @@ -99,6 +131,7 @@ async fn main() -> Result<()> {
backoff,
max_retries,
} => {
let runtime = Runtime::from_config(&args.paladin, register()).await?;
let previous_proof = get_previous_proof(previous_proof)?;
let mut block_interval = BlockInterval::new(&block_interval)?;

Expand Down
Loading

0 comments on commit 4198fd9

Please sign in to comment.