Coreum Deterministic Gas

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 + max((GasForBytes + GasForSignatures - TxBaseGas), 0) + Sum(Gas for each message)

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.

GasForBytes = TxByteSize * TxSizeCostPerByte

GasForSignatures = NumOfSigs * SigVerifyCost

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

  • FixedGas: 65000
  • TxBaseGas: 21480
  • SigVerifyCost: 1000
  • TxSizeCostPerByte: 10
  • FreeSignatures: 1
  • FreeBytes: 2048
  • WriteCostPerByte: 30

To summarize user pays FixedGas as long as GasForBytes + GasForSignatures <= TxBaseGas. If GasForBytes + GasForSignatures > TxBaseGas user will have to pay anything above TxBaseGas on top of FixedGas.

As an example if the transaction has 1 signature on it and size is below 2048 bytes, the user will not pay anything extra. Or user can have multiple signatures but fewer bytes then nothing extra should be paid.

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 = 65000 + max(0, (21480 - 1 * 1000 + 1000 * 10)) + 1 * 50000

Example 2

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

TotalGas = 65000 + max(0, (21480 - 2 * 1000 + 2050 * 10)) + 2 * 70000

Extensions

If one of the follwoing messages contains a token which have the extension feature enabled, it will not be considered deterministic any more . The reason is that extensions invlove smart contract calls which are nondeterministic in nature.

  • /ibc.applications.transfer.v1.MsgTransfer
  • /coreum.asset.ft.v1.MsgIssue
  • /cosmos.bank.v1beta1.MsgSend
  • /cosmos.bank.v1beta1.MsgMultiSend
  • /cosmos.distribution.v1beta1.MsgCommunityPoolSpend
  • /cosmos.distribution.v1beta1.MsgFundCommunityPool
  • /cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount
  • /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount
  • /cosmos.vesting.v1beta1.MsgCreateVestingAccount

It should also be mentioned that this rule applies for all the messages inside /cosmos.authz.v1beta1.MsgExec

Gas Tables

Deterministic messages

Message TypeGas
/coreum.asset.nft.v1.MsgIssueClassspecial case
/coreum.asset.nft.v1.MsgMintspecial case
/coreum.asset.nft.v1.MsgUpdateDataspecial case
/cosmos.authz.v1beta1.MsgExecspecial case
/cosmos.bank.v1beta1.MsgMultiSendspecial case
/cosmos.bank.v1beta1.MsgSendspecial case
/coreum.asset.ft.v1.MsgBurn35000
/coreum.asset.ft.v1.MsgClawback15500
/coreum.asset.ft.v1.MsgClearAdmin8500
/coreum.asset.ft.v1.MsgFreeze8500
/coreum.asset.ft.v1.MsgGloballyFreeze5000
/coreum.asset.ft.v1.MsgGloballyUnfreeze5000
/coreum.asset.ft.v1.MsgIssue70000
/coreum.asset.ft.v1.MsgMint31000
/coreum.asset.ft.v1.MsgSetFrozen8500
/coreum.asset.ft.v1.MsgSetWhitelistedLimit9000
/coreum.asset.ft.v1.MsgTransferAdmin10000
/coreum.asset.ft.v1.MsgUnfreeze8500
/coreum.asset.ft.v1.MsgUpgradeTokenV125000
/coreum.asset.nft.v1.MsgAddToClassWhitelist7000
/coreum.asset.nft.v1.MsgAddToWhitelist7000
/coreum.asset.nft.v1.MsgBurn26000
/coreum.asset.nft.v1.MsgClassFreeze8000
/coreum.asset.nft.v1.MsgClassUnfreeze5000
/coreum.asset.nft.v1.MsgFreeze8000
/coreum.asset.nft.v1.MsgRemoveFromClassWhitelist3500
/coreum.asset.nft.v1.MsgRemoveFromWhitelist3500
/coreum.asset.nft.v1.MsgUnfreeze5000
/coreum.dex.v1.MsgPlaceOrder10000
/coreum.nft.v1beta1.MsgSend25000
/cosmos.authz.v1beta1.MsgGrant28000
/cosmos.authz.v1beta1.MsgRevoke8000
/cosmos.distribution.v1beta1.MsgFundCommunityPool17000
/cosmos.distribution.v1beta1.MsgSetWithdrawAddress5000
/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward79000
/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission22000
/cosmos.feegrant.v1beta1.MsgGrantAllowance11000
/cosmos.feegrant.v1beta1.MsgRevokeAllowance2500
/cosmos.gov.v1.MsgDeposit65000
/cosmos.gov.v1.MsgVote6000
/cosmos.gov.v1.MsgVoteWeighted6500
/cosmos.gov.v1beta1.MsgDeposit85000
/cosmos.gov.v1beta1.MsgVote6000
/cosmos.gov.v1beta1.MsgVoteWeighted9000
/cosmos.group.v1.MsgCreateGroup55000
/cosmos.group.v1.MsgCreateGroupPolicy40000
/cosmos.group.v1.MsgCreateGroupWithPolicy95000
/cosmos.group.v1.MsgLeaveGroup17500
/cosmos.group.v1.MsgUpdateGroupAdmin13500
/cosmos.group.v1.MsgUpdateGroupMembers17500
/cosmos.group.v1.MsgUpdateGroupMetadata9500
/cosmos.group.v1.MsgUpdateGroupPolicyAdmin20000
/cosmos.group.v1.MsgUpdateGroupPolicyDecisionPolicy17000
/cosmos.group.v1.MsgUpdateGroupPolicyMetadata15000
/cosmos.group.v1.MsgWithdrawProposal22000
/cosmos.nft.v1beta1.MsgSend25000
/cosmos.slashing.v1beta1.MsgUnjail90000
/cosmos.staking.v1beta1.MsgBeginRedelegate157000
/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation75000
/cosmos.staking.v1beta1.MsgCreateValidator117000
/cosmos.staking.v1beta1.MsgDelegate83000
/cosmos.staking.v1beta1.MsgEditValidator13000
/cosmos.staking.v1beta1.MsgUndelegate112000
/cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount32000
/cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount30000
/cosmos.vesting.v1beta1.MsgCreateVestingAccount30000
/cosmwasm.wasm.v1.MsgClearAdmin6500
/cosmwasm.wasm.v1.MsgUpdateAdmin8000
/ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccount160000
/ibc.applications.transfer.v1.MsgTransfer54000

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 50000.

/cosmos.bank.v1beta1.MsgMultiSend

DeterministicGasForMsg = bankMultiSendPerOperationGas * (NumberOfInputs + NumberOfOutputs)

bankMultiSendPerOperationGas is currently equal to 35000.

/cosmos.authz.v1beta1.MsgExec

DeterministicGasForMsg = authzMsgExecOverhead + Sum(DeterministicGas(ChildMsg))

authzMsgExecOverhead is currently equal to 1500.

/coreum.asset.nft.v1.MsgIssueClass

DeterministicGasForMsg = msgGas + Len(msg.Data) * WriteCostPerByte

msgGas is currently equal to 16000.

/coreum.asset.nft.v1.MsgMint

DeterministicGasForMsg = msgGas + Len(msg.Data) * WriteCostPerByte

msgGas is currently equal to 39000.

Nondeterministic messages

Message Type
/coreum.asset.ft.v1.MsgUpdateParams
/coreum.asset.nft.v1.MsgUpdateParams
/coreum.customparams.v1.MsgUpdateStakingParams
/coreum.feemodel.v1.MsgUpdateParams
/cosmos.auth.v1beta1.MsgUpdateParams
/cosmos.bank.v1beta1.MsgSetSendEnabled
/cosmos.bank.v1beta1.MsgUpdateParams
/cosmos.consensus.v1.MsgUpdateParams
/cosmos.crisis.v1beta1.MsgUpdateParams
/cosmos.crisis.v1beta1.MsgVerifyInvariant
/cosmos.distribution.v1beta1.MsgCommunityPoolSpend
/cosmos.distribution.v1beta1.MsgUpdateParams
/cosmos.evidence.v1beta1.MsgSubmitEvidence
/cosmos.gov.v1.MsgExecLegacyContent
/cosmos.gov.v1.MsgSubmitProposal
/cosmos.gov.v1.MsgUpdateParams
/cosmos.gov.v1beta1.MsgSubmitProposal
/cosmos.group.v1.MsgExec
/cosmos.group.v1.MsgSubmitProposal
/cosmos.group.v1.MsgVote
/cosmos.mint.v1beta1.MsgUpdateParams
/cosmos.slashing.v1beta1.MsgUpdateParams
/cosmos.staking.v1beta1.MsgUpdateParams
/cosmos.upgrade.v1beta1.MsgCancelUpgrade
/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade
/cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddresses
/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.MsgPinCodes
/cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddresses
/cosmwasm.wasm.v1.MsgStoreAndInstantiateContract
/cosmwasm.wasm.v1.MsgStoreAndMigrateContract
/cosmwasm.wasm.v1.MsgStoreCode
/cosmwasm.wasm.v1.MsgSudoContract
/cosmwasm.wasm.v1.MsgUnpinCodes
/cosmwasm.wasm.v1.MsgUpdateContractLabel
/cosmwasm.wasm.v1.MsgUpdateInstantiateConfig
/cosmwasm.wasm.v1.MsgUpdateParams
/ibc.applications.interchain_accounts.controller.v1.MsgSendTx
/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
/packetforward.v1.MsgUpdateParams