Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
9a44e103
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9a44e103
编写于
6月 21, 2017
作者:
M
Martin Holst Swende
提交者:
Felix Lange
6月 21, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cmd/evm, core/vm: add --nomemory, --nostack to evm (#14617)
上级
9012863a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
68 addition
and
47 deletion
+68
-47
cmd/evm/json_logger.go
cmd/evm/json_logger.go
+20
-13
cmd/evm/main.go
cmd/evm/main.go
+10
-0
cmd/evm/runner.go
cmd/evm/runner.go
+7
-3
core/vm/gen_structlog.go
core/vm/gen_structlog.go
+15
-11
core/vm/logger.go
core/vm/logger.go
+16
-20
未找到文件。
cmd/evm/json_logger.go
浏览文件 @
9a44e103
...
...
@@ -28,25 +28,32 @@ import (
type
JSONLogger
struct
{
encoder
*
json
.
Encoder
cfg
*
vm
.
LogConfig
}
func
NewJSONLogger
(
writer
io
.
Writer
)
*
JSONLogger
{
return
&
JSONLogger
{
json
.
NewEncoder
(
writer
)}
func
NewJSONLogger
(
cfg
*
vm
.
LogConfig
,
writer
io
.
Writer
)
*
JSONLogger
{
return
&
JSONLogger
{
json
.
NewEncoder
(
writer
)
,
cfg
}
}
// CaptureState outputs state information on the logger.
func
(
l
*
JSONLogger
)
CaptureState
(
env
*
vm
.
EVM
,
pc
uint64
,
op
vm
.
OpCode
,
gas
,
cost
uint64
,
memory
*
vm
.
Memory
,
stack
*
vm
.
Stack
,
contract
*
vm
.
Contract
,
depth
int
,
err
error
)
error
{
return
l
.
encoder
.
Encode
(
vm
.
StructLog
{
Pc
:
pc
,
Op
:
op
,
Gas
:
gas
+
cost
,
GasCost
:
cost
,
Memory
:
memory
.
Data
(),
Stack
:
stack
.
Data
(),
Storage
:
nil
,
Depth
:
depth
,
Err
:
err
,
})
log
:=
vm
.
StructLog
{
Pc
:
pc
,
Op
:
op
,
Gas
:
gas
+
cost
,
GasCost
:
cost
,
MemorySize
:
memory
.
Len
(),
Storage
:
nil
,
Depth
:
depth
,
Err
:
err
,
}
if
!
l
.
cfg
.
DisableMemory
{
log
.
Memory
=
memory
.
Data
()
}
if
!
l
.
cfg
.
DisableStack
{
log
.
Stack
=
stack
.
Data
()
}
return
l
.
encoder
.
Encode
(
log
)
}
// CaptureEnd is triggered at end of execution.
...
...
cmd/evm/main.go
浏览文件 @
9a44e103
...
...
@@ -102,6 +102,14 @@ var (
Name
:
"sender"
,
Usage
:
"The transaction origin"
,
}
DisableMemoryFlag
=
cli
.
BoolFlag
{
Name
:
"nomemory"
,
Usage
:
"disable memory output"
,
}
DisableStackFlag
=
cli
.
BoolFlag
{
Name
:
"nostack"
,
Usage
:
"disable stack output"
,
}
)
func
init
()
{
...
...
@@ -123,6 +131,8 @@ func init() {
GenesisFlag
,
MachineFlag
,
SenderFlag
,
DisableMemoryFlag
,
DisableStackFlag
,
}
app
.
Commands
=
[]
cli
.
Command
{
compileCommand
,
...
...
cmd/evm/runner.go
浏览文件 @
9a44e103
...
...
@@ -73,6 +73,10 @@ func runCmd(ctx *cli.Context) error {
glogger
:=
log
.
NewGlogHandler
(
log
.
StreamHandler
(
os
.
Stderr
,
log
.
TerminalFormat
(
false
)))
glogger
.
Verbosity
(
log
.
Lvl
(
ctx
.
GlobalInt
(
VerbosityFlag
.
Name
)))
log
.
Root
()
.
SetHandler
(
glogger
)
logconfig
:=
&
vm
.
LogConfig
{
DisableMemory
:
ctx
.
GlobalBool
(
DisableMemoryFlag
.
Name
),
DisableStack
:
ctx
.
GlobalBool
(
DisableStackFlag
.
Name
),
}
var
(
tracer
vm
.
Tracer
...
...
@@ -82,12 +86,12 @@ func runCmd(ctx *cli.Context) error {
sender
=
common
.
StringToAddress
(
"sender"
)
)
if
ctx
.
GlobalBool
(
MachineFlag
.
Name
)
{
tracer
=
NewJSONLogger
(
os
.
Stdout
)
tracer
=
NewJSONLogger
(
logconfig
,
os
.
Stdout
)
}
else
if
ctx
.
GlobalBool
(
DebugFlag
.
Name
)
{
debugLogger
=
vm
.
NewStructLogger
(
nil
)
debugLogger
=
vm
.
NewStructLogger
(
logconfig
)
tracer
=
debugLogger
}
else
{
debugLogger
=
vm
.
NewStructLogger
(
nil
)
debugLogger
=
vm
.
NewStructLogger
(
logconfig
)
}
if
ctx
.
GlobalString
(
GenesisFlag
.
Name
)
!=
""
{
gen
:=
readGenesis
(
ctx
.
GlobalString
(
GenesisFlag
.
Name
))
...
...
core/vm/gen_structlog.go
浏览文件 @
9a44e103
...
...
@@ -18,12 +18,12 @@ func (s StructLog) MarshalJSON() ([]byte, error) {
Gas
math
.
HexOrDecimal64
`json:"gas"`
GasCost
math
.
HexOrDecimal64
`json:"gasCost"`
Memory
hexutil
.
Bytes
`json:"memory"`
MemorySize
int
`json:"memSize"`
Stack
[]
*
math
.
HexOrDecimal256
`json:"stack"`
Storage
map
[
common
.
Hash
]
common
.
Hash
`json:"-"`
Depth
int
`json:"depth"`
Err
error
`json:"error"`
OpName
string
`json:"opName"`
MemorySize
int
`json:"memSize"`
}
var
enc
StructLog
enc
.
Pc
=
s
.
Pc
...
...
@@ -31,6 +31,7 @@ func (s StructLog) MarshalJSON() ([]byte, error) {
enc
.
Gas
=
math
.
HexOrDecimal64
(
s
.
Gas
)
enc
.
GasCost
=
math
.
HexOrDecimal64
(
s
.
GasCost
)
enc
.
Memory
=
s
.
Memory
enc
.
MemorySize
=
s
.
MemorySize
if
s
.
Stack
!=
nil
{
enc
.
Stack
=
make
([]
*
math
.
HexOrDecimal256
,
len
(
s
.
Stack
))
for
k
,
v
:=
range
s
.
Stack
{
...
...
@@ -41,21 +42,21 @@ func (s StructLog) MarshalJSON() ([]byte, error) {
enc
.
Depth
=
s
.
Depth
enc
.
Err
=
s
.
Err
enc
.
OpName
=
s
.
OpName
()
enc
.
MemorySize
=
s
.
MemorySize
()
return
json
.
Marshal
(
&
enc
)
}
func
(
s
*
StructLog
)
UnmarshalJSON
(
input
[]
byte
)
error
{
type
StructLog
struct
{
Pc
*
uint64
`json:"pc"`
Op
*
OpCode
`json:"op"`
Gas
*
math
.
HexOrDecimal64
`json:"gas"`
GasCost
*
math
.
HexOrDecimal64
`json:"gasCost"`
Memory
hexutil
.
Bytes
`json:"memory"`
Stack
[]
*
math
.
HexOrDecimal256
`json:"stack"`
Storage
map
[
common
.
Hash
]
common
.
Hash
`json:"-"`
Depth
*
int
`json:"depth"`
Err
*
error
`json:"error"`
Pc
*
uint64
`json:"pc"`
Op
*
OpCode
`json:"op"`
Gas
*
math
.
HexOrDecimal64
`json:"gas"`
GasCost
*
math
.
HexOrDecimal64
`json:"gasCost"`
Memory
hexutil
.
Bytes
`json:"memory"`
MemorySize
*
int
`json:"memSize"`
Stack
[]
*
math
.
HexOrDecimal256
`json:"stack"`
Storage
map
[
common
.
Hash
]
common
.
Hash
`json:"-"`
Depth
*
int
`json:"depth"`
Err
*
error
`json:"error"`
}
var
dec
StructLog
if
err
:=
json
.
Unmarshal
(
input
,
&
dec
);
err
!=
nil
{
...
...
@@ -76,6 +77,9 @@ func (s *StructLog) UnmarshalJSON(input []byte) error {
if
dec
.
Memory
!=
nil
{
s
.
Memory
=
dec
.
Memory
}
if
dec
.
MemorySize
!=
nil
{
s
.
MemorySize
=
*
dec
.
MemorySize
}
if
dec
.
Stack
!=
nil
{
s
.
Stack
=
make
([]
*
big
.
Int
,
len
(
dec
.
Stack
))
for
k
,
v
:=
range
dec
.
Stack
{
...
...
core/vm/logger.go
浏览文件 @
9a44e103
...
...
@@ -54,35 +54,31 @@ type LogConfig struct {
// StructLog is emitted to the EVM each cycle and lists information about the current internal state
// prior to the execution of the statement.
type
StructLog
struct
{
Pc
uint64
`json:"pc"`
Op
OpCode
`json:"op"`
Gas
uint64
`json:"gas"`
GasCost
uint64
`json:"gasCost"`
Memory
[]
byte
`json:"memory"`
Stack
[]
*
big
.
Int
`json:"stack"`
Storage
map
[
common
.
Hash
]
common
.
Hash
`json:"-"`
Depth
int
`json:"depth"`
Err
error
`json:"error"`
Pc
uint64
`json:"pc"`
Op
OpCode
`json:"op"`
Gas
uint64
`json:"gas"`
GasCost
uint64
`json:"gasCost"`
Memory
[]
byte
`json:"memory"`
MemorySize
int
`json:"memSize"`
Stack
[]
*
big
.
Int
`json:"stack"`
Storage
map
[
common
.
Hash
]
common
.
Hash
`json:"-"`
Depth
int
`json:"depth"`
Err
error
`json:"error"`
}
// overrides for gencodec
type
structLogMarshaling
struct
{
Stack
[]
*
math
.
HexOrDecimal256
Gas
math
.
HexOrDecimal64
GasCost
math
.
HexOrDecimal64
Memory
hexutil
.
Bytes
OpName
string
`json:"opName"`
MemorySize
int
`json:"memSize"`
Stack
[]
*
math
.
HexOrDecimal256
Gas
math
.
HexOrDecimal64
GasCost
math
.
HexOrDecimal64
Memory
hexutil
.
Bytes
OpName
string
`json:"opName"`
}
func
(
s
*
StructLog
)
OpName
()
string
{
return
s
.
Op
.
String
()
}
func
(
s
*
StructLog
)
MemorySize
()
int
{
return
len
(
s
.
Memory
)
}
// Tracer is used to collect execution traces from an EVM transaction
// execution. CaptureState is called for each step of the VM with the
// current VM state.
...
...
@@ -181,7 +177,7 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
}
}
// create a new snaptshot of the EVM.
log
:=
StructLog
{
pc
,
op
,
gas
,
cost
,
mem
,
stck
,
storage
,
env
.
depth
,
err
}
log
:=
StructLog
{
pc
,
op
,
gas
,
cost
,
mem
,
memory
.
Len
(),
stck
,
storage
,
depth
,
err
}
l
.
logs
=
append
(
l
.
logs
,
log
)
return
nil
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录