Skip to content

Commit 987582b

Browse files
committed
fix: modify removeParity function
1 parent 46084fc commit 987582b

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

core/txpool/blobpool/blobpool.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -184,33 +184,37 @@ func (ptx *PooledBlobTx) Convert() (*types.Transaction, error) {
184184

185185
return ptx.Transaction.WithBlobTxSidecar(sidecar), nil
186186
}
187-
188187
func (ptx *PooledBlobTx) RemoveParity() error {
189188
sc := ptx.Sidecar
190-
custodySize := sc.Custody.OneCount()
191-
if custodySize == 0 {
192-
return errors.New("blobless transaction")
189+
if sc == nil {
190+
return errors.New("nil sidecar")
193191
}
194-
blobCount := len(sc.Cells) / custodySize
195192

196-
var cellsWithoutParity []kzg4844.Cell
197-
pos := 0
198-
for range blobCount {
199-
for bit := 0; bit < kzg4844.CellsPerBlob; bit++ {
200-
if sc.Custody.IsSet(uint(bit)) {
201-
cell := sc.Cells[pos]
202-
pos++
203-
if bit < kzg4844.DataPerBlob {
204-
cellsWithoutParity = append(cellsWithoutParity, cell)
205-
}
206-
}
193+
for bit := range kzg4844.DataPerBlob {
194+
if !sc.Custody.IsSet(uint(bit)) {
195+
return errors.New("cannot remove parity for non-full payload transaction")
207196
}
208197
}
209-
sc.Cells = cellsWithoutParity
210-
for bit := 64; bit < kzg4844.CellsPerBlob; bit++ {
211-
sc.Custody.Clear(uint(bit))
198+
199+
blobCount := len(sc.Cells) / kzg4844.CellsPerBlob
200+
if blobCount == 0 || len(sc.Cells)%kzg4844.CellsPerBlob != 0 {
201+
return errors.New("inconsistent cell count")
212202
}
213203

204+
var cellsWithoutParity []kzg4844.Cell
205+
for blob := range blobCount {
206+
offset := blob * kzg4844.CellsPerBlob
207+
cellsWithoutParity = append(
208+
cellsWithoutParity,
209+
sc.Cells[offset:offset+kzg4844.DataPerBlob]...,
210+
)
211+
212+
for bit := 64; bit < kzg4844.CellsPerBlob; bit++ {
213+
sc.Custody.Clear(uint(bit))
214+
}
215+
}
216+
217+
sc.Cells = cellsWithoutParity
214218
return nil
215219
}
216220

core/txpool/validation.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
145145
}
146146

147147
func ValidateBlobSidecar(tx *types.Transaction, sidecar *types.BlobTxCellSidecar, head *types.Header, opts *ValidationOptions) error {
148+
if sidecar.Custody.OneCount() == 0 {
149+
return errors.New("blobless blob transaction")
150+
}
148151
// Ensure the blob fee cap satisfies the minimum blob gas price
149152
if tx.BlobGasFeeCapIntCmp(blobTxMinBlobGasPrice) < 0 {
150153
return fmt.Errorf("%w: blob fee cap %v, minimum needed %v", ErrTxGasPriceTooLow, tx.BlobGasFeeCap(), blobTxMinBlobGasPrice)

0 commit comments

Comments
 (0)