Fix Randao Reveal Bug (#1801)

* use 32 bytes

* all tests passed

* lint
This commit is contained in:
terence tsao 2019-03-02 15:24:15 -08:00 committed by Raul Jordan
parent 3144c36164
commit 5ab93dfabb
3 changed files with 6 additions and 4 deletions

View File

@ -20,6 +20,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/forkutils"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/trieutil"
)
@ -94,7 +95,8 @@ func ProcessBlockRandao(beaconState *pb.BeaconState, block *pb.BeaconBlock, veri
latestMixesLength := params.BeaconConfig().LatestRandaoMixesLength
currentEpoch := helpers.CurrentEpoch(beaconState)
latestMixSlice := beaconState.LatestRandaoMixes[currentEpoch%latestMixesLength]
for i, x := range block.RandaoReveal {
blockRandaoReveal := hashutil.Hash(block.RandaoReveal)
for i, x := range blockRandaoReveal {
latestMixSlice[i] ^= x
}
beaconState.LatestRandaoMixes[currentEpoch%latestMixesLength] = latestMixSlice

View File

@ -106,7 +106,8 @@ func TestProcessBlockRandao_SignatureVerifiesAndUpdatesLatestStateMixes(t *testi
}
currentEpoch := helpers.CurrentEpoch(beaconState)
mix := newState.LatestRandaoMixes[currentEpoch%params.BeaconConfig().LatestRandaoMixesLength]
if bytes.Equal(mix, params.BeaconConfig().EmptySignature[:]) {
if bytes.Equal(mix, params.BeaconConfig().ZeroHash[:]) {
t.Errorf(
"Expected empty signature to be overwritten by randao reveal, received %v",
params.BeaconConfig().EmptySignature,

View File

@ -28,8 +28,7 @@ func GenesisBeaconState(
params.BeaconConfig().LatestRandaoMixesLength,
)
for i := 0; i < len(latestRandaoMixes); i++ {
emptySig := params.BeaconConfig().EmptySignature
latestRandaoMixes[i] = emptySig[:]
latestRandaoMixes[i] = make([]byte, 32)
}
zeroHash := params.BeaconConfig().ZeroHash[:]