From 871b634a691259c13e8789d82be05f7d9b505912 Mon Sep 17 00:00:00 2001 From: Mouradif Date: Thu, 18 Apr 2024 04:31:16 +0200 Subject: [PATCH] feat: Dencun opcodes --- .../assets/disassembler_test_assets.ts | 33 +++++++++++++++++++ src/utils/evm_opcodes.ts | 7 +++- src/utils/helpers.ts | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/__tests__/disassembler/assets/disassembler_test_assets.ts b/__tests__/disassembler/assets/disassembler_test_assets.ts index b1c42ce..e1f98a7 100644 --- a/__tests__/disassembler/assets/disassembler_test_assets.ts +++ b/__tests__/disassembler/assets/disassembler_test_assets.ts @@ -23,6 +23,39 @@ export const DISASSEMBLER_TESTING_ASSETS = [ { index16: '0x17', hex: 'fe', mnemonic: 'INVALID', operand: [] }, ], }, + { + bytecode: + '0x601d8060093d393df3365f5d5f5f3761000a565b5f5c591061001857005b5f5ffd', + expectedDisassembly: [ + { index16: '0x0', hex: '60', mnemonic: 'PUSH1', operand: ['1d'] }, + { index16: '0x2', hex: '80', mnemonic: 'DUP1', operand: [] }, + { index16: '0x3', hex: '60', mnemonic: 'PUSH1', operand: ['09'] }, + { index16: '0x5', hex: '3d', mnemonic: 'RETURNDATASIZE', operand: [] }, + { index16: '0x6', hex: '39', mnemonic: 'CODECOPY', operand: [] }, + { index16: '0x7', hex: '3d', mnemonic: 'RETURNDATASIZE', operand: [] }, + { index16: '0x8', hex: 'f3', mnemonic: 'RETURN', operand: [] }, + { index16: '0x9', hex: '36', mnemonic: 'CALLDATASIZE', operand: [] }, + { index16: '0xa', hex: '5f', mnemonic: 'PUSH0', operand: [] }, + { index16: '0xb', hex: '5d', mnemonic: 'TSTORE', operand: [] }, + { index16: '0xc', hex: '5f', mnemonic: 'PUSH0', operand: [] }, + { index16: '0xd', hex: '5f', mnemonic: 'PUSH0', operand: [] }, + { index16: '0xe', hex: '37', mnemonic: 'CALLDATACOPY', operand: [] }, + { index16: '0xf', hex: '61', mnemonic: 'PUSH2', operand: ['00', '0a'] }, + { index16: '0x12', hex: '56', mnemonic: 'JUMP', operand: [] }, + { index16: '0x13', hex: '5b', mnemonic: 'JUMPDEST', operand: [] }, + { index16: '0x14', hex: '5f', mnemonic: 'PUSH0', operand: [] }, + { index16: '0x15', hex: '5c', mnemonic: 'TLOAD', operand: [] }, + { index16: '0x16', hex: '59', mnemonic: 'MSIZE', operand: [] }, + { index16: '0x17', hex: '10', mnemonic: 'LT', operand: [] }, + { index16: '0x18', hex: '61', mnemonic: 'PUSH2', operand: ['00', '18'] }, + { index16: '0x1b', hex: '57', mnemonic: 'JUMPI', operand: [] }, + { index16: '0x1c', hex: '00', mnemonic: 'STOP', operand: [] }, + { index16: '0x1d', hex: '5b', mnemonic: 'JUMPDEST', operand: [] }, + { index16: '0x1e', hex: '5f', mnemonic: 'PUSH0', operand: [] }, + { index16: '0x1f', hex: '5f', mnemonic: 'PUSH0', operand: [] }, + { index16: '0x20', hex: 'fd', mnemonic: 'REVERT', operand: [] }, + ], + }, { bytecode: '6080604052348015600e575f80fd5b50603e80601a5f395ff3fe60806040525f80fdfea264697066735822122050e5031fe7e93a1922e48aa845237cf82fc6f3ab36fc1a876ad6fbeda900307a64736f6c63430008150033', diff --git a/src/utils/evm_opcodes.ts b/src/utils/evm_opcodes.ts index a6ab582..58c0cf6 100644 --- a/src/utils/evm_opcodes.ts +++ b/src/utils/evm_opcodes.ts @@ -53,11 +53,13 @@ export const EVM_OPCODES = new Map([ ['41', { mnemonic: 'COINBASE', operand: 0 }], ['42', { mnemonic: 'TIMESTAMP', operand: 0 }], ['43', { mnemonic: 'NUMBER', operand: 0 }], - ['44', { mnemonic: 'DIFFICULTY', operand: 0 }], + ['44', { mnemonic: 'PREVRANDAO', operand: 0 }], ['45', { mnemonic: 'GASLIMIT', operand: 0 }], ['46', { mnemonic: 'CHAINID', operand: 0 }], ['47', { mnemonic: 'SELFBALANCE', operand: 0 }], ['48', { mnemonic: 'BASEFEE', operand: 0 }], + ['49', { mnemonic: 'BLOBHASH', operand: 0 }], + ['4a', { mnemonic: 'BLOBBASEFEE', operand: 0 }], ['50', { mnemonic: 'POP', operand: 0 }], ['51', { mnemonic: 'MLOAD', operand: 0 }], ['52', { mnemonic: 'MSTORE', operand: 0 }], @@ -70,6 +72,9 @@ export const EVM_OPCODES = new Map([ ['59', { mnemonic: 'MSIZE', operand: 0 }], ['5a', { mnemonic: 'GAS', operand: 0 }], ['5b', { mnemonic: 'JUMPDEST', operand: 0 }], + ['5c', { mnemonic: 'TLOAD', operand: 0 }], + ['5d', { mnemonic: 'TSTORE', operand: 0 }], + ['5e', { mnemonic: 'MCOPY', operand: 0 }], ['5f', { mnemonic: 'PUSH0', operand: 0 }], ['60', { mnemonic: 'PUSH1', operand: 1 }], ['61', { mnemonic: 'PUSH2', operand: 2 }], diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 56624bb..b3c36cf 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -8,7 +8,7 @@ export class Helpers { * @returns */ public static isPushOp(opcode: EvmOpcode): boolean { - return opcode.mnemonic.includes('PUSH'); + return opcode.mnemonic.startsWith('PUSH'); } /**