Skip to content

Commit

Permalink
fix: SRS ingestion and cfg loading bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
epociask committed Jul 19, 2024
1 parent 5c215b4 commit d37acd2
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 12 deletions.
108 changes: 107 additions & 1 deletion e2e/server_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package e2e_test

import (
"fmt"
"sync"
"testing"
"time"

"github.com/Layr-Labs/eigenda-proxy/client"
"github.com/Layr-Labs/eigenda-proxy/e2e"
"github.com/Layr-Labs/eigenda-proxy/utils"
op_plasma "github.com/ethereum-optimism/optimism/op-plasma"

"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -88,3 +91,106 @@ func TestProxyClient(t *testing.T) {
require.NoError(t, err)
require.Equal(t, testPreimage, preimage)
}

func TestProxyClientWithLargeBlob(t *testing.T) {
if !runIntegrationTests && !runTestnetIntegrationTests {
t.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
}

t.Parallel()

ts, kill := e2e.CreateTestSuite(t, useMemory(), false)
defer kill()

cfg := &client.Config{
URL: ts.Address(),
}
daClient := client.New(cfg)
// 2MB blob
testPreimage := []byte(e2e.RandString(2000000))

t.Log("Setting input data on proxy server...")
blobInfo, err := daClient.SetData(ts.Ctx, testPreimage)
require.NoError(t, err)

t.Log("Getting input data from proxy server...")
preimage, err := daClient.GetData(ts.Ctx, blobInfo)
require.NoError(t, err)
require.Equal(t, testPreimage, preimage)
}

func TestProxyClientMultiSameContentBlobsSameBatch(t *testing.T) {
t.Skip("Skipping test until fix is applied to holesky")


t.Parallel()

ts, kill := e2e.CreateTestSuite(t, useMemory(), false)
defer kill()

cfg := &client.Config{
URL: ts.Address(),
}

errChan := make(chan error, 10)
var wg sync.WaitGroup

// disperse 10 blobs with the same content in the same batch
for i := 0; i < 4; i ++ {
wg.Add(1)
go func(){
defer wg.Done()
daClient := client.New(cfg)
testPreimage := []byte("hellooooooooooo world!")

t.Log("Setting input data on proxy server...")
blobInfo, err := daClient.SetData(ts.Ctx, testPreimage)
if err != nil {
errChan <- err
return
}

t.Log("Getting input data from proxy server...")
preimage, err := daClient.GetData(ts.Ctx, blobInfo)
if err != nil {
errChan <- err
return
}

if !utils.EqualSlices(preimage, testPreimage) {
errChan <- fmt.Errorf("expected preimage %s, got %s", testPreimage, preimage)
return
}
}()
}

timedOut := waitTimeout(&wg, 10*time.Minute)
if timedOut {
t.Fatal("timed out waiting for parallel tests to complete")
}

if len(errChan) > 0 {
// iterate over channel and log errors
for i := 0; i < len(errChan); i++ {
err := <-errChan
t.Log(err.Error())
t.Fail()
}
}
}

// waitTimeout waits for the waitgroup for the specified max timeout.
// Returns true if waiting timed out.
func waitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
c := make(chan struct{})
go func() {
defer close(c)
wg.Wait()
}()
select {
case <-c:
return false
case <-time.After(timeout):
return true
}
}
Binary file modified resources/g1.point
Binary file not shown.
Binary file modified resources/g2.point.powerOf2
Binary file not shown.
12 changes: 8 additions & 4 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,12 @@ func (c *Config) VerificationCfg() *verify.Config {
panic(fmt.Errorf("Check() was not called on config object, err is not nil: %w", err))
}

numPointsNeeded := uint64(math.Ceil(float64(numBytes) / BytesPerSymbol))

kzgCfg := &kzg.KzgConfig{
G1Path: c.G1Path,
G2PowerOf2Path: c.G2PowerOfTauPath,
CacheDir: c.CacheDir,
SRSOrder: numPointsNeeded,
SRSNumberToLoad: numPointsNeeded,
SRSOrder: 268435456, // 2 ^ 32
SRSNumberToLoad: numBytes / 32, // # of fp.Elements
NumWorker: uint64(runtime.GOMAXPROCS(0)),
}

Expand Down Expand Up @@ -162,6 +160,12 @@ func ReadConfig(ctx *cli.Context) Config {
MemstoreBlobExpiration: ctx.Duration(MemstoreExpirationFlagName),
}
cfg.ClientConfig.WaitForFinalization = (cfg.EthConfirmationDepth < 0)


if cfg.EthConfirmationDepth >= 0 && (cfg.SvcManagerAddr == "" || cfg.EthRPC == "") {
panic("Eth Confirmation Depth is set for certificate verification, but Eth RPC or SvcManagerAddr is not set")
}

return cfg
}

Expand Down
9 changes: 5 additions & 4 deletions store/eigenda.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ func (e EigenDAStore) Get(ctx context.Context, key []byte) ([]byte, error) {

// Put disperses a blob for some pre-image and returns the associated RLP encoded certificate commit.
func (e EigenDAStore) Put(ctx context.Context, value []byte) (comm []byte, err error) {
if uint64(len(value)) > e.cfg.MaxBlobSizeBytes {
return nil, fmt.Errorf("blob is larger than max blob size: blob length %d, max blob size %d", len(value), e.cfg.MaxBlobSizeBytes)
}

dispersalStart := time.Now()
blobInfo, err := e.client.PutBlob(ctx, value)
if err != nil {
Expand All @@ -83,6 +79,11 @@ func (e EigenDAStore) Put(ctx context.Context, value []byte) (comm []byte, err e
if err != nil {
return nil, fmt.Errorf("EigenDA client failed to re-encode blob: %w", err)
}
if uint64(len(encodedBlob)) > e.cfg.MaxBlobSizeBytes {
return nil, fmt.Errorf("encoded blob is larger than max blob size: blob length %d, max blob size %d", len(value), e.cfg.MaxBlobSizeBytes)
}


err = e.verifier.VerifyCommitment(cert.BlobHeader.Commitment, encodedBlob)
if err != nil {
return nil, err
Expand Down
4 changes: 1 addition & 3 deletions verify/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ func (v *Verifier) VerifyCert(cert *Certificate) error {
}

func (v *Verifier) Commit(blob []byte) (*bn254.G1Affine, error) {
// ChunkLength and TotalChunks aren't relevant for computing data
// commitment which is why they're currently set arbitrarily
encoder, err := v.kzgProver.GetKzgEncoder(
encoding.ParamsFromSysPar(420, 69, uint64(len(blob))),
encoding.ParamsFromSysPar(1, 1, uint64(len(blob))),
)
if err != nil {
return nil, err
Expand Down

0 comments on commit d37acd2

Please sign in to comment.