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
9fa49102
Unverified
Commit
9fa49102
authored
May 14, 2021
by
yann300
Committed by
GitHub
May 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decode calldata during debugging (#1179)
fix
https://github.com/ethereum/remix-project/issues/481
parent
4af124d3
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
66 additions
and
15 deletions
+66
-15
debugger.spec.ts
apps/remix-ide-e2e/src/tests/debugger.spec.ts
+2
-2
Ethdebugger.ts
libs/remix-debug/src/Ethdebugger.ts
+2
-1
solidityLocals.ts
libs/remix-debug/src/debugger/solidityLocals.ts
+10
-1
internalCallTree.ts
libs/remix-debug/src/solidity-decoder/internalCallTree.ts
+6
-4
localDecoder.ts
libs/remix-debug/src/solidity-decoder/localDecoder.ts
+2
-2
RefType.ts
libs/remix-debug/src/solidity-decoder/types/RefType.ts
+32
-1
StringType.ts
libs/remix-debug/src/solidity-decoder/types/StringType.ts
+2
-2
ValueType.ts
libs/remix-debug/src/solidity-decoder/types/ValueType.ts
+1
-1
helper.ts
libs/remix-debug/test/decoder/localsTests/helper.ts
+9
-1
No files found.
apps/remix-ide-e2e/src/tests/debugger.spec.ts
View file @
9fa49102
...
...
@@ -323,7 +323,7 @@ const localVariable_step266_ABIEncoder = { // eslint-disable-line
value
:
'0x0000000000000000000000000000000000000000000000000000000000000002'
},
userData
:
{
error
:
'<decoding failed - no decoder for calldata>
'
,
value
:
'0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000015b38da6a701c568545dcfcb03fcb875f56beddc4
'
,
type
:
'bytes'
}
}
...
...
@@ -360,7 +360,7 @@ const localVariable_step717_ABIEncoder = { // eslint-disable-line
value
:
'0x5b38da6a701c568545dcfcb03fcb875f56beddc45b38da6a701c568545dcfcb03fcb875f56beddc400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001'
},
userData
:
{
error
:
'<decoding failed - no decoder for calldata>
'
,
value
:
'0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000015b38da6a701c568545dcfcb03fcb875f56beddc4
'
,
type
:
'bytes'
}
}
...
...
libs/remix-debug/src/Ethdebugger.ts
View file @
9fa49102
...
...
@@ -104,9 +104,10 @@ export class Ethdebugger {
const
stack
=
this
.
traceManager
.
getStackAt
(
step
)
const
memory
=
this
.
traceManager
.
getMemoryAt
(
step
)
const
address
=
this
.
traceManager
.
getCurrentCalledAddressAt
(
step
)
const
calldata
=
this
.
traceManager
.
getCallDataAt
(
step
)
try
{
const
storageViewer
=
new
StorageViewer
({
stepIndex
:
step
,
tx
:
this
.
tx
,
address
:
address
},
this
.
storageResolver
,
this
.
traceManager
)
const
locals
=
await
localDecoder
.
solidityLocals
(
step
,
this
.
callTree
,
stack
,
memory
,
storageViewer
,
sourceLocation
,
null
)
const
locals
=
await
localDecoder
.
solidityLocals
(
step
,
this
.
callTree
,
stack
,
memory
,
storageViewer
,
calldata
,
sourceLocation
,
null
)
if
(
locals
[
'error'
])
{
return
callback
(
locals
[
'error'
])
}
...
...
libs/remix-debug/src/debugger/solidityLocals.ts
View file @
9fa49102
...
...
@@ -62,6 +62,14 @@ export class DebuggerSolidityLocals {
}
catch
(
error
)
{
next
(
error
)
}
},
function
getCallDataAt
(
stepIndex
,
next
)
{
try
{
const
calldata
=
self
.
traceManager
.
getCallDataAt
(
stepIndex
)
next
(
null
,
calldata
)
}
catch
(
error
)
{
next
(
error
)
}
}],
this
.
stepManager
.
currentStepIndex
,
(
error
,
result
)
=>
{
...
...
@@ -70,9 +78,10 @@ export class DebuggerSolidityLocals {
}
var
stack
=
result
[
0
].
value
var
memory
=
result
[
1
].
value
var
calldata
=
result
[
3
].
value
try
{
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
this
.
stepManager
.
currentStepIndex
,
tx
:
this
.
tx
,
address
:
result
[
2
].
value
},
this
.
storageResolver
,
this
.
traceManager
)
solidityLocals
(
this
.
stepManager
.
currentStepIndex
,
this
.
internalTreeCall
,
stack
,
memory
,
storageViewer
,
sourceLocation
,
cursor
).
then
((
locals
)
=>
{
solidityLocals
(
this
.
stepManager
.
currentStepIndex
,
this
.
internalTreeCall
,
stack
,
memory
,
storageViewer
,
calldata
,
sourceLocation
,
cursor
).
then
((
locals
)
=>
{
if
(
!
cursor
)
{
if
(
!
locals
[
'error'
])
{
this
.
event
.
trigger
(
'solidityLocals'
,
[
locals
])
...
...
libs/remix-debug/src/solidity-decoder/internalCallTree.ts
View file @
9fa49102
...
...
@@ -310,10 +310,10 @@ async function includeVariableDeclaration (tree, step, sourceLocation, scopeId,
// }
// input params
if
(
inputs
&&
inputs
.
parameters
)
{
functionDefinitionAndInputs
.
inputs
=
addParams
(
inputs
,
tree
,
scopeId
,
states
,
contractObj
.
name
,
previousSourceLocation
,
stack
.
length
,
inputs
.
parameters
.
length
,
-
1
)
functionDefinitionAndInputs
.
inputs
=
addParams
(
inputs
,
tree
,
scopeId
,
states
,
contractObj
,
previousSourceLocation
,
stack
.
length
,
inputs
.
parameters
.
length
,
-
1
)
}
// output params
if
(
outputs
)
addParams
(
outputs
,
tree
,
scopeId
,
states
,
contractObj
.
name
,
previousSourceLocation
,
stack
.
length
,
0
,
1
)
if
(
outputs
)
addParams
(
outputs
,
tree
,
scopeId
,
states
,
contractObj
,
previousSourceLocation
,
stack
.
length
,
0
,
1
)
}
}
catch
(
error
)
{
console
.
log
(
error
)
...
...
@@ -373,7 +373,8 @@ function extractFunctionDefinitions (ast, astWalker) {
return
ret
}
function
addParams
(
parameterList
,
tree
,
scopeId
,
states
,
contractName
,
sourceLocation
,
stackLength
,
stackPosition
,
dir
)
{
function
addParams
(
parameterList
,
tree
,
scopeId
,
states
,
contractObj
,
sourceLocation
,
stackLength
,
stackPosition
,
dir
)
{
const
contractName
=
contractObj
.
name
const
params
=
[]
for
(
const
inputParam
in
parameterList
.
parameters
)
{
const
param
=
parameterList
.
parameters
[
inputParam
]
...
...
@@ -386,7 +387,8 @@ function addParams (parameterList, tree, scopeId, states, contractName, sourceLo
name
:
attributesName
,
type
:
parseType
(
param
.
typeDescriptions
.
typeString
,
states
,
contractName
,
location
),
stackDepth
:
stackDepth
,
sourceLocation
:
sourceLocation
sourceLocation
:
sourceLocation
,
abi
:
contractObj
.
contract
.
abi
}
params
.
push
(
attributesName
)
}
...
...
libs/remix-debug/src/solidity-decoder/localDecoder.ts
View file @
9fa49102
'use strict'
export
async
function
solidityLocals
(
vmtraceIndex
,
internalTreeCall
,
stack
,
memory
,
storageResolver
,
currentSourceLocation
,
cursor
)
{
export
async
function
solidityLocals
(
vmtraceIndex
,
internalTreeCall
,
stack
,
memory
,
storageResolver
,
c
alldata
,
c
urrentSourceLocation
,
cursor
)
{
const
scope
=
internalTreeCall
.
findScope
(
vmtraceIndex
)
if
(
!
scope
)
{
const
error
=
{
message
:
'Can
\'
t display locals. reason: compilation result might not have been provided'
}
...
...
@@ -18,7 +18,7 @@ export async function solidityLocals (vmtraceIndex, internalTreeCall, stack, mem
anonymousIncr
++
}
try
{
locals
[
name
]
=
await
variable
.
type
.
decodeFromStack
(
variable
.
stackDepth
,
stack
,
memory
,
storageResolver
,
c
ursor
)
locals
[
name
]
=
await
variable
.
type
.
decodeFromStack
(
variable
.
stackDepth
,
stack
,
memory
,
storageResolver
,
c
alldata
,
cursor
,
variable
)
}
catch
(
e
)
{
console
.
log
(
e
)
locals
[
name
]
=
'<decoding failed - '
+
e
.
message
+
'>'
...
...
libs/remix-debug/src/solidity-decoder/types/RefType.ts
View file @
9fa49102
'use strict'
import
{
ethers
}
from
'ethers'
import
{
toBN
}
from
'./util'
export
class
RefType
{
...
...
@@ -7,6 +8,7 @@ export class RefType {
storageBytes
typeName
basicType
underlyingType
constructor
(
storageSlots
,
storageBytes
,
typeName
,
location
)
{
this
.
location
=
location
...
...
@@ -33,7 +35,7 @@ export class RefType {
* @param {Object} - storageResolver
* @return {Object} decoded value
*/
async
decodeFromStack
(
stackDepth
,
stack
,
memory
,
storageResolver
,
c
ursor
):
Promise
<
any
>
{
async
decodeFromStack
(
stackDepth
,
stack
,
memory
,
storageResolver
,
c
alldata
,
cursor
,
variableDetails
?
):
Promise
<
any
>
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
return
{
error
:
'<decoding failed - stack underflow '
+
stackDepth
+
'>'
,
type
:
this
.
typeName
}
}
...
...
@@ -49,6 +51,26 @@ export class RefType {
}
else
if
(
this
.
isInMemory
())
{
offset
=
parseInt
(
offset
,
16
)
return
this
.
decodeFromMemoryInternal
(
offset
,
memory
,
cursor
)
}
else
if
(
this
.
isInCallData
())
{
calldata
=
calldata
.
length
>
0
?
calldata
[
0
]
:
'0x'
const
ethersAbi
=
new
ethers
.
utils
.
Interface
(
variableDetails
.
abi
)
const
fnSign
=
calldata
.
substr
(
0
,
10
)
const
decodedData
=
ethersAbi
.
decodeFunctionData
(
ethersAbi
.
getFunction
(
fnSign
),
calldata
)
let
decodedValue
=
decodedData
[
variableDetails
.
name
]
const
isArray
=
Array
.
isArray
(
decodedValue
)
if
(
isArray
)
{
decodedValue
=
decodedValue
.
map
((
el
)
=>
{
return
{
value
:
el
.
toString
(),
type
:
this
.
underlyingType
.
typeName
}
})
}
return
{
length
:
Array
.
isArray
(
decodedValue
)
?
'0x'
+
decodedValue
.
length
.
toString
(
16
)
:
undefined
,
value
:
decodedValue
,
type
:
this
.
typeName
}
}
else
{
return
{
error
:
'<decoding failed - no decoder for '
+
this
.
location
+
'>'
,
type
:
this
.
typeName
}
}
...
...
@@ -84,4 +106,13 @@ export class RefType {
isInMemory
()
{
return
this
.
location
.
indexOf
(
'memory'
)
===
0
}
/**
* current type defined in storage
*
* @return {Bool} - return true if the type is defined in the storage
*/
isInCallData
()
{
return
this
.
location
.
indexOf
(
'calldata'
)
===
0
}
}
libs/remix-debug/src/solidity-decoder/types/StringType.ts
View file @
9fa49102
...
...
@@ -20,9 +20,9 @@ export class StringType extends DynamicByteArray {
return
format
(
decoded
)
}
async
decodeFromStack
(
stackDepth
,
stack
,
memory
)
{
async
decodeFromStack
(
stackDepth
,
stack
,
memory
,
calldata
,
variableDetails
?
)
{
try
{
return
await
super
.
decodeFromStack
(
stackDepth
,
stack
,
memory
,
null
,
null
)
return
await
super
.
decodeFromStack
(
stackDepth
,
stack
,
memory
,
null
,
calldata
,
variableDetails
)
}
catch
(
e
)
{
console
.
log
(
e
)
return
'<decoding failed - '
+
e
.
message
+
'>'
...
...
libs/remix-debug/src/solidity-decoder/types/ValueType.ts
View file @
9fa49102
...
...
@@ -43,7 +43,7 @@ export class ValueType {
* @param {String} - memory
* @return {Object} - decoded value
*/
async
decodeFromStack
(
stackDepth
,
stack
,
memory
)
{
async
decodeFromStack
(
stackDepth
,
stack
,
memory
,
calldata
,
variableDetails
?
)
{
let
value
if
(
stackDepth
>=
stack
.
length
)
{
value
=
this
.
decodeValue
(
''
)
...
...
libs/remix-debug/test/decoder/localsTests/helper.ts
View file @
9fa49102
...
...
@@ -22,13 +22,21 @@ export function decodeLocals (st, index, traceManager, callTree, verifier) {
}
catch
(
error
)
{
callback
(
error
)
}
},
function
getCallDataAt
(
stepIndex
,
callback
)
{
try
{
const
result
=
traceManager
.
getCallDataAt
(
stepIndex
)
callback
(
null
,
result
)
}
catch
(
error
)
{
callback
(
error
)
}
}],
index
,
function
(
error
,
result
)
{
if
(
error
)
{
return
st
.
fail
(
error
)
}
solidityLocals
(
index
,
callTree
,
result
[
0
].
value
,
result
[
1
].
value
,
{},
{
start
:
5000
},
null
).
then
((
locals
)
=>
{
solidityLocals
(
index
,
callTree
,
result
[
0
].
value
,
result
[
1
].
value
,
{},
result
[
2
].
value
,
{
start
:
5000
},
null
).
then
((
locals
)
=>
{
verifier
(
locals
)
})
})
...
...
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