Skip to content

Commit

Permalink
blob: fix some sidecar RLP encode/decode issues;
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbundler committed May 13, 2024
1 parent d7088de commit fc02fb4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
50 changes: 17 additions & 33 deletions core/types/blob_sidecars.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,9 @@ func (s *BlobSidecar) EncodeRLP(w io.Writer) error {
if err := EncodeStructSizePrefix(s.payloadSize(), w, b[:]); err != nil {
return err
}
// blobs
if err := s.Blobs.encodePayload(w, b[:], s.Blobs.payloadSize()); err != nil {
if err := s.BlobTxSidecar.EncodeRLP(w); err != nil {
return err
}

// commitments
if err := s.Commitments.encodePayload(w, b[:], s.Commitments.payloadSize()); err != nil {
return err
}

// proofs
if err := s.Proofs.encodePayload(w, b[:], s.Proofs.payloadSize()); err != nil {
return err
}

if err := rlp.Encode(w, s.BlockNumber); err != nil {
return err
}
Expand All @@ -98,31 +86,27 @@ func (sc *BlobSidecar) DecodeRLP(s *rlp.Stream) error {
if err != nil {
return err
}

if err := sc.Blobs.DecodeRLP(s); err != nil {
return fmt.Errorf("decode Blobs: %w", err)
}

if err := sc.Commitments.DecodeRLP(s); err != nil {
return fmt.Errorf("decode Commitments: %w", err)
}

if err := sc.Proofs.DecodeRLP(s); err != nil {
return fmt.Errorf("decode Proofs: %w", err)
if err := sc.BlobTxSidecar.DecodeRLP(s); err != nil {
return err
}
sc.BlockNumber = new(big.Int)
if err := s.Decode(sc.BlockNumber); err != nil {
var b []byte
if b, err = s.Bytes(); err != nil {
return err
}
if err := s.Decode(&sc.BlockHash); err != nil {
sc.BlockNumber = new(big.Int).SetBytes(b)
if b, err = s.Bytes(); err != nil {
return err
}
if err := s.Decode(&sc.TxIndex); err != nil {
sc.BlockHash = libcommon.BytesToHash(b)

if sc.TxIndex, err = s.Uint(); err != nil {
return err
}
if err := s.Decode(&sc.TxHash); err != nil {

if b, err = s.Bytes(); err != nil {
return err
}
sc.TxHash = libcommon.BytesToHash(b)

if err = s.ListEnd(); err != nil {
return fmt.Errorf("close BlobSidecar: %w", err)
Expand All @@ -132,10 +116,10 @@ func (sc *BlobSidecar) DecodeRLP(s *rlp.Stream) error {

func (s *BlobSidecar) payloadSize() int {
size := s.BlobTxSidecar.payloadSize()
size += 1 + rlp.BigIntLenExcludingHead(s.BlockNumber)
size += 33
size += 1 + rlp.IntLenExcludingHead(s.TxIndex)
size += 33
size += rlp.BigIntLenExcludingHead(s.BlockNumber)
size += 32
size += 8
size += 32
return size
}

Expand Down
32 changes: 32 additions & 0 deletions core/types/blob_sidecars_test.go

Large diffs are not rendered by default.

0 comments on commit fc02fb4

Please sign in to comment.