Skip to content

Commit

Permalink
crypto/bls: disable blst by default (#410)
Browse files Browse the repository at this point in the history
* crypto/bls: remove unused herumi library

This library is deprecated in prysm and unused in Ronin, so this commit removes
that library.

* crypto/bls: add missing functions to bls stub file

The bls stub helps to make compilation successful when blst is disabled. This
commit adds some missing functions that are used but not included in the stub.

* crypto/bls: disable blst by default

Blst is the library Ronin uses to support BLS signature. The library is
implemented in C and assembly which requires CGO in Go and correct flag to build
the portable version across different architectures.

Other services may use Ronin as a library and don't need to use BLS feature.
However, currently, they still needs CGO and correct CGO flag, which is
cumbersome.

This commit disables blst by default so other services that use Ronin as a
library do not need to care about BLS. Ronin standalone build will explicitly
enable BLS feature.
  • Loading branch information
minh-bq authored Mar 25, 2024
1 parent 62b7e73 commit 86ca613
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 38 deletions.
6 changes: 6 additions & 0 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ func doInstall(cmdline []string) {
// Show packages during build.
gobuild.Args = append(gobuild.Args, "-v")

// Enable blst on Ronin build
gobuild.Args = append(gobuild.Args, "-tags=blst_enabled")

// Now we choose what we're even building.
// Default: collect all 'main' packages in cmd/ and build those.
packages := flag.Args()
Expand Down Expand Up @@ -310,6 +313,9 @@ func doTest(cmdline []string) {
gotest.Args = append(gotest.Args, "-race")
}

// Enable blst on Ronin build
gotest.Args = append(gotest.Args, "-tags=blst_enabled")

packages := []string{"./..."}
if len(flag.CommandLine.Args()) > 0 {
packages = flag.CommandLine.Args()
Expand Down
6 changes: 0 additions & 6 deletions crypto/bls/bls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ package bls
import (
"github.com/ethereum/go-ethereum/crypto/bls/blst"
"github.com/ethereum/go-ethereum/crypto/bls/common"
"github.com/ethereum/go-ethereum/crypto/bls/herumi"
)

// Initialize herumi temporarily while we transition to blst for ethdo.
func init() {
herumi.HerumiInit()
}

// SecretKeyFromBytes creates a BLS private key from a BigEndian byte slice.
func SecretKeyFromBytes(privKey []byte) (SecretKey, error) {
return blst.SecretKeyFromBytes(privKey)
Expand Down
2 changes: 1 addition & 1 deletion crypto/bls/blst/aliases.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && !blst_disabled
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && blst_enabled

package blst

Expand Down
5 changes: 3 additions & 2 deletions crypto/bls/blst/bls_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && !blst_disabled
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && blst_enabled

package blst_test

import (
"github.com/stretchr/testify/require"
"testing"

"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/crypto/bls/blst"
"github.com/ethereum/go-ethereum/crypto/bls/common"
)
Expand Down
2 changes: 1 addition & 1 deletion crypto/bls/blst/init.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && !blst_disabled
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && blst_enabled

package blst

Expand Down
3 changes: 2 additions & 1 deletion crypto/bls/blst/public_key.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && !blst_disabled
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && blst_enabled

package blst

import (
"fmt"

"github.com/ethereum/go-ethereum/crypto/bls/common"
"github.com/ethereum/go-ethereum/params"
lru "github.com/hashicorp/golang-lru"
Expand Down
5 changes: 3 additions & 2 deletions crypto/bls/blst/public_key_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && !blst_disabled
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && blst_enabled

package blst_test

import (
"bytes"
"errors"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"

"github.com/ethereum/go-ethereum/crypto/bls/blst"
"github.com/ethereum/go-ethereum/crypto/bls/common"
Expand Down
2 changes: 1 addition & 1 deletion crypto/bls/blst/secret_key.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && !blst_disabled
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && blst_enabled

package blst

Expand Down
5 changes: 3 additions & 2 deletions crypto/bls/blst/secret_key_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && !blst_disabled
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && blst_enabled

package blst_test

import (
"bytes"
"crypto/rand"
"errors"
"testing"

byteutil "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"

"github.com/ethereum/go-ethereum/crypto/bls/blst"
"github.com/ethereum/go-ethereum/crypto/bls/common"
Expand Down
2 changes: 1 addition & 1 deletion crypto/bls/blst/signature.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && !blst_disabled
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && blst_enabled

package blst

Expand Down
2 changes: 1 addition & 1 deletion crypto/bls/blst/signature_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && !blst_disabled
//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && blst_enabled

package blst

Expand Down
17 changes: 16 additions & 1 deletion crypto/bls/blst/stub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build blst_disabled
//go:build !blst_enabled

package blst

Expand All @@ -22,6 +22,11 @@ func (s SecretKey) Sign(_ []byte) common.Signature {
panic(err)
}

// SignProof -- stub
func (s SecretKey) SignProof(_ []byte) common.Signature {
panic(err)
}

// Marshal -- stub
func (s SecretKey) Marshal() []byte {
panic(err)
Expand Down Expand Up @@ -68,6 +73,11 @@ func (s Signature) Verify(_ common.PublicKey, _ []byte) bool {
panic(err)
}

// VerifyProof -- stub
func (s Signature) VerifyProof(_ common.PublicKey, _ []byte) bool {
panic(err)
}

// AggregateVerify -- stub
func (s Signature) AggregateVerify(_ []common.PublicKey, _ [][32]byte) bool {
panic(err)
Expand Down Expand Up @@ -133,6 +143,11 @@ func AggregateCompressedSignatures(multiSigs [][]byte) (common.Signature, error)
panic(err)
}

// VerifySignature -- stub
func VerifySignature(_ []byte, _ [32]byte, _ common.PublicKey) (bool, error) {
panic(err)
}

// VerifyMultipleSignatures -- stub
func VerifyMultipleSignatures(_ [][]byte, _ [][32]byte, _ []common.PublicKey) (bool, error) {
panic(err)
Expand Down
16 changes: 0 additions & 16 deletions crypto/bls/herumi/init.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ require (
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be
github.com/golang/mock v1.6.0
github.com/grafana/pyroscope-go v1.1.1
github.com/herumi/bls-eth-go-binary v1.31.0
github.com/klauspost/compress v1.17.3
github.com/pkg/errors v0.9.1
github.com/supranational/blst v0.3.11
Expand Down Expand Up @@ -108,6 +107,7 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/pprof v0.0.0-20230405160723-4a4c7d95572b // indirect
github.com/grafana/pyroscope-go/godeltaprof v0.1.6 // indirect
github.com/herumi/bls-eth-go-binary v1.31.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,6 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
Expand Down

0 comments on commit 86ca613

Please sign in to comment.