revm_interpreter/instructions/
block_info.rs1use crate::{
2 gas,
3 interpreter_types::{InterpreterTypes, RuntimeFlag, StackTr},
4 Host,
5};
6use primitives::{hardfork::SpecId::*, U256};
7
8use crate::InstructionContext;
9
10pub fn chainid<WIRE: InterpreterTypes, H: Host + ?Sized>(context: InstructionContext<'_, H, WIRE>) {
12 check!(context.interpreter, ISTANBUL);
13 gas!(context.interpreter, gas::BASE);
14 push!(context.interpreter, context.host.chain_id());
15}
16
17pub fn coinbase<WIRE: InterpreterTypes, H: Host + ?Sized>(
21 context: InstructionContext<'_, H, WIRE>,
22) {
23 gas!(context.interpreter, gas::BASE);
24 push!(
25 context.interpreter,
26 context.host.beneficiary().into_word().into()
27 );
28}
29
30pub fn timestamp<WIRE: InterpreterTypes, H: Host + ?Sized>(
34 context: InstructionContext<'_, H, WIRE>,
35) {
36 gas!(context.interpreter, gas::BASE);
37 push!(context.interpreter, context.host.timestamp());
38}
39
40pub fn block_number<WIRE: InterpreterTypes, H: Host + ?Sized>(
44 context: InstructionContext<'_, H, WIRE>,
45) {
46 gas!(context.interpreter, gas::BASE);
47 push!(context.interpreter, U256::from(context.host.block_number()));
48}
49
50pub fn difficulty<WIRE: InterpreterTypes, H: Host + ?Sized>(
54 context: InstructionContext<'_, H, WIRE>,
55) {
56 gas!(context.interpreter, gas::BASE);
57 if context
58 .interpreter
59 .runtime_flag
60 .spec_id()
61 .is_enabled_in(MERGE)
62 {
63 push!(context.interpreter, context.host.prevrandao().unwrap());
65 } else {
66 push!(context.interpreter, context.host.difficulty());
67 }
68}
69
70pub fn gaslimit<WIRE: InterpreterTypes, H: Host + ?Sized>(
74 context: InstructionContext<'_, H, WIRE>,
75) {
76 gas!(context.interpreter, gas::BASE);
77 push!(context.interpreter, context.host.gas_limit());
78}
79
80pub fn basefee<WIRE: InterpreterTypes, H: Host + ?Sized>(context: InstructionContext<'_, H, WIRE>) {
82 check!(context.interpreter, LONDON);
83 gas!(context.interpreter, gas::BASE);
84 push!(context.interpreter, context.host.basefee());
85}
86
87pub fn blob_basefee<WIRE: InterpreterTypes, H: Host + ?Sized>(
89 context: InstructionContext<'_, H, WIRE>,
90) {
91 check!(context.interpreter, CANCUN);
92 gas!(context.interpreter, gas::BASE);
93 push!(context.interpreter, context.host.blob_gasprice());
94}