Browsing Tag: GasLimit

    Gas
    Blockchain public chain

    Easy to read Gas,GasLimit,GasPrice on Ethereum

    July 4, 2020

    What is Gas?

    Gas exists in the EVM of Ethereum, and is the unit of measurement for calculating workload. As the fuel of Ethereum network, it provides power for the development and operation of Ethereum network ecology. Just as gasoline plays a role in automobiles, Gas is essential for Ethereum users and developers.

    On the one hand, Gas is used to reward Ethereum miners to pack blocks; on the other hand, its existence improves the threshold of malicious transactions, which can better maintain the normal operation of Ethereum network.

    In the bottom layer of Ethereum system, Gas consumption is determined for each specified operation and contract method, and Gas consumption is required for each operation step in the transaction process. For example, the user deploying the NEST Oracle quotation contract needs to pay a certain Gas fee to execute the transaction, and Gas is the service charge charged by the Ethereum system. When using Ethereum network, the maximum value of Gas consumption must be set. When the Gas consumption is finished or the smart contract logic is completed, the execution of the contract will be stopped. In Ethereum system, Gas needs to be converted into ETH for payment.

    Tip: no matter whether the transaction initiated by the user is packaged successfully or not, the Gas fee must be paid. This is just like driving home on the way home and running out of Gas. Even if you don’t get home successfully, the gasoline consumed has indeed been consumed, so you have to pay for it.

    GasLimit

    What is GasLimit?

    GasLimit is the maximum amount of Gas that Ethereum users are willing to pay for the successful execution of a transaction logic.

    If the GasLimit of a transaction is set too low to complete the transaction logic, the system will prompt “out of Gas” and the transaction will fail. The transaction will still be packaged into the block, and the Ethereum assets carried in the transaction will be automatically returned, but the Gas fee will still be charged, which will be paid as a reward to the miners who pack the block. (users who often deploy smart contracts should have encountered this situation)

    If the number of Gas used in the transaction is less than or equal to the GasLimit you set, it will be packaged successfully. The total amount of Gas consumed in the execution of this transaction is GasUsed, and the unused Gas will be returned to the transaction initiation address.

    Please note that GasLimit here refers to the Gas cap of a transaction. In the whole development process of Ethereum, there is also a GasLimit value that is more important and often mentioned, that is, the GasLimit of a block, that is, the upper limit of the total Gas of the transactions that can be executed in a single Ethereum block.

    When each block is packed, the total GasLimit of all transactions in the current block will be determined, so as to determine the number of transactions that can be packed in the block. Therefore, when packing each transaction, miners will judge whether the current Gas volume is enough to package the current transaction. If you package a transaction that will exceed the GasLimit of the current block, it will be rejected by the Ethereum network, and the system feedback will be “below Gas limit”. After several upgrades of Ethereum 1. X, the GasLimit value of an Ethereum block is 12 million Gas.

    Etherscan GasPrice data
    Etherscan GasPrice data

    Price of single Gas: GasPrice

    GasPrice is the price a user is willing to pay for each Gas, in Gwei.

    1 ETH = 1,000,000,000 Gwei

    In addition to the award of mining block, Ethereum miners always hope that more Gas fees will be included in the block; therefore, when the mining pool packs the transaction, it will give priority to the transaction that pays more miners’ fees.

    Miner’s fee for one transaction = GasPrice * GasUsed

    Therefore, the higher the GasPrice is set, the earlier the transaction is packed into the block and the more confirmed; if the GasPrice setting is too low, the transaction will be in the pending state for a long time, waiting for the miner to pack. Therefore, when the Ethereum network is congested, if we want to speed up the transaction, we need to greatly increase the GasPrice value of the transaction, and let the miners give priority to packing our transactions.

    The above is about the definition and relationship of Gas, GasLimit and GasPrice parameters in Ethereum network. If you want to have a more direct perception of blockchain technology and smart contracts, you can quickly deploy your own smart contract on the Ethereum chain, or join the NEST price Oracle network to become a quotation miner and participate in the Oracle quotation.

    ETH authorization
    Blockchain public chain

    What is “authorization” in Ethereum contract interaction?

    June 30, 2020

    As for the “authorization” operation, many new Ethereum users are confused when they first operate the smart contract. I don’t understand what authorization is, let alone why authorization initiates a transaction, and the transaction itself does not carry any assets, and at the same time, it has to pay a miner’s fee.

    In this article, we will explain the nature of “authorization” operation from the perspective of technology.

    When users interact with Ethereum smart contract token assets, they must first approve. So, why do you need authorization?

    quotation for nest oracle

    Let’s give an example of a miners’ quotation for nest oracle:

    • Bob is a nest price maker. When he participates in the ETH/USDT price prediction machine quotation, he needs to transfer the ETH and USDT assets into the quotation contract according to his own quotation data. Here, it is assumed that 10 ETH and 1600 USDT are used to conduct a quotation operation.
    • Then Bob must first authorize the USDT asset to the quotation contract of nest Oracle, so that the quotation contract has the authority to operate the USDT asset in Bob’s wallet, so that the transaction logic related to USDT asset can be executed smoothly when the verifier takes the order within the quotation life cycle.
    • Authorization here is essentially an on chain transaction, requiring users to pay miners’ fees (Gas fees). The purpose is to tell the USDT token contract that target smart contract a has the right to control the number of USDT assets in my wallet X. Then, when the target contract A needs to conduct USDT transactions, it will take the initiative to obtain no more than x USDT assets from the USDT token contract.

    However, in the above case, another question arises. Why only ERC20 tokens such as USDT need to be authorized while ETH does not?

    Technical analysis: because ETH is the native asset of Ethereum network, when transferring money to the target smart contract, the underlying layer of Ethereum network forces the target contract to have a certain receiving method, so the transaction itself can carry ETH assets into the target contract; while ERC20 token only changes the ERC20 token when transferring to the target contract The target contract will not receive any notice for the account book information of the contract itself.

    Therefore, ETH does not need authorization operations like ERC20 token when it interacts with smart contracts.

    To be exact, there are two steps in the authorization operation:

    Step 1: authorize the transaction itself. It is to tell an ERC20 token contract that in the future, a target smart contract address a may come to my wallet account to take x quantity of token assets;

    Step 2: the transaction execution itself. When the logic execution in the target contract A requires the token transaction, contract a will take the initiative to trigger the transfer transaction of ERC20 token to take away the X quantity of the token; on the contrary, if the transaction of the token is not involved, even if it has been authorized, the asset transaction will not really occur.

    In short, after the authorization operation, the token transaction is not necessarily executed, but such a fund operation authority is reserved for the target contract A.

    In order to avoid users’ repeated authorization operations, many smart contract developers usually set the maximum number of tokens authorized to the target smart contract by default. Obviously, there are certain risks in this way. If there is a loophole in the smart contract or the contract administrator does something evil, the user’s token assets will be lost, which is the problem caused by “over authorization“.

    Whether in NEST DAPP or imToken wallet, we often encounter this problem.

    over authorization

    In order to solve the problem of “over authorization”, NEST DAPP has an authorization management page. If a miner does not expect to participate in NEST Oracle quotation in a short time, he can “cancel authorization” to eliminate the security problems caused by existing authorization. imToken wallet also takes some measures, such as “clear authorization information” for each authorization, and has an exclusive DAPP for authorization management, so that users can freely manage their existing authorization.

    The feasibility scheme of skipping authorization operation: by implementing specific transfer logic in ERC20 token contract, that is, a method of forcibly invoking the target contract while transferring money, the current authorization operation can be avoided. However, in order to keep the purity of token contract, the mainstream ERC20 token does not implement this function.

    Ethereum block
    Blockchain public chain

    How to determine the size of Ethereum block

    June 28, 2020

    With the development of blockchain industry, the ecosystem based on the Ethereum network is becoming larger and larger. In addition to the transaction package of various assets issued based on the Ethereum network, it also needs to meet a variety of smart contract package transactions, such as the business contracts related to the DeFi protocol (Uniswap), Oracle protocol(NEST protocol), and the game (Decentraland). This makes the Ethereum network need to deal with more and more transactions, so that we often see the congestion of Ethereum and the increase of miners’ fees when the market fluctuates.

    EthGasStation
    Ethgasstation: ranking of Gas consumption of Ethereum network

    According to the natural growth rate of the current Ethereum blockchain state, the Ethereum network will face some problems before long. Because, with the continuous growth of Ethereum block data, the threshold for us to run the whole Ethereum node will be higher and higher, which will lead to the more centralized Ethereum network. (currently, an Ethereum node needs about 220GB of storage space)

    With the increase of network delay, its speed may become slower and slower; with the emergence of “state expansion“, block verification may become more difficult. Finally, as the transaction TPS reaches the upper limit, and the improvement of the client is more difficult to achieve, the end users and core developers of Ethereum will be hit, which will affect the sustainable development of Ethereum ecology.

    daily transactions to be packed
    Etherscan: number of daily transactions to be packed in the Ethereum network

    At the macro level, the problem that Ethereum 1.0 network is facing is that the Ethereum blockchain is becoming larger and larger! In terms of segmentation, the variables that make the problem more prominent are data storage, transaction status and block size. Today, we mainly analyze the core factor of “Ethereum block size“, and specifically understand how to determine the block size of the Ethereum network.

    Unlike Bitcoin networks, Ethereum does not explicitly limit the size of each block by memory, but forces the size of each block by block GasLimit.

    The block GasLimit setting of Ethereum effectively limits the amount of transactions that can be packaged in a block. The GasLimit parameter is determined by the Ethereum miners collectively, that is, to dynamically increase or decrease the GasLimit value by voting. The most recent vote was in the second half of 2019. The miners voted to increase the block GasLimit of Ethereum from the original 8 million gas units to 10 million, increasing the size of each block by about 25% compared with the previous block, which theoretically improves the TPS of Ethereum network.

    Ethereum network TPS
    BTC.COM Display, Ethereum network TPS: 8 ~ 14

    Increasing the GasLimit of a block means that the data volume of a single block package transaction increases and the block becomes larger, which slows down the information transmission speed, which will increase the probability of out of block of the uncle block. Even though Ethereum uncle block has some ETH mining rewards, the miners don’t want to meet it.Therefore, there is a balance between the upper limit of GasLimit in a single block and the miner group. (Note: in the Ethereum system, if multiple miners dig out new blocks at the same block height, one of these blocks will become the block on the longest chain, while the other blocks, if referenced by subsequent blocks, will be called Uncle block)

    Therefore, the GasLimit of a single block of the Ethereum network can not be significantly prompted in a short time, but it should be dynamically adjusted according to the development state of the Ethereum network to balance the efficiency required by the ecological development and the interests of the miners.

    So far, there is a scientific conclusion about the “safe” block size upper limit data, but we generally believe that the TPS improvement brought by increasing the single block GasLimit upper limit is not enough to achieve the development of Ethereum in the next three years. In addition, there are many other related problems.

    Finally, we look forward to the early arrival of eth 2.0!