From 0fceaf12d2968d0e9b0fd4449804eb0d584956bc Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 13 Feb 2020 20:59:03 +0300 Subject: [PATCH] core: deal with bad transaction Inputs They may not really have a reference. Fixes #671. --- pkg/core/blockchain.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 0c1ad2495..3ef37e36d 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -965,14 +965,15 @@ func (bc *Blockchain) References(t *transaction.Transaction) map[transaction.Inp references := make(map[transaction.Input]*transaction.Output) for prevHash, inputs := range t.GroupInputsByPrevHash() { - if tx, _, err := bc.dao.GetTransaction(prevHash); err != nil { - tx = nil - } else if tx != nil { - for _, in := range inputs { - references[*in] = &tx.Outputs[in.PrevIndex] + tx, _, err := bc.dao.GetTransaction(prevHash) + if err != nil { + return nil + } + for _, in := range inputs { + if int(in.PrevIndex) > len(tx.Outputs)-1 { + return nil } - } else { - references = nil + references[*in] = &tx.Outputs[in.PrevIndex] } } return references @@ -1450,7 +1451,7 @@ func (bc *Blockchain) GetScriptHashesForVerifying(t *transaction.Transaction) ([ } references := bc.References(t) if references == nil { - return nil, errors.New("Invalid operation") + return nil, errors.New("invalid inputs") } hashes := make(map[util.Uint160]bool) for _, i := range t.Inputs {