@@ -167,33 +167,37 @@ func (ptx *PooledBlobTx) Convert() (*types.Transaction, error) {
167167
168168 return ptx .Transaction .WithBlobTxSidecar (sidecar ), nil
169169}
170-
171170func (ptx * PooledBlobTx ) RemoveParity () error {
172171 sc := ptx .Sidecar
173- custodySize := sc .Custody .OneCount ()
174- if custodySize == 0 {
175- return errors .New ("blobless transaction" )
172+ if sc == nil {
173+ return errors .New ("nil sidecar" )
176174 }
177- blobCount := len (sc .Cells ) / custodySize
178175
179- var cellsWithoutParity []kzg4844.Cell
180- pos := 0
181- for range blobCount {
182- for bit := 0 ; bit < kzg4844 .CellsPerBlob ; bit ++ {
183- if sc .Custody .IsSet (uint (bit )) {
184- cell := sc .Cells [pos ]
185- pos ++
186- if bit < kzg4844 .DataPerBlob {
187- cellsWithoutParity = append (cellsWithoutParity , cell )
188- }
189- }
176+ for bit := range kzg4844 .DataPerBlob {
177+ if ! sc .Custody .IsSet (uint (bit )) {
178+ return errors .New ("cannot remove parity for non-full payload transaction" )
190179 }
191180 }
192- sc .Cells = cellsWithoutParity
193- for bit := 64 ; bit < kzg4844 .CellsPerBlob ; bit ++ {
194- sc .Custody .Clear (uint (bit ))
181+
182+ blobCount := len (sc .Cells ) / kzg4844 .CellsPerBlob
183+ if blobCount == 0 || len (sc .Cells )% kzg4844 .CellsPerBlob != 0 {
184+ return errors .New ("inconsistent cell count" )
195185 }
196186
187+ var cellsWithoutParity []kzg4844.Cell
188+ for blob := range blobCount {
189+ offset := blob * kzg4844 .CellsPerBlob
190+ cellsWithoutParity = append (
191+ cellsWithoutParity ,
192+ sc .Cells [offset :offset + kzg4844 .DataPerBlob ]... ,
193+ )
194+
195+ for bit := 64 ; bit < kzg4844 .CellsPerBlob ; bit ++ {
196+ sc .Custody .Clear (uint (bit ))
197+ }
198+ }
199+
200+ sc .Cells = cellsWithoutParity
197201 return nil
198202}
199203
0 commit comments