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