Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into refactor_ll_initia…
Browse files Browse the repository at this point in the history
…l_hashing
  • Loading branch information
4l0n50 committed Sep 12, 2024
2 parents 4447e8f + 7d436c1 commit 71e7021
Show file tree
Hide file tree
Showing 20 changed files with 94 additions and 92 deletions.
9 changes: 4 additions & 5 deletions Cargo.lock

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

22 changes: 21 additions & 1 deletion common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ethereum_types::H256;
use ethereum_types::{H256, U256};

/// The hash value of an account empty EVM code.
/// 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
Expand All @@ -14,6 +14,26 @@ pub const EMPTY_TRIE_HASH: H256 = H256([
108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33,
]);

/// Converts an amount in `ETH` to `wei` units.
pub fn eth_to_wei(eth: U256) -> U256 {
// 1 ether = 10^18 wei.
eth * U256::from(10).pow(18.into())
}

/// Converts an amount in `gwei` to `wei` units.
/// This also works for converting `ETH` to `gwei`.
pub fn gwei_to_wei(eth: U256) -> U256 {
// 1 ether = 10^9 gwei = 10^18 wei.
eth * U256::from(10).pow(9.into())
}

#[test]
fn test_eth_conversion() {
assert_eq!(
eth_to_wei(U256::one()),
gwei_to_wei(gwei_to_wei(U256::one()))
);
}
#[test]
fn test_empty_code_hash() {
assert_eq!(EMPTY_CODE_HASH, keccak_hash::keccak([]));
Expand Down
1 change: 1 addition & 0 deletions evm_arithmetization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ serde-big-array = { workspace = true }
mpt_trie = { workspace = true }
smt_trie = { workspace = true, optional = true }
zk_evm_proc_macro = { workspace = true }
zk_evm_common = { workspace = true }

[dev-dependencies]
criterion = { workspace = true }
Expand Down
6 changes: 0 additions & 6 deletions evm_arithmetization/src/testing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,3 @@ pub fn scalable_contract_from_storage(storage_trie: &HashedPartialTrie) -> Accou
..Default::default()
}
}

/// Converts an amount in `ETH` to `wei` units.
pub fn eth_to_wei(eth: U256) -> U256 {
// 1 ether = 10^18 wei.
eth * U256::from(10).pow(18.into())
}
3 changes: 2 additions & 1 deletion evm_arithmetization/tests/selfdestruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use evm_arithmetization::generation::{GenerationInputs, TrieInputs};
use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots};
use evm_arithmetization::prover::testing::prove_all_segments;
use evm_arithmetization::testing_utils::{
beacon_roots_account_nibbles, beacon_roots_contract_from_storage, eth_to_wei, init_logger,
beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger,
preinitialized_state_and_storage_tries, update_beacon_roots_account_storage,
};
use evm_arithmetization::verifier::testing::verify_all_proofs;
Expand All @@ -21,6 +21,7 @@ use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::plonk::config::KeccakGoldilocksConfig;
use plonky2::util::timing::TimingTree;
use zk_evm_common::eth_to_wei;

type F = GoldilocksField;
const D: usize = 2;
Expand Down
3 changes: 2 additions & 1 deletion evm_arithmetization/tests/simple_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use evm_arithmetization::generation::{GenerationInputs, TrieInputs};
use evm_arithmetization::proof::{BlockHashes, BlockMetadata, TrieRoots};
use evm_arithmetization::prover::testing::prove_all_segments;
use evm_arithmetization::testing_utils::{
beacon_roots_account_nibbles, beacon_roots_contract_from_storage, eth_to_wei, init_logger,
beacon_roots_account_nibbles, beacon_roots_contract_from_storage, init_logger,
preinitialized_state_and_storage_tries, update_beacon_roots_account_storage,
};
use evm_arithmetization::verifier::testing::verify_all_proofs;
Expand All @@ -22,6 +22,7 @@ use mpt_trie::partial_trie::{HashedPartialTrie, PartialTrie};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::plonk::config::KeccakGoldilocksConfig;
use plonky2::util::timing::TimingTree;
use zk_evm_common::eth_to_wei;

type F = GoldilocksField;
const D: usize = 2;
Expand Down
1 change: 0 additions & 1 deletion trace_decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ criterion = { workspace = true }
glob = "0.3.1"
libtest-mimic = "0.7.3"
plonky2_maybe_rayon = { workspace = true }
pretty_env_logger = { workspace = true }
prover = { workspace = true }
serde_json = { workspace = true }
serde_path_to_error = { workspace = true }
Expand Down
8 changes: 2 additions & 6 deletions trace_decoder/src/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use mpt_trie::{
trie_ops::TrieOpError,
utils::{IntoTrieKey as _, TriePath},
};
use zk_evm_common::gwei_to_wei;

use crate::{
hash,
Expand Down Expand Up @@ -442,7 +443,7 @@ fn add_withdrawals_to_txns(
) -> anyhow::Result<()> {
// Scale withdrawals amounts.
for (_addr, amt) in withdrawals.iter_mut() {
*amt = eth_to_gwei(*amt)
*amt = gwei_to_wei(*amt)
}

let withdrawals_with_hashed_addrs_iter = || {
Expand Down Expand Up @@ -692,11 +693,6 @@ fn create_trie_subset_wrapped(
.context(format!("missing keys when creating {}", trie_type))
}

fn eth_to_gwei(eth: U256) -> U256 {
// 1 ether = 10^9 gwei.
eth * U256::from(10).pow(9.into())
}

// This is just `rlp(0)`.
const ZERO_STORAGE_SLOT_VAL_RLPED: [u8; 1] = [128];

Expand Down
9 changes: 5 additions & 4 deletions zero_bin/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,41 @@ anyhow = { workspace = true }
async-stream = { workspace = true }
cargo_metadata = { workspace = true }
clap = { workspace = true }
dotenvy = { workspace = true }
futures = { workspace = true }
lru = { workspace = true }
once_cell = { workspace = true }
plonky2 = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_path_to_error = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
vergen = { workspace = true }

directories = "5.0.1"

# Local dependencies
evm_arithmetization = { workspace = true }
proof_gen = { workspace = true }
trace_decoder = { workspace = true }

[build-dependencies]
anyhow = { workspace = true }
cargo_metadata = { workspace = true }
vergen = { workspace = true }
anyhow = { workspace = true }


[features]
default = ["eth_mainnet"]
eth_mainnet = [
"evm_arithmetization/eth_mainnet",
"proof_gen/eth_mainnet",
"trace_decoder/eth_mainnet",
]
cdk_erigon = [
"evm_arithmetization/cdk_erigon",
"proof_gen/cdk_erigon",
"trace_decoder/cdk_erigon",
]

[lints]
Expand Down
16 changes: 16 additions & 0 deletions zero_bin/common/src/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::io;

use dotenvy::dotenv;
use tracing::warn;

/// Attempt to load in the local `.env` if present and set any environment
/// variables specified inside of it.
///
/// To keep things simple, any IO error we will treat as the file not existing
/// and continue moving on without the `env` variables set.
pub fn load_dotenvy_vars_if_present() {
match dotenv() {
Ok(_) | Err(dotenvy::Error::Io(io::Error { .. })) => (),
Err(e) => warn!("Found local `.env` file but was unable to parse it! (err: {e})",),
}
}
15 changes: 15 additions & 0 deletions zero_bin/common/src/fs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
use std::fs::File;
use std::path::PathBuf;

use proof_gen::proof_types::GeneratedBlockProof;

pub fn generate_block_proof_file_name(directory: &Option<&str>, block_height: u64) -> PathBuf {
let mut path = PathBuf::from(directory.unwrap_or(""));
path.push(format!("b{}.zkproof", block_height));
path
}

pub fn get_previous_proof(path: Option<PathBuf>) -> anyhow::Result<Option<GeneratedBlockProof>> {
if path.is_none() {
return Ok(None);
}

let path = path.unwrap();
let file = File::open(path)?;
let des = &mut serde_json::Deserializer::from_reader(&file);
let proof: GeneratedBlockProof = serde_path_to_error::deserialize(des)?;
Ok(Some(proof))
}
2 changes: 2 additions & 0 deletions zero_bin/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pub mod block_interval;
pub mod debug_utils;
pub mod env;
pub mod fs;
pub mod parsing;
pub mod pre_checks;
pub mod prover_state;
pub mod provider;
pub mod tracing;
pub mod version;

/// Size of the channel used to send block prover inputs to the per block
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use tracing_subscriber::{prelude::*, util::SubscriberInitExt, EnvFilter};
pub(crate) fn tracing() {

pub fn init() {
tracing_subscriber::Registry::default()
.with(
tracing_subscriber::fmt::layer()
Expand Down
18 changes: 8 additions & 10 deletions zero_bin/leader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ categories.workspace = true
build = "../common/build.rs"

[dependencies]
paladin-core = { workspace = true }
clap = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
alloy = { workspace = true }
anyhow = { workspace = true }
axum = { workspace = true }
clap = { workspace = true }
futures = { workspace = true }
paladin-core = { workspace = true }
serde = { workspace = true }
dotenvy = { workspace = true }
tokio = { workspace = true }
serde_json = { workspace = true }
serde_path_to_error = { workspace = true }
futures = { workspace = true }
alloy.workspace = true
axum = { workspace = true }
toml = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

# Local dependencies
evm_arithmetization = { workspace = true }
Expand Down
36 changes: 5 additions & 31 deletions zero_bin/leader/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use std::env;
use std::sync::Arc;
use std::{env, io};
use std::{fs::File, path::PathBuf};

use anyhow::Result;
use clap::Parser;
use cli::Command;
use client::RpcParams;
use dotenvy::dotenv;
use ops::register;
use paladin::runtime::Runtime;
use proof_gen::proof_types::GeneratedBlockProof;
use prover::ProverConfig;
use tracing::{info, warn};
use tracing::info;
use zero_bin_common::env::load_dotenvy_vars_if_present;
use zero_bin_common::fs::get_previous_proof;
use zero_bin_common::{
block_interval::BlockInterval, prover_state::persistence::set_circuit_cache_dir_env_if_not_set,
};
Expand All @@ -22,26 +21,13 @@ use crate::client::{client_main, LeaderConfig};
mod cli;
mod client;
mod http;
mod init;
mod stdio;

fn get_previous_proof(path: Option<PathBuf>) -> Result<Option<GeneratedBlockProof>> {
if path.is_none() {
return Ok(None);
}

let path = path.unwrap();
let file = File::open(path)?;
let des = &mut serde_json::Deserializer::from_reader(&file);
let proof: GeneratedBlockProof = serde_path_to_error::deserialize(des)?;
Ok(Some(proof))
}

#[tokio::main]
async fn main() -> Result<()> {
load_dotenvy_vars_if_present();
set_circuit_cache_dir_env_if_not_set()?;
init::tracing();
zero_bin_common::tracing::init();

let args: Vec<String> = env::args().collect();

Expand Down Expand Up @@ -127,15 +113,3 @@ async fn main() -> Result<()> {

Ok(())
}

/// Attempt to load in the local `.env` if present and set any environment
/// variables specified inside of it.
///
/// To keep things simple, any IO error we will treat as the file not existing
/// and continue moving on without the `env` variables set.
fn load_dotenvy_vars_if_present() {
match dotenv() {
Ok(_) | Err(dotenvy::Error::Io(io::Error { .. })) => (),
Err(e) => warn!("Found local `.env` file but was unable to parse it! (err: {e})",),
}
}
Loading

0 comments on commit 71e7021

Please sign in to comment.