From 3ef538502f82159a8facce6a282d53fe8277c64c Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 8 Apr 2025 14:51:26 +0200 Subject: [PATCH] core/types: fix rlp decoding --- core/txpool/validation.go | 6 ++++++ core/types/tx_blob.go | 32 +++++++++++++++++++++++--------- eth/catalyst/api.go | 2 +- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/core/txpool/validation.go b/core/txpool/validation.go index da4828eab8..a1adcf8138 100644 --- a/core/txpool/validation.go +++ b/core/txpool/validation.go @@ -173,6 +173,9 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types } func validateBlobSidecar(hashes []common.Hash, sidecar *types.BlobTxSidecar) error { + if sidecar.Version != 0 { + return fmt.Errorf("invalid sidecar version pre-osaka: %v", sidecar.Version) + } if len(sidecar.Blobs) != len(hashes) { return fmt.Errorf("invalid number of %d blobs compared to %d blob hashes", len(sidecar.Blobs), len(hashes)) } @@ -193,6 +196,9 @@ func validateBlobSidecar(hashes []common.Hash, sidecar *types.BlobTxSidecar) err } func validateBlobSidecarOsaka(hashes []common.Hash, sidecar *types.BlobTxSidecar) error { + if sidecar.Version != 1 { + return fmt.Errorf("invalid sidecar version post-osaka: %v", sidecar.Version) + } if len(sidecar.Blobs) != len(hashes) { return fmt.Errorf("invalid number of %d blobs compared to %d blob hashes", len(sidecar.Blobs), len(hashes)) } diff --git a/core/types/tx_blob.go b/core/types/tx_blob.go index 742539b8b4..73832c7d30 100644 --- a/core/types/tx_blob.go +++ b/core/types/tx_blob.go @@ -55,6 +55,7 @@ type BlobTx struct { // BlobTxSidecar contains the blobs of a blob transaction. type BlobTxSidecar struct { + Version byte // Version Blobs []kzg4844.Blob // Blobs needed by the blob pool Commitments []kzg4844.Commitment // Commitments needed by the blob pool Proofs []kzg4844.Proof // Proofs needed by the blob pool @@ -125,8 +126,8 @@ type blobTxWithBlobs struct { } type versionedBlobTxWithBlobs struct { - Version byte BlobTx *BlobTx + Version byte Blobs []kzg4844.Blob Commitments []kzg4844.Commitment Proofs []kzg4844.Proof @@ -240,6 +241,17 @@ func (tx *BlobTx) encode(b *bytes.Buffer) error { if tx.Sidecar == nil { return rlp.Encode(b, tx) } + // Encode a cell proof transaction + if tx.Sidecar.Version != 0 { + inner := &versionedBlobTxWithBlobs{ + BlobTx: tx, + Version: tx.Sidecar.Version, + Blobs: tx.Sidecar.Blobs, + Commitments: tx.Sidecar.Commitments, + Proofs: tx.Sidecar.Proofs, + } + return rlp.Encode(b, inner) + } inner := &blobTxWithBlobs{ BlobTx: tx, Blobs: tx.Sidecar.Blobs, @@ -269,20 +281,22 @@ func (tx *BlobTx) decode(input []byte) error { return rlp.DecodeBytes(input, tx) } - // It's a tx with blobs. - var inner blobTxWithBlobs + // It's a tx with blobs. Try to decode it as version 0. + var inner versionedBlobTxWithBlobs if err := rlp.DecodeBytes(input, &inner); err != nil { - var innerWithVersion versionedBlobTxWithBlobs - if err := rlp.DecodeBytes(input, &innerWithVersion); err != nil { + var innerV0 blobTxWithBlobs + if err := rlp.DecodeBytes(input, &innerV0); err != nil { return err } - inner.BlobTx = innerWithVersion.BlobTx - inner.Blobs = innerWithVersion.Blobs - inner.Commitments = innerWithVersion.Commitments - inner.Proofs = innerWithVersion.Proofs + inner.BlobTx = innerV0.BlobTx + inner.Version = 0 + inner.Blobs = innerV0.Blobs + inner.Commitments = innerV0.Commitments + inner.Proofs = innerV0.Proofs } *tx = *inner.BlobTx tx.Sidecar = &BlobTxSidecar{ + Version: inner.Version, Blobs: inner.Blobs, Commitments: inner.Commitments, Proofs: inner.Proofs, diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go index 65b0aca08e..ef1e3aac46 100644 --- a/eth/catalyst/api.go +++ b/eth/catalyst/api.go @@ -571,7 +571,7 @@ func (api *ConsensusAPI) GetBlobsV1(hashes []common.Hash) ([]*engine.BlobAndProo index[hash] = i } for i, sidecar := range sidecars { - if res[i] != nil { + if res[i] != nil && sidecar == nil { // already filled continue }