Add validation of tx hash when syncing
This commit is contained in:
parent
b51a5ffe75
commit
43871c6141
@ -158,6 +158,9 @@ func (sm *syncManager) processReceivedBlock(block types2.Block) error {
|
||||
if !txProofVerified {
|
||||
return fmt.Errorf("transaction doesn't present in block hash merkle tree")
|
||||
}
|
||||
if !tx.ValidateHash() {
|
||||
return fmt.Errorf("transaction hash is invalid")
|
||||
}
|
||||
}
|
||||
|
||||
err = sm.blockPool.StoreBlock(&block)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"time"
|
||||
@ -27,3 +28,11 @@ func CreateTransaction(data []byte) *Transaction {
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func (tx *Transaction) ValidateHash() bool {
|
||||
h := crypto.Keccak256([]byte(fmt.Sprintf("%d_%s", tx.Timestamp.Unix(), tx.Hash)))
|
||||
if bytes.Compare(h, tx.Hash) != 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user