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
22d29a6d
Commit
22d29a6d
authored
Dec 18, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
0dc56612
a7f4ade7
Changes
21
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
2082 additions
and
342 deletions
+2082
-342
gui.go
cmd/mist/gui.go
+10
-10
block_manager.go
core/block_manager.go
+3
-3
state_transition.go
core/state_transition.go
+90
-55
transaction_pool.go
core/transaction_pool.go
+6
-15
transaction.go
core/types/transaction.go
+46
-48
vm_env.go
core/vm_env.go
+5
-5
miner.go
miner/miner.go
+3
-3
state.go
state/state.go
+14
-21
stInitCodeTest.json
tests/files/StateTests/stInitCodeTest.json
+870
-0
stRefundTest.json
tests/files/StateTests/stRefundTest.json
+523
-0
stSystemOperationsTest.json
tests/files/StateTests/stSystemOperationsTest.json
+1
-1
stTransactionTest.json
tests/files/StateTests/stTransactionTest.json
+277
-0
vmArithmeticTest.json
tests/files/VMTests/vmArithmeticTest.json
+147
-147
index.js
tests/files/index.js
+6
-1
vm.go
tests/helper/vm.go
+32
-5
gh_test.go
tests/vm/gh_test.go
+21
-1
common.go
vm/common.go
+1
-1
vm_debug.go
vm/vm_debug.go
+14
-13
hexface.go
xeth/hexface.go
+2
-2
js_types.go
xeth/js_types.go
+7
-7
pipe.go
xeth/pipe.go
+4
-4
No files found.
cmd/mist/gui.go
View file @
22d29a6d
...
@@ -309,13 +309,13 @@ func (gui *Gui) insertTransaction(window string, tx *types.Transaction) {
...
@@ -309,13 +309,13 @@ func (gui *Gui) insertTransaction(window string, tx *types.Transaction) {
var
(
var
(
ptx
=
xeth
.
NewJSTx
(
tx
,
pipe
.
World
()
.
State
())
ptx
=
xeth
.
NewJSTx
(
tx
,
pipe
.
World
()
.
State
())
send
=
nameReg
.
Storage
(
tx
.
Sender
())
send
=
nameReg
.
Storage
(
tx
.
From
())
rec
=
nameReg
.
Storage
(
tx
.
Recipient
)
rec
=
nameReg
.
Storage
(
tx
.
To
()
)
s
,
r
string
s
,
r
string
)
)
if
tx
.
CreatesContract
(
)
{
if
core
.
MessageCreatesContract
(
tx
)
{
rec
=
nameReg
.
Storage
(
tx
.
CreationAddress
(
pipe
.
World
()
.
State
()
))
rec
=
nameReg
.
Storage
(
core
.
AddressFromMessage
(
tx
))
}
}
if
send
.
Len
()
!=
0
{
if
send
.
Len
()
!=
0
{
...
@@ -326,10 +326,10 @@ func (gui *Gui) insertTransaction(window string, tx *types.Transaction) {
...
@@ -326,10 +326,10 @@ func (gui *Gui) insertTransaction(window string, tx *types.Transaction) {
if
rec
.
Len
()
!=
0
{
if
rec
.
Len
()
!=
0
{
r
=
strings
.
Trim
(
rec
.
Str
(),
"
\x00
"
)
r
=
strings
.
Trim
(
rec
.
Str
(),
"
\x00
"
)
}
else
{
}
else
{
if
tx
.
CreatesContract
(
)
{
if
core
.
MessageCreatesContract
(
tx
)
{
r
=
ethutil
.
Bytes2Hex
(
tx
.
CreationAddress
(
pipe
.
World
()
.
State
()
))
r
=
ethutil
.
Bytes2Hex
(
core
.
AddressFromMessage
(
tx
))
}
else
{
}
else
{
r
=
ethutil
.
Bytes2Hex
(
tx
.
Recipient
)
r
=
ethutil
.
Bytes2Hex
(
tx
.
To
()
)
}
}
}
}
ptx
.
Sender
=
s
ptx
.
Sender
=
s
...
@@ -454,11 +454,11 @@ func (gui *Gui) update() {
...
@@ -454,11 +454,11 @@ func (gui *Gui) update() {
object
:=
state
.
GetAccount
(
gui
.
address
())
object
:=
state
.
GetAccount
(
gui
.
address
())
if
bytes
.
Compare
(
tx
.
Sender
(),
gui
.
address
())
==
0
{
if
bytes
.
Compare
(
tx
.
Sender
(),
gui
.
address
())
==
0
{
object
.
SubAmount
(
tx
.
Value
)
object
.
SubAmount
(
tx
.
Value
()
)
gui
.
txDb
.
Put
(
tx
.
Hash
(),
tx
.
RlpEncode
())
gui
.
txDb
.
Put
(
tx
.
Hash
(),
tx
.
RlpEncode
())
}
else
if
bytes
.
Compare
(
tx
.
Recipient
,
gui
.
address
())
==
0
{
}
else
if
bytes
.
Compare
(
tx
.
To
()
,
gui
.
address
())
==
0
{
object
.
AddAmount
(
tx
.
Value
)
object
.
AddAmount
(
tx
.
Value
()
)
gui
.
txDb
.
Put
(
tx
.
Hash
(),
tx
.
RlpEncode
())
gui
.
txDb
.
Put
(
tx
.
Hash
(),
tx
.
RlpEncode
())
}
}
...
...
core/block_manager.go
View file @
22d29a6d
...
@@ -109,11 +109,11 @@ done:
...
@@ -109,11 +109,11 @@ done:
// If we are mining this block and validating we want to set the logs back to 0
// If we are mining this block and validating we want to set the logs back to 0
state
.
EmptyLogs
()
state
.
EmptyLogs
()
txGas
:=
new
(
big
.
Int
)
.
Set
(
tx
.
Gas
)
txGas
:=
new
(
big
.
Int
)
.
Set
(
tx
.
Gas
()
)
cb
:=
state
.
GetStateObject
(
coinbase
.
Address
())
cb
:=
state
.
GetStateObject
(
coinbase
.
Address
())
st
:=
NewStateTransition
(
cb
,
tx
,
state
,
block
)
st
:=
NewStateTransition
(
cb
,
tx
,
state
,
block
)
err
=
st
.
TransitionState
()
_
,
err
=
st
.
TransitionState
()
if
err
!=
nil
{
if
err
!=
nil
{
switch
{
switch
{
case
IsNonceErr
(
err
)
:
case
IsNonceErr
(
err
)
:
...
@@ -132,7 +132,7 @@ done:
...
@@ -132,7 +132,7 @@ done:
}
}
txGas
.
Sub
(
txGas
,
st
.
gas
)
txGas
.
Sub
(
txGas
,
st
.
gas
)
cumulativeSum
.
Add
(
cumulativeSum
,
new
(
big
.
Int
)
.
Mul
(
txGas
,
tx
.
GasPrice
))
cumulativeSum
.
Add
(
cumulativeSum
,
new
(
big
.
Int
)
.
Mul
(
txGas
,
tx
.
GasPrice
()
))
// Update the state with pending changes
// Update the state with pending changes
state
.
Update
(
txGas
)
state
.
Update
(
txGas
)
...
...
core/state_transition.go
View file @
22d29a6d
...
@@ -5,6 +5,8 @@ import (
...
@@ -5,6 +5,8 @@ import (
"math/big"
"math/big"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/vm"
"github.com/ethereum/go-ethereum/vm"
)
)
...
@@ -27,48 +29,69 @@ import (
...
@@ -27,48 +29,69 @@ import (
*/
*/
type
StateTransition
struct
{
type
StateTransition
struct
{
coinbase
,
receiver
[]
byte
coinbase
,
receiver
[]
byte
tx
*
types
.
Transaction
msg
Message
gas
,
gasPrice
*
big
.
Int
gas
,
gasPrice
*
big
.
Int
initialGas
*
big
.
Int
value
*
big
.
Int
value
*
big
.
Int
data
[]
byte
data
[]
byte
state
*
state
.
StateDB
state
*
state
.
StateDB
block
*
types
.
Block
block
*
types
.
Block
cb
,
rec
,
sen
*
state
.
StateObject
cb
,
rec
,
sen
*
state
.
StateObject
Env
vm
.
Environment
}
}
func
NewStateTransition
(
coinbase
*
state
.
StateObject
,
tx
*
types
.
Transaction
,
state
*
state
.
StateDB
,
block
*
types
.
Block
)
*
StateTransition
{
type
Message
interface
{
return
&
StateTransition
{
coinbase
.
Address
(),
tx
.
Recipient
,
tx
,
new
(
big
.
Int
),
new
(
big
.
Int
)
.
Set
(
tx
.
GasPrice
),
tx
.
Value
,
tx
.
Data
,
state
,
block
,
coinbase
,
nil
,
nil
}
Hash
()
[]
byte
From
()
[]
byte
To
()
[]
byte
GasPrice
()
*
big
.
Int
Gas
()
*
big
.
Int
Value
()
*
big
.
Int
Nonce
()
uint64
Data
()
[]
byte
}
}
func
(
self
*
StateTransition
)
Coinbase
()
*
state
.
StateObject
{
func
AddressFromMessage
(
msg
Message
)
[]
byte
{
if
self
.
cb
!=
nil
{
// Generate a new address
return
self
.
cb
return
crypto
.
Sha3
(
ethutil
.
NewValue
([]
interface
{}{
msg
.
From
(),
msg
.
Nonce
()})
.
Encode
())[
12
:
]
}
}
self
.
cb
=
self
.
state
.
GetOrNewStateObject
(
self
.
coinbase
)
func
MessageCreatesContract
(
msg
Message
)
bool
{
return
self
.
cb
return
len
(
msg
.
To
())
==
0
}
}
func
(
self
*
StateTransition
)
Sender
()
*
state
.
StateObject
{
if
self
.
sen
!=
nil
{
return
self
.
sen
}
self
.
sen
=
self
.
state
.
GetOrNewStateObject
(
self
.
tx
.
Sender
())
func
MessageGasValue
(
msg
Message
)
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Mul
(
msg
.
Gas
(),
msg
.
GasPrice
())
}
return
self
.
sen
func
NewStateTransition
(
coinbase
*
state
.
StateObject
,
msg
Message
,
state
*
state
.
StateDB
,
block
*
types
.
Block
)
*
StateTransition
{
return
&
StateTransition
{
coinbase
.
Address
(),
msg
.
To
(),
msg
,
new
(
big
.
Int
),
new
(
big
.
Int
)
.
Set
(
msg
.
GasPrice
()),
new
(
big
.
Int
),
msg
.
Value
(),
msg
.
Data
(),
state
,
block
,
coinbase
,
nil
,
nil
,
nil
}
}
}
func
(
self
*
StateTransition
)
Receiver
()
*
state
.
StateObject
{
if
self
.
tx
!=
nil
&&
self
.
tx
.
CreatesContract
()
{
return
nil
}
if
self
.
rec
!=
nil
{
func
(
self
*
StateTransition
)
VmEnv
()
vm
.
Environment
{
return
self
.
rec
if
self
.
Env
==
nil
{
self
.
Env
=
NewEnv
(
self
.
state
,
self
.
msg
,
self
.
block
)
}
}
self
.
rec
=
self
.
state
.
GetOrNewStateObject
(
self
.
tx
.
Recipient
)
return
self
.
Env
return
self
.
rec
}
func
(
self
*
StateTransition
)
Coinbase
()
*
state
.
StateObject
{
return
self
.
state
.
GetOrNewStateObject
(
self
.
coinbase
)
}
func
(
self
*
StateTransition
)
From
()
*
state
.
StateObject
{
return
self
.
state
.
GetOrNewStateObject
(
self
.
msg
.
From
())
}
func
(
self
*
StateTransition
)
To
()
*
state
.
StateObject
{
if
self
.
msg
!=
nil
&&
MessageCreatesContract
(
self
.
msg
)
{
return
nil
}
return
self
.
state
.
GetOrNewStateObject
(
self
.
msg
.
To
())
}
}
func
(
self
*
StateTransition
)
UseGas
(
amount
*
big
.
Int
)
error
{
func
(
self
*
StateTransition
)
UseGas
(
amount
*
big
.
Int
)
error
{
...
@@ -87,41 +110,33 @@ func (self *StateTransition) AddGas(amount *big.Int) {
...
@@ -87,41 +110,33 @@ func (self *StateTransition) AddGas(amount *big.Int) {
func
(
self
*
StateTransition
)
BuyGas
()
error
{
func
(
self
*
StateTransition
)
BuyGas
()
error
{
var
err
error
var
err
error
sender
:=
self
.
Sender
()
sender
:=
self
.
From
()
if
sender
.
Balance
()
.
Cmp
(
self
.
tx
.
GasValue
(
))
<
0
{
if
sender
.
Balance
()
.
Cmp
(
MessageGasValue
(
self
.
msg
))
<
0
{
return
fmt
.
Errorf
(
"Insufficient funds to pre-pay gas. Req %v, has %v"
,
self
.
tx
.
GasValue
(
),
sender
.
Balance
())
return
fmt
.
Errorf
(
"Insufficient funds to pre-pay gas. Req %v, has %v"
,
MessageGasValue
(
self
.
msg
),
sender
.
Balance
())
}
}
coinbase
:=
self
.
Coinbase
()
coinbase
:=
self
.
Coinbase
()
err
=
coinbase
.
BuyGas
(
self
.
tx
.
Gas
,
self
.
tx
.
GasPrice
)
err
=
coinbase
.
BuyGas
(
self
.
msg
.
Gas
(),
self
.
msg
.
GasPrice
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
self
.
AddGas
(
self
.
tx
.
Gas
)
self
.
AddGas
(
self
.
msg
.
Gas
())
sender
.
SubAmount
(
self
.
tx
.
GasValue
())
self
.
initialGas
.
Set
(
self
.
msg
.
Gas
())
sender
.
SubAmount
(
MessageGasValue
(
self
.
msg
))
return
nil
return
nil
}
}
func
(
self
*
StateTransition
)
RefundGas
()
{
coinbase
,
sender
:=
self
.
Coinbase
(),
self
.
Sender
()
coinbase
.
RefundGas
(
self
.
gas
,
self
.
tx
.
GasPrice
)
// Return remaining gas
remaining
:=
new
(
big
.
Int
)
.
Mul
(
self
.
gas
,
self
.
tx
.
GasPrice
)
sender
.
AddAmount
(
remaining
)
}
func
(
self
*
StateTransition
)
preCheck
()
(
err
error
)
{
func
(
self
*
StateTransition
)
preCheck
()
(
err
error
)
{
var
(
var
(
tx
=
self
.
tx
msg
=
self
.
msg
sender
=
self
.
Sender
()
sender
=
self
.
From
()
)
)
// Make sure this transaction's nonce is correct
// Make sure this transaction's nonce is correct
if
sender
.
Nonce
!=
tx
.
Nonce
{
if
sender
.
Nonce
!=
msg
.
Nonce
()
{
return
NonceError
(
tx
.
Nonce
,
sender
.
Nonce
)
return
NonceError
(
msg
.
Nonce
()
,
sender
.
Nonce
)
}
}
// Pre-pay gas / Buy gas of the coinbase account
// Pre-pay gas / Buy gas of the coinbase account
...
@@ -132,8 +147,8 @@ func (self *StateTransition) preCheck() (err error) {
...
@@ -132,8 +147,8 @@ func (self *StateTransition) preCheck() (err error) {
return
nil
return
nil
}
}
func
(
self
*
StateTransition
)
TransitionState
()
(
err
error
)
{
func
(
self
*
StateTransition
)
TransitionState
()
(
ret
[]
byte
,
err
error
)
{
statelogger
.
Debugf
(
"(~) %x
\n
"
,
self
.
tx
.
Hash
())
statelogger
.
Debugf
(
"(~) %x
\n
"
,
self
.
msg
.
Hash
())
// XXX Transactions after this point are considered valid.
// XXX Transactions after this point are considered valid.
if
err
=
self
.
preCheck
();
err
!=
nil
{
if
err
=
self
.
preCheck
();
err
!=
nil
{
...
@@ -141,8 +156,8 @@ func (self *StateTransition) TransitionState() (err error) {
...
@@ -141,8 +156,8 @@ func (self *StateTransition) TransitionState() (err error) {
}
}
var
(
var
(
tx
=
self
.
tx
msg
=
self
.
msg
sender
=
self
.
Sender
()
sender
=
self
.
From
()
)
)
defer
self
.
RefundGas
()
defer
self
.
RefundGas
()
...
@@ -168,16 +183,15 @@ func (self *StateTransition) TransitionState() (err error) {
...
@@ -168,16 +183,15 @@ func (self *StateTransition) TransitionState() (err error) {
return
return
}
}
var
ret
[]
byte
vmenv
:=
self
.
VmEnv
()
vmenv
:=
NewEnv
(
self
.
state
,
self
.
tx
,
self
.
block
)
var
ref
vm
.
ClosureRef
var
ref
vm
.
ClosureRef
if
tx
.
CreatesContract
(
)
{
if
MessageCreatesContract
(
msg
)
{
self
.
rec
=
MakeContract
(
tx
,
self
.
state
)
self
.
rec
=
MakeContract
(
msg
,
self
.
state
)
ret
,
err
,
ref
=
vmenv
.
Create
(
sender
,
self
.
rec
.
Address
(),
self
.
tx
.
Data
,
self
.
gas
,
self
.
gasPrice
,
self
.
value
)
ret
,
err
,
ref
=
vmenv
.
Create
(
sender
,
self
.
rec
.
Address
(),
self
.
msg
.
Data
()
,
self
.
gas
,
self
.
gasPrice
,
self
.
value
)
ref
.
SetCode
(
ret
)
ref
.
SetCode
(
ret
)
}
else
{
}
else
{
ret
,
err
=
vmenv
.
Call
(
self
.
Sender
(),
self
.
Receiver
()
.
Address
(),
self
.
tx
.
Data
,
self
.
gas
,
self
.
gasPrice
,
self
.
value
)
ret
,
err
=
vmenv
.
Call
(
self
.
From
(),
self
.
To
()
.
Address
(),
self
.
msg
.
Data
()
,
self
.
gas
,
self
.
gasPrice
,
self
.
value
)
}
}
if
err
!=
nil
{
if
err
!=
nil
{
statelogger
.
Debugln
(
err
)
statelogger
.
Debugln
(
err
)
...
@@ -187,11 +201,32 @@ func (self *StateTransition) TransitionState() (err error) {
...
@@ -187,11 +201,32 @@ func (self *StateTransition) TransitionState() (err error) {
}
}
// Converts an transaction in to a state object
// Converts an transaction in to a state object
func
MakeContract
(
tx
*
types
.
Transaction
,
state
*
state
.
StateDB
)
*
state
.
StateObject
{
func
MakeContract
(
msg
Message
,
state
*
state
.
StateDB
)
*
state
.
StateObject
{
addr
:=
tx
.
CreationAddress
(
state
)
addr
:=
AddressFromMessage
(
msg
)
contract
:=
state
.
GetOrNewStateObject
(
addr
)
contract
:=
state
.
GetOrNewStateObject
(
addr
)
contract
.
InitCode
=
tx
.
Data
contract
.
InitCode
=
msg
.
Data
()
return
contract
return
contract
}
}
func
(
self
*
StateTransition
)
RefundGas
()
{
coinbaseSub
:=
new
(
big
.
Int
)
.
Set
(
self
.
gas
)
uhalf
:=
new
(
big
.
Int
)
.
Div
(
self
.
GasUsed
(),
ethutil
.
Big2
)
for
addr
,
ref
:=
range
self
.
state
.
Refunds
()
{
refund
:=
ethutil
.
BigMin
(
uhalf
,
ref
)
coinbaseSub
.
Add
(
self
.
gas
,
refund
)
self
.
state
.
AddBalance
([]
byte
(
addr
),
refund
.
Mul
(
refund
,
self
.
msg
.
GasPrice
()))
}
coinbase
,
sender
:=
self
.
Coinbase
(),
self
.
From
()
coinbase
.
RefundGas
(
coinbaseSub
,
self
.
msg
.
GasPrice
())
// Return remaining gas
remaining
:=
new
(
big
.
Int
)
.
Mul
(
self
.
gas
,
self
.
msg
.
GasPrice
())
sender
.
AddAmount
(
remaining
)
}
func
(
self
*
StateTransition
)
GasUsed
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Sub
(
self
.
initialGas
,
self
.
gas
)
}
core/transaction_pool.go
View file @
22d29a6d
...
@@ -106,8 +106,8 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
...
@@ -106,8 +106,8 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
return
fmt
.
Errorf
(
"No last block on the block chain"
)
return
fmt
.
Errorf
(
"No last block on the block chain"
)
}
}
if
len
(
tx
.
Recipient
)
!=
0
&&
len
(
tx
.
Recipient
)
!=
20
{
if
len
(
tx
.
To
())
!=
0
&&
len
(
tx
.
To
()
)
!=
20
{
return
fmt
.
Errorf
(
"Invalid recipient. len = %d"
,
len
(
tx
.
Recipient
))
return
fmt
.
Errorf
(
"Invalid recipient. len = %d"
,
len
(
tx
.
To
()
))
}
}
v
,
_
,
_
:=
tx
.
Curve
()
v
,
_
,
_
:=
tx
.
Curve
()
...
@@ -118,17 +118,11 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
...
@@ -118,17 +118,11 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
// Get the sender
// Get the sender
sender
:=
pool
.
chainManager
.
State
()
.
GetAccount
(
tx
.
Sender
())
sender
:=
pool
.
chainManager
.
State
()
.
GetAccount
(
tx
.
Sender
())
totAmount
:=
new
(
big
.
Int
)
.
Set
(
tx
.
Value
)
totAmount
:=
new
(
big
.
Int
)
.
Set
(
tx
.
Value
()
)
// Make sure there's enough in the sender's account. Having insufficient
// Make sure there's enough in the sender's account. Having insufficient
// funds won't invalidate this transaction but simple ignores it.
// funds won't invalidate this transaction but simple ignores it.
if
sender
.
Balance
()
.
Cmp
(
totAmount
)
<
0
{
if
sender
.
Balance
()
.
Cmp
(
totAmount
)
<
0
{
return
fmt
.
Errorf
(
"Insufficient amount in sender's (%x) account"
,
tx
.
Sender
())
return
fmt
.
Errorf
(
"Insufficient amount in sender's (%x) account"
,
tx
.
From
())
}
if
tx
.
IsContract
()
{
if
tx
.
GasPrice
.
Cmp
(
big
.
NewInt
(
minGasPrice
))
<
0
{
return
fmt
.
Errorf
(
"Gasprice too low, %s given should be at least %d."
,
tx
.
GasPrice
,
minGasPrice
)
}
}
}
// Increment the nonce making each tx valid only once to prevent replay
// Increment the nonce making each tx valid only once to prevent replay
...
@@ -154,10 +148,7 @@ func (self *TxPool) Add(tx *types.Transaction) error {
...
@@ -154,10 +148,7 @@ func (self *TxPool) Add(tx *types.Transaction) error {
self
.
addTransaction
(
tx
)
self
.
addTransaction
(
tx
)
tmp
:=
make
([]
byte
,
4
)
txplogger
.
Debugf
(
"(t) %x => %x (%v) %x
\n
"
,
tx
.
From
()[
:
4
],
tx
.
To
()[
:
4
],
tx
.
Value
,
tx
.
Hash
())
copy
(
tmp
,
tx
.
Recipient
)
txplogger
.
Debugf
(
"(t) %x => %x (%v) %x
\n
"
,
tx
.
Sender
()[
:
4
],
tmp
,
tx
.
Value
,
tx
.
Hash
())
// Notify the subscribers
// Notify the subscribers
go
self
.
eventMux
.
Post
(
TxPreEvent
{
tx
})
go
self
.
eventMux
.
Post
(
TxPreEvent
{
tx
})
...
@@ -204,7 +195,7 @@ func (pool *TxPool) RemoveInvalid(state *state.StateDB) {
...
@@ -204,7 +195,7 @@ func (pool *TxPool) RemoveInvalid(state *state.StateDB) {
tx
:=
e
.
Value
.
(
*
types
.
Transaction
)
tx
:=
e
.
Value
.
(
*
types
.
Transaction
)
sender
:=
state
.
GetAccount
(
tx
.
Sender
())
sender
:=
state
.
GetAccount
(
tx
.
Sender
())
err
:=
pool
.
ValidateTransaction
(
tx
)
err
:=
pool
.
ValidateTransaction
(
tx
)
if
err
!=
nil
||
sender
.
Nonce
>=
tx
.
Nonce
{
if
err
!=
nil
||
sender
.
Nonce
>=
tx
.
Nonce
()
{
pool
.
pool
.
Remove
(
e
)
pool
.
pool
.
Remove
(
e
)
}
}
}
}
...
...
core/types/transaction.go
View file @
22d29a6d
...
@@ -6,37 +6,30 @@ import (
...
@@ -6,37 +6,30 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/obscuren/secp256k1-go"
"github.com/obscuren/secp256k1-go"
)
)
var
ContractAddr
=
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
}
func
IsContractAddr
(
addr
[]
byte
)
bool
{
func
IsContractAddr
(
addr
[]
byte
)
bool
{
return
len
(
addr
)
==
0
return
len
(
addr
)
==
0
//return bytes.Compare(addr, ContractAddr) == 0
}
}
type
Transaction
struct
{
type
Transaction
struct
{
N
once
uint64
n
once
uint64
R
ecipient
[]
byte
r
ecipient
[]
byte
V
alue
*
big
.
Int
v
alue
*
big
.
Int
G
as
*
big
.
Int
g
as
*
big
.
Int
G
asPrice
*
big
.
Int
g
asPrice
*
big
.
Int
D
ata
[]
byte
d
ata
[]
byte
v
byte
v
byte
r
,
s
[]
byte
r
,
s
[]
byte
// Indicates whether this tx is a contract creation transaction
contractCreation
bool
}
}
func
NewContractCreationTx
(
value
,
gas
,
gasPrice
*
big
.
Int
,
script
[]
byte
)
*
Transaction
{
func
NewContractCreationTx
(
value
,
gas
,
gasPrice
*
big
.
Int
,
script
[]
byte
)
*
Transaction
{
return
&
Transaction
{
Recipient
:
nil
,
Value
:
value
,
Gas
:
gas
,
GasPrice
:
gasPrice
,
Data
:
script
,
contractCreation
:
true
}
return
&
Transaction
{
recipient
:
nil
,
value
:
value
,
gas
:
gas
,
gasPrice
:
gasPrice
,
data
:
script
}
}
}
func
NewTransactionMessage
(
to
[]
byte
,
value
,
gas
,
gasPrice
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
func
NewTransactionMessage
(
to
[]
byte
,
value
,
gas
,
gasPrice
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
return
&
Transaction
{
Recipient
:
to
,
Value
:
value
,
GasPrice
:
gasPrice
,
Gas
:
gas
,
Data
:
data
,
contractCreation
:
IsContractAddr
(
to
)
}
return
&
Transaction
{
recipient
:
to
,
value
:
value
,
gasPrice
:
gasPrice
,
gas
:
gas
,
data
:
data
}
}
}
func
NewTransactionFromBytes
(
data
[]
byte
)
*
Transaction
{
func
NewTransactionFromBytes
(
data
[]
byte
)
*
Transaction
{
...
@@ -53,33 +46,42 @@ func NewTransactionFromValue(val *ethutil.Value) *Transaction {
...
@@ -53,33 +46,42 @@ func NewTransactionFromValue(val *ethutil.Value) *Transaction {
return
tx
return
tx
}
}
func
(
self
*
Transaction
)
GasValue
()
*
big
.
Int
{
func
(
tx
*
Transaction
)
Hash
()
[]
byte
{
return
new
(
big
.
Int
)
.
Mul
(
self
.
Gas
,
self
.
GasPrice
)
data
:=
[]
interface
{}{
tx
.
Nonce
,
tx
.
gasPrice
,
tx
.
gas
,
tx
.
recipient
,
tx
.
Value
,
tx
.
Data
}
return
crypto
.
Sha3
(
ethutil
.
NewValue
(
data
)
.
Encode
())
}
}
func
(
self
*
Transaction
)
TotalValue
()
*
big
.
Int
{
func
(
self
*
Transaction
)
Data
()
[]
byte
{
v
:=
self
.
GasValue
()
return
self
.
data
return
v
.
Add
(
v
,
self
.
Value
)
}
}
func
(
tx
*
Transaction
)
Hash
()
[]
byte
{
func
(
self
*
Transaction
)
Gas
()
*
big
.
Int
{
data
:=
[]
interface
{}{
tx
.
Nonce
,
tx
.
GasPrice
,
tx
.
Gas
,
tx
.
Recipient
,
tx
.
Value
,
tx
.
Data
}
return
self
.
gas
}
return
crypto
.
Sha3
(
ethutil
.
NewValue
(
data
)
.
Encode
())
func
(
self
*
Transaction
)
GasPrice
()
*
big
.
Int
{
return
self
.
gasPrice
}
func
(
self
*
Transaction
)
Value
()
*
big
.
Int
{
return
self
.
value
}
}
func
(
tx
*
Transaction
)
CreatesContract
()
bool
{
func
(
self
*
Transaction
)
Nonce
()
uint64
{
return
tx
.
contractCreation
return
self
.
nonce
}
}
/* Deprecated */
func
(
self
*
Transaction
)
SetNonce
(
nonce
uint64
)
{
func
(
tx
*
Transaction
)
IsContract
()
bool
{
self
.
nonce
=
nonce
return
tx
.
CreatesContract
()
}
}
func
(
tx
*
Transaction
)
CreationAddress
(
state
*
state
.
StateDB
)
[]
byte
{
func
(
self
*
Transaction
)
From
()
[]
byte
{
// Generate a new address
return
self
.
Sender
()
return
crypto
.
Sha3
(
ethutil
.
NewValue
([]
interface
{}{
tx
.
Sender
(),
tx
.
Nonce
})
.
Encode
())[
12
:
]
}
func
(
self
*
Transaction
)
To
()
[]
byte
{
return
self
.
recipient
}
}
func
(
tx
*
Transaction
)
Curve
()
(
v
byte
,
r
[]
byte
,
s
[]
byte
)
{
func
(
tx
*
Transaction
)
Curve
()
(
v
byte
,
r
[]
byte
,
s
[]
byte
)
{
...
@@ -136,7 +138,7 @@ func (tx *Transaction) Sign(privk []byte) error {
...
@@ -136,7 +138,7 @@ func (tx *Transaction) Sign(privk []byte) error {
}
}
func
(
tx
*
Transaction
)
RlpData
()
interface
{}
{
func
(
tx
*
Transaction
)
RlpData
()
interface
{}
{
data
:=
[]
interface
{}{
tx
.
Nonce
,
tx
.
GasPrice
,
tx
.
Gas
,
tx
.
R
ecipient
,
tx
.
Value
,
tx
.
Data
}
data
:=
[]
interface
{}{
tx
.
Nonce
,
tx
.
GasPrice
,
tx
.
Gas
,
tx
.
r
ecipient
,
tx
.
Value
,
tx
.
Data
}
// TODO Remove prefixing zero's
// TODO Remove prefixing zero's
...
@@ -156,20 +158,16 @@ func (tx *Transaction) RlpDecode(data []byte) {
...
@@ -156,20 +158,16 @@ func (tx *Transaction) RlpDecode(data []byte) {
}
}
func
(
tx
*
Transaction
)
RlpValueDecode
(
decoder
*
ethutil
.
Value
)
{
func
(
tx
*
Transaction
)
RlpValueDecode
(
decoder
*
ethutil
.
Value
)
{
tx
.
N
once
=
decoder
.
Get
(
0
)
.
Uint
()
tx
.
n
once
=
decoder
.
Get
(
0
)
.
Uint
()
tx
.
G
asPrice
=
decoder
.
Get
(
1
)
.
BigInt
()
tx
.
g
asPrice
=
decoder
.
Get
(
1
)
.
BigInt
()
tx
.
G
as
=
decoder
.
Get
(
2
)
.
BigInt
()
tx
.
g
as
=
decoder
.
Get
(
2
)
.
BigInt
()
tx
.
R
ecipient
=
decoder
.
Get
(
3
)
.
Bytes
()
tx
.
r
ecipient
=
decoder
.
Get
(
3
)
.
Bytes
()
tx
.
V
alue
=
decoder
.
Get
(
4
)
.
BigInt
()
tx
.
v
alue
=
decoder
.
Get
(
4
)
.
BigInt
()
tx
.
D
ata
=
decoder
.
Get
(
5
)
.
Bytes
()
tx
.
d
ata
=
decoder
.
Get
(
5
)
.
Bytes
()
tx
.
v
=
byte
(
decoder
.
Get
(
6
)
.
Uint
())
tx
.
v
=
byte
(
decoder
.
Get
(
6
)
.
Uint
())
tx
.
r
=
decoder
.
Get
(
7
)
.
Bytes
()
tx
.
r
=
decoder
.
Get
(
7
)
.
Bytes
()
tx
.
s
=
decoder
.
Get
(
8
)
.
Bytes
()
tx
.
s
=
decoder
.
Get
(
8
)
.
Bytes
()
if
IsContractAddr
(
tx
.
Recipient
)
{
tx
.
contractCreation
=
true
}
}
}
func
(
tx
*
Transaction
)
String
()
string
{
func
(
tx
*
Transaction
)
String
()
string
{
...
@@ -188,12 +186,12 @@ func (tx *Transaction) String() string {
...
@@ -188,12 +186,12 @@ func (tx *Transaction) String() string {
S: 0x%x
S: 0x%x
`
,
`
,
tx
.
Hash
(),
tx
.
Hash
(),
len
(
tx
.
R
ecipient
)
==
0
,
len
(
tx
.
r
ecipient
)
==
0
,
tx
.
Sender
(),
tx
.
Sender
(),
tx
.
R
ecipient
,
tx
.
r
ecipient
,
tx
.
N
once
,
tx
.
n
once
,
tx
.
G
asPrice
,
tx
.
g
asPrice
,
tx
.
G
as
,
tx
.
g
as
,
tx
.
Value
,
tx
.
Value
,
tx
.
Data
,
tx
.
Data
,
tx
.
v
,
tx
.
v
,
...
@@ -221,5 +219,5 @@ func (s Transactions) GetRlp(i int) []byte { return ethutil.Rlp(s[i]) }
...
@@ -221,5 +219,5 @@ func (s Transactions) GetRlp(i int) []byte { return ethutil.Rlp(s[i]) }
type
TxByNonce
struct
{
Transactions
}
type
TxByNonce
struct
{
Transactions
}
func
(
s
TxByNonce
)
Less
(
i
,
j
int
)
bool
{
func
(
s
TxByNonce
)
Less
(
i
,
j
int
)
bool
{
return
s
.
Transactions
[
i
]
.
Nonce
<
s
.
Transactions
[
j
]
.
N
once
return
s
.
Transactions
[
i
]
.
nonce
<
s
.
Transactions
[
j
]
.
n
once
}
}
core/vm_env.go
View file @
22d29a6d
...
@@ -11,26 +11,26 @@ import (
...
@@ -11,26 +11,26 @@ import (
type
VMEnv
struct
{
type
VMEnv
struct
{
state
*
state
.
StateDB
state
*
state
.
StateDB
block
*
types
.
Block
block
*
types
.
Block
tx
*
types
.
Transaction
msg
Message
depth
int
depth
int
}
}
func
NewEnv
(
state
*
state
.
StateDB
,
tx
*
types
.
Transaction
,
block
*
types
.
Block
)
*
VMEnv
{
func
NewEnv
(
state
*
state
.
StateDB
,
msg
Message
,
block
*
types
.
Block
)
*
VMEnv
{
return
&
VMEnv
{
return
&
VMEnv
{
state
:
state
,
state
:
state
,
block
:
block
,
block
:
block
,
tx
:
tx
,
msg
:
msg
,
}
}
}
}
func
(
self
*
VMEnv
)
Origin
()
[]
byte
{
return
self
.
tx
.
Sender
()
}
func
(
self
*
VMEnv
)
Origin
()
[]
byte
{
return
self
.
msg
.
From
()
}
func
(
self
*
VMEnv
)
BlockNumber
()
*
big
.
Int
{
return
self
.
block
.
Number
}
func
(
self
*
VMEnv
)
BlockNumber
()
*
big
.
Int
{
return
self
.
block
.
Number
}
func
(
self
*
VMEnv
)
PrevHash
()
[]
byte
{
return
self
.
block
.
PrevHash
}
func
(
self
*
VMEnv
)
PrevHash
()
[]
byte
{
return
self
.
block
.
PrevHash
}
func
(
self
*
VMEnv
)
Coinbase
()
[]
byte
{
return
self
.
block
.
Coinbase
}
func
(
self
*
VMEnv
)
Coinbase
()
[]
byte
{
return
self
.
block
.
Coinbase
}
func
(
self
*
VMEnv
)
Time
()
int64
{
return
self
.
block
.
Time
}
func
(
self
*
VMEnv
)
Time
()
int64
{
return
self
.
block
.
Time
}
func
(
self
*
VMEnv
)
Difficulty
()
*
big
.
Int
{
return
self
.
block
.
Difficulty
}
func
(
self
*
VMEnv
)
Difficulty
()
*
big
.
Int
{
return
self
.
block
.
Difficulty
}
func
(
self
*
VMEnv
)
BlockHash
()
[]
byte
{
return
self
.
block
.
Hash
()
}
func
(
self
*
VMEnv
)
BlockHash
()
[]
byte
{
return
self
.
block
.
Hash
()
}
func
(
self
*
VMEnv
)
Value
()
*
big
.
Int
{
return
self
.
tx
.
Value
}
func
(
self
*
VMEnv
)
Value
()
*
big
.
Int
{
return
self
.
msg
.
Value
()
}
func
(
self
*
VMEnv
)
State
()
*
state
.
StateDB
{
return
self
.
state
}
func
(
self
*
VMEnv
)
State
()
*
state
.
StateDB
{
return
self
.
state
}
func
(
self
*
VMEnv
)
GasLimit
()
*
big
.
Int
{
return
self
.
block
.
GasLimit
}
func
(
self
*
VMEnv
)
GasLimit
()
*
big
.
Int
{
return
self
.
block
.
GasLimit
}
func
(
self
*
VMEnv
)
Depth
()
int
{
return
self
.
depth
}
func
(
self
*
VMEnv
)
Depth
()
int
{
return
self
.
depth
}
...
...
miner/miner.go
View file @
22d29a6d
...
@@ -236,8 +236,8 @@ func (self *Miner) finiliseTxs() types.Transactions {
...
@@ -236,8 +236,8 @@ func (self *Miner) finiliseTxs() types.Transactions {
key
:=
self
.
eth
.
KeyManager
()
key
:=
self
.
eth
.
KeyManager
()
for
i
,
ltx
:=
range
self
.
localTxs
{
for
i
,
ltx
:=
range
self
.
localTxs
{
tx
:=
types
.
NewTransactionMessage
(
ltx
.
To
,
ethutil
.
Big
(
ltx
.
Value
),
ethutil
.
Big
(
ltx
.
Gas
),
ethutil
.
Big
(
ltx
.
GasPrice
),
ltx
.
Data
)
tx
:=
types
.
NewTransactionMessage
(
ltx
.
To
,
ethutil
.
Big
(
ltx
.
Value
),
ethutil
.
Big
(
ltx
.
Gas
),
ethutil
.
Big
(
ltx
.
GasPrice
),
ltx
.
Data
)
tx
.
Nonce
=
state
.
GetNonce
(
self
.
Coinbase
)
tx
.
SetNonce
(
state
.
GetNonce
(
self
.
Coinbase
)
)
state
.
SetNonce
(
self
.
Coinbase
,
tx
.
Nonce
+
1
)
state
.
SetNonce
(
self
.
Coinbase
,
tx
.
Nonce
()
+
1
)
tx
.
Sign
(
key
.
PrivateKey
())
tx
.
Sign
(
key
.
PrivateKey
())
...
@@ -246,7 +246,7 @@ func (self *Miner) finiliseTxs() types.Transactions {
...
@@ -246,7 +246,7 @@ func (self *Miner) finiliseTxs() types.Transactions {
// Faster than append
// Faster than append
for
_
,
tx
:=
range
self
.
eth
.
TxPool
()
.
GetTransactions
()
{
for
_
,
tx
:=
range
self
.
eth
.
TxPool
()
.
GetTransactions
()
{
if
tx
.
GasPrice
.
Cmp
(
self
.
MinAcceptedGasPrice
)
>=
0
{
if
tx
.
GasPrice
()
.
Cmp
(
self
.
MinAcceptedGasPrice
)
>=
0
{
txs
[
actualSize
]
=
tx
txs
[
actualSize
]
=
tx
actualSize
++
actualSize
++
}
}
...
...
state/state.go
View file @
22d29a6d
...
@@ -23,14 +23,14 @@ type StateDB struct {
...
@@ -23,14 +23,14 @@ type StateDB struct {
manifest
*
Manifest
manifest
*
Manifest
refund
map
[
string
]
[]
refund
refund
map
[
string
]
*
big
.
Int
logs
Logs
logs
Logs
}
}
// Create a new state from a given trie
// Create a new state from a given trie
func
New
(
trie
*
trie
.
Trie
)
*
StateDB
{
func
New
(
trie
*
trie
.
Trie
)
*
StateDB
{
return
&
StateDB
{
Trie
:
trie
,
stateObjects
:
make
(
map
[
string
]
*
StateObject
),
manifest
:
NewManifest
(),
refund
:
make
(
map
[
string
]
[]
refund
)}
return
&
StateDB
{
Trie
:
trie
,
stateObjects
:
make
(
map
[
string
]
*
StateObject
),
manifest
:
NewManifest
(),
refund
:
make
(
map
[
string
]
*
big
.
Int
)}
}
}
func
(
self
*
StateDB
)
EmptyLogs
()
{
func
(
self
*
StateDB
)
EmptyLogs
()
{
...
@@ -55,12 +55,11 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int {
...
@@ -55,12 +55,11 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int {
return
ethutil
.
Big0
return
ethutil
.
Big0
}
}
type
refund
struct
{
func
(
self
*
StateDB
)
Refund
(
addr
[]
byte
,
gas
*
big
.
Int
)
{
gas
,
price
*
big
.
Int
if
self
.
refund
[
string
(
addr
)]
==
nil
{
}
self
.
refund
[
string
(
addr
)]
=
new
(
big
.
Int
)
}
func
(
self
*
StateDB
)
Refund
(
addr
[]
byte
,
gas
,
price
*
big
.
Int
)
{
self
.
refund
[
string
(
addr
)]
.
Add
(
self
.
refund
[
string
(
addr
)],
gas
)
self
.
refund
[
string
(
addr
)]
=
append
(
self
.
refund
[
string
(
addr
)],
refund
{
gas
,
price
})
}
}
func
(
self
*
StateDB
)
AddBalance
(
addr
[]
byte
,
amount
*
big
.
Int
)
{
func
(
self
*
StateDB
)
AddBalance
(
addr
[]
byte
,
amount
*
big
.
Int
)
{
...
@@ -211,7 +210,7 @@ func (self *StateDB) Copy() *StateDB {
...
@@ -211,7 +210,7 @@ func (self *StateDB) Copy() *StateDB {
}
}
for
addr
,
refund
:=
range
self
.
refund
{
for
addr
,
refund
:=
range
self
.
refund
{
state
.
refund
[
addr
]
=
refund
state
.
refund
[
addr
]
=
new
(
big
.
Int
)
.
Set
(
refund
)
}
}
logs
:=
make
(
Logs
,
len
(
self
.
logs
))
logs
:=
make
(
Logs
,
len
(
self
.
logs
))
...
@@ -273,23 +272,17 @@ func (s *StateDB) Sync() {
...
@@ -273,23 +272,17 @@ func (s *StateDB) Sync() {
func
(
self
*
StateDB
)
Empty
()
{
func
(
self
*
StateDB
)
Empty
()
{
self
.
stateObjects
=
make
(
map
[
string
]
*
StateObject
)
self
.
stateObjects
=
make
(
map
[
string
]
*
StateObject
)
self
.
refund
=
make
(
map
[
string
][]
refund
)
self
.
refund
=
make
(
map
[
string
]
*
big
.
Int
)
}
func
(
self
*
StateDB
)
Refunds
()
map
[
string
]
*
big
.
Int
{
return
self
.
refund
}
}
func
(
self
*
StateDB
)
Update
(
gasUsed
*
big
.
Int
)
{
func
(
self
*
StateDB
)
Update
(
gasUsed
*
big
.
Int
)
{
var
deleted
bool
var
deleted
bool
// Refund any gas that's left
self
.
refund
=
make
(
map
[
string
]
*
big
.
Int
)
// XXX THIS WILL CHANGE IN POC8
uhalf
:=
new
(
big
.
Int
)
.
Div
(
gasUsed
,
ethutil
.
Big2
)
for
addr
,
refs
:=
range
self
.
refund
{
for
_
,
ref
:=
range
refs
{
refund
:=
ethutil
.
BigMin
(
uhalf
,
ref
.
gas
)
self
.
GetStateObject
([]
byte
(
addr
))
.
AddBalance
(
refund
.
Mul
(
refund
,
ref
.
price
))
}
}
self
.
refund
=
make
(
map
[
string
][]
refund
)
for
_
,
stateObject
:=
range
self
.
stateObjects
{
for
_
,
stateObject
:=
range
self
.
stateObjects
{
if
stateObject
.
remove
{
if
stateObject
.
remove
{
...
...
tests/files/StateTests/stInitCodeTest.json
0 → 100644
View file @
22d29a6d
This diff is collapsed.
Click to expand it.
tests/files/StateTests/stRefundTest.json
0 → 100644
View file @
22d29a6d
This diff is collapsed.
Click to expand it.
tests/files/StateTests/stSystemOperationsTest.json
View file @
22d29a6d
...
@@ -5827,4 +5827,4 @@
...
@@ -5827,4 +5827,4 @@
"value"
:
"100000"
"value"
:
"100000"
}
}
}
}
}
}
\ No newline at end of file
tests/files/StateTests/stTransactionTest.json
0 → 100644
View file @
22d29a6d
{
"EmptyTransaction"
:
{
"env"
:
{
"currentCoinbase"
:
"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
,
"currentDifficulty"
:
"45678256"
,
"currentGasLimit"
:
"1000000"
,
"currentNumber"
:
"0"
,
"currentTimestamp"
:
1
,
"previousHash"
:
"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"logs"
:
[
],
"out"
:
"0x"
,
"post"
:
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"
:
{
"balance"
:
"100000"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
}
},
"pre"
:
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"
:
{
"balance"
:
"100000"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
}
},
"transaction"
:
{
"data"
:
""
,
"gasLimit"
:
""
,
"gasPrice"
:
""
,
"nonce"
:
""
,
"secretKey"
:
"45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
,
"to"
:
""
,
"value"
:
""
}
},
"TransactionFromCoinbaseNotEnoughFounds"
:
{
"env"
:
{
"currentCoinbase"
:
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"
,
"currentDifficulty"
:
"45678256"
,
"currentGasLimit"
:
"1100"
,
"currentNumber"
:
"0"
,
"currentTimestamp"
:
1
,
"previousHash"
:
"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"logs"
:
[
],
"out"
:
"0x"
,
"post"
:
{
"b94f5374fce5edbc8e2a8697c15331677e6ebf0b"
:
{
"balance"
:
"1000"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
}
},
"pre"
:
{
"b94f5374fce5edbc8e2a8697c15331677e6ebf0b"
:
{
"balance"
:
"1000"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
}
},
"transaction"
:
{
"data"
:
""
,
"gasLimit"
:
"600"
,
"gasPrice"
:
"1"
,
"nonce"
:
""
,
"secretKey"
:
"45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
,
"to"
:
"b94f5374fce5edbc8e2a8697c15331677e6ebf0b"
,
"value"
:
"502"
}
},
"TransactionSendingToEmpty"
:
{
"env"
:
{
"currentCoinbase"
:
"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
,
"currentDifficulty"
:
"45678256"
,
"currentGasLimit"
:
"1000000"
,
"currentNumber"
:
"0"
,
"currentTimestamp"
:
1
,
"previousHash"
:
"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"logs"
:
[
],
"out"
:
"0x"
,
"post"
:
{
"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
:
{
"balance"
:
"500"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
},
"6295ee1b4f6dd65047762f924ecd367c17eabf8f"
:
{
"balance"
:
"0"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"
:
{
"balance"
:
"99500"
,
"code"
:
"0x"
,
"nonce"
:
"1"
,
"storage"
:
{
}
}
},
"pre"
:
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"
:
{
"balance"
:
"100000"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
}
},
"transaction"
:
{
"data"
:
""
,
"gasLimit"
:
"500"
,
"gasPrice"
:
"1"
,
"nonce"
:
""
,
"secretKey"
:
"45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
,
"to"
:
""
,
"value"
:
""
}
},
"TransactionSendingToZero"
:
{
"env"
:
{
"currentCoinbase"
:
"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
,
"currentDifficulty"
:
"45678256"
,
"currentGasLimit"
:
"1000000"
,
"currentNumber"
:
"0"
,
"currentTimestamp"
:
1
,
"previousHash"
:
"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"logs"
:
[
],
"out"
:
"0x"
,
"post"
:
{
"0000000000000000000000000000000000000000"
:
{
"balance"
:
"1"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
},
"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
:
{
"balance"
:
"500"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"
:
{
"balance"
:
"99499"
,
"code"
:
"0x"
,
"nonce"
:
"1"
,
"storage"
:
{
}
}
},
"pre"
:
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"
:
{
"balance"
:
"100000"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
}
},
"transaction"
:
{
"data"
:
""
,
"gasLimit"
:
"5000"
,
"gasPrice"
:
"1"
,
"nonce"
:
""
,
"secretKey"
:
"45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
,
"to"
:
"0000000000000000000000000000000000000000"
,
"value"
:
"1"
}
},
"TransactionToItself"
:
{
"env"
:
{
"currentCoinbase"
:
"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
,
"currentDifficulty"
:
"45678256"
,
"currentGasLimit"
:
"1000000"
,
"currentNumber"
:
"0"
,
"currentTimestamp"
:
1
,
"previousHash"
:
"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"logs"
:
[
],
"out"
:
"0x"
,
"post"
:
{
"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
:
{
"balance"
:
"500"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"
:
{
"balance"
:
"99500"
,
"code"
:
"0x"
,
"nonce"
:
"1"
,
"storage"
:
{
}
}
},
"pre"
:
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"
:
{
"balance"
:
"100000"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
}
},
"transaction"
:
{
"data"
:
""
,
"gasLimit"
:
"5000"
,
"gasPrice"
:
"1"
,
"nonce"
:
""
,
"secretKey"
:
"45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
,
"to"
:
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"
,
"value"
:
"1"
}
},
"TransactionToItselfNotEnoughFounds"
:
{
"env"
:
{
"currentCoinbase"
:
"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
,
"currentDifficulty"
:
"45678256"
,
"currentGasLimit"
:
"1000000"
,
"currentNumber"
:
"0"
,
"currentTimestamp"
:
1
,
"previousHash"
:
"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"logs"
:
[
],
"out"
:
"0x"
,
"post"
:
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"
:
{
"balance"
:
"1101"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
}
},
"pre"
:
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"
:
{
"balance"
:
"1101"
,
"code"
:
"0x"
,
"nonce"
:
"0"
,
"storage"
:
{
}
}
},
"transaction"
:
{
"data"
:
""
,
"gasLimit"
:
"600"
,
"gasPrice"
:
"1"
,
"nonce"
:
""
,
"secretKey"
:
"45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
,
"to"
:
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"
,
"value"
:
"502"
}
}
}
\ No newline at end of file
tests/files/VMTests/vmArithmeticTest.json
View file @
22d29a6d
This diff is collapsed.
Click to expand it.
tests/files/index.js
View file @
22d29a6d
...
@@ -8,12 +8,17 @@ module.exports = {
...
@@ -8,12 +8,17 @@ module.exports = {
trietestnextprev
:
require
(
'./TrieTests/trietestnextprev'
),
trietestnextprev
:
require
(
'./TrieTests/trietestnextprev'
),
txtest
:
require
(
'./BasicTests/txtest'
),
txtest
:
require
(
'./BasicTests/txtest'
),
StateTests
:
{
StateTests
:
{
stExample
:
require
(
'./StateTests/stExample.json'
),
stInitCodeTest
:
require
(
'./StateTests/stInitCodeTest.json'
),
stLogTests
:
require
(
'./StateTests/stLogTests.json'
),
stPreCompiledContracts
:
require
(
'./StateTests/stPreCompiledContracts'
),
stPreCompiledContracts
:
require
(
'./StateTests/stPreCompiledContracts'
),
stRecursiveCreate
:
require
(
'./StateTests/stRecursiveCreate'
),
stRecursiveCreate
:
require
(
'./StateTests/stRecursiveCreate'
),
stSpecial
:
require
(
'./StateTests/stSpecialTest'
),
stSpecial
:
require
(
'./StateTests/stSpecialTest'
),
stSystemOperationsTest
:
require
(
'./StateTests/stSystemOperationsTest'
),
stSystemOperationsTest
:
require
(
'./StateTests/stSystemOperationsTest'
),
stTransactionTest
:
require
(
'./StateTests/stTransactionTest'
)
},
},
VMTests
:
{
VMTests
:
{
vmRandom
:
require
(
'./VMTests/RandomTests/randomTest'
),
vmArithmeticTest
:
require
(
'./VMTests/vmArithmeticTest'
),
vmArithmeticTest
:
require
(
'./VMTests/vmArithmeticTest'
),
vmBitwiseLogicOperationTest
:
require
(
'./VMTests/vmBitwiseLogicOperationTest'
),
vmBitwiseLogicOperationTest
:
require
(
'./VMTests/vmBitwiseLogicOperationTest'
),
vmBlockInfoTest
:
require
(
'./VMTests/vmBlockInfoTest'
),
vmBlockInfoTest
:
require
(
'./VMTests/vmBlockInfoTest'
),
...
@@ -22,6 +27,6 @@ module.exports = {
...
@@ -22,6 +27,6 @@ module.exports = {
vmLogTest
:
require
(
'./VMTests/vmLogTest'
),
vmLogTest
:
require
(
'./VMTests/vmLogTest'
),
vmPushDupSwapTest
:
require
(
'./VMTests/vmPushDupSwapTest'
),
vmPushDupSwapTest
:
require
(
'./VMTests/vmPushDupSwapTest'
),
vmSha3Test
:
require
(
'./VMTests/vmSha3Test'
),
vmSha3Test
:
require
(
'./VMTests/vmSha3Test'
),
vmtests
:
require
(
'./VMTests/vmtests'
)
,
vmtests
:
require
(
'./VMTests/vmtests'
)
}
}
};
};
tests/helper/vm.go
View file @
22d29a6d
...
@@ -44,6 +44,7 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
...
@@ -44,6 +44,7 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
env
.
time
=
ethutil
.
Big
(
envValues
[
"currentTimestamp"
])
.
Int64
()
env
.
time
=
ethutil
.
Big
(
envValues
[
"currentTimestamp"
])
.
Int64
()
env
.
difficulty
=
ethutil
.
Big
(
envValues
[
"currentDifficulty"
])
env
.
difficulty
=
ethutil
.
Big
(
envValues
[
"currentDifficulty"
])
env
.
gasLimit
=
ethutil
.
Big
(
envValues
[
"currentGasLimit"
])
env
.
gasLimit
=
ethutil
.
Big
(
envValues
[
"currentGasLimit"
])
env
.
Gas
=
new
(
big
.
Int
)
return
env
return
env
}
}
...
@@ -110,7 +111,7 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Log
...
@@ -110,7 +111,7 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Log
return
ret
,
vmenv
.
logs
,
vmenv
.
Gas
,
err
return
ret
,
vmenv
.
logs
,
vmenv
.
Gas
,
err
}
}
func
RunState
(
state
*
state
.
StateDB
,
env
,
tx
map
[
string
]
string
)
([]
byte
,
state
.
Logs
,
*
big
.
Int
,
error
)
{
func
RunState
(
state
db
*
state
.
StateDB
,
env
,
tx
map
[
string
]
string
)
([]
byte
,
state
.
Logs
,
*
big
.
Int
,
error
)
{
var
(
var
(
keyPair
,
_
=
crypto
.
NewKeyPairFromSec
([]
byte
(
ethutil
.
Hex2Bytes
(
tx
[
"secretKey"
])))
keyPair
,
_
=
crypto
.
NewKeyPairFromSec
([]
byte
(
ethutil
.
Hex2Bytes
(
tx
[
"secretKey"
])))
to
=
FromHex
(
tx
[
"to"
])
to
=
FromHex
(
tx
[
"to"
])
...
@@ -118,13 +119,39 @@ func RunState(state *state.StateDB, env, tx map[string]string) ([]byte, state.Lo
...
@@ -118,13 +119,39 @@ func RunState(state *state.StateDB, env, tx map[string]string) ([]byte, state.Lo
gas
=
ethutil
.
Big
(
tx
[
"gasLimit"
])
gas
=
ethutil
.
Big
(
tx
[
"gasLimit"
])
price
=
ethutil
.
Big
(
tx
[
"gasPrice"
])
price
=
ethutil
.
Big
(
tx
[
"gasPrice"
])
value
=
ethutil
.
Big
(
tx
[
"value"
])
value
=
ethutil
.
Big
(
tx
[
"value"
])
caddr
=
FromHex
(
env
[
"currentCoinbase"
])
)
)
caller
:=
state
.
GetOrNewStateObject
(
keyPair
.
Address
())
coinbase
:=
statedb
.
GetOrNewStateObject
(
caddr
)
coinbase
.
SetGasPool
(
ethutil
.
Big
(
env
[
"currentGasLimit"
]))
vmenv
:=
NewEnvFromMap
(
state
,
env
,
tx
)
message
:=
NewMessage
(
keyPair
.
Address
(),
to
,
data
,
value
,
gas
,
price
)
vmenv
.
origin
=
caller
.
Address
()
Log
.
DebugDetailf
(
"message{ to: %x, from %x, value: %v, gas: %v, price: %v }
\n
"
,
message
.
to
[
:
4
],
message
.
from
[
:
4
],
message
.
value
,
message
.
gas
,
message
.
price
)
ret
,
err
:=
vmenv
.
Call
(
caller
,
to
,
data
,
gas
,
price
,
value
)
st
:=
core
.
NewStateTransition
(
coinbase
,
message
,
statedb
,
nil
)
vmenv
:=
NewEnvFromMap
(
statedb
,
env
,
tx
)
vmenv
.
origin
=
keyPair
.
Address
()
st
.
Env
=
vmenv
ret
,
err
:=
st
.
TransitionState
()
statedb
.
Update
(
vmenv
.
Gas
)
return
ret
,
vmenv
.
logs
,
vmenv
.
Gas
,
err
return
ret
,
vmenv
.
logs
,
vmenv
.
Gas
,
err
}
}
type
Message
struct
{
from
,
to
[]
byte
value
,
gas
,
price
*
big
.
Int
data
[]
byte
}
func
NewMessage
(
from
,
to
,
data
[]
byte
,
value
,
gas
,
price
*
big
.
Int
)
Message
{
return
Message
{
from
,
to
,
value
,
gas
,
price
,
data
}
}
func
(
self
Message
)
Hash
()
[]
byte
{
return
nil
}
func
(
self
Message
)
From
()
[]
byte
{
return
self
.
from
}
func
(
self
Message
)
To
()
[]
byte
{
return
self
.
to
}
func
(
self
Message
)
GasPrice
()
*
big
.
Int
{
return
self
.
price
}
func
(
self
Message
)
Gas
()
*
big
.
Int
{
return
self
.
gas
}
func
(
self
Message
)
Value
()
*
big
.
Int
{
return
self
.
value
}
func
(
self
Message
)
Nonce
()
uint64
{
return
0
}
func
(
self
Message
)
Data
()
[]
byte
{
return
self
.
data
}
tests/vm/gh_test.go
View file @
22d29a6d
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/tests/helper"
"github.com/ethereum/go-ethereum/tests/helper"
)
)
...
@@ -81,6 +82,9 @@ func RunVmTest(p string, t *testing.T) {
...
@@ -81,6 +82,9 @@ func RunVmTest(p string, t *testing.T) {
for
addr
,
account
:=
range
test
.
Pre
{
for
addr
,
account
:=
range
test
.
Pre
{
obj
:=
StateObjectFromAccount
(
addr
,
account
)
obj
:=
StateObjectFromAccount
(
addr
,
account
)
statedb
.
SetStateObject
(
obj
)
statedb
.
SetStateObject
(
obj
)
for
a
,
v
:=
range
account
.
Storage
{
obj
.
SetState
(
helper
.
FromHex
(
a
),
ethutil
.
NewValue
(
helper
.
FromHex
(
v
)))
}
}
}
// XXX Yeah, yeah...
// XXX Yeah, yeah...
...
@@ -129,6 +133,16 @@ func RunVmTest(p string, t *testing.T) {
...
@@ -129,6 +133,16 @@ func RunVmTest(p string, t *testing.T) {
for
addr
,
account
:=
range
test
.
Post
{
for
addr
,
account
:=
range
test
.
Post
{
obj
:=
statedb
.
GetStateObject
(
helper
.
FromHex
(
addr
))
obj
:=
statedb
.
GetStateObject
(
helper
.
FromHex
(
addr
))
if
obj
==
nil
{
continue
}
if
len
(
test
.
Exec
)
==
0
{
if
obj
.
Balance
()
.
Cmp
(
ethutil
.
Big
(
account
.
Balance
))
!=
0
{
t
.
Errorf
(
"%s's : (%x) balance failed. Expected %v, got %v => %v
\n
"
,
name
,
obj
.
Address
()[
:
4
],
account
.
Balance
,
obj
.
Balance
(),
new
(
big
.
Int
)
.
Sub
(
ethutil
.
Big
(
account
.
Balance
),
obj
.
Balance
()))
}
}
for
addr
,
value
:=
range
account
.
Storage
{
for
addr
,
value
:=
range
account
.
Storage
{
v
:=
obj
.
GetState
(
helper
.
FromHex
(
addr
))
.
Bytes
()
v
:=
obj
.
GetState
(
helper
.
FromHex
(
addr
))
.
Bytes
()
vexp
:=
helper
.
FromHex
(
value
)
vexp
:=
helper
.
FromHex
(
value
)
...
@@ -149,6 +163,7 @@ func RunVmTest(p string, t *testing.T) {
...
@@ -149,6 +163,7 @@ func RunVmTest(p string, t *testing.T) {
}
}
}
}
}
}
logger
.
Flush
()
}
}
// I've created a new function for each tests so it's easier to identify where the problem lies if any of them fail.
// I've created a new function for each tests so it's easier to identify where the problem lies if any of them fail.
...
@@ -212,7 +227,12 @@ func TestStateRecursiveCreate(t *testing.T) {
...
@@ -212,7 +227,12 @@ func TestStateRecursiveCreate(t *testing.T) {
RunVmTest
(
fn
,
t
)
RunVmTest
(
fn
,
t
)
}
}
func
TestStateSpecial
Test
(
t
*
testing
.
T
)
{
func
TestStateSpecial
(
t
*
testing
.
T
)
{
const
fn
=
"../files/StateTests/stSpecialTest.json"
const
fn
=
"../files/StateTests/stSpecialTest.json"
RunVmTest
(
fn
,
t
)
RunVmTest
(
fn
,
t
)
}
}
func
TestStateRefund
(
t
*
testing
.
T
)
{
const
fn
=
"../files/StateTests/stRefundTest.json"
RunVmTest
(
fn
,
t
)
}
vm/common.go
View file @
22d29a6d
...
@@ -37,7 +37,7 @@ var (
...
@@ -37,7 +37,7 @@ var (
GasLog
=
big
.
NewInt
(
32
)
GasLog
=
big
.
NewInt
(
32
)
GasSha256
=
big
.
NewInt
(
50
)
GasSha256
=
big
.
NewInt
(
50
)
GasRipemd
=
big
.
NewInt
(
50
)
GasRipemd
=
big
.
NewInt
(
50
)
GasEcrecover
=
big
.
NewInt
(
1
00
)
GasEcrecover
=
big
.
NewInt
(
5
00
)
Pow256
=
ethutil
.
BigPow
(
2
,
256
)
Pow256
=
ethutil
.
BigPow
(
2
,
256
)
...
...
vm/vm_debug.go
View file @
22d29a6d
...
@@ -2,6 +2,7 @@ package vm
...
@@ -2,6 +2,7 @@ package vm
import
(
import
(
"fmt"
"fmt"
"math"
"math/big"
"math/big"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
...
@@ -112,7 +113,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
...
@@ -112,7 +113,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
return
closure
.
Return
(
nil
),
nil
return
closure
.
Return
(
nil
),
nil
}
}
vmlogger
.
Debugf
(
"(%d)
%x gas: %v (d) %x
\n
"
,
self
.
env
.
Depth
()
,
closure
.
Address
(),
closure
.
Gas
,
callData
)
vmlogger
.
Debugf
(
"(%d)
(%x) %x gas: %v (d) %x
\n
"
,
self
.
env
.
Depth
(),
caller
.
Address
()[
:
4
]
,
closure
.
Address
(),
closure
.
Gas
,
callData
)
for
{
for
{
prevStep
=
step
prevStep
=
step
...
@@ -180,16 +181,17 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
...
@@ -180,16 +181,17 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
var
mult
*
big
.
Int
var
mult
*
big
.
Int
y
,
x
:=
stack
.
Peekn
()
y
,
x
:=
stack
.
Peekn
()
val
:=
closure
.
GetStorage
(
x
)
//val := closure.GetStorage(x)
if
val
.
BigInt
()
.
Cmp
(
ethutil
.
Big0
)
==
0
&&
len
(
y
.
Bytes
())
>
0
{
val
:=
statedb
.
GetState
(
closure
.
Address
(),
x
.
Bytes
())
if
len
(
val
)
==
0
&&
len
(
y
.
Bytes
())
>
0
{
// 0 => non 0
// 0 => non 0
mult
=
ethutil
.
Big3
mult
=
ethutil
.
Big3
}
else
if
val
.
BigInt
()
.
Cmp
(
ethutil
.
Big0
)
!=
0
&&
len
(
y
.
Bytes
())
==
0
{
}
else
if
len
(
val
)
>
0
&&
len
(
y
.
Bytes
())
==
0
{
statedb
.
Refund
(
c
losure
.
caller
.
Address
(),
GasSStoreRefund
,
closure
.
Price
)
statedb
.
Refund
(
c
aller
.
Address
(),
GasSStoreRefund
)
mult
=
ethutil
.
Big0
mult
=
ethutil
.
Big0
}
else
{
}
else
{
// non 0 => non 0
// non 0 => non 0
(or 0 => 0)
mult
=
ethutil
.
Big1
mult
=
ethutil
.
Big1
}
}
gas
.
Set
(
new
(
big
.
Int
)
.
Mul
(
mult
,
GasSStore
))
gas
.
Set
(
new
(
big
.
Int
)
.
Mul
(
mult
,
GasSStore
))
...
@@ -660,7 +662,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
...
@@ -660,7 +662,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
cOff
=
0
cOff
=
0
l
=
0
l
=
0
}
else
if
cOff
+
l
>
size
{
}
else
if
cOff
+
l
>
size
{
l
=
0
l
=
uint64
(
math
.
Min
(
float64
(
cOff
+
l
),
float64
(
size
)))
}
}
codeCopy
:=
code
[
cOff
:
cOff
+
l
]
codeCopy
:=
code
[
cOff
:
cOff
+
l
]
...
@@ -776,10 +778,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
...
@@ -776,10 +778,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
val
,
loc
:=
stack
.
Popn
()
val
,
loc
:=
stack
.
Popn
()
statedb
.
SetState
(
closure
.
Address
(),
loc
.
Bytes
(),
val
)
statedb
.
SetState
(
closure
.
Address
(),
loc
.
Bytes
(),
val
)
// Debug sessions are allowed to run without message
closure
.
message
.
AddStorageChange
(
loc
.
Bytes
())
if
closure
.
message
!=
nil
{
closure
.
message
.
AddStorageChange
(
loc
.
Bytes
())
}
self
.
Printf
(
" {0x%x : 0x%x}"
,
loc
.
Bytes
(),
val
.
Bytes
())
self
.
Printf
(
" {0x%x : 0x%x}"
,
loc
.
Bytes
(),
val
.
Bytes
())
case
JUMP
:
case
JUMP
:
...
@@ -898,10 +897,12 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
...
@@ -898,10 +897,12 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
return
closure
.
Return
(
ret
),
nil
return
closure
.
Return
(
ret
),
nil
case
SUICIDE
:
case
SUICIDE
:
receiver
:=
statedb
.
GetOrNewStateObject
(
stack
.
Pop
()
.
Bytes
())
receiver
:=
statedb
.
GetOrNewStateObject
(
stack
.
Pop
()
.
Bytes
())
balance
:=
statedb
.
GetBalance
(
closure
.
Address
())
self
.
Printf
(
" => (%x) %v"
,
receiver
.
Address
()[
:
4
],
balance
)
receiver
.
AddAmount
(
statedb
.
GetBalance
(
closure
.
Address
())
)
receiver
.
AddAmount
(
balance
)
statedb
.
Delete
(
closure
.
Address
())
statedb
.
Delete
(
closure
.
Address
())
fallthrough
fallthrough
...
...
xeth/hexface.go
View file @
22d29a6d
...
@@ -211,7 +211,7 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
...
@@ -211,7 +211,7 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
return
""
,
err
return
""
,
err
}
}
if
types
.
IsContractAddr
(
to
)
{
if
types
.
IsContractAddr
(
to
)
{
return
ethutil
.
Bytes2Hex
(
tx
.
CreationAddress
(
nil
)),
nil
return
ethutil
.
Bytes2Hex
(
core
.
AddressFromMessage
(
tx
)),
nil
}
}
return
ethutil
.
Bytes2Hex
(
tx
.
Hash
()),
nil
return
ethutil
.
Bytes2Hex
(
tx
.
Hash
()),
nil
...
@@ -224,7 +224,7 @@ func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) {
...
@@ -224,7 +224,7 @@ func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) {
return
nil
,
err
return
nil
,
err
}
}
return
NewJSReciept
(
tx
.
CreatesContract
(),
tx
.
CreationAddress
(
self
.
World
()
.
State
()),
tx
.
Hash
(),
tx
.
Sender
()),
nil
return
NewJSReciept
(
core
.
MessageCreatesContract
(
tx
),
core
.
AddressFromMessage
(
tx
),
tx
.
Hash
(),
tx
.
From
()),
nil
}
}
func
(
self
*
JSXEth
)
CompileMutan
(
code
string
)
string
{
func
(
self
*
JSXEth
)
CompileMutan
(
code
string
)
string
{
...
...
xeth/js_types.go
View file @
22d29a6d
...
@@ -96,21 +96,21 @@ type JSTransaction struct {
...
@@ -96,21 +96,21 @@ type JSTransaction struct {
func
NewJSTx
(
tx
*
types
.
Transaction
,
state
*
state
.
StateDB
)
*
JSTransaction
{
func
NewJSTx
(
tx
*
types
.
Transaction
,
state
*
state
.
StateDB
)
*
JSTransaction
{
hash
:=
ethutil
.
Bytes2Hex
(
tx
.
Hash
())
hash
:=
ethutil
.
Bytes2Hex
(
tx
.
Hash
())
receiver
:=
ethutil
.
Bytes2Hex
(
tx
.
Recipient
)
receiver
:=
ethutil
.
Bytes2Hex
(
tx
.
To
()
)
if
receiver
==
"0000000000000000000000000000000000000000"
{
if
receiver
==
"0000000000000000000000000000000000000000"
{
receiver
=
ethutil
.
Bytes2Hex
(
tx
.
CreationAddress
(
state
))
receiver
=
ethutil
.
Bytes2Hex
(
core
.
AddressFromMessage
(
tx
))
}
}
sender
:=
ethutil
.
Bytes2Hex
(
tx
.
Sender
())
sender
:=
ethutil
.
Bytes2Hex
(
tx
.
Sender
())
createsContract
:=
tx
.
CreatesContract
(
)
createsContract
:=
core
.
MessageCreatesContract
(
tx
)
var
data
string
var
data
string
if
tx
.
CreatesContract
()
{
if
createsContract
{
data
=
strings
.
Join
(
core
.
Disassemble
(
tx
.
Data
),
"
\n
"
)
data
=
strings
.
Join
(
core
.
Disassemble
(
tx
.
Data
()
),
"
\n
"
)
}
else
{
}
else
{
data
=
ethutil
.
Bytes2Hex
(
tx
.
Data
)
data
=
ethutil
.
Bytes2Hex
(
tx
.
Data
()
)
}
}
return
&
JSTransaction
{
ref
:
tx
,
Hash
:
hash
,
Value
:
ethutil
.
CurrencyToString
(
tx
.
Value
),
Address
:
receiver
,
Contract
:
tx
.
CreatesContract
(),
Gas
:
tx
.
Gas
.
String
(),
GasPrice
:
tx
.
GasPrice
.
String
(),
Data
:
data
,
Sender
:
sender
,
CreatesContract
:
createsContract
,
RawData
:
ethutil
.
Bytes2Hex
(
tx
.
Data
)}
return
&
JSTransaction
{
ref
:
tx
,
Hash
:
hash
,
Value
:
ethutil
.
CurrencyToString
(
tx
.
Value
()),
Address
:
receiver
,
Contract
:
createsContract
,
Gas
:
tx
.
Gas
()
.
String
(),
GasPrice
:
tx
.
GasPrice
()
.
String
(),
Data
:
data
,
Sender
:
sender
,
CreatesContract
:
createsContract
,
RawData
:
ethutil
.
Bytes2Hex
(
tx
.
Data
()
)}
}
}
func
(
self
*
JSTransaction
)
ToString
()
string
{
func
(
self
*
JSTransaction
)
ToString
()
string
{
...
...
xeth/pipe.go
View file @
22d29a6d
...
@@ -134,7 +134,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et
...
@@ -134,7 +134,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et
state
:=
self
.
chainManager
.
TransState
()
state
:=
self
.
chainManager
.
TransState
()
nonce
:=
state
.
GetNonce
(
key
.
Address
())
nonce
:=
state
.
GetNonce
(
key
.
Address
())
tx
.
Nonce
=
nonce
tx
.
SetNonce
(
nonce
)
tx
.
Sign
(
key
.
PrivateKey
)
tx
.
Sign
(
key
.
PrivateKey
)
// Do some pre processing for our "pre" events and hooks
// Do some pre processing for our "pre" events and hooks
...
@@ -150,7 +150,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et
...
@@ -150,7 +150,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et
state
.
SetNonce
(
key
.
Address
(),
nonce
+
1
)
state
.
SetNonce
(
key
.
Address
(),
nonce
+
1
)
if
contractCreation
{
if
contractCreation
{
addr
:=
tx
.
CreationAddress
(
self
.
World
()
.
State
()
)
addr
:=
core
.
AddressFromMessage
(
tx
)
pipelogger
.
Infof
(
"Contract addr %x
\n
"
,
addr
)
pipelogger
.
Infof
(
"Contract addr %x
\n
"
,
addr
)
}
}
...
@@ -163,8 +163,8 @@ func (self *XEth) PushTx(tx *types.Transaction) ([]byte, error) {
...
@@ -163,8 +163,8 @@ func (self *XEth) PushTx(tx *types.Transaction) ([]byte, error) {
return
nil
,
err
return
nil
,
err
}
}
if
tx
.
Recipient
==
nil
{
if
tx
.
To
()
==
nil
{
addr
:=
tx
.
CreationAddress
(
self
.
World
()
.
State
()
)
addr
:=
core
.
AddressFromMessage
(
tx
)
pipelogger
.
Infof
(
"Contract addr %x
\n
"
,
addr
)
pipelogger
.
Infof
(
"Contract addr %x
\n
"
,
addr
)
return
addr
,
nil
return
addr
,
nil
}
}
...
...
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