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

fix(driver): fix a blob decoding issue #629

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ func (s *Syncer) onBlockProposed(
}
txListBytes, err := txListDecoder.Fetch(ctx, tx, &event.Meta)
if err != nil {
return fmt.Errorf("failed to decode tx list: %w", err)
if errors.Is(err, rpc.ErrBlobInvalid) {
log.Info("Invalid blob detected", "blockID", event.BlockId)
txListBytes = []byte{}
} else {
return fmt.Errorf("failed to decode tx list: %w", err)
}
}

l1Origin := &rawdb.L1Origin{
Expand Down
19 changes: 12 additions & 7 deletions pkg/rpc/tx_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
)

var (
errBlobInvalid = errors.New("invalid blob encoding")
ErrBlobInvalid = errors.New("invalid blob encoding")
)

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

func decode(data []byte) []byte {
func decode(data []byte) ([]byte, error) {
blobLen := new(big.Int).SetBytes(data[:preLenBlob])
var lenBytes = blobLen.Uint64()
return data[preLenBlob:lenBytes]
if int(lenBytes) > len(data) {
return nil, ErrBlobInvalid
}
return data[preLenBlob:lenBytes], nil
}

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

// DecodeBlob decodes the given blob data.
func DecodeBlob(blob []byte) ([]byte, error) {
func DecodeBlob(blob []byte) (res []byte, err error) {
if len(blob) != BlobBytes {
return nil, errBlobInvalid
return nil, ErrBlobInvalid
}
blob, err = decode(blob)
if err != nil {
return nil, err
}
blob = decode(blob)

var res []byte
for ; len(blob) >= 32; blob = blob[32:] {
data := [31]byte{}
copy(data[:], blob[1:])
Expand Down
Loading