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..5aa9024 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 @@ -710,7 +712,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 +749,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 }