@@ -132,6 +132,19 @@ func (d *DirkSigner) getAccount(pubkey [48]byte) e2wt.AccountProtectingSigner {
132132 return nil
133133}
134134
135+ func nilCheckFork (fork * api.Fork ) * errors.SignerError {
136+ if fork .CurrentVersion == nil {
137+ return errors .ErrBadRequest
138+ }
139+ if fork .Epoch == nil {
140+ return errors .ErrBadRequest
141+ }
142+ if fork .PreviousVersion == nil {
143+ return errors .ErrBadRequest
144+ }
145+ return nil
146+ }
147+
135148func (d * DirkSigner ) AggregationSlotSigning (ctx context.Context , pubkey [48 ]byte , obj * api.AggregationSlotSigning ) ([96 ]byte , * errors.SignerError ) {
136149 return [96 ]byte {}, nil
137150}
@@ -177,7 +190,134 @@ func (d *DirkSigner) SyncCommitteeSelectionProofSigning(ctx context.Context, pub
177190}
178191
179192func (d * DirkSigner ) SyncCommitteeContributionAndProofSigning (ctx context.Context , pubkey [48 ]byte , obj * api.SyncCommitteeContributionAndProofSigning ) ([96 ]byte , * errors.SignerError ) {
180- return [96 ]byte {}, nil
193+ // Sanity check field nilness
194+ if obj .ContributionAndProof .AggregatorIndex == nil {
195+ d .log .Warn ("aggregator index is nil" )
196+ return [96 ]byte {}, errors .ErrBadRequest
197+ }
198+ if obj .ContributionAndProof .Contribution == nil {
199+ d .log .Warn ("contribution is nil" )
200+ return [96 ]byte {}, errors .ErrBadRequest
201+ }
202+ if obj .ContributionAndProof .SelectionProof == nil {
203+ d .log .Warn ("selection proof is nil" )
204+ return [96 ]byte {}, errors .ErrBadRequest
205+ }
206+
207+ contribution := obj .ContributionAndProof .Contribution
208+ if contribution .AggregationBits == nil {
209+ d .log .Warn ("aggregation bits is nil" )
210+ return [96 ]byte {}, errors .ErrBadRequest
211+ }
212+ if contribution .BeaconBlockRoot == nil {
213+ d .log .Warn ("beacon block root is nil" )
214+ return [96 ]byte {}, errors .ErrBadRequest
215+ }
216+ if contribution .Signature == nil {
217+ d .log .Warn ("signature is nil" )
218+ return [96 ]byte {}, errors .ErrBadRequest
219+ }
220+ if contribution .Slot == nil {
221+ d .log .Warn ("slot is nil" )
222+ return [96 ]byte {}, errors .ErrBadRequest
223+ }
224+ if contribution .SubcommitteeIndex == nil {
225+ d .log .Warn ("subcommittee index is nil" )
226+ return [96 ]byte {}, errors .ErrBadRequest
227+ }
228+
229+ if nilCheckFork (& obj .ForkInfo .Fork ) != nil {
230+ d .log .Warn ("fork info is nil" )
231+ return [96 ]byte {}, errors .ErrBadRequest
232+ }
233+
234+ aggregatorIndex , err := decodeValidatorIndex (* obj .ContributionAndProof .AggregatorIndex )
235+ if err != nil {
236+ d .log .Warn ("failed to decode aggregator index" , "error" , err , "aggregator index" , * obj .ContributionAndProof .AggregatorIndex )
237+ return [96 ]byte {}, err
238+ }
239+
240+ aggregationBits , err := decodeBitVector128 (* contribution .AggregationBits )
241+ if err != nil {
242+ d .log .Warn ("failed to decode aggregation bits" , "error" , err , "aggregation bits" , * contribution .AggregationBits )
243+ return [96 ]byte {}, err
244+ }
245+
246+ beaconBlockRoot , err := decodeRoot (* contribution .BeaconBlockRoot )
247+ if err != nil {
248+ d .log .Warn ("failed to decode beacon block root" , "error" , err , "beacon block root" , * contribution .BeaconBlockRoot )
249+ return [96 ]byte {}, err
250+ }
251+
252+ contributionSignature , err := decodeSignature (* contribution .Signature )
253+ if err != nil {
254+ d .log .Warn ("failed to decode signature" , "error" , err , "signature" , * contribution .Signature )
255+ return [96 ]byte {}, err
256+ }
257+
258+ slot , err := decodeSlot (* contribution .Slot )
259+ if err != nil {
260+ d .log .Warn ("failed to decode slot" , "error" , err , "slot" , * contribution .Slot )
261+ return [96 ]byte {}, err
262+ }
263+
264+ subcommitteeIndex , err := decodeUint64 (* contribution .SubcommitteeIndex )
265+ if err != nil {
266+ d .log .Warn ("failed to decode subcommittee index" , "error" , err , "subcommittee index" , * contribution .SubcommitteeIndex )
267+ return [96 ]byte {}, err
268+ }
269+
270+ selectionProof , err := decodeSignature (* obj .ContributionAndProof .SelectionProof )
271+ if err != nil {
272+ d .log .Warn ("failed to decode selection proof" , "error" , err , "selection proof" , * obj .ContributionAndProof .SelectionProof )
273+ return [96 ]byte {}, err
274+ }
275+
276+ genesisValidatorsRoot , err := decodeRoot (obj .ForkInfo .GenesisValidatorsRoot )
277+ if err != nil {
278+ d .log .Warn ("failed to decode genesis validators root" , "error" , err , "genesis validators root" , obj .ForkInfo .GenesisValidatorsRoot )
279+ return [96 ]byte {}, err
280+ }
281+
282+ // Parse everything into ethpb.SyncCommitteeContributionAndProof
283+ contributionAndProof := & ethpb.ContributionAndProof {
284+ AggregatorIndex : aggregatorIndex ,
285+ Contribution : & ethpb.SyncCommitteeContribution {
286+ AggregationBits : aggregationBits ,
287+ BlockRoot : beaconBlockRoot [:],
288+ Signature : contributionSignature [:],
289+ Slot : slot ,
290+ SubcommitteeIndex : subcommitteeIndex ,
291+ },
292+ SelectionProof : selectionProof [:],
293+ }
294+
295+ hashTreeRoot , nErr := contributionAndProof .HashTreeRoot ()
296+ if nErr != nil {
297+ d .log .Warn ("failed to compute hash tree root" , "error" , nErr )
298+ return [96 ]byte {}, errors .ErrInternalServerError
299+ }
300+
301+ // Compute the domain
302+ domain , nErr := d .domain (domains .DomainSyncContributionAndProof , genesisValidatorsRoot [:], & obj .ForkInfo .Fork )
303+ if nErr != nil {
304+ d .log .Warn ("failed to compute domain" , "error" , nErr )
305+ return [96 ]byte {}, errors .ErrInternalServerError
306+ }
307+
308+ account := d .getAccount (pubkey )
309+ if account == nil {
310+ d .log .Warn ("account not found in cache" , "pubkey" , hex .EncodeToString (pubkey [:]))
311+ return [96 ]byte {}, errors .ErrPublicKeyNotFound
312+ }
313+
314+ signature , nErr := account .SignGeneric (ctx , hashTreeRoot [:], domain [:])
315+ if nErr != nil {
316+ d .log .Warn ("failed to sign sync committee contribution and proof" , "error" , nErr )
317+ return [96 ]byte {}, errors .ErrInternalServerError
318+ }
319+ d .log .Debug ("signed sync committee contribution and proof" , "pubkey" , hex .EncodeToString (pubkey [:]))
320+ return returnSignature (signature )
181321}
182322
183323func (d * DirkSigner ) ValidatorRegistrationSigning (ctx context.Context , pubkey [48 ]byte , obj * api.ValidatorRegistrationSigning ) ([96 ]byte , * errors.SignerError ) {
@@ -199,12 +339,6 @@ func (d *DirkSigner) ValidatorRegistrationSigning(ctx context.Context, pubkey [4
199339 return [96 ]byte {}, errors .ErrBadRequest
200340 }
201341
202- account := d .getAccount (pubkey )
203- if account == nil {
204- d .log .Warn ("account not found in cache" , "pubkey" , hex .EncodeToString (pubkey [:]))
205- return [96 ]byte {}, errors .ErrPublicKeyNotFound
206- }
207-
208342 feeRecipient , err := feeRecipient (* obj .ValidatorRegistration .FeeRecipient )
209343 if err != nil {
210344 d .log .Warn ("failed to decode fee recipient" , "error" , err , "fee recipient" , * obj .ValidatorRegistration .FeeRecipient )
@@ -246,8 +380,15 @@ func (d *DirkSigner) ValidatorRegistrationSigning(ctx context.Context, pubkey [4
246380 Pubkey : pubkey [:],
247381 }
248382
383+ hashTreeRoot , nErr := validatorRegistration .HashTreeRoot ()
384+ if nErr != nil {
385+ d .log .Warn ("failed to compute hash tree root" , "error" , nErr )
386+ return [96 ]byte {}, errors .ErrInternalServerError
387+ }
388+
249389 // Compute the domain
250- // For validator registrations, only genesis for version is needed
390+ // For validator registrations, only genesis fork version is needed
391+ // genesis validators root must be nil
251392 domain , nErr := signing .ComputeDomain (
252393 domains .DomainApplicationBuilder ,
253394 d .genesisForkVersion ,
@@ -258,10 +399,10 @@ func (d *DirkSigner) ValidatorRegistrationSigning(ctx context.Context, pubkey [4
258399 return [96 ]byte {}, errors .ErrInternalServerError
259400 }
260401
261- hashTreeRoot , nErr := validatorRegistration . HashTreeRoot ( )
262- if nErr ! = nil {
263- d .log .Warn ("failed to compute hash tree root " , "error " , nErr )
264- return [96 ]byte {}, errors .ErrInternalServerError
402+ account := d . getAccount ( pubkey )
403+ if account = = nil {
404+ d .log .Warn ("account not found in cache " , "pubkey " , hex . EncodeToString ( pubkey [:]) )
405+ return [96 ]byte {}, errors .ErrPublicKeyNotFound
265406 }
266407
267408 signature , nErr := account .SignGeneric (ctx , hashTreeRoot [:], domain [:])
0 commit comments