diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-05-27 02:45:23 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-05-27 02:45:23 +0800 |
commit | b1f7b5d1f60521cd700c08ae2985518cd36fc627 (patch) | |
tree | 521de84ace66e7bd06e0074ca86e7d06eb7cfafb | |
parent | a55f408c10ea7ed40e2bd843668b6eb6c2dc038b (diff) | |
parent | c37389f19ced68c8eb3bd6589f206b8a14d9a00a (diff) | |
download | go-tangerine-b1f7b5d1f60521cd700c08ae2985518cd36fc627.tar.gz go-tangerine-b1f7b5d1f60521cd700c08ae2985518cd36fc627.tar.zst go-tangerine-b1f7b5d1f60521cd700c08ae2985518cd36fc627.zip |
Merge pull request #1111 from obscuren/neg_tx_check
core: check negative value transactions. Closes #1109
-rw-r--r-- | core/chain_manager.go | 2 | ||||
-rw-r--r-- | core/transaction_pool.go | 5 | ||||
-rw-r--r-- | core/transaction_pool_test.go | 14 | ||||
-rw-r--r-- | eth/sync.go | 1 |
4 files changed, 20 insertions, 2 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go index 2b86bb794..ec479db25 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -750,7 +750,7 @@ out: func blockErr(block *types.Block, err error) { h := block.Header() - glog.V(logger.Error).Infof("INVALID block #%v (%x)\n", h.Number, h.Hash().Bytes()) + glog.V(logger.Error).Infof("Bad block #%v (%x)\n", h.Number, h.Hash().Bytes()) glog.V(logger.Error).Infoln(err) glog.V(logger.Debug).Infoln(block) } diff --git a/core/transaction_pool.go b/core/transaction_pool.go index e68f7406a..c896488d1 100644 --- a/core/transaction_pool.go +++ b/core/transaction_pool.go @@ -25,6 +25,7 @@ var ( ErrInsufficientFunds = errors.New("Insufficient funds for gas * price + value") ErrIntrinsicGas = errors.New("Intrinsic gas too low") ErrGasLimit = errors.New("Exceeds block gas limit") + ErrNegativeValue = errors.New("Negative value") ) const txPoolQueueSize = 50 @@ -125,6 +126,10 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error { return ErrGasLimit } + if tx.Amount.Cmp(common.Big0) < 0 { + return ErrNegativeValue + } + total := new(big.Int).Mul(tx.Price, tx.GasLimit) total.Add(total, tx.Value()) if pool.currentState().GetBalance(from).Cmp(total) < 0 { diff --git a/core/transaction_pool_test.go b/core/transaction_pool_test.go index 49224be5b..d6ea4a2a9 100644 --- a/core/transaction_pool_test.go +++ b/core/transaction_pool_test.go @@ -138,3 +138,17 @@ func TestRemoveTx(t *testing.T) { t.Error("expected txs to be 0, got", len(pool.txs)) } } + +func TestNegativeValue(t *testing.T) { + pool, key := setupTxPool() + + tx := transaction() + tx.Value().Set(big.NewInt(-1)) + tx.SignECDSA(key) + from, _ := tx.From() + pool.currentState().AddBalance(from, big.NewInt(1)) + err := pool.Add(tx) + if err != ErrNegativeValue { + t.Error("expected", ErrNegativeValue, "got", err) + } +} diff --git a/eth/sync.go b/eth/sync.go index d93f83a78..cf549f852 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -70,7 +70,6 @@ func (pm *ProtocolManager) processBlocks() error { // Try to inset the blocks, drop the originating peer if there's an error index, err := pm.chainman.InsertChain(raw) if err != nil { - glog.V(logger.Warn).Infof("Block insertion failed: %v", err) pm.removePeer(blocks[index].OriginPeer) pm.downloader.Cancel() return err |