Gas
In Nebulas, either a normal transaction which transfer balance or a smart contract deploy & call burns gas, and charged from the balance of from
address. A transaction contains two gas parameters gasPrice
and gasLimit
:
gasPrice
: the price of per gas.gasLimit
: the limit of gas use.
The actual gas consumption of a transaction is the value: gasPrice
* gasUsed
, which will be the reward to the miner coinbase. The gasUsed
value must less than or equal to the gasLimit
. Transaction's gasUsed
can be estimate by RPC interface estimategas and store in transaction's execution result event.
Design reason
Users want to avoid gas costs when the transaction is packaged. Like Bitcoin and Ethereum, Nebulas GAS is used for transaction fee, it have two major purposes:
As a rewards for minter, to incentive them to pack transactions. The packaging of the transaction costs the computing resources, especially the execution of the contract, so the user needs to pay for the transaction.
As a cost for attackers. The DDOS attach is quite cheap in Internet, black hackers hijack user's computer to send large network volume to target server. In Bitcoin and Ethereum network, each transaction must be paid, that significant raise the cost of attack.
Gas constitution
When users submit a transaction, gas will be burned at these aspects:
transaction submition
transaction data storage
transaction payload addition
transaction payload execution
(smart contract execution)
In all these aspects, the power and resources of the net will be consumed and the miners will need to be paid.
Transaction submition
A transaction's submition will add a transaction to the tail block. Miners use resources to record the deal and need to be paid. It will burn a fixed number of gas, that would be defined in code as the following:
If the transaction verifies failed, the gas and value transfer will rollback.
Transaction data storage
When deploying a contract or call contract's method, the raw data of contract execution save in the transaction's data filed, which cost the storage of resources on the chain. A formula to calculate gas:
The TransactionDataGas
is a fixed number of gas defined in code.
Different types of transactions' payload have different gas consumption when executed. The types of transactions currently supported by nebulas are as follows:
binary
: Thebinary
type of transaction allows users to attach binary data to transaction execution. These binary data do not do any processing when the transaction is executed.The fixed number of gas defined 0.
deploy & call
: Thedeploy
andcall
type of transaction allows users to deploy smart contract on nebulas. Nebulas must startnvm
to execute the contract, so these types of transction must paid for the nvm start.The fixed number of gas defined 60.
Transaction payload execution(Smart contract deploy & call)
The binary
type of transaction do not do any processing when the transaction is executed, so the execution need not be paid.
When a smart contract deploys or call in transaction submition, the contract execution will consume miner's computer resources and may store data on the chain.
execution instructions: Every contract execution cost the miner's computer resources, the v8 instruction counter calculates the execution instructions. The limit of execution instructions will prevent the excessive consumption of computer computing power and the generation of the death cycle.
contract storage: The smart contract's
LocalContractStorage
which storage contract objects also burn gas. Only one gas per 32 bytes is consumed when stored(set
/put
),get
ordelete
not burns gas.
The limit of contract execution is:
Gas Count Matrix
The gas count matrix of smart contract execution
Tips
In nebulas, the transaction pool of each node has a minimum and maximum gasPrice
and maximum gasLimit
value. If transaction's gasPrice
is not in the range of the pool's gasPrice
or the gasLimit
greater than the pool's gasLimit the transaction will be refused.
Transaction pool gasPrice and gasLimit configuration:
gasPrice
minimum: The minimum gasPrice can be set in the configuration file. If the minimum value is not configured, the default value is
1000000
(10^6).maximum: The maximum gasPrice is
1000000000000
(10^12), transaction pool's maximum configuration and transaction'sgasPrice
can't be overflow.
gasLimit
minimum: The transaction's minimum gasLimit must greater than zero.
maximum: The maximum gasPrice is
50000000000
(50*10^9), transaction pool's maximum configuration and transaction'sgasLimit
can't be overflow.
Last updated