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
311c6f8a
Commit
311c6f8a
authored
Oct 15, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed remote Arithmetic tests
parent
266d2120
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
187 additions
and
100 deletions
+187
-100
state_transition.go
ethchain/state_transition.go
+2
-1
state.go
ethstate/state.go
+9
-0
state_object.go
ethstate/state_object.go
+4
-6
big.go
ethutil/big.go
+20
-9
common.go
ethvm/common.go
+2
-1
vm.go
ethvm/vm.go
+45
-20
vm_debug.go
ethvm/vm_debug.go
+73
-44
http.go
tests/helper/http.go
+6
-5
init.go
tests/helper/init.go
+4
-1
vm.go
tests/helper/vm.go
+2
-6
gh_test.go
tests/vm/gh_test.go
+20
-7
No files found.
ethchain/state_transition.go
View file @
311c6f8a
...
@@ -270,7 +270,8 @@ func (self *StateTransition) Eval(msg *ethstate.Message, script []byte, context
...
@@ -270,7 +270,8 @@ func (self *StateTransition) Eval(msg *ethstate.Message, script []byte, context
callerClosure
=
ethvm
.
NewClosure
(
msg
,
transactor
,
context
,
script
,
self
.
gas
,
self
.
gasPrice
)
callerClosure
=
ethvm
.
NewClosure
(
msg
,
transactor
,
context
,
script
,
self
.
gas
,
self
.
gasPrice
)
)
)
vm
:=
ethvm
.
New
(
env
,
ethvm
.
Type
(
ethutil
.
Config
.
VmType
))
//vm := ethvm.New(env, ethvm.Type(ethutil.Config.VmType))
vm
:=
ethutil
.
New
(
env
,
ethvm
.
DebugVmTy
)
ret
,
_
,
err
=
callerClosure
.
Call
(
vm
,
self
.
tx
.
Data
)
ret
,
_
,
err
=
callerClosure
.
Call
(
vm
,
self
.
tx
.
Data
)
...
...
ethstate/state.go
View file @
311c6f8a
...
@@ -57,6 +57,15 @@ func (self *State) GetCode(addr []byte) []byte {
...
@@ -57,6 +57,15 @@ func (self *State) GetCode(addr []byte) []byte {
return
nil
return
nil
}
}
func
(
self
*
State
)
GetState
(
a
,
b
[]
byte
)
[]
byte
{
stateObject
:=
self
.
GetStateObject
(
a
)
if
stateObject
!=
nil
{
return
stateObject
.
GetState
(
b
)
.
Bytes
()
}
return
nil
}
//
//
// Setting, updating & deleting state object methods
// Setting, updating & deleting state object methods
//
//
...
...
ethstate/state_object.go
View file @
311c6f8a
...
@@ -98,13 +98,13 @@ func (c *StateObject) SetAddr(addr []byte, value interface{}) {
...
@@ -98,13 +98,13 @@ func (c *StateObject) SetAddr(addr []byte, value interface{}) {
}
}
func
(
self
*
StateObject
)
GetStorage
(
key
*
big
.
Int
)
*
ethutil
.
Value
{
func
(
self
*
StateObject
)
GetStorage
(
key
*
big
.
Int
)
*
ethutil
.
Value
{
return
self
.
getStorag
e
(
key
.
Bytes
())
return
self
.
GetStat
e
(
key
.
Bytes
())
}
}
func
(
self
*
StateObject
)
SetStorage
(
key
*
big
.
Int
,
value
*
ethutil
.
Value
)
{
func
(
self
*
StateObject
)
SetStorage
(
key
*
big
.
Int
,
value
*
ethutil
.
Value
)
{
self
.
setStorag
e
(
key
.
Bytes
(),
value
)
self
.
SetStat
e
(
key
.
Bytes
(),
value
)
}
}
func
(
self
*
StateObject
)
getStorag
e
(
k
[]
byte
)
*
ethutil
.
Value
{
func
(
self
*
StateObject
)
GetStat
e
(
k
[]
byte
)
*
ethutil
.
Value
{
key
:=
ethutil
.
LeftPadBytes
(
k
,
32
)
key
:=
ethutil
.
LeftPadBytes
(
k
,
32
)
value
:=
self
.
storage
[
string
(
key
)]
value
:=
self
.
storage
[
string
(
key
)]
...
@@ -117,11 +117,9 @@ func (self *StateObject) getStorage(k []byte) *ethutil.Value {
...
@@ -117,11 +117,9 @@ func (self *StateObject) getStorage(k []byte) *ethutil.Value {
}
}
return
value
return
value
//return self.GetAddr(key)
}
}
func
(
self
*
StateObject
)
setStorag
e
(
k
[]
byte
,
value
*
ethutil
.
Value
)
{
func
(
self
*
StateObject
)
SetStat
e
(
k
[]
byte
,
value
*
ethutil
.
Value
)
{
key
:=
ethutil
.
LeftPadBytes
(
k
,
32
)
key
:=
ethutil
.
LeftPadBytes
(
k
,
32
)
self
.
storage
[
string
(
key
)]
=
value
.
Copy
()
self
.
storage
[
string
(
key
)]
=
value
.
Copy
()
}
}
...
...
ethutil/big.go
View file @
311c6f8a
package
ethutil
package
ethutil
import
(
import
"math/big"
"math/big"
)
var
MaxInt256
*
big
.
Int
=
BigD
(
Hex2Bytes
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
)
)
// Big pow
// Big pow
//
//
...
@@ -37,16 +37,27 @@ func BigD(data []byte) *big.Int {
...
@@ -37,16 +37,27 @@ func BigD(data []byte) *big.Int {
// To256
// To256
//
//
// "cast" the big int to a 256 big int (i.e., limit to)
// "cast" the big int to a 256 big int (i.e., limit to)
var
tt256
=
new
(
big
.
Int
)
.
Sub
(
new
(
big
.
Int
)
.
Lsh
(
big
.
NewInt
(
1
),
256
),
big
.
NewInt
(
1
))
var
tt256
=
new
(
big
.
Int
)
.
Lsh
(
big
.
NewInt
(
1
),
256
)
var
tt256m1
=
new
(
big
.
Int
)
.
Sub
(
new
(
big
.
Int
)
.
Lsh
(
big
.
NewInt
(
1
),
256
),
big
.
NewInt
(
1
))
var
tt255
=
new
(
big
.
Int
)
.
Lsh
(
big
.
NewInt
(
1
),
255
)
func
To256
(
x
*
big
.
Int
)
*
big
.
Int
{
func
U256
(
x
*
big
.
Int
)
*
big
.
Int
{
x
.
And
(
x
,
tt256
)
//if x.Cmp(Big0) < 0 {
// return new(big.Int).Add(tt256, x)
// }
if
x
.
Cmp
(
new
(
big
.
Int
))
<
0
{
x
.
And
(
x
,
tt256m1
)
x
.
SetInt64
(
0
)
}
return
x
}
func
S256
(
x
*
big
.
Int
)
*
big
.
Int
{
if
x
.
Cmp
(
tt255
)
<
0
{
return
x
return
x
}
else
{
// We don't want to modify x, ever
return
new
(
big
.
Int
)
.
Sub
(
x
,
tt256
)
}
}
}
// Big to bytes
// Big to bytes
...
...
ethvm/common.go
View file @
311c6f8a
...
@@ -35,7 +35,8 @@ var (
...
@@ -35,7 +35,8 @@ var (
LogTyPretty
byte
=
0x1
LogTyPretty
byte
=
0x1
LogTyDiff
byte
=
0x2
LogTyDiff
byte
=
0x2
To256
=
ethutil
.
To256
U256
=
ethutil
.
U256
S256
=
ethutil
.
S256
)
)
const
MaxCallDepth
=
1024
const
MaxCallDepth
=
1024
...
...
ethvm/vm.go
View file @
311c6f8a
...
@@ -8,6 +8,9 @@ import (
...
@@ -8,6 +8,9 @@ import (
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
)
)
// BIG FAT WARNING. THIS VM IS NOT YET IS USE!
// I want to get all VM tests pass first before updating this VM
type
Vm
struct
{
type
Vm
struct
{
env
Environment
env
Environment
err
error
err
error
...
@@ -170,7 +173,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -170,7 +173,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Add
(
y
,
x
)
base
.
Add
(
y
,
x
)
To
256
(
base
)
U
256
(
base
)
// Pop result back on the stack
// Pop result back on the stack
stack
.
Push
(
base
)
stack
.
Push
(
base
)
...
@@ -180,7 +183,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -180,7 +183,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Sub
(
y
,
x
)
base
.
Sub
(
y
,
x
)
To
256
(
base
)
U
256
(
base
)
// Pop result back on the stack
// Pop result back on the stack
stack
.
Push
(
base
)
stack
.
Push
(
base
)
...
@@ -190,7 +193,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -190,7 +193,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Mul
(
y
,
x
)
base
.
Mul
(
y
,
x
)
To
256
(
base
)
U
256
(
base
)
// Pop result back on the stack
// Pop result back on the stack
stack
.
Push
(
base
)
stack
.
Push
(
base
)
...
@@ -202,21 +205,29 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -202,21 +205,29 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Div
(
y
,
x
)
base
.
Div
(
y
,
x
)
}
}
To
256
(
base
)
U
256
(
base
)
// Pop result back on the stack
// Pop result back on the stack
stack
.
Push
(
base
)
stack
.
Push
(
base
)
case
SDIV
:
case
SDIV
:
require
(
2
)
require
(
2
)
x
,
y
:=
stack
.
Popn
(
)
y
,
x
:=
S256
(
stack
.
Pop
()),
S256
(
stack
.
Pop
()
)
if
x
.
Cmp
(
ethutil
.
Big0
)
!=
0
{
if
x
.
Cmp
(
ethutil
.
Big0
)
==
0
{
base
.
Div
(
y
,
x
)
base
.
Set
(
ethutil
.
Big0
)
}
else
{
n
:=
new
(
big
.
Int
)
if
new
(
big
.
Int
)
.
Mul
(
y
,
x
)
.
Cmp
(
ethutil
.
Big0
)
<
0
{
n
.
SetInt64
(
-
1
)
}
else
{
n
.
SetInt64
(
1
)
}
}
To256
(
base
)
base
.
Div
(
y
.
Abs
(
y
),
x
.
Mul
(
x
.
Abs
(
x
),
n
))
U256
(
base
)
}
// Pop result back on the stack
stack
.
Push
(
base
)
stack
.
Push
(
base
)
case
MOD
:
case
MOD
:
require
(
2
)
require
(
2
)
...
@@ -224,16 +235,27 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -224,16 +235,27 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Mod
(
y
,
x
)
base
.
Mod
(
y
,
x
)
To
256
(
base
)
U
256
(
base
)
stack
.
Push
(
base
)
stack
.
Push
(
base
)
case
SMOD
:
case
SMOD
:
require
(
2
)
require
(
2
)
x
,
y
:=
stack
.
Popn
(
)
y
,
x
:=
S256
(
stack
.
Pop
()),
S256
(
stack
.
Pop
()
)
base
.
Mod
(
y
,
x
)
if
x
.
Cmp
(
ethutil
.
Big0
)
==
0
{
base
.
Set
(
ethutil
.
Big0
)
}
else
{
n
:=
new
(
big
.
Int
)
if
y
.
Cmp
(
ethutil
.
Big0
)
<
0
{
n
.
SetInt64
(
-
1
)
}
else
{
n
.
SetInt64
(
1
)
}
To256
(
base
)
base
.
Mod
(
y
.
Abs
(
y
),
x
.
Mul
(
x
.
Abs
(
x
),
n
))
U256
(
base
)
}
stack
.
Push
(
base
)
stack
.
Push
(
base
)
...
@@ -243,12 +265,15 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -243,12 +265,15 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Exp
(
y
,
x
,
Pow256
)
base
.
Exp
(
y
,
x
,
Pow256
)
To
256
(
base
)
U
256
(
base
)
stack
.
Push
(
base
)
stack
.
Push
(
base
)
case
NEG
:
case
NEG
:
require
(
1
)
require
(
1
)
base
.
Sub
(
Pow256
,
stack
.
Pop
())
base
.
Sub
(
Pow256
,
stack
.
Pop
())
base
=
U256
(
base
)
stack
.
Push
(
base
)
stack
.
Push
(
base
)
case
LT
:
case
LT
:
require
(
2
)
require
(
2
)
...
@@ -272,16 +297,16 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -272,16 +297,16 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
case
SLT
:
case
SLT
:
require
(
2
)
require
(
2
)
x
,
y
:=
stack
.
Popn
(
)
y
,
x
:=
S256
(
stack
.
Pop
()),
S256
(
stack
.
Pop
()
)
// x < y
// x < y
if
y
.
Cmp
(
x
)
<
0
{
if
y
.
Cmp
(
S256
(
x
)
)
<
0
{
stack
.
Push
(
ethutil
.
BigTrue
)
stack
.
Push
(
ethutil
.
BigTrue
)
}
else
{
}
else
{
stack
.
Push
(
ethutil
.
BigFalse
)
stack
.
Push
(
ethutil
.
BigFalse
)
}
}
case
SGT
:
case
SGT
:
require
(
2
)
require
(
2
)
x
,
y
:=
stack
.
Popn
(
)
y
,
x
:=
S256
(
stack
.
Pop
()),
S256
(
stack
.
Pop
()
)
// x > y
// x > y
if
y
.
Cmp
(
x
)
>
0
{
if
y
.
Cmp
(
x
)
>
0
{
...
@@ -345,7 +370,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -345,7 +370,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Add
(
x
,
y
)
base
.
Add
(
x
,
y
)
base
.
Mod
(
base
,
z
)
base
.
Mod
(
base
,
z
)
To
256
(
base
)
U
256
(
base
)
stack
.
Push
(
base
)
stack
.
Push
(
base
)
case
MULMOD
:
case
MULMOD
:
...
@@ -358,7 +383,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -358,7 +383,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Mul
(
x
,
y
)
base
.
Mul
(
x
,
y
)
base
.
Mod
(
base
,
z
)
base
.
Mod
(
base
,
z
)
To
256
(
base
)
U
256
(
base
)
stack
.
Push
(
base
)
stack
.
Push
(
base
)
...
...
ethvm/vm_debug.go
View file @
311c6f8a
...
@@ -40,10 +40,27 @@ func NewDebugVm(env Environment) *DebugVm {
...
@@ -40,10 +40,27 @@ func NewDebugVm(env Environment) *DebugVm {
func
(
self
*
DebugVm
)
RunClosure
(
closure
*
Closure
)
(
ret
[]
byte
,
err
error
)
{
func
(
self
*
DebugVm
)
RunClosure
(
closure
*
Closure
)
(
ret
[]
byte
,
err
error
)
{
self
.
depth
++
self
.
depth
++
var
(
op
OpCode
mem
=
&
Memory
{}
stack
=
NewStack
()
pc
=
big
.
NewInt
(
0
)
step
=
0
prevStep
=
0
require
=
func
(
m
int
)
{
if
stack
.
Len
()
<
m
{
panic
(
fmt
.
Sprintf
(
"%04v (%v) stack err size = %d, required = %d"
,
pc
,
op
,
stack
.
Len
(),
m
))
}
}
)
if
self
.
Recoverable
{
if
self
.
Recoverable
{
// Recover from any require exception
// Recover from any require exception
defer
func
()
{
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
if
r
:=
recover
();
r
!=
nil
{
self
.
Endl
()
ret
=
closure
.
Return
(
nil
)
ret
=
closure
.
Return
(
nil
)
err
=
fmt
.
Errorf
(
"%v"
,
r
)
err
=
fmt
.
Errorf
(
"%v"
,
r
)
}
}
...
@@ -62,21 +79,6 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -62,21 +79,6 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
vmlogger
.
Debugf
(
"(%s) %x gas: %v (d) %x
\n
"
,
self
.
Fn
,
closure
.
Address
(),
closure
.
Gas
,
closure
.
Args
)
vmlogger
.
Debugf
(
"(%s) %x gas: %v (d) %x
\n
"
,
self
.
Fn
,
closure
.
Address
(),
closure
.
Gas
,
closure
.
Args
)
var
(
op
OpCode
mem
=
&
Memory
{}
stack
=
NewStack
()
pc
=
big
.
NewInt
(
0
)
step
=
0
prevStep
=
0
require
=
func
(
m
int
)
{
if
stack
.
Len
()
<
m
{
panic
(
fmt
.
Sprintf
(
"%04v (%v) stack err size = %d, required = %d"
,
pc
,
op
,
stack
.
Len
(),
m
))
}
}
)
for
{
for
{
prevStep
=
step
prevStep
=
step
// The base for all big integer arithmetic
// The base for all big integer arithmetic
...
@@ -223,7 +225,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -223,7 +225,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Add
(
y
,
x
)
base
.
Add
(
y
,
x
)
To
256
(
base
)
U
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
self
.
Printf
(
" = %v"
,
base
)
// Pop result back on the stack
// Pop result back on the stack
...
@@ -235,7 +237,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -235,7 +237,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Sub
(
y
,
x
)
base
.
Sub
(
y
,
x
)
To
256
(
base
)
U
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
self
.
Printf
(
" = %v"
,
base
)
// Pop result back on the stack
// Pop result back on the stack
...
@@ -247,60 +249,84 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -247,60 +249,84 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Mul
(
y
,
x
)
base
.
Mul
(
y
,
x
)
To
256
(
base
)
U
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
self
.
Printf
(
" = %v"
,
base
)
// Pop result back on the stack
// Pop result back on the stack
stack
.
Push
(
base
)
stack
.
Push
(
base
)
case
DIV
:
case
DIV
:
require
(
2
)
require
(
2
)
x
,
y
:=
stack
.
Pop
n
()
x
,
y
:=
stack
.
Pop
(),
stack
.
Pop
()
self
.
Printf
(
" %v / %v"
,
y
,
x
)
self
.
Printf
(
" %v / %v"
,
x
,
y
)
if
x
.
Cmp
(
ethutil
.
Big0
)
!=
0
{
if
y
.
Cmp
(
ethutil
.
Big0
)
!=
0
{
base
.
Div
(
y
,
x
)
base
.
Div
(
x
,
y
)
}
}
To
256
(
base
)
U
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
self
.
Printf
(
" = %v"
,
base
)
// Pop result back on the stack
// Pop result back on the stack
stack
.
Push
(
base
)
stack
.
Push
(
base
)
case
SDIV
:
case
SDIV
:
require
(
2
)
require
(
2
)
x
,
y
:=
stack
.
Popn
()
x
,
y
:=
S256
(
stack
.
Pop
()),
S256
(
stack
.
Pop
())
self
.
Printf
(
" %v / %v"
,
y
,
x
)
if
x
.
Cmp
(
ethutil
.
Big0
)
!=
0
{
self
.
Printf
(
" %v / %v"
,
x
,
y
)
base
.
Div
(
y
,
x
)
if
y
.
Cmp
(
ethutil
.
Big0
)
==
0
{
base
.
Set
(
ethutil
.
Big0
)
}
else
{
n
:=
new
(
big
.
Int
)
if
new
(
big
.
Int
)
.
Mul
(
x
,
y
)
.
Cmp
(
ethutil
.
Big0
)
<
0
{
n
.
SetInt64
(
-
1
)
}
else
{
n
.
SetInt64
(
1
)
}
}
To256
(
base
)
base
.
Div
(
x
.
Abs
(
x
),
y
.
Abs
(
y
))
.
Mul
(
base
,
n
)
U256
(
base
)
}
self
.
Printf
(
" = %v"
,
base
)
self
.
Printf
(
" = %v"
,
base
)
// Pop result back on the stack
stack
.
Push
(
base
)
stack
.
Push
(
base
)
case
MOD
:
case
MOD
:
require
(
2
)
require
(
2
)
x
,
y
:=
stack
.
Pop
n
()
x
,
y
:=
stack
.
Pop
(),
stack
.
Pop
()
self
.
Printf
(
" %v %% %v"
,
y
,
x
)
self
.
Printf
(
" %v %% %v"
,
x
,
y
)
base
.
Mod
(
y
,
x
)
if
y
.
Cmp
(
ethutil
.
Big0
)
==
0
{
base
.
Set
(
ethutil
.
Big0
)
}
else
{
base
.
Mod
(
x
,
y
)
}
To
256
(
base
)
U
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
self
.
Printf
(
" = %v"
,
base
)
stack
.
Push
(
base
)
stack
.
Push
(
base
)
case
SMOD
:
case
SMOD
:
require
(
2
)
require
(
2
)
x
,
y
:=
stack
.
Popn
(
)
x
,
y
:=
S256
(
stack
.
Pop
()),
S256
(
stack
.
Pop
()
)
self
.
Printf
(
" %v %% %v"
,
y
,
x
)
self
.
Printf
(
" %v %% %v"
,
x
,
y
)
base
.
Mod
(
y
,
x
)
if
y
.
Cmp
(
ethutil
.
Big0
)
==
0
{
base
.
Set
(
ethutil
.
Big0
)
}
else
{
n
:=
new
(
big
.
Int
)
if
x
.
Cmp
(
ethutil
.
Big0
)
<
0
{
n
.
SetInt64
(
-
1
)
}
else
{
n
.
SetInt64
(
1
)
}
To256
(
base
)
base
.
Mod
(
x
.
Abs
(
x
),
y
.
Abs
(
y
))
.
Mul
(
base
,
n
)
U256
(
base
)
}
self
.
Printf
(
" = %v"
,
base
)
self
.
Printf
(
" = %v"
,
base
)
stack
.
Push
(
base
)
stack
.
Push
(
base
)
...
@@ -313,7 +339,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -313,7 +339,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Exp
(
y
,
x
,
Pow256
)
base
.
Exp
(
y
,
x
,
Pow256
)
To
256
(
base
)
U
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
self
.
Printf
(
" = %v"
,
base
)
...
@@ -321,6 +347,9 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -321,6 +347,9 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
case
NEG
:
case
NEG
:
require
(
1
)
require
(
1
)
base
.
Sub
(
Pow256
,
stack
.
Pop
())
base
.
Sub
(
Pow256
,
stack
.
Pop
())
base
=
U256
(
base
)
stack
.
Push
(
base
)
stack
.
Push
(
base
)
case
LT
:
case
LT
:
require
(
2
)
require
(
2
)
...
@@ -346,17 +375,17 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -346,17 +375,17 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
case
SLT
:
case
SLT
:
require
(
2
)
require
(
2
)
x
,
y
:=
stack
.
Popn
(
)
y
,
x
:=
S256
(
stack
.
Pop
()),
S256
(
stack
.
Pop
()
)
self
.
Printf
(
" %v < %v"
,
y
,
x
)
self
.
Printf
(
" %v < %v"
,
y
,
x
)
// x < y
// x < y
if
y
.
Cmp
(
x
)
<
0
{
if
y
.
Cmp
(
S256
(
x
)
)
<
0
{
stack
.
Push
(
ethutil
.
BigTrue
)
stack
.
Push
(
ethutil
.
BigTrue
)
}
else
{
}
else
{
stack
.
Push
(
ethutil
.
BigFalse
)
stack
.
Push
(
ethutil
.
BigFalse
)
}
}
case
SGT
:
case
SGT
:
require
(
2
)
require
(
2
)
x
,
y
:=
stack
.
Popn
(
)
y
,
x
:=
S256
(
stack
.
Pop
()),
S256
(
stack
.
Pop
()
)
self
.
Printf
(
" %v > %v"
,
y
,
x
)
self
.
Printf
(
" %v > %v"
,
y
,
x
)
// x > y
// x > y
...
@@ -426,7 +455,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -426,7 +455,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Add
(
x
,
y
)
base
.
Add
(
x
,
y
)
base
.
Mod
(
base
,
z
)
base
.
Mod
(
base
,
z
)
To
256
(
base
)
U
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
self
.
Printf
(
" = %v"
,
base
)
...
@@ -441,7 +470,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -441,7 +470,7 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Mul
(
x
,
y
)
base
.
Mul
(
x
,
y
)
base
.
Mod
(
base
,
z
)
base
.
Mod
(
base
,
z
)
To
256
(
base
)
U
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
self
.
Printf
(
" = %v"
,
base
)
...
...
tests/helper/http.go
View file @
311c6f8a
...
@@ -4,12 +4,15 @@ import (
...
@@ -4,12 +4,15 @@ import (
"encoding/json"
"encoding/json"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"testing"
)
)
func
CreateTests
(
uri
string
,
value
interface
{})
error
{
func
CreateTests
(
t
*
testing
.
T
,
uri
string
,
value
interface
{})
{
resp
,
err
:=
http
.
Get
(
uri
)
resp
,
err
:=
http
.
Get
(
uri
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
t
.
Error
(
err
)
return
}
}
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
...
@@ -17,8 +20,6 @@ func CreateTests(uri string, value interface{}) error {
...
@@ -17,8 +20,6 @@ func CreateTests(uri string, value interface{}) error {
err
=
json
.
Unmarshal
(
data
,
&
value
)
err
=
json
.
Unmarshal
(
data
,
&
value
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
t
.
Error
(
err
)
}
}
return
nil
}
}
tests/helper/init.go
View file @
311c6f8a
...
@@ -8,8 +8,11 @@ import (
...
@@ -8,8 +8,11 @@ import (
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
)
)
var
Logger
ethlog
.
LogSystem
func
init
()
{
func
init
()
{
ethlog
.
AddLogSystem
(
ethlog
.
NewStdLogSystem
(
os
.
Stdout
,
log
.
LstdFlags
,
ethlog
.
LogLevel
(
4
)))
Logger
=
ethlog
.
NewStdLogSystem
(
os
.
Stdout
,
log
.
LstdFlags
,
ethlog
.
LogLevel
(
4
))
ethlog
.
AddLogSystem
(
Logger
)
ethutil
.
ReadConfig
(
".ethtest"
,
"/tmp/ethtest"
,
""
)
ethutil
.
ReadConfig
(
".ethtest"
,
"/tmp/ethtest"
,
""
)
}
}
tests/helper/vm.go
View file @
311c6f8a
package
helper
package
helper
import
(
import
(
"fmt"
"math/big"
"math/big"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethstate"
...
@@ -51,16 +50,13 @@ func (self *Env) BlockHash() []byte { return nil }
...
@@ -51,16 +50,13 @@ func (self *Env) BlockHash() []byte { return nil }
// This is likely to fail if anything ever gets looked up in the state trie :-)
// This is likely to fail if anything ever gets looked up in the state trie :-)
func
(
self
*
Env
)
State
()
*
ethstate
.
State
{
return
ethstate
.
New
(
ethtrie
.
New
(
nil
,
""
))
}
func
(
self
*
Env
)
State
()
*
ethstate
.
State
{
return
ethstate
.
New
(
ethtrie
.
New
(
nil
,
""
))
}
func
RunVm
(
state
*
ethstate
.
State
,
env
,
exec
map
[
string
]
string
)
([]
byte
,
*
big
.
Int
)
{
func
RunVm
(
state
*
ethstate
.
State
,
env
,
exec
map
[
string
]
string
)
([]
byte
,
*
big
.
Int
,
error
)
{
caller
:=
state
.
NewStateObject
(
ethutil
.
Hex2Bytes
(
exec
[
"caller"
]))
caller
:=
state
.
NewStateObject
(
ethutil
.
Hex2Bytes
(
exec
[
"caller"
]))
callee
:=
state
.
GetStateObject
(
ethutil
.
Hex2Bytes
(
exec
[
"address"
]))
callee
:=
state
.
GetStateObject
(
ethutil
.
Hex2Bytes
(
exec
[
"address"
]))
closure
:=
ethvm
.
NewClosure
(
nil
,
caller
,
callee
,
callee
.
Code
,
ethutil
.
Big
(
exec
[
"gas"
]),
ethutil
.
Big
(
exec
[
"gasPrice"
]))
closure
:=
ethvm
.
NewClosure
(
nil
,
caller
,
callee
,
callee
.
Code
,
ethutil
.
Big
(
exec
[
"gas"
]),
ethutil
.
Big
(
exec
[
"gasPrice"
]))
vm
:=
ethvm
.
New
(
NewEnvFromMap
(
state
,
env
,
exec
),
ethvm
.
DebugVmTy
)
vm
:=
ethvm
.
New
(
NewEnvFromMap
(
state
,
env
,
exec
),
ethvm
.
DebugVmTy
)
ret
,
_
,
e
:=
closure
.
Call
(
vm
,
nil
)
ret
,
_
,
e
:=
closure
.
Call
(
vm
,
nil
)
if
e
!=
nil
{
fmt
.
Println
(
e
)
}
return
ret
,
closure
.
Gas
return
ret
,
closure
.
Gas
,
e
}
}
tests/vm/gh_test.go
View file @
311c6f8a
...
@@ -2,7 +2,6 @@ package ethvm
...
@@ -2,7 +2,6 @@ package ethvm
import
(
import
(
"bytes"
"bytes"
"log"
"testing"
"testing"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethstate"
...
@@ -40,12 +39,9 @@ type VmTest struct {
...
@@ -40,12 +39,9 @@ type VmTest struct {
Pre
map
[
string
]
Account
Pre
map
[
string
]
Account
}
}
func
TestRemote
(
t
*
testing
.
T
)
{
func
RunVmTest
(
url
string
,
t
*
testing
.
T
)
{
tests
:=
make
(
map
[
string
]
VmTest
)
tests
:=
make
(
map
[
string
]
VmTest
)
err
:=
helper
.
CreateTests
(
"https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmSha3Test.json"
,
&
tests
)
helper
.
CreateTests
(
t
,
url
,
&
tests
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
for
name
,
test
:=
range
tests
{
for
name
,
test
:=
range
tests
{
state
:=
ethstate
.
New
(
helper
.
NewTrie
())
state
:=
ethstate
.
New
(
helper
.
NewTrie
())
...
@@ -54,7 +50,10 @@ func TestRemote(t *testing.T) {
...
@@ -54,7 +50,10 @@ func TestRemote(t *testing.T) {
state
.
SetStateObject
(
obj
)
state
.
SetStateObject
(
obj
)
}
}
ret
,
gas
:=
helper
.
RunVm
(
state
,
test
.
Env
,
test
.
Exec
)
ret
,
gas
,
err
:=
helper
.
RunVm
(
state
,
test
.
Env
,
test
.
Exec
)
if
err
!=
nil
{
t
.
Errorf
(
"%s's execution failed. %v
\n
"
,
name
,
err
)
}
rexp
:=
helper
.
FromHex
(
test
.
Out
)
rexp
:=
helper
.
FromHex
(
test
.
Out
)
if
bytes
.
Compare
(
rexp
,
ret
)
!=
0
{
if
bytes
.
Compare
(
rexp
,
ret
)
!=
0
{
...
@@ -79,3 +78,17 @@ func TestRemote(t *testing.T) {
...
@@ -79,3 +78,17 @@ func TestRemote(t *testing.T) {
}
}
}
}
}
}
// I've created a new function for each tests so it's easier to identify where the problem lies if any of them fail.
func
TestVMSha3
(
t
*
testing
.
T
)
{
helper
.
Logger
.
SetLogLevel
(
0
)
defer
helper
.
Logger
.
SetLogLevel
(
4
)
const
url
=
"https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmSha3Test.json"
RunVmTest
(
url
,
t
)
}
func
TestVMArithmetic
(
t
*
testing
.
T
)
{
const
url
=
"https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmArithmeticTest.json"
RunVmTest
(
url
,
t
)
}
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