Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
kadenzipfel committed Oct 8, 2022
1 parent 19e7a41 commit 674eea4
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 341 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
phf = { version = "0.10", features = ["macros"] }
strum = "0.24"
strum_macros = "0.24"
colored = "2.0.0"
304 changes: 2 additions & 302 deletions src/evm.rs
Original file line number Diff line number Diff line change
@@ -1,308 +1,6 @@
use phf::phf_map;
use std::fmt;
use strum_macros::EnumString;

// Source: https://github.com/huff-language/huff-rs/blob/main/huff_utils/src/evm.rs

/// All the EVM opcodes as a static array
/// They are arranged in a particular order such that all the opcodes that have common
/// prefixes are ordered by decreasing length to avoid mismatch when lexing.
/// Example : [origin, or] or [push32, ..., push3]
pub const OPCODES: [&str; 144] = [
"lt",
"gt",
"slt",
"sgt",
"eq",
"iszero",
"and",
"origin",
"or",
"xor",
"not",
"sha3",
"address",
"balance",
"caller",
"callvalue",
"calldataload",
"calldatasize",
"calldatacopy",
"codesize",
"codecopy",
"basefee",
"blockhash",
"coinbase",
"timestamp",
"number",
"difficulty",
"prevrandao",
"gaslimit",
"chainid",
"selfbalance",
"pop",
"mload",
"mstore8",
"mstore",
"sload",
"sstore",
"jumpdest",
"jumpi",
"jump",
"pc",
"msize",
"stop",
"addmod",
"add",
"mulmod",
"mul",
"sub",
"div",
"sdiv",
"mod",
"smod",
"exp",
"signextend",
"byte",
"shl",
"shr",
"sar",
"gasprice",
"extcodesize",
"extcodecopy",
"returndatasize",
"returndatacopy",
"extcodehash",
"gas",
"log0",
"log1",
"log2",
"log3",
"log4",
"create2",
"create",
"callcode",
"call",
"return",
"delegatecall",
"staticcall",
"revert",
"invalid",
"selfdestruct",
"push32",
"push31",
"push30",
"push29",
"push28",
"push27",
"push26",
"push25",
"push24",
"push23",
"push22",
"push21",
"push20",
"push19",
"push18",
"push17",
"push16",
"push15",
"push14",
"push13",
"push12",
"push11",
"push10",
"push9",
"push8",
"push7",
"push6",
"push5",
"push4",
"push3",
"push2",
"push1",
"swap16",
"swap15",
"swap14",
"swap13",
"swap12",
"swap11",
"swap10",
"swap9",
"swap8",
"swap7",
"swap6",
"swap5",
"swap4",
"swap3",
"swap2",
"swap1",
"dup16",
"dup15",
"dup14",
"dup13",
"dup12",
"dup11",
"dup10",
"dup9",
"dup8",
"dup7",
"dup6",
"dup5",
"dup4",
"dup3",
"dup2",
"dup1",
];

/// Hashmap of all the EVM opcodes
pub static OPCODES_MAP: phf::Map<&'static str, Opcode> = phf_map! {
"lt" => Opcode::Lt,
"gt" => Opcode::Gt,
"slt" => Opcode::Slt,
"sgt" => Opcode::Sgt,
"eq" => Opcode::Eq,
"iszero" => Opcode::Iszero,
"and" => Opcode::And,
"or" => Opcode::Or,
"xor" => Opcode::Xor,
"not" => Opcode::Not,
"sha3" => Opcode::Sha3,
"address" => Opcode::Address,
"balance" => Opcode::Balance,
"origin" => Opcode::Origin,
"caller" => Opcode::Caller,
"callvalue" => Opcode::Callvalue,
"calldataload" => Opcode::Calldataload,
"calldatasize" => Opcode::Calldatasize,
"calldatacopy" => Opcode::Calldatacopy,
"codesize" => Opcode::Codesize,
"codecopy" => Opcode::Codecopy,
"basefee" => Opcode::Basefee,
"blockhash" => Opcode::Blockhash,
"coinbase" => Opcode::Coinbase,
"timestamp" => Opcode::Timestamp,
"number" => Opcode::Number,
"difficulty" => Opcode::Difficulty,
"prevrandao" => Opcode::Prevrandao,
"gaslimit" => Opcode::Gaslimit,
"chainid" => Opcode::Chainid,
"selfbalance" => Opcode::Selfbalance,
"pop" => Opcode::Pop,
"mload" => Opcode::Mload,
"mstore" => Opcode::Mstore,
"mstore8" => Opcode::Mstore8,
"sload" => Opcode::Sload,
"sstore" => Opcode::Sstore,
"jump" => Opcode::Jump,
"jumpi" => Opcode::Jumpi,
"pc" => Opcode::Pc,
"msize" => Opcode::Msize,
"push1" => Opcode::Push1,
"push2" => Opcode::Push2,
"push3" => Opcode::Push3,
"push4" => Opcode::Push4,
"push5" => Opcode::Push5,
"push6" => Opcode::Push6,
"push7" => Opcode::Push7,
"push8" => Opcode::Push8,
"push9" => Opcode::Push9,
"push10" => Opcode::Push10,
"push17" => Opcode::Push17,
"push18" => Opcode::Push18,
"push19" => Opcode::Push19,
"push20" => Opcode::Push20,
"push21" => Opcode::Push21,
"push22" => Opcode::Push22,
"push23" => Opcode::Push23,
"push24" => Opcode::Push24,
"push25" => Opcode::Push25,
"push26" => Opcode::Push26,
"dup1" => Opcode::Dup1,
"dup2" => Opcode::Dup2,
"dup3" => Opcode::Dup3,
"dup4" => Opcode::Dup4,
"dup5" => Opcode::Dup5,
"dup6" => Opcode::Dup6,
"dup7" => Opcode::Dup7,
"dup8" => Opcode::Dup8,
"dup9" => Opcode::Dup9,
"dup10" => Opcode::Dup10,
"swap1" => Opcode::Swap1,
"swap2" => Opcode::Swap2,
"swap3" => Opcode::Swap3,
"swap4" => Opcode::Swap4,
"swap5" => Opcode::Swap5,
"swap6" => Opcode::Swap6,
"swap7" => Opcode::Swap7,
"swap8" => Opcode::Swap8,
"swap9" => Opcode::Swap9,
"swap10" => Opcode::Swap10,
"stop" => Opcode::Stop,
"add" => Opcode::Add,
"mul" => Opcode::Mul,
"sub" => Opcode::Sub,
"div" => Opcode::Div,
"sdiv" => Opcode::Sdiv,
"mod" => Opcode::Mod,
"smod" => Opcode::Smod,
"addmod" => Opcode::Addmod,
"mulmod" => Opcode::Mulmod,
"exp" => Opcode::Exp,
"signextend" => Opcode::Signextend,
"byte" => Opcode::Byte,
"shl" => Opcode::Shl,
"shr" => Opcode::Shr,
"sar" => Opcode::Sar,
"gasprice" => Opcode::Gasprice,
"extcodesize" => Opcode::Extcodesize,
"extcodecopy" => Opcode::Extcodecopy,
"returndatasize" => Opcode::Returndatasize,
"returndatacopy" => Opcode::Returndatacopy,
"extcodehash" => Opcode::Extcodehash,
"gas" => Opcode::Gas,
"jumpdest" => Opcode::Jumpdest,
"push11" => Opcode::Push11,
"push12" => Opcode::Push12,
"push13" => Opcode::Push13,
"push14" => Opcode::Push14,
"push15" => Opcode::Push15,
"push16" => Opcode::Push16,
"push27" => Opcode::Push27,
"push28" => Opcode::Push28,
"push29" => Opcode::Push29,
"push30" => Opcode::Push30,
"push31" => Opcode::Push31,
"push32" => Opcode::Push32,
"dup11" => Opcode::Dup11,
"dup12" => Opcode::Dup12,
"dup13" => Opcode::Dup13,
"dup14" => Opcode::Dup14,
"dup15" => Opcode::Dup15,
"dup16" => Opcode::Dup16,
"swap11" => Opcode::Swap11,
"swap12" => Opcode::Swap12,
"swap13" => Opcode::Swap13,
"swap14" => Opcode::Swap14,
"swap15" => Opcode::Swap15,
"swap16" => Opcode::Swap16,
"log0" => Opcode::Log0,
"log1" => Opcode::Log1,
"log2" => Opcode::Log2,
"log3" => Opcode::Log3,
"log4" => Opcode::Log4,
"create" => Opcode::Create,
"call" => Opcode::Call,
"callcode" => Opcode::Callcode,
"return" => Opcode::Return,
"delegatecall" => Opcode::Delegatecall,
"staticcall" => Opcode::Staticcall,
"create2" => Opcode::Create2,
"revert" => Opcode::Revert,
"invalid" => Opcode::Invalid,
"selfdestruct" => Opcode::Selfdestruct
};

pub const PUSH_OPS: [Opcode; 32] = [
Opcode::Push1,
Opcode::Push2,
Expand Down Expand Up @@ -338,6 +36,7 @@ pub const PUSH_OPS: [Opcode; 32] = [
Opcode::Push32,
];

// Source: https://github.com/huff-language/huff-rs/blob/main/huff_utils/src/evm.rs
/// EVM Opcodes
/// References <https://evm.codes>
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, EnumString)]
Expand Down Expand Up @@ -636,6 +335,7 @@ pub enum Opcode {
InvalidOpcode,
}

// Source: https://github.com/huff-language/huff-rs/blob/main/huff_utils/src/evm.rs
impl Opcode {
/// Translates a hex string into an Opcode
pub fn new(string: &str) -> Self {
Expand Down
38 changes: 0 additions & 38 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,6 @@ pub fn min_pushdata_len(string: &String) -> (usize, String) {
(len, string[start..].to_string())
}

pub fn is_push_op(opcode: Opcode) -> bool {
match opcode {
Opcode::Push1 => true,
Opcode::Push2 => true,
Opcode::Push3 => true,
Opcode::Push4 => true,
Opcode::Push5 => true,
Opcode::Push6 => true,
Opcode::Push7 => true,
Opcode::Push8 => true,
Opcode::Push9 => true,
Opcode::Push10 => true,
Opcode::Push11 => true,
Opcode::Push12 => true,
Opcode::Push13 => true,
Opcode::Push14 => true,
Opcode::Push15 => true,
Opcode::Push16 => true,
Opcode::Push17 => true,
Opcode::Push18 => true,
Opcode::Push19 => true,
Opcode::Push20 => true,
Opcode::Push21 => true,
Opcode::Push22 => true,
Opcode::Push23 => true,
Opcode::Push24 => true,
Opcode::Push25 => true,
Opcode::Push26 => true,
Opcode::Push27 => true,
Opcode::Push28 => true,
Opcode::Push29 => true,
Opcode::Push30 => true,
Opcode::Push31 => true,
Opcode::Push32 => true,
_ => false,
}
}

pub fn match_push_n(opcode: Opcode) -> usize {
match opcode {
Opcode::Push1 => 1,
Expand Down

0 comments on commit 674eea4

Please sign in to comment.