diff --git a/axiom-codec/Cargo.toml b/axiom-codec/Cargo.toml index 3b61bf9d..ca090628 100644 --- a/axiom-codec/Cargo.toml +++ b/axiom-codec/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "axiom-codec" -version = "0.2.0" +version = "0.2.1" authors = ["Intrinsic Technologies"] license = "MIT" edition = "2021" @@ -19,7 +19,7 @@ serde_with = { version = "2.2", optional = true } anyhow = "1.0" # halo2, features turned on by axiom-eth -axiom-eth = { version = "=0.4.0", path = "../axiom-eth", default-features = false } +axiom-eth = { version = "0.4.1", path = "../axiom-eth", default-features = false } # ethereum ethers-core = { version = "2.0.10" } diff --git a/axiom-core/Cargo.toml b/axiom-core/Cargo.toml index aa7d4fdc..639a2f36 100644 --- a/axiom-core/Cargo.toml +++ b/axiom-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "axiom-core" -version = "2.0.12" +version = "2.0.13" authors = ["Intrinsic Technologies"] license = "MIT" edition = "2021" @@ -29,7 +29,7 @@ anyhow = "1.0" hex = "0.4.3" # halo2, features turned on by axiom-eth -axiom-eth = { version = "=0.4.0", path = "../axiom-eth", default-features = false, features = ["providers", "aggregation", "evm"] } +axiom-eth = { version = "=0.4.1", path = "../axiom-eth", default-features = false, features = ["providers", "aggregation", "evm"] } # crypto ethers-core = { version = "=2.0.10" } diff --git a/axiom-eth/Cargo.toml b/axiom-eth/Cargo.toml index 82181850..3ddb7cb3 100644 --- a/axiom-eth/Cargo.toml +++ b/axiom-eth/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "axiom-eth" -version = "0.4.0" +version = "0.4.1" authors = ["Intrinsic Technologies"] license = "MIT" edition = "2021" @@ -35,7 +35,7 @@ zkevm-hashes = { git = "https://github.com/axiom-crypto/halo2-lib.git", tag = "v # crypto rlp = "=0.5.2" -ethers-core = { version = "2.0.10" } +ethers-core = { version = "=2.0.10" } # fix the version as it affects what fields are included in the `Block` struct # mpt implementation hasher = { version = "=0.1", features = ["hash-keccak"] } cita_trie = "=5.0.0" @@ -53,7 +53,7 @@ snark-verifier = { git = "https://github.com/axiom-crypto/snark-verifier.git", t snark-verifier-sdk = { git = "https://github.com/axiom-crypto/snark-verifier.git", tag = "v0.1.7-git", default-features = false } # generating circuit inputs from blockchain -ethers-providers = { version = "2.0.10", optional = true } +ethers-providers = { version = "=2.0.10", optional = true } tokio = { version = "1.28", default-features = false, features = ["rt", "rt-multi-thread", "macros"], optional = true } futures = { version = "0.3", optional = true } diff --git a/axiom-eth/src/providers/block.rs b/axiom-eth/src/providers/block.rs index 7359d510..d326d975 100644 --- a/axiom-eth/src/providers/block.rs +++ b/axiom-eth/src/providers/block.rs @@ -1,5 +1,5 @@ use ethers_core::{ - types::{Block, H256}, + types::{Block, H256, U64}, utils::keccak256, }; use ethers_providers::{JsonRpcClient, Middleware, Provider, ProviderError}; @@ -33,9 +33,36 @@ pub fn get_block_rlp_from_num( } pub fn get_block_rlp(block: &Block) -> Vec { - let withdrawals_root: Option = block.withdrawals_root; let base_fee = block.base_fee_per_gas; - let rlp_len = 15 + usize::from(base_fee.is_some()) + usize::from(withdrawals_root.is_some()); + let withdrawals_root: Option = block.withdrawals_root; + // EIP-4844: + let other = &block.other; + let mut blob_gas_used = other.get("blobGasUsed"); // EIP-4844 spec + if blob_gas_used.is_none() { + blob_gas_used = other.get("dataGasUsed"); // EIP-4788 spec + } + let blob_gas_used: Option = + blob_gas_used.map(|v| serde_json::from_value(v.clone()).unwrap()); + let mut excess_blob_gas = other.get("excessBlobGas"); // EIP-4844 spec + if excess_blob_gas.is_none() { + excess_blob_gas = other.get("excessDataGas"); // EIP-4788 spec + } + let excess_blob_gas: Option = + excess_blob_gas.map(|v| serde_json::from_value(v.clone()).unwrap()); + // EIP-4788: + let parent_beacon_block_root: Option = + other.get("parentBeaconBlockRoot").map(|v| serde_json::from_value(v.clone()).unwrap()); + + let mut rlp_len = 15; + for opt in [ + base_fee.is_some(), + withdrawals_root.is_some(), + blob_gas_used.is_some(), + excess_blob_gas.is_some(), + parent_beacon_block_root.is_some(), + ] { + rlp_len += opt as usize; + } let mut rlp = RlpStream::new_list(rlp_len); rlp.append(&block.parent_hash); rlp.append(&block.uncles_hash); @@ -54,6 +81,9 @@ pub fn get_block_rlp(block: &Block) -> Vec { rlp.append(&block.nonce.unwrap()); base_fee.map(|base_fee| rlp.append(&base_fee)); withdrawals_root.map(|withdrawals_root| rlp.append(&withdrawals_root)); + blob_gas_used.map(|blob_gas_used| rlp.append(&blob_gas_used)); + excess_blob_gas.map(|excess_blob_gas| rlp.append(&excess_blob_gas)); + parent_beacon_block_root.map(|parent_beacon_block_root| rlp.append(&parent_beacon_block_root)); let encoding: Vec = rlp.out().into(); assert_eq!(keccak256(&encoding), block.hash.unwrap().0); encoding @@ -96,4 +126,16 @@ mod tests { get_block_rlp(&block); } } + + #[test] + fn test_retry_provider_sepolia() { + let provider = setup_provider(Chain::Sepolia); + + let rt = Runtime::new().unwrap(); + let latest = rt.block_on(provider.get_block_number()).unwrap(); + for block_num in [0, 5000050, 5187023, 5187810, 5187814, latest.as_u64()] { + let block = rt.block_on(provider.get_block(block_num)).unwrap().unwrap(); + get_block_rlp(&block); + } + } } diff --git a/axiom-eth/src/providers/mod.rs b/axiom-eth/src/providers/mod.rs index 2580bc21..9ceb455e 100644 --- a/axiom-eth/src/providers/mod.rs +++ b/axiom-eth/src/providers/mod.rs @@ -20,6 +20,7 @@ pub fn setup_provider(chain: Chain) -> Provider> { Provider::new_client(&provider_uri, 10, 500).expect("could not instantiate HTTP Provider") } +/// Version of `Vec::from_hex` that works with odd-length strings. Assumes string does not start with `0x` and only has hex characters. pub fn from_hex(s: &str) -> Vec { let s = if s.len() % 2 == 1 { format!("0{s}") } else { s.to_string() }; Vec::from_hex(s).unwrap() diff --git a/axiom-query/Cargo.toml b/axiom-query/Cargo.toml index 86bec6a0..1338f925 100644 --- a/axiom-query/Cargo.toml +++ b/axiom-query/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "axiom-query" -version = "2.0.14" +version = "2.0.15" authors = ["Intrinsic Technologies"] license = "MIT" edition = "2021" @@ -35,8 +35,8 @@ rand = "0.8" rand_core = { version = "0.6", default-features = false, features = ["getrandom"] } # halo2, features turned on by axiom-eth -axiom-eth = { version = "=0.4.0", path = "../axiom-eth", default-features = false, features = ["providers", "aggregation", "evm"] } -axiom-codec = { version = "0.2.0", path = "../axiom-codec", default-features = false } +axiom-eth = { version = "=0.4.1", path = "../axiom-eth", default-features = false, features = ["providers", "aggregation", "evm"] } +axiom-codec = { version = "0.2.1", path = "../axiom-codec", default-features = false } # crypto rlp = "0.5.2"