aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/queue.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-05-15 16:58:37 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-05-15 20:01:58 +0800
commit72411eb24c47a6b41d8530e6057a88c60491f0e1 (patch)
tree280fdf56742e298ddfb3f63d4db6c10d7c6b3cae /eth/downloader/queue.go
parentbcc2980179f39eea4825df72ad882274086d912e (diff)
downloadgo-tangerine-72411eb24c47a6b41d8530e6057a88c60491f0e1.tar.gz
go-tangerine-72411eb24c47a6b41d8530e6057a88c60491f0e1.tar.zst
go-tangerine-72411eb24c47a6b41d8530e6057a88c60491f0e1.zip
eth/downloader: circumvent hash reordering attacks
Diffstat (limited to 'eth/downloader/queue.go')
-rw-r--r--eth/downloader/queue.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go
index fdea1f63f..aa48c521a 100644
--- a/eth/downloader/queue.go
+++ b/eth/downloader/queue.go
@@ -298,18 +298,17 @@ func (q *queue) Deliver(id string, blocks []*types.Block) (err error) {
// Iterate over the downloaded blocks and add each of them
errs := make([]error, 0)
for _, block := range blocks {
- // Skip any blocks that fall outside the cache range
- index := int(block.NumberU64()) - q.blockOffset
- if index >= len(q.blockCache) || index < 0 {
- //fmt.Printf("block cache overflown (N=%v O=%v, C=%v)", block.Number(), q.blockOffset, len(q.blockCache))
- continue
- }
// Skip any blocks that were not requested
hash := block.Hash()
if _, ok := request.Hashes[hash]; !ok {
errs = append(errs, fmt.Errorf("non-requested block %v", hash))
continue
}
+ // If a requested block falls out of the range, the hash chain is invalid
+ index := int(block.NumberU64()) - q.blockOffset
+ if index >= len(q.blockCache) || index < 0 {
+ return ErrInvalidChain
+ }
// Otherwise merge the block and mark the hash block
q.blockCache[index] = block