mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(l2-withdrawals): Move l2 withdrawals root computation into reth-optimism-storage (#14610)
This commit is contained in:
@ -11,10 +11,29 @@ repository.workspace = true
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-primitives.workspace = true
|
||||
reth-trie-common.workspace = true
|
||||
reth-storage-api.workspace = true
|
||||
|
||||
# ethereum
|
||||
alloy-primitives.workspace = true
|
||||
revm.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
reth-codecs.workspace = true
|
||||
reth-db-api.workspace = true
|
||||
reth-prune-types.workspace = true
|
||||
reth-stages-types.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"reth-primitives/std",
|
||||
"reth-trie-common/std",
|
||||
"reth-storage-api/std",
|
||||
"alloy-primitives/std",
|
||||
"revm/std",
|
||||
"reth-prune-types/std",
|
||||
"reth-stages-types/std",
|
||||
]
|
||||
|
||||
@ -6,6 +6,10 @@
|
||||
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
|
||||
)]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
pub mod predeploys;
|
||||
pub use predeploys::withdrawals_root;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
29
crates/optimism/storage/src/predeploys.rs
Normal file
29
crates/optimism/storage/src/predeploys.rs
Normal file
@ -0,0 +1,29 @@
|
||||
//! Utilities for accessing Optimism predeploy state
|
||||
|
||||
use alloy_primitives::{address, Address, B256};
|
||||
use reth_storage_api::{errors::ProviderResult, StorageRootProvider};
|
||||
use reth_trie_common::HashedStorage;
|
||||
use revm::database::BundleState;
|
||||
|
||||
/// The L2 contract `L2ToL1MessagePasser`, stores commitments to withdrawal transactions.
|
||||
pub const ADDRESS_L2_TO_L1_MESSAGE_PASSER: Address =
|
||||
address!("4200000000000000000000000000000000000016");
|
||||
|
||||
/// Computes the storage root of predeploy `L2ToL1MessagePasser.sol` with state updates from block
|
||||
/// execution.
|
||||
pub fn withdrawals_root<DB: StorageRootProvider>(
|
||||
state_updates: &BundleState,
|
||||
state: DB,
|
||||
) -> ProviderResult<B256> {
|
||||
// if l2 withdrawals transactions were executed, use predeploy storage updates in storage root
|
||||
// computation
|
||||
let hashed_storage_updates =
|
||||
state_updates.state().get(&ADDRESS_L2_TO_L1_MESSAGE_PASSER).map(|acc| {
|
||||
HashedStorage::from_plain_storage(
|
||||
acc.status,
|
||||
acc.storage.iter().map(|(slot, value)| (slot, &value.present_value)),
|
||||
)
|
||||
});
|
||||
|
||||
state.storage_root(ADDRESS_L2_TO_L1_MESSAGE_PASSER, hashed_storage_updates.unwrap_or_default())
|
||||
}
|
||||
Reference in New Issue
Block a user