-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add opdevnet to integrations package #243
Changes from all commits
2671044
ec52fdd
c64501a
6d104a7
7f0e6c7
0f7ee67
01b7a44
d2c50b0
c36d1c4
0b5b04f
01acddb
82db06a
3ca6bb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,19 +5,21 @@ import ( | |||||
"fmt" | ||||||
|
||||||
bfttypes "github.com/cometbft/cometbft/types" | ||||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||||||
sdktx "github.com/cosmos/cosmos-sdk/types/tx" | ||||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" | ||||||
sdktypes "github.com/cosmos/cosmos-sdk/types" | ||||||
"github.com/ethereum/go-ethereum/common/hexutil" | ||||||
ethtypes "github.com/ethereum/go-ethereum/core/types" | ||||||
rolluptypes "github.com/polymerdao/monomer/x/rollup/types" | ||||||
) | ||||||
|
||||||
var PrivKey = secp256k1.GenPrivKeyFromSecret([]byte("monomer")) | ||||||
|
||||||
var errL1AttributesNotFound = errors.New("L1 attributes tx not found") | ||||||
|
||||||
type TxSigner func(tx *sdktx.Tx) error | ||||||
type TxSigner func([]sdktypes.Msg) (bfttypes.Tx, error) | ||||||
|
||||||
// AdaptPayloadTxsToCosmosTxs assumes the deposit transactions come first. | ||||||
func AdaptPayloadTxsToCosmosTxs(ethTxs []hexutil.Bytes, signTx TxSigner, from string) (bfttypes.Txs, error) { | ||||||
func AdaptPayloadTxsToCosmosTxs(ethTxs []hexutil.Bytes, _ TxSigner, _ string) (bfttypes.Txs, error) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor Function Signature to Remove Unused Parameters The function Apply this diff to remove the unused parameters: -func AdaptPayloadTxsToCosmosTxs(ethTxs []hexutil.Bytes, _ TxSigner, _ string) (bfttypes.Txs, error) {
+func AdaptPayloadTxsToCosmosTxs(ethTxs []hexutil.Bytes) (bfttypes.Txs, error) { 📝 Committable suggestion
Suggested change
|
||||||
if len(ethTxs) == 0 { | ||||||
return bfttypes.Txs{}, nil | ||||||
} | ||||||
|
@@ -27,24 +29,17 @@ func AdaptPayloadTxsToCosmosTxs(ethTxs []hexutil.Bytes, signTx TxSigner, from st | |||||
return nil, fmt.Errorf("count deposit transactions: %v", err) | ||||||
} | ||||||
|
||||||
depositTx, err := packDepositTxsToCosmosTx(ethTxs[:numDepositTxs], from) | ||||||
depositTx, err := packDepositTxsToCosmosTx(ethTxs[:numDepositTxs], "") | ||||||
if err != nil { | ||||||
return nil, fmt.Errorf("pack deposit txs: %v", err) | ||||||
} | ||||||
|
||||||
if signTx != nil { | ||||||
if err := signTx(depositTx); err != nil { | ||||||
return nil, fmt.Errorf("sign tx: %v", err) | ||||||
} | ||||||
} | ||||||
|
||||||
depositSDKMsgBytes, err := depositTx.Marshal() | ||||||
depositTxBytes, err := depositTx.Marshal() | ||||||
if err != nil { | ||||||
return nil, fmt.Errorf("marshal tx: %v", err) | ||||||
} | ||||||
|
||||||
cosmosTxs := make(bfttypes.Txs, 0, 1+numDepositTxs) | ||||||
cosmosTxs = append(cosmosTxs, depositSDKMsgBytes) | ||||||
cosmosTxs = append(cosmosTxs, depositTxBytes) | ||||||
|
||||||
cosmosNonDepositTxs, err := convertToCosmosNonDepositTxs(ethTxs[numDepositTxs:]) | ||||||
if err != nil { | ||||||
|
@@ -76,20 +71,14 @@ func countDepositTransactions(ethTxs []hexutil.Bytes) (int, error) { | |||||
return numDepositTxs, nil | ||||||
} | ||||||
|
||||||
func packDepositTxsToCosmosTx(depositTxs []hexutil.Bytes, from string) (*sdktx.Tx, error) { | ||||||
func packDepositTxsToCosmosTx(depositTxs []hexutil.Bytes, _ string) (*rolluptypes.MsgApplyL1Txs, error) { //nolint:unparam | ||||||
depositTxsBytes := make([][]byte, 0, len(depositTxs)) | ||||||
for _, depositTx := range depositTxs { | ||||||
depositTxsBytes = append(depositTxsBytes, depositTx) | ||||||
} | ||||||
msgAny, err := codectypes.NewAnyWithValue(&rolluptypes.MsgApplyL1Txs{ | ||||||
TxBytes: depositTxsBytes, | ||||||
FromAddress: from, | ||||||
}) | ||||||
if err != nil { | ||||||
return nil, fmt.Errorf("new any with value: %v", err) | ||||||
} | ||||||
|
||||||
return &sdktx.Tx{Body: &sdktx.TxBody{Messages: []*codectypes.Any{msgAny}}}, nil | ||||||
return &rolluptypes.MsgApplyL1Txs{ | ||||||
TxBytes: depositTxsBytes, | ||||||
}, nil | ||||||
Comment on lines
+74
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove Unused Parameter from The parameter Apply this diff to remove the unused parameter: -func packDepositTxsToCosmosTx(depositTxs []hexutil.Bytes, _ string) (*rolluptypes.MsgApplyL1Txs, error) { //nolint:unparam
+func packDepositTxsToCosmosTx(depositTxs []hexutil.Bytes) (*rolluptypes.MsgApplyL1Txs, error) { //nolint:unparam And update the function call accordingly at line 32: - depositTx, err := packDepositTxsToCosmosTx(ethTxs[:numDepositTxs], "")
+ depositTx, err := packDepositTxsToCosmosTx(ethTxs[:numDepositTxs])
|
||||||
} | ||||||
|
||||||
func convertToCosmosNonDepositTxs(nonDepositTxs []hexutil.Bytes) (bfttypes.Txs, error) { | ||||||
|
@@ -123,17 +112,9 @@ func AdaptCosmosTxsToEthTxs(cosmosTxs bfttypes.Txs) (ethtypes.Transactions, erro | |||||
} | ||||||
|
||||||
func GetDepositTxs(txsBytes [][]byte) (ethtypes.Transactions, error) { | ||||||
cosmosEthTx := new(sdktx.Tx) | ||||||
if err := cosmosEthTx.Unmarshal(txsBytes[0]); err != nil { | ||||||
return nil, fmt.Errorf("unmarshal cosmos tx: %v", err) | ||||||
} | ||||||
msgs := cosmosEthTx.GetBody().GetMessages() | ||||||
if num := len(msgs); num != 1 { | ||||||
return nil, fmt.Errorf("unexpected number of msgs in Eth Cosmos tx: want 1, got %d", num) | ||||||
} | ||||||
msg := new(rolluptypes.MsgApplyL1Txs) | ||||||
if err := msg.Unmarshal(msgs[0].GetValue()); err != nil { | ||||||
return nil, fmt.Errorf("unmarshal MsgL1Txs smsg: %v", err) | ||||||
if err := msg.Unmarshal(txsBytes[0]); err != nil { | ||||||
return nil, fmt.Errorf("unmarshal MsgL1Txs msg: %v", err) | ||||||
Comment on lines
+116
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential Index Out of Range Error The code accesses Consider adding a check to ensure that if len(txsBytes) == 0 {
return nil, errors.New("no transactions provided")
}
if err := msg.Unmarshal(txsBytes[0]); err != nil {
return nil, fmt.Errorf("unmarshal MsgL1Txs msg: %v", err)
} |
||||||
} | ||||||
ethTxsBytes := msg.GetTxBytes() | ||||||
if len(ethTxsBytes) == 0 { | ||||||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,7 +284,10 @@ func (b *Builder) parseWithdrawalMessages( | |
if execTxResult.IsOK() { | ||
cosmosTx := new(sdktx.Tx) | ||
if err := cosmosTx.Unmarshal(tx); err != nil { | ||
return nil, fmt.Errorf("unmarshal cosmos tx: %v", err) | ||
// TODO we should check for withdrawal messages on all transaction types. | ||
// Unfortunately, we can't get the app's TxDecoder inside the builder. | ||
// We may want to explore using a PostHandler to manage withdrawals instead. | ||
return execTxResult, nil | ||
Comment on lines
+287
to
+290
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider the implications of ignoring unmarshalling errors The changes to error handling in
Consider the following recommendations:
To address these concerns, consider implementing a logging mechanism for unmarshalling errors: if err := cosmosTx.Unmarshal(tx); err != nil {
+ // Log the error for debugging purposes
+ b.logger.Error("Failed to unmarshal transaction", "error", err)
// TODO we should check for withdrawal messages on all transaction types.
// Unfortunately, we can't get the app's TxDecoder inside the builder.
// We may want to explore using a PostHandler to manage withdrawals instead.
return execTxResult, nil
} Additionally, create a task to explore the PostHandler approach for managing withdrawals. This could potentially resolve the issues with checking withdrawal messages across all transaction types.
|
||
} | ||
for _, msg := range cosmosTx.GetBody().GetMessages() { | ||
withdrawalMsg := new(rolluptypes.MsgInitiateWithdrawal) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ import ( | |
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
appchainClient "github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" | ||
"github.com/ethereum-optimism/optimism/op-service/eth" | ||
"github.com/ethereum/go-ethereum/beacon/engine" | ||
"github.com/ethereum/go-ethereum/common" | ||
|
@@ -50,11 +49,9 @@ func NewEngineAPI( | |
appchainCtx *appchainClient.Context, | ||
metrics Metrics, | ||
) *EngineAPI { | ||
privKey := ed25519.GenPrivKeyFromSecret([]byte("monomer")) // TODO: configurable | ||
|
||
return &EngineAPI{ | ||
txValidator: txValidator, | ||
signer: signer.New(appchainCtx, privKey), | ||
signer: signer.New(appchainCtx, monomer.PrivKey), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential security issue: Usage of global Using Consider updating the code to pass the private key explicitly: func NewEngineAPI(
b *builder.Builder,
txValidator TxValidator,
blockStore DB,
appchainCtx *appchainClient.Context,
metrics Metrics,
+ privKey someKeyType,
) *EngineAPI {
return &EngineAPI{
txValidator: txValidator,
- signer: signer.New(appchainCtx, monomer.PrivKey),
+ signer: signer.New(appchainCtx, privKey),
blockStore: blockStore,
builder: b,
metrics: metrics,
}
}
|
||
blockStore: blockStore, | ||
builder: b, | ||
metrics: metrics, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security Concern: Hardcoded Private Key
Including a hardcoded private key in the code is a significant security risk. Hardcoding secrets can lead to vulnerabilities if the code is exposed. Consider using a secure method to manage private keys, such as environment variables, configuration files, or a secrets management system.