diff --git a/src/content/developers/docs/consensus-mechanisms/pow/index.md b/src/content/developers/docs/consensus-mechanisms/pow/index.md index 49694e7776b..48a81da0d12 100644 --- a/src/content/developers/docs/consensus-mechanisms/pow/index.md +++ b/src/content/developers/docs/consensus-mechanisms/pow/index.md @@ -3,12 +3,13 @@ title: Proof-of-work (PoW) description: An explanation of the proof-of-work consensus protocol and its role in Ethereum. lang: en sidebar: true -incomplete: true --- -Ethereum, like Bitcoin, currently uses a consensus protocol called **[Proof-of-work (PoW)](https://wikipedia.org/wiki/Proof_of_work)**. This allows the nodes of the Ethereum network to agree on the state of all information recorded on the Ethereum blockchain and prevents certain kinds of economic attacks. +The Ethereum network began by using a consensus mechanism that involved **[Proof-of-work (PoW)](/developers/docs/consensus-mechanisms/pow)**. This allowed the nodes of the Ethereum network to agree on the state of all information recorded on the Ethereum blockchain and prevented certain kinds of economic attacks. However, Ethereum switched off proof-of-work in 2022 and started using [proof-of-stake](/developers/docs/consensus-mechanisms/pos) instead. -Over the next year, proof-of-work will be phased out in favour of **[Proof-of-stake (PoS)](/developers/docs/consensus-mechanisms/pos)**. The transition to proof-of-stake will also phase out mining from Ethereum. [More on The Merge.](/upgrades/merge/) + + Proof-of-work has now been deprecated. Ethereum no longer uses proof-of-work as part of its consensus mechanism. Instead, it uses proof-of-stake. Read more on proof-of-stake and staking. + ## Prerequisites {#prerequisites} @@ -16,63 +17,59 @@ To better understand this page, we recommend you first read up on [transactions] ## What is Proof-of-work (PoW)? {#what-is-pow} -Proof-of-work is the mechanism that allows the decentralized Ethereum network to come to consensus, or agree on things like account balances and the order of transactions. This prevents users from "double spending" their coins and ensures that the Ethereum chain is tremendously difficult to attack or manipulate. +Nakamoto consensus, which utilizes proof-of-work, is the mechanism that once allowed the decentralized Ethereum network to come to consensus (i.e. all nodes agree) on things like account balances and the order of transactions. This prevented users from "double spending" their coins and ensured that the Ethereum chain was tremendously difficult to attack or manipulate. These security properties now come from proof-of-stake instead using the consensus mechanism known as [Gasper](/developers/docs/consensus-mechanisms/pos/gasper/). ## Proof-of-work and mining {#pow-and-mining} -Proof-of-work is the underlying algorithm that sets the difficulty and rules for the work miners do. Mining is the "work" itself. It's the act of adding valid blocks to the chain. This is important because the chain's length helps the network follow the correct Ethereum chain and understand Ethereum's current state. The more "work" done, the longer the chain, and the higher the block number, the more certain the network can be of the current state of things. +Proof-of-work is the underlying algorithm that sets the difficulty and rules for the work miners do on proof-of-work blockchains. Mining is the "work" itself. It's the act of adding valid blocks to the chain. This is important because the chain's length helps the network follow the correct fork of the blockchain. The more "work" done, the longer the chain, and the higher the block number, the more certain the network can be of the current state of things. [More on mining](/developers/docs/consensus-mechanisms/pow/mining/) -## How does Ethereum's proof-of-work work? {#how-it-works} +## How did Ethereum's proof-of-work work? {#how-it-works} -Ethereum transactions are processed into blocks. Each block has a: +Ethereum transactions are processed into blocks. In the now-deprecated proof-of-work Ethereum, each block contained: - block difficulty – for example: 3,324,092,183,262,715 - mixHash – for example: `0x44bca881b07a6a09f83b130798072441705d9a665c5ac8bdf2f39a3cdf3bee29` - nonce – for example: `0xd3ee432b4fb3d26b` -This block data is directly related to proof-of-work. +This block data was directly related to proof-of-work. ### The work in proof-of-work {#the-work} -The proof-of-work protocol, Ethash, requires miners to go through an intense race of trial and error to find the nonce for a block. Only blocks with a valid nonce can be added to the chain. +The proof-of-work protocol, Ethash, required miners to go through an intense race of trial and error to find the nonce for a block. Only blocks with a valid nonce could be added to the chain. -When racing to create a block, a miner will repeatedly put a dataset, that you can only get from downloading and running the full chain (as a miner does), through a mathematical function. The dataset gets used to generate a mixHash below a target nonce, as dictated by the block difficulty. The best way to do this is through trial and error. +When racing to create a block, a miner repeatedly put a dataset, that could only be obtained by downloading and running the full chain (as a miner does), through a mathematical function. The dataset was used to generate a mixHash below a target that is dictated by the block difficulty. The best way to do this is through trial and error. -The difficulty determines the target for the hash. The lower the target, the smaller the set of valid hashes. Once generated, this is incredibly easy for other miners and clients to verify. Even if one transaction were to change, the hash would be completely different, signalling fraud. +The difficulty determined the target for the hash. The lower the target, the smaller the set of valid hashes. Once generated, this was incredibly easy for other miners and clients to verify. Even if one transaction were to change, the hash would be completely different, signalling fraud. -Hashing makes fraud easy to spot. But proof-of-work as a process is also a big deterrent to attacking the chain. +Hashing makes fraud easy to spot. But proof-of-work as a process was also a big deterrent to attacking the chain. ### Proof-of-work and security {#security} -Miners are incentivised to do this work on the main Ethereum chain. There is little incentive for a subset of miners to start their own chain – it undermines the system. Blockchains rely on having a single state as a source of truth. And users will always choose the longest or "heaviest" chain. +Miners were incentivized to do this work on the main Ethereum chain. There was little incentive for a subset of miners to start their own chain—it undermines the system. Blockchains rely on having a single state as a source of truth. -The objective of proof-of-work is to extend the chain. The longest chain is most believable as the valid one because it's had the most computational work done. Within Ethereum's PoW system, it's nearly impossible to create new blocks that erase transactions, create fake ones, or maintain a second chain. That's because a malicious miner would need to always solve the block nonce faster than everyone else. +The objective of proof-of-work was to extend the chain. The longest chain was most believable as the valid one because it had the most computational work done to generate it. Within Ethereum's PoW system, it was nearly impossible to create new blocks that erase transactions, create fake ones, or maintain a second chain. That's because a malicious miner would have needed to always solve the block nonce faster than everyone else. -To consistently create malicious yet valid blocks, you'd need over 51% of the network mining power to beat everyone else. You'd need a lot of computing power to be able to do this amount of "work". And the energy spent might even outweigh the gains you'd make in an attack. +To consistently create malicious yet valid blocks, a malicious miner would have needed over 51% of the network mining power to beat everyone else. That amount of "work" requires a lot of expensive computing power and the energy spent might even have outweighed the gains made in an attack. ### Proof-of-work economics {#economics} -Proof-of-work is also responsible for issuing new currency into the system and incentivizing miners to do the work. +Proof-of-work was also responsible for issuing new currency into the system and incentivizing miners to do the work. -Miners who successfully create a block get rewarded with two freshly minted ETH but no longer receive all the transaction fees, as the base fee gets burned, while the tip and block reward goes to the miner. A miner may also get 1.75 ETH for an uncle block. Uncle blocks are valid blocks created by a miner practically at the same time as another miner mined the successful block. Uncle blocks usually happen due to network latency. +Since the [Constantinople upgrade](/history/#constantinople), miners who successfully create a block were rewarded with two freshly minted ETH and part of the transaction fees. Ommer blocks also compensated 1.75 ETH. Ommer blocks were valid blocks created by a miner practically at the same time as another miner created the canonical block, which was ultimately determined by which chain was built on top of first. Ommer blocks usually happened due to network latency. ## Finality {#finality} A transaction has "finality" on Ethereum when it's part of a block that can't change. -Because miners work in a decentralized way, two valid blocks can get mined at the same time. This creates a temporary fork. Eventually, one of these chains will become the accepted chain after a subsequent block has been mined and added, making it longer. +Because miners worked in a decentralized way, two valid blocks could be mined at the same time. This creates a temporary fork. Eventually, one of these chains became the accepted chain after subsequent blocks were mined and added to it, making it longer. -But to complicate things further, transactions rejected on the temporary fork may have been included in the accepted chain. This means it could get reversed. So finality refers to the time you should wait before considering a transaction irreversible. For Ethereum, the recommended time is six blocks or just over 1 minute. After six blocks, you can say with relative confidence that the transaction was successful. You can wait longer for even greater assurances. - -Finality is something to bear in mind when designing dapps. It would be a poor user experience to misrepresent transaction information to your users, especially if the transaction is of high value. - -Remember, this timing doesn't include the wait times for having a transaction picked up by a miner. +To complicate things further, transactions rejected on the temporary fork may not have been included in the accepted chain. This means it could get reversed. So finality refers to the time you should wait before considering a transaction irreversible. Under the previous proof-of-work Ethereum, the more blocks were mined on top of a specific block `N`, the higher confidence that the transactions in `N` were successful and would not be reverted. Now, with proof-of-stake, finalization is an explicit, rather than probabilistic, property of a block. ## Proof-of-work energy-usage {#energy} -A major criticism of proof-of-work is the amount of energy output required to keep the network safe. To maintain security and decentralization, Ethereum on proof-of-work consumes 73.2 TWh annually, the energy equivalent of a medium-sized country like Austria. +A major criticism of proof-of-work is the amount of energy output required to keep the network safe. To maintain security and decentralization, Ethereum on proof-of-work consumed large amounts of energy. Shortly before switching to proof-of-stake, Ethereum miners were collectively consuming about 70 TWh/yr (about the same as the Czech Republic - according to [digiconomist](digiconomist.net) on 18-July-2022). ## Pros and cons {#pros-and-cons} diff --git a/src/content/developers/docs/gas/index.md b/src/content/developers/docs/gas/index.md index e89691815d7..29d5e01ca70 100644 --- a/src/content/developers/docs/gas/index.md +++ b/src/content/developers/docs/gas/index.md @@ -18,22 +18,24 @@ Gas refers to the unit that measures the amount of computational effort required Since each Ethereum transaction requires computational resources to execute, each transaction requires a fee. Gas refers to the fee required to conduct a transaction on Ethereum successfully. -![A diagram showing where gas is needed in EVM operations](/developers/docs/gas/gas.png) +![A diagram showing where gas is needed in EVM operations](./gas.png) _Diagram adapted from [Ethereum EVM illustrated](https://takenobu-hs.github.io/downloads/ethereum_evm_illustrated.pdf)_ Gas fees are paid in Ethereum's native currency, ether (ETH). Gas prices are denoted in gwei, which itself is a denomination of ETH - each gwei is equal to 0.000000001 ETH (10-9 ETH). For example, instead of saying that your gas costs 0.000000001 ether, you can say your gas costs 1 gwei. The word 'gwei' itself means 'giga-wei', and it is equal to 1,000,000,000 wei. Wei itself (named after [Wei Dai](https://wikipedia.org/wiki/Wei_Dai), creator of [b-money](https://www.investopedia.com/terms/b/bmoney.asp)) is the smallest unit of ETH. -## How Gas works {#how-gas-works} +## Prior to the London upgrade {#pre-london} -Since the [London Upgrade](/history/#london) every block has a base fee, the minimum price per unit of gas for inclusion in this block, calculated by the network based on demand for block space. As the base fee of the transaction fee is burnt, users are also expected to set a tip (priority fee) in their transactions. The tip compensates validators for executing and propagating user transactions in blocks and is expected to be set automatically by most wallets. +The way transaction fees on the Ethereum network were calculated changed with [the London Upgrade](/history/#london) of August 2021. Here is a recap of how things used to work: -Calculating the total transaction fee works as follows: +Let's say Alice had to pay Bob 1 ETH. +In the transaction, the gas limit is 21,000 units, and the gas price is 200 gwei. -`Gas units (limit) * (Base fee + Tip)` +Total fee would have been: `Gas units (limit) * Gas price per unit` +i.e `21,000 * 200 = 4,200,000 gwei` or 0.0042 ETH Let's say Jordan has to pay Taylor 1 ETH. In the transaction, the gas limit is 21,000 units and the base fee is 10 gwei. Jordan includes a tip of 2 gwei. -Using the formula above we can calculate this as +## After the London upgrade {#post-london} `21,000 * (10 + 2) = 252,000 gwei` or 0.000252 ETH. @@ -52,7 +54,7 @@ The London Upgrade introduced variable-size blocks to Ethereum. Each block has a ### Base fee {#base-fee} -Every block has a base fee which acts as a reserve price. To be eligible for inclusion in a block the offered price per gas must at least equal the base fee. The base fee is calculated independently of the current block and is instead determined by the blocks before it - making transaction fees more predictable for users. When the block is added to the blockchain this base fee is "burned", removing it from circulation. +Every block has a base fee which acts as a reserve price. To be eligible for inclusion in a block the offered price per gas must at least equal the base fee. The base fee is calculated independently of the current block and is instead determined by the blocks before it - making transaction fees more predictable for users. When the block is mined this base fee is "burned", removing it from circulation. The base fee is calculated by a formula that compares the size of the previous block (the amount of gas used for all the transactions) with the target size. The base fee will increase by a maximum of 12.5% per block if the target block size is exceeded. This exponential growth makes it economically non-viable for block size to remain high indefinitely. @@ -81,7 +83,9 @@ It's also important to note it is unlikely we will see extended spikes of full b ### Priority fee (tips) {#priority-fee} -In addition to the base fee, which is burned, there is also a priority fee (tip) to incentivize validators to include a transaction in the block. Without tips, validators would find it economically viable to propose empty blocks, as they would receive the same block reward. Under normal conditions, a small tip provides validators a sufficient incentive to include a transaction. For transactions that need to get preferentially executed ahead of other transactions in the same block, a higher tip will be necessary to attempt to outbid competing transactions. +Before the London Upgrade, miners would receive the total gas fee from any transaction included in a block. + +With the new base fee getting burned, the London Upgrade introduced a priority fee (tip) to incentivize miners to include a transaction in the block. Without tips, miners would find it economically viable to mine empty blocks, as they would receive the same block reward. Under normal conditions, a small tip provides miners a minimal incentive to include a transaction. For transactions that need to get preferentially executed ahead of other transactions in the same block, a higher tip will be necessary to attempt to outbid competing transactions. ### Max fee {#maxfee} @@ -89,13 +93,13 @@ To execute a transaction on the network, users can specify a maximum limit they ### Calculating fees {#calculating-fees} -For wallets that support the London upgrade, instead of explicitly stating how much you are willing to pay to get your transaction through, wallet providers will automatically set a recommended transaction fee (base fee + recommended priority fee) to reduce the amount of complexity burdened onto their users. +One of the main benefits of the London upgrade is improving the user's experience when setting transaction fees. For wallets that support the upgrade, instead of explicitly stating how much you are willing to pay to get your transaction through, wallet providers will automatically set a recommended transaction fee (base fee + recommended priority fee) to reduce the amount of complexity burdened onto their users. ## EIP-1559 {#eip-1559} The implementation of [EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md) in the London Upgrade made the transaction fee mechanism more complex than the previous gas price auction, but it has the advantage of making gas fees more predictable, resulting in a more efficient transaction fee market. Users can submit transactions with a `maxFeePerGas` corresponding to how much they are willing to pay for the transaction to be executing, knowing that they will not pay more than the market price for gas (`baseFeePerGas`), and get any extra, minus their tip, refunded. -This video explains EIP-1559 and the benefits it brought: +This video explains EIP-1559 and the benefits it brings: @@ -117,7 +121,7 @@ _Diagram adapted from [Ethereum EVM illustrated](https://takenobu-hs.github.io/d Gas limit refers to the maximum amount of gas you are willing to consume on a transaction. More complicated transactions involving [smart contracts](/developers/docs/smart-contracts/) require more computational work, so they require a higher gas limit than a simple payment. A standard ETH transfer requires a gas limit of 21,000 units of gas. -For example, if you put a gas limit of 50,000 for a simple ETH transfer, the EVM would consume 21,000, and you would get back the remaining 29,000. However, if you specify too little gas, for example, a gas limit of 20,000 for a simple ETH transfer, the EVM will consume your 20,000 gas units attempting to fulfill the transaction, but it will not complete. The EVM then reverts any changes, but since the block-proposer has already done 20k gas units worth of work, that gas is consumed. +For example, if you put a gas limit of 50,000 for a simple ETH transfer, the EVM would consume 21,000, and you would get back the remaining 29,000. However, if you specify too little gas, for example, a gas limit of 20,000 for a simple ETH transfer, the EVM will consume your 20,000 gas units attempting to fulfill the transaction, but it will not complete. The EVM then reverts any changes, but since the miner has already done 20k gas units worth of work, that gas is consumed. ## Why can gas fees get so high? {#why-can-gas-fees-get-so-high} @@ -133,7 +137,7 @@ Layer 2 scaling is a primary initiative to greatly improve gas costs, user exper ## Strategies for you to reduce gas costs {#strategies-for-you-to-reduce-gas-costs} -If you are looking to reduce gas costs for your ETH, you can set a tip to indicate the priority level of your transaction. Validators will execute transactions that offer a higher tip per gas, as they get to keep the tips that you pay and will be less inclined to execute transactions with lower tips set. +If you are looking to reduce gas costs for your ETH, you can set a tip to indicate the priority level of your transaction. Miners will 'work on' and execute transactions that offer a higher tip per gas, as they get to keep the tips that you pay and will be less inclined to execute transactions with lower tips set. If you want to monitor gas prices, so you can send your ETH for less, you can use many different tools such as: @@ -154,3 +158,7 @@ If you want to monitor gas prices, so you can send your ETH for less, you can us - [Is Ethereum more expensive to use as price rises?](https://docs.ethhub.io/questions-about-ethereum/is-ethereum-more-expensive-to-use-as-price-rises/) - [Reducing the gas consumption of your Smart Contracts](https://medium.com/coinmonks/8-ways-of-reducing-the-gas-consumption-of-your-smart-contracts-9a506b339c0a) - [Proof of Stake versus Proof of Work](https://blockgeeks.com/guides/proof-of-work-vs-proof-of-stake/) + +## Related topics {#related-topics} + +- [Mining](/developers/docs/consensus-mechanisms/pow/mining/)