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