Skip to content

blst Go bindings no longer compile with Go 1.24 #245

@mark-rushakoff

Description

@mark-rushakoff

I tried building Go code that references blst at the latest release, and with go1.24rc1 the blst bindings fail to build.

This failure can be reproduced from the blst repository, in the bindings/go directory.

Tests run fine with go1.23:

$ go version ; go test
go version go1.23.4 darwin/arm64
PASS
ok  	github.com/supranational/blst/bindings/go	0.715

With go1.24rc1, the bindings fail to build:

$ ~/go/bin/go1.24rc1 version;  ~/go/bin/go1.24rc1 test .
go version go1.24rc1 darwin/arm64
# github.com/supranational/blst/bindings/go [github.com/supranational/blst/bindings/go.test]
./blst.go:237:11: cannot define new methods on non-local type SecretKey
./blst.go:324:15: cannot define new methods on non-local type SecretKey
./blst.go:444:11: cannot define new methods on non-local type Fp12
./blst.go:448:11: cannot define new methods on non-local type Fp12
./blst.go:452:11: cannot define new methods on non-local type Fp12
./blst.go:456:11: cannot define new methods on non-local type Fp12
./blst.go:462:12: cannot define new methods on non-local type Fp12
./blst.go:482:11: cannot define new methods on non-local type P1Affine
./blst.go:487:11: cannot define new methods on non-local type P1Affine
./blst.go:495:12: cannot define new methods on non-local type P2Affine
./blst.go:495:12: too many errors
FAIL	github.com/supranational/blst/bindings/go [build failed]
FAIL

This appears to be a deliberate change in the Go toolchain, according to the draft Go 1.24 release notes:

The compiler already disallowed defining new methods with receiver types that were cgo-generated, but it was possible to circumvent that restriction via an alias type. Go 1.24 now always reports an error if a receiver denotes a cgo-generated type, whether directly or indirectly (through an alias type).

The HTML comments at that paragraph indicate golang/go#60725 and golang/go#57926.

The fix is probably changing this set of types:

blst/bindings/go/blst.go

Lines 171 to 182 in bef14ca

type Scalar = C.blst_scalar
type Fp = C.blst_fp
type Fp2 = C.blst_fp2
type Fp6 = C.blst_fp6
type Fp12 = C.blst_fp12
type P1 = C.blst_p1
type P2 = C.blst_p2
type P1Affine = C.blst_p1_affine
type P2Affine = C.blst_p2_affine
type Message = []byte
type Pairing = []C.blst_pairing
type SecretKey = Scalar

to "normal" type definitions (e.g. type Scalar C.blst_scalar without the = in the middle) and then defining the required methods, including forwarding all the other methods that already exist on the C.blst_scalar type. I think this would avoid breaking any existing usage, but I haven't really used this package yet so it's a bit of a guess on my part.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions