11package peerdas
22
33import (
4- "context"
54 "encoding/binary"
65 "math"
76 "slices"
@@ -20,7 +19,6 @@ import (
2019 "github.com/prysmaticlabs/prysm/v5/crypto/hash"
2120 "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
2221 ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
23- "golang.org/x/sync/errgroup"
2422)
2523
2624var (
@@ -105,59 +103,36 @@ func ComputeColumnsForCustodyGroup(custodyGroup uint64) ([]uint64, error) {
105103 return columns , nil
106104}
107105
108- // DataColumnSidecars computes the data column sidecars from the signed block and blobs.
109- // 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 {
106+ // DataColumnSidecars computes the data column sidecars from the signed block, cells and cell proofs.
107+ // https://github.com/ethereum/consensus-specs/blob/v1.5.0-beta.3/specs/fulu/das-core.md#get_data_column_sidecars
108+ func DataColumnSidecars (signedBlock interfaces.ReadOnlySignedBeaconBlock , cellsAndProofs []kzg.CellsAndProofs ) ([]* ethpb.DataColumnSidecar , error ) {
109+ start := time .Now ()
110+ if signedBlock == nil || len (cellsAndProofs ) == 0 {
114111 return nil , nil
115112 }
116113
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.
124114 block := signedBlock .Block ()
125115 blockBody := block .Body ()
126-
127- // Get the blob KZG commitments.
128116 blobKzgCommitments , err := blockBody .BlobKzgCommitments ()
129117 if err != nil {
130118 return nil , errors .Wrap (err , "blob KZG commitments" )
131119 }
132120
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" )
137123 }
138124
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" )
155128 }
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" )
158133 }
159134
160- // Get the column sidecars.
135+ blobsCount := len ( cellsAndProofs )
161136 sidecars := make ([]* ethpb.DataColumnSidecar , 0 , fieldparams .NumberOfColumns )
162137 for columnIndex := uint64 (0 ); columnIndex < fieldparams .NumberOfColumns ; columnIndex ++ {
163138 column := make ([]kzg.Cell , 0 , blobsCount )
@@ -196,7 +171,8 @@ func DataColumnSidecars(signedBlock interfaces.ReadOnlySignedBeaconBlock, blobs
196171
197172 sidecars = append (sidecars , sidecar )
198173 }
199- dataColumnComputationTime .Observe (float64 (time .Since (startTime ).Milliseconds ()))
174+
175+ dataColumnComputationTime .Observe (float64 (time .Since (start ).Milliseconds ()))
200176 return sidecars , nil
201177}
202178
0 commit comments