diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-09-03 10:01:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-03 10:01:40 +0800 |
commit | c8d3092208f73ee991a123052a71b7dbf7fffc27 (patch) | |
tree | fdcb3b90b859531e042dbbdd6bcd7b0cca40e86a /core/crypto.go | |
parent | 9491ddae81640e04f8aed38e2cddeb64cc62d55b (diff) | |
download | tangerine-consensus-c8d3092208f73ee991a123052a71b7dbf7fffc27.tar tangerine-consensus-c8d3092208f73ee991a123052a71b7dbf7fffc27.tar.gz tangerine-consensus-c8d3092208f73ee991a123052a71b7dbf7fffc27.tar.bz2 tangerine-consensus-c8d3092208f73ee991a123052a71b7dbf7fffc27.tar.lz tangerine-consensus-c8d3092208f73ee991a123052a71b7dbf7fffc27.tar.xz tangerine-consensus-c8d3092208f73ee991a123052a71b7dbf7fffc27.tar.zst tangerine-consensus-c8d3092208f73ee991a123052a71b7dbf7fffc27.zip |
core: Add a new structure `Position` and move `ShardID`, `ChainID` and `Height` from `Block` (#89)
Diffstat (limited to 'core/crypto.go')
-rw-r--r-- | core/crypto.go | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/core/crypto.go b/core/crypto.go index d6af360..f097703 100644 --- a/core/crypto.go +++ b/core/crypto.go @@ -50,7 +50,7 @@ func verifyNotarySignature(pubkey crypto.PublicKey, } func hashBlock(block *types.Block) (common.Hash, error) { - hashPosition := hashPosition(block.ShardID, block.ChainID, block.Height) + hashPosition := hashPosition(block.Position) // Handling Block.Acks. acks := make(common.Hashes, 0, len(block.Acks)) for ack := range block.Acks { @@ -103,10 +103,13 @@ func hashVote(vote *types.Vote) common.Hash { binaryPeriod := make([]byte, 8) binary.LittleEndian.PutUint64(binaryPeriod, vote.Period) + hashPosition := hashPosition(vote.Position) + hash := crypto.Keccak256Hash( vote.ProposerID.Hash[:], vote.BlockHash[:], binaryPeriod, + hashPosition[:], []byte{byte(vote.Type)}, ) return hash @@ -125,7 +128,7 @@ func verifyVoteSignature(vote *types.Vote, sigToPub SigToPubFn) (bool, error) { } func hashCRS(block *types.Block, crs common.Hash) common.Hash { - hashPos := hashPosition(block.ShardID, block.ChainID, block.Height) + hashPos := hashPosition(block.Position) return crypto.Keccak256Hash(crs[:], hashPos[:]) } @@ -142,15 +145,15 @@ func verifyCRSSignature(block *types.Block, crs common.Hash, sigToPub SigToPubFn return true, nil } -func hashPosition(shardID, chainID, height uint64) common.Hash { - binaryShardID := make([]byte, 8) - binary.LittleEndian.PutUint64(binaryShardID, shardID) +func hashPosition(position types.Position) common.Hash { + binaryShardID := make([]byte, 4) + binary.LittleEndian.PutUint32(binaryShardID, position.ShardID) - binaryChainID := make([]byte, 8) - binary.LittleEndian.PutUint64(binaryChainID, chainID) + binaryChainID := make([]byte, 4) + binary.LittleEndian.PutUint32(binaryChainID, position.ChainID) binaryHeight := make([]byte, 8) - binary.LittleEndian.PutUint64(binaryHeight, height) + binary.LittleEndian.PutUint64(binaryHeight, position.Height) return crypto.Keccak256Hash( binaryShardID, |