Skip to content

Commit c1891a7

Browse files
committed
Improve general CFG, improve .evm support
1 parent b3f1b4a commit c1891a7

File tree

10 files changed

+225
-54
lines changed

10 files changed

+225
-54
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ There are already tools that allow you to debug Ethereum transactions (Solidity)
2020

2121
Use one of these releases:
2222

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

2626
If you want to use master (it can be more unstable), clone and start the application

package-lock.json

Lines changed: 114 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "ethereum-graph-debugger",
33
"author": "Fernando Garcia",
44
"license": "GPL",
5-
"version": "3.1.0",
5+
"version": "2.3.0",
66
"description": "Ethereum graph debugger",
77
"main": "dist/run-server.js",
88
"scripts": {
@@ -83,7 +83,7 @@
8383
"recursive-readdir": "^2.2.2",
8484
"redux-thunk": "^2.3.0",
8585
"reflect-metadata": "^0.1.12",
86-
"solc": "^0.5.8",
86+
"solc": "^0.4.24",
8787
"terser": "3.14.1",
8888
"tsoa": "2.1.8",
8989
"web3": "1.0.0-beta.37",

src/api/bytecode/EVMDisassembler.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ export class EVMDisassembler implements Disassembler {
4646
if (bytecode.startsWith('0x')) {
4747
code = bytecode.slice(2)
4848
}
49+
4950
if (code.includes(EVMDisassembler.metadataPrefix)) {
5051
code = code.split(EVMDisassembler.metadataPrefix)[0]
5152
}
52-
53+
54+
code = code.length % 2 !== 0 ? code.substr(0, code.length-1): code
5355
if (code.length % 2 !== 0) {
54-
throw new Error(`Bad input, bytecode length not even: ${code}, length: ${code.length}`)
56+
throw new Error(`disassembleContract - Bad input, bytecode length not even: ${code}, length: ${code.length}`)
5557
}
5658

5759
const operations: Operation[] = this.disassembleBytecode(bytecode)
@@ -60,7 +62,7 @@ export class EVMDisassembler implements Disassembler {
6062
let runtime = operations
6163
if (hasConstructor) {
6264
// pre- 0.5.* the opcode we are searching is 'STOP', post 0.5.* is INVALID
63-
const firstStopIndex = operations.findIndex(op => op.opcode.name === 'INVALID')
65+
const firstStopIndex = operations.findIndex(op => op.opcode.name === 'STOP')
6466
constructor = operations.slice(0, firstStopIndex + 1)
6567
runtime = this.adjustRuntimeOffset(operations.slice(firstStopIndex + 1, operations.length))
6668
}
@@ -82,8 +84,9 @@ export class EVMDisassembler implements Disassembler {
8284
if (code.includes(EVMDisassembler.metadataPrefix)) {
8385
code = code.split(EVMDisassembler.metadataPrefix)[0]
8486
}
87+
code = code.length % 2 !== 0 ? code.substr(0, code.length-1): code
8588
if (code.length % 2 !== 0) {
86-
throw new Error(`Bad input, bytecode length not even: ${code}, length: ${code.length}`)
89+
throw new Error(`disassembleBytecode - Bad input, bytecode length not even: ${code}, length: ${code.length}`)
8790
}
8891
let offset = 0
8992
const operations = code.match(/.{1,2}/g)

src/api/bytecode/Opcodes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export class Opcodes {
155155
static isJump(op: Opcode) {
156156
return op.name.startsWith('JUMP')
157157
}
158+
159+
static isJumpOp(op: string) {
160+
return op.startsWith('JUMP') && op !== 'JUMPDEST'
161+
}
158162
}
159163

160164
Opcodes.populate()

src/api/cfg/CFGBlocks.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ export class CFGBlocks {
77
this.blocks[offset] = block
88
}
99

10-
// getBlock(offset: number): OperationBlock {
11-
// return this.blocks[offset]
12-
// }
13-
1410
get(offset: number): OperationBlock {
1511
const block: OperationBlock = this.blocks[offset]
1612
if(!block) {

src/api/service/controller/DebuggerController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class DebuggerController extends Controller {
4242
blockchainBasicAuthPassword
4343
} as Web3Configuration
4444
const contractBlocks: CFGContract = await this.cfgService.buildCFGFromSource(name, source, path)
45-
const runtimeRawBytecode = `0x${contractBlocks.contractRuntime.rawBytecode}`
45+
const runtimeRawBytecode = contractBlocks.contractRuntime.rawBytecode.startsWith('0x')? contractBlocks.contractRuntime.rawBytecode: `0x${contractBlocks.contractRuntime.rawBytecode}`
4646
const trace: DebugTrace = await this.transactionService.findTransactionTrace(tx, runtimeRawBytecode, config)
4747
const cfg = this.createCFG(contractBlocks, false, trace)
4848
return this.buildResponse(contractBlocks, false, cfg, trace)
@@ -57,6 +57,7 @@ export class DebuggerController extends Controller {
5757
if (constructor) {
5858
blocks = contractBlocks.contractConstructor.blocks
5959
}
60+
this.cfgService.completeCFGWithTrace(blocks, trace)
6061
return this.graphVizService.createDotFromBlocks(blocks, trace)
6162
}
6263

0 commit comments

Comments
 (0)