@@ -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)
0 commit comments