revm_interpreter/instructions/
tx_info.rs

1use crate::{
2    gas,
3    interpreter::Interpreter,
4    interpreter_types::{InterpreterTypes, LoopControl, RuntimeFlag, StackTr},
5    Host,
6};
7use context_interface::{Block, Transaction, TransactionType};
8use primitives::U256;
9
10pub fn gasprice<WIRE: InterpreterTypes, H: Host + ?Sized>(
11    interpreter: &mut Interpreter<WIRE>,
12    host: &mut H,
13) {
14    gas!(interpreter, gas::BASE);
15    let basefee = host.block().basefee();
16    push!(
17        interpreter,
18        U256::from(host.tx().effective_gas_price(basefee as u128))
19    );
20}
21
22pub fn origin<WIRE: InterpreterTypes, H: Host + ?Sized>(
23    interpreter: &mut Interpreter<WIRE>,
24    host: &mut H,
25) {
26    gas!(interpreter, gas::BASE);
27    push!(interpreter, host.tx().caller().into_word().into());
28}
29
30// EIP-4844: Shard Blob Transactions
31pub fn blob_hash<WIRE: InterpreterTypes, H: Host + ?Sized>(
32    interpreter: &mut Interpreter<WIRE>,
33    host: &mut H,
34) {
35    check!(interpreter, CANCUN);
36    gas!(interpreter, gas::VERYLOW);
37    popn_top!([], index, interpreter);
38    let i = as_usize_saturated!(index);
39    let tx = &host.tx();
40    *index = if tx.tx_type() == TransactionType::Eip4844 {
41        tx.blob_versioned_hashes()
42            .get(i)
43            .cloned()
44            .map(|b| U256::from_be_bytes(*b))
45            .unwrap_or(U256::ZERO)
46    } else {
47        U256::ZERO
48    };
49}