From f3a8cf405349dc3d522f9289f859c25c42c61237 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 11 Apr 2017 22:55:39 +0200 Subject: [PATCH] check key && hashedkey --- src/storage/storageResolver.js | 20 ++++++++++++-------- src/storage/storageViewer.js | 16 +++++++++++++++- src/trace/traceCache.js | 5 +++++ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/storage/storageResolver.js b/src/storage/storageResolver.js index 4e8bf9e0ae..a90a455cb3 100644 --- a/src/storage/storageResolver.js +++ b/src/storage/storageResolver.js @@ -1,6 +1,5 @@ 'use strict' var traceHelper = require('../helpers/traceHelper') -var helper = require('../helpers/util') var util = require('../helpers/global') class StorageResolver { @@ -19,7 +18,7 @@ class StorageResolver { * @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value} */ storageRange (tx, stepIndex, callback) { - storageRangeInternal(this, '0x0', tx, stepIndex, true, callback) + storageRangeInternal(this, '0x0000000000000000000000000000000000000000000000000000000000000000', tx, stepIndex, true, callback) } /** @@ -31,12 +30,11 @@ class StorageResolver { * @param {Function} - callback - {key, hashedKey, value} - */ storageSlot (slot, tx, stepIndex, callback) { - var hashed = helper.sha3_32(slot) - storageRangeInternal(this, hashed, tx, stepIndex, false, function (error, storage) { + storageRangeInternal(this, slot, tx, stepIndex, false, function (error, storage) { if (error) { callback(error) } else { - callback(null, storage[hashed] !== undefined ? storage[hashed] : null) + callback(null, storage[slot] !== undefined ? storage[slot] : null) } }) } @@ -71,15 +69,21 @@ function storageRangeInternal (self, slotKey, tx, stepIndex, fullStorage, callba return callback(null, storageChanges) } var cached = fromCache(self, address) - if (cached && cached[slotKey]) { // we have the current slot in the cache and maybe the next 1000... - return callback(null, Object.assign(cached, storageChanges)) + if (cached && cached.storage[slotKey]) { // we have the current slot in the cache and maybe the next 1000... + return callback(null, Object.assign(cached.storage, storageChanges)) } storageRangeWeb3Call(tx, address, slotKey, self.maxSize, (error, storage, complete) => { if (error) { return callback(error) } + if (!storage[slotKey]) { + storage[slotKey] = { + key: slotKey, + value: '0x0000000000000000000000000000000000000000000000000000000000000000' + } + } toCache(self, address, storage) - if (slotKey === '0x0' && Object.keys(storage).length < self.maxSize) { + if (slotKey === '0x0000000000000000000000000000000000000000000000000000000000000000' && Object.keys(storage).length < self.maxSize) { self.storageByAddress[address].complete = true } callback(null, Object.assign(storage, storageChanges)) diff --git a/src/storage/storageViewer.js b/src/storage/storageViewer.js index af551cc442..a20b138d71 100644 --- a/src/storage/storageViewer.js +++ b/src/storage/storageViewer.js @@ -1,4 +1,5 @@ 'use strict' +var helper = require('../helpers/util') class StorageViewer { constructor (_context, _storageResolver) { @@ -22,7 +23,20 @@ class StorageViewer { * @param {Function} - callback - {key, hashedKey, value} - */ storageSlot (slot, callback) { - this.storageResolver.storageSlot(slot, this.context.tx, this.context.stepIndex, callback) + this.storageResolver.storageSlot(slot, this.context.tx, this.context.stepIndex, (error, result) => { + if (error || !result || !result[slot]) { + var hashed = helper.sha3_32(slot) + this.storageResolver.storageSlot(hashed, this.context.tx, this.context.stepIndex, (error, result) => { + if (error) { + callback(error) + } else { + callback(null, result) + } + }) + } else { + return callback(null, result) + } + }) } /** diff --git a/src/trace/traceCache.js b/src/trace/traceCache.js index 7a94109c7b..17cb135747 100644 --- a/src/trace/traceCache.js +++ b/src/trace/traceCache.js @@ -106,6 +106,11 @@ TraceCache.prototype.accumulateStorageChanges = function (index, address, storag key: sstore.key, value: sstore.value } + ret[sstore.key] = { + hashedKey: sstore.hashedKey, + key: sstore.key, + value: sstore.value + } } } return ret