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
d2161740
Commit
d2161740
authored
Dec 14, 2020
by
aniket-engg
Committed by
Aniket
Dec 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trace analyser, cache and helper updated
parent
1187d4ad
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
45 deletions
+63
-45
traceAnalyser.ts
libs/remix-debug/src/trace/traceAnalyser.ts
+21
-16
traceCache.ts
libs/remix-debug/src/trace/traceCache.ts
+41
-28
traceHelper.ts
libs/remix-debug/src/trace/traceHelper.ts
+1
-1
No files found.
libs/remix-debug/src/trace/traceAnalyser.ts
View file @
d2161740
'use strict'
const
traceHelper
=
require
(
'./traceHelper'
)
function
TraceAnalyser
(
_cache
)
{
export
class
TraceAnalyser
{
traceCache
trace
constructor
(
_cache
)
{
this
.
traceCache
=
_cache
this
.
trace
=
null
}
}
TraceAnalyser
.
prototype
.
analyse
=
function
(
trace
,
tx
)
{
analyse
(
trace
,
tx
)
{
this
.
trace
=
trace
this
.
traceCache
.
pushStoreChanges
(
0
,
tx
.
to
)
let
context
=
{
...
...
@@ -28,9 +33,9 @@ TraceAnalyser.prototype.analyse = function (trace, tx) {
this
.
buildReturnValues
(
k
,
step
)
}
return
true
}
}
TraceAnalyser
.
prototype
.
buildReturnValues
=
function
(
index
,
step
)
{
buildReturnValues
(
index
,
step
)
{
if
(
traceHelper
.
isReturnInstruction
(
step
))
{
let
offset
=
2
*
parseInt
(
step
.
stack
[
step
.
stack
.
length
-
1
],
16
)
const
size
=
2
*
parseInt
(
step
.
stack
[
step
.
stack
.
length
-
2
],
16
)
...
...
@@ -45,9 +50,9 @@ TraceAnalyser.prototype.buildReturnValues = function (index, step) {
this
.
traceCache
.
pushReturnValue
(
index
,
returnParamsObj
)
}
}
}
TraceAnalyser
.
prototype
.
buildCalldata
=
function
(
index
,
step
,
tx
,
newContext
)
{
buildCalldata
(
index
,
step
,
tx
,
newContext
)
{
let
calldata
=
''
if
(
index
===
0
)
{
calldata
=
tx
.
input
...
...
@@ -59,8 +64,8 @@ TraceAnalyser.prototype.buildCalldata = function (index, step, tx, newContext) {
const
memory
=
this
.
trace
[
this
.
traceCache
.
memoryChanges
[
this
.
traceCache
.
memoryChanges
.
length
-
1
]].
memory
const
callStep
=
this
.
trace
[
index
]
const
stack
=
callStep
.
stack
let
offset
=
''
let
size
=
''
let
offset
=
0
let
size
=
0
if
(
callStep
.
op
===
'DELEGATECALL'
)
{
offset
=
2
*
parseInt
(
stack
[
stack
.
length
-
3
],
16
)
size
=
2
*
parseInt
(
stack
[
stack
.
length
-
4
],
16
)
...
...
@@ -71,15 +76,15 @@ TraceAnalyser.prototype.buildCalldata = function (index, step, tx, newContext) {
calldata
=
'0x'
+
memory
.
join
(
''
).
substr
(
offset
,
size
)
this
.
traceCache
.
pushCallDataChanges
(
index
+
1
,
calldata
)
}
}
}
TraceAnalyser
.
prototype
.
buildMemory
=
function
(
index
,
step
)
{
buildMemory
(
index
,
step
)
{
if
(
step
.
memory
)
{
this
.
traceCache
.
pushMemoryChanges
(
index
)
}
}
}
TraceAnalyser
.
prototype
.
buildStorage
=
function
(
index
,
step
,
context
)
{
buildStorage
(
index
,
step
,
context
)
{
if
(
traceHelper
.
newContextStorage
(
step
)
&&
!
traceHelper
.
isCallToPrecompiledContract
(
index
,
this
.
trace
))
{
const
calledAddress
=
traceHelper
.
resolveCalledAddress
(
index
,
this
.
trace
)
if
(
calledAddress
)
{
...
...
@@ -98,9 +103,9 @@ TraceAnalyser.prototype.buildStorage = function (index, step, context) {
this
.
traceCache
.
resetStoreChanges
()
}
return
context
}
}
TraceAnalyser
.
prototype
.
buildDepth
=
function
(
index
,
step
,
tx
,
callStack
,
context
)
{
buildDepth
(
index
,
step
,
tx
,
callStack
,
context
)
{
if
(
traceHelper
.
isCallInstruction
(
step
)
&&
!
traceHelper
.
isCallToPrecompiledContract
(
index
,
this
.
trace
))
{
let
newAddress
if
(
traceHelper
.
isCreateInstruction
(
step
))
{
...
...
@@ -134,6 +139,6 @@ TraceAnalyser.prototype.buildDepth = function (index, step, tx, callStack, conte
context
.
currentCallIndex
++
}
return
context
}
}
module
.
exports
=
TraceAnalyser
libs/remix-debug/src/trace/traceCache.ts
View file @
d2161740
...
...
@@ -2,11 +2,26 @@
const
remixLib
=
require
(
'@remix-project/remix-lib'
)
const
helper
=
remixLib
.
util
function
TraceCache
()
{
export
class
TraceCache
{
returnValues
currentCall
callsTree
callsData
contractCreation
steps
addresses
callDataChanges
memoryChanges
storageChanges
sstore
constructor
()
{
this
.
init
()
}
}
TraceCache
.
prototype
.
init
=
function
()
{
init
()
{
// ...Changes contains index in the vmtrace of the corresponding changes
this
.
returnValues
=
{}
...
...
@@ -16,29 +31,28 @@ TraceCache.prototype.init = function () {
this
.
contractCreation
=
{}
this
.
steps
=
{}
this
.
addresses
=
[]
this
.
callDataChanges
=
[]
this
.
memoryChanges
=
[]
this
.
storageChanges
=
[]
this
.
sstore
=
{}
// all sstore occurence in the trace
}
}
TraceCache
.
prototype
.
pushSteps
=
function
(
index
,
currentCallIndex
)
{
pushSteps
(
index
,
currentCallIndex
)
{
this
.
steps
[
index
]
=
currentCallIndex
}
}
TraceCache
.
prototype
.
pushCallDataChanges
=
function
(
value
,
calldata
)
{
pushCallDataChanges
(
value
,
calldata
)
{
this
.
callDataChanges
.
push
(
value
)
this
.
callsData
[
value
]
=
calldata
}
}
TraceCache
.
prototype
.
pushMemoryChanges
=
function
(
value
)
{
pushMemoryChanges
(
value
)
{
this
.
memoryChanges
.
push
(
value
)
}
}
// outOfGas has been removed because gas left logging is apparently made differently
// in the vm/geth/eth. TODO add the error property (with about the error in all clients)
TraceCache
.
prototype
.
pushCall
=
function
(
step
,
index
,
address
,
callStack
,
reverted
)
{
// outOfGas has been removed because gas left logging is apparently made differently
// in the vm/geth/eth. TODO add the error property (with about the error in all clients)
pushCall
(
step
,
index
,
address
,
callStack
,
reverted
)
{
let
validReturnStep
=
step
.
op
===
'RETURN'
||
step
.
op
===
'STOP'
if
((
validReturnStep
||
reverted
)
&&
(
this
.
currentCall
))
{
this
.
currentCall
.
call
.
return
=
index
-
1
...
...
@@ -63,30 +77,30 @@ TraceCache.prototype.pushCall = function (step, index, address, callStack, rever
this
.
callsTree
=
{
call
:
call
}
}
this
.
currentCall
=
{
call
:
call
,
parent
:
this
.
currentCall
}
}
}
TraceCache
.
prototype
.
pushReturnValue
=
function
(
step
,
value
)
{
pushReturnValue
(
step
,
value
)
{
this
.
returnValues
[
step
]
=
value
}
}
TraceCache
.
prototype
.
pushContractCreationFromMemory
=
function
(
index
,
token
,
trace
,
lastMemoryChange
)
{
pushContractCreationFromMemory
(
index
,
token
,
trace
,
lastMemoryChange
)
{
const
memory
=
trace
[
lastMemoryChange
].
memory
const
stack
=
trace
[
index
].
stack
const
offset
=
2
*
parseInt
(
stack
[
stack
.
length
-
2
],
16
)
const
size
=
2
*
parseInt
(
stack
[
stack
.
length
-
3
],
16
)
this
.
contractCreation
[
token
]
=
'0x'
+
memory
.
join
(
''
).
substr
(
offset
,
size
)
}
}
TraceCache
.
prototype
.
pushContractCreation
=
func
tion
(
token
,
code
)
{
pushContractCrea
tion
(
token
,
code
)
{
this
.
contractCreation
[
token
]
=
code
}
}
TraceCache
.
prototype
.
resetStoreChanges
=
function
(
index
,
address
,
key
,
value
)
{
resetStoreChanges
(
index
,
address
,
key
,
value
)
{
this
.
sstore
=
{}
this
.
storageChanges
=
[]
}
}
TraceCache
.
prototype
.
pushStoreChanges
=
function
(
index
,
address
,
key
,
value
)
{
pushStoreChanges
(
index
,
address
,
key
,
value
)
{
this
.
sstore
[
index
]
=
{
'address'
:
address
,
'key'
:
key
,
...
...
@@ -94,9 +108,9 @@ TraceCache.prototype.pushStoreChanges = function (index, address, key, value) {
'hashedKey'
:
helper
.
sha3_256
(
key
)
}
this
.
storageChanges
.
push
(
index
)
}
}
TraceCache
.
prototype
.
accumulateStorageChanges
=
function
(
index
,
address
,
storage
)
{
accumulateStorageChanges
(
index
,
address
,
storage
)
{
const
ret
=
Object
.
assign
({},
storage
)
for
(
var
k
in
this
.
storageChanges
)
{
const
changesIndex
=
this
.
storageChanges
[
k
]
...
...
@@ -112,6 +126,5 @@ TraceCache.prototype.accumulateStorageChanges = function (index, address, storag
}
}
return
ret
}
}
module
.
exports
=
TraceCache
libs/remix-debug/src/trace/traceHelper.ts
View file @
d2161740
...
...
@@ -2,7 +2,7 @@
const
remixLib
=
require
(
'@remix-project/remix-lib'
)
const
ui
=
remixLib
.
helpers
.
ui
module
.
exports
=
{
export
=
{
// vmTraceIndex has to point to a CALL, CODECALL, ...
resolveCalledAddress
:
function
(
vmTraceIndex
,
trace
)
{
const
step
=
trace
[
vmTraceIndex
]
...
...
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