pallet_revive/vm/evm/instructions/
block_info.rs1use super::Context;
19use crate::{
20 vm::{
21 evm::{U256Converter, BASE_FEE, DIFFICULTY},
22 Ext,
23 },
24 RuntimeCosts,
25};
26use revm::{
27 interpreter::gas as revm_gas,
28 primitives::{Address, U256},
29};
30use sp_core::H160;
31
32pub fn chainid<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
34 gas_legacy!(context.interpreter, revm_gas::BASE);
35 push!(context.interpreter, U256::from(context.interpreter.extend.chain_id()));
36}
37
38pub fn coinbase<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
42 gas!(context.interpreter, RuntimeCosts::BlockAuthor);
43 let coinbase: Address =
44 context.interpreter.extend.block_author().unwrap_or(H160::zero()).0.into();
45 push!(context.interpreter, coinbase.into_word().into());
46}
47
48pub fn timestamp<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
52 gas!(context.interpreter, RuntimeCosts::Now);
53 let timestamp = context.interpreter.extend.now();
54 push!(context.interpreter, timestamp.into_revm_u256());
55}
56
57pub fn block_number<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
61 gas!(context.interpreter, RuntimeCosts::BlockNumber);
62 let block_number = context.interpreter.extend.block_number();
63 push!(context.interpreter, block_number.into_revm_u256());
64}
65
66pub fn difficulty<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
70 gas_legacy!(context.interpreter, revm_gas::BASE);
71 push!(context.interpreter, U256::from(DIFFICULTY));
72}
73
74pub fn gaslimit<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
78 gas!(context.interpreter, RuntimeCosts::GasLimit);
79 let gas_limit = context.interpreter.extend.gas_limit();
80 push!(context.interpreter, U256::from(gas_limit));
81}
82
83pub fn basefee<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
85 gas!(context.interpreter, RuntimeCosts::BaseFee);
86 push!(context.interpreter, BASE_FEE.into_revm_u256());
87}
88
89pub fn blob_basefee<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
91 context.interpreter.halt(revm::interpreter::InstructionResult::NotActivated);
92}