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
3d9a4e70
Commit
3d9a4e70
authored
Dec 03, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed mem error in vm. Fixed logs tests
parent
f7789220
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
59 additions
and
24 deletions
+59
-24
bloom9.go
chain/bloom9.go
+2
-2
main.go
cmd/ethereum/main.go
+1
-1
main.go
cmd/mist/main.go
+1
-1
vm.go
tests/helper/vm.go
+11
-6
gh_test.go
tests/vm/gh_test.go
+32
-8
stack.go
vm/stack.go
+1
-2
types.go
vm/types.go
+5
-0
vm_debug.go
vm/vm_debug.go
+6
-4
No files found.
chain/bloom9.go
View file @
3d9a4e70
...
...
@@ -11,13 +11,13 @@ import (
func
CreateBloom
(
receipts
Receipts
)
[]
byte
{
bin
:=
new
(
big
.
Int
)
for
_
,
receipt
:=
range
receipts
{
bin
.
Or
(
bin
,
l
ogsBloom
(
receipt
.
logs
))
bin
.
Or
(
bin
,
L
ogsBloom
(
receipt
.
logs
))
}
return
ethutil
.
LeftPadBytes
(
bin
.
Bytes
(),
64
)
}
func
l
ogsBloom
(
logs
state
.
Logs
)
*
big
.
Int
{
func
L
ogsBloom
(
logs
state
.
Logs
)
*
big
.
Int
{
bin
:=
new
(
big
.
Int
)
for
_
,
log
:=
range
logs
{
data
:=
[][]
byte
{
log
.
Address
}
...
...
cmd/ethereum/main.go
View file @
3d9a4e70
...
...
@@ -30,7 +30,7 @@ import (
const
(
ClientIdentifier
=
"Ethereum(G)"
Version
=
"0.7.
6
"
Version
=
"0.7.
7
"
)
var
clilogger
=
logger
.
NewLogger
(
"CLI"
)
...
...
cmd/mist/main.go
View file @
3d9a4e70
...
...
@@ -31,7 +31,7 @@ import (
const
(
ClientIdentifier
=
"Mist"
Version
=
"0.7.
6
"
Version
=
"0.7.
7
"
)
var
ethereum
*
eth
.
Ethereum
...
...
tests/helper/vm.go
View file @
3d9a4e70
...
...
@@ -20,6 +20,8 @@ type Env struct {
time
int64
difficulty
*
big
.
Int
gasLimit
*
big
.
Int
logs
state
.
Logs
}
func
NewEnv
(
state
*
state
.
State
)
*
Env
{
...
...
@@ -51,24 +53,27 @@ func (self *Env) Difficulty() *big.Int { return self.difficulty }
func
(
self
*
Env
)
BlockHash
()
[]
byte
{
return
nil
}
func
(
self
*
Env
)
State
()
*
state
.
State
{
return
self
.
state
}
func
(
self
*
Env
)
GasLimit
()
*
big
.
Int
{
return
self
.
gasLimit
}
func
(
self
*
Env
)
AddLog
(
*
state
.
Log
)
{}
func
(
self
*
Env
)
AddLog
(
log
*
state
.
Log
)
{
self
.
logs
=
append
(
self
.
logs
,
log
)
}
func
(
self
*
Env
)
Transfer
(
from
,
to
vm
.
Account
,
amount
*
big
.
Int
)
error
{
return
vm
.
Transfer
(
from
,
to
,
amount
)
}
func
RunVm
(
state
*
state
.
State
,
env
,
exec
map
[
string
]
string
)
([]
byte
,
*
big
.
Int
,
error
)
{
func
RunVm
(
state
*
state
.
State
,
env
,
exec
map
[
string
]
string
)
([]
byte
,
state
.
Logs
,
*
big
.
Int
,
error
)
{
address
:=
FromHex
(
exec
[
"address"
])
caller
:=
state
.
GetOrNewStateObject
(
FromHex
(
exec
[
"caller"
]))
evm
:=
vm
.
New
(
NewEnvFromMap
(
state
,
env
,
exec
),
vm
.
DebugVmTy
)
vmenv
:=
NewEnvFromMap
(
state
,
env
,
exec
)
evm
:=
vm
.
New
(
vmenv
,
vm
.
DebugVmTy
)
execution
:=
vm
.
NewExecution
(
evm
,
address
,
FromHex
(
exec
[
"data"
]),
ethutil
.
Big
(
exec
[
"gas"
]),
ethutil
.
Big
(
exec
[
"gasPrice"
]),
ethutil
.
Big
(
exec
[
"value"
]))
execution
.
SkipTransfer
=
true
ret
,
err
:=
execution
.
Exec
(
address
,
caller
)
return
ret
,
execution
.
Gas
,
err
return
ret
,
vmenv
.
logs
,
execution
.
Gas
,
err
}
func
RunState
(
state
*
state
.
State
,
env
,
tx
map
[
string
]
string
)
([]
byte
,
*
big
.
Int
,
error
)
{
func
RunState
(
state
*
state
.
State
,
env
,
tx
map
[
string
]
string
)
([]
byte
,
state
.
Logs
,
*
big
.
Int
,
error
)
{
address
:=
FromHex
(
tx
[
"to"
])
keyPair
,
_
:=
crypto
.
NewKeyPairFromSec
([]
byte
(
ethutil
.
Hex2Bytes
(
tx
[
"secretKey"
])))
caller
:=
state
.
GetOrNewStateObject
(
keyPair
.
Address
())
...
...
@@ -79,5 +84,5 @@ func RunState(state *state.State, env, tx map[string]string) ([]byte, *big.Int,
execution
:=
vm
.
NewExecution
(
evm
,
address
,
FromHex
(
tx
[
"data"
]),
ethutil
.
Big
(
tx
[
"gasLimit"
]),
ethutil
.
Big
(
tx
[
"gasPrice"
]),
ethutil
.
Big
(
tx
[
"value"
]))
ret
,
err
:=
execution
.
Exec
(
address
,
caller
)
return
ret
,
execution
.
Gas
,
err
return
ret
,
vmenv
.
logs
,
execution
.
Gas
,
err
}
tests/vm/gh_test.go
View file @
3d9a4e70
...
...
@@ -6,6 +6,7 @@ import (
"strconv"
"testing"
"github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/tests/helper"
...
...
@@ -18,6 +19,12 @@ type Account struct {
Storage
map
[
string
]
string
}
type
Log
struct
{
Address
string
Data
string
Topics
[]
string
}
func
StateObjectFromAccount
(
addr
string
,
account
Account
)
*
state
.
StateObject
{
obj
:=
state
.
NewStateObject
(
ethutil
.
Hex2Bytes
(
addr
))
obj
.
SetBalance
(
ethutil
.
Big
(
account
.
Balance
))
...
...
@@ -46,6 +53,7 @@ type VmTest struct {
Env
Env
Exec
map
[
string
]
string
Transaction
map
[
string
]
string
Logs
map
[
string
]
Log
Gas
string
Out
string
Post
map
[
string
]
Account
...
...
@@ -57,10 +65,10 @@ func RunVmTest(p string, t *testing.T) {
helper
.
CreateFileTests
(
t
,
p
,
&
tests
)
for
name
,
test
:=
range
tests
{
state
:=
state
.
New
(
helper
.
NewTrie
())
state
db
:=
state
.
New
(
helper
.
NewTrie
())
for
addr
,
account
:=
range
test
.
Pre
{
obj
:=
StateObjectFromAccount
(
addr
,
account
)
state
.
SetStateObject
(
obj
)
state
db
.
SetStateObject
(
obj
)
}
// XXX Yeah, yeah...
...
...
@@ -77,15 +85,16 @@ func RunVmTest(p string, t *testing.T) {
}
var
(
ret
[]
byte
gas
*
big
.
Int
err
error
ret
[]
byte
gas
*
big
.
Int
err
error
logs
state
.
Logs
)
if
len
(
test
.
Exec
)
>
0
{
ret
,
gas
,
err
=
helper
.
RunVm
(
state
,
env
,
test
.
Exec
)
ret
,
logs
,
gas
,
err
=
helper
.
RunVm
(
statedb
,
env
,
test
.
Exec
)
}
else
{
ret
,
gas
,
err
=
helper
.
RunState
(
state
,
env
,
test
.
Transaction
)
ret
,
logs
,
gas
,
err
=
helper
.
RunState
(
statedb
,
env
,
test
.
Transaction
)
}
// When an error is returned it doesn't always mean the tests fails.
...
...
@@ -107,7 +116,7 @@ func RunVmTest(p string, t *testing.T) {
}
for
addr
,
account
:=
range
test
.
Post
{
obj
:=
state
.
GetStateObject
(
helper
.
FromHex
(
addr
))
obj
:=
state
db
.
GetStateObject
(
helper
.
FromHex
(
addr
))
for
addr
,
value
:=
range
account
.
Storage
{
v
:=
obj
.
GetState
(
helper
.
FromHex
(
addr
))
.
Bytes
()
vexp
:=
helper
.
FromHex
(
value
)
...
...
@@ -117,6 +126,16 @@ func RunVmTest(p string, t *testing.T) {
}
}
}
if
len
(
test
.
Logs
)
>
0
{
genBloom
:=
ethutil
.
LeftPadBytes
(
chain
.
LogsBloom
(
logs
)
.
Bytes
(),
64
)
// Logs within the test itself aren't correct, missing empty fields (32 0s)
for
bloom
/*logs*/
,
_
:=
range
test
.
Logs
{
if
!
bytes
.
Equal
(
genBloom
,
ethutil
.
Hex2Bytes
(
bloom
))
{
t
.
Errorf
(
"bloom mismatch"
)
}
}
}
}
}
...
...
@@ -161,6 +180,11 @@ func TestVm(t *testing.T) {
RunVmTest
(
fn
,
t
)
}
func
TestVmLog
(
t
*
testing
.
T
)
{
const
fn
=
"../files/vmtests/vmLogTest.json"
RunVmTest
(
fn
,
t
)
}
func
TestStateSystemOperations
(
t
*
testing
.
T
)
{
const
fn
=
"../files/StateTests/stSystemOperationsTest.json"
RunVmTest
(
fn
,
t
)
...
...
vm/stack.go
View file @
3d9a4e70
...
...
@@ -147,9 +147,8 @@ func (m *Memory) Get(offset, size int64) []byte {
func
(
self
*
Memory
)
Geti
(
offset
,
size
int64
)
(
cpy
[]
byte
)
{
if
len
(
self
.
store
)
>
int
(
offset
)
{
s
:=
int64
(
math
.
Min
(
float64
(
len
(
self
.
store
)),
float64
(
offset
+
size
)))
cpy
=
make
([]
byte
,
size
)
copy
(
cpy
,
self
.
store
[
offset
:
offset
+
s
])
copy
(
cpy
,
self
.
store
[
offset
:
offset
+
s
ize
])
return
}
...
...
vm/types.go
View file @
3d9a4e70
...
...
@@ -308,6 +308,11 @@ var opCodeToString = map[OpCode]string{
SWAP14
:
"SWAP14"
,
SWAP15
:
"SWAP15"
,
SWAP16
:
"SWAP16"
,
LOG0
:
"LOG0"
,
LOG1
:
"LOG1"
,
LOG2
:
"LOG2"
,
LOG3
:
"LOG3"
,
LOG4
:
"LOG4"
,
// 0xf0 range
CREATE
:
"CREATE"
,
...
...
vm/vm_debug.go
View file @
3d9a4e70
...
...
@@ -35,7 +35,7 @@ func NewDebugVm(env Environment) *DebugVm {
lt
=
LogTyDiff
}
return
&
DebugVm
{
env
:
env
,
logTy
:
lt
,
Recoverable
:
tru
e
}
return
&
DebugVm
{
env
:
env
,
logTy
:
lt
,
Recoverable
:
fals
e
}
}
func
(
self
*
DebugVm
)
RunClosure
(
closure
*
Closure
)
(
ret
[]
byte
,
err
error
)
{
...
...
@@ -168,8 +168,10 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
gas
.
Set
(
GasLog
)
addStepGasUsage
(
new
(
big
.
Int
)
.
Mul
(
big
.
NewInt
(
int64
(
n
)),
GasLog
))
mSize
,
_
:=
stack
.
Peekn
()
mSize
,
mStart
:=
stack
.
Peekn
()
addStepGasUsage
(
mSize
)
newMemSize
=
calcMemSize
(
mStart
,
mSize
)
case
EXP
:
require
(
2
)
...
...
@@ -755,10 +757,10 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
case
LOG0
,
LOG1
,
LOG2
,
LOG3
,
LOG4
:
n
:=
int
(
op
-
LOG0
)
topics
:=
make
([][]
byte
,
n
)
mS
tart
,
mSize
:=
stack
.
Pop
()
.
Int64
(),
stack
.
Pop
()
.
Int64
()
mS
ize
,
mStart
:=
stack
.
Pop
()
.
Int64
(),
stack
.
Pop
()
.
Int64
()
data
:=
mem
.
Geti
(
mStart
,
mSize
)
for
i
:=
0
;
i
<
n
;
i
++
{
topics
[
i
]
=
stack
.
Pop
()
.
Bytes
(
)
topics
[
i
]
=
ethutil
.
LeftPadBytes
(
stack
.
Pop
()
.
Bytes
(),
32
)
}
log
:=
&
state
.
Log
{
closure
.
Address
(),
topics
,
data
}
...
...
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