From f04c893907b027138e6f4f25944f42a5827c5cfd Mon Sep 17 00:00:00 2001 From: minh-bq <97180373+minh-bq@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:19:08 +0700 Subject: [PATCH] crypto/bls: disable blst by default (#410) * 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. --- build/ci.go | 6 ++++++ crypto/bls/bls.go | 6 ------ crypto/bls/blst/aliases.go | 2 +- crypto/bls/blst/bls_benchmark_test.go | 5 +++-- crypto/bls/blst/init.go | 2 +- crypto/bls/blst/public_key.go | 3 ++- crypto/bls/blst/public_key_test.go | 5 +++-- crypto/bls/blst/secret_key.go | 2 +- crypto/bls/blst/secret_key_test.go | 5 +++-- crypto/bls/blst/signature.go | 2 +- crypto/bls/blst/signature_test.go | 2 +- crypto/bls/blst/stub.go | 17 ++++++++++++++++- crypto/bls/herumi/init.go | 16 ---------------- go.mod | 2 +- go.sum | 2 -- 15 files changed, 39 insertions(+), 38 deletions(-) delete mode 100644 crypto/bls/herumi/init.go diff --git a/build/ci.go b/build/ci.go index e6b24754d8..dd54b669a4 100644 --- a/build/ci.go +++ b/build/ci.go @@ -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() @@ -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() diff --git a/crypto/bls/bls.go b/crypto/bls/bls.go index eb266d2b7e..35664fbeba 100644 --- a/crypto/bls/bls.go +++ b/crypto/bls/bls.go @@ -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) diff --git a/crypto/bls/blst/aliases.go b/crypto/bls/blst/aliases.go index 8f3028a7eb..2c06920b4e 100644 --- a/crypto/bls/blst/aliases.go +++ b/crypto/bls/blst/aliases.go @@ -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 diff --git a/crypto/bls/blst/bls_benchmark_test.go b/crypto/bls/blst/bls_benchmark_test.go index a11332882d..7b6d435656 100644 --- a/crypto/bls/blst/bls_benchmark_test.go +++ b/crypto/bls/blst/bls_benchmark_test.go @@ -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" ) diff --git a/crypto/bls/blst/init.go b/crypto/bls/blst/init.go index ab8be94ca5..71eb6379af 100644 --- a/crypto/bls/blst/init.go +++ b/crypto/bls/blst/init.go @@ -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 diff --git a/crypto/bls/blst/public_key.go b/crypto/bls/blst/public_key.go index f543241057..2ef7484935 100644 --- a/crypto/bls/blst/public_key.go +++ b/crypto/bls/blst/public_key.go @@ -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" diff --git a/crypto/bls/blst/public_key_test.go b/crypto/bls/blst/public_key_test.go index 9b9ed5408e..e3aedc7682 100644 --- a/crypto/bls/blst/public_key_test.go +++ b/crypto/bls/blst/public_key_test.go @@ -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" diff --git a/crypto/bls/blst/secret_key.go b/crypto/bls/blst/secret_key.go index 330a69a769..18cbacbb5c 100644 --- a/crypto/bls/blst/secret_key.go +++ b/crypto/bls/blst/secret_key.go @@ -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 diff --git a/crypto/bls/blst/secret_key_test.go b/crypto/bls/blst/secret_key_test.go index 0d440ace4a..ca1222ae33 100644 --- a/crypto/bls/blst/secret_key_test.go +++ b/crypto/bls/blst/secret_key_test.go @@ -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_test @@ -6,10 +6,11 @@ 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" diff --git a/crypto/bls/blst/signature.go b/crypto/bls/blst/signature.go index 85c0d11e01..d5d41c387e 100644 --- a/crypto/bls/blst/signature.go +++ b/crypto/bls/blst/signature.go @@ -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 diff --git a/crypto/bls/blst/signature_test.go b/crypto/bls/blst/signature_test.go index 6d4762273a..41953fcd39 100644 --- a/crypto/bls/blst/signature_test.go +++ b/crypto/bls/blst/signature_test.go @@ -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 diff --git a/crypto/bls/blst/stub.go b/crypto/bls/blst/stub.go index a75e7e7338..631b4286f1 100644 --- a/crypto/bls/blst/stub.go +++ b/crypto/bls/blst/stub.go @@ -1,4 +1,4 @@ -//go:build blst_disabled +//go:build !blst_enabled package blst @@ -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) @@ -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) @@ -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) diff --git a/crypto/bls/herumi/init.go b/crypto/bls/herumi/init.go deleted file mode 100644 index 9afa76ab5e..0000000000 --- a/crypto/bls/herumi/init.go +++ /dev/null @@ -1,16 +0,0 @@ -package herumi - -import "github.com/herumi/bls-eth-go-binary/bls" - -// HerumiInit allows the required curve orders and appropriate sub-groups to be initialized. -func HerumiInit() { - if err := bls.Init(bls.BLS12_381); err != nil { - panic(err) - } - if err := bls.SetETHmode(bls.EthModeDraft07); err != nil { - panic(err) - } - // Check subgroup order for pubkeys and signatures. - bls.VerifyPublicKeyOrder(true) - bls.VerifySignatureOrder(true) -} diff --git a/go.mod b/go.mod index d74970c836..b485f4582d 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 173d174db7..1a1d09adc7 100644 --- a/go.sum +++ b/go.sum @@ -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=