Skip to content

Commit

Permalink
Merge pull request #22 from Layr-Labs/epociask--feat-data-domain-filt…
Browse files Browse the repository at this point in the history
…ering

Add data domain option and max blob size config setting
  • Loading branch information
teddyknox authored Jun 6, 2024
2 parents c26c709 + 506a4e4 commit e322532
Show file tree
Hide file tree
Showing 19 changed files with 590 additions and 308 deletions.
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Additional CLI args are provided for targeting an EigenDA network backend:
* `--eigenda-g1-path`: Directory path to g1.point file
* `--eigenda-g2-power-of-tau`: Directory path to g2.point.powerOf2 file
* `--eigenda-cache-path`: Directory path to dump cached SRS tables
* `--eigenda-max-blob-length`: The maximum blob length that this EigenDA sidecar proxy should expect to be written or read from EigenDA. This configuration setting is used to determine how many SRS points should be loaded into memory for generating/verifying KZG commitments returned by the EigenDA disperser. Valid byte units are either base-2 or base-10 byte amounts (not bits), e.g. `30 MiB`, `4Kb`, `30MB`. The maximum blob size is a little more than `1GB`.

### In-Memory Storage

Expand Down Expand Up @@ -61,17 +62,7 @@ An `EigenDACommitment` layer type has been added that supports verification agai
```

The `raw commitment` for EigenDA is encoding the following certificate and kzg fields:

```go
type Cert struct {
BatchHeaderHash []byte
BlobIndex uint32
ReferenceBlockNumber uint32
QuorumIDs []uint32
BlobCommitment *common.G1Commitment
}
```
The `raw commitment` for EigenDA is encoding certificate and kzg fields.

**NOTE:** Commitments are cryptographically verified against the data fetched from EigenDA for all `/get` calls. The server will respond with status `500` in the event where EigenDA were to lie and provide falsified data thats irrespective of the client provided commitment. This feature isn't flag guarded and is part of standard operation.

Expand Down
22 changes: 14 additions & 8 deletions cmd/server/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,34 @@ import (
"github.com/ethereum-optimism/optimism/op-service/opio"
)

func LoadStore(cfg CLIConfig, ctx context.Context, log log.Logger) (proxy.Store, error) {
if cfg.MemStoreCfg.Enabled {
log.Info("Using memstore backend")
return store.NewMemStore(ctx, &cfg.MemStoreCfg, log)
}

func LoadStore(cfg CLIConfig, ctx context.Context, log log.Logger) (store.Store, error) {
log.Info("Using eigenda backend")
daCfg := cfg.EigenDAConfig

v, err := verify.NewVerifier(daCfg.KzgConfig())
verifier, err := verify.NewVerifier(daCfg.KzgConfig())
if err != nil {
return nil, err
}

maxBlobLength, err := daCfg.GetMaxBlobLength()
if err != nil {
return nil, err
}

if cfg.MemStoreCfg.Enabled {
log.Info("Using memstore backend")
return store.NewMemStore(ctx, &cfg.MemStoreCfg, verifier, log, maxBlobLength)
}

client, err := clients.NewEigenDAClient(log, daCfg.ClientConfig)
if err != nil {
return nil, err
}
return store.NewEigenDAStore(
ctx,
client,
v,
verifier,
maxBlobLength,
)
}

Expand Down
1 change: 0 additions & 1 deletion cmd/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func ReadCLIConfig(ctx *cli.Context) CLIConfig {
}

func (c CLIConfig) Check() error {

err := c.EigenDAConfig.Check()
if err != nil {
return err
Expand Down
80 changes: 80 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
package common

import (
"fmt"
"strconv"
"strings"
)

var (
ErrInvalidDomainType = fmt.Errorf("invalid domain type")
)

// DomainType is a enumeration type for the different data domains for which a
// blob can exist between
type DomainType uint8

const (
BinaryDomain DomainType = iota
PolyDomain
UnknownDomain
)

func StrToDomainType(s string) DomainType {
switch s {
case "binary":
return BinaryDomain
case "polynomial":
return PolyDomain
default:
return UnknownDomain
}
}

// Helper utility functions //

func EqualSlices[P comparable](s1, s2 []P) bool {
if len(s1) != len(s2) {
return false
Expand All @@ -13,3 +46,50 @@ func EqualSlices[P comparable](s1, s2 []P) bool {

return true
}

func ParseBytesAmount(s string) (uint64, error) {
s = strings.TrimSpace(s)

// Extract numeric part and unit
numStr := s
unit := ""
for i, r := range s {
if !('0' <= r && r <= '9' || r == '.') {
numStr = s[:i]
unit = s[i:]
break
}
}

// Convert numeric part to float64
num, err := strconv.ParseFloat(numStr, 64)
if err != nil {
return 0, fmt.Errorf("invalid numeric value: %v", err)
}

unit = strings.ToLower(strings.TrimSpace(unit))

// Convert to uint64 based on the unit (case-insensitive)
switch unit {
case "b", "":
return uint64(num), nil
case "kib":
return uint64(num * 1024), nil
case "kb":
return uint64(num * 1000), nil // Decimal kilobyte
case "mib":
return uint64(num * 1024 * 1024), nil
case "mb":
return uint64(num * 1000 * 1000), nil // Decimal megabyte
case "gib":
return uint64(num * 1024 * 1024 * 1024), nil
case "gb":
return uint64(num * 1000 * 1000 * 1000), nil // Decimal gigabyte
case "tib":
return uint64(num * 1024 * 1024 * 1024 * 1024), nil
case "tb":
return uint64(num * 1000 * 1000 * 1000 * 1000), nil // Decimal terabyte
default:
return 0, fmt.Errorf("unsupported unit: %s", unit)
}
}
54 changes: 54 additions & 0 deletions common/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package common_test

import (
"fmt"
"testing"

"github.com/Layr-Labs/eigenda-proxy/common"
)

func TestParseByteAmount(t *testing.T) {
testCases := []struct {
input string
expected uint64
wantErr bool
}{
{"10 B", 10, false},
{"15 b", 15, false}, // Case-insensitive
{"1 KiB", 1024, false},
{"2 kib", 2048, false}, // Case-insensitive
{"5 KB", 5000, false}, // Decimal kilobyte
{"10 kb", 10000, false}, // Decimal kilobyte (case-insensitive)
{"1 MiB", 1024 * 1024, false},
{"3 mib", 3 * 1024 * 1024, false},
{"10 MB", 10 * 1000 * 1000, false},
{"100 mb", 100 * 1000 * 1000, false},
{"1 GiB", 1024 * 1024 * 1024, false},
{"10 gib", 10 * 1024 * 1024 * 1024, false},
{"10 GB", 10 * 1000 * 1000 * 1000, false},
{"100 gb", 100 * 1000 * 1000 * 1000, false},
{"1 TiB", 1024 * 1024 * 1024 * 1024, false},
{"10 tib", 10 * 1024 * 1024 * 1024 * 1024, false},
{"1 TB", 1000 * 1000 * 1000 * 1000, false},
{"100 tb", 100 * 1000 * 1000 * 1000 * 1000, false},

{" 5 B ", 5, false}, // Whitespace handling
{"10", 10, false}, // Default to bytes if no unit

{"10 XB", 0, true}, // Invalid unit
{"abc", 0, true}, // Non-numeric value
{"1.5 KiB", 1536, false},
}

for _, tc := range testCases {
t.Run(fmt.Sprintf("Input: %s", tc.input), func(t *testing.T) {
got, err := common.ParseBytesAmount(tc.input)
if (err != nil) != tc.wantErr {
t.Errorf("wantErr: %v, got error: %v", tc.wantErr, err)
}
if got != tc.expected {
t.Errorf("got: %d, expected: %d", got, tc.expected)
}
})
}
}
27 changes: 0 additions & 27 deletions eigenda/cert.go

This file was deleted.

61 changes: 0 additions & 61 deletions eigenda/cert_test.go

This file was deleted.

9 changes: 9 additions & 0 deletions eigenda/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"

op_plasma "github.com/ethereum-optimism/optimism/op-plasma"
"github.com/ethereum/go-ethereum/common/hexutil"
)

// ErrCommitmentLength is returned when the commitment length is invalid.
Expand Down Expand Up @@ -35,6 +36,14 @@ func (c Commitment) Encode() []byte {
return append([]byte{byte(op_plasma.GenericCommitmentType), byte(EigenDA), byte(EigenV0)}, c...)
}

func StringToCommit(key string) (Commitment, error) {
comm, err := hexutil.Decode(key)
if err != nil {
return nil, err
}
return DecodeCommitment(comm)
}

// DecodeCommitment verifies and decodes an EigenDACommit from raw encoded bytes.
func DecodeCommitment(commitment []byte) (Commitment, error) {
if len(commitment) <= 3 {
Expand Down
Loading

0 comments on commit e322532

Please sign in to comment.