Skip to content

Commit

Permalink
move signature below other checks
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelneuder committed Sep 21, 2023
1 parent 335bff2 commit 3e5f962
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
5 changes: 4 additions & 1 deletion services/api/optimistic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,10 @@ func TestBuilderApiSubmitNewBlockOptimisticV2_full(t *testing.T) {
badSigReq := common.TestBuilderSubmitBlockRequestV2(secretkey, getTestBidTrace(*pubkey, 10))
badSigReq.Signature[0] = 0xaa
invalidSigReq := common.TestBuilderSubmitBlockRequestV2(secretkey, getTestBidTrace(*pubkey, 10))
invalidSigReq.Message.Slot += 1
// Sign over a message with a different value.
diffSig, err := boostTypes.SignMessage(getTestBidTrace(*pubkey, 11), boostTypes.DomainBuilder, secretkey)
require.Nil(t, err)
invalidSigReq.Signature = phase0.BLSSignature(diffSig)
badTimestampReq := common.TestBuilderSubmitBlockRequestV2(secretkey, getTestBidTrace(*pubkey, 10))
badTimestampReq.ExecutionPayloadHeader.Timestamp -= 1
badWithdrawalsRootReq := common.TestBuilderSubmitBlockRequestV2(secretkey, getTestBidTrace(*pubkey, 10))
Expand Down
30 changes: 15 additions & 15 deletions services/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2149,25 +2149,11 @@ func (api *RelayAPI) handleSubmitNewBlockV2(w http.ResponseWriter, req *http.Req
"value": bid.Value.String(),
})

// Verify the signature
log = log.WithField("timestampBeforeSignatureCheck", time.Now().UTC().UnixMilli())
ok, err := boostTypes.VerifySignature(bid, api.opts.EthNetDetails.DomainBuilder, bid.BuilderPubkey[:], sig[:])
log = log.WithField("timestampAfterSignatureCheck", time.Now().UTC().UnixMilli())
if err != nil {
log.WithError(err).Warn("failed verifying builder signature")
api.RespondError(w, http.StatusBadRequest, "failed verifying builder signature")
return
} else if !ok {
log.Warn("invalid builder signature")
api.RespondError(w, http.StatusBadRequest, "invalid signature")
return
}

log.WithFields(logrus.Fields{
"bid": bid,
"signature": sig,
"decode_time": pf.Decode,
}).Info("optimistically parsed bid and verified signature")
}).Info("optimistically parsed bid")

// Check optimistic eligibility.
builderPubkey := bid.BuilderPubkey
Expand Down Expand Up @@ -2242,6 +2228,20 @@ func (api *RelayAPI) handleSubmitNewBlockV2(w http.ResponseWriter, req *http.Req
return
}

// Verify the signature
log = log.WithField("timestampBeforeSignatureCheck", time.Now().UTC().UnixMilli())
ok, err = boostTypes.VerifySignature(bid, api.opts.EthNetDetails.DomainBuilder, bid.BuilderPubkey[:], sig[:])
log = log.WithField("timestampAfterSignatureCheck", time.Now().UTC().UnixMilli())
if err != nil {
log.WithError(err).Warn("failed verifying builder signature")
api.RespondError(w, http.StatusBadRequest, "failed verifying builder signature")
return
} else if !ok {
log.Warn("invalid builder signature")
api.RespondError(w, http.StatusBadRequest, "invalid signature")
return
}

// Create the redis pipeline tx
tx := api.redis.NewTxPipeline()

Expand Down

0 comments on commit 3e5f962

Please sign in to comment.