Merge pull request #489 from ethereum/fixStorage

Fix storage
pull/7/head
yann300 8 years ago committed by GitHub
commit 3069e36c4b
  1. 3
      src/helpers/util.js
  2. 10
      src/storage/storageResolver.js
  3. 2
      src/storage/storageViewer.js
  4. 1
      src/trace/traceCache.js
  5. 4
      src/web3Provider/web3VmProvider.js
  6. 6
      test-browser/vmdebugger.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)

@ -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')
}

@ -44,7 +44,7 @@ class StorageViewer {
if (error) {
callback(error)
} else {
callback(null, storage[hashed] !== undefined ? storage[hashed] : null)
callback(null, storage)
}
})
}

@ -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
}

@ -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)

@ -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)'])

Loading…
Cancel
Save