Skip to content

Commit 61cd7f9

Browse files
add bls signer abstraction from eigensdk (Layr-Labs#985)
1 parent fcd50ae commit 61cd7f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+487
-304
lines changed

.github/workflows/codeql-scanning.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- name: Install golang
4545
uses: actions/setup-go@v3
4646
with:
47-
go-version: '1.21.1'
47+
go-version: '1.21.13'
4848

4949
- name: Custom build using make
5050
run: |

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ARG SEMVER=""
77
ARG GITCOMMIT=""
88
ARG GITDATE=""
99

10-
FROM golang:1.21.1-alpine3.18 AS base-builder
10+
FROM golang:1.21.13-alpine3.20 AS base-builder
1111
RUN apk add --no-cache make musl-dev linux-headers gcc git jq bash
1212

1313
# Common build stage

api/builder/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.21.12-bookworm
1+
FROM golang:1.21.13-bookworm
22

33
# The URL where the protoc binary can be downloaded. Is different depending on architecture.
44
ARG PROTOC_URL

api/clients/retrieval_client_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/Layr-Labs/eigenda/api/clients"
1010
clientsmock "github.com/Layr-Labs/eigenda/api/clients/mock"
11+
"github.com/Layr-Labs/eigenda/common/testutils"
1112
"github.com/Layr-Labs/eigenda/core"
1213
coreindexer "github.com/Layr-Labs/eigenda/core/indexer"
1314
coremock "github.com/Layr-Labs/eigenda/core/mock"
@@ -17,7 +18,6 @@ import (
1718
"github.com/Layr-Labs/eigenda/encoding/kzg/verifier"
1819
"github.com/Layr-Labs/eigenda/encoding/utils/codec"
1920
indexermock "github.com/Layr-Labs/eigenda/indexer/mock"
20-
"github.com/Layr-Labs/eigensdk-go/logging"
2121
"github.com/consensys/gnark-crypto/ecc/bn254"
2222
"github.com/stretchr/testify/assert"
2323
"github.com/stretchr/testify/mock"
@@ -96,7 +96,7 @@ func setup(t *testing.T) {
9696
if err != nil {
9797
t.Fatal(err)
9898
}
99-
logger := logging.NewNoopLogger()
99+
logger := testutils.GetLogger()
100100
indexer = &indexermock.MockIndexer{}
101101
indexer.On("Index").Return(nil).Once()
102102

common/geth/multihoming_client_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/Layr-Labs/eigenda/common/geth"
1010
damock "github.com/Layr-Labs/eigenda/common/mock"
11-
"github.com/Layr-Labs/eigensdk-go/logging"
11+
"github.com/Layr-Labs/eigenda/common/testutils"
1212
"github.com/ethereum/go-ethereum/rpc"
1313
"github.com/stretchr/testify/mock"
1414
"github.com/stretchr/testify/require"
@@ -25,7 +25,7 @@ func (j *JsonError) Error() string { return "json error" }
2525
func (j *JsonError) ErrorCode() int { return -32000 }
2626

2727
func makeTestMultihomingClient(numRetries int, designatedError error) (*geth.MultiHomingClient, error) {
28-
logger := logging.NewNoopLogger()
28+
logger := testutils.GetLogger()
2929

3030
ethClientCfg := geth.EthClientConfig{
3131
RPCURLs: rpcURLs,

common/ratelimit/ratelimit_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/Layr-Labs/eigenda/common"
99
"github.com/Layr-Labs/eigenda/common/ratelimit"
1010
"github.com/Layr-Labs/eigenda/common/store"
11-
"github.com/Layr-Labs/eigensdk-go/logging"
11+
"github.com/Layr-Labs/eigenda/common/testutils"
1212
"github.com/prometheus/client_golang/prometheus"
1313
"github.com/stretchr/testify/assert"
1414
)
@@ -26,7 +26,7 @@ func makeTestRatelimiter() (common.RateLimiter, error) {
2626
return nil, err
2727
}
2828

29-
ratelimiter := ratelimit.NewRateLimiter(prometheus.NewRegistry(), globalParams, bucketStore, logging.NewNoopLogger())
29+
ratelimiter := ratelimit.NewRateLimiter(prometheus.NewRegistry(), globalParams, bucketStore, testutils.GetLogger())
3030

3131
return ratelimiter, nil
3232

common/store/dynamo_store_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import (
1212
"github.com/Layr-Labs/eigenda/common/aws/dynamodb"
1313
test_utils "github.com/Layr-Labs/eigenda/common/aws/dynamodb/utils"
1414
"github.com/Layr-Labs/eigenda/common/store"
15+
"github.com/Layr-Labs/eigenda/common/testutils"
1516
"github.com/Layr-Labs/eigenda/inabox/deploy"
16-
"github.com/Layr-Labs/eigensdk-go/logging"
1717
"github.com/ory/dockertest/v3"
1818
"github.com/stretchr/testify/assert"
1919
)
2020

2121
var (
22-
logger = logging.NewNoopLogger()
22+
logger = testutils.GetLogger()
2323

2424
dockertestPool *dockertest.Pool
2525
dockertestResource *dockertest.Resource

common/testutils/test_utils.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ package testutils
33
import (
44
"context"
55
"fmt"
6-
"github.com/stretchr/testify/assert"
7-
"golang.org/x/exp/rand"
6+
"os"
87
"testing"
98
"time"
9+
10+
"github.com/Layr-Labs/eigensdk-go/logging"
11+
"github.com/stretchr/testify/assert"
12+
"golang.org/x/exp/rand"
1013
)
1114

1215
// InitializeRandom initializes the random number generator. If no arguments are provided, then the seed is randomly
@@ -112,3 +115,7 @@ func RandomString(length int) string {
112115
}
113116
return string(b)
114117
}
118+
119+
func GetLogger() logging.Logger {
120+
return logging.NewTextSLogger(os.Stdout, &logging.SLoggerOptions{})
121+
}

core/aggregation_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"os"
88
"testing"
99

10+
"github.com/Layr-Labs/eigenda/common/testutils"
1011
"github.com/Layr-Labs/eigenda/core"
1112
"github.com/Layr-Labs/eigenda/core/mock"
12-
"github.com/Layr-Labs/eigensdk-go/logging"
1313
gethcommon "github.com/ethereum/go-ethereum/common"
1414
"github.com/stretchr/testify/assert"
1515
)
@@ -30,7 +30,7 @@ func TestMain(m *testing.M) {
3030
if err != nil {
3131
panic(err)
3232
}
33-
logger := logging.NewNoopLogger()
33+
logger := testutils.GetLogger()
3434
transactor := &mock.MockWriter{}
3535
transactor.On("OperatorIDToAddress").Return(gethcommon.Address{}, nil)
3636
agg, err = core.NewStdSignatureAggregator(logger, transactor)

core/chainio.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"math/big"
77

88
"github.com/Layr-Labs/eigenda/api/grpc/churner"
9+
blssigner "github.com/Layr-Labs/eigensdk-go/signer/bls"
910
gethcommon "github.com/ethereum/go-ethereum/common"
1011
"github.com/ethereum/go-ethereum/core/types"
1112
)
@@ -145,7 +146,7 @@ type Writer interface {
145146
// will be returned.
146147
RegisterOperator(
147148
ctx context.Context,
148-
keypair *KeyPair,
149+
signer blssigner.Signer,
149150
socket string,
150151
quorumIds []QuorumID,
151152
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
@@ -157,7 +158,7 @@ type Writer interface {
157158
// with the provided signature from the churner
158159
RegisterOperatorWithChurn(
159160
ctx context.Context,
160-
keypair *KeyPair,
161+
signer blssigner.Signer,
161162
socket string,
162163
quorumIds []QuorumID,
163164
operatorEcdsaPrivateKey *ecdsa.PrivateKey,

core/eth/reader.go

+39-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package eth
33
import (
44
"context"
55
"crypto/ecdsa"
6+
"encoding/hex"
67
"fmt"
78
"math/big"
89
"strings"
@@ -29,6 +30,8 @@ import (
2930
"github.com/ethereum/go-ethereum/core/types"
3031
"github.com/ethereum/go-ethereum/crypto"
3132
"github.com/pingcap/errors"
33+
34+
blssigner "github.com/Layr-Labs/eigensdk-go/signer/bls"
3235
)
3336

3437
type ContractBindings struct {
@@ -287,7 +290,7 @@ func (t *Reader) GetRegisteredQuorumIdsForOperator(ctx context.Context, operator
287290

288291
func (t *Reader) getRegistrationParams(
289292
ctx context.Context,
290-
keypair *core.KeyPair,
293+
blssigner blssigner.Signer,
291294
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
292295
operatorToAvsRegistrationSigSalt [32]byte,
293296
operatorToAvsRegistrationSigExpiry *big.Int,
@@ -303,24 +306,55 @@ func (t *Reader) getRegistrationParams(
303306
}
304307

305308
msgToSignG1 := core.NewG1Point(msgToSignG1_.X, msgToSignG1_.Y)
306-
signature := keypair.SignHashedToCurveMessage(msgToSignG1)
309+
sigBytes, err := blssigner.SignG1(ctx, msgToSignG1.Serialize())
310+
if err != nil {
311+
return nil, nil, err
312+
}
313+
sig := new(core.Signature)
314+
g, err := sig.Deserialize(sigBytes)
315+
if err != nil {
316+
return nil, nil, err
317+
}
318+
signature := &core.Signature{
319+
G1Point: g,
320+
}
307321

308322
signedMessageHashParam := regcoordinator.BN254G1Point{
309323
X: signature.X.BigInt(big.NewInt(0)),
310324
Y: signature.Y.BigInt(big.NewInt(0)),
311325
}
312326

313-
g1Point_ := pubKeyG1ToBN254G1Point(keypair.GetPubKeyG1())
327+
g1KeyHex := blssigner.GetPublicKeyG1()
328+
g1KeyBytes, err := hex.DecodeString(g1KeyHex)
329+
if err != nil {
330+
return nil, nil, err
331+
}
332+
g1point := new(core.G1Point)
333+
g1point, err = g1point.Deserialize(g1KeyBytes)
334+
if err != nil {
335+
return nil, nil, err
336+
}
337+
g1Point_ := pubKeyG1ToBN254G1Point(g1point)
314338
g1Point := regcoordinator.BN254G1Point{
315339
X: g1Point_.X,
316340
Y: g1Point_.Y,
317341
}
318-
g2Point_ := pubKeyG2ToBN254G2Point(keypair.GetPubKeyG2())
342+
343+
g2KeyHex := blssigner.GetPublicKeyG2()
344+
g2KeyBytes, err := hex.DecodeString(g2KeyHex)
345+
if err != nil {
346+
return nil, nil, err
347+
}
348+
g2point := new(core.G2Point)
349+
g2point, err = g2point.Deserialize(g2KeyBytes)
350+
if err != nil {
351+
return nil, nil, err
352+
}
353+
g2Point_ := pubKeyG2ToBN254G2Point(g2point)
319354
g2Point := regcoordinator.BN254G2Point{
320355
X: g2Point_.X,
321356
Y: g2Point_.Y,
322357
}
323-
324358
params := regcoordinator.IBLSApkRegistryPubkeyRegistrationParams{
325359
PubkeyRegistrationSignature: signedMessageHashParam,
326360
PubkeyG1: g1Point,

core/eth/writer.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ import (
66
"encoding/hex"
77
"encoding/json"
88
"fmt"
9-
"github.com/Layr-Labs/eigenda/api"
10-
dreg "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDADisperserRegistry"
119
"log"
1210
"math/big"
1311

12+
"github.com/Layr-Labs/eigenda/api"
13+
dreg "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDADisperserRegistry"
14+
1415
"github.com/Layr-Labs/eigenda/api/grpc/churner"
1516
"github.com/Layr-Labs/eigenda/common"
1617
eigendasrvmg "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDAServiceManager"
1718
regcoordinator "github.com/Layr-Labs/eigenda/contracts/bindings/RegistryCoordinator"
1819
"github.com/Layr-Labs/eigenda/core"
1920
"github.com/Layr-Labs/eigensdk-go/logging"
21+
blssigner "github.com/Layr-Labs/eigensdk-go/signer/bls"
2022
"github.com/ethereum/go-ethereum/accounts/abi/bind"
2123
gethcommon "github.com/ethereum/go-ethereum/common"
2224
"github.com/ethereum/go-ethereum/core/types"
@@ -61,15 +63,15 @@ func NewWriter(
6163
// will be returned.
6264
func (t *Writer) RegisterOperator(
6365
ctx context.Context,
64-
keypair *core.KeyPair,
66+
signer blssigner.Signer,
6567
socket string,
6668
quorumIds []core.QuorumID,
6769
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
6870
operatorToAvsRegistrationSigSalt [32]byte,
6971
operatorToAvsRegistrationSigExpiry *big.Int,
7072
) error {
7173

72-
params, operatorSignature, err := t.getRegistrationParams(ctx, keypair, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry)
74+
params, operatorSignature, err := t.getRegistrationParams(ctx, signer, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry)
7375
if err != nil {
7476
t.logger.Error("Failed to get registration params", "err", err)
7577
return err
@@ -101,7 +103,7 @@ func (t *Writer) RegisterOperator(
101103
// with the provided signature from the churner
102104
func (t *Writer) RegisterOperatorWithChurn(
103105
ctx context.Context,
104-
keypair *core.KeyPair,
106+
signer blssigner.Signer,
105107
socket string,
106108
quorumIds []core.QuorumID,
107109
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
@@ -110,7 +112,7 @@ func (t *Writer) RegisterOperatorWithChurn(
110112
churnReply *churner.ChurnReply,
111113
) error {
112114

113-
params, operatorSignature, err := t.getRegistrationParams(ctx, keypair, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry)
115+
params, operatorSignature, err := t.getRegistrationParams(ctx, signer, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry)
114116
if err != nil {
115117
t.logger.Error("Failed to get registration params", "err", err)
116118
return err

core/indexer/state_test.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/Layr-Labs/eigenda/common"
2020
"github.com/Layr-Labs/eigenda/common/geth"
21+
"github.com/Layr-Labs/eigenda/common/testutils"
2122
"github.com/Layr-Labs/eigenda/core"
2223
"github.com/Layr-Labs/eigenda/core/eth"
2324
indexedstate "github.com/Layr-Labs/eigenda/core/indexer"
@@ -26,6 +27,8 @@ import (
2627
. "github.com/onsi/ginkgo/v2"
2728
. "github.com/onsi/gomega"
2829

30+
blssigner "github.com/Layr-Labs/eigensdk-go/signer/bls"
31+
blssignerTypes "github.com/Layr-Labs/eigensdk-go/signer/bls/types"
2932
gethcommon "github.com/ethereum/go-ethereum/common"
3033
"github.com/ethereum/go-ethereum/crypto"
3134
"github.com/ethereum/go-ethereum/rpc"
@@ -50,7 +53,10 @@ func mustRegisterOperators(env *deploy.Config, logger logging.Logger) {
5053
for _, op := range env.Operators {
5154
tx := mustMakeOperatorTransactor(env, op, logger)
5255

53-
keyPair, err := core.MakeKeyPairFromString(op.NODE_TEST_PRIVATE_BLS)
56+
signer, err := blssigner.NewSigner(blssignerTypes.SignerConfig{
57+
PrivateKey: op.NODE_TEST_PRIVATE_BLS,
58+
SignerType: blssignerTypes.PrivateKey,
59+
})
5460
Expect(err).To(BeNil())
5561

5662
socket := fmt.Sprintf("%v:%v", op.NODE_HOSTNAME, op.NODE_DISPERSAL_PORT)
@@ -63,7 +69,7 @@ func mustRegisterOperators(env *deploy.Config, logger logging.Logger) {
6369
privKey, err := crypto.HexToECDSA(op.NODE_PRIVATE_KEY)
6470
Expect(err).To(BeNil())
6571

66-
err = tx.RegisterOperator(context.Background(), keyPair, socket, quorums, privKey, salt, expiry)
72+
err = tx.RegisterOperator(context.Background(), signer, socket, quorums, privKey, salt, expiry)
6773
Expect(err).To(BeNil())
6874
}
6975
}
@@ -154,7 +160,7 @@ var _ = Describe("Indexer", func() {
154160
Skip("No test path provided")
155161
}
156162

157-
logger := logging.NewNoopLogger()
163+
logger := testutils.GetLogger()
158164
ctx, cancel := context.WithCancel(context.Background())
159165
_ = cancel
160166

core/meterer/meterer_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/Layr-Labs/eigenda/common"
1313
commonaws "github.com/Layr-Labs/eigenda/common/aws"
1414
commondynamodb "github.com/Layr-Labs/eigenda/common/aws/dynamodb"
15+
"github.com/Layr-Labs/eigenda/common/testutils"
1516
"github.com/Layr-Labs/eigenda/core"
1617
"github.com/Layr-Labs/eigenda/core/meterer"
1718
"github.com/Layr-Labs/eigenda/core/mock"
@@ -22,8 +23,6 @@ import (
2223
"github.com/ory/dockertest/v3"
2324
"github.com/stretchr/testify/assert"
2425
testifymock "github.com/stretchr/testify/mock"
25-
26-
"github.com/Layr-Labs/eigensdk-go/logging"
2726
)
2827

2928
var (
@@ -108,7 +107,7 @@ func setup(_ *testing.M) {
108107
panic("failed to generate private key")
109108
}
110109

111-
logger = logging.NewNoopLogger()
110+
logger = testutils.GetLogger()
112111
config := meterer.Config{
113112
ChainReadTimeout: 3 * time.Second,
114113
UpdateInterval: 1 * time.Second,

0 commit comments

Comments
 (0)