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 return ptx.Transaction.WithBlobTxSidecar(sidecar), nil
} }
func (ptx *PooledBlobTx) RemoveParity() error { func (ptx *PooledBlobTx) RemoveParity() error {
sc := ptx.Sidecar sc := ptx.Sidecar
custodySize := sc.Custody.OneCount() if sc == nil {
if custodySize == 0 { return errors.New("nil sidecar")
return errors.New("blobless transaction")
} }
blobCount := len(sc.Cells) / custodySize
var cellsWithoutParity []kzg4844.Cell for bit := range kzg4844.DataPerBlob {
pos := 0 if !sc.Custody.IsSet(uint(bit)) {
for range blobCount { return errors.New("cannot remove parity for non-full payload transaction")
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 bit := 64; bit < kzg4844.CellsPerBlob; bit++ { blobCount := len(sc.Cells) / kzg4844.CellsPerBlob
sc.Custody.Clear(uint(bit)) 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 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 { 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 // Ensure the blob fee cap satisfies the minimum blob gas price
if tx.BlobGasFeeCapIntCmp(blobTxMinBlobGasPrice) < 0 { if tx.BlobGasFeeCapIntCmp(blobTxMinBlobGasPrice) < 0 {
return fmt.Errorf("%w: blob fee cap %v, minimum needed %v", ErrTxGasPriceTooLow, tx.BlobGasFeeCap(), blobTxMinBlobGasPrice) return fmt.Errorf("%w: blob fee cap %v, minimum needed %v", ErrTxGasPriceTooLow, tx.BlobGasFeeCap(), blobTxMinBlobGasPrice)