description |
---|
The math behind gas fee calculation on the VeChainThor blockchain. |
Blockchain networks often refer to transaction fees as gas. Gas refers to the unit that measures the amount of computation effort required to execute operations on the blockchain network. This is a fee that is paid by the transaction sender and received by the blockchain network validator.
The VeChainThor blockchain transaction model is capable of containing clauses which allows a single transaction to carry out multiple tasks. Therefore, the total gas cost of the transaction needs to include all the clauses gas costs in the transaction.
The total gas,
- where
$$g_0 = 5,000$$ - There are two types of
$$g_{type}$$ - Regular transaction : 16,000
- Contract creation : 48,000
-
$$g_{data}^i = 4 \cdot n_z^i + 68 \cdot n_{nz}^i$$ -
$$n_z^i$$ is the number of bytes equal to zero within the data in the$$i^{th}$$ clause and$$n_{nz}^i$$ the number of bytes not equal to zero
-
-
$$g_{vm}^i$$ is the gas cost returned by the virtual machine for executing the$$i^{th}$$ clause.
The VeChainThor blockchain allows for transaction-level proof of work (PoW) and converts the proved work into extra gas price that will be used by the system to generate more reward to the block generator, the Authority Masternode, that validates the transaction. In other words, users can utilize their local computational power to make their transactions more likely to be included in a new block.
In particular, the computational work can be proved through fields Nonce
and BlockRef
in the transaction model. Let Nonce
and Gas
, respectively. We use BlockRef
and Nonce
and Signature
,
The PoW,
The extra gas price,
with the following constraint
The VTHO reward for packing the transaction into a new block is computed as:
where
From the above equations, we know that
- Since
$$h_0$$ is a valid block number,BlockRef
must refer to an existing block, that is, it's value must equal the first four bytes of an existing block ID; - The transaction must be packed into a block within the period of 30 blocks after block
$$b$$ , or otherwise, the PoW would not be recognized by the system; - The extra gas price
$$\Delta P$$ can not be greater than base gas price P.
The total gas price for the transaction sender is computed as:
and the total price for block generators as
Where GasPriceCoef
(a value between 0-255) and
It can be seen that the gas price used to calculate the transaction cost depends solely on the input gas-price coefficient while the reward for packing the transaction into a block varies due to the transaction-level proof-of-work mechanism.