Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
afdfdebd
Commit
afdfdebd
authored
7 years ago
by
Péter Szilágyi
Committed by
GitHub
7 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14983 from karalabe/metropolis-revert
core/vm: implement REVERT metropolis opcode
parents
e311bb52
1bbd4008
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
73 additions
and
42 deletions
+73
-42
evm.go
core/vm/evm.go
+16
-16
gas_table.go
core/vm/gas_table.go
+4
-0
instructions.go
core/vm/instructions.go
+20
-7
interpreter.go
core/vm/interpreter.go
+7
-5
jump_table.go
core/vm/jump_table.go
+16
-14
memory_table.go
core/vm/memory_table.go
+4
-0
opcodes.go
core/vm/opcodes.go
+3
-0
state_test.go
tests/state_test.go
+3
-0
No files found.
core/vm/evm.go
View file @
afdfdebd
...
...
@@ -168,8 +168,10 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
// above we revert to the snapshot and consume any gas remaining. Additionally
// when we're in homestead this also counts for code storage gas errors.
if
err
!=
nil
{
contract
.
UseGas
(
contract
.
Gas
)
evm
.
StateDB
.
RevertToSnapshot
(
snapshot
)
if
err
!=
errExecutionReverted
{
contract
.
UseGas
(
contract
.
Gas
)
}
}
return
ret
,
contract
.
Gas
,
err
}
...
...
@@ -207,10 +209,11 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
ret
,
err
=
run
(
evm
,
snapshot
,
contract
,
input
)
if
err
!=
nil
{
contract
.
UseGas
(
contract
.
Gas
)
evm
.
StateDB
.
RevertToSnapshot
(
snapshot
)
if
err
!=
errExecutionReverted
{
contract
.
UseGas
(
contract
.
Gas
)
}
}
return
ret
,
contract
.
Gas
,
err
}
...
...
@@ -239,10 +242,11 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
ret
,
err
=
run
(
evm
,
snapshot
,
contract
,
input
)
if
err
!=
nil
{
contract
.
UseGas
(
contract
.
Gas
)
evm
.
StateDB
.
RevertToSnapshot
(
snapshot
)
if
err
!=
errExecutionReverted
{
contract
.
UseGas
(
contract
.
Gas
)
}
}
return
ret
,
contract
.
Gas
,
err
}
...
...
@@ -281,8 +285,10 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
// when we're in Homestead this also counts for code storage gas errors.
ret
,
err
=
run
(
evm
,
snapshot
,
contract
,
input
)
if
err
!=
nil
{
contract
.
UseGas
(
contract
.
Gas
)
evm
.
StateDB
.
RevertToSnapshot
(
snapshot
)
if
err
!=
errExecutionReverted
{
contract
.
UseGas
(
contract
.
Gas
)
}
}
return
ret
,
contract
.
Gas
,
err
}
...
...
@@ -339,18 +345,12 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I
// When an error was returned by the EVM or when setting the creation code
// above we revert to the snapshot and consume any gas remaining. Additionally
// when we're in homestead this also counts for code storage gas errors.
if
maxCodeSizeExceeded
||
(
err
!=
nil
&&
(
evm
.
ChainConfig
()
.
IsHomestead
(
evm
.
BlockNumber
)
||
err
!=
ErrCodeStoreOutOfGas
))
{
contract
.
UseGas
(
contract
.
Gas
)
if
maxCodeSizeExceeded
||
(
err
!=
nil
&&
(
evm
.
ChainConfig
()
.
IsHomestead
(
evm
.
BlockNumber
)
||
err
!=
ErrCodeStoreOutOfGas
))
{
evm
.
StateDB
.
RevertToSnapshot
(
snapshot
)
if
err
!=
errExecutionReverted
{
contract
.
UseGas
(
contract
.
Gas
)
}
}
// If the vm returned with an error the return value should be set to nil.
// This isn't consensus critical but merely to for behaviour reasons such as
// tests, RPC calls, etc.
if
err
!=
nil
{
ret
=
nil
}
return
ret
,
contractAddr
,
contract
.
Gas
,
err
}
...
...
This diff is collapsed.
Click to expand it.
core/vm/gas_table.go
View file @
afdfdebd
...
...
@@ -396,6 +396,10 @@ func gasReturn(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, m
return
memoryGasCost
(
mem
,
memorySize
)
}
func
gasRevert
(
gt
params
.
GasTable
,
evm
*
EVM
,
contract
*
Contract
,
stack
*
Stack
,
mem
*
Memory
,
memorySize
uint64
)
(
uint64
,
error
)
{
return
memoryGasCost
(
mem
,
memorySize
)
}
func
gasSuicide
(
gt
params
.
GasTable
,
evm
*
EVM
,
contract
*
Contract
,
stack
*
Stack
,
mem
*
Memory
,
memorySize
uint64
)
(
uint64
,
error
)
{
var
gas
uint64
// EIP150 homestead gas reprice fork:
...
...
This diff is collapsed.
Click to expand it.
core/vm/instructions.go
View file @
afdfdebd
...
...
@@ -32,6 +32,7 @@ var (
bigZero
=
new
(
big
.
Int
)
errWriteProtection
=
errors
.
New
(
"evm: write protection"
)
errReturnDataOutOfBounds
=
errors
.
New
(
"evm: return data out of bounds"
)
errExecutionReverted
=
errors
.
New
(
"evm: execution reverted"
)
)
func
opAdd
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
...
...
@@ -579,7 +580,7 @@ func opCreate(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *S
}
contract
.
UseGas
(
gas
)
_
,
addr
,
returnGas
,
suberr
:=
evm
.
Create
(
contract
,
input
,
gas
,
value
)
res
,
addr
,
returnGas
,
suberr
:=
evm
.
Create
(
contract
,
input
,
gas
,
value
)
// Push item on the stack based on the returned error. If the ruleset is
// homestead we must check for CodeStoreOutOfGasError (homestead only
// rule) and treat as an error, if the ruleset is frontier we must
...
...
@@ -592,9 +593,11 @@ func opCreate(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *S
stack
.
push
(
addr
.
Big
())
}
contract
.
Gas
+=
returnGas
evm
.
interpreter
.
intPool
.
put
(
value
,
offset
,
size
)
if
suberr
==
errExecutionReverted
{
return
res
,
nil
}
return
nil
,
nil
}
...
...
@@ -622,7 +625,8 @@ func opCall(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Sta
stack
.
push
(
new
(
big
.
Int
))
}
else
{
stack
.
push
(
big
.
NewInt
(
1
))
}
if
err
==
nil
||
err
==
errExecutionReverted
{
memory
.
Set
(
retOffset
.
Uint64
(),
retSize
.
Uint64
(),
ret
)
}
contract
.
Gas
+=
returnGas
...
...
@@ -653,10 +657,10 @@ func opCallCode(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack
ret
,
returnGas
,
err
:=
evm
.
CallCode
(
contract
,
address
,
args
,
gas
,
value
)
if
err
!=
nil
{
stack
.
push
(
new
(
big
.
Int
))
}
else
{
stack
.
push
(
big
.
NewInt
(
1
))
}
if
err
==
nil
||
err
==
errExecutionReverted
{
memory
.
Set
(
retOffset
.
Uint64
(),
retSize
.
Uint64
(),
ret
)
}
contract
.
Gas
+=
returnGas
...
...
@@ -676,6 +680,8 @@ func opDelegateCall(pc *uint64, evm *EVM, contract *Contract, memory *Memory, st
stack
.
push
(
new
(
big
.
Int
))
}
else
{
stack
.
push
(
big
.
NewInt
(
1
))
}
if
err
==
nil
||
err
==
errExecutionReverted
{
memory
.
Set
(
outOffset
.
Uint64
(),
outSize
.
Uint64
(),
ret
)
}
contract
.
Gas
+=
returnGas
...
...
@@ -704,7 +710,8 @@ func opStaticCall(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stac
stack
.
push
(
new
(
big
.
Int
))
}
else
{
stack
.
push
(
big
.
NewInt
(
1
))
}
if
err
==
nil
||
err
==
errExecutionReverted
{
memory
.
Set
(
retOffset
.
Uint64
(),
retSize
.
Uint64
(),
ret
)
}
contract
.
Gas
+=
returnGas
...
...
@@ -718,7 +725,14 @@ func opReturn(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *S
ret
:=
memory
.
GetPtr
(
offset
.
Int64
(),
size
.
Int64
())
evm
.
interpreter
.
intPool
.
put
(
offset
,
size
)
return
ret
,
nil
}
func
opRevert
(
pc
*
uint64
,
evm
*
EVM
,
contract
*
Contract
,
memory
*
Memory
,
stack
*
Stack
)
([]
byte
,
error
)
{
offset
,
size
:=
stack
.
pop
(),
stack
.
pop
()
ret
:=
memory
.
GetPtr
(
offset
.
Int64
(),
size
.
Int64
())
evm
.
interpreter
.
intPool
.
put
(
offset
,
size
)
return
ret
,
nil
}
...
...
@@ -731,7 +745,6 @@ func opSuicide(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *
evm
.
StateDB
.
AddBalance
(
common
.
BigToAddress
(
stack
.
pop
()),
balance
)
evm
.
StateDB
.
Suicide
(
contract
.
Address
())
return
nil
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
core/vm/interpreter.go
View file @
afdfdebd
...
...
@@ -209,20 +209,22 @@ func (in *Interpreter) Run(snapshot int, contract *Contract, input []byte) (ret
if
verifyPool
{
verifyIntegerPool
(
in
.
intPool
)
}
// 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
.
returns
{
in
.
returnData
=
res
}
switch
{
case
err
!=
nil
:
return
nil
,
err
case
operation
.
reverts
:
return
res
,
errExecutionReverted
case
operation
.
halts
:
return
res
,
nil
case
!
operation
.
jumps
:
pc
++
}
// 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
.
returns
{
in
.
returnData
=
res
}
}
return
nil
,
nil
}
This diff is collapsed.
Click to expand it.
core/vm/jump_table.go
View file @
afdfdebd
...
...
@@ -41,20 +41,13 @@ type operation struct {
validateStack
stackValidationFunc
// memorySize returns the memory size required for the operation
memorySize
memorySizeFunc
// halts indicates whether the operation shoult halt further execution
// and return
halts
bool
// jumps indicates whether operation made a jump. This prevents the program
// counter from further incrementing.
jumps
bool
// writes determines whether this a state modifying operation
writes
bool
// valid is used to check whether the retrieved operation is valid and known
valid
bool
// reverts determined whether the operation reverts state
reverts
bool
// returns determines whether the opertions sets the return data
returns
bool
halts
bool
// indicates whether the operation shoult halt further execution
jumps
bool
// indicates whether the program counter should not increment
writes
bool
// determines whether this a state modifying operation
valid
bool
// indication whether the retrieved operation is valid and known
reverts
bool
// determines whether the operation reverts state (implicitly halts)
returns
bool
// determines whether the opertions sets the return data content
}
var
(
...
...
@@ -89,6 +82,15 @@ func NewMetropolisInstructionSet() [256]operation {
memorySize
:
memoryReturnDataCopy
,
valid
:
true
,
}
instructionSet
[
REVERT
]
=
operation
{
execute
:
opRevert
,
gasCost
:
gasRevert
,
validateStack
:
makeStackFunc
(
2
,
0
),
memorySize
:
memoryRevert
,
valid
:
true
,
reverts
:
true
,
returns
:
true
,
}
return
instructionSet
}
...
...
This diff is collapsed.
Click to expand it.
core/vm/memory_table.go
View file @
afdfdebd
...
...
@@ -89,6 +89,10 @@ func memoryReturn(stack *Stack) *big.Int {
return
calcMemSize
(
stack
.
Back
(
0
),
stack
.
Back
(
1
))
}
func
memoryRevert
(
stack
*
Stack
)
*
big
.
Int
{
return
calcMemSize
(
stack
.
Back
(
0
),
stack
.
Back
(
1
))
}
func
memoryLog
(
stack
*
Stack
)
*
big
.
Int
{
mSize
,
mStart
:=
stack
.
Back
(
1
),
stack
.
Back
(
0
)
return
calcMemSize
(
mStart
,
mSize
)
...
...
This diff is collapsed.
Click to expand it.
core/vm/opcodes.go
View file @
afdfdebd
...
...
@@ -204,6 +204,7 @@ const (
DELEGATECALL
STATICCALL
=
0xfa
REVERT
=
0xfd
SELFDESTRUCT
=
0xff
)
...
...
@@ -360,6 +361,7 @@ var opCodeToString = map[OpCode]string{
CALLCODE
:
"CALLCODE"
,
DELEGATECALL
:
"DELEGATECALL"
,
STATICCALL
:
"STATICCALL"
,
REVERT
:
"REVERT"
,
SELFDESTRUCT
:
"SELFDESTRUCT"
,
PUSH
:
"PUSH"
,
...
...
@@ -509,6 +511,7 @@ var stringToOp = map[string]OpCode{
"CALL"
:
CALL
,
"RETURN"
:
RETURN
,
"CALLCODE"
:
CALLCODE
,
"REVERT"
:
REVERT
,
"SELFDESTRUCT"
:
SELFDESTRUCT
,
}
...
...
This diff is collapsed.
Click to expand it.
tests/state_test.go
View file @
afdfdebd
...
...
@@ -40,6 +40,9 @@ func TestState(t *testing.T) {
st
.
fails
(
`^stRevertTest/RevertDepthCreateAddressCollision\.json/EIP15[08]/[67]`
,
"bug in test"
)
st
.
fails
(
`^stRevertTest/RevertPrecompiledTouch\.json/EIP158`
,
"bug in test"
)
st
.
fails
(
`^stRevertTest/RevertPrefoundEmptyOOG\.json/EIP158`
,
"bug in test"
)
st
.
fails
(
`^stRevertTest/RevertDepthCreateAddressCollision\.json/Byzantium/[67]`
,
"bug in test"
)
st
.
fails
(
`^stRevertTest/RevertPrecompiledTouch\.json/Byzantium`
,
"bug in test"
)
st
.
fails
(
`^stRevertTest/RevertPrefoundEmptyOOG\.json/Byzantium`
,
"bug in test"
)
st
.
walk
(
t
,
stateTestDir
,
func
(
t
*
testing
.
T
,
name
string
,
test
*
StateTest
)
{
for
_
,
subtest
:=
range
test
.
Subtests
()
{
...
...
This diff is collapsed.
Click to expand it.
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