diff --git a/e2e/server_test.go b/e2e/server_test.go index ae4c3f51..898dcfdd 100644 --- a/e2e/server_test.go +++ b/e2e/server_test.go @@ -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" ) @@ -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 + } +} \ No newline at end of file diff --git a/resources/g1.point b/resources/g1.point index 483074e4..4922cd06 100644 Binary files a/resources/g1.point and b/resources/g1.point differ diff --git a/resources/g2.point.powerOf2 b/resources/g2.point.powerOf2 index 58e349b6..d10c8844 100644 Binary files a/resources/g2.point.powerOf2 and b/resources/g2.point.powerOf2 differ diff --git a/server/config.go b/server/config.go index ed5307c0..6df7c2a3 100644 --- a/server/config.go +++ b/server/config.go @@ -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)), } @@ -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 } diff --git a/store/eigenda.go b/store/eigenda.go index 65eb8eaf..c58447b4 100644 --- a/store/eigenda.go +++ b/store/eigenda.go @@ -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 { @@ -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 diff --git a/verify/verifier.go b/verify/verifier.go index d02753f7..bd310a67 100644 --- a/verify/verifier.go +++ b/verify/verifier.go @@ -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