UNPKG

@bcoders.gr/evm-disassembler

Version:

A comprehensive EVM bytecode disassembler and analyzer with support for multiple EVM versions

142 lines (122 loc) 4.43 kB
/** * Constants and configurations for EVM bytecode disassembler * @module constants */ /** * Core constants used throughout the disassembler */ const CONSTANTS = { JUMPDEST_OPCODE: 0x5b, PUSH0_OPCODE: 0x5f, PUSH_START: 0x60, PUSH_END: 0x7f, PUSH_BASE: 0x5f, MIN_ASCII: 32, MAX_ASCII: 126, ASCII_THRESHOLD: 0.7, MAX_BYTECODE_SIZE: 24576 * 2 // 24KB contract size limit * 2 for hex }; /** * Dangerous opcodes that should be flagged during analysis */ const DANGEROUS_OPCODES = ['DELEGATECALL', 'CALLCODE', 'SELFDESTRUCT', 'CREATE2']; /** * Common metadata markers in bytecode */ const METADATA_MARKERS = [ { pattern: "a164736f6c6343", name: "Solidity compiler", type: "solc" }, { pattern: "a265627a7a72315820", name: "Solidity (older)", type: "solc" }, { pattern: "b53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850", name: "Vyper", type: "vyper" } ]; /** * Known function signatures for common ERC standards */ const KNOWN_SIGNATURES = new Map([ ['a9059cbb', 'transfer(address,uint256)'], ['095ea7b3', 'approve(address,uint256)'], ['70a08231', 'balanceOf(address)'], ['dd62ed3e', 'allowance(address,address)'], ['18160ddd', 'totalSupply()'], ['06fdde03', 'name()'], ['95d89b41', 'symbol()'], ['313ce567', 'decimals()'], ['8da5cb5b', 'owner()'], ['f2fde38b', 'transferOwnership(address)'], ['715018a6', 'renounceOwnership()'], ['5c975abb', 'pause()'], ['3f4ba83a', 'unpause()'], ['5c19a95c', 'paused()'], ['23b872dd', 'transferFrom(address,address,uint256)'], ['a22cb465', 'setApprovalForAll(address,bool)'], ['e985e9c5', 'isApprovedForAll(address,address)'], ['42842e0e', 'safeTransferFrom(address,address,uint256)'], ['b88d4fde', 'safeTransferFrom(address,address,uint256,bytes)'], ['6352211e', 'ownerOf(uint256)'], ['081812fc', 'getApproved(uint256)'], ['01ffc9a7', 'supportsInterface(bytes4)'] ]); /** * Stack effects for each opcode [inputs, outputs] */ const STACK_EFFECTS = { // Arithmetic operations (2 inputs, 1 output) 'ADD': [2, 1], 'MUL': [2, 1], 'SUB': [2, 1], 'DIV': [2, 1], 'SDIV': [2, 1], 'MOD': [2, 1], 'SMOD': [2, 1], 'EXP': [2, 1], 'SIGNEXTEND': [2, 1], 'LT': [2, 1], 'GT': [2, 1], 'SLT': [2, 1], 'SGT': [2, 1], 'EQ': [2, 1], 'AND': [2, 1], 'OR': [2, 1], 'XOR': [2, 1], 'BYTE': [2, 1], 'SHL': [2, 1], 'SHR': [2, 1], 'SAR': [2, 1], // Ternary operations (3 inputs, 1 output) 'ADDMOD': [3, 1], 'MULMOD': [3, 1], // Unary operations (1 input, 1 output) 'ISZERO': [1, 1], 'NOT': [1, 1], // Stack operations 'POP': [1, 0], // Memory operations 'MLOAD': [1, 1], 'MSTORE': [2, 0], 'MSTORE8': [2, 0], 'CALLDATALOAD': [1, 1], 'CALLDATACOPY': [3, 0], 'CODECOPY': [3, 0], 'EXTCODECOPY': [4, 0], 'RETURNDATACOPY': [3, 0], 'MCOPY': [3, 0], // Storage operations 'SLOAD': [1, 1], 'SSTORE': [2, 0], 'TLOAD': [1, 1], 'TSTORE': [2, 0], // Control flow 'JUMP': [1, 0], 'JUMPI': [2, 0], // System operations 'RETURN': [2, 0], 'REVERT': [2, 0], 'STOP': [0, 0], 'SELFDESTRUCT': [1, 0], // Calls (with proper input counts) 'CALL': [7, 1], 'CALLCODE': [7, 1], 'DELEGATECALL': [6, 1], 'STATICCALL': [6, 1], 'CREATE': [3, 1], 'CREATE2': [4, 1], // Environmental info (0 inputs, 1 output) 'ADDRESS': [0, 1], 'ORIGIN': [0, 1], 'CALLER': [0, 1], 'CALLVALUE': [0, 1], 'CALLDATASIZE': [0, 1], 'CODESIZE': [0, 1], 'GASPRICE': [0, 1], 'RETURNDATASIZE': [0, 1], 'PC': [0, 1], 'MSIZE': [0, 1], 'GAS': [0, 1], 'COINBASE': [0, 1], 'TIMESTAMP': [0, 1], 'NUMBER': [0, 1], 'PREVRANDAO': [0, 1], 'GASLIMIT': [0, 1], 'CHAINID': [0, 1], 'SELFBALANCE': [0, 1], 'BASEFEE': [0, 1], 'BLOBHASH': [1, 1], 'BLOBBASEFEE': [0, 1], // Crypto 'SHA3': [2, 1], // Other operations with inputs 'BALANCE': [1, 1], 'EXTCODESIZE': [1, 1], 'EXTCODEHASH': [1, 1], 'BLOCKHASH': [1, 1], // Logging (offset + size + topics) 'LOG0': [2, 0], 'LOG1': [3, 0], 'LOG2': [4, 0], 'LOG3': [5, 0], 'LOG4': [6, 0], // No stack effect 'JUMPDEST': [0, 0], 'INVALID': [0, 0] }; module.exports = { CONSTANTS, DANGEROUS_OPCODES, METADATA_MARKERS, KNOWN_SIGNATURES, STACK_EFFECTS };