rpc, evm: secure tx signing (#20)

* rpc, evm: secure signing

* evm, ante: test signer

* tests
This commit is contained in:
Federico Kunze
2021-05-12 09:08:31 -04:00
committed by GitHub
parent decd0748ac
commit 65453e4aa0
13 changed files with 439 additions and 201 deletions
+2 -2
View File
@@ -63,7 +63,7 @@ func NewAnteHandler(
opts := txWithExtensions.GetExtensionOptions()
if len(opts) > 0 {
switch typeURL := opts[0].GetTypeUrl(); typeURL {
case "/ethermint.evm.v1beta1.ExtensionOptionsEthereumTx":
case "/ethermint.evm.v1alpha1.ExtensionOptionsEthereumTx":
// handle as *evmtypes.MsgEthereumTx
anteHandler = sdk.ChainAnteDecorators(
@@ -79,7 +79,7 @@ func NewAnteHandler(
NewEthIncrementSenderSequenceDecorator(ak), // innermost AnteDecorator.
)
case "/ethermint.evm.v1beta1.ExtensionOptionsWeb3Tx":
case "/ethermint.evm.v1alpha1.ExtensionOptionsWeb3Tx":
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
switch tx.(type) {
+1 -1
View File
@@ -290,7 +290,7 @@ func (avd EthAccountVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx
if balance.Amount.BigInt().Cmp(msgEthTx.Cost()) < 0 {
return ctx, sdkerrors.Wrapf(
sdkerrors.ErrInsufficientFunds,
"sender balance < tx gas cost (%s%s < %s%s)", balance.String(), evmDenom, msgEthTx.Cost().String(), evmDenom,
"sender balance < tx gas cost (%s < %s%s)", balance.String(), msgEthTx.Cost().String(), evmDenom,
)
}
+6 -1
View File
@@ -17,9 +17,11 @@ import (
"github.com/cosmos/ethermint/app"
ante "github.com/cosmos/ethermint/app/ante"
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
"github.com/cosmos/ethermint/tests"
ethermint "github.com/cosmos/ethermint/types"
evmtypes "github.com/cosmos/ethermint/x/evm/types"
"github.com/ethereum/go-ethereum/common"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
@@ -102,7 +104,10 @@ func newTestSDKTx(
func (suite *AnteTestSuite) newTestEthTx(msg *evmtypes.MsgEthereumTx, priv cryptotypes.PrivKey) (sdk.Tx, error) {
privkey := &ethsecp256k1.PrivKey{Key: priv.Bytes()}
if err := msg.Sign(suite.chainID, privkey.ToECDSA()); err != nil {
signer := tests.NewSigner(privkey)
msg.From = common.BytesToAddress(privkey.PubKey().Address().Bytes()).String()
if err := msg.Sign(suite.chainID, signer); err != nil {
return nil, err
}