Skip to content

Commit

Permalink
add mixHash length check at selectRandomCommittee
Browse files Browse the repository at this point in the history
  • Loading branch information
yoomee1313 committed Dec 19, 2024
1 parent 06da763 commit 5af51ea
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion consensus/istanbul/backend/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,4 @@ func (sb *backend) regen(chain consensus.ChainReader, headers []*types.Header) {
if commitTried { // This prevents pushing too many logs by potential DoS attack
logger.Trace("[Snapshot] Snapshot restoring completed", "len(headers)", len(headers), "from", from, "to", to, "elapsed", time.Since(start))
}
}
}
2 changes: 1 addition & 1 deletion kaiax/valset/impl/committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (c *committeeContext) selectRandomCommittee(round uint64, proposer, nextDis
// return shuffled[:min(committee_size, len(validators))]
func (c *committeeContext) selectRandaoCommittee() ([]common.Address, error) {
prevMixHash := c.prevHeader.MixHash
if prevMixHash == nil {
if prevMixHash == nil || len(prevMixHash) != 32 {
prevMixHash = params.ZeroMixHash
}

Expand Down
4 changes: 2 additions & 2 deletions kaiax/valset/impl/getter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestGetCommittee(t *testing.T) {
// per committeeSize
{"committeesize is zero", defaultBN, defaultRound, testProposerPolicy, 0, tgn, nil, errInvalidCommitteeSize},
{"committeesize is one", defaultBN, defaultRound, testProposerPolicy, 1, tgn, []common.Address{tgn}, nil},
{"committeesize is three", defaultBN, defaultRound, testProposerPolicy, testSubGroupSize, tgn, []common.Address{n[0], n[1], n[2]}, nil},
{"committeesize is three", defaultBN, defaultRound, testProposerPolicy, testSubGroupSize, tgn, []common.Address{n[0], n[3], n[1]}, nil},
{"committeesize is six", defaultBN, defaultRound, testProposerPolicy, testSubGroupSize + 3, tgn, []common.Address{tgn, n[1], n[3], n[2]}, nil},
{"committeesize is seven", defaultBN, defaultRound, testProposerPolicy, testSubGroupSize + 4, tgn, []common.Address{tgn, n[1], n[3], n[2]}, nil},
// per proposerPolicy
Expand All @@ -88,7 +88,7 @@ func TestGetCommittee(t *testing.T) {
{"block 1", 1, defaultRound, testProposerPolicy, testSubGroupSize, tgn, []common.Address{n[1], n[2], tgn}, nil},
{"istanbul hf activated", testIstanbulCompatibleNumber.Uint64() + 1, defaultRound, testProposerPolicy, testSubGroupSize, tgn, []common.Address{n[1], n[2], n[3]}, nil},
{"kore hf activated", testKoreCompatibleBlock.Uint64() + 1, defaultRound, testProposerPolicy, testSubGroupSize, tgn, []common.Address{n[3], tgn, n[1]}, nil},
{"randao hf activated", testRandaoCompatibleBlock.Uint64() + 1, defaultRound, testProposerPolicy, testSubGroupSize, tgn, []common.Address{tgn, n[1], n[2]}, nil},
{"randao hf activated", testRandaoCompatibleBlock.Uint64() + 1, defaultRound, testProposerPolicy, testSubGroupSize, tgn, []common.Address{n[0], n[3], n[1]}, nil},
// TODO-kaia-valset: add mainnet,testnet testcases
} {
t.Run(tc.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion kaiax/valset/impl/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var (
testRandaoCompatibleBlock = big.NewInt(int64(testEpoch) + 30)
testKaiaCompatibleBlock = big.NewInt(int64(testEpoch) + 40)

testMixHash = common.Hex2Bytes("0x365643b31592079285c66bfbf9215bccc5d977210ec0b28fb2f19b6b92773625")
testMixHash = common.Hex2Bytes("365643b31592079285c66bfbf9215bccc5d977210ec0b28fb2f19b6b92773625")
testPrevHash = common.HexToHash("0x2e43e99fe04c8664f93f21b255356cd2279b0e993cc367db8d3e629d8c745635")
)

Expand Down

0 comments on commit 5af51ea

Please sign in to comment.