aboutsummaryrefslogtreecommitdiffstats
path: root/core/block_validator.go
diff options
context:
space:
mode:
authorSonic <sonic@dexon.org>2019-01-18 11:55:51 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:56 +0800
commit88b3ad43fb7f7d69672a9ce42992b01e17ffbb5f (patch)
tree092628d1c460a676dd234f4a3fb54185a611405f /core/block_validator.go
parent4848d54d3a497990030831cb10ea69274ddbd2f2 (diff)
downloaddexon-88b3ad43fb7f7d69672a9ce42992b01e17ffbb5f.tar
dexon-88b3ad43fb7f7d69672a9ce42992b01e17ffbb5f.tar.gz
dexon-88b3ad43fb7f7d69672a9ce42992b01e17ffbb5f.tar.bz2
dexon-88b3ad43fb7f7d69672a9ce42992b01e17ffbb5f.tar.lz
dexon-88b3ad43fb7f7d69672a9ce42992b01e17ffbb5f.tar.xz
dexon-88b3ad43fb7f7d69672a9ce42992b01e17ffbb5f.tar.zst
dexon-88b3ad43fb7f7d69672a9ce42992b01e17ffbb5f.zip
core, dex: use block hash as witness data (#160)
Using only state root and receipt root as witness data can not protect other fields in block header, ex: bloom, difficulty, gas limit, gas used... So that everyone can manipulate these fields to create as many valid blocks at the same height as he want. Although this will not effect the state, one can spam us when syncing. Using block hash as witness data can solve this.
Diffstat (limited to 'core/block_validator.go')
-rw-r--r--core/block_validator.go14
1 files changed, 5 insertions, 9 deletions
diff --git a/core/block_validator.go b/core/block_validator.go
index c6038381f..f42ea6b11 100644
--- a/core/block_validator.go
+++ b/core/block_validator.go
@@ -19,6 +19,7 @@ package core
import (
"fmt"
+ "github.com/dexon-foundation/dexon/common"
"github.com/dexon-foundation/dexon/consensus"
"github.com/dexon-foundation/dexon/core/state"
"github.com/dexon-foundation/dexon/core/types"
@@ -101,20 +102,15 @@ func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *stat
return nil
}
-func (v *BlockValidator) ValidateWitnessData(height uint64, data types.WitnessData) error {
+func (v *BlockValidator) ValidateWitnessData(height uint64, blockHash common.Hash) error {
b := v.bc.GetBlockByNumber(height)
if b == nil {
return fmt.Errorf("can not find block %v either pending or confirmed block", height)
}
- if b.Root() != data.Root {
- return fmt.Errorf("invalid witness root %s vs %s",
- b.Root().String(), data.Root.String())
- }
-
- if b.ReceiptHash() != data.ReceiptHash {
- return fmt.Errorf("invalid witness receipt hash %s vs %s",
- b.ReceiptHash().String(), data.ReceiptHash.String())
+ if b.Hash() != blockHash {
+ return fmt.Errorf("invalid witness block %s vs %s",
+ b.Hash().String(), blockHash.String())
}
return nil
}