Search code examples
cgocryptographybitcoinecdsa

SIGTRAP: trace trap error in Golang wrapping C library, but only when running go test


I've set up a minimal codebase repo to replicate the error and explain this error as clearly as possible: https://github.com/soroushjp/go_wrapper_c_err

I'm currently working on a project doing ECDSA signing using a Go package go-secp256k1 that wraps the C secp256k1 library.

If I use the functions in go-secp256k1 directly by importing them (as seen in main.go), it works fine. So in the repo, running main.go works beautifully and a public key is printed out.

So here's the strange error: If I try to write a test for a package using go-secp256k1, I receive a strange error. To replicate, run:

go test github.com/soroushjp/go_wrapper_c_err/cryptoutil -v

The error I receive:

=== RUN TestNewPublicKey
SIGTRAP: trace trap
PC=0x4031730
signal arrived during cgo execution

goroutine 20 [syscall]:
runtime.cgocall(0x40013d0, 0x436ddd0)
    /usr/local/go/src/pkg/runtime/cgocall.c:143 +0xe5 fp=0x436ddb8 sp=0x436dd70
github.com/toxeus/go-secp256k1._Cfunc_secp256k1_start(0x404c14d)
    github.com/toxeus/go-secp256k1/_obj/_cgo_defun.c:99 +0x31 fp=0x436ddd0 sp=0x436ddb8
github.com/toxeus/go-secp256k1.Start()
    /Users/soroushjp/Desktop/Dropbox/Development/go/src/github.com/toxeus/go-secp256k1/secp256k1.go:9 +0x1a fp=0x436ddd8 sp=0x436ddd0
github.com/soroushjp/go_wrapper_c_err/cryptoutil.NewPublicKey(0xc20800e080, 0x20, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0)
    /Users/soroushjp/go/src/github.com/soroushjp/go_wrapper_c_err/cryptoutil/cryptoutil.go:35 +0xbd fp=0x436de98 sp=0x436ddd8
github.com/soroushjp/go_wrapper_c_err/cryptoutil.TestNewPublicKey(0xc20804c090)
    /Users/soroushjp/go/src/github.com/soroushjp/go_wrapper_c_err/cryptoutil/cryptoutil_test.go:10 +0x5f fp=0x436df68 sp=0x436de98
testing.tRunner(0xc20804c090, 0x420e110)
    /usr/local/go/src/pkg/testing/testing.go:422 +0x8b fp=0x436df98 sp=0x436df68
runtime.goexit()
    /usr/local/go/src/pkg/runtime/proc.c:1445 fp=0x436dfa0 sp=0x436df98
created by testing.RunTests
    /usr/local/go/src/pkg/testing/testing.go:504 +0x8db

goroutine 16 [chan receive]:
testing.RunTests(0x418fe08, 0x420e110, 0x1, 0x1, 0x1)
    /usr/local/go/src/pkg/testing/testing.go:505 +0x923
testing.Main(0x418fe08, 0x420e110, 0x1, 0x1, 0x4216960, 0x0, 0x0, 0x4216960, 0x0, 0x0)
    /usr/local/go/src/pkg/testing/testing.go:435 +0x84
main.main()
    github.com/soroushjp/go_wrapper_c_err/cryptoutil/_test/_testmain.go:47 +0x9c

goroutine 19 [finalizer wait]:
runtime.park(0x401c710, 0x4231e98, 0x4215dc9)
    /usr/local/go/src/pkg/runtime/proc.c:1369 +0x89
runtime.parkunlock(0x4231e98, 0x4215dc9)
    /usr/local/go/src/pkg/runtime/proc.c:1385 +0x3b
runfinq()
    /usr/local/go/src/pkg/runtime/mgc0.c:2644 +0xcf
runtime.goexit()
    /usr/local/go/src/pkg/runtime/proc.c:1445

goroutine 17 [syscall]:
runtime.goexit()
    /usr/local/go/src/pkg/runtime/proc.c:1445

rax     0x4031720
rbx     0xc208018d80
rcx     0xc208002a20
rdx     0x0
rdi     0x4403a90
rsi     0xc208002a20
rbp     0xb0103e30
rsp     0xb006efc0
r8      0x1
r9      0x3f
r10     0x3
r11     0x7fffffffffffffff
r12     0x7fff74c4e420
r13     0x1b8f53c9daf8
r14     0x4403a78
r15     0x4403a30
rip     0x4031730
rflags  0x246
cs      0x2b
fs      0x0
gs      0x0
exit status 2
FAIL    github.com/soroushjp/go_wrapper_c_err/cryptoutil    0.016s

My testing code is extremely minimal and almost identical to what is going on in main.go:

package cryptoutil

import (
    "fmt"
    "testing"
)

func TestNewPublicKey(t *testing.T) {
    privateKey := NewPrivateKey()
    publicKey, err := NewPublicKey(privateKey)
    if err != nil {
        t.Error(err)
    }
    fmt.Println(publicKey)
}

Any idea what is going on here? What is happening different between 'go test' and 'go run' that's causing the ECDSA wrapper to run into this error?


Solution

  • Simply updating from Go 1.4 from 1.3 solved the issue for me on OS X Mavericks. The Go installer at golang.org will remove any older versions of Go when installing 1.4