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
490ca410
Commit
490ca410
authored
Jul 22, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor improvements and fixes to the new vm structure
parent
1e8b54ab
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
18 additions
and
24 deletions
+18
-24
asm.go
ethchain/asm.go
+2
-2
vm.go
ethchain/vm.go
+3
-2
state_object.go
ethstate/state_object.go
+1
-1
asm.go
ethvm/asm.go
+2
-2
vm.go
ethvm/vm.go
+2
-6
vm_test.go
ethvm/vm_test.go
+8
-11
No files found.
ethchain/asm.go
View file @
490ca410
...
@@ -25,7 +25,7 @@ func Disassemble(script []byte) (asm []string) {
...
@@ -25,7 +25,7 @@ func Disassemble(script []byte) (asm []string) {
pc
.
Add
(
pc
,
ethutil
.
Big1
)
pc
.
Add
(
pc
,
ethutil
.
Big1
)
a
:=
int64
(
op
)
-
int64
(
PUSH1
)
+
1
a
:=
int64
(
op
)
-
int64
(
PUSH1
)
+
1
if
int
(
pc
.
Int64
()
+
a
)
>
len
(
script
)
{
if
int
(
pc
.
Int64
()
+
a
)
>
len
(
script
)
{
return
nil
return
}
}
data
:=
script
[
pc
.
Int64
()
:
pc
.
Int64
()
+
a
]
data
:=
script
[
pc
.
Int64
()
:
pc
.
Int64
()
+
a
]
...
@@ -40,5 +40,5 @@ func Disassemble(script []byte) (asm []string) {
...
@@ -40,5 +40,5 @@ func Disassemble(script []byte) (asm []string) {
pc
.
Add
(
pc
,
ethutil
.
Big1
)
pc
.
Add
(
pc
,
ethutil
.
Big1
)
}
}
return
return
asm
}
}
ethchain/vm.go
View file @
490ca410
...
@@ -563,10 +563,9 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -563,10 +563,9 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
}
}
code
:=
closure
.
Script
[
cOff
:
cOff
+
l
]
code
:=
closure
.
Script
[
cOff
:
cOff
+
l
]
//
fmt.Println("len:", l, "code off:", cOff, "mem off:", mOff)
fmt
.
Println
(
"len:"
,
l
,
"code off:"
,
cOff
,
"mem off:"
,
mOff
)
mem
.
Set
(
mOff
,
l
,
code
)
mem
.
Set
(
mOff
,
l
,
code
)
//fmt.Println(Code(mem.Get(mOff, l)))
case
GASPRICE
:
case
GASPRICE
:
stack
.
Push
(
closure
.
Price
)
stack
.
Push
(
closure
.
Price
)
...
@@ -673,6 +672,8 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -673,6 +672,8 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
stack
.
Push
(
pc
)
stack
.
Push
(
pc
)
case
MSIZE
:
case
MSIZE
:
stack
.
Push
(
big
.
NewInt
(
int64
(
mem
.
Len
())))
stack
.
Push
(
big
.
NewInt
(
int64
(
mem
.
Len
())))
vm
.
Printf
(
" => %v"
,
mem
.
Len
())
.
Endl
()
case
GAS
:
case
GAS
:
stack
.
Push
(
closure
.
Gas
)
stack
.
Push
(
closure
.
Gas
)
// 0x60 range
// 0x60 range
...
...
ethstate/state_object.go
View file @
490ca410
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
type
Code
[]
byte
type
Code
[]
byte
func
(
self
Code
)
String
()
string
{
func
(
self
Code
)
String
()
string
{
return
""
//strings.Join(Disassemble(self), " ")
return
string
(
self
)
//strings.Join(Disassemble(self), " ")
}
}
type
Storage
map
[
string
]
*
ethutil
.
Value
type
Storage
map
[
string
]
*
ethutil
.
Value
...
...
ethvm/asm.go
View file @
490ca410
...
@@ -18,7 +18,7 @@ func Disassemble(script []byte) (asm []string) {
...
@@ -18,7 +18,7 @@ func Disassemble(script []byte) (asm []string) {
// Get the opcode (it must be an opcode!)
// Get the opcode (it must be an opcode!)
op
:=
OpCode
(
val
)
op
:=
OpCode
(
val
)
asm
=
append
(
asm
,
fmt
.
Sprintf
(
"%
04v: %v"
,
pc
,
op
))
asm
=
append
(
asm
,
fmt
.
Sprintf
(
"%
v"
,
op
))
switch
op
{
switch
op
{
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
:
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
:
...
@@ -32,7 +32,7 @@ func Disassemble(script []byte) (asm []string) {
...
@@ -32,7 +32,7 @@ func Disassemble(script []byte) (asm []string) {
if
len
(
data
)
==
0
{
if
len
(
data
)
==
0
{
data
=
[]
byte
{
0
}
data
=
[]
byte
{
0
}
}
}
asm
=
append
(
asm
,
fmt
.
Sprintf
(
"
%04v: 0x%x"
,
pc
,
data
))
asm
=
append
(
asm
,
fmt
.
Sprintf
(
"
0x%x"
,
data
))
pc
.
Add
(
pc
,
big
.
NewInt
(
a
-
1
))
pc
.
Add
(
pc
,
big
.
NewInt
(
a
-
1
))
}
}
...
...
ethvm/vm.go
View file @
490ca410
...
@@ -48,7 +48,6 @@ type Environment interface {
...
@@ -48,7 +48,6 @@ type Environment interface {
Coinbase
()
[]
byte
Coinbase
()
[]
byte
Time
()
int64
Time
()
int64
Difficulty
()
*
big
.
Int
Difficulty
()
*
big
.
Int
Data
()
[]
string
Value
()
*
big
.
Int
Value
()
*
big
.
Int
}
}
...
@@ -420,7 +419,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -420,7 +419,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
require
(
2
)
require
(
2
)
val
,
th
:=
stack
.
Popn
()
val
,
th
:=
stack
.
Popn
()
if
th
.
Cmp
(
big
.
NewInt
(
32
))
<
0
&&
th
.
Cmp
(
big
.
NewInt
(
int64
(
len
(
val
.
Bytes
()))))
<
0
{
if
th
.
Cmp
(
big
.
NewInt
(
32
))
<
0
&&
th
.
Cmp
(
big
.
NewInt
(
int64
(
len
(
val
.
Bytes
()))))
<
0
{
byt
:=
big
.
NewInt
(
int64
(
val
.
Bytes
(
)[
th
.
Int64
()]))
byt
:=
big
.
NewInt
(
int64
(
ethutil
.
LeftPadBytes
(
val
.
Bytes
(),
32
)[
th
.
Int64
()]))
stack
.
Push
(
byt
)
stack
.
Push
(
byt
)
self
.
Printf
(
" => 0x%x"
,
byt
.
Bytes
())
self
.
Printf
(
" => 0x%x"
,
byt
.
Bytes
())
...
@@ -530,10 +529,8 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -530,10 +529,8 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
}
}
code
:=
closure
.
Code
[
cOff
:
cOff
+
l
]
code
:=
closure
.
Code
[
cOff
:
cOff
+
l
]
//fmt.Println("len:", l, "code off:", cOff, "mem off:", mOff)
mem
.
Set
(
mOff
,
l
,
code
)
mem
.
Set
(
mOff
,
l
,
code
)
//fmt.Println(Code(mem.Get(mOff, l)))
case
GASPRICE
:
case
GASPRICE
:
stack
.
Push
(
closure
.
Price
)
stack
.
Push
(
closure
.
Price
)
...
@@ -638,7 +635,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -638,7 +635,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
// Add the change to manifest
// Add the change to manifest
self
.
env
.
State
()
.
Manifest
()
.
AddStorageChange
(
closure
.
Object
(),
loc
.
Bytes
(),
val
)
self
.
env
.
State
()
.
Manifest
()
.
AddStorageChange
(
closure
.
Object
(),
loc
.
Bytes
(),
val
)
self
.
Printf
(
" {0x%x : 0x%x}"
,
loc
,
val
)
self
.
Printf
(
" {0x%x : 0x%x}"
,
loc
.
Bytes
(),
val
.
Bytes
()
)
case
JUMP
:
case
JUMP
:
require
(
1
)
require
(
1
)
pc
=
stack
.
Pop
()
pc
=
stack
.
Pop
()
...
@@ -802,7 +799,6 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -802,7 +799,6 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
return
closure
.
Return
(
nil
),
nil
return
closure
.
Return
(
nil
),
nil
default
:
default
:
vmlogger
.
Debugf
(
"(pc) %-3v Invalid opcode %x
\n
"
,
pc
,
op
)
vmlogger
.
Debugf
(
"(pc) %-3v Invalid opcode %x
\n
"
,
pc
,
op
)
fmt
.
Println
(
ethstate
.
Code
(
closure
.
Code
))
return
closure
.
Return
(
nil
),
fmt
.
Errorf
(
"Invalid opcode %x"
,
op
)
return
closure
.
Return
(
nil
),
fmt
.
Errorf
(
"Invalid opcode %x"
,
op
)
}
}
...
...
ethvm/vm_test.go
View file @
490ca410
...
@@ -15,17 +15,14 @@ import (
...
@@ -15,17 +15,14 @@ import (
type
TestEnv
struct
{
type
TestEnv
struct
{
}
}
func
(
self
TestEnv
)
GetObject
()
Object
{
return
nil
}
func
(
self
TestEnv
)
Origin
()
[]
byte
{
return
nil
}
func
(
self
TestEnv
)
Origin
()
[]
byte
{
return
nil
}
func
(
self
TestEnv
)
BlockNumber
()
*
big
.
Int
{
return
nil
}
func
(
self
TestEnv
)
BlockNumber
()
*
big
.
Int
{
return
nil
}
func
(
self
TestEnv
)
PrevHash
()
[]
byte
{
return
nil
}
func
(
self
TestEnv
)
PrevHash
()
[]
byte
{
return
nil
}
func
(
self
TestEnv
)
Coinbase
()
[]
byte
{
return
nil
}
func
(
self
TestEnv
)
Coinbase
()
[]
byte
{
return
nil
}
func
(
self
TestEnv
)
Time
()
int64
{
return
0
}
func
(
self
TestEnv
)
Time
()
int64
{
return
0
}
func
(
self
TestEnv
)
Difficulty
()
*
big
.
Int
{
return
nil
}
func
(
self
TestEnv
)
Difficulty
()
*
big
.
Int
{
return
nil
}
func
(
self
TestEnv
)
Value
()
*
big
.
Int
{
return
nil
}
func
(
self
TestEnv
)
Data
()
[]
string
{
return
nil
}
func
(
self
TestEnv
)
State
()
*
ethstate
.
State
{
return
nil
}
func
(
self
TestEnv
)
Value
()
*
big
.
Int
{
return
nil
}
func
(
self
TestEnv
)
GetBalance
(
addr
[]
byte
)
*
big
.
Int
{
return
nil
}
func
(
self
TestEnv
)
State
()
*
ethstate
.
State
{
return
nil
}
func
TestVm
(
t
*
testing
.
T
)
{
func
TestVm
(
t
*
testing
.
T
)
{
ethlog
.
AddLogSystem
(
ethlog
.
NewStdLogSystem
(
os
.
Stdout
,
log
.
LstdFlags
,
ethlog
.
LogLevel
(
4
)))
ethlog
.
AddLogSystem
(
ethlog
.
NewStdLogSystem
(
os
.
Stdout
,
log
.
LstdFlags
,
ethlog
.
LogLevel
(
4
)))
...
...
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