Skip to content

Commit

Permalink
Improve general CFG, improve .evm support
Browse files Browse the repository at this point in the history
  • Loading branch information
fergarrui committed May 6, 2019
1 parent b3f1b4a commit c1891a7
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ There are already tools that allow you to debug Ethereum transactions (Solidity)

Use one of these releases:

* solc 0.4.24 compatible with ganache use: [v2.2.0](https://github.com/fergarrui/ethereum-graph-debugger/releases/tag/v2.2.0)
* solc 0.4.24 compatible with ganache use: [v2.3.0](https://github.com/fergarrui/ethereum-graph-debugger/releases/tag/v2.3.0)
* solc 0.5.8 (not compatible with ganache) use: [v3.1.0](https://github.com/fergarrui/ethereum-graph-debugger/releases/tag/v3.1.0)

If you want to use master (it can be more unstable), clone and start the application
Expand Down
150 changes: 114 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ethereum-graph-debugger",
"author": "Fernando Garcia",
"license": "GPL",
"version": "3.1.0",
"version": "2.3.0",
"description": "Ethereum graph debugger",
"main": "dist/run-server.js",
"scripts": {
Expand Down Expand Up @@ -83,7 +83,7 @@
"recursive-readdir": "^2.2.2",
"redux-thunk": "^2.3.0",
"reflect-metadata": "^0.1.12",
"solc": "^0.5.8",
"solc": "^0.4.24",
"terser": "3.14.1",
"tsoa": "2.1.8",
"web3": "1.0.0-beta.37",
Expand Down
11 changes: 7 additions & 4 deletions src/api/bytecode/EVMDisassembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ export class EVMDisassembler implements Disassembler {
if (bytecode.startsWith('0x')) {
code = bytecode.slice(2)
}

if (code.includes(EVMDisassembler.metadataPrefix)) {
code = code.split(EVMDisassembler.metadataPrefix)[0]
}


code = code.length % 2 !== 0 ? code.substr(0, code.length-1): code
if (code.length % 2 !== 0) {
throw new Error(`Bad input, bytecode length not even: ${code}, length: ${code.length}`)
throw new Error(`disassembleContract - Bad input, bytecode length not even: ${code}, length: ${code.length}`)
}

const operations: Operation[] = this.disassembleBytecode(bytecode)
Expand All @@ -60,7 +62,7 @@ export class EVMDisassembler implements Disassembler {
let runtime = operations
if (hasConstructor) {
// pre- 0.5.* the opcode we are searching is 'STOP', post 0.5.* is INVALID
const firstStopIndex = operations.findIndex(op => op.opcode.name === 'INVALID')
const firstStopIndex = operations.findIndex(op => op.opcode.name === 'STOP')
constructor = operations.slice(0, firstStopIndex + 1)
runtime = this.adjustRuntimeOffset(operations.slice(firstStopIndex + 1, operations.length))
}
Expand All @@ -82,8 +84,9 @@ export class EVMDisassembler implements Disassembler {
if (code.includes(EVMDisassembler.metadataPrefix)) {
code = code.split(EVMDisassembler.metadataPrefix)[0]
}
code = code.length % 2 !== 0 ? code.substr(0, code.length-1): code
if (code.length % 2 !== 0) {
throw new Error(`Bad input, bytecode length not even: ${code}, length: ${code.length}`)
throw new Error(`disassembleBytecode - Bad input, bytecode length not even: ${code}, length: ${code.length}`)
}
let offset = 0
const operations = code.match(/.{1,2}/g)
Expand Down
4 changes: 4 additions & 0 deletions src/api/bytecode/Opcodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ export class Opcodes {
static isJump(op: Opcode) {
return op.name.startsWith('JUMP')
}

static isJumpOp(op: string) {
return op.startsWith('JUMP') && op !== 'JUMPDEST'
}
}

Opcodes.populate()
4 changes: 0 additions & 4 deletions src/api/cfg/CFGBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ export class CFGBlocks {
this.blocks[offset] = block
}

// getBlock(offset: number): OperationBlock {
// return this.blocks[offset]
// }

get(offset: number): OperationBlock {
const block: OperationBlock = this.blocks[offset]
if(!block) {
Expand Down
3 changes: 2 additions & 1 deletion src/api/service/controller/DebuggerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class DebuggerController extends Controller {
blockchainBasicAuthPassword
} as Web3Configuration
const contractBlocks: CFGContract = await this.cfgService.buildCFGFromSource(name, source, path)
const runtimeRawBytecode = `0x${contractBlocks.contractRuntime.rawBytecode}`
const runtimeRawBytecode = contractBlocks.contractRuntime.rawBytecode.startsWith('0x')? contractBlocks.contractRuntime.rawBytecode: `0x${contractBlocks.contractRuntime.rawBytecode}`
const trace: DebugTrace = await this.transactionService.findTransactionTrace(tx, runtimeRawBytecode, config)
const cfg = this.createCFG(contractBlocks, false, trace)
return this.buildResponse(contractBlocks, false, cfg, trace)
Expand All @@ -57,6 +57,7 @@ export class DebuggerController extends Controller {
if (constructor) {
blocks = contractBlocks.contractConstructor.blocks
}
this.cfgService.completeCFGWithTrace(blocks, trace)
return this.graphVizService.createDotFromBlocks(blocks, trace)
}

Expand Down
Loading

0 comments on commit c1891a7

Please sign in to comment.