Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
4e0fea4d
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,发现更多精彩内容 >>
未验证
提交
4e0fea4d
编写于
8月 16, 2017
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core/vm: polish RETURNDATA, add missing returns to CALL*
上级
9bd6068f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
75 addition
and
72 deletion
+75
-72
core/vm/evm.go
core/vm/evm.go
+3
-3
core/vm/gas_table.go
core/vm/gas_table.go
+1
-1
core/vm/instructions.go
core/vm/instructions.go
+38
-35
core/vm/interpreter.go
core/vm/interpreter.go
+4
-5
core/vm/jump_table.go
core/vm/jump_table.go
+28
-26
core/vm/memory.go
core/vm/memory.go
+0
-1
core/vm/memory_table.go
core/vm/memory_table.go
+1
-1
未找到文件。
core/vm/evm.go
浏览文件 @
4e0fea4d
...
...
@@ -261,9 +261,9 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
// Make sure the readonly is only set if we aren't in readonly yet
// this makes also sure that the readonly flag isn't removed for
// child calls.
if
!
evm
.
interpreter
.
read
o
nly
{
evm
.
interpreter
.
read
o
nly
=
true
defer
func
()
{
evm
.
interpreter
.
read
o
nly
=
false
}()
if
!
evm
.
interpreter
.
read
O
nly
{
evm
.
interpreter
.
read
O
nly
=
true
defer
func
()
{
evm
.
interpreter
.
read
O
nly
=
false
}()
}
var
(
...
...
core/vm/gas_table.go
浏览文件 @
4e0fea4d
...
...
@@ -65,7 +65,7 @@ func constGasFunc(gas uint64) gasFunc {
}
}
func
gasCall
d
ataCopy
(
gt
params
.
GasTable
,
evm
*
EVM
,
contract
*
Contract
,
stack
*
Stack
,
mem
*
Memory
,
memorySize
uint64
)
(
uint64
,
error
)
{
func
gasCall
D
ataCopy
(
gt
params
.
GasTable
,
evm
*
EVM
,
contract
*
Contract
,
stack
*
Stack
,
mem
*
Memory
,
memorySize
uint64
)
(
uint64
,
error
)
{
gas
,
err
:=
memoryGasCost
(
mem
,
memorySize
)
if
err
!=
nil
{
return
0
,
err
...
...
core/vm/instructions.go
浏览文件 @
4e0fea4d
...
...
@@ -29,9 +29,9 @@ import (
)
var
(
bigZero
=
new
(
big
.
Int
)
errWriteProtection
=
errors
.
New
(
"evm: write protection"
)
errRe
adOutOfBound
=
errors
.
New
(
"evm: read out of bound
"
)
bigZero
=
new
(
big
.
Int
)
errWriteProtection
=
errors
.
New
(
"evm: write protection"
)
errRe
turnDataOutOfBounds
=
errors
.
New
(
"evm: return data out of bounds
"
)
)
func
opAdd
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
...
...
@@ -243,6 +243,7 @@ func opAnd(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stac
evm
.
interpreter
.
intPool
.
put
(
y
)
return
nil
,
nil
}
func
opOr
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
x
,
y
:=
stack
.
pop
(),
stack
.
pop
()
stack
.
push
(
x
.
Or
(
x
,
y
))
...
...
@@ -250,6 +251,7 @@ func opOr(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack
evm
.
interpreter
.
intPool
.
put
(
y
)
return
nil
,
nil
}
func
opXor
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
x
,
y
:=
stack
.
pop
(),
stack
.
pop
()
stack
.
push
(
x
.
Xor
(
x
,
y
))
...
...
@@ -269,6 +271,7 @@ func opByte(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Sta
evm
.
interpreter
.
intPool
.
put
(
th
)
return
nil
,
nil
}
func
opAddmod
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
x
,
y
,
z
:=
stack
.
pop
(),
stack
.
pop
(),
stack
.
pop
()
if
z
.
Cmp
(
bigZero
)
>
0
{
...
...
@@ -282,6 +285,7 @@ func opAddmod(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *S
evm
.
interpreter
.
intPool
.
put
(
y
,
z
)
return
nil
,
nil
}
func
opMulmod
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
x
,
y
,
z
:=
stack
.
pop
(),
stack
.
pop
(),
stack
.
pop
()
if
z
.
Cmp
(
bigZero
)
>
0
{
...
...
@@ -339,25 +343,25 @@ func opCallValue(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack
return
nil
,
nil
}
func
opCall
d
ataLoad
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
func
opCall
D
ataLoad
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
stack
.
push
(
new
(
big
.
Int
)
.
SetBytes
(
getDataBig
(
contract
.
Input
,
stack
.
pop
(),
big32
)))
return
nil
,
nil
}
func
opCall
d
ataSize
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
func
opCall
D
ataSize
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
stack
.
push
(
evm
.
interpreter
.
intPool
.
get
()
.
SetInt64
(
int64
(
len
(
contract
.
Input
))))
return
nil
,
nil
}
func
opCall
d
ataCopy
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
func
opCall
D
ataCopy
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
var
(
m
Off
=
stack
.
pop
()
cOff
=
stack
.
pop
()
l
=
stack
.
pop
()
m
emOffset
=
stack
.
pop
()
dataOffset
=
stack
.
pop
()
l
ength
=
stack
.
pop
()
)
memory
.
Set
(
m
Off
.
Uint64
(),
l
.
Uint64
(),
getDataBig
(
contract
.
Input
,
cOff
,
l
))
memory
.
Set
(
m
emOffset
.
Uint64
(),
length
.
Uint64
(),
getDataBig
(
contract
.
Input
,
dataOffset
,
length
))
evm
.
interpreter
.
intPool
.
put
(
m
Off
,
cOff
,
l
)
evm
.
interpreter
.
intPool
.
put
(
m
emOffset
,
dataOffset
,
length
)
return
nil
,
nil
}
...
...
@@ -368,17 +372,17 @@ func opReturnDataSize(pc *uint64, evm *EVM, contract *Contract, memory *Memory,
func
opReturnDataCopy
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
var
(
m
Off
=
stack
.
pop
()
cOff
=
stack
.
pop
()
l
=
stack
.
pop
()
m
emOffset
=
stack
.
pop
()
dataOffset
=
stack
.
pop
()
l
ength
=
stack
.
pop
()
)
defer
evm
.
interpreter
.
intPool
.
put
(
m
Off
,
cOff
,
l
)
defer
evm
.
interpreter
.
intPool
.
put
(
m
emOffset
,
dataOffset
,
length
)
cEnd
:=
new
(
big
.
Int
)
.
Add
(
cOff
,
l
)
if
cEnd
.
BitLen
()
>
64
||
uint64
(
len
(
evm
.
interpreter
.
returnData
))
<
cE
nd
.
Uint64
()
{
return
nil
,
errRe
adOutOfBound
end
:=
new
(
big
.
Int
)
.
Add
(
dataOffset
,
length
)
if
end
.
BitLen
()
>
64
||
uint64
(
len
(
evm
.
interpreter
.
returnData
))
<
e
nd
.
Uint64
()
{
return
nil
,
errRe
turnDataOutOfBounds
}
memory
.
Set
(
m
Off
.
Uint64
(),
l
.
Uint64
(),
evm
.
interpreter
.
returnData
[
cOff
.
Uint64
()
:
cE
nd
.
Uint64
()])
memory
.
Set
(
m
emOffset
.
Uint64
(),
length
.
Uint64
(),
evm
.
interpreter
.
returnData
[
dataOffset
.
Uint64
()
:
e
nd
.
Uint64
()])
return
nil
,
nil
}
...
...
@@ -401,31 +405,28 @@ func opCodeSize(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack
func
opCodeCopy
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
var
(
m
Off
=
stack
.
pop
()
c
Off
=
stack
.
pop
()
l
=
stack
.
pop
()
m
emOffset
=
stack
.
pop
()
c
odeOffset
=
stack
.
pop
()
l
ength
=
stack
.
pop
()
)
codeCopy
:=
getDataBig
(
contract
.
Code
,
cOff
,
l
)
memory
.
Set
(
mOff
.
Uint64
(),
l
.
Uint64
(),
codeCopy
)
codeCopy
:=
getDataBig
(
contract
.
Code
,
codeOffset
,
length
)
memory
.
Set
(
memOffset
.
Uint64
(),
length
.
Uint64
(),
codeCopy
)
evm
.
interpreter
.
intPool
.
put
(
m
Off
,
cOff
,
l
)
evm
.
interpreter
.
intPool
.
put
(
m
emOffset
,
codeOffset
,
length
)
return
nil
,
nil
}
func
opExtCodeCopy
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
var
(
addr
=
common
.
BigToAddress
(
stack
.
pop
())
m
Off
=
stack
.
pop
()
c
Off
=
stack
.
pop
()
l
=
stack
.
pop
()
addr
=
common
.
BigToAddress
(
stack
.
pop
())
m
emOffset
=
stack
.
pop
()
c
odeOffset
=
stack
.
pop
()
l
ength
=
stack
.
pop
()
)
codeCopy
:=
getDataBig
(
evm
.
StateDB
.
GetCode
(
addr
),
cOff
,
l
)
memory
.
Set
(
mOff
.
Uint64
(),
l
.
Uint64
(),
codeCopy
)
evm
.
interpreter
.
intPool
.
put
(
mOff
,
cOff
,
l
)
codeCopy
:=
getDataBig
(
evm
.
StateDB
.
GetCode
(
addr
),
codeOffset
,
length
)
memory
.
Set
(
memOffset
.
Uint64
(),
length
.
Uint64
(),
codeCopy
)
evm
.
interpreter
.
intPool
.
put
(
memOffset
,
codeOffset
,
length
)
return
nil
,
nil
}
...
...
@@ -530,6 +531,7 @@ func opJump(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Sta
evm
.
interpreter
.
intPool
.
put
(
pos
)
return
nil
,
nil
}
func
opJumpi
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
pos
,
cond
:=
stack
.
pop
(),
stack
.
pop
()
if
cond
.
Sign
()
!=
0
{
...
...
@@ -545,6 +547,7 @@ func opJumpi(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *St
evm
.
interpreter
.
intPool
.
put
(
pos
,
cond
)
return
nil
,
nil
}
func
opJumpdest
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
return
nil
,
nil
}
...
...
core/vm/interpreter.go
浏览文件 @
4e0fea4d
...
...
@@ -59,9 +59,8 @@ type Interpreter struct {
gasTable
params
.
GasTable
intPool
*
intPool
readonly
bool
// returnData contains the last call's return data
returnData
[]
byte
readOnly
bool
// Whether to throw on stateful modifications
returnData
[]
byte
// Last CALL's return data for subsequent reuse
}
// NewInterpreter returns a new instance of the Interpreter.
...
...
@@ -90,7 +89,7 @@ func NewInterpreter(evm *EVM, cfg Config) *Interpreter {
func
(
in
*
Interpreter
)
enforceRestrictions
(
op
OpCode
,
operation
operation
,
stack
*
Stack
)
error
{
if
in
.
evm
.
chainRules
.
IsMetropolis
{
if
in
.
read
o
nly
{
if
in
.
read
O
nly
{
// If the interpreter is operating in readonly mode, make sure no
// state-modifying operation is performed. The 3rd stack item
// for a call operation is the value. Transfering value from one
...
...
@@ -221,7 +220,7 @@ func (in *Interpreter) Run(snapshot int, contract *Contract, input []byte) (ret
}
// if the operation clears the return data (e.g. it has returning data)
// set the last return to the result of the operation.
if
operation
.
clearsReturndata
{
if
operation
.
returns
{
in
.
returnData
=
res
}
}
...
...
core/vm/jump_table.go
浏览文件 @
4e0fea4d
...
...
@@ -53,8 +53,8 @@ type operation struct {
valid
bool
// reverts determined whether the operation reverts state
reverts
bool
//
clearsReturndata determines whether the opertions clear
s the return data
clearsReturndata
bool
//
returns determines whether the opertions set
s the return data
returns
bool
}
var
(
...
...
@@ -74,6 +74,7 @@ func NewMetropolisInstructionSet() [256]operation {
validateStack
:
makeStackFunc
(
6
,
1
),
memorySize
:
memoryStaticCall
,
valid
:
true
,
returns
:
true
,
}
instructionSet
[
RETURNDATASIZE
]
=
operation
{
execute
:
opReturnDataSize
,
...
...
@@ -101,6 +102,7 @@ func NewHomesteadInstructionSet() [256]operation {
validateStack
:
makeStackFunc
(
6
,
1
),
memorySize
:
memoryDelegateCall
,
valid
:
true
,
returns
:
true
,
}
return
instructionSet
}
...
...
@@ -286,22 +288,22 @@ func NewFrontierInstructionSet() [256]operation {
valid
:
true
,
},
CALLDATALOAD
:
{
execute
:
opCall
d
ataLoad
,
execute
:
opCall
D
ataLoad
,
gasCost
:
constGasFunc
(
GasFastestStep
),
validateStack
:
makeStackFunc
(
1
,
1
),
valid
:
true
,
},
CALLDATASIZE
:
{
execute
:
opCall
d
ataSize
,
execute
:
opCall
D
ataSize
,
gasCost
:
constGasFunc
(
GasQuickStep
),
validateStack
:
makeStackFunc
(
0
,
1
),
valid
:
true
,
},
CALLDATACOPY
:
{
execute
:
opCall
d
ataCopy
,
gasCost
:
gasCall
d
ataCopy
,
execute
:
opCall
D
ataCopy
,
gasCost
:
gasCall
D
ataCopy
,
validateStack
:
makeStackFunc
(
3
,
0
),
memorySize
:
memoryCall
d
ataCopy
,
memorySize
:
memoryCall
D
ataCopy
,
valid
:
true
,
},
CODESIZE
:
{
...
...
@@ -876,29 +878,29 @@ func NewFrontierInstructionSet() [256]operation {
writes
:
true
,
},
CREATE
:
{
execute
:
opCreate
,
gasCost
:
gasCreate
,
validateStack
:
makeStackFunc
(
3
,
1
),
memorySize
:
memoryCreate
,
valid
:
true
,
writes
:
true
,
clearsReturndata
:
true
,
execute
:
opCreate
,
gasCost
:
gasCreate
,
validateStack
:
makeStackFunc
(
3
,
1
),
memorySize
:
memoryCreate
,
valid
:
true
,
writes
:
true
,
returns
:
true
,
},
CALL
:
{
execute
:
opCall
,
gasCost
:
gasCall
,
validateStack
:
makeStackFunc
(
7
,
1
),
memorySize
:
memoryCall
,
valid
:
true
,
clearsReturndata
:
true
,
execute
:
opCall
,
gasCost
:
gasCall
,
validateStack
:
makeStackFunc
(
7
,
1
),
memorySize
:
memoryCall
,
valid
:
true
,
returns
:
true
,
},
CALLCODE
:
{
execute
:
opCallCode
,
gasCost
:
gasCallCode
,
validateStack
:
makeStackFunc
(
7
,
1
),
memorySize
:
memoryCall
,
valid
:
true
,
clearsReturndata
:
true
,
execute
:
opCallCode
,
gasCost
:
gasCallCode
,
validateStack
:
makeStackFunc
(
7
,
1
),
memorySize
:
memoryCall
,
valid
:
true
,
returns
:
true
,
},
RETURN
:
{
execute
:
opReturn
,
...
...
core/vm/memory.go
浏览文件 @
4e0fea4d
...
...
@@ -22,7 +22,6 @@ import "fmt"
type
Memory
struct
{
store
[]
byte
lastGasCost
uint64
lastReturn
[]
byte
}
func
NewMemory
()
*
Memory
{
...
...
core/vm/memory_table.go
浏览文件 @
4e0fea4d
...
...
@@ -26,7 +26,7 @@ func memorySha3(stack *Stack) *big.Int {
return
calcMemSize
(
stack
.
Back
(
0
),
stack
.
Back
(
1
))
}
func
memoryCall
d
ataCopy
(
stack
*
Stack
)
*
big
.
Int
{
func
memoryCall
D
ataCopy
(
stack
*
Stack
)
*
big
.
Int
{
return
calcMemSize
(
stack
.
Back
(
0
),
stack
.
Back
(
2
))
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录