@@ -167,33 +167,37 @@ func (ptx *PooledBlobTx) Convert() (*types.Transaction, error) {
167
167
168
168
return ptx .Transaction .WithBlobTxSidecar (sidecar ), nil
169
169
}
170
-
171
170
func (ptx * PooledBlobTx ) RemoveParity () error {
172
171
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" )
176
174
}
177
- blobCount := len (sc .Cells ) / custodySize
178
175
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" )
190
179
}
191
180
}
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" )
195
185
}
196
186
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
197
201
return nil
198
202
}
199
203
0 commit comments