revm_interpreter/instructions/
block_info.rs1use crate::{
2 interpreter_types::{InterpreterTypes, RuntimeFlag, StackTr},
3 Host,
4};
5use primitives::hardfork::SpecId::*;
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());
13}
14
15pub fn coinbase<WIRE: InterpreterTypes, H: Host + ?Sized>(
19 context: InstructionContext<'_, H, WIRE>,
20) {
21 push!(
22 context.interpreter,
23 context.host.beneficiary().into_word().into()
24 );
25}
26
27pub fn timestamp<WIRE: InterpreterTypes, H: Host + ?Sized>(
31 context: InstructionContext<'_, H, WIRE>,
32) {
33 push!(context.interpreter, context.host.timestamp());
34}
35
36pub fn block_number<WIRE: InterpreterTypes, H: Host + ?Sized>(
40 context: InstructionContext<'_, H, WIRE>,
41) {
42 push!(context.interpreter, context.host.block_number());
43}
44
45pub fn difficulty<WIRE: InterpreterTypes, H: Host + ?Sized>(
49 context: InstructionContext<'_, H, WIRE>,
50) {
51 if context
52 .interpreter
53 .runtime_flag
54 .spec_id()
55 .is_enabled_in(MERGE)
56 {
57 push!(context.interpreter, context.host.prevrandao().unwrap());
59 } else {
60 push!(context.interpreter, context.host.difficulty());
61 }
62}
63
64pub fn gaslimit<WIRE: InterpreterTypes, H: Host + ?Sized>(
68 context: InstructionContext<'_, H, WIRE>,
69) {
70 push!(context.interpreter, context.host.gas_limit());
71}
72
73pub fn basefee<WIRE: InterpreterTypes, H: Host + ?Sized>(context: InstructionContext<'_, H, WIRE>) {
75 check!(context.interpreter, LONDON);
76 push!(context.interpreter, context.host.basefee());
77}
78
79pub fn blob_basefee<WIRE: InterpreterTypes, H: Host + ?Sized>(
81 context: InstructionContext<'_, H, WIRE>,
82) {
83 check!(context.interpreter, CANCUN);
84 push!(context.interpreter, context.host.blob_gasprice());
85}