aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-06-04 01:29:47 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-06-04 01:29:47 +0800
commit861031491860c69f29e1444c22dd84c38abfedf4 (patch)
tree0025aeed5a7c93044e6772623e7b0e7ced6e9818
parent71d9367edcc5c42b1054fa6ad69e5b4fd954fd40 (diff)
parent147a699c6543b1e4ec8c933f8aaff4e0639897b6 (diff)
downloaddexon-861031491860c69f29e1444c22dd84c38abfedf4.tar
dexon-861031491860c69f29e1444c22dd84c38abfedf4.tar.gz
dexon-861031491860c69f29e1444c22dd84c38abfedf4.tar.bz2
dexon-861031491860c69f29e1444c22dd84c38abfedf4.tar.lz
dexon-861031491860c69f29e1444c22dd84c38abfedf4.tar.xz
dexon-861031491860c69f29e1444c22dd84c38abfedf4.tar.zst
dexon-861031491860c69f29e1444c22dd84c38abfedf4.zip
Merge pull request #1167 from Gustav-Simonsson/check_ec_recover_err
Add missing err checks on From()
-rw-r--r--cmd/geth/admin.go1
-rw-r--r--core/state_transition.go35
-rw-r--r--core/transaction_pool.go2
-rw-r--r--xeth/types.go5
4 files changed, 25 insertions, 18 deletions
diff --git a/cmd/geth/admin.go b/cmd/geth/admin.go
index f0be444c6..01de97ac2 100644
--- a/cmd/geth/admin.go
+++ b/cmd/geth/admin.go
@@ -160,7 +160,6 @@ func (js *jsre) pendingTransactions(call otto.FunctionCall) otto.Value {
//ltxs := make([]*tx, len(txs))
var ltxs []*tx
for _, tx := range txs {
- // no need to check err
if from, _ := tx.From(); accountSet.Has(from) {
ltxs = append(ltxs, newTx(tx))
}
diff --git a/core/state_transition.go b/core/state_transition.go
index 3d11a0464..7672fa3ff 100644
--- a/core/state_transition.go
+++ b/core/state_transition.go
@@ -62,7 +62,6 @@ type Message interface {
func AddressFromMessage(msg Message) common.Address {
from, _ := msg.From()
-
return crypto.CreateAddress(from, msg.Nonce())
}
@@ -109,9 +108,12 @@ func NewStateTransition(env vm.Environment, msg Message, coinbase *state.StateOb
func (self *StateTransition) Coinbase() *state.StateObject {
return self.state.GetOrNewStateObject(self.coinbase)
}
-func (self *StateTransition) From() *state.StateObject {
- f, _ := self.msg.From()
- return self.state.GetOrNewStateObject(f)
+func (self *StateTransition) From() (*state.StateObject, error) {
+ f, err := self.msg.From()
+ if err != nil {
+ return nil, err
+ }
+ return self.state.GetOrNewStateObject(f), nil
}
func (self *StateTransition) To() *state.StateObject {
if self.msg == nil {
@@ -140,7 +142,10 @@ func (self *StateTransition) AddGas(amount *big.Int) {
func (self *StateTransition) BuyGas() error {
var err error
- sender := self.From()
+ sender, err := self.From()
+ if err != nil {
+ return err
+ }
if sender.Balance().Cmp(MessageGasValue(self.msg)) < 0 {
return fmt.Errorf("insufficient ETH for gas (%x). Req %v, has %v", sender.Address().Bytes()[:4], MessageGasValue(self.msg), sender.Balance())
}
@@ -159,10 +164,11 @@ func (self *StateTransition) BuyGas() error {
}
func (self *StateTransition) preCheck() (err error) {
- var (
- msg = self.msg
- sender = self.From()
- )
+ msg := self.msg
+ sender, err := self.From()
+ if err != nil {
+ return err
+ }
// Make sure this transaction's nonce is correct
if sender.Nonce() != msg.Nonce() {
@@ -185,10 +191,8 @@ func (self *StateTransition) transitionState() (ret []byte, usedGas *big.Int, er
return
}
- var (
- msg = self.msg
- sender = self.From()
- )
+ msg := self.msg
+ sender, _ := self.From() // err checked in preCheck
// Pay intrinsic gas
if err = self.UseGas(IntrinsicGas(self.msg)); err != nil {
@@ -212,7 +216,7 @@ func (self *StateTransition) transitionState() (ret []byte, usedGas *big.Int, er
} else {
// Increment the nonce for the next transaction
self.state.SetNonce(sender.Address(), sender.Nonce()+1)
- ret, err = vmenv.Call(self.From(), self.To().Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)
+ ret, err = vmenv.Call(sender, self.To().Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)
}
if err != nil && IsValueTransferErr(err) {
@@ -226,7 +230,8 @@ func (self *StateTransition) transitionState() (ret []byte, usedGas *big.Int, er
}
func (self *StateTransition) refundGas() {
- coinbase, sender := self.Coinbase(), self.From()
+ coinbase := self.Coinbase()
+ sender, _ := self.From() // err already checked
// Return remaining gas
remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice())
sender.AddBalance(remaining)
diff --git a/core/transaction_pool.go b/core/transaction_pool.go
index ee6360614..4296c79f6 100644
--- a/core/transaction_pool.go
+++ b/core/transaction_pool.go
@@ -271,7 +271,7 @@ func (pool *TxPool) Stop() {
}
func (self *TxPool) queueTx(tx *types.Transaction) {
- from, _ := tx.From()
+ from, _ := tx.From() // already validated
self.queue[from] = append(self.queue[from], tx)
}
diff --git a/xeth/types.go b/xeth/types.go
index 1be5e109c..3bb1447ca 100644
--- a/xeth/types.go
+++ b/xeth/types.go
@@ -139,6 +139,10 @@ type Transaction struct {
}
func NewTx(tx *types.Transaction) *Transaction {
+ sender, err := tx.From()
+ if err != nil {
+ return nil
+ }
hash := tx.Hash().Hex()
var receiver string
@@ -147,7 +151,6 @@ func NewTx(tx *types.Transaction) *Transaction {
} else {
receiver = core.AddressFromMessage(tx).Hex()
}
- sender, _ := tx.From()
createsContract := core.MessageCreatesContract(tx)
var data string