revm_interpreter/instructions/
block_info.rs1use crate::{
2 interpreter_types::{InterpreterTypes as ITy, RuntimeFlag, StackTr},
3 Host, InstructionExecResult as Result,
4};
5use primitives::hardfork::SpecId::*;
6
7use crate::InstructionContext as Ictx;
8
9pub fn chainid<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
11 check!(context.interpreter, ISTANBUL);
12 push!(context.interpreter, context.host.chain_id());
13 Ok(())
14}
15
16pub fn coinbase<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
20 push!(
21 context.interpreter,
22 context.host.beneficiary().into_word().into()
23 );
24 Ok(())
25}
26
27pub fn timestamp<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
31 push!(context.interpreter, context.host.timestamp());
32 Ok(())
33}
34
35pub fn block_number<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
39 push!(context.interpreter, context.host.block_number());
40 Ok(())
41}
42
43pub fn difficulty<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
47 if context
48 .interpreter
49 .runtime_flag
50 .spec_id()
51 .is_enabled_in(MERGE)
52 {
53 push!(context.interpreter, context.host.prevrandao().unwrap());
55 } else {
56 push!(context.interpreter, context.host.difficulty());
57 }
58 Ok(())
59}
60
61pub fn gaslimit<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
65 push!(context.interpreter, context.host.gas_limit());
66 Ok(())
67}
68
69pub fn basefee<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
71 check!(context.interpreter, LONDON);
72 push!(context.interpreter, context.host.basefee());
73 Ok(())
74}
75
76pub fn blob_basefee<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
78 check!(context.interpreter, CANCUN);
79 push!(context.interpreter, context.host.blob_gasprice());
80 Ok(())
81}
82
83pub fn slot_num<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
85 check!(context.interpreter, AMSTERDAM);
86 push!(context.interpreter, context.host.slot_num());
87 Ok(())
88}