evm: fix params (#437)

This commit is contained in:
Federico Kunze Küllmer 2021-08-15 10:54:44 -04:00 committed by GitHub
parent 1300071bd6
commit ff8f63e99b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -129,6 +129,14 @@ func (k *Keeper) ApplyTransaction(tx *ethtypes.Transaction) (*types.MsgEthereumT
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), types.MetricKeyTransitionDB) defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), types.MetricKeyTransitionDB)
params := k.GetParams(k.Ctx()) 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) ethCfg := params.ChainConfig.EthereumConfig(k.eip155ChainID)
// get the latest signer according to the chain rules from the config // 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 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. // 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 // 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. // and the transaction won't be committed to the store.