aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-04-22 21:29:19 +0800
committerGustav Simonsson <gustav.simonsson@gmail.com>2015-04-23 05:16:19 +0800
commit4e0a2c8e8cf418528742500dff8e6916e4fd1bc5 (patch)
tree9f194fe587d93100dbb28bffa1a4100c2ada0b1e
parentec6acacc539c3392c8dd68c89a2b714ec609ff19 (diff)
downloadgo-tangerine-4e0a2c8e8cf418528742500dff8e6916e4fd1bc5.tar.gz
go-tangerine-4e0a2c8e8cf418528742500dff8e6916e4fd1bc5.tar.zst
go-tangerine-4e0a2c8e8cf418528742500dff8e6916e4fd1bc5.zip
Validate block header UncleHash against calculated hash
-rw-r--r--core/block_processor.go11
-rw-r--r--core/types/block.go4
2 files changed, 13 insertions, 2 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index 28636a725..f33f0d433 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -219,14 +219,21 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st
// can be used by light clients to make sure they've received the correct Txs
txSha := types.DeriveSha(block.Transactions())
if txSha != header.TxHash {
- err = fmt.Errorf("validating transaction root. received=%x got=%x", header.TxHash, txSha)
+ err = fmt.Errorf("invalid transaction root hash. received=%x calculated=%x", header.TxHash, txSha)
return
}
// Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, R1]]))
receiptSha := types.DeriveSha(receipts)
if receiptSha != header.ReceiptHash {
- err = fmt.Errorf("validating receipt root. received=%x got=%x", header.ReceiptHash, receiptSha)
+ err = fmt.Errorf("invalid receipt root hash. received=%x calculated=%x", header.ReceiptHash, receiptSha)
+ return
+ }
+
+ // Verify UncleHash before running other uncle validations
+ unclesSha := block.CalculateUnclesHash()
+ if unclesSha != header.UncleHash {
+ err = fmt.Errorf("invalid uncles root hash. received=%x calculated=%x", header.UncleHash, unclesSha)
return
}
diff --git a/core/types/block.go b/core/types/block.go
index f9206ec76..fa83fc8e8 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -209,6 +209,10 @@ func (self *Block) Uncles() []*Header {
return self.uncles
}
+func (self *Block) CalculateUnclesHash() common.Hash {
+ return rlpHash(self.uncles)
+}
+
func (self *Block) SetUncles(uncleHeaders []*Header) {
self.uncles = uncleHeaders
self.header.UncleHash = rlpHash(uncleHeaders)