Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
aef34c6d
Commit
aef34c6d
authored
May 18, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move sha3 mapping from traceChache to web3VMProvider
- add we3.debug.preimage - move mapping resolver from soliditystate to storageViewer
parent
8b768613
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
132 additions
and
108 deletions
+132
-108
decodeInfo.js
src/solidity/decodeInfo.js
+2
-2
Mapping.js
src/solidity/types/Mapping.js
+15
-10
StringType.js
src/solidity/types/StringType.js
+1
-1
mappingPreimages.js
src/storage/mappingPreimages.js
+58
-0
storageViewer.js
src/storage/storageViewer.js
+12
-0
traceAnalyser.js
src/trace/traceAnalyser.js
+0
-16
traceCache.js
src/trace/traceCache.js
+0
-14
SolidityState.js
src/ui/SolidityState.js
+3
-65
web3Admin.js
src/util/web3Admin.js
+9
-0
web3VmProvider.js
src/web3Provider/web3VmProvider.js
+32
-0
No files found.
src/solidity/decodeInfo.js
View file @
aef34c6d
...
@@ -190,7 +190,7 @@ function struct (type, stateDefinitions, contractName, location) {
...
@@ -190,7 +190,7 @@ function struct (type, stateDefinitions, contractName, location) {
if
(
!
location
)
{
if
(
!
location
)
{
location
=
match
[
2
].
trim
()
location
=
match
[
2
].
trim
()
}
}
var
memberDetails
=
getStructMembers
(
match
[
1
],
stateDefinitions
,
contractName
)
// type is used to extract the ast struct definition
var
memberDetails
=
getStructMembers
(
match
[
1
],
stateDefinitions
,
contractName
,
location
)
// type is used to extract the ast struct definition
if
(
!
memberDetails
)
return
null
if
(
!
memberDetails
)
return
null
return
new
StructType
(
memberDetails
,
location
,
match
[
1
])
return
new
StructType
(
memberDetails
,
location
,
match
[
1
])
}
else
{
}
else
{
...
@@ -233,7 +233,7 @@ function getEnum (type, stateDefinitions, contractName) {
...
@@ -233,7 +233,7 @@ function getEnum (type, stateDefinitions, contractName) {
* @param {String} location - location of the data (storage ref| storage pointer| memory| calldata)
* @param {String} location - location of the data (storage ref| storage pointer| memory| calldata)
* @return {Array} containing all members of the current struct type
* @return {Array} containing all members of the current struct type
*/
*/
function
getStructMembers
(
type
,
stateDefinitions
,
contractName
)
{
function
getStructMembers
(
type
,
stateDefinitions
,
contractName
,
location
)
{
var
split
=
type
.
split
(
'.'
)
var
split
=
type
.
split
(
'.'
)
if
(
!
split
.
length
)
{
if
(
!
split
.
length
)
{
type
=
contractName
+
'.'
+
type
type
=
contractName
+
'.'
+
type
...
...
src/solidity/types/Mapping.js
View file @
aef34c6d
'use strict'
'use strict'
var
RefType
=
require
(
'./RefType'
)
var
RefType
=
require
(
'./RefType'
)
var
util
=
require
(
'./util'
)
var
ethutil
=
require
(
'ethereumjs-util'
)
var
ethutil
=
require
(
'ethereumjs-util'
)
class
Mapping
extends
RefType
{
class
Mapping
extends
RefType
{
...
@@ -9,22 +10,26 @@ class Mapping extends RefType {
...
@@ -9,22 +10,26 @@ class Mapping extends RefType {
this
.
valueType
=
underlyingTypes
.
valueType
this
.
valueType
=
underlyingTypes
.
valueType
}
}
setMappingElements
(
mappingKeyPreimages
)
{
this
.
preimages
=
mappingKeyPreimages
}
async
decodeFromStorage
(
location
,
storageResolver
)
{
async
decodeFromStorage
(
location
,
storageResolver
)
{
// location.offset should always be 0 for a mapping (?? double check)
try
{
var
mappingsPreimages
=
await
storageResolver
.
mappingPreimages
()
}
catch
(
e
)
{
return
{
value
:
'<error> '
+
e
.
message
,
type
:
this
.
type
}
}
var
mapSlot
=
util
.
toBN
(
location
.
slot
).
toString
(
16
)
mapSlot
=
ethutil
.
setLengthLeft
(
'0x'
+
mapSlot
,
32
).
toString
(
'hex'
)
var
mappingPreimages
=
mappingsPreimages
[
mapSlot
]
var
ret
=
{}
var
ret
=
{}
for
(
var
i
in
this
.
preimages
)
{
for
(
var
i
in
mappingPreimages
)
{
var
preimage
=
this
.
preimages
[
i
]
var
mapLocation
=
getMappingLocation
(
i
,
location
.
slot
)
var
mapLocation
=
getMappingLocation
(
preimage
,
location
.
slot
)
var
globalLocation
=
{
var
globalLocation
=
{
offset
:
location
.
offset
,
offset
:
location
.
offset
,
slot
:
mapLocation
slot
:
mapLocation
}
}
ret
[
preimage
]
=
await
this
.
valueType
.
decodeFromStorage
(
globalLocation
,
storageResolver
)
ret
[
i
]
=
await
this
.
valueType
.
decodeFromStorage
(
globalLocation
,
storageResolver
)
}
}
return
{
return
{
...
...
src/solidity/types/StringType.js
View file @
aef34c6d
...
@@ -40,7 +40,7 @@ function format (decoded) {
...
@@ -40,7 +40,7 @@ function format (decoded) {
var
value
=
decoded
.
value
var
value
=
decoded
.
value
value
=
value
.
replace
(
'0x'
,
''
).
replace
(
/
(
..
)
/g
,
'%$1'
)
value
=
value
.
replace
(
'0x'
,
''
).
replace
(
/
(
..
)
/g
,
'%$1'
)
var
ret
=
{
var
ret
=
{
// length: decoded.length, // unneeded, only dynamicBytes uses length
length
:
decoded
.
length
,
raw
:
decoded
.
value
,
raw
:
decoded
.
value
,
type
:
'string'
type
:
'string'
}
}
...
...
src/storage/mappingPreimages.js
0 → 100644
View file @
aef34c6d
var
global
=
require
(
'../helpers/global'
)
module
.
exports
=
{
extractMappingPreimages
:
extractMappingPreimages
}
async
function
extractMappingPreimages
(
storageViewer
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
storageViewer
.
storageRange
(
function
(
error
,
storage
)
{
if
(
!
error
)
{
decodeMappingsKeys
(
storage
,
(
error
,
mappings
)
=>
{
if
(
error
)
{
reject
(
error
)
}
else
{
resolve
(
mappings
)
}
})
}
else
{
reject
(
error
)
}
})
})
}
async
function
decodeMappingsKeys
(
storage
,
callback
)
{
var
ret
=
{}
for
(
var
hashedLoc
in
storage
)
{
var
preimage
try
{
preimage
=
await
getPreimage
(
storage
[
hashedLoc
].
key
)
}
catch
(
e
)
{
}
if
(
preimage
)
{
// got preimage!
// get mapping position (i.e. storage slot), its the last 32 bytes
var
slotByteOffset
=
preimage
.
length
-
64
var
mappingSlot
=
preimage
.
substr
(
slotByteOffset
)
var
mappingKey
=
preimage
.
substr
(
0
,
slotByteOffset
)
if
(
!
ret
[
mappingSlot
])
{
ret
[
mappingSlot
]
=
{}
}
ret
[
mappingSlot
][
mappingKey
]
=
preimage
}
}
callback
(
null
,
ret
)
}
function
getPreimage
(
key
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
global
.
web3
.
debug
.
preimage
(
key
,
function
(
error
,
preimage
)
{
if
(
error
)
{
reject
(
error
)
}
else
{
resolve
(
preimage
)
}
})
})
}
src/storage/storageViewer.js
View file @
aef34c6d
'use strict'
'use strict'
var
helper
=
require
(
'../helpers/util'
)
var
helper
=
require
(
'../helpers/util'
)
var
mappingPreimagesExtractor
=
require
(
'./mappingPreimages'
)
class
StorageViewer
{
class
StorageViewer
{
constructor
(
_context
,
_storageResolver
,
_traceManager
)
{
constructor
(
_context
,
_storageResolver
,
_traceManager
)
{
this
.
context
=
_context
this
.
context
=
_context
this
.
storageResolver
=
_storageResolver
this
.
storageResolver
=
_storageResolver
// contains [mappingSlot][mappingkey] = preimage
// this map is renewed for each execution step
// this map is shared among all the mapping types
this
.
mappingsPreimages
=
null
_traceManager
.
accumulateStorageChanges
(
this
.
context
.
stepIndex
,
this
.
context
.
address
,
{},
(
error
,
storageChanges
)
=>
{
_traceManager
.
accumulateStorageChanges
(
this
.
context
.
stepIndex
,
this
.
context
.
address
,
{},
(
error
,
storageChanges
)
=>
{
if
(
!
error
)
{
if
(
!
error
)
{
this
.
storageChanges
=
storageChanges
this
.
storageChanges
=
storageChanges
...
@@ -58,6 +63,13 @@ class StorageViewer {
...
@@ -58,6 +63,13 @@ class StorageViewer {
isComplete
(
address
)
{
isComplete
(
address
)
{
return
this
.
storageResolver
.
isComplete
(
address
)
return
this
.
storageResolver
.
isComplete
(
address
)
}
}
async
mappingPreimages
()
{
if
(
!
this
.
mappingsPreimages
)
{
this
.
mappingsPreimages
=
await
mappingPreimagesExtractor
.
extractMappingPreimages
(
this
)
}
return
this
.
mappingsPreimages
}
}
}
module
.
exports
=
StorageViewer
module
.
exports
=
StorageViewer
src/trace/traceAnalyser.js
View file @
aef34c6d
'use strict'
'use strict'
var
traceHelper
=
require
(
'../helpers/traceHelper'
)
var
traceHelper
=
require
(
'../helpers/traceHelper'
)
var
ethutil
=
require
(
'ethereumjs-util'
)
function
TraceAnalyser
(
_cache
)
{
function
TraceAnalyser
(
_cache
)
{
this
.
traceCache
=
_cache
this
.
traceCache
=
_cache
...
@@ -72,18 +71,6 @@ TraceAnalyser.prototype.buildMemory = function (index, step) {
...
@@ -72,18 +71,6 @@ TraceAnalyser.prototype.buildMemory = function (index, step) {
}
}
}
}
function
getSha3Input
(
stack
,
memory
)
{
var
memoryStart
=
stack
[
stack
.
length
-
1
]
var
memoryLength
=
stack
[
stack
.
length
-
2
]
var
memStartDec
=
(
new
ethutil
.
BN
(
memoryStart
.
replace
(
'0x'
,
''
),
16
)).
toString
(
10
)
memoryStart
=
parseInt
(
memStartDec
)
*
2
var
memLengthDec
=
(
new
ethutil
.
BN
(
memoryLength
.
replace
(
'0x'
,
''
),
16
).
toString
(
10
))
memoryLength
=
parseInt
(
memLengthDec
)
*
2
var
memoryHex
=
memory
.
join
(
''
)
var
sha3Input
=
memoryHex
.
substr
(
memoryStart
,
memoryLength
)
return
sha3Input
}
TraceAnalyser
.
prototype
.
buildStorage
=
function
(
index
,
step
,
context
)
{
TraceAnalyser
.
prototype
.
buildStorage
=
function
(
index
,
step
,
context
)
{
if
(
traceHelper
.
newContextStorage
(
step
)
&&
!
traceHelper
.
isCallToPrecompiledContract
(
index
,
this
.
trace
))
{
if
(
traceHelper
.
newContextStorage
(
step
)
&&
!
traceHelper
.
isCallToPrecompiledContract
(
index
,
this
.
trace
))
{
var
calledAddress
=
traceHelper
.
resolveCalledAddress
(
index
,
this
.
trace
)
var
calledAddress
=
traceHelper
.
resolveCalledAddress
(
index
,
this
.
trace
)
...
@@ -93,9 +80,6 @@ TraceAnalyser.prototype.buildStorage = function (index, step, context) {
...
@@ -93,9 +80,6 @@ TraceAnalyser.prototype.buildStorage = function (index, step, context) {
console
.
log
(
'unable to build storage changes. '
+
index
+
' does not match with a CALL. storage changes will be corrupted'
)
console
.
log
(
'unable to build storage changes. '
+
index
+
' does not match with a CALL. storage changes will be corrupted'
)
}
}
this
.
traceCache
.
pushStoreChanges
(
index
+
1
,
context
.
storageContext
[
context
.
storageContext
.
length
-
1
])
this
.
traceCache
.
pushStoreChanges
(
index
+
1
,
context
.
storageContext
[
context
.
storageContext
.
length
-
1
])
}
else
if
(
traceHelper
.
isSHA3Instruction
(
step
))
{
var
sha3Input
=
getSha3Input
(
step
.
stack
,
step
.
memory
)
this
.
traceCache
.
pushSha3Preimage
(
sha3Input
,
context
.
storageContext
[
context
.
storageContext
.
length
-
1
])
}
else
if
(
traceHelper
.
isSSTOREInstruction
(
step
))
{
}
else
if
(
traceHelper
.
isSSTOREInstruction
(
step
))
{
this
.
traceCache
.
pushStoreChanges
(
index
+
1
,
context
.
storageContext
[
context
.
storageContext
.
length
-
1
],
step
.
stack
[
step
.
stack
.
length
-
1
],
step
.
stack
[
step
.
stack
.
length
-
2
])
this
.
traceCache
.
pushStoreChanges
(
index
+
1
,
context
.
storageContext
[
context
.
storageContext
.
length
-
1
],
step
.
stack
[
step
.
stack
.
length
-
1
],
step
.
stack
[
step
.
stack
.
length
-
2
])
}
else
if
(
traceHelper
.
isReturnInstruction
(
step
))
{
}
else
if
(
traceHelper
.
isReturnInstruction
(
step
))
{
...
...
src/trace/traceCache.js
View file @
aef34c6d
'use strict'
'use strict'
var
helper
=
require
(
'../helpers/util'
)
var
helper
=
require
(
'../helpers/util'
)
var
ethutil
=
require
(
'ethereumjs-util'
)
function
TraceCache
()
{
function
TraceCache
()
{
this
.
init
()
this
.
init
()
...
@@ -21,9 +20,6 @@ TraceCache.prototype.init = function () {
...
@@ -21,9 +20,6 @@ TraceCache.prototype.init = function () {
this
.
memoryChanges
=
[]
this
.
memoryChanges
=
[]
this
.
storageChanges
=
[]
this
.
storageChanges
=
[]
this
.
sstore
=
{}
// all sstore occurence in the trace
this
.
sstore
=
{}
// all sstore occurence in the trace
if
(
!
this
.
sha3Preimages
)
{
// need to accumulate the preimages over multiple tx's, so dont clear
this
.
sha3Preimages
=
{}
}
}
}
TraceCache
.
prototype
.
pushSteps
=
function
(
index
,
currentCallIndex
)
{
TraceCache
.
prototype
.
pushSteps
=
function
(
index
,
currentCallIndex
)
{
...
@@ -96,16 +92,6 @@ TraceCache.prototype.pushStoreChanges = function (index, address, key, value) {
...
@@ -96,16 +92,6 @@ TraceCache.prototype.pushStoreChanges = function (index, address, key, value) {
this
.
storageChanges
.
push
(
index
)
this
.
storageChanges
.
push
(
index
)
}
}
TraceCache
.
prototype
.
pushSha3Preimage
=
function
(
sha3Input
,
address
)
{
console
.
log
(
'pushSha3Preimage sha3Input:'
,
sha3Input
)
var
preimage
=
sha3Input
var
imageHash
=
ethutil
.
sha3
(
'0x'
+
sha3Input
).
toString
(
'hex'
)
this
.
sha3Preimages
[
imageHash
]
=
{
'address'
:
address
,
'preimage'
:
preimage
}
}
TraceCache
.
prototype
.
accumulateStorageChanges
=
function
(
index
,
address
,
storage
)
{
TraceCache
.
prototype
.
accumulateStorageChanges
=
function
(
index
,
address
,
storage
)
{
var
ret
=
Object
.
assign
({},
storage
)
var
ret
=
Object
.
assign
({},
storage
)
for
(
var
k
in
this
.
storageChanges
)
{
for
(
var
k
in
this
.
storageChanges
)
{
...
...
src/ui/SolidityState.js
View file @
aef34c6d
...
@@ -3,8 +3,6 @@ var DropdownPanel = require('./DropdownPanel')
...
@@ -3,8 +3,6 @@ var DropdownPanel = require('./DropdownPanel')
var
stateDecoder
=
require
(
'../solidity/stateDecoder'
)
var
stateDecoder
=
require
(
'../solidity/stateDecoder'
)
var
solidityTypeFormatter
=
require
(
'./SolidityTypeFormatter'
)
var
solidityTypeFormatter
=
require
(
'./SolidityTypeFormatter'
)
var
StorageViewer
=
require
(
'../storage/storageViewer'
)
var
StorageViewer
=
require
(
'../storage/storageViewer'
)
var
util
=
require
(
'../solidity/types/util'
)
var
ethutil
=
require
(
'ethereumjs-util'
)
var
yo
=
require
(
'yo-yo'
)
var
yo
=
require
(
'yo-yo'
)
function
SolidityState
(
_parent
,
_traceManager
,
_codeManager
,
_solidityProxy
)
{
function
SolidityState
(
_parent
,
_traceManager
,
_codeManager
,
_solidityProxy
)
{
...
@@ -66,28 +64,9 @@ SolidityState.prototype.init = function () {
...
@@ -66,28 +64,9 @@ SolidityState.prototype.init = function () {
tx
:
self
.
parent
.
tx
,
tx
:
self
.
parent
.
tx
,
address
:
address
address
:
address
},
self
.
storageResolver
,
self
.
traceManager
)
},
self
.
storageResolver
,
self
.
traceManager
)
stateDecoder
.
decodeState
(
stateVars
,
storageViewer
).
then
((
result
)
=>
{
var
storageJSON
=
{}
if
(
!
result
.
error
)
{
storageViewer
.
storageRange
(
function
(
error
,
result
)
{
self
.
basicPanel
.
update
(
result
)
if
(
!
error
)
{
storageJSON
=
result
var
sha3Preimages
=
self
.
traceManager
.
traceCache
.
sha3Preimages
var
mappingPreimages
=
getMappingPreimages
(
stateVars
,
storageJSON
,
sha3Preimages
)
for
(
var
k
in
stateVars
)
{
var
stateVar
=
stateVars
[
k
]
if
(
stateVar
.
type
.
typeName
.
indexOf
(
'mapping'
)
===
0
)
{
var
mapSlot
=
util
.
toBN
(
stateVar
.
storagelocation
.
slot
).
toString
(
16
)
mapSlot
=
ethutil
.
setLengthLeft
(
'0x'
+
mapSlot
,
32
).
toString
(
'hex'
)
stateVar
.
type
.
setMappingElements
(
mappingPreimages
[
mapSlot
])
}
}
stateDecoder
.
decodeState
(
stateVars
,
storageViewer
).
then
((
result
)
=>
{
if
(
!
result
.
error
)
{
self
.
basicPanel
.
update
(
result
)
}
})
}
}
})
})
}
}
...
@@ -97,45 +76,4 @@ SolidityState.prototype.init = function () {
...
@@ -97,45 +76,4 @@ SolidityState.prototype.init = function () {
})
})
}
}
function
getMappingPreimages
(
stateVars
,
storage
,
preimages
)
{
// loop over stateVars and get the locations of all the mappings
// then on each mapping, pass its specific preimage keys
// first filter out all non-mapping storage slots
var
ignoreSlots
=
[]
for
(
var
k
in
stateVars
)
{
var
stateVar
=
stateVars
[
k
]
if
(
stateVar
.
type
.
typeName
.
indexOf
(
'mapping'
)
!==
0
)
{
ignoreSlots
.
push
(
stateVar
.
storagelocation
.
slot
.
toString
())
}
}
var
possibleMappings
=
[]
for
(
var
hashedLoc
in
storage
)
{
var
slotNum
=
util
.
toBN
(
storage
[
hashedLoc
].
key
).
toString
(
10
)
if
(
ignoreSlots
.
indexOf
(
slotNum
)
===
-
1
)
{
possibleMappings
.
push
(
storage
[
hashedLoc
].
key
)
}
}
var
storageMappings
=
{}
for
(
var
pk
in
possibleMappings
)
{
var
possMapKey
=
possibleMappings
[
pk
].
replace
(
'0x'
,
''
)
if
(
preimages
[
possMapKey
])
{
// got preimage!
var
preimage
=
preimages
[
possMapKey
].
preimage
// get mapping position (i.e. storage slot), its the last 32 bytes
var
slotByteOffset
=
preimage
.
length
-
64
var
mappingSlot
=
preimage
.
substr
(
slotByteOffset
)
var
mappingKey
=
preimage
.
substr
(
0
,
slotByteOffset
)
if
(
!
storageMappings
[
mappingSlot
])
{
storageMappings
[
mappingSlot
]
=
[]
}
storageMappings
[
mappingSlot
].
push
(
mappingKey
)
}
}
return
storageMappings
}
module
.
exports
=
SolidityState
module
.
exports
=
SolidityState
src/util/web3Admin.js
View file @
aef34c6d
...
@@ -6,6 +6,15 @@ module.exports = {
...
@@ -6,6 +6,15 @@ module.exports = {
}
}
// DEBUG
// DEBUG
var
methods
=
[]
var
methods
=
[]
if
(
!
(
web3
.
debug
&&
web3
.
debug
.
preimage
))
{
methods
.
push
(
new
web3
.
_extend
.
Method
({
name
:
'preimage'
,
call
:
'debug_preimage'
,
inputFormatter
:
[
null
],
params
:
1
}))
}
if
(
!
(
web3
.
debug
&&
web3
.
debug
.
traceTransaction
))
{
if
(
!
(
web3
.
debug
&&
web3
.
debug
.
traceTransaction
))
{
methods
.
push
(
new
web3
.
_extend
.
Method
({
methods
.
push
(
new
web3
.
_extend
.
Method
({
name
:
'traceTransaction'
,
name
:
'traceTransaction'
,
...
...
src/web3Provider/web3VmProvider.js
View file @
aef34c6d
var
util
=
require
(
'../helpers/util'
)
var
util
=
require
(
'../helpers/util'
)
var
uiutil
=
require
(
'../helpers/ui'
)
var
uiutil
=
require
(
'../helpers/ui'
)
var
traceHelper
=
require
(
'../helpers/traceHelper'
)
var
traceHelper
=
require
(
'../helpers/traceHelper'
)
var
ethutil
=
require
(
'ethereumjs-util'
)
var
Web3
=
require
(
'web3'
)
var
Web3
=
require
(
'web3'
)
function
web3VmProvider
()
{
function
web3VmProvider
()
{
...
@@ -22,9 +23,11 @@ function web3VmProvider () {
...
@@ -22,9 +23,11 @@ function web3VmProvider () {
this
.
eth
.
getBlockNumber
=
function
(
cb
)
{
return
self
.
getBlockNumber
(
cb
)
}
this
.
eth
.
getBlockNumber
=
function
(
cb
)
{
return
self
.
getBlockNumber
(
cb
)
}
this
.
debug
.
traceTransaction
=
function
(
hash
,
options
,
cb
)
{
return
self
.
traceTransaction
(
hash
,
options
,
cb
)
}
this
.
debug
.
traceTransaction
=
function
(
hash
,
options
,
cb
)
{
return
self
.
traceTransaction
(
hash
,
options
,
cb
)
}
this
.
debug
.
storageRangeAt
=
function
(
blockNumber
,
txIndex
,
address
,
start
,
end
,
maxLength
,
cb
)
{
return
self
.
storageRangeAt
(
blockNumber
,
txIndex
,
address
,
start
,
end
,
maxLength
,
cb
)
}
this
.
debug
.
storageRangeAt
=
function
(
blockNumber
,
txIndex
,
address
,
start
,
end
,
maxLength
,
cb
)
{
return
self
.
storageRangeAt
(
blockNumber
,
txIndex
,
address
,
start
,
end
,
maxLength
,
cb
)
}
this
.
debug
.
preimage
=
function
(
hashedKey
,
cb
)
{
return
self
.
preimage
(
hashedKey
,
cb
)
}
this
.
providers
=
{
'HttpProvider'
:
function
(
url
)
{}
}
this
.
providers
=
{
'HttpProvider'
:
function
(
url
)
{}
}
this
.
currentProvider
=
{
'host'
:
'vm provider'
}
this
.
currentProvider
=
{
'host'
:
'vm provider'
}
this
.
storageCache
=
{}
this
.
storageCache
=
{}
this
.
sha3Preimages
=
{}
}
}
web3VmProvider
.
prototype
.
setVM
=
function
(
vm
)
{
web3VmProvider
.
prototype
.
setVM
=
function
(
vm
)
{
...
@@ -128,6 +131,10 @@ web3VmProvider.prototype.pushTrace = function (self, data) {
...
@@ -128,6 +131,10 @@ web3VmProvider.prototype.pushTrace = function (self, data) {
}
}
}
}
}
}
if
(
traceHelper
.
isSHA3Instruction
(
step
))
{
var
sha3Input
=
getSha3Input
(
step
.
stack
,
step
.
memory
)
pushSha3Preimage
(
this
,
sha3Input
)
}
this
.
processingIndex
++
this
.
processingIndex
++
this
.
previousDepth
=
depth
this
.
previousDepth
=
depth
}
}
...
@@ -189,4 +196,29 @@ web3VmProvider.prototype.getTransactionFromBlock = function (blockNumber, txInde
...
@@ -189,4 +196,29 @@ web3VmProvider.prototype.getTransactionFromBlock = function (blockNumber, txInde
}
}
}
}
web3VmProvider
.
prototype
.
preimage
=
function
(
hashedKey
,
cb
)
{
hashedKey
=
hashedKey
.
replace
(
'0x'
,
''
)
cb
(
null
,
this
.
sha3Preimages
[
hashedKey
]
!==
undefined
?
this
.
sha3Preimages
[
hashedKey
].
preimage
:
null
)
}
function
pushSha3Preimage
(
self
,
sha3Input
)
{
var
preimage
=
sha3Input
var
imageHash
=
ethutil
.
sha3
(
'0x'
+
sha3Input
).
toString
(
'hex'
)
self
.
sha3Preimages
[
imageHash
]
=
{
'preimage'
:
preimage
}
}
function
getSha3Input
(
stack
,
memory
)
{
var
memoryStart
=
stack
[
stack
.
length
-
1
]
var
memoryLength
=
stack
[
stack
.
length
-
2
]
var
memStartDec
=
(
new
ethutil
.
BN
(
memoryStart
.
replace
(
'0x'
,
''
),
16
)).
toString
(
10
)
memoryStart
=
parseInt
(
memStartDec
)
*
2
var
memLengthDec
=
(
new
ethutil
.
BN
(
memoryLength
.
replace
(
'0x'
,
''
),
16
).
toString
(
10
))
memoryLength
=
parseInt
(
memLengthDec
)
*
2
var
memoryHex
=
memory
.
join
(
''
)
var
sha3Input
=
memoryHex
.
substr
(
memoryStart
,
memoryLength
)
return
sha3Input
}
module
.
exports
=
web3VmProvider
module
.
exports
=
web3VmProvider
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment