Coreum Deterministic Gas
Intro
Coreum is using a deterministic gas model for its transactions. Meaning that given a transaction type (e.g /coreum.asset.ft.v1.MsgMint
) one can know how much gas will be used before hand, 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. For a more recent data, consult this file
Formula
Here is the 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
: 50000SigVerifyCost
: 1000TxSizeCostPerByte
: 10FreeSignatures
: 1FreeBytes
: 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 example
Let's say we have a transaction with 2 messages of type /coreum.asset.ft.v1.MsgMint
inside, also there are 2 signatures and the tx size is 2050 bytes, total will be:
TotalGas = 50000 + 35000 * 2 + (2050-2048) * 10 + 1 * 1000
TotalGas = 121040
Gas Tables
Deterministic messages
Message Type | Gas |
---|---|
/coreum.asset.ft.v1.MsgBurn | 23000 |
/coreum.asset.ft.v1.MsgFreeze | 5000 |
/coreum.asset.ft.v1.MsgGloballyFreeze | 5000 |
/coreum.asset.ft.v1.MsgGloballyUnfreeze | 2500 |
/coreum.asset.ft.v1.MsgIssue | 70000 |
/coreum.asset.ft.v1.MsgMint | 11000 |
/coreum.asset.ft.v1.MsgSetWhitelistedLimit | 5000 |
/coreum.asset.ft.v1.MsgUnfreeze | 2500 |
/coreum.asset.nft.v1.MsgBurn | 16000 |
/coreum.asset.nft.v1.MsgFreeze | 7000 |
/coreum.asset.nft.v1.MsgIssueClass | 16000 |
/coreum.asset.nft.v1.MsgMint | 39000 |
/coreum.asset.nft.v1.MsgUnfreeze | 5000 |
/coreum.nft.v1beta1.MsgSend | 16000 |
/cosmos.authz.v1beta1.MsgExec | special case |
/cosmos.authz.v1beta1.MsgGrant | 7000 |
/cosmos.authz.v1beta1.MsgRevoke | 2500 |
/cosmos.bank.v1beta1.MsgMultiSend | special case |
/cosmos.bank.v1beta1.MsgSend | special case |
/cosmos.distribution.v1beta1.MsgFundCommunityPool | 15000 |
/cosmos.distribution.v1beta1.MsgSetWithdrawAddress | 5000 |
/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward | 65000 |
/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission | 22000 |
/cosmos.feegrant.v1beta1.MsgGrantAllowance | 10000 |
/cosmos.feegrant.v1beta1.MsgRevokeAllowance | 2500 |
/cosmos.gov.v1beta1.MsgDeposit | 52000 |
/cosmos.gov.v1beta1.MsgSubmitProposal | 65000 |
/cosmos.gov.v1beta1.MsgVote | 7000 |
/cosmos.gov.v1beta1.MsgVoteWeighted | 9000 |
/cosmos.slashing.v1beta1.MsgUnjail | 25000 |
/cosmos.staking.v1beta1.MsgBeginRedelegate | 142000 |
/cosmos.staking.v1beta1.MsgCreateValidator | 76000 |
/cosmos.staking.v1beta1.MsgDelegate | 69000 |
/cosmos.staking.v1beta1.MsgEditValidator | 13000 |
/cosmos.staking.v1beta1.MsgUndelegate | 112000 |
/cosmos.vesting.v1beta1.MsgCreateVestingAccount | 25000 |
/cosmwasm.wasm.v1.MsgClearAdmin | 6500 |
/cosmwasm.wasm.v1.MsgUpdateAdmin | 8000 |
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 |
/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 |