Skip to content

Commit

Permalink
Remove redundant signature decoding (sei-protocol#1462)
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen authored Mar 22, 2024
1 parent 8857793 commit 0f9c32b
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
cmath "github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -50,11 +51,7 @@ func (server msgServer) EVMTransaction(goCtx context.Context, msg *types.MsgEVMT
stateDB := state.NewDBImpl(ctx, &server, false)
tx, _ := msg.AsTransaction()
ctx, gp := server.getGasPool(ctx)
emsg, err := server.getEVMMessage(ctx, tx)
if err != nil {
ctx.Logger().Error(fmt.Sprintf("EVM message server error: getting EVM message failed due to %s", err))
return
}
emsg := server.getEVMMessage(ctx, tx, msg.Derived.SenderEVMAddr)

defer func() {
if pe := recover(); pe != nil {
Expand Down Expand Up @@ -160,10 +157,28 @@ func (k *Keeper) getGasPool(ctx sdk.Context) (sdk.Context, core.GasPool) {
return ctx, math.MaxUint64
}

func (server msgServer) getEVMMessage(ctx sdk.Context, tx *ethtypes.Transaction) (*core.Message, error) {
cfg := types.DefaultChainConfig().EthereumConfig(server.ChainID(ctx))
signer := ethtypes.MakeSigner(cfg, big.NewInt(ctx.BlockHeight()), uint64(ctx.BlockTime().Unix()))
return core.TransactionToMessage(tx, signer, server.GetBaseFee(ctx))
func (server msgServer) getEVMMessage(ctx sdk.Context, tx *ethtypes.Transaction, sender common.Address) *core.Message {
msg := &core.Message{
Nonce: tx.Nonce(),
GasLimit: tx.Gas(),
GasPrice: new(big.Int).Set(tx.GasPrice()),
GasFeeCap: new(big.Int).Set(tx.GasFeeCap()),
GasTipCap: new(big.Int).Set(tx.GasTipCap()),
To: tx.To(),
Value: tx.Value(),
Data: tx.Data(),
AccessList: tx.AccessList(),
SkipAccountChecks: false,
BlobHashes: tx.BlobHashes(),
BlobGasFeeCap: tx.BlobGasFeeCap(),
From: sender,
}
// If baseFee provided, set gasPrice to effectiveGasPrice.
baseFee := server.GetBaseFee(ctx)
if baseFee != nil {
msg.GasPrice = cmath.BigMin(msg.GasPrice.Add(msg.GasTipCap, baseFee), msg.GasFeeCap)
}
return msg
}

func (server msgServer) applyEVMMessage(ctx sdk.Context, msg *core.Message, stateDB *state.DBImpl, gp core.GasPool) (*core.ExecutionResult, error) {
Expand Down

0 comments on commit 0f9c32b

Please sign in to comment.