diff --git a/evm_loader/program/src/evm/mod.rs b/evm_loader/program/src/evm/mod.rs index e8df6f32c7..9014f12a3d 100644 --- a/evm_loader/program/src/evm/mod.rs +++ b/evm_loader/program/src/evm/mod.rs @@ -25,11 +25,7 @@ mod buffer; pub mod database; mod memory; mod opcode; -#[cfg(feature = "library")] -mod opcode_async; -#[cfg(not(feature = "library"))] -mod opcode_sync; -mod opcode_values; +mod opcode_table; mod precompile; mod stack; #[cfg(feature = "library")] @@ -404,7 +400,8 @@ impl Machine { Ok(result) => result, Err(e) => { let message = build_revert_message(&e.to_string()); - self.opcode_revert_impl(Buffer::from_slice(&message), backend)? + self.opcode_revert_impl(Buffer::from_slice(&message), backend) + .await? } }; diff --git a/evm_loader/program/src/evm/opcode.rs b/evm_loader/program/src/evm/opcode.rs index 79688df311..f1f8c9b48d 100644 --- a/evm_loader/program/src/evm/opcode.rs +++ b/evm_loader/program/src/evm/opcode.rs @@ -21,9 +21,11 @@ pub enum Action { Noop, } +#[allow(clippy::unused_async)] impl Machine { /// Unknown instruction - pub fn opcode_unknown(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_unknown(&mut self, _backend: &mut B) -> Result { Err(Error::UnknownOpcode( self.context.contract, self.execution_code[self.pc], @@ -31,7 +33,8 @@ impl Machine { } /// (u)int256 addition modulo 2**256 - pub fn opcode_add(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_add(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_u256()?; let b = self.stack.pop_u256()?; let c = a.wrapping_add(b); @@ -42,7 +45,8 @@ impl Machine { } /// (u)int256 multiplication modulo 2**256 - pub fn opcode_mul(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_mul(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_u256()?; let b = self.stack.pop_u256()?; let c = a.wrapping_mul(b); @@ -53,7 +57,8 @@ impl Machine { } /// (u)int256 subtraction modulo 2**256 - pub fn opcode_sub(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_sub(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_u256()?; let b = self.stack.pop_u256()?; let c = a.wrapping_sub(b); @@ -64,7 +69,8 @@ impl Machine { } /// uint256 division - pub fn opcode_div(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_div(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_u256()?; let b = self.stack.pop_u256()?; @@ -79,7 +85,8 @@ impl Machine { } /// int256 division - pub fn opcode_sdiv(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_sdiv(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_i256()?; let b = self.stack.pop_i256()?; @@ -95,7 +102,8 @@ impl Machine { } /// uint256 modulus - pub fn opcode_mod(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_mod(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_u256()?; let b = self.stack.pop_u256()?; @@ -110,7 +118,8 @@ impl Machine { } /// int256 modulus - pub fn opcode_smod(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_smod(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_i256()?; let b = self.stack.pop_i256()?; @@ -127,7 +136,8 @@ impl Machine { /// (u)int256 addition modulo M /// (a + b) % m /// - pub fn opcode_addmod(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_addmod(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_u256()?; let b = self.stack.pop_u256()?; let m = self.stack.pop_u256()?; @@ -158,7 +168,8 @@ impl Machine { /// (u)int256 multiplication modulo M /// (a * b) % m /// - pub fn opcode_mulmod(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_mulmod(&mut self, _backend: &mut B) -> Result { let mut a = self.stack.pop_u256()?; let mut b = self.stack.pop_u256()?; let m = self.stack.pop_u256()?; @@ -203,7 +214,8 @@ impl Machine { /// uint256 exponentiation modulo 2**256 /// a ** b - pub fn opcode_exp(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_exp(&mut self, _backend: &mut B) -> Result { let mut a = self.stack.pop_u256()?; let mut b = self.stack.pop_u256()?; @@ -232,7 +244,8 @@ impl Machine { } /// sign extends x from (b + 1) * 8 bits to 256 bits. - pub fn opcode_signextend(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_signextend(&mut self, _backend: &mut B) -> Result { let b = self.stack.pop_u256()?; let x = self.stack.pop_u256()?; @@ -257,7 +270,8 @@ impl Machine { /// uint256 comparison /// a < b - pub fn opcode_lt(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_lt(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_u256()?; let b = self.stack.pop_u256()?; @@ -268,7 +282,8 @@ impl Machine { /// uint256 comparison /// a > b - pub fn opcode_gt(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_gt(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_u256()?; let b = self.stack.pop_u256()?; @@ -279,7 +294,8 @@ impl Machine { /// int256 comparison /// a < b - pub fn opcode_slt(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_slt(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_i256()?; let b = self.stack.pop_i256()?; self.stack.push_bool(a < b)?; @@ -289,7 +305,8 @@ impl Machine { /// int256 comparison /// a > b - pub fn opcode_sgt(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_sgt(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_i256()?; let b = self.stack.pop_i256()?; self.stack.push_bool(a > b)?; @@ -299,7 +316,8 @@ impl Machine { /// (u)int256 equality /// a == b - pub fn opcode_eq(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_eq(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_u256()?; let b = self.stack.pop_u256()?; @@ -310,7 +328,8 @@ impl Machine { /// (u)int256 is zero /// a == 0 - pub fn opcode_iszero(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_iszero(&mut self, _backend: &mut B) -> Result { let result = { let a = self.stack.pop_array()?; a == &[0_u8; 32] @@ -322,7 +341,8 @@ impl Machine { } /// 256-bit bitwise and - pub fn opcode_and(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_and(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_u256()?; let b = self.stack.pop_u256()?; @@ -332,7 +352,8 @@ impl Machine { } /// 256-bit bitwise or - pub fn opcode_or(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_or(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_u256()?; let b = self.stack.pop_u256()?; @@ -342,7 +363,8 @@ impl Machine { } /// 256-bit bitwise xor - pub fn opcode_xor(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_xor(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_u256()?; let b = self.stack.pop_u256()?; @@ -352,7 +374,8 @@ impl Machine { } /// 256-bit bitwise not - pub fn opcode_not(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_not(&mut self, _backend: &mut B) -> Result { let a = self.stack.pop_u256()?; self.stack.push_u256(!a)?; @@ -360,7 +383,8 @@ impl Machine { } /// ith byte of (u)int256 x, counting from most significant byte - pub fn opcode_byte(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_byte(&mut self, _backend: &mut B) -> Result { let result = { let i = self.stack.pop_u256()?; let x = self.stack.pop_array()?; @@ -378,7 +402,8 @@ impl Machine { } /// 256-bit shift left - pub fn opcode_shl(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_shl(&mut self, _backend: &mut B) -> Result { let shift = self.stack.pop_u256()?; let value = self.stack.pop_u256()?; @@ -392,7 +417,8 @@ impl Machine { } /// 256-bit shift right - pub fn opcode_shr(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_shr(&mut self, _backend: &mut B) -> Result { let shift = self.stack.pop_u256()?; let value = self.stack.pop_u256()?; @@ -406,7 +432,8 @@ impl Machine { } /// arithmetic int256 shift right - pub fn opcode_sar(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_sar(&mut self, _backend: &mut B) -> Result { let (shift, value) = { let shift = self.stack.pop_u256()?; let value = self.stack.pop_i256()?; @@ -423,7 +450,8 @@ impl Machine { } /// hash = keccak256(memory[offset:offset+length]) - pub fn opcode_sha3(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_sha3(&mut self, _backend: &mut B) -> Result { use solana_program::keccak::{hash, Hash}; let offset = self.stack.pop_usize()?; @@ -438,7 +466,8 @@ impl Machine { } /// address of the executing contract - pub fn opcode_address(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_address(&mut self, _backend: &mut B) -> Result { self.stack.push_address(&self.context.contract)?; Ok(Action::Continue) @@ -459,7 +488,8 @@ impl Machine { /// transaction origin address /// tx.origin - pub fn opcode_origin(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_origin(&mut self, _backend: &mut B) -> Result { self.stack.push_address(&self.origin)?; Ok(Action::Continue) @@ -467,7 +497,8 @@ impl Machine { /// message caller address /// msg.caller - pub fn opcode_caller(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_caller(&mut self, _backend: &mut B) -> Result { self.stack.push_address(&self.context.caller)?; Ok(Action::Continue) @@ -475,7 +506,8 @@ impl Machine { /// message funds in wei /// msg.value - pub fn opcode_callvalue(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_callvalue(&mut self, _backend: &mut B) -> Result { self.stack.push_u256(self.context.value)?; Ok(Action::Continue) @@ -483,7 +515,8 @@ impl Machine { /// reads a (u)int256 from message data /// msg.data[i:i+32] - pub fn opcode_calldataload(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_calldataload(&mut self, _backend: &mut B) -> Result { let index = self.stack.pop_usize()?; if let Some(buffer) = self.call_data.get(index..index + 32) { @@ -504,14 +537,16 @@ impl Machine { /// message data length in bytes /// msg.data.size - pub fn opcode_calldatasize(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_calldatasize(&mut self, _backend: &mut B) -> Result { self.stack.push_usize(self.call_data.len())?; Ok(Action::Continue) } /// copy message data to memory - pub fn opcode_calldatacopy(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_calldatacopy(&mut self, _backend: &mut B) -> Result { let memory_offset = self.stack.pop_usize()?; let data_offset = self.stack.pop_usize()?; let length = self.stack.pop_usize()?; @@ -524,14 +559,16 @@ impl Machine { /// length of the executing contract's code in bytes /// address(this).code.size - pub fn opcode_codesize(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_codesize(&mut self, _backend: &mut B) -> Result { self.stack.push_usize(self.execution_code.len())?; Ok(Action::Continue) } /// copy executing contract's bytecode - pub fn opcode_codecopy(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_codecopy(&mut self, _backend: &mut B) -> Result { let memory_offset = self.stack.pop_usize()?; let data_offset = self.stack.pop_usize()?; let length = self.stack.pop_usize()?; @@ -544,7 +581,8 @@ impl Machine { /// gas price of the executing transaction, in wei per unit of gas /// tx.gasprice - pub fn opcode_gasprice(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_gasprice(&mut self, _backend: &mut B) -> Result { self.stack.push_u256(self.gas_price)?; Ok(Action::Continue) @@ -581,14 +619,16 @@ impl Machine { } /// Byzantium hardfork, EIP-211: the size of the returned data from the last external call, in bytes - pub fn opcode_returndatasize(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_returndatasize(&mut self, _backend: &mut B) -> Result { self.stack.push_usize(self.return_data.len())?; Ok(Action::Continue) } /// Byzantium hardfork, EIP-211: copy returned data - pub fn opcode_returndatacopy(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_returndatacopy(&mut self, _backend: &mut B) -> Result { let memory_offset = self.stack.pop_usize()?; let data_offset = self.stack.pop_usize()?; let length = self.stack.pop_usize()?; @@ -633,14 +673,16 @@ impl Machine { /// address of the current block's miner /// NOT SUPPORTED - pub fn opcode_coinbase(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_coinbase(&mut self, _backend: &mut B) -> Result { self.stack.push_zero()?; Ok(Action::Continue) } /// current block's Unix timestamp in seconds - pub fn opcode_timestamp(&mut self, backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_timestamp(&mut self, backend: &mut B) -> Result { let timestamp = backend.block_timestamp()?; self.stack.push_u256(timestamp)?; @@ -649,7 +691,8 @@ impl Machine { } /// current block's number - pub fn opcode_number(&mut self, backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_number(&mut self, backend: &mut B) -> Result { let block_number = backend.block_number()?; self.stack.push_u256(block_number)?; @@ -659,7 +702,8 @@ impl Machine { /// current block's difficulty /// NOT SUPPORTED - pub fn opcode_difficulty(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_difficulty(&mut self, _backend: &mut B) -> Result { self.stack.push_zero()?; Ok(Action::Continue) @@ -667,14 +711,16 @@ impl Machine { /// current block's gas limit /// NOT SUPPORTED - pub fn opcode_gaslimit(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_gaslimit(&mut self, _backend: &mut B) -> Result { self.stack.push_u256(U256::MAX)?; Ok(Action::Continue) } /// Istanbul hardfork, EIP-1344: current network's chain id - pub fn opcode_chainid(&mut self, backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_chainid(&mut self, backend: &mut B) -> Result { let chain_id = backend.chain_id(); self.stack.push_u256(chain_id)?; @@ -694,21 +740,24 @@ impl Machine { /// London hardfork, EIP-3198: current block's base fee /// NOT SUPPORTED - pub fn opcode_basefee(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_basefee(&mut self, _backend: &mut B) -> Result { self.stack.push_zero()?; Ok(Action::Continue) } /// pops a (u)int256 off the stack and discards it - pub fn opcode_pop(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_pop(&mut self, _backend: &mut B) -> Result { self.stack.discard()?; Ok(Action::Continue) } /// reads a (u)int256 from memory - pub fn opcode_mload(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_mload(&mut self, _backend: &mut B) -> Result { let offset = self.stack.pop_usize()?; let value = self.memory.read_32(offset)?; @@ -718,7 +767,8 @@ impl Machine { } /// writes a (u)int256 to memory - pub fn opcode_mstore(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_mstore(&mut self, _backend: &mut B) -> Result { let offset = self.stack.pop_usize()?; let value = self.stack.pop_array()?; @@ -728,7 +778,8 @@ impl Machine { } /// writes a uint8 to memory - pub fn opcode_mstore8(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_mstore8(&mut self, _backend: &mut B) -> Result { let offset = self.stack.pop_usize()?; let value = self.stack.pop_array()?; @@ -751,7 +802,8 @@ impl Machine { } /// writes a (u)int256 to storage - pub fn opcode_sstore(&mut self, backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_sstore(&mut self, backend: &mut B) -> Result { if self.is_static { return Err(Error::StaticModeViolation(self.context.contract)); } @@ -768,7 +820,8 @@ impl Machine { } /// unconditional jump - pub fn opcode_jump(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_jump(&mut self, _backend: &mut B) -> Result { const JUMPDEST: u8 = 0x5B; let value = self.stack.pop_usize()?; @@ -781,7 +834,8 @@ impl Machine { } /// conditional jump - pub fn opcode_jumpi(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_jumpi(&mut self, _backend: &mut B) -> Result { const JUMPDEST: u8 = 0x5B; let value = self.stack.pop_usize()?; @@ -799,33 +853,38 @@ impl Machine { } /// program counter - pub fn opcode_pc(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_pc(&mut self, _backend: &mut B) -> Result { self.stack.push_usize(self.pc)?; Ok(Action::Continue) } /// memory size - pub fn opcode_msize(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_msize(&mut self, _backend: &mut B) -> Result { self.stack.push_usize(self.memory.size())?; Ok(Action::Continue) } /// remaining gas - pub fn opcode_gas(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_gas(&mut self, _backend: &mut B) -> Result { self.stack.push_u256(self.gas_limit)?; Ok(Action::Continue) } /// metadata to annotate possible jump destinations - pub fn opcode_jumpdest(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_jumpdest(&mut self, _backend: &mut B) -> Result { Ok(Action::Continue) } /// Place zero on stack - pub fn opcode_push_0(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_push_0(&mut self, _backend: &mut B) -> Result { self.stack.push_zero()?; Ok(Action::Continue) @@ -833,7 +892,8 @@ impl Machine { /// Place 1 byte item on stack /// ~50% of contract bytecode are PUSH opcodes - pub fn opcode_push_1(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_push_1(&mut self, _backend: &mut B) -> Result { if self.execution_code.len() <= self.pc + 1 { return Err(Error::PushOutOfBounds(self.context.contract)); } @@ -846,7 +906,8 @@ impl Machine { } /// Place 2-31 byte item on stack. - pub fn opcode_push_2_31(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_push_2_31(&mut self, _backend: &mut B) -> Result { if self.execution_code.len() <= self.pc + 1 + N { return Err(Error::PushOutOfBounds(self.context.contract)); } @@ -862,7 +923,8 @@ impl Machine { } /// Place 32 byte item on stack - pub fn opcode_push_32(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_push_32(&mut self, _backend: &mut B) -> Result { if self.execution_code.len() <= self.pc + 1 + 32 { return Err(Error::PushOutOfBounds(self.context.contract)); } @@ -879,14 +941,16 @@ impl Machine { /// Duplicate Nth stack item /// ~25% of contract bytecode are DUP and SWAP opcodes - pub fn opcode_dup_1_16(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_dup_1_16(&mut self, _backend: &mut B) -> Result { self.stack.dup_1_16::()?; Ok(Action::Continue) } /// Exchange 1st and (N+1)th stack item - pub fn opcode_swap_1_16(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_swap_1_16(&mut self, _backend: &mut B) -> Result { self.stack.swap_1_16::()?; Ok(Action::Continue) @@ -894,7 +958,8 @@ impl Machine { /// Append log record with N topics #[rustfmt::skip] - pub fn opcode_log_0_4(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_log_0_4(&mut self, _backend: &mut B) -> Result { if self.is_static { return Err(Error::StaticModeViolation(self.context.contract)); } @@ -1217,24 +1282,28 @@ impl Machine { }; if let Some(return_data) = result.transpose()? { - return self.opcode_return_impl(Buffer::from_slice(&return_data), backend); + return self + .opcode_return_impl(Buffer::from_slice(&return_data), backend) + .await; } Ok(Action::Noop) } /// Halt execution returning output data - pub fn opcode_return(&mut self, backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_return(&mut self, backend: &mut B) -> Result { let offset = self.stack.pop_usize()?; let length = self.stack.pop_usize()?; let return_data = self.memory.read_buffer(offset, length)?; - self.opcode_return_impl(return_data, backend) + self.opcode_return_impl(return_data, backend).await } /// Halt execution returning output data - pub fn opcode_return_impl( + #[maybe_async] + pub async fn opcode_return_impl( &mut self, mut return_data: Buffer, backend: &mut B, @@ -1277,16 +1346,22 @@ impl Machine { } /// Byzantium hardfork, EIP-140: Halt execution reverting state changes but returning data - pub fn opcode_revert(&mut self, backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_revert(&mut self, backend: &mut B) -> Result { let offset = self.stack.pop_usize()?; let length = self.stack.pop_usize()?; let return_data = self.memory.read_buffer(offset, length)?; - self.opcode_revert_impl(return_data, backend) + self.opcode_revert_impl(return_data, backend).await } - pub fn opcode_revert_impl(&mut self, return_data: Buffer, backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_revert_impl( + &mut self, + return_data: Buffer, + backend: &mut B, + ) -> Result { backend.revert_snapshot(); sol_log_data(&[b"EXIT", b"REVERT", &return_data]); @@ -1319,7 +1394,8 @@ impl Machine { } /// Invalid instruction - pub fn opcode_invalid(&mut self, _backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_invalid(&mut self, _backend: &mut B) -> Result { Err(Error::InvalidOpcode( self.context.contract, self.execution_code[self.pc], @@ -1371,7 +1447,8 @@ impl Machine { } /// Halts execution of the contract - pub fn opcode_stop(&mut self, backend: &mut B) -> Result { + #[maybe_async] + pub async fn opcode_stop(&mut self, backend: &mut B) -> Result { backend.commit_snapshot(); sol_log_data(&[b"EXIT", b"STOP"]); diff --git a/evm_loader/program/src/evm/opcode_async.rs b/evm_loader/program/src/evm/opcode_async.rs deleted file mode 100644 index 2b89eb20c2..0000000000 --- a/evm_loader/program/src/evm/opcode_async.rs +++ /dev/null @@ -1,171 +0,0 @@ -use crate::error::Result; -use crate::evm::database::Database; -use crate::evm::opcode::Action; -#[allow(clippy::wildcard_imports)] -use crate::evm::opcode_values::*; -use crate::evm::Machine; - -impl Machine { - #[allow(clippy::too_many_lines)] - pub async fn execute_opcode(&mut self, backend: &mut B, opcode: u8) -> Result { - match opcode { - OPCODE_STOP => self.opcode_stop(backend), - OPCODE_ADD => self.opcode_add(backend), - OPCODE_MUL => self.opcode_mul(backend), - OPCODE_SUB => self.opcode_sub(backend), - OPCODE_DIV => self.opcode_div(backend), - OPCODE_SDIV => self.opcode_sdiv(backend), - OPCODE_MOD => self.opcode_mod(backend), - OPCODE_SMOD => self.opcode_smod(backend), - OPCODE_ADDMOD => self.opcode_addmod(backend), - OPCODE_MULMOD => self.opcode_mulmod(backend), - OPCODE_EXP => self.opcode_exp(backend), - OPCODE_SIGNEXTEND => self.opcode_signextend(backend), - - OPCODE_LT => self.opcode_lt(backend), - OPCODE_GT => self.opcode_gt(backend), - OPCODE_SLT => self.opcode_slt(backend), - OPCODE_SGT => self.opcode_sgt(backend), - OPCODE_EQ => self.opcode_eq(backend), - OPCODE_ISZERO => self.opcode_iszero(backend), - OPCODE_AND => self.opcode_and(backend), - OPCODE_OR => self.opcode_or(backend), - OPCODE_XOR => self.opcode_xor(backend), - OPCODE_NOT => self.opcode_not(backend), - OPCODE_BYTE => self.opcode_byte(backend), - OPCODE_SHL => self.opcode_shl(backend), - OPCODE_SHR => self.opcode_shr(backend), - OPCODE_SAR => self.opcode_sar(backend), - - OPCODE_KECCAK256 => self.opcode_sha3(backend), - - OPCODE_ADDRESS => self.opcode_address(backend), - OPCODE_BALANCE => self.opcode_balance(backend).await, - OPCODE_ORIGIN => self.opcode_origin(backend), - OPCODE_CALLER => self.opcode_caller(backend), - OPCODE_CALLVALUE => self.opcode_callvalue(backend), - OPCODE_CALLDATALOAD => self.opcode_calldataload(backend), - OPCODE_CALLDATASIZE => self.opcode_calldatasize(backend), - OPCODE_CALLDATACOPY => self.opcode_calldatacopy(backend), - OPCODE_CODESIZE => self.opcode_codesize(backend), - OPCODE_CODECOPY => self.opcode_codecopy(backend), - OPCODE_GASPRICE => self.opcode_gasprice(backend), - OPCODE_EXTCODESIZE => self.opcode_extcodesize(backend).await, - OPCODE_EXTCODECOPY => self.opcode_extcodecopy(backend).await, - OPCODE_RETURNDATASIZE => self.opcode_returndatasize(backend), - OPCODE_RETURNDATACOPY => self.opcode_returndatacopy(backend), - OPCODE_EXTCODEHASH => self.opcode_extcodehash(backend).await, - OPCODE_BLOCKHASH => self.opcode_blockhash(backend).await, - OPCODE_COINBASE => self.opcode_coinbase(backend), - OPCODE_TIMESTAMP => self.opcode_timestamp(backend), - OPCODE_NUMBER => self.opcode_number(backend), - OPCODE_PREVRANDAO => self.opcode_difficulty(backend), - OPCODE_GASLIMIT => self.opcode_gaslimit(backend), - OPCODE_CHAINID => self.opcode_chainid(backend), - OPCODE_SELFBALANCE => self.opcode_selfbalance(backend).await, - OPCODE_BASEFEE => self.opcode_basefee(backend), - - OPCODE_POP => self.opcode_pop(backend), - OPCODE_MLOAD => self.opcode_mload(backend), - OPCODE_MSTORE => self.opcode_mstore(backend), - OPCODE_MSTORE8 => self.opcode_mstore8(backend), - OPCODE_SLOAD => self.opcode_sload(backend).await, - OPCODE_SSTORE => self.opcode_sstore(backend), - OPCODE_JUMP => self.opcode_jump(backend), - OPCODE_JUMPI => self.opcode_jumpi(backend), - OPCODE_PC => self.opcode_pc(backend), - OPCODE_MSIZE => self.opcode_msize(backend), - OPCODE_GAS => self.opcode_gas(backend), - OPCODE_JUMPDEST => self.opcode_jumpdest(backend), - - OPCODE_PUSH0 => self.opcode_push_0(backend), - OPCODE_PUSH1 => self.opcode_push_1(backend), - OPCODE_PUSH2 => self.opcode_push_2_31::<2>(backend), - OPCODE_PUSH3 => self.opcode_push_2_31::<3>(backend), - OPCODE_PUSH4 => self.opcode_push_2_31::<4>(backend), - OPCODE_PUSH5 => self.opcode_push_2_31::<5>(backend), - OPCODE_PUSH6 => self.opcode_push_2_31::<6>(backend), - OPCODE_PUSH7 => self.opcode_push_2_31::<7>(backend), - OPCODE_PUSH8 => self.opcode_push_2_31::<8>(backend), - OPCODE_PUSH9 => self.opcode_push_2_31::<9>(backend), - OPCODE_PUSH10 => self.opcode_push_2_31::<10>(backend), - OPCODE_PUSH11 => self.opcode_push_2_31::<11>(backend), - OPCODE_PUSH12 => self.opcode_push_2_31::<12>(backend), - OPCODE_PUSH13 => self.opcode_push_2_31::<13>(backend), - OPCODE_PUSH14 => self.opcode_push_2_31::<14>(backend), - OPCODE_PUSH15 => self.opcode_push_2_31::<15>(backend), - OPCODE_PUSH16 => self.opcode_push_2_31::<16>(backend), - OPCODE_PUSH17 => self.opcode_push_2_31::<17>(backend), - OPCODE_PUSH18 => self.opcode_push_2_31::<18>(backend), - OPCODE_PUSH19 => self.opcode_push_2_31::<19>(backend), - OPCODE_PUSH20 => self.opcode_push_2_31::<20>(backend), - OPCODE_PUSH21 => self.opcode_push_2_31::<21>(backend), - OPCODE_PUSH22 => self.opcode_push_2_31::<22>(backend), - OPCODE_PUSH23 => self.opcode_push_2_31::<23>(backend), - OPCODE_PUSH24 => self.opcode_push_2_31::<24>(backend), - OPCODE_PUSH25 => self.opcode_push_2_31::<25>(backend), - OPCODE_PUSH26 => self.opcode_push_2_31::<26>(backend), - OPCODE_PUSH27 => self.opcode_push_2_31::<27>(backend), - OPCODE_PUSH28 => self.opcode_push_2_31::<28>(backend), - OPCODE_PUSH29 => self.opcode_push_2_31::<29>(backend), - OPCODE_PUSH30 => self.opcode_push_2_31::<30>(backend), - OPCODE_PUSH31 => self.opcode_push_2_31::<31>(backend), - OPCODE_PUSH32 => self.opcode_push_32(backend), - - OPCODE_DUP1 => self.opcode_dup_1_16::<1>(backend), - OPCODE_DUP2 => self.opcode_dup_1_16::<2>(backend), - OPCODE_DUP3 => self.opcode_dup_1_16::<3>(backend), - OPCODE_DUP4 => self.opcode_dup_1_16::<4>(backend), - OPCODE_DUP5 => self.opcode_dup_1_16::<5>(backend), - OPCODE_DUP6 => self.opcode_dup_1_16::<6>(backend), - OPCODE_DUP7 => self.opcode_dup_1_16::<7>(backend), - OPCODE_DUP8 => self.opcode_dup_1_16::<8>(backend), - OPCODE_DUP9 => self.opcode_dup_1_16::<9>(backend), - OPCODE_DUP10 => self.opcode_dup_1_16::<10>(backend), - OPCODE_DUP11 => self.opcode_dup_1_16::<11>(backend), - OPCODE_DUP12 => self.opcode_dup_1_16::<12>(backend), - OPCODE_DUP13 => self.opcode_dup_1_16::<13>(backend), - OPCODE_DUP14 => self.opcode_dup_1_16::<14>(backend), - OPCODE_DUP15 => self.opcode_dup_1_16::<15>(backend), - OPCODE_DUP16 => self.opcode_dup_1_16::<16>(backend), - - OPCODE_SWAP1 => self.opcode_swap_1_16::<1>(backend), - OPCODE_SWAP2 => self.opcode_swap_1_16::<2>(backend), - OPCODE_SWAP3 => self.opcode_swap_1_16::<3>(backend), - OPCODE_SWAP4 => self.opcode_swap_1_16::<4>(backend), - OPCODE_SWAP5 => self.opcode_swap_1_16::<5>(backend), - OPCODE_SWAP6 => self.opcode_swap_1_16::<6>(backend), - OPCODE_SWAP7 => self.opcode_swap_1_16::<7>(backend), - OPCODE_SWAP8 => self.opcode_swap_1_16::<8>(backend), - OPCODE_SWAP9 => self.opcode_swap_1_16::<9>(backend), - OPCODE_SWAP10 => self.opcode_swap_1_16::<10>(backend), - OPCODE_SWAP11 => self.opcode_swap_1_16::<11>(backend), - OPCODE_SWAP12 => self.opcode_swap_1_16::<12>(backend), - OPCODE_SWAP13 => self.opcode_swap_1_16::<13>(backend), - OPCODE_SWAP14 => self.opcode_swap_1_16::<14>(backend), - OPCODE_SWAP15 => self.opcode_swap_1_16::<15>(backend), - OPCODE_SWAP16 => self.opcode_swap_1_16::<16>(backend), - - OPCODE_LOG0 => self.opcode_log_0_4::<0>(backend), - OPCODE_LOG1 => self.opcode_log_0_4::<1>(backend), - OPCODE_LOG2 => self.opcode_log_0_4::<2>(backend), - OPCODE_LOG3 => self.opcode_log_0_4::<3>(backend), - OPCODE_LOG4 => self.opcode_log_0_4::<4>(backend), - - OPCODE_CREATE => self.opcode_create(backend).await, - OPCODE_CALL => self.opcode_call(backend).await, - OPCODE_CALLCODE => self.opcode_callcode(backend).await, - OPCODE_RETURN => self.opcode_return(backend), - OPCODE_DELEGATECALL => self.opcode_delegatecall(backend).await, - OPCODE_CREATE2 => self.opcode_create2(backend).await, - - OPCODE_STATICCALL => self.opcode_staticcall(backend).await, - - OPCODE_REVERT => self.opcode_revert(backend), - OPCODE_INVALID => self.opcode_invalid(backend), - - OPCODE_SELFDESTRUCT => self.opcode_selfdestruct(backend).await, - _ => self.opcode_unknown(backend), - } - } -} diff --git a/evm_loader/program/src/evm/opcode_sync.rs b/evm_loader/program/src/evm/opcode_sync.rs deleted file mode 100644 index c51ed4780d..0000000000 --- a/evm_loader/program/src/evm/opcode_sync.rs +++ /dev/null @@ -1,178 +0,0 @@ -use crate::error::Result; - -use super::{database::Database, opcode::Action, Machine}; -#[allow(clippy::wildcard_imports)] -use crate::evm::opcode_values::*; - -type OpCode = fn(&mut Machine, &mut B) -> Result; - -impl Machine { - const OPCODES: [OpCode; 256] = { - let mut opcodes: [OpCode; 256] = [Self::opcode_unknown; 256]; - - opcodes[OPCODE_STOP as usize] = Self::opcode_stop; - opcodes[OPCODE_ADD as usize] = Self::opcode_add; - opcodes[OPCODE_MUL as usize] = Self::opcode_mul; - opcodes[OPCODE_SUB as usize] = Self::opcode_sub; - opcodes[OPCODE_DIV as usize] = Self::opcode_div; - opcodes[OPCODE_SDIV as usize] = Self::opcode_sdiv; - opcodes[OPCODE_MOD as usize] = Self::opcode_mod; - opcodes[OPCODE_SMOD as usize] = Self::opcode_smod; - opcodes[OPCODE_ADDMOD as usize] = Self::opcode_addmod; - opcodes[OPCODE_MULMOD as usize] = Self::opcode_mulmod; - opcodes[OPCODE_EXP as usize] = Self::opcode_exp; - opcodes[OPCODE_SIGNEXTEND as usize] = Self::opcode_signextend; - - opcodes[OPCODE_LT as usize] = Self::opcode_lt; - opcodes[OPCODE_GT as usize] = Self::opcode_gt; - opcodes[OPCODE_SLT as usize] = Self::opcode_slt; - opcodes[OPCODE_SGT as usize] = Self::opcode_sgt; - opcodes[OPCODE_EQ as usize] = Self::opcode_eq; - opcodes[OPCODE_ISZERO as usize] = Self::opcode_iszero; - opcodes[OPCODE_AND as usize] = Self::opcode_and; - opcodes[OPCODE_OR as usize] = Self::opcode_or; - opcodes[OPCODE_XOR as usize] = Self::opcode_xor; - opcodes[OPCODE_NOT as usize] = Self::opcode_not; - opcodes[OPCODE_BYTE as usize] = Self::opcode_byte; - opcodes[OPCODE_SHL as usize] = Self::opcode_shl; - opcodes[OPCODE_SHR as usize] = Self::opcode_shr; - opcodes[OPCODE_SAR as usize] = Self::opcode_sar; - - opcodes[OPCODE_KECCAK256 as usize] = Self::opcode_sha3; - - opcodes[OPCODE_ADDRESS as usize] = Self::opcode_address; - opcodes[OPCODE_BALANCE as usize] = Self::opcode_balance; - opcodes[OPCODE_ORIGIN as usize] = Self::opcode_origin; - opcodes[OPCODE_CALLER as usize] = Self::opcode_caller; - opcodes[OPCODE_CALLVALUE as usize] = Self::opcode_callvalue; - opcodes[OPCODE_CALLDATALOAD as usize] = Self::opcode_calldataload; - opcodes[OPCODE_CALLDATASIZE as usize] = Self::opcode_calldatasize; - opcodes[OPCODE_CALLDATACOPY as usize] = Self::opcode_calldatacopy; - opcodes[OPCODE_CODESIZE as usize] = Self::opcode_codesize; - opcodes[OPCODE_CODECOPY as usize] = Self::opcode_codecopy; - opcodes[OPCODE_GASPRICE as usize] = Self::opcode_gasprice; - opcodes[OPCODE_EXTCODESIZE as usize] = Self::opcode_extcodesize; - opcodes[OPCODE_EXTCODECOPY as usize] = Self::opcode_extcodecopy; - opcodes[OPCODE_RETURNDATASIZE as usize] = Self::opcode_returndatasize; - opcodes[OPCODE_RETURNDATACOPY as usize] = Self::opcode_returndatacopy; - opcodes[OPCODE_EXTCODEHASH as usize] = Self::opcode_extcodehash; - opcodes[OPCODE_BLOCKHASH as usize] = Self::opcode_blockhash; - opcodes[OPCODE_COINBASE as usize] = Self::opcode_coinbase; - opcodes[OPCODE_TIMESTAMP as usize] = Self::opcode_timestamp; - opcodes[OPCODE_NUMBER as usize] = Self::opcode_number; - opcodes[OPCODE_PREVRANDAO as usize] = Self::opcode_difficulty; - opcodes[OPCODE_GASLIMIT as usize] = Self::opcode_gaslimit; - opcodes[OPCODE_CHAINID as usize] = Self::opcode_chainid; - opcodes[OPCODE_SELFBALANCE as usize] = Self::opcode_selfbalance; - opcodes[OPCODE_BASEFEE as usize] = Self::opcode_basefee; - - opcodes[OPCODE_POP as usize] = Self::opcode_pop; - opcodes[OPCODE_MLOAD as usize] = Self::opcode_mload; - opcodes[OPCODE_MSTORE as usize] = Self::opcode_mstore; - opcodes[OPCODE_MSTORE8 as usize] = Self::opcode_mstore8; - opcodes[OPCODE_SLOAD as usize] = Self::opcode_sload; - opcodes[OPCODE_SSTORE as usize] = Self::opcode_sstore; - opcodes[OPCODE_JUMP as usize] = Self::opcode_jump; - opcodes[OPCODE_JUMPI as usize] = Self::opcode_jumpi; - opcodes[OPCODE_PC as usize] = Self::opcode_pc; - opcodes[OPCODE_MSIZE as usize] = Self::opcode_msize; - opcodes[OPCODE_GAS as usize] = Self::opcode_gas; - opcodes[OPCODE_JUMPDEST as usize] = Self::opcode_jumpdest; - - opcodes[OPCODE_PUSH0 as usize] = Self::opcode_push_0; - opcodes[OPCODE_PUSH1 as usize] = Self::opcode_push_1; - opcodes[OPCODE_PUSH2 as usize] = Self::opcode_push_2_31::<2>; - opcodes[OPCODE_PUSH3 as usize] = Self::opcode_push_2_31::<3>; - opcodes[OPCODE_PUSH4 as usize] = Self::opcode_push_2_31::<4>; - opcodes[OPCODE_PUSH5 as usize] = Self::opcode_push_2_31::<5>; - opcodes[OPCODE_PUSH6 as usize] = Self::opcode_push_2_31::<6>; - opcodes[OPCODE_PUSH7 as usize] = Self::opcode_push_2_31::<7>; - opcodes[OPCODE_PUSH8 as usize] = Self::opcode_push_2_31::<8>; - opcodes[OPCODE_PUSH9 as usize] = Self::opcode_push_2_31::<9>; - opcodes[OPCODE_PUSH10 as usize] = Self::opcode_push_2_31::<10>; - opcodes[OPCODE_PUSH11 as usize] = Self::opcode_push_2_31::<11>; - opcodes[OPCODE_PUSH12 as usize] = Self::opcode_push_2_31::<12>; - opcodes[OPCODE_PUSH13 as usize] = Self::opcode_push_2_31::<13>; - opcodes[OPCODE_PUSH14 as usize] = Self::opcode_push_2_31::<14>; - opcodes[OPCODE_PUSH15 as usize] = Self::opcode_push_2_31::<15>; - opcodes[OPCODE_PUSH16 as usize] = Self::opcode_push_2_31::<16>; - opcodes[OPCODE_PUSH17 as usize] = Self::opcode_push_2_31::<17>; - opcodes[OPCODE_PUSH18 as usize] = Self::opcode_push_2_31::<18>; - opcodes[OPCODE_PUSH19 as usize] = Self::opcode_push_2_31::<19>; - opcodes[OPCODE_PUSH20 as usize] = Self::opcode_push_2_31::<20>; - opcodes[OPCODE_PUSH21 as usize] = Self::opcode_push_2_31::<21>; - opcodes[OPCODE_PUSH22 as usize] = Self::opcode_push_2_31::<22>; - opcodes[OPCODE_PUSH23 as usize] = Self::opcode_push_2_31::<23>; - opcodes[OPCODE_PUSH24 as usize] = Self::opcode_push_2_31::<24>; - opcodes[OPCODE_PUSH25 as usize] = Self::opcode_push_2_31::<25>; - opcodes[OPCODE_PUSH26 as usize] = Self::opcode_push_2_31::<26>; - opcodes[OPCODE_PUSH27 as usize] = Self::opcode_push_2_31::<27>; - opcodes[OPCODE_PUSH28 as usize] = Self::opcode_push_2_31::<28>; - opcodes[OPCODE_PUSH29 as usize] = Self::opcode_push_2_31::<29>; - opcodes[OPCODE_PUSH30 as usize] = Self::opcode_push_2_31::<30>; - opcodes[OPCODE_PUSH31 as usize] = Self::opcode_push_2_31::<31>; - opcodes[OPCODE_PUSH32 as usize] = Self::opcode_push_32; - - opcodes[OPCODE_DUP1 as usize] = Self::opcode_dup_1_16::<1>; - opcodes[OPCODE_DUP2 as usize] = Self::opcode_dup_1_16::<2>; - opcodes[OPCODE_DUP3 as usize] = Self::opcode_dup_1_16::<3>; - opcodes[OPCODE_DUP4 as usize] = Self::opcode_dup_1_16::<4>; - opcodes[OPCODE_DUP5 as usize] = Self::opcode_dup_1_16::<5>; - opcodes[OPCODE_DUP6 as usize] = Self::opcode_dup_1_16::<6>; - opcodes[OPCODE_DUP7 as usize] = Self::opcode_dup_1_16::<7>; - opcodes[OPCODE_DUP8 as usize] = Self::opcode_dup_1_16::<8>; - opcodes[OPCODE_DUP9 as usize] = Self::opcode_dup_1_16::<9>; - opcodes[OPCODE_DUP10 as usize] = Self::opcode_dup_1_16::<10>; - opcodes[OPCODE_DUP11 as usize] = Self::opcode_dup_1_16::<11>; - opcodes[OPCODE_DUP12 as usize] = Self::opcode_dup_1_16::<12>; - opcodes[OPCODE_DUP13 as usize] = Self::opcode_dup_1_16::<13>; - opcodes[OPCODE_DUP14 as usize] = Self::opcode_dup_1_16::<14>; - opcodes[OPCODE_DUP15 as usize] = Self::opcode_dup_1_16::<15>; - opcodes[OPCODE_DUP16 as usize] = Self::opcode_dup_1_16::<16>; - - opcodes[OPCODE_SWAP1 as usize] = Self::opcode_swap_1_16::<1>; - opcodes[OPCODE_SWAP2 as usize] = Self::opcode_swap_1_16::<2>; - opcodes[OPCODE_SWAP3 as usize] = Self::opcode_swap_1_16::<3>; - opcodes[OPCODE_SWAP4 as usize] = Self::opcode_swap_1_16::<4>; - opcodes[OPCODE_SWAP5 as usize] = Self::opcode_swap_1_16::<5>; - opcodes[OPCODE_SWAP6 as usize] = Self::opcode_swap_1_16::<6>; - opcodes[OPCODE_SWAP7 as usize] = Self::opcode_swap_1_16::<7>; - opcodes[OPCODE_SWAP8 as usize] = Self::opcode_swap_1_16::<8>; - opcodes[OPCODE_SWAP9 as usize] = Self::opcode_swap_1_16::<9>; - opcodes[OPCODE_SWAP10 as usize] = Self::opcode_swap_1_16::<10>; - opcodes[OPCODE_SWAP11 as usize] = Self::opcode_swap_1_16::<11>; - opcodes[OPCODE_SWAP12 as usize] = Self::opcode_swap_1_16::<12>; - opcodes[OPCODE_SWAP13 as usize] = Self::opcode_swap_1_16::<13>; - opcodes[OPCODE_SWAP14 as usize] = Self::opcode_swap_1_16::<14>; - opcodes[OPCODE_SWAP15 as usize] = Self::opcode_swap_1_16::<15>; - opcodes[OPCODE_SWAP16 as usize] = Self::opcode_swap_1_16::<16>; - - opcodes[OPCODE_LOG0 as usize] = Self::opcode_log_0_4::<0>; - opcodes[OPCODE_LOG1 as usize] = Self::opcode_log_0_4::<1>; - opcodes[OPCODE_LOG2 as usize] = Self::opcode_log_0_4::<2>; - opcodes[OPCODE_LOG3 as usize] = Self::opcode_log_0_4::<3>; - opcodes[OPCODE_LOG4 as usize] = Self::opcode_log_0_4::<4>; - - opcodes[OPCODE_CREATE as usize] = Self::opcode_create; - opcodes[OPCODE_CALL as usize] = Self::opcode_call; - opcodes[OPCODE_CALLCODE as usize] = Self::opcode_callcode; - opcodes[OPCODE_RETURN as usize] = Self::opcode_return; - opcodes[OPCODE_DELEGATECALL as usize] = Self::opcode_delegatecall; - opcodes[OPCODE_CREATE2 as usize] = Self::opcode_create2; - - opcodes[OPCODE_STATICCALL as usize] = Self::opcode_staticcall; - - opcodes[OPCODE_REVERT as usize] = Self::opcode_revert; - opcodes[OPCODE_INVALID as usize] = Self::opcode_invalid; - - opcodes[OPCODE_SELFDESTRUCT as usize] = Self::opcode_selfdestruct; - - opcodes - }; - - pub fn execute_opcode(&mut self, backend: &mut B, opcode: u8) -> Result { - // SAFETY: OPCODES.len() == 256, opcode <= 255 - let opcode_fn = unsafe { Self::OPCODES.get_unchecked(opcode as usize) }; - opcode_fn(self, backend) - } -} diff --git a/evm_loader/program/src/evm/opcode_table.rs b/evm_loader/program/src/evm/opcode_table.rs new file mode 100644 index 0000000000..d30045e4f9 --- /dev/null +++ b/evm_loader/program/src/evm/opcode_table.rs @@ -0,0 +1,205 @@ +use crate::error::Result; + +use super::{database::Database, opcode::Action, Machine}; + +macro_rules! opcode_table { + ($( $opcode:literal, $opname:literal, $op:path;)*) => { + #[cfg(not(feature = "library"))] + type OpCode = fn(&mut Machine, &mut B) -> Result; + + #[cfg(not(feature = "library"))] + impl Machine { + const OPCODES: [OpCode; 256] = { + let mut opcodes: [OpCode; 256] = [Self::opcode_unknown; 256]; + + $(opcodes[$opcode as usize] = $op;)* + + opcodes + }; + + pub fn execute_opcode(&mut self, backend: &mut B, opcode: u8) -> Result { + // SAFETY: OPCODES.len() == 256, opcode <= 255 + let opcode_fn = unsafe { Self::OPCODES.get_unchecked(opcode as usize) }; + opcode_fn(self, backend) + } + } + + #[cfg(feature = "library")] + impl Machine { + pub async fn execute_opcode(&mut self, backend: &mut B, opcode: u8) -> Result { + match opcode { + $($opcode => $op(self, backend).await,)* + _ => Self::opcode_unknown(self, backend).await, + } + } + } + + #[cfg(feature = "library")] + pub const OPNAMES: [&str; 256] = { + let mut opnames: [&str; 256] = [""; 256]; + + $(opnames[$opcode as usize] = $opname;)* + + opnames + }; + } +} + +opcode_table![ + 0x00, "STOP", Self::opcode_stop; + 0x01, "ADD", Self::opcode_add; + 0x02, "MUL", Self::opcode_mul; + 0x03, "SUB", Self::opcode_sub; + 0x04, "DIV", Self::opcode_div; + 0x05, "SDIV", Self::opcode_sdiv; + 0x06, "MOD", Self::opcode_mod; + 0x07, "SMOD", Self::opcode_smod; + 0x08, "ADDMOD", Self::opcode_addmod; + 0x09, "MULMOD", Self::opcode_mulmod; + 0x0A, "EXP", Self::opcode_exp; + 0x0B, "SIGNEXTEND", Self::opcode_signextend; + + 0x10, "LT", Self::opcode_lt; + 0x11, "GT", Self::opcode_gt; + 0x12, "SLT", Self::opcode_slt; + 0x13, "SGT", Self::opcode_sgt; + 0x14, "EQ", Self::opcode_eq; + 0x15, "ISZERO", Self::opcode_iszero; + 0x16, "AND", Self::opcode_and; + 0x17, "OR", Self::opcode_or; + 0x18, "XOR", Self::opcode_xor; + 0x19, "NOT", Self::opcode_not; + 0x1A, "BYTE", Self::opcode_byte; + 0x1B, "SHL", Self::opcode_shl; + 0x1C, "SHR", Self::opcode_shr; + 0x1D, "SAR", Self::opcode_sar; + + 0x20, "KECCAK256", Self::opcode_sha3; + + 0x30, "ADDRESS", Self::opcode_address; + 0x31, "BALANCE", Self::opcode_balance; + 0x32, "ORIGIN", Self::opcode_origin; + 0x33, "CALLER", Self::opcode_caller; + 0x34, "CALLVALUE", Self::opcode_callvalue; + 0x35, "CALLDATALOAD", Self::opcode_calldataload; + 0x36, "CALLDATASIZE", Self::opcode_calldatasize; + 0x37, "CALLDATACOPY", Self::opcode_calldatacopy; + 0x38, "CODESIZE", Self::opcode_codesize; + 0x39, "CODECOPY", Self::opcode_codecopy; + 0x3A, "GASPRICE", Self::opcode_gasprice; + 0x3B, "EXTCODESIZE", Self::opcode_extcodesize; + 0x3C, "EXTCODECOPY", Self::opcode_extcodecopy; + 0x3D, "RETURNDATASIZE", Self::opcode_returndatasize; + 0x3E, "RETURNDATACOPY", Self::opcode_returndatacopy; + 0x3F, "EXTCODEHASH", Self::opcode_extcodehash; + 0x40, "BLOCKHASH", Self::opcode_blockhash; + 0x41, "COINBASE", Self::opcode_coinbase; + 0x42, "TIMESTAMP", Self::opcode_timestamp; + 0x43, "NUMBER", Self::opcode_number; + 0x44, "PREVRANDAO", Self::opcode_difficulty; + 0x45, "GASLIMIT", Self::opcode_gaslimit; + 0x46, "CHAINID", Self::opcode_chainid; + 0x47, "SELFBALANCE", Self::opcode_selfbalance; + 0x48, "BASEFEE", Self::opcode_basefee; + + 0x50, "POP", Self::opcode_pop; + 0x51, "MLOAD", Self::opcode_mload; + 0x52, "MSTORE", Self::opcode_mstore; + 0x53, "MSTORE8", Self::opcode_mstore8; + 0x54, "SLOAD", Self::opcode_sload; + 0x55, "SSTORE", Self::opcode_sstore; + 0x56, "JUMP", Self::opcode_jump; + 0x57, "JUMPI", Self::opcode_jumpi; + 0x58, "PC", Self::opcode_pc; + 0x59, "MSIZE", Self::opcode_msize; + 0x5A, "GAS", Self::opcode_gas; + 0x5B, "JUMPDEST", Self::opcode_jumpdest; + + 0x5F, "PUSH0", Self::opcode_push_0; + 0x60, "PUSH1", Self::opcode_push_1; + 0x61, "PUSH2", Self::opcode_push_2_31::<2>; + 0x62, "PUSH3", Self::opcode_push_2_31::<3>; + 0x63, "PUSH4", Self::opcode_push_2_31::<4>; + 0x64, "PUSH5", Self::opcode_push_2_31::<5>; + 0x65, "PUSH6", Self::opcode_push_2_31::<6>; + 0x66, "PUSH7", Self::opcode_push_2_31::<7>; + 0x67, "PUSH8", Self::opcode_push_2_31::<8>; + 0x68, "PUSH9", Self::opcode_push_2_31::<9>; + 0x69, "PUSH10", Self::opcode_push_2_31::<10>; + 0x6A, "PUSH11", Self::opcode_push_2_31::<11>; + 0x6B, "PUSH12", Self::opcode_push_2_31::<12>; + 0x6C, "PUSH13", Self::opcode_push_2_31::<13>; + 0x6D, "PUSH14", Self::opcode_push_2_31::<14>; + 0x6E, "PUSH15", Self::opcode_push_2_31::<15>; + 0x6F, "PUSH16", Self::opcode_push_2_31::<16>; + 0x70, "PUSH17", Self::opcode_push_2_31::<17>; + 0x71, "PUSH18", Self::opcode_push_2_31::<18>; + 0x72, "PUSH19", Self::opcode_push_2_31::<19>; + 0x73, "PUSH20", Self::opcode_push_2_31::<20>; + 0x74, "PUSH21", Self::opcode_push_2_31::<21>; + 0x75, "PUSH22", Self::opcode_push_2_31::<22>; + 0x76, "PUSH23", Self::opcode_push_2_31::<23>; + 0x77, "PUSH24", Self::opcode_push_2_31::<24>; + 0x78, "PUSH25", Self::opcode_push_2_31::<25>; + 0x79, "PUSH26", Self::opcode_push_2_31::<26>; + 0x7A, "PUSH27", Self::opcode_push_2_31::<27>; + 0x7B, "PUSH28", Self::opcode_push_2_31::<28>; + 0x7C, "PUSH29", Self::opcode_push_2_31::<29>; + 0x7D, "PUSH30", Self::opcode_push_2_31::<30>; + 0x7E, "PUSH31", Self::opcode_push_2_31::<31>; + 0x7F, "PUSH32", Self::opcode_push_32; + + 0x80, "DUP1", Self::opcode_dup_1_16::<1>; + 0x81, "DUP2", Self::opcode_dup_1_16::<2>; + 0x82, "DUP3", Self::opcode_dup_1_16::<3>; + 0x83, "DUP4", Self::opcode_dup_1_16::<4>; + 0x84, "DUP5", Self::opcode_dup_1_16::<5>; + 0x85, "DUP6", Self::opcode_dup_1_16::<6>; + 0x86, "DUP7", Self::opcode_dup_1_16::<7>; + 0x87, "DUP8", Self::opcode_dup_1_16::<8>; + 0x88, "DUP9", Self::opcode_dup_1_16::<9>; + 0x89, "DUP10", Self::opcode_dup_1_16::<10>; + 0x8A, "DUP11", Self::opcode_dup_1_16::<11>; + 0x8B, "DUP12", Self::opcode_dup_1_16::<12>; + 0x8C, "DUP13", Self::opcode_dup_1_16::<13>; + 0x8D, "DUP14", Self::opcode_dup_1_16::<14>; + 0x8E, "DUP15", Self::opcode_dup_1_16::<15>; + 0x8F, "DUP16", Self::opcode_dup_1_16::<16>; + + 0x90, "SWAP1", Self::opcode_swap_1_16::<1>; + 0x91, "SWAP2", Self::opcode_swap_1_16::<2>; + 0x92, "SWAP3", Self::opcode_swap_1_16::<3>; + 0x93, "SWAP4", Self::opcode_swap_1_16::<4>; + 0x94, "SWAP5", Self::opcode_swap_1_16::<5>; + 0x95, "SWAP6", Self::opcode_swap_1_16::<6>; + 0x96, "SWAP7", Self::opcode_swap_1_16::<7>; + 0x97, "SWAP8", Self::opcode_swap_1_16::<8>; + 0x98, "SWAP9", Self::opcode_swap_1_16::<9>; + 0x99, "SWAP10", Self::opcode_swap_1_16::<10>; + 0x9A, "SWAP11", Self::opcode_swap_1_16::<11>; + 0x9B, "SWAP12", Self::opcode_swap_1_16::<12>; + 0x9C, "SWAP13", Self::opcode_swap_1_16::<13>; + 0x9D, "SWAP14", Self::opcode_swap_1_16::<14>; + 0x9E, "SWAP15", Self::opcode_swap_1_16::<15>; + 0x9F, "SWAP16", Self::opcode_swap_1_16::<16>; + + 0xA0, "LOG0", Self::opcode_log_0_4::<0>; + 0xA1, "LOG1", Self::opcode_log_0_4::<1>; + 0xA2, "LOG2", Self::opcode_log_0_4::<2>; + 0xA3, "LOG3", Self::opcode_log_0_4::<3>; + 0xA4, "LOG4", Self::opcode_log_0_4::<4>; + + 0xF0, "CREATE", Self::opcode_create; + 0xF1, "CALL", Self::opcode_call; + 0xF2, "CALLCODE", Self::opcode_callcode; + 0xF3, "RETURN", Self::opcode_return; + 0xF4, "DELEGATECALL", Self::opcode_delegatecall; + 0xF5, "CREATE2", Self::opcode_create2; + + 0xFA, "STATICCALL", Self::opcode_staticcall; + + 0xFD, "REVERT", Self::opcode_revert; + 0xFE, "INVALID", Self::opcode_invalid; + + 0xFF, "SELFDESTRUCT", Self::opcode_selfdestruct; +]; diff --git a/evm_loader/program/src/evm/opcode_values.rs b/evm_loader/program/src/evm/opcode_values.rs deleted file mode 100644 index 6101e75c58..0000000000 --- a/evm_loader/program/src/evm/opcode_values.rs +++ /dev/null @@ -1,156 +0,0 @@ -pub const OPCODE_STOP: u8 = 0x00; -pub const OPCODE_ADD: u8 = 0x01; -pub const OPCODE_MUL: u8 = 0x02; -pub const OPCODE_SUB: u8 = 0x03; -pub const OPCODE_DIV: u8 = 0x04; -pub const OPCODE_SDIV: u8 = 0x05; -pub const OPCODE_MOD: u8 = 0x06; -pub const OPCODE_SMOD: u8 = 0x07; -pub const OPCODE_ADDMOD: u8 = 0x08; -pub const OPCODE_MULMOD: u8 = 0x09; -pub const OPCODE_EXP: u8 = 0x0A; -pub const OPCODE_SIGNEXTEND: u8 = 0x0B; - -pub const OPCODE_LT: u8 = 0x10; -pub const OPCODE_GT: u8 = 0x11; -pub const OPCODE_SLT: u8 = 0x12; -pub const OPCODE_SGT: u8 = 0x13; -pub const OPCODE_EQ: u8 = 0x14; -pub const OPCODE_ISZERO: u8 = 0x15; -pub const OPCODE_AND: u8 = 0x16; -pub const OPCODE_OR: u8 = 0x17; -pub const OPCODE_XOR: u8 = 0x18; -pub const OPCODE_NOT: u8 = 0x19; -pub const OPCODE_BYTE: u8 = 0x1A; -pub const OPCODE_SHL: u8 = 0x1B; -pub const OPCODE_SHR: u8 = 0x1C; -pub const OPCODE_SAR: u8 = 0x1D; - -pub const OPCODE_KECCAK256: u8 = 0x20; - -pub const OPCODE_ADDRESS: u8 = 0x30; -pub const OPCODE_BALANCE: u8 = 0x31; -pub const OPCODE_ORIGIN: u8 = 0x32; -pub const OPCODE_CALLER: u8 = 0x33; -pub const OPCODE_CALLVALUE: u8 = 0x34; -pub const OPCODE_CALLDATALOAD: u8 = 0x35; -pub const OPCODE_CALLDATASIZE: u8 = 0x36; -pub const OPCODE_CALLDATACOPY: u8 = 0x37; -pub const OPCODE_CODESIZE: u8 = 0x38; -pub const OPCODE_CODECOPY: u8 = 0x39; -pub const OPCODE_GASPRICE: u8 = 0x3A; -pub const OPCODE_EXTCODESIZE: u8 = 0x3B; -pub const OPCODE_EXTCODECOPY: u8 = 0x3C; -pub const OPCODE_RETURNDATASIZE: u8 = 0x3D; -pub const OPCODE_RETURNDATACOPY: u8 = 0x3E; -pub const OPCODE_EXTCODEHASH: u8 = 0x3F; -pub const OPCODE_BLOCKHASH: u8 = 0x40; -pub const OPCODE_COINBASE: u8 = 0x41; -pub const OPCODE_TIMESTAMP: u8 = 0x42; -pub const OPCODE_NUMBER: u8 = 0x43; -pub const OPCODE_PREVRANDAO: u8 = 0x44; -pub const OPCODE_GASLIMIT: u8 = 0x45; -pub const OPCODE_CHAINID: u8 = 0x46; -pub const OPCODE_SELFBALANCE: u8 = 0x47; -pub const OPCODE_BASEFEE: u8 = 0x48; - -pub const OPCODE_POP: u8 = 0x50; -pub const OPCODE_MLOAD: u8 = 0x51; -pub const OPCODE_MSTORE: u8 = 0x52; -pub const OPCODE_MSTORE8: u8 = 0x53; -pub const OPCODE_SLOAD: u8 = 0x54; -pub const OPCODE_SSTORE: u8 = 0x55; -pub const OPCODE_JUMP: u8 = 0x56; -pub const OPCODE_JUMPI: u8 = 0x57; -pub const OPCODE_PC: u8 = 0x58; -pub const OPCODE_MSIZE: u8 = 0x59; -pub const OPCODE_GAS: u8 = 0x5A; -pub const OPCODE_JUMPDEST: u8 = 0x5B; - -pub const OPCODE_PUSH0: u8 = 0x5F; -pub const OPCODE_PUSH1: u8 = 0x60; -pub const OPCODE_PUSH2: u8 = 0x61; -pub const OPCODE_PUSH3: u8 = 0x62; -pub const OPCODE_PUSH4: u8 = 0x63; -pub const OPCODE_PUSH5: u8 = 0x64; -pub const OPCODE_PUSH6: u8 = 0x65; -pub const OPCODE_PUSH7: u8 = 0x66; -pub const OPCODE_PUSH8: u8 = 0x67; -pub const OPCODE_PUSH9: u8 = 0x68; -pub const OPCODE_PUSH10: u8 = 0x69; -pub const OPCODE_PUSH11: u8 = 0x6A; -pub const OPCODE_PUSH12: u8 = 0x6B; -pub const OPCODE_PUSH13: u8 = 0x6C; -pub const OPCODE_PUSH14: u8 = 0x6D; -pub const OPCODE_PUSH15: u8 = 0x6E; -pub const OPCODE_PUSH16: u8 = 0x6F; -pub const OPCODE_PUSH17: u8 = 0x70; -pub const OPCODE_PUSH18: u8 = 0x71; -pub const OPCODE_PUSH19: u8 = 0x72; -pub const OPCODE_PUSH20: u8 = 0x73; -pub const OPCODE_PUSH21: u8 = 0x74; -pub const OPCODE_PUSH22: u8 = 0x75; -pub const OPCODE_PUSH23: u8 = 0x76; -pub const OPCODE_PUSH24: u8 = 0x77; -pub const OPCODE_PUSH25: u8 = 0x78; -pub const OPCODE_PUSH26: u8 = 0x79; -pub const OPCODE_PUSH27: u8 = 0x7A; -pub const OPCODE_PUSH28: u8 = 0x7B; -pub const OPCODE_PUSH29: u8 = 0x7C; -pub const OPCODE_PUSH30: u8 = 0x7D; -pub const OPCODE_PUSH31: u8 = 0x7E; -pub const OPCODE_PUSH32: u8 = 0x7F; - -pub const OPCODE_DUP1: u8 = 0x80; -pub const OPCODE_DUP2: u8 = 0x81; -pub const OPCODE_DUP3: u8 = 0x82; -pub const OPCODE_DUP4: u8 = 0x83; -pub const OPCODE_DUP5: u8 = 0x84; -pub const OPCODE_DUP6: u8 = 0x85; -pub const OPCODE_DUP7: u8 = 0x86; -pub const OPCODE_DUP8: u8 = 0x87; -pub const OPCODE_DUP9: u8 = 0x88; -pub const OPCODE_DUP10: u8 = 0x89; -pub const OPCODE_DUP11: u8 = 0x8A; -pub const OPCODE_DUP12: u8 = 0x8B; -pub const OPCODE_DUP13: u8 = 0x8C; -pub const OPCODE_DUP14: u8 = 0x8D; -pub const OPCODE_DUP15: u8 = 0x8E; -pub const OPCODE_DUP16: u8 = 0x8F; - -pub const OPCODE_SWAP1: u8 = 0x90; -pub const OPCODE_SWAP2: u8 = 0x91; -pub const OPCODE_SWAP3: u8 = 0x92; -pub const OPCODE_SWAP4: u8 = 0x93; -pub const OPCODE_SWAP5: u8 = 0x94; -pub const OPCODE_SWAP6: u8 = 0x95; -pub const OPCODE_SWAP7: u8 = 0x96; -pub const OPCODE_SWAP8: u8 = 0x97; -pub const OPCODE_SWAP9: u8 = 0x98; -pub const OPCODE_SWAP10: u8 = 0x99; -pub const OPCODE_SWAP11: u8 = 0x9A; -pub const OPCODE_SWAP12: u8 = 0x9B; -pub const OPCODE_SWAP13: u8 = 0x9C; -pub const OPCODE_SWAP14: u8 = 0x9D; -pub const OPCODE_SWAP15: u8 = 0x9E; -pub const OPCODE_SWAP16: u8 = 0x9F; - -pub const OPCODE_LOG0: u8 = 0xA0; -pub const OPCODE_LOG1: u8 = 0xA1; -pub const OPCODE_LOG2: u8 = 0xA2; -pub const OPCODE_LOG3: u8 = 0xA3; -pub const OPCODE_LOG4: u8 = 0xA4; - -pub const OPCODE_CREATE: u8 = 0xF0; -pub const OPCODE_CALL: u8 = 0xF1; -pub const OPCODE_CALLCODE: u8 = 0xF2; -pub const OPCODE_RETURN: u8 = 0xF3; -pub const OPCODE_DELEGATECALL: u8 = 0xF4; -pub const OPCODE_CREATE2: u8 = 0xF5; - -pub const OPCODE_STATICCALL: u8 = 0xFA; - -pub const OPCODE_REVERT: u8 = 0xFD; -pub const OPCODE_INVALID: u8 = 0xFE; - -pub const OPCODE_SELFDESTRUCT: u8 = 0xFF; diff --git a/evm_loader/program/src/evm/tracing/tracers/mod.rs b/evm_loader/program/src/evm/tracing/tracers/mod.rs index 91ceb994a7..ed98e1af9e 100644 --- a/evm_loader/program/src/evm/tracing/tracers/mod.rs +++ b/evm_loader/program/src/evm/tracing/tracers/mod.rs @@ -4,8 +4,6 @@ use crate::evm::tracing::TracerType; use std::cell::RefCell; use std::rc::Rc; -mod opname_table; - pub mod struct_logger; pub fn new_tracer(trace_config: &TraceConfig) -> crate::error::Result { diff --git a/evm_loader/program/src/evm/tracing/tracers/opname_table.rs b/evm_loader/program/src/evm/tracing/tracers/opname_table.rs deleted file mode 100644 index 2c5a80abc6..0000000000 --- a/evm_loader/program/src/evm/tracing/tracers/opname_table.rs +++ /dev/null @@ -1,165 +0,0 @@ -#[allow(clippy::wildcard_imports)] -use crate::evm::opcode_values::*; - -pub const OPNAMES: [&str; 256] = { - let mut opnames: [&str; 256] = [""; 256]; - - opnames[OPCODE_STOP as usize] = "STOP"; - opnames[OPCODE_ADD as usize] = "ADD"; - opnames[OPCODE_MUL as usize] = "MUL"; - opnames[OPCODE_SUB as usize] = "SUB"; - opnames[OPCODE_DIV as usize] = "DIV"; - opnames[OPCODE_SDIV as usize] = "SDIV"; - opnames[OPCODE_MOD as usize] = "MOD"; - opnames[OPCODE_SMOD as usize] = "SMOD"; - opnames[OPCODE_ADDMOD as usize] = "ADDMOD"; - opnames[OPCODE_MULMOD as usize] = "MULMOD"; - opnames[OPCODE_EXP as usize] = "EXP"; - opnames[OPCODE_SIGNEXTEND as usize] = "SIGNEXTEND"; - - opnames[OPCODE_LT as usize] = "LT"; - opnames[OPCODE_GT as usize] = "GT"; - opnames[OPCODE_SLT as usize] = "SLT"; - opnames[OPCODE_SGT as usize] = "SGT"; - opnames[OPCODE_EQ as usize] = "EQ"; - opnames[OPCODE_ISZERO as usize] = "ISZERO"; - opnames[OPCODE_AND as usize] = "AND"; - opnames[OPCODE_OR as usize] = "OR"; - opnames[OPCODE_XOR as usize] = "XOR"; - opnames[OPCODE_NOT as usize] = "NOT"; - opnames[OPCODE_BYTE as usize] = "BYTE"; - opnames[OPCODE_SHL as usize] = "SHL"; - opnames[OPCODE_SHR as usize] = "SHR"; - opnames[OPCODE_SAR as usize] = "SAR"; - - opnames[OPCODE_KECCAK256 as usize] = "KECCAK256"; - - opnames[OPCODE_ADDRESS as usize] = "ADDRESS"; - opnames[OPCODE_BALANCE as usize] = "BALANCE"; - opnames[OPCODE_ORIGIN as usize] = "ORIGIN"; - opnames[OPCODE_CALLER as usize] = "CALLER"; - opnames[OPCODE_CALLVALUE as usize] = "CALLVALUE"; - opnames[OPCODE_CALLDATALOAD as usize] = "CALLDATALOAD"; - opnames[OPCODE_CALLDATASIZE as usize] = "CALLDATASIZE"; - opnames[OPCODE_CALLDATACOPY as usize] = "CALLDATACOPY"; - opnames[OPCODE_CODESIZE as usize] = "CODESIZE"; - opnames[OPCODE_CODECOPY as usize] = "CODECOPY"; - opnames[OPCODE_GASPRICE as usize] = "GASPRICE"; - opnames[OPCODE_EXTCODESIZE as usize] = "EXTCODESIZE"; - opnames[OPCODE_EXTCODECOPY as usize] = "EXTCODECOPY"; - opnames[OPCODE_RETURNDATASIZE as usize] = "RETURNDATASIZE"; - opnames[OPCODE_RETURNDATACOPY as usize] = "RETURNDATACOPY"; - opnames[OPCODE_EXTCODEHASH as usize] = "EXTCODEHASH"; - opnames[OPCODE_BLOCKHASH as usize] = "BLOCKHASH"; - opnames[OPCODE_COINBASE as usize] = "COINBASE"; - opnames[OPCODE_TIMESTAMP as usize] = "TIMESTAMP"; - opnames[OPCODE_NUMBER as usize] = "NUMBER"; - opnames[OPCODE_PREVRANDAO as usize] = "PREVRANDAO"; - opnames[OPCODE_GASLIMIT as usize] = "GASLIMIT"; - opnames[OPCODE_CHAINID as usize] = "CHAINID"; - opnames[OPCODE_SELFBALANCE as usize] = "SELFBALANCE"; - opnames[OPCODE_BASEFEE as usize] = "BASEFEE"; - - opnames[OPCODE_POP as usize] = "POP"; - opnames[OPCODE_MLOAD as usize] = "MLOAD"; - opnames[OPCODE_MSTORE as usize] = "MSTORE"; - opnames[OPCODE_MSTORE8 as usize] = "MSTORE8"; - opnames[OPCODE_SLOAD as usize] = "SLOAD"; - opnames[OPCODE_SSTORE as usize] = "SSTORE"; - opnames[OPCODE_JUMP as usize] = "JUMP"; - opnames[OPCODE_JUMPI as usize] = "JUMPI"; - opnames[OPCODE_PC as usize] = "PC"; - opnames[OPCODE_MSIZE as usize] = "MSIZE"; - opnames[OPCODE_GAS as usize] = "GAS"; - opnames[OPCODE_JUMPDEST as usize] = "JUMPDEST"; - - opnames[OPCODE_PUSH0 as usize] = "PUSH0"; - opnames[OPCODE_PUSH1 as usize] = "PUSH1"; - opnames[OPCODE_PUSH2 as usize] = "PUSH2"; - opnames[OPCODE_PUSH3 as usize] = "PUSH3"; - opnames[OPCODE_PUSH4 as usize] = "PUSH4"; - opnames[OPCODE_PUSH5 as usize] = "PUSH5"; - opnames[OPCODE_PUSH6 as usize] = "PUSH6"; - opnames[OPCODE_PUSH7 as usize] = "PUSH7"; - opnames[OPCODE_PUSH8 as usize] = "PUSH8"; - opnames[OPCODE_PUSH9 as usize] = "PUSH9"; - opnames[OPCODE_PUSH10 as usize] = "PUSH10"; - opnames[OPCODE_PUSH11 as usize] = "PUSH11"; - opnames[OPCODE_PUSH12 as usize] = "PUSH12"; - opnames[OPCODE_PUSH13 as usize] = "PUSH13"; - opnames[OPCODE_PUSH14 as usize] = "PUSH14"; - opnames[OPCODE_PUSH15 as usize] = "PUSH15"; - opnames[OPCODE_PUSH16 as usize] = "PUSH16"; - opnames[OPCODE_PUSH17 as usize] = "PUSH17"; - opnames[OPCODE_PUSH18 as usize] = "PUSH18"; - opnames[OPCODE_PUSH19 as usize] = "PUSH19"; - opnames[OPCODE_PUSH20 as usize] = "PUSH20"; - opnames[OPCODE_PUSH21 as usize] = "PUSH21"; - opnames[OPCODE_PUSH22 as usize] = "PUSH22"; - opnames[OPCODE_PUSH23 as usize] = "PUSH23"; - opnames[OPCODE_PUSH24 as usize] = "PUSH24"; - opnames[OPCODE_PUSH25 as usize] = "PUSH25"; - opnames[OPCODE_PUSH26 as usize] = "PUSH26"; - opnames[OPCODE_PUSH27 as usize] = "PUSH27"; - opnames[OPCODE_PUSH28 as usize] = "PUSH28"; - opnames[OPCODE_PUSH29 as usize] = "PUSH29"; - opnames[OPCODE_PUSH30 as usize] = "PUSH30"; - opnames[OPCODE_PUSH31 as usize] = "PUSH31"; - opnames[OPCODE_PUSH32 as usize] = "PUSH32"; - - opnames[OPCODE_DUP1 as usize] = "DUP1"; - opnames[OPCODE_DUP2 as usize] = "DUP2"; - opnames[OPCODE_DUP3 as usize] = "DUP3"; - opnames[OPCODE_DUP4 as usize] = "DUP4"; - opnames[OPCODE_DUP5 as usize] = "DUP5"; - opnames[OPCODE_DUP6 as usize] = "DUP6"; - opnames[OPCODE_DUP7 as usize] = "DUP7"; - opnames[OPCODE_DUP8 as usize] = "DUP8"; - opnames[OPCODE_DUP9 as usize] = "DUP9"; - opnames[OPCODE_DUP10 as usize] = "DUP10"; - opnames[OPCODE_DUP11 as usize] = "DUP11"; - opnames[OPCODE_DUP12 as usize] = "DUP12"; - opnames[OPCODE_DUP13 as usize] = "DUP13"; - opnames[OPCODE_DUP14 as usize] = "DUP14"; - opnames[OPCODE_DUP15 as usize] = "DUP15"; - opnames[OPCODE_DUP16 as usize] = "DUP16"; - - opnames[OPCODE_SWAP1 as usize] = "SWAP1"; - opnames[OPCODE_SWAP2 as usize] = "SWAP2"; - opnames[OPCODE_SWAP3 as usize] = "SWAP3"; - opnames[OPCODE_SWAP4 as usize] = "SWAP4"; - opnames[OPCODE_SWAP5 as usize] = "SWAP5"; - opnames[OPCODE_SWAP6 as usize] = "SWAP6"; - opnames[OPCODE_SWAP7 as usize] = "SWAP7"; - opnames[OPCODE_SWAP8 as usize] = "SWAP8"; - opnames[OPCODE_SWAP9 as usize] = "SWAP9"; - opnames[OPCODE_SWAP10 as usize] = "SWAP10"; - opnames[OPCODE_SWAP11 as usize] = "SWAP11"; - opnames[OPCODE_SWAP12 as usize] = "SWAP12"; - opnames[OPCODE_SWAP13 as usize] = "SWAP13"; - opnames[OPCODE_SWAP14 as usize] = "SWAP14"; - opnames[OPCODE_SWAP15 as usize] = "SWAP15"; - opnames[OPCODE_SWAP16 as usize] = "SWAP16"; - - opnames[OPCODE_LOG0 as usize] = "LOG0"; - opnames[OPCODE_LOG1 as usize] = "LOG1"; - opnames[OPCODE_LOG2 as usize] = "LOG2"; - opnames[OPCODE_LOG3 as usize] = "LOG3"; - opnames[OPCODE_LOG4 as usize] = "LOG4"; - - opnames[OPCODE_CREATE as usize] = "CREATE"; - opnames[OPCODE_CALL as usize] = "CALL"; - opnames[OPCODE_CALLCODE as usize] = "CALLCODE"; - opnames[OPCODE_RETURN as usize] = "RETURN"; - opnames[OPCODE_DELEGATECALL as usize] = "DELEGATECALL"; - opnames[OPCODE_CREATE2 as usize] = "CREATE2"; - - opnames[OPCODE_STATICCALL as usize] = "STATICCALL"; - - opnames[OPCODE_REVERT as usize] = "REVERT"; - opnames[OPCODE_INVALID as usize] = "INVALID"; - - opnames[OPCODE_SELFDESTRUCT as usize] = "SELFDESTRUCT"; - - opnames -}; diff --git a/evm_loader/program/src/evm/tracing/tracers/struct_logger.rs b/evm_loader/program/src/evm/tracing/tracers/struct_logger.rs index d165ebea3a..08ebd2dc1b 100644 --- a/evm_loader/program/src/evm/tracing/tracers/struct_logger.rs +++ b/evm_loader/program/src/evm/tracing/tracers/struct_logger.rs @@ -4,7 +4,7 @@ use ethnum::U256; use serde::Serialize; use serde_json::Value; -use crate::evm::tracing::tracers::opname_table::OPNAMES; +use crate::evm::opcode_table::OPNAMES; use crate::evm::tracing::TraceConfig; use crate::evm::tracing::{EmulationResult, Event, EventListener}; use crate::types::hexbytes::HexBytes;