tempo_revm/
instructions.rs

1use crate::evm::TempoContext;
2use alloy_evm::Database;
3use revm::{
4    handler::instructions::EthInstructions,
5    interpreter::{Instruction, InstructionContext, interpreter::EthInterpreter, push},
6};
7
8/// Instruction ID for opcode returning milliseconds timestamp.
9const MILLIS_TIMESTAMP: u8 = 0x4F;
10
11/// Gas cost for [`MILLIS_TIMESTAMP`] instruction. Same as other opcodes accessing block information.
12const MILLIS_TIMESTAMP_GAS_COST: u64 = 2;
13
14/// Alias for Tempo-specific [`InstructionContext`].
15type TempoInstructionContext<'a, DB> = InstructionContext<'a, TempoContext<DB>, EthInterpreter>;
16
17/// Opcode returning current timestamp in milliseconds.
18fn millis_timestamp<DB: Database>(context: TempoInstructionContext<'_, DB>) {
19    push!(context.interpreter, context.host.block.timestamp_millis());
20}
21
22/// Returns configured instructions table for Tempo.
23pub(crate) fn tempo_instructions<DB: Database>() -> EthInstructions<EthInterpreter, TempoContext<DB>>
24{
25    let mut instructions = EthInstructions::new_mainnet();
26    instructions.insert_instruction(
27        MILLIS_TIMESTAMP,
28        Instruction::new(millis_timestamp, MILLIS_TIMESTAMP_GAS_COST),
29    );
30    instructions
31}