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 {
|
if !txProofVerified {
|
||||||
return fmt.Errorf("transaction doesn't present in block hash merkle tree")
|
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)
|
err = sm.blockPool.StoreBlock(&block)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
@ -27,3 +28,11 @@ func CreateTransaction(data []byte) *Transaction {
|
|||||||
Data: data,
|
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