Skip to content

Commit

Permalink
Merge branch 'master' into 771-read-traffic-generator
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Littley <cody@eigenlabs.org>
  • Loading branch information
cody-littley committed Oct 3, 2024
2 parents 75de082 + b3d1c35 commit 54af37a
Show file tree
Hide file tree
Showing 64 changed files with 1,087 additions and 583 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
version: v1.60
args: --timeout 3m --verbose
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ lightnode/docker/build-info.txt
lightnode/docker/args.sh

.idea
.env
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ We welcome all contributions! There are many ways to contribute to the project,
## Contact

- [Open an Issue](https://github.com/Layr-Labs/eigenda/issues/new/choose)
- [EigenLayer/EigenDA forum](https://forum.eigenlayer.xyz/c/eigenda/9)
- [EigenLayer/EigenDA forum](https://forum.eigenlayer.xyz)
- [Email](mailto:eigenda-support@eigenlabs.org)
- [Follow us on X](https://x.com/eigen_da)
5 changes: 3 additions & 2 deletions api/clients/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ func (c *EigenDAClientConfig) CheckAndSetDefaults() error {
if c.ResponseTimeout == 0 {
c.ResponseTimeout = 30 * time.Second
}
if len(c.SignerPrivateKeyHex) != 64 {
return fmt.Errorf("EigenDAClientConfig.SignerPrivateKeyHex should be 64 hex characters long, should not have 0x prefix")
if len(c.SignerPrivateKeyHex) > 0 && len(c.SignerPrivateKeyHex) != 64 {
return fmt.Errorf("a valid length SignerPrivateKeyHex needs to have 64 bytes")
}

if len(c.RPC) == 0 {
return fmt.Errorf("EigenDAClientConfig.RPC not set")
}
Expand Down
42 changes: 26 additions & 16 deletions api/clients/disperser_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,32 @@ func (c *disperserClient) DisperseBlob(ctx context.Context, data []byte, quorums
}

func (c *disperserClient) DisperseBlobAuthenticated(ctx context.Context, data []byte, quorums []uint8) (*disperser.BlobStatus, []byte, error) {
if c.signer == nil {
return nil, nil, fmt.Errorf("uninitialized signer for authenticated dispersal")
}

// first check if signer is valid
accountId, err := c.signer.GetAccountID()
if err != nil {
return nil, nil, fmt.Errorf("please configure signer key if you want to use authenticated endpoint %w", err)
}

quorumNumbers := make([]uint32, len(quorums))
for i, q := range quorums {
quorumNumbers[i] = uint32(q)
}

// check every 32 bytes of data are within the valid range for a bn254 field element
_, err = rs.ToFrArray(data)
if err != nil {
return nil, nil, fmt.Errorf("encountered an error to convert a 32-bytes into a valid field element, please use the correct format where every 32bytes(big-endian) is less than 21888242871839275222246405745257275088548364400416034343698204186575808495617, %w", err)
}

request := &disperser_rpc.DisperseBlobRequest{
Data: data,
CustomQuorumNumbers: quorumNumbers,
AccountId: accountId,
}

addr := fmt.Sprintf("%v:%v", c.config.Hostname, c.config.Port)

Expand All @@ -128,22 +154,6 @@ func (c *disperserClient) DisperseBlobAuthenticated(ctx context.Context, data []
return nil, nil, fmt.Errorf("error while calling DisperseBlobAuthenticated: %w", err)
}

quorumNumbers := make([]uint32, len(quorums))
for i, q := range quorums {
quorumNumbers[i] = uint32(q)
}

// check every 32 bytes of data are within the valid range for a bn254 field element
_, err = rs.ToFrArray(data)
if err != nil {
return nil, nil, fmt.Errorf("encountered an error to convert a 32-bytes into a valid field element, please use the correct format where every 32bytes(big-endian) is less than 21888242871839275222246405745257275088548364400416034343698204186575808495617, %w", err)
}
request := &disperser_rpc.DisperseBlobRequest{
Data: data,
CustomQuorumNumbers: quorumNumbers,
AccountId: c.signer.GetAccountID(),
}

// Send the initial request
err = stream.Send(&disperser_rpc.AuthenticatedRequest{Payload: &disperser_rpc.AuthenticatedRequest_DisperseRequest{
DisperseRequest: request,
Expand Down
11 changes: 10 additions & 1 deletion api/clients/eigenda_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/Layr-Labs/eigenda/api/clients/codecs"
grpcdisperser "github.com/Layr-Labs/eigenda/api/grpc/disperser"
"github.com/Layr-Labs/eigenda/core"
"github.com/Layr-Labs/eigenda/core/auth"
"github.com/Layr-Labs/eigenda/disperser"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -41,7 +42,15 @@ func NewEigenDAClient(log log.Logger, config EigenDAClientConfig) (*EigenDAClien
return nil, fmt.Errorf("failed to parse EigenDA RPC: %w", err)
}

signer := auth.NewLocalBlobRequestSigner(config.SignerPrivateKeyHex)
var signer core.BlobRequestSigner
if len(config.SignerPrivateKeyHex) == 64 {
signer = auth.NewLocalBlobRequestSigner(config.SignerPrivateKeyHex)
} else if len(config.SignerPrivateKeyHex) == 0 {
signer = auth.NewLocalNoopSigner()
} else {
return nil, fmt.Errorf("invalid length for signer private key")
}

llConfig := NewConfig(host, port, config.ResponseTimeout, !config.DisableTLS)
llClient := NewDisperserClient(llConfig, signer)

Expand Down
12 changes: 12 additions & 0 deletions api/clients/eigenda_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
clientsmock "github.com/Layr-Labs/eigenda/api/clients/mock"
"github.com/Layr-Labs/eigenda/api/grpc/common"
grpcdisperser "github.com/Layr-Labs/eigenda/api/grpc/disperser"
"github.com/Layr-Labs/eigenda/core/auth"
"github.com/Layr-Labs/eigenda/disperser"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -505,3 +506,14 @@ func TestPutBlobTotalTimeout(t *testing.T) {
require.Error(t, err)
require.Nil(t, blobInfo)
}

func TestPutBlobNoopSigner(t *testing.T) {
config := clients.NewConfig("nohost", "noport", time.Second, false)
disperserClient := clients.NewDisperserClient(config, auth.NewLocalNoopSigner())

test := []byte("test")
test[0] = 0x00 // make sure the first byte of the requst is always 0
quorums := []uint8{0}
_, _, err := disperserClient.DisperseBlobAuthenticated(context.Background(), test, quorums)
assert.EqualError(t, err, "please configure signer key if you want to use authenticated endpoint noop signer cannot get accountID")
}
5 changes: 3 additions & 2 deletions api/clients/mock/retrieval_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ func (c *MockRetrievalClient) RetrieveBlobChunks(
batchRoot [32]byte,
quorumID core.QuorumID) (*clients.BlobChunks, error) {

return nil, nil
args := c.Called(batchHeaderHash, blobIndex, referenceBlockNumber, batchRoot, quorumID)
return args.Get(0).(*clients.BlobChunks), args.Error(1)
}

func (c *MockRetrievalClient) CombineChunks(chunks *clients.BlobChunks) ([]byte, error) {
args := c.Called()
args := c.Called(chunks)

result := args.Get(0)
return result.([]byte), args.Error(1)
Expand Down
3 changes: 1 addition & 2 deletions api/clients/retrieval_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"errors"
"fmt"

"github.com/Layr-Labs/eigenda/core"
"github.com/Layr-Labs/eigenda/encoding"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/wealdtech/go-merkletree/v2"

"github.com/gammazero/workerpool"
"github.com/wealdtech/go-merkletree/v2"
"github.com/wealdtech/go-merkletree/v2/keccak256"
)

Expand Down
2 changes: 1 addition & 1 deletion api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// before return to users from APIs.

func NewGRPCError(code codes.Code, msg string) error {
return status.Errorf(code, msg)
return status.Error(code, msg)
}

// HTTP Mapping: 400 Bad Request
Expand Down
18 changes: 18 additions & 0 deletions common/geth/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

var (
rpcUrlFlagName = "chain.rpc"
rpcFallbackUrlFlagName = "chain.rpc_fallback"
privateKeyFlagName = "chain.private-key"
numConfirmationsFlagName = "chain.num-confirmations"
numRetriesFlagName = "chain.num-retries"
Expand All @@ -27,6 +28,13 @@ func EthClientFlags(envPrefix string) []cli.Flag {
Required: true,
EnvVar: common.PrefixEnvVar(envPrefix, "CHAIN_RPC"),
},
cli.StringFlag{
Name: rpcFallbackUrlFlagName,
Usage: "Fallback chain rpc for Disperser/Batcher/Dataapi",
Required: false,
Value: "",
EnvVar: common.PrefixEnvVar(envPrefix, "CHAIN_RPC_FALLBACK"),
},
cli.StringFlag{
Name: privateKeyFlagName,
Usage: "Ethereum private key for disperser",
Expand Down Expand Up @@ -57,6 +65,11 @@ func ReadEthClientConfig(ctx *cli.Context) EthClientConfig {
cfg.NumConfirmations = ctx.GlobalInt(numConfirmationsFlagName)
cfg.NumRetries = ctx.GlobalInt(numRetriesFlagName)

fallbackRPCURL := ctx.GlobalString(rpcFallbackUrlFlagName)
if len(fallbackRPCURL) > 0 {
cfg.RPCURLs = append(cfg.RPCURLs, []string{fallbackRPCURL}...)
}

return cfg
}

Expand All @@ -68,5 +81,10 @@ func ReadEthClientConfigRPCOnly(ctx *cli.Context) EthClientConfig {
cfg.NumConfirmations = ctx.GlobalInt(numConfirmationsFlagName)
cfg.NumRetries = ctx.GlobalInt(numRetriesFlagName)

fallbackRPCURL := ctx.GlobalString(rpcFallbackUrlFlagName)
if len(fallbackRPCURL) > 0 {
cfg.RPCURLs = append(cfg.RPCURLs, []string{fallbackRPCURL}...)
}

return cfg
}
6 changes: 6 additions & 0 deletions common/geth/multihoming_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ var _ dacommon.EthClient = (*MultiHomingClient)(nil)
func NewMultiHomingClient(config EthClientConfig, senderAddress gethcommon.Address, logger logging.Logger) (*MultiHomingClient, error) {
rpcUrls := config.RPCURLs

if len(config.RPCURLs) > 1 {
logger.Info("Fallback chain RPC enabled")
} else {
logger.Info("Fallback chain RPC not available")
}

FailoverController, err := NewFailoverController(logger, rpcUrls)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion core/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ type BlobRequestAuthenticator interface {

type BlobRequestSigner interface {
SignBlobRequest(header BlobAuthHeader) ([]byte, error)
GetAccountID() string
GetAccountID() (string, error)
}
25 changes: 23 additions & 2 deletions core/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ func TestAuthentication(t *testing.T) {
privateKeyHex := "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
signer := auth.NewLocalBlobRequestSigner(privateKeyHex)

accountId, err := signer.GetAccountID()
assert.NoError(t, err)

testHeader := core.BlobAuthHeader{
BlobCommitments: encoding.BlobCommitments{},
AccountID: signer.GetAccountID(),
AccountID: accountId,
Nonce: rand.Uint32(),
AuthenticationData: []byte{},
}
Expand All @@ -46,9 +49,12 @@ func TestAuthenticationFail(t *testing.T) {
privateKeyHex := "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
signer := auth.NewLocalBlobRequestSigner(privateKeyHex)

accountId, err := signer.GetAccountID()
assert.NoError(t, err)

testHeader := core.BlobAuthHeader{
BlobCommitments: encoding.BlobCommitments{},
AccountID: signer.GetAccountID(),
AccountID: accountId,
Nonce: rand.Uint32(),
AuthenticationData: []byte{},
}
Expand All @@ -66,3 +72,18 @@ func TestAuthenticationFail(t *testing.T) {
assert.Error(t, err)

}

func TestNoopSignerFail(t *testing.T) {
signer := auth.NewLocalNoopSigner()
accountId, err := signer.GetAccountID()
assert.EqualError(t, err, "noop signer cannot get accountID")

testHeader := core.BlobAuthHeader{
BlobCommitments: encoding.BlobCommitments{},
AccountID: accountId,
Nonce: rand.Uint32(),
AuthenticationData: []byte{},
}
_, err = signer.SignBlobRequest(testHeader)
assert.EqualError(t, err, "noop signer cannot sign blob request")
}
18 changes: 16 additions & 2 deletions core/auth/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,23 @@ func (s *LocalBlobRequestSigner) SignBlobRequest(header core.BlobAuthHeader) ([]
return sig, nil
}

func (s *LocalBlobRequestSigner) GetAccountID() string {
func (s *LocalBlobRequestSigner) GetAccountID() (string, error) {

publicKeyBytes := crypto.FromECDSAPub(&s.PrivateKey.PublicKey)
return hexutil.Encode(publicKeyBytes)
return hexutil.Encode(publicKeyBytes), nil

}

type LocalNoopSigner struct{}

func NewLocalNoopSigner() *LocalNoopSigner {
return &LocalNoopSigner{}
}

func (s *LocalNoopSigner) SignBlobRequest(header core.BlobAuthHeader) ([]byte, error) {
return nil, fmt.Errorf("noop signer cannot sign blob request")
}

func (s *LocalNoopSigner) GetAccountID() (string, error) {
return "", fmt.Errorf("noop signer cannot get accountID")
}
7 changes: 5 additions & 2 deletions disperser/apiserver/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,15 @@ func simulateClient(t *testing.T, signer core.BlobRequestSigner, origin string,
stream.Close()
}()

err := stream.SendFromClient(&pb.AuthenticatedRequest{
accountId, err := signer.GetAccountID()
assert.NoError(t, err)

err = stream.SendFromClient(&pb.AuthenticatedRequest{
Payload: &pb.AuthenticatedRequest_DisperseRequest{
DisperseRequest: &pb.DisperseBlobRequest{
Data: data,
CustomQuorumNumbers: quorums,
AccountId: signer.GetAccountID(),
AccountId: accountId,
},
},
})
Expand Down
Loading

0 comments on commit 54af37a

Please sign in to comment.