Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-txpool: external validating proxy for conditional transactions #11223

Closed
wants to merge 3 commits into from

Conversation

hamdiallam
Copy link
Contributor

Requires

This PR introduces a txpool service to proxy certain rpcs prior to reaching mempool. Primarily just the sendRawTransactionConditional endpoint. This implements the validation and requirements described in the design doc

  • Authentication
  • Rate Limiting
  • Metrics
  • Enable/Disable Conditional Requests
  • 4337 Entrypoint tx target restriction
  • Basic conditional validation

Note: While this service fans out to the list of block builders specified in the config, proxyd will support this broadcast functionality

@hamdiallam hamdiallam requested a review from a team as a code owner July 24, 2024 17:23
return common.Hash{}, invalidAuthenticationErr
}

caller, signature := common.HexToAddress(authElems[0]), common.Hex2Bytes(authElems[1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found banned use of common.Hex2Bytes. Use common.FromHex instead.

Suggested change
caller, signature := common.HexToAddress(authElems[0]), common.Hex2Bytes(authElems[1])
caller, signature := common.HexToAddress(authElems[0]), common.FromHex(authElems[1])
Ignore this finding from ban-common-hex2bytes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is important

Comment on lines +128 to +132
hash, err := s.sendCondTx(ctx, caller, txBytes, cond)
if err != nil {
s.failures.WithLabelValues(err.Error()).Inc()
s.log.Error("failed transaction conditional", "caller", caller.String(), "hash", hash.String(), "err", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable hash is likely modified and later used on error. In some cases this could result in panics due to a nil dereference

Ignore this finding from invalid-usage-of-modified-variable.

require.NoError(t, err)
defer c.Close()

c.SetHeader(authHeaderKey, fmt.Sprintf("%s:%s", common.HexToAddress("0xa"), "foobar"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use net.JoinHostPort instead of fmt.Sprintf("foobar", common.HexToAddress("0xa"))

Ignore this finding from sprintf-host-port.

addr = common.Address{19: 1}
}

req.Header.Set(authHeaderKey, fmt.Sprintf("%s:%s", addr, hex.EncodeToString(sig)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use net.JoinHostPort instead of fmt.Sprintf(hex.EncodeToString(sig), addr)

Ignore this finding from sprintf-host-port.

)

var (
authHeaderKey = "x-optimism-signature"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be mindful of the existing tooling that just works with the flashbots auth header key, now new tooling must be built to support our small diff

}, nil
}

func (s *ConditionalTxService) SendRawTransactionConditional(ctx context.Context, txBytes hexutil.Bytes, cond *types.TransactionConditional) (common.Hash, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this service was just supposed to verify the auth header and not do anything else?

s.failures.WithLabelValues("missing auth").Inc()
return common.Hash{}, invalidAuthenticationErr
}
authElems := strings.Split(authHeader, ":")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementing this under SendRawTransactionConditional means it cannot easily be used for any other RPC endpoints. I feel like it should be more generic and not coupled this this RPC endpoint

@tynes
Copy link
Contributor

tynes commented Jul 24, 2024

I don't think this is a tx pool, its more of a passthru proxy? I also think this should live outside of the protocol monorepo as it will result in maintenance overhead when updating versions of op-geth. It isn't protocol critical

@hamdiallam
Copy link
Contributor Author

I don't think this is a tx pool, its more of a passthru proxy? I also think this should live outside of the protocol monorepo as it will result in maintenance overhead when updating versions of op-geth. It isn't protocol critical

Yea not managing txs. I'll think of a better name. Perhaps this service better lives in ethereum-optimism/infra since it's supporting infrastructure? I would expect operators that enable the endpoint in op-geth to also need this service which is why I opened the PR here since it has an op-geth dependency. But the infra repo also works

@tynes
Copy link
Contributor

tynes commented Jul 25, 2024

I don't think this is a tx pool, its more of a passthru proxy? I also think this should live outside of the protocol monorepo as it will result in maintenance overhead when updating versions of op-geth. It isn't protocol critical

Yea not managing txs. I'll think of a better name. Perhaps this service better lives in ethereum-optimism/infra since it's supporting infrastructure? I would expect operators that enable the endpoint in op-geth to also need this service which is why I opened the PR here since it has an op-geth dependency. But the infra repo also works

I think it would make more sense to go in the infra repo since its infra. It could also go in its own repo.

@tynes
Copy link
Contributor

tynes commented Jul 30, 2024

@hamdiallam Is it ok if we close this?

@hamdiallam
Copy link
Contributor Author

Closing this here and will re-open in infra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants