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

kilic multiplication isn't reentrant #16

Open
gballet opened this issue May 21, 2021 · 0 comments
Open

kilic multiplication isn't reentrant #16

gballet opened this issue May 21, 2021 · 0 comments

Comments

@gballet
Copy link
Contributor

gballet commented May 21, 2021

We found another thread-safety issue with Kilic, described here. In short, it seems that if MulG1 is called concurrently, the two contexts will interact and give an incorrect results.

The following test exposes the problem: 10 threads are running concurrently, each performing a simple EC point multiplication with MulG1, and the result will be sent over a channel. The results are compared with a value calculated in a serial execution context, and they differ (see the failed CI build).

func TestConcurrentMulG1(t *testing.T) {
	var fr bls.Fr
	bls.AsFr(&fr, 2)
	expected := new(bls.G1Point)
	bls.MulG1(expected, &bls.GenG1, &fr)

	threads := 10
	ch := make(chan *bls.G1Point)
	builder := func() {
		var fr bls.Fr
		bls.AsFr(&fr, 2)
		dst := new(bls.G1Point)
		bls.MulG1(dst, &bls.GenG1, &fr)
		ch <- dst
	}

	for i := 0; i < threads; i++ {
		go builder()
	}

	for i := 0; i < threads; i++ {
		res := <-ch
		if res.String() != expected.String() {
			t.Error("Incorrect fr")
		}
	}
}
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

1 participant