|
|
@ -1,5 +1,5 @@ |
|
|
|
import { util } from '@remix-project/remix-lib' |
|
|
|
import { util } from '@remix-project/remix-lib' |
|
|
|
const { hexListFromBNs, formatMemory } = util |
|
|
|
const { toHexPaddedString, formatMemory } = util |
|
|
|
import { helpers } from '@remix-project/remix-lib' |
|
|
|
import { helpers } from '@remix-project/remix-lib' |
|
|
|
const { normalizeHexAddress } = helpers.ui |
|
|
|
const { normalizeHexAddress } = helpers.ui |
|
|
|
import { ConsoleLogs } from '@remix-project/remix-lib' |
|
|
|
import { ConsoleLogs } from '@remix-project/remix-lib' |
|
|
@ -240,7 +240,7 @@ export class VmProxy { |
|
|
|
previousOpcode.invalidDepthChange = previousOpcode.op !== 'RETURN' && previousOpcode.op !== 'STOP' |
|
|
|
previousOpcode.invalidDepthChange = previousOpcode.op !== 'RETURN' && previousOpcode.op !== 'STOP' |
|
|
|
} |
|
|
|
} |
|
|
|
const step = { |
|
|
|
const step = { |
|
|
|
stack: hexListFromBNs(data.stack), |
|
|
|
stack: { ...data.stack }, |
|
|
|
storage: {}, |
|
|
|
storage: {}, |
|
|
|
memory: null, |
|
|
|
memory: null, |
|
|
|
op: data.opcode.name, |
|
|
|
op: data.opcode.name, |
|
|
@ -249,6 +249,7 @@ export class VmProxy { |
|
|
|
gas: data.gasLeft.toString(), |
|
|
|
gas: data.gasLeft.toString(), |
|
|
|
depth: depth |
|
|
|
depth: depth |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
step.stack.length = Object.keys(data.stack).length |
|
|
|
|
|
|
|
|
|
|
|
if (previousOpcode && (previousOpcode.op === 'CALLDATACOPY' || previousOpcode.op === 'CODECOPY' || previousOpcode.op === 'EXTCODECOPY' || previousOpcode.op === 'RETURNDATACOPY' || previousOpcode.op === 'MSTORE' || previousOpcode.op === 'MSTORE8')) { |
|
|
|
if (previousOpcode && (previousOpcode.op === 'CALLDATACOPY' || previousOpcode.op === 'CODECOPY' || previousOpcode.op === 'EXTCODECOPY' || previousOpcode.op === 'RETURNDATACOPY' || previousOpcode.op === 'MSTORE' || previousOpcode.op === 'MSTORE8')) { |
|
|
|
step.memory = data.memory |
|
|
|
step.memory = data.memory |
|
|
@ -256,9 +257,8 @@ export class VmProxy { |
|
|
|
} |
|
|
|
} |
|
|
|
this.vmTraces[this.processingHash].structLogs.push(step) |
|
|
|
this.vmTraces[this.processingHash].structLogs.push(step) |
|
|
|
// Track hardhat console.log call
|
|
|
|
// Track hardhat console.log call
|
|
|
|
if (step.op === 'STATICCALL' && step.stack[step.stack.length - 2] === '0x000000000000000000000000000000000000000000636f6e736f6c652e6c6f67') { |
|
|
|
if (step.op === 'STATICCALL' && toHexPaddedString(step.stack[step.stack.length - 2]) === '0x000000000000000000000000000000000000000000636f6e736f6c652e6c6f67') { |
|
|
|
const stackLength = step.stack.length |
|
|
|
const payloadStart = parseInt(toHexPaddedString(step.stack[step.stack.length - 3]), 16) |
|
|
|
const payloadStart = parseInt(step.stack[stackLength - 3], 16) |
|
|
|
|
|
|
|
const memory = formatMemory(data.memory) |
|
|
|
const memory = formatMemory(data.memory) |
|
|
|
const memoryStr = memory.join('') |
|
|
|
const memoryStr = memory.join('') |
|
|
|
let payload = memoryStr.substring(payloadStart * 2, memoryStr.length) |
|
|
|
let payload = memoryStr.substring(payloadStart * 2, memoryStr.length) |
|
|
@ -290,7 +290,7 @@ export class VmProxy { |
|
|
|
this.processingAddress = '(Contract Creation - Step ' + this.processingIndex + ')' |
|
|
|
this.processingAddress = '(Contract Creation - Step ' + this.processingIndex + ')' |
|
|
|
this.storageCache[this.processingHash][this.processingAddress] = {} |
|
|
|
this.storageCache[this.processingHash][this.processingAddress] = {} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.processingAddress = normalizeHexAddress(step.stack[step.stack.length - 2]) |
|
|
|
this.processingAddress = normalizeHexAddress(toHexPaddedString(step.stack[step.stack.length - 2])) |
|
|
|
this.processingAddress = toChecksumAddress(this.processingAddress) |
|
|
|
this.processingAddress = toChecksumAddress(this.processingAddress) |
|
|
|
if (!this.storageCache[this.processingHash][this.processingAddress]) { |
|
|
|
if (!this.storageCache[this.processingHash][this.processingAddress]) { |
|
|
|
(async (processingHash, processingAddress, self) => { |
|
|
|
(async (processingHash, processingAddress, self) => { |
|
|
@ -307,7 +307,7 @@ export class VmProxy { |
|
|
|
} |
|
|
|
} |
|
|
|
if (previousOpcode && previousOpcode.op === 'SHA3') { |
|
|
|
if (previousOpcode && previousOpcode.op === 'SHA3') { |
|
|
|
const preimage = this.getSha3Input(previousOpcode.stack, formatMemory(this.lastMemoryUpdate)) |
|
|
|
const preimage = this.getSha3Input(previousOpcode.stack, formatMemory(this.lastMemoryUpdate)) |
|
|
|
const imageHash = step.stack[step.stack.length - 1].replace('0x', '') |
|
|
|
const imageHash = toHexPaddedString(step.stack[step.stack.length - 1]).replace('0x', '') |
|
|
|
this.sha3Preimages[imageHash] = { |
|
|
|
this.sha3Preimages[imageHash] = { |
|
|
|
preimage: preimage |
|
|
|
preimage: preimage |
|
|
|
} |
|
|
|
} |
|
|
@ -421,26 +421,26 @@ export class VmProxy { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getSha3Input (stack, memory) { |
|
|
|
getSha3Input (stack, memory) { |
|
|
|
let memoryStart = stack[stack.length - 1] |
|
|
|
const memoryStart = toHexPaddedString(stack[stack.length - 1]) |
|
|
|
let memoryLength = stack[stack.length - 2] |
|
|
|
const memoryLength = toHexPaddedString(stack[stack.length - 2]) |
|
|
|
const memStartDec = (new BN(memoryStart.replace('0x', ''), 16)).toString(10) |
|
|
|
const memStartDec = (new BN(memoryStart.replace('0x', ''), 16)).toString(10) |
|
|
|
memoryStart = parseInt(memStartDec) * 2 |
|
|
|
const memoryStartInt = parseInt(memStartDec) * 2 |
|
|
|
const memLengthDec = (new BN(memoryLength.replace('0x', ''), 16).toString(10)) |
|
|
|
const memLengthDec = (new BN(memoryLength.replace('0x', ''), 16).toString(10)) |
|
|
|
memoryLength = parseInt(memLengthDec) * 2 |
|
|
|
const memoryLengthInt = parseInt(memLengthDec) * 2 |
|
|
|
|
|
|
|
|
|
|
|
let i = Math.floor(memoryStart / 32) |
|
|
|
let i = Math.floor(memoryStartInt / 32) |
|
|
|
const maxIndex = Math.floor(memoryLength / 32) + i |
|
|
|
const maxIndex = Math.floor(memoryLengthInt / 32) + i |
|
|
|
if (!memory[i]) { |
|
|
|
if (!memory[i]) { |
|
|
|
return this.emptyFill(memoryLength) |
|
|
|
return this.emptyFill(memoryLength) |
|
|
|
} |
|
|
|
} |
|
|
|
let sha3Input = memory[i].slice(memoryStart - 32 * i) |
|
|
|
let sha3Input = memory[i].slice(memoryStartInt - 32 * i) |
|
|
|
i++ |
|
|
|
i++ |
|
|
|
while (i < maxIndex) { |
|
|
|
while (i < maxIndex) { |
|
|
|
sha3Input += memory[i] ? memory[i] : this.emptyFill(32) |
|
|
|
sha3Input += memory[i] ? memory[i] : this.emptyFill(32) |
|
|
|
i++ |
|
|
|
i++ |
|
|
|
} |
|
|
|
} |
|
|
|
if (sha3Input.length < memoryLength) { |
|
|
|
if (sha3Input.length < memoryLength) { |
|
|
|
const leftSize = memoryLength - sha3Input.length |
|
|
|
const leftSize = memoryLengthInt - sha3Input.length |
|
|
|
sha3Input += memory[i] ? memory[i].slice(0, leftSize) : this.emptyFill(leftSize) |
|
|
|
sha3Input += memory[i] ? memory[i].slice(0, leftSize) : this.emptyFill(leftSize) |
|
|
|
} |
|
|
|
} |
|
|
|
return sha3Input |
|
|
|
return sha3Input |
|
|
|