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>(
18 context: InstructionContext<'_, H, WIRE>,
19) {
20 gas!(context.interpreter, gas::BASE);
21 push!(
22 context.interpreter,
23 context.host.beneficiary().into_word().into()
24 );
25}
26
27pub fn timestamp<WIRE: InterpreterTypes, H: Host + ?Sized>(
28 context: InstructionContext<'_, H, WIRE>,
29) {
30 gas!(context.interpreter, gas::BASE);
31 push!(context.interpreter, context.host.timestamp());
32}
33
34pub fn block_number<WIRE: InterpreterTypes, H: Host + ?Sized>(
35 context: InstructionContext<'_, H, WIRE>,
36) {
37 gas!(context.interpreter, gas::BASE);
38 push!(context.interpreter, U256::from(context.host.block_number()));
39}
40
41pub fn difficulty<WIRE: InterpreterTypes, H: Host + ?Sized>(
42 context: InstructionContext<'_, H, WIRE>,
43) {
44 gas!(context.interpreter, gas::BASE);
45 if context
46 .interpreter
47 .runtime_flag
48 .spec_id()
49 .is_enabled_in(MERGE)
50 {
51 push!(context.interpreter, context.host.prevrandao().unwrap());
53 } else {
54 push!(context.interpreter, context.host.difficulty());
55 }
56}
57
58pub fn gaslimit<WIRE: InterpreterTypes, H: Host + ?Sized>(
59 context: InstructionContext<'_, H, WIRE>,
60) {
61 gas!(context.interpreter, gas::BASE);
62 push!(context.interpreter, context.host.gas_limit());
63}
64
65pub fn basefee<WIRE: InterpreterTypes, H: Host + ?Sized>(context: InstructionContext<'_, H, WIRE>) {
67 check!(context.interpreter, LONDON);
68 gas!(context.interpreter, gas::BASE);
69 push!(context.interpreter, context.host.basefee());
70}
71
72pub fn blob_basefee<WIRE: InterpreterTypes, H: Host + ?Sized>(
74 context: InstructionContext<'_, H, WIRE>,
75) {
76 check!(context.interpreter, CANCUN);
77 gas!(context.interpreter, gas::BASE);
78 push!(context.interpreter, context.host.blob_gasprice());
79}