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
5ee7ba8b
Commit
5ee7ba8b
authored
Jun 24, 2016
by
yann300
Committed by
GitHub
Jun 24, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #37 from yann300/calldata
get calldata from memory
parents
4f364352
8a4fd68f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
14 deletions
+40
-14
TxBrowser.js
src/TxBrowser.js
+1
-1
traceAnalyser.js
src/trace/traceAnalyser.js
+35
-11
traceCache.js
src/trace/traceCache.js
+3
-1
traceManager.js
src/trace/traceManager.js
+1
-1
No files found.
src/TxBrowser.js
View file @
5ee7ba8b
...
...
@@ -10,7 +10,7 @@ function TxBrowser (_web3) {
this
.
web3
=
_web3
this
.
blockNumber
this
.
txNumber
=
'0x
20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51
'
this
.
txNumber
=
'0x
71a6d583d16d142c5c3e8903060e8a4ee5a5016348a9448df6c3e63b68076ec4
'
this
.
hash
this
.
from
this
.
to
...
...
src/trace/traceAnalyser.js
View file @
5ee7ba8b
...
...
@@ -21,20 +21,40 @@ TraceAnalyser.prototype.analyse = function (trace, tx, callback) {
if
(
traceHelper
.
isContractCreation
(
tx
.
to
))
{
this
.
traceCache
.
pushContractCreation
(
tx
.
to
,
tx
.
input
)
}
this
.
buildCalldata
(
0
,
this
.
trace
[
0
],
tx
,
true
)
for
(
var
k
=
0
;
k
<
this
.
trace
.
length
;
k
++
)
{
var
step
=
this
.
trace
[
k
]
this
.
buildCalldata
(
k
,
step
)
this
.
buildMemory
(
k
,
step
)
this
.
buildDepth
(
k
,
step
,
callStack
)
this
.
buildDepth
(
k
,
step
,
tx
,
callStack
)
context
=
this
.
buildStorage
(
k
,
step
,
context
)
}
callback
(
null
,
true
)
}
TraceAnalyser
.
prototype
.
buildCalldata
=
function
(
index
,
step
)
{
if
(
step
.
calldata
)
{
this
.
traceCache
.
pushCallDataChanges
(
index
)
TraceAnalyser
.
prototype
.
buildCalldata
=
function
(
index
,
step
,
tx
,
newContext
)
{
var
calldata
=
''
if
(
index
===
0
)
{
calldata
=
tx
.
input
this
.
traceCache
.
pushCallDataChanges
(
index
,
calldata
)
}
else
if
(
!
newContext
)
{
var
lastCall
=
this
.
traceCache
.
callsData
[
this
.
traceCache
.
callDataChanges
[
this
.
traceCache
.
callDataChanges
.
length
-
2
]]
this
.
traceCache
.
pushCallDataChanges
(
index
+
1
,
lastCall
)
}
else
{
var
memory
=
this
.
trace
[
this
.
traceCache
.
memoryChanges
[
this
.
traceCache
.
memoryChanges
.
length
-
1
]].
memory
var
callStep
=
this
.
trace
[
index
]
var
stack
=
callStep
.
stack
var
offset
=
''
var
size
=
''
if
(
callStep
.
op
===
'DELEGATECALL'
)
{
offset
=
2
*
parseInt
(
stack
[
stack
.
length
-
3
],
16
)
size
=
2
*
parseInt
(
stack
[
stack
.
length
-
4
],
16
)
}
else
{
offset
=
2
*
parseInt
(
stack
[
stack
.
length
-
4
],
16
)
size
=
2
*
parseInt
(
stack
[
stack
.
length
-
5
],
16
)
}
calldata
=
'0x'
+
memory
.
join
(
''
).
substr
(
offset
,
size
)
this
.
traceCache
.
pushCallDataChanges
(
index
+
1
,
calldata
)
}
}
...
...
@@ -62,7 +82,7 @@ TraceAnalyser.prototype.buildStorage = function (index, step, context) {
return
context
}
TraceAnalyser
.
prototype
.
buildDepth
=
function
(
index
,
step
,
callStack
)
{
TraceAnalyser
.
prototype
.
buildDepth
=
function
(
index
,
step
,
tx
,
callStack
)
{
if
(
traceHelper
.
isCallInstruction
(
step
)
&&
!
traceHelper
.
isCallToPrecompiledContract
(
index
,
this
.
trace
))
{
if
(
traceHelper
.
isCreateInstruction
(
step
))
{
var
contractToken
=
traceHelper
.
contractCreationToken
(
index
)
...
...
@@ -81,12 +101,16 @@ TraceAnalyser.prototype.buildDepth = function (index, step, callStack) {
this
.
traceCache
.
pushCallStack
(
index
+
1
,
{
callStack
:
callStack
.
slice
(
0
)
})
this
.
buildCalldata
(
index
,
step
,
tx
,
true
)
}
else
if
(
traceHelper
.
isReturnInstruction
(
step
))
{
callStack
.
pop
()
this
.
traceCache
.
pushCallChanges
(
step
,
index
+
1
)
this
.
traceCache
.
pushCallStack
(
index
+
1
,
{
callStack
:
callStack
.
slice
(
0
)
})
if
(
index
+
1
<
this
.
trace
.
length
)
{
callStack
.
pop
()
this
.
traceCache
.
pushCallChanges
(
step
,
index
+
1
)
this
.
traceCache
.
pushCallStack
(
index
+
1
,
{
callStack
:
callStack
.
slice
(
0
)
})
this
.
buildCalldata
(
index
,
step
,
tx
,
false
)
}
}
}
...
...
src/trace/traceCache.js
View file @
5ee7ba8b
...
...
@@ -9,6 +9,7 @@ TraceCache.prototype.init = function () {
this
.
callChanges
=
[]
this
.
returnChanges
=
[]
this
.
calls
=
{}
this
.
callsData
=
{}
this
.
contractCreation
=
{}
this
.
callDataChanges
=
[]
...
...
@@ -18,8 +19,9 @@ TraceCache.prototype.init = function () {
this
.
callStack
=
{}
// contains all callStack by vmtrace index (we need to rebuild it, callstack is not included in the vmtrace)
}
TraceCache
.
prototype
.
pushCallDataChanges
=
function
(
value
)
{
TraceCache
.
prototype
.
pushCallDataChanges
=
function
(
value
,
calldata
)
{
this
.
callDataChanges
.
push
(
value
)
this
.
callsData
[
value
]
=
calldata
}
TraceCache
.
prototype
.
pushMemoryChanges
=
function
(
value
)
{
...
...
src/trace/traceManager.js
View file @
5ee7ba8b
...
...
@@ -101,7 +101,7 @@ TraceManager.prototype.getCallDataAt = function (stepIndex, callback) {
}
var
callDataChange
=
traceHelper
.
findLowerBound
(
stepIndex
,
this
.
traceCache
.
callDataChanges
)
if
(
callDataChange
===
undefined
)
return
callback
(
'no calldata found'
,
null
)
callback
(
null
,
[
this
.
trace
[
callDataChange
].
calldata
])
callback
(
null
,
[
this
.
trace
Cache
.
callsData
[
callDataChange
]
])
}
TraceManager
.
prototype
.
getCallStackAt
=
function
(
stepIndex
,
callback
)
{
...
...
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