1
1
package peerdas
2
2
3
3
import (
4
- "context"
5
4
"encoding/binary"
6
5
"math"
7
6
"slices"
@@ -20,7 +19,6 @@ import (
20
19
"github.com/prysmaticlabs/prysm/v5/crypto/hash"
21
20
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
22
21
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
23
- "golang.org/x/sync/errgroup"
24
22
)
25
23
26
24
var (
@@ -107,57 +105,34 @@ func ComputeColumnsForCustodyGroup(custodyGroup uint64) ([]uint64, error) {
107
105
108
106
// DataColumnSidecars computes the data column sidecars from the signed block and blobs.
109
107
// https://github.com/ethereum/consensus-specs/blob/dev/specs/fulu/das-core.md#get_data_column_sidecars
110
- func DataColumnSidecars (signedBlock interfaces.ReadOnlySignedBeaconBlock , blobs []kzg.Blob ) ([]* ethpb.DataColumnSidecar , error ) {
111
- startTime := time .Now ()
112
- blobsCount := len (blobs )
113
- if blobsCount == 0 {
108
+ func DataColumnSidecars (signedBlock interfaces.ReadOnlySignedBeaconBlock , cellsAndProofs []kzg.CellsAndProofs ) ([]* ethpb.DataColumnSidecar , error ) {
109
+ if signedBlock == nil || len (cellsAndProofs ) == 0 {
114
110
return nil , nil
115
111
}
116
112
117
- // Get the signed block header.
118
- signedBlockHeader , err := signedBlock .Header ()
119
- if err != nil {
120
- return nil , errors .Wrap (err , "signed block header" )
121
- }
122
-
123
- // Get the block body.
113
+ start := time .Now ()
124
114
block := signedBlock .Block ()
125
115
blockBody := block .Body ()
126
-
127
- // Get the blob KZG commitments.
128
116
blobKzgCommitments , err := blockBody .BlobKzgCommitments ()
129
117
if err != nil {
130
118
return nil , errors .Wrap (err , "blob KZG commitments" )
131
119
}
132
120
133
- // Compute the KZG commitments inclusion proof.
134
- kzgCommitmentsInclusionProof , err := blocks .MerkleProofKZGCommitments (blockBody )
135
- if err != nil {
136
- return nil , errors .Wrap (err , "merkle proof ZKG commitments" )
121
+ if len (blobKzgCommitments ) != len (cellsAndProofs ) {
122
+ return nil , errors .New ("mismatch in the number of blob KZG commitments and cellsAndProofs" )
137
123
}
138
124
139
- // Compute cells and proofs.
140
- cellsAndProofs := make ([]kzg.CellsAndProofs , blobsCount )
141
-
142
- eg , _ := errgroup .WithContext (context .Background ())
143
- for i := range blobs {
144
- blobIndex := i
145
- eg .Go (func () error {
146
- blob := & blobs [blobIndex ]
147
- blobCellsAndProofs , err := kzg .ComputeCellsAndKZGProofs (blob )
148
- if err != nil {
149
- return errors .Wrap (err , "compute cells and KZG proofs" )
150
- }
151
-
152
- cellsAndProofs [blobIndex ] = blobCellsAndProofs
153
- return nil
154
- })
125
+ signedBlockHeader , err := signedBlock .Header ()
126
+ if err != nil {
127
+ return nil , errors .Wrap (err , "signed block header" )
155
128
}
156
- if err := eg .Wait (); err != nil {
157
- return nil , err
129
+
130
+ kzgCommitmentsInclusionProof , err := blocks .MerkleProofKZGCommitments (blockBody )
131
+ if err != nil {
132
+ return nil , errors .Wrap (err , "merkle proof ZKG commitments" )
158
133
}
159
134
160
- // Get the column sidecars.
135
+ blobsCount := len ( cellsAndProofs )
161
136
sidecars := make ([]* ethpb.DataColumnSidecar , 0 , fieldparams .NumberOfColumns )
162
137
for columnIndex := uint64 (0 ); columnIndex < fieldparams .NumberOfColumns ; columnIndex ++ {
163
138
column := make ([]kzg.Cell , 0 , blobsCount )
@@ -196,7 +171,8 @@ func DataColumnSidecars(signedBlock interfaces.ReadOnlySignedBeaconBlock, blobs
196
171
197
172
sidecars = append (sidecars , sidecar )
198
173
}
199
- dataColumnComputationTime .Observe (float64 (time .Since (startTime ).Milliseconds ()))
174
+
175
+ dataColumnComputationTime .Observe (float64 (time .Since (start ).Milliseconds ()))
200
176
return sidecars , nil
201
177
}
202
178
0 commit comments