Skip to content
This repository was archived by the owner on May 11, 2024. It is now read-only.

Commit 0a29936

Browse files
authored
fix(driver): fix a blob decoding issue (#629)
1 parent df0e897 commit 0a29936

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

driver/chain_syncer/calldata/syncer.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,12 @@ func (s *Syncer) onBlockProposed(
236236
}
237237
txListBytes, err := txListDecoder.Fetch(ctx, tx, &event.Meta)
238238
if err != nil {
239-
return fmt.Errorf("failed to decode tx list: %w", err)
239+
if errors.Is(err, rpc.ErrBlobInvalid) {
240+
log.Info("Invalid blob detected", "blockID", event.BlockId)
241+
txListBytes = []byte{}
242+
} else {
243+
return fmt.Errorf("failed to decode tx list: %w", err)
244+
}
240245
}
241246

242247
l1Origin := &rawdb.L1Origin{

pkg/rpc/tx_blob.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var (
1717
)
1818

1919
var (
20-
errBlobInvalid = errors.New("invalid blob encoding")
20+
ErrBlobInvalid = errors.New("invalid blob encoding")
2121
)
2222

2323
// TransactBlobTx creates, signs and then sends blob transactions.
@@ -148,10 +148,13 @@ func encode(origin []byte) []byte {
148148
return res
149149
}
150150

151-
func decode(data []byte) []byte {
151+
func decode(data []byte) ([]byte, error) {
152152
blobLen := new(big.Int).SetBytes(data[:preLenBlob])
153153
var lenBytes = blobLen.Uint64()
154-
return data[preLenBlob:lenBytes]
154+
if int(lenBytes) > len(data) {
155+
return nil, ErrBlobInvalid
156+
}
157+
return data[preLenBlob:lenBytes], nil
155158
}
156159

157160
// EncodeBlobs encodes bytes into a EIP-4844 blob.
@@ -172,13 +175,15 @@ func EncodeBlobs(origin []byte) []kzg4844.Blob {
172175
}
173176

174177
// DecodeBlob decodes the given blob data.
175-
func DecodeBlob(blob []byte) ([]byte, error) {
178+
func DecodeBlob(blob []byte) (res []byte, err error) {
176179
if len(blob) != BlobBytes {
177-
return nil, errBlobInvalid
180+
return nil, ErrBlobInvalid
181+
}
182+
blob, err = decode(blob)
183+
if err != nil {
184+
return nil, err
178185
}
179-
blob = decode(blob)
180186

181-
var res []byte
182187
for ; len(blob) >= 32; blob = blob[32:] {
183188
data := [31]byte{}
184189
copy(data[:], blob[1:])

0 commit comments

Comments
 (0)