aboutsummaryrefslogtreecommitdiffstats
path: root/core/crypto.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-04 14:56:00 +0800
committerGitHub <noreply@github.com>2018-10-04 14:56:00 +0800
commit149e918f4fc78632483bf549dd8f5ffe55366e18 (patch)
treefeabcb67103d76cc829ea81a1d57735e71db23d8 /core/crypto.go
parent519cc8a734a510f44463b8dd175b7505f0308a22 (diff)
downloaddexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar
dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.gz
dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.bz2
dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.lz
dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.xz
dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.tar.zst
dexon-consensus-149e918f4fc78632483bf549dd8f5ffe55366e18.zip
core: Check Witness height. Add ConsensusTime and ConsensusHeight to block. (#170)
Diffstat (limited to 'core/crypto.go')
-rw-r--r--core/crypto.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/core/crypto.go b/core/crypto.go
index a0bacac..6fc0d1b 100644
--- a/core/crypto.go
+++ b/core/crypto.go
@@ -25,6 +25,19 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/core/types"
)
+func hashWitness(witness *types.Witness) (common.Hash, error) {
+ binaryTimestamp, err := witness.Timestamp.MarshalBinary()
+ if err != nil {
+ return common.Hash{}, err
+ }
+ binaryHeight := make([]byte, 8)
+ binary.LittleEndian.PutUint64(binaryHeight, witness.Height)
+ return crypto.Keccak256Hash(
+ binaryHeight,
+ binaryTimestamp,
+ witness.Data), nil
+}
+
func hashBlock(block *types.Block) (common.Hash, error) {
hashPosition := hashPosition(block.Position)
// Handling Block.Acks.
@@ -37,6 +50,10 @@ func hashBlock(block *types.Block) (common.Hash, error) {
if err != nil {
return common.Hash{}, err
}
+ binaryWitness, err := hashWitness(&block.Witness)
+ if err != nil {
+ return common.Hash{}, err
+ }
payloadHash := crypto.Keccak256Hash(block.Payload)
hash := crypto.Keccak256Hash(
@@ -45,7 +62,8 @@ func hashBlock(block *types.Block) (common.Hash, error) {
hashPosition[:],
hashAcks[:],
binaryTimestamp[:],
- payloadHash[:])
+ payloadHash[:],
+ binaryWitness[:])
return hash, nil
}