diff --git a/libs/remix-debug/src/code/codeUtils.ts b/libs/remix-debug/src/code/codeUtils.ts index 061b64e8c8..b44dd2be61 100644 --- a/libs/remix-debug/src/code/codeUtils.ts +++ b/libs/remix-debug/src/code/codeUtils.ts @@ -1,6 +1,7 @@ 'use strict' import Common from '@ethereumjs/common' import { getOpcodesForHF } from '@ethereumjs/vm/dist/evm/opcodes' +import getOpcodes from './opcodes' export function nameOpCodes (raw, hardfork) { const common = new Common({ chain: 'mainnet', hardfork }) @@ -34,6 +35,12 @@ export function nameOpCodes (raw, hardfork) { return [code, codeMap] } +type Opcode = { + name: String, + pushData?: Array + in?: number + out?: number +} /** * Parses code as a list of integers into a list of objects containing * information about the opcode. @@ -44,15 +51,19 @@ export function parseCode (raw) { const code = [] for (let i = 0; i < raw.length; i++) { - let opcode + const opcode: Opcode = { name: 'INVALID' } try { - opcode = opcodes.get(raw[i]).fullName + const code = opcodes.get(raw[i]) + const opcodeDetails = getOpcodes(raw[i], false) + opcode.in = opcodeDetails.in + opcode.out = opcodeDetails.out + opcode.name = code.fullName } catch (e) { - opcode = 'INVALID' + opcode.name = 'INVALID' } if (opcode.name.slice(0, 4) === 'PUSH') { const length = raw[i] - 0x5f - opcode['pushData'] = raw.slice(i + 1, i + length + 1) + opcode.pushData = raw.slice(i + 1, i + length + 1) // in case pushdata extends beyond code if (i + 1 + length > raw.length) { for (let j = opcode['pushData'].length; j < length; j++) {