![]() | IntroductionValidators execute transactions in a block, and compute the resulting changes to the network. Transactions in blocks have fees associated with them, called gas fees, that serve as a defense mechanism protecting blockchains from attack. The Halting ProblemLet’s start with an old computer science problem solved by Alan Turing himself; The Halting Problem. The Halting Problem says that the only way to find out if a program will halt execution at some point (as it should), is to execute that program. There is no way to determine if there will be a result without working to compute that result. This simple discovery is the essence for why gas exists on Ethereum. Why Blockchains Have Gas FeesBlockchains must always be operational, which requires miners/validators to continuously execute transactions. These transactions are broadcast in programming languages like Solidity or the lower-level bytecode, which means that transactions are themselves programs. Validators execute transactions and compute the changes our transactions have on the network, but remember the Halting Problem here. A malicious person could send a transaction that never halts, keeps looping, and drains validator resources. Gas serves as the protection against this behavior. When we send transactions, we must associate them with gas fees we’re willing to pay. This gas cost covers the resources used to compute our transaction - but is also a limit on the resources the transaction can take. If a transaction runs out of gas, execution stops and the transaction is discarded. This is far better than having transactions stuck in loops, draining resources. Gas LimitGas is measured in units. Each operation that can be performed requires units of gas based on how much effort it requires. Complex transactions like deploying a smart contract or minting an NFT require more effort to compute than a simple transfer of currency. The difference of effort is measured in the different units of gas required. The units of gas used by a transaction is expressed in its gas limit. The higher the gas limit, the more effort validators can spend executing it. If a transaction requires more effort to execute than the gas allocated to it, the transaction will fail. When transactions fail due to this “out of gas” error, validators stop executing them and keep the gas for the effort they already spent. The gas limit prevents blockchains from experiencing the Halting Problem. No transaction can execute indefinitely unless it also has an indefinite amount of gas associated. This in unrealistically expensive, especially since as we will see next, gas costs money. Gas Pricehe cost of each unit of gas is measured in sub-units of Ethereum’s currency, called gwei. The cost of a transaction is the gas limit multiplied by the gas price. Transactions can also include an additional tip to the validator, called a priority fee. You can find the gas price at a given time using Etherscan. 1 ETH splits into one billion gwei, but even with such small amounts costs can add up. The price in gwei that a transaction will require is based on current network traffic. These prices are very dynamic. When many people are performing transactions at the same time, the price of gas in gwei tends to go up. This is because blocks are limited in size to 30 million units of gas maximum, and people will outbid each other to ensure their transactions are executed. Block space is limited, so the price of that space changes with how popular it is at a given point in time. This is the other side of the defense; performing an attack that spams a network to drain it of its resources (known as a DDoS attack) would increase gas prices for each subsequent transaction in that attack, making it increasingly expensive. A notably different example is Solana which has a fixed gas fee for all transactions. This has proven to not be an adequate defense, causing the chain to stop operating on many occasions. Thank You!This write-up is a summary of the full write-up from my free newsletter. Sign up to support me and receive simple write-ups on blockchain concepts, delivered every other week. Stay kind. Stay curious. [link] [comments] |

You can get bonuses upto $100 FREE BONUS when you:
💰 Install these recommended apps:
💲 SocialGood - 100% Crypto Back on Everyday Shopping
💲 xPortal - The DeFi For The Next Billion
💲 CryptoTab Browser - Lightweight, fast, and ready to mine!
💰 Register on these recommended exchanges:
🟡 Binance🟡 Bitfinex🟡 Bitmart🟡 Bittrex🟡 Bitget
🟡 CoinEx🟡 Crypto.com🟡 Gate.io🟡 Huobi🟡 Kucoin.
Comments