From 0ba6cd5eece8c8affaa25c055a47f4711c08c9a7 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 20 Apr 2017 14:16:10 +0200 Subject: [PATCH 01/10] normalize hex --- src/helpers/util.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/helpers/util.js b/src/helpers/util.js index e9f51c4167..1d1d3655da 100644 --- a/src/helpers/util.js +++ b/src/helpers/util.js @@ -133,6 +133,9 @@ module.exports = { * @return {Object} - return sha3ied value */ sha3_256: function (value) { + if (typeof value === 'string' && !value.startsWith('0x')) { + value = '0x' + value + } var ret = ethutil.bufferToHex(ethutil.setLengthLeft(value, 32)) ret = ethutil.sha3(ret) return ethutil.bufferToHex(ret) From cd9dd859ad97da2e1af1aafc8f846243aca941df Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 20 Apr 2017 14:16:29 +0200 Subject: [PATCH 02/10] fix storageSlot --- src/storage/storageViewer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage/storageViewer.js b/src/storage/storageViewer.js index 472ce20603..ca117f5b6c 100644 --- a/src/storage/storageViewer.js +++ b/src/storage/storageViewer.js @@ -44,7 +44,7 @@ class StorageViewer { if (error) { callback(error) } else { - callback(null, storage[hashed] !== undefined ? storage[hashed] : null) + callback(null, storage) } }) } From 7641c37dc1e95660bb428878b3091942e5ea15d8 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 20 Apr 2017 14:16:40 +0200 Subject: [PATCH 03/10] don't cache zero slot --- src/storage/storageResolver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage/storageResolver.js b/src/storage/storageResolver.js index 4d1521f055..8873b36638 100644 --- a/src/storage/storageResolver.js +++ b/src/storage/storageResolver.js @@ -66,7 +66,7 @@ function storageRangeInternal (self, slotKey, tx, stepIndex, address, callback) if (error) { return callback(error) } - if (!storage[slotKey]) { + if (!storage[slotKey] && slotKey !== zeroSlot) { // we don't cache the zero slot (could lead to inconsistency) storage[slotKey] = { key: slotKey, value: zeroSlot From 6f96dc5737755451d0a14e0f39ac4571b79c8b12 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 20 Apr 2017 14:18:22 +0200 Subject: [PATCH 04/10] storageRangeAt implementation changed --- src/storage/storageResolver.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/storage/storageResolver.js b/src/storage/storageResolver.js index 8873b36638..c0d6ee19c3 100644 --- a/src/storage/storageResolver.js +++ b/src/storage/storageResolver.js @@ -62,7 +62,7 @@ function storageRangeInternal (self, slotKey, tx, stepIndex, address, callback) if (cached && cached.storage[slotKey]) { // we have the current slot in the cache and maybe the next 1000... return callback(null, cached.storage) } - storageRangeWeb3Call(tx, address, slotKey, self.maxSize, (error, storage, complete) => { + storageRangeWeb3Call(tx, address, slotKey, self.maxSize, (error, storage, nextKey) => { if (error) { return callback(error) } @@ -73,7 +73,7 @@ function storageRangeInternal (self, slotKey, tx, stepIndex, address, callback) } } toCache(self, address, storage) - if (slotKey === zeroSlot && Object.keys(storage).length < self.maxSize) { // only working if keys are sorted !! + if (slotKey === zeroSlot && !nextKey) { // only working if keys are sorted !! self.storageByAddress[address].complete = true } callback(null, storage) @@ -121,7 +121,7 @@ function storageRangeWeb3Call (tx, address, start, maxSize, callback) { if (error) { callback(error) } else if (result.storage) { - callback(null, result.storage, result.complete) + callback(null, result.storage, result.nextKey) } else { callback('the storage has not been provided') } From 3da6ebc586ae62c275ead3a9ed109edecdc740f0 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 20 Apr 2017 14:23:58 +0200 Subject: [PATCH 05/10] fix vm web3 provider --- src/storage/storageResolver.js | 2 +- src/web3Provider/web3VmProvider.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/storage/storageResolver.js b/src/storage/storageResolver.js index c0d6ee19c3..4165388642 100644 --- a/src/storage/storageResolver.js +++ b/src/storage/storageResolver.js @@ -110,7 +110,7 @@ function toCache (self, address, storage) { function storageRangeWeb3Call (tx, address, start, maxSize, callback) { if (traceHelper.isContractCreation(address)) { - callback(null, {}, true) + callback(null, {}, null) } else { util.web3.debug.storageRangeAt( tx.blockHash, tx.transactionIndex === undefined ? tx.hash : tx.transactionIndex, diff --git a/src/web3Provider/web3VmProvider.js b/src/web3Provider/web3VmProvider.js index 88f7769d87..5f61dfb59c 100644 --- a/src/web3Provider/web3VmProvider.js +++ b/src/web3Provider/web3VmProvider.js @@ -158,8 +158,8 @@ web3VmProvider.prototype.storageRangeAt = function (blockNumber, txIndex, addres if (this.storageCache[txIndex] && this.storageCache[txIndex][address]) { var storage = this.storageCache[txIndex][address] return cb(null, { - storage: JSON.parse(JSON.stringify(storage)), // copy - complete: true + storage: Object.assign({}, storage), + nextKey: null }) } else { cb('unable to retrieve storage ' + txIndex + ' ' + address) From b03c67075e70fe0c79d8be140f6aa9525c9979bd Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 20 Apr 2017 14:36:38 +0200 Subject: [PATCH 06/10] remove hashedKey from the storagechange value --- src/trace/traceCache.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/trace/traceCache.js b/src/trace/traceCache.js index 3d31012270..71f14be8ee 100644 --- a/src/trace/traceCache.js +++ b/src/trace/traceCache.js @@ -102,7 +102,6 @@ TraceCache.prototype.accumulateStorageChanges = function (index, address, storag var sstore = this.sstore[changesIndex] if (sstore.address === address && sstore.key) { ret[sstore.hashedKey] = { - hashedKey: sstore.hashedKey, key: sstore.key, value: sstore.value } From fd2bcb4e4925af5bc6742920acf795e3f64c58ce Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 21 Apr 2017 11:10:58 +0200 Subject: [PATCH 07/10] fix test --- test-browser/vmdebugger.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test-browser/vmdebugger.js b/test-browser/vmdebugger.js index 2c7459b768..a307289311 100644 --- a/test-browser/vmdebugger.js +++ b/test-browser/vmdebugger.js @@ -64,9 +64,7 @@ function panels (browser) { .click('#load') .multipleClick('#intoforward', 63) .assertStack(['0:0x', '1:0x60', '2:0x65', '3:0x38', '4:0x55', '5:0x60fe47b1']) - .assertStorageChanges([ - '0x0000000000000000000000000000000000000000000000000000000000000000:Objectkey:0x0000000000000000000000000000000000000000000000000000000000000000value:0x0000000000000000000000000000000000000000000000000000000000000000', - '0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563:ObjecthashedKey:0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563key:0x00value:0x38']) + .assertStorageChanges(['0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563:Objectkey:0x00value:0x38']) .assertCallData(['0:0x60fe47b10000000000000000000000000000000000000000000000000000000000000038']) .assertCallStack(['0:0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5']) .assertStackValue(1, '1:0x60') @@ -75,7 +73,7 @@ function panels (browser) { .assertMemoryValue(8, '0x80:5b806001016000600050819055505b50?????????P??UP?P') .click('#intoforward') // CREATE .assertStack(['']) - .assertStorageChanges(['0x0000000000000000000000000000000000000000000000000000000000000000:Objectkey:0x0000000000000000000000000000000000000000000000000000000000000000value:0x0000000000000000000000000000000000000000000000000000000000000000']) + .assertStorageChanges([]) .assertMemory(['']) .assertCallData(['0:0x0000000000000000000000000000000000000000000000000000000000000000000000000000006060606040526040516020806045833981016040528080519060200190919050505b806001016000600050819055']) .assertCallStack(['0:0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', '1:(ContractCreation-Step63)']) From 189e6ee38ba4fee62b92e96879ccb6c7702eeec0 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 21 Apr 2017 11:51:31 +0200 Subject: [PATCH 08/10] fix build --- package.json | 72 +++++++++++++++++++++++------- src/web3Provider/web3VmProvider.js | 2 +- 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index d060ec9822..208fd49604 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,9 @@ }, "devDependencies": { "babel-eslint": "^7.1.1", - "babel-preset-es2015": "^6.24.0", "babel-plugin-transform-object-assign": "^6.22.0", + "babel-plugin-yo-yoify": "^0.4.0", + "babel-preset-es2015": "^6.24.0", "babelify": "^7.3.0", "browserify": "^13.0.1", "ethereum-common": "0.0.18", @@ -40,7 +41,7 @@ "yo-yoify": "^3.1.0" }, "scripts": { - "build": "mkdirp build; browserify src/index.js > build/app.js", + "build": "mkdirp build; browserify src/index.js > build/app.js -d", "lint": "standard | notify-error", "nightwatch_local": "nightwatch --config nightwatch.js --env local", "nightwatch_remote_chrome": "nightwatch --config nightwatch.js --env chrome", @@ -81,23 +82,60 @@ ], "parser": "babel-eslint" }, + "babel": { + "plugins": [ + "transform-es2015-template-literals", + "transform-es2015-literals", + "transform-es2015-function-name", + "transform-es2015-arrow-functions", + "transform-es2015-block-scoped-functions", + "transform-es2015-classes", + "transform-es2015-object-super", + "transform-es2015-shorthand-properties", + "transform-es2015-duplicate-keys", + "transform-es2015-computed-properties", + "transform-es2015-for-of", + "transform-es2015-sticky-regex", + "transform-es2015-unicode-regex", + "check-es2015-constants", + "transform-es2015-spread", + "transform-es2015-parameters", + "transform-es2015-destructuring", + "transform-es2015-block-scoping" + ] + }, "browserify": { "transform": [ - ["babelify", { - "plugins": [ - ["fast-async", { - "runtimePatten": null, - "compiler": { - "promises": true, - "es7": true, - "noRuntime": true, - "wrapAwait": true - } - }], "transform-object-assign" - ] - }], - ["yo-yoify"], - ["babelify", { "presets": ["es2015"] }] + [ + "babelify", + { + "sourceMapsAbsolute": false, + "sourceMaps": true, + "plugins": [ + [ + "fast-async", + { + "runtimePattern": null, + "compiler": { + "es7": true, + "noRuntime": true, + "promises": true, + "wrapAwait": true + } + } + ], + [ + "yo-yoify" + ], + [ + "transform-object-assign" + ] + ], + "presets": [ + "es2015" + ] + } + ] ] } } diff --git a/src/web3Provider/web3VmProvider.js b/src/web3Provider/web3VmProvider.js index 5f61dfb59c..e53d6a0b50 100644 --- a/src/web3Provider/web3VmProvider.js +++ b/src/web3Provider/web3VmProvider.js @@ -158,7 +158,7 @@ web3VmProvider.prototype.storageRangeAt = function (blockNumber, txIndex, addres if (this.storageCache[txIndex] && this.storageCache[txIndex][address]) { var storage = this.storageCache[txIndex][address] return cb(null, { - storage: Object.assign({}, storage), + storage: JSON.parse(JSON.stringify(storage)), nextKey: null }) } else { From 9f8ef39670c606fc66990a9c2219e2aa4ec54090 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 21 Apr 2017 16:57:57 +0200 Subject: [PATCH 09/10] rollback package.json --- package.json | 72 +++++++++++++--------------------------------------- 1 file changed, 17 insertions(+), 55 deletions(-) diff --git a/package.json b/package.json index 208fd49604..d060ec9822 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,8 @@ }, "devDependencies": { "babel-eslint": "^7.1.1", - "babel-plugin-transform-object-assign": "^6.22.0", - "babel-plugin-yo-yoify": "^0.4.0", "babel-preset-es2015": "^6.24.0", + "babel-plugin-transform-object-assign": "^6.22.0", "babelify": "^7.3.0", "browserify": "^13.0.1", "ethereum-common": "0.0.18", @@ -41,7 +40,7 @@ "yo-yoify": "^3.1.0" }, "scripts": { - "build": "mkdirp build; browserify src/index.js > build/app.js -d", + "build": "mkdirp build; browserify src/index.js > build/app.js", "lint": "standard | notify-error", "nightwatch_local": "nightwatch --config nightwatch.js --env local", "nightwatch_remote_chrome": "nightwatch --config nightwatch.js --env chrome", @@ -82,60 +81,23 @@ ], "parser": "babel-eslint" }, - "babel": { - "plugins": [ - "transform-es2015-template-literals", - "transform-es2015-literals", - "transform-es2015-function-name", - "transform-es2015-arrow-functions", - "transform-es2015-block-scoped-functions", - "transform-es2015-classes", - "transform-es2015-object-super", - "transform-es2015-shorthand-properties", - "transform-es2015-duplicate-keys", - "transform-es2015-computed-properties", - "transform-es2015-for-of", - "transform-es2015-sticky-regex", - "transform-es2015-unicode-regex", - "check-es2015-constants", - "transform-es2015-spread", - "transform-es2015-parameters", - "transform-es2015-destructuring", - "transform-es2015-block-scoping" - ] - }, "browserify": { "transform": [ - [ - "babelify", - { - "sourceMapsAbsolute": false, - "sourceMaps": true, - "plugins": [ - [ - "fast-async", - { - "runtimePattern": null, - "compiler": { - "es7": true, - "noRuntime": true, - "promises": true, - "wrapAwait": true - } - } - ], - [ - "yo-yoify" - ], - [ - "transform-object-assign" - ] - ], - "presets": [ - "es2015" - ] - } - ] + ["babelify", { + "plugins": [ + ["fast-async", { + "runtimePatten": null, + "compiler": { + "promises": true, + "es7": true, + "noRuntime": true, + "wrapAwait": true + } + }], "transform-object-assign" + ] + }], + ["yo-yoify"], + ["babelify", { "presets": ["es2015"] }] ] } } From ed9a95dfa8de53253d1ab6f90f8381ceae3e120c Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 21 Apr 2017 17:26:50 +0200 Subject: [PATCH 10/10] fix test --- src/helpers/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/util.js b/src/helpers/util.js index 1d1d3655da..8c6aa39ffd 100644 --- a/src/helpers/util.js +++ b/src/helpers/util.js @@ -133,7 +133,7 @@ module.exports = { * @return {Object} - return sha3ied value */ sha3_256: function (value) { - if (typeof value === 'string' && !value.startsWith('0x')) { + if (typeof value === 'string' && value.indexOf('0x') !== 0) { value = '0x' + value } var ret = ethutil.bufferToHex(ethutil.setLengthLeft(value, 32))