Change to Custom Hashing for BlockHeaders (#4860)

* change to custom hashing
* Merge branch 'master' into minorOpt
* goimports
* Merge branch 'minorOpt' of https://github.com/prysmaticlabs/geth-sharding into minorOpt
* gaz
* pad to 32 bytes
This commit is contained in:
Nishant Das 2020-02-14 13:19:20 +08:00 committed by GitHub
parent 549b0f66fa
commit ecfd7bdfa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 4 deletions

View File

@ -25,6 +25,7 @@ go_library(
"//shared/mathutil:go_default_library",
"//shared/params:go_default_library",
"//shared/sliceutil:go_default_library",
"//shared/stateutil:go_default_library",
"//shared/trieutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_pkg_errors//:go_default_library",

View File

@ -25,6 +25,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/mathutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/sliceutil"
"github.com/prysmaticlabs/prysm/shared/stateutil"
"github.com/prysmaticlabs/prysm/shared/trieutil"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
@ -250,7 +251,7 @@ func ProcessBlockHeaderNoVerify(
if beaconState.Slot() != block.Slot {
return nil, fmt.Errorf("state slot: %d is different then block slot: %d", beaconState.Slot(), block.Slot)
}
parentRoot, err := ssz.HashTreeRoot(beaconState.LatestBlockHeader())
parentRoot, err := stateutil.BlockHeaderRoot(beaconState.LatestBlockHeader())
if err != nil {
return nil, err
}

View File

@ -20,9 +20,12 @@ func BlockHeaderRoot(header *ethpb.BeaconBlockHeader) ([32]byte, error) {
binary.LittleEndian.PutUint64(headerSlotBuf, header.Slot)
headerSlotRoot := bytesutil.ToBytes32(headerSlotBuf)
fieldRoots[0] = headerSlotRoot[:]
fieldRoots[1] = header.ParentRoot
fieldRoots[2] = header.StateRoot
fieldRoots[3] = header.BodyRoot
parentRoot := bytesutil.ToBytes32(header.ParentRoot)
fieldRoots[1] = parentRoot[:]
stateRoot := bytesutil.ToBytes32(header.StateRoot)
fieldRoots[2] = stateRoot[:]
bodyRoot := bytesutil.ToBytes32(header.BodyRoot)
fieldRoots[3] = bodyRoot[:]
}
return bitwiseMerkleize(fieldRoots, uint64(len(fieldRoots)), uint64(len(fieldRoots)))
}