aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/downloader_test.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-05-21 13:37:27 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-05-21 13:37:27 +0800
commit52db6d8be577669bd5ba659ac223acf61956b05a (patch)
tree7791708f9cacb86bba97fb6847ba918999163a81 /eth/downloader/downloader_test.go
parente8b22b9253da400cc350dbc673d07789f93f57bc (diff)
downloadgo-tangerine-52db6d8be577669bd5ba659ac223acf61956b05a.tar
go-tangerine-52db6d8be577669bd5ba659ac223acf61956b05a.tar.gz
go-tangerine-52db6d8be577669bd5ba659ac223acf61956b05a.tar.bz2
go-tangerine-52db6d8be577669bd5ba659ac223acf61956b05a.tar.lz
go-tangerine-52db6d8be577669bd5ba659ac223acf61956b05a.tar.xz
go-tangerine-52db6d8be577669bd5ba659ac223acf61956b05a.tar.zst
go-tangerine-52db6d8be577669bd5ba659ac223acf61956b05a.zip
eth/downloader: circumvent a forged block chain with known parent attack
Diffstat (limited to 'eth/downloader/downloader_test.go')
-rw-r--r--eth/downloader/downloader_test.go36
1 files changed, 35 insertions, 1 deletions
diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go
index 8ed3289c6..d623a7c76 100644
--- a/eth/downloader/downloader_test.go
+++ b/eth/downloader/downloader_test.go
@@ -502,7 +502,7 @@ func TestMadeupBlockChainAttack(t *testing.T) {
crossCheckCycle = 25 * time.Millisecond
// Create a long chain of blocks and simulate an invalid chain by dropping every second
- hashes := createHashes(0, 32*blockCacheLimit)
+ hashes := createHashes(0, 16*blockCacheLimit)
blocks := createBlocksFromHashes(hashes)
gapped := make([]common.Hash, len(hashes)/2)
@@ -525,3 +525,37 @@ func TestMadeupBlockChainAttack(t *testing.T) {
t.Fatalf("failed to synchronise blocks: %v", err)
}
}
+
+// Advanced form of the above forged blockchain attack, where not only does the
+// attacker make up a valid hashes for random blocks, but also forges the block
+// parents to point to existing hashes.
+func TestMadeupParentBlockChainAttack(t *testing.T) {
+ defaultBlockTTL := blockTTL
+ defaultCrossCheckCycle := crossCheckCycle
+
+ blockTTL = 100 * time.Millisecond
+ crossCheckCycle = 25 * time.Millisecond
+
+ // Create a long chain of blocks and simulate an invalid chain by dropping every second
+ hashes := createHashes(0, 16*blockCacheLimit)
+ blocks := createBlocksFromHashes(hashes)
+ forges := createBlocksFromHashes(hashes)
+ for hash, block := range forges {
+ block.ParentHeaderHash = hash // Simulate pointing to already known hash
+ }
+ // Try and sync with the malicious node and check that it fails
+ tester := newTester(t, hashes, forges)
+ tester.newPeer("attack", big.NewInt(10000), hashes[0])
+ if _, err := tester.syncTake("attack", hashes[0]); err != ErrCrossCheckFailed {
+ t.Fatalf("synchronisation error mismatch: have %v, want %v", err, ErrCrossCheckFailed)
+ }
+ // Ensure that a valid chain can still pass sync
+ blockTTL = defaultBlockTTL
+ crossCheckCycle = defaultCrossCheckCycle
+
+ tester.blocks = blocks
+ tester.newPeer("valid", big.NewInt(20000), hashes[0])
+ if _, err := tester.syncTake("valid", hashes[0]); err != nil {
+ t.Fatalf("failed to synchronise blocks: %v", err)
+ }
+}