Skip to content

Commit

Permalink
Merge pull request #172 from ethereum-optimism/09-24-fix_relayer_forc…
Browse files Browse the repository at this point in the history
…e_private_key_curve_to_make_tx_send_correctly
  • Loading branch information
jakim929 authored Sep 24, 2024
2 parents 9f9e889 + 8e26fa8 commit ac09226
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 153 deletions.
11 changes: 6 additions & 5 deletions config/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"math/big"
"strings"

"github.com/ethereum-optimism/optimism/op-chain-ops/devkeys"
registry "github.com/ethereum-optimism/superchain-registry/superchain"
"github.com/ethereum-optimism/supersim/genesis"
"github.com/ethereum-optimism/supersim/hdaccount"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -139,7 +139,8 @@ func GetDefaultNetworkConfig(startingTimestamp uint64, logsDirectory string) Net

// Note: The default secrets config is used everywhere
func DefaultSecretsConfigAsString() string {
hdAccountStore, err := hdaccount.NewHdAccountStore(DefaultSecretsConfig.Mnemonic, DefaultSecretsConfig.DerivationPath)

keys, err := devkeys.NewMnemonicDevKeys(devkeys.TestMnemonic)
if err != nil {
panic(err)
}
Expand All @@ -150,15 +151,15 @@ func DefaultSecretsConfigAsString() string {
fmt.Fprintf(&b, "-----------------------\n")

for i := range DefaultSecretsConfig.Accounts {
addressHex, _ := hdAccountStore.AddressHexAt(uint32(i))
fmt.Fprintf(&b, "(%d): %s\n", i, addressHex)
address, _ := keys.Address(devkeys.UserKey(i))
fmt.Fprintf(&b, "(%d): %s\n", i, address.Hex())
}

fmt.Fprintf(&b, "\nPrivate Keys\n")
fmt.Fprintf(&b, "-----------------------\n")

for i := range DefaultSecretsConfig.Accounts {
privateKeyHex, _ := hdAccountStore.PrivateKeyHexAt(uint32(i))
privateKeyHex, _ := keys.Secret(devkeys.UserKey(i))
fmt.Fprintf(&b, "(%d): %s\n", i, privateKeyHex)
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/lib/optimism
Submodule optimism updated 480 files
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ go 1.22.3

require (
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/btcutil v1.1.5
github.com/ethereum-optimism/optimism v1.9.2-0.20240916204539-7d92c98c75a2
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240910145426-b3905c89e8ac
github.com/ethereum/go-ethereum v1.14.8
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.9.0
github.com/tyler-smith/go-bip39 v1.1.0
github.com/urfave/cli/v2 v2.27.4
)

Expand All @@ -23,7 +20,9 @@ require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd v0.24.2 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
Expand Down Expand Up @@ -86,6 +85,7 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
golang.org/x/crypto v0.27.0 // indirect
Expand Down
105 changes: 0 additions & 105 deletions hdaccount/hd_account_store.go

This file was deleted.

27 changes: 21 additions & 6 deletions interop/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import (
"math/big"
"sync"

"github.com/ethereum-optimism/optimism/op-chain-ops/devkeys"
"github.com/ethereum-optimism/optimism/op-service/predeploys"
"github.com/ethereum-optimism/optimism/op-service/tasks"
"github.com/ethereum-optimism/supersim/bindings"
"github.com/ethereum-optimism/supersim/config"
"github.com/ethereum-optimism/supersim/hdaccount"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
)

type L2ToL2MessageRelayer struct {
logger log.Logger

l2ToL2MessageIndexer *L2ToL2MessageIndexer

clients map[uint64]*ethclient.Client
Expand All @@ -26,10 +29,11 @@ type L2ToL2MessageRelayer struct {
tasksCancel context.CancelFunc
}

func NewL2ToL2MessageRelayer() *L2ToL2MessageRelayer {
func NewL2ToL2MessageRelayer(logger log.Logger) *L2ToL2MessageRelayer {
tasksCtx, tasksCancel := context.WithCancel(context.Background())

return &L2ToL2MessageRelayer{
logger: logger,
tasks: tasks.Group{
HandleCrit: func(err error) {
fmt.Printf("unhandled indexer error: %v\n", err)
Expand All @@ -45,12 +49,16 @@ func (r *L2ToL2MessageRelayer) Start(indexer *L2ToL2MessageIndexer, clients map[
r.l2ToL2MessageIndexer = indexer
r.clients = clients

hdAccountStore, err := hdaccount.NewHdAccountStore(config.DefaultSecretsConfig.Mnemonic, config.DefaultSecretsConfig.DerivationPath)
keys, err := devkeys.NewMnemonicDevKeys(devkeys.TestMnemonic)
if err != nil {
return fmt.Errorf("failed to create hd account store: %w", err)
return fmt.Errorf("failed to create dev keys: %w", err)
}

privateKey, err := hdAccountStore.DerivePrivateKeyAt(9)
privateKey, err := keys.Secret(devkeys.UserKey(9))
// we force the curve to Geth's instance, because Geth does an equality check in the nocgo version:
// https://github.com/ethereum/go-ethereum/blob/723b1e36ad6a9e998f06f74cc8b11d51635c6402/crypto/signature_nocgo.go#L82
privateKey.PublicKey.Curve = crypto.S256()

if err != nil {
return fmt.Errorf("failed to derive private key: %w", err)
}
Expand All @@ -62,16 +70,19 @@ func (r *L2ToL2MessageRelayer) Start(indexer *L2ToL2MessageIndexer, clients map[
unsubscribe, err := r.l2ToL2MessageIndexer.SubscribeSentMessageToDestination(destinationChainID, sentMessageCh)

if err != nil {
r.logger.Debug("failed to create transactor", "err", err)
return fmt.Errorf("failed to subscribe to sent message events: %w", err)
}

transactor, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(int64(destinationChainID)))
if err != nil {
r.logger.Debug("failed to create transactor", "err", err)
return fmt.Errorf("failed to create transactor: %w", err)
}

crossL2Inbox, err := bindings.NewCrossL2InboxTransactor(predeploys.CrossL2InboxAddr, client)
if err != nil {
r.logger.Debug("failed to create transactor", "err", err)
return fmt.Errorf("failed to create transactor: %w", err)
}

Expand All @@ -87,12 +98,14 @@ func (r *L2ToL2MessageRelayer) Start(indexer *L2ToL2MessageIndexer, clients map[
calldata, err := msg.EventData()

if err != nil {
r.logger.Debug("failed to get event data", "err", err)
return fmt.Errorf("failed to get event data: %w", err)
}

// For some reason gas estimation does not work properly for some messages so estimating and padding gas (https://github.com/ethereum-optimism/supersim/issues/143)
txData, err := bindings.CrossL2InboxParsedABI.Pack("executeMessage", *identifier, predeploys.L2toL2CrossDomainMessengerAddr, calldata)
if err != nil {
r.logger.Debug("failed to create execute message calldata", "err", err)
return fmt.Errorf("failed to create execute message calldata: %w", err)
}
gasEstimate, err := client.EstimateGas(r.tasksCtx, ethereum.CallMsg{
Expand All @@ -101,6 +114,7 @@ func (r *L2ToL2MessageRelayer) Start(indexer *L2ToL2MessageIndexer, clients map[
Data: txData,
})
if err != nil {
r.logger.Debug("failed to estimate gas for execute message tx", "err", err)
return fmt.Errorf("failed to estimate gas for execute message tx: %w", err)
}
// Pad gas by 33%.
Expand All @@ -111,6 +125,7 @@ func (r *L2ToL2MessageRelayer) Start(indexer *L2ToL2MessageIndexer, clients map[
transactor.GasLimit = paddedGas

if _, err := crossL2Inbox.ExecuteMessage(transactor, *identifier, predeploys.L2toL2CrossDomainMessengerAddr, calldata); err != nil {
r.logger.Debug("failed to execute message", "err", err)
return fmt.Errorf("failed to execute message: %w", err)
}
transactor.GasLimit = originalTransactorGasLimit
Expand Down
2 changes: 1 addition & 1 deletion orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewOrchestrator(log log.Logger, closeApp context.CancelCauseFunc, networkCo
if networkConfig.InteropEnabled {
o.l2ToL2MsgIndexer = interop.NewL2ToL2MessageIndexer(log)
if networkConfig.InteropAutoRelay {
o.l2ToL2MsgRelayer = interop.NewL2ToL2MessageRelayer()
o.l2ToL2MsgRelayer = interop.NewL2ToL2MessageRelayer(log)
}
}

Expand Down
Loading

0 comments on commit ac09226

Please sign in to comment.