From fa467ce62851d8d317f564e4ea54d44feaf495f2 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 27 Apr 2020 09:25:23 +0300 Subject: [PATCH] core: add txes duplication check on block.DecodeBinary --- pkg/core/block/block.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/core/block/block.go b/pkg/core/block/block.go index c06d0c6de..a9715d71e 100644 --- a/pkg/core/block/block.go +++ b/pkg/core/block/block.go @@ -56,6 +56,17 @@ func (b *Block) RebuildMerkleRoot() error { // Verify verifies the integrity of the block. func (b *Block) Verify() error { + if b.Transactions != nil { + hashes := map[util.Uint256]bool{} + for _, tx := range b.Transactions { + if !hashes[tx.Hash()] { + hashes[tx.Hash()] = true + } else { + return errors.New("transaction duplication is not allowed") + } + } + } + merkle, err := b.computeMerkleTree() if err != nil { return err @@ -142,15 +153,7 @@ func (b *Block) DecodeBinary(br *io.BinReader) { txes[i] = tx } b.Transactions = txes - merkle, err := b.computeMerkleTree() - if err != nil { - br.Err = err - return - } - if !b.MerkleRoot.Equals(merkle.Root()) { - br.Err = errors.New("MerkleRoot mismatch") - return - } + br.Err = b.Verify() } // EncodeBinary encodes the block to the given BinWriter, implementing