diff --git a/src/helpers/util.js b/src/helpers/util.js index e9f51c4167..8c6aa39ffd 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.indexOf('0x') !== 0) { + value = '0x' + value + } var ret = ethutil.bufferToHex(ethutil.setLengthLeft(value, 32)) ret = ethutil.sha3(ret) return ethutil.bufferToHex(ret) diff --git a/src/storage/storageResolver.js b/src/storage/storageResolver.js index 4d1521f055..4165388642 100644 --- a/src/storage/storageResolver.js +++ b/src/storage/storageResolver.js @@ -62,18 +62,18 @@ 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) } - 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 } } 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) @@ -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, @@ -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') } 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) } }) } 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 } diff --git a/src/web3Provider/web3VmProvider.js b/src/web3Provider/web3VmProvider.js index 88f7769d87..e53d6a0b50 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: JSON.parse(JSON.stringify(storage)), + nextKey: null }) } else { cb('unable to retrieve storage ' + txIndex + ' ' + address) 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)'])