Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

* (cli) [#1615](https://github.com/evmos/ethermint/pull/1615) Support customize db opener in `StartCmd`.
* (ante) [#227](https://github.com/crypto-org-chain/ethermint/pull/227) Reuse sender recovery result.

### State Machine Breaking

Expand Down
2 changes: 1 addition & 1 deletion x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
}
}

response, err := k.ApplyTransaction(ctx, tx)
response, err := k.ApplyTransaction(ctx, msg)
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to apply transaction")
}
Expand Down
7 changes: 4 additions & 3 deletions x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (k Keeper) GetHashFn(ctx sdk.Context) vm.GetHashFunc {
// returning.
//
// For relevant discussion see: https://github.com/cosmos/cosmos-sdk/discussions/9072
func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*types.MsgEthereumTxResponse, error) {
func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *types.MsgEthereumTx) (*types.MsgEthereumTxResponse, error) {
var (
bloom *big.Int
bloomReceipt ethtypes.Bloom
Expand All @@ -203,7 +203,8 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to load evm config")
}
txConfig := k.TxConfig(ctx, tx.Hash())
ethTx := tx.AsTransaction()
txConfig := k.TxConfig(ctx, ethTx.Hash())

// get the signer according to the chain rules from the config and block height
signer := ethtypes.MakeSigner(cfg.ChainConfig, big.NewInt(ctx.BlockHeight()))
Expand Down Expand Up @@ -251,7 +252,7 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t
}

receipt := &ethtypes.Receipt{
Type: tx.Type(),
Type: ethTx.Type(),
PostState: nil, // TODO: intermediate state root
CumulativeGasUsed: cumulativeGasUsed,
Bloom: bloomReceipt,
Expand Down
8 changes: 6 additions & 2 deletions x/evm/keeper/state_transition_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func newSignedEthTx(
addr sdk.Address,
krSigner keyring.Signer,
ethSigner ethtypes.Signer,
) (*ethtypes.Transaction, error) {
) (*evmtypes.MsgEthereumTx, error) {
var ethTx *ethtypes.Transaction
switch txData := txData.(type) {
case *ethtypes.AccessListTx:
Expand All @@ -72,7 +72,11 @@ func newSignedEthTx(
return nil, err
}

return ethTx, nil
var msg evmtypes.MsgEthereumTx
if err := msg.FromEthereumTx(ethTx); err != nil {
return nil, err
}
return &msg, nil
}

func newEthMsgTx(
Expand Down
34 changes: 33 additions & 1 deletion x/evm/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/evmos/ethermint/types"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
)
Expand Down Expand Up @@ -308,7 +309,38 @@ func (msg MsgEthereumTx) AsTransaction() *ethtypes.Transaction {

// AsMessage creates an Ethereum core.Message from the msg fields
func (msg MsgEthereumTx) AsMessage(signer ethtypes.Signer, baseFee *big.Int) (core.Message, error) {
return msg.AsTransaction().AsMessage(signer, baseFee)
txData, err := UnpackTxData(msg.Data)
if err != nil {
return nil, err
}

gasPrice, gasFeeCap, gasTipCap := txData.GetGasPrice(), txData.GetGasFeeCap(), txData.GetGasTipCap()
if baseFee != nil {
gasPrice = math.BigMin(gasPrice.Add(gasTipCap, baseFee), gasFeeCap)
}
var from common.Address
if len(msg.From) > 0 {
from = common.HexToAddress(msg.From)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// user can't set arbitrary value in From field in transaction, the SigVerify ante handler will verify the signature and recover the sender address and populate the From field, so the other code can use it directly when available.

} else {
// heavy path
from, err = signer.Sender(msg.AsTransaction())
if err != nil {
return nil, err
}
}
ethMsg := ethtypes.NewMessage(
from,
txData.GetTo(),
txData.GetNonce(),
txData.GetValue(),
txData.GetGas(),
gasPrice, gasFeeCap, gasTipCap,
txData.GetData(),
txData.GetAccessList(),
false,
)

return ethMsg, nil
}

// GetSender extracts the sender address from the signature values using the latest signer for the given chainID.
Expand Down