revm_primitives/
lib.rs

1//! # revm-primitives
2//!
3//! Core primitive types and constants for the Ethereum Virtual Machine (EVM) implementation.
4//!
5//! This crate provides:
6//! - EVM constants and limits (gas, stack, code size)
7//! - Ethereum hard fork management and version control
8//! - EIP-specific constants and configuration values
9//! - Cross-platform synchronization primitives
10//! - Type aliases for common EVM concepts (storage keys/values)
11//! - Re-exports of alloy primitive types for convenience
12#![cfg_attr(not(test), warn(unused_crate_dependencies))]
13#![cfg_attr(not(feature = "std"), no_std)]
14
15#[cfg(not(feature = "std"))]
16extern crate alloc as std;
17
18pub mod constants;
19pub mod eip170;
20pub mod eip3860;
21pub mod eip4844;
22pub mod eip7702;
23pub mod eip7823;
24pub mod eip7825;
25pub mod eip7907;
26pub mod eip7918;
27pub mod hardfork;
28mod once_lock;
29
30pub use constants::*;
31pub use once_lock::OnceLock;
32
33// Reexport alloy primitives.
34
35pub use alloy_primitives::map::{self, hash_map, hash_set, HashMap, HashSet};
36pub use alloy_primitives::{
37    self, address, b256, bytes, fixed_bytes, hex, hex_literal, keccak256, ruint, uint, Address,
38    Bytes, FixedBytes, Log, LogData, TxKind, B256, I128, I256, U128, U256,
39};
40
41/// Type alias for EVM storage keys (256-bit unsigned integers).
42/// Used to identify storage slots within smart contract storage.
43pub type StorageKey = U256;
44
45/// Type alias for EVM storage values (256-bit unsigned integers).
46/// Used to store data values in smart contract storage slots.
47pub type StorageValue = U256;
48
49/// Optimize short address access.
50pub const SHORT_ADDRESS_CAP: usize = 300;
51
52/// Returns the short address from Address.
53///
54/// Short address is considered address that has 18 leading zeros
55/// and last two bytes are less than [`SHORT_ADDRESS_CAP`].
56#[inline]
57pub fn short_address(address: &Address) -> Option<usize> {
58    if address.0[..18].iter().all(|b| *b == 0) {
59        let short_address = u16::from_be_bytes([address.0[18], address.0[19]]) as usize;
60        if short_address < SHORT_ADDRESS_CAP {
61            return Some(short_address);
62        }
63    }
64    None
65}