From 31ec2ae9c284076c15f775c4be79c3f00b0fa15d Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 18 Apr 2017 12:11:47 +0200 Subject: [PATCH 1/2] remove swarm hash --- src/code/sourceLocationTracker.js | 2 +- src/solidity/solidityProxy.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/code/sourceLocationTracker.js b/src/code/sourceLocationTracker.js index 5da61f8cd0..3955bc1f62 100644 --- a/src/code/sourceLocationTracker.js +++ b/src/code/sourceLocationTracker.js @@ -67,7 +67,7 @@ function getSourceMap (address, code, contracts) { var isCreation = helper.isContractCreation(address) var byteProp = isCreation ? 'bytecode' : 'runtimeBytecode' for (var k in contracts) { - if (code.indexOf('0x' + contracts[k][byteProp]) === 0) { + if (code.replace(/.{64}0029$/, '').indexOf('0x' + contracts[k][byteProp].replace(/.{64}0029$/, '')) === 0) { return isCreation ? contracts[k].srcmap : srcmapRuntime(contracts[k]) } } diff --git a/src/solidity/solidityProxy.js b/src/solidity/solidityProxy.js index c0db891e71..c15bff4940 100644 --- a/src/solidity/solidityProxy.js +++ b/src/solidity/solidityProxy.js @@ -136,7 +136,7 @@ function contractNameFromCode (contracts, code, address) { var isCreation = traceHelper.isContractCreation(address) var byteProp = isCreation ? 'bytecode' : 'runtimeBytecode' for (var k in contracts) { - if ('0x' + contracts[k][byteProp] === code) { + if ('0x' + contracts[k][byteProp].replace(/.{64}0029$/, '') === code.replace(/.{64}0029$/, '')) { return k } } From 553e4b43bec57ab46fa8a0cbd482bf4d885ee14d Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 19 Apr 2017 10:19:35 +0200 Subject: [PATCH 2/2] fix swarm hash extraction --- src/code/sourceLocationTracker.js | 3 ++- src/helpers/util.js | 35 +++++++++++++++++++------------ src/solidity/solidityProxy.js | 3 ++- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/code/sourceLocationTracker.js b/src/code/sourceLocationTracker.js index 3955bc1f62..b8737ff66f 100644 --- a/src/code/sourceLocationTracker.js +++ b/src/code/sourceLocationTracker.js @@ -2,6 +2,7 @@ var EventManager = require('../lib/eventManager') var helper = require('../helpers/traceHelper') var SourceMappingDecoder = require('../util/sourceMappingDecoder') +var util = require('../helpers/util') /** * Process the source code location for the current executing bytecode @@ -67,7 +68,7 @@ function getSourceMap (address, code, contracts) { var isCreation = helper.isContractCreation(address) var byteProp = isCreation ? 'bytecode' : 'runtimeBytecode' for (var k in contracts) { - if (code.replace(/.{64}0029$/, '').indexOf('0x' + contracts[k][byteProp].replace(/.{64}0029$/, '')) === 0) { + if (code.replace(util.swarmHashExtraction(), '').indexOf('0x' + contracts[k][byteProp].replace(util.swarmHashExtraction(), '')) === 0) { return isCreation ? contracts[k].srcmap : srcmapRuntime(contracts[k]) } } diff --git a/src/helpers/util.js b/src/helpers/util.js index c421be2853..e9f51c4167 100644 --- a/src/helpers/util.js +++ b/src/helpers/util.js @@ -109,14 +109,21 @@ module.exports = { }, /** - * Find the call from @args rootCall which contains @args index (recursive) - * - * @param {Int} index - index of the vmtrace - * @param {Object} rootCall - call tree, built by the trace analyser - * @return {Object} - return the call which include the @args index - */ + * Find the call from @args rootCall which contains @args index (recursive) + * + * @param {Int} index - index of the vmtrace + * @param {Object} rootCall - call tree, built by the trace analyser + * @return {Object} - return the call which include the @args index + */ findCall: findCall, + /** + * Find calls path from @args rootCall which leads to @args index (recursive) + * + * @param {Int} index - index of the vmtrace + * @param {Object} rootCall - call tree, built by the trace analyser + * @return {Array} - return the calls path to @args index + */ buildCallPath: buildCallPath, /** @@ -129,16 +136,18 @@ module.exports = { var ret = ethutil.bufferToHex(ethutil.setLengthLeft(value, 32)) ret = ethutil.sha3(ret) return ethutil.bufferToHex(ret) + }, + + /** + * return a regex which extract the swarmhash from the bytecode. + * + * @return {RegEx} + */ + swarmHashExtraction: function () { + return /a165627a7a72305820([0-9a-f]{64})0029$/ } } -/** - * Find calls path from @args rootCall which leads to @args index (recursive) - * - * @param {Int} index - index of the vmtrace - * @param {Object} rootCall - call tree, built by the trace analyser - * @return {Array} - return the calls path to @args index - */ function buildCallPath (index, rootCall) { var ret = [] findCallInternal(index, rootCall, ret) diff --git a/src/solidity/solidityProxy.js b/src/solidity/solidityProxy.js index c15bff4940..f7c1a22742 100644 --- a/src/solidity/solidityProxy.js +++ b/src/solidity/solidityProxy.js @@ -2,6 +2,7 @@ var traceHelper = require('../helpers/traceHelper') var stateDecoder = require('./stateDecoder') var astHelper = require('./astHelper') +var util = require('../helpers/util') class SolidityProxy { constructor (traceManager, codeManager) { @@ -136,7 +137,7 @@ function contractNameFromCode (contracts, code, address) { var isCreation = traceHelper.isContractCreation(address) var byteProp = isCreation ? 'bytecode' : 'runtimeBytecode' for (var k in contracts) { - if ('0x' + contracts[k][byteProp].replace(/.{64}0029$/, '') === code.replace(/.{64}0029$/, '')) { + if ('0x' + contracts[k][byteProp].replace(util.swarmHashExtraction(), '') === code.replace(util.swarmHashExtraction(), '')) { return k } }