mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Update zero hash to sha256().digest() (#2932)
* update zero hash * change zero hash to conform with spec * goimports * add test for zero hash
This commit is contained in:
@@ -56,5 +56,6 @@ go_test(
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/trieutil"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gopkg.in/d4l3k/messagediff.v1"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -308,18 +309,19 @@ func TestProcessBlockHeader_OK(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to process block header got: %v", err)
|
||||
}
|
||||
var zeroHash [32]byte
|
||||
var zeroSig [96]byte
|
||||
nsh := newState.LatestBlockHeader
|
||||
expected := &pb.BeaconBlockHeader{
|
||||
Slot: block.Slot,
|
||||
ParentRoot: latestBlockSignedRoot[:],
|
||||
BodyRoot: bodyRoot[:],
|
||||
StateRoot: zeroHash[:],
|
||||
StateRoot: params.BeaconConfig().ZeroHash[:],
|
||||
Signature: zeroSig[:],
|
||||
}
|
||||
if !proto.Equal(nsh, expected) {
|
||||
t.Errorf("Expected %v, received %vk9k", expected, nsh)
|
||||
diff, _ := messagediff.PrettyDiff(nsh, expected)
|
||||
t.Log(diff)
|
||||
t.Error("Mismatched state")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +344,7 @@ func TestProcessRandao_IncorrectProposerFailsVerification(t *testing.T) {
|
||||
domain := helpers.Domain(beaconState, epoch, params.BeaconConfig().DomainRandao)
|
||||
|
||||
// We make the previous validator's index sign the message instead of the proposer.
|
||||
epochSignature := privKeys[proposerIdx-1].Sign(buf, domain)
|
||||
epochSignature := privKeys[proposerIdx+1].Sign(buf, domain)
|
||||
block := &pb.BeaconBlock{
|
||||
Body: &pb.BeaconBlockBody{
|
||||
RandaoReveal: epochSignature.Marshal(),
|
||||
|
||||
@@ -34,10 +34,6 @@ func TestGenesisBeaconState_OK(t *testing.T) {
|
||||
}
|
||||
genesisForkVersion := params.BeaconConfig().GenesisForkVersion
|
||||
|
||||
if params.BeaconConfig().ZeroHash != [32]byte{} {
|
||||
t.Error("ZeroHash should be all 0s for these tests to pass")
|
||||
}
|
||||
|
||||
if params.BeaconConfig().EpochsPerHistoricalVector != 65536 {
|
||||
t.Error("EpochsPerHistoricalVector should be 8192 for these tests to pass")
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ type BeaconChainConfig struct {
|
||||
|
||||
// Initial value constants.
|
||||
BLSWithdrawalPrefixByte byte `yaml:"BLS_WITHDRAWAL_PREFIX_BYTE"` // BLSWithdrawalPrefixByte is used for BLS withdrawal and it's the first byte.
|
||||
ZeroHash [32]byte // ZeroHash is used to represent a zeroed out 32 byte array.
|
||||
ZeroHash [32]byte // ZeroHash is an alias for sha256().digest().
|
||||
|
||||
// Time parameters constants.
|
||||
MinAttestationInclusionDelay uint64 `yaml:"MIN_ATTESTATION_INCLUSION_DELAY"` // MinAttestationInclusionDelay defines how long validator has to wait to include attestation for beacon block.
|
||||
@@ -134,7 +134,7 @@ var defaultBeaconConfig = &BeaconChainConfig{
|
||||
|
||||
// Initial value constants.
|
||||
BLSWithdrawalPrefixByte: byte(0),
|
||||
ZeroHash: [32]byte{},
|
||||
ZeroHash: [32]byte{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55},
|
||||
|
||||
// Time parameter constants.
|
||||
MinAttestationInclusionDelay: 1,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package params
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -12,3 +14,10 @@ func TestOverrideBeaconConfig(t *testing.T) {
|
||||
t.Errorf("Shardcount in BeaconConfig incorrect. Wanted %d, got %d", 5, c.ShardCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMainnetConfig_ZeroHashIsAliasOfSha256(t *testing.T) {
|
||||
h := sha256.New()
|
||||
if !bytes.Equal(BeaconConfig().ZeroHash[:], h.Sum(nil)) {
|
||||
t.Error("Zero hash is not sha256.New().Sum()")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user