From c37389f19ced68c8eb3bd6589f206b8a14d9a00a Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 26 May 2015 19:50:42 +0200 Subject: core: check negative value transactions. Closes #1109 --- core/chain_manager.go | 2 +- core/transaction_pool.go | 5 +++++ core/transaction_pool_test.go | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'core') 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) + } +} -- cgit v1.2.3 From b2f2806055c90f6956db6c89bfdc3df65b95d6b6 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 27 May 2015 00:11:54 +0200 Subject: cmd/geth, core: Updated DB version & seedhash debug method --- core/block_processor.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/block_processor.go b/core/block_processor.go index 3f10e5efd..037782407 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -21,7 +21,7 @@ import ( const ( // must be bumped when consensus algorithm is changed, this forces the upgradedb // command to be run (forces the blocks to be imported again using the new algorithm) - BlockChainVersion = 2 + BlockChainVersion = 3 ) var receiptsPre = []byte("receipts-") @@ -159,6 +159,9 @@ func (sm *BlockProcessor) RetryProcess(block *types.Block) (logs state.Logs, err return nil, ParentError(header.ParentHash) } parent := sm.bc.GetBlock(header.ParentHash) + if !sm.Pow.Verify(block) { + return nil, ValidationError("Block's nonce is invalid (= %x)", block.Nonce) + } return sm.processWithParent(block, parent) } -- cgit v1.2.3 From be2b0501b5832c0b49f07cdf2db597cc34450199 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 27 May 2015 01:52:03 +0200 Subject: core: block.gasLimit - parent.gasLimit <= parent.gasLimit / GasLimitBoundDivisor --- core/block_processor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/block_processor.go b/core/block_processor.go index 037782407..e808c03da 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -302,7 +302,7 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header, checkPow b a := new(big.Int).Sub(block.GasLimit, parent.GasLimit) a.Abs(a) b := new(big.Int).Div(parent.GasLimit, params.GasLimitBoundDivisor) - if !(a.Cmp(b) < 0) || (block.GasLimit.Cmp(params.MinGasLimit) == -1) { + if !(a.Cmp(b) <= 0) || (block.GasLimit.Cmp(params.MinGasLimit) == -1) { return fmt.Errorf("GasLimit check failed for block %v (%v > %v)", block.GasLimit, a, b) } -- cgit v1.2.3