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 @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (evm) [#742](https://github.com/crypto-org-chain/ethermint/pull/742) fix: prevent nil pointer dereference in tracer hooks
* (evm) [#728](https://github.com/crypto-org-chain/ethermint/pull/728) feat: support preinstalls
* (evm) [#722](https://github.com/crypto-org-chain/ethermint/pull/722) feat: support EIP-2935
* (rpc) [#764](https://github.com/crypto-org-chain/ethermint/pull/764) rpc: apply state overrides to eth_estimateGas

## [v0.22.0] - 2025-08-12

Expand Down
2 changes: 1 addition & 1 deletion rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type EVMBackend interface {
Resend(args evmtypes.TransactionArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error)
SendRawTransaction(data hexutil.Bytes) (common.Hash, error)
SetTxDefaults(args evmtypes.TransactionArgs) (evmtypes.TransactionArgs, error)
EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rpctypes.BlockNumber) (hexutil.Uint64, error)
EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rpctypes.BlockNumber, overrides *json.RawMessage) (hexutil.Uint64, error)
DoCall(args evmtypes.TransactionArgs, blockNr rpctypes.BlockNumber, overrides *json.RawMessage) (*evmtypes.MsgEthereumTxResponse, error)
GasPrice() (*hexutil.Big, error)

Expand Down
17 changes: 14 additions & 3 deletions rpc/backend/call_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (b *Backend) SetTxDefaults(args evmtypes.TransactionArgs) (evmtypes.Transac
}

blockNr := rpctypes.NewBlockNumber(big.NewInt(0))
estimated, err := b.EstimateGas(callArgs, &blockNr)
estimated, err := b.EstimateGas(callArgs, &blockNr, nil)
if err != nil {
return args, err
}
Expand All @@ -319,7 +319,11 @@ func (b *Backend) handleRevertError(vmError string, ret []byte) error {
}

// EstimateGas returns an estimate of gas usage for the given smart contract call.
func (b *Backend) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rpctypes.BlockNumber) (hexutil.Uint64, error) {
func (b *Backend) EstimateGas(
args evmtypes.TransactionArgs,
blockNrOptional *rpctypes.BlockNumber,
overrides *json.RawMessage,
) (hexutil.Uint64, error) {
blockNr := rpctypes.EthPendingBlockNumber
if blockNrOptional != nil {
blockNr = *blockNrOptional
Expand All @@ -336,11 +340,17 @@ func (b *Backend) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rp
return 0, errors.New("header not found")
}

var bzOverrides []byte
if overrides != nil {
bzOverrides = *overrides
}

req := evmtypes.EthCallRequest{
Args: bz,
GasCap: b.RPCGasCap(),
ProposerAddress: sdk.ConsAddress(header.Header.ProposerAddress),
ChainId: b.chainID.Int64(),
Overrides: bzOverrides,
}

// From ContextWithHeight: if the provided height is 0,
Expand All @@ -359,7 +369,8 @@ func (b *Backend) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rp
// DoCall performs a simulated call operation through the evmtypes. It returns the
// estimated gas used on the operation or an error if fails.
func (b *Backend) DoCall(
args evmtypes.TransactionArgs, blockNr rpctypes.BlockNumber,
args evmtypes.TransactionArgs,
blockNr rpctypes.BlockNumber,
overrides *json.RawMessage,
) (*evmtypes.MsgEthereumTxResponse, error) {
bz, err := json.Marshal(&args)
Expand Down
10 changes: 7 additions & 3 deletions rpc/namespaces/ethereum/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type EthereumAPI interface {
// Returns information on the Ethereum network and internal settings.
ProtocolVersion() hexutil.Uint
GasPrice() (*hexutil.Big, error)
EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rpctypes.BlockNumber) (hexutil.Uint64, error)
EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rpctypes.BlockNumber, overrides *json.RawMessage) (hexutil.Uint64, error)
FeeHistory(blockCount math.HexOrDecimal64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*rpctypes.FeeHistoryResult, error)
MaxPriorityFeePerGas() (*hexutil.Big, error)
ChainId() (*hexutil.Big, error)
Expand Down Expand Up @@ -322,9 +322,13 @@ func (e *PublicAPI) GasPrice() (*hexutil.Big, error) {
}

// EstimateGas returns an estimate of gas usage for the given smart contract call.
func (e *PublicAPI) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rpctypes.BlockNumber) (hexutil.Uint64, error) {
func (e *PublicAPI) EstimateGas(
args evmtypes.TransactionArgs,
blockNrOptional *rpctypes.BlockNumber,
overrides *json.RawMessage,
) (hexutil.Uint64, error) {
e.logger.Debug("eth_estimateGas")
return e.backend.EstimateGas(args, blockNrOptional)
return e.backend.EstimateGas(args, blockNrOptional, overrides)
}

func (e *PublicAPI) FeeHistory(blockCount math.HexOrDecimal64,
Expand Down
9 changes: 9 additions & 0 deletions x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ func (k Keeper) EstimateGas(c context.Context, req *types.EthCallRequest) (*type
return nil, status.Error(codes.Internal, "failed to load evm config")
}

var overrides rpctypes.StateOverride
if len(req.Overrides) > 0 {
if err := json.Unmarshal(req.Overrides, &overrides); err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}

cfg.Overrides = &overrides
}

// ApplyMessageWithConfig expect correct nonce set in msg
nonce := k.GetNonce(ctx, args.GetFrom())
args.Nonce = (*hexutil.Uint64)(&nonce)
Expand Down
Loading