aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreth.go10
-rw-r--r--examples/chain/main.go3
-rw-r--r--plugin/evm/vm.go3
3 files changed, 16 insertions, 0 deletions
diff --git a/coreth.go b/coreth.go
index b7e45af..baa82be 100644
--- a/coreth.go
+++ b/coreth.go
@@ -84,6 +84,16 @@ func (self *ETHChain) GenBlock() {
self.backend.Miner().GenBlock()
}
+func (self *ETHChain) VerifyBlock(block *types.Block) bool {
+ txnHash := types.DeriveSha(block.Transactions())
+ uncleHash := types.CalcUncleHash(block.Uncles())
+ ethHeader := block.Header()
+ if txnHash != ethHeader.TxHash || uncleHash != ethHeader.UncleHash {
+ return false
+ }
+ return true
+}
+
func (self *ETHChain) PendingSize() (int, error) {
pending, err := self.backend.TxPool().Pending()
count := 0
diff --git a/examples/chain/main.go b/examples/chain/main.go
index 7b2ce8e..cd9a8f9 100644
--- a/examples/chain/main.go
+++ b/examples/chain/main.go
@@ -91,6 +91,9 @@ func NewTestChain(name string, config *eth.Config,
if err != nil {
panic(err)
}
+ if !tc.chain.VerifyBlock(block) {
+ panic("invalid block")
+ }
tc.chain.InsertChain([]*types.Block{block})
tc.insertBlock(block)
log.Info(fmt.Sprintf("%s: got block %s, sending ack", name, block.Hash().Hex()))
diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go
index 4b16f71..c710b9d 100644
--- a/plugin/evm/vm.go
+++ b/plugin/evm/vm.go
@@ -314,6 +314,9 @@ func (vm *VM) ParseBlock(b []byte) (snowman.Block, error) {
if err := rlp.DecodeBytes(b, ethBlock); err != nil {
return nil, err
}
+ if !vm.chain.VerifyBlock(ethBlock) {
+ return nil, errInvalidBlock
+ }
blockHash := ethBlock.Hash()
// Coinbase must be zero on C-Chain
if bytes.Compare(blockHash.Bytes(), vm.genesisHash.Bytes()) != 0 &&