From 6a59ff4288df06ad50bede5509cc2e338e0a81a9 Mon Sep 17 00:00:00 2001 From: Federico Franzoni <8609060+fed-franz@users.noreply.github.com> Date: Fri, 2 Jun 2023 17:22:23 +0200 Subject: [PATCH] Make sortition hash compliant with specification --- pkg/core/consensus/user/sortition.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/core/consensus/user/sortition.go b/pkg/core/consensus/user/sortition.go index ebf59c54c..e5b2ba0d3 100644 --- a/pkg/core/consensus/user/sortition.go +++ b/pkg/core/consensus/user/sortition.go @@ -74,16 +74,15 @@ func (v VotingCommittee) MarshalJSON() ([]byte, error) { } // createSortitionHash takes the Seed value 'seed', the round number 'round', the step number 'step', -// the index 'i' of the committee member to extract, -// and returns the hash (SHA3-256) of their concatenation (i.e., H(round||i||step||seed)). +// the index 'i' of the vote credit to assign, and returns the hash (SHA3-256) of their concatenation +// (i.e., H(seed||round||step||i). func createSortitionHash(seed []byte, round uint64, step uint8, i int) ([]byte, error) { - msg := make([]byte, 12) + msg := make([]byte, len(seed)+8+1+4) - binary.LittleEndian.PutUint64(msg[:8], round) - binary.LittleEndian.PutUint32(msg[8:12], uint32(i)) - - msg = append(msg, step) - msg = append(msg, seed...) + copy(msg, seed) + binary.LittleEndian.PutUint64(msg[len(seed):len(seed)+8], round) + msg[len(seed)+8] = step + binary.LittleEndian.PutUint32(msg[len(seed)+9:len(seed)+13], uint32(i)) return hash.Sha3256(msg) }