package
2.0.2
Repository: https://github.com/coreumfoundation/coreum.git
Documentation: pkg.go.dev

# README

x/deterministicgas

Intro

Coreum uses a deterministic gas model for its transactions. Meaning that given a transaction type (e.g /coreum.asset.ft.v1.MsgIssueGasPrice) one can know how much gas will be used beforehand, and this amount is fixed if some preconditions are met. Of course this deterministic gas does not apply to the type of transactions that have a complicated, nondeterministic execution path (e.g /cosmwasm.wasm.v1.MsgExecuteContract). We provide tables with all deterministic gas & nondeterministic gas for all our types.

Formula

Here is formula for the transaction

Gas = FixedGas + Sum(Gas for each message) + GasForExtraBytes + GasForExtraSignatures

If message type is deterministic, then the value is looked up from the table, if it is non-deterministic, then the required gas is determined after the execution.

GasForExtraBytes = max(0, TxByteSize-FreeBytes) * TxSizeCostPerByte

GasForExtraSignatures = max(0, NumOfSigs-FreeSigs) * SigVerifyCost

Currently, we have values for the above variables as follows:

  • FixedGas: 50000
  • SigVerifyCost: 1000
  • TxSizeCostPerByte: 10
  • FreeSignatures: 1
  • FreeBytes: 2048

As an example if the transaction has 1 signature on it and is below 2048 bytes, the user will not pay anything extra, and if one of those values exceed those limits, the user will pay for the extra resources.

Full examples

Example 1

Let's say we have a transaction with 1 messages of type /cosmos.bank.v1beta1.MsgSend containing single coin inside, also there is a single signatures and the tx size is 1000 bytes, total will be:

TotalGas = 50000 + 1 * 24000 + 1 * 1000 + max(0, 1000-2048) * 10

Example 2

Let's say we have a transaction with 2 messages of type /coreum.asset.ft.v1.MsgIssueGasPrice inside, also there are 2 signatures and the tx size is 2050 bytes, total will be:

TotalGas = 50000 + 2 * 70000 + 2 * 1000 + max(0, 2050-2048) * 10

Gas Tables

Deterministic messages

Message TypeGas
/cosmos.authz.v1beta1.MsgExecspecial case
/cosmos.bank.v1beta1.MsgMultiSendspecial case
/cosmos.bank.v1beta1.MsgSendspecial case
/coreum.asset.ft.v1.MsgBurn23000
/coreum.asset.ft.v1.MsgFreeze5000
/coreum.asset.ft.v1.MsgGloballyFreeze5000
/coreum.asset.ft.v1.MsgGloballyUnfreeze2500
/coreum.asset.ft.v1.MsgIssue70000
/coreum.asset.ft.v1.MsgMint11000
/coreum.asset.ft.v1.MsgSetWhitelistedLimit5000
/coreum.asset.ft.v1.MsgUnfreeze2500
/coreum.asset.ft.v1.MsgUpgradeTokenV125000
/coreum.asset.nft.v1.MsgAddToWhitelist7000
/coreum.asset.nft.v1.MsgBurn16000
/coreum.asset.nft.v1.MsgFreeze7000
/coreum.asset.nft.v1.MsgIssueClass16000
/coreum.asset.nft.v1.MsgMint39000
/coreum.asset.nft.v1.MsgRemoveFromWhitelist3500
/coreum.asset.nft.v1.MsgUnfreeze5000
/coreum.nft.v1beta1.MsgSend16000
/cosmos.authz.v1beta1.MsgGrant7000
/cosmos.authz.v1beta1.MsgRevoke2500
/cosmos.distribution.v1beta1.MsgFundCommunityPool15000
/cosmos.distribution.v1beta1.MsgSetWithdrawAddress5000
/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward65000
/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission22000
/cosmos.feegrant.v1beta1.MsgGrantAllowance10000
/cosmos.feegrant.v1beta1.MsgRevokeAllowance2500
/cosmos.gov.v1beta1.MsgDeposit52000
/cosmos.gov.v1beta1.MsgVote7000
/cosmos.gov.v1beta1.MsgVoteWeighted9000
/cosmos.slashing.v1beta1.MsgUnjail25000
/cosmos.staking.v1beta1.MsgBeginRedelegate142000
/cosmos.staking.v1beta1.MsgCreateValidator76000
/cosmos.staking.v1beta1.MsgDelegate69000
/cosmos.staking.v1beta1.MsgEditValidator13000
/cosmos.staking.v1beta1.MsgUndelegate112000
/cosmos.vesting.v1beta1.MsgCreateVestingAccount25000
/cosmwasm.wasm.v1.MsgClearAdmin6500
/cosmwasm.wasm.v1.MsgUpdateAdmin8000
/ibc.applications.transfer.v1.MsgTransfer37000

Special Cases

There are some special cases when custom logic is applied for deterministic gas calculation. Real examples of special case tests could be found here

/cosmos.bank.v1beta1.MsgSend

DeterministicGasForMsg = bankSendPerCoinGas * NumberOfCoins

bankSendPerCoinGas is currently equal to 24000.

/cosmos.bank.v1beta1.MsgMultiSend

DeterministicGasForMsg = bankMultiSendPerOperationGas * (NumberOfInputs + NumberOfOutputs)

bankMultiSendPerOperationGas is currently equal to 11000.

/cosmos.authz.v1beta1.MsgExec

DeterministicGasForMsg = authzMsgExecOverhead + Sum(DeterministicGas(ChildMsg))

authzMsgExecOverhead is currently equal to 2000.

Nondeterministic messages

Message Type
/cosmos.crisis.v1beta1.MsgVerifyInvariant
/cosmos.evidence.v1beta1.MsgSubmitEvidence
/cosmos.gov.v1beta1.MsgSubmitProposal
/cosmwasm.wasm.v1.MsgExecuteContract
/cosmwasm.wasm.v1.MsgIBCCloseChannel
/cosmwasm.wasm.v1.MsgIBCSend
/cosmwasm.wasm.v1.MsgInstantiateContract
/cosmwasm.wasm.v1.MsgInstantiateContract2
/cosmwasm.wasm.v1.MsgMigrateContract
/cosmwasm.wasm.v1.MsgStoreCode
/ibc.core.channel.v1.MsgAcknowledgement
/ibc.core.channel.v1.MsgChannelCloseConfirm
/ibc.core.channel.v1.MsgChannelCloseInit
/ibc.core.channel.v1.MsgChannelOpenAck
/ibc.core.channel.v1.MsgChannelOpenConfirm
/ibc.core.channel.v1.MsgChannelOpenInit
/ibc.core.channel.v1.MsgChannelOpenTry
/ibc.core.channel.v1.MsgRecvPacket
/ibc.core.channel.v1.MsgTimeout
/ibc.core.channel.v1.MsgTimeoutOnClose
/ibc.core.client.v1.MsgCreateClient
/ibc.core.client.v1.MsgSubmitMisbehaviour
/ibc.core.client.v1.MsgUpdateClient
/ibc.core.client.v1.MsgUpgradeClient
/ibc.core.connection.v1.MsgConnectionOpenAck
/ibc.core.connection.v1.MsgConnectionOpenConfirm
/ibc.core.connection.v1.MsgConnectionOpenInit
/ibc.core.connection.v1.MsgConnectionOpenTry