Gas and Fees
Gas costs and transaction fees are used in the Venom network to compensate validators and to cover the storage costs of saving a message on the blockchain. For this reason, a given amount of $VENOM tokens needs to be attached to each message sent in the network so that it can be processed.
Venom's gas model and transaction fee structure serve two key purposes in the network:
- Incentivize validators: Compensation for committing blocks, transaction calculations, storing contract data, and participating in consensus.
- Restrict spam and network attacks: Gas costs and transaction fees help Venom to prevent spam and the network and to avoid malicious parties slowing the chain down.
Commissions are characterized by several important factors:
- Fixed cost per unit of gas: The cost per unit of gas as outlined in the global configuration can only be modified by validators.
- Data storage commission: A commission is charged for storing data during its entire existence in the network.
- Payment via contract balance: Commissions are always paid through the contract balance. This is because external messages cannot be value-bearing.
Users are able to define how many tokens to attach as payment fees for the transaction. The attached tokens are the upper limit the user is willing to pay for the cost of executing the call. If the threshold is not met, the remaining balance will be returned to the user.
The execution of a transaction passes several different phases, as outlined in the section about messages and transactions. For each phase, there is its own type of fee:
- Inbound external message fee: A forward message fee charged for transactions initiated by external messages.
- Storage fee: Charged for storing smart contract and associated data.
- Credit: No fees.
- Compute fee: Gas fees for performing calculations in the called contract
- Action fee: Charged for sending outgoing messages.
- Bounce fee: Fee for sending an erroneous message.
Based on these fee types, the transaction fees are calculated in the following way:
The standard forwarding fee formula is used to calculate fees for inbound messages that are imported for transaction execution. (Also referred to as action fee).
The fee for forwarding a message is calculated by adding the lump_price to the fee for forwarding the bits and cells of the message.
The following is applied to calculate the fees for a message's bits and cells:
- Multiplying price per bit and number of bits in the message.
- Multiplying price per cell and number of cells in the message.
Accordingly, the following formula is used to calculate the forward message fee:
Forward message fee = lump_price + [bit_price ∗ bits + cell_price ∗ cells]
Every transaction in the Venom network moves through a storage phase, incurring a storage fee. The fee is calculated by:
- Multiplying number of bits by global bit price.
- Multiplying number of cells by global cell price.
The results of both calculations are added and then multiplied by the period value.
Accordingly, the following formula is used to calculate the storage fee:
Storage fee = [(bits ∗ global bit price + cells ∗ global cell price) ∗ period]
Gas fees are only charged if a transaction requires the TVM compute phase to be initialized. If there is no initialization, gas fees may be skipped.
The gas fee for the most primitives is calculated via the following formula:
Pb: = 10+b
b refers to the instruction length in bits.
Action fees are charged for performing send message actions. Included are all fees for external outbound messages as well as the first fraction of the internal outbound message fees.
Action fees are calculated via the following formula:
Total action fees = total_out_ext_msg_fwd_fee + total_int_msg_mine_fee
If no actions are performed during a transaction, action fees may be absent.
The fees for outbound internal messages are calculated by adding each outbound internal message fee generated as a result of the execution of the transaction.
Outbound message fees are calculated via the following formula:
Outbound internal messages fee = ∑ n, i=1 (out_int_msg_i.fwd_fee+out_int_msg_i.ihr_fee)