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
6095edac
Commit
6095edac
authored
Dec 03, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
64f35ba8
3d9a4e70
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
124 additions
and
82 deletions
+124
-82
block_manager.go
chain/block_manager.go
+29
-26
chain_manager.go
chain/chain_manager.go
+3
-0
dagger.go
chain/dagger.go
+9
-5
error.go
chain/error.go
+2
-2
filter.go
chain/filter.go
+2
-2
state_transition.go
chain/state_transition.go
+0
-6
block.go
chain/types/block.go
+2
-0
bloom9.go
chain/types/bloom9.go
+2
-2
main.go
cmd/ethereum/main.go
+1
-1
miner.qml
cmd/mist/assets/qml/views/miner.qml
+2
-0
wallet.qml
cmd/mist/assets/qml/views/wallet.qml
+9
-3
main.go
cmd/mist/main.go
+1
-1
cmd.go
cmd/utils/cmd.go
+1
-1
peer.go
peer.go
+1
-1
vm.go
tests/helper/vm.go
+11
-6
gh_test.go
tests/vm/gh_test.go
+32
-8
execution.go
vm/execution.go
+1
-3
stack.go
vm/stack.go
+1
-2
types.go
vm/types.go
+6
-7
vm_debug.go
vm/vm_debug.go
+9
-6
No files found.
chain/block_manager.go
View file @
6095edac
...
...
@@ -118,6 +118,19 @@ func (sm *BlockManager) ChainManager() *ChainManager {
return
sm
.
bc
}
func
(
sm
*
BlockManager
)
TransitionState
(
statedb
*
state
.
State
,
parent
,
block
*
types
.
Block
)
(
receipts
types
.
Receipts
,
err
error
)
{
coinbase
:=
statedb
.
GetOrNewStateObject
(
block
.
Coinbase
)
coinbase
.
SetGasPool
(
block
.
CalcGasLimit
(
parent
))
// Process the transactions on to current block
receipts
,
_
,
_
,
_
,
err
=
sm
.
ProcessTransactions
(
coinbase
,
statedb
,
block
,
parent
,
block
.
Transactions
())
if
err
!=
nil
{
return
nil
,
err
}
return
receipts
,
nil
}
func
(
self
*
BlockManager
)
ProcessTransactions
(
coinbase
*
state
.
StateObject
,
state
*
state
.
State
,
block
,
parent
*
types
.
Block
,
txs
types
.
Transactions
)
(
types
.
Receipts
,
types
.
Transactions
,
types
.
Transactions
,
types
.
Transactions
,
error
)
{
var
(
receipts
types
.
Receipts
...
...
@@ -125,6 +138,7 @@ func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state
erroneous
types
.
Transactions
totalUsedGas
=
big
.
NewInt
(
0
)
err
error
cumulativeSum
=
new
(
big
.
Int
)
)
done
:
...
...
@@ -156,6 +170,7 @@ done:
}
txGas
.
Sub
(
txGas
,
st
.
gas
)
cumulativeSum
.
Add
(
cumulativeSum
,
new
(
big
.
Int
)
.
Mul
(
txGas
,
tx
.
GasPrice
))
// Update the state with pending changes
state
.
Update
(
txGas
)
...
...
@@ -176,6 +191,7 @@ done:
}
}
block
.
Reward
=
cumulativeSum
block
.
GasUsed
=
totalUsedGas
return
receipts
,
handled
,
unhandled
,
erroneous
,
err
...
...
@@ -187,8 +203,7 @@ func (sm *BlockManager) Process(block *types.Block) (td *big.Int, msgs state.Mes
defer
sm
.
mutex
.
Unlock
()
if
sm
.
bc
.
HasBlock
(
block
.
Hash
())
{
fmt
.
Println
(
"already having this block"
)
return
nil
,
nil
,
nil
return
nil
,
nil
,
&
KnownBlockError
{
block
.
Number
,
block
.
Hash
()}
}
if
!
sm
.
bc
.
HasBlock
(
block
.
PrevHash
)
{
...
...
@@ -214,7 +229,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
fmt
.
Printf
(
"## %x %x ##
\n
"
,
block
.
Hash
(),
block
.
Number
)
}
_
,
err
=
sm
.
ApplyDiff
(
state
,
parent
,
block
)
_
,
err
=
sm
.
TransitionState
(
state
,
parent
,
block
)
if
err
!=
nil
{
return
}
...
...
@@ -235,12 +250,10 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
// Block validation
if
err
=
sm
.
ValidateBlock
(
block
,
parent
);
err
!=
nil
{
statelogger
.
Errorln
(
"validating block:"
,
err
)
return
}
if
err
=
sm
.
AccumelateRewards
(
state
,
block
,
parent
);
err
!=
nil
{
statelogger
.
Errorln
(
"accumulating reward"
,
err
)
return
}
...
...
@@ -273,7 +286,6 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
sm
.
transState
=
state
.
Copy
()
sm
.
eth
.
TxPool
()
.
RemoveSet
(
block
.
Transactions
())
fmt
.
Println
(
"TD"
,
td
)
return
td
,
messages
,
nil
}
else
{
...
...
@@ -281,19 +293,6 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
}
}
func
(
sm
*
BlockManager
)
ApplyDiff
(
state
*
state
.
State
,
parent
,
block
*
types
.
Block
)
(
receipts
types
.
Receipts
,
err
error
)
{
coinbase
:=
state
.
GetOrNewStateObject
(
block
.
Coinbase
)
coinbase
.
SetGasPool
(
block
.
CalcGasLimit
(
parent
))
// Process the transactions on to current block
receipts
,
_
,
_
,
_
,
err
=
sm
.
ProcessTransactions
(
coinbase
,
state
,
block
,
parent
,
block
.
Transactions
())
if
err
!=
nil
{
return
nil
,
err
}
return
receipts
,
nil
}
func
(
sm
*
BlockManager
)
CalculateTD
(
block
*
types
.
Block
)
(
*
big
.
Int
,
bool
)
{
uncleDiff
:=
new
(
big
.
Int
)
for
_
,
uncle
:=
range
block
.
Uncles
{
...
...
@@ -309,9 +308,6 @@ func (sm *BlockManager) CalculateTD(block *types.Block) (*big.Int, bool) {
// is greater than the previous.
if
td
.
Cmp
(
sm
.
bc
.
TD
)
>
0
{
return
td
,
true
// Set the new total difficulty back to the block chain
//sm.bc.SetTotalDifficulty(td)
}
return
nil
,
false
...
...
@@ -375,17 +371,25 @@ func (sm *BlockManager) AccumelateRewards(state *state.State, block, parent *typ
r
:=
new
(
big
.
Int
)
r
.
Mul
(
BlockReward
,
big
.
NewInt
(
15
))
.
Div
(
r
,
big
.
NewInt
(
16
))
uncleAccount
:=
state
.
GetAccount
(
uncle
.
Coinbase
)
uncleAccount
:=
state
db
.
GetAccount
(
uncle
.
Coinbase
)
uncleAccount
.
AddAmount
(
r
)
reward
.
Add
(
reward
,
new
(
big
.
Int
)
.
Div
(
BlockReward
,
big
.
NewInt
(
32
)))
}
// Get the account associated with the coinbase
account
:=
state
.
GetAccount
(
block
.
Coinbase
)
account
:=
state
db
.
GetAccount
(
block
.
Coinbase
)
// Reward amount of ether to the coinbase address
account
.
AddAmount
(
reward
)
statedb
.
Manifest
()
.
AddMessage
(
&
state
.
Message
{
To
:
block
.
Coinbase
,
From
:
block
.
Coinbase
,
Input
:
nil
,
Origin
:
nil
,
Block
:
block
.
Hash
(),
Timestamp
:
block
.
Time
,
Coinbase
:
block
.
Coinbase
,
Number
:
block
.
Number
,
Value
:
new
(
big
.
Int
)
.
Add
(
reward
,
block
.
Reward
),
})
return
nil
}
...
...
@@ -403,8 +407,7 @@ func (sm *BlockManager) GetMessages(block *types.Block) (messages []*state.Messa
defer
state
.
Reset
()
sm
.
ApplyDiff
(
state
,
parent
,
block
)
sm
.
TransitionState
(
state
,
parent
,
block
)
sm
.
AccumelateRewards
(
state
,
block
,
parent
)
return
state
.
Manifest
()
.
Messages
,
nil
...
...
chain/chain_manager.go
View file @
6095edac
...
...
@@ -258,6 +258,9 @@ func (self *ChainManager) InsertChain(chain Blocks) error {
continue
}
chainlogger
.
Infof
(
"block #%v process failed (%x)
\n
"
,
block
.
Number
,
block
.
Hash
()[
:
4
])
chainlogger
.
Infoln
(
block
)
chainlogger
.
Infoln
(
err
)
return
err
}
...
...
chain/dagger.go
View file @
6095edac
...
...
@@ -82,13 +82,17 @@ func (pow *EasyPow) Verify(hash []byte, diff *big.Int, nonce []byte) bool {
d
:=
append
(
hash
,
nonce
...
)
sha
.
Write
(
d
)
v
:=
ethutil
.
BigPow
(
2
,
256
)
re
t
:=
new
(
big
.
Int
)
.
Div
(
v
,
diff
)
v
erification
:=
new
(
big
.
Int
)
.
Div
(
ethutil
.
BigPow
(
2
,
256
),
diff
)
re
s
:=
ethutil
.
U256
(
ethutil
.
BigD
(
sha
.
Sum
(
nil
))
)
res
:=
new
(
big
.
Int
)
res
.
SetBytes
(
sha
.
Sum
(
nil
))
/*
fmt.Printf("hash w/o nonce %x\n", hash)
fmt.Printf("2**256 / %v = %v\n", diff, verification)
fmt.Printf("%v <= %v\n", res, verification)
fmt.Printf("vlen: %d rlen: %d\n", len(verification.Bytes()), len(res.Bytes()))
*/
return
res
.
Cmp
(
ret
)
==
-
1
return
res
.
Cmp
(
verification
)
<=
0
}
func
(
pow
*
EasyPow
)
SetHash
(
hash
*
big
.
Int
)
{
...
...
chain/error.go
View file @
6095edac
...
...
@@ -128,12 +128,12 @@ func IsTDError(e error) bool {
}
type
KnownBlockError
struct
{
number
uint64
number
*
big
.
Int
hash
[]
byte
}
func
(
self
*
KnownBlockError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"block %
d
already known (%x)"
,
self
.
number
,
self
.
hash
[
0
:
4
])
return
fmt
.
Sprintf
(
"block %
v
already known (%x)"
,
self
.
number
,
self
.
hash
[
0
:
4
])
}
func
IsKnownBlockErr
(
e
error
)
bool
{
_
,
ok
:=
e
.
(
*
KnownBlockError
)
...
...
chain/filter.go
View file @
6095edac
...
...
@@ -176,7 +176,7 @@ func (self *Filter) bloomFilter(block *types.Block) bool {
var
fromIncluded
,
toIncluded
bool
if
len
(
self
.
from
)
>
0
{
for
_
,
from
:=
range
self
.
from
{
if
types
.
BloomLookup
(
block
.
LogsBloom
,
from
)
{
if
types
.
BloomLookup
(
block
.
LogsBloom
,
from
)
||
bytes
.
Equal
(
block
.
Coinbase
,
from
)
{
fromIncluded
=
true
break
}
...
...
@@ -187,7 +187,7 @@ func (self *Filter) bloomFilter(block *types.Block) bool {
if
len
(
self
.
to
)
>
0
{
for
_
,
to
:=
range
self
.
to
{
if
types
.
BloomLookup
(
block
.
LogsBloom
,
ethutil
.
U256
(
new
(
big
.
Int
)
.
Add
(
ethutil
.
Big1
,
ethutil
.
BigD
(
to
)))
.
Bytes
())
{
if
types
.
BloomLookup
(
block
.
LogsBloom
,
ethutil
.
U256
(
new
(
big
.
Int
)
.
Add
(
ethutil
.
Big1
,
ethutil
.
BigD
(
to
)))
.
Bytes
())
||
bytes
.
Equal
(
block
.
Coinbase
,
to
)
{
toIncluded
=
true
break
}
...
...
chain/state_transition.go
View file @
6095edac
...
...
@@ -169,12 +169,6 @@ func (self *StateTransition) TransitionState() (err error) {
return
}
//dataPrice := big.NewInt(int64(len(self.data)))
//dataPrice.Mul(dataPrice, vm.GasData)
//if err = self.UseGas(dataPrice); err != nil {
// return
//}
if
sender
.
Balance
()
.
Cmp
(
self
.
value
)
<
0
{
return
fmt
.
Errorf
(
"Insufficient funds to transfer value. Req %v, has %v"
,
self
.
value
,
sender
.
Balance
)
}
...
...
chain/types/block.go
View file @
6095edac
...
...
@@ -97,6 +97,8 @@ type Block struct {
receipts
Receipts
TxSha
,
ReceiptSha
[]
byte
LogsBloom
[]
byte
Reward
*
big
.
Int
}
func
NewBlockFromBytes
(
raw
[]
byte
)
*
Block
{
...
...
chain/types/bloom9.go
View file @
6095edac
...
...
@@ -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 @
6095edac
...
...
@@ -30,7 +30,7 @@ import (
const
(
ClientIdentifier
=
"Ethereum(G)"
Version
=
"0.7.
6
"
Version
=
"0.7.
7
"
)
var
clilogger
=
logger
.
NewLogger
(
"CLI"
)
...
...
cmd/mist/assets/qml/views/miner.qml
View file @
6095edac
...
...
@@ -119,12 +119,14 @@ Rectangle {
}
}
Component.onCompleted
:
{
/*
// XXX Temp. replace with above eventually
var tmpItems = ["JEVCoin", "Some coin", "Other coin", "Etc coin"];
var address = "e6716f9544a56c530d868e4bfbacb172315bdead";
for (var i = 0; i < tmpItems.length; i++) {
mergedMiningModel.append({checked: false, name: tmpItems[i], address: address, id: 0, itemId: i});
}
*/
}
}
}
...
...
cmd/mist/assets/qml/views/wallet.qml
View file @
6095edac
...
...
@@ -16,6 +16,12 @@ Rectangle {
anchors.fill
:
parent
function
onReady
()
{
setBalance
()
}
function
setBalance
()
{
balance
.
text
=
"<b>Balance</b>: "
+
eth
.
numberToHuman
(
eth
.
balanceAt
(
eth
.
key
().
address
))
if
(
menuItem
)
menuItem
.
secondaryTitle
=
eth
.
numberToHuman
(
eth
.
balanceAt
(
eth
.
key
().
address
))
}
...
...
@@ -39,7 +45,6 @@ Rectangle {
Text
{
id
:
balance
text
:
"<b>Balance</b>: "
+
eth
.
numberToHuman
(
eth
.
balanceAt
(
eth
.
key
().
address
))
font.pixelSize
:
24
anchors
{
horizontalCenter
:
parent
.
horizontalCenter
...
...
@@ -126,7 +131,6 @@ Rectangle {
var
value
=
txValue
.
text
+
denomModel
.
get
(
valueDenom
.
currentIndex
).
zeros
;
var
gasPrice
=
"10000000000000"
var
res
=
eth
.
transact
({
from
:
eth
.
key
().
privateKey
,
to
:
txTo
.
text
,
value
:
value
,
gas
:
"500"
,
gasPrice
:
gasPrice
})
console
.
log
(
res
)
}
}
}
...
...
@@ -158,6 +162,8 @@ Rectangle {
}
function
addTxs
(
messages
)
{
setBalance
()
for
(
var
i
=
0
;
i
<
messages
.
length
;
i
++
)
{
var
message
=
messages
.
get
(
i
);
var
to
=
eth
.
lookupName
(
message
.
to
);
...
...
cmd/mist/main.go
View file @
6095edac
...
...
@@ -31,7 +31,7 @@ import (
const
(
ClientIdentifier
=
"Mist"
Version
=
"0.7.
6
"
Version
=
"0.7.
7
"
)
var
ethereum
*
eth
.
Ethereum
...
...
cmd/utils/cmd.go
View file @
6095edac
...
...
@@ -317,7 +317,7 @@ func BlockDo(ethereum *eth.Ethereum, hash []byte) error {
parent
:=
ethereum
.
ChainManager
()
.
GetBlock
(
block
.
PrevHash
)
_
,
err
:=
ethereum
.
BlockManager
()
.
ApplyDiff
(
parent
.
State
(),
parent
,
block
)
_
,
err
:=
ethereum
.
BlockManager
()
.
TransitionState
(
parent
.
State
(),
parent
,
block
)
if
err
!=
nil
{
return
err
}
...
...
peer.go
View file @
6095edac
...
...
@@ -24,7 +24,7 @@ const (
// The size of the output buffer for writing messages
outputBufferSize
=
50
// Current protocol version
ProtocolVersion
=
4
5
ProtocolVersion
=
4
6
// Current P2P version
P2PVersion
=
2
// Ethereum network version
...
...
tests/helper/vm.go
View file @
6095edac
...
...
@@ -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 @
6095edac
...
...
@@ -141,6 +141,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"
...
...
@@ -153,6 +154,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
))
...
...
@@ -181,6 +188,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
...
...
@@ -192,10 +200,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...
...
...
@@ -215,12 +223,13 @@ func RunVmTest(p string, t *testing.T) {
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.
...
...
@@ -242,7 +251,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
)
...
...
@@ -252,6 +261,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"
)
}
}
}
}
}
...
...
@@ -296,6 +315,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/execution.go
View file @
6095edac
...
...
@@ -26,7 +26,7 @@ func (self *Execution) Addr() []byte {
func
(
self
*
Execution
)
Exec
(
codeAddr
[]
byte
,
caller
ClosureRef
)
([]
byte
,
error
)
{
// Retrieve the executing code
code
:=
self
.
vm
.
Env
()
.
State
()
.
GetCode
(
codeAddr
)
code
:=
self
.
vm
.
Env
()
.
GetCode
(
codeAddr
)
return
self
.
exec
(
code
,
codeAddr
,
caller
)
}
...
...
@@ -34,13 +34,11 @@ func (self *Execution) Exec(codeAddr []byte, caller ClosureRef) ([]byte, error)
func
(
self
*
Execution
)
exec
(
code
,
caddr
[]
byte
,
caller
ClosureRef
)
(
ret
[]
byte
,
err
error
)
{
env
:=
self
.
vm
.
Env
()
vmlogger
.
Debugf
(
"pre state %x
\n
"
,
env
.
State
()
.
Root
())
snapshot
:=
env
.
State
()
.
Copy
()
defer
func
()
{
if
IsDepthErr
(
err
)
||
IsOOGErr
(
err
)
{
env
.
State
()
.
Set
(
snapshot
)
}
vmlogger
.
Debugf
(
"post state %x
\n
"
,
env
.
State
()
.
Root
())
}()
msg
:=
env
.
State
()
.
Manifest
()
.
AddMessage
(
&
state
.
Message
{
...
...
vm/stack.go
View file @
6095edac
...
...
@@ -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 @
6095edac
...
...
@@ -163,8 +163,8 @@ const (
// 0xf0 range - closures
CREATE
OpCode
=
0xf0
+
iota
CALL
RETURN
CALLCODE
RETURN
// 0x70 range - other
SUICIDE
=
0xff
...
...
@@ -308,7 +308,6 @@ var opCodeToString = map[OpCode]string{
SWAP14
:
"SWAP14"
,
SWAP15
:
"SWAP15"
,
SWAP16
:
"SWAP16"
,
LOG0
:
"LOG0"
,
LOG1
:
"LOG1"
,
LOG2
:
"LOG2"
,
...
...
vm/vm_debug.go
View file @
6095edac
...
...
@@ -41,7 +41,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) {
...
...
@@ -177,10 +177,13 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, err error) {
n
:=
int
(
op
-
LOG0
)
require
(
n
+
2
)
mSize
,
mStart
:=
stack
.
Peekn
()
reqGs
.
Set
(
GasLog
)
gas
.
Set
(
GasLog
)
addStepGasUsage
(
new
(
big
.
Int
)
.
Mul
(
big
.
NewInt
(
int64
(
n
)),
GasLog
))
addStepGasUsage
(
new
(
big
.
Int
)
.
Add
(
mSize
,
mStart
))
mSize
,
mStart
:=
stack
.
Peekn
()
addStepGasUsage
(
mSize
)
newMemSize
=
calcMemSize
(
mStart
,
mSize
)
case
EXP
:
require
(
2
)
...
...
@@ -762,10 +765,10 @@ func (self *DebugVm) Run(call Options) (ret []byte, gas *big.Int, 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