dusk-blockchain icon indicating copy to clipboard operation
dusk-blockchain copied to clipboard

Add support in sortition for bls public keys that starts with zeros

Open goshawk-3 opened this issue 2 years ago • 0 comments

Describe the bug p.MemberAt(i) in extractCommitteeMember would return nil member making the sortition panic, when a provisioner public key starts with zeros.

To Reproduce

  1. Try to generate a valid BLS key where the public key starts with zeros
  2. Stake with it
  3. If extractCommitteeMember loop reaches this member, it will panic.

Expected behaviour As it is an existing item, p.MemberAt(i) should return the real member but not nil. To achieve this, Int.FillBytes should be used.

Additional context

func TestSetBytes(t *testing.T) {
	b1 := decodeString("0000d081884c")
	bigInt1 := new(big.Int).SetBytes(b1)

	b2 := bigInt1.Bytes()

	assert.True(t, bytes.Equal(b1, b2))
	// failed
}

goshawk-3 avatar Aug 26 '22 08:08 goshawk-3