Skip to content

Commit

Permalink
Merge pull request #2379 from OffchainLabs/cherry-pick-sendTxArgs
Browse files Browse the repository at this point in the history
Pin go-ethereum with cherry-picked commit
  • Loading branch information
PlasmaPower authored Jun 14, 2024
2 parents 2043d88 + 43429f7 commit 7ca1933
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 202 deletions.
54 changes: 51 additions & 3 deletions arbnode/dataposter/data_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/go-redis/redis/v8"
"github.com/holiman/uint256"
"github.com/offchainlabs/nitro/arbnode/dataposter/dbstorage"
"github.com/offchainlabs/nitro/arbnode/dataposter/externalsigner"
"github.com/offchainlabs/nitro/arbnode/dataposter/noop"
"github.com/offchainlabs/nitro/arbnode/dataposter/slice"
"github.com/offchainlabs/nitro/arbnode/dataposter/storage"
Expand Down Expand Up @@ -255,6 +255,50 @@ func rpcClient(ctx context.Context, opts *ExternalSignerCfg) (*rpc.Client, error
)
}

// TxToSignTxArgs converts transaction to SendTxArgs. This is needed for
// external signer to specify From field.
func TxToSignTxArgs(addr common.Address, tx *types.Transaction) (*apitypes.SendTxArgs, error) {
var to *common.MixedcaseAddress
if tx.To() != nil {
to = new(common.MixedcaseAddress)
*to = common.NewMixedcaseAddress(*tx.To())
}
data := (hexutil.Bytes)(tx.Data())
val := (*hexutil.Big)(tx.Value())
if val == nil {
val = (*hexutil.Big)(big.NewInt(0))
}
al := tx.AccessList()
var (
blobs []kzg4844.Blob
commitments []kzg4844.Commitment
proofs []kzg4844.Proof
)
if tx.BlobTxSidecar() != nil {
blobs = tx.BlobTxSidecar().Blobs
commitments = tx.BlobTxSidecar().Commitments
proofs = tx.BlobTxSidecar().Proofs
}
return &apitypes.SendTxArgs{
From: common.NewMixedcaseAddress(addr),
To: to,
Gas: hexutil.Uint64(tx.Gas()),
GasPrice: (*hexutil.Big)(tx.GasPrice()),
MaxFeePerGas: (*hexutil.Big)(tx.GasFeeCap()),
MaxPriorityFeePerGas: (*hexutil.Big)(tx.GasTipCap()),
Value: *val,
Nonce: hexutil.Uint64(tx.Nonce()),
Data: &data,
AccessList: &al,
ChainID: (*hexutil.Big)(tx.ChainId()),
BlobFeeCap: (*hexutil.Big)(tx.BlobGasFeeCap()),
BlobHashes: tx.BlobHashes(),
Blobs: blobs,
Commitments: commitments,
Proofs: proofs,
}, nil
}

// externalSigner returns signer function and ethereum address of the signer.
// Returns an error if address isn't specified or if it can't connect to the
// signer RPC server.
Expand All @@ -273,7 +317,7 @@ func externalSigner(ctx context.Context, opts *ExternalSignerCfg) (signerFn, com
// RLP encoded transaction object.
// https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_signtransaction
var data hexutil.Bytes
args, err := externalsigner.TxToSignTxArgs(addr, tx)
args, err := TxToSignTxArgs(addr, tx)
if err != nil {
return nil, fmt.Errorf("error converting transaction to sendTxArgs: %w", err)
}
Expand All @@ -285,7 +329,11 @@ func externalSigner(ctx context.Context, opts *ExternalSignerCfg) (signerFn, com
return nil, fmt.Errorf("unmarshaling signed transaction: %w", err)
}
hasher := types.LatestSignerForChainID(tx.ChainId())
if h := hasher.Hash(args.ToTransaction()); h != hasher.Hash(signedTx) {
gotTx, err := args.ToTransaction()
if err != nil {
return nil, fmt.Errorf("converting transaction arguments into transaction: %w", err)
}
if h := hasher.Hash(gotTx); h != hasher.Hash(signedTx) {
return nil, fmt.Errorf("transaction: %x from external signer differs from request: %x", hasher.Hash(signedTx), h)
}
return signedTx, nil
Expand Down
7 changes: 1 addition & 6 deletions arbnode/dataposter/dataposter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/google/go-cmp/cmp"
"github.com/holiman/uint256"
"github.com/offchainlabs/nitro/arbnode/dataposter/externalsigner"
"github.com/offchainlabs/nitro/arbnode/dataposter/externalsignertest"
"github.com/offchainlabs/nitro/util/arbmath"
)
Expand Down Expand Up @@ -142,11 +141,7 @@ func TestExternalSigner(t *testing.T) {
if err != nil {
t.Fatalf("Error signing transaction with external signer: %v", err)
}
args, err := externalsigner.TxToSignTxArgs(addr, tc.tx)
if err != nil {
t.Fatalf("Error converting transaction to sendTxArgs: %v", err)
}
want, err := srv.SignerFn(addr, args.ToTransaction())
want, err := srv.SignerFn(addr, tc.tx)
if err != nil {
t.Fatalf("Error signing transaction: %v", err)
}
Expand Down
115 changes: 0 additions & 115 deletions arbnode/dataposter/externalsigner/externalsigner.go

This file was deleted.

74 changes: 0 additions & 74 deletions arbnode/dataposter/externalsigner/externalsigner_test.go

This file was deleted.

10 changes: 7 additions & 3 deletions arbnode/dataposter/externalsignertest/externalsignertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
"github.com/offchainlabs/nitro/arbnode/dataposter/externalsigner"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/offchainlabs/nitro/util/testhelpers"
)

Expand Down Expand Up @@ -179,11 +179,15 @@ type SignerAPI struct {
Address common.Address
}

func (a *SignerAPI) SignTransaction(ctx context.Context, req *externalsigner.SignTxArgs) (hexutil.Bytes, error) {
func (a *SignerAPI) SignTransaction(ctx context.Context, req *apitypes.SendTxArgs) (hexutil.Bytes, error) {
if req == nil {
return nil, fmt.Errorf("nil request")
}
signedTx, err := a.SignerFn(a.Address, req.ToTransaction())
tx, err := req.ToTransaction()
if err != nil {
return nil, fmt.Errorf("converting send transaction arguments to transaction: %w", err)
}
signedTx, err := a.SignerFn(a.Address, tx)
if err != nil {
return nil, fmt.Errorf("signing transaction: %w", err)
}
Expand Down

0 comments on commit 7ca1933

Please sign in to comment.