revm_context_interface/
block.rs

1//! Block related types and functions.
2//!
3//! [`Block`] trait is used to retrieve block information required for execution.
4pub mod blob;
5
6pub use blob::{calc_blob_gasprice, calc_excess_blob_gas, BlobExcessGasAndPrice};
7
8use auto_impl::auto_impl;
9use primitives::{Address, B256, U256};
10
11/// Trait for retrieving block information required for execution.
12#[auto_impl(&, &mut, Box, Arc)]
13pub trait Block {
14    /// The number of ancestor blocks of this block (block height).
15    fn number(&self) -> U256;
16
17    /// Beneficiary (Coinbase, miner) is a address that have signed the block.
18    ///
19    /// This is the receiver address of priority gas rewards.
20    fn beneficiary(&self) -> Address;
21
22    /// The timestamp of the block in seconds since the UNIX epoch.
23    fn timestamp(&self) -> U256;
24
25    /// The gas limit of the block.
26    fn gas_limit(&self) -> u64;
27
28    /// The base fee per gas, added in the London upgrade with [EIP-1559].
29    ///
30    /// [EIP-1559]: https://eips.ethereum.org/EIPS/eip-1559
31    fn basefee(&self) -> u64;
32
33    /// The difficulty of the block.
34    ///
35    /// Unused after the Paris (AKA the merge) upgrade, and replaced by `prevrandao`.
36    fn difficulty(&self) -> U256;
37
38    /// The output of the randomness beacon provided by the beacon chain.
39    ///
40    /// Replaces `difficulty` after the Paris (AKA the merge) upgrade with [EIP-4399].
41    ///
42    /// Note: `prevrandao` can be found in a block in place of `mix_hash`.
43    ///
44    /// [EIP-4399]: https://eips.ethereum.org/EIPS/eip-4399
45    fn prevrandao(&self) -> Option<B256>;
46
47    /// Excess blob gas and blob gasprice.
48    /// See also [`calc_excess_blob_gas`]
49    /// and [`calc_blob_gasprice`].
50    ///
51    /// Incorporated as part of the Cancun upgrade via [EIP-4844].
52    ///
53    /// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844
54    fn blob_excess_gas_and_price(&self) -> Option<BlobExcessGasAndPrice>;
55
56    /// See [EIP-4844] and [`calc_blob_gasprice`].
57    ///
58    /// Returns `None` if `Cancun` is not enabled.
59    ///
60    /// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844
61    fn blob_gasprice(&self) -> Option<u128> {
62        self.blob_excess_gas_and_price().map(|a| a.blob_gasprice)
63    }
64
65    /// Return `blob_excess_gas` header field. See [EIP-4844].
66    ///
67    /// Returns `None` if `Cancun` is not enabled.
68    ///
69    /// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844
70    fn blob_excess_gas(&self) -> Option<u64> {
71        self.blob_excess_gas_and_price().map(|a| a.excess_blob_gas)
72    }
73}