Skip to content

Commit

Permalink
Add in Proposer Index to Custom HTR (#5269)
Browse files Browse the repository at this point in the history
* fix test

* Update beacon-chain/state/stateutil/blocks_test.go

Co-authored-by: terence tsao <terence@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 1, 2020
1 parent 9998b97 commit d15c12f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions beacon-chain/state/stateutil/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ func BlockRoot(blk *ethpb.BeaconBlock) ([32]byte, error) {
if !featureconfig.Get().EnableBlockHTR {
return ssz.HashTreeRoot(blk)
}
fieldRoots := make([][32]byte, 4)
fieldRoots := make([][32]byte, 5)
if blk != nil {
headerSlotBuf := make([]byte, 8)
binary.LittleEndian.PutUint64(headerSlotBuf, blk.Slot)
headerSlotRoot := bytesutil.ToBytes32(headerSlotBuf)
fieldRoots[0] = headerSlotRoot
proposerIdxBuf := make([]byte, 8)
binary.LittleEndian.PutUint64(proposerIdxBuf, blk.ProposerIndex)
proposerIndexRoot := bytesutil.ToBytes32(proposerIdxBuf)
fieldRoots[1] = proposerIndexRoot
parentRoot := bytesutil.ToBytes32(blk.ParentRoot)
fieldRoots[1] = parentRoot
fieldRoots[2] = parentRoot
stateRoot := bytesutil.ToBytes32(blk.StateRoot)
fieldRoots[2] = stateRoot
fieldRoots[3] = stateRoot
bodyRoot, err := BlockBodyRoot(blk.Body)
if err != nil {
return [32]byte{}, err
}
fieldRoots[3] = bodyRoot
fieldRoots[4] = bodyRoot
}
return bitwiseMerkleizeArrays(hashutil.CustomSHA256Hasher(), fieldRoots, uint64(len(fieldRoots)), uint64(len(fieldRoots)))
}
Expand Down
4 changes: 4 additions & 0 deletions beacon-chain/state/stateutil/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package stateutil_test
import (
"testing"

"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
)

func TestBlockRoot(t *testing.T) {
f := featureconfig.Get()
f.EnableBlockHTR = true
featureconfig.Init(f)
genState, keys := testutil.DeterministicGenesisState(t, 100)
blk, err := testutil.GenerateFullBlock(genState, keys, testutil.DefaultBlockGenConfig(), 10)
if err != nil {
Expand Down

0 comments on commit d15c12f

Please sign in to comment.