Commit 6f1d8d9a authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge pull request #5052 from mdehoog/michael/fix-address-comparison

[op-signer] Populate from address in TransactionArgs
parents 55230429 42e92639
package crypto package crypto
import ( import (
"bytes"
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"errors" "errors"
...@@ -56,10 +57,10 @@ func SignerFactoryFromConfig(l log.Logger, privateKey, mnemonic, hdPath string, ...@@ -56,10 +57,10 @@ func SignerFactoryFromConfig(l log.Logger, privateKey, mnemonic, hdPath string,
fromAddress = common.HexToAddress(signerConfig.Address) fromAddress = common.HexToAddress(signerConfig.Address)
signer = func(chainID *big.Int) SignerFn { signer = func(chainID *big.Int) SignerFn {
return func(ctx context.Context, address common.Address, tx *types.Transaction) (*types.Transaction, error) { return func(ctx context.Context, address common.Address, tx *types.Transaction) (*types.Transaction, error) {
if address.String() != signerConfig.Address { if !bytes.Equal(address[:], fromAddress[:]) {
return nil, fmt.Errorf("attempting to sign for %s, expected %s: ", address, signerConfig.Address) return nil, fmt.Errorf("attempting to sign for %s, expected %s: ", address, signerConfig.Address)
} }
return signerClient.SignTransaction(ctx, chainID, tx) return signerClient.SignTransaction(ctx, chainID, address, tx)
} }
} }
} else { } else {
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
optls "github.com/ethereum-optimism/optimism/op-service/tls" optls "github.com/ethereum-optimism/optimism/op-service/tls"
"github.com/ethereum-optimism/optimism/op-service/tls/certman" "github.com/ethereum-optimism/optimism/op-service/tls/certman"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
...@@ -91,8 +92,8 @@ func (s *SignerClient) pingVersion() (string, error) { ...@@ -91,8 +92,8 @@ func (s *SignerClient) pingVersion() (string, error) {
return v, nil return v, nil
} }
func (s *SignerClient) SignTransaction(ctx context.Context, chainId *big.Int, tx *types.Transaction) (*types.Transaction, error) { func (s *SignerClient) SignTransaction(ctx context.Context, chainId *big.Int, from common.Address, tx *types.Transaction) (*types.Transaction, error) {
args := NewTransactionArgsFromTransaction(chainId, tx) args := NewTransactionArgsFromTransaction(chainId, from, tx)
var result hexutil.Bytes var result hexutil.Bytes
if err := s.client.CallContext(ctx, &result, "eth_signTransaction", args); err != nil { if err := s.client.CallContext(ctx, &result, "eth_signTransaction", args); err != nil {
......
...@@ -31,12 +31,13 @@ type TransactionArgs struct { ...@@ -31,12 +31,13 @@ type TransactionArgs struct {
} }
// NewTransactionArgsFromTransaction creates a TransactionArgs struct from an EIP-1559 transaction // NewTransactionArgsFromTransaction creates a TransactionArgs struct from an EIP-1559 transaction
func NewTransactionArgsFromTransaction(chainId *big.Int, tx *types.Transaction) *TransactionArgs { func NewTransactionArgsFromTransaction(chainId *big.Int, from common.Address, tx *types.Transaction) *TransactionArgs {
data := hexutil.Bytes(tx.Data()) data := hexutil.Bytes(tx.Data())
nonce := hexutil.Uint64(tx.Nonce()) nonce := hexutil.Uint64(tx.Nonce())
gas := hexutil.Uint64(tx.Gas()) gas := hexutil.Uint64(tx.Gas())
accesses := tx.AccessList() accesses := tx.AccessList()
args := &TransactionArgs{ args := &TransactionArgs{
From: &from,
Input: &data, Input: &data,
Nonce: &nonce, Nonce: &nonce,
Value: (*hexutil.Big)(tx.Value()), Value: (*hexutil.Big)(tx.Value()),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment