From 987582b5b300ba3482a39ff3716929aabfcc1e23 Mon Sep 17 00:00:00 2001 From: healthykim Date: Fri, 12 Sep 2025 00:24:53 +0900 Subject: [PATCH] fix: modify removeParity function --- core/txpool/blobpool/blobpool.go | 42 +++++++++++++++++--------------- core/txpool/validation.go | 3 +++ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 4b9932b826..966f4b7772 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -184,33 +184,37 @@ func (ptx *PooledBlobTx) Convert() (*types.Transaction, error) { return ptx.Transaction.WithBlobTxSidecar(sidecar), nil } - func (ptx *PooledBlobTx) RemoveParity() error { sc := ptx.Sidecar - custodySize := sc.Custody.OneCount() - if custodySize == 0 { - return errors.New("blobless transaction") + if sc == nil { + return errors.New("nil sidecar") } - blobCount := len(sc.Cells) / custodySize - var cellsWithoutParity []kzg4844.Cell - pos := 0 - for range blobCount { - for bit := 0; bit < kzg4844.CellsPerBlob; bit++ { - if sc.Custody.IsSet(uint(bit)) { - cell := sc.Cells[pos] - pos++ - if bit < kzg4844.DataPerBlob { - cellsWithoutParity = append(cellsWithoutParity, cell) - } - } + for bit := range kzg4844.DataPerBlob { + if !sc.Custody.IsSet(uint(bit)) { + return errors.New("cannot remove parity for non-full payload transaction") } } - sc.Cells = cellsWithoutParity - for bit := 64; bit < kzg4844.CellsPerBlob; bit++ { - sc.Custody.Clear(uint(bit)) + + blobCount := len(sc.Cells) / kzg4844.CellsPerBlob + if blobCount == 0 || len(sc.Cells)%kzg4844.CellsPerBlob != 0 { + return errors.New("inconsistent cell count") } + var cellsWithoutParity []kzg4844.Cell + for blob := range blobCount { + offset := blob * kzg4844.CellsPerBlob + cellsWithoutParity = append( + cellsWithoutParity, + sc.Cells[offset:offset+kzg4844.DataPerBlob]..., + ) + + for bit := 64; bit < kzg4844.CellsPerBlob; bit++ { + sc.Custody.Clear(uint(bit)) + } + } + + sc.Cells = cellsWithoutParity return nil } diff --git a/core/txpool/validation.go b/core/txpool/validation.go index 0fb4104a05..254e1a8e68 100644 --- a/core/txpool/validation.go +++ b/core/txpool/validation.go @@ -145,6 +145,9 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types } func ValidateBlobSidecar(tx *types.Transaction, sidecar *types.BlobTxCellSidecar, head *types.Header, opts *ValidationOptions) error { + if sidecar.Custody.OneCount() == 0 { + return errors.New("blobless blob transaction") + } // Ensure the blob fee cap satisfies the minimum blob gas price if tx.BlobGasFeeCapIntCmp(blobTxMinBlobGasPrice) < 0 { return fmt.Errorf("%w: blob fee cap %v, minimum needed %v", ErrTxGasPriceTooLow, tx.BlobGasFeeCap(), blobTxMinBlobGasPrice)