@@ -39,7 +39,10 @@ type RelayPayloadRetrieverTester struct {
39
39
RelayPayloadRetriever * RelayPayloadRetriever
40
40
MockRelayClient * clientsmock.MockRelayClient
41
41
G1Srs []bn254.G1Affine
42
- PayloadPolynomialForm codecs.PolynomialForm
42
+ }
43
+
44
+ func (t * RelayPayloadRetrieverTester ) PayloadPolynomialForm () codecs.PolynomialForm {
45
+ return t .RelayPayloadRetriever .config .PayloadPolynomialForm
43
46
}
44
47
45
48
// buildRelayPayloadRetrieverTester sets up a client with mocks necessary for testing
@@ -76,7 +79,6 @@ func buildRelayPayloadRetrieverTester(t *testing.T) RelayPayloadRetrieverTester
76
79
RelayPayloadRetriever : client ,
77
80
MockRelayClient : & mockRelayClient ,
78
81
G1Srs : g1Srs ,
79
- PayloadPolynomialForm : clientConfig .PayloadPolynomialForm ,
80
82
}
81
83
}
82
84
@@ -88,11 +90,22 @@ func buildBlobAndCert(
88
90
) (core.BlobKey , []byte , * coretypes.EigenDACertV3 ) {
89
91
90
92
payloadBytes := tester .Random .Bytes (tester .Random .Intn (maxPayloadBytes ))
91
- blob , err := coretypes .NewPayload (payloadBytes ).ToBlob (tester .PayloadPolynomialForm )
93
+ blob , err := coretypes .NewPayload (payloadBytes ).ToBlob (tester .PayloadPolynomialForm () )
92
94
require .NoError (t , err )
93
-
94
95
blobBytes := blob .Serialize ()
95
96
require .NotNil (t , blobBytes )
97
+ blobKey , cert := buildCertFromBlobBytes (t , blobBytes , relayKeys )
98
+ return blobKey , blobBytes , cert
99
+
100
+ }
101
+
102
+ // buildCert builds a blob key, blob bytes, and valid certificate from the given blob and relay keys.
103
+ // It is used to generate a valid cert from a wrongly encoded blob, to test for decoding errors.
104
+ func buildCertFromBlobBytes (
105
+ t * testing.T ,
106
+ blobBytes []byte ,
107
+ relayKeys []core.RelayKey ,
108
+ ) (core.BlobKey , * coretypes.EigenDACertV3 ) {
96
109
97
110
kzgConfig := & kzg.KzgConfig {
98
111
G1Path : "../../../../inabox/resources/kzg/g1.point" ,
@@ -141,7 +154,7 @@ func buildBlobAndCert(
141
154
blobKey , err := eigenDACert .ComputeBlobKey ()
142
155
require .NoError (t , err )
143
156
144
- return * blobKey , blobBytes , eigenDACert
157
+ return * blobKey , eigenDACert
145
158
}
146
159
147
160
// TestGetPayloadSuccess tests that a blob is received without error in the happy case
@@ -446,3 +459,38 @@ func TestErrorClose(t *testing.T) {
446
459
447
460
tester .MockRelayClient .AssertExpectations (t )
448
461
}
462
+
463
+ // TestCommitmentVerifiesButBlobToPayloadFails tests the case where commitment verification succeeds
464
+ // but conversion from blob to payload fails. This is a critical edge case that should not be possible
465
+ // with valid data, but could indicate malicious dispersed data.
466
+ func TestCommitmentVerifiesButBlobToPayloadFails (t * testing.T ) {
467
+ tester := buildRelayPayloadRetrieverTester (t )
468
+ // We keep the blob in coeff form so that we can manipulate it directly (otherwise it gets IFFT'd)
469
+ tester .RelayPayloadRetriever .config .PayloadPolynomialForm = codecs .PolynomialFormCoeff
470
+ relayKeys := make ([]core.RelayKey , 1 )
471
+ relayKeys [0 ] = tester .Random .Uint32 ()
472
+
473
+ payloadBytes := tester .Random .Bytes (tester .Random .Intn (maxPayloadBytes ))
474
+ blob , err := coretypes .NewPayload (payloadBytes ).ToBlob (tester .PayloadPolynomialForm ())
475
+ require .NoError (t , err )
476
+ blobBytes := blob .Serialize ()
477
+ require .NotNil (t , blobBytes )
478
+ blobBytes [1 ] = 0xFF // Invalid encoding version - this will cause decode to fail
479
+
480
+ blobKey , blobCert := buildCertFromBlobBytes (t , blobBytes , relayKeys )
481
+
482
+ // Mock the relay to return our incorrectly encoded blob
483
+ tester .MockRelayClient .On ("GetBlob" , mock .Anything , relayKeys [0 ], blobKey ).Return (blobBytes , nil ).Once ()
484
+
485
+ // Try to get the payload - this should fail during blob to payload conversion
486
+ payload , err := tester .RelayPayloadRetriever .GetPayload (context .Background (), blobCert )
487
+ require .Nil (t , payload )
488
+ require .Error (t , err )
489
+
490
+ // Verify it's specifically a DerivationError with status code 4 (blob decoding failed)
491
+ derivationErr := coretypes.DerivationError {}
492
+ require .ErrorAs (t , err , & derivationErr )
493
+ require .Equal (t , coretypes .ErrBlobDecodingFailedDerivationError .StatusCode , derivationErr .StatusCode )
494
+
495
+ tester .MockRelayClient .AssertExpectations (t )
496
+ }
0 commit comments