@@ -184,33 +184,37 @@ func (ptx *PooledBlobTx) Convert() (*types.Transaction, error) {
184184
185185 return ptx .Transaction .WithBlobTxSidecar (sidecar ), nil
186186}
187-
188187func (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
0 commit comments