From ff8f63e99bc8c3ff8d7c13798d7c2edd478f578c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Sun, 15 Aug 2021 10:54:44 -0400 Subject: [PATCH] evm: fix params (#437) --- x/evm/keeper/state_transition.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index 1cae6d2a..30b0e481 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -129,6 +129,14 @@ func (k *Keeper) ApplyTransaction(tx *ethtypes.Transaction) (*types.MsgEthereumT defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), types.MetricKeyTransitionDB) params := k.GetParams(k.Ctx()) + + // return error if contract creation or call are disabled through governance + if !params.EnableCreate && tx.To() == nil { + return nil, stacktrace.Propagate(types.ErrCreateDisabled, "failed to create new contract") + } else if !params.EnableCall && tx.To() != nil { + return nil, stacktrace.Propagate(types.ErrCallDisabled, "failed to call contract") + } + ethCfg := params.ChainConfig.EthereumConfig(k.eip155ChainID) // get the latest signer according to the chain rules from the config @@ -184,22 +192,6 @@ func (k *Keeper) ApplyTransaction(tx *ethtypes.Transaction) (*types.MsgEthereumT return res, nil } -// Gas consumption notes (write doc from this) - -// gas = remaining gas = limit - consumed - -// Gas consumption in ethereum: -// 0. Buy gas -> deduct gasLimit * gasPrice from user account -// 0.1 leftover gas = gas limit -// 1. consume intrinsic gas -// 1.1 leftover gas = leftover gas - intrinsic gas -// 2. Exec vm functions by passing the gas (i.e remaining gas) -// 2.1 final leftover gas returned after spending gas from the opcodes jump tables -// 3. Refund amount = max(gasConsumed / 2, gas refund), where gas refund is a local variable - -// TODO: (@fedekunze) currently we consume the entire gas limit in the ante handler, so if a transaction fails -// the amount spent will be grater than the gas spent in an Ethereum tx (i.e here the leftover gas won't be refunded). - // ApplyMessage computes the new state by applying the given message against the existing state. // If the message fails, the VM execution error with the reason will be returned to the client // and the transaction won't be committed to the store.