Skip to content

Commit

Permalink
Change to Custom Hashing for BlockHeaders (#4860)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nisdas committed Feb 14, 2020
1 parent 549b0f6 commit ecfd7bd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions beacon-chain/core/blocks/BUILD.bazel
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion beacon-chain/core/blocks/block_operations.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 6 additions & 3 deletions shared/stateutil/blocks.go
Expand Up @@ -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)))
}
Expand Down

0 comments on commit ecfd7bd

Please sign in to comment.