revm_context_interface/
block.rs

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