|
9 | 9 | "github.com/Layr-Labs/eigenda/encoding"
|
10 | 10 | "github.com/Layr-Labs/eigenda/encoding/kzg"
|
11 | 11 | "github.com/Layr-Labs/eigenda/encoding/kzg/prover"
|
| 12 | + "github.com/consensys/gnark-crypto/ecc/bn254" |
12 | 13 | )
|
13 | 14 |
|
14 | 15 | func TestNewSRSTable_PreComputeWorks(t *testing.T) {
|
@@ -43,3 +44,41 @@ func TestNewSRSTable_PreComputeWorks(t *testing.T) {
|
43 | 44 | // Result of non precomputed GetSubTables should equal precomputed GetSubTables
|
44 | 45 | assert.Equal(t, fftPoints1, fftPoints2)
|
45 | 46 | }
|
| 47 | + |
| 48 | +// This test reproduces the scenario where SRS_LOAD=2097152 and computing a subtable |
| 49 | +// with the parameters (DimE=4, CosetSize=2097152) would cause a panic. |
| 50 | +// The issue: m = numChunks*chunkLen - 1 = 4*2097152 - 1 = 8388607 |
| 51 | +// When j=0, k starts at m - cosetSize = 8388607 - 2097152 = 6291455 |
| 52 | +// Since 6291455 >= 2097152 (the length of our SRS), we get: |
| 53 | +// panic: runtime error: index out of range [6291455] with length 2097152 |
| 54 | +func TestSRSTable_InsufficientSRSPoints_NoPanic(t *testing.T) { |
| 55 | + // Create a limited SRS with only 2097152 points |
| 56 | + limitedSRSSize := uint64(2097152) |
| 57 | + limitedSRS := make([]bn254.G1Affine, limitedSRSSize) |
| 58 | + |
| 59 | + // Initialize with some dummy points (doesn't matter what they are for this test) |
| 60 | + var generator bn254.G1Affine |
| 61 | + _, err := generator.X.SetString("1") |
| 62 | + require.NoError(t, err) |
| 63 | + _, err = generator.Y.SetString("2") |
| 64 | + require.NoError(t, err) |
| 65 | + for i := range limitedSRS { |
| 66 | + limitedSRS[i] = generator |
| 67 | + } |
| 68 | + |
| 69 | + // Create SRSTable with limited SRS points |
| 70 | + tempDir := t.TempDir() |
| 71 | + srsTable, err := prover.NewSRSTable(tempDir, limitedSRS, 1) |
| 72 | + require.NoError(t, err) |
| 73 | + |
| 74 | + // Try to create subtables with the following parameters |
| 75 | + numChunks := uint64(4) |
| 76 | + chunkLen := uint64(2097152) |
| 77 | + |
| 78 | + // This should return an error instead of panicking |
| 79 | + fftPoints, err := srsTable.GetSubTables(numChunks, chunkLen) |
| 80 | + |
| 81 | + assert.Error(t, err) |
| 82 | + assert.Nil(t, fftPoints) |
| 83 | + assert.Contains(t, err.Error(), "insufficient SRS points") |
| 84 | +} |
0 commit comments