Skip to content

Commit

Permalink
include err in response
Browse files Browse the repository at this point in the history
  • Loading branch information
hamdiallam committed Nov 7, 2024
1 parent ed410c0 commit 86ab7ed
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions op-txproxy/auth_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var (
DefaultAuthHeaderKey = "X-Optimism-Signature"

// errs
misformattedAuthErr = errors.New("misformatted auth header")
invalidAuthSignatureErr = errors.New("invalid auth signature")
misformattedAuthErr = errors.New("misformatted <caller>:<signature> header")
invalidSignatureErr = errors.New("invalid signature")
mismatchedRecoveredSignerErr = errors.New("mismatched recovered signer")
)

Expand Down Expand Up @@ -88,7 +88,7 @@ func (h *authHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
caller, signature := common.HexToAddress(authElems[0]), common.FromHex(authElems[1])
sigPubKey, err := crypto.SigToPub(txtHash, signature)
if sigPubKey == nil || err != nil {
newCtx := context.WithValue(r.Context(), authContextKey{}, &AuthContext{common.Address{}, invalidAuthSignatureErr})
newCtx := context.WithValue(r.Context(), authContextKey{}, &AuthContext{common.Address{}, invalidSignatureErr})
h.next.ServeHTTP(w, r.WithContext(newCtx))
return
}
Expand Down
4 changes: 2 additions & 2 deletions op-txproxy/auth_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ func TestAuthHandlerBadSignature(t *testing.T) {

rr := httptest.NewRecorder()
r, _ := http.NewRequest("GET", "/", nil)
r.Header.Set("auth", fmt.Sprintf("%s:%s", common.HexToAddress("a"), "foobar"))
r.Header.Set("auth", fmt.Sprintf("%s:%s", common.HexToAddress("a"), "0x123"))

handler.ServeHTTP(rr, r)
require.NotNil(t, authContext)
require.Zero(t, authContext.Caller)
require.Equal(t, invalidAuthSignatureErr, authContext.Err)
require.Equal(t, invalidSignatureErr, authContext.Err)
}

func TestAuthHandlerMismatchedCaller(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion op-txproxy/conditional_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ func (s *ConditionalTxService) SendRawTransactionConditional(ctx context.Context
}
if authInfo.Err != nil {
s.failures.WithLabelValues("invalid auth").Inc()
return common.Hash{}, invalidAuthenticationErr
return common.Hash{}, &rpc.JsonError{
Message: fmt.Sprintf("invalid authentication: %s", authInfo.Err),
Code: params.TransactionConditionalRejectedErrCode,
}
}

// Handle the request. For now, we do nothing with the authenticated signer
Expand Down

0 comments on commit 86ab7ed

Please sign in to comment.