Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in Proposer Index to Custom HTR #5269

Merged
merged 9 commits into from
Apr 1, 2020
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
5 changes: 5 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,17 @@ package stateutil_test
import (
"testing"

"github.com/prysmaticlabs/prysm/shared/featureconfig"

terencechain marked this conversation as resolved.
Show resolved Hide resolved
"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