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

Commit

Permalink
fix(driver): fix a blob decoding issue (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
mask-pp authored Mar 11, 2024
1 parent df0e897 commit 0a29936
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
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

0 comments on commit 0a29936

Please sign in to comment.