@@ -12,6 +12,7 @@ import (
1212 builderApi "github.com/attestantio/go-builder-client/api"
1313 denebApi "github.com/attestantio/go-builder-client/api/deneb"
1414 builderSpec "github.com/attestantio/go-builder-client/spec"
15+ eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella"
1516 eth2ApiV1Deneb "github.com/attestantio/go-eth2-client/api/v1/deneb"
1617 eth2ApiV1Electra "github.com/attestantio/go-eth2-client/api/v1/electra"
1718 "github.com/attestantio/go-eth2-client/spec"
@@ -25,7 +26,8 @@ import (
2526)
2627
2728type Payload interface {
28- * eth2ApiV1Deneb.SignedBlindedBeaconBlock |
29+ * eth2ApiV1Capella.SignedBlindedBeaconBlock |
30+ * eth2ApiV1Deneb.SignedBlindedBeaconBlock |
2931 * eth2ApiV1Electra.SignedBlindedBeaconBlock
3032}
3133
3941
4042func processPayload [P Payload ](m * BoostService , log * logrus.Entry , ua UserAgent , blindedBlock P ) (* builderApi.VersionedSubmitBlindedBlockResponse , bidResp ) {
4143 var (
42- slot = slot [ P ] (blindedBlock )
43- blockHash = blockHash [ P ] (blindedBlock )
44+ slot = slot (blindedBlock )
45+ blockHash = blockHash (blindedBlock )
4446 )
4547 // Get the currentSlotUID for this slot
4648 currentSlotUID := ""
@@ -53,7 +55,7 @@ func processPayload[P Payload](m *BoostService, log *logrus.Entry, ua UserAgent,
5355 m .slotUIDLock .Unlock ()
5456
5557 // Prepare logger
56- log = prepareLogger [ P ] (log , blindedBlock , ua , currentSlotUID )
58+ log = prepareLogger (log , blindedBlock , ua , currentSlotUID )
5759
5860 // Log how late into the slot the request starts
5961 slotStartTimestamp := m .genesisTime + slot * config .SlotTimeSec
@@ -110,7 +112,7 @@ func processPayload[P Payload](m *BoostService, log *logrus.Entry, ua UserAgent,
110112 return
111113 }
112114
113- if err := verifyPayload [ P ] (blindedBlock , log , responsePayload ); err != nil {
115+ if err := verifyPayload (blindedBlock , log , responsePayload ); err != nil {
114116 return
115117 }
116118
@@ -133,6 +135,13 @@ func processPayload[P Payload](m *BoostService, log *logrus.Entry, ua UserAgent,
133135func verifyPayload [P Payload ](payload P , log * logrus.Entry , response * builderApi.VersionedSubmitBlindedBlockResponse ) error {
134136 // Step 1: verify version
135137 switch any (payload ).(type ) {
138+ case * eth2ApiV1Capella.SignedBlindedBeaconBlock :
139+ if response .Version != spec .DataVersionCapella {
140+ log .WithFields (logrus.Fields {
141+ "version" : response .Version ,
142+ }).Error ("response version was not capella" )
143+ return errInvalidVersion
144+ }
136145 case * eth2ApiV1Deneb.SignedBlindedBeaconBlock :
137146 if response .Version != spec .DataVersionDeneb {
138147 log .WithFields (logrus.Fields {
@@ -155,38 +164,41 @@ func verifyPayload[P Payload](payload P, log *logrus.Entry, response *builderApi
155164 return errEmptyPayload
156165 }
157166
158- // TODO(MariusVanDerWijden): make this generic once
159- // execution payload or blobs bundle change between forks.
160- var (
161- executionPayload * deneb.ExecutionPayload
162- blobs * denebApi.BlobsBundle
163- )
164-
165- switch any (payload ).(type ) {
167+ // Step 3: verify post-conditions
168+ switch block := any (payload ).(type ) {
169+ case * eth2ApiV1Capella.SignedBlindedBeaconBlock :
170+ if err := verifyBlockhash (log , payload , response .Capella .BlockHash ); err != nil {
171+ return err
172+ }
166173 case * eth2ApiV1Deneb.SignedBlindedBeaconBlock :
167- executionPayload = response .Deneb .ExecutionPayload
168- blobs = response .Deneb .BlobsBundle
174+ if err := verifyBlockhash (log , payload , response .Deneb .ExecutionPayload .BlockHash ); err != nil {
175+ return err
176+ }
177+ if err := verifyKZGCommitments (log , response .Deneb .BlobsBundle , block .Message .Body .BlobKZGCommitments ); err != nil {
178+ return err
179+ }
169180 case * eth2ApiV1Electra.SignedBlindedBeaconBlock :
170- executionPayload = response .Electra .ExecutionPayload
171- blobs = response .Electra .BlobsBundle
181+ if err := verifyBlockhash (log , payload , response .Electra .ExecutionPayload .BlockHash ); err != nil {
182+ return err
183+ }
184+ if err := verifyKZGCommitments (log , response .Electra .BlobsBundle , block .Message .Body .BlobKZGCommitments ); err != nil {
185+ return err
186+ }
172187 }
188+ return nil
189+ }
173190
174- // Step 3: Ensure the response blockhash matches the request
175- if blockHash [ P ] (payload ) != executionPayload . BlockHash {
191+ func verifyBlockhash [ P Payload ]( log * logrus. Entry , payload P , executionPayloadHash phase0. Hash32 ) error {
192+ if blockHash (payload ) != executionPayloadHash {
176193 log .WithFields (logrus.Fields {
177- "responseBlockHash" : executionPayload .String (),
194+ "responseBlockHash" : executionPayloadHash .String (),
178195 }).Error ("requestBlockHash does not equal responseBlockHash" )
179196 return errInvalidBlockhash
180197 }
198+ return nil
199+ }
181200
182- // Step 4: Verify KZG commitments
183- var commitments []deneb.KZGCommitment
184- switch block := any (payload ).(type ) {
185- case * eth2ApiV1Deneb.SignedBlindedBeaconBlock :
186- commitments = block .Message .Body .BlobKZGCommitments
187- case * eth2ApiV1Electra.SignedBlindedBeaconBlock :
188- commitments = block .Message .Body .BlobKZGCommitments
189- }
201+ func verifyKZGCommitments (log * logrus.Entry , blobs * denebApi.BlobsBundle , commitments []deneb.KZGCommitment ) error {
190202 // Ensure that blobs are valid and matches the request
191203 if len (commitments ) != len (blobs .Blobs ) || len (commitments ) != len (blobs .Commitments ) || len (commitments ) != len (blobs .Proofs ) {
192204 log .WithFields (logrus.Fields {
@@ -213,6 +225,14 @@ func verifyPayload[P Payload](payload P, log *logrus.Entry, response *builderApi
213225
214226func prepareLogger [P Payload ](log * logrus.Entry , payload P , userAgent UserAgent , slotUID string ) * logrus.Entry {
215227 switch block := any (payload ).(type ) {
228+ case * eth2ApiV1Capella.SignedBlindedBeaconBlock :
229+ return log .WithFields (logrus.Fields {
230+ "ua" : userAgent ,
231+ "slot" : block .Message .Slot ,
232+ "blockHash" : block .Message .Body .ExecutionPayloadHeader .BlockHash .String (),
233+ "parentHash" : block .Message .Body .ExecutionPayloadHeader .ParentHash .String (),
234+ "slotUID" : slotUID ,
235+ })
216236 case * eth2ApiV1Deneb.SignedBlindedBeaconBlock :
217237 return log .WithFields (logrus.Fields {
218238 "ua" : userAgent ,
@@ -235,6 +255,8 @@ func prepareLogger[P Payload](log *logrus.Entry, payload P, userAgent UserAgent,
235255
236256func slot [P Payload ](payload P ) uint64 {
237257 switch block := any (payload ).(type ) {
258+ case * eth2ApiV1Capella.SignedBlindedBeaconBlock :
259+ return uint64 (block .Message .Slot )
238260 case * eth2ApiV1Deneb.SignedBlindedBeaconBlock :
239261 return uint64 (block .Message .Slot )
240262 case * eth2ApiV1Electra.SignedBlindedBeaconBlock :
@@ -245,6 +267,8 @@ func slot[P Payload](payload P) uint64 {
245267
246268func blockHash [P Payload ](payload P ) phase0.Hash32 {
247269 switch block := any (payload ).(type ) {
270+ case * eth2ApiV1Capella.SignedBlindedBeaconBlock :
271+ return block .Message .Body .ExecutionPayloadHeader .BlockHash
248272 case * eth2ApiV1Deneb.SignedBlindedBeaconBlock :
249273 return block .Message .Body .ExecutionPayloadHeader .BlockHash
250274 case * eth2ApiV1Electra.SignedBlindedBeaconBlock :
0 commit comments