From 39bcc49194b4225358bf92bc264ff0a973403df6 Mon Sep 17 00:00:00 2001 From: sprites0 <199826320+sprites0@users.noreply.github.com> Date: Thu, 17 Jul 2025 20:57:44 -0400 Subject: [PATCH 1/4] chore: lint --- bin/reth/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/reth/src/main.rs b/bin/reth/src/main.rs index 08da17655..a19ff491a 100644 --- a/bin/reth/src/main.rs +++ b/bin/reth/src/main.rs @@ -9,7 +9,7 @@ mod serialized; mod spot_meta; mod tx_forwarder; -use std::{collections::BTreeMap, path::PathBuf, sync::Arc}; +use std::{collections::BTreeMap, sync::Arc}; use block_ingest::BlockIngest; use call_forwarder::CallForwarderApiServer; From dbcd73884e5f00c589b266de4b4997d55c725a6f Mon Sep 17 00:00:00 2001 From: sprites0 <199826320+sprites0@users.noreply.github.com> Date: Thu, 17 Jul 2025 20:59:32 -0400 Subject: [PATCH 2/4] feat: Ingest highest_precompile_address --- bin/reth/src/block_ingest.rs | 7 +++++-- bin/reth/src/serialized.rs | 1 + crates/ethereum/evm/src/lib.rs | 9 +++++++-- crates/hyperliquid-types/src/lib.rs | 9 +++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/bin/reth/src/block_ingest.rs b/bin/reth/src/block_ingest.rs index 090d845e8..09b99e9b6 100644 --- a/bin/reth/src/block_ingest.rs +++ b/bin/reth/src/block_ingest.rs @@ -12,7 +12,7 @@ use alloy_rpc_types::engine::{ use jsonrpsee::http_client::{transport::HttpBackend, HttpClient}; use reth::network::PeersHandleProvider; use reth_chainspec::{EthChainSpec, EthereumHardforks}; -use reth_hyperliquid_types::PrecompilesCache; +use reth_hyperliquid_types::{PrecompileData, PrecompilesCache}; use reth_node_api::{Block, FullNodeComponents, PayloadTypes}; use reth_node_builder::EngineTypes; use reth_node_builder::NodeTypesWithEngine; @@ -191,7 +191,10 @@ impl BlockIngest { let mut u_cache = cache.lock().await; let mut u_pre_cache = precompiles_cache.lock(); for blk in new_blocks { - let precompiles = blk.read_precompile_calls.clone(); + let precompiles = PrecompileData { + precompiles: blk.read_precompile_calls.clone(), + highest_precompile_address: blk.highest_precompile_address, + }; let h = match &blk.block { EvmBlock::Reth115(b) => { let block_number = b.header().number() as u64; diff --git a/bin/reth/src/serialized.rs b/bin/reth/src/serialized.rs index 49dec5740..8ea87c6fe 100644 --- a/bin/reth/src/serialized.rs +++ b/bin/reth/src/serialized.rs @@ -11,6 +11,7 @@ pub(crate) struct BlockAndReceipts { pub system_txs: Vec, #[serde(default)] pub read_precompile_calls: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>, + pub highest_precompile_address: Option
, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/crates/ethereum/evm/src/lib.rs b/crates/ethereum/evm/src/lib.rs index b601df299..d014f1cd1 100644 --- a/crates/ethereum/evm/src/lib.rs +++ b/crates/ethereum/evm/src/lib.rs @@ -24,6 +24,7 @@ pub use alloy_evm::EthEvm; use alloy_primitives::Address; use alloy_primitives::U160; use alloy_primitives::U256; +use reth_hyperliquid_types::PrecompileData; use core::{convert::Infallible, fmt::Debug}; use parking_lot::RwLock; use reth_chainspec::{ChainSpec, EthChainSpec, MAINNET}; @@ -200,6 +201,7 @@ impl ConfigureEvmEnv for EthEvmConfig { pub(crate) struct BlockAndReceipts { #[serde(default)] pub read_precompile_calls: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>, + pub highest_precompile_address: Option
, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -228,7 +230,7 @@ pub(crate) fn collect_s3_block(ingest_path: PathBuf, height: u64) -> Option Option)>> { +) -> Option { let mut u_cache = precompiles_cache.lock(); u_cache.remove(&height) } @@ -244,7 +246,10 @@ pub(crate) fn collect_block( if let Some(calls) = get_locally_sourced_precompiles_for_height(shared_state.precompiles_cache, height) { - return Some(BlockAndReceipts { read_precompile_calls: calls }); + return Some(BlockAndReceipts { + read_precompile_calls: calls.precompiles, + highest_precompile_address: calls.highest_precompile_address, + }); } } // Fallback to s3 always diff --git a/crates/hyperliquid-types/src/lib.rs b/crates/hyperliquid-types/src/lib.rs index 70d19119e..b7c16cbea 100644 --- a/crates/hyperliquid-types/src/lib.rs +++ b/crates/hyperliquid-types/src/lib.rs @@ -18,5 +18,10 @@ pub enum ReadPrecompileResult { UnexpectedError, } -pub type PrecompilesCache = - Arc)>>>>; +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PrecompileData { + pub precompiles: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>, + pub highest_precompile_address: Option
, +} + +pub type PrecompilesCache = Arc>>; From 4d2d2ae273456d758f4c49b46745cdceff33c0cb Mon Sep 17 00:00:00 2001 From: sprites0 <199826320+sprites0@users.noreply.github.com> Date: Thu, 17 Jul 2025 21:04:09 -0400 Subject: [PATCH 3/4] feat: Use highest_precompile_address for all blocks This implements https://github.com/hyperliquid-dex/hyper-evm-sync/pull/5 . --- crates/ethereum/evm/src/lib.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/crates/ethereum/evm/src/lib.rs b/crates/ethereum/evm/src/lib.rs index d014f1cd1..a4822d5f0 100644 --- a/crates/ethereum/evm/src/lib.rs +++ b/crates/ethereum/evm/src/lib.rs @@ -21,15 +21,13 @@ use alloc::sync::Arc; use alloy_consensus::{BlockHeader, Header}; use alloy_evm::eth::EthEvmContext; pub use alloy_evm::EthEvm; -use alloy_primitives::Address; -use alloy_primitives::U160; -use alloy_primitives::U256; -use reth_hyperliquid_types::PrecompileData; +use alloy_primitives::{address, Address, U160, U256}; use core::{convert::Infallible, fmt::Debug}; use parking_lot::RwLock; use reth_chainspec::{ChainSpec, EthChainSpec, MAINNET}; use reth_evm::Database; use reth_evm::{ConfigureEvm, ConfigureEvmEnv, EvmEnv, EvmFactory, NextBlockEnvAttributes}; +use reth_hyperliquid_types::PrecompileData; use reth_hyperliquid_types::{PrecompilesCache, ReadPrecompileInput, ReadPrecompileResult}; use reth_node_builder::HyperliquidSharedState; use reth_primitives::SealedBlock; @@ -256,6 +254,8 @@ pub(crate) fn collect_block( collect_s3_block(ingest_path, height) } +const WARM_PRECOMPILES_BLOCK_NUMBER: u64 = 8_197_684; + impl EvmFactory for HyperliquidEvmFactory { type Evm, EthInterpreter>> = EthEvm>>; @@ -277,10 +277,16 @@ impl EvmFactory for HyperliquidEvmFactory { .map(|(address, calls)| (address, HashMap::from_iter(calls.into_iter()))) .collect(); - // NOTE: Hotfix but semantically correct. Will be removed once hl-node pipeline is updated (#17) - if input.block_env.number >= 7000000 { - for i in 0x800..=0x80D { - cache.entry(Address::from(U160::from(i))).or_insert(HashMap::new()); + if input.block_env.number >= WARM_PRECOMPILES_BLOCK_NUMBER { + let highest_precompile_address = block + .highest_precompile_address + .unwrap_or(address!("0x000000000000000000000000000000000000080d")); + for i in 0x800.. { + let address = Address::from(U160::from(i)); + if address > highest_precompile_address { + break; + } + cache.entry(address).or_insert(HashMap::new()); } } From 15685daef7bf80b6a856eacdf5cc513246507324 Mon Sep 17 00:00:00 2001 From: sprites0 <199826320+sprites0@users.noreply.github.com> Date: Thu, 17 Jul 2025 21:07:12 -0400 Subject: [PATCH 4/4] chore: lint --- crates/ethereum/evm/src/execute.rs | 6 ------ crates/ethereum/evm/src/precompile_replay.rs | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index 2c6293c09..fcbac3f83 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -27,12 +27,6 @@ use reth_primitives_traits::{transaction::signed::is_impersonated_tx, NodePrimit use reth_revm::{ context_interface::result::ResultAndState, db::State, state::Bytecode, DatabaseCommit, }; -use std::{ - cell::RefCell, - sync::Mutex, - time::{Duration, Instant}, -}; -use tracing::info; /// Factory for [`EthExecutionStrategy`]. #[derive(Debug, Clone)] diff --git a/crates/ethereum/evm/src/precompile_replay.rs b/crates/ethereum/evm/src/precompile_replay.rs index 09b24d511..9293bb494 100644 --- a/crates/ethereum/evm/src/precompile_replay.rs +++ b/crates/ethereum/evm/src/precompile_replay.rs @@ -5,7 +5,7 @@ use reth_revm::{ context::{Cfg, ContextTr}, handler::{EthPrecompiles, PrecompileProvider}, interpreter::{Gas, InstructionResult, InterpreterResult}, - precompile::{PrecompileError, PrecompileErrors}, + precompile::PrecompileErrors, }; use std::{collections::HashMap, sync::Arc}; @@ -59,7 +59,7 @@ impl PrecompileProvider for ReplayPrecompile { let Some(get) = precompile_calls.get(&input) else { result.gas.spend_all(); result.result = InstructionResult::PrecompileError; - return Ok(Some(result)) + return Ok(Some(result)); }; return match *get {