From 4c8eb4ecea38f40ffc949ecf6b89f214574ea59e Mon Sep 17 00:00:00 2001 From: Daisuke Kanda Date: Mon, 20 Jan 2025 06:07:49 +0000 Subject: [PATCH 1/2] skip sign for estimateGas and not to restore sender address from signature Signed-off-by: Daisuke Kanda --- pkg/client/client.go | 7 +------ pkg/relay/ethereum/signer.go | 6 ++++++ pkg/relay/ethereum/tx.go | 10 +++++++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 7491be4..b9c69d9 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -190,12 +190,7 @@ func (c *CallFrame) UnmarshalJSON(input []byte) error { return nil } -func (cl *ETHClient) EstimateGasFromTx(ctx context.Context, tx *gethtypes.Transaction) (uint64, error) { - from, err := gethtypes.LatestSignerForChainID(tx.ChainId()).Sender(tx) - if err != nil { - return 0, err - } - +func (cl *ETHClient) EstimateGasFromTx(ctx context.Context, tx *gethtypes.Transaction, from common.Address) (uint64, error) { callMsg := ethereum.CallMsg{ From: from, To: tx.To(), diff --git a/pkg/relay/ethereum/signer.go b/pkg/relay/ethereum/signer.go index 32cfb5a..c19fd8b 100644 --- a/pkg/relay/ethereum/signer.go +++ b/pkg/relay/ethereum/signer.go @@ -16,6 +16,7 @@ type EthereumSigner struct { gethSigner gethtypes.Signer addressCache common.Address logger *log.RelayLogger + NoSign bool } func NewEthereumSigner(bytesSigner signer.Signer, chainID *big.Int) (*EthereumSigner, error) { @@ -38,6 +39,7 @@ func NewEthereumSigner(bytesSigner signer.Signer, chainID *big.Int) (*EthereumSi gethSigner: gethSigner, addressCache: addr, logger: nil, + NoSign: false, }, nil } @@ -58,6 +60,10 @@ func (s *EthereumSigner) Sign(address common.Address, tx *gethtypes.Transaction) return nil, fmt.Errorf("unauthorized address: authorized=%v, given=%v", s.Address(), address) } + if s.NoSign { + return tx, nil + } + txHash := s.gethSigner.Hash(tx) if (s.logger != nil) { diff --git a/pkg/relay/ethereum/tx.go b/pkg/relay/ethereum/tx.go index e6ea895..536f56d 100644 --- a/pkg/relay/ethereum/tx.go +++ b/pkg/relay/ethereum/tx.go @@ -553,7 +553,7 @@ func estimateGas( logger = &log.RelayLogger{Logger: logger.With(logAttrRawTxData, hex.EncodeToString(rawTxData))} } - estimatedGas, err := c.client.EstimateGasFromTx(ctx, tx) + estimatedGas, err := c.client.EstimateGasFromTx(ctx, tx, c.ethereumSigner.Address()) if err != nil { if revertReason, rawErrorData, err := c.getRevertReasonFromRpcError(err); err != nil { // Raw error data may be available even if revert reason isn't available. @@ -666,7 +666,9 @@ func (iter *CallIter) buildSingleTx(ctx context.Context, c *Chain) (*CallIterBui // gas estimation { opts.GasLimit = math.MaxUint64 + c.ethereumSigner.NoSign = true tx, err := c.BuildMessageTx(opts, iter.Current(), iter.skipUpdateClientCommitment) + c.ethereumSigner.NoSign = false if err != nil { logger.Error("failed to build tx for gas estimation", err) return nil, err @@ -679,6 +681,7 @@ func (iter *CallIter) buildSingleTx(ctx context.Context, c *Chain) (*CallIterBui opts.GasLimit = txGasLimit } + c.ethereumSigner.NoSign = false tx, err := c.BuildMessageTx(opts, iter.Current(), iter.skipUpdateClientCommitment) if err != nil { logger.Error("failed to build tx", err) @@ -710,7 +713,9 @@ func (iter *CallIter) buildMultiTx(ctx context.Context, c *Chain) (*CallIterBuil logger := iter.updateLoggerMessageInfo(logger, i, 1) // note that its nonce is not checked + c.ethereumSigner.NoSign = true tx, err := c.BuildMessageTx(opts, iter.msgs[i], iter.skipUpdateClientCommitment) + c.ethereumSigner.NoSign = false if err != nil { logger.Error("failed to build tx for gas estimation", err) return nil, err @@ -745,7 +750,9 @@ func (iter *CallIter) buildMultiTx(ctx context.Context, c *Chain) (*CallIterBuil }) } + c.ethereumSigner.NoSign = true multiTx, err := c.multicall3.Aggregate(opts, calls) + c.ethereumSigner.NoSign = false if err != nil { return err } @@ -774,6 +781,7 @@ func (iter *CallIter) buildMultiTx(ctx context.Context, c *Chain) (*CallIterBuil opts.GasLimit = lastOkGasLimit // add raw tx to log attribute + c.ethereumSigner.NoSign = false tx, err := c.multicall3.Aggregate(opts, lastOkCalls) if err != nil { logger.Error("failed to build multicall tx with real send parameters", err) From 4009e2785fb6047568b71f248e777fd0521f63de Mon Sep 17 00:00:00 2001 From: Daisuke Kanda Date: Wed, 29 Jan 2025 17:46:10 +0000 Subject: [PATCH 2/2] remove redundant code Signed-off-by: Daisuke Kanda --- pkg/relay/ethereum/tx.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/relay/ethereum/tx.go b/pkg/relay/ethereum/tx.go index 536f56d..5aa9024 100644 --- a/pkg/relay/ethereum/tx.go +++ b/pkg/relay/ethereum/tx.go @@ -681,7 +681,6 @@ func (iter *CallIter) buildSingleTx(ctx context.Context, c *Chain) (*CallIterBui opts.GasLimit = txGasLimit } - c.ethereumSigner.NoSign = false tx, err := c.BuildMessageTx(opts, iter.Current(), iter.skipUpdateClientCommitment) if err != nil { logger.Error("failed to build tx", err) @@ -781,7 +780,6 @@ func (iter *CallIter) buildMultiTx(ctx context.Context, c *Chain) (*CallIterBuil opts.GasLimit = lastOkGasLimit // add raw tx to log attribute - c.ethereumSigner.NoSign = false tx, err := c.multicall3.Aggregate(opts, lastOkCalls) if err != nil { logger.Error("failed to build multicall tx with real send parameters", err)