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

Farmer key miss match #7

Closed
goomario opened this issue Jul 7, 2023 · 1 comment
Closed

Farmer key miss match #7

goomario opened this issue Jul 7, 2023 · 1 comment

Comments

@goomario
Copy link

goomario commented Jul 7, 2023

TestCase:

func TestSignature(t *testing.T) {
	var seed [64]byte
	for i := 0; i < 100; i++ {
		_, _ = rand.Read(seed[:])

		// blsgo
		blsgoPrivateKey := blsgo.KeyGen(seed[:])
		blsgoFarmerPrivateKey := blsgoPrivateKey.FarmerSk()
		blsgoFarmerPrivateKeyBytes := blsgoFarmerPrivateKey.Bytes()

		// chia bls with cgo
		blsPrivateKey, _ := bls.GenerateKeyFromSeed(seed[:])
		blsFarmerPrivateKey := blsPrivateKey.DeriveChild([]int{12381, 8444, 0, 0})
		blsFarmerPrivateKeyBytes, _ := blsFarmerPrivateKey.MarshalBinary()

		if bytes.Compare(blsgoFarmerPrivateKeyBytes, blsFarmerPrivateKeyBytes) != 0 {
			t.Errorf("Bad farmer key: i=%d seed=%s blsgo=%s chia-bls=%s", i, hex.EncodeToString(seed[:]),
				hex.EncodeToString(blsgoFarmerPrivateKeyBytes),
				hex.EncodeToString(blsFarmerPrivateKeyBytes))
		}
	}
}

Output:

=== RUN   TestSignature
    service_test.go:142: Bad farmer key: i=23 seed=53f830604c1432a737b18b8f8d94fe897e735cba0fcd3f2cf0212973a521f84bf9ed8bb739012d6811c81d0c4dff726642225dcb8e63d4bdf02341a5fa5c1101 blsgo=090ccc11e11032e691f1c0671c8aa43b2fc6fef7b6e0101ffb289e2cce9bf422 chia-bls=3cd15ca01d255815a8dc24a6b3344761c3578b4d2b325aced906a65072f4f612
    service_test.go:142: Bad farmer key: i=35 seed=9ad7c719f59d794bb8527dcafa4a17243df11b12e1b077ad39d60cd4d0409432d13ba749d6932792b218b28a361a545cf5aa174e3d236039193f603eaa128dd6 blsgo=0433e87b7c5ea124b0ebe1cbb7d96c7fbf59aa49b2d891f50d99f517b82ab97d chia-bls=5479365fdd776bff9e8daa9ea79c58a1b8af08b907c733c81b9cfd3f43fbd31c
    service_test.go:142: Bad farmer key: i=70 seed=2d59eab383318d51a26290cb78cbcdc9941c21e175d446779025ddb20643da99b87dfcc14e012ba2029e5574bcc1e71344172c18810db086696ba0593b0c8500 blsgo=67d2819d00db4bc1d14a3cf7e131b3b1f4085f10bbcea53f225e9b9c6f9b1454 chia-bls=66c9a4109557cfe20199565e5138ceecdea77a5db8b1eb88cb1169ba5367edb5
    service_test.go:142: Bad farmer key: i=75 seed=eb0dcf3c89de963b4f047dd85f79212b0dbf269d73deae5ab3d043f815778394d6ac9ff01526127520d35916eed90aada0f4f05b50c17a1648a141f79b5d495b blsgo=3645c8df7e38d12464eca7f7f9711edc538d91aa8545d42c8c01d6848856105e chia-bls=05a891a033d8b47931bed5594eadf754e7d751fa15ddbd27bcd2b7c8283616d4
    service_test.go:142: Bad farmer key: i=79 seed=a83903c9c2acef4c279c98faaa2d6656f146139c2a0b0839e36a0304f6f2755c19f27575e3a5342f88f5a255290112c152b97032df5af5d1e3c6235f4e42fb39 blsgo=17721e215429eaf5657cea3b2ccb1b968df1c9475739c8a275216898a8abda7d chia-bls=666bf79655c82de816fa22781d0cce550b03820b4e6641f7938466577aa5700c
--- FAIL: TestSignature (1.12s)
@chuwt
Copy link
Owner

chuwt commented Jul 8, 2023

Hi @goomario , thanks for the report, the bug was fixed, this bug was caused by the wrong use of big.Int.Bytes(), it should be replaced with big.Int.FillBytes()

chia-bls-go/util.go

Lines 37 to 38 in 447398c

ikm := make([]byte, 32)
parentSk.value.FillBytes(ikm)

@chuwt chuwt closed this as completed Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants