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

Panic on cgo call of secp256k1 #203

Open
nepet opened this issue Jul 8, 2022 · 9 comments
Open

Panic on cgo call of secp256k1 #203

nepet opened this issue Jul 8, 2022 · 9 comments

Comments

@nepet
Copy link

nepet commented Jul 8, 2022

Hi folks,

Does anyone of you here have an idea why we are getting this panic log?

fatal: morestack on g0
SIGTRAP: trace trap
PC=0x466a02 m=4 sigcode=128
signal arrived during cgo execution

goroutine 46 [syscall]:
runtime.cgocall(0x7069f0, 0xc0001d1328)
	/usr/local/src/runtime/cgocall.go:157 +0x5c fp=0xc0001d1300 sp=0xc0001d12c8 pc=0x4078bc
github.com/vulpemventures/go-secp256k1-zkp._Cfunc_secp256k1_context_create(0x301)
	_cgo_gotypes.go:298 +0x4d fp=0xc0001d1328 sp=0xc0001d1300 pc=0x6bd0cd
github.com/vulpemventures/go-secp256k1-zkp.ContextCreate(0x301)
	/root/go/pkg/mod/github.com/vulpemventures/go-secp256k1-zkp@v1.1.5/secp256k1.go:74 +0x37 fp=0xc0001d1350 sp=0xc0001d1328 pc=0x6c1817
github.com/vulpemventures/go-elements/confidential.nonceHash({0xc0005ac900, 0x21, 0x30}, {0xc000490f20, 0x20, 0x20})
	/root/go/pkg/mod/github.com/vulpemventures/go-elements@v0.3.7/confidential/confidential.go:175 +0x7b fp=0xc0001d13d0 sp=0xc0001d1350 pc=0x6c2bdb
github.com/vulpemventures/go-elements/confidential.NonceHash(...)
	/root/go/pkg/mod/github.com/vulpemventures/go-elements@v0.3.7/confidential/confidential.go:16

Cheers,
Peter

@tiero
Copy link
Member

tiero commented Jul 11, 2022

Hey, @nepet this never happened to us so far.

Any chance you can provide us with a "minimal repro" go file that triggers this panic?

From the stack trace it seems to originate from NonceHash call which is very straightforward, can you double-check your inputs?

@nepet
Copy link
Author

nepet commented Jul 11, 2022

Thanks for checking on this @tiero!
I will check on the inputs. It seems to be a flaky behavior that we could not reproduce so far.

func nonceHash(pubKey, privKey []byte) (result [32]byte, err error) {
ctx, _ := secp256k1.ContextCreate(secp256k1.ContextBoth)
defer secp256k1.ContextDestroy(ctx)

The stack trace seems to originate from the ContextCreate method of secp256k1 which is not related to the inputs of NonceHash, or do I miss something here?

@tiero
Copy link
Member

tiero commented Jul 11, 2022

oh, ok seems then related to some memory leak. I just quickly read on your reference issue, please be sure to defer any calls, so cgo will release memory before panic

@wtogami
Copy link

wtogami commented Jul 13, 2022

https://musl.libc.org/
The crash seems to be reproducible with musl libc ... but we haven't seen it crash with ordinary glibc. Everything you deploy in Alpine Linux is built in this way. Something similar happened again just now. Alpine developer claims their FORTIFY stuff is more strict than glibc so it may be exposing memory use errors.

fatal: morestack on g0
SIGTRAP: trace trap
PC=0x466a02 m=7 sigcode=128
signal arrived during cgo execution

goroutine 13777 [syscall]:
runtime.cgocall(0x706d90, 0xc0004bd9f8)
        /usr/local/src/runtime/cgocall.go:157 +0x5c fp=0xc0004bd9d0 sp=0xc0004bd998 pc=0x4078bc
github.com/vulpemventures/go-secp256k1-zkp._Cfunc_secp256k1_context_create(0x301)
        _cgo_gotypes.go:298 +0x4d fp=0xc0004bd9f8 sp=0xc0004bd9d0 pc=0x6bd42d
github.com/vulpemventures/go-secp256k1-zkp.ContextCreate(0x301)
        /root/go/pkg/mod/github.com/vulpemventures/go-secp256k1-zkp@v1.1.5/secp256k1.go:74 +0x37 fp=0xc0004bda20 sp=0xc0004bd9f8 pc=0x6c1b77
github.com/vulpemventures/go-elements/confidential.nonceHash({0xc0004f2180, 0x21, 0x30}, {0xc00046e120, 0x20, 0x20})
        /root/go/pkg/mod/github.com/vulpemventures/go-elements@v0.3.7/confidential/confidential.go:175 +0x7b fp=0xc0004bdaa0 sp=0xc0004bda20 pc=0x6c2f3b
github.com/vulpemventures/go-elements/confidential.NonceHash(...)
        /root/go/pkg/mod/github.com/vulpemventures/go-elements@v0.3.7/confidential/confidential.go:16
github.com/vulpemventures/go-elements/confidential.UnblindOutputWithKey(0xc0005a6240, {0xc00046e120?, 0x3?, 0xc000352080?})
        /root/go/pkg/mod/github.com/vulpemventures/go-elements@v0.3.7/confidential/confidential.go:39 +0x6a fp=0xc0004bdb40 sp=0xc0004bdaa0 pc=0x6c2dea

@wtogami
Copy link

wtogami commented Jul 13, 2022

happened again ... same place ...

@tiero
Copy link
Member

tiero commented Jul 13, 2022

I think the best way would be to have a single go file, with the code stripped down to what caused these crashes, and will then start investigating from there if it's something related to our implementation and/or usage of cgo calls or if it's a golang cgo specific thing.

Eventually then using a Dockerfile we can test on Alpine too.

Thanks

@wtogami
Copy link

wtogami commented Jul 14, 2022

@nepet since we're reproducing this crash easily on our alpine deployment, could you make a test commit that prints out all the inputs before it calls this so we could try to make a minimal reproducer out of it?

@tiero
Copy link
Member

tiero commented Jul 21, 2022

Also paging @altafan in case you have ever experienced this or tried already on alpine/musl.

We never tested outside debian-like evn to be honest

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

4 participants