fix: modify removeParity function

This commit is contained in:
healthykim 2025-09-12 00:24:53 +09:00
parent 46084fc2a5
commit 987582b5b3
2 changed files with 26 additions and 19 deletions

View file

@ -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")
}
for bit := range kzg4844.DataPerBlob {
if !sc.Custody.IsSet(uint(bit)) {
return errors.New("cannot remove parity for non-full payload transaction")
}
}
blobCount := len(sc.Cells) / kzg4844.CellsPerBlob
if blobCount == 0 || len(sc.Cells)%kzg4844.CellsPerBlob != 0 {
return errors.New("inconsistent cell count")
}
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)
}
}
}
}
sc.Cells = cellsWithoutParity
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
}

View file

@ -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)