Skip to content

Commit

Permalink
add bls signer abstraction from eigensdk
Browse files Browse the repository at this point in the history
update eigensdk to that commit

upgrade logger to remove noop

fix testmode

fix nil pointers

rebase and fix

rebase

update to new eigensdk

add bls signer to plugin
  • Loading branch information
shrimalmadhur committed Jan 8, 2025
1 parent c33ad29 commit 5af9a4b
Show file tree
Hide file tree
Showing 54 changed files with 423 additions and 250 deletions.
5 changes: 3 additions & 2 deletions api/clients/retrieval_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package clients_test
import (
"bytes"
"context"

"runtime"
"testing"

"github.com/Layr-Labs/eigenda/api/clients"
clientsmock "github.com/Layr-Labs/eigenda/api/clients/mock"
"github.com/Layr-Labs/eigenda/common/testutils"
"github.com/Layr-Labs/eigenda/core"
coreindexer "github.com/Layr-Labs/eigenda/core/indexer"
coremock "github.com/Layr-Labs/eigenda/core/mock"
Expand All @@ -17,7 +19,6 @@ import (
"github.com/Layr-Labs/eigenda/encoding/kzg/verifier"
"github.com/Layr-Labs/eigenda/encoding/utils/codec"
indexermock "github.com/Layr-Labs/eigenda/indexer/mock"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/consensys/gnark-crypto/ecc/bn254"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -96,7 +97,7 @@ func setup(t *testing.T) {
if err != nil {
t.Fatal(err)
}
logger := logging.NewNoopLogger()
logger := testutils.GetLogger()
indexer = &indexermock.MockIndexer{}
indexer.On("Index").Return(nil).Once()

Expand Down
5 changes: 3 additions & 2 deletions common/geth/multihoming_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package geth_test
import (
"context"
"fmt"

"math/big"
"testing"

"github.com/Layr-Labs/eigenda/common/geth"
damock "github.com/Layr-Labs/eigenda/common/mock"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigenda/common/testutils"
"github.com/ethereum/go-ethereum/rpc"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand All @@ -25,7 +26,7 @@ func (j *JsonError) Error() string { return "json error" }
func (j *JsonError) ErrorCode() int { return -32000 }

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

ethClientCfg := geth.EthClientConfig{
RPCURLs: rpcURLs,
Expand Down
4 changes: 2 additions & 2 deletions common/ratelimit/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/Layr-Labs/eigenda/common"
"github.com/Layr-Labs/eigenda/common/ratelimit"
"github.com/Layr-Labs/eigenda/common/store"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigenda/common/testutils"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
)
Expand All @@ -26,7 +26,7 @@ func makeTestRatelimiter() (common.RateLimiter, error) {
return nil, err
}

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

return ratelimiter, nil

Expand Down
5 changes: 3 additions & 2 deletions common/store/dynamo_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package store_test
import (
"context"
"fmt"

"os"
"testing"
"time"
Expand All @@ -12,14 +13,14 @@ import (
"github.com/Layr-Labs/eigenda/common/aws/dynamodb"
test_utils "github.com/Layr-Labs/eigenda/common/aws/dynamodb/utils"
"github.com/Layr-Labs/eigenda/common/store"
"github.com/Layr-Labs/eigenda/common/testutils"
"github.com/Layr-Labs/eigenda/inabox/deploy"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/ory/dockertest/v3"
"github.com/stretchr/testify/assert"
)

var (
logger = logging.NewNoopLogger()
logger = testutils.GetLogger()

dockertestPool *dockertest.Pool
dockertestResource *dockertest.Resource
Expand Down
6 changes: 6 additions & 0 deletions common/testutils/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package testutils
import (
"context"
"fmt"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/stretchr/testify/assert"
"golang.org/x/exp/rand"
"os"
"testing"
"time"
)
Expand Down Expand Up @@ -112,3 +114,7 @@ func RandomString(length int) string {
}
return string(b)
}

func GetLogger() logging.Logger {
return logging.NewTextSLogger(os.Stdout, &logging.SLoggerOptions{})
}
4 changes: 2 additions & 2 deletions core/aggregation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"os"
"testing"

"github.com/Layr-Labs/eigenda/common/testutils"
"github.com/Layr-Labs/eigenda/core"
"github.com/Layr-Labs/eigenda/core/mock"
"github.com/Layr-Labs/eigensdk-go/logging"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
)
Expand All @@ -30,7 +30,7 @@ func TestMain(m *testing.M) {
if err != nil {
panic(err)
}
logger := logging.NewNoopLogger()
logger := testutils.GetLogger()
transactor := &mock.MockWriter{}
transactor.On("OperatorIDToAddress").Return(gethcommon.Address{}, nil)
agg, err = core.NewStdSignatureAggregator(logger, transactor)
Expand Down
3 changes: 3 additions & 0 deletions core/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/big"

"github.com/Layr-Labs/eigenda/api/grpc/churner"
sdkSigner "github.com/Layr-Labs/eigensdk-go/signer/bls"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
Expand Down Expand Up @@ -146,6 +147,7 @@ type Writer interface {
RegisterOperator(
ctx context.Context,
keypair *KeyPair,
signer sdkSigner.Signer,
socket string,
quorumIds []QuorumID,
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
Expand All @@ -158,6 +160,7 @@ type Writer interface {
RegisterOperatorWithChurn(
ctx context.Context,
keypair *KeyPair,
signer sdkSigner.Signer,
socket string,
quorumIds []QuorumID,
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
Expand Down
40 changes: 37 additions & 3 deletions core/eth/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/ecdsa"
"fmt"
"encoding/hex"
"math/big"
"strings"

Expand All @@ -29,6 +30,8 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/pingcap/errors"

sdkSigner "github.com/Layr-Labs/eigensdk-go/signer/bls"
)

type ContractBindings struct {
Expand Down Expand Up @@ -288,6 +291,7 @@ func (t *Reader) GetRegisteredQuorumIdsForOperator(ctx context.Context, operator
func (t *Reader) getRegistrationParams(
ctx context.Context,
keypair *core.KeyPair,
sdkSigner sdkSigner.Signer,
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
operatorToAvsRegistrationSigSalt [32]byte,
operatorToAvsRegistrationSigExpiry *big.Int,
Expand All @@ -302,20 +306,50 @@ func (t *Reader) getRegistrationParams(
return nil, nil, err
}


msgToSignG1 := core.NewG1Point(msgToSignG1_.X, msgToSignG1_.Y)
signature := keypair.SignHashedToCurveMessage(msgToSignG1)
sigBytes, err := sdkSigner.SignG1(ctx, msgToSignG1.Serialize())
if err != nil {
return nil, nil, err
}
sig := new(core.Signature)
signature, err := sig.Deserialize(sigBytes)
if err != nil {
return nil, nil, err
}

signedMessageHashParam := regcoordinator.BN254G1Point{
X: signature.X.BigInt(big.NewInt(0)),
Y: signature.Y.BigInt(big.NewInt(0)),
}

g1Point_ := pubKeyG1ToBN254G1Point(keypair.GetPubKeyG1())
g1KeyHex := sdkSigner.GetPublicKeyG1()
g1KeyBytes, err := hex.DecodeString(g1KeyHex)
if err != nil {
return nil, nil, err
}
g1point := new(core.G1Point)
_, err = g1point.Deserialize(g1KeyBytes)
if err != nil {
return nil, nil, err
}
g1Point_ := pubKeyG1ToBN254G1Point(g1point)
g1Point := regcoordinator.BN254G1Point{
X: g1Point_.X,
Y: g1Point_.Y,
}
g2Point_ := pubKeyG2ToBN254G2Point(keypair.GetPubKeyG2())

g2KeyHex := sdkSigner.GetPublicKeyG2()
g2KeyBytes, err := hex.DecodeString(g2KeyHex)
if err != nil {
return nil, nil, err
}
g2point := new(core.G2Point)
_, err = g2point.Deserialize(g2KeyBytes)
if err != nil {
return nil, nil, err
}
g2Point_ := pubKeyG2ToBN254G2Point(g2point)
g2Point := regcoordinator.BN254G2Point{
X: g2Point_.X,
Y: g2Point_.Y,
Expand Down
7 changes: 5 additions & 2 deletions core/eth/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
regcoordinator "github.com/Layr-Labs/eigenda/contracts/bindings/RegistryCoordinator"
"github.com/Layr-Labs/eigenda/core"
"github.com/Layr-Labs/eigensdk-go/logging"
sdkSigner "github.com/Layr-Labs/eigensdk-go/signer/bls"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -59,14 +60,15 @@ func NewWriter(
func (t *Writer) RegisterOperator(
ctx context.Context,
keypair *core.KeyPair,
signer sdkSigner.Signer,
socket string,
quorumIds []core.QuorumID,
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
operatorToAvsRegistrationSigSalt [32]byte,
operatorToAvsRegistrationSigExpiry *big.Int,
) error {

params, operatorSignature, err := t.getRegistrationParams(ctx, keypair, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry)
params, operatorSignature, err := t.getRegistrationParams(ctx, keypair, signer, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry)
if err != nil {
t.logger.Error("Failed to get registration params", "err", err)
return err
Expand Down Expand Up @@ -99,6 +101,7 @@ func (t *Writer) RegisterOperator(
func (t *Writer) RegisterOperatorWithChurn(
ctx context.Context,
keypair *core.KeyPair,
signer sdkSigner.Signer,
socket string,
quorumIds []core.QuorumID,
operatorEcdsaPrivateKey *ecdsa.PrivateKey,
Expand All @@ -107,7 +110,7 @@ func (t *Writer) RegisterOperatorWithChurn(
churnReply *churner.ChurnReply,
) error {

params, operatorSignature, err := t.getRegistrationParams(ctx, keypair, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry)
params, operatorSignature, err := t.getRegistrationParams(ctx, keypair, signer, operatorEcdsaPrivateKey, operatorToAvsRegistrationSigSalt, operatorToAvsRegistrationSigExpiry)
if err != nil {
t.logger.Error("Failed to get registration params", "err", err)
return err
Expand Down
13 changes: 11 additions & 2 deletions core/indexer/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/Layr-Labs/eigenda/common"
"github.com/Layr-Labs/eigenda/common/geth"
"github.com/Layr-Labs/eigenda/common/testutils"
"github.com/Layr-Labs/eigenda/core"
"github.com/Layr-Labs/eigenda/core/eth"
indexedstate "github.com/Layr-Labs/eigenda/core/indexer"
Expand All @@ -26,6 +27,8 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

sdkSigner "github.com/Layr-Labs/eigensdk-go/signer/bls"
sdkSignerTypes "github.com/Layr-Labs/eigensdk-go/signer/bls/types"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rpc"
Expand All @@ -50,6 +53,12 @@ func mustRegisterOperators(env *deploy.Config, logger logging.Logger) {
for _, op := range env.Operators {
tx := mustMakeOperatorTransactor(env, op, logger)

signer, err := sdkSigner.NewSigner(sdkSignerTypes.SignerConfig{
PrivateKey: op.NODE_TEST_PRIVATE_BLS,
SignerType: sdkSignerTypes.PrivateKey,
})
Expect(err).To(BeNil())

keyPair, err := core.MakeKeyPairFromString(op.NODE_TEST_PRIVATE_BLS)
Expect(err).To(BeNil())

Expand All @@ -63,7 +72,7 @@ func mustRegisterOperators(env *deploy.Config, logger logging.Logger) {
privKey, err := crypto.HexToECDSA(op.NODE_PRIVATE_KEY)
Expect(err).To(BeNil())

err = tx.RegisterOperator(context.Background(), keyPair, socket, quorums, privKey, salt, expiry)
err = tx.RegisterOperator(context.Background(), keyPair, signer, socket, quorums, privKey, salt, expiry)
Expect(err).To(BeNil())
}
}
Expand Down Expand Up @@ -154,7 +163,7 @@ var _ = Describe("Indexer", func() {
Skip("No test path provided")
}

logger := logging.NewNoopLogger()
logger := testutils.GetLogger()
ctx, cancel := context.WithCancel(context.Background())
_ = cancel

Expand Down
5 changes: 2 additions & 3 deletions core/meterer/meterer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/Layr-Labs/eigenda/common"
commonaws "github.com/Layr-Labs/eigenda/common/aws"
commondynamodb "github.com/Layr-Labs/eigenda/common/aws/dynamodb"
"github.com/Layr-Labs/eigenda/common/testutils"
"github.com/Layr-Labs/eigenda/core"
"github.com/Layr-Labs/eigenda/core/meterer"
"github.com/Layr-Labs/eigenda/core/mock"
Expand All @@ -22,8 +23,6 @@ import (
"github.com/ory/dockertest/v3"
"github.com/stretchr/testify/assert"
testifymock "github.com/stretchr/testify/mock"

"github.com/Layr-Labs/eigensdk-go/logging"
)

var (
Expand Down Expand Up @@ -108,7 +107,7 @@ func setup(_ *testing.M) {
panic("failed to generate private key")
}

logger = logging.NewNoopLogger()
logger = testutils.GetLogger()
config := meterer.Config{
ChainReadTimeout: 3 * time.Second,
UpdateInterval: 1 * time.Second,
Expand Down
9 changes: 9 additions & 0 deletions core/mock/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"sort"

"github.com/Layr-Labs/eigenda/core"
sdkSigner "github.com/Layr-Labs/eigensdk-go/signer/bls"
sdkSignerTypes "github.com/Layr-Labs/eigensdk-go/signer/bls/types"
"github.com/stretchr/testify/mock"
)

Expand All @@ -25,6 +27,7 @@ var _ core.IndexedChainState = (*ChainDataMock)(nil)
type PrivateOperatorInfo struct {
*core.IndexedOperatorInfo
KeyPair *core.KeyPair
Signer sdkSigner.Signer
Host string
DispersalPort string
RetrievalPort string
Expand Down Expand Up @@ -143,9 +146,15 @@ func (d *ChainDataMock) GetTotalOperatorStateWithQuorums(ctx context.Context, bl
PubkeyG2: d.KeyPairs[id].GetPubKeyG2(),
}

signer, _ := sdkSigner.NewSigner(sdkSignerTypes.SignerConfig{
PrivateKey: d.KeyPairs[id].PrivKey.String(),
SignerType: sdkSignerTypes.Local,
})

private := &PrivateOperatorInfo{
IndexedOperatorInfo: indexed,
KeyPair: d.KeyPairs[id],
Signer: signer,
Host: host,
DispersalPort: dispersalPort,
RetrievalPort: retrievalPort,
Expand Down
Loading

0 comments on commit 5af9a4b

Please sign in to comment.