From 84a2ed0eeefc1c8c9f2b6d2a63761c386039bc5a Mon Sep 17 00:00:00 2001 From: MikkySnow Date: Tue, 8 Oct 2024 16:02:57 +0200 Subject: [PATCH] refactor: remove unused eth_signTypedData endpoint --- rpc/backend/backend.go | 3 -- rpc/backend/sign_tx.go | 34 +------------------- rpc/backend/sign_tx_test.go | 50 ------------------------------ rpc/namespaces/ethereum/eth/api.go | 9 ------ 4 files changed, 1 insertion(+), 95 deletions(-) diff --git a/rpc/backend/backend.go b/rpc/backend/backend.go index 60bcb519..a4e7cb44 100644 --- a/rpc/backend/backend.go +++ b/rpc/backend/backend.go @@ -31,8 +31,6 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" - "github.com/ethereum/go-ethereum/signer/core/apitypes" - rpctypes "swisstronik/rpc/types" "swisstronik/server/config" ethermint "swisstronik/types" @@ -75,7 +73,6 @@ type EVMBackend interface { // Sign Tx Sign(address common.Address, data hexutil.Bytes) (hexutil.Bytes, error) SendTransaction(args evmtypes.TransactionArgs) (common.Hash, error) - SignTypedData(address common.Address, typedData apitypes.TypedData) (hexutil.Bytes, error) // Blocks Info BlockNumber() (hexutil.Uint64, error) diff --git a/rpc/backend/sign_tx.go b/rpc/backend/sign_tx.go index f6511e65..d891d64f 100644 --- a/rpc/backend/sign_tx.go +++ b/rpc/backend/sign_tx.go @@ -28,8 +28,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/signer/core/apitypes" - evmtypes "swisstronik/x/evm/types" ) @@ -126,7 +124,7 @@ func (b *Backend) SendTransaction(args evmtypes.TransactionArgs) (common.Hash, e // Sign signs the provided data using the private key of address via Geth's signature standard. func (b *Backend) Sign(address common.Address, data hexutil.Bytes) (hexutil.Bytes, error) { if !b.cfg.JSONRPC.UnsafeEthEndpointsEnabled { - return nil, fmt.Errorf("eth_sendTransaction not enabled") + return nil, fmt.Errorf("eth_sign not enabled") } from := sdk.AccAddress(address.Bytes()) @@ -147,33 +145,3 @@ func (b *Backend) Sign(address common.Address, data hexutil.Bytes) (hexutil.Byte signature[crypto.RecoveryIDOffset] += 27 // Transform V from 0/1 to 27/28 according to the yellow paper return signature, nil } - -// SignTypedData signs EIP-712 conformant typed data -func (b *Backend) SignTypedData(address common.Address, typedData apitypes.TypedData) (hexutil.Bytes, error) { - if !b.cfg.JSONRPC.UnsafeEthEndpointsEnabled { - return nil, fmt.Errorf("eth_sendTransaction not enabled") - } - - from := sdk.AccAddress(address.Bytes()) - - _, err := b.clientCtx.Keyring.KeyByAddress(from) - if err != nil { - b.logger.Error("failed to find key in keyring", "address", address.String()) - return nil, fmt.Errorf("%s; %s", keystore.ErrNoMatch, err.Error()) - } - - sigHash, _, err := apitypes.TypedDataAndHash(typedData) - if err != nil { - return nil, err - } - - // Sign the requested hash with the wallet - signature, _, err := b.clientCtx.Keyring.SignByAddress(from, sigHash) - if err != nil { - b.logger.Error("keyring.SignByAddress failed", "address", address.Hex()) - return nil, err - } - - signature[crypto.RecoveryIDOffset] += 27 // Transform V from 0/1 to 27/28 according to the yellow paper - return signature, nil -} diff --git a/rpc/backend/sign_tx_test.go b/rpc/backend/sign_tx_test.go index e6644823..86df566e 100644 --- a/rpc/backend/sign_tx_test.go +++ b/rpc/backend/sign_tx_test.go @@ -9,7 +9,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" ethtypes "github.com/ethereum/go-ethereum/core/types" goethcrypto "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/signer/core/apitypes" "google.golang.org/grpc/metadata" "swisstronik/crypto/ethsecp256k1" @@ -227,52 +226,3 @@ func (suite *BackendTestSuite) TestSign() { }) } } - -func (suite *BackendTestSuite) TestSignTypedData() { - from, priv := tests.RandomEthAddressWithPrivateKey() - testCases := []struct { - name string - registerMock func() - fromAddr common.Address - inputTypedData apitypes.TypedData - expPass bool - }{ - { - "fail - can't find key in Keyring", - func() {}, - from, - apitypes.TypedData{}, - false, - }, - { - "fail - empty TypeData", - func() { - armor := crypto.EncryptArmorPrivKey(priv, "", "eth_secp256k1") - err := suite.backend.clientCtx.Keyring.ImportPrivKey("test_key", armor, "") - suite.Require().NoError(err) - }, - from, - apitypes.TypedData{}, - false, - }, - } - - for _, tc := range testCases { - suite.Run(fmt.Sprintf("case %s", tc.name), func() { - suite.SetupTest() // reset test and queries - tc.registerMock() - - responseBz, err := suite.backend.SignTypedData(tc.fromAddr, tc.inputTypedData) - - if tc.expPass { - sigHash, _, err := apitypes.TypedDataAndHash(tc.inputTypedData) - signature, _, err := suite.backend.clientCtx.Keyring.SignByAddress((sdk.AccAddress)(from.Bytes()), sigHash) - signature[goethcrypto.RecoveryIDOffset] += 27 - suite.Require().NoError(err) - suite.Require().Equal((hexutil.Bytes)(signature), responseBz) - } else { - suite.Require().Error(err) - } - }) - } -} diff --git a/rpc/namespaces/ethereum/eth/api.go b/rpc/namespaces/ethereum/eth/api.go index d44c57c7..e19e1f30 100644 --- a/rpc/namespaces/ethereum/eth/api.go +++ b/rpc/namespaces/ethereum/eth/api.go @@ -18,8 +18,6 @@ package eth import ( "context" - "github.com/ethereum/go-ethereum/signer/core/apitypes" - "github.com/ethereum/go-ethereum/rpc" "github.com/cometbft/cometbft/libs/log" @@ -113,7 +111,6 @@ type EthereumAPI interface { Coinbase() (string, error) Sign(address common.Address, data hexutil.Bytes) (hexutil.Bytes, error) GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error) - SignTypedData(address common.Address, typedData apitypes.TypedData) (hexutil.Bytes, error) FillTransaction(args evmtypes.TransactionArgs) (*rpctypes.SignTransactionResult, error) Resend(ctx context.Context, args evmtypes.TransactionArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error) GetPendingTransactions() ([]*rpctypes.RPCTransaction, error) @@ -454,12 +451,6 @@ func (e *PublicAPI) GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, err return backend.TxLogsFromEvents(resBlockResult.TxsResults[res.TxIndex].Events, int(res.MsgIndex)) } -// SignTypedData signs EIP-712 conformant typed data -func (e *PublicAPI) SignTypedData(address common.Address, typedData apitypes.TypedData) (hexutil.Bytes, error) { - e.logger.Debug("eth_signTypedData", "address", address.Hex(), "data", typedData) - return e.backend.SignTypedData(address, typedData) -} - // FillTransaction fills the defaults (nonce, gas, gasPrice or 1559 fields) // on a given unsigned transaction, and returns it to the caller for further // processing (signing + broadcast).