@@ -13,7 +13,6 @@ import (
1313 "sync"
1414
1515 "github.com/morph-l2/go-ethereum/common"
16- "github.com/morph-l2/go-ethereum/common/hexutil"
1716 "github.com/morph-l2/go-ethereum/core/types"
1817 "github.com/morph-l2/go-ethereum/crypto/kzg4844"
1918 "github.com/morph-l2/go-ethereum/params"
@@ -131,70 +130,16 @@ func (cl *L1BeaconClient) GetBlobSidecars(ctx context.Context, ref L1BlockRef, h
131130 if err := cl .apiReq (ctx , & resp , builder .String ()); err != nil {
132131 return nil , fmt .Errorf ("%w: failed to fetch blob sidecars for slot %v block %v" , err , slot , ref )
133132 }
134- if len (hashes ) != len (resp .Data ) {
135- return nil , fmt .Errorf ("expected %v sidecars but got %v" , len (hashes ), len (resp .Data ))
133+ // Some Beacon nodes may ignore the indices parameter and return all sidecars for the slot.
134+ // We only need to ensure we have at least the number of sidecars we requested.
135+ // Callers are responsible for filtering the correct sidecars by index if needed.
136+ if len (resp .Data ) < len (hashes ) {
137+ return nil , fmt .Errorf ("expected at least %v sidecars but got %v" , len (hashes ), len (resp .Data ))
136138 }
137139
138140 return resp .Data , nil
139141}
140142
141- // GetBlobSidecar fetches blob sidecars that were confirmed in the specified L1 block with the
142- // given indexed hashes. Order of the returned sidecars is not guaranteed, and blob data is not
143- // checked for validity.
144- func (cl * L1BeaconClient ) GetBlobSidecar (ctx context.Context , ref L1BlockRef , hashes []IndexedBlobHash ) (types.BlobTxSidecar , error ) {
145- blobSidecars , err := cl .GetBlobSidecars (ctx , ref , hashes )
146- if err != nil {
147- return types.BlobTxSidecar {}, fmt .Errorf ("%w: failed to get blob sidecars for L1BlockRef %v" , err , ref )
148- }
149- return sidecarFromSidecars (blobSidecars , hashes )
150- }
151-
152- func indexFunc (s []* BlobSidecar , f func (blobSidecars * BlobSidecar ) bool ) int {
153- for i := range s {
154- if f (s [i ]) {
155- return i
156- }
157- }
158- return - 1
159- }
160-
161- func sidecarFromSidecars (blobSidecars []* BlobSidecar , hashes []IndexedBlobHash ) (types.BlobTxSidecar , error ) {
162- var blobTxSidecar types.BlobTxSidecar
163- for i , ih := range hashes {
164- // The beacon node api makes no guarantees on order of the returned blob sidecars, so
165- // search for the sidecar that matches the current indexed hash to ensure blobs are
166- // returned in the same order.
167- scIndex := indexFunc (
168- blobSidecars ,
169- func (sc * BlobSidecar ) bool { return uint64 (sc .Index ) == ih .Index })
170- if scIndex == - 1 {
171- return types.BlobTxSidecar {}, fmt .Errorf ("no blob in response matches desired index: %v" , ih .Index )
172- }
173- sidecar := blobSidecars [scIndex ]
174-
175- // make sure the blob's kzg commitment hashes to the expected value
176- hash := KZGToVersionedHash (kzg4844 .Commitment (sidecar .KZGCommitment ))
177- if hash != ih .Hash {
178- return types.BlobTxSidecar {}, fmt .Errorf ("expected hash %s for blob at index %d but got %s" , ih .Hash , ih .Index , hash )
179- }
180-
181- // confirm blob data is valid by verifying its proof against the commitment
182- var blob Blob
183- b , err := hexutil .Decode (sidecar .Blob )
184- if err != nil {
185- return types.BlobTxSidecar {}, fmt .Errorf ("hexutil.Decode(sidecar.Blob) error:%v" , err )
186- }
187- copy (blob [:], b )
188- if err := VerifyBlobProof (& blob , kzg4844 .Commitment (sidecar .KZGCommitment ), kzg4844 .Proof (sidecar .KZGProof )); err != nil {
189- return types.BlobTxSidecar {}, fmt .Errorf ("%w: blob at index %d failed verification" , err , i )
190- }
191- blobTxSidecar .Blobs = append (blobTxSidecar .Blobs , * blob .KZGBlob ())
192- blobTxSidecar .Commitments = append (blobTxSidecar .Commitments , kzg4844 .Commitment (sidecar .KZGCommitment ))
193- blobTxSidecar .Proofs = append (blobTxSidecar .Proofs , kzg4844 .Proof (sidecar .KZGProof ))
194- }
195- return blobTxSidecar , nil
196- }
197-
198143// IndexedBlobHash represents a blob hash that commits to a single blob confirmed in a block. The
199144// index helps us avoid unnecessary blob to blob hash conversions to find the right content in a
200145// sidecar.
0 commit comments