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
4dc7ee90
Commit
4dc7ee90
authored
Jan 02, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closure => Context
parent
e2d1d832
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
107 additions
and
119 deletions
+107
-119
main.go
cmd/evm/main.go
+3
-3
vm_env.go
cmd/utils/vm_env.go
+3
-3
chain_manager.go
core/chain_manager.go
+0
-20
execution.go
core/execution.go
+3
-3
state_transition.go
core/state_transition.go
+1
-1
vm_env.go
core/vm_env.go
+3
-3
vm.go
tests/helper/vm.go
+3
-3
context.go
vm/context.go
+17
-17
environment.go
vm/environment.go
+3
-3
virtual_machine.go
vm/virtual_machine.go
+1
-1
vm.go
vm/vm.go
+1
-1
vm_debug.go
vm/vm_debug.go
+66
-58
vm_env.go
xeth/vm_env.go
+3
-3
No files found.
cmd/evm/main.go
View file @
4dc7ee90
...
...
@@ -144,19 +144,19 @@ func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execu
return
core
.
NewExecution
(
self
,
addr
,
data
,
gas
,
price
,
value
)
}
func
(
self
*
VMEnv
)
Call
(
caller
vm
.
C
losure
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
func
(
self
*
VMEnv
)
Call
(
caller
vm
.
C
ontext
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
exe
:=
self
.
vm
(
addr
,
data
,
gas
,
price
,
value
)
ret
,
err
:=
exe
.
Call
(
addr
,
caller
)
self
.
Gas
=
exe
.
Gas
return
ret
,
err
}
func
(
self
*
VMEnv
)
CallCode
(
caller
vm
.
C
losure
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
func
(
self
*
VMEnv
)
CallCode
(
caller
vm
.
C
ontext
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
exe
:=
self
.
vm
(
caller
.
Address
(),
data
,
gas
,
price
,
value
)
return
exe
.
Call
(
addr
,
caller
)
}
func
(
self
*
VMEnv
)
Create
(
caller
vm
.
C
losureRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
vm
.
Closure
Ref
)
{
func
(
self
*
VMEnv
)
Create
(
caller
vm
.
C
ontextRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
vm
.
Context
Ref
)
{
exe
:=
self
.
vm
(
addr
,
data
,
gas
,
price
,
value
)
return
exe
.
Create
(
caller
)
}
cmd/utils/vm_env.go
View file @
4dc7ee90
...
...
@@ -52,19 +52,19 @@ func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execu
return
core
.
NewExecution
(
self
,
addr
,
data
,
gas
,
price
,
value
)
}
func
(
self
*
VMEnv
)
Call
(
caller
vm
.
C
losure
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
func
(
self
*
VMEnv
)
Call
(
caller
vm
.
C
ontext
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
exe
:=
self
.
vm
(
addr
,
data
,
gas
,
price
,
value
)
ret
,
err
:=
exe
.
Call
(
addr
,
caller
)
self
.
Gas
=
exe
.
Gas
return
ret
,
err
}
func
(
self
*
VMEnv
)
CallCode
(
caller
vm
.
C
losure
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
func
(
self
*
VMEnv
)
CallCode
(
caller
vm
.
C
ontext
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
exe
:=
self
.
vm
(
caller
.
Address
(),
data
,
gas
,
price
,
value
)
return
exe
.
Call
(
addr
,
caller
)
}
func
(
self
*
VMEnv
)
Create
(
caller
vm
.
C
losureRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
vm
.
Closure
Ref
)
{
func
(
self
*
VMEnv
)
Create
(
caller
vm
.
C
ontextRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
vm
.
Context
Ref
)
{
exe
:=
self
.
vm
(
addr
,
data
,
gas
,
price
,
value
)
return
exe
.
Create
(
caller
)
}
core/chain_manager.go
View file @
4dc7ee90
...
...
@@ -20,26 +20,6 @@ type StateQuery interface {
GetAccount
(
addr
[]
byte
)
*
state
.
StateObject
}
/*
func AddTestNetFunds(block *types.Block) {
for _, addr := range []string{
"51ba59315b3a95761d0863b05ccc7a7f54703d99",
"e4157b34ea9615cfbde6b4fda419828124b70c78",
"b9c015918bdaba24b4ff057a92a3873d6eb201be",
"6c386a4b26f73c802f34673f7248bb118f97424a",
"cd2a3d9f938e13cd947ec05abc7fe734df8dd826",
"2ef47100e0787b915105fd5e3f4ff6752079d5cb",
"e6716f9544a56c530d868e4bfbacb172315bdead",
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4",
} {
codedAddr := ethutil.Hex2Bytes(addr)
account := block.State().GetAccount(codedAddr)
account.SetBalance(ethutil.Big("1606938044258990275541962092341162602522202993782792835301376")) //ethutil.BigPow(2, 200)
block.State().UpdateStateObject(account)
}
}
*/
func
CalcDifficulty
(
block
,
parent
*
types
.
Block
)
*
big
.
Int
{
diff
:=
new
(
big
.
Int
)
...
...
core/execution.go
View file @
4dc7ee90
...
...
@@ -24,14 +24,14 @@ func (self *Execution) Addr() []byte {
return
self
.
address
}
func
(
self
*
Execution
)
Call
(
codeAddr
[]
byte
,
caller
vm
.
C
losure
Ref
)
([]
byte
,
error
)
{
func
(
self
*
Execution
)
Call
(
codeAddr
[]
byte
,
caller
vm
.
C
ontext
Ref
)
([]
byte
,
error
)
{
// Retrieve the executing code
code
:=
self
.
env
.
State
()
.
GetCode
(
codeAddr
)
return
self
.
exec
(
code
,
codeAddr
,
caller
)
}
func
(
self
*
Execution
)
exec
(
code
,
contextAddr
[]
byte
,
caller
vm
.
C
losure
Ref
)
(
ret
[]
byte
,
err
error
)
{
func
(
self
*
Execution
)
exec
(
code
,
contextAddr
[]
byte
,
caller
vm
.
C
ontext
Ref
)
(
ret
[]
byte
,
err
error
)
{
env
:=
self
.
env
evm
:=
vm
.
New
(
env
,
vm
.
DebugVmTy
)
...
...
@@ -63,7 +63,7 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ClosureRef) (ret
return
}
func
(
self
*
Execution
)
Create
(
caller
vm
.
C
losure
Ref
)
(
ret
[]
byte
,
err
error
,
account
*
state
.
StateObject
)
{
func
(
self
*
Execution
)
Create
(
caller
vm
.
C
ontext
Ref
)
(
ret
[]
byte
,
err
error
,
account
*
state
.
StateObject
)
{
ret
,
err
=
self
.
exec
(
self
.
input
,
nil
,
caller
)
account
=
self
.
env
.
State
()
.
GetStateObject
(
self
.
address
)
...
...
core/state_transition.go
View file @
4dc7ee90
...
...
@@ -184,7 +184,7 @@ func (self *StateTransition) TransitionState() (ret []byte, err error) {
}
vmenv
:=
self
.
VmEnv
()
var
ref
vm
.
C
losure
Ref
var
ref
vm
.
C
ontext
Ref
if
MessageCreatesContract
(
msg
)
{
contract
:=
MakeContract
(
msg
,
self
.
state
)
ret
,
err
,
ref
=
vmenv
.
Create
(
sender
,
contract
.
Address
(),
self
.
msg
.
Data
(),
self
.
gas
,
self
.
gasPrice
,
self
.
value
)
...
...
core/vm_env.go
View file @
4dc7ee90
...
...
@@ -46,16 +46,16 @@ func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *Execution
return
NewExecution
(
self
,
addr
,
data
,
gas
,
price
,
value
)
}
func
(
self
*
VMEnv
)
Call
(
me
vm
.
C
losure
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
func
(
self
*
VMEnv
)
Call
(
me
vm
.
C
ontext
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
exe
:=
self
.
vm
(
addr
,
data
,
gas
,
price
,
value
)
return
exe
.
Call
(
addr
,
me
)
}
func
(
self
*
VMEnv
)
CallCode
(
me
vm
.
C
losure
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
func
(
self
*
VMEnv
)
CallCode
(
me
vm
.
C
ontext
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
exe
:=
self
.
vm
(
me
.
Address
(),
data
,
gas
,
price
,
value
)
return
exe
.
Call
(
addr
,
me
)
}
func
(
self
*
VMEnv
)
Create
(
me
vm
.
C
losureRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
vm
.
Closure
Ref
)
{
func
(
self
*
VMEnv
)
Create
(
me
vm
.
C
ontextRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
vm
.
Context
Ref
)
{
exe
:=
self
.
vm
(
addr
,
data
,
gas
,
price
,
value
)
return
exe
.
Create
(
me
)
}
tests/helper/vm.go
View file @
4dc7ee90
...
...
@@ -74,19 +74,19 @@ func (self *Env) vm(addr, data []byte, gas, price, value *big.Int) *core.Executi
return
exec
}
func
(
self
*
Env
)
Call
(
caller
vm
.
C
losure
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
func
(
self
*
Env
)
Call
(
caller
vm
.
C
ontext
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
exe
:=
self
.
vm
(
addr
,
data
,
gas
,
price
,
value
)
ret
,
err
:=
exe
.
Call
(
addr
,
caller
)
self
.
Gas
=
exe
.
Gas
return
ret
,
err
}
func
(
self
*
Env
)
CallCode
(
caller
vm
.
C
losure
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
func
(
self
*
Env
)
CallCode
(
caller
vm
.
C
ontext
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
exe
:=
self
.
vm
(
caller
.
Address
(),
data
,
gas
,
price
,
value
)
return
exe
.
Call
(
addr
,
caller
)
}
func
(
self
*
Env
)
Create
(
caller
vm
.
C
losureRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
vm
.
Closure
Ref
)
{
func
(
self
*
Env
)
Create
(
caller
vm
.
C
ontextRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
vm
.
Context
Ref
)
{
exe
:=
self
.
vm
(
addr
,
data
,
gas
,
price
,
value
)
return
exe
.
Create
(
caller
)
}
...
...
vm/c
losure
.go
→
vm/c
ontext
.go
View file @
4dc7ee90
...
...
@@ -8,15 +8,15 @@ import (
"github.com/ethereum/go-ethereum/state"
)
type
C
losure
Ref
interface
{
type
C
ontext
Ref
interface
{
ReturnGas
(
*
big
.
Int
,
*
big
.
Int
)
Address
()
[]
byte
SetCode
([]
byte
)
}
type
C
losure
struct
{
caller
C
losure
Ref
object
C
losure
Ref
type
C
ontext
struct
{
caller
C
ontext
Ref
object
C
ontext
Ref
Code
[]
byte
message
*
state
.
Message
...
...
@@ -25,9 +25,9 @@ type Closure struct {
Args
[]
byte
}
// Create a new c
losure
for the given data items
func
NewC
losure
(
msg
*
state
.
Message
,
caller
ClosureRef
,
object
ClosureRef
,
code
[]
byte
,
gas
,
price
*
big
.
Int
)
*
Closure
{
c
:=
&
C
losure
{
message
:
msg
,
caller
:
caller
,
object
:
object
,
Code
:
code
,
Args
:
nil
}
// Create a new c
ontext
for the given data items
func
NewC
ontext
(
msg
*
state
.
Message
,
caller
ContextRef
,
object
ContextRef
,
code
[]
byte
,
gas
,
price
*
big
.
Int
)
*
Context
{
c
:=
&
C
ontext
{
message
:
msg
,
caller
:
caller
,
object
:
object
,
Code
:
code
,
Args
:
nil
}
// Gas should be a pointer so it can safely be reduced through the run
// This pointer will be off the state transition
...
...
@@ -40,11 +40,11 @@ func NewClosure(msg *state.Message, caller ClosureRef, object ClosureRef, code [
return
c
}
func
(
c
*
C
losure
)
GetOp
(
x
uint64
)
OpCode
{
func
(
c
*
C
ontext
)
GetOp
(
x
uint64
)
OpCode
{
return
OpCode
(
c
.
GetByte
(
x
))
}
func
(
c
*
C
losure
)
GetByte
(
x
uint64
)
byte
{
func
(
c
*
C
ontext
)
GetByte
(
x
uint64
)
byte
{
if
x
<
uint64
(
len
(
c
.
Code
))
{
return
c
.
Code
[
x
]
}
...
...
@@ -52,18 +52,18 @@ func (c *Closure) GetByte(x uint64) byte {
return
0
}
func
(
c
*
C
losure
)
GetBytes
(
x
,
y
int
)
[]
byte
{
func
(
c
*
C
ontext
)
GetBytes
(
x
,
y
int
)
[]
byte
{
return
c
.
GetRangeValue
(
uint64
(
x
),
uint64
(
y
))
}
func
(
c
*
C
losure
)
GetRangeValue
(
x
,
size
uint64
)
[]
byte
{
func
(
c
*
C
ontext
)
GetRangeValue
(
x
,
size
uint64
)
[]
byte
{
x
=
uint64
(
math
.
Min
(
float64
(
x
),
float64
(
len
(
c
.
Code
))))
y
:=
uint64
(
math
.
Min
(
float64
(
x
+
size
),
float64
(
len
(
c
.
Code
))))
return
ethutil
.
LeftPadBytes
(
c
.
Code
[
x
:
y
],
int
(
size
))
}
func
(
c
*
C
losure
)
Return
(
ret
[]
byte
)
[]
byte
{
func
(
c
*
C
ontext
)
Return
(
ret
[]
byte
)
[]
byte
{
// Return the remaining gas to the caller
c
.
caller
.
ReturnGas
(
c
.
Gas
,
c
.
Price
)
...
...
@@ -73,7 +73,7 @@ func (c *Closure) Return(ret []byte) []byte {
/*
* Gas functions
*/
func
(
c
*
C
losure
)
UseGas
(
gas
*
big
.
Int
)
bool
{
func
(
c
*
C
ontext
)
UseGas
(
gas
*
big
.
Int
)
bool
{
if
c
.
Gas
.
Cmp
(
gas
)
<
0
{
return
false
}
...
...
@@ -86,8 +86,8 @@ func (c *Closure) UseGas(gas *big.Int) bool {
}
// Implement the caller interface
func
(
c
*
C
losure
)
ReturnGas
(
gas
,
price
*
big
.
Int
)
{
// Return the gas to the c
losure
func
(
c
*
C
ontext
)
ReturnGas
(
gas
,
price
*
big
.
Int
)
{
// Return the gas to the c
ontext
c
.
Gas
.
Add
(
c
.
Gas
,
gas
)
c
.
UsedGas
.
Sub
(
c
.
UsedGas
,
gas
)
}
...
...
@@ -95,10 +95,10 @@ func (c *Closure) ReturnGas(gas, price *big.Int) {
/*
* Set / Get
*/
func
(
c
*
C
losure
)
Address
()
[]
byte
{
func
(
c
*
C
ontext
)
Address
()
[]
byte
{
return
c
.
object
.
Address
()
}
func
(
self
*
C
losure
)
SetCode
(
code
[]
byte
)
{
func
(
self
*
C
ontext
)
SetCode
(
code
[]
byte
)
{
self
.
Code
=
code
}
vm/environment.go
View file @
4dc7ee90
...
...
@@ -26,9 +26,9 @@ type Environment interface {
Depth
()
int
SetDepth
(
i
int
)
Call
(
me
C
losure
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
CallCode
(
me
C
losure
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
Create
(
me
C
losureRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
Closure
Ref
)
Call
(
me
C
ontext
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
CallCode
(
me
C
ontext
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
Create
(
me
C
ontextRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
Context
Ref
)
}
type
Object
interface
{
...
...
vm/virtual_machine.go
View file @
4dc7ee90
...
...
@@ -4,7 +4,7 @@ import "math/big"
type
VirtualMachine
interface
{
Env
()
Environment
Run
(
me
,
caller
C
losure
Ref
,
code
[]
byte
,
value
,
gas
,
price
*
big
.
Int
,
data
[]
byte
)
([]
byte
,
error
)
Run
(
me
,
caller
C
ontext
Ref
,
code
[]
byte
,
value
,
gas
,
price
*
big
.
Int
,
data
[]
byte
)
([]
byte
,
error
)
Printf
(
string
,
...
interface
{})
VirtualMachine
Endl
()
VirtualMachine
}
vm/vm.go
View file @
4dc7ee90
...
...
@@ -20,7 +20,7 @@ func New(env Environment, typ Type) VirtualMachine {
}
}
func
(
self
*
Vm
)
Run
(
me
,
caller
C
losure
Ref
,
code
[]
byte
,
value
,
gas
,
price
*
big
.
Int
,
data
[]
byte
)
(
ret
[]
byte
,
err
error
)
{
func
(
self
*
Vm
)
Run
(
me
,
caller
C
ontext
Ref
,
code
[]
byte
,
value
,
gas
,
price
*
big
.
Int
,
data
[]
byte
)
(
ret
[]
byte
,
err
error
)
{
panic
(
"not implemented"
)
}
...
...
vm/vm_debug.go
View file @
4dc7ee90
...
...
@@ -37,7 +37,7 @@ func NewDebugVm(env Environment) *DebugVm {
return
&
DebugVm
{
env
:
env
,
logTy
:
lt
,
Recoverable
:
true
}
}
func
(
self
*
DebugVm
)
Run
(
me
,
caller
C
losure
Ref
,
code
[]
byte
,
value
,
gas
,
price
*
big
.
Int
,
callData
[]
byte
)
(
ret
[]
byte
,
err
error
)
{
func
(
self
*
DebugVm
)
Run
(
me
,
caller
C
ontext
Ref
,
code
[]
byte
,
value
,
gas
,
price
*
big
.
Int
,
callData
[]
byte
)
(
ret
[]
byte
,
err
error
)
{
self
.
env
.
SetDepth
(
self
.
env
.
Depth
()
+
1
)
msg
:=
self
.
env
.
State
()
.
Manifest
()
.
AddMessage
(
&
state
.
Message
{
...
...
@@ -47,7 +47,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
Block
:
self
.
env
.
BlockHash
(),
Timestamp
:
self
.
env
.
Time
(),
Coinbase
:
self
.
env
.
Coinbase
(),
Number
:
self
.
env
.
BlockNumber
(),
Value
:
value
,
})
c
losure
:=
NewClosure
(
msg
,
caller
,
me
,
code
,
gas
,
price
)
c
ontext
:=
NewContext
(
msg
,
caller
,
me
,
code
,
gas
,
price
)
if
self
.
Recoverable
{
// Recover from any require exception
...
...
@@ -55,9 +55,9 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
if
r
:=
recover
();
r
!=
nil
{
self
.
Printf
(
" %v"
,
r
)
.
Endl
()
c
losure
.
UseGas
(
closure
.
Gas
)
c
ontext
.
UseGas
(
context
.
Gas
)
ret
=
c
losure
.
Return
(
nil
)
ret
=
c
ontext
.
Return
(
nil
)
err
=
fmt
.
Errorf
(
"%v"
,
r
)
...
...
@@ -66,13 +66,13 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
}
if
p
:=
Precompiled
[
string
(
me
.
Address
())];
p
!=
nil
{
return
self
.
RunPrecompiled
(
p
,
callData
,
c
losure
)
return
self
.
RunPrecompiled
(
p
,
callData
,
c
ontext
)
}
var
(
op
OpCode
destinations
=
analyseJumpDests
(
c
losure
.
Code
)
destinations
=
analyseJumpDests
(
c
ontext
.
Code
)
mem
=
NewMemory
()
stack
=
NewStack
()
pc
uint64
=
0
...
...
@@ -84,11 +84,19 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
p
:=
to
.
Uint64
()
self
.
Printf
(
" ~> %v"
,
to
)
/* NOTE: new model. Will change soon
nop := OpCode(context.GetOp(p))
if nop != JUMPDEST {
panic(fmt.Sprintf("invalid jump destination (%v) %v", nop, p))
}
pc = to.Uint64()
*/
// Return to start
if
p
==
0
{
pc
=
0
}
else
{
nop
:=
OpCode
(
c
losure
.
GetOp
(
p
))
nop
:=
OpCode
(
c
ontext
.
GetOp
(
p
))
if
!
(
nop
==
JUMPDEST
||
destinations
[
from
]
!=
nil
)
{
panic
(
fmt
.
Sprintf
(
"invalid jump destination (%v) %v"
,
nop
,
p
))
}
else
if
nop
==
JUMP
||
nop
==
JUMPI
{
...
...
@@ -103,11 +111,11 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
}
)
vmlogger
.
Debugf
(
"(%d) (%x) %x (code=%d) gas: %v (d) %x
\n
"
,
self
.
env
.
Depth
(),
caller
.
Address
()[
:
4
],
c
losure
.
Address
(),
len
(
code
),
closure
.
Gas
,
callData
)
vmlogger
.
Debugf
(
"(%d) (%x) %x (code=%d) gas: %v (d) %x
\n
"
,
self
.
env
.
Depth
(),
caller
.
Address
()[
:
4
],
c
ontext
.
Address
(),
len
(
code
),
context
.
Gas
,
callData
)
// Don't bother with the execution if there's no code.
if
len
(
code
)
==
0
{
return
c
losure
.
Return
(
nil
),
nil
return
c
ontext
.
Return
(
nil
),
nil
}
for
{
...
...
@@ -117,22 +125,22 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
step
++
// Get the memory location of pc
op
=
c
losure
.
GetOp
(
pc
)
op
=
c
ontext
.
GetOp
(
pc
)
self
.
Printf
(
"(pc) %-3d -o- %-14s (m) %-4d (s) %-4d "
,
pc
,
op
.
String
(),
mem
.
Len
(),
stack
.
Len
())
newMemSize
,
gas
:=
self
.
calculateGasAndSize
(
c
losure
,
caller
,
op
,
statedb
,
mem
,
stack
)
newMemSize
,
gas
:=
self
.
calculateGasAndSize
(
c
ontext
,
caller
,
op
,
statedb
,
mem
,
stack
)
self
.
Printf
(
"(g) %-3v (%v)"
,
gas
,
c
losure
.
Gas
)
self
.
Printf
(
"(g) %-3v (%v)"
,
gas
,
c
ontext
.
Gas
)
if
!
c
losure
.
UseGas
(
gas
)
{
if
!
c
ontext
.
UseGas
(
gas
)
{
self
.
Endl
()
tmp
:=
new
(
big
.
Int
)
.
Set
(
c
losure
.
Gas
)
tmp
:=
new
(
big
.
Int
)
.
Set
(
c
ontext
.
Gas
)
c
losure
.
UseGas
(
closure
.
Gas
)
c
ontext
.
UseGas
(
context
.
Gas
)
return
c
losure
.
Return
(
nil
),
OOG
(
gas
,
tmp
)
return
c
ontext
.
Return
(
nil
),
OOG
(
gas
,
tmp
)
}
mem
.
Resize
(
newMemSize
.
Uint64
())
...
...
@@ -410,9 +418,9 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
self
.
Printf
(
" => %x"
,
data
)
// 0x30 range
case
ADDRESS
:
stack
.
Push
(
ethutil
.
BigD
(
c
losure
.
Address
()))
stack
.
Push
(
ethutil
.
BigD
(
c
ontext
.
Address
()))
self
.
Printf
(
" => %x"
,
c
losure
.
Address
())
self
.
Printf
(
" => %x"
,
c
ontext
.
Address
())
case
BALANCE
:
addr
:=
stack
.
Pop
()
.
Bytes
()
...
...
@@ -428,7 +436,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
self
.
Printf
(
" => %x"
,
origin
)
case
CALLER
:
caller
:=
c
losure
.
caller
.
Address
()
caller
:=
c
ontext
.
caller
.
Address
()
stack
.
Push
(
ethutil
.
BigD
(
caller
))
self
.
Printf
(
" => %x"
,
caller
)
...
...
@@ -485,7 +493,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
code
=
statedb
.
GetCode
(
addr
)
}
else
{
code
=
c
losure
.
Code
code
=
c
ontext
.
Code
}
l
:=
big
.
NewInt
(
int64
(
len
(
code
)))
...
...
@@ -497,7 +505,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
if
op
==
EXTCODECOPY
{
code
=
statedb
.
GetCode
(
stack
.
Pop
()
.
Bytes
())
}
else
{
code
=
c
losure
.
Code
code
=
c
ontext
.
Code
}
var
(
...
...
@@ -519,9 +527,9 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
self
.
Printf
(
" => [%v, %v, %v] %x"
,
mOff
,
cOff
,
l
,
codeCopy
)
case
GASPRICE
:
stack
.
Push
(
c
losure
.
Price
)
stack
.
Push
(
c
ontext
.
Price
)
self
.
Printf
(
" => %v"
,
c
losure
.
Price
)
self
.
Printf
(
" => %v"
,
c
ontext
.
Price
)
// 0x40 range
case
PREVHASH
:
...
...
@@ -560,7 +568,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
// 0x50 range
case
PUSH1
,
PUSH2
,
PUSH3
,
PUSH4
,
PUSH5
,
PUSH6
,
PUSH7
,
PUSH8
,
PUSH9
,
PUSH10
,
PUSH11
,
PUSH12
,
PUSH13
,
PUSH14
,
PUSH15
,
PUSH16
,
PUSH17
,
PUSH18
,
PUSH19
,
PUSH20
,
PUSH21
,
PUSH22
,
PUSH23
,
PUSH24
,
PUSH25
,
PUSH26
,
PUSH27
,
PUSH28
,
PUSH29
,
PUSH30
,
PUSH31
,
PUSH32
:
a
:=
uint64
(
op
-
PUSH1
+
1
)
byts
:=
c
losure
.
GetRangeValue
(
pc
+
1
,
a
)
byts
:=
c
ontext
.
GetRangeValue
(
pc
+
1
,
a
)
// Push value to stack
stack
.
Push
(
ethutil
.
BigD
(
byts
))
pc
+=
a
...
...
@@ -589,7 +597,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
}
data
:=
mem
.
Geti
(
mStart
.
Int64
(),
mSize
.
Int64
())
log
:=
&
Log
{
c
losure
.
Address
(),
topics
,
data
}
log
:=
&
Log
{
c
ontext
.
Address
(),
topics
,
data
}
self
.
env
.
AddLog
(
log
)
self
.
Printf
(
" => %v"
,
log
)
...
...
@@ -614,15 +622,15 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
self
.
Printf
(
" => [%v] 0x%x"
,
off
,
val
)
case
SLOAD
:
loc
:=
stack
.
Pop
()
val
:=
ethutil
.
BigD
(
statedb
.
GetState
(
c
losure
.
Address
(),
loc
.
Bytes
()))
val
:=
ethutil
.
BigD
(
statedb
.
GetState
(
c
ontext
.
Address
(),
loc
.
Bytes
()))
stack
.
Push
(
val
)
self
.
Printf
(
" {0x%x : 0x%x}"
,
loc
.
Bytes
(),
val
.
Bytes
())
case
SSTORE
:
val
,
loc
:=
stack
.
Popn
()
statedb
.
SetState
(
c
losure
.
Address
(),
loc
.
Bytes
(),
val
)
statedb
.
SetState
(
c
ontext
.
Address
(),
loc
.
Bytes
(),
val
)
c
losure
.
message
.
AddStorageChange
(
loc
.
Bytes
())
c
ontext
.
message
.
AddStorageChange
(
loc
.
Bytes
())
self
.
Printf
(
" {0x%x : 0x%x}"
,
loc
.
Bytes
(),
val
.
Bytes
())
case
JUMP
:
...
...
@@ -644,7 +652,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
case
MSIZE
:
stack
.
Push
(
big
.
NewInt
(
int64
(
mem
.
Len
())))
case
GAS
:
stack
.
Push
(
c
losure
.
Gas
)
stack
.
Push
(
c
ontext
.
Gas
)
// 0x60 range
case
CREATE
:
...
...
@@ -653,7 +661,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
value
=
stack
.
Pop
()
size
,
offset
=
stack
.
Popn
()
input
=
mem
.
Get
(
offset
.
Int64
(),
size
.
Int64
())
gas
=
new
(
big
.
Int
)
.
Set
(
c
losure
.
Gas
)
gas
=
new
(
big
.
Int
)
.
Set
(
c
ontext
.
Gas
)
// Snapshot the current stack so we are able to
// revert back to it later.
...
...
@@ -661,15 +669,15 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
)
// Generate a new address
n
:=
statedb
.
GetNonce
(
c
losure
.
Address
())
addr
:=
crypto
.
CreateAddress
(
c
losure
.
Address
(),
n
)
statedb
.
SetNonce
(
c
losure
.
Address
(),
n
+
1
)
n
:=
statedb
.
GetNonce
(
c
ontext
.
Address
())
addr
:=
crypto
.
CreateAddress
(
c
ontext
.
Address
(),
n
)
statedb
.
SetNonce
(
c
ontext
.
Address
(),
n
+
1
)
self
.
Printf
(
" (*) %x"
,
addr
)
.
Endl
()
c
losure
.
UseGas
(
closure
.
Gas
)
c
ontext
.
UseGas
(
context
.
Gas
)
ret
,
err
,
ref
:=
self
.
env
.
Create
(
c
losure
,
addr
,
input
,
gas
,
price
,
value
)
ret
,
err
,
ref
:=
self
.
env
.
Create
(
c
ontext
,
addr
,
input
,
gas
,
price
,
value
)
if
err
!=
nil
{
stack
.
Push
(
ethutil
.
BigFalse
)
...
...
@@ -678,7 +686,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
// gas < len(ret) * CreateDataGas == NO_CODE
dataGas
:=
big
.
NewInt
(
int64
(
len
(
ret
)))
dataGas
.
Mul
(
dataGas
,
GasCreateByte
)
if
c
losure
.
UseGas
(
dataGas
)
{
if
c
ontext
.
UseGas
(
dataGas
)
{
ref
.
SetCode
(
ret
)
msg
.
Output
=
ret
}
...
...
@@ -690,7 +698,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
// Debug hook
if
self
.
Dbg
!=
nil
{
self
.
Dbg
.
SetCode
(
c
losure
.
Code
)
self
.
Dbg
.
SetCode
(
c
ontext
.
Code
)
}
case
CALL
,
CALLCODE
:
self
.
Endl
()
...
...
@@ -711,9 +719,9 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
err
error
)
if
op
==
CALLCODE
{
ret
,
err
=
self
.
env
.
CallCode
(
c
losure
,
addr
.
Bytes
(),
args
,
gas
,
price
,
value
)
ret
,
err
=
self
.
env
.
CallCode
(
c
ontext
,
addr
.
Bytes
(),
args
,
gas
,
price
,
value
)
}
else
{
ret
,
err
=
self
.
env
.
Call
(
c
losure
,
addr
.
Bytes
(),
args
,
gas
,
price
,
value
)
ret
,
err
=
self
.
env
.
Call
(
c
ontext
,
addr
.
Bytes
(),
args
,
gas
,
price
,
value
)
}
if
err
!=
nil
{
...
...
@@ -726,11 +734,11 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
mem
.
Set
(
retOffset
.
Uint64
(),
retSize
.
Uint64
(),
ret
)
}
self
.
Printf
(
"resume %x (%v)"
,
c
losure
.
Address
(),
closure
.
Gas
)
self
.
Printf
(
"resume %x (%v)"
,
c
ontext
.
Address
(),
context
.
Gas
)
// Debug hook
if
self
.
Dbg
!=
nil
{
self
.
Dbg
.
SetCode
(
c
losure
.
Code
)
self
.
Dbg
.
SetCode
(
c
ontext
.
Code
)
}
case
RETURN
:
...
...
@@ -739,27 +747,27 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
self
.
Printf
(
" => [%v, %v] (%d) 0x%x"
,
offset
,
size
,
len
(
ret
),
ret
)
.
Endl
()
return
c
losure
.
Return
(
ret
),
nil
return
c
ontext
.
Return
(
ret
),
nil
case
SUICIDE
:
receiver
:=
statedb
.
GetOrNewStateObject
(
stack
.
Pop
()
.
Bytes
())
balance
:=
statedb
.
GetBalance
(
c
losure
.
Address
())
balance
:=
statedb
.
GetBalance
(
c
ontext
.
Address
())
self
.
Printf
(
" => (%x) %v"
,
receiver
.
Address
()[
:
4
],
balance
)
receiver
.
AddAmount
(
balance
)
statedb
.
Delete
(
c
losure
.
Address
())
statedb
.
Delete
(
c
ontext
.
Address
())
fallthrough
case
STOP
:
// Stop the c
losure
case
STOP
:
// Stop the c
ontext
self
.
Endl
()
return
c
losure
.
Return
(
nil
),
nil
return
c
ontext
.
Return
(
nil
),
nil
default
:
vmlogger
.
Debugf
(
"(pc) %-3v Invalid opcode %x
\n
"
,
pc
,
op
)
c
losure
.
ReturnGas
(
big
.
NewInt
(
1
),
nil
)
c
ontext
.
ReturnGas
(
big
.
NewInt
(
1
),
nil
)
return
c
losure
.
Return
(
nil
),
fmt
.
Errorf
(
"Invalid opcode %x"
,
op
)
return
c
ontext
.
Return
(
nil
),
fmt
.
Errorf
(
"Invalid opcode %x"
,
op
)
}
pc
++
...
...
@@ -771,11 +779,11 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
if
pc
==
uint64
(
instrNo
)
{
self
.
Stepping
=
true
if
!
self
.
Dbg
.
BreakHook
(
prevStep
,
op
,
mem
,
stack
,
statedb
.
GetStateObject
(
c
losure
.
Address
()))
{
if
!
self
.
Dbg
.
BreakHook
(
prevStep
,
op
,
mem
,
stack
,
statedb
.
GetStateObject
(
c
ontext
.
Address
()))
{
return
nil
,
nil
}
}
else
if
self
.
Stepping
{
if
!
self
.
Dbg
.
StepHook
(
prevStep
,
op
,
mem
,
stack
,
statedb
.
GetStateObject
(
c
losure
.
Address
()))
{
if
!
self
.
Dbg
.
StepHook
(
prevStep
,
op
,
mem
,
stack
,
statedb
.
GetStateObject
(
c
ontext
.
Address
()))
{
return
nil
,
nil
}
}
...
...
@@ -785,7 +793,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
}
}
func
(
self
*
DebugVm
)
calculateGasAndSize
(
c
losure
*
Closure
,
caller
Closure
Ref
,
op
OpCode
,
statedb
*
state
.
StateDB
,
mem
*
Memory
,
stack
*
Stack
)
(
*
big
.
Int
,
*
big
.
Int
)
{
func
(
self
*
DebugVm
)
calculateGasAndSize
(
c
ontext
*
Context
,
caller
Context
Ref
,
op
OpCode
,
statedb
*
state
.
StateDB
,
mem
*
Memory
,
stack
*
Stack
)
(
*
big
.
Int
,
*
big
.
Int
)
{
gas
:=
new
(
big
.
Int
)
addStepGasUsage
:=
func
(
amount
*
big
.
Int
)
{
if
amount
.
Cmp
(
ethutil
.
Big0
)
>=
0
{
...
...
@@ -844,7 +852,7 @@ func (self *DebugVm) calculateGasAndSize(closure *Closure, caller ClosureRef, op
var
mult
*
big
.
Int
y
,
x
:=
stack
.
Peekn
()
val
:=
statedb
.
GetState
(
c
losure
.
Address
(),
x
.
Bytes
())
val
:=
statedb
.
GetState
(
c
ontext
.
Address
(),
x
.
Bytes
())
if
len
(
val
)
==
0
&&
len
(
y
.
Bytes
())
>
0
{
// 0 => non 0
mult
=
ethutil
.
Big3
...
...
@@ -940,22 +948,22 @@ func (self *DebugVm) calculateGasAndSize(closure *Closure, caller ClosureRef, op
return
newMemSize
,
gas
}
func
(
self
*
DebugVm
)
RunPrecompiled
(
p
*
PrecompiledAccount
,
callData
[]
byte
,
c
losure
*
Closure
)
(
ret
[]
byte
,
err
error
)
{
func
(
self
*
DebugVm
)
RunPrecompiled
(
p
*
PrecompiledAccount
,
callData
[]
byte
,
c
ontext
*
Context
)
(
ret
[]
byte
,
err
error
)
{
gas
:=
p
.
Gas
(
len
(
callData
))
if
c
losure
.
UseGas
(
gas
)
{
if
c
ontext
.
UseGas
(
gas
)
{
ret
=
p
.
Call
(
callData
)
self
.
Printf
(
"NATIVE_FUNC => %x"
,
ret
)
self
.
Endl
()
return
c
losure
.
Return
(
ret
),
nil
return
c
ontext
.
Return
(
ret
),
nil
}
else
{
self
.
Endl
()
tmp
:=
new
(
big
.
Int
)
.
Set
(
c
losure
.
Gas
)
tmp
:=
new
(
big
.
Int
)
.
Set
(
c
ontext
.
Gas
)
c
losure
.
UseGas
(
closure
.
Gas
)
c
ontext
.
UseGas
(
context
.
Gas
)
return
c
losure
.
Return
(
nil
),
OOG
(
gas
,
tmp
)
return
c
ontext
.
Return
(
nil
),
OOG
(
gas
,
tmp
)
}
}
...
...
xeth/vm_env.go
View file @
4dc7ee90
...
...
@@ -50,16 +50,16 @@ func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execu
return
core
.
NewExecution
(
self
,
addr
,
data
,
gas
,
price
,
value
)
}
func
(
self
*
VMEnv
)
Call
(
me
vm
.
C
losure
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
func
(
self
*
VMEnv
)
Call
(
me
vm
.
C
ontext
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
exe
:=
self
.
vm
(
addr
,
data
,
gas
,
price
,
value
)
return
exe
.
Call
(
addr
,
me
)
}
func
(
self
*
VMEnv
)
CallCode
(
me
vm
.
C
losure
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
func
(
self
*
VMEnv
)
CallCode
(
me
vm
.
C
ontext
Ref
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
)
{
exe
:=
self
.
vm
(
me
.
Address
(),
data
,
gas
,
price
,
value
)
return
exe
.
Call
(
addr
,
me
)
}
func
(
self
*
VMEnv
)
Create
(
me
vm
.
C
losureRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
vm
.
Closure
Ref
)
{
func
(
self
*
VMEnv
)
Create
(
me
vm
.
C
ontextRef
,
addr
,
data
[]
byte
,
gas
,
price
,
value
*
big
.
Int
)
([]
byte
,
error
,
vm
.
Context
Ref
)
{
exe
:=
self
.
vm
(
addr
,
data
,
gas
,
price
,
value
)
return
exe
.
Create
(
me
)
}
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