add tweak vm

add_tweak_vm
yann300 2 years ago
parent 5414ea5e3a
commit abce838dae
  1. 19
      libs/remix-core-plugin/src/lib/compiler-content-imports.ts
  2. 20
      libs/remix-simulator/src/VmProxy.ts

@ -170,6 +170,25 @@ export class CompilerImports extends Plugin {
await this.call('solidityUnitTesting', 'createTestLibs')
exist = await provider.exists(url)
}
if (!exist && url === 'forge-std/Vm.sol') {
const content = `// SPDX-License-Identifier: MIT
pragma solidity >= 0.4.22 <0.9.0;
library vm {
address constant VM_ADDRESS = address(0x000000000000000000636f6E736F6C652e6c6F68);
function startPrank(address _sender) private view {
bytes memory payload = abi.encodeWithSignature("startPrank(address)", _sender);
uint256 payloadLength = payload.length;
address consoleAddress = VM_ADDRESS;
assembly {
let payloadStart := add(payload, 32)
let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0)
}
}
}`
await this.call('fileManager', 'writeFile', 'forge-std/Vm.sol', content)
}
if (!exist && url.startsWith('browser/')) throw new Error(`not found ${url}`)
if (!exist && url.startsWith('localhost/')) throw new Error(`not found ${url}`)
if (exist) {

@ -286,6 +286,26 @@ export class VmProxy {
this.hhLogs[this.processingHash] = this.hhLogs[this.processingHash] ? this.hhLogs[this.processingHash] : []
this.hhLogs[this.processingHash].push(consoleArgs)
}
// Track forge vm call
if (step.op === 'STATICCALL' && toHexPaddedString(step.stack[step.stack.length - 2]) === '0x000000000000000000000000000000000000000000636f6e736f6c652e6c6f68') {
const payloadStart = parseInt(toHexPaddedString(step.stack[step.stack.length - 3]), 16)
const memory = formatMemory(data.memory)
const memoryStr = memory.join('')
let payload = memoryStr.substring(payloadStart * 2, memoryStr.length)
const fnselectorStr = payload.substring(0, 8)
const fnselectorStrInHex = '0x' + fnselectorStr
const fnArgs = '(address)'
const iface = new ethers.utils.Interface([`function prank${fnArgs} view`])
const functionDesc = iface.getFunction(`prank${fnArgs}`)
const sigHash = iface.getSighash(`prank${fnArgs}`)
if (fnArgs.includes('uint') && sigHash !== fnselectorStrInHex) {
payload = payload.replace(fnselectorStr, sigHash)
} else {
payload = '0x' + payload
}
let prankArgs = iface.decodeFunctionData(functionDesc, payload)
}
if (step.op === 'CREATE' || step.op === 'CALL') {
if (step.op === 'CREATE') {

Loading…
Cancel
Save